Эх сурвалжийг харах

2021-09-22 / Wendell

Actions
1. use clock time to count SystemTimeoutTimer
2. add PantographFlag logic
3. add gfd function in DoComm
3. send cabinet's output voltage and current to ev board when PantographFlag is set

Files
1. As follow commit history

Image version : V1.14.XX.XXXX.XX
Wendell 3 жил өмнө
parent
commit
1a480ff1a3
57 өөрчлөгдсөн 852 нэмэгдсэн , 342 устгасан
  1. 15 0
      EVSE/Projects/DD360/Apps/CSU/SelfTest.c
  2. 32 12
      EVSE/Projects/DD360/Apps/CSU/main.c
  3. 105 82
      EVSE/Projects/DD360/Apps/Define/define.h
  4. 67 6
      EVSE/Projects/DD360/Apps/ModuleDoComm/DoComm.c
  5. 5 0
      EVSE/Projects/DD360/Apps/ModuleDoComm/DoComm.h
  6. 11 9
      EVSE/Projects/DD360/Apps/ModuleEvComm/Module_EvTxComm.c
  7. 4 1
      EVSE/Projects/DD360/Apps/ModuleInternalComm/Module_InternalComm.c
  8. 41 4
      EVSE/Projects/DD360/Apps/ModuleInternalComm/RelayBoard.c
  9. 4 0
      EVSE/Projects/DD360/Apps/ShareMemory/shmMem.c
  10. BIN
      EVSE/Projects/DD360/Images/ramdisk.gz
  11. BIN
      EVSE/Projects/DD360/output/FactoryConfig
  12. BIN
      EVSE/Projects/DD360/output/Module_DoComm
  13. BIN
      EVSE/Projects/DD360/output/Module_EvComm
  14. BIN
      EVSE/Projects/DD360/output/Module_EventLogging
  15. BIN
      EVSE/Projects/DD360/output/Module_InternalComm
  16. BIN
      EVSE/Projects/DD360/output/Module_LcmControl
  17. BIN
      EVSE/Projects/DD360/output/Module_PrimaryComm
  18. BIN
      EVSE/Projects/DD360/output/ReadCmdline
  19. BIN
      EVSE/Projects/DD360/output/main
  20. 15 0
      EVSE/Projects/DD360Audi/Apps/CSU/SelfTest.c
  21. 32 12
      EVSE/Projects/DD360Audi/Apps/CSU/main.c
  22. 105 82
      EVSE/Projects/DD360Audi/Apps/Define/define.h
  23. 67 6
      EVSE/Projects/DD360Audi/Apps/ModuleDoComm/DoComm.c
  24. 5 0
      EVSE/Projects/DD360Audi/Apps/ModuleDoComm/DoComm.h
  25. 11 9
      EVSE/Projects/DD360Audi/Apps/ModuleEvComm/Module_EvTxComm.c
  26. 4 1
      EVSE/Projects/DD360Audi/Apps/ModuleInternalComm/Module_InternalComm.c
  27. 41 4
      EVSE/Projects/DD360Audi/Apps/ModuleInternalComm/RelayBoard.c
  28. 4 0
      EVSE/Projects/DD360Audi/Apps/ShareMemory/shmMem.c
  29. BIN
      EVSE/Projects/DD360Audi/Images/ramdisk.gz
  30. BIN
      EVSE/Projects/DD360Audi/output/FactoryConfig
  31. BIN
      EVSE/Projects/DD360Audi/output/Module_DoComm
  32. BIN
      EVSE/Projects/DD360Audi/output/Module_EvComm
  33. BIN
      EVSE/Projects/DD360Audi/output/Module_EventLogging
  34. BIN
      EVSE/Projects/DD360Audi/output/Module_InternalComm
  35. BIN
      EVSE/Projects/DD360Audi/output/Module_LcmControl
  36. BIN
      EVSE/Projects/DD360Audi/output/Module_PrimaryComm
  37. BIN
      EVSE/Projects/DD360Audi/output/ReadCmdline
  38. BIN
      EVSE/Projects/DD360Audi/output/main
  39. 15 0
      EVSE/Projects/DD360ComBox/Apps/CSU/SelfTest.c
  40. 32 12
      EVSE/Projects/DD360ComBox/Apps/CSU/main.c
  41. 105 82
      EVSE/Projects/DD360ComBox/Apps/Define/define.h
  42. 67 6
      EVSE/Projects/DD360ComBox/Apps/ModuleDoComm/DoComm.c
  43. 5 0
      EVSE/Projects/DD360ComBox/Apps/ModuleDoComm/DoComm.h
  44. 11 9
      EVSE/Projects/DD360ComBox/Apps/ModuleEvComm/Module_EvTxComm.c
  45. 4 1
      EVSE/Projects/DD360ComBox/Apps/ModuleInternalComm/Module_InternalComm.c
  46. 41 4
      EVSE/Projects/DD360ComBox/Apps/ModuleInternalComm/RelayBoard.c
  47. 4 0
      EVSE/Projects/DD360ComBox/Apps/ShareMemory/shmMem.c
  48. BIN
      EVSE/Projects/DD360ComBox/Images/ramdisk.gz
  49. BIN
      EVSE/Projects/DD360ComBox/output/FactoryConfig
  50. BIN
      EVSE/Projects/DD360ComBox/output/Module_DoComm
  51. BIN
      EVSE/Projects/DD360ComBox/output/Module_EvComm
  52. BIN
      EVSE/Projects/DD360ComBox/output/Module_EventLogging
  53. BIN
      EVSE/Projects/DD360ComBox/output/Module_InternalComm
  54. BIN
      EVSE/Projects/DD360ComBox/output/Module_LcmControl
  55. BIN
      EVSE/Projects/DD360ComBox/output/Module_PrimaryComm
  56. BIN
      EVSE/Projects/DD360ComBox/output/ReadCmdline
  57. BIN
      EVSE/Projects/DD360ComBox/output/main

+ 15 - 0
EVSE/Projects/DD360/Apps/CSU/SelfTest.c

