UDSService.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662
  1. #include "bsp.h"
  2. #include "bsp_custom.h"
  3. #include "osasys.h"
  4. #include "ostask.h"
  5. #include "queue.h"
  6. #include "ps_event_callback.h"
  7. #include "cmisim.h"
  8. #include "cmimm.h"
  9. #include "cmips.h"
  10. #include "sockets.h"
  11. #include "psifevent.h"
  12. #include "ps_lib_api.h"
  13. #include "lwip/netdb.h"
  14. #include <cis_def.h>
  15. #include "debug_log.h"
  16. #include "slpman_ec616.h"
  17. #include "plat_config.h"
  18. #include "ec_tcpip_api.h"
  19. #include "hal_module_adapter.h"
  20. #include "UartTask.h"
  21. #include "MainTask.h"
  22. #include "app.h"
  23. #include "CANTask.h"
  24. #include "flash_ec616_rt.h"
  25. #include "Signal.h"
  26. #include "UDSService.h"
  27. extern AppSocketConnectionContext socContext;
  28. extern UINT8 GpsData[16];
  29. extern UINT8 battInfo[8*14];
  30. void UDS_Service(void);
  31. void UDS_CAN_Update(void);
  32. BOOL UDSClearFotaDownloadRegion(void);
  33. BOOL UDSAskforDownLoadData(void);
  34. UINT8 UDSPositiveAnswer(UINT8 answerLen,UINT8 messageIndex,UINT32 posCode);
  35. UINT8 UDSNegtiveAnswer(UINT8 answerLen,UINT8 messageIndex, UINT32 negCode);
  36. extern void appSaveConfigValue(void);
  37. UINT8 UDSService[2];
  38. UINT8 UDSSubService[2];
  39. UINT8 UDSSubServiceActionCode[2];
  40. UINT8 UDSSwitch = 0;
  41. UINT8 UDSDialogMode = 01;
  42. UINT8 UDSBattSN[BATT_SN_LEN];
  43. UINT32 updateDifferDataByteLen = 0;
  44. //each package means 100 bytes, max PackageCounter = updateDifferDataByteLen%100 + 1
  45. UINT16 updateDifferDataPackageCounter = 0;
  46. //each slice means 4 bytes, max SliceCounter = 25;
  47. UINT32 updateDifferDataSliceCounter = 0;
  48. static BOOL downloadReady = FALSE;
  49. UINT8 updateDataBuffer[100];
  50. void UDS_Service()
  51. {
  52. UINT8 i,j= 0;
  53. UINT32 k=0;
  54. INT8 ret,errorCount = 0;
  55. BOOL boolRet = false;
  56. static UINT8 snFlag = 0;
  57. static UINT32 sliceCounterFlag = 0;
  58. UINT32 tempSliceCounter=0;
  59. static UINT8 counter=0;
  60. CAN_Msg_Type UDSAnswer ={0};
  61. UINT32 posCode,negCode;
  62. //UINT8 temp00[94] ={0x00,0x0E,0x00,0x05,0x0D,0xDE,0x0D,0xDE,0x0D,0xDE,0x0D,0xDE,0x0D,0x7A,0x0D,0xDE,0x0D,0xDE,0x0D,0xDE,0x0D,0xDE,0x0D,0xDE,0x0E,0x42,0x0D,0xDE,0x0D,0xDE,0x0D,0xDE,0x13,0x38,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x21,0x00,0x24,0x00,0x26,0x00,0x22,0x00,0x24,0x00,0x00,0x00,0x00,0x6e,0x78,0x00,0x00,0x00,0x00,0x00,0x5F,0x00,0x62,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x13,0x74,0x0E,0x42,0x0D,0x7A,0x00,0x00};
  63. //MEMCPY(battInfo, temp00, 94);
  64. //while(true)
  65. //{
  66. //if(UDSSwitch == 1)
  67. {
  68. for(i=0; i<2; i++)
  69. {
  70. UDSAnswer.DLC = 8;
  71. memset(UDSAnswer.Data, 0, UDSAnswer.DLC);
  72. if(CanRxMsg[i].Id == 0x7A0)
  73. {
  74. switch (UDSService[i])
  75. {
  76. case 0x10:
  77. if(UDSSubService[i] == 0x01)
  78. {
  79. if((UDSDialogMode == 0x01 || UDSDialogMode==0x02)||UDSSwitch == 0)
  80. {
  81. UDSPositiveAnswer(0x04,i,0x00);
  82. UDSSwitch = 0;
  83. UDSDialogMode = 1;
  84. }
  85. else
  86. {
  87. UDSNegtiveAnswer(0x05,i,0xFF);
  88. }
  89. }
  90. else if(UDSSubService[i] == 0x02)
  91. {
  92. UDSPositiveAnswer(0x04,i,0x00);
  93. UDSSwitch = 1;
  94. UDSDialogMode = 2;
  95. }
  96. else if(UDSSubService[i] == 0x03)
  97. {
  98. if(UDSSwitch == 1)
  99. {
  100. UDSPositiveAnswer(0x04,i,0x00);
  101. UDSSwitch = 1;
  102. UDSDialogMode = 3;
  103. }
  104. else
  105. {
  106. UDSNegtiveAnswer(0x05,i,0xFF);
  107. }
  108. }
  109. else if(UDSSubService[i] == 0x11) //make NB software reset
  110. {
  111. if(UDSDialogMode == 2)
  112. {
  113. UDSPositiveAnswer(0x04,i,0x00);
  114. osDelay(100);
  115. appSaveNVMData();
  116. appSetCFUN(0);
  117. osDelay(1000);
  118. EC_SystemReset();
  119. }
  120. else
  121. {
  122. UDSNegtiveAnswer(0x05,i,0xFF);
  123. }
  124. }
  125. else
  126. {
  127. UDSNegtiveAnswer(0x05,i,0xEE);
  128. }
  129. break;
  130. case 0x22:
  131. if(UDSDialogMode == 2)
  132. {
  133. if(UDSSubService[i] == 0x01) //check the sw of NB
  134. {
  135. UDSPositiveAnswer(0x08,i,APPSWVERSION);
  136. }
  137. else if(UDSSubService[i] == 0x02) //check the hw of NB
  138. {
  139. UDSPositiveAnswer(0x06,i,HWVERSION);
  140. }
  141. else if(UDSSubService[i] == 0x03) //check the SN number
  142. {
  143. switch(UDSSubServiceActionCode[i])
  144. {
  145. case 00:
  146. UDSAnswer.Id = 0x7B0;
  147. CANEncodeFunction(UDSAnswer.Id, UDSAnswer.Data);
  148. ret = HAL_Can_Transmit(UDSAnswer);
  149. break;
  150. case 01:
  151. UDSAnswer.Id = 0x7B1;
  152. CANEncodeFunction(UDSAnswer.Id, UDSAnswer.Data);
  153. ret = HAL_Can_Transmit(UDSAnswer);
  154. break;
  155. case 02:
  156. UDSAnswer.Id = 0x7B2;
  157. CANEncodeFunction(UDSAnswer.Id, UDSAnswer.Data);
  158. ret = HAL_Can_Transmit(UDSAnswer);
  159. break;
  160. default:
  161. break;
  162. }
  163. }
  164. else if(UDSSubService[i] == 0x04) //check the batt message
  165. {
  166. UDSAnswer.Id = 0x7C0+UDSSubServiceActionCode[i];
  167. CANEncodeFunction(UDSAnswer.Id, UDSAnswer.Data);
  168. ret = HAL_Can_Transmit(UDSAnswer);
  169. }
  170. else if(UDSSubService[i] == 0x05) //check the enviroment temp of NB
  171. {
  172. UINT32 temp = ((fastChargeTemp<<24)&0xFF000000) | ((normalChargeTemp<<16)&0xFF0000) | ((heatTemp1<<8)&0xFF00) | (heatTemp2&0xFF);
  173. UDSPositiveAnswer(0x08,i,temp); //ntcvalue
  174. }
  175. else if(UDSSubService[i] == 0x06) //check the tcp link of NB
  176. {
  177. UDSPositiveAnswer(0x06,i,TcpSendLen); //TcpconnectStatus
  178. }
  179. else if(UDSSubService[i] == 0x07) //check the GPS link of NB
  180. {
  181. posCode =(UINT32) GpsData[1];
  182. UDSPositiveAnswer(0x05,i,posCode); //gps satellite num(uint8), should be modified
  183. }
  184. else
  185. {
  186. UDSNegtiveAnswer(0x05,i,0xEE);
  187. }
  188. }
  189. else //the service is not surpported in current dialog mode
  190. {
  191. UDSNegtiveAnswer(0x05,i,0xFF);
  192. }
  193. break;
  194. case 0x2E: //write service
  195. if(UDSDialogMode == 2)
  196. {
  197. if(UDSSubService[i] == 0x03) // write the battSN
  198. {
  199. if(UDSSubServiceActionCode[i] == 0x00 && snFlag == 0x00)
  200. {
  201. for(j=0; j<5; j++)
  202. {
  203. UDSBattSN[j+5*0] = CanRxMsg[i].Data[j+3];
  204. }
  205. snFlag = snFlag|0x01;
  206. }
  207. else if(UDSSubServiceActionCode[i] == 0x01 && snFlag == 0x01)
  208. {
  209. for(j=0; j<5; j++)
  210. {
  211. UDSBattSN[j+5*1] = CanRxMsg[i].Data[j+3];
  212. }
  213. snFlag = snFlag|0x02;
  214. }
  215. else if(UDSSubServiceActionCode[i] == 0x02 && snFlag == 0x03)
  216. {
  217. for(j=0; j<5; j++)
  218. {
  219. UDSBattSN[j+5*2] = CanRxMsg[i].Data[j+3];
  220. }
  221. snFlag = snFlag|0x04;
  222. }
  223. else if(UDSSubServiceActionCode[i] == 0x03 && snFlag == 0x07)
  224. {
  225. for(j=0; j<2; j++)
  226. {
  227. UDSBattSN[j+5*3] = CanRxMsg[i].Data[j+3];
  228. }
  229. snFlag = snFlag|0x08;
  230. }
  231. if(snFlag == 0x0F)
  232. {
  233. snFlag = 0;
  234. UDSPositiveAnswer(0x04,i,00);
  235. MEMCPY(AppNVMData.battSN, UDSBattSN, BATT_SN_LEN);
  236. AppNVMData.EOLState = 1; //SN号写入完成,表明已经进行过下线配置
  237. appSaveNVMData();
  238. }
  239. else
  240. {
  241. UDSAnswer.Id = 0x7A8;
  242. UDSAnswer.Data[0] = 0x05;
  243. UDSAnswer.Data[1] = 0x3E;
  244. UDSAnswer.Data[2] = UDSService[i];
  245. UDSAnswer.Data[3] = UDSSubService[i];
  246. UDSAnswer.Data[4] = snFlag;
  247. ret = HAL_Can_Transmit(UDSAnswer);
  248. }
  249. }
  250. else if(UDSSubService[i] == 0xFF)
  251. {
  252. RecoveyTheData();
  253. UDSPositiveAnswer(0x04,i,00);
  254. }
  255. else if(UDSSubService[i] == 0x0F) //write the update config:updateDifferDataByteLen
  256. {
  257. updateDifferDataByteLen = (CanRxMsg[i].Data[2]<<16)|(CanRxMsg[i].Data[3]<<8)|CanRxMsg[i].Data[4];
  258. UDSPositiveAnswer(0x04,i,00);
  259. }
  260. else
  261. {
  262. UDSNegtiveAnswer(0x05,i,0xEE);
  263. }
  264. break;
  265. }
  266. else
  267. {
  268. UDSNegtiveAnswer(0x05,i,0xFF);
  269. }
  270. break;
  271. case 0x31: //clear the flash service
  272. if(UDSDialogMode == 3)
  273. {
  274. if(UDSSubService[i] == 0x0F) //clear the fota flash
  275. {
  276. if(UDSSubServiceActionCode[i] == 0x01)
  277. {
  278. //Clear the Flash
  279. boolRet = UDSClearFotaDownloadRegion();
  280. //if ok
  281. UDSPositiveAnswer(0x05,i,(UINT32)boolRet);
  282. }
  283. else
  284. {
  285. UDSNegtiveAnswer(0x06,i,UDSSubServiceActionCode[i]<<8|0xFF); //重点测试
  286. }
  287. }
  288. else
  289. {
  290. UDSNegtiveAnswer(0x05,i,0xEE); //the subservice is not surpported
  291. }
  292. }
  293. else
  294. {
  295. UDSNegtiveAnswer(0x05,i,0xFF); //the survie is not surpported in current dialog mode
  296. }
  297. break;
  298. case 0x34: //prepare for some one process
  299. if(UDSDialogMode == 3)
  300. {
  301. if(UDSSubService[i] == 0x0F) //ask for download update data
  302. {
  303. boolRet = UDSAskforDownLoadData();
  304. //if ok
  305. UDSPositiveAnswer(0x05,i,(UINT32)boolRet);
  306. }
  307. else
  308. {
  309. UDSNegtiveAnswer(0x05,i,0xEE);
  310. }
  311. }
  312. else
  313. {
  314. UDSNegtiveAnswer(0x05,i,0xFF);
  315. }
  316. break;
  317. case 0x36: //download the update data
  318. if(UDSDialogMode == 3)
  319. {
  320. if(downloadReady == TRUE)
  321. {
  322. counter++; //记录报文数量
  323. tempSliceCounter = (CanRxMsg[i].Data[1]<<16)|(CanRxMsg[i].Data[2]<<8)|(CanRxMsg[i].Data[3]);
  324. /*
  325. #ifdef USING_PRINTF
  326. printf("tempSliceCounter = %x\n",tempSliceCounter);
  327. #endif
  328. */
  329. if(tempSliceCounter < (updateDifferDataPackageCounter+1)*25 && tempSliceCounter>=updateDifferDataPackageCounter*25)
  330. {
  331. updateDifferDataSliceCounter = tempSliceCounter % 25;
  332. for(j=0;j<4;j++)
  333. {
  334. updateDataBuffer[updateDifferDataSliceCounter*4+j] = CanRxMsg[i].Data[4+j];
  335. }
  336. if(updateDifferDataSliceCounter>0)
  337. {
  338. sliceCounterFlag = sliceCounterFlag |(0x01<<updateDifferDataSliceCounter);
  339. }
  340. else
  341. {
  342. sliceCounterFlag = sliceCounterFlag |0x01;
  343. }
  344. /*
  345. #ifdef USING_PRINTF
  346. printf("sliceCounterFlag = %x counter=%d\n",sliceCounterFlag,counter);
  347. #endif
  348. */
  349. }
  350. else
  351. {
  352. counter--;
  353. }
  354. if(counter == 25)
  355. {
  356. counter = 0;
  357. if(sliceCounterFlag == 0x1FFFFFF) //received all the 25 message of current package
  358. {
  359. //write the buffer(100 byte) to flash
  360. ret = (uint8_t)BSP_QSPI_Write_Safe(updateDataBuffer,FLASH_FOTA_REGION_START+(updateDifferDataPackageCounter)*100,100);
  361. errorCount = 0;
  362. while(ret != QSPI_OK && errorCount<3) //try to write most 3 times
  363. {
  364. errorCount++;
  365. BSP_QSPI_Erase_Safe(FLASH_FOTA_REGION_START+(updateDifferDataPackageCounter)*100,100);
  366. ret = (uint8_t)BSP_QSPI_Write_Safe(updateDataBuffer,FLASH_FOTA_REGION_START+(updateDifferDataPackageCounter)*100,100);
  367. }
  368. if(ret == QSPI_OK) // write successed
  369. {
  370. UDSPositiveAnswer(0x08,i,tempSliceCounter);
  371. /*
  372. #if 0
  373. #ifdef USING_PRINTF
  374. UINT8 checksum0,checksum1=0;
  375. printf("updateDifferDataPackageCounter = %d\n",updateDifferDataPackageCounter);
  376. printf("updateDataBuffer write:\n");
  377. for(k=0;k<100;k++)
  378. {
  379. printf("%x ",updateDataBuffer[k]);
  380. checksum0+=updateDataBuffer[k];
  381. }
  382. printf("\n");
  383. UINT8 readFlash=0;
  384. printf("updateDataBuffer read:\n");
  385. for(k=0;k<100;k++)
  386. {
  387. BSP_QSPI_Read_Safe(&readFlash,FLASH_FOTA_REGION_START+updateDifferDataPackageCounter*100+k, 1);
  388. printf("%2x ",readFlash);
  389. checksum1+=readFlash;
  390. }
  391. printf("\n");
  392. if(checksum0 == checksum1)
  393. {
  394. printf("write succeed!\nchecksum0 = %2x,checksum1 = %2x\n",checksum0,checksum1);
  395. }
  396. else
  397. {
  398. printf("write fail!\nchecksum0 = %2x,checksum1 = %2x\n",checksum0,checksum1);
  399. }
  400. //printf("write succeed, next updateDifferDataPackageCounter = %x\n",updateDifferDataPackageCounter+1);
  401. #endif
  402. #endif
  403. */
  404. memset(updateDataBuffer,0, 100);
  405. sliceCounterFlag = 0x0;
  406. updateDifferDataPackageCounter++;
  407. }
  408. else //write fail
  409. {
  410. UDSNegtiveAnswer(0x08,i,0xFFFFFFFF); //failed to write this package to flash
  411. /*
  412. #if 0
  413. #ifdef USING_PRINTF
  414. printf("write flash fail!! updateDifferDataPackageCounter = %d\n",updateDifferDataPackageCounter);
  415. printf("ERROR: sliceCounterFlag=%x\n",sliceCounterFlag);
  416. #endif
  417. #endif
  418. */
  419. }
  420. }
  421. else
  422. {
  423. //received 25 messages, but lose one or more messages
  424. //in this case, updater will try to send the package again(most 4 times)
  425. UDSNegtiveAnswer(0x08,i,sliceCounterFlag);
  426. #ifdef USING_PRINTF
  427. printf("ERROR: package lose one or mo message!! sliceCounterFlag = %x\n",sliceCounterFlag);
  428. #endif
  429. //sliceCounterFlag = 0x0;
  430. /*
  431. #ifdef USING_PRINTF
  432. printf("updateDifferDataPackageCounter = %d\n",updateDifferDataPackageCounter+1);
  433. printf("updateDataBuffer:\n");
  434. for(k=0;k<100;k++)
  435. {
  436. printf("%x ",updateDataBuffer[k]);
  437. }
  438. printf("\n");
  439. #endif
  440. */
  441. //memset(updateDataBuffer,0, 100);
  442. }
  443. }
  444. }
  445. else
  446. {
  447. UDSNegtiveAnswer(0x05,i,0xEF); //the download process is not ready
  448. counter = 0;
  449. }
  450. }
  451. else
  452. {
  453. UDSNegtiveAnswer(0x05,i,0xFF); //the service is not surpported in current dialog mode
  454. }
  455. break;
  456. case 0x37: //exit some one process
  457. if(UDSDialogMode == 3)
  458. {
  459. if(UDSSubService[i] == 0x0F) // exit the download
  460. {
  461. UDSPositiveAnswer(0x04,i,0x00);
  462. /*
  463. #if 0
  464. #ifdef USING_PRINTF
  465. printf("CAN update data:\n");
  466. UINT8 ts=0;
  467. for(UINT32 jjj =0;jjj<updateDifferDataByteLen;jjj++)
  468. {
  469. BSP_QSPI_Read_Safe(&ts,FLASH_FOTA_REGION_START+jjj,1);
  470. printf("%x ",ts);
  471. }
  472. printf("\n");
  473. #endif
  474. #endif
  475. */
  476. downloadReady = FALSE;
  477. }
  478. else
  479. {
  480. UDSNegtiveAnswer(0x05,i,0xEE);
  481. }
  482. }
  483. else
  484. {
  485. UDSNegtiveAnswer(0x05,i,0xFF);
  486. }
  487. break;
  488. default:
  489. UDSNegtiveAnswer(0x04,i,0xFF); //the service is not surpported
  490. break;
  491. }
  492. }
  493. }
  494. }
  495. //}
  496. for(i=0; i<2; i++)
  497. {
  498. UDSService[i] = 0;
  499. UDSSubService[i] = 0;
  500. }
  501. }
  502. UINT8 UDSPositiveAnswer(UINT8 answerLen,UINT8 messageIndex,UINT32 posCode)
  503. {
  504. CAN_Msg_Type UDSAnswer;
  505. UINT8 ret;
  506. UDSAnswer.Id = 0x7A8;
  507. UDSAnswer.DLC = 8;
  508. UDSAnswer.Data[0] = answerLen;
  509. UDSAnswer.Data[1] = 0x78;
  510. UDSAnswer.Data[2] = UDSService[messageIndex];
  511. UDSAnswer.Data[3] = UDSSubService[messageIndex];
  512. if(answerLen == 4)
  513. {
  514. UDSAnswer.Data[4] = 0x00;
  515. UDSAnswer.Data[5] = 0x00;
  516. UDSAnswer.Data[6] = 0x00;
  517. UDSAnswer.Data[7] = 0x00;
  518. }
  519. else if(answerLen==5)
  520. { UDSAnswer.Data[4] = posCode;
  521. UDSAnswer.Data[5] = 0x00;
  522. UDSAnswer.Data[6] = 0x00;
  523. UDSAnswer.Data[7] = 0x00;
  524. }
  525. else if(answerLen==6)
  526. {
  527. UDSAnswer.Data[4] = posCode>>8;
  528. UDSAnswer.Data[5] = posCode;
  529. UDSAnswer.Data[6] = 0x00;
  530. UDSAnswer.Data[7] = 0x00;
  531. }
  532. else if(answerLen==7)
  533. {
  534. UDSAnswer.Data[4] = posCode>>16;
  535. UDSAnswer.Data[5] = posCode>>8;
  536. UDSAnswer.Data[6] = posCode;
  537. UDSAnswer.Data[7] = 0x00;
  538. }
  539. else if(answerLen==8)
  540. {
  541. UDSAnswer.Data[4] = posCode>>24;
  542. UDSAnswer.Data[5] = posCode>>16;
  543. UDSAnswer.Data[6] = posCode>>8;
  544. UDSAnswer.Data[7] = posCode;
  545. }
  546. ret = HAL_Can_Transmit(UDSAnswer);
  547. return ret;
  548. }
  549. UINT8 UDSNegtiveAnswer(UINT8 answerLen,UINT8 messageIndex, UINT32 negCode)
  550. {
  551. CAN_Msg_Type UDSAnswer;
  552. UINT8 ret;
  553. UDSAnswer.Id = 0x7A8;
  554. UDSAnswer.DLC = 8;
  555. UDSAnswer.Data[0] = answerLen;
  556. UDSAnswer.Data[1] = 0x7F;
  557. UDSAnswer.Data[2] = UDSService[messageIndex];
  558. UDSAnswer.Data[3] = UDSSubService[messageIndex];
  559. if(answerLen==4)
  560. {
  561. UDSAnswer.Data[3] = negCode;
  562. UDSAnswer.Data[4] = 0x00;
  563. UDSAnswer.Data[5] = 0x00;
  564. UDSAnswer.Data[6] = 0x00;
  565. UDSAnswer.Data[7] = 0x00;
  566. }
  567. if(answerLen==5)
  568. { UDSAnswer.Data[4] = negCode;
  569. UDSAnswer.Data[5] = 0x00;
  570. UDSAnswer.Data[6] = 0x00;
  571. UDSAnswer.Data[7] = 0x00;
  572. }
  573. else if(answerLen==6)
  574. {
  575. UDSAnswer.Data[4] = negCode>>8;
  576. UDSAnswer.Data[5] = negCode;
  577. UDSAnswer.Data[6] = 0x00;
  578. UDSAnswer.Data[7] = 0x00;
  579. }
  580. else if(answerLen==7)
  581. {
  582. UDSAnswer.Data[4] = negCode>>16;
  583. UDSAnswer.Data[5] = negCode>>8;
  584. UDSAnswer.Data[6] = negCode;
  585. UDSAnswer.Data[7] = 0x00;
  586. }
  587. else if(answerLen==8)
  588. {
  589. UDSAnswer.Data[4] = negCode>>24;
  590. UDSAnswer.Data[5] = negCode>>16;
  591. UDSAnswer.Data[6] = negCode>>8;
  592. UDSAnswer.Data[7] = negCode;
  593. }
  594. ret = HAL_Can_Transmit(UDSAnswer);
  595. return ret;
  596. }
  597. BOOL UDSAskforDownLoadData()
  598. {
  599. updateDifferDataPackageCounter = 0;
  600. downloadReady = true;
  601. return TRUE;
  602. }
  603. BOOL UDSClearFotaDownloadRegion()
  604. {
  605. UINT8 ret = FALSE;
  606. ret = BSP_QSPI_Erase_Safe(FLASH_FOTA_REGION_START, 0x46000); //512k-32k -200k = 280k -> 0x46000
  607. if(ret == QSPI_OK)
  608. {
  609. return TRUE;
  610. }
  611. else
  612. {
  613. return FALSE;
  614. }
  615. }