595 lines
14 KiB
C
595 lines
14 KiB
C
#include <stdio.h>
|
|
#include <sys/types.h>
|
|
#include <sys/ipc.h>
|
|
#include <sys/msg.h>
|
|
#include <string.h>
|
|
#include <unistd.h>
|
|
#include <stdlib.h>
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
#include <errno.h>
|
|
#include <sys/msg.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <unistd.h>
|
|
#include <sys/types.h>
|
|
#include <sys/stat.h>
|
|
#include <fcntl.h>
|
|
#include <termios.h>
|
|
#include <errno.h>
|
|
#include <math.h>
|
|
#include <pthread.h>
|
|
#include <semaphore.h>
|
|
#include <string.h>
|
|
#include <unistd.h>
|
|
#include <sys/prctl.h>
|
|
|
|
#include "../inc/main.h"
|
|
#include "../inc/msg.h"
|
|
#include "../inc/isys_config.h"
|
|
#include "../inc/iweb_task.h"
|
|
#include "../inc/os_task.h"
|
|
#include "../inc/iuart_user.h"
|
|
#include "../inc/http_get.h"
|
|
#include "../inc/upgrade.h"
|
|
#include "../inc/isys_com.h"
|
|
|
|
|
|
|
|
//extern void http_save_sys_para(S_CGI_SYS_PARA_T *ppara);
|
|
//extern void lcd_save_web_sys_para(MSG* pmsg);
|
|
extern void uart_remote(MSG *pmsg);
|
|
extern void uart_hw_init(void);
|
|
extern void uart_hw_deinit(void);
|
|
extern void udp_imgp_reinit(MSG *pmsg);
|
|
|
|
extern void rs232_uart_hw_init(void);
|
|
extern void rs232_uart_hw_deinit(void);
|
|
|
|
|
|
#if 1//@CONFIRMED
|
|
int sys_msg_send(MSG *p_msg, key_t keyid)
|
|
{
|
|
|
|
struct msg_st data;
|
|
|
|
int msgid = -1;
|
|
|
|
// creat msg queue
|
|
msgid = msgget((key_t)keyid, 0666 | IPC_CREAT);
|
|
if(msgid == -1) {
|
|
fprintf(stderr, "msgget failed with error: %d, keyid=%d\n", errno,keyid);
|
|
return -1;
|
|
}
|
|
|
|
switch (keyid)
|
|
{
|
|
case WEB_MSG_KEY_ID:
|
|
data.mtype = MSGQ_TYPE_WEB;
|
|
break;
|
|
case LCD_MSG_KEY_ID:
|
|
data.mtype = MSGQ_TYPE_LCD;
|
|
break;
|
|
case UART_MSG_KEY_ID:
|
|
data.mtype = MSGQ_TYPE_UART;
|
|
break;
|
|
case TSOIP_MSG_KEY_ID:
|
|
data.mtype = MSGQ_TYPE_TSOIP;
|
|
break;
|
|
case LOG_MSG_KEY_ID:
|
|
data.mtype = MSGQ_TYPE_LOG;
|
|
break;
|
|
case GPS_UART_MSG_KEY_ID:
|
|
data.mtype = MSGQ_TYPE_GPS_UART;
|
|
break;
|
|
//....
|
|
//add hear
|
|
//....
|
|
default:
|
|
data.mtype = MSGQ_TYPE_ALL;
|
|
break;
|
|
}
|
|
memcpy(&data.msg, p_msg, sizeof(MSG));
|
|
|
|
// send msg
|
|
if(msgsnd(msgid, (void*)&data, MAX_TEXT, 0) == -1) {
|
|
fprintf(stderr, "a-msgsnd failed, errno=%d, keyid=%d, msgid=%d\n",errno,keyid,msgid);
|
|
return -1;
|
|
}
|
|
|
|
//printf("send type=%d, rpdata= 0x%x ,lpara=0x%lx\n", p_msg->type , p_msg->rPara, p_msg->lPara);
|
|
return 0;
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
#if DEF_NEED_TO_EN //@NEED_TO_EN
|
|
|
|
static void * log_msg_recv_thr(void * args)
|
|
{
|
|
int running = 1;
|
|
int msgid = -1;
|
|
struct msg_st data;
|
|
long int msgtype = MSGQ_TYPE_LOG; //注意1
|
|
|
|
//建立消息队列
|
|
msgid = msgget((key_t)LOG_MSG_KEY_ID, 0666 | IPC_CREAT);
|
|
if(msgid == -1) {
|
|
fprintf(stderr, "msgget failed with error: %d\n", errno);
|
|
goto TSOIP_MSG_RECV_ERR_EXIT;
|
|
}
|
|
|
|
//从队列中获取消息
|
|
while(running) {
|
|
if(msgrcv(msgid, (void*)&data, BUFSIZ, msgtype, 0) == -1) {
|
|
fprintf(stderr, "msgrcv failed with errno: %d\n", errno);
|
|
goto TSOIP_MSG_RECV_ERR_EXIT;
|
|
}
|
|
|
|
//printf("[LOG MSG recv ]getmsg: data.msg_type=%ld , data.msg.type=%u\n",data.mtype, data.msg.type);
|
|
|
|
switch(data.msg.type)
|
|
{
|
|
case MSG_LOG:
|
|
|
|
break;
|
|
|
|
case MSG_LOG_RECORD_RESET:
|
|
|
|
break;
|
|
}
|
|
usleep(50000);
|
|
}
|
|
|
|
|
|
TSOIP_MSG_RECV_ERR_EXIT:
|
|
|
|
//删除消息队列
|
|
if(msgctl(msgid, IPC_RMID, 0) == -1) {
|
|
fprintf(stderr, "msgctl(IPC_RMID) failed\n");
|
|
}
|
|
return (void*)NULL;
|
|
}
|
|
#endif//DEF_NEED_TO_EN
|
|
#if 1
|
|
static void * tsoip_msg_recv_thr(void * args)
|
|
{
|
|
int running = 1;
|
|
int msgid = -1;
|
|
struct msg_st data;
|
|
long int msgtype = MSGQ_TYPE_TSOIP; //注意1
|
|
|
|
log_printf(LOG_DEBUG,I_NOUSED,"[.thr.] tsoip_msg_recv_thr Start.\n");
|
|
|
|
//建立消息队列
|
|
msgid = msgget((key_t)TSOIP_MSG_KEY_ID, 0666 | IPC_CREAT);
|
|
if(msgid == -1) {
|
|
fprintf(stderr, "msgget failed with error: %d\n", errno);
|
|
goto TSOIP_MSG_RECV_ERR_EXIT;
|
|
}
|
|
log_printf(LOG_DEBUG,I_NOUSED,"tsoip msg_id=%d\n",msgid);
|
|
|
|
//从队列中获取消息
|
|
while(running) {
|
|
|
|
if(get_upgrade_flg()){
|
|
usleep(1000000);
|
|
continue;
|
|
}
|
|
if(msgrcv(msgid, (void*)&data, BUFSIZ, msgtype, 0) == -1) {
|
|
fprintf(stderr, "msgrcv failed with errno: %d\n", errno);
|
|
goto TSOIP_MSG_RECV_ERR_EXIT;
|
|
}
|
|
|
|
//printf("[UART MSG recv ]getmsg: data.msg_type=%ld , data.msg.type=%u\n",data.mtype, data.msg.type);
|
|
switch(data.msg.type)
|
|
{
|
|
case MSG_IGMP_REINIT:
|
|
udp_imgp_reinit(&data.msg);
|
|
break;
|
|
}
|
|
|
|
// if(data.msg.need_free==MSG_NEED_FREE)
|
|
// free(&data.msg);
|
|
usleep(50000);
|
|
}
|
|
|
|
|
|
TSOIP_MSG_RECV_ERR_EXIT:
|
|
|
|
//删除消息队列
|
|
if(msgctl(msgid, IPC_RMID, 0) == -1) {
|
|
fprintf(stderr, "msgctl(IPC_RMID) failed\n");
|
|
}
|
|
return (void*)NULL;
|
|
}
|
|
#endif
|
|
|
|
#if 1
|
|
|
|
static void * uart_msg_recv_thr(void * args)
|
|
{
|
|
int running = 1;
|
|
int msgid = -1;
|
|
struct msg_st data;
|
|
long int msgtype = MSGQ_TYPE_UART; //注意1
|
|
|
|
log_printf(LOG_DEBUG,I_NOUSED,"[.thr.] uart_msg_recv_thr Start.\n");
|
|
|
|
//建立消息队列
|
|
msgid = msgget((key_t)UART_MSG_KEY_ID, 0666 | IPC_CREAT);
|
|
if(msgid == -1) {
|
|
fprintf(stderr, "msgget failed with error: %d\n", errno);
|
|
goto UART_MSG_RECV_ERR_EXIT;
|
|
}
|
|
log_printf(LOG_DEBUG,I_NOUSED,"u232 msg_id=%d\n",msgid);
|
|
|
|
//从队列中获取消息
|
|
while(running) {
|
|
|
|
if(get_upgrade_flg()){
|
|
usleep(1000000);
|
|
continue;
|
|
}
|
|
if(msgrcv(msgid, (void*)&data, BUFSIZ, msgtype, 0) == -1) {
|
|
fprintf(stderr, "msgrcv failed with errno: %d\n", errno);
|
|
goto UART_MSG_RECV_ERR_EXIT;
|
|
}
|
|
|
|
//printf("[UART MSG recv ]getmsg: data.msg_type=%ld , data.msg.type=%u\n",data.mtype, data.msg.type);
|
|
switch(data.msg.type)
|
|
{
|
|
case MSG_RS232:
|
|
uart_remote(&data.msg);
|
|
break;
|
|
case MSG_UART_RE_INIT:
|
|
uart_hw_deinit();
|
|
uart_hw_init();
|
|
rs232_uart_hw_init();
|
|
break;
|
|
|
|
}
|
|
|
|
usleep(1000);
|
|
}
|
|
|
|
|
|
UART_MSG_RECV_ERR_EXIT:
|
|
|
|
//删除消息队列
|
|
if(msgctl(msgid, IPC_RMID, 0) == -1) {
|
|
fprintf(stderr, "msgctl(IPC_RMID) failed\n");
|
|
}
|
|
|
|
return (void*)NULL;
|
|
}
|
|
|
|
extern void gps_uart_proc(MSG *pmsg);
|
|
extern void ublox_proc_state(void);
|
|
static void * gps_uart_msg_recv_thr(void * args)
|
|
{
|
|
int running = 1;
|
|
int msgid = -1;
|
|
struct msg_st data;
|
|
long int msgtype = MSGQ_TYPE_GPS_UART; //注意1
|
|
|
|
log_printf(LOG_DEBUG,I_NOUSED,"[.thr.] gps_uart_msg_recv_thr Start.\n");
|
|
|
|
//建立消息队列
|
|
msgid = msgget((key_t)GPS_UART_MSG_KEY_ID, 0666 | IPC_CREAT);
|
|
if(msgid == -1) {
|
|
log_printf(LOG_ERR,I_NOUSED,"msgget failed with error\n");
|
|
|
|
fprintf(stderr, "msgget failed with error: %d\n", errno);
|
|
goto GPS_UART_MSG_RECV_ERR_EXIT;
|
|
}
|
|
|
|
log_printf(LOG_DEBUG,I_NOUSED,"gps msg_id=%d\n",msgid);
|
|
|
|
//从队列中获取消息
|
|
while(running) {
|
|
if(msgrcv(msgid, (void*)&data, BUFSIZ, msgtype, 0) == -1) {
|
|
log_printf(LOG_ERR,I_NOUSED,"msgrcv failed with errno\n");
|
|
fprintf(stderr, "msgrcv failed with errno: %d\n", errno);
|
|
goto GPS_UART_MSG_RECV_ERR_EXIT;
|
|
}
|
|
|
|
//printf("[UART MSG recv ]getmsg: data.msg_type=%ld , data.msg.type=%u\n",data.mtype, data.msg.type);
|
|
switch(data.msg.type)
|
|
{
|
|
case MSG_RS232:
|
|
log_printf(LOG_DEBUG,I_NOUSED," gps_uart get MSG_RS232 id=%d\n",msgid);
|
|
gps_uart_proc(&data.msg);
|
|
break;
|
|
case MSG_SEC:
|
|
//printf(" gps_uart get MSG_SEC\n");
|
|
ublox_proc_state();
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
|
|
usleep(1000);
|
|
}
|
|
|
|
|
|
GPS_UART_MSG_RECV_ERR_EXIT:
|
|
|
|
//删除消息队列
|
|
if(msgctl(msgid, IPC_RMID, 0) == -1) {
|
|
fprintf(stderr, "msgctl(IPC_RMID) failed\n");
|
|
}
|
|
|
|
return (void*)NULL;
|
|
}
|
|
|
|
|
|
#endif
|
|
//@tmp
|
|
/*uint8 g_flg_load=0;
|
|
uint8 g_web_flg_load=0;
|
|
#include "../inc/dpd_proc.h"*/
|
|
|
|
static void * lcd_msg_recv_thr(void * args)
|
|
{
|
|
int running = 1;
|
|
int msgid = -1;
|
|
struct msg_st data;
|
|
long int msgtype = MSGQ_TYPE_LCD; //注意1
|
|
|
|
log_printf(LOG_DEBUG,I_NOUSED,"[.thr.] lcd_msg_recv_thr Start.\n");
|
|
|
|
//建立消息队列
|
|
msgid = msgget((key_t)LCD_MSG_KEY_ID, 0666 | IPC_CREAT);
|
|
if(msgid == -1) {
|
|
fprintf(stderr, "msgget failed with error: %d\n", errno);
|
|
goto LCD_MSG_RECV_ERR_EXIT;
|
|
}
|
|
log_printf(LOG_DEBUG,I_NOUSED,"lcd msg_id=%d\n",msgid);
|
|
|
|
//从队列中获取消息
|
|
while(running) {
|
|
|
|
if(get_upgrade_flg()){
|
|
usleep(2000000);
|
|
continue;
|
|
}
|
|
if(msgrcv(msgid, (void*)&data, BUFSIZ, msgtype, 0) == -1) {
|
|
fprintf(stderr, "msgrcv failed with errno: %d\n", errno);
|
|
log_printf(LOG_ERR,I_NOUSED,"msgrcv failed with errno: %d\n", errno);
|
|
goto LCD_MSG_RECV_ERR_EXIT;
|
|
}
|
|
|
|
//printf("[LCD MSG ]getmsg: data.msg_type=%ld , data.msg.type=%u\n",data.mtype, data.msg.type);
|
|
|
|
switch(data.msg.type)
|
|
{
|
|
case MSG_WEB_SAVE_PARA:
|
|
http_save_change_para(&data.msg);
|
|
break;
|
|
|
|
case MSG_PSTS_UPDATE:
|
|
#if USE_PSTS
|
|
psts_para_update(&atsc_para.psts_para);
|
|
#endif
|
|
break;
|
|
}
|
|
usleep(50000);
|
|
}
|
|
|
|
|
|
LCD_MSG_RECV_ERR_EXIT:
|
|
|
|
//删除消息队列
|
|
if(msgctl(msgid, IPC_RMID, 0) == -1) {
|
|
fprintf(stderr, "msgctl(IPC_RMID) failed\n");
|
|
}
|
|
|
|
return (void*)NULL;
|
|
}
|
|
|
|
|
|
static void * web_msg_recv_thr(void * args)
|
|
{
|
|
int running = 1;
|
|
int msgid = -1;
|
|
struct msg_st data;
|
|
long int msgtype = MSGQ_TYPE_WEB; //注意
|
|
|
|
log_printf(LOG_DEBUG,I_NOUSED,"[.thr.] web_msg_recv_thr Start.\n");
|
|
|
|
//建立消息队列
|
|
msgid = msgget((key_t)WEB_MSG_KEY_ID, 0666 | IPC_CREAT);
|
|
if(msgid == -1) {
|
|
fprintf(stderr, "msgget failed with error: %d\n", errno);
|
|
goto WEB_MSG_RECV_ERR_EXIT;
|
|
}
|
|
log_printf(LOG_DEBUG,I_NOUSED,"web msg_id=%d\n",msgid);
|
|
|
|
while(running) {
|
|
|
|
if(get_upgrade_flg()){
|
|
usleep(1000000);
|
|
continue;
|
|
}
|
|
|
|
// recv msg
|
|
if(msgrcv(msgid, (void*)&data, BUFSIZ, msgtype, 0) == -1) {
|
|
fprintf(stderr, "msgrcv failed with errno: %d\n", errno);
|
|
goto WEB_MSG_RECV_ERR_EXIT;
|
|
}
|
|
#if 0
|
|
printf("[web msg] getmsg: data.msg_type=%ld , data.msg.type=%u, %s lpara=0x%lx\n",
|
|
data.mtype,
|
|
data.msg.type,
|
|
(data.msg.need_free==MSG_NEED_FREE)?"needfree":" ",
|
|
data.msg.lPara);
|
|
#endif
|
|
|
|
|
|
#if 1//proc on lcd, NEED_TO_EN
|
|
http_save_change_para(&data.msg);
|
|
#endif
|
|
usleep(50000);
|
|
}
|
|
|
|
|
|
WEB_MSG_RECV_ERR_EXIT:
|
|
|
|
//删除消息队列
|
|
if(msgctl(msgid, IPC_RMID, 0) == -1) {
|
|
fprintf(stderr, "msgctl(IPC_RMID) failed\n");
|
|
}
|
|
|
|
return (void*)NULL;
|
|
}
|
|
|
|
|
|
int creat_web_msg_thread(void)
|
|
{
|
|
int ret = -1;
|
|
pthread_t web_msg_thr_id;
|
|
|
|
log_printf(LOG_DEBUG,I_NOUSED,"[.thr.]->-\n");
|
|
ret = pthread_create(&web_msg_thr_id, NULL, (void *)web_msg_recv_thr, NULL);
|
|
if(ret != 0) {
|
|
log_printf(LOG_ERR,I_NOUSED," creat thread err.\n");
|
|
return -1;
|
|
}
|
|
else{
|
|
log_printf(LOG_DEBUG,I_NOUSED," Ok. creat thread succeed.\n");
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
//@tmp
|
|
/*void send_msg_for_tst(){
|
|
static MSG msg;
|
|
MSG *pmsg;
|
|
|
|
pmsg = &msg;
|
|
|
|
pmsg->type = 0xff;//0xffMSG_WEB_SAVE_PARA
|
|
pmsg->wPara =0xff; // CGI_CTTB_WEB_SYSPARA
|
|
pmsg->lPara =0;
|
|
pmsg->need_free = MSG_NO_NEED_FREE;
|
|
printf("[%s,%d]\n",__FUNCTION__,__LINE__);
|
|
printf("send msg to LCd\n");
|
|
|
|
cttb_msg_send_to_lcd(pmsg);
|
|
}*/
|
|
|
|
int creat_lcd_msg_thread(void)
|
|
{
|
|
int ret = -1;
|
|
pthread_t lcd_msg_thr_id;
|
|
|
|
log_printf(LOG_DEBUG,I_NOUSED,"[.thr.]->-\n");
|
|
ret = pthread_create(&lcd_msg_thr_id, NULL, (void *)lcd_msg_recv_thr, NULL);
|
|
if(ret != 0) {
|
|
log_printf(LOG_ERR,I_NOUSED," creat thread err.\n");
|
|
return -1;
|
|
}
|
|
else{
|
|
log_printf(LOG_DEBUG,I_NOUSED," Ok . creat thread succeed.\n");
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
#if 1
|
|
|
|
int creat_uart_msg_thread(void)
|
|
{
|
|
int ret = -1;
|
|
pthread_t uart_msg_thr_id;
|
|
|
|
log_printf(LOG_DEBUG,I_NOUSED,"[.thr.]->-\n");
|
|
ret = pthread_create(&uart_msg_thr_id, NULL, (void *)uart_msg_recv_thr, NULL);
|
|
if(ret != 0) {
|
|
log_printf(LOG_ERR,I_NOUSED," creat thread err.\n");
|
|
return -1;
|
|
}
|
|
else{
|
|
log_printf(LOG_DEBUG,I_NOUSED," Ok. creat thread succeed.\n");
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
extern uint8 g_gps_init_ok;
|
|
void sec_msg_to_gps_uart_thr(void)
|
|
{
|
|
MSG msg;
|
|
|
|
if(g_gps_init_ok==1){
|
|
msg.type = MSG_SEC;
|
|
msg.need_free = MSG_NO_NEED_FREE; // lpara no need free
|
|
msg.rPara = UART_USER_232_COM;
|
|
msg_send_to_gps_uart(&msg);//cttb_msg_send_to_uart
|
|
}
|
|
}
|
|
|
|
int creat_gps_uart_msg_thread(void)
|
|
{
|
|
int ret = -1;
|
|
pthread_t gps_uart_msg_thr_id;
|
|
|
|
log_printf(LOG_DEBUG,I_NOUSED,"[.thr.]->-\n");
|
|
ret = pthread_create(&gps_uart_msg_thr_id, NULL, (void *)gps_uart_msg_recv_thr, NULL);
|
|
if(ret != 0) {
|
|
log_printf(LOG_ERR,I_NOUSED," creat thread err.\n");
|
|
return -1;
|
|
}
|
|
else{
|
|
log_printf(LOG_DEBUG,I_NOUSED," Ok . creat thread succeed.\n");
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
#endif
|
|
|
|
#if 1
|
|
int creat_tsoip_msg_thread(void)
|
|
{
|
|
int ret = -1;
|
|
pthread_t tsoip_msg_thr_id;
|
|
|
|
log_printf(LOG_DEBUG,I_NOUSED,"[.thr.]->-\n");
|
|
ret = pthread_create(&tsoip_msg_thr_id, NULL, (void *)tsoip_msg_recv_thr, NULL);
|
|
if(ret != 0) {
|
|
log_printf(LOG_ERR,I_NOUSED," creat thread err.\n");
|
|
return -1;
|
|
}
|
|
else{
|
|
log_printf(LOG_DEBUG,I_NOUSED," Ok. creat thread succeed.\n");
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
#endif
|
|
|
|
#if DEF_NEED_TO_EN //@NEED_TO_EN
|
|
|
|
int creat_log_msg_thread(void)
|
|
{
|
|
int ret = -1;
|
|
pthread_t log_msg_thr_id;
|
|
|
|
ret = pthread_create(&log_msg_thr_id, NULL, (void *)log_msg_recv_thr, NULL);
|
|
if(ret != 0) {
|
|
printf(" Err.[%s,%d] creat thread err.\n", __FUNCTION__,__LINE__);
|
|
return -1;
|
|
}
|
|
else{
|
|
printf(" Ok .[%s,%d] creat thread succeed.\n", __FUNCTION__,__LINE__);
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
#endif//DEF_NEED_TO_EN
|
|
|