浏览代码

2022-04-27 / Simon Xue

Action:
1. [Add] Chiller Tube OTP status code.
2. [Add] DoComm protocol Register 0x20~0x24
3. [Modify] LCM show System ID.
4. [Modify] System date&time timing.

Files
As the following commit history files

Image Version: 2.06.XX.XXXX.XX
Simon Xue 2 年之前
父节点
当前提交
0b8b83168a
共有 29 个文件被更改,包括 779 次插入237 次删除
  1. 108 41
      EVSE/Projects/DD360UCar/Apps/CSU/main.c
  2. 35 2
      EVSE/Projects/DD360UCar/Apps/Config.h
  3. 1 1
      EVSE/Projects/DD360UCar/Apps/Define/define.c
  4. 32 30
      EVSE/Projects/DD360UCar/Apps/Define/define.h
  5. 435 126
      EVSE/Projects/DD360UCar/Apps/ModuleDoComm/DoComm.c
  6. 16 3
      EVSE/Projects/DD360UCar/Apps/ModuleDoComm/DoComm.h
  7. 14 1
      EVSE/Projects/DD360UCar/Apps/ModuleEvComm/Ev_Comm.c
  8. 26 27
      EVSE/Projects/DD360UCar/Apps/ModuleEvComm/Module_EvRxComm.c
  9. 2 1
      EVSE/Projects/DD360UCar/Apps/ModuleEvComm/Module_EvTxComm.c
  10. 6 4
      EVSE/Projects/DD360UCar/Apps/ModuleLcmCtrl/Module_LcmControl.c
  11. 1 0
      EVSE/Projects/DD360UCar/Apps/ModuleLcmCtrl/Module_LcmControl.h
  12. 71 0
      EVSE/Projects/DD360UCar/Apps/ReadCmdline.c
  13. 2 1
      EVSE/Projects/DD360UCar/Apps/SelectGun/SelectGun.h
  14. 29 0
      EVSE/Projects/DD360UCar/Apps/ShareMemory/shmMem.c
  15. 1 0
      EVSE/Projects/DD360UCar/Apps/ShareMemory/shmMem.h
  16. 二进制
      EVSE/Projects/DD360UCar/Images/ramdisk.gz
  17. 二进制
      EVSE/Projects/DD360UCar/output/FactoryConfig
  18. 二进制
      EVSE/Projects/DD360UCar/output/Module_ChkSysTask
  19. 二进制
      EVSE/Projects/DD360UCar/output/Module_DoComm
  20. 二进制
      EVSE/Projects/DD360UCar/output/Module_EvComm
  21. 二进制
      EVSE/Projects/DD360UCar/output/Module_EventLogging
  22. 二进制
      EVSE/Projects/DD360UCar/output/Module_InternalComm
  23. 二进制
      EVSE/Projects/DD360UCar/output/Module_LcmControl
  24. 二进制
      EVSE/Projects/DD360UCar/output/Module_PrimaryComm
  25. 二进制
      EVSE/Projects/DD360UCar/output/Module_UpdateFW
  26. 二进制
      EVSE/Projects/DD360UCar/output/ReadCmdline
  27. 二进制
      EVSE/Projects/DD360UCar/output/main
  28. 二进制
      EVSE/Projects/DD360UCar/output/simulation
  29. 二进制
      EVSE/rootfs/root/Module_PowerSharing

+ 108 - 41
EVSE/Projects/DD360UCar/Apps/CSU/main.c

@@ -82,8 +82,8 @@ uint8_t bd0_2_status = 0;
 uint8_t bd1_1_status = 0;
 uint8_t bd1_2_status = 0;
 
-char *fwVersion = "V2.05.00.0000.00"; // Phihong version
-char* DebugVersion = "V2.05.01";      // Software debug version
+char *fwVersion = "V2.06.00.0000.00"; // Phihong version
+char* DebugVersion = "V2.06.00";      // Software debug version
 //sqlite3 *localDb;
 bool isDb_ready;
 
