/*
 * 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>
#include    <fcntl.h>
#include    <termios.h>
#include    <errno.h>
#include 	<errno.h>
#include 	<string.h>
#include	<time.h>
#include	<ctype.h>
#include	"define.h"
#include	"main.h"
#include	"Module_AlarmDetect.h"

#define FILTER_SPEC			2

#define DEBUG_INFO(format, args...) StoreLogMsg("[%s:%d][%s][Info] "format, (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__), __LINE__, __FUNCTION__, ##args)
#define DEBUG_WARN(format, args...) StoreLogMsg("[%s:%d][%s][Warn] "format, (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__), __LINE__, __FUNCTION__, ##args)
#define DEBUG_ERROR(format, args...) StoreLogMsg("[%s:%d][%s][Error] "format, (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __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

#define ALARM_OC_RETRY_COUNT 		4
#define FILTER_SPEC_FOR_CCS			60	// 6 seconds		
#define	TIMEOUT_SPEC_OC_RECOVER 	60

//#define isDebugPrint

struct{
	unsigned short int	OV[3];
	unsigned short int	UV[3];
	unsigned short int	OC[3];
	unsigned short int	OT_AMB;
	unsigned short int	GMI;
	unsigned short int	Short[3];
	unsigned short int	Leakage;
	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;
	unsigned short int	OC_Retry[3];
}Alarm_Counter[2];

struct{
	uint16_t OC_BegThreshold; 	// OCP過電流門檻值 	單位0.01A	ex: 48 * 110 = 5280 (52.80A)
	uint16_t OC_EndThreshold;	// OCP過電流門檻值 	單位0.01A	ex: 48 * 110 = 5280 (52.80A)
}Over_Current[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 OCPP20Data				*ShmOCPP20Data;
struct Charger					*ShmCharger;
unsigned long					previousAlarmCode[AC_QUANTITY];
uint32_t OCP_Magnification = 0;		// Magnification

struct timespec					startTime[TMR_IDX_CNT];

int StoreLogMsg(const char *fmt, ...)
{
	char Buf[4096+256];
	char buffer[4096];
	time_t CurrentTime;
	struct tm *tm;
	struct timeval tv;
	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);
	gettimeofday(&tv, NULL); // get microseconds, 10^-6

	if((ShmSysConfigAndInfo->SysConfig.ModelName != NULL) && (ShmSysConfigAndInfo->SysConfig.SerialNumber != NULL) && (strlen((char*)ShmSysConfigAndInfo->SysConfig.ModelName) >= 14))
	{
		sprintf(Buf,"echo -n \"[%04d.%02d.%02d %02d:%02d:%02d.%06ld]%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,tv.tv_usec,
					buffer,
					tm->tm_year+1900,tm->tm_mon+1,
					ShmSysConfigAndInfo->SysConfig.ModelName,
					ShmSysConfigAndInfo->SysConfig.SerialNumber);
	}
	else
	{
		sprintf(Buf,"echo -n \"[%04d.%02d.%02d %02d:%02d:%02d.%06ld]%s\" >> /Storage/SystemLog/[%04d.%02d]SystemLog",
					tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,tv.tv_usec,
					buffer,
					tm->tm_year+1900,tm->tm_mon+1);
	}

#ifdef SystemLogMessage
	system(Buf);
#endif

#ifdef ConsloePrintLog
	printf("[%04d.%02d.%02d %02d:%02d:%02d.%06ld]%s", tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,tv.tv_usec, buffer);
#endif

	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;
}

void refreshStartTimer(struct timespec *timer)
{
	clock_gettime(CLOCK_MONOTONIC, timer);
}

int getDiffSecNow(struct timespec timer)
{
	struct timespec timerNow;

	clock_gettime(CLOCK_MONOTONIC, &timerNow);

	return (int)((((unsigned long)(timerNow.tv_sec - timer.tv_sec) * 1000) + ((unsigned long)((timerNow.tv_nsec / 1000000) - (timer.tv_nsec / 1000000))))/1000);
}

//==========================================
// 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\n");

		result = FAIL;
	}
	else if ((ShmCharger = shmat(MeterSMId, NULL, 0)) == (void *) -1)
	{

		DEBUG_ERROR("shmat ShmCharger NG\n");

		result = FAIL;
	}
	else
	{}

   	//creat ShmOCPP16Data
	if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
	{

		DEBUG_ERROR("shmget ShmOCPP16Data NG\n");

		result = FAIL;
	}
	else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
	{

		DEBUG_ERROR("shmat ShmOCPP16Data NG\n");

		result = FAIL;
	}
	else
	{}

   	//creat ShmOCPP20Data
   	if ((MeterSMId = shmget(ShmOcpp20ModuleKey, sizeof(struct OCPP20Data),  0777)) < 0)
	{
		DEBUG_ERROR("shmget ShmOCPP20Data NG\n");
		result = FAIL;
	}
	else if ((ShmOCPP20Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
	{
		DEBUG_ERROR("shmat ShmOCPP20Data NG\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;
}

void getNowDatetime(uint8_t *data)
{
	time_t t = time(NULL);
	struct tm tm = *localtime(&t);

	sprintf((char*)data, "%04d-%02d-%02dT%02d:%02d:%02dZ", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);
}

int qca7000FlashCheck()
{
	int result = FAIL;
	char buf[256];
	FILE *fp;

	fp = popen("/usr/bin/plcID", "r");
	if(fp != NULL)
	{
		while(fgets(buf, sizeof(buf), fp) != NULL)
		{
			if(strlen(buf) >= 10)result = PASS;
		}
	}
	pclose(fp);

	return result;
}

void ccsOverCurrentProtection(uint8_t gun_index)
{	
	if((ShmSysConfigAndInfo->SysConfig.ModelName[3] == 'E') ||
	   (ShmSysConfigAndInfo->SysConfig.ModelName[3] == 'T') ||
	   (ShmSysConfigAndInfo->SysConfig.ModelName[3] == 'Z'))
	{
		Over_Current[gun_index].OC_BegThreshold = (ShmCharger->gun_info[gun_index].targetCurrent * OCP_Magnification) - 100;
		Over_Current[gun_index].OC_EndThreshold = (ShmCharger->gun_info[gun_index].targetCurrent * OCP_Magnification) - 200;
	}
	else
	{
		if(ShmCharger->gun_info[gun_index].targetCurrent > 20)
		{
			Over_Current[gun_index].OC_BegThreshold = (ShmCharger->gun_info[gun_index].targetCurrent * OCP_Magnification) + 0;
			Over_Current[gun_index].OC_EndThreshold = (ShmCharger->gun_info[gun_index].targetCurrent * OCP_Magnification) - 200;
		}
		else
		{
			Over_Current[gun_index].OC_BegThreshold = (ShmCharger->gun_info[gun_index].targetCurrent * 100) + 200;
			Over_Current[gun_index].OC_EndThreshold = (ShmCharger->gun_info[gun_index].targetCurrent * 100) + 0;
		}
	}
	
	#ifdef isDebugPrint
	DEBUG_INFO("Gun-[%d] OC_BegThreshold: %d \n", gun_index, Over_Current[gun_index].OC_BegThreshold);
	DEBUG_INFO("Gun-[%d] OC_EndThreshold: %d \n", gun_index, Over_Current[gun_index].OC_EndThreshold);
	#endif
}
	

//==========================================
// Main process
//==========================================
int main(void)
{
	uint8_t isCheckQca7000[AC_QUANTITY] = {0};

	if(InitShareMemory() == FAIL)
	{
		DEBUG_ERROR("InitShareMemory NG\n");

		if(ShmStatusCodeData!=NULL)
		{
			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
		}
		sleep(5);
		return FAIL;
	}
	
	if((ShmSysConfigAndInfo->SysConfig.ModelName[3] == 'E') ||
	   (ShmSysConfigAndInfo->SysConfig.ModelName[3] == 'T') ||
	   (ShmSysConfigAndInfo->SysConfig.ModelName[3] == 'Z'))
	{
		// Europe
		OCP_Magnification = 125;
	}
	else
	{
		// Other
		OCP_Magnification = 110;
	}
	
	DEBUG_INFO("OCP_Magnification: %d/100 => %.2f \n", OCP_Magnification,(float)(OCP_Magnification/100.0));

	for(;;)
	{
		for(int gun_index = 0;gun_index<AC_QUANTITY;gun_index++)
		{
			//=====================================
			// Over voltage detection
			//=====================================
			if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.OVP_L1 == ON)
			{
				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_L1_OVER_VOLTAGE;
						DEBUG_INFO("ALARM_L1_OVER_VOLTAGE : alarm \n");
					}
				}
				else
				{
					Alarm_Counter[gun_index].OV[0]++;
				}
			}
			else
			{
				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_L1_OVER_VOLTAGE;
					DEBUG_INFO("ALARM_L1_OVER_VOLTAGE : recover \n");
				}
			}

			if(ShmSysConfigAndInfo->SysConfig.AcPhaseCount == 3)
			{
				if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.OVP_L2 == ON)
				{
					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_L2_OVER_VOLTAGE;
							DEBUG_INFO("ALARM_L2_OVER_VOLTAGE : alarm \n");
						}
					}
					else
					{
						Alarm_Counter[gun_index].OV[1]++;
					}
				}
				else
				{
					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_L2_OVER_VOLTAGE;
						DEBUG_INFO("ALARM_L2_OVER_VOLTAGE : recover \n");
					}
				}

				if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.OVP_L3 == ON)
				{
					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_L3_OVER_VOLTAGE;
							DEBUG_INFO("ALARM_L3_OVER_VOLTAGE : alarm \n");
						}
					}
					else
					{
						Alarm_Counter[gun_index].OV[2]++;
					}
				}
				else
				{
					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_L3_OVER_VOLTAGE;
						DEBUG_INFO("ALARM_L3_OVER_VOLTAGE : recover \n");
					}
				}
			}

			//=====================================
			// Under voltage detection
			//=====================================
			if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.UVP_L1 == ON)
			{
				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_L1_UNDER_VOLTAGE;
						DEBUG_INFO("ALARM_L1_UNDER_VOLTAGE : alarm \n");
					}
				}
				else
				{
					Alarm_Counter[gun_index].UV[0]++;
				}
			}
			else
			{
				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_L1_UNDER_VOLTAGE;
					DEBUG_INFO("ALARM_L1_UNDER_VOLTAGE : recover \n");
				}
			}

			if(ShmSysConfigAndInfo->SysConfig.AcPhaseCount == 3)
			{
				if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.UVP_L2 == ON)
				{
					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_L2_UNDER_VOLTAGE;
							DEBUG_INFO("ALARM_L2_UNDER_VOLTAGE : alarm \n");
						}
					}
					else
					{
						Alarm_Counter[gun_index].UV[1]++;
					}
				}
				else
				{
					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_L2_UNDER_VOLTAGE;
						DEBUG_INFO("ALARM_L2_UNDER_VOLTAGE : recover \n");
					}
				}

				if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.UVP_L3 == ON)
				{
					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_L3_UNDER_VOLTAGE;
							DEBUG_INFO("ALARM_L3_UNDER_VOLTAGE : alarm \n");
						}
					}
					else
					{
						Alarm_Counter[gun_index].UV[2]++;
					}
				}
				else
				{
					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_L3_UNDER_VOLTAGE;
						DEBUG_INFO("ALARM_L3_UNDER_VOLTAGE : recover \n");
					}
				}			
			}

			//=====================================
			// Over current detection
			//=====================================
			ccsOverCurrentProtection(gun_index);
			if((ShmCharger->gun_info[gun_index].chargingMode == CHARGING_MODE_HLC?((uint16_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargingCurrent*100.0) > Over_Current[gun_index].OC_BegThreshold):(ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.OCP_L1 == ON)))
			{
				if((ShmCharger->gun_info[gun_index].chargingMode == CHARGING_MODE_HLC?(Alarm_Counter[gun_index].OC[0] > FILTER_SPEC_FOR_CCS):(Alarm_Counter[gun_index].OC[0] > FILTER_SPEC)))
				{
					if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAcOutputOCP == OFF)
					{
						refreshStartTimer(&startTime[ALARM_TMR_IDX_OCP_L1]);
						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAcOutputOCP = ON;
						ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_L1_OVER_CURRENT;
						
						if(ShmCharger->gun_info[gun_index].chargingMode == CHARGING_MODE_HLC)
						{
							Alarm_Counter[gun_index].OC_Retry[0]++;
							
							DEBUG_INFO("Gun-[%d] PresentChargingCurrent: %d \n", gun_index, (uint16_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargingCurrent*100.0));
							DEBUG_INFO("Gun-[%d] OC_BegThreshold: %d \n", gun_index, Over_Current[gun_index].OC_BegThreshold);
							DEBUG_INFO("Gun-[%d] OC_Retry[0]: %d \n", gun_index, Alarm_Counter[gun_index].OC_Retry[0]);
							//DEBUG_INFO("Gun-[%d] OC_Connter[0]: %d \n", gun_index, Alarm_Counter[gun_index].OC[0]);
						}
						else
						{
							Alarm_Counter[gun_index].OC_Retry[0] = 0;
						}
						
						DEBUG_INFO("ALARM_L1_OVER_CURRENT : alarm \n");
					}
				}
				else
				{
					Alarm_Counter[gun_index].OC[0]++;
				}
			}
			else if((ShmCharger->gun_info[gun_index].chargingMode == CHARGING_MODE_HLC?((uint16_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargingCurrent*100.0) < Over_Current[gun_index].OC_EndThreshold):(ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.OCP_L1 == OFF)))
			{
				Alarm_Counter[gun_index].OC[0] = 0;
				if(ShmCharger->gun_info[gun_index].chargingMode == CHARGING_MODE_HLC)
				{
					if((Alarm_Counter[gun_index].OC_Retry[0] <= ALARM_OC_RETRY_COUNT) && (getDiffSecNow(startTime[ALARM_TMR_IDX_OCP_L1]) >= TIMEOUT_SPEC_OC_RECOVER))
					{
						if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAcOutputOCP == ON)
						{
							ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAcOutputOCP = OFF;
							ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_L1_OVER_CURRENT;
							DEBUG_INFO("ALARM_L1_OVER_CURRENT : Automatically recover \n");
						}
					}
					else
					{
						if(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PilotState == CP_STATE_A)
						{
							Alarm_Counter[gun_index].OC_Retry[0] = 0;
							refreshStartTimer(&startTime[ALARM_TMR_IDX_OCP_L1]);
							if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAcOutputOCP == ON)
							{
								ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAcOutputOCP = OFF;
								ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_L1_OVER_CURRENT;
								DEBUG_INFO("ALARM_L1_OVER_CURRENT : Latched and recover by unplugging the gun  \n");
							}
						}
					}
				}
				else
				{
					if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAcOutputOCP == ON)
					{
						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAcOutputOCP = OFF;
						ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_L1_OVER_CURRENT;
						DEBUG_INFO("ALARM_L1_OVER_CURRENT : recover \n");
					}
				}
			}

			if(ShmSysConfigAndInfo->SysConfig.AcPhaseCount == 3)
			{
				if((ShmCharger->gun_info[gun_index].chargingMode == CHARGING_MODE_HLC?((uint16_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargingCurrentL2*100.0) > Over_Current[gun_index].OC_BegThreshold):(ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.OCP_L2 == ON)))
				{
					if((ShmCharger->gun_info[gun_index].chargingMode == CHARGING_MODE_HLC?(Alarm_Counter[gun_index].OC[1] > FILTER_SPEC_FOR_CCS):(Alarm_Counter[gun_index].OC[1] > FILTER_SPEC)))
					{
						if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAcOutputOCPL2 == OFF)
						{
							refreshStartTimer(&startTime[ALARM_TMR_IDX_OCP_L2]);
							ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAcOutputOCPL2 = ON;
							ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_L2_OVER_CURRENT;
							
							if(ShmCharger->gun_info[gun_index].chargingMode == CHARGING_MODE_HLC)
							{
								Alarm_Counter[gun_index].OC_Retry[1]++;
								
								DEBUG_INFO("Gun-[%d] PresentChargingCurrentL2: %d \n", gun_index, (uint16_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargingCurrentL2*100.0));
								DEBUG_INFO("Gun-[%d] OC_BegThreshold: %d \n", gun_index, Over_Current[gun_index].OC_BegThreshold);
								DEBUG_INFO("Gun-[%d] OC_Retry[1]: %d \n", gun_index, Alarm_Counter[gun_index].OC_Retry[1]);
								//DEBUG_INFO("Gun-[%d] OC_Connter[1]: %d \n", gun_index, Alarm_Counter[gun_index].OC[1]);
							}
							else
							{
								Alarm_Counter[gun_index].OC_Retry[1] = 0;
							}
							
							DEBUG_INFO("ALARM_L2_OVER_CURRENT : alarm \n");
						}
					}
					else
					{
						Alarm_Counter[gun_index].OC[1]++;
					}
					
				}
				else if((ShmCharger->gun_info[gun_index].chargingMode == CHARGING_MODE_HLC?((uint16_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargingCurrentL2*100.0) < Over_Current[gun_index].OC_EndThreshold):(ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.OCP_L2 == OFF)))
				{
					Alarm_Counter[gun_index].OC[1] = 0;
					if(ShmCharger->gun_info[gun_index].chargingMode == CHARGING_MODE_HLC)
					{
						if((Alarm_Counter[gun_index].OC_Retry[1] <= ALARM_OC_RETRY_COUNT) && (getDiffSecNow(startTime[ALARM_TMR_IDX_OCP_L2]) >= TIMEOUT_SPEC_OC_RECOVER))
						{
							if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAcOutputOCPL2 == ON)
							{
								ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAcOutputOCPL2 = OFF;
								ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_L2_OVER_CURRENT;
								DEBUG_INFO("ALARM_L2_OVER_CURRENT : Automatically recover \n");
							}
						}
						else
						{
							if(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PilotState == CP_STATE_A)
							{
								Alarm_Counter[gun_index].OC_Retry[1] = 0;
								refreshStartTimer(&startTime[ALARM_TMR_IDX_OCP_L2]);
								if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAcOutputOCPL2 == ON)
								{
									ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAcOutputOCPL2 = OFF;
									ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_L2_OVER_CURRENT;
									DEBUG_INFO("ALARM_L2_OVER_CURRENT : Latched and recover by unplugging the gun \n");
								}
							}
						}
					}
					else
					{
						if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAcOutputOCPL2 == ON)
						{
							ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAcOutputOCPL2 = OFF;
							ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_L2_OVER_CURRENT;
							DEBUG_INFO("ALARM_L2_OVER_CURRENT : recover \n");
						}
					}
				}

				if((ShmCharger->gun_info[gun_index].chargingMode == CHARGING_MODE_HLC?((uint16_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargingCurrentL3*100.0) > Over_Current[gun_index].OC_BegThreshold):(ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.OCP_L3 == ON)))
				{
					if((ShmCharger->gun_info[gun_index].chargingMode == CHARGING_MODE_HLC?(Alarm_Counter[gun_index].OC[2] > FILTER_SPEC_FOR_CCS):(Alarm_Counter[gun_index].OC[2] > FILTER_SPEC)))
					{
						if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAcOutputOCPL3 == OFF)
						{
							refreshStartTimer(&startTime[ALARM_TMR_IDX_OCP_L3]);
							ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAcOutputOCPL3 = ON;
							ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_L3_OVER_CURRENT;
							
							if(ShmCharger->gun_info[gun_index].chargingMode == CHARGING_MODE_HLC)
							{
								Alarm_Counter[gun_index].OC_Retry[2]++;
								
								DEBUG_INFO("Gun-[%d] PresentChargingCurrentL3: %d \n", gun_index, (uint16_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargingCurrentL3*100.0));
								DEBUG_INFO("Gun-[%d] OC_BegThreshold: %d \n", gun_index, Over_Current[gun_index].OC_BegThreshold);
								DEBUG_INFO("Gun-[%d] OC_Retry[2]: %d \n", gun_index, Alarm_Counter[gun_index].OC_Retry[2]);
								//DEBUG_INFO("Gun-[%d] OC_Connter[2]: %d \n", gun_index, Alarm_Counter[gun_index].OC[2]);
							}
							else
							{
								Alarm_Counter[gun_index].OC_Retry[2] = 0;
							}

							DEBUG_INFO("ALARM_L3_OVER_CURRENT : alarm \n");
						}
					}
					else
					{
						Alarm_Counter[gun_index].OC[2]++;
					}
				}
				else if((ShmCharger->gun_info[gun_index].chargingMode == CHARGING_MODE_HLC?((uint16_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargingCurrentL3*100.0) < Over_Current[gun_index].OC_EndThreshold):(ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.OCP_L3 == OFF)))
				{
					Alarm_Counter[gun_index].OC[2] = 0;
					if(ShmCharger->gun_info[gun_index].chargingMode == CHARGING_MODE_HLC)
					{
						if((Alarm_Counter[gun_index].OC_Retry[2] <= ALARM_OC_RETRY_COUNT) && (getDiffSecNow(startTime[ALARM_TMR_IDX_OCP_L3]) >= TIMEOUT_SPEC_OC_RECOVER))
						{
							if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAcOutputOCPL3 == ON)
							{
								ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAcOutputOCPL3 = OFF;
								ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_L3_OVER_CURRENT;
								DEBUG_INFO("ALARM_L3_OVER_CURRENT : Automatically recover \n");
							}	
						}
						else
						{
							if(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PilotState == CP_STATE_A)
							{
								Alarm_Counter[gun_index].OC_Retry[2] = 0;
								refreshStartTimer(&startTime[ALARM_TMR_IDX_OCP_L3]);
								if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAcOutputOCPL3 == ON)
								{
									ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAcOutputOCPL3 = OFF;
									ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_L3_OVER_CURRENT;
									DEBUG_INFO("ALARM_L3_OVER_CURRENT : Latched and recover by unplugging the gun \n");
								}
							}
						}
					}
					else
					{
						if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAcOutputOCPL3 == ON)
						{
							ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAcOutputOCPL3 = OFF;
							ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_L3_OVER_CURRENT;
							DEBUG_INFO("ALARM_L3_OVER_CURRENT : recover \n");
						}
					}
				}
			}

			//=====================================
			// Over temperature detection
			//=====================================
			if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.OTP == ON)
			{
				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 \n");
					}
				}
				else
				{
					Alarm_Counter[gun_index].OT_AMB++;
				}
			}
			else
			{
				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 \n");
				}
			}

			//=====================================
			// Ground fault detection
			//=====================================
			if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.gmi_fault == ON)
			{
				if(Alarm_Counter[gun_index].GMI > FILTER_SPEC)
				{
					if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.AcGroundfaultFail == OFF)
					{
						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.AcGroundfaultFail = ON;
						ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_GROUND_FAIL;
						DEBUG_INFO("ALARM_GROUND_FAIL : alarm \n");
					}
				}
				else
				{
					Alarm_Counter[gun_index].GMI++;
				}
			}
			else
			{
				Alarm_Counter[gun_index].GMI = 0;
				if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.AcGroundfaultFail == ON)
				{
					ShmStatusCodeData->AlarmCode.AlarmEvents.bits.AcGroundfaultFail = OFF;
					ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_GROUND_FAIL;
					DEBUG_INFO("ALARM_GROUND_FAIL : recover \n");
				}
			}

			//=====================================
			// CP level fail detection
			//=====================================
			if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.cp_fault == ON)
			{
				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 \n");
					}
				}
				else
				{
					Alarm_Counter[gun_index].CP_LevelFail++;
				}
			}
			else
			{
				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 \n");
				}
			}

			//=====================================
			// Current AC/DC leak detection
			//=====================================
			if((ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.ac_leak == ON) ||
			   (ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.dc_leak == ON))
			{
				if(Alarm_Counter[gun_index].Leakage > FILTER_SPEC)
				{
					if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.RcdTrip == OFF)
					{
						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.RcdTrip = ON;
						if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.ac_leak == ON)
						{
							ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_CURRENT_LEAK_AC;
							ShmCharger->gun_info[gun_index].otherAlarmCode.isACLeakage = ON;
							DEBUG_INFO("ALARM_CURRENT_LEAK_AC : alarm \n");
						}
						else if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.dc_leak == ON)
						{
							ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_CURRENT_LEAK_DC;
							ShmCharger->gun_info[gun_index].otherAlarmCode.isDcLeakage = ON;
							DEBUG_INFO("ALARM_CURRENT_LEAK_DC : alarm \n");
						}
					}
				}
				else
				{
					Alarm_Counter[gun_index].Leakage++;
				}
			}
			else
			{
				Alarm_Counter[gun_index].Leakage = 0;
				if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.RcdTrip == ON)
				{
					ShmStatusCodeData->AlarmCode.AlarmEvents.bits.RcdTrip = OFF;
					if(ShmCharger->gun_info[gun_index].otherAlarmCode.isACLeakage == ON)
					{
						ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_CURRENT_LEAK_AC;
						ShmCharger->gun_info[gun_index].otherAlarmCode.isACLeakage = OFF;
						DEBUG_INFO("ALARM_CURRENT_LEAK_AC : recover \n");
					}
					else if(ShmCharger->gun_info[gun_index].otherAlarmCode.isDcLeakage == ON)
					{
						ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_CURRENT_LEAK_DC;
						ShmCharger->gun_info[gun_index].otherAlarmCode.isDcLeakage = OFF;
						DEBUG_INFO("ALARM_CURRENT_LEAK_DC : recover \n");
					}
				}
			}

			//=====================================
			// MCU self test fail detection
			//=====================================
			if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.mcu_selftest_fail == ON)
			{
				if(Alarm_Counter[gun_index].MCU_SelfTestFail > FILTER_SPEC)
				{
					if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.McuSelftestFail == OFF)
					{
						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.McuSelftestFail = ON;
						ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_MCU_TESTFAIL;
						DEBUG_INFO("ALARM_MCU_TESTFAIL : alarm \n");
					}
				}
				else
				{
					Alarm_Counter[gun_index].MCU_SelfTestFail++;
				}
			}
			else
			{
				Alarm_Counter[gun_index].MCU_SelfTestFail = 0;
				if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.McuSelftestFail == ON)
				{
					ShmStatusCodeData->AlarmCode.AlarmEvents.bits.McuSelftestFail = OFF;
					ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_MCU_TESTFAIL;
					DEBUG_INFO("ALARM_MCU_TESTFAIL : recover \n");
				}
			}

			//=====================================
			// Hand shaking timeout detection
			//=====================================
			if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.handshaking_timeout == ON)
			{
				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 \n");
				}

			}
			else
			{
				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 \n");
				}
			}

			//=====================================
			// Emergency stop detection
			//=====================================
			if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.emergency_stop == ON)
			{
				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 \n");
					}
				}
				else
				{
					Alarm_Counter[gun_index].EmrgencyBTN++;
				}
			}
			else
			{
				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 \n");
				}
			}

			//=====================================
			// Relay welding detection
			//=====================================
			if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.relay_welding == ON)
			{
				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 \n");
					}
				}
				else
				{
					Alarm_Counter[gun_index].Relay_Welding++;
				}
			}
			else
			{
				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 \n");
				}
			}

			//=====================================
			// Relay driving fault detection
			//=====================================
			if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.relay_drive_fault == ON)
			{
				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 \n");
					}
				}
				else
				{
					Alarm_Counter[gun_index].Relay_DrivingFault++;
				}
			}
			else
			{
				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 \n");
				}
			}

			//=====================================
			// Current short detection
			//=====================================
			if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.short_circuit_L1 == ON)
			{
				if(Alarm_Counter[gun_index].Short[0] > FILTER_SPEC)
				{
					if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CircuitShort == OFF)
					{
						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CircuitShort = ON;
						ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_L1_CIRCUIT_SHORT;
						DEBUG_INFO("ALARM_L1_CIRCUIT_SHORT : alarm \n");
					}
				}
				else
				{
					Alarm_Counter[gun_index].Short[0]++;
				}
			}
			else
			{
				Alarm_Counter[gun_index].Short[0] = 0;
				if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CircuitShort == ON)
				{
					ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CircuitShort = OFF;
					ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_L1_CIRCUIT_SHORT;
					DEBUG_INFO("ALARM_L1_CIRCUIT_SHORT : recover \n");
				}
			}
			
			if(ShmSysConfigAndInfo->SysConfig.AcPhaseCount == 3)
			{
				if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.short_circuit_L2 == ON)
				{
					if(Alarm_Counter[gun_index].Short[1] > FILTER_SPEC)
					{
						if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CircuitShortL2 == OFF)
						{
							ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CircuitShortL2 = ON;
							ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_L2_CIRCUIT_SHORT;
							DEBUG_INFO("ALARM_L2_CIRCUIT_SHORT : alarm \n");
						}
					}
					else
					{
						Alarm_Counter[gun_index].Short[1]++;
					}
				}
				else
				{
					Alarm_Counter[gun_index].Short[1] = 0;
					if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CircuitShortL2 == ON)
					{
						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CircuitShortL2 = OFF;
						ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_L2_CIRCUIT_SHORT;
						DEBUG_INFO("ALARM_L2_CIRCUIT_SHORT : recover \n");
					}
				}

				if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.short_circuit_L3 == ON)
				{
					if(Alarm_Counter[gun_index].Short[2] > FILTER_SPEC)
					{
						if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CircuitShortL3 == OFF)
						{
							ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CircuitShortL3 = ON;
							ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_L3_CIRCUIT_SHORT;
							DEBUG_INFO("ALARM_L3_CIRCUIT_SHORT : alarm \n");
						}
					}
					else
					{
						Alarm_Counter[gun_index].Short[2]++;
					}
				}
				else
				{
					Alarm_Counter[gun_index].Short[2] = 0;
					if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CircuitShortL3 == ON)
					{
						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CircuitShortL3 = OFF;
						ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_L3_CIRCUIT_SHORT;
						DEBUG_INFO("ALARM_L3_CIRCUIT_SHORT : recover \n");
					}
				}
			}

			//=====================================
			// Rotatory switch detection
			//=====================================
			if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.rotate_switch_fault == ON)
			{
				if(ShmStatusCodeData->FaultCode.FaultEvents.bits.RotarySwitchFault == OFF)
				{
					ShmStatusCodeData->FaultCode.FaultEvents.bits.RotarySwitchFault = ON;
					ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_ROTATORY_SWITCH_FAULT;
					DEBUG_INFO("ALARM_ROTATORY_SWITCH_FAULT : alarm \n");
				}
			}
			else
			{
				if(ShmStatusCodeData->FaultCode.FaultEvents.bits.RotarySwitchFault == ON)
				{
					ShmStatusCodeData->FaultCode.FaultEvents.bits.RotarySwitchFault = OFF;
					ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_ROTATORY_SWITCH_FAULT;
					DEBUG_INFO("ALARM_ROTATORY_SWITCH_FAULT : recover \n");
				}
			}

			//=====================================
			// Leakage module detection
			//=====================================
			if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.leak_module_fail == ON)
			{
				if(ShmStatusCodeData->FaultCode.FaultEvents.bits.RcdSelfTestFail == OFF)
				{
					ShmStatusCodeData->FaultCode.FaultEvents.bits.RcdSelfTestFail = ON;
					ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_LEAK_MODULE_FAIL;
					DEBUG_INFO("ALARM_LEAK_MODULE_FAIL : alarm \n");
				}
			}
			else
			{
				if(ShmStatusCodeData->FaultCode.FaultEvents.bits.RcdSelfTestFail == ON)
				{
					ShmStatusCodeData->FaultCode.FaultEvents.bits.RcdSelfTestFail = OFF;
					ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_LEAK_MODULE_FAIL;
					DEBUG_INFO("ALARM_LEAK_MODULE_FAIL : recover \n");
				}
			}

			//=====================================
			// Shutter detection
			//=====================================
			if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.shutter_fault == ON)
			{
				if(ShmStatusCodeData->FaultCode.FaultEvents.bits.ShutterFault == OFF)
				{
					ShmStatusCodeData->FaultCode.FaultEvents.bits.ShutterFault = ON;
					ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_SHUTTER_FAULT;
					DEBUG_INFO("ALARM_SHUTTER_FAULT : alarm \n");
				}
			}
			else
			{
				if(ShmStatusCodeData->FaultCode.FaultEvents.bits.ShutterFault == ON)
				{
					ShmStatusCodeData->FaultCode.FaultEvents.bits.ShutterFault = OFF;
					ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_SHUTTER_FAULT;
					DEBUG_INFO("ALARM_SHUTTER_FAULT : recover \n");
				}
			}

			//=====================================
			// Locker detection
			//=====================================
			if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.locker_fault == ON)
			{
				if(ShmStatusCodeData->FaultCode.FaultEvents.bits.AcConnectorLockFail == OFF)
				{
					ShmStatusCodeData->FaultCode.FaultEvents.bits.AcConnectorLockFail = ON;
					ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_LOCKER_FAULT;
					DEBUG_INFO("ALARM_LOCKER_FAULT : alarm \n");
				}
			}
			else
			{
				if(ShmStatusCodeData->FaultCode.FaultEvents.bits.AcConnectorLockFail == ON)
				{
					ShmStatusCodeData->FaultCode.FaultEvents.bits.AcConnectorLockFail = OFF;
					ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_LOCKER_FAULT;
					DEBUG_INFO("ALARM_LOCKER_FAULT : recover \n");
				}
			}

			//=====================================
			// Power drop detection
			//=====================================
			if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.power_drop == ON)
			{
				if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputDrop == OFF)
				{
					ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputDrop = ON;
					ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_POWER_DROP;
					DEBUG_INFO("ALARM_POWER_DROP : alarm \n");
				}
			}
			else
			{
				if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputDrop == ON)
				{
					ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputDrop = OFF;
					ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_POWER_DROP;
					DEBUG_INFO("ALARM_POWER_DROP : recover \n");
				}
			}

			//=====================================
			// Meter communication timeout detection
			//=====================================
			if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.meter_comm_timeout == ON)
			{
				if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.MeterCommTimeout == OFF)
				{
					ShmStatusCodeData->AlarmCode.AlarmEvents.bits.MeterCommTimeout = ON;
					ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_METER_TIMEOUT;
					DEBUG_INFO("ALARM_METER_TIMEOUT : alarm \n");
				}
			}
			else
			{
				if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.MeterCommTimeout == ON)
				{
					ShmStatusCodeData->AlarmCode.AlarmEvents.bits.MeterCommTimeout = OFF;
					ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_METER_TIMEOUT;
					DEBUG_INFO("ALARM_METER_TIMEOUT : recover \n");
				}
			}

			//=====================================
			// Meter ic communication timeout detection
			//=====================================
			if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.meter_ic_comm_timeout == ON)
			{
				if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.MeterIcCommTimeout == OFF)
				{
					ShmStatusCodeData->AlarmCode.AlarmEvents.bits.MeterIcCommTimeout = ON;
					ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_METER_IC_TIMEOUT;
					DEBUG_INFO("ALARM_METER_IC_TIMEOUT : alarm \n");
				}
			}
			else
			{
				if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.MeterIcCommTimeout == ON)
				{
					ShmStatusCodeData->AlarmCode.AlarmEvents.bits.MeterIcCommTimeout = OFF;
					ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_METER_IC_TIMEOUT;
					DEBUG_INFO("ALARM_METER_IC_TIMEOUT : recover \n");
				}
			}

			//=====================================
			// Pilot negative error detection
			//=====================================
			if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.pilot_negative_error == ON)
			{
				if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PilotNegativeError == OFF)
				{
					ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PilotNegativeError = ON;
					ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_CP_NEG_ERROR;
					DEBUG_INFO("ALARM_PILOT_NEGATIVE_ERROR : alarm \n");
				}
			}
			else
			{
				if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PilotNegativeError == ON)
				{
					ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PilotNegativeError = OFF;
					ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_CP_NEG_ERROR;
					DEBUG_INFO("ALARM_PILOT_NEGATIVE_ERROR : recover \n");
				}
			}

			//=====================================
			// QCA7000 flash content check
			//=====================================
			if((((gun_index == 0) && (ShmSysConfigAndInfo->SysConfig.ModelName[9] == '7')) ||
			    ((gun_index == 1) && (ShmSysConfigAndInfo->SysConfig.ModelName[8] == '7')) ||
			    ((gun_index == 2) && (ShmSysConfigAndInfo->SysConfig.ModelName[7] == '7'))) && !isCheckQca7000[gun_index])
			{
				if(qca7000FlashCheck() == FAIL)
				{
					if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CCSboardStestFail == OFF)
					{
						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CCSboardStestFail = ON;
						ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode |= ALARM_QCA_FLASH_FAIL;
						DEBUG_INFO("ALARM_QCA_FLASH_FAIL : alarm \n");
					}
				}
				else
				{
					if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CCSboardStestFail == ON)
					{
						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CCSboardStestFail = OFF;
						ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode &= ~ALARM_QCA_FLASH_FAIL;
						DEBUG_INFO("ALARM_QCA_FLASH_FAIL : recover \n");
					}
				}

				isCheckQca7000[gun_index] = TRUE;
			}

			//=====================================
			// OCPP error code message
			//=====================================
			if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
			{
				if((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_L1_OVER_VOLTAGE) ||
					(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_L2_OVER_VOLTAGE) ||
					(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_L3_OVER_VOLTAGE))
				{
					sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode , "OverVoltage");
					if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputOVP == ON)
						sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode , "012200");
					else if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputOVP == ON)
						sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode , "012201");
					else if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputOVP == ON)
						sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode , "012202");

				}
				else if((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_L1_UNDER_VOLTAGE) ||
						(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_L2_UNDER_VOLTAGE) ||
						(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_L3_UNDER_VOLTAGE))
				{
					sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode , "UnderVoltage");
					if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputUVP == ON)
						sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode , "012203");
					else if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputUVP == ON)
						sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode , "012204");
					else if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputUVP == ON)
						sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode , "012205");

				}
				else if((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_L1_OVER_CURRENT) ||
						(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_L2_OVER_CURRENT) ||
						(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_L3_OVER_CURRENT))
				{
					sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode , "OverCurrentFailure");
					if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAcOutputOCP == ON)
						sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode , "012216");
					else if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAcOutputOCPL2 == ON)
						sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode , "012299");
					else if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAcOutputOCPL3 == ON)
						sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode , "012300");

				}
				else if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_OVER_TEMPERATURE)
				{
					sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode , "HighTemperature");
					sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode , "012223");
				}
				else if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_GROUND_FAIL)
				{
					sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode , "GroundFailure");
					sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode , "012256");
				}
				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 , "023703");
					sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].Info , "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 , "012233");
					sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].Info , "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 , "012233");
					sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].Info , "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 , "012257");
					sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].Info , "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");
					sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].Info , "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 , "012251");
					sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].Info , "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 , "011009");
					sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].Info , "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 , "011004");
					sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].Info , "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 , "011034");
					sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].Info , "ShutterFault");
				}
				else if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_LOCKER_FAULT)
				{
					sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode , "ConnectorLockFailure");
					sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode , "011027");
				}
				else if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_POWER_DROP)
				{
					sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode , "OtherError");
					if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputDrop == ON)
						sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode , "012212");
					else if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputDrop == ON)
						sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode , "012213");
					else if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputDrop == ON)
						sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode , "012214");

					sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].Info , "PowerDrop");
				}
				else if((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_L1_CIRCUIT_SHORT) ||
						(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_L2_CIRCUIT_SHORT) ||
						(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_L3_CIRCUIT_SHORT))
				{
					sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode , "OtherError");
					if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CircuitShort == ON)
						sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode , "012262");
					else if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CircuitShortL2 == ON)
						sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode , "012301");
					else if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CircuitShortL3 == ON)
						sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode , "012302");

					sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].Info , "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 , "011036");
					sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].Info , "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 , "011010");
					sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].Info , "RelayDriveFault");
				}
				else if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_METER_TIMEOUT)
				{
					sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode , "OtherError");
					sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode , "012305");
					sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].Info , "MeterCommunicationTimeout");
				}
				else if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_METER_IC_TIMEOUT)
				{
					sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode , "OtherError");
					sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode , "012344");
					sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].Info , "MeterIcCommunicationTimeout");
				}
				else if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_CP_NEG_ERROR)
				{
					sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode , "OtherError");
					sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode , "012345");
					sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].Info , "PilotNegativeError");
				}
				else if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_QCA_FLASH_FAIL)
				{
					sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode , "OtherError");
					sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode , "012284");
					sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].Info , "QCA Self test Failed");
				}
				else
				{
					sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode , "NoError");
					memset(ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode, 0x00, ARRAY_SIZE(ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode));
				}
			}
			else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
			{
				uint8_t idxEvent = 0;

				if((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_L1_OVER_VOLTAGE) != (previousAlarmCode[gun_index] & ALARM_L1_OVER_VOLTAGE))
				{
					getNowDatetime(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].timestamp);
					ShmOCPP20Data->NotifyEvent.eventData[idxEvent].eventId = idxEvent;
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].trigger, "Alerting");
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].actualValue, ((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_L1_OVER_VOLTAGE)?"true":"false"));
					ShmOCPP20Data->NotifyEvent.eventData[idxEvent].cleared = ((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_L1_OVER_VOLTAGE)?OFF:ON);
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].eventNotificationType, "HardWiredNotification");

					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].techcode, "012200");
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].techInfo, "System L1 input OVP");

					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.name, "Voltage");
					ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.evse.connectorId = (gun_index+1);
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].variable.name, "Problem");

					idxEvent += ((idxEvent<ARRAY_SIZE(ShmOCPP20Data->NotifyEvent.eventData)-1)?1:0);

					if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_L1_OVER_VOLTAGE)
						previousAlarmCode[gun_index] |= ALARM_L1_OVER_VOLTAGE;
					else
						previousAlarmCode[gun_index] &= ~ALARM_L1_OVER_VOLTAGE;
				}

				if((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_L2_OVER_VOLTAGE) != (previousAlarmCode[gun_index] & ALARM_L2_OVER_VOLTAGE))
				{

					getNowDatetime(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].timestamp);
					ShmOCPP20Data->NotifyEvent.eventData[idxEvent].eventId = idxEvent;
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].trigger, "Alerting");
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].actualValue, ((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_L2_OVER_VOLTAGE)?"true":"false"));
					ShmOCPP20Data->NotifyEvent.eventData[idxEvent].cleared = ((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_L2_OVER_VOLTAGE)?OFF:ON);
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].eventNotificationType, "HardWiredNotification");

					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].techcode, "012201");
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].techInfo, "System L2 input OVP");

					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.name, "Voltage");
					ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.evse.connectorId = (gun_index+1);
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].variable.name, "Problem");

					idxEvent += ((idxEvent<ARRAY_SIZE(ShmOCPP20Data->NotifyEvent.eventData)-1)?1:0);

					if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_L2_OVER_VOLTAGE)
						previousAlarmCode[gun_index] |= ALARM_L2_OVER_VOLTAGE;
					else
						previousAlarmCode[gun_index] &= ~ALARM_L2_OVER_VOLTAGE;
				}

				if((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_L3_OVER_VOLTAGE) != (previousAlarmCode[gun_index] & ALARM_L3_OVER_VOLTAGE))
				{
					getNowDatetime(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].timestamp);
					ShmOCPP20Data->NotifyEvent.eventData[idxEvent].eventId = idxEvent;
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].trigger, "Alerting");
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].actualValue, ((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_L3_OVER_VOLTAGE)?"true":"false"));
					ShmOCPP20Data->NotifyEvent.eventData[idxEvent].cleared = ((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_L3_OVER_VOLTAGE)?OFF:ON);
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].eventNotificationType, "HardWiredNotification");

					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].techcode, "012202");
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].techInfo, "System L3 input OVP");

					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.name, "Voltage");
					ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.evse.connectorId = (gun_index+1);
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].variable.name, "Problem");

					idxEvent += ((idxEvent<ARRAY_SIZE(ShmOCPP20Data->NotifyEvent.eventData)-1)?1:0);

					if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_L3_OVER_VOLTAGE)
						previousAlarmCode[gun_index] |= ALARM_L3_OVER_VOLTAGE;
					else
						previousAlarmCode[gun_index] &= ~ALARM_L3_OVER_VOLTAGE;
				}

				if((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_L1_UNDER_VOLTAGE) != (previousAlarmCode[gun_index] & ALARM_L1_UNDER_VOLTAGE))
				{
					getNowDatetime(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].timestamp);
					ShmOCPP20Data->NotifyEvent.eventData[idxEvent].eventId = idxEvent;
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].trigger, "Alerting");
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].actualValue, ((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_L1_UNDER_VOLTAGE)?"true":"false"));
					ShmOCPP20Data->NotifyEvent.eventData[idxEvent].cleared = ((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_L1_UNDER_VOLTAGE)?OFF:ON);
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].eventNotificationType, "HardWiredNotification");

					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].techcode, "012203");
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].techInfo, "System L1 input UVP");

					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.name, "Voltage");
					ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.evse.connectorId = (gun_index+1);
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].variable.name, "Problem");

					idxEvent += ((idxEvent<ARRAY_SIZE(ShmOCPP20Data->NotifyEvent.eventData)-1)?1:0);

					if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_L1_UNDER_VOLTAGE)
						previousAlarmCode[gun_index] |= ALARM_L1_UNDER_VOLTAGE;
					else
						previousAlarmCode[gun_index] &= ~ALARM_L1_UNDER_VOLTAGE;
				}

				if((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_L2_UNDER_VOLTAGE) != (previousAlarmCode[gun_index] & ALARM_L2_UNDER_VOLTAGE))
				{
					getNowDatetime(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].timestamp);
					ShmOCPP20Data->NotifyEvent.eventData[idxEvent].eventId = idxEvent;
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].trigger, "Alerting");
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].actualValue, ((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_L2_UNDER_VOLTAGE)?"true":"false"));
					ShmOCPP20Data->NotifyEvent.eventData[idxEvent].cleared = ((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_L2_UNDER_VOLTAGE)?OFF:ON);
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].eventNotificationType, "HardWiredNotification");

					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].techcode, "012204");
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].techInfo, "System L2 input UVP");

					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.name, "Voltage");
					ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.evse.connectorId = (gun_index+1);
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].variable.name, "Problem");

					idxEvent += ((idxEvent<ARRAY_SIZE(ShmOCPP20Data->NotifyEvent.eventData)-1)?1:0);

					if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_L2_UNDER_VOLTAGE)
						previousAlarmCode[gun_index] |= ALARM_L2_UNDER_VOLTAGE;
					else
						previousAlarmCode[gun_index] &= ~ALARM_L2_UNDER_VOLTAGE;
				}

				if((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_L3_UNDER_VOLTAGE) != (previousAlarmCode[gun_index] & ALARM_L3_UNDER_VOLTAGE))
				{
					getNowDatetime(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].timestamp);
					ShmOCPP20Data->NotifyEvent.eventData[idxEvent].eventId = idxEvent;
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].trigger, "Alerting");
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].actualValue, ((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_L3_UNDER_VOLTAGE)?"true":"false"));
					ShmOCPP20Data->NotifyEvent.eventData[idxEvent].cleared = ((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_L3_UNDER_VOLTAGE)?OFF:ON);
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].eventNotificationType, "HardWiredNotification");

					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].techcode, "012205");
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].techInfo, "System L3 input UVP");

					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.name, "Voltage");
					ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.evse.connectorId = (gun_index+1);
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].variable.name, "Problem");

					idxEvent += ((idxEvent<ARRAY_SIZE(ShmOCPP20Data->NotifyEvent.eventData)-1)?1:0);

					if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_L3_UNDER_VOLTAGE)
						previousAlarmCode[gun_index] |= ALARM_L3_UNDER_VOLTAGE;
					else
						previousAlarmCode[gun_index] &= ~ALARM_L3_UNDER_VOLTAGE;
				}

				if((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_L1_OVER_CURRENT) != (previousAlarmCode[gun_index] & ALARM_L1_OVER_CURRENT))
				{
					getNowDatetime(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].timestamp);
					ShmOCPP20Data->NotifyEvent.eventData[idxEvent].eventId = idxEvent;
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].trigger, "Alerting");
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].actualValue, ((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_L1_OVER_CURRENT)?"true":"false"));
					ShmOCPP20Data->NotifyEvent.eventData[idxEvent].cleared = ((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_L1_OVER_CURRENT)?OFF:ON);
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].eventNotificationType, "HardWiredNotification");

					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].techcode, "012216");
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].techInfo, "System AC output OCP L1");

					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.name, "Current");
					ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.evse.connectorId = (gun_index+1);
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].variable.name, "Problem");

					idxEvent += ((idxEvent<ARRAY_SIZE(ShmOCPP20Data->NotifyEvent.eventData)-1)?1:0);

					if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_L1_OVER_CURRENT)
						previousAlarmCode[gun_index] |= ALARM_L1_OVER_CURRENT;
					else
						previousAlarmCode[gun_index] &= ~ALARM_L1_OVER_CURRENT;
				}

				if((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_L2_OVER_CURRENT) != (previousAlarmCode[gun_index] & ALARM_L2_OVER_CURRENT))
				{
					getNowDatetime(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].timestamp);
					ShmOCPP20Data->NotifyEvent.eventData[idxEvent].eventId = idxEvent;
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].trigger, "Alerting");
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].actualValue, ((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_L2_OVER_CURRENT)?"true":"false"));
					ShmOCPP20Data->NotifyEvent.eventData[idxEvent].cleared = ((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_L2_OVER_CURRENT)?OFF:ON);
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].eventNotificationType, "HardWiredNotification");

					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].techcode, "012299");
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].techInfo, "System AC output OCP L2");

					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.name, "Current");
					ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.evse.connectorId = (gun_index+1);
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].variable.name, "Problem");

					idxEvent += ((idxEvent<ARRAY_SIZE(ShmOCPP20Data->NotifyEvent.eventData)-1)?1:0);

					if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_L2_OVER_CURRENT)
						previousAlarmCode[gun_index] |= ALARM_L2_OVER_CURRENT;
					else
						previousAlarmCode[gun_index] &= ~ALARM_L2_OVER_CURRENT;
				}

				if((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_L3_OVER_CURRENT) != (previousAlarmCode[gun_index] & ALARM_L3_OVER_CURRENT))
				{
					getNowDatetime(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].timestamp);
					ShmOCPP20Data->NotifyEvent.eventData[idxEvent].eventId = idxEvent;
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].trigger, "Alerting");
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].actualValue, ((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_L3_OVER_CURRENT)?"true":"false"));
					ShmOCPP20Data->NotifyEvent.eventData[idxEvent].cleared = ((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_L3_OVER_CURRENT)?OFF:ON);
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].eventNotificationType, "HardWiredNotification");

					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].techcode, "012300");
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].techInfo, "System AC output OCP L3");

					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.name, "Current");
					ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.evse.connectorId = (gun_index+1);
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].variable.name, "Problem");

					idxEvent += ((idxEvent<ARRAY_SIZE(ShmOCPP20Data->NotifyEvent.eventData)-1)?1:0);

					if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_L3_OVER_CURRENT)
						previousAlarmCode[gun_index] |= ALARM_L3_OVER_CURRENT;
					else
						previousAlarmCode[gun_index] &= ~ALARM_L3_OVER_CURRENT;
				}

				if((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_OVER_TEMPERATURE) != (previousAlarmCode[gun_index] & ALARM_OVER_TEMPERATURE))
				{
					getNowDatetime(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].timestamp);
					ShmOCPP20Data->NotifyEvent.eventData[idxEvent].eventId = idxEvent;
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].trigger, "Alerting");
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].actualValue, ((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_OVER_TEMPERATURE)?"true":"false"));
					ShmOCPP20Data->NotifyEvent.eventData[idxEvent].cleared = ((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_OVER_TEMPERATURE)?OFF:ON);
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].eventNotificationType, "HardWiredNotification");

					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].techcode, "012223");
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].techInfo, "System ambient/inlet OTP");

					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.name, "Temperature");
					ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.evse.connectorId = (gun_index+1);
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].variable.name, "Problem");

					idxEvent += ((idxEvent<ARRAY_SIZE(ShmOCPP20Data->NotifyEvent.eventData)-1)?1:0);

					if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_OVER_TEMPERATURE)
						previousAlarmCode[gun_index] |= ALARM_OVER_TEMPERATURE;
					else
						previousAlarmCode[gun_index] &= ~ALARM_OVER_TEMPERATURE;
				}

				if((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_GROUND_FAIL) != (previousAlarmCode[gun_index] & ALARM_GROUND_FAIL))
				{
					getNowDatetime(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].timestamp);
					ShmOCPP20Data->NotifyEvent.eventData[idxEvent].eventId = idxEvent;
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].trigger, "Alerting");
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].actualValue, ((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_GROUND_FAIL)?"true":"false"));
					ShmOCPP20Data->NotifyEvent.eventData[idxEvent].cleared = ((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_GROUND_FAIL)?OFF:ON);
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].eventNotificationType, "HardWiredNotification");

					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].techcode, "012256");
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].techInfo, "AC Ground Fault");

					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.name, "Ground(PE)");
					ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.evse.connectorId = (gun_index+1);
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].variable.name, "Problem");

					idxEvent += ((idxEvent<ARRAY_SIZE(ShmOCPP20Data->NotifyEvent.eventData)-1)?1:0);

					if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_GROUND_FAIL)
						previousAlarmCode[gun_index] |= ALARM_GROUND_FAIL;
					else
						previousAlarmCode[gun_index] &= ~ALARM_GROUND_FAIL;
				}

				if((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_CP_ERROR) != (previousAlarmCode[gun_index] & ALARM_CP_ERROR))
				{
					getNowDatetime(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].timestamp);
					ShmOCPP20Data->NotifyEvent.eventData[idxEvent].eventId = idxEvent;
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].trigger, "Alerting");
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].actualValue, ((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_CP_ERROR)?"true":"false"));
					ShmOCPP20Data->NotifyEvent.eventData[idxEvent].cleared = ((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_CP_ERROR)?OFF:ON);
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].eventNotificationType, "HardWiredNotification");

					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].techcode, "023703");
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].techInfo, "pilot fault");

					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.name, "Control pilot");
					ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.evse.connectorId = (gun_index+1);
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].variable.name, "Problem");

					idxEvent += ((idxEvent<ARRAY_SIZE(ShmOCPP20Data->NotifyEvent.eventData)-1)?1:0);

					if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_CP_ERROR)
						previousAlarmCode[gun_index] |= ALARM_CP_ERROR;
					else
						previousAlarmCode[gun_index] &= ~ALARM_CP_ERROR;
				}

				if((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_CURRENT_LEAK_AC) != (previousAlarmCode[gun_index] & ALARM_CURRENT_LEAK_AC))
				{
					getNowDatetime(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].timestamp);
					ShmOCPP20Data->NotifyEvent.eventData[idxEvent].eventId = idxEvent;
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].trigger, "Alerting");
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].actualValue, ((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_CURRENT_LEAK_AC)?"true":"false"));
					ShmOCPP20Data->NotifyEvent.eventData[idxEvent].cleared = ((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_CURRENT_LEAK_AC)?OFF:ON);
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].eventNotificationType, "HardWiredNotification");

					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].techcode, "012233");
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].techInfo, "RCD/CCID trip");

					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.name, "CCID");
					ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.evse.connectorId = (gun_index+1);
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].variable.name, "Problem");

					idxEvent += ((idxEvent<ARRAY_SIZE(ShmOCPP20Data->NotifyEvent.eventData)-1)?1:0);

					if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_CURRENT_LEAK_AC)
						previousAlarmCode[gun_index] |= ALARM_CURRENT_LEAK_AC;
					else
						previousAlarmCode[gun_index] &= ~ALARM_CURRENT_LEAK_AC;
				}

				if((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_CURRENT_LEAK_DC) != (previousAlarmCode[gun_index] & ALARM_CURRENT_LEAK_DC))
				{
					getNowDatetime(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].timestamp);
					ShmOCPP20Data->NotifyEvent.eventData[idxEvent].eventId = idxEvent;
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].trigger, "Alerting");
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].actualValue, ((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_CURRENT_LEAK_DC)?"true":"false"));
					ShmOCPP20Data->NotifyEvent.eventData[idxEvent].cleared = ((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_CURRENT_LEAK_DC)?OFF:ON);
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].eventNotificationType, "HardWiredNotification");

					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].techcode, "012233");
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].techInfo, "RCD/CCID trip");

					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.name, "CCID");
					ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.evse.connectorId = (gun_index+1);
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].variable.name, "Problem");

					idxEvent += ((idxEvent<ARRAY_SIZE(ShmOCPP20Data->NotifyEvent.eventData)-1)?1:0);

					if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_CURRENT_LEAK_DC)
						previousAlarmCode[gun_index] |= ALARM_CURRENT_LEAK_DC;
					else
						previousAlarmCode[gun_index] &= ~ALARM_CURRENT_LEAK_DC;
				}

				if((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_MCU_TESTFAIL) != (previousAlarmCode[gun_index] & ALARM_MCU_TESTFAIL))
				{
					getNowDatetime(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].timestamp);
					ShmOCPP20Data->NotifyEvent.eventData[idxEvent].eventId = idxEvent;
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].trigger, "Alerting");
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].actualValue, ((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_MCU_TESTFAIL)?"true":"false"));
					ShmOCPP20Data->NotifyEvent.eventData[idxEvent].cleared = ((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_MCU_TESTFAIL)?OFF:ON);
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].eventNotificationType, "HardWiredNotification");

					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].techcode, "012257");
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].techInfo, "MCU self-test Fault");

					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.name, "MCU");
					ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.evse.connectorId = (gun_index+1);
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].variable.name, "Problem");

					idxEvent += ((idxEvent<ARRAY_SIZE(ShmOCPP20Data->NotifyEvent.eventData)-1)?1:0);

					if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_MCU_TESTFAIL)
						previousAlarmCode[gun_index] |= ALARM_MCU_TESTFAIL;
					else
						previousAlarmCode[gun_index] &= ~ALARM_MCU_TESTFAIL;
				}

				if((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_HANDSHAKE_TIMEOUT) != (previousAlarmCode[gun_index] & ALARM_HANDSHAKE_TIMEOUT))
				{
					getNowDatetime(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].timestamp);
					ShmOCPP20Data->NotifyEvent.eventData[idxEvent].eventId = idxEvent;
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].trigger, "Alerting");
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].actualValue, ((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_HANDSHAKE_TIMEOUT)?"true":"false"));
					ShmOCPP20Data->NotifyEvent.eventData[idxEvent].cleared = ((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_HANDSHAKE_TIMEOUT)?OFF:ON);
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].eventNotificationType, "HardWiredNotification");

					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].techcode, "HandshakeTimeout");
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].techInfo, "HandshakeTimeout");

					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.name, "Operation");
					ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.evse.connectorId = (gun_index+1);
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].variable.name, "Problem");

					idxEvent += ((idxEvent<ARRAY_SIZE(ShmOCPP20Data->NotifyEvent.eventData)-1)?1:0);

					if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_HANDSHAKE_TIMEOUT)
						previousAlarmCode[gun_index] |= ALARM_HANDSHAKE_TIMEOUT;
					else
						previousAlarmCode[gun_index] &= ~ALARM_HANDSHAKE_TIMEOUT;
				}

				if((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_EMERGENCY_STOP) != (previousAlarmCode[gun_index] & ALARM_EMERGENCY_STOP))
				{
					getNowDatetime(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].timestamp);
					ShmOCPP20Data->NotifyEvent.eventData[idxEvent].eventId = idxEvent;
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].trigger, "Alerting");
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].actualValue, ((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_EMERGENCY_STOP)?"true":"false"));
					ShmOCPP20Data->NotifyEvent.eventData[idxEvent].cleared = ((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_EMERGENCY_STOP)?OFF:ON);
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].eventNotificationType, "HardWiredNotification");

					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].techcode, "012251");
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].techInfo, "Emergency stop");

					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.name, "Button");
					ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.evse.connectorId = (gun_index+1);
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].variable.name, "Problem");

					idxEvent += ((idxEvent<ARRAY_SIZE(ShmOCPP20Data->NotifyEvent.eventData)-1)?1:0);

					if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_EMERGENCY_STOP)
						previousAlarmCode[gun_index] |= ALARM_EMERGENCY_STOP;
					else
						previousAlarmCode[gun_index] &= ~ALARM_EMERGENCY_STOP;
				}

				if((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_RELAY_WELDING) != (previousAlarmCode[gun_index] & ALARM_RELAY_WELDING))
				{
					getNowDatetime(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].timestamp);
					ShmOCPP20Data->NotifyEvent.eventData[idxEvent].eventId = idxEvent;
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].trigger, "Alerting");
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].actualValue, ((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_RELAY_WELDING)?"true":"false"));
					ShmOCPP20Data->NotifyEvent.eventData[idxEvent].cleared = ((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_RELAY_WELDING)?OFF:ON);
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].eventNotificationType, "HardWiredNotification");

					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].techcode, "011009");
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].techInfo, "AC output relay welding");

					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.name, "Relay");
					ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.evse.connectorId = (gun_index+1);
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].variable.name, "Problem");

					idxEvent += ((idxEvent<ARRAY_SIZE(ShmOCPP20Data->NotifyEvent.eventData)-1)?1:0);

					if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_RELAY_WELDING)
						previousAlarmCode[gun_index] |= ALARM_RELAY_WELDING;
					else
						previousAlarmCode[gun_index] &= ~ALARM_RELAY_WELDING;
				}

				if((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_LEAK_MODULE_FAIL) != (previousAlarmCode[gun_index] & ALARM_LEAK_MODULE_FAIL))
				{
					getNowDatetime(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].timestamp);
					ShmOCPP20Data->NotifyEvent.eventData[idxEvent].eventId = idxEvent;
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].trigger, "Alerting");
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].actualValue, ((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_LEAK_MODULE_FAIL)?"true":"false"));
					ShmOCPP20Data->NotifyEvent.eventData[idxEvent].cleared = ((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_LEAK_MODULE_FAIL)?OFF:ON);
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].eventNotificationType, "HardWiredNotification");

					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].techcode, "011004");
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].techInfo, "RCD/CCID self-test fail");

					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.name, "CCID");
					ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.evse.connectorId = (gun_index+1);
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].variable.name, "Problem");

					idxEvent += ((idxEvent<ARRAY_SIZE(ShmOCPP20Data->NotifyEvent.eventData)-1)?1:0);

					if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_LEAK_MODULE_FAIL)
						previousAlarmCode[gun_index] |= ALARM_LEAK_MODULE_FAIL;
					else
						previousAlarmCode[gun_index] &= ~ALARM_LEAK_MODULE_FAIL;
				}

				if((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_SHUTTER_FAULT) != (previousAlarmCode[gun_index] & ALARM_SHUTTER_FAULT))
				{
					getNowDatetime(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].timestamp);
					ShmOCPP20Data->NotifyEvent.eventData[idxEvent].eventId = idxEvent;
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].trigger, "Alerting");
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].actualValue, ((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_SHUTTER_FAULT)?"true":"false"));
					ShmOCPP20Data->NotifyEvent.eventData[idxEvent].cleared = ((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_SHUTTER_FAULT)?OFF:ON);
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].eventNotificationType, "HardWiredNotification");

					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].techcode, "011034");
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].techInfo, "Shutter fault");

					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.name, "Shutter");
					ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.evse.connectorId = (gun_index+1);
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].variable.name, "Problem");

					idxEvent += ((idxEvent<ARRAY_SIZE(ShmOCPP20Data->NotifyEvent.eventData)-1)?1:0);

					if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_SHUTTER_FAULT)
						previousAlarmCode[gun_index] |= ALARM_SHUTTER_FAULT;
					else
						previousAlarmCode[gun_index] &= ~ALARM_SHUTTER_FAULT;
				}

				if((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_LOCKER_FAULT) != (previousAlarmCode[gun_index] & ALARM_LOCKER_FAULT))
				{
					getNowDatetime(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].timestamp);
					ShmOCPP20Data->NotifyEvent.eventData[idxEvent].eventId = idxEvent;
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].trigger, "Alerting");
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].actualValue, ((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_LOCKER_FAULT)?"true":"false"));
					ShmOCPP20Data->NotifyEvent.eventData[idxEvent].cleared = ((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_LOCKER_FAULT)?OFF:ON);
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].eventNotificationType, "HardWiredNotification");

					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].techcode, "011027");
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].techInfo, "AC connector lock fail");

					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.name, "Locker");
					ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.evse.connectorId = (gun_index+1);
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].variable.name, "Problem");

					idxEvent += ((idxEvent<ARRAY_SIZE(ShmOCPP20Data->NotifyEvent.eventData)-1)?1:0);

					if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_LOCKER_FAULT)
						previousAlarmCode[gun_index] |= ALARM_LOCKER_FAULT;
					else
						previousAlarmCode[gun_index] &= ~ALARM_LOCKER_FAULT;
				}

				if((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_POWER_DROP) != (previousAlarmCode[gun_index] & ALARM_POWER_DROP))
				{
					getNowDatetime(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].timestamp);
					ShmOCPP20Data->NotifyEvent.eventData[idxEvent].eventId = idxEvent;
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].trigger, "Alerting");
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].actualValue, ((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_POWER_DROP)?"true":"false"));
					ShmOCPP20Data->NotifyEvent.eventData[idxEvent].cleared = ((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_POWER_DROP)?OFF:ON);
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].eventNotificationType, "HardWiredNotification");

					if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputDrop == ON)
					{
						sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].techcode, "012212");
						sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].techInfo, "System L1 input drop");
					}
					else if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputDrop == ON)
					{
						sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].techcode, "012213");
						sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].techInfo, "System L2 input drop");
					}
					else if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputDrop == ON)
					{
						sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].techcode, "012214");
						sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].techInfo, "System L3 input drop");
					}

					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.name, "Voltage");
					ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.evse.connectorId = (gun_index+1);
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].variable.name, "Problem");

					idxEvent += ((idxEvent<ARRAY_SIZE(ShmOCPP20Data->NotifyEvent.eventData)-1)?1:0);

					if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_POWER_DROP)
						previousAlarmCode[gun_index] |= ALARM_POWER_DROP;
					else
						previousAlarmCode[gun_index] &= ~ALARM_POWER_DROP;
				}

				if((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_L1_CIRCUIT_SHORT) != (previousAlarmCode[gun_index] & ALARM_L1_CIRCUIT_SHORT))
				{
					getNowDatetime(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].timestamp);
					ShmOCPP20Data->NotifyEvent.eventData[idxEvent].eventId = idxEvent;
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].trigger, "Alerting");
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].actualValue, ((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_L1_CIRCUIT_SHORT)?"true":"false"));
					ShmOCPP20Data->NotifyEvent.eventData[idxEvent].cleared = ((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_L1_CIRCUIT_SHORT)?OFF:ON);
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].eventNotificationType, "HardWiredNotification");

					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].techcode, "012262");
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].techInfo, "Circuit Short L1");

					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.name, "Current");
					ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.evse.connectorId = (gun_index+1);
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].variable.name, "Problem");

					idxEvent += ((idxEvent<ARRAY_SIZE(ShmOCPP20Data->NotifyEvent.eventData)-1)?1:0);

					if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_L1_CIRCUIT_SHORT)
						previousAlarmCode[gun_index] |= ALARM_L1_CIRCUIT_SHORT;
					else
						previousAlarmCode[gun_index] &= ~ALARM_L1_CIRCUIT_SHORT;
				}

				if((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_L2_CIRCUIT_SHORT) != (previousAlarmCode[gun_index] & ALARM_L2_CIRCUIT_SHORT))
				{
					getNowDatetime(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].timestamp);
					ShmOCPP20Data->NotifyEvent.eventData[idxEvent].eventId = idxEvent;
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].trigger, "Alerting");
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].actualValue, ((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_L2_CIRCUIT_SHORT)?"true":"false"));
					ShmOCPP20Data->NotifyEvent.eventData[idxEvent].cleared = ((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_L2_CIRCUIT_SHORT)?OFF:ON);
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].eventNotificationType, "HardWiredNotification");

					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].techcode, "012301");
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].techInfo, "Circuit Short L2");

					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.name, "Current");
					ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.evse.connectorId = (gun_index+1);
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].variable.name, "Problem");

					idxEvent += ((idxEvent<ARRAY_SIZE(ShmOCPP20Data->NotifyEvent.eventData)-1)?1:0);

					if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_L2_CIRCUIT_SHORT)
						previousAlarmCode[gun_index] |= ALARM_L2_CIRCUIT_SHORT;
					else
						previousAlarmCode[gun_index] &= ~ALARM_L2_CIRCUIT_SHORT;
				}


				if((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_L3_CIRCUIT_SHORT) != (previousAlarmCode[gun_index] & ALARM_L3_CIRCUIT_SHORT))
				{
					getNowDatetime(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].timestamp);
					ShmOCPP20Data->NotifyEvent.eventData[idxEvent].eventId = idxEvent;
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].trigger, "Alerting");
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].actualValue, ((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_L3_CIRCUIT_SHORT)?"true":"false"));
					ShmOCPP20Data->NotifyEvent.eventData[idxEvent].cleared = ((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_L3_CIRCUIT_SHORT)?OFF:ON);
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].eventNotificationType, "HardWiredNotification");

					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].techcode, "012302");
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].techInfo, "Circuit Short L3");

					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.name, "Current");
					ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.evse.connectorId = (gun_index+1);
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].variable.name, "Problem");

					idxEvent += ((idxEvent<ARRAY_SIZE(ShmOCPP20Data->NotifyEvent.eventData)-1)?1:0);

					if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_L3_CIRCUIT_SHORT)
						previousAlarmCode[gun_index] |= ALARM_L3_CIRCUIT_SHORT;
					else
						previousAlarmCode[gun_index] &= ~ALARM_L3_CIRCUIT_SHORT;
				}

				if((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_ROTATORY_SWITCH_FAULT) != (previousAlarmCode[gun_index] & ALARM_ROTATORY_SWITCH_FAULT))
				{
					getNowDatetime(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].timestamp);
					ShmOCPP20Data->NotifyEvent.eventData[idxEvent].eventId = idxEvent;
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].trigger, "Alerting");
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].actualValue, ((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_ROTATORY_SWITCH_FAULT)?"true":"false"));
					ShmOCPP20Data->NotifyEvent.eventData[idxEvent].cleared = ((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_ROTATORY_SWITCH_FAULT)?OFF:ON);
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].eventNotificationType, "HardWiredNotification");

					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].techcode, "011036");
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].techInfo, "Rotary switch fault");

					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.name, "Rotary switch");
					ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.evse.connectorId = (gun_index+1);
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].variable.name, "Problem");

					idxEvent += ((idxEvent<ARRAY_SIZE(ShmOCPP20Data->NotifyEvent.eventData)-1)?1:0);

					if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_ROTATORY_SWITCH_FAULT)
						previousAlarmCode[gun_index] |= ALARM_ROTATORY_SWITCH_FAULT;
					else
						previousAlarmCode[gun_index] &= ~ALARM_ROTATORY_SWITCH_FAULT;
				}

				if((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_RELAY_DRIVE_FAULT) != (previousAlarmCode[gun_index] & ALARM_RELAY_DRIVE_FAULT))
				{
					getNowDatetime(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].timestamp);
					ShmOCPP20Data->NotifyEvent.eventData[idxEvent].eventId = idxEvent;
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].trigger, "Alerting");
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].actualValue, ((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_RELAY_DRIVE_FAULT)?"true":"false"));
					ShmOCPP20Data->NotifyEvent.eventData[idxEvent].cleared = ((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_RELAY_DRIVE_FAULT)?OFF:ON);
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].eventNotificationType, "HardWiredNotification");

					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].techcode, "011010");
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].techInfo, "AC output relay driving fault");

					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.name, "Relay");
					ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.evse.connectorId = (gun_index+1);
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].variable.name, "Problem");

					idxEvent += ((idxEvent<ARRAY_SIZE(ShmOCPP20Data->NotifyEvent.eventData)-1)?1:0);

					if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_RELAY_DRIVE_FAULT)
						previousAlarmCode[gun_index] |= ALARM_RELAY_DRIVE_FAULT;
					else
						previousAlarmCode[gun_index] &= ~ALARM_RELAY_DRIVE_FAULT;
				}

				if((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_METER_TIMEOUT) != (previousAlarmCode[gun_index] & ALARM_METER_TIMEOUT))
				{
					getNowDatetime(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].timestamp);
					ShmOCPP20Data->NotifyEvent.eventData[idxEvent].eventId = idxEvent;
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].trigger, "Alerting");
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].actualValue, ((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_METER_TIMEOUT)?"true":"false"));
					ShmOCPP20Data->NotifyEvent.eventData[idxEvent].cleared = ((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_METER_TIMEOUT)?OFF:ON);
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].eventNotificationType, "HardWiredNotification");

					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].techcode, "012305");
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].techInfo, "Meter communication timeout");

					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.name, "Meter");
					ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.evse.connectorId = (gun_index+1);
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].variable.name, "Problem");

					idxEvent += ((idxEvent<ARRAY_SIZE(ShmOCPP20Data->NotifyEvent.eventData)-1)?1:0);

					if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_METER_TIMEOUT)
						previousAlarmCode[gun_index] |= ALARM_METER_TIMEOUT;
					else
						previousAlarmCode[gun_index] &= ~ALARM_METER_TIMEOUT;
				}

				if((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_METER_IC_TIMEOUT) != (previousAlarmCode[gun_index] & ALARM_METER_IC_TIMEOUT))
				{
					getNowDatetime(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].timestamp);
					ShmOCPP20Data->NotifyEvent.eventData[idxEvent].eventId = idxEvent;
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].trigger, "Alerting");
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].actualValue, ((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_METER_IC_TIMEOUT)?"true":"false"));
					ShmOCPP20Data->NotifyEvent.eventData[idxEvent].cleared = ((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_METER_IC_TIMEOUT)?OFF:ON);
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].eventNotificationType, "HardWiredNotification");
					
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].techcode, "012344");
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].techInfo, "Meter ic communication timeout");
					
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.name, "Meter");
					ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.evse.connectorId = (gun_index+1);
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].variable.name, "Problem");
					
					idxEvent += ((idxEvent<ARRAY_SIZE(ShmOCPP20Data->NotifyEvent.eventData)-1)?1:0);
					
					if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_METER_IC_TIMEOUT)
						previousAlarmCode[gun_index] |= ALARM_METER_IC_TIMEOUT;
					else
						previousAlarmCode[gun_index] &= ~ALARM_METER_IC_TIMEOUT;
				}

				if((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_CP_NEG_ERROR) != (previousAlarmCode[gun_index] & ALARM_CP_NEG_ERROR))
				{
					getNowDatetime(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].timestamp);
					ShmOCPP20Data->NotifyEvent.eventData[idxEvent].eventId = idxEvent;
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].trigger, "Alerting");
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].actualValue, ((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_CP_NEG_ERROR)?"true":"false"));
					ShmOCPP20Data->NotifyEvent.eventData[idxEvent].cleared = ((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_CP_NEG_ERROR)?OFF:ON);
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].eventNotificationType, "HardWiredNotification");
					
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].techcode, "012345");
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].techInfo, "Pilot negative error");
					
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.name, "PCBA");
					ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.evse.connectorId = (gun_index+1);
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].variable.name, "Problem");
					
					idxEvent += ((idxEvent<ARRAY_SIZE(ShmOCPP20Data->NotifyEvent.eventData)-1)?1:0);
					
					if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_CP_NEG_ERROR)
						previousAlarmCode[gun_index] |= ALARM_CP_NEG_ERROR;
					else
						previousAlarmCode[gun_index] &= ~ALARM_CP_NEG_ERROR;
				}

				if((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_QCA_FLASH_FAIL) != (previousAlarmCode[gun_index] & ALARM_QCA_FLASH_FAIL))
				{
					getNowDatetime(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].timestamp);
					ShmOCPP20Data->NotifyEvent.eventData[idxEvent].eventId = idxEvent;
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].trigger, "Alerting");
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].actualValue, ((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_CP_NEG_ERROR)?"true":"false"));
					ShmOCPP20Data->NotifyEvent.eventData[idxEvent].cleared = ((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_CP_NEG_ERROR)?OFF:ON);
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].eventNotificationType, "HardWiredNotification");

					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].techcode, "012284");
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].techInfo, "QCA Self test Failed");

					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.name, "PCBA");
					ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.evse.connectorId = (gun_index+1);
					sprintf((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].variable.name, "Problem");

					idxEvent += ((idxEvent<ARRAY_SIZE(ShmOCPP20Data->NotifyEvent.eventData)-1)?1:0);

					if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_QCA_FLASH_FAIL)
						previousAlarmCode[gun_index] |= ALARM_QCA_FLASH_FAIL;
					else
						previousAlarmCode[gun_index] &= ~ALARM_QCA_FLASH_FAIL;
				}

				if(idxEvent > 0)
					ShmOCPP20Data->SpMsg.bits.NotifyEventReq = ON;
			}


			//=====================================
			// 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
				*/
			}
			
			ShmCharger->gun_info[gun_index].acCcsInfo.CSUAlarmStatusCode = ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode;
		}

		usleep(100000);
	}

	return FAIL;
}