Browse Source

2022-09-20 / Simon Xue

Action:
1. [Mod] RFID big and little endiam using old set.
2. [Fix] Model name set one gun occure EVComm lost.
3. [Mod] Power derating not open.
4. [Add] Chiller Alarm pin and heater control pin working.

Files
As the following commit history files.

Image Version: V1.23.XX.XXXX.XX
Debug Version: V1.23.5
Simon Xue 2 years ago
parent
commit
71584df25c
38 changed files with 562 additions and 704 deletions
  1. 1 1
      EVSE/Projects/DD360/Apps/CSU/Ethernet.c
  2. 1 1
      EVSE/Projects/DD360/Apps/CSU/Primary.c
  3. 3 87
      EVSE/Projects/DD360/Apps/CSU/RFID.c
  4. 16 8
      EVSE/Projects/DD360/Apps/CSU/main.c
  5. 135 10
      EVSE/Projects/DD360/Apps/Define/define.h
  6. 10 0
      EVSE/Projects/DD360/Apps/ModuleDoComm/DoComm.c
  7. 5 0
      EVSE/Projects/DD360/Apps/ModuleDoComm/DoComm.h
  8. 5 1
      EVSE/Projects/DD360/Apps/ModuleEvComm/Module_EvRxComm.c
  9. 27 6
      EVSE/Projects/DD360/Apps/ModuleEvComm/Module_EvTxComm.c
  10. 9 6
      EVSE/Projects/DD360/Apps/ModuleInternalComm/RelayBoard.c
  11. 29 206
      EVSE/Projects/DD360/Apps/ModulePrimary/Module_PrimaryComm.c
  12. 2 1
      EVSE/Projects/DD360/Apps/ModulePrimary/PrimaryComm.c
  13. 38 25
      EVSE/Projects/DD360/Apps/ReadCmdline.c
  14. BIN
      EVSE/Projects/DD360/Images/ramdisk.gz
  15. BIN
      EVSE/Projects/DD360/output/FactoryConfig
  16. BIN
      EVSE/Projects/DD360/output/Module_ChkSysTask
  17. BIN
      EVSE/Projects/DD360/output/Module_DoComm
  18. BIN
      EVSE/Projects/DD360/output/Module_EvComm
  19. BIN
      EVSE/Projects/DD360/output/Module_EventLogging
  20. BIN
      EVSE/Projects/DD360/output/Module_InternalComm
  21. BIN
      EVSE/Projects/DD360/output/Module_LcmControl
  22. BIN
      EVSE/Projects/DD360/output/Module_PrimaryComm
  23. BIN
      EVSE/Projects/DD360/output/Module_UpdateFW
  24. BIN
      EVSE/Projects/DD360/output/ReadCmdline
  25. BIN
      EVSE/Projects/DD360/output/main
  26. 1 1
      EVSE/Projects/DD360Audi/Apps/CSU/Ethernet.c
  27. 1 1
      EVSE/Projects/DD360Audi/Apps/CSU/Primary.c
  28. 3 87
      EVSE/Projects/DD360Audi/Apps/CSU/RFID.c
  29. 16 8
      EVSE/Projects/DD360Audi/Apps/CSU/main.c
  30. 135 10
      EVSE/Projects/DD360Audi/Apps/Define/define.h
  31. 10 0
      EVSE/Projects/DD360Audi/Apps/ModuleDoComm/DoComm.c
  32. 5 0
      EVSE/Projects/DD360Audi/Apps/ModuleDoComm/DoComm.h
  33. 5 1
      EVSE/Projects/DD360Audi/Apps/ModuleEvComm/Module_EvRxComm.c
  34. 27 6
      EVSE/Projects/DD360Audi/Apps/ModuleEvComm/Module_EvTxComm.c
  35. 9 6
      EVSE/Projects/DD360Audi/Apps/ModuleInternalComm/RelayBoard.c
  36. 29 206
      EVSE/Projects/DD360Audi/Apps/ModulePrimary/Module_PrimaryComm.c
  37. 2 1
      EVSE/Projects/DD360Audi/Apps/ModulePrimary/PrimaryComm.c
  38. 38 25
      EVSE/Projects/DD360Audi/Apps/ReadCmdline.c

+ 1 - 1
EVSE/Projects/DD360/Apps/CSU/Ethernet.c

@@ -186,7 +186,7 @@ void InitEthernet(void)
     log_info("%s",tmpbuf);
     system(tmpbuf);
 
-    system("/sbin/ifconfig lo up");
+    //system("/sbin/ifconfig lo up");
 
     //Run DHCP client if enabled
     system("killall udhcpc");

+ 1 - 1
EVSE/Projects/DD360/Apps/CSU/Primary.c

@@ -59,7 +59,7 @@ void PrimaryLedIndicatorCtrlFork(void)
     if (pid == 0) {
         uint8_t gunIndex = 0;
         int isContinue = 1;
-
+        log_info("Primary Fork Child's PID is %d", getpid());
         struct SysConfigData *pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
         struct SysInfoData *pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
         struct WARNING_CODE_INFO *pSysWarning = (struct WARNING_CODE_INFO *)GetShmSysWarningInfo();

+ 3 - 87
EVSE/Projects/DD360/Apps/CSU/RFID.c

@@ -278,18 +278,16 @@ void ScannerCardProcess(void)
         UserScanFunction();
     }
 