@@ -18,6 +18,7 @@ extern void ChkPrimaryStatus(void);
 void SelfTestRun(void)
 {
     bool evInitFlag = false;
+    bool isRelayBypass = false;
     uint8_t index = 0;
     struct SysConfigData *pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
     struct SysInfoData *pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
@@ -34,6 +35,15 @@ void SelfTestRun(void)
     struct ChargingInfoData *pDcChargingInfo = NULL;
     struct ChargingInfoData *pAcChargingInfo = NULL;
 
+    for(int i = 0; i < pSysConfig->TotalConnectorCount; i++)
+    {
+        pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(i);
+        if(pDcChargingInfo->PantographFlag == YES)
+        {
+            isRelayBypass = true;
+        }
+    }
+
     StartSystemTimeoutDet(Timeout_SelftestChk);
     pSysInfo->SelfTestSeq = _STEST_VERSION;
 
@@ -62,6 +72,11 @@ void SelfTestRun(void)
 
         switch (pSysInfo->SelfTestSeq) {
         case _STEST_VERSION:
+            if(isRelayBypass == YES && ShmRelayModuleData->SelfTest_Comp != YES)
+            {
+                log_info("Relay Board Bypass");
+                ShmRelayModuleData->SelfTest_Comp = YES;
+            }
             if ((strlen((char *)pSysInfo->RelayModuleFwRev) != 0 ||
                     pSysInfo->RelayModuleFwRev[0] != '\0') &&
                     (ShmRelayModuleData->SelfTest_Comp != YES)

+ 32 - 12
EVSE/Projects/DD360/Apps/CSU/main.c

@@ -77,7 +77,7 @@ uint8_t bd0_2_status = 0;
 uint8_t bd1_1_status = 0;
 uint8_t bd1_2_status = 0;
 
-char *fwVersion = "V1.13.00.0000.00"; // "V0.16.00.0000.00";
+char *fwVersion = "V1.14.00.0000.00"; // "V0.16.00.0000.00";
 
 //sqlite3 *localDb;
 bool isDb_ready;
@@ -89,6 +89,8 @@ long long DiffTimebWithNow(struct timeb ST);
 uint8_t DetectBitValue(uint8_t _byte, uint8_t _bit);
 void SetBitValue(uint8_t *_byte, uint8_t _bit, uint8_t value);
 unsigned long GetTimeoutValue(struct timeval _sour_time);
+void GetClockTime(struct timespec *_now_time, void *null);
+unsigned long GetClockTimeoutValue(struct timespec _start_time);
 void gpio_set_value(unsigned int gpio, unsigned int value);
 void InformOcppErrOccur(uint8_t codeType);
 
@@ -753,6 +755,24 @@ unsigned long GetTimeoutValue(struct timeval _sour_time)
     return 1000000 * (_end_time.tv_sec - _sour_time.tv_sec) + _end_time.tv_usec - _sour_time.tv_usec;
 }
 
+void GetClockTime(struct timespec *_now_time, void *null)
+{
+    clock_gettime(CLOCK_MONOTONIC, _now_time);
+}
+
+// return value unit: 1us
+unsigned long GetClockTimeoutValue(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) * 1000000) + ((unsigned long)((ts_end.tv_nsec / 1000) - (_start_time.tv_nsec/ 1000)));
+
+    return ret;
+}
+
 int DiffTimeb(struct timeb ST, struct timeb ET)
 {
     //return milli-second
@@ -2645,14 +2665,14 @@ void KillAllTask(void)
 void StartSystemTimeoutDet(uint8_t flag)
 {
     if (pSysInfo->SystemTimeoutFlag != flag) {
-        gettimeofday(&pSysInfo->SystemTimeoutTimer, NULL);
+        GetClockTime(&pSysInfo->SystemTimeoutTimer, NULL);
     }
     pSysInfo->SystemTimeoutFlag = flag;
 }
 
 void StopSystemTimeoutDet(void)
 {
-    gettimeofday(&pSysInfo->SystemTimeoutTimer, NULL);
+    GetClockTime(&pSysInfo->SystemTimeoutTimer, NULL);
     pSysInfo->SystemTimeoutFlag = Timeout_None;
 }
 
@@ -2724,7 +2744,7 @@ void CreateTimeoutFork(void)
             // 系統
             switch (pSysInfo->SystemTimeoutFlag) {
             case Timeout_SelftestChk:
-                if (GetTimeoutValue(pSysInfo->SystemTimeoutTimer) / uSEC_VAL >= SELFTEST_TIMEOUT) {
+                if (GetClockTimeoutValue(pSysInfo->SystemTimeoutTimer) / uSEC_VAL >= SELFTEST_TIMEOUT) {
                     _SelfTestTimeout();
                     StopSystemTimeoutDet();
                     destroySelGun(DESTROY_ALL_SEL); //jerry add
@@ -2732,7 +2752,7 @@ void CreateTimeoutFork(void)
                 break;
 
             case Timeout_Authorizing:
-                if (GetTimeoutValue(pSysInfo->SystemTimeoutTimer) / uSEC_VAL >= AUTHORIZE_TIMEOUT) {
+                if (GetClockTimeoutValue(pSysInfo->SystemTimeoutTimer) / uSEC_VAL >= AUTHORIZE_TIMEOUT) {
                     _AuthorizedTimeout();
                     StopSystemTimeoutDet();
                     destroySelGun(pSysInfo->CurGunSelected);
@@ -2748,7 +2768,7 @@ void CreateTimeoutFork(void)
                 break;
 
             case Timeout_VerifyFail:
-                if (GetTimeoutValue(pSysInfo->SystemTimeoutTimer) / uSEC_VAL >= AUTHORIZE_FAIL_TIMEOUT) {
+                if (GetClockTimeoutValue(pSysInfo->SystemTimeoutTimer) / uSEC_VAL >= AUTHORIZE_FAIL_TIMEOUT) {
                     _AutoReturnTimeout();
                     StopSystemTimeoutDet();
                     destroySelGun(pSysInfo->CurGunSelected);
@@ -2764,14 +2784,14 @@ void CreateTimeoutFork(void)
                 break;
 
             case Timeout_VerifyComp:
-                if (GetTimeoutValue(pSysInfo->SystemTimeoutTimer) / uSEC_VAL >= AUTHORIZE_COMP_TIMEOUT) {
+                if (GetClockTimeoutValue(pSysInfo->SystemTimeoutTimer) / uSEC_VAL >= AUTHORIZE_COMP_TIMEOUT) {
                     _AutoReturnTimeout();
                     StopSystemTimeoutDet();
                 }
                 break;
 
             case Timeout_WaitPlug:
-                if (GetTimeoutValue(pSysInfo->SystemTimeoutTimer) / uSEC_VAL >= _connectionTimeout) {
+                if (GetClockTimeoutValue(pSysInfo->SystemTimeoutTimer) / uSEC_VAL >= _connectionTimeout) {
                     _DetectPlugInTimeout();
                     StopSystemTimeoutDet();
                     destroySelGun(pSysInfo->CurGunSelected);
@@ -2779,7 +2799,7 @@ void CreateTimeoutFork(void)
                 break;
 
             case Timeout_ReturnToChargingGunDet:
-                if (GetTimeoutValue(pSysInfo->SystemTimeoutTimer) / uSEC_VAL >= RETURN_TO_CHARGING_PAGE) {
+                if (GetClockTimeoutValue(pSysInfo->SystemTimeoutTimer) / uSEC_VAL >= RETURN_TO_CHARGING_PAGE) {
 #if defined DD360Audi
                     if (getCurLcmPage() != _LCM_PRE_CHARGE &&
                             getCurLcmPage() != _LCM_CHARGING &&
@@ -2794,7 +2814,7 @@ void CreateTimeoutFork(void)
                 break;
 
             case Timeout_AuthorizingForStop:
-                if (GetTimeoutValue(pSysInfo->SystemTimeoutTimer) / uSEC_VAL >= AUTHORIZE_STOP_TIMEOUT) {
+                if (GetClockTimeoutValue(pSysInfo->SystemTimeoutTimer) / uSEC_VAL >= AUTHORIZE_STOP_TIMEOUT) {
                     strcpy((char *)pSysConfig->UserId, "");
                     ClearAuthorizedFlag();
                     StopSystemTimeoutDet();
@@ -4996,7 +5016,7 @@ int main(void)
                 // 切換 D+ Relay to Precharge Relay
                 if (isPrechargeStatus_ccs(gunIndex) == 39 ||
                         isPrechargeStatus_ccs(gunIndex) == 40) {
-                    if (pDcChargingInfo->RelayKPK2Status == YES &&
+                    if ((pDcChargingInfo->RelayKPK2Status == YES || pDcChargingInfo->PantographFlag == YES) &&
                             pDcChargingInfo->PrechargeStatus != PRECHARGE_READY)
                         //if (pDcChargingInfo->PrechargeStatus != PRECHARGE_PRERELAY_PASS)
                     {
@@ -5041,7 +5061,7 @@ int main(void)
 
                 // 等待小板通知進入充電
                 // 切換 D+ Relay to Precharge Relay
-                if (pDcChargingInfo->RelayK1K2Status == YES) {
+                if (pDcChargingInfo->RelayK1K2Status == YES || pDcChargingInfo->PantographFlag == YES) {
                     pDcChargingInfo->PrechargeStatus = PRECHARGE_READY;
                     setChargerMode(gunIndex, MODE_CHARGING);
                 }

+ 105 - 82
EVSE/Projects/DD360/Apps/Define/define.h

@@ -176,6 +176,11 @@ Storage							0x0A200000-0x7FFFFFFF		1886 MB
 /**************************************************************************************/
 /****************** Share memory configuration value constant define ******************/
 /**************************************************************************************/
+struct NoneUse
+{
+    unsigned char       unknown;                    // None use struct
+};
+
 enum SYSTEM_STATUS
 {
 	SYS_MODE_BOOTING		= 0,
@@ -287,7 +292,7 @@ enum CoreProfile {
 	 TransactionMessageRetryInterval,
 	 UnlockConnectorOnEVSideDisconnect,
 	 WebSocketPingInterval,
-	 QueueOffLineStartTransactionMessage,
+	 QueueOffLineMeterValues,
 	 AuthorizationKey,
 	 SecurityProfile,
      DefaultPrice,
@@ -304,15 +309,21 @@ enum OCPP_RUNNING_VERSION {
     OCPP_RUNNING_VERSION_16=0,
     OCPP_RUNNING_VERSION_20
 };
+
+enum OCPP_START_ID_TYPE {
+    IdTokenType_Central=0,
+    IdTokenType_eMAID,
+    IdTokenType_ISO14443,
+    IdTokenType_KeyCode,
+    IdTokenType_Local,
+    IdTokenType_NoAuthorization,
+    IdTokenType_ISO15693
+};
 /**************************************************************************************/
 /****structure SysConfigData => shall store the data to NAND flash****************/
 /****structure SysInfoData => shall NOT store the data to NAND flash***************/
 /****according to System Configuration and Information Table.xlsx Rev.0.2 *******/
 /**************************************************************************************/
-struct NoneUse
-{
-	unsigned char		unknown;					// None use struct
-};
 
 struct EthConfigData
 {
@@ -454,9 +465,9 @@ typedef struct
     unsigned int isCalibratedCaOffset:1;                // Current phase a offset is calibrated, 0: default 1: Calibrated
     unsigned int isCalibratedCbOffset:1;                // Current phase b offset is calibrated, 0: default 1: Calibrated
     unsigned int isCalibratedCcOffset:1;                // Current phase c offset is calibrated, 0: default 1: Calibrated
-    unsigned int isCalibratedPa:1;                      // Phase angle a is calibrated, 0: default  1: Calibrated
-    unsigned int isCalibratedPb:1;                      // Phase angle b gain is calibrated, 0: default 1: Calibrated
-    unsigned int isCalibratedPc:1;                      // Phase angle c gain is calibrated, 0: default 1: Calibrated
+    unsigned int isCalibratedPa:1;                      // Phase angle a is calibrated, 0: default          1: Calibrated
+    unsigned int isCalibratedPb:1;                      // Phase angle b gain is calibrated, 0: default     1: Calibrated
+    unsigned int isCalibratedPc:1;                      // Phase angle c gain is calibrated, 0: default     1: Calibrated
     unsigned int :1;
 }MeterIcCalibration;
 
@@ -515,8 +526,8 @@ struct SysConfigData
 	unsigned char 			OcppServerURL[512];			//http: non-secure OCPP 1.5-S, https: secure OCPP 1.5-S, ws: non-secure OCPP 1.6-J, wss: secure OCPP 1.6-J"
 	unsigned char 			ChargeBoxId[128];
 	unsigned char			chargePointVendor[20];		//the Vendor of the ChargePoint
-	unsigned char			OcppSecurityProfile;		//OCPP security profile 0~3
-	unsigned char			OcppSecurityPassword[41];	//OCPP AuthorizationKey for security profile
+    unsigned char           OcppSecurityProfile;        //OCPP security profile 0~3
+    unsigned char           OcppSecurityPassword[41];   //OCPP AuthorizationKey for security profile
 	unsigned int 			Checksum;					//4 bytes checksum
 	struct LED				LedInfo;					// LED configuration info
 	unsigned char			ShowInformation;
@@ -544,14 +555,14 @@ struct ChargingInfoData
 	unsigned char 		IsAvailable;
 	float MaximumChargingVoltage;	// unit 0.1V
 	float AvailableChargingCurrent;	// unit 0.1A
-	float AvailableChargingPower;	// unit .01kW
+	float AvailableChargingPower;	// unit 0.1kW
 	float DividChargingCurrent;		//0~6553.5 amp
-	float DeratingChargingCurrent;  //0~6553.5 amp
-	float DeratingChargingPower;	//0~6553.5 kW
+	float DeratingChargingCurrent;  // unit 0.1A
+	float DeratingChargingPower;	// unit 0.1kW
 	float FuseChargingVoltage;		//0~6553.5 volt
 	float FireChargingVoltage;		//0~6553.5 volt
-	float PresentChargingVoltage;	//0~6553.5 volt
-	float PresentChargingCurrent;		//0~6553.5 amp
+	float PresentChargingVoltage;   // unit: 1V
+	float PresentChargingCurrent;   // unit: 1A
 	float PresentChargingPower;		//0~6553.5 kW
 	float PresentChargedEnergy;		//0~6553.5 kWh
 	int PresentChargedDuration;	// second
@@ -566,17 +577,18 @@ struct ChargingInfoData
 	unsigned char PilotState;//1:state A, 2:State B1, 3:State B2, 4:State C, 5:State D, 6:State E, 7:State F, 8: Pilot error
 	unsigned char PilotDuty;					// 0~100%
 	unsigned char			StartUserId[32];			// This ID is trigger start charging event user by RFID, back-end, BLE.
+	unsigned char           StartIdType;                // 0: Central   1: eMAID    2: ISO14443 3: ISO15693 4: KeyCode  5: Local    6: MaxAddress   7: NoAuthorization
 	unsigned char			StartDateTime[32];			// Charging cycle start date time
 	unsigned char			StopDateTime[32];			// Charging cycle stop date time
 	unsigned char			StartMethod;
 	float					ChargingFee;
 	// Connector Temp
 	unsigned char 		ConnectorTemp;			//0x00: -60¢XC  ~  0xFE: 194
-	//Chiller Temp
+    //Chiller Temp
     unsigned char       ChillerTemp;            //0x00: -60¢XC  ~  0xFE: 194
 	// Charging Status
 	unsigned char 		GroundFaultStatus;		// for GFD result => 0x00 : None, 0x01 : Can Start Charging, 0x02 : Stop Charging
-	unsigned short		RealRatingPower;
+	unsigned short		RealRatingPower;        // unit: 0.1kW
 	unsigned char 		RelayWeldingCheck;		// 0 : No Comp., 1 : Comp.
 	unsigned char 		PrechargeStatus;		// for ccs precharge => 0x00 : None defined, 0x01 : Accepted
 	float 				PowerConsumption;		// This contains the meter value (Power Consumption) kWh
@@ -590,7 +602,7 @@ struct ChargingInfoData
 	unsigned char		AcCcsChargingMode;				// 0:BC (PWM) only, 1:BC & PLC mixed
 	unsigned short		SampleChargingCur[10];
 
-	/**************Alston for AC***************/
+	/************** Alston ***************/
 	unsigned char 		SelfTest_Comp;
 	unsigned char		version[16];
 	unsigned char 		IsModeChagned;
@@ -603,7 +615,7 @@ struct ChargingInfoData
 	unsigned char 		ConnectorAlarmCode[7];
 	unsigned char 		EvConnAlarmCode[7];
 	float 				ChargingProfileCurrent;			//0~6553.5 amp
-	float 				ChargingProfilePower;			//0~6553.5 kW
+	float 				ChargingProfilePower;			//0~6553.5 W
 	float 				PresentChargingVoltageL2;		//0~6553.5 volt
 	float 				PresentChargingVoltageL3;		//0~6553.5 volt
 	float 				PresentChargingCurrentL2;		//0~6553.5 amp	
@@ -616,11 +628,15 @@ struct ChargingInfoData
 	int 				EvBatteryStartSoc;				// 0~100%
 	unsigned char 		NormalStopChargeFlag;			// for EV board
 	ChargingStop        ChargingStopFlag;
-	char 				ReservedStartFlag;
-	float 				ConnectorMaxVoltage;			// 0~6553.5 volt
-	float 				ConnectorMaxCurrent;			// 0~6553.5 volt
-	unsigned char 		ModelType;
+    char                ReservedStartFlag;
+    float               ConnectorMaxVoltage;            // 0~6553.5 volt
+    float               ConnectorMaxCurrent;            // 0~6553.5 volt
+    unsigned char       ModelType;
     MeterIcCalibration  meterIcCalInfo;
+    float               PowerOffered;                   //0~6553.5 kW
+    float               CurrentOffered;                 //0~6553.5 amp
+    struct timespec     ConnectorTimeout;
+    unsigned char       PantographFlag;                 // 0: normal gun type,  1: pantograph gun type
 };
 
 typedef union
@@ -772,7 +788,8 @@ typedef union
         unsigned int  AlarmStopRequest:1;               // 0: no effect,    1: connector alarm stop request                     ( dispenser -> cabinet)
         unsigned int  FaultStatusRequest:1;
         unsigned int  Disconnection:1;
-        unsigned int  res:10;
+        unsigned int  GfdDetection:1;                   // 0: stop,         1: start
+        unsigned int  res:9;
     }bits;
 }ConnectorParameter;
 
@@ -821,8 +838,8 @@ typedef union
         unsigned int AuthorizingCompleted:1;    // 0: not yet, 1: authorizing completed
         unsigned int DispenserDisconnection:1;  // 0: no connection,  1: dispenser connected
         unsigned int BackendAuthorized:1;       // 0: local authorized, 1: backend authorized
-        unsigned int WiringInfoChanged:1;       // 0: no effect, 1: wiring info has changed
-        unsigned int EnableWriteWiringInfo:1;   // 0: no effect, 1: enable write wiring info after timeout
+        unsigned int FlashConfigChanged:1;      // 0: no effect, 1: flash config has changed
+        unsigned int EnableWriteFlash:1;        // 0: no effect, 1: enable to write flash after timeout
         unsigned int CleanWiringInfo:1;         // 0: no effect, 1: clean wiring info
         unsigned int res:25;
     }bits;
@@ -905,6 +922,7 @@ struct SysInfoData
 	/**************Backend***************/
 	unsigned char 		OcppConnStatus;					//0: disconnected, 1: connected
 	char 				OrderCharging;
+    float               MaxChargingProfilePower;        //0~6553.5 W
 	/**************Alston***************/
 	unsigned char 		WaitForPlugit;					//0: none scan, 1: scanning
 	unsigned char 		PageIndex;						//0 : Initialize
@@ -923,7 +941,7 @@ struct SysInfoData
 	unsigned char 		FirmwareUpdate;					// 0 : none, 1 : update.
 	unsigned char 		AcContactorStatus;				// 0: disconnected, 1: connected
 	unsigned char 	 	SystemTimeoutFlag;				// 0 : none, 1 : self test
-	struct timeval		SystemTimeoutTimer;
+	struct timespec		SystemTimeoutTimer;
 	unsigned char 		SystemPage;
 	unsigned char 		ConnectorPage;
 	unsigned char		IsAlternatvieConf;				// 0 : normal, 1 : alternative
@@ -1124,8 +1142,8 @@ struct FaultCodeData
 			unsigned char BleModuleBroken:1;					//bit 2
 			unsigned char RotarySwitchFault:1;					//bit 3 
 			unsigned char CcsLiquidChillerWaterLevelFault:1;    //bit 4
-			unsigned char ChillerTempSensorBroken:1;            //bit 5
-			unsigned char :2;									//bit 6 ~ 7	reserved
+            unsigned char ChillerTempSensorBroken:1;            //bit 5
+            unsigned char :2;                                   //bit 6 ~ 7 reserved
 		}bits;
 	}FaultEvents;
 };
@@ -1257,9 +1275,9 @@ char AlarmStatusCode[128][6]=
     "012321",   // System CCS output UCP
     "012322",   // System GBT output UCP
     "012323",   // System Chiller output OTP
-    "012324",   // reserved
-    "012325",   // reserved
-    "012326",   // reserved
+    "012324",   // Connector 1 detects abnormal voltage on the output line
+    "012325",   // Connector 2 detects abnormal voltage on the output line
+    "012326",   // System task is lost
     "012327",   // reserved
 };
 */
@@ -1411,7 +1429,10 @@ struct AlarmCodeData
             unsigned char SystemCCSOutputUCP:1;                     //bit 1
             unsigned char SystemGBTOutputUCP:1;                     //bit 2
             unsigned char SystemChillerOTP:1;                       //bit 3
-            unsigned char Reserved:4;                               //bit 4~7
+            unsigned char AbnormalVoltageOnOutputLine_1:1;          //bit 4
+            unsigned char AbnormalVoltageOnOutputLine_2:1;          //bit 5
+            unsigned char SystemTaskLost:1;                         //bit 6
+            unsigned char Reserved:1;                               //bit 7
 		}bits;
 	}AlarmEvents;
 };
@@ -2148,8 +2169,8 @@ struct PsuModuleData
 	unsigned short 	InputCurrentL3;		//abcd=abc.d amp
 	unsigned short 	PresentOutputVoltage;	//abcd=abc.d volt
 	unsigned short 	PresentOutputCurrent;	//abcd=abc.d amp
-	unsigned short 	AvailableCurrent;		//abcd=abc.d amp
-	unsigned int 		AvailablePower;		//abcd=abc.d kWatt
+	unsigned short 	AvailableCurrent;		// unit: 0.1A
+	unsigned int 		AvailablePower;		// unit: 0.1kW
 	char 				CriticalTemp1;			//0x00: -60¢XC  ~  0xFE: 194¢XC, resolution: 1¢XC, offset: -60¢XC, 0xFF: invalid
 	char 				CriticalTemp2;			//0x00: -60¢XC  ~  0xFE: 194¢XC, resolution: 1¢XC, offset: -60¢XC, 0xFF: invalid
 	char 				CriticalTemp3;			//0x00: -60¢XC  ~  0xFE: 194¢XC, resolution: 1¢XC, offset: -60¢XC, 0xFF: invalid
@@ -2160,7 +2181,7 @@ struct PsuModuleData
 	char 				OutletTemp;			//0x00: -60¢XC  ~  0xFE: 194¢XC, resolution: 1¢XC, offset: -60¢XC, 0xFF: invalid
 	unsigned int 		AlarmCode;
 	unsigned int 		FaultCode;			//
-	unsigned int 		IAvailableCurrent;		//abcd=abc.d amp
+	unsigned int 		IAvailableCurrent;		            // unit: 0.1A
 };
 
 /*Following are the information for each PSU Group*/
@@ -2170,12 +2191,12 @@ struct PsuGroupData
 	unsigned char           GroupOutputPowerSwitch;         //0: D.D normal OFF,  1: D.D emergency OFF,  2: D.D ON
 	unsigned short          GroupTargetOutputVoltage;       //abcd=abc.d volt
 	unsigned short          GroupTargetOutputCurrent;       //abcd=abc.d amp
-	unsigned short          GroupAvailableCurrent;          //abcd=abc.d amp
-	unsigned int            GroupAvailablePower;            //abcd=abc.d kWatt
-	unsigned int            GroupRealOutputPower;           //Watt
-	unsigned short          GroupPresentOutputVoltage; 	    //abcd=abc.d volt
-	unsigned short          GroupPresentOutputCurrent;      //abcd=abc.d Amps
-	unsigned int            GroupPresentOutputPower;        //Watt
+	unsigned short          GroupAvailableCurrent;          // unit: 0.1A
+	unsigned int            GroupAvailablePower;            // unit: 0.1kW
+	unsigned int            GroupRealOutputPower;           // unit: 1kW
+	unsigned short          GroupPresentOutputVoltage; 	    // unit: 0.1V
+	unsigned short          GroupPresentOutputCurrent;      // unit: 0.1A
+	unsigned int            GroupPresentOutputPower;        // unit: 0.1kW
 	struct PsuModuleData 	PsuModule[MAX_PSU_QUANTITY];
 	PsuGroupError           GroupErrorFlag;
     unsigned short          TotalIAvailableCurrent;         // unit: 0.1A
@@ -3832,49 +3853,49 @@ struct CcsData
 /**************************************************************************************/
 struct PrimaryMcuData
 {
-	unsigned char 	SelfTest_Comp;
-	unsigned char	version[16];									//STM32F407 firmware version
-	unsigned int 	InputVoltage;									//value comes from external meter
-	unsigned int 	InputCurrent;									//value comes from external meter
-	union
-	{
-		unsigned char OutputDrvValue[1];
-		struct
-		{
-			//OutputDrvValue[0]
-			unsigned char OnButtonLedDrv:1;                     //bit 0,    H: ON,      L:OFF
-			unsigned char OffButtonLedDrv:1;                    //bit 1,    H: ON,      L:OFF
-			unsigned char SystemLed1Drv:1;                      //bit 2,    H: ON,      L:OFF
-			unsigned char SystemLed2Drv:1;                      //bit 3,    H: ON,      L:OFF
-			unsigned char SystemLed3Drv:1;                      //bit 4,    H: ON,      L:OFF
-			unsigned char SystemLed4Drv:1;                      //bit 5,    H: ON,      L:OFF
-			unsigned char AcContactorDrv:1;                     //bit 6,    H: ON,      L:OFF
-			unsigned char:1;                                    //bit 7 reserved
-		}bits;
-	}OutputDrv;
-	union
-	{
-		unsigned char InputDetValue[2];
-		struct
-		{
-			//InputDetValue[0]
-		    unsigned char AcContactorDetec:1;					//bit 0,	H: ON, 		L:OFF
-			unsigned char AcMainBreakerDetec:1;					//bit 1,	H: ON, 		L:OFF
-			unsigned char SpdDetec:1; 							//bit 2,	H: ON, 		L:OFF
-			unsigned char DoorOpen:1;							//bit 3,	H: Open,		L:Close
-			unsigned char Gfd1:1;								//bit 4,	H: Trigger,		L:Normal
-			unsigned char Gfd2:1;								//bit 5,	H: Trigger,		L:Normal
-			unsigned char Button1:1;								//bit 6 ,	H: Push, 		L:Release
-			unsigned char Button2:1;								//bit 7,	H: Push, 		L:Release
-			//InputDetValue[1]
-			unsigned char EmergencyButton:1;						//bit 0,	H: Push, 		L:Release
+    unsigned char   SelfTest_Comp;
+    unsigned char   version[16];                                //STM32F407 firmware version
+    unsigned int    InputVoltage;                               //value comes from external meter
+    unsigned int    InputCurrent;                               //value comes from external meter
+    union
+    {
+        unsigned char OutputDrvValue[1];
+        struct
+        {
+            //OutputDrvValue[0]
+            unsigned char OnButtonLedDrv:1;                     //bit 0,    H: ON,      L:OFF
+            unsigned char OffButtonLedDrv:1;                    //bit 1,    H: ON,      L:OFF
+            unsigned char SystemLed1Drv:1;                      //bit 2,    H: ON,      L:OFF
+            unsigned char SystemLed2Drv:1;                      //bit 3,    H: ON,      L:OFF
+            unsigned char SystemLed3Drv:1;                      //bit 4,    H: ON,      L:OFF
+            unsigned char SystemLed4Drv:1;                      //bit 5,    H: ON,      L:OFF
+            unsigned char AcContactorDrv:1;                     //bit 6,    H: ON,      L:OFF
+            unsigned char:1;                                    //bit 7 reserved
+        }bits;
+    }OutputDrv;
+    union
+    {
+        unsigned char InputDetValue[2];
+        struct
+        {
+            //InputDetValue[0]
+            unsigned char AcContactorDetec:1;                   //bit 0,    H: ON,      L:OFF
+            unsigned char AcMainBreakerDetec:1;                 //bit 1,    H: ON,      L:OFF
+            unsigned char SpdDetec:1;                           //bit 2,    H: ON,      L:OFF
+            unsigned char DoorOpen:1;                           //bit 3,    H: Open,    L:Close
+            unsigned char Gfd1:1;                               //bit 4,    H: Trigger, L:Normal
+            unsigned char Gfd2:1;                               //bit 5,    H: Trigger, L:Normal
+            unsigned char Button1:1;                            //bit 6 ,   H: Push,    L:Release
+            unsigned char Button2:1;                            //bit 7,    H: Push,    L:Release
+            //InputDetValue[1]
+            unsigned char EmergencyButton:1;                    //bit 0,    H: Push,    L:Release
             unsigned char Key0:1;                               //bit 1,    H: ON,      L:OFF
             unsigned char Key1:1;                               //bit 2,    H: ON,      L:OFF
             unsigned char Key2:1;                               //bit 3,    H: ON,      L:OFF
             unsigned char Key3:1;                               //bit 4,    H: ON,      L:OFF
             unsigned char :3;                                   //bit 5~7,  Reserved
-		}bits;
-	}InputDet;
+        }bits;
+    }InputDet;
 };
 /**************************************************************************************/
 /*************Fan power module Communication Share memory******************/
@@ -4295,7 +4316,7 @@ struct OCPP16ConfigurationItem
 {
 	unsigned char 		ItemName[64];
 	unsigned char 		ItemAccessibility;//0:RO, 1:RW
-	unsigned char 		ItemData[128];
+	unsigned char 		ItemData[500];
 };
 
 struct OCPP16ConfigurationTable
@@ -4750,6 +4771,7 @@ enum OCPP20CtrlrVariable
 	OCPPCommCtrlr_WebSocketPingInterval,
 	OCPPCommCtrlr_ResetRetries,
 	OCPPCommCtrlr_PublicKeyWithSignedMeterValue,
+    OCPPCommCtrlr_VariableVersion,
 	ReservationCtrlr_Enabled,
 	ReservationCtrlr_Available,
 	ReservationCtrlr_NonEvseSpecific,
@@ -5119,7 +5141,7 @@ struct UnitOfMeasureType
 
 struct SampledValueType
 {
-	float value;													// Required. Indicates the measured value.
+    double value;													// Required. Indicates the measured value.
 	unsigned char context[32];										// Optional. Type of detail value: start, end or sample. Default = "Sample.Periodic"
 	unsigned char measurand[32];									// Optional. Type of measurement. Default = "Energy.Active.Import.Register"
 	unsigned char phase[8];											// Optional. Indicates how the measured value is to be interpreted.
@@ -5371,6 +5393,7 @@ struct GetCertificateStatus_20
 	struct OCSPRequestDataType ocspRequestData;						// Required. Indicates the certificate of which the status is requested.
 	unsigned char Response_status[16];								// Required. This indicates whether the charging station was able to retrieve the OCSP certificate status.
 	unsigned char Response_ocspResult[5501];						// Optional. OCSPResponse class as defined in IETF RFC 6960. DER encoded (as defined in IETF RFC 6960), and then base64 encoded. MAY only be omitted when status is not Accepted.
+	struct StatusInfoType Response_statusInfo;                      // Optional. Detailed status information.
 };
 
 struct GetChargingProfiles_20

+ 67 - 6
EVSE/Projects/DD360/Apps/ModuleDoComm/DoComm.c

@@ -57,10 +57,16 @@ static void removeFaultCodeToBuf(uint8_t *Code);
 static void addFaultCodeToBuf(uint8_t *Code);
 static int readMiscCommand(int fd, uint8_t id);
 static int writeCsuModuleVersion(int fd);
+static int writeGroundFaultDetection(int fd, uint8_t status, uint8_t id);
 
 //------------------------------------------------------------------------------
 //--- Common function ---
 //------------------------------------------------------------------------------
+void GetClockTime(struct timespec *_now_time, void *null)
+{
+    clock_gettime(CLOCK_MONOTONIC, _now_time);
+}
+
 /*static int StoreLogMsg(const char *fmt, ...)
 {
     char Buf[4096 + 256];
@@ -715,7 +721,7 @@ static int miscCommandHandle(uint8_t dataLen, uint8_t plugNum, uint8_t *data)
                     pSysInfo->WaitForPlugit = NO;
                     sleep(1); //Jerry add
                     pSysInfo->SystemPage = _LCM_SELECT_GUN;
-                    gettimeofday(&pSysInfo->SystemTimeoutTimer, NULL);
+                    GetClockTime(&pSysInfo->SystemTimeoutTimer, NULL);
                     pSysInfo->SystemTimeoutFlag = Timeout_None;
                 }
 
@@ -727,7 +733,7 @@ static int miscCommandHandle(uint8_t dataLen, uint8_t plugNum, uint8_t *data)
                     pSysInfo->WaitForPlugit = NO;
                     sleep(1); //Jerry add
                     pSysInfo->SystemPage = _LCM_SELECT_GUN;
-                    gettimeofday(&pSysInfo->SystemTimeoutTimer, NULL);
+                    GetClockTime(&pSysInfo->SystemTimeoutTimer, NULL);
                     pSysInfo->SystemTimeoutFlag = Timeout_None;
                 }
 
@@ -756,7 +762,7 @@ static int miscCommandHandle(uint8_t dataLen, uint8_t plugNum, uint8_t *data)
             strcpy((char *)pSysConfig->UserId, "");
             pSysInfo->WaitForPlugit = NO;
             pSysInfo->SystemPage = _LCM_SELECT_GUN;
-            gettimeofday(&pSysInfo->SystemTimeoutTimer, NULL);
+            GetClockTime(&pSysInfo->SystemTimeoutTimer, NULL);
             pSysInfo->SystemTimeoutFlag = Timeout_None;
             destroySelectGun(plugNum);
 
@@ -776,7 +782,7 @@ static int miscCommandHandle(uint8_t dataLen, uint8_t plugNum, uint8_t *data)
                 strcpy((char *)pSysConfig->UserId, "");
                 pSysInfo->WaitForPlugit = NO;
                 pSysInfo->SystemPage = _LCM_SELECT_GUN;
-                gettimeofday(&pSysInfo->SystemTimeoutTimer, NULL);
+                GetClockTime(&pSysInfo->SystemTimeoutTimer, NULL);
                 pSysInfo->SystemTimeoutFlag = Timeout_None;
                 destroySelectGun(plugNum);
             } else {
@@ -1167,6 +1173,26 @@ static int responsePackeHandle(int fd, uint8_t *pResult, uint8_t plugNum, uint8_
     case REG_WAIT_PLUG_IT_STATE:
         break;
 
+    case REG_Ground_Fault_Detection:
+        if (pCsuResult->Data.Result == COMMAND_RESULT_NG) {
+            return COMMAND_RESULT_NG;
+        }
+
+        //集電弓relay 不打開才能進入動作
+        pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(plugNum);
+        if(pDcChargingInfo->PantographFlag == YES)
+        {
+            GroundFaultDetection *gfd = (GroundFaultDetection *)&pCsuResult->Data.Data[0];
+            if(pDcChargingInfo->GroundFaultStatus != gfd->Status)
+            {
+                log_info("id = %d, GFD Result = %d\r\n",
+                           pCsuResult->Head.ID,
+                           gfd->Status);
+            }
+            pDcChargingInfo->GroundFaultStatus = gfd->Status;
+        }
+        break;
+
     default:
         break;
     }
@@ -1277,8 +1303,16 @@ static int writePresentChargingInfo(int fd, uint8_t plugNum, uint8_t id)
     PreChargingInfo *pPreChargingInfo = (PreChargingInfo *)dataBuf;
     pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(plugNum);
 
-    pPreChargingInfo->PresentChargingVoltage = htons((uint16_t)(pDcChargingInfo->PresentChargingVoltage * 10));
-    pPreChargingInfo->PresentChargingCurrent = htons((uint16_t)(pDcChargingInfo->PresentChargingCurrent * 10));
+    if(pDcChargingInfo->PantographFlag == NO)
+    {
+        pPreChargingInfo->PresentChargingVoltage = htons((uint16_t)(pDcChargingInfo->PresentChargingVoltage * 10));
+        pPreChargingInfo->PresentChargingCurrent = htons((uint16_t)(pDcChargingInfo->PresentChargingCurrent * 10));
+    }
+    else
+    {
+        pPreChargingInfo->PresentChargingVoltage = htons((uint16_t)(ShmDcCommonData->PcPsuOutput[plugNum].Voltage));
+        pPreChargingInfo->PresentChargingCurrent = htons((uint16_t)(ShmDcCommonData->PcPsuOutput[plugNum].Current));
+    }
     pPreChargingInfo->RemainChargingDuration = htonl(pDcChargingInfo->RemainChargingDuration);
     pPreChargingInfo->EvBatterySoc = pDcChargingInfo->EvBatterySoc;
 
@@ -1369,6 +1403,19 @@ static int readChargePermission(int fd, uint8_t id)
                              NULL);
 }
 
+static int writeGroundFaultDetection(int fd, uint8_t status, uint8_t id)
+{
+    int ret = PASS;
+    uint8_t dataBuf[1] = {status};
+    ret = composeSocketData(fd,
+                            id,
+                            OP_WRITE_DATA,
+                            REG_Ground_Fault_Detection,
+                            1,
+                            &dataBuf[0]);
+    return ret;
+}
+
 static int writeUserID(int fd, uint8_t id, uint8_t *pUserID)
 {
     if ((strlen((char *)pUserID) <= 0) || (pUserID == NULL)) {
@@ -1940,6 +1987,7 @@ static void systemStatusProcess(int fd, uint8_t totalGun, uint8_t plugNum, uint8
                 DiffTimeb(gRegTimeUp[plugNum][REG_CHARGING_CAP], AuthNowTime) < 0
            ) {
             readChargingCapability(fd, gunID);
+            writeGroundFaultDetection(fd, 0, gunID);
             ftime(&gRegTimeUp[plugNum][REG_CHARGING_CAP]);
         }
         break;
@@ -1973,6 +2021,7 @@ static void systemStatusProcess(int fd, uint8_t totalGun, uint8_t plugNum, uint8
                 DiffTimeb(gRegTimeUp[plugNum][REG_PRESENT_CHARGING_INFO], AuthNowTime) < 0
            ) {
             writePresentChargingInfo(fd, plugNum, gunID);
+            writeGroundFaultDetection(fd, 0, gunID);
             ftime(&gRegTimeUp[plugNum][REG_PRESENT_CHARGING_INFO]);
         }
         break;
@@ -2004,6 +2053,7 @@ static void systemStatusProcess(int fd, uint8_t totalGun, uint8_t plugNum, uint8
                 DiffTimeb(gRegTimeUp[plugNum][REG_PRESENT_CHARGING_INFO], AuthNowTime) < 0
            ) {
             writePresentChargingInfo(fd, plugNum, gunID);
+            writeGroundFaultDetection(fd, 0, gunID);
             ftime(&gRegTimeUp[plugNum][REG_PRESENT_CHARGING_INFO]);
         }
         break;
@@ -2012,6 +2062,7 @@ static void systemStatusProcess(int fd, uint8_t totalGun, uint8_t plugNum, uint8
     case S_CCS_PRECHARGE_ST0:
     case S_CCS_PRECHARGE_ST1:
         writeChargingTarget(fd, plugNum, gunID);
+        writeGroundFaultDetection(fd, 1, gunID);
 
         ftime(&AuthNowTime);
         if (DiffTimeb(gRegTimeUp[plugNum][REG_CHARGING_CAP], AuthNowTime) > LOOP_RETRY_TIME ||
@@ -2045,6 +2096,15 @@ static void systemStatusProcess(int fd, uint8_t totalGun, uint8_t plugNum, uint8
 
     case S_CHARGING: //charging
     case S_TERMINATING:
+        if(pDcChargingInfo->Type == _Type_GB || pDcChargingInfo->Type == _Type_Chademo)
+        {
+            writeGroundFaultDetection(fd, 0, gunID);
+        }
+        else
+        {
+            writeGroundFaultDetection(fd, 1, gunID);
+        }
+
         ftime(&AuthNowTime);
         if (DiffTimeb(gRegTimeUp[plugNum][REG_CHARGING_CAP], AuthNowTime) > LOOP_RETRY_TIME ||
                 DiffTimeb(gRegTimeUp[plugNum][REG_CHARGING_CAP], AuthNowTime) < 0
@@ -2083,6 +2143,7 @@ static void systemStatusProcess(int fd, uint8_t totalGun, uint8_t plugNum, uint8
                 DiffTimeb(gRegTimeUp[plugNum][REG_CHARGING_CAP], AuthNowTime) < 0
            ) {
             readChargingCapability(fd, gunID);
+            writeGroundFaultDetection(fd, 0, gunID);
             ftime(&gRegTimeUp[plugNum][REG_CHARGING_CAP]);
         }
         break;

+ 5 - 0
EVSE/Projects/DD360/Apps/ModuleDoComm/DoComm.h

@@ -79,6 +79,7 @@
 #define REG_PRESENT_CHARGING_INFO               0X0F
 #define REG_QRCODE_URL_INFO                     0X10
 #define REG_WAIT_PLUG_IT_STATE                  0x11
+#define REG_Ground_Fault_Detection              0x12
 
 //------------------------------------------------------------------------------
 //--- dispenser result ---
@@ -207,6 +208,10 @@ typedef struct StPresentChargingInfo {
     uint8_t EvBatterySoc;               // 0~100%
 } PreChargingInfo;
 
+typedef struct StGroundFaultDetection { //Ground Fault Detection
+    uint8_t Status;
+} GroundFaultDetection;
+
 typedef struct StSoftwareUpdInfo {
     uint8_t UpdateState;         //1:update , 2: not update
     uint8_t ImgName[248];

+ 11 - 9
EVSE/Projects/DD360/Apps/ModuleEvComm/Module_EvTxComm.c

@@ -505,7 +505,7 @@ static void SetPresentChargingOutputPower(void)
     PcPsuOutput *pPcPsuOutput2 = NULL;
     struct ChargingInfoData *chargingData_1 = NULL;
     struct ChargingInfoData *chargingData_2 = NULL;
-    bool isPsuOutput1 = false, isPsuOutput2 = false;
+    bool isPsuVol1 = false, isPsuVol2 = false, isPsuCur1 = false, isPsuCur2 = false;
 
     if (pSysConfig->TotalConnectorCount == 1) {
         pPcPsuOutput1 = (PcPsuOutput *)&ShmDcCommonData->PcPsuOutput[0];
@@ -522,15 +522,17 @@ static void SetPresentChargingOutputPower(void)
     psuOutputReady[0] = chargingData_1->SystemStatus != S_CHARGING ? false : psuOutputReady[0];
     psuOutputReady[1] = chargingData_2->SystemStatus != S_CHARGING ? false : psuOutputReady[1];
 
-    isPsuOutput1 = (pPcPsuOutput1->Voltage != 0 && psuOutputReady[0] == true);
-    isPsuOutput2 = (pPcPsuOutput2->Voltage != 0 && psuOutputReady[1] == true);
+    isPsuVol1 = chargingData_1->PantographFlag ? true : (pPcPsuOutput1->Voltage != 0 && psuOutputReady[0] == true);
+    isPsuVol2 = chargingData_2->PantographFlag ? true : (pPcPsuOutput2->Voltage != 0 && psuOutputReady[1] == true);
+    isPsuCur1 = chargingData_1->PantographFlag ? true : false;
+    isPsuCur2 = chargingData_2->PantographFlag ? true : false;
 
     //vol1 = chargingData_1->FireChargingVoltage;
-    vol1 = isPsuOutput1 == false ? chargingData_1->FireChargingVoltage : (((float)pPcPsuOutput1->Voltage));
-    cur1 = (chargingData_1->PresentChargingCurrent * 10);
+    vol1 = isPsuVol1 == false ? chargingData_1->FireChargingVoltage : (((float)pPcPsuOutput1->Voltage));
+    cur1 = isPsuCur1 == false ? (chargingData_1->PresentChargingCurrent * 10) : pPcPsuOutput1->Current;
     //vol2 = chargingData_2->FireChargingVoltage;
-    vol2 = isPsuOutput2 == false ? chargingData_2->FireChargingVoltage : (((float)pPcPsuOutput2->Voltage));
-    cur2 = (chargingData_2->PresentChargingCurrent * 10);
+    vol2 = isPsuVol2 == false ? chargingData_2->FireChargingVoltage : (((float)pPcPsuOutput2->Voltage));
+    cur2 = isPsuCur2 == false ? (chargingData_2->PresentChargingCurrent * 10) : pPcPsuOutput2->Current;
 
     //DS60-120 add
     if ((LogInfo[0][EV_LOG_NOW_OUTPUT_VOL] >= vol1 + CHK_VOL_RANGE) ||
@@ -543,10 +545,10 @@ static void SetPresentChargingOutputPower(void)
             (LogInfo[1][EV_LOG_NOW_OUTPUT_CUR] <= cur2 - CHK_CUR_RANGE)
        ) {
         log_info("G1 -> Output Vol(%s) = %.1f, Output Cur = %.1f -- G2 -> Output Vol(%s) = %.1f, Output Cur = %.1f\r\n",
-                 isPsuOutput1 == true ? "P" : "R",
+                 isPsuVol1 == true ? "P" : "R",
                  vol1 / 10,
                  cur1 / 10,
-                 isPsuOutput2 == true ? "P" : "R",
+                 isPsuVol2 == true ? "P" : "R",
                  vol2 / 10,
                  cur2 / 10);
 

+ 4 - 1
EVSE/Projects/DD360/Apps/ModuleInternalComm/Module_InternalComm.c

@@ -100,7 +100,10 @@ int main(int argc, char *argv[])
     //FanBoardTask(fd);
 
     while (isContinue) {
-        AcPlugTask(fd);
+        if(AC_QUANTITY > 0)
+        {
+            AcPlugTask(fd);
+        }
         usleep(100000);
     }
 

+ 41 - 4
EVSE/Projects/DD360/Apps/ModuleInternalComm/RelayBoard.c

@@ -780,6 +780,13 @@ void CableCheckDetected(uint8_t index)
                     SetGfdConfig(targetID, GFD_CHARGING);
                 }
             }
+        }
+        else if(pDcChargingInfo->SystemStatus == S_TERMINATING || pDcChargingInfo->SystemStatus == S_ALARM)
+        {
+            if (pDcChargingInfo->Type == _Type_CCS_2)
+            {
+                SetGfdConfig(targetID, GFD_CHARGING);
+            }
         } else {
             SetGfdConfig(targetID, GFD_IDLE);
         }
@@ -1648,6 +1655,7 @@ static void LEDBoardProcess(void)
 
 void RelayBoardTask(int uartFD)
 {
+    bool isRelayBypass = false;
     pid_t pid = fork();
 
     if (pid == 0) {
@@ -1671,8 +1679,20 @@ void RelayBoardTask(int uartFD)
 
         Uart5Fd = uartFD;
 
+        for(int i = 0; i < pSysConfig->TotalConnectorCount; i++)
+        {
+            pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(i);
+            if(pDcChargingInfo->PantographFlag == YES)
+            {
+                isRelayBypass = true;
+            }
+        }
+
         //relay init
-        outputRelayInit(uartFD);
+        if(isRelayBypass == false)
+        {
+            outputRelayInit(uartFD);
+        }
 
         while (isContinue) {
 
@@ -1683,7 +1703,7 @@ void RelayBoardTask(int uartFD)
             }
 
             // 程序開始之前~ 必須先確定 FW 版本與硬體版本,確認後!!~ 該模組才算是真正的 Initial Comp.
-            if (ShmRelayModuleData->SelfTest_Comp == NO) {
+            if (ShmRelayModuleData->SelfTest_Comp == NO && isRelayBypass == false) {
                 GetFwAndHwVersion_Relay();
                 SetModelName_Relay(); //DS60-120 add
                 SetRtcData_Relay();
@@ -1698,7 +1718,7 @@ void RelayBoardTask(int uartFD)
             LEDBoardSelfTest();
 #endif //defined DD360ComBox
 
-            if (ShmRelayModuleData->SelfTest_Comp == YES)
+            if (ShmRelayModuleData->SelfTest_Comp == YES && isRelayBypass == false)
             {
                 // ==============優先權最高 10 ms ==============
                 // 輸出電壓
@@ -1711,7 +1731,6 @@ void RelayBoardTask(int uartFD)
 
                 // 讀取當前 AC relay 狀態
                 regRelay.relay_event.bits.AC_Contactor = pSysInfo->AcContactorStatus;
-
                 GetRelayOutputStatus();
 
                 // Cable check (Get)
@@ -1848,6 +1867,24 @@ void RelayBoardTask(int uartFD)
                     }
                 }
             }
+            else if(isRelayBypass == true)
+            {
+                for(i = 0; i < pSysConfig->TotalConnectorCount; i++)
+                {
+                    pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(i);
+
+                    if (pDcChargingInfo->SystemStatus == S_IDLE ||
+                            pDcChargingInfo->SystemStatus == S_RESERVATION ||
+                            pDcChargingInfo->SystemStatus == S_MAINTAIN)
+                    {
+                        _isOvpChkTimeFlag[i] = NO;
+                    }
+                    if (pDcChargingInfo->SystemStatus == S_CHARGING)
+                    {
+                        CheckOutputPowerOverCarReq(i);
+                    }
+                }
+            }
 
 #if !defined NO_FAN_BOARD && !defined DD360ComBox
             fanBoardPorcess();

+ 4 - 0
EVSE/Projects/DD360/Apps/ShareMemory/shmMem.c

@@ -923,6 +923,10 @@ static bool addGunInfoByConnector(uint8_t typeValue, uint8_t slots)
             pCcsData->CommProtocol = _CCS_COMM_V2GMessage_DIN70121;
             gGunIndexInfo.CcsIndex++;
             gGunIndexInfo.DcGunIndex++;
+            if(typeValue == 'P')
+            {
+                pDcChargingInfo->PantographFlag = YES;
+            }
         } else {
             result = false;
         }

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


BIN
EVSE/Projects/DD360/output/FactoryConfig


BIN
EVSE/Projects/DD360/output/Module_DoComm


BIN
EVSE/Projects/DD360/output/Module_EvComm


BIN
EVSE/Projects/DD360/output/Module_EventLogging


BIN
EVSE/Projects/DD360/output/Module_InternalComm


BIN
EVSE/Projects/DD360/output/Module_LcmControl


BIN
EVSE/Projects/DD360/output/Module_PrimaryComm


BIN
EVSE/Projects/DD360/output/ReadCmdline


BIN
EVSE/Projects/DD360/output/main


+ 15 - 0
EVSE/Projects/DD360Audi/Apps/CSU/SelfTest.c

@@ -18,6 +18,7 @@ extern void ChkPrimaryStatus(void);
 void SelfTestRun(void)
 {
     bool evInitFlag = false;
+    bool isRelayBypass = false;
     uint8_t index = 0;
     struct SysConfigData *pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
     struct SysInfoData *pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
@@ -34,6 +35,15 @@ void SelfTestRun(void)
     struct ChargingInfoData *pDcChargingInfo = NULL;
     struct ChargingInfoData *pAcChargingInfo = NULL;
 
+    for(int i = 0; i < pSysConfig->TotalConnectorCount; i++)
+    {
+        pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(i);
+        if(pDcChargingInfo->PantographFlag == YES)
+        {
+            isRelayBypass = true;
+        }
+    }
+
     StartSystemTimeoutDet(Timeout_SelftestChk);
     pSysInfo->SelfTestSeq = _STEST_VERSION;
 
@@ -62,6 +72,11 @@ void SelfTestRun(void)
 
         switch (pSysInfo->SelfTestSeq) {
         case _STEST_VERSION:
+            if(isRelayBypass == YES && ShmRelayModuleData->SelfTest_Comp != YES)
+            {
+                log_info("Relay Board Bypass");
+                ShmRelayModuleData->SelfTest_Comp = YES;
+            }
             if ((strlen((char *)pSysInfo->RelayModuleFwRev) != 0 ||
                     pSysInfo->RelayModuleFwRev[0] != '\0') &&
                     (ShmRelayModuleData->SelfTest_Comp != YES)

+ 32 - 12
EVSE/Projects/DD360Audi/Apps/CSU/main.c

@@ -77,7 +77,7 @@ uint8_t bd0_2_status = 0;
 uint8_t bd1_1_status = 0;
 uint8_t bd1_2_status = 0;
 
-char *fwVersion = "V1.13.00.0000.00"; // "V0.16.00.0000.00";
+char *fwVersion = "V1.14.00.0000.00"; // "V0.16.00.0000.00";
 
 //sqlite3 *localDb;
 bool isDb_ready;
@@ -89,6 +89,8 @@ long long DiffTimebWithNow(struct timeb ST);
 uint8_t DetectBitValue(uint8_t _byte, uint8_t _bit);
 void SetBitValue(uint8_t *_byte, uint8_t _bit, uint8_t value);
 unsigned long GetTimeoutValue(struct timeval _sour_time);
+void GetClockTime(struct timespec *_now_time, void *null);
+unsigned long GetClockTimeoutValue(struct timespec _start_time);
 void gpio_set_value(unsigned int gpio, unsigned int value);
 void InformOcppErrOccur(uint8_t codeType);
 
@@ -753,6 +755,24 @@ unsigned long GetTimeoutValue(struct timeval _sour_time)
     return 1000000 * (_end_time.tv_sec - _sour_time.tv_sec) + _end_time.tv_usec - _sour_time.tv_usec;
 }
 
+void GetClockTime(struct timespec *_now_time, void *null)
+{
+    clock_gettime(CLOCK_MONOTONIC, _now_time);
+}
+
+// return value unit: 1us
+unsigned long GetClockTimeoutValue(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) * 1000000) + ((unsigned long)((ts_end.tv_nsec / 1000) - (_start_time.tv_nsec/ 1000)));
+
+    return ret;
+}
+
 int DiffTimeb(struct timeb ST, struct timeb ET)
 {
     //return milli-second
@@ -2645,14 +2665,14 @@ void KillAllTask(void)
 void StartSystemTimeoutDet(uint8_t flag)
 {
     if (pSysInfo->SystemTimeoutFlag != flag) {
-        gettimeofday(&pSysInfo->SystemTimeoutTimer, NULL);
+        GetClockTime(&pSysInfo->SystemTimeoutTimer, NULL);
     }
     pSysInfo->SystemTimeoutFlag = flag;
 }
 
 void StopSystemTimeoutDet(void)
 {
-    gettimeofday(&pSysInfo->SystemTimeoutTimer, NULL);
+    GetClockTime(&pSysInfo->SystemTimeoutTimer, NULL);
     pSysInfo->SystemTimeoutFlag = Timeout_None;
 }
 
@@ -2724,7 +2744,7 @@ void CreateTimeoutFork(void)
             // 系統
             switch (pSysInfo->SystemTimeoutFlag) {
             case Timeout_SelftestChk:
-                if (GetTimeoutValue(pSysInfo->SystemTimeoutTimer) / uSEC_VAL >= SELFTEST_TIMEOUT) {
+                if (GetClockTimeoutValue(pSysInfo->SystemTimeoutTimer) / uSEC_VAL >= SELFTEST_TIMEOUT) {
                     _SelfTestTimeout();
                     StopSystemTimeoutDet();
                     destroySelGun(DESTROY_ALL_SEL); //jerry add
@@ -2732,7 +2752,7 @@ void CreateTimeoutFork(void)
                 break;
 
             case Timeout_Authorizing:
-                if (GetTimeoutValue(pSysInfo->SystemTimeoutTimer) / uSEC_VAL >= AUTHORIZE_TIMEOUT) {
+                if (GetClockTimeoutValue(pSysInfo->SystemTimeoutTimer) / uSEC_VAL >= AUTHORIZE_TIMEOUT) {
                     _AuthorizedTimeout();
                     StopSystemTimeoutDet();
                     destroySelGun(pSysInfo->CurGunSelected);
@@ -2748,7 +2768,7 @@ void CreateTimeoutFork(void)
                 break;
 
             case Timeout_VerifyFail:
-                if (GetTimeoutValue(pSysInfo->SystemTimeoutTimer) / uSEC_VAL >= AUTHORIZE_FAIL_TIMEOUT) {
+                if (GetClockTimeoutValue(pSysInfo->SystemTimeoutTimer) / uSEC_VAL >= AUTHORIZE_FAIL_TIMEOUT) {
                     _AutoReturnTimeout();
                     StopSystemTimeoutDet();
                     destroySelGun(pSysInfo->CurGunSelected);
@@ -2764,14 +2784,14 @@ void CreateTimeoutFork(void)
                 break;
 
             case Timeout_VerifyComp:
-                if (GetTimeoutValue(pSysInfo->SystemTimeoutTimer) / uSEC_VAL >= AUTHORIZE_COMP_TIMEOUT) {
+                if (GetClockTimeoutValue(pSysInfo->SystemTimeoutTimer) / uSEC_VAL >= AUTHORIZE_COMP_TIMEOUT) {
                     _AutoReturnTimeout();
                     StopSystemTimeoutDet();
                 }
                 break;
 
             case Timeout_WaitPlug:
-                if (GetTimeoutValue(pSysInfo->SystemTimeoutTimer) / uSEC_VAL >= _connectionTimeout) {
+                if (GetClockTimeoutValue(pSysInfo->SystemTimeoutTimer) / uSEC_VAL >= _connectionTimeout) {
                     _DetectPlugInTimeout();
                     StopSystemTimeoutDet();
                     destroySelGun(pSysInfo->CurGunSelected);
@@ -2779,7 +2799,7 @@ void CreateTimeoutFork(void)
                 break;
 
             case Timeout_ReturnToChargingGunDet:
-                if (GetTimeoutValue(pSysInfo->SystemTimeoutTimer) / uSEC_VAL >= RETURN_TO_CHARGING_PAGE) {
+                if (GetClockTimeoutValue(pSysInfo->SystemTimeoutTimer) / uSEC_VAL >= RETURN_TO_CHARGING_PAGE) {
 #if defined DD360Audi
                     if (getCurLcmPage() != _LCM_PRE_CHARGE &&
                             getCurLcmPage() != _LCM_CHARGING &&
@@ -2794,7 +2814,7 @@ void CreateTimeoutFork(void)
                 break;
 
             case Timeout_AuthorizingForStop:
-                if (GetTimeoutValue(pSysInfo->SystemTimeoutTimer) / uSEC_VAL >= AUTHORIZE_STOP_TIMEOUT) {
+                if (GetClockTimeoutValue(pSysInfo->SystemTimeoutTimer) / uSEC_VAL >= AUTHORIZE_STOP_TIMEOUT) {
                     strcpy((char *)pSysConfig->UserId, "");
                     ClearAuthorizedFlag();
                     StopSystemTimeoutDet();
@@ -4996,7 +5016,7 @@ int main(void)
                 // 切換 D+ Relay to Precharge Relay
                 if (isPrechargeStatus_ccs(gunIndex) == 39 ||
                         isPrechargeStatus_ccs(gunIndex) == 40) {
-                    if (pDcChargingInfo->RelayKPK2Status == YES &&
+                    if ((pDcChargingInfo->RelayKPK2Status == YES || pDcChargingInfo->PantographFlag == YES) &&
                             pDcChargingInfo->PrechargeStatus != PRECHARGE_READY)
                         //if (pDcChargingInfo->PrechargeStatus != PRECHARGE_PRERELAY_PASS)
                     {
@@ -5041,7 +5061,7 @@ int main(void)
 
                 // 等待小板通知進入充電
                 // 切換 D+ Relay to Precharge Relay
-                if (pDcChargingInfo->RelayK1K2Status == YES) {
+                if (pDcChargingInfo->RelayK1K2Status == YES || pDcChargingInfo->PantographFlag == YES) {
                     pDcChargingInfo->PrechargeStatus = PRECHARGE_READY;
                     setChargerMode(gunIndex, MODE_CHARGING);
                 }

+ 105 - 82
EVSE/Projects/DD360Audi/Apps/Define/define.h

@@ -176,6 +176,11 @@ Storage							0x0A200000-0x7FFFFFFF		1886 MB
 /**************************************************************************************/
 /****************** Share memory configuration value constant define ******************/
 /**************************************************************************************/
+struct NoneUse
+{
+    unsigned char       unknown;                    // None use struct
+};
+
 enum SYSTEM_STATUS
 {
 	SYS_MODE_BOOTING		= 0,
@@ -287,7 +292,7 @@ enum CoreProfile {
 	 TransactionMessageRetryInterval,
 	 UnlockConnectorOnEVSideDisconnect,
 	 WebSocketPingInterval,
-	 QueueOffLineStartTransactionMessage,
+	 QueueOffLineMeterValues,
 	 AuthorizationKey,
 	 SecurityProfile,
      DefaultPrice,
@@ -304,15 +309,21 @@ enum OCPP_RUNNING_VERSION {
     OCPP_RUNNING_VERSION_16=0,
     OCPP_RUNNING_VERSION_20
 };
+
+enum OCPP_START_ID_TYPE {
+    IdTokenType_Central=0,
+    IdTokenType_eMAID,
+    IdTokenType_ISO14443,
+    IdTokenType_KeyCode,
+    IdTokenType_Local,
+    IdTokenType_NoAuthorization,
+    IdTokenType_ISO15693
+};
 /**************************************************************************************/
 /****structure SysConfigData => shall store the data to NAND flash****************/
 /****structure SysInfoData => shall NOT store the data to NAND flash***************/
 /****according to System Configuration and Information Table.xlsx Rev.0.2 *******/
 /**************************************************************************************/
-struct NoneUse
-{
-	unsigned char		unknown;					// None use struct
-};
 
 struct EthConfigData
 {
@@ -454,9 +465,9 @@ typedef struct
     unsigned int isCalibratedCaOffset:1;                // Current phase a offset is calibrated, 0: default 1: Calibrated
     unsigned int isCalibratedCbOffset:1;                // Current phase b offset is calibrated, 0: default 1: Calibrated
     unsigned int isCalibratedCcOffset:1;                // Current phase c offset is calibrated, 0: default 1: Calibrated
-    unsigned int isCalibratedPa:1;                      // Phase angle a is calibrated, 0: default  1: Calibrated
-    unsigned int isCalibratedPb:1;                      // Phase angle b gain is calibrated, 0: default 1: Calibrated
-    unsigned int isCalibratedPc:1;                      // Phase angle c gain is calibrated, 0: default 1: Calibrated
+    unsigned int isCalibratedPa:1;                      // Phase angle a is calibrated, 0: default          1: Calibrated
+    unsigned int isCalibratedPb:1;                      // Phase angle b gain is calibrated, 0: default     1: Calibrated
+    unsigned int isCalibratedPc:1;                      // Phase angle c gain is calibrated, 0: default     1: Calibrated
     unsigned int :1;
 }MeterIcCalibration;
 
@@ -515,8 +526,8 @@ struct SysConfigData
 	unsigned char 			OcppServerURL[512];			//http: non-secure OCPP 1.5-S, https: secure OCPP 1.5-S, ws: non-secure OCPP 1.6-J, wss: secure OCPP 1.6-J"
 	unsigned char 			ChargeBoxId[128];
 	unsigned char			chargePointVendor[20];		//the Vendor of the ChargePoint
-	unsigned char			OcppSecurityProfile;		//OCPP security profile 0~3
-	unsigned char			OcppSecurityPassword[41];	//OCPP AuthorizationKey for security profile
+    unsigned char           OcppSecurityProfile;        //OCPP security profile 0~3
+    unsigned char           OcppSecurityPassword[41];   //OCPP AuthorizationKey for security profile
 	unsigned int 			Checksum;					//4 bytes checksum
 	struct LED				LedInfo;					// LED configuration info
 	unsigned char			ShowInformation;
@@ -544,14 +555,14 @@ struct ChargingInfoData
 	unsigned char 		IsAvailable;
 	float MaximumChargingVoltage;	// unit 0.1V
 	float AvailableChargingCurrent;	// unit 0.1A
-	float AvailableChargingPower;	// unit .01kW
+	float AvailableChargingPower;	// unit 0.1kW
 	float DividChargingCurrent;		//0~6553.5 amp
-	float DeratingChargingCurrent;  //0~6553.5 amp
-	float DeratingChargingPower;	//0~6553.5 kW
+	float DeratingChargingCurrent;  // unit 0.1A
+	float DeratingChargingPower;	// unit 0.1kW
 	float FuseChargingVoltage;		//0~6553.5 volt
 	float FireChargingVoltage;		//0~6553.5 volt
-	float PresentChargingVoltage;	//0~6553.5 volt
-	float PresentChargingCurrent;		//0~6553.5 amp
+	float PresentChargingVoltage;   // unit: 1V
+	float PresentChargingCurrent;   // unit: 1A
 	float PresentChargingPower;		//0~6553.5 kW
 	float PresentChargedEnergy;		//0~6553.5 kWh
 	int PresentChargedDuration;	// second
@@ -566,17 +577,18 @@ struct ChargingInfoData
 	unsigned char PilotState;//1:state A, 2:State B1, 3:State B2, 4:State C, 5:State D, 6:State E, 7:State F, 8: Pilot error
 	unsigned char PilotDuty;					// 0~100%
 	unsigned char			StartUserId[32];			// This ID is trigger start charging event user by RFID, back-end, BLE.
+	unsigned char           StartIdType;                // 0: Central   1: eMAID    2: ISO14443 3: ISO15693 4: KeyCode  5: Local    6: MaxAddress   7: NoAuthorization
 	unsigned char			StartDateTime[32];			// Charging cycle start date time
 	unsigned char			StopDateTime[32];			// Charging cycle stop date time
 	unsigned char			StartMethod;
 	float					ChargingFee;
 	// Connector Temp
 	unsigned char 		ConnectorTemp;			//0x00: -60¢XC  ~  0xFE: 194
-	//Chiller Temp
+    //Chiller Temp
     unsigned char       ChillerTemp;            //0x00: -60¢XC  ~  0xFE: 194
 	// Charging Status
 	unsigned char 		GroundFaultStatus;		// for GFD result => 0x00 : None, 0x01 : Can Start Charging, 0x02 : Stop Charging
-	unsigned short		RealRatingPower;
+	unsigned short		RealRatingPower;        // unit: 0.1kW
 	unsigned char 		RelayWeldingCheck;		// 0 : No Comp., 1 : Comp.
 	unsigned char 		PrechargeStatus;		// for ccs precharge => 0x00 : None defined, 0x01 : Accepted
 	float 				PowerConsumption;		// This contains the meter value (Power Consumption) kWh
@@ -590,7 +602,7 @@ struct ChargingInfoData
 	unsigned char		AcCcsChargingMode;				// 0:BC (PWM) only, 1:BC & PLC mixed
 	unsigned short		SampleChargingCur[10];
 
-	/**************Alston for AC***************/
+	/************** Alston ***************/
 	unsigned char 		SelfTest_Comp;
 	unsigned char		version[16];
 	unsigned char 		IsModeChagned;
@@ -603,7 +615,7 @@ struct ChargingInfoData
 	unsigned char 		ConnectorAlarmCode[7];
 	unsigned char 		EvConnAlarmCode[7];
 	float 				ChargingProfileCurrent;			//0~6553.5 amp
-	float 				ChargingProfilePower;			//0~6553.5 kW
+	float 				ChargingProfilePower;			//0~6553.5 W
 	float 				PresentChargingVoltageL2;		//0~6553.5 volt
 	float 				PresentChargingVoltageL3;		//0~6553.5 volt
 	float 				PresentChargingCurrentL2;		//0~6553.5 amp	
@@ -616,11 +628,15 @@ struct ChargingInfoData
 	int 				EvBatteryStartSoc;				// 0~100%
 	unsigned char 		NormalStopChargeFlag;			// for EV board
 	ChargingStop        ChargingStopFlag;
-	char 				ReservedStartFlag;
-	float 				ConnectorMaxVoltage;			// 0~6553.5 volt
-	float 				ConnectorMaxCurrent;			// 0~6553.5 volt
-	unsigned char 		ModelType;
+    char                ReservedStartFlag;
+    float               ConnectorMaxVoltage;            // 0~6553.5 volt
+    float               ConnectorMaxCurrent;            // 0~6553.5 volt
+    unsigned char       ModelType;
     MeterIcCalibration  meterIcCalInfo;
+    float               PowerOffered;                   //0~6553.5 kW
+    float               CurrentOffered;                 //0~6553.5 amp
+    struct timespec     ConnectorTimeout;
+    unsigned char       PantographFlag;                 // 0: normal gun type,  1: pantograph gun type
 };
 
 typedef union
@@ -772,7 +788,8 @@ typedef union
         unsigned int  AlarmStopRequest:1;               // 0: no effect,    1: connector alarm stop request                     ( dispenser -> cabinet)
         unsigned int  FaultStatusRequest:1;
         unsigned int  Disconnection:1;
-        unsigned int  res:10;
+        unsigned int  GfdDetection:1;                   // 0: stop,         1: start
+        unsigned int  res:9;
     }bits;
 }ConnectorParameter;
 
@@ -821,8 +838,8 @@ typedef union
         unsigned int AuthorizingCompleted:1;    // 0: not yet, 1: authorizing completed
         unsigned int DispenserDisconnection:1;  // 0: no connection,  1: dispenser connected
         unsigned int BackendAuthorized:1;       // 0: local authorized, 1: backend authorized
-        unsigned int WiringInfoChanged:1;       // 0: no effect, 1: wiring info has changed
-        unsigned int EnableWriteWiringInfo:1;   // 0: no effect, 1: enable write wiring info after timeout
+        unsigned int FlashConfigChanged:1;      // 0: no effect, 1: flash config has changed
+        unsigned int EnableWriteFlash:1;        // 0: no effect, 1: enable to write flash after timeout
         unsigned int CleanWiringInfo:1;         // 0: no effect, 1: clean wiring info
         unsigned int res:25;
     }bits;
@@ -905,6 +922,7 @@ struct SysInfoData
 	/**************Backend***************/
 	unsigned char 		OcppConnStatus;					//0: disconnected, 1: connected
 	char 				OrderCharging;
+    float               MaxChargingProfilePower;        //0~6553.5 W
 	/**************Alston***************/
 	unsigned char 		WaitForPlugit;					//0: none scan, 1: scanning
 	unsigned char 		PageIndex;						//0 : Initialize
@@ -923,7 +941,7 @@ struct SysInfoData
 	unsigned char 		FirmwareUpdate;					// 0 : none, 1 : update.
 	unsigned char 		AcContactorStatus;				// 0: disconnected, 1: connected
 	unsigned char 	 	SystemTimeoutFlag;				// 0 : none, 1 : self test
-	struct timeval		SystemTimeoutTimer;
+	struct timespec		SystemTimeoutTimer;
 	unsigned char 		SystemPage;
 	unsigned char 		ConnectorPage;
 	unsigned char		IsAlternatvieConf;				// 0 : normal, 1 : alternative
@@ -1124,8 +1142,8 @@ struct FaultCodeData
 			unsigned char BleModuleBroken:1;					//bit 2
 			unsigned char RotarySwitchFault:1;					//bit 3 
 			unsigned char CcsLiquidChillerWaterLevelFault:1;    //bit 4
-			unsigned char ChillerTempSensorBroken:1;            //bit 5
-			unsigned char :2;									//bit 6 ~ 7	reserved
+            unsigned char ChillerTempSensorBroken:1;            //bit 5
+            unsigned char :2;                                   //bit 6 ~ 7 reserved
 		}bits;
 	}FaultEvents;
 };
@@ -1257,9 +1275,9 @@ char AlarmStatusCode[128][6]=
     "012321",   // System CCS output UCP
     "012322",   // System GBT output UCP
     "012323",   // System Chiller output OTP
-    "012324",   // reserved
-    "012325",   // reserved
-    "012326",   // reserved
+    "012324",   // Connector 1 detects abnormal voltage on the output line
+    "012325",   // Connector 2 detects abnormal voltage on the output line
+    "012326",   // System task is lost
     "012327",   // reserved
 };
 */
@@ -1411,7 +1429,10 @@ struct AlarmCodeData
             unsigned char SystemCCSOutputUCP:1;                     //bit 1
             unsigned char SystemGBTOutputUCP:1;                     //bit 2
             unsigned char SystemChillerOTP:1;                       //bit 3
-            unsigned char Reserved:4;                               //bit 4~7
+            unsigned char AbnormalVoltageOnOutputLine_1:1;          //bit 4
+            unsigned char AbnormalVoltageOnOutputLine_2:1;          //bit 5
+            unsigned char SystemTaskLost:1;                         //bit 6
+            unsigned char Reserved:1;                               //bit 7
 		}bits;
 	}AlarmEvents;
 };
@@ -2148,8 +2169,8 @@ struct PsuModuleData
 	unsigned short 	InputCurrentL3;		//abcd=abc.d amp
 	unsigned short 	PresentOutputVoltage;	//abcd=abc.d volt
 	unsigned short 	PresentOutputCurrent;	//abcd=abc.d amp
-	unsigned short 	AvailableCurrent;		//abcd=abc.d amp
-	unsigned int 		AvailablePower;		//abcd=abc.d kWatt
+	unsigned short 	AvailableCurrent;		// unit: 0.1A
+	unsigned int 		AvailablePower;		// unit: 0.1kW
 	char 				CriticalTemp1;			//0x00: -60¢XC  ~  0xFE: 194¢XC, resolution: 1¢XC, offset: -60¢XC, 0xFF: invalid
 	char 				CriticalTemp2;			//0x00: -60¢XC  ~  0xFE: 194¢XC, resolution: 1¢XC, offset: -60¢XC, 0xFF: invalid
 	char 				CriticalTemp3;			//0x00: -60¢XC  ~  0xFE: 194¢XC, resolution: 1¢XC, offset: -60¢XC, 0xFF: invalid
@@ -2160,7 +2181,7 @@ struct PsuModuleData
 	char 				OutletTemp;			//0x00: -60¢XC  ~  0xFE: 194¢XC, resolution: 1¢XC, offset: -60¢XC, 0xFF: invalid
 	unsigned int 		AlarmCode;
 	unsigned int 		FaultCode;			//
-	unsigned int 		IAvailableCurrent;		//abcd=abc.d amp
+	unsigned int 		IAvailableCurrent;		            // unit: 0.1A
 };
 
 /*Following are the information for each PSU Group*/
