本文共 5943 字,大约阅读时间需要 19 分钟。
#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("");}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; } }}"); printf(""); printf("设置结果"); printf(" %s", info); printf("
#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
#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("
#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