@@ -357,52 +357,106 @@ static void checkGunOTPState(uint8_t gunIndex)
 
     //水冷機溫度檢測
     if (((ShmDcCommonData->ChillerValve.MultiChillerGun & 0x80) >> 7) == YES) {
-        if (pDcChargingInfo->ChillerTemp != UNDEFINED_TEMP) {
-            if (pDcChargingInfo->ChillerTemp >= GUN_OTP_VALUE) {
-                if (((gunIndex == 0) &&
-                        ((strncmp((char *)&pSysConfig->ModelName[7], "V", 1) == 0) ||
-                         (strncmp((char *)&pSysConfig->ModelName[7], "F", 1) == 0)))
-                         ||
-                    ((gunIndex == 1) &&
-                        ((strncmp((char *)&pSysConfig->ModelName[9], "V", 1) == 0) ||
-                         (strncmp((char *)&pSysConfig->ModelName[9], "F", 1) == 0)))
-                   ) {
-                    RecordAlarmCode(gunIndex, "012323");
+        if ((ShmDcCommonData->ChillerValve.MultiChillerGun & 0x7F) == 1) {
+            // 單水冷機
+            // Chiller OTP
+            if (ShmDcCommonData->SystemTemp[0] == UNDEFINED_TEMP || ShmDcCommonData->SystemTemp[1] == UNDEFINED_TEMP) {
+                // 溫度為255時判斷Sensor fail
+                ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerOTP = NO;
+                ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTempSensorFail = YES;
+            } else {
+                //判斷OTP
+                if (ShmDcCommonData->SystemTemp[0] >= pSysInfo->OTPTemp || ShmDcCommonData->SystemTemp[1] >= pSysInfo->OTPTemp) {
                     ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerOTP = YES;
-                }
-                else
-                {
+                    RecordAlarmCode(gunIndex, "012323");
+                } else if (ShmDcCommonData->SystemTemp[0] != 0 && ShmDcCommonData->SystemTemp[0] < pSysInfo->OTPTempR &&
+                    ShmDcCommonData->SystemTemp[1] != 0 && ShmDcCommonData->SystemTemp[1] < pSysInfo->OTPTempR) {
                     ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerOTP = NO;
                 }
-            } else if (pDcChargingInfo->ChillerTemp != 0 &&
-                       pDcChargingInfo->ChillerTemp < GUN_OTP_RECOVERY) {
-                //ResetChargerAlarmCode(gunIndex, "012323");
-                ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerOTP = NO;
+                ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTempSensorFail = NO;
             }
-            ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTempSensorFail = NO;
-        } else {
-            // 沒接上 Sensor or 異常
-            //RecordAlarmCode(gunIndex, "011038");
-            //ResetChargerAlarmCode(gunIndex, "012323");
-            ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerOTP = NO;
-            if (((gunIndex == 0) &&
-                    ((strncmp((char *)&pSysConfig->ModelName[7], "V", 1) == 0) ||
-                     (strncmp((char *)&pSysConfig->ModelName[7], "F", 1) == 0)))
-                     ||
-                ((gunIndex == 1) &&
-                    ((strncmp((char *)&pSysConfig->ModelName[9], "V", 1) == 0) ||
-                     (strncmp((char *)&pSysConfig->ModelName[9], "F", 1) == 0)))
-               ) {
+            // Chiller Tube OTP
+            if (ShmDcCommonData->SystemTemp[2] == UNDEFINED_TEMP || ShmDcCommonData->SystemTemp[3] == UNDEFINED_TEMP) {
+                // 溫度為255時判斷Sensor fail
+                ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTubeOTP = NO;
                 ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTempSensorFail = YES;
-            }
-            else
-            {
+            } else {
+                //判斷OTP
+                if (ShmDcCommonData->SystemTemp[2] >= pSysInfo->OTPTemp || ShmDcCommonData->SystemTemp[3] >= pSysInfo->OTPTemp) {
+                    ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTubeOTP = YES;
+                    RecordAlarmCode(gunIndex, "012332");
+                } else if (ShmDcCommonData->SystemTemp[2] != 0 && ShmDcCommonData->SystemTemp[2] < pSysInfo->OTPTempR &&
+                    ShmDcCommonData->SystemTemp[3] != 0 && ShmDcCommonData->SystemTemp[3] < pSysInfo->OTPTempR) {
+                    ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTubeOTP = NO;
+                }
                 ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTempSensorFail = NO;
             }
+        } else {
+            // 雙水冷機
+            if (gunIndex == LEFT_GUN_NUM) {
+                if (ShmDcCommonData->SystemTemp[0] == UNDEFINED_TEMP) {
+                    // 溫度為255時判斷Sensor fail
+                    ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerOTP = NO;
+                    ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTempSensorFail = YES;
+                } else {
+                    //判斷OTP
+                    if (ShmDcCommonData->SystemTemp[0] >= pSysInfo->OTPTemp) {
+                        ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerOTP = YES;
+                        RecordAlarmCode(gunIndex, "012323");
+                    } else if (ShmDcCommonData->SystemTemp[0] != 0 && ShmDcCommonData->SystemTemp[0] < pSysInfo->OTPTempR) {
+                        ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerOTP = NO;
+                    }
+                    ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTempSensorFail = NO;
+                }
+                if (ShmDcCommonData->SystemTemp[1] == UNDEFINED_TEMP) {
+                    // 溫度為255時判斷Sensor fail
+                    ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTubeOTP = NO;
+                    ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTempSensorFail = YES;
+                } else {
+                    //判斷OTP
+                    if (ShmDcCommonData->SystemTemp[1] >= pSysInfo->OTPTemp) {
+                        ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTubeOTP = YES;
+                        RecordAlarmCode(gunIndex, "012332");
+                    } else if (ShmDcCommonData->SystemTemp[1] != 0 && ShmDcCommonData->SystemTemp[1] < pSysInfo->OTPTempR) {
+                        ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTubeOTP = NO;
+                    }
+                    ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTempSensorFail = NO;
+                }
+            } else {
+                if (ShmDcCommonData->SystemTemp[2] == UNDEFINED_TEMP) {
+                    // 溫度為255時判斷Sensor fail
+                    ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerOTP = NO;
+                    ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTempSensorFail = YES;
+                } else {
+                    //判斷OTP
+                    if (ShmDcCommonData->SystemTemp[2] >= pSysInfo->OTPTemp) {
+                        ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerOTP = YES;
+                        RecordAlarmCode(gunIndex, "012323");
+                    } else if ( ShmDcCommonData->SystemTemp[2] != 0 && ShmDcCommonData->SystemTemp[2] < pSysInfo->OTPTempR) {
+                        ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerOTP = NO;
+                    }
+                    ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTempSensorFail = NO;
+                }
+                if (ShmDcCommonData->SystemTemp[3] == UNDEFINED_TEMP) {
+                    // 溫度為255時判斷Sensor fail
+                    ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTubeOTP = NO;
+                    ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTempSensorFail = YES;
+                } else {
+                    //判斷OTP
+                    if (ShmDcCommonData->SystemTemp[3] >= pSysInfo->OTPTemp) {
+                        ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTubeOTP = YES;
+                        RecordAlarmCode(gunIndex, "012332");
+
+                        log_info("Right Gun Chiller Tube OTP");
+                    } else if (ShmDcCommonData->SystemTemp[2] != 0 && ShmDcCommonData->SystemTemp[3] < pSysInfo->OTPTempR) {
+                        ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTubeOTP = NO;
+                    }
+                    ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTempSensorFail = NO;
+                }
+            }
         }
 
-        if(pFaultCode->FaultEvents.bits.CcsLiquidChillerWaterLevelFault == YES)
-        {
+        if(pFaultCode->FaultEvents.bits.CcsLiquidChillerWaterLevelFault == YES) {
             RecordAlarmCode(gunIndex, "011037");
         }
     }
@@ -679,6 +733,12 @@ static void checkChillerAlarmState(void)
     } else {
         pFaultCode->FaultEvents.bits.ChillerTempSensorBroken = NO;
     }
+
+    if (DetectBitValue(gChillerTempErr.TempErrMsg, 2)) {
+        pAlarmCode->AlarmEvents.bits.ChillerTubeOTP = YES;
+    } else {
+        pAlarmCode->AlarmEvents.bits.ChillerTubeOTP = NO;
+    }
 }
 
 static void checkEvBoardAlarmState(uint8_t gunType)
@@ -1658,6 +1718,8 @@ void ResetChargerAlarmCode(uint8_t gunIndex, char *code)
         ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerOTP = NO;
     } else if (strcmp(code, "011038") == EQUAL) {
         ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTempSensorFail = NO;
+    } else if (strcmp(code, "012332") == EQUAL) {
+        ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTubeOTP = NO;
     }
 
     if (strncmp((char *)pDcChargingInfo->ConnectorAlarmCode, "012229", 6) == EQUAL ||
@@ -1673,7 +1735,8 @@ void ResetChargerAlarmCode(uint8_t gunIndex, char *code)
             strncmp((char *)pDcChargingInfo->ConnectorAlarmCode, "011019", 6) == EQUAL ||
             strncmp((char *)pDcChargingInfo->ConnectorAlarmCode, "011020", 6) == EQUAL ||
             strncmp((char *)pDcChargingInfo->ConnectorAlarmCode, "012323", 6) == EQUAL ||
-            strncmp((char *)pDcChargingInfo->ConnectorAlarmCode, "011038", 6) == EQUAL) {
+            strncmp((char *)pDcChargingInfo->ConnectorAlarmCode, "011038", 6) == EQUAL ||
+            strncmp((char *)pDcChargingInfo->ConnectorAlarmCode, "012332", 6) == EQUAL) {
         strncpy((char *)pDcChargingInfo->ConnectorAlarmCode, "", 6);
     }
 }
@@ -1681,17 +1744,18 @@ void ResetChargerAlarmCode(uint8_t gunIndex, char *code)
 void RecordAlarmCode(uint8_t gunIndex, char *code)
 {
     pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
-
     if((pDcChargingInfo->SystemStatus > S_IDLE && pDcChargingInfo->SystemStatus < S_TERMINATING) ||
         (pDcChargingInfo->SystemStatus >= S_CCS_PRECHARGE_ST0 && pDcChargingInfo->SystemStatus <= S_CCS_PRECHARGE_ST1))
     {
         if (strncmp((char *)pDcChargingInfo->ConnectorAlarmCode, "", 6) == EQUAL) {
             memcpy(pDcChargingInfo->ConnectorAlarmCode, code, 6);
+
         }
 
         if (pDcChargingInfo->StopChargeFlag == NO)
         {
             pDcChargingInfo->StopChargeFlag = YES;
+
         }
     }
 }
@@ -3978,6 +4042,9 @@ int main(void)
 
     CreateWatchdog();
     int is_idle = TRUE;
+    pSysInfo->OTPTemp = GUN_OTP_VALUE;
+    pSysInfo->OTPTempR = GUN_OTP_RECOVERY;
+
     for (;;) {
 
         CheckOcppStatus();

+ 35 - 2
EVSE/Projects/DD360UCar/Apps/Config.h

@@ -397,7 +397,8 @@ typedef union {
     struct {
         uint8_t ChillerOTP: 1;            //chiller Temperature OVP
         uint8_t ChillerTempSensorFail: 1; //Chiller temperature sensor failure
-        uint8_t Reserved: 6;
+        uint8_t ChillerTubeOTP : 1;
+        uint8_t Reserved: 5;
     } StatusBit;
 } ChillerTempErr;
 
@@ -413,6 +414,30 @@ typedef struct StPcPsuOutput { //from power cabinet PSU output
     uint16_t Current;
 } PcPsuOutput;
 
+typedef struct StPowerConsumptionInfo {
+    float Gun1_Consumption;
+    float Gun2_Consumption;
+    float Gun3_Consumption;
+    float Gun4_Consumption;
+} PowerConsumptionValue;
+
+typedef struct StPowConsumValue {
+    uint32_t Gun1_Consumption;
+    uint32_t Gun2_Consumption;
+    uint32_t Gun3_Consumption;
+    uint32_t Gun4_Consumption;
+} PowConsumValue;
+
+typedef struct StGunInfo {
+    int ConnectorID;
+    char ReceiptInfo[255];
+    int finalcost_flag;
+    time_t EVLoseTimer;
+    uint8_t EVLoseFlag;
+    char ReservationID[32];
+    uint8_t ReservationStatus;
+} GunInfo;
+
 typedef struct Psu_VersionInfo{
 	uint8_t n_PSU;
 	uint8_t DCVersion[32];
@@ -505,7 +530,7 @@ typedef struct StDcCommonInfo {
     unsigned int TradeCancel;
     int reupload_deduct_status;		// 0:Not ReUpload 1:ReUpload 2:ReUpload finish
     RecordTransactionInfo TransactionInfo[2];
-    int TzOffset;
+    int TZOffset;
     int DebugFlag;
     int chillerCtrl;
     time_t EVDisconnectTime[2];
@@ -515,6 +540,14 @@ typedef struct StDcCommonInfo {
     time_t LedDisconnectTime;
     time_t FanDisconnectTime;
     int DemoCount;
+    char QRCodeString[255];
+    GunInfo pGunInfo[2];
+    char DefaultPriceString[255];
+    char UserPriceString[255];
+    PowerConsumptionValue pConsumption;
+    uint8_t AuthroizeType; // 0: Central   1: eMAID    2: ISO14443 3: ISO15693 4: KeyCode  5: Local    6: MacAddress   7: NoAuthorization
+    uint8_t showNetPackage;
+    uint8_t showCanPackage;
 } DcCommonInfo;
 
 #endif /* CONFIG_H_ */

+ 1 - 1
EVSE/Projects/DD360UCar/Apps/Define/define.c

@@ -241,7 +241,7 @@ char AlarmStatusCode[160][6]=
 "012329",   // Psu Can Communication Fault
 "012330",   // Psu Dc to Dc OTP
 "012331",   // Psu Dc to Dc OVP
-"012332",   // reserved
+"012332",   // Chiller Tube OTP
 "012333",   // reserved
 "012334",   // reserved
 "012335",   // reserved

+ 32 - 30
EVSE/Projects/DD360UCar/Apps/Define/define.h

@@ -187,6 +187,7 @@ Storage							0x0A200000-0x7FFFFFFF		1886 MB
 #define ShmOcpp20ModuleKey		1012
 #define ShmRelay2BdKey			1013
 #define ShmYesCustomKey         1014
+#define ShmOcppPHModuleKey      1015
 
 #define FaultCodeLength         5
 #define AlarmCodeLength         20
@@ -327,6 +328,10 @@ enum CoreProfile {
      MaintainServer,
      StatusNotificationPeriodically,
      StatusNotificationInterval,
+     PreAuthAmount,
+     isEnableLocalPowerSharing,
+     PowerSharingServerIP,
+     EVCCID_PREFIX,
      ConfigurationVersion,
 	 _CoreProfile_CNT
 };
@@ -340,10 +345,11 @@ enum OCPP_START_ID_TYPE {
     IdTokenType_Central=0,
     IdTokenType_eMAID,
     IdTokenType_ISO14443,
+    IdTokenType_ISO15693,
     IdTokenType_KeyCode,
     IdTokenType_Local,
-    IdTokenType_NoAuthorization,
-    IdTokenType_ISO15693
+    IdTokenType_MacAddress,
+    IdTokenType_NoAuthorization
 };
 /**************************************************************************************/
 /****structure SysConfigData => shall store the data to NAND flash****************/
@@ -379,7 +385,8 @@ struct TeleConfigData
 {
 	unsigned char		TelcomModelName[64];		//default: Null
 	unsigned char		TelcomSoftwareVer[64];		//default: Null
-	unsigned char		TelcomApn[256];				//default: Null
+	unsigned char		TelcomApn[255];				//default: Null
+	unsigned char		TelcomNetworkType;			//0: Auto	1: CDMA	 2: WCDMA  3: LTE  4: TD-SCDMA  5: UMTS  6: CDMA  7: HDR  8: CDMA/HDR
 	int					TelcomRssi;					//dbm
 	unsigned char		TelcomChapPapId[256];		//default: Null
 	unsigned char		TelcomChapPapPwd[256];		//default: Null
@@ -460,7 +467,7 @@ struct TTIA
 
 struct LocalSharingInfo
 {
-    unsigned short      AvailableShargingCurrent;       // 0 ~ rating value amp,  Synchronize from local sharing server
+    unsigned short      AvailableShargingCurrent[4];    // 0 ~ rating value amp,  Synchronize from local sharing server
     unsigned char       isConnectedSharingServer:1;     // 0: Disconnected, 1: Connected
 };
 
@@ -571,7 +578,7 @@ struct SysConfigData
 	struct LED				LedInfo;					// LED configuration info
 	unsigned char			ShowInformation;
 	unsigned char           isReqFirstUpgrade;          //EVSE is request first upgrade from PH server
-	unsigned char           isEnableLocalPowerSharging; //0: Disable power sharing  1: Enable power sharing
+	unsigned char           isEnableLocalPowerSharing;  //0: Disable power sharing  1: Master   2: Slave
 	unsigned char           StopChargingByButton;       //0: Disable  1: Enable
     struct LCD_NOUSE        Legacy_LcdOveride;          // LCD override info (no use anymore)
     struct TTIA             TTIA_Info;                  // TTIA configuration struct
@@ -584,6 +591,7 @@ struct SysConfigData
     unsigned char           MaintainServerURL[512];             // ws: non-secure OCPP 1.6-J, wss: secure OCPP 1.6-J"
     unsigned char           MaintainServerSecurityProfile;      // Maintain server security profile 0~3
     unsigned char           MaintainServerSecurityPassword[41]; // Maintain server AuthorizationKey for security profile
+    unsigned char           PowerSharingServerIP[512];          // Local power sharing server ip address
 };
 
 struct ChargingInfoData
@@ -623,7 +631,7 @@ 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           StartIdType;                // 0: Central   1: eMAID    2: ISO14443 3: ISO15693 4: KeyCode  5: Local    6: MacAddress   7: NoAuthorization
 	unsigned char			StartDateTime[32];			// Charging cycle start date time
 	unsigned char			StopDateTime[32];			// Charging cycle stop date time
 	unsigned char			StartMethod;
@@ -699,7 +707,7 @@ typedef struct
     unsigned char       AuthType;                       // 0: _AuthType_None,   1: _AuthType_RFID, 2: _AuthType_RemoteStart
     unsigned char       AuthResult;                     // 0: _AuthResult_None, 1: _AuthResult_Valid,   2: _AuthResult_Invalid
     unsigned char       AuthRequest;                    // 0: no request, 1: authorize request
-    unsigned char       res;
+    unsigned char       AuthIdType;
 }AuthorizingInfoData;
 
 typedef union
@@ -718,16 +726,7 @@ typedef union
         unsigned int FirmwareUpdateRequest:1;           // firmware update request
         unsigned int FirmwareUpdateConfirm:1;           // firmware update start
         unsigned int FirmwareUpdateCompleted:1;         // firmware update completed
-        unsigned int BackendStatusRequest:1;            // 0: no request,   1: backend connection status has changed            ( cabinet -> dispenser)
-        unsigned int EthernetStatusRequest:1;           // 0: no request,   1: ethernet connection status has changed           ( cabinet -> dispenser)
-        unsigned int WiFiStatusRequest:1;               // 0: no request,   1: wifi connection status has changed               ( cabinet -> dispenser)
-        unsigned int TelcomModemStatusRequest:1;        // 0: no request,   1: 4g connection status has changed                 ( cabinet -> dispenser)
-        unsigned int BillingStatusRequest:1;            // 0: no request,   1: billing status has changed                       ( cabinet -> dispenser)
-        unsigned int StopButtonStatusRequest:1;         // 0: no request,   1: stop charging button status has changed          ( cabinet -> dispenser)
-        unsigned int AuthModeConfigRequest:1;           // 0: no request,   1: AuthMode Config has changed                      ( cabinet -> dispenser)
-        unsigned int EVCCIDConfigRequest:1;             // 0: no request,   1: EVCCID Config has changed                        ( cabinet -> dispenser)
-        unsigned int LEDIntensityRequest:1;             // 0: no request,   1: LED Intensity has changed                        ( cabinet -> dispenser)
-        unsigned int res:12;
+        unsigned int res:21;
     }bits;
 }DispenserSettingFlag;
 
@@ -744,7 +743,7 @@ struct DispenserModule
     unsigned char   RfidCardNumEndian;          //0: little endian,  1: big endian
     unsigned char   isAPP;                      //for AuthorisationMode=0; 0:false, 1:true
     unsigned char   isQRCode;                   //for AuthorisationMode=0; 0:false, 1:true
-    unsigned char   isRFID;                     //for AuthorisationMode=0; 0:false, 1:true
+    unsigned char   isRFID;                     //for AuthorisationMode=0; 0:false, 1:true; for Noodoe Credit Card +2^1:true
     unsigned char   QRCodeMadeMode;             //for isQRCode=1 ; 0: default	1:customized
     unsigned char   QRCodeContent[128];         //for QRCodeMadeMode=1
 
@@ -837,7 +836,7 @@ typedef union
         unsigned int  Disconnection:1;
         unsigned int  GfdDetection:1;                   // 0: stop,         1: start
         unsigned int  GetStartChargingSoc:1;            // 0: no effect,    1: get start soc
-        unsigned int  res:14;
+        unsigned int  res:13;
     }bits;
 }ConnectorParameter;
 
