FolusWen 3 жил өмнө
parent
commit
6a144d9403

+ 22 - 3
EVSE/Projects/DO360/Apps/Common.c

@@ -70,14 +70,14 @@ void GetClockTime(struct timespec *_now_time)
 }
 
 // return value unit: 1us
-long GetTimeoutValue(struct timespec _start_time)
+unsigned long GetTimeoutValue(struct timespec _start_time)
 {
     struct timespec ts_end;
-    long ret = 0;
+    unsigned long ret = 0;
 
     clock_gettime(CLOCK_MONOTONIC, &ts_end);
 
-    ret = ((ts_end.tv_sec - _start_time.tv_sec) * 1000000) + ((ts_end.tv_nsec - _start_time.tv_nsec) / 1000);
+    ret = ((unsigned long)(ts_end.tv_sec - _start_time.tv_sec) * 1000000) + ((unsigned long)((ts_end.tv_nsec / 1000) - (_start_time.tv_nsec/ 1000)));
     /*
     printf("\r\n TimeInterval: %ld.%09ld - %ld.%09ld = %ld.%06ld ns",
         ts_end.tv_sec, ts_end.tv_nsec,  _start_time.tv_sec, _start_time.tv_nsec,
@@ -98,3 +98,22 @@ long GetTimeoutValue(struct timespec _start_time)
     return ret;
 }
 
+// return value unit: 1s
+unsigned long GetSecTimeoutValue(struct timespec _start_time)
+{
+    struct timespec ts_end;
+    unsigned long ret = 0;
+
+    clock_gettime(CLOCK_MONOTONIC, &ts_end);
+
+    ret = ((unsigned long)(ts_end.tv_sec - _start_time.tv_sec) * 1000) + ((unsigned long)((ts_end.tv_nsec / 1000000) - (_start_time.tv_nsec / 1000000)));
+    /*
+    printf("\r\n TimeInterval: %ld.%09ld - %ld.%09ld = %ld.%03ld ms",
+        ts_end.tv_sec, ts_end.tv_nsec,  _start_time.tv_sec, _start_time.tv_nsec,
+        (ret / 1000), (ret % 1000));
+    */
+    ret /= 1000;
+
+    return ret;
+}
+

+ 15 - 1
EVSE/Projects/DO360/Apps/Common.h

@@ -10,6 +10,19 @@
 
 #include <time.h>
 
+#define ARRAY_SIZE(A)               (sizeof(A) / sizeof(A[0]))
+#define PASS                        1
+#define FAIL                        -1
+#define YES                         1
+#define NO                          0
+#define ON                          1
+#define OFF                         0
+#define true                        1
+#define false                       0
+#define NORMAL                      0
+#define ABNORMAL                    1
+#define EQUAL                       0
+
 #define LOG_INFO(format, args...) StoreSysLogMsg("[%s:%4d][%s][Info] "format, (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__), __LINE__, __FUNCTION__, ##args)
 #define LOG_WARN(format, args...) StoreSysLogMsg("[%s:%4d][%s][Warn] "format, (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__), __LINE__, __FUNCTION__, ##args)
 #define LOG_ERROR(format, args...) StoreSysLogMsg("[%s:%4d][%s][Erro] "format, (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__), __LINE__, __FUNCTION__, ##args)
@@ -19,6 +32,7 @@
 int StoreSysLogMsg(const char *fmt, ...);
 int StorePsuLogMsg(const char *fmt, ...);
 void GetClockTime(struct timespec *_now_time);
-long GetTimeoutValue(struct timespec _start_time);
+unsigned long GetTimeoutValue(struct timespec _start_time);
+unsigned long GetSecTimeoutValue(struct timespec _start_time);
 
 #endif /* COMMON_H_ */

+ 12 - 1
EVSE/Projects/DO360/Apps/Config.h

@@ -53,6 +53,8 @@ typedef unsigned char               byte;
 #define MAX_MODULE_PER_GROUP        12
 #define SM_ChargerInfoKey           3000
 
+#define SAFETY_TEST_ENABLE          0
+
 // **********  Audi ********** //
 // Model Name: DOYC182000D2AD
 // Model Name: DDYC182V0UE2AD
@@ -69,6 +71,9 @@ typedef unsigned char               byte;
 // Model Name: DOYE242000D2BD
 // Model Name: DDYE242V0UE2BD
 
+// *********** TCC *********** //
+// Model Name: DBYE182000D1PH
+
 enum _SYSTEM_STATUS
 {
 	S_BOOTING =                         0,
@@ -448,6 +453,8 @@ typedef struct
 {
     unsigned char   MaxDispenser;
     unsigned char   MaxConnector;
+    unsigned char   CabinetSwitch;
+    unsigned char   reserved;
     SystemControl   SysCtrl;
     TestControl     TestCtrl;
     DebugControl    DebugCtrl;
@@ -529,13 +536,15 @@ typedef union
         unsigned int IdleCtrlRes:22;
 
         // MasterCtrlValue
+        unsigned int CableCheckDone:1;                          // 0: no effect,                1: CableCheck done
+        unsigned int InPrechargeMode:1;                         // 0: no effect,                1: system status in PreCharge mode
         unsigned int AlreadyInChargingMode:1;                   // 0: no effect,                1: system status ever enter charging mode
         unsigned int ExtendAvailable:1;                         // 0: no effect,                1: extend capability is available
         unsigned int NeedCurrentBalance:1;                      // 0: no effect,                1: need to current balance
         unsigned int OutputCurrentStable:1;                     // 0: no effect,                1: output current is stable
         unsigned int ReachMaxCurrentDemand:1;                   // 0: no effect,                1: reach ev max current demand
         unsigned int ReachMaxStageCurrent:1;                    // 0: no effect,                1: reach ev max stage current
-        unsigned int MasterCtrlRes:26;
+        unsigned int MasterCtrlRes:24;
 
         // StopChargingCtrlValue
         unsigned int StopChargingRequest:1;                     // 0: no effect,                1: master need to stop
@@ -599,6 +608,8 @@ typedef struct
     unsigned short          ParallelCheck;
     unsigned char           ParallelConfig[MAX_GROUP_QUANTITY]; // group parallel relay setting
     unsigned short          GunLoading;                         // gun output loading, unit: 0.01%
+    unsigned char           GunPsuQuantity;                     // record psu quantity at this gun
+    unsigned char           res;
 }PsuGroupCollectionData;
 
 typedef struct

+ 115 - 94
EVSE/Projects/DO360/Apps/InfyGroup_PsuCommObj.c

@@ -394,6 +394,104 @@ void SendCmdToPsu(int cmd, byte *data, byte dataLen)
     }
 }
 
