|
@@ -400,7 +400,6 @@ static int qrCodeUrlInfoHandle(uint8_t *data)
|
|
|
//copy QR code string
|
|
|
if (strncmp((char *)localTime, (char *)&data[0], timeLen - 2) != 0) {
|
|
|
memset(ShmSysConfigAndInfo->SysConfig.SystemId, '\0', sizeof(ShmSysConfigAndInfo->SysConfig.SystemId));
|
|
|
- //strncpy(ShmSysConfigAndInfo->SysConfig.SystemId, '\0', sizeof(ShmSysConfigAndInfo->SysConfig.SystemId));
|
|
|
//printf("data = %s\r\n", data);
|
|
|
len = string2ByteArray((char *)data, (uint8_t *)ShmSysConfigAndInfo->SysConfig.SystemId);
|
|
|
//printf("SystemId = %s\r\n", ShmSysConfigAndInfo->SysConfig.SystemId);
|
|
@@ -427,6 +426,20 @@ static int qrCodeUrlInfoHandle(uint8_t *data)
|
|
|
|
|
|
static int updateFirmwareHandle(uint8_t *imgName)
|
|
|
{
|
|
|
+ int ret = PASS;
|
|
|
+ char cmdBuf[1024] = {0};
|
|
|
+
|
|
|
+ sprintf(cmdBuf, "/mnt/%s", imgName);
|
|
|
+ DEBUG_INFO("Program ready to check file %s\n", cmdBuf);
|
|
|
+ if ( access(cmdBuf, F_OK) != -1) {
|
|
|
+ DEBUG_INFO("File '%s' exist.\n", cmdBuf);
|
|
|
+ ShmSysConfigAndInfo->SysInfo.FirmwareUpdate = YES;
|
|
|
+ } else {
|
|
|
+ DEBUG_INFO("File '%s' doesn't exist.\n", cmdBuf);
|
|
|
+ ret = FAIL;
|
|
|
+ }
|
|
|
+
|
|
|
+#if 0
|
|
|
char cmdBuf[1024] = {0};
|
|
|
int status = 0;
|
|
|
|
|
@@ -457,8 +470,9 @@ static int updateFirmwareHandle(uint8_t *imgName)
|
|
|
}
|
|
|
|
|
|
system("rm -rf ./tftpUpdate.sh"); //刪除shell
|
|
|
+#endif //0
|
|
|
|
|
|
- return PASS;
|
|
|
+ return ret;
|
|
|
}
|
|
|
|
|
|
static int miscCommandHandle(uint8_t dataLen, uint8_t id, uint8_t *data)
|
|
@@ -613,6 +627,7 @@ static int miscCommandHandle(uint8_t dataLen, uint8_t id, uint8_t *data)
|
|
|
clearMiscCommand();
|
|
|
break;
|
|
|
}
|
|
|
+ usleep(128);
|
|
|
}
|
|
|
|
|
|
return ret;
|
|
@@ -620,10 +635,13 @@ static int miscCommandHandle(uint8_t dataLen, uint8_t id, uint8_t *data)
|
|
|
|
|
|
static int chargingcapabilityHandle(uint8_t *data, uint8_t gunID)
|
|
|
{
|
|
|
+ uint8_t addr = 0;
|
|
|
float MaxVolt, MaxCurrent, MaxPower;
|
|
|
+ static PricesInfo pricesInfo[2] = {0};
|
|
|
CapabilityInfo *pCapabilityInfo = NULL;
|
|
|
AccountInfo *pAccountInfo = NULL;
|
|
|
|
|
|
+ //--- charging capability information --------------------------------------
|
|
|
pCapabilityInfo = (CapabilityInfo *)&data[0];
|
|
|
|
|
|
MaxVolt = (float)(ntohs(pCapabilityInfo->OutputVoltage));
|
|
@@ -645,19 +663,27 @@ static int chargingcapabilityHandle(uint8_t *data, uint8_t gunID)
|
|
|
//MaxPower = (float)(data[4] << 8 | data[5]);
|
|
|
//printf("MaxVolt=%f, MaxCurrent=%f, MaxPower=%f,\n", MaxVolt, MaxCurrent, MaxPower);
|
|
|
|
|
|
- pAccountInfo = (AccountInfo *)&data[6];
|
|
|
+ //--- user prices information ----------------------------------------------
|
|
|
+ addr = (sizeof(CapabilityInfo) - 2); //2 byte reserved
|
|
|
+ pAccountInfo = (AccountInfo *)&data[addr];
|
|
|
|
|
|
ShmSysConfigAndInfo->SysConfig.BillingData.Currency = pAccountInfo->Currency;
|
|
|
- gAudiCustInfo->PricesInfo[gunID].UserPrices = transPricesUnit(ntohl(pAccountInfo->UserPrices));
|
|
|
- ChargingData[gunID]->ChargingFee = transPricesUnit(ntohl(pAccountInfo->TotalCost));
|
|
|
- gAudiCustInfo->PricesInfo[gunID].Balance = transPricesUnit(ntohl(pAccountInfo->Balance));
|
|
|
+ gAudiCustInfo->PricesInfo[gunID].UserPrices = transPricesUnit(ntohl(pAccountInfo->UserPrices));
|
|
|
+ ChargingData[gunID]->ChargingFee = transPricesUnit(ntohl(pAccountInfo->TotalCost));
|
|
|
+ gAudiCustInfo->PricesInfo[gunID].Balance = transPricesUnit(ntohl(pAccountInfo->Balance));
|
|
|
|
|
|
- DEBUG_INFO("id = %d, user prices = %.2f, Total cost = %.2f, Account balances = %.2f, currency = %s\r\n",
|
|
|
- gunID,
|
|
|
- gAudiCustInfo->PricesInfo[gunID].UserPrices,
|
|
|
- ChargingData[gunID]->ChargingFee,
|
|
|
- gAudiCustInfo->PricesInfo[gunID].Balance,
|
|
|
- (uint8_t *)Currency[ShmSysConfigAndInfo->SysConfig.BillingData.Currency]);
|
|
|
+ if ((pricesInfo[gunID].UserPrices != gAudiCustInfo->PricesInfo[gunID].UserPrices) ||
|
|
|
+ (pricesInfo[gunID].Balance != gAudiCustInfo->PricesInfo[gunID].Balance)) {
|
|
|
+ pricesInfo[gunID].UserPrices = gAudiCustInfo->PricesInfo[gunID].UserPrices;
|
|
|
+ pricesInfo[gunID].Balance = gAudiCustInfo->PricesInfo[gunID].Balance;
|
|
|
+
|
|
|
+ DEBUG_INFO("id = %d, user prices = %.2f, Total cost = %.2f, Account balances = %.2f, currency = %s\r\n",
|
|
|
+ gunID,
|
|
|
+ gAudiCustInfo->PricesInfo[gunID].UserPrices,
|
|
|
+ ChargingData[gunID]->ChargingFee,
|
|
|
+ gAudiCustInfo->PricesInfo[gunID].Balance,
|
|
|
+ (uint8_t *)Currency[ShmSysConfigAndInfo->SysConfig.BillingData.Currency]);
|
|
|
+ }
|
|
|
|
|
|
return PASS;
|
|
|
}
|
|
@@ -684,6 +710,7 @@ static void removeFaultCodeToBuf(uint8_t *Code)
|
|
|
|
|
|
// 把相關的錯誤碼一次移除,避免重複顯示
|
|
|
while (find) {
|
|
|
+ usleep(128);
|
|
|
find = 0x00;
|
|
|
for (i = 0; i < ShmSysConfigAndInfo->SysWarningInfo.WarningCount; i++) {
|
|
|
if (find == 0x00) {
|
|
@@ -714,6 +741,7 @@ static int powerCabinetStatusProcess(uint8_t dataLen, uint8_t *data)
|
|
|
DEBUG_ERROR("raw data len < 6 = %d\r\n", dataLen);
|
|
|
if (ShmSysConfigAndInfo->SysWarningInfo.WarningCount > 0) {
|
|
|
for (i = 0; i < ShmSysConfigAndInfo->SysWarningInfo.WarningCount; i++) {
|
|
|
+ usleep(128);
|
|
|
if (ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][1] >= 0x33) { //from backend or power cabinet
|
|
|
memset(EventCodeTmp, 0, sizeof(EventCodeTmp));
|
|
|
memcpy(EventCodeTmp,
|
|
@@ -727,6 +755,7 @@ static int powerCabinetStatusProcess(uint8_t dataLen, uint8_t *data)
|
|
|
}
|
|
|
|
|
|
for (count = 0; count < dataLen; count += WARNING_CODE_SIZE) {
|
|
|
+ usleep(128);
|
|
|
// misc command status code handle
|
|
|
if (strcmp((char *)&data[count], MISC_ST_MISC_CMD) == 0) {
|
|
|
if (gDoCommGblData.MiscCmd != REG_MISC_CONTROL) {
|
|
@@ -745,7 +774,7 @@ static int powerCabinetStatusProcess(uint8_t dataLen, uint8_t *data)
|
|
|
strncpy((char *)&StatusArray[count / WARNING_CODE_SIZE], (char *)&data[count], WARNING_CODE_SIZE);
|
|
|
ret = 0;
|
|
|
for (i = 0; i < ShmSysConfigAndInfo->SysWarningInfo.WarningCount; i++) {
|
|
|
-
|
|
|
+ usleep(128);
|
|
|
if (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0],
|
|
|
StatusArray[count / WARNING_CODE_SIZE],
|
|
|
WARNING_CODE_SIZE) == 0) {
|
|
@@ -761,10 +790,12 @@ static int powerCabinetStatusProcess(uint8_t dataLen, uint8_t *data)
|
|
|
}
|
|
|
|
|
|
for (i = 0; i < ShmSysConfigAndInfo->SysWarningInfo.WarningCount; i++) {
|
|
|
+ usleep(128);
|
|
|
if (ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][1] >= '3') { //from backend or power cabinet 0x33
|
|
|
ret = 0;
|
|
|
|
|
|
for (count = 0; count < (dataLen / WARNING_CODE_SIZE); count++) {
|
|
|
+ usleep(128);
|
|
|
if (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0],
|
|
|
StatusArray[count],
|
|
|
WARNING_CODE_SIZE) == 0) {
|
|
@@ -837,12 +868,15 @@ static int responsePackeHandle(int fd, uint8_t *pResult, uint8_t id, uint8_t reg
|
|
|
case REG_SOFTWARE_UPDATE:
|
|
|
pSoftwareUpd = (SoftwareUpdInfo *)&pCsuResult->Data.Data[0];
|
|
|
|
|
|
- if ((pSoftwareUpd->ImgName == NULL) || (rawDataLen == 0)) {
|
|
|
+ if ((strcmp((char *)pSoftwareUpd->ImgName, "") == 0) ||
|
|
|
+ (rawDataLen == 0) ||
|
|
|
+ pSoftwareUpd->UpdateState != 1) {
|
|
|
ret = FAIL;
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
- updateFirmwareHandle(pSoftwareUpd->ImgName);
|
|
|
+ ret = FAIL;
|
|
|
+ ret = updateFirmwareHandle(pSoftwareUpd->ImgName);
|
|
|
break;
|
|
|
|
|
|
case REG_PLUG_IN_STATE:
|
|
@@ -970,7 +1004,7 @@ static int writeWaitPlugItState(int fd, uint8_t id)
|
|
|
return ret;
|
|
|
}
|
|
|
|
|
|
-static int readPowerCabinetSystemID(int fd)
|
|
|
+static int readQRcodeURLAndSystemDate(int fd)
|
|
|
{
|
|
|
int ret = PASS;
|
|
|
|
|
@@ -1149,13 +1183,14 @@ static int writePlugInStatus(int fd, uint8_t plugNum, uint8_t id)
|
|
|
static int readSoftwareUpdate(int fd)
|
|
|
{
|
|
|
int ret = PASS;
|
|
|
+ uint8_t dataBuf[2] = {ShmSysConfigAndInfo->SysInfo.FirmwareUpdate, 0};
|
|
|
|
|
|
ret = composeSocketData(fd,
|
|
|
- ID_REGISTER,
|
|
|
+ 0x01,
|
|
|
OP_READ_DATA,
|
|
|
REG_SOFTWARE_UPDATE,
|
|
|
- 0,
|
|
|
- NULL);
|
|
|
+ 1,
|
|
|
+ &dataBuf[0]);
|
|
|
|
|
|
return ret;
|
|
|
}
|
|
@@ -1401,6 +1436,46 @@ static int InitShareMemory(void)
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
+static void updateFirmwareProcess(int fd, uint8_t totalConnCount)
|
|
|
+{
|
|
|
+ bool canUpdateFirmware = true;
|
|
|
+ uint8_t plugNum = 0;
|
|
|
+ uint8_t ackCount = 5;
|
|
|
+ struct timeb updateTime;
|
|
|
+
|
|
|
+ if (ShmSysConfigAndInfo->SysWarningInfo.Level != 2) {
|
|
|
+ for (plugNum = 0; plugNum < totalConnCount; plugNum++) {
|
|
|
+ if (ChargingData[plugNum]->SystemStatus != S_IDLE &&
|
|
|
+ ChargingData[plugNum]->SystemStatus != S_RESERVATION &&
|
|
|
+ ChargingData[plugNum]->SystemStatus != S_MAINTAIN) {
|
|
|
+ canUpdateFirmware = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (canUpdateFirmware) {
|
|
|
+ ftime(&updateTime);
|
|
|
+ if (DiffTimeb(gRegTimeUp[0][REG_SOFTWARE_UPDATE], updateTime) > LOOP_RETRY_TIME * 5) {
|
|
|
+ readSoftwareUpdate(fd);
|
|
|
+ ftime(&gRegTimeUp[0][REG_SOFTWARE_UPDATE]);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (ShmSysConfigAndInfo->SysInfo.FirmwareUpdate == YES) {
|
|
|
+ while (ackCount != 0) {
|
|
|
+ ftime(&updateTime);
|
|
|
+ if (DiffTimeb(gRegTimeUp[0][REG_SOFTWARE_UPDATE], updateTime) > LOOP_RETRY_TIME / 2) {
|
|
|
+ readSoftwareUpdate(fd);
|
|
|
+ ftime(&gRegTimeUp[0][REG_SOFTWARE_UPDATE]);
|
|
|
+ if (ShmSysConfigAndInfo->SysInfo.FirmwareUpdate == NO) {
|
|
|
+ ackCount--;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ usleep(128);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
static void checkAuthorProcess(int fd, uint8_t plugNum)
|
|
|
{
|
|
|
int ret = 0;
|
|
@@ -1446,6 +1521,7 @@ static int messageTrigger(int fd, uint8_t plugNum, uint8_t gunID, uint8_t curReg
|
|
|
struct timeb NowTime;
|
|
|
|
|
|
while (isContinue) {
|
|
|
+ usleep(128);
|
|
|
ftime(&NowTime);
|
|
|
|
|
|
switch (curReg) {
|
|
@@ -1488,11 +1564,20 @@ static int messageTrigger(int fd, uint8_t plugNum, uint8_t gunID, uint8_t curReg
|
|
|
// break;
|
|
|
|
|
|
//case REG_SOFTWARE_UPDATE:
|
|
|
- // if (DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) > LOOP_RETRY_TIME) {
|
|
|
- // readSoftwareUpdate(fd);
|
|
|
- // ftime(&gRegTimeUp[plugNum][curReg]);
|
|
|
+ // if (ChargingData[plugNum]->SystemStatus == S_IDLE) {
|
|
|
+ // if (DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) > LOOP_RETRY_TIME * 10) {
|
|
|
+ // readSoftwareUpdate(fd);
|
|
|
+ // ftime(&gRegTimeUp[plugNum][curReg]);
|
|
|
+ // }
|
|
|
+ // while (ShmSysConfigAndInfo->SysInfo.FirmwareUpdate == YES) {
|
|
|
+ // ftime(&NowTime);
|
|
|
+ // if (DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) > LOOP_RETRY_TIME) {
|
|
|
+ // readSoftwareUpdate(fd);
|
|
|
+ // }
|
|
|
+ // usleep(128);
|
|
|
+ // }
|
|
|
// }
|
|
|
- // curReg = REG_PLUG_IN_STATE;
|
|
|
+ // isContinue = 0;
|
|
|
// break;
|
|
|
|
|
|
case REG_PLUG_IN_STATE:
|
|
@@ -1541,7 +1626,7 @@ static int messageTrigger(int fd, uint8_t plugNum, uint8_t gunID, uint8_t curReg
|
|
|
//power up write dispenser version and get power cabinet system ID
|
|
|
if ((writeCsuModuleVersion(fd) == PASS) &&
|
|
|
(writeOtherModuleVersion(fd) == PASS) &&
|
|
|
- (readPowerCabinetSystemID(fd) == PASS)) {
|
|
|
+ (readQRcodeURLAndSystemDate(fd) == PASS)) {
|
|
|
//gDoCommGblData.DisConnCount = 0;
|
|
|
isContinue = 0;
|
|
|
}
|
|
@@ -1554,12 +1639,12 @@ static int messageTrigger(int fd, uint8_t plugNum, uint8_t gunID, uint8_t curReg
|
|
|
case REG_QRCODE_URL_INFO:
|
|
|
if (gunID == 1) {
|
|
|
if (DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) > (LOOP_RETRY_TIME * 10)) {
|
|
|
- readPowerCabinetSystemID(fd);
|
|
|
+ readQRcodeURLAndSystemDate(fd);
|
|
|
ftime(&gRegTimeUp[plugNum][curReg]);
|
|
|
}
|
|
|
}
|
|
|
isContinue = 0;
|
|
|
- //curReg = REG_WAIT_PLUG_IT_STATE;
|
|
|
+ //curReg = REG_SOFTWARE_UPDATE;
|
|
|
break;
|
|
|
|
|
|
//case REG_WAIT_PLUG_IT_STATE:
|
|
@@ -1621,15 +1706,6 @@ static void systemStatusProcess(int fd, uint8_t plugNum, uint8_t gunID)
|
|
|
ftime(&gRegTimeUp[plugNum][REG_CHARGING_CAP]);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- //check update firmware
|
|
|
- //if (ChargingData[plugNum]->SystemStatus == S_IDLE) {
|
|
|
- // ftime(&AuthNowTime);
|
|
|
- // if (DiffTimeb(gRegTimeUp[plugNum][REG_SOFTWARE_UPDATE], AuthNowTime) > LOOP_RETRY_TIME) {
|
|
|
- // readSoftwareUpdate(fd);
|
|
|
- // ftime(&gRegTimeUp[plugNum][REG_SOFTWARE_UPDATE]);
|
|
|
- // }
|
|
|
- //}
|
|
|
break;
|
|
|
|
|
|
case S_PREPARNING: //get permission
|
|
@@ -1845,10 +1921,12 @@ int main(int argc, char *argv[])
|
|
|
gunID = (plugNum + 1); //connector Id, 1 = left gun, 2 = right gun
|
|
|
systemStatusProcess(fd, plugNum, gunID);
|
|
|
|
|
|
- if ((initDone = messageTrigger(fd,
|
|
|
- plugNum,
|
|
|
- gunID,
|
|
|
- REG_POWER_CABINET_STATUS)) == DISPENSER_SOCKET_RECONN) {
|
|
|
+ initDone = messageTrigger(fd,
|
|
|
+ plugNum,
|
|
|
+ gunID,
|
|
|
+ REG_POWER_CABINET_STATUS);
|
|
|
+
|
|
|
+ if (initDone == DISPENSER_SOCKET_RECONN) {
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
@@ -1866,6 +1944,12 @@ int main(int argc, char *argv[])
|
|
|
|
|
|
initDone = DISPENER_INIT_FAIL;
|
|
|
}
|
|
|
+
|
|
|
+ //update dispenser firmware
|
|
|
+ if (initDone != DISPENER_INIT_FAIL) {
|
|
|
+ updateFirmwareProcess(fd, totalConnCount);
|
|
|
+ }
|
|
|
+
|
|
|
usleep(1000);
|
|
|
}
|
|
|
}
|