@@ -877,7 +876,9 @@ struct ConnectorInfoData
     float                   UserPrice;                      // connector user's user price, unit: 1 (dollar / kWh)
     float                   TotalCost;                      // connector user's total cost, unit: 1 dollar
     float                   AccountBalance;                 // connector user's account balance, unit: 1 dollar
-    float                   CostDiscount;                   // connector user's account balance, unit: 1 dollar
+    float                   CostDiscount;                   // connector user's Discount or couponPoint, unit: 1 point
+    float                   EnergyCost;                     // connector user's energy cost, unit: 1 dollar
+    float                   ParkingFee;                     // connector user's parking fee, unit: 1 dollar
 };
 
 typedef union
@@ -1321,7 +1322,7 @@ char AlarmStatusCode[160][6]=
     "012329",   // Psu Can Communication Fault
     "012330",   // Psu Dc to Dc OTP
     "012331",   // Psu Dc to Dc OVP
-    "012332",   // reserved
+    "012332",   // Chiller Tube OTP
     "012333",   // reserved
     "012334",   // reserved
     "012335",   // reserved
@@ -1508,7 +1509,8 @@ struct AlarmCodeData
             unsigned char PsuCanCommFault:1;                        //bit 1
             unsigned char PsuDcDcOtp:1;                             //bit 2
             unsigned char PsuDcDcOvp:1;                             //bit 3
-            unsigned char :4;                                       //reserved bit 4 ~ bit 7
+			unsigned char ChillerTubeOTP : 1;                       //bit 4
+            unsigned char :3;                                       //reserved bit 5 ~ bit 7
     //AlarmVal[17]
             unsigned char :8;                                       //reserved bit 0 ~ bit 7
             //AlarmVal[18]
@@ -2300,7 +2302,7 @@ struct PsuData
 	unsigned char           GroupCount;
 	unsigned char           Work_Step;
 	struct PsuModuleVer     PsuVersion[MAX_PSU_QUANTITY];
-	unsigned char 			PsuStopChargeFlag;
+	unsigned char           PsuStopChargeFlag;
 };
 
 /************************************************************************************/
@@ -4418,7 +4420,7 @@ struct OCPP16ConfigurationTable
 struct StrcutSetUserPrice
 {
     unsigned char   idToken[21];
-    unsigned char   price[256];
+    unsigned char   price[1024];
 };
 
 struct ChargingPrice
@@ -4462,13 +4464,13 @@ struct StrcutRunningCost
     struct IdlePrice        idlePrice;              // (optional) Price components while not charging. Optional if no idle fee is charged.
     struct NextPeriod       nextPeriod;             // (optional) Pricing for next period
     struct Triggers         triggerMeterValue;      // (optional) Triggers to request a new meter value. Optional if no idle fee charged.
-    unsigned char           description[256];       // Compatible California pricing V1.0
+    unsigned char           description[1024];      // Compatible California pricing V1.0
 };
 
 struct StrcutFinalCost
 {
     int             txId;
-    unsigned char   description[256];
+    unsigned char   description[1024];
 };
 
 struct StructCost
@@ -4617,8 +4619,8 @@ struct StructCreditDeductResult
 
 struct StructReaderStatus
 {
-	int readerStatus;
-	unsigned char creditNo[64];
+    int readerStatus;
+    unsigned char creditNo[64];
     unsigned char ReportReaderStatusReq:1;
 };
 
@@ -4630,7 +4632,7 @@ struct StructTcciCustomData
     struct StructReaderStatus ReaderStatus[CONNECTOR_QUANTITY];
     unsigned char TriggerReaderReq[3];
     unsigned char SerialNo[CONNECTOR_QUANTITY][37];
-	unsigned char VEMData[CONNECTOR_QUANTITY][65];
+    unsigned char VEMData[CONNECTOR_QUANTITY][65];
 
     unsigned char ReportCreditDeductReq:1;
     unsigned char ChargerInfoReq:1;
@@ -5144,7 +5146,7 @@ struct ChargingScheduleType
 
 struct ChargingProfileType
 {
-	unsigned short int id;											// Required. Id of ChargingProfile.
+	int id;											                // Required. Id of ChargingProfile.
 	unsigned short int stackLevel;									// Required. Value determining level in hierarchy stack of profiles. Higher values have precedence over lower values. Lowest level is 0.
 	unsigned char chargingProfilePurpose[36];						// Required. Defines the purpose of the schedule transferred by this profile
 	unsigned char chargingProfileKind[16];							// Required. Indicates the kind of schedule.

+ 435 - 126
EVSE/Projects/DD360UCar/Apps/ModuleDoComm/DoComm.c

@@ -59,7 +59,8 @@ static uint8_t DeductResultReq[2] = {0};
 static int LineStatusCode[2] = {0};
 static unsigned int LedIntensity = 0;
 static int TimeZoneOffset = 0;
-
+int RxLen;
+char Rxdata[1024];
 //------------------------------------------------------------------------------
 static void removeFaultCodeToBuf(uint8_t *Code);
 static void addFaultCodeToBuf(uint8_t *Code);
@@ -157,6 +158,23 @@ static int string2ByteArray(char *input, uint8_t *output)
     return loop + 1;
 }
 