+void SetPowerOnOff(byte address, byte device, byte value)
+{
+    byte data[8];
+    PwrFrame PwrFrameMsg;
+    PwrFrameMsg.PwrMessage = 0;
+    PwrFrameMsg.InfyBits.CmdValue = PSU_WCmd_ModulePowerOnOff;
+
+    memset(data, 0x00, ARRAY_SIZE(data));
+    // 1 : 關機
+    // 0 : 開機
+    data[0] = value;
+
+    PwrFrameMsg.InfyBits.DeviceValue = device;
+    PwrFrameMsg.InfyBits.DestinationAddress = address;
+    PwrFrameMsg.InfyBits.SourceAddress = INFY_ADD_CSU;
+
+    SendCmdToPsu(PwrFrameMsg.PwrMessage, data, sizeof(data));
+}
+
+void SetAllModuleOutput(byte address, byte device, int voltage, int current)
+{
+    byte data[8];
+    PwrFrame PwrFrameMsg;
+    PwrFrameMsg.PwrMessage = 0;
+    PwrFrameMsg.InfyBits.CmdValue = PSU_WCmd_SetOutput;
+
+    int Vol = voltage * 100;
+    int Cur = current * 100;
+
+    memset(data, 0x00, ARRAY_SIZE(data));
+
+    // 輸出電壓
+    data[0] = (Vol >> 24) & 0xFF;
+    data[1] = (Vol >> 16) & 0xFF;
+    data[2] = (Vol >> 8) & 0xFF;
+    data[3] = Vol & 0xFF;
+    // 輸出電流
+    data[4] = (Cur >> 24) & 0xFF;
+    data[5] = (Cur >> 16) & 0xFF;
+    data[6] = (Cur >> 8) & 0xFF;
+    data[7] = Cur & 0xFF;
+
+    PwrFrameMsg.InfyBits.DeviceValue = device;
+    PwrFrameMsg.InfyBits.DestinationAddress = address;
+    PwrFrameMsg.InfyBits.SourceAddress = INFY_ADD_CSU;
+
+    SendCmdToPsu(PwrFrameMsg.PwrMessage, data, sizeof(data));
+}
+
+void SetModuleOutputVol(byte address, byte device, int voltage, int current)
+{
+    byte data[8];
+    PwrFrame PwrFrameMsg;
+    PwrFrameMsg.PwrMessage = 0;
+    PwrFrameMsg.InfyBits.CmdValue = PSU_WCmd_ModuleSetOutput;
+
+    int Vol = voltage * 100;
+    int Cur = current * 100;
+
+    memset(data, 0x00, ARRAY_SIZE(data));
+
+    // 輸出電壓
+    data[0] = (Vol >> 24) & 0xFF;
+    data[1] = (Vol >> 16) & 0xFF;
+    data[2] = (Vol >> 8) & 0xFF;
+    data[3] = Vol & 0xFF;
+    // 輸出電流
+    data[4] = (Cur >> 24) & 0xFF;
+    data[5] = (Cur >> 16) & 0xFF;
+    data[6] = (Cur >> 8) & 0xFF;
+    data[7] = Cur & 0xFF;
+
+    PwrFrameMsg.InfyBits.DeviceValue = device;
+    PwrFrameMsg.InfyBits.DestinationAddress = address;
+    PwrFrameMsg.InfyBits.SourceAddress = INFY_ADD_CSU;
+
+    SendCmdToPsu(PwrFrameMsg.PwrMessage, data, sizeof(data));
+}
+
+void SetLed(byte address, byte device, byte value)
+{
+    byte data[8];
+    PwrFrame PwrFrameMsg;
+    PwrFrameMsg.PwrMessage = 0;
+    PwrFrameMsg.InfyBits.CmdValue = PSU_WCmd_ModuleFlashLed;
+
+    memset(data, 0x00, ARRAY_SIZE(data));
+    // 1 : 閃爍
+    // 0 : 正常
+    data[0] = value;
+
+    PwrFrameMsg.InfyBits.DeviceValue = device;
+    PwrFrameMsg.InfyBits.DestinationAddress = address;
+    PwrFrameMsg.InfyBits.SourceAddress = INFY_ADD_CSU;
+
+    SendCmdToPsu(PwrFrameMsg.PwrMessage, data, sizeof(data));
+}
+
 bool InitialCommunication()
 {
     CanFd = InitCanBus();
@@ -418,28 +516,19 @@ bool InitialCommunication()
 //================================================
 void SwitchPower(byte group, byte value)
 {
-    byte data[8];
-    PwrFrame PwrFrameMsg;
-    PwrFrameMsg.PwrMessage = 0;
-    PwrFrameMsg.InfyBits.CmdValue = PSU_WCmd_ModulePowerOnOff;
-
-    memset(data, 0x00, ARRAY_SIZE(data));
-    // 1 : 關機
-    // 0 : 開機
-    data[0] = value;
-
     if (group == INFY_ADD_BROADCAST)
     {
-        PwrFrameMsg.InfyBits.DeviceValue = DEVICE_NO_SINGLE_MODULE;
+        SetPowerOnOff(group, DEVICE_NO_SINGLE_MODULE, value);
     }
     else
     {
-        PwrFrameMsg.InfyBits.DeviceValue = DEVICE_NO_GROUP_MODULE;
+        SetPowerOnOff(group, DEVICE_NO_GROUP_MODULE, value);
     }
-    PwrFrameMsg.InfyBits.DestinationAddress = group;
-    PwrFrameMsg.InfyBits.SourceAddress = INFY_ADD_CSU;
+}
 
-    SendCmdToPsu(PwrFrameMsg.PwrMessage, data, sizeof(data));
+void SinglePsuPower(byte address, byte value)
+{
+    SetPowerOnOff(address, DEVICE_NO_SINGLE_MODULE, value);
 }
 
 void SleepMode(byte group, byte value)
@@ -470,104 +559,36 @@ void SleepMode(byte group, byte value)
 
 void FlashLed(byte group, byte value)
 {
-    byte data[8];
-    PwrFrame PwrFrameMsg;
-    PwrFrameMsg.PwrMessage = 0;
-    PwrFrameMsg.InfyBits.CmdValue = PSU_WCmd_ModuleFlashLed;
-
-    memset(data, 0x00, ARRAY_SIZE(data));
-    // 1 : 閃爍
-    // 0 : 正常
-    data[0] = value;
-
     if (group == INFY_ADD_BROADCAST)
     {
-        PwrFrameMsg.InfyBits.DeviceValue = DEVICE_NO_SINGLE_MODULE;
+        SetLed(group, DEVICE_NO_SINGLE_MODULE, value);
     }
     else
     {
-        PwrFrameMsg.InfyBits.DeviceValue = DEVICE_NO_GROUP_MODULE;
+        SetLed(group, DEVICE_NO_GROUP_MODULE, value);
     }
-    PwrFrameMsg.InfyBits.DestinationAddress = group;
-    PwrFrameMsg.InfyBits.SourceAddress = INFY_ADD_CSU;
+}
 
-    SendCmdToPsu(PwrFrameMsg.PwrMessage, data, sizeof(data));
+void SingleFlashLed(byte address, byte value)
+{
+    SetLed(address, DEVICE_NO_SINGLE_MODULE, value);
 }
 
 void PresentOutputVol(byte group, int voltage, int current)
 {
-	byte data[8];
-    PwrFrame PwrFrameMsg;
-    PwrFrameMsg.PwrMessage = 0;
-    PwrFrameMsg.InfyBits.CmdValue = PSU_WCmd_SetOutput;
-
-	int Vol = voltage * 100;
-	int Cur = current * 100;
-
-	memset(data, 0x00, ARRAY_SIZE(data));
-
-	// 輸出電壓
-	data[0] = (Vol >> 24) & 0xFF;
-	data[1] = (Vol >> 16) & 0xFF;
-	data[2] = (Vol >> 8) & 0xFF;
-	data[3] = Vol & 0xFF;
-	// 輸出電流
-	data[4] = (Cur >> 24) & 0xFF;
-	data[5] = (Cur >> 16) & 0xFF;
-	data[6] = (Cur >> 8) & 0xFF;
-	data[7] = Cur & 0xFF;
-
-    if (group == INFY_ADD_BROADCAST)
+    if(group == INFY_ADD_BROADCAST)
     {
-        PwrFrameMsg.InfyBits.DeviceValue = DEVICE_NO_SINGLE_MODULE;
+        SetAllModuleOutput(group, DEVICE_NO_SINGLE_MODULE, voltage, current);
     }
     else
     {
-        PwrFrameMsg.InfyBits.DeviceValue = DEVICE_NO_GROUP_MODULE;
+        SetAllModuleOutput(group, DEVICE_NO_GROUP_MODULE, voltage, current);
     }
-    PwrFrameMsg.InfyBits.DestinationAddress = group;
-    PwrFrameMsg.InfyBits.SourceAddress = INFY_ADD_CSU;
-
-	SendCmdToPsu(PwrFrameMsg.PwrMessage, data, sizeof(data));
 }
 
-// voltage: unit: 1mV
-// current: unit: 1mA
-void SetModuleOutputVol(byte group, int voltage, int current)
+void SingleOutputVol(byte address, int voltage, int current)
 {
-    byte data[8];
-    PwrFrame PwrFrameMsg;
-    PwrFrameMsg.PwrMessage = 0;
-    PwrFrameMsg.InfyBits.CmdValue = PSU_WCmd_ModuleSetOutput;
-
-    int Vol = voltage;
-    int Cur = current;
-
-    memset(data, 0x00, ARRAY_SIZE(data));
-
-    // 輸出電壓
-    data[0] = (Vol >> 24) & 0xFF;
-    data[1] = (Vol >> 16) & 0xFF;
-    data[2] = (Vol >> 8) & 0xFF;
-    data[3] = Vol & 0xFF;
-    // 輸出電流
-    data[4] = (Cur >> 24) & 0xFF;
-    data[5] = (Cur >> 16) & 0xFF;
-    data[6] = (Cur >> 8) & 0xFF;
-    data[7] = Cur & 0xFF;
-
-    if (group == INFY_ADD_BROADCAST)
-    {
-        PwrFrameMsg.InfyBits.DeviceValue = DEVICE_NO_SINGLE_MODULE;
-    }
-    else
-    {
-        PwrFrameMsg.InfyBits.DeviceValue = DEVICE_NO_GROUP_MODULE;
-    }
-    PwrFrameMsg.InfyBits.DestinationAddress = group;
-    PwrFrameMsg.InfyBits.SourceAddress = INFY_ADD_CSU;
-
-    SendCmdToPsu(PwrFrameMsg.PwrMessage, data, sizeof(data));
+    SetModuleOutputVol(address, DEVICE_NO_SINGLE_MODULE, voltage, current);
 }
 
 void FanNoiseInfo(byte group, byte value)

+ 3 - 1
EVSE/Projects/DO360/Apps/InfyGroup_PsuCommObj.h

@@ -170,10 +170,12 @@ bool InitialCommunication();
 
 /*Set Cmd*/
 void SwitchPower(byte group, byte value);
+void SinglePsuPower(byte address, byte value);
 void SleepMode(byte group, byte value);
 void FlashLed(byte group, byte value);
+void SingleFlashLed(byte address, byte value);
 void PresentOutputVol(byte group, int voltage, int current);
-void SetModuleOutputVol(byte group, int voltage, int current);
+void SingleOutputVol(byte address, int voltage, int current);
 void FanNoiseInfo(byte group, byte value);
 void SetWalkInConfig(byte group, byte enable, byte sec);
 void SetDipSwitchMode();

+ 119 - 27
EVSE/Projects/DO360/Apps/Module_EvComm.c

@@ -42,19 +42,10 @@
 #include	"Config.h"
 #include    "Common.h"
 
-#define ARRAY_SIZE(A)				(sizeof(A) / sizeof(A[0]))
-#define PASS						1
-#define FAIL			   			-1
-#define YES							1
-#define NO							0
-#define ON							1
-#define OFF							0
-#define true			    		1
-#define false						0
-
 struct SysConfigAndInfo				*ShmSysConfigAndInfo;
 ChargerInfoData                     *ShmChargerInfo;
 struct ChargingInfoData             *chargingInfo[CONNECTOR_QUANTITY];
+struct PsuData                      *ShmPsuData;
 
 void ShowSocketData(struct PACKET_STRUCTURE *packet)
 {
@@ -115,6 +106,21 @@ int InitShareMemory()
         result = FAIL;
     }
 
+    if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData),  0777)) < 0)
+    {
+        #ifdef SystemLogMessage
+        LOG_ERROR("shmget ShmPsuData NG");
+        #endif
+        result = FAIL;
+    }
+    else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
+    {
+        #ifdef SystemLogMessage
+        LOG_ERROR("shmat ShmPsuData NG");
+        #endif
+        result = FAIL;
+    }
+
 	return result;
 }
 
@@ -959,18 +965,100 @@ void GetPhysicalLimitVoltageAndCurrent(byte index, unsigned short *voltage, unsi
     }
 }
 
-void GetConfigLimitVoltageAndCurrent(byte index, unsigned short *voltage, unsigned short *currrent)
+void GetConfigLimitPowerAndCurrent(byte index, unsigned short *power, unsigned short *currrent)
 {
-    unsigned short limitCurrent = ShmSysConfigAndInfo->SysInfo.MainChargingMode == _MAIN_CHARGING_MODE_MAX ?
-            (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].MaxTotalChargingCurrent) :
-            (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].MaxTotalChargingCurrent / 2);
+    unsigned short limitPower = 0, limitCurrent = 0;
+    unsigned char inUsingCnt = 0;
+
+    for(int i = 0; i < GENERAL_GUN_QUANTITY; i++)
+    {
+        if(ShmChargerInfo->PsuGrouping.GroupCollection[i].Role == _GROLE_MASTER)
+        {
+            inUsingCnt += ShmChargerInfo->PsuGrouping.GroupCollection[i].GunPsuQuantity;
+        }
+    }
+
+    if(ShmChargerInfo->PsuGrouping.GroupCollection[index].GunPsuQuantity != 0 && inUsingCnt != 0 &&
+        ShmSysConfigAndInfo->SysConfig.MaxChargingPower != 0)
+    {
+        limitPower = ShmSysConfigAndInfo->SysConfig.MaxChargingPower * 10;
+        limitPower = (limitPower * ShmChargerInfo->PsuGrouping.GroupCollection[index].GunPsuQuantity) / inUsingCnt;
+    }
+    ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].MaxTotalChargingPower = limitPower;
 
+    if(ShmChargerInfo->PsuGrouping.GroupCollection[index].GunPsuQuantity != 0 && inUsingCnt != 0 &&
+        ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent != 0)
+    {
+        limitCurrent = ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent * 10;
+        limitCurrent = (limitCurrent * ShmChargerInfo->PsuGrouping.GroupCollection[index].GunPsuQuantity) / inUsingCnt;
+    }
+    ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].MaxTotalChargingCurrent = limitCurrent;
+
+    if(limitPower != 0 && limitPower <= *power)
+    {
+        *power = limitPower;
+    }
     if(limitCurrent != 0 && limitCurrent <= *currrent)
     {
         *currrent = limitCurrent;
     }
 }
 
+void GetChargingProfileLimit(byte index, unsigned short *power, unsigned short *currrent)
+{
+    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]->ChargingProfilePower >= 0 && *power > ((int)chargingInfo[index]->ChargingProfilePower / 100))
+        {
+            *power = (int)chargingInfo[index]->ChargingProfilePower / 100;
+        }
+
+        if(chargingInfo[index]->ChargingProfileCurrent >= 0 && *currrent > (int)chargingInfo[index]->ChargingProfileCurrent)
+        {
+            *currrent = (int)chargingInfo[index]->ChargingProfileCurrent;
+        }
+    }
+}
+
+void GetMaxChargingProfileLimit(byte index, unsigned short *power, unsigned short *currrent)
+{
+    unsigned short limitPower = 0, limitCurrent = 0;
+    unsigned char inUsingCnt = 0;
+
+    for(int i = 0; i < GENERAL_GUN_QUANTITY; i++)
+    {
+        if(ShmChargerInfo->PsuGrouping.GroupCollection[i].Role == _GROLE_MASTER)
+        {
+            inUsingCnt += ShmChargerInfo->PsuGrouping.GroupCollection[i].GunPsuQuantity;
+        }
+    }
+
+    // max charging profile
+    if(ShmChargerInfo->PsuGrouping.GroupCollection[index].GunPsuQuantity != 0 && inUsingCnt != 0 &&
+        ShmSysConfigAndInfo->SysInfo.MaxChargingProfilePower >= 0)
+    {
+        limitPower = (int)ShmSysConfigAndInfo->SysInfo.MaxChargingProfilePower / 100;
+        limitPower = (limitPower * ShmChargerInfo->PsuGrouping.GroupCollection[index].GunPsuQuantity) / inUsingCnt;
+
+        if(*power > limitPower)
+        {
+            *power = limitPower;
+        }
+
+        if (chargingInfo[index]->EvBatterytargetVoltage > 0 &&
+            (int)chargingInfo[index]->PresentChargingVoltage > 0)
+        {
+            limitCurrent = (limitPower * 100 / chargingInfo[index]->PresentChargingVoltage) * 10;
+
+            if(*currrent > limitCurrent)
+            {
+                *currrent = limitCurrent;
+            }
+        }
+    }
+}
+
 void ChargingCapabilityResponse(int socket, struct PACKET_STRUCTURE *packet)
 {
 	struct PACKET_STRUCTURE sendBuffer;
@@ -984,7 +1072,9 @@ void ChargingCapabilityResponse(int socket, struct PACKET_STRUCTURE *packet)
 	power = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].GeneralChargingData.AvailableChargingPower;
 
 	GetPhysicalLimitVoltageAndCurrent(packet->Header.id - 1, &voltage, &current);