-    if (pSysInfo->SystemPage == _LCM_AUTHORIZING) {
+    if (pSysInfo->PageIndex == _LCM_AUTHORIZING) {
         if(!isAuthorizedComplete())
             StartSystemTimeoutDet(Timeout_Authorizing);
 
         //printf("isAuthorizedComplete = %d, %f", isAuthorizedComplete(), ShmSelectGunInfo->PricesInfo[pSysInfo->CurGunSelected].Balance);
         // 確認驗證卡號完成沒
         if (isAuthorizedComplete()
-            /*
 #if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
                 || pSysConfig->OfflinePolicy == _OFFLINE_POLICY_FREE_CHARGING
 #endif //!defined DD360 && !defined DD360Audi && !defined DD360ComBox
-*/
            ) {
                 //StopSystemTimeoutDet();
                 StartSystemTimeoutDet(Timeout_WaitBalance);
@@ -307,14 +305,14 @@ void ScannerCardProcess(void)
                 }
 
             } ClearAuthorizedFlag();
-        } /*else if (pSysConfig->OfflinePolicy == _OFFLINE_POLICY_LOCAL_LIST) {
+        }/* else if (pSysConfig->OfflinePolicy == _OFFLINE_POLICY_LOCAL_LIST) {
             // 白名單驗證
             for (i = 0; i < 10; i++) {
                 if (strcmp((char *)pSysConfig->LocalWhiteCard[i], "") == EQUAL) {
                     continue;
                 }
+
                 if (strcmp((char *)pSysConfig->LocalWhiteCard[i], (char *)pSysConfig->UserId) == EQUAL) {
-                    log_info("Local White Card [%d]:%s", i, pSysConfig->LocalWhiteCard[i]);
                     pSysInfo->SystemPage = _LCM_AUTHORIZ_COMP;
                     ClearAuthorizedFlag();
                     break;
@@ -395,7 +393,6 @@ void CreateRfidFork(void)
 
             if (pSysConfig->RfidCardNumEndian == RFID_ENDIAN_LITTLE) {
                 switch (rfid.snType) {
-#ifdef DD360Audi
                 case RFID_SN_TYPE_6BYTE:
                     sprintf((char *) pSysConfig->UserId,
                             "%02X%02X%02X%02X%02X%02X",
@@ -426,50 +423,9 @@ void CreateRfidFork(void)
                             rfid.currentCard[0], rfid.currentCard[1],
                             rfid.currentCard[2], rfid.currentCard[3]);
                     break;
-#else
-                case RFID_SN_TYPE_6BYTE:
-                    sprintf((char*)pSysConfig->UserId,
-                        "%02X%02X%02X%02X%02X%02X",
-                        rfid.currentCard[5], rfid.currentCard[4],
-                        rfid.currentCard[3], rfid.currentCard[2],
-                        rfid.currentCard[1], rfid.currentCard[0]);
-                    break;
-                case RFID_SN_TYPE_7BYTE:
-                    sprintf((char*)pSysConfig->UserId,
-                        "%02X%02X%02X%02X%02X%02X%02X",
-                        rfid.currentCard[6], rfid.currentCard[5],
-                        rfid.currentCard[4], rfid.currentCard[3],
-                        rfid.currentCard[2], rfid.currentCard[1],
-                        rfid.currentCard[0]);
-                    break;
-                case RFID_SN_TYPE_8BYTE:
-                    sprintf((char*)pSysConfig->UserId,
-                        "%02X%02X%02X%02X%02X%02X%02X%02X",
-                        rfid.currentCard[7], rfid.currentCard[6],
-                        rfid.currentCard[5], rfid.currentCard[4],
-                        rfid.currentCard[3], rfid.currentCard[2],
-                        rfid.currentCard[1], rfid.currentCard[0]);
-                    break;
-                case RFID_SN_TYPE_10BYTE:
-                    sprintf((char*)pSysConfig->UserId,
-                        "%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X",
-                        rfid.currentCard[9], rfid.currentCard[8],
-                        rfid.currentCard[7], rfid.currentCard[6],
-                        rfid.currentCard[5], rfid.currentCard[4],
-                        rfid.currentCard[3], rfid.currentCard[2],
-                        rfid.currentCard[1], rfid.currentCard[0]);
-                    break;
-                case RFID_SN_TYPE_4BYTE:
-                    sprintf((char*)pSysConfig->UserId,
-                        "%02X%02X%02X%02X",
-                        rfid.currentCard[3], rfid.currentCard[2],
-                        rfid.currentCard[1], rfid.currentCard[0]);
-                    break;
-#endif
                 }
             } else if (pSysConfig->RfidCardNumEndian == RFID_ENDIAN_BIG) {
                 switch (rfid.snType) {
-#ifdef DD360Audi
                 case RFID_SN_TYPE_6BYTE:
                     sprintf((char *) pSysConfig->UserId,
                             "%02X%02X%02X%02X%02X%02X",
@@ -500,46 +456,6 @@ void CreateRfidFork(void)
                             rfid.currentCard[3], rfid.currentCard[2],
                             rfid.currentCard[1], rfid.currentCard[0]);
                     break;
-#else
-                case RFID_SN_TYPE_6BYTE:
-                    sprintf((char*)pSysConfig->UserId,
-                        "%02X%02X%02X%02X%02X%02X",
-                        rfid.currentCard[0], rfid.currentCard[1],
-                        rfid.currentCard[2], rfid.currentCard[3],
-                        rfid.currentCard[4], rfid.currentCard[5]);
-                    break;
-                case RFID_SN_TYPE_7BYTE:
-                    sprintf((char*)pSysConfig->UserId,
-                        "%02X%02X%02X%02X%02X%02X%02X",
-                        rfid.currentCard[0], rfid.currentCard[1],
-                        rfid.currentCard[2], rfid.currentCard[3],
-                        rfid.currentCard[4], rfid.currentCard[5],
-                        rfid.currentCard[6]);
-                    break;
-                case RFID_SN_TYPE_8BYTE:
-                    sprintf((char*)pSysConfig->UserId,
-                        "%02X%02X%02X%02X%02X%02X%02X%02X",
-                        rfid.currentCard[0], rfid.currentCard[1],
-                        rfid.currentCard[2], rfid.currentCard[3],
-                        rfid.currentCard[4], rfid.currentCard[5],
-                        rfid.currentCard[6], rfid.currentCard[7]);
-                    break;
-                case RFID_SN_TYPE_10BYTE:
-                    sprintf((char*)pSysConfig->UserId,
-                        "%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X",
-                        rfid.currentCard[0], rfid.currentCard[1],
-                        rfid.currentCard[2], rfid.currentCard[3],
-                        rfid.currentCard[4], rfid.currentCard[5],
-                        rfid.currentCard[6], rfid.currentCard[7],
-                        rfid.currentCard[8], rfid.currentCard[9]);
-                    break;
-                case RFID_SN_TYPE_4BYTE:
-                    sprintf((char*)pSysConfig->UserId,
-                        "%02X%02X%02X%02X",
-                        rfid.currentCard[0], rfid.currentCard[1],
-                        rfid.currentCard[2], rfid.currentCard[3]);
-                    break;
-#endif
                 }
             }
             log_info("card number = %s", pSysConfig->UserId);

+ 16 - 8
EVSE/Projects/DD360/Apps/CSU/main.c

@@ -85,8 +85,8 @@ uint8_t bd0_2_status = 0;
 uint8_t bd1_1_status = 0;
 uint8_t bd1_2_status = 0;
 
-char *fwVersion = "T1.23.00.0000.00"; // "V0.16.00.0000.00";
-char* DebugVersion = "T1.23.3";
+char *fwVersion = "V1.23.00.0000.00"; // "V0.16.00.0000.00";
+char* DebugVersion = "V1.23.5";
 //sqlite3 *localDb;
 bool isDb_ready;
 
@@ -1488,6 +1488,8 @@ bool isEvBoardNormalStopChargeFlag(uint8_t gunIndex)
 //===============================================
 void ClearDetectPluginFlag(int gunIndex)
 {
+    if (pSysConfig->TotalConnectorCount == 1 && gunIndex == RIGHT_GUN_NUM)
+        return;
 
     ShmDcCommonData->pGunInfo[gunIndex].WaitForPlugit = NO;
     //DS60-120 add
@@ -1507,12 +1509,16 @@ void ClearDetectPluginFlag(int gunIndex)
 void DetectPluginStart(int gunIndex)
 {
     //pSysInfo->WaitForPlugit = YES;
+    if (pSysConfig->TotalConnectorCount == 1 && gunIndex == RIGHT_GUN_NUM)
+        return;
     ShmDcCommonData->pGunInfo[gunIndex].WaitForPlugit = YES;
     log_info("Gun%d start detect plug in",gunIndex);
 }
 
 bool isDetectPlugin(int gunIndex)
 {
+    if (pSysConfig->TotalConnectorCount == 1 && gunIndex == RIGHT_GUN_NUM)
+        return false;
     if (ShmDcCommonData->pGunInfo[gunIndex].WaitForPlugit == YES) {
         return true;
     }
@@ -1683,9 +1689,11 @@ void _AutoReturnTimeout(int gunIndex)
             pDcChargingInfo = (struct ChargingInfoData*)GetDcChargingInfoData(LEFT_GUN_NUM);
             if (pDcChargingInfo->SystemStatus == S_IDLE || pDcChargingInfo->SystemStatus == S_RESERVATION)
                 DetectPluginStart(LEFT_GUN_NUM);
-            pDcChargingInfo = (struct ChargingInfoData*)GetDcChargingInfoData(RIGHT_GUN_NUM);
-            if (pDcChargingInfo->SystemStatus == S_IDLE || pDcChargingInfo->SystemStatus == S_RESERVATION)
-                DetectPluginStart(RIGHT_GUN_NUM);
+            if (pSysConfig->TotalConnectorCount > 1) {
+                pDcChargingInfo = (struct ChargingInfoData*)GetDcChargingInfoData(RIGHT_GUN_NUM);
+                if (pDcChargingInfo->SystemStatus == S_IDLE || pDcChargingInfo->SystemStatus == S_RESERVATION)
+                    DetectPluginStart(RIGHT_GUN_NUM);
+            }
         }
     }
 
@@ -2840,9 +2848,9 @@ void StartGunInfoTimeoutDet(uint8_t gunIndex, uint8_t flag)
 
 void StopGunInfoTimeoutDet(uint8_t gunIndex)
 {
-    pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
 
     if (gunIndex < pSysConfig->TotalConnectorCount) {
+        pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
         pDcChargingInfo->TimeoutFlag = Timeout_None;
     }
 }
@@ -4742,7 +4750,7 @@ int main(void)
 
     time_t ShowEVStatusTimer[2] = { 0 };
 
-    SetGunTypeOTPValue();
+    //SetGunTypeOTPValue();
 
     for (;;) {
 
@@ -5073,7 +5081,7 @@ int main(void)
 
                 if (ShmPsuData->SystemPresentPsuQuantity > 0 &&
                         ShmPsuData->SystemAvailablePower > 10 &&
-                        GetTimeoutValue(pDcChargingInfo->TimeoutTimer) >= 1000000) {
+                        GetTimeoutValue(pDcChargingInfo->TimeoutTimer) >= 3000000) {
                     setChargerMode(gunIndex, MODE_PREPARE_FOR_EV);
                 }
 

+ 135 - 10
EVSE/Projects/DD360/Apps/Define/define.h

@@ -610,7 +610,8 @@ struct SysConfigData
     unsigned char           MaintainServerSecurityPassword[41]; // Maintain server AuthorizationKey for security profile
     unsigned char           PowerSharingServerIP[512];          // Local power sharing server ip address
     unsigned int            PowerSharingCapacityPower;          // Local power sharing capacity power
-    unsigned char           MaxChargingSoc;                     //0: unlimit, 1 ~ 100 percent
+    unsigned char           MaxChargingSoc;                     // 0: unlimit, 1 ~ 100 percent
+    unsigned char			FanControlPolicy;					// 0: Auto mode		1: Quite mode
 };
 
 struct DERATING_BY_OTP
@@ -925,12 +926,126 @@ typedef union
 
 struct DC_METER_INFO
 {
-    double presetVoltage;                       // resolution: 1.000v
-    double presentCurrent;                      // resolution: 1.000a
-    double presentPower;                        // resolution: 1.000kw
-    double totlizeImportEnergy;                 // resolution: 1.000kwh
-    double totlizeExportEnergy;                 // resolution: 1.000kwh
-    unsigned char LinkStatus;                   // 0 = unknow ,1 = link , 2 miss link
+    double presetVoltage;						// resolution: 1.000v
+	double presentCurrent;					// resolution: 1.000a
+	double presentPower;						// resolution: 1.000kw
+	double totlizeImportEnergy;			// resolution: 1.000kwh
+	double totlizeExportEnergy;			// resolution: 1.000kwh
+	unsigned char timestamp[32];
+	unsigned char LinkStatus;								// 0 = unknow ,1 = link , 2 miss link
+};
+
+typedef union
+{
+		unsigned char Status;
+        struct
+        {
+	    			unsigned char suLinkStatusIsOk:1;
+            unsigned char muFatalErrorOccured:1;
+            unsigned char transactionIsOnGoing:1;
+            unsigned char tamperingIsDetected:1;
+            unsigned char timeSyncStatusIsOk:1;
+            unsigned char overTemperatureIsDetected:1;
+            unsigned char reversedVoltage:1;
+            unsigned char suMeasureFailureOccurred:1;
+        }bits;
+        
+}DcmbStatusFlag;
+
+typedef union
+{
+        unsigned char Errors;
+        struct
+        {
+            unsigned char muInitIsFailed:1;
+            unsigned char suStateIsInvalid:1;
+            unsigned char versionCheckIsFailed:1;
+            unsigned char muRngInitIsFailed:1;
+            unsigned char muDataIntegrityIsFailed:1;
+            unsigned char muFwIntegrityIsFailed:1;
+            unsigned char suIntegrityIsFailed:1;
+            unsigned char logbookIntegrityIsFailed:1;
+            unsigned char logbookIsFull:1;
+            unsigned char memoryAccessIsFailed:1;
+            unsigned char muStateIsFailed:1;
+            unsigned char res:5;
+        }bits;
+        
+}DcmbErrorFlag;
+   
+struct DC_METER_STATUS_INFO
+{
+	unsigned short StatusValue;
+	DcmbStatusFlag MeterStatusFlag;
+    
+	unsigned char applicationFirmwareVersion[16];
+    unsigned char applicationFirmwareAuthTag[32];
+    unsigned char legalFirmwareVersion[16];
+    unsigned char legalFirmwareAuthTag[32];
+    unsigned char sensorFirmwareVersion[16];
+    unsigned char sensorFirmwareCrc[4];
+
+    unsigned char Systime[32];
+    unsigned char ipAddress[32];
+    unsigned char meterId[32];
+
+	unsigned short ErrorValue;
+ 	DcmbErrorFlag MeterErrorFlag;
+   
+    unsigned char publicKey[140];
+    unsigned char publicKeyOcmf[200];
+    unsigned short indexOfLastTransaction;
+    unsigned short numberOfStoredTransactions;
+};
+
+struct DC_METER_TRANSACTION_HEAD
+{
+    unsigned char evseId[32];
+    unsigned char transactionId[32];
+    unsigned char clientId[32];
+    unsigned short tariffId;
+    unsigned short cableId;
+    unsigned short userData[32];
+    
+};
+
+struct DC_METER_TRANSACTION_ACTION
+{
+	struct DC_METER_TRANSACTION_HEAD head;
+	unsigned char transactionOCMF[512];
+	unsigned char OcmfInfoReady;                // 0 = nothing, 1 = ocmp info ready
+	unsigned char ActionCmd;                   // 1 = transaction Start, 2 transaction Stop, sync time
+};
+
+typedef union
+{
+				unsigned char Status;
+        struct
+        {
+	    			unsigned char intermediateRead:1;
+            unsigned char res:7;
+        }bits;
+        
+}DcmbTransactionReadlevel;
+
+struct DC_METER_TRANSACTION_RESULT
+{
+	unsigned short paginationCounter;
+	struct DC_METER_TRANSACTION_HEAD head;
+    unsigned char timestampStart[32];
+    unsigned char timestampStop[32];
+    unsigned int transactionDuration;
+    DcmbTransactionReadlevel intermediateRead;
+    unsigned int  transactionStatus;
+    unsigned char energyUnit[8];
+    double energyImport;
+    double energyImportTotalStart;
+    double energyImportTotalStop;
+    double energyExport;
+    double energyExportTotalStart;
+    double energyExportTotalStop;
+    unsigned char signature[140];
+    //unsigned char transactionOCMF[512];
 };
 
 typedef struct Bazel8Command
@@ -1081,6 +1196,10 @@ struct SysInfoData
     CabinetSettingFlag      CabinetSetting;
     struct LocalSharingInfo localSharingInfo;           // Local power sharing info structure
     struct DC_METER_INFO    DcMeterInfo[4];
+    struct DC_METER_STATUS_INFO DcMeterStatusInfo[4];
+    struct DC_METER_TRANSACTION_ACTION DcMeterReadTransactionRecord[4];
+    struct DC_METER_TRANSACTION_ACTION DcMeterTransactionAction[4];
+    struct DC_METER_TRANSACTION_RESULT DcMeterTransactionResult[4];
     unsigned char           OTPTemp;                    // OTP Temperature
     unsigned char           OTPTempR;                   // OTP Recovery Temperature
     struct LCD_OVERRIDE     LcdOveride;                 // LCD override info (no use anymore)
@@ -1419,7 +1538,7 @@ char AlarmStatusCode[160][6]=
     "012340",   // reserved
     "012341",   // reserved
     "012342",   // reserved
-    "012343",   // reserved
+    "012343",   // Tilt sensor self-test failed
     "012344",   // AC: Meter IC communication timeout
     "012345",   // AC: Pilot negative error
     "012346",   // Psu Communication error with CSU
@@ -1599,7 +1718,8 @@ struct AlarmCodeData
             unsigned char PsuPhaseOvp:1;                            //bit 5
             unsigned char :2;                                       //reserved bit 6 ~ bit 7
             //AlarmVal[17]
-            unsigned char :8;                                       //reserved bit 0 ~ bit 7
+            unsigned char :7;                                       //reserved bit 0 ~ bit 6
+            unsigned char TiltSensorStestFail:1;                    //reserved bit 7
             //AlarmVal[18]
             unsigned char MeterIcCommTimeout:1;                     //bit 0
             unsigned char PilotNegativeError:1;                     //bit 1
@@ -1609,7 +1729,12 @@ struct AlarmCodeData
 			unsigned char :3;                                       //reserved bit 4 ~ bit 7
             //AlarmVal[19]
             unsigned char PaymentCommTimeout:1;                     //Payment system communication timeout
-            unsigned char :7;                                       //reserved bit 1 ~ bit 7
+           	unsigned char MeterSlaveLosLink:1;                     	//DCMB meter slave module los link
+            unsigned char MeterSyncTimeError:1;            					//DCMB meter Sync Time Error
+            unsigned char MetertStartTransactionError:1;            //DCMB meter Start Transaction Error
+            unsigned char MetertStopTransactionError:1;             //DCMB meter Stop Transaction Error
+            unsigned char MetertGetTransactionOcmfError:1;          //DCMB meter Get OCMF Error        	
+            unsigned char :2;                                       //reserved bit 1 ~ bit 7
 		}bits;
 	}AlarmEvents;
 };

+ 10 - 0
EVSE/Projects/DD360/Apps/ModuleDoComm/DoComm.c

@@ -356,11 +356,15 @@ static void ClearAuthorizedFlag(void)
 
 static void ClearDetectPluginFlag(int gunIndex)
 {
+    if (pSysConfig->TotalConnectorCount > 1 && gunIndex == RIGHT_GUN_NUM)
+        return;
     ShmDcCommonData->pGunInfo[gunIndex].WaitForPlugit = NO;
 }
 
 static bool isDetectPlugin(int gunIndex)
 {
+    if (pSysConfig->TotalConnectorCount == 1 && gunIndex == RIGHT_GUN_NUM)
+        return false;
     if (ShmDcCommonData->pGunInfo[gunIndex].WaitForPlugit == YES) {
         return true;
     }
@@ -946,6 +950,12 @@ static int miscCommandHandle(uint8_t dataLen, uint8_t plugNum, uint8_t *data)
             }
             gMoreInfoReq[plugNum].bits.ReceiptReq = YES;
             break;
+        case MISC_CMD_RFIDCARD_ENDIAN:
+            if (pSysConfig->RfidCardNumEndian != value) {
+                pSysConfig->RfidCardNumEndian = value;
+                log_info("Set RFID CARD %s endian", value ? "Little" : "Big");
+            }
+            break;
         default:
             clearMiscCommand();
             break;

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

@@ -133,6 +133,8 @@
 #define MISC_CMD_LED_INTENSITY                  (0x000E)
 #define MISC_CMD_AC_CONTACTOR                   (0x000F)
 #define MISC_CMD_TIME_OFFSET                    (0x0010)
+#define MISC_CMD_PARKING_PRICE                  (0x0011)
+#define MISC_CMD_RFIDCARD_ENDIAN                (0x0012)
 
 #define MISC_CMD_HARDWARE_REBOOT                (0x0101)
 #define MISC_CMD_SOFTWARE_RESTART               (0x0102)
@@ -148,6 +150,9 @@
 #define MISC_CMD_DEFAULT_PRICE_REQ              (0x010C)
 #define MISC_CMD_USER_PRICE_REQ                 (0x010D)
 #define MISC_CMD_RECEIPT_REQ                    (0x010E)
+#define MISC_CMD_CHARGING_BILL                  (0x010F)
+#define MISC_CMD_PARKING_PRICES                 (0x0110)
+
 
 #define ST_UPDATE_FIRMWARE                      (0x01)
 #define ST_NO_UPDATE_FIRMWARE                   (0x02)

+ 5 - 1
EVSE/Projects/DD360/Apps/ModuleEvComm/Module_EvRxComm.c

@@ -236,7 +236,11 @@ void CheckEvConnect(int gunIndex)
     struct ChargingInfoData* pDcChargingInfo = (struct ChargingInfoData*)GetDcChargingInfoData(gunIndex);
     struct InfoCodeData* pInfoCode = (struct InfoCodeData*)GetShmInfoCodeData();
     struct ChargingInfoData* pDcChargingInfo_0 = (struct ChargingInfoData*)GetDcChargingInfoData(0);
-    struct ChargingInfoData* pDcChargingInfo_1 = (struct ChargingInfoData*)GetDcChargingInfoData(1);
+    struct ChargingInfoData* pDcChargingInfo_1 = NULL;
+    if (pSysConfig->TotalConnectorCount == 1)
+        pDcChargingInfo_1 = (struct ChargingInfoData*)GetDcChargingInfoData(0);
+    else
+        pDcChargingInfo_1 = (struct ChargingInfoData*)GetDcChargingInfoData(1);
 
     if (pDcChargingInfo_0->Type == pDcChargingInfo_1->Type) {
         isSameType = TRUE;

+ 27 - 6
EVSE/Projects/DD360/Apps/ModuleEvComm/Module_EvTxComm.c

@@ -56,6 +56,7 @@ static int CanFd = -1;
 
 bool psuOutputReady[2] = {0, 0};
 uint8_t deratingIndex[2];
+bool ischillerHighTemp[2];
 //------------------------------------------------------------------------------
 extern void CANReceiver(int fd);
 extern void ClearAbnormalStatus_Chademo(uint8_t gun_index);
@@ -413,15 +414,35 @@ static void SetPresentChargingOutputCap(void)
             deratingIndex[1] = chargingData_2->deratingByConnOtp.deratingIndex;
         }
     }
+    // Chiller 錯誤或溫度降載
+    if (chargingData_1->ChillerTemp <= 70 && ShmDcCommonData->pGunInfo[0].withChiller && !ischillerHighTemp[0]) {
+        ischillerHighTemp[0] = TRUE;
+        if (cur1 > 2500) {
+            log_info("Gun0 chiller temperature(%d) too high set current less than 250A", chargingData_1->ChillerTemp);
+            cur1 = 2500;
+        }
+    } else if (chargingData_1->ChillerTemp > 75 && ischillerHighTemp[0]) {
+        cur1 = 2500;
+    }
+
+    if (chargingData_2->ChillerTemp <= 70 && ShmDcCommonData->pGunInfo[1].withChiller && !ischillerHighTemp[1]) {
+        ischillerHighTemp[1] = TRUE;
+        if (cur2 > 2500) {
+            log_info("Gun1 chiller temperature(%d) too high set current less than 250A", chargingData_2->ChillerTemp);
+            cur2 = 2500;
+        }
+    } else if (chargingData_2->ChillerTemp > 75 && ischillerHighTemp[1]) {
+        cur1 = 2500;
+    }
 
     if (ShmPrimaryMcuData->InputDet.bits.Ac_Drop == ABNORMAL) {
-        if (cur1 > 1500) {
-            log_info("Gun0 chiller alarm set current less than 150A");
-            cur1 = 1500;
+        if (cur1 > 2500) {
+            log_info("Gun0 chiller alarm set current less than 250A");
+            cur1 = 2500;
         }
-        if (cur2 > 1500) {
-            log_info("Gun1 chiller alarm set current less than 150A");
-            cur2 = 1500;
+        if (cur2 > 2500) {
+            log_info("Gun1 chiller alarm set current less than 250A");
+            cur2 = 2500;
         }
     }
     //DS60-120 add

+ 9 - 6
EVSE/Projects/DD360/Apps/ModuleInternalComm/RelayBoard.c

@@ -1253,12 +1253,14 @@ static void GetFanSpeedByFunction(void)
     struct ChargingInfoData* pDcChargingInfo = NULL;
     for (gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++) {
         pDcChargingInfo = (struct ChargingInfoData*)GetDcChargingInfoData(gunIndex);
-        if ((pDcChargingInfo->SystemStatus > S_AUTHORIZING && pDcChargingInfo->SystemStatus < S_TERMINATING) ||
-            (pDcChargingInfo->SystemStatus >= S_CCS_PRECHARGE_ST0 && pDcChargingInfo->SystemStatus <= S_CCS_PRECHARGE_ST1)) {
-            ShmDcCommonData->FanOnTime = time((time_t*)NULL);
-            if (ShmFanModuleData->SetFan1Speed == 0) {
-                ShmFanModuleData->SetFan1Speed = 7000;
-                log_info("Set Fan speed 7000");
+        if (ShmDcCommonData->pGunInfo[gunIndex].withChiller) {
+            if ((pDcChargingInfo->SystemStatus > S_AUTHORIZING && pDcChargingInfo->SystemStatus < S_TERMINATING) ||
+                (pDcChargingInfo->SystemStatus >= S_CCS_PRECHARGE_ST0 && pDcChargingInfo->SystemStatus <= S_CCS_PRECHARGE_ST1)) {
+                ShmDcCommonData->FanOnTime = time((time_t*)NULL);
+                if (ShmFanModuleData->SetFan1Speed == 0) {
+                    ShmFanModuleData->SetFan1Speed = 7000;
+                    log_info("Set Fan speed 7000");
+                }
             }
         }
     }
@@ -1267,6 +1269,7 @@ static void GetFanSpeedByFunction(void)
         ShmFanModuleData->SetFan1Speed == 7000) {
         ShmFanModuleData->SetFan1Speed = 0;
         log_info("Close fan");
+        ShmDcCommonData->FanOnTime = time((time_t*)NULL);
     }
 
     /*

+ 29 - 206
EVSE/Projects/DD360/Apps/ModulePrimary/Module_PrimaryComm.c

@@ -54,108 +54,6 @@ uint8_t Door_count = 0;
 uint8_t EmgBtn_flag = 0;
 uint8_t Door_flag = 0;
 
-//struct ChargingInfoData *ChargingData[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
-
-//------------------------------------------------------------------------------
-/*int StoreLogMsg(const char *fmt, ...)
-{
-    char Buf[4096 + 256];
-    char buffer[4096];
-    va_list args;
-    struct timeb  SeqEndTime;
-    struct tm *tm;
-
-    va_start(args, fmt);
-    int rc = vsnprintf(buffer, sizeof(buffer), fmt, args);
-    va_end(args);
-
-    memset(Buf, 0, sizeof(Buf));
-    ftime(&SeqEndTime);
-    SeqEndTime.time = time(NULL);
-    tm = localtime(&SeqEndTime.time);
-
-    if (pSysConfig->SwitchDebugFlag == YES) {
-        sprintf(Buf, "%02d:%02d:%02d:%03d - %s",
-                tm->tm_hour, tm->tm_min, tm->tm_sec, SeqEndTime.millitm, buffer);
-        printf("%s ", Buf);
-    } else {
-        sprintf(Buf, "echo \"%04d-%02d-%02d %02d:%02d:%02d:%03d - %s\" >> /Storage/SystemLog/[%04d.%02d]SystemLog",
-                tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec, SeqEndTime.millitm,
-                buffer,
-                tm->tm_year + 1900, tm->tm_mon + 1);
-        system(Buf);
-    }
-
-    return rc;
-}
-*/
-
-#if 0 //non use
-int DiffTimeb(struct timeb ST, struct timeb ET)
-{
-    //return milli-second
-    unsigned int StartTime, StopTime;
-
-    StartTime = (unsigned int)ST.time;
-    StopTime = (unsigned int)ET.time;
-    return (StopTime - StartTime) * 1000 + ET.millitm - ST.millitm;
-}
-
-//=================================
-// Common routine
-//=================================
-char *getTimeString(void)
-{
-    char *result = malloc(21);
-    time_t timep;
-    struct tm *p;
-    time(&timep);
-    p = gmtime(&timep);
-
-    sprintf(result, "[%04d-%02d-%02d %02d:%02d:%02d]",
-            (1900 + p->tm_year),
-            (1 + p->tm_mon),
-            p->tm_mday,
-            p->tm_hour,
-            p->tm_hour,
-            p->tm_sec);
-
-    return result;
-}
-#endif //0
-
-//==========================================
-// Init all share memory
-//==========================================
-/*int InitShareMemory()
-{
-    int result = PASS;
-    int MeterSMId;
-
-    //creat ShmSysConfigAndInfo
-    if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo),  0777)) < 0) {
-        result = FAIL;
-    } else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
-        result = FAIL;
-    }
-
-    //creat ShmStatusCodeData
-    if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData),  0777)) < 0) {
-        result = FAIL;
-    } else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
-        result = FAIL;
-    }
-
-    //creat ShmStatusCodeData
-    if ((MeterSMId = shmget(ShmPrimaryMcuKey, sizeof(struct PrimaryMcuData), 0777)) < 0) {
-        result = FAIL;
-    } else if ((ShmPrimaryMcuData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
-        result = FAIL;
-    }
-
-    return result;
-}
-*/
 
 //================================================
 // Function
