在欢迎界面导航栏中点击设备设置->设备添加,则打开dev_add.cgi程序,
一、该进程首先通过进程间通信函数向主控进程发送查询消息,主控进程将主数据结构内存中的数据加载至共享内存,cgi进程然后将共享内存的数据显示到html中。
二、在html中点击表单的submit键时,cgi程序将表单中的数据提取出,修改共享内存数据,然后向主控进程发送更新消息,主控进程则将共享内存中的数据更新至主数据结构内存。
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("");
printf(" ",type_id,name);
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][16];
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;
}
strcpy(item_name[0],"设备名称");
strcpy(item_name[1],"节点信息");
strcpy(item_name[2],"设备类型");
strcpy(item_name[3],"连接状态");
strcpy(item_name[4],"提交操作");
printf("