-	GetConfigLimitVoltageAndCurrent(packet->Header.id - 1, &voltage, &current);
+	GetConfigLimitPowerAndCurrent(packet->Header.id - 1, &power, &current);
+	GetChargingProfileLimit(packet->Header.id - 1, &power, &current);
+	GetMaxChargingProfileLimit(packet->Header.id - 1, &power, &current);
 
 	currency = ShmSysConfigAndInfo->SysInfo.DispenserInfo.Currency;
 	price = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].UserPrice;
@@ -1388,7 +1478,7 @@ void WriteChargingInfoResponse(int socket, struct PACKET_STRUCTURE *packet, unsi
     voltage -= ((current * 8 * 10) / 10000);
 #endif
 
-    if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun].Parameter.bits.PantographEnable)
+    if(chargingInfo[gun]->PantographFlag == YES)
     {
         voltage = (unsigned short)(chargingInfo[gun]->PresentChargingVoltage * 10);
         current = (unsigned short)(chargingInfo[gun]->PresentChargingCurrent * 10);
@@ -1427,8 +1517,7 @@ int GetChargerSystemId(char *id)
 
         case _QR_MODE_Default:
         default:
-            strcat((char *)id, (char *)ShmSysConfigAndInfo->SysConfig.ModelName);
-            strcat((char *)id, (char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
+            strcat((char *)id, (char *)ShmSysConfigAndInfo->SysConfig.SystemId);
             break;
     }
 
@@ -1572,10 +1661,10 @@ void ConnectorPantographBindingHandler(unsigned char connectorIndex, unsigned ch
     switch(physical)
     {
         case 'P':
-            ShmSysConfigAndInfo->SysInfo.ConnectorInfo[connectorIndex].Parameter.bits.PantographEnable = 1;
+            chargingInfo[connectorIndex]->PantographFlag = YES;
             break;
         default:
-            ShmSysConfigAndInfo->SysInfo.ConnectorInfo[connectorIndex].Parameter.bits.PantographEnable = 0;
+            chargingInfo[connectorIndex]->PantographFlag = NO;
             break;
     }
 }
@@ -1597,7 +1686,7 @@ void ConnectorTypeBindingHandler(unsigned char dispenserIndex, unsigned char *ty
             dispenserIndex + 1, gunIndex + 1, str_gun_type[type[i]],
             ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gunIndex].RemoteMaxPhysicalVoltage,
             ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gunIndex].RemoteMaxPhysicalCurrent,
-            ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gunIndex].Parameter.bits.PantographEnable ? "Normal" : "Pantograph");
+            chargingInfo[gunIndex]->PantographFlag == YES ? "Pantograph" : "Normal");
 	}
 }
 
@@ -1822,7 +1911,7 @@ BOOL ConnectorChargingTargetHandler(struct PACKET_STRUCTURE *packet, unsigned ch
 {
 	BOOL find = FindConnectorID(dispenserIndex, packet->Header.id);
 	BOOL done = false;
-	unsigned short voltage = 0, current = 0;
+	unsigned short voltage = 0, current = 0, power = 0;
 
 	if(find)
 	{
@@ -1841,7 +1930,7 @@ BOOL ConnectorChargingTargetHandler(struct PACKET_STRUCTURE *packet, unsigned ch
 		}
 
 		GetPhysicalLimitVoltageAndCurrent(packet->Header.id - 1, &voltage, &current);
-		GetConfigLimitVoltageAndCurrent(packet->Header.id - 1, &voltage, &current);
+		GetConfigLimitPowerAndCurrent(packet->Header.id - 1, &power, &current);
 
 		if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].RemoteTargetVoltage != voltage ||
             ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].RemoteTargetCurrent != current)
@@ -2438,7 +2527,7 @@ unsigned char GroundFaultDetectionHandler(struct PACKET_STRUCTURE *packet, unsig
         gun = packet->Header.id - 1;
         unsigned char enable = packet->Payload.data[0];
 
-        if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun].Parameter.bits.PantographEnable)
+        if(chargingInfo[gun]->PantographFlag == YES)
         {
             if(enable == _GFD_Enable &&
                 (chargingInfo[gun]->SystemStatus >= S_PREPARING_FOR_EVSE && chargingInfo[gun]->SystemStatus <= S_CHARGING))
@@ -2486,7 +2575,7 @@ void DispenserSocketProcess(int socketFd, struct sockaddr_in clientInfo, unsigne
 	unsigned char ackResult = _R_NG;
 	DispenserAck_Status ack = _DAS_Wait;
 
-	LOG_INFO("IP %s connection(%d) is established, start dispenser process", (inet_ntoa(clientInfo.sin_addr)), index);
+	LOG_INFO("IP %s connection(%d) is established, start dispenser process, PID = %d", (inet_ntoa(clientInfo.sin_addr)), index, getpid());
 
 	while(1)
 	{
@@ -2827,7 +2916,10 @@ BOOL IsConflictIp(uint32_t ipAddress)
 		if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[i].IpAddress == ipAddress)
 		{
             int dispenser = ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[i].DispenserIndex;
-            ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenser].Setting.bits.DuplicateIp = true;
+            if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenser].Setting.bits.DuplicateIp == false)
+            {
+                ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenser].Setting.bits.DuplicateIp = true;
+            }
 			return true;
 		}
 	}
@@ -2990,7 +3082,7 @@ int tcpSocketServerStart(void)
     }
 	listen(sockFd, CONNECTION_LIMIT);
 
-	LOG_INFO("TCP Server Start");
+	LOG_INFO("Dispenser TCP Server Start");
 
 	signal(SIGCHLD, SIG_IGN);
 

+ 2 - 2
EVSE/Projects/DO360/Apps/Module_EvComm.h

@@ -1,7 +1,7 @@
 /*
  * Module_EvComm.h
  *
- *  Created on: 2020�~9��14��
+ *  Created on: 2020年9月14日
  *      Author: Wendell
  */
 
@@ -25,7 +25,7 @@
 
 // socket setting
 #define	CONNECTION_LIMIT				5
-#define MAXIMUM_CONNECT_QUANTITY		2
+#define MAXIMUM_CONNECT_QUANTITY		4
 
 #define CCS_MAX_PHYSICAL_VOLTAGE        9500
 #define CCS_NATURAL_MAX_CURRENT         2000

+ 0 - 6
EVSE/Projects/DO360/Apps/Module_EventLogging.c

@@ -29,12 +29,6 @@
 #include	"../../define.h"
 #include    "Common.h"
 
-#define ARRAY_SIZE(A)		(sizeof(A) / sizeof(A[0]))
-#define PASS				1
-#define FAIL				-1
-#define YES					1
-#define NO					0
-
 struct SysConfigAndInfo			*ShmSysConfigAndInfo;
 struct StatusCodeData 			*ShmStatusCodeData;
 struct StatusCodeData           StatusCodeDisableMask;

+ 147 - 18
EVSE/Projects/DO360/Apps/Module_InternalComm.c

@@ -33,16 +33,10 @@
 #include    "Config.h"
 #include    "Common.h"
 
-#define ARRAY_SIZE(A)		(sizeof(A) / sizeof(A[0]))
-#define PASS				1
-#define FAIL				-1
-#define YES					1
-#define NO					0
 #define TEN_MINUTES			600
 #define ENV_TEMP_MIN		45
 #define ENV_TEMP_MAX		50
 #define DEFAULT_AC_INDEX	2
-#define EQUAL				0
 #define COLOR_MAX_LV		100
 #define COLOR_MIN_LV		0
 
@@ -116,6 +110,12 @@ Connector_GFD                   *LocaltionGfd[MAX_GROUP_QUANTITY];
 // 確認 Relay Welding 電壓
 #define RELAY_WELDING_DET					300
 
+#if SAFETY_TEST_ENABLE
+#define RELAY_OPEN_AT_PRECHARGE             1
+#else
+#define RELAY_OPEN_AT_PRECHARGE             0
+#endif
+
 byte gunCount;
 byte acgunCount;
 // 槍資訊
