app.c 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. #include "includes.h"
  2. TALKING_DEF talking;
  3. void callinfoinit(void);
  4. /*
  5. app_init
  6. 初始化应用层数据
  7. */
  8. void app_init(void){
  9. callinfoinit();
  10. memset((T_UINT8 *)&talking, 0, sizeof(TALKING_DEF));
  11. talking.keepLogin=TRUE;
  12. talking.media=MEDIA_IDLE;
  13. talking.pttReleasedAlready=TRUE;
  14. talking.outputInfoInterval=50;
  15. talking.fileDirReady=TRUE;
  16. talking.toneStatus='0';
  17. talking.operationID=0;
  18. talking.groupStart=TRUE;//开机会访问一次集群
  19. #if 0
  20. //bellow for test
  21. talking.netWork.ppp=1;
  22. talking.getImeiFlag=TRUE;
  23. strcpy(talking.imei, "868541234567895");
  24. talking.remoteEnable=TRUE;
  25. talking.maxValue_none_4G=100;
  26. #endif
  27. }
  28. /*
  29. ptQueueComReadTask
  30. 通用队列读取任务
  31. 主要负责读取通用队列数据,分析处理
  32. 包括负责转发需要发送到外部(串口外设)的消息
  33. 负责转发需要发送到内部(module)的消息
  34. 负责处理从外部(串口外设)输入的消息
  35. 负责处理从内部(module)返回的消息
  36. */
  37. PT_THREAD (ptQueueComReadTask(pt_timer_t *ptPool, struct pt *pt)){
  38. static pt_timer_t ptTimer;
  39. T_UINT8 buffer[TUP_DATA_MAX+EXT_DATA],type;
  40. T_INT16 len;
  41. PT_BEGIN(pt);
  42. while(1){
  43. ticketDeVote(TICKET_PT_QUECOM);//其实这个没用,因为没消息时肯定就投票了
  44. while(1){
  45. len=msgQueueAccept(buffer,sizeof(buffer)-1, Q_OUTER, &type);
  46. if(len>0){
  47. buffer[len]=0;
  48. if(QSUB_COM_TO_OUTTER==type){//msg that need to send to outter(usart)
  49. outterInfo(buffer, len);
  50. }else if(QSUB_COM_FROM_OUTTER==type){//process commands from user(usart)
  51. OutterCmdHandle(buffer, len);
  52. }
  53. continue;
  54. }else break;
  55. }
  56. while(1){
  57. len=msgQueueAccept(buffer,sizeof(buffer)-1, Q_INNER, &type);
  58. if(len>0){
  59. buffer[len]=0;
  60. if(QSUB_COM_TO_INNER==type){//msg that need to send to inner(modem)
  61. innerInfo(buffer, len);
  62. }else if(QSUB_COM_FROM_INNER==type){//process commands from inner(modem)
  63. InnerCmdHandler(buffer, len);
  64. }
  65. continue;
  66. }else break;
  67. }
  68. while(1){
  69. len=msgQueueAccept(buffer,sizeof(buffer)-1, Q_LOG, &type);
  70. if(len>0){
  71. buffer[len]=0;
  72. outterInfo(buffer, len);
  73. continue;
  74. }else break;
  75. }
  76. ticketVote(TICKET_PT_QUECOM);
  77. PTTimerStart(ptPool, &ptTimer,1);//should be fast
  78. PT_WAIT_UNTIL(pt, PTTimerIsExpired(&ptTimer));
  79. }
  80. PT_END(pt);
  81. }
  82. static LINES_ENUM lineStatus=LINES_OFF_IDLE;
  83. /*
  84. updateLineStatus
  85. 更新登陆状态接口
  86. */
  87. void updateLineStatus(LINES_ENUM status, SETCLR_ENUM flag){
  88. if(S_SET==flag) lineStatus |= (LINES_ENUM)(1<<status);
  89. else lineStatus &= (LINES_ENUM)(~(1<<status));
  90. }
  91. /*
  92. getLineStatus
  93. 获取登陆状态接口
  94. */
  95. LINES_ENUM getLineStatus(void){
  96. if(lineStatus & (1<<LINES_ONLINE)) return LINES_ONLINE;
  97. else if(lineStatus & (1<<LINES_NO_SERVICE)) return LINES_NO_SERVICE;
  98. else if(lineStatus & (1<<LINES_NO_LINK)) return LINES_NO_LINK;
  99. else if(lineStatus & (1<<LINES_ACCOUNT_ERR)) return LINES_ACCOUNT_ERR;
  100. else if(lineStatus & (1<<LINES_UN_CONNECT_IP)) return LINES_UN_CONNECT_IP;
  101. else return LINES_OFF_IDLE;
  102. }
  103. /*
  104. ptLoginInfoTask
  105. 当网络允许后,负责执行登陆到对讲服务器的主要命令以及流程操作
  106. */
  107. static T_UINT16 noticeCnt=0;
  108. void outPutInfoNow(void){
  109. noticeCnt=talking.outputInfoInterval;
  110. }
  111. PT_THREAD (ptLoginInfoTask(pt_timer_t *ptPool, struct pt *pt)){
  112. static pt_timer_t ptTimer;
  113. static LINES_ENUM lastLineStatus=LINES_MAX;
  114. LINES_ENUM tempLineStatus;
  115. T_INT8 info[50],accountErr[50]={0};
  116. T_BOOL needWarn=TRUE;
  117. static T_UINT8 stopLoginCnt=0xf0;
  118. PT_BEGIN(pt);
  119. while(1){
  120. ++noticeCnt;
  121. tempLineStatus=getLineStatus();
  122. if(tempLineStatus != lastLineStatus){
  123. lastLineStatus=tempLineStatus;
  124. noticeCnt=0;
  125. }
  126. snprintf(info, sizeof(info), "+POC:820000000000");
  127. if(TRUE==talking.keepLogin){
  128. switch(lastLineStatus){
  129. case LINES_OFF_IDLE:
  130. case LINES_ONLINE:
  131. needWarn=FALSE;noticeCnt=0;
  132. break;
  133. case LINES_NO_LINK:
  134. if(CODE_GBK==paras.msgCode) strcat(info, "CEDECDF8C2E7C1ACBDD3");
  135. else strcat(info, "E065517FDC7EDE8FA563");
  136. break;
  137. case LINES_ACCOUNT_ERR:
  138. snprintf(accountErr, sizeof(accountErr), "+POC:820600000000");
  139. if(CODE_GBK==paras.msgCode){
  140. strcat(info, "B5C7C2BDCAA7B0DC");
  141. strcat(accountErr, "D5CBBAC5D0C5CFA2B4EDCEF3");
  142. }else{
  143. strcat(info, "7B7646963159258D");
  144. strcat(accountErr, "268DF753E14F6F601995EF8B");
  145. }
  146. strcat(accountErr, "\r\n");
  147. break;
  148. case LINES_UN_CONNECT_IP:
  149. if(CODE_GBK==paras.msgCode) strcat(info, "CEDEB7A8C1ACBDD3");
  150. else strcat(info, "E065D56CDE8FA563");
  151. break;
  152. case LINES_NO_SERVICE:
  153. if(CODE_GBK==paras.msgCode) strcat(info, "C3BBD3D0B7FECEF1");
  154. else strcat(info, "A16C09670D67A152");
  155. break;
  156. }
  157. if(noticeCnt >= talking.outputInfoInterval){
  158. if(needWarn==TRUE){
  159. if(30 != talking.outputInfoInterval) talking.outputInfoInterval=30;
  160. strcat(info, "\r\n");
  161. msgToOutter(info);
  162. if(NULL != accountErr) msgToOutter(accountErr);
  163. }
  164. noticeCnt=0;
  165. }
  166. }else{
  167. //定时输出"登陆停止"
  168. if(++stopLoginCnt>=30){
  169. stopLoginCnt=0;
  170. if(CODE_GBK==paras.msgCode) strcat(info, "B5C7C2BDCDA3D6B9");
  171. else strcat(info, "7B7646965C50626B");
  172. strcat(info, "\r\n");
  173. msgToOutter(info);
  174. }
  175. }
  176. ticketVote(TICKET_PT_LOGININFO);
  177. PTTimerStart(ptPool, &ptTimer,100);//need set to 1 seconds
  178. PT_WAIT_UNTIL(pt, PTTimerIsExpired(&ptTimer));
  179. }
  180. PT_END(pt);
  181. }
  182. /*
  183. logEnable
  184. 打印/保存应用日志的方式
  185. type:0 不保存到系统本地
  186. type:1 保存到系统本地
  187. 不同平台可以方式不一样,或者有些平台不支持(空间问题)
  188. */
  189. void logEnable(char type){
  190. }
  191. void threadPostEvent(LSAPI_OSI_Thread_t *threadId, T_INT32 id){
  192. LSAPI_OSI_Event_t pEventSend;
  193. pEventSend.id=id;
  194. //LSAPI_OSI_EvnetSend(threadId,&pEventSend);
  195. osiEventTrySend(threadId,&pEventSend,0);
  196. }
  197. void userExitThread(const char *name){
  198. wlog_info("[DieThread:%x]%s", LSAPI_OSI_ThreadCurrent(),name);
  199. LSAPI_OSI_ThreadExit();
  200. }
  201. typedef struct{
  202. int uid;
  203. char usrname[GU_NAME_MAX];
  204. }CALLER_NAME_DEF;
  205. #define BACKUP_CALLER_NAME_NUM 5
  206. CALLER_NAME_DEF callinfo[BACKUP_CALLER_NAME_NUM];
  207. static unsigned char cindex=0;
  208. static int lastCallUid=-1;//TCP指令最后输出给MCU的成员
  209. void callinfoinit(void){
  210. int i;
  211. for(i=0;i<BACKUP_CALLER_NAME_NUM;i++) callinfo[i].uid=-1;
  212. }
  213. void pushCallerInfo(int uid, char *name,int namelen){
  214. int i;
  215. //入列
  216. callinfo[cindex].uid=uid;
  217. for(i=0;i<namelen;i++){
  218. if(i<sizeof(callinfo[cindex].usrname)-1) callinfo[cindex].usrname[i]=name[i];
  219. }
  220. if(i<sizeof(callinfo[cindex].usrname)) callinfo[cindex].usrname[i]=0;
  221. if(++cindex>=BACKUP_CALLER_NAME_NUM) cindex=0;
  222. lastCallUid=uid;
  223. }
  224. void callerNameProcess(int uid){
  225. int i;
  226. char info[GU_NAME_MAX*2+50];
  227. if(uid==lastCallUid) return;//实际说话者已输出了
  228. //检测列中是否有已在的uid信息
  229. for(i=0;i<BACKUP_CALLER_NAME_NUM;i++){
  230. if(uid==callinfo[i].uid){
  231. lastCallUid=uid;
  232. //存在则输出一次成员信息
  233. snprintf(info, sizeof(info), "+POC:8300%08x%s\r\n",callinfo[i].uid,callinfo[i].usrname);
  234. msgToOutter(info);
  235. wlog_info("reput call info:%s",info);
  236. return;
  237. }
  238. }
  239. }