|
@@ -25,6 +25,7 @@
|
|
|
#include "Config.h"
|
|
|
#include "ReDoComm.h"
|
|
|
#include "AudiCust.h"
|
|
|
+#include "timeout.h"
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
#define DEBUG_INFO(format, args...) StoreLogMsg("[%s:%d][%s][Info] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
|
|
@@ -43,7 +44,7 @@ static struct OCPP16Data *ShmOCPP16Data;
|
|
|
static struct PrimaryMcuData *ShmPrimaryMcuData;
|
|
|
static struct ChargingInfoData *ChargingData[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
|
|
|
static struct timeb gRegTimeUp[2][MAX_REGISTER_NUM] = {0};
|
|
|
-static struct WARNING_CODE_INFO PreSysWarningInfo = {0};
|
|
|
+static struct WARNING_CODE_INFO gPreSysWarningInfo = {0};
|
|
|
static AudiCustInfo *gAudiCustInfo = NULL;
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
@@ -151,7 +152,7 @@ static void Hexdump(const void *p, size_t size)
|
|
|
|
|
|
message_len += sprintf(&message[message_len], "\r\n");
|
|
|
|
|
|
- printf("%s", message);
|
|
|
+ DEBUG_INFO("%s", message);
|
|
|
}
|
|
|
|
|
|
static int string2ByteArray(char *input, byte *output)
|
|
@@ -295,36 +296,67 @@ static int doCommConnToServer(void)
|
|
|
}
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
-//--- DoComm function ---
|
|
|
+//--- Audi select gun ---
|
|
|
//------------------------------------------------------------------------------
|
|
|
-static int compareOpcode(uint8_t opCode)
|
|
|
+static void clearPricesInfo(uint8_t id)
|
|
|
{
|
|
|
- if (opCode != OP_WAIT_RESPONSE) {
|
|
|
- //DEBUG_ERROR("response operative code fail\r\n");
|
|
|
- return FAIL;
|
|
|
- }
|
|
|
+ memset(&gAudiCustInfo->PricesInfo[id], 0, sizeof(PricesInfo));
|
|
|
+ gAudiCustInfo->PricesInfo[id].Balance = FAIL_BALANCE_PRICES;
|
|
|
+}
|
|
|
|
|
|
- return PASS;
|
|
|
+static void ClearAuthorizedFlag(void)
|
|
|
+{
|
|
|
+ ShmOCPP16Data->SpMsg.bits.AuthorizeConf = NO;
|
|
|
+ ShmSysConfigAndInfo->SysInfo.AuthorizeFlag = NO;
|
|
|
}
|
|
|
|
|
|
-static int compareResult(uint8_t result)
|
|
|
+static void ClearDetectPluginFlag(void)
|
|
|
{
|
|
|
- if (result != COMMAND_RESULT_OK) {
|
|
|
- //DEBUG_ERROR("response result fail\r\n");
|
|
|
- return FAIL;
|
|
|
+ ShmSysConfigAndInfo->SysInfo.WaitForPlugit = NO;
|
|
|
+}
|
|
|
+
|
|
|
+static bool isDetectPlugin(void)
|
|
|
+{
|
|
|
+ if (ShmSysConfigAndInfo->SysInfo.WaitForPlugit == YES) {
|
|
|
+ return YES;
|
|
|
}
|
|
|
|
|
|
- return PASS;
|
|
|
+ return NO;
|
|
|
}
|
|
|
|
|
|
-static int compareRegister(uint8_t srcReg, uint8_t destReg)
|
|
|
+static void destroySelectGun(uint8_t curGun)
|
|
|
{
|
|
|
- if (srcReg != destReg) {
|
|
|
- //DEBUG_ERROR("response register fail\r\n");
|
|
|
- return FAIL;
|
|
|
+ uint8_t i = 0;
|
|
|
+ uint8_t totalGun = ShmSysConfigAndInfo->SysConfig.TotalConnectorCount;
|
|
|
+
|
|
|
+ if (curGun == DESTROY_ALL_SEL) {
|
|
|
+ gAudiCustInfo->SelGunInfo.RightGun = SEL_GUN_RELEASE;
|
|
|
+ gAudiCustInfo->SelGunInfo.LeftGun = SEL_GUN_RELEASE;
|
|
|
+
|
|
|
+ for (i = 0; i < totalGun; i++) {
|
|
|
+ ChargingData[i]->TimeoutFlag = Timeout_None;
|
|
|
+ clearPricesInfo(i);
|
|
|
+ }
|
|
|
+ ShmSysConfigAndInfo->SysInfo.CurGunSelected = 0;
|
|
|
+ strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
|
|
|
}
|
|
|
|
|
|
- return PASS;
|
|
|
+ //for charging timeout or complete
|
|
|
+ if ((curGun == LEFT_GUN_NUM) && (gAudiCustInfo->SelGunInfo.LeftGun != SEL_GUN_RELEASE)) {
|
|
|
+ gAudiCustInfo->SelGunInfo.LeftGun = SEL_GUN_RELEASE;
|
|
|
+ if (ShmOCPP16Data->SpMsg.bits.AuthorizeConf != NO) {
|
|
|
+ ClearAuthorizedFlag();
|
|
|
+ }
|
|
|
+ clearPricesInfo(curGun);
|
|
|
+ }
|
|
|
+
|
|
|
+ if ((curGun == RIGHT_GUN_NUM) && (gAudiCustInfo->SelGunInfo.RightGun != SEL_GUN_RELEASE)) {
|
|
|
+ if (ShmOCPP16Data->SpMsg.bits.AuthorizeConf != NO) {
|
|
|
+ ClearAuthorizedFlag();
|
|
|
+ }
|
|
|
+
|
|
|
+ clearPricesInfo(curGun);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
static int getConfirmSelectedGun(uint8_t curSel)
|
|
@@ -354,11 +386,44 @@ static void setConfirmSelGun(uint8_t selGun)
|
|
|
{
|
|
|
if (selGun == LEFT_GUN_NUM && gAudiCustInfo->SelGunInfo.LeftGun == SEL_GUN_RELEASE) {
|
|
|
gAudiCustInfo->SelGunInfo.LeftGun = SEL_GUN_CONFIRM;
|
|
|
- printf("confirmSelGun left\r\n");
|
|
|
+ //printf("confirmSelGun left\r\n");
|
|
|
} else if (selGun == RIGHT_GUN_NUM && gAudiCustInfo->SelGunInfo.RightGun == SEL_GUN_RELEASE) {
|
|
|
gAudiCustInfo->SelGunInfo.RightGun = SEL_GUN_CONFIRM;
|
|
|
- printf("confirmSelGun right\r\n");
|
|
|
+ //printf("confirmSelGun right\r\n");
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+//------------------------------------------------------------------------------
|
|
|
+//--- DoComm function ---
|
|
|
+//------------------------------------------------------------------------------
|
|
|
+static int compareOpcode(uint8_t opCode)
|
|
|
+{
|
|
|
+ if (opCode != OP_WAIT_RESPONSE) {
|
|
|
+ //DEBUG_ERROR("response operative code fail\r\n");
|
|
|
+ return FAIL;
|
|
|
+ }
|
|
|
+
|
|
|
+ return PASS;
|
|
|
+}
|
|
|
+
|
|
|
+static int compareResult(uint8_t result)
|
|
|
+{
|
|
|
+ if (result != COMMAND_RESULT_OK) {
|
|
|
+ //DEBUG_ERROR("response result fail\r\n");
|
|
|
+ return FAIL;
|
|
|
}
|
|
|
+
|
|
|
+ return PASS;
|
|
|
+}
|
|
|
+
|
|
|
+static int compareRegister(uint8_t srcReg, uint8_t destReg)
|
|
|
+{
|
|
|
+ if (srcReg != destReg) {
|
|
|
+ //DEBUG_ERROR("response register fail\r\n");
|
|
|
+ return FAIL;
|
|
|
+ }
|
|
|
+
|
|
|
+ return PASS;
|
|
|
}
|
|
|
|
|
|
static float transPricesUnit(int prices)
|
|
@@ -375,7 +440,7 @@ static void clearMiscCommand(void)
|
|
|
static int qrCodeUrlInfoHandle(uint8_t *data)
|
|
|
{
|
|
|
int len = 0;
|
|
|
- char cmdBuf[128] = {0};
|
|
|
+ //char cmdBuf[128] = {0};
|
|
|
char localTime[128] = {0};
|
|
|
uint16_t timeLen = 0;
|
|
|
struct timeb SeqEndTime;
|
|
@@ -400,7 +465,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 +491,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 +535,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)
|
|
@@ -585,27 +664,88 @@ static int miscCommandHandle(uint8_t dataLen, uint8_t id, uint8_t *data)
|
|
|
}
|
|
|
DEBUG_INFO("Remote start charging id = %d\r\n", id);
|
|
|
|
|
|
- if (getConfirmSelectedGun(id - 1) == FAIL) {
|
|
|
- DEBUG_INFO("Remote start not select gun\r\n");
|
|
|
+ //if (getConfirmSelectedGun(id - 1) == FAIL) {
|
|
|
+ // DEBUG_INFO("Remote start not select gun\r\n");
|
|
|
+ // break;
|
|
|
+ //}
|
|
|
+
|
|
|
+ if (getSelGunWaitToAuthor(id - 1) == FAIL) {
|
|
|
+ DEBUG_ERROR("Remote start gun already charging\r\n");
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
- //if (getSelGunWaitToAuthor(id - 1) == FAIL) {
|
|
|
- // DEBUG_ERROR("Remote start gun already charging\r\n");
|
|
|
- // break;
|
|
|
- //}
|
|
|
+ if (ShmSysConfigAndInfo->SysInfo.CurGunSelected != (id - 1)) {
|
|
|
+ if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == LEFT_GUN_NUM &&
|
|
|
+ (gAudiCustInfo->SelGunInfo.LeftGun == SEL_GUN_CONFIRM ||
|
|
|
+ gAudiCustInfo->SelGunInfo.LeftGun == SEL_GUN_ATHOR)) {
|
|
|
+ gAudiCustInfo->SelGunInfo.LeftGun = SEL_GUN_RELEASE;
|
|
|
+ strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
|
|
|
+ ShmSysConfigAndInfo->SysInfo.WaitForPlugit = NO;
|
|
|
+ sleep(1); //Jerry add
|
|
|
+ ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_SELECT_GUN;
|
|
|
+ gettimeofday(&ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer, NULL);
|
|
|
+ ShmSysConfigAndInfo->SysInfo.SystemTimeoutFlag = Timeout_None;
|
|
|
+ }
|
|
|
|
|
|
- //if (ShmSysConfigAndInfo->SysInfo.CurGunSelected != (id - 1)) {
|
|
|
- // ShmSysConfigAndInfo->SysInfo.CurGunSelected = (id - 1);
|
|
|
- // ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc = NO_DEFINE;
|
|
|
- //}
|
|
|
+ if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == RIGHT_GUN_NUM &&
|
|
|
+ (gAudiCustInfo->SelGunInfo.RightGun == SEL_GUN_CONFIRM ||
|
|
|
+ gAudiCustInfo->SelGunInfo.RightGun == SEL_GUN_ATHOR)) {
|
|
|
+ gAudiCustInfo->SelGunInfo.RightGun = SEL_GUN_RELEASE;
|
|
|
+ strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
|
|
|
+ ShmSysConfigAndInfo->SysInfo.WaitForPlugit = NO;
|
|
|
+ sleep(1); //Jerry add
|
|
|
+ ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_SELECT_GUN;
|
|
|
+ gettimeofday(&ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer, NULL);
|
|
|
+ ShmSysConfigAndInfo->SysInfo.SystemTimeoutFlag = Timeout_None;
|
|
|
+ }
|
|
|
+
|
|
|
+ ShmSysConfigAndInfo->SysInfo.CurGunSelected = (id - 1);
|
|
|
+ ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc = NO_DEFINE;
|
|
|
+ }
|
|
|
|
|
|
- //setConfirmSelGun(ShmSysConfigAndInfo->SysInfo.CurGunSelected);
|
|
|
+ setConfirmSelGun(ShmSysConfigAndInfo->SysInfo.CurGunSelected);
|
|
|
|
|
|
ShmOCPP16Data->CsMsg.bits[id - 1].RemoteStartTransactionReq = YES;
|
|
|
gAudiCustInfo->PricesInfo[id - 1].Balance = 0.00;
|
|
|
- if (id == 2) {
|
|
|
- clearMiscCommand();
|
|
|
+ clearMiscCommand();
|
|
|
+ break;
|
|
|
+
|
|
|
+ case MISC_CMD_REMOTE_STOP_CHARGING:
|
|
|
+ if (value != YES) {
|
|
|
+ if (id == 2) {
|
|
|
+ clearMiscCommand();
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
|
|
|
+ ShmSysConfigAndInfo->SysInfo.WaitForPlugit = NO;
|
|
|
+ ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_SELECT_GUN;
|
|
|
+ gettimeofday(&ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer, NULL);
|
|
|
+ ShmSysConfigAndInfo->SysInfo.SystemTimeoutFlag = Timeout_None;
|
|
|
+ destroySelectGun(id - 1);
|
|
|
+
|
|
|
+ clearMiscCommand();
|
|
|
+ break;
|
|
|
+
|
|
|
+ case MISC_CMD_REMOTE_UNLOCK:
|
|
|
+ if (value != YES) {
|
|
|
+ if (id == 2) {
|
|
|
+ clearMiscCommand();
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (isDetectPlugin() == YES) {
|
|
|
+ ClearDetectPluginFlag();
|
|
|
+ strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
|
|
|
+ ShmSysConfigAndInfo->SysInfo.WaitForPlugit = NO;
|
|
|
+ ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_SELECT_GUN;
|
|
|
+ gettimeofday(&ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer, NULL);
|
|
|
+ ShmSysConfigAndInfo->SysInfo.SystemTimeoutFlag = Timeout_None;
|
|
|
+ destroySelectGun(id - 1);
|
|
|
+ } else {
|
|
|
+ ChargingData[id - 1]->StopChargeFlag = YES;
|
|
|
}
|
|
|
break;
|
|
|
|
|
@@ -613,6 +753,7 @@ static int miscCommandHandle(uint8_t dataLen, uint8_t id, uint8_t *data)
|
|
|
clearMiscCommand();
|
|
|
break;
|
|
|
}
|
|
|
+ usleep(128);
|
|
|
}
|
|
|
|
|
|
return ret;
|
|
@@ -620,24 +761,36 @@ 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));
|
|
|
- if ((MaxVolt >= 0) && (MaxVolt <= MAX_VOLTAGE)) {
|
|
|
+ if (MaxVolt >= 0) {
|
|
|
+ if (MaxVolt > MAX_VOLTAGE) {
|
|
|
+ MaxVolt = MAX_VOLTAGE;
|
|
|
+ }
|
|
|
ChargingData[gunID]->MaximumChargingVoltage = MaxVolt;
|
|
|
}
|
|
|
|
|
|
MaxCurrent = (float)(ntohs(pCapabilityInfo->OutputCurrent));
|
|
|
- if ((MaxCurrent >= 0) && (MaxCurrent <= MAX_CURRENCY)) {
|
|
|
+ if (MaxCurrent >= 0) {
|
|
|
+ if (MaxCurrent > MAX_CURRENCY) {
|
|
|
+ MaxCurrent = MAX_CURRENCY;
|
|
|
+ }
|
|
|
ChargingData[gunID]->AvailableChargingCurrent = MaxCurrent;
|
|
|
}
|
|
|
|
|
|
MaxPower = (float)(ntohs(pCapabilityInfo->OutputPower));
|
|
|
- if ((MaxPower >= 0) && (MaxPower <= MAX_POWER)) {
|
|
|
+ if (MaxPower >= 0) {
|
|
|
+ if (MaxPower > MAX_POWER) {
|
|
|
+ MaxPower = MAX_POWER;
|
|
|
+ }
|
|
|
ChargingData[gunID]->AvailableChargingPower = MaxPower;
|
|
|
}
|
|
|
//MaxVolt = (float)(data[0] << 8 |data[1]);
|
|
@@ -645,19 +798,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,8 +845,10 @@ static void removeFaultCodeToBuf(uint8_t *Code)
|
|
|
|
|
|
// 把相關的錯誤碼一次移除,避免重複顯示
|
|
|
while (find) {
|
|
|
+ usleep(128);
|
|
|
find = 0x00;
|
|
|
for (i = 0; i < ShmSysConfigAndInfo->SysWarningInfo.WarningCount; i++) {
|
|
|
+ usleep(128);
|
|
|
if (find == 0x00) {
|
|
|
if (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], _code, 7) == 0) {
|
|
|
find = 0x01;
|
|
@@ -702,6 +865,20 @@ static void removeFaultCodeToBuf(uint8_t *Code)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+bool CompareArrayIsZero(uint8_t *array, unsigned int array_size)
|
|
|
+{
|
|
|
+ uint8_t i;
|
|
|
+
|
|
|
+ if (array != NULL) {
|
|
|
+ for (i = 0; i < array_size; i++) {
|
|
|
+ if (array[i] != 0) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return true;
|
|
|
+}
|
|
|
static int powerCabinetStatusProcess(uint8_t dataLen, uint8_t *data)
|
|
|
{
|
|
|
uint8_t ret = 0;
|
|
@@ -709,12 +886,22 @@ static int powerCabinetStatusProcess(uint8_t dataLen, uint8_t *data)
|
|
|
uint8_t count = 0;
|
|
|
uint8_t EventCodeTmp[7] = {0};
|
|
|
uint8_t StatusArray[MAX_REGISTER_NUM][WARNING_CODE_SIZE] = {0};
|
|
|
+ uint8_t remaindLen = dataLen % dataLen;
|
|
|
+ uint8_t statusCodeError = 0;
|
|
|
+
|
|
|
+ if (remaindLen != 0) {
|
|
|
+ dataLen -= remaindLen;
|
|
|
+ }
|
|
|
|
|
|
if (dataLen < WARNING_CODE_SIZE) {
|
|
|
- DEBUG_ERROR("raw data len < 6 = %d\r\n", dataLen);
|
|
|
+ DEBUG_ERROR("fail status code length = %d\r\n", dataLen);
|
|
|
+ Hexdump(data, dataLen);
|
|
|
if (ShmSysConfigAndInfo->SysWarningInfo.WarningCount > 0) {
|
|
|
for (i = 0; i < ShmSysConfigAndInfo->SysWarningInfo.WarningCount; i++) {
|
|
|
- if (ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][1] >= 0x33) { //from backend or power cabinet
|
|
|
+ usleep(128);
|
|
|
+ if (ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][1] >= '3' || //from backend or power cabinet
|
|
|
+ (ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0] >= 'B' &&
|
|
|
+ ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][1] >= '4')) {
|
|
|
memset(EventCodeTmp, 0, sizeof(EventCodeTmp));
|
|
|
memcpy(EventCodeTmp,
|
|
|
ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i],
|
|
@@ -727,25 +914,34 @@ 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) {
|
|
|
- gDoCommGblData.MiscCmd = REG_MISC_CONTROL;
|
|
|
- }
|
|
|
+ if (strncmp((char *)&data[count], MISC_ST_MISC_CMD, WARNING_CODE_SIZE) == 0) {
|
|
|
+ //if (gDoCommGblData.MiscCmd != REG_MISC_CONTROL) {
|
|
|
+ gDoCommGblData.MiscCmd = REG_MISC_CONTROL;
|
|
|
+ //}
|
|
|
memset((char *)&data[count], 0, WARNING_CODE_SIZE);
|
|
|
continue;
|
|
|
- } else if (strcmp((char *)&data[count], MISC_ST_VERSION) == 0) {
|
|
|
- if (gDoCommGblData.MiscCmd != REG_REPORT_CSU_VERSION) {
|
|
|
- gDoCommGblData.MiscCmd = REG_REPORT_CSU_VERSION;
|
|
|
- }
|
|
|
+ } else if (strncmp((char *)&data[count], MISC_ST_VERSION, WARNING_CODE_SIZE) == 0) {
|
|
|
+ //if (gDoCommGblData.MiscCmd != REG_REPORT_CSU_VERSION) {
|
|
|
+ gDoCommGblData.MiscCmd = REG_REPORT_CSU_VERSION;
|
|
|
+ //}
|
|
|
memset((char *)&data[count], 0, WARNING_CODE_SIZE);
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
+ if (CompareArrayIsZero((uint8_t *)&data[count], WARNING_CODE_SIZE) == true) {
|
|
|
+ memset(EventCodeTmp, 0, sizeof(EventCodeTmp));
|
|
|
+ memcpy(EventCodeTmp, (char *)&data[count], sizeof(EventCodeTmp));
|
|
|
+ DEBUG_ERROR("error status = %s\r\n", EventCodeTmp);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
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 +957,23 @@ static int powerCabinetStatusProcess(uint8_t dataLen, uint8_t *data)
|
|
|
}
|
|
|
|
|
|
for (i = 0; i < ShmSysConfigAndInfo->SysWarningInfo.WarningCount; i++) {
|
|
|
- if (ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][1] >= '3') { //from backend or power cabinet 0x33
|
|
|
+ usleep(128);
|
|
|
+ //if (ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0] >= 'B' &&
|
|
|
+ // ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][1] >= '4') {
|
|
|
+ // memset(EventCodeTmp, 0, sizeof(EventCodeTmp));
|
|
|
+ // memcpy(EventCodeTmp,
|
|
|
+ // ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i],
|
|
|
+ // sizeof(EventCodeTmp));
|
|
|
+ // removeFaultCodeToBuf(EventCodeTmp);
|
|
|
+ //}
|
|
|
+
|
|
|
+ if (ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][1] >= '3' || //from backend or power cabinet 0x33
|
|
|
+ (ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0] >= 'B' &&
|
|
|
+ ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][1] >= '4')) {
|
|
|
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) {
|
|
@@ -821,8 +1030,8 @@ static int responsePackeHandle(int fd, uint8_t *pResult, uint8_t id, uint8_t reg
|
|
|
break;
|
|
|
|
|
|
case REG_DISPENSER_STATUS:
|
|
|
- memset(&PreSysWarningInfo, 0, sizeof(struct WARNING_CODE_INFO));
|
|
|
- memcpy(&PreSysWarningInfo,
|
|
|
+ memset(&gPreSysWarningInfo, 0, sizeof(struct WARNING_CODE_INFO));
|
|
|
+ memcpy(&gPreSysWarningInfo,
|
|
|
&(ShmSysConfigAndInfo->SysWarningInfo),
|
|
|
sizeof(struct WARNING_CODE_INFO));
|
|
|
break;
|
|
@@ -837,12 +1046,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 +1182,7 @@ static int writeWaitPlugItState(int fd, uint8_t id)
|
|
|
return ret;
|
|
|
}
|
|
|
|
|
|
-static int readPowerCabinetSystemID(int fd)
|
|
|
+static int readQRcodeURLAndSystemDate(int fd)
|
|
|
{
|
|
|
int ret = PASS;
|
|
|
|
|
@@ -989,10 +1201,10 @@ static int writePresentChargingInfo(int fd, uint8_t plugNum, uint8_t id)
|
|
|
uint8_t dataBuf[16] = {0};
|
|
|
PreChargingInfo *pPreChargingInfo = (PreChargingInfo *)dataBuf;
|
|
|
|
|
|
- pPreChargingInfo->EvBatterySoc = htonl(ChargingData[plugNum]->EvBatterySoc);
|
|
|
+ pPreChargingInfo->PresentChargingVoltage = htons((uint16_t)ChargingData[plugNum]->PresentChargingVoltage * 10);
|
|
|
+ pPreChargingInfo->PresentChargingCurrent = htons((uint16_t)ChargingData[plugNum]->PresentChargingCurrent * 10);
|
|
|
pPreChargingInfo->RemainChargingDuration = htonl(ChargingData[plugNum]->RemainChargingDuration);
|
|
|
- pPreChargingInfo->PresentChargingVoltage = htonl(ChargingData[plugNum]->PresentChargingVoltage);
|
|
|
- pPreChargingInfo->PresentChargingCurrent = htonl(ChargingData[plugNum]->PresentChargingCurrent);
|
|
|
+ pPreChargingInfo->EvBatterySoc = ChargingData[plugNum]->EvBatterySoc;
|
|
|
|
|
|
ret = composeSocketData(fd,
|
|
|
id,
|
|
@@ -1149,13 +1361,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;
|
|
|
}
|
|
@@ -1209,7 +1422,7 @@ static int writeDispenserStatus(int fd)
|
|
|
int ret = PASS;
|
|
|
|
|
|
if ((ShmSysConfigAndInfo->SysWarningInfo.WarningCount <= 0) &&
|
|
|
- (PreSysWarningInfo.WarningCount <= 0)) {
|
|
|
+ (gPreSysWarningInfo.WarningCount <= 0)) {
|
|
|
return FAIL;
|
|
|
}
|
|
|
|
|
@@ -1218,9 +1431,9 @@ static int writeDispenserStatus(int fd)
|
|
|
memcpy(CurWarnCodeTmp[count], ShmSysConfigAndInfo->SysWarningInfo.WarningCode[count], WARNING_CODE_SIZE);
|
|
|
}
|
|
|
|
|
|
- warningCount = PreSysWarningInfo.WarningCount;
|
|
|
+ warningCount = gPreSysWarningInfo.WarningCount;
|
|
|
for (count = 0; count < warningCount; count++) {
|
|
|
- memcpy(PreWarnCodeTmp[count], PreSysWarningInfo.WarningCode[count], WARNING_CODE_SIZE);
|
|
|
+ memcpy(PreWarnCodeTmp[count], gPreSysWarningInfo.WarningCode[count], WARNING_CODE_SIZE);
|
|
|
}
|
|
|
|
|
|
if (strcmp((char *)&CurWarnCodeTmp[0], (char *)&PreWarnCodeTmp[0]) == 0) {
|
|
@@ -1401,6 +1614,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 +1699,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 +1742,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 +1804,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 +1817,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:
|
|
@@ -1586,14 +1849,14 @@ static int messageTrigger(int fd, uint8_t plugNum, uint8_t gunID, uint8_t curReg
|
|
|
return ret;
|
|
|
}
|
|
|
|
|
|
-static bool isDetectPlugin()
|
|
|
-{
|
|
|
- if (ShmSysConfigAndInfo->SysInfo.WaitForPlugit == YES) {
|
|
|
- return YES;
|
|
|
- }
|
|
|
-
|
|
|
- return NO;
|
|
|
-}
|
|
|
+//static bool isDetectPlugin()
|
|
|
+//{
|
|
|
+// if (ShmSysConfigAndInfo->SysInfo.WaitForPlugit == YES) {
|
|
|
+// return YES;
|
|
|
+// }
|
|
|
+//
|
|
|
+// return NO;
|
|
|
+//}
|
|
|
|
|
|
static void systemStatusProcess(int fd, uint8_t plugNum, uint8_t gunID)
|
|
|
{
|
|
@@ -1621,15 +1884,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
|
|
@@ -1780,6 +2034,7 @@ static int networkCreatePorcess(void)
|
|
|
ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthGatewayAddress);
|
|
|
|
|
|
gDoCommGblData.DisConnCount = 0;
|
|
|
+ destroySelectGun(DESTROY_ALL_SEL);
|
|
|
|
|
|
sleep(3);
|
|
|
|
|
@@ -1811,14 +2066,14 @@ int main(int argc, char *argv[])
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
- totalConnCount = ShmSysConfigAndInfo->SysConfig.TotalConnectorCount;
|
|
|
+ totalConnCount = ShmSysConfigAndInfo->SysConfig.TotalConnectorCount;
|
|
|
|
|
|
for (index = 0; index < totalConnCount; index++) {
|
|
|
if (!FindChargingInfoData(index, &ChargingData[0])) {
|
|
|
DEBUG_ERROR("FindChargingInfoData false \n");
|
|
|
break;
|
|
|
}
|
|
|
- gAudiCustInfo->PricesInfo[index].Balance = FAIL_BALANCE_PRICES;
|
|
|
+ clearPricesInfo(index);
|
|
|
}
|
|
|
|
|
|
//initial trigger message timer
|
|
@@ -1845,10 +2100,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 +2123,12 @@ int main(int argc, char *argv[])
|
|
|
|
|
|
initDone = DISPENER_INIT_FAIL;
|
|
|
}
|
|
|
+
|
|
|
+ //update dispenser firmware
|
|
|
+ if (initDone != DISPENER_INIT_FAIL) {
|
|
|
+ updateFirmwareProcess(fd, totalConnCount);
|
|
|
+ }
|
|
|
+
|
|
|
usleep(1000);
|
|
|
}
|
|
|
}
|