@@ -415,6 +415,16 @@ void SetModelName_Fan()
 // AC 三相輸入電壓
 void GetPresentInputVol()
 {
+    if(ShmChargerInfo->Control.RelayCtrl.bits.AcInputDisable == YES)
+    {
+        ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputUVP = NO;
+        ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputUVP = NO;
+        ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputUVP = NO;
+        ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputOVP = NO;
+        ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputOVP = NO;
+        ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputOVP = NO;
+        return;
+    }
 	if (Query_Present_InputVoltage(Uart5Fd, Addr.DO360_RC1, &inputVoltage) == PASS)
 	{
 		// resolution : 0.1
@@ -900,7 +910,7 @@ void GetGfdAdc(void)
     {
         for(int i = 0; i < ShmChargerInfo->Control.MaxConnector; i++)
         {
-            if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].Parameter.bits.PantographEnable)
+            if(_chargingData[i]->PantographFlag == YES)
             {
                 _isGfdEnable = true;
                 LOG_INFO("Enable Power Cabinet GFD Function");
@@ -915,8 +925,20 @@ void GetGfdAdc(void)
         // warning : >= 100 歐姆 && <= 500 歐姆 @ 150-750 Vdc
         if(Query_Gfd_Adc(Uart5Fd, Addr.DO360_RC1, &gfd_adc[0]) == PASS)
         {
-
+//            if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[0].Parameter.bits.GfdDetection ||
+//                ShmSysConfigAndInfo->SysInfo.ConnectorInfo[1].Parameter.bits.GfdDetection)
+//            {
+//                LOG_INFO("Query Relay1 GFD ADC1 Status = %d, ADC2 Status = %d", gfd_adc[0].result_conn1, gfd_adc[0].result_conn2);
+//            }
         }
+//        else
+//        {
+//            if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[0].Parameter.bits.GfdDetection ||
+//                ShmSysConfigAndInfo->SysInfo.ConnectorInfo[1].Parameter.bits.GfdDetection)
+//            {
+//                LOG_INFO("Query Relay1 GFD ADC Fail");
+//            }
+//        }
         if(ShmChargerInfo->Control.SysCtrl.bits.SecondRelayBoardEnable)
         {
             if(Query_Gfd_Adc(Uart5Fd, Addr.DO360_RC2, &gfd_adc[1]) == PASS)
@@ -1098,12 +1120,70 @@ void SetK1K2RelayStatus(byte index)
             }
             else
             {
+#if RELAY_OPEN_AT_PRECHARGE
+
+                if(_chargingData[index]->SystemStatus == S_PREPARING_FOR_EVSE)
+                {
+                    if(ShmPsuGrouping->GroupCollection[index].GroupCtrl.bits.CableCheckDone == false &&
+                        ShmPsuGrouping->GroupCollection[index].GroupCtrl.bits.InPrechargeMode == false)
+                    {
+                        if(!ShmOutputRelayConfig[index]->bits.Output_N || !ShmOutputRelayConfig[index]->bits.Output_P)
+                        {
+                            LOG_INFO("Gun %d Set K1K2 Close And Prepare To Cable Check", index + 1);
+                        }
+                        ShmOutputRelayConfig[index]->bits.Output_N = true;
+                        ShmOutputRelayConfig[index]->bits.Output_P = true;
+                    }
+                    else if(ShmPsuGrouping->GroupCollection[index].GroupCtrl.bits.CableCheckDone == true &&
+                        ShmPsuGrouping->GroupCollection[index].GroupCtrl.bits.InPrechargeMode == false)
+                    {
+                        if(_chargingData[index]->FireChargingVoltage <= SELF_TO_CHANGE_RELAY_STATUS)
+                        {
+                            if(ShmOutputRelayConfig[index]->bits.Output_N || ShmOutputRelayConfig[index]->bits.Output_P)
+                            {
+                                LOG_INFO("Gun %d Set K1K2 Open By Cable Check Done", index + 1);
+                            }
+                            ShmOutputRelayConfig[index]->bits.Output_N = false;
+                            ShmOutputRelayConfig[index]->bits.Output_P = false;
+                        }
+                    }
+                    else if(ShmPsuGrouping->GroupCollection[index].GroupCtrl.bits.CableCheckDone == true &&
+                        ShmPsuGrouping->GroupCollection[index].GroupCtrl.bits.InPrechargeMode == true)
+                    {
+                        unsigned short voltage = 0, diffVol = 0;
+                        voltage = (int)(_chargingData[index]->PresentChargingVoltage * 10);
+                        diffVol = voltage >= ShmPsuGrouping->GroupOutput[index].GTargetVoltage ?
+                            voltage - ShmPsuGrouping->GroupOutput[index].GTargetVoltage :
+                            ShmPsuGrouping->GroupOutput[index].GTargetVoltage - voltage;
+
+                        if(diffVol <= 30)
+                        {
+                            if(!ShmOutputRelayConfig[index]->bits.Output_N || !ShmOutputRelayConfig[index]->bits.Output_P)
+                            {
+                                LOG_INFO("Gun %d Set K1K2 Close And Voltage Is Balance", index + 1);
+                            }
+                            ShmOutputRelayConfig[index]->bits.Output_N = true;
+                            ShmOutputRelayConfig[index]->bits.Output_P = true;
+                        }
+                    }
+                }
+                else
+                {
+                    if(!ShmOutputRelayConfig[index]->bits.Output_N || !ShmOutputRelayConfig[index]->bits.Output_P)
+                    {
+                        LOG_INFO("Gun %d Set K1K2 Close In Charging Status", index + 1);
+                    }
+                    ShmOutputRelayConfig[index]->bits.Output_N = true;
+                    ShmOutputRelayConfig[index]->bits.Output_P = true;
+                }
+#else
                 if(!ShmOutputRelayConfig[index]->bits.Output_N || !ShmOutputRelayConfig[index]->bits.Output_P)
                 {
                     LOG_INFO("Gun %d Set K1K2 Close And Prepare To Charging", index + 1);
                 }
                 ShmOutputRelayConfig[index]->bits.Output_N = true;
                 ShmOutputRelayConfig[index]->bits.Output_P = true;
+#endif
             }
         }
         else if ((_chargingData[index]->SystemStatus >= S_TERMINATING &&
@@ -1431,7 +1511,7 @@ int InitShareMemory()
 		#endif
 		result = FAIL;
 	}
-	memset(ShmFanModuleData,0,sizeof(struct FanModuleData));
+	//memset(ShmFanModuleData,0,sizeof(struct FanModuleData));
 
 	if ((MeterSMId = shmget(ShmRelayBdKey, sizeof(struct RelayModuleData), 0777)) < 0)
 	{
@@ -1447,7 +1527,7 @@ int InitShareMemory()
 		#endif
 		result = FAIL;
 	}
-	memset(ShmRelayModuleData[0],0,sizeof(struct RelayModuleData));
+	//memset(ShmRelayModuleData[0],0,sizeof(struct RelayModuleData));
 
 	// DO360 RC2
 	if ((MeterSMId = shmget(ShmRelay2BdKey, sizeof(struct RelayModuleData), 0777)) < 0)
@@ -1464,7 +1544,7 @@ int InitShareMemory()
 		#endif
 		result = FAIL;
 	}
-	memset(ShmRelayModuleData[1],0,sizeof(struct RelayModuleData));
+	//memset(ShmRelayModuleData[1],0,sizeof(struct RelayModuleData));
 
 
 	if ((MeterSMId = shmget(ShmLedBdKey, sizeof(struct LedModuleData), 0777)) < 0)
@@ -1481,7 +1561,7 @@ int InitShareMemory()
 		#endif
 		result = FAIL;
 	}
-	memset(ShmLedModuleData,0,sizeof(struct LedModuleData));
+	//memset(ShmLedModuleData,0,sizeof(struct LedModuleData));
 
 	if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
 	{
@@ -1818,12 +1898,28 @@ void SetGfdConfig(byte index, byte resister)
 //		LOG_INFO("Set reqVol = %f, resister = %d",
 //				gfd_config.reqVol,
 //				gfd_config.resister);
+//        if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[0].Parameter.bits.GfdDetection ||
+//            ShmSysConfigAndInfo->SysInfo.ConnectorInfo[1].Parameter.bits.GfdDetection)
+//        {
+//            LOG_INFO("Set Relay %02X GFD Config index = %d, state = %d OK", add, gfd_config.index, gfd_config.state);
+//        }
 	}
+//	else
+//	{
+//        if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[0].Parameter.bits.GfdDetection ||
+//            ShmSysConfigAndInfo->SysInfo.ConnectorInfo[1].Parameter.bits.GfdDetection)
+//        {
+//            LOG_INFO("Set Relay %02X GFD Config index = %d, state = %d NG", add, gfd_config.index, gfd_config.state);
+//        }
+//	}
 }
 
+char GfdConfig[4];
+
 void CableCheckDetected(byte index)
 {
     unsigned char location = 0;
+    char *strGfdConfig[] = {"Idle", "CableCheck", "PreCharge", "Charging"};
 
 	// Cable Check
 	// 當火線上的電壓 = 車端要求的電壓電流
@@ -1833,7 +1929,7 @@ void CableCheckDetected(byte index)
 	// Pre-Warning : 150 歐/V < Rgfd <= 500 歐/V 假設電壓為 500V 則 75000 歐 < Rgfd <= 250000
 	// SO Normal : Rgfd > 500 歐/V 假設電壓為 500 V 則 Rgfd > 250000 歐
 
-    if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].Parameter.bits.PantographEnable)
+    if(_chargingData[index]->PantographFlag == YES)
     {
         location = ShmPsuGrouping->GroupCollection[index].Location;
 
@@ -1843,15 +1939,31 @@ void CableCheckDetected(byte index)
             if(_chargingData[index]->SystemStatus == S_PREPARING_FOR_EVSE && _chargingData[index]->RelayWeldingCheck == YES)
             {
                 SetGfdConfig(location, GFD_CABLECHK);
+                if(GfdConfig[index] != GFD_CABLECHK)
+                {
+                    LOG_INFO("Gun %d Set GFD = %s", index + 1, strGfdConfig[GFD_CABLECHK]);
+                }
+                GfdConfig[index] = GFD_CABLECHK;
             }
             else
             {
                 SetGfdConfig(location, GFD_CHARGING);
+                if(GfdConfig[index] != GFD_CHARGING)
+                {
+                    LOG_INFO("Gun %d Set GFD = %s", index + 1, strGfdConfig[GFD_CHARGING]);
+                }
+                GfdConfig[index] = GFD_CHARGING;
             }
         }
         else
         {
             SetGfdConfig(location, GFD_IDLE);
+            if(GfdConfig[index] != GFD_IDLE)
+            {
+                LOG_INFO("Gun %d Set GFD = %s", index + 1, strGfdConfig[GFD_IDLE]);
+            }
+            GfdConfig[index] = GFD_IDLE;
+            ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].Parameter.bits.GfdDetection = 0;
         }
     }
 }
@@ -2408,22 +2520,39 @@ int main(void)
 		return 0;
 	}
 
+	_RelaySelfTestOK = NO;
 	memset(&outputRelay[0], 0x00, sizeof(Relay));
 	memset(&outputRelay[1], 0x00, sizeof(Relay));
 
     if(ShmChargerInfo->Control.SysCtrl.bits.RelayBoardDisable == false)
     {
-        if(Config_Relay_Output(Uart5Fd, Addr.DO360_RC1, &outputRelay[0]) != PASS)
-            LOG_INFO("Config_Relay1_Output fail");
+        if(ShmRelayModuleData[0]->SelfTest_Comp == NO)
+        {
+            if(Config_Relay_Output(Uart5Fd, Addr.DO360_RC1, &outputRelay[0]) != PASS)
+                LOG_INFO("Config_Relay1_Output fail");
+        }
+        else
+        {
+            if(ShmChargerInfo->Control.SysCtrl.bits.SecondRelayBoardEnable == false)
+            {
+                _RelaySelfTestOK = YES;
+            }
+        }
 
         if(ShmChargerInfo->Control.SysCtrl.bits.SecondRelayBoardEnable)
         {
-            if(Config_Relay_Output(Uart5Fd, Addr.DO360_RC2, &outputRelay[1]) != PASS)
-                LOG_INFO("Config_Relay2_Output fail");
+            if(ShmRelayModuleData[1]->SelfTest_Comp == NO)
+            {
+                if(Config_Relay_Output(Uart5Fd, Addr.DO360_RC2, &outputRelay[1]) != PASS)
+                    LOG_INFO("Config_Relay2_Output fail");
+            }
+            else
+            {
+                _RelaySelfTestOK = YES;
+            }
         }
     }
 
-    _RelaySelfTestOK = NO;
 	cur_led_color.Connect_1_Red = COLOR_MIN_LV;
 	cur_led_color.Connect_1_Green = COLOR_MIN_LV;
 	cur_led_color.Connect_1_Blue = COLOR_MIN_LV;

+ 103 - 9
EVSE/Projects/DO360/Apps/Module_PrimaryComm.c

@@ -33,13 +33,8 @@
 #include    "Config.h"
 #include    "Common.h"
 
-#define ARRAY_SIZE(A)		(sizeof(A) / sizeof(A[0]))
-#define PASS				1
-#define FAIL				-1
-#define YES					1
-#define NO					0
-
-#define COMM_FAIL_COUNT     10
+#define COMM_FAIL_COUNT         10
+#define STATE_CHANGE_COUNT      3
 
 typedef unsigned char 		byte;
 
@@ -64,6 +59,15 @@ byte _OutputDrv = 0;
 byte _acStatus = 0;
 byte _acChkCount = 0;
 int _CommFailCount = 0;