@@ -186,7 +84,8 @@ void GetInputGpioStatus(int fd)
     }
 
     ShmPrimaryMcuData->InputDet.bits.SpdDetec = gpio_in.SPD;
-    ShmPrimaryMcuData->InputDet.bits.Ac_Drop = ~gpio_in.AC_Drop; // Chiller Alarm ping
+    //log_info("gpio_in.AC_Drop:%d", gpio_in.AC_Drop);
+    ShmPrimaryMcuData->InputDet.bits.Ac_Drop = gpio_in.AC_Drop; // Chiller Alarm ping
 
 #ifdef DD360ComBox
     EmgBtn_flag = 0;
@@ -226,7 +125,7 @@ void GetInputGpioStatus(int fd)
     ShmPrimaryMcuData->InputDet.bits.Button1 = gpio_in.Button[0];
     ShmPrimaryMcuData->InputDet.bits.Button2 = gpio_in.Button[1];
 
-#if defined DD360 || defined DD360Audi || defined DD360ComBox
+//#if defined DD360 || defined DD360Audi || defined DD360ComBox
     if ((strncmp((char *)&pSysConfig->ModelName[7], "V", 1) == 0) ||
             (strncmp((char *)&pSysConfig->ModelName[9], "V", 1) == 0) ||
             (strncmp((char *)&pSysConfig->ModelName[7], "F", 1) == 0) ||
@@ -288,56 +187,8 @@ void GetInputGpioStatus(int fd)
     ShmPrimaryMcuData->InputDet.bits.Key3 = ~gpio_in.Key[3] & 0x01;
 
     return;
-#endif //defined DD360 || defined DD360Audi || defined DD360ComBox
-
-    static uint8_t _curDeviceStatus[3] = {0};
-    static uint8_t _reCheckCount[3] = {0};
-
-    //DS60-120 add
-    if (_curDeviceStatus[_PRIMARY_CHECK_TAG_AC_CONTACT] != gpio_in.AC_Connector) {
-        if (_reCheckCount[_PRIMARY_CHECK_TAG_AC_CONTACT] >= 3) {
-            _curDeviceStatus[_PRIMARY_CHECK_TAG_AC_CONTACT] = gpio_in.AC_Connector;
-            pSysInfo->AcContactorStatus =
-                ShmPrimaryMcuData->InputDet.bits.AcContactorDetec =
-                    gpio_in.AC_Connector;
-        } else {
-            _reCheckCount[_PRIMARY_CHECK_TAG_AC_CONTACT]++;
-        }
-    } else {
-        _reCheckCount[_PRIMARY_CHECK_TAG_AC_CONTACT] = 0;
-    }
 
-    if (_curDeviceStatus[_PRIMARY_CHECK_TAG_MAIN_BREAKER] != gpio_in.AC_MainBreaker) {
-        if (_reCheckCount[_PRIMARY_CHECK_TAG_MAIN_BREAKER] >= 3) {
-            _curDeviceStatus[_PRIMARY_CHECK_TAG_MAIN_BREAKER] = gpio_in.AC_MainBreaker;
-            ShmPrimaryMcuData->InputDet.bits.AcMainBreakerDetec = gpio_in.AC_MainBreaker;
-        } else {
-            _reCheckCount[_PRIMARY_CHECK_TAG_MAIN_BREAKER]++;
-        }
-    } else {
-        _reCheckCount[_PRIMARY_CHECK_TAG_MAIN_BREAKER] = 0;
-    }
-    //pSysInfo->AcContactorStatus = ShmPrimaryMcuData->InputDet.bits.AcContactorDetec = gpio_in.AC_Connector;
-    //ShmPrimaryMcuData->InputDet.bits.AcMainBreakerDetec = gpio_in.AC_MainBreaker;
-
-    ShmPrimaryMcuData->InputDet.bits.Key0 = gpio_in.Key[0] & 0x01;
-    ShmPrimaryMcuData->InputDet.bits.Key1 = gpio_in.Key[1] & 0x01;
-    ShmPrimaryMcuData->InputDet.bits.Key2 = gpio_in.Key[2] & 0x01;
-    ShmPrimaryMcuData->InputDet.bits.Key3 = gpio_in.Key[3] & 0x01;
-    ShmPrimaryMcuData->InputDet.bits.DoorOpen = gpio_in.Door_Open;
-
-    /*printf(" gpio_in.Key[0]~ gpio_in.Key[3]=%d, %d, %d, %d",
-    ShmPrimaryMcuData->InputDet.bits.Key0 , ShmPrimaryMcuData->InputDet.bits.Key1,
-    ShmPrimaryMcuData->InputDet.bits.Key2,ShmPrimaryMcuData->InputDet.bits.Key3);
-    printf("pAlarmCode->AlarmEvents.bits.CcsLiquidChillerWaterLevelWarning=%d", pAlarmCode->AlarmEvents.bits.CcsLiquidChillerWaterLevelWarning);
-    printf("pFaultCode->FaultEvents.bits.CcsLiquidChillerWaterLevelFault=%d", pFaultCode->FaultEvents.bits.CcsLiquidChillerWaterLevelFault);
-    */
-    //log_info("left = %d ", ShmPrimaryMcuData->InputDet.bits.Button1);
-    //log_info("right = %d ", ShmPrimaryMcuData->InputDet.bits.Button2);
-    //log_info("pSysInfo->AcContactorStatus = %d ", pSysInfo->AcContactorStatus);
-    if (ShmPrimaryMcuData->InputDet.bits.AcMainBreakerDetec == YES) {
-        log_error("AC Mainbreaker occur. ");
-    }
+
 }
 
 static void checkChillerStatus(Gpio_out *gpio)
