Module_UpdateFW.c 23 KB

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