Pārlūkot izejas kodu

2020-02-24 / Alston Lin

Actions
1. Fix the connector stay on alarm status that is by ev board gfd fail

Files
1. As follow commit history

Image Version: D0.01.04.20.02.00
Alston 5 gadi atpakaļ
vecāks
revīzija
ba397ae85d

+ 20 - 20
EVSE/Projects/DS60-120/Apps/Makefile

@@ -13,74 +13,74 @@ apps: MainTask EvCommTask EventLoggingTask InternalCommTask LcmControlTask Prima
 MainTask:
 	rm -f *.o
 	rm -f main;
-	$(CC) -include../../../Modularization/Module_RFID.h -O0 -g3 -Wall -c -fmessage-length=0 -o main.o main.c
-	$(CC) -include../../../Modularization/Module_RFID.h -O0 -g3 -Wall -c -fmessage-length=0 -o timeout.o timeout.c
+	$(CC) -D $(Project) -include../../../Modularization/Module_RFID.h -O0 -g3 -Wall -c -fmessage-length=0 -o main.o main.c
+	$(CC) -D $(Project) -include../../../Modularization/Module_RFID.h -O0 -g3 -Wall -c -fmessage-length=0 -o timeout.o timeout.c
 	$(CC) -o main main.o timeout.o ../../../Modularization/libModule_RFID.a ../../../Modularization/libModule_Upgrade.a	
 	cp -f main ../Images/root
 
 EvCommTask:
 	rm -f Module_EvComm;
-	$(CC) -includeConfig.h -O0 -g3 -Wall -c -fmessage-length=0 -o Ev_Comm.o Ev_Comm.c
-	$(CC) -includeConfig.h -O0 -g3 -Wall -c -fmessage-length=0 -o Module_EvComm.o Module_EvComm.c
+	$(CC) -D $(Project) -includeConfig.h -O0 -g3 -Wall -c -fmessage-length=0 -o Ev_Comm.o Ev_Comm.c
+	$(CC) -D $(Project) -includeConfig.h -O0 -g3 -Wall -c -fmessage-length=0 -o Module_EvComm.o Module_EvComm.c
 	$(CC) -o Module_EvComm Ev_Comm.o Module_EvComm.o
 	cp -f Module_EvComm ../Images/root	
 	
 EventLoggingTask:
 	rm -f Module_EventLogging;
-	$(CC) -includeConfig.h -O0 -g3 -Wall -c -fmessage-length=0 -o Module_EventLogging.o Module_EventLogging.c
+	$(CC) -D $(Project) -includeConfig.h -O0 -g3 -Wall -c -fmessage-length=0 -o Module_EventLogging.o Module_EventLogging.c
 	$(CC) -o Module_EventLogging Module_EventLogging.o 	
 	cp -f Module_EventLogging ../Images/root	
 	
 InternalCommTask:
 	rm -f Module_InternalComm; 
-	$(CC) -includeConfig.h -O0 -g3 -Wall -c -fmessage-length=0 -o internalComm.o internalComm.c
-	$(CC) -includeConfig.h -O0 -g3 -Wall -c -fmessage-length=0 -o Module_InternalComm.o Module_InternalComm.c
+	$(CC) -D $(Project) -includeConfig.h -O0 -g3 -Wall -c -fmessage-length=0 -o internalComm.o internalComm.c
+	$(CC) -D $(Project) -includeConfig.h -O0 -g3 -Wall -c -fmessage-length=0 -o Module_InternalComm.o Module_InternalComm.c
 	$(CC) -o Module_InternalComm Module_InternalComm.o internalComm.o 	
 	cp -f Module_InternalComm ../Images/root
 	
 LcmControlTask:
 	rm -f Module_LcmControl; 
-	$(CC) -includeConfig.h -O0 -g3 -Wall -c -fmessage-length=0 -o Module_LcmControl.o Module_LcmControl.c
+	$(CC) -D $(Project) -includeConfig.h -O0 -g3 -Wall -c -fmessage-length=0 -o Module_LcmControl.o Module_LcmControl.c
 	$(CC) -o Module_LcmControl Module_LcmControl.o
 	cp -f Module_LcmControl ../Images/root			
 
 PrimaryCommTask:
 	rm -f Module_PrimaryComm; 
