|
@@ -1,6 +1,7 @@
|
|
|
#include "define.h"
|
|
|
#include "main.h"
|
|
|
|
|
|
+
|
|
|
//==========================
|
|
|
// System basic sample constant
|
|
|
//==========================
|
|
@@ -56,6 +57,7 @@ void setSpeaker(unsigned char isOn, unsigned char speaker_mode);
|
|
|
//==========================
|
|
|
#define MODULE_EWT 0
|
|
|
|
|
|
+int wtdFd = -1;
|
|
|
int rfidFd = -1;
|
|
|
char* rfidPortName = "/dev/ttyS2";
|
|
|
RFID rfid;
|
|
@@ -493,10 +495,26 @@ int DB_Insert_Record(sqlite3 *db, int gun_index)
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
//======================================================
|
|
|
// Peripheral initial
|
|
|
//======================================================
|
|
|
+int InitWatchDog()
|
|
|
+{
|
|
|
+ int fd;
|
|
|
+
|
|
|
+ system("/usr/bin/fuser -k /dev/watchdog");
|
|
|
+ sleep(1);
|
|
|
+ system("echo V > /dev/watchdog");
|
|
|
+ sleep(1);
|
|
|
+ fd=open("/dev/watchdog", O_RDWR);
|
|
|
+ if(fd<=0)
|
|
|
+ {
|
|
|
+ DEBUG_ERROR("System watch dog initial fail.\r\n");
|
|
|
+ }
|
|
|
+
|
|
|
+ return fd;
|
|
|
+}
|
|
|
+
|
|
|
void InitGPIO()
|
|
|
{
|
|
|
/*****************0~3, 4 bank, bank x 32+ num*********************/
|
|
@@ -644,7 +662,6 @@ int LoadSysConfigAndInfo(struct SysConfigData *ptr)
|
|
|
//================================================
|
|
|
if(ChkSum!=ChkSumOrg)
|
|
|
{
|
|
|
-
|
|
|
DEBUG_WARN("backup SysConfigData checksum NG, read Factory default\r\n");
|
|
|
|
|
|
fd = open("/dev/mtdblock12", O_RDWR);
|
|
@@ -732,6 +749,7 @@ void InitEthernet()
|
|
|
sprintf(tmpbuf,"route add default gw %s eth0 ",
|
|
|
ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthGatewayAddress);
|
|
|
system(tmpbuf);
|
|
|
+ system("/sbin/ifconfig eth0:1 192.168.201.201 netmask 255.255.255.248 up");
|
|
|
}
|
|
|
|
|
|
if(isInterfaceUp("eth1")==PASS)
|
|
@@ -792,6 +810,7 @@ int SpawnTask()
|
|
|
system ("pkill Module_AlarmDetect");
|
|
|
system ("pkill Module_InternalComm");
|
|
|
system ("pkill Module_Speaker");
|
|
|
+ system ("pkill Module_ProduceUtils");
|
|
|
|
|
|
if(ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'T')
|
|
|
{
|
|
@@ -807,9 +826,10 @@ int SpawnTask()
|
|
|
{
|
|
|
system("/root/OcppBackend &");
|
|
|
}
|
|
|
- system("/root/Module_AlarmDetect &");
|
|
|
- system("/root/Module_InternalComm &");
|
|
|
+ system ("/root/Module_AlarmDetect &");
|
|
|
+ system ("/root/Module_InternalComm &");
|
|
|
system ("/root/Module_Speaker &");
|
|
|
+ system ("/root/Module_ProduceUtils &");
|
|
|
|
|
|
return PASS;
|
|
|
}
|
|
@@ -887,9 +907,14 @@ int Initialization()
|
|
|
|
|
|
InitEthernet();
|
|
|
|
|
|
+ if(DB_Open(localDb) != PASS)
|
|
|
+ result = FAIL;
|
|
|
+
|
|
|
rfidFd = InitRfidPort();
|
|
|
|
|
|
- if((DB_Open(localDb) != PASS) || (rfidFd < 0))
|
|
|
+ wtdFd = InitWatchDog();
|
|
|
+
|
|
|
+ if((wtdFd < 0) || (rfidFd < 0))
|
|
|
result = FAIL;
|
|
|
|
|
|
if(result == PASS)
|
|
@@ -945,6 +970,12 @@ char* getSystemModeName(unsigned char mode)
|
|
|
case SYS_MODE_DEBUG:
|
|
|
result = "debug";
|
|
|
break;
|
|
|
+ case SYS_MODE_UPDATE:
|
|
|
+ result = "upgrade";
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ result = "unknown";
|
|
|
+ break;
|
|
|
}
|
|
|
|
|
|
return result;
|
|
@@ -1006,7 +1037,7 @@ void get_firmware_version(unsigned char gun_index)
|
|
|
}
|
|
|
|
|
|
// Get CSU root file system version
|
|
|
- sprintf((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev, "D0.04.40.0007.PH");
|
|
|
+ sprintf((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev, "D0.10.40.0007.PH");
|
|
|
|
|
|
// Get MCU firmware version
|
|
|
strcpy((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev, ShmCharger->gun_info[gun_index].ver.Version_FW);
|
|
@@ -1018,6 +1049,7 @@ void get_firmware_version(unsigned char gun_index)
|
|
|
DEBUG_INFO("CSU MCU-%2d firmware version: %s\r\n", gun_index, ShmCharger->gun_info[gun_index].ver.Version_FW);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
//===============================================
|
|
|
// Upgrade firmware
|
|
|
//===============================================
|
|
@@ -1243,61 +1275,6 @@ int GetFaultValue()
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
-//===============================================
|
|
|
-// Authorizing Response Status
|
|
|
-//===============================================
|
|
|
-int isAuthorizedPass()
|
|
|
-{
|
|
|
- int result = FAIL;
|
|
|
-
|
|
|
- char tmp[16] = "";
|
|
|
- memset(tmp, 0, ARRAY_SIZE(tmp));
|
|
|
-
|
|
|
- for(int index = 0; index < strlen((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);index++)
|
|
|
- {
|
|
|
- sprintf(tmp + (index - 1) * 2, "%02X",ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status[index]);
|
|
|
- }
|
|
|
- sprintf(tmp, "%s", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
|
|
|
-
|
|
|
- DEBUG_INFO("Authorize Response Id TagInfo: %s\r\n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
|
|
|
-
|
|
|
- if(strstr(tmp, "Accepted") != 0)
|
|
|
- {
|
|
|
- result = PASS;
|
|
|
- }
|
|
|
- else
|
|
|
- {}
|
|
|
-
|
|
|
- return result;
|
|
|
-}
|
|
|
-
|
|
|
-//===============================================
|
|
|
-// BootNotification Response Status
|
|
|
-//===============================================
|
|
|
-int isBootNotificationSignature()
|
|
|
-{
|
|
|
- int result = FAIL;
|
|
|
-
|
|
|
- char tmp[16] = "";
|
|
|
- memset(tmp, 0, ARRAY_SIZE(tmp));
|
|
|
-
|
|
|
- for(int index = 0; index < strlen((char *)ShmOCPP16Data->BootNotification.ResponseStatus);index++)
|
|
|
- {
|
|
|
- sprintf(tmp + (index - 1) * 2, "%02X",ShmOCPP16Data->BootNotification.ResponseStatus[index]);
|
|
|
- }
|
|
|
- sprintf(tmp, "%s",ShmOCPP16Data->BootNotification.ResponseStatus);
|
|
|
-
|
|
|
- DEBUG_INFO("BootNotification Response Status: %s\r\n", ShmOCPP16Data->BootNotification.ResponseStatus);
|
|
|
- if(strstr(tmp, "Accepted") != 0)
|
|
|
- {
|
|
|
- result = PASS;
|
|
|
- }
|
|
|
- else
|
|
|
- {}
|
|
|
-
|
|
|
- return result;
|
|
|
-}
|
|
|
-
|
|
|
//===============================================
|
|
|
// Set led motion
|
|
|
//===============================================
|
|
@@ -1363,7 +1340,7 @@ void setLedMotion(unsigned char gun_index,unsigned char led_mode)
|
|
|
}
|
|
|
|
|
|
//===============================================
|
|
|
-// Relay on/off request
|
|
|
+// Relay on/off request set
|
|
|
//===============================================
|
|
|
void setRelay(unsigned char gun_index,unsigned char isOn)
|
|
|
{
|
|
@@ -1385,6 +1362,14 @@ void setRelay(unsigned char gun_index,unsigned char isOn)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+//===============================================
|
|
|
+// Relay on/off request get
|
|
|
+//===============================================
|
|
|
+int getRelay(unsigned char gun_index)
|
|
|
+{
|
|
|
+ return ShmCharger->gun_info[gun_index].legacyRequest.isLegacyRequest;
|
|
|
+}
|
|
|
+
|
|
|
//===============================================
|
|
|
// Set speaker on/off request
|
|
|
//===============================================
|
|
@@ -1481,15 +1466,21 @@ int isReservationExpired(unsigned char gun_index)
|
|
|
|
|
|
if(sscanf((char*)ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate, "%4d-%2d-%2dT%2d:%2d:%2d", &expiredDate.tm_year, &expiredDate.tm_mon, &expiredDate.tm_mday, &expiredDate.tm_hour, &expiredDate.tm_min, &expiredDate.tm_sec) == 6)
|
|
|
{
|
|
|
+ expiredDate.tm_year -= 1900;
|
|
|
+ expiredDate.tm_mon -= 1;
|
|
|
expiredTime.time = mktime(&expiredDate);
|
|
|
|
|
|
- if(DiffTimebWithNow(expiredTime)>0)
|
|
|
+ if(DiffTimebWithNow(expiredTime) >= 0)
|
|
|
{
|
|
|
result = YES;
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
- DEBUG_WARN("Expired date parsing error\r\n");
|
|
|
+ {
|
|
|
+ DEBUG_WARN("Expired date parsing error...\r\n");
|
|
|
+ DEBUG_INFO("Date expired...\r\n");
|
|
|
+ result = YES;
|
|
|
+ }
|
|
|
|
|
|
return result;
|
|
|
}
|
|
@@ -1538,6 +1529,8 @@ int main(void)
|
|
|
for(int gun_index = 0;gun_index<AC_QUANTITY;gun_index++)
|
|
|
{
|
|
|
ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PreviousSystemStatus = 0xff;
|
|
|
+ ShmCharger->gun_info[gun_index].primaryMcuState.rotatory_switch = 0xff;
|
|
|
+ ShmCharger->gun_info[gun_index].mcuResetRequest.isMcuResetRequest = ON;
|
|
|
}
|
|
|
|
|
|
// Main loop
|
|
@@ -1575,7 +1568,7 @@ int main(void)
|
|
|
{
|
|
|
ShmCharger->isUpdateSuccess = FAIL;
|
|
|
for(int gun_index = 0;gun_index<AC_QUANTITY;gun_index++)
|
|
|
- setChargerMode(gun_index, SYS_MODE_MAINTAIN);
|
|
|
+ setChargerMode(gun_index, SYS_MODE_UPDATE);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -1620,6 +1613,9 @@ int main(void)
|
|
|
//==========================================
|
|
|
for(int gun_index = 0;gun_index<AC_QUANTITY;gun_index++)
|
|
|
{
|
|
|
+ // Synchronize current rating value from MCU
|
|
|
+ ShmSysConfigAndInfo->SysConfig.RatingCurrent = ShmCharger->gun_info[gun_index].primaryMcuState.rating_current;
|
|
|
+
|
|
|
// Assign connector location index for OCPP
|
|
|
ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].Index = gun_index;
|
|
|
|
|
@@ -1714,7 +1710,10 @@ int main(void)
|
|
|
DEBUG_INFO("Wifi SSID: %s\r\n", ShmSysConfigAndInfo->SysConfig.AthInterface.WifiSsid);
|
|
|
DEBUG_INFO("Wifi password: %s\r\n", ShmSysConfigAndInfo->SysConfig.AthInterface.WifiPassword);
|
|
|
|
|
|
- setChargerMode(gun_index, SYS_MODE_IDLE);
|
|
|
+ if(ShmCharger->gun_info[gun_index].primaryMcuState.rotatory_switch == 0)
|
|
|
+ setChargerMode(gun_index, SYS_MODE_DEBUG);
|
|
|
+ else
|
|
|
+ setChargerMode(gun_index, SYS_MODE_IDLE);
|
|
|
}
|
|
|
|
|
|
break;
|
|
@@ -1729,9 +1728,9 @@ int main(void)
|
|
|
ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStartTransactionReq = OFF;
|
|
|
ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStopTransactionReq = OFF;
|
|
|
ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode = 0x00;
|
|
|
- ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = ShmCharger->gun_info[gun_index].primaryMcuState.rating_current;
|
|
|
ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargedDuration = 0;
|
|
|
ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargedEnergy = 0;
|
|
|
+ ShmCharger->gun_info[gun_index].targetCurrent = ShmCharger->gun_info[gun_index].primaryMcuState.rating_current;
|
|
|
}
|
|
|
|
|
|
if(((ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_FREE) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PilotState == CP_STATE_B)) ||
|
|
@@ -1741,7 +1740,6 @@ int main(void)
|
|
|
{
|
|
|
// Clean User id & Card Number
|
|
|
memset(ShmSysConfigAndInfo->SysConfig.UserId, 0x00, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.UserId));
|
|
|
- memset(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].CardNumber, 0x00, ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].CardNumber));
|
|
|
|
|
|
if((ShmCharger->gun_info[gun_index].rfidReq == ON))
|
|
|
{
|
|
@@ -1788,10 +1786,8 @@ int main(void)
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
- memcpy((char*)ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].CardNumber, ShmSysConfigAndInfo->SysConfig.UserId, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.UserId));
|
|
|
|
|
|
DEBUG_INFO("Start request User Id : %s\r\n", ShmSysConfigAndInfo->SysConfig.UserId);
|
|
|
- DEBUG_INFO("Card number : %s\r\n", ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].CardNumber);
|
|
|
}
|
|
|
else if(ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStartTransactionReq)
|
|
|
{
|
|
@@ -1864,7 +1860,7 @@ int main(void)
|
|
|
|
|
|
if(DiffTimebWithNow(startTime[gun_index][TMR_IDX_AUTH]) > TIMEOUT_SPEC_AUTH)
|
|
|
{
|
|
|
- // Authorization timeout process.
|
|
|
+ // Authorization timeout process.
|
|
|
ShmCharger->gun_info[gun_index].rfidReq = OFF;
|
|
|
setChargerMode(gun_index, SYS_MODE_IDLE);
|
|
|
DEBUG_WARN("Authorize timeout!\r\n");
|
|
@@ -1917,6 +1913,12 @@ int main(void)
|
|
|
setRelay(gun_index, ON);
|
|
|
}
|
|
|
|
|
|
+ // If control pilot detect Bx, skip watch dog time out.
|
|
|
+ if(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PilotState == CP_STATE_B)
|
|
|
+ {
|
|
|
+ ftime(&startTime[gun_index][TMR_IDX_HANDSHAKING]);
|
|
|
+ }
|
|
|
+
|
|
|
if(DiffTimebWithNow(startTime[gun_index][TMR_IDX_HANDSHAKING]) > TIMEOUT_SPEC_HANDSHAKING)
|
|
|
{
|
|
|
setLedMotion(gun_index, LED_ACTION_HANDSHAKE_FAIL);
|
|
@@ -1959,144 +1961,174 @@ int main(void)
|
|
|
(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PilotState != CP_STATE_C) ||
|
|
|
ShmOCPP16Data->MsMsg.bits.ResetReq)
|
|
|
{
|
|
|
- // If RFID SN different with start user, it need to authorize ID
|
|
|
- if((ShmCharger->gun_info[gun_index].rfidReq == ON) && !isMatchStartUser(gun_index))
|
|
|
- {
|
|
|
- ShmCharger->gun_info[gun_index].rfidReq = OFF;
|
|
|
- if(DiffTimebWithNow(startTime[gun_index][TMR_IDX_AUTH]) > TIMEOUT_SPEC_AUTH)
|
|
|
- {
|
|
|
- // 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);
|
|
|
-
|
|
|
- if(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartMethod == START_METHOD_RFID)
|
|
|
- {
|
|
|
- switch(ShmSysConfigAndInfo->SysConfig.AuthorisationMode)
|
|
|
- {
|
|
|
- case AUTH_MODE_BACKEND_OCPP:
|
|
|
- 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_FREE:
|
|
|
- default:
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- if(ShmOCPP16Data->SpMsg.bits.AuthorizeConf ||
|
|
|
- (ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_FREE) ||
|
|
|
- !ShmOCPP16Data->OcppConnStatus)
|
|
|
- {
|
|
|
- if((strcmp((char*)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted")==0) ||
|
|
|
- (ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_FREE) ||
|
|
|
- (!ShmOCPP16Data->OcppConnStatus&&(ShmSysConfigAndInfo->SysConfig.OfflinePolicy == OFF_POLICY_FREE)))
|
|
|
- {
|
|
|
- ShmCharger->gun_info[gun_index].isAuthPassEnd = ON;
|
|
|
- setChargerMode(gun_index, SYS_MODE_TERMINATING);
|
|
|
- }
|
|
|
-
|
|
|
- ShmCharger->gun_info[gun_index].rfidReq = OFF;
|
|
|
- ShmOCPP16Data->SpMsg.bits.AuthorizeConf = OFF;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- setChargerMode(gun_index, SYS_MODE_TERMINATING);
|
|
|
- }
|
|
|
+ setChargerMode(gun_index, SYS_MODE_TERMINATING);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- /*
|
|
|
- * TODO:
|
|
|
- * 1. Update charging cycle information.
|
|
|
- * 2. CP PWM duty dynamic control logic.
|
|
|
- */
|
|
|
- setRelay(gun_index,ON);
|
|
|
setLedMotion(gun_index,LED_ACTION_CHARGING);
|
|
|
ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ((float)ShmCharger->gun_info[gun_index].powerConsumption.power_consumption/100.0) - ShmOCPP16Data->StartTransaction[gun_index].MeterStart;
|
|
|
ftime(&endChargingTime[gun_index]);
|
|
|
- ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargedDuration = DiffTimeb(startChargingTime[gun_index], endChargingTime[gun_index]);
|
|
|
+ ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargedDuration = DiffTimeb(startChargingTime[gun_index], endChargingTime[gun_index])/1000;
|
|
|
ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargedEnergy = (ShmCharger->gun_info[gun_index].powerConsumption.power_consumption - ShmOCPP16Data->StartTransaction[gun_index].MeterStart)/100.0;
|
|
|
ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].OutputEnergy = (ShmCharger->gun_info[gun_index].powerConsumption.power_consumption - ShmOCPP16Data->StartTransaction[gun_index].MeterStart)/100.0;
|
|
|
- // Charging profile
|
|
|
|
|
|
+ /*
|
|
|
+ * TODO:
|
|
|
+ * 1. Query target current from charging profile
|
|
|
+ */
|
|
|
+ // Checking charging profile target current
|
|
|
+
|
|
|
+ // Determine max charging current to MCU
|
|
|
+ if(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent == 0)
|
|
|
+ {
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+
|
|
|
+ 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);
|
|
|
+
|
|
|
+ if((ShmSysConfigAndInfo->SysConfig.MaxChargingDuration > 0) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargedDuration >= (ShmSysConfigAndInfo->SysConfig.MaxChargingDuration*60)) )
|
|
|
+ {
|
|
|
+ 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 >= (ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy/10.0)))
|
|
|
+ {
|
|
|
+ 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, (ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy/10.0));
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ setRelay(gun_index, ON);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
break;
|
|
|
case SYS_MODE_TERMINATING:
|
|
|
if(isModeChange(gun_index))
|
|
|
{
|
|
|
- setLedMotion(gun_index,LED_ACTION_STOP);
|
|
|
if(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargedDuration != 0)
|
|
|
{
|
|
|
- ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargedDuration = DiffTimeb(startChargingTime[gun_index], endChargingTime[gun_index]);
|
|
|
+ ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargedDuration = DiffTimeb(startChargingTime[gun_index], endChargingTime[gun_index])/1000;
|
|
|
+ }
|
|
|
+
|
|
|
+ setLedMotion(gun_index, LED_ACTION_STOP);
|
|
|
+ setRelay(gun_index, OFF);
|
|
|
+ getDateTimeString((char*)ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StopDateTime);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 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);
|
|
|
+
|
|
|
+ if(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartMethod == START_METHOD_RFID)
|
|
|
+ {
|
|
|
+ switch(ShmSysConfigAndInfo->SysConfig.AuthorisationMode)
|
|
|
+ {
|
|
|
+ case AUTH_MODE_BACKEND_OCPP:
|
|
|
+ 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_FREE:
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if(ShmOCPP16Data->SpMsg.bits.AuthorizeConf ||
|
|
|
+ (ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_FREE) ||
|
|
|
+ !ShmOCPP16Data->OcppConnStatus)
|
|
|
+ {
|
|
|
+ if((strcmp((char*)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted")==0) ||
|
|
|
+ (ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_FREE) ||
|
|
|
+ (!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.AuthorizeConf = OFF;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ // End authorize pass
|
|
|
if(((ShmCharger->gun_info[gun_index].rfidReq == ON) && isMatchStartUser(gun_index)) ||
|
|
|
(ShmCharger->gun_info[gun_index].isAuthPassEnd) ||
|
|
|
(ShmCharger->gun_info[gun_index].bleConfigData.isRequestStop == ON) ||
|
|
@@ -2104,14 +2136,11 @@ int main(void)
|
|
|
(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PilotState == CP_STATE_A) ||
|
|
|
ShmOCPP16Data->MsMsg.bits.ResetReq)
|
|
|
{
|
|
|
- /*
|
|
|
- * TODO:
|
|
|
- * 1. Record charging history.
|
|
|
- */
|
|
|
- if(ShmCharger->gun_info[gun_index].legacyRequest.isLegacyRequest == ON)
|
|
|
- {
|
|
|
- setSpeaker(ON,SPEAKER_SHORT);
|
|
|
+ setSpeaker(ON,SPEAKER_SHORT);
|
|
|
+ sleep(5);
|
|
|
|
|
|
+ if(!ShmCharger->gun_info[gun_index].primaryMcuState.relay_state)
|
|
|
+ {
|
|
|
if(ShmOCPP16Data->MsMsg.bits.ResetReq)
|
|
|
{
|
|
|
if(strcmp((char*)ShmOCPP16Data->Reset.Type, "Hard")==0)
|
|
@@ -2140,13 +2169,6 @@ int main(void)
|
|
|
ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmCharger->gun_info[gun_index].powerConsumption.power_consumption;
|
|
|
ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = ON;
|
|
|
|
|
|
- getDateTimeString((char*)ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StopDateTime);
|
|
|
- }
|
|
|
-
|
|
|
- setRelay(gun_index,OFF);
|
|
|
-
|
|
|
- if(!ShmCharger->gun_info[gun_index].primaryMcuState.relay_state)
|
|
|
- {
|
|
|
ShmCharger->gun_info[gun_index].rfidReq = OFF;
|
|
|
ShmCharger->gun_info[gun_index].isAuthPassEnd = OFF;
|
|
|
ShmCharger->gun_info[gun_index].bleConfigData.isRequestStop = OFF;
|
|
@@ -2158,13 +2180,16 @@ int main(void)
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- if((ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PilotState == CP_STATE_C))
|
|
|
- {
|
|
|
- setChargerMode(gun_index, SYS_MODE_CHARGING);
|
|
|
- }
|
|
|
+ if((ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PilotState == CP_STATE_C) &&
|
|
|
+ (ShmCharger->gun_info[gun_index].bleConfigData.isRequestStop != ON) &&
|
|
|
+ (ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStopTransactionReq != ON) &&
|
|
|
+ !ShmOCPP16Data->MsMsg.bits.ResetReq &&
|
|
|
+ !((ShmSysConfigAndInfo->SysConfig.MaxChargingDuration > 0) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargedDuration >= (ShmSysConfigAndInfo->SysConfig.MaxChargingDuration*60))) &&
|
|
|
+ !((ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy > 0) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargedEnergy >= (ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy/10.0))))
|
|
|
+ {
|
|
|
+ setChargerMode(gun_index, SYS_MODE_CHARGING);
|
|
|
+ }
|
|
|
}
|
|
|
-
|
|
|
- setLedMotion(gun_index,LED_ACTION_STOP);
|
|
|
break;
|
|
|
case SYS_MODE_ALARM:
|
|
|
if((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode == 0))
|
|
@@ -2204,6 +2229,13 @@ int main(void)
|
|
|
setLedMotion(gun_index,LED_ACTION_MAINTAIN);
|
|
|
}
|
|
|
|
|
|
+ break;
|
|
|
+ case SYS_MODE_UPDATE:
|
|
|
+ if(isModeChange(gun_index))
|
|
|
+ {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
//======================================
|
|
|
// Check local upgrade firmware request
|
|
|
//======================================
|
|
@@ -2286,8 +2318,14 @@ int main(void)
|
|
|
setLedMotion(gun_index,LED_ACTION_MAINTAIN);
|
|
|
}
|
|
|
|
|
|
- if(isReservationExpired(gun_index) || ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationReq)
|
|
|
+ if(isReservationExpired(gun_index))
|
|
|
+ {
|
|
|
+ DEBUG_INFO("Reservation: Time's up...\r\n");
|
|
|
+ setChargerMode(gun_index, SYS_MODE_IDLE);
|
|
|
+ }
|
|
|
+ else if(ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationReq)
|
|
|
{
|
|
|
+ DEBUG_INFO("Reservation: Cancel reservation...\r\n");
|
|
|
setChargerMode(gun_index, SYS_MODE_IDLE);
|
|
|
|
|
|
ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationReq = OFF;
|
|
@@ -2308,17 +2346,15 @@ int main(void)
|
|
|
case SYS_MODE_DEBUG:
|
|
|
if(isModeChange(gun_index))
|
|
|
{
|
|
|
- /*
|
|
|
- * TODO:
|
|
|
- * 1. LED control depend on relay status
|
|
|
- */
|
|
|
+ setLedMotion(gun_index,LED_ACTION_DEBUG);
|
|
|
}
|
|
|
-
|
|
|
- setLedMotion(gun_index,LED_ACTION_DEBUG);
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ // System watch dog reset
|
|
|
+ write(wtdFd, "a", 1);
|
|
|
+
|
|
|
usleep(50000);
|
|
|
}
|
|
|
|