@@ -2170,12 +2191,12 @@ struct PsuGroupData
 	unsigned char           GroupOutputPowerSwitch;         //0: D.D normal OFF,  1: D.D emergency OFF,  2: D.D ON
 	unsigned short          GroupTargetOutputVoltage;       //abcd=abc.d volt
 	unsigned short          GroupTargetOutputCurrent;       //abcd=abc.d amp
-	unsigned short          GroupAvailableCurrent;          //abcd=abc.d amp
-	unsigned int            GroupAvailablePower;            //abcd=abc.d kWatt
-	unsigned int            GroupRealOutputPower;           //Watt
-	unsigned short          GroupPresentOutputVoltage; 	    //abcd=abc.d volt
-	unsigned short          GroupPresentOutputCurrent;      //abcd=abc.d Amps
-	unsigned int            GroupPresentOutputPower;        //Watt
+	unsigned short          GroupAvailableCurrent;          // unit: 0.1A
+	unsigned int            GroupAvailablePower;            // unit: 0.1kW
+	unsigned int            GroupRealOutputPower;           // unit: 1kW
+	unsigned short          GroupPresentOutputVoltage; 	    // unit: 0.1V
+	unsigned short          GroupPresentOutputCurrent;      // unit: 0.1A
+	unsigned int            GroupPresentOutputPower;        // unit: 0.1kW
 	struct PsuModuleData 	PsuModule[MAX_PSU_QUANTITY];
 	PsuGroupError           GroupErrorFlag;
     unsigned short          TotalIAvailableCurrent;         // unit: 0.1A