-	$(CC) -includeConfig.h -O0 -g3 -Wall -c -fmessage-length=0 -o Module_PrimaryComm.o Module_PrimaryComm.c
-	$(CC) -includeConfig.h -O0 -g3 -Wall -c -fmessage-length=0 -o PrimaryComm.o PrimaryComm.c
+	$(CC) -D $(Project) -includeConfig.h -O0 -g3 -Wall -c -fmessage-length=0 -o Module_PrimaryComm.o Module_PrimaryComm.c
+	$(CC) -D $(Project) -includeConfig.h -O0 -g3 -Wall -c -fmessage-length=0 -o PrimaryComm.o PrimaryComm.c
 	$(CC) -o Module_PrimaryComm Module_PrimaryComm.o PrimaryComm.o
 	cp -f Module_PrimaryComm ../Images/root	
 
 PsuCommTask:
 	rm -f Module_PsuComm; 
-	$(CC) -include../../../Modularization/Infypwr_PsuCommObj.h -includeConfig.h -O0 -g3 -Wall -c -fmessage-length=0 -o Module_PsuComm.o Module_PsuComm.c
+	$(CC) -D $(Project) -include../../../Modularization/Infypwr_PsuCommObj.h -includeConfig.h -O0 -g3 -Wall -c -fmessage-length=0 -o Module_PsuComm.o Module_PsuComm.c
 	$(CC) -o Module_PsuComm Module_PsuComm.o ../../../Modularization/libInfypwr_PsuCommObj.a
 	cp -f Module_PsuComm ../Images/root	
 	
 ReadCmdlineTask:
 	rm -f ReadCmdline; 
-	$(CC) -includeConfig.h -O0 -g3 -Wall -c -fmessage-length=0 -o ReadCmdline.o ReadCmdline.c
+	$(CC) -D $(Project) -includeConfig.h -O0 -g3 -Wall -c -fmessage-length=0 -o ReadCmdline.o ReadCmdline.c
 	$(CC) -o ReadCmdline ReadCmdline.o
 	cp -f ReadCmdline ../Images/root
 
-WebService:
-	cp -f ../../../Modularization/WebService ../Images/root
-
-4GTask:
-	cp -f ../../../Modularization/Module_4g ../Images/root
-
 FactoryConfigApp:
 	@echo "===== Module_FactoryConfig_Task =================================="
 	rm -f FactoryConfig
-	gcc "-I../../" -o FactoryConfig "./FactoryConfig.c"
+	gcc -D $(Project) "-I../../" -o FactoryConfig "./FactoryConfig.c"
 	mkdir -p /Storage/SystemLog	
 	./FactoryConfig -f;true
 	cp /mnt/FactoryDefaultConfig.bin ../Images
 	rm -f FactoryConfig; 
-	$(CC) -O0 -g3 -Wall -c -fmessage-length=0 -o FactoryConfig.o FactoryConfig.c 
+	$(CC) -D $(Project) -O0 -g3 -Wall -c -fmessage-length=0 -o FactoryConfig.o FactoryConfig.c 
 	$(CC) -o FactoryConfig FactoryConfig.o 
 	cp -f FactoryConfig ../Images/root
 
+WebService:
+	cp -f ../../../Modularization/WebService ../Images/root
+
+4GTask:
+	cp -f ../../../Modularization/Module_4g ../Images/root
+
 OtherTools:
 	cp -f init.sh ../Images/root
 	cp -f kill.sh ../Images/root

+ 9 - 37
EVSE/Projects/DS60-120/Apps/Module_EvComm.c

