LED
#include "data_global.h"
#include "chrdev.h"
#include <unistd.h>
extern pthread_mutex_t mutex_led;
extern pthread_cond_t cond_led;
//:A9LED模块线程.
void* pthread_led(void* arg)
{
printf("pthread_led\n");
int i, j;
int led_fd;
led_desc_t led;
led_fd = open(LED_DEV, O_RDWR);//打开设备节点
if (led_fd == -1)
{
printf("open failed.\n");
}
printf("led_fd ;%d.\n", led_fd);
while (1)
{
pthread_mutex_lock(&mutex_led);
pthread_cond_wait(&cond_led, &mutex_led);
printf("led ioctl:***********\n");
if (cmd_led == 0x41)
{
for (j = 0;j < 1;j++)
{
for (i = 2;i < 6;i++)
{
led.which = i;
ioctl(led_fd, FSLEDON, &led);
usleep(500000);
led.which = i;
ioctl(led_fd, FSLEDOFF, &led);
usleep(500000);
}
}
}
pthread_mutex_unlock(&mutex_led);
}
close(led_fd);
}
#include "data_global.h"
extern int msgid;
extern key_t key;
extern pthread_mutex_t mutex_client_request,
mutex_refresh,
mutex_sqlite,
mutex_transfer,
mutex_analysis,
mutex_sms,
mutex_buzzer,
mutex_led,
mutex_camera;
extern pthread_cond_t cond_client_request,
cond_refresh,
cond_sqlite,
cond_transfer,
cond_analysis,
cond_sms,
cond_buzzer,
cond_led,
cond_camera;
extern unsigned char cmd_led;
extern char recive_phone[12];
extern char center_phone[12];
struct msg msgbuf;
void* pthread_client_request(void* arg)
{
if ((key = ftok("/tmp", 'g')) < 0)
{
perror("ftok failed .\n");
exit(-1);
}
msgid = msgget(key, IPC_CREAT | IPC_EXCL | 0666);
if (msgid == -1)
{
if (errno == EEXIST)
{
msgid = msgget(key, 0777);
}
else
{
perror("fail to msgget");
exit(1);
}
}
printf("pthread_client_request\n");
while (1)
{
bzero(&msgbuf, sizeof(msgbuf));
printf("wait form client request...\n");
msgrcv(msgid, &msgbuf, sizeof(msgbuf) - sizeof(long), 1L, 0);
printf("Get %ldL msg\n", msgbuf.msgtype);
printf("text[0] = %#x\n", msgbuf.text[0]);
switch (msgbuf.msgtype)
{
case 1L:
pthread_mutex_lock(&mutex_led);
printf("hello led\n");
cmd_led = msgbuf.text[0];//将命令赋值给led条件变量
pthread_mutex_unlock(&mutex_led); //解锁
pthread_cond_signal(&cond_led);//通知led线程
break;
case 2L:
printf("hello beep\n");
break;
case 3L:
printf("hello seg\n");
break;
case 4L:
printf("hello fan\n");
break;
case 5L:
printf("set env data\n");
printf("temMAX: %d\n", *((int*)&msgbuf.text[1]));
printf("temMIN: %d\n", *((int*)&msgbuf.text[5]));
printf("humMAX: %d\n", *((int*)&msgbuf.text