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

2021-11-12 / Simon Xue

Action
1. Add Setting OTPTemp & OTPTempR for OTP temperature and recovery temperature.
2. Modify LCM.

File
As follow commit history

Version
V1.18.0
Simon Xue 3 жил өмнө
parent
commit
0fac506088

+ 12 - 12
EVSE/Projects/DD360Audi/Apps/CSU/SelfTest.c

@@ -81,7 +81,7 @@ void SelfTestRun(void)
                     pSysInfo->RelayModuleFwRev[0] != '\0') &&
                     (ShmRelayModuleData->SelfTest_Comp != YES)
                ) {
-                log_info("Relay Board FW Rev = %s", pSysInfo->RelayModuleFwRev);
+                //log_info("Relay Board FW Rev = %s", pSysInfo->RelayModuleFwRev);
                 ShmRelayModuleData->SelfTest_Comp = YES;
             }
 
@@ -90,7 +90,7 @@ void SelfTestRun(void)
                     pSysInfo->FanModuleFwRev[0] != '\0') &&
                     (ShmFanModuleData->SelfTest_Comp != YES)
                ) {
-                log_info("Fan Board FW Rev = %s", pSysInfo->FanModuleFwRev);
+                //log_info("Fan Board FW Rev = %s", pSysInfo->FanModuleFwRev);
                 ShmFanModuleData->SelfTest_Comp = YES;
             }
 #else
@@ -101,7 +101,7 @@ void SelfTestRun(void)
                     ShmPrimaryMcuData->version[0] != '\0') &&
                     (ShmPrimaryMcuData->SelfTest_Comp != YES)
                ) {
-                log_info("Primary FW Rev = %s", pSysInfo->CsuPrimFwRev);
+                //log_info("Primary FW Rev = %s", pSysInfo->CsuPrimFwRev);
                 ShmPrimaryMcuData->SelfTest_Comp = YES;
             }
 