@@ -3832,49 +3853,49 @@ struct CcsData
 /**************************************************************************************/
 struct PrimaryMcuData
 {
-	unsigned char 	SelfTest_Comp;
-	unsigned char	version[16];									//STM32F407 firmware version
-	unsigned int 	InputVoltage;									//value comes from external meter
-	unsigned int 	InputCurrent;									//value comes from external meter
-	union
-	{
-		unsigned char OutputDrvValue[1];
-		struct
-		{
-			//OutputDrvValue[0]
-			unsigned char OnButtonLedDrv:1;                     //bit 0,    H: ON,      L:OFF
-			unsigned char OffButtonLedDrv:1;                    //bit 1,    H: ON,      L:OFF
-			unsigned char SystemLed1Drv:1;                      //bit 2,    H: ON,      L:OFF
-			unsigned char SystemLed2Drv:1;                      //bit 3,    H: ON,      L:OFF
-			unsigned char SystemLed3Drv:1;                      //bit 4,    H: ON,      L:OFF
-			unsigned char SystemLed4Drv:1;                      //bit 5,    H: ON,      L:OFF
-			unsigned char AcContactorDrv:1;                     //bit 6,    H: ON,      L:OFF
-			unsigned char:1;                                    //bit 7 reserved
-		}bits;
-	}OutputDrv;
-	union
-	{
-		unsigned char InputDetValue[2];
-		struct
-		{
-			//InputDetValue[0]
-		    unsigned char AcContactorDetec:1;					//bit 0,	H: ON, 		L:OFF
-			unsigned char AcMainBreakerDetec:1;					//bit 1,	H: ON, 		L:OFF
-			unsigned char SpdDetec:1; 							//bit 2,	H: ON, 		L:OFF
-			unsigned char DoorOpen:1;							//bit 3,	H: Open,		L:Close
-			unsigned char Gfd1:1;								//bit 4,	H: Trigger,		L:Normal
-			unsigned char Gfd2:1;								//bit 5,	H: Trigger,		L:Normal
-			unsigned char Button1:1;								//bit 6 ,	H: Push, 		L:Release
-			unsigned char Button2:1;								//bit 7,	H: Push, 		L:Release
-			//InputDetValue[1]
-			unsigned char EmergencyButton:1;						//bit 0,	H: Push, 		L:Release
+    unsigned char   SelfTest_Comp;
+    unsigned char   version[16];                                //STM32F407 firmware version
+    unsigned int    InputVoltage;                               //value comes from external meter
+    unsigned int    InputCurrent;                               //value comes from external meter
+    union
+    {
+        unsigned char OutputDrvValue[1];
+        struct
+        {
+            //OutputDrvValue[0]
+            unsigned char OnButtonLedDrv:1;                     //bit 0,    H: ON,      L:OFF
+            unsigned char OffButtonLedDrv:1;                    //bit 1,    H: ON,      L:OFF
+            unsigned char SystemLed1Drv:1;                      //bit 2,    H: ON,      L:OFF
+            unsigned char SystemLed2Drv:1;                      //bit 3,    H: ON,      L:OFF
+            unsigned char SystemLed3Drv:1;                      //bit 4,    H: ON,      L:OFF
+            unsigned char SystemLed4Drv:1;                      //bit 5,    H: ON,      L:OFF
+            unsigned char AcContactorDrv:1;                     //bit 6,    H: ON,      L:OFF
+            unsigned char:1;                                    //bit 7 reserved
+        }bits;
+    }OutputDrv;
+    union
+    {
+        unsigned char InputDetValue[2];
+        struct
+        {
+            //InputDetValue[0]
+            unsigned char AcContactorDetec:1;                   //bit 0,    H: ON,      L:OFF
+            unsigned char AcMainBreakerDetec:1;                 //bit 1,    H: ON,      L:OFF
+            unsigned char SpdDetec:1;                           //bit 2,    H: ON,      L:OFF
+            unsigned char DoorOpen:1;                           //bit 3,    H: Open,    L:Close
+            unsigned char Gfd1:1;                               //bit 4,    H: Trigger, L:Normal
+            unsigned char Gfd2:1;                               //bit 5,    H: Trigger, L:Normal
+            unsigned char Button1:1;                            //bit 6 ,   H: Push,    L:Release
+            unsigned char Button2:1;                            //bit 7,    H: Push,    L:Release
+            //InputDetValue[1]
+            unsigned char EmergencyButton:1;                    //bit 0,    H: Push,    L:Release
             unsigned char Key0:1;                               //bit 1,    H: ON,      L:OFF
             unsigned char Key1:1;                               //bit 2,    H: ON,      L:OFF
             unsigned char Key2:1;                               //bit 3,    H: ON,      L:OFF
             unsigned char Key3:1;                               //bit 4,    H: ON,      L:OFF
             unsigned char :3;                                   //bit 5~7,  Reserved
-		}bits;
-	}InputDet;
+        }bits;
+    }InputDet;
 };
 /**************************************************************************************/
 /*************Fan power module Communication Share memory******************/
