系统主控程序(包含了进程间通信处理线程)
main.c
#include <stdlib.h>
#include <stdio.h>
#include <pthread.h>
#include "sys_ipc.h"
#include "config.h"
#include "net_pro.h"
#include "com_pro.h"
struct st_sys g_dev[1]; //系统配置结构体全局变量
int g_net_port;//网络端口
int init_sys(void)
{
printf("init system struct,LED flash.\n");
load_dev(g_dev);
}
//进程间通信处理
void* ipcs_pro(void* arg)
{
int i,msgid_menu,msgid_web;
struct st_sys* shm_dev;
printf("temp control pthread start...\n");
if((msgid_menu=get_msgid_menu()) < 0){
printf("msg_menu error\n");
exit(1);
}
if((msgid_web=get_msgid_web()) < 0){
printf("msg_web error\n");
exit(1);
}
if((shm_dev=(struct st_sys*)set_web_shm())==NULL){
printf("shm_web error\n");
exit(1);
}
while(1){
msg_menu_update(msgid_menu,g_dev);
if(msg_recv_webreq(msgid_web)>0){
//update shm
for(i=0;i<DEF_MAX_CHANNEL;i++){
shm_dev->temp_max[i] = g_dev->temp_max[i];
shm_dev->temp_data[i] = g_dev->temp_data[i];
shm_dev->status[i] = g_dev->status[i];
}
shm_dev->update_time = g_dev->update_time;
}
//msg_send_webupdate(msgid_web,g_dev);
sleep(2);
}
}
int main(int argc,char* argv[])
{
pthread_t pth_ipc,pth_com,pth_net;
//set net port
if(argc < 2){
g_net_port = DEF_PORT_8848;
printf("sys default net port=[8848]\n");
}else{
g_net_port = atoi(argv[1]);
}
init_sys();
//创建系统各功能线程
pthread_create(&pth_ipc,NULL,ipcs_pro,NULL);
pthread_create(&pth_com,NULL,com1_pro,NULL);
pthread_create(&pth_net,NULL,net_pro,NULL);
pthread_join(pth_ipc,NULL);
pthread_join(pth_net,NULL);
pthread_join(pth_com,NULL);
}