+int _CabinetSwitch = -1;
+int _TempSwitch = -1;
+int _TempSPD = -1;
+int _TempDoor = -1;
+int _TempEmg = -1;
+byte _SwitchCnt = 0;
+byte _SPDCnt = 0;
+byte _DoorCnt = 0;
+byte _EmgBtnCnt = 0;
 
 int DiffTimeb(struct timeb ST, struct timeb ET)
 {
@@ -269,9 +273,26 @@ void GetInputGpioStatus()
 			_acChkCount = 0;
 
 		ShmPrimaryMcuData->InputDet.bits.AcMainBreakerDetec = gpio_in.AC_MainBreaker;
+
+		if(_TempSPD != gpio_in.SPD)
+		{
+		    _SPDCnt++;
+		    if(_SPDCnt >= STATE_CHANGE_COUNT || _TempSPD < 0)
+		    {
+		        _TempSPD = gpio_in.SPD;
+		        _SPDCnt = 0;
+		    }
+		}
+		if(_TempSPD >= 0)
+		{
+		    ShmPrimaryMcuData->InputDet.bits.SpdDetec = _TempSPD;
+		}
+#if 0
 		ShmPrimaryMcuData->InputDet.bits.SpdDetec = gpio_in.SPD;
+#endif
 
 		// DO360 Door Status is the inverse of DS's
+#if 0
         if(ShmChargerInfo->Control.PrimaryCtrl.bits.DoorSensorReverse)
         {
             ShmPrimaryMcuData->InputDet.bits.DoorOpen = gpio_in.Door_Open ? 0 : 1;
@@ -280,19 +301,92 @@ void GetInputGpioStatus()
         {
             ShmPrimaryMcuData->InputDet.bits.DoorOpen = gpio_in.Door_Open ? 1 : 0;
         }
-
+#endif
+        if(_TempDoor != gpio_in.Door_Open)
+        {
+            _DoorCnt++;
+            if(_DoorCnt >= STATE_CHANGE_COUNT || _TempDoor < 0)
+            {
+                _TempDoor = gpio_in.Door_Open;
+                _DoorCnt = 0;
+            }
+        }
+        if(_TempDoor >= 0)
+        {
+            if(ShmChargerInfo->Control.PrimaryCtrl.bits.DoorSensorReverse)
+            {
+                ShmPrimaryMcuData->InputDet.bits.DoorOpen = _TempDoor > 0 ? 0 : 1;
+            }
+            else
+            {
+                ShmPrimaryMcuData->InputDet.bits.DoorOpen = _TempDoor > 0 ? 1 : 0;
+            }
+        }
 		// Bypass door open
 		//ShmPrimaryMcuData->InputDet.bits.DoorOpen = 0;
 
 		ShmPrimaryMcuData->InputDet.bits.Button1 = gpio_in.Button[0];
 		ShmPrimaryMcuData->InputDet.bits.Button2 = gpio_in.Button[1];
-		ShmPrimaryMcuData->InputDet.bits.EmergencyButton = gpio_in.Emergency_Btn;
 
+		if(_TempEmg != gpio_in.Emergency_Btn)
+		{
+		    _EmgBtnCnt++;
+		    if(_EmgBtnCnt >= STATE_CHANGE_COUNT || _TempEmg < 0)
+		    {
+		        _TempEmg = gpio_in.Emergency_Btn;
+		        _EmgBtnCnt = 0;
+		    }
+		}
+		if(_TempEmg >= 0)
+		{
+		    ShmPrimaryMcuData->InputDet.bits.EmergencyButton = _TempEmg > 0 ? 1 : 0;
+		}
+#if 0
+		ShmPrimaryMcuData->InputDet.bits.EmergencyButton = gpio_in.Emergency_Btn;
+#endif
 		//LOG_INFO("left = %d", ShmPrimaryMcuData->InputDet.bits.Button1);
 		//LOG_INFO("right = %d", ShmPrimaryMcuData->InputDet.bits.Button2);
 		//LOG_INFO("ShmSysConfigAndInfo->SysInfo.AcContactorStatus = %d", ShmSysConfigAndInfo->SysInfo.AcContactorStatus);
 		//if (ShmPrimaryMcuData->InputDet.bits.AcMainBreakerDetec == YES)
 		//	LOG_INFO("AC Mainbreaker occur.");
+
+		ShmPrimaryMcuData->InputDet.bits.Key0 = gpio_in.Key[0] ? 0 : 1;
+		ShmPrimaryMcuData->InputDet.bits.Key1 = gpio_in.Key[1] ? 0 : 1;
+		ShmPrimaryMcuData->InputDet.bits.Key2 = gpio_in.Key[2] ? 0 : 1;
+		ShmPrimaryMcuData->InputDet.bits.Key3 = gpio_in.Key[3] ? 0 : 1;
+
+		char _SwValue = (ShmPrimaryMcuData->InputDet.bits.Key0 << 0) |
+		                (ShmPrimaryMcuData->InputDet.bits.Key1 << 1) |
+                        (ShmPrimaryMcuData->InputDet.bits.Key2 << 2) |
+                        (ShmPrimaryMcuData->InputDet.bits.Key3 << 3);
+		if(_TempSwitch != _SwValue)
+		{
+		    _SwitchCnt++;
+		    if(_SwitchCnt >= STATE_CHANGE_COUNT)
+		    {
+		        _TempSwitch = _SwValue;
+		        _SwitchCnt = 0;
+		    }
+		}
+
+		if(_CabinetSwitch != _TempSwitch)
+		{
+            LOG_INFO("Switch: %d, Key3: %d, Key2: %d, Key1: %d, Key0: %d",
+                _TempSwitch,
+                ShmPrimaryMcuData->InputDet.bits.Key3,
+                ShmPrimaryMcuData->InputDet.bits.Key2,
+                ShmPrimaryMcuData->InputDet.bits.Key1,
+                ShmPrimaryMcuData->InputDet.bits.Key0);
+		}
+        _CabinetSwitch = _TempSwitch;
+        if(_CabinetSwitch >= 0)
+        {
+            if(ShmChargerInfo->Control.CabinetSwitch != _CabinetSwitch)
+            {
+                LOG_INFO("Set Cabinet Switch: %d", _CabinetSwitch);
+            }
+            ShmChargerInfo->Control.CabinetSwitch = _CabinetSwitch;
+        }
 	}
 }
 

Файлын зөрүү хэтэрхий том тул дарагдсан байна
+ 284 - 166
EVSE/Projects/DO360/Apps/Module_PsuComm.c


+ 6 - 0
EVSE/Projects/DO360/Apps/Module_PsuComm.h

@@ -36,6 +36,12 @@ typedef unsigned char 		byte;
 typedef unsigned short 	    word;
 typedef unsigned int 		unit;
 
+#define PREPARE_STEP_NONE                   0
+#define PREPARE_STEP_CABLE_CHECK            1
+#define PREPARE_STEP_GFD_DONE               2
+#define PREPARE_STEP_PRECHARGE              3
+#define PREPARE_STEP_CHARGING               4
+
 struct ChargingInfoData *chargingInfo[CONNECTOR_QUANTITY];
 bool isStartOutputSwitch[CONNECTOR_QUANTITY];
 

+ 183 - 109
EVSE/Projects/DO360/Apps/ReadCmdline.c

@@ -42,9 +42,6 @@
 #include    "Common.h"
 
 typedef unsigned char			byte;
-#define PASS				1
-#define FAIL				-1
-#define ARRAY_SIZE(A)		(sizeof(A) / sizeof(A[0]))
 #define	NO_DEFINE			255
 #define DEFAULT_AC_INDEX	2
 
@@ -65,7 +62,6 @@ struct PsuData 					*ShmPsuData;
 ChargerInfoData                 *ShmChargerInfo;
 PsuPositionInfoData             *ShmPsuPosition;
 PsuGroupingInfoData             *ShmPsuGrouping;
-PsuGroupCollectionData          *ShmGroupCollection;
 
 struct ChargingInfoData 		*_chargingData[CONNECTOR_QUANTITY];
 struct ChargingInfoData 		*ac_chargingInfo[AC_QUANTITY];
@@ -247,7 +243,6 @@ int InitShareMemory()
     {
         ShmPsuPosition = &ShmChargerInfo->PsuPosition;
         ShmPsuGrouping = &ShmChargerInfo->PsuGrouping;
-        ShmGroupCollection = &ShmChargerInfo->PsuGrouping.GroupCollection[0];
     }
 
     return result;
@@ -608,7 +603,7 @@ void GetSystemInfo()
 	printf ("\r\nSerialNumber = %s", ShmSysConfigAndInfo->SysConfig.SerialNumber);
 	printf ("\r\nInternetConn = %d", ShmSysConfigAndInfo->SysInfo.InternetConn);
 
-	printf ("\r\nMaxChargingPower = %d, MaxChargingCurrent = %d",
+	printf ("\r\nMaxChargingPower = %d kW, MaxChargingCurrent = %d A",
 			ShmSysConfigAndInfo->SysConfig.MaxChargingPower,
 			ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
 	printf("\r\n\r\n");
@@ -1487,11 +1482,11 @@ void SetGroupRole(byte group, byte role)
 {
     if(group < GENERAL_GUN_QUANTITY)
     {
-        if(ShmGroupCollection[group].Role != role)
+        if(ShmChargerInfo->PsuGrouping.GroupCollection[group].Role != role)
         {
             //printf("\r\nSet Group %d Role = %d", group, role);
         }
-        ShmGroupCollection[group].Role = role;
+        ShmChargerInfo->PsuGrouping.GroupCollection[group].Role = role;
     }
 }
 
@@ -1500,9 +1495,9 @@ void SetGroupToIdle(byte group)
     if(group < GENERAL_GUN_QUANTITY)
     {
         SetGroupRole(group, _GROLE_IDLE);
-        ShmGroupCollection[group].Partner.Quantity = 0;
-        memset(ShmGroupCollection[group].Partner.Member, 0x00, ARRAY_SIZE(ShmGroupCollection[group].Partner.Member));
-        ShmGroupCollection[group].TargetGroup = 0;
+        ShmChargerInfo->PsuGrouping.GroupCollection[group].Partner.Quantity = 0;
+        memset(ShmChargerInfo->PsuGrouping.GroupCollection[group].Partner.Member, 0x00, ARRAY_SIZE(ShmChargerInfo->PsuGrouping.GroupCollection[group].Partner.Member));
+        ShmChargerInfo->PsuGrouping.GroupCollection[group].TargetGroup = 0;
         //printf("\r\n Reset Group %02X To Idle", group);
     }
 }
@@ -1512,7 +1507,7 @@ void SetGroupToMaster(byte group)
     if(group < GENERAL_GUN_QUANTITY)
     {
         SetGroupRole(group, _GROLE_MASTER);
-        ShmGroupCollection[group].TargetGroup = group + 1;
+        ShmChargerInfo->PsuGrouping.GroupCollection[group].TargetGroup = group + 1;
         //printf("\r\n Set Group %02X As Master", group);
     }
 }
@@ -1522,7 +1517,7 @@ void SetGroupToSlave(byte group, byte target)
     if(group < GENERAL_GUN_QUANTITY && target < GENERAL_GUN_QUANTITY)
     {
         SetGroupRole(group, _GROLE_SLAVE);
-        ShmGroupCollection[group].TargetGroup = target + 1;
+        ShmChargerInfo->PsuGrouping.GroupCollection[group].TargetGroup = target + 1;
         //printf("\r\n Set Group %02X As Slave", group);
     }
 }
@@ -1535,25 +1530,25 @@ void AddGroupCollection(byte group, byte target)
 
     if(group < GENERAL_GUN_QUANTITY && target < GENERAL_GUN_QUANTITY)
     {
-        if(ShmGroupCollection[target].Role != _GROLE_MASTER)
+        if(ShmChargerInfo->PsuGrouping.GroupCollection[target].Role != _GROLE_MASTER)
         {
             return;
         }
-        if(ShmGroupCollection[group].Role != _GROLE_IDLE &&
-            ShmGroupCollection[group].Role != _GROLE_WAIT_IDLE &&
-            ShmGroupCollection[group].Role != _GROLE_PRECHARGE_READY)
+        if(ShmChargerInfo->PsuGrouping.GroupCollection[group].Role != _GROLE_IDLE &&
+            ShmChargerInfo->PsuGrouping.GroupCollection[group].Role != _GROLE_WAIT_IDLE &&
+            ShmChargerInfo->PsuGrouping.GroupCollection[group].Role != _GROLE_PRECHARGE_READY)
         {
             return;
         }
 
         SetGroupToSlave(group, target);
-        ShmGroupCollection[target].Partner.Member[ShmGroupCollection[target].Partner.Quantity++] = group;
-        ParallelConfig = ShmGroupCollection[target].ParallelConfig[group];
+        ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Member[ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Quantity++] = group;
+        ParallelConfig = ShmChargerInfo->PsuGrouping.GroupCollection[target].ParallelConfig[group];
         if(ParallelConfig != 0)
         {
             ShmPsuGrouping->ParallelRelayConfig.CtrlValue |= (1 << (ParallelConfig - 1));
         }
-        //printf("\r\n Add Group %02X To Gun %d (Quantity %d), Set Parallel Relay %d On", group, target + 1, ShmGroupCollection[target].Partner.Quantity, ParallelConfig);
+        //printf("\r\n Add Group %02X To Gun %d (Quantity %d), Set Parallel Relay %d On", group, target + 1, ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Quantity, ParallelConfig);
     }
 }
 