@@ -4295,7 +4316,7 @@ struct OCPP16ConfigurationItem
 {
 	unsigned char 		ItemName[64];
 	unsigned char 		ItemAccessibility;//0:RO, 1:RW
-	unsigned char 		ItemData[128];
+	unsigned char 		ItemData[500];
 };
 
 struct OCPP16ConfigurationTable
@@ -4750,6 +4771,7 @@ enum OCPP20CtrlrVariable
 	OCPPCommCtrlr_WebSocketPingInterval,
 	OCPPCommCtrlr_ResetRetries,
 	OCPPCommCtrlr_PublicKeyWithSignedMeterValue,
+    OCPPCommCtrlr_VariableVersion,
 	ReservationCtrlr_Enabled,
 	ReservationCtrlr_Available,
 	ReservationCtrlr_NonEvseSpecific,
@@ -5119,7 +5141,7 @@ struct UnitOfMeasureType
 
 struct SampledValueType
 {
-	float value;													// Required. Indicates the measured value.
+    double value;													// Required. Indicates the measured value.
 	unsigned char context[32];										// Optional. Type of detail value: start, end or sample. Default = "Sample.Periodic"
 	unsigned char measurand[32];									// Optional. Type of measurement. Default = "Energy.Active.Import.Register"
 	unsigned char phase[8];											// Optional. Indicates how the measured value is to be interpreted.
@@ -5371,6 +5393,7 @@ struct GetCertificateStatus_20
 	struct OCSPRequestDataType ocspRequestData;						// Required. Indicates the certificate of which the status is requested.
 	unsigned char Response_status[16];								// Required. This indicates whether the charging station was able to retrieve the OCSP certificate status.
 	unsigned char Response_ocspResult[5501];						// Optional. OCSPResponse class as defined in IETF RFC 6960. DER encoded (as defined in IETF RFC 6960), and then base64 encoded. MAY only be omitted when status is not Accepted.
+	struct StatusInfoType Response_statusInfo;                      // Optional. Detailed status information.
 };
 
 struct GetChargingProfiles_20

+ 67 - 6
EVSE/Projects/DD360Audi/Apps/ModuleDoComm/DoComm.c

@@ -57,10 +57,16 @@ static void removeFaultCodeToBuf(uint8_t *Code);
 static void addFaultCodeToBuf(uint8_t *Code);
 static int readMiscCommand(int fd, uint8_t id);
 static int writeCsuModuleVersion(int fd);
+static int writeGroundFaultDetection(int fd, uint8_t status, uint8_t id);
 
 //------------------------------------------------------------------------------
 //--- Common function ---
 //------------------------------------------------------------------------------
