您的位置:首页 > 其它

基于ARM的智能灯光控制系统总结(17-网页CGI进程之区域添加)

2018-03-13 05:59 465 查看
区域添加同设备添加大同小异



area_add.c#include<unistd.h>
#include<stdlib.h>
#include<stdio.h>
#include<string.h>
#include "html.h"
#include "config.h"
#include "ipc.h"

void table_tr(struct sys_all * shm_dev)
{
char id;
int i;

printf("<tr><td><input type=\"text\" name=\"name\" value=\"%s\"></td><td>","区域N");

for(i=0;i<shm_dev->count_dev;i++){
id=shm_dev->sys_dev[i].node.type;
if(id==DEV_T_LIGHT1||id==DEV_T_LIGHT2||id==DEV_T_LIG_NET)
printf("<input type=\"checkbox\" name=\"light%d\" value=\"%d\">%s ",id,id,shm_dev->sys_dev[i].name);
}

printf("</td><td class=\"center\"><button type=\"submit\">创建</button></td></tr>");
}

int main(int argc, char * argv[])
{
int ret=0;
int i,msgid;
struct sys_all * shm_dev;
char item_name[3][16];

if((msgid=get_msgid())<0){
ret=ERR_MSG;
}

if(msg_send(msgid,CMD_GET)==0){
if(NULL==(shm_dev=(struct sys_all *)set_web_shm())){
ret=ERR_SHM;
}
}

html_head();
html_title();
html_nav();
html_table_title("区域创建","区域设置","区域创建");
if(ret!=0){
html_return_show(ret);
html_end();
return 0;
}

printf("<form method=\"get\" action=\"/cgi-bin/area_add_post.cgi\">");

strcpy(item_name[0],"区域名称");
strcpy(item_name[1],"设备选择");
strcpy(item_name[2],"提交操作");

html_table_head(3,item_name,"区域创建");
table_tr(shm_dev);
html_table_end();
html_end();
return 0;
}
area_add_post.c#include<unistd.h>
#include<stdlib.h>
#include<stdio.h>
#include<string.h>
#include "html.h"
#include "config.h"
#include "ipc.h"
#include "getvalue.h"

int main(int argc,char * argv[])
{
int ret=0;
char *val=NULL;
char val_name[16];
char type_id[2]="0";
int i,j,index,msgid;
struct sys_all * shm_dev;

set_env(getenv("REQUEST_METHOD"),getenv("CONTENT_LENGTH"),getenv("QUERY_STRING"));

html_head();
html_refresh("3","/cgi-bin/area_add.cgi");
html_title();
html_nav();
html_table_title("区域创建","区域设置","区域创建");

if(NULL==(shm_dev=(struct sys_all *)set_web_shm())){
ret=ERR_SHM;
}else{
for(i=0;i<MAX_DEV;i++){
if(shm_dev->sys_area[i].enable_flag==0){
val=get_value("name");
strcpy(shm_dev->sys_area[i].name,val);
index=0;
shm_dev->sys_area[i].enable_flag=1;
for(j=0;j<shm_dev->count_dev;j++){
type_id[0]=shm_dev->sys_dev[j].node.type+'0';
strcpy(val_name,"light");
strcat(val_name,type_id);
val=get_value(val_name);
if(val!=NULL){
shm_dev->sys_area[i].dev_id[index]=val[0]-'0';
index++;
}
}
break;//找到第一个enable_flag=0的区域后就把刚添加的赋值给它就可以了,不用再往下进行了
}
}
if(i==8) ret=ERR_REG;//I=8时说明没有enable_flag=0的区域了,区域设置满了
}

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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