Browse Source

2021.01.15 / Jerry Wang

Action:
1. debug charging interrupt jump complete page.
2. debug Docomm charging info packet format.
3. remove CheckOutputVolNoneMatchFire() function.
4. push emergency button print message on fix page.

Files:
folow commit history.

Image version: V1.05.XX.XXXX.XX
Image checksum: XXXXXXXX
Jerry_Wang 4 years ago
parent
commit
fe3063d20e

+ 1 - 0
EVSE/Projects/DD360Audi/Apps/Module_EvComm.c

@@ -2292,6 +2292,7 @@ void CANReceiver()
                     //printf("id = %d, EvBatterytargetCurrent = %.2f\r\n", targetGun, _chargingData[targetGun]->EvBatterytargetCurrent);
 
                     _chargingData[targetGun]->RemainChargingDuration = ((short) frame.data[7] << 8) + (short) frame.data[6];
+                    //printf("RemainChargingDuration = %d\r\n",  _chargingData[targetGun]->RemainChargingDuration);
 
                     if (_chargingData[targetGun]->Type == _Type_Chademo) {
                         //if (ShmCHAdeMOData->ev[_chargingData[targetGun]->type_index].EvDetection != frame.data[0])

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

@@ -2274,7 +2274,7 @@ int main(void)
 
                     if (_chargingData[i]->SystemStatus == S_CHARGING) {
                         CheckOutputPowerOverCarReq(i);
-                        CheckOutputVolNoneMatchFire(i);
+                        //CheckOutputVolNoneMatchFire(i);
                     } else {
                         _isOutputNoneMatch[i] = NO;
                     }

+ 16 - 14
EVSE/Projects/DD360Audi/Apps/Module_LcmControl.c

@@ -365,19 +365,20 @@ void ChangeWarningFunc()
         if ((i - j) >= 5) {
             break;
         }
-        if ((memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i + ShmSysConfigAndInfo->SysWarningInfo.PageIndex * 5][0], "033900", 6) == 0) ||
-                (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i + ShmSysConfigAndInfo->SysWarningInfo.PageIndex * 5][0], "033901", 6) == 0) ||
-                (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i + ShmSysConfigAndInfo->SysWarningInfo.PageIndex * 5][0], "033902", 6) == 0) ||
-                (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i + ShmSysConfigAndInfo->SysWarningInfo.PageIndex * 5][0], "043627", 6) == 0) ||
-                (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i + ShmSysConfigAndInfo->SysWarningInfo.PageIndex * 5][0], "043628", 6) == 0) ||
-                (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i + ShmSysConfigAndInfo->SysWarningInfo.PageIndex * 5][0], "043622", 6) == 0)  ||
-                (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i + ShmSysConfigAndInfo->SysWarningInfo.PageIndex * 5][0], "043623", 6) == 0) ||
-                (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i + ShmSysConfigAndInfo->SysWarningInfo.PageIndex * 5][0], "043624", 6) == 0) ||
-                (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i + ShmSysConfigAndInfo->SysWarningInfo.PageIndex * 5][0], "043625", 6) == 0) ||
-                (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i + ShmSysConfigAndInfo->SysWarningInfo.PageIndex * 5][0], "043626", 6) == 0)  ||
-                (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i + ShmSysConfigAndInfo->SysWarningInfo.PageIndex * 5][0], "042241", 6) == 0) ||
-                (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i + ShmSysConfigAndInfo->SysWarningInfo.PageIndex * 5][0], "042242", 6) == 0)
-           ) {
+        if (
+            (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i + ShmSysConfigAndInfo->SysWarningInfo.PageIndex * 5][0], "033900", 6) == 0) ||
+            (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i + ShmSysConfigAndInfo->SysWarningInfo.PageIndex * 5][0], "033901", 6) == 0) ||
+            (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i + ShmSysConfigAndInfo->SysWarningInfo.PageIndex * 5][0], "033902", 6) == 0) ||
+            (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i + ShmSysConfigAndInfo->SysWarningInfo.PageIndex * 5][0], "043627", 6) == 0) ||
+            (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i + ShmSysConfigAndInfo->SysWarningInfo.PageIndex * 5][0], "043628", 6) == 0) ||
+            (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i + ShmSysConfigAndInfo->SysWarningInfo.PageIndex * 5][0], "043622", 6) == 0) ||
+            (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i + ShmSysConfigAndInfo->SysWarningInfo.PageIndex * 5][0], "043623", 6) == 0) ||
+            (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i + ShmSysConfigAndInfo->SysWarningInfo.PageIndex * 5][0], "043624", 6) == 0) ||
+            (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i + ShmSysConfigAndInfo->SysWarningInfo.PageIndex * 5][0], "043625", 6) == 0) ||
+            (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i + ShmSysConfigAndInfo->SysWarningInfo.PageIndex * 5][0], "043626", 6) == 0) ||
+            (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i + ShmSysConfigAndInfo->SysWarningInfo.PageIndex * 5][0], "042241", 6) == 0) ||
+            (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i + ShmSysConfigAndInfo->SysWarningInfo.PageIndex * 5][0], "042242", 6) == 0)
+        ) {
             j++;
             continue;
         }
@@ -1387,7 +1388,7 @@ void ProcessPageInfo()
     break;
 
     case _LCM_FIX:
-        if (ShmPrimaryMcuData->InputDet.bits.EmergencyButton != 1) {
+        if (ShmPrimaryMcuData->InputDet.bits.EmergencyButton == 1) {
             ChangeDisplay2Value(_emergency_map, _emergency_disable_map);
         } else {
             ChangeDisplay2Value(_emergency_map, _disappear);
@@ -1541,5 +1542,6 @@ int main(void)
     }
 
     CloseCommunicationLcmPort();
+
     return FAIL;
 }

+ 12 - 11
EVSE/Projects/DD360Audi/Apps/ReDoComm.c