@@ -380,19 +380,6 @@ void AddrAssignment(byte *data)
 
 void ClearAbnormalStatus_Chademo(byte gun_index)
 {
-	int codeValue = 0;
-
-	if (strlen((char *)ShmSysConfigAndInfo->SysStopChargingAlarmCode.StopCode[gun_index]) == 6)
-	{
-		codeValue = atoi((char *)ShmSysConfigAndInfo->SysStopChargingAlarmCode.StopCode[gun_index]);
-
-		if (codeValue >= 23700 && codeValue <= 23736)
-		{
-			memcpy(&ShmSysConfigAndInfo->SysStopChargingAlarmCode.StopCode[gun_index][0], "", 7);
-			ShmSysConfigAndInfo->SysStopChargingAlarmCode.Level = 0;
-		}
-	}
-
 	ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoEvCommFail = 0x00;
 	ShmStatusCodeData->InfoCode.InfoEvents.bits.PilotFault = 0x00;
 	ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBatteryMalfun = 0x00;
@@ -432,19 +419,6 @@ void ClearAbnormalStatus_Chademo(byte gun_index)
 
 void ClearAbnormalStatus_CCS(byte gun_index)
 {
-	int codeValue = 0;
-
-	if (strlen((char *)ShmSysConfigAndInfo->SysStopChargingAlarmCode.StopCode[gun_index]) == 6)
-	{
-		codeValue = atoi((char *)ShmSysConfigAndInfo->SysStopChargingAlarmCode.StopCode[gun_index]);
-
-		if (codeValue >= 23737 && codeValue <= 23888)
-		{
-			memcpy(&ShmSysConfigAndInfo->SysStopChargingAlarmCode.StopCode[gun_index][0], "", 7);
-			ShmSysConfigAndInfo->SysStopChargingAlarmCode.Level = 0;
-		}
-	}
-
 	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsRESTemperatureInhibit = 0x00;
 	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsEVShiftPosition = 0x00;
 	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsChargerConnectorLockFault = 0x00;
@@ -585,14 +559,6 @@ void AbnormalStopAnalysis(byte gun_index, byte *errCode)
 	char string[7];
 	sprintf(string, "%d%d%d%d%d%d", *(errCode + 5), *(errCode + 4), *(errCode + 3), *(errCode + 2), *(errCode + 1), *(errCode + 0));
 
-	if (gun_index < gun_count)
-	{
-		if (strlen((char *)ShmSysConfigAndInfo->SysStopChargingAlarmCode.StopCode[gun_index]) <= 0)
-		{
-			memcpy(&ShmSysConfigAndInfo->SysStopChargingAlarmCode.StopCode[gun_index][0], string, 7);
-			ShmSysConfigAndInfo->SysStopChargingAlarmCode.Level = 0x00;
-		}
-	}
 	PRINTF_FUNC("NOTIFICATION_EV_STOP : Err Code = %s \n", string);
 
 	if (strcmp(string, "023700") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoEvCommFail = 0x01;
@@ -1102,8 +1068,10 @@ void GetMaxPowerMethod(float *pow)
 		*pow = maxChargingPow;
 }
 
-void GetStopChargingReasonByEvse(byte gunIndex, byte *reason)
+byte GetStopChargingReasonByEvse(byte gunIndex, byte *reason)
 {
+	byte result = NO;
+
 	if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.EmergencyStopTrip == 0x01)
 	{
 		// 012251
@@ -1113,6 +1081,7 @@ void GetStopChargingReasonByEvse(byte gunIndex, byte *reason)
 		*(reason + 2)  = 2;
 		*(reason + 1)  = 5;
 		*(reason + 0)  = 1;
+		result = YES;
 	}
 	else if (_chargingData[gunIndex]->Type == _Type_Chademo &&
 			ShmStatusCodeData->FaultCode.FaultEvents.bits.ChademoOutputRelayDrivingFault == 0x01)
@@ -1124,6 +1093,7 @@ void GetStopChargingReasonByEvse(byte gunIndex, byte *reason)
 		*(reason + 2) = 0;
 		*(reason + 1) = 1;
 		*(reason + 0) = 2;
+		result = YES;
 	}
 	else if (_chargingData[gunIndex]->Type == _Type_CCS_2 &&
 			ShmStatusCodeData->FaultCode.FaultEvents.bits.CcsOutputRelayDrivingFault == 0x01)
@@ -1135,7 +1105,10 @@ void GetStopChargingReasonByEvse(byte gunIndex, byte *reason)
 		*(reason + 2) = 0;
 		*(reason + 1) = 1;
 		*(reason + 0) = 4;
+		result = YES;
 	}
+
+	return result;
 }
 
 int main(int argc, char *argv[])
@@ -1364,10 +1337,9 @@ int main(int argc, char *argv[])
 						byte normalStop = 0x01;
 						byte stopReason[6] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
 