+int string2Date(char* input, uint8_t* output)
+{
+    int loop = 0;
+    int i = 0;
+
+    while (input[loop] != '\0') {
+        loop++;
+    }
+    loop++;
+
+    while (input[loop] != '\0') {
+        output[i++] = input[loop++];
+    }
+    output[loop] = '\0';
+
+    return loop + 1;
+}
 static void unixSocketSigPipeHandle(int sig)
 {
     log_error("socket packet error %x", sig);
@@ -181,11 +199,28 @@ static void setTcpStatus(uint8_t setValue)
 //------------------------------------------------------------------------------
 //--- TCP socket function ---
 //------------------------------------------------------------------------------
-static int sendTcpSocket(int fd, uint8_t *data, uint16_t dataLen)
+static int sendTcpSocket(int fd, uint8_t* data, uint16_t dataLen)
 {
     int size = -1;
+    int i;
+    char _info[1024];
+    int len = 0;
+
+    // ReadCmdline show network package
+    if (ShmDcCommonData->showNetPackage) {
+        len = 0;
+        len += sprintf(&_info[len], "Net Tx[%d]:", dataLen);
+        for (i = 0; i < dataLen; i++) {
+            if (i == 0)
+                len += sprintf(&_info[len], "[%X]\t", data[i]);
+            else
+                len += sprintf(&_info[len], "%X ", data[i]);
+        }
+        len += sprintf(&_info[len], "\n");
+        printf("%s", _info);
+    }
 
-    size = send(fd, data, dataLen , 0);
+    size = send(fd, data, dataLen, 0);
     if ((size < 0) || (errno == EAGAIN)) {
         if (size < 0) {
             log_error("Send Socket Size = %d, EAGAIN error %d:%s", size, errno, strerror(errno));
@@ -195,15 +230,34 @@ static int sendTcpSocket(int fd, uint8_t *data, uint16_t dataLen)
     return size;
 }
 
-static int recvTcpSocket(int fd, uint8_t *data, uint16_t dataLen)
+static int recvTcpSocket(int fd, uint8_t* data, uint16_t dataLen, uint8_t ishead)
 {
     int size = -1;
-    uint8_t *pdata = (uint8_t *)data;
+    int i;
+    uint8_t* pdata = (uint8_t*)data;
 
     size = recv(fd, pdata, dataLen, MSG_WAITALL);
     if ((errno == EAGAIN) || (size < 0)) {
         log_error("Receive Socket Size = %d, EAGAIN error %d:%s", size, errno, strerror(errno));
     }
+    // ReadCmdline show network package
+    if (ShmDcCommonData->showNetPackage) {
+        if (ishead) {
+            RxLen = 0;
+            RxLen += sprintf(&Rxdata[RxLen], "Net Rx[%d]:", size);
+        }
+        for (i = 0; i < dataLen; i++) {
+            if (ishead && i == 0)
+                RxLen += sprintf(&Rxdata[RxLen], "[%X]\t", data[i]);
+            else
+                RxLen += sprintf(&Rxdata[RxLen], "%X ", data[i]);
+        }
+        if (!ishead) {
+            RxLen += sprintf(&Rxdata[RxLen], "\n");
+            printf("%s", Rxdata);
+            strcpy(Rxdata, "");
+        }
+    }
 
     return size;
 }
@@ -427,7 +481,15 @@ static void clearMiscCommand(void)
 {
     gDoCommGblData.MiscCmd = 0;
 }
-
+int timecmp(uint8_t* time1, uint8_t* time2)
+{
+    for (int i = 0; i < strlen(time1); i++) {
+        if (time1[i] != time2[i]) {
+            return FALSE;
+        }
+    }
+    return TRUE;
+}
 static int qrCodeUrlInfoHandle(uint8_t *data)
 {
     //int len = 0;
@@ -436,7 +498,8 @@ static int qrCodeUrlInfoHandle(uint8_t *data)
     uint16_t timeLen = 0;
     struct timeb SeqEndTime;
     struct tm *tm;
-
+    char _setTime[50];
+    uint8_t cmdBuf[128];
     if ((char *)&data[0] == '\0') {
         log_error("QR code date error");
         return FAIL;
@@ -454,19 +517,21 @@ static int qrCodeUrlInfoHandle(uint8_t *data)
                       tm->tm_min);
 
     //copy QR code string
-    if (strncmp((char *)localTime, (char *)&data[0], timeLen - 2) != 0) {
-        memset(pSysConfig->SystemId, '\0', sizeof(pSysConfig->SystemId));
-        //printf("data =  %s", data);
-        //len =
+    memset(ShmDcCommonData->QRCodeString, '\0', sizeof(ShmDcCommonData->QRCodeString));
+    //printf("data =  %s", data);
+    //len =
 
-        string2ByteArray((char *)data, (uint8_t *)pSysConfig->SystemId);
-        //printf("SystemId =  %s", pSysConfig->SystemId);
-        //log_info("SystemId:%s",pSysConfig->SystemId);
+    string2ByteArray((char *)data, (uint8_t *)ShmDcCommonData->QRCodeString);
+    string2Date((char*)data, (uint8_t*)_setTime);
+    //printf("SystemId =  %s", pSysConfig->SystemId);
+    if (!timecmp(localTime, _setTime)) {
+        log_info("Set Timer:%s", _setTime);
+        sprintf((char*)cmdBuf, "date -u -s \"%s\" >> /dev/null &", _setTime);
+        system((char*)cmdBuf);
+        system("hwclock -w -u");
+        system("hwclock -s");
     }
-    sprintf(ShmDcCommonData->PresentTime, "%04d/%02d/%02d",
-                      tm->tm_year + 1900,
-                      tm->tm_mon + 1,
-                      tm->tm_mday);
+
 
     //if ((char *)&data[len] == '\0') {
     //    log_error("power cabinet system date error");
@@ -839,7 +904,34 @@ static int miscCommandHandle(uint8_t dataLen, uint8_t plugNum, uint8_t *data)
         case MISC_CMD_TIME_OFFSET:
             TimeZoneOffset = value;
             log_info("Time Zone Offset: %d", TimeZoneOffset);
-            ShmDcCommonData->TzOffset = TimeZoneOffset;
+            ShmDcCommonData->TZOffset = TimeZoneOffset;
+            /*
+            if (TimeZoneOffset == 480) {
+                system("export TZ=CST-8");
+                log_info("Set Time Zone CST 8");
+            }
+            */
+            break;
+        case MISC_CMD_DEFAULT_PRICE_REQ:
+            if (value != YES)
+            {
+                break;
+            }
+            gMoreInfoReq[plugNum].bits.DefaultPriceReq = YES;
+            break;
+        case MISC_CMD_USER_PRICE_REQ:
+            if (value != YES)
+            {
+                break;
+            }
+            gMoreInfoReq[plugNum].bits.UserPriceReq = YES;
+            break;
+        case MISC_CMD_RECEIPT_REQ:
+            if (value != YES)
+            {
+                break;
+            }
+            gMoreInfoReq[plugNum].bits.ReceiptReq = YES;
             break;
         default:
             clearMiscCommand();
@@ -917,25 +1009,38 @@ static int chargingcapabilityHandle(uint8_t *data, uint8_t plugNum)
     ShmSelectGunInfo->PricesInfo[plugNum].Balance    = transPricesUnit(ntohl(pAccountInfo->Balance));
     ShmSelectGunInfo->PricesInfo[plugNum].Discount   = transPricesUnit(ntohl(pAccountInfo->Discount));
     ShmSelectGunInfo->PricesInfo[plugNum].TransactionId = ntohl(pAccountInfo->Transaction);
+    ShmSelectGunInfo->PricesInfo[plugNum].EnergyCost = transPricesUnit(ntohl(pAccountInfo->EnergyCost));
+    ShmSelectGunInfo->PricesInfo[plugNum].ParkingFee = transPricesUnit(ntohl(pAccountInfo->ParkingFee));
 
     if ((pricesInfo[plugNum].UserPrices != ShmSelectGunInfo->PricesInfo[plugNum].UserPrices) ||
             (pricesInfo[plugNum].Balance != ShmSelectGunInfo->PricesInfo[plugNum].Balance) ||
 			(pricesInfo[plugNum].Discount != ShmSelectGunInfo->PricesInfo[plugNum].Discount) ||
-			(pricesInfo[plugNum].TransactionId != ShmSelectGunInfo->PricesInfo[plugNum].TransactionId)) {
+			(pricesInfo[plugNum].TransactionId != ShmSelectGunInfo->PricesInfo[plugNum].TransactionId) ||
+            (pricesInfo[plugNum].EnergyCost != ShmSelectGunInfo->PricesInfo[plugNum].EnergyCost) ||
+            (pricesInfo[plugNum].ParkingFee != ShmSelectGunInfo->PricesInfo[plugNum].ParkingFee)) {
         pricesInfo[plugNum].UserPrices = ShmSelectGunInfo->PricesInfo[plugNum].UserPrices;
         pricesInfo[plugNum].Balance = ShmSelectGunInfo->PricesInfo[plugNum].Balance;
         pricesInfo[plugNum].Discount = ShmSelectGunInfo->PricesInfo[plugNum].Discount;
         pricesInfo[plugNum].TransactionId = ShmSelectGunInfo->PricesInfo[plugNum].TransactionId;
+        pricesInfo[plugNum].ParkingFee = ShmSelectGunInfo->PricesInfo[plugNum].ParkingFee;
+        pricesInfo[plugNum].EnergyCost = ShmSelectGunInfo->PricesInfo[plugNum].EnergyCost;
+        if (ShmSelectGunInfo->PricesInfo[plugNum].TransactionId != 0) {
 
-        log_info("id = %d, transaction id = %d, user prices = %.2f, Discount = %.2f, Total cost = %.2f, Account balances = %.2f, currency = %s",
-                 plugNum,
-				 ShmSelectGunInfo->PricesInfo[plugNum].TransactionId,
-                 ShmSelectGunInfo->PricesInfo[plugNum].UserPrices,
-				 ShmSelectGunInfo->PricesInfo[plugNum].Discount,
-                 pDcChargingInfo->ChargingFee,
-                 ShmSelectGunInfo->PricesInfo[plugNum].Balance,
-                 (uint8_t *)GetCurrency(pSysConfig->BillingData.Currency)
-                );
+            //ShmDcCommonData->TransactionInfo[plugNum].TransactionId = ShmSelectGunInfo->PricesInfo[plugNum].TransactionId;
+            //UpdateDeductInfoStatus(plugNum, &ShmDcCommonData->TransactionInfo[plugNum]);
+
+            log_info("id = %d, transaction id = %d, user prices = %.2f, Discount = %.2f, Account balances = %.2f, currency = %s",
+                plugNum,
+                ShmSelectGunInfo->PricesInfo[plugNum].TransactionId,
+                ShmSelectGunInfo->PricesInfo[plugNum].UserPrices,
+                ShmSelectGunInfo->PricesInfo[plugNum].Discount,
+                ShmSelectGunInfo->PricesInfo[plugNum].Balance,
+                (uint8_t*)GetCurrency(pSysConfig->BillingData.Currency)
+            );
+            log_info("Total Cost:%.2f", pDcChargingInfo->ChargingFee);
+            log_info("Parking Fee:%.2f", ShmSelectGunInfo->PricesInfo[plugNum].ParkingFee);
+            log_info("Energy Cost:%.2f", ShmSelectGunInfo->PricesInfo[plugNum].EnergyCost);
+        }
     }
 
     return PASS;
@@ -1300,15 +1405,24 @@ static int responsePackeHandle(int fd, uint8_t *pResult, uint8_t plugNum, uint8_
         {
             strcpy(&ReservationIdTag[plugNum][0], (char *)&pCsuResult->Data.Data[1]);
         }
-        if(reservationState != ReservationState[plugNum])
+        if(reservationState != ReservationState[plugNum] || 
+            (strcmp((char*)ShmDcCommonData->pGunInfo[plugNum].ReservationID, (char*)ReservationIdTag[plugNum]) != EQUAL) )
         {
             log_info("id = %d reservation is %s", pCsuResult->Head.ID, reservationState ? "trigger" : "expired");
             if(reservationState)
             {
                 log_info("id = %d reservation idTag: %s", pCsuResult->Head.ID, (char *)&ReservationIdTag[plugNum][0]);
+                pDcChargingInfo = (struct ChargingInfoData*)GetDcChargingInfoData(plugNum);
+                strcpy(&ShmDcCommonData->pGunInfo[plugNum].ReservationID[0], (char*)&pCsuResult->Data.Data[1]);
+                
+                pDcChargingInfo->SystemStatus = S_RESERVATION;
+            } else {
+                if (pDcChargingInfo->SystemStatus == S_RESERVATION && pSysInfo->WaitForPlugit == NO)
+                    pDcChargingInfo->SystemStatus = S_IDLE;
             }
         }
         ReservationState[plugNum] = reservationState;
+        ShmDcCommonData->pGunInfo[plugNum].ReservationStatus = reservationState;
         break;
 
     case REG_REMOTE_START_NO_ID:
@@ -1361,7 +1475,69 @@ static int responsePackeHandle(int fd, uint8_t *pResult, uint8_t plugNum, uint8_
             return COMMAND_RESULT_NG;
         }
         break;
-
+    case REG_READ_CABINET_SYSTEMID:
+        if (pCsuResult->Data.Result == COMMAND_RESULT_NG) {
+            return COMMAND_RESULT_NG;
+        }
+        if (strcmp((char*)pSysConfig->SystemId, (char*)pCsuResult->Data.Data) != 0) {
+            strcpy((char*)pSysConfig->SystemId, (char*)pCsuResult->Data.Data);
+            log_info("System ID:%s", pSysConfig->SystemId);
+        }
+        break;
+    case REG_READ_DEFAULT_PRICE:
+        if (pCsuResult->Data.Result == COMMAND_RESULT_NG) {
+            return COMMAND_RESULT_NG;
+        }
+        gMoreInfoReq[plugNum].bits.DefaultPriceReq = NO;
+        if (strcmp((char*)ShmDcCommonData->DefaultPriceString, (char*)pCsuResult->Data.Data) != EQUAL) {
+            strcpy((char*)ShmDcCommonData->DefaultPriceString, (char*)pCsuResult->Data.Data);
+            log_info("Default Price:%s", ShmDcCommonData->DefaultPriceString);
+        }
+        break;
+    case REG_READ_USER_PRICE:
+        if (pCsuResult->Data.Result == COMMAND_RESULT_NG) {
+            return COMMAND_RESULT_NG;
+        }
+        gMoreInfoReq[plugNum].bits.UserPriceReq = NO;
+        if (strcmp((char*)ShmDcCommonData->UserPriceString, (char*)pCsuResult->Data.Data) != EQUAL) {
+            strcpy((char*)ShmDcCommonData->UserPriceString, (char*)pCsuResult->Data.Data);
+            log_info("User Price:%s", ShmDcCommonData->UserPriceString);
+        }
+        break;
+    case REG_RECEIPT_INFO:
+        if (pCsuResult->Data.Result == COMMAND_RESULT_NG) {
+            return COMMAND_RESULT_NG;
+        }
+        gMoreInfoReq[plugNum].bits.ReceiptReq = NO;
+        if (strcmp((char*)ShmDcCommonData->pGunInfo[plugNum].ReceiptInfo, (char*)pCsuResult->Data.Data) != EQUAL) {
+            strcpy((char*)ShmDcCommonData->pGunInfo[plugNum].ReceiptInfo, (char*)pCsuResult->Data.Data);
+            log_info("Gun%d Receipt:%s", plugNum, ShmDcCommonData->pGunInfo[plugNum].ReceiptInfo);
+        }
+        break;
+    case REG_POWER_CONSUMPTION_INFO:
+        if (pCsuResult->Data.Result == COMMAND_RESULT_NG) {
+            return COMMAND_RESULT_NG;
+        }
+        
+        PowConsumValue* pValue =NULL;
+        pValue = (PowConsumValue*)&pCsuResult->Data.Data[0];
+
+        pValue->Gun1_Consumption = ntohl(pValue->Gun1_Consumption);
+        pValue->Gun2_Consumption = ntohl(pValue->Gun2_Consumption);
+        pValue->Gun3_Consumption = ntohl(pValue->Gun3_Consumption);
+        pValue->Gun4_Consumption = ntohl(pValue->Gun4_Consumption);
+        memcpy((char*)&ShmDcCommonData->pConsumption.Gun1_Consumption, (char*)&pValue->Gun1_Consumption, sizeof(uint32_t));
+        memcpy((char*)&ShmDcCommonData->pConsumption.Gun2_Consumption, (char*)&pValue->Gun2_Consumption, sizeof(uint32_t));
+        memcpy((char*)&ShmDcCommonData->pConsumption.Gun3_Consumption, (char*)&pValue->Gun3_Consumption, sizeof(uint32_t));
+        memcpy((char*)&ShmDcCommonData->pConsumption.Gun4_Consumption, (char*)&pValue->Gun4_Consumption, sizeof(uint32_t));
+
+        log_info("Gun1_Consumption:%f", ShmDcCommonData->pConsumption.Gun1_Consumption);
+        log_info("Gun2_Consumption:%f", ShmDcCommonData->pConsumption.Gun2_Consumption);
+        log_info("Gun3_Consumption:%f", ShmDcCommonData->pConsumption.Gun3_Consumption);
+        log_info("Gun4_Consumption:%f", ShmDcCommonData->pConsumption.Gun4_Consumption);
+        
+        
+        break;
     default:
         break;
     }
@@ -1400,11 +1576,6 @@ static int composeSocketData(int fd,
 
     // Not Let ask cabinet version trasmit into FAIL Network
 
-    if (reg == REG_CABINET_DCM_VERSION || reg == REG_CABINET_OTHER_VERSION ||
-    		reg == REG_TOTAL_PSU_QUANTITY || reg == REG_PSU_VERSION) {
-    	gDoCommGblData.DisConnCount = 0;
-    }
-
     //send command packet
     if ((size = sendTcpSocket(fd, (uint8_t *)&csuCmdPkt, sendPktLen)) < 0) {
         log_error("TCP socket send packet fail = %d", size);
@@ -1413,14 +1584,19 @@ static int composeSocketData(int fd,
     }
 
     //receive result head
-    if ((size = recvTcpSocket(fd, (uint8_t *)&csuResult.Head, sizeof(csuResult.Head))) < 0) {
+    if ((size = recvTcpSocket(fd, (uint8_t *)&csuResult.Head, sizeof(csuResult.Head),1)) < 0) {
         log_error("TCP socket RX head fail = %d", size);
-        gDoCommGblData.DisConnCount++;
+        // 若收不到以下封包,不產生錯誤
+        if (reg != REG_CABINET_DCM_VERSION && reg != REG_CABINET_OTHER_VERSION &&
+            reg != REG_TOTAL_PSU_QUANTITY && reg != REG_PSU_VERSION &&
+            reg != REG_READ_CABINET_SYSTEMID) {
+            gDoCommGblData.DisConnCount++;
+        }
         return FAIL;
     }
 
     //receive result raw data
-    if ((size = recvTcpSocket(fd, (uint8_t *)&csuResult.Data, csuResult.Head.DataLen)) < 0) {
+    if ((size = recvTcpSocket(fd, (uint8_t *)&csuResult.Data, csuResult.Head.DataLen,0)) < 0) {
         log_error("TCP socket RX data fail = %d", size);
         gDoCommGblData.DisConnCount++;
         return FAIL;
@@ -1514,12 +1690,12 @@ static int readChargerStationInfo(int fd)
 
     return ret;
 }
-
+/*
 static int writeDeductInfo(int fd, uint8_t id,uint8_t gunIndex, RecordTransactionInfo *transactionInfo)
 {
     int ret = PASS;
-    uint8_t dataBuf[22] = {0};
-    int i;
+    uint8_t dataBuf[104] = {0};
+    //int i;
 
     memset((char *)dataBuf, 0x00, sizeof(dataBuf));
     dataBuf[0] = transactionInfo->DeductResult;
@@ -1535,28 +1711,33 @@ static int writeDeductInfo(int fd, uint8_t id,uint8_t gunIndex, RecordTransactio
     dataBuf[7] = (amount >> 16) & 0xFF;
     dataBuf[8] = (amount >> 8) & 0xFF;
     dataBuf[9] = (amount & 0xFF);
-    memcpy((char *)&dataBuf[10], transactionInfo->ApprovalNo,9);
-    /*
-    for(i=0;i<22;i++) {
-    	log_info("dataBuf[%d]:0x%x",i,dataBuf[i]);
-    }
-    */
-    log_info("Gun[%d] TransactionId:%d DeductResult:%d IsDonateInvoice:%d Amount:%f",
-    		gunIndex,transactionInfo->TransactionId,transactionInfo->DeductResult,transactionInfo->IsDonateInvoice,transactionInfo->Amount);
+    memcpy((char *)&dataBuf[10], transactionInfo->pCreditCard.ApprovalNo,9);
+    memcpy((char *)&dataBuf[19], transactionInfo->pCreditCard.VemData, 64);
+    memcpy((char*)&dataBuf[83], transactionInfo->pCreditCard.CardNo, 20);
+
+    log_info("Gun[%d] TransactionId:%d DeductResult:%d IsDonateInvoice:%d Amount:%f Approva Num:'%s' VemData:'%s' CardNo:'%s'",
+    		transactionInfo->ConnectorID,
+            transactionInfo->TransactionId,
+            transactionInfo->DeductResult,
+            transactionInfo->IsDonateInvoice,
+            transactionInfo->Amount,
+            transactionInfo->pCreditCard.ApprovalNo,
+            transactionInfo->pCreditCard.VemData,
+            transactionInfo->pCreditCard.CardNo);
     // copy deduct result to dataBuf here
 
     if ((ret = composeSocketData(fd,
                                  id,
                                  OP_WRITE_DATA,
                                  REG_DEDUCT_INFO,
-                                 22,
+                                 104,
                                  &dataBuf[0])) == FAIL) {
         return ret;
     }
 
     return ret;
 }
-
+*/
 static int writeWaitPlugItState(int fd, uint8_t id)
 {
     int ret = PASS;
@@ -1714,13 +1895,18 @@ static int writeUserID(int fd, uint8_t id, uint8_t *pUserID)
     if ((strlen((char *)pUserID) <= 0) || (pUserID == NULL)) {
         return FAIL;
     }
-
+    uint8_t data[50];
+    int datalen = strlen((char*)pUserID);
+    memcpy((uint8_t*)data, pUserID, datalen);
+    data[datalen] = '\0';
+    data[datalen+1] = ShmDcCommonData->AuthroizeType;
+    datalen += 2;
     return composeSocketData(fd,
                              id,
                              OP_WRITE_DATA,
                              REG_USER_ID,
-                             strlen((char *)pUserID),
-                             pUserID);
+                             datalen,
+                             &data[0]);
 }
 
 static int writeConnectorState(int fd, uint8_t plugNum, uint8_t id)
@@ -1919,6 +2105,21 @@ static int readCabinetEachPSUVersion(int fd, uint8_t id,uint8_t n_psu)
 
     return ret;
 }
+
+static int readReceiptInfo(int fd, uint8_t id)
+{
+    int ret = PASS;
+
+    ret = composeSocketData(fd,
+        id,
+        OP_READ_DATA,
+        REG_RECEIPT_INFO,
+        0,
+        NULL);
+
+    return ret;
+}
+
 static int writeDispenserStatus(int fd, uint8_t gunID)
 {
     uint8_t warningCount = 0;
@@ -1983,7 +2184,58 @@ static int readConnectorID(int fd)
 
     return ret;
 }
+static int readSystemID(int fd)
+{
+    int ret = PASS;
+
+    ret = composeSocketData(fd,
+                            ID_REGISTER,
+                            OP_READ_DATA,
+                            REG_READ_CABINET_SYSTEMID,
+                            0,
+                            NULL);
+
+    return ret;
+}
+static int readDefaultPrice(int fd)
+{
+    int ret = PASS;
+
+    ret = composeSocketData(fd,
+                            ID_REGISTER,
+                            OP_READ_DATA,
+                            REG_READ_DEFAULT_PRICE,
+                            0,
+                            NULL);
+
+    return ret;
+}
+static int readUserPrice(int fd, uint8_t gunID)
+{
+    int ret = PASS;
+
+    ret = composeSocketData(fd,
+                            gunID,
+                            OP_READ_DATA,
+                            REG_READ_USER_PRICE,
+                            0,
+                            NULL);
+
+    return ret;
+}
+static int readConsumptionInfo(int fd)
+{
+    int ret = PASS;
+
+    ret = composeSocketData(fd,
+                            ID_REGISTER,
+                            OP_READ_DATA,
+                            REG_POWER_CONSUMPTION_INFO,
+                            0,
+                            NULL);
 
+    return ret;
+}
 static int WriteModelName(int fd)
 {
     int ret = PASS;
@@ -2182,9 +2434,9 @@ static int messageTrigger(int fd, uint8_t plugNum, uint8_t gunID, uint8_t curReg
                 if (readChargingCapability(fd, gunID) == PASS) {
 					gMoreInfoReq[plugNum].bits.FinalCostReq = false;
 					pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(plugNum);
-					ShmDcCommonData->finalcost[plugNum] = pDcChargingInfo->ChargingFee;
-					ShmDcCommonData->finalcost_flag[plugNum] = TRUE;
-					log_info("Gun %d get final cost %d", plugNum, pDcChargingInfo->ChargingFee);
+					//ShmDcCommonData->TransactionInfo[plugNum].Amount = pDcChargingInfo->ChargingFee;
+					ShmDcCommonData->pGunInfo[plugNum].finalcost_flag = TRUE;
+					log_info("Gun %d get final cost %f", plugNum, pDcChargingInfo->ChargingFee);
                 }
             }
             curReg = REG_PLUG_IN_STATE;
@@ -2232,9 +2484,39 @@ static int messageTrigger(int fd, uint8_t plugNum, uint8_t gunID, uint8_t curReg
                 writeConnectorState(fd, plugNum, gunID);
                 ftime(&gRegTimeUp[plugNum][curReg]);
             }
-            curReg = REG_QRCODE_URL_INFO;
+            curReg = REG_DISPENSER_REQUEST;
             break;
+        case REG_DISPENSER_REQUEST:
+            /*
+            gConnectorActReq[plugNum].bits.ChargingCancel = ShmDcCommonData->OperateIDLE[plugNum];
+            if (gConnectorActReq[plugNum].Value != 0)
+            {
+                if (DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) > LOOP_RETRY_TIME ||
+                    DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) < 0) {
 
+                    if (writeDispenserRequest(fd, gunID, plugNum) == PASS)
+                    {
+                        gConnectorActReq[plugNum].Value = 0;
+                        log_info("Gun %d CHARGING_CANCEL OK", plugNum);
+                        ShmDcCommonData->OperateIDLE[plugNum] = 0;
+                    }
+                    ftime(&gRegTimeUp[plugNum][curReg]);
+                }
+            }
+            */
+            curReg = REG_QRCODE_URL_INFO;
+            break;
+        case REG_QRCODE_URL_INFO:
+            if (gunID == 1) {
+                if (DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) > (LOOP_RETRY_TIME * 10) ||
+                    DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) < 0
+                    ) {
+                    readQRcodeURLAndSystemDate(fd);
+                    ftime(&gRegTimeUp[plugNum][curReg]);
+                }
+            }
+            curReg = REG_READ_CABINET_SYSTEMID;
+            break;
         //case REG_USER_ID:
         //    writeUserID(fd, gunID, uint8_t *pUserID);
         //    break;
@@ -2278,29 +2560,7 @@ static int messageTrigger(int fd, uint8_t plugNum, uint8_t gunID, uint8_t curReg
         //case REG_PRESENT_CHARGING_INFO:
         //    break;
 
-        case REG_QRCODE_URL_INFO:
-            if (gunID == 1) {
-                if (DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) > (LOOP_RETRY_TIME * 10) ||
-                        DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) < 0
-                   ) {
-                    readQRcodeURLAndSystemDate(fd);
-                    ftime(&gRegTimeUp[plugNum][curReg]);
-                }
-            }
 
-            //check misc command from power cabinet
-            if (gDoCommGblData.MiscCmd != 0) {
-                if (gDoCommGblData.MiscCmd != REG_MISC_CONTROL) {
-                    log_error("misc command failed = %x", gDoCommGblData.MiscCmd);
-                }
-                curReg = gDoCommGblData.MiscCmd;
-            } else if (gMoreInfoReq[plugNum].Value != 0) {
-                curReg = REG_RESERVATION_IDTAG;
-            } else {
-                isContinue = 0;
-            }
-            //curReg = REG_SOFTWARE_UPDATE;
-            break;
 
         //case REG_WAIT_PLUG_IT_STATE:
         //    if (DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) > (LOOP_RETRY_TIME / 10)) {
@@ -2322,56 +2582,119 @@ static int messageTrigger(int fd, uint8_t plugNum, uint8_t gunID, uint8_t curReg
         //case REG_PSU_VERSION:
         //    break;
 
+
+        //case REG_DISPENSER_REQUEST:
+        //    break;
+
+
+        case REG_READ_CABINET_SYSTEMID:
+            if (DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) > LOOP_RETRY_TIME ||
+                DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) < 0) {
+                readSystemID(fd);
+                ftime(&gRegTimeUp[plugNum][curReg]);
+            }
+            curReg = REG_POWER_CONSUMPTION_INFO;
+            break;
+
+        case REG_POWER_CONSUMPTION_INFO:
+            if (pSysConfig->ShowInformation || ShmDcCommonData->DebugFlag) {
+                if (DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) > LOOP_RETRY_TIME ||
+                    DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) < 0) {
+                    readConsumptionInfo(fd);
+                    ftime(&gRegTimeUp[plugNum][curReg]);
+                }
+            }
+            //check misc command from power cabinet
+            if (gDoCommGblData.MiscCmd != 0) {
+                if (gDoCommGblData.MiscCmd != REG_MISC_CONTROL) {
+                    log_error("misc command failed = %x", gDoCommGblData.MiscCmd);
+                }
+                curReg = gDoCommGblData.MiscCmd;
+            } else if (gMoreInfoReq[plugNum].Value != 0) {
+                curReg = REG_RESERVATION_IDTAG;
+            } else {
+                isContinue = 0;
+            }
+            break;
+
         case REG_RESERVATION_IDTAG:
-            if(gMoreInfoReq[plugNum].bits.ReservationReq)
+            if (gMoreInfoReq[plugNum].bits.ReservationReq)
             {
                 if (DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) > LOOP_RETRY_TIME ||
-                        DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) < 0) {
-                    if(readReservationState(fd, gunID) == PASS)
+                    DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) < 0) {
+                    if (readReservationState(fd, gunID) == PASS)
                     {
                         gMoreInfoReq[plugNum].bits.ReservationReq = ReservationState[plugNum] == NO ? NO : YES;
                     }
                     ftime(&gRegTimeUp[plugNum][curReg]);
                 }
             }
