Chinaunix首页 | 论坛 | 博客
  • 博客访问: 685882
  • 博文数量: 152
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 1793
  • 用 户 组: 普通用户
  • 注册时间: 2013-09-12 12:26
个人简介

相信自己,只有不想做的,没有做不到的。

文章分类

全部博文(152)

文章存档

2021年(1)

2015年(2)

2014年(74)

2013年(75)

分类: Html/Css

2013-10-27 09:40:58

html------->main1.html     与cgi程序向关联




仓库一






        
 
cgi-bin/setEnv.cgi" method="get">

         
         
         
         


cgi-------> cgi-picture1.cgi    在网页上点击历史照片 调用一下的这个cgi程序  读取目录中的图片
 
int cgiMain()
{
DIR *dir;
struct dirent *dirp;


cgiHeaderContentType("text/html");                //在cgi程序中嵌套 html语言
fprintf(cgiOut, "\n");
fprintf(cgiOut, "");
fprintf(cgiOut, " ");
fprintf(cgiOut, "");
fprintf(cgiOut, " history Picture");
fprintf(cgiOut, "");
fprintf(cgiOut, "

history Picture:

");
fprintf(cgiOut, "回主页");


if((dir = opendir("../pice/")) == NULL)
{
perror("fail to opendir");
return -1;
}


if(dir != NULL)
{
while((dirp = readdir(dir)) != NULL)
{
if(dirp->d_name[0] == '.') continue;
fprintf(cgiOut, "
");
fprintf(cgiOut,"%s",dirp->d_name);
fprintf(cgiOut, "
");
fprintf(cgiOut, "
",dirp->d_name);
fprintf(cgiOut, "
");
}
}



fprintf(cgiOut, " ");



return 0;
}

cgi------> cgi程序与主main函数相关联
#define N 32
struct msg
{
long type;
long msgtype;
unsigned char text[N];
};

struct setEnv
{
int temMAX;
int temMIN;
int humMAX;
int humMIN;
int illMAX;
int illMIN;
};


int cgiMain()
{
key_t  key;
char sto_no[2];
char buf[20];
struct setEnv new;
int msgid;
struct msg msg_buf;

memset(&msg_buf,0,sizeof(msg_buf));
cgiFormString("store", sto_no, 2);  //判断仓库号


cgiFormString("temMAX", buf, 20);   //通过html上的name="temMAX",读取数据到buf中
new.temMAX = atoi (buf);               //在把字符串转化成整形
cgiFormString("temMIN", buf, 20);
new.temMIN = atoi (buf);
cgiFormString("humMAX", buf, 20);
new.humMAX = atoi (buf);
cgiFormString("humMIN", buf, 20);
new.humMIN = atoi (buf);
cgiFormString("illMAX", buf, 20);
new.illMAX = atoi (buf);
cgiFormString("illMIN", buf, 20);
new.illMIN = atoi (buf);


if((key = ftok("/app", 'g')) < 0)   //获得Key
{
perror("ftok");
exit(1);
}


if((msgid = msgget(key, 0666)) < 0)  //创建消息队列
{
perror("msgget");
exit(1);
}

memcpy (msg_buf.text+1, &new, 24);

msg_buf.type = 1L;
msg_buf.msgtype = 2L;
msg_buf.text[0] = sto_no[0];   //填充消息队列结构体

msgsnd(msgid, &msg_buf,sizeof(msg_buf)-sizeof(long),0);   //发给main函数的  消息队列通过消息类型发送  msg.type=1L


sto_no[0] -= 48;

cgiHeaderContentType("text/html\n\n"); 
fprintf(cgiOut, "\n"); 
fprintf(cgiOut, "My CGI\n"); 
fprintf(cgiOut, ""); 


fprintf(cgiOut, "

send sucess

");



//fprintf(cgiOut, "返回"); 
fprintf(cgiOut, "", sto_no[0]);
fprintf(cgiOut, "\n"); 
fprintf(cgiOut, "\n"); 




return 0; 


}


main函数-------->
if ((key = ftok ("/app", 'g')) < 0)  //获得key
 if ((msgid = msgget (key, IPC_CREAT | IPC_EXCL | 0666)) < 0)  //创建消息结构体
while (1)
{
bzero (&msgbuf, sizeof (msgbuf));
msgsize = msgrcv (msgid, &msgbuf, sizeof (msgbuf) - sizeof (long), 1L, 0);  //结果的消息类型为1L

switch (msgbuf.msgtype)
{
case 1L:      //可以
{
pthread_mutex_lock (&mutex_led);
dev_led_mask = msgbuf.text[0];
pthread_cond_signal (&cond_led);      可以唤醒led点灯的线程,对底层的led做操作,此处的led.c与底层的led.ko的调用接口要匹配
pthread_mutex_unlock (&mutex_led);
break;
}
case 2L:   //这样就到了主函数的客户端出来线程的函数了,可以在此函数内做你要做的事情,可以
pthread_mutex_lock (&mutex_global);
printf ("sto_no = %d temMAX = %d, temMIN = %d, humMAX = %d, hunMIN = %d, illMAX = %d, illMIN = %d\n", 
sto_no, new.temMAX, new.temMIN, new.humMAX, new.humMIN, new.illMAX, new.illMIN);
pthread_cond_signal (&cond_sqlite);                          //唤醒数据库处理线程
pthread_mutex_lock (&mutex_slinklist);

//这就是一个html调用cgi程序,在cgi程序中封装消息结构体,在通过消息类型发送给主函数,主函数在通过消息类型接受消息,在判断消息结构体中的msg.type=?,
在做相应的线程唤醒与操作,打开led,打开蜂鸣器等等







阅读(1043) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~