-						if (strlen((char *)ShmSysConfigAndInfo->SysStopChargingAlarmCode.StopCode[_index]) > 0)
+						if (GetStopChargingReasonByEvse(_index, stopReason))
 						{
 							normalStop = 0x02;
-							GetStopChargingReasonByEvse(_index, stopReason);
 						}
 
 						EvseStopChargingEvent(normalStop, stopReason, _chargingData[_index]->Evboard_id);

+ 16 - 3
EVSE/Projects/DS60-120/Apps/ReadCmdline.c

@@ -362,6 +362,14 @@ void SetFanSpeed(char *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 GetPsuInformation(char *v1)
 {
 	printf("*************************************************\n");
@@ -425,7 +433,7 @@ static int get_char()
 void RunUnconditionalChargeIndex1(char *v1, char *v2, char *v3)
 {
 	int _GunIndex = atoi(v1);
-	int _Voltage = atoi(v2);
+	float _Voltage = atof(v2);
 	int _Current = atoi(v3);
 	unsigned char PreviousSystemStatus = 0xff;
 	int ch = 0;
@@ -436,7 +444,7 @@ void RunUnconditionalChargeIndex1(char *v1, char *v2, char *v3)
 		return;
 	}
 
-    printf ("ReqVoltage = %d, ReqCurrent = %d\n", _Voltage,_Current);
+    printf ("ReqVoltage = %f, ReqCurrent = %d\n", _Voltage,_Current);
 
     if(_Voltage > 1000 || _Voltage < 150){
 
@@ -522,7 +530,7 @@ void RunUnconditionalChargeIndex1(char *v1, char *v2, char *v3)
         	        PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
 
         	        printf ("[UnconditionalCharge - S_PREPARING_FOR_EV]\n");
-        	        printf ("ReqVoltage = %d, ReqCurrent = %d\n", _Voltage,_Current);
+        	        printf ("ReqVoltage = %f, ReqCurrent = %d\n", _Voltage,_Current);
 
         	    }
     		    //清除 main timeout 機制
@@ -818,6 +826,11 @@ int main(void)
 			// 設定風扇速度
 			SetFanSpeed(newString[1]);
 		}
+		else if(strcmp(newString[0], "speed") == 0)
+		{
+			// 取得風扇速度
+			GetFanSpeed();
+		}
 		else if(strcmp(newString[0], "psu") == 0)
 		{
 			//如果連一個參數都沒有 (此命令不理會) 加上判斷第二參數

+ 79 - 119
EVSE/Projects/DS60-120/Apps/main.c

@@ -498,7 +498,7 @@ int CreateShareMemory()
 //=================================
 void ChangeLcmByIndex(byte page_index)
 {
-	if (ShmSysConfigAndInfo->SysStopChargingAlarmCode.Level != 2 ||
+	if (ShmSysConfigAndInfo->SysWarningInfo.Level != 2 ||
 			page_index == _LCM_COMPLETE || page_index == _LCM_FIX)
 	{
 		ShmSysConfigAndInfo->SysInfo.PageIndex = page_index;
@@ -909,8 +909,6 @@ void InitialShareMemoryInfo()
 	char cmd[512];
 	char buf[512];
 
-	sprintf((char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev, "D0.01.04.20.01.00");
-
 	sprintf((char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomApn, "Internet");
 	sprintf((char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapId, " ");
 	sprintf((char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapPwd, " ");
@@ -941,7 +939,7 @@ void InitialShareMemoryInfo()
 		}
 	}
 
-	sprintf((char *) ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev, "D0.01.44.0030");
+	sprintf((char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev, "D0.01.04.20.02.00");
 	sprintf((char *) ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev, " ");
 
 	sprintf((char *) ShmSysConfigAndInfo->SysInfo.LcmHwRev, " ");
@@ -1033,13 +1031,6 @@ bool InitialSystemDefaultConfig()
 	LoadSysConfigAndInfo(&ShmSysConfigAndInfo->SysConfig);
 	InitGPIO();
 	//InitEthernet();
-	if (DEBUG == NO)
-	{
-		wtdFd = InitWatchDog();
-
-		if (wtdFd < 0)
-			result = false;
-	}
 
 	system("echo 1 > /sys/class/gpio/gpio110/value"); //reset PHY
 	sleep(3);
@@ -1097,7 +1088,7 @@ void SelfTestRun()
 	while (ShmSysConfigAndInfo->SysInfo.SelfTestSeq != _STEST_COMPLETE)
 	{
 		ChkPrimaryStatus();
-		if (ShmSysConfigAndInfo->SysStopChargingAlarmCode.Level == 2)
+		if (ShmSysConfigAndInfo->SysWarningInfo.Level == 2)
 		{
 			ShmSysConfigAndInfo->SysInfo.SelfTestSeq = _STEST_FAIL;
 			return;
@@ -1235,15 +1226,15 @@ int SpawnTask()
 	system("/root/Module_LcmControl &");
 	system("/root/Module_InternalComm &");
 	system("/root/Module_PsuComm &");
-	system("/root/OcppBackend &");
+	//system("/root/OcppBackend &");
 
 	if(ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'T')
 	{
-		system("/root/Module_4g &");
+		//system("/root/Module_4g &");
 	}
 	else if(ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'W')
 	{
-		system("/root/Module_Wifi &");
+		//system("/root/Module_Wifi &");
 	}
 
 	// 加入參數
@@ -1449,37 +1440,6 @@ void _AutoReturnTimeout()
 	}
 
 	ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
-//
-//	for (byte i = 0; i < CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY; i++)
-//	{
-//		if (chargingInfo[i]->SystemStatus > S_IDLE)
-//		{
-//			switch(chargingInfo[i]->SystemStatus)
-//			{
-//				case S_PREPARNING:
-//				case S_PREPARING_FOR_EV:
-//				case S_PREPARING_FOR_EVSE:
-//				{
-//					ChangeLcmByIndex(i, _LCM_PRE_CHARGE);
-//				}
-//					break;
-//				case S_CHARGING:
-//				{
-//					ChangeLcmByIndex(i, _LCM_CHARGING);
-//				}
-//					break;
-//				case S_TERMINATING:
-//				{
-//					ChangeLcmByIndex(i, _LCM_COMPLETE);
-//				}
-//					break;
-//			}
-//			return;
-//		}
-//	}
-
-//	if (!IsAuthorizingMode())
-//		ChangeLcmByIndex(255, _LCM_IDLE);
 }
 
 void _SelfTestTimeout()
@@ -1636,7 +1596,7 @@ void ReleaseAlarmCode(byte gunIndex)
 {
 	if (chargingInfo[gunIndex]->Type == _Type_Chademo)
 	{
-		ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoGfdTrip = 0x00;
+		ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoGfdTrip = NO;
 	}
 	else if (chargingInfo[gunIndex]->Type == _Type_CCS_2)
 	{
@@ -1654,31 +1614,39 @@ void ChargingTerminalProcess(byte gunIndex)
 
 void StopChargingProcessByString(byte level, byte gun_index, char *string)
 {
-	if (strlen((char *)ShmSysConfigAndInfo->SysStopChargingAlarmCode.StopCode[gun_index]) == 0 ||
-		level > ShmSysConfigAndInfo->SysStopChargingAlarmCode.Level)
+	if (level > ShmSysConfigAndInfo->SysWarningInfo.Level)
 	{
-		memcpy(&ShmSysConfigAndInfo->SysStopChargingAlarmCode.StopCode[gun_index][0], string, 7);
-		ShmSysConfigAndInfo->SysStopChargingAlarmCode.Level = level;
+		ShmSysConfigAndInfo->SysWarningInfo.Level = level;
 	}
 }
 
-void ReleaseChargingProcessByString(byte gun_index, char *code)
+void ReleaseChargingProcessByString(byte level, char *code)
 {
-	memcpy(&ShmSysConfigAndInfo->SysStopChargingAlarmCode.StopCode[gun_index][0], "", 7);
-	ShmSysConfigAndInfo->SysStopChargingAlarmCode.Level = 0;
+	if (level >= ShmSysConfigAndInfo->SysWarningInfo.Level)
+		ShmSysConfigAndInfo->SysWarningInfo.Level = 0;
 }
 
-// 各小板的停止充電處理函式
-void EmcOccureByString(byte index, char *code)
+// 一般錯誤停止充電處理函式
+void BoardErrOccurByString(byte index, char *code)
 {
-	bool isStopCharger = false;
-	if (strncmp(code, "012251", 6) == 0 || strncmp(code, "012252", 6) == 0 ||
-			strncmp(code, "012237", 6) == 0 || strncmp(code, "012238", 6) == 0)
+	byte level = 1;
+	if ((chargingInfo[index]->SystemStatus > S_IDLE && chargingInfo[index]->SystemStatus < S_TERMINATING) ||
+			(chargingInfo[index]->SystemStatus >= S_CCS_PRECHARGE_ST0 && chargingInfo[index]->SystemStatus <= S_CCS_PRECHARGE_ST1))
 	{
-		isStopCharger = true;
+		ChargingTerminalProcess(index);
 	}
 
-	if (isStopCharger)
+	StopChargingProcessByString(level, index, code);
+}
+
+// 急停狀況的停止充電處理函式
+void EmcOccureByString(char *code)
+{
+	byte level = 2;
+	// 嚴重的急停有四種 : EMC 按鈕、Mainbreak、Dooropen、SPD Trip
+	// 其錯誤等級為 2
+	if (strncmp(code, "012251", 6) == 0 || strncmp(code, "012252", 6) == 0 ||
+			strncmp(code, "012237", 6) == 0 || strncmp(code, "012238", 6) == 0)
 	{
 		for (byte gun = 0; gun < _gunCount; gun++)
 		{
@@ -1688,69 +1656,57 @@ void EmcOccureByString(byte index, char *code)
 				ChargingTerminalProcess(gun);
 			}
 
-			StopChargingProcessByString(2, gun, code);
+			StopChargingProcessByString(level, gun, code);
 		}
 	}
-	else
+}
+
+void ReleaseBoardErrOccurByString(byte index, char *code)
+{
+	bool isTrigger = false;
+	byte level = 1;
+
+	if (strncmp(code, "023730", 6) == 0 && ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoChargerGetEmergencyStop == YES)
 	{
-		if ((chargingInfo[index]->SystemStatus > S_IDLE && chargingInfo[index]->SystemStatus < S_TERMINATING) ||
-				(chargingInfo[index]->SystemStatus >= S_CCS_PRECHARGE_ST0 && chargingInfo[index]->SystemStatus <= S_CCS_PRECHARGE_ST1))
-		{
-			ChargingTerminalProcess(index);
-		}
+		isTrigger = true;
+		ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoChargerGetEmergencyStop = NO;
+	}
 
-		StopChargingProcessByString(2, index, code);
+	if (isTrigger)
+	{
+		ReleaseChargingProcessByString(level, code);
 	}
 }
 
 void ReleaseEmsOccureByString(byte index, char *code)
 {
-	bool isReleaseCharger = false;
 	bool isTrigger = false;
+	byte level = 2;
 
 	if (strncmp(code, "012251", 6) == 0 && ShmStatusCodeData->AlarmCode.AlarmEvents.bits.EmergencyStopTrip == YES)
 	{
 		isTrigger = true;
 		ShmStatusCodeData->AlarmCode.AlarmEvents.bits.EmergencyStopTrip = NO;
-		isReleaseCharger = true;
 	}
 	else if (strncmp(code, "012252", 6) == 0 && ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DoorOpen == YES)
 	{
 		isTrigger = true;
 		ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DoorOpen = NO;
-		isReleaseCharger = true;
 	}
 	else if (strncmp(code, "012237", 6) == 0 && ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SpdTrip == YES)
 	{
 		isTrigger = true;
 		ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SpdTrip = NO;
-		isReleaseCharger = true;
 	}
 	else if (strncmp(code, "012238", 6) == 0 && ShmStatusCodeData->AlarmCode.AlarmEvents.bits.MainPowerBreakerTrip == YES)
 	{
 		isTrigger = true;
 		ShmStatusCodeData->AlarmCode.AlarmEvents.bits.MainPowerBreakerTrip = NO;
-		isReleaseCharger = true;
-	}
-	else if (strncmp(code, "023730", 6) == 0 && ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoChargerGetEmergencyStop == YES)
-	{
-		isTrigger = true;
-		ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoChargerGetEmergencyStop = NO;
 	}
 
 	if (isTrigger)
 	{
-		if (isReleaseCharger)
-		{
-			for (byte gun = 0; gun < _gunCount; gun++)
-			{
-				ReleaseChargingProcessByString(gun, code);
-			}
-		}
-		else
-		{
-			ReleaseChargingProcessByString(index, code);
-		}
+		ReleaseChargingProcessByString(level, code);
 	}
 }
 
@@ -1765,7 +1721,7 @@ void ChkPrimaryStatus()
 	if (ShmPrimaryMcuData->InputDet.bits.EmergencyButton == ABNORMAL)
 	{
 		ShmStatusCodeData->AlarmCode.AlarmEvents.bits.EmergencyStopTrip = YES;
-		EmcOccureByString(0, "012251");
+		EmcOccureByString("012251");
 	}
 	else
 		ReleaseEmsOccureByString(0, "012251");
@@ -1773,7 +1729,7 @@ void ChkPrimaryStatus()
 	if (ShmPrimaryMcuData->InputDet.bits.AcMainBreakerDetec == ABNORMAL)
 	{
 		ShmStatusCodeData->AlarmCode.AlarmEvents.bits.MainPowerBreakerTrip = YES;
-		EmcOccureByString(0, "012238");
+		EmcOccureByString("012238");
 	}
 	else
 		ReleaseEmsOccureByString(0, "012238");
@@ -1781,7 +1737,7 @@ void ChkPrimaryStatus()
 	if (ShmPrimaryMcuData->InputDet.bits.SpdDetec == ABNORMAL)
 	{
 		ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SpdTrip = YES;
-		EmcOccureByString(0, "012237");
+		EmcOccureByString("012237");
 	}
 	else
 		ReleaseEmsOccureByString(0, "012237");
@@ -1789,7 +1745,7 @@ void ChkPrimaryStatus()
 	if (ShmPrimaryMcuData->InputDet.bits.DoorOpen == ABNORMAL)
 	{
 		ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DoorOpen = YES;
-		EmcOccureByString(0, "012252");
+		EmcOccureByString("012252");
 	}
 	else
 		ReleaseEmsOccureByString(0, "012252");
@@ -1894,19 +1850,17 @@ void CheckErrorOccurStatus(byte index)
 	// 小板
 	if (chargingInfo[index]->Type == _Type_Chademo)
 	{
-		if (ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoChargerGetEmergencyStop == YES)
-			EmcOccureByString(index, "023730");
-		else if (ShmStatusCodeData->FaultCode.FaultEvents.bits.ChademoOutputRelayDrivingFault == YES)
-			EmcOccureByString(index, "011012");
+		if (ShmStatusCodeData->FaultCode.FaultEvents.bits.ChademoOutputRelayDrivingFault == YES)
+			BoardErrOccurByString(index, "011012");
 		else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoGfdTrip == YES)
-			EmcOccureByString(index, "012234");
+			BoardErrOccurByString(index, "012234");
 	}
 	else if (chargingInfo[index]->Type == _Type_CCS_2)
 	{
 		if (ShmStatusCodeData->FaultCode.FaultEvents.bits.CcsOutputRelayDrivingFault == YES)
-			EmcOccureByString(index, "011014");
+			BoardErrOccurByString(index, "011014");
 		else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsGfdTrip == YES)
-			EmcOccureByString(index, "012235");
+			BoardErrOccurByString(index, "012235");
 	}
 }
 
@@ -2007,14 +1961,12 @@ void CheckGpioInStatus()
 						if (chargingInfo[i]->slotsIndex == 1)
 						{
 							if (chargingInfo[i]->Type == _Type_Chademo)
-								EmcOccureByString(i, "023730");
+								BoardErrOccurByString(i, "023730");
 							else if (chargingInfo[i]->Type == _Type_CCS_2)
-								EmcOccureByString(i, "013627");
+								BoardErrOccurByString(i, "013627");
 							break;
 						}
 					}
-
-					//gpio_set_value(pinOut[0], gpioValue);
 				}
 					break;
 				case 27:
@@ -2024,14 +1976,12 @@ void CheckGpioInStatus()
 						if (chargingInfo[i]->slotsIndex == 3)
 						{
 							if (chargingInfo[i]->Type == _Type_Chademo)
-								EmcOccureByString(i, "023730");
+								BoardErrOccurByString(i, "023730");
 							else if (chargingInfo[i]->Type == _Type_CCS_2)
-								EmcOccureByString(i, "013627");
+								BoardErrOccurByString(i, "013627");
 							break;
 						}
 					}
-
-					//gpio_set_value(pinOut[1], gpioValue);
 				}
 					break;
 			}
@@ -2054,8 +2004,6 @@ void CheckGpioInStatus()
 							break;
 						}
 					}