-            curReg = REG_DISPENSER_REQUEST;
+            curReg = REG_REMOTE_START_NO_ID;
             break;
-
-        //case REG_DISPENSER_REQUEST:
-        //    break;
-            case REG_DISPENSER_REQUEST:
-                if (gConnectorActReq[plugNum].Value != 0)
-                {
-                    if (DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) > LOOP_RETRY_TIME ||
-                        DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) < 0) {
-
-
-
-                        if (writeDispenserRequest(fd, gunID, plugNum) == PASS)
-                        {
-                            gConnectorActReq[plugNum].Value = 0;
-                            log_info("Gun %d CHARGING_CANCEL OK");
-                        }
-                        ftime(&gRegTimeUp[plugNum][curReg]);
-                    }
-                }
-                curReg = REG_REMOTE_START_NO_ID;
-                break;
         case REG_REMOTE_START_NO_ID:
-            if(gMoreInfoReq[plugNum].bits.RemoteStartNoID)
+            if (gMoreInfoReq[plugNum].bits.RemoteStartNoID)
             {
                 if (DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) > LOOP_RETRY_TIME ||
-                        DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) < 0) {
-                    if(readRemoteStartNoIDState(fd) == PASS)
+                    DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) < 0) {
+                    if (readRemoteStartNoIDState(fd) == PASS)
                     {
                         gMoreInfoReq[plugNum].bits.RemoteStartNoID = RemoteStartNoIDState == NO ? NO : YES;
                     }
                     ftime(&gRegTimeUp[plugNum][curReg]);
                 }
             }
