Module_UpdateFW.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698
  1. #include <stdio.h> /*標準輸入輸出定義*/
  2. #include <stdlib.h> /*標準函數庫定義*/
  3. #include <string.h>
  4. #include <stdint.h>
  5. #include <sys/types.h>
  6. #include <dirent.h>
  7. #include "../Config.h"
  8. #include "../Log/log.h"
  9. #include "../Define/define.h"
  10. #include "../ShareMemory/shmMem.h"
  11. #include "../CSU/main.h"
  12. struct SysConfigData *pSysConfig = NULL;
  13. struct SysInfoData *pSysInfo = NULL;
  14. struct OCPP16Data *ShmOCPP16Data = NULL;
  15. struct ChargingInfoData *pAcChargingInfo = NULL;
  16. static struct ChargingInfoData *pDcChargingInfo = NULL;
  17. #define MODELNAME_FAIL (0)
  18. #define UPGRADE_FAN (0x02)
  19. #if defined DD360 || defined DD360Audi || defined DD360ComBox
  20. #define UPGRADE_RB (0x09) //0x09 for DD360 dispenser
  21. #else
  22. #define UPGRADE_RB (0x03) //other module use
  23. #endif //defined DD360 ||defined DD360Audi || defined DD360ComBox
  24. #define UPGRADE_PRI (0x04)
  25. #define UPGRADE_AC (0x05)
  26. #define UPGRADE_LED (0x06)
  27. //------------------------------------------------------------------------------
  28. static char *_priPortName = "/dev/ttyS1";
  29. static char *_485PortName = "/dev/ttyS5";
  30. //------------------------------------------------------------------------------
  31. void KillAllTask(void)
  32. {
  33. pSysInfo->PageIndex = _LCM_FIX;
  34. system("killall Module_EventLogging");
  35. system("killall Module_PrimaryComm");
  36. system("killall Module_EvComm");
  37. system("killall Module_LcmControl");
  38. system("killall Module_InternalComm");
  39. #if defined DD360 || defined DD360Audi || defined DD360ComBox
  40. system("killall Module_DoComm");
  41. return ;
  42. #endif //defined DD360 || defined DD360Audi || defined DD360ComBox
  43. system("killall Module_PsuComm");
  44. system("killall OcppBackend &");
  45. system("killall Module_4g &");
  46. system("killall Module_Wifi &");
  47. }
  48. void KillTask(void)
  49. {
  50. pSysInfo->PageIndex = _LCM_FIX;
  51. system("killall Module_EventLogging");
  52. system("killall Module_PrimaryComm");
  53. system("killall Module_EvComm");
  54. system("killall Module_LcmControl");
  55. system("killall Module_InternalComm");
  56. //system("killall Module_DoComm");
  57. #if defined DD360 || defined DD360Audi || defined DD360ComBox
  58. return ;
  59. #endif //defined DD360 || defined DD360Audi || defined DD360ComBox
  60. system("killall Module_PsuComm");
  61. system("killall OcppBackend &");
  62. system("killall Module_4g &");
  63. system("killall Module_Wifi &");
  64. }
  65. void setChargerMode(uint8_t gunIndex, uint8_t mode)
  66. {
  67. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
  68. pDcChargingInfo->SystemStatus = mode;
  69. log_info(" ====== System Status:%d ======",mode);
  70. }
  71. void TryCloseWatchdog()
  72. {
  73. system("echo V > /dev/watchdog");
  74. }
  75. static int InitComPort(uint8_t target)
  76. {
  77. int fd;
  78. struct termios tios;
  79. if (target == UPGRADE_PRI) {
  80. fd = open(_priPortName, O_RDWR);
  81. } else if (target == UPGRADE_FAN ||
  82. target == UPGRADE_RB ||
  83. target == UPGRADE_AC ||
  84. target == UPGRADE_LED
  85. ) {
  86. fd = open(_485PortName, O_RDWR);
  87. }
  88. if (fd <= 0) {
  89. log_error("open 407 Communication port NG ");
  90. return -1;
  91. }
  92. ioctl (fd, TCGETS, &tios);
  93. tios.c_cflag = B115200 | CS8 | CLOCAL | CREAD;
  94. tios.c_lflag = 0;
  95. tios.c_iflag = 0;
  96. tios.c_oflag = 0;
  97. tios.c_cc[VMIN] = 0;
  98. tios.c_cc[VTIME] = (uint8_t)1;
  99. tios.c_lflag = 0;
  100. tcflush(fd, TCIFLUSH);
  101. ioctl (fd, TCSETS, &tios);
  102. return fd;
  103. }
  104. bool IsConnectorWholeIdle()
  105. {
  106. bool result = true;
  107. for (uint8_t count = 0; count < pSysConfig->TotalConnectorCount; count++) {
  108. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(count);
  109. if (pDcChargingInfo->SystemStatus != S_IDLE &&
  110. pDcChargingInfo->SystemStatus != S_RESERVATION) {
  111. result = false;
  112. break;
  113. }
  114. }
  115. for (uint8_t count = 0; count < pSysConfig->AcConnectorCount; count++) {
  116. pAcChargingInfo = (struct ChargingInfoData *)GetAcChargingInfoData(count);
  117. if (pAcChargingInfo->SystemStatus != S_IDLE &&
  118. pAcChargingInfo->IsErrorOccur == NO) {
  119. result = false;
  120. break;
  121. }
  122. }
  123. return result;
  124. }
  125. static int InitCanBus(void)
  126. {
  127. int fd = -1;
  128. int nbytes;
  129. struct timeval tv;
  130. struct ifreq ifr0;
  131. struct sockaddr_can addr0;
  132. system("/sbin/ip link set can0 down");
  133. system("/sbin/ip link set can0 type can bitrate 500000 restart-ms 100");
  134. system("/sbin/ip link set can0 up");
  135. fd = socket(PF_CAN, SOCK_RAW, CAN_RAW);
  136. tv.tv_sec = 0;
  137. tv.tv_usec = 10000;
  138. if (setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv, sizeof(struct timeval)) < 0) {
  139. log_error("Set SO_RCVTIMEO NG");
  140. }
  141. nbytes = 40960;
  142. if (setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &nbytes, sizeof(int)) < 0) {
  143. log_error("Set SO_RCVBUF NG");
  144. }
  145. nbytes = 40960;
  146. if (setsockopt(fd, SOL_SOCKET, SO_SNDBUF, &nbytes, sizeof(int)) < 0) {
  147. log_error("Set SO_SNDBUF NG");
  148. }
  149. strcpy(ifr0.ifr_name, "can0");
  150. ioctl(fd, SIOCGIFINDEX, &ifr0); /* ifr.ifr_ifindex gets filled with that device's index */
  151. addr0.can_family = AF_CAN;
  152. addr0.can_ifindex = ifr0.ifr_ifindex;
  153. bind(fd, (struct sockaddr *)&addr0, sizeof(addr0));
  154. return fd;
  155. }
  156. unsigned long long getAvailableMemory()
  157. {
  158. system("pkill ntpd");
  159. sleep(1);
  160. long pages = sysconf(_SC_AVPHYS_PAGES);
  161. long page_size = sysconf(_SC_PAGE_SIZE);
  162. log_info("Avaiable Memory size:%d MB",(pages*page_size/(1024*1024)));
  163. return pages * page_size;
  164. }
  165. bool CreateBufferForLcmFile(char *file)
  166. {
  167. bool result = FAIL;
  168. unsigned char *ptr = NULL;
  169. long int MaxLen = 100 * 1024 * 1024, ImageLen = 0;
  170. int fd, fd_lcm;
  171. int wrd_lcm;
  172. char Buf_lcm[256] = "/mnt/BUFFER.zip";
  173. fd = open ( file, O_RDONLY );
  174. if (fd < 0) {
  175. close ( fd );
  176. return result;
  177. }
  178. ptr = malloc(MaxLen);
  179. ImageLen = read(fd, ptr, MaxLen);
  180. fd_lcm = open ( Buf_lcm, O_RDWR | O_CREAT | O_EXCL );
  181. if (fd_lcm < 0) {
  182. log_info( "Can not create %s \n", Buf_lcm );
  183. } else {
  184. log_info( "Writing data to %s file.... \n", Buf_lcm );
  185. wrd_lcm = write ( fd_lcm, ptr + 48, ImageLen - 48 );
  186. close ( fd_lcm );
  187. log_info( ">> %s Written length : 0x%x \n", Buf_lcm, wrd_lcm );
  188. if (wrd_lcm != (ImageLen - 48)) {
  189. result = FAIL;
  190. } else {
  191. result = PASS;
  192. }
  193. close(fd);
  194. free(ptr);
  195. }
  196. return result;
  197. }
  198. bool CreateAPKForLcmFile(char *file)
  199. {
  200. bool result = FAIL;
  201. unsigned char *ptr = NULL;
  202. long int MaxLen = 100 * 1024 * 1024, ImageLen = 0;
  203. int fd, fd_lcm;
  204. int wrd_lcm;
  205. char Buf_lcm[256] = "/mnt/evcharging.apk";
  206. fd = open ( file, O_RDONLY );
  207. if (fd < 0) {
  208. close ( fd );
  209. return result;
  210. }
  211. ptr = malloc(MaxLen);
  212. ImageLen = read(fd, ptr, MaxLen);
  213. fd_lcm = open ( Buf_lcm, O_RDWR | O_CREAT | O_EXCL );
  214. if (fd_lcm < 0) {
  215. log_info( "Can not create %s \n", Buf_lcm );
  216. } else {
  217. log_info( "Writing data to %s file.... \n", Buf_lcm );
  218. wrd_lcm = write ( fd_lcm, ptr + 48, ImageLen - 48 );
  219. close ( fd_lcm );
  220. log_info( ">> %s Written length : 0x%x \n", Buf_lcm, wrd_lcm );
  221. if (wrd_lcm != (ImageLen - 48)) {
  222. result = FAIL;
  223. } else {
  224. result = PASS;
  225. }
  226. close(fd);
  227. free(ptr);
  228. }
  229. return result;
  230. }
  231. bool CreateAdVideoForLcmFile(char *file)
  232. {
  233. bool result = FAIL;
  234. unsigned char *ptr = NULL;
  235. long int MaxLen = 100 * 1024 * 1024, ImageLen = 0;
  236. int fd, fd_lcm;
  237. int wrd_lcm;
  238. char Buf_lcm[256] = "/mnt/videoPresent.mp4";
  239. fd = open ( file, O_RDONLY );
  240. if (fd < 0) {
  241. close ( fd );
  242. return result;
  243. }
  244. ptr = malloc(MaxLen);
  245. ImageLen = read(fd, ptr, MaxLen);
  246. fd_lcm = open ( Buf_lcm, O_RDWR | O_CREAT | O_EXCL );
  247. if (fd_lcm < 0) {
  248. log_info( "Can not create %s \n", Buf_lcm );
  249. } else {
  250. log_info( "Writing data to %s file.... \n", Buf_lcm );
  251. wrd_lcm = write ( fd_lcm, ptr + 48, ImageLen - 48 );
  252. close ( fd_lcm );
  253. log_info( ">> %s Written length : 0x%x \n", Buf_lcm, wrd_lcm );
  254. if (wrd_lcm != (ImageLen - 48)) {
  255. result = FAIL;
  256. } else {
  257. result = PASS;
  258. }
  259. close(fd);
  260. free(ptr);
  261. }
  262. return result;
  263. }
  264. static int CheckUpdateProcess(void)
  265. {
  266. //bool isPass = true;
  267. uint8_t retSucc = 0;
  268. uint8_t retFail = 0;
  269. uint8_t index = 0;
  270. uint8_t target = 0;
  271. char Buf[256];
  272. char *new_str = NULL;
  273. uint8_t *ptr = NULL;
  274. int fd = 0;
  275. int CanFd = 0;
  276. int uartFd = 0;
  277. unsigned int Type = 0;
  278. long int MaxLen = 48 * 1024 * 1024, ImageLen = 0;
  279. DIR *d;
  280. struct dirent *dir;
  281. DcCommonInfo *ShmDcCommonData = (DcCommonInfo *)GetShmDcCommonData();
  282. struct ChargingInfoData *pDcChargingInfo = NULL;
  283. if (getAvailableMemory() < (200 * 1024 * 1024))
  284. {
  285. log_info("Available memory less than 200 MBytes, free cache first.\n");
  286. system("echo 3 > /proc/sys/vm/drop_caches");
  287. }
  288. pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
  289. d = opendir("/mnt/");
  290. if (d) {
  291. while ((dir = readdir(d)) != NULL) {
  292. if (strcmp(dir->d_name, ".") == 0 || strcmp(dir->d_name, "..") == 0) {
  293. continue;
  294. }
  295. new_str = calloc(strlen("/mnt/") + strlen(dir->d_name) + 1, sizeof(char));
  296. //new_str[0] = '\0';
  297. strcat(new_str, "/mnt/");
  298. strcat(new_str, dir->d_name);
  299. log_info("%s%s", "/mnt/", dir->d_name);
  300. fd = open(new_str, O_RDONLY);
  301. if (fd < 0) {
  302. return FAIL;
  303. }
  304. ptr = calloc(MaxLen, sizeof(char)); //-48 is take out the header
  305. //memset(ptr, 0xFF, MaxLen); //-48 is take out the header
  306. //get the image length
  307. ImageLen = read(fd, ptr, MaxLen);
  308. for (uint8_t i = 0; i < 16; i++) {
  309. if (pSysConfig->ModelName[i] != ptr[i]) {
  310. return FAIL;
  311. }
  312. }
  313. log_info("model name check pass. ");
  314. if (ImageLen > 20) {
  315. Type = (((unsigned int)ptr[16]) << 24 |
  316. ((unsigned int)ptr[17]) << 16 |
  317. ((unsigned int)ptr[18]) << 8 |
  318. ((unsigned int)ptr[19]));
  319. log_info("Typed...%x ", Type);
  320. free(ptr);
  321. switch (Type) {
  322. case 0x10000001:
  323. case 0x10000002:
  324. case 0x10000003:
  325. case 0x10000004:
  326. case 0x10000005:
  327. if (Upgrade_Flash(Type, new_str, (char *)pSysConfig->ModelName) == PASS) {
  328. //return PASS;
  329. retSucc++;
  330. } else {
  331. log_info("Upgrade %x Failed", Type);
  332. //return FAIL;
  333. retFail++;
  334. }
  335. break;
  336. case 0x10000007:
  337. case 0x10000008:
  338. case 0x10000009:
  339. case 0x1000000A:
  340. CanFd = InitCanBus();
  341. if (CanFd > 0) {
  342. for (index = 0; index < pSysConfig->TotalConnectorCount; index++) {
  343. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(index);
  344. if (pDcChargingInfo->Type == _Type_CCS_2) {
  345. uint8_t targetID = pDcChargingInfo->Evboard_id;
  346. if (pSysConfig->TotalConnectorCount == 1 &&
  347. ShmDcCommonData->CcsVersion == _CCS_VERSION_CHECK_TAG_V015S0) {
  348. //targetID += 1;
  349. }
  350. system("echo 3 > /proc/sys/vm/drop_caches");
  351. sleep(2);
  352. log_info("Upgrade CCS Processing..target id = %d ", targetID);
  353. if (Upgrade_CCS(CanFd,
  354. Type,
  355. targetID,
  356. new_str,
  357. (char *)pSysConfig->ModelName) == FAIL) {
  358. log_info("Upgrade CCS Failed ");
  359. retFail++;
  360. } else {
  361. retSucc++;
  362. }
  363. }
  364. }
  365. close(CanFd);
  366. }
  367. memset(Buf, 0, sizeof(Buf));
  368. sprintf(Buf, "rm -rvf /mnt/%s", new_str);
  369. system(Buf);
  370. //isPass = true;
  371. #if 0
  372. CanFd = InitCanBus();
  373. if (CanFd > 0) {
  374. for (index = 0; index < pSysConfig->TotalConnectorCount; index++) {
  375. //if (!isPass) {
  376. // break;
  377. //}
  378. if (chargingInfo[index]->Type == _Type_CCS_2) {
  379. if (Upgrade_CCS(CanFd, Type, chargingInfo[index]->Evboard_id, new_str, (char *)pSysConfig->ModelName) == FAIL) {
  380. //isPass = false;
  381. log_info("Upgrade %x Failed", Type);
  382. retFail++;
  383. }
  384. }
  385. }
  386. } else {
  387. log_error("Upgrade CCS open CAN FD fail.");
  388. //isPass = false;
  389. return FAIL;
  390. }
  391. if (retFail != 0) {
  392. break;
  393. } else {
  394. retSucc++;
  395. }
  396. //return isPass;
  397. #endif //0
  398. break;
  399. case 0x10000006:
  400. case 0x1000000D:
  401. case 0x1000000E:
  402. case 0x20000002:
  403. case 0x10000014:
  404. // CSU_PRIMARY_CONTROLLER : 0x10000006
  405. target = 0x00;
  406. if (Type == 0x10000006) {
  407. target = UPGRADE_PRI;
  408. } else if (Type == 0x1000000D) {
  409. target = UPGRADE_RB;
  410. } else if (Type == 0x1000000E) {
  411. target = UPGRADE_FAN;
  412. } else if (Type == 0x20000002) {
  413. target = UPGRADE_AC;
  414. } else if (Type == 0x10000014) {
  415. target = UPGRADE_LED;
  416. }
  417. uartFd = InitComPort(target);
  418. if (Upgrade_UART(uartFd, Type, target, new_str, (char *)pSysConfig->ModelName) == PASS) {
  419. //return PASS;
  420. retSucc++;
  421. } else {
  422. log_info("Upgrade %x Failed", Type);
  423. //return FAIL;
  424. return FAIL;
  425. }
  426. if (uartFd > 0) {
  427. close(uartFd);
  428. }
  429. break;
  430. case 0x1000000B:
  431. case 0x1000000C:
  432. // CHAdeMO_BOARD : 0x1000000B, GBT : 0x1000000C
  433. //bool isPass = true;
  434. CanFd = InitCanBus();
  435. if (CanFd > 0) {
  436. for (index = 0; index < pSysConfig->TotalConnectorCount; index++) {
  437. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(index);
  438. //if (!isPass) {
  439. // break;
  440. //}
  441. if ((Type == 0x1000000B && pDcChargingInfo->Type == _Type_Chademo) ||
  442. (Type == 0x1000000C && pDcChargingInfo->Type == _Type_GB)) {
  443. if (Upgrade_CAN(CanFd, Type, pDcChargingInfo->Evboard_id, new_str, (char *)pSysConfig->ModelName) == PASS) {
  444. //isPass = PASS;
  445. retSucc++;
  446. } else {
  447. log_info("Upgrade %x Failed", Type);
  448. //isPass = FAIL;
  449. retFail++;
  450. }
  451. }
  452. }
  453. } else {
  454. log_info("Upgrad FD fail. ");
  455. //isPass = false;
  456. return FAIL;
  457. }
  458. //return isPass;
  459. break;
  460. case 0x1000000F:
  461. // Update LCM
  462. if (CreateBufferForLcmFile(new_str)) {
  463. system("chmod 777 /mnt/BUFFER.zip");
  464. log_info("Start Upgrade LCM Firmware.");
  465. ShmDcCommonData->_upgrade_lcm_flag = YES;
  466. while (ShmDcCommonData->_upgrade_lcm_result == _LCM_UPGRADE_RESULT_WAIT) {
  467. sleep(5);
  468. }
  469. if (ShmDcCommonData->_upgrade_lcm_result == _LCM_UPGRADE_RESULT_PASS) {
  470. retSucc++;
  471. } else
  472. retFail++;
  473. } else {
  474. log_info("CreateBufferForLcmFile fail");
  475. }
  476. break;
  477. case 0x10000015:
  478. if (CreateAPKForLcmFile(new_str)) {
  479. //system("chmod 777 /mnt/BUFFER.zip");
  480. //system("unzip /mnt/BUFFER.zip -d /mnt/");
  481. system("chmod 777 /mnt/evcharging.apk");
  482. log_info("Start Upgrade LCM Firmware.");
  483. ShmDcCommonData->_upgrade_lcm_apk_flag = YES;
  484. while (ShmDcCommonData->_upgrade_lcm_result == _LCM_UPGRADE_RESULT_WAIT) {
  485. sleep(5);
  486. }
  487. if (ShmDcCommonData->_upgrade_lcm_result == _LCM_UPGRADE_RESULT_PASS) {
  488. retSucc++;
  489. return PASS;
  490. } else
  491. retFail++;
  492. } else {
  493. log_info("CreateAPKForLcmFile fail");
  494. }
  495. break;
  496. case 0x10000016:
  497. if (CreateAdVideoForLcmFile(new_str)) {
  498. system("chmod 777 /mnt/videoPresent.mp4");
  499. log_info("Start Upgrade Ad Video");
  500. if (system("ftpput -u zerova -p zerova@2022 192.168.0.60 /srv/ads/videoPresent.mp4 /mnt/videoPresent.mp4")) {
  501. retSucc++;
  502. return PASS;
  503. } else
  504. retFail++;
  505. } else {
  506. log_info("CreateAdVideoForLcmFile fail");
  507. }
  508. break;
  509. }
  510. } else {
  511. free(ptr);
  512. }
  513. free(new_str);
  514. }
  515. }
  516. //free(dir);
  517. closedir(d);
  518. if (retFail != 0) {
  519. return FAIL;
  520. }
  521. return PASS;
  522. }
  523. void CheckFwUpdateFunction(void)
  524. {
  525. //log_info("pSysInfo->FirmwareUpdate = %d ", pSysInfo->FirmwareUpdate);
  526. if (pSysInfo->FirmwareUpdate == YES) {
  527. log_info("ftp : update start. ");
  528. TryCloseWatchdog();
  529. pSysInfo->SystemPage = _LCM_FIX;
  530. for (uint8_t gun_index = 0; gun_index < pSysConfig->TotalConnectorCount; gun_index++) {
  531. setChargerMode(gun_index, MODE_UPDATE);
  532. }
  533. sleep(1);
  534. uint8_t updateResult = CheckUpdateProcess();
  535. if (updateResult == PASS) {
  536. log_info("ftp : update complete. ");
  537. } else if (updateResult == MODELNAME_FAIL) {
  538. log_info("ftp : model name is none match. ");
  539. KillAllTask();
  540. pSysInfo->FirmwareUpdate = NO;
  541. sleep(5);
  542. system("/usr/bin/run_evse_restart.sh");
  543. return;
  544. } else {
  545. log_info("ftp : update fail. ");
  546. }
  547. pSysInfo->FirmwareUpdate = NO;
  548. sleep(5);
  549. system("reboot -f");
  550. } else if (ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq == YES) {
  551. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = NO;
  552. if (strcmp((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "Downloaded") == EQUAL) {
  553. log_info("Backend : update start. ");
  554. TryCloseWatchdog();
  555. strcpy((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "");
  556. strcpy((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "Installing");
  557. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = YES;
  558. KillTask();
  559. for (uint8_t _index = 0; _index < pSysConfig->TotalConnectorCount; _index++) {
  560. setChargerMode(_index, MODE_UPDATE);
  561. }
  562. for (uint8_t _index = 0; _index < pSysConfig->AcConnectorCount; _index++) {
  563. pAcChargingInfo = (struct ChargingInfoData *)GetAcChargingInfoData(_index);
  564. pAcChargingInfo->SystemStatus = MODE_UPDATE;
  565. }
  566. sleep(1);
  567. uint8_t updateResult = CheckUpdateProcess();
  568. if (updateResult == PASS) {
  569. log_info("Backend : update complete. ");
  570. strcpy((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "Installed");
  571. } else if (updateResult == MODELNAME_FAIL) {
  572. log_info("Backend : model name is none match. ");
  573. KillAllTask();
  574. strcpy((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "InstallationFailed");
  575. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = YES;
  576. sleep(5);
  577. system("/usr/bin/run_evse_restart.sh");
  578. return;
  579. } else {
  580. log_info("Backend : update fail. ");
  581. strcpy((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "InstallationFailed");
  582. }
  583. strcpy((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "Installed");
  584. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = YES;
  585. sleep(5);
  586. system("reboot -f");
  587. }
  588. }
  589. }
  590. int main(int argc, char *argv[])
  591. {
  592. if (CreateAllCsuShareMemory() == FAIL) {
  593. log_error("create share memory error");
  594. return FAIL;
  595. }
  596. MappingGunChargingInfo("Upgrade Task");
  597. pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
  598. pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
  599. ShmOCPP16Data = (struct OCPP16Data *)GetShmOCPP16Data();
  600. while (1) {
  601. if (IsConnectorWholeIdle() || (pSysInfo->PageIndex == _LCM_FIX) )
  602. CheckFwUpdateFunction();
  603. sleep(3);
  604. } //while
  605. return 0;
  606. }