|
@@ -118,7 +118,7 @@
|
|
|
char *valid_Internet[2] = {"8.8.8.8", "180.76.76.76"};
|
|
|
unsigned char mask_table[] = { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 };
|
|
|
int whileLoopTime = 10000; // 10 ms
|
|
|
-int wtdFd = -1;
|
|
|
+int wtdFd = -1;
|
|
|
byte _authorizeIndex = NO_DEFINE;
|
|
|
BOOL _UpgradeNeedReboot = FALSE;
|
|
|
|
|
@@ -195,6 +195,9 @@ bool IsConnectorWholeIdle();
|
|
|
void SetAcContactor(unsigned char OnOff);
|
|
|
void UpdateErrorCodeToOcpp(byte index);
|
|
|
bool CheckConnectorTypeStatus(void);
|
|
|
+void CreateWatchdog(void);
|
|
|
+void TryCloseWatchdog(void);
|
|
|
+void TryFeedWatchdog(void);
|
|
|
|
|
|
struct SysConfigAndInfo *ShmSysConfigAndInfo;
|
|
|
struct StatusCodeData *ShmStatusCodeData;
|
|
@@ -207,6 +210,8 @@ struct FanModuleData *ShmFanModuleData;
|
|
|
struct RelayModuleData *ShmRelayModuleData[2];
|
|
|
struct LedModuleData *ShmLedModuleData;
|
|
|
struct OCPP16Data *ShmOCPP16Data;
|
|
|
+struct OCPP20Data *ShmOCPP20Data;
|
|
|
+struct MeterInformation *ShmCsuMeterData;
|
|
|
ChargerInfoData *ShmChargerInfo;
|
|
|
PsuPositionInfoData *ShmPsuPosition;
|
|
|
PsuGroupingInfoData *ShmPsuGrouping;
|
|
@@ -226,6 +231,12 @@ struct timespec _SystemStatus_Time[CONNECTOR_QUANTITY];
|
|
|
|
|
|
unsigned char _PsuGroupAvailable[CONNECTOR_QUANTITY];
|
|
|
|
|
|
+float gunOutputVol[CONNECTOR_QUANTITY];
|
|
|
+unsigned char _ocppProfileChkFlag[CONNECTOR_QUANTITY];
|
|
|
+float _lastProfilePower[CONNECTOR_QUANTITY];
|
|
|
+float _lastProfileCurrent[CONNECTOR_QUANTITY];
|
|
|
+float _lastMaxProfilePower;
|
|
|
+
|
|
|
bool _NeedReset4gWifi;
|
|
|
struct timespec _4gWifiReset_time;
|
|
|
|
|
@@ -246,7 +257,7 @@ bool isModelNameMatch = true;
|
|
|
|
|
|
//int rfidFd = -1;
|
|
|
//char* rfidPortName = "/dev/ttyS2";
|
|
|
-char* fwVersion = "V1.02.00.0000.00";
|
|
|
+char* fwVersion = "V1.03.00.0000.00";
|
|
|
|
|
|
sqlite3 *localDb;
|
|
|
bool isDb_ready;
|
|
@@ -347,6 +358,8 @@ void substr(char *dest, const char* src, unsigned int start, unsigned int cnt)
|
|
|
int InitWatchDog()
|
|
|
{
|
|
|
int fd;
|
|
|
+ int timeout = 180;
|
|
|
+
|
|
|
system("/usr/bin/fuser -k /dev/watchdog");
|
|
|
sleep(1);
|
|
|
system("echo V > /dev/watchdog");
|
|
@@ -357,6 +370,8 @@ int InitWatchDog()
|
|
|
{
|
|
|
LOG_ERROR("System watch dog initial fail.\r\n");
|
|
|
}
|
|
|
+ ioctl(fd, _IOWR('W', 6, int), &timeout);
|
|
|
+
|
|
|
return fd;
|
|
|
}
|
|
|
|
|
@@ -693,7 +708,18 @@ int CreateShareMemory()
|
|
|
}
|
|
|
memset(ShmOCPP16Data,0,sizeof(struct OCPP16Data));
|
|
|
|
|
|
- //creat ShmOCPP16Data
|
|
|
+ if ((MeterSMId = shmget(ShmOcpp20ModuleKey, sizeof(struct OCPP20Data), IPC_CREAT | 0777)) < 0)
|
|
|
+ {
|
|
|
+ LOG_ERROR("[main]CreatShareMemory:shmget OCPP20Data NG\n");
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ else if ((ShmOCPP20Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
|
|
|
+ {
|
|
|
+ LOG_ERROR("[main]CreatShareMemory:shmat OCPP20Data NG\n");
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ memset(ShmOCPP20Data,0,sizeof(struct OCPP20Data));
|
|
|
+
|
|
|
if ((MeterSMId = shmget(SM_ChargerInfoKey, sizeof(ChargerInfoData), IPC_CREAT | 0777)) < 0)
|
|
|
{
|
|
|
#ifdef SystemLogMessage
|
|
@@ -1452,6 +1478,7 @@ void InitEthernet()
|
|
|
ShmSysConfigAndInfo->SysInfo.CabinetMicsStatus.EthernetStatus = _Connnection_Disconnected;
|
|
|
ShmSysConfigAndInfo->SysInfo.CabinetMicsStatus.WiFiStatus = _Connnection_Disable;
|
|
|
ShmSysConfigAndInfo->SysInfo.CabinetMicsStatus.TelcomModemStatus = _Connnection_Disable;
|
|
|
+ LOG_INFO("Internet Fork PID = %d", getpid());
|
|
|
|
|
|
for(;;)
|
|
|
{
|
|
@@ -1803,6 +1830,7 @@ void InitialShareMemoryInfo()
|
|
|
ShmSysConfigAndInfo->SysInfo.InternetConn = 0;
|
|
|
ShmSysConfigAndInfo->SysInfo.OcppConnStatus = 0;
|
|
|
ShmSysConfigAndInfo->SysInfo.OrderCharging = NO_DEFINE;
|
|
|
+ ShmSysConfigAndInfo->SysInfo.MaxChargingProfilePower = -1;
|
|
|
|
|
|
strcpy((char *) ShmSysConfigAndInfo->SysConfig.UserId, "");
|
|
|
|
|
@@ -1924,7 +1952,7 @@ void InitialPsuGroupingAndLocation(void)
|
|
|
|
|
|
void InitialMaxDispenserConnectorQuantity(void)
|
|
|
{
|
|
|
- if(ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'D' && ShmSysConfigAndInfo->SysConfig.ModelName[1] == 'K')
|
|
|
+ if(ShmChargerInfo->Control.SysCtrl.bits.SecondRelayBoardEnable == false)
|
|
|
{
|
|
|
ShmChargerInfo->Control.MaxDispenser = 2;
|
|
|
ShmChargerInfo->Control.MaxConnector = 2;
|
|
@@ -1995,6 +2023,15 @@ bool InitialChargerSetting(void)
|
|
|
|
|
|
ShmChargerInfo->Control.SysCtrl.bits.E4YOULedIndication = true;
|
|
|
}
|
|
|
+ else if(ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'D' && ShmSysConfigAndInfo->SysConfig.ModelName[1] == 'B')
|
|
|
+ {
|
|
|
+ ShmChargerInfo->Control.SysCtrl.bits.FanBoardDisable = true;
|
|
|
+ ShmChargerInfo->Control.SysCtrl.bits.LedBoardDisable = true;
|
|
|
+
|
|
|
+ ShmChargerInfo->Control.SysCtrl.bits.E4YOULedIndication = true;
|
|
|
+ ShmChargerInfo->Control.RelayCtrl.bits.AcInputDisable = true;
|
|
|
+ ShmChargerInfo->Control.RelayCtrl.bits.DcInputEnable = true;
|
|
|
+ }
|
|
|
else
|
|
|
{
|
|
|
result = false;
|
|
@@ -2800,7 +2837,7 @@ void ReleaseEmsOccureByString(byte index, char *code)
|
|
|
if (isTrigger)
|
|
|
{
|
|
|
ReleaseChargingProcessByString(level);
|
|
|
- InformOcppErrOccur(6);
|
|
|
+ //InformOcppErrOccur(6);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -3899,7 +3936,7 @@ bool CheckConnectorTypeStatus(void)
|
|
|
for(int i = 0; i < CONNECTOR_QUANTITY; i++)
|
|
|
{
|
|
|
chargingInfo[i] = &ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].GeneralChargingData;
|
|
|
- chargingInfo[i]->Index = 0xFF;
|
|
|
+ chargingInfo[i]->Index = (i < ShmSysConfigAndInfo->SysConfig.WiringInfo.MaxConnectorQuantity || i == 0) ? i : 0xFF;
|
|
|
chargingInfo[i]->Evboard_id = 0x00;
|
|
|
chargingInfo[i]->ReservationId = -1;
|
|
|
chargingInfo[i]->slotsIndex = 0;
|
|
@@ -4421,10 +4458,11 @@ void CreateTimeoutFork()
|
|
|
pid_t timeoutPid;
|
|
|
|
|
|
timeoutPid = fork();
|
|
|
- if (timeoutPid > 0)
|
|
|
+ if (timeoutPid == 0)
|
|
|
{
|
|
|
GetClockTime(&_cmdSubPriority_time);
|
|
|
CheckConnectionTimeout();
|
|
|
+ LOG_INFO("Timeout Fork PID = %d", getpid());
|
|
|
|
|
|
while(true)
|
|
|
{
|
|
@@ -4575,6 +4613,8 @@ void CheckFwUpdateFunction()
|
|
|
if (ShmSysConfigAndInfo->SysInfo.FirmwareUpdate == YES)
|
|
|
{
|
|
|
LOG_INFO("ftp : update start.");
|
|
|
+ TryCloseWatchdog();
|
|
|
+
|
|
|
//KillTask();
|
|
|
ChangeLcmByIndex(_LCM_FIX);
|
|
|
system("killall Module_PrimaryComm");
|
|
@@ -4609,6 +4649,8 @@ void CheckFwUpdateFunction()
|
|
|
if (strcmp((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "Downloaded") == EQUAL)
|
|
|
{
|
|
|
LOG_INFO("Backend : update start.");
|
|
|
+ TryCloseWatchdog();
|
|
|
+
|
|
|
strcpy((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "");
|
|
|
strcpy((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "Installing");
|
|
|
ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = YES;
|
|
@@ -4721,6 +4763,7 @@ void CheckSoftHardReset(void)
|
|
|
sleep(5);
|
|
|
system("killall OcppBackend &");
|
|
|
KillAllTask();
|
|
|
+ TryCloseWatchdog();
|
|
|
system("/usr/bin/run_evse_restart.sh");
|
|
|
|
|
|
}
|
|
@@ -5138,6 +5181,7 @@ void CheckOcppStatus()
|
|
|
sleep(3);
|
|
|
system("killall OcppBackend &");
|
|
|
KillAllTask();
|
|
|
+ TryCloseWatchdog();
|
|
|
system("/usr/bin/run_evse_restart.sh");
|
|
|
}
|
|
|
}
|
|
@@ -5156,6 +5200,7 @@ void OcppStartTransation(byte gunIndex)
|
|
|
|
|
|
LOG_INFO("Gun index %d, OCPP Start Transation Index %d, IdTag = %s, StartSoc = %d",
|
|
|
chargingInfo[gunIndex]->Index, _OcppGunIndex, ShmOCPP16Data->StartTransaction[_OcppGunIndex].IdTag, chargingInfo[gunIndex]->EvBatteryStartSoc);
|
|
|
+ ShmOCPP16Data->CpMsg.bits[_OcppGunIndex].StartTransactionConf = NO;
|
|
|
ShmOCPP16Data->CpMsg.bits[_OcppGunIndex].StartTransactionReq = YES;
|
|
|
}
|
|
|
|
|
@@ -5743,6 +5788,7 @@ void StopProcessingLoop()
|
|
|
LOG_INFO("Soft reboot for retry self-tets (Primary).");
|
|
|
KillAllTask();
|
|
|
sleep(3);
|
|
|
+ TryCloseWatchdog();
|
|
|
system("/usr/bin/run_evse_restart.sh");
|
|
|
return;
|
|
|
}
|
|
@@ -5766,15 +5812,36 @@ void StopProcessingLoop()
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-void CreateWatchdog()
|
|
|
+void CreateWatchdog(void)
|
|
|
{
|
|
|
- if (ShmSysConfigAndInfo->SysConfig.SwitchDebugFlag == NO)
|
|
|
- {
|
|
|
- wtdFd = InitWatchDog();
|
|
|
+ wtdFd = InitWatchDog();
|
|
|
|
|
|
- if (wtdFd < 0)
|
|
|
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed = 1;
|
|
|
- }
|
|
|
+ if(wtdFd < 0)
|
|
|
+ {
|
|
|
+ LOG_INFO("Watchdog Initial Fail");
|
|
|
+ ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed = 1;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ LOG_INFO("Watchdog Initial Success");
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+void TryCloseWatchdog(void)
|
|
|
+{
|
|
|
+ if(wtdFd > 0)
|
|
|
+ {
|
|
|
+ write(wtdFd, "V", 1);
|
|
|
+ close(wtdFd);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+void TryFeedWatchdog(void)
|
|
|
+{
|
|
|
+ if(wtdFd > 0)
|
|
|
+ {
|
|
|
+ write(wtdFd, "a", 1);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
bool IsConnectorWholeIdle()
|
|
@@ -5870,8 +5937,9 @@ void CheckTask()
|
|
|
|
|
|
if(system("pidof -s Module_InternalComm > /dev/null") != 0)
|
|
|
{
|
|
|
- LOG_ERROR("Module_InternalComm not running, System Restart.");
|
|
|
- ShmChargerInfo->Control.SysCtrl.bits.NeedSoftReset = true;
|
|
|
+ LOG_ERROR("Module_InternalComm not running, restart it.");
|
|
|
+ system ("/root/Module_InternalComm &");
|
|
|
+ //ShmChargerInfo->Control.SysCtrl.bits.NeedSoftReset = true;
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -5907,6 +5975,34 @@ void StartDispenserDhcpServer(void)
|
|
|
//==========================================
|
|
|
// Check Smart Charging Profile
|
|
|
//==========================================
|
|
|
+void Ocpp_ProfileReq_Cmd(byte gunIndex)
|
|
|
+{
|
|
|
+ if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
|
|
|
+ {
|
|
|
+ if(ShmOCPP16Data->CSUMsg.bits[gunIndex].ChargingProfileConf == NO)
|
|
|
+ {
|
|
|
+ if(ShmOCPP16Data->CSUMsg.bits[gunIndex].ChargingProfileReq == NO)
|
|
|
+ {
|
|
|
+ ShmOCPP16Data->CSUMsg.bits[gunIndex].ChargingProfileReq = YES;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+bool Ocpp_Chk_ProfileConf_Cmd(byte gunIndex)
|
|
|
+{
|
|
|
+ if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
|
|
|
+ {
|
|
|
+ if (ShmOCPP16Data->CSUMsg.bits[gunIndex].ChargingProfileConf == YES)
|
|
|
+ {
|
|
|
+ ShmOCPP16Data->CSUMsg.bits[gunIndex].ChargingProfileConf = NO;
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return false;
|
|
|
+}
|
|
|
+
|
|
|
int GetStartScheduleTime(unsigned char *time)
|
|
|
{
|
|
|
int result = -1;
|
|
@@ -5926,68 +6022,171 @@ int GetStartScheduleTime(unsigned char *time)
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
-void CheckSmartChargeProfile(byte _index)
|
|
|
+void Ocpp_ChargingProfile_Process(byte _index)
|
|
|
{
|
|
|
- if (ShmOCPP16Data->CSUMsg.bits[_index].ChargingProfileConf == NO)
|
|
|
- {
|
|
|
- if (ShmOCPP16Data->CSUMsg.bits[_index].ChargingProfileReq == NO)
|
|
|
- ShmOCPP16Data->CSUMsg.bits[_index].ChargingProfileReq = YES;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- // Get Charging Profile
|
|
|
- ShmOCPP16Data->CSUMsg.bits[_index].ChargingProfileConf = NO;
|
|
|
- if (strcmp((char *)ShmOCPP16Data->SmartChargingProfile[_index].ChargingProfileKind, "Absolute") == EQUAL)
|
|
|
- {
|
|
|
- int _time = GetStartScheduleTime(ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.StartSchedule);
|
|
|
- byte _startCount = NO_DEFINE;
|
|
|
- byte _maxCount = ARRAY_SIZE(ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod);
|
|
|
+ int _time = 0;
|
|
|
+ int _startCount = NO_DEFINE;
|
|
|
+ int _maxCount = 0;
|
|
|
|
|
|
- for (byte _count = 0; _count < _maxCount; _count++)
|
|
|
- {
|
|
|
- // 預設最小輸出電流 (MIN_OUTPUT_CUR) A
|
|
|
- if (_time >= ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[_count].StartPeriod &&
|
|
|
- ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[_count].Limit > MIN_OUTPUT_CUR)
|
|
|
- {
|
|
|
- _startCount = _count;
|
|
|
- }
|
|
|
- }
|
|
|
+ if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
|
|
|
+ {
|
|
|
+ if (strcmp((char *)ShmOCPP16Data->SmartChargingProfile[_index].ChargingProfileKind, "Absolute") == EQUAL &&
|
|
|
+ ShmOCPP16Data->SmartChargingProfile[_index].ChargingProfileId == YES)
|
|
|
+ {
|
|
|
+ _time = GetStartScheduleTime(ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.StartSchedule);
|
|
|
+ _maxCount = ARRAY_SIZE(ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod);
|
|
|
+ _startCount = NO_DEFINE;
|
|
|
|
|
|
- LOG_INFO("_startCount = %d", _startCount);
|
|
|
- if (_startCount < _maxCount)
|
|
|
- {
|
|
|
- LOG_INFO("*********Limit = %f ", ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[_startCount].Limit);
|
|
|
- chargingInfo[_index]->ChargingProfileCurrent = ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[_startCount].Limit * 10;
|
|
|
- chargingInfo[_index]->ChargingProfilePower = ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[_startCount].Limit * chargingInfo[_index]->EvBatterytargetVoltage / 100;
|
|
|
+ for (byte _count = 0; _count < _maxCount; _count++)
|
|
|
+ {
|
|
|
+ // 預設最小輸出電流 (MIN_OUTPUT_CUR) A
|
|
|
+ if (_time >= ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[_count].StartPeriod)
|
|
|
+ {
|
|
|
+ if ((_count == 0 && ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[_count].Limit >= MIN_OUTPUT_CUR) ||
|
|
|
+ ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[_count].Limit > MIN_OUTPUT_CUR)
|
|
|
+ {
|
|
|
+ _startCount = _count;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- //chargingInfo[_index]->ChargingProfilePower = ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[_startCount].Limit * AC_OUTPUT_VOL;
|
|
|
-// if ((chargingInfo[_index]->EvBatterytargetVoltage * 10) > 0)
|
|
|
-// {
|
|
|
-// chargingInfo[_index]->ChargingProfileCurrent = chargingInfo[_index]->ChargingProfilePower / (chargingInfo[_index]->EvBatterytargetVoltage * 10);
|
|
|
-// }
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- chargingInfo[_index]->ChargingProfilePower = -1;
|
|
|
- chargingInfo[_index]->ChargingProfileCurrent = -1;
|
|
|
- }
|
|
|
+ if (_startCount < _maxCount)
|
|
|
+ {
|
|
|
+ chargingInfo[_index]->ChargingProfilePower = ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[_startCount].Limit * AC_OUTPUT_VOL * ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[_startCount].NumberPhases;
|
|
|
+ if (chargingInfo[_index]->EvBatterytargetVoltage > 0 &&
|
|
|
+ (int)chargingInfo[_index]->PresentChargingVoltage > 0)
|
|
|
+ {
|
|
|
+ chargingInfo[_index]->ChargingProfileCurrent = (chargingInfo[_index]->ChargingProfilePower / chargingInfo[_index]->PresentChargingVoltage) * 10;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ chargingInfo[_index]->ChargingProfileCurrent = -1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ chargingInfo[_index]->ChargingProfilePower = -1;
|
|
|
+ chargingInfo[_index]->ChargingProfileCurrent = -1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ chargingInfo[_index]->ChargingProfilePower = -1;
|
|
|
+ chargingInfo[_index]->ChargingProfileCurrent = -1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ chargingInfo[_index]->ChargingProfilePower = -1;
|
|
|
+ chargingInfo[_index]->ChargingProfileCurrent = -1;
|
|
|
+ }
|
|
|
|
|
|
- LOG_INFO("ChargingProfilePower = %f", chargingInfo[_index]->ChargingProfilePower);
|
|
|
- LOG_INFO("ChargingProfileCurrent = %f", chargingInfo[_index]->ChargingProfileCurrent);
|
|
|
- }
|
|
|
-//
|
|
|
-// printf("-------------Schedule------------\n");
|
|
|
-// printf("index = %d \n", _index);
|
|
|
-// printf("StartSchedule = %s \n", ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.StartSchedule);
|
|
|
-// printf("ChargingRateUnit = %s \n", ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingRateUnit);
|
|
|
-// printf("----------SchedulePeriod---------\n");
|
|
|
-// for (int v = 0; v < 10; v++)
|
|
|
-// {
|
|
|
-// printf("StartPeriod = %d \n", ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[v].StartPeriod);
|
|
|
-// printf("Limit = %f \n", ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[v].Limit);
|
|
|
-// }
|
|
|
-// printf("---------------------------------\n");
|
|
|
- }
|
|
|
+ if((int)_lastProfilePower[_index] != (int)chargingInfo[_index]->ChargingProfilePower ||
|
|
|
+ (int)_lastProfileCurrent[_index] != (int)chargingInfo[_index]->ChargingProfileCurrent)
|
|
|
+ {
|
|
|
+ LOG_INFO("Gun %d Get Profile - Index = %d, Limit = %f",
|
|
|
+ _index + 1, _startCount,
|
|
|
+ ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[_startCount].Limit);
|
|
|
+ LOG_INFO("Max: %d kW, Gun %d ChargingProfile Power = %d, Current = %d",
|
|
|
+ ShmSysConfigAndInfo->SysInfo.MaxChargingProfilePower == -1 ? (int)ShmSysConfigAndInfo->SysInfo.MaxChargingProfilePower : ((int)ShmSysConfigAndInfo->SysInfo.MaxChargingProfilePower / 1000),
|
|
|
+ _index + 1, (int)chargingInfo[_index]->ChargingProfilePower, (int)chargingInfo[_index]->ChargingProfileCurrent);
|
|
|
+ }
|
|
|
+ _lastProfilePower[_index] = chargingInfo[_index]->ChargingProfilePower;
|
|
|
+ _lastProfileCurrent[_index] = chargingInfo[_index]->ChargingProfileCurrent;
|
|
|
+}
|
|
|
+
|
|
|
+void Ocpp_MaxChargingProfile_Process(void)
|
|
|
+{
|
|
|
+ int _time = 0;
|
|
|
+ int _startCount = NO_DEFINE;
|
|
|
+ int _maxCount = 0;
|
|
|
+
|
|
|
+ if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
|
|
|
+ {
|
|
|
+ if (strcmp((char *)ShmOCPP16Data->MaxChargingProfile.ChargingProfileKind, "Absolute") == EQUAL &&
|
|
|
+ ShmOCPP16Data->MaxChargingProfile.ChargingProfileId == YES)
|
|
|
+ {
|
|
|
+ _time = GetStartScheduleTime(ShmOCPP16Data->MaxChargingProfile.ChargingSchedule.StartSchedule);
|
|
|
+ _maxCount = ARRAY_SIZE(ShmOCPP16Data->MaxChargingProfile.ChargingSchedule.ChargingSchedulePeriod);
|
|
|
+ _startCount = NO_DEFINE;
|
|
|
+
|
|
|
+ for (byte _count = 0; _count < _maxCount; _count++)
|
|
|
+ {
|
|
|
+ // 預設最小輸出電流 (MIN_OUTPUT_CUR) A
|
|
|
+ if (_time >= ShmOCPP16Data->MaxChargingProfile.ChargingSchedule.ChargingSchedulePeriod[_count].StartPeriod)
|
|
|
+ {
|
|
|
+ if ((_count == 0 && ShmOCPP16Data->MaxChargingProfile.ChargingSchedule.ChargingSchedulePeriod[_count].Limit >= MIN_OUTPUT_CUR) ||
|
|
|
+ ShmOCPP16Data->MaxChargingProfile.ChargingSchedule.ChargingSchedulePeriod[_count].Limit > MIN_OUTPUT_CUR)
|
|
|
+ {
|
|
|
+ _startCount = _count;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if(_startCount < _maxCount)
|
|
|
+ {
|
|
|
+ ShmSysConfigAndInfo->SysInfo.MaxChargingProfilePower = ShmOCPP16Data->MaxChargingProfile.ChargingSchedule.ChargingSchedulePeriod[_startCount].Limit * AC_OUTPUT_VOL * ShmOCPP16Data->MaxChargingProfile.ChargingSchedule.ChargingSchedulePeriod[_startCount].NumberPhases;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ ShmSysConfigAndInfo->SysInfo.MaxChargingProfilePower = -1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ ShmSysConfigAndInfo->SysInfo.MaxChargingProfilePower = -1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ ShmSysConfigAndInfo->SysInfo.MaxChargingProfilePower = -1;
|
|
|
+ }
|
|
|
+
|
|
|
+ if((int)_lastMaxProfilePower != (int)ShmSysConfigAndInfo->SysInfo.MaxChargingProfilePower)
|
|
|
+ {
|
|
|
+ LOG_INFO("Charger Get Max Profile - Index = %d, Limit = %f",
|
|
|
+ _startCount, ShmOCPP16Data->MaxChargingProfile.ChargingSchedule.ChargingSchedulePeriod[_startCount].Limit);
|
|
|
+ LOG_INFO("Charger Max Profile Power = %d", (int)ShmSysConfigAndInfo->SysInfo.MaxChargingProfilePower);
|
|
|
+ }
|
|
|
+ _lastMaxProfilePower = ShmSysConfigAndInfo->SysInfo.MaxChargingProfilePower;
|
|
|
+}
|
|
|
+
|
|
|
+void CheckSmartChargeProfile(byte _index)
|
|
|
+{
|
|
|
+ if(Ocpp_Chk_ProfileConf_Cmd(_index))
|
|
|
+ {
|
|
|
+ Ocpp_MaxChargingProfile_Process();
|
|
|
+ Ocpp_ChargingProfile_Process(_index);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+bool Ocpp_CheckInvalidId(byte _index)
|
|
|
+{
|
|
|
+ bool invalid = false;
|
|
|
+
|
|
|
+ if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
|
|
|
+ {
|
|
|
+ if(strstr((char *) ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "TRUE"))
|
|
|
+ {
|
|
|
+ if(strcmp((char *)ShmOCPP16Data->StartTransaction[_index].ResponseIdTagInfo.Status, "Blocked") == EQUAL ||
|
|
|
+ strcmp((char *)ShmOCPP16Data->StartTransaction[_index].ResponseIdTagInfo.Status, "Expired") == EQUAL ||
|
|
|
+ strcmp((char *)ShmOCPP16Data->StartTransaction[_index].ResponseIdTagInfo.Status, "Invalid") == EQUAL)
|
|
|
+ {
|
|
|
+ invalid = true;
|
|
|
+ LOG_INFO("Gun %d Stop Transaction On Invalid Id", _index + 1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if(strcmp((char *)ShmOCPP16Data->StartTransaction[_index].ResponseIdTagInfo.Status, "Accepted") != EQUAL)
|
|
|
+ {
|
|
|
+ invalid = true;
|
|
|
+ LOG_INFO("Gun %d Start Transaction Not Accepted", _index + 1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return invalid;
|
|
|
}
|
|
|
|
|
|
void TheEndCharging(byte gun_index)
|
|
@@ -6078,6 +6277,10 @@ void CheckDispenserVersionUpdateRequirement(void)
|
|
|
|
|
|
}
|
|
|
|
|
|
+void ChargerBootingProcess(void)
|
|
|
+{
|
|
|
+
|
|
|
+}
|
|
|
|
|
|
// connector: connector infex, 0 ~ 3
|
|
|
void SetLedIndicationStatus(unsigned char connector, unsigned char indication)
|
|
@@ -6277,6 +6480,7 @@ void CreateLedIndicationFork(void)
|
|
|
pid = fork();
|
|
|
if(pid == 0)
|
|
|
{
|
|
|
+ LOG_INFO("Led Indication Fork PID = %d", getpid());
|
|
|
while(1)
|
|
|
{
|
|
|
LedIndicationProcess();
|
|
@@ -6360,7 +6564,7 @@ bool IsConnectorGroupingCompleted(unsigned char connector)
|
|
|
|
|
|
int main(void)
|
|
|
{
|
|
|
- int time = 0;
|
|
|
+ unsigned long time = 0;
|
|
|
|
|
|
if(CreateShareMemory() == 0)
|
|
|
{
|
|
@@ -6378,6 +6582,7 @@ int main(void)
|
|
|
}
|
|
|
LOG_INFO("\n");
|
|
|
LOG_INFO("===== Boot and Initialization start =====");
|
|
|
+ LOG_INFO("Main Fork PID = %d", getpid());
|
|
|
|
|
|
if (!InitialSystemDefaultConfig())
|
|
|
{
|
|
@@ -6490,6 +6695,7 @@ int main(void)
|
|
|
|
|
|
CreateLedIndicationFork();
|
|
|
|
|
|
+ CreateWatchdog();
|
|
|
// Main loop
|
|
|
LOG_INFO("****************************Main Loop********************************** \n");
|
|
|
GetClockTime(&_cmdMainPriority_time);
|
|
@@ -6531,8 +6737,25 @@ int main(void)
|
|
|
CheckTask();
|
|
|
for (byte _index = 0; _index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _index++)
|
|
|
{
|
|
|
- if (chargingInfo[_index]->SystemStatus == S_CHARGING)
|
|
|
- CheckSmartChargeProfile(_index);
|
|
|
+ if((chargingInfo[_index]->SystemStatus >= S_PREPARING_FOR_EVSE && chargingInfo[_index]->SystemStatus <= S_CHARGING) ||
|
|
|
+ (chargingInfo[_index]->SystemStatus >= S_CCS_PRECHARGE_ST0 && chargingInfo[_index]->SystemStatus <= S_CCS_PRECHARGE_ST1))
|
|
|
+ {
|
|
|
+ if (chargingInfo[_index]->SystemStatus == S_CHARGING && _ocppProfileChkFlag[_index] == 12)
|
|
|
+ {
|
|
|
+ Ocpp_ProfileReq_Cmd(_index);
|
|
|
+ gunOutputVol[_index] = chargingInfo[_index]->PresentChargingVoltage;
|
|
|
+ _ocppProfileChkFlag[_index] = 0;
|
|
|
+ }
|
|
|
+ else if (chargingInfo[_index]->SystemStatus != S_CHARGING)
|
|
|
+ {
|
|
|
+ Ocpp_ProfileReq_Cmd(_index);
|
|
|
+ _ocppProfileChkFlag[_index] = 0;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ _ocppProfileChkFlag[_index]++;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
GetClockTime(&_cmdMainPriority_time);
|
|
@@ -6549,6 +6772,22 @@ int main(void)
|
|
|
CheckErrorOccurStatus(gun_index);
|
|
|
ChkOcppStatus(gun_index);
|
|
|
|
|
|
+ if((chargingInfo[gun_index]->SystemStatus >= S_PREPARING_FOR_EVSE && chargingInfo[gun_index]->SystemStatus <= S_CHARGING) ||
|
|
|
+ (chargingInfo[gun_index]->SystemStatus >= S_CCS_PRECHARGE_ST0 && chargingInfo[gun_index]->SystemStatus <= S_CCS_PRECHARGE_ST1))
|
|
|
+ {
|
|
|
+ if(chargingInfo[gun_index]->SystemStatus == S_CHARGING)
|
|
|
+ {
|
|
|
+ // 進充電後,如果輸出電壓落差大於 10V 則直接繼續看 ChargingProfile
|
|
|
+ if (chargingInfo[gun_index]->PresentChargingVoltage >= gunOutputVol[gun_index] + 10 ||
|
|
|
+ chargingInfo[gun_index]->PresentChargingVoltage <= gunOutputVol[gun_index] - 10)
|
|
|
+ {
|
|
|
+ _ocppProfileChkFlag[gun_index] = 12;
|
|
|
+ gunOutputVol[gun_index] = chargingInfo[gun_index]->PresentChargingVoltage;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ CheckSmartChargeProfile(gun_index);
|
|
|
+
|
|
|
//LOG_INFO("index = %d, ErrorCode = %s \n", gun_index, ShmOCPP16Data->StatusNotification[gun_index].ErrorCode);
|
|
|
switch(chargingInfo[gun_index]->SystemStatus)
|
|
|
{
|
|
@@ -6624,6 +6863,12 @@ int main(void)
|
|
|
chargingInfo[gun_index]->PresentChargedEnergy = 0;
|
|
|
chargingInfo[gun_index]->PresentChargingPower = 0;
|
|
|
|
|
|
+ ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].MaxTotalChargingPower = 0;
|
|
|
+ ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].MaxTotalChargingCurrent = 0;
|
|
|
+
|
|
|
+ chargingInfo[gun_index]->ChargingProfilePower = -1;
|
|
|
+ chargingInfo[gun_index]->ChargingProfileCurrent = -1;
|
|
|
+
|
|
|
// clean force charging info
|
|
|
memset(&ShmChargerInfo->Control.FCharging[gun_index], 0x00, sizeof(ForceCharging));
|
|
|
}
|
|
@@ -6837,14 +7082,12 @@ int main(void)
|
|
|
ShmSysConfigAndInfo->SysInfo.OrderCharging = NO_DEFINE;
|
|
|
//StopSystemTimeoutDet();
|
|
|
ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].Parameter.bits.PsuReleasable = false;
|
|
|
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].MaxTotalChargingCurrent = ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent * 10;
|
|
|
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].MaxTotalChargingPower = ShmSysConfigAndInfo->SysConfig.MaxChargingPower * 10;
|
|
|
ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].MaxOutputEnergy = ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy;
|
|
|
ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].MaxOutputDuration = ShmSysConfigAndInfo->SysConfig.MaxChargingDuration;
|
|
|
|
|
|
- LOG_INFO("Max Total Current %d, Max Total Power %d, Total Energy %d, Total Duration %d",
|
|
|
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].MaxTotalChargingCurrent,
|
|
|
- ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].MaxTotalChargingPower,
|
|
|
+ LOG_INFO("Max Total Current %d A, Max Total Power %d kW, Total Energy %d kWh, Total Duration %d",
|
|
|
+ ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent,
|
|
|
+ ShmSysConfigAndInfo->SysConfig.MaxChargingPower,
|
|
|
ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].MaxOutputEnergy,
|
|
|
ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].MaxOutputDuration);
|
|
|
SetAcContactor(ON);
|
|
@@ -7097,7 +7340,7 @@ int main(void)
|
|
|
chargingInfo[gun_index]->EvBatterytargetCurrent = current;
|
|
|
}
|
|
|
|
|
|
- time = GetTimeoutValue(_SystemStatus_Time[gun_index]) / uSEC_VAL;
|
|
|
+ time = GetSecTimeoutValue(_SystemStatus_Time[gun_index]);
|
|
|
|
|
|
// 計算 Power
|
|
|
//chargingInfo[gun_index]->PresentChargingPower = ((float)((chargingInfo[gun_index]->PresentChargingVoltage) * (chargingInfo[gun_index]->PresentChargingCurrent)) / 1000);
|
|
@@ -7137,18 +7380,28 @@ int main(void)
|
|
|
ChargingTerminalProcess(gun_index);
|
|
|
}
|
|
|
else if(CheckBackendChargingTimeout(gun_index) ||
|
|
|
- CheckBackendChargingEnergy(gun_index) ||
|
|
|
- (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf &&
|
|
|
- strcmp((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "Invalid") == EQUAL))
|
|
|
+ CheckBackendChargingEnergy(gun_index))
|
|
|
{
|
|
|
LOG_INFO("********** Gun %d Backend Stop (S_CHARGING) **********", gun_index + 1);
|
|
|
// 板端或後臺要求停止
|
|
|
ChargingTerminalProcess(gun_index);
|
|
|
}
|
|
|
+ else if(ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf)
|
|
|
+ {
|
|
|
+ if(Ocpp_CheckInvalidId(gun_index))
|
|
|
+ {
|
|
|
+ LOG_INFO("********** Gun %d Backend InvalidId Stop (S_CHARGING) **********", gun_index + 1);
|
|
|
+ ChargingTerminalProcess(gun_index);
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
if(ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf)
|
|
|
{
|
|
|
ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = NO;
|
|
|
+ if(strcmp((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "Accepted") == EQUAL)
|
|
|
+ {
|
|
|
+ LOG_INFO("Gun %d OCPP Start Transaction Accepted, Id = %d", gun_index + 1, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
break;
|
|
@@ -7271,7 +7524,7 @@ int main(void)
|
|
|
ChangeLcmByIndex(ShmSysConfigAndInfo->SysInfo.ConnectorPage);
|
|
|
}
|
|
|
|
|
|
- write(wtdFd, "a", 1);
|
|
|
+ TryFeedWatchdog();
|
|
|
usleep(whileLoopTime);
|
|
|
}
|
|
|
|