-            curReg = REG_REFUND_AMOUNT;
+            curReg = REG_STATION_INFO;
             break;
+        case REG_STATION_INFO:
+            if (gMoreInfoReq[plugNum].bits.StationInfoReq)
+            {
+                if (DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) > LOOP_RETRY_TIME ||
+                    DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) < 0) {
 
+                    if (readChargerStationInfo(fd) == PASS)
+                    {
+                        gMoreInfoReq[plugNum].bits.StationInfoReq = NO;
+                    }
+                    ftime(&gRegTimeUp[plugNum][curReg]);
+                }
+            }
+            //isContinue = 0;
+            curReg = REG_READ_DEFAULT_PRICE;
+            break;
+
+        case REG_READ_DEFAULT_PRICE:
+            if (gMoreInfoReq[plugNum].bits.DefaultPriceReq)
+            {
+                if (DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) > LOOP_RETRY_TIME ||
+                    DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) < 0) {
+                    readDefaultPrice(fd);
+                    ftime(&gRegTimeUp[plugNum][curReg]);
+                }
+            }
+            curReg = REG_READ_USER_PRICE;
+            break;
+        case REG_READ_USER_PRICE:
+            if (gMoreInfoReq[plugNum].bits.UserPriceReq)
+            {
+                if (DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) > LOOP_RETRY_TIME ||
+                    DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) < 0) {
+                    readUserPrice(fd,gunID);
+                    ftime(&gRegTimeUp[plugNum][curReg]);
+                }
+            }
+            curReg = REG_RECEIPT_INFO;
+            break;
+        case REG_RECEIPT_INFO:
+            if (gMoreInfoReq[plugNum].bits.ReceiptReq)
+            {
+                if (DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) > LOOP_RETRY_TIME ||
+                    DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) < 0) {
+                    readReceiptInfo(fd, gunID);
+                    ftime(&gRegTimeUp[plugNum][curReg]);
+                }
+            }
+            curReg = REG_REFUND_AMOUNT;
+            break;
         case REG_REFUND_AMOUNT:
             curReg = REG_PREPAYMENT_INFO;
             break;