@@ -347,17 +198,18 @@ static void checkChillerStatus(Gpio_out *gpio)
     struct ChargingInfoData *pDcChargingInfo = NULL;
     static ChillerInfo fChillerInfo[2] = {0}, *pChillerInfo = NULL;
     static ChillerInfo _chiller;
-    struct FanModuleData* ShmFanModuleData = (struct FanModuleData*)GetShmFanModuleData();;
+    struct FanModuleData* ShmFanModuleData = (struct FanModuleData*)GetShmFanModuleData();
+    DcCommonInfo* ShmDcCommonData = (DcCommonInfo*)GetShmDcCommonData();
     Gpio_out *pGpio = (Gpio_out *)gpio;
 
-    if ((strncmp((char *)&pSysConfig->ModelName[7], "V", 1) == 0) ||
-            (strncmp((char *)&pSysConfig->ModelName[7], "F", 1) == 0)) {
+    if ((strncmp((char*)&pSysConfig->ModelName[7], "V", 1) == 0) ||
+        (strncmp((char*)&pSysConfig->ModelName[7], "F", 1) == 0)) {
         chillerCount++;
         ShmDcCommonData->pGunInfo[0].withChiller = TRUE;
     }
 
-    if ((strncmp((char *)&pSysConfig->ModelName[9], "V", 1) == 0) ||
-            (strncmp((char *)&pSysConfig->ModelName[9], "F", 1) == 0)) {
+    if ((strncmp((char*)&pSysConfig->ModelName[9], "V", 1) == 0) ||
+        (strncmp((char*)&pSysConfig->ModelName[9], "F", 1) == 0)) {
         chillerCount++;
         ShmDcCommonData->pGunInfo[1].withChiller = TRUE;
     }
@@ -382,28 +234,30 @@ static void checkChillerStatus(Gpio_out *gpio)
                 //10分鐘後停止
                 if ((time((time_t *)NULL) - pChillerInfo->ChillerOnTime) >= 600) {
                     pChillerInfo->ChillerSwitch = NO;
+                    ShmDcCommonData->FanOnTime = time((time_t*)NULL);
                 }
             } else {
                 pChillerInfo->ChillerSwitch = NO;
+                ShmFanModuleData->SetFan1Speed = 0;
             }
         }
         // 檢查Chiller溫度點,若小於零下時開啟heater,大於10度時關閉heater
