|
@@ -1,7 +1,6 @@
|
|
|
#include "define.h"
|
|
|
#include "main.h"
|
|
|
|
|
|
-
|
|
|
//==========================
|
|
|
// System basic sample constant
|
|
|
//==========================
|
|
@@ -21,7 +20,7 @@
|
|
|
#define TMR_IDX_AUTH 1
|
|
|
#define TMR_IDX_LOGPPRINTOUT 2
|
|
|
#define TMR_IDX_PROFILE_PREPARE 3
|
|
|
-#define TMR_IDX_4 4
|
|
|
+#define TMR_IDX_PWN_CHANGE 4
|
|
|
#define TMR_IDX_5 5
|
|
|
#define TMR_IDX_6 6
|
|
|
#define TMR_IDX_7 7
|
|
@@ -33,6 +32,7 @@
|
|
|
#define TIMEOUT_SPEC_HANDSHAKING_LED 185000
|
|
|
#define TIMEOUT_SPEC_LOGPPRINTOUT 30000
|
|
|
#define TIMEOUT_SPEC_PROFILE_PREPARE 5000
|
|
|
+#define TIMEOUT_SPEC_PWN_CHANGE 5000
|
|
|
|
|
|
#define MtdBlockSize 0x600000
|
|
|
|
|
@@ -675,7 +675,6 @@ int LoadSysConfigAndInfo(struct SysConfigData *ptr)
|
|
|
|
|
|
if((buf=malloc(MtdBlockSize))==NULL)
|
|
|
{
|
|
|
-
|
|
|
DEBUG_ERROR("malloc buffer NG,rebooting..\r\n");
|
|
|
|
|
|
if(ShmStatusCodeData!=NULL)
|
|
@@ -737,7 +736,6 @@ int LoadSysConfigAndInfo(struct SysConfigData *ptr)
|
|
|
//================================================
|
|
|
if(ChkSum!=ChkSumOrg)
|
|
|
{
|
|
|
-
|
|
|
DEBUG_ERROR("Primary SysConfigData checksum NG, read backup\r\n");
|
|
|
|
|
|
fd = open("/dev/mtdblock11", O_RDWR);
|
|
@@ -791,10 +789,9 @@ int LoadSysConfigAndInfo(struct SysConfigData *ptr)
|
|
|
fd = open("/dev/mtdblock12", O_RDWR);
|
|
|
if (fd < 0)
|
|
|
{
|
|
|
- free(buf);
|
|
|
-
|
|
|
DEBUG_ERROR("open mtdblock12 (Factory default) NG,rebooting..\r\n");
|
|
|
-
|
|
|
+
|
|
|
+ free(buf);
|
|
|
if(ShmStatusCodeData!=NULL)
|
|
|
{
|
|
|
ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed=1;
|
|
@@ -809,10 +806,9 @@ int LoadSysConfigAndInfo(struct SysConfigData *ptr)
|
|
|
close(fd);
|
|
|
if(wrd<MtdBlockSize)
|
|
|
{
|
|
|
- free(buf);
|
|
|
-
|
|
|
DEBUG_ERROR("read factory default SysConfigData data NG,rebooting..\r\n");
|
|
|
-
|
|
|
+
|
|
|
+ free(buf);
|
|
|
if(ShmStatusCodeData!=NULL)
|
|
|
{
|
|
|
ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed=1;
|
|
@@ -895,8 +891,8 @@ int StoreUsrConfigData(struct SysConfigData *UsrData)
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- DEBUG_ERROR("write /dev/mtdblock10 NG\r\n");
|
|
|
- result = FAIL;
|
|
|
+ DEBUG_ERROR("write /dev/mtdblock10 NG\r\n");
|
|
|
+ result = FAIL;
|
|
|
}
|
|
|
}
|
|
|
else
|
|
@@ -908,8 +904,9 @@ int StoreUsrConfigData(struct SysConfigData *UsrData)
|
|
|
else
|
|
|
{
|
|
|
DEBUG_ERROR("alloc BlockSize NG\r\n");
|
|
|
- result = FAIL;
|
|
|
+ result = FAIL;
|
|
|
}
|
|
|
+
|
|
|
if(BufTmp!=NULL)
|
|
|
free(BufTmp);
|
|
|
|
|
@@ -1190,7 +1187,7 @@ void get_firmware_version(unsigned char gun_index)
|
|
|
strcpy((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev, ShmCharger->gun_info[gun_index].ver.Version_FW);
|
|
|
|
|
|
// Get CSU root file system version
|
|
|
- sprintf((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev, "B0.40.00.0000.00");
|
|
|
+ sprintf((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev, "V0.41.00.0000.00");
|
|
|
|
|
|
// Get AC connector type from model name
|
|
|
for(uint8_t idx=0;idx<3;idx++)
|
|
@@ -1641,34 +1638,63 @@ int isReachableInternet()
|
|
|
FILE *fp;
|
|
|
char cmd[256];
|
|
|
char buf[512];
|
|
|
- //char tmp[512];
|
|
|
-
|
|
|
- for(int idx=0;idx<ARRAY_SIZE(valid_Internet);idx++)
|
|
|
+ char tmp[512];
|
|
|
+
|
|
|
+ if(ShmOCPP16Data->OcppConnStatus == PASS)
|
|
|
+ {
|
|
|
+ result = PASS;
|
|
|
+ }
|
|
|
+ else
|
|
|
{
|
|
|
- sprintf(cmd, "ping -c 1 -w 3 -I eth0 %s", valid_Internet[idx]);
|
|
|
+ strcpy(cmd, "ifconfig eth0");
|
|
|
fp = popen(cmd, "r");
|
|
|
- if(fp != NULL)
|
|
|
+
|
|
|
+ if (fp != NULL)
|
|
|
{
|
|
|
while(fgets(buf, sizeof(buf), fp) != NULL)
|
|
|
{
|
|
|
- if(strstr(buf, "transmitted") > 0)
|
|
|
+ if (strstr(buf, "inet addr:") > 0)
|
|
|
{
|
|
|
- //sscanf(buf, "%*s%*s%*s%*s%*s%*s%s", tmp);
|
|
|
+ sscanf(buf, "%*s%s", tmp);
|
|
|
+ substr(tmp, tmp, strspn(tmp, "addr:"), strlen(buf)-strspn(tmp, "addr:"));
|
|
|
|
|
|
- if(strstr(buf,"100%") != NULL)
|
|
|
+ if (strcmp(tmp, (char *)ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthIpAddress) != 0)
|
|
|
{
|
|
|
-
|
|
|
+ strcpy((char *) ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthIpAddress, tmp);
|
|
|
}
|
|
|
- else
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ pclose(fp);
|
|
|
+ memset(buf, 0x00, sizeof(buf));
|
|
|
+
|
|
|
+ for(int idx=0;idx<ARRAY_SIZE(valid_Internet);idx++)
|
|
|
+ {
|
|
|
+ sprintf(cmd, "ping -c 1 -w 3 -I eth0 %s", valid_Internet[idx]);
|
|
|
+ fp = popen(cmd, "r");
|
|
|
+ if(fp != NULL)
|
|
|
+ {
|
|
|
+ while(fgets(buf, sizeof(buf), fp) != NULL)
|
|
|
+ {
|
|
|
+ if(strstr(buf, "transmitted") > 0)
|
|
|
{
|
|
|
- result = PASS;
|
|
|
+ //sscanf(buf, "%*s%*s%*s%*s%*s%*s%s", tmp);
|
|
|
+
|
|
|
+ if(strstr(buf,"100%") != NULL)
|
|
|
+ {
|
|
|
+
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ result = PASS;
|
|
|
+ }
|
|
|
+ //DEBUG_INFO("%s",buf);
|
|
|
+ //DEBUG_INFO("%s\n",tmp);
|
|
|
}
|
|
|
- //DEBUG_INFO("%s",buf);
|
|
|
- //DEBUG_INFO("%s\n",tmp);
|
|
|
}
|
|
|
}
|
|
|
+ pclose(fp);
|
|
|
}
|
|
|
- pclose(fp);
|
|
|
}
|
|
|
|
|
|
return result;
|
|
@@ -1745,7 +1771,6 @@ int getScheduleStart(int gun_index)
|
|
|
struct tm tmScheduleStart;;
|
|
|
struct timeb tbScheduleStart;
|
|
|
|
|
|
-
|
|
|
if((sscanf((char*)ShmOCPP16Data->SmartChargingProfile[gun_index].ChargingSchedule.StartSchedule, "%4d-%2d-%2dT%2d:%2d:%2d", &tmScheduleStart.tm_year, &tmScheduleStart.tm_mon, &tmScheduleStart.tm_mday, &tmScheduleStart.tm_hour, &tmScheduleStart.tm_min, &tmScheduleStart.tm_sec) == 6))
|
|
|
{
|
|
|
tmScheduleStart.tm_year -= 1900;
|
|
@@ -1754,8 +1779,8 @@ int getScheduleStart(int gun_index)
|
|
|
tbScheduleStart.millitm = 0;
|
|
|
|
|
|
result = DiffTimebWithNow(tbScheduleStart)/1000;
|
|
|
-
|
|
|
- DEBUG_INFO("Schedule start compare Now(seconds): %d\r\n", result);
|
|
|
+
|
|
|
+ //DEBUG_INFO("Schedule start compare Now(seconds): %d\r\n", result);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
@@ -1783,7 +1808,8 @@ int getStartSinceToday()
|
|
|
tbStartToday.time = mktime(tmStartToday);
|
|
|
|
|
|
result = DiffTimebWithNow(tbStartToday)/1000;
|
|
|
- DEBUG_INFO("Start today compare Now(seconds): %d\r\n", result);
|
|
|
+
|
|
|
+ //DEBUG_INFO("Start today compare Now(seconds): %d\r\n", result);
|
|
|
|
|
|
return result;
|
|
|
}
|
|
@@ -1807,8 +1833,8 @@ int getStartSinceWeek()
|
|
|
tbStartWeek.time = mktime(tmStartWeek);
|
|
|
|
|
|
result = DiffTimebWithNow(tbStartWeek)/1000;
|
|
|
-
|
|
|
- DEBUG_INFO("Start week compare Now(seconds): %d\r\n", result);
|
|
|
+
|
|
|
+ //DEBUG_INFO("Start week compare Now(seconds): %d\r\n", result);
|
|
|
|
|
|
return result;
|
|
|
}
|
|
@@ -1841,7 +1867,7 @@ int getEth0MacAddress()
|
|
|
char buf[512];
|
|
|
char tmp[512];
|
|
|
|
|
|
- strcpy(cmd, "ifconfig");;
|
|
|
+ strcpy(cmd, "ifconfig eth0");
|
|
|
fp = popen(cmd, "r");
|
|
|
if(fp != NULL)
|
|
|
{
|
|
@@ -2389,7 +2415,7 @@ int main(void)
|
|
|
{
|
|
|
ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartMethod = START_METHOD_FREE;
|
|
|
memcpy(ShmSysConfigAndInfo->SysConfig.UserId, ShmSysConfigAndInfo->SysConfig.SerialNumber, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.SerialNumber));
|
|
|
- DEBUG_INFO("Start Method : FREE..\r\n");
|
|
|
+ DEBUG_INFO("Start Method : FREE...\r\n");
|
|
|
}
|
|
|
|
|
|
ShmCharger->gun_info[gun_index].rfidReq = OFF;
|
|
@@ -2409,6 +2435,7 @@ int main(void)
|
|
|
ftime(&startTime[gun_index][TMR_IDX_AUTH]);
|
|
|
if(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartMethod == START_METHOD_RFID)
|
|
|
{
|
|
|
+ memset(ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, 0x00, ARRAY_SIZE(ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status));
|
|
|
switch(ShmSysConfigAndInfo->SysConfig.AuthorisationMode)
|
|
|
{
|
|
|
case AUTH_MODE_ENABLE:
|
|
@@ -2442,7 +2469,7 @@ int main(void)
|
|
|
}
|
|
|
ShmCharger->gun_info[gun_index].mcuFlag.isSetCpPwmDuty = YES;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
if(DiffTimebWithNow(startTime[gun_index][TMR_IDX_AUTH]) > TIMEOUT_SPEC_AUTH)
|
|
|
{
|
|
|
// Authorization timeout process.
|
|
@@ -2548,7 +2575,7 @@ int main(void)
|
|
|
ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargedEnergy = 0;
|
|
|
getDateTimeString((char*)ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartDateTime);
|
|
|
ShmCharger->gun_info[gun_index].powerConsumption.power_consumption_at_start = ShmCharger->gun_info[gun_index].powerConsumption.power_consumption;
|
|
|
- ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PowerConsumption = (ShmCharger->gun_info[gun_index].powerConsumption.power_consumption/100);
|
|
|
+ ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PowerConsumption = (ShmCharger->gun_info[gun_index].powerConsumption.power_consumption/100.0);
|
|
|
memcpy((char*)ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartUserId, ShmSysConfigAndInfo->SysConfig.UserId, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.UserId));
|
|
|
|
|
|
memcpy((char*)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (char*)ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartUserId, ARRAY_SIZE(ShmOCPP16Data->StartTransaction[gun_index].IdTag));
|
|
@@ -2565,8 +2592,11 @@ int main(void)
|
|
|
ftime(&startChargingTime[gun_index]);
|
|
|
ftime(&startTime[gun_index][TMR_IDX_LOGPPRINTOUT]);
|
|
|
ftime(&startTime[gun_index][TMR_IDX_PROFILE_PREPARE]);
|
|
|
+ ftime(&startTime[gun_index][TMR_IDX_PWN_CHANGE]);
|
|
|
startTime[gun_index][TMR_IDX_AUTH].time -= TIMEOUT_SPEC_AUTH;
|
|
|
ShmOCPP16Data->SpMsg.bits.AuthorizeReq = OFF;
|
|
|
+ ShmOCPP16Data->SmartChargingProfile[gun_index].ChargingProfileId = 0;
|
|
|
+ ShmCharger->gun_info[gun_index].isChargerStopByCondition = NO;
|
|
|
}
|
|
|
|
|
|
if((ShmCharger->gun_info[gun_index].rfidReq == ON) ||
|
|
@@ -2576,9 +2606,10 @@ int main(void)
|
|
|
(ShmOCPP16Data->MsMsg.bits.ResetReq) ||
|
|
|
(ShmCharger->gun_info[ShmOCPP16Data->UnlockConnector[gun_index].ConnectorId-1].isUnlockerConnetor == ON))
|
|
|
{
|
|
|
-
|
|
|
if(ShmCharger->gun_info[gun_index].rfidReq)
|
|
|
{
|
|
|
+ DEBUG_INFO("Certified in charging mode... \r\n");
|
|
|
+
|
|
|
// If RFID SN different with start user, it need to authorize ID
|
|
|
if((ShmCharger->gun_info[gun_index].rfidReq == ON) && !isMatchStartUser(gun_index))
|
|
|
{
|
|
@@ -2627,11 +2658,12 @@ int main(void)
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
DEBUG_INFO("End request User Id : %s\r\n", ShmSysConfigAndInfo->SysConfig.UserId);
|
|
|
- DEBUG_INFO("Start method : %d...\r\n ", ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartMethod);
|
|
|
+ DEBUG_INFO("Start method : %d\r\n ", ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartMethod);
|
|
|
|
|
|
if((ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartMethod == START_METHOD_RFID) ||
|
|
|
- (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartMethod == START_METHOD_BACKEND) ||
|
|
|
+ //(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartMethod == START_METHOD_BACKEND) ||
|
|
|
(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartMethod == START_METHOD_BLE))
|
|
|
{
|
|
|
switch(ShmSysConfigAndInfo->SysConfig.AuthorisationMode)
|
|
@@ -2665,6 +2697,11 @@ int main(void)
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
+ else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartMethod == START_METHOD_BACKEND)
|
|
|
+ {
|
|
|
+ DEBUG_INFO("Should be remote stop charger... \r\n");
|
|
|
+ ShmCharger->gun_info[gun_index].rfidReq = OFF;
|
|
|
+ }
|
|
|
}
|
|
|
else
|
|
|
{
|
|
@@ -2706,10 +2743,10 @@ int main(void)
|
|
|
else
|
|
|
{
|
|
|
setLedMotion(gun_index,LED_ACTION_CHARGING);
|
|
|
- ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PowerConsumption = (ShmCharger->gun_info[gun_index].powerConsumption.power_consumption/100);
|
|
|
+ ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PowerConsumption = (ShmCharger->gun_info[gun_index].powerConsumption.power_consumption/100.0);
|
|
|
ftime(&endChargingTime[gun_index]);
|
|
|
ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargedDuration = DiffTimeb(startChargingTime[gun_index], endChargingTime[gun_index])/1000;
|
|
|
- ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargedEnergy = ((float)(ShmCharger->gun_info[gun_index].powerConsumption.power_consumption - ShmCharger->gun_info[gun_index].powerConsumption.power_consumption_at_start))/100;
|
|
|
+ ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargedEnergy = (ShmCharger->gun_info[gun_index].powerConsumption.power_consumption - ShmCharger->gun_info[gun_index].powerConsumption.power_consumption_at_start)/100.0;
|
|
|
|
|
|
// Response StartTransactionConf
|
|
|
if(ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf == ON)
|
|
@@ -2732,7 +2769,7 @@ int main(void)
|
|
|
}
|
|
|
|
|
|
// Checking profile id > 0 and current time is between charging profile validFrom & validTo
|
|
|
- if((ShmOCPP16Data->SmartChargingProfile[gun_index].ChargingProfileId>0) &&
|
|
|
+ if((ShmOCPP16Data->SmartChargingProfile[gun_index].ChargingProfileId > 0) &&
|
|
|
(ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq != ON) &&
|
|
|
(((strlen((char*)ShmOCPP16Data->SmartChargingProfile[gun_index].ValidFrom)>0) && (strlen((char*)ShmOCPP16Data->SmartChargingProfile[gun_index].ValidTo)>0)) ? isProfileValid(gun_index) : ON))
|
|
|
{
|
|
@@ -2830,15 +2867,25 @@ int main(void)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+ else if((ShmOCPP16Data->SmartChargingProfile[gun_index].ChargingProfileId == 0) && (ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq != ON))
|
|
|
+ {
|
|
|
+ ShmCharger->gun_info[gun_index].targetCurrent = ShmCharger->gun_info[gun_index].primaryMcuState.rating_current;
|
|
|
+ }
|
|
|
+
|
|
|
// Determine max charging current to MCU
|
|
|
if(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent == 0)
|
|
|
{
|
|
|
ShmCharger->gun_info[gun_index].targetCurrent = ((ShmCharger->gun_info[gun_index].targetCurrent > ShmCharger->gun_info[gun_index].primaryMcuState.rating_current)?ShmCharger->gun_info[gun_index].primaryMcuState.rating_current:ShmCharger->gun_info[gun_index].targetCurrent);
|
|
|
if(ShmCharger->gun_info[gun_index].targetCurrent != ShmCharger->gun_info[gun_index].primaryMcuCp_Pwn_Duty.max_current)
|
|
|
{
|
|
|
- ShmCharger->gun_info[gun_index].primaryMcuCp_Pwn_Duty.max_current = ((ShmCharger->gun_info[gun_index].targetCurrent > ShmCharger->gun_info[gun_index].primaryMcuState.rating_current)?ShmCharger->gun_info[gun_index].primaryMcuState.rating_current:ShmCharger->gun_info[gun_index].targetCurrent);
|
|
|
- ShmCharger->gun_info[gun_index].mcuFlag.isSetCpPwmDuty = YES;
|
|
|
+ if(DiffTimebWithNow(startTime[gun_index][TMR_IDX_PWN_CHANGE]) > TIMEOUT_SPEC_PWN_CHANGE)
|
|
|
+ {
|
|
|
+ ShmCharger->gun_info[gun_index].primaryMcuCp_Pwn_Duty.max_current = ((ShmCharger->gun_info[gun_index].targetCurrent > ShmCharger->gun_info[gun_index].primaryMcuState.rating_current)?ShmCharger->gun_info[gun_index].primaryMcuState.rating_current:ShmCharger->gun_info[gun_index].targetCurrent);
|
|
|
+ ShmCharger->gun_info[gun_index].mcuFlag.isSetCpPwmDuty = YES;
|
|
|
+ ftime(&startTime[gun_index][TMR_IDX_PWN_CHANGE]);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {}
|
|
|
}
|
|
|
}
|
|
|
else
|
|
@@ -2846,8 +2893,14 @@ int main(void)
|
|
|
ShmCharger->gun_info[gun_index].targetCurrent = ((ShmCharger->gun_info[gun_index].targetCurrent > ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent)?ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent:ShmCharger->gun_info[gun_index].targetCurrent);
|
|
|
if(ShmCharger->gun_info[gun_index].targetCurrent != ShmCharger->gun_info[gun_index].primaryMcuCp_Pwn_Duty.max_current)
|
|
|
{
|
|
|
- ShmCharger->gun_info[gun_index].primaryMcuCp_Pwn_Duty.max_current = ((ShmCharger->gun_info[gun_index].targetCurrent > ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent)?ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent:ShmCharger->gun_info[gun_index].targetCurrent);
|
|
|
- ShmCharger->gun_info[gun_index].mcuFlag.isSetCpPwmDuty = YES;
|
|
|
+ if(DiffTimebWithNow(startTime[gun_index][TMR_IDX_PWN_CHANGE]) > TIMEOUT_SPEC_PWN_CHANGE)
|
|
|
+ {
|
|
|
+ ShmCharger->gun_info[gun_index].primaryMcuCp_Pwn_Duty.max_current = ((ShmCharger->gun_info[gun_index].targetCurrent > ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent)?ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent:ShmCharger->gun_info[gun_index].targetCurrent);
|
|
|
+ ShmCharger->gun_info[gun_index].mcuFlag.isSetCpPwmDuty = YES;
|
|
|
+ ftime(&startTime[gun_index][TMR_IDX_PWN_CHANGE]);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {}
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -2855,7 +2908,7 @@ int main(void)
|
|
|
if(DiffTimebWithNow(startTime[gun_index][TMR_IDX_LOGPPRINTOUT]) > TIMEOUT_SPEC_LOGPPRINTOUT)
|
|
|
{
|
|
|
DEBUG_INFO("=======================================================================\r\n");
|
|
|
- DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent: %d \r\n", ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
|
|
|
+ DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent: %d\r\n", ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
|
|
|
DEBUG_INFO("ShmCharger->gun_info[%d].primaryMcuCp_Pwn_Duty.max_current: %d\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuCp_Pwn_Duty.max_current);
|
|
|
DEBUG_INFO("ShmCharger->gun_info[%d].targetCurrent: %d\r\n", gun_index, ShmCharger->gun_info[gun_index].targetCurrent);
|
|
|
DEBUG_INFO("=======================================================================\r\n");
|
|
@@ -2867,16 +2920,21 @@ int main(void)
|
|
|
// On-line max condition check
|
|
|
if((ShmSysConfigAndInfo->SysConfig.MaxChargingDuration > 0) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargedDuration >= (ShmSysConfigAndInfo->SysConfig.MaxChargingDuration*60)))
|
|
|
{
|
|
|
+ setRelay(gun_index, OFF);
|
|
|
+ ShmCharger->gun_info[gun_index].isChargerStopByCondition = YES;
|
|
|
setChargerMode(gun_index, SYS_MODE_TERMINATING);
|
|
|
DEBUG_INFO("Connector-%d charging duration(%d) already over max duration(%d) in second.\r\n", gun_index, ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargedDuration, (ShmSysConfigAndInfo->SysConfig.MaxChargingDuration*60));
|
|
|
}
|
|
|
else if((ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy > 0) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargedEnergy >= ((float)ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy)))
|
|
|
{
|
|
|
+ setRelay(gun_index, OFF);
|
|
|
+ ShmCharger->gun_info[gun_index].isChargerStopByCondition = YES;
|
|
|
setChargerMode(gun_index, SYS_MODE_TERMINATING);
|
|
|
DEBUG_INFO("Connector-%d charging energy(%.2f) already over max energy(%.2f) in KWH.\r\n", gun_index, ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargedEnergy, ((float)ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy));
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
+ ShmCharger->gun_info[gun_index].isChargerStopByCondition = NO;
|
|
|
setRelay(gun_index, ON);
|
|
|
}
|
|
|
}
|
|
@@ -2888,16 +2946,21 @@ int main(void)
|
|
|
{
|
|
|
if(((ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeDuration > 0) ? (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargedDuration >= (ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeDuration*60)) : (ShmSysConfigAndInfo->SysConfig.MaxChargingDuration > 0) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargedDuration >= (ShmSysConfigAndInfo->SysConfig.MaxChargingDuration*60))))
|
|
|
{
|
|
|
+ setRelay(gun_index, OFF);
|
|
|
+ ShmCharger->gun_info[gun_index].isChargerStopByCondition = YES;
|
|
|
setChargerMode(gun_index, SYS_MODE_TERMINATING);
|
|
|
DEBUG_INFO("Connector-%d charging duration(%d) already over off-line max duration(%d) in second.\r\n", gun_index, ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargedDuration, (ShmSysConfigAndInfo->SysConfig.MaxChargingDuration*60));
|
|
|
}
|
|
|
else if(((ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy > 0) ? (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargedEnergy >= ((float)ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy)) : (ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy > 0) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargedEnergy >= ((float)ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy))))
|
|
|
{
|
|
|
+ setRelay(gun_index, OFF);
|
|
|
+ ShmCharger->gun_info[gun_index].isChargerStopByCondition = YES;
|
|
|
setChargerMode(gun_index, SYS_MODE_TERMINATING);
|
|
|
DEBUG_INFO("Connector-%d charging energy(%.2f) already over off-line max energy(%.2f) in KWH.\r\n", gun_index, ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargedEnergy, ((float)ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy));
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
+ ShmCharger->gun_info[gun_index].isChargerStopByCondition = NO;
|
|
|
setRelay(gun_index, ON);
|
|
|
}
|
|
|
}
|
|
@@ -2918,14 +2981,8 @@ int main(void)
|
|
|
ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargedDuration = DiffTimeb(startChargingTime[gun_index], endChargingTime[gun_index])/1000;
|
|
|
}
|
|
|
|
|
|
- if(!ShmCharger->gun_info[gun_index].primaryMcuState.relay_state)
|
|
|
- {
|
|
|
- setLedMotion(gun_index, LED_ACTION_STOP);
|
|
|
- }
|
|
|
- else
|
|
|
- {}
|
|
|
-
|
|
|
getDateTimeString((char*)ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StopDateTime);
|
|
|
+ startTime[gun_index][TMR_IDX_AUTH].time -= TIMEOUT_SPEC_AUTH;
|
|
|
}
|
|
|
|
|
|
// End authorize pass
|
|
@@ -2937,7 +2994,7 @@ int main(void)
|
|
|
(ShmOCPP16Data->MsMsg.bits.ResetReq) ||
|
|
|
(ShmCharger->gun_info[ShmOCPP16Data->UnlockConnector[gun_index].ConnectorId-1].isUnlockerConnetor == ON))
|
|
|
{
|
|
|
- if(ShmCharger->gun_info[gun_index].legacyRequest.isLegacyRequest == ON)
|
|
|
+ if((ShmCharger->gun_info[gun_index].legacyRequest.isLegacyRequest == ON) || (ShmCharger->gun_info[gun_index].isChargerStopByCondition == YES))
|
|
|
{
|
|
|
if(((ShmCharger->gun_info[gun_index].rfidReq == ON) && isMatchStartUser(gun_index)) ||
|
|
|
(ShmCharger->gun_info[gun_index].isAuthPassEnd))
|
|
@@ -2947,13 +3004,32 @@ int main(void)
|
|
|
setLedMotion(gun_index,LED_ACTION_RFID_PASS);
|
|
|
sleep(3);
|
|
|
}
|
|
|
+ else
|
|
|
+ {
|
|
|
+ /*
|
|
|
+ // If stop reason is "Bluetooth" / "RemoteStop" / "Reset" / "Unplug" should be set speaker on
|
|
|
+ if(ShmCharger->gun_info[gun_index].bleConfigData.isRequestStop == ON)
|
|
|
+ DEBUG_INFO("Bluetooth to stop charging... \r\n");
|
|
|
+ else if(ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStopTransactionReq == ON)
|
|
|
+ DEBUG_INFO("Remote to stop charging... \r\n");
|
|
|
+ else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PilotState == CP_STATE_A) && (strcmp((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE") == 0))
|
|
|
+ DEBUG_INFO("Unplug to stop charging... \r\n");
|
|
|
+ else if(ShmOCPP16Data->MsMsg.bits.ResetReq)
|
|
|
+ DEBUG_INFO("Reset request to stop charging... \r\n");
|
|
|
+ else if(ShmCharger->gun_info[ShmOCPP16Data->UnlockConnector[gun_index].ConnectorId-1].isUnlockerConnetor == ON)
|
|
|
+ DEBUG_INFO("Unlock connector request to stop charging... \r\n");
|
|
|
+
|
|
|
+ setSpeaker(ON,SPEAKER_SHORT);
|
|
|
+ */
|
|
|
+ }
|
|
|
}
|
|
|
else
|
|
|
{}
|
|
|
|
|
|
setRelay(gun_index, OFF);
|
|
|
setLedMotion(gun_index, LED_ACTION_STOP);
|
|
|
-
|
|
|
+
|
|
|
+ // If relay is off, the system should change to complete mode
|
|
|
if(!ShmCharger->gun_info[gun_index].primaryMcuState.relay_state)
|
|
|
{
|
|
|
setChargerMode(gun_index, SYS_MODE_COMPLETE);
|
|
@@ -2961,6 +3037,140 @@ int main(void)
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
+ // If the charger stops charging, the led should be stoped blink
|
|
|
+ if(!ShmCharger->gun_info[gun_index].primaryMcuState.relay_state)
|
|
|
+ {
|
|
|
+ setLedMotion(gun_index, LED_ACTION_STOP);
|
|
|
+ }
|
|
|
+
|
|
|
+ if(ShmCharger->gun_info[gun_index].rfidReq)
|
|
|
+ {
|
|
|
+ DEBUG_INFO("Certified in terminating mode... \r\n");
|
|
|
+
|
|
|
+ // If RFID SN different with start user, it need to authorize ID
|
|
|
+ if((ShmCharger->gun_info[gun_index].rfidReq == ON) && !isMatchStartUser(gun_index))
|
|
|
+ {
|
|
|
+ if((DiffTimebWithNow(startTime[gun_index][TMR_IDX_AUTH]) > TIMEOUT_SPEC_AUTH) && !ShmOCPP16Data->SpMsg.bits.AuthorizeReq)
|
|
|
+ {
|
|
|
+ // Request authorization
|
|
|
+ ftime(&startTime[gun_index][TMR_IDX_AUTH]);
|
|
|
+ memset(ShmSysConfigAndInfo->SysConfig.UserId, 0x00, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.UserId));
|
|
|
+ if(ShmSysConfigAndInfo->SysConfig.RfidCardNumEndian)
|
|
|
+ {
|
|
|
+ // Big endian
|
|
|
+ switch(rfid.snType)
|
|
|
+ {
|
|
|
+ case RFID_SN_TYPE_6BYTE:
|
|
|
+ sprintf((char*)ShmSysConfigAndInfo->SysConfig.UserId, "%02X%02X%02X%02X%02X%02X", rfid.currentCard[0], rfid.currentCard[1], rfid.currentCard[2], rfid.currentCard[3], rfid.currentCard[4], rfid.currentCard[5]);
|
|
|
+ break;
|
|
|
+ case RFID_SN_TYPE_7BYTE:
|
|
|
+ sprintf((char*)ShmSysConfigAndInfo->SysConfig.UserId, "%02X%02X%02X%02X%02X%02X%02X", rfid.currentCard[0], rfid.currentCard[1], rfid.currentCard[2], rfid.currentCard[3], rfid.currentCard[4], rfid.currentCard[5], rfid.currentCard[6]);
|
|
|
+ break;
|
|
|
+ case RFID_SN_TYPE_10BYTE:
|
|
|
+ sprintf((char*)ShmSysConfigAndInfo->SysConfig.UserId, "%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X", rfid.currentCard[0], rfid.currentCard[1], rfid.currentCard[2], rfid.currentCard[3], rfid.currentCard[4], rfid.currentCard[5], rfid.currentCard[6], rfid.currentCard[7], rfid.currentCard[8], rfid.currentCard[9]);
|
|
|
+ break;
|
|
|
+ case RFID_SN_TYPE_4BYTE:
|
|
|
+ default:
|
|
|
+ sprintf((char*)ShmSysConfigAndInfo->SysConfig.UserId, "%02X%02X%02X%02X", rfid.currentCard[0], rfid.currentCard[1], rfid.currentCard[2], rfid.currentCard[3]);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ // Little endian
|
|
|
+ switch(rfid.snType)
|
|
|
+ {
|
|
|
+ case RFID_SN_TYPE_6BYTE:
|
|
|
+ sprintf((char*)ShmSysConfigAndInfo->SysConfig.UserId, "%02X%02X%02X%02X%02X%02X", rfid.currentCard[5], rfid.currentCard[4], rfid.currentCard[3], rfid.currentCard[2], rfid.currentCard[1], rfid.currentCard[0]);
|
|
|
+ break;
|
|
|
+ case RFID_SN_TYPE_7BYTE:
|
|
|
+ sprintf((char*)ShmSysConfigAndInfo->SysConfig.UserId, "%02X%02X%02X%02X%02X%02X%02X", rfid.currentCard[6], rfid.currentCard[5], rfid.currentCard[4], rfid.currentCard[3], rfid.currentCard[2], rfid.currentCard[1], rfid.currentCard[0]);
|
|
|
+ break;
|
|
|
+ case RFID_SN_TYPE_10BYTE:
|
|
|
+ sprintf((char*)ShmSysConfigAndInfo->SysConfig.UserId, "%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X", rfid.currentCard[9], rfid.currentCard[8], rfid.currentCard[7], rfid.currentCard[6], rfid.currentCard[5], rfid.currentCard[4], rfid.currentCard[3], rfid.currentCard[2], rfid.currentCard[1], rfid.currentCard[0]);
|
|
|
+ break;
|
|
|
+ case RFID_SN_TYPE_4BYTE:
|
|
|
+ default:
|
|
|
+ sprintf((char*)ShmSysConfigAndInfo->SysConfig.UserId, "%02X%02X%02X%02X", rfid.currentCard[3], rfid.currentCard[2], rfid.currentCard[1], rfid.currentCard[0]);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ DEBUG_INFO("End request User Id : %s... \r\n", ShmSysConfigAndInfo->SysConfig.UserId);
|
|
|
+ DEBUG_INFO("Start method : %d... \r\n ", ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartMethod);
|
|
|
+
|
|
|
+ if((ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartMethod == START_METHOD_RFID) ||
|
|
|
+ //(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartMethod == START_METHOD_BACKEND) ||
|
|
|
+ (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartMethod == START_METHOD_BLE))
|
|
|
+ {
|
|
|
+ switch(ShmSysConfigAndInfo->SysConfig.AuthorisationMode)
|
|
|
+ {
|
|
|
+ case AUTH_MODE_ENABLE:
|
|
|
+ if(ShmOCPP16Data->OcppConnStatus)
|
|
|
+ {
|
|
|
+ // On line
|
|
|
+ ShmOCPP16Data->SpMsg.bits.AuthorizeReq = ON;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ // Off line
|
|
|
+ switch(ShmSysConfigAndInfo->SysConfig.OfflinePolicy)
|
|
|
+ {
|
|
|
+ case OFF_POLICY_LOCALLIST:
|
|
|
+ ShmOCPP16Data->SpMsg.bits.AuthorizeReq = ON;
|
|
|
+ break;
|
|
|
+ case OFF_POLICY_PH_RFID:
|
|
|
+ break;
|
|
|
+ case OFF_POLICY_FREE:
|
|
|
+ break;
|
|
|
+ case OFF_POLICY_NOCHARGE:
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case AUTH_MODE_DISABLE:
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartMethod == START_METHOD_BACKEND)
|
|
|
+ {
|
|
|
+ DEBUG_INFO("Should be remote stop charger... \r\n");
|
|
|
+ ShmCharger->gun_info[gun_index].rfidReq = OFF;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if(ShmOCPP16Data->SpMsg.bits.AuthorizeConf ||
|
|
|
+ (ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_DISABLE) ||
|
|
|
+ (!ShmOCPP16Data->OcppConnStatus && (ShmSysConfigAndInfo->SysConfig.OfflinePolicy == OFF_POLICY_LOCALLIST)) ||
|
|
|
+ (!ShmOCPP16Data->OcppConnStatus && (ShmSysConfigAndInfo->SysConfig.OfflinePolicy == OFF_POLICY_FREE)))
|
|
|
+ {
|
|
|
+ if((strcmp((char*)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted")==0) ||
|
|
|
+ (ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_DISABLE) ||
|
|
|
+ (!ShmOCPP16Data->OcppConnStatus && (isValidLocalWhiteCard() == PASS) && (ShmSysConfigAndInfo->SysConfig.OfflinePolicy == OFF_POLICY_LOCALLIST)) ||
|
|
|
+ (!ShmOCPP16Data->OcppConnStatus && (ShmSysConfigAndInfo->SysConfig.OfflinePolicy == OFF_POLICY_FREE)))
|
|
|
+ {
|
|
|
+ ShmCharger->gun_info[gun_index].isAuthPassEnd = ON;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ ShmCharger->gun_info[gun_index].rfidReq = OFF;
|
|
|
+ ShmOCPP16Data->SpMsg.bits.AuthorizeReq = OFF;
|
|
|
+ DEBUG_INFO("Authorize fail... \r\n");
|
|
|
+ setSpeaker(ON,SPEAKER_INTERVAL_3COUNT);
|
|
|
+ setLedMotion(gun_index,LED_ACTION_RFID_FAIL);
|
|
|
+ sleep(3);
|
|
|
+ }
|
|
|
+
|
|
|
+ startTime[gun_index][TMR_IDX_AUTH].time -= TIMEOUT_SPEC_AUTH;
|
|
|
+ ShmOCPP16Data->SpMsg.bits.AuthorizeConf = OFF;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
if((ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PilotState == CP_STATE_C) &&
|
|
|
(ShmCharger->gun_info[gun_index].rfidReq != ON) &&
|
|
|
(ShmCharger->gun_info[gun_index].bleConfigData.isRequestStop != ON) &&
|
|
@@ -3012,9 +3222,9 @@ int main(void)
|
|
|
DEBUG_INFO("Gun-%d : StopReason [ %s ]...\r\n.",gun_index,ShmOCPP16Data->StopTransaction[gun_index].StopReason);
|
|
|
|
|
|
memcpy((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag, (char*)ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartUserId, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].IdTag));
|
|
|
- ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PowerConsumption = (ShmCharger->gun_info[gun_index].powerConsumption.power_consumption/100);
|
|
|
+ ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PowerConsumption = (ShmCharger->gun_info[gun_index].powerConsumption.power_consumption/100.0);
|
|
|
+
|
|
|
ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = ON;
|
|
|
-
|
|
|
ShmCharger->gun_info[gun_index].rfidReq = OFF;
|
|
|
ShmCharger->gun_info[gun_index].isAuthPassEnd = OFF;
|
|
|
ShmCharger->gun_info[gun_index].bleConfigData.isRequestStop = OFF;
|
|
@@ -3078,7 +3288,7 @@ int main(void)
|
|
|
ShmSysConfigAndInfo->SysInfo.FirmwareUpdate = OFF;
|
|
|
int value = upgrade_check();
|
|
|
|
|
|
- DEBUG_INFO("Local update Value: %d...\r\n",value);
|
|
|
+ DEBUG_INFO("Local update Value: %s... \r\n",((value == PASS)?"Pass": "Fail"));
|
|
|
if(value == PASS)
|
|
|
{
|
|
|
if(ShmStatusCodeData->InfoCode.InfoEvents.bits.CsuFimrwareUpdateFail == ON)
|
|
@@ -3115,7 +3325,7 @@ int main(void)
|
|
|
ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = OFF;
|
|
|
int result = upgrade_check();
|
|
|
|
|
|
- DEBUG_INFO("Remote update Result: %d...\r\n",result);
|
|
|
+ DEBUG_INFO("Remote update Result: %s... \r\n",((result == PASS)?"Pass": "Fail"));
|
|
|
if(result == PASS)
|
|
|
{
|
|
|
if(ShmStatusCodeData->InfoCode.InfoEvents.bits.CsuFimrwareUpdateFail == ON)
|