Signed-off-by: 李彦亲 <李彦亲@163.com>

This commit is contained in:
李彦亲 2022-02-11 16:31:53 +08:00
parent 441ce0d4a7
commit caa2e49a01
8 changed files with 270 additions and 226 deletions

View File

@ -1,7 +1,5 @@
{
"files.associations": {
"*.S": "arm",
"*.dts": "arm",
"signal.h": "c"
"server.h": "c"
}
}

View File

@ -2,7 +2,7 @@
# OBJS= main.c server.c convert.c srv.c tcp.c sqlite.c sqlite3.c modul.c shm.c serial.c
OBJS= ./src/*.c
CC=gcc
TARGET=main
TARGET=smart_greenhouse
$(TARGET):$(OBJS)
$(CC) $^ -o $@ -lpthread -lsqlite3 -ldl

Binary file not shown.

Binary file not shown.

View File

@ -1,13 +1,6 @@
/*************************************************************************
> File Name: main.c
> Author: lei
> Mail:
> Created Time: Thu 30 Aug 2018 09:14:46 AM CST
************************************************************************/
#include <stdio.h>
#include "../inc/server.h"
//#include "./include/camera_process.h"
//#include "../include/camera_process.h"
#include <sys/types.h>
#include <unistd.h>

View File

@ -6,18 +6,19 @@
#include "../inc/server.h"
#define ZGB_DATA_SIZE 36
//extern int zgbfd;
// #define ZGB_NWK_ID 0x02
// extern int zgbfd;
extern char *p_shm;
extern char cmd_buf[1];
extern float value[8];
//m0的环境变量
struct env_char{
//char smog;
// m0的环境变量
struct env_char
{
// char smog;
char led_one;
char led_two;
char fan;
//char buzz;
// char buzz;
char h_tem;
char l_tem;
char h_hum;
@ -32,8 +33,8 @@ struct env_char env_char_data;
//读取共享内存数据
void read_cmd()
{
read_shm(p_shm+11,cmd_buf,1);
printf("cmd_buf[0] = %d\r\n",cmd_buf[0]);
read_shm(p_shm + 11, cmd_buf, 1);
// printf("cmd_buf[0] = %d\r\n", cmd_buf[0]);
}
/*void read_secure()
@ -42,40 +43,40 @@ void read_cmd()
printf("p_shm = %.2f\r\n",p_shm[12]);
}*/
//zigbee初始化
// zigbee初始化
int zigbee_init(char *devpath, int baudrate)
{
return serial_init(devpath);
}
//zigbee采集数据
// zigbee采集数据
int zigbee_get_dat(int fd)
{
int i = 0;
ssize_t ret;
unsigned char buf[ZGB_DATA_SIZE];
memset(buf, 0, sizeof(buf));
//fprintf(stdout,"hi\n");
// fprintf(stdout,"tip\n");
ret = serial_recv_exact_nbytes(fd, buf, sizeof(buf));
//fprintf(stdout,"hi1\n");
// fprintf(stdout,"tips\n");
if (ret == sizeof(buf))
{
if (buf[0] == 0xBB)
{
memset(&data, 0, sizeof(struct env));
data.id = (int)buf[1];
data.tem = (float)((buf[5]*10 + buf[4])/10) ;
data.hum = (float)((buf[7]*10 + buf[6])/10) ;
//data.smog = (int)buf[16];
data.tem = (float)((buf[5] * 10 + buf[4]) / 10);
data.hum = (float)((buf[7] * 10 + buf[6]) / 10);
// data.smog = (int)buf[16];
data.light = (int)((buf[23] << 24) + (buf[22] << 16) + (buf[21] << 8) + buf[20]);
//printf("smog = %d\r\n",data.smog);
// printf("smog = %d\r\n",data.smog);
env_char_data.l_tem = buf[4];
env_char_data.h_tem = buf[5];
env_char_data.l_hum = buf[6];
env_char_data.h_hum = buf[7];
//env_char_data.smog = buf[16]; //烟雾浓度
//printf("smog = %d\r\n",(int)buf[16]);
// env_char_data.smog = buf[16]; //烟雾浓度
// printf("smog = %d\r\n",(int)buf[16]);
env_char_data.first_light = buf[20];
env_char_data.second_light = buf[21];
env_char_data.third_light = buf[22];
@ -83,102 +84,123 @@ int zigbee_get_dat(int fd)
data.led = buf[24];
data.fan = buf[25];
//data.buzz = buf[26];
// data.buzz = buf[26];
env_char_data.led_one = buf[24];
env_char_data.fan = buf[25];
//env_char_data.buzz = buf[26];
// env_char_data.buzz = buf[26];
env_char_data.led_two = buf[27];
}
}
return ret;
}
//zigbee发送命令
// zigbee发送命令
int zigbee_exe_cmd(int fd, unsigned char *p)
{
unsigned char buf[ZGB_DATA_SIZE] = {0xdd, 0x06, 0x24, 0x00, 0x00};
if (strstr(p, "LIGHT_ON") != NULL){
unsigned char buf[ZGB_DATA_SIZE] = {0xdd, data.id, 0x24, 0x00, 0x00};
if (strstr(p, "LIGHT_ON") != NULL)
{
buf[4] = 0x00;
} else if (strstr(p, "LIGHT_OFF") != NULL){
}
else if (strstr(p, "LIGHT_OFF") != NULL)
{
buf[4] = 0x01;
} else if (strstr(p, "BUZZ_ON") != NULL){
}
else if (strstr(p, "BUZZ_ON") != NULL)
{
buf[4] = 0x02;
} else if (strstr(p, "BUZZ_OFF") != NULL){
}
else if (strstr(p, "BUZZ_OFF") != NULL)
{
buf[4] = 0x03;
} else if (strstr(p, "FAN_ON") != NULL){
}
else if (strstr(p, "FAN_ON") != NULL)
{
buf[4] = 0x04;
} else if (strstr(p, "FAN_OFF") != NULL){
}
else if (strstr(p, "FAN_OFF") != NULL)
{
buf[4] = 0x08;
} else if (strstr(p, "SHU_ON") != NULL){
}
else if (strstr(p, "SHU_ON") != NULL)
{
buf[4] = 0x09;
} else if (strstr(p, "SHU_OFF") != NULL){
}
else if (strstr(p, "SHU_OFF") != NULL)
{
buf[4] = 0x0a;
}
int ret = serial_send_exact_nbytes(fd, buf, sizeof(buf));
return ret;
}
//AP发送给m0命令
//发送给m0命令
void send_cmd_m0(int signum)
{
read_cmd();
if(cmd_buf[0] == 1)
if (cmd_buf[0] == 1)
{
printf("Living now:ON = %d\r\n",cmd_buf[0]);
zigbee_exe_cmd(zgbfd,"LIGHT_ON"); //led1
printf("光照灯:ON = %d\r\n", cmd_buf[0]);
zigbee_exe_cmd(zgbfd, "LIGHT_ON"); // led1
}
else if(cmd_buf[0] == 2)
else if (cmd_buf[0] == 2)
{
printf("Living now:OFF = %d\r\n",cmd_buf[0]);
zigbee_exe_cmd(zgbfd,"LIGHT_OFF"); //led1
printf("光照灯:OFF = %d\r\n", cmd_buf[0]);
zigbee_exe_cmd(zgbfd, "LIGHT_OFF"); // led1
}
else if(cmd_buf[0] == 3)
else if (cmd_buf[0] == 3)
{
printf("Bedroom now:ON = %d\r\n",cmd_buf[0]);
zigbee_exe_cmd(zgbfd,"SHU_ON"); //led2
printf("数码管:ON = %d\r\n", cmd_buf[0]);
zigbee_exe_cmd(zgbfd, "SHU_ON"); //数码管
}
else if(cmd_buf[0] == 4)
else if (cmd_buf[0] == 4)
{
printf("Bedroom now:OFF = %d\r\n",cmd_buf[0]);
zigbee_exe_cmd(zgbfd,"SHU_OFF"); //led2
printf("数码管:OFF = %d\r\n", cmd_buf[0]);
zigbee_exe_cmd(zgbfd, "SHU_OFF"); //数码管
}
else if(cmd_buf[0] == 5)
else if (cmd_buf[0] == 5)
{
printf("Aircondition now:ON = %d\r\n",cmd_buf[0]);
zigbee_exe_cmd(zgbfd,"FAN_ON"); //fan
printf("风扇:ON = %d\r\n", cmd_buf[0]);
zigbee_exe_cmd(zgbfd, "FAN_ON"); // fan
}
else if(cmd_buf[0] == 6)
else if (cmd_buf[0] == 6)
{
printf("Aircondition now:OFF%d\r\n",cmd_buf[0]);
zigbee_exe_cmd(zgbfd,"FAN_OFF"); //fan
printf("Aircondition now:OFF%d\r\n",cmd_buf[0]);
zigbee_exe_cmd(zgbfd, "FAN_OFF"); // fan
printf("风扇:OFF=%d\r\n", cmd_buf[0]);
}
else if (cmd_buf[0] == 7)
{
zigbee_exe_cmd(zgbfd, "BUZZ_ON"); // BUZZ
printf("蜂鸣器:ON=%d\r\n", cmd_buf[0]);
}
else if (cmd_buf[0] == 8)
{
zigbee_exe_cmd(zgbfd, "BUZZ_OFF"); // BUZZ
printf("蜂鸣器:OFF=%d\r\n", cmd_buf[0]);
}
}
/*void send_alarm_m0(int signo)
/* void send_alarm_m0(int signo)
{
read_secure();
printf("data_tem = %f\r\n",data.tem);
printf("value[1] = %.2f\r\n",value[1]);
printf("value[0] = %.2f\r\n",value[0]);
if(data.tem < value[0] || data.tem > value[1] || data.hum < value[2] || data.hum > value[3] || data.light < value[4] || data.light > value[5])
zigbee_exe_cmd(zgbfd,"BUZZ_ON");
printf("data_tem = %f\r\n", data.tem);
printf("value[1] = %.2f\r\n", value[1]);
printf("value[0] = %.2f\r\n", value[0]);
if (data.tem < value[0] || data.tem > value[1] || data.hum < value[2] || data.hum > value[3] || data.light < value[4] || data.light > value[5])
zigbee_exe_cmd(zgbfd, "BUZZ_ON");
else
zigbee_exe_cmd(zgbfd,"BUZZ_OFF");
}*/
//zigbee退出
zigbee_exe_cmd(zgbfd, "BUZZ_OFF");
}
*/
// zigbee退出
int zigbee_exit(int fd)
{
//处理申请的内存等
return serial_exit(fd);
}

View File

@ -203,7 +203,7 @@ int serial_Set(int fd,int speed,int flow_ctrl,int databits,int stopbits,int pari
int serial_init(char *devpath)
{
printf("串口设备地址:%s\n",devpath);
// printf("串口设备地址:%s\n",devpath);
int fd_comport = FALSE;
//打开串口
if((fd_comport=serial_open(devpath))<0)
@ -228,14 +228,14 @@ ssize_t serial_recv_exact_nbytes(int fd, void *buf, size_t count)
assert(buf != NULL);
while (total != count) {
fprintf(stdout,"%d\n",fd);
fprintf(stdout,"hi..\n");
// fprintf(stdout,"%d\n",fd);
// fprintf(stdout,"hi..\n");
ret = read(fd, buf + total, count - total);
/*int i = 0;
for (i = 0; i < 36; i++){
printf("%.2x ", buf1[i]);
}*/
fprintf(stdout,"hi2\n");
// fprintf(stdout,"hi2\n");
if (ret == -1)
{
perror("serial->recv");
@ -259,6 +259,7 @@ ssize_t serial_send_exact_nbytes(int fd, unsigned char *buf, size_t count)
ssize_t total = 0;
assert(buf != NULL);
//循环打印一下
//int i = 0;
/*for (i = 0; i < 36; i++){
printf("%.2x ", buf[i]);

View File

@ -1,4 +1,3 @@
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
@ -30,23 +29,23 @@ char get_history_data[72][25];
float value[8] = {0};
void read_env(int signo)
{
read_shm(p_shm,env_buf,sizeof(env_char_data));
read_shm(p_shm, env_buf, sizeof(env_char_data));
}
int service_process()
{
int i = 0;
char led1,led2,fan;
int socketId,connfd = 0;
char led1, led2, fan , buzz_l;
int socketId, connfd = 0;
int ret = 0;
int recv_len = 0;
struct sockaddr_in serveraddr,clientaddr;
socklen_t server_len,client_len;
struct sockaddr_in serveraddr, clientaddr;
socklen_t server_len, client_len;
char *buf_ope = NULL;
char *s = "//";
char cmd[BUFFER_SIZE] = {0};
pid_t pid,pid_zigbee;
pid_t pid, pid_zigbee;
int signo = 0;
char *pPath = NULL;
@ -56,14 +55,14 @@ int service_process()
char tabname2[] = "max_data";
//获取pPath
pPath = getPath(dbName);
//open or create db
// open or create db
pdb = SqlOpen(pPath);
SqlCreatTable(pdb,tabname1);
SqlCreatTable1(pdb,tabname2);
SqlCreatTable(pdb, tabname1);
SqlCreatTable1(pdb, tabname2);
//创建zigbee进程
pid_zigbee = fork();
if(pid_zigbee < 0)
if (pid_zigbee < 0)
{
perror("zigbee process fail!");
return -1;
@ -72,37 +71,41 @@ int service_process()
{
int i = 0;
char buf[1] = {'\0'};
AA: zgbfd = serial_init("/dev/ttyUSB0");
//等待打开串口设备
AA:
zgbfd = serial_init("/dev/ttyUSB0");
if (zgbfd == -1)
{
sleep(1);
sleep(2);
goto AA;
}
else
fprintf(stdout, "init zigbee success\n");
//创建共享内存
//创建共享内存(ipcs -m ,ipcrm -m shmid ,共享内存查看管理 )
p_shm = create_shm();
while(1)
while (1)
{
//send_alarm_m0(signo);
// send_alarm_m0(signo);
send_cmd_m0(signo);
ret = zigbee_get_dat(zgbfd);
if(ret < 0)
if (ret < 0)
{
perror("env_recv:");
}
SqlInsert(pdb,tabname1,data.tem,data.hum,data.light,0);
//sqlSelected(tabname1,pdb);
SqlInsert(pdb, tabname1, data.tem, data.hum, data.light, 0);
// sqlSelected(tabname1,pdb);
//写入共享内存
write_shm(p_shm,&env_char_data,sizeof(env_char_data));
signal(SIGUSR2,read_env);
sleep(2);
write_shm(p_shm, &env_char_data, sizeof(env_char_data));
//进程间通信信号
signal(SIGUSR2, read_env);
sleep(1);
}
}
//建立socket连接
socketId = socket(AF_INET,SOCK_STREAM,0);
if(socketId < 0)
socketId = socket(AF_INET, SOCK_STREAM, 0);
if (socketId < 0)
{
perror("create socket error");
return -1;
@ -111,14 +114,14 @@ int service_process()
//设置sockaddr_in结构体的相关参数
server_len = sizeof(struct sockaddr_in);
memset(&serveraddr,0,server_len);
memset(&serveraddr, 0, server_len);
serveraddr.sin_family = AF_INET;
serveraddr.sin_port = htons(SPORT);
serveraddr.sin_addr.s_addr = INADDR_ANY;
//绑定
ret = bind(socketId,(struct sockaddr *)&serveraddr,server_len);
if(ret < 0)
ret = bind(socketId, (struct sockaddr *)&serveraddr, server_len);
if (ret < 0)
{
perror("bind error");
return -1;
@ -126,8 +129,8 @@ int service_process()
printf("bind succeed!\r\n");
//建立监听队列
ret = listen(socketId,LISNUM);
if(ret < 0)
ret = listen(socketId, LISNUM);
if (ret < 0)
{
perror("listen error");
return -1;
@ -136,160 +139,187 @@ int service_process()
//等待客户端的连接(并发服务器)
client_len = sizeof(clientaddr);
memset(&clientaddr,0,client_len);
signal(SIGCHLD,SIG_IGN);
while(1)
memset(&clientaddr, 0, client_len);
signal(SIGCHLD, SIG_IGN);
while (1)
{
connfd = accept(socketId,(struct sockaddr *)&clientaddr,&client_len);
if(connfd < 0)
connfd = accept(socketId, (struct sockaddr *)&clientaddr, &client_len);
if (connfd < 0)
{
perror("connected error");
return -1;
}
printf("connected succeed!\r\n");
//通信
pid = fork();
if(pid < 0)
if (pid < 0)
{
perror("create process error");
return -1;
}
if(pid == 0)
if (pid == 0)
{
recv_len = recv(connfd,cmd,BUFFER_SIZE,0);
while(recv_len > 0)
recv_len = recv(connfd, cmd, BUFFER_SIZE, 0);
while (recv_len > 0)
{
printf("套接字数据:%s\n", cmd);
//查询历史数据
if(0 == strncmp(cmd,"SearchHistoryData",17))
if (0 == strncmp(cmd, "SearchHistoryData", 17))
{
//p_shm = create_shm();
//read_env(signo);
//send(connfd,env_buf,sizeof(env_buf),0);
printf("cmd = %s\r\n",cmd);
for(i = 0; i < 11; i++)
// p_shm = create_shm();
// read_env(signo);
// send(connfd,env_buf,sizeof(env_buf),0);
// printf("cmd = %s\r\n", cmd);
for (i = 0; i < 11; i++)
{
printf("buf = %d\r\n",env_buf[i]);
printf("buf = %d\r\n", env_buf[i]);
}
}
//设置安全阈值
else if(0 == strncmp(cmd,"SetSecureValue:",15))
else if (0 == strncmp(cmd, "SetSecureValue:", 15))
{
//p_shm = create_shm();
buf_ope = strtok(cmd+15,s);
while(buf_ope != NULL)
// p_shm = create_shm();
buf_ope = strtok(cmd + 15, s);
while (buf_ope != NULL)
{
value[i] = atof(buf_ope);
printf("value = %.2f\r\n",value[i]);
printf("value = %.2f\r\n", value[i]);
i++;
buf_ope = strtok(NULL,s);
buf_ope = strtok(NULL, s);
}
/*write_shm(p_shm,value,sizeof(value)/sizeof(value[0]));
signal(SIGUSR1,send_alarm_m0);
printf("value[1] = %.2f\r\n",value[1]);
printf("p_shm[1] = %.2f\r\n",p_shm[1]);*/
//将阈值插入到数据库
SqlInsert1(pdb,tabname2,*value,*(value+1),*(value+2),*(value+3),*(value+4),*(value+5),*(value+6),*(value+7));
//sqlSelected(tabname2,pdb);
SqlInsert1(pdb, tabname2, *value, *(value + 1), *(value + 2), *(value + 3), *(value + 4), *(value + 5), *(value + 6), *(value + 7));
// sqlSelected(tabname2,pdb);
}
//解析到是主界面
else if(strncmp(cmd,"ThisIsWidget",12))
else if (0 == strncmp(cmd, "ThisIsWidget", 12))
{
p_shm = create_shm();
read_env(signo);
send(connfd,env_buf,sizeof(env_buf),0);
printf("cmd = %s\r\n",cmd);
for(i = 0; i < 11; i++)
printf("buf = %d\r\n",env_buf[i]);
send(connfd, env_buf, sizeof(env_buf), 0);
printf("主界面刷新\r\n");
// for (i = 0; i < 11; i++)
// printf("buf = %d\r\n", env_buf[i]);
}
//解析客厅灯
else if(0 == strncmp(cmd,"Livingroom:ON",13))
//解析光照灯
else if (0 == strncmp(cmd, "Lamp:ON\n", 8))
{
printf("cmd = %s\r\n",cmd);
memset(cmd,0,sizeof(cmd));
strncpy(cmd,"Livingroom:open",15);
send(connfd,cmd,sizeof(cmd),0);
// printf("lyq = %s\n", cmd);
memset(cmd, 0, sizeof(cmd));
strncpy(cmd, "Lamp:open", 10);
// printf("cmdlyq: %s\r\n", cmd);
// lyq send(connfd, cmd, sizeof(cmd), 0);
led1 = 1;
write_shm(p_shm+11,&led1,1);
printf("p_shm = %d\r\n",p_shm[11]);
signal(SIGUSR1,send_cmd_m0);
write_shm(p_shm + 11, &led1, 1);
printf("p_shm:\n %d\r\n", p_shm[11]);
signal(SIGUSR1, send_cmd_m0);
}
else if(0 == strncmp(cmd,"Livingroom:OFF",14))
else if (0 == strncmp(cmd, "Lamp:OFF\n", 9))
{
p_shm = create_shm();
printf("cmd = %s\r\n",cmd);
memset(cmd,0,sizeof(cmd));
strncpy(cmd,"Livingroom:close",16);
send(connfd,cmd,sizeof(cmd),0);
// p_shm = create_shm();
// printf("cmd = %s\r\n", cmd);
memset(cmd, 0, sizeof(cmd));
strncpy(cmd, "Lamp:close\n", 16);
// lyq send(connfd, cmd, sizeof(cmd), 0);
led1 = 2;
write_shm(p_shm+11,&led1,1);
printf("p_shm = %d\r\n",p_shm[11]);
signal(SIGUSR1,send_cmd_m0);
write_shm(p_shm + 11, &led1, 1);
printf("p_shm = %d\r\n", p_shm[11]);
signal(SIGUSR1, send_cmd_m0);
}
//解析卧室灯
else if(0 == strncmp(cmd,"Bedroom:ON",10))
//解析温控灯
else if (0 == strncmp(cmd, "TemCtl:ON\n", 11))
{
p_shm = create_shm();
printf("cmd = %s\r\n",cmd);
memset(cmd,0,sizeof(cmd));
strncpy(cmd,"Bedroom:open",10);
send(connfd,cmd,sizeof(cmd),0);
// p_shm = create_shm();
// printf("cmd = %s\r\n", cmd);
memset(cmd, 0, sizeof(cmd));
strncpy(cmd, "TemCtl:open", 12);
// lyq send(connfd, cmd, sizeof(cmd), 0);
led2 = 3;
write_shm(p_shm+11,&led2,1);
printf("p_shm = %d\r\n",p_shm[11]);
signal(SIGUSR1,send_cmd_m0);
write_shm(p_shm + 11, &led2, 1);
printf("p_shm = %d\r\n", p_shm[11]);
signal(SIGUSR1, send_cmd_m0);
}
else if(0 == strncmp(cmd,"Bedroom:OFF",11))
else if (0 == strncmp(cmd, "TemCtl:OFF\n", 12))
{
p_shm = create_shm();
printf("cmd = %s\r\n",cmd);
memset(cmd,0,sizeof(cmd));
strncpy(cmd,"Bedroom:close",13);
send(connfd,cmd,sizeof(cmd),0);
// p_shm = create_shm();
// printf("cmd = %s\r\n", cmd);
memset(cmd, 0, sizeof(cmd));
strncpy(cmd, "Bedroom:close", 13);
// lyq send(connfd, cmd, sizeof(cmd), 0);
led2 = 4;
write_shm(p_shm+11,&led2,1);
printf("p_shm = %d\r\n",p_shm[11]);
signal(SIGUSR1,send_cmd_m0);
write_shm(p_shm + 11, &led2, 1);
printf("p_shm = %d\r\n", p_shm[11]);
signal(SIGUSR1, send_cmd_m0);
}
//解析空调
else if(0 == strncmp(cmd,"Aircondition:ON",15))
//解析风扇
else if (0 == strncmp(cmd, "Fan:ON\n", 8))
{
p_shm = create_shm();
printf("cmd = %s\r\n",cmd);
memset(cmd,0,sizeof(cmd));
strncpy(cmd,"Aircondition:open",17);
send(connfd,cmd,sizeof(cmd),0);
// p_shm = create_shm();
// printf("cmd = %s\r\n", cmd);
memset(cmd, 0, sizeof(cmd));
strncpy(cmd, "Fan:open", 9);
// lyq send(connfd, cmd, sizeof(cmd), 0);
fan = 5;
write_shm(p_shm+11,&fan,1);
printf("p_shm = %d\r\n",p_shm[11]);
signal(SIGUSR1,send_cmd_m0);
write_shm(p_shm + 11, &fan, 1);
printf("p_shm = %d\r\n", p_shm[11]);
signal(SIGUSR1, send_cmd_m0);
}
else if(0 == strncmp(cmd,"Aircondition:OFF",16))
else if (0 == strncmp(cmd, "Fan:OFF\n", 9))
{
p_shm = create_shm();
printf("cmd = %s\r\n",cmd);
memset(cmd,0,sizeof(cmd));
strncpy(cmd,"Aircondition:close",18);
send(connfd,cmd,sizeof(cmd),0);
// p_shm = create_shm();
// printf("cmd = %s\r\n", cmd);
memset(cmd, 0, sizeof(cmd));
strncpy(cmd, "Fan:close", 10);
// lyq send(connfd, cmd, sizeof(cmd), 0);
fan = 6;
write_shm(p_shm+11,&fan,1);
printf("p_shm = %d\r\n",p_shm[11]);
signal(SIGUSR1,send_cmd_m0);
write_shm(p_shm + 11, &fan, 1);
printf("p_shm = %d\r\n", p_shm[11]);
signal(SIGUSR1, send_cmd_m0);
}
recv_len = recv(connfd,cmd,BUFFER_SIZE,0);
//解析buzz
else if (0 == strncmp(cmd, "BUZZ:ON\n", 9))
{
// p_shm = create_shm();
// printf("cmd = %s\r\n", cmd);
memset(cmd, 0, sizeof(cmd));
strncpy(cmd, "BUZZ:open", 9);
// lyq send(connfd, cmd, sizeof(cmd), 0);
buzz_l = 7;
write_shm(p_shm + 11, &buzz_l, 1);
printf("p_shm = %d\r\n", p_shm[11]);
signal(SIGUSR1, send_cmd_m0);
}
else if (0 == strncmp(cmd, "BUZZ:OFF\n", 10))
{
// p_shm = create_shm();
// printf("cmd = %s\r\n", cmd);
memset(cmd, 0, sizeof(cmd));
strncpy(cmd, "BUZZ:close", 10);
// lyq send(connfd, cmd, sizeof(cmd), 0);
buzz_l = 8;
write_shm(p_shm + 11, &buzz_l, 1);
printf("p_shm = %d\r\n", p_shm[11]);
signal(SIGUSR1, send_cmd_m0);
}
memset(cmd, 0, sizeof(cmd));
recv_len = recv(connfd, cmd, BUFFER_SIZE, 0);
}
}
//关闭连接
// delete_shm(p_shm);
close(connfd);
}