123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256 |
- #include "includes.h"
- TALKING_DEF talking;
- void callinfoinit(void);
- /*
- app_init
- 初始化应用层数据
- */
- void app_init(void){
- callinfoinit();
- memset((T_UINT8 *)&talking, 0, sizeof(TALKING_DEF));
- talking.keepLogin=TRUE;
- talking.media=MEDIA_IDLE;
- talking.pttReleasedAlready=TRUE;
- talking.outputInfoInterval=50;
- talking.fileDirReady=TRUE;
- talking.toneStatus='0';
- talking.operationID=0;
- talking.groupStart=TRUE;//开机会访问一次集群
- #if 0
- //bellow for test
- talking.netWork.ppp=1;
- talking.getImeiFlag=TRUE;
- strcpy(talking.imei, "868541234567895");
- talking.remoteEnable=TRUE;
- talking.maxValue_none_4G=100;
- #endif
- }
- /*
- ptQueueComReadTask
- 通用队列读取任务
- 主要负责读取通用队列数据,分析处理
- 包括负责转发需要发送到外部(串口外设)的消息
- 负责转发需要发送到内部(module)的消息
- 负责处理从外部(串口外设)输入的消息
- 负责处理从内部(module)返回的消息
- */
- PT_THREAD (ptQueueComReadTask(pt_timer_t *ptPool, struct pt *pt)){
- static pt_timer_t ptTimer;
- T_UINT8 buffer[TUP_DATA_MAX+EXT_DATA],type;
- T_INT16 len;
- PT_BEGIN(pt);
- while(1){
- ticketDeVote(TICKET_PT_QUECOM);//其实这个没用,因为没消息时肯定就投票了
- while(1){
- len=msgQueueAccept(buffer,sizeof(buffer)-1, Q_OUTER, &type);
- if(len>0){
- buffer[len]=0;
- if(QSUB_COM_TO_OUTTER==type){//msg that need to send to outter(usart)
- outterInfo(buffer, len);
- }else if(QSUB_COM_FROM_OUTTER==type){//process commands from user(usart)
- OutterCmdHandle(buffer, len);
- }
- continue;
- }else break;
- }
- while(1){
- len=msgQueueAccept(buffer,sizeof(buffer)-1, Q_INNER, &type);
- if(len>0){
- buffer[len]=0;
- if(QSUB_COM_TO_INNER==type){//msg that need to send to inner(modem)
- innerInfo(buffer, len);
- }else if(QSUB_COM_FROM_INNER==type){//process commands from inner(modem)
- InnerCmdHandler(buffer, len);
- }
- continue;
- }else break;
- }
- while(1){
- len=msgQueueAccept(buffer,sizeof(buffer)-1, Q_LOG, &type);
- if(len>0){
- buffer[len]=0;
- outterInfo(buffer, len);
- continue;
- }else break;
- }
- ticketVote(TICKET_PT_QUECOM);
- PTTimerStart(ptPool, &ptTimer,1);//should be fast
- PT_WAIT_UNTIL(pt, PTTimerIsExpired(&ptTimer));
- }
- PT_END(pt);
- }
- static LINES_ENUM lineStatus=LINES_OFF_IDLE;
- /*
- updateLineStatus
- 更新登陆状态接口
- */
- void updateLineStatus(LINES_ENUM status, SETCLR_ENUM flag){
- if(S_SET==flag) lineStatus |= (LINES_ENUM)(1<<status);
- else lineStatus &= (LINES_ENUM)(~(1<<status));
- }
- /*
- getLineStatus
- 获取登陆状态接口
- */
- LINES_ENUM getLineStatus(void){
- if(lineStatus & (1<<LINES_ONLINE)) return LINES_ONLINE;
- else if(lineStatus & (1<<LINES_NO_SERVICE)) return LINES_NO_SERVICE;
- else if(lineStatus & (1<<LINES_NO_LINK)) return LINES_NO_LINK;
- else if(lineStatus & (1<<LINES_ACCOUNT_ERR)) return LINES_ACCOUNT_ERR;
- else if(lineStatus & (1<<LINES_UN_CONNECT_IP)) return LINES_UN_CONNECT_IP;
- else return LINES_OFF_IDLE;
- }
- /*
- ptLoginInfoTask
- 当网络允许后,负责执行登陆到对讲服务器的主要命令以及流程操作
- */
- static T_UINT16 noticeCnt=0;
- void outPutInfoNow(void){
- noticeCnt=talking.outputInfoInterval;
- }
- PT_THREAD (ptLoginInfoTask(pt_timer_t *ptPool, struct pt *pt)){
- static pt_timer_t ptTimer;
- static LINES_ENUM lastLineStatus=LINES_MAX;
- LINES_ENUM tempLineStatus;
- T_INT8 info[50],accountErr[50]={0};
- T_BOOL needWarn=TRUE;
- static T_UINT8 stopLoginCnt=0xf0;
- PT_BEGIN(pt);
- while(1){
- ++noticeCnt;
- tempLineStatus=getLineStatus();
- if(tempLineStatus != lastLineStatus){
- lastLineStatus=tempLineStatus;
- noticeCnt=0;
- }
- snprintf(info, sizeof(info), "+POC:820000000000");
- if(TRUE==talking.keepLogin){
- switch(lastLineStatus){
- case LINES_OFF_IDLE:
- case LINES_ONLINE:
- needWarn=FALSE;noticeCnt=0;
- break;
- case LINES_NO_LINK:
- if(CODE_GBK==paras.msgCode) strcat(info, "CEDECDF8C2E7C1ACBDD3");
- else strcat(info, "E065517FDC7EDE8FA563");
- break;
- case LINES_ACCOUNT_ERR:
- snprintf(accountErr, sizeof(accountErr), "+POC:820600000000");
- if(CODE_GBK==paras.msgCode){
- strcat(info, "B5C7C2BDCAA7B0DC");
- strcat(accountErr, "D5CBBAC5D0C5CFA2B4EDCEF3");
- }else{
- strcat(info, "7B7646963159258D");
- strcat(accountErr, "268DF753E14F6F601995EF8B");
- }
- strcat(accountErr, "\r\n");
- break;
- case LINES_UN_CONNECT_IP:
- if(CODE_GBK==paras.msgCode) strcat(info, "CEDEB7A8C1ACBDD3");
- else strcat(info, "E065D56CDE8FA563");
- break;
- case LINES_NO_SERVICE:
- if(CODE_GBK==paras.msgCode) strcat(info, "C3BBD3D0B7FECEF1");
- else strcat(info, "A16C09670D67A152");
- break;
- }
- if(noticeCnt >= talking.outputInfoInterval){
- if(needWarn==TRUE){
- if(30 != talking.outputInfoInterval) talking.outputInfoInterval=30;
- strcat(info, "\r\n");
- msgToOutter(info);
- if(NULL != accountErr) msgToOutter(accountErr);
- }
- noticeCnt=0;
- }
- }else{
- //定时输出"登陆停止"
- if(++stopLoginCnt>=30){
- stopLoginCnt=0;
- if(CODE_GBK==paras.msgCode) strcat(info, "B5C7C2BDCDA3D6B9");
- else strcat(info, "7B7646965C50626B");
- strcat(info, "\r\n");
- msgToOutter(info);
- }
- }
- ticketVote(TICKET_PT_LOGININFO);
- PTTimerStart(ptPool, &ptTimer,100);//need set to 1 seconds
- PT_WAIT_UNTIL(pt, PTTimerIsExpired(&ptTimer));
- }
- PT_END(pt);
- }
- /*
- logEnable
- 打印/保存应用日志的方式
- type:0 不保存到系统本地
- type:1 保存到系统本地
- 不同平台可以方式不一样,或者有些平台不支持(空间问题)
- */
- void logEnable(char type){
- }
- void threadPostEvent(nwy_osiThread_t *threadId, T_INT32 id){
- nwy_osiEvent_t pEventSend;
- pEventSend.id=id;
- nwy_send_thead_event(threadId, &pEventSend,0);
- }
- void userExitThread(const char *name){
- wlog_info("[DieThread:%x]%s", nwy_get_current_thread(),name);
- nwy_exit_thread();
- }
- typedef struct{
- int uid;
- char usrname[GU_NAME_MAX];
- }CALLER_NAME_DEF;
- #define BACKUP_CALLER_NAME_NUM 1
- CALLER_NAME_DEF callinfo[BACKUP_CALLER_NAME_NUM];
- static unsigned char cindex=0;
- static int lastCallUid=-1;//TCP指令最后输出给MCU的成员
- void callinfoinit(void){
- int i;
- for(i=0;i<BACKUP_CALLER_NAME_NUM;i++) callinfo[i].uid=-1;
- }
- void pushCallerInfo(int uid, char *name,int namelen){
- int i;
- //入列
- callinfo[cindex].uid=uid;
- for(i=0;i<namelen;i++){
- if(i<sizeof(callinfo[cindex].usrname)-1) callinfo[cindex].usrname[i]=name[i];
- }
- if(i<sizeof(callinfo[cindex].usrname)) callinfo[cindex].usrname[i]=0;
- if(++cindex>=BACKUP_CALLER_NAME_NUM) cindex=0;
- lastCallUid=uid;
- }
- void callerNameProcess(int uid){
- int i;
- char info[GU_NAME_MAX*2+50];
- if(uid==lastCallUid) return;//实际说话者已输出了
- //检测列中是否有已在的uid信息
- for(i=0;i<BACKUP_CALLER_NAME_NUM;i++){
- if(uid==callinfo[i].uid){
- lastCallUid=uid;
- //存在则输出一次成员信息
- snprintf(info, sizeof(info), "+POC:8300%08x%s\r\n",callinfo[i].uid,callinfo[i].usrname);
- msgToOutter(info);
- wlog_info("reput call info:%s",info);
- return;
- }
- }
- }
|