@@ -1567,11 +1562,11 @@ void RemoveGroupCollection(byte group, byte target)
 
     if(group < GENERAL_GUN_QUANTITY && target < GENERAL_GUN_QUANTITY)
     {
-        for(int i = 0; i < ShmGroupCollection[target].Partner.Quantity; i++)
+        for(int i = 0; i < ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Quantity; i++)
         {
-            if(group == ShmGroupCollection[target].Partner.Member[i])
+            if(group == ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Member[i])
             {
-                ShmGroupCollection[target].Partner.Member[i] = 0;
+                ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Member[i] = 0;
                 location = i;
                 find = true;
                 break;
@@ -1579,20 +1574,20 @@ void RemoveGroupCollection(byte group, byte target)
         }
         if(find)
         {
-            for(int i = location + 1; i < ShmGroupCollection[target].Partner.Quantity; i++)
+            for(int i = location + 1; i < ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Quantity; i++)
             {
-                slave = ShmGroupCollection[target].Partner.Member[i];
-                ShmGroupCollection[target].Partner.Member[i] = 0;
-                ShmGroupCollection[target].Partner.Member[i - 1] = slave;
+                slave = ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Member[i];
+                ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Member[i] = 0;
+                ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Member[i - 1] = slave;
             }
-            ShmGroupCollection[target].Partner.Quantity--;
+            ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Quantity--;
             SetGroupToIdle(group);
-            ParallelConfig = ShmGroupCollection[target].ParallelConfig[group];
+            ParallelConfig = ShmChargerInfo->PsuGrouping.GroupCollection[target].ParallelConfig[group];
             if(ParallelConfig != 0)
             {
                 ShmPsuGrouping->ParallelRelayConfig.CtrlValue &= ~(1 << (ParallelConfig - 1));
             }
-            //printf("\r\n Remove Group %02X From Gun %d (Quantity %d), Clean Parallel Relay %d Off", group, target + 1, ShmGroupCollection[target].Partner.Quantity, ParallelConfig);
+            //printf("\r\n Remove Group %02X From Gun %d (Quantity %d), Clean Parallel Relay %d Off", group, target + 1, ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Quantity, ParallelConfig);
         }
     }
 }