@@ -120,9 +120,9 @@ void SelfTestRun(void)
                                 ShmCHAdeMOData->evse[pDcChargingInfo->type_index].version[0] != '\0')
                                 //&& (ShmCHAdeMOData->evse[pDcChargingInfo->type_index].SelfTest_Comp != YES)
                            ) {
-                            log_info("CHAdeMO[%d] FW Rev = %s",
-                                     pDcChargingInfo->type_index,
-                                     ShmCHAdeMOData->evse[pDcChargingInfo->type_index].version);
+                            //log_info("CHAdeMO[%d] FW Rev = %s",
+                            //         pDcChargingInfo->type_index,
+                            //         ShmCHAdeMOData->evse[pDcChargingInfo->type_index].version);
                             ShmCHAdeMOData->evse[pDcChargingInfo->type_index].SelfTest_Comp = YES;
                         } else {
                             //log_info("chademo fw lose...... %s \n", ShmCHAdeMOData->evse[pDcChargingInfo->type_index].version);
@@ -133,9 +133,9 @@ void SelfTestRun(void)
                                 ShmGBTData->evse[pDcChargingInfo->type_index].version[0] != '\0')
                                 //&& (ShmGBTData->evse[pDcChargingInfo->type_index].SelfTest_Comp != YES)
                            ) {
-                            log_info("GBT[%d] FW Rev = %s",
-                                     pDcChargingInfo->type_index,
-                                     ShmGBTData->evse[pDcChargingInfo->type_index].version);
+                            //log_info("GBT[%d] FW Rev = %s",
+                            //         pDcChargingInfo->type_index,
+                            //         ShmGBTData->evse[pDcChargingInfo->type_index].version);
                             ShmGBTData->evse[pDcChargingInfo->type_index].SelfTest_Comp = YES;
                         } else {
                             //log_info("GBT fw lose...... %s \n", ShmCHAdeMOData->evse[pDcChargingInfo->type_index].version);
@@ -147,9 +147,9 @@ void SelfTestRun(void)
                                     ShmCcsData->V2GMessage_DIN70121[pDcChargingInfo->type_index].version[0] != '\0')
                                     /*&&(ShmCcsData->V2GMessage_DIN70121[pDcChargingInfo->type_index].SelfTest_Comp != YES)*/
                                ) {
-                                log_info("CCS[%d] FW Rev = %s",
-                                         pDcChargingInfo->type_index,
-                                         ShmCcsData->V2GMessage_DIN70121[pDcChargingInfo->type_index].version);
+                             //   log_info("CCS[%d] FW Rev = %s",
+                             //            pDcChargingInfo->type_index,
+                             //            ShmCcsData->V2GMessage_DIN70121[pDcChargingInfo->type_index].version);
                                 ShmCcsData->V2GMessage_DIN70121[pDcChargingInfo->type_index].SelfTest_Comp = YES;
                             } else {
                                 //log_info("CCS[%d] ccs fw lose...... %s \n",

+ 44 - 21
EVSE/Projects/DD360Audi/Apps/CSU/main.c

@@ -82,8 +82,8 @@ uint8_t bd0_2_status = 0;
 uint8_t bd1_1_status = 0;
 uint8_t bd1_2_status = 0;
 
-char *fwVersion = "V1.17.00.0000.00"; // "V0.16.00.0000.00";
-char* DebugVersion = "v1.17.2";
+char *fwVersion = "V1.18.00.0000.00"; // "V0.16.00.0000.00";
+char* DebugVersion = "v1.18.0";
 //sqlite3 *localDb;
 bool isDb_ready;
 
@@ -395,10 +395,11 @@ static void checkGunOTPState(uint8_t gunIndex)
 {
     pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
 
+    //log_info("OTP:%d OTPR%d",pSysInfo->OTPTemp,pSysInfo->OTPTempR);
     //水冷機溫度檢測
     if (((ShmDcCommonData->ChillerValve.MultiChillerGun & 0x80) >> 7) == YES) {
         if (pDcChargingInfo->ChillerTemp != UNDEFINED_TEMP) {
-            if (pDcChargingInfo->ChillerTemp >= GUN_OTP_VALUE) {
+            if (pDcChargingInfo->ChillerTemp >= pSysInfo->OTPTemp ) {
                 if (((gunIndex == 0) &&
                         ((strncmp((char *)&pSysConfig->ModelName[7], "V", 1) == 0) ||
                          (strncmp((char *)&pSysConfig->ModelName[7], "F", 1) == 0)))
@@ -415,7 +416,7 @@ static void checkGunOTPState(uint8_t gunIndex)
                     ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerOTP = NO;
                 }
             } else if (pDcChargingInfo->ChillerTemp != 0 &&
-                       pDcChargingInfo->ChillerTemp < GUN_OTP_RECOVERY) {
+                       pDcChargingInfo->ChillerTemp < pSysInfo->OTPTempR) {
                 //ResetChargerAlarmCode(gunIndex, "012323");
                 ShmDcCommonData->ChillerTempErr[gunIndex].StatusBit.ChillerOTP = NO;
             }
@@ -450,11 +451,11 @@ static void checkGunOTPState(uint8_t gunIndex)
     switch (pDcChargingInfo->Type) {
     case _Type_Chademo:
         if (pDcChargingInfo->ConnectorTemp != UNDEFINED_TEMP) {
-            if (pDcChargingInfo->ConnectorTemp >= GUN_OTP_VALUE) {
+            if (pDcChargingInfo->ConnectorTemp >= pSysInfo->OTPTemp) {
                 RecordAlarmCode(gunIndex, "012229");
                 ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaConnectOTP = YES;
             } else if (pDcChargingInfo->ConnectorTemp != 0 &&
-                       pDcChargingInfo->ConnectorTemp < GUN_OTP_RECOVERY) {
+                       pDcChargingInfo->ConnectorTemp < pSysInfo->OTPTempR) {
                 //ResetChargerAlarmCode(gunIndex, "012229");
                 ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaConnectOTP = NO;
             }
@@ -473,11 +474,11 @@ static void checkGunOTPState(uint8_t gunIndex)
         if (pDcChargingInfo->ConnectorTemp != UNDEFINED_TEMP) {
             //ResetChargerAlarmCode(gunIndex, "011019");
 
-            if (pDcChargingInfo->ConnectorTemp >= GUN_OTP_VALUE) {
+            if (pDcChargingInfo->ConnectorTemp >= pSysInfo->OTPTemp) {
                 RecordAlarmCode(gunIndex, "012230");
                 ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSConnectOTP = YES;
             } else if (pDcChargingInfo->ConnectorTemp != 0 &&
-                       pDcChargingInfo->ConnectorTemp < GUN_OTP_RECOVERY) {
+                       pDcChargingInfo->ConnectorTemp < pSysInfo->OTPTempR) {
                 //ResetChargerAlarmCode(gunIndex, "012230");
                 ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSConnectOTP = NO;
             }
@@ -494,11 +495,11 @@ static void checkGunOTPState(uint8_t gunIndex)
 
     case _Type_GB:
         if (pDcChargingInfo->ConnectorTemp != UNDEFINED_TEMP) {
-            if (pDcChargingInfo->ConnectorTemp >= GUN_OTP_VALUE) {
+            if (pDcChargingInfo->ConnectorTemp >= pSysInfo->OTPTemp) {
                 RecordAlarmCode(gunIndex, "012231");
                 ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTConnectOTP = YES;
             } else if (pDcChargingInfo->ConnectorTemp != 0 &&
-                       pDcChargingInfo->ConnectorTemp < GUN_OTP_RECOVERY) {
+                       pDcChargingInfo->ConnectorTemp < pSysInfo->OTPTempR) {
                 //ResetChargerAlarmCode(gunIndex, "012231");
                 ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTConnectOTP = NO;
             }
@@ -3776,7 +3777,7 @@ static void autoStartCharging(uint8_t gunIndex)
     pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
 
     if ( (pSysInfo->SystemPage >= _LCM_AUTHORIZING && pSysInfo->SystemPage <= _LCM_AUTHORIZ_FAIL) ||
-        pDcChargingInfo->isEVCCIDVerify ) {
+        pDcChargingInfo->isEVCCIDVerify || (strcmp( (char *)pSysConfig->UserId , "" ) != EQUAL)) {
             return;
     }
 
@@ -3814,7 +3815,7 @@ static void autoStartCharging(uint8_t gunIndex)
             confirmSelGun(gunIndex);
             pSysInfo->SystemPage = _LCM_AUTHORIZING;
         }
-        if ( (strcmp( (char *)pSysConfig->UserId , "" ) != EQUAL) && (strcmp( (char *)pSysConfig->UserId , OldUseId ) != EQUAL)) {
+        if (strcmp( (char *)pSysConfig->UserId , OldUseId ) != EQUAL) {
             strcpy((char *)OldUseId, (char *)pSysConfig->UserId);
             log_info("Get User(%d) ID:%s",gunIndex,pSysConfig->UserId);
         }
@@ -4292,7 +4293,34 @@ static void checkEvBoardReqStop(uint8_t sysStatus, uint8_t gunIndex)
         ChargingTerminalProcess(gunIndex);
     }
 }
-
+void showversion()
+{
+    uint8_t index = 0;
+    log_info("\t========= Charger info ========= ");
+    log_info("\tSW Version = %s", fwVersion);
+    log_info("\tDebug Version = %s",DebugVersion);
+    log_info("\tModelName = %s", pSysConfig->ModelName);
+    log_info("\tRelay Board FW Rev = %s", pSysInfo->RelayModuleFwRev);
+    log_info("\tFan Board FW Rev = %s", pSysInfo->FanModuleFwRev);
+    log_info("\tPrimary FW Rev = %s", pSysInfo->CsuPrimFwRev);
+    for (index = 0; index < pSysConfig->TotalConnectorCount; index++) {
+        pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(index);
+        if (pDcChargingInfo->Type == _Type_Chademo) {
+            log_info("\tCHAdeMO[%d] FW Rev = %s",
+                                     pDcChargingInfo->type_index,
+                                     ShmCHAdeMOData->evse[pDcChargingInfo->type_index].version);
+        } else if (pDcChargingInfo->Type == _Type_GB) {
+            log_info("\tGBT[%d] FW Rev = %s",
+                                     pDcChargingInfo->type_index,
+                                     ShmGBTData->evse[pDcChargingInfo->type_index].version);
+        } else if (pDcChargingInfo->Type == _Type_CCS_2) {
+            log_info("\tCCS[%d] FW Rev = %s",
+                                         pDcChargingInfo->type_index,
+                                         ShmCcsData->V2GMessage_DIN70121[pDcChargingInfo->type_index].version);
+        }
+    }
+    log_info("\t================================ ");
+}
 int main(void)
 {
     bool isModelNameMatch = true;
@@ -4437,12 +4465,7 @@ int main(void)
     // 2. ouput fuse - 控制風扇轉速
     CreateRfidFork();
     // Main loop
-
-    log_info("\t======= Charger info ======= ");
-    log_info("\tSW Version = %s", fwVersion);
-    log_info("\tDebug Version = %s",DebugVersion);
-    log_info("\tModelName = %s", pSysConfig->ModelName);
-    log_info("\t============================ ");
+    showversion();
     CheckFwSlotStatusLog();
     //AdjustChargerCurrent();
     gettimeofday(&_cmdMainPriority_time, NULL);
@@ -4453,6 +4476,8 @@ int main(void)
 
     CreateWatchdog();
 
+    pSysInfo->OTPTemp = GUN_OTP_VALUE;
+    pSysInfo->OTPTempR = GUN_OTP_RECOVERY;
     for (;;) {
 
         CheckOcppStatus();
@@ -4625,7 +4650,6 @@ int main(void)
                 }
                 if (pSysWarning->Level == WARN_LV_ER) {
                     struct ChargingInfoData *pSelectedDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(pSysInfo->CurGunSelected);
-
                     if (gunIndex == pSysInfo->CurGunSelected) {
                         pSysInfo->SystemPage = _LCM_FIX;
                     } else if (pSelectedDcChargingInfo->SystemStatus != S_IDLE &&
@@ -4638,7 +4662,6 @@ int main(void)
                             systemPageRestoreInit();
                         }
                     }
-
                     ClearDetectPluginFlag();
 
                     if (pDcChargingInfo->SystemStatus != S_FAULT)

+ 384 - 382
EVSE/Projects/DD360Audi/Apps/Config.h

@@ -1,382 +1,384 @@
-/*
- * Config.h
- *
- *  Created on: 2019年4月23日
- *      Author: foluswen
- */
-#ifndef CONFIG_H_
-#define CONFIG_H_
-
-//------------------------------------------------------------------------------
-#include <stdint.h>
-
-//------------------------------------------------------------------------------
-//Dispenser simulation ev signal
-//------------------------------------------------------------------------------
-#define SIMULATION 0
-//------------------------------------------------------------------------------
-//independent common share memory key
-//------------------------------------------------------------------------------
-#define ShmCsuMeterKey                          2001
-#define ShmCommonKey                            2002
-
-//------------------------------------------------------------------------------
-#define TOTAL_QUANTITY_GUN                      4               //Max Count
-
-//------------------------------------------------------------------------------
-//system  runtime state
-//------------------------------------------------------------------------------
-#define MODE_BOOT                               (0)
-#define MODE_IDLE                               (1)
-#define MODE_AUTHORIZING                        (2)
-#define MODE_REASSIGN_CHECK                     (3)
-#define MODE_REASSIGN                           (4)
-#define MODE_PRECHARGE                          (5)
-#define MODE_PREPARE_FOR_EV                     (6)
-#define MODE_PREPARE_FOR_EVSE                   (7)
-#define MODE_CHARGING                           (8)
-#define MODE_TERMINATING                        (9)
-#define MODE_COMPLETE                           (10)
-#define MODE_ALARM                              (11)
-#define MODE_FAULT                              (12)
-#define MODE_RESERVATION                        (13)
-#define MODE_BOOKING                            (14)
-#define MODE_MAINTAIN                           (15)
-#define MODE_DEBUG                              (16)
-#define MODE_CCS_PRECHARGE_STEP0                (17)  // ready for ccs precharge processing, For D+ relay to precharge relay
-#define MODE_CCS_PRECHARGE_STEP1                (18)  // waitting for ev board inform to enter to charging, For precharge relay to D+ relay
-#define MODE_UPDATE                             (19)
-
-#define GFD_WAIT                                (0)
-#define GFD_PASS                                (1)
-#define GFD_FAIL                                (2)
-#define GFD_WARNING                             (3)
-
-#define PRECHARGE_WAIT                          (0)
-#define PRECHARGE_READY                         (1)
-#define PRECHARGE_PRERELAY_PASS                 (2)
-#define PRECHARGE_CHARELAY_PASS                 (3)
-
-#define BOOTTING                                (0)
-#define BOOT_COMPLETE                           (1)
-
-//------------------------------------------------------------------------------
-//common define
-//------------------------------------------------------------------------------
-#define ARRAY_SIZE(A)                           (sizeof(A) / sizeof(A[0]))
-
-#define PASS                                    (1)
-#define FAIL                                    (-1)
-
-#define START                                   (1)
-#define STOP                                    (0)
-
-#define YES                                     (1)
-#define NO                                      (0)
-
-#define NORMAL                                  (0)
-#define ABNORMAL                                (1)
-
-#define EQUAL                                   (0)
-
-#define NO_DEFINE                               (255)
-
-#define MtdBlockSize                            (0x300000) //(0x600000)
-
-//------------------------------------------------------------------------------
-//gun temperatures
-//------------------------------------------------------------------------------
-#define GUN_OTP_VALUE                           (150)
-#define GUN_OTP_RECOVERY                        (140)
-#define UNDEFINED_TEMP                          (255)
-#define TEMP_BOUNDARY                           (200)
-
-#define WARN_LV_NL                              (0) //normal state
-#define WARN_LV_WARN                            (1)
-#define WARN_LV_ER                              (2) //emergency state
-
-//------------------------------------------------------------------------------
-enum _SYSTEM_STATUS {
-    S_BOOTING = 0,
-    S_IDLE,
-    S_AUTHORIZING,
-    S_REASSIGN_CHECK,
-    S_REASSIGN,
-    S_PREPARNING,
-    S_PREPARING_FOR_EV,
-    S_PREPARING_FOR_EVSE,
-    S_CHARGING,
-    S_TERMINATING,
-    S_COMPLETE,
-    S_ALARM,
-    S_FAULT,
-    S_RESERVATION,
-    S_BOOKING,
-    S_MAINTAIN,
-    S_DEBUG,
-    S_CCS_PRECHARGE_ST0,
-    S_CCS_PRECHARGE_ST1,
-    S_UPDATE,
-    S_NONE,
-};
-
-enum _AC_SYSTEM_STATUS {
-    AC_SYS_NONE = 0,
-    AC_SYS_A,
-    AC_SYS_B,
-    AC_SYS_C,
-    AC_SYS_D,
-    AC_SYS_E
-};
-
-enum _GUN_TYPE {
-    _Type_Chademo = 0,
-    _Type_CCS_2,
-    _Type_GB,
-    _Type_AC,
-};
-
-enum _LCM_INDEX {
-    _LCM_INIT          = 0x00,
-    _LCM_IDLE          = 0x01,
-    _LCM_AUTHORIZING   = 0x02,
-    _LCM_AUTHORIZ_COMP = 0x03,
-    _LCM_AUTHORIZ_FAIL = 0x04,
-    _LCM_WAIT_FOR_PLUG = 0x05,
-    _LCM_PRE_CHARGE    = 0x06,
-    _LCM_CHARGING      = 0x07,
-    _LCM_COMPLETE      = 0x08,
-    _LCM_FIX           = 0x09,
-    _LCM_SELECT_GUN    = 0x0A,
-    _LCM_NONE          = 0xFF,
-};
-
-enum _SELF_TEST_SEQ {
-    _STEST_VERSION      = 0x00,
-    _STEST_AC_CONTACTOR = 0x01,
-    _STEST_PSU_DETECT   = 0x02,
-    _STEST_PSU_CAP      = 0x03,
-    _STEST_FAIL         = 0x04,
-    _STEST_COMPLETE     = 0xEE,
-};
-
-enum _MODULE_PSU_WORK_STEP {
-    INITIAL_START    = 0,
-    GET_PSU_COUNT    = 1,
-    GET_SYS_CAP      = 2,
-    BOOTING_COMPLETE = 3,
-
-    _WORK_CHARGING   = 10,
-
-    _TEST_MODE       = 20,
-
-    _NO_WORKING      = 254,
-    _INIT_PSU_STATUS = 255,
-};
-
-enum _OFFLINE_POLICY {
-    _OFFLINE_POLICY_LOCAL_LIST       = 0x00,
-    _OFFLINE_POLICY_PHIHONG_RFID_TAG = 0x01,
-    _OFFLINE_POLICY_FREE_CHARGING    = 0x02,
-    _OFFLINE_POLICY_NO_CHARGING      = 0x03,
-};
-
-enum _REASSIGNED_RESOURCE_STEP {
-    _REASSIGNED_NONE           = 0,  //
-    _REASSIGNED_PREPARE_M_TO_A = 1,  // 系統收到需要降載需求 (輸出總電流降低),PSU Task 收到將狀態切換至下個狀態
-    _REASSIGNED_GET_NEW_CAP    = 2,  // 充電中的重新取得屬於自己火線上的總能量並透過小板通知車端 - 超過10秒直接跳下一步
-    _REASSIGNED_ADJUST_M_TO_A  = 3,  // 模塊重新分配完成
-    _REASSIGNED_RELAY_M_TO_A   = 4,  // 切斷橋接的 Relay
-
-    _REASSIGNED_PREPARE_A_TO_M = 11,
-    _REASSIGNED_ADJUST_A_TO_M  = 12, // 模塊升壓
-    _REASSIGNED_RELAY_A_TO_M   = 13, // 搭接橋接的 Relay
-    _REASSIGNED_WAITING        = 14,
-    _REASSIGNED_COMP           = 15,
-};
-
-enum _MAIN_CHARGING_MODE {
-    _MAIN_CHARGING_MODE_MAX  = 0,
-    _MAIN_CHARGING_MODE_AVER = 1,
-};
-
-enum _EXTRA_ERR_PROCESS {
-    _EXTRA_ERR_PROCESS_NONE  = 0,
-    _EXTRA_ERR_PROCESS_INUVP = 1,
-    _EXTRA_ERR_PROCESS_INOVP = 2,
-};
-
-enum _CHARGER_TYPE {
-    _CHARGER_TYPE_IEC = 0,
-    _CHARGER_TYPE_UL  = 1,
-};
-
-enum _SYS_WIFI_MODE {
-    _SYS_WIFI_MODE_DISABLE = 0,
-    _SYS_WIFI_MODE_STATION = 1,
-    _SYS_WIFI_MODE_AP      = 2,
-};
-
-enum _LED_INTENSITY_LV {
-    _LED_INTENSITY_DARKEST   = 0,
-    _LED_INTENSITY_MEDIUM    = 1,
-    _LED_INTENSITY_BRIGHTEST = 2,
-};
-
-enum _CCS_COMM_PROTOCOL {
-    _CCS_COMM_V2GMessage_DIN70121      = 0x01,
-    _CCS_COMM_V2GMessage_ISO15118_2014 = 0x02,
-    _CCS_COMM_V2GMessage_ISO15118_2018 = 0x03
-};
-
-enum _ETHERNET_USAGE {
-    _ETHERNET_USAGE_NONE = 0,
-    _ETHERNET_USAGE_LAN,
-    _ETHERNET_USAGE_WIFI,
-    _ETHERNET_USAGE_3G_4g,
-};
-
-enum _PRIMARY_CHECK_TAG {
-    _PRIMARY_CHECK_TAG_AC_CONTACT   = 0,
-    _PRIMARY_CHECK_TAG_MAIN_BREAKER = 1,
-};
-
-enum _CCS_VERSION_CHECK_TAG {
-    _CCS_VERSION_CHECK_TAG_V015S0 = 0,
-    _CCS_VERSION_CHECK_TAG_V013S0 = 1,
-};
-
-enum RELAY_STATUS_ERROR_INDEX {
-    RELAY_SMR1_P_STATUS = 0,
-    RELAY_SMR1_N_STATUS = 1,
-    RELAY_SMR2_P_STATUS = 2,
-    RELAY_SMR2_N_STATUS = 3,
-    RELAY_PARA_P_STATUS = 4,
-    RELAY_PARA_N_STATUS = 5,
-};
-
-enum RELAY_STATUS_ERROR_TYPE {
-    RELAY_STATUS_ERROR_NONE    = 0,
-    RELAY_STATUS_ERROR_WELDING = 10,
-    RELAY_STATUS_ERROR_DRIVING = 11,
-};
-
-enum _CCS_TYPE {
-    _CCS_TYPE_CCS1 = 0,
-    _CCS_TYPE_CCS2 = 1,
-};
-
-//------------------------------------------------------------------------------
-//struct StructMeter {
-//    float curMeterValue;
-//    float newMeterValue;
-//    uint8_t isCalculation;
-//    float _chargingValue;
-//    float _curTotalCharging;
-//};
-
-//struct MeterInformation {
-//    struct StructMeter _meter[2];
-//    uint8_t isWorking;
-//};
-
-//struct DcCommonInformation {
-//    // check if the guns are of the same type
-//    uint8_t SysGunAreSameType;
-//    // to check the ccs version
-//    uint8_t CcsVersion;
-//    // for relay welding/driving check
-//    char RelayCheckStatus[6];
-//    char GunRelayWeldingOccur[2];
-//    char GunRelayDrivingOccur[2];
-//};
-
-typedef union {
-    uint32_t GunErrMessage;
-    struct {
-        // Chademo
-        uint8_t ChaGfdTrip: 1;
-        uint8_t ChaUvpFail: 1;
-        uint8_t ChaConnectOTP: 1;
-        uint8_t ChaConnectOVP: 1;
-        uint8_t ChaGfdWarning: 1;
-        uint8_t ChaRelayWeldingFault: 1;
-        uint8_t ChaRelayDrivingFault: 1;
-        uint8_t ChaConnectTempSensorFail: 1;
-
-        // CCS
-        uint8_t CCSGfdTrip : 1;
-        uint8_t CCSUvpFail : 1;
-        uint8_t CCSConnectOTP : 1;
-        uint8_t CCSConnectOVP : 1;
-        uint8_t CCSGfdWarning : 1;
-        uint8_t CCSRelayWeldingFault : 1;
-        uint8_t CCSRelayDrivingFault : 1;
-        uint8_t CCSConnectTempSensorFail : 1;
-
-        // GBT
-        uint8_t GBTGfdTrip : 1;
-        uint8_t GBTUvpFail : 1;
-        uint8_t GBTConnectOTP : 1;
-        uint8_t GBTConnectOVP : 1;
-        uint8_t GBTGfdWarning : 1;
-        uint8_t GBTRelayWeldingFault : 1;
-        uint8_t GBTRelayDrivingFault : 1;
-        uint8_t GBTConnectTempSensorFail : 1;
-    } GunBits;
-} EvBoardErrMsg;
-
-typedef union {
-    uint8_t AlarmState;
-    struct {
-        uint8_t EmergencyStop: 1;    //Power cabinet emergency stop
-        uint8_t DoorOpen: 1;         //Power cabinet emergency door open
-        uint8_t SystemL1InputOVP: 1; //Power cabinet system L1 input OVP
-        uint8_t SystemL2InputOVP: 1; //Power cabinet System L2 input OVP
-        uint8_t SystemL3InputOVP: 1; //Power cabinet System L3 input OVP
-        uint8_t PsuFailure: 1;       //Power cabinet PSU Failure Alarm
-        uint8_t Reserved: 2;
-    } StatusBit;
-} PowerAlarmState;
-
-typedef union {
-    uint8_t TempErrMsg;
-    struct {
-        uint8_t ChillerOTP: 1;            //chiller Temperature OVP
-        uint8_t ChillerTempSensorFail: 1; //Chiller temperature sensor failure
-        uint8_t Reserved: 6;
-    } StatusBit;
-} ChillerTempErr;
-
-typedef struct StChillerValve {
-    uint8_t MultiChillerGun; //0x80, 0: 沒有水冷槍, 1: 有水冷槍, 0x7F: 紀錄水冷槍數
-    uint8_t LeftTemp;  //左槍最高溫度
-    uint8_t RightTemp; //右槍最高溫度
-    uint8_t Reserved;
-} ChillerValve;
-
-typedef struct StPcPsuOutput { //from power cabinet PSU output
-    uint16_t Voltage;
-    uint16_t Current;
-} PcPsuOutput;
-
-typedef struct StDcCommonInfo {
-    uint8_t RebootCount;
-    uint8_t CcsVersion;
-    EvBoardErrMsg ConnectErrList[2]; //connector error list, 0: left gun, 1: right gun
-    uint8_t CheckRelayStatus[6]; //check Relay welding or driving fault
-    uint8_t GunRelayWeldingOccur[2];
-    uint8_t GunRelayDrivingOccur[2];
-    uint8_t ConnectorTemp[2][2];
-    uint8_t SystemTemp[4];
-    uint8_t SystemModeChange[2]; //for Module_EvRxComm
-    PowerAlarmState PowerAlarmState;
-    ChillerTempErr ChillerTempErr[2];
-    ChillerValve ChillerValve;
-    uint8_t TestTemperature; //ReadCmdline test, manual input value
-    uint8_t CcsTypeSaved[2];
-    PcPsuOutput PcPsuOutput[2];
-    uint8_t Reserved[3];
-} DcCommonInfo;
-
-#endif /* CONFIG_H_ */
+/*
+ * Config.h
+ *
+ *  Created on: 2019年4月23日
+ *      Author: foluswen
+ */
+#ifndef CONFIG_H_
+#define CONFIG_H_
+
+//------------------------------------------------------------------------------
+#include <stdint.h>
+
+//------------------------------------------------------------------------------
+//Dispenser simulation ev signal
+//------------------------------------------------------------------------------
+#define SIMULATION 0
+//------------------------------------------------------------------------------
+//independent common share memory key
+//------------------------------------------------------------------------------
+#define ShmCsuMeterKey                          2001
+#define ShmCommonKey                            2002
+
+//------------------------------------------------------------------------------
+#define TOTAL_QUANTITY_GUN                      4               //Max Count
+
+//------------------------------------------------------------------------------
+//system  runtime state
+//------------------------------------------------------------------------------
+#define MODE_BOOT                               (0)
+#define MODE_IDLE                               (1)
+#define MODE_AUTHORIZING                        (2)
+#define MODE_REASSIGN_CHECK                     (3)
+#define MODE_REASSIGN                           (4)
+#define MODE_PRECHARGE                          (5)
+#define MODE_PREPARE_FOR_EV                     (6)
+#define MODE_PREPARE_FOR_EVSE                   (7)
+#define MODE_CHARGING                           (8)
+#define MODE_TERMINATING                        (9)
+#define MODE_COMPLETE                           (10)
+#define MODE_ALARM                              (11)
+#define MODE_FAULT                              (12)
+#define MODE_RESERVATION                        (13)
+#define MODE_BOOKING                            (14)
+#define MODE_MAINTAIN                           (15)
+#define MODE_DEBUG                              (16)
+#define MODE_CCS_PRECHARGE_STEP0                (17)  // ready for ccs precharge processing, For D+ relay to precharge relay
+#define MODE_CCS_PRECHARGE_STEP1                (18)  // waitting for ev board inform to enter to charging, For precharge relay to D+ relay
+#define MODE_UPDATE                             (19)
+
+#define GFD_WAIT                                (0)
+#define GFD_PASS                                (1)
+#define GFD_FAIL                                (2)
+#define GFD_WARNING                             (3)
+
+#define PRECHARGE_WAIT                          (0)
+#define PRECHARGE_READY                         (1)
+#define PRECHARGE_PRERELAY_PASS                 (2)
+#define PRECHARGE_CHARELAY_PASS                 (3)
+
+#define BOOTTING                                (0)
+#define BOOT_COMPLETE                           (1)
+
+//------------------------------------------------------------------------------
+//common define
+//------------------------------------------------------------------------------
+#define ARRAY_SIZE(A)                           (sizeof(A) / sizeof(A[0]))
+
+#define PASS                                    (1)
+#define FAIL                                    (-1)
+
+#define START                                   (1)
+#define STOP                                    (0)
+
+#define YES                                     (1)
+#define NO                                      (0)
+
+#define NORMAL                                  (0)
+#define ABNORMAL                                (1)
+
+#define EQUAL                                   (0)
+
+#define NO_DEFINE                               (255)
+
+#define MtdBlockSize                            (0x300000) //(0x600000)
+
+//------------------------------------------------------------------------------
+//gun temperatures
+//------------------------------------------------------------------------------
+#define GUN_OTP_VALUE                           (150)
+#define GUN_OTP_RECOVERY                        (140)
+#define UNDEFINED_TEMP                          (255)
+#define TEMP_BOUNDARY                           (200)
+
+#define WARN_LV_NL                              (0) //normal state
+#define WARN_LV_WARN                            (1)
+#define WARN_LV_ER                              (2) //emergency state
+
+//------------------------------------------------------------------------------
+enum _SYSTEM_STATUS {
+    S_BOOTING = 0,
+    S_IDLE,
+    S_AUTHORIZING,
+    S_REASSIGN_CHECK,
+    S_REASSIGN,
+    S_PREPARNING,
+    S_PREPARING_FOR_EV,
+    S_PREPARING_FOR_EVSE,
+    S_CHARGING,
+    S_TERMINATING,
+    S_COMPLETE,
+    S_ALARM,
+    S_FAULT,
+    S_RESERVATION,
+    S_BOOKING,
+    S_MAINTAIN,
+    S_DEBUG,
+    S_CCS_PRECHARGE_ST0,
+    S_CCS_PRECHARGE_ST1,
+    S_UPDATE,
+    S_NONE,
+};
+
+enum _AC_SYSTEM_STATUS {
+    AC_SYS_NONE = 0,
+    AC_SYS_A,
+    AC_SYS_B,
+    AC_SYS_C,
+    AC_SYS_D,
+    AC_SYS_E
+};
+
+enum _GUN_TYPE {
+    _Type_Chademo = 0,
+    _Type_CCS_2,
+    _Type_GB,
+    _Type_AC,
+};
+
+enum _LCM_INDEX {
+    _LCM_INIT          = 0x00,
+    _LCM_IDLE          = 0x01,
+    _LCM_AUTHORIZING   = 0x02,
+    _LCM_AUTHORIZ_COMP = 0x03,
+    _LCM_AUTHORIZ_FAIL = 0x04,
+    _LCM_WAIT_FOR_PLUG = 0x05,
+    _LCM_PRE_CHARGE    = 0x06,
+    _LCM_CHARGING      = 0x07,
+    _LCM_COMPLETE      = 0x08,
+    _LCM_FIX           = 0x09,
+    _LCM_SELECT_GUN    = 0x0A,
+    _LCM_EMERGENCY     = 0x0B,
+    _LCM_DISCONNECT    = 0x0C,
+    _LCM_NONE          = 0xFF,
+};
+
+enum _SELF_TEST_SEQ {
+    _STEST_VERSION      = 0x00,
+    _STEST_AC_CONTACTOR = 0x01,
+    _STEST_PSU_DETECT   = 0x02,
+    _STEST_PSU_CAP      = 0x03,
+    _STEST_FAIL         = 0x04,
+    _STEST_COMPLETE     = 0xEE,
+};
+
+enum _MODULE_PSU_WORK_STEP {
+    INITIAL_START    = 0,
+    GET_PSU_COUNT    = 1,
+    GET_SYS_CAP      = 2,
+    BOOTING_COMPLETE = 3,
+
+    _WORK_CHARGING   = 10,
+
+    _TEST_MODE       = 20,
+
+    _NO_WORKING      = 254,
+    _INIT_PSU_STATUS = 255,
+};
+
+enum _OFFLINE_POLICY {
+    _OFFLINE_POLICY_LOCAL_LIST       = 0x00,
+    _OFFLINE_POLICY_PHIHONG_RFID_TAG = 0x01,
+    _OFFLINE_POLICY_FREE_CHARGING    = 0x02,
+    _OFFLINE_POLICY_NO_CHARGING      = 0x03,
+};
+
+enum _REASSIGNED_RESOURCE_STEP {
+    _REASSIGNED_NONE           = 0,  //
+    _REASSIGNED_PREPARE_M_TO_A = 1,  // 系統收到需要降載需求 (輸出總電流降低),PSU Task 收到將狀態切換至下個狀態
+    _REASSIGNED_GET_NEW_CAP    = 2,  // 充電中的重新取得屬於自己火線上的總能量並透過小板通知車端 - 超過10秒直接跳下一步
+    _REASSIGNED_ADJUST_M_TO_A  = 3,  // 模塊重新分配完成
+    _REASSIGNED_RELAY_M_TO_A   = 4,  // 切斷橋接的 Relay
+
+    _REASSIGNED_PREPARE_A_TO_M = 11,
+    _REASSIGNED_ADJUST_A_TO_M  = 12, // 模塊升壓
+    _REASSIGNED_RELAY_A_TO_M   = 13, // 搭接橋接的 Relay
+    _REASSIGNED_WAITING        = 14,
+    _REASSIGNED_COMP           = 15,
+};
+
+enum _MAIN_CHARGING_MODE {
+    _MAIN_CHARGING_MODE_MAX  = 0,
+    _MAIN_CHARGING_MODE_AVER = 1,
+};
+
+enum _EXTRA_ERR_PROCESS {
+    _EXTRA_ERR_PROCESS_NONE  = 0,
+    _EXTRA_ERR_PROCESS_INUVP = 1,
+    _EXTRA_ERR_PROCESS_INOVP = 2,
+};
+
+enum _CHARGER_TYPE {
+    _CHARGER_TYPE_IEC = 0,
+    _CHARGER_TYPE_UL  = 1,
+};
+
+enum _SYS_WIFI_MODE {
+    _SYS_WIFI_MODE_DISABLE = 0,
+    _SYS_WIFI_MODE_STATION = 1,
+    _SYS_WIFI_MODE_AP      = 2,
+};
+
+enum _LED_INTENSITY_LV {
+    _LED_INTENSITY_DARKEST   = 0,
+    _LED_INTENSITY_MEDIUM    = 1,
+    _LED_INTENSITY_BRIGHTEST = 2,
+};
+
+enum _CCS_COMM_PROTOCOL {
+    _CCS_COMM_V2GMessage_DIN70121      = 0x01,
+    _CCS_COMM_V2GMessage_ISO15118_2014 = 0x02,
+    _CCS_COMM_V2GMessage_ISO15118_2018 = 0x03
+};
+
+enum _ETHERNET_USAGE {
+    _ETHERNET_USAGE_NONE = 0,
+    _ETHERNET_USAGE_LAN,
+    _ETHERNET_USAGE_WIFI,
+    _ETHERNET_USAGE_3G_4g,
+};
+
+enum _PRIMARY_CHECK_TAG {
+    _PRIMARY_CHECK_TAG_AC_CONTACT   = 0,
+    _PRIMARY_CHECK_TAG_MAIN_BREAKER = 1,
+};
+
+enum _CCS_VERSION_CHECK_TAG {
+    _CCS_VERSION_CHECK_TAG_V015S0 = 0,
+    _CCS_VERSION_CHECK_TAG_V013S0 = 1,
+};
+
+enum RELAY_STATUS_ERROR_INDEX {
+    RELAY_SMR1_P_STATUS = 0,
+    RELAY_SMR1_N_STATUS = 1,
+    RELAY_SMR2_P_STATUS = 2,
+    RELAY_SMR2_N_STATUS = 3,
+    RELAY_PARA_P_STATUS = 4,
+    RELAY_PARA_N_STATUS = 5,
+};
+
+enum RELAY_STATUS_ERROR_TYPE {
+    RELAY_STATUS_ERROR_NONE    = 0,
+    RELAY_STATUS_ERROR_WELDING = 10,
+    RELAY_STATUS_ERROR_DRIVING = 11,
+};
+
+enum _CCS_TYPE {
+    _CCS_TYPE_CCS1 = 0,
+    _CCS_TYPE_CCS2 = 1,
+};
+
+//------------------------------------------------------------------------------
+//struct StructMeter {
+//    float curMeterValue;
+//    float newMeterValue;
+//    uint8_t isCalculation;
+//    float _chargingValue;
+//    float _curTotalCharging;
+//};
+
+//struct MeterInformation {
+//    struct StructMeter _meter[2];
+//    uint8_t isWorking;
+//};
+
+//struct DcCommonInformation {
+//    // check if the guns are of the same type
+//    uint8_t SysGunAreSameType;
+//    // to check the ccs version
+//    uint8_t CcsVersion;
+//    // for relay welding/driving check
+//    char RelayCheckStatus[6];
+//    char GunRelayWeldingOccur[2];
+//    char GunRelayDrivingOccur[2];
+//};
+
+typedef union {
+    uint32_t GunErrMessage;
+    struct {
+        // Chademo
+        uint8_t ChaGfdTrip: 1;
+        uint8_t ChaUvpFail: 1;
+        uint8_t ChaConnectOTP: 1;
+        uint8_t ChaConnectOVP: 1;
+        uint8_t ChaGfdWarning: 1;
+        uint8_t ChaRelayWeldingFault: 1;
+        uint8_t ChaRelayDrivingFault: 1;
+        uint8_t ChaConnectTempSensorFail: 1;
+
+        // CCS
+        uint8_t CCSGfdTrip : 1;
+        uint8_t CCSUvpFail : 1;
+        uint8_t CCSConnectOTP : 1;
+        uint8_t CCSConnectOVP : 1;
+        uint8_t CCSGfdWarning : 1;
+        uint8_t CCSRelayWeldingFault : 1;
+        uint8_t CCSRelayDrivingFault : 1;
+        uint8_t CCSConnectTempSensorFail : 1;
+
+        // GBT
+        uint8_t GBTGfdTrip : 1;
+        uint8_t GBTUvpFail : 1;
+        uint8_t GBTConnectOTP : 1;
+        uint8_t GBTConnectOVP : 1;
+        uint8_t GBTGfdWarning : 1;
+        uint8_t GBTRelayWeldingFault : 1;
+        uint8_t GBTRelayDrivingFault : 1;
+        uint8_t GBTConnectTempSensorFail : 1;
+    } GunBits;
+} EvBoardErrMsg;
+
+typedef union {
+    uint8_t AlarmState;
+    struct {
+        uint8_t EmergencyStop: 1;    //Power cabinet emergency stop
+        uint8_t DoorOpen: 1;         //Power cabinet emergency door open
+        uint8_t SystemL1InputOVP: 1; //Power cabinet system L1 input OVP
+        uint8_t SystemL2InputOVP: 1; //Power cabinet System L2 input OVP
+        uint8_t SystemL3InputOVP: 1; //Power cabinet System L3 input OVP
+        uint8_t PsuFailure: 1;       //Power cabinet PSU Failure Alarm
+        uint8_t Reserved: 2;
+    } StatusBit;
+} PowerAlarmState;
+
+typedef union {
+    uint8_t TempErrMsg;
+    struct {
+        uint8_t ChillerOTP: 1;            //chiller Temperature OVP
+        uint8_t ChillerTempSensorFail: 1; //Chiller temperature sensor failure
+        uint8_t Reserved: 6;
+    } StatusBit;
+} ChillerTempErr;
+
+typedef struct StChillerValve {
+    uint8_t MultiChillerGun; //0x80, 0: 沒有水冷槍, 1: 有水冷槍, 0x7F: 紀錄水冷槍數
+    uint8_t LeftTemp;  //左槍最高溫度
+    uint8_t RightTemp; //右槍最高溫度
+    uint8_t Reserved;
+} ChillerValve;
+
+typedef struct StPcPsuOutput { //from power cabinet PSU output
+    uint16_t Voltage;
+    uint16_t Current;
+} PcPsuOutput;
+
+typedef struct StDcCommonInfo {
+    uint8_t RebootCount;
+    uint8_t CcsVersion;
+    EvBoardErrMsg ConnectErrList[2]; //connector error list, 0: left gun, 1: right gun
+    uint8_t CheckRelayStatus[6]; //check Relay welding or driving fault
+    uint8_t GunRelayWeldingOccur[2];
+    uint8_t GunRelayDrivingOccur[2];
+    uint8_t ConnectorTemp[2][2];
+    uint8_t SystemTemp[4];
+    uint8_t SystemModeChange[2]; //for Module_EvRxComm
+    PowerAlarmState PowerAlarmState;
+    ChillerTempErr ChillerTempErr[2];
+    ChillerValve ChillerValve;
+    uint8_t TestTemperature; //ReadCmdline test, manual input value
+    uint8_t CcsTypeSaved[2];
+    PcPsuOutput PcPsuOutput[2];
+    uint8_t Reserved[3];
+} DcCommonInfo;
+
+#endif /* CONFIG_H_ */

+ 48 - 4
EVSE/Projects/DD360Audi/Apps/Define/define.h

@@ -897,9 +897,10 @@ struct SysInfoData
 	unsigned char BootingStatus;			// 0 : booting, 1 : Initializing Complete.
 	unsigned char AuthorizeFlag;			// 0 : None, 1 : Authorizing
 	unsigned char FactoryConfiguration;	//0: normal, 1: trigger, charger will return the configuration to factory default if trigger
-	float InputVoltageR;			//0~655.35 volt
-	float InputVoltageS;				//0~655.35 volt
-	float InputVoltageT;				//0~655.35 volt
+	float InputVoltageR;                    //0~655.35 volt
+	float InputVoltageS;                    //0~655.35 volt
+	float InputVoltageT;                    //0~655.35 volt
+	float InputVoltageDc;                   //0~655.35 volt
 	unsigned int SystemFanRotaSpeed;		//0 ~ 65535 RPM
 	unsigned int PsuFanRotaSpeed;			//0 ~ 65535 RPM
 	unsigned char AuxPower5V;				//0 ~ 255 volt
@@ -983,6 +984,8 @@ struct SysInfoData
     CabinetMiscCommand      CabinetMicsStatus;
     struct LocalSharingInfo localSharingInfo;           // Local power sharing info structure
     DC_Meter_Info DcMeterInfo[4];
+    unsigned char           OTPTemp;                    // OTP Temperature 
+    unsigned char           OTPTempR;                   // OTP Recovery Temperature
 };
 
 struct SysConfigAndInfo
@@ -1169,7 +1172,7 @@ struct FaultCodeData
 };
 
 /*
-char AlarmStatusCode[128][6]=
+char AlarmStatusCode[160][6]=
 {
 	"012200",	//System L1 input OVP
 	"012201",	//System L2 input OVP
@@ -1299,6 +1302,38 @@ char AlarmStatusCode[128][6]=
     "012325",   // Connector 2 detects abnormal voltage on the output line
     "012326",   // System task is lost
     "012327",   // reserved
+    "012328",   // reserved
+    "012329",   // reserved
+    "012330",   // reserved
+    "012331",   // reserved
+    "012332",   // reserved
+    "012333",   // reserved
+    "012334",   // reserved
+    "012335",   // reserved
+    "012336",   // reserved
+    "012337",   // reserved
+    "012338",   // reserved
+    "012339",   // reserved
+    "012340",   // reserved
+    "012341",   // reserved
+    "012342",   // reserved
+    "012343",   // reserved
+    "012344",   // AC: Meter IC communication timeout
+    "012345",   // AC: Pilot negative error
+    "012346",   // reserved
+    "012347",   // reserved
+    "012348",   // reserved
+    "012349",   // reserved
+    "012350",   // reserved
+    "012351",   // reserved
+    "012352",   // reserved
+    "012353",   // reserved
+    "012354",   // reserved
+    "012355",   // reserved
+    "012356",   // reserved
+    "012357",   // reserved
+    "012358",   // reserved
+    "012359",   // reserved
 };
 */
 struct AlarmCodeData
@@ -4524,6 +4559,13 @@ struct StructSignedFirmwareStatusNotification
     int requestId;
 };
 
+struct StructSessionTarget
+{
+	unsigned char		targetSoc;			// Unit: %,   		0 is unlimit
+	unsigned short		targetEnergy;		// Unit: KWH		0 is unlimit
+	unsigned short		targetDuration;		// Unit: Minutes	0 is unlimit
+};
+
 struct OCPP16Data
 {
     unsigned char                           OcppServerURL[512];     //http: non-secure OCPP 1.5-S, https: secure OCPP 1.5-S, ws: non-secure OCPP 1.6-J, wss: secure OCPP 1.6-J"
@@ -4712,6 +4754,7 @@ struct OCPP16Data
     struct StructSecurityEventNotification          SecurityEventNotification;
     struct StructSignCertificate                    SignCertificate;
     struct StructSignedFirmwareStatusNotification   SignedFirmwareStatusNotification;
+    struct StructSessionTarget	                    SessionTarget[CONNECTOR_QUANTITY];
 };
 
 
@@ -6090,6 +6133,7 @@ struct OCPP20Data
 	struct UpdateFirmware_20					UpdateFirmware;
 	struct ChargingProfileType                  SmartChargingProfile[CONNECTOR_QUANTITY];
 	struct ChargingProfileType                  MaxChargingProfile;
+	struct StructSessionTarget	                SessionTarget[CONNECTOR_QUANTITY];
 };
 
 

+ 83 - 22
EVSE/Projects/DD360Audi/Apps/ModuleLcmCtrl/Module_LcmControl.c

@@ -225,9 +225,21 @@ uint8_t _select_gun_btn         = 70;
 uint8_t _emergency_disable_map  = 72;
 // For replug
 struct timespec showReplugStrTimer;
-short __show_replugString_value = 0x0460;
-uint8_t _showReplugStr_1 = 74;
-uint8_t _showReplugStr_2 = 75;
+struct timespec showFullTargetTimer;
+short __show_StatusString_value_1 = 0x0460;
+short __show_StatusString_value_2 = 0x0462;
+uint8_t _showfulltarget_1       = 73;
+uint8_t _showfulltarget_2       = 74;
+uint8_t _showReplugStr_1        = 75;
+uint8_t _showReplugStr_2        = 76;
+// Select Gun for Audi
+short __show_selectgun_value    = 0x0464;
+uint8_t _showselectgun_left     = 77;
+uint8_t _showselectgun_right    = 78;
+// Wait for gun plugin Audi
+short __show_waitgunplug_value    = 0x0468;
+uint8_t _showwaitgunplug_left     = 80;
+uint8_t _showwaitgunplug_right    = 81;
 
 //#define log_info(format, args...) StoreLogMsg("[%s:%d][%s][Info] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
 //#define log_warn(format, args...) StoreLogMsg("[%s:%d][%s][Warn] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
@@ -874,14 +886,37 @@ void RunReplugStringFunction(bool isRun)
     if (isRun) {
         int time = GetTimeoutValue(&showReplugStrTimer);
         if (time >=1 && time <2) {
-            ChangeDisplay2Value(__show_replugString_value, _showReplugStr_1);
+            ChangeDisplay2Value(__show_StatusString_value_1, _showReplugStr_1);
+            ChangeDisplay2Value(__show_StatusString_value_2, _showReplugStr_2);
         } else if (time < 1) {
-            ChangeDisplay2Value(__show_replugString_value, _showReplugStr_2);
+            ChangeDisplay2Value(__show_StatusString_value_1, _disappear);
+            ChangeDisplay2Value(__show_StatusString_value_2, _disappear);
         } else
             GetTimespecFunc(&showReplugStrTimer);
 
-    } else
-        ChangeDisplay2Value(__show_replugString_value, _disappear);
+    } else {
+        ChangeDisplay2Value(__show_StatusString_value_1, _disappear);
+        ChangeDisplay2Value(__show_StatusString_value_2, _disappear);
+    }
+}
+void RunFullTargetFunction(bool isRun)
+{
+    if (isRun) {
+        int time = GetTimeoutValue(&showFullTargetTimer);
+        if (time >=1 && time <2) {
+            ChangeDisplay2Value(__show_StatusString_value_1, _showfulltarget_1 );
+            ChangeDisplay2Value(__show_StatusString_value_2, _showfulltarget_2);
+        } else if (time < 1) {
+            ChangeDisplay2Value(__show_StatusString_value_1, _disappear);
+            ChangeDisplay2Value(__show_StatusString_value_2, _disappear);
+
+        } else
+            GetTimespecFunc(&showFullTargetTimer);
+
+    } else {
+        ChangeDisplay2Value(__show_StatusString_value_1, _disappear);
+        ChangeDisplay2Value(__show_StatusString_value_2, _disappear);
+    }
 }
 
 /**
@@ -1165,11 +1200,11 @@ void RefreshConnStatus()
     // Wifi priority is higher than Ethernet
 #if defined DD360 ||defined DD360Audi || defined DD360ComBox
     uint8_t i = 0;
-    uint8_t ehtStatus = 0;
+    uint8_t ethstatus = 0;
 
     for (i = 0; i < pSysWarning->WarningCount; i++) {
         if (memcmp(&pSysWarning->WarningCode[i][0], "012304", 6) == 0) {
-            ehtStatus = 1;
+            ethstatus = 1;
             //if (ShmSelectGunInfo->EthDevStatus.Ethernet != DEV_ST_DISABLE) {
             //    ShmSelectGunInfo->EthDevStatus.Ethernet = DEV_ST_ENABLE_NO_USE;
             //}
@@ -1185,7 +1220,7 @@ void RefreshConnStatus()
         ChangeDisplay2Value(__conn_status, _disconnect);
     }
 
-    if (ehtStatus == 1) {
+    if (ethstatus == 1) {
         if (ShmSelectGunInfo->EthDevStatus.Ethernet != DEV_ST_DISABLE) {
             ChangeDisplay2Value(__ethernet_status, _eth_disconnect);
         }
@@ -1708,6 +1743,9 @@ void ProcessPageInfo()
 {
     _page_reload = IsPageReloadChk();
     pAcChargingInfo = (struct ChargingInfoData *)GetAcChargingInfoData(0);
+    struct InfoCodeData *pInfoCode = (struct InfoCodeData *)GetShmInfoCodeData();
+    struct AlarmCodeData *pAlarmCode = (struct AlarmCodeData *)GetShmAlarmCodeData();
+    uint8_t i;
 
     // 隨插即充 - 可省略該按鈕 //DS60-120 add
     if (pSysConfig->AuthorisationMode == AUTH_MODE_ENABLE) {
@@ -1753,7 +1791,12 @@ void ProcessPageInfo()
         } else {
             ChangeDisplay2Value(__main_app, _main_none_app);
         }
-
+#if defined DD360Audi
+        if(pSysInfo->CurGunSelected == LEFT_GUN_NUM )
+            ChangeDisplay2Value(__show_selectgun_value, _showselectgun_left);
+        else if (pSysInfo->CurGunSelected == RIGHT_GUN_NUM )
+            ChangeDisplay2Value(__show_selectgun_value, _showselectgun_right);
+#endif
         //if (FirstPageChanged() == YES || needReloadQr || _page_reload) {
         if (pSysConfig->isQRCode) {
             needReloadQr = false;
@@ -1800,6 +1843,12 @@ void ProcessPageInfo()
     }
     break;
     case _LCM_WAIT_FOR_PLUG: {
+ #if defined DD360Audi
+        if(pSysInfo->CurGunSelected == LEFT_GUN_NUM )
+            ChangeDisplay2Value(__show_waitgunplug_value, _showwaitgunplug_left);
+        else if (pSysInfo->CurGunSelected == RIGHT_GUN_NUM )
+            ChangeDisplay2Value(__show_waitgunplug_value, _showwaitgunplug_right);
+#endif
         FirstPageChanged();
         if (pSysConfig->AuthorisationMode == AUTH_MODE_DISABLE) {
             // 新增隨插即充功能預設在等待插槍頁面在開啟
@@ -2073,12 +2122,16 @@ void ProcessPageInfo()
                     }
 #ifdef DD360Audi
                     // Warming Occur in prepare or precharing state, turn into complete mode
-                    if (pDcChargingInfo->Replug_flag) {
-                        RunReplugStringFunction(true);
+                    if (pInfoCode->InfoEvents.bits.Stop_by_EV_with_unknow_reason) {
+                        RunFullTargetFunction(true);
                     } else {
-                        RunReplugStringFunction(false);
+                        RunFullTargetFunction(false);
+                        if (pDcChargingInfo->Replug_flag) {
+                            RunReplugStringFunction(true);
+                        } else {
+                            RunReplugStringFunction(false);
+                        }
                     }
-#else
 #endif					
                 }
             }
@@ -2115,14 +2168,23 @@ void ProcessPageInfo()
         }
     }
     break;
-
     case _LCM_FIX:
-        // AUDI_LCM_CHANGE
+#if defined DD360Audi
+        // For Emergency Button
         if (ShmPrimaryMcuData->InputDet.bits.EmergencyButton == 1) {
-            ChangeDisplay2Value(_emergency_map, _emergency_disable_map);
-        } else {
-            ChangeDisplay2Value(_emergency_map, _disappear);
+            ChangeToOtherPage(_LCM_EMERGENCY);
+            break;
         }
+        // For Network Disconnect
+        for (i = 0; i < pSysWarning->WarningCount; i++) {
+            if (memcmp(&pSysWarning->WarningCode[i][0], "012304", 6) == 0 || 
+                memcmp(&pSysWarning->WarningCode[i][0], "042304", 6) == 0) {
+                ChangeToOtherPage(_LCM_DISCONNECT);
+            break;
+            }
+        }
+#endif
+
         break;
     }
 }
@@ -2294,7 +2356,6 @@ int main(void)
 
                 ChangeWarningFunc();
             }
-
             // 頁面資訊處理
             ProcessPageInfo();
 
@@ -2323,7 +2384,7 @@ int main(void)
     }
 
 #ifndef DD360ComBox
-            ShmStatusCodeData->AlarmCode.AlarmEvents.bits.LcmModuleCommFail = true;
+    ShmStatusCodeData->AlarmCode.AlarmEvents.bits.LcmModuleCommFail = true;
 #endif
     log_info("Close LCM Uart Port");
     CloseCommunicationLcmPort();

+ 1468 - 1416
EVSE/Projects/DD360Audi/Apps/ReadCmdline.c

@@ -1,1416 +1,1468 @@
-/*
- * Main.c
- *
- *  Created on: 2019年8月6日
- *      Author: 7564
- */
-
-
-#include <sys/time.h>
-#include <sys/timeb.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-#include <sys/ioctl.h>
-#include <sys/socket.h>
-#include <sys/ipc.h>
-#include <sys/shm.h>
-#include <sys/shm.h>
-#include <sys/mman.h>
-#include <linux/wireless.h>
-#include <arpa/inet.h>
-#include <netinet/in.h>
-
-#include <unistd.h>
-#include <stdarg.h>
-#include <stdio.h>      /*標準輸入輸出定義*/
-#include <stdlib.h>     /*標準函數庫定義*/
-#include <stdint.h>
-#include <unistd.h>     /*Unix 標準函數定義*/
-#include <fcntl.h>      /*檔控制定義*/
-#include <termios.h>    /*PPSIX 終端控制定義*/
-#include <errno.h>      /*錯誤號定義*/
-#include <errno.h>
-#include <string.h>
-#include <time.h>
-#include <ctype.h>
-#include <ifaddrs.h>
-#include <math.h>
-#include <stdbool.h>
-
-#include "./ShareMemory/shmMem.h"
-#include "./Define/define.h"
-#include "./SelectGun/SelectGun.h"
-#include "Config.h"
-
-//------------------------------------------------------------------------------
-#define CMD_KEY_WAIT                                (1)
-#define CMD_KEY_DONT_WAIT                           (0)
-
-#define DEFAULT_AC_INDEX                            (2)
-
-#define AUTORUN_STEP1_TIME_START                    (140)             // Minutes
-#define AUTORUN_STEP1_TIME_END                      (150)
-#define AUTORUN_STEP2_TIME_START                    (210)
-#define AUTORUN_STEP2_TIME_END                      (410)
-#define AUTORUN_END_TIME                            (480)
-#define AUTORUN_CYCLE_COUNT                         (30)
-
-#define TTY_PATH                                    "/dev/tty"
-#define STTY_US                                     "stty raw -echo -F "
-#define STTY_DEF                                    "stty -raw echo -F "
-
-//------------------------------------------------------------------------------
-uint8_t _curAutoRunCount = 0;
-uint8_t _usingAutoRun = 0;
-struct timeval _autoTime;
-
-static struct SysConfigData *pSysConfig = NULL;
-static struct SysInfoData *pSysInfo = NULL;
-static struct WARNING_CODE_INFO *pSysWarning = NULL;
-
-static struct AlarmCodeData *pAlarmCode = NULL;
-
-static struct PrimaryMcuData *ShmPrimaryMcuData = NULL;
-static struct CHAdeMOData *ShmCHAdeMOData = NULL;
-static struct CcsData *ShmCcsData = NULL;
-static struct GBTData *ShmGBTData = NULL;
-static struct FanModuleData *ShmFanModuleData = NULL;
-static struct RelayModuleData *ShmRelayModuleData = NULL;
-static struct LedModuleData *ShmLedModuleData = NULL;
-static struct PsuData *ShmPsuData = NULL;
-static struct OCPP16Data *ShmOCPP16Data = NULL;
-static SelectGunInfo *ShmSelectGunInfo = NULL;
-static DcCommonInfo *ShmDcCommonData = NULL;
-
-static struct ChargingInfoData *pDcChargingInfo = NULL;
-static struct ChargingInfoData *pAcChargingInfo = NULL;
-
-static char newString[8][16] = {0};
-
-//------------------------------------------------------------------------------
-static 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;
-}
-
-static void get_char(char *word)
-{
-    fd_set rfds;
-    struct timeval tv;
-
-    FD_ZERO(&rfds);
-    FD_SET(0, &rfds);
-    tv.tv_sec = 0;
-    tv.tv_usec = 10; //wait input timout time
-
-    //if input
-    if (select(1, &rfds, NULL, NULL, &tv) > 0) {
-        fgets(word, 128, stdin);
-    }
-}
-
-static uint8_t helpCmd(void)
-{
-    if (strcmp(newString[0], "?") == 0 ||
-            strcmp(newString[0], "help") == 0 ||
-            strcmp(newString[0], "h") == 0) {
-        return YES;
-    }
-
-    return NO;
-}
-
-static uint8_t exitCmd(void)
-{
-    if (strcmp(newString[0], "c") == EQUAL ||
-            strcmp(newString[0], "C") == EQUAL ||
-            strncmp(&newString[0][0], "exit", 4) == EQUAL
-       ) {
-        return YES;
-    }
-
-    return NO;
-}
-
-static uint8_t readCmdKey(uint8_t state)
-{
-    char word[128] = {0};
-    int i = 0, j = 0, ctr = 0;
-
-    memset(word, 0, sizeof(word));
-    if (state == CMD_KEY_WAIT) {
-        fgets(word, sizeof(word), stdin);
-    } else if (state == CMD_KEY_DONT_WAIT) {
-        get_char(word);
-
-        if (strlen(word) == 0) {
-            //usleep(50000);
-            return NO;
-        }
-    }
-
-    memset(newString, 0, sizeof(newString));
-
-    strcpy(newString[1], "-1");
-    strcpy(newString[2], "-1");
-    for (i = 0; i <= (strlen(word)); i++) {
-        if (word[i] == ' ' ||
-                word[i] == '\0' ||
-                word[i] == '\r' ||
-                word[i] == '\n' ||
-                word[i] == 10) {
-            newString[ctr][j] = '\0';
-            ctr++;
-            j = 0;
-        } else {
-            newString[ctr][j] = word[i];
-            j++;
-        }
-    }
-
-    return YES;
-}
-
-unsigned long GetTimeoutValue(struct timeval _sour_time)
-{
-    struct timeval _end_time;
-    gettimeofday(&_end_time, NULL);
-
-    return (_end_time.tv_sec - _sour_time.tv_sec);
-}
-
-void RunStatusProc(char *v1, char *v2)
-{
-    printf("OrderCharging = %d \n", pSysInfo->OrderCharging);
-    printf("WaitForPlugit = %d \n", pSysInfo->WaitForPlugit);
-    if (strcmp(v1, "ac") == 0) {
-        pAcChargingInfo = (struct ChargingInfoData *)GetAcChargingInfoData(0);
-        //if (!FindAcChargingInfoData(0, &ac_chargingInfo[0])) {
-        //    printf("FindChargingInfoData (AC) false \n");
-        //}
-        printf("AC Status = %d \n", pAcChargingInfo->ConnectorPlugIn);
-        return;
-    }
-
-    int _index = atoi(v1);
-
-    if (_index <= 1) {
-        //if (!FindChargingInfoData(_index, &_chargingData[0])) {
-        //    printf ("FindChargingInfoData error\n");
-        //    return;
-        //}
-        pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_index);
-
-        if (strcmp(v2, "-1") == 0 || strcmp(v2, "") == 0) {
-            // get
-            printf ("index = %x, status = %x (%d)\n",
-                    _index,
-                    pDcChargingInfo->SystemStatus,
-                    pDcChargingInfo->IsAvailable);
-            printf ("SystemTimeoutFlag = %d, PageIndex = %d\n",
-                    pSysInfo->SystemTimeoutFlag, pSysInfo->PageIndex);
-        } else {
-            // set
-            pDcChargingInfo->SystemStatus = atoi(v2);
-        }
-    } else {
-        //if (!FindAcChargingInfoData(0, &ac_chargingInfo[0])) {
-        //    printf("FindChargingInfoData (AC) false \n");
-        //}
-        pAcChargingInfo = (struct ChargingInfoData *)GetAcChargingInfoData(0);
-
-        if (strcmp(v2, "-1") == 0 || strcmp(v2, "") == 0) {
-            // get
-            printf ("AC Type, status = %x (%d)\n",
-                    pAcChargingInfo->SystemStatus,
-                    pAcChargingInfo->IsAvailable);
-        } else {
-            // set
-            pAcChargingInfo->SystemStatus = atoi(v2);
-        }
-    }
-}
-
-void RunCardProc(char *v1, char *v2)
-{
-    if (strcmp(v1, "-1") == 0 || strcmp(v1, "") == 0) {
-        if (pSysInfo->WaitForPlugit) {
-            pSysInfo->WaitForPlugit = 0x00;
-            printf ("SysInfo.WaitForPlugit = %x \n", pSysInfo->WaitForPlugit);
-        } else {
-            pSysInfo->WaitForPlugit = 0x01;
-            printf ("SysInfo.WaitForPlugit = %x \n", pSysInfo->WaitForPlugit);
-        }
-    } else {
-        strcpy((char *)pSysConfig->UserId, "");
-        memcpy((char *)pSysConfig->UserId, v1, strlen(v1));
-        pSysConfig->UserId[strlen(v1)] = '\0';
-        printf("StartUserId = %s \n", pSysConfig->UserId);
-    }
-}
-
-void RunGunPlugitProc(char *v1, char *v2)
-{
-    if (strcmp(v1, "ac") == 0) {
-        //if (!FindAcChargingInfoData(0, &ac_chargingInfo[0])) {
-        //    printf("FindChargingInfoData (AC) false \n");
-        //}
-        pAcChargingInfo = (struct ChargingInfoData *)GetAcChargingInfoData(0);
-
-        if (strcmp(v2, "-1") == 0 || strcmp(v2, "") == 0) {
-            // get
-            printf("ConnectorPlugIn = %d \n", pAcChargingInfo->ConnectorPlugIn);
-        } else {
-            // set
-            pAcChargingInfo->ConnectorPlugIn = atoi(v2);
-        }
-        return;
-    }
-
-    int _index = atoi(v1);
-    //if (!FindChargingInfoData(_index, &_chargingData[0])) {
-    //    printf("FindChargingInfoData error\n");
-    //    return;
-    //}
-    pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_index);
-
-    if (strcmp(v2, "-1") == 0 || strcmp(v2, "") == 0) {
-        // get
-        printf("index = %x, plug it = %x\n",
-               _index,
-               pDcChargingInfo->ConnectorPlugIn);
-    } else {
-        // set
-        pDcChargingInfo->ConnectorPlugIn = atoi(v2);
-    }
-}
-
-void GetGunLockStatusProc(char *v1, char *v2)
-{
-    int _index = atoi(v1);
-    //if (!FindChargingInfoData(_index, &_chargingData[0])) {
-    //    printf("FindChargingInfoData error\n");
-    //    return;
-    //}
-    pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_index);
-
-    if (strcmp(v2, "-1") != 0 && strcmp(v2, "") != 0) {
-        pDcChargingInfo->GunLocked = atoi(v2);
-    }
-
-    printf("Gun Locked Status = %d \n", pDcChargingInfo->GunLocked);
-}
-
-void SetSystemIDProc()
-{
-    char *systemId = "Alston_Test";
-    memcpy(&pSysConfig->SystemId, systemId, strlen(systemId));
-}
-
-void RunSelfProc()
-{
-    printf("self test status = %x\n", pSysInfo->SelfTestSeq);
-}
-
-void GetFwVerProc(void)
-{
-    int _index = 0;
-    int isContinue = 1;
-    char *usageMsg = "Usage:\n"
-                     "      model\n"
-                     "      407\n"
-                     "      conn index, ex: conn 0 | 1\n"
-                     "      relay\n"
-                     "      fan\n"
-                     "      dc\n"
-                     "      led\n"
-                     "      ac\n"
-                     "      exit | c | C\n"
-                     "      help | ? | h\n";
-
-    while (isContinue) {
-        if (readCmdKey(CMD_KEY_WAIT) == NO) {
-            continue;
-        }
-
-        if (strcmp(newString[0], "407") == 0) {
-            printf("407 FW Version = %s\n", ShmPrimaryMcuData->version);
-        } else if (strcmp(newString[0], "model") == 0) {
-            printf("ModelName = %s\r\n", pSysConfig->ModelName);
-        } else if (strcmp(newString[0], "conn") == 0) {
-            if (strcmp(newString[1], "-1") == 0  ||
-                    strcmp(newString[1], "") == 0 ||
-                    atoi(newString[1]) >= pSysConfig->TotalConnectorCount
-               ) {
-                printf("index over flow\r\n");
-                continue;
-            }
-
-            _index = atoi(newString[1]);
-
-            if (_index == 0) {
-                printf("Gun 0 FW Version = %s \n", pSysInfo->Connector1FwRev);
-            } else if (_index == 1) {
-                printf("Gun 1 FW Version = %s \n", pSysInfo->Connector2FwRev);
-            }
-        } else if (strcmp(newString[0], "relay") == 0) {
-            printf("RB Version = %s \n", pSysInfo->RelayModuleFwRev);
-        } else if (strcmp(newString[0], "fan") == 0) {
-            printf("FAN Version = %s \n", pSysInfo->FanModuleFwRev);
-        } else if (strcmp(newString[0], "dc") == 0) {
-            printf("DC Main Version = %s \n", pSysInfo->CsuRootFsFwRev);
-        } else if (strcmp(newString[0], "led") == 0) {
-            printf("LED Version = %s \n", pSysInfo->LedModuleFwRev);
-        } else if (strcmp(newString[0], "ac") == 0) {
-            pAcChargingInfo = (struct ChargingInfoData *)GetAcChargingInfoData(0);
-
-            printf("AC Version = %s \n", pAcChargingInfo->version);
-        } else if (exitCmd() == YES) {
-            return;
-        } else if (helpCmd() == YES) {
-            printf ("%s\n", usageMsg);
-        }
-
-    }//while
-}
-
-void CreateOneError(char *v1)
-{
-    int value = atoi(v1);
-
-    pAlarmCode->AlarmEvents.bits.SystemL1InputOVP = value;
-    pSysConfig->BillingData.isBilling = value;
-}
-
-void GetAuthorizeFlag(char *v1)
-{
-    if (strcmp(v1, "-1") == 0 || strcmp(v1, "") == 0) {
-        printf("AuthorizeFlag = %d \n", pSysInfo->AuthorizeFlag);
-    } else {
-        pSysInfo->AuthorizeFlag = atoi(v1);
-    }
-}
-
-void GetRelayStatus(char *v1)
-{
-    int _index = atoi(v1);
-    //if (!FindChargingInfoData(_index, &_chargingData[0])) {
-    //    printf("FindChargingInfoData error\n");
-    //    return;
-    //}
-    pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_index);
-
-    printf("RelayK1K2Status = %d \n", pDcChargingInfo->RelayK1K2Status);
-    printf("RelayKPK2Status = %d \n", pDcChargingInfo->RelayKPK2Status);
-}
-
-void FwUpdateFlagProc()
-{
-    pSysInfo->FirmwareUpdate = 0x01;
-}
-
-void CheckAcStatus(char *v1)
-{
-    if (strcmp(v1, "-1") == 0 || strcmp(v1, "") == 0) {
-        printf("AC Status = %d \n", pSysInfo->AcContactorStatus);
-    }
-}
-
-void SetCableChkStatus(char *v1, char *v2)
-{
-    int _index = atoi(v1);
-    //if (!FindChargingInfoData(_index, &_chargingData[0])) {
-    //    printf ("FindChargingInfoData error\n");
-    //    return;
-    //}
-    pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_index);
-
-    pDcChargingInfo->GroundFaultStatus = atoi(v2);
-}
-
-void SetChargingInfoCCID(char *v1, char *v2)
-{
-    int _index = atoi(v1);
-    //if (!FindChargingInfoData(_index, &_chargingData[0])) {
-    //    printf ("FindChargingInfoData error\n");
-    //    return;
-    //}
-    pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_index);
-
-    memcpy(pDcChargingInfo->EVCCID, v2, 8);
-    pDcChargingInfo->EVCCID[8] = '\0';
-}
-
-void SetPowerValue(char *v1, char *v2)
-{
-    int _index = atoi(v1);
-    float _Current = atof(v2);
-
-    //if (!FindChargingInfoData(_index, &_chargingData[0])) {
-    //    printf ("FindChargingInfoData error\n");
-    //    return;
-    //}
-    pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_index);
-
-    // 盲沖的時候才允許使用~
-    if (pDcChargingInfo->Type != 9) {
-        return;
-    }
-
-    pDcChargingInfo->EvBatterytargetCurrent = _Current;
-}
-
-void GetSystemInfo()
-{
-    printf ("ModelName = %s \n", pSysConfig->ModelName);
-    printf ("SerialNumber = %s \n", pSysConfig->SerialNumber);
-    printf ("InternetConn = %d \n", pSysInfo->InternetConn);
-
-    printf ("MaxChargingPower = %d, MaxChargingCurrent = %d \n",
-            pSysConfig->MaxChargingPower,
-            pSysConfig->MaxChargingCurrent);
-}
-
-void ChangeGunNum()
-{
-    if (pSysInfo->CurGunSelected + 1 < pSysConfig->TotalConnectorCount) {
-        pSysInfo->CurGunSelected += 1;
-        pSysInfo->CurGunSelectedByAc = NO_DEFINE;
-    } else if (pSysConfig->AcConnectorCount > 0 &&
-               pSysInfo->CurGunSelectedByAc == NO_DEFINE) {
-        pSysInfo->CurGunSelectedByAc = DEFAULT_AC_INDEX;
-    } else {
-        pSysInfo->CurGunSelected = 0;
-        pSysInfo->CurGunSelectedByAc = NO_DEFINE;
-    }
-}
-
-void GetGunSelectedNum(char *v1)
-{
-    if (strcmp(v1, "-1") == 0 || strcmp(v1, "") == 0) {
-        if (AC_QUANTITY > 0 &&
-                pSysInfo->CurGunSelectedByAc != NO_DEFINE) {
-            printf("connector select changed = AC \n");
-        } else {
-            printf("connector selected = %d \n", pSysInfo->CurGunSelected);
-        }
-    } else {
-        int _index = atoi(v1);
-        if (_index <= 1) {
-            pSysInfo->CurGunSelected = _index;
-            pSysInfo->CurGunSelectedByAc = NO_DEFINE;
-            printf("connector select changed = %d \n", _index);
-        } else if (AC_QUANTITY > 0) {
-            pSysInfo->CurGunSelectedByAc = DEFAULT_AC_INDEX;
-            printf("connector select changed = AC \n");
-        }
-    }
-}
-
-void SetFanSpeed(char *v1)
-{
-    int speed = atoi(v1);
-
-    ShmFanModuleData->TestFanSpeed = speed;
-}
-
-void GetFanSpeed()
-{
-    printf("ShmFanModuleData->PresentFan1Speed = %d \n", ShmFanModuleData->PresentFan1Speed);
-    printf("ShmFanModuleData->PresentFan2Speed = %d \n", ShmFanModuleData->PresentFan2Speed);
-    printf("ShmFanModuleData->PresentFan3Speed = %d \n", ShmFanModuleData->PresentFan3Speed);
-    printf("ShmFanModuleData->PresentFan4Speed = %d \n", ShmFanModuleData->PresentFan4Speed);
-}
-
-void SetDebugMode(char *v1)
-{
-    int mode = atoi(v1);
-
-    pSysConfig->SwitchDebugFlag = mode;
-}
-
-void SetGFDMode(char *v1)
-{
-    int mode = atoi(v1);
-
-    pSysConfig->AlwaysGfdFlag = mode;
-}
-
-void GetPsuTemp()
-{
-    for (uint8_t index = 0; index < ShmPsuData->GroupCount; index++) {
-        for (uint8_t count = 0; count < ShmPsuData->PsuGroup[index].GroupPresentPsuQuantity; count++) {
-            printf("PSU Temp = %d \n", ShmPsuData->PsuGroup[index].PsuModule[count].ExletTemp);
-        }
-    }
-}
-
-void GetAcInputVol()
-{
-    printf("L1N_L12 = %f, L2N_L23 = %f, L3N_L31 = %f \n",
-           pSysInfo->InputVoltageR,
-           pSysInfo->InputVoltageS,
-           pSysInfo->InputVoltageT);
-}
-
-void GetPsuInformation(char *v1, char *v2, char *v3)
-{
-    printf("**********************AC Contact needed*************************\n");
-    if (strcmp(v1, "count") == 0) {
-        for (int i = 0; i < 4; i++) {
-            printf("Group Index = %d, Module Count = %d \n",
-                   i,
-                   ShmPsuData->PsuGroup[i].GroupPresentPsuQuantity);
-        }
-    } else if (strcmp(v1, "ver") == 0) {
-        for (int i = 0; i < ShmPsuData->SystemPresentPsuQuantity; i++) {
-            printf("Psu Index = %d, PriVersion = %s, SecVersion = %s \n",
-                   i, ShmPsuData->PsuVersion[i].FwPrimaryVersion,
-                   ShmPsuData->PsuVersion[i].FwSecondVersion);
-        }
-
-        for (int i = 0; i < ShmPsuData->GroupCount; i++) {
-            for (int j = 0; j < ShmPsuData->PsuGroup[i].GroupPresentPsuQuantity; j++) {
-                printf("Group Index = %d, Psu Index = %d, Version = %s \n",
-                       i,
-                       j,
-                       ShmPsuData->PsuGroup[i].PsuModule[j].FwVersion);
-            }
-        }
-    } else if (strcmp(v1, "cap") == 0) {
-        for (int i = 0; i < ShmPsuData->GroupCount; i++) {
-            printf("Group Index = %d, MaxCur = %d, Power = %d \n",
-                   i,
-                   ShmPsuData->PsuGroup[i].GroupAvailableCurrent,
-                   ShmPsuData->PsuGroup[i].GroupAvailablePower);
-        }
-    } else if (strcmp(v1, "input") == 0) {
-        for (int i = 0; i < ShmPsuData->GroupCount; i++) {
-            for (uint8_t count = 0; count < ShmPsuData->PsuGroup[i].GroupPresentPsuQuantity; count++) {
-                printf("gp = %d, Index = %d, volR = %d, volS = %d, volT = %d \n",
-                       i,
-                       count,
-                       ShmPsuData->PsuGroup[i].PsuModule[count].InputVoltageL1,
-                       ShmPsuData->PsuGroup[i].PsuModule[count].InputVoltageL2,
-                       ShmPsuData->PsuGroup[i].PsuModule[count].InputVoltageL3);
-            }
-        }
-    } else if (strcmp(v1, "output") == 0) {
-        for (int i = 0; i < ShmPsuData->GroupCount; i++) {
-            printf("Group Index = %d, OutputV = %d, OutputC = %d \n",
-                   i,
-                   ShmPsuData->PsuGroup[i].GroupPresentOutputVoltage,
-                   ShmPsuData->PsuGroup[i].GroupPresentOutputCurrent);
-        }
-
-        for (int i = 0; i < pSysConfig->TotalConnectorCount; i++) {
-            //if (!FindChargingInfoData(i, &_chargingData[0])) {
-            //    printf ("FindChargingInfoData error\n");
-            //    continue;
-            //}
-            pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(i);
-
-            printf("Form RB : Group Index = %d, OutputV = %f \n",
-                   i,
-                   pDcChargingInfo->FireChargingVoltage);
-        }
-    } else if (strcmp(v1, "test") == 0) {
-        int mode = atoi(v2);
-
-        if (mode >= _TEST_MODE && mode <= _TEST_MODE) {
-            ShmPsuData->Work_Step = mode;
-        }
-    } else if (strcmp(v1, "out") == 0) {
-        float vol = atof(v2);
-        float cur = atof(v3);
-
-        if (ShmPsuData->Work_Step >= _TEST_MODE && ShmPsuData->Work_Step <= _TEST_MODE) {
-            //if (!FindChargingInfoData(0, &_chargingData[0])) {
-            //    printf ("FindChargingInfoData error\n");
-            //    return;
-            //}
-            pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(0);
-
-            pDcChargingInfo->EvBatterytargetVoltage = vol;
-            pDcChargingInfo->EvBatterytargetCurrent = cur;
-        }
-    }
-    printf("*************************************************\n");
-}
-
-void GetConnectorCapInfo(char *v1)
-{
-    int _GunIndex = atoi(v1);
-
-    //if (!FindChargingInfoData(_GunIndex, &_chargingData[0])) {
-    //    printf ("FindChargingInfoData error\n");
-    //    return;
-    //}
-    pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_GunIndex);
-
-    printf ("Charger Max Current = %d, Max Power = %d \n",
-            pSysConfig->MaxChargingCurrent * 10,
-            pSysConfig->MaxChargingPower * 10);
-
-    printf ("Index = %d, MaxPow = %f, MaxVol = %f, MaxCur = %f\n",
-            _GunIndex,
-            pDcChargingInfo->RealMaxPower,
-            pDcChargingInfo->RealMaxVoltage,
-            pDcChargingInfo->RealMaxCurrent);
-}
-
-static void setConfirmSelGun(uint8_t selGun)
-{
-    if (selGun == LEFT_GUN_NUM && ShmSelectGunInfo->SelGunInfo.LeftGun == SEL_GUN_RELEASE) {
-        ShmSelectGunInfo->SelGunInfo.LeftGun = SEL_GUN_CONFIRM;
-        //printf("confirmSelGun left\r\n");
-    } else if (selGun == RIGHT_GUN_NUM && ShmSelectGunInfo->SelGunInfo.RightGun == SEL_GUN_RELEASE) {
-        ShmSelectGunInfo->SelGunInfo.RightGun = SEL_GUN_CONFIRM;
-        //printf("confirmSelGun right\r\n");
-    }
-}
-
-void RunUnconditionalChargeIndex1(char *v1, char *v2, char *v3)
-{
-    int _GunIndex;
-    uint8_t gunIndex = 0;
-    uint8_t stopChg = 0;
-    uint8_t curGun = 0;
-    int isContinue = 1;
-    float _Voltage;
-    float _Current;
-    uint8_t PreviousSystemStatus[2] = {0xff};
-    char *usageMsg = "Usage:\n"
-                     "       strchg <index> <voltage> <current>    ex: strchg 0 150 2\n"
-                     "       chg    <voltage> <current>            ex: chg 500 100\n"
-                     "       c      <index>                        ex: c 0\n"
-                     "       help | ? | h\n"
-                     "\r\n";
-
-    if (strcmp(v1, "auto") == EQUAL) {
-        _usingAutoRun = 0x01;
-        _GunIndex = 0;
-        _Voltage = 500;
-        _Current = (pSysConfig->MaxChargingPower * 1000) / _Voltage;
-    } else {
-        _usingAutoRun = 0x00;
-        _GunIndex = atoi(v1);
-        _Voltage = atof(v2);
-        _Current = atof(v3);
-    }
-
-    pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_GunIndex);
-
-    printf("Power = %d, ReqVoltage = %f, ReqCurrent = %f\n",
-           pSysConfig->MaxChargingPower,
-           _Voltage,
-           _Current);
-
-    if (_Voltage > 1000 || _Voltage < 50) {
-        printf ("Input Voltage over range\n");
-        return;
-    }
-
-    //kill ev task
-    system("killall Module_EvComm");
-
-    pSysInfo->CurGunSelected = _GunIndex;
-
-    while (isContinue) {
-
-        curGun = pSysInfo->CurGunSelected;
-        pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(curGun);
-
-        //fix gun 1
-        switch (pDcChargingInfo->SystemStatus) {
-        case S_IDLE:
-            if (PreviousSystemStatus[curGun] != pDcChargingInfo->SystemStatus) {
-                PreviousSystemStatus[curGun] = pDcChargingInfo->SystemStatus;
-#if defined DD360Audi
-                setConfirmSelGun(curGun);
-#endif //defined DD360Audi
-
-                strcpy((char *)pSysConfig->UserId, "AutoStartCharging");
-                pDcChargingInfo->ConnectorPlugIn = 1;
-                printf ("[UnconditionalCharge - S_IDLE]\n");
-                pDcChargingInfo->Type = 9;
-
-            }
-            if (ShmOCPP16Data->SpMsg.bits.AuthorizeConf == 1) {
-                pSysInfo->StartToChargingFlag = 0x01;
-                pDcChargingInfo->SystemStatus = S_PREPARNING;
-            }
-            break;
-
-        case S_PREPARNING:
-            if (PreviousSystemStatus[curGun] != pDcChargingInfo->SystemStatus) {
-                PreviousSystemStatus[curGun] = pDcChargingInfo->SystemStatus;
-
-                printf ("[UnconditionalCharge - S_PREPARNIN]\n");
-
-                //等待 AC Relay 搭上且找到模組 (main 在此 statue 其它 task 會去做完)
-                printf ("wait find module\n");
-
-            }
-            //main 會在此階段判斷以下資料跳到下一個 state
-            //用來得知 AC 是否有搭上 (搭上模組的資訊才會出來) 因為每次  AC_Contactor
-            //ShmPsuData->SystemPresentPsuQuantity;
-            //ShmPsuData->PsuGroup[gun_index].GroupPresentPsuQuantity;
-            //ShmPsuData->PsuGroup[gun_index].GroupAvailablePower;
-            //_chargingData[gun_index]->AvailableChargingPower;
-
-            //等待 AC Relay 搭上且找到模組 (main 在此 statue 其它 task 會去做完)
-            //sleep(10);
-
-            //清除 main timeout 機制
-            pDcChargingInfo->TimeoutFlag = 0;
-            //不論是什麼 type 的槍都固意設成 Chademo 不跑 Prechage step
-            pDcChargingInfo->Type = 9;
-            break;
-
-        case S_PREPARING_FOR_EV:
-            if (PreviousSystemStatus[curGun] != pDcChargingInfo->SystemStatus) {
-                PreviousSystemStatus[curGun] = pDcChargingInfo->SystemStatus;
-
-                printf ("[UnconditionalCharge - S_PREPARING_FOR_EV]\n");
-                printf ("ReqVoltage = %f, ReqCurrent = %f \n", _Voltage * 10, _Current * 10);
-
-            }
-            //清除 main timeout 機制
-            pDcChargingInfo->TimeoutFlag = 0;
-            //不論是什麼 type 的槍都固意設成 Chademo 不跑 Prechage step
-            pDcChargingInfo->Type = 9;
-
-            //充電電壓電流
-            pDcChargingInfo->EvBatterySoc             = 50;
-            pDcChargingInfo->EvBatterytargetVoltage   = 500;
-            pDcChargingInfo->EvBatterytargetCurrent   = 2;
-            pDcChargingInfo->AvailableChargingCurrent = 1000;
-
-            //****** 注意~此行為是防止 K1K2 先開導到無法升壓 ( Relay Board 在此 state 還未搭上 K1K2 )
-            //確定模組己升壓完成
-            //if(pDcChargingInfo->PresentChargingVoltage <=  (3000+500) &&
-            //  pDcChargingInfo->PresentChargingVoltage >=  (3000-500) )
-            {
-                printf ("Precharge Done = %f \n",
-                        pDcChargingInfo->PresentChargingVoltage);
-                //EV done
-                pDcChargingInfo->SystemStatus = S_PREPARING_FOR_EVSE;
-            }
-            break;
-
-        case S_PREPARING_FOR_EVSE:
-            if (PreviousSystemStatus[curGun] != pDcChargingInfo->SystemStatus) {
-                PreviousSystemStatus[curGun] = pDcChargingInfo->SystemStatus;
-
-                printf ("[UnconditionalCharge - S_PREPARING_FOR_EVSE]\n");
-
-            }
-            //printf ("tar vol = %d \n", _Voltage);
-            //printf ("tar cur = %d \n", _Current);
-
-            //清除 main timeout 機制
-            pDcChargingInfo->TimeoutFlag = 0;
-            //不論是什麼 type 的槍都固意設成 Chademo 不跑 Prechage step
-            pDcChargingInfo->Type = 9;
-
-            //充電電壓電流
-            pDcChargingInfo->EvBatterySoc = 50;
-            pDcChargingInfo->EvBatterytargetVoltage = 500;
-            pDcChargingInfo->EvBatterytargetCurrent = 2;
-            pDcChargingInfo->AvailableChargingCurrent = 1000;
-
-            //printf ("tar vol_ = %d \n", pDcChargingInfo->EvBatterytargetVoltage);
-            // printf ("tar cur_ = %d \n", pDcChargingInfo->EvBatterytargetCurrent);
-
-            //****** 注意~此行為是防止 K1K2 先開導到無法升壓 ( Relay Board 在此 state 還未搭上 K1K2 )
-            //確定模組己升壓完成
-            if (pDcChargingInfo->GroundFaultStatus == 0x01 ||
-                    pDcChargingInfo->GroundFaultStatus == 0x03) {
-                printf ("First Ground Fault State (%d)\n",
-                        pDcChargingInfo->GroundFaultStatus);
-                printf ("Wait K1K2 = %f \n", pDcChargingInfo->PresentChargingVoltage);
-                sleep(5);
-                //EV done
-                pDcChargingInfo->SystemStatus = S_CHARGING;
-            } else if (pDcChargingInfo->GroundFaultStatus > 0x02) {
-                printf ("First Ground Fault check Fail (%d)\n",
-                        pDcChargingInfo->GroundFaultStatus);
-                pDcChargingInfo->SystemStatus = S_TERMINATING;
-            }
-            break;
-
-        case S_CHARGING:
-            if (PreviousSystemStatus[curGun] != pDcChargingInfo->SystemStatus) {
-                PreviousSystemStatus[curGun] = pDcChargingInfo->SystemStatus;
-
-                if (_usingAutoRun == 0x00) {
-                    //充電電壓電流
-                    pDcChargingInfo->EvBatterytargetVoltage = _Voltage;
-                    pDcChargingInfo->EvBatterytargetCurrent = _Current;
-                } else {
-                    _curAutoRunCount = 0;
-                    gettimeofday(&_autoTime, NULL);
-                }
-
-                pDcChargingInfo->EvBatterySoc = 50;
-                pDcChargingInfo->AvailableChargingCurrent = 1000;
-
-                printf ("[UnconditionalCharge - S_CHARGING]\n");
-            }
-
-            if (_usingAutoRun == 0x01) {
-                if (((GetTimeoutValue(_autoTime)) >= AUTORUN_STEP1_TIME_START * 60 &&
-                        (GetTimeoutValue(_autoTime)) <= AUTORUN_STEP1_TIME_END * 60) ||
-                        ((GetTimeoutValue(_autoTime)) >= AUTORUN_STEP2_TIME_START * 60 &&
-                         (GetTimeoutValue(_autoTime)) <= AUTORUN_STEP2_TIME_END * 60)
-                   ) {
-                    pDcChargingInfo->EvBatterytargetVoltage = _Voltage;
-                    pDcChargingInfo->EvBatterytargetCurrent = _Current;
-                } else if ((GetTimeoutValue(_autoTime)) >= AUTORUN_END_TIME * 60) {
-                    _curAutoRunCount++;
-                    if (_curAutoRunCount >= AUTORUN_CYCLE_COUNT) {
-                        pDcChargingInfo->SystemStatus = S_TERMINATING;
-                    } else {
-                        gettimeofday(&_autoTime, NULL);
-                    }
-                } else {
-                    pDcChargingInfo->EvBatterytargetVoltage = 0;
-                    pDcChargingInfo->EvBatterytargetCurrent = 0;
-                }
-            }
-
-//              printf("out : vol = %f, cur = %f \n",
-//                      pDcChargingInfo->EvBatterytargetVoltage,
-//                      pDcChargingInfo->EvBatterytargetCurrent);
-            //ev task do this
-            pDcChargingInfo->PresentChargingPower =
-                ((float)((pDcChargingInfo->PresentChargingVoltage) *
-                         (pDcChargingInfo->PresentChargingCurrent)) / 1000);
-
-            if (pDcChargingInfo->GroundFaultStatus == 0x02) {
-                printf ("Charging Ground Fault check Fail (%d)\n",
-                        pDcChargingInfo->GroundFaultStatus);
-                pDcChargingInfo->SystemStatus = S_TERMINATING;
-            }
-            break;
-
-        case S_TERMINATING:
-            if (PreviousSystemStatus[curGun] != pDcChargingInfo->SystemStatus) {
-                PreviousSystemStatus[curGun] = pDcChargingInfo->SystemStatus;
-
-                printf ("[UnconditionalCharge - S_TERMINATING]\n");
-                //無阻塞偵測 keybaord 結束
-                system(STTY_DEF TTY_PATH);
-            }
-
-            pDcChargingInfo->SystemStatus = S_COMPLETE;
-            break;
-
-        case S_COMPLETE:
-            if (PreviousSystemStatus[curGun] != pDcChargingInfo->SystemStatus) {
-                PreviousSystemStatus[curGun] = pDcChargingInfo->SystemStatus;
-
-                printf ("[UnconditionalCharge - S_COMPLETE]\n");
-            }
-
-            PreviousSystemStatus[curGun] = 0xFF;
-            stopChg = 0;
-            for (gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++) {
-                if (PreviousSystemStatus[gunIndex] == 0xFF) {
-                    pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(curGun);
-                    pDcChargingInfo->SystemStatus = S_IDLE;
-                } else {
-                    pSysInfo->CurGunSelected = gunIndex;
-                }
-
-                pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
-                if (pDcChargingInfo->SystemStatus == S_IDLE) {
-                    stopChg++;
-                }
-            }
-
-            pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(curGun);
-            pDcChargingInfo->PresentChargingPower = 0;
-
-            if (stopChg == pSysConfig->TotalConnectorCount) {
-                system("/root/Module_EvComm &");
-                sleep(3);
-
-                for (_GunIndex = 0; _GunIndex < pSysConfig->TotalConnectorCount; _GunIndex++) {
-                    pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_GunIndex);
-
-                    pDcChargingInfo->SystemStatus = S_IDLE;
-                }
-                return;
-            }
-            break;
-        }
-
-        if (readCmdKey(CMD_KEY_DONT_WAIT) == NO) {
-            continue;
-        }
-
-        if (strcmp(newString[0], "strchg") == 0) {
-            if (strcmp(newString[1], "-1") == 0 ||
-                    strcmp(newString[1], "") == 0 ||
-                    strcmp(newString[2], "-1") == 0 ||
-                    strcmp(newString[2], "") == 0
-               ) {
-                printf ("Input cmd fail ------  strchg [vol 150-1000] [cru 2-100]\n");
-                continue;
-            }
-
-            if (atoi(newString[1]) == pSysInfo->CurGunSelected) {
-                continue;
-            }
-
-            _GunIndex = atoi((char *)newString[1]);
-            _Voltage = atof((char *)newString[2]);
-            _Current = atof((char *)newString[3]);
-
-            printf ("Power = %d, ReqVoltage = %f, ReqCurrent = %f\n",
-                    pSysConfig->MaxChargingPower,
-                    _Voltage,
-                    _Current);
-
-            if (_Voltage > 1000 || _Voltage < 50) {
-                _Voltage = 200;
-                printf ("Input Voltage over range\n");
-                continue;
-            }
-
-            pSysInfo->CurGunSelected = _GunIndex;
-            strcpy((char *)pSysConfig->UserId, "");
-        } else if (strcmp(newString[0], "chg") == 0) {
-            if (strcmp(newString[1], "-1") == 0) {
-                continue;
-            }
-
-            if (strcmp(newString[2], "-1") == 0 ||
-                    strcmp(newString[2], "") == 0) {
-                continue;
-            }
-
-            if (strcmp(newString[3], "-1") == 0 ||
-                    strcmp(newString[3], "") == 0) {
-                continue;
-            }
-
-            _GunIndex = atoi((char *)newString[1]);
-            float _vol = atof(newString[2]);
-            float _cur = atof(newString[3]);
-
-            if (_cur <= 0 || _cur <= 0) {
-                continue;
-            }
-
-            pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_GunIndex);
-
-            printf("reset vol = %f, cur = %f \n", _vol, _cur);
-            pDcChargingInfo->EvBatterytargetVoltage = _vol;
-            pDcChargingInfo->EvBatterytargetCurrent = _cur;
-        } else if (strcmp(newString[0], "c") == 0) {
-            if (strcmp(newString[1], "-1") == 0 ||
-                    strcmp(newString[1], "") == 0) {
-                printf("argc 1 is error parameter\r\n");
-                continue;
-            }
-
-            if (atoi((char *)newString[1]) != -1) {
-                pSysInfo->CurGunSelected = atoi((char *)newString[1]);
-            }
-            printf("stop \n\r");
-
-            pSysInfo->StartToChargingFlag = 0x00;
-
-            pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData( pSysInfo->CurGunSelected);
-
-            pDcChargingInfo->SystemStatus = S_TERMINATING;
-        } else if (helpCmd() == YES) {
-            printf("%s\n", usageMsg);
-        }
-
-        usleep(100000);
-    }
-}
-
-int printTimeMsg(const char *fmt, ...)
-{
-    char Buf[4096 + 256] = {0};
-    char buffer[4096] = {0};
-    int rc = -1;
-    va_list args;
-    struct timeb  SeqEndTime;
-    struct tm *tm;
-    struct SysConfigData *pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
-
-    va_start(args, fmt);
-    rc = vsnprintf(buffer, sizeof(buffer), fmt, args);
-    va_end(args);
-
-    ftime(&SeqEndTime);
-    SeqEndTime.time = time(NULL);
-    tm = localtime(&SeqEndTime.time);
-
-    sprintf(Buf, "%02d:%02d:%02d:%03d - %s",
-            tm->tm_hour,
-            tm->tm_min,
-            tm->tm_sec,
-            SeqEndTime.millitm,
-            buffer);
-    printf("%s", Buf);
-
-    return rc;
-}
-
-static void resdGunAndChillerTemp(void)
-{
-    int isContinue = 1;
-    uint8_t i = 0;
-    uint32_t sleepTime = 500000;
-    uint32_t loopTime = 1000;
-    struct timeb showTime;
-    struct timeb nowTime;
-
-    char *usageMsg = "Usage:\n"
-                     "       t <index>: loop time, ex: t 1\n"
-                     "       exit | c | C: exit test\n"
-                     "       h | help | ?: show usage message\n"
-                     "\r\n";
-
-    ftime(&showTime);
-
-    while (isContinue) {
-        ftime(&nowTime);
-
-        if (DiffTimeb(showTime, nowTime) > loopTime ||
-                DiffTimeb(showTime, nowTime) < 0) {
-            for (i = 0; i < pSysConfig->TotalConnectorCount; i++) {
-
-                pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(i);
-
-                printTimeMsg("get gun %d temp = %3d, chiller = %3d, ConnTemp = %3d, %3d,SysTemp = %3d, %3d, %3d, %3d\r\n",
-                             i,
-                             pDcChargingInfo->ConnectorTemp,
-                             pDcChargingInfo->ChillerTemp,
-                             ShmDcCommonData->ConnectorTemp[i][0],
-                             ShmDcCommonData->ConnectorTemp[i][1],
-                             ShmDcCommonData->SystemTemp[0],
-                             ShmDcCommonData->SystemTemp[1],
-                             ShmDcCommonData->SystemTemp[2],
-                             ShmDcCommonData->SystemTemp[3]);
-            }//for
-            ftime(&showTime);
-        }
-
-        if (readCmdKey(CMD_KEY_DONT_WAIT) == NO) {
-            usleep(sleepTime);
-            continue;
-        }
-
-        if (strcmp(newString[0], "t") == 0) {
-            if (strcmp(newString[1], "-1") == 0 ||
-                    strcmp(newString[1], "") == 0 ||
-                    atoi((char *)newString[1]) > 255
-               ) {
-                printf("argc 1 is error parameter\r\n");
-                continue;
-            }
-
-            loopTime = ((atoi((char *)newString[1])) * 1000);
-            printf("loopTime = %d\r\n", loopTime);
-            ftime(&showTime);
-            continue;
-        } else if (exitCmd() == YES) {
-            return;
-        } else if (helpCmd() == YES) {
-            printf ("%s\n", usageMsg);
-        }
-
-        usleep(sleepTime);
-    }//while
-}
-
-static void writeGunAndChillerTemp(void)
-{
-    uint8_t _GunIndex = 0;
-    int isContinue = 1;
-    uint32_t sleepTime = 500000;
-    char *usageMsg = "Usage:\n"
-                     "       conn    <index> <temp>, ex: conn 0 150\n"
-                     "       chiller <index> <temp>, ex: chiller 0 150\n"
-                     "       tempR\n"
-                     "       exit | c | C\n"
-                     "       help | ? | h\n"
-                     "\r\n";
-
-    ShmDcCommonData->TestTemperature = YES;
-
-    while (isContinue) {
-        if (readCmdKey(CMD_KEY_WAIT) == NO) {
-            sleep(sleepTime);
-            continue;
-        }
-
-        if (helpCmd() == YES) {
-            printf ("%s\n", usageMsg);
-            continue;
-        } else if (exitCmd() == YES) {
-            ShmDcCommonData->TestTemperature = NO;
-            sleep(1);
-            return;
-        } else if (strcmp(newString[0], "tempR") == 0) {
-            resdGunAndChillerTemp();
-        }
-
-        if ((strcmp(newString[0], "chiller") != 0) &&
-                (strcmp(newString[1], "-1") == 0 ||
-                 strcmp(newString[1], "") == 0)
-           ) {
-            printf("argc 1 is error parameter\r\n");
-            continue;
-        }
-
-        if (atoi(newString[2]) > 255 ||
-                atoi(newString[2]) == -1) {
-            printf("temperature value overflow\r\n");
-            continue;
-        }
-
-        _GunIndex = atoi((char *)newString[1]);
-
-        if (_GunIndex >= pSysConfig->TotalConnectorCount) {
-            printf("gun index over total connector\r\n");
-            continue;
-        }
-
-        if (strcmp(newString[0], "chiller") == 0) {//修改水冷機溫度值
-            if (_GunIndex >= 1) {
-                _GunIndex = 0; //只會有一個水冷機
-            }
-
-            pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_GunIndex);
-            pDcChargingInfo->ChillerTemp = atoi(newString[2]);
-            printf("set %d chiller temperature = %d\r\n",
-                   _GunIndex,
-                   pDcChargingInfo->ChillerTemp);
-        } else if (strcmp(newString[0], "conn") == 0) {//修改槍頭溫度值
-            pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_GunIndex);
-
-            pDcChargingInfo->ConnectorTemp = atoi(newString[2]);
-            printf("set %d connector temp = %d\r\n",
-                   _GunIndex,
-                   pDcChargingInfo->ConnectorTemp);
-        }
-
-        usleep(sleepTime);
-    }//while
-}
-
-int main(void)
-{
-    uint8_t _GunIndex = 0;
-    int isContinue = 1;
-    char *usageMsg = "Usage:\n"
-                     "       state <index>                     : get gun state\n"
-                     "       card                              : scanning card (x)\n"
-                     "       gun <index>                       : get gun plugit state\n"
-                     "       lock <index>                      : get gun locked state\n"
-                     "       sysid                             : test system ID\n"
-                     "       self                              : self test state (x)\n"
-                     "       version | v | -v                  : version of board (407 or relay or other)\n"
-                     "       update                            : update firmware\n"
-                     "       ac                                : get ac relay state (x) \n"
-                     "       cable <index> <state>             : set ground fault state\n"
-                     "       pow <index> <power>               : set power value\n"
-                     "       model                             : get system information\n"
-                     "       temp                              : get PSU temperature\n"
-                     "       fan <speed>                       : set fan board speed\n"
-                     "       strchg <auto>                     : auto test charging\n"
-                     "       strchg <index> <voltage <current> : select gun test charging\n"
-                     "       tempW                             : write connector header and Chiller temperature\r\n"
-                     "       tempR                             : print connector header and chiller temperature\r\n"
-                     "\r\n";
-
-    if (CreateAllCsuShareMemory() == FAIL) {
-        printf("create share memory error\r\n");
-        return FAIL;
-    }
-
-    MappingGunChargingInfo("ReadCmdline Task");
-
-    pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
-    pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
-    pSysWarning = (struct WARNING_CODE_INFO *)GetShmSysWarningInfo();
-
-    pAlarmCode = (struct AlarmCodeData *)GetShmAlarmCodeData();
-
-    ShmCHAdeMOData = (struct CHAdeMOData *)GetShmCHAdeMOData();
-    ShmGBTData = (struct GBTData *)GetShmGBTData();
-    ShmCcsData = (struct CcsData *)GetShmCcsData();
-
-    ShmPrimaryMcuData = (struct PrimaryMcuData *)GetShmPrimaryMcuData();
-    ShmFanModuleData = (struct FanModuleData *)GetShmFanModuleData();
-    ShmRelayModuleData = (struct RelayModuleData *)GetShmRelayModuleData();
-    ShmLedModuleData = (struct LedModuleData *)GetShmLedModuleData();
-    ShmPsuData = (struct PsuData *)GetShmPsuData();
-    ShmOCPP16Data = (struct OCPP16Data *)GetShmOCPP16Data();
-    ShmSelectGunInfo = (SelectGunInfo *)GetShmSelectGunInfo();
-    ShmDcCommonData = (DcCommonInfo *)GetShmDcCommonData();
-
-//    for (_GunIndex = 0; _GunIndex < pSysConfig->TotalConnectorCount; _GunIndex++) {
-//        pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_GunIndex);
-
-//        pDcChargingInfo->SystemStatus = S_IDLE;
-//    }
-
-    while (isContinue) {
-        if (readCmdKey(CMD_KEY_WAIT) == NO) {
-            continue;
-        }
-
-        if (strcmp(newString[0], "state") == 0) {
-            if (strcmp(newString[1], "-1") == 0 ||
-                    strcmp(newString[1], "") == 0) {
-                continue;
-            }
-
-            // 槍狀態
-            RunStatusProc(newString[1], newString[2]);
-        } else if (strcmp(newString[0], "card") == 0) {
-            // 刷卡狀態
-            RunCardProc(newString[1], newString[2]);
-        } else if (strcmp(newString[0], "gun") == 0) {
-            if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0) {
-                continue;
-            }
-
-            // 插槍狀態
-            RunGunPlugitProc(newString[1], newString[2]);
-        } else if (strcmp(newString[0], "lock") == 0) {
-            if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0) {
-                continue;
-            }
-
-            // 插槍狀態
-            GetGunLockStatusProc(newString[1], newString[2]);
-        } else if (strcmp(newString[0], "sysid") == 0) {
-            // 測試 sys id
-            SetSystemIDProc();
-        } else if (strcmp(newString[0], "self") == 0) {
-            // CSU 自我檢測狀態
-            RunSelfProc(newString[1]);
-        } else if (strcmp(newString[0], "version") == 0 ||
-                   strcmp(newString[0], "v") == 0 ||
-                   strcmp(newString[0], "-v") == 0) {
-            //if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0) {
-            //    continue;
-            //}
-            // 取 FW 版號
-            GetFwVerProc();
-        } else if (strcmp(newString[0], "update") == 0) {
-            // 更新
-            FwUpdateFlagProc(newString[1]);
-        } else if (strcmp(newString[0], "ac") == 0) {
-            // AC contactor 狀態
-            CheckAcStatus(newString[1]);
-        } else if (strcmp(newString[0], "cable") == 0) {
-            if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0) {
-                continue;
-            }
-
-            // cable check pass
-            SetCableChkStatus(newString[1], newString[2]);
-        } else if (strcmp(newString[0], "pow") == 0) {
-            if (strcmp(newString[1], "-1") == 0 ||
-                    strcmp(newString[1], "") == 0) {
-                continue;
-            }
-            // cable check pass
-            SetPowerValue(newString[1], newString[2]);
-        } else if (strcmp(newString[0], "model") == 0) {
-            GetSystemInfo();
-        } else if (strcmp(newString[0], "select") == 0) {
-            // 取得 / 設定 當前選的槍號
-            GetGunSelectedNum(newString[1]);
-        } else if (strcmp(newString[0], "change") == 0) {
-            // 模擬按鈕改變選槍
-            ChangeGunNum();
-        } else if (strcmp(newString[0], "fan") == 0) {
-            // 設定風扇速度
-            SetFanSpeed(newString[1]);
-        } else if (strcmp(newString[0], "speed") == 0) {
-            // 取得風扇速度
-            GetFanSpeed();
-        } else if (strcmp(newString[0], "debug") == 0) {
-            // 設定 debug mode
-            SetDebugMode(newString[1]);
-        } else if (strcmp(newString[0], "gfd") == 0) {
-            // 設定盲沖使用 GFD 功能
-            SetGFDMode(newString[1]);
-        } else if (strcmp(newString[0], "temp") == 0) {
-            // 取得 PSU 溫度
-            GetPsuTemp();
-        } else if (strcmp(newString[0], "acin") == 0) {
-            // 取得三向輸入電壓
-            GetAcInputVol();
-        } else if (strcmp(newString[0], "psu") == 0) {
-            //如果連一個參數都沒有 (此命令不理會) 加上判斷第二參數
-            if (strcmp(newString[1], "-1") == 0 ||
-                    strcmp(newString[1], "") == 0) {
-                printf ("PSU : Param fail..Please retry again......\n");
-                continue;
-            }
-            // 取得 PSU 資訊
-            GetPsuInformation(newString[1], newString[2], newString[3]);
-        } else if (strcmp(newString[0], "cap") == 0) {
-            GetConnectorCapInfo(newString[1]);
-        } else if (strcmp(newString[0], "error") == 0) {
-            CreateOneError(newString[1]);
-        } else if (strcmp(newString[0], "auth") == 0) {
-            GetAuthorizeFlag(newString[1]);
-        } else if (strcmp(newString[0], "relay") == 0) {
-            GetRelayStatus(newString[1]);
-        } else if (strcmp(newString[0], "ccid") == 0) {
-            if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0 ||
-                    strcmp(newString[2], "-1") == 0 || strcmp(newString[2], "") == 0) {
-                printf ("Input ccid fail.\n");
-                continue;
-            }
-            SetChargingInfoCCID(newString[1], newString[2]);
-        } else if (strcmp(newString[0], "strchg") == 0) {
-            //如果連一個參數都沒有 (此命令不理會) 加上判斷第二參數
-            if (strcmp(newString[1], "auto") == 0) {
-                newString[2][0] = 0;
-                newString[3][0] = 0;
-            } else if (strcmp(newString[1], "-1") == 0 ||
-                       strcmp(newString[1], "") == 0   ||
-                       strcmp(newString[2], "-1") == 0 ||
-                       strcmp(newString[2], "") == 0) {
-                printf ("Input cmd fail ------  strchg [vol 150-1000] [cru 2-100]\n");
-                continue;
-            }
-
-            // 槍狀態
-            RunUnconditionalChargeIndex1(newString[1], newString[2], newString[3]);
-        } else if (strcmp(newString[0], "tempW") == 0) { //測試槍頭和水冷機溫度
-            writeGunAndChillerTemp();
-        } else if (strcmp(newString[0], "tempR") == 0) { //讀取槍頭和水冷機溫度
-            resdGunAndChillerTemp();
-        } else {
-            printf("%s\n", usageMsg);
-        }
-
-        sleep(1);
-    }//while
-
-    return 0;
-}
+/*
+ * Main.c
+ *
+ *  Created on: 2019年8月6日
+ *      Author: 7564
+ */
+
+
+#include <sys/time.h>
+#include <sys/timeb.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <sys/ioctl.h>
+#include <sys/socket.h>
+#include <sys/ipc.h>
+#include <sys/shm.h>
+#include <sys/shm.h>
+#include <sys/mman.h>
+#include <linux/wireless.h>
+#include <arpa/inet.h>
+#include <netinet/in.h>
+
+#include <unistd.h>
+#include <stdarg.h>
+#include <stdio.h>      /*標準輸入輸出定義*/
+#include <stdlib.h>     /*標準函數庫定義*/
+#include <stdint.h>
+#include <unistd.h>     /*Unix 標準函數定義*/
+#include <fcntl.h>      /*檔控制定義*/
+#include <termios.h>    /*PPSIX 終端控制定義*/
+#include <errno.h>      /*錯誤號定義*/
+#include <errno.h>
+#include <string.h>
+#include <time.h>
+#include <ctype.h>
+#include <ifaddrs.h>
+#include <math.h>
+#include <stdbool.h>
+
+#include "./ShareMemory/shmMem.h"
+#include "./Define/define.h"
+#include "./SelectGun/SelectGun.h"
+#include "Config.h"
+
+//------------------------------------------------------------------------------
+#define CMD_KEY_WAIT                                (1)
+#define CMD_KEY_DONT_WAIT                           (0)
+
+#define DEFAULT_AC_INDEX                            (2)
+
+#define AUTORUN_STEP1_TIME_START                    (140)             // Minutes
+#define AUTORUN_STEP1_TIME_END                      (150)
+#define AUTORUN_STEP2_TIME_START                    (210)
+#define AUTORUN_STEP2_TIME_END                      (410)
+#define AUTORUN_END_TIME                            (480)
+#define AUTORUN_CYCLE_COUNT                         (30)
+
+#define TTY_PATH                                    "/dev/tty"
+#define STTY_US                                     "stty raw -echo -F "
+#define STTY_DEF                                    "stty -raw echo -F "
+
+//------------------------------------------------------------------------------
+uint8_t _curAutoRunCount = 0;
+uint8_t _usingAutoRun = 0;
+struct timeval _autoTime;
+
+static struct SysConfigData *pSysConfig = NULL;
+static struct SysInfoData *pSysInfo = NULL;
+static struct WARNING_CODE_INFO *pSysWarning = NULL;
+
+static struct AlarmCodeData *pAlarmCode = NULL;
+
+static struct PrimaryMcuData *ShmPrimaryMcuData = NULL;
+static struct CHAdeMOData *ShmCHAdeMOData = NULL;
+static struct CcsData *ShmCcsData = NULL;
+static struct GBTData *ShmGBTData = NULL;
+static struct FanModuleData *ShmFanModuleData = NULL;
+static struct RelayModuleData *ShmRelayModuleData = NULL;
+static struct LedModuleData *ShmLedModuleData = NULL;
+static struct PsuData *ShmPsuData = NULL;
+static struct OCPP16Data *ShmOCPP16Data = NULL;
+static SelectGunInfo *ShmSelectGunInfo = NULL;
+static DcCommonInfo *ShmDcCommonData = NULL;
+
+static struct ChargingInfoData *pDcChargingInfo = NULL;
+static struct ChargingInfoData *pAcChargingInfo = NULL;
+
+static char newString[8][16] = {0};
+
+//------------------------------------------------------------------------------
+static 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;
+}
+
+static void get_char(char *word)
+{
+    fd_set rfds;
+    struct timeval tv;
+
+    FD_ZERO(&rfds);
+    FD_SET(0, &rfds);
+    tv.tv_sec = 0;
+    tv.tv_usec = 10; //wait input timout time
+
+    //if input
+    if (select(1, &rfds, NULL, NULL, &tv) > 0) {
+        fgets(word, 128, stdin);
+    }
+}
+
+static uint8_t helpCmd(void)
+{
+    if (strcmp(newString[0], "?") == 0 ||
+            strcmp(newString[0], "help") == 0 ||
+            strcmp(newString[0], "h") == 0) {
+        return YES;
+    }
+
+    return NO;
+}
+
+static uint8_t exitCmd(void)
+{
+    if (strcmp(newString[0], "c") == EQUAL ||
+            strcmp(newString[0], "C") == EQUAL ||
+            strncmp(&newString[0][0], "exit", 4) == EQUAL
+       ) {
+        return YES;
+    }
+
+    return NO;
+}
+
+static uint8_t readCmdKey(uint8_t state)
+{
+    char word[128] = {0};
+    int i = 0, j = 0, ctr = 0;
+
+    memset(word, 0, sizeof(word));
+    if (state == CMD_KEY_WAIT) {
+        fgets(word, sizeof(word), stdin);
+    } else if (state == CMD_KEY_DONT_WAIT) {
+        get_char(word);
+
+        if (strlen(word) == 0) {
+            //usleep(50000);
+            return NO;
+        }
+    }
+
+    memset(newString, 0, sizeof(newString));
+
+    strcpy(newString[1], "-1");
+    strcpy(newString[2], "-1");
+    for (i = 0; i <= (strlen(word)); i++) {
+        if (word[i] == ' ' ||
+                word[i] == '\0' ||
+                word[i] == '\r' ||
+                word[i] == '\n' ||
+                word[i] == 10) {
+            newString[ctr][j] = '\0';
+            ctr++;
+            j = 0;
+        } else {
+            newString[ctr][j] = word[i];
+            j++;
+        }
+    }
+
+    return YES;
+}
+
+unsigned long GetTimeoutValue(struct timeval _sour_time)
+{
+    struct timeval _end_time;
+    gettimeofday(&_end_time, NULL);
+
+    return (_end_time.tv_sec - _sour_time.tv_sec);
+}
+
+void RunStatusProc(char *v1, char *v2)
+{
+    printf("OrderCharging = %d \n", pSysInfo->OrderCharging);
+    printf("WaitForPlugit = %d \n", pSysInfo->WaitForPlugit);
+    if (strcmp(v1, "ac") == 0) {
+        pAcChargingInfo = (struct ChargingInfoData *)GetAcChargingInfoData(0);
+        //if (!FindAcChargingInfoData(0, &ac_chargingInfo[0])) {
+        //    printf("FindChargingInfoData (AC) false \n");
+        //}
+        printf("AC Status = %d \n", pAcChargingInfo->ConnectorPlugIn);
+        return;
+    }
+
+    int _index = atoi(v1);
+
+    if (_index <= 1) {
+        //if (!FindChargingInfoData(_index, &_chargingData[0])) {
+        //    printf ("FindChargingInfoData error\n");
+        //    return;
+        //}
+        pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_index);
+
+        if (strcmp(v2, "-1") == 0 || strcmp(v2, "") == 0) {
+            // get
+            printf ("index = %x, status = %x (%d)\n",
+                    _index,
+                    pDcChargingInfo->SystemStatus,
+                    pDcChargingInfo->IsAvailable);
+            printf ("SystemTimeoutFlag = %d, PageIndex = %d\n",
+                    pSysInfo->SystemTimeoutFlag, pSysInfo->PageIndex);
+        } else {
+            // set
+            pDcChargingInfo->SystemStatus = atoi(v2);
+        }
+    } else {
+        //if (!FindAcChargingInfoData(0, &ac_chargingInfo[0])) {
+        //    printf("FindChargingInfoData (AC) false \n");
+        //}
+        pAcChargingInfo = (struct ChargingInfoData *)GetAcChargingInfoData(0);
+
+        if (strcmp(v2, "-1") == 0 || strcmp(v2, "") == 0) {
+            // get
+            printf ("AC Type, status = %x (%d)\n",
+                    pAcChargingInfo->SystemStatus,
+                    pAcChargingInfo->IsAvailable);
+        } else {
+            // set
+            pAcChargingInfo->SystemStatus = atoi(v2);
+        }
+    }
+}
+
+void RunCardProc(char *v1, char *v2)
+{
+    if (strcmp(v1, "-1") == 0 || strcmp(v1, "") == 0) {
+        if (pSysInfo->WaitForPlugit) {
+            pSysInfo->WaitForPlugit = 0x00;
+            printf ("SysInfo.WaitForPlugit = %x \n", pSysInfo->WaitForPlugit);
+        } else {
+            pSysInfo->WaitForPlugit = 0x01;
+            printf ("SysInfo.WaitForPlugit = %x \n", pSysInfo->WaitForPlugit);
+        }
+    } else {
+        strcpy((char *)pSysConfig->UserId, "");
+        memcpy((char *)pSysConfig->UserId, v1, strlen(v1));
+        pSysConfig->UserId[strlen(v1)] = '\0';
+        printf("StartUserId = %s \n", pSysConfig->UserId);
+    }
+}
+
+void RunGunPlugitProc(char *v1, char *v2)
+{
+    if (strcmp(v1, "ac") == 0) {
+        //if (!FindAcChargingInfoData(0, &ac_chargingInfo[0])) {
+        //    printf("FindChargingInfoData (AC) false \n");
+        //}
+        pAcChargingInfo = (struct ChargingInfoData *)GetAcChargingInfoData(0);
+
+        if (strcmp(v2, "-1") == 0 || strcmp(v2, "") == 0) {
+            // get
+            printf("ConnectorPlugIn = %d \n", pAcChargingInfo->ConnectorPlugIn);
+        } else {
+            // set
+            pAcChargingInfo->ConnectorPlugIn = atoi(v2);
+        }
+        return;
+    }
+
+    int _index = atoi(v1);
+    //if (!FindChargingInfoData(_index, &_chargingData[0])) {
+    //    printf("FindChargingInfoData error\n");
+    //    return;
+    //}
+    pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_index);
+
+    if (strcmp(v2, "-1") == 0 || strcmp(v2, "") == 0) {
+        // get
+        printf("index = %x, plug it = %x\n",
+               _index,
+               pDcChargingInfo->ConnectorPlugIn);
+    } else {
+        // set
+        pDcChargingInfo->ConnectorPlugIn = atoi(v2);
+    }
+}
+
+void GetGunLockStatusProc(char *v1, char *v2)
+{
+    int _index = atoi(v1);
+    //if (!FindChargingInfoData(_index, &_chargingData[0])) {
+    //    printf("FindChargingInfoData error\n");
+    //    return;
+    //}
+    pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_index);
+
+    if (strcmp(v2, "-1") != 0 && strcmp(v2, "") != 0) {
+        pDcChargingInfo->GunLocked = atoi(v2);
+    }
+
+    printf("Gun Locked Status = %d \n", pDcChargingInfo->GunLocked);
+}
+
+void SetSystemIDProc()
+{
+    char *systemId = "Alston_Test";
+    memcpy(&pSysConfig->SystemId, systemId, strlen(systemId));
+}
+
+void RunSelfProc()
+{
+    printf("self test status = %x\n", pSysInfo->SelfTestSeq);
+}
+
+void GetFwVerProc(void)
+{
+    int _index = 0;
+    int isContinue = 1;
+    char *usageMsg = "Usage:\n"
+                     "      model\n"
+                     "      407\n"
+                     "      conn index, ex: conn 0 | 1\n"
+                     "      relay\n"
+                     "      fan\n"
+                     "      dc\n"
+                     "      led\n"
+                     "      ac\n"
+                     "      exit | c | C\n"
+                     "      help | ? | h\n";
+
+    while (isContinue) {
+        if (readCmdKey(CMD_KEY_WAIT) == NO) {
+            continue;
+        }
+
+        if (strcmp(newString[0], "407") == 0) {
+            printf("407 FW Version = %s\n", ShmPrimaryMcuData->version);
+        } else if (strcmp(newString[0], "model") == 0) {
+            printf("ModelName = %s\r\n", pSysConfig->ModelName);
+        } else if (strcmp(newString[0], "conn") == 0) {
+            if (strcmp(newString[1], "-1") == 0  ||
+                    strcmp(newString[1], "") == 0 ||
+                    atoi(newString[1]) >= pSysConfig->TotalConnectorCount
+               ) {
+                printf("index over flow\r\n");
+                continue;
+            }
+
+            _index = atoi(newString[1]);
+
+            if (_index == 0) {
+                printf("Gun 0 FW Version = %s \n", pSysInfo->Connector1FwRev);
+            } else if (_index == 1) {
+                printf("Gun 1 FW Version = %s \n", pSysInfo->Connector2FwRev);
+            }
+        } else if (strcmp(newString[0], "relay") == 0) {
+            printf("RB Version = %s \n", pSysInfo->RelayModuleFwRev);
+        } else if (strcmp(newString[0], "fan") == 0) {
+            printf("FAN Version = %s \n", pSysInfo->FanModuleFwRev);
+        } else if (strcmp(newString[0], "dc") == 0) {
+            printf("DC Main Version = %s \n", pSysInfo->CsuRootFsFwRev);
+        } else if (strcmp(newString[0], "led") == 0) {
+            printf("LED Version = %s \n", pSysInfo->LedModuleFwRev);
+        } else if (strcmp(newString[0], "ac") == 0) {
+            pAcChargingInfo = (struct ChargingInfoData *)GetAcChargingInfoData(0);
+
+            printf("AC Version = %s \n", pAcChargingInfo->version);
+        } else if (exitCmd() == YES) {
+            return;
+        } else if (helpCmd() == YES) {
+            printf ("%s\n", usageMsg);
+        }
+
+    }//while
+}
+
+void CreateOneError(char *v1)
+{
+    int value = atoi(v1);
+
+    pAlarmCode->AlarmEvents.bits.SystemL1InputOVP = value;
+    pSysConfig->BillingData.isBilling = value;
+}
+
+void GetAuthorizeFlag(char *v1)
+{
+    if (strcmp(v1, "-1") == 0 || strcmp(v1, "") == 0) {
+        printf("AuthorizeFlag = %d \n", pSysInfo->AuthorizeFlag);
+    } else {
+        pSysInfo->AuthorizeFlag = atoi(v1);
+    }
+}
+
+void GetRelayStatus(char *v1)
+{
+    int _index = atoi(v1);
+    //if (!FindChargingInfoData(_index, &_chargingData[0])) {
+    //    printf("FindChargingInfoData error\n");
+    //    return;
+    //}
+    pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_index);
+
+    printf("RelayK1K2Status = %d \n", pDcChargingInfo->RelayK1K2Status);
+    printf("RelayKPK2Status = %d \n", pDcChargingInfo->RelayKPK2Status);
+}
+
+void FwUpdateFlagProc()
+{
+    pSysInfo->FirmwareUpdate = 0x01;
+}
+
+void CheckAcStatus(char *v1)
+{
+    if (strcmp(v1, "-1") == 0 || strcmp(v1, "") == 0) {
+        printf("AC Status = %d \n", pSysInfo->AcContactorStatus);
+    }
+}
+
+void SetCableChkStatus(char *v1, char *v2)
+{
+    int _index = atoi(v1);
+    //if (!FindChargingInfoData(_index, &_chargingData[0])) {
+    //    printf ("FindChargingInfoData error\n");
+    //    return;
+    //}
+    pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_index);
+
+    pDcChargingInfo->GroundFaultStatus = atoi(v2);
+}
+
+void SetChargingInfoCCID(char *v1, char *v2)
+{
+    int _index = atoi(v1);
+    //if (!FindChargingInfoData(_index, &_chargingData[0])) {
+    //    printf ("FindChargingInfoData error\n");
+    //    return;
+    //}
+    pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_index);
+
+    memcpy(pDcChargingInfo->EVCCID, v2, 8);
+    pDcChargingInfo->EVCCID[8] = '\0';
+}
+
+void SetPowerValue(char *v1, char *v2)
+{
+    int _index = atoi(v1);
+    float _Current = atof(v2);
+
+    //if (!FindChargingInfoData(_index, &_chargingData[0])) {
+    //    printf ("FindChargingInfoData error\n");
+    //    return;
+    //}
+    pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_index);
+
+    // 盲沖的時候才允許使用~
+    if (pDcChargingInfo->Type != 9) {
+        return;
+    }
+
+    pDcChargingInfo->EvBatterytargetCurrent = _Current;
+}
+
+void GetSystemInfo()
+{
+    printf ("ModelName = %s \n", pSysConfig->ModelName);
+    printf ("SerialNumber = %s \n", pSysConfig->SerialNumber);
+    printf ("InternetConn = %d \n", pSysInfo->InternetConn);
+
+    printf ("MaxChargingPower = %d, MaxChargingCurrent = %d \n",
+            pSysConfig->MaxChargingPower,
+            pSysConfig->MaxChargingCurrent);
+}
+
+void ChangeGunNum()
+{
+    if (pSysInfo->CurGunSelected + 1 < pSysConfig->TotalConnectorCount) {
+        pSysInfo->CurGunSelected += 1;
+        pSysInfo->CurGunSelectedByAc = NO_DEFINE;
+    } else if (pSysConfig->AcConnectorCount > 0 &&
+               pSysInfo->CurGunSelectedByAc == NO_DEFINE) {
+        pSysInfo->CurGunSelectedByAc = DEFAULT_AC_INDEX;
+    } else {
+        pSysInfo->CurGunSelected = 0;
+        pSysInfo->CurGunSelectedByAc = NO_DEFINE;
+    }
+}
+
+void GetGunSelectedNum(char *v1)
+{
+    if (strcmp(v1, "-1") == 0 || strcmp(v1, "") == 0) {
+        if (AC_QUANTITY > 0 &&
+                pSysInfo->CurGunSelectedByAc != NO_DEFINE) {
+            printf("connector select changed = AC \n");
+        } else {
+            printf("connector selected = %d \n", pSysInfo->CurGunSelected);
+        }
+    } else {
+        int _index = atoi(v1);
+        if (_index <= 1) {
+            pSysInfo->CurGunSelected = _index;
+            pSysInfo->CurGunSelectedByAc = NO_DEFINE;
+            printf("connector select changed = %d \n", _index);
+        } else if (AC_QUANTITY > 0) {
+            pSysInfo->CurGunSelectedByAc = DEFAULT_AC_INDEX;
+            printf("connector select changed = AC \n");
+        }
+    }
+}
+
+void SetFanSpeed(char *v1)
+{
+    int speed = atoi(v1);
+
+    ShmFanModuleData->TestFanSpeed = speed;
+}
+
+void GetFanSpeed()
+{
+    printf("ShmFanModuleData->PresentFan1Speed = %d \n", ShmFanModuleData->PresentFan1Speed);
+    printf("ShmFanModuleData->PresentFan2Speed = %d \n", ShmFanModuleData->PresentFan2Speed);
+    printf("ShmFanModuleData->PresentFan3Speed = %d \n", ShmFanModuleData->PresentFan3Speed);
+    printf("ShmFanModuleData->PresentFan4Speed = %d \n", ShmFanModuleData->PresentFan4Speed);
+}
+
+void SetDebugMode(char *v1)
+{
+    int mode = atoi(v1);
+
+    pSysConfig->SwitchDebugFlag = mode;
+}
+
+void SetGFDMode(char *v1)
+{
+    int mode = atoi(v1);
+
+    pSysConfig->AlwaysGfdFlag = mode;
+}
+
+void GetPsuTemp()
+{
+    for (uint8_t index = 0; index < ShmPsuData->GroupCount; index++) {
+        for (uint8_t count = 0; count < ShmPsuData->PsuGroup[index].GroupPresentPsuQuantity; count++) {
+            printf("PSU Temp = %d \n", ShmPsuData->PsuGroup[index].PsuModule[count].ExletTemp);
+        }
+    }
+}
+
+void GetAcInputVol()
+{
+    printf("L1N_L12 = %f, L2N_L23 = %f, L3N_L31 = %f \n",
+           pSysInfo->InputVoltageR,
+           pSysInfo->InputVoltageS,
+           pSysInfo->InputVoltageT);
+}
+
+void GetPsuInformation(char *v1, char *v2, char *v3)
+{
+    printf("**********************AC Contact needed*************************\n");
+    if (strcmp(v1, "count") == 0) {
+        for (int i = 0; i < 4; i++) {
+            printf("Group Index = %d, Module Count = %d \n",
+                   i,
+                   ShmPsuData->PsuGroup[i].GroupPresentPsuQuantity);
+        }
+    } else if (strcmp(v1, "ver") == 0) {
+        for (int i = 0; i < ShmPsuData->SystemPresentPsuQuantity; i++) {
+            printf("Psu Index = %d, PriVersion = %s, SecVersion = %s \n",
+                   i, ShmPsuData->PsuVersion[i].FwPrimaryVersion,
+                   ShmPsuData->PsuVersion[i].FwSecondVersion);
+        }
+
+        for (int i = 0; i < ShmPsuData->GroupCount; i++) {
+            for (int j = 0; j < ShmPsuData->PsuGroup[i].GroupPresentPsuQuantity; j++) {
+                printf("Group Index = %d, Psu Index = %d, Version = %s \n",
+                       i,
+                       j,
+                       ShmPsuData->PsuGroup[i].PsuModule[j].FwVersion);
+            }
+        }
+    } else if (strcmp(v1, "cap") == 0) {
+        for (int i = 0; i < ShmPsuData->GroupCount; i++) {
+            printf("Group Index = %d, MaxCur = %d, Power = %d \n",
+                   i,
+                   ShmPsuData->PsuGroup[i].GroupAvailableCurrent,
+                   ShmPsuData->PsuGroup[i].GroupAvailablePower);
+        }
+    } else if (strcmp(v1, "input") == 0) {
+        for (int i = 0; i < ShmPsuData->GroupCount; i++) {
+            for (uint8_t count = 0; count < ShmPsuData->PsuGroup[i].GroupPresentPsuQuantity; count++) {
+                printf("gp = %d, Index = %d, volR = %d, volS = %d, volT = %d \n",
+                       i,
+                       count,
+                       ShmPsuData->PsuGroup[i].PsuModule[count].InputVoltageL1,
+                       ShmPsuData->PsuGroup[i].PsuModule[count].InputVoltageL2,
+                       ShmPsuData->PsuGroup[i].PsuModule[count].InputVoltageL3);
+            }
+        }
+    } else if (strcmp(v1, "output") == 0) {
+        for (int i = 0; i < ShmPsuData->GroupCount; i++) {
+            printf("Group Index = %d, OutputV = %d, OutputC = %d \n",
+                   i,
+                   ShmPsuData->PsuGroup[i].GroupPresentOutputVoltage,
+                   ShmPsuData->PsuGroup[i].GroupPresentOutputCurrent);
+        }
+
+        for (int i = 0; i < pSysConfig->TotalConnectorCount; i++) {
+            //if (!FindChargingInfoData(i, &_chargingData[0])) {
+            //    printf ("FindChargingInfoData error\n");
+            //    continue;
+            //}
+            pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(i);
+
+            printf("Form RB : Group Index = %d, OutputV = %f \n",
+                   i,
+                   pDcChargingInfo->FireChargingVoltage);
+        }
+    } else if (strcmp(v1, "test") == 0) {
+        int mode = atoi(v2);
+
+        if (mode >= _TEST_MODE && mode <= _TEST_MODE) {
+            ShmPsuData->Work_Step = mode;
+        }
+    } else if (strcmp(v1, "out") == 0) {
+        float vol = atof(v2);
+        float cur = atof(v3);
+
+        if (ShmPsuData->Work_Step >= _TEST_MODE && ShmPsuData->Work_Step <= _TEST_MODE) {
+            //if (!FindChargingInfoData(0, &_chargingData[0])) {
+            //    printf ("FindChargingInfoData error\n");
+            //    return;
+            //}
+            pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(0);
+
+            pDcChargingInfo->EvBatterytargetVoltage = vol;
+            pDcChargingInfo->EvBatterytargetCurrent = cur;
+        }
+    }
+    printf("*************************************************\n");
+}
+
+void GetConnectorCapInfo(char *v1)
+{
+    int _GunIndex = atoi(v1);
+
+    //if (!FindChargingInfoData(_GunIndex, &_chargingData[0])) {
+    //    printf ("FindChargingInfoData error\n");
+    //    return;
+    //}
+    pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_GunIndex);
+
+    printf ("Charger Max Current = %d, Max Power = %d \n",
+            pSysConfig->MaxChargingCurrent * 10,
+            pSysConfig->MaxChargingPower * 10);
+
+    printf ("Index = %d, MaxPow = %f, MaxVol = %f, MaxCur = %f\n",
+            _GunIndex,
+            pDcChargingInfo->RealMaxPower,
+            pDcChargingInfo->RealMaxVoltage,
+            pDcChargingInfo->RealMaxCurrent);
+}
+
+static void setConfirmSelGun(uint8_t selGun)
+{
+    if (selGun == LEFT_GUN_NUM && ShmSelectGunInfo->SelGunInfo.LeftGun == SEL_GUN_RELEASE) {
+        ShmSelectGunInfo->SelGunInfo.LeftGun = SEL_GUN_CONFIRM;
+        //printf("confirmSelGun left\r\n");
+    } else if (selGun == RIGHT_GUN_NUM && ShmSelectGunInfo->SelGunInfo.RightGun == SEL_GUN_RELEASE) {
+        ShmSelectGunInfo->SelGunInfo.RightGun = SEL_GUN_CONFIRM;
+        //printf("confirmSelGun right\r\n");
+    }
+}
+
+void RunUnconditionalChargeIndex1(char *v1, char *v2, char *v3)
+{
+    int _GunIndex;
+    uint8_t gunIndex = 0;
+    uint8_t stopChg = 0;
+    uint8_t curGun = 0;
+    int isContinue = 1;
+    float _Voltage;
+    float _Current;
+    uint8_t PreviousSystemStatus[2] = {0xff};
+    char *usageMsg = "Usage:\n"
+                     "       strchg <index> <voltage> <current>    ex: strchg 0 150 2\n"
+                     "       chg    <voltage> <current>            ex: chg 500 100\n"
+                     "       c      <index>                        ex: c 0\n"
+                     "       help | ? | h\n"
+                     "\r\n";
+
+    if (strcmp(v1, "auto") == EQUAL) {
+        _usingAutoRun = 0x01;
+        _GunIndex = 0;
+        _Voltage = 500;
+        _Current = (pSysConfig->MaxChargingPower * 1000) / _Voltage;
+    } else {
+        _usingAutoRun = 0x00;
+        _GunIndex = atoi(v1);
+        _Voltage = atof(v2);
+        _Current = atof(v3);
+    }
+
+    pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_GunIndex);
+
+    printf("Power = %d, ReqVoltage = %f, ReqCurrent = %f\n",
+           pSysConfig->MaxChargingPower,
+           _Voltage,
+           _Current);
+
+    if (_Voltage > 1000 || _Voltage < 50) {
+        printf ("Input Voltage over range\n");
+        return;
+    }
+
+    //kill ev task
+    system("killall Module_EvComm");
+
+    pSysInfo->CurGunSelected = _GunIndex;
+
+    while (isContinue) {
+
+        curGun = pSysInfo->CurGunSelected;
+        pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(curGun);
+
+        //fix gun 1
+        switch (pDcChargingInfo->SystemStatus) {
+        case S_IDLE:
+            if (PreviousSystemStatus[curGun] != pDcChargingInfo->SystemStatus) {
+                PreviousSystemStatus[curGun] = pDcChargingInfo->SystemStatus;
+#if defined DD360Audi
+                setConfirmSelGun(curGun);
+#endif //defined DD360Audi
+
+                strcpy((char *)pSysConfig->UserId, "AutoStartCharging");
+                pDcChargingInfo->ConnectorPlugIn = 1;
+                printf ("[UnconditionalCharge - S_IDLE]\n");
+                pDcChargingInfo->Type = 9;
+
+            }
+            if (ShmOCPP16Data->SpMsg.bits.AuthorizeConf == 1) {
+                pSysInfo->StartToChargingFlag = 0x01;
+                pDcChargingInfo->SystemStatus = S_PREPARNING;
+            }
+            break;
+
+        case S_PREPARNING:
+            if (PreviousSystemStatus[curGun] != pDcChargingInfo->SystemStatus) {
+                PreviousSystemStatus[curGun] = pDcChargingInfo->SystemStatus;
+
+                printf ("[UnconditionalCharge - S_PREPARNIN]\n");
+
+                //等待 AC Relay 搭上且找到模組 (main 在此 statue 其它 task 會去做完)
+                printf ("wait find module\n");
+
+            }
+            //main 會在此階段判斷以下資料跳到下一個 state
+            //用來得知 AC 是否有搭上 (搭上模組的資訊才會出來) 因為每次  AC_Contactor
+            //ShmPsuData->SystemPresentPsuQuantity;
+            //ShmPsuData->PsuGroup[gun_index].GroupPresentPsuQuantity;
+            //ShmPsuData->PsuGroup[gun_index].GroupAvailablePower;
+            //_chargingData[gun_index]->AvailableChargingPower;
+
+            //等待 AC Relay 搭上且找到模組 (main 在此 statue 其它 task 會去做完)
+            //sleep(10);
+
+            //清除 main timeout 機制
+            pDcChargingInfo->TimeoutFlag = 0;
+            //不論是什麼 type 的槍都固意設成 Chademo 不跑 Prechage step
+            pDcChargingInfo->Type = 9;
+            break;
+
+        case S_PREPARING_FOR_EV:
+            if (PreviousSystemStatus[curGun] != pDcChargingInfo->SystemStatus) {
+                PreviousSystemStatus[curGun] = pDcChargingInfo->SystemStatus;
+
+                printf ("[UnconditionalCharge - S_PREPARING_FOR_EV]\n");
+                printf ("ReqVoltage = %f, ReqCurrent = %f \n", _Voltage * 10, _Current * 10);
+
+            }
+            //清除 main timeout 機制
+            pDcChargingInfo->TimeoutFlag = 0;
+            //不論是什麼 type 的槍都固意設成 Chademo 不跑 Prechage step
+            pDcChargingInfo->Type = 9;
+
+            //充電電壓電流
+            pDcChargingInfo->EvBatterySoc             = 50;
+            pDcChargingInfo->EvBatterytargetVoltage   = 500;
+            pDcChargingInfo->EvBatterytargetCurrent   = 2;
+            pDcChargingInfo->AvailableChargingCurrent = 1000;
+
+            //****** 注意~此行為是防止 K1K2 先開導到無法升壓 ( Relay Board 在此 state 還未搭上 K1K2 )
+            //確定模組己升壓完成
+            //if(pDcChargingInfo->PresentChargingVoltage <=  (3000+500) &&
+            //  pDcChargingInfo->PresentChargingVoltage >=  (3000-500) )
+            {
+                printf ("Precharge Done = %f \n",
+                        pDcChargingInfo->PresentChargingVoltage);
+                //EV done
+                pDcChargingInfo->SystemStatus = S_PREPARING_FOR_EVSE;
+            }
+            break;
+
+        case S_PREPARING_FOR_EVSE:
+            if (PreviousSystemStatus[curGun] != pDcChargingInfo->SystemStatus) {
+                PreviousSystemStatus[curGun] = pDcChargingInfo->SystemStatus;
+
+                printf ("[UnconditionalCharge - S_PREPARING_FOR_EVSE]\n");
+
+            }
+            //printf ("tar vol = %d \n", _Voltage);
+            //printf ("tar cur = %d \n", _Current);
+
+            //清除 main timeout 機制
+            pDcChargingInfo->TimeoutFlag = 0;
+            //不論是什麼 type 的槍都固意設成 Chademo 不跑 Prechage step
+            pDcChargingInfo->Type = 9;
+
+            //充電電壓電流
+            pDcChargingInfo->EvBatterySoc = 50;
+            pDcChargingInfo->EvBatterytargetVoltage = 500;
+            pDcChargingInfo->EvBatterytargetCurrent = 2;
+            pDcChargingInfo->AvailableChargingCurrent = 1000;
+
+            //printf ("tar vol_ = %d \n", pDcChargingInfo->EvBatterytargetVoltage);
+            // printf ("tar cur_ = %d \n", pDcChargingInfo->EvBatterytargetCurrent);
+
+            //****** 注意~此行為是防止 K1K2 先開導到無法升壓 ( Relay Board 在此 state 還未搭上 K1K2 )
+            //確定模組己升壓完成
+            if (pDcChargingInfo->GroundFaultStatus == 0x01 ||
+                    pDcChargingInfo->GroundFaultStatus == 0x03) {
+                printf ("First Ground Fault State (%d)\n",
+                        pDcChargingInfo->GroundFaultStatus);
+                printf ("Wait K1K2 = %f \n", pDcChargingInfo->PresentChargingVoltage);
+                sleep(5);
+                //EV done
+                pDcChargingInfo->SystemStatus = S_CHARGING;
+            } else if (pDcChargingInfo->GroundFaultStatus > 0x02) {
+                printf ("First Ground Fault check Fail (%d)\n",
+                        pDcChargingInfo->GroundFaultStatus);
+                pDcChargingInfo->SystemStatus = S_TERMINATING;
+            }
+            break;
+
+        case S_CHARGING:
+            if (PreviousSystemStatus[curGun] != pDcChargingInfo->SystemStatus) {
+                PreviousSystemStatus[curGun] = pDcChargingInfo->SystemStatus;
+
+                if (_usingAutoRun == 0x00) {
+                    //充電電壓電流
+                    pDcChargingInfo->EvBatterytargetVoltage = _Voltage;
+                    pDcChargingInfo->EvBatterytargetCurrent = _Current;
+                } else {
+                    _curAutoRunCount = 0;
+                    gettimeofday(&_autoTime, NULL);
+                }
+
+                pDcChargingInfo->EvBatterySoc = 50;
+                pDcChargingInfo->AvailableChargingCurrent = 1000;
+
+                printf ("[UnconditionalCharge - S_CHARGING]\n");
+            }
+
+            if (_usingAutoRun == 0x01) {
+                if (((GetTimeoutValue(_autoTime)) >= AUTORUN_STEP1_TIME_START * 60 &&
+                        (GetTimeoutValue(_autoTime)) <= AUTORUN_STEP1_TIME_END * 60) ||
+                        ((GetTimeoutValue(_autoTime)) >= AUTORUN_STEP2_TIME_START * 60 &&
+                         (GetTimeoutValue(_autoTime)) <= AUTORUN_STEP2_TIME_END * 60)
+                   ) {
+                    pDcChargingInfo->EvBatterytargetVoltage = _Voltage;
+                    pDcChargingInfo->EvBatterytargetCurrent = _Current;
+                } else if ((GetTimeoutValue(_autoTime)) >= AUTORUN_END_TIME * 60) {
+                    _curAutoRunCount++;
+                    if (_curAutoRunCount >= AUTORUN_CYCLE_COUNT) {
+                        pDcChargingInfo->SystemStatus = S_TERMINATING;
+                    } else {
+                        gettimeofday(&_autoTime, NULL);
+                    }
+                } else {
+                    pDcChargingInfo->EvBatterytargetVoltage = 0;
+                    pDcChargingInfo->EvBatterytargetCurrent = 0;
+                }
+            }
+
+//              printf("out : vol = %f, cur = %f \n",
+//                      pDcChargingInfo->EvBatterytargetVoltage,
+//                      pDcChargingInfo->EvBatterytargetCurrent);
+            //ev task do this
+            pDcChargingInfo->PresentChargingPower =
+                ((float)((pDcChargingInfo->PresentChargingVoltage) *
+                         (pDcChargingInfo->PresentChargingCurrent)) / 1000);
+
+            if (pDcChargingInfo->GroundFaultStatus == 0x02) {
+                printf ("Charging Ground Fault check Fail (%d)\n",
+                        pDcChargingInfo->GroundFaultStatus);
+                pDcChargingInfo->SystemStatus = S_TERMINATING;
+            }
+            break;
+
+        case S_TERMINATING:
+            if (PreviousSystemStatus[curGun] != pDcChargingInfo->SystemStatus) {
+                PreviousSystemStatus[curGun] = pDcChargingInfo->SystemStatus;
+
+                printf ("[UnconditionalCharge - S_TERMINATING]\n");
+                //無阻塞偵測 keybaord 結束
+                system(STTY_DEF TTY_PATH);
+            }
+
+            pDcChargingInfo->SystemStatus = S_COMPLETE;
+            break;
+
+        case S_COMPLETE:
+            if (PreviousSystemStatus[curGun] != pDcChargingInfo->SystemStatus) {
+                PreviousSystemStatus[curGun] = pDcChargingInfo->SystemStatus;
+
+                printf ("[UnconditionalCharge - S_COMPLETE]\n");
+            }
+
+            PreviousSystemStatus[curGun] = 0xFF;
+            stopChg = 0;
+            for (gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++) {
+                if (PreviousSystemStatus[gunIndex] == 0xFF) {
+                    pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(curGun);
+                    pDcChargingInfo->SystemStatus = S_IDLE;
+                } else {
+                    pSysInfo->CurGunSelected = gunIndex;
+                }
+
+                pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
+                if (pDcChargingInfo->SystemStatus == S_IDLE) {
+                    stopChg++;
+                }
+            }
+
+            pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(curGun);
+            pDcChargingInfo->PresentChargingPower = 0;
+
+            if (stopChg == pSysConfig->TotalConnectorCount) {
+                system("/root/Module_EvComm &");
+                sleep(3);
+
+                for (_GunIndex = 0; _GunIndex < pSysConfig->TotalConnectorCount; _GunIndex++) {
+                    pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_GunIndex);
+
+                    pDcChargingInfo->SystemStatus = S_IDLE;
+                }
+                return;
+            }
+            break;
+        }
+
+        if (readCmdKey(CMD_KEY_DONT_WAIT) == NO) {
+            continue;
+        }
+
+        if (strcmp(newString[0], "strchg") == 0) {
+            if (strcmp(newString[1], "-1") == 0 ||
+                    strcmp(newString[1], "") == 0 ||
+                    strcmp(newString[2], "-1") == 0 ||
+                    strcmp(newString[2], "") == 0
+               ) {
+                printf ("Input cmd fail ------  strchg [vol 150-1000] [cru 2-100]\n");
+                continue;
+            }
+
+            if (atoi(newString[1]) == pSysInfo->CurGunSelected) {
+                continue;
+            }
+
+            _GunIndex = atoi((char *)newString[1]);
+            _Voltage = atof((char *)newString[2]);
+            _Current = atof((char *)newString[3]);
+
+            printf ("Power = %d, ReqVoltage = %f, ReqCurrent = %f\n",
+                    pSysConfig->MaxChargingPower,
+                    _Voltage,
+                    _Current);
+
+            if (_Voltage > 1000 || _Voltage < 50) {
+                _Voltage = 200;
+                printf ("Input Voltage over range\n");
+                continue;
+            }
+
+            pSysInfo->CurGunSelected = _GunIndex;
+            strcpy((char *)pSysConfig->UserId, "");
+        } else if (strcmp(newString[0], "chg") == 0) {
+            if (strcmp(newString[1], "-1") == 0) {
+                continue;
+            }
+
+            if (strcmp(newString[2], "-1") == 0 ||
+                    strcmp(newString[2], "") == 0) {
+                continue;
+            }
+
+            if (strcmp(newString[3], "-1") == 0 ||
+                    strcmp(newString[3], "") == 0) {
+                continue;
+            }
+
+            _GunIndex = atoi((char *)newString[1]);
+            float _vol = atof(newString[2]);
+            float _cur = atof(newString[3]);
+
+            if (_cur <= 0 || _cur <= 0) {
+                continue;
+            }
+
+            pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_GunIndex);
+
+            printf("reset vol = %f, cur = %f \n", _vol, _cur);
+            pDcChargingInfo->EvBatterytargetVoltage = _vol;
+            pDcChargingInfo->EvBatterytargetCurrent = _cur;
+        } else if (strcmp(newString[0], "c") == 0) {
+            if (strcmp(newString[1], "-1") == 0 ||
+                    strcmp(newString[1], "") == 0) {
+                printf("argc 1 is error parameter\r\n");
+                continue;
+            }
+
+            if (atoi((char *)newString[1]) != -1) {
+                pSysInfo->CurGunSelected = atoi((char *)newString[1]);
+            }
+            printf("stop \n\r");
+
+            pSysInfo->StartToChargingFlag = 0x00;
+
+            pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData( pSysInfo->CurGunSelected);
+
+            pDcChargingInfo->SystemStatus = S_TERMINATING;
+        } else if (helpCmd() == YES) {
+            printf("%s\n", usageMsg);
+        }
+
+        usleep(100000);
+    }
+}
+
+int printTimeMsg(const char *fmt, ...)
+{
+    char Buf[4096 + 256] = {0};
+    char buffer[4096] = {0};
+    int rc = -1;
+    va_list args;
+    struct timeb  SeqEndTime;
+    struct tm *tm;
+    struct SysConfigData *pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
+
+    va_start(args, fmt);
+    rc = vsnprintf(buffer, sizeof(buffer), fmt, args);
+    va_end(args);
+
+    ftime(&SeqEndTime);
+    SeqEndTime.time = time(NULL);
+    tm = localtime(&SeqEndTime.time);
+
+    sprintf(Buf, "%02d:%02d:%02d:%03d - %s",
+            tm->tm_hour,
+            tm->tm_min,
+            tm->tm_sec,
+            SeqEndTime.millitm,
+            buffer);
+    printf("%s", Buf);
+
+    return rc;
+}
+
+static void resdGunAndChillerTemp(void)
+{
+    int isContinue = 1;
+    uint8_t i = 0;
+    uint32_t sleepTime = 500000;
+    uint32_t loopTime = 1000;
+    struct timeb showTime;
+    struct timeb nowTime;
+
+    char *usageMsg = "Usage:\n"
+                     "       t <index>: loop time, ex: t 1\n"
+                     "       exit | c | C: exit test\n"
+                     "       h | help | ?: show usage message\n"
+                     "\r\n";
+
+    ftime(&showTime);
+
+    while (isContinue) {
+        ftime(&nowTime);
+
+        if (DiffTimeb(showTime, nowTime) > loopTime ||
+                DiffTimeb(showTime, nowTime) < 0) {
+            for (i = 0; i < pSysConfig->TotalConnectorCount; i++) {
+
+                pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(i);
+
+                printTimeMsg("get gun %d temp = %3d, chiller = %3d, ConnTemp = %3d, %3d,SysTemp = %3d, %3d, %3d, %3d\r\n",
+                             i,
+                             pDcChargingInfo->ConnectorTemp,
+                             pDcChargingInfo->ChillerTemp,
+                             ShmDcCommonData->ConnectorTemp[i][0],
+                             ShmDcCommonData->ConnectorTemp[i][1],
+                             ShmDcCommonData->SystemTemp[0],
+                             ShmDcCommonData->SystemTemp[1],
+                             ShmDcCommonData->SystemTemp[2],
+                             ShmDcCommonData->SystemTemp[3]);
+            }//for
+            ftime(&showTime);
+        }
+
+        if (readCmdKey(CMD_KEY_DONT_WAIT) == NO) {
+            usleep(sleepTime);
+            continue;
+        }
+
+        if (strcmp(newString[0], "t") == 0) {
+            if (strcmp(newString[1], "-1") == 0 ||
+                    strcmp(newString[1], "") == 0 ||
+                    atoi((char *)newString[1]) > 255
+               ) {
+                printf("argc 1 is error parameter\r\n");
+                continue;
+            }
+
+            loopTime = ((atoi((char *)newString[1])) * 1000);
+            printf("loopTime = %d\r\n", loopTime);
+            ftime(&showTime);
+            continue;
+        } else if (exitCmd() == YES) {
+            return;
+        } else if (helpCmd() == YES) {
+            printf ("%s\n", usageMsg);
+        }
+
+        usleep(sleepTime);
+    }//while
+}
+static void writeOTPTemp(void)
+{
+    uint8_t _GunIndex = 0;
+    int isContinue = 1;
+    uint32_t sleepTime = 500000;
+    char *usageMsg = "Usage:\n"
+                     "       OTP  <temp_recovery>  <temp>, ex: OTP 140 150\n"
+                     "       exit | c | C\n"
+                     "       help | ? | h\n"
+                     "\r\n";
+
+    while (isContinue) {
+        if (readCmdKey(CMD_KEY_WAIT) == NO) {
+            sleep(sleepTime);
+            continue;
+        }
+
+        if (helpCmd() == YES) {
+            printf ("%s\n", usageMsg);
+            continue;
+        } else if (exitCmd() == YES) {
+            sleep(1);
+            return;
+        } 
+        if (strcmp(newString[0], "OTP") != 0) {
+            printf("argc 1 is error parameter\r\n");
+            continue;
+        }
+
+        if (atoi(newString[1]) > 255 ||
+                atoi(newString[1]) == -1) {
+            printf("Recovey temperature value overflow\r\n");
+            continue;
+        }
+
+        if (atoi(newString[2]) > 255 ||
+                atoi(newString[2]) == -1) {
+            printf("Recovey temperature value overflow\r\n");
+            continue;
+        }
+
+        pSysInfo->OTPTempR = atoi(newString[1]);
+        pSysInfo->OTPTemp = atoi(newString[2]);
+
+        printf("OTP Recovery Temp set:%d\n",pSysInfo->OTPTempR);
+        printf("OTP Temp set:%d\n",pSysInfo->OTPTemp);
+        usleep(sleepTime);
+    }//while
+}
+
+static void writeGunAndChillerTemp(void)
+{
+    uint8_t _GunIndex = 0;
+    int isContinue = 1;
+    uint32_t sleepTime = 500000;
+    char *usageMsg = "Usage:\n"
+                     "       conn    <index> <temp>, ex: conn 0 150\n"
+                     "       chiller <index> <temp>, ex: chiller 0 150\n"
+                     "       tempR\n"
+                     "       exit | c | C\n"
+                     "       help | ? | h\n"
+                     "\r\n";
+
+    ShmDcCommonData->TestTemperature = YES;
+
+    while (isContinue) {
+        if (readCmdKey(CMD_KEY_WAIT) == NO) {
+            sleep(sleepTime);
+            continue;
+        }
+
+        if (helpCmd() == YES) {
+            printf ("%s\n", usageMsg);
+            continue;
+        } else if (exitCmd() == YES) {
+            ShmDcCommonData->TestTemperature = NO;
+            sleep(1);
+            return;
+        } else if (strcmp(newString[0], "tempR") == 0) {
+            resdGunAndChillerTemp();
+        }
+
+        if ((strcmp(newString[0], "chiller") != 0) &&
+                (strcmp(newString[1], "-1") == 0 ||
+                 strcmp(newString[1], "") == 0)
+           ) {
+            printf("argc 1 is error parameter\r\n");
+            continue;
+        }
+
+        if (atoi(newString[2]) > 255 ||
+                atoi(newString[2]) == -1) {
+            printf("temperature value overflow\r\n");
+            continue;
+        }
+
+        _GunIndex = atoi((char *)newString[1]);
+
+        if (_GunIndex >= pSysConfig->TotalConnectorCount) {
+            printf("gun index over total connector\r\n");
+            continue;
+        }
+
+        if (strcmp(newString[0], "chiller") == 0) {//修改水冷機溫度值
+            if (_GunIndex >= 1) {
+                _GunIndex = 0; //只會有一個水冷機
+            }
+
+            pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_GunIndex);
+            pDcChargingInfo->ChillerTemp = atoi(newString[2]);
+            printf("set %d chiller temperature = %d\r\n",
+                   _GunIndex,
+                   pDcChargingInfo->ChillerTemp);
+        } else if (strcmp(newString[0], "conn") == 0) {//修改槍頭溫度值
+            pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_GunIndex);
+
+            pDcChargingInfo->ConnectorTemp = atoi(newString[2]);
+            printf("set %d connector temp = %d\r\n",
+                   _GunIndex,
+                   pDcChargingInfo->ConnectorTemp);
+        }
+
+        usleep(sleepTime);
+    }//while
+}
+
+int main(void)
+{
+    uint8_t _GunIndex = 0;
+    int isContinue = 1;
+    char *usageMsg = "Usage:\n"
+                     "       state <index>                     : get gun state\n"
+                     "       card                              : scanning card (x)\n"
+                     "       gun <index>                       : get gun plugit state\n"
+                     "       lock <index>                      : get gun locked state\n"
+                     "       sysid                             : test system ID\n"
+                     "       self                              : self test state (x)\n"
+                     "       version | v | -v                  : version of board (407 or relay or other)\n"
+                     "       update                            : update firmware\n"
+                     "       ac                                : get ac relay state (x) \n"
+                     "       cable <index> <state>             : set ground fault state\n"
+                     "       pow <index> <power>               : set power value\n"
+                     "       model                             : get system information\n"
+                     "       temp                              : get PSU temperature\n"
+                     "       fan <speed>                       : set fan board speed\n"
+                     "       strchg <auto>                     : auto test charging\n"
+                     "       strchg <index> <voltage <current> : select gun test charging\n"
+                     "       tempW                             : write connector header and Chiller temperature\r\n"
+                     "       tempR                             : print connector header and chiller temperature\r\n"
+                     "       OTP                               : Write OTP temperature\r\n"
+                     "\r\n";
+
+    if (CreateAllCsuShareMemory() == FAIL) {
+        printf("create share memory error\r\n");
+        return FAIL;
+    }
+
+    MappingGunChargingInfo("ReadCmdline Task");
+
+    pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
+    pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
+    pSysWarning = (struct WARNING_CODE_INFO *)GetShmSysWarningInfo();
+
+    pAlarmCode = (struct AlarmCodeData *)GetShmAlarmCodeData();
+
+    ShmCHAdeMOData = (struct CHAdeMOData *)GetShmCHAdeMOData();
+    ShmGBTData = (struct GBTData *)GetShmGBTData();
+    ShmCcsData = (struct CcsData *)GetShmCcsData();
+
+    ShmPrimaryMcuData = (struct PrimaryMcuData *)GetShmPrimaryMcuData();
+    ShmFanModuleData = (struct FanModuleData *)GetShmFanModuleData();
+    ShmRelayModuleData = (struct RelayModuleData *)GetShmRelayModuleData();
+    ShmLedModuleData = (struct LedModuleData *)GetShmLedModuleData();
+    ShmPsuData = (struct PsuData *)GetShmPsuData();
+    ShmOCPP16Data = (struct OCPP16Data *)GetShmOCPP16Data();
+    ShmSelectGunInfo = (SelectGunInfo *)GetShmSelectGunInfo();
+    ShmDcCommonData = (DcCommonInfo *)GetShmDcCommonData();
+
+//    for (_GunIndex = 0; _GunIndex < pSysConfig->TotalConnectorCount; _GunIndex++) {
+//        pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_GunIndex);
+
+//        pDcChargingInfo->SystemStatus = S_IDLE;
+//    }
+
+    while (isContinue) {
+        if (readCmdKey(CMD_KEY_WAIT) == NO) {
+            continue;
+        }
+
+        if (strcmp(newString[0], "state") == 0) {
+            if (strcmp(newString[1], "-1") == 0 ||
+                    strcmp(newString[1], "") == 0) {
+                continue;
+            }
+
+            // 槍狀態
+            RunStatusProc(newString[1], newString[2]);
+        } else if (strcmp(newString[0], "card") == 0) {
+            // 刷卡狀態
+            RunCardProc(newString[1], newString[2]);
+        } else if (strcmp(newString[0], "gun") == 0) {
+            if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0) {
+                continue;
+            }
+
+            // 插槍狀態
+            RunGunPlugitProc(newString[1], newString[2]);
+        } else if (strcmp(newString[0], "lock") == 0) {
+            if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0) {
+                continue;
+            }
+
+            // 插槍狀態
+            GetGunLockStatusProc(newString[1], newString[2]);
+        } else if (strcmp(newString[0], "sysid") == 0) {
+            // 測試 sys id
+            SetSystemIDProc();
+        } else if (strcmp(newString[0], "self") == 0) {
+            // CSU 自我檢測狀態
+            RunSelfProc(newString[1]);
+        } else if (strcmp(newString[0], "version") == 0 ||
+                   strcmp(newString[0], "v") == 0 ||
+                   strcmp(newString[0], "-v") == 0) {
+            //if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0) {
+            //    continue;
+            //}
+            // 取 FW 版號
+            GetFwVerProc();
+        } else if (strcmp(newString[0], "update") == 0) {
+            // 更新
+            FwUpdateFlagProc(newString[1]);
+        } else if (strcmp(newString[0], "ac") == 0) {
+            // AC contactor 狀態
+            CheckAcStatus(newString[1]);
+        } else if (strcmp(newString[0], "cable") == 0) {
+            if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0) {
+                continue;
+            }
+
+            // cable check pass
+            SetCableChkStatus(newString[1], newString[2]);
+        } else if (strcmp(newString[0], "pow") == 0) {
+            if (strcmp(newString[1], "-1") == 0 ||
+                    strcmp(newString[1], "") == 0) {
+                continue;
+            }
+            // cable check pass
+            SetPowerValue(newString[1], newString[2]);
+        } else if (strcmp(newString[0], "model") == 0) {
+            GetSystemInfo();
+        } else if (strcmp(newString[0], "select") == 0) {
+            // 取得 / 設定 當前選的槍號
+            GetGunSelectedNum(newString[1]);
+        } else if (strcmp(newString[0], "change") == 0) {
+            // 模擬按鈕改變選槍
+            ChangeGunNum();
+        } else if (strcmp(newString[0], "fan") == 0) {
+            // 設定風扇速度
+            SetFanSpeed(newString[1]);
+        } else if (strcmp(newString[0], "speed") == 0) {
+            // 取得風扇速度
+            GetFanSpeed();
+        } else if (strcmp(newString[0], "debug") == 0) {
+            // 設定 debug mode
+            SetDebugMode(newString[1]);
+        } else if (strcmp(newString[0], "gfd") == 0) {
+            // 設定盲沖使用 GFD 功能
+            SetGFDMode(newString[1]);
+        } else if (strcmp(newString[0], "temp") == 0) {
+            // 取得 PSU 溫度
+            GetPsuTemp();
+        } else if (strcmp(newString[0], "acin") == 0) {
+            // 取得三向輸入電壓
+            GetAcInputVol();
+        } else if (strcmp(newString[0], "psu") == 0) {
+            //如果連一個參數都沒有 (此命令不理會) 加上判斷第二參數
+            if (strcmp(newString[1], "-1") == 0 ||
+                    strcmp(newString[1], "") == 0) {
+                printf ("PSU : Param fail..Please retry again......\n");
+                continue;
+            }
+            // 取得 PSU 資訊
+            GetPsuInformation(newString[1], newString[2], newString[3]);
+        } else if (strcmp(newString[0], "cap") == 0) {
+            GetConnectorCapInfo(newString[1]);
+        } else if (strcmp(newString[0], "error") == 0) {
+            CreateOneError(newString[1]);
+        } else if (strcmp(newString[0], "auth") == 0) {
+            GetAuthorizeFlag(newString[1]);
+        } else if (strcmp(newString[0], "relay") == 0) {
+            GetRelayStatus(newString[1]);
+        } else if (strcmp(newString[0], "ccid") == 0) {
+            if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0 ||
+                    strcmp(newString[2], "-1") == 0 || strcmp(newString[2], "") == 0) {
+                printf ("Input ccid fail.\n");
+                continue;
+            }
+            SetChargingInfoCCID(newString[1], newString[2]);
+        } else if (strcmp(newString[0], "strchg") == 0) {
+            //如果連一個參數都沒有 (此命令不理會) 加上判斷第二參數
+            if (strcmp(newString[1], "auto") == 0) {
+                newString[2][0] = 0;
+                newString[3][0] = 0;
+            } else if (strcmp(newString[1], "-1") == 0 ||
+                       strcmp(newString[1], "") == 0   ||
+                       strcmp(newString[2], "-1") == 0 ||
+                       strcmp(newString[2], "") == 0) {
+                printf ("Input cmd fail ------  strchg [vol 150-1000] [cru 2-100]\n");
+                continue;
+            }
+
+            // 槍狀態
+            RunUnconditionalChargeIndex1(newString[1], newString[2], newString[3]);
+        } else if (strcmp(newString[0], "tempW") == 0) { //測試槍頭和水冷機溫度
+            writeGunAndChillerTemp();
+        } else if (strcmp(newString[0], "tempR") == 0) { //讀取槍頭和水冷機溫度
+            resdGunAndChillerTemp();
+        } else if (strcmp(newString[0], "OTP") == 0) { //測試槍頭和水冷機溫度
+            writeOTPTemp();
+        } else {
+            printf("%s\n", usageMsg);
+        }
+
+        sleep(1);
+    }//while
+
+    return 0;
+}

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


