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

本文总结了基于ARM的智能灯光控制系统中,如何实现网页CGI进程的区域添加功能,主要涉及area_add.c和area_add_post.c两个关键文件的详细操作。
摘要由CSDN通过智能技术生成

区域添加同设备添加大同小异


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;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值