-
-					//gpio_set_value(pinOut[0], gpioValue);
 				}
 					break;
 				case 27:
@@ -2071,8 +2019,6 @@ void CheckGpioInStatus()
 							break;
 						}
 					}
-
-					//gpio_set_value(pinOut[1], gpioValue);
 				}
 				break;
 			}
@@ -2194,7 +2140,7 @@ unsigned char isModeChange(unsigned char gun_index)
 
 void ScannerCardProcess()
 {
-	if (!isDetectPlugin() && !isCardScan && ShmSysConfigAndInfo->SysStopChargingAlarmCode.Level == 0 &&
+	if (!isDetectPlugin() && !isCardScan && ShmSysConfigAndInfo->SysWarningInfo.Level == 0 &&
 			ShmSysConfigAndInfo->SysConfig.AuthorisationMode == _SYS_AUTHORIZE_OCPP)
 	{
 		isCardScan = true;
@@ -2687,7 +2633,7 @@ void CreateTimeoutFork()
 					}
 					break;
 				case Timeout_Authorizing:
-					if (GetTimeoutValue(ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer) >= 50000000)
+					if (GetTimeoutValue(ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer) >= 30000000)
 					{
 						_AuthorizedTimeout();
 						StopSystemTimeoutDet();
@@ -2730,7 +2676,7 @@ void CreateTimeoutFork()
 				switch(chargingInfo[gun_index]->TimeoutFlag)
 				{
 					case Timeout_Preparing:
-						if (GetTimeoutValue(chargingInfo[gun_index]->TimeoutTimer) >= 40000000)
+						if (GetTimeoutValue(chargingInfo[gun_index]->TimeoutTimer) >= 30000000)
 						{
 							_PrepareTimeout(gun_index);
 							StopGunInfoTimeoutDet(gun_index);
@@ -2744,7 +2690,7 @@ void CreateTimeoutFork()
 						}
 						break;
 					case Timeout_EvseChargingDet:
-						if (GetTimeoutValue(chargingInfo[gun_index]->TimeoutTimer) >= 60000000)
+						if (GetTimeoutValue(chargingInfo[gun_index]->TimeoutTimer) >= 30000000)
 						{
 							_DetectEvseChargingEnableTimeout(gun_index);
 							StopGunInfoTimeoutDet(gun_index);
@@ -3181,6 +3127,17 @@ void StopProcessing()
 		sleep(5);
 }
 
+void CreateWatchdog()
+{
+	if (DEBUG == NO)
+	{
+		wtdFd = InitWatchDog();
+
+		if (wtdFd < 0)
+			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed = 1;
+	}
+}
+
 int main(void)
 {
 	if(CreateShareMemory() == 0)
@@ -3190,7 +3147,7 @@ int main(void)
 		#endif
 		if(ShmStatusCodeData!=NULL)
 		{
-			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
+			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory = 1;
 		}
 		return 0;
 		sleep(5);
@@ -3259,6 +3216,9 @@ int main(void)
 	// 1. Thernal - 控制風扇轉速
 	// 2. ouput fuse - 控制風扇轉速
 	CreateRfidFork();
+	// Create Watchdog
+	CreateWatchdog();
+
 	// Main loop
 	PRINTF_FUNC("Main Loop. \n");
 	for (;;)
@@ -3303,7 +3263,7 @@ int main(void)
 						ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = YES;
 					}
 
-					if (ShmSysConfigAndInfo->SysStopChargingAlarmCode.Level == 2)
+					if (ShmSysConfigAndInfo->SysWarningInfo.Level == 2)
 					{
 						if (gun_index == ShmSysConfigAndInfo->SysInfo.CurGunSelected)
 						{