BIN
EVSE/Projects/DD360Audi/output/FactoryConfig


BIN
EVSE/Projects/DD360Audi/output/Module_ChkSysTask


BIN
EVSE/Projects/DD360Audi/output/Module_DoComm


BIN
EVSE/Projects/DD360Audi/output/Module_EvComm


BIN
EVSE/Projects/DD360Audi/output/Module_EventLogging


BIN
EVSE/Projects/DD360Audi/output/Module_InternalComm


BIN
EVSE/Projects/DD360Audi/output/Module_LcmControl


BIN
EVSE/Projects/DD360Audi/output/Module_PrimaryComm


BIN
EVSE/Projects/DD360Audi/output/Module_UpdateFW


BIN
EVSE/Projects/DD360Audi/output/ReadCmdline


BIN
EVSE/Projects/DD360Audi/output/main


BIN
EVSE/Projects/DD360Audi/output/simulation


+ 15 - 3
EVSE/Projects/define.h

@@ -897,9 +897,10 @@ struct SysInfoData
 	unsigned char BootingStatus;			// 0 : booting, 1 : Initializing Complete.
 	unsigned char AuthorizeFlag;			// 0 : None, 1 : Authorizing
 	unsigned char FactoryConfiguration;	//0: normal, 1: trigger, charger will return the configuration to factory default if trigger