@@ -1609,14 +1604,14 @@ void ShowGroupingInfo(void)
     {
         target = ShmPsuGrouping->Layout[i];
         printf("\r\n  %d   (%2d)   %2d  %d     %02X    ",
-            target + 1, _chargingData[target]->SystemStatus, ShmGroupCollection[target].Role,
-            ShmGroupCollection[target].Partner.Quantity, ShmGroupCollection[target].TargetGroup);
+            target + 1, _chargingData[target]->SystemStatus, ShmChargerInfo->PsuGrouping.GroupCollection[target].Role,
+            ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Quantity, ShmChargerInfo->PsuGrouping.GroupCollection[target].TargetGroup);
 
         for(int j = 0; j < 3; j++)
         {
-            if(ShmGroupCollection[target].Role == 1 && j < ShmGroupCollection[target].Partner.Quantity)
+            if(ShmChargerInfo->PsuGrouping.GroupCollection[target].Role == 1 && j < ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Quantity)
             {
-                printf("[%02X] ", ShmGroupCollection[target].Partner.Member[j]);
+                printf("[%02X] ", ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Member[j]);
             }
             else
             {
@@ -1640,19 +1635,19 @@ void PsuGroupSwitchToIdle(byte group)
 {
     int master = 0, quantity = 0, location = 0, total = 0;
 
-    if(ShmGroupCollection[group].Role != _GROLE_SLAVE)
+    if(ShmChargerInfo->PsuGrouping.GroupCollection[group].Role != _GROLE_SLAVE)
     {
         return;
     }
 
-    master = ShmGroupCollection[group].TargetGroup - 1;
-    quantity = ShmGroupCollection[master].Partner.Quantity;
+    master = ShmChargerInfo->PsuGrouping.GroupCollection[group].TargetGroup - 1;
+    quantity = ShmChargerInfo->PsuGrouping.GroupCollection[master].Partner.Quantity;
     //printf("\r\n Search Group %02X From Gun %d", group, master + 1);
     for(int i = 0; i < quantity; i++)
     {
         if(total == 0)
         {
-            if(group == ShmGroupCollection[master].Partner.Member[i])
+            if(group == ShmChargerInfo->PsuGrouping.GroupCollection[master].Partner.Member[i])
             {
                 location = i;
                 total++;
@@ -1662,20 +1657,20 @@ void PsuGroupSwitchToIdle(byte group)
         else
         {
             // find other group in the same direction
-            if(ShmPsuGrouping->Location[ShmGroupCollection[master].Partner.Member[location]] < ShmPsuGrouping->Location[master])
+            if(ShmPsuGrouping->Location[ShmChargerInfo->PsuGrouping.GroupCollection[master].Partner.Member[location]] < ShmPsuGrouping->Location[master])
             {
-                if(ShmPsuGrouping->Location[ShmGroupCollection[master].Partner.Member[i]] < ShmPsuGrouping->Location[master])
+                if(ShmPsuGrouping->Location[ShmChargerInfo->PsuGrouping.GroupCollection[master].Partner.Member[i]] < ShmPsuGrouping->Location[master])
                 {
                     total++;
-                    //printf("\r\n Find Other Group %02X In The Same Direction", ShmGroupCollection[master].Partner.Member[i]);
+                    //printf("\r\n Find Other Group %02X In The Same Direction", ShmChargerInfo->PsuGrouping.GroupCollection[master].Partner.Member[i]);
                 }
             }
-            if(ShmPsuGrouping->Location[ShmGroupCollection[master].Partner.Member[location]] > ShmPsuGrouping->Location[master])
+            if(ShmPsuGrouping->Location[ShmChargerInfo->PsuGrouping.GroupCollection[master].Partner.Member[location]] > ShmPsuGrouping->Location[master])
             {
-                if(ShmPsuGrouping->Location[ShmGroupCollection[master].Partner.Member[i]] > ShmPsuGrouping->Location[master])
+                if(ShmPsuGrouping->Location[ShmChargerInfo->PsuGrouping.GroupCollection[master].Partner.Member[i]] > ShmPsuGrouping->Location[master])
                 {
                     total++;
-                    //printf("\r\n Find Other Group %02X In The Same Direction", ShmGroupCollection[master].Partner.Member[i]);
+                    //printf("\r\n Find Other Group %02X In The Same Direction", ShmChargerInfo->PsuGrouping.GroupCollection[master].Partner.Member[i]);
                 }
             }
         }
@@ -1685,7 +1680,7 @@ void PsuGroupSwitchToIdle(byte group)
     {
         unsigned char collection[GENERAL_GUN_QUANTITY];
         //printf("\r\n There are %d Group Need To Switch Idle:", total);
-        memcpy(collection, ShmGroupCollection[master].Partner.Member, ARRAY_SIZE(ShmGroupCollection[master].Partner.Member));
+        memcpy(collection, ShmChargerInfo->PsuGrouping.GroupCollection[master].Partner.Member, ARRAY_SIZE(ShmChargerInfo->PsuGrouping.GroupCollection[master].Partner.Member));
 
         for(int i = 0; i < total; i++)
         {
@@ -1706,7 +1701,7 @@ void FindPsuGroupPartner(byte master, byte quantity, PsuGroupPartner *tPartner)
     memset(&partner, 0x00, sizeof(PsuGroupPartner));
 
     // search from left
-    location = ShmGroupCollection[master].Location - 1;
+    location = ShmChargerInfo->PsuGrouping.GroupCollection[master].Location - 1;
     for(int i = location; i >= 0; i--)
     {
         if(partner.Quantity >= quantity)
@@ -1715,14 +1710,14 @@ void FindPsuGroupPartner(byte master, byte quantity, PsuGroupPartner *tPartner)
         }
 
         slave = ShmPsuGrouping->Layout[i];
-        if(ShmGroupCollection[slave].Role == _GROLE_IDLE)
+        if(ShmChargerInfo->PsuGrouping.GroupCollection[slave].Role == _GROLE_IDLE)
         {
             //printf("\r\n Find Group %02X From Left", slave);
             partner.Member[partner.Quantity++] = slave;
         }
         else
         {
-            if(ShmGroupCollection[slave].Role == _GROLE_SLAVE && master == (ShmGroupCollection[slave].TargetGroup - 1))
+            if(ShmChargerInfo->PsuGrouping.GroupCollection[slave].Role == _GROLE_SLAVE && master == (ShmChargerInfo->PsuGrouping.GroupCollection[slave].TargetGroup - 1))
             {
                 continue;
             }
@@ -1731,7 +1726,7 @@ void FindPsuGroupPartner(byte master, byte quantity, PsuGroupPartner *tPartner)
     }
 
     // search from right
-    location = ShmGroupCollection[master].Location + 1;
+    location = ShmChargerInfo->PsuGrouping.GroupCollection[master].Location + 1;
     for(int i = location; i < 4; i++)
     {
         if(partner.Quantity >= quantity)
@@ -1740,14 +1735,14 @@ void FindPsuGroupPartner(byte master, byte quantity, PsuGroupPartner *tPartner)
         }
 
         slave = ShmPsuGrouping->Layout[i];
-        if(ShmGroupCollection[slave].Role == _GROLE_IDLE)
+        if(ShmChargerInfo->PsuGrouping.GroupCollection[slave].Role == _GROLE_IDLE)
         {
             //printf("\r\n Find Group %02X From Right", slave);
             partner.Member[partner.Quantity++] = slave;
         }
         else
         {
-            if(ShmGroupCollection[slave].Role == _GROLE_SLAVE && master == (ShmGroupCollection[slave].TargetGroup - 1))
+            if(ShmChargerInfo->PsuGrouping.GroupCollection[slave].Role == _GROLE_SLAVE && master == (ShmChargerInfo->PsuGrouping.GroupCollection[slave].TargetGroup - 1))
             {
                 continue;
             }
@@ -1769,17 +1764,17 @@ int GetPsuGroupAvailable(byte group)
     return partner.Quantity;
 #if 0
     // search from left
-    location = ShmGroupCollection[group].Location - 1;
+    location = ShmChargerInfo->PsuGrouping.GroupCollection[group].Location - 1;
     for(int i = location; i >= 0; i--)
     {
         slave = ShmPsuGrouping->Layout[i];
-        if(ShmGroupCollection[slave].Role == _GROLE_IDLE)
+        if(ShmChargerInfo->PsuGrouping.GroupCollection[slave].Role == _GROLE_IDLE)
         {
             available++;
         }
         else
         {
-            if(ShmGroupCollection[slave].Role == _GROLE_SLAVE && group == (ShmGroupCollection[slave].TargetGroup - 1))
+            if(ShmChargerInfo->PsuGrouping.GroupCollection[slave].Role == _GROLE_SLAVE && group == (ShmChargerInfo->PsuGrouping.GroupCollection[slave].TargetGroup - 1))
             {
                 continue;
             }
@@ -1787,17 +1782,17 @@ int GetPsuGroupAvailable(byte group)
         }
     }
     // search from right
-    location = ShmGroupCollection[group].Location + 1;
+    location = ShmChargerInfo->PsuGrouping.GroupCollection[group].Location + 1;
     for(int i = location; i < 4; i++)
     {
         slave = ShmPsuGrouping->Layout[i];
-        if(ShmGroupCollection[slave].Role == _GROLE_IDLE)
+        if(ShmChargerInfo->PsuGrouping.GroupCollection[slave].Role == _GROLE_IDLE)
         {
             available++;
         }
         else
         {
-            if(ShmGroupCollection[slave].Role == _GROLE_SLAVE && group == (ShmGroupCollection[slave].TargetGroup - 1))
+            if(ShmChargerInfo->PsuGrouping.GroupCollection[slave].Role == _GROLE_SLAVE && group == (ShmChargerInfo->PsuGrouping.GroupCollection[slave].TargetGroup - 1))
             {
                 continue;
             }
@@ -1816,18 +1811,18 @@ void PsuGroupShareCheck(byte group)
     //printf("\r\n Gun %d Total Group = %d", group + 1, total);
 
     // search from left
-    location = ShmGroupCollection[group].Location - 1;
+    location = ShmChargerInfo->PsuGrouping.GroupCollection[group].Location - 1;
     for(int i = location; i >= 0; i--)
     {
         slave = ShmPsuGrouping->Layout[i];
-        if(ShmGroupCollection[slave].Role == _GROLE_SLAVE)
+        if(ShmChargerInfo->PsuGrouping.GroupCollection[slave].Role == _GROLE_SLAVE)
         {
-            target = ShmGroupCollection[slave].TargetGroup - 1;
-            if((ShmGroupCollection[target].Partner.Quantity + 1) > total)
+            target = ShmChargerInfo->PsuGrouping.GroupCollection[slave].TargetGroup - 1;
+            if((ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Quantity + 1) > total)
             {
-                share = (ShmGroupCollection[target].Partner.Quantity + 1 - total) / 2;
+                share = (ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Quantity + 1 - total) / 2;
             }
-            //printf("\r\n Find Group %02X Have %d Resource Can Shared %d From Left", target, ShmGroupCollection[target].Partner.Quantity, share);
+            //printf("\r\n Find Group %02X Have %d Resource Can Shared %d From Left", target, ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Quantity, share);
             break;
         }
         else
@@ -1839,18 +1834,18 @@ void PsuGroupShareCheck(byte group)
     if(share == 0)
     {
         // search from right
-        location = ShmGroupCollection[group].Location + 1;
+        location = ShmChargerInfo->PsuGrouping.GroupCollection[group].Location + 1;
         for(int i = location; i < 4; i++)
         {
             slave = ShmPsuGrouping->Layout[i];
-            if(ShmGroupCollection[slave].Role == _GROLE_SLAVE)
+            if(ShmChargerInfo->PsuGrouping.GroupCollection[slave].Role == _GROLE_SLAVE)
             {
-                target = ShmGroupCollection[slave].TargetGroup - 1;
-                if((ShmGroupCollection[target].Partner.Quantity + 1) > total)
+                target = ShmChargerInfo->PsuGrouping.GroupCollection[slave].TargetGroup - 1;
+                if((ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Quantity + 1) > total)
                 {
-                    share = (ShmGroupCollection[target].Partner.Quantity + 1 - total) / 2;
+                    share = (ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Quantity + 1 - total) / 2;
                 }
-                //printf("\r\n Find Group %02X Have %d Resource Can Shared %d From Left", target, ShmGroupCollection[target].Partner.Quantity, share);
+                //printf("\r\n Find Group %02X Have %d Resource Can Shared %d From Left", target, ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Quantity, share);
                 break;
             }
             else
@@ -1877,17 +1872,17 @@ void SimplePsuGroupStartCharging(byte group)
     int available = 0;
     PsuGroupPartner partner;
 
-    if(ShmGroupCollection[group].Role == _GROLE_SLAVE)
+    if(ShmChargerInfo->PsuGrouping.GroupCollection[group].Role == _GROLE_SLAVE)
     {
         return;
     }
 
-    if(ShmGroupCollection[group].Role != _GROLE_IDLE && ShmGroupCollection[group].Role != _GROLE_MASTER)
+    if(ShmChargerInfo->PsuGrouping.GroupCollection[group].Role != _GROLE_IDLE && ShmChargerInfo->PsuGrouping.GroupCollection[group].Role != _GROLE_MASTER)
     {
         return;
     }
 
-    if(ShmGroupCollection[group].Role == _GROLE_IDLE)
+    if(ShmChargerInfo->PsuGrouping.GroupCollection[group].Role == _GROLE_IDLE)
     {
         SetGroupToMaster(group);
 
@@ -1916,18 +1911,18 @@ void SimplePsuGroupStartCharging(byte group)
 
 #if 0
     // search from left
-    location = ShmGroupCollection[group].Location - 1;
+    location = ShmChargerInfo->PsuGrouping.GroupCollection[group].Location - 1;
     for(int i = location; i >= 0; i--)
     {
         slave = ShmPsuGrouping->Layout[i];
-        if(ShmGroupCollection[slave].Role == _GROLE_IDLE)
+        if(ShmChargerInfo->PsuGrouping.GroupCollection[slave].Role == _GROLE_IDLE)
         {
             //printf("\r\n Find %02X From Left", slave);
             AddGroupCollection(slave, group);
         }
         else
         {
-            if(ShmGroupCollection[slave].Role == _GROLE_SLAVE && group == (ShmGroupCollection[slave].TargetGroup - 1))
+            if(ShmChargerInfo->PsuGrouping.GroupCollection[slave].Role == _GROLE_SLAVE && group == (ShmChargerInfo->PsuGrouping.GroupCollection[slave].TargetGroup - 1))
             {
                 continue;
             }
@@ -1936,18 +1931,18 @@ void SimplePsuGroupStartCharging(byte group)
     }
 
     // search from right
-    location = ShmGroupCollection[group].Location + 1;
+    location = ShmChargerInfo->PsuGrouping.GroupCollection[group].Location + 1;
     for(int i = location; i < 4; i++)
     {
         slave = ShmPsuGrouping->Layout[i];
-        if(ShmGroupCollection[slave].Role == _GROLE_IDLE)
+        if(ShmChargerInfo->PsuGrouping.GroupCollection[slave].Role == _GROLE_IDLE)
         {
             //printf("\r\n Find %02X From Right", slave);
             AddGroupCollection(slave, group);
         }
         else
         {
-            if(ShmGroupCollection[slave].Role == _GROLE_SLAVE && group == (ShmGroupCollection[slave].TargetGroup - 1))
+            if(ShmChargerInfo->PsuGrouping.GroupCollection[slave].Role == _GROLE_SLAVE && group == (ShmChargerInfo->PsuGrouping.GroupCollection[slave].TargetGroup - 1))
             {
                 continue;
             }
@@ -1961,17 +1956,17 @@ void PsuGroupStopCharging(byte group)
 {
     int total = 0;
 
-    if(ShmGroupCollection[group].Role != _GROLE_MASTER)
+    if(ShmChargerInfo->PsuGrouping.GroupCollection[group].Role != _GROLE_MASTER)
     {
         return;
     }
 
-    total = ShmGroupCollection[group].Partner.Quantity;
+    total = ShmChargerInfo->PsuGrouping.GroupCollection[group].Partner.Quantity;
     if(total > 0)
     {
         unsigned char collection[GENERAL_GUN_QUANTITY];
-        //printf("\r\n There are %d Group Need To Stop:", ShmGroupCollection[group].Partner.Quantity);
-        memcpy(collection, ShmGroupCollection[group].Partner.Member, ARRAY_SIZE(ShmGroupCollection[group].Partner.Member));
+        //printf("\r\n There are %d Group Need To Stop:", ShmChargerInfo->PsuGrouping.GroupCollection[group].Partner.Quantity);
+        memcpy(collection, ShmChargerInfo->PsuGrouping.GroupCollection[group].Partner.Member, ARRAY_SIZE(ShmChargerInfo->PsuGrouping.GroupCollection[group].Partner.Member));
 
         for(int i = 0; i < total; i++)
         {
@@ -2001,7 +1996,7 @@ void RunSimplePsuGrouping(char *v1, char *v2)
     {
         if(charging > 0)
         {
-            if(ShmGroupCollection[group].Role == _GROLE_SLAVE)
+            if(ShmChargerInfo->PsuGrouping.GroupCollection[group].Role == _GROLE_SLAVE)
             {
                 //printf("\r\nGroup %02X Is In Use, Need To Stop Charging", group);
                 PsuGroupSwitchToIdle(group);
@@ -2011,11 +2006,11 @@ void RunSimplePsuGrouping(char *v1, char *v2)
         }
         if(charging == 0)
         {
-            if(ShmGroupCollection[group].Role == _GROLE_MASTER)
+            if(ShmChargerInfo->PsuGrouping.GroupCollection[group].Role == _GROLE_MASTER)
             {
                 PsuGroupStopCharging(group);
             }
-            if(ShmGroupCollection[group].Role == _GROLE_SLAVE)
+            if(ShmChargerInfo->PsuGrouping.GroupCollection[group].Role == _GROLE_SLAVE)
             {
                 PsuGroupSwitchToIdle(group);
             }
@@ -2037,7 +2032,17 @@ void ShowCabinetInfo(void)
         ShmSysConfigAndInfo->SysInfo.DispenserInfo.DispenserQuantity,
         ShmSysConfigAndInfo->SysInfo.DispenserInfo.PresentConnectorQuantity,
         ShmSysConfigAndInfo->SysInfo.DispenserInfo.TotalConnectorQuantity);
+    printf("\r\n");
+    for(int i = 0; i < GENERAL_GUN_QUANTITY; i++)
+    {
+        ipAddress = ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[i].IpAddress;
 
+        printf("\r\n Dispenser Connection[%d] Status: %d, DispenserIndex: %d, IP: %d.%d.%d.%d", i,
+                ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[i].Status,
+                ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[i].DispenserIndex,
+                ((ipAddress >> 0) & 0xFF), ((ipAddress >> 8) & 0xFF), ((ipAddress >> 16) & 0xFF), ((ipAddress >> 24) & 0xFF));
+    }
+    printf("\r\n");
     for(int i = 0; i < GENERAL_GUN_QUANTITY; i++)
     {
         printf("\r\n Connector[%d] Index: %2X, Status = %2d , %s", i, _chargingData[i]->Index, _chargingData[i]->SystemStatus,
@@ -2136,9 +2141,9 @@ void ShowGroupingDemand(void)
     for(int i = 0; i < 4; i++)
     {
         target = ShmPsuGrouping->Layout[i];
-        if(ShmGroupCollection[target].TargetGroup != 0)
+        if(ShmChargerInfo->PsuGrouping.GroupCollection[target].TargetGroup != 0)
         {
-            k1k2 = _chargingData[ShmGroupCollection[target].TargetGroup - 1]->RelayK1K2Status;
+            k1k2 = _chargingData[ShmChargerInfo->PsuGrouping.GroupCollection[target].TargetGroup - 1]->RelayK1K2Status;
         }
         else
         {
@@ -2146,16 +2151,16 @@ void ShowGroupingDemand(void)
         }
 
         printf("\r\n  %d    %2d     %02X      %d     %4d V    %3d.%d A       %4d A         %3d.%02d",
-            target + 1, ShmGroupCollection[target].Role, ShmGroupCollection[target].TargetGroup, k1k2,
+            target + 1, ShmChargerInfo->PsuGrouping.GroupCollection[target].Role, ShmChargerInfo->PsuGrouping.GroupCollection[target].TargetGroup, k1k2,
             (ShmPsuGrouping->GroupOutput[target].GTargetVoltage / 10),
             (ShmPsuGrouping->GroupOutput[target].GTargetCurrent / 10),
             (ShmPsuGrouping->GroupOutput[target].GTargetCurrent % 10),
             (int)(_chargingData[target]->AvailableChargingCurrent / 10),
             (ShmPsuGrouping->GroupOutput[target].OutputLoading / 100),
             (ShmPsuGrouping->GroupOutput[target].OutputLoading % 100));
-        if(ShmGroupCollection[target].TargetGroup == target + 1)
+        if(ShmChargerInfo->PsuGrouping.GroupCollection[target].TargetGroup == target + 1)
         {
-            printf("       %3d.%02d", (ShmGroupCollection[target].GunLoading / 100), (ShmGroupCollection[target].GunLoading % 100));
+            printf("       %3d.%02d", (ShmChargerInfo->PsuGrouping.GroupCollection[target].GunLoading / 100), (ShmChargerInfo->PsuGrouping.GroupCollection[target].GunLoading % 100));
         }
     }
 
@@ -2190,7 +2195,7 @@ void SetGunStartCharging(char *v1, char *v2, char *v3)
         ShmChargerInfo->Control.FCharging[gun - 1].FTargetVoltage = _voltage * 10;
         ShmChargerInfo->Control.FCharging[gun - 1].FTargetCurrent = _current * 10;
     }
-    else if(ShmGroupCollection[gun - 1].Role == _GROLE_MASTER)
+    else if(ShmChargerInfo->PsuGrouping.GroupCollection[gun - 1].Role == _GROLE_MASTER)
     {
         if(ShmChargerInfo->Control.FCharging[gun - 1].FCtrl.bits.EnableForceCharging)
         {
@@ -2418,10 +2423,10 @@ void SetGunStopCharging(char *v1)
         printf("\r\nSet Gun %d Stop Charging(ManualStop)", gun);
         _chargingData[gun - 1]->ChargingStopFlag.bits.ManualStop = true;
     }
-    else if(ShmGroupCollection[gun - 1].Role == _GROLE_SLAVE)
+    else if(ShmChargerInfo->PsuGrouping.GroupCollection[gun - 1].Role == _GROLE_SLAVE)
     {
         printf("\r\nSet Group [%02X] Stop", gun - 1);
-        ShmGroupCollection[gun - 1].GroupCtrl.bits.SlavePowerOffRequest = true;
+        ShmChargerInfo->PsuGrouping.GroupCollection[gun - 1].GroupCtrl.bits.SlavePowerOffRequest = true;
     }
     else
     {
@@ -2447,10 +2452,10 @@ void SetGunStopCharging(char *v1)
 
                     if(PreviousSystemStatus == 0xFF)
                     {
-                        if(ShmGroupCollection[gun - 1].Role == _GROLE_SLAVE)
+                        if(ShmChargerInfo->PsuGrouping.GroupCollection[gun - 1].Role == _GROLE_SLAVE)
                         {
                             printf("\r\nSet Group [%02X] Stop", gun - 1);
-                            ShmGroupCollection[gun - 1].GroupCtrl.bits.SlavePowerOffRequest = true;
+                            ShmChargerInfo->PsuGrouping.GroupCollection[gun - 1].GroupCtrl.bits.SlavePowerOffRequest = true;
                         }
                     }
                     PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
@@ -2633,10 +2638,10 @@ void SetGunExtend(char *v1)
 
     gun = atoi(v1);
 
-    if(_chargingData[gun - 1]->SystemStatus == S_CHARGING && ShmGroupCollection[gun - 1].Role == _GROLE_MASTER)
+    if(_chargingData[gun - 1]->SystemStatus == S_CHARGING && ShmChargerInfo->PsuGrouping.GroupCollection[gun - 1].Role == _GROLE_MASTER)
     {
         printf("\r\nSet Group [%02X] Extend Capability", gun - 1);
-        ShmGroupCollection[gun - 1].GroupCtrl.bits.MorePowerRequest = true;
+        ShmChargerInfo->PsuGrouping.GroupCollection[gun - 1].GroupCtrl.bits.MorePowerRequest = true;
     }
     else
     {
@@ -2815,6 +2820,71 @@ void EraseWhiteCard(char *v1)
     printf("\r\n\r\n");
 }
 
+void ShowChargerLimit(void)
+{
+    int limitPower = -1;
+    char *str_gun_type[] = {STR_GUN_TYPE_CHADEMO, STR_GUN_TYPE_CCS, STR_GUN_TYPE_GBT};
+    unsigned char inUsingCnt = 0;
+
+    printf("\r\nCharger Limit");
+
+    printf("\r\n System Psu Cnt: %2d", ShmPsuData->SystemPresentPsuQuantity);
+    printf("\r\n Charger Max ChargingProfile Power: %d kW", ShmSysConfigAndInfo->SysInfo.MaxChargingProfilePower == -1 ?
+        (int)ShmSysConfigAndInfo->SysInfo.MaxChargingProfilePower : (int)ShmSysConfigAndInfo->SysInfo.MaxChargingProfilePower / 1000);
+    printf("\r\n Max Total Current: %d A, Max Total Power: %d kW, Total Energy: %d kW, Total Duration %d",
+        ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent, ShmSysConfigAndInfo->SysConfig.MaxChargingPower,
+        ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy, ShmSysConfigAndInfo->SysConfig.MaxChargingDuration);
+
+    printf("\r\n\r\n Gun Enable    Type  Psu  Phy_Vol  Phy_Cur  Config_Ocpp_MaxOcpp_Pow  Config_Ocpp_MaxOcpp_Cur");
+    for(int i = 0; i < GENERAL_GUN_QUANTITY; i++)
+    {
+        inUsingCnt = 0;
+        for(int j = 0; j < GENERAL_GUN_QUANTITY; j++)
+        {
+            if(ShmChargerInfo->PsuGrouping.GroupCollection[j].Role == _GROLE_MASTER)
+            {
+                inUsingCnt += ShmChargerInfo->PsuGrouping.GroupCollection[i].GunPsuQuantity;
+            }
+        }
+        // Gun Enable    Type  Psu  Phy_Vol  Phy_Cur  Config_Ocpp_MaxOcpp_Pow  Config_Ocpp_MaxOcpp_Cur
+        //  1    0    CHAdeMO   00   0000 V   0000 A    0000 / 0000 / 0000 kW     0000 / 0000 A
+        // Gun 1  Enable, Type: CCS, Psu Cnt: 00, Max Physical Vol: 0000 V, Cur: 0000 A, Max Config Pow: 0000 kW, Cur: 0000 A
+        printf("\r\n  %d    %d   ", i + 1, ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].Enable);
+        if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].Enable)
+        {
+            printf(" %7s   %2d",
+                _chargingData[i]->Type <= _Type_GB ? str_gun_type[_chargingData[i]->Type] : "???",
+                ShmChargerInfo->PsuGrouping.GroupCollection[i].GunPsuQuantity);
+            printf("   %4d V   %4d A",
+                (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].RemoteMaxPhysicalVoltage / 10),
+                (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].RemoteMaxPhysicalCurrent / 10));
+
+            if(ShmSysConfigAndInfo->SysInfo.MaxChargingProfilePower != -1)
+            {
+                limitPower = (int)ShmSysConfigAndInfo->SysInfo.MaxChargingProfilePower;
+                if(inUsingCnt > 0)
+                {
+                    limitPower = (limitPower * ShmChargerInfo->PsuGrouping.GroupCollection[i].GunPsuQuantity) / inUsingCnt;
+                }
+            }
+            else
+            {
+                limitPower = -1;
+            }
+            printf("    %4d / %4d / %4d kW",
+                (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].MaxTotalChargingPower / 10),
+                _chargingData[i]->ChargingProfilePower == -1 ? (int)_chargingData[i]->ChargingProfilePower : ((int)_chargingData[i]->ChargingProfilePower / 1000),
+                limitPower == -1 ? limitPower : (limitPower / 1000));
+
+            printf("     %4d / %4d A",
+                ((int)ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].MaxTotalChargingCurrent / 10),
+                _chargingData[i]->ChargingProfileCurrent == -1 ? (int)_chargingData[i]->ChargingProfileCurrent : ((int)_chargingData[i]->ChargingProfileCurrent / 10));
+        }
+    }
+
+    printf("\r\n\r\n");
+}
+
 int main(void)
 {
 	if(InitShareMemory() == FAIL)
@@ -2837,18 +2907,18 @@ int main(void)
     }
 
     /*
-    memset(&ShmGroupCollection[0], 0x00, sizeof(PsuGroupCollectionData));
-    memset(&ShmGroupCollection[1], 0x00, sizeof(PsuGroupCollectionData));
-    memset(&ShmGroupCollection[2], 0x00, sizeof(PsuGroupCollectionData));
-    memset(&ShmGroupCollection[3], 0x00, sizeof(PsuGroupCollectionData));
-    ShmGroupCollection[0].Index = 0;
-    ShmGroupCollection[1].Index = 1;
-    ShmGroupCollection[2].Index = 2;
-    ShmGroupCollection[3].Index = 3;
-    ShmGroupCollection[0].Location = 0;
-    ShmGroupCollection[1].Location = 3;
-    ShmGroupCollection[2].Location = 1;
-    ShmGroupCollection[3].Location = 2;
+    memset(&ShmChargerInfo->PsuGrouping.GroupCollection[0], 0x00, sizeof(PsuGroupCollectionData));
+    memset(&ShmChargerInfo->PsuGrouping.GroupCollection[1], 0x00, sizeof(PsuGroupCollectionData));
+    memset(&ShmChargerInfo->PsuGrouping.GroupCollection[2], 0x00, sizeof(PsuGroupCollectionData));
+    memset(&ShmChargerInfo->PsuGrouping.GroupCollection[3], 0x00, sizeof(PsuGroupCollectionData));
+    ShmChargerInfo->PsuGrouping.GroupCollection[0].Index = 0;
+    ShmChargerInfo->PsuGrouping.GroupCollection[1].Index = 1;
+    ShmChargerInfo->PsuGrouping.GroupCollection[2].Index = 2;
+    ShmChargerInfo->PsuGrouping.GroupCollection[3].Index = 3;
+    ShmChargerInfo->PsuGrouping.GroupCollection[0].Location = 0;
+    ShmChargerInfo->PsuGrouping.GroupCollection[1].Location = 3;
+    ShmChargerInfo->PsuGrouping.GroupCollection[2].Location = 1;
+    ShmChargerInfo->PsuGrouping.GroupCollection[3].Location = 2;
     */
 
 	for(;;)
@@ -3182,6 +3252,10 @@ int main(void)
                 continue;
             }
             EraseWhiteCard(newString[1]);
+        }
+        else if(strcmp(newString[0], "limit") == 0)
+        {
+            ShowChargerLimit();
         }
 		else
 			printf ("%s\n", msg);

+ 3 - 0
EVSE/Projects/DO360/Apps/kill.sh

@@ -11,3 +11,6 @@ pkill OcppBackend
 pkill Module_ProduceUtils
 pkill main
 
+sleep 1
+
+echo V > /dev/watchdog

BIN
EVSE/Projects/DO360/Apps/libInfyGroup_PsuCommObj.a


Файлын зөрүү хэтэрхий том тул дарагдсан байна
+ 421 - 152
EVSE/Projects/DO360/Apps/main.c


BIN
EVSE/Projects/DO360/Images/FactoryDefaultConfig.bin


BIN
EVSE/Projects/DO360/Images/ramdisk.gz


Энэ ялгаанд хэт олон файл өөрчлөгдсөн тул зарим файлыг харуулаагүй болно