app.c 60 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547
  1. /*******************************
  2. *
  3. * 骑享程序测试
  4. *
  5. * ****************************/
  6. #include "bsp.h"
  7. #include "bsp_custom.h"
  8. #include "osasys.h"
  9. #include "ostask.h"
  10. #include "queue.h"
  11. #include "ps_event_callback.h"
  12. #include "app.h"
  13. #include "cmisim.h"
  14. #include "cmimm.h"
  15. #include "cmips.h"
  16. #include "sockets.h"
  17. #include "psifevent.h"
  18. #include "ps_lib_api.h"
  19. #include "lwip/netdb.h"
  20. #include <cis_def.h>
  21. #include "debug_log.h"
  22. #include "slpman_ec616.h"
  23. #include "plat_config.h"
  24. //空间及变量定义
  25. #define PROC_MAIN_TASK_STACK_SIZE (2048)
  26. #define PROC_UART_TASK_STACK_SIZE (1024)
  27. #define PROC_CAN_TASK_STACK_SIZE (1024*2)
  28. #define PROC_TCP_TASK_STACK_SIZE (2048)
  29. #define APP_EVENT_QUEUE_SIZE (10)
  30. uint8_t deepslpTimerID = DEEPSLP_TIMER_ID7;
  31. uint8_t MainSlpHandler = 0xff;
  32. uint8_t UartSlpHandler = 0xfe;
  33. uint8_t CanSlpHandler = 0xfd;
  34. uint8_t TcpSlpHandler = 0xfd;
  35. #define Uart_Send_LEN (8)
  36. #define Uart_Rece_LEN (40)
  37. #define battbuffer_len (110)
  38. #define RTE_UART_RX_IO_MODE RTE_UART1_RX_IO_MODE
  39. extern ARM_DRIVER_USART Driver_USART1;
  40. static ARM_DRIVER_USART *USARTdrv = &Driver_USART1;
  41. volatile bool isRecvTimeout = false;
  42. volatile bool isRecvComplete = false;
  43. QueueHandle_t gpsMsgQueue = NULL;
  44. GPS_INFO Gps_Data;
  45. static volatile UINT32 Event;
  46. static QueueHandle_t psEventQueueHandle;
  47. static UINT8 gImsi[16] = {0};
  48. static INT32 sockfd = -1;
  49. static UINT32 gCellID = 0;
  50. int TcpconnectID = -1;
  51. volatile uint8_t Tcp_statuts = 0;
  52. //slpManTimerID_e Timer_ID;
  53. //#define BAT6060
  54. #define BAT4830
  55. #ifdef BAT4830
  56. uint8_t Batt_Cell_Num = 14;
  57. uint8_t Batt_Temp_Num = 5;
  58. #else
  59. uint8_t Batt_Cell_Num = 17;
  60. uint8_t Batt_Temp_Num = 7;
  61. #endif
  62. CHAR SN[] = "GY483000000000001";//SN应写到osfile里面
  63. uint8_t Batt_Cell_Num_2 ;//默认数值
  64. int16_t Uart_Rece_BattI=0x0000;
  65. uint8_t Can_Rece_buffer[8];
  66. volatile bool Can_Enable = false;
  67. uint16_t data_index = 0x0000;
  68. volatile bool Sleep_Flag = false;
  69. volatile bool Uart_Sleep_Flag = false;
  70. volatile bool Can_Sleep_Flag = false;
  71. volatile bool Tcp_Sleep_Flag = false;
  72. uint8_t battbuffer[battbuffer_len];//电池数据都存在此数组中————电压14,温度5
  73. /**
  74. * 存放规则如下:
  75. * 位置: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
  76. * 数据: 年 月 日 时 分 秒 信息体标志 年 月 日 时 分 秒 网络信号 故障等级 故障代码高 故障代码低
  77. *
  78. * 17 18 19 20 21 22 23 24 25 26 27 28 29 30 30+1 .... 30+X*2 31+X*2 31+1...31+X*2+N
  79. * 电流H 电流L Link电压H Link电压L Pack电压H Pack电压L 开关状态 SOC SOH 均衡状态 单体个数X 单体v1...单体vX 温度个数N 温度1..温度N
  80. * 32+X*2+N 33+X*2+N 34+x*2+N 35 +X*2+N 36+X*2 +N 37+X*2+N
  81. * 电池状态 是否加热 最高单体H 最高单体L 最低单体H 最低单体L
  82. * */
  83. //GPS信息
  84. uint8_t gpsbuffer[30];//定位都存在此数组中
  85. /**
  86. * 存放规则如下:
  87. * 位置: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
  88. * 数据: 年 月 日 时 分 秒 信息体标志 年 月 日 时 分 秒 定位标志 卫星数目 航向H 航向L
  89. *
  90. * 17 18 19 20 21 22 23 24 25 26 27 28
  91. * 速度H 速度L 海拔H 海拔L 纬度HH 纬度HL 纬度LH 纬度LL 经度HH 经度HL 经度LH 经度LL
  92. *
  93. * */
  94. //GPS信息
  95. //状态机定义
  96. typedef enum
  97. {
  98. PROCESS_STATE_IDLE = 0,
  99. PROCESS_STATE_WORK,
  100. PROCESS_STATE_SLEEP
  101. }process_Main;
  102. static process_Main gProcess_Main_Task = PROCESS_STATE_IDLE;
  103. #define PROC_MAIN_STATE_SWITCH(a) (gProcess_Main_Task = a)
  104. typedef enum
  105. {
  106. PROCESS_UART_STATE_IDLE = 0,
  107. PROCESS_UART_STATE_CHECK,
  108. PROCESS_UART_STATE_WORK,
  109. PROCESS_UART_STATE_SLEEP
  110. }process_Uart;
  111. static process_Uart gProcess_Uart_Task = PROCESS_UART_STATE_IDLE;
  112. #define PROC_UART_STATE_SWITCH(a) (gProcess_Uart_Task = a)
  113. typedef enum
  114. {
  115. PROCESS_CAN_STATE_IDLE = 0,
  116. PROCESS_CAN_STATE_RECV,
  117. PROCESS_CAN_STATE_SEND,
  118. PROCESS_CAN_STATE_SLEEP
  119. }process_CAN;
  120. static process_CAN gProcess_Can_Task = PROCESS_CAN_STATE_IDLE;
  121. #define PROC_CAN_STATE_SWITCH(a) (gProcess_Can_Task = a)
  122. typedef enum
  123. {
  124. PROCESS_TCP_STATE_IDLE = 0,
  125. PROCESS_TCP_STATE_LINK,
  126. PROCESS_TCP_STATE_WORK,
  127. PROCESS_TCP_STATE_SLEEP
  128. }process_TCP;
  129. static process_TCP gProcess_Tcp_Task = PROCESS_TCP_STATE_IDLE;
  130. #define PROC_TCP_STATE_SWITCH(a) (gProcess_Tcp_Task = a)
  131. //堆栈申请
  132. static StaticTask_t gProcess_Main_Task_t;
  133. static UINT8 gProcess_Main_TaskStack[PROC_MAIN_TASK_STACK_SIZE];
  134. static StaticTask_t gProcess_Uart_Task_t;
  135. static UINT8 gProcess_Uart_TaskStack[PROC_UART_TASK_STACK_SIZE];
  136. static StaticTask_t gProcess_Can_Task_t;
  137. static UINT8 gProcess_Can_TaskStack[PROC_CAN_TASK_STACK_SIZE];
  138. static StaticTask_t gProcess_Tcp_Task_t;
  139. static UINT8 gProcess_Tcp_TaskStack[PROC_TCP_TASK_STACK_SIZE];
  140. #ifdef BL_FILE_LOG
  141. uint8_t lockoutState=0;
  142. #endif
  143. //睡眠进出函数
  144. static void appBeforeHib(void *pdata, slpManLpState state)
  145. {
  146. uint32_t *p_param = (uint32_t *)pdata;
  147. #ifdef USING_PRINTF
  148. printf("Before Hibernate:%d \n",state);
  149. #endif
  150. slpManAONIOLatchEn(AonIOLatch_Enable);
  151. }
  152. static void appAfterHib(void *pdata, slpManLpState state)
  153. {
  154. #ifdef USING_PRINTF
  155. printf("Try Hibernate Failed:%d \n",state);
  156. #endif
  157. }
  158. static void appBeforeSlp1(void *pdata, slpManLpState state)
  159. {
  160. #ifdef USING_PRINTF
  161. printf("Before Sleep1:%d \n",state);
  162. #endif
  163. slpManAONIOLatchEn(AonIOLatch_Enable);
  164. }
  165. static void appAfterSlp1(void *pdata, slpManLpState state)
  166. {
  167. #ifdef USING_PRINTF
  168. printf("After Sleep1:%d \n",state);
  169. #endif
  170. }
  171. static void appBeforeSlp2(void *pdata, slpManLpState state)
  172. {
  173. #ifdef USING_PRINTF
  174. printf("before sleep2:%d \n",state);
  175. #endif
  176. slpManAONIOLatchEn(AonIOLatch_Enable);
  177. }
  178. static void appAfterSlp2(void *pdata, slpManLpState state)
  179. {
  180. #ifdef USING_PRINTF
  181. printf("sleep2 failed:%d \n",state);
  182. #endif
  183. }
  184. // 主任务线程
  185. static void Main_Task(void* arg)
  186. {
  187. UINT16 Can_index = 0;
  188. UINT16 Uart_index = 0;
  189. UINT16 Tcp_index = 0;
  190. uint32_t sleep_index = 0;
  191. uint32_t sleep_time_flag;
  192. int32_t inParam = 0xAABBCCDD;
  193. uint32_t Chrgend_Work_time = 180000;
  194. uint32_t Wakeup_Work_time = 5*60*100;
  195. uint32_t Sleep_Time = 5*60*1000;
  196. //上述参数应写入文件里
  197. slpManWakeSrc_e Wakeup_source;
  198. PROC_MAIN_STATE_SWITCH(PROCESS_STATE_IDLE);
  199. NetSocDisplay(LED_SOC_0,LED_TURN_OFF);
  200. NetSocDisplay(LED_SOC_1,LED_TURN_OFF);
  201. NetSocDisplay(LED_SOC_2,LED_TURN_OFF);
  202. NetSocDisplay(LED_SOC_3,LED_TURN_OFF);
  203. FaultDisplay(LED_TURN_OFF);
  204. NVIC_EnableIRQ(PadWakeup1_IRQn);
  205. slpManSetPmuSleepMode(true,SLP_HIB_STATE,false);
  206. slpManApplyPlatVoteHandle("MainSlp",&MainSlpHandler);
  207. slpManPlatVoteDisableSleep(MainSlpHandler, SLP_SLP2_STATE);
  208. slpManRegisterUsrdefinedBackupCb(appBeforeHib,&inParam,SLPMAN_HIBERNATE_STATE);
  209. slpManRegisterUsrdefinedRestoreCb(appAfterHib,NULL,SLPMAN_HIBERNATE_STATE);
  210. slpManRegisterUsrdefinedBackupCb(appBeforeSlp1,NULL,SLPMAN_SLEEP1_STATE);
  211. slpManRegisterUsrdefinedRestoreCb(appAfterSlp1,NULL,SLPMAN_SLEEP1_STATE);
  212. slpManRegisterUsrdefinedBackupCb(appBeforeSlp2,NULL,SLPMAN_SLEEP2_STATE);
  213. slpManRegisterUsrdefinedRestoreCb(appAfterSlp2,NULL,SLPMAN_SLEEP2_STATE);
  214. slpManSlpState_t slpstate = slpManGetLastSlpState();
  215. #ifdef USING_PRINTF
  216. printf("slpstate:%d \n",slpstate);
  217. #endif
  218. Wakeup_source = slpManGetWakeupSrc();//获取唤醒源
  219. #ifdef USING_PRINTF
  220. printf("Wakeup_source:%d \n",Wakeup_source);
  221. #endif
  222. if (Wakeup_source==0)
  223. {
  224. sleep_time_flag = Wakeup_Work_time;
  225. }
  226. else if (Wakeup_source==1)
  227. {
  228. sleep_time_flag = Wakeup_Work_time;
  229. }
  230. else
  231. {
  232. sleep_time_flag = Chrgend_Work_time;
  233. }
  234. if((slpstate == SLP_SLP2_STATE) || (slpstate == SLP_HIB_STATE))
  235. {
  236. PROC_MAIN_STATE_SWITCH(PROCESS_STATE_WORK);
  237. }
  238. else
  239. {
  240. PROC_MAIN_STATE_SWITCH(PROCESS_STATE_WORK);
  241. }
  242. // if (Timer_ID!=7)
  243. // {
  244. // PROC_MAIN_STATE_SWITCH(PROCESS_STATE_SLEEP);
  245. // }
  246. // else
  247. // {
  248. // PROC_MAIN_STATE_SWITCH(PROCESS_STATE_IDLE);
  249. // }
  250. //线程初始化完成
  251. while (true)
  252. {
  253. switch(gProcess_Main_Task)
  254. {
  255. case PROCESS_STATE_IDLE:
  256. {
  257. // 暂时不区分唤醒
  258. PROC_MAIN_STATE_SWITCH(PROCESS_STATE_WORK);
  259. break;
  260. }
  261. case PROCESS_STATE_WORK:
  262. {
  263. osDelay(10/portTICK_PERIOD_MS);
  264. Can_index++;
  265. Uart_index++;
  266. Tcp_index++;
  267. if (Uart_index >100)//Uart 1s 调用一次
  268. {
  269. PROC_UART_STATE_SWITCH(PROCESS_UART_STATE_WORK);
  270. Uart_index = 0;
  271. }
  272. if (Can_index >=100)//Can 1s 调用一次
  273. {
  274. PROC_CAN_STATE_SWITCH(PROCESS_CAN_STATE_RECV);
  275. Can_index = 0;
  276. }
  277. if (Tcp_index >=1000)//Tcp 5s 调用一次
  278. {
  279. PROC_TCP_STATE_SWITCH(PROCESS_TCP_STATE_LINK);
  280. Tcp_index = 0;
  281. }
  282. if((!Can_Enable)&&((Uart_Rece_BattI==0x0000)||(Uart_Rece_BattI==0xffff)))
  283. {
  284. sleep_index++;
  285. }
  286. else
  287. {
  288. sleep_index = 0;
  289. }
  290. if ((Uart_Rece_BattI!=0x0000)&&(Uart_Rece_BattI<=0x8000))
  291. {
  292. sleep_time_flag = Chrgend_Work_time;
  293. }
  294. if (sleep_index >=sleep_time_flag)
  295. {
  296. PROC_MAIN_STATE_SWITCH(PROCESS_STATE_SLEEP);
  297. sleep_index = 0;
  298. }
  299. break;
  300. }
  301. case PROCESS_STATE_SLEEP:
  302. {
  303. while(true)
  304. {
  305. PROC_UART_STATE_SWITCH(PROCESS_UART_STATE_SLEEP);
  306. PROC_CAN_STATE_SWITCH(PROCESS_CAN_STATE_SLEEP);
  307. PROC_TCP_STATE_SWITCH(PROCESS_TCP_STATE_SLEEP);
  308. Sleep_Flag = TRUE;
  309. if((Uart_Sleep_Flag)&&(Can_Sleep_Flag)&&(Tcp_Sleep_Flag))
  310. break;
  311. }
  312. osDelay(10000);
  313. #ifdef USING_PRINTF
  314. printf("Ms_sleep:uart_%d,can_%d,tcp_%d\r\n",gProcess_Uart_Task,gProcess_Can_Task,gProcess_Tcp_Task);
  315. #endif
  316. slpManSlpState_t State;
  317. uint8_t cnt;
  318. if(slpManCheckVoteState(MainSlpHandler, &State, &cnt)==RET_TRUE)
  319. {
  320. #ifdef USING_PRINTF
  321. printf("[%d]We Can Check Vote Main State, state=%d, cnt=%d\r\n",__LINE__,State,cnt);
  322. #endif
  323. }
  324. slpManPlatVoteForceEnableSleep(MainSlpHandler, SLP_SLP2_STATE); //增加强制投票
  325. if(slpManCheckVoteState(MainSlpHandler, &State, &cnt)==RET_TRUE)
  326. {
  327. #ifdef USING_PRINTF
  328. printf("[%d]We Can Check Vote Main State Again, state=%d, cnt=%d\r\n",__LINE__,State,cnt);
  329. #endif
  330. }
  331. #ifdef USING_PRINTF
  332. printf("[%d]Waiting sleep\r\n",__LINE__);
  333. #endif
  334. FaultDisplay(LED_TURN_ON);
  335. slpManSlpState_t slpstate = slpManPlatGetSlpState();
  336. #ifdef USING_PRINTF
  337. printf("which slpstate can go now :%d \n",slpstate);
  338. #endif
  339. #ifdef BL_FILE_LOG
  340. bluejoy_printf(BL_LEVEL3,"sleep\n");
  341. #endif
  342. slpManDeepSlpTimerStart(deepslpTimerID, Sleep_Time);
  343. while(1)
  344. {
  345. if(!slpManDeepSlpTimerIsRunning(deepslpTimerID))
  346. {
  347. slpManDeepSlpTimerDel(deepslpTimerID);
  348. }
  349. slpManDeepSlpTimerStart(deepslpTimerID, Sleep_Time);
  350. osDelay(60000/portTICK_PERIOD_MS);
  351. }
  352. break;
  353. }
  354. }
  355. }
  356. }
  357. //Uart校验程序
  358. unsigned int crc_chk(uint8_t* data, uint8_t length)
  359. {
  360. int j;
  361. uint16_t reg_crc=0xFFFF;
  362. while(length--)
  363. {
  364. reg_crc ^= *data++;
  365. for(j=0;j<8;j++)
  366. {
  367. if(reg_crc & 0x01)
  368. {
  369. reg_crc=(reg_crc>>1) ^ 0xA001;
  370. }
  371. else
  372. {
  373. reg_crc=reg_crc >>1;
  374. }
  375. }
  376. }
  377. return reg_crc;
  378. }
  379. //Uart回调程序
  380. void USART_callback(uint32_t event)
  381. {
  382. if(event & ARM_USART_EVENT_RX_TIMEOUT)
  383. {
  384. isRecvTimeout = true;
  385. }
  386. if(event & ARM_USART_EVENT_RECEIVE_COMPLETE)
  387. {
  388. isRecvComplete = true;
  389. }
  390. }
  391. //Uart发送接收函数
  392. uint8_t* Uart_Receive_func(Uart_Receive_Type Uart_Receive_Msg,uint8_t* Uart_Rece_buffer,uint8_t Data_Len)
  393. {
  394. uint16_t CRC_Rece_buffer;
  395. uint16_t CRC_chk_buffer;
  396. uint8_t Uart_Send_buffer[8];
  397. Uart_Send_buffer[0] = Uart_Receive_Msg.Bms_Address;
  398. Uart_Send_buffer[1] = Uart_Receive_Msg.Bms_Read_Funcode;
  399. Uart_Send_buffer[2] = Uart_Receive_Msg.Reg_Begin_H;
  400. Uart_Send_buffer[3] = Uart_Receive_Msg.Reg_Begin_L;
  401. Uart_Send_buffer[4] = Uart_Receive_Msg.Reg_Num_H;
  402. Uart_Send_buffer[5] = Uart_Receive_Msg.Reg_Num_L;
  403. CRC_chk_buffer = crc_chk(Uart_Send_buffer,6);
  404. Uart_Send_buffer[6] = CRC_chk_buffer;
  405. Uart_Send_buffer[7] = CRC_chk_buffer>>8;
  406. uint32_t timeout = 0x00000000;
  407. USARTdrv->Send(Uart_Send_buffer,8);
  408. // #ifdef USING_PRINTF
  409. // printf("Uart_Send_buffer: ");
  410. // for(int i=0;i<8;i++)
  411. // {
  412. // printf("%x ",Uart_Send_buffer[i]);
  413. // }
  414. // printf("\n");
  415. // #endif
  416. USARTdrv->Receive(Uart_Rece_buffer,Data_Len);
  417. while((isRecvTimeout == false) && (isRecvComplete == false))
  418. {
  419. timeout++;
  420. osDelay(100);
  421. if (timeout>=10)
  422. {
  423. timeout =0;
  424. isRecvTimeout = true;
  425. break;
  426. }
  427. }
  428. // #ifdef USING_PRINTF
  429. // printf("Uart_Rece_buffer1: ");
  430. // for(int i=0;i<Data_Len;i++)
  431. // {
  432. // printf("%x ",*(Uart_Rece_buffer+i));
  433. // }
  434. // #endif
  435. if (isRecvComplete == true)
  436. {
  437. isRecvComplete = false;
  438. CRC_Rece_buffer =*(Uart_Rece_buffer+Data_Len-1)<<8|*(Uart_Rece_buffer+Data_Len-2);
  439. CRC_chk_buffer = crc_chk(Uart_Rece_buffer,Data_Len-2);
  440. // #ifdef USING_PRINTF
  441. // printf("Uart_Rece_buffer2: ");
  442. // for(int i=0;i<Data_Len;i++)
  443. // {
  444. // printf("%x ",*(Uart_Rece_buffer+i));
  445. // }
  446. // printf("\ncrcchk:%x,%x\n ",CRC_chk_buffer,CRC_Rece_buffer);
  447. // #endif
  448. if (CRC_Rece_buffer == CRC_chk_buffer)//满足校验
  449. {
  450. return Uart_Rece_buffer;//此处指针移位出现重启问题
  451. }
  452. else //接收数据的校验不过
  453. {
  454. USARTdrv->Uninitialize();
  455. osDelay(1000);
  456. USARTdrv->Initialize(USART_callback);
  457. USARTdrv->PowerControl(ARM_POWER_FULL);
  458. USARTdrv->Control(ARM_USART_MODE_ASYNCHRONOUS |
  459. ARM_USART_DATA_BITS_8 |
  460. ARM_USART_PARITY_NONE |
  461. ARM_USART_STOP_BITS_1 |
  462. ARM_USART_FLOW_CONTROL_NONE, 9600);
  463. memset(Uart_Rece_buffer,0xff,Data_Len);
  464. return Uart_Rece_buffer;
  465. }
  466. }
  467. else
  468. {
  469. osDelay(100);
  470. memset(Uart_Rece_buffer,0x00,Data_Len);
  471. isRecvTimeout = false;
  472. return Uart_Rece_buffer;
  473. }
  474. }
  475. void GGACallBack(UINT8 res, UINT8 * params)
  476. {
  477. #ifdef USING_PRINTF
  478. printf("GPS:len=%d,data=%s\r\n",res,params);
  479. #else
  480. ECOMM_STRING(UNILOG_PLA_STRING, GPS_DATA, P_INFO, "gps:%s", params);
  481. #endif
  482. }
  483. //Uart线程
  484. static void Uart_Task(void* arg)
  485. {
  486. USARTdrv->Initialize(USART_callback);
  487. USARTdrv->PowerControl(ARM_POWER_FULL);
  488. USARTdrv->Control(ARM_USART_MODE_ASYNCHRONOUS |
  489. ARM_USART_DATA_BITS_8 |
  490. ARM_USART_PARITY_NONE |
  491. ARM_USART_STOP_BITS_1 |
  492. ARM_USART_FLOW_CONTROL_NONE, 9600);
  493. int Rece_index = 0;
  494. volatile uint8_t Data_Len;
  495. Uart_Receive_Type Uart_Receive_Msg;
  496. memset(&battbuffer[0],0x00,battbuffer_len);
  497. PROC_UART_STATE_SWITCH(PROCESS_UART_STATE_IDLE);
  498. slpManApplyPlatVoteHandle("UARTSLP",&UartSlpHandler);
  499. slpManPlatVoteDisableSleep(UartSlpHandler, SLP_SLP2_STATE);
  500. Uart_Receive_Msg.Bms_Address = 0x01;
  501. Uart_Receive_Msg.Bms_Read_Funcode = 0x03;
  502. uint8_t *Uart_Rece_buffer = NULL;
  503. volatile bool Uart_task = false;
  504. Batt_Cell_Num_2 = Batt_Cell_Num<<1;
  505. while (true)
  506. {
  507. switch (gProcess_Uart_Task)
  508. {
  509. case PROCESS_UART_STATE_IDLE:
  510. {
  511. Rece_index = 0;
  512. break;
  513. }
  514. case PROCESS_UART_STATE_CHECK:
  515. {
  516. Uart_Rece_buffer = (uint8_t *)malloc(Uart_Rece_LEN);
  517. Uart_Receive_Msg.Reg_Begin_H = 0x00;
  518. Uart_Receive_Msg.Reg_Begin_L= 0x02+Batt_Cell_Num;
  519. Uart_Receive_Msg.Reg_Num_H = 0x00;
  520. Uart_Receive_Msg.Reg_Num_L = 0x01;
  521. Data_Len = Uart_Receive_Msg.Reg_Num_L*2+5;
  522. memset(Uart_Rece_buffer,0x00,Data_Len);
  523. Uart_Rece_buffer = Uart_Receive_func(Uart_Receive_Msg,Uart_Rece_buffer,Data_Len);
  524. Uart_Rece_BattI = *(Uart_Rece_buffer+3+0)<<8 |*(Uart_Rece_buffer+3+1);
  525. #ifdef USING_PRINTF
  526. printf("Check_Current!\n");
  527. #endif
  528. PROC_UART_STATE_SWITCH(PROCESS_UART_STATE_IDLE);
  529. free(Uart_Rece_buffer);
  530. break;
  531. }
  532. case PROCESS_UART_STATE_WORK:
  533. {
  534. #ifdef USING_PRINTF
  535. //printf("UART_STATE_WORK!\n");
  536. #endif
  537. Uart_task = false;
  538. Uart_Rece_buffer = (uint8_t *)malloc(Uart_Rece_LEN);
  539. while(!Uart_task)
  540. {
  541. switch (Rece_index)
  542. {
  543. case 0://current
  544. {
  545. Uart_Receive_Msg.Reg_Begin_H = 0x00;
  546. Uart_Receive_Msg.Reg_Begin_L= 0x02+Batt_Cell_Num;
  547. Uart_Receive_Msg.Reg_Num_H = 0x00;
  548. Uart_Receive_Msg.Reg_Num_L = 0x01;
  549. Data_Len = Uart_Receive_Msg.Reg_Num_L*2+5;
  550. memset(Uart_Rece_buffer,0x00,Data_Len);
  551. Uart_Rece_buffer = Uart_Receive_func(Uart_Receive_Msg,Uart_Rece_buffer,Data_Len);
  552. Uart_Rece_BattI = *(Uart_Rece_buffer+3+0)<<8 |*(Uart_Rece_buffer+3+1);
  553. break;
  554. }
  555. case 1://cell votage
  556. {
  557. Uart_Receive_Msg.Reg_Begin_H = 0x00;
  558. Uart_Receive_Msg.Reg_Begin_L = 0x02;
  559. Uart_Receive_Msg.Reg_Num_H = Batt_Cell_Num>>8;
  560. Uart_Receive_Msg.Reg_Num_L = Batt_Cell_Num;
  561. Data_Len = Uart_Receive_Msg.Reg_Num_L*2+5;
  562. memset(Uart_Rece_buffer,0x00,Data_Len);
  563. Uart_Rece_buffer = Uart_Receive_func(Uart_Receive_Msg,Uart_Rece_buffer,Data_Len);
  564. battbuffer[30] = Batt_Cell_Num;
  565. memcpy(&battbuffer[31],Uart_Rece_buffer+3,Batt_Cell_Num_2);
  566. break;
  567. }
  568. case 2://temprature
  569. {
  570. Uart_Receive_Msg.Reg_Begin_H = 0x00;
  571. Uart_Receive_Msg.Reg_Begin_L = 0x06+Batt_Cell_Num;
  572. Uart_Receive_Msg.Reg_Num_H = Batt_Temp_Num>>8;
  573. Uart_Receive_Msg.Reg_Num_L = Batt_Temp_Num;
  574. Data_Len = Uart_Receive_Msg.Reg_Num_L*2+5;
  575. memset(Uart_Rece_buffer,0x00,Data_Len);
  576. Uart_Rece_buffer = Uart_Receive_func(Uart_Receive_Msg,Uart_Rece_buffer,Data_Len);
  577. battbuffer[31+Batt_Cell_Num_2] = Batt_Temp_Num;
  578. for (int i = 0; i < Batt_Temp_Num; i++)
  579. {
  580. battbuffer[32+Batt_Cell_Num_2+i] = *(Uart_Rece_buffer+3+2*i+1);
  581. }
  582. break;
  583. }
  584. case 3://batt votage
  585. {
  586. Uart_Receive_Msg.Reg_Begin_H = 0x00;
  587. Uart_Receive_Msg.Reg_Begin_L = 0x18+Batt_Cell_Num+Batt_Temp_Num;
  588. Uart_Receive_Msg.Reg_Num_H = 0x00;
  589. Uart_Receive_Msg.Reg_Num_L = 0x01;
  590. Data_Len = Uart_Receive_Msg.Reg_Num_L*2+5;
  591. memset(Uart_Rece_buffer,0x00,Data_Len);
  592. Uart_Rece_buffer = Uart_Receive_func(Uart_Receive_Msg,Uart_Rece_buffer,Data_Len);
  593. battbuffer[19] = *(Uart_Rece_buffer+3+0);//Link U
  594. battbuffer[20] = *(Uart_Rece_buffer+3+1);
  595. battbuffer[21] = *(Uart_Rece_buffer+3+0);//Pack U
  596. battbuffer[22] = *(Uart_Rece_buffer+3+1);
  597. break;
  598. }
  599. case 4://soc,soh
  600. {
  601. Uart_Receive_Msg.Reg_Begin_H = 0x00;
  602. Uart_Receive_Msg.Reg_Begin_L = 0x09+Batt_Cell_Num+Batt_Temp_Num;
  603. Uart_Receive_Msg.Reg_Num_H = 0x00;
  604. Uart_Receive_Msg.Reg_Num_L = 0x04;
  605. Data_Len = Uart_Receive_Msg.Reg_Num_L*2+5;
  606. memset(Uart_Rece_buffer,0x00,Data_Len);
  607. Uart_Rece_buffer = Uart_Receive_func(Uart_Receive_Msg,Uart_Rece_buffer,Data_Len);
  608. battbuffer[23] = *(Uart_Rece_buffer+3+0)>>1;//mos状态
  609. battbuffer[24] = *(Uart_Rece_buffer+3+5);//SOC
  610. battbuffer[25] = *(Uart_Rece_buffer+3+7);//SOH
  611. break;
  612. }
  613. case 5://均衡
  614. {
  615. Uart_Receive_Msg.Reg_Begin_H = 0x00;
  616. Uart_Receive_Msg.Reg_Begin_L = 0x06+Batt_Cell_Num+Batt_Temp_Num;
  617. Uart_Receive_Msg.Reg_Num_H = 0x00;
  618. Uart_Receive_Msg.Reg_Num_L = 0x02;
  619. Data_Len = Uart_Receive_Msg.Reg_Num_L*2+5;
  620. memset(Uart_Rece_buffer,0x00,Data_Len);
  621. Uart_Rece_buffer = Uart_Receive_func(Uart_Receive_Msg,Uart_Rece_buffer,Data_Len);
  622. memcpy(&battbuffer[26],Uart_Rece_buffer+3,4);
  623. break;
  624. }
  625. case 6://最高最低温度和加热和充放电MOS控制
  626. {
  627. Uart_Receive_Msg.Reg_Begin_H = 0x00;
  628. Uart_Receive_Msg.Reg_Begin_L = 0x19+Batt_Cell_Num+Batt_Temp_Num;
  629. Uart_Receive_Msg.Reg_Num_H = 0x00;
  630. Uart_Receive_Msg.Reg_Num_L = 0x04;
  631. Data_Len = Uart_Receive_Msg.Reg_Num_L*2+5;
  632. memset(Uart_Rece_buffer,0x00,Data_Len);
  633. Uart_Rece_buffer = Uart_Receive_func(Uart_Receive_Msg,Uart_Rece_buffer,Data_Len);
  634. memcpy(&battbuffer[34+Batt_Cell_Num_2+Batt_Temp_Num],Uart_Rece_buffer+3,4);
  635. memcpy(&battbuffer[32+Batt_Cell_Num_2+Batt_Temp_Num],Uart_Rece_buffer+3+6,2);
  636. break;
  637. }
  638. default:
  639. {
  640. PROC_UART_STATE_SWITCH(PROCESS_UART_STATE_IDLE);
  641. Uart_task = true;
  642. break;
  643. }
  644. }
  645. Rece_index++;
  646. }
  647. free(Uart_Rece_buffer);
  648. break;
  649. }
  650. case PROCESS_UART_STATE_SLEEP:
  651. {
  652. USARTdrv->PowerControl(ARM_POWER_LOW);
  653. slpManPlatVoteEnableSleep(UartSlpHandler, SLP_SLP2_STATE);
  654. #ifdef USING_PRINTF
  655. printf("UART_STATE_SLEEP\n");
  656. #endif
  657. Uart_Sleep_Flag = true;
  658. while(1)
  659. {
  660. osDelay(60000/portTICK_PERIOD_MS);
  661. }
  662. }
  663. }
  664. }
  665. }
  666. //Can-线程任务
  667. static void Can_Task(void* arg)
  668. {
  669. uint32_t Can_ID;
  670. Can_InitType param;
  671. Can_TxMsgType Can_TxMsg;
  672. param.baudrate = CAN_500Kbps;
  673. param.mode = REQOP_NORMAL;
  674. //过滤ID配置
  675. param.TxStdIDH = 0x00;
  676. param.TxStdIDL = 0x00;
  677. param.RxStdIDH[0] = 0x00;
  678. param.RxStdIDL[0] = 0x00;
  679. /*stdid 0000 0000 001x*/
  680. param.RxStdIDH[1] = 0x00;
  681. param.RxStdIDL[1] = 0x20;
  682. /*stdid 0000 0000 010x */
  683. param.RxStdIDH[2] = 0x00;
  684. param.RxStdIDL[2] = 0x40;
  685. /*stdid 0000 0000 011x*/
  686. param.RxStdIDH[3] = 0x00;
  687. param.RxStdIDL[3] =0x60;
  688. /*stdid 0000 0000 100x */
  689. param.RxStdIDH[4] = 0x00;
  690. param.RxStdIDL[4] = 0x80;
  691. /*stdid 0000 0000 101x*/
  692. param.RxStdIDH[5] = 0x00;
  693. param.RxStdIDL[5] =0xa0;
  694. //配置完毕
  695. param.packType = STD_PACK;
  696. HAL_Can_Init(param);
  697. int send_index = 0;
  698. uint16_t Batt_Cell_addU = 0x0000;
  699. slpManApplyPlatVoteHandle("CanSlp",&CanSlpHandler);
  700. slpManPlatVoteDisableSleep(CanSlpHandler, SLP_SLP2_STATE);
  701. volatile bool Can_Flag=false;
  702. PROC_CAN_STATE_SWITCH(PROCESS_CAN_STATE_IDLE);
  703. posGGAServiceStart(GGACallBack);
  704. posGGAReset();
  705. while(1)
  706. {
  707. switch(gProcess_Can_Task)
  708. {
  709. case PROCESS_CAN_STATE_IDLE:
  710. {
  711. Can_Rece_buffer[0]=0xff;
  712. send_index = 0;
  713. break;
  714. }
  715. case PROCESS_CAN_STATE_RECV:
  716. {
  717. //加入GPS启动程序
  718. if(gpsMsgQueue == NULL)
  719. {
  720. gpsMsgQueue = osMessageQueueNew(1,sizeof(GPS_INFO), NULL);
  721. }
  722. osMessageQueueGet(gpsMsgQueue, &Gps_Data, 0, 1000);
  723. #ifdef USING_PRINTF
  724. printf("Gpsmsgqueue: %d,%d,%d,%d\r\n",Gps_Data.latitude,Gps_Data.longitude,Gps_Data.speed,Gps_Data.direction);
  725. #endif
  726. #ifdef BL_FILE_LOG
  727. bluejoy_printf(BL_LEVEL3,"Gpsmsg: %d,%d,%d,%d\r\n",Gps_Data.latitude,Gps_Data.longitude,Gps_Data.speed,Gps_Data.direction);
  728. #endif
  729. //can采用先接收后发送的策略
  730. HAL_Can_Receive(Can_Rece_buffer);
  731. if (Can_Rece_buffer[0]!=0xff)//满足can发送使能
  732. {
  733. PROC_CAN_STATE_SWITCH(PROCESS_CAN_STATE_SEND);
  734. Can_Enable = true;
  735. }
  736. else
  737. {
  738. PROC_CAN_STATE_SWITCH(PROCESS_CAN_STATE_IDLE);
  739. Can_Enable = false;
  740. }
  741. break;
  742. }
  743. case PROCESS_CAN_STATE_SEND:
  744. {
  745. #ifdef USING_PRINTF
  746. printf("CAN_STATE_SEND!\n");
  747. #endif
  748. Can_Flag=false;
  749. while(!Can_Flag)
  750. {
  751. switch(send_index)
  752. {
  753. case 0:
  754. {
  755. Can_ID = 0x001;
  756. for (int i = 0; i < 8; i++)
  757. {
  758. Can_TxMsg.Data[i] = battbuffer[i+31+0*8];
  759. }
  760. Can_TxMsg.stdIDH = Can_ID>>3;
  761. Can_TxMsg.stdIDL = Can_ID<<5;
  762. Can_TxMsg.DLC = 8;
  763. HAL_Can_Transmit(Can_TxMsg);
  764. break;
  765. }
  766. case 1:
  767. {
  768. Can_ID = 0x011;
  769. for (int i = 0; i < 8; i++)
  770. {
  771. Can_TxMsg.Data[i] = battbuffer[i+31+1*8];
  772. }
  773. Can_TxMsg.stdIDH = Can_ID>>3;
  774. Can_TxMsg.stdIDL = Can_ID<<5;
  775. Can_TxMsg.DLC = 8;
  776. HAL_Can_Transmit(Can_TxMsg);
  777. break;
  778. }
  779. case 2:
  780. {
  781. Can_ID = 0x020;
  782. for (int i = 0; i < 8; i++)
  783. {
  784. Can_TxMsg.Data[i] = battbuffer[i+31+2*8];
  785. }
  786. Can_TxMsg.stdIDH = Can_ID>>3;
  787. Can_TxMsg.stdIDL = Can_ID<<5;
  788. Can_TxMsg.DLC = 8;
  789. HAL_Can_Transmit(Can_TxMsg);
  790. break;
  791. }
  792. case 3:
  793. {
  794. #ifdef BAT4830
  795. Can_ID = 0x031;
  796. for (int i = 0; i < 4; i++)
  797. {
  798. Can_TxMsg.Data[i] = battbuffer[i+31+3*8];
  799. }
  800. Can_TxMsg.stdIDH = Can_ID>>3;
  801. Can_TxMsg.stdIDL = Can_ID<<5;
  802. Can_TxMsg.DLC = 8;
  803. HAL_Can_Transmit(Can_TxMsg);
  804. #else
  805. Can_ID = 0x031;
  806. for (int i = 0; i < 8; i++)
  807. {
  808. Can_TxMsg.Data[i] = battbuffer[i+31+3*8];
  809. }
  810. Can_TxMsg.stdIDH = Can_ID>>3;
  811. Can_TxMsg.stdIDL = Can_ID<<5;
  812. Can_TxMsg.DLC = 8;
  813. HAL_Can_Transmit(Can_TxMsg);
  814. Can_ID = 0x041;
  815. for (int i = 0; i < 2; i++)
  816. {
  817. Can_TxMsg.Data[i] = battbuffer[i+31+4*8];
  818. }
  819. for (int i = 0; i < 6; i++)
  820. {
  821. Can_TxMsg.Data[i+2] = 0x00;
  822. }
  823. Can_TxMsg.stdIDH = Can_ID>>3;
  824. Can_TxMsg.stdIDL = Can_ID<<5;
  825. Can_TxMsg.DLC = 8;
  826. HAL_Can_Transmit(Can_TxMsg);
  827. #endif
  828. break;
  829. }
  830. case 4:
  831. {
  832. Can_ID = 0x101;
  833. for (int i = 0; i < Batt_Temp_Num; i++)
  834. {
  835. Can_TxMsg.Data[i] = battbuffer[i+32+Batt_Cell_Num_2];
  836. }
  837. Can_TxMsg.stdIDH = Can_ID>>3;
  838. Can_TxMsg.stdIDL = Can_ID<<5;
  839. Can_TxMsg.DLC = 8;
  840. HAL_Can_Transmit(Can_TxMsg);
  841. break;
  842. }
  843. case 5:
  844. {
  845. Can_ID = 0x200;
  846. Batt_Cell_addU = 0x0000;
  847. for (int i = 0; i < Batt_Cell_Num; i++)
  848. {
  849. Batt_Cell_addU = Batt_Cell_addU + (battbuffer[31+i*2]<<8|battbuffer[31+i*2+1])/10;
  850. }
  851. Can_TxMsg.Data[0] = battbuffer[19];
  852. Can_TxMsg.Data[1] = battbuffer[20];
  853. Can_TxMsg.Data[2] = battbuffer[21];
  854. Can_TxMsg.Data[3] = battbuffer[22];//外电压
  855. Can_TxMsg.Data[4] = Batt_Cell_addU>>8;
  856. Can_TxMsg.Data[5] = Batt_Cell_addU;//累加电压
  857. Can_TxMsg.Data[6] = Uart_Rece_BattI>>8;
  858. Can_TxMsg.Data[7] = Uart_Rece_BattI;
  859. Can_TxMsg.stdIDH = Can_ID>>3;
  860. Can_TxMsg.stdIDL = Can_ID<<5;
  861. Can_TxMsg.DLC = 8;
  862. HAL_Can_Transmit(Can_TxMsg);
  863. break;
  864. }
  865. case 6:
  866. {
  867. Can_ID = 0x211;
  868. Can_TxMsg.Data[0] = battbuffer[34+Batt_Cell_Num_2+Batt_Temp_Num];
  869. Can_TxMsg.Data[1] = battbuffer[35+Batt_Cell_Num_2+Batt_Temp_Num];
  870. Can_TxMsg.Data[2] = battbuffer[36+Batt_Cell_Num_2+Batt_Temp_Num];
  871. Can_TxMsg.Data[3] = battbuffer[37+Batt_Cell_Num_2+Batt_Temp_Num];
  872. Can_TxMsg.Data[4] = 0x00;
  873. Can_TxMsg.Data[5] = 0x00;
  874. Can_TxMsg.Data[6] = battbuffer[24];
  875. Can_TxMsg.Data[7] = Batt_Temp_Num<<4|0;
  876. Can_TxMsg.stdIDH = Can_ID>>3;
  877. Can_TxMsg.stdIDL = Can_ID<<5;
  878. Can_TxMsg.DLC = 8;
  879. HAL_Can_Transmit(Can_TxMsg);
  880. break;
  881. }
  882. case 7:
  883. {
  884. Can_ID = 0x221;
  885. Can_TxMsg.Data[0] = battbuffer[25];//SOH
  886. Can_TxMsg.Data[1] = 0x00;
  887. Can_TxMsg.Data[2] = 0x00;
  888. Can_TxMsg.Data[3] = 0x00;
  889. Can_TxMsg.Data[4] = 0x00;
  890. Can_TxMsg.Data[5] = 0x00;
  891. Can_TxMsg.Data[6] = 0x00;
  892. Can_TxMsg.Data[7] = 0x00;
  893. Can_TxMsg.stdIDH = Can_ID>>3;
  894. Can_TxMsg.stdIDL = Can_ID<<5;
  895. Can_TxMsg.DLC = 8;
  896. HAL_Can_Transmit(Can_TxMsg);
  897. break;
  898. }
  899. default:
  900. {
  901. Can_Flag=true;
  902. PROC_CAN_STATE_SWITCH(PROCESS_CAN_STATE_IDLE);
  903. break;
  904. }
  905. }
  906. send_index ++;
  907. }
  908. break;
  909. }
  910. case PROCESS_CAN_STATE_SLEEP:
  911. {
  912. posGGAServiceStop();
  913. HAL_Can_Sleep();
  914. slpManSlpState_t State;
  915. uint8_t cnt;
  916. if(slpManCheckVoteState(CanSlpHandler, &State, &cnt)==RET_TRUE)
  917. {
  918. #ifdef USING_PRINTF
  919. printf("[%d]We Can Check Vote Can State, state=%d, cnt=%d\r\n",__LINE__,State,cnt);
  920. #endif
  921. }
  922. slpManPlatVoteEnableSleep(CanSlpHandler, SLP_SLP2_STATE);
  923. if(slpManCheckVoteState(CanSlpHandler, &State, &cnt)==RET_TRUE)
  924. {
  925. #ifdef USING_PRINTF
  926. printf("[%d]We Can Check Vote can State Again, state=%d, cnt=%d\r\n",__LINE__,State,cnt);
  927. #endif
  928. }
  929. Can_Sleep_Flag = true;
  930. while(true)
  931. {
  932. osDelay(60000/portTICK_PERIOD_MS);
  933. }
  934. }
  935. }
  936. }
  937. }
  938. static void sendQueueMsg(UINT32 msgId, UINT32 xTickstoWait)
  939. {
  940. eventCallbackMessage_t *queueMsg = NULL;
  941. queueMsg = malloc(sizeof(eventCallbackMessage_t));
  942. queueMsg->messageId = msgId;
  943. if (psEventQueueHandle)
  944. {
  945. if (pdTRUE != xQueueSend(psEventQueueHandle, &queueMsg, xTickstoWait))
  946. {
  947. ECOMM_TRACE(UNILOG_PLA_APP, sendQueueMsg_1, P_ERROR, 0, "xQueueSend error");
  948. }
  949. }
  950. }
  951. // void slpManTimerCb(slpManTimerID_e ID)
  952. // {
  953. // Timer_ID = ID;
  954. // }
  955. static INT32 socketRegisterPSUrcCallback(urcID_t eventID, void *param, UINT32 paramLen)
  956. {
  957. CmiSimImsiStr *imsi = NULL;
  958. CmiPsCeregInd *cereg = NULL;
  959. UINT8 rssi = 0, index = 0;
  960. NmAtiNetifInfo *netif = NULL;
  961. switch(eventID)
  962. {
  963. case NB_URC_ID_SIM_READY:
  964. {
  965. imsi = (CmiSimImsiStr *)param;
  966. memcpy(gImsi, imsi->contents, imsi->length);
  967. #ifdef USING_PRINTF
  968. printf("SIM ready(imsi=%s)\n",(UINT8 *)imsi->contents);
  969. #endif
  970. break;
  971. }
  972. case NB_URC_ID_MM_SIGQ:
  973. {
  974. rssi = *(UINT8 *)param;
  975. #ifdef USING_PRINTF
  976. printf("RSSI signal=%d\n",rssi);
  977. #endif
  978. ECOMM_TRACE(UNILOG_PLA_APP, socketRegisterPSUrcCallback_1, P_INFO, 1, "RSSI signal=%d", rssi);
  979. break;
  980. }
  981. case NB_URC_ID_PS_BEARER_ACTED:
  982. {
  983. #ifdef USING_PRINTF
  984. printf("Default bearer activated\n");
  985. #endif
  986. break;
  987. }
  988. case NB_URC_ID_PS_BEARER_DEACTED:
  989. {
  990. #ifdef USING_PRINTF
  991. printf("Default bearer Deactivated\n");
  992. #endif
  993. break;
  994. }
  995. case NB_URC_ID_PS_CEREG_CHANGED:
  996. {
  997. cereg = (CmiPsCeregInd *)param;
  998. gCellID = cereg->celId;
  999. #ifdef USING_PRINTF
  1000. printf("URCCallBack:CEREG changed act:%d celId:%d locPresent:%d tac:%d\n", cereg->act, cereg->celId, cereg->locPresent, cereg->tac);
  1001. #endif
  1002. break;
  1003. }
  1004. case NB_URC_ID_PS_NETINFO:
  1005. {
  1006. netif = (NmAtiNetifInfo *)param;
  1007. if (netif->netStatus == NM_NETIF_ACTIVATED)
  1008. //sendQueueMsg(QMSG_ID_NW_IP_READY, 0);
  1009. Tcp_statuts = 1;
  1010. break;
  1011. }
  1012. }
  1013. return 0;
  1014. }
  1015. uint8_t bcc_chk(uint8_t* data, uint8_t length)//发送bcc校验函数
  1016. {
  1017. uint8_t bcc_chk_return = 0x00;
  1018. uint8_t count = 0;
  1019. while (count<length)
  1020. {
  1021. bcc_chk_return^=data[count];
  1022. count++;
  1023. }
  1024. return bcc_chk_return;
  1025. }
  1026. //电池数据组装函数
  1027. void Tcp_Batt_Data_Assemble(void)
  1028. {
  1029. int16_t Batt_current;
  1030. uint16_t BattU = 0x00;
  1031. uint8_t csq=0;
  1032. int8_t snr=0;
  1033. int8_t rsnr=0;
  1034. Batt_current = Uart_Rece_BattI;
  1035. OsaUtcTimeTValue timestracture;
  1036. appGetSystemTimeUtcSync(&timestracture);
  1037. battbuffer[0] = timestracture.UTCtimer1>>16;
  1038. battbuffer[0] = battbuffer[0] - 0x07D0;
  1039. battbuffer[1] = timestracture.UTCtimer1>>8;
  1040. battbuffer[2] = timestracture.UTCtimer1;
  1041. battbuffer[3] = timestracture.UTCtimer2>>24;
  1042. battbuffer[4] = timestracture.UTCtimer2>>16;
  1043. battbuffer[5] = timestracture.UTCtimer2>>8;
  1044. battbuffer[6] = 0x80;//信息体标志,此处为电池信息
  1045. battbuffer[7] = battbuffer[0];//年
  1046. battbuffer[8] = battbuffer[1];//月
  1047. battbuffer[9] = battbuffer[2];//日
  1048. battbuffer[10] = battbuffer[3];//时 0时区时间
  1049. battbuffer[11] = battbuffer[4];//分
  1050. battbuffer[12] = battbuffer[5];//秒
  1051. appGetSignalInfoSync(&csq,&snr,&rsnr);//获取信号质量
  1052. battbuffer[13] = csq;// 网络信号
  1053. battbuffer[14] = 0x00;//故障等级
  1054. battbuffer[15] = 0x00;//故障代码高
  1055. battbuffer[16] = 0x00;//故障代码低
  1056. //电流适应性更改,从int转换到uint,加10000的偏移量,100mA的单位
  1057. if (Batt_current>0x8000)
  1058. {
  1059. Batt_current = Batt_current|0x7fff;
  1060. Batt_current = Batt_current/10;
  1061. Batt_current = 0x2710 - Batt_current;
  1062. Batt_current = Batt_current;
  1063. }
  1064. else
  1065. {
  1066. Batt_current = Batt_current/10;
  1067. Batt_current = Batt_current+0x2710;
  1068. Batt_current = Batt_current;
  1069. }
  1070. battbuffer[17] = Batt_current>>8;
  1071. battbuffer[18] = Batt_current;
  1072. BattU =( battbuffer[19]<<8|battbuffer[20])/10;
  1073. battbuffer[19] = BattU>>8;
  1074. battbuffer[20] = BattU;
  1075. battbuffer[21] = BattU>>8;
  1076. battbuffer[22] = BattU;//外电压
  1077. data_index = 32+Batt_Cell_Num_2+Batt_Temp_Num;
  1078. if(Batt_current==10000)
  1079. {
  1080. battbuffer[data_index] = 0x00;//电池状态
  1081. }
  1082. else if(Batt_current>10000)
  1083. {
  1084. battbuffer[data_index] = 0x02;//电池状态
  1085. }
  1086. else if(Batt_current<10000)
  1087. {
  1088. battbuffer[data_index] = 0x01;//电池状态
  1089. }
  1090. data_index++;
  1091. //battbuffer[data_index] = 0x00;//是否加热
  1092. data_index++;
  1093. }
  1094. //Gps 数据组装函数
  1095. void Tcp_Gps_Data_Assemble(void)
  1096. {
  1097. OsaUtcTimeTValue timestracture;
  1098. appGetSystemTimeUtcSync(&timestracture);
  1099. gpsbuffer[0] = timestracture.UTCtimer1>>16;
  1100. gpsbuffer[0] = gpsbuffer[0] - 0x07D0;
  1101. gpsbuffer[1] = timestracture.UTCtimer1>>8;
  1102. gpsbuffer[2] = timestracture.UTCtimer1;
  1103. gpsbuffer[3] = timestracture.UTCtimer2>>24;
  1104. gpsbuffer[4] = timestracture.UTCtimer2>>16;
  1105. gpsbuffer[5] = timestracture.UTCtimer2>>8;
  1106. gpsbuffer[6] = 0x82;//信息体标志,此处为GPS信息
  1107. gpsbuffer[7] = gpsbuffer[0];//年
  1108. gpsbuffer[8] = gpsbuffer[1];//月
  1109. gpsbuffer[9] = gpsbuffer[2];//日
  1110. gpsbuffer[10] = gpsbuffer[3];//时 0时区时间
  1111. gpsbuffer[11] = gpsbuffer[4];//分
  1112. gpsbuffer[12] = gpsbuffer[5];//秒
  1113. gpsbuffer[13] = Gps_Data.status;
  1114. gpsbuffer[14] = Gps_Data.satellite_num;
  1115. gpsbuffer[15] = Gps_Data.direction>>8;
  1116. gpsbuffer[16] = Gps_Data.direction;
  1117. gpsbuffer[17] = Gps_Data.speed>>8;
  1118. gpsbuffer[18] = Gps_Data.speed;
  1119. gpsbuffer[19] = Gps_Data.altitude>>8;
  1120. gpsbuffer[20] = Gps_Data.altitude;
  1121. gpsbuffer[21] = Gps_Data.latitude>>24;
  1122. gpsbuffer[22] = Gps_Data.latitude>>16;
  1123. gpsbuffer[23] = Gps_Data.latitude>>8;
  1124. gpsbuffer[24] = Gps_Data.latitude;
  1125. gpsbuffer[25] = Gps_Data.longitude>>24;
  1126. gpsbuffer[26] = Gps_Data.longitude>>16;
  1127. gpsbuffer[27] = Gps_Data.longitude>>8;
  1128. gpsbuffer[28] = Gps_Data.longitude;
  1129. }
  1130. //Tcp线程
  1131. static void Tcp_Task(void* arg)
  1132. {
  1133. CHAR serverip[] = "47.97.127.222";
  1134. CHAR serverport[] = "8712";
  1135. struct addrinfo hints, *server_res;
  1136. int TcpsendID = -1;
  1137. memset( &hints, 0, sizeof( hints ) );
  1138. hints.ai_socktype = SOCK_STREAM;
  1139. hints.ai_protocol = IPPROTO_TCP;
  1140. psEventQueueHandle = xQueueCreate(APP_EVENT_QUEUE_SIZE, sizeof(eventCallbackMessage_t*));
  1141. slpManApplyPlatVoteHandle("TcpSlp",&TcpSlpHandler);
  1142. slpManPlatVoteDisableSleep(TcpSlpHandler, SLP_SLP2_STATE);
  1143. PROC_TCP_STATE_SWITCH(PROCESS_TCP_STATE_IDLE);
  1144. uint8_t Tcp_Index = 0;
  1145. uint8_t* TcpSendBuffer=NULL;
  1146. volatile bool Tcp_Flag=false;
  1147. eventCallbackMessage_t *queueItem = NULL;
  1148. uint8_t pmode;
  1149. uint32_t tau;
  1150. uint32_t act;
  1151. uint8_t NB_send_len;
  1152. uint8_t Reconnect_Num = 0;
  1153. appSetEDRXSettingSync(0,5,1800000);
  1154. appSetPSMSettingSync(1,3*60*60,10);
  1155. slpManWakeSrc_e Wakeup_source;
  1156. Wakeup_source = slpManGetWakeupSrc();//获取唤醒源
  1157. if(Wakeup_source==0)
  1158. {
  1159. Tcp_statuts = 0;
  1160. }
  1161. else
  1162. {
  1163. Tcp_statuts = 1;
  1164. }
  1165. #ifdef BL_FILE_LOG
  1166. if(lockoutState)
  1167. bluejoy_del_logfile();
  1168. bluejoy_read_logfile();
  1169. bluejoy_printf(BL_LEVEL3,"processAppTask\n");
  1170. #endif
  1171. NetSocDisplay(LED_SOC_2,LED_TURN_ON);
  1172. appSetCFUN(1);
  1173. while(true)
  1174. {
  1175. switch(gProcess_Tcp_Task)
  1176. {
  1177. case PROCESS_TCP_STATE_IDLE:
  1178. {
  1179. osDelay(100);
  1180. break;
  1181. }
  1182. case PROCESS_TCP_STATE_LINK:
  1183. {
  1184. #ifdef USING_PRINTF
  1185. printf("TCP_statuts:%d\n",Tcp_statuts);
  1186. #endif
  1187. switch(Tcp_statuts)
  1188. {
  1189. case 0://0代表网络为驻网前
  1190. {
  1191. #ifdef USING_PRINTF
  1192. printf("TCP Not Ready\n");
  1193. #endif
  1194. PROC_TCP_STATE_SWITCH(PROCESS_TCP_STATE_IDLE);
  1195. break;
  1196. }
  1197. case 1://1代表网络驻网
  1198. {
  1199. if (getaddrinfo( serverip, serverport , &hints, &server_res ) != 0 )
  1200. {
  1201. #ifdef USING_PRINTF
  1202. printf("TCP connect unresolved dns\n");
  1203. #endif
  1204. #ifdef BL_FILE_LOG
  1205. //bluejoy_printf(BL_LEVEL3,"TCP connect unresolved dns\n");
  1206. #endif
  1207. }
  1208. Tcp_statuts=2;
  1209. break;
  1210. }
  1211. case 2://2代表尝试建立连接
  1212. {
  1213. #ifdef USING_PRINTF
  1214. printf("Connecting...!%d\n",TcpconnectID);
  1215. #endif
  1216. sockfd = socket(AF_INET, SOCK_STREAM, 0);
  1217. if(sockfd<0)
  1218. {
  1219. #ifdef USING_PRINTF
  1220. printf("socket create error\n");
  1221. #endif
  1222. #ifdef BL_FILE_LOG
  1223. //bluejoy_printf(BL_LEVEL3,"socket create error\n");
  1224. #endif
  1225. Tcp_statuts=1;
  1226. }
  1227. else
  1228. {
  1229. TcpconnectID = connect(sockfd, (struct sockaddr *) server_res->ai_addr, server_res->ai_addrlen);
  1230. if(TcpconnectID<0 && errno != EINPROGRESS)
  1231. {
  1232. #ifdef USING_PRINTF
  1233. printf("Connect failed!%d,Reconnect:%d\n",TcpconnectID,Reconnect_Num);
  1234. #endif
  1235. close(sockfd);
  1236. Tcp_statuts=2;
  1237. PROC_TCP_STATE_SWITCH(PROCESS_TCP_STATE_IDLE);
  1238. Reconnect_Num++;
  1239. NetSocDisplay(LED_SOC_0,LED_TURN_ON);
  1240. }
  1241. else
  1242. {
  1243. NetSocDisplay(LED_SOC_0,LED_TURN_OFF);
  1244. Tcp_statuts=3;
  1245. Reconnect_Num = 0;
  1246. }
  1247. if(Reconnect_Num>=20)
  1248. {
  1249. #ifdef BL_FILE_LOG
  1250. //bluejoy_printf(BL_LEVEL3,"20 Connect failed!%d,Reconnect:%d\n",TcpconnectID,Reconnect_Num);
  1251. #endif
  1252. appSetCFUN(0);
  1253. osDelay(10);
  1254. appSetCFUN(1);
  1255. PSInitEventCallbackTable();
  1256. Tcp_statuts=1;
  1257. Reconnect_Num = 0;
  1258. }
  1259. }
  1260. break;
  1261. }
  1262. case 3://3代表连接建立成功
  1263. {
  1264. PROC_TCP_STATE_SWITCH(PROCESS_TCP_STATE_WORK);
  1265. break;
  1266. }
  1267. case 4://4代表连接断开
  1268. {
  1269. Tcp_statuts=2;
  1270. break;
  1271. }
  1272. }
  1273. break;
  1274. }
  1275. case PROCESS_TCP_STATE_WORK:
  1276. {
  1277. #ifdef USING_PRINTF
  1278. printf("TCP_STATE_WORK!\n");
  1279. #endif
  1280. appGetPSMSettingSync(&pmode,&tau,&act);
  1281. #ifdef USING_PRINTF
  1282. printf("psm:pmode-%d,tau-%d,act-%d!\n",pmode,tau,act);
  1283. #endif
  1284. Tcp_Flag = false;
  1285. while (!Tcp_Flag)
  1286. {
  1287. switch(Tcp_Index)
  1288. {
  1289. case 0://发送登录信息
  1290. {
  1291. Tcp_Index=1;
  1292. break;
  1293. }
  1294. case 1://发送电池数据
  1295. {
  1296. NB_send_len=59+Batt_Cell_Num_2+Batt_Temp_Num;//电池数据长度
  1297. TcpSendBuffer = (uint8_t *)malloc(NB_send_len);
  1298. data_index = 0;
  1299. memset(TcpSendBuffer,0x00,NB_send_len);
  1300. *(TcpSendBuffer+0) = 0x23;
  1301. *(TcpSendBuffer+1) = 0x23;
  1302. *(TcpSendBuffer+2) = 0x02;
  1303. *(TcpSendBuffer+3) = 0xfe;
  1304. memcpy(TcpSendBuffer+4,SN,17);
  1305. *(TcpSendBuffer+21) = 0x01;//01表示不加密
  1306. Tcp_Batt_Data_Assemble();//数据组装函数
  1307. *(TcpSendBuffer+22) = data_index>>8;//数据长度
  1308. *(TcpSendBuffer+23) = data_index;//数据长度
  1309. memcpy(TcpSendBuffer+24,battbuffer,data_index);
  1310. *(TcpSendBuffer+NB_send_len-1) = bcc_chk(TcpSendBuffer,NB_send_len-1);
  1311. // #ifdef USING_PRINTF
  1312. // printf("battbuffer:");
  1313. // for (int i = 0; i < data_index; i++)
  1314. // {
  1315. // printf("%x ",battbuffer[i]);
  1316. // }
  1317. // printf("\n");
  1318. //#endif
  1319. TcpsendID = send(sockfd, TcpSendBuffer, NB_send_len, 0 );
  1320. //发送失败
  1321. // #ifdef USING_PRINTF
  1322. // printf("ConnectID:%d,TcpSend:%d,data length:%d,Data: ",sockfd,TcpsendID,NB_send_len);
  1323. // for (int i = 0; i < NB_send_len; i++)
  1324. // {
  1325. // printf("%x ",*(TcpSendBuffer+i));
  1326. // }
  1327. // printf("\n");
  1328. // #endif
  1329. free(TcpSendBuffer);
  1330. if (TcpsendID<0)
  1331. {
  1332. #ifdef BL_FILE_LOG
  1333. //bluejoy_printf(BL_LEVEL3,"send failed,ConnectID:%d,TcpSend:%d,data length:%d\n",sockfd,TcpsendID,NB_send_len);
  1334. #endif
  1335. closesocket(sockfd);
  1336. TcpconnectID = -1;
  1337. Tcp_Index=-1;
  1338. Tcp_statuts = 4;
  1339. }
  1340. else
  1341. {
  1342. Tcp_Index=2;
  1343. }
  1344. break;
  1345. }
  1346. case 2:
  1347. {
  1348. data_index = 29;
  1349. NB_send_len = 25+29;//数据总长度:25个固定+29个GPS长度
  1350. TcpSendBuffer = (uint8_t *)malloc(NB_send_len);
  1351. memset(TcpSendBuffer,0x00,NB_send_len);
  1352. *(TcpSendBuffer+0) = 0x23;
  1353. *(TcpSendBuffer+1) = 0x23;
  1354. *(TcpSendBuffer+2) = 0x02;
  1355. *(TcpSendBuffer+3) = 0xfe;
  1356. memcpy(TcpSendBuffer+4,SN,17);
  1357. *(TcpSendBuffer+21) = 0x01;//01表示不加密
  1358. Tcp_Gps_Data_Assemble();//Gps数据组装
  1359. *(TcpSendBuffer+22) = data_index>>8;//数据长度
  1360. *(TcpSendBuffer+23) = data_index;//数据长度
  1361. memcpy(TcpSendBuffer+24,gpsbuffer,data_index);
  1362. *(TcpSendBuffer+NB_send_len-1) = bcc_chk(TcpSendBuffer,NB_send_len-1);
  1363. // #ifdef USING_PRINTF
  1364. // printf("ConnectID:%d,TcpSend:%d,data length:%d,Data: ",sockfd,TcpsendID,NB_send_len);
  1365. // for (int i = 0; i < NB_send_len; i++)
  1366. // {
  1367. // printf("%x ",*(TcpSendBuffer+i));
  1368. // }
  1369. // printf("\n");
  1370. // #endif
  1371. TcpsendID = send(sockfd, TcpSendBuffer, NB_send_len, 0 );
  1372. free(TcpSendBuffer);
  1373. if (TcpsendID<0)
  1374. {
  1375. closesocket(sockfd);
  1376. TcpconnectID = -1;
  1377. Tcp_Index=-1;
  1378. Tcp_statuts = 4;
  1379. NetSocDisplay(LED_SOC_1,LED_TURN_ON);
  1380. }
  1381. else
  1382. {
  1383. NetSocDisplay(LED_SOC_1,LED_TURN_OFF);
  1384. Tcp_Index=3;
  1385. }
  1386. break;
  1387. }
  1388. default:
  1389. {
  1390. PROC_TCP_STATE_SWITCH(PROCESS_TCP_STATE_IDLE);
  1391. Tcp_Index = 0;
  1392. Tcp_Flag = true;
  1393. }
  1394. }
  1395. }
  1396. break;
  1397. }
  1398. case PROCESS_TCP_STATE_SLEEP:
  1399. {
  1400. slpManPlatVoteEnableSleep(TcpSlpHandler, SLP_SLP2_STATE);
  1401. closesocket(sockfd);
  1402. //deregisterPSEventCallback(socketRegisterPSUrcCallback);//注销NB网络事件函数
  1403. #ifdef USING_PRINTF
  1404. printf("TCP_STATE_SLEEP\n");
  1405. #endif
  1406. Tcp_Sleep_Flag = TRUE;
  1407. appSetCFUN(0);
  1408. while(1)
  1409. {
  1410. osDelay(30000/portTICK_PERIOD_MS);
  1411. }
  1412. }
  1413. }
  1414. }
  1415. }
  1416. //主任务线程初始化
  1417. void Main_Task_Init()
  1418. {
  1419. #ifndef USING_PRINTF
  1420. if(BSP_GetPlatConfigItemValue(PLAT_CONFIG_ITEM_LOG_CONTROL) != 0)
  1421. {
  1422. HAL_UART_RecvFlowControl(false);
  1423. }
  1424. #endif
  1425. //slpManDeepSlpTimerRegisterExpCb(slpManTimerCb);
  1426. osThreadAttr_t task_attr;
  1427. memset(&task_attr,0,sizeof(task_attr));
  1428. memset(gProcess_Main_TaskStack, 0xA5, PROC_MAIN_TASK_STACK_SIZE);
  1429. task_attr.name = "Main_Task";
  1430. task_attr.stack_mem = gProcess_Main_TaskStack;
  1431. task_attr.stack_size = PROC_MAIN_TASK_STACK_SIZE;
  1432. task_attr.priority = osPriorityNormal;
  1433. task_attr.cb_mem = &gProcess_Main_Task_t;
  1434. task_attr.cb_size = sizeof(StaticTask_t);
  1435. osThreadNew(Main_Task, NULL, &task_attr);
  1436. }
  1437. //Uart读取线程初始化
  1438. void Uart_Task_Init()
  1439. {
  1440. osThreadAttr_t task_attr;
  1441. memset(&task_attr,0,sizeof(task_attr));
  1442. memset(gProcess_Uart_TaskStack, 0xA5, PROC_UART_TASK_STACK_SIZE);
  1443. task_attr.name = "Uart_Task";
  1444. task_attr.stack_mem = gProcess_Uart_TaskStack;
  1445. task_attr.stack_size = PROC_UART_TASK_STACK_SIZE;
  1446. task_attr.priority = osPriorityBelowNormal7;
  1447. task_attr.cb_mem = &gProcess_Uart_Task_t;
  1448. task_attr.cb_size = sizeof(StaticTask_t);
  1449. osThreadNew(Uart_Task, NULL, &task_attr);
  1450. }
  1451. //Can线程初始化
  1452. void Can_Task_Init()
  1453. {
  1454. osThreadAttr_t task_attr;
  1455. memset(&task_attr,0,sizeof(task_attr));
  1456. memset(gProcess_Can_TaskStack, 0xA5, PROC_CAN_TASK_STACK_SIZE);
  1457. task_attr.name = "Can_Task";
  1458. task_attr.stack_mem = gProcess_Can_TaskStack;
  1459. task_attr.stack_size = PROC_CAN_TASK_STACK_SIZE;
  1460. task_attr.priority = osPriorityBelowNormal7;
  1461. task_attr.cb_mem = &gProcess_Can_Task_t;
  1462. task_attr.cb_size = sizeof(StaticTask_t);
  1463. osThreadNew(Can_Task, NULL, &task_attr);
  1464. }
  1465. //Tcp线程初始化
  1466. void Tcp_Task_Init()
  1467. {
  1468. osThreadAttr_t task_attr;
  1469. registerPSEventCallback(NB_GROUP_ALL_MASK, socketRegisterPSUrcCallback);
  1470. memset(&task_attr,0,sizeof(task_attr));
  1471. memset(gProcess_Tcp_TaskStack, 0xA5, PROC_TCP_TASK_STACK_SIZE);
  1472. task_attr.name = "Tcp_Task";
  1473. task_attr.stack_mem = gProcess_Tcp_TaskStack;
  1474. task_attr.stack_size = PROC_TCP_TASK_STACK_SIZE;
  1475. task_attr.priority = osPriorityBelowNormal7;
  1476. task_attr.cb_mem = &gProcess_Tcp_Task_t;
  1477. task_attr.cb_size = sizeof(StaticTask_t);
  1478. osThreadNew(Tcp_Task, NULL, &task_attr);
  1479. }
  1480. void appInit(void *arg)
  1481. {
  1482. Main_Task_Init();
  1483. Uart_Task_Init();
  1484. Can_Task_Init();
  1485. GpsTaskInit();
  1486. Tcp_Task_Init();
  1487. }
  1488. //主函数入口
  1489. void main_entry(void) {
  1490. BSP_CommonInit();
  1491. osKernelInitialize();
  1492. registerAppEntry(appInit, NULL);
  1493. if (osKernelGetState() == osKernelReady)
  1494. {
  1495. osKernelStart();
  1496. }
  1497. while(1);
  1498. }