@@ -44,7 +44,7 @@ static struct OCPP16Data        *ShmOCPP16Data;
 static struct PrimaryMcuData    *ShmPrimaryMcuData;
 static struct ChargingInfoData  *ChargingData[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
 static struct timeb             gRegTimeUp[2][MAX_REGISTER_NUM] = {0};
-static struct WARNING_CODE_INFO PreSysWarningInfo = {0};
+static struct WARNING_CODE_INFO gPreSysWarningInfo = {0};
 static AudiCustInfo             *gAudiCustInfo = NULL;
 
 //------------------------------------------------------------------------------
@@ -681,6 +681,7 @@ static int miscCommandHandle(uint8_t dataLen, uint8_t id, uint8_t *data)
                     gAudiCustInfo->SelGunInfo.LeftGun = SEL_GUN_RELEASE;
                     strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
                     ShmSysConfigAndInfo->SysInfo.WaitForPlugit = NO;
+                    sleep(1); //Jerry add
                     ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_SELECT_GUN;
                     gettimeofday(&ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer, NULL);
                     ShmSysConfigAndInfo->SysInfo.SystemTimeoutFlag = Timeout_None;
@@ -692,6 +693,7 @@ static int miscCommandHandle(uint8_t dataLen, uint8_t id, uint8_t *data)
                     gAudiCustInfo->SelGunInfo.RightGun = SEL_GUN_RELEASE;
                     strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
                     ShmSysConfigAndInfo->SysInfo.WaitForPlugit = NO;
+                    sleep(1); //Jerry add
                     ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_SELECT_GUN;
                     gettimeofday(&ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer, NULL);
                     ShmSysConfigAndInfo->SysInfo.SystemTimeoutFlag = Timeout_None;
@@ -1028,8 +1030,8 @@ static int responsePackeHandle(int fd, uint8_t *pResult, uint8_t id, uint8_t reg
         break;
 
     case REG_DISPENSER_STATUS:
-        memset(&PreSysWarningInfo, 0, sizeof(struct WARNING_CODE_INFO));
-        memcpy(&PreSysWarningInfo,
+        memset(&gPreSysWarningInfo, 0, sizeof(struct WARNING_CODE_INFO));
+        memcpy(&gPreSysWarningInfo,
                &(ShmSysConfigAndInfo->SysWarningInfo),
                sizeof(struct WARNING_CODE_INFO));
         break;
@@ -1199,10 +1201,10 @@ static int writePresentChargingInfo(int fd, uint8_t plugNum, uint8_t id)
     uint8_t dataBuf[16] = {0};
     PreChargingInfo *pPreChargingInfo = (PreChargingInfo *)dataBuf;
 
-    pPreChargingInfo->EvBatterySoc = htonl(ChargingData[plugNum]->EvBatterySoc);
+    pPreChargingInfo->PresentChargingVoltage = htons((uint16_t)ChargingData[plugNum]->PresentChargingVoltage * 10);
+    pPreChargingInfo->PresentChargingCurrent = htons((uint16_t)ChargingData[plugNum]->PresentChargingCurrent * 10);
     pPreChargingInfo->RemainChargingDuration = htonl(ChargingData[plugNum]->RemainChargingDuration);
-    pPreChargingInfo->PresentChargingVoltage = htonl(ChargingData[plugNum]->PresentChargingVoltage);
-    pPreChargingInfo->PresentChargingCurrent = htonl(ChargingData[plugNum]->PresentChargingCurrent);
+    pPreChargingInfo->EvBatterySoc = ChargingData[plugNum]->EvBatterySoc;
 
     ret = composeSocketData(fd,
                             id,
@@ -1420,7 +1422,7 @@ static int writeDispenserStatus(int fd)
     int ret = PASS;
 
     if ((ShmSysConfigAndInfo->SysWarningInfo.WarningCount <= 0) &&
-            (PreSysWarningInfo.WarningCount <= 0)) {
+            (gPreSysWarningInfo.WarningCount <= 0)) {
         return FAIL;
     }
 
@@ -1429,9 +1431,9 @@ static int writeDispenserStatus(int fd)
         memcpy(CurWarnCodeTmp[count], ShmSysConfigAndInfo->SysWarningInfo.WarningCode[count], WARNING_CODE_SIZE);
     }
 
-    warningCount = PreSysWarningInfo.WarningCount;
+    warningCount = gPreSysWarningInfo.WarningCount;
     for (count = 0; count < warningCount; count++) {
-        memcpy(PreWarnCodeTmp[count], PreSysWarningInfo.WarningCode[count], WARNING_CODE_SIZE);
+        memcpy(PreWarnCodeTmp[count], gPreSysWarningInfo.WarningCode[count], WARNING_CODE_SIZE);
     }
 
     if (strcmp((char *)&CurWarnCodeTmp[0], (char *)&PreWarnCodeTmp[0]) == 0) {
@@ -1869,8 +1871,7 @@ static void systemStatusProcess(int fd, uint8_t plugNum, uint8_t gunID)
         checkAuthorProcess(fd, plugNum);
 
         //authorization complete, write wait plug it state
-        if (gAudiCustInfo->PricesInfo[plugNum].Balance != FAIL_BALANCE_PRICES &&
-                ShmOCPP16Data->SpMsg.bits.AuthorizeConf == YES) {
+        if (gAudiCustInfo->PricesInfo[plugNum].Balance != FAIL_BALANCE_PRICES) {
             ftime(&AuthNowTime);
             if (DiffTimeb(gRegTimeUp[plugNum][REG_WAIT_PLUG_IT_STATE], AuthNowTime) > (LOOP_RETRY_TIME / 10)) {
                 writeWaitPlugItState(fd, gunID);

+ 3 - 3
EVSE/Projects/DD360Audi/Apps/ReDoComm.h

@@ -178,10 +178,10 @@ typedef struct StMiscCommand {
 } MiscCommand;
 
 typedef struct StPresentChargingInfo {
-    int EvBatterySoc;               // 0~100%
+    uint16_t PresentChargingVoltage;   //0~6553.5 volt
+    uint16_t PresentChargingCurrent;   //0~6553.5 amp
     int RemainChargingDuration;     // second
-    float PresentChargingVoltage;   //0~6553.5 volt
-    float PresentChargingCurrent;   //0~6553.5 amp
+    uint8_t EvBatterySoc;               // 0~100%
 } PreChargingInfo;
 
 typedef struct StSoftwareUpdInfo {

+ 339 - 122
EVSE/Projects/DD360Audi/Apps/main.c

@@ -155,7 +155,7 @@ bool isModelNameMatch = true;
 
 int rfidFd = -1;
 char *rfidPortName = "/dev/ttyS2";
-char *fwVersion = "V1.04.00.0000.00"; // "V0.16.00.0000.00";
+char *fwVersion = "V1.05.00.0000.00"; // "V0.16.00.0000.00";
 
 sqlite3 *localDb;
 bool isDb_ready;
@@ -1765,6 +1765,11 @@ bool isEvBoardStopChargeFlag(byte gunIndex)
     return chargingInfo[gunIndex]->StopChargeFlag;
 }
 
+bool isEvBoardNormalStopChargeFlag(byte gunIndex)
+{
+    return chargingInfo[gunIndex]->UnKnowStopChargeFlag;
+}
+
 //===============================================
 // 掃描插槍狀況
 //===============================================
@@ -2177,6 +2182,11 @@ void ChargingTerminalProcess(byte gunIndex)
     setChargerMode(gunIndex, MODE_TERMINATING);
 }
 
+void ChargingAlarmProcess(byte gunIndex)
+{
+    setChargerMode(gunIndex, MODE_ALARM);
+}
+
 void AcChargingTerminalProcess()
 {
     ac_chargingInfo[0]->SystemStatus = MODE_TERMINATING;
@@ -2217,13 +2227,21 @@ void EmcOccureByString(char *code)
     byte level = 2;
     // 嚴重的急停有以下幾種 : EMC 按鈕、Mainbreak、Dooropen
     // 其錯誤等級為 2
-    if (strncmp(code, "012251", 6) == EQUAL || strncmp(code, "012252", 6) == EQUAL || strncmp(code, "012238", 6) == EQUAL ||
-            strncmp(code, "042251", 6) == EQUAL || strncmp(code, "042252", 6) == EQUAL || strncmp(code, "012304", 6) == EQUAL ||
-            strncmp(code, "042200", 6) == EQUAL || strncmp(code, "042201", 6) == EQUAL || strncmp(code, "042202", 6) == EQUAL) {
+    if (strncmp(code, "012251", 6) == EQUAL ||
+            strncmp(code, "012252", 6) == EQUAL ||
+            strncmp(code, "012238", 6) == EQUAL ||
+            strncmp(code, "042251", 6) == EQUAL ||
+            strncmp(code, "042252", 6) == EQUAL ||
+            strncmp(code, "012304", 6) == EQUAL ||
+            strncmp(code, "042200", 6) == EQUAL ||
+            strncmp(code, "042201", 6) == EQUAL ||
+            strncmp(code, "042202", 6) == EQUAL ||
+            strncmp(code, "042267", 6) == EQUAL) {
         for (byte gun = 0; gun < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gun++) {
             if ((chargingInfo[gun]->SystemStatus > S_IDLE && chargingInfo[gun]->SystemStatus < S_TERMINATING) ||
                     (chargingInfo[gun]->SystemStatus >= S_CCS_PRECHARGE_ST0 && chargingInfo[gun]->SystemStatus <= S_CCS_PRECHARGE_ST1)) {
-                ChargingTerminalProcess(gun);
+                //ChargingTerminalProcess(gun);
+                ChargingAlarmProcess(gun);
             }
         }
 
@@ -3891,6 +3909,16 @@ bool OcppRemoteStop(byte gunIndex)
     return result;
 }
 
+bool WifiScheduleStop(byte gunIndex)
+{
+    bool result = false;
+
+    result = chargingInfo[gunIndex]->schedule.isTriggerStop;
+    chargingInfo[gunIndex]->schedule.isTriggerStop = NO;
+
+    return result;
+}
+
 void OcppRemoteStartChk()
 {
     if (ShmSysConfigAndInfo->SysConfig.OfflinePolicy == _OFFLINE_POLICY_NO_CHARGING)
@@ -4598,6 +4626,21 @@ bool GetStartChargingByAlterMode(byte _gun)
     return result;
 }
 
+void TheEndCharging(byte gun_index)
+{
+    ftime(&endChargingTime[gun_index]);
+    if (chargingInfo[gun_index]->PresentChargedDuration != 0) {
+        chargingInfo[gun_index]->PresentChargedDuration = DiffTimeb(startChargingTime[gun_index], endChargingTime[gun_index]);
+    }
+
+    chargingInfo[gun_index]->isRemoteStart = NO;
+
+    StopGunInfoTimeoutDet(gun_index);
+    StartGunInfoTimeoutDet(gun_index, Timeout_EvseCompleteDet);
+    ChangeStartOrStopDateTime(NO, gun_index);
+    DB_Insert_Record(localDb, gun_index);
+}
+
 void ResetDetAlarmStatus(byte gun)
 {
     if (chargingInfo[gun]->Type == _Type_Chademo) {
@@ -4615,6 +4658,17 @@ void ResetDetAlarmStatus(byte gun)
     }
 }
 
+static void powerCabinetPsuAlarmStatus(void)
+{
+    uint8_t i = 0;
+
+    for (i = 0; i < ShmSysConfigAndInfo->SysWarningInfo.WarningCount; i++) {
+        if (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], "042267", 6) == 0) {
+            EmcOccureByString("042267");
+        }
+    }
+}
+
 int main(void)
 {
     if (CreateShareMemory() == 0) {
@@ -4718,6 +4772,8 @@ int main(void)
         ClearAlarmCodeWhenAcOff();
         // 確認是否要回到充電中的槍畫面邏輯判斷
         CheckReturnToChargingConn();
+        //確認Power cabinet PSU Status
+        powerCabinetPsuAlarmStatus();
 
         if (_acgunIndex > 0 && isDetectPlugin() && !isCardScan) {
             ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_WAIT_FOR_PLUG;
@@ -4744,7 +4800,7 @@ int main(void)
             case S_IDLE:
             case S_RESERVATION:
             case S_MAINTAIN:
-            case S_ALARM: {
+            case S_FAULT: {
                 if (chargingInfo[gun_index]->SystemStatus == S_IDLE &&
                         isModeChange(gun_index)) {
                     DEBUG_INFO_MSG("S_IDLE================================== %x \n", gun_index);
@@ -4758,7 +4814,7 @@ int main(void)
                     //Jerry add
                     memset(&gAudiCustInfo->PricesInfo[gun_index], 0, sizeof(PricesInfo));
                     gAudiCustInfo->PricesInfo[gun_index].Balance = FAIL_BALANCE_PRICES;
-                    ResetDetAlarmStatus(gun_index);
+                    ResetDetAlarmStatus(gun_index); //recovery OVP status code
                 } else if (chargingInfo[gun_index]->SystemStatus == S_RESERVATION &&
                            isModeChange(gun_index)) {
                     DEBUG_INFO_MSG("S_RESERVATION....................%x \n", gun_index);
@@ -4770,22 +4826,33 @@ int main(void)
                 }
 
                 if (ShmSysConfigAndInfo->SysWarningInfo.Level == 2) {
-                    //if (gun_index == ShmSysConfigAndInfo->SysInfo.CurGunSelected)
-                    {
+                    if (gun_index == ShmSysConfigAndInfo->SysInfo.CurGunSelected) {
                         ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_FIX;
+                    } else if (chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus != S_IDLE &&
+                               chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus != S_RESERVATION &&
+                               chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus != S_MAINTAIN &&
+                               chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus != S_FAULT) {
+                        if (chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus == S_CHARGING) {
+                            ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_COMPLETE;
+                        } else {
+                            ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_SELECT_GUN;//_LCM_NONE;
+                        }
                     }
-                    ClearDetectPluginFlag();
-                    setChargerMode(gun_index, MODE_ALARM);
-                } else if (ShmSysConfigAndInfo->SysConfig.OfflinePolicy == _OFFLINE_POLICY_NO_CHARGING) {
-                    /*                           不給充電                        */
 
+                    ClearDetectPluginFlag();
+                    //UpdateErrorCodeToOcpp(gun_index);
+                    setChargerMode(gun_index, MODE_FAULT);
                 } else {
-                    if (ShmSysConfigAndInfo->SysInfo.SystemPage == _LCM_FIX) {
-                        ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_SELECT_GUN;//_LCM_NONE; //Jerry add
-                        for (byte g_index = 0; g_index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; g_index++) {
-                            setChargerMode(g_index, MODE_IDLE);
-                        }
+                    if (chargingInfo[gun_index]->SystemStatus == S_FAULT) {
+                        ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_SELECT_GUN;
+                        setChargerMode(gun_index, MODE_IDLE);
                     }
+                    //if (ShmSysConfigAndInfo->SysInfo.SystemPage == _LCM_FIX) {
+                    //    ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_SELECT_GUN;//_LCM_NONE; //Jerry add
+                    //    //for (byte g_index = 0; g_index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; g_index++) {
+                    //    setChargerMode(gun_index, MODE_IDLE);
+                    //    //}
+                    //}
 
                     if (ShmSysConfigAndInfo->SysInfo.MainChargingMode == _MAIN_CHARGING_MODE_AVER) {
 #if !defined DD360 && !defined DD360Audi
@@ -4816,7 +4883,11 @@ int main(void)
                         ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_NONE;
                     }
 
-                    {
+                    if (ShmSysConfigAndInfo->SysConfig.OfflinePolicy == _OFFLINE_POLICY_NO_CHARGING) {
+                        if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index) {
+                            ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_SELECT_GUN;//_LCM_IDLE;
+                        }
+                    } else {
                         // Idle 正常程序起點
                         // 判斷是否有啟用檢查插槍
                         if (isDetectPlugin()) {
@@ -4833,11 +4904,7 @@ int main(void)
                                     chargingInfo[gun_index]->RemoteStartFlag = NO;
                                     ChangeGunSelectByIndex(gun_index);
                                     AddPlugInTimes(gun_index);
-//#if defined DD360 || defined DD360Audi
-//                                    setChargerMode(gun_index, MODE_PRECHARGE);
-//#else
                                     setChargerMode(gun_index, MODE_REASSIGN_CHECK);
-//#endif //defined DD360 || defined DD360Audi
                                     strcpy((char *)chargingInfo[gun_index]->StartUserId, "");
                                     ClearDetectPluginFlag();
                                     continue;
@@ -4857,11 +4924,7 @@ int main(void)
                                     PRINTF_FUNC("index = %d, CardNumber = %s \n", gun_index, chargingInfo[gun_index]->StartUserId);
                                     strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
                                     // 當前操作的槍號,進入 Preparing
-                                    //#ifdef DD360
-                                    //setChargerMode(gun_index, MODE_PRECHARGE);
-                                    //#else
                                     setChargerMode(gun_index, MODE_REASSIGN_CHECK);
-                                    //#endif
                                     ClearDetectPluginFlag();
                                     continue;
                                 }
@@ -4883,11 +4946,7 @@ int main(void)
                             if (isCanStartChargingFlag) {
                                 ChangeGunSelectByIndex(gun_index);
                                 AddPlugInTimes(gun_index);
-                                //#ifdef DD360
-                                //setChargerMode(gun_index, MODE_PRECHARGE);
-                                //#else
                                 setChargerMode(gun_index, MODE_REASSIGN_CHECK);
-                                //#endif
                                 ClearDetectPluginFlag();
                                 continue;
                             }
@@ -4897,9 +4956,8 @@ int main(void)
                             }
                         }
                     } // Idle 正常程序終點
+                    ReleaseAlarmCode(gun_index);
                 }
-
-                ReleaseAlarmCode(gun_index);
             }
             break;
             case S_REASSIGN_CHECK: {
@@ -4947,14 +5005,15 @@ int main(void)
                         continue;
                     }
                 }
-#endif
-                if (0)
+#endif // 0
+
+                if (0) { // if (isRessign)
 #if defined DD360 || defined DD360Audi
                     setChargerMode(gun_index, MODE_PRECHARGE);
 #else
                     setChargerMode(gun_index, MODE_REASSIGN);
 #endif //defined DD360 || defined DD360Audi
-                else {
+                } else {
                     setChargerMode(gun_index, MODE_PRECHARGE);
                 }
 
@@ -5007,11 +5066,29 @@ int main(void)
                     }
                 }
 
-                if (isEvBoardStopChargeFlag(gun_index) == YES || OcppRemoteStop(gun_index) == YES) {
-                    // 板端或後臺要求停止
+                if (isEvBoardStopChargeFlag(gun_index) == YES) {
+                    // 板端要求停止 (錯誤)
+                    if (strcmp((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "") == EQUAL) {
+                        strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "EVDisconnected");
+                    }
+                    ChargingAlarmProcess(gun_index);
+                } else if (isEvBoardNormalStopChargeFlag(gun_index) == YES) {
+                    // 板端要求停止 (正常)
+                    if (strcmp((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "") == EQUAL) {
+                        strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "EVDisconnected");
+                    }
+                    ChargingTerminalProcess(gun_index);
+                } else if (OcppRemoteStop(gun_index) == YES ||
+                           WifiScheduleStop(gun_index)) {
+                    // 後臺要求停止
                     ChargingTerminalProcess(gun_index);
                 }
 
+                //if (isEvBoardStopChargeFlag(gun_index) == YES || OcppRemoteStop(gun_index) == YES) {
+                //    // 板端或後臺要求停止
+                //    ChargingTerminalProcess(gun_index);
+                //}
+
                 if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index) {
                     ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_PRE_CHARGE;
                 }
@@ -5042,12 +5119,30 @@ int main(void)
                     }
                 }
 
-                if (isEvBoardStopChargeFlag(gun_index) == YES  ||
-                        OcppRemoteStop(gun_index) == YES) {
-                    // 板端或後臺要求停止
+                if (isEvBoardStopChargeFlag(gun_index) == YES) {
+                    // 板端要求停止 (錯誤)
+                    if (strcmp((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "") == EQUAL) {
+                        strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "EVDisconnected");
+                    }
+                    ChargingAlarmProcess(gun_index);
+                } else if (isEvBoardNormalStopChargeFlag(gun_index) == YES) {
+                    // 板端要求停止 (正常)
+                    if (strcmp((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "") == EQUAL) {
+                        strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "EVDisconnected");
+                    }
+                    ChargingTerminalProcess(gun_index);
+                } else if (OcppRemoteStop(gun_index) == YES ||
+                           WifiScheduleStop(gun_index)) {
+                    // 後臺要求停止
                     ChargingTerminalProcess(gun_index);
                 }
 
+                //if (isEvBoardStopChargeFlag(gun_index) == YES  ||
+                //        OcppRemoteStop(gun_index) == YES) {
+                //    // 板端或後臺要求停止
+                //    ChargingTerminalProcess(gun_index);
+                //}
+
                 // LCM => Pre-charging
                 if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index) {
                     ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_PRE_CHARGE;
@@ -5092,12 +5187,7 @@ int main(void)
                     // 檢查樁端的 GFD 結果
                     if ((chargingInfo[gun_index]->GroundFaultStatus == GFD_PASS ||
                             chargingInfo[gun_index]->GroundFaultStatus == GFD_WARNING)) {
-#if defined DD360 || defined DD360Audi
-                        //setChargerMode(gun_index, MODE_CHARGING);
                         setChargerMode(gun_index, MODE_CCS_PRECHARGE_STEP0);
-#else
-                        setChargerMode(gun_index, MODE_CCS_PRECHARGE_STEP0);
-#endif //defined DD360 || defined DD360Audi
                     }
 
                     if (chargingInfo[gun_index]->GroundFaultStatus == GFD_FAIL) {
@@ -5109,12 +5199,30 @@ int main(void)
                     }
                 }
 
-                if (isEvBoardStopChargeFlag(gun_index) == YES ||
-                        OcppRemoteStop(gun_index) == YES) {
-                    // 板端或後臺要求停止
+                if (isEvBoardStopChargeFlag(gun_index) == YES) {
+                    // 板端要求停止 (錯誤)
+                    if (strcmp((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "") == EQUAL) {
+                        strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "EVDisconnected");
+                    }
+                    ChargingAlarmProcess(gun_index);
+                } else if (isEvBoardNormalStopChargeFlag(gun_index) == YES) {
+                    // 板端要求停止 (正常)
+                    if (strcmp((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "") == EQUAL) {
+                        strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "EVDisconnected");
+                    }
+                    ChargingTerminalProcess(gun_index);
+                } else if (OcppRemoteStop(gun_index) == YES ||
+                           WifiScheduleStop(gun_index)) {
+                    // 後臺要求停止
                     ChargingTerminalProcess(gun_index);
                 }
 
+                //if (isEvBoardStopChargeFlag(gun_index) == YES ||
+                //        OcppRemoteStop(gun_index) == YES) {
+                //    // 板端或後臺要求停止
+                //    ChargingTerminalProcess(gun_index);
+                //}
+
                 // LCM => Pre-charging
                 if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index) {
                     ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_PRE_CHARGE;
@@ -5140,12 +5248,14 @@ int main(void)
                     if (chargingInfo[gun_index]->GroundFaultStatus == GFD_FAIL) {
                         // GFD 錯誤停止
                         RecordAlarmCode(gun_index, "012234");
-                    } else if (((chargingInfo[gun_index]->EvBatterytargetVoltage * 10) > 0 && chargingInfo[gun_index]->EvBatterytargetVoltage < SYSTEM_MIN_VOL)/* ||
-(chargingInfo[gun_index]->PresentChargedDuration >= 10 && chargingInfo[gun_index]->PresentChargingVoltage < SYSTEM_MIN_VOL)*/) {
-                        // UVP
-                        RecordAlarmCode(gun_index, "012289");
-                        ChargingTerminalProcess(gun_index);
-                    } else if (chargingInfo[gun_index]->GroundFaultStatus == GFD_WARNING) {
+                    }
+                    //else if (((chargingInfo[gun_index]->EvBatterytargetVoltage * 10) > 0 && chargingInfo[gun_index]->EvBatterytargetVoltage < SYSTEM_MIN_VOL) ||
+                    //           (chargingInfo[gun_index]->PresentChargedDuration >= 10 && chargingInfo[gun_index]->PresentChargingVoltage < SYSTEM_MIN_VOL)) {
+                    //    // UVP
+                    //    RecordAlarmCode(gun_index, "012289");
+                    //    ChargingTerminalProcess(gun_index);
+                    //}
+                    else if (chargingInfo[gun_index]->GroundFaultStatus == GFD_WARNING) {
                         // GFD 警告
                         RecordWarningCode(gun_index, "012296");
                     }
@@ -5153,13 +5263,15 @@ int main(void)
                     if (chargingInfo[gun_index]->GroundFaultStatus == GFD_FAIL) {
                         // GFD 錯誤停止
                         RecordAlarmCode(gun_index, "012236");
-                    } else if (isPrechargeStatus_gb(gun_index) == 10 &&
-                               (((chargingInfo[gun_index]->EvBatterytargetVoltage * 10) > 0 && chargingInfo[gun_index]->EvBatterytargetVoltage < SYSTEM_MIN_VOL)/* ||
-(chargingInfo[gun_index]->PresentChargedDuration >= 10 && chargingInfo[gun_index]->PresentChargingVoltage < SYSTEM_MIN_VOL)*/)) {
-                        // UVP
-                        RecordAlarmCode(gun_index, "012290");
-                        ChargingTerminalProcess(gun_index);
-                    } else if (chargingInfo[gun_index]->GroundFaultStatus == GFD_WARNING) {
+                    }
+                    //else if (isPrechargeStatus_gb(gun_index) == 10 &&
+                    //           (((chargingInfo[gun_index]->EvBatterytargetVoltage * 10) > 0 && chargingInfo[gun_index]->EvBatterytargetVoltage < SYSTEM_MIN_VOL) ||
+                    //            (chargingInfo[gun_index]->PresentChargedDuration >= 10 && chargingInfo[gun_index]->PresentChargingVoltage < SYSTEM_MIN_VOL))) {
+                    //    // UVP
+                    //    RecordAlarmCode(gun_index, "012290");
+                    //    ChargingTerminalProcess(gun_index);
+                    //}
+                    else if (chargingInfo[gun_index]->GroundFaultStatus == GFD_WARNING) {
                         // GFD 警告
                         RecordWarningCode(gun_index, "012298");
                     }
@@ -5167,47 +5279,89 @@ int main(void)
                     if (chargingInfo[gun_index]->GroundFaultStatus == GFD_FAIL) {
                         // GFD 錯誤停止
                         RecordAlarmCode(gun_index, "012235");
-                    } else if (((chargingInfo[gun_index]->EvBatterytargetVoltage * 10) > 0 && chargingInfo[gun_index]->EvBatterytargetVoltage < SYSTEM_MIN_VOL)/* ||
-(chargingInfo[gun_index]->PresentChargedDuration >= 10 && chargingInfo[gun_index]->PresentChargingVoltage < SYSTEM_MIN_VOL)*/) {
-                        // UVP
-                        RecordAlarmCode(gun_index, "012288");
-                        ChargingTerminalProcess(gun_index);
-                    } else if (chargingInfo[gun_index]->GroundFaultStatus == GFD_WARNING) {
+                    }
+                    //else if (((chargingInfo[gun_index]->EvBatterytargetVoltage * 10) > 0 && chargingInfo[gun_index]->EvBatterytargetVoltage < SYSTEM_MIN_VOL) ||
+                    //           (chargingInfo[gun_index]->PresentChargedDuration >= 10 && chargingInfo[gun_index]->PresentChargingVoltage < SYSTEM_MIN_VOL)) {
+                    //    // UVP
+                    //    RecordAlarmCode(gun_index, "012288");
+                    //    ChargingTerminalProcess(gun_index);
+                    //}
+                    else if (chargingInfo[gun_index]->GroundFaultStatus == GFD_WARNING) {
                         // GFD 警告
                         RecordWarningCode(gun_index, "012297");
                     }
                 }
 
-                if (isEvBoardStopChargeFlag(gun_index) ||
-                        OcppRemoteStop(gun_index) ||
-                        CheckBackendChargingTimeout(gun_index) ||
-                        CheckBackendChargingEnergy(gun_index) ||
-                        strcmp((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "Invalid") == EQUAL) {
-                    DEBUG_INFO_MSG("S_CHARGING=======Stop=========================== %f \n", (chargingInfo[gun_index]->EvBatterytargetVoltage * 10));
-                    // 板端或後臺要求停止
+                if (isEvBoardStopChargeFlag(gun_index) == YES) {
+                    // 板端要求停止 (錯誤)
+                    if (strcmp((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "") == EQUAL) {
+                        strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "EVDisconnected");
+                    }
+                    ChargingAlarmProcess(gun_index);
+                } else if (isEvBoardNormalStopChargeFlag(gun_index) == YES) {
+                    // 板端要求停止 (正常)
+                    if (strcmp((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "") == EQUAL) {
+                        strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "EVDisconnected");
+                    }
+                    ChargingTerminalProcess(gun_index);
+                } else if (OcppRemoteStop(gun_index) == YES ||
+                           WifiScheduleStop(gun_index) ||
+                           CheckBackendChargingTimeout(gun_index) ||
+                           CheckBackendChargingEnergy(gun_index) ||
+                           strcmp((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "Invalid") == EQUAL) {
+
+                    // 後臺要求停止
                     ChargingTerminalProcess(gun_index);
                 }
 
+                //if (isEvBoardStopChargeFlag(gun_index) ||
+                //        OcppRemoteStop(gun_index) ||
+                //        CheckBackendChargingTimeout(gun_index) ||
+                //        CheckBackendChargingEnergy(gun_index) ||
+                //        strcmp((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "Invalid") == EQUAL) {
+                //    DEBUG_INFO_MSG("S_CHARGING=======Stop=========================== %f \n", (chargingInfo[gun_index]->EvBatterytargetVoltage * 10));
+                //    // 板端或後臺要求停止
+                //    ChargingTerminalProcess(gun_index);
+                //}
+
                 // LCM => Charging
                 if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index) {
                     ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_CHARGING;
                 }
             }
             break;
+            case S_ALARM:
             case S_TERMINATING: {
                 if (isModeChange(gun_index)) {
-                    DEBUG_INFO_MSG ("terminating......................... %x \n", gun_index);
+                    if (strcmp((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "") == EQUAL) {
+                        strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "Local");
+                    }
+
+                    if (chargingInfo[gun_index]->SystemStatus == S_ALARM) {
+                        PRINTF_FUNC("================== S_ALARM (%x) ================ \n", gun_index);
+                        //UpdateErrorCodeToOcpp(gun_index);
+
+                        if (strcmp((char *)chargingInfo[gun_index]->StartDateTime, "") != EQUAL) {
+                            OcppStopTransation(gun_index);
+                        }
+
+                        TheEndCharging(gun_index);
+                    } else {
+                        PRINTF_FUNC("================== S_TERMINATING (%x) ================ \n", gun_index);
+                    }
+
+                    //DEBUG_INFO_MSG ("terminating......................... %x \n", gun_index);
                     StopGunInfoTimeoutDet(gun_index);
                 }
 
                 if (chargingInfo[gun_index]->Type == _Type_Chademo) {
                     // 非車端的停止 : 需等待小板送出停止指令,讓車端解除槍
-                    if (isEvStopCharging_chademo(gun_index) == YES) {
-                        /*+++ 20200908, vern, disable it for DD360 +++*/
-                        /*if (strcmp((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "") == EQUAL)
-                            strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "Local");*/
-                        /*--- 20200908, vern, disable it for DD360 ---*/
-                    }
+                    //if (isEvStopCharging_chademo(gun_index) == YES) {
+                    //    /*+++ 20200908, vern, disable it for DD360 +++*/
+                    //    /*if (strcmp((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "") == EQUAL)
+                    //        strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "Local");*/
+                    //    /*--- 20200908, vern, disable it for DD360 ---*/
+                    //}
 
                     if (chargingInfo[gun_index]->GroundFaultStatus == GFD_FAIL) {
                         // GFD 錯誤停止
@@ -5217,19 +5371,19 @@ int main(void)
                         RecordWarningCode(gun_index, "012296");
                     }
 
-                    if (isEvStopCharging_chademo(gun_index) == YES ||
-                            isPrechargeStatus_chademo(gun_index) <= 0) {
-                        setChargerMode(gun_index, MODE_COMPLETE);
-                    }
+                    //if (isEvStopCharging_chademo(gun_index) == YES ||
+                    //        isPrechargeStatus_chademo(gun_index) <= 0) {
+                    //    setChargerMode(gun_index, MODE_COMPLETE);
+                    //}
                 } else if (chargingInfo[gun_index]->Type == _Type_GB) {
                     DEBUG_INFO_MSG("************ GB lock Status = %d, status = %d \n", isEvStopCharging_gb(gun_index), isPrechargeStatus_gb(gun_index));
                     // 非車端的停止 : 需等待小板送出停止指令,讓車端解除槍
-                    if (isEvStopCharging_chademo(gun_index) == YES) {
-                        /*+++ 20200908, vern, disable it for DD360 +++*/
-                        /*if (strcmp((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "") == EQUAL)
-                                strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "Local");*/
-                        /*--- 20200908, vern, disable it for DD360 ---*/
-                    }
+                    //if (isEvStopCharging_chademo(gun_index) == YES) {
+                    //    /*+++ 20200908, vern, disable it for DD360 +++*/
+                    //    /*if (strcmp((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "") == EQUAL)
+                    //            strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "Local");*/
+                    //    /*--- 20200908, vern, disable it for DD360 ---*/
+                    //}
 
                     if (chargingInfo[gun_index]->GroundFaultStatus == GFD_FAIL) {
                         // GFD 錯誤停止
@@ -5239,18 +5393,18 @@ int main(void)
                         RecordWarningCode(gun_index, "012298");
                     }
 
-                    if (isEvStopCharging_gb(gun_index) == YES ||
-                            isPrechargeStatus_gb(gun_index) <= 0) {
-                        setChargerMode(gun_index, MODE_COMPLETE);
-                    }
+                    //if (isEvStopCharging_gb(gun_index) == YES ||
+                    //        isPrechargeStatus_gb(gun_index) <= 0) {
+                    //    setChargerMode(gun_index, MODE_COMPLETE);
+                    //}
                 } else if (chargingInfo[gun_index]->Type == _Type_CCS_2) {
                     // 非車端的停止 : 需等待小板送出停止指令,讓車端解除槍
-                    if (isEvStopCharging_chademo(gun_index) == YES) {
-                        /*+++ 20200908, vern, disable it for DD360 +++*/
-                        /*if (strcmp((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "") == EQUAL)
-                                strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "Local");*/
-                        /*--- 20200908, vern, disable it for DD360 ---*/
-                    }
+                    //if (isEvStopCharging_chademo(gun_index) == YES) {
+                    //    /*+++ 20200908, vern, disable it for DD360 +++*/
+                    //    /*if (strcmp((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "") == EQUAL)
+                    //            strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "Local");*/
+                    //    /*--- 20200908, vern, disable it for DD360 ---*/
+                    //}
 
                     if (chargingInfo[gun_index]->GroundFaultStatus == GFD_FAIL) {
                         // GFD 錯誤停止
@@ -5260,17 +5414,42 @@ int main(void)
                         RecordWarningCode(gun_index, "012297");
                     }
 
-                    if (isEvStopCharging_ccs(gun_index) == YES &&
-                            (isPrechargeStatus_ccs(gun_index) >= 53 || isPrechargeStatus_ccs(gun_index) == 0 ||
-                             isPrechargeStatus_ccs(gun_index) == 13 || isPrechargeStatus_ccs(gun_index) == 14)) {
-                        setChargerMode(gun_index, MODE_COMPLETE);
+                    //if (isEvStopCharging_ccs(gun_index) == YES &&
+                    //        (isPrechargeStatus_ccs(gun_index) >= 53 || isPrechargeStatus_ccs(gun_index) == 0 ||
+                    //         isPrechargeStatus_ccs(gun_index) == 13 || isPrechargeStatus_ccs(gun_index) == 14)) {
+                    //    setChargerMode(gun_index, MODE_COMPLETE);
+                    //}
+                }
+
+                if (chargingInfo[gun_index]->SystemStatus == S_ALARM) {
+                    if (chargingInfo[gun_index]->ConnectorPlugIn == NO &&
+                            GetTimeoutValue(chargingInfo[gun_index]->TimeoutTimer) >= 10000000) {
+                        setChargerMode(gun_index, MODE_IDLE);
+                    }
+                } else {
+                    if (chargingInfo[gun_index]->Type == _Type_Chademo) {
+                        if (isEvStopCharging_chademo(gun_index) == YES ||
+                                isPrechargeStatus_chademo(gun_index) <= 0) {
+                            setChargerMode(gun_index, MODE_COMPLETE);
+                        }
+                    } else if (chargingInfo[gun_index]->Type == _Type_GB) {
+                        if (isEvStopCharging_gb(gun_index) == YES ||
+                                isPrechargeStatus_gb(gun_index) <= 0) {
+                            setChargerMode(gun_index, MODE_COMPLETE);
+                        }
+                    } else if (chargingInfo[gun_index]->Type == _Type_CCS_2) {
+                        if (isEvStopCharging_ccs(gun_index) == YES &&
+                                (isPrechargeStatus_ccs(gun_index) >= 53 || isPrechargeStatus_ccs(gun_index) == 0 ||
+                                 isPrechargeStatus_ccs(gun_index) == 13 || isPrechargeStatus_ccs(gun_index) == 14)) {
+                            setChargerMode(gun_index, MODE_COMPLETE);
+                        }
                     }
                 }
 
                 // 車端的停止
-                if (strcmp((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "") == EQUAL) {
-                    strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "EVDisconnected");
-                }
+                //if (strcmp((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "") == EQUAL) {
+                //    strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "EVDisconnected");
+                //}
 
                 if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index) {
                     ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_COMPLETE;
@@ -5283,19 +5462,27 @@ int main(void)
                     if (strcmp((char *)chargingInfo[gun_index]->StartDateTime, "") != EQUAL) {
                         OcppStopTransation(gun_index);
                     }
-                    ftime(&endChargingTime[gun_index]);
-                    if (chargingInfo[gun_index]->PresentChargedDuration != 0) {
-                        chargingInfo[gun_index]->PresentChargedDuration = DiffTimeb(startChargingTime[gun_index], endChargingTime[gun_index]);
-                    }
 
-                    StopGunInfoTimeoutDet(gun_index);
-                    StartGunInfoTimeoutDet(gun_index, Timeout_EvseCompleteDet);
-                    ChangeStartOrStopDateTime(NO, gun_index);
+                    TheEndCharging(gun_index);
+                    //ftime(&endChargingTime[gun_index]);
+                    //if (chargingInfo[gun_index]->PresentChargedDuration != 0) {
+                    //    chargingInfo[gun_index]->PresentChargedDuration = DiffTimeb(startChargingTime[gun_index], endChargingTime[gun_index]);
+                    //}
+
+                    //StopGunInfoTimeoutDet(gun_index);
+                    //StartGunInfoTimeoutDet(gun_index, Timeout_EvseCompleteDet);
+                    //ChangeStartOrStopDateTime(NO, gun_index);
                 }
 
-                if (((chargingInfo[gun_index]->ConnectorPlugIn == NO) ||
-                        (restartFlag == 1)) &&
-                        (GetTimeoutValue(chargingInfo[gun_index]->TimeoutTimer) >= 10000000)) {
+                //if (((chargingInfo[gun_index]->ConnectorPlugIn == NO) ||
+                //        (restartFlag == 1)) &&
+                //        (GetTimeoutValue(chargingInfo[gun_index]->TimeoutTimer) >= 10000000)) {
+                //    setChargerMode(gun_index, MODE_IDLE);
+                //    destroySelGun(gun_index); //Jerry add
+                //}
+
+                if (chargingInfo[gun_index]->ConnectorPlugIn == NO &&
+                        GetTimeoutValue(chargingInfo[gun_index]->TimeoutTimer) >= 10000000) {
                     setChargerMode(gun_index, MODE_IDLE);
                     destroySelGun(gun_index); //Jerry add
                 }
@@ -5318,17 +5505,35 @@ int main(void)
                 }
 
                 if (isEvBoardStopChargeFlag(gun_index) == YES) {
-                    // 板端要求停止
+                    // 板端要求停止 (錯誤)
+                    ChargingAlarmProcess(gun_index);
+                } else if (isEvBoardNormalStopChargeFlag(gun_index) == YES) {
+                    // 板端要求停止 (正常)
+                    ChargingTerminalProcess(gun_index);
+                } else if (OcppRemoteStop(gun_index) == YES ||
+                           WifiScheduleStop(gun_index)) {
+                    // 後臺要求停止
                     ChargingTerminalProcess(gun_index);
                 }
 
+                //if (isEvBoardStopChargeFlag(gun_index) == YES) {
+                //    // 板端要求停止
+                //    ChargingTerminalProcess(gun_index);
+                //}
+
                 // 等待 EV 小板 (CCS) 通知可以開始 Precharge
                 // 切換 D+ Relay to Precharge Relay
                 if (isPrechargeStatus_ccs(gun_index) == 39 || isPrechargeStatus_ccs(gun_index) == 40) {
                     if (chargingInfo[gun_index]->RelayKPK2Status == YES && chargingInfo[gun_index]->PrechargeStatus != PRECHARGE_READY)
                         //if (chargingInfo[gun_index]->PrechargeStatus != PRECHARGE_PRERELAY_PASS)
                     {
-                        PRINTF_FUNC("Send precharge ready 1..........%x, status = %d \n", gun_index, isPrechargeStatus_ccs(gun_index));
+                        //PRINTF_FUNC("Send precharge ready 1..........%x, status = %d \n", gun_index, isPrechargeStatus_ccs(gun_index));
+                        if (isPrechargeStatus_ccs(gun_index) == 39) {
+                            PRINTF_FUNC("Conn %x, Precharge ready, CCS status = PreChargeResponse (%d) \n", gun_index, isPrechargeStatus_ccs(gun_index));
+                        } else if (isPrechargeStatus_ccs(gun_index) == 40) {
+                            PRINTF_FUNC("Conn %x, Precharge ready, CCS status = PowerDeliveryRequest start (%d) \n", gun_index, isPrechargeStatus_ccs(gun_index));
+                        }
+
                         chargingInfo[gun_index]->PrechargeStatus = PRECHARGE_READY;
                     }
                 } else if (isPrechargeStatus_ccs(gun_index) == 45 || isPrechargeStatus_ccs(gun_index) == 46) {
@@ -5351,10 +5556,22 @@ int main(void)
                 }
 
                 if (isEvBoardStopChargeFlag(gun_index) == YES) {
-                    // 板端要求停止
+                    // 板端要求停止 (錯誤)
+                    ChargingAlarmProcess(gun_index);
+                } else if (isEvBoardNormalStopChargeFlag(gun_index) == YES) {
+                    // 板端要求停止 (正常)
+                    ChargingTerminalProcess(gun_index);
+                } else if (OcppRemoteStop(gun_index) == YES ||
+                           WifiScheduleStop(gun_index)) {
+                    // 後臺要求停止
                     ChargingTerminalProcess(gun_index);
                 }
 
+                //if (isEvBoardStopChargeFlag(gun_index) == YES) {
+                //    // 板端要求停止
+                //    ChargingTerminalProcess(gun_index);
+                //}
+
                 // 等待小板通知進入充電
                 // 切換 D+ Relay to Precharge Relay
                 if (chargingInfo[gun_index]->RelayK1K2Status == YES) {

BIN
EVSE/Projects/DD360Audi/AudiUI/DWIN_SET_AudiUI_Emergence_20210113.7z


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


BIN
EVSE/Projects/DD360Audi/output/DoComm


BIN
EVSE/Projects/DD360Audi/output/Module_EvComm


BIN
EVSE/Projects/DD360Audi/output/Module_InternalComm


BIN
EVSE/Projects/DD360Audi/output/Module_LcmControl


BIN
EVSE/Projects/DD360Audi/output/main