@@ -2385,25 +2708,10 @@ static int messageTrigger(int fd, uint8_t plugNum, uint8_t gunID, uint8_t curReg
             break;
 
         case REG_CONNECTOR_QR_CODE:
-            curReg = REG_STATION_INFO;
-            break;
-
-        case REG_STATION_INFO:
-            if(gMoreInfoReq[plugNum].bits.StationInfoReq)
-            {
-                if (DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) > LOOP_RETRY_TIME ||
-                        DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) < 0) {
-
-                    if(readChargerStationInfo(fd) == PASS)
-                    {
-                        gMoreInfoReq[plugNum].bits.StationInfoReq = NO;
-                    }
-                    ftime(&gRegTimeUp[plugNum][curReg]);
-                }
-            }
             isContinue = 0;
             break;
 
+
         default:
             log_error("error curReg = %x", curReg);
             gDoCommGblData.MiscCmd = 0;
@@ -2791,6 +3099,7 @@ int main(int argc, char *argv[])
 
 
         if (pSysConfig->Eth0Interface.EthDhcpClient == 0) {
+            system("pgrep -f \"udhcpc -i eth0\" | xargs kill");
             sprintf(tmpbuf,
                     "/sbin/udhcpc -i eth0 -x hostname:CSU3_%s -s /root/dhcp_script/eth0.script > /dev/null &",
                     pSysConfig->SystemId);

+ 16 - 3
EVSE/Projects/DD360UCar/Apps/ModuleDoComm/DoComm.h

@@ -16,7 +16,7 @@
 #define TFTP_PULL_CMD                           "tftp"
 #define SIGTERM_MSG                             "SegmentFault.~~~~\n"
 
-#define MAX_REGISTER_NUM                        30
+#define MAX_REGISTER_NUM                        40
 
 #define CHECK_NETWORK_FAIL_COUNT                10//10
 #define CONNECT_SERVER_FAIL_COUNT               3//5
@@ -93,6 +93,11 @@
 #define REG_CONNECTOR_QR_CODE                   0x1D
 #define REG_STATION_INFO                        0x1E
 #define REG_DEDUCT_INFO                         0x1F
+#define REG_READ_CABINET_SYSTEMID               0x20
+#define REG_READ_DEFAULT_PRICE                  0x21
+#define REG_READ_USER_PRICE                     0x22
+#define REG_RECEIPT_INFO                        0x23
+#define REG_POWER_CONSUMPTION_INFO              0x24
 
 //------------------------------------------------------------------------------
 //--- dispenser result ---
@@ -139,6 +144,9 @@
 #define MISC_CMD_STATION_INFO_REQ               (0x0109)
 #define MISC_CMD_FINAL_COST_REQ                 (0x010A)
 #define MISC_CMD_LINE_STATUS_REQ                (0x010B)
+#define MISC_CMD_DEFAULT_PRICE_REQ              (0x010C)
+#define MISC_CMD_USER_PRICE_REQ                 (0x010D)
+#define MISC_CMD_RECEIPT_REQ                    (0x010E)
 
 #define ST_UPDATE_FIRMWARE                      (0x01)
 #define ST_NO_UPDATE_FIRMWARE                   (0x02)
@@ -192,7 +200,10 @@ typedef union
         unsigned int RemoteStartNoID:1;             // 0: no effect,                1: need to request RemoteStartNoID
         unsigned int StationInfoReq:1;              // 0: no effect,                1: need to request StationInfo
         unsigned int FinalCostReq:1;                // 0: no effect,                1: need to request FinalCost
-        unsigned int res:28;
+        unsigned int DefaultPriceReq : 1;           // 0: no effect,                1: need to request Default price
+        unsigned int UserPriceReq : 1;              // 0: no effect,                1: need to request User price
+        unsigned int ReceiptReq : 1;                // 0: no effect,                1: need to request Receipt
+        unsigned int res:27;
     }bits;
 } MoreInfoReq;
 
@@ -312,7 +323,9 @@ typedef struct StAccountInfo {
     int Balance;
     int Discount;
     int Transaction;
-    uint8_t Reserved[3];
+    int EnergyCost;
+    int ParkingFee;
+    uint8_t Reserved[1];
 } AccountInfo;
 
 typedef struct stCabinetDCMVersion {

+ 14 - 1
EVSE/Projects/DD360UCar/Apps/ModuleEvComm/Ev_Comm.c

@@ -14,6 +14,7 @@
 #include "Ev_Comm.h"
 #include "Module_EvComm.h"
 #include "../ShareMemory/shmMem.h"
+#include "../Config.h"
 
 //------------------------------------------------------------------------------
 int PackageIdCmd(int cmd)
@@ -23,14 +24,26 @@ int PackageIdCmd(int cmd)
 
 void SendCmdToEvboard(int cmd, uint8_t *data, uint8_t dataLen)
 {
+    DcCommonInfo* ShmDcCommonData = (DcCommonInfo*)GetShmDcCommonData();
     int fd = GetCanFd();
     struct can_frame frame;
-
+    int len = 0;
+    char _info[1024];
+    int i;
     frame.can_id = cmd;
     frame.can_dlc = dataLen;
     memcpy(frame.data, data, sizeof(frame.data));
 
     write(fd, &frame, sizeof(struct can_frame));
+
+    if (ShmDcCommonData->showCanPackage) {
+        len += sprintf(&_info[len], "CAN Dispenser => EV Tx:\t[0x%X] ", cmd);
+        for (i = 0; i < dataLen; i++) {
+            len += sprintf(&_info[len], "%X ", data[i]);
+        }
+        len += sprintf(&_info[len], "\n");
+        printf("%s", _info);
+    }
 }
 
 //------------------------------------------------------------------------------

+ 26 - 27
EVSE/Projects/DD360UCar/Apps/ModuleEvComm/Module_EvRxComm.c

@@ -642,39 +642,38 @@ void CANReceiver(int fd)
 
                     pDcChargingInfo->ChillerTemp = maxChillerTemp;
                 }
-
-                maxConnTemp = getMaxConnectTemp(frame.data[1], frame.data[2]);
-                //if ((maxConnTemp - 3) >= pDcChargingInfo->ConnectorTemp) {
-                //    printConnTemp = YES;
-                //}
-                maxConnTemp = getAvageTemp(maxConnTemp,targetGun);
-                if(maxConnTemp > (lastConnTemp[targetGun] + 2) || maxConnTemp < (lastConnTemp[targetGun] - 2))
-                {
-                    lastConnTemp[targetGun] = maxConnTemp;
-                    printConnTemp = YES;
+                // 避免EV小板Reset產生數值為零的情況
+                if (ShmDcCommonData->ConnectorTemp[gunTypeIndex][0] != 0 && ShmDcCommonData->ConnectorTemp[gunTypeIndex][1] != 0) {
+                    maxConnTemp = getMaxConnectTemp(ShmDcCommonData->ConnectorTemp[gunTypeIndex][0], ShmDcCommonData->ConnectorTemp[gunTypeIndex][1]);
+                    //if ((maxConnTemp - 3) >= pDcChargingInfo->ConnectorTemp) {
+                    //    printConnTemp = YES;
+                    //}
+                    maxConnTemp = getAvageTemp(maxConnTemp, targetGun);
+                    if (maxConnTemp > (lastConnTemp[targetGun] + 2) || maxConnTemp < (lastConnTemp[targetGun] - 2))
+                    {
+                        lastConnTemp[targetGun] = maxConnTemp;
+                        printConnTemp = YES;
+                    }
+                    pDcChargingInfo->ConnectorTemp = maxConnTemp;
                 }
-
-                pDcChargingInfo->ConnectorTemp = maxConnTemp;
-
                 //紀錄槍頭和水冷機溫度, 在系統狀態變化或溫度大於150
                 if ((ShmDcCommonData->SystemModeChange[targetGun] == YES) ||
-                        (printConnTemp == YES) ||
-                        (printChillerTemp == YES) //&&
-                        //(((pDcChargingInfo->ConnectorTemp >= GUN_OTP_VALUE) &&
-                        //  (pDcChargingInfo->ConnectorTemp != UNDEFINED_TEMP)) ||
-                        // ((pDcChargingInfo->ChillerTemp >= GUN_OTP_VALUE) &&
-                        //  (pDcChargingInfo->ChillerTemp != UNDEFINED_TEMP)))
-                   ) {
+                    (printConnTemp == YES) ||
+                    (printChillerTemp == YES) //&&
+                    //(((pDcChargingInfo->ConnectorTemp >= GUN_OTP_VALUE) &&
+                    //  (pDcChargingInfo->ConnectorTemp != UNDEFINED_TEMP)) ||
+                    // ((pDcChargingInfo->ChillerTemp >= GUN_OTP_VALUE) &&
+                    //  (pDcChargingInfo->ChillerTemp != UNDEFINED_TEMP)))
+                    ) {
                     ShmDcCommonData->SystemModeChange[targetGun] = NO;
                     log_info("Gun%d max head temp = %d, chiller1 = [%d,%d], chiller2 = [%d,%d]",
-                             targetGun,
-                             maxConnTemp,
-                             chiilerTemp.Temp[0],
-                             chiilerTemp.Temp[1],
-                             chiilerTemp.Temp[2],
-                             chiilerTemp.Temp[3]);
+                        targetGun,
+                        pDcChargingInfo->ConnectorTemp,
+                        chiilerTemp.Temp[0],
+                        chiilerTemp.Temp[1],
+                        chiilerTemp.Temp[2],
+                        chiilerTemp.Temp[3]);
                 }
