Pārlūkot izejas kodu

2020-01-16 / Folus Wen

Actions:
1. Synchronize source code from Eason Eclipse project.
2. Module_Speaker.c add sleep into for loop to solve CPU utilization issue.
3. Module_AlarmDetect.c add alarm code to ShmOCPP16Data.
4. Module_InternalComm.c reduce debug output info.
5. Module_Internal Comm.c add CMD_CONFIG_MCU_RESET_REQUEST command.
6. main.c implement remote reset, authorize, reservation, upgrade firmware logic.

Files:
1. As follow commit history.
FolusWen 5 gadi atpakaļ
vecāks
revīzija
1550e102ce

BIN
EVSE/Modularization/Module_4g


BIN
EVSE/Modularization/Module_Wifi


BIN
EVSE/Modularization/OcppBackend


BIN
EVSE/Modularization/WebService


BIN
EVSE/Modularization/libInfypwr_PsuCommObj.a


BIN
EVSE/Modularization/libModule_RFID.a


BIN
EVSE/Modularization/libModule_Upgrade.a


BIN
EVSE/Modularization/libPhihong_PsuCommObj.a


BIN
EVSE/Modularization/logPackTools


+ 1081 - 970
EVSE/Projects/AW-Regular/Apps/Module_AlarmDetect.c