+void GetClockTime(struct timespec *_now_time, void *null)
+{
+    clock_gettime(CLOCK_MONOTONIC, _now_time);
+}
+
 /*static int StoreLogMsg(const char *fmt, ...)
 {
     char Buf[4096 + 256];
@@ -715,7 +721,7 @@ static int miscCommandHandle(uint8_t dataLen, uint8_t plugNum, uint8_t *data)
                     pSysInfo->WaitForPlugit = NO;
                     sleep(1); //Jerry add
                     pSysInfo->SystemPage = _LCM_SELECT_GUN;
-                    gettimeofday(&pSysInfo->SystemTimeoutTimer, NULL);
+                    GetClockTime(&pSysInfo->SystemTimeoutTimer, NULL);
                     pSysInfo->SystemTimeoutFlag = Timeout_None;
                 }
 
@@ -727,7 +733,7 @@ static int miscCommandHandle(uint8_t dataLen, uint8_t plugNum, uint8_t *data)
                     pSysInfo->WaitForPlugit = NO;
                     sleep(1); //Jerry add
                     pSysInfo->SystemPage = _LCM_SELECT_GUN;
-                    gettimeofday(&pSysInfo->SystemTimeoutTimer, NULL);
+                    GetClockTime(&pSysInfo->SystemTimeoutTimer, NULL);
                     pSysInfo->SystemTimeoutFlag = Timeout_None;
                 }
 
@@ -756,7 +762,7 @@ static int miscCommandHandle(uint8_t dataLen, uint8_t plugNum, uint8_t *data)
             strcpy((char *)pSysConfig->UserId, "");
             pSysInfo->WaitForPlugit = NO;
             pSysInfo->SystemPage = _LCM_SELECT_GUN;
-            gettimeofday(&pSysInfo->SystemTimeoutTimer, NULL);
+            GetClockTime(&pSysInfo->SystemTimeoutTimer, NULL);
             pSysInfo->SystemTimeoutFlag = Timeout_None;
             destroySelectGun(plugNum);
 
@@ -776,7 +782,7 @@ static int miscCommandHandle(uint8_t dataLen, uint8_t plugNum, uint8_t *data)
                 strcpy((char *)pSysConfig->UserId, "");
                 pSysInfo->WaitForPlugit = NO;
                 pSysInfo->SystemPage = _LCM_SELECT_GUN;
-                gettimeofday(&pSysInfo->SystemTimeoutTimer, NULL);
+                GetClockTime(&pSysInfo->SystemTimeoutTimer, NULL);
                 pSysInfo->SystemTimeoutFlag = Timeout_None;
                 destroySelectGun(plugNum);
             } else {
@@ -1167,6 +1173,26 @@ static int responsePackeHandle(int fd, uint8_t *pResult, uint8_t plugNum, uint8_
     case REG_WAIT_PLUG_IT_STATE:
         break;
 
+    case REG_Ground_Fault_Detection:
+        if (pCsuResult->Data.Result == COMMAND_RESULT_NG) {
+            return COMMAND_RESULT_NG;
+        }
+
+        //集電弓relay 不打開才能進入動作
+        pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(plugNum);
+        if(pDcChargingInfo->PantographFlag == YES)
+        {
+            GroundFaultDetection *gfd = (GroundFaultDetection *)&pCsuResult->Data.Data[0];
+            if(pDcChargingInfo->GroundFaultStatus != gfd->Status)
+            {
+                log_info("id = %d, GFD Result = %d\r\n",
+                           pCsuResult->Head.ID,
+                           gfd->Status);
+            }
+            pDcChargingInfo->GroundFaultStatus = gfd->Status;
+        }
+        break;
+
     default:
         break;
     }
@@ -1277,8 +1303,16 @@ static int writePresentChargingInfo(int fd, uint8_t plugNum, uint8_t id)
     PreChargingInfo *pPreChargingInfo = (PreChargingInfo *)dataBuf;
     pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(plugNum);
 
-    pPreChargingInfo->PresentChargingVoltage = htons((uint16_t)(pDcChargingInfo->PresentChargingVoltage * 10));
-    pPreChargingInfo->PresentChargingCurrent = htons((uint16_t)(pDcChargingInfo->PresentChargingCurrent * 10));
+    if(pDcChargingInfo->PantographFlag == NO)
+    {
+        pPreChargingInfo->PresentChargingVoltage = htons((uint16_t)(pDcChargingInfo->PresentChargingVoltage * 10));
+        pPreChargingInfo->PresentChargingCurrent = htons((uint16_t)(pDcChargingInfo->PresentChargingCurrent * 10));
+    }
+    else
+    {
+        pPreChargingInfo->PresentChargingVoltage = htons((uint16_t)(ShmDcCommonData->PcPsuOutput[plugNum].Voltage));
+        pPreChargingInfo->PresentChargingCurrent = htons((uint16_t)(ShmDcCommonData->PcPsuOutput[plugNum].Current));
+    }
     pPreChargingInfo->RemainChargingDuration = htonl(pDcChargingInfo->RemainChargingDuration);
     pPreChargingInfo->EvBatterySoc = pDcChargingInfo->EvBatterySoc;
 
@@ -1369,6 +1403,19 @@ static int readChargePermission(int fd, uint8_t id)
                              NULL);
 }
 
+static int writeGroundFaultDetection(int fd, uint8_t status, uint8_t id)
+{
+    int ret = PASS;
+    uint8_t dataBuf[1] = {status};
+    ret = composeSocketData(fd,
+                            id,
+                            OP_WRITE_DATA,
+                            REG_Ground_Fault_Detection,
+                            1,
+                            &dataBuf[0]);
+    return ret;
+}
+
 static int writeUserID(int fd, uint8_t id, uint8_t *pUserID)
 {
     if ((strlen((char *)pUserID) <= 0) || (pUserID == NULL)) {
@@ -1940,6 +1987,7 @@ static void systemStatusProcess(int fd, uint8_t totalGun, uint8_t plugNum, uint8
                 DiffTimeb(gRegTimeUp[plugNum][REG_CHARGING_CAP], AuthNowTime) < 0
            ) {
             readChargingCapability(fd, gunID);
+            writeGroundFaultDetection(fd, 0, gunID);
             ftime(&gRegTimeUp[plugNum][REG_CHARGING_CAP]);
         }
         break;
@@ -1973,6 +2021,7 @@ static void systemStatusProcess(int fd, uint8_t totalGun, uint8_t plugNum, uint8
                 DiffTimeb(gRegTimeUp[plugNum][REG_PRESENT_CHARGING_INFO], AuthNowTime) < 0
            ) {
             writePresentChargingInfo(fd, plugNum, gunID);
+            writeGroundFaultDetection(fd, 0, gunID);
             ftime(&gRegTimeUp[plugNum][REG_PRESENT_CHARGING_INFO]);
         }
         break;
@@ -2004,6 +2053,7 @@ static void systemStatusProcess(int fd, uint8_t totalGun, uint8_t plugNum, uint8
                 DiffTimeb(gRegTimeUp[plugNum][REG_PRESENT_CHARGING_INFO], AuthNowTime) < 0
            ) {
             writePresentChargingInfo(fd, plugNum, gunID);
+            writeGroundFaultDetection(fd, 0, gunID);
             ftime(&gRegTimeUp[plugNum][REG_PRESENT_CHARGING_INFO]);
         }
         break;
@@ -2012,6 +2062,7 @@ static void systemStatusProcess(int fd, uint8_t totalGun, uint8_t plugNum, uint8
     case S_CCS_PRECHARGE_ST0:
     case S_CCS_PRECHARGE_ST1:
         writeChargingTarget(fd, plugNum, gunID);
+        writeGroundFaultDetection(fd, 1, gunID);
 
         ftime(&AuthNowTime);
         if (DiffTimeb(gRegTimeUp[plugNum][REG_CHARGING_CAP], AuthNowTime) > LOOP_RETRY_TIME ||
@@ -2045,6 +2096,15 @@ static void systemStatusProcess(int fd, uint8_t totalGun, uint8_t plugNum, uint8
 
     case S_CHARGING: //charging
     case S_TERMINATING:
+        if(pDcChargingInfo->Type == _Type_GB || pDcChargingInfo->Type == _Type_Chademo)
+        {
+            writeGroundFaultDetection(fd, 0, gunID);
+        }
+        else
+        {
+            writeGroundFaultDetection(fd, 1, gunID);
+        }
+
         ftime(&AuthNowTime);
         if (DiffTimeb(gRegTimeUp[plugNum][REG_CHARGING_CAP], AuthNowTime) > LOOP_RETRY_TIME ||
                 DiffTimeb(gRegTimeUp[plugNum][REG_CHARGING_CAP], AuthNowTime) < 0
@@ -2083,6 +2143,7 @@ static void systemStatusProcess(int fd, uint8_t totalGun, uint8_t plugNum, uint8
                 DiffTimeb(gRegTimeUp[plugNum][REG_CHARGING_CAP], AuthNowTime) < 0
            ) {
             readChargingCapability(fd, gunID);
+            writeGroundFaultDetection(fd, 0, gunID);
             ftime(&gRegTimeUp[plugNum][REG_CHARGING_CAP]);
         }
         break;

+ 5 - 0
EVSE/Projects/DD360Audi/Apps/ModuleDoComm/DoComm.h

@@ -79,6 +79,7 @@
 #define REG_PRESENT_CHARGING_INFO               0X0F
 #define REG_QRCODE_URL_INFO                     0X10
 #define REG_WAIT_PLUG_IT_STATE                  0x11
+#define REG_Ground_Fault_Detection              0x12
 
 //------------------------------------------------------------------------------
 //--- dispenser result ---
@@ -207,6 +208,10 @@ typedef struct StPresentChargingInfo {
     uint8_t EvBatterySoc;               // 0~100%
 } PreChargingInfo;
 
+typedef struct StGroundFaultDetection { //Ground Fault Detection
+    uint8_t Status;
+} GroundFaultDetection;
+
 typedef struct StSoftwareUpdInfo {
     uint8_t UpdateState;         //1:update , 2: not update
     uint8_t ImgName[248];

+ 11 - 9
EVSE/Projects/DD360Audi/Apps/ModuleEvComm/Module_EvTxComm.c

@@ -505,7 +505,7 @@ static void SetPresentChargingOutputPower(void)
     PcPsuOutput *pPcPsuOutput2 = NULL;
     struct ChargingInfoData *chargingData_1 = NULL;
     struct ChargingInfoData *chargingData_2 = NULL;
-    bool isPsuOutput1 = false, isPsuOutput2 = false;
+    bool isPsuVol1 = false, isPsuVol2 = false, isPsuCur1 = false, isPsuCur2 = false;
 
     if (pSysConfig->TotalConnectorCount == 1) {
         pPcPsuOutput1 = (PcPsuOutput *)&ShmDcCommonData->PcPsuOutput[0];
@@ -522,15 +522,17 @@ static void SetPresentChargingOutputPower(void)
     psuOutputReady[0] = chargingData_1->SystemStatus != S_CHARGING ? false : psuOutputReady[0];
     psuOutputReady[1] = chargingData_2->SystemStatus != S_CHARGING ? false : psuOutputReady[1];
 
-    isPsuOutput1 = (pPcPsuOutput1->Voltage != 0 && psuOutputReady[0] == true);
-    isPsuOutput2 = (pPcPsuOutput2->Voltage != 0 && psuOutputReady[1] == true);
+    isPsuVol1 = chargingData_1->PantographFlag ? true : (pPcPsuOutput1->Voltage != 0 && psuOutputReady[0] == true);
+    isPsuVol2 = chargingData_2->PantographFlag ? true : (pPcPsuOutput2->Voltage != 0 && psuOutputReady[1] == true);
+    isPsuCur1 = chargingData_1->PantographFlag ? true : false;
+    isPsuCur2 = chargingData_2->PantographFlag ? true : false;
 
     //vol1 = chargingData_1->FireChargingVoltage;
-    vol1 = isPsuOutput1 == false ? chargingData_1->FireChargingVoltage : (((float)pPcPsuOutput1->Voltage));
-    cur1 = (chargingData_1->PresentChargingCurrent * 10);
+    vol1 = isPsuVol1 == false ? chargingData_1->FireChargingVoltage : (((float)pPcPsuOutput1->Voltage));
+    cur1 = isPsuCur1 == false ? (chargingData_1->PresentChargingCurrent * 10) : pPcPsuOutput1->Current;
     //vol2 = chargingData_2->FireChargingVoltage;
-    vol2 = isPsuOutput2 == false ? chargingData_2->FireChargingVoltage : (((float)pPcPsuOutput2->Voltage));
-    cur2 = (chargingData_2->PresentChargingCurrent * 10);
+    vol2 = isPsuVol2 == false ? chargingData_2->FireChargingVoltage : (((float)pPcPsuOutput2->Voltage));
+    cur2 = isPsuCur2 == false ? (chargingData_2->PresentChargingCurrent * 10) : pPcPsuOutput2->Current;
 
     //DS60-120 add
     if ((LogInfo[0][EV_LOG_NOW_OUTPUT_VOL] >= vol1 + CHK_VOL_RANGE) ||
@@ -543,10 +545,10 @@ static void SetPresentChargingOutputPower(void)
             (LogInfo[1][EV_LOG_NOW_OUTPUT_CUR] <= cur2 - CHK_CUR_RANGE)
        ) {
         log_info("G1 -> Output Vol(%s) = %.1f, Output Cur = %.1f -- G2 -> Output Vol(%s) = %.1f, Output Cur = %.1f\r\n",
-                 isPsuOutput1 == true ? "P" : "R",
+                 isPsuVol1 == true ? "P" : "R",
                  vol1 / 10,
                  cur1 / 10,
-                 isPsuOutput2 == true ? "P" : "R",
+                 isPsuVol2 == true ? "P" : "R",
                  vol2 / 10,
                  cur2 / 10);
 

+ 4 - 1
EVSE/Projects/DD360Audi/Apps/ModuleInternalComm/Module_InternalComm.c

@@ -100,7 +100,10 @@ int main(int argc, char *argv[])
     //FanBoardTask(fd);
 
     while (isContinue) {
-        AcPlugTask(fd);
+        if(AC_QUANTITY > 0)
+        {
+            AcPlugTask(fd);
+        }
         usleep(100000);
     }
 

+ 41 - 4
EVSE/Projects/DD360Audi/Apps/ModuleInternalComm/RelayBoard.c

@@ -780,6 +780,13 @@ void CableCheckDetected(uint8_t index)
                     SetGfdConfig(targetID, GFD_CHARGING);
                 }
             }
+        }
+        else if(pDcChargingInfo->SystemStatus == S_TERMINATING || pDcChargingInfo->SystemStatus == S_ALARM)
+        {
+            if (pDcChargingInfo->Type == _Type_CCS_2)
+            {
+                SetGfdConfig(targetID, GFD_CHARGING);
+            }
         } else {
             SetGfdConfig(targetID, GFD_IDLE);
         }
@@ -1648,6 +1655,7 @@ static void LEDBoardProcess(void)
 
 void RelayBoardTask(int uartFD)
 {
+    bool isRelayBypass = false;
     pid_t pid = fork();
 
     if (pid == 0) {
@@ -1671,8 +1679,20 @@ void RelayBoardTask(int uartFD)
 
         Uart5Fd = uartFD;
 
+        for(int i = 0; i < pSysConfig->TotalConnectorCount; i++)
+        {
+            pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(i);
+            if(pDcChargingInfo->PantographFlag == YES)
+            {
+                isRelayBypass = true;
+            }
+        }
+
         //relay init
-        outputRelayInit(uartFD);
+        if(isRelayBypass == false)
+        {
+            outputRelayInit(uartFD);
+        }
 
         while (isContinue) {
 
@@ -1683,7 +1703,7 @@ void RelayBoardTask(int uartFD)
             }
 
             // 程序開始之前~ 必須先確定 FW 版本與硬體版本,確認後!!~ 該模組才算是真正的 Initial Comp.
-            if (ShmRelayModuleData->SelfTest_Comp == NO) {
+            if (ShmRelayModuleData->SelfTest_Comp == NO && isRelayBypass == false) {
                 GetFwAndHwVersion_Relay();
                 SetModelName_Relay(); //DS60-120 add
                 SetRtcData_Relay();
@@ -1698,7 +1718,7 @@ void RelayBoardTask(int uartFD)
             LEDBoardSelfTest();
 #endif //defined DD360ComBox
 
-            if (ShmRelayModuleData->SelfTest_Comp == YES)
+            if (ShmRelayModuleData->SelfTest_Comp == YES && isRelayBypass == false)
             {
                 // ==============優先權最高 10 ms ==============
                 // 輸出電壓
@@ -1711,7 +1731,6 @@ void RelayBoardTask(int uartFD)
 
                 // 讀取當前 AC relay 狀態
                 regRelay.relay_event.bits.AC_Contactor = pSysInfo->AcContactorStatus;
-
                 GetRelayOutputStatus();
 
                 // Cable check (Get)
@@ -1848,6 +1867,24 @@ void RelayBoardTask(int uartFD)
                     }
                 }
             }
+            else if(isRelayBypass == true)
+            {
+                for(i = 0; i < pSysConfig->TotalConnectorCount; i++)
+                {
+                    pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(i);
+
+                    if (pDcChargingInfo->SystemStatus == S_IDLE ||
+                            pDcChargingInfo->SystemStatus == S_RESERVATION ||
+                            pDcChargingInfo->SystemStatus == S_MAINTAIN)
+                    {
+                        _isOvpChkTimeFlag[i] = NO;
+                    }
+                    if (pDcChargingInfo->SystemStatus == S_CHARGING)
+                    {
+                        CheckOutputPowerOverCarReq(i);
+                    }
+                }
+            }
 
 #if !defined NO_FAN_BOARD && !defined DD360ComBox
             fanBoardPorcess();

+ 4 - 0
EVSE/Projects/DD360Audi/Apps/ShareMemory/shmMem.c

@@ -923,6 +923,10 @@ static bool addGunInfoByConnector(uint8_t typeValue, uint8_t slots)
             pCcsData->CommProtocol = _CCS_COMM_V2GMessage_DIN70121;
             gGunIndexInfo.CcsIndex++;
             gGunIndexInfo.DcGunIndex++;
+            if(typeValue == 'P')
+            {
+                pDcChargingInfo->PantographFlag = YES;
+            }
         } else {
             result = false;
         }

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


BIN
EVSE/Projects/DD360Audi/output/FactoryConfig


BIN
EVSE/Projects/DD360Audi/output/Module_DoComm


BIN
EVSE/Projects/DD360Audi/output/Module_EvComm


BIN
EVSE/Projects/DD360Audi/output/Module_EventLogging


BIN
EVSE/Projects/DD360Audi/output/Module_InternalComm


BIN
EVSE/Projects/DD360Audi/output/Module_LcmControl


BIN
EVSE/Projects/DD360Audi/output/Module_PrimaryComm


BIN
EVSE/Projects/DD360Audi/output/ReadCmdline


BIN
EVSE/Projects/DD360Audi/output/main


+ 15 - 0
EVSE/Projects/DD360ComBox/Apps/CSU/SelfTest.c

@@ -18,6 +18,7 @@ extern void ChkPrimaryStatus(void);
 void SelfTestRun(void)
 {
     bool evInitFlag = false;
+    bool isRelayBypass = false;
     uint8_t index = 0;
     struct SysConfigData *pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
     struct SysInfoData *pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
@@ -34,6 +35,15 @@ void SelfTestRun(void)
     struct ChargingInfoData *pDcChargingInfo = NULL;
     struct ChargingInfoData *pAcChargingInfo = NULL;
 
+    for(int i = 0; i < pSysConfig->TotalConnectorCount; i++)
+    {
+        pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(i);
+        if(pDcChargingInfo->PantographFlag == YES)
+        {
+            isRelayBypass = true;
+        }
+    }
+
     StartSystemTimeoutDet(Timeout_SelftestChk);
     pSysInfo->SelfTestSeq = _STEST_VERSION;
 
@@ -62,6 +72,11 @@ void SelfTestRun(void)
 
         switch (pSysInfo->SelfTestSeq) {
         case _STEST_VERSION:
+            if(isRelayBypass == YES && ShmRelayModuleData->SelfTest_Comp != YES)
+            {
+                log_info("Relay Board Bypass");
+                ShmRelayModuleData->SelfTest_Comp = YES;
+            }
             if ((strlen((char *)pSysInfo->RelayModuleFwRev) != 0 ||
                     pSysInfo->RelayModuleFwRev[0] != '\0') &&
                     (ShmRelayModuleData->SelfTest_Comp != YES)

+ 32 - 12
EVSE/Projects/DD360ComBox/Apps/CSU/main.c

@@ -77,7 +77,7 @@ uint8_t bd0_2_status = 0;
 uint8_t bd1_1_status = 0;
 uint8_t bd1_2_status = 0;
 
-char *fwVersion = "V1.13.00.0000.00"; // "V0.16.00.0000.00";
+char *fwVersion = "V1.14.00.0000.00"; // "V0.16.00.0000.00";
 
 //sqlite3 *localDb;
 bool isDb_ready;
@@ -89,6 +89,8 @@ long long DiffTimebWithNow(struct timeb ST);
 uint8_t DetectBitValue(uint8_t _byte, uint8_t _bit);
 void SetBitValue(uint8_t *_byte, uint8_t _bit, uint8_t value);
 unsigned long GetTimeoutValue(struct timeval _sour_time);
+void GetClockTime(struct timespec *_now_time, void *null);
+unsigned long GetClockTimeoutValue(struct timespec _start_time);
 void gpio_set_value(unsigned int gpio, unsigned int value);
 void InformOcppErrOccur(uint8_t codeType);
 
@@ -753,6 +755,24 @@ unsigned long GetTimeoutValue(struct timeval _sour_time)
     return 1000000 * (_end_time.tv_sec - _sour_time.tv_sec) + _end_time.tv_usec - _sour_time.tv_usec;
 }
 
+void GetClockTime(struct timespec *_now_time, void *null)
+{
+    clock_gettime(CLOCK_MONOTONIC, _now_time);
+}
+
+// return value unit: 1us
+unsigned long GetClockTimeoutValue(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) * 1000000) + ((unsigned long)((ts_end.tv_nsec / 1000) - (_start_time.tv_nsec/ 1000)));
+
+    return ret;
+}
+
 int DiffTimeb(struct timeb ST, struct timeb ET)
 {
     //return milli-second
@@ -2645,14 +2665,14 @@ void KillAllTask(void)
 void StartSystemTimeoutDet(uint8_t flag)
 {
     if (pSysInfo->SystemTimeoutFlag != flag) {
-        gettimeofday(&pSysInfo->SystemTimeoutTimer, NULL);
+        GetClockTime(&pSysInfo->SystemTimeoutTimer, NULL);
     }
     pSysInfo->SystemTimeoutFlag = flag;
 }
 
 void StopSystemTimeoutDet(void)
 {
-    gettimeofday(&pSysInfo->SystemTimeoutTimer, NULL);
+    GetClockTime(&pSysInfo->SystemTimeoutTimer, NULL);
     pSysInfo->SystemTimeoutFlag = Timeout_None;
 }
 
@@ -2724,7 +2744,7 @@ void CreateTimeoutFork(void)
             // 系統
             switch (pSysInfo->SystemTimeoutFlag) {
             case Timeout_SelftestChk:
-                if (GetTimeoutValue(pSysInfo->SystemTimeoutTimer) / uSEC_VAL >= SELFTEST_TIMEOUT) {
+                if (GetClockTimeoutValue(pSysInfo->SystemTimeoutTimer) / uSEC_VAL >= SELFTEST_TIMEOUT) {
                     _SelfTestTimeout();
                     StopSystemTimeoutDet();
                     destroySelGun(DESTROY_ALL_SEL); //jerry add
@@ -2732,7 +2752,7 @@ void CreateTimeoutFork(void)
                 break;
 
             case Timeout_Authorizing:
-                if (GetTimeoutValue(pSysInfo->SystemTimeoutTimer) / uSEC_VAL >= AUTHORIZE_TIMEOUT) {
+                if (GetClockTimeoutValue(pSysInfo->SystemTimeoutTimer) / uSEC_VAL >= AUTHORIZE_TIMEOUT) {
                     _AuthorizedTimeout();
                     StopSystemTimeoutDet();
                     destroySelGun(pSysInfo->CurGunSelected);
@@ -2748,7 +2768,7 @@ void CreateTimeoutFork(void)
                 break;
 
             case Timeout_VerifyFail:
-                if (GetTimeoutValue(pSysInfo->SystemTimeoutTimer) / uSEC_VAL >= AUTHORIZE_FAIL_TIMEOUT) {
+                if (GetClockTimeoutValue(pSysInfo->SystemTimeoutTimer) / uSEC_VAL >= AUTHORIZE_FAIL_TIMEOUT) {
                     _AutoReturnTimeout();
                     StopSystemTimeoutDet();
                     destroySelGun(pSysInfo->CurGunSelected);
@@ -2764,14 +2784,14 @@ void CreateTimeoutFork(void)
                 break;
 
             case Timeout_VerifyComp:
-                if (GetTimeoutValue(pSysInfo->SystemTimeoutTimer) / uSEC_VAL >= AUTHORIZE_COMP_TIMEOUT) {
+                if (GetClockTimeoutValue(pSysInfo->SystemTimeoutTimer) / uSEC_VAL >= AUTHORIZE_COMP_TIMEOUT) {
                     _AutoReturnTimeout();
                     StopSystemTimeoutDet();
                 }
                 break;
 
             case Timeout_WaitPlug:
-                if (GetTimeoutValue(pSysInfo->SystemTimeoutTimer) / uSEC_VAL >= _connectionTimeout) {
+                if (GetClockTimeoutValue(pSysInfo->SystemTimeoutTimer) / uSEC_VAL >= _connectionTimeout) {
                     _DetectPlugInTimeout();
                     StopSystemTimeoutDet();
                     destroySelGun(pSysInfo->CurGunSelected);
@@ -2779,7 +2799,7 @@ void CreateTimeoutFork(void)
                 break;
 
             case Timeout_ReturnToChargingGunDet:
-                if (GetTimeoutValue(pSysInfo->SystemTimeoutTimer) / uSEC_VAL >= RETURN_TO_CHARGING_PAGE) {
+                if (GetClockTimeoutValue(pSysInfo->SystemTimeoutTimer) / uSEC_VAL >= RETURN_TO_CHARGING_PAGE) {
 #if defined DD360Audi
                     if (getCurLcmPage() != _LCM_PRE_CHARGE &&
                             getCurLcmPage() != _LCM_CHARGING &&
@@ -2794,7 +2814,7 @@ void CreateTimeoutFork(void)
                 break;
 
             case Timeout_AuthorizingForStop:
-                if (GetTimeoutValue(pSysInfo->SystemTimeoutTimer) / uSEC_VAL >= AUTHORIZE_STOP_TIMEOUT) {
+                if (GetClockTimeoutValue(pSysInfo->SystemTimeoutTimer) / uSEC_VAL >= AUTHORIZE_STOP_TIMEOUT) {
                     strcpy((char *)pSysConfig->UserId, "");
                     ClearAuthorizedFlag();
                     StopSystemTimeoutDet();
@@ -4996,7 +5016,7 @@ int main(void)
                 // 切換 D+ Relay to Precharge Relay
                 if (isPrechargeStatus_ccs(gunIndex) == 39 ||
                         isPrechargeStatus_ccs(gunIndex) == 40) {
-                    if (pDcChargingInfo->RelayKPK2Status == YES &&
+                    if ((pDcChargingInfo->RelayKPK2Status == YES || pDcChargingInfo->PantographFlag == YES) &&
                             pDcChargingInfo->PrechargeStatus != PRECHARGE_READY)
                         //if (pDcChargingInfo->PrechargeStatus != PRECHARGE_PRERELAY_PASS)
                     {
@@ -5041,7 +5061,7 @@ int main(void)
 
                 // 等待小板通知進入充電
                 // 切換 D+ Relay to Precharge Relay
-                if (pDcChargingInfo->RelayK1K2Status == YES) {
+                if (pDcChargingInfo->RelayK1K2Status == YES || pDcChargingInfo->PantographFlag == YES) {
                     pDcChargingInfo->PrechargeStatus = PRECHARGE_READY;
                     setChargerMode(gunIndex, MODE_CHARGING);
                 }

+ 105 - 82
EVSE/Projects/DD360ComBox/Apps/Define/define.h

@@ -176,6 +176,11 @@ Storage							0x0A200000-0x7FFFFFFF		1886 MB
 /**************************************************************************************/
 /****************** Share memory configuration value constant define ******************/
 /**************************************************************************************/