-
                 if (((ShmDcCommonData->ChillerValve.MultiChillerGun & 0x80) >> 7) == YES) {
                     //沒有水冷槍
                     break;

+ 2 - 1
EVSE/Projects/DD360UCar/Apps/ModuleEvComm/Module_EvTxComm.c

@@ -600,7 +600,8 @@ static void checkConnectorOVPState(uint8_t gunIndex)
         break;
     }
 
-    if (ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerOTP == YES) {
+    if (ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerOTP == YES ||
+        ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerTubeOTP == YES) {
         isOTP = true;
     }
 

+ 6 - 4
EVSE/Projects/DD360UCar/Apps/ModuleLcmCtrl/Module_LcmControl.c

@@ -533,8 +533,10 @@ void ShowViewChargingPower(uint8_t gunIndex,float power)
 }
 void ShowConnectId()
 {
-    ChangeDisplay2Value(_LeftGun_ConnectorId, _ICON_CONNECTOR_1);
-    ChangeDisplay2Value(_RightGun_ConnectorId, _ICON_CONNECTOR_1);
+    int id = atoi(pSysConfig->SystemId);
+    if (id == 0)
+        id = 1;
+    ChangeDisplay2Value(_Text_SystemID, id);
     
     if (ShmDcCommonData->ConnectorId[0] <= 2) {
         ChangeDisplay2Value(_LeftGun_Symbol_Icon, _ICON_CONNECTOR_A);
@@ -788,7 +790,7 @@ void ShowSummaryPage()
     GetHrFormTimeString(pDcChargingInfo->StopDateTime,end_hr);
     GetMinFormTimeString(pDcChargingInfo->StopDateTime,end_min);
 
-    t_hr = atoi(start_hr) + (ShmDcCommonData->TzOffset / 60);
+    t_hr = atoi(start_hr) + (ShmDcCommonData->TZOffset / 60);
     if (t_hr >= 24)
         t_hr -= 24;
     if (!ShmDcCommonData->isIntoCharge[pSysInfo->CurGunSelected]) {
@@ -797,7 +799,7 @@ void ShowSummaryPage()
     }
     ChangeDisplay2Value(_Summary_Start_time_hr, t_hr);
     ChangeDisplay2Value(_Summary_Start_time_min, atoi(start_min));
-    t_hr = atoi(end_hr) + (ShmDcCommonData->TzOffset / 60);
+    t_hr = atoi(end_hr) + (ShmDcCommonData->TZOffset / 60);
     if (t_hr >= 24)
         t_hr -= 24;
     if (!ShmDcCommonData->isIntoCharge[pSysInfo->CurGunSelected]) {

+ 1 - 0
EVSE/Projects/DD360UCar/Apps/ModuleLcmCtrl/Module_LcmControl.h

@@ -144,6 +144,7 @@
 #define _Text_Warming2              0x1120
 #define _Text_Warming3              0x1130
 #define _Text_Warming4              0x1140
+#define _Text_SystemID              0x1150
 
 int DemoPage[22] = {
     1, // All Idle

+ 71 - 0
EVSE/Projects/DD360UCar/Apps/ReadCmdline.c

@@ -1219,6 +1219,71 @@ static void writeGunAndChillerTemp(void)
         usleep(sleepTime);
     }//while
 }
+void showNetworkPage(char* v1)
+{
+    ShmDcCommonData->showNetPackage = atoi(newString[1]);
+    if (ShmDcCommonData->showNetPackage)
+        printf("Show Network Package on\n");
+    else
+        printf("Show Network Package off\n");
+}
+void showCANBUSPage(char* v1)
+{
+    ShmDcCommonData->showCanPackage = atoi(newString[1]);
+    if (ShmDcCommonData->showCanPackage)
+        printf("Show CAN Bus Package on\n");
+    else
+        printf("Show CAN Bus Package off\n");
+}
+static void writeOTPTemp(void)
+{
+    uint8_t _GunIndex = 0;
+    int isContinue = 1;
+    uint32_t sleepTime = 500000;
+    char* usageMsg = "Usage:\n"
+        "       OTP  <temp_recovery>  <temp>, ex: OTP 140 150\n"
+        "       exit | c | C\n"
+        "       help | ? | h\n"
+        "\r\n";
+
+    while (isContinue) {
+        if (readCmdKey(CMD_KEY_WAIT) == NO) {
+            sleep(sleepTime);
+            continue;
+        }
+
+        if (helpCmd() == YES) {
+            printf("%s\n", usageMsg);
+            continue;
+        } else if (exitCmd() == YES) {
+            sleep(1);
+            return;
+        }
+        if (strcmp(newString[0], "OTP") != 0) {
+            printf("argc 1 is error parameter\r\n");
+            continue;
+        }
+
+        if (atoi(newString[1]) > 255 ||
+            atoi(newString[1]) == -1) {
+            printf("Recovey temperature value overflow\r\n");
+            continue;
+        }
+
+        if (atoi(newString[2]) > 255 ||
+            atoi(newString[2]) == -1) {
+            printf("Recovey temperature value overflow\r\n");
+            continue;
+        }
+
+        pSysInfo->OTPTempR = atoi(newString[1]);
+        pSysInfo->OTPTemp = atoi(newString[2]);
+
+        printf("OTP Recovery Temp set:%d\n", pSysInfo->OTPTempR);
+        printf("OTP Temp set:%d\n", pSysInfo->OTPTemp);
+        usleep(sleepTime);
+    }//while
+}
 
 int main(void)
 {
@@ -1420,6 +1485,12 @@ int main(void)
         	ShmPrimaryMcuData->InputDet.bits.Button2 = BTN_PRESS;
         	sleep(1);
         	ShmPrimaryMcuData->InputDet.bits.Button2 = BTN_RELEASE;
+        } else if (strcmp(newString[0], "OTP") == 0) { //測試槍頭和水冷機溫度
+            writeOTPTemp();
+        } else if (strcmp(newString[0], "netdump") == 0) { //印出網路封包
+            showNetworkPage(newString[1]);
+        } else if (strcmp(newString[0], "candump") == 0) { //印出網路封包
+            showCANBUSPage(newString[1]);
         } else {
             printf("%s\n", usageMsg);
         }

+ 2 - 1
EVSE/Projects/DD360UCar/Apps/SelectGun/SelectGun.h

@@ -63,7 +63,8 @@ typedef struct StPricesInfo {
     //float DefaultPrices;        //unit = 0.01 dollar, value / 100
     float Discount;
     int TransactionId;
-    uint8_t Reserved[4];
+    float EnergyCost;
+    float ParkingFee;
 } PricesInfo;
 
 //typedef struct StOperativeInfo {

+ 29 - 0
EVSE/Projects/DD360UCar/Apps/ShareMemory/shmMem.c

@@ -38,6 +38,7 @@ static struct FanModuleData *ShmFanModuleData = NULL;
 static struct RelayModuleData *ShmRelayModuleData = NULL;
 static struct LedModuleData *ShmLedModuleData = NULL;
 static struct OCPP16Data *ShmOCPP16Data = NULL;
+static struct OCPP20Data* ShmOCPP20Data = NULL;
 
 static SelectGunInfo *ShmSelectGunInfo = NULL;
 static DcCommonInfo *ShmDcCommonData = NULL;
@@ -300,6 +301,15 @@ void *GetShmOCPP16Data(void)
     return ShmOCPP16Data;
 }
 
+void* GetShmOCPP20Data(void)
+{
+    if (ShmOCPP20Data == NULL) {
+        return NULL;
+    }
+
+    return ShmOCPP20Data;
+}
+
 void *GetShmSelectGunInfo(void)
 {
     if (ShmSelectGunInfo == NULL) {
@@ -602,6 +612,21 @@ int InitOCPPShmMem(void)
     return PASS;
 }
 
+int InitOCPP20ShmMem(void)
+{
+    int MeterSMId = FAIL;
+
+    if ((MeterSMId = shmget(ShmOcpp20ModuleKey, sizeof(struct OCPP20Data), IPC_CREAT | 0777)) < 0) {
+        log_info("Get OCPP20 share memory error");
+        return FAIL;
+    } else if ((ShmOCPP20Data = shmat(MeterSMId, NULL, 0)) == (void*)-1) {
+        log_info("Create OCPP20 share memory error");
+        return FAIL;
+    }
+
+    return PASS;
+}
+
 int InitLEDShmMem(void)
 {
     int MeterSMId = FAIL;
@@ -1123,6 +1148,10 @@ int CreateAllCsuShareMemory(void)
         return ret;
     }
 
+    if ((ret = InitOCPP20ShmMem()) == FAIL) {
+        return ret;
+    }
+
     if ((ret = InitSelectGunShmMem()) == FAIL) {
         return ret;
     }

+ 1 - 0
EVSE/Projects/DD360UCar/Apps/ShareMemory/shmMem.h

@@ -42,6 +42,7 @@ void *GetShmSysInfoData(void);
 void *GetShmSysWarningInfo(void);
 
 void *GetShmOCPP16Data(void);
+void* GetShmOCPP20Data(void);
 
 void *GetShmCHAdeMOData(void);
 void *GetShmGBTData(void);

二进制
EVSE/Projects/DD360UCar/Images/ramdisk.gz


二进制
EVSE/Projects/DD360UCar/output/FactoryConfig


二进制
EVSE/Projects/DD360UCar/output/Module_ChkSysTask


二进制
EVSE/Projects/DD360UCar/output/Module_DoComm


二进制
EVSE/Projects/DD360UCar/output/Module_EvComm


二进制
EVSE/Projects/DD360UCar/output/Module_EventLogging


二进制
EVSE/Projects/DD360UCar/output/Module_InternalComm


二进制
EVSE/Projects/DD360UCar/output/Module_LcmControl


二进制
EVSE/Projects/DD360UCar/output/Module_PrimaryComm


二进制
EVSE/Projects/DD360UCar/output/Module_UpdateFW


二进制
EVSE/Projects/DD360UCar/output/ReadCmdline


二进制
EVSE/Projects/DD360UCar/output/main


二进制
EVSE/Projects/DD360UCar/output/simulation


二进制
EVSE/rootfs/root/Module_PowerSharing