@@ -1,970 +1,1081 @@
-/*
- * Module_AlarmDetect.c
- *
- *  Created on: 2019年8月17日
- *      Author: foluswen
- */
-#include    <sys/types.h>
-#include    <sys/stat.h>
-#include 	<sys/time.h>
-#include 	<sys/timeb.h>
-#include 	<sys/ipc.h>
-#include 	<sys/shm.h>
-#include 	<sys/mman.h>
-
-#include 	<unistd.h>
-#include 	<stdarg.h>
-#include    <stdio.h>      /*標準輸入輸出定義*/
-#include    <stdlib.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	"define.h"
-#include	"main.h"
-
-#define FILTER_SPEC			50
-
-#define DEBUG_INFO(format, args...) StoreLogMsg("[%s:%d][%s][Info] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
-#define DEBUG_WARN(format, args...) StoreLogMsg("[%s:%d][%s][Warn] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
-#define DEBUG_ERROR(format, args...) StoreLogMsg("[%s:%d][%s][Error] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
-
-#define Debug
-#define ARRAY_SIZE(A)		(sizeof(A) / sizeof(A[0]))
-#define PASS				1
-#define FAIL				0
-#define ON					1
-#define OFF					0
-
-#define SPEC_OV				275
-#define SPEC_UV				160
-#define SPEC_OC				(32*1.1)
-#define SPEC_OT				85
-
-#define HYSTERETIC_OUV		10
-#define HYSTERETIC_OT		10
-#define HYSTERETIC_OC		10
-
-struct{
-	unsigned short int	OV[3];
-	unsigned short int	UV[3];
-	unsigned short int	OC;
-	unsigned short int	OT_AMB;
-	unsigned short int	GMI;
-	unsigned short int	Short;
-	unsigned short int	Ac_Leak;
-	unsigned short int	Dc_Leak;
-	unsigned short int	HandShakingTimeout;
-	unsigned short int	EmrgencyBTN;
-	unsigned short int	Relay_Welding;
-	unsigned short int	Relay_DrivingFault;
-	unsigned short int	CP_LevelFail;
-	unsigned short int	MCU_SelfTestFail;
-}Alarm_Counter[2];
-
-void trim(char *s);
-void substr(char *dest, const char* src, unsigned int start, unsigned int cnt);
-
-struct SysConfigAndInfo			*ShmSysConfigAndInfo;
-struct StatusCodeData 			*ShmStatusCodeData;
-struct Charger					*ShmCharger;
-
-int StoreLogMsg(const char *fmt, ...)
-{
-	char Buf[4096+256];
-	char buffer[4096];
-	time_t CurrentTime;
-	struct tm *tm;
-	va_list args;
-
-	va_start(args, fmt);
-	int rc = vsnprintf(buffer, sizeof(buffer), fmt, args);
-	va_end(args);
-
-	memset(Buf,0,sizeof(Buf));
-	CurrentTime = time(NULL);
-	tm=localtime(&CurrentTime);
-	sprintf(Buf,"echo \"[%04d.%02d.%02d %02d:%02d:%02d] - %s\" >> /Storage/SystemLog/%04d-%02d_%s_%s_SystemLog",
-			tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,
-			buffer,
-			tm->tm_year+1900,tm->tm_mon+1,
-			ShmSysConfigAndInfo->SysConfig.ModelName,
-			ShmSysConfigAndInfo->SysConfig.SerialNumber);
-#ifdef SystemLogMessage
-	system(Buf);
-#endif
-
-	printf("[%04d.%02d.%02d %02d:%02d:%02d] - %s", tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec, buffer);
-
-	return rc;
-}
-
-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;
-}
-
-//==========================================
-// Init all share memory
-//==========================================
-int InitShareMemory()
-{
-	int result = PASS;
-	int MeterSMId;
-
-	//creat ShmSysConfigAndInfo
-	if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo),  0777)) < 0)
-    {
-		#ifdef SystemLogMessage
-		DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
-		#endif
-		result = FAIL;
-	}
-    else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
-    {
-    	#ifdef SystemLogMessage
-    	DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
-		#endif
-    	result = FAIL;
-   	 }
-    else
-    {}
-
-   	//creat ShmStatusCodeData
-   	if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData),  0777)) < 0)
-    {
-		#ifdef SystemLogMessage
-   		DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
-		#endif
-   		result = FAIL;
-	}
-    else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
-    {
-    	#ifdef SystemLogMessage
-    	DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
-		#endif
-    	result = FAIL;
-   	}
-    else
-    {}
-
-   	//creat ShmStatusCodeData
-   	if ((MeterSMId = shmget(ShmChargerKey, sizeof(struct Charger), IPC_CREAT | 0777)) < 0)
-	{
-
-		DEBUG_ERROR("shmget ShmCharger NG\r\n");
-
-		result = FAIL;
-	}
-	else if ((ShmCharger = shmat(MeterSMId, NULL, 0)) == (void *) -1)
-	{
-
-		DEBUG_ERROR("shmat ShmCharger NG\r\n");
-
-		result = FAIL;
-	}
-	else
-	{}
-
-    return result;
-}
-
-//==========================================
-// Common routine
-//==========================================
-void trim(char *s)
-{
-    int i=0, j, k, l=0;
-
-    while((s[i]==' ')||(s[i]=='\t')||(s[i]=='\n'))
-        i++;
-
-    j = strlen(s)-1;
-    while((s[j]==' ')||(s[j]=='\t')||(s[j]=='\n'))
-        j--;
-
-    if(i==0 && j==strlen(s)-1) { }
-    else if(i==0) s[j+1] = '\0';
-    else {
-        for(k=i; k<=j; k++) s[l++] = s[k];
-        s[l] = '\0';
-    }
-}
-
-void substr(char *dest, const char* src, unsigned int start, unsigned int cnt)
-{
-	strncpy(dest, src + start, cnt);
-	dest[cnt] = 0;
-}
-
-//==========================================
-// Main process
-//==========================================
-int main(void)
-{
-
-	if(InitShareMemory() == FAIL)
-	{
-		DEBUG_ERROR("InitShareMemory NG\n");
-
-		if(ShmStatusCodeData!=NULL)
-		{
-			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
-		}
-		sleep(5);
-		return FAIL;
-	}
-
-	for(;;)
-	{
-		for(int gun_index = 0;gun_index<AC_QUANTITY;gun_index++)
-		{
-			//=====================================
-			// Over voltage detection
-			//=====================================
-			if((ShmSysConfigAndInfo->SysInfo.InputVoltageR > SPEC_OV) &&
-				(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_OVER_VOLTAGE))
-			{
-				if(Alarm_Counter[gun_index].OV[0] > FILTER_SPEC)
-				{
-					if((ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputOVP == OFF))
-					{
-						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputOVP = ON;
-						ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_OVER_VOLTAGE;
-						DEBUG_INFO("ALARM_OVER_VOLTAGE : alarm \r\n");
-					}
-				}
-				else
-				{
-					Alarm_Counter[gun_index].OV[0]++;
-				}
-			}
-			else if((ShmSysConfigAndInfo->SysInfo.InputVoltageR < (SPEC_OV-HYSTERETIC_OUV)) &&
-					(!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_OVER_VOLTAGE)))
-			{
-				Alarm_Counter[gun_index].OV[0] = 0;
-				if((ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputOVP == ON))
-				{
-					ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputOVP = OFF;
-					ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_OVER_VOLTAGE;
-					DEBUG_INFO("ALARM_OVER_VOLTAGE : recover \r\n");
-				}
-			}
-
-			if(ShmSysConfigAndInfo->SysConfig.AcPhaseCount == 3)
-			{
-				if((ShmSysConfigAndInfo->SysInfo.InputVoltageS > SPEC_OV) &&
-				   (ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_OVER_VOLTAGE))
-				{
-					if(Alarm_Counter[gun_index].OV[1] > FILTER_SPEC)
-					{
-						if((ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputOVP == OFF))
-						{
-							ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputOVP = ON;
-							ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_OVER_VOLTAGE;
-							DEBUG_INFO("ALARM_OVER_VOLTAGE : alarm \r\n");
-						}
-					}
-					else
-					{
-						Alarm_Counter[gun_index].OV[1]++;
-					}
-				}
-				else if((ShmSysConfigAndInfo->SysInfo.InputVoltageS < (SPEC_OV-HYSTERETIC_OUV)) &&
-						(!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_OVER_VOLTAGE)))
-				{
-					Alarm_Counter[gun_index].OV[1] = 0;
-					if((ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputOVP == ON))
-					{
-						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputOVP = OFF;
-						ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_OVER_VOLTAGE;
-						DEBUG_INFO("ALARM_OVER_VOLTAGE : recover \r\n");
-					}
-				}
-
-				if((ShmSysConfigAndInfo->SysInfo.InputVoltageT > SPEC_OV) &&
-				   (ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_OVER_VOLTAGE))
-				{
-					if(Alarm_Counter[gun_index].OV[2] > FILTER_SPEC)
-					{
-						if((ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputOVP == OFF))
-						{
-							ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputOVP = ON;
-							ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_OVER_VOLTAGE;
-							DEBUG_INFO("ALARM_OVER_VOLTAGE : alarm \r\n");
-						}
-					}
-					else
-					{
-						Alarm_Counter[gun_index].OV[2]++;
-					}
-				}
-				else if((ShmSysConfigAndInfo->SysInfo.InputVoltageT < (SPEC_OV-HYSTERETIC_OUV)) &&
-						(!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_OVER_VOLTAGE)))
-				{
-					Alarm_Counter[gun_index].OV[2] = 0;
-					if((ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputOVP == ON))
-					{
-						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputOVP = OFF;
-						ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_OVER_VOLTAGE;
-						DEBUG_INFO("ALARM_OVER_VOLTAGE : recover \r\n");
-					}
-				}
-			}
-
-			//=====================================
-			// Under voltage detection
-			//=====================================
-			if((ShmSysConfigAndInfo->SysInfo.InputVoltageR  < SPEC_UV) &&
-				(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_UNDER_VOLTAGE))
-			{
-				if(Alarm_Counter[gun_index].UV[0] > FILTER_SPEC)
-				{
-					if((ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputUVP == OFF))
-					{
-						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputUVP = ON;
-						ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_UNDER_VOLTAGE;
-						DEBUG_INFO("ALARM_UNDER_VOLTAGE : alarm \r\n");
-					}
-				}
-				else
-				{
-					Alarm_Counter[gun_index].UV[0]++;
-				}
-			}
-			else if((ShmSysConfigAndInfo->SysInfo.InputVoltageR  > (SPEC_UV+HYSTERETIC_OUV)) &&
-					(!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_UNDER_VOLTAGE)))
-			{
-				Alarm_Counter[gun_index].UV[0] = 0;
-				if((ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputUVP == ON))
-				{
-					ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputUVP = OFF;
-					ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_UNDER_VOLTAGE;
-					DEBUG_INFO("ALARM_UNDER_VOLTAGE : recover \r\n");
-				}
-			}
-
-			if(ShmSysConfigAndInfo->SysConfig.AcPhaseCount == 3)
-			{
-				if((ShmSysConfigAndInfo->SysInfo.InputVoltageS < SPEC_UV) &&
-				   (ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_UNDER_VOLTAGE))
-				{
-					if(Alarm_Counter[gun_index].UV[1] > FILTER_SPEC)
-					{
-						if((ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputUVP == OFF))
-						{
-							ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputUVP = ON;
-							ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_UNDER_VOLTAGE;
-							DEBUG_INFO("ALARM_UNDER_VOLTAGE : alarm \r\n");
-						}
-					}
-					else
-					{
-						Alarm_Counter[gun_index].UV[1]++;
-					}
-				}
-				else if((ShmSysConfigAndInfo->SysInfo.InputVoltageS > (SPEC_UV+HYSTERETIC_OUV)) &&
-						(!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_UNDER_VOLTAGE)))
-				{
-					Alarm_Counter[gun_index].UV[1] = 0;
-					if((ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputUVP == ON))
-					{
-						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputUVP = OFF;
-						ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_UNDER_VOLTAGE;
-						DEBUG_INFO("ALARM_UNDER_VOLTAGE : recover \r\n");
-					}
-				}
-
-				if((ShmSysConfigAndInfo->SysInfo.InputVoltageT < SPEC_UV) &&
-				   (ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_UNDER_VOLTAGE))
-				{
-					if(Alarm_Counter[gun_index].UV[2] > FILTER_SPEC)
-					{
-						if((ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputUVP == OFF))
-						{
-							ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputUVP = ON;
-							ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_UNDER_VOLTAGE;
-							DEBUG_INFO("ALARM_UNDER_VOLTAGE : alarm \r\n");
-						}
-					}
-					else
-					{
-						Alarm_Counter[gun_index].UV[2]++;
-					}
-				}
-				else if((ShmSysConfigAndInfo->SysInfo.InputVoltageT > (SPEC_OV+HYSTERETIC_OUV)) &&
-						(!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_UNDER_VOLTAGE)))
-				{
-					Alarm_Counter[gun_index].UV[2] = 0;
-					if((ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputUVP == ON))
-					{
-						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputUVP = OFF;
-						ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_UNDER_VOLTAGE;
-						DEBUG_INFO("ALARM_UNDER_VOLTAGE : recover \r\n");
-					}
-				}
-			}
-
-			//=====================================
-			// Over current detection
-			//=====================================
-			if((ShmCharger->gun_info[gun_index].outputCurrent.L1N_L12[0] > SPEC_OC) &&
-			   (ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_OVER_CURRENT))
-			{
-				if((ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAcOutputOCP == OFF))
-				{
-					ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAcOutputOCP = ON;
-					ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_OVER_CURRENT;
-					DEBUG_INFO("ALARM_OVER_CURRENT : alarm \r\n");
-				}
-			}
-			else if ((ShmCharger->gun_info[gun_index].outputCurrent.L1N_L12[0] < (SPEC_OC-HYSTERETIC_OC)) &&
-					 (!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_OVER_CURRENT)))
-			{
-				if((ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAcOutputOCP == ON))
-				{
-					ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAcOutputOCP = OFF;
-					ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_OVER_CURRENT;
-					DEBUG_INFO("ALARM_OVER_CURRENT : recover \r\n");
-				}
-			}
-
-			if(ShmSysConfigAndInfo->SysConfig.AcPhaseCount == 3)
-			{
-				if((ShmCharger->gun_info[gun_index].outputCurrent.L2N_L23[0] > SPEC_OC) &&
-				   (ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_OVER_CURRENT))
-				{
-					if((ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAcOutputOCP == OFF))
-					{
-						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAcOutputOCP = ON;
-						ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_OVER_CURRENT;
-						DEBUG_INFO("ALARM_OVER_CURRENT : alarm \r\n");
-					}
-				}
-				else if ((ShmCharger->gun_info[gun_index].outputCurrent.L2N_L23[0] < (SPEC_OC-HYSTERETIC_OC)) &&
-						 (!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_OVER_CURRENT)))
-				{
-					if((ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAcOutputOCP == ON))
-					{
-						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAcOutputOCP = OFF;
-						ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_OVER_CURRENT;
-						DEBUG_INFO("ALARM_OVER_CURRENT : recover \r\n");
-					}
-				}
-
-				if((ShmCharger->gun_info[gun_index].outputCurrent.L3N_L31[0] > SPEC_OC) &&
-				   (ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_OVER_CURRENT))
-				{
-					if((ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAcOutputOCP == OFF))
-					{
-						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAcOutputOCP = ON;
-						ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_OVER_CURRENT;
-						DEBUG_INFO("ALARM_OVER_CURRENT : alarm \r\n");
-					}
-				}
-				else if ((ShmCharger->gun_info[gun_index].outputCurrent.L3N_L31[0] < (SPEC_OC-HYSTERETIC_OC)) &&
-						 (!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_OVER_CURRENT)))
-				{
-					if((ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAcOutputOCP == ON))
-					{
-						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAcOutputOCP = OFF;
-						ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_OVER_CURRENT;
-						DEBUG_INFO("ALARM_OVER_CURRENT : recover \r\n");
-					}
-				}
-			}
-
-			//=====================================
-			// Over temperature detection
-			//=====================================
-			if(//(ShmSysConfigAndInfo->SysInfo.SystemAmbientTemp > SPEC_OT) &&
-			   (ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_OVER_TEMPERATURE))
-			{
-				if(Alarm_Counter[gun_index].OT_AMB > FILTER_SPEC)
-				{
-					if((ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAmbientOTP == OFF))
-					{
-						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAmbientOTP = ON;
-						ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_OVER_TEMPERATURE;
-						DEBUG_INFO("ALARM_OVER_TEMPERATURE : alarm \r\n");
-					}
-				}
-				else
-				{
-					Alarm_Counter[gun_index].OT_AMB++;
-				}
-			}
-			else if(//(ShmSysConfigAndInfo->SysInfo.SystemAmbientTemp < (SPEC_OT-10)) &&
-					(!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_OVER_TEMPERATURE)))
-			{
-				Alarm_Counter[gun_index].OT_AMB = 0;
-				if((ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAmbientOTP == ON))
-				{
-					ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAmbientOTP = OFF;
-					ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_OVER_TEMPERATURE;
-					DEBUG_INFO("ALARM_OVER_TEMPERATURE : recover \r\n");
-				}
-			}
-
-			//=====================================
-			// Ground fault detection
-			//=====================================
-			if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_GROUND_FAIL)
-			{
-				if(Alarm_Counter[gun_index].GMI > FILTER_SPEC)
-				{
-					if((ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbGfdTrip == OFF))
-					{
-						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbGfdTrip = ON;
-						ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_GROUND_FAIL;
-						DEBUG_INFO("ALARM_GROUND_FAIL : alarm \r\n");
-					}
-				}
-				else
-				{
-					Alarm_Counter[gun_index].GMI++;
-				}
-			}
-			else if (!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_GROUND_FAIL))
-			{
-				Alarm_Counter[gun_index].GMI = 0;
-				if((ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbGfdTrip == ON ))
-				{
-					ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbGfdTrip = OFF;
-					ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_GROUND_FAIL;
-					DEBUG_INFO("ALARM_GROUND_FAIL : recover \r\n");
-				}
-			}
-
-			//=====================================
-			// CP level fail detection
-			//====================================
-			if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_CP_ERROR)
-			{
-				if(Alarm_Counter[gun_index].CP_LevelFail > FILTER_SPEC)
-				{
-					if(ShmStatusCodeData->InfoCode.InfoEvents.bits.PilotFault == OFF)
-					{
-						ShmStatusCodeData->InfoCode.InfoEvents.bits.PilotFault = ON;
-						ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_CP_ERROR;
-						DEBUG_INFO("ALARM_CP_ERROR : alarm \r\n");
-					}
-				}
-				else
-				{
-					Alarm_Counter[gun_index].CP_LevelFail++;
-				}
-			}
-			else if(!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_CP_ERROR))
-			{
-				Alarm_Counter[gun_index].CP_LevelFail= 0;
-				if(ShmStatusCodeData->InfoCode.InfoEvents.bits.PilotFault == ON)
-				{
-					ShmStatusCodeData->InfoCode.InfoEvents.bits.PilotFault = OFF;
-					ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_CP_ERROR;
-					DEBUG_INFO("ALARM_CP_ERROR : recover \r\n");
-				}
-			}
-
-			//=====================================
-			// Current AC leak detection
-			//=====================================
-			if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_CURRENT_LEAK_AC)
-			{
-				if(Alarm_Counter[gun_index].Ac_Leak > FILTER_SPEC)
-				{
-					if((ShmStatusCodeData->AlarmCode.AlarmEvents.bits.RcdTrip == OFF))
-					{
-						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.RcdTrip = ON;
-						ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_CURRENT_LEAK_AC;
-						DEBUG_INFO("ALARM_CURRENT_LEAK_AC : alarm \r\n");
-					}
-				}
-				else
-				{
-					Alarm_Counter[gun_index].Ac_Leak++;
-				}
-			}
-			else if(!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_CURRENT_LEAK_AC))
-			{
-				Alarm_Counter[gun_index].Ac_Leak = 0;
-				if((ShmStatusCodeData->AlarmCode.AlarmEvents.bits.RcdTrip == ON))
-				{
-					ShmStatusCodeData->AlarmCode.AlarmEvents.bits.RcdTrip = OFF;
-					ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_CURRENT_LEAK_AC;
-					DEBUG_INFO("ALARM_CURRENT_LEAK_AC : recover \r\n");
-				}
-			}
-
-			//=====================================
-			// Current DC leak detection
-			//=====================================
-			/*
-			if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_CURRENT_LEAK_DC)
-			{
-				if(Alarm_Counter[gun_index].Dc_Leak > FILTER_SPEC)
-				{
-					if((ShmStatusCodeData->AlarmCode.AlarmEvents.bits.RcdTrip == OFF))
-					{
-						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.RcdTrip = ON;
-						ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_CURRENT_LEAK_DC;
-						DEBUG_INFO("ALARM_CURRENT_LEAK_DC : alarm \r\n");
-					}
-				}
-				else
-				{
-					Alarm_Counter[gun_index].Dc_Leak++;
-				}
-			}
-			else if(!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_CURRENT_LEAK_DC))
-			{
-				Alarm_Counter[gun_index].Dc_Leak = 0;
-				if((ShmStatusCodeData->AlarmCode.AlarmEvents.bits.RcdTrip == ON))
-				{
-					ShmStatusCodeData->AlarmCode.AlarmEvents.bits.RcdTrip = OFF;
-					ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_CURRENT_LEAK_DC;
-					DEBUG_INFO("ALARM_CURRENT_LEAK_DC : recover \r\n");
-				}
-			}
-			*/
-
-			//=====================================
-			// MCU self test fail detection
-			//=====================================
-			if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_MCU_TESTFAIL)
-			{
-				if(Alarm_Counter[gun_index].MCU_SelfTestFail > FILTER_SPEC)
-				{
-					if(ShmCharger->gun_info[gun_index].otherAlarmCode.isMcuSelfTest == OFF)
-					{
-						ShmCharger->gun_info[gun_index].otherAlarmCode.isMcuSelfTest = ON;
-						ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_MCU_TESTFAIL;
-						DEBUG_INFO("ALARM_MCU_TESTFAIL : alarm \r\n");
-					}
-				}
-				else
-				{
-					Alarm_Counter[gun_index].MCU_SelfTestFail++;
-				}
-			}
-			else if(!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_MCU_TESTFAIL))
-			{
-				Alarm_Counter[gun_index].MCU_SelfTestFail = 0;
-				if(ShmCharger->gun_info[gun_index].otherAlarmCode.isMcuSelfTest == ON)
-				{
-					ShmCharger->gun_info[gun_index].otherAlarmCode.isMcuSelfTest = OFF;
-					ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_MCU_TESTFAIL;
-					DEBUG_INFO("ALARM_MCU_TESTFAIL : recover \r\n");
-				}
-			}
-
-			//=====================================
-			// Hand shaking timeout detection
-			//=====================================
-			if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_HANDSHAKE_TIMEOUT)
-			{
-				if(ShmCharger->gun_info[gun_index].otherAlarmCode.isHandshakingTimeOut == OFF)
-				{
-					ShmCharger->gun_info[gun_index].otherAlarmCode.isHandshakingTimeOut  = ON;
-					ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_HANDSHAKE_TIMEOUT;
-					DEBUG_INFO("ALARM_HANDSHAKE_TIMEOUT : alarm \r\n");
-				}
-
-			}
-			else if(!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_HANDSHAKE_TIMEOUT))
-			{
-				if(ShmCharger->gun_info[gun_index].otherAlarmCode.isHandshakingTimeOut  == ON)
-				{
-					ShmCharger->gun_info[gun_index].otherAlarmCode.isHandshakingTimeOut  = OFF;
-					ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_HANDSHAKE_TIMEOUT;
-					DEBUG_INFO("ALARM_HANDSHAKE_TIMEOUT : recover \r\n");
-				}
-			}
-
-			//=====================================
-			// Emergency stop detection
-			//=====================================
-			if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_EMERGENCY_STOP)
-			{
-				if(Alarm_Counter[gun_index].EmrgencyBTN > FILTER_SPEC)
-				{
-					if((ShmStatusCodeData->AlarmCode.AlarmEvents.bits.EmergencyStopTrip == OFF))
-					{
-						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.EmergencyStopTrip = ON;
-						ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_EMERGENCY_STOP;
-						DEBUG_INFO("ALARM_EMERGENCY_STOP : alarm \r\n");
-					}
-				}
-				else
-				{
-					Alarm_Counter[gun_index].EmrgencyBTN++;
-				}
-			}
-			else if(!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_EMERGENCY_STOP))
-			{
-				Alarm_Counter[gun_index].EmrgencyBTN = 0;
-				if((ShmStatusCodeData->AlarmCode.AlarmEvents.bits.EmergencyStopTrip == ON))
-				{
-					ShmStatusCodeData->AlarmCode.AlarmEvents.bits.EmergencyStopTrip = OFF;
-					ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_EMERGENCY_STOP;
-					DEBUG_INFO("ALARM_EMERGENCY_STOP : recover \r\n");
-				}
-			}
-
-			//=====================================
-			// Relay welding detection
-			//=====================================
-			if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_RELAY_STATUS)
-			{
-				if(Alarm_Counter[gun_index].Relay_Welding > FILTER_SPEC)
-				{
-					if((ShmStatusCodeData->FaultCode.FaultEvents.bits.AcOutputRelayWelding == OFF))
-					{
-						ShmStatusCodeData->FaultCode.FaultEvents.bits.AcOutputRelayWelding = ON;
-						ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_RELAY_STATUS;
-						DEBUG_INFO("ALARM_RELAY_STATUS : alarm \r\n");
-					}
-				}
-				else
-				{
-					Alarm_Counter[gun_index].Relay_Welding++;
-				}
-			}
-			else if(!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_RELAY_STATUS))
-			{
-				Alarm_Counter[gun_index].Relay_Welding = 0;
-				if((ShmStatusCodeData->FaultCode.FaultEvents.bits.AcOutputRelayWelding == ON))
-				{
-					ShmStatusCodeData->FaultCode.FaultEvents.bits.AcOutputRelayWelding = OFF;
-					ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_RELAY_STATUS;
-					DEBUG_INFO("ALARM_RELAY_STATUS : recover \r\n");
-				}
-			}
-
-			//=====================================
-			// Relay driving fault detection
-			//=====================================
-			if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_RELAY_DRIVE_FAULT)
-			{
-				if(Alarm_Counter[gun_index].Relay_DrivingFault > FILTER_SPEC)
-				{
-					if((ShmStatusCodeData->FaultCode.FaultEvents.bits.AcOutputRelayDrivingFault == OFF))
-					{
-						ShmStatusCodeData->FaultCode.FaultEvents.bits.AcOutputRelayDrivingFault = ON;
-						ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_RELAY_DRIVE_FAULT;
-						DEBUG_INFO("ALARM_RELAY_DRIVE_FAULT : alarm \r\n");
-					}
-				}
-				else
-				{
-					Alarm_Counter[gun_index].Relay_DrivingFault++;
-				}
-			}
-			else if(!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_RELAY_DRIVE_FAULT))
-			{
-				Alarm_Counter[gun_index].Relay_DrivingFault = 0;
-				if((ShmStatusCodeData->FaultCode.FaultEvents.bits.AcOutputRelayDrivingFault == ON))
-				{
-					ShmStatusCodeData->FaultCode.FaultEvents.bits.AcOutputRelayDrivingFault = OFF;
-					ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_RELAY_DRIVE_FAULT;
-					DEBUG_INFO("ALARM_RELAY_DRIVE_FAULT : recover \r\n");
-				}
-			}
-
-			//=====================================
-			// Current short detection
-			//=====================================
-			if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_CIRCUIT_SHORT)
-			{
-				if(Alarm_Counter[gun_index].Short > FILTER_SPEC)
-				{
-					if(ShmCharger->gun_info[gun_index].otherAlarmCode.isCurrentShort == OFF)
-					{
-						ShmCharger->gun_info[gun_index].otherAlarmCode.isCurrentShort = ON;
-						ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_CIRCUIT_SHORT;
-						DEBUG_INFO("ALARM_CIRCUIT_SHORT : alarm \r\n");
-					}
-				}
-				else
-				{
-					Alarm_Counter[gun_index].Short++;
-				}
-			}
-			else if(!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_CIRCUIT_SHORT))
-			{
-				Alarm_Counter[gun_index].Short = 0;
-
-				if(ShmCharger->gun_info[gun_index].otherAlarmCode.isCurrentShort == ON)
-				{
-					ShmCharger->gun_info[gun_index].otherAlarmCode.isCurrentShort = OFF;
-					ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_CIRCUIT_SHORT;
-					DEBUG_INFO("ALARM_CIRCUIT_SHORT : recover \r\n");
-				}
-			}
-
-			//=====================================
-			// Rotatory switch detection
-			//=====================================
-			if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_ROTATORY_SWITCH_FAULT)
-			{
-				if(ShmCharger->gun_info[gun_index].otherAlarmCode.isShutter == OFF)
-				{
-					ShmCharger->gun_info[gun_index].otherAlarmCode.isShutter = ON;
-					ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_ROTATORY_SWITCH_FAULT;
-					DEBUG_INFO("ALARM_ROTATORY_SWITCH_FAULT : alarm \r\n");
-				}
-			}
-			else if(!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_ROTATORY_SWITCH_FAULT))
-			{
-				if(ShmCharger->gun_info[gun_index].otherAlarmCode.isShutter == ON)
-				{
-					ShmCharger->gun_info[gun_index].otherAlarmCode.isShutter = OFF;
-					ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_ROTATORY_SWITCH_FAULT;
-					DEBUG_INFO("ALARM_ROTATORY_SWITCH_FAULT : recover \r\n");
-				}
-			}
-
-			//=====================================
-			// Leakage module detection
-			//=====================================
-			if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_LEAK_MODULE_FAIL)
-			{
-				if(ShmCharger->gun_info[gun_index].otherAlarmCode.isLeakageModule == OFF)
-				{
-					ShmCharger->gun_info[gun_index].otherAlarmCode.isLeakageModule = ON;
-					ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_LEAK_MODULE_FAIL;
-
-					DEBUG_INFO("ALARM_LEAK_MODULE_FAIL : alarm \r\n");
-				}
-			}
-			else if(!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_LEAK_MODULE_FAIL))
-			{
-				if(ShmCharger->gun_info[gun_index].otherAlarmCode.isLeakageModule == ON)
-				{
-					ShmCharger->gun_info[gun_index].otherAlarmCode.isLeakageModule = OFF;
-					ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_LEAK_MODULE_FAIL;
-
-					DEBUG_INFO("ALARM_LEAK_MODULE_FAIL : recover \r\n");
-				}
-			}
-//
-//			//=====================================
-//			// Shutter detection
-//			//=====================================
-//			if(ShmCsuInputInfo->AcChargerInfoData[gun_index].InputAlarmCode & ALARM_SHUTTER_FAULT)
-//			{
-//				if(ShmCsuInputInfo->AcChargerInfoData[gun_index].AlarmCode.bits.SHUTTER_FAULT == OFF)
-//				{
-//					ShmCsuInputInfo->AcChargerInfoData[gun_index].AlarmCode.bits.SHUTTER_FAULT = ON;
-//					ShmCsuInputInfo->AcChargerInfoData[gun_index].SystemAlarmCode |= ALARM_SHUTTER_FAULT;
-//
-//					DEBUG_INFO("ALARM_SHUTTER_FAULT : alarm \r\n");
-//				}
-//			}
-//			else if(!(ShmCsuInputInfo->AcChargerInfoData[gun_index].InputAlarmCode & ALARM_SHUTTER_FAULT))
-//			{
-//				if(ShmCsuInputInfo->AcChargerInfoData[gun_index].AlarmCode.bits.SHUTTER_FAULT == ON)
-//				{
-//					ShmCsuInputInfo->AcChargerInfoData[gun_index].AlarmCode.bits.SHUTTER_FAULT = OFF;
-//					ShmCsuInputInfo->AcChargerInfoData[gun_index].SystemAlarmCode &= ~ALARM_SHUTTER_FAULT;
-//
-//					DEBUG_INFO("ALARM_SHUTTER_FAULT : recover \r\n");
-//				}
-//			}
-//
-//			//=====================================
-//			// Locker detection
-//			//=====================================
-//			if(ShmCsuInputInfo->AcChargerInfoData[gun_index].InputAlarmCode & ALARM_LOCKER_FAULT)
-//			{
-//				if(ShmCsuInputInfo->AcChargerInfoData[gun_index].AlarmCode.bits.LOCKER_FAULT == OFF)
-//				{
-//					ShmCsuInputInfo->AcChargerInfoData[gun_index].AlarmCode.bits.LOCKER_FAULT = ON;
-//					ShmCsuInputInfo->AcChargerInfoData[gun_index].SystemAlarmCode |= ALARM_LOCKER_FAULT;
-//
-//					DEBUG_INFO("ALARM_LOCKER_FAULT : alarm \r\n");
-//				}
-//			}
-//			else if(!(ShmCsuInputInfo->AcChargerInfoData[gun_index].InputAlarmCode & ALARM_LOCKER_FAULT))
-//			{
-//				if(ShmCsuInputInfo->AcChargerInfoData[gun_index].AlarmCode.bits.LOCKER_FAULT == ON)
-//				{
-//					ShmCsuInputInfo->AcChargerInfoData[gun_index].AlarmCode.bits.LOCKER_FAULT = OFF;
-//					ShmCsuInputInfo->AcChargerInfoData[gun_index].SystemAlarmCode &= ~ALARM_LOCKER_FAULT;
-//
-//					DEBUG_INFO("ALARM_LOCKER_FAULT : recover \r\n");
-//				}
-//			}
-//
-//			//=====================================
-//			// Power drop detection
-//			//=====================================
-//			if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_POWER_DROP)
-//			{
-//				if(ShmCharger->gun_info[gun_index].otherAlarmCode.isPowerDrop == OFF)
-//				{
-//					ShmCharger->gun_info[gun_index].otherAlarmCode.isPowerDrop = ON;
-//					ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_POWER_DROP;
-//
-//					DEBUG_INFO("ALARM_POWER_DROP : alarm \r\n");
-//				}
-//			}
-//			else if(!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_POWER_DROP))
-//			{
-//				if(ShmCharger->gun_info[gun_index].otherAlarmCode.isPowerDrop == ON)
-//				{
-//					ShmCharger->gun_info[gun_index].otherAlarmCode.isPowerDrop = OFF;
-//					ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_POWER_DROP;
-//
-//					DEBUG_INFO("ALARM_POWER_DROP : recover \r\n");
-//				}
-//			}
-//
-
-
-
-			//=====================================
-			// Latch alarm recover in state A
-			//=====================================
-			if((ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PilotState == 1))
-			{
-				/*
-				  TODO: Recover latch alarm here
-				*/
-			}
-
-			//=====================================
-			// Latch alarm recover in state B1 and B2
-			//=====================================
-			if((ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PilotState == 2) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PilotState == 3))
-			{
-				/*
-				TODO: Recover latch alarm here
-				*/
-			}
-
-			//=====================================
-			// Latch alarm recover in state C
-			//=====================================
-			if((ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PilotState == 4))
-			{
-				/*
-				  TODO: Recover latch alarm here
-				*/
-			}
-		}
-
-		usleep(100000);
-	}
-
-	return FAIL;
-}
+/*
+ * Module_AlarmDetect.c
+ *
+ *  Created on: 2020年01月15日
+ *      Author: Eason Yang
+ */
+#include    <sys/types.h>
+#include    <sys/stat.h>
+#include 	<sys/time.h>
+#include 	<sys/timeb.h>
+#include 	<sys/ipc.h>
+#include 	<sys/shm.h>
+#include 	<sys/mman.h>
+
+#include 	<unistd.h>
+#include 	<stdarg.h>
+#include    <stdio.h>      /*標準輸入輸出定義*/
+#include    <stdlib.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	"define.h"
+#include	"main.h"
+
+#define FILTER_SPEC			50
+
+#define DEBUG_INFO(format, args...) StoreLogMsg("[%s:%d][%s][Info] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
+#define DEBUG_WARN(format, args...) StoreLogMsg("[%s:%d][%s][Warn] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
+#define DEBUG_ERROR(format, args...) StoreLogMsg("[%s:%d][%s][Error] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
+
+#define Debug
+#define ARRAY_SIZE(A)		(sizeof(A) / sizeof(A[0]))
+#define PASS				1
+#define FAIL				0
+#define ON					1
+#define OFF					0
+
+#define SPEC_OV				275
+#define SPEC_UV				160
+#define SPEC_OC				(32*1.1)
+#define SPEC_OT				85
+
+#define HYSTERETIC_OUV		10
+#define HYSTERETIC_OT		10
+#define HYSTERETIC_OC		10
+
+struct{
+	unsigned short int	OV[3];
+	unsigned short int	UV[3];
+	unsigned short int	OC;
+	unsigned short int	OT_AMB;
+	unsigned short int	GMI;
+	unsigned short int	Short;
+	unsigned short int	Ac_Leak;
+	unsigned short int	Dc_Leak;
+	unsigned short int	HandShakingTimeout;
+	unsigned short int	EmrgencyBTN;
+	unsigned short int	Relay_Welding;
+	unsigned short int	Relay_DrivingFault;
+	unsigned short int	CP_LevelFail;
+	unsigned short int	MCU_SelfTestFail;
+}Alarm_Counter[2];
+
+void trim(char *s);
+void substr(char *dest, const char* src, unsigned int start, unsigned int cnt);
+
+struct SysConfigAndInfo			*ShmSysConfigAndInfo;
+struct StatusCodeData 			*ShmStatusCodeData;
+struct OCPP16Data				*ShmOCPP16Data;
+struct Charger					*ShmCharger;
+
+int StoreLogMsg(const char *fmt, ...)
+{
+	char Buf[4096+256];
+	char buffer[4096];
+	time_t CurrentTime;
+	struct tm *tm;
+	va_list args;
+
+	va_start(args, fmt);
+	int rc = vsnprintf(buffer, sizeof(buffer), fmt, args);
+	va_end(args);
+
+	memset(Buf,0,sizeof(Buf));
+	CurrentTime = time(NULL);
+	tm=localtime(&CurrentTime);
+	sprintf(Buf,"echo \"[%04d.%02d.%02d %02d:%02d:%02d] - %s\" >> /Storage/SystemLog/%04d-%02d_%s_%s_SystemLog",
+			tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,
+			buffer,
+			tm->tm_year+1900,tm->tm_mon+1,
+			ShmSysConfigAndInfo->SysConfig.ModelName,
+			ShmSysConfigAndInfo->SysConfig.SerialNumber);
+#ifdef SystemLogMessage
+	system(Buf);
+#endif
+
+	printf("[%04d.%02d.%02d %02d:%02d:%02d] - %s", tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec, buffer);
+
+	return rc;
+}
+
+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;
+}
+
+//==========================================
+// Init all share memory
+//==========================================
+int InitShareMemory()
+{
+	int result = PASS;
+	int MeterSMId;
+
+	//creat ShmSysConfigAndInfo
+	if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo),  0777)) < 0)
+    {
+		#ifdef SystemLogMessage
+		DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
+		#endif
+		result = FAIL;
+	}
+    else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
+    {
+    	#ifdef SystemLogMessage
+    	DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
+		#endif
+    	result = FAIL;
+   	 }
+    else
+    {}
+
+   	//creat ShmStatusCodeData
+   	if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData),  0777)) < 0)
+    {
+		#ifdef SystemLogMessage
+   		DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
+		#endif
+   		result = FAIL;
+	}
+    else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
+    {
+    	#ifdef SystemLogMessage
+    	DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
+		#endif
+    	result = FAIL;
+   	}
+    else
+    {}
+
+   	//creat ShmStatusCodeData
+   	if ((MeterSMId = shmget(ShmChargerKey, sizeof(struct Charger), 0777)) < 0)
+	{
+
+		DEBUG_ERROR("shmget ShmCharger NG\r\n");
+
+		result = FAIL;
+	}
+	else if ((ShmCharger = shmat(MeterSMId, NULL, 0)) == (void *) -1)
+	{
+
+		DEBUG_ERROR("shmat ShmCharger NG\r\n");
+
+		result = FAIL;
+	}
+	else
+	{}
+
+   	//creat ShmOCPP16Data
+	if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
+	{
+
+		DEBUG_ERROR("shmget ShmOCPP16Data NG\r\n");
+
+		result = FAIL;
+	}
+	else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
+	{
+
+		DEBUG_ERROR("shmat ShmOCPP16Data NG\r\n");
+
+		result = FAIL;
+	}
+	else
+	{}
+
+    return result;
+}
+
+//==========================================
+// Common routine
+//==========================================
+void trim(char *s)
+{
+    int i=0, j, k, l=0;
+
+    while((s[i]==' ')||(s[i]=='\t')||(s[i]=='\n'))
+        i++;
+
+    j = strlen(s)-1;
+    while((s[j]==' ')||(s[j]=='\t')||(s[j]=='\n'))
+        j--;
+
+    if(i==0 && j==strlen(s)-1) { }
+    else if(i==0) s[j+1] = '\0';
+    else {
+        for(k=i; k<=j; k++) s[l++] = s[k];
+        s[l] = '\0';
+    }
+}
+
+void substr(char *dest, const char* src, unsigned int start, unsigned int cnt)
+{
+	strncpy(dest, src + start, cnt);
+	dest[cnt] = 0;
+}
+
+//==========================================
+// Main process
+//==========================================
+int main(void)
+{
+
+	if(InitShareMemory() == FAIL)
+	{
+		DEBUG_ERROR("InitShareMemory NG\n");
+
+		if(ShmStatusCodeData!=NULL)
+		{
+			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
+		}
+		sleep(5);
+		return FAIL;
+	}
+
+	for(;;)
+	{
+		for(int gun_index = 0;gun_index<AC_QUANTITY;gun_index++)
+		{
+			//=====================================
+			// Over voltage detection
+			//=====================================
+			if((ShmSysConfigAndInfo->SysInfo.InputVoltageR > SPEC_OV) &&
+				(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_OVER_VOLTAGE))
+			{
+				if(Alarm_Counter[gun_index].OV[0] > FILTER_SPEC)
+				{
+					if((ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputOVP == OFF))
+					{
+						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputOVP = ON;
+						ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_OVER_VOLTAGE;
+						DEBUG_INFO("ALARM_OVER_VOLTAGE : alarm \r\n");
+					}
+				}
+				else
+				{
+					Alarm_Counter[gun_index].OV[0]++;
+				}
+			}
+			else if((ShmSysConfigAndInfo->SysInfo.InputVoltageR < (SPEC_OV-HYSTERETIC_OUV)) &&
+					(!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_OVER_VOLTAGE)))
+			{
+				Alarm_Counter[gun_index].OV[0] = 0;
+				if((ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputOVP == ON))
+				{
+					ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputOVP = OFF;
+					ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_OVER_VOLTAGE;
+					DEBUG_INFO("ALARM_OVER_VOLTAGE : recover \r\n");
+				}
+			}
+
+			if(ShmSysConfigAndInfo->SysConfig.AcPhaseCount == 3)
+			{
+				if((ShmSysConfigAndInfo->SysInfo.InputVoltageS > SPEC_OV) &&
+				   (ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_OVER_VOLTAGE))
+				{
+					if(Alarm_Counter[gun_index].OV[1] > FILTER_SPEC)
+					{
+						if((ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputOVP == OFF))
+						{
+							ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputOVP = ON;
+							ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_OVER_VOLTAGE;
+							DEBUG_INFO("ALARM_OVER_VOLTAGE : alarm \r\n");
+						}
+					}
+					else
+					{
+						Alarm_Counter[gun_index].OV[1]++;
+					}
+				}
+				else if((ShmSysConfigAndInfo->SysInfo.InputVoltageS < (SPEC_OV-HYSTERETIC_OUV)) &&
+						(!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_OVER_VOLTAGE)))
+				{
+					Alarm_Counter[gun_index].OV[1] = 0;
+					if((ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputOVP == ON))
+					{
+						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputOVP = OFF;
+						ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_OVER_VOLTAGE;
+						DEBUG_INFO("ALARM_OVER_VOLTAGE : recover \r\n");
+					}
+				}
+
+				if((ShmSysConfigAndInfo->SysInfo.InputVoltageT > SPEC_OV) &&
+				   (ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_OVER_VOLTAGE))
+				{
+					if(Alarm_Counter[gun_index].OV[2] > FILTER_SPEC)
+					{
+						if((ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputOVP == OFF))
+						{
+							ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputOVP = ON;
+							ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_OVER_VOLTAGE;
+							DEBUG_INFO("ALARM_OVER_VOLTAGE : alarm \r\n");
+						}
+					}
+					else
+					{
+						Alarm_Counter[gun_index].OV[2]++;
+					}
+				}
+				else if((ShmSysConfigAndInfo->SysInfo.InputVoltageT < (SPEC_OV-HYSTERETIC_OUV)) &&
+						(!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_OVER_VOLTAGE)))
+				{
+					Alarm_Counter[gun_index].OV[2] = 0;
+					if((ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputOVP == ON))
+					{
+						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputOVP = OFF;
+						ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_OVER_VOLTAGE;
+						DEBUG_INFO("ALARM_OVER_VOLTAGE : recover \r\n");
+					}
+				}
+			}
+
+			//=====================================
+			// Under voltage detection
+			//=====================================
+			if((ShmSysConfigAndInfo->SysInfo.InputVoltageR  < SPEC_UV) &&
+				(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_UNDER_VOLTAGE))
+			{
+				if(Alarm_Counter[gun_index].UV[0] > FILTER_SPEC)
+				{
+					if((ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputUVP == OFF))
+					{
+						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputUVP = ON;
+						ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_UNDER_VOLTAGE;
+						DEBUG_INFO("ALARM_UNDER_VOLTAGE : alarm \r\n");
+					}
+				}
+				else
+				{
+					Alarm_Counter[gun_index].UV[0]++;
+				}
+			}
+			else if((ShmSysConfigAndInfo->SysInfo.InputVoltageR  > (SPEC_UV+HYSTERETIC_OUV)) &&
+					(!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_UNDER_VOLTAGE)))
+			{
+				Alarm_Counter[gun_index].UV[0] = 0;
+				if((ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputUVP == ON))
+				{
+					ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputUVP = OFF;
+					ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_UNDER_VOLTAGE;
+					DEBUG_INFO("ALARM_UNDER_VOLTAGE : recover \r\n");
+				}
+			}
+
+			if(ShmSysConfigAndInfo->SysConfig.AcPhaseCount == 3)
+			{
+				if((ShmSysConfigAndInfo->SysInfo.InputVoltageS < SPEC_UV) &&
+				   (ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_UNDER_VOLTAGE))
+				{
+					if(Alarm_Counter[gun_index].UV[1] > FILTER_SPEC)
+					{
+						if((ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputUVP == OFF))
+						{
+							ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputUVP = ON;
+							ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_UNDER_VOLTAGE;
+							DEBUG_INFO("ALARM_UNDER_VOLTAGE : alarm \r\n");
+						}
+					}
+					else
+					{
+						Alarm_Counter[gun_index].UV[1]++;
+					}
+				}
+				else if((ShmSysConfigAndInfo->SysInfo.InputVoltageS > (SPEC_UV+HYSTERETIC_OUV)) &&
+						(!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_UNDER_VOLTAGE)))
+				{
+					Alarm_Counter[gun_index].UV[1] = 0;
+					if((ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputUVP == ON))
+					{
+						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputUVP = OFF;
+						ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_UNDER_VOLTAGE;
+						DEBUG_INFO("ALARM_UNDER_VOLTAGE : recover \r\n");
+					}
+				}
+
+				if((ShmSysConfigAndInfo->SysInfo.InputVoltageT < SPEC_UV) &&
+				   (ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_UNDER_VOLTAGE))
+				{
+					if(Alarm_Counter[gun_index].UV[2] > FILTER_SPEC)
+					{
+						if((ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputUVP == OFF))
+						{
+							ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputUVP = ON;
+							ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_UNDER_VOLTAGE;
+							DEBUG_INFO("ALARM_UNDER_VOLTAGE : alarm \r\n");
+						}
+					}
+					else
+					{
+						Alarm_Counter[gun_index].UV[2]++;
+					}
+				}
+				else if((ShmSysConfigAndInfo->SysInfo.InputVoltageT > (SPEC_OV+HYSTERETIC_OUV)) &&
+						(!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_UNDER_VOLTAGE)))
+				{
+					Alarm_Counter[gun_index].UV[2] = 0;
+					if((ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputUVP == ON))
+					{
+						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputUVP = OFF;
+						ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_UNDER_VOLTAGE;
+						DEBUG_INFO("ALARM_UNDER_VOLTAGE : recover \r\n");
+					}
+				}
+			}
+
+			//=====================================
+			// Over current detection
+			//=====================================
+			if((ShmCharger->gun_info[gun_index].outputCurrent.L1N_L12[0] > SPEC_OC) &&
+			   (ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_OVER_CURRENT))
+			{
+				if((ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAcOutputOCP == OFF))
+				{
+					ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAcOutputOCP = ON;
+					ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_OVER_CURRENT;
+					DEBUG_INFO("ALARM_OVER_CURRENT : alarm \r\n");
+				}
+			}
+			else if ((ShmCharger->gun_info[gun_index].outputCurrent.L1N_L12[0] < (SPEC_OC-HYSTERETIC_OC)) &&
+					 (!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_OVER_CURRENT)))
+			{
+				if((ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAcOutputOCP == ON))
+				{
+					ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAcOutputOCP = OFF;
+					ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_OVER_CURRENT;
+					DEBUG_INFO("ALARM_OVER_CURRENT : recover \r\n");
+				}
+			}
+
+			if(ShmSysConfigAndInfo->SysConfig.AcPhaseCount == 3)
+			{
+				if((ShmCharger->gun_info[gun_index].outputCurrent.L2N_L23[0] > SPEC_OC) &&
+				   (ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_OVER_CURRENT))
+				{
+					if((ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAcOutputOCP == OFF))
+					{
+						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAcOutputOCP = ON;
+						ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_OVER_CURRENT;
+						DEBUG_INFO("ALARM_OVER_CURRENT : alarm \r\n");
+					}
+				}
+				else if ((ShmCharger->gun_info[gun_index].outputCurrent.L2N_L23[0] < (SPEC_OC-HYSTERETIC_OC)) &&
+						 (!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_OVER_CURRENT)))
+				{
+					if((ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAcOutputOCP == ON))
+					{
+						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAcOutputOCP = OFF;
+						ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_OVER_CURRENT;
+						DEBUG_INFO("ALARM_OVER_CURRENT : recover \r\n");
+					}
+				}
+
+				if((ShmCharger->gun_info[gun_index].outputCurrent.L3N_L31[0] > SPEC_OC) &&
+				   (ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_OVER_CURRENT))
+				{
+					if((ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAcOutputOCP == OFF))
+					{
+						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAcOutputOCP = ON;
+						ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_OVER_CURRENT;
+						DEBUG_INFO("ALARM_OVER_CURRENT : alarm \r\n");
+					}
+				}
+				else if ((ShmCharger->gun_info[gun_index].outputCurrent.L3N_L31[0] < (SPEC_OC-HYSTERETIC_OC)) &&
+						 (!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_OVER_CURRENT)))
+				{
+					if((ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAcOutputOCP == ON))
+					{
+						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAcOutputOCP = OFF;
+						ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_OVER_CURRENT;
+						DEBUG_INFO("ALARM_OVER_CURRENT : recover \r\n");
+					}
+				}
+			}
+
+			//=====================================
+			// Over temperature detection
+			//=====================================
+			if(//(ShmSysConfigAndInfo->SysInfo.SystemAmbientTemp > SPEC_OT) &&
+			   (ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_OVER_TEMPERATURE))
+			{
+				if(Alarm_Counter[gun_index].OT_AMB > FILTER_SPEC)
+				{
+					if((ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAmbientOTP == OFF))
+					{
+						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAmbientOTP = ON;
+						ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_OVER_TEMPERATURE;
+						DEBUG_INFO("ALARM_OVER_TEMPERATURE : alarm \r\n");
+					}
+				}
+				else
+				{
+					Alarm_Counter[gun_index].OT_AMB++;
+				}
+			}
+			else if(//(ShmSysConfigAndInfo->SysInfo.SystemAmbientTemp < (SPEC_OT-10)) &&
+					(!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_OVER_TEMPERATURE)))
+			{
+				Alarm_Counter[gun_index].OT_AMB = 0;
+				if((ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAmbientOTP == ON))
+				{
+					ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAmbientOTP = OFF;
+					ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_OVER_TEMPERATURE;
+					DEBUG_INFO("ALARM_OVER_TEMPERATURE : recover \r\n");
+				}
+			}
+
+			//=====================================
+			// Ground fault detection
+			//=====================================
+			if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_GROUND_FAIL)
+			{
+				if(Alarm_Counter[gun_index].GMI > FILTER_SPEC)
+				{
+					if((ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbGfdTrip == OFF))
+					{
+						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbGfdTrip = ON;
+						ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_GROUND_FAIL;
+						DEBUG_INFO("ALARM_GROUND_FAIL : alarm \r\n");
+					}
+				}
+				else
+				{
+					Alarm_Counter[gun_index].GMI++;
+				}
+			}
+			else if (!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_GROUND_FAIL))
+			{
+				Alarm_Counter[gun_index].GMI = 0;
+				if((ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbGfdTrip == ON ))
+				{
+					ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbGfdTrip = OFF;
+					ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_GROUND_FAIL;
+					DEBUG_INFO("ALARM_GROUND_FAIL : recover \r\n");
+				}
+			}
+
+			//=====================================
+			// CP level fail detection
+			//====================================
+			if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_CP_ERROR)
+			{
+				if(Alarm_Counter[gun_index].CP_LevelFail > FILTER_SPEC)
+				{
+					if(ShmStatusCodeData->InfoCode.InfoEvents.bits.PilotFault == OFF)
+					{
+						ShmStatusCodeData->InfoCode.InfoEvents.bits.PilotFault = ON;
+						ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_CP_ERROR;
+						DEBUG_INFO("ALARM_CP_ERROR : alarm \r\n");
+					}
+				}
+				else
+				{
+					Alarm_Counter[gun_index].CP_LevelFail++;
+				}
+			}
+			else if(!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_CP_ERROR))
+			{
+				Alarm_Counter[gun_index].CP_LevelFail= 0;
+				if(ShmStatusCodeData->InfoCode.InfoEvents.bits.PilotFault == ON)
+				{
+					ShmStatusCodeData->InfoCode.InfoEvents.bits.PilotFault = OFF;
+					ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_CP_ERROR;
+					DEBUG_INFO("ALARM_CP_ERROR : recover \r\n");
+				}
+			}
+
+			//=====================================
+			// Current AC leak detection
+			//=====================================
+			if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_CURRENT_LEAK_AC)
+			{
+				if(Alarm_Counter[gun_index].Ac_Leak > FILTER_SPEC)
+				{
+					if((ShmStatusCodeData->AlarmCode.AlarmEvents.bits.RcdTrip == OFF))
+					{
+						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.RcdTrip = ON;
+						ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_CURRENT_LEAK_AC;
+						DEBUG_INFO("ALARM_CURRENT_LEAK_AC : alarm \r\n");
+					}
+				}
+				else
+				{
+					Alarm_Counter[gun_index].Ac_Leak++;
+				}
+			}
+			else if(!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_CURRENT_LEAK_AC))
+			{
+				Alarm_Counter[gun_index].Ac_Leak = 0;
+				if((ShmStatusCodeData->AlarmCode.AlarmEvents.bits.RcdTrip == ON))
+				{
+					ShmStatusCodeData->AlarmCode.AlarmEvents.bits.RcdTrip = OFF;
+					ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_CURRENT_LEAK_AC;
+					DEBUG_INFO("ALARM_CURRENT_LEAK_AC : recover \r\n");
+				}
+			}
+
+			//=====================================
+			// Current DC leak detection
+			//=====================================
+//			if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_CURRENT_LEAK_DC)
+//			{
+//				if(Alarm_Counter[gun_index].Dc_Leak > FILTER_SPEC)
+//				{
+//					if((ShmStatusCodeData->AlarmCode.AlarmEvents.bits.RcdTrip == OFF))
+//					{
+//						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.RcdTrip = ON;
+//						ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_CURRENT_LEAK_DC;
+//						DEBUG_INFO("ALARM_CURRENT_LEAK_DC : alarm \r\n");
+//					}
+//				}
+//				else
+//				{
+//					Alarm_Counter[gun_index].Dc_Leak++;
+//				}
+//			}
+//			else if(!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_CURRENT_LEAK_DC))
+//			{
+//				Alarm_Counter[gun_index].Dc_Leak = 0;
+//				if((ShmStatusCodeData->AlarmCode.AlarmEvents.bits.RcdTrip == ON))
+//				{
+//					ShmStatusCodeData->AlarmCode.AlarmEvents.bits.RcdTrip = OFF;
+//					ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_CURRENT_LEAK_DC;
+//					DEBUG_INFO("ALARM_CURRENT_LEAK_DC : recover \r\n");
+//				}
+//			}
+
+			//=====================================
+			// MCU self test fail detection
+			//=====================================
+			if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_MCU_TESTFAIL)
+			{
+				if(Alarm_Counter[gun_index].MCU_SelfTestFail > FILTER_SPEC)
+				{
+					if(ShmCharger->gun_info[gun_index].otherAlarmCode.isMcuSelfTest == OFF)
+					{
+						ShmCharger->gun_info[gun_index].otherAlarmCode.isMcuSelfTest = ON;
+						ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_MCU_TESTFAIL;
+						DEBUG_INFO("ALARM_MCU_TESTFAIL : alarm \r\n");
+					}
+				}
+				else
+				{
+					Alarm_Counter[gun_index].MCU_SelfTestFail++;
+				}
+			}
+			else if(!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_MCU_TESTFAIL))
+			{
+				Alarm_Counter[gun_index].MCU_SelfTestFail = 0;
+				if(ShmCharger->gun_info[gun_index].otherAlarmCode.isMcuSelfTest == ON)
+				{
+					ShmCharger->gun_info[gun_index].otherAlarmCode.isMcuSelfTest = OFF;
+					ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_MCU_TESTFAIL;
+					DEBUG_INFO("ALARM_MCU_TESTFAIL : recover \r\n");
+				}
+			}
+
+			//=====================================
+			// Hand shaking timeout detection
+			//=====================================
+			if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_HANDSHAKE_TIMEOUT)
+			{
+				if(ShmCharger->gun_info[gun_index].otherAlarmCode.isHandshakingTimeOut == OFF)
+				{
+					ShmCharger->gun_info[gun_index].otherAlarmCode.isHandshakingTimeOut  = ON;
+					ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_HANDSHAKE_TIMEOUT;
+					DEBUG_INFO("ALARM_HANDSHAKE_TIMEOUT : alarm \r\n");
+				}
+
+			}
+			else if(!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_HANDSHAKE_TIMEOUT))
+			{
+				if(ShmCharger->gun_info[gun_index].otherAlarmCode.isHandshakingTimeOut  == ON)
+				{
+					ShmCharger->gun_info[gun_index].otherAlarmCode.isHandshakingTimeOut  = OFF;
+					ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_HANDSHAKE_TIMEOUT;
+					DEBUG_INFO("ALARM_HANDSHAKE_TIMEOUT : recover \r\n");
+				}
+			}
+
+			//=====================================
+			// Emergency stop detection
+			//=====================================
+			if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_EMERGENCY_STOP)
+			{
+				if(Alarm_Counter[gun_index].EmrgencyBTN > FILTER_SPEC)
+				{
+					if((ShmStatusCodeData->AlarmCode.AlarmEvents.bits.EmergencyStopTrip == OFF))
+					{
+						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.EmergencyStopTrip = ON;
+						ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_EMERGENCY_STOP;
+						DEBUG_INFO("ALARM_EMERGENCY_STOP : alarm \r\n");
+					}
+				}
+				else
+				{
+					Alarm_Counter[gun_index].EmrgencyBTN++;
+				}
+			}
+			else if(!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_EMERGENCY_STOP))
+			{
+				Alarm_Counter[gun_index].EmrgencyBTN = 0;
+				if((ShmStatusCodeData->AlarmCode.AlarmEvents.bits.EmergencyStopTrip == ON))
+				{
+					ShmStatusCodeData->AlarmCode.AlarmEvents.bits.EmergencyStopTrip = OFF;
+					ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_EMERGENCY_STOP;
+					DEBUG_INFO("ALARM_EMERGENCY_STOP : recover \r\n");
+				}
+			}
+
+			//=====================================
+			// Relay welding detection
+			//=====================================
+			if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_RELAY_WELDING)
+			{
+				if(Alarm_Counter[gun_index].Relay_Welding > FILTER_SPEC)
+				{
+					if((ShmStatusCodeData->FaultCode.FaultEvents.bits.AcOutputRelayWelding == OFF))
+					{
+						ShmStatusCodeData->FaultCode.FaultEvents.bits.AcOutputRelayWelding = ON;
+						ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_RELAY_WELDING;
+						DEBUG_INFO("ALARM_RELAY_STATUS : alarm \r\n");
+					}
+				}
+				else
+				{
+					Alarm_Counter[gun_index].Relay_Welding++;
+				}
+			}
+			else if(!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_RELAY_WELDING))
+			{
+				Alarm_Counter[gun_index].Relay_Welding = 0;
+				if((ShmStatusCodeData->FaultCode.FaultEvents.bits.AcOutputRelayWelding == ON))
+				{
+					ShmStatusCodeData->FaultCode.FaultEvents.bits.AcOutputRelayWelding = OFF;
+					ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_RELAY_WELDING;
+					DEBUG_INFO("ALARM_RELAY_STATUS : recover \r\n");
+				}
+			}
+
+			//=====================================
+			// Relay driving fault detection
+			//=====================================
+			if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_RELAY_DRIVE_FAULT)
+			{
+				if(Alarm_Counter[gun_index].Relay_DrivingFault > FILTER_SPEC)
+				{
+					if((ShmStatusCodeData->FaultCode.FaultEvents.bits.AcOutputRelayDrivingFault == OFF))
+					{
+						ShmStatusCodeData->FaultCode.FaultEvents.bits.AcOutputRelayDrivingFault = ON;
+						ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_RELAY_DRIVE_FAULT;
+						DEBUG_INFO("ALARM_RELAY_DRIVE_FAULT : alarm \r\n");
+					}
+				}
+				else
+				{
+					Alarm_Counter[gun_index].Relay_DrivingFault++;
+				}
+			}
+			else if(!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_RELAY_DRIVE_FAULT))
+			{
+				Alarm_Counter[gun_index].Relay_DrivingFault = 0;
+				if((ShmStatusCodeData->FaultCode.FaultEvents.bits.AcOutputRelayDrivingFault == ON))
+				{
+					ShmStatusCodeData->FaultCode.FaultEvents.bits.AcOutputRelayDrivingFault = OFF;
+					ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_RELAY_DRIVE_FAULT;
+					DEBUG_INFO("ALARM_RELAY_DRIVE_FAULT : recover \r\n");
+				}
+			}
+
+			//=====================================
+			// Current short detection
+			//=====================================
+			if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_CURRENT_SHORT)
+			{
+				if(Alarm_Counter[gun_index].Short > FILTER_SPEC)
+				{
+					if(ShmCharger->gun_info[gun_index].otherAlarmCode.isCurrentShort == OFF)
+					{
+						ShmCharger->gun_info[gun_index].otherAlarmCode.isCurrentShort = ON;
+						ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_CURRENT_SHORT;
+						DEBUG_INFO("ALARM_CIRCUIT_SHORT : alarm \r\n");
+					}
+				}
+				else
+				{
+					Alarm_Counter[gun_index].Short++;
+				}
+			}
+			else if(!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_CURRENT_SHORT))
+			{
+				Alarm_Counter[gun_index].Short = 0;
+
+				if(ShmCharger->gun_info[gun_index].otherAlarmCode.isCurrentShort == ON)
+				{
+					ShmCharger->gun_info[gun_index].otherAlarmCode.isCurrentShort = OFF;
+					ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_CURRENT_SHORT;
+					DEBUG_INFO("ALARM_CIRCUIT_SHORT : recover \r\n");
+				}
+			}
+
+			//=====================================
+			// Rotatory switch detection
+			//=====================================
+			if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_ROTATORY_SWITCH_FAULT)
+			{
+				if(ShmCharger->gun_info[gun_index].otherAlarmCode.isRotatorySwitch == OFF)
+				{
+					ShmCharger->gun_info[gun_index].otherAlarmCode.isRotatorySwitch = ON;
+					ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_ROTATORY_SWITCH_FAULT;
+					DEBUG_INFO("ALARM_ROTATORY_SWITCH_FAULT : alarm \r\n");
+				}
+			}
+			else if(!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_ROTATORY_SWITCH_FAULT))
+			{
+				if(ShmCharger->gun_info[gun_index].otherAlarmCode.isRotatorySwitch == ON)
+				{
+					ShmCharger->gun_info[gun_index].otherAlarmCode.isRotatorySwitch = OFF;
+					ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_ROTATORY_SWITCH_FAULT;
+					DEBUG_INFO("ALARM_ROTATORY_SWITCH_FAULT : recover \r\n");
+				}
+			}
+
+			//=====================================
+			// Leakage module detection
+			//=====================================
+			if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_LEAK_MODULE_FAIL)
+			{
+				if(ShmCharger->gun_info[gun_index].otherAlarmCode.isLeakageModule == OFF)
+				{
+					ShmCharger->gun_info[gun_index].otherAlarmCode.isLeakageModule = ON;
+					ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_LEAK_MODULE_FAIL;
+
+					DEBUG_INFO("ALARM_LEAK_MODULE_FAIL : alarm \r\n");
+				}
+			}
+			else if(!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_LEAK_MODULE_FAIL))
+			{
+				if(ShmCharger->gun_info[gun_index].otherAlarmCode.isLeakageModule == ON)
+				{
+					ShmCharger->gun_info[gun_index].otherAlarmCode.isLeakageModule = OFF;
+					ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_LEAK_MODULE_FAIL;
+
+					DEBUG_INFO("ALARM_LEAK_MODULE_FAIL : recover \r\n");
+				}
+			}
+
+			//=====================================
+			// Shutter detection
+			//=====================================
+			if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_SHUTTER_FAULT)
+			{
+				if(ShmCharger->gun_info[gun_index].otherAlarmCode.isShutterFail == OFF)
+				{
+					ShmCharger->gun_info[gun_index].otherAlarmCode.isShutterFail = ON;
+					ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_SHUTTER_FAULT;
+
+					DEBUG_INFO("ALARM_SHUTTER_FAULT : alarm \r\n");
+				}
+			}
+			else if(!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_SHUTTER_FAULT))
+			{
+				if(ShmCharger->gun_info[gun_index].otherAlarmCode.isShutterFail == ON)
+				{
+					ShmCharger->gun_info[gun_index].otherAlarmCode.isShutterFail = OFF;
+					ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_SHUTTER_FAULT;
+
+					DEBUG_INFO("ALARM_SHUTTER_FAULT : recover \r\n");
+				}
+			}
+
+			//=====================================
+			// Locker detection
+			//=====================================
+			if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_LOCKER_FAULT)
+			{
+				if(ShmCharger->gun_info[gun_index].otherAlarmCode.isLockerFault == OFF)
+				{
+					ShmCharger->gun_info[gun_index].otherAlarmCode.isLockerFault = ON;
+					ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_LOCKER_FAULT;
+
+					DEBUG_INFO("ALARM_LOCKER_FAULT : alarm \r\n");
+				}
+			}
+			else if(!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_LOCKER_FAULT))
+			{
+				if(ShmCharger->gun_info[gun_index].otherAlarmCode.isLockerFault== ON)
+				{
+					ShmCharger->gun_info[gun_index].otherAlarmCode.isLockerFault = OFF;
+					ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_LOCKER_FAULT;
+
+					DEBUG_INFO("ALARM_LOCKER_FAULT : recover \r\n");
+				}
+			}
+
+			//=====================================
+			// Power drop detection
+			//=====================================
+			if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_POWER_DROP)
+			{
+				if(ShmCharger->gun_info[gun_index].otherAlarmCode.isPowerDrop == OFF)
+				{
+					ShmCharger->gun_info[gun_index].otherAlarmCode.isPowerDrop = ON;
+					ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_POWER_DROP;
+
+					DEBUG_INFO("ALARM_POWER_DROP : alarm \r\n");
+				}
+			}
+			else if(!(ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode & ALARM_POWER_DROP))
+			{
+				if(ShmCharger->gun_info[gun_index].otherAlarmCode.isPowerDrop == ON)
+				{
+					ShmCharger->gun_info[gun_index].otherAlarmCode.isPowerDrop = OFF;
+					ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_POWER_DROP;
+
+					DEBUG_INFO("ALARM_POWER_DROP : recover \r\n");
+				}
+			}
+
+			//=====================================
+			// OCPP error code message
+			//=====================================
+			if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_OVER_VOLTAGE)
+			{
+				sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode , "OverVoltage");
+			}
+			else if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_UNDER_VOLTAGE)
+			{
+				sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode , "UnderVoltage");
+			}
+			else if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_OVER_CURRENT)
+			{
+				sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode , "OverCurrentFailure");
+			}
+			else if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_OVER_TEMPERATURE)
+			{
+				sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode , "HighTemperature");
+			}
+			else if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_GROUND_FAIL)
+			{
+				sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode , "GroundFailure");
+			}
+			else if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_CP_ERROR)
+			{
+				sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode , "OtherError");
+				sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode , "CpError");
+			}
+			else if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_CURRENT_LEAK_AC)
+			{
+				sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode , "OtherError");
+				sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode , "ACLeakage");
+			}
+			else if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_CURRENT_LEAK_DC)
+			{
+				sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode , "OtherError");
+				sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode , "DCLeakage");
+			}
+			else if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_MCU_TESTFAIL)
+			{
+				sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode , "OtherError");
+				sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode , "McuTestFail");
+			}
+			else if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_HANDSHAKE_TIMEOUT)
+			{
+				sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode , "OtherError");
+				sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode , "HandshakeTimeout");
+			}
+			else if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_EMERGENCY_STOP)
+			{
+				sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode , "OtherError");
+				sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode , "EmergencyStop");
+			}
+			else if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_RELAY_WELDING)
+			{
+				sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode , "OtherError");
+				sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode , "RelayWelding");
+			}
+			else if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_LEAK_MODULE_FAIL)
+			{
+				sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode , "OtherError");
+				sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode , "LeakageModuleFail");
+			}
+			else if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_SHUTTER_FAULT)
+			{
+				sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode , "OtherError");
+				sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode , "ShutterFault");
+			}
+			else if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_LOCKER_FAULT)
+			{
+				sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode , "ConnectorLockFailure");
+			}
+			else if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_POWER_DROP)
+			{
+				sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode , "OtherError");
+				sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode , "PowerDrop");
+			}
+			else if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_CURRENT_SHORT)
+			{
+				sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode , "OtherError");
+				sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode , "CircuitShort");
+			}
+			else if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_ROTATORY_SWITCH_FAULT)
+			{
+				sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode , "OtherError");
+				sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode , "RotatorySwitchFault");
+			}
+			else if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_RELAY_DRIVE_FAULT)
+			{
+				sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode , "OtherError");
+				sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode , "RelayDriveFault");
+			}
+			else
+			{
+				sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode , "NoError");
+			}
+
+			//=====================================
+			// Latch alarm recover in state A
+			//=====================================
+			if((ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PilotState == 1))
+			{
+				/*
+				  TODO: Recover latch alarm here
+				*/
+			}
+
+			//=====================================
+			// Latch alarm recover in state B1 and B2
+			//=====================================
+			if((ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PilotState == 2) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PilotState == 3))
+			{
+				/*
+				TODO: Recover latch alarm here
+				*/
+			}
+
+			//=====================================
+			// Latch alarm recover in state C
+			//=====================================
+			if((ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PilotState == 4))
+			{
+				/*
+				  TODO: Recover latch alarm here
+				*/
+			}
+		}
+
+		usleep(100000);
+	}
+
+	return FAIL;
+}