+struct NoneUse
+{
+    unsigned char       unknown;                    // None use struct
+};
+
 enum SYSTEM_STATUS
 {
 	SYS_MODE_BOOTING		= 0,
@@ -287,7 +292,7 @@ enum CoreProfile {
 	 TransactionMessageRetryInterval,
 	 UnlockConnectorOnEVSideDisconnect,
 	 WebSocketPingInterval,
-	 QueueOffLineStartTransactionMessage,
+	 QueueOffLineMeterValues,
 	 AuthorizationKey,
 	 SecurityProfile,
      DefaultPrice,
@@ -304,15 +309,21 @@ enum OCPP_RUNNING_VERSION {
     OCPP_RUNNING_VERSION_16=0,
     OCPP_RUNNING_VERSION_20
 };
+
+enum OCPP_START_ID_TYPE {
+    IdTokenType_Central=0,
+    IdTokenType_eMAID,
+    IdTokenType_ISO14443,
+    IdTokenType_KeyCode,
+    IdTokenType_Local,
+    IdTokenType_NoAuthorization,
+    IdTokenType_ISO15693
+};
 /**************************************************************************************/
 /****structure SysConfigData => shall store the data to NAND flash****************/
 /****structure SysInfoData => shall NOT store the data to NAND flash***************/
 /****according to System Configuration and Information Table.xlsx Rev.0.2 *******/
 /**************************************************************************************/
-struct NoneUse
-{
-	unsigned char		unknown;					// None use struct
-};
 
 struct EthConfigData
 {
@@ -454,9 +465,9 @@ typedef struct
     unsigned int isCalibratedCaOffset:1;                // Current phase a offset is calibrated, 0: default 1: Calibrated
     unsigned int isCalibratedCbOffset:1;                // Current phase b offset is calibrated, 0: default 1: Calibrated
     unsigned int isCalibratedCcOffset:1;                // Current phase c offset is calibrated, 0: default 1: Calibrated
-    unsigned int isCalibratedPa:1;                      // Phase angle a is calibrated, 0: default  1: Calibrated
-    unsigned int isCalibratedPb:1;                      // Phase angle b gain is calibrated, 0: default 1: Calibrated
-    unsigned int isCalibratedPc:1;                      // Phase angle c gain is calibrated, 0: default 1: Calibrated
+    unsigned int isCalibratedPa:1;                      // Phase angle a is calibrated, 0: default          1: Calibrated
+    unsigned int isCalibratedPb:1;                      // Phase angle b gain is calibrated, 0: default     1: Calibrated
+    unsigned int isCalibratedPc:1;                      // Phase angle c gain is calibrated, 0: default     1: Calibrated
     unsigned int :1;
 }MeterIcCalibration;
 
@@ -515,8 +526,8 @@ struct SysConfigData
 	unsigned char 			OcppServerURL[512];			//http: non-secure OCPP 1.5-S, https: secure OCPP 1.5-S, ws: non-secure OCPP 1.6-J, wss: secure OCPP 1.6-J"
 	unsigned char 			ChargeBoxId[128];
 	unsigned char			chargePointVendor[20];		//the Vendor of the ChargePoint
-	unsigned char			OcppSecurityProfile;		//OCPP security profile 0~3
-	unsigned char			OcppSecurityPassword[41];	//OCPP AuthorizationKey for security profile
+    unsigned char           OcppSecurityProfile;        //OCPP security profile 0~3
+    unsigned char           OcppSecurityPassword[41];   //OCPP AuthorizationKey for security profile
 	unsigned int 			Checksum;					//4 bytes checksum
 	struct LED				LedInfo;					// LED configuration info
 	unsigned char			ShowInformation;
@@ -544,14 +555,14 @@ struct ChargingInfoData
 	unsigned char 		IsAvailable;
 	float MaximumChargingVoltage;	// unit 0.1V
 	float AvailableChargingCurrent;	// unit 0.1A
-	float AvailableChargingPower;	// unit .01kW
+	float AvailableChargingPower;	// unit 0.1kW
 	float DividChargingCurrent;		//0~6553.5 amp
-	float DeratingChargingCurrent;  //0~6553.5 amp
-	float DeratingChargingPower;	//0~6553.5 kW
+	float DeratingChargingCurrent;  // unit 0.1A
+	float DeratingChargingPower;	// unit 0.1kW
 	float FuseChargingVoltage;		//0~6553.5 volt
 	float FireChargingVoltage;		//0~6553.5 volt
-	float PresentChargingVoltage;	//0~6553.5 volt
-	float PresentChargingCurrent;		//0~6553.5 amp
+	float PresentChargingVoltage;   // unit: 1V
+	float PresentChargingCurrent;   // unit: 1A
 	float PresentChargingPower;		//0~6553.5 kW
 	float PresentChargedEnergy;		//0~6553.5 kWh
 	int PresentChargedDuration;	// second
@@ -566,17 +577,18 @@ struct ChargingInfoData
 	unsigned char PilotState;//1:state A, 2:State B1, 3:State B2, 4:State C, 5:State D, 6:State E, 7:State F, 8: Pilot error
 	unsigned char PilotDuty;					// 0~100%
 	unsigned char			StartUserId[32];			// This ID is trigger start charging event user by RFID, back-end, BLE.
+	unsigned char           StartIdType;                // 0: Central   1: eMAID    2: ISO14443 3: ISO15693 4: KeyCode  5: Local    6: MaxAddress   7: NoAuthorization
 	unsigned char			StartDateTime[32];			// Charging cycle start date time
 	unsigned char			StopDateTime[32];			// Charging cycle stop date time
 	unsigned char			StartMethod;
 	float					ChargingFee;
 	// Connector Temp
 	unsigned char 		ConnectorTemp;			//0x00: -60¢XC  ~  0xFE: 194
-	//Chiller Temp
+    //Chiller Temp
     unsigned char       ChillerTemp;            //0x00: -60¢XC  ~  0xFE: 194
 	// Charging Status
 	unsigned char 		GroundFaultStatus;		// for GFD result => 0x00 : None, 0x01 : Can Start Charging, 0x02 : Stop Charging
-	unsigned short		RealRatingPower;
+	unsigned short		RealRatingPower;        // unit: 0.1kW
 	unsigned char 		RelayWeldingCheck;		// 0 : No Comp., 1 : Comp.
 	unsigned char 		PrechargeStatus;		// for ccs precharge => 0x00 : None defined, 0x01 : Accepted
 	float 				PowerConsumption;		// This contains the meter value (Power Consumption) kWh
@@ -590,7 +602,7 @@ struct ChargingInfoData
 	unsigned char		AcCcsChargingMode;				// 0:BC (PWM) only, 1:BC & PLC mixed
 	unsigned short		SampleChargingCur[10];
 
-	/**************Alston for AC***************/
+	/************** Alston ***************/
 	unsigned char 		SelfTest_Comp;
 	unsigned char		version[16];
 	unsigned char 		IsModeChagned;
@@ -603,7 +615,7 @@ struct ChargingInfoData
 	unsigned char 		ConnectorAlarmCode[7];
 	unsigned char 		EvConnAlarmCode[7];
 	float 				ChargingProfileCurrent;			//0~6553.5 amp
-	float 				ChargingProfilePower;			//0~6553.5 kW
+	float 				ChargingProfilePower;			//0~6553.5 W
 	float 				PresentChargingVoltageL2;		//0~6553.5 volt
 	float 				PresentChargingVoltageL3;		//0~6553.5 volt
 	float 				PresentChargingCurrentL2;		//0~6553.5 amp	
@@ -616,11 +628,15 @@ struct ChargingInfoData
 	int 				EvBatteryStartSoc;				// 0~100%
 	unsigned char 		NormalStopChargeFlag;			// for EV board
 	ChargingStop        ChargingStopFlag;
-	char 				ReservedStartFlag;
-	float 				ConnectorMaxVoltage;			// 0~6553.5 volt
-	float 				ConnectorMaxCurrent;			// 0~6553.5 volt
-	unsigned char 		ModelType;
+    char                ReservedStartFlag;
+    float               ConnectorMaxVoltage;            // 0~6553.5 volt
+    float               ConnectorMaxCurrent;            // 0~6553.5 volt
+    unsigned char       ModelType;
     MeterIcCalibration  meterIcCalInfo;
+    float               PowerOffered;                   //0~6553.5 kW
+    float               CurrentOffered;                 //0~6553.5 amp
+    struct timespec     ConnectorTimeout;
+    unsigned char       PantographFlag;                 // 0: normal gun type,  1: pantograph gun type
 };
 
 typedef union
@@ -772,7 +788,8 @@ typedef union
         unsigned int  AlarmStopRequest:1;               // 0: no effect,    1: connector alarm stop request                     ( dispenser -> cabinet)
         unsigned int  FaultStatusRequest:1;
         unsigned int  Disconnection:1;
-        unsigned int  res:10;
+        unsigned int  GfdDetection:1;                   // 0: stop,         1: start
+        unsigned int  res:9;
     }bits;
 }ConnectorParameter;
 
@@ -821,8 +838,8 @@ typedef union
         unsigned int AuthorizingCompleted:1;    // 0: not yet, 1: authorizing completed
         unsigned int DispenserDisconnection:1;  // 0: no connection,  1: dispenser connected
         unsigned int BackendAuthorized:1;       // 0: local authorized, 1: backend authorized
-        unsigned int WiringInfoChanged:1;       // 0: no effect, 1: wiring info has changed
-        unsigned int EnableWriteWiringInfo:1;   // 0: no effect, 1: enable write wiring info after timeout
+        unsigned int FlashConfigChanged:1;      // 0: no effect, 1: flash config has changed
+        unsigned int EnableWriteFlash:1;        // 0: no effect, 1: enable to write flash after timeout
         unsigned int CleanWiringInfo:1;         // 0: no effect, 1: clean wiring info
         unsigned int res:25;
     }bits;
@@ -905,6 +922,7 @@ struct SysInfoData
 	/**************Backend***************/
 	unsigned char 		OcppConnStatus;					//0: disconnected, 1: connected
 	char 				OrderCharging;
+    float               MaxChargingProfilePower;        //0~6553.5 W
 	/**************Alston***************/
 	unsigned char 		WaitForPlugit;					//0: none scan, 1: scanning
 	unsigned char 		PageIndex;						//0 : Initialize
@@ -923,7 +941,7 @@ struct SysInfoData
 	unsigned char 		FirmwareUpdate;					// 0 : none, 1 : update.
 	unsigned char 		AcContactorStatus;				// 0: disconnected, 1: connected
 	unsigned char 	 	SystemTimeoutFlag;				// 0 : none, 1 : self test
-	struct timeval		SystemTimeoutTimer;
+	struct timespec		SystemTimeoutTimer;
 	unsigned char 		SystemPage;
 	unsigned char 		ConnectorPage;
 	unsigned char		IsAlternatvieConf;				// 0 : normal, 1 : alternative
@@ -1124,8 +1142,8 @@ struct FaultCodeData
 			unsigned char BleModuleBroken:1;					//bit 2
 			unsigned char RotarySwitchFault:1;					//bit 3 
 			unsigned char CcsLiquidChillerWaterLevelFault:1;    //bit 4
-			unsigned char ChillerTempSensorBroken:1;            //bit 5
-			unsigned char :2;									//bit 6 ~ 7	reserved
+            unsigned char ChillerTempSensorBroken:1;            //bit 5
+            unsigned char :2;                                   //bit 6 ~ 7 reserved
 		}bits;
 	}FaultEvents;
 };
@@ -1257,9 +1275,9 @@ char AlarmStatusCode[128][6]=
     "012321",   // System CCS output UCP
     "012322",   // System GBT output UCP
     "012323",   // System Chiller output OTP
-    "012324",   // reserved
-    "012325",   // reserved
-    "012326",   // reserved
+    "012324",   // Connector 1 detects abnormal voltage on the output line
+    "012325",   // Connector 2 detects abnormal voltage on the output line
+    "012326",   // System task is lost
     "012327",   // reserved
 };
 */
@@ -1411,7 +1429,10 @@ struct AlarmCodeData
             unsigned char SystemCCSOutputUCP:1;                     //bit 1
             unsigned char SystemGBTOutputUCP:1;                     //bit 2
             unsigned char SystemChillerOTP:1;                       //bit 3
-            unsigned char Reserved:4;                               //bit 4~7
+            unsigned char AbnormalVoltageOnOutputLine_1:1;          //bit 4
+            unsigned char AbnormalVoltageOnOutputLine_2:1;          //bit 5
+            unsigned char SystemTaskLost:1;                         //bit 6
+            unsigned char Reserved:1;                               //bit 7
 		}bits;
 	}AlarmEvents;
 };
@@ -2148,8 +2169,8 @@ struct PsuModuleData
 	unsigned short 	InputCurrentL3;		//abcd=abc.d amp
 	unsigned short 	PresentOutputVoltage;	//abcd=abc.d volt
 	unsigned short 	PresentOutputCurrent;	//abcd=abc.d amp
-	unsigned short 	AvailableCurrent;		//abcd=abc.d amp
-	unsigned int 		AvailablePower;		//abcd=abc.d kWatt
+	unsigned short 	AvailableCurrent;		// unit: 0.1A
+	unsigned int 		AvailablePower;		// unit: 0.1kW
 	char 				CriticalTemp1;			//0x00: -60¢XC  ~  0xFE: 194¢XC, resolution: 1¢XC, offset: -60¢XC, 0xFF: invalid
 	char 				CriticalTemp2;			//0x00: -60¢XC  ~  0xFE: 194¢XC, resolution: 1¢XC, offset: -60¢XC, 0xFF: invalid
 	char 				CriticalTemp3;			//0x00: -60¢XC  ~  0xFE: 194¢XC, resolution: 1¢XC, offset: -60¢XC, 0xFF: invalid
@@ -2160,7 +2181,7 @@ struct PsuModuleData
 	char 				OutletTemp;			//0x00: -60¢XC  ~  0xFE: 194¢XC, resolution: 1¢XC, offset: -60¢XC, 0xFF: invalid
 	unsigned int 		AlarmCode;
 	unsigned int 		FaultCode;			//
-	unsigned int 		IAvailableCurrent;		//abcd=abc.d amp
+	unsigned int 		IAvailableCurrent;		            // unit: 0.1A
 };
 
 /*Following are the information for each PSU Group*/
@@ -2170,12 +2191,12 @@ struct PsuGroupData
 	unsigned char           GroupOutputPowerSwitch;         //0: D.D normal OFF,  1: D.D emergency OFF,  2: D.D ON
 	unsigned short          GroupTargetOutputVoltage;       //abcd=abc.d volt
 	unsigned short          GroupTargetOutputCurrent;       //abcd=abc.d amp
-	unsigned short          GroupAvailableCurrent;          //abcd=abc.d amp
-	unsigned int            GroupAvailablePower;            //abcd=abc.d kWatt
-	unsigned int            GroupRealOutputPower;           //Watt
-	unsigned short          GroupPresentOutputVoltage; 	    //abcd=abc.d volt
-	unsigned short          GroupPresentOutputCurrent;      //abcd=abc.d Amps
-	unsigned int            GroupPresentOutputPower;        //Watt
+	unsigned short          GroupAvailableCurrent;          // unit: 0.1A
+	unsigned int            GroupAvailablePower;            // unit: 0.1kW
+	unsigned int            GroupRealOutputPower;           // unit: 1kW
+	unsigned short          GroupPresentOutputVoltage; 	    // unit: 0.1V
+	unsigned short          GroupPresentOutputCurrent;      // unit: 0.1A
+	unsigned int            GroupPresentOutputPower;        // unit: 0.1kW
 	struct PsuModuleData 	PsuModule[MAX_PSU_QUANTITY];
 	PsuGroupError           GroupErrorFlag;
     unsigned short          TotalIAvailableCurrent;         // unit: 0.1A
@@ -3832,49 +3853,49 @@ struct CcsData
 /**************************************************************************************/
 struct PrimaryMcuData
 {
-	unsigned char 	SelfTest_Comp;
-	unsigned char	version[16];									//STM32F407 firmware version
-	unsigned int 	InputVoltage;									//value comes from external meter
-	unsigned int 	InputCurrent;									//value comes from external meter
-	union
-	{
-		unsigned char OutputDrvValue[1];
-		struct
-		{
-			//OutputDrvValue[0]
-			unsigned char OnButtonLedDrv:1;                     //bit 0,    H: ON,      L:OFF
-			unsigned char OffButtonLedDrv:1;                    //bit 1,    H: ON,      L:OFF
-			unsigned char SystemLed1Drv:1;                      //bit 2,    H: ON,      L:OFF
-			unsigned char SystemLed2Drv:1;                      //bit 3,    H: ON,      L:OFF
-			unsigned char SystemLed3Drv:1;                      //bit 4,    H: ON,      L:OFF
-			unsigned char SystemLed4Drv:1;                      //bit 5,    H: ON,      L:OFF
-			unsigned char AcContactorDrv:1;                     //bit 6,    H: ON,      L:OFF
-			unsigned char:1;                                    //bit 7 reserved
-		}bits;
-	}OutputDrv;
-	union
-	{
-		unsigned char InputDetValue[2];
-		struct
-		{
-			//InputDetValue[0]
-		    unsigned char AcContactorDetec:1;					//bit 0,	H: ON, 		L:OFF
-			unsigned char AcMainBreakerDetec:1;					//bit 1,	H: ON, 		L:OFF
-			unsigned char SpdDetec:1; 							//bit 2,	H: ON, 		L:OFF
-			unsigned char DoorOpen:1;							//bit 3,	H: Open,		L:Close
-			unsigned char Gfd1:1;								//bit 4,	H: Trigger,		L:Normal
-			unsigned char Gfd2:1;								//bit 5,	H: Trigger,		L:Normal
-			unsigned char Button1:1;								//bit 6 ,	H: Push, 		L:Release
-			unsigned char Button2:1;								//bit 7,	H: Push, 		L:Release
-			//InputDetValue[1]
-			unsigned char EmergencyButton:1;						//bit 0,	H: Push, 		L:Release
+    unsigned char   SelfTest_Comp;
+    unsigned char   version[16];                                //STM32F407 firmware version
+    unsigned int    InputVoltage;                               //value comes from external meter
+    unsigned int    InputCurrent;                               //value comes from external meter
+    union
+    {
+        unsigned char OutputDrvValue[1];
+        struct
+        {
+            //OutputDrvValue[0]
+            unsigned char OnButtonLedDrv:1;                     //bit 0,    H: ON,      L:OFF
+            unsigned char OffButtonLedDrv:1;                    //bit 1,    H: ON,      L:OFF
+            unsigned char SystemLed1Drv:1;                      //bit 2,    H: ON,      L:OFF
+            unsigned char SystemLed2Drv:1;                      //bit 3,    H: ON,      L:OFF
+            unsigned char SystemLed3Drv:1;                      //bit 4,    H: ON,      L:OFF
+            unsigned char SystemLed4Drv:1;                      //bit 5,    H: ON,      L:OFF
+            unsigned char AcContactorDrv:1;                     //bit 6,    H: ON,      L:OFF
+            unsigned char:1;                                    //bit 7 reserved
+        }bits;
+    }OutputDrv;
+    union
+    {
+        unsigned char InputDetValue[2];
+        struct
+        {
+            //InputDetValue[0]
+            unsigned char AcContactorDetec:1;                   //bit 0,    H: ON,      L:OFF
+            unsigned char AcMainBreakerDetec:1;                 //bit 1,    H: ON,      L:OFF
+            unsigned char SpdDetec:1;                           //bit 2,    H: ON,      L:OFF
+            unsigned char DoorOpen:1;                           //bit 3,    H: Open,    L:Close
+            unsigned char Gfd1:1;                               //bit 4,    H: Trigger, L:Normal
+            unsigned char Gfd2:1;                               //bit 5,    H: Trigger, L:Normal
+            unsigned char Button1:1;                            //bit 6 ,   H: Push,    L:Release
+            unsigned char Button2:1;                            //bit 7,    H: Push,    L:Release
+            //InputDetValue[1]
+            unsigned char EmergencyButton:1;                    //bit 0,    H: Push,    L:Release
             unsigned char Key0:1;                               //bit 1,    H: ON,      L:OFF
             unsigned char Key1:1;                               //bit 2,    H: ON,      L:OFF
             unsigned char Key2:1;                               //bit 3,    H: ON,      L:OFF
             unsigned char Key3:1;                               //bit 4,    H: ON,      L:OFF
             unsigned char :3;                                   //bit 5~7,  Reserved
-		}bits;
-	}InputDet;
+        }bits;
+    }InputDet;
 };
 /**************************************************************************************/
 /*************Fan power module Communication Share memory******************/
@@ -4295,7 +4316,7 @@ struct OCPP16ConfigurationItem
 {
 	unsigned char 		ItemName[64];
 	unsigned char 		ItemAccessibility;//0:RO, 1:RW
-	unsigned char 		ItemData[128];
+	unsigned char 		ItemData[500];
 };
 
 struct OCPP16ConfigurationTable
@@ -4750,6 +4771,7 @@ enum OCPP20CtrlrVariable
 	OCPPCommCtrlr_WebSocketPingInterval,
 	OCPPCommCtrlr_ResetRetries,
 	OCPPCommCtrlr_PublicKeyWithSignedMeterValue,
+    OCPPCommCtrlr_VariableVersion,
 	ReservationCtrlr_Enabled,
 	ReservationCtrlr_Available,
 	ReservationCtrlr_NonEvseSpecific,
@@ -5119,7 +5141,7 @@ struct UnitOfMeasureType
 
 struct SampledValueType
 {
-	float value;													// Required. Indicates the measured value.
+    double value;													// Required. Indicates the measured value.
 	unsigned char context[32];										// Optional. Type of detail value: start, end or sample. Default = "Sample.Periodic"
 	unsigned char measurand[32];									// Optional. Type of measurement. Default = "Energy.Active.Import.Register"
 	unsigned char phase[8];											// Optional. Indicates how the measured value is to be interpreted.
@@ -5371,6 +5393,7 @@ struct GetCertificateStatus_20
 	struct OCSPRequestDataType ocspRequestData;						// Required. Indicates the certificate of which the status is requested.
 	unsigned char Response_status[16];								// Required. This indicates whether the charging station was able to retrieve the OCSP certificate status.
 	unsigned char Response_ocspResult[5501];						// Optional. OCSPResponse class as defined in IETF RFC 6960. DER encoded (as defined in IETF RFC 6960), and then base64 encoded. MAY only be omitted when status is not Accepted.
+	struct StatusInfoType Response_statusInfo;                      // Optional. Detailed status information.
 };
 
 struct GetChargingProfiles_20

