博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
基于ARM的智能灯光控制系统(8)设备添加
阅读量:7014 次
发布时间:2019-06-28

本文共 5943 字,大约阅读时间需要 19 分钟。

基于ARM的智能灯光控制系统(8)设备添加

设备添加页面

这里写图片描述

网页显示头文件(html.h)

#include 
#define ERR_SHM 1#define ERR_MSG 2#define ERR_REG 3void html_head(){ printf("Content-type:text/html\r\n\r\n"); printf(""); printf("
SL1200智能灯光控制系统"); printf("
"); printf("
"); printf("
");}void html_refresh(char* second, char* url){ printf("
",second, url);}void html_title(){ printf("
"); ...}void html_nav(){ printf("
"); ... }void html_table_title(char* title,char * title1,char *title2){ ...}void html_table_head(int len, char argv[][10],char* title){ ...}void html_table_end(){ printf("
");}void html_end(){ ... printf("");}void html_return_info(char* info){ printf("
"); printf("
"); printf("设置结果
"); printf("
%s", info); printf("
");}void html_return_show(int ret){ if(ret == 0){ html_return_info("设置完成,返回界面."); }else{ switch(ret){ case ERR_SHM: html_return_info("共享内存错误."); break; case ERR_MSG: html_return_info("区域记录己满."); break; case ERR_REG: html_return_info("区域记录己满."); break; default: html_return_info("设置失败,未知错误."); break; } }}

进程通信头文件(ipc.h)

#ifndef __IPC_H_#define __IPC_H_#include 
#include
#include
#include
#include
#define CMD_GET 1#define CMD_SET 2int get_msgid(void){ int id = -1; id = msgget((key_t)1234,0666|IPC_CREAT); return id;}void* set_web_shm(void){ int shmid; void* shmaddr=(void*)0; if((shmid=shmget((key_t)1122,sizeof(struct sys_all),0666|IPC_CREAT))<0){ return NULL; }else{ if((shmaddr=shmat(shmid,(void*)0,0))==(char *)-1){ return NULL; } } return shmaddr;}int msg_send(int msgid,int cmd_da){ struct st_msg_req cmd; cmd.index = WEB_UPDATE_SMG_INDEX; cmd.req = cmd_da; if(msgsnd(msgid,(void*)&cmd,1,0)==-1) return -1; return 0;}#endif

设备添加页面程序(dev_add.c)

#include 
#include
#include
#include
#include "html.h"#include "config.h"#include "ipc.h"void table_tr(char* name,char type,int checked){ char type_id[2]="0"; type_id[0] = type + '0'; printf("
",type_id,name); //显示id printf("
",type_id,type_id); switch(type) { case 1: printf("主控制器"); break; case 2: printf("分控制器"); break; case 3: printf("光线感应"); break; case 4: printf("人体感应"); break; case 5: printf("声音感应"); break; case 6: case 7: printf("灯光设备"); break; case 8: printf("网络设备"); break; default: break; } if(checked==1) { printf("
连通
断开",type_id,type_id); }else{ printf("
连通
断开",type_id,type_id); } printf("
");}int main(int argc, char *argv[]){ int ret = 0; int i,msgid; struct sys_all* shm_dev; char item_name[5][10]; if((msgid=get_msgid()) < 0){ ret = ERR_MSG; } if(msg_send(msgid,CMD_GET)==0){ if((shm_dev=(struct sys_all*)set_web_shm())==NULL){ ret = ERR_SHM; } } html_head(); html_title(); html_nav(); html_table_title("设备添加" , "设备设置" , "设备添加" ); if(ret != 0){ html_return_show(ret); html_end(); return 0; } printf("
"); strcpy(item_name[0],"设备名称"); strcpy(item_name[1],"节点信息"); strcpy(item_name[2],"设备类型"); strcpy(item_name[3],"连接状态"); strcpy(item_name[4],"提交操作"); html_table_head(5,item_name,"设备列表"); for(i=0;i
count_dev;i++){ table_tr(shm_dev->sys_dev[i].name,shm_dev->sys_dev[i].node.type, shm_dev->sys_dev[i].join_sta); } html_table_end(); printf(""); html_end(); return 0;}

页面处理程序(dev_add_post.c)

#include 
#include
#include
#include
#include "getvalue.h"#include "html.h"#include "config.h"#include "ipc.h"int main(int argc, char *argv[]){ int ret = 0; char *val = NULL; char val_name[16]; char type_id[2]="0"; int i,msgid; struct sys_all* shm_dev; set_env(getenv("REQUEST_METHOD"), getenv("CONTENT_LENGTH"), getenv("QUERY_STRING")); html_head(); html_refresh("3","/cgi-bin/dev_add.cgi"); html_title(); html_nav(); html_table_title("设备添加" , "设备设置" , "设备添加" ); if((shm_dev=(struct sys_all*)set_web_shm())==NULL){ ret = ERR_SHM; }else{ for(i=0;i
count_dev;i++){ //根据配置文件实时数据,动态读取变量名join_sta+id type_id[0] = shm_dev->sys_dev[i].node.type + '0'; strcpy(val_name,"join_sta"); strcat(val_name,type_id); val = get_value(val_name); shm_dev->sys_dev[i].join_sta = val[0]-'0'; strcpy(val_name,"name_"); strcat(val_name,type_id); val = get_value(val_name); strcpy(shm_dev->sys_dev[i].name,val); } } if(ret == 0){ if((msgid=get_msgid()) < 0){ ret = ERR_MSG; } if(msg_send(msgid,CMD_SET) < 0) ret = ERR_MSG; } html_return_show(ret); html_end(); return 0;}

转载于:https://blog.51cto.com/91arm/2052758

你可能感兴趣的文章
2 - 建立 Django 博客应用
查看>>
【iOS报错】“this class is not key value coding-compliant for the key userPhoneNum”给字典设置键值对的时候报错...
查看>>
UI技术总结--性能优化
查看>>
Android NDK JNI 开发之旅01 环境搭建入门篇
查看>>
Javascript之迭代器模式
查看>>
Flutter花式玩转TextField,写一个验证码输入框超简单!
查看>>
RxJava应用:实现七牛云多图上传
查看>>
Tmux入门教程
查看>>
智能直播审核方案:视频云智能业务截帧策略
查看>>
亲历者说:Kubernetes API 与 Operator,不为人知的开发者战争
查看>>
[ARKit]10-3D模型怎么制作,哪里寻找,如何使用?
查看>>
Kotlin结合DataBinding简单封装一个RecyclerView的Adapter
查看>>
Android爬坑之旅之不易发现的BUG
查看>>
数值计算 插值与拟合
查看>>
支付与签名原串的那些事,但选择排序生成签名原串
查看>>
koa2开发微信公众号: 不定期推送最新币圈消息
查看>>
小tips:JS中this操作执行像(object.getName = object.getName)()操作改变了this
查看>>
为什么国外的 App 很少会有开屏广告?
查看>>
移动端中webview的h5访问,出现了运营商的广告解决方案
查看>>
PHP curl 返回Connection timed out解决办法
查看>>