+ 13 - 13
EVSE/Projects/AW-Regular/Apps/Module_AlarmDetect.h

@@ -1,13 +1,13 @@
-/*
- * Module_AlarmDetect.h
- *
- *  Created on: 2019¦~8¤ë17¤é
- *      Author: foluswen
- */
-
-#ifndef MODULE_ALARMDETECT_H_
-#define MODULE_ALARMDETECT_H_
-
-
-
-#endif /* MODULE_ALARMDETECT_H_ */
+/*
+ * Module_AlarmDetect.h
+ *
+ *  Created on: 2020¦~01¤ë15¤é
+ *      Author: Eason Yang
+ */
+
+#ifndef MODULE_ALARMDETECT_H_
+#define MODULE_ALARMDETECT_H_
+
+
+
+#endif /* MODULE_ALARMDETECT_H_ */

+ 103 - 32
EVSE/Projects/AW-Regular/Apps/Module_InternalComm.c

@@ -1264,10 +1264,56 @@ unsigned char Config_AC_MCU_LEGACY_REQUEST(unsigned char fd, unsigned char targe
 	return result;
 }
 
+unsigned char Config_AC_MCU_RESET_REQUEST(unsigned char fd, unsigned char targetAddr, Mcu_Reset_Request *Set_Buf)
+{
+	unsigned char result = FAIL;
+	unsigned char tx[9];
+	unsigned char rx[512];
+	unsigned char chksum = 0x00;
+
+	tx[0] = 0xaa;
+	tx[1] = 0x00;
+	tx[2] = targetAddr;
+	tx[3] = CMD_CONFIG_MCU_RESET_REQUEST;
+	tx[4] = 0x02;
+	tx[5] = 0x00;
+	tx[6] = Set_Buf->isMcuResetRequest;
+	tx[7] = 0x00;
+
+	for(int idx=0;idx<(tx[4] | tx[5]<<8);idx++)
+		chksum ^= tx[6+idx];
+	tx[8] = chksum;
+
+	unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
+
+	if(len > 6)
+	{
+		if (len < 6+(rx[4] | rx[5]<<8))
+			return result;
+
+		chksum = 0x00;
+		for(int idx=0;idx<(rx[4] | rx[5]<<8);idx++)
+		{
+			chksum ^= rx[6+idx];
+		}
+
+		if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
+		   (rx[2] == tx[1]) &&
+		   (rx[1] == tx[2]) &&
+		   (rx[3] == tx[3]) &&
+		   (rx[6] == 0x01))
+		{
+			result = PASS;
+		}
+	}
+
+	return result;
+}
+
 unsigned char Query_AC_GUN_PLUGIN_TIMES(unsigned char fd, unsigned char targetAddr, Gun_Plugin_Times *Ret_Buf)
 {
 	unsigned char result = FAIL;
-	unsigned char tx[7] = {0xaa, 0x00, targetAddr, CMD_CONFIG_GUN_PLUGIN_TIMES, 0x00, 0x00, 0x00};
+	unsigned char tx[7] = {0xaa, 0x00, targetAddr, CMD_QUERY_GUN_PLUGIN_TIMES, 0x00, 0x00, 0x00};
 	unsigned char rx[512];
 	unsigned char chksum = 0x00;
 	unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
@@ -1650,17 +1696,20 @@ int main(void)
 				//===============================
 				if(Query_AC_MCU_Status(Uart1Fd, (gun_index>0?ADDR_AC_PRIMARY_2:ADDR_AC_PRIMARY_1), &ShmCharger->gun_info[gun_index].primaryMcuState))
 				{
-					DEBUG_INFO("MCU-%d get Pilot State : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuState.cp_state);
-					DEBUG_INFO("MCU-%d get Pilot Duty : %.2f\r\n", gun_index, (float)ShmCharger->gun_info[gun_index].primaryMcuState.current_limit);
-					DEBUG_INFO("MCU-%d get Pilot Voltage Positive : %.2f\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuState.cp_voltage_positive);
-					DEBUG_INFO("MCU-%d get Pilot Voltage Negative : %.2f\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuState.cp_voltage_negtive);
-					DEBUG_INFO("MCU-%d get Locker State : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuState.locker_state);
-					DEBUG_INFO("MCU-%d get Relay State : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuState.relay_state);
-					DEBUG_INFO("MCU-%d get Shutter State : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuState.shutter_state);
-					DEBUG_INFO("MCU-%d get Meter State : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuState.meter_state);
-					DEBUG_INFO("MCU-%d get PP State : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuState.pp_state);
-					DEBUG_INFO("MCU-%d get Rating Current : %.2f\r\n", gun_index, (float)ShmCharger->gun_info[gun_index].primaryMcuState.rating_current);
-					DEBUG_INFO("MCU-%d get Rotatory switch : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuState.rotatory_switch);
+					if(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PreviousSystemStatus != ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].SystemStatus)
+					{
+						DEBUG_INFO("MCU-%d get Pilot State : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuState.cp_state);
+						DEBUG_INFO("MCU-%d get Pilot Duty : %.2f\r\n", gun_index, (float)ShmCharger->gun_info[gun_index].primaryMcuState.current_limit);
+						DEBUG_INFO("MCU-%d get Pilot Voltage Positive : %.2f\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuState.cp_voltage_positive);
+						DEBUG_INFO("MCU-%d get Pilot Voltage Negative : %.2f\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuState.cp_voltage_negtive);
+						DEBUG_INFO("MCU-%d get Locker State : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuState.locker_state);
+						DEBUG_INFO("MCU-%d get Relay State : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuState.relay_state);
+						DEBUG_INFO("MCU-%d get Shutter State : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuState.shutter_state);
+						DEBUG_INFO("MCU-%d get Meter State : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuState.meter_state);
+						DEBUG_INFO("MCU-%d get PP State : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuState.pp_state);
+						DEBUG_INFO("MCU-%d get Rating Current : %.2f\r\n", gun_index, (float)ShmCharger->gun_info[gun_index].primaryMcuState.rating_current);
+						DEBUG_INFO("MCU-%d get Rotatory switch : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuState.rotatory_switch);
+					}
 
 					ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PilotState = ShmCharger->gun_info[gun_index].primaryMcuState.cp_state;
 					ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PilotDuty = (ShmCharger->gun_info[gun_index].primaryMcuState.current_limit>51?(unsigned char)((ShmCharger->gun_info[gun_index].primaryMcuState.current_limit/2.5)+64):(unsigned char)(ShmCharger->gun_info[gun_index].primaryMcuState.current_limit/0.6));
@@ -1800,26 +1849,30 @@ int main(void)
 					// Byte[9]
 					//================================================
 					// Debug print out
-					DEBUG_INFO("MCU-%d get OVP : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.OVP);
-					DEBUG_INFO("MCU-%d get UVP : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.UVP);
-					DEBUG_INFO("MCU-%d get OCP : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.OCP);
-					DEBUG_INFO("MCU-%d get OTP : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.OTP);
-					DEBUG_INFO("MCU-%d get gmi_fault : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.gmi_fault);
-					DEBUG_INFO("MCU-%d get cp_fault : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.cp_fault);
-					DEBUG_INFO("MCU-%d get ac_leak : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.ac_leak);
-					DEBUG_INFO("MCU-%d get dc_leak : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.dc_leak);
-					DEBUG_INFO("MCU-%d get mcu_selftest_fail : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.mcu_selftest_fail);
-					DEBUG_INFO("MCU-%d get handshaking_timeout : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.handshaking_timeout);
-					DEBUG_INFO("MCU-%d get emergency_stop : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.emergency_stop);
-					DEBUG_INFO("MCU-%d get relay_welding : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.relay_welding);
-					DEBUG_INFO("MCU-%d get leak_module_fail : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.leak_module_fail);
-					DEBUG_INFO("MCU-%d get shutter_fault : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.shutter_fault);
-					DEBUG_INFO("MCU-%d get locker_fault : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.locker_fault);
-					DEBUG_INFO("MCU-%d get power_drop : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.power_drop);
-					DEBUG_INFO("MCU-%d get circuit_short : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.circuit_short);
-					DEBUG_INFO("MCU-%d get set_circuit : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.set_circuit);
-					DEBUG_INFO("MCU-%d get relay_drive_fault : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.relay_drive_fault);
-					DEBUG_INFO("MCU-%d get InputAlarmCode : %x\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode);
+
+					if(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PreviousSystemStatus != ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].SystemStatus)
+					{
+						DEBUG_INFO("MCU-%d get OVP : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.OVP);
+						DEBUG_INFO("MCU-%d get UVP : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.UVP);
+						DEBUG_INFO("MCU-%d get OCP : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.OCP);
+						DEBUG_INFO("MCU-%d get OTP : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.OTP);
+						DEBUG_INFO("MCU-%d get gmi_fault : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.gmi_fault);
+						DEBUG_INFO("MCU-%d get cp_fault : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.cp_fault);
+						DEBUG_INFO("MCU-%d get ac_leak : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.ac_leak);
+						DEBUG_INFO("MCU-%d get dc_leak : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.dc_leak);
+						DEBUG_INFO("MCU-%d get mcu_selftest_fail : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.mcu_selftest_fail);
+						DEBUG_INFO("MCU-%d get handshaking_timeout : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.handshaking_timeout);
+						DEBUG_INFO("MCU-%d get emergency_stop : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.emergency_stop);
+						DEBUG_INFO("MCU-%d get relay_welding : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.relay_welding);
+						DEBUG_INFO("MCU-%d get leak_module_fail : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.leak_module_fail);
+						DEBUG_INFO("MCU-%d get shutter_fault : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.shutter_fault);
+						DEBUG_INFO("MCU-%d get locker_fault : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.locker_fault);
+						DEBUG_INFO("MCU-%d get power_drop : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.power_drop);
+						DEBUG_INFO("MCU-%d get circuit_short : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.circuit_short);
+						DEBUG_INFO("MCU-%d get set_circuit : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.set_circuit);
+						DEBUG_INFO("MCU-%d get relay_drive_fault : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.relay_drive_fault);
+						DEBUG_INFO("MCU-%d get InputAlarmCode : %x\r\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode);
+					}
 
 					failCount[gun_index] = 0;
 				}
@@ -1832,7 +1885,25 @@ int main(void)
 					}
 				}
 
+				//===============================
+				// Config primary MCU reset request
+				//===============================
+				/*
+				if(Config_AC_MCU_RESET_REQUEST(Uart1Fd, (gun_index>0?ADDR_AC_PRIMARY_2:ADDR_AC_PRIMARY_1), &ShmCharger->gun_info[gun_index].mcuResetRequest))
+				{
+					DEBUG_INFO("MCU-%d set MCU reset Request : %d\r\n", gun_index, ShmCharger->gun_info[gun_index].mcuResetRequest.isMcuResetRequest);
 
+					failCount[gun_index] = 0;
+				}
+				else
+				{
+					DEBUG_WARN("MCU-%d get MCU reset fail...%d\r\n", gun_index, failCount[gun_index]);
+					if(failCount[gun_index]<1000)
+					{
+						failCount[gun_index]++;
+					}
+				}
+				*/
 			}
 			else
 			{

+ 3 - 2
EVSE/Projects/AW-Regular/Apps/Module_InternalComm.h

@@ -1,7 +1,7 @@
 /*
  * Module_InternalComm.h
  *
- *  Created on: 2019年8月28日
+ *  Created on: 2020¦~01¤ë15¤é
  *      Author: USER
  */
 
@@ -34,6 +34,7 @@ enum MESSAGE_COMMAND
 	CMD_QUERY_BLE_CONFIG_DATA = 0x2A,
 	CMD_QUERY_BLE_CENTRAL_ID = 0x2B,
 	CMD_QUERY_POWER_CONSUMPTION = 0x2C,
+	CMD_QUERY_GUN_PLUGIN_TIMES = 0x2D,
 
 	CMD_CONFIG_FAN_SPEED = 0x81,
 	CMD_CONFIG_SERIAL_NUMBER = 0x82,
@@ -44,7 +45,7 @@ enum MESSAGE_COMMAND
 	CMD_CONFIG_AC_LED = 0x88,
 	CMD_CONFIG_CURRENT_LINIT = 0x89,
 	CMD_CONFIG_MCU_MODE = 0x8A,
-	CMD_CONFIG_GUN_PLUGIN_TIMES = 0x2D,
+	CMD_CONFIG_MCU_RESET_REQUEST = 0x8C,
 
 	CMD_UPDATE_START = 0xe0,
 	CMD_UPDATE_ABOARD = 0xe1,

+ 4 - 2
EVSE/Projects/AW-Regular/Apps/Module_Speaker.c

@@ -1,8 +1,8 @@
 /*
  * Module_Speaker.c
  *
- *  Created on: 2019¦~12¤ë23¤é
- *      Author: USER
+ *  Created on: 2020¦~01¤ë15¤é
+ *      Author: Eason Yang
  */
 
 #include 	<sys/time.h>
@@ -280,6 +280,8 @@ int main(void)
 					break;
 			}
 		}
+		else
+			usleep(100000);
 	}
 }
 

Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 395 - 200
EVSE/Projects/AW-Regular/Apps/main.c


+ 16 - 43
EVSE/Projects/AW-Regular/Apps/main.h

@@ -1,8 +1,8 @@
 /*
  * Config.h
  *
- *  Created on: 2019年12月25日
- *      Author: EasonYang
+ *  Created on: 2020年01月15日
+ *      Author: Eason Yang
  */
 
 #ifndef CONFIG_MAIN_H_
@@ -40,21 +40,6 @@
 #include	<stddef.h>
 #include	<stdint.h>
 
-//==========================
-//	Define system mode constant
-//==========================
-#define MODE_BOOTING				0
-#define MODE_IDLE					1
-#define MODE_AUTHORIZING			2
-#define MODE_PREPARING				3
-#define MODE_CHARGING				4
-#define MODE_TERMINATING			5
-#define MODE_ALARM					6
-#define MODE_FAULT					7
-#define MODE_RESERVATION			8
-#define MODE_BOOKING				9
-#define MODE_MAINTAIN				10
-#define MODE_DEBUG					11
 
 //===================================
 //	Define CP State constant
@@ -70,7 +55,7 @@
 //===================================
 // Define start mode constant
 //===================================
-#define START_METHOD_MANUAL 		0
+#define START_METHOD_FREE	 		0
 #define START_METHOD_RFID	 		1
 #define START_METHOD_BACKEND 		2
 #define START_METHOD_BLE	 		3
@@ -100,12 +85,12 @@
 #define ALARM_MCU_TESTFAIL          0x000100
 #define ALARM_HANDSHAKE_TIMEOUT     0x000200
 #define ALARM_EMERGENCY_STOP        0x000400
-#define ALARM_RELAY_STATUS          0x000800
+#define ALARM_RELAY_WELDING         0x000800
 #define ALARM_LEAK_MODULE_FAIL      0x001000
 #define ALARM_SHUTTER_FAULT         0x002000
 #define ALARM_LOCKER_FAULT          0x004000
 #define ALARM_POWER_DROP            0x008000
-#define ALARM_CIRCUIT_SHORT         0x010000
+#define ALARM_CURRENT_SHORT         0x010000
 #define ALARM_ROTATORY_SWITCH_FAULT 0x020000
 #define ALARM_RELAY_DRIVE_FAULT     0x040000
 
@@ -129,21 +114,8 @@
 #define LED_RELAY_ON               	 	14
 #define LED_RELAY_OFF               	15
 #define LED_ACTION_HANDSHAKE_FAIL   	16
+#define LED_ACTION_INTERNET_DISCONNECT	17
 
-#define START_METHOD_MANUAL 			0
-#define START_METHOD_RFID	 			1
-#define START_METHOD_BACKEND 			2
-#define START_METHOD_BLE	 			3
-
-#define AUTH_MODE_PH_RFID				0
-#define AUTH_MODE_OCPP					1
-#define AUTH_MODE_PH_BACKEND			2
-#define AUTH_MODE_FREEMODE				3
-
-#define OFF_POLICY_LOCALLIST			0
-#define OFF_POLICY_PH_RFID				1
-#define OFF_POLICY_FREEMODE				2
-#define OFF_POLICY_NOCHARGE				3
 
 #define DEBUG_INFO(format, args...) StoreLogMsg("[%s:%d][%s][Info] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
 #define DEBUG_WARN(format, args...) StoreLogMsg("[%s:%d][%s][Warn] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
@@ -353,9 +325,9 @@ typedef struct OTHER_ALARM_CODE
 	unsigned char isMcuSelfTest:1;
 	unsigned char isCurrentShort:1;
 	unsigned char isLeakageModule:1;
-	unsigned char isShutter:1;
-	unsigned char isLocker:1;
-	unsigned char isRotatorySwitchr:1;
+	unsigned char isShutterFail:1;
+	unsigned char isLockerFault:1;
+	unsigned char isRotatorySwitch:1;
 	unsigned char isPowerDrop:1;
 	unsigned char isOverCurrent:1;
 	unsigned char isHandshakingTimeOut:1;
@@ -382,11 +354,10 @@ typedef struct GUN_PLUGIN_TIMES
 
 }Gun_Plugin_Times;
 
-typedef struct INTERNAL_SYSTEM_STATUS
+typedef struct MCU_RESET_REQUEST
 {
-	unsigned char SystemStatus;
-	unsigned char PreviousSystemStatus;
-}Internal_Sysyem_status;
+	unsigned char isMcuResetRequest:1;
+}Mcu_Reset_Request;
 
 typedef struct GUN_INFO
 {
@@ -408,7 +379,8 @@ typedef struct GUN_INFO
 	Other_Alarm_Code								otherAlarmCode;
 	Pilot_Voltage									PilotVoltage;
 	Gun_Plugin_Times								gunPluginTimes;
-	Internal_Sysyem_status							internalSystemStatus;
+	Mcu_Reset_Request								mcuResetRequest;
+	uint8_t											isAuthPassEnd:1;
 }Gun_Info;
 
 struct Charger
@@ -417,9 +389,10 @@ struct Charger
 	Evse_Id					evseId;
 	Gun_Info 				gun_info[2];
 	Fw_Upgrade_Info			fwUpgradeInfo;
-	unsigned char			rfidReq:1;
+	
 
 	unsigned char 			speaker_type;
+	unsigned char			rfidReq:1;
 	unsigned char			isSpeakerOn:1;
 };
 

BIN
EVSE/Projects/AW-Regular/Images/FactoryDefaultConfig.bin


BIN
EVSE/Projects/AW-Regular/Images/ramdisk.gz


BIN
EVSE/rootfs/root/Module_4g


BIN
EVSE/rootfs/root/Module_Wifi


BIN
EVSE/rootfs/root/OcppBackend


BIN
EVSE/rootfs/root/WebService


BIN
EVSE/rootfs/root/logPackTools


Daži faili netika attēloti, jo izmaiņu fails ir pārāk liels