app.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. #include "includes.h"
  2. #include "lsapi_sys.h"
  3. APP_DEF app;
  4. /*
  5. app_init
  6. 初始化应用层数据
  7. */
  8. void app_init(void){
  9. ticketReset();
  10. memset((T_UINT8 *)&app, 0, sizeof(APP_DEF));
  11. app.media=MEDIA_IDLE;
  12. app.paraFileReady=TRUE;
  13. app.psnFileReady=TRUE;
  14. app.loadVoicePlayAlready=TRUE;
  15. #ifdef FORCE_ONWORK_STATUS
  16. app.onWorkZone=1;
  17. #endif
  18. }
  19. /*
  20. ptQueueComReadTask
  21. 通用队列读取任务
  22. 主要负责读取通用队列数据,分析处理
  23. 包括负责转发需要发送到外部(串口外设)的消息
  24. 负责转发需要发送到内部(module)的消息
  25. 负责处理从外部(串口外设)输入的消息
  26. 负责处理从内部(module)返回的消息
  27. */
  28. PT_THREAD (ptQueueComReadTask(pt_timer_t *ptPool, struct pt *pt)){
  29. static pt_timer_t ptTimer;
  30. T_UINT8 buffer[TUP_DATA_MAX+EXT_DATA],type;
  31. T_INT16 len;
  32. PT_BEGIN(pt);
  33. while(1){
  34. ticketDeVote(TICKET_PT_QUECOM);//其实这个没用,因为没消息时肯定就投票了
  35. while(1){
  36. len=msgQueueAccept(buffer,sizeof(buffer)-1, Q_OUTER, &type);
  37. if(len>0){
  38. buffer[len]=0;
  39. if(QSUB_COM_TO_OUTTER==type){//msg that need to send to outter(usart)
  40. outterInfo(buffer, len);
  41. }else if(QSUB_COM_FROM_OUTTER==type){//process commands from user(usart)
  42. OutterCmdHandle(buffer, len);
  43. }
  44. continue;
  45. }else break;
  46. }
  47. while(1){
  48. len=msgQueueAccept(buffer,sizeof(buffer)-1, Q_INNER, &type);
  49. if(len>0){
  50. buffer[len]=0;
  51. if(QSUB_COM_TO_INNER==type){//msg that need to send to inner(modem)
  52. innerInfo(buffer, len);
  53. }else if(QSUB_COM_FROM_INNER==type){//process commands from inner(modem)
  54. InnerCmdHandler(buffer, len);
  55. }
  56. continue;
  57. }else break;
  58. }
  59. while(1){
  60. len=msgQueueAccept(buffer,sizeof(buffer)-1, Q_LOG, &type);
  61. if(len>0){
  62. buffer[len]=0;
  63. outterInfo(buffer, len);
  64. continue;
  65. }else break;
  66. }
  67. ticketVote(TICKET_PT_QUECOM);
  68. PTTimerStart(ptPool, &ptTimer,1);//should be fast
  69. PT_WAIT_UNTIL(pt, PTTimerIsExpired(&ptTimer));
  70. }
  71. PT_END(pt);
  72. }
  73. /*
  74. MCU升级模式开始,关闭网络及相关业务
  75. MCU升级模式退出,打开网络及相关业务
  76. */
  77. void normalTaskStatus(T_BOOL status){
  78. //netWorkCtl(status);
  79. authWorkCtl(status);
  80. locationWorkCtl(status);
  81. }
  82. void sysInfoShow(void){
  83. static unsigned char cnt=0;
  84. if(++cnt>=10){
  85. cnt=0;
  86. //打印注册,pdp,netif
  87. wlog_info("[sys]reg:%d,pdp:%d,netif:%d",app.netWork.reg,app.netWork.pdp,app.netWork.netReayd);
  88. //打印iot验证、业务登录和等待计数
  89. wlog_info("[sys]iot:%d,login:%d,nextCnt:%d",getIotStatus(),getLoginStatus(),getNextCnt());
  90. //打印作业状态及上传使用能情况
  91. wlog_info("[sys]onWork:%d,voice:%d,sos:%d",app.onWorkZone,sut_para.voiceUploadEnable_N,sut_para.sosUpoadEnable_N);
  92. //打印作业状态和采样实际使用值
  93. wlog_info("[sys]devT:%d,gnssT:%d,nearT:%d,dataT:%d",app.devSampleTime,app.gnssSampleTime,app.nearSampleTime,app.dataUploadTime);
  94. //打印参数文件和PSN文件状态
  95. wlog_info("[sys]fpara:%d,fpsn:%d", app.paraFileReady, app.psnFileReady);
  96. }
  97. }
  98. #include "nmea.h"
  99. typedef struct{
  100. unsigned char reg:1;
  101. unsigned char ppp:1;
  102. unsigned char iot:1;
  103. unsigned char auth:1;
  104. unsigned char ksos:1;
  105. unsigned char krec:1;
  106. unsigned char locate:1;
  107. unsigned int psn;
  108. unsigned char sdata[4];
  109. int csq;
  110. unsigned int lat;
  111. unsigned int lon;
  112. int bat;
  113. short ax;
  114. short ay;
  115. short az;
  116. int step;
  117. unsigned short mcc;
  118. unsigned char mnc;
  119. unsigned short lac;
  120. unsigned int cellid;
  121. NEAR_DEF near;
  122. }TINFO_DEF;
  123. TINFO_DEF tinfo={
  124. .reg=0,
  125. .ppp=0,
  126. .iot=0,
  127. .auth=0,
  128. .ksos=0,
  129. .krec=0,
  130. .locate=0,
  131. .psn=999,
  132. .sdata[0]=0,
  133. .sdata[1]=0,
  134. .sdata[2]=0,
  135. .sdata[3]=0,
  136. .csq=-99,
  137. .lat=999,
  138. .lon=999,
  139. .bat=-99,
  140. .ax=999,
  141. .ay=999,
  142. .az=999,
  143. .step=0,
  144. .mcc=999,
  145. .mnc=99,
  146. .lac=999,
  147. .cellid=999,
  148. };
  149. void getTinfo(void){
  150. char info[30];
  151. static T_BOOL nearFlag=FALSE;
  152. tinfo.psn=sut_psn.psn;
  153. memcpy(tinfo.sdata,app.bubiaoSerVer,4);
  154. tinfo.reg=app.netWork.reg;
  155. tinfo.ppp=app.netWork.netReayd;
  156. LSAPI_NET_GetCsq(&tinfo.csq);
  157. tinfo.iot=getIotStatus();
  158. tinfo.auth=getLoginStatus();
  159. tinfo.ksos=app.ksos;
  160. tinfo.krec=app.krec;
  161. tinfo.locate=nmeaInfo.isGpsValid;
  162. tinfo.lat=nmeaInfo.Latitude;
  163. tinfo.lon=nmeaInfo.Longitude;
  164. tinfo.bat=app.bat;
  165. tinfo.ax=sut_saveRecDev.record.aspeed_x;
  166. tinfo.ay=sut_saveRecDev.record.aspeed_y;
  167. tinfo.az=sut_saveRecDev.record.aspeed_z;
  168. tinfo.step=sut_saveRecDev.record.steps;
  169. tinfo.mcc=sut_saveRecDev.record.mcc;
  170. tinfo.mnc=sut_saveRecDev.record.mnc;
  171. tinfo.lac=sut_saveRecDev.record.lac;
  172. tinfo.cellid=sut_saveRecDev.record.cellid;
  173. if(nearFlag==FALSE){
  174. if(sut_saveRecNear.record.num==0) memset((unsigned char *)&tinfo.near,0,sizeof(NEAR_DEF));
  175. else{
  176. memcpy((unsigned char *)&tinfo.near, &sut_saveRecNear.record.info[0],sizeof(NEAR_DEF));
  177. nearFlag=TRUE;
  178. }
  179. }
  180. }
  181. /*用于获取测试数据*/
  182. void getTestInfo(void){
  183. char info[100];
  184. getTinfo();
  185. snprintf(info, sizeof(info), "<PARA>psn=%d,sdata=%d.%d.%d.%d\r\n",tinfo.psn,tinfo.sdata[0],tinfo.sdata[1],tinfo.sdata[2],tinfo.sdata[3]);
  186. outterInfo(info, strlen(info));
  187. snprintf(info, sizeof(info), "<NET>iccid=%s,reg=%d,ppp=%d,csq=%d\r\n",app.CCID,tinfo.reg,tinfo.ppp,tinfo.csq);
  188. outterInfo(info, strlen(info));
  189. snprintf(info, sizeof(info), "<SERVER>iot=%d,data=%d\r\n",tinfo.iot,tinfo.auth);
  190. outterInfo(info, strlen(info));
  191. snprintf(info, sizeof(info), "<KEY>sos=%d,rec=%d,charge=%d\r\n",tinfo.ksos,tinfo.krec,app.vcharge);
  192. outterInfo(info, strlen(info));
  193. snprintf(info, sizeof(info), "<GPS>locate=%d,lat=%d,long=%d\r\n",tinfo.locate,tinfo.lat,tinfo.lon);
  194. outterInfo(info, strlen(info));
  195. snprintf(info, sizeof(info), "<DEV>bat=%d,ax=%d,ay=%d,az=%d,step=%d\r\n",tinfo.bat,tinfo.ax,tinfo.ay,tinfo.az,tinfo.step);
  196. outterInfo(info, strlen(info));
  197. snprintf(info, sizeof(info), "<LBS>mcc=%d,mnc=%d,lac=%d,cellid=%d\r\n",tinfo.mcc,tinfo.mnc,tinfo.lac,tinfo.cellid);
  198. outterInfo(info, strlen(info));
  199. snprintf(info, sizeof(info), "<NEAR>acc=%02x%02x%02x%02x%02x%02x,rssi=%d\r\n",tinfo.near.mac[0],tinfo.near.mac[1],tinfo.near.mac[2],tinfo.near.mac[3],tinfo.near.mac[4],tinfo.near.mac[5],tinfo.near.rssi);
  200. outterInfo(info, strlen(info));
  201. snprintf(info, sizeof(info), "<LTE>name=%s,lte=%s\r\n",APP_NAME,APP_VERSION);
  202. outterInfo(info, strlen(info));
  203. snprintf(info, sizeof(info), "<MODEM>ati=%s\r\n",app.fmVersion);
  204. outterInfo(info, strlen(info));
  205. }