本帖最后由 himol 于 2015-10-24 10:07 编辑
PS:
在正式介绍前简单给大家说下:因为时间原因和其他因素在之后的介绍中将不再介绍LED模块、摄像头模块、SMS模块、wifi模块、希望大家理解。
第六节:处理客户请求模块(设备控制)
1. 功能描述
接收CGI,QT以及别的线程检测到异常发送设备控制请求的线程。
2. 数据描述
数据类型 | | |
| | |
| |
| |
| |
| | |
| |
| |
| |
| |
| |
| | |
| |
| |
| |
| |
| |
| | |
struct env_info_clien_addr | | |
| | |
3. 流程图
4. 详细说明
本线程主要用来接收从消息队列里传入的请求,主要是硬件设备的操作,包括A8与M0上的硬件资源的操作,同时也能接收CGI与QT修改仓库各种上下限的值,本线程大部分完成的是一个数据的转发过程,因为通信的结构在发送线程与设备之间已经定义好了相应的协议。 #include "dota_cache.h"
#include "sqlite_link_list.h"
extern unsigned char dev_led_mask;
extern unsigned char dev_camera_mask;
extern unsigned char dev_buzzer_mask;
extern unsigned char dev_uart_mask;
extern pthread_cond_t cond_led;
extern pthread_cond_t cond_camera;
extern pthread_cond_t cond_buzzer;
extern pthread_cond_t cond_refresh;
extern pthread_cond_t cond_uart_cmd;
extern pthread_cond_t cond_sqlite;
extern pthread_mutex_t mutex_global;
extern pthread_mutex_t mutex_uart_cmd;
extern pthread_mutex_t mutex_led;
extern pthread_mutex_t mutex_buzzer;
extern pthread_mutex_t mutex_camera;
extern pthread_mutex_t mutex_slinklist;
extern char cgi_status;
extern int msgid;
extern struct env_info_clien_addr all_info_RT;
extern dota_cache_list m0_cache_head, m0_cache_tail;
struct setEnv
{
int temMAX;
int temMIN;
int humMAX;
int humMIN;
int illMAX;
int illMIN;
};
void *pthread_client_request (void *arg)
{
key_t key;
ssize_t msgsize;
struct msg msgbuf;
struct setEnv new;
int sto_no;
if ((key = ftok ("/app", 'g')) < 0)
{
perror ("ftok msgqueue");
exit (-1);
}
if ((msgid = msgget (key, IPC_CREAT | IPC_EXCL | 0666)) < 0)
{
perror ("msgget msgid");
exit (-1);
}
m0_cache_head = CreateEmptyCacheList ();
m0_cache_tail = m0_cache_head;
unsigned char *m0_temp;
printf ("pthread_client_request is okn");
while (1)
{
bzero (&msgbuf, sizeof (msgbuf));
msgsize = msgrcv (msgid, &msgbuf, sizeof (msgbuf) - sizeof (long), 1L, 0);
switch (msgbuf.msgtype)
{
case 1L:
{
pthread_mutex_lock (&mutex_led);
dev_led_mask = msgbuf.text[0];
pthread_cond_signal (&cond_led);
pthread_mutex_unlock (&mutex_led);
break;
}
case 2L:
{
pthread_mutex_lock (&mutex_buzzer);
dev_buzzer_mask = msgbuf.text[0];
pthread_cond_signal (&cond_buzzer);
pthread_mutex_unlock (&mutex_buzzer);
break;
}
case 3L:
{
pthread_mutex_lock (&mutex_camera);
dev_camera_mask = msgbuf.text[0];
pthread_cond_signal (&cond_camera);
pthread_mutex_unlock (&mutex_camera);
break;
}
case 4L:
{
pthread_mutex_lock (&mutex_uart_cmd);
m0_temp = (unsigned char *)malloc (sizeof (unsigned char));
*m0_temp = msgbuf.text[0];
InsertCacheNode (&m0_cache_tail, m0_temp);
pthread_mutex_unlock (&mutex_uart_cmd);
pthread_cond_signal (&cond_uart_cmd);
break;
}
case 5L:
{
memcpy (&new, msgbuf.text + 1, 24);
sto_no = msgbuf.text[0] - 48;
printf ("sto_no = %d temMAX = %d, temMIN = %d, humMAX = %d, hunMIN = %d, illMAX = %d, illMIN = %dn",
sto_no, new.temMAX, new.temMIN, new.humMAX, new.humMIN, new.illMAX, new.illMIN);
pthread_mutex_lock (&mutex_global);
if (new.temMAX > 0 && new.temMAX > all_info_RT.storage_no[sto_no].temperatureMIN)
{
all_info_RT.storage_no[sto_no].temperatureMAX = new.temMAX;
}
if (new.temMIN > 0 && new.temMIN < all_info_RT.storage_no[sto_no].temperatureMAX)
{
all_info_RT.storage_no[sto_no].temperatureMIN = new.temMIN;
}
if (new.humMAX > 0 && new.humMAX > all_info_RT.storage_no[sto_no].humidityMIN)
{
all_info_RT.storage_no[sto_no].humidityMAX = new.humMAX;
}
if (new.humMIN > 0 && new.humMIN < all_info_RT.storage_no[sto_no].temperatureMAX)
{
all_info_RT.storage_no[sto_no].humidityMIN = new.humMIN;
}
if (new.illMAX > 0 && new.illMAX > all_info_RT.storage_no[sto_no].illuminationMIN) {
all_info_RT.storage_no[sto_no].illuminationMAX = new.illMAX;
}
if (new.illMIN > 0 && new.illMIN < all_info_RT.storage_no[sto_no].illuminationMAX)
{
all_info_RT.storage_no[sto_no].illuminationMIN = new.illMIN;
}
pthread_mutex_lock (&mutex_slinklist);
sqlite_InsertLinknode (ENV_UPDATE, all_info_RT, sto_no, 0);
pthread_mutex_unlock (&mutex_slinklist);
pthread_cond_signal (&cond_sqlite);
pthread_mutex_unlock (&mutex_global);
pthread_cond_signal (&cond_refresh);
break;
}
#if 1
case 10L:
{
int i = 0 , j = 0 ;
for(i = 0 ; i < 11; i++)
{
recive_phone = msgbuf.text;
}
recive_phone = '