+ 67 - 6
EVSE/Projects/DD360ComBox/Apps/ModuleDoComm/DoComm.c

@@ -57,10 +57,16 @@ static void removeFaultCodeToBuf(uint8_t *Code);
 static void addFaultCodeToBuf(uint8_t *Code);
 static int readMiscCommand(int fd, uint8_t id);
 static int writeCsuModuleVersion(int fd);
+static int writeGroundFaultDetection(int fd, uint8_t status, uint8_t id);
 
 //------------------------------------------------------------------------------
 //--- Common function ---
 //------------------------------------------------------------------------------
+void GetClockTime(struct timespec *_now_time, void *null)
+{
+    clock_gettime(CLOCK_MONOTONIC, _now_time);
+}
+
 /*static int StoreLogMsg(const char *fmt, ...)
 {
     char Buf[4096 + 256];
@@ -715,7 +721,7 @@ static int miscCommandHandle(uint8_t dataLen, uint8_t plugNum, uint8_t *data)
                     pSysInfo->WaitForPlugit = NO;
                     sleep(1); //Jerry add
                     pSysInfo->SystemPage = _LCM_SELECT_GUN;
-                    gettimeofday(&pSysInfo->SystemTimeoutTimer, NULL);
+                    GetClockTime(&pSysInfo->SystemTimeoutTimer, NULL);
                     pSysInfo->SystemTimeoutFlag = Timeout_None;
                 }
 
@@ -727,7 +733,7 @@ static int miscCommandHandle(uint8_t dataLen, uint8_t plugNum, uint8_t *data)
                     pSysInfo->WaitForPlugit = NO;
                     sleep(1); //Jerry add
                     pSysInfo->SystemPage = _LCM_SELECT_GUN;
-                    gettimeofday(&pSysInfo->SystemTimeoutTimer, NULL);
+                    GetClockTime(&pSysInfo->SystemTimeoutTimer, NULL);
                     pSysInfo->SystemTimeoutFlag = Timeout_None;
                 }
 
@@ -756,7 +762,7 @@ static int miscCommandHandle(uint8_t dataLen, uint8_t plugNum, uint8_t *data)
             strcpy((char *)pSysConfig->UserId, "");
             pSysInfo->WaitForPlugit = NO;
             pSysInfo->SystemPage = _LCM_SELECT_GUN;
-            gettimeofday(&pSysInfo->SystemTimeoutTimer, NULL);
+            GetClockTime(&pSysInfo->SystemTimeoutTimer, NULL);
             pSysInfo->SystemTimeoutFlag = Timeout_None;
             destroySelectGun(plugNum);
 
@@ -776,7 +782,7 @@ static int miscCommandHandle(uint8_t dataLen, uint8_t plugNum, uint8_t *data)
                 strcpy((char *)pSysConfig->UserId, "");
                 pSysInfo->WaitForPlugit = NO;
                 pSysInfo->SystemPage = _LCM_SELECT_GUN;
-                gettimeofday(&pSysInfo->SystemTimeoutTimer, NULL);
+                GetClockTime(&pSysInfo->SystemTimeoutTimer, NULL);
                 pSysInfo->SystemTimeoutFlag = Timeout_None;
                 destroySelectGun(plugNum);
             } else {
@@ -1167,6 +1173,26 @@ static int responsePackeHandle(int fd, uint8_t *pResult, uint8_t plugNum, uint8_
     case REG_WAIT_PLUG_IT_STATE:
         break;
 
+    case REG_Ground_Fault_Detection:
+        if (pCsuResult->Data.Result == COMMAND_RESULT_NG) {
+            return COMMAND_RESULT_NG;
+        }
+
+        //集電弓relay 不打開才能進入動作
+        pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(plugNum);
+        if(pDcChargingInfo->PantographFlag == YES)
+        {
+            GroundFaultDetection *gfd = (GroundFaultDetection *)&pCsuResult->Data.Data[0];
+            if(pDcChargingInfo->GroundFaultStatus != gfd->Status)
+            {
+                log_info("id = %d, GFD Result = %d\r\n",
+                           pCsuResult->Head.ID,
+                           gfd->Status);
+            }
+            pDcChargingInfo->GroundFaultStatus = gfd->Status;
+        }
+        break;
+
     default:
         break;
     }
@@ -1277,8 +1303,16 @@ static int writePresentChargingInfo(int fd, uint8_t plugNum, uint8_t id)
     PreChargingInfo *pPreChargingInfo = (PreChargingInfo *)dataBuf;
     pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(plugNum);
 
-    pPreChargingInfo->PresentChargingVoltage = htons((uint16_t)(pDcChargingInfo->PresentChargingVoltage * 10));
-    pPreChargingInfo->PresentChargingCurrent = htons((uint16_t)(pDcChargingInfo->PresentChargingCurrent * 10));
+    if(pDcChargingInfo->PantographFlag == NO)
+    {
+        pPreChargingInfo->PresentChargingVoltage = htons((uint16_t)(pDcChargingInfo->PresentChargingVoltage * 10));
+        pPreChargingInfo->PresentChargingCurrent = htons((uint16_t)(pDcChargingInfo->PresentChargingCurrent * 10));
+    }
+    else
+    {
+        pPreChargingInfo->PresentChargingVoltage = htons((uint16_t)(ShmDcCommonData->PcPsuOutput[plugNum].Voltage));
+        pPreChargingInfo->PresentChargingCurrent = htons((uint16_t)(ShmDcCommonData->PcPsuOutput[plugNum].Current));
+    }
     pPreChargingInfo->RemainChargingDuration = htonl(pDcChargingInfo->RemainChargingDuration);
     pPreChargingInfo->EvBatterySoc = pDcChargingInfo->EvBatterySoc;
 
@@ -1369,6 +1403,19 @@ static int readChargePermission(int fd, uint8_t id)
                              NULL);
 }
 
+static int writeGroundFaultDetection(int fd, uint8_t status, uint8_t id)
+{
+    int ret = PASS;
+    uint8_t dataBuf[1] = {status};
+    ret = composeSocketData(fd,
+                            id,
+                            OP_WRITE_DATA,
+                            REG_Ground_Fault_Detection,
+                            1,
+                            &dataBuf[0]);
+    return ret;
+}
+
 static int writeUserID(int fd, uint8_t id, uint8_t *pUserID)
 {
     if ((strlen((char *)pUserID) <= 0) || (pUserID == NULL)) {
@@ -1940,6 +1987,7 @@ static void systemStatusProcess(int fd, uint8_t totalGun, uint8_t plugNum, uint8
                 DiffTimeb(gRegTimeUp[plugNum][REG_CHARGING_CAP], AuthNowTime) < 0
            ) {
             readChargingCapability(fd, gunID);
+            writeGroundFaultDetection(fd, 0, gunID);
             ftime(&gRegTimeUp[plugNum][REG_CHARGING_CAP]);
         }
         break;
@@ -1973,6 +2021,7 @@ static void systemStatusProcess(int fd, uint8_t totalGun, uint8_t plugNum, uint8
                 DiffTimeb(gRegTimeUp[plugNum][REG_PRESENT_CHARGING_INFO], AuthNowTime) < 0
            ) {
             writePresentChargingInfo(fd, plugNum, gunID);
+            writeGroundFaultDetection(fd, 0, gunID);
             ftime(&gRegTimeUp[plugNum][REG_PRESENT_CHARGING_INFO]);
         }
         break;
@@ -2004,6 +2053,7 @@ static void systemStatusProcess(int fd, uint8_t totalGun, uint8_t plugNum, uint8
                 DiffTimeb(gRegTimeUp[plugNum][REG_PRESENT_CHARGING_INFO], AuthNowTime) < 0
            ) {
             writePresentChargingInfo(fd, plugNum, gunID);
+            writeGroundFaultDetection(fd, 0, gunID);
             ftime(&gRegTimeUp[plugNum][REG_PRESENT_CHARGING_INFO]);
         }
         break;
@@ -2012,6 +2062,7 @@ static void systemStatusProcess(int fd, uint8_t totalGun, uint8_t plugNum, uint8
     case S_CCS_PRECHARGE_ST0:
     case S_CCS_PRECHARGE_ST1:
         writeChargingTarget(fd, plugNum, gunID);
+        writeGroundFaultDetection(fd, 1, gunID);
 
         ftime(&AuthNowTime);
         if (DiffTimeb(gRegTimeUp[plugNum][REG_CHARGING_CAP], AuthNowTime) > LOOP_RETRY_TIME ||
@@ -2045,6 +2096,15 @@ static void systemStatusProcess(int fd, uint8_t totalGun, uint8_t plugNum, uint8
 
     case S_CHARGING: //charging
     case S_TERMINATING:
+        if(pDcChargingInfo->Type == _Type_GB || pDcChargingInfo->Type == _Type_Chademo)
+        {
+            writeGroundFaultDetection(fd, 0, gunID);
+        }
+        else
+        {
+            writeGroundFaultDetection(fd, 1, gunID);
+        }
+
         ftime(&AuthNowTime);
         if (DiffTimeb(gRegTimeUp[plugNum][REG_CHARGING_CAP], AuthNowTime) > LOOP_RETRY_TIME ||
                 DiffTimeb(gRegTimeUp[plugNum][REG_CHARGING_CAP], AuthNowTime) < 0
@@ -2083,6 +2143,7 @@ static void systemStatusProcess(int fd, uint8_t totalGun, uint8_t plugNum, uint8
                 DiffTimeb(gRegTimeUp[plugNum][REG_CHARGING_CAP], AuthNowTime) < 0
            ) {
             readChargingCapability(fd, gunID);
+            writeGroundFaultDetection(fd, 0, gunID);
             ftime(&gRegTimeUp[plugNum][REG_CHARGING_CAP]);
         }
         break;

+ 5 - 0
EVSE/Projects/DD360ComBox/Apps/ModuleDoComm/DoComm.h

@@ -79,6 +79,7 @@
 #define REG_PRESENT_CHARGING_INFO               0X0F
 #define REG_QRCODE_URL_INFO                     0X10
 #define REG_WAIT_PLUG_IT_STATE                  0x11
+#define REG_Ground_Fault_Detection              0x12
 
 //------------------------------------------------------------------------------
 //--- dispenser result ---
@@ -207,6 +208,10 @@ typedef struct StPresentChargingInfo {
     uint8_t EvBatterySoc;               // 0~100%
 } PreChargingInfo;
 
+typedef struct StGroundFaultDetection { //Ground Fault Detection
+    uint8_t Status;
+} GroundFaultDetection;
+
 typedef struct StSoftwareUpdInfo {
     uint8_t UpdateState;         //1:update , 2: not update
     uint8_t ImgName[248];

+ 11 - 9
EVSE/Projects/DD360ComBox/Apps/ModuleEvComm/Module_EvTxComm.c

@@ -505,7 +505,7 @@ static void SetPresentChargingOutputPower(void)
     PcPsuOutput *pPcPsuOutput2 = NULL;
     struct ChargingInfoData *chargingData_1 = NULL;
     struct ChargingInfoData *chargingData_2 = NULL;
-    bool isPsuOutput1 = false, isPsuOutput2 = false;
+    bool isPsuVol1 = false, isPsuVol2 = false, isPsuCur1 = false, isPsuCur2 = false;
 
     if (pSysConfig->TotalConnectorCount == 1) {
         pPcPsuOutput1 = (PcPsuOutput *)&ShmDcCommonData->PcPsuOutput[0];
@@ -522,15 +522,17 @@ static void SetPresentChargingOutputPower(void)
     psuOutputReady[0] = chargingData_1->SystemStatus != S_CHARGING ? false : psuOutputReady[0];
     psuOutputReady[1] = chargingData_2->SystemStatus != S_CHARGING ? false : psuOutputReady[1];
 
-    isPsuOutput1 = (pPcPsuOutput1->Voltage != 0 && psuOutputReady[0] == true);
-    isPsuOutput2 = (pPcPsuOutput2->Voltage != 0 && psuOutputReady[1] == true);
+    isPsuVol1 = chargingData_1->PantographFlag ? true : (pPcPsuOutput1->Voltage != 0 && psuOutputReady[0] == true);
+    isPsuVol2 = chargingData_2->PantographFlag ? true : (pPcPsuOutput2->Voltage != 0 && psuOutputReady[1] == true);
+    isPsuCur1 = chargingData_1->PantographFlag ? true : false;
+    isPsuCur2 = chargingData_2->PantographFlag ? true : false;
 
     //vol1 = chargingData_1->FireChargingVoltage;
-    vol1 = isPsuOutput1 == false ? chargingData_1->FireChargingVoltage : (((float)pPcPsuOutput1->Voltage));
-    cur1 = (chargingData_1->PresentChargingCurrent * 10);
+    vol1 = isPsuVol1 == false ? chargingData_1->FireChargingVoltage : (((float)pPcPsuOutput1->Voltage));
+    cur1 = isPsuCur1 == false ? (chargingData_1->PresentChargingCurrent * 10) : pPcPsuOutput1->Current;
     //vol2 = chargingData_2->FireChargingVoltage;
-    vol2 = isPsuOutput2 == false ? chargingData_2->FireChargingVoltage : (((float)pPcPsuOutput2->Voltage));
-    cur2 = (chargingData_2->PresentChargingCurrent * 10);
+    vol2 = isPsuVol2 == false ? chargingData_2->FireChargingVoltage : (((float)pPcPsuOutput2->Voltage));
+    cur2 = isPsuCur2 == false ? (chargingData_2->PresentChargingCurrent * 10) : pPcPsuOutput2->Current;
 
     //DS60-120 add
     if ((LogInfo[0][EV_LOG_NOW_OUTPUT_VOL] >= vol1 + CHK_VOL_RANGE) ||
@@ -543,10 +545,10 @@ static void SetPresentChargingOutputPower(void)
             (LogInfo[1][EV_LOG_NOW_OUTPUT_CUR] <= cur2 - CHK_CUR_RANGE)
        ) {
         log_info("G1 -> Output Vol(%s) = %.1f, Output Cur = %.1f -- G2 -> Output Vol(%s) = %.1f, Output Cur = %.1f\r\n",
-                 isPsuOutput1 == true ? "P" : "R",
+                 isPsuVol1 == true ? "P" : "R",
                  vol1 / 10,
                  cur1 / 10,
-                 isPsuOutput2 == true ? "P" : "R",
+                 isPsuVol2 == true ? "P" : "R",
                  vol2 / 10,
                  cur2 / 10);
 

+ 4 - 1
EVSE/Projects/DD360ComBox/Apps/ModuleInternalComm/Module_InternalComm.c

@@ -100,7 +100,10 @@ int main(int argc, char *argv[])
     //FanBoardTask(fd);
 
     while (isContinue) {
-        AcPlugTask(fd);
+        if(AC_QUANTITY > 0)
+        {
+            AcPlugTask(fd);
+        }
         usleep(100000);
     }
 

+ 41 - 4
EVSE/Projects/DD360ComBox/Apps/ModuleInternalComm/RelayBoard.c

@@ -780,6 +780,13 @@ void CableCheckDetected(uint8_t index)
                     SetGfdConfig(targetID, GFD_CHARGING);
                 }
             }
+        }
+        else if(pDcChargingInfo->SystemStatus == S_TERMINATING || pDcChargingInfo->SystemStatus == S_ALARM)
+        {
+            if (pDcChargingInfo->Type == _Type_CCS_2)
+            {
+                SetGfdConfig(targetID, GFD_CHARGING);
+            }
         } else {
             SetGfdConfig(targetID, GFD_IDLE);
         }
@@ -1648,6 +1655,7 @@ static void LEDBoardProcess(void)
 
 void RelayBoardTask(int uartFD)
 {
+    bool isRelayBypass = false;
     pid_t pid = fork();
 
     if (pid == 0) {
@@ -1671,8 +1679,20 @@ void RelayBoardTask(int uartFD)
 
         Uart5Fd = uartFD;
 
+        for(int i = 0; i < pSysConfig->TotalConnectorCount; i++)
+        {
+            pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(i);
+            if(pDcChargingInfo->PantographFlag == YES)
+            {
+                isRelayBypass = true;
+            }
+        }
+
         //relay init
-        outputRelayInit(uartFD);
+        if(isRelayBypass == false)
+        {
+            outputRelayInit(uartFD);
+        }
 
         while (isContinue) {
 
@@ -1683,7 +1703,7 @@ void RelayBoardTask(int uartFD)
             }
 
             // 程序開始之前~ 必須先確定 FW 版本與硬體版本,確認後!!~ 該模組才算是真正的 Initial Comp.
-            if (ShmRelayModuleData->SelfTest_Comp == NO) {
+            if (ShmRelayModuleData->SelfTest_Comp == NO && isRelayBypass == false) {
                 GetFwAndHwVersion_Relay();
                 SetModelName_Relay(); //DS60-120 add
                 SetRtcData_Relay();
@@ -1698,7 +1718,7 @@ void RelayBoardTask(int uartFD)
             LEDBoardSelfTest();
 #endif //defined DD360ComBox
 
-            if (ShmRelayModuleData->SelfTest_Comp == YES)
+            if (ShmRelayModuleData->SelfTest_Comp == YES && isRelayBypass == false)
             {
                 // ==============優先權最高 10 ms ==============
                 // 輸出電壓
@@ -1711,7 +1731,6 @@ void RelayBoardTask(int uartFD)
 
                 // 讀取當前 AC relay 狀態
                 regRelay.relay_event.bits.AC_Contactor = pSysInfo->AcContactorStatus;
-
                 GetRelayOutputStatus();
 
                 // Cable check (Get)
@@ -1848,6 +1867,24 @@ void RelayBoardTask(int uartFD)
                     }
                 }
             }
+            else if(isRelayBypass == true)
+            {
+                for(i = 0; i < pSysConfig->TotalConnectorCount; i++)
+                {
+                    pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(i);
+
+                    if (pDcChargingInfo->SystemStatus == S_IDLE ||
+                            pDcChargingInfo->SystemStatus == S_RESERVATION ||
+                            pDcChargingInfo->SystemStatus == S_MAINTAIN)
+                    {
+                        _isOvpChkTimeFlag[i] = NO;
+                    }
+                    if (pDcChargingInfo->SystemStatus == S_CHARGING)
+                    {
+                        CheckOutputPowerOverCarReq(i);
+                    }
+                }
+            }
 
 #if !defined NO_FAN_BOARD && !defined DD360ComBox
             fanBoardPorcess();

+ 4 - 0
EVSE/Projects/DD360ComBox/Apps/ShareMemory/shmMem.c

@@ -923,6 +923,10 @@ static bool addGunInfoByConnector(uint8_t typeValue, uint8_t slots)
             pCcsData->CommProtocol = _CCS_COMM_V2GMessage_DIN70121;
             gGunIndexInfo.CcsIndex++;
             gGunIndexInfo.DcGunIndex++;
+            if(typeValue == 'P')
+            {
+                pDcChargingInfo->PantographFlag = YES;
+            }
         } else {
             result = false;
         }

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


BIN
EVSE/Projects/DD360ComBox/output/FactoryConfig


BIN
EVSE/Projects/DD360ComBox/output/Module_DoComm


BIN
EVSE/Projects/DD360ComBox/output/Module_EvComm


BIN
EVSE/Projects/DD360ComBox/output/Module_EventLogging


BIN
EVSE/Projects/DD360ComBox/output/Module_InternalComm


BIN
EVSE/Projects/DD360ComBox/output/Module_LcmControl


BIN
EVSE/Projects/DD360ComBox/output/Module_PrimaryComm


BIN
EVSE/Projects/DD360ComBox/output/ReadCmdline


BIN
EVSE/Projects/DD360ComBox/output/main