-	float InputVoltageR;			//0~655.35 volt
-	float InputVoltageS;				//0~655.35 volt
-	float InputVoltageT;				//0~655.35 volt
+	float InputVoltageR;                    //0~655.35 volt
+	float InputVoltageS;                    //0~655.35 volt
+	float InputVoltageT;                    //0~655.35 volt
+	float InputVoltageDc;                   //0~655.35 volt
 	unsigned int SystemFanRotaSpeed;		//0 ~ 65535 RPM
 	unsigned int PsuFanRotaSpeed;			//0 ~ 65535 RPM
 	unsigned char AuxPower5V;				//0 ~ 255 volt
@@ -983,6 +984,8 @@ struct SysInfoData
     CabinetMiscCommand      CabinetMicsStatus;
     struct LocalSharingInfo localSharingInfo;           // Local power sharing info structure
     DC_Meter_Info DcMeterInfo[4];
+    unsigned char           OTPTemp;                    // OTP Temperature 
+    unsigned char           OTPTempR;                   // OTP Recovery Temperature
 };
 
 struct SysConfigAndInfo
@@ -4548,6 +4551,13 @@ struct StructSignedFirmwareStatusNotification
     int requestId;
 };
 
+struct StructSessionTarget
+{
+	unsigned char		targetSoc;			// Unit: %,   		0 is unlimit
+	unsigned short		targetEnergy;		// Unit: KWH		0 is unlimit
+	unsigned short		targetDuration;		// Unit: Minutes	0 is unlimit
+};
+
 struct OCPP16Data
 {
     unsigned char                           OcppServerURL[512];     //http: non-secure OCPP 1.5-S, https: secure OCPP 1.5-S, ws: non-secure OCPP 1.6-J, wss: secure OCPP 1.6-J"
@@ -4736,6 +4746,7 @@ struct OCPP16Data
     struct StructSecurityEventNotification          SecurityEventNotification;
     struct StructSignCertificate                    SignCertificate;
     struct StructSignedFirmwareStatusNotification   SignedFirmwareStatusNotification;
+    struct StructSessionTarget	                    SessionTarget[CONNECTOR_QUANTITY];
 };
 
 