-        if (pDcChargingInfo->ChillerTemp < 60) {
+        if (pDcChargingInfo->ChillerTemp < 70) {
             pGpio->AC_Breaker = YES;
-        } else if(pDcChargingInfo->ChillerTemp > 70) {
+        } else if(pDcChargingInfo->ChillerTemp > 75) {
             pGpio->AC_Breaker = NO;
         }
-        //log_info("Set Heater %s", pGpio->AC_Breaker ? "ON" : "OFF");
+        //log_info("Gun%d Set Heater %s", gunIndex, pGpio->AC_Breaker ? "ON" : "OFF");
     }
     uint8_t _chillerNeedOn = NO;
     for (gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++)
     {
-        pChillerInfo = (ChillerInfo *)&fChillerInfo[gunIndex];
-        if(pChillerInfo->ChillerSwitch == YES) {
+        pChillerInfo = (ChillerInfo*)&fChillerInfo[gunIndex];
+        if (pChillerInfo->ChillerSwitch == YES) {
             _chillerNeedOn = YES;
+            ShmFanModuleData->SetFan1Speed = 7000;
         }
     }
-
     /*
     if (ShmDcCommonData->debugflag == YES)
         _chillerNeedOn = ShmDcCommonData->chillerCtrl;
@@ -451,7 +305,7 @@ void SetOutputGpio(int fd, uint8_t outputValue)
 
     checkChillerStatus(&gpio);
 
-    //gpio.AC_Breaker = 0x00;
+    //gpio.AC_Breaker = 0x01;
 
     Config_Gpio_Output(fd, OP_ADDR_IO_EXTEND, &gpio);
 }
@@ -541,48 +395,17 @@ 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;
 }
+unsigned long GetClockTimeoutValue(struct timespec _start_time)
+{
+    struct timespec ts_end;
+    unsigned long ret = 0;
+
+    clock_gettime(CLOCK_MONOTONIC, &ts_end);
 
-//int FindChargingInfoData(uint8_t target, struct ChargingInfoData **chargingData)
-//{
-//    for (uint8_t index = 0; index < CHAdeMO_QUANTITY; index++) {
-//        if (pSysInfo->ChademoChargingData[index].Index == target) {
-//            chargingData[target] = &pSysInfo->ChademoChargingData[index];
-//            return 1;
-//        }
-//    }
-//
-//    for (uint8_t index = 0; index < CCS_QUANTITY; index++) {
-//        if (pSysInfo->CcsChargingData[index].Index == target) {
-//            chargingData[target] = &pSysInfo->CcsChargingData[index];
-//            return 1;
-//        }
-//    }
-//
-//    for (uint8_t index = 0; index < GB_QUANTITY; index++) {
-//        if (pSysInfo->GbChargingData[index].Index == target) {
-//            chargingData[target] = &pSysInfo->GbChargingData[index];
-//            return 1;
-//        }
-//    }
-//
-//    return 0;
-//}
-
-//void Initialization() //DS60-120 add
-//{
-//    bool isPass = false;
-//    while (!isPass) {
-//        isPass = true;
-//        for (uint8_t _index = 0; _index < gun_count; _index++) {
-//            if (!FindChargingInfoData(_index, &ChargingData[0])) {
-//                log_error("EvComm (main) : FindChargingInfoData false ");
-//                isPass = false;
-//                break;
-//            }
-//        }
-//        sleep(1);
-//    }
-//}
+    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;
+}
 
 static bool IsPrimaryProcessNeedPause(void)
 {

+ 2 - 1
EVSE/Projects/DD360/Apps/ModulePrimary/PrimaryComm.c

@@ -117,6 +117,7 @@ int Query_Gpio_Input(uint8_t fd, uint8_t targetAddr, Gpio_in *Ret_Buf)
                 (rx[2] == tx[1]) &&
                 (rx[1] == tx[2]) &&
                 (rx[3] == tx[3])) {
+            //log_info("rx[6]:0x%x,rx[7]:0x%x", rx[6], rx[7]);
             Ret_Buf->AC_Connector       = (rx[6] >> 0) & 0x01;
             Ret_Buf->AC_MainBreaker     = (rx[6] >> 1) & 0x01;
             Ret_Buf->SPD                = (rx[6] >> 2) & 0x01;
@@ -124,7 +125,7 @@ int Query_Gpio_Input(uint8_t fd, uint8_t targetAddr, Gpio_in *Ret_Buf)
             Ret_Buf->GFD[0]             = (rx[6] >> 4) & 0x01;
             Ret_Buf->GFD[1]             = (rx[6] >> 5) & 0x01;
             Ret_Buf->AC_Drop            = (rx[6] >> 6) & 0x01;
-            Ret_Buf->Emergency_IO       = (rx[6] >> 7) & 0x01;
+            Ret_Buf->Emergency_IO       = (rx[6] >> 7) & 0x01; 
 
             Ret_Buf->Emergency_Btn      = (rx[7] >> 0) & 0x01;
             Ret_Buf->Button[0]          = (rx[7] >> 1) & 0x01;

+ 38 - 25
EVSE/Projects/DD360/Apps/ReadCmdline.c

@@ -774,23 +774,6 @@ void GetOtpPwrOrCurMethod(struct ChargingInfoData* chargingData, float* pow, flo
             chargingData->deratingByConnOtp.deratingIndex = 2;
         }
     }
-    /*
-    if (((chargingData->ConnectorTemp >= STAGE1_GUN_DERATING_TEMP &&
-        chargingData->ConnectorTemp < STAGE2_GUN_DERATING_TEMP) ||
-        (chargingData->ChillerTemp >= STAGE1_GUN_DERATING_TEMP &&
-            chargingData->ChillerTemp < STAGE2_GUN_DERATING_TEMP)) &&
-        chargingData->deratingByConnOtp.deratingIndex < 1)
-    {
-        chargingData->deratingByConnOtp.deratingIndex = 1;
-    } else if ((chargingData->ConnectorTemp >= STAGE2_GUN_DERATING_TEMP ||
-        chargingData->ChillerTemp >= STAGE2_GUN_DERATING_TEMP) &&
-        chargingData->ConnectorTemp != UNDEFINED_TEMP &&
-        chargingData->ChillerTemp != UNDEFINED_TEMP &&
-        chargingData->deratingByConnOtp.deratingIndex < 2)
-    {
-        chargingData->deratingByConnOtp.deratingIndex = 2;
-    }
-    */
     if (chargingData->deratingByConnOtp.deratingTargetRate[chargingData->deratingByConnOtp.deratingIndex] != 0)
     {
         *pow *= chargingData->deratingByConnOtp.deratingTargetRate[chargingData->deratingByConnOtp.deratingIndex];
@@ -863,6 +846,7 @@ void RunUnconditionalChargeIndex1(char *v1, char *v2, char *v3)
         case S_IDLE:
             if (PreviousSystemStatus[curGun] != pDcChargingInfo->SystemStatus) {
                 PreviousSystemStatus[curGun] = pDcChargingInfo->SystemStatus;
+                sleep(3);
 #if defined DD360Audi
                 setConfirmSelGun(curGun);
 #endif //defined DD360Audi
@@ -1026,11 +1010,35 @@ void RunUnconditionalChargeIndex1(char *v1, char *v2, char *v3)
             //ev task do this
             for (idx = 0; idx < pSysConfig->TotalConnectorCount; idx++) {
                 struct ChargingInfoData* pInfo = (struct ChargingInfoData*)GetDcChargingInfoData(idx);
+                if (!ShmDcCommonData->TestTemperature)
+                    getChillerTemperature(pInfo);
+                // 低溫保護
+                if ((strncmp((char*)&pSysConfig->ModelName[7 + idx * 2], "V", 1) == 0) ||
+                    (strncmp((char*)&pSysConfig->ModelName[7 + idx * 2], "F", 1) == 0)) {
+                    if ((ShmDcCommonData->SystemTemp[idx * 2] <= 70 ||
+                        ShmDcCommonData->SystemTemp[idx * 2 + 1] <= 70)) {
+                        if (pInfo->EvBatterytargetCurrent > 250) {
+                            pInfo->EvBatterytargetCurrent = 250;
+                            printf("Chiller%d temperature(%d %d) too low limit target Current under 250A\n", idx, ShmDcCommonData->SystemTemp[idx * 2],
+                                ShmDcCommonData->SystemTemp[idx * 2 + 1]);
+                        }
+                    } else if ((ShmDcCommonData->SystemTemp[idx * 2] >= 80 ||
+                        ShmDcCommonData->SystemTemp[idx * 2 + 1] >= 80) && pInfo->EvBatterytargetCurrent != _Current) {
+                        pInfo->EvBatterytargetCurrent = _Current;
+                        printf("Chiller%d temperature(%d %d) recovery target Current set %.2fA\n", idx, ShmDcCommonData->SystemTemp[idx * 2],
+                            ShmDcCommonData->SystemTemp[idx * 2 + 1], pInfo->EvBatterytargetCurrent);
+                    }
+                    if (ShmPrimaryMcuData->InputDet.bits.Ac_Drop == ABNORMAL) {
+                        if (pInfo->EvBatterytargetCurrent > 250) {
+                            pInfo->EvBatterytargetCurrent = 250;
+                            printf("Chiller alarm limit target Current under 250A\n");
+                        }
+                    }
+                }
+                // 高溫保護
                 if (pInfo->deratingByConnOtp.isNeedDerating) {
                     deratingCurrent = pInfo->EvBatterytargetCurrent;
                     deratingPower = pInfo->AvailableChargingPower;
-
-                    getChillerTemperature(pInfo);
                     GetOtpPwrOrCurMethod(pInfo, &deratingPower, &deratingCurrent);
                     if (derating_index != pDcChargingInfo->deratingByConnOtp.deratingIndex) {
                         printf("Change Derating Index:%d\n", pInfo->deratingByConnOtp.deratingIndex);
@@ -1043,14 +1051,17 @@ void RunUnconditionalChargeIndex1(char *v1, char *v2, char *v3)
                         printf("Derating Current:%.3f Power:%.3f\n", pInfo->EvBatterytargetCurrent, pInfo->AvailableChargingPower);
                     }
                 }
-                if (ShmPrimaryMcuData->InputDet.bits.Ac_Drop == ABNORMAL) {
-                    if (pInfo->EvBatterytargetCurrent > 1500) {
-                        pInfo->EvBatterytargetCurrent = 1500;
-                        printf("Chiller alarm limit target Current under 150A");
-                    }
-                }
+
+
             } // for
 
+            // 水冷槍低溫保護
+            if ((strncmp((char*)&pSysConfig->ModelName[7 + curGun * 2], "V", 1) == 0) ||
+                (strncmp((char*)&pSysConfig->ModelName[7 + curGun * 2], "F", 1) == 0)) {
+
+            }
+            
+
             pDcChargingInfo->PresentChargingPower =
                 ((float)((pDcChargingInfo->PresentChargingVoltage) *
                          (pDcChargingInfo->PresentChargingCurrent)) / 1000);
@@ -1070,8 +1081,10 @@ void RunUnconditionalChargeIndex1(char *v1, char *v2, char *v3)
                 //無阻塞偵測 keybaord 結束
                 system(STTY_DEF TTY_PATH);
             }
+            sleep(1);
             pDcChargingInfo->ConnectorPlugIn = 0;
             pDcChargingInfo->SystemStatus = S_COMPLETE;
+
             break;
 
         case S_COMPLETE:

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


BIN
EVSE/Projects/DD360/output/FactoryConfig


BIN
EVSE/Projects/DD360/output/Module_ChkSysTask


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/Module_UpdateFW


BIN
EVSE/Projects/DD360/output/ReadCmdline


BIN
EVSE/Projects/DD360/output/main


+ 1 - 1
EVSE/Projects/DD360Audi/Apps/CSU/Ethernet.c

@@ -186,7 +186,7 @@ void InitEthernet(void)
     log_info("%s",tmpbuf);
     system(tmpbuf);
 
-    system("/sbin/ifconfig lo up");
+    //system("/sbin/ifconfig lo up");
 
     //Run DHCP client if enabled
     system("killall udhcpc");

+ 1 - 1
EVSE/Projects/DD360Audi/Apps/CSU/Primary.c

@@ -59,7 +59,7 @@ void PrimaryLedIndicatorCtrlFork(void)
     if (pid == 0) {
         uint8_t gunIndex = 0;
         int isContinue = 1;
-
+        log_info("Primary Fork Child's PID is %d", getpid());
         struct SysConfigData *pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
         struct SysInfoData *pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
         struct WARNING_CODE_INFO *pSysWarning = (struct WARNING_CODE_INFO *)GetShmSysWarningInfo();

+ 3 - 87
EVSE/Projects/DD360Audi/Apps/CSU/RFID.c

@@ -278,18 +278,16 @@ void ScannerCardProcess(void)
         UserScanFunction();
     }
 
-    if (pSysInfo->SystemPage == _LCM_AUTHORIZING) {
+    if (pSysInfo->PageIndex == _LCM_AUTHORIZING) {
         if(!isAuthorizedComplete())
             StartSystemTimeoutDet(Timeout_Authorizing);
 
         //printf("isAuthorizedComplete = %d, %f", isAuthorizedComplete(), ShmSelectGunInfo->PricesInfo[pSysInfo->CurGunSelected].Balance);
         // 確認驗證卡號完成沒
         if (isAuthorizedComplete()
-            /*
 #if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
                 || pSysConfig->OfflinePolicy == _OFFLINE_POLICY_FREE_CHARGING
 #endif //!defined DD360 && !defined DD360Audi && !defined DD360ComBox
-*/
            ) {
                 //StopSystemTimeoutDet();
                 StartSystemTimeoutDet(Timeout_WaitBalance);
@@ -307,14 +305,14 @@ void ScannerCardProcess(void)
                 }
 
             } ClearAuthorizedFlag();
-        } /*else if (pSysConfig->OfflinePolicy == _OFFLINE_POLICY_LOCAL_LIST) {
+        }/* else if (pSysConfig->OfflinePolicy == _OFFLINE_POLICY_LOCAL_LIST) {
             // 白名單驗證
             for (i = 0; i < 10; i++) {
                 if (strcmp((char *)pSysConfig->LocalWhiteCard[i], "") == EQUAL) {
                     continue;
                 }
+
                 if (strcmp((char *)pSysConfig->LocalWhiteCard[i], (char *)pSysConfig->UserId) == EQUAL) {
-                    log_info("Local White Card [%d]:%s", i, pSysConfig->LocalWhiteCard[i]);
                     pSysInfo->SystemPage = _LCM_AUTHORIZ_COMP;
                     ClearAuthorizedFlag();
                     break;
@@ -395,7 +393,6 @@ void CreateRfidFork(void)
 
             if (pSysConfig->RfidCardNumEndian == RFID_ENDIAN_LITTLE) {
                 switch (rfid.snType) {
-#ifdef DD360Audi
                 case RFID_SN_TYPE_6BYTE:
                     sprintf((char *) pSysConfig->UserId,
                             "%02X%02X%02X%02X%02X%02X",
@@ -426,50 +423,9 @@ void CreateRfidFork(void)
                             rfid.currentCard[0], rfid.currentCard[1],
                             rfid.currentCard[2], rfid.currentCard[3]);
                     break;
-#else
-                case RFID_SN_TYPE_6BYTE:
-                    sprintf((char*)pSysConfig->UserId,
-                        "%02X%02X%02X%02X%02X%02X",
-                        rfid.currentCard[5], rfid.currentCard[4],
-                        rfid.currentCard[3], rfid.currentCard[2],
-                        rfid.currentCard[1], rfid.currentCard[0]);
-                    break;
-                case RFID_SN_TYPE_7BYTE:
-                    sprintf((char*)pSysConfig->UserId,
-                        "%02X%02X%02X%02X%02X%02X%02X",
-                        rfid.currentCard[6], rfid.currentCard[5],
-                        rfid.currentCard[4], rfid.currentCard[3],
-                        rfid.currentCard[2], rfid.currentCard[1],
-                        rfid.currentCard[0]);
-                    break;
-                case RFID_SN_TYPE_8BYTE:
-                    sprintf((char*)pSysConfig->UserId,
-                        "%02X%02X%02X%02X%02X%02X%02X%02X",
-                        rfid.currentCard[7], rfid.currentCard[6],
-                        rfid.currentCard[5], rfid.currentCard[4],
-                        rfid.currentCard[3], rfid.currentCard[2],
-                        rfid.currentCard[1], rfid.currentCard[0]);
-                    break;
-                case RFID_SN_TYPE_10BYTE:
-                    sprintf((char*)pSysConfig->UserId,
-                        "%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X",
-                        rfid.currentCard[9], rfid.currentCard[8],
-                        rfid.currentCard[7], rfid.currentCard[6],
-                        rfid.currentCard[5], rfid.currentCard[4],
-                        rfid.currentCard[3], rfid.currentCard[2],
-                        rfid.currentCard[1], rfid.currentCard[0]);
-                    break;
-                case RFID_SN_TYPE_4BYTE:
-                    sprintf((char*)pSysConfig->UserId,
-                        "%02X%02X%02X%02X",
-                        rfid.currentCard[3], rfid.currentCard[2],
-                        rfid.currentCard[1], rfid.currentCard[0]);
-                    break;
-#endif
                 }
             } else if (pSysConfig->RfidCardNumEndian == RFID_ENDIAN_BIG) {
                 switch (rfid.snType) {
-#ifdef DD360Audi
                 case RFID_SN_TYPE_6BYTE:
                     sprintf((char *) pSysConfig->UserId,
                             "%02X%02X%02X%02X%02X%02X",
@@ -500,46 +456,6 @@ void CreateRfidFork(void)
                             rfid.currentCard[3], rfid.currentCard[2],
                             rfid.currentCard[1], rfid.currentCard[0]);
                     break;
-#else
-                case RFID_SN_TYPE_6BYTE:
-                    sprintf((char*)pSysConfig->UserId,
-                        "%02X%02X%02X%02X%02X%02X",
-                        rfid.currentCard[0], rfid.currentCard[1],
-                        rfid.currentCard[2], rfid.currentCard[3],
-                        rfid.currentCard[4], rfid.currentCard[5]);
-                    break;
-                case RFID_SN_TYPE_7BYTE:
-                    sprintf((char*)pSysConfig->UserId,
-                        "%02X%02X%02X%02X%02X%02X%02X",
-                        rfid.currentCard[0], rfid.currentCard[1],
-                        rfid.currentCard[2], rfid.currentCard[3],
-                        rfid.currentCard[4], rfid.currentCard[5],
-                        rfid.currentCard[6]);
-                    break;
-                case RFID_SN_TYPE_8BYTE:
-                    sprintf((char*)pSysConfig->UserId,
-                        "%02X%02X%02X%02X%02X%02X%02X%02X",
-                        rfid.currentCard[0], rfid.currentCard[1],
-                        rfid.currentCard[2], rfid.currentCard[3],
-                        rfid.currentCard[4], rfid.currentCard[5],
-                        rfid.currentCard[6], rfid.currentCard[7]);
-                    break;
-                case RFID_SN_TYPE_10BYTE:
-                    sprintf((char*)pSysConfig->UserId,
-                        "%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X",
-                        rfid.currentCard[0], rfid.currentCard[1],
-                        rfid.currentCard[2], rfid.currentCard[3],
-                        rfid.currentCard[4], rfid.currentCard[5],
-                        rfid.currentCard[6], rfid.currentCard[7],
-                        rfid.currentCard[8], rfid.currentCard[9]);
-                    break;
-                case RFID_SN_TYPE_4BYTE:
-                    sprintf((char*)pSysConfig->UserId,
-                        "%02X%02X%02X%02X",
-                        rfid.currentCard[0], rfid.currentCard[1],
-                        rfid.currentCard[2], rfid.currentCard[3]);
-                    break;
-#endif
                 }
             }
             log_info("card number = %s", pSysConfig->UserId);

+ 16 - 8
EVSE/Projects/DD360Audi/Apps/CSU/main.c

@@ -85,8 +85,8 @@ uint8_t bd0_2_status = 0;
 uint8_t bd1_1_status = 0;
 uint8_t bd1_2_status = 0;
 
-char *fwVersion = "T1.23.00.0000.00"; // "V0.16.00.0000.00";
-char* DebugVersion = "T1.23.3";
+char *fwVersion = "V1.23.00.0000.00"; // "V0.16.00.0000.00";
+char* DebugVersion = "V1.23.5";
 //sqlite3 *localDb;
 bool isDb_ready;
 
@@ -1488,6 +1488,8 @@ bool isEvBoardNormalStopChargeFlag(uint8_t gunIndex)
 //===============================================
 void ClearDetectPluginFlag(int gunIndex)
 {
+    if (pSysConfig->TotalConnectorCount == 1 && gunIndex == RIGHT_GUN_NUM)
+        return;
 
     ShmDcCommonData->pGunInfo[gunIndex].WaitForPlugit = NO;
     //DS60-120 add
@@ -1507,12 +1509,16 @@ void ClearDetectPluginFlag(int gunIndex)
 void DetectPluginStart(int gunIndex)
 {
     //pSysInfo->WaitForPlugit = YES;
+    if (pSysConfig->TotalConnectorCount == 1 && gunIndex == RIGHT_GUN_NUM)
+        return;
     ShmDcCommonData->pGunInfo[gunIndex].WaitForPlugit = YES;
     log_info("Gun%d start detect plug in",gunIndex);
 }
 
 bool isDetectPlugin(int gunIndex)
 {
+    if (pSysConfig->TotalConnectorCount == 1 && gunIndex == RIGHT_GUN_NUM)
+        return false;
     if (ShmDcCommonData->pGunInfo[gunIndex].WaitForPlugit == YES) {
         return true;
     }
@@ -1683,9 +1689,11 @@ void _AutoReturnTimeout(int gunIndex)
             pDcChargingInfo = (struct ChargingInfoData*)GetDcChargingInfoData(LEFT_GUN_NUM);
             if (pDcChargingInfo->SystemStatus == S_IDLE || pDcChargingInfo->SystemStatus == S_RESERVATION)
                 DetectPluginStart(LEFT_GUN_NUM);
-            pDcChargingInfo = (struct ChargingInfoData*)GetDcChargingInfoData(RIGHT_GUN_NUM);
-            if (pDcChargingInfo->SystemStatus == S_IDLE || pDcChargingInfo->SystemStatus == S_RESERVATION)
-                DetectPluginStart(RIGHT_GUN_NUM);
+            if (pSysConfig->TotalConnectorCount > 1) {
+                pDcChargingInfo = (struct ChargingInfoData*)GetDcChargingInfoData(RIGHT_GUN_NUM);
+                if (pDcChargingInfo->SystemStatus == S_IDLE || pDcChargingInfo->SystemStatus == S_RESERVATION)
+                    DetectPluginStart(RIGHT_GUN_NUM);
+            }
         }
     }
 
@@ -2840,9 +2848,9 @@ void StartGunInfoTimeoutDet(uint8_t gunIndex, uint8_t flag)
 
 void StopGunInfoTimeoutDet(uint8_t gunIndex)
 {
-    pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
 
     if (gunIndex < pSysConfig->TotalConnectorCount) {
+        pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
         pDcChargingInfo->TimeoutFlag = Timeout_None;
     }
 }
@@ -4742,7 +4750,7 @@ int main(void)
 
     time_t ShowEVStatusTimer[2] = { 0 };
 
-    SetGunTypeOTPValue();
+    //SetGunTypeOTPValue();
 
     for (;;) {
 
@@ -5073,7 +5081,7 @@ int main(void)
 
                 if (ShmPsuData->SystemPresentPsuQuantity > 0 &&
                         ShmPsuData->SystemAvailablePower > 10 &&
-                        GetTimeoutValue(pDcChargingInfo->TimeoutTimer) >= 1000000) {
+                        GetTimeoutValue(pDcChargingInfo->TimeoutTimer) >= 3000000) {
                     setChargerMode(gunIndex, MODE_PREPARE_FOR_EV);
                 }
 

+ 135 - 10
EVSE/Projects/DD360Audi/Apps/Define/define.h

@@ -610,7 +610,8 @@ struct SysConfigData
     unsigned char           MaintainServerSecurityPassword[41]; // Maintain server AuthorizationKey for security profile
     unsigned char           PowerSharingServerIP[512];          // Local power sharing server ip address
     unsigned int            PowerSharingCapacityPower;          // Local power sharing capacity power
-    unsigned char           MaxChargingSoc;                     //0: unlimit, 1 ~ 100 percent
+    unsigned char           MaxChargingSoc;                     // 0: unlimit, 1 ~ 100 percent
+    unsigned char			FanControlPolicy;					// 0: Auto mode		1: Quite mode
 };
 
 struct DERATING_BY_OTP
@@ -925,12 +926,126 @@ typedef union
 
 struct DC_METER_INFO
 {
-    double presetVoltage;                       // resolution: 1.000v
-    double presentCurrent;                      // resolution: 1.000a
-    double presentPower;                        // resolution: 1.000kw
-    double totlizeImportEnergy;                 // resolution: 1.000kwh
-    double totlizeExportEnergy;                 // resolution: 1.000kwh
-    unsigned char LinkStatus;                   // 0 = unknow ,1 = link , 2 miss link
+    double presetVoltage;						// resolution: 1.000v
+	double presentCurrent;					// resolution: 1.000a
+	double presentPower;						// resolution: 1.000kw
+	double totlizeImportEnergy;			// resolution: 1.000kwh
+	double totlizeExportEnergy;			// resolution: 1.000kwh
+	unsigned char timestamp[32];
+	unsigned char LinkStatus;								// 0 = unknow ,1 = link , 2 miss link
+};
+
+typedef union
+{
+		unsigned char Status;
+        struct
+        {
+	    			unsigned char suLinkStatusIsOk:1;
+            unsigned char muFatalErrorOccured:1;
+            unsigned char transactionIsOnGoing:1;
+            unsigned char tamperingIsDetected:1;
+            unsigned char timeSyncStatusIsOk:1;
+            unsigned char overTemperatureIsDetected:1;
+            unsigned char reversedVoltage:1;
+            unsigned char suMeasureFailureOccurred:1;
+        }bits;
+        
+}DcmbStatusFlag;
+
+typedef union
+{
+        unsigned char Errors;
+        struct
+        {
+            unsigned char muInitIsFailed:1;
+            unsigned char suStateIsInvalid:1;
+            unsigned char versionCheckIsFailed:1;
+            unsigned char muRngInitIsFailed:1;
+            unsigned char muDataIntegrityIsFailed:1;
+            unsigned char muFwIntegrityIsFailed:1;
+            unsigned char suIntegrityIsFailed:1;
+            unsigned char logbookIntegrityIsFailed:1;
+            unsigned char logbookIsFull:1;
+            unsigned char memoryAccessIsFailed:1;
+            unsigned char muStateIsFailed:1;
+            unsigned char res:5;
+        }bits;
+        
+}DcmbErrorFlag;
+   
+struct DC_METER_STATUS_INFO
+{
+	unsigned short StatusValue;
+	DcmbStatusFlag MeterStatusFlag;
+    
+	unsigned char applicationFirmwareVersion[16];
+    unsigned char applicationFirmwareAuthTag[32];
+    unsigned char legalFirmwareVersion[16];
+    unsigned char legalFirmwareAuthTag[32];
+    unsigned char sensorFirmwareVersion[16];
+    unsigned char sensorFirmwareCrc[4];
+
+    unsigned char Systime[32];
+    unsigned char ipAddress[32];
+    unsigned char meterId[32];
+
+	unsigned short ErrorValue;
+ 	DcmbErrorFlag MeterErrorFlag;
+   
+    unsigned char publicKey[140];
+    unsigned char publicKeyOcmf[200];
+    unsigned short indexOfLastTransaction;
+    unsigned short numberOfStoredTransactions;
+};
+
+struct DC_METER_TRANSACTION_HEAD
+{
+    unsigned char evseId[32];
+    unsigned char transactionId[32];
+    unsigned char clientId[32];
+    unsigned short tariffId;
+    unsigned short cableId;
+    unsigned short userData[32];
+    
+};
+
+struct DC_METER_TRANSACTION_ACTION
+{
+	struct DC_METER_TRANSACTION_HEAD head;
+	unsigned char transactionOCMF[512];
+	unsigned char OcmfInfoReady;                // 0 = nothing, 1 = ocmp info ready
+	unsigned char ActionCmd;                   // 1 = transaction Start, 2 transaction Stop, sync time
+};
+
+typedef union
+{
+				unsigned char Status;
+        struct
+        {
+	    			unsigned char intermediateRead:1;
+            unsigned char res:7;
+        }bits;
+        
+}DcmbTransactionReadlevel;
+
+struct DC_METER_TRANSACTION_RESULT
+{
+	unsigned short paginationCounter;
+	struct DC_METER_TRANSACTION_HEAD head;
+    unsigned char timestampStart[32];
+    unsigned char timestampStop[32];
+    unsigned int transactionDuration;
+    DcmbTransactionReadlevel intermediateRead;
+    unsigned int  transactionStatus;
+    unsigned char energyUnit[8];
+    double energyImport;
+    double energyImportTotalStart;
+    double energyImportTotalStop;
+    double energyExport;
+    double energyExportTotalStart;
+    double energyExportTotalStop;
+    unsigned char signature[140];
+    //unsigned char transactionOCMF[512];
 };
 
 typedef struct Bazel8Command
@@ -1081,6 +1196,10 @@ struct SysInfoData
     CabinetSettingFlag      CabinetSetting;
     struct LocalSharingInfo localSharingInfo;           // Local power sharing info structure
     struct DC_METER_INFO    DcMeterInfo[4];
+    struct DC_METER_STATUS_INFO DcMeterStatusInfo[4];
+    struct DC_METER_TRANSACTION_ACTION DcMeterReadTransactionRecord[4];
+    struct DC_METER_TRANSACTION_ACTION DcMeterTransactionAction[4];
+    struct DC_METER_TRANSACTION_RESULT DcMeterTransactionResult[4];
     unsigned char           OTPTemp;                    // OTP Temperature
     unsigned char           OTPTempR;                   // OTP Recovery Temperature
     struct LCD_OVERRIDE     LcdOveride;                 // LCD override info (no use anymore)
@@ -1419,7 +1538,7 @@ char AlarmStatusCode[160][6]=
     "012340",   // reserved
     "012341",   // reserved
     "012342",   // reserved
-    "012343",   // reserved
+    "012343",   // Tilt sensor self-test failed
     "012344",   // AC: Meter IC communication timeout
     "012345",   // AC: Pilot negative error
     "012346",   // Psu Communication error with CSU
@@ -1599,7 +1718,8 @@ struct AlarmCodeData
             unsigned char PsuPhaseOvp:1;                            //bit 5
             unsigned char :2;                                       //reserved bit 6 ~ bit 7
             //AlarmVal[17]
-            unsigned char :8;                                       //reserved bit 0 ~ bit 7
+            unsigned char :7;                                       //reserved bit 0 ~ bit 6
+            unsigned char TiltSensorStestFail:1;                    //reserved bit 7
             //AlarmVal[18]
             unsigned char MeterIcCommTimeout:1;                     //bit 0
             unsigned char PilotNegativeError:1;                     //bit 1
@@ -1609,7 +1729,12 @@ struct AlarmCodeData
 			unsigned char :3;                                       //reserved bit 4 ~ bit 7
             //AlarmVal[19]
             unsigned char PaymentCommTimeout:1;                     //Payment system communication timeout
-            unsigned char :7;                                       //reserved bit 1 ~ bit 7
+           	unsigned char MeterSlaveLosLink:1;                     	//DCMB meter slave module los link
+            unsigned char MeterSyncTimeError:1;            					//DCMB meter Sync Time Error
+            unsigned char MetertStartTransactionError:1;            //DCMB meter Start Transaction Error
+            unsigned char MetertStopTransactionError:1;             //DCMB meter Stop Transaction Error
+            unsigned char MetertGetTransactionOcmfError:1;          //DCMB meter Get OCMF Error        	
+            unsigned char :2;                                       //reserved bit 1 ~ bit 7
 		}bits;
 	}AlarmEvents;
 };

+ 10 - 0
EVSE/Projects/DD360Audi/Apps/ModuleDoComm/DoComm.c

@@ -356,11 +356,15 @@ static void ClearAuthorizedFlag(void)
 
 static void ClearDetectPluginFlag(int gunIndex)
 {
+    if (pSysConfig->TotalConnectorCount > 1 && gunIndex == RIGHT_GUN_NUM)
+        return;
     ShmDcCommonData->pGunInfo[gunIndex].WaitForPlugit = NO;
 }
 
 static bool isDetectPlugin(int gunIndex)
 {
+    if (pSysConfig->TotalConnectorCount == 1 && gunIndex == RIGHT_GUN_NUM)
+        return false;
     if (ShmDcCommonData->pGunInfo[gunIndex].WaitForPlugit == YES) {
         return true;
     }
@@ -946,6 +950,12 @@ static int miscCommandHandle(uint8_t dataLen, uint8_t plugNum, uint8_t *data)
             }
             gMoreInfoReq[plugNum].bits.ReceiptReq = YES;
             break;
+        case MISC_CMD_RFIDCARD_ENDIAN:
+            if (pSysConfig->RfidCardNumEndian != value) {
+                pSysConfig->RfidCardNumEndian = value;
+                log_info("Set RFID CARD %s endian", value ? "Little" : "Big");
+            }
+            break;
         default:
             clearMiscCommand();
             break;

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

@@ -133,6 +133,8 @@
 #define MISC_CMD_LED_INTENSITY                  (0x000E)
 #define MISC_CMD_AC_CONTACTOR                   (0x000F)
 #define MISC_CMD_TIME_OFFSET                    (0x0010)
+#define MISC_CMD_PARKING_PRICE                  (0x0011)
+#define MISC_CMD_RFIDCARD_ENDIAN                (0x0012)
 
 #define MISC_CMD_HARDWARE_REBOOT                (0x0101)
 #define MISC_CMD_SOFTWARE_RESTART               (0x0102)
@@ -148,6 +150,9 @@
 #define MISC_CMD_DEFAULT_PRICE_REQ              (0x010C)
 #define MISC_CMD_USER_PRICE_REQ                 (0x010D)
 #define MISC_CMD_RECEIPT_REQ                    (0x010E)
+#define MISC_CMD_CHARGING_BILL                  (0x010F)
+#define MISC_CMD_PARKING_PRICES                 (0x0110)
+
 
 #define ST_UPDATE_FIRMWARE                      (0x01)
 #define ST_NO_UPDATE_FIRMWARE                   (0x02)

+ 5 - 1
EVSE/Projects/DD360Audi/Apps/ModuleEvComm/Module_EvRxComm.c

@@ -236,7 +236,11 @@ void CheckEvConnect(int gunIndex)
     struct ChargingInfoData* pDcChargingInfo = (struct ChargingInfoData*)GetDcChargingInfoData(gunIndex);
     struct InfoCodeData* pInfoCode = (struct InfoCodeData*)GetShmInfoCodeData();
     struct ChargingInfoData* pDcChargingInfo_0 = (struct ChargingInfoData*)GetDcChargingInfoData(0);
-    struct ChargingInfoData* pDcChargingInfo_1 = (struct ChargingInfoData*)GetDcChargingInfoData(1);
+    struct ChargingInfoData* pDcChargingInfo_1 = NULL;
+    if (pSysConfig->TotalConnectorCount == 1)
+        pDcChargingInfo_1 = (struct ChargingInfoData*)GetDcChargingInfoData(0);
+    else
+        pDcChargingInfo_1 = (struct ChargingInfoData*)GetDcChargingInfoData(1);
 
     if (pDcChargingInfo_0->Type == pDcChargingInfo_1->Type) {
         isSameType = TRUE;

+ 27 - 6
EVSE/Projects/DD360Audi/Apps/ModuleEvComm/Module_EvTxComm.c

@@ -56,6 +56,7 @@ static int CanFd = -1;
 
 bool psuOutputReady[2] = {0, 0};
 uint8_t deratingIndex[2];
+bool ischillerHighTemp[2];
 //------------------------------------------------------------------------------
 extern void CANReceiver(int fd);
 extern void ClearAbnormalStatus_Chademo(uint8_t gun_index);
@@ -413,15 +414,35 @@ static void SetPresentChargingOutputCap(void)
             deratingIndex[1] = chargingData_2->deratingByConnOtp.deratingIndex;
         }
     }
+    // Chiller 錯誤或溫度降載
+    if (chargingData_1->ChillerTemp <= 70 && ShmDcCommonData->pGunInfo[0].withChiller && !ischillerHighTemp[0]) {
+        ischillerHighTemp[0] = TRUE;
+        if (cur1 > 2500) {
+            log_info("Gun0 chiller temperature(%d) too high set current less than 250A", chargingData_1->ChillerTemp);
+            cur1 = 2500;
+        }
+    } else if (chargingData_1->ChillerTemp > 75 && ischillerHighTemp[0]) {
+        cur1 = 2500;
+    }
+
+    if (chargingData_2->ChillerTemp <= 70 && ShmDcCommonData->pGunInfo[1].withChiller && !ischillerHighTemp[1]) {
+        ischillerHighTemp[1] = TRUE;
+        if (cur2 > 2500) {
+            log_info("Gun1 chiller temperature(%d) too high set current less than 250A", chargingData_2->ChillerTemp);
+            cur2 = 2500;
+        }
+    } else if (chargingData_2->ChillerTemp > 75 && ischillerHighTemp[1]) {
+        cur1 = 2500;
+    }
 
     if (ShmPrimaryMcuData->InputDet.bits.Ac_Drop == ABNORMAL) {
-        if (cur1 > 1500) {
-            log_info("Gun0 chiller alarm set current less than 150A");
-            cur1 = 1500;
+        if (cur1 > 2500) {
+            log_info("Gun0 chiller alarm set current less than 250A");
+            cur1 = 2500;
         }
-        if (cur2 > 1500) {
-            log_info("Gun1 chiller alarm set current less than 150A");
-            cur2 = 1500;
+        if (cur2 > 2500) {
+            log_info("Gun1 chiller alarm set current less than 250A");
+            cur2 = 2500;
         }
     }
     //DS60-120 add

+ 9 - 6
EVSE/Projects/DD360Audi/Apps/ModuleInternalComm/RelayBoard.c

@@ -1253,12 +1253,14 @@ static void GetFanSpeedByFunction(void)
     struct ChargingInfoData* pDcChargingInfo = NULL;
     for (gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++) {
         pDcChargingInfo = (struct ChargingInfoData*)GetDcChargingInfoData(gunIndex);
-        if ((pDcChargingInfo->SystemStatus > S_AUTHORIZING && pDcChargingInfo->SystemStatus < S_TERMINATING) ||
-            (pDcChargingInfo->SystemStatus >= S_CCS_PRECHARGE_ST0 && pDcChargingInfo->SystemStatus <= S_CCS_PRECHARGE_ST1)) {
-            ShmDcCommonData->FanOnTime = time((time_t*)NULL);
-            if (ShmFanModuleData->SetFan1Speed == 0) {
-                ShmFanModuleData->SetFan1Speed = 7000;
-                log_info("Set Fan speed 7000");
+        if (ShmDcCommonData->pGunInfo[gunIndex].withChiller) {
+            if ((pDcChargingInfo->SystemStatus > S_AUTHORIZING && pDcChargingInfo->SystemStatus < S_TERMINATING) ||
+                (pDcChargingInfo->SystemStatus >= S_CCS_PRECHARGE_ST0 && pDcChargingInfo->SystemStatus <= S_CCS_PRECHARGE_ST1)) {
+                ShmDcCommonData->FanOnTime = time((time_t*)NULL);
+                if (ShmFanModuleData->SetFan1Speed == 0) {
+                    ShmFanModuleData->SetFan1Speed = 7000;
+                    log_info("Set Fan speed 7000");
+                }
             }
         }
     }
@@ -1267,6 +1269,7 @@ static void GetFanSpeedByFunction(void)
         ShmFanModuleData->SetFan1Speed == 7000) {
         ShmFanModuleData->SetFan1Speed = 0;
         log_info("Close fan");
+        ShmDcCommonData->FanOnTime = time((time_t*)NULL);
     }
 
     /*

+ 29 - 206
EVSE/Projects/DD360Audi/Apps/ModulePrimary/Module_PrimaryComm.c

@@ -54,108 +54,6 @@ uint8_t Door_count = 0;
 uint8_t EmgBtn_flag = 0;
 uint8_t Door_flag = 0;
 
-//struct ChargingInfoData *ChargingData[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
-
-//------------------------------------------------------------------------------
-/*int StoreLogMsg(const char *fmt, ...)
-{
-    char Buf[4096 + 256];
-    char buffer[4096];
-    va_list args;
-    struct timeb  SeqEndTime;
-    struct tm *tm;
-
-    va_start(args, fmt);
-    int rc = vsnprintf(buffer, sizeof(buffer), fmt, args);
-    va_end(args);
-
-    memset(Buf, 0, sizeof(Buf));
-    ftime(&SeqEndTime);
-    SeqEndTime.time = time(NULL);
-    tm = localtime(&SeqEndTime.time);
-
-    if (pSysConfig->SwitchDebugFlag == YES) {
-        sprintf(Buf, "%02d:%02d:%02d:%03d - %s",
-                tm->tm_hour, tm->tm_min, tm->tm_sec, SeqEndTime.millitm, buffer);
-        printf("%s ", Buf);
-    } else {
-        sprintf(Buf, "echo \"%04d-%02d-%02d %02d:%02d:%02d:%03d - %s\" >> /Storage/SystemLog/[%04d.%02d]SystemLog",
-                tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec, SeqEndTime.millitm,
-                buffer,
-                tm->tm_year + 1900, tm->tm_mon + 1);
-        system(Buf);
-    }
-
-    return rc;
-}
-*/
-
-#if 0 //non use
-int DiffTimeb(struct timeb ST, struct timeb ET)
-{
-    //return milli-second
-    unsigned int StartTime, StopTime;
-
-    StartTime = (unsigned int)ST.time;
-    StopTime = (unsigned int)ET.time;
-    return (StopTime - StartTime) * 1000 + ET.millitm - ST.millitm;
-}
-
-//=================================
-// Common routine
-//=================================
-char *getTimeString(void)
-{
-    char *result = malloc(21);
-    time_t timep;
-    struct tm *p;
-    time(&timep);
-    p = gmtime(&timep);
-
-    sprintf(result, "[%04d-%02d-%02d %02d:%02d:%02d]",
-            (1900 + p->tm_year),
-            (1 + p->tm_mon),
-            p->tm_mday,
-            p->tm_hour,
-            p->tm_hour,
-            p->tm_sec);
-
-    return result;
-}
-#endif //0
-
-//==========================================
-// Init all share memory
-//==========================================
-/*int InitShareMemory()
-{
-    int result = PASS;
-    int MeterSMId;
-
-    //creat ShmSysConfigAndInfo
-    if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo),  0777)) < 0) {
-        result = FAIL;
-    } else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
-        result = FAIL;
-    }
-
-    //creat ShmStatusCodeData
-    if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData),  0777)) < 0) {
-        result = FAIL;
-    } else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
-        result = FAIL;
-    }
-
-    //creat ShmStatusCodeData
-    if ((MeterSMId = shmget(ShmPrimaryMcuKey, sizeof(struct PrimaryMcuData), 0777)) < 0) {
-        result = FAIL;
-    } else if ((ShmPrimaryMcuData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
-        result = FAIL;
-    }
-
-    return result;
-}
-*/
 
 //================================================
 // Function
@@ -186,7 +84,8 @@ void GetInputGpioStatus(int fd)
     }
 
     ShmPrimaryMcuData->InputDet.bits.SpdDetec = gpio_in.SPD;
-    ShmPrimaryMcuData->InputDet.bits.Ac_Drop = ~gpio_in.AC_Drop; // Chiller Alarm ping
+    //log_info("gpio_in.AC_Drop:%d", gpio_in.AC_Drop);
+    ShmPrimaryMcuData->InputDet.bits.Ac_Drop = gpio_in.AC_Drop; // Chiller Alarm ping
 
 #ifdef DD360ComBox
     EmgBtn_flag = 0;
@@ -226,7 +125,7 @@ void GetInputGpioStatus(int fd)
     ShmPrimaryMcuData->InputDet.bits.Button1 = gpio_in.Button[0];
     ShmPrimaryMcuData->InputDet.bits.Button2 = gpio_in.Button[1];
 
-#if defined DD360 || defined DD360Audi || defined DD360ComBox
+//#if defined DD360 || defined DD360Audi || defined DD360ComBox
     if ((strncmp((char *)&pSysConfig->ModelName[7], "V", 1) == 0) ||
             (strncmp((char *)&pSysConfig->ModelName[9], "V", 1) == 0) ||
             (strncmp((char *)&pSysConfig->ModelName[7], "F", 1) == 0) ||
@@ -288,56 +187,8 @@ void GetInputGpioStatus(int fd)
     ShmPrimaryMcuData->InputDet.bits.Key3 = ~gpio_in.Key[3] & 0x01;
 
     return;
-#endif //defined DD360 || defined DD360Audi || defined DD360ComBox
-
-    static uint8_t _curDeviceStatus[3] = {0};
-    static uint8_t _reCheckCount[3] = {0};
-
-    //DS60-120 add
-    if (_curDeviceStatus[_PRIMARY_CHECK_TAG_AC_CONTACT] != gpio_in.AC_Connector) {
-        if (_reCheckCount[_PRIMARY_CHECK_TAG_AC_CONTACT] >= 3) {
-            _curDeviceStatus[_PRIMARY_CHECK_TAG_AC_CONTACT] = gpio_in.AC_Connector;
-            pSysInfo->AcContactorStatus =
-                ShmPrimaryMcuData->InputDet.bits.AcContactorDetec =
-                    gpio_in.AC_Connector;
-        } else {
-            _reCheckCount[_PRIMARY_CHECK_TAG_AC_CONTACT]++;
-        }
-    } else {
-        _reCheckCount[_PRIMARY_CHECK_TAG_AC_CONTACT] = 0;
-    }
 
-    if (_curDeviceStatus[_PRIMARY_CHECK_TAG_MAIN_BREAKER] != gpio_in.AC_MainBreaker) {
-        if (_reCheckCount[_PRIMARY_CHECK_TAG_MAIN_BREAKER] >= 3) {
-            _curDeviceStatus[_PRIMARY_CHECK_TAG_MAIN_BREAKER] = gpio_in.AC_MainBreaker;
-            ShmPrimaryMcuData->InputDet.bits.AcMainBreakerDetec = gpio_in.AC_MainBreaker;
-        } else {
-            _reCheckCount[_PRIMARY_CHECK_TAG_MAIN_BREAKER]++;
-        }
-    } else {
-        _reCheckCount[_PRIMARY_CHECK_TAG_MAIN_BREAKER] = 0;
-    }
-    //pSysInfo->AcContactorStatus = ShmPrimaryMcuData->InputDet.bits.AcContactorDetec = gpio_in.AC_Connector;
-    //ShmPrimaryMcuData->InputDet.bits.AcMainBreakerDetec = gpio_in.AC_MainBreaker;
-
-    ShmPrimaryMcuData->InputDet.bits.Key0 = gpio_in.Key[0] & 0x01;
-    ShmPrimaryMcuData->InputDet.bits.Key1 = gpio_in.Key[1] & 0x01;
-    ShmPrimaryMcuData->InputDet.bits.Key2 = gpio_in.Key[2] & 0x01;
-    ShmPrimaryMcuData->InputDet.bits.Key3 = gpio_in.Key[3] & 0x01;
-    ShmPrimaryMcuData->InputDet.bits.DoorOpen = gpio_in.Door_Open;
-
-    /*printf(" gpio_in.Key[0]~ gpio_in.Key[3]=%d, %d, %d, %d",
-    ShmPrimaryMcuData->InputDet.bits.Key0 , ShmPrimaryMcuData->InputDet.bits.Key1,
-    ShmPrimaryMcuData->InputDet.bits.Key2,ShmPrimaryMcuData->InputDet.bits.Key3);
-    printf("pAlarmCode->AlarmEvents.bits.CcsLiquidChillerWaterLevelWarning=%d", pAlarmCode->AlarmEvents.bits.CcsLiquidChillerWaterLevelWarning);
-    printf("pFaultCode->FaultEvents.bits.CcsLiquidChillerWaterLevelFault=%d", pFaultCode->FaultEvents.bits.CcsLiquidChillerWaterLevelFault);
-    */
-    //log_info("left = %d ", ShmPrimaryMcuData->InputDet.bits.Button1);
-    //log_info("right = %d ", ShmPrimaryMcuData->InputDet.bits.Button2);
-    //log_info("pSysInfo->AcContactorStatus = %d ", pSysInfo->AcContactorStatus);
-    if (ShmPrimaryMcuData->InputDet.bits.AcMainBreakerDetec == YES) {
-        log_error("AC Mainbreaker occur. ");
-    }
+
 }
 
 static void checkChillerStatus(Gpio_out *gpio)
@@ -347,17 +198,18 @@ static void checkChillerStatus(Gpio_out *gpio)
     struct ChargingInfoData *pDcChargingInfo = NULL;
     static ChillerInfo fChillerInfo[2] = {0}, *pChillerInfo = NULL;
     static ChillerInfo _chiller;
-    struct FanModuleData* ShmFanModuleData = (struct FanModuleData*)GetShmFanModuleData();;
+    struct FanModuleData* ShmFanModuleData = (struct FanModuleData*)GetShmFanModuleData();
+    DcCommonInfo* ShmDcCommonData = (DcCommonInfo*)GetShmDcCommonData();
     Gpio_out *pGpio = (Gpio_out *)gpio;
 
-    if ((strncmp((char *)&pSysConfig->ModelName[7], "V", 1) == 0) ||
-            (strncmp((char *)&pSysConfig->ModelName[7], "F", 1) == 0)) {
+    if ((strncmp((char*)&pSysConfig->ModelName[7], "V", 1) == 0) ||
+        (strncmp((char*)&pSysConfig->ModelName[7], "F", 1) == 0)) {
         chillerCount++;
         ShmDcCommonData->pGunInfo[0].withChiller = TRUE;
     }
 
-    if ((strncmp((char *)&pSysConfig->ModelName[9], "V", 1) == 0) ||
-            (strncmp((char *)&pSysConfig->ModelName[9], "F", 1) == 0)) {
+    if ((strncmp((char*)&pSysConfig->ModelName[9], "V", 1) == 0) ||
+        (strncmp((char*)&pSysConfig->ModelName[9], "F", 1) == 0)) {
         chillerCount++;
         ShmDcCommonData->pGunInfo[1].withChiller = TRUE;
     }
@@ -382,28 +234,30 @@ static void checkChillerStatus(Gpio_out *gpio)
                 //10分鐘後停止
                 if ((time((time_t *)NULL) - pChillerInfo->ChillerOnTime) >= 600) {
                     pChillerInfo->ChillerSwitch = NO;
+                    ShmDcCommonData->FanOnTime = time((time_t*)NULL);
                 }
             } else {
                 pChillerInfo->ChillerSwitch = NO;
+                ShmFanModuleData->SetFan1Speed = 0;
             }
         }
         // 檢查Chiller溫度點,若小於零下時開啟heater,大於10度時關閉heater
-        if (pDcChargingInfo->ChillerTemp < 60) {
+        if (pDcChargingInfo->ChillerTemp < 70) {
             pGpio->AC_Breaker = YES;
-        } else if(pDcChargingInfo->ChillerTemp > 70) {
+        } else if(pDcChargingInfo->ChillerTemp > 75) {
             pGpio->AC_Breaker = NO;
         }
-        //log_info("Set Heater %s", pGpio->AC_Breaker ? "ON" : "OFF");
+        //log_info("Gun%d Set Heater %s", gunIndex, pGpio->AC_Breaker ? "ON" : "OFF");
     }
     uint8_t _chillerNeedOn = NO;
     for (gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++)
     {
-        pChillerInfo = (ChillerInfo *)&fChillerInfo[gunIndex];
-        if(pChillerInfo->ChillerSwitch == YES) {
+        pChillerInfo = (ChillerInfo*)&fChillerInfo[gunIndex];
+        if (pChillerInfo->ChillerSwitch == YES) {
             _chillerNeedOn = YES;
+            ShmFanModuleData->SetFan1Speed = 7000;
         }
     }
-
     /*
     if (ShmDcCommonData->debugflag == YES)
         _chillerNeedOn = ShmDcCommonData->chillerCtrl;
@@ -451,7 +305,7 @@ void SetOutputGpio(int fd, uint8_t outputValue)
 
     checkChillerStatus(&gpio);
 
-    //gpio.AC_Breaker = 0x00;
+    //gpio.AC_Breaker = 0x01;
 
     Config_Gpio_Output(fd, OP_ADDR_IO_EXTEND, &gpio);
 }
@@ -541,48 +395,17 @@ 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;
 }
+unsigned long GetClockTimeoutValue(struct timespec _start_time)
+{
+    struct timespec ts_end;
+    unsigned long ret = 0;
+
+    clock_gettime(CLOCK_MONOTONIC, &ts_end);
 
-//int FindChargingInfoData(uint8_t target, struct ChargingInfoData **chargingData)
-//{
-//    for (uint8_t index = 0; index < CHAdeMO_QUANTITY; index++) {
-//        if (pSysInfo->ChademoChargingData[index].Index == target) {
-//            chargingData[target] = &pSysInfo->ChademoChargingData[index];
-//            return 1;
-//        }
-//    }
-//
-//    for (uint8_t index = 0; index < CCS_QUANTITY; index++) {
-//        if (pSysInfo->CcsChargingData[index].Index == target) {
-//            chargingData[target] = &pSysInfo->CcsChargingData[index];
-//            return 1;
-//        }
-//    }
-//
-//    for (uint8_t index = 0; index < GB_QUANTITY; index++) {
-//        if (pSysInfo->GbChargingData[index].Index == target) {
-//            chargingData[target] = &pSysInfo->GbChargingData[index];
-//            return 1;
-//        }
-//    }
-//
-//    return 0;
-//}
-
-//void Initialization() //DS60-120 add
-//{
-//    bool isPass = false;
-//    while (!isPass) {
-//        isPass = true;
-//        for (uint8_t _index = 0; _index < gun_count; _index++) {
-//            if (!FindChargingInfoData(_index, &ChargingData[0])) {
-//                log_error("EvComm (main) : FindChargingInfoData false ");
-//                isPass = false;
-//                break;
-//            }
-//        }
-//        sleep(1);
-//    }
-//}
+    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;
+}
 
 static bool IsPrimaryProcessNeedPause(void)
 {

+ 2 - 1
EVSE/Projects/DD360Audi/Apps/ModulePrimary/PrimaryComm.c

@@ -117,6 +117,7 @@ int Query_Gpio_Input(uint8_t fd, uint8_t targetAddr, Gpio_in *Ret_Buf)
                 (rx[2] == tx[1]) &&
                 (rx[1] == tx[2]) &&
                 (rx[3] == tx[3])) {
+            //log_info("rx[6]:0x%x,rx[7]:0x%x", rx[6], rx[7]);
             Ret_Buf->AC_Connector       = (rx[6] >> 0) & 0x01;
             Ret_Buf->AC_MainBreaker     = (rx[6] >> 1) & 0x01;
             Ret_Buf->SPD                = (rx[6] >> 2) & 0x01;
@@ -124,7 +125,7 @@ int Query_Gpio_Input(uint8_t fd, uint8_t targetAddr, Gpio_in *Ret_Buf)
             Ret_Buf->GFD[0]             = (rx[6] >> 4) & 0x01;
             Ret_Buf->GFD[1]             = (rx[6] >> 5) & 0x01;
             Ret_Buf->AC_Drop            = (rx[6] >> 6) & 0x01;
-            Ret_Buf->Emergency_IO       = (rx[6] >> 7) & 0x01;
+            Ret_Buf->Emergency_IO       = (rx[6] >> 7) & 0x01; 
 
             Ret_Buf->Emergency_Btn      = (rx[7] >> 0) & 0x01;
             Ret_Buf->Button[0]          = (rx[7] >> 1) & 0x01;

+ 38 - 25
EVSE/Projects/DD360Audi/Apps/ReadCmdline.c

@@ -774,23 +774,6 @@ void GetOtpPwrOrCurMethod(struct ChargingInfoData* chargingData, float* pow, flo
             chargingData->deratingByConnOtp.deratingIndex = 2;
         }
     }
-    /*
-    if (((chargingData->ConnectorTemp >= STAGE1_GUN_DERATING_TEMP &&
-        chargingData->ConnectorTemp < STAGE2_GUN_DERATING_TEMP) ||
-        (chargingData->ChillerTemp >= STAGE1_GUN_DERATING_TEMP &&
-            chargingData->ChillerTemp < STAGE2_GUN_DERATING_TEMP)) &&
-        chargingData->deratingByConnOtp.deratingIndex < 1)
-    {
-        chargingData->deratingByConnOtp.deratingIndex = 1;
-    } else if ((chargingData->ConnectorTemp >= STAGE2_GUN_DERATING_TEMP ||
-        chargingData->ChillerTemp >= STAGE2_GUN_DERATING_TEMP) &&
-        chargingData->ConnectorTemp != UNDEFINED_TEMP &&
-        chargingData->ChillerTemp != UNDEFINED_TEMP &&
-        chargingData->deratingByConnOtp.deratingIndex < 2)
-    {
-        chargingData->deratingByConnOtp.deratingIndex = 2;
-    }
-    */
     if (chargingData->deratingByConnOtp.deratingTargetRate[chargingData->deratingByConnOtp.deratingIndex] != 0)
     {
         *pow *= chargingData->deratingByConnOtp.deratingTargetRate[chargingData->deratingByConnOtp.deratingIndex];
@@ -863,6 +846,7 @@ void RunUnconditionalChargeIndex1(char *v1, char *v2, char *v3)
         case S_IDLE:
             if (PreviousSystemStatus[curGun] != pDcChargingInfo->SystemStatus) {
                 PreviousSystemStatus[curGun] = pDcChargingInfo->SystemStatus;
+                sleep(3);
 #if defined DD360Audi
                 setConfirmSelGun(curGun);
 #endif //defined DD360Audi
@@ -1026,11 +1010,35 @@ void RunUnconditionalChargeIndex1(char *v1, char *v2, char *v3)
             //ev task do this
             for (idx = 0; idx < pSysConfig->TotalConnectorCount; idx++) {
                 struct ChargingInfoData* pInfo = (struct ChargingInfoData*)GetDcChargingInfoData(idx);
+                if (!ShmDcCommonData->TestTemperature)
+                    getChillerTemperature(pInfo);
+                // 低溫保護
+                if ((strncmp((char*)&pSysConfig->ModelName[7 + idx * 2], "V", 1) == 0) ||
+                    (strncmp((char*)&pSysConfig->ModelName[7 + idx * 2], "F", 1) == 0)) {
+                    if ((ShmDcCommonData->SystemTemp[idx * 2] <= 70 ||
+                        ShmDcCommonData->SystemTemp[idx * 2 + 1] <= 70)) {
+                        if (pInfo->EvBatterytargetCurrent > 250) {
+                            pInfo->EvBatterytargetCurrent = 250;
+                            printf("Chiller%d temperature(%d %d) too low limit target Current under 250A\n", idx, ShmDcCommonData->SystemTemp[idx * 2],
+                                ShmDcCommonData->SystemTemp[idx * 2 + 1]);
+                        }
+                    } else if ((ShmDcCommonData->SystemTemp[idx * 2] >= 80 ||
+                        ShmDcCommonData->SystemTemp[idx * 2 + 1] >= 80) && pInfo->EvBatterytargetCurrent != _Current) {
+                        pInfo->EvBatterytargetCurrent = _Current;
+                        printf("Chiller%d temperature(%d %d) recovery target Current set %.2fA\n", idx, ShmDcCommonData->SystemTemp[idx * 2],
+                            ShmDcCommonData->SystemTemp[idx * 2 + 1], pInfo->EvBatterytargetCurrent);
+                    }
+                    if (ShmPrimaryMcuData->InputDet.bits.Ac_Drop == ABNORMAL) {
+                        if (pInfo->EvBatterytargetCurrent > 250) {
+                            pInfo->EvBatterytargetCurrent = 250;
+                            printf("Chiller alarm limit target Current under 250A\n");
+                        }
+                    }
+                }
+                // 高溫保護
                 if (pInfo->deratingByConnOtp.isNeedDerating) {
                     deratingCurrent = pInfo->EvBatterytargetCurrent;
                     deratingPower = pInfo->AvailableChargingPower;
-
-                    getChillerTemperature(pInfo);
                     GetOtpPwrOrCurMethod(pInfo, &deratingPower, &deratingCurrent);
                     if (derating_index != pDcChargingInfo->deratingByConnOtp.deratingIndex) {
                         printf("Change Derating Index:%d\n", pInfo->deratingByConnOtp.deratingIndex);
@@ -1043,14 +1051,17 @@ void RunUnconditionalChargeIndex1(char *v1, char *v2, char *v3)
                         printf("Derating Current:%.3f Power:%.3f\n", pInfo->EvBatterytargetCurrent, pInfo->AvailableChargingPower);
                     }
                 }
-                if (ShmPrimaryMcuData->InputDet.bits.Ac_Drop == ABNORMAL) {
-                    if (pInfo->EvBatterytargetCurrent > 1500) {
-                        pInfo->EvBatterytargetCurrent = 1500;
-                        printf("Chiller alarm limit target Current under 150A");
-                    }
-                }
+
+
             } // for
 
+            // 水冷槍低溫保護
+            if ((strncmp((char*)&pSysConfig->ModelName[7 + curGun * 2], "V", 1) == 0) ||
+                (strncmp((char*)&pSysConfig->ModelName[7 + curGun * 2], "F", 1) == 0)) {
+
+            }
+            
+
             pDcChargingInfo->PresentChargingPower =
                 ((float)((pDcChargingInfo->PresentChargingVoltage) *
                          (pDcChargingInfo->PresentChargingCurrent)) / 1000);
@@ -1070,8 +1081,10 @@ void RunUnconditionalChargeIndex1(char *v1, char *v2, char *v3)
                 //無阻塞偵測 keybaord 結束
                 system(STTY_DEF TTY_PATH);
             }
+            sleep(1);
             pDcChargingInfo->ConnectorPlugIn = 0;
             pDcChargingInfo->SystemStatus = S_COMPLETE;
+
             break;
 
         case S_COMPLETE: