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

时间:2022-09-08 14:26:01

区域管理cgi程序在网页上设定一个区域内所有灯光设备的开关

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

area_con.c

#include<unistd.h>#include<stdlib.h>
#include<stdio.h>
#include<string.h>
#include<sys/types.h>
#include "html.h"
#include "config.h"
#include "ipc.h"

void table_tr(char * name,char sw,int type_id)
{
int i;

printf("<tr><td>%s</td>",name);

if(sw==1){
printf("<td class=\"center\"><input type=\"radio\" checked=\"checked\" value=\"1\" name=\"sw_sta%d\">开启<input type=\"radio\" value=\"0\" name=\"sw_sta%d\">关闭</td>",type_id,type_id);
}else{
printf("<td class=\"center\"><input type=\"radio\" value=\"1\" name=\"sw_sta%d\">开启<input type=\"radio\" value=\"0\" name=\"sw_sta%d\" checked=\"checked\">关闭</td>",type_id,type_id);
}

printf("<td><input type=\"checkbox\" name=\"flag%d\" value=\"0\">删除区域</td>",type_id);
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[4][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_con_post.cgi\">");

strcpy(item_name[0],"区域名称");
strcpy(item_name[1],"区域开关");
strcpy(item_name[2],"区域删除");
strcpy(item_name[3],"提交操作");

html_table_head(4,item_name,"区域管理");
for(i=0;i<MAX_DEV;i++){
if(shm_dev->sys_area[i].enable_flag==1)
table_tr(shm_dev->sys_area[i].name,shm_dev->sys_area[i].sw_sta,i);
}

html_table_end();
html_end();
return 0;
}

area_con_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,msgid;	struct sys_all * shm_dev;	char buf[32]="";		set_env(getenv("REQUEST_METHOD"),getenv("CONTENT_LENGTH"),getenv("QUERY_STRING"));	html_head();	html_refresh("3","/cgi-bin/area_con.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++){			type_id[0]=i+'0';			strcpy(val_name,"sw_sta");			strcat(val_name,type_id);			val=get_value(val_name);			if(val!=NULL){				shm_dev->sys_area[i].sw_sta=val[0]-'0';			}			strcpy(val_name,"flag");			strcat(val_name,type_id);			val=get_value(val_name);			if(val!=NULL){				shm_dev->sys_area[i].enable_flag=val[0]-'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;}