@@ -6114,6 +6125,7 @@ struct OCPP20Data
 	struct UpdateFirmware_20					UpdateFirmware;
 	struct ChargingProfileType                  SmartChargingProfile[CONNECTOR_QUANTITY];
 	struct ChargingProfileType                  MaxChargingProfile;
+	struct StructSessionTarget	                SessionTarget[CONNECTOR_QUANTITY];
 };
 
 #endif // DEFINE_H_

+ 5 - 5
build_rootfs_copy.sh

@@ -2,10 +2,10 @@
 sudo rm /dev/ram*
 sleep 3
 #rm /mnt/e/Temp/IMAGE/*
-sudo make DD359Audi-rootfs
+sudo make DD360Audi-rootfs
 cp /opt/ti-processor-sdk-linux-am335x-evm-04.02.00.09/EVSE/Projects/DD360Audi/Images/* /mnt/e/Image/DD360Audi/
-sudo make DD360-rootfs
-cp /opt/ti-processor-sdk-linux-am335x-evm-04.02.00.09/EVSE/Projects/DD360/Images/* /mnt/e/Image/DD360/
-sudo make DD360ComBox-rootfs
-cp /opt/ti-processor-sdk-linux-am335x-evm-04.02.00.09/EVSE/Projects/DD360ComBox/Images/* /mnt/e/Image/DD360ComBox/
+#sudo make DD360-rootfs
+#cp /opt/ti-processor-sdk-linux-am335x-evm-04.02.00.09/EVSE/Projects/DD360/Images/* /mnt/e/Image/DD360/
+#sudo make DD360ComBox-rootfs
+#cp /opt/ti-processor-sdk-linux-am335x-evm-04.02.00.09/EVSE/Projects/DD360ComBox/Images/* /mnt/e/Image/DD360ComBox/