123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271 |
- #include <stdio.h> /*標準輸入輸出定義*/
- #include <stdlib.h> /*標準函數庫定義*/
- #include <string.h>
- #include <stdint.h>
- #include "../Config.h"
- #include "../Log/log.h"
- #include "../Define/define.h"
- #include "../ShareMemory/shmMem.h"
- //------------------------------------------------------------------------------
- int CheckUpdateProcess(void)
- {
- //bool isPass = true;
- uint8_t retSucc = 0;
- uint8_t retFail = 0;
- uint8_t index = 0;
- uint8_t target = 0;
- char *new_str = NULL;
- uint8_t *ptr = NULL;
- int fd = 0;
- int CanFd = 0;
- int uartFd = 0;
- unsigned int Type = 0;
- long int MaxLen = (48 * 1024 * 1024, ImageLen = 0);
- DIR *d;
- struct dirent *dir;
- struct SysConfigData *pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
- struct SysInfoData *pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
- d = opendir("/mnt/");
- if (d) {
- while ((dir = readdir(d)) != NULL) {
- if (strcmp(dir->d_name, ".") == 0 || strcmp(dir->d_name, "..") == 0) {
- continue;
- }
- new_str = calloc(strlen("/mnt/") + strlen(dir->d_name) + 1, sizeof(char));
- //new_str[0] = '\0';
- strcat(new_str, "/mnt/");
- strcat(new_str, dir->d_name);
- log_info("%s%s\r\n", "/mnt/", dir->d_name);
- fd = open(new_str, O_RDONLY);
- if (fd < 0) {
- return FAIL;
- }
- ptr = calloc(MaxLen, sizeof(char)); //-48 is take out the header
- //memset(ptr, 0xFF, MaxLen); //-48 is take out the header
- //get the image length
- ImageLen = read(fd, ptr, MaxLen);
- for (uint8_t i = 0; i < 16; i++) {
- if (pSysConfig->ModelName[i] != ptr[i]) {
- return FAIL;
- }
- }
- log_info("model name check pass. \n");
- if (ImageLen > 20) {
- Type = (((unsigned int)ptr[16]) << 24 |
- ((unsigned int)ptr[17]) << 16 |
- ((unsigned int)ptr[18]) << 8 |
- ((unsigned int)ptr[19]));
- log_info("Typed...%x \r\n", Type);
- switch (Type) {
- case 0x10000001:
- case 0x10000002:
- case 0x10000003:
- case 0x10000004:
- case 0x10000005:
- if (Upgrade_Flash(Type, new_str, (char *)pSysConfig->ModelName) == PASS) {
- //return PASS;
- retSucc++;
- } else {
- log_info("Upgrade %x Failed\r\n", Type);
- //return FAIL;
- retFail++;
- }
- break;
- case 0x10000007:
- case 0x10000008:
- case 0x10000009:
- case 0x1000000A:
- //isPass = true;
- CanFd = InitCanBus();
- if (CanFd > 0) {
- for (index = 0; index < pSysConfig->TotalConnectorCount; index++) {
- //if (!isPass) {
- // break;
- //}
- if (chargingInfo[index]->Type == _Type_CCS_2) {
- if (Upgrade_CCS(CanFd, Type, chargingInfo[index]->Evboard_id, new_str, (char *)pSysConfig->ModelName) == FAIL) {
- //isPass = false;
- log_info("Upgrade %x Failed\r\n", Type);
- retFail++;
- }
- }
- }
- } else {
- log_error("Upgrade CCS open CAN FD fail.\n");
- //isPass = false;
- return FAIL;
- }
- if (retFail != 0) {
- break;
- } else {
- retSucc++;
- }
- //return isPass;
- break;
- case 0x10000006:
- case 0x1000000D:
- case 0x1000000E:
- case 0x20000002:
- case 0x10000014:
- // CSU_PRIMARY_CONTROLLER : 0x10000006
- target = 0x00;
- if (Type == 0x10000006) {
- target = UPGRADE_PRI;
- } else if (Type == 0x1000000D) {
- target = UPGRADE_RB;
- } else if (Type == 0x1000000E) {
- target = UPGRADE_FAN;
- } else if (Type == 0x20000002) {
- target = UPGRADE_AC;
- } else if (Type == 0x10000014) {
- target = UPGRADE_LED;
- }
- uartFd = InitComPort(target);
- if (Upgrade_UART(uartFd, Type, target, new_str, (char *)pSysConfig->ModelName) == PASS) {
- //return PASS;
- retSucc++;
- } else {
- log_info("Upgrade %x Failed\r\n", Type);
- //return FAIL;
- return FAIL;
- }
- if (uartFd > 0) {
- close(uartFd);
- }
- break;
- case 0x1000000B:
- case 0x1000000C:
- // CHAdeMO_BOARD : 0x1000000B, GBT : 0x1000000C
- //bool isPass = true;
- CanFd = InitCanBus();
- if (CanFd > 0) {
- for (index = 0; index < pSysConfig->TotalConnectorCount; index++) {
- //if (!isPass) {
- // break;
- //}
- if ((Type == 0x1000000B && chargingInfo[index]->Type == _Type_Chademo) ||
- (Type == 0x1000000C && chargingInfo[index]->Type == _Type_GB)) {
- if (Upgrade_CAN(CanFd, Type, chargingInfo[index]->Evboard_id, new_str, (char *)pSysConfig->ModelName) == PASS) {
- //isPass = PASS;
- retSucc++;
- } else {
- log_info("Upgrade %x Failed\r\n", Type);
- //isPass = FAIL;
- retFail++;
- }
- }
- }
- } else {
- log_info("Upgrad FD fail. \n");
- //isPass = false;
- return FAIL;
- }
- //return isPass;
- break;
- }
- }
- free(new_str);
- free(ptr);
- }
- }
- free(dir);
- closedir(d);
- if (retFail != 0) {
- return FAIL;
- }
- return PASS;
- }
- void CheckFwUpdateFunction(void)
- {
- struct SysConfigData *pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
- struct SysInfoData *pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
- //log_info("pSysInfo->FirmwareUpdate = %d \n", pSysInfo->FirmwareUpdate);
- if (pSysInfo->FirmwareUpdate == YES) {
- log_info("ftp : update start. \n");
- for (uint8_t gun_index = 0; gun_index < pSysConfig->TotalConnectorCount; gun_index++) {
- setChargerMode(gun_index, MODE_UPDATE);
- }
- uint8_t updateResult = CheckUpdateProcess();
- if (updateResult == PASS) {
- log_info("ftp : update complete. \n");
- } else if (updateResult == MODELNAME_FAIL) {
- log_info("ftp : model name is none match. \n");
- KillAllTask();
- pSysInfo->FirmwareUpdate = NO;
- sleep(5);
- system("/usr/bin/run_evse_restart.sh");
- return;
- } else {
- log_info("ftp : update fail. \n");
- }
- pSysInfo->FirmwareUpdate = NO;
- sleep(5);
- system("reboot -f");
- } else if (ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq == YES) {
- ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = NO;
- if (strcmp((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "Downloaded") == EQUAL) {
- log_info("Backend : update start. \n");
- strcpy((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "");
- strcpy((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "Installing");
- ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = YES;
- KillTask();
- for (uint8_t _index = 0; _index < pSysConfig->TotalConnectorCount; _index++) {
- setChargerMode(_index, MODE_UPDATE);
- }
- for (uint8_t _index = 0; _index < pSysConfig->AcConnectorCount; _index++) {
- ac_chargingInfo[_index]->SystemStatus = MODE_UPDATE;
- }
- uint8_t updateResult = CheckUpdateProcess();
- if (updateResult == PASS) {
- log_info("Backend : update complete. \n");
- strcpy((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "Installed");
- } else if (updateResult == MODELNAME_FAIL) {
- log_info("Backend : model name is none match. \n");
- KillAllTask();
- strcpy((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "InstallationFailed");
- ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = YES;
- sleep(5);
- system("/usr/bin/run_evse_restart.sh");
- return;
- } else {
- log_info("Backend : update fail. \n");
- strcpy((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "InstallationFailed");
- }
- strcpy((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "Installed");
- ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = YES;
- sleep(5);
- system("reboot -f");
- }
- }
- }
|