AppTaskTcp.c 58 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227
  1. /****************************************************************************
  2. *
  3. * Copy right: Qx.Chen jie
  4. * File name: TcpTask.c
  5. * Description: 主要负责:1.数据发送、定时心跳上报,2.数据接收、命令接收及处理,3.Fota函数调用,4.驻网及失败状态监测与上报
  6. * History: 2021-07-05
  7. * Version: V3.0
  8. ****************************************************************************/
  9. #include "AppTaskTcp.h"
  10. #include "numeric.h"
  11. //局部变量申请
  12. static StaticTask_t gProcess_Tcp_Task_t;
  13. static UINT8 gProcess_Tcp_TaskStack[PROC_TCP_TASK_STACK_SIZE];
  14. static QueueHandle_t psEventQueueHandle; //状态转换队列句柄
  15. static osThreadId_t TcpTaskId = NULL;
  16. static eventCallbackMessage_t *queueItem = NULL;
  17. static UINT8 gImsi[16] = {0};
  18. static UINT32 gCellID = 0;
  19. static QueueHandle_t TcpRecvHandle = NULL;
  20. static UINT8 TcpRecvEnd = 0;
  21. static UINT32 send_counter = 0;
  22. static void sendQueueMsg(UINT32 msgId, UINT32 xTickstoWait);
  23. static INT32 socketRegisterPSUrcCallback(urcID_t eventID, void *param, UINT32 paramLen);
  24. static void socketAppConnectionCallBack(UINT8 connectionEventType, void *bodyEvent);
  25. static void TcpDataInfoRecvHandle();
  26. static void TcpDataInfoAssembleSend();
  27. static void TcpHeartDataSend();
  28. static void TcpTask(void *arg)
  29. {
  30. appSetEDRXSettingSync(0, 5, 1800000);
  31. appSetPSMSettingSync(0, 3 * 60 * 60, 10);
  32. appSetCFUN(1);
  33. psEventQueueHandle = xQueueCreate(APP_EVENT_QUEUE_SIZE, sizeof(eventCallbackMessage_t *));
  34. if (psEventQueueHandle == NULL)
  35. {
  36. return;
  37. }
  38. if (TcpRecvHandle == NULL)
  39. {
  40. TcpRecvHandle = osMessageQueueNew(3, sizeof(TcpipConnectionRecvDataInd *), NULL);
  41. }
  42. osDelay(5000); //等待驻网延时5s
  43. while (true)
  44. {
  45. osDelay(100);
  46. if (gProcess_app == WORK && TCPWorkState == 0x00 && AppNVMData.EOLState == 1 && TimeCounter % 10 == 0)
  47. {
  48. sendQueueMsg(QMSG_ID_SOCK_SENDPKG, 0);
  49. }
  50. else if (gProcess_app == LISTEN && TimeCounter % (10 * 60 * 3) == 0)
  51. {
  52. sendQueueMsg(QMSG_ID_SOCK_LISTEN, 0);
  53. send_counter = 0;
  54. }
  55. if (TCPWorkState != 0 && TimeCounter % 10 == 0)
  56. {
  57. TcpRecvEnd++;
  58. if (TcpRecvEnd > 10)
  59. {
  60. TcpRecvEnd = 0;
  61. TCPWorkState = 0;
  62. }
  63. }
  64. if (xQueueReceive(psEventQueueHandle, &queueItem, 0))
  65. {
  66. switch (queueItem->messageId)
  67. {
  68. case QMSG_ID_NW_IP_READY:
  69. if (socContext.id < 0)
  70. {
  71. struct addrinfo hints;
  72. struct addrinfo *servinfo = NULL;
  73. char *Tcp_ip_des;
  74. memset(&hints, 0, sizeof(hints));
  75. hints.ai_family = AF_INET;
  76. hints.ai_socktype = SOCK_STREAM;
  77. getaddrinfo(TCP_ADD, NULL, &hints, &servinfo);
  78. Tcp_ip_des = ip4addr_ntoa((const ip4_addr_t *)(&(servinfo->ai_addr->sa_data[2])));
  79. #ifdef USING_PRINTF1
  80. printf("\nservinfo-%d:\n", servinfo->ai_addr->sa_len);
  81. for (int i = 0; i < 4; i++)
  82. printf("%d ", servinfo->ai_addr->sa_data[2 + i]);
  83. printf("\nTcp_ip_des-%d:\n", sizeof(Tcp_ip_des));
  84. for (int i = 0; i < 16; i++)
  85. printf("%c", *(Tcp_ip_des + i));
  86. #endif
  87. socContext.id = tcpipConnectionCreate(TCPIP_CONNECTION_PROTOCOL_TCP, PNULL, 0, Tcp_ip_des, TCP_PORT, socketAppConnectionCallBack);
  88. if (NULL != servinfo)
  89. {
  90. freeaddrinfo(servinfo);
  91. }
  92. }
  93. if (socContext.id >= 0)
  94. {
  95. TcpErrorcount = 0;
  96. socContext.status = APP_SOCKET_CONNECTION_CONNECTED;
  97. #ifdef USING_PRINTF
  98. printf("create connection %u success\n", socContext.id);
  99. #endif
  100. ECOMM_TRACE(UNILOG_PLA_APP, ecTestCaseTcpClient_2, P_INFO, 1, "create connection %u success", socContext.id);
  101. }
  102. else
  103. {
  104. sendQueueMsg(QMSG_ID_NW_IP_NOREACHABLE, 0);
  105. #ifdef USING_PRINTF
  106. printf("create connection fail\n");
  107. #endif
  108. ECOMM_TRACE(UNILOG_PLA_APP, ecTestCaseTcpClient_3, P_ERROR, 0, "create connection fail");
  109. }
  110. break;
  111. case QMSG_ID_NW_IP_NOREACHABLE:
  112. {
  113. TcpErrorcount++;
  114. socContext.id = -1;
  115. appSetCFUN(0);
  116. osDelay(5000);
  117. appSetCFUN(1);
  118. osDelay(10000);
  119. #ifdef USING_PRINTF
  120. printf("Network restart\n");
  121. #endif
  122. }
  123. break;
  124. case QMSG_ID_SOCK_SENDPKG:
  125. if (socContext.id >= 0 && socContext.status == APP_SOCKET_CONNECTION_CONNECTED)
  126. {
  127. NmAtiSyncRet netstatus1;
  128. appGetNetInfoSync(0, &netstatus1);
  129. if (netstatus1.body.netInfoRet.netifInfo.netStatus == NM_NETIF_ACTIVATED || netstatus1.body.netInfoRet.netifInfo.netStatus == NM_NETIF_ACTIVATED_INFO_CHNAGED)
  130. {
  131. TcpDataInfoAssembleSend();
  132. }
  133. else
  134. {
  135. sendQueueMsg(QMSG_ID_NW_IP_SUSPEND, 0);
  136. }
  137. }
  138. else
  139. {
  140. sendQueueMsg(QMSG_ID_NW_IP_READY, 0);
  141. #ifdef USING_PRINTF
  142. printf("connection %u or status invalid", socContext.id, socContext.status);
  143. #endif
  144. ECOMM_TRACE(UNILOG_PLA_APP, ecTestCaseTcpClient_9, P_ERROR, 2, "connection %u or status invalid", socContext.id, socContext.status);
  145. }
  146. break;
  147. case QMSG_ID_SOCK_RECVPKG:
  148. {
  149. TcpDataInfoRecvHandle();
  150. osDelay(100);
  151. TcpRecvEnd = 0;
  152. break;
  153. }
  154. case QMSG_ID_NW_IP_SUSPEND:
  155. if (socContext.id >= 0 && socContext.status != APP_SOCKET_CONNECTION_CLOSED)
  156. {
  157. if (tcpipConnectionClose(socContext.id) < 0)
  158. {
  159. #ifdef USING_PRINTF
  160. printf("close connection %u success", socContext.id);
  161. #endif
  162. socContext.id = -1;
  163. socContext.status = APP_SOCKET_CONNECTION_CLOSED;
  164. ECOMM_TRACE(UNILOG_PLA_APP, ecTestCaseTcpClient_4, P_INFO, 1, "close connection %u success", socContext.id);
  165. }
  166. else
  167. {
  168. #ifdef USING_PRINTF
  169. printf("close connection %u fail", socContext.id);
  170. #endif
  171. ECOMM_TRACE(UNILOG_PLA_APP, ecTestCaseTcpClient_5, P_ERROR, 1, "close connection %u fail", socContext.id);
  172. }
  173. }
  174. else
  175. {
  176. sendQueueMsg(QMSG_ID_NW_IP_NOREACHABLE, 0);
  177. #ifdef USING_PRINTF
  178. printf("connection %u or status invalid", socContext.id, socContext.status);
  179. #endif
  180. ECOMM_TRACE(UNILOG_PLA_APP, ecTestCaseTcpClient_6, P_ERROR, 2, "connection %u or status invalid", socContext.id, socContext.status);
  181. }
  182. break;
  183. case QMSG_ID_SOCK_LISTEN:
  184. {
  185. if (socContext.id >= 0 && socContext.status == APP_SOCKET_CONNECTION_CONNECTED)
  186. {
  187. #ifdef USING_PRINTF
  188. printf("[%d]QMSG_ID_SOCK_LISTEN\n", __LINE__);
  189. #endif
  190. TcpHeartDataSend();
  191. }
  192. else
  193. {
  194. sendQueueMsg(QMSG_ID_NW_IP_READY, 0);
  195. #ifdef USING_PRINTF
  196. printf("connection %u or status invalid", socContext.id, socContext.status);
  197. #endif
  198. }
  199. break;
  200. }
  201. case QMSG_ID_SOCK_EXIT:
  202. #ifdef USING_PRINTF
  203. printf("QMSG_ID_SOCK_EXIT queueItem->messageId:%x\n", queueItem->messageId);
  204. #endif
  205. #ifdef USING_PRINTF
  206. printf("socket exit\n");
  207. #endif
  208. appSetCFUN(0);
  209. osDelay(1000);
  210. break;
  211. }
  212. free(queueItem);
  213. } //if
  214. } //while 循环
  215. }
  216. /***********************************************************************************************************************
  217. * 网络组包发送函数
  218. * 输入:空
  219. * 输出:空
  220. * 处理:将相关信息组包之后进行按一定频率发送,每次调用间隔为1s
  221. ***********************************************************************************************************************/
  222. static void TcpDataInfoAssembleSend()
  223. {
  224. OsaUtcTimeTValue TimeStracture;
  225. INT8 snr = 0;
  226. INT8 rsnr = 0;
  227. UINT16 DataLen = 0;
  228. UINT16 BattSendFreq = 30;
  229. UINT8 GpsSendFreq = 30;
  230. UINT16 year;
  231. UINT8 month, day, hour, minute, sec;
  232. UTC8TimeType UTC8TimeTcp;
  233. UINT8 i = 0;
  234. INT16 len = -1;
  235. UINT8 *SendBuffer = NULL;
  236. appGetSignalInfoSync(&csq, &snr, &rsnr);
  237. BattSendFreq = AppDataInfo.BattInfoSendFreqNomal;
  238. GpsSendFreq = AppDataInfo.PosInfoSendFreqNormal;
  239. if (getbit(PadInterrupt, 3) == 1 || getbit(PadInterrupt, 4) == 1) //有震动产生,提高位置信息发送频率
  240. {
  241. GpsSendFreq = AppDataInfo.PosInfoSendFreqHigh;
  242. if (send_counter % 10 == 0)
  243. {
  244. clrbit(PadInterrupt, 3);
  245. clrbit(PadInterrupt, 4);
  246. }
  247. }
  248. if (BattWorkStateDelay == BATT_IDLE_SYM)
  249. {
  250. BattSendFreq = 10 * 60;
  251. }
  252. else
  253. {
  254. BattSendFreq = 10;
  255. }
  256. /*
  257. if(FALSE)
  258. {
  259. UINT16 ErrorTemp = 0x00;
  260. UINT8 ProtocolHeaderLen = 25; //电池信息协议头部加校验码长度,此长度不更改
  261. UINT8 ProtocolFixedLen = 60; //电池信息协议固定总长度 如协议新增,需要更改此长度
  262. UINT8 ProtocolFluctedLen = AppNVMData.BattCellCount*2 + AppNVMData.BattTempCount + BMS_OTHER_TEMP + NB_OTHER_TEMP_NUM;//电池信息协议变动长度
  263. SendBuffer = malloc(ProtocolFixedLen + ProtocolFluctedLen);
  264. if(SendBuffer==NULL)
  265. {
  266. return;
  267. }
  268. appGetSystemTimeUtcSync(&TimeStracture);
  269. year=(TimeStracture.UTCtimer1&0xffff0000)>>16;
  270. month=(TimeStracture.UTCtimer1&0xff00)>>8;
  271. day=TimeStracture.UTCtimer1&0xff;
  272. hour=(TimeStracture.UTCtimer2&0xff000000)>>24;
  273. minute=(TimeStracture.UTCtimer2&0xff0000)>>16;
  274. sec=(TimeStracture.UTCtimer2&0xff00)>>8;
  275. UTCToBeijing((UTC8TimeType *)&UTC8TimeTcp,year,month,day,hour,minute,sec);
  276. appGetSignalInfoSync(&csq,&snr,&rsnr);
  277. *(SendBuffer + 0 ) = TCP_START_SYM1; //起始码-1
  278. *(SendBuffer + 1 ) = TCP_START_SYM2; //起始码-2
  279. *(SendBuffer + 2 ) = TCP_CMD_SYM; //命令标识-3
  280. *(SendBuffer + 3 ) = TCP_ANS_SYM; //应答标识-4
  281. memcpy(SendBuffer + 4,AppNVMData.battSN,BATT_SN_LEN); //SN码 5-21
  282. *(SendBuffer + 21 ) = TCP_ENCPT_DISABLE; //加密方式-22
  283. DataLen = ProtocolFixedLen + ProtocolFluctedLen -ProtocolHeaderLen; //电池信息单元协议固定长度
  284. *(SendBuffer + 22 ) = (DataLen>>8) & 0xFF; //数据长度H-23
  285. *(SendBuffer + 23 ) = DataLen & 0xFF; //数据长度L-24
  286. *(SendBuffer + 24 ) = (UTC8TimeTcp.year - 0x07D0) & 0xFF; //year-25
  287. *(SendBuffer + 25 ) = UTC8TimeTcp.month & 0xFF; //month-26
  288. *(SendBuffer + 26 ) = UTC8TimeTcp.day & 0xFF; //day-27
  289. *(SendBuffer + 27 ) = UTC8TimeTcp.hour & 0xFF; //hour-28
  290. *(SendBuffer + 28 ) = UTC8TimeTcp.minute & 0xFF; //mins-29
  291. *(SendBuffer + 29 ) = UTC8TimeTcp.second & 0xFF; //sec-30
  292. *(SendBuffer + 30 ) = BATTMSG; //电池信息发送-31
  293. *(SendBuffer + 31 ) = (UTC8TimeTcp.year - 0x07D0) & 0xFF; //year-32
  294. *(SendBuffer + 32 ) = UTC8TimeTcp.month & 0xFF; //month-33
  295. *(SendBuffer + 33 ) = UTC8TimeTcp.day & 0xFF; //day-34
  296. *(SendBuffer + 34 ) = UTC8TimeTcp.hour & 0xFF; //hour-35
  297. *(SendBuffer + 35 ) = UTC8TimeTcp.minute & 0xFF; //mins-36
  298. *(SendBuffer + 36 ) = UTC8TimeTcp.second & 0xFF; //sec-37
  299. *(SendBuffer + 37 ) = csq; //信号强度-38
  300. *(SendBuffer + 38 ) = 0x00; //故障等级-39
  301. if(osOK==osMutexAcquire(Error_Mutex, 100))
  302. {
  303. ErrorTemp = GetErrorNum((UINT16 *)ErrorNum,sizeof(ErrorNum));
  304. }
  305. else
  306. {
  307. ErrorTemp = 0x0000;
  308. }
  309. osMutexRelease(Error_Mutex);
  310. *(SendBuffer + 39 ) = ErrorTemp>>8; //故障代码H-40
  311. *(SendBuffer + 40 ) = ErrorTemp & 0xFF; //故障代码L-41
  312. *(SendBuffer + 41 ) = battI>>8; //电流-42
  313. *(SendBuffer + 42 ) = battI & 0xFF; //电流-43
  314. *(SendBuffer + 43 ) = battPackVol >> 8; //电压-44
  315. *(SendBuffer + 44 ) = battPackVol & 0xFF; //电压-45
  316. *(SendBuffer + 45 ) = battPackVol >> 8; //电压-46
  317. *(SendBuffer + 46 ) = battPackVol & 0xFF; //电压-47
  318. *(SendBuffer + 47 ) = battMOSSwitchState; //mos状态-48
  319. *(SendBuffer + 48 ) = battSOC; //soc-49
  320. *(SendBuffer + 49 ) = battSOH; //soh-50
  321. *(SendBuffer + 50 ) = (battBalanceoInfo>>24)&0xFF;
  322. *(SendBuffer + 51 ) = (battBalanceoInfo>>16)&0xFF;
  323. *(SendBuffer + 52 ) = (battBalanceoInfo>>8)&0xFF;
  324. *(SendBuffer + 53 ) = battBalanceoInfo&0xFF; //均衡状态-51-54
  325. *(SendBuffer + 54 ) = AppNVMData.BattCellCount; //电压个数-55
  326. for(i=0;i<AppNVMData.BattCellCount;i++) //单体电压
  327. {
  328. *(SendBuffer + 54 + i*2 + 1) = (battCellU[i]>>8) & 0xFF;
  329. *(SendBuffer + 54 + i*2 + 2) = battCellU[i] & 0xFF;
  330. }
  331. *(SendBuffer + 55 + AppNVMData.BattCellCount*2) = AppNVMData.BattTempCount; //模组温度个数
  332. memcpy((SendBuffer + 55 + AppNVMData.BattCellCount*2 + 1),&battCellTemp,AppNVMData.BattTempCount); //模组温度
  333. *(SendBuffer + 56 + AppNVMData.BattCellCount*2 + AppNVMData.BattTempCount) = battWorkState; //电池工作状态
  334. *(SendBuffer + 57 + AppNVMData.BattCellCount*2 + AppNVMData.BattTempCount) = battHeatEnableState; //电池加热使能
  335. *(SendBuffer + 58 + AppNVMData.BattCellCount*2 + AppNVMData.BattTempCount) = BMS_OTHER_TEMP+NB_OTHER_TEMP_NUM; //其他温度个数
  336. *(SendBuffer + 58 + AppNVMData.BattCellCount*2 + AppNVMData.BattTempCount + 1 ) = MOSTemp; //mos温度
  337. *(SendBuffer + 58 + AppNVMData.BattCellCount*2 + AppNVMData.BattTempCount + 2 ) = packTemp; //环境温度
  338. *(SendBuffer + 58 + AppNVMData.BattCellCount*2 + AppNVMData.BattTempCount + 3 ) = fastChargeTemp; //快充温度
  339. *(SendBuffer + 58 + AppNVMData.BattCellCount*2 + AppNVMData.BattTempCount + 4) = normalChargeTemp; //慢充温度
  340. *(SendBuffer + 58 + AppNVMData.BattCellCount*2 + AppNVMData.BattTempCount + 5) = heatTemp1; //加热温度1
  341. *(SendBuffer + 58 + AppNVMData.BattCellCount*2 + AppNVMData.BattTempCount + 6) = heatTemp2; //加热温度2
  342. *(SendBuffer + 59 + AppNVMData.BattCellCount*2 + AppNVMData.BattTempCount + BMS_OTHER_TEMP+NB_OTHER_TEMP_NUM) = bcc_chk(SendBuffer, ProtocolFixedLen + ProtocolFluctedLen - 1 );//校验码
  343. if(UartRecvFlag)
  344. {
  345. len = tcpipConnectionSend(socContext.id, SendBuffer, ProtocolFixedLen + ProtocolFluctedLen, 0, 0, 0);
  346. #ifdef USING_PRINTF1
  347. printf("Batt-[%d]:\n",len);
  348. #endif
  349. if(len>0)
  350. {
  351. TcpSendLen = 0x02 | TcpSendLen;
  352. }
  353. else
  354. {
  355. TcpSendLen = 0xFD & TcpSendLen;
  356. sendQueueMsg(QMSG_ID_NW_IP_SUSPEND, 0);
  357. }
  358. }
  359. if(SendBuffer!=NULL)
  360. {
  361. free(SendBuffer);
  362. }
  363. SendBuffer=NULL;
  364. }
  365. */
  366. GpsSendFreq = min(3 * 60, BattSendFreq);
  367. if (send_counter % GpsSendFreq == 0 && send_counter != 0)
  368. {
  369. osMessageQueueReset(GpsRecvHandle);
  370. GPSInfo *GpsRecvData = NULL;
  371. GPSMsgtoTcpType GpsToTcpInfo;
  372. UINT16 tac = 0;
  373. UINT32 cellId = 0;
  374. appGetLocationInfoSync(&tac, &cellId);
  375. appGetSystemTimeUtcSync(&TimeStracture);
  376. year = (TimeStracture.UTCtimer1 & 0xffff0000) >> 16;
  377. month = (TimeStracture.UTCtimer1 & 0xff00) >> 8;
  378. day = TimeStracture.UTCtimer1 & 0xff;
  379. hour = (TimeStracture.UTCtimer2 & 0xff000000) >> 24;
  380. minute = (TimeStracture.UTCtimer2 & 0xff0000) >> 16;
  381. sec = (TimeStracture.UTCtimer2 & 0xff00) >> 8;
  382. UTCToBeijing((UTC8TimeType *)&UTC8TimeTcp, year, month, day, hour, minute, sec);
  383. DataLen = (UINT16)sizeof(GpsToTcpInfo.gpsInfo);
  384. GpsToTcpInfo.startSymbol[0] = TCP_START_SYM1;
  385. GpsToTcpInfo.startSymbol[1] = TCP_START_SYM2;
  386. GpsToTcpInfo.cmdSymbol = TCP_CMD_SYM;
  387. GpsToTcpInfo.ansSymbol = TCP_ANS_SYM;
  388. memcpy(GpsToTcpInfo.SN, AppNVMData.battSN, BATT_SN_LEN);
  389. GpsToTcpInfo.encryptMethod = TCP_ENCPT_DISABLE; //not encrypt
  390. GpsToTcpInfo.dataLength[0] = (DataLen >> 8) & 0xFF;
  391. GpsToTcpInfo.dataLength[1] = DataLen & 0xFF;
  392. GpsToTcpInfo.gpsInfo.sendTimeUTC[0] = (UTC8TimeTcp.year - 0x07D0) & 0xFF; //year
  393. GpsToTcpInfo.gpsInfo.sendTimeUTC[1] = UTC8TimeTcp.month & 0xFF; //month
  394. GpsToTcpInfo.gpsInfo.sendTimeUTC[2] = UTC8TimeTcp.day & 0xFF; //day
  395. GpsToTcpInfo.gpsInfo.sendTimeUTC[3] = UTC8TimeTcp.hour & 0xFF; //hour
  396. GpsToTcpInfo.gpsInfo.sendTimeUTC[4] = UTC8TimeTcp.minute & 0xFF; //mins
  397. GpsToTcpInfo.gpsInfo.sendTimeUTC[5] = UTC8TimeTcp.second & 0xFF; //sec
  398. GpsToTcpInfo.gpsInfo.msgMark = GPSMSG;
  399. GpsToTcpInfo.gpsInfo.msgCollectionTimeUTC[0] = (UTC8TimeTcp.year - 0x07D0) & 0xFF; //year
  400. GpsToTcpInfo.gpsInfo.msgCollectionTimeUTC[1] = UTC8TimeTcp.month & 0xFF; //month
  401. GpsToTcpInfo.gpsInfo.msgCollectionTimeUTC[2] = UTC8TimeTcp.day & 0xFF; //day
  402. GpsToTcpInfo.gpsInfo.msgCollectionTimeUTC[3] = UTC8TimeTcp.hour & 0xFF; //hour
  403. GpsToTcpInfo.gpsInfo.msgCollectionTimeUTC[4] = UTC8TimeTcp.minute & 0xFF; //mins
  404. GpsToTcpInfo.gpsInfo.msgCollectionTimeUTC[5] = UTC8TimeTcp.second & 0xFF;
  405. osStatus_t ret = osMessageQueueGet(GpsRecvHandle, &GpsRecvData, 0, 2000);
  406. if (ret == 0)
  407. {
  408. memcpy((UINT8 *)&GpsToTcpInfo.gpsInfo.locateMark, GpsRecvData, sizeof(GPSInfo));
  409. GpsToTcpInfo.gpsInfo.Tac[0] = tac >> 8;
  410. GpsToTcpInfo.gpsInfo.Tac[1] = tac & 0xFF;
  411. GpsToTcpInfo.gpsInfo.CellID[0] = cellId >> 24;
  412. GpsToTcpInfo.gpsInfo.CellID[0] = cellId >> 16;
  413. GpsToTcpInfo.gpsInfo.CellID[0] = cellId >> 8;
  414. GpsToTcpInfo.gpsInfo.CellID[0] = cellId;
  415. GpsToTcpInfo.CRC = bcc_chk((UINT8 *)&GpsToTcpInfo, sizeof(GPSMsgtoTcpType) - 1);
  416. //if(GpsToTcpInfo.gpsInfo.locateMark==0x01)
  417. if (1)
  418. {
  419. len = tcpipConnectionSend(socContext.id, (UINT8 *)&GpsToTcpInfo, sizeof(GpsToTcpInfo), 0, 0, 0);
  420. #ifdef USING_PRINTF1
  421. for (int i = 0; i < sizeof(GpsToTcpInfo); i++)
  422. {
  423. printf("%02x ", *((UINT8 *)&GpsToTcpInfo + i));
  424. }
  425. printf("-[%d]-Gpslen:%d\n", __LINE__, len);
  426. #endif
  427. if (len > 0)
  428. {
  429. TcpSendLen = 0x04 | TcpSendLen;
  430. }
  431. else
  432. {
  433. TcpSendLen = 0xFB & TcpSendLen;
  434. sendQueueMsg(QMSG_ID_NW_IP_SUSPEND, 0);
  435. }
  436. }
  437. }
  438. if (GpsRecvData != NULL)
  439. free(GpsRecvData);
  440. GpsRecvData = NULL;
  441. }
  442. if (send_counter == 1) //版本信息上报 上报频率为每次重启后上报或者每次更新后上报或者每天上报一次均可
  443. {
  444. VersionMsgtoTcpType VerMsgToTcpInfo;
  445. CHAR iccid[20];
  446. CHAR imei[15];
  447. appGetIccidNumSync(iccid);
  448. appGetImeiNumSync(imei);
  449. // CHAR *verData = NULL;
  450. // verData = appGetNBVersionInfo();
  451. // #ifdef USING_PRINTF
  452. // printf("verData:%s\n",verData);
  453. // #endif
  454. appGetSystemTimeUtcSync(&TimeStracture);
  455. year = (TimeStracture.UTCtimer1 & 0xffff0000) >> 16;
  456. month = (TimeStracture.UTCtimer1 & 0xff00) >> 8;
  457. day = TimeStracture.UTCtimer1 & 0xff;
  458. hour = (TimeStracture.UTCtimer2 & 0xff000000) >> 24;
  459. minute = (TimeStracture.UTCtimer2 & 0xff0000) >> 16;
  460. sec = (TimeStracture.UTCtimer2 & 0xff00) >> 8;
  461. UTCToBeijing((UTC8TimeType *)&UTC8TimeTcp, year, month, day, hour, minute, sec);
  462. DataLen = (UINT16)sizeof(VerMsgToTcpInfo.VerInfo);
  463. VerMsgToTcpInfo.startSymbol[0] = TCP_START_SYM1;
  464. VerMsgToTcpInfo.startSymbol[1] = TCP_START_SYM2;
  465. VerMsgToTcpInfo.cmdSymbol = TCP_CMD_SYM;
  466. VerMsgToTcpInfo.ansSymbol = TCP_ANS_SYM;
  467. memcpy(VerMsgToTcpInfo.SN, AppNVMData.battSN, BATT_SN_LEN);
  468. VerMsgToTcpInfo.encryptMethod = TCP_ENCPT_DISABLE; //not encrypt
  469. VerMsgToTcpInfo.dataLength[0] = (DataLen >> 8) & 0xFF;
  470. VerMsgToTcpInfo.dataLength[1] = DataLen & 0xFF;
  471. VerMsgToTcpInfo.VerInfo.sendTimeUTC[0] = (UTC8TimeTcp.year - 0x07D0) & 0xFF; //year
  472. VerMsgToTcpInfo.VerInfo.sendTimeUTC[1] = UTC8TimeTcp.month & 0xFF; //month
  473. VerMsgToTcpInfo.VerInfo.sendTimeUTC[2] = UTC8TimeTcp.day & 0xFF; //day
  474. VerMsgToTcpInfo.VerInfo.sendTimeUTC[3] = UTC8TimeTcp.hour & 0xFF; //hour
  475. VerMsgToTcpInfo.VerInfo.sendTimeUTC[4] = UTC8TimeTcp.minute & 0xFF; //mins
  476. VerMsgToTcpInfo.VerInfo.sendTimeUTC[5] = UTC8TimeTcp.second & 0xFF; //sec
  477. VerMsgToTcpInfo.VerInfo.msgMark = VERSIONMSG;
  478. VerMsgToTcpInfo.VerInfo.msgCollectionTimeUTC[0] = (UTC8TimeTcp.year - 0x07D0) & 0xFF; //year
  479. VerMsgToTcpInfo.VerInfo.msgCollectionTimeUTC[1] = UTC8TimeTcp.month & 0xFF; //month
  480. VerMsgToTcpInfo.VerInfo.msgCollectionTimeUTC[2] = UTC8TimeTcp.day & 0xFF; //day
  481. VerMsgToTcpInfo.VerInfo.msgCollectionTimeUTC[3] = UTC8TimeTcp.hour & 0xFF; //hour
  482. VerMsgToTcpInfo.VerInfo.msgCollectionTimeUTC[4] = UTC8TimeTcp.minute & 0xFF; //mins
  483. VerMsgToTcpInfo.VerInfo.msgCollectionTimeUTC[5] = UTC8TimeTcp.second & 0xFF;
  484. memcpy(VerMsgToTcpInfo.VerInfo.ICCID, iccid, 20);
  485. memcpy(VerMsgToTcpInfo.VerInfo.IMEI, imei, 15);
  486. VerMsgToTcpInfo.VerInfo.BMSHwVersion[0] = AppNVMData.BmsHwVersion / 10;
  487. VerMsgToTcpInfo.VerInfo.BMSHwVersion[1] = AppNVMData.BmsHwVersion % 10;
  488. VerMsgToTcpInfo.VerInfo.BMSSwVersion[0] = 0;
  489. VerMsgToTcpInfo.VerInfo.BMSSwVersion[1] = 0;
  490. VerMsgToTcpInfo.VerInfo.BMSSwVersion[2] = AppNVMData.BmsSwVersion / 10;
  491. VerMsgToTcpInfo.VerInfo.BMSSwVersion[3] = AppNVMData.BmsSwVersion % 10;
  492. VerMsgToTcpInfo.VerInfo.NBHwVersion[0] = (HWVERSION >> 8) & 0xFF;
  493. VerMsgToTcpInfo.VerInfo.NBHwVersion[1] = (HWVERSION)&0xFF;
  494. VerMsgToTcpInfo.VerInfo.BLVersion[0] = (BLSWVERSION >> 24) & 0xFF;
  495. VerMsgToTcpInfo.VerInfo.BLVersion[1] = (BLSWVERSION >> 16) & 0xFF;
  496. VerMsgToTcpInfo.VerInfo.BLVersion[2] = (BLSWVERSION >> 8) & 0xFF;
  497. VerMsgToTcpInfo.VerInfo.BLVersion[3] = (BLSWVERSION)&0xFF;
  498. VerMsgToTcpInfo.VerInfo.DRVVersion[0] = (DRVSWVERSION >> 24) & 0xFF;
  499. VerMsgToTcpInfo.VerInfo.DRVVersion[1] = (DRVSWVERSION >> 16) & 0xFF;
  500. VerMsgToTcpInfo.VerInfo.DRVVersion[2] = (DRVSWVERSION >> 8) & 0xFF;
  501. VerMsgToTcpInfo.VerInfo.DRVVersion[3] = (DRVSWVERSION)&0xFF;
  502. VerMsgToTcpInfo.VerInfo.APPVersion[0] = (APPSWVERSION >> 24) & 0xFF;
  503. VerMsgToTcpInfo.VerInfo.APPVersion[1] = (APPSWVERSION >> 16) & 0xFF;
  504. VerMsgToTcpInfo.VerInfo.APPVersion[2] = (APPSWVERSION >> 8) & 0xFF;
  505. VerMsgToTcpInfo.VerInfo.APPVersion[3] = (APPSWVERSION)&0xFF;
  506. VerMsgToTcpInfo.VerInfo.BmsType = BMS_MANUFACTURE;
  507. VerMsgToTcpInfo.VerInfo.BmsInfo = BMS_INFO;
  508. VerMsgToTcpInfo.VerInfo.DataModuleType = DATA_MODULE_TYPE;
  509. VerMsgToTcpInfo.CRC = bcc_chk((UINT8 *)&VerMsgToTcpInfo, sizeof(VerMsgToTcpInfo) - 1);
  510. if (NB_Fota_update_flag == FALSE)
  511. {
  512. len = tcpipConnectionSend(socContext.id, (UINT8 *)&VerMsgToTcpInfo, sizeof(VerMsgToTcpInfo), 0, 0, 0);
  513. if (len > 0)
  514. {
  515. TcpSendLen = 0x01 | TcpSendLen;
  516. }
  517. else
  518. {
  519. TcpSendLen = 0xFE & TcpSendLen;
  520. sendQueueMsg(QMSG_ID_NW_IP_SUSPEND, 0);
  521. }
  522. }
  523. }
  524. if ((send_counter) % (BattSendFreq * 3) == 0) //90发送
  525. {
  526. appGetSystemTimeUtcSync(&TimeStracture);
  527. year = (TimeStracture.UTCtimer1 & 0xffff0000) >> 16;
  528. month = (TimeStracture.UTCtimer1 & 0xff00) >> 8;
  529. day = TimeStracture.UTCtimer1 & 0xff;
  530. hour = (TimeStracture.UTCtimer2 & 0xff000000) >> 24;
  531. minute = (TimeStracture.UTCtimer2 & 0xff0000) >> 16;
  532. sec = (TimeStracture.UTCtimer2 & 0xff00) >> 8;
  533. UTCToBeijing((UTC8TimeType *)&UTC8TimeTcp, year, month, day, hour, minute, sec);
  534. UINT8 Tcptype = 0x90;
  535. UINT16 BufferLen = 0x56;
  536. SendBuffer = malloc(BufferLen);
  537. TcpDataAssemble(Tcptype, SendBuffer, UTC8TimeTcp);
  538. len = tcpipConnectionSend(socContext.id, SendBuffer, BufferLen, 0, 0, 0);
  539. #ifdef USING_PRINTF1
  540. printf("[%d]DebugMsg-[%d]:\n", __LINE__, len);
  541. for (UINT16 i = 0; i < BufferLen; i++)
  542. {
  543. printf("%02x ", *(SendBuffer + i));
  544. }
  545. printf("[%d]\n", __LINE__);
  546. #endif
  547. if (SendBuffer != NULL)
  548. {
  549. free(SendBuffer);
  550. }
  551. SendBuffer = NULL;
  552. if (len > 0)
  553. {
  554. ;
  555. }
  556. else
  557. {
  558. sendQueueMsg(QMSG_ID_NW_IP_SUSPEND, 0);
  559. }
  560. }
  561. if ((send_counter - 1) % BattSendFreq == 0) //91发送
  562. {
  563. appGetSystemTimeUtcSync(&TimeStracture);
  564. year = (TimeStracture.UTCtimer1 & 0xffff0000) >> 16;
  565. month = (TimeStracture.UTCtimer1 & 0xff00) >> 8;
  566. day = TimeStracture.UTCtimer1 & 0xff;
  567. hour = (TimeStracture.UTCtimer2 & 0xff000000) >> 24;
  568. minute = (TimeStracture.UTCtimer2 & 0xff0000) >> 16;
  569. sec = (TimeStracture.UTCtimer2 & 0xff00) >> 8;
  570. UTCToBeijing((UTC8TimeType *)&UTC8TimeTcp, year, month, day, hour, minute, sec);
  571. UINT8 Tcptype = 0x91;
  572. UINT16 BufferLen = 0x54 + CELL_NUM * 2 + CELL_TEMP_NUM;
  573. SendBuffer = malloc(BufferLen);
  574. TcpDataAssemble(Tcptype, SendBuffer, UTC8TimeTcp);
  575. len = tcpipConnectionSend(socContext.id, SendBuffer, BufferLen, 0, 0, 0);
  576. #ifdef USING_PRINTF1
  577. printf("[%d]0x91-[%d]:\n", __LINE__, len);
  578. for (UINT16 i = 0; i < BufferLen; i++)
  579. {
  580. printf("%02x ", *(SendBuffer + i));
  581. }
  582. printf("[%d]\n", __LINE__);
  583. #endif
  584. if (SendBuffer != NULL)
  585. {
  586. free(SendBuffer);
  587. }
  588. SendBuffer = NULL;
  589. if (len > 0)
  590. {
  591. ;
  592. }
  593. else
  594. {
  595. sendQueueMsg(QMSG_ID_NW_IP_SUSPEND, 0);
  596. }
  597. }
  598. if ((send_counter - 2) % (BattSendFreq * 4) == 0) //92发送
  599. {
  600. appGetSystemTimeUtcSync(&TimeStracture);
  601. year = (TimeStracture.UTCtimer1 & 0xffff0000) >> 16;
  602. month = (TimeStracture.UTCtimer1 & 0xff00) >> 8;
  603. day = TimeStracture.UTCtimer1 & 0xff;
  604. hour = (TimeStracture.UTCtimer2 & 0xff000000) >> 24;
  605. minute = (TimeStracture.UTCtimer2 & 0xff0000) >> 16;
  606. sec = (TimeStracture.UTCtimer2 & 0xff00) >> 8;
  607. UTCToBeijing((UTC8TimeType *)&UTC8TimeTcp, year, month, day, hour, minute, sec);
  608. UINT8 Tcptype = 0x92;
  609. UINT16 BufferLen = 0x4E;
  610. SendBuffer = malloc(BufferLen);
  611. TcpDataAssemble(Tcptype, SendBuffer, UTC8TimeTcp);
  612. len = tcpipConnectionSend(socContext.id, SendBuffer, BufferLen, 0, 0, 0);
  613. #ifdef USING_PRINTF1
  614. printf("[%d]DebugMsg-[%d]:\n", __LINE__, len);
  615. for (UINT16 i = 0; i < BufferLen; i++)
  616. {
  617. printf("%02x ", *(SendBuffer + i));
  618. }
  619. printf("[%d]\n", __LINE__);
  620. #endif
  621. if (SendBuffer != NULL)
  622. {
  623. free(SendBuffer);
  624. }
  625. SendBuffer = NULL;
  626. if (len > 0)
  627. {
  628. ;
  629. }
  630. else
  631. {
  632. sendQueueMsg(QMSG_ID_NW_IP_SUSPEND, 0);
  633. }
  634. }
  635. /*调试信息字符发送形式,但是发送流量会大2倍
  636. if((send_counter)%10==0)//90发送
  637. {
  638. appGetSystemTimeUtcSync(&TimeStracture);
  639. year=(TimeStracture.UTCtimer1&0xffff0000)>>16;
  640. month=(TimeStracture.UTCtimer1&0xff00)>>8;
  641. day=TimeStracture.UTCtimer1&0xff;
  642. hour=(TimeStracture.UTCtimer2&0xff000000)>>24;
  643. minute=(TimeStracture.UTCtimer2&0xff0000)>>16;
  644. sec=(TimeStracture.UTCtimer2&0xff00)>>8;
  645. UTCToBeijing((UTC8TimeType *)&UTC8TimeTcp,year,month,day,hour,minute,sec);
  646. DebugMsgtoTcpType DebugMsgInfo;
  647. UINT8 Tcptype =0x90;
  648. UINT16 BufferLen1 = 0x55,BufferLen = 0;
  649. UINT8 *rbuf = NULL;
  650. rbuf = malloc(BufferLen1);
  651. BufferLen = BufferLen1*2;
  652. SendBuffer = malloc(BufferLen+sizeof(DebugMsgInfo));
  653. TcpDataAssemble(Tcptype,rbuf,UTC8TimeTcp);
  654. for(UINT16 i=0;i<BufferLen1;i++)
  655. {
  656. sprintf((char *)(SendBuffer+sizeof(DebugMsgInfo)-1+i*2),"%02x",*(rbuf+i));
  657. }
  658. if(rbuf!=NULL)
  659. {
  660. free(rbuf);
  661. }
  662. rbuf=NULL;
  663. DataLen=sizeof(DebugMsgInfo.DebugInfo) + BufferLen;
  664. DebugMsgInfo.startSymbol[0] = TCP_START_SYM1;
  665. DebugMsgInfo.startSymbol[1] = TCP_START_SYM2;
  666. DebugMsgInfo.cmdSymbol = TCP_CMD_SYM;
  667. DebugMsgInfo.ansSymbol = TCP_ANS_SYM;
  668. memcpy(DebugMsgInfo.SN, AppNVMData.battSN,BATT_SN_LEN);
  669. DebugMsgInfo.encryptMethod = TCP_ENCPT_DISABLE; //not encrypt
  670. DebugMsgInfo.dataLength[0] = (DataLen>>8) & 0xFF;
  671. DebugMsgInfo.dataLength[1] = DataLen & 0xFF;
  672. DebugMsgInfo.DebugInfo.sendTimeUTC[0] = (UTC8TimeTcp.year - 0x07D0) & 0xFF; //year
  673. DebugMsgInfo.DebugInfo.sendTimeUTC[1] = UTC8TimeTcp.month & 0xFF; //month
  674. DebugMsgInfo.DebugInfo.sendTimeUTC[2] = UTC8TimeTcp.day & 0xFF; //day
  675. DebugMsgInfo.DebugInfo.sendTimeUTC[3] = UTC8TimeTcp.hour & 0xFF; //hour
  676. DebugMsgInfo.DebugInfo.sendTimeUTC[4] = UTC8TimeTcp.minute & 0xFF; //mins
  677. DebugMsgInfo.DebugInfo.sendTimeUTC[5] = UTC8TimeTcp.second & 0xFF; //sec
  678. DebugMsgInfo.DebugInfo.msgMark = DEBUGMSG;
  679. DebugMsgInfo.DebugInfo.DebugLen[0] = BufferLen>>8;
  680. DebugMsgInfo.DebugInfo.DebugLen[1] = BufferLen;
  681. memcpy(SendBuffer,(UINT8 *)&DebugMsgInfo,sizeof(DebugMsgInfo)-1);
  682. DebugMsgInfo.CRC = bcc_chk(SendBuffer, BufferLen+sizeof(DebugMsgInfo)-1);
  683. memcpy(SendBuffer+BufferLen+sizeof(DebugMsgInfo)-1,&DebugMsgInfo.CRC,1);
  684. len = tcpipConnectionSend(socContext.id, SendBuffer, BufferLen+sizeof(DebugMsgInfo), 0, 0, 0);
  685. #ifdef USING_PRINTF
  686. printf("[%d]DebugMsg-[%d]-[%d]:\n",__LINE__,BufferLen,len);
  687. #endif
  688. #ifdef USING_PRINTF1
  689. printf("[%d]DebugMsg-[%d]:\n",__LINE__,len);
  690. for (UINT16 i = 0; i < BufferLen*2+sizeof(DebugMsgInfo); i++)
  691. {
  692. printf("%02x ",*(SendBuffer + i));
  693. }
  694. #endif
  695. if(SendBuffer!=NULL)
  696. {
  697. free(SendBuffer);
  698. }
  699. SendBuffer=NULL;
  700. }
  701. if((send_counter+1)%10==0)//91发送
  702. {
  703. appGetSystemTimeUtcSync(&TimeStracture);
  704. year=(TimeStracture.UTCtimer1&0xffff0000)>>16;
  705. month=(TimeStracture.UTCtimer1&0xff00)>>8;
  706. day=TimeStracture.UTCtimer1&0xff;
  707. hour=(TimeStracture.UTCtimer2&0xff000000)>>24;
  708. minute=(TimeStracture.UTCtimer2&0xff0000)>>16;
  709. sec=(TimeStracture.UTCtimer2&0xff00)>>8;
  710. UTCToBeijing((UTC8TimeType *)&UTC8TimeTcp,year,month,day,hour,minute,sec);
  711. DebugMsgtoTcpType DebugMsgInfo;
  712. UINT8 Tcptype =0x91;
  713. UINT16 BufferLen1 = 0x53 + numOfCells*2 + numOfCellTemp,BufferLen = 0;
  714. UINT8 *rbuf = NULL;
  715. BufferLen = BufferLen1*2;
  716. rbuf = malloc(BufferLen1);
  717. SendBuffer = malloc(BufferLen+sizeof(DebugMsgInfo));
  718. TcpDataAssemble(Tcptype,rbuf,UTC8TimeTcp);
  719. for(UINT16 i=0;i<BufferLen1;i++)
  720. {
  721. sprintf((char *)(SendBuffer+sizeof(DebugMsgInfo)-1+i*2),"%02x",*(rbuf+i));
  722. }
  723. if(rbuf!=NULL)
  724. {
  725. free(rbuf);
  726. }
  727. rbuf=NULL;
  728. DataLen=sizeof(DebugMsgInfo.DebugInfo) + BufferLen;
  729. DebugMsgInfo.startSymbol[0] = TCP_START_SYM1;
  730. DebugMsgInfo.startSymbol[1] = TCP_START_SYM2;
  731. DebugMsgInfo.cmdSymbol = TCP_CMD_SYM;
  732. DebugMsgInfo.ansSymbol = TCP_ANS_SYM;
  733. memcpy(DebugMsgInfo.SN, AppNVMData.battSN,BATT_SN_LEN);
  734. DebugMsgInfo.encryptMethod = TCP_ENCPT_DISABLE; //not encrypt
  735. DebugMsgInfo.dataLength[0] = (DataLen>>8) & 0xFF;
  736. DebugMsgInfo.dataLength[1] = DataLen & 0xFF;
  737. DebugMsgInfo.DebugInfo.sendTimeUTC[0] = (UTC8TimeTcp.year - 0x07D0) & 0xFF; //year
  738. DebugMsgInfo.DebugInfo.sendTimeUTC[1] = UTC8TimeTcp.month & 0xFF; //month
  739. DebugMsgInfo.DebugInfo.sendTimeUTC[2] = UTC8TimeTcp.day & 0xFF; //day
  740. DebugMsgInfo.DebugInfo.sendTimeUTC[3] = UTC8TimeTcp.hour & 0xFF; //hour
  741. DebugMsgInfo.DebugInfo.sendTimeUTC[4] = UTC8TimeTcp.minute & 0xFF; //mins
  742. DebugMsgInfo.DebugInfo.sendTimeUTC[5] = UTC8TimeTcp.second & 0xFF; //sec
  743. DebugMsgInfo.DebugInfo.msgMark = DEBUGMSG;
  744. DebugMsgInfo.DebugInfo.DebugLen[0] = BufferLen>>8;
  745. DebugMsgInfo.DebugInfo.DebugLen[1] = BufferLen;
  746. memcpy(SendBuffer,(UINT8 *)&DebugMsgInfo,sizeof(DebugMsgInfo)-1);
  747. DebugMsgInfo.CRC = bcc_chk(SendBuffer, BufferLen+sizeof(DebugMsgInfo)-1);
  748. memcpy(SendBuffer+BufferLen+sizeof(DebugMsgInfo)-1,&DebugMsgInfo.CRC,1);
  749. len = tcpipConnectionSend(socContext.id, SendBuffer, BufferLen+sizeof(DebugMsgInfo), 0, 0, 0);
  750. #ifdef USING_PRINTF
  751. printf("[%d]DebugMsg-[%d]-[%d]:\n",__LINE__,BufferLen,len);
  752. #endif
  753. #ifdef USING_PRINTF1
  754. printf("[%d]DebugMsg-[%d]:\n",__LINE__,len);
  755. for (UINT16 i = 0; i < BufferLen*2+sizeof(DebugMsgInfo); i++)
  756. {
  757. printf("%c ",*(SendBuffer + i));
  758. }
  759. #endif
  760. if(SendBuffer!=NULL)
  761. {
  762. free(SendBuffer);
  763. }
  764. SendBuffer=NULL;
  765. }
  766. if((send_counter+2)%60==0)//92发送
  767. {
  768. appGetSystemTimeUtcSync(&TimeStracture);
  769. year=(TimeStracture.UTCtimer1&0xffff0000)>>16;
  770. month=(TimeStracture.UTCtimer1&0xff00)>>8;
  771. day=TimeStracture.UTCtimer1&0xff;
  772. hour=(TimeStracture.UTCtimer2&0xff000000)>>24;
  773. minute=(TimeStracture.UTCtimer2&0xff0000)>>16;
  774. sec=(TimeStracture.UTCtimer2&0xff00)>>8;
  775. UTCToBeijing((UTC8TimeType *)&UTC8TimeTcp,year,month,day,hour,minute,sec);
  776. DebugMsgtoTcpType DebugMsgInfo;
  777. UINT8 Tcptype =0x92;
  778. UINT16 BufferLen1 = 0x4D,BufferLen = 0;
  779. UINT8 *rbuf = NULL;
  780. rbuf = malloc(BufferLen1);
  781. BufferLen = BufferLen1*2;
  782. SendBuffer = malloc(BufferLen+sizeof(DebugMsgInfo));
  783. TcpDataAssemble(Tcptype,rbuf,UTC8TimeTcp);
  784. for(UINT16 i=0;i<BufferLen1;i++)
  785. {
  786. sprintf((char *)(SendBuffer+sizeof(DebugMsgInfo)-1+i*2),"%02x",*(rbuf+i));
  787. }
  788. if(rbuf!=NULL)
  789. {
  790. free(rbuf);
  791. }
  792. rbuf=NULL;
  793. #ifdef USING_PRINTF
  794. printf("[%d]DebugMsg-[%d]:\n",__LINE__,BufferLen);
  795. #endif
  796. DataLen=sizeof(DebugMsgInfo.DebugInfo) + BufferLen;
  797. DebugMsgInfo.startSymbol[0] = TCP_START_SYM1;
  798. DebugMsgInfo.startSymbol[1] = TCP_START_SYM2;
  799. DebugMsgInfo.cmdSymbol = TCP_CMD_SYM;
  800. DebugMsgInfo.ansSymbol = TCP_ANS_SYM;
  801. memcpy(DebugMsgInfo.SN, AppNVMData.battSN,BATT_SN_LEN);
  802. DebugMsgInfo.encryptMethod = TCP_ENCPT_DISABLE; //not encrypt
  803. DebugMsgInfo.dataLength[0] = (DataLen>>8) & 0xFF;
  804. DebugMsgInfo.dataLength[1] = DataLen & 0xFF;
  805. DebugMsgInfo.DebugInfo.sendTimeUTC[0] = (UTC8TimeTcp.year - 0x07D0) & 0xFF; //year
  806. DebugMsgInfo.DebugInfo.sendTimeUTC[1] = UTC8TimeTcp.month & 0xFF; //month
  807. DebugMsgInfo.DebugInfo.sendTimeUTC[2] = UTC8TimeTcp.day & 0xFF; //day
  808. DebugMsgInfo.DebugInfo.sendTimeUTC[3] = UTC8TimeTcp.hour & 0xFF; //hour
  809. DebugMsgInfo.DebugInfo.sendTimeUTC[4] = UTC8TimeTcp.minute & 0xFF; //mins
  810. DebugMsgInfo.DebugInfo.sendTimeUTC[5] = UTC8TimeTcp.second & 0xFF; //sec
  811. DebugMsgInfo.DebugInfo.msgMark = DEBUGMSG;
  812. DebugMsgInfo.DebugInfo.DebugLen[0] = BufferLen>>8;
  813. DebugMsgInfo.DebugInfo.DebugLen[1] = BufferLen;
  814. memcpy(SendBuffer,(UINT8 *)&DebugMsgInfo,sizeof(DebugMsgInfo)-1);
  815. DebugMsgInfo.CRC = bcc_chk(SendBuffer, BufferLen+sizeof(DebugMsgInfo)-1);
  816. memcpy(SendBuffer+BufferLen+sizeof(DebugMsgInfo)-1,&DebugMsgInfo.CRC,1);
  817. len = tcpipConnectionSend(socContext.id, SendBuffer, BufferLen+sizeof(DebugMsgInfo), 0, 0, 0);
  818. #ifdef USING_PRINTF1
  819. printf("[%d]DebugMsg-[%d]:\n",__LINE__,len);
  820. for (UINT16 i = 0; i < BufferLen*2+sizeof(DebugMsgInfo); i++)
  821. {
  822. printf("%c ",*(SendBuffer + i));
  823. }
  824. #endif
  825. if(SendBuffer!=NULL)
  826. {
  827. free(SendBuffer);
  828. }
  829. SendBuffer=NULL;
  830. }
  831. */
  832. /*
  833. if(FALSE)//调试信息暂时不发,需调整之后发送
  834. {
  835. DebugMsgtoTcpType DebugMsgInfo;
  836. UINT16 BufferLen = 0;
  837. slpManWakeSrc_e Wakeup_source;
  838. Wakeup_source = slpManGetWakeupSrc();//获取唤醒源
  839. #ifdef DEBUGLOG
  840. Debug_printf("[%d]\n",Wakeup_source);
  841. #endif
  842. BufferLen = Debug_GetSize();
  843. if(BufferLen==0)
  844. {
  845. send_counter++;
  846. return;
  847. }
  848. else if(BufferLen>200)
  849. {
  850. Debug_Del_Logfile();
  851. #ifdef DEBUGLOG
  852. Debug_printf("oversize-Sys:%d\n",AppDataInfo.SysReStartCount);
  853. #endif
  854. BufferLen = Debug_GetSize();
  855. }
  856. UINT8 rbuf[BufferLen];
  857. Debug_Read_Logfile(rbuf,BufferLen);
  858. SendBuffer = malloc(BufferLen+sizeof(DebugMsgInfo));
  859. memcpy(SendBuffer+sizeof(DebugMsgInfo)-1, rbuf,BufferLen);
  860. appGetSystemTimeUtcSync(&TimeStracture);
  861. year=(TimeStracture.UTCtimer1&0xffff0000)>>16;
  862. month=(TimeStracture.UTCtimer1&0xff00)>>8;
  863. day=TimeStracture.UTCtimer1&0xff;
  864. hour=(TimeStracture.UTCtimer2&0xff000000)>>24;
  865. minute=(TimeStracture.UTCtimer2&0xff0000)>>16;
  866. sec=(TimeStracture.UTCtimer2&0xff00)>>8;
  867. UTCToBeijing((UTC8TimeType *)&UTC8TimeTcp,year,month,day,hour,minute,sec);
  868. DataLen=sizeof(DebugMsgInfo.DebugInfo) + BufferLen;
  869. DebugMsgInfo.startSymbol[0] = TCP_START_SYM1;
  870. DebugMsgInfo.startSymbol[1] = TCP_START_SYM2;
  871. DebugMsgInfo.cmdSymbol = TCP_CMD_SYM;
  872. DebugMsgInfo.ansSymbol = TCP_ANS_SYM;
  873. memcpy(DebugMsgInfo.SN, AppNVMData.battSN,BATT_SN_LEN);
  874. DebugMsgInfo.encryptMethod = TCP_ENCPT_DISABLE; //not encrypt
  875. DebugMsgInfo.dataLength[0] = (DataLen>>8) & 0xFF;
  876. DebugMsgInfo.dataLength[1] = DataLen & 0xFF;
  877. DebugMsgInfo.DebugInfo.sendTimeUTC[0] = (UTC8TimeTcp.year - 0x07D0) & 0xFF; //year
  878. DebugMsgInfo.DebugInfo.sendTimeUTC[1] = UTC8TimeTcp.month & 0xFF; //month
  879. DebugMsgInfo.DebugInfo.sendTimeUTC[2] = UTC8TimeTcp.day & 0xFF; //day
  880. DebugMsgInfo.DebugInfo.sendTimeUTC[3] = UTC8TimeTcp.hour & 0xFF; //hour
  881. DebugMsgInfo.DebugInfo.sendTimeUTC[4] = UTC8TimeTcp.minute & 0xFF; //mins
  882. DebugMsgInfo.DebugInfo.sendTimeUTC[5] = UTC8TimeTcp.second & 0xFF; //sec
  883. DebugMsgInfo.DebugInfo.msgMark = DEBUGMSG;
  884. DebugMsgInfo.DebugInfo.DebugLen[0] = BufferLen>>8;
  885. DebugMsgInfo.DebugInfo.DebugLen[1] = BufferLen;
  886. memcpy(SendBuffer,(UINT8 *)&DebugMsgInfo,sizeof(DebugMsgInfo)-1);
  887. DebugMsgInfo.CRC = bcc_chk(SendBuffer, BufferLen+sizeof(DebugMsgInfo)-1);
  888. memcpy(SendBuffer+BufferLen+sizeof(DebugMsgInfo)-1,&DebugMsgInfo.CRC,1);
  889. len = tcpipConnectionSend(socContext.id, SendBuffer, BufferLen+sizeof(DebugMsgInfo), 0, 0, 0);
  890. #ifdef USING_PRINTF1
  891. printf("DebugMsg-[%d]:\n",len);
  892. // for (int i = 0; i < BufferLen+sizeof(DebugMsgInfo); i++)
  893. // {
  894. // printf("%02x ",*(SendBuffer + i));
  895. // }
  896. #endif
  897. if(len>0)
  898. {
  899. Debug_Del_Logfile();
  900. }
  901. if(SendBuffer!=NULL)
  902. {
  903. free(SendBuffer);
  904. }
  905. SendBuffer=NULL;
  906. }
  907. */
  908. if (send_counter > 0xffff)
  909. {
  910. send_counter = 0;
  911. }
  912. else
  913. {
  914. send_counter++;
  915. }
  916. }
  917. static void TcpHeartDataSend()
  918. {
  919. UINT8 len = 0;
  920. HeartMsgtoTcpType HeartMsgToTcp;
  921. HeartMsgToTcp.startSymbol[0] = TCP_START_SYM1;
  922. HeartMsgToTcp.startSymbol[1] = TCP_START_SYM2;
  923. HeartMsgToTcp.cmdSymbol = TCP_HEART_SYM;
  924. HeartMsgToTcp.ansSymbol = TCP_ANS_SYM;
  925. memcpy(HeartMsgToTcp.SN, AppNVMData.battSN, BATT_SN_LEN);
  926. HeartMsgToTcp.encryptMethod = TCP_ENCPT_DISABLE; //not encrypt
  927. HeartMsgToTcp.dataLength[0] = 0;
  928. HeartMsgToTcp.dataLength[1] = 0;
  929. HeartMsgToTcp.CRC = bcc_chk((UINT8 *)&HeartMsgToTcp, sizeof(HeartMsgToTcp) - 1);
  930. len = tcpipConnectionSend(socContext.id, (UINT8 *)&HeartMsgToTcp, sizeof(HeartMsgToTcp), 0, 0, 0);
  931. if (len < 0)
  932. {
  933. sendQueueMsg(QMSG_ID_NW_IP_SUSPEND, 0);
  934. }
  935. #ifdef USING_PRINTF1
  936. printf("HeartMsg-[%d]:\n", len);
  937. for (int i = 0; i < sizeof(HeartMsgToTcp); i++)
  938. printf("%02x ", *((UINT8 *)&HeartMsgToTcp + i));
  939. #endif
  940. }
  941. static void TcpDataInfoRecvHandle()
  942. {
  943. TcpipConnectionRecvDataInd *TcpRecvData = NULL;
  944. osMessageQueueGet(TcpRecvHandle, &TcpRecvData, 0, 0);
  945. UINT8 Tcp_Cmd;
  946. UINT8 *Ptr;
  947. UINT8 TcpCmdAnswer[31];
  948. TcpCmdAnswer[0] = TCP_START_SYM1;
  949. TcpCmdAnswer[1] = TCP_START_SYM1;
  950. if (TcpRecvData != NULL && TcpRecvData->length != 0)
  951. {
  952. Ptr = TcpRecvData->data;
  953. if ((*(Ptr + 0) == TCP_START_SYM1) && (*(Ptr + 1) == TCP_START_SYM2)) //服务器起始信息
  954. {
  955. Tcp_Cmd = *(Ptr + 2); //命令标志
  956. if (*(Ptr + 3) == 0xFE)
  957. {
  958. TCPWorkState = 0x01;
  959. }
  960. switch (Tcp_Cmd)
  961. {
  962. case TCP_QUERY_SYM:
  963. break;
  964. case TCP_SETCMD_SYM:
  965. break;
  966. case TCP_CONCMD_SYM:
  967. {
  968. TcpCmdAnswer[2] = TCP_CONCMD_SYM;
  969. if (*(Ptr + 30) == 0x01) //远程升级命令
  970. {
  971. Fota_Func(Ptr, socContext.id);
  972. }
  973. else if (*(Ptr + 30) == 0x88) //BMS远程升级数据传输命令
  974. {
  975. Fota_Func(Ptr, socContext.id);
  976. }
  977. else
  978. {
  979. TcpCmdAnswer[3] = 0x0f;
  980. memcpy(&TcpCmdAnswer[4], (Ptr + 4), BATT_SN_LEN);
  981. TcpCmdAnswer[21] = TCP_ENCPT_DISABLE;
  982. TcpCmdAnswer[22] = 0x00;
  983. TcpCmdAnswer[23] = 0x06;
  984. memcpy(&TcpCmdAnswer[24], (Ptr + 24), 6);
  985. TcpCmdAnswer[30] = bcc_chk(TcpCmdAnswer, 30);
  986. tcpipConnectionSend(socContext.id, TcpCmdAnswer, 31, 0, 0, 0);
  987. }
  988. break;
  989. }
  990. default:
  991. {
  992. break;
  993. }
  994. }
  995. }
  996. if (TcpRecvData != NULL)
  997. {
  998. free(TcpRecvData);
  999. }
  1000. TcpRecvData = NULL;
  1001. }
  1002. }
  1003. //Tcp线程初始化
  1004. void AppTaskTcpInit(void *arg)
  1005. {
  1006. osThreadAttr_t task_attr;
  1007. registerPSEventCallback(NB_GROUP_ALL_MASK, socketRegisterPSUrcCallback);
  1008. memset(&task_attr, 0, sizeof(task_attr));
  1009. memset(gProcess_Tcp_TaskStack, 0xA5, PROC_TCP_TASK_STACK_SIZE);
  1010. task_attr.name = "Tcp_Task";
  1011. task_attr.stack_mem = gProcess_Tcp_TaskStack;
  1012. task_attr.stack_size = PROC_TCP_TASK_STACK_SIZE;
  1013. task_attr.priority = osPriorityBelowNormal7;
  1014. task_attr.cb_mem = &gProcess_Tcp_Task_t;
  1015. task_attr.cb_size = sizeof(StaticTask_t);
  1016. TcpTaskId = osThreadNew(TcpTask, NULL, &task_attr);
  1017. }
  1018. void AppTaskTcpDeInit(void *arg)
  1019. {
  1020. osThreadTerminate(TcpTaskId);
  1021. TcpTaskId = NULL;
  1022. }
  1023. //Tcp 状态转换函数
  1024. static void sendQueueMsg(UINT32 msgId, UINT32 xTickstoWait)
  1025. {
  1026. eventCallbackMessage_t *queueMsg = NULL;
  1027. queueMsg = malloc(sizeof(eventCallbackMessage_t));
  1028. queueMsg->messageId = msgId;
  1029. if (psEventQueueHandle)
  1030. {
  1031. if (pdTRUE != xQueueSend(psEventQueueHandle, &queueMsg, xTickstoWait))
  1032. {
  1033. ECOMM_TRACE(UNILOG_PLA_APP, sendQueueMsg_1, P_ERROR, 0, "xQueueSend error");
  1034. }
  1035. }
  1036. }
  1037. //Tcp状态注册函数
  1038. static INT32 socketRegisterPSUrcCallback(urcID_t eventID, void *param, UINT32 paramLen)
  1039. {
  1040. CmiSimImsiStr *imsi = NULL;
  1041. CmiPsCeregInd *cereg = NULL;
  1042. NmAtiNetifInfo *netif = NULL;
  1043. switch (eventID)
  1044. {
  1045. case NB_URC_ID_SIM_READY:
  1046. {
  1047. imsi = (CmiSimImsiStr *)param;
  1048. memcpy(gImsi, imsi->contents, imsi->length);
  1049. #ifdef USING_PRINTF
  1050. printf("SIM ready(imsi=%s)\n", (UINT8 *)imsi->contents);
  1051. #endif
  1052. break;
  1053. }
  1054. case NB_URC_ID_MM_SIGQ:
  1055. {
  1056. //rssi = *(UINT8 *)param;
  1057. #ifdef USING_PRINTF1
  1058. printf("RSSI signal=%d\n", rssi);
  1059. #endif
  1060. break;
  1061. }
  1062. case NB_URC_ID_PS_BEARER_ACTED:
  1063. {
  1064. #ifdef USING_PRINTF
  1065. printf("Default bearer activated\n");
  1066. #endif
  1067. break;
  1068. }
  1069. case NB_URC_ID_PS_BEARER_DEACTED:
  1070. {
  1071. #ifdef USING_PRINTF
  1072. printf("Default bearer Deactivated\n");
  1073. #endif
  1074. break;
  1075. }
  1076. case NB_URC_ID_PS_CEREG_CHANGED:
  1077. {
  1078. cereg = (CmiPsCeregInd *)param;
  1079. gCellID = cereg->celId;
  1080. #ifdef USING_PRINTF
  1081. printf("URCCallBack:CEREG changed act:%d celId:%d locPresent:%d tac:%d\n", cereg->act, cereg->celId, cereg->locPresent, cereg->tac);
  1082. #endif
  1083. break;
  1084. }
  1085. case NB_URC_ID_PS_NETINFO:
  1086. {
  1087. netif = (NmAtiNetifInfo *)param;
  1088. if (netif->netStatus == NM_NETIF_ACTIVATED)
  1089. sendQueueMsg(QMSG_ID_NW_IP_READY, 0);
  1090. break;
  1091. }
  1092. }
  1093. return 0;
  1094. }
  1095. //Tcpz连接状态回调函数
  1096. static void socketAppConnectionCallBack(UINT8 connectionEventType, void *bodyEvent)
  1097. {
  1098. switch (connectionEventType)
  1099. {
  1100. case TCPIP_CONNECTION_STATUS_EVENT:
  1101. {
  1102. TcpipConnectionStatusInd *statusInd;
  1103. statusInd = (TcpipConnectionStatusInd *)bodyEvent;
  1104. if (statusInd != PNULL)
  1105. {
  1106. if (statusInd->status == TCPIP_CONNECTION_STATUS_CLOSED)
  1107. {
  1108. #ifdef USING_PRINTF
  1109. printf("socketAppConnectionCallBack socket connection %u closed,cause %u", statusInd->connectionId, statusInd->cause);
  1110. #endif
  1111. ECOMM_TRACE(UNILOG_PLA_APP, socketAppConnectionCallBack_1, P_ERROR, 2, "socketAppConnectionCallBack socket connection %u closed,cause %u", statusInd->connectionId, statusInd->cause);
  1112. if (statusInd->connectionId == socContext.id)
  1113. {
  1114. socContext.id = -1;
  1115. socContext.status = APP_SOCKET_CONNECTION_CLOSED;
  1116. }
  1117. }
  1118. else if (statusInd->status == TCPIP_CONNECTION_STATUS_CONNECTING)
  1119. {
  1120. #ifdef USING_PRINTF
  1121. printf("socketAppConnectionCallBack socket connection %u is connecting", statusInd->connectionId);
  1122. #endif
  1123. ECOMM_TRACE(UNILOG_PLA_APP, socketAppConnectionCallBack_2, P_INFO, 1, "socketAppConnectionCallBack socket connection %u is connecting", statusInd->connectionId);
  1124. if (statusInd->connectionId == socContext.id)
  1125. {
  1126. socContext.status = APP_SOCKET_CONNECTION_CONNECTING;
  1127. }
  1128. }
  1129. else if (statusInd->status == TCPIP_CONNECTION_STATUS_CONNECTED)
  1130. {
  1131. #ifdef USING_PRINTF
  1132. printf("socketAppConnectionCallBack socket connection %u is connected", statusInd->connectionId);
  1133. #endif
  1134. ECOMM_TRACE(UNILOG_PLA_APP, socketAppConnectionCallBack_3, P_ERROR, 1, "socketAppConnectionCallBack socket connection %u is connected", statusInd->connectionId);
  1135. if (statusInd->connectionId == socContext.id)
  1136. {
  1137. socContext.status = APP_SOCKET_CONNECTION_CONNECTED;
  1138. }
  1139. }
  1140. }
  1141. else
  1142. {
  1143. #ifdef USING_PRINTF
  1144. printf("socketAppConnectionCallBack invalid connection status event");
  1145. #endif
  1146. ECOMM_TRACE(UNILOG_PLA_APP, socketAppConnectionCallBack_4, P_ERROR, 0, "socketAppConnectionCallBack invalid connection status event");
  1147. }
  1148. break;
  1149. }
  1150. case TCPIP_CONNECTION_RECEIVE_EVENT:
  1151. {
  1152. TcpipConnectionRecvDataInd *rcvInd = PNULL;
  1153. TcpipConnectionRecvDataInd *rcvbuffer = NULL;
  1154. rcvInd = (TcpipConnectionRecvDataInd *)bodyEvent;
  1155. if (rcvInd != PNULL)
  1156. {
  1157. rcvbuffer = malloc(sizeof(TcpipConnectionRecvDataInd));
  1158. memcpy(rcvbuffer, rcvInd, sizeof(TcpipConnectionRecvDataInd));
  1159. osMessageQueuePut(TcpRecvHandle, &rcvbuffer, 0, 1000);
  1160. sendQueueMsg(QMSG_ID_SOCK_RECVPKG, 0);
  1161. #ifdef USING_PRINTF
  1162. // uint8_t* Ptr;
  1163. // Ptr=rcvInd->data;
  1164. printf("socket connection %u receive length %u data:\n", rcvInd->connectionId, rcvInd->length);
  1165. // for(int i = 0;i<rcvInd->length;i++)
  1166. // printf("%x ",*(Ptr+i));
  1167. // printf("\n");
  1168. #endif
  1169. ECOMM_TRACE(UNILOG_PLA_APP, socketAppConnectionCallBack_5, P_INFO, 2, "socketAppConnectionCallBack socket connection %u receive length %u data", rcvInd->connectionId, rcvInd->length);
  1170. }
  1171. else
  1172. {
  1173. #ifdef USING_PRINTF
  1174. printf("socketAppConnectionCallBack invalid connection rcv event");
  1175. #endif
  1176. ECOMM_TRACE(UNILOG_PLA_APP, socketAppConnectionCallBack_6, P_ERROR, 0, "socketAppConnectionCallBack invalid connection rcv event");
  1177. }
  1178. break;
  1179. }
  1180. case TCPIP_CONNECTION_UL_STATUS_EVENT:
  1181. {
  1182. TcpipConnectionUlDataStatusInd *ulStatusInd;
  1183. ulStatusInd = (TcpipConnectionUlDataStatusInd *)bodyEvent;
  1184. if (ulStatusInd != PNULL)
  1185. {
  1186. if (ulStatusInd->status == Tcpip_Connection_UL_DATA_SUCCESS)
  1187. {
  1188. #ifdef USING_PRINTF
  1189. printf("socketAppConnectionCallBack socket connection %u sequence %u data has sent success", ulStatusInd->connectionId, ulStatusInd->sequence);
  1190. #endif
  1191. ECOMM_TRACE(UNILOG_PLA_APP, socketAppConnectionCallBack_7, P_INFO, 2, "socketAppConnectionCallBack socket connection %u sequence %u data has sent success", ulStatusInd->connectionId, ulStatusInd->sequence);
  1192. }
  1193. else if (ulStatusInd->status == Tcpip_Connection_UL_DATA_FAIL)
  1194. {
  1195. #ifdef USING_PRINTF
  1196. printf("socketAppConnectionCallBack socket connection %u sequence %u data has sent fail", ulStatusInd->connectionId, ulStatusInd->sequence);
  1197. #endif
  1198. ECOMM_TRACE(UNILOG_PLA_APP, socketAppConnectionCallBack_8, P_WARNING, 2, "socketAppConnectionCallBack socket connection %u sequence %u data has sent fail", ulStatusInd->connectionId, ulStatusInd->sequence);
  1199. }
  1200. }
  1201. else
  1202. {
  1203. #ifdef USING_PRINTF
  1204. printf("socketAppConnectionCallBack invalid connection ul status event");
  1205. #endif
  1206. ECOMM_TRACE(UNILOG_PLA_APP, socketAppConnectionCallBack_9, P_ERROR, 0, "socketAppConnectionCallBack invalid connection ul status event");
  1207. }
  1208. break;
  1209. }
  1210. default:
  1211. #ifdef USING_PRINTF
  1212. printf("socketAppConnectionCallBack invalid event type %u", connectionEventType);
  1213. #endif
  1214. ECOMM_TRACE(UNILOG_PLA_APP, socketAppConnectionCallBack_10, P_ERROR, 1, "socketAppConnectionCallBack invalid event type %u", connectionEventType);
  1215. break;
  1216. }
  1217. }