فهرست منبع

2020.10.20 / Wendell
Actions:
1. DO360 first release

Files:
1. As follow commit history

Wendell 4 سال پیش
والد
کامیت
fb216f74ba

+ 2 - 2
EVSE/Modularization/ocppfiles/MessageHandler.c

@@ -147,7 +147,7 @@ typedef union
 		unsigned char StatusNotificationConf:1;		//bit 1,
 		unsigned char TriggerMeterValue:1;			//bit 2,
 		unsigned char :5;	//bit 5~7
-	}bits[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
+	}bits[CONNECTOR_QUANTITY];
 }CpinitiateMsg;
 
 CpinitiateMsg cpinitateMsg;
@@ -16600,7 +16600,7 @@ void InitialSystemValue(void)
 
  	if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
 	{
- 		if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='O')
+ 		if(ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O')
  		{
  			// DO series
  			for(int index=0; index<GENERAL_GUN_QUANTITY ; index++)

+ 45 - 2
EVSE/Projects/DO360/Apps/Config.h

@@ -30,7 +30,7 @@ typedef unsigned char			byte;
 #define MODE_DEBUG					16
 #define MODE_CCS_PRECHARGE_STEP0	17 	// ready for ccs precharge processing, For D+ relay to precharge relay
 #define MODE_CCS_PRECHARGE_STEP1	18	// waitting for ev board inform to enter to charging, For precharge relay to D+ relay
-#define MODE_SINGLE_RUN				19
+#define MODE_UPDATE					19
 
 #define GFD_WAIT			0
 #define GFD_PASS			1
@@ -66,7 +66,7 @@ enum _SYSTEM_STATUS
 	S_DEBUG,
 	S_CCS_PRECHARGE_ST0,
 	S_CCS_PRECHARGE_ST1,
-	S_SINGLE_RUN,
+	S_UPDATE,
 	S_NONE,
 };
 
@@ -86,6 +86,7 @@ enum _GUN_TYPE
 	_Type_CCS_2,
 	_Type_GB,
 	_Type_AC,
+	_Type_Unknown = 0xFF
 };
 
 //enum _LCM_INDEX
@@ -118,6 +119,26 @@ enum _LCM_INDEX
 	_LCM_NONE = 			0xFF,
 };
 
+enum _DispenserAuthorizeStatus
+{
+    _AuthorizeStatus_Idle   = 0x00,
+    _AuthorizeStatus_Wait   = 0x01,
+    _AuthorizeStatus_Busy   = 0x02,
+    _AuthorizeStatus_Pass   = 0x03,
+    _AuthorizeStatus_Fail   = 0x04,
+};
+
+#define AUTHORIZE_SRC_NONE_DEV      "None  Src"
+#define AUTHORIZE_SRC_LOCAL_DEV     "Dispenser"
+#define AUTHORIZE_SRC_REMOTE_DEV    "Connector"
+
+enum _AuthorizeSource
+{
+    _AuthorizeSrc_None      = 0x00,
+    _AuthorizeSrc_Local     = 0x01,
+    _AuthorizeSrc_Remote    = 0x02,
+};
+
 enum _SELF_TEST_SEQ
 {
 	_STEST_VERSION = 0x00,
@@ -192,4 +213,26 @@ enum _SYS_WIFI_MODE
 	_SYS_WIFI_MODE_AP = 2
 };
 
+enum _LED_INTENSITY_LV
+{
+	_LED_INTENSITY_DARKEST 	 = 0,
+	_LED_INTENSITY_MEDIUM 	 = 1,
+	_LED_INTENSITY_BRIGHTEST = 2
+};
+
+enum _CCS_COMM_PROTOCOL
+{
+	_CCS_COMM_V2GMessage_DIN70121 		= 0x01,
+	_CCS_COMM_V2GMessage_ISO15118_2014 	= 0x02,
+	_CCS_COMM_V2GMessage_ISO15118_2018 	= 0x03
+};
+
+enum _ETHERNET_USAGE
+{
+	_ETHERNET_USAGE_NONE 	= 0,
+	_ETHERNET_USAGE_LAN,
+	_ETHERNET_USAGE_WIFI,
+	_ETHERNET_USAGE_3G_4g
+};
+
 #endif /* CONFIG_H_ */

+ 6 - 194
EVSE/Projects/DO360/Apps/Ev_Comm.c

@@ -1,196 +1,8 @@
-#include "Module_EvComm.h"
-#include 	<linux/can.h>
-#include 	<linux/can/raw.h>
-#include 	<string.h>
-#include    <stdio.h>      /*¼Ð·Ç¿é¤J¿é¥X©w¸q*/
-#include    <stdlib.h>     /*¼Ð·Ç¨ç¼Æ®w©w¸q*/
-#include    <unistd.h>     /*Unix ¼Ð·Ç¨ç¼Æ©w¸q*/
-#include    <fcntl.h>      /*Àɱ±¨î©w¸q*/
-#include    <termios.h>    /*PPSIX ²×ºÝ±±¨î©w¸q*/
-#include    <errno.h>      /*¿ù»~¸¹©w¸q*/
+/*
+ * Ev_Comm.c
+ *
+ *  Created on: 2020年9月14日
+ *      Author: Wendell
+ */
 
-//================================================
-//================================================
-// CANBUS send cmd
-//================================================
-//================================================
-
-int PackageIdCmd(int cmd)
-{
-	return cmd | 0x80000000;
-}
-
-void SendCmdToEvboard(int cmd, byte *data, byte dataLen)
-{
-    struct can_frame frame;
-
-    frame.can_id = cmd;
-    frame.can_dlc = dataLen;
-    memcpy(frame.data, data, sizeof(frame.data));
-
-    write(CanFd, &frame, sizeof(struct can_frame));
-}
-
-void SetTargetAddr(byte *target_number, byte index)
-{
-	int id = PackageIdCmd(Ev_Cmd.address_assignment + index);
-	//printf("intCmd = %x \n", cmd & CAN_EFF_MASK);
-	//cmd = cmd & CAN_EFF_MASK;
-
-	byte data[8];
-
-	data[0] = *target_number;
-	data[1] = *(target_number + 1);
-	data[2] = *(target_number + 2);
-	data[3] = *(target_number + 3);
-	data[4] = index;
-
-	SendCmdToEvboard(id, data, 5);
-}
-
-void GetFirmwareVersion(byte gun_index, byte toId)
-{
-	int id = PackageIdCmd(Ev_Cmd.get_firmware_ver + toId);
-	byte data[8];
-
-	SendCmdToEvboard(id, data, 0);
-}
-
-void SyncRtcInfo(byte gun_index, byte toId, int epoch)
-{
-	int id = PackageIdCmd(Ev_Cmd.sync_rtc_info + toId);
-	byte data[8];
-
-	data[0] = epoch & 0xff;
-	data[1] = (epoch >> 8) & 0xff;
-	data[2] = (epoch >> 16) & 0xff;
-	data[3] = (epoch >> 24) & 0xff;
-
-	SendCmdToEvboard(id, data, 4);
-}
-
-void GetHardwareVersion(byte gun_index, byte toId)
-{
-	int id = PackageIdCmd(Ev_Cmd.get_hardware_ver + toId);
-	byte data[8];
-
-	SendCmdToEvboard(id, data, 0);
-}
-
-void SetChargingPermission(byte gun_index, byte permissionStatus, short aOutputPw, short aOutputCur, short aOutputVol, byte toId)
-{
-	int id = PackageIdCmd(Ev_Cmd.charging_permission + toId);
-	byte data[8];
-
-	data[0] = permissionStatus;
-	data[1] = aOutputPw & 0xff;
-	data[2] = (aOutputPw >> 8) & 0xff;
-	data[3] = aOutputCur & 0xff;
-	data[4] = (aOutputCur >> 8) & 0xff;
-	data[5] = aOutputVol & 0xff;
-	data[6] = (aOutputVol >> 8) & 0xff;
-	data[7] = 0xf0;
-
-	SendCmdToEvboard(id, data, sizeof(data));
-}
-
-void SetPresentOutputPower(short outputVol_b1, short outputCur_b1, short outputVol_b2, short outputCur_b2)
-{
-	int id = PackageIdCmd(Ev_Cmd.present_output_power);
-	byte data[8];
-
-	data[0] = outputVol_b1 & 0xff;
-	data[1] = (outputVol_b1 >> 8) & 0xff;
-	data[2] = outputCur_b1 & 0xff;
-	data[3] = (outputCur_b1 >> 8) & 0xff;
-	data[4] = outputVol_b2 & 0xff;
-	data[5] = (outputVol_b2 >> 8) & 0xff;
-	data[6] = outputCur_b2 & 0xff;
-	data[7] = (outputCur_b2 >> 8) & 0xff;
-
-	SendCmdToEvboard(id, data, 8);
-}
-
-void SetPresentOutputCapacity(short aOutputPw_b1, short aOutputCur_b1, short aOutputPw_b2, short aOutputCur_b2)
-{
-	int id = PackageIdCmd(Ev_Cmd.present_output_cap);
-	byte data[8];
-
-	data[0] = aOutputPw_b1 & 0xff;
-	data[1] = (aOutputPw_b1 >> 8) & 0xff;
-	data[2] = aOutputCur_b1 & 0xff;
-	data[3] = (aOutputCur_b1 >> 8) & 0xff;
-	data[4] = aOutputPw_b2 & 0xff;
-	data[5] = (aOutputPw_b2 >> 8) & 0xff;
-	data[6] = aOutputCur_b2 & 0xff;
-	data[7] = (aOutputCur_b2 >> 8) & 0xff;
-
-	SendCmdToEvboard(id, data, 8);
-}
-
-void GetOutputReq(byte gun_index, byte toId)
-{
-	int id = PackageIdCmd(Ev_Cmd.get_output_req + toId);
-	byte data[8];
-
-	SendCmdToEvboard(id, data, 0);
-}
-
-void GetEvBatteryInfo(byte gun_index, byte toId)
-{
-	int id = PackageIdCmd(Ev_Cmd.get_battery_info + toId);
-	byte data[8];
-
-	SendCmdToEvboard(id, data, 0);
-}
-
-void EvseStopChargingEvent(byte stopResult, byte *stopReason, byte toId)
-{
-	int id = PackageIdCmd(Ev_Cmd.evse_stop_charging + toId);
-	byte data[8];
-
-	data[0] = stopResult;
-	data[1] = *stopReason;
-	data[2] = *(stopReason + 1);
-	data[3] = *(stopReason + 2);
-	data[4] = *(stopReason + 3);
-	data[5] = *(stopReason + 4);
-	data[6] = *(stopReason + 5);
-
-	SendCmdToEvboard(id, data, 7);
-}
-
-void GetMiscellaneousInfo(byte gun_index, byte relayStatus, float power, float voltage, byte toId)
-{
-	int id = PackageIdCmd(Ev_Cmd.get_miscellaneous_info + toId);
-	byte data[8];
-
-	int _power = power * 10;
-
-	data[0] = relayStatus;
-	data[1] = (int)_power & 0xff;
-	data[2] = ((int)_power >> 8) & 0xff;
-	data[3] = (int)voltage & 0xff;
-	data[4] = ((int)voltage >> 8) & 0xff;
-
-	SendCmdToEvboard(id, data, 5);
-}
-
-void SetIsolationStatus(byte gun_index, byte result, byte toId)
-{
-	int id = PackageIdCmd(Ev_Cmd.isolation_status + toId);
-	byte data[8];
-
-	data[0] = result;
-	SendCmdToEvboard(id, data, 1);
-}
-
-void SetEvsePrechargeInfo(byte gun_index, byte result, byte toId)
-{
-	int id = PackageIdCmd(Ev_Cmd.evse_precharge_info + toId);
-	byte data[8];
-
-	data[0] = result;
-	SendCmdToEvboard(id, data, 1);
-}
 

+ 12 - 13
EVSE/Projects/DO360/Apps/FactoryConfig.c

@@ -17,12 +17,12 @@
 
 #include 	<unistd.h>
 #include 	<stdarg.h>
-#include    <stdio.h>      /*標準輸入輸出定義*/
-#include    <stdlib.h>     /*標準函數庫定義*/
-#include    <unistd.h>     /*Unix 標準函數定義*/
-#include    <fcntl.h>      /*檔控制定義*/
-#include    <termios.h>    /*PPSIX 終端控制定義*/
-#include    <errno.h>      /*錯誤號定義*/
+#include    <stdio.h>      /*璅蹱�頛詨�頛詨枂摰𡁶儔*/
+#include    <stdlib.h>     /*璅蹱��賣彍摨怠�蝢�*/
+#include    <unistd.h>     /*Unix 璅蹱��賣彍摰𡁶儔*/
+#include    <fcntl.h>      /*瑼娍綉�嗅�蝢�*/
+#include    <termios.h>    /*PPSIX 蝯�垢�批�摰𡁶儔*/
+#include    <errno.h>      /*�航炊�笔�蝢�*/
 #include 	<errno.h>
 #include 	<string.h>
 #include	<time.h>
@@ -80,7 +80,7 @@ void helpOutput(void)
 
 /**************************************************************************************/
 /************This task will create Factory default confgiuration file *****************/
- /***********and store it into mtdblock 10,11,12                               ****************/
+/***********and store it into mtdblock 10,11,12                        ****************/
 /**************************************************************************************/
 int main(int argc,char *argv[])
 {
@@ -105,14 +105,12 @@ int main(int argc,char *argv[])
 	*/
 	//********** System **********// udhcpc -i eth1 -s ./dhcp_script/eth1.script
 	//
-	strcpy((char *)SysConfig.ModelName, "DSYE601J0EE2PH");
-	strcpy((char *)SysConfig.SerialNumber, "SERIALFORRD");
+	strcpy((char *)SysConfig.ModelName, "DOYC182000D2AD");
+	strcpy((char *)SysConfig.SerialNumber, "NeedSetupSN");
 
 	memset(SysConfig.SystemId, 0x00, sizeof(SysConfig.SystemId));
-	char Dash = '-';
 
 	strcat((char *)SysConfig.SystemId, (char *)SysConfig.ModelName);
-	strncat((char *)SysConfig.SystemId, &Dash, 1);
 	strcat((char *)SysConfig.SystemId, (char *)SysConfig.SerialNumber);
 
 	strcpy((char *)SysConfig.SystemDateTime, "");
@@ -130,7 +128,7 @@ int main(int argc,char *argv[])
 	SysConfig.isRFID = 1;
 	//********** Charging **********//
 	SysConfig.MaxChargingEnergy = 0;
-	SysConfig.MaxChargingCurrent = 200;		// 最大可輸出電流 (整樁)
+	SysConfig.MaxChargingCurrent = 200;		// ��憭批虾頛詨枂�餅� (�湔�)
 	SysConfig.MaxChargingDuration = 0;
 	SysConfig.AcMaxChargingCurrent = 0;
 	SysConfig.PhaseLossPolicy = 0;
@@ -145,7 +143,7 @@ int main(int argc,char *argv[])
 	strcpy((char *) SysConfig.Eth0Interface.EthSubmaskAddress, "255.255.255.0");
 	strcpy((char *) SysConfig.Eth0Interface.EthGatewayAddress, "192.168.1.254");
 	SysConfig.Eth1Interface.EthDhcpClient = 0;
-	strcpy((char *) SysConfig.Eth1Interface.EthIpAddress, "192.168.0.10");
+	strcpy((char *) SysConfig.Eth1Interface.EthIpAddress, "192.168.100.1");
 	strcpy((char *) SysConfig.Eth1Interface.EthSubmaskAddress, "255.255.255.0");
 	strcpy((char *) SysConfig.Eth1Interface.EthGatewayAddress, "192.168.0.254");
 	if(SysConfig.ModelName[10] == 'W')
@@ -184,6 +182,7 @@ int main(int argc,char *argv[])
 	SysConfig.OfflineMaxChargeDuration = 0;
 	strcpy((char *) SysConfig.OcppServerURL, "");
 	strcpy((char *) SysConfig.ChargeBoxId, "");
+	SysConfig.LedInfo.Intensity = 2;
 
 	//copy default configuration to pointer
 	memcpy(ptr,&SysConfig,sizeof(struct SysConfigData));

+ 1848 - 3497
EVSE/Projects/DO360/Apps/Module_EvComm.c

@@ -1,3497 +1,1848 @@
-#include 	<sys/time.h>
-#include 	<sys/timeb.h>
-#include    <sys/types.h>
-#include    <sys/stat.h>
-#include 	<sys/types.h>
-#include 	<sys/ioctl.h>
-#include 	<sys/socket.h>
-#include 	<sys/ipc.h>
-#include 	<sys/shm.h>
-#include 	<sys/shm.h>
-#include 	<sys/mman.h>
-#include 	<linux/can.h>
-#include 	<linux/can/raw.h>
-#include 	<linux/wireless.h>
-#include 	<arpa/inet.h>
-#include 	<netinet/in.h>
-
-#include 	<unistd.h>
-#include 	<stdarg.h>
-#include    <stdio.h>      /*標準輸入輸出定義*/
-#include    <stdlib.h>     /*標準函數庫定義*/
-#include    <unistd.h>     /*Unix 標準函數定義*/
-#include    <fcntl.h>      /*檔控制定義*/
-#include    <termios.h>    /*PPSIX 終端控制定義*/
-#include    <errno.h>      /*錯誤號定義*/
-#include 	<errno.h>
-#include 	<string.h>
-#include	<time.h>
-#include	<ctype.h>
-#include 	<ifaddrs.h>
-#include	"../../define.h"
-#include 	"Module_EvComm.h"
-
-#define ARRAY_SIZE(A)		(sizeof(A) / sizeof(A[0]))
-#define PASS				1
-#define FAIL				-1
-#define START				1
-#define STOP				0
-#define YES					1
-#define NO					0
-#define EQUAL				0
-
-struct SysConfigAndInfo			*ShmSysConfigAndInfo;
-struct StatusCodeData 			*ShmStatusCodeData;
-struct FanModuleData			*ShmFanModuleData;
-struct CHAdeMOData				*ShmCHAdeMOData;
-struct GBTData					*ShmGBTData;
-struct CcsData					*ShmCcsData;
-
-byte gun_count;
-int chargingTime[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
-struct timeval _chk_ratingPower_timeout[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
-
-float _pow_1 = 0;
-float _cur_1 = 0;
-float _pow_2 = 0;
-float _cur_2 = 0;
-
-float _outVol_1 = 0;
-float _outCur_1 = 0;
-float _outVol_2 = 0;
-float _outCur_2 = 0;
-
-// 限制最大充電電壓,因應不同 type 槍線來限制
-// Chademo : 500V, 125A,
-// GB : 750, 120A
-// CCS : 950V, 120A
-float maxChargingVol[2] = { 5000, 9500 };			// 限制最大充電電壓,如依照模塊則填上 0
-// 限制最大充電電流與能量透過 Web
-float maxChargingCur[2] = { 1200, 1200 };			// 限制最大充電電流,如依照模塊則填上 0
-float maxChargingPow = 0;							// 限制最大充電能量,如依照模塊則填上 0
-
-// 槍資訊
-struct ChargingInfoData *_chargingData[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
-
-struct Ev_Board_Cmd Ev_Cmd={
-		0,
-		0x00000200,
-		0x00000400,
-		0x00000500,
-		0x00000600,
-		0x00000700,
-		0x00000800,
-		0x00000900,
-		0x00000A00,
-		0x00000C00,
-		0x00000D00,
-
-		0x00000E00,
-		0x00000F00,
-		0x00001000,
-		0x00001100,
-
-		0x00001200,
-		0x00001400,
-		0x00001500,
-};
-
-unsigned char mask_table[] = { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 };
-
-void PRINTF_FUNC(char *string, ...);
-
-void GetMaxVolAndCurMethod(byte index, float *vol, float *cur);
-void GetMaxPowerMethod(float *pow);
-unsigned long GetTimeoutValue(struct timeval _sour_time);
-
-#define DEBUG_INFO(format, args...) StoreLogMsg("[%s:%d][%s][Info] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
-#define DEBUG_WARN(format, args...) StoreLogMsg("[%s:%d][%s][Warn] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
-#define DEBUG_ERROR(format, args...) StoreLogMsg("[%s:%d][%s][Error] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
-
-unsigned long GetTimeoutValue(struct timeval _sour_time)
-{
-	struct timeval _end_time;
-	gettimeofday(&_end_time, NULL);
-
-	return 1000000 * (_end_time.tv_sec - _sour_time.tv_sec) + _end_time.tv_usec - _sour_time.tv_usec;
-}
-
-int StoreLogMsg(const char *fmt, ...)
-{
-	char Buf[4096+256];
-	char buffer[4096];
-	va_list args;
-	struct timeb  SeqEndTime;
-	struct tm *tm;
-
-	va_start(args, fmt);
-	int rc = vsnprintf(buffer, sizeof(buffer), fmt, args);
-	va_end(args);
-
-	memset(Buf,0,sizeof(Buf));
-	ftime(&SeqEndTime);
-	SeqEndTime.time = time(NULL);
-	tm=localtime(&SeqEndTime.time);
-
-	if (ShmSysConfigAndInfo->SysConfig.SwitchDebugFlag == YES)
-	{
-		sprintf(Buf,"%02d:%02d:%02d:%03d - %s",
-			tm->tm_hour,tm->tm_min,tm->tm_sec,SeqEndTime.millitm, buffer);
-		printf("%s \n", Buf);
-	}
-	else
-	{
-		sprintf(Buf,"echo \"%04d-%02d-%02d %02d:%02d:%02d:%03d - %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,SeqEndTime.millitm,
-			buffer,
-			tm->tm_year+1900,tm->tm_mon+1);
-		system(Buf);
-	}
-
-	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 PRINTF_FUNC(char *string, ...)
-{
-	va_list args;
-	char buffer[4096];
-	va_start(args, string);
-	vsnprintf(buffer, sizeof(buffer), string, args);
-	va_end(args);
-
-	DEBUG_INFO("%s \n", buffer);
-}
-
-//=================================
-// Common routine
-//=================================
-void getTimeString(char *buff)
-{
-	time_t timep;
-	struct tm *p;
-	time(&timep);
-	p=gmtime(&timep);
-
-	sprintf(buff, "[%04d-%02d-%02d %02d:%02d:%02d]", (1900+p->tm_year), (1+p->tm_mon), p->tm_mday, p->tm_hour, p->tm_hour, p->tm_sec);
-}
-
-bool CheckUniqNumber(byte value)
-{
-	for (byte index = 0; index < gun_count; index++)
-	{
-		if (_chargingData[index]->Evboard_id == value)
-		{
-			struct timeval _end_time;
-			gettimeofday(&_end_time, NULL);
-			unsigned long diff = 1000000 *	(_end_time.tv_sec - _id_assign_time.tv_sec) + _end_time.tv_usec - _id_assign_time.tv_usec;
-			if (diff >= 3000000)
-			{
-				gettimeofday(&_id_assign_time, NULL);
-				return true;
-			}
-			else
-			{
-				return false;
-			}
-		}
-	}
-
-	gettimeofday(&_id_assign_time, NULL);
-	return true;
-}
-
-//==========================================
-// Init all share memory
-//==========================================
-int InitShareMemory()
-{
-	int result = PASS;
-	int MeterSMId;
-
-	//initial 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
-    {}
-
-   	 //initial 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
-    {}
-
-   	if(CHAdeMO_QUANTITY > 0)
-   	{
-   		if ((MeterSMId = shmget(ShmCHAdeMOCommKey, sizeof(struct CHAdeMOData),	IPC_CREAT | 0777)) < 0)
-   		{
-   			#ifdef SystemLogMessage
-   		   	DEBUG_ERROR("[shmget ShmCHAdeMOData NG \n");
-   			#endif
-   			return FAIL;
-   		}
-   		else if ((ShmCHAdeMOData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
-   		{
-   			#ifdef SystemLogMessage
-   		   	DEBUG_ERROR("shmat ShmCHAdeMOData NG \n");
-   			#endif
-   			return FAIL;
-   		}
-   		else
-   		{}
-   	}
-	if(GB_QUANTITY > 0)
-	{
-		if ((MeterSMId = shmget(ShmGBTCommKey, sizeof(struct GBTData),	IPC_CREAT | 0777)) < 0)
-	   	{
-	   		#ifdef SystemLogMessage
-	   		DEBUG_ERROR("[shmget ShmGBTData NG \n");
-	   		#endif
-	   		return FAIL;
-	   	}
-	   	else if ((ShmGBTData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
-	   	{
-	   		#ifdef SystemLogMessage
-	   		DEBUG_ERROR("shmat ShmGBTData NG \n");
-	   		#endif
-	   		return FAIL;
-	   	}
-	   	else
-	   	{}
-	}
-
-   	if(CCS_QUANTITY > 0)
-   	{
-   		if ((MeterSMId = shmget(ShmCcsCommKey, sizeof(struct CcsData),	IPC_CREAT | 0777)) < 0)
-   		{
-   			#ifdef SystemLogMessage
-   			DEBUG_ERROR("shmget ShmCcsData NG \n");
-   			#endif
-   			return FAIL;
-   		}
-   		else if ((ShmCcsData = shmat(MeterSMId, NULL, 0)) == (void *) -1) {
-   			#ifdef SystemLogMessage
-   		   	DEBUG_ERROR("shmat ShmCcsData NG \n");
-   			#endif
-   			return FAIL;
-   		}
-   		else
-   		{}
-   	}
-
-    return result;
-}
-
-//================================================
-// initial can-bus
-//================================================
-int InitCanBus()
-{
-	int 					s0,nbytes;
-	struct timeval			tv;
-	struct ifreq 			ifr0;
-	struct sockaddr_can		addr0;
-
-	system("/sbin/ip link set can0 down");
-	system("/sbin/ip link set can0 type can bitrate 500000 restart-ms 100");
-	system("/sbin/ip link set can0 up");
-
-	s0 = socket(PF_CAN, SOCK_RAW, CAN_RAW);
-
-	tv.tv_sec = 0;
-	tv.tv_usec = 10000;
-   	if (setsockopt(s0, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv, sizeof(struct	timeval)) < 0)
-	{
-		#ifdef SystemLogMessage
-		DEBUG_ERROR("Set SO_RCVTIMEO NG");
-		#endif
-	}
-	nbytes=40960;
-	if (setsockopt(s0, SOL_SOCKET,  SO_RCVBUF, &nbytes, sizeof(int)) < 0)
-	{
-		#ifdef SystemLogMessage
-		DEBUG_ERROR("Set SO_RCVBUF NG");
-		#endif
-	}
-	nbytes=40960;
-	if (setsockopt(s0, SOL_SOCKET, SO_SNDBUF, &nbytes, sizeof(int)) < 0)
-	{
-		#ifdef SystemLogMessage
-		DEBUG_ERROR("Set SO_SNDBUF NG");
-		#endif
-	}
-
-   	strcpy(ifr0.ifr_name, "can0" );
-	ioctl(s0, SIOCGIFINDEX, &ifr0); /* ifr.ifr_ifindex gets filled with that device's index */
-	addr0.can_family = AF_CAN;
-	addr0.can_ifindex = ifr0.ifr_ifindex;
-	bind(s0, (struct sockaddr *)&addr0, sizeof(addr0));
-	return s0;
-}
-
-//================================================
-//================================================
-// CANBUS receive task
-//================================================
-//================================================
-bool FindChargingInfoData(byte target, struct ChargingInfoData **chargingData)
-{
-	for (byte index = 0; index < CHAdeMO_QUANTITY; index++)
-	{
-		if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == target)
-		{
-			chargingData[target] = &ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index];
-			return true;
-		}
-	}
-
-	for (byte index = 0; index < CCS_QUANTITY; index++)
-	{
-		if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == target)
-		{
-			chargingData[target] = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[index];
-			return true;
-		}
-	}
-
-	for (byte index = 0; index < GB_QUANTITY; index++)
-	{
-		if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == target)
-		{
-			chargingData[target] = &ShmSysConfigAndInfo->SysInfo.GbChargingData[index];
-			return true;
-		}
-	}
-
-	return false;
-}
-
-void AddrAssignment(byte *data)
-{
-	byte target_number[8];
-	byte index = 0x00;
-
-	memcpy(target_number, data, sizeof(target_number));
-	index = *(data + 4);
-
-	if (gun_count == 1)
-		index = 0x01;
-//	if (CheckUniqNumber(index))
-	{
-		PRINTF_FUNC("EV board id = %x \n", index);
-//		PRINTF_FUNC("target_number[0] = %x \n", target_number[0]);
-//		PRINTF_FUNC("target_number[1] = %x \n", target_number[1]);
-//		PRINTF_FUNC("target_number[2] = %x \n", target_number[2]);
-//		PRINTF_FUNC("target_number[3] = %x \n", target_number[3]);
-//		PRINTF_FUNC("target_number[4] = %x \n", target_number[4]);
-
-		PRINTF_FUNC("SetTargetAddr = %d, type = %d \n", index, _chargingData[index - 1]->Type);
-		SetTargetAddr(target_number, index);
-	}
-}
-
-void ClearAbnormalStatus_Chademo(byte gun_index)
-{
-	bool isCleanCheck = false;
-	char code[7];
-
-	if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "", 6) == EQUAL)
-		return;
-
-	if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023700", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoEvCommFail == YES)
-	{
-		memcpy(code, "023700", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023704", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBatteryMalfun == YES)
-	{
-		memcpy(code, "023704", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023705", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoNoPermission == YES)
-	{
-		memcpy(code, "023705", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023706", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBatteryIncompatibility == YES)
-	{
-		memcpy(code, "023706", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023707", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBatteryOVP == YES)
-	{
-		memcpy(code, "023707", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023708", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBatteryUVP == YES)
-	{
-		memcpy(code, "023708", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023709", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBatteryOTP == YES)
-	{
-		memcpy(code, "023709", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023710", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBatteryCurrentDiff == YES)
-	{
-		memcpy(code, "023710", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023711", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBatteryVoltageDiff == YES)
-	{
-		memcpy(code, "023711", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023712", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoShiftPosition == YES)
-	{
-		memcpy(code, "023712", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023713", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBatteryOtherFault == YES)
-	{
-		memcpy(code, "023713", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023714", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoChargingSystemError == YES)
-	{
-		memcpy(code, "023714", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023715", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoEvNormalStop == YES)
-	{
-		memcpy(code, "023715", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023716", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoTempSensorBroken == YES)
-	{
-		memcpy(code, "023716", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023717", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoConnectorLockFail == YES)
-	{
-		memcpy(code, "023717", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023718", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoD1OnNoReceive == YES)
-	{
-		memcpy(code, "023718", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023719", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBmsKtoJTimeout == YES)
-	{
-		memcpy(code, "023719", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023720", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBmsChargeAllowTimeout == YES)
-	{
-		memcpy(code, "023720", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023721", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoWaitGfdTimeout == YES)
-	{
-		memcpy(code, "023721", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023722", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBmsEvRelayTimeout == YES)
-	{
-		memcpy(code, "023722", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023723", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBmsReqCurrentTimeout == YES)
-	{
-		memcpy(code, "023723", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023724", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBmsKtoJOffTimeout == YES)
-	{
-		memcpy(code, "023724", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023725", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBmsEvRelayOffTimeout == YES)
-	{
-		memcpy(code, "023725", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023726", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoAdcMoreThan10V == YES)
-	{
-		memcpy(code, "023726", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023727", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoAdcMoreThan20V == YES)
-	{
-		memcpy(code, "023727", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023728", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBmsChargeBeforeStop == YES)
-	{
-		memcpy(code, "023728", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023729", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoChargerGetNormalStop == YES)
-	{
-		memcpy(code, "023729", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023730", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoChargerGetEmergencyStop == YES)
-	{
-		memcpy(code, "023730", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023731", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoIsolationResultFail == YES)
-	{
-		memcpy(code, "023731", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023732", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoMissLinkWithMotherBoard == YES)
-	{
-		memcpy(code, "023732", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023733", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoOutputVolMoreThanLimit == YES)
-	{
-		memcpy(code, "023733", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023734", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoReqCurrentMoreThanLimit == YES)
-	{
-		memcpy(code, "023734", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023735", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoReCapBmsEqrCurrentExceed == YES)
-	{
-		memcpy(code, "023735", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023736", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoChargeRemainCountDown == YES)
-	{
-		memcpy(code, "023736", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-
-	if (isCleanCheck)
-	{
-		for (byte index = 0; index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; index++)
-		{
-			if (index != gun_index || ShmSysConfigAndInfo->SysConfig.TotalConnectorCount == 1)
-			{
-				PRINTF_FUNC("CHA clean error : index = %d, EvConnAlarmCode = %s, code = %s \n", index, _chargingData[index]->EvConnAlarmCode, code);
-				if (strncmp((char *)_chargingData[index]->EvConnAlarmCode, code, 6) != EQUAL)
-				{
-					if (strncmp(code, "023700", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoEvCommFail = NO;
-					if (strncmp(code, "023704", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBatteryMalfun = NO;
-					if (strncmp(code, "023705", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoNoPermission = NO;
-					if (strncmp(code, "023706", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBatteryIncompatibility = NO;
-					if (strncmp(code, "023707", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBatteryOVP = NO;
-					if (strncmp(code, "023708", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBatteryUVP = NO;
-					if (strncmp(code, "023709", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBatteryOTP = NO;
-					if (strncmp(code, "023710", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBatteryCurrentDiff = NO;
-					if (strncmp(code, "023711", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBatteryVoltageDiff = NO;
-					if (strncmp(code, "023712", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoShiftPosition = NO;
-					if (strncmp(code, "023713", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBatteryOtherFault = NO;
-					if (strncmp(code, "023714", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoChargingSystemError = NO;
-					if (strncmp(code, "023715", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoEvNormalStop = NO;
-					if (strncmp(code, "023716", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoTempSensorBroken = NO;
-					if (strncmp(code, "023717", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoConnectorLockFail = NO;
-					if (strncmp(code, "023718", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoD1OnNoReceive = NO;
-					if (strncmp(code, "023719", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBmsKtoJTimeout = NO;
-					if (strncmp(code, "023720", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBmsChargeAllowTimeout = NO;
-					if (strncmp(code, "023721", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoWaitGfdTimeout = NO;
-					if (strncmp(code, "023722", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBmsEvRelayTimeout = NO;
-					if (strncmp(code, "023723", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBmsReqCurrentTimeout = NO;
-					if (strncmp(code, "023724", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBmsKtoJOffTimeout = NO;
-					if (strncmp(code, "023725", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBmsEvRelayOffTimeout = NO;
-					if (strncmp(code, "023726", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoAdcMoreThan10V = NO;
-					if (strncmp(code, "023727", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoAdcMoreThan20V = NO;
-					if (strncmp(code, "023728", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBmsChargeBeforeStop = NO;
-					if (strncmp(code, "023729", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoChargerGetNormalStop = NO;
-					if (strncmp(code, "023730", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoChargerGetEmergencyStop = NO;
-					if (strncmp(code, "023731", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoIsolationResultFail = NO;
-					if (strncmp(code, "023732", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoMissLinkWithMotherBoard = NO;
-					if (strncmp(code, "023733", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoOutputVolMoreThanLimit = NO;
-					if (strncmp(code, "023734", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoReqCurrentMoreThanLimit = NO;
-					if (strncmp(code, "023735", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoReCapBmsEqrCurrentExceed = NO;
-					if (strncmp(code, "023736", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoChargeRemainCountDown = NO;
-				}
-			}
-		}
-	}
-}
-
-void ClearAbnormalStatus_GB(byte gun_index)
-{
-	bool isCleanCheck = false;
-	char code[7];
-
-	if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "", 6) == EQUAL)
-		return;
-
-	if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023702", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.GbEvCommFail == YES)
-	{
-		memcpy(code, "023702", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023900", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_LOS_CC1 == YES)
-	{
-		memcpy(code, "023900", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023901", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_CONNECTOR_LOCK_FAIL == YES)
-	{
-		memcpy(code, "023901", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023902", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_BATTERY_INCOMPATIBLE == YES)
-	{
-		memcpy(code, "023902", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023903", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_BMS_BROAA_TIMEOUT == YES)
-	{
-		memcpy(code, "023903", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023904", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_CSU_PRECHARGE_TIMEOUT == YES)
-	{
-		memcpy(code, "023904", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023905", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_BMS_PRESENT_VOLTAGE_FAULT == YES)
-	{
-		memcpy(code, "023905", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023906", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_BMS_VOLTAGE_OVER_RANGE == YES)
-	{
-		memcpy(code, "023906", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023907", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_BSM_CHARGE_ALLOW_00_10MIN_COUUNTDONE == YES)
-	{
-		memcpy(code, "023907", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023908", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_WAIT_GROUNDFAULT_TIMEOUT == YES)
-	{
-		memcpy(code, "023908", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023909", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_ADC_MORE_THAN_10V == YES)
-	{
-		memcpy(code, "023909", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023910", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_ADC_MORE_THAN_60V == YES)
-	{
-		memcpy(code, "023910", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023911", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_CHARGER_GET_NORMAL_STOP_CMD == YES)
-	{
-		memcpy(code, "023911", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023912", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_CHARGER_GET_EMERGENCY_STOP_CMD == YES)
-	{
-		memcpy(code, "023912", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023913", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_ISOLATION_RESULT_FAIL == YES)
-	{
-		memcpy(code, "023913", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023914", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_MOTHER_BOARD_MISS_LINK == YES)
-	{
-		memcpy(code, "023914", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023915", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_OUTPUT_VOLTAGE_MORE_THAN_LIMIT == YES)
-	{
-		memcpy(code, "023915", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023916", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_REQ_CURRENT_MORE_THAN_LIMIT == YES)
-	{
-		memcpy(code, "023916", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023917", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_OUTPUT_VOLTAGE_MORE_THAN_10_PERCENT == YES)
-	{
-		memcpy(code, "023917", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023918", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_OUTPUT_VOLTAGE_DIFF_BCS_5_PERCENT == YES)
-	{
-		memcpy(code, "023918", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023919", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_STOP_ADC_MORE_THAN_10V == YES)
-	{
-		memcpy(code, "023919", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023930", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_CEM_BHM_TIMEOUT == YES)
-	{
-		memcpy(code, "023930", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023931", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_CEM_BRM_TIMEOUT == YES)
-	{
-		memcpy(code, "023931", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023932", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_CEM_BCP_TIMEOUT == YES)
-	{
-		memcpy(code, "023932", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023933", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_CEM_BRO_TIMEOUT == YES)
-	{
-		memcpy(code, "023933", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023934", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_CEM_BCL_TIMEOUT == YES)
-	{
-		memcpy(code, "023934", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023935", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_CEM_BCS_TIMEOUT == YES)
-	{
-		memcpy(code, "023935", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023936", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_CEM_BSM_TIMEOUT == YES)
-	{
-		memcpy(code, "023936", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023937", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_CEM_BST_TIMEOUT == YES)
-	{
-		memcpy(code, "023937", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023938", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_CEM_BSD_TIMEOUT == YES)
-	{
-		memcpy(code, "023938", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023939", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_CEM_BEM_OTHER_TIMEOUT == YES)
-	{
-		memcpy(code, "023939", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023940", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BEM_CRM_TIMEOUT == YES)
-	{
-		memcpy(code, "023940", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023941", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BEM_CRMAA_TIMEOUT == YES)
-	{
-		memcpy(code, "023941", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023942", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BEM_CTS_CML_TIMEOUT == YES)
-	{
-		memcpy(code, "023942", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023943", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BEM_CRO_TIMEOUT == YES)
-	{
-		memcpy(code, "023943", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023944", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BEM_CCS_TIMEOUT == YES)
-	{
-		memcpy(code, "023944", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023945", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BEM_CST_TIMEOUT == YES)
-	{
-		memcpy(code, "023945", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023946", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BEM_CSD_TIMEOUT == YES)
-	{
-		memcpy(code, "023946", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023947", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BEM_BEM_OTHER_TIMEOUT == YES)
-	{
-		memcpy(code, "023947", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023950", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_SOC_GOAL == YES)
-	{
-		memcpy(code, "023950", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023951", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_TOTAL_VOLTAGE_GOAL == YES)
-	{
-		memcpy(code, "023951", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023952", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_CELL_VOLTAGE_GOAL == YES)
-	{
-		memcpy(code, "023952", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023953", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_GET_CST == YES)
-	{
-		memcpy(code, "023953", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023954", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_ISOLATION == YES)
-	{
-		memcpy(code, "023954", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023955", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_OUTPUT_CONNECTOR_OTP == YES)
-	{
-		memcpy(code, "023955", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023956", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_COMPONENT == YES)
-	{
-		memcpy(code, "023956", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023957", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_CHARGE_CONNECTOR == YES)
-	{
-		memcpy(code, "023957", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023958", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_OTP == YES)
-	{
-		memcpy(code, "023958", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023959", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_OTHER == YES)
-	{
-		memcpy(code, "023959", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023960", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_HIGH_V == YES)
-	{
-		memcpy(code, "023960", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023961", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_CC2 == YES)
-	{
-		memcpy(code, "023961", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023962", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_CURRENT == YES)
-	{
-		memcpy(code, "023962", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023963", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_VOLTAGE == YES)
-	{
-		memcpy(code, "023963", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023964", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GET_BST_NO_REASON == YES)
-	{
-		memcpy(code, "023964", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023970", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BSM_CELL_OVER_VOLTAGE == YES)
-	{
-		memcpy(code, "023970", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023971", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BSM_CELL_UNDER_VOLTAGE == YES)
-	{
-		memcpy(code, "023971", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023972", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BSM_OVER_SOC == YES)
-	{
-		memcpy(code, "023972", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023973", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BSM_UNDER_SOC == YES)
-	{
-		memcpy(code, "023973", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023974", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BSM_CURRENT == YES)
-	{
-		memcpy(code, "023974", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023975", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BSM_TEMPERATURE == YES)
-	{
-		memcpy(code, "023975", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023976", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BSM_ISOLATE == YES)
-	{
-		memcpy(code, "023976", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023977", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BSM_OUTPUT_CONNECTOR == YES)
-	{
-		memcpy(code, "023977", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-
-	if (isCleanCheck)
-	{
-		for (byte index = 0; index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; index++)
-		{
-			if (index != gun_index || ShmSysConfigAndInfo->SysConfig.TotalConnectorCount == 1)
-			{
-				PRINTF_FUNC("GBT clean error : index = %d, EvConnAlarmCode = %s, code = %s \n", index, _chargingData[index]->EvConnAlarmCode, code);
-				if (strncmp((char *)_chargingData[index]->EvConnAlarmCode, code, 6) != EQUAL)
-				{
-					if (strncmp(code, "023702", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.GbEvCommFail = NO;
-					if (strncmp(code, "023900", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_LOS_CC1 = NO;
-					if (strncmp(code, "023901", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_CONNECTOR_LOCK_FAIL = NO;
-					if (strncmp(code, "023902", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_BATTERY_INCOMPATIBLE = NO;
-					if (strncmp(code, "023903", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_BMS_BROAA_TIMEOUT = NO;
-					if (strncmp(code, "023904", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_CSU_PRECHARGE_TIMEOUT = NO;
-					if (strncmp(code, "023905", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_BMS_PRESENT_VOLTAGE_FAULT = NO;
-					if (strncmp(code, "023906", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_BMS_VOLTAGE_OVER_RANGE = NO;
-					if (strncmp(code, "023907", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_BSM_CHARGE_ALLOW_00_10MIN_COUUNTDONE = NO;
-					if (strncmp(code, "023908", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_WAIT_GROUNDFAULT_TIMEOUT = NO;
-					if (strncmp(code, "023909", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_ADC_MORE_THAN_10V = NO;
-					if (strncmp(code, "023910", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_ADC_MORE_THAN_60V = NO;
-					if (strncmp(code, "023911", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_CHARGER_GET_NORMAL_STOP_CMD = NO;
-					if (strncmp(code, "023912", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_CHARGER_GET_EMERGENCY_STOP_CMD = NO;
-					if (strncmp(code, "023913", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_ISOLATION_RESULT_FAIL = NO;
-					if (strncmp(code, "023914", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_MOTHER_BOARD_MISS_LINK = NO;
-					if (strncmp(code, "023915", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_OUTPUT_VOLTAGE_MORE_THAN_LIMIT = NO;
-					if (strncmp(code, "023916", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_REQ_CURRENT_MORE_THAN_LIMIT = NO;
-					if (strncmp(code, "023917", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_OUTPUT_VOLTAGE_MORE_THAN_10_PERCENT = NO;
-					if (strncmp(code, "023918", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_OUTPUT_VOLTAGE_DIFF_BCS_5_PERCENT = NO;
-					if (strncmp(code, "023919", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_STOP_ADC_MORE_THAN_10V = NO;
-					if (strncmp(code, "023930", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_CEM_BHM_TIMEOUT = NO;
-					if (strncmp(code, "023931", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_CEM_BRM_TIMEOUT = NO;
-					if (strncmp(code, "023932", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_CEM_BCP_TIMEOUT = NO;
-					if (strncmp(code, "023933", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_CEM_BRO_TIMEOUT = NO;
-					if (strncmp(code, "023934", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_CEM_BCL_TIMEOUT = NO;
-					if (strncmp(code, "023935", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_CEM_BCS_TIMEOUT = NO;
-					if (strncmp(code, "023936", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_CEM_BSM_TIMEOUT = NO;
-					if (strncmp(code, "023937", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_CEM_BST_TIMEOUT = NO;
-					if (strncmp(code, "023938", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_CEM_BSD_TIMEOUT = NO;
-					if (strncmp(code, "023939", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_CEM_BEM_OTHER_TIMEOUT = NO;
-					if (strncmp(code, "023940", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BEM_CRM_TIMEOUT = NO;
-					if (strncmp(code, "023941", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BEM_CRMAA_TIMEOUT = NO;
-					if (strncmp(code, "023942", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BEM_CTS_CML_TIMEOUT = NO;
-					if (strncmp(code, "023943", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BEM_CRO_TIMEOUT = NO;
-					if (strncmp(code, "023944", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BEM_CCS_TIMEOUT = NO;
-					if (strncmp(code, "023945", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BEM_CST_TIMEOUT = NO;
-					if (strncmp(code, "023946", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BEM_CSD_TIMEOUT = NO;
-					if (strncmp(code, "023947", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BEM_BEM_OTHER_TIMEOUT = NO;
-					if (strncmp(code, "023950", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_SOC_GOAL = NO;
-					if (strncmp(code, "023951", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_TOTAL_VOLTAGE_GOAL = NO;
-					if (strncmp(code, "023952", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_CELL_VOLTAGE_GOAL = NO;
-					if (strncmp(code, "023953", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_GET_CST = NO;
-					if (strncmp(code, "023954", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_ISOLATION = NO;
-					if (strncmp(code, "023955", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_OUTPUT_CONNECTOR_OTP = NO;
-					if (strncmp(code, "023956", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_COMPONENT = NO;
-					if (strncmp(code, "023957", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_CHARGE_CONNECTOR = NO;
-					if (strncmp(code, "023958", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_OTP = NO;
-					if (strncmp(code, "023959", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_OTHER = NO;
-					if (strncmp(code, "023960", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_HIGH_V = NO;
-					if (strncmp(code, "023961", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_CC2 = NO;
-					if (strncmp(code, "023962", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_CURRENT = NO;
-					if (strncmp(code, "023963", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_VOLTAGE = NO;
-					if (strncmp(code, "023964", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GET_BST_NO_REASON = NO;
-					if (strncmp(code, "023970", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BSM_CELL_OVER_VOLTAGE = NO;
-					if (strncmp(code, "023971", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BSM_CELL_UNDER_VOLTAGE = NO;
-					if (strncmp(code, "023972", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BSM_OVER_SOC = NO;
-					if (strncmp(code, "023973", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BSM_UNDER_SOC = NO;
-					if (strncmp(code, "023974", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BSM_CURRENT = NO;
-					if (strncmp(code, "023975", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BSM_TEMPERATURE = NO;
-					if (strncmp(code, "023976", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BSM_ISOLATE = NO;
-					if (strncmp(code, "023977", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BSM_OUTPUT_CONNECTOR = NO;
-				}
-			}
-		}
-	}
-}
-
-void ClearAbnormalStatus_CCS(byte gun_index)
-{
-	bool isCleanCheck = false;
-	char code[7];
-
-	if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "", 6) == EQUAL)
-		return;
-
-	if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023701", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsEvCommFail == YES)
-	{
-		memcpy(code, "023701", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023737", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsRESTemperatureInhibit == YES)
-	{
-		memcpy(code, "023737", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023738", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsEVShiftPosition == YES)
-	{
-		memcpy(code, "023738", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023739", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsChargerConnectorLockFault == YES)
-	{
-		memcpy(code, "023739", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023740", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsEVRESSMalfunction == YES)
-	{
-		memcpy(code, "023740", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023741", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsChargingCurrentdifferential == YES)
-	{
-		memcpy(code, "023741", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023742", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsChargingVoltageOutOfRange == YES)
-	{
-		memcpy(code, "023742", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023743", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsChargingSystemIncompatibility == YES)
-	{
-		memcpy(code, "023743", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023744", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsEmergencyEvent == YES)
-	{
-		memcpy(code, "023744", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023745", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsBreaker == YES)
-	{
-		memcpy(code, "023745", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023746", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsNoData == YES)
-	{
-		memcpy(code, "023746", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023747", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_DIN_A == YES)
-	{
-		memcpy(code, "023747", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023748", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_DIN_B == YES)
-	{
-		memcpy(code, "023748", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023749", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_DIN_C == YES)
-	{
-		memcpy(code, "023749", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023750", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_ISO_1 == YES)
-	{
-		memcpy(code, "023750", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023751", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_ISO_2 == YES)
-	{
-		memcpy(code, "023751", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023752", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_ISO_3 == YES)
-	{
-		memcpy(code, "023752", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023753", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_OEM_1 == YES)
-	{
-		memcpy(code, "023753", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023754", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_OEM_2 == YES)
-	{
-		memcpy(code, "023754", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023755", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_OEM_3 == YES)
-	{
-		memcpy(code, "023755", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023756", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_OEM_4 == YES)
-	{
-		memcpy(code, "023756", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023757", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_OEM_5 == YES)
-	{
-		memcpy(code, "023757", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023758", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSequenceError == YES)
-	{
-		memcpy(code, "023758", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023759", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSignatureError == YES)
-	{
-		memcpy(code, "023759", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023760", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsUnknownSession == YES)
-	{
-		memcpy(code, "023760", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023761", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsServiceIDInvalid == YES)
-	{
-		memcpy(code, "023761", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023762", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsPaymentSelectionInvalid == YES)
-	{
-		memcpy(code, "023762", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023763", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsIdentificationSelectionInvalid == YES)
-	{
-		memcpy(code, "023763", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023764", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsServiceSelectionInvalid == YES)
-	{
-		memcpy(code, "023764", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023765", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCertificateExpired == YES)
-	{
-		memcpy(code, "023765", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023766", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCertificateNotYetValid == YES)
-	{
-		memcpy(code, "023766", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023767", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCertificateRevoked == YES)
-	{
-		memcpy(code, "023767", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023768", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsNoCertificateAvailable == YES)
-	{
-		memcpy(code, "023768", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023769", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCertChainError == YES)
-	{
-		memcpy(code, "023769", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023770", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCertValidationError == YES)
-	{
-		memcpy(code, "023770", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023771", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCertVerificationError == YES)
-	{
-		memcpy(code, "023771", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023772", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsContractCanceled == YES)
-	{
-		memcpy(code, "023772", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023773", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsChallengeInvalid == YES)
-	{
-		memcpy(code, "023773", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023774", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsWrongEnergyTransferMode == YES)
-	{
-		memcpy(code, "023774", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023775", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsWrongChargeParameter == YES)
-	{
-		memcpy(code, "023775", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023776", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsChargingProfileInvalid == YES)
-	{
-		memcpy(code, "023776", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023777", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTariffSelectionInvalid == YES)
-	{
-		memcpy(code, "023777", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023778", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsEVSEPresentVoltageToLow == YES)
-	{
-		memcpy(code, "023778", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023779", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsPowerDeliveryNotApplied == YES)
-	{
-		memcpy(code, "023779", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023780", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsMeteringSignatureNotValid == YES)
-	{
-		memcpy(code, "023780", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023781", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsNoChargeServiceSelected == YES)
-	{
-		memcpy(code, "023781", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023782", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsContactorError == YES)
-	{
-		memcpy(code, "023782", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023783", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCertificateNotAllowedAtThisEVSE == YES)
-	{
-		memcpy(code, "023783", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023784", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsGAChargeStop == YES)
-	{
-		memcpy(code, "023784", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023785", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsAlignmentError == YES)
-	{
-		memcpy(code, "023785", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023786", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsACDError == YES)
-	{
-		memcpy(code, "023786", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023787", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsAssociationError == YES)
-	{
-		memcpy(code, "023787", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023788", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsEVSEChargeAbort == YES)
-	{
-		memcpy(code, "023788", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023789", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsNoSupportedAppProtocol == YES)
-	{
-		memcpy(code, "023789", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023790", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsContractNotAccepted == YES)
-	{
-		memcpy(code, "023790", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023791", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsMOUnknown == YES)
-	{
-		memcpy(code, "023791", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023792", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsOEM_Prov_CertificateRevoke == YES)
-	{
-		memcpy(code, "023792", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023793", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsOEM_SubCA1_CertificateRevoked == YES)
-	{
-		memcpy(code, "023793", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023794", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsOEM_SubCA2_CertificateRevoked == YES)
-	{
-		memcpy(code, "023794", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023795", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsOEM_RootCA_CertificateRevoked == YES)
-	{
-		memcpy(code, "023795", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023796", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsMO_Prov_CertificateRevoked == YES)
-	{
-		memcpy(code, "023796", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023797", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsMO_SubCA1_CertificateRevoked == YES)
-	{
-		memcpy(code, "023797", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023798", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsMO_SubCA2_CertificateRevoked == YES)
-	{
-		memcpy(code, "023798", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023799", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsMO_RootCA_CertificateRevoked == YES)
-	{
-		memcpy(code, "023799", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023800", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCPS_Prov_CertificateRevoked == YES)
-	{
-		memcpy(code, "023800", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023801", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCPS_SubCA1_CertificateRevoked == YES)
-	{
-		memcpy(code, "023801", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023802", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCPS_SubCA2_CertificateRevoked == YES)
-	{
-		memcpy(code, "023802", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023803", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCPS_RootCA_CertificateRevoked == YES)
-	{
-		memcpy(code, "023803", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023809", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_EVSE_SLAC_init == YES)
-	{
-		memcpy(code, "023809", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023810", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_match_response == YES)
-	{
-		memcpy(code, "023810", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023811", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_match_sequence == YES)
-	{
-		memcpy(code, "023811", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023812", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_EVSE_match_MNBC == YES)
-	{
-		memcpy(code, "023812", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023813", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_EVSE_avg_atten_calc == YES)
-	{
-		memcpy(code, "023813", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023814", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_match_response == YES)
-	{
-		memcpy(code, "023814", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023815", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_EVSE_match_session == YES)
-	{
-		memcpy(code, "023815", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023816", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_EVSE_assoc_session == YES)
-	{
-		memcpy(code, "023816", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023817", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_EVSE_vald_toggle == YES)
-	{
-		memcpy(code, "023817", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023823", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsUDP_TT_match_join == YES)
-	{
-		memcpy(code, "023823", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023824", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTCP_TT_match_join == YES)
-	{
-		memcpy(code, "023824", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023825", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_amp_map_exchange == YES)
-	{
-		memcpy(code, "023825", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023826", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_link_ready_notification == YES)
-	{
-		memcpy(code, "023826", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023832", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSupportedAppProtocolRes == YES)
-	{
-		memcpy(code, "023832", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023833", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSessionSetupRes == YES)
-	{
-		memcpy(code, "023833", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023834", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsServiceDiscoveryRes == YES)
-	{
-		memcpy(code, "023834", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023835", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsServicePaymentSelectionRes == YES)
-	{
-		memcpy(code, "023835", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023836", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsContractAuthenticationRes == YES)
-	{
-		memcpy(code, "023836", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023837", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsChargeParameterDiscoveryRes == YES)
-	{
-		memcpy(code, "023837", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023838", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsPowerDeliveryRes == YES)
-	{
-		memcpy(code, "023838", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023839", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCableCheckRes == YES)
-	{
-		memcpy(code, "023839", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023840", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsPreChargeRes == YES)
-	{
-		memcpy(code, "023840", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023841", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCurrentDemandRes == YES)
-	{
-		memcpy(code, "023841", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023842", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsWeldingDetectionRes == YES)
-	{
-		memcpy(code, "023842", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023843", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSessionStopRes == YES)
-	{
-		memcpy(code, "023843", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023844", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSequence_Time == YES)
-	{
-		memcpy(code, "023844", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023845", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsReadyToCharge_Performance_Time == YES)
-	{
-		memcpy(code, "023845", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023846", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCommunicationSetup_Performance_Time == YES)
-	{
-		memcpy(code, "023846", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023847", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCableCheck_Performance_Time == YES)
-	{
-		memcpy(code, "023847", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023848", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCPState_Detection_Time == YES)
-	{
-		memcpy(code, "023848", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023849", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCPOscillator_Retain_Time == YES)
-	{
-		memcpy(code, "023849", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023850", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSeccTimeoutV2GPreChargePerformaceTime == YES)
-	{
-		memcpy(code, "023850", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023855", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_GET_EV_TARGET_INFO == YES)
-	{
-		memcpy(code, "023855", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023856", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_GET_EV_TARGET_INFO == YES)
-	{
-		memcpy(code, "023856", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023857", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_GET_EV_BATTERY_INFO == YES)
-	{
-		memcpy(code, "023857", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023858", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_GET_EV_BATTERY_INFO == YES)
-	{
-		memcpy(code, "023858", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023859", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_EV_STOP_EVENT == YES)
-	{
-		memcpy(code, "023859", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023860", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_EV_STOP_EVENT == YES)
-	{
-		memcpy(code, "023860", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023861", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_EVSE_STOP_EVENT == YES)
-	{
-		memcpy(code, "023861", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023862", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_EVSE_STOP_EVENT == YES)
-	{
-		memcpy(code, "023862", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023863", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_GET_MISC_INFO == YES)
-	{
-		memcpy(code, "023863", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023864", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_GET_MISC_INFO == YES)
-	{
-		memcpy(code, "023864", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023865", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_DOWNLOAD_REQUEST == YES)
-	{
-		memcpy(code, "023865", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023866", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_DOWNLOAD_REQUEST == YES)
-	{
-		memcpy(code, "023866", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023867", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_START_BLOCK_TRANSFER == YES)
-	{
-		memcpy(code, "023867", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023868", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_START_BLOCK_TRANSFER == YES)
-	{
-		memcpy(code, "023868", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023869", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_DATA_TRANSFER == YES)
-	{
-		memcpy(code, "023869", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023870", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_DATA_TRANSFER == YES)
-	{
-		memcpy(code, "023870", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023871", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_DOWNLOAD_FINISH == YES)
-	{
-		memcpy(code, "023871", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023872", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_DOWNLOAD_FINISH == YES)
-	{
-		memcpy(code, "023872", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023873", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_ISOLATION_STATUS == YES)
-	{
-		memcpy(code, "023873", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023874", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_ISOLATION_STATUS == YES)
-	{
-		memcpy(code, "023874", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023875", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_CONNECTOR_INFO == YES)
-	{
-		memcpy(code, "023875", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023876", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_CONNECTOR_INFO == YES)
-	{
-		memcpy(code, "023876", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023877", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_RTC_INFO == YES)
-	{
-		memcpy(code, "023877", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023878", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_RTC_INFO == YES)
-	{
-		memcpy(code, "023878", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023879", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_EVSE_PRECHARGE_INFO == YES)
-	{
-		memcpy(code, "023879", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023880", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_EVSE_PRECHARGE_INFO == YES)
-	{
-		memcpy(code, "023880", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023881", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsMSG_Sequence == YES)
-	{
-		memcpy(code, "023881", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023882", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCAN_MSG_Unrecognized_CMD_ID == YES)
-	{
-		memcpy(code, "023882", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023883", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsDIN_Msg_Decode_Error == YES)
-	{
-		memcpy(code, "023883", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023884", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsDIN_Msg_Encode_Error == YES)
-	{
-		memcpy(code, "023884", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023885", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsISO1_Msg_Decode_Error == YES)
-	{
-		memcpy(code, "023885", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023886", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsISO1_Msg_Encode_Error == YES)
-	{
-		memcpy(code, "023886", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023887", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsISO2_Msg_Decode_Error == YES)
-	{
-		memcpy(code, "023887", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023888", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsISO2_Msg_Encode_Error == YES)
-	{
-		memcpy(code, "023888", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023889", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCpStatus_Error == YES)
-	{
-		memcpy(code, "023889", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023890", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsUnexpectVolBeforeCharing_Error == YES)
-	{
-		memcpy(code, "023890", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023891", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSeccNotReadyForCharging == YES)
-	{
-		memcpy(code, "023891", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023892", 6) == EQUAL &&
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSeccTimeoutQCA7000Comm == YES)
-	{
-		memcpy(code, "023892", 6);
-		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
-		isCleanCheck = true;
-	}
-
-	if (isCleanCheck)
-	{
-		for (byte index = 0; index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; index++)
-		{
-			if (index != gun_index || ShmSysConfigAndInfo->SysConfig.TotalConnectorCount == 1)
-			{
-				PRINTF_FUNC("CCS clean error : index = %d, EvConnAlarmCode = %s, code = %s \n", index, _chargingData[index]->EvConnAlarmCode, code);
-				if (strncmp((char *)_chargingData[index]->EvConnAlarmCode, code, 6) != EQUAL)
-				{
-					if (strncmp(code, "023701", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsEvCommFail = NO;
-					if (strncmp(code, "023737", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsRESTemperatureInhibit = NO;
-					if (strncmp(code, "023738", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsEVShiftPosition = NO;
-					if (strncmp(code, "023739", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsChargerConnectorLockFault = NO;
-					if (strncmp(code, "023740", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsEVRESSMalfunction = NO;
-					if (strncmp(code, "023741", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsChargingCurrentdifferential = NO;
-					if (strncmp(code, "023742", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsChargingVoltageOutOfRange = NO;
-					if (strncmp(code, "023743", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsChargingSystemIncompatibility = NO;
-					if (strncmp(code, "023744", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsEmergencyEvent = NO;
-					if (strncmp(code, "023745", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsBreaker = NO;
-					if (strncmp(code, "023746", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsNoData = NO;
-					if (strncmp(code, "023747", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_DIN_A = NO;
-					if (strncmp(code, "023748", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_DIN_B = NO;
-					if (strncmp(code, "023749", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_DIN_C = NO;
-					if (strncmp(code, "023750", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_ISO_1 = NO;
-					if (strncmp(code, "023751", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_ISO_2 = NO;
-					if (strncmp(code, "023752", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_ISO_3 = NO;
-					if (strncmp(code, "023753", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_OEM_1 = NO;
-					if (strncmp(code, "023754", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_OEM_2 = NO;
-					if (strncmp(code, "023755", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_OEM_3 = NO;
-					if (strncmp(code, "023756", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_OEM_4 = NO;
-					if (strncmp(code, "023757", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_OEM_5 = NO;
-					if (strncmp(code, "023758", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSequenceError = NO;
-					if (strncmp(code, "023759", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSignatureError = NO;
-					if (strncmp(code, "023760", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsUnknownSession = NO;
-					if (strncmp(code, "023761", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsServiceIDInvalid = NO;
-					if (strncmp(code, "023762", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsPaymentSelectionInvalid = NO;
-					if (strncmp(code, "023763", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsIdentificationSelectionInvalid = NO;
-					if (strncmp(code, "023764", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsServiceSelectionInvalid = NO;
-					if (strncmp(code, "023765", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCertificateExpired = NO;
-					if (strncmp(code, "023766", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCertificateNotYetValid = NO;
-					if (strncmp(code, "023767", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCertificateRevoked = NO;
-					if (strncmp(code, "023768", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsNoCertificateAvailable = NO;
-					if (strncmp(code, "023769", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCertChainError = NO;
-					if (strncmp(code, "023770", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCertValidationError = NO;
-					if (strncmp(code, "023771", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCertVerificationError = NO;
-					if (strncmp(code, "023772", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsContractCanceled = NO;
-					if (strncmp(code, "023773", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsChallengeInvalid = NO;
-					if (strncmp(code, "023774", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsWrongEnergyTransferMode = NO;
-					if (strncmp(code, "023775", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsWrongChargeParameter = NO;
-					if (strncmp(code, "023776", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsChargingProfileInvalid = NO;
-					if (strncmp(code, "023777", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTariffSelectionInvalid = NO;
-					if (strncmp(code, "023778", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsEVSEPresentVoltageToLow = NO;
-					if (strncmp(code, "023779", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsPowerDeliveryNotApplied = NO;
-					if (strncmp(code, "023780", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsMeteringSignatureNotValid = NO;
-					if (strncmp(code, "023781", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsNoChargeServiceSelected = NO;
-					if (strncmp(code, "023782", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsContactorError = NO;
-					if (strncmp(code, "023783", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCertificateNotAllowedAtThisEVSE = NO;
-					if (strncmp(code, "023784", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsGAChargeStop = NO;
-					if (strncmp(code, "023785", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsAlignmentError = NO;
-					if (strncmp(code, "023786", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsACDError = NO;
-					if (strncmp(code, "023787", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsAssociationError = NO;
-					if (strncmp(code, "023788", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsEVSEChargeAbort = NO;
-					if (strncmp(code, "023789", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsNoSupportedAppProtocol = NO;
-					if (strncmp(code, "023790", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsContractNotAccepted = NO;
-					if (strncmp(code, "023791", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsMOUnknown = NO;
-					if (strncmp(code, "023792", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsOEM_Prov_CertificateRevoke = NO;
-					if (strncmp(code, "023793", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsOEM_SubCA1_CertificateRevoked = NO;
-					if (strncmp(code, "023794", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsOEM_SubCA2_CertificateRevoked = NO;
-					if (strncmp(code, "023795", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsOEM_RootCA_CertificateRevoked = NO;
-					if (strncmp(code, "023796", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsMO_Prov_CertificateRevoked = NO;
-					if (strncmp(code, "023797", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsMO_SubCA1_CertificateRevoked = NO;
-					if (strncmp(code, "023798", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsMO_SubCA2_CertificateRevoked = NO;
-					if (strncmp(code, "023799", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsMO_RootCA_CertificateRevoked = NO;
-					if (strncmp(code, "023800", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCPS_Prov_CertificateRevoked = NO;
-					if (strncmp(code, "023801", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCPS_SubCA1_CertificateRevoked = NO;
-					if (strncmp(code, "023802", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCPS_SubCA2_CertificateRevoked = NO;
-					if (strncmp(code, "023803", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCPS_RootCA_CertificateRevoked = NO;
-					if (strncmp(code, "023809", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_EVSE_SLAC_init = NO;
-					if (strncmp(code, "023810", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_match_response = NO;
-					if (strncmp(code, "023811", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_match_sequence = NO;
-					if (strncmp(code, "023812", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_EVSE_match_MNBC = NO;
-					if (strncmp(code, "023813", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_EVSE_avg_atten_calc = NO;
-					if (strncmp(code, "023814", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_match_response = NO;
-					if (strncmp(code, "023815", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_EVSE_match_session = NO;
-					if (strncmp(code, "023816", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_EVSE_assoc_session = NO;
-					if (strncmp(code, "023817", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_EVSE_vald_toggle = NO;
-					if (strncmp(code, "023823", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsUDP_TT_match_join = NO;
-					if (strncmp(code, "023824", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTCP_TT_match_join = NO;
-					if (strncmp(code, "023825", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_amp_map_exchange = NO;
-					if (strncmp(code, "023826", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_link_ready_notification = NO;
-					if (strncmp(code, "023832", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSupportedAppProtocolRes = NO;
-					if (strncmp(code, "023833", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSessionSetupRes = NO;
-					if (strncmp(code, "023834", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsServiceDiscoveryRes = NO;
-					if (strncmp(code, "023835", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsServicePaymentSelectionRes = NO;
-					if (strncmp(code, "023836", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsContractAuthenticationRes = NO;
-					if (strncmp(code, "023837", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsChargeParameterDiscoveryRes = NO;
-					if (strncmp(code, "023838", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsPowerDeliveryRes = NO;
-					if (strncmp(code, "023839", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCableCheckRes = NO;
-					if (strncmp(code, "023840", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsPreChargeRes = NO;
-					if (strncmp(code, "023841", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCurrentDemandRes = NO;
-					if (strncmp(code, "023842", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsWeldingDetectionRes = NO;
-					if (strncmp(code, "023843", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSessionStopRes = NO;
-					if (strncmp(code, "023844", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSequence_Time = NO;
-					if (strncmp(code, "023845", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsReadyToCharge_Performance_Time = NO;
-					if (strncmp(code, "023846", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCommunicationSetup_Performance_Time = NO;
-					if (strncmp(code, "023847", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCableCheck_Performance_Time = NO;
-					if (strncmp(code, "023848", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCPState_Detection_Time = NO;
-					if (strncmp(code, "023849", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCPOscillator_Retain_Time = NO;
-					if (strncmp(code, "023850", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSeccTimeoutV2GPreChargePerformaceTime = NO;
-					if (strncmp(code, "023855", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_GET_EV_TARGET_INFO = NO;
-					if (strncmp(code, "023856", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_GET_EV_TARGET_INFO = NO;
-					if (strncmp(code, "023857", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_GET_EV_BATTERY_INFO = NO;
-					if (strncmp(code, "023858", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_GET_EV_BATTERY_INFO = NO;
-					if (strncmp(code, "023859", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_EV_STOP_EVENT = NO;
-					if (strncmp(code, "023860", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_EV_STOP_EVENT = NO;
-					if (strncmp(code, "023861", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_EVSE_STOP_EVENT = NO;
-					if (strncmp(code, "023862", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_EVSE_STOP_EVENT = NO;
-					if (strncmp(code, "023863", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_GET_MISC_INFO = NO;
-					if (strncmp(code, "023864", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_GET_MISC_INFO = NO;
-					if (strncmp(code, "023865", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_DOWNLOAD_REQUEST = NO;
-					if (strncmp(code, "023866", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_DOWNLOAD_REQUEST = NO;
-					if (strncmp(code, "023867", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_START_BLOCK_TRANSFER = NO;
-					if (strncmp(code, "023868", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_START_BLOCK_TRANSFER = NO;
-					if (strncmp(code, "023869", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_DATA_TRANSFER = NO;
-					if (strncmp(code, "023870", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_DATA_TRANSFER = NO;
-					if (strncmp(code, "023871", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_DOWNLOAD_FINISH = NO;
-					if (strncmp(code, "023872", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_DOWNLOAD_FINISH = NO;
-					if (strncmp(code, "023873", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_ISOLATION_STATUS = NO;
-					if (strncmp(code, "023874", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_ISOLATION_STATUS = NO;
-					if (strncmp(code, "023875", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_CONNECTOR_INFO = NO;
-					if (strncmp(code, "023876", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_CONNECTOR_INFO = NO;
-					if (strncmp(code, "023877", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_RTC_INFO = NO;
-					if (strncmp(code, "023878", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_RTC_INFO = NO;
-					if (strncmp(code, "023879", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_EVSE_PRECHARGE_INFO = NO;
-					if (strncmp(code, "023880", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_EVSE_PRECHARGE_INFO = NO;
-					if (strncmp(code, "023881", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsMSG_Sequence = NO;
-					if (strncmp(code, "023882", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCAN_MSG_Unrecognized_CMD_ID = NO;
-					if (strncmp(code, "023883", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsDIN_Msg_Decode_Error = NO;
-					if (strncmp(code, "023884", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsDIN_Msg_Encode_Error = NO;
-					if (strncmp(code, "023885", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsISO1_Msg_Decode_Error = NO;
-					if (strncmp(code, "023886", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsISO1_Msg_Encode_Error = NO;
-					if (strncmp(code, "023887", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsISO2_Msg_Decode_Error = NO;
-					if (strncmp(code, "023888", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsISO2_Msg_Encode_Error = NO;
-					if (strncmp(code, "023889", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCpStatus_Error = NO;
-					if (strncmp(code, "023890", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsUnexpectVolBeforeCharing_Error = NO;
-					if (strncmp(code, "023891", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSeccNotReadyForCharging = NO;
-					if (strncmp(code, "023892", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSeccTimeoutQCA7000Comm = NO;
-				}
-			}
-		}
-	}
-}
-
-void AbnormalStopAnalysis(byte gun_index, byte *errCode)
-{
-	char string[7];
-	sprintf(string, "%d%d%d%d%d%d", *(errCode + 0), *(errCode + 1), *(errCode + 2), *(errCode + 3), *(errCode + 4), *(errCode + 5));
-
-	PRINTF_FUNC("NOTIFICATION_EV_STOP : Err Code = %s \n", string);
-	if (strncmp(string, "000000", 6) == EQUAL ||
-			strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "", 6) != EQUAL)
-		return;
-
-	memcpy(_chargingData[gun_index]->EvConnAlarmCode, string, 6);
-	printf("NOTIFICATION_EV_STOP : EvConnAlarmCode = %s \n", _chargingData[gun_index]->EvConnAlarmCode);
-
-	if (strcmp(string, "023700") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoEvCommFail = YES;
-	if (strcmp(string, "023704") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBatteryMalfun = YES;
-	if (strcmp(string, "023705") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoNoPermission = YES;
-	if (strcmp(string, "023706") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBatteryIncompatibility = YES;
-	if (strcmp(string, "023707") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBatteryOVP = YES;
-	if (strcmp(string, "023708") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBatteryUVP = YES;
-	if (strcmp(string, "023709") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBatteryOTP = YES;
-	if (strcmp(string, "023710") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBatteryCurrentDiff = YES;
-	if (strcmp(string, "023711") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBatteryVoltageDiff = YES;
-	if (strcmp(string, "023712") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoShiftPosition = YES;
-	if (strcmp(string, "023713") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBatteryOtherFault = YES;
-	if (strcmp(string, "023714") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoChargingSystemError = YES;
-	if (strcmp(string, "023715") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoEvNormalStop = YES;
-	if (strcmp(string, "023716") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoTempSensorBroken = YES;
-	if (strcmp(string, "023717") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoConnectorLockFail = YES;
-	if (strcmp(string, "023718") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoD1OnNoReceive = YES;
-	if (strcmp(string, "023719") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBmsKtoJTimeout = YES;
-	if (strcmp(string, "023720") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBmsChargeAllowTimeout = YES;
-	if (strcmp(string, "023721") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoWaitGfdTimeout = YES;
-	if (strcmp(string, "023722") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBmsEvRelayTimeout = YES;
-	if (strcmp(string, "023723") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBmsReqCurrentTimeout = YES;
-	if (strcmp(string, "023724") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBmsKtoJOffTimeout = YES;
-	if (strcmp(string, "023725") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBmsEvRelayOffTimeout = YES;
-	if (strcmp(string, "023726") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoAdcMoreThan10V = YES;
-	if (strcmp(string, "023727") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoAdcMoreThan20V = YES;
-	if (strcmp(string, "023728") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBmsChargeBeforeStop = YES;
-	if (strcmp(string, "023729") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoChargerGetNormalStop = YES;
-	if (strcmp(string, "023730") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoChargerGetEmergencyStop = YES;
-	if (strcmp(string, "023731") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoIsolationResultFail = YES;
-	if (strcmp(string, "023732") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoMissLinkWithMotherBoard = YES;
-	if (strcmp(string, "023733") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoOutputVolMoreThanLimit = YES;
-	if (strcmp(string, "023734") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoReqCurrentMoreThanLimit = YES;
-	if (strcmp(string, "023735") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoReCapBmsEqrCurrentExceed = YES;
-	if (strcmp(string, "023736") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoChargeRemainCountDown = YES;
-
-	if (strcmp(string, "023701") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsEvCommFail = YES;
-	if (strcmp(string, "023737") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsRESTemperatureInhibit = YES;
-	if (strcmp(string, "023738") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsEVShiftPosition = YES;
-	if (strcmp(string, "023739") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsChargerConnectorLockFault = YES;
-	if (strcmp(string, "023740") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsEVRESSMalfunction = YES;
-	if (strcmp(string, "023741") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsChargingCurrentdifferential = YES;
-	if (strcmp(string, "023742") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsChargingVoltageOutOfRange = YES;
-	if (strcmp(string, "023743") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsChargingSystemIncompatibility = YES;
-	if (strcmp(string, "023744") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsEmergencyEvent = YES;
-	if (strcmp(string, "023745") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsBreaker = YES;
-	if (strcmp(string, "023746") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsNoData = YES;
-	if (strcmp(string, "023747") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_DIN_A = YES;
-	if (strcmp(string, "023748") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_DIN_B = YES;
-	if (strcmp(string, "023749") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_DIN_C = YES;
-	if (strcmp(string, "023750") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_ISO_1 = YES;
-	if (strcmp(string, "023751") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_ISO_2 = YES;
-	if (strcmp(string, "023752") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_ISO_3 = YES;
-	if (strcmp(string, "023753") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_OEM_1 = YES;
-	if (strcmp(string, "023754") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_OEM_2 = YES;
-	if (strcmp(string, "023755") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_OEM_3 = YES;
-	if (strcmp(string, "023756") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_OEM_4 = YES;
-	if (strcmp(string, "023757") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_OEM_5 = YES;
-	if (strcmp(string, "023758") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSequenceError = YES;
-	if (strcmp(string, "023759") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSignatureError = YES;
-	if (strcmp(string, "023760") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsUnknownSession = YES;
-	if (strcmp(string, "023761") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsServiceIDInvalid = YES;
-	if (strcmp(string, "023762") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsPaymentSelectionInvalid = YES;
-	if (strcmp(string, "023763") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsIdentificationSelectionInvalid = YES;
-	if (strcmp(string, "023764") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsServiceSelectionInvalid = YES;
-	if (strcmp(string, "023765") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCertificateExpired = YES;
-	if (strcmp(string, "023766") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCertificateNotYetValid = YES;
-	if (strcmp(string, "023767") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCertificateRevoked = YES;
-	if (strcmp(string, "023768") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsNoCertificateAvailable = YES;
-	if (strcmp(string, "023769") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCertChainError = YES;
-	if (strcmp(string, "023770") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCertValidationError = YES;
-	if (strcmp(string, "023771") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCertVerificationError = YES;
-	if (strcmp(string, "023772") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsContractCanceled = YES;
-	if (strcmp(string, "023773") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsChallengeInvalid = YES;
-	if (strcmp(string, "023774") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsWrongEnergyTransferMode = YES;
-	if (strcmp(string, "023775") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsWrongChargeParameter = YES;
-	if (strcmp(string, "023776") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsChargingProfileInvalid = YES;
-	if (strcmp(string, "023777") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTariffSelectionInvalid = YES;
-	if (strcmp(string, "023778") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsEVSEPresentVoltageToLow = YES;
-	if (strcmp(string, "023779") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsPowerDeliveryNotApplied = YES;
-	if (strcmp(string, "023780") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsMeteringSignatureNotValid = YES;
-	if (strcmp(string, "023781") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsNoChargeServiceSelected = YES;
-	if (strcmp(string, "023782") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsContactorError = YES;
-	if (strcmp(string, "023783") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCertificateNotAllowedAtThisEVSE = YES;
-	if (strcmp(string, "023784") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsGAChargeStop = YES;
-	if (strcmp(string, "023785") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsAlignmentError = YES;
-	if (strcmp(string, "023786") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsACDError = YES;
-	if (strcmp(string, "023787") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsAssociationError = YES;
-	if (strcmp(string, "023788") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsEVSEChargeAbort = YES;
-	if (strcmp(string, "023789") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsNoSupportedAppProtocol = YES;
-	if (strcmp(string, "023790") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsContractNotAccepted = YES;
-	if (strcmp(string, "023791") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsMOUnknown = YES;
-	if (strcmp(string, "023792") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsOEM_Prov_CertificateRevoke = YES;
-	if (strcmp(string, "023793") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsOEM_SubCA1_CertificateRevoked = YES;
-	if (strcmp(string, "023794") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsOEM_SubCA2_CertificateRevoked = YES;
-	if (strcmp(string, "023795") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsOEM_RootCA_CertificateRevoked = YES;
-	if (strcmp(string, "023796") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsMO_Prov_CertificateRevoked = YES;
-	if (strcmp(string, "023797") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsMO_SubCA1_CertificateRevoked = YES;
-	if (strcmp(string, "023798") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsMO_SubCA2_CertificateRevoked = YES;
-	if (strcmp(string, "023799") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsMO_RootCA_CertificateRevoked = YES;
-	if (strcmp(string, "023800") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCPS_Prov_CertificateRevoked = YES;
-	if (strcmp(string, "023801") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCPS_SubCA1_CertificateRevoked = YES;
-	if (strcmp(string, "023802") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCPS_SubCA2_CertificateRevoked = YES;
-	if (strcmp(string, "023803") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCPS_RootCA_CertificateRevoked = YES;
-	if (strcmp(string, "023809") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_EVSE_SLAC_init = YES;
-	if (strcmp(string, "023810") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_match_response = YES;
-	if (strcmp(string, "023811") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_match_sequence = YES;
-	if (strcmp(string, "023812") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_EVSE_match_MNBC = YES;
-	if (strcmp(string, "023813") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_EVSE_avg_atten_calc = YES;
-	if (strcmp(string, "023814") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_match_response = YES;
-	if (strcmp(string, "023815") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_EVSE_match_session = YES;
-	if (strcmp(string, "023816") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_EVSE_assoc_session = YES;
-	if (strcmp(string, "023817") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_EVSE_vald_toggle = YES;
-	if (strcmp(string, "023823") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsUDP_TT_match_join = YES;
-	if (strcmp(string, "023824") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTCP_TT_match_join = YES;
-	if (strcmp(string, "023825") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_amp_map_exchange = YES;
-	if (strcmp(string, "023826") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_link_ready_notification = YES;
-	if (strcmp(string, "023832") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSupportedAppProtocolRes = YES;
-	if (strcmp(string, "023833") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSessionSetupRes = YES;
-	if (strcmp(string, "023834") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsServiceDiscoveryRes = YES;
-	if (strcmp(string, "023835") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsServicePaymentSelectionRes = YES;
-	if (strcmp(string, "023836") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsContractAuthenticationRes = YES;
-	if (strcmp(string, "023837") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsChargeParameterDiscoveryRes = YES;
-	if (strcmp(string, "023838") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsPowerDeliveryRes = YES;
-	if (strcmp(string, "023839") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCableCheckRes = YES;
-	if (strcmp(string, "023840") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsPreChargeRes = YES;
-	if (strcmp(string, "023841") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCurrentDemandRes = YES;
-	if (strcmp(string, "023842") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsWeldingDetectionRes = YES;
-	if (strcmp(string, "023843") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSessionStopRes = YES;
-	if (strcmp(string, "023844") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSequence_Time = YES;
-	if (strcmp(string, "023845") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsReadyToCharge_Performance_Time = YES;
-	if (strcmp(string, "023846") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCommunicationSetup_Performance_Time = YES;
-	if (strcmp(string, "023847") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCableCheck_Performance_Time = YES;
-	if (strcmp(string, "023848") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCPState_Detection_Time = YES;
-	if (strcmp(string, "023849") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCPOscillator_Retain_Time = YES;
-	if (strcmp(string, "023850") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSeccTimeoutV2GPreChargePerformaceTime = YES;
-	if (strcmp(string, "023855") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_GET_EV_TARGET_INFO = YES;
-	if (strcmp(string, "023856") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_GET_EV_TARGET_INFO = YES;
-	if (strcmp(string, "023857") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_GET_EV_BATTERY_INFO = YES;
-	if (strcmp(string, "023858") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_GET_EV_BATTERY_INFO = YES;
-	if (strcmp(string, "023859") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_EV_STOP_EVENT = YES;
-	if (strcmp(string, "023860") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_EV_STOP_EVENT = YES;
-	if (strcmp(string, "023861") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_EVSE_STOP_EVENT = YES;
-	if (strcmp(string, "023862") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_EVSE_STOP_EVENT = YES;
-	if (strcmp(string, "023863") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_GET_MISC_INFO = YES;
-	if (strcmp(string, "023864") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_GET_MISC_INFO = YES;
-	if (strcmp(string, "023865") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_DOWNLOAD_REQUEST = YES;
-	if (strcmp(string, "023866") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_DOWNLOAD_REQUEST = YES;
-	if (strcmp(string, "023867") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_START_BLOCK_TRANSFER = YES;
-	if (strcmp(string, "023868") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_START_BLOCK_TRANSFER = YES;
-	if (strcmp(string, "023869") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_DATA_TRANSFER = YES;
-	if (strcmp(string, "023870") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_DATA_TRANSFER = YES;
-	if (strcmp(string, "023871") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_DOWNLOAD_FINISH = YES;
-	if (strcmp(string, "023872") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_DOWNLOAD_FINISH = YES;
-	if (strcmp(string, "023873") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_ISOLATION_STATUS = YES;
-	if (strcmp(string, "023874") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_ISOLATION_STATUS = YES;
-	if (strcmp(string, "023875") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_CONNECTOR_INFO = YES;
-	if (strcmp(string, "023876") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_CONNECTOR_INFO = YES;
-	if (strcmp(string, "023877") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_RTC_INFO = YES;
-	if (strcmp(string, "023878") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_RTC_INFO = YES;
-	if (strcmp(string, "023879") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_EVSE_PRECHARGE_INFO = YES;
-	if (strcmp(string, "023880") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_EVSE_PRECHARGE_INFO = YES;
-	if (strcmp(string, "023881") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsMSG_Sequence = YES;
-	if (strcmp(string, "023882") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCAN_MSG_Unrecognized_CMD_ID = YES;
-	if (strcmp(string, "023883") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsDIN_Msg_Decode_Error = YES;
-	if (strcmp(string, "023884") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsDIN_Msg_Encode_Error = YES;
-	if (strcmp(string, "023885") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsISO1_Msg_Decode_Error = YES;
-	if (strcmp(string, "023886") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsISO1_Msg_Encode_Error = YES;
-	if (strcmp(string, "023887") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsISO2_Msg_Decode_Error = YES;
-	if (strcmp(string, "023888") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsISO2_Msg_Encode_Error = YES;
-	if (strcmp(string, "023889") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCpStatus_Error = YES;
-	if (strcmp(string, "023890") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsUnexpectVolBeforeCharing_Error = YES;
-	if (strcmp(string, "023891") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSeccNotReadyForCharging = YES;
-	if (strcmp(string, "023892") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSeccTimeoutQCA7000Comm = YES;
-
-	if (strcmp(string, "023702") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.GbEvCommFail = YES;
-	if (strcmp(string, "023900") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_LOS_CC1 = YES;
-	if (strcmp(string, "023901") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_CONNECTOR_LOCK_FAIL = YES;
-	if (strcmp(string, "023902") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_BATTERY_INCOMPATIBLE = YES;
-	if (strcmp(string, "023903") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_BMS_BROAA_TIMEOUT = YES;
-	if (strcmp(string, "023904") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_CSU_PRECHARGE_TIMEOUT = YES;
-	if (strcmp(string, "023905") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_BMS_PRESENT_VOLTAGE_FAULT = YES;
-	if (strcmp(string, "023906") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_BMS_VOLTAGE_OVER_RANGE = YES;
-	if (strcmp(string, "023907") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_BSM_CHARGE_ALLOW_00_10MIN_COUUNTDONE = YES;
-	if (strcmp(string, "023908") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_WAIT_GROUNDFAULT_TIMEOUT = YES;
-	if (strcmp(string, "023909") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_ADC_MORE_THAN_10V = YES;
-	if (strcmp(string, "023910") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_ADC_MORE_THAN_60V = YES;
-	if (strcmp(string, "023911") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_CHARGER_GET_NORMAL_STOP_CMD = YES;
-	if (strcmp(string, "023912") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_CHARGER_GET_EMERGENCY_STOP_CMD = YES;
-	if (strcmp(string, "023913") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_ISOLATION_RESULT_FAIL = YES;
-	if (strcmp(string, "023914") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_MOTHER_BOARD_MISS_LINK = YES;
-	if (strcmp(string, "023915") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_OUTPUT_VOLTAGE_MORE_THAN_LIMIT = YES;
-	if (strcmp(string, "023916") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_REQ_CURRENT_MORE_THAN_LIMIT = YES;
-	if (strcmp(string, "023917") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_OUTPUT_VOLTAGE_MORE_THAN_10_PERCENT = YES;
-	if (strcmp(string, "023918") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_OUTPUT_VOLTAGE_DIFF_BCS_5_PERCENT = YES;
-	if (strcmp(string, "023919") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_STOP_ADC_MORE_THAN_10V = YES;
-	if (strcmp(string, "023930") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_CEM_BHM_TIMEOUT = YES;
-	if (strcmp(string, "023931") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_CEM_BRM_TIMEOUT = YES;
-	if (strcmp(string, "023932") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_CEM_BCP_TIMEOUT = YES;
-	if (strcmp(string, "023933") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_CEM_BRO_TIMEOUT = YES;
-	if (strcmp(string, "023934") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_CEM_BCL_TIMEOUT = YES;
-	if (strcmp(string, "023935") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_CEM_BCS_TIMEOUT = YES;
-	if (strcmp(string, "023936") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_CEM_BSM_TIMEOUT = YES;
-	if (strcmp(string, "023937") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_CEM_BST_TIMEOUT = YES;
-	if (strcmp(string, "023938") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_CEM_BSD_TIMEOUT = YES;
-	if (strcmp(string, "023939") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_CEM_BEM_OTHER_TIMEOUT = YES;
-	if (strcmp(string, "023940") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BEM_CRM_TIMEOUT = YES;
-	if (strcmp(string, "023941") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BEM_CRMAA_TIMEOUT = YES;
-	if (strcmp(string, "023942") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BEM_CTS_CML_TIMEOUT = YES;
-	if (strcmp(string, "023943") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BEM_CRO_TIMEOUT = YES;
-	if (strcmp(string, "023944") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BEM_CCS_TIMEOUT = YES;
-	if (strcmp(string, "023945") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BEM_CST_TIMEOUT = YES;
-	if (strcmp(string, "023946") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BEM_CSD_TIMEOUT = YES;
-	if (strcmp(string, "023947") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BEM_BEM_OTHER_TIMEOUT = YES;
-	if (strcmp(string, "023950") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_SOC_GOAL = YES;
-	if (strcmp(string, "023951") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_TOTAL_VOLTAGE_GOAL = YES;
-	if (strcmp(string, "023952") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_CELL_VOLTAGE_GOAL = YES;
-	if (strcmp(string, "023953") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_GET_CST = YES;
-	if (strcmp(string, "023954") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_ISOLATION = YES;
-	if (strcmp(string, "023955") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_OUTPUT_CONNECTOR_OTP = YES;
-	if (strcmp(string, "023956") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_COMPONENT = YES;
-	if (strcmp(string, "023957") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_CHARGE_CONNECTOR = YES;
-	if (strcmp(string, "023958") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_OTP = YES;
-	if (strcmp(string, "023959") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_OTHER = YES;
-	if (strcmp(string, "023960") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_HIGH_V = YES;
-	if (strcmp(string, "023961") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_CC2 = YES;
-	if (strcmp(string, "023962") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_CURRENT = YES;
-	if (strcmp(string, "023963") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_VOLTAGE = YES;
-	if (strcmp(string, "023964") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GET_BST_NO_REASON = YES;
-	if (strcmp(string, "023970") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BSM_CELL_OVER_VOLTAGE = YES;
-	if (strcmp(string, "023971") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BSM_CELL_UNDER_VOLTAGE = YES;
-	if (strcmp(string, "023972") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BSM_OVER_SOC = YES;
-	if (strcmp(string, "023973") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BSM_UNDER_SOC = YES;
-	if (strcmp(string, "023974") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BSM_CURRENT = YES;
-	if (strcmp(string, "023975") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BSM_TEMPERATURE = YES;
-	if (strcmp(string, "023976") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BSM_ISOLATE = YES;
-	if (strcmp(string, "023977") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BSM_OUTPUT_CONNECTOR = YES;
-}
-
-void CANReceiver()
-{
-	pid_t canRecPid;
-
-	canRecPid = fork();
-
-	if(canRecPid > 0)
-	{
-		int nbytes;
-		struct can_frame frame;
-		int intCmd;
-
-		// 槍資訊
-		struct ChargingInfoData *_chargingData[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
-		struct timeval _cmd_ack_timeout[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
-
-		bool isPass = false;
-		gun_count = ShmSysConfigAndInfo->SysConfig.TotalConnectorCount;
-
-		while(!isPass)
-		{
-			isPass = true;
-			for (byte _index = 0; _index < gun_count; _index++)
-			{
-				if (!FindChargingInfoData(_index, &_chargingData[0]))
-				{
-					DEBUG_ERROR("EvComm (main) : FindChargingInfoData false \n");
-					isPass = false;
-					break;
-				}
-			}
-
-			sleep(1);
-		}
-
-		for (byte _index = 0; _index < gun_count; _index++)
-			gettimeofday(&_cmd_ack_timeout[_index], NULL);
-
-		while (1)
-		{
-			memset(&frame, 0, sizeof(struct can_frame));
-			nbytes = read(CanFd, &frame, sizeof(struct can_frame));
-
-			for (byte _index = 0; _index < gun_count; _index++)
-			{
-				if (GetTimeoutValue(_cmd_ack_timeout[_index]) >= 5000000)
-				{
-					// ACK timeout
-					//PRINTF_FUNC("gun = %x, ack timeout \n", _index);
-				}
-			}
-
-			if (nbytes > 0)
-			{
-				byte target;
-				byte targetGun = 0x00;
-				intCmd = (int) (frame.can_id & CAN_EFF_MASK);
-
-				if (intCmd == ADDRESS_REQ)
-				{
-					AddrAssignment(frame.data);
-					continue;
-				}
-				intCmd = (int) (frame.can_id & CAN_EFF_MASK & 0xFFFFFF00);
-				target = ((byte) (frame.can_id & 0x000000FF));		// 0x01 or 0x02
-
-				for (byte _index = 0; _index < gun_count; _index++)
-				{
-					if (_chargingData[_index]->Evboard_id == target)
-					{
-						targetGun = _index;
-						break;
-					}
-				}
-
-				if(targetGun < 0 || targetGun >= CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)
-				{
-					PRINTF_FUNC("EvComm (CANReceiver) : Target index = %x is < 0 or > QUANTITY \n", targetGun);
-					continue;
-				}
-				if(intCmd == 256)
-				{
-					continue;
-				}
-
-				gettimeofday(&_cmd_ack_timeout[targetGun], NULL);
-				switch (intCmd)
-				{
-					case NOTIFICATION_EV_STATUS:
-					{
-						if (_chargingData[targetGun]->ConnectorPlugIn != frame.data[0])
-							PRINTF_FUNC("index = %d, ConnectorPlugIn = %x, data[0] = %x \n", targetGun, _chargingData[targetGun]->ConnectorPlugIn, frame.data[0]);
-
-						_chargingData[targetGun]->ConnectorPlugIn = frame.data[0];
-						_chargingData[targetGun]->PilotVoltage = frame.data[1];
-
-						//PRINTF_FUNC("index = %d, ConnectorPlugIn = %x, data[0] = %x \n", targetGun, _chargingData[targetGun]->ConnectorPlugIn, frame.data[0]);
-						//PRINTF_FUNC("ConnectorPlugIn = %x \n", (-120 + frame.data[1]) / 10);
-					}
-						break;
-					case ACK_EV_FW_VERSION:
-					{
-						byte ver[16];
-
-						memset(ver, 0, sizeof(ver));
-						if (_chargingData[targetGun]->Type == _Type_Chademo)
-						{
-							memcpy(ver, frame.data, frame.can_dlc);
-							memcpy(ShmCHAdeMOData->evse[_chargingData[targetGun]->type_index].version, ver, ARRAY_SIZE(ver));
-							ShmCHAdeMOData->evse[_chargingData[targetGun]->type_index].SelfTest_Comp = PASS;
-							PRINTF_FUNC("chademo ver. : %s\n", ShmCHAdeMOData->evse[_chargingData[targetGun]->type_index].version);
-						}
-						else if (_chargingData[targetGun]->Type == _Type_GB)
-						{
-							memcpy(ver, frame.data, frame.can_dlc);
-							memcpy(ShmGBTData->evse[_chargingData[targetGun]->type_index].version, ver, ARRAY_SIZE(ver));
-							ShmGBTData->evse[_chargingData[targetGun]->type_index].SelfTest_Comp = PASS;
-							PRINTF_FUNC("gbt ver. : %s\n", ShmGBTData->evse[_chargingData[targetGun]->type_index].version);
-						}
-						else if (_chargingData[targetGun]->Type == _Type_CCS_2)
-						{
-							if (ShmCcsData->CommProtocol == 0x01)
-							{
-								for (byte _vCount = 0, _vPoint = 0; _vCount < frame.can_dlc; _vCount++)
-								{
-									if (_vCount % 2 == 0 && _vCount != 0)
-									{
-										ver[_vCount + _vPoint] = 0x2E;
-										_vPoint++;
-									}
-
-									ver[_vCount + _vPoint] = frame.data[_vCount];
-								}
-
-								memcpy(&ShmCcsData->V2GMessage_DIN70121[_chargingData[targetGun]->type_index].version, ver, ARRAY_SIZE(ver));
-								ShmCcsData->V2GMessage_DIN70121[_chargingData[targetGun]->type_index].SelfTest_Comp = PASS;
-								PRINTF_FUNC("CCS FW = %s \n", ShmCcsData->V2GMessage_DIN70121[_chargingData[targetGun]->type_index].version);
-							}
-						}
-
-						if (targetGun == 0)
-						{
-							memset(ShmSysConfigAndInfo->SysInfo.Connector1FwRev, 0, sizeof(ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
-							memcpy(ShmSysConfigAndInfo->SysInfo.Connector1FwRev, ver, ARRAY_SIZE(ver));
-						}
-						else
-						{
-							memset(ShmSysConfigAndInfo->SysInfo.Connector2FwRev, 0, sizeof(ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
-							memcpy(ShmSysConfigAndInfo->SysInfo.Connector2FwRev, ver, ARRAY_SIZE(ver));
-						}
-					}
-						break;
-					case ACK_EV_HW_VERSION:
-					{
-						//PRINTF_FUNC("Get EV HW = %s \n", frame.data);
-					}
-						break;
-					case ACK_GET_OUTPUT_REQ:
-					{
-						_chargingData[targetGun]->EvBatterySoc = frame.data[1];
-						_chargingData[targetGun]->EvBatterytargetVoltage = (((short) frame.data[3] << 8) + (short) frame.data[2]) / 10;
-						_chargingData[targetGun]->EvBatterytargetCurrent = (((short) frame.data[5] << 8) + (short) frame.data[4]) / 10;
-						_chargingData[targetGun]->RemainChargingDuration = ((short) frame.data[7] << 8) + (short) frame.data[6];
-
-						if (_chargingData[targetGun]->Type == _Type_Chademo)
-						{
-							//if (ShmCHAdeMOData->ev[_chargingData[targetGun]->type_index].EvDetection != frame.data[0])
-							{
-								ShmCHAdeMOData->ev[_chargingData[targetGun]->type_index].PresentMsgFlowStatus = frame.data[0];
-							}
-
-							ShmCHAdeMOData->ev[_chargingData[targetGun]->type_index].EvDetection = frame.data[0];
-							ShmCHAdeMOData->ev[_chargingData[targetGun]->type_index].SOC = _chargingData[targetGun]->EvBatterySoc;
-							ShmCHAdeMOData->ev[_chargingData[targetGun]->type_index].TargetBatteryVoltage = (_chargingData[targetGun]->EvBatterytargetVoltage * 10);
-							ShmCHAdeMOData->ev[_chargingData[targetGun]->type_index].ChargingCurrentRequest = (_chargingData[targetGun]->EvBatterytargetCurrent * 10);
-						}
-						else if (_chargingData[targetGun]->Type == _Type_GB)
-						{
-							//if (ShmGBTData->ev[_chargingData[targetGun]->type_index].EvDetection != frame.data[0])
-							{
-								ShmGBTData->ev[_chargingData[targetGun]->type_index].PresentMsgFlowStatus = frame.data[0];
-							}
-
-							ShmGBTData->ev[_chargingData[targetGun]->type_index].EvDetection = frame.data[0];
-							ShmGBTData->ev[_chargingData[targetGun]->type_index].SOC = _chargingData[targetGun]->EvBatterySoc;
-							ShmGBTData->ev[_chargingData[targetGun]->type_index].TargetBatteryVoltage = (_chargingData[targetGun]->EvBatterytargetVoltage * 10);
-							ShmGBTData->ev[_chargingData[targetGun]->type_index].ChargingCurrentRequest = (_chargingData[targetGun]->EvBatterytargetCurrent * 10);
-						}
-						else if (_chargingData[targetGun]->Type == _Type_CCS_2)
-						{
-							if(ShmCcsData->CommProtocol == 0x01)
-							{
-								ShmCcsData->V2GMessage_DIN70121[_chargingData[targetGun]->type_index].PresentMsgFlowStatus = frame.data[0];
-							}
-						}
-
-						//PRINTF_FUNC("EvBatterytargetVoltage = %f \n", _chargingData[targetGun]->EvBatterytargetVoltage);
-						//PRINTF_FUNC("EvBatterytargetCurrent = %f \n", _chargingData[targetGun]->EvBatterytargetCurrent);
-						//PRINTF_FUNC("BatteryVoltage = %d \n", ShmCHAdeMOData->ev[_chargingData[target]->type_index].TargetBatteryVoltage);
-						//PRINTF_FUNC("CurrentRequest = %d \n", ShmCHAdeMOData->ev[_chargingData[target]->type_index].ChargingCurrentRequest);
-					}
-						break;
-					case ACK_GET_EV_BATTERY_INFO:
-					{
-						//_chargingData[target].EvACorDCcharging = frame.data[0];
-						//_chargingData[target]->TotalBatteryCap = ((float) frame.data[4] << 8) + (short) frame.data[3];
-						_chargingData[targetGun]->EvBatteryMaxVoltage = (((short) frame.data[4] << 8) + (short) frame.data[3]) / 10;
-						//_chargingData[target]->EvBatteryMaxCurrent = ((float) frame.data[4] << 8) + (short) frame.data[3];
-						//_chargingData[target].MaxiBatteryCurrent = ((short) frame.data[6] << 8) + (short) frame.data[5];
-						if (_chargingData[targetGun]->Type == _Type_Chademo)
-						{
-							ShmCHAdeMOData->ev[_chargingData[targetGun]->type_index].TotalBatteryCapacity = ((short) frame.data[2] << 8) + (short) frame.data[1];
-							ShmCHAdeMOData->ev[_chargingData[targetGun]->type_index].MaxiBatteryVoltage = _chargingData[targetGun]->EvBatteryMaxVoltage;
-
-							//PRINTF_FUNC("EvBatteryMaxVoltage = %f \n", _chargingData[target]->EvBatteryMaxVoltage);
-							//PRINTF_FUNC("TotalBatteryCapacity = %d \n", ShmCHAdeMOData->ev[_chargingData[target]->type_index].TotalBatteryCapacity);
-							//PRINTF_FUNC("MaxiBatteryVoltage = %d \n", ShmCHAdeMOData->ev[_chargingData[target]->type_index].MaxiBatteryVoltage);
-						}
-						else if (_chargingData[targetGun]->Type == _Type_GB)
-						{
-							ShmGBTData->ev[_chargingData[targetGun]->type_index].TotalBatteryCapacity = ((short) frame.data[2] << 8) + (short) frame.data[1];
-							ShmGBTData->ev[_chargingData[targetGun]->type_index].MaxiBatteryVoltage = _chargingData[targetGun]->EvBatteryMaxVoltage;
-						}
-						else if (_chargingData[targetGun]->Type == _Type_CCS_2)
-						{
-
-						}
-					}
-						break;
-					case ACK_GET_MISCELLANEOUS_INFO:
-					{
-						_chargingData[targetGun]->GunLocked = frame.data[0];
-						_chargingData[targetGun]->PilotVoltage = (float)(-120 + frame.data[3]) / 10;
-
-						if (_chargingData[targetGun]->Type == _Type_Chademo)
-						{
-							ShmCHAdeMOData->evse[_chargingData[targetGun]->type_index].ConnectorTemperatureP = frame.data[1];
-							ShmCHAdeMOData->evse[_chargingData[targetGun]->type_index].ConnectorTemperatureN = frame.data[2];
-							ShmCHAdeMOData->evse[_chargingData[targetGun]->type_index].EvboardStatus = frame.data[7];
-						}
-						else if (_chargingData[targetGun]->Type == _Type_GB)
-						{
-							ShmGBTData->evse[_chargingData[targetGun]->type_index].ConnectorTemperatureP = frame.data[1];
-							ShmGBTData->evse[_chargingData[targetGun]->type_index].ConnectorTemperatureN = frame.data[2];
-							ShmGBTData->evse[_chargingData[targetGun]->type_index].EvboardStatus = frame.data[7];
-						}
-						else if (_chargingData[targetGun]->Type == _Type_CCS_2)
-						{
-							if (ShmCcsData->CommProtocol == 0x01)
-							{
-								//ShmCcsData->V2GMessage_DIN70121[_chargingData[targetGun]->type_index]. .ConnectorTemperatureP = frame.data[1];
-								//ShmCcsData->V2GMessage_DIN70121[_chargingData[targetGun]->type_index]. .ConnectorTemperatureN = frame.data[2];
-							}
-						}
-
-						//PRINTF_FUNC("EvboardStatus = %x \n", ShmCHAdeMOData->evse[_chargingData[target]->type_index].EvboardStatus);
-						//PRINTF_FUNC("ConnectorPlug locked = %x \n", frame.data[0]);
-						//PRINTF_FUNC("ConnectorTemp 0= %d \n", ShmCHAdeMOData->evse[_chargingData[target]->type_index].ConnectorTemperatureP);
-						//PRINTF_FUNC("ConnectorTemp 1= %d \n", ShmCHAdeMOData->evse[_chargingData[target]->type_index].ConnectorTemperatureN);
-						//PRINTF_FUNC("PilotVoltage = %x \n", (-120 + frame.data[3]) / 10);
-					}
-						break;
-					case ACK_EVSE_ISOLATION_STATUS:	{}
-						break;
-					case ACK_EVSE_PRECHAGE_INFO:
-					{
-						_chargingData[targetGun]->PrechargeStatus = frame.data[0];
-					}
-						break;
-					case NOTIFICATION_EV_STOP:
-					{
-						// 車端要求停止
-						// frame.data[0] : 0x01 => normal stop, 0x02 => ev emergency stop
-						PRINTF_FUNC("(%d) NOTIFICATION_EV_STOP err level = %d-----------------------------\n", targetGun, frame.data[0]);
-						//if (frame.data[0] == 0x02)
-						{
-							AbnormalStopAnalysis(targetGun, frame.data + 1);
-						}
-						_chargingData[targetGun]->StopChargeFlag = YES;
-					}
-						break;
-					default:
-						PRINTF_FUNC("EV board = %d, Ack none defined. intCmd = %d  \n", targetGun, intCmd);
-						break;
-				}
-			}
-			usleep(10000);
-		}
-	}
-}
-
-//================================================
-// Main process
-//================================================
-// 檢查 Byte 中某個 Bit 的值
-// _byte : 欲改變的 byte
-// _bit : 該 byte 的第幾個 bit
-unsigned char EvDetectionStatus(unsigned char _byte, unsigned char _bit)
-{
-	return ( _byte & mask_table[_bit] ) != 0x00;
-}
-
-bool IsConnectorPlugIn(struct ChargingInfoData *chargingData)
-{
-	return (chargingData->ConnectorPlugIn == 0x01) ? true : false;
-}
-
-void SetPresentChargingOutputPower(struct ChargingInfoData *chargingData_1, struct ChargingInfoData *chargingData_2)
-{
-	float vol1 = 0, cur1 = 0;
-	float vol2 = 0, cur2 = 0;
-
-	vol1 = chargingData_1->FireChargingVoltage;
-	cur1 = (chargingData_1->PresentChargingCurrent * 10);
-
-	vol2 = chargingData_2->FireChargingVoltage;
-	cur2 = (chargingData_2->PresentChargingCurrent * 10);
-
-	if (_outVol_1 != vol1 ||
-		_outCur_1 != cur1 ||
-		_outVol_2 != vol2 ||
-		_outCur_2 != cur2)
-	{
-		PRINTF_FUNC("G1 -> Output Vol = %f, Output Cur = %f -- G2 -> Output Vol = %f, Output Cur = %f \n",
-			vol1, cur1, vol2, cur2);
-
-		_outVol_1 = vol1; _outCur_1 = cur1; _outVol_2 = vol2; _outCur_2 = cur2;
-	}
-
-	SetPresentOutputPower(vol1, cur1, vol2, cur2);
-}
-
-void SetPresentChargingOutputCap(struct ChargingInfoData *chargingData_1, struct ChargingInfoData *chargingData_2)
-{
-	float pow1 = 0, cur1 = 0;
-	float pow2 = 0, cur2 = 0;
-	float vol = 0;
-
-	pow1 = chargingData_1->AvailableChargingPower;
-	cur1 = chargingData_1->AvailableChargingCurrent;
-
-	vol = chargingData_1->MaximumChargingVoltage;
-	GetMaxVolAndCurMethod(chargingData_1->Index, &vol, &cur1);
-	GetMaxPowerMethod(&pow1);
-
-	pow2 = chargingData_2->AvailableChargingPower;
-	cur2 = chargingData_2->AvailableChargingCurrent;
-	vol = chargingData_2->MaximumChargingVoltage;
-
-	GetMaxVolAndCurMethod(chargingData_2->Index, &vol, &cur2);
-	GetMaxPowerMethod(&pow2);
-
-	if (_pow_1 != pow1 ||
-		_cur_1 != cur1 ||
-		_pow_2 != pow2 ||
-		_cur_2 != cur2)
-	{
-		PRINTF_FUNC("To EV (Real) Power_1 = %f, Cur_1 = %f, Power_2 = %f, Cur_2 = %f \n",
-				pow1, cur1, pow2, cur2);
-		_pow_1 = pow1; _cur_1 = cur1; _pow_2 = pow2; _cur_2 = cur2;
-		chargingData_1->RealMaxCurrent = _cur_1;
-		chargingData_1->RealMaxPower = pow1;
-
-		if (gun_count == 2)
-		{
-			chargingData_2->RealMaxCurrent = cur2;
-			chargingData_2->RealMaxPower = pow2;
-		}
-	}
-
-	SetPresentOutputCapacity(pow1, cur1, pow2, cur2);
-}
-
-void Initialization()
-{
-	bool isPass = false;
-	while(!isPass)
-	{
-		isPass = true;
-		for (byte _index = 0; _index < gun_count; _index++)
-		{
-			if (!FindChargingInfoData(_index, &_chargingData[0]))
-			{
-				DEBUG_ERROR("EvComm (main) : FindChargingInfoData false \n");
-				isPass = false;
-				break;
-			}
-		}
-		sleep(1);
-	}
-}
-
-void GetMaxVolAndCurMethod(byte index, float *vol, float *cur)
-{
-	if (maxChargingVol[index] != 0 && maxChargingVol[index] <= *vol)
-		*vol = maxChargingVol[index];
-
-	if (maxChargingCur[index] != 0 && maxChargingCur[index] <= *cur)
-		*cur = maxChargingCur[index];
-}
-
-void GetMaxPowerMethod(float *pow)
-{
-	if (maxChargingPow != 0 && maxChargingPow <= *pow)
-		*pow = maxChargingPow;
-}
-
-time_t GetRtcInfoForEpoch()
-{
-	struct timeb csuTime;
-	struct tm *tmCSU;
-	struct tm t;
-	time_t result;
-
-	ftime(&csuTime);
-	tmCSU = localtime(&csuTime.time);
-
-	t.tm_year = tmCSU->tm_year;
-	t.tm_mon = tmCSU->tm_mon;
-	t.tm_mday = tmCSU->tm_mday;
-	t.tm_hour = tmCSU->tm_hour;
-	t.tm_min = tmCSU->tm_min;
-	t.tm_sec = tmCSU->tm_sec;
-	t.tm_isdst = -1;
-	result = mktime(&t);
-
-	return result;
-}
-
-byte GetStopChargingReasonByEvse(byte gunIndex, byte *reason)
-{
-	byte result = NO;
-
-	if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.EmergencyStopTrip == 0x01)
-	{
-		// 012251
-		*(reason + 5)  = 0;
-		*(reason + 4)  = 1;
-		*(reason + 3)  = 2;
-		*(reason + 2)  = 2;
-		*(reason + 1)  = 5;
-		*(reason + 0)  = 1;
-		result = YES;
-	}
-
-	if (_chargingData[gunIndex]->Type == _Type_Chademo)
-	{
-		if (ShmStatusCodeData->FaultCode.FaultEvents.bits.ChademoOutputRelayDrivingFault == YES)
-		{
-			// 011012
-			*(reason + 5) = 0;
-			*(reason + 4) = 1;
-			*(reason + 3) = 1;
-			*(reason + 2) = 0;
-			*(reason + 1) = 1;
-			*(reason + 0) = 2;
-			result = YES;
-		}
-		else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoOutputUVPFail == YES)
-		{
-			// 012289
-			*(reason + 5) = 0;
-			*(reason + 4) = 1;
-			*(reason + 3) = 2;
-			*(reason + 2) = 2;
-			*(reason + 1) = 8;
-			*(reason + 0) = 9;
-			result = YES;
-		}
-		else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoGfdTrip == YES)
-		{
-			// 012234
-			*(reason + 5) = 0;
-			*(reason + 4) = 1;
-			*(reason + 3) = 2;
-			*(reason + 2) = 2;
-			*(reason + 1) = 3;
-			*(reason + 0) = 4;
-			result = YES;
-		}
-	}
-	else if (_chargingData[gunIndex]->Type == _Type_GB)
-	{
-		if (ShmStatusCodeData->FaultCode.FaultEvents.bits.ChademoOutputRelayDrivingFault == YES)
-		{
-			// 012290
-			*(reason + 5) = 0;
-			*(reason + 4) = 1;
-			*(reason + 3) = 2;
-			*(reason + 2) = 2;
-			*(reason + 1) = 9;
-			*(reason + 0) = 0;
-			result = YES;
-		}
-		else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbGfdTrip == YES)
-		{
-			// 012236
-			*(reason + 5) = 0;
-			*(reason + 4) = 1;
-			*(reason + 3) = 2;
-			*(reason + 2) = 2;
-			*(reason + 1) = 3;
-			*(reason + 0) = 6;
-			result = YES;
-		}
-	}
-	else if (_chargingData[gunIndex]->Type == _Type_CCS_2)
-	{
-		if (ShmStatusCodeData->FaultCode.FaultEvents.bits.CcsOutputRelayDrivingFault == YES)
-		{
-			// 011014
-			*(reason + 5) = 0;
-			*(reason + 4) = 1;
-			*(reason + 3) = 1;
-			*(reason + 2) = 0;
-			*(reason + 1) = 1;
-			*(reason + 0) = 4;
-			result = YES;
-		}
-		else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsOutputUVPFail == YES)
-		{
-			// 012288
-			*(reason + 5) = 0;
-			*(reason + 4) = 1;
-			*(reason + 3) = 2;
-			*(reason + 2) = 2;
-			*(reason + 1) = 8;
-			*(reason + 0) = 8;
-			result = YES;
-		}
-		else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsGfdTrip == YES)
-		{
-			// 012236
-			*(reason + 5) = 0;
-			*(reason + 4) = 1;
-			*(reason + 3) = 2;
-			*(reason + 2) = 2;
-			*(reason + 1) = 3;
-			*(reason + 0) = 5;
-			result = YES;
-		}
-	}
-
-	return result;
-}
-
-int main(int argc, char *argv[])
-{
-	if(InitShareMemory() == FAIL)
-	{
-		#ifdef SystemLogMessage
-		DEBUG_ERROR("InitShareMemory NG\n");
-		#endif
-		if(ShmStatusCodeData != NULL)
-		{
-			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
-		}
-		sleep(5);
-		return 0;
-	}
-
-	gun_count = ShmSysConfigAndInfo->SysConfig.TotalConnectorCount;
-	Initialization();
-	CanFd = InitCanBus();
-	CANReceiver();
-
-	byte priorityLow = 1;
-	time_t rtc = GetRtcInfoForEpoch();
-	while(CanFd)
-	{
-		for(byte _index = 0; _index < gun_count; _index++)
-		{
-			if (priorityLow == 1)
-			{
-				// 優先權較低 - 只要有回應即不會再詢問
-				if (_chargingData[_index]->Type == _Type_Chademo &&
-						ShmCHAdeMOData->evse[_chargingData[_index]->type_index].SelfTest_Comp != PASS)
-				{
-					SyncRtcInfo(_index, _chargingData[_index]->Evboard_id, (int)rtc);
-					GetFirmwareVersion(_index, _chargingData[_index]->Evboard_id);
-				}
-				else if (_chargingData[_index]->Type == _Type_GB &&
-						ShmGBTData->evse[_chargingData[_index]->type_index].SelfTest_Comp != PASS)
-				{
-					SyncRtcInfo(_index, _chargingData[_index]->Evboard_id, (int)rtc);
-					GetFirmwareVersion(_index, _chargingData[_index]->Evboard_id);
-				}
-				else if (_chargingData[_index]->Type == _Type_CCS_2)
-				{
-					if (ShmCcsData->CommProtocol == 0x01 &&
-						ShmCcsData->V2GMessage_DIN70121[_chargingData[_index]->type_index].SelfTest_Comp != PASS)
-					{
-						SyncRtcInfo(_index, _chargingData[_index]->Evboard_id, (int)rtc);
-						GetFirmwareVersion(_index, _chargingData[_index]->Evboard_id);
-					}
-				}
-
-				// 固定要取得的資訊 : 1.槍鎖狀態, 2."Connector 1" 溫度, 3."Connector 2" 溫度, 4.Pilot Voltage
-				//PRINTF_FUNC("GetMiscellaneousInfo. index = %d, Eid = %d \n", _index, _chargingData[_index]->Evboard_id);
-				GetMiscellaneousInfo(_index,
-						_chargingData[_index]->RelayK1K2Status,
-						_chargingData[_index]->PresentChargedEnergy,
-						(_chargingData[_index]->PresentChargingVoltage * 10),
-						_chargingData[_index]->Evboard_id);
-			}
-
-			switch (_chargingData[_index]->SystemStatus)
-			{
-				case S_IDLE:
-				case S_RESERVATION:
-					if (_chargingData[_index]->Type == _Type_Chademo)
-					{
-						ClearAbnormalStatus_Chademo(_index);
-					}
-					else if (_chargingData[_index]->Type == _Type_GB)
-					{
-						ClearAbnormalStatus_GB(_index);
-					}
-					else if (_chargingData[_index]->Type == _Type_CCS_2)
-					{
-						ClearAbnormalStatus_CCS(_index);
-					}
-
-					if (priorityLow == 1)
-					{
-						_chargingData[_index]->PresentChargedEnergy = 0;
-						_chargingData[_index]->PresentChargingPower = 0;
-						_chargingData[_index]->GroundFaultStatus = GFD_WAIT;
-						_chargingData[_index]->RealRatingPower = 0;
-						_chargingData[_index]->StopChargeFlag = NO;
-						_chargingData[_index]->ChargingFee = 0.0;
-						_chargingData[_index]->EvBatterySoc = 0;
-						_chargingData[_index]->PresentChargingVoltage = 0;
-						_chargingData[_index]->PresentChargingCurrent = 0;
-						_chargingData[_index]->EvBatteryMaxVoltage = 0;
-
-						chargingTime[_index] = 0;
-
-						//maxChargingCur[_index] = ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent * 10;
-						maxChargingPow = (ShmSysConfigAndInfo->SysConfig.MaxChargingPower * 10);
-					}
-					break;
-				case S_PREPARNING:
-				{
-					// 設定當前輸出
-					if (gun_count == 1)
-						SetPresentChargingOutputPower(_chargingData[0], _chargingData[0]);
-					else if (gun_count == 2)
-						SetPresentChargingOutputPower(_chargingData[0], _chargingData[1]);
-				}
-					break;
-				case S_PREPARING_FOR_EV:
-				{
-					// 開始確認車端是否同意開始充電 : 1.SOC, 2.Target Vol, 3.Target Cur, 4.Charging remaining time
-					GetOutputReq(_index, _chargingData[_index]->Evboard_id);
-
-//					PRINTF_FUNC("PresentChargingVoltage = %f \n", _chargingData[_index]->PresentChargingVoltage);
-//					PRINTF_FUNC("PresentChargingCurrent = %f \n", _chargingData[_index]->PresentChargingCurrent);
-//					PRINTF_FUNC("AvailableChargingPower = %f \n", _chargingData[_index]->AvailableChargingPower);
-//					PRINTF_FUNC("AvailableChargingCurrent = %f \n", _chargingData[_index]->AvailableChargingCurrent);
-//					PRINTF_FUNC("MaximumChargingVoltage = %f \n", _chargingData[_index]->MaximumChargingVoltage);
-
-					// 設定當前輸出
-					if (gun_count == 1)
-						SetPresentChargingOutputPower(_chargingData[0], _chargingData[0]);
-					else if (gun_count == 2)
-						SetPresentChargingOutputPower(_chargingData[0], _chargingData[1]);
-
-					if (priorityLow == 1)
-					{
-						float maxVol, maxCur;
-						// 樁端輸出能力
-						maxVol = _chargingData[_index]->MaximumChargingVoltage;
-						maxCur = _chargingData[_index]->AvailableChargingCurrent;
-
-						GetMaxVolAndCurMethod(_index, &maxVol, &maxCur);
-
-						PRINTF_FUNC("To EV_%d Max_Vol = %f, Cap_Cur = %f, Cap_Pow = %f \n",
-								_index, maxVol, maxCur, _chargingData[_index]->AvailableChargingPower);
-						_chargingData[_index]->RealMaxVoltage = maxVol;
-
-						SetChargingPermission(_index, START,
-						_chargingData[_index]->AvailableChargingPower,
-								maxCur,
-								maxVol,
-								_chargingData[_index]->Evboard_id);
-
-						// 取得車端電池資訊 : 1.AC or DC ? 2.Total battery cap, 3.Max battery vol, 4.Max battery cur
-						GetEvBatteryInfo(_index, _chargingData[_index]->Evboard_id);
-					}
-					//gettimeofday(&_chk_ratingPower_timeout[_index], NULL);
-				}
-					break;
-				case S_PREPARING_FOR_EVSE:
-				case S_CCS_PRECHARGE_ST0:
-				case S_CCS_PRECHARGE_ST1:
-				{
-					// 開始確認車端是否同意開始充電
-					GetOutputReq(_index, _chargingData[_index]->Evboard_id);
-
-					// 設定當前輸出
-					if (gun_count == 1)
-						SetPresentChargingOutputPower(_chargingData[0], _chargingData[0]);
-					else if (gun_count == 2)
-						SetPresentChargingOutputPower(_chargingData[0], _chargingData[1]);
-
-					if (priorityLow % 5 == 1)
-					{
-						// 樁端輸出能力改變
-						if (gun_count == 1)
-							SetPresentChargingOutputCap(_chargingData[0], _chargingData[0]);
-						else if (gun_count == 2)
-							SetPresentChargingOutputCap(_chargingData[0], _chargingData[1]);
-					}
-
-					// 持續通知 Isolation 測試狀態
-					if (priorityLow == 1)
-					{
-						// 拉 500 V 如果在一秒鐘內 GFD 都符合則 PASS
-//						if (_chargingData[_index]->FireChargingVoltage >= 3500)
-//							_chargingData[_index]->GroundFaultStatus = GFD_PASS;
-
-						//PRINTF_FUNC("To EV_%d GFD = %d \n",	_index, _chargingData[_index]->GroundFaultStatus);
-						//if(_chargingData[_index]->GroundFaultStatus != GFD_WAIT)
-						{
-							//if ((GetTimeoutValue(_derating_time) / 1000) > 1000)
-							unsigned char _result = GFD_WAIT;
-
-							_result = _chargingData[_index]->GroundFaultStatus;
-
-							// GB & Chademo ~ Warning 也先算 Pass,因為 CCS 認證會驗 Warning 故不可更動
-							if(_chargingData[_index]->Type == _Type_Chademo ||
-								_chargingData[_index]->Type == _Type_GB)
-							{
-								if (_result == GFD_WARNING)
-								{
-									_result = GFD_PASS;
-								}
-							}
-
-//							if (_result == GFD_WARNING || _result == GFD_PASS)
-//							{
-//								if ((GetTimeoutValue(_chk_ratingPower_timeout[_index]) / 1000) > 10000)
-//								{
-//									if (_chargingData[_index]->RealRatingPower == 0)
-//										_chargingData[_index]->RealRatingPower = _chargingData[_index]->AvailableChargingPower;
-//									_result = GFD_PASS;
-//								}
-//								else
-//									_result = GFD_WAIT;
-//							}
-
-							SetIsolationStatus(_index, _result, _chargingData[_index]->Evboard_id);
-						}
-
-						if(_chargingData[_index]->SystemStatus == S_CCS_PRECHARGE_ST0 &&
-							_chargingData[_index]->PrechargeStatus == PRECHARGE_READY)
-						{
-							SetEvsePrechargeInfo(_index, PRECHARGE_PRERELAY_PASS, _chargingData[_index]->Evboard_id);
-						}
-					}
-				}
-					break;
-				case S_CHARGING:
-				{
-					// 計算 Power
-					_chargingData[_index]->PresentChargingPower = ((float)((_chargingData[_index]->PresentChargingVoltage) * (_chargingData[_index]->PresentChargingCurrent)) / 1000);
-
-					if (chargingTime[_index] == 0 ||
-							chargingTime[_index] > _chargingData[_index]->PresentChargedDuration)
-					{
-						chargingTime[_index] = _chargingData[_index]->PresentChargedDuration;
-					}
-					else
-					{
-						int passTime = _chargingData[_index]->PresentChargedDuration - chargingTime[_index];
-
-						if (passTime > 0)
-						{
-							float changingPow = (_chargingData[_index]->PresentChargingPower) * passTime / 3600;
-							if (ShmSysConfigAndInfo->SysConfig.BillingData.isBilling)
-							{
-								_chargingData[_index]->ChargingFee += changingPow * ShmSysConfigAndInfo->SysConfig.BillingData.Cur_fee;
-							}
-
-							_chargingData[_index]->PresentChargedEnergy += changingPow;
-							chargingTime[_index] = _chargingData[_index]->PresentChargedDuration;
-						}
-					}
-
-					// 開始確認車端是否同意開始充電
-					GetOutputReq(_index, _chargingData[_index]->Evboard_id);
-
-					// 設定當前輸出
-					if (gun_count == 1)
-						SetPresentChargingOutputPower(_chargingData[0], _chargingData[0]);
-					else if (gun_count == 2)
-						SetPresentChargingOutputPower(_chargingData[0], _chargingData[1]);
-
-					// for test end
-					if (priorityLow % 5 == 0)
-					{
-						// 樁端輸出能力改變
-						if (gun_count == 1)
-							SetPresentChargingOutputCap(_chargingData[0], _chargingData[0]);
-						else if (gun_count == 2)
-							SetPresentChargingOutputCap(_chargingData[0], _chargingData[1]);
-					}
-
-					// GFD 失敗再通知
-					if (priorityLow == 1)
-					{
-						if(_chargingData[_index]->GroundFaultStatus == GFD_FAIL)
-						{
-							SetIsolationStatus(_index, _chargingData[_index]->GroundFaultStatus, _chargingData[_index]->Evboard_id);
-						}
-
-						if(_chargingData[_index]->Type == _Type_CCS_2 &&
-							_chargingData[_index]->PrechargeStatus == PRECHARGE_READY)
-						{
-							SetEvsePrechargeInfo(_index, PRECHARGE_CHARELAY_PASS, _chargingData[_index]->Evboard_id);
-						}
-					}
-				}
-					break;
-				case S_TERMINATING:
-				{
-					// 設定當前輸出
-					if (gun_count == 1)
-						SetPresentChargingOutputPower(_chargingData[0], _chargingData[0]);
-					else if (gun_count == 2)
-						SetPresentChargingOutputPower(_chargingData[0], _chargingData[1]);
-
-					// 槍鎖還在,則代表是樁端要求的停止
-					if (_chargingData[_index]->GunLocked == START ||
-							_chargingData[_index]->Type == _Type_CCS_2)
-					{
-						byte normalStop = 0x01;
-						byte stopReason[6] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
-
-						if (GetStopChargingReasonByEvse(_index, stopReason))
-						{
-							normalStop = 0x02;
-						}
-
-						EvseStopChargingEvent(normalStop, stopReason, _chargingData[_index]->Evboard_id);
-					}
-					GetOutputReq(_index, _chargingData[_index]->Evboard_id);
-				}
-					break;
-				case S_COMPLETE:
-				{
-					if (priorityLow == 1)
-					{
-						float maxVol, maxCur;
-
-						// 樁端輸出能力
-						maxVol = _chargingData[_index]->MaximumChargingVoltage;
-						maxCur = _chargingData[_index]->AvailableChargingCurrent;
-
-						GetMaxVolAndCurMethod(_index, &maxVol, &maxCur);
-						SetChargingPermission(_index, STOP,
-								_chargingData[_index]->AvailableChargingPower,
-								maxCur,
-								maxVol,
-								_chargingData[_index]->Evboard_id);
-					}
-				}
-					break;
-			}
-		}
-		priorityLow >= 20 ? priorityLow = 1 : priorityLow++;
-		usleep(45000); //EV 小板通訊 (50 ms)
-	}
-	DEBUG_INFO("Module_EvComm : Can-bus port = %d \n", CanFd);
-	return FAIL;
-}
+/*
+ * Module_EvComm.c
+ *
+ *  Created on: 2020嚙羯9嚙踝蕭14嚙踝蕭
+ *      Author: Wendell
+ */
+
+#include 	<sys/time.h>
+#include 	<sys/timeb.h>
+#include    <sys/types.h>
+#include    <sys/stat.h>
+#include 	<sys/types.h>
+#include 	<sys/ioctl.h>
+#include 	<sys/socket.h>
+#include 	<sys/ipc.h>
+#include 	<sys/shm.h>
+#include 	<sys/shm.h>
+#include 	<sys/mman.h>
+#include 	<linux/can.h>
+#include 	<linux/can/raw.h>
+#include 	<linux/wireless.h>
+#include 	<arpa/inet.h>
+#include 	<netinet/in.h>
+
+#include 	<unistd.h>
+#include 	<stdarg.h>
+#include    <stdio.h>      /*璅蹱�頛詨�頛詨枂摰𡁶儔*/
+#include    <stdlib.h>     /*璅蹱��賣彍摨怠�蝢�*/
+#include    <unistd.h>     /*Unix 璅蹱��賣彍摰𡁶儔*/
+#include    <fcntl.h>      /*瑼娍綉�嗅�蝢�*/
+#include    <termios.h>    /*PPSIX 蝯�垢�批�摰𡁶儔*/
+#include    <errno.h>      /*�航炊�笔�蝢�*/
+#include 	<errno.h>
+#include 	<string.h>
+#include	<time.h>
+#include	<ctype.h>
+#include 	<ifaddrs.h>
+#include 	<signal.h>
+#include 	<net/if_arp.h>
+#include	"../../define.h"
+#include 	"Module_EvComm.h"
+#include	"Config.h"
+
+#define ARRAY_SIZE(A)				(sizeof(A) / sizeof(A[0]))
+#define PASS						1
+#define FAIL			   			-1
+#define YES							1
+#define NO							0
+#define ON							1
+#define OFF							0
+#define true			    		1
+#define false						0
+
+struct SysConfigAndInfo				*ShmSysConfigAndInfo;
+
+void PRINTF_FUNC(char *string, ...);
+
+int StoreLogMsg(const char *fmt, ...);
+#define DEBUG_INFO(format, args...) PRINTF_FUNC("[%s:%d][%s][Info] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
+#define DEBUG_WARN(format, args...) PRINTF_FUNC("[%s:%d][%s][Warn] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
+#define DEBUG_ERROR(format, args...) PRINTF_FUNC("[%s:%d][%s][Error] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
+
+int StoreLogMsg(const char *fmt, ...)
+{
+	char Buf[4096+256];
+	char buffer[4096];
+	va_list args;
+	struct timeb  SeqEndTime;
+	struct tm *tm;
+
+	va_start(args, fmt);
+	int rc = vsnprintf(buffer, sizeof(buffer), fmt, args);
+	va_end(args);
+
+	memset(Buf,0,sizeof(Buf));
+	ftime(&SeqEndTime);
+	SeqEndTime.time = time(NULL);
+	tm=localtime(&SeqEndTime.time);
+
+	if (ShmSysConfigAndInfo->SysConfig.SwitchDebugFlag == YES)
+	{
+		sprintf(Buf,"%02d:%02d:%02d:%03d - %s",
+			tm->tm_hour,tm->tm_min,tm->tm_sec,SeqEndTime.millitm, buffer);
+		printf("%s \n", Buf);
+	}
+	else
+	{
+		sprintf(Buf,"echo \"%04d-%02d-%02d %02d:%02d:%02d:%03d - %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,SeqEndTime.millitm,
+			buffer,
+			tm->tm_year+1900,tm->tm_mon+1);
+		system(Buf);
+	}
+
+	return rc;
+}
+
+void PRINTF_FUNC(char *string, ...)
+{
+	va_list args;
+	char buffer[4096];
+	va_start(args, string);
+	vsnprintf(buffer, sizeof(buffer), string, args);
+	va_end(args);
+
+	printf("%s \n", buffer);
+}
+
+void ShowSocketData(struct PACKET_STRUCTURE *packet)
+{
+	printf("se: %02X, id: %02X, op: %d, len: %3d, reg: %02X",
+		packet->Header.se, packet->Header.id, packet->Header.op, packet->Header.len, packet->Payload.reg);
+
+	if(packet->Header.len > 1)
+	{
+		printf(", Data:");
+		for(int i = 0; i < packet->Header.len - 1; i++)
+		{
+			printf(" %02X", packet->Payload.data[i]);
+		}
+	}
+	printf("\n");
+}
+
+//==========================================
+// Init all share memory
+//==========================================
+int InitShareMemory()
+{
+	int result = PASS;
+	int MeterSMId;
+
+	//creat ShmSysConfigAndInfo
+	if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), IPC_CREAT | 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 ShmOCPP16Data
+	if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data),  0777)) < 0)
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR("shmget ShmOCPP16Data NG");
+		#endif
+		result = FAIL;
+	}
+	else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR("shmat ShmOCPP16Data NG");
+		#endif
+		result = FAIL;
+	}
+	else
+	{}
+
+	//creat ShmPsuData
+	if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData),  0777)) < 0)
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR("shmget ShmPsuData NG \n");
+		#endif
+		result = FAIL;
+	}
+	else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR("shmat ShmPsuData NG \n");
+		#endif
+		result = FAIL;
+	 }
+	memset(ShmPsuData,0,sizeof(struct PsuData));
+	*/
+	return result;
+}
+
+//-------------------------------------------Socket Client Start-------------------------------------------
+unsigned char seqNum = 0;
+
+void sendCmdDispenserModelName(int socket, unsigned char se)
+{
+	struct PACKET_STRUCTURE sendBuffer;
+	char *modelName = "DSYE601J0EW2PH";
+	//char *modelName = "DSYE601J00W2PH";
+
+	memset(&sendBuffer, 0x00, sizeof(sendBuffer));
+	sendBuffer.Header.se = se;
+	sendBuffer.Header.id = 0xFF;
+	sendBuffer.Header.op = _Header_Write;
+	sendBuffer.Header.len = strlen(modelName) + 2;
+	sendBuffer.Payload.reg = _Reg_Dispenser_Model_Name;
+	memcpy(&sendBuffer.Payload.data[0], modelName, strlen(modelName));
+	sendBuffer.Payload.data[strlen(modelName)] = 1;
+
+	send(socket, &sendBuffer, sendBuffer.Header.len + 4, 0);
+}
+
+void sendCmdDispenserConnectorIDRequest(int socket, unsigned char se)
+{
+	struct PACKET_STRUCTURE sendBuffer;
+
+	memset(&sendBuffer, 0x00, sizeof(sendBuffer));
+	sendBuffer.Header.se = se;
+	sendBuffer.Header.id = 0xFF;
+	sendBuffer.Header.op = _Header_Read;
+	sendBuffer.Header.len = 1;
+	sendBuffer.Payload.reg = _Reg_Connector_ID;
+
+	send(socket, &sendBuffer, sendBuffer.Header.len + 4, 0);
+}
+
+void sendCmdPowerCabinetStatusRequest(int socket, unsigned char connector, unsigned char se)
+{
+	struct PACKET_STRUCTURE sendBuffer;
+
+	memset(&sendBuffer, 0x00, sizeof(sendBuffer));
+	sendBuffer.Header.se = se;
+	sendBuffer.Header.id = connector;
+	sendBuffer.Header.op = _Header_Read;
+	sendBuffer.Header.len = 1;
+	sendBuffer.Payload.reg = _Reg_Power_Cabinet_Status;
+
+	send(socket, &sendBuffer, sendBuffer.Header.len + 4, 0);
+}
+
+void sendCmdWriteDispenserStatus(int socket, unsigned char connector, unsigned char se)
+{
+	struct PACKET_STRUCTURE sendBuffer;
+
+	memset(&sendBuffer, 0x00, sizeof(sendBuffer));
+	sendBuffer.Header.se = se;
+	sendBuffer.Header.id = connector;
+	sendBuffer.Header.op = _Header_Write;
+	sendBuffer.Header.len = 1;
+	sendBuffer.Payload.reg = _Reg_Dispenser_Status;
+
+	send(socket, &sendBuffer, sendBuffer.Header.len + 4, 0);
+}
+
+void sendCmdReadChargingCapability(int socket, unsigned char connector, unsigned char se)
+{
+	struct PACKET_STRUCTURE sendBuffer;
+
+	memset(&sendBuffer, 0x00, sizeof(sendBuffer));
+	sendBuffer.Header.se = se;
+	sendBuffer.Header.id = connector;
+	sendBuffer.Header.op = _Header_Read;
+	sendBuffer.Header.len = 1;
+	sendBuffer.Payload.reg = _Reg_Charging_Capability;
+
+	send(socket, &sendBuffer, sendBuffer.Header.len + 4, 0);
+}
+
+void sendCmdWriteChargingTarget(int socket, unsigned char connector, unsigned char se, unsigned short voltage, unsigned short current)
+{
+	struct PACKET_STRUCTURE sendBuffer;
+
+	memset(&sendBuffer, 0x00, sizeof(sendBuffer));
+	sendBuffer.Header.se = se;
+	sendBuffer.Header.id = connector;
+	sendBuffer.Header.op = _Header_Write;
+	sendBuffer.Header.len = 5;
+	sendBuffer.Payload.reg = _Reg_Charging_Target;
+	sendBuffer.Payload.data[0] = (voltage >> 8) & 0xFF;
+	sendBuffer.Payload.data[1] = voltage & 0xFF;
+	sendBuffer.Payload.data[2] = (current >> 8) & 0xFF;
+	sendBuffer.Payload.data[3] = current & 0xFF;
+
+	send(socket, &sendBuffer, sendBuffer.Header.len + 4, 0);
+}
+
+void sendCmdWritePlugInStatus(int socket, unsigned char connector, unsigned char se)
+{
+	struct PACKET_STRUCTURE sendBuffer;
+
+	memset(&sendBuffer, 0x00, sizeof(sendBuffer));
+	sendBuffer.Header.se = se;
+	sendBuffer.Header.id = connector;
+	sendBuffer.Header.op = _Header_Write;
+	sendBuffer.Header.len = 2;
+	sendBuffer.Payload.reg = _Reg_Plug_In_Status;
+	sendBuffer.Payload.data[0] = se % 2 == 0 ?_PIS_UnPlugged : _PIS_PluggedIn;
+
+	send(socket, &sendBuffer, sendBuffer.Header.len + 4, 0);
+}
+
+void sendCmdWriteConnectorState(int socket, unsigned char connector, unsigned char se)
+{
+	struct PACKET_STRUCTURE sendBuffer;
+
+	memset(&sendBuffer, 0x00, sizeof(sendBuffer));
+	sendBuffer.Header.se = se;
+	sendBuffer.Header.id = connector;
+	sendBuffer.Header.op = _Header_Write;
+	sendBuffer.Header.len = 2;
+	sendBuffer.Payload.reg = _Reg_Connector_State;
+	sendBuffer.Payload.data[0] = _CRS_Idle;
+
+	send(socket, &sendBuffer, sendBuffer.Header.len + 4, 0);
+}
+
+void sendCmdWriteUserID(int socket, unsigned char connector, unsigned char se)
+{
+	struct PACKET_STRUCTURE sendBuffer;
+	char *userID = "010203040506";
+
+	memset(&sendBuffer, 0x00, sizeof(sendBuffer));
+	sendBuffer.Header.se = se;
+	sendBuffer.Header.id = connector;
+	sendBuffer.Header.op = _Header_Write;
+	sendBuffer.Header.len = strlen(userID) + 1;
+	sendBuffer.Payload.reg = _Reg_User_ID;
+	memcpy(sendBuffer.Payload.data, userID, strlen(userID));
+
+	send(socket, &sendBuffer, sendBuffer.Header.len + 4, 0);
+}
+
+void sendCmdReadChargingPermission(int socket, unsigned char connector, unsigned char se)
+{
+	struct PACKET_STRUCTURE sendBuffer;
+
+	memset(&sendBuffer, 0x00, sizeof(sendBuffer));
+	sendBuffer.Header.se = se;
+	sendBuffer.Header.id = connector;
+	sendBuffer.Header.op = _Header_Read;
+	sendBuffer.Header.len = 1;
+	sendBuffer.Payload.reg = _Reg_Charging_Permission;
+
+	send(socket, &sendBuffer, sendBuffer.Header.len + 4, 0);
+}
+
+int DispenserModelNameCheckIn(int socket, unsigned char se)
+{
+	int rxLen = 0, timeout = 0;
+	struct PACKET_STRUCTURE receiveBuffer;
+	int result = FAIL;
+
+	sendCmdDispenserModelName(socket, se);
+	while(1)
+	{
+		if((rxLen = recv(socket, &receiveBuffer, sizeof(Packet_Structure), MSG_DONTWAIT )) > 0)
+		{
+			if(rxLen == (receiveBuffer.Header.len + PACKET_HEADER_LENGTH))
+			{
+				ShowSocketData(&receiveBuffer);
+
+				if(receiveBuffer.Header.len == 2)
+				{
+					if(receiveBuffer.Payload.reg == _Reg_Dispenser_Model_Name && receiveBuffer.Payload.data[0] == _R_OK)
+					{
+						PRINTF_FUNC("Write Model Name OK");
+						result = PASS;
+						break;
+					}
+				}
+			}
+		}
+
+		timeout += SOCKET_RECEIVE_INTERVAL;
+		usleep((SOCKET_RECEIVE_INTERVAL * 1000));
+
+		if(timeout >= DISPENSER_MODEL_NAME_RESEND)
+		{
+			//timeout
+			break;
+		}
+	}
+
+	return result;
+}
+
+int DispenserConnectorRequest(int socket, unsigned char se)
+{
+	int rxLen = 0, timeout = 0;
+	struct PACKET_STRUCTURE receiveBuffer;
+	int result = FAIL;
+
+	sendCmdDispenserConnectorIDRequest(socket, se);
+	while(1)
+	{
+		if((rxLen = recv(socket, &receiveBuffer, sizeof(Packet_Structure), MSG_DONTWAIT )) > 0)
+		{
+			if(rxLen == (receiveBuffer.Header.len + PACKET_HEADER_LENGTH))
+			{
+				ShowSocketData(&receiveBuffer);
+
+				if(receiveBuffer.Header.len == 4)
+				{
+					if(receiveBuffer.Payload.reg == _Reg_Connector_ID && receiveBuffer.Payload.data[0] == _R_OK)
+					{
+						PRINTF_FUNC("Get Connector ID: %02X, %02X", receiveBuffer.Payload.data[1], receiveBuffer.Payload.data[2]);
+						result = PASS;
+						break;
+					}
+				}
+			}
+		}
+
+		timeout += SOCKET_RECEIVE_INTERVAL;
+		usleep((SOCKET_RECEIVE_INTERVAL * 1000));
+
+		if(timeout >= DISPENSER_CONNECTOR_RESEND)
+		{
+			//timeout
+			break;
+		}
+	}
+
+	return result;
+}
+
+int DispenserReadPowerCabinetStatus(int socket, unsigned char connector, unsigned char se)
+{
+	int rxLen = 0, timeout = 0;
+	struct PACKET_STRUCTURE receiveBuffer;
+	int result = FAIL;
+
+	sendCmdPowerCabinetStatusRequest(socket, connector, se);
+	while(1)
+	{
+		if((rxLen = recv(socket, &receiveBuffer, sizeof(Packet_Structure), MSG_DONTWAIT )) > 0)
+		{
+			if(rxLen == (receiveBuffer.Header.len + PACKET_HEADER_LENGTH))
+			{
+				ShowSocketData(&receiveBuffer);
+
+				if(receiveBuffer.Payload.reg == _Reg_Power_Cabinet_Status && receiveBuffer.Payload.data[0] == _R_OK)
+				{
+					PRINTF_FUNC("Get Cabinet Status Code, Len: %d", (receiveBuffer.Header.len - 2) / 6);
+					result = PASS;
+				}
+			}
+		}
+
+		timeout += SOCKET_RECEIVE_INTERVAL;
+		usleep((SOCKET_RECEIVE_INTERVAL * 1000));
+
+		if(timeout >= CABINET_STATUS_REQUEST_RESEND)
+		{
+			//timeout
+			break;
+		}
+	}
+
+	return result;
+}
+
+int DispenserWriteStatusCode(int socket, unsigned char connector, unsigned char se)
+{
+	int rxLen = 0, timeout = 0;
+	struct PACKET_STRUCTURE receiveBuffer;
+	int result = FAIL;
+
+	sendCmdWriteDispenserStatus(socket, connector, se);
+	while(1)
+	{
+		if((rxLen = recv(socket, &receiveBuffer, sizeof(Packet_Structure), MSG_DONTWAIT )) > 0)
+		{
+			if(rxLen == (receiveBuffer.Header.len + PACKET_HEADER_LENGTH))
+			{
+				ShowSocketData(&receiveBuffer);
+
+				if(receiveBuffer.Header.len == 2)
+				{
+					if(receiveBuffer.Payload.reg == _Reg_Dispenser_Status && receiveBuffer.Payload.data[0] == _R_OK)
+					{
+						PRINTF_FUNC("Write Dispenser Status Code OK");
+						result = PASS;
+					}
+				}
+			}
+		}
+
+		timeout += SOCKET_RECEIVE_INTERVAL;
+		usleep((SOCKET_RECEIVE_INTERVAL * 1000));
+
+		if(timeout >= CABINET_STATUS_REQUEST_RESEND)
+		{
+			//timeout
+			break;
+		}
+	}
+
+	return result;
+}
+
+int DispenserReadChargingCapability(int socket, unsigned char connector, unsigned char se)
+{
+	int rxLen = 0, timeout = 0;
+	struct PACKET_STRUCTURE receiveBuffer;
+	int result = FAIL;
+	unsigned short voltage = 0, current = 0, power = 0;
+
+	sendCmdReadChargingCapability(socket, connector, se);
+	while(1)
+	{
+		if((rxLen = recv(socket, &receiveBuffer, sizeof(Packet_Structure), MSG_DONTWAIT )) > 0)
+		{
+			if(rxLen == (receiveBuffer.Header.len + PACKET_HEADER_LENGTH))
+			{
+				ShowSocketData(&receiveBuffer);
+
+				if(receiveBuffer.Header.len == 8)
+				{
+					if(receiveBuffer.Payload.reg == _Reg_Charging_Capability && receiveBuffer.Payload.data[0] == _R_OK)
+					{
+						voltage = (receiveBuffer.Payload.data[1] << 8) + receiveBuffer.Payload.data[2];
+						current = (receiveBuffer.Payload.data[3] << 8) + receiveBuffer.Payload.data[4];
+						power = (receiveBuffer.Payload.data[5] << 8) + receiveBuffer.Payload.data[6];
+
+						PRINTF_FUNC("Capability Voltage: %d.%dV, Current: %d.%dA, Power: %d.%dkW",
+							voltage / 10, voltage % 10, current / 10, current % 10, power / 10, power % 10);
+						result = PASS;
+					}
+				}
+			}
+		}
+
+		timeout += SOCKET_RECEIVE_INTERVAL;
+		usleep((SOCKET_RECEIVE_INTERVAL * 1000));
+
+		if(timeout >= CHARGING_CAPABILITY_RESEND)
+		{
+			//timeout
+			break;
+		}
+	}
+
+	return result;
+}
+
+int DispenserWriteChargingTarget(int socket, unsigned char connector, unsigned char se)
+{
+	int rxLen = 0, timeout = 0;
+	struct PACKET_STRUCTURE receiveBuffer;
+	int result = FAIL;
+
+	sendCmdWriteChargingTarget(socket, connector, se, 7505, 406);
+	while(1)
+	{
+		if((rxLen = recv(socket, &receiveBuffer, sizeof(Packet_Structure), MSG_DONTWAIT )) > 0)
+		{
+			if(rxLen == (receiveBuffer.Header.len + PACKET_HEADER_LENGTH))
+			{
+				ShowSocketData(&receiveBuffer);
+
+				if(receiveBuffer.Header.len == 2)
+				{
+					if(receiveBuffer.Payload.reg == _Reg_Charging_Target && receiveBuffer.Payload.data[0] == _R_OK)
+					{
+						PRINTF_FUNC("Write Charging Target OK");
+						result = PASS;
+					}
+				}
+			}
+		}
+
+		timeout += SOCKET_RECEIVE_INTERVAL;
+		usleep((SOCKET_RECEIVE_INTERVAL * 1000));
+
+		if(timeout >= CHARGING_CAPABILITY_RESEND)
+		{
+			//timeout
+			break;
+		}
+	}
+
+	return result;
+}
+
+int DispenserWritePlugInStatus(int socket, unsigned char connector, unsigned char se)
+{
+	int rxLen = 0, timeout = 0;
+	struct PACKET_STRUCTURE receiveBuffer;
+	int result = FAIL;
+
+	sendCmdWritePlugInStatus(socket, connector, se);
+	while(1)
+	{
+		if((rxLen = recv(socket, &receiveBuffer, sizeof(Packet_Structure), MSG_DONTWAIT )) > 0)
+		{
+			if(rxLen == (receiveBuffer.Header.len + PACKET_HEADER_LENGTH))
+			{
+				ShowSocketData(&receiveBuffer);
+
+				if(receiveBuffer.Header.len == 2)
+				{
+					if(receiveBuffer.Payload.reg == _Reg_Plug_In_Status && receiveBuffer.Payload.data[0] == _R_OK)
+					{
+						PRINTF_FUNC("Write Plug In Status OK");
+						result = PASS;
+					}
+				}
+			}
+		}
+
+		timeout += SOCKET_RECEIVE_INTERVAL;
+		usleep((SOCKET_RECEIVE_INTERVAL * 1000));
+
+		if(timeout >= CHARGING_CAPABILITY_RESEND)
+		{
+			//timeout
+			break;
+		}
+	}
+
+	return result;
+}
+
+int DispenserWriteConnectorState(int socket, unsigned char connector, unsigned char se)
+{
+	int rxLen = 0, timeout = 0;
+	struct PACKET_STRUCTURE receiveBuffer;
+	int result = FAIL;
+
+	sendCmdWriteConnectorState(socket, connector, se);
+	while(1)
+	{
+		if((rxLen = recv(socket, &receiveBuffer, sizeof(Packet_Structure), MSG_DONTWAIT )) > 0)
+		{
+			if(rxLen == (receiveBuffer.Header.len + PACKET_HEADER_LENGTH))
+			{
+				ShowSocketData(&receiveBuffer);
+
+				if(receiveBuffer.Header.len == 2)
+				{
+					if(receiveBuffer.Payload.reg == _Reg_Connector_State && receiveBuffer.Payload.data[0] == _R_OK)
+					{
+						PRINTF_FUNC("Write Connector State OK");
+						result = PASS;
+					}
+				}
+			}
+		}
+
+		timeout += SOCKET_RECEIVE_INTERVAL;
+		usleep((SOCKET_RECEIVE_INTERVAL * 1000));
+
+		if(timeout >= CHARGING_CAPABILITY_RESEND)
+		{
+			//timeout
+			break;
+		}
+	}
+
+	return result;
+}
+
+int DispenserWriteUserID(int socket, unsigned char connector, unsigned char se)
+{
+	int rxLen = 0, timeout = 0;
+	struct PACKET_STRUCTURE receiveBuffer;
+	int result = FAIL;
+
+	sendCmdWriteUserID(socket, connector, se);
+	while(1)
+	{
+		if((rxLen = recv(socket, &receiveBuffer, sizeof(Packet_Structure), MSG_DONTWAIT )) > 0)
+		{
+			if(rxLen == (receiveBuffer.Header.len + PACKET_HEADER_LENGTH))
+			{
+				ShowSocketData(&receiveBuffer);
+
+				if(receiveBuffer.Header.len == 2)
+				{
+					if(receiveBuffer.Payload.reg == _Reg_User_ID && receiveBuffer.Payload.data[0] == _R_OK)
+					{
+						PRINTF_FUNC("Write User ID OK");
+						result = PASS;
+					}
+				}
+			}
+		}
+
+		timeout += SOCKET_RECEIVE_INTERVAL;
+		usleep((SOCKET_RECEIVE_INTERVAL * 1000));
+
+		if(timeout >= CHARGING_CAPABILITY_RESEND)
+		{
+			//timeout
+			break;
+		}
+	}
+
+	return result;
+}
+
+int DispenserReadChargingPermission(int socket, unsigned char connector, unsigned char se)
+{
+	int rxLen = 0, timeout = 0;
+	struct PACKET_STRUCTURE receiveBuffer;
+	int result = FAIL;
+
+	sendCmdReadChargingPermission(socket, connector, se);
+	while(1)
+	{
+		if((rxLen = recv(socket, &receiveBuffer, sizeof(Packet_Structure), MSG_DONTWAIT )) > 0)
+		{
+			if(rxLen == (receiveBuffer.Header.len + PACKET_HEADER_LENGTH))
+			{
+				ShowSocketData(&receiveBuffer);
+
+				if(receiveBuffer.Header.len == 3)
+				{
+					if(receiveBuffer.Payload.reg == _Reg_Charging_Permission && receiveBuffer.Payload.data[0] == _R_OK)
+					{
+						PRINTF_FUNC("Charging Permission: %s", receiveBuffer.Payload.data[1] == _PS_Permitted ? "Permitted" : "Not Permitted");
+						result = PASS;
+					}
+				}
+			}
+		}
+
+		timeout += SOCKET_RECEIVE_INTERVAL;
+		usleep((SOCKET_RECEIVE_INTERVAL * 1000));
+
+		if(timeout >= CHARGING_CAPABILITY_RESEND)
+		{
+			//timeout
+			break;
+		}
+	}
+
+	return result;
+}
+
+void tcpSocketClientStart(void)
+{
+	struct sockaddr_in 	info;
+	struct timeval 		tv;
+	uint8_t 			socketEnable;
+	int 				sockfd = 0;
+	unsigned char clientStatus = 0;
+	unsigned char se = 0;
+
+	//start dhcp client
+	//udhcpc -i eth1 --script /root/dhcp_script/eth1.script
+	//udhcpc -i eth1 -s /root/dhcp_script/eth1.script &
+	//udhcpc -i eth0 -x hostname CSU3_DSYE601J0EW2PH-SERIALFORRD -s /root/dhcp_script/eth0.script
+	for(;;)
+	{
+		bzero(&info,sizeof(info));
+		info.sin_family = PF_INET;
+		info.sin_addr.s_addr = inet_addr(SOCKET_SERVER_IP);
+		info.sin_port = htons(TCP_LISTEN_PORT);
+
+		sockfd = socket(AF_INET, SOCK_STREAM, 0);
+		if (sockfd == -1)
+		{
+			PRINTF_FUNC("Fail to create a socket.");
+			return;
+		}
+		PRINTF_FUNC("TCP Client Start");
+
+		if(connect(sockfd, (struct sockaddr *)&info, sizeof(info)) == -1)
+		{
+			PRINTF_FUNC("Connection error");
+		}
+		else
+		{
+			PRINTF_FUNC("Connect to %s success", inet_ntoa(info.sin_addr));
+			tv.tv_sec = 0;
+			tv.tv_usec = 500000;
+			setsockopt(sockfd, SOL_SOCKET, SO_RCVTIMEO, (const char*)&tv, sizeof tv);
+			socketEnable = ON;
+		}
+
+		while(socketEnable)
+		{
+			switch(clientStatus)
+			{
+				case 0:
+					//5.1 Dispenser model name
+					if(DispenserModelNameCheckIn(sockfd, se++) == PASS)
+					{
+						clientStatus = 1;
+					}
+					break;
+				case 1:
+					if(DispenserConnectorRequest(sockfd, se++) == PASS)
+					{
+						clientStatus = 2;
+					}
+					break;
+				case 2:
+					if(DispenserReadPowerCabinetStatus(sockfd, 0x01, se++) == PASS)
+					{
+						if(DispenserWriteStatusCode(sockfd, 0x01, se++) == PASS)
+						{
+							clientStatus = 3;
+						}
+					}
+					break;
+				case 3:
+					if(DispenserWriteUserID(sockfd, 0x01, se++) == PASS)
+					{
+						clientStatus = 4;
+					}
+					break;
+				case 4:
+					if(DispenserReadChargingCapability(sockfd, 0x01, se++) == PASS)
+					{
+
+					}
+					if(DispenserWriteChargingTarget(sockfd, 0x01, se++) == PASS)
+					{
+
+					}
+					if(DispenserWritePlugInStatus(sockfd, 0x01, se++) == PASS)
+					{
+
+					}
+					if(DispenserWriteConnectorState(sockfd, 0x01, se++) == PASS)
+					{
+
+					}
+					if(DispenserReadChargingPermission(sockfd, 0x01, se++) == PASS)
+					{
+
+					}
+					break;
+				default:
+					break;
+			}
+		}
+		close(sockfd);
+		sleep(5);
+		return;
+	}
+}
+
+//--------------------------------------------Socket Client End--------------------------------------------
+
+BOOL IsAvalibleGunType(char name, unsigned char *type)
+{
+	char modelList[6] = {'J', 'U', 'E', 'G', 'V', 'F'};
+	unsigned char typeList[6] = {0, 1, 1, 2, 1, 1};		// 0 : Chademo, 1: CCS, 2: GB
+
+	for(int i = 0; i < 6; i++)
+	{
+		if(name == modelList[i])
+		{
+			*type = typeList[i];
+			return true;
+		}
+	}
+	return false;
+}
+
+unsigned char ConnectorQuantityTypeParsing(unsigned char *modelName, unsigned char *type)
+{
+	unsigned char quantity = 0;
+
+	for(int i = 0; i < 3; i++)
+	{
+		if(IsAvalibleGunType(modelName[7 + i], type))
+		{
+			if(quantity < 2)
+			{
+				quantity++;
+			}
+			else
+			{
+				quantity = 0;
+				break;
+			}
+		}
+	}
+	return quantity;
+}
+
+void ModelNameResponse(int socket, struct PACKET_STRUCTURE *packet, unsigned char result)
+{
+	struct PACKET_STRUCTURE sendBuffer;
+
+	memset(&sendBuffer, 0x00, sizeof(sendBuffer));
+	sendBuffer.Header.se = packet->Header.se;
+	sendBuffer.Header.id = 0xFF;
+	sendBuffer.Header.op = _Header_Response;
+	sendBuffer.Header.len = 2;
+	sendBuffer.Payload.reg = _Reg_Dispenser_Model_Name;
+	sendBuffer.Payload.data[0] = result;
+
+	send(socket, &sendBuffer, sendBuffer.Header.len + 4, 0);
+}
+
+void ConnectorIDResponse(int socket, struct PACKET_STRUCTURE *packet, unsigned char result, unsigned char dispenserIndex)
+{
+	struct PACKET_STRUCTURE sendBuffer;
+
+	memset(&sendBuffer, 0x00, sizeof(sendBuffer));
+	sendBuffer.Header.se = packet->Header.se;
+	sendBuffer.Header.id = 0xFF;
+	sendBuffer.Header.op = _Header_Response;
+	sendBuffer.Header.len = 4;
+	sendBuffer.Payload.reg = _Reg_Connector_ID;
+	sendBuffer.Payload.data[0] = result;
+	sendBuffer.Payload.data[1] = ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].ConnectorID[0];
+	sendBuffer.Payload.data[2] = ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].ConnectorID[1];
+
+	send(socket, &sendBuffer, sendBuffer.Header.len + 4, 0);
+}
+
+void PowerCabinetStatusResponse(int socket, struct PACKET_STRUCTURE *packet)
+{
+	struct PACKET_STRUCTURE sendBuffer;
+
+	memset(&sendBuffer, 0x00, sizeof(sendBuffer));
+	sendBuffer.Header.se = packet->Header.se;
+	sendBuffer.Header.id = packet->Header.id;
+	sendBuffer.Header.op = _Header_Response;
+	sendBuffer.Header.len = 2;
+	sendBuffer.Payload.reg = _Reg_Power_Cabinet_Status;
+	sendBuffer.Payload.data[0] = _R_OK;
+
+	if(ShmSysConfigAndInfo->SysWarningInfo.WarningCount > 0)
+	{
+		sendBuffer.Header.len += (ShmSysConfigAndInfo->SysWarningInfo.WarningCount * 6);
+		for(int i = 0; i < ShmSysConfigAndInfo->SysWarningInfo.WarningCount; i++)
+		{
+		    memcpy(&sendBuffer.Payload.data[1 + (i * 6)], &ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], ShmSysConfigAndInfo->SysWarningInfo.WarningCount * 6);
+		}
+	}
+
+	send(socket, &sendBuffer, sendBuffer.Header.len + 4, 0);
+}
+
+void DispenserStatusResponse(int socket, struct PACKET_STRUCTURE *packet, unsigned char result)
+{
+	struct PACKET_STRUCTURE sendBuffer;
+
+	memset(&sendBuffer, 0x00, sizeof(sendBuffer));
+	sendBuffer.Header.se = packet->Header.se;
+	sendBuffer.Header.id = packet->Header.id;
+	sendBuffer.Header.op = _Header_Response;
+	sendBuffer.Header.len = 2;
+	sendBuffer.Payload.reg = _Reg_Dispenser_Status;
+	sendBuffer.Payload.data[0] = result;
+
+	send(socket, &sendBuffer, sendBuffer.Header.len + 4, 0);
+}
+
+void ChargingCapabilityResponse(int socket, struct PACKET_STRUCTURE *packet)
+{
+	struct PACKET_STRUCTURE sendBuffer;
+	unsigned short voltage = 0, current = 0, power = 0;
+
+	memset(&sendBuffer, 0x00, sizeof(sendBuffer));
+	voltage = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].GeneralChargingData.MaximumChargingVoltage;
+	current = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].GeneralChargingData.AvailableChargingCurrent;
+	power = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].GeneralChargingData.AvailableChargingPower;
+
+	PRINTF_FUNC("Connector %d Capability Voltage: %d, Current: %d, Power: %d", packet->Header.id, (int)(voltage), (int)(current), (int)(power));
+
+	sendBuffer.Header.se = packet->Header.se;
+	sendBuffer.Header.id = packet->Header.id;
+	sendBuffer.Header.op = _Header_Response;
+	sendBuffer.Header.len = 8;
+	sendBuffer.Payload.reg = _Reg_Charging_Capability;
+	sendBuffer.Payload.data[0] = _R_OK;
+	sendBuffer.Payload.data[1] = ((voltage >> 8) & 0xFF);
+	sendBuffer.Payload.data[2] = (voltage & 0xFF);
+	sendBuffer.Payload.data[3] = ((current >> 8) & 0xFF);
+	sendBuffer.Payload.data[4] = (current & 0xFF);
+	sendBuffer.Payload.data[5] = ((power >> 8) & 0xFF);
+	sendBuffer.Payload.data[6] = (power & 0xFF);
+
+	send(socket, &sendBuffer, sendBuffer.Header.len + 4, 0);
+}
+
+void ChargingTargetResponse(int socket, struct PACKET_STRUCTURE *packet, unsigned char result)
+{
+	struct PACKET_STRUCTURE sendBuffer;
+
+	memset(&sendBuffer, 0x00, sizeof(sendBuffer));
+	sendBuffer.Header.se = packet->Header.se;
+	sendBuffer.Header.id = packet->Header.id;
+	sendBuffer.Header.op = _Header_Response;
+	sendBuffer.Header.len = 2;
+	sendBuffer.Payload.reg = _Reg_Charging_Target;
+	sendBuffer.Payload.data[0] = result;
+
+	send(socket, &sendBuffer, sendBuffer.Header.len + 4, 0);
+}
+
+void PlugInStatusResponse(int socket, struct PACKET_STRUCTURE *packet, unsigned char result)
+{
+	struct PACKET_STRUCTURE sendBuffer;
+
+	memset(&sendBuffer, 0x00, sizeof(sendBuffer));
+	sendBuffer.Header.se = packet->Header.se;
+	sendBuffer.Header.id = packet->Header.id;
+	sendBuffer.Header.op = _Header_Response;
+	sendBuffer.Header.len = 2;
+	sendBuffer.Payload.reg = _Reg_Plug_In_Status;
+	sendBuffer.Payload.data[0] = result;
+
+	send(socket, &sendBuffer, sendBuffer.Header.len + 4, 0);
+}
+
+void ConnectorStateResponse(int socket, struct PACKET_STRUCTURE *packet, unsigned char result)
+{
+	struct PACKET_STRUCTURE sendBuffer;
+
+	memset(&sendBuffer, 0x00, sizeof(sendBuffer));
+	sendBuffer.Header.se = packet->Header.se;
+	sendBuffer.Header.id = packet->Header.id;
+	sendBuffer.Header.op = _Header_Response;
+	sendBuffer.Header.len = 2;
+	sendBuffer.Payload.reg = _Reg_Connector_State;
+	sendBuffer.Payload.data[0] = result;
+
+	send(socket, &sendBuffer, sendBuffer.Header.len + 4, 0);
+}
+
+void UserIDResponse(int socket, struct PACKET_STRUCTURE *packet, unsigned char result)
+{
+	struct PACKET_STRUCTURE sendBuffer;
+
+	memset(&sendBuffer, 0x00, sizeof(sendBuffer));
+	sendBuffer.Header.se = packet->Header.se;
+	sendBuffer.Header.id = packet->Header.id;
+	sendBuffer.Header.op = _Header_Response;
+	sendBuffer.Header.len = 3;
+	sendBuffer.Payload.reg = _Reg_User_ID;
+	sendBuffer.Payload.data[0] = result == _DAS_Wait ? _R_NG : _R_OK;
+	sendBuffer.Payload.data[1] = result == _DAS_Allowed ? _PS_Permitted : _PS_NotPermitted;
+
+	send(socket, &sendBuffer, sendBuffer.Header.len + 4, 0);
+}
+
+void ChargingPermissionResponse(int socket, struct PACKET_STRUCTURE *packet, unsigned char result)
+{
+	struct PACKET_STRUCTURE sendBuffer;
+
+	memset(&sendBuffer, 0x00, sizeof(sendBuffer));
+	sendBuffer.Header.se = packet->Header.se;
+	sendBuffer.Header.id = packet->Header.id;
+	sendBuffer.Header.op = _Header_Response;
+	sendBuffer.Header.len = 3;
+	sendBuffer.Payload.reg = _Reg_Charging_Permission;
+	sendBuffer.Payload.data[0] = result == _DAS_Wait ? _R_NG : _R_OK;
+	sendBuffer.Payload.data[1] = result == _DAS_Allowed ? _PS_Permitted : _PS_NotPermitted;
+
+	send(socket, &sendBuffer, sendBuffer.Header.len + 4, 0);
+}
+
+BOOL FindConnectorID(unsigned char dispenserIndex, unsigned char id)
+{
+	BOOL find = false;
+
+	for(int i = 0; i < ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].ConnectorQuantity; i++)
+	{
+		if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].ConnectorID[i] == id)
+		{
+			find = true;
+			break;
+		}
+	}
+
+	return find;
+}
+
+void ConnectorTypeBindingHandler(unsigned char dispenserIndex, unsigned char *type)
+{
+	for(int i = 0; i < ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].ConnectorQuantity; i++)
+	{
+		unsigned char gunIndex = ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].ConnectorID[i] - 1;
+		ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gunIndex].ParentDispensetIndex = dispenserIndex;
+		ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gunIndex].GeneralChargingData.Type = type[i];
+	}
+}
+
+BOOL IsAvailableDispenserIndexSequence(unsigned char index)
+{
+	if((ShmSysConfigAndInfo->SysInfo.DispenserInfo.CheckInLog.Status & (1 << index)) > 0)
+	{
+		// dispenser ever checkin
+		return true;
+	}
+	else
+	{
+		for(int i = 0; i < GENERAL_GUN_QUANTITY; i++)
+		{
+			if(i == index)
+			{
+				return true;
+			}
+
+			if((ShmSysConfigAndInfo->SysInfo.DispenserInfo.CheckInLog.Status & (1 << index)) == 0)
+			{
+				// i is not check in yet before index
+				return false;
+			}
+		}
+	}
+	return false;
+}
+
+void DispenserCheckInInfoUpdate(void)
+{
+	unsigned char dispenser = 0, connector = 0;
+	BOOL change = false;
+
+	for(int i = 0; i < GENERAL_GUN_QUANTITY; i++)
+	{
+		if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].LocalStatus != _DS_None &&
+			ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].LocalStatus != _DS_Timeout)
+		{
+			dispenser++;
+			ShmSysConfigAndInfo->SysInfo.DispenserInfo.CheckInLog.Status |= (1 << i);
+			ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectorLog[i] = ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].ConnectorQuantity;
+			connector += ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].ConnectorQuantity;
+		}
+	}
+
+	if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.DispenserQuantity != dispenser ||
+		ShmSysConfigAndInfo->SysInfo.DispenserInfo.TotalConnectorQuantity != connector)
+	{
+		change = true;
+	}
+	ShmSysConfigAndInfo->SysInfo.DispenserInfo.DispenserQuantity = dispenser;
+	ShmSysConfigAndInfo->SysInfo.DispenserInfo.TotalConnectorQuantity = connector;
+
+	if(change)
+	{
+		PRINTF_FUNC("Total Dispenser: %d, Total Connector: %d",
+			ShmSysConfigAndInfo->SysInfo.DispenserInfo.DispenserQuantity,
+			ShmSysConfigAndInfo->SysInfo.DispenserInfo.TotalConnectorQuantity);
+	}
+}
+
+void SetConnectorID(unsigned char dispenserIndex, unsigned char quantity)
+{
+	unsigned char currentQuantity = 0;
+
+	ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].ConnectorID[0] = 0x00;
+	ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].ConnectorID[1] = 0x00;
+
+	for(int i = 0; i < dispenserIndex; i++)
+	{
+		currentQuantity += ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectorLog[i];
+	}
+
+	for(int i = 0; i < quantity; i++)
+	{
+		currentQuantity++;
+		ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].ConnectorID[i] = currentQuantity;
+		ShmSysConfigAndInfo->SysInfo.ConnectorInfo[currentQuantity - 1].Enable = true;
+	}
+}
+
+BOOL DispenserIdentificationHandler(struct PACKET_STRUCTURE *packet, unsigned char dispenserIndex, unsigned char *modelName)
+{
+	unsigned char quantity = 0;
+
+	unsigned char connectorType[2] = {0, 0};
+
+	quantity = ConnectorQuantityTypeParsing(modelName, connectorType);
+
+	if(quantity > 0)
+	{
+		if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].LocalStatus == _DS_Timeout &&
+			quantity != ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectorLog[dispenserIndex])
+		{
+			PRINTF_FUNC("The same dispenser id (%d) but connector quantity not match", dispenserIndex + 1);
+			return false;
+		}
+		if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].LocalStatus == _DS_None ||
+			ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].LocalStatus == _DS_Timeout)
+		{
+			ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].LocalStatus = _DS_Identification;
+			ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].ConnectorQuantity = quantity;
+			ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectorLog[dispenserIndex] = quantity;
+			SetConnectorID(dispenserIndex, quantity);
+			memcpy(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].ModelName, packet->Payload.data, (packet->Header.len - 2));
+
+			ConnectorTypeBindingHandler(dispenserIndex, connectorType);
+
+			PRINTF_FUNC("Dispenser id %d identified, Connector: %d, ID: %d, %d", dispenserIndex + 1, quantity,
+				ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].ConnectorID[0],
+				ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].ConnectorID[1]);
+
+			DispenserCheckInInfoUpdate();
+
+			return true;
+		}
+		else
+		{
+			PRINTF_FUNC("Conflict dispenser ID: %d", dispenserIndex + 1);
+		}
+	}
+	else
+	{
+		PRINTF_FUNC("Connector quantity fail, model name: %s", modelName);
+	}
+	return false;
+}
+
+BOOL DispenserStatusCodeHandler(struct PACKET_STRUCTURE *packet, unsigned char dispenserIndex)
+{
+	BOOL find = FindConnectorID(dispenserIndex, packet->Header.id);
+
+	if(find)
+	{
+		ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].WarningInfo.WarningCount = (packet->Header.len - 1) / 6;
+		if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].WarningInfo.WarningCount > 10)
+		{
+			ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].WarningInfo.WarningCount = 10;
+		}
+
+		for(int i = 0; i < ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].WarningInfo.WarningCount; i++)
+		{
+			memcpy(&ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].WarningInfo.WarningCode[i][0],
+				&packet->Payload.data[i * 6], 6);
+		}
+
+		PRINTF_FUNC("Dispenser %d, Status Code Len: %d", packet->Header.id, ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].WarningInfo.WarningCount);
+	}
+	else
+	{
+
+	}
+
+	return find;
+}
+
+BOOL ConnectorChargingCapabilityHandler(struct PACKET_STRUCTURE *packet, unsigned char dispenserIndex)
+{
+    BOOL find = FindConnectorID(dispenserIndex, packet->Header.id);
+    BOOL done = false;
+
+    if(find)
+    {
+        done = true;
+    }
+
+    return done;
+}
+
+unsigned long GetTimeoutValue(struct timeval _sour_time)
+{
+    struct timeval _end_time;
+    gettimeofday(&_end_time, NULL);
+
+    return 1000000 * (_end_time.tv_sec - _sour_time.tv_sec) + _end_time.tv_usec - _sour_time.tv_usec;
+}
+
+struct timeval _ConnectorCapabilityTime[CONNECTOR_QUANTITY];
+
+BOOL ConnectorChargingTargetHandler(struct PACKET_STRUCTURE *packet, unsigned char dispenserIndex)
+{
+	BOOL find = FindConnectorID(dispenserIndex, packet->Header.id);
+	BOOL done = false;
+	float voltage = 0, current = 0;
+
+	if(find)
+	{
+		voltage = (float)((packet->Payload.data[0] << 8) + packet->Payload.data[1]) / 10;
+		current = (float)((packet->Payload.data[2] << 8) + packet->Payload.data[3]) / 10;
+
+//        if(GetTimeoutValue(_ConnectorCapabilityTime[packet->Header.id - 1]) / 1000 >= 2000)
+//        {
+//            gettimeofday(&_ConnectorCapabilityTime[packet->Header.id - 1], NULL);
+//            ShowSocketData(packet);
+//        }
+
+		if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].GeneralChargingData.SystemStatus == S_CHARGING)
+		{
+			if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].GeneralChargingData.EvBatterytargetVoltage != voltage ||
+				ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].GeneralChargingData.EvBatterytargetCurrent != current)
+			{
+				PRINTF_FUNC("Connector %d Target Voltage: %d, Current: %d", packet->Header.id, (int)(voltage * 10), (int)(current * 10));
+			}
+
+			ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].GeneralChargingData.EvBatterytargetVoltage = (float)voltage;
+			ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].GeneralChargingData.EvBatterytargetCurrent = (float)current;
+
+			done = true;
+		}
+		else
+		{
+			if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].GeneralChargingData.EvBatterytargetVoltage != 0 ||
+				ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].GeneralChargingData.EvBatterytargetCurrent != 0)
+			{
+				PRINTF_FUNC("Connector %d Not Charging Status, Set Voltage & Current Fail", packet->Header.id);
+			}
+			ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].GeneralChargingData.EvBatterytargetVoltage = 0;
+			ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].GeneralChargingData.EvBatterytargetCurrent = 0;
+		}
+	}
+	else
+	{
+
+	}
+
+	return done;
+}
+
+BOOL ConnectorPlugInHandler(struct PACKET_STRUCTURE *packet, unsigned char dispenserIndex)
+{
+	BOOL find = FindConnectorID(dispenserIndex, packet->Header.id);
+
+	if(find)
+	{
+		if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].GeneralChargingData.ConnectorPlugIn != packet->Payload.data[0])
+		{
+			PRINTF_FUNC("Connector %d %s", packet->Header.id, packet->Payload.data[0] == _PIS_PluggedIn ? "Pluged In" : "Un Plugged");
+		}
+		ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].GeneralChargingData.ConnectorPlugIn = packet->Payload.data[0];
+	}
+	else
+	{
+
+	}
+
+	return find;
+}
+
+BOOL ConnectorStateHandler(struct PACKET_STRUCTURE *packet, unsigned char dispenserIndex)
+{
+	BOOL find = FindConnectorID(dispenserIndex, packet->Header.id);
+
+	if(find)
+	{
+		if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].RemoteStatus != packet->Payload.data[0])
+		{
+			PRINTF_FUNC("Connector %d Remote Status: %d", packet->Header.id, packet->Payload.data[0]);
+
+			if((packet->Payload.data[0] == _CRS_Idle && ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].RemoteStatus != _CRS_Terminating) ||
+				packet->Payload.data[0] == _CRS_Terminating)
+			{
+			    PRINTF_FUNC("*********** Connector id %d Set Stop Flag ***********\n", packet->Header.id);
+				ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].GeneralChargingData.StopChargeFlag = true;
+			}
+		}
+		ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].RemoteStatus = packet->Payload.data[0];
+	}
+	else
+	{
+
+	}
+
+	return true;
+}
+
+unsigned char UserIDHandler(struct PACKET_STRUCTURE *packet, unsigned char dispenserIndex)
+{
+	DispenserAck_Status authorize = _DAS_Wait;
+
+	if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].AuthorizeStatus == _AuthorizeStatus_Idle)
+	{
+	    if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].Setting.bits.AuthorizeRequest)
+	    {
+	        ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].Setting.bits.AuthorizeRequest = false;
+	    }
+	    memset(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].UserId, 0x00, 32);
+	    memcpy(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].UserId, packet->Payload.data, packet->Header.len - 1);
+
+	    PRINTF_FUNC("Dispenser id %d user id %s need authorize", dispenserIndex + 1, ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].UserId);
+        ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].Setting.bits.AuthorizeRequest = true;
+        authorize = _DAS_Wait;
+	}
+	else if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].AuthorizeStatus == _AuthorizeStatus_Fail)
+	{
+	    PRINTF_FUNC("Dispenser id %d user id %s authorizing fail", dispenserIndex + 1, ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].UserId);
+	    authorize = _DAS_NotAllowed;
+	}
+	else if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].AuthorizeStatus == _AuthorizeStatus_Pass)
+	{
+	    PRINTF_FUNC("Dispenser id %d user id %s authorizing ok", dispenserIndex + 1, ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].UserId);
+	    authorize = _DAS_Allowed;
+	}
+	else
+	{
+	    authorize = _DAS_Wait;
+	}
+
+	return authorize;
+}
+
+unsigned char ChargingPermissionHandler(struct PACKET_STRUCTURE *packet, unsigned char dispenserIndex)
+{
+	BOOL find = FindConnectorID(dispenserIndex, packet->Header.id);
+	DispenserAck_Status permission = _DAS_Wait;
+
+	if(find)
+	{
+	    switch(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].GeneralChargingData.SystemStatus)
+	    {
+            case S_PREPARING_FOR_EV:
+                if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].RemoteStatus >= _CRS_Preparing &&
+                    ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].RemoteStatus <= _CRS_Charging)
+                {
+                    if(!ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].ReadyToCharge)
+                    {
+                        ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].ReadyToCharge = true;
+                        PRINTF_FUNC("Allow dispenser index %d connector id %d start to charge", dispenserIndex, packet->Header.id);
+                    }
+                    permission = _DAS_Allowed;
+                }
+                else if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].RemoteStatus == _CRS_Terminating)
+                {
+                    permission = _DAS_NotAllowed;
+                    PRINTF_FUNC("Allow dispenser index %d connector id %d start to charge", dispenserIndex, packet->Header.id);
+                }
+                else
+                {
+                    // keep wait
+                }
+                break;
+            case S_CHARGING:
+                if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].RemoteStatus == _CRS_Preparing ||
+                    ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].RemoteStatus == _CRS_Charging)
+                {
+                    permission = _DAS_Allowed;
+                }
+                else
+                {
+                    permission = _DAS_NotAllowed;
+                    PRINTF_FUNC("Dispenser index %d connector id %d remote status not in charging mode", dispenserIndex, packet->Header.id);
+                }
+                break;
+            default:
+                break;
+	    }
+	}
+	else
+	{
+	    PRINTF_FUNC("Dispenser index %d Connector id %d not found", dispenserIndex, packet->Header.id);
+	    permission = _DAS_NotAllowed;
+	}
+
+//	PRINTF_FUNC("Dispenser %d Permission %s, Gun Status: %d, Connector Status: %d, Wait Plug: %d, PlugIn: %d, Available: %d, Order: %d", dispenserIndex, permission == true ? "OK" : "NG",
+//		ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].GeneralChargingData.SystemStatus,
+//		ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].RemoteStatus,
+//		ShmSysConfigAndInfo->SysInfo.WaitForPlugit,
+//		ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].GeneralChargingData.ConnectorPlugIn,
+//		ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].GeneralChargingData.IsAvailable,
+//		ShmSysConfigAndInfo->SysInfo.OrderCharging);
+
+	return permission;
+}
+
+void DisableConnector(unsigned char dispenserIndex)
+{
+	for(int i = 0; i < ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].ConnectorQuantity; i++)
+	{
+		unsigned char connector = ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].ConnectorID[i] - 1;
+		ShmSysConfigAndInfo->SysInfo.ConnectorInfo[connector].Enable = false;
+	}
+}
+
+void DispenserSocketProcess(int socketFd, struct sockaddr_in clientInfo, unsigned char index)
+{
+	int rxLen = 0, timeout = 0;
+	unsigned char dispenserID = 0, dispenserIndex = 0;
+	struct PACKET_STRUCTURE receiveBuffer;
+	unsigned char modelName[64];
+	unsigned char ackResult = _R_NG;
+	DispenserAck_Status ack = _DAS_Wait;
+
+	PRINTF_FUNC("IP %s connection(%d) is established, start dispenser process", (inet_ntoa(clientInfo.sin_addr)), index);
+
+	for(int i = 0; i < CONNECTOR_QUANTITY; i++)
+	{
+	    memset(&_ConnectorCapabilityTime[i], 0x00, sizeof(struct timeval));
+	}
+
+	while(1)
+	{
+		if((rxLen = recv(socketFd, &receiveBuffer, sizeof(Packet_Structure), MSG_DONTWAIT )) > 0)
+		{
+			if(rxLen == (receiveBuffer.Header.len + PACKET_HEADER_LENGTH))
+			{
+				ackResult = _R_NG;
+				//ShowSocketData(&receiveBuffer);
+
+				if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[index].Status == _CNS_WaitModelName)
+				{
+				    // Reg: 0x01, Dispenser model name
+					if(receiveBuffer.Header.op == _Header_Write && receiveBuffer.Payload.reg == _Reg_Dispenser_Model_Name)
+					{
+						memset(modelName, 0x00, 64);
+						dispenserID = receiveBuffer.Payload.data[receiveBuffer.Header.len - 2];
+
+						if(dispenserID > 0 && dispenserID <= GENERAL_GUN_QUANTITY)
+						{
+						    dispenserIndex = dispenserID - 1;
+						    memcpy(modelName, receiveBuffer.Payload.data, receiveBuffer.Header.len - 2);
+
+	                        if(IsAvailableDispenserIndexSequence(dispenserIndex))
+	                        {
+	                            if(DispenserIdentificationHandler(&receiveBuffer, dispenserIndex, modelName) == true)
+	                            {
+	                                ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[index].DispenserIndex = dispenserIndex;
+	                                ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[index].Status = _CNS_DispenserMatched;
+	                                PRINTF_FUNC("Dispenser id %d check in, model name: %s", dispenserID, modelName);
+	                                ackResult = _R_OK;
+	                            }
+	                            else
+	                            {
+	                                // response NG: gun quantity fail
+	                                PRINTF_FUNC("Dispenser ID %d Identification Fail", dispenserID);
+	                            }
+	                        }
+	                        else
+	                        {
+	                            // response NG: dispenser Index fail
+	                            PRINTF_FUNC("Dispenser ID %d Fail, Need Wait Another Dispenser", dispenserID);
+	                        }
+						}
+						else
+						{
+						    PRINTF_FUNC("Dispenser ID: %d Over Range", dispenserID);
+						}
+
+						ModelNameResponse(socketFd, &receiveBuffer, ackResult);
+					}
+					else
+					{
+						// do nothing
+					}
+				}
+				else if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[index].Status == _CNS_DispenserMatched)
+				{
+				    // Reg: 0x01, Dispenser model name
+					if(receiveBuffer.Header.op == _Header_Write && receiveBuffer.Payload.reg == _Reg_Dispenser_Model_Name)
+					{
+						ackResult = _R_OK;
+						ModelNameResponse(socketFd, &receiveBuffer, ackResult);
+					}
+
+					// Reg: 0x02, Connector ID
+					if(receiveBuffer.Header.op == _Header_Read && receiveBuffer.Payload.reg == _Reg_Connector_ID)
+					{
+						if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].ConnectorQuantity > 0)
+						{
+							ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].LocalStatus = _DS_Idle;
+							ackResult = _R_OK;
+						}
+						PRINTF_FUNC("Dispenser %d Get Connector ID %s", dispenserIndex, ackResult == _R_OK ? "OK" : "NG");
+						ConnectorIDResponse(socketFd, &receiveBuffer, ackResult, dispenserIndex);
+					}
+
+					// Reg: 0x03, Power cabinet status
+					if(receiveBuffer.Header.op == _Header_Read && receiveBuffer.Payload.reg == _Reg_Power_Cabinet_Status)
+					{
+						PowerCabinetStatusResponse(socketFd, &receiveBuffer);
+					}
+
+					// Reg: 0x04, Dispenser status
+					if(receiveBuffer.Header.op == _Header_Write && receiveBuffer.Payload.reg == _Reg_Dispenser_Status)
+					{
+						if(DispenserStatusCodeHandler(&receiveBuffer, dispenserIndex))
+						{
+							ackResult = _R_OK;
+						}
+						DispenserStatusResponse(socketFd, &receiveBuffer, ackResult);
+					}
+
+					// Reg: 0x05, Charging capability
+					if(receiveBuffer.Header.op == _Header_Read && receiveBuffer.Payload.reg == _Reg_Charging_Capability)
+					{
+					    if(ConnectorChargingCapabilityHandler(&receiveBuffer, dispenserIndex))
+					    {
+					        ChargingCapabilityResponse(socketFd, &receiveBuffer);
+					    }
+					}
+
+					// Reg: 0x06, Charging target
+					if(receiveBuffer.Header.op == _Header_Write && receiveBuffer.Payload.reg == _Reg_Charging_Target)
+					{
+						if(receiveBuffer.Header.len == 5)
+						{
+							if(ConnectorChargingTargetHandler(&receiveBuffer, dispenserIndex))
+							{
+								ackResult = _R_OK;
+							}
+						}
+						ChargingTargetResponse(socketFd, &receiveBuffer, ackResult);
+					}
+
+					// Reg: 0x07, Software update
+
+					// Reg: 0x08, Plug-in status
+					if(receiveBuffer.Header.op == _Header_Write && receiveBuffer.Payload.reg == _Reg_Plug_In_Status)
+					{
+						if(receiveBuffer.Header.len == 2)
+						{
+							if(ConnectorPlugInHandler(&receiveBuffer, dispenserIndex))
+							{
+								ackResult = _R_OK;
+							}
+						}
+						PlugInStatusResponse(socketFd, &receiveBuffer, ackResult);
+					}
+
+					// Reg: 0x09, Connector state
+					if(receiveBuffer.Header.op == _Header_Write && receiveBuffer.Payload.reg == _Reg_Connector_State)
+					{
+						if(ConnectorStateHandler(&receiveBuffer, dispenserIndex))
+						{
+							ackResult = _R_OK;
+						}
+						ConnectorStateResponse(socketFd, &receiveBuffer, ackResult);
+					}
+
+					// Reg: 0x0A, User ID
+					if(receiveBuffer.Header.op == _Header_Write && receiveBuffer.Payload.reg == _Reg_User_ID)
+					{
+					    ack = UserIDHandler(&receiveBuffer, dispenserIndex);
+
+						UserIDResponse(socketFd, &receiveBuffer, ack);
+					}
+
+					// Reg: 0x0B, Charging permission
+					if(receiveBuffer.Header.op == _Header_Read && receiveBuffer.Payload.reg == _Reg_Charging_Permission)
+					{
+					    ack = ChargingPermissionHandler(&receiveBuffer, dispenserIndex);
+
+						ChargingPermissionResponse(socketFd, &receiveBuffer, ack);
+					}
+				}
+
+				// clean timeout
+				timeout = 0;
+			}
+		}
+		else
+		{
+			timeout += SOCKET_RECEIVE_INTERVAL;
+			usleep((SOCKET_RECEIVE_INTERVAL * 1000));
+		}
+
+		if(timeout >= DISPENSER_SOCKET_TIMEOUT)
+		{
+			//timeout
+			PRINTF_FUNC("IP: %s, Socket %d connection timeout", (inet_ntoa(clientInfo.sin_addr)), index);
+			if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[index].Status == _CNS_DispenserMatched)
+			{
+				DisableConnector(dispenserIndex);
+
+				memset(&ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex], 0x00, sizeof(struct DispenserModule));
+				ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].LocalStatus = _DS_Timeout;
+
+				DispenserCheckInInfoUpdate();
+			}
+			break;
+		}
+	}
+}
+
+
+int GetMacAddress(int sockFd, unsigned char *mac)
+{
+	struct arpreq arpReq;
+	struct sockaddr_in clientInfo;
+	socklen_t len = sizeof(struct sockaddr_in);
+
+	memset(mac, 0x00, 6);
+
+	if(getpeername(sockFd, (struct sockaddr*)&clientInfo, &len) < 0)
+	{
+		return 0;
+	}
+    else
+	{
+		memcpy(&arpReq.arp_pa, &clientInfo, sizeof(struct sockaddr_in));
+		strcpy(arpReq.arp_dev, "eth1");
+		arpReq.arp_pa.sa_family = AF_INET;
+		arpReq.arp_ha.sa_family = AF_UNSPEC;
+		if(ioctl(sockFd, SIOCGARP, &arpReq) < 0)
+		{
+			return 0;
+		}
+		else
+		{
+			memcpy(mac, arpReq.arp_ha.sa_data, 6);
+		}
+	}
+
+	return 1;
+}
+
+int FindFreeChannel(void)
+{
+	for(int i = 0; i < MAXIMUM_CONNECT_QUANTITY; i++)
+	{
+		if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[i].Status == _CNS_FREE)
+		{
+			return i;
+		}
+	}
+	return FAIL;
+}
+
+BOOL IsConflictIp(uint32_t ipAddress)
+{
+	for(int i = 0; i < MAXIMUM_CONNECT_QUANTITY; i++)
+	{
+		if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[i].IpAddress == ipAddress)
+		{
+			return true;
+		}
+	}
+	return false;
+}
+
+void InitDispenserInfo(void)
+{
+	for(int i = 0; i < GENERAL_GUN_QUANTITY; i++)
+	{
+		memset(&ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i], 0x00, sizeof(struct ConnectorInfoData));
+	}
+	memset(&ShmSysConfigAndInfo->SysInfo.DispenserInfo, 0x00, sizeof(struct DispenserInfoData));
+}
+
+void tcpSocketServerStart(void)
+{
+	int sockFd = 0;
+	int clientSockFd = 0;
+	int connectIndex = 0;
+	pid_t forkId;
+
+	struct sockaddr_in 	serverInfo, clientInfo;
+	socklen_t 			addrlen = sizeof(clientInfo);
+	//struct timeval      timeout = {3, 0};
+
+	sockFd = socket(AF_INET, SOCK_STREAM, 0);
+	if(sockFd == -1)
+	{
+		PRINTF_FUNC("InitSocketServer NG\n");
+		sleep(5);
+		return;
+	}
+
+	InitDispenserInfo();
+
+	bzero(&serverInfo,sizeof(serverInfo));
+	serverInfo.sin_family = PF_INET;
+	serverInfo.sin_addr.s_addr = htonl(INADDR_ANY);
+	serverInfo.sin_port = htons(TCP_LISTEN_PORT);
+	bind(sockFd, (struct sockaddr *)&serverInfo, sizeof(serverInfo));
+	listen(sockFd, CONNECTION_LIMIT);
+
+	PRINTF_FUNC("TCP Server Start\n");
+
+	signal(SIGCHLD, SIG_IGN);
+	// Main loop
+	while(1)
+	{
+		clientSockFd = accept(sockFd, (struct sockaddr*) &clientInfo, &addrlen);
+		PRINTF_FUNC("Client ip: %s is accepted at port: %d", inet_ntoa(clientInfo.sin_addr), clientInfo.sin_port);
+
+		connectIndex = FindFreeChannel();
+		if(connectIndex >= 0)
+		{
+			if(IsConflictIp(clientInfo.sin_addr.s_addr) == false)
+			{
+				ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[connectIndex].Status = _CNS_WaitModelName;
+				ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[connectIndex].IpAddress = clientInfo.sin_addr.s_addr;
+
+				forkId = fork();
+				if(forkId == 0)
+				{
+					// child process
+					DispenserSocketProcess(clientSockFd, clientInfo, connectIndex);
+					close(clientSockFd);
+					memset(&ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[connectIndex], 0x00, sizeof(struct ConnectionInfoData));
+					return;
+				}
+				else if(forkId == -1)
+				{
+					PRINTF_FUNC("fork fail");
+				}
+			}
+			else
+			{
+				// conflict ip address
+				PRINTF_FUNC("Conflict IP address, close socket");
+				close(clientSockFd);
+			}
+		}
+		else
+		{
+			// no free channel
+			PRINTF_FUNC("No free channel, close socket");
+			close(clientSockFd);
+		}
+		usleep(10000);
+	}
+
+	return;
+}
+
+int main(void)
+{
+	if(InitShareMemory() == FAIL)
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR("InitShareMemory NG\n");
+		#endif
+
+		sleep(5);
+		return 0;
+	}
+
+	// wait for self test completed
+	while(ShmSysConfigAndInfo->SysInfo.BootingStatus == BOOTTING);
+
+	tcpSocketServerStart();
+
+	//tcpSocketClientStart();
+
+	return 0;
+}
+

+ 121 - 67
EVSE/Projects/DO360/Apps/Module_EvComm.h

@@ -1,79 +1,133 @@
+/*
+ * Module_EvComm.h
+ *
+ *  Created on: 2020嚙羯9嚙踝蕭14嚙踝蕭
+ *      Author: Wendell
+ */
+
 #ifndef MODULE_EVCOMM_H_
 #define MODULE_EVCOMM_H_
 
-#include 	<stdbool.h>
+// server protocol setting
+#define SOCKET_SERVER_IP				"192.168.0.10"
+#define PACKET_HEADER_LENGTH			4
+#define MAXIMUM_PAYLOAD_LENGTH			249			// 249 bytes
+#define TCP_LISTEN_PORT					36000
+#define SOCKET_RECEIVE_INTERVAL			10			// 10ms
+#define DISPENSER_SOCKET_TIMEOUT		10000		// 10s
 
-int CanFd;
+// client protocol setting
+#define DISPENSER_MODEL_NAME_RESEND		3000		// 3s
+#define DISPENSER_CONNECTOR_RESEND		3000		// 3s
+#define CABINET_STATUS_REQUEST_RESEND	1000		// 1s
+#define CHARGING_CAPABILITY_RESEND		1000		// 1s
 
-typedef unsigned char 		byte;
+// socket setting
+#define	CONNECTION_LIMIT				5
+#define MAXIMUM_CONNECT_QUANTITY		2
 
-extern struct Ev_Board_Cmd
+struct Message
 {
-	int none;							// 0
-	int address_assignment;				// 0x00000200
-	int get_firmware_ver;				// 0x00000400
-	int get_hardware_ver;				// 0x00000500
-	int charging_permission;			// 0x00000600
-	int present_output_power;			// 0x00000700
-	int present_output_cap;				// 0x00000800
-	int get_output_req;					// 0x00000900
-	int get_battery_info;				// 0x00000A00
-	int evse_stop_charging;				// 0x00000C00
-	int get_miscellaneous_info;			// 0x00000D00
-
-	int download_req;					// 0x00000E00
-	int start_block_transfer;			// 0x00000F00
-	int data_transfer;					// 0x00001000
-	int download_finish;				// 0x00001100
-
-	int isolation_status;				// 0x00001200
-	int sync_rtc_info;					// 0x00001400
-	int evse_precharge_info;			// 0x00001500
-}Ev_Cmd;
-
-extern struct Ev_Cmd_Dir
+	int				size;
+	unsigned char 	buffer[2048];
+};
+
+enum HEADER_OP
+{
+	_Header_Read		= 0x01,
+	_Header_Write		= 0x02,
+	_Header_Response	= 0x03,
+};
+
+enum PAYLOAD_REGISTER
 {
-	unsigned short master_to_slave;
-	unsigned short slave_to_master;
-}Ev_Dir;
-
-struct timeval _id_assign_time;
-
-// Send msg to can-bus
-void SetTargetAddr(byte *target_number, byte index);
-
-void GetFirmwareVersion(byte gun_index, byte toId);
-void SyncRtcInfo(byte gun_index, byte toId, int epoch);
-void GetHardwareVersion(byte gun_index, byte toId);
-void SetChargingPermission(byte gun_index, byte permissionStatus, short aOutputPw, short aOutputVol, short aOutputCur, byte toId);
-void SetPresentOutputPower(short outputVol_b1, short outputCur_b1, short outputVol_b2, short outputCur_b2);
-void SetPresentOutputCapacity(short aOutputPw_b1, short aOutputCur_b1, short aOutputPw_b2, short aOutputCur_b2);
-void GetOutputReq(byte gun_index, byte toId);
-void GetEvBatteryInfo(byte gun_index, byte toId);
-void GetMiscellaneousInfo(byte gun_index, byte relayStatus, float power, float voltage, byte toId);
-void SetIsolationStatus(byte gun_index, byte result, byte toId);
-void SetEvsePrechargeInfo(byte gun_index, byte result, byte toId);
-// 發送電樁主動停止充電結果及原因
-void EvseStopChargingEvent(byte stopResult, byte *stopReason, byte toId);
-
-// Receive msg From can-bus.
-
-enum Receieve_PSU_msgf
+	_Reg_Dispenser_Model_Name		= 0x01,
+	_Reg_Connector_ID				= 0x02,
+	_Reg_Power_Cabinet_Status		= 0x03,
+	_Reg_Dispenser_Status			= 0x04,
+	_Reg_Charging_Capability		= 0x05,
+	_Reg_Charging_Target			= 0x06,
+	_Reg_Software_Update			= 0x07,
+	_Reg_Plug_In_Status				= 0x08,
+	_Reg_Connector_State			= 0x09,
+	_Reg_User_ID					= 0x0A,
+	_Reg_Charging_Permission		= 0x0B,
+};
+
+enum Response_Result
 {
-	// 車端主動
-	ADDRESS_REQ = 						0x080001FF,
-	NOTIFICATION_EV_STATUS = 			0x08000300,
-	NOTIFICATION_EV_STOP = 				0x08000B00,
-
-	// 車端回應
-	ACK_EV_FW_VERSION = 				0x08000400,
-	ACK_EV_HW_VERSION = 				0x08000500,
-	ACK_GET_OUTPUT_REQ =				0x08000900,
-	ACK_GET_EV_BATTERY_INFO =			0x08000A00,
-	ACK_GET_MISCELLANEOUS_INFO = 		0x08000D00,
-	ACK_EVSE_ISOLATION_STATUS = 		0x08001200,
-	ACK_EVSE_PRECHAGE_INFO = 			0x08001500,
+	_R_OK	= 0x01,
+	_R_NG	= 0x02,
 };
 
-#endif /* MODULE_EVCOMM_H_ */
+enum PlugIn_Status
+{
+	_PIS_UnPlugged	= 0x00,
+	_PIS_PluggedIn	= 0x01,
+};
+
+enum Connector_Remote_Status
+{
+	_CRS_Idle			= 0x00,
+	_CRS_Preparing		= 0x01,
+	_CRS_Charging		= 0x02,
+	_CRS_Terminating	= 0x03,
+};
+
+typedef enum
+{
+    _DAS_NotAllowed     = 0x00,
+    _DAS_Allowed        = 0x01,
+    _DAS_Wait           = 0x02,
+}DispenserAck_Status;
+
+enum Permission_Status
+{
+	_PS_NotPermitted	= 0x00,
+	_PS_Permitted		= 0x01,
+};
 
+enum Accept_Status
+{
+	_AS_Reject			= 0x00,
+	_AS_Accept			= 0x01,
+};
+
+struct HEADER_STRUCTURE
+{
+	unsigned char se;
+	unsigned char id;
+	unsigned char op;
+	unsigned char len;
+};
+
+struct PAYLOAD_STRUCTURE
+{
+	unsigned char reg;
+	unsigned char data[MAXIMUM_PAYLOAD_LENGTH];
+};
+
+struct PACKET_STRUCTURE
+{
+	struct HEADER_STRUCTURE  Header;
+	struct PAYLOAD_STRUCTURE Payload;
+}Packet_Structure;
+
+enum DispenserStatus
+{
+	_DS_None					= 0x00,
+	_DS_Identification			= 0x01,
+	_DS_Idle					= 0x02,
+	_DS_Alarm					= 0x03,
+	_DS_Charging				= 0x04,
+	_DS_Timeout					= 0x05,
+};
+
+enum ConnectionStatus
+{
+	_CNS_FREE					= 0x00,
+	_CNS_WaitModelName			= 0x01,
+	_CNS_DispenserMatched		= 0x02,
+};
+
+#endif /* MODULE_EVCOMM_H_ */

تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 446 - 302
EVSE/Projects/DO360/Apps/Module_InternalComm.c


+ 98 - 50
EVSE/Projects/DO360/Apps/Module_PrimaryComm.c

@@ -15,12 +15,12 @@
 
 #include 	<unistd.h>
 #include 	<stdarg.h>
-#include    <stdio.h>      /*標準輸入輸出定義*/
-#include    <stdlib.h>     /*標準函數庫定義*/
-#include    <unistd.h>     /*Unix 標準函數定義*/
-#include    <fcntl.h>      /*檔控制定義*/
-#include    <termios.h>    /*PPSIX 終端控制定義*/
-#include    <errno.h>      /*錯誤號定義*/
+#include    <stdio.h>      /*璅蹱�頛詨�頛詨枂摰𡁶儔*/
+#include    <stdlib.h>     /*璅蹱��賣彍摨怠�蝢�*/
+#include    <unistd.h>     /*Unix 璅蹱��賣彍摰𡁶儔*/
+#include    <fcntl.h>      /*瑼娍綉�嗅�蝢�*/
+#include    <termios.h>    /*PPSIX 蝯�垢�批�摰𡁶儔*/
+#include    <errno.h>      /*�航炊�笔�蝢�*/
 #include 	<errno.h>
 #include 	<string.h>
 #include	<time.h>
@@ -55,7 +55,10 @@ Gpio_in gpio_in;
 Rtc rtc;
 
 struct timeval _flash_time;
-byte flash = NO;
+byte _OutputDrv = 0;
+
+byte _acStatus = 0;
+byte _acChkCount = 0;
 
 void PRINTF_FUNC(char *string, ...);
 
@@ -266,10 +269,37 @@ void GetInputGpioStatus()
 	//PRINTF_FUNC("GetInputGpioStatus \n");
 	if (Query_Gpio_Input(Uart1Fd, Addr.IoExtend, &gpio_in) == PASS)
 	{
-		ShmSysConfigAndInfo->SysInfo.AcContactorStatus = ShmPrimaryMcuData->InputDet.bits.AcContactorDetec = gpio_in.AC_Connector;
+		if (_acStatus != gpio_in.AC_Connector)
+		{
+			if (_acChkCount >= 3)
+			{
+				_acStatus = gpio_in.AC_Connector;
+
+				// DO360 AC_Connector Status is the inverse of DS's
+				if(gpio_in.AC_Connector)
+				{
+					ShmSysConfigAndInfo->SysInfo.AcContactorStatus = 0;
+					ShmPrimaryMcuData->InputDet.bits.AcContactorDetec = 0;
+				}
+				else
+				{
+					ShmSysConfigAndInfo->SysInfo.AcContactorStatus = 1;
+					ShmPrimaryMcuData->InputDet.bits.AcContactorDetec = 1;
+				}
+			}
+			else
+				_acChkCount++;
+		}
+		else
+			_acChkCount = 0;
+
 		ShmPrimaryMcuData->InputDet.bits.AcMainBreakerDetec = gpio_in.AC_MainBreaker;
 		ShmPrimaryMcuData->InputDet.bits.SpdDetec = gpio_in.SPD;
-		ShmPrimaryMcuData->InputDet.bits.DoorOpen = gpio_in.Door_Open;
+
+		// DO360 Door Status is the inverse of DS's
+		//ShmPrimaryMcuData->InputDet.bits.DoorOpen = gpio_in.Door_Open > 0 ? 0 : 1;
+		// Bypass door open
+		ShmPrimaryMcuData->InputDet.bits.DoorOpen = 0;
 
 		ShmPrimaryMcuData->InputDet.bits.Button1 = gpio_in.Button[0];
 		ShmPrimaryMcuData->InputDet.bits.Button2 = gpio_in.Button[1];
@@ -286,24 +316,26 @@ void GetInputGpioStatus()
 void SetOutputGpio(byte flash)
 {
 	Gpio_out gpio;
-	gpio.Button_LED[0] = flash;
-	gpio.Button_LED[1] = flash;
-
-	gpio.System_LED[0] = 0x00;
-	gpio.System_LED[1] = 0x00;
-	gpio.System_LED[2] = 0x00;
-	gpio.System_LED[3] = 0x00;
 
-	gpio.AC_Connector = 0x00;
-	gpio.AC_Breaker = 0x00;
-
-	if (Config_Gpio_Output(Uart1Fd, Addr.IoExtend, &gpio) == PASS)
+	if(_OutputDrv != flash)
 	{
-		//PRINTF_FUNC("SetOutputGpio sucessfully. %d \n", flash);
+        gpio.Button_LED[0] = (flash & 0x01) > 0 ? 1 : 0;
+        gpio.Button_LED[1] = (flash & 0x02) > 0 ? 1 : 0;
+        gpio.System_LED[0] = (flash & 0x04) > 0 ? 1 : 0;
+        gpio.System_LED[1] = (flash & 0x08) > 0 ? 1 : 0;
+        gpio.System_LED[2] = (flash & 0x10) > 0 ? 1 : 0;
+        gpio.System_LED[3] = (flash & 0x20) > 0 ? 1 : 0;
+        gpio.AC_Connector  = (flash & 0x40) > 0 ? 1 : 0;
+        gpio.AC_Breaker    = (flash & 0x80) > 0 ? 1 : 0;
+
+        if (Config_Gpio_Output(Uart1Fd, Addr.IoExtend, &gpio) == PASS)
+        {
+            _OutputDrv = flash;
+        }
 	}
 	else
 	{
-		//PRINTF_FUNC("SetOutputGpio fail. \n");
+	    // do nothing when no change
 	}
 }
 
@@ -419,44 +451,60 @@ int main(void)
 
 	SetRtcData();
 	gettimeofday(&_flash_time, NULL);
-	for(;;)
-	{
-		if (strcmp((char *)ShmSysConfigAndInfo->SysInfo.LcmHwRev, " ") == 0x00)
-		{
-			if ((GetTimeoutValue(_flash_time) / 1000) > 1000)
-			{
-				if (flash == NO)
-					flash = YES;
-				else
-					flash = NO;
-				SetOutputGpio(flash);
-				gettimeofday(&_flash_time, NULL);
-			}
-		}
-		else
-		{
-			if ((GetTimeoutValue(_flash_time) / 1000) > 5000)
-			{
-				if (flash == NO)
-					flash = YES;
 
-				SetOutputGpio(flash);
-				gettimeofday(&_flash_time, NULL);
-			}
-		}
+	// update ac contact status
+	//_acStatus = ShmSysConfigAndInfo->SysInfo.AcContactorStatus;
+	_acStatus = ShmSysConfigAndInfo->SysInfo.AcContactorStatus > 0 ? 0 : 1;
+
+	// set wrong value, it will update at the first time
+	_OutputDrv = ~ShmPrimaryMcuData->OutputDrv.OutputDrvValue[0];
 
-		// 程序開始之前~ 必須先確定 FW 版本與硬體版本,確認後!!~ 該模組才算是真正的 Initial Comp.
-		// 模組更新 FW 後,需重新做
+	for(;;)
+	{
+//		if (strcmp((char *)ShmSysConfigAndInfo->SysInfo.LcmHwRev, " ") == 0x00)
+//		{
+//			if ((GetTimeoutValue(_flash_time) / 1000) > 1000)
+//			{
+//				if (flash == NO)
+//					flash = YES;
+//				else
+//					flash = NO;
+//				SetOutputGpio(flash);
+//				gettimeofday(&_flash_time, NULL);
+//			}
+//		}
+//		else
+//		{
+//			if ((GetTimeoutValue(_flash_time) / 1000) > 5000)
+//			{
+//				if (flash == NO)
+//					flash = YES;
+
+//				SetOutputGpio(flash);
+//				gettimeofday(&_flash_time, NULL);
+//			}
+//		}
+
+		// 蝔见��见�銋见�~ 敹����Ⅱ摰� FW ��𧋦��′擃𠉛��穿�蝣箄�敺�!!~ 閰脫芋蝯��蝞埈糓��迤�� Initial Comp.
+		// 璅∠��湔鰵 FW 敺䕘����齿鰵��
 		if(ShmPrimaryMcuData->SelfTest_Comp != PASS)
 		{
-			PRINTF_FUNC("(407) Get Fw and Hw Ver. \n");
+		    memset(ShmPrimaryMcuData->version, 0x00, 16);
+
 			GetFwAndHwVersion();
 			sleep(1);
-			ShmPrimaryMcuData->SelfTest_Comp = PASS;
+
+            if(strlen((char *)ShmPrimaryMcuData->version) != 0)
+            {
+                ShmPrimaryMcuData->SelfTest_Comp = YES;
+            }
 		}
 		else
 		{
 			GetInputGpioStatus();
+			//PRINTF_FUNC("Input Status: %02X %02X", ShmPrimaryMcuData->InputDet.InputDetValue[1], ShmPrimaryMcuData->InputDet.InputDetValue[0]);
+
+			SetOutputGpio(ShmPrimaryMcuData->OutputDrv.OutputDrvValue[0]);
 		}
 
 		usleep(100000);

تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 473 - 203
EVSE/Projects/DO360/Apps/Module_PsuComm.c


+ 19 - 9
EVSE/Projects/DO360/Apps/Module_PsuComm.h

@@ -17,12 +17,12 @@
 
 #include 	<unistd.h>
 #include 	<stdarg.h>
-#include   <stdio.h>      /*シミキヌソ鬢Jソ鬣Xゥwクq*/
-#include   <stdlib.h>     /*シミキヌィ郛ニョwゥwクq*/
-#include   <unistd.h>     /*Unix シミキヌィ郛ニゥwクq*/
-#include   <fcntl.h>      /*タノアアィ鉀wクq*/
-#include   <termios.h>    /*PPSIX イラコンアアィ鉀wクq*/
-#include   <errno.h>      /*ソ�~クケゥwクq*/
+#include   <stdio.h>      /*讓呎コ冶シク蜈・霈ク蜃コ螳夂セゥ*/
+#include   <stdlib.h>     /*讓呎コ門�謨ク蠎ォ螳夂セゥ*/
+#include   <unistd.h>     /*Unix 讓呎コ門�謨ク螳夂セゥ*/
+#include   <fcntl.h>      /*讙疲而蛻カ螳夂セゥ*/
+#include   <termios.h>    /*PPSIX 邨らォッ謗ァ蛻カ螳夂セゥ*/
+#include   <errno.h>      /*骭ッ隱、陌溷ョ夂セゥ*/
 #include 	<errno.h>
 #include 	<string.h>
 #include	<time.h>
@@ -37,11 +37,10 @@ typedef unsigned short 	word;
 typedef unsigned int 		unit;
 
 unsigned char _gunCount;
-struct ChargingInfoData *chargingInfo[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
-bool isStartOutputSwitch[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
+struct ChargingInfoData *chargingInfo[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY + GENERAL_GUN_QUANTITY];
+bool isStartOutputSwitch[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY + GENERAL_GUN_QUANTITY];
 
 struct timeval _cmdSubPriority_time;
-byte _getCapDelayCount;
 struct timeval _derating_time;
 struct timeval _max_time;
 
@@ -61,3 +60,14 @@ int connector_1[12];
 int connector_2[12];
 byte conn_1_count = 0;
 byte conn_2_count = 0;
+
+enum _PSU_CMD_SEQ
+{
+	_PSU_CMD_STATUS		= 1,
+	_PSU_CMD_VERSION	= 2,
+
+	_PSU_CMD_CAP		= 10,
+	_PSU_CMD_OUTPUT		= 11,
+	_PSU_CMD_IVAILIABLE	= 12,
+	_PSU_CMD_TEMP		= 13
+};

+ 134 - 20
EVSE/Projects/DO360/Apps/OutputTask.c

@@ -7,6 +7,84 @@
 
 #include 	"OutputTask.h"
 
+int Uart5Fd;
+int PresentRPM;
+
+char *relayRs485PortName = "/dev/ttyS5";
+
+int InitComPort5()
+{
+	int fd;
+	struct termios tios;
+
+	fd = open(relayRs485PortName, O_RDWR);
+	if(fd <= 0)
+	{
+		printf("InitComPort NG\n");
+		sleep(5);
+		return -1;
+	}
+	ioctl (fd, TCGETS, &tios);
+	tios.c_cflag = B115200 | CS8 | CLOCAL | CREAD;
+	tios.c_lflag = 0;
+	tios.c_iflag = 0;
+	tios.c_oflag = 0;
+	tios.c_cc[VMIN]=0;
+	tios.c_cc[VTIME]=(byte)0;		// timeout 0.5 second
+	tios.c_lflag=0;
+	tcflush(fd, TCIFLUSH);
+	ioctl (fd, TCSETS, &tios);
+
+	return fd;
+}
+
+unsigned char Set_Fan_Speed(unsigned char fd, int rpm)
+{
+	unsigned char result = FAIL;
+
+	PresentRPM = rpm;
+	if(rpm >= 14000)
+	{
+		rpm = 14000;
+	}
+	if(rpm < 0)
+	{
+		rpm = 0;
+	}
+
+	unsigned char tx[15] = {0xaa, 0x00, 0x02, 0x81, 0x08, 0x00, (rpm & 0xFF), ((rpm >> 8) & 0xFF), (rpm & 0xFF), ((rpm >> 8) & 0xFF), (rpm & 0xFF), ((rpm >> 8) & 0xFF), (rpm & 0xFF), ((rpm >> 8) & 0xFF), 0x00};
+	unsigned char rx[512];
+	unsigned char chksum = 0x00;
+
+	for(int idx = 0;idx<(tx[4] | tx[5]<<8);idx++)
+		chksum ^= tx[6+idx];
+	tx[14] = chksum;
+
+	unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
+	if(len > 6)
+	{
+		if (len < 6+(rx[4] | rx[5]<<8))
+			return result;
+
+		chksum = 0x00;
+		for(int idx = 0;idx<(rx[4] | rx[5]<<8);idx++)
+		{
+			chksum ^= rx[6+idx];
+		}
+
+		if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
+		   (rx[2] == tx[1]) &&
+		   (rx[1] == tx[2]) &&
+		   (rx[3] == tx[3]) &&
+		   rx[6] == PASS)
+		{
+			result = PASS;
+		}
+	}
+
+	return result;
+}
+
 bool isOpen;
 
 int InitComPort()
@@ -191,6 +269,7 @@ void GetInputString()
 
 	VOLTAGE = atof(newString[0]);
 	CURRENT = atof(newString[1]);
+	FANRPM = atoi(newString[2]);
 	if (VOLTAGE <= UnSafeDataInfo->PSU_VOLTAGE && CURRENT <= UnSafeDataInfo->PSU_CURRENT)
 	{
 		//printf("OutputVol = %f, OutputCur = %f \n", VOLTAGE, CURRENT);
@@ -203,27 +282,27 @@ void GetInputString()
 
 void GetIavailableCallback(byte address, unsigned short Iavail, unsigned short Vext)
 {
-	printf("address = %d, Iavail = %d, Vext = %d \n", address, Iavail, Vext);
+	//printf("address = %d, Iavail = %d, Vext = %d \n", address, Iavail, Vext);
 }
 
 void GetOutputAndTempCallback(byte address, unsigned short outputVol,
 		unsigned short outputCur, unsigned short outputPower, unsigned char Temperature)
 {
-//	PRINTF_FUNC("***Output Value and Temp*** address = %d, Vol = %d, Cur = %d, Pow = %d, Temp = %d \n",
-//			address, outputVol, outputCur, outputPower, Temperature);
+	//printf("***Output Value and Temp*** address = %d, Vol = %d, Cur = %d, Pow = %d, Temp = %d \n",
+	//		address, outputVol, outputCur, outputPower, Temperature);
 }
 
 void GetModuleStatusCallback(byte address, unsigned char isErr, unsigned char status,
 		unsigned char err1, unsigned char err2, unsigned char err3, unsigned char err4)
 {
-	int alarm = (err2 << 24) | (err3 << 16) | (err4 << 8);
+	//int alarm = (err2 << 24) | (err3 << 16) | (err4 << 8);
 
 	// err2 == state 2
 	// err3 == state 1
 	// err4 == state 0
 	//printf("***Status*** address = %d, alarm = %d \n", address, alarm);
-	printf("***Status*** address = %d, err1 = %d, err2 = %d, err3 = %d, err4 = %d \n",
-			address, err1,err2,err3,err4);
+//	printf("***Status*** address = %d, err1 = %d, err2 = %d, err3 = %d, err4 = %d \n",
+//			address, err1,err2,err3,err4);
 }
 
 void GetModuleInputCallback(byte address, unsigned short inputR,
@@ -254,6 +333,7 @@ int main(void)
 	AutoMode_RefreshModuleInput(&GetModuleInputCallback);
 
 	Uart1Fd = InitComPort();
+	Uart5Fd = InitComPort5();
 	libInitialize = InitialCommunication();
 
 	if (Uart1Fd < 0 || !libInitialize)
@@ -262,26 +342,32 @@ int main(void)
 		return 0;
 	}
 
+	if(Uart5Fd < 0)
+	{
+		printf("(Internal) open port error. \n");
+		return 0;
+	}
+
 	sleep(5);
 	gettimeofday(&_cmdSubPriority_time, NULL);
 	VOLTAGE = 0.0;
 	CURRENT = 0.0;
 
 	SwitchPower(SYSTEM_CMD, PSU_POWER_OFF);
-	while (1)
-	{
-		printf("++++++++++++++2++++++++++++++++++++++++++++++++++++++\n");
-		SetWalkInConfig(0, YES, 0);
-		SetWalkInConfig(1, NO, 0);
-		printf("++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
-		sleep(1);
-	}
-
-	sleep(1);
-		printf("++++++++++++++2++++++++++++++++++++++++++++++++++++++\n");
-		SetWalkInConfig(SYSTEM_CMD, NO, 0);
-		printf("++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
-	return 0;
+//	while (1)
+//	{
+//		printf("++++++++++++++2++++++++++++++++++++++++++++++++++++++\n");
+//		SetWalkInConfig(0, YES, 0);
+//		SetWalkInConfig(1, NO, 0);
+//		printf("++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
+//		sleep(1);
+//	}
+//
+//	sleep(1);
+//		printf("++++++++++++++2++++++++++++++++++++++++++++++++++++++\n");
+//		SetWalkInConfig(SYSTEM_CMD, NO, 0);
+//		printf("++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
+//	return 0;
 	while (1)
 	{
 		GetInputGpioStatus();
@@ -304,6 +390,19 @@ int main(void)
 			else
 				_charging_mode = CHARGING_MODE_TERMINATING;
 			//printf("_charging_mode = %d \n", _charging_mode);
+
+			if(PresentRPM != FANRPM)
+			{
+				if(Set_Fan_Speed(Uart5Fd, FANRPM) == PASS)
+				{
+					printf("Set Fan RPM: %d OK\n", FANRPM);
+				}
+				else
+				{
+					printf("Set Fan RPM: %d Fail\n", FANRPM);
+				}
+			}
+
 			switch(_charging_mode)
 			{
 				case CHARGING_MODE_START:
@@ -312,6 +411,13 @@ int main(void)
 					{
 						SwitchPower(SYSTEM_CMD, PSU_POWER_ON);
 						FlashLed(SYSTEM_CMD, PSU_FLASH_ON);
+
+						isOpen = true;
+						//SetDirModulePresentOutput(0,
+						//						VOLTAGE * 10,
+						//						CURRENT * 10,
+						//						0x01,
+						//						0x01);
 					}
 					PresentOutputVol(SYSTEM_CMD, VOLTAGE * 10, CURRENT * 10);
 				}
@@ -320,8 +426,16 @@ int main(void)
 				{
 					if (isOpen)
 					{
+						//SetDirModulePresentOutput(0,
+						//	VOLTAGE * 10,
+						//	CURRENT * 10,
+						//	0x00,
+						//	0x01);
 						SwitchPower(SYSTEM_CMD, PSU_POWER_OFF);
 						FlashLed(SYSTEM_CMD, PSU_FLASH_NORMAL);
+
+
+						isOpen = false;
 					}
 				}
 					break;

+ 1 - 0
EVSE/Projects/DO360/Apps/OutputTask.h

@@ -68,6 +68,7 @@ unsigned char isGetCount = NO;
 
 float VOLTAGE;
 float CURRENT;
+int FANRPM;
 
 struct PsuModuleInfo
 {

+ 6 - 6
EVSE/Projects/DO360/Apps/PrimaryComm.c

@@ -15,12 +15,12 @@
 
 #include 	<unistd.h>
 #include 	<stdarg.h>
-#include    <stdio.h>      /*シミキヌソ鬢Jソ鬣Xゥwクq*/
-#include    <stdlib.h>     /*シミキヌィ郛ニョwゥwクq*/
-#include    <unistd.h>     /*Unix シミキヌィ郛ニゥwクq*/
-#include    <fcntl.h>      /*タノアアィ鉀wクq*/
-#include    <termios.h>    /*PPSIX イラコンアアィ鉀wクq*/
-#include    <errno.h>      /*ソ�~クケゥwクq*/
+#include    <stdio.h>      /*讓呎コ冶シク蜈・霈ク蜃コ螳夂セゥ*/
+#include    <stdlib.h>     /*讓呎コ門�謨ク蠎ォ螳夂セゥ*/
+#include    <unistd.h>     /*Unix 讓呎コ門�謨ク螳夂セゥ*/
+#include    <fcntl.h>      /*讙疲而蛻カ螳夂セゥ*/
+#include    <termios.h>    /*PPSIX 邨らォッ謗ァ蛻カ螳夂セゥ*/
+#include    <errno.h>      /*骭ッ隱、陌溷ョ夂セゥ*/
 #include 	<errno.h>
 #include 	<string.h>
 #include	<time.h>

+ 58 - 51
EVSE/Projects/DO360/Apps/ReadCmdline.c

@@ -1,7 +1,7 @@
 /*
  * Main.c
  *
- *  Created on: 2019¦~8¤ë6¤é
+ *  Created on: 2019年8月6日
  *      Author: 7564
  */
 
@@ -23,12 +23,12 @@
 
 #include 	<unistd.h>
 #include 	<stdarg.h>
-#include    <stdio.h>      /*¼Ð·Ç¿é¤J¿é¥X©w¸q*/
-#include    <stdlib.h>     /*¼Ð·Ç¨ç¼Æ®w©w¸q*/
-#include    <unistd.h>     /*Unix ¼Ð·Ç¨ç¼Æ©w¸q*/
-#include    <fcntl.h>      /*Àɱ±¨î©w¸q*/
-#include    <termios.h>    /*PPSIX ²×ºÝ±±¨î©w¸q*/
-#include    <errno.h>      /*¿ù»~¸¹©w¸q*/
+#include    <stdio.h>      /*標準輸入輸出定義*/
+#include    <stdlib.h>     /*標準函數庫定義*/
+#include    <unistd.h>     /*Unix 標準函數定義*/
+#include    <fcntl.h>      /*檔控制定義*/
+#include    <termios.h>    /*PPSIX 終端控制定義*/
+#include    <errno.h>      /*錯誤號定義*/
 #include 	<errno.h>
 #include 	<string.h>
 #include	<time.h>
@@ -37,6 +37,7 @@
 #include 	<math.h>
 #include 	<stdbool.h>
 #include 	"../../define.h"
+#include    "Config.h"
 
 typedef unsigned char			byte;
 #define PASS				1
@@ -60,7 +61,7 @@ struct RelayModuleData			*ShmRelayModuleData;
 struct LedModuleData			*ShmLedModuleData;
 struct PsuData 					*ShmPsuData;
 
-struct ChargingInfoData 		*_chargingData[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
+struct ChargingInfoData 		*_chargingData[CONNECTOR_QUANTITY];
 struct ChargingInfoData 		*ac_chargingInfo[AC_QUANTITY];
 
 char *msg = "state : get gun state (index) \n"
@@ -100,6 +101,12 @@ bool FindChargingInfoData(byte target, struct ChargingInfoData **chargingData)
 		}
 	}
 
+    if(GENERAL_GUN_QUANTITY > 0 && target < GENERAL_GUN_QUANTITY)
+    {
+        chargingData[target] = &ShmSysConfigAndInfo->SysInfo.ConnectorInfo[target].GeneralChargingData;
+        return true;
+    }
+
 	return false;
 }
 
@@ -476,7 +483,7 @@ void SetPowerValue(char *v1, char *v2)
 {
 	int _index = atoi(v1);
 	float _Current = atof(v2);
-	// ª¼¨Rªº®É­Ô¤~¤¹³\¨Ï¥Î~
+	// 盲沖的時候��許使用~
 	if (_chargingData[_index]->Type != 9)
 		return;
 
@@ -744,7 +751,7 @@ void RunUnconditionalChargeIndex1(char *v1, char *v2, char *v3)
 //        return;
 //    }
 
-    //´ú¸Õ´Á¶¡¥ý¸õ¹L¦Û§Ú´ú¸Õ _STEST_COMPLETE = 0xfe
+    //測試期間先跳�自我測試 _STEST_COMPLETE = 0xfe
     //ShmSysConfigAndInfo->SysInfo.SelfTestSeq = 0xfe;
 
     //kill ev task
@@ -786,12 +793,12 @@ void RunUnconditionalChargeIndex1(char *v1, char *v2, char *v3)
 
         	        printf ("[UnconditionalCharge - S_PREPARNIN]\n");
 
-        	        //µ¥«Ý AC Relay ·f¤W¥B§ä¨ì¼Ò²Õ (main ¦b¦¹ statue ¨ä¥¦ task ·|¥h°µ§¹)
+        	        //等待 AC Relay �上且找到模組 (main 在此 statue 其它 task 會去�完)
         	        printf ("wait find module\n");
 
         	    }
-    		    //main ·|¦b¦¹¶¥¬q§PÂ_¥H¤U¸ê®Æ¸õ¨ì¤U¤@­Ó state
-    		    //¥Î¨Ó±oª¾ AC ¬O§_¦³·f¤W (·f¤W¼Ò²Õªº¸ê°T¤~·|¥X¨Ó) ¦]¬°¨C¦¸  AC_Contactor
+                //main 會在此階段判斷以下資料跳到下一個 state
+                //用來得知 AC 是�有�上 (�上模組的資訊�會出來) 因為�次  AC_Contactor
 
 
     		    //ShmPsuData->SystemPresentPsuQuantity;
@@ -799,12 +806,12 @@ void RunUnconditionalChargeIndex1(char *v1, char *v2, char *v3)
     		    //ShmPsuData->PsuGroup[gun_index].GroupAvailablePower;
     		    //_chargingData[gun_index]->AvailableChargingPower;
 
-    		    //µ¥«Ý AC Relay ·f¤W¥B§ä¨ì¼Ò²Õ (main ¦b¦¹ statue ¨ä¥¦ task ·|¥h°µ§¹)
+        	    //等待 AC Relay �上且找到模組 (main 在此 statue 其它 task 會去�完)
     		    //sleep(10);
 
-    		    //²M°£ main timeout ¾÷¨î
+        	    //清除 main timeout 機制
     		    _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->TimeoutFlag = 0;
-    		    //¤£½×¬O¤°»ò type ªººj³£©T·N³]¦¨ Chademo ¤£¶] Prechage step
+    		    //�論是什麼 type 的�都固�設� Chademo �跑 Prechage step
     		    _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->Type = 9;
 
     		}
@@ -820,19 +827,19 @@ void RunUnconditionalChargeIndex1(char *v1, char *v2, char *v3)
         	        printf ("ReqVoltage = %f, ReqCurrent = %f \n", _Voltage * 10,_Current * 10);
 
         	    }
-    		    //²M°£ main timeout ¾÷¨î
+        	    //清除 main timeout 機制
     		    _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->TimeoutFlag = 0;
-    		    //¤£½×¬O¤°»ò type ªººj³£©T·N³]¦¨ Chademo ¤£¶] Prechage step
+    		    //�論是什麼 type 的�都固�設� Chademo �跑 Prechage step
     		    _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->Type = 9;
 
-    		    //¥R¹q¹qÀ£¹q¬y
+    		    //充電電壓電�
     		    _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterySoc = 50;
    		        _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage = 500;
     		    _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent = 2;
     		    _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->AvailableChargingCurrent = 1000;
 
-    		    //****** ª`·N~¦¹¦æ¬°¬O¨¾¤î K1K2 ¥ý¶}¾É¨ìµLªk¤ÉÀ£ ( Relay Board ¦b¦¹ state ÁÙ¥¼·f¤W K1K2 )
-    		    //½T©w¼Ò²Õ¤v¤ÉÀ£§¹¦¨
+                //****** 注�~此行為是防止 K1K2 先開導到無法�壓 ( Relay Board 在此 state 還未�上 K1K2 )
+                //確定模組己�壓完�
     		    //if(_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingVoltage <=  (3000+500) &&
     		    //  _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingVoltage >=  (3000-500) )
     		    {
@@ -857,12 +864,12 @@ void RunUnconditionalChargeIndex1(char *v1, char *v2, char *v3)
         	    //printf ("tar vol = %d \n", _Voltage);
         	    //printf ("tar cur = %d \n", _Current);
 
-    		    //²M°£ main timeout ¾÷¨î
-    		    _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->TimeoutFlag = 0;
-    		    //¤£½×¬O¤°»ò type ªººj³£©T·N³]¦¨ Chademo ¤£¶] Prechage step
-    		    _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->Type = 9;
+        	    //清除 main timeout 機制
+                _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->TimeoutFlag = 0;
+                //�論是什麼 type 的�都固�設� Chademo �跑 Prechage step
+                _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->Type = 9;
 
-    		    //¥R¹q¹qÀ£¹q¬y
+                //充電電壓電�
     		    _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterySoc = 50;
     		    _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage = 500;
     		    _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent = 2;
@@ -871,8 +878,8 @@ void RunUnconditionalChargeIndex1(char *v1, char *v2, char *v3)
     		    //printf ("tar vol_ = %d \n", _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage);
         	   // printf ("tar cur_ = %d \n", _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent);
 
-    		    //****** ª`·N~¦¹¦æ¬°¬O¨¾¤î K1K2 ¥ý¶}¾É¨ìµLªk¤ÉÀ£ ( Relay Board ¦b¦¹ state ÁÙ¥¼·f¤W K1K2 )
-    		    //½T©w¼Ò²Õ¤v¤ÉÀ£§¹¦¨
+                //****** 注�~此行為是防止 K1K2 先開導到無法�壓 ( Relay Board 在此 state 還未�上 K1K2 )
+                //確定模組己�壓完�
     		    if(_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus == 0x01 ||
     		        _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus == 0x03)
     		    {
@@ -897,7 +904,7 @@ void RunUnconditionalChargeIndex1(char *v1, char *v2, char *v3)
         	    {
         	        PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
 
-        	        //¥R¹q¹qÀ£¹q¬y
+        	        //充電電壓電�
         	        _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterySoc = 50;
         	        _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage = _Voltage;
         	        _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent = _Current;
@@ -925,7 +932,7 @@ void RunUnconditionalChargeIndex1(char *v1, char *v2, char *v3)
         	        system("/root/Module_EvComm &");
 
         	        printf ("[UnconditionalCharge - S_TERMINATING]\n");
-        	        //µLªý¶ë°»´ú keybaord µ²§ô
+        	        //無阻塞�測 keybaord ��
         	        system(STTY_DEF TTY_PATH);
         	    }
 
@@ -1049,12 +1056,12 @@ int main(void)
 			if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
 				continue;
 
-			// ºjª¬ºA
+			// �狀態
 			RunStatusProc(newString[1], newString[2]);
 		}
 		else if(strcmp(newString[0], "card") == 0)
 		{
-			// ¨ê¥dª¬ºA
+		    // 刷�狀態
 			RunCardProc(newString[1], newString[2]);
 		}
 		else if(strcmp(newString[0], "gun") == 0)
@@ -1062,7 +1069,7 @@ int main(void)
 			if (strcmp(newString[1], "-1") == 0	|| strcmp(newString[1], "") == 0)
 				continue;
 
-			// ´¡ºjª¬ºA
+			// ��狀態
 			RunGunPlugitProc(newString[1], newString[2]);
 		}
 		else if(strcmp(newString[0], "lock") == 0)
@@ -1070,34 +1077,34 @@ int main(void)
 			if (strcmp(newString[1], "-1") == 0	|| strcmp(newString[1], "") == 0)
 				continue;
 
-			// ´¡ºjª¬ºA
+			// ��狀態
 			GetGunLockStatusProc(newString[1], newString[2]);
 		}
 		else if(strcmp(newString[0], "sysid") == 0)
 		{
-			// ´ú¸Õ sys id
+		    // 測試 sys id
 			SetSystemIDProc();
 		}
 		else if(strcmp(newString[0], "self") == 0)
 		{
-			// CSU ¦Û§ÚÀË´úª¬ºA
+		    // CSU 自我檢測狀態
 			RunSelfProc(newString[1]);
 		}
 		else if(strcmp(newString[0], "ver") == 0)
 		{
 			if (strcmp(newString[1], "-1") == 0	|| strcmp(newString[1], "") == 0)
 				continue;
-			// ¨ú FW ª©¸¹
+			// � FW 版號
 			GetFwVerProc(newString[1]);
 		}
 		else if (strcmp(newString[0], "update") == 0)
 		{
-			// §ó·s
+		    // æ›´æ–°
 			FwUpdateFlagProc(newString[1]);
 		}
 		else if (strcmp(newString[0], "ac") == 0)
 		{
-			// AC contactor ª¬ºA
+		    // AC contactor 狀態
 			CheckAcStatus(newString[1]);
 		}
 		else if (strcmp(newString[0], "cable") == 0)
@@ -1120,54 +1127,54 @@ int main(void)
 		}
 		else if(strcmp(newString[0], "select") == 0)
 		{
-			// ¨ú±o / ³]©w ·í«e¿ïªººj¸¹
+		    // �得 / 設定 當��的�號
 			GetGunSelectedNum(newString[1]);
 		}
 		else if(strcmp(newString[0], "change") == 0)
 		{
-			// ¼ÒÀÀ«ö¶s§ïÅÜ¿ïºj
+		    // 模擬按鈕改變��
 			ChangeGunNum();
 		}
 		else if(strcmp(newString[0], "fan") == 0)
 		{
-			// ³]©w­·®°³t«×
+		    // 設定風扇速度
 			SetFanSpeed(newString[1]);
 		}
 		else if(strcmp(newString[0], "speed") == 0)
 		{
-			// ¨ú±o­·®°³t«×
+		    // �得風扇速度
 			GetFanSpeed();
 		}
 		else if(strcmp(newString[0], "debug") == 0)
 		{
-			// ³]©w debug mode
+		    // 設定 debug mode
 			SetDebugMode(newString[1]);
 		}
 		else if (strcmp(newString[0], "gfd") == 0)
 		{
-			// ³]©wª¼¨R¨Ï¥Î GFD ¥\¯à
+		    // 設定盲沖使用 GFD 功能
 			SetGFDMode(newString[1]);
 		}
 		else if(strcmp(newString[0], "temp") == 0)
 		{
-			// ¨ú±o PSU ·Å«×
+		    // �得 PSU 溫度
 			GetPsuTemp();
 		}
 		else if(strcmp(newString[0], "acin") == 0)
 		{
-			// ¨ú±o¤T¦V¿é¤J¹qÀ£
+		    // �得三�輸入電壓
 			GetAcInputVol();
 		}
 		else if(strcmp(newString[0], "psu") == 0)
 		{
-			//¦pªG³s¤@­Ó°Ñ¼Æ³£¨S¦³ (¦¹©R¥O¤£²z·|) ¥[¤W§PÂ_²Ä¤G°Ñ¼Æ
+		    //如果連一個�數都沒有 (此命令��會) 加上判斷第二�數
 			if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
 			{
 				printf ("PSU : Param fail..Please retry again......\n");
 				continue;
 			}
 
-			// ¨ú±o PSU ¸ê°T
+			// �得 PSU 資訊
 			GetPsuInformation(newString[1], newString[2], newString[3]);
 		}
 		else if (strcmp(newString[0], "cap") == 0)
@@ -1188,7 +1195,7 @@ int main(void)
 		}
 		else if(strcmp(newString[0], "strchg") == 0)
 		{
-			//¦pªG³s¤@­Ó°Ñ¼Æ³£¨S¦³ (¦¹©R¥O¤£²z·|) ¥[¤W§PÂ_²Ä¤G°Ñ¼Æ
+		    //如果連一個�數都沒有 (此命令��會) 加上判斷第二�數
 			if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0 ||
 					strcmp(newString[2], "-1") == 0 || strcmp(newString[2], "") == 0)
 			{
@@ -1196,7 +1203,7 @@ int main(void)
 				continue;
 			}
 
-			// ºjª¬ºA
+			// �狀態
 			RunUnconditionalChargeIndex1(newString[1], newString[2], newString[3]);
 		}
 		else

+ 8 - 8
EVSE/Projects/DO360/Apps/internalComm.c

@@ -1,7 +1,7 @@
 /*
  * internalComm.c
  *
- *  Created on: 2019¦~5¤ë7¤é
+ *  Created on: 2019年5月7日
  *      Author: foluswen
  */
 #include 	<sys/time.h>
@@ -21,12 +21,12 @@
 
 #include 	<unistd.h>
 #include 	<stdarg.h>
-#include    <stdio.h>      /*¼Ð·Ç¿é¤J¿é¥X©w¸q*/
-#include    <stdlib.h>     /*¼Ð·Ç¨ç¼Æ®w©w¸q*/
-#include    <unistd.h>     /*Unix ¼Ð·Ç¨ç¼Æ©w¸q*/
-#include    <fcntl.h>      /*Àɱ±¨î©w¸q*/
-#include    <termios.h>    /*PPSIX ²×ºÝ±±¨î©w¸q*/
-#include    <errno.h>      /*¿ù»~¸¹©w¸q*/
+#include    <stdio.h>      /*標準輸入輸出定義*/
+#include    <stdlib.h>     /*標準函數庫定義*/
+#include    <unistd.h>     /*Unix 標準函數定義*/
+#include    <fcntl.h>      /*檔控制定義*/
+#include    <termios.h>    /*PPSIX 終端控制定義*/
+#include    <errno.h>      /*錯誤號定義*/
 #include 	<errno.h>
 #include 	<string.h>
 #include	<time.h>
@@ -38,7 +38,7 @@
 #define PASS				1
 #define FAIL				-1
 
-struct Address Addr={0x01,0x02,0x03,0x05,0x06,0xFF};
+struct Address Addr={0x01,0x02,0x03,0x05,0x06,0x07,0x08,0x09,0xFF};
 struct Command Cmd={0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x24,0x27,0x28,0x29,0x2C,0x81,0x83,
 		0x85,0x86,0x87,0x88,0x089,0x8A,0x8B,0x8C,0x90,0x93,0xe0,0xe1,0xe2,0xe3};
 

+ 7 - 4
EVSE/Projects/DO360/Apps/internalComm.h

@@ -1,7 +1,7 @@
 /*
  * internalComm.h
  *
- *  Created on: 2019¦~5¤ë7¤é
+ *  Created on: 2019年5月7日
  *      Author: foluswen
  */
 
@@ -15,6 +15,9 @@ extern struct Address
 	unsigned char Relay;
 	unsigned char AcPlug;
 	unsigned char Led;
+	unsigned char DO360_RC1;
+	unsigned char DO360_RC2;
+	unsigned char DD360_Relay;
 	unsigned char Broadcast;
 }Addr;
 
@@ -116,7 +119,7 @@ typedef struct RELAY
 
 			unsigned char Gun1_N :1;			//bit 0
 			unsigned char Gun1_P :1;			//bit 1
-			unsigned char Gun1_Parallel_N :1;  //bit 2
+			unsigned char Gun1_Parallel_N :1;	//bit 2
 			unsigned char Gun1_Parallel_P :1;	//bit 3
 			unsigned char :1;					//bit 4 reserved
 			unsigned char :1;					//bit 5 reserved
@@ -125,8 +128,8 @@ typedef struct RELAY
 
 			unsigned char Gun2_N :1;			//bit 0
 			unsigned char Gun2_P :1;			//bit 1
-			unsigned char :1; 					//bit 2 reserved
-			unsigned char :1;					//bit 3 reserved
+			unsigned char Gun2_Parallel_N :1;	//bit 2
+			unsigned char Gun2_Parallel_P :1;	//bit 3
 			unsigned char :1;					//bit 4 reserved
 			unsigned char :1;					//bit 5 reserved
 			unsigned char :1;					//bit 6 reserved

+ 6223 - 5375
EVSE/Projects/DO360/Apps/main.c

@@ -1,5375 +1,6223 @@
-#include    <sys/types.h>
-#include    <sys/stat.h>
-#include 	<sys/time.h>
-#include 	<sys/timeb.h>
-#include 	<sys/types.h>
-#include 	<sys/ioctl.h>
-#include 	<sys/socket.h>
-#include 	<sys/ipc.h>
-#include 	<sys/shm.h>
-#include 	<sys/mman.h>
-#include 	<linux/wireless.h>
-#include 	<arpa/inet.h>
-#include 	<netinet/in.h>
-
-#include 	<unistd.h>
-#include 	<stdarg.h>
-#include    <stdio.h>      /*標準輸入輸出定義*/
-#include    <stdlib.h>     /*標準函數庫定義*/
-#include    <unistd.h>     /*Unix 標準函數定義*/
-#include    <fcntl.h>      /*檔控制定義*/
-#include    <termios.h>    /*PPSIX 終端控制定義*/
-#include    <errno.h>      /*錯誤號定義*/
-#include 	<errno.h>
-#include 	<string.h>
-#include 	<stdint.h>
-#include	<time.h>
-#include	<ctype.h>
-#include 	<ifaddrs.h>
-#include 	<math.h>
-#include 	"../../define.h"
-#include 	"Config.h"
-#include 	<stdbool.h>
-#include 	<dirent.h>
-#include	"timeout.h"
-
-#define 	ARRAY_SIZE(A)		(sizeof(A) / sizeof(A[0]))
-#define 	PASS				1
-#define 	FAIL				-1
-#define 	BUFFER_SIZE			128
-#define 	YES					1
-#define 	NO					0
-#define 	NORMAL				0
-#define		ABNORMAL			1
-#define 	EQUAL				0
-#define 	BTN_RELEASE			0
-#define 	BTN_PRESS			1
-#define 	MAX_BUF 			64
-#define 	MtdBlockSize 		0x600000
-#define 	SYSFS_GPIO_DIR 		"/sys/class/gpio"
-#define		UPGRADE_FAN			0x02
-#define		UPGRADE_RB			0x03
-#define		UPGRADE_PRI			0x04
-#define		UPGRADE_AC			0x05
-#define		SYSTEM_MIN_VOL		150
-#define 	MIN_OUTPUT_CUR		0
-#define		AC_OUTPUT_VOL		220
-
-#define		NO_DEFINE			255
-#define 	DEFAULT_AC_INDEX	2
-#define  	PSU_MIN_CUR			100
-
-#define 	DB_FILE				"/Storage/ChargeLog/localCgargingRecord.db"
-
-char 	*valid_Internet[2] 	  = {"8.8.8.8", "180.76.76.76"};
-unsigned char mask_table[] = { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 };
-int whileLoopTime = 10000; // 10 ms
-int	wtdFd = -1;
-byte _authorizeIndex = NO_DEFINE;
-
-bool IsAuthorizingMode();
-void ClearAuthorizedFlag();
-bool isDetectPlugin();
-void ClearDetectPluginFlag();
-int mystrcmp(unsigned char *p1, unsigned char *p2);
-
-long long DiffTimebWithNow(struct timeb ST);
-unsigned char DetectBitValue(unsigned char _byte, unsigned char _bit);
-void SetBitValue(unsigned char *_byte, unsigned char _bit, unsigned char value);
-void ChargingTerminalProcess(byte gunIndex);
-void ChkPrimaryStatus();
-void StartSystemTimeoutDet(unsigned char flag);
-void StopSystemTimeoutDet();
-void StartGunInfoTimeoutDet(unsigned char gunIndex, unsigned char flag);
-void StopGunInfoTimeoutDet(unsigned char gunIndex);
-int StoreLogMsg_1(const char *fmt, ...);
-unsigned long GetTimeoutValue(struct timeval _sour_time);
-void gpio_set_value(unsigned int gpio, unsigned int value);
-void PRINTF_FUNC(char *string, ...);
-void ChangeGunSelectByIndex(byte sel);
-
-void RecordAlarmCode(byte gunIndex, char *code);
-void RecordWarningCode(byte gunIndex, char *code);
-void ReleaseWarningCodeByString(byte gunIndex, char *code);
-void ReleaseAlarmCode(byte gunIndex);
-
-int DB_Open(sqlite3 *db);
-int DB_Insert_Record(sqlite3 *db, int gun_index);
-int DB_Update_Operactive(sqlite3 *db, uint8_t gun_index, uint8_t IsAvailable);
-int DB_Get_Operactive(sqlite3 *db, uint8_t gun_index);
-
-#define DEBUG_INFO_MSG(format, args...) StoreLogMsg_1("[%s:%d][%s][Info] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
-#define DEBUG_WARN_MSG(format, args...) StoreLogMsg_1("[%s:%d][%s][Warn] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
-#define DEBUG_ERROR_MSG(format, args...) StoreLogMsg_1("[%s:%d][%s][Error] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
-
-struct SysConfigAndInfo			*ShmSysConfigAndInfo;
-struct StatusCodeData 			*ShmStatusCodeData;
-struct PsuData 					*ShmPsuData;
-struct CHAdeMOData				*ShmCHAdeMOData;
-struct GBTData					*ShmGBTData;
-struct CcsData					*ShmCcsData;
-struct PrimaryMcuData			*ShmPrimaryMcuData;
-struct FanModuleData			*ShmFanModuleData;
-struct RelayModuleData			*ShmRelayModuleData;
-struct LedModuleData			*ShmLedModuleData;
-struct OCPP16Data				*ShmOCPP16Data;
-
-struct ChargingInfoData			*chargingInfo[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
-struct ChargingInfoData			*ac_chargingInfo[AC_QUANTITY];
-struct timeb 					startChargingTime[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
-struct timeb 					endChargingTime[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
-
-// for initial index to check EV board type is correct
-byte _gunIndex = 0;
-byte _acgunIndex = 0;
-byte _chademoIndex = 0;
-byte _ccsIndex = 0;
-byte _gb_Index = 0;
-byte _ac_Index = 0;
-byte bd0_1_status = 0;
-byte bd0_2_status = 0;
-byte bd1_1_status = 0;
-byte bd1_2_status = 0;
-
-bool isCardScan = false;
-bool isModelNameMatch = true;
-
-int rfidFd = -1;
-char* rfidPortName = "/dev/ttyS2";
-char* fwVersion = "D0.14.00.0000.00";
-
-sqlite3 *localDb;
-bool isDb_ready;
-
-//================================================
-// initial can-bus
-//================================================
-int InitCanBus()
-{
-	int 					s0,nbytes;
-	struct timeval			tv;
-	struct ifreq 			ifr0;
-	struct sockaddr_can		addr0;
-
-	system("/sbin/ip link set can0 down");
-	system("/sbin/ip link set can0 type can bitrate 500000 restart-ms 100");
-	system("/sbin/ip link set can0 up");
-
-	s0 = socket(PF_CAN, SOCK_RAW, CAN_RAW);
-
-	tv.tv_sec = 0;
-	tv.tv_usec = 10000;
-   	if (setsockopt(s0, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv, sizeof(struct	timeval)) < 0)
-	{
-		#ifdef SystemLogMessage
-		DEBUG_ERROR_MSG("Set SO_RCVTIMEO NG");
-		#endif
-	}
-	nbytes=40960;
-	if (setsockopt(s0, SOL_SOCKET,  SO_RCVBUF, &nbytes, sizeof(int)) < 0)
-	{
-		#ifdef SystemLogMessage
-		DEBUG_ERROR_MSG("Set SO_RCVBUF NG");
-		#endif
-	}
-	nbytes=40960;
-	if (setsockopt(s0, SOL_SOCKET, SO_SNDBUF, &nbytes, sizeof(int)) < 0)
-	{
-		#ifdef SystemLogMessage
-		DEBUG_ERROR_MSG("Set SO_SNDBUF NG");
-		#endif
-	}
-
-   	strcpy(ifr0.ifr_name, "can0" );
-	ioctl(s0, SIOCGIFINDEX, &ifr0); /* ifr.ifr_ifindex gets filled with that device's index */
-	addr0.can_family = AF_CAN;
-	addr0.can_ifindex = ifr0.ifr_ifindex;
-	bind(s0, (struct sockaddr *)&addr0, sizeof(addr0));
-	return s0;
-}
-
-//================================================
-// initial uart port
-//================================================
-char *_priPortName = "/dev/ttyS1";
-char *_485PortName = "/dev/ttyS5";
-
-int InitComPort(byte target)
-{
-	int fd;
-	struct termios tios;
-
-	if(target == UPGRADE_PRI)
-		fd = open(_priPortName, O_RDWR);
-	else if (target == UPGRADE_FAN ||  target == UPGRADE_RB || target == UPGRADE_AC)
-		fd = open(_485PortName, O_RDWR);
-
-	if(fd<=0)
-	{
-		#ifdef SystemLogMessage
-		DEBUG_ERROR_MSG("open 407 Communication port NG \n");
-		#endif
-		return -1;
-	}
-	ioctl (fd, TCGETS, &tios);
-	tios.c_cflag = B115200| CS8 | CLOCAL | CREAD;
-	tios.c_lflag = 0;
-	tios.c_iflag = 0;
-	tios.c_oflag = 0;
-	tios.c_cc[VMIN]=0;
-	tios.c_cc[VTIME]=(unsigned char)1;
-	tios.c_lflag=0;
-	tcflush(fd, TCIFLUSH);
-	ioctl (fd, TCSETS, &tios);
-
-	return fd;
-}
-
-//=================================
-// Common routine
-//=================================
-int InitWatchDog()
-{
-	int fd;
-	system("/usr/bin/fuser -k /dev/watchdog");
-	sleep(1);
-	system("echo V > /dev/watchdog");
-	sleep(1);
-	fd=open("/dev/watchdog", O_RDWR);
-
-	if(fd<=0)
-	{
-		DEBUG_ERROR_MSG("System watch dog initial fail.\r\n");
-	}
-	return fd;
-}
-
-int StoreLogMsg_1(const char *fmt, ...)
-{
-	char Buf[4096+256];
-	char buffer[4096];
-	va_list args;
-	struct timeb  SeqEndTime;
-	struct tm *tm;
-
-	va_start(args, fmt);
-	int rc = vsnprintf(buffer, sizeof(buffer), fmt, args);
-	va_end(args);
-
-	memset(Buf,0,sizeof(Buf));
-	ftime(&SeqEndTime);
-	SeqEndTime.time = time(NULL);
-	tm=localtime(&SeqEndTime.time);
-
-	if (ShmSysConfigAndInfo->SysConfig.SwitchDebugFlag == YES)
-	{
-		sprintf(Buf,"%02d:%02d:%02d:%03d - %s",
-			tm->tm_hour,tm->tm_min,tm->tm_sec,SeqEndTime.millitm, buffer);
-		printf("%s \n", Buf);
-	}
-	else
-	{
-		sprintf(Buf,"echo \"%04d-%02d-%02d %02d:%02d:%02d:%03d - %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,SeqEndTime.millitm,
-			buffer,
-			tm->tm_year+1900,tm->tm_mon+1);
-		system(Buf);
-	}
-
-	return rc;
-}
-
-unsigned long GetTimeoutValue(struct timeval _sour_time)
-{
-	struct timeval _end_time;
-	gettimeofday(&_end_time, NULL);
-
-	return 1000000 * (_end_time.tv_sec - _sour_time.tv_sec) + _end_time.tv_usec - _sour_time.tv_usec;
-}
-
-int mystrcmp(unsigned char *p1, unsigned char *p2)
-{
-    while(*p1==*p2)
-    {
-        if(*p1=='\0' || *p2=='\0')
-            break;
-        p1++;
-        p2++;
-    }
-    if(*p1=='\0' && *p2=='\0')
-        return(PASS);
-    else
-        return(FAIL);
-}
-
-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;
-	return (StopTime-StartTime);
-}
-
-bool CheckTimeOut(struct timeb ST)
-{
-	struct timeb ET;
-	unsigned int StartTime, StopTime;
-
-	ftime(&ET);
-	StartTime = (unsigned int) ST.time;
-	StopTime = (unsigned int) ET.time;
-	return (StopTime > StartTime)? YES : NO;
-}
-
-void setChargerMode(byte gun_index, byte mode)
-{
-	chargingInfo[gun_index]->SystemStatus = mode;
-}
-
-void PRINTF_FUNC(char *string, ...)
-{
-	va_list args;
-	char buffer[4096];
-	va_start(args, string);
-	vsnprintf(buffer, sizeof(buffer), string, args);
-	va_end(args);
-
-	DEBUG_INFO_MSG("%s \n", buffer);
-}
-
-long long DiffTimebWithNow(struct timeb ST)
-{
-	//return milli-second
-	struct timeb ET;
-	long long StartTime,StopTime;
-
-	ftime(&ET);
-	StartTime=(long long)ST.time;
-	StopTime=(long long)ET.time;
-	return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
-}
-
-//==========================================
-// Check interface status
-//==========================================
-int isInterfaceUp(const char *interface)
-{
-	int result = FAIL;
-
-	FILE *fp;
-	char cmd[256];
-	char buf[512];
-
-	strcpy(cmd, "ifconfig");
-	fp = popen(cmd, "r");
-	if(fp != NULL)
-	{
-		while(fgets(buf, sizeof(buf), fp) != NULL)
-		{
-			if(strstr(buf, interface) > 0)
-			{
-				result = PASS;
-			}
-		}
-	}
-	pclose(fp);
-
-	return result;
-}
-
-//=================================
-// Create all share memory
-//=================================
-int CreateShareMemory()
-{
-	int MeterSMId;
-
-	if ((MeterSMId = shmget(ShmSysConfigAndInfoKey,	sizeof(struct SysConfigAndInfo), IPC_CREAT | 0777)) < 0)
-	{
-		#ifdef SystemLogMessage
-		DEBUG_ERROR_MSG("[main]CreatShareMemory:shmget ShmSysConfigAndInfo NG \n");
-		#endif
-		return 0;
-	}
-	else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0))	== (void *) -1)
-	{
-		#ifdef SystemLogMessage
-		DEBUG_ERROR_MSG("[main]CreatShareMemory:shmat ShmSysConfigAndInfo NG \n");
-		#endif
-		return 0;
-	}
-	memset(ShmSysConfigAndInfo, 0, sizeof(struct SysConfigAndInfo));
-
-	if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), IPC_CREAT | 0777)) < 0)
-	{
-		#ifdef SystemLogMessage
-		DEBUG_ERROR_MSG("[main]CreatShareMemory:shmget ShmStatusCodeData NG \n");
-		#endif
-		return 0;
-	}
-	else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
-	{
-		#ifdef SystemLogMessage
-		DEBUG_ERROR_MSG("[main]CreatShareMemory:shmat ShmStatusCodeData NG \n");
-		#endif
-		return 0;
-	}
-
-	memset(ShmStatusCodeData, 0, sizeof(struct StatusCodeData));
-
-	//creat ShmPsuData
-	if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), IPC_CREAT | 0777)) < 0)
-	{
-		#ifdef SystemLogMessage
-		DEBUG_ERROR_MSG("[main]CreatShareMemory:shmget ShmPsuData NG \n");
-		#endif
-		return 0;
-	}
-	else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
-	{
-		#ifdef SystemLogMessage
-		DEBUG_ERROR_MSG("[main]CreatShareMemory:shmat ShmPsuData NG \n");
-		#endif
-		return 0;
-	}
-	memset(ShmPsuData, 0, sizeof(struct PsuData));
-
-	if(CHAdeMO_QUANTITY > 0)
-	{
-		if ((MeterSMId = shmget(ShmCHAdeMOCommKey, sizeof(struct CHAdeMOData),	IPC_CREAT | 0777)) < 0)
-		{
-			#ifdef SystemLogMessage
-			DEBUG_ERROR_MSG("[main]CreatShareMemory:shmget ShmCHAdeMOData NG \n");
-			#endif
-			return 0;
-		}
-		else if ((ShmCHAdeMOData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
-		{
-			#ifdef SystemLogMessage
-			DEBUG_ERROR_MSG("[main]CreatShareMemory:shmat ShmCHAdeMOData NG \n");
-			#endif
-			return 0;
-		}
-		memset(ShmCHAdeMOData, 0, sizeof(struct CHAdeMOData));
-	}
-
-	if(GB_QUANTITY > 0)
-	{
-		if ((MeterSMId = shmget(ShmGBTCommKey, sizeof(struct GBTData),	IPC_CREAT | 0777)) < 0)
-		{
-			#ifdef SystemLogMessage
-			DEBUG_ERROR_MSG("[main]CreatShareMemory:shmget ShmGBTData NG \n");
-			#endif
-			return 0;
-		}
-		else if ((ShmGBTData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
-		{
-			#ifdef SystemLogMessage
-			DEBUG_ERROR_MSG("[main]CreatShareMemory:shmat ShmGBTData NG \n");
-			#endif
-			return 0;
-		}
-		memset(ShmGBTData, 0, sizeof(struct GBTData));
-	}
-
-	//creat ShmCcsData
-	if(CCS_QUANTITY > 0)
-	{
-		if ((MeterSMId = shmget(ShmCcsCommKey, sizeof(struct CcsData),	IPC_CREAT | 0777)) < 0)
-		{
-			#ifdef SystemLogMessage
-			DEBUG_ERROR_MSG("[main]CreatShareMemory:shmget ShmCcsData NG \n");
-			#endif
-			return 0;
-		}
-		else if ((ShmCcsData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
-		{
-			#ifdef SystemLogMessage
-			DEBUG_ERROR_MSG("[main]CreatShareMemory:shmat ShmCcsData NG \n");
-			#endif
-			return 0;
-		}
-		memset(ShmCcsData, 0, sizeof(struct CcsData));
-	}
-
-	//creat ShmPrimaryMcuData
-	if ((MeterSMId = shmget(ShmPrimaryMcuKey, sizeof(struct PrimaryMcuData), IPC_CREAT | 0777)) < 0)
-	{
-		#ifdef SystemLogMessage
-		DEBUG_ERROR_MSG("[main]CreatShareMemory:shmget ShmPrimaryMcuData NG \n");
-		#endif
-		return 0;
-	}
-	else if ((ShmPrimaryMcuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
-	{
-		#ifdef SystemLogMessage
-		DEBUG_ERROR_MSG("[main]CreatShareMemory:shmat ShmPrimaryMcuData NG \n");
-		#endif
-		return 0;
-	}
-	memset(ShmPrimaryMcuData, 0, sizeof(struct PrimaryMcuData));
-
-	//creat ShmFanModuleData
-	if ((MeterSMId = shmget(ShmFanBdKey, sizeof(struct FanModuleData),	IPC_CREAT | 0777)) < 0)
-	{
-		#ifdef SystemLogMessage
-		DEBUG_ERROR_MSG("[main]CreatShareMemory:shmget ShmFanModuleData NG \n");
-		#endif
-		return 0;
-	}
-	else if ((ShmFanModuleData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
-	{
-		#ifdef SystemLogMessage
-		DEBUG_ERROR_MSG("[main]CreatShareMemory:shmat ShmFanModuleData NG \n");
-		#endif
-		return 0;
-	}
-	memset(ShmFanModuleData, 0, sizeof(struct FanModuleData));
-
-	//creat ShmRelayModuleData
-	if ((MeterSMId = shmget(ShmRelayBdKey, sizeof(struct RelayModuleData),	IPC_CREAT | 0777)) < 0)
-	{
-		#ifdef SystemLogMessage
-		DEBUG_ERROR_MSG("[main]CreatShareMemory:shmget ShmRelayModuleData NG \n");
-		#endif
-		return 0;
-	}
-	else if ((ShmRelayModuleData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
-	{
-		#ifdef SystemLogMessage
-		DEBUG_ERROR_MSG("[main]CreatShareMemory:shmat ShmRelayModuleData NG \n");
-		#endif
-		return 0;
-	}
-	memset(ShmRelayModuleData, 0, sizeof(struct RelayModuleData));
-
-	if ((MeterSMId = shmget(ShmLedBdKey, sizeof(struct LedModuleData), IPC_CREAT | 0777)) < 0)
-	{
-		#ifdef SystemLogMessage
-		DEBUG_ERROR_MSG("[main]CreatShareMemory:shmget ShmLedModuleData NG \n");
-		#endif
-		return 0;
-	}
-	else if ((ShmLedModuleData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
-	{
-		#ifdef SystemLogMessage
-		DEBUG_ERROR_MSG("[main]CreatShareMemory:shmat ShmLedModuleData NG \n");
-		#endif
-		return 0;
-	}
-	memset(ShmLedModuleData, 0, sizeof(struct LedModuleData));
-
-	//creat ShmOCPP16Data
-	if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), IPC_CREAT | 0777)) < 0)
-	{
-		#ifdef SystemLogMessage
-		DEBUG_ERROR_MSG("[main]CreatShareMemory:shmget ShmOCPP16Data NG \n");
-		#endif
-		return 0;
-	}
-	else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
-	{
-		#ifdef SystemLogMessage
-		DEBUG_ERROR_MSG("[main]CreatShareMemory:shmat ShmOCPP16Data NG \n");
-		#endif
-		return 0;
-	}
-	// memset(ShmOCPP16Data,0,sizeof(struct OCPP16Data));
-	return 1;
-}
-
-//=================================
-// LCM Page
-//=================================
-void ChangeLcmByIndex(byte page_index)
-{
-	if (ShmSysConfigAndInfo->SysWarningInfo.Level != 2 ||
-			page_index == _LCM_COMPLETE || page_index == _LCM_FIX)
-	{
-		ShmSysConfigAndInfo->SysInfo.PageIndex = page_index;
-	}
-}
-
-//======================================================
-// Peripheral initial
-//======================================================
-void InitGPIO()
-{
-	/*****************0~3, 4 bank, bank x 32+ num*********************/
-	/***************************************************************/
-	/*************** GPIO 0 ***************************************/
-	/***************************************************************/
-	/* GPMC_AD8			=> 	GPIO0_22 *//*ID BD1_1*/
-	system("echo 22 > /sys/class/gpio/export");
-	system("echo \"in\" > /sys/class/gpio/gpio22/direction");
-	/* GPMC_AD9			=>	GPIO0_23 *//*ID BD1_2*/
-	system("echo 23 > /sys/class/gpio/export");
-	system("echo \"in\" > /sys/class/gpio/gpio23/direction");
-	/* GPMC_AD10		=>	GPIO0_26 *//*IO BD1_1*/
-	system("echo 26 > /sys/class/gpio/export");
-	system("echo \"out\" > /sys/class/gpio/gpio26/direction");
-	system("echo 1 > /sys/class/gpio/gpio26/value");
-	/* GPMC_AD11		=>	GPIO0_27 *//*IO BD1_2*/
-	system("echo 27 > /sys/class/gpio/export");
-	system("echo \"in\" > /sys/class/gpio/gpio27/direction");
-	/* RMII1_REF_CLK		=>	GPIO0_29 *//*USB 0 OCP detection*/
-	system("echo 29 > /sys/class/gpio/export");
-	system("echo \"in\" > /sys/class/gpio/gpio29/direction");
-	/*XDMA_EVENT_INTR0	=>	GPIO0_19 *//*AM_RFID_RST*/
-	system("echo 19 > /sys/class/gpio/export");
-	system("echo \"out\" > /sys/class/gpio/gpio19/direction");
-	system("echo 1 > /sys/class/gpio/gpio19/value");
-	/*XDMA_EVENT_INTR1	=>	GPIO0_20 *//*AM_RFID_ICC*/
-	system("echo 20 > /sys/class/gpio/export");
-	system("echo \"in\" > /sys/class/gpio/gpio20/direction");
-	/***************************************************************/
-	/*************** GPIO 1 ***************************************/
-	/***************************************************************/
-	/* GPMC_AD12	=> 	GPIO1_12 *//*ID BD2_1*/
-	system("echo 44 > /sys/class/gpio/export");
-	system("echo \"in\" > /sys/class/gpio/gpio44/direction");
-	/* GPMC_AD13	=>	GPIO1_13 *//*ID BD2_2*/
-	system("echo 45 > /sys/class/gpio/export");
-	system("echo \"in\" > /sys/class/gpio/gpio45/direction");
-	/* GPMC_AD14	=>	GPIO1_14 *//*IO BD2_1*/
-	system("echo 46 > /sys/class/gpio/export");
-	system("echo \"out\" > /sys/class/gpio/gpio46/direction");
-	system("echo 0 > /sys/class/gpio/gpio46/value");
-	/* GPMC_AD15	=>	GPIO1_15 *//*IO BD2_2*/
-	system("echo 47 > /sys/class/gpio/export");
-	system("echo \"in\" > /sys/class/gpio/gpio47/direction");
-	/***************************************************************/
-	/*************** GPIO 2 ***************************************/
-	/***************************************************************/
-	/*LCD_AC_BIAS_EN	=>	GPIO2_25*//*RS-485 for module DE control*/
-	system("echo 89 > /sys/class/gpio/export");
-	system("echo \"out\" > /sys/class/gpio/gpio89/direction");
-	system("echo 1 > /sys/class/gpio/gpio89/value");
-	/*LCD_HSYNC		=>	GPIO2_23*//*RS-485 for module RE control*/
-	system("echo 87 > /sys/class/gpio/export");
-	system("echo \"out\" > /sys/class/gpio/gpio87/direction");
-	system("echo 0 > /sys/class/gpio/gpio87/value");
-	/*LCD_PCLK		=>	GPIO2_24*//*CCS communication board 1 proximity*/
-	system("echo 88 > /sys/class/gpio/export");
-	system("echo \"in\" > /sys/class/gpio/gpio88/direction");
-	/*LCD_VSYNC		=>	GPIO2_22*//*CCS communication board 2 proximity*/
-	system("echo 86 > /sys/class/gpio/export");
-	system("echo \"in\" > /sys/class/gpio/gpio86/direction");
-	/***************************************************************/
-	/*************** GPIO 3 ***************************************/
-	/***************************************************************/
-	/*MCASP0_FSX		=>	GPIO3_15*//*Emergency Stop button detect*/
-	system("echo 111 > /sys/class/gpio/export");
-	system("echo \"in\" > /sys/class/gpio/gpio111/direction");
-	/*MCASP0_ACLKR	=>	GPIO3_18*//*USB1 OCP detect*/
-	system("echo 114 > /sys/class/gpio/export");
-	system("echo \"in\" > /sys/class/gpio/gpio114/direction");
-	/*MCASP0_AHCLKR	=>	GPIO3_17*//*Emergency IO for AM3352 and STM32F407*/
-	system("echo 113 > /sys/class/gpio/export");
-	system("echo \"in\" > /sys/class/gpio/gpio113/direction");
-	/*MCASP0_ACLKX	=>	GPIO3_14*//*Ethernet PHY reset*/
-	system("echo 110 > /sys/class/gpio/export");
-	system("echo \"out\" > /sys/class/gpio/gpio110/direction");
-	system("echo 0 > /sys/class/gpio/gpio110/value");
-	/* MCASP0_FSR		=>	GPIO3_19 *//*SMR Enable control_1 for Pskill_1*/
-	system("echo 115 > /sys/class/gpio/export");
-	system("echo \"out\" > /sys/class/gpio/gpio115/direction");
-	system("echo 0 > /sys/class/gpio/gpio115/value");
-	/* MCASP0_AXR0	=>	GPIO3_16 *//*CSU board function OK indicator.*/
-	system("echo 112 > /sys/class/gpio/export");
-	system("echo \"out\" > /sys/class/gpio/gpio112/direction");
-	system("echo 1 > /sys/class/gpio/gpio112/value");
-	/* MCASP0_AXR1	=>	GPIO3_20 *//*SMR Enable control_2 for Pskill_2*/
-	system("echo 116 > /sys/class/gpio/export");
-	system("echo \"out\" > /sys/class/gpio/gpio116/direction");
-	system("echo 0 > /sys/class/gpio/gpio116/value");
-#ifdef SystemLogMessage
-	DEBUG_INFO_MSG("[main]InitGPIO: Initial GPIO OK");
-#endif
-}
-
-int LoadSysConfigAndInfo(struct SysConfigData *ptr)
-{
-	int fd,wrd;
-	unsigned char *buf;
-	unsigned int ChkSum,ChkSumOrg;
-
-	if((buf=malloc(MtdBlockSize))==NULL)
-	{
-		DEBUG_ERROR_MSG("malloc buffer NG,rebooting..\r\n");
-		if(ShmStatusCodeData!=NULL)
-		{
-			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed=1;
-		}
-		sleep(5);
-		system("reboot -f");
-		sleep(5);
-		system("reboot -f");
-	}
-	memset(buf, 0, MtdBlockSize);
-
-	//================================================
-	// Load configuration from mtdblock10
-	//================================================
-	fd = open("/dev/mtdblock10", O_RDWR);
-	if (fd < 0)
-	{
-		free(buf);
-		DEBUG_ERROR_MSG("open mtdblock10 NG,rebooting..\r\n");
-		if(ShmStatusCodeData!=NULL)
-		{
-			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed=1;
-		}
-		sleep(5);
-		system("reboot -f");
-		sleep(5);
-		system("reboot -f");
-	}
-
-	wrd=read(fd, buf, MtdBlockSize);
-	close(fd);
-	if(wrd<MtdBlockSize)
-	{
-		free(buf);
-		DEBUG_ERROR_MSG("read SysConfigData data NG,rebooting..\r\n");
-		if(ShmStatusCodeData!=NULL)
-		{
-			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed=1;
-		}
-		sleep(5);
-		system("reboot -f");
-		sleep(5);
-		system("reboot -f");
-	}
-	ChkSum=0;
-	for(wrd=0;wrd<MtdBlockSize-4;wrd++)
-	{
-		ChkSum+=buf[wrd];
-	}
-	memcpy(&ChkSumOrg,buf+(0x00600000-4),sizeof(ChkSumOrg));
-
-	//================================================
-	// Load configuration from mtdblock11
-	//================================================
-	if(ChkSum!=ChkSumOrg)
-	{
-		DEBUG_ERROR_MSG("Primary SysConfigData checksum NG, read backup\r\n");
-		fd = open("/dev/mtdblock11", O_RDWR);
-		if (fd < 0)
-		{
-			free(buf);
-			DEBUG_ERROR_MSG("open mtdblock11 (backup) NG,rebooting..\r\n");
-			if(ShmStatusCodeData!=NULL)
-			{
-				ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed=1;
-			}
-			sleep(5);
-			system("reboot -f");
-			sleep(5);
-			system("reboot -f");
-		}
-
-		memset(buf, 0, MtdBlockSize);
-	    wrd=read(fd, buf,MtdBlockSize);
-	    close(fd);
-		if(wrd<MtdBlockSize)
-		{
-			free(buf);
-			DEBUG_ERROR_MSG("read backup SysConfigData data NG,rebooting..\r\n");
-			if(ShmStatusCodeData!=NULL)
-			{
-				ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed=1;
-			}
-			sleep(5);
-			system("reboot -f");
-			sleep(5);
-			system("reboot -f");
-		}
-		ChkSum=0;
-		for(wrd=0;wrd<MtdBlockSize-4;wrd++)
-		{
-			ChkSum+=buf[wrd];
-		}
-		memcpy(&ChkSumOrg,buf+(0x00600000-4),sizeof(ChkSumOrg));
-
-		//================================================
-		// Load configuration from mtdblock12 (Factory default)
-		//================================================
-		if(ChkSum!=ChkSumOrg)
-		{
-			DEBUG_ERROR_MSG("backup SysConfigData checksum NG, read Factory default\r\n");
-			fd = open("/dev/mtdblock12", O_RDWR);
-			if (fd < 0)
-			{
-				free(buf);
-				DEBUG_ERROR_MSG("open mtdblock12 (Factory default) NG,rebooting..\r\n");
-				if(ShmStatusCodeData!=NULL)
-				{
-					ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed=1;
-				}
-				sleep(5);
-				system("reboot -f");
-				sleep(5);
-				system("reboot -f");
-		    }
-		    memset(buf, 0, MtdBlockSize);
-	   		wrd=read(fd, buf,MtdBlockSize);
-	    	close(fd);
-			if(wrd<MtdBlockSize)
-			{
-				free(buf);
-				DEBUG_ERROR_MSG("read factory default  SysConfigData data NG,rebooting..\r\n");
-				if(ShmStatusCodeData!=NULL)
-				{
-					ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed=1;
-				}
-				sleep(5);
-				system("reboot -f");
-				sleep(5);
-				system("reboot -f");
-			}
-			ChkSum=0;
-			for(wrd=0;wrd<MtdBlockSize-4;wrd++)
-			{
-				ChkSum+=buf[wrd];
-			}
-			memcpy(&ChkSumOrg,buf+(0x00600000-4),sizeof(ChkSumOrg));
-			if(ChkSum!=ChkSumOrg)
-			{
-				DEBUG_ERROR_MSG("factory default  SysConfigData checksum NG, restore factory default\r\n");
-				free(buf);
-				system("cd /root;./FactoryConfig -m");
-				system("sync");
-				sleep(5);
-				system("reboot -f");
-				sleep(5);
-				system("reboot -f");
-
-				return FAIL;
-			}
-		}
-	}
-
-	//load OK
-	memcpy((struct SysConfigData *)ptr,buf,sizeof(struct SysConfigData));
-	free(buf);
-	DEBUG_INFO_MSG("Load SysConfigData OK\r\n");
-	return PASS;
-}
-
-int isReachableInternet()
-{
-	int result = FAIL;
-	FILE *fp;
-	char cmd[256];
-	char buf[512];
-	//char tmp[512];
-
-	for(int idx=0;idx<ARRAY_SIZE(valid_Internet);idx++)
-	{
-		strcpy(cmd, "ping -c 1 -w 3 ");
-		strcat(cmd, valid_Internet[idx]);
-		fp = popen(cmd, "r");
-		if(fp != NULL)
-		{
-			while(fgets(buf, sizeof(buf), fp) != NULL)
-			{
-				if(strstr(buf, "transmitted") > 0)
-				{
-					//sscanf(buf, "%*s%*s%*s%*s%*s%*s%s", tmp);
-
-					if(strstr(buf,"100%") != NULL)
-					{
-
-					}
-					else
-					{
-						result = PASS;
-					}
-					//DEBUG_INFO("%s",buf);
-					//DEBUG_INFO("%s\n",tmp);
-				}
-			}
-		}
-		pclose(fp);
-	}
-
-	return result;
-}
-
-void InitEthernet()
-{
-	char tmpbuf[256];
-	// /sbin/ifconfig eth0 192.168.1.10 netmask 255.255.255.0 down
-	system("echo 1 > /sys/class/gpio/gpio110/value");//reset PHY
-	sleep(2);
-	//Init Eth0 for internet
-	memset(tmpbuf,0,256);
-	sprintf(tmpbuf,"/sbin/ifconfig eth0 %s netmask %s up",
-	ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthIpAddress,
-	ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthSubmaskAddress);
-	system(tmpbuf);
-
-	memset(tmpbuf,0,256);
-	sprintf(tmpbuf,"route add default gw %s eth0 ",
-	ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthGatewayAddress);
-	system(tmpbuf);
-	//system("ifconfig lo up");
-	//  /sbin/ifconfig eth0 192.168.1.10 netmask 255.255.255.0 up
-    //Init Eth1 for administrator tool
-	memset(tmpbuf,0,256);
-	sprintf(tmpbuf,"/sbin/ifconfig eth1 %s netmask %s up",
-	ShmSysConfigAndInfo->SysConfig.Eth1Interface.EthIpAddress,
-	ShmSysConfigAndInfo->SysConfig.Eth1Interface.EthSubmaskAddress);
-	system(tmpbuf);
-
-    //Run DHCP client if enabled
-	system("killall udhcpc");
-	system("rm -rf /etc/resolv.conf");
-	system("echo nameserver 8.8.8.8 > /etc/resolv.conf");		//Google DNS server
-	system("echo nameserver 180.76.76.76 > /etc/resolv.conf");	//Baidu DNS server
-
-	if(ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthDhcpClient == 0)
-	{
-		sprintf(tmpbuf, "/sbin/udhcpc -i eth0 -x hostname:CSU3_%s -s /root/dhcp_script/eth0.script > /dev/null &", ShmSysConfigAndInfo->SysConfig.SystemId);
-		system(tmpbuf);
-	}
-
-	//Upgrade system id to /etc/hostname
-	sprintf(tmpbuf, "echo %s > /etc/hostname", ShmSysConfigAndInfo->SysConfig.SystemId);
-	system(tmpbuf);
-
-	pid_t pid = fork();
-	uint8_t cnt_pingDNS_Fail;
-
-	if(pid == 0)
-	{
-		for(;;)
-		{
-			if(isReachableInternet() == PASS)
-			{
-				ShmSysConfigAndInfo->SysInfo.InternetConn = YES;
-				ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet= NO;
-				cnt_pingDNS_Fail = 0;
-			}
-			else
-			{
-				if(++cnt_pingDNS_Fail > 3)
-				{
-					ShmSysConfigAndInfo->SysInfo.InternetConn = NO;
-					//ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet= YES;
-				}
-			}
-
-			sleep(5);
-		}
-	}
-
-	#ifdef SystemLogMessage
-	DEBUG_INFO_MSG("[main]InitEthernet: Initial Ethernet OK");
-	#endif
-}
-
-int InitialRfidPort()
-{
-	int uartO2 = open(rfidPortName, O_RDWR);
-	struct termios tios;
-
-	if (uartO2 != FAIL)
-	{
-		ioctl (uartO2, TCGETS, &tios);
-		tios.c_cflag = B19200 | CS8 | CLOCAL | CREAD;
-		tios.c_lflag = 0;
-		tios.c_iflag = 0;
-		tios.c_oflag = 0;
-		tios.c_cc[VMIN] = 0;
-		tios.c_cc[VTIME] = (unsigned char) 1;
-		tios.c_lflag = 0;
-		tcflush(uartO2, TCIFLUSH);
-		ioctl(uartO2, TCSETS, &tios);
-	}
-
-	if (uartO2 < 0)
-	{
-		ShmStatusCodeData->AlarmCode.AlarmEvents.bits.RfidModuleCommFail = 1;
-	}
-
-	return uartO2;
-}
-
-void GetMacAddress()
-{
-	for (byte index = 0; index < 2; index++)
-	{
-		int fd;
-		struct ifreq ifr;
-		char tarEth[5];
-		char Mac[18];
-
-		sprintf(tarEth,"eth%d",index);
-		fd = socket(AF_INET, SOCK_DGRAM, 0);
-
-		ifr.ifr_addr.sa_family = AF_INET;
-		strncpy(ifr.ifr_name, tarEth, IFNAMSIZ - 1);
-
-		ioctl(fd, SIOCGIFHWADDR, &ifr);
-		close(fd);
-
-		sprintf(Mac, "%.2x:%.2x:%.2x:%.2x:%.2x:%.2x",
-				ifr.ifr_hwaddr.sa_data[0], ifr.ifr_hwaddr.sa_data[1], ifr.ifr_hwaddr.sa_data[2],
-				ifr.ifr_hwaddr.sa_data[3], ifr.ifr_hwaddr.sa_data[4], ifr.ifr_hwaddr.sa_data[5]);
-
-		if (index == 0)
-			strcpy((char *) ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthMacAddress, Mac);
-		else
-			strcpy((char *) ShmSysConfigAndInfo->SysConfig.Eth1Interface.EthMacAddress, Mac);
-	}
-}
-
-void GetFirmwareVersion()
-{
-	// Get CSU root file system version
-	sprintf((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev, fwVersion);
-
-	byte count = 0, chademo = 0, ccs = 0, gb = 0;
-	for(uint8_t idx=0;idx<3;idx++)
-	{
-		if (ShmSysConfigAndInfo->SysConfig.ModelName[7+idx] == 'J')
-		{
-			chademo++;
-			count++;
-		}
-		else  if (ShmSysConfigAndInfo->SysConfig.ModelName[7+idx] == 'G')
-		{
-			gb++;
-			count++;
-		}
-		else  if (ShmSysConfigAndInfo->SysConfig.ModelName[7+idx] == 'U' ||
-				ShmSysConfigAndInfo->SysConfig.ModelName[7+idx] == 'E')
-		{
-			ccs++;
-			count++;
-		}
-	}
-
-	if (count == 1)
-	{
-		if (chademo > 0)
-			ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[7] = '1';
-		else if (ccs > 0)
-			ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[7] = '2';
-		else if (gb > 0)
-			ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[7] = '3';
-	}
-	else
-	{
-		if (chademo > 0 && ccs > 0)
-			ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[7] = '4';
-		else if (chademo > 0 && gb > 0)
-			ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[7] = '5';
-		else if (ccs > 0 && gb > 0)
-			ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[7] = '6';
-	}
-
-	// Get network option from model name
-	switch(ShmSysConfigAndInfo->SysConfig.ModelName[10])
-	{
-		case 'B':
-		case 'U':
-			//Blue tooth
-			ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[9] = '3';
-			break;
-		case 'W':
-			// WIFI
-			ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[9] = '1';
-			break;
-		case 'T':
-			// 3G/4G
-			ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[9] = '2';
-			break;
-		default:
-			// LAN
-			ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[9] = '0';
-			break;
-	}
-	// Get rating power from model name
-	memcpy(&ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[10], &ShmSysConfigAndInfo->SysConfig.ModelName[4], 0x03);
-
-	// Get IEC or UL
-	char _buf[3] = {0};
-	memcpy(_buf, &ShmSysConfigAndInfo->SysConfig.ModelName[2], 2);
-
-	if (strcmp(_buf, "YE") == EQUAL || strcmp(_buf, "YC") == EQUAL)
-		ShmSysConfigAndInfo->SysInfo.ChargerType = _CHARGER_TYPE_IEC;
-	else if (strcmp(_buf, "WU") == EQUAL)
-		ShmSysConfigAndInfo->SysInfo.ChargerType = _CHARGER_TYPE_UL;
-}
-
-void InitialShareMemoryInfo()
-{
-	FILE *fp;
-	char cmd[512];
-	char buf[512];
-
-	sprintf((char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomApn, "Internet");
-	sprintf((char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapId, " ");
-	sprintf((char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapPwd, " ");
-
-	ShmSysConfigAndInfo->SysConfig.TotalConnectorCount = 0;
-	ShmSysConfigAndInfo->SysConfig.AcConnectorCount = 0;
-
-	ShmSysConfigAndInfo->SysInfo.FactoryConfiguration = 0;
-	ShmSysConfigAndInfo->SysInfo.InputVoltageR = 0;
-	ShmSysConfigAndInfo->SysInfo.InputVoltageS = 0;
-	ShmSysConfigAndInfo->SysInfo.InputVoltageT = 0;
-	ShmSysConfigAndInfo->SysInfo.SystemFanRotaSpeed = 0;
-	ShmSysConfigAndInfo->SysInfo.PsuFanRotaSpeed = 0;
-	ShmSysConfigAndInfo->SysInfo.AuxPower5V = 0;
-	ShmSysConfigAndInfo->SysInfo.AuxPower12V = 0;
-	ShmSysConfigAndInfo->SysInfo.AuxPower24V = 0;
-	ShmSysConfigAndInfo->SysInfo.AuxPower48V = 0;
-
-	sprintf((char *)ShmSysConfigAndInfo->SysInfo.CsuHwRev, "REV:5.0");
-	memcpy(ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev, ShmSysConfigAndInfo->SysConfig.CsuBootLoadFwRev, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.CsuBootLoadFwRev));
-
-	sprintf(cmd, "/bin/uname -r");
-	fp = popen(cmd, "r");
-	if(fp == NULL)
-		sprintf((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev, "Unknown version");
-	else
-	{
-		while(fgets(buf, sizeof(buf), fp) != NULL)
-		{
-			strcpy((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev, buf);
-		}
-	}
-
-	// 雙槍 CCS + Chademo
-	GetFirmwareVersion();
-	//sprintf((char *) ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev, fwVersion);
-	sprintf((char *) ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev, " ");
-
-	sprintf((char *) ShmSysConfigAndInfo->SysInfo.LcmHwRev, " ");
-	sprintf((char *) ShmSysConfigAndInfo->SysInfo.LcmFwRev, " ");
-	sprintf((char *) ShmSysConfigAndInfo->SysInfo.PsuHwRev, " ");
-	sprintf((char *) ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev, " ");
-	sprintf((char *) ShmSysConfigAndInfo->SysInfo.PsuSecFwRev, " ");
-	sprintf((char *) ShmSysConfigAndInfo->SysInfo.AuxPwrHwRev, " ");
-	sprintf((char *) ShmSysConfigAndInfo->SysInfo.AuxPwrFwRev, " ");
-	sprintf((char *) ShmSysConfigAndInfo->SysInfo.FanModuleHwRev, " ");
-	sprintf((char *) ShmSysConfigAndInfo->SysInfo.FanModuleFwRev, " ");
-	sprintf((char *) ShmSysConfigAndInfo->SysInfo.RelayModuleHwRev, " ");
-	sprintf((char *) ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev, " ");
-	sprintf((char *) ShmSysConfigAndInfo->SysInfo.TelcomModemFwRev, " ");
-	ShmSysConfigAndInfo->SysInfo.SystemAmbientTemp = 0;
-	ShmSysConfigAndInfo->SysInfo.SystemCriticalTemp = 0;
-	ShmSysConfigAndInfo->SysInfo.PsuAmbientTemp = 0;
-	ShmSysConfigAndInfo->SysInfo.CcsConnectorTemp = 0;
-	ShmSysConfigAndInfo->SysInfo.InternetConn = 0;
-	ShmSysConfigAndInfo->SysInfo.OcppConnStatus = 0;
-	ShmSysConfigAndInfo->SysInfo.OrderCharging = NO_DEFINE;
-
-	strcpy((char *) ShmSysConfigAndInfo->SysConfig.UserId, "");
-
-	ShmStatusCodeData->AlarmCode.AlarmEvents.bits.RelayboardStestFail = NO;
-	ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FanboardStestFail = NO;
-	ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PrimaryStestFail = NO;
-	ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoboardStestFail = NO;
-	ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CCSboardStestFail = NO;
-	ShmStatusCodeData->AlarmCode.AlarmEvents.bits.AcContactStestFail = NO;
-	ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuModuleStestFail = NO;
-
-	memset(ShmSysConfigAndInfo->SysInfo.FanModuleFwRev, 0, ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
-	memset(ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev, 0, ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
-	ShmPrimaryMcuData->SelfTest_Comp = NO;
-	ShmRelayModuleData->SelfTest_Comp = NO;
-	ShmFanModuleData->SelfTest_Comp = NO;
-	ShmLedModuleData->SelfTest_Comp = NO;
-	ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
-	ShmSysConfigAndInfo->SysInfo.MainChargingMode = _MAIN_CHARGING_MODE_MAX;
-	ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_NONE;
-	ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc = NO_DEFINE;
-
-	ShmFanModuleData->TestFanSpeed = 0;
-
-	ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ModelNameNoneMatchStestFail = NO;
-	ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuNoResource = NO;
-
-	char EvsePower[2];
-
-	EvsePower[2] = '\0';
-	unsigned short buf_pow = 0;
-	if (strlen((char *) ShmSysConfigAndInfo->SysConfig.ModelName) >= 6)
-	{
-		strncpy(EvsePower, (char *)(ShmSysConfigAndInfo->SysConfig.ModelName + 4), 2);
-		if (strcmp(EvsePower, "15") == EQUAL)
-			buf_pow = 150;
-		else if (strcmp(EvsePower, "30") == EQUAL)
-			buf_pow = 30;
-		else if (strcmp(EvsePower, "60") == EQUAL)
-			buf_pow = 60;
-		else if (strcmp(EvsePower, "18") == EQUAL)
-			buf_pow = 180;
-		else if (strcmp(EvsePower, "36") == EQUAL)
-			buf_pow = 360;
-
-		ShmSysConfigAndInfo->SysConfig.RatingCurrent = (buf_pow / 30) * PSU_MIN_CUR;
-
-		if(ShmSysConfigAndInfo->SysConfig.MaxChargingPower == 0 ||
-				ShmSysConfigAndInfo->SysConfig.MaxChargingPower > buf_pow)
-			ShmSysConfigAndInfo->SysConfig.MaxChargingPower = buf_pow;
-	}
-	ShmSysConfigAndInfo->SysConfig.SwitchDebugFlag = NO;
-	ShmSysConfigAndInfo->SysConfig.AlwaysGfdFlag = NO;
-}
-
-int Initialization()
-{
-	// 初始化卡號驗證的 Flag
-	ClearAuthorizedFlag();
-	// 初始化插槍驗證的 Flag
-	ClearDetectPluginFlag();
-
-	// UART 2 for Rfid
-	rfidFd = InitialRfidPort();
-
-	int pinOut[2] = { 115, 116 };
-	for (byte count = 0; count < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; count++)
-	{
-		chargingInfo[count]->RemoteStartFlag = NO;
-
-		if (chargingInfo[count]->Type == _Type_Chademo)
-		{
-			gpio_set_value(pinOut[count], 0x01);
-			ShmCHAdeMOData->evse[chargingInfo[count]->type_index].SelfTest_Comp = NO;
-		}
-		else if (chargingInfo[count]->Type == _Type_GB)
-		{
-			gpio_set_value(pinOut[count], 0x01);
-			ShmGBTData->evse[chargingInfo[count]->type_index].SelfTest_Comp = NO;
-		}
-		else if (chargingInfo[count]->Type == _Type_CCS_2)
-		{
-			if (ShmCcsData->CommProtocol == 0x01)
-			{
-				if (ShmSysConfigAndInfo->SysConfig.TotalConnectorCount == 1)
-					gpio_set_value(pinOut[1], 0x00);
-				else
-					gpio_set_value(pinOut[count], 0x00);
-				ShmCcsData->V2GMessage_DIN70121[chargingInfo[count]->type_index].SelfTest_Comp = NO;
-			}
-		}
-
-		strcpy((char *)ShmOCPP16Data->StatusNotification[count].ErrorCode, "NoError");
-	}
-
-	for (byte count = 0; count < ShmSysConfigAndInfo->SysConfig.AcConnectorCount; count++)
-	{
-		ac_chargingInfo[count]->RemoteStartFlag = NO;
-
-		if (ac_chargingInfo[count]->Type == _Type_AC)
-		{
-			ac_chargingInfo[count]->SelfTest_Comp = NO;
-			strcpy((char *)ShmOCPP16Data->StatusNotification[count + ShmSysConfigAndInfo->SysConfig.TotalConnectorCount].ErrorCode, "NoError");
-		}
-	}
-
-	PRINTF_FUNC("Initialization OK \n");
-	return PASS;
-}
-
-bool InitialSystemDefaultConfig()
-{
-	bool result = true;
-
-	LoadSysConfigAndInfo(&ShmSysConfigAndInfo->SysConfig);
-	InitGPIO();
-	InitEthernet();
-	GetMacAddress();
-
-//	system("echo 1 > /sys/class/gpio/gpio110/value"); //reset PHY
-//	sleep(3);
-//	system("/sbin/ifconfig eth0 192.168.1.10 netmask 255.255.255.0 down");
-//	sleep(1);
-//	system("/sbin/ifconfig eth1 192.168.0.10 netmask 255.255.255.0 up");
-
-	return result;
-}
-
-void DisplaySelfTestFailReason()
-{
-	// RB、FB、407、EV 小板中有些板子無回應
-	if (ShmRelayModuleData->SelfTest_Comp == NO)
-	{ ShmStatusCodeData->AlarmCode.AlarmEvents.bits.RelayboardStestFail = YES; }
-	if (ShmFanModuleData->SelfTest_Comp == NO)
-	{ ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FanboardStestFail = YES; }
-	if (ShmPrimaryMcuData->SelfTest_Comp == NO)
-	{ ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PrimaryStestFail = YES; }
-//	if (ShmLedModuleData->SelfTest_Comp == NO)
-//	{ ShmStatusCodeData->AlarmCode.AlarmEvents.bits.LedboardStestFail = YES; }
-	for (byte index = 0; index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; index++)
-	{
-		if (chargingInfo[index]->Type == _Type_Chademo)
-		{
-			if (ShmCHAdeMOData->evse[chargingInfo[index]->type_index].SelfTest_Comp == NO)
-			{ ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoboardStestFail = YES; }
-		}
-		else if (chargingInfo[index]->Type == _Type_GB)
-		{
-			if (ShmGBTData->evse[chargingInfo[index]->type_index].SelfTest_Comp == NO)
-			{ ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbtboardStestFail = YES; }
-		}
-		else if (chargingInfo[index]->Type == _Type_CCS_2)
-		{
-			if (ShmCcsData->CommProtocol == 0x01)
-			{
-				if (ShmCcsData->V2GMessage_DIN70121[chargingInfo[index]->type_index].SelfTest_Comp == NO)
-				{ ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CCSboardStestFail = YES; }
-			}
-		}
-	}
-	for (byte index = 0; index < ShmSysConfigAndInfo->SysConfig.AcConnectorCount; index++)
-	{
-		// 先借 GBT 顯示
-		if (ac_chargingInfo[index]->SelfTest_Comp == NO)
-		{ ShmStatusCodeData->AlarmCode.AlarmEvents.bits.AcConnectorStestFail = YES; }
-	}
-
-	if (ShmSysConfigAndInfo->SysInfo.AcContactorStatus == NO)
-	{
-		// AC Contact 未搭上
-		ShmStatusCodeData->AlarmCode.AlarmEvents.bits.AcContactStestFail = YES;
-	}
-	else if (ShmPsuData->SystemAvailablePower <= 0 && ShmPsuData->SystemAvailableCurrent <= 0)
-	{
-		// PSU 通訊問題
-		ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuModuleStestFail = YES;
-	}
-}
-
-void SelfTestRun()
-{
-	bool evInitFlag = false;
-
-	StartSystemTimeoutDet(Timeout_SelftestChk);
-	ShmSysConfigAndInfo->SysInfo.SelfTestSeq = _STEST_VERSION;
-	while (ShmSysConfigAndInfo->SysInfo.SelfTestSeq != _STEST_COMPLETE)
-	{
-		ChkPrimaryStatus();
-		if (ShmSysConfigAndInfo->SysWarningInfo.Level == 2)
-		{
-			ShmSysConfigAndInfo->SysInfo.SelfTestSeq = _STEST_FAIL;
-			return;
-		}
-
-		if (ShmSysConfigAndInfo->SysConfig.TotalConnectorCount > 0)
-		{
-			if (ShmPsuData->Work_Step == _NO_WORKING ||
-					ShmSysConfigAndInfo->SysInfo.SelfTestSeq == _STEST_FAIL)
-			{
-				ShmSysConfigAndInfo->SysInfo.SelfTestSeq = _STEST_FAIL;
-				return;
-			}
-
-			switch(ShmSysConfigAndInfo->SysInfo.SelfTestSeq)
-			{
-				case _STEST_VERSION:
-				{
-					if (strlen((char *)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev) != 0 ||
-							ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev[0] != '\0')
-					{
-						//PRINTF_FUNC("RB pass \n");
-						ShmRelayModuleData->SelfTest_Comp = YES;
-					}
-
-					if  (strlen((char *)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev) != 0 ||
-							ShmSysConfigAndInfo->SysInfo.FanModuleFwRev[0] != '\0')
-					{
-						//PRINTF_FUNC("Fan pass \n");
-						ShmFanModuleData->SelfTest_Comp = YES;
-					}
-
-					if (strlen((char *)ShmPrimaryMcuData->version) != 0 ||
-							ShmPrimaryMcuData->version[0] != '\0')
-					{
-						//PRINTF_FUNC("407 pass \n");
-						ShmPrimaryMcuData->SelfTest_Comp = YES;
-					}
-					// EV 小板
-					if (!evInitFlag)
-					{
-						evInitFlag = YES;
-						for (byte index = 0; index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; index++)
-						{
-							if (chargingInfo[index]->Type == _Type_Chademo)
-							{
-								if (strlen((char *)ShmCHAdeMOData->evse[chargingInfo[index]->type_index].version) != 0 ||
-										ShmCHAdeMOData->evse[chargingInfo[index]->type_index].version[0] != '\0')
-								{
-									//PRINTF_FUNC("chademo pass \n");
-									ShmCHAdeMOData->evse[chargingInfo[index]->type_index].SelfTest_Comp = YES;
-								}
-								else
-								{
-									//PRINTF_FUNC("chademo fw lose...... %s \n", ShmCHAdeMOData->evse[chargingInfo[index]->type_index].version);
-									evInitFlag = NO;
-								}
-							}
-							else if (chargingInfo[index]->Type == _Type_GB)
-							{
-								if (strlen((char *)ShmGBTData->evse[chargingInfo[index]->type_index].version) != 0 ||
-										ShmGBTData->evse[chargingInfo[index]->type_index].version[0] != '\0')
-								{
-									//PRINTF_FUNC("GBT pass \n");
-									ShmGBTData->evse[chargingInfo[index]->type_index].SelfTest_Comp = YES;
-								}
-								else
-								{
-									//PRINTF_FUNC("GBT fw lose...... %s \n", ShmCHAdeMOData->evse[chargingInfo[index]->type_index].version);
-									evInitFlag = NO;
-								}
-							}
-							else if (chargingInfo[index]->Type == _Type_CCS_2)
-							{
-								if (ShmCcsData->CommProtocol == 0x01)
-								{
-									if (strlen((char *)ShmCcsData->V2GMessage_DIN70121[chargingInfo[index]->type_index].version) != 0 ||
-										ShmCcsData->V2GMessage_DIN70121[chargingInfo[index]->type_index].version[0] != '\0')
-									{
-										//PRINTF_FUNC("ccs fw =  %s \n", ShmCcsData->V2GMessage_DIN70121[chargingInfo[index]->type_index].version);
-										ShmCcsData->V2GMessage_DIN70121[chargingInfo[index]->type_index].SelfTest_Comp = YES;
-									}
-									else
-									{
-										//PRINTF_FUNC("ccs fw lose...... %s \n", ShmCcsData->V2GMessage_DIN70121[chargingInfo[index]->type_index].version);
-										evInitFlag = NO;
-									}
-								}
-							}
-						}
-
-						for (byte index = 0; index < ShmSysConfigAndInfo->SysConfig.AcConnectorCount; index++)
-						{
-							if (ac_chargingInfo[index]->Type == _Type_AC)
-							{
-								if (strlen((char *)ac_chargingInfo[index]->version) != 0 ||
-										ac_chargingInfo[index]->version[0] != '\0')
-								{
-									ac_chargingInfo[index]->SelfTest_Comp = YES;
-								}
-								else
-								{
-									evInitFlag = NO;
-								}
-							}
-						}
-					}
-
-					if (ShmFanModuleData->SelfTest_Comp &&
-							ShmRelayModuleData->SelfTest_Comp &&
-							ShmPrimaryMcuData->SelfTest_Comp &&
-							evInitFlag)
-					{
-						ShmSysConfigAndInfo->SysInfo.SelfTestSeq = _STEST_AC_CONTACTOR;
-					}
-				}
-					break;
-				case _STEST_AC_CONTACTOR:
-				{
-					//ShmPsuData->Work_Step = _TEST_COMPLETE;
-					// 因為 30KW 以下沒有 Relay feedback 功能,所以暫時先直接跳過
-					if (ShmSysConfigAndInfo->SysInfo.AcContactorStatus == YES)
-					{
-						ShmSysConfigAndInfo->SysInfo.SelfTestSeq = _STEST_PSU_DETECT;
-						PRINTF_FUNC("Communication board pass. \n");
-					}
-				}
-					break;
-				case _STEST_PSU_DETECT:
-				{
-					if (ShmPsuData->Work_Step >= GET_SYS_CAP)
-					{
-						ShmSysConfigAndInfo->SysInfo.SelfTestSeq = _STEST_PSU_CAP;
-					}
-				}
-					break;
-				case _STEST_PSU_CAP:
-				{
-					// 此測試是要確認當前總輸出能力
-					// 如果沒有 PSU 模組請 bypass
-					if (ShmPsuData->Work_Step == BOOTING_COMPLETE)
-					{
-						sleep(1);
-						ShmSysConfigAndInfo->SysInfo.SelfTestSeq = _STEST_COMPLETE;
-						ShmSysConfigAndInfo->SysInfo.BootingStatus = BOOT_COMPLETE;
-					}
-				}
-					break;
-			}
-		}
-		else
-			break;
-
-		usleep(100000);
-	}
-}
-
-int SpawnTask()
-{
-	sleep(2);
-	system("/root/Module_EventLogging &");
-	system("/root/Module_PrimaryComm &");
-	system("/root/Module_EvComm &");
-	system("/root/Module_LcmControl &");
-	system("/root/Module_InternalComm &");
-	system("/root/Module_PsuComm &");
-	system("/root/Module_ProduceUtils &");
-
-	if(strcmp((char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, "") != EQUAL &&
-		strcmp((char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId, "") != EQUAL)
-	{
-		system("/root/OcppBackend &");
-	}
-
-	if(ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'T')
-	{
-		system("/root/Module_4g &");
-	}
-
-	if(ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'W')
-	{
-		system("/root/Module_Wifi &");
-	}
-
-	return PASS;
-}
-
-int StoreUsrConfigData(struct SysConfigData *UsrData)
-{
-	int result = PASS;
-	int fd,wrd;
-	unsigned int i,Chk;
-	unsigned char *ptr, *BufTmp;
-
-	Chk=0;
-	ptr=(unsigned char *)UsrData;
-	if((BufTmp = malloc(MtdBlockSize)) != NULL)
-	{
-		memset(BufTmp, 0, MtdBlockSize);
-		memcpy(BufTmp, ptr, sizeof(struct SysConfigData));
-		for(i=0; i<MtdBlockSize-4; i++)
-			Chk+=*(ptr+i);
-
-		memcpy(BufTmp + MtdBlockSize-4, &Chk, 4);
-		fd = open("/dev/mtdblock10", O_RDWR);
-		if (fd > 0)
-		{
-			wrd=write(fd, BufTmp, MtdBlockSize);
-			close(fd);
-			if(wrd >= MtdBlockSize)
-			{
-				fd = open("/dev/mtdblock11", O_RDWR);
-				if (fd > 0)
-				{
-					wrd=write(fd, BufTmp, MtdBlockSize);
-	    			close(fd);
-					if(wrd < MtdBlockSize)
-					{
-						DEBUG_ERROR_MSG("write /dev/mtdblock11(backup) NG\r\n");
-					   	result = FAIL;
-					}
-				}
-				else
-				{
-					DEBUG_ERROR_MSG("open /dev/mtdblock11(backup) NG\r\n");
-					result = FAIL;
-				}
-			}
-			else
-			{
-				DEBUG_ERROR_MSG("write /dev/mtdblock10 NG\r\n");
-			    result = FAIL;
-			}
-
-		}
-		else
-		{
-			DEBUG_ERROR_MSG("open /dev/mtdblock10 NG\r\n");
-			result = FAIL;
-		}
-	}
-	else
-	{
-		DEBUG_ERROR_MSG("alloc BlockSize NG\r\n");
-	    result = FAIL;
-	}
-
-	if(BufTmp != NULL)
-		free(BufTmp);
-
-	return result;
-}
-
-//===============================================
-// Common Detect Chk - Stop Charging ?
-//===============================================
-bool isEvBoardStopChargeFlag(byte gunIndex)
-{
-	return chargingInfo[gunIndex]->StopChargeFlag;
-}
-
-//===============================================
-// 掃描插槍狀況
-//===============================================
-void ClearDetectPluginFlag()
-{
-	ShmSysConfigAndInfo->SysInfo.WaitForPlugit = NO;
-}
-
-void DetectPluginStart()
-{
-	ShmSysConfigAndInfo->SysInfo.WaitForPlugit = YES;
-}
-
-bool isDetectPlugin()
-{
-	if(ShmSysConfigAndInfo->SysInfo.WaitForPlugit == YES)
-		return YES;
-
-	return NO;
-}
-
-//===============================================
-// Common Detect Chk - Chademo
-//===============================================
-bool isEvGunLocked_chademo(byte gunIndex)
-{
-	return (DetectBitValue(chargingInfo[gunIndex]->GunLocked , 0) == 0)? NO : YES;
-}
-
-bool isEvContactorWelding_chademo(byte gunIndex)
-{
-	return DetectBitValue(ShmCHAdeMOData->ev[chargingInfo[gunIndex]->type_index].EvDetection, 3);
-}
-
-bool isEvStopReq_chademo(byte gunIndex)
-{
-	return DetectBitValue(ShmCHAdeMOData->ev[chargingInfo[gunIndex]->type_index].EvDetection, 4);
-}
-
-bool isEvStopCharging_chademo(byte gunIndex)
-{
-	if (isEvGunLocked_chademo(gunIndex) == NO)
-	{
-		// 無鎖槍 = 停止
-		PRINTF_FUNC("gun locked none (%d) \n", gunIndex);
-		return YES;
-	}
-
-	return NO;
-}
-
-byte isPrechargeStatus_chademo(byte gunIndex)
-{
-	byte result = 0x00;
-
-	result = ShmCHAdeMOData->ev[chargingInfo[gunIndex]->type_index].PresentMsgFlowStatus;
-
-	return result;
-}
-//===============================================
-// Common Detect Chk - GB
-//===============================================
-bool isEvGunLocked_gb(byte gunIndex)
-{
-	return (DetectBitValue(chargingInfo[gunIndex]->GunLocked , 0) == 0)? NO : YES;
-}
-
-bool isEvStopCharging_gb(byte gunIndex)
-{
-	if (isEvGunLocked_gb(gunIndex) == NO)
-	{
-		// 無鎖槍 = 停止
-		PRINTF_FUNC("gun locked none. \n");
-		return YES;
-	}
-
-	return NO;
-}
-
-byte isPrechargeStatus_gb(byte gunIndex)
-{
-	byte result = 0x00;
-
-	result = ShmGBTData->ev[chargingInfo[gunIndex]->type_index].PresentMsgFlowStatus;
-
-	return result;
-}
-
-//===============================================
-// Common Detect Chk - CCS
-//===============================================
-bool isEvGunLocked_ccs(byte gunIndex)
-{
-	return (DetectBitValue(chargingInfo[gunIndex]->GunLocked , 0) == 0)? NO : YES;
-}
-
-byte isPrechargeStatus_ccs(byte gunIndex)
-{
-	byte result = 0x00;
-
-	if (ShmCcsData->CommProtocol == 0x01)
-	{
-		result = ShmCcsData->V2GMessage_DIN70121[chargingInfo[gunIndex]->type_index].PresentMsgFlowStatus;
-	}
-
-	return result;
-}
-
-bool isEvStopCharging_ccs(byte gunIndex)
-{
-	if (isEvGunLocked_ccs(gunIndex) == NO)
-	{
-		// 無鎖槍 = 停止
-		PRINTF_FUNC("gun locked none. \n");
-		return YES;
-	}
-
-	return NO;
-}
-
-//===============================================
-// Callback
-//===============================================
-void DisplayChargingInfo()
-{
-	PRINTF_FUNC("*********** DisplayChargingInfo *********** \n");
-	for (byte i = 0; i < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; i++)
-	{
-		if (chargingInfo[i]->SystemStatus != S_IDLE &&
-				chargingInfo[i]->SystemStatus != S_RESERVATION)
-		{
-			ChangeGunSelectByIndex(i);
-			return;
-		}
-	}
-
-	if (ShmSysConfigAndInfo->SysConfig.AcConnectorCount > 0 &&
-		ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc == NO_DEFINE &&
-		ac_chargingInfo[0]->SystemStatus >= S_PREPARNING && ac_chargingInfo[0]->SystemStatus <= S_COMPLETE)
-	{
-		ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc = DEFAULT_AC_INDEX;
-	}
-
-	usleep(50000);
-	ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
-}
-
-void _AutoReturnTimeout()
-{
-	PRINTF_FUNC("*********** _AutoReturnTimeout %d*********** \n", ShmSysConfigAndInfo->SysInfo.PageIndex);
-	if (ShmSysConfigAndInfo->SysInfo.PageIndex == _LCM_WAIT_FOR_PLUG)
-	{
-		ClearDetectPluginFlag();
-	}
-	else if (ShmSysConfigAndInfo->SysInfo.PageIndex == _LCM_AUTHORIZ_COMP)
-	{
-		DetectPluginStart();
-	}
-	usleep(50000);
-	ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
-}
-
-void _SelfTestTimeout()
-{
-	if (ShmSysConfigAndInfo->SysInfo.BootingStatus != BOOT_COMPLETE)
-	{
-		for (byte gun_index = 0; gun_index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gun_index++)
-		{
-			setChargerMode(gun_index, MODE_ALARM);
-		}
-	}
-	ShmPsuData->Work_Step = _NO_WORKING;
-	ShmSysConfigAndInfo->SysInfo.SelfTestSeq = _STEST_FAIL;
-	PRINTF_FUNC("Self test timeout. \n");
-}
-
-void _AuthorizedTimeout()
-{
-	if(IsAuthorizingMode())
-	{
-		PRINTF_FUNC("*********** _AuthorizedTimeout *********** \n");
-		isCardScan = false;
-		ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_AUTHORIZ_FAIL;
-		//ChangeLcmByIndex(_LCM_AUTHORIZ_FAIL);
-		strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
-		ClearAuthorizedFlag();
-	}
-}
-
-void _DetectPlugInTimeout()
-{
-	PRINTF_FUNC("*********** _DetectPlugInTimeout *********** \n");
-	strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
-	ClearDetectPluginFlag();
-	usleep(50000);
-	ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
-}
-
-void _DetectEvChargingEnableTimeout(byte gunIndex)
-{
-	if (chargingInfo[gunIndex]->Type == _Type_Chademo)
-	{
-		if(!isEvGunLocked_chademo(gunIndex))
-		{
-			PRINTF_FUNC("*********** _DetectEvChargingEnableTimeout (chademo) ***********\n");
-		}
-	}
-	else if (chargingInfo[gunIndex]->Type == _Type_GB)
-	{
-		if(!isEvGunLocked_ccs(gunIndex))
-		{
-			PRINTF_FUNC("*********** _DetectEvChargingEnableTimeout (gb) ***********\n");
-		}
-	}
-	else if (chargingInfo[gunIndex]->Type == _Type_CCS_2)
-	{
-		if(!isEvGunLocked_ccs(gunIndex))
-		{
-			PRINTF_FUNC("*********** _DetectEvChargingEnableTimeout (ccs) ***********\n");
-		}
-	}
-	ChargingTerminalProcess(gunIndex);
-	_AutoReturnTimeout();
-}
-
-void _DetectEvseChargingEnableTimeout(byte gunIndex)
-{
-	PRINTF_FUNC("*********** _DetectEvseChargingEnableTimeout (GFD timeout) ***********\n");
-	//if (chargingInfo[gunIndex]->GroundFaultStatus != GFD_PASS)
-	{
-		setChargerMode(gunIndex, MODE_IDLE);
-		_AutoReturnTimeout();
-	}
-}
-
-void _PrepareTimeout(byte gunIndex)
-{
-	PRINTF_FUNC("*********** _PrepareTimeout ***********\n");
-	setChargerMode(gunIndex, MODE_IDLE);
-	ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuNoResource = YES;
-	_AutoReturnTimeout();
-}
-
-void _CcsPrechargeTimeout(byte gunIndex)
-{
-	PRINTF_FUNC("*********** _CcsPrechargeTimeout ***********\n");
-	setChargerMode(gunIndex, MODE_IDLE);
-}
-
-//===============================================
-// 取得卡號與卡號驗證
-//===============================================
-bool canStartCharging()
-{
-	char buf2[16] = "";
-	memset(buf2, 0, ARRAY_SIZE(buf2));
-
-	for (byte index = 0; index < strlen((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status); index++)
-	{
-		sprintf(buf2 + (index - 1) * 2, "%02X",	ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status[index]);
-	}
-	sprintf(buf2, "%s",	ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
-
-	// 因為無法得知實際的長度,所以只能用搜尋的方式
-	if(strcmp(buf2, "Accepted") == EQUAL)
-		return true;
-	else
-	{
-
-	}
-
-	return false;
-}
-
-void AuthorizingStart()
-{
-	ShmOCPP16Data->SpMsg.bits.AuthorizeReq = YES;
-	ShmSysConfigAndInfo->SysInfo.AuthorizeFlag = YES;
-}
-
-void ClearAuthorizedFlag()
-{
-	ShmOCPP16Data->SpMsg.bits.AuthorizeConf = NO;
-	ShmSysConfigAndInfo->SysInfo.AuthorizeFlag = NO;
-}
-
-bool isAuthorizedComplete()
-{
-	if (ShmOCPP16Data->SpMsg.bits.AuthorizeConf == NO)
-		return false;
-
-	return true;
-}
-
-bool IsAuthorizingMode()
-{
-	if(ShmSysConfigAndInfo->SysInfo.AuthorizeFlag == NO)
-		return false;
-
-	return true;
-}
-
-//===============================================
-// 紀錄 Alarm Code
-//===============================================
-void RecordAlarmCode(byte gunIndex, char *code)
-{
-	memcpy(chargingInfo[gunIndex]->ConnectorAlarmCode, code, 6);
-
-	if (strcmp(code, "012234") == EQUAL) ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoGfdTrip = YES;
-	if (strcmp(code, "012235") == EQUAL) ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsGfdTrip = YES;
-	if (strcmp(code, "012236") == EQUAL) ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbGfdTrip = YES;
-	if (strcmp(code, "012288") == EQUAL) ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsOutputUVPFail = YES;
-	if (strcmp(code, "012289") == EQUAL) ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoOutputUVPFail = YES;
-	if (strcmp(code, "012290") == EQUAL) ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbtOutputUVPFail = YES;
-}
-
-void RecordWarningCode(byte gunIndex, char *code)
-{
-	memcpy(chargingInfo[gunIndex]->ConnectorWarningCode, code, 6);
-
-	if (strcmp(code, "012296") == EQUAL) ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoGroundWarning = YES;
-	if (strcmp(code, "012297") == EQUAL) ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsGroundfaultWarning = YES;
-	if (strcmp(code, "012298") == EQUAL) ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbGroundfaultWarning = YES;
-}
-
-void ReleaseAlarmCode(byte gunIndex)
-{
-	bool isCleanCheck = false;
-	char code[7];
-
-	if (chargingInfo[gunIndex]->Type == _Type_Chademo)
-	{
-		if (strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012234", 6) == EQUAL &&
-			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoGfdTrip == YES)
-		{
-			memcpy(code, "012234", 6);
-			memcpy(chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6);
-			isCleanCheck = true;
-		}
-		else if (strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012289", 6) == EQUAL &&
-				ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoOutputUVPFail == YES)
-		{
-			memcpy(code, "012289", 6);
-			memcpy(chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6);
-			isCleanCheck = true;
-		}
-		else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoGroundWarning == YES)
-		{
-			ReleaseWarningCodeByString(gunIndex, "012296");
-		}
-	}
-	else if (chargingInfo[gunIndex]->Type == _Type_GB)
-	{
-		if (strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012236", 6) == EQUAL &&
-			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbGfdTrip == YES)
-		{
-			memcpy(code, "012236", 6);
-			memcpy(chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6);
-			isCleanCheck = true;
-		}
-		else if (strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012290", 6) == EQUAL &&
-				ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbtOutputUVPFail == YES)
-		{
-			memcpy(code, "012290", 6);
-			memcpy(chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6);
-			isCleanCheck = true;
-		}
-		else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbGroundfaultWarning == YES)
-		{
-			ReleaseWarningCodeByString(gunIndex, "012298");
-		}
-	}
-	else if (chargingInfo[gunIndex]->Type == _Type_CCS_2)
-	{
-		if (strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012235", 6) == EQUAL &&
-			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsGfdTrip == YES)
-		{
-			memcpy(code, "012235", 6);
-			memcpy(chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6);
-			isCleanCheck = true;
-		}
-		else if (strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012288", 6) == EQUAL &&
-				ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsOutputUVPFail == YES)
-		{
-			memcpy(code, "012288", 6);
-			memcpy(chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6);
-			isCleanCheck = true;
-		}
-		else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsGroundfaultWarning == YES)
-		{
-			ReleaseWarningCodeByString(gunIndex, "012297");
-		}
-	}
-
-	if (isCleanCheck)
-	{
-		for (byte index = 0; index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; index++)
-		{
-			if (index != gunIndex || ShmSysConfigAndInfo->SysConfig.TotalConnectorCount == 1)
-			{
-				if (strncmp((char *)chargingInfo[index]->ConnectorAlarmCode, code, 6) != EQUAL)
-				{
-					if (strncmp(code, "012234", 6) == EQUAL) ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoGfdTrip = NO;
-					if (strncmp(code, "012289", 6) == EQUAL) ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoOutputUVPFail = NO;
-
-					if (strncmp(code, "012236", 6) == EQUAL) ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbGfdTrip = NO;
-					if (strncmp(code, "012290", 6) == EQUAL) ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbtOutputUVPFail = NO;
-
-					if (strncmp(code, "012235", 6) == EQUAL) ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsGfdTrip = NO;
-					if (strncmp(code, "012288", 6) == EQUAL) ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsOutputUVPFail = NO;
-				}
-			}
-		}
-	}
-}
-
-void ReleaseWarningCodeByString(byte gunIndex, char *code)
-{
-	bool isCleanCheck = false;
-
-	if (strncmp((char *)chargingInfo[gunIndex]->ConnectorWarningCode, code, 6) == EQUAL &&
-			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoGroundWarning == YES)
-	{
-		memcpy(chargingInfo[gunIndex]->ConnectorWarningCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)chargingInfo[gunIndex]->ConnectorWarningCode, code, 6) == EQUAL &&
-			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsGroundfaultWarning == YES)
-	{
-		memcpy(chargingInfo[gunIndex]->ConnectorWarningCode, "", 6);
-		isCleanCheck = true;
-	}
-	else if (strncmp((char *)chargingInfo[gunIndex]->ConnectorWarningCode, code, 6) == EQUAL &&
-			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbGroundfaultWarning == YES)
-	{
-		memcpy(chargingInfo[gunIndex]->ConnectorWarningCode, "", 6);
-		isCleanCheck = true;
-	}
-
-	if (isCleanCheck)
-	{
-		for (byte index = 0; index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; index++)
-		{
-			if (index != gunIndex || ShmSysConfigAndInfo->SysConfig.TotalConnectorCount == 1)
-			{
-				if (strncmp((char *)chargingInfo[index]->ConnectorWarningCode, code, 6) != EQUAL)
-				{
-					if (strncmp(code, "012296", 6) == EQUAL) ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoGroundWarning = NO;
-					if (strncmp(code, "012297", 6) == EQUAL) ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsGroundfaultWarning = NO;
-					if (strncmp(code, "012298", 6) == EQUAL) ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbGroundfaultWarning = NO;
-				}
-			}
-		}
-	}
-}
-//===============================================
-// EmergencyStop and Charging Stop
-//===============================================
-void ChargingTerminalProcess(byte gunIndex)
-{
-	setChargerMode(gunIndex, MODE_TERMINATING);
-}
-
-void AcChargingTerminalProcess()
-{
-	ac_chargingInfo[0]->SystemStatus = MODE_TERMINATING;
-}
-
-void StopChargingProcessByString(byte level)
-{
-	if (level > ShmSysConfigAndInfo->SysWarningInfo.Level)
-	{
-		ShmSysConfigAndInfo->SysWarningInfo.Level = level;
-	}
-}
-
-void ReleaseChargingProcessByString(byte level)
-{
-	if (level >= ShmSysConfigAndInfo->SysWarningInfo.Level)
-		ShmSysConfigAndInfo->SysWarningInfo.Level = 0;
-}
-
-// 一般錯誤停止充電處理函式
-void BoardErrOccurByString(byte index, char *code)
-{
-	byte level = 1;
-	if ((chargingInfo[index]->SystemStatus > S_IDLE && chargingInfo[index]->SystemStatus < S_TERMINATING) ||
-			(chargingInfo[index]->SystemStatus >= S_CCS_PRECHARGE_ST0 && chargingInfo[index]->SystemStatus <= S_CCS_PRECHARGE_ST1))
-	{
-		if (strncmp(code, "023730", 6) == EQUAL && ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoChargerGetEmergencyStop == NO)
-		{
-			ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoChargerGetEmergencyStop = YES;
-		}
-		ChargingTerminalProcess(index);
-	}
-
-	StopChargingProcessByString(level);
-}
-
-// 急停狀況的停止充電處理函式
-void EmcOccureByString(char *code)
-{
-	byte level = 2;
-	// 嚴重的急停有四種 : EMC 按鈕、Mainbreak、Dooropen、SPD Trip
-	// 其錯誤等級為 2
-	if (strncmp(code, "012251", 6) == EQUAL || strncmp(code, "012252", 6) == EQUAL ||
-			strncmp(code, "012237", 6) == EQUAL || strncmp(code, "012238", 6) == EQUAL)
-	{
-		for (byte gun = 0; gun < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gun++)
-		{
-			if ((chargingInfo[gun]->SystemStatus > S_IDLE && chargingInfo[gun]->SystemStatus < S_TERMINATING) ||
-					(chargingInfo[gun]->SystemStatus >= S_CCS_PRECHARGE_ST0 && chargingInfo[gun]->SystemStatus <= S_CCS_PRECHARGE_ST1))
-			{
-				ChargingTerminalProcess(gun);
-			}
-
-			StopChargingProcessByString(level);
-		}
-	}
-}
-
-void ReleaseBoardErrOccurByString(byte index, char *code)
-{
-	bool isTrigger = false;
-	byte level = 1;
-
-	if (strncmp(code, "023730", 6) == 0 && ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoChargerGetEmergencyStop == YES)
-	{
-		isTrigger = true;
-		ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoChargerGetEmergencyStop = NO;
-	}
-
-	if (isTrigger)
-	{
-		ReleaseChargingProcessByString(level);
-	}
-}
-
-void ReleaseEmsOccureByString(byte index, char *code)
-{
-	bool isTrigger = false;
-	byte level = 2;
-
-	if (strncmp(code, "012251", 6) == 0 && ShmStatusCodeData->AlarmCode.AlarmEvents.bits.EmergencyStopTrip == YES)
-	{
-		isTrigger = true;
-		ShmStatusCodeData->AlarmCode.AlarmEvents.bits.EmergencyStopTrip = NO;
-	}
-	else if (strncmp(code, "012252", 6) == 0 && ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DoorOpen == YES)
-	{
-		isTrigger = true;
-		ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DoorOpen = NO;
-	}
-	else if (strncmp(code, "012237", 6) == 0 && ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SpdTrip == YES)
-	{
-		isTrigger = true;
-		ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SpdTrip = NO;
-	}
-	else if (strncmp(code, "012238", 6) == 0 && ShmStatusCodeData->AlarmCode.AlarmEvents.bits.MainPowerBreakerTrip == YES)
-	{
-		isTrigger = true;
-		ShmStatusCodeData->AlarmCode.AlarmEvents.bits.MainPowerBreakerTrip = NO;
-	}
-
-	if (isTrigger)
-	{
-		ReleaseChargingProcessByString(level);
-	}
-}
-
-//===============================================
-// 確認硬體 (按鈕) 狀態
-//===============================================
-bool leftBtnPush = false;
-bool rightBtnPush = false;
-
-void ChkPrimaryStatus()
-{
-	if (ShmPrimaryMcuData->InputDet.bits.EmergencyButton == ABNORMAL)
-	{
-		ShmStatusCodeData->AlarmCode.AlarmEvents.bits.EmergencyStopTrip = YES;
-		EmcOccureByString("012251");
-	}
-	else
-		ReleaseEmsOccureByString(0, "012251");
-
-	if (ShmPrimaryMcuData->InputDet.bits.AcMainBreakerDetec == ABNORMAL)
-	{
-		ShmStatusCodeData->AlarmCode.AlarmEvents.bits.MainPowerBreakerTrip = YES;
-		EmcOccureByString("012238");
-	}
-	else
-		ReleaseEmsOccureByString(0, "012238");
-
-	if (ShmPrimaryMcuData->InputDet.bits.SpdDetec == ABNORMAL)
-	{
-		ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SpdTrip = YES;
-		//EmcOccureByString("012237");
-	}
-	else
-		ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SpdTrip = NO;
-		//ReleaseEmsOccureByString(0, "012237");
-
-	if (ShmPrimaryMcuData->InputDet.bits.DoorOpen == ABNORMAL)
-	{
-		ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DoorOpen = YES;
-		EmcOccureByString("012252");
-	}
-	else
-		ReleaseEmsOccureByString(0, "012252");
-
-	if (ShmPrimaryMcuData->InputDet.bits.Button1 == BTN_PRESS && !leftBtnPush)
-	{
-		if(!leftBtnPush)
-		{
-			leftBtnPush = true;
-			PRINTF_FUNC("left btn down............................... \n");
-			if (ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc != NO_DEFINE)
-			{
-				switch(ac_chargingInfo[0]->SystemStatus)
-				{
-				case S_IDLE:
-				{
-					if(isDetectPlugin())
-					{
-						_DetectPlugInTimeout();
-						StopSystemTimeoutDet();
-					}
-				}
-					break;
-				case S_REASSIGN_CHECK:
-				case S_REASSIGN:
-				case S_PREPARNING:
-				case S_PREPARING_FOR_EV:
-				case S_PREPARING_FOR_EVSE:
-				case S_CCS_PRECHARGE_ST0:
-				case S_CCS_PRECHARGE_ST1:
-				{
-					// 取消充電
-					AcChargingTerminalProcess();
-				}
-					break;
-				case S_CHARGING:
-				{
-					if (ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_DISABLE)
-					{
-						// 停止充電
-						AcChargingTerminalProcess();
-					}
-				}
-					break;
-				case S_COMPLETE:
-				{}
-					break;
-				}
-			}
-
-			switch(chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
-			{
-				case S_IDLE:
-				{
-					if(isDetectPlugin())
-					{
-						_DetectPlugInTimeout();
-						StopSystemTimeoutDet();
-					}
-				}
-					break;
-				case S_REASSIGN_CHECK:
-				case S_REASSIGN:
-				case S_PREPARNING:
-				case S_PREPARING_FOR_EV:
-				case S_PREPARING_FOR_EVSE:
-				case S_CCS_PRECHARGE_ST0:
-				case S_CCS_PRECHARGE_ST1:
-				{
-					// 取消充電
-					if (ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc != NO_DEFINE)
-						AcChargingTerminalProcess();
-					else
-						ChargingTerminalProcess(ShmSysConfigAndInfo->SysInfo.CurGunSelected);
-				}
-					break;
-				case S_CHARGING:
-				{
-					if (ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_DISABLE)
-					{
-						// 停止充電
-						ChargingTerminalProcess(ShmSysConfigAndInfo->SysInfo.CurGunSelected);
-					}
-				}
-					break;
-				case S_COMPLETE:
-				{
-					// 回 IDLE
-					//PRINTF_FUNC("right btn down.................S_COMPLETE \n");
-					//chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_IDLE;
-				}
-					break;
-			}
-		}
-	}
-	else if (ShmPrimaryMcuData->InputDet.bits.Button1 == BTN_RELEASE)
-	{
-		if(leftBtnPush)
-		{
-			leftBtnPush = false;
-			PRINTF_FUNC("left btn up............................... \n");
-		}
-	}
-
-	if (ShmPrimaryMcuData->InputDet.bits.Button2 == BTN_PRESS && !rightBtnPush)
-	{
-		if(!rightBtnPush)
-		{
-			rightBtnPush = true;
-			PRINTF_FUNC("right btn down............................... %d \n", ShmSysConfigAndInfo->SysInfo.CurGunSelected);
-			if (ShmSysConfigAndInfo->SysInfo.CurGunSelected + 1 < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount &&
-					ShmSysConfigAndInfo->SysInfo.IsAlternatvieConf == NO)
-			{
-				ShmSysConfigAndInfo->SysInfo.CurGunSelected++;
-				ChangeGunSelectByIndex(ShmSysConfigAndInfo->SysInfo.CurGunSelected);
-			}
-			else if (ShmSysConfigAndInfo->SysConfig.AcConnectorCount > 0 &&
-					ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc == NO_DEFINE)
-				ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc = DEFAULT_AC_INDEX;
-			else if (ShmSysConfigAndInfo->SysInfo.IsAlternatvieConf == YES)
-			{
-				for (byte _index = 0; _index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _index++)
-				{
-					if (chargingInfo[_index]->SystemStatus != S_BOOTING &&
-							chargingInfo[_index]->SystemStatus != S_IDLE &&
-							chargingInfo[_index]->SystemStatus != S_RESERVATION)
-					{
-						ShmSysConfigAndInfo->SysInfo.CurGunSelected = _index;
-						ChangeGunSelectByIndex(ShmSysConfigAndInfo->SysInfo.CurGunSelected);
-						return;
-					}
-				}
-
-				ShmSysConfigAndInfo->SysInfo.CurGunSelected = 0;
-				ChangeGunSelectByIndex(ShmSysConfigAndInfo->SysInfo.CurGunSelected);
-			}
-			else
-			{
-				ShmSysConfigAndInfo->SysInfo.CurGunSelected = 0;
-				ChangeGunSelectByIndex(ShmSysConfigAndInfo->SysInfo.CurGunSelected);
-			}
-		}
-	}
-	else if (ShmPrimaryMcuData->InputDet.bits.Button2 == BTN_RELEASE)
-	{
-		if(rightBtnPush)
-		{
-			rightBtnPush = false;
-			PRINTF_FUNC("right btn up............................... \n");
-		}
-	}
-}
-
-//===============================================
-// 確認各小板偵測的錯誤狀況
-//===============================================
-void CheckErrorOccurStatus(byte index)
-{
-	// 小板
-	if (chargingInfo[index]->Type == _Type_Chademo)
-	{
-		if (ShmStatusCodeData->FaultCode.FaultEvents.bits.ChademoOutputRelayDrivingFault == YES)
-			BoardErrOccurByString(index, "011012");
-		else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoGfdTrip == YES)
-			BoardErrOccurByString(index, "012234");
-	}
-	else if (chargingInfo[index]->Type == _Type_GB)
-	{
-		if (ShmStatusCodeData->FaultCode.FaultEvents.bits.GbOutputRelayDrivingFault == YES)
-			BoardErrOccurByString(index, "011016");
-		else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbGfdTrip == YES)
-			BoardErrOccurByString(index, "012236");
-	}
-	else if (chargingInfo[index]->Type == _Type_CCS_2)
-	{
-		if (ShmStatusCodeData->FaultCode.FaultEvents.bits.CcsOutputRelayDrivingFault == YES)
-			BoardErrOccurByString(index, "011014");
-		else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsGfdTrip == YES)
-			BoardErrOccurByString(index, "012235");
-	}
-
-	// RB
-	if (ShmSysConfigAndInfo->SysConfig.PhaseLossPolicy == YES)
-	{
-		if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputUVP == YES ||
-				ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputUVP == YES ||
-				ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputUVP == YES)
-		{
-			if (ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess == _EXTRA_ERR_PROCESS_NONE)
-			{
-				ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess = _EXTRA_ERR_PROCESS_INUVP;
-				StopChargingProcessByString(2);
-			}
-		}
-		else
-		{
-			if (ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess == _EXTRA_ERR_PROCESS_INUVP)
-			{
-				ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess = _EXTRA_ERR_PROCESS_NONE;
-				ReleaseChargingProcessByString(2);
-			}
-		}
-	}
-	else
-	{
-		if (ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess == _EXTRA_ERR_PROCESS_INUVP)
-		{
-			ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess = _EXTRA_ERR_PROCESS_NONE;
-			ReleaseChargingProcessByString(2);
-		}
-	}
-
-	if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputOVP == YES ||
-			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputOVP == YES ||
-			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputOVP == YES)
-	{
-		if (ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess == _EXTRA_ERR_PROCESS_NONE)
-		{
-			ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess = _EXTRA_ERR_PROCESS_INOVP;
-			StopChargingProcessByString(2);
-		}
-	}
-	else
-	{
-		if (ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess == _EXTRA_ERR_PROCESS_INOVP)
-		{
-			ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess = _EXTRA_ERR_PROCESS_NONE;
-			ReleaseChargingProcessByString(2);
-		}
-	}
-}
-
-//===============================================
-// 確認 GPIO 狀態
-//===============================================
-void gpio_set_value(unsigned int gpio, unsigned int value)
-{
-	int fd;
-	char buf[MAX_BUF];
-
-	snprintf(buf, sizeof(buf), SYSFS_GPIO_DIR "/gpio%d/value", gpio);
-	fd = open(buf, O_WRONLY);
-	if (fd < 0)
-	{
-	    perror("gpio/set-value");
-	    return;
-	}
-
-	if (value)
-		write(fd, "1", 2);
-	else
-	    write(fd, "0", 2);
-
-	close(fd);
-}
-
-int gpio_get_value(unsigned int gpio, unsigned int *value)
-{
-    int fd;
-    char buf[MAX_BUF];
-    char ch;
-
-    snprintf(buf, sizeof(buf), SYSFS_GPIO_DIR "/gpio%d/value", gpio);
-
-    fd = open(buf, O_RDONLY);
-    if (fd < 0) {
-        perror("gpio/get-value");
-        return fd;
-    }
-
-    read(fd, &ch, 1);
-
-    if (ch != '0') {
-        *value = 1;
-    } else {
-        *value = 0;
-    }
-
-    close(fd);
-    return 0;
-}
-
-void CheckGunTypeFromHw()
-{
-	int pinIn[4] = { 22, 23, 44, 45 };
-	unsigned int gpioValue = 0;
-
-	for (int i = 0; i < ARRAY_SIZE(pinIn); i++) {
-		gpio_get_value(pinIn[i], &gpioValue);
-		{
-			switch (pinIn[i])
-			{
-			case 22:
-				bd1_1_status = gpioValue;
-				break;
-			case 23:
-				bd1_2_status = gpioValue;
-				break;
-			case 44:
-				bd0_1_status = gpioValue;
-				break;
-			case 45:
-				bd0_2_status = gpioValue;
-				break;
-			}
-		}
-	}
-}
-
-void CheckGpioInStatus()
-{
-	int pinIn[2] = { 27, 47 };
-	unsigned int gpioValue = 0;
-
-	for (int i = 0; i < ARRAY_SIZE(pinIn); i++)
-	{
-		gpio_get_value(pinIn[i], &gpioValue);
-		if (gpioValue == 0x01)
-		{
-			switch(pinIn[i])
-			{
-				// 小板緊急停止
-				case 47:
-				{
-					for(int i = 0; i < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; i++)
-					{
-						if (chargingInfo[i]->slotsIndex == 1)
-						{
-							if (chargingInfo[i]->Type == _Type_Chademo)
-								BoardErrOccurByString(i, "023730");
-							else if (chargingInfo[i]->Type == _Type_CCS_2)
-								BoardErrOccurByString(i, "013627");
-							break;
-						}
-					}
-				}
-					break;
-				case 27:
-				{
-					for(int i = 0; i < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; i++)
-					{
-						if (chargingInfo[i]->slotsIndex == 3)
-						{
-							if (chargingInfo[i]->Type == _Type_Chademo)
-								BoardErrOccurByString(i, "023730");
-							else if (chargingInfo[i]->Type == _Type_CCS_2)
-								BoardErrOccurByString(i, "013627");
-							break;
-						}
-					}
-				}
-					break;
-			}
-		}
-		else
-		{
-			switch (pinIn[i])
-			{
-				// 小板解除緊急停止
-				case 47:
-				{
-					for(int i = 0; i < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; i++)
-					{
-						if (chargingInfo[i]->slotsIndex == 1)
-						{
-							if (chargingInfo[i]->Type == _Type_Chademo)
-								ReleaseBoardErrOccurByString(i, "023730");
-							else if (chargingInfo[i]->Type == _Type_CCS_2)
-								ReleaseBoardErrOccurByString(i, "013627");
-							break;
-						}
-					}
-				}
-					break;
-				case 27:
-				{
-					for (int i = 0; i < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; i++)
-					{
-						if (chargingInfo[i]->slotsIndex == 3)
-						{
-							if (chargingInfo[i]->Type == _Type_Chademo)
-								ReleaseBoardErrOccurByString(i, "023730");
-							else if (chargingInfo[i]->Type == _Type_CCS_2)
-								ReleaseBoardErrOccurByString(i, "013627");
-							break;
-						}
-					}
-				}
-				break;
-			}
-		}
-	}
-}
-
-//===============================================
-// Main process
-//===============================================
-// 檢查 Byte 中某個 Bit 的值
-// _byte : 欲改變的 byte
-// _bit : 該 byte 的第幾個 bit
-unsigned char DetectBitValue(unsigned char _byte, unsigned char _bit)
-{
-	return ( _byte & mask_table[_bit] ) != 0x00;
-}
-
-// 設定 Byte 中某個 Bit的值
-// _byte : 欲改變的 byte
-// _bit : 該 byte 的第幾個 bit
-// value : 修改的值為 0 or 1
-void SetBitValue(unsigned char *_byte, unsigned char _bit, unsigned char value)
-{
-	if(value == 1)
-		*_byte |= (1 << _bit);
-	else if (value == 0)
-		*_byte ^= (1 << _bit);
-}
-
-void UserScanFunction()
-{
-	bool idleReq = false;
-	unsigned char stopReq = 255;
-
-	// 當前非驗證的狀態
-	if(!IsAuthorizingMode())
-	{
-		// 先判斷現在是否可以提供刷卡
-		// 1. 如果當前沒有槍是閒置狀態,則無提供刷卡功能
-		// 2. 停止充電
-		if (ShmSysConfigAndInfo->SysInfo.PageIndex == _LCM_FIX)
-		{
-			strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
-			return;
-		}
-
-		for (byte i = 0; i < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; i++)
-		{
-			if (chargingInfo[i]->SystemStatus == S_CHARGING)
-			{
-				stopReq = i;
-			}
-			if ((chargingInfo[i]->SystemStatus == S_IDLE && chargingInfo[i]->IsAvailable) == YES ||
-					(_acgunIndex > 0 && ac_chargingInfo[0]->SystemStatus == S_IDLE && ac_chargingInfo[0]->IsAvailable))
-			{
-				idleReq = true;
-			}
-		}
-
-		if (_acgunIndex > 0 && ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc == DEFAULT_AC_INDEX &&
-				ac_chargingInfo[0]->SystemStatus == S_CHARGING)
-		{
-			stopReq = DEFAULT_AC_INDEX;
-		}
-
-		if (strlen((char *)ShmSysConfigAndInfo->SysConfig.UserId) > 0)
-		{
-			if (_acgunIndex > 0 && stopReq == DEFAULT_AC_INDEX && ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc == DEFAULT_AC_INDEX)
-			{
-				char value[32];
-
-				PRINTF_FUNC("ac stop charging \n");
-				PRINTF_FUNC("index = %d, card number = %s, UserId = %s \n", ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc,
-						ac_chargingInfo[0]->StartUserId, ShmSysConfigAndInfo->SysConfig.UserId);
-				memcpy(value, (unsigned char *)ac_chargingInfo[0]->StartUserId,
-					ARRAY_SIZE(ac_chargingInfo[0]->StartUserId));
-				if (strcmp((char *)ShmSysConfigAndInfo->SysConfig.UserId, value) == EQUAL)
-				{
-					AcChargingTerminalProcess();
-				}
-				strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
-			}
-			else if (stopReq < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount &&
-					chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus == S_CHARGING &&
-					(_acgunIndex <= 0 || (_acgunIndex > 0 && ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc == NO_DEFINE)))
-			{
-				char value[32];
-
-				PRINTF_FUNC("stop charging \n");
-				PRINTF_FUNC("index = %d, card number = %s, UserId = %s \n", ShmSysConfigAndInfo->SysInfo.CurGunSelected,
-						chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->StartUserId, ShmSysConfigAndInfo->SysConfig.UserId);
-				memcpy(value, (unsigned char *)chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->StartUserId,
-						ARRAY_SIZE(chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->StartUserId));
-
-				// 同一張卡直接停掉
-				if (strcmp((char *)ShmSysConfigAndInfo->SysConfig.UserId, value) == EQUAL)
-				{
-					ChargingTerminalProcess(ShmSysConfigAndInfo->SysInfo.CurGunSelected);
-					strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
-				}
-				else
-				{
-					// 進驗證
-					if (_acgunIndex > 0 && ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc == DEFAULT_AC_INDEX)
-					{
-						_authorizeIndex = ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc;
-					}
-					else
-					{
-						_authorizeIndex = ShmSysConfigAndInfo->SysInfo.CurGunSelected;
-					}
-
-					StartSystemTimeoutDet(Timeout_AuthorizingForStop);
-					AuthorizingStart();
-				}
-			}
-			else if (idleReq)
-			{
-				if (ShmSysConfigAndInfo->SysConfig.TotalConnectorCount > 1 &&
-						stopReq != 255 &&
-						ShmSysConfigAndInfo->SysInfo.IsAlternatvieConf == YES)
-				{
-					idleReq = false;
-					strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
-				}
-				else if ((_acgunIndex > 0 && ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc == DEFAULT_AC_INDEX) ||
-						chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus == S_IDLE)
-				{
-					PRINTF_FUNC("// LCM => Authorizing \n");
-					// LCM => Authorizing
-					ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_AUTHORIZING;
-					// 進入確認卡號狀態
-					AuthorizingStart();
-				}
-				else
-					strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
-			}
-			else
-			{
-				strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
-			}
-		}
-	}
-	else
-	{
-		// 透過後臺停止充電的判斷
-		if (isAuthorizedComplete() ||
-				(ShmSysConfigAndInfo->SysInfo.OcppConnStatus == NO &&
-					ShmSysConfigAndInfo->SysConfig.OfflinePolicy == _OFFLINE_POLICY_FREE_CHARGING))
-		{
-			// 判斷後台回覆狀態
-			if(canStartCharging() ||
-				(ShmSysConfigAndInfo->SysInfo.OcppConnStatus == NO &&
-					ShmSysConfigAndInfo->SysConfig.OfflinePolicy == _OFFLINE_POLICY_FREE_CHARGING))
-			{
-				if (_authorizeIndex != NO_DEFINE)
-				{
-					// 先找 AC
-					if (_authorizeIndex == DEFAULT_AC_INDEX)
-					{
-						if (ShmSysConfigAndInfo->SysConfig.OfflinePolicy == _OFFLINE_POLICY_LOCAL_LIST &&
-								strcmp((char *)chargingInfo[_authorizeIndex]->StartUserId, "") != EQUAL)
-						{
-							AcChargingTerminalProcess();
-						}
-					}
-					else
-					{
-						if (ShmSysConfigAndInfo->SysConfig.OfflinePolicy == _OFFLINE_POLICY_LOCAL_LIST &&
-								strcmp((char *)chargingInfo[_authorizeIndex]->StartUserId, "") != EQUAL)
-						{
-							ChargingTerminalProcess(_authorizeIndex);
-						}
-					}
-					strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
-					_authorizeIndex = NO_DEFINE;
-				}
-			}
-			else
-				strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
-			ClearAuthorizedFlag();
-		}
-		else if (ShmSysConfigAndInfo->SysConfig.OfflinePolicy == _OFFLINE_POLICY_LOCAL_LIST)
-		{
-			// 白名單驗證
-			for (int i = 0; i < 10; i++)
-			{
-				if (strcmp((char *)ShmSysConfigAndInfo->SysConfig.LocalWhiteCard[i], "") != EQUAL)
-				{
-					if (strcmp((char *)ShmSysConfigAndInfo->SysConfig.LocalWhiteCard[i], (char *)ShmSysConfigAndInfo->SysConfig.UserId) == EQUAL)
-					{
-						ChargingTerminalProcess(_authorizeIndex);
-						strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
-						ClearAuthorizedFlag();
-						break;
-					}
-				}
-			}
-		}
-	}
-}
-
-unsigned char isModeChange(unsigned char gun_index)
-{
-	unsigned char result = NO;
-
-	if(chargingInfo[gun_index]->SystemStatus != chargingInfo[gun_index]->PreviousSystemStatus)
-	{
-		result = YES;
-		chargingInfo[gun_index]->PreviousSystemStatus = chargingInfo[gun_index]->SystemStatus;
-	}
-
-	return result;
-}
-
-void ScannerCardProcess()
-{
-	if (!isDetectPlugin() && !isCardScan && ShmSysConfigAndInfo->SysWarningInfo.Level != 2 &&
-			ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_ENABLE)
-	{
-		isCardScan = true;
-		// 處理刷卡及驗證卡號的動作
-		UserScanFunction();
-	}
-
-	if (ShmSysConfigAndInfo->SysInfo.PageIndex == _LCM_AUTHORIZING)
-	{
-		StartSystemTimeoutDet(Timeout_Authorizing);
-
-		// 確認驗證卡號完成沒
-		if (isAuthorizedComplete() || ShmSysConfigAndInfo->SysConfig.OfflinePolicy == _OFFLINE_POLICY_FREE_CHARGING)
-		{
-			StopSystemTimeoutDet();
-			// 判斷後台回覆狀態
-			if(canStartCharging() || ShmSysConfigAndInfo->SysConfig.OfflinePolicy == _OFFLINE_POLICY_FREE_CHARGING)
-			{
-				// LCM => Authorize complete
-				ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_AUTHORIZ_COMP;
-			}
-			else
-			{
-				// LCM => Authorize fail
-				ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_AUTHORIZ_FAIL;
-				strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
-			}
-			ClearAuthorizedFlag();
-		}
-		else if (ShmSysConfigAndInfo->SysConfig.OfflinePolicy == _OFFLINE_POLICY_LOCAL_LIST)
-		{
-			// 白名單驗證
-			for (int i = 0; i < 10; i++)
-			{
-				if (strcmp((char *)ShmSysConfigAndInfo->SysConfig.LocalWhiteCard[i], "") != EQUAL)
-				{
-					if (strcmp((char *)ShmSysConfigAndInfo->SysConfig.LocalWhiteCard[i], (char *)ShmSysConfigAndInfo->SysConfig.UserId) == EQUAL)
-					{
-						ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_AUTHORIZ_COMP;
-						ClearAuthorizedFlag();
-						break;
-					}
-				}
-			}
-		}
-	}
-	else if (ShmSysConfigAndInfo->SysInfo.PageIndex == _LCM_AUTHORIZ_FAIL)
-	{
-		StartSystemTimeoutDet(Timeout_VerifyFail);
-		isCardScan = false;
-	}
-	else if(ShmSysConfigAndInfo->SysInfo.PageIndex == _LCM_AUTHORIZ_COMP)
-	{
-		StartSystemTimeoutDet(Timeout_VerifyComp);
-	}
-	else if(ShmSysConfigAndInfo->SysInfo.PageIndex == _LCM_WAIT_FOR_PLUG)
-	{
-		StartSystemTimeoutDet(Timeout_WaitPlug);
-	}
-	else
-		isCardScan = false;
-}
-
-bool AddGunInfoByConnector(byte typeValue, byte slots)
-{
-	bool result = true;
-
-	switch (typeValue)
-	{
-		case '0': // none
-			break;
-		case '1': // IEC 62196-2 Type 1/SAE J1772 Plug
-			break;
-		case '2': // IEC 62196-2 Type 1/SAE J1772 Socket
-			break;
-		case '3': // IEC 62196-2 Type 2 Plug
-		case '4': // IEC 62196-2 Type 2 Socket
-			if (AC_QUANTITY > _ac_Index)
-			{
-				ac_chargingInfo[_acgunIndex] = &ShmSysConfigAndInfo->SysInfo.AcChargingData[_ac_Index];
-
-				// AC 固定 index
-				ac_chargingInfo[_acgunIndex]->Index = 0;
-				ac_chargingInfo[_acgunIndex]->ReservationId = -1;
-				ac_chargingInfo[_acgunIndex]->SystemStatus = S_IDLE;
-				ac_chargingInfo[_acgunIndex]->Type = _Type_AC;
-				ac_chargingInfo[_acgunIndex]->IsAvailable = YES;
-				_ac_Index++;
-				_acgunIndex++;
-			}
-			else
-				result = false;
-			break;
-		case '5': // GB/T AC Plug
-			break;
-		case '6': // GB/T AC Socket
-			break;
-		case 'J': // CHAdeMO
-		{
-			if (CHAdeMO_QUANTITY > _chademoIndex)
-			{
-				chargingInfo[_gunIndex] = &ShmSysConfigAndInfo->SysInfo.ChademoChargingData[_chademoIndex];
-				chargingInfo[_gunIndex]->Index = _gunIndex;
-				chargingInfo[_gunIndex]->ReservationId = -1;
-				chargingInfo[_gunIndex]->slotsIndex = slots;
-				chargingInfo[_gunIndex]->SystemStatus = S_BOOTING;
-				chargingInfo[_gunIndex]->Type = _Type_Chademo;
-				chargingInfo[_gunIndex]->type_index = _chademoIndex;
-				chargingInfo[_gunIndex]->IsAvailable = YES;
-				_chademoIndex++;
-				_gunIndex++;
-			}
-			else
-				result = false;
-		}
-			break;
-		case 'U': // CCS1 combo
-		case 'E': // CCS2 combo
-		{
-			if (CCS_QUANTITY > _ccsIndex)
-			{
-				chargingInfo[_gunIndex] = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[_ccsIndex];
-
-				chargingInfo[_gunIndex]->Index = _gunIndex;
-				chargingInfo[_gunIndex]->ReservationId = -1;
-				chargingInfo[_gunIndex]->slotsIndex = slots;
-				chargingInfo[_gunIndex]->SystemStatus = S_BOOTING;
-				chargingInfo[_gunIndex]->Type = _Type_CCS_2;
-				chargingInfo[_gunIndex]->type_index = _ccsIndex;
-				chargingInfo[_gunIndex]->IsAvailable = YES;
-				// 現階段預設為走 DIN70121
-				ShmCcsData->CommProtocol = 0x01;
-				_ccsIndex++;
-				_gunIndex++;
-			}
-			else
-				result = false;
-		}
-			break;
-		case 'G': // GBT DC
-		{
-			if (GB_QUANTITY > _gb_Index)
-			{
-				chargingInfo[_gunIndex] = &ShmSysConfigAndInfo->SysInfo.GbChargingData[_gb_Index];
-
-				chargingInfo[_gunIndex]->Index = _gunIndex;
-				chargingInfo[_gunIndex]->ReservationId = -1;
-				chargingInfo[_gunIndex]->slotsIndex = slots;
-				chargingInfo[_gunIndex]->SystemStatus = S_BOOTING;
-				chargingInfo[_gunIndex]->Type = _Type_GB;
-				chargingInfo[_gunIndex]->type_index = _gb_Index;
-				chargingInfo[_gunIndex]->IsAvailable = YES;
-				_gb_Index++;
-				_gunIndex++;
-			}
-			else
-				result = false;
-		}
-			break;
-		case 'D': // GBT DC x 2
-			break;
-	}
-	return result;
-}
-
-bool CheckConnectorTypeStatus()
-{
-	bool result = true;
-
-	PRINTF_FUNC("bd0_1_status = %d, bd0_2_status = %d, bd1_1_status = %d, bd1_2_status = %d \n",
-			bd0_1_status, bd0_2_status, bd1_1_status, bd1_2_status);
-	if (strlen((char *) ShmSysConfigAndInfo->SysConfig.ModelName) >= 9)
-	{
-		byte slots = 1;
-		for (byte typeIndex = 7; typeIndex <= 9; typeIndex++)
-		{
-			if(!AddGunInfoByConnector(ShmSysConfigAndInfo->SysConfig.ModelName[typeIndex], slots))
-			{
-				return false;
-			}
-
-			slots++;
-		}
-
-		// AC index 接在 DC 後面
-		if (AC_QUANTITY > 0)
-			ac_chargingInfo[0]->Index += _gunIndex;
-
-		ShmSysConfigAndInfo->SysConfig.TotalConnectorCount = _gunIndex;
-		ShmSysConfigAndInfo->SysConfig.AcConnectorCount = _acgunIndex;
-		PRINTF_FUNC("DC _gunCount = %d, AC _gunCount = %d \n",
-				ShmSysConfigAndInfo->SysConfig.TotalConnectorCount,
-				ShmSysConfigAndInfo->SysConfig.AcConnectorCount);
-
-		if (ShmSysConfigAndInfo->SysConfig.TotalConnectorCount == 0 &&
-				ShmSysConfigAndInfo->SysConfig.AcConnectorCount == 0)
-			result = false;
-
-		if (ShmSysConfigAndInfo->SysConfig.TotalConnectorCount == 1)
-		{
-			chargingInfo[0]->Evboard_id = 0x01;
-			PRINTF_FUNC("index = %d, Type = %d, Evboard_id = %d \n", 0, chargingInfo[0]->Type, chargingInfo[0]->Evboard_id);
-		}
-		else
-		{
-			// 偵測槍屬於哪個 slot : 可知道插在板上的Slot 0 或 1 是 Chademo 還是 CCS
-			for (byte gunIndex = 0; gunIndex < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gunIndex++)
-			{
-				if (gunIndex == 0 && bd0_1_status == 0 && bd0_2_status == 1)
-				{
-					// 與硬體相同 type : Chademo
-					if (chargingInfo[gunIndex]->Type == _Type_Chademo)
-					{
-						chargingInfo[gunIndex]->Evboard_id = 0x01;
-					}
-				}
-				else if (gunIndex == 0 && bd0_1_status == 1 && bd0_2_status == 0)
-				{
-					// 與硬體相同 type : CCS
-					if (chargingInfo[gunIndex]->Type == _Type_CCS_2)
-					{
-						chargingInfo[gunIndex]->Evboard_id = 0x01;
-					}
-				}
-				else if (gunIndex == 0 && bd0_1_status == 1 && bd0_2_status == 1)
-				{
-					// 與硬體相同 type : GB
-					if (chargingInfo[gunIndex]->Type == _Type_GB)
-					{
-						chargingInfo[gunIndex]->Evboard_id = 0x01;
-					}
-				}
-
-				if (gunIndex == 1 && bd1_1_status == 0 && bd1_2_status == 1)
-				{
-					// 與硬體相同 type : Chademo
-					if (chargingInfo[gunIndex]->Type == _Type_Chademo)
-					{
-						chargingInfo[gunIndex]->Evboard_id = 0x02;
-					}
-
-					if (ShmSysConfigAndInfo->SysConfig.TotalConnectorCount == 1)
-						chargingInfo[gunIndex]->Evboard_id = 0x01;
-				}
-				else if (gunIndex == 1 && bd1_1_status == 1 && bd1_2_status == 0)
-				{
-					// 與硬體相同 type : CCS
-					if (chargingInfo[gunIndex]->Type == _Type_CCS_2)
-					{
-						chargingInfo[gunIndex]->Evboard_id = 0x02;
-					}
-
-					if (ShmSysConfigAndInfo->SysConfig.TotalConnectorCount == 1)
-						chargingInfo[gunIndex]->Evboard_id = 0x01;
-				}
-				else if (gunIndex == 1 && bd1_1_status == 1 && bd1_2_status == 1)
-				{
-					// 與硬體相同 type : GB
-					if (chargingInfo[gunIndex]->Type == _Type_GB)
-					{
-						chargingInfo[gunIndex]->Evboard_id = 0x02;
-					}
-
-					if (ShmSysConfigAndInfo->SysConfig.TotalConnectorCount == 1)
-						chargingInfo[gunIndex]->Evboard_id = 0x01;
-				}
-
-				PRINTF_FUNC("index = %d, Type = %d, Evboard_id = %d \n", gunIndex, chargingInfo[gunIndex]->Type, chargingInfo[gunIndex]->Evboard_id);
-				if (chargingInfo[gunIndex]->Evboard_id == 0x00)
-					result = false;
-			}
-		}
-	}
-	else
-	{
-		// Module Name 不正確 - 告警
-		result = false;
-	}
-
-	return result;
-}
-
-void KillTask()
-{
-	ChangeLcmByIndex(_LCM_FIX);
-	system("killall Module_EventLogging");
-	system("killall Module_PrimaryComm");
-	system("killall Module_EvComm");
-	system("killall Module_LcmControl");
-	system("killall Module_InternalComm");
-	system("killall Module_PsuComm");
-	//system("killall OcppBackend &");
-	system("killall Module_4g &");
-	system("killall Module_Wifi &");
-}
-
-char CheckUpdateProcess()
-{
-	DIR *d;
-	struct dirent *dir;
-	d = opendir("/mnt/");
-
-	if (d)
-	{
-		long int MaxLen=48*1024*1024, ImageLen = 0;
-		while ((dir = readdir(d)) != NULL)
-		{
-			char *new_str;
-			new_str = malloc(strlen("/mnt/")+strlen(dir->d_name)+1);
-			new_str[0] = '\0';
-			strcat(new_str, "/mnt/");
-			strcat(new_str, dir->d_name);
-			int fd = open(new_str, O_RDONLY);
-			if (fd < 0)
-			{
-				return FAIL;
-			}
-
-			unsigned char *ptr = malloc(MaxLen); //-48 is take out the header
-			memset(ptr, 0xFF, MaxLen);  //-48 is take out the header
-			//get the image length
-			ImageLen = read(fd, ptr, MaxLen);
-
-			if (ImageLen > 20)
-			{
-				unsigned int Type = (((unsigned int)ptr[16])<<24 | ((unsigned int)ptr[17])<<16 | ((unsigned int)ptr[18])<<8 | ((unsigned int)ptr[19]));
-			    PRINTF_FUNC("Typed...%x \r\n", Type);
-
-			    switch (Type)
-			    {
-			    	case 0x10000001:
-			    	case 0x10000002:
-			    	case 0x10000003:
-			    	case 0x10000004:
-			    	case 0x10000005:
-			    	{
-			    		if (Upgrade_Flash(Type, new_str, (char *)ShmSysConfigAndInfo->SysConfig.ModelName) == PASS)
-			    			return PASS;
-			    		else
-			    			return FAIL;
-			    	}
-			    	break;
-					case 0x10000007:
-					case 0x10000008:
-					case 0x10000009:
-					case 0x1000000A:
-					{
-						bool isPass = true;
-						int CanFd = InitCanBus();
-
-						if (CanFd > 0)
-						{
-							for(byte index = 0; index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; index++)
-							{
-								if (!isPass)
-						        break;
-
-						        if (chargingInfo[index]->Type == _Type_CCS_2)
-						        {
-						        	if (Upgrade_CCS(CanFd, Type, chargingInfo[index]->Evboard_id, new_str, (char *)ShmSysConfigAndInfo->SysConfig.ModelName) == FAIL)
-						            {
-						            	isPass = false;
-						            }
-						        }
-						    }
-						}
-						else
-						{
-						    printf("Upgrade CCS open CAN FD fail.\n");
-						    isPass = false;
-						}
-
-						return isPass;
-					}
-						break;
-			    	case 0x10000006:
-			    	case 0x1000000D:
-			    	case 0x1000000E:
-			    	case 0x20000002:
-			    	{
-			    		// CSU_PRIMARY_CONTROLLER : 0x10000006
-			    		byte target = 0x00;
-
-			    		if (Type == 0x10000006)
-			    			target = UPGRADE_PRI;
-			    		else if (Type == 0x1000000D)
-			    			target = UPGRADE_RB;
-			    		else if (Type == 0x1000000E)
-			    			target = UPGRADE_FAN;
-			    		else if (Type == 0x20000002)
-			    			target = UPGRADE_AC;
-
-			    		int fd = InitComPort(target);
-
-			    		if (Upgrade_UART(fd, Type, target, new_str, (char *)ShmSysConfigAndInfo->SysConfig.ModelName) == PASS)
-			    			return PASS;
-			    		else
-			    			return FAIL;
-
-			    		close(fd);
-			    	}
-			    	break;
-			    	case 0x1000000B:
-			    	case 0x1000000C:
-			    	{
-			    		// CHAdeMO_BOARD : 0x1000000B, GBT : 0x1000000C
-			    		bool isPass = true;
-			    		int CanFd = InitCanBus();
-
-			    		if (CanFd > 0)
-			    		{
-			    			for(byte index = 0; index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; index++)
-			    			{
-			    				if (!isPass)
-			    					break;
-
-			    				if ((Type == 0x1000000B && chargingInfo[index]->Type == _Type_Chademo) ||
-			    						(Type == 0x1000000C && chargingInfo[index]->Type == _Type_GB))
-			    				{
-			    					if (Upgrade_CAN(CanFd, Type, chargingInfo[index]->Evboard_id, new_str, (char *)ShmSysConfigAndInfo->SysConfig.ModelName) == PASS)
-			    						return PASS;
-			    					else
-			    						return FAIL;
-			    				}
-			    			}
-			    		}
-			    		else
-			    		{
-			    			PRINTF_FUNC("Upgrad FD fail. \n");
-			    			isPass = false;
-			    		}
-
-			    		return isPass;
-			    		break;
-			    	}
-			    }
-			}
-			free(new_str);
-			free(ptr);
-		}
-	}
-	free(dir);
-	closedir(d);
-	return FAIL;
-}
-
-void CreateRfidFork()
-{
-	pid_t rfidRecPid;
-
-	rfidRecPid = fork();
-	if (rfidRecPid == 0)
-	{
-		while(true)
-		{
-			// 刷卡判斷
-			RFID rfid;
-			if (ShmSysConfigAndInfo->SysConfig.OfflinePolicy == _OFFLINE_POLICY_NO_CHARGING ||
-					!ShmSysConfigAndInfo->SysConfig.isRFID)
-			{}
-			else if(getRequestCardSN(rfidFd, 0, &rfid))
-			{
-				PRINTF_FUNC("Get Card..-%s- \n", ShmSysConfigAndInfo->SysConfig.UserId);
-				if (strlen((char *)ShmSysConfigAndInfo->SysConfig.UserId) == 0)
-				{
-					if (ShmSysConfigAndInfo->SysConfig.RfidCardNumEndian == RFID_ENDIAN_LITTLE)
-					{
-						switch (rfid.snType)
-						{
-						case RFID_SN_TYPE_6BYTE:
-							sprintf((char *) ShmSysConfigAndInfo->SysConfig.UserId,
-									"%02X%02X%02X%02X%02X%02X",
-									rfid.currentCard[0], rfid.currentCard[1],
-									rfid.currentCard[2], rfid.currentCard[3],
-									rfid.currentCard[4], rfid.currentCard[5]);
-							break;
-						case RFID_SN_TYPE_7BYTE:
-							sprintf((char *) ShmSysConfigAndInfo->SysConfig.UserId,
-									"%02X%02X%02X%02X%02X%02X%02X",
-									rfid.currentCard[0], rfid.currentCard[1],
-									rfid.currentCard[2], rfid.currentCard[3],
-									rfid.currentCard[4], rfid.currentCard[5],
-									rfid.currentCard[6]);
-							break;
-						case RFID_SN_TYPE_10BYTE:
-							sprintf((char *) ShmSysConfigAndInfo->SysConfig.UserId,
-									"%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X",
-									rfid.currentCard[0], rfid.currentCard[1],
-									rfid.currentCard[2], rfid.currentCard[3],
-									rfid.currentCard[4], rfid.currentCard[5],
-									rfid.currentCard[6], rfid.currentCard[7],
-									rfid.currentCard[8], rfid.currentCard[9]);
-							break;
-						case RFID_SN_TYPE_4BYTE:
-							sprintf((char *) ShmSysConfigAndInfo->SysConfig.UserId,
-									"%02X%02X%02X%02X",
-									rfid.currentCard[0], rfid.currentCard[1],
-									rfid.currentCard[2], rfid.currentCard[3]);
-							break;
-						}
-					}
-					else if (ShmSysConfigAndInfo->SysConfig.RfidCardNumEndian == RFID_ENDIAN_BIG)
-					{
-						switch (rfid.snType)
-						{
-						case RFID_SN_TYPE_6BYTE:
-							sprintf((char *) ShmSysConfigAndInfo->SysConfig.UserId,
-									"%02X%02X%02X%02X%02X%02X",
-									rfid.currentCard[5], rfid.currentCard[4],
-									rfid.currentCard[3], rfid.currentCard[2],
-									rfid.currentCard[1], rfid.currentCard[0]);
-							break;
-						case RFID_SN_TYPE_7BYTE:
-							sprintf((char *) ShmSysConfigAndInfo->SysConfig.UserId,
-									"%02X%02X%02X%02X%02X%02X%02X",
-									rfid.currentCard[6], rfid.currentCard[5],
-									rfid.currentCard[4], rfid.currentCard[3],
-									rfid.currentCard[2], rfid.currentCard[1],
-									rfid.currentCard[0]);
-							break;
-						case RFID_SN_TYPE_10BYTE:
-							sprintf((char *) ShmSysConfigAndInfo->SysConfig.UserId,
-									"%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X",
-									rfid.currentCard[9], rfid.currentCard[8],
-									rfid.currentCard[7], rfid.currentCard[6],
-									rfid.currentCard[5], rfid.currentCard[4],
-									rfid.currentCard[3], rfid.currentCard[2],
-									rfid.currentCard[1], rfid.currentCard[0]);
-							break;
-						case RFID_SN_TYPE_4BYTE:
-							sprintf((char *) ShmSysConfigAndInfo->SysConfig.UserId,
-									"%02X%02X%02X%02X",
-									rfid.currentCard[3], rfid.currentCard[2],
-									rfid.currentCard[1], rfid.currentCard[0]);
-							break;
-						}
-					}
-
-					PRINTF_FUNC("card number = %s\n", ShmSysConfigAndInfo->SysConfig.UserId);
-				}
-			}
-			sleep(1);
-		}
-	}
-}
-
-void StartSystemTimeoutDet(unsigned char flag)
-{
-	if (ShmSysConfigAndInfo->SysInfo.SystemTimeoutFlag != flag)
-	{
-		gettimeofday(&ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer, NULL);
-	}
-	ShmSysConfigAndInfo->SysInfo.SystemTimeoutFlag = flag;
-}
-
-void StopSystemTimeoutDet()
-{
-	gettimeofday(&ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer, NULL);
-	ShmSysConfigAndInfo->SysInfo.SystemTimeoutFlag = Timeout_None;
-}
-
-void StartGunInfoTimeoutDet(unsigned char gunIndex, unsigned char flag)
-{
-	if (gunIndex < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount)
-	{
-		if (chargingInfo[gunIndex]->TimeoutFlag != flag)
-		{
-			gettimeofday(&chargingInfo[gunIndex]->TimeoutTimer, NULL);
-		}
-		chargingInfo[gunIndex]->TimeoutFlag = flag;
-	}
-}
-
-void StopGunInfoTimeoutDet(unsigned char gunIndex)
-{
-	if (gunIndex < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount)
-	{
-		chargingInfo[gunIndex]->TimeoutFlag = Timeout_None;
-	}
-}
-
-void CheckConnectionTimeout()
-{
-	if(system("pidof -s OcppBackend > /dev/null") != 0)
-	{
-		_connectionTimeout = CONN_PLUG_TIME_OUT;
-	}
-	else
-	{
-		if(strcmp((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData,"") != 0)
-		{
-			_connectionTimeout = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
-			if(_connectionTimeout <= 0)
-			{
-				_connectionTimeout = CONN_PLUG_TIME_OUT;
-			}
-		}
-		else
-		{
-			_connectionTimeout = CONN_PLUG_TIME_OUT;
-		}
-	}
-}
-
-void CreateTimeoutFork()
-{
-	pid_t timeoutPid;
-
-	timeoutPid = fork();
-	if (timeoutPid > 0)
-	{
-		gettimeofday(&_cmdSubPriority_time, NULL);
-		CheckConnectionTimeout();
-
-		while(true)
-		{
-			if ((GetTimeoutValue(_cmdSubPriority_time) / 1000) > 5000)
-			{
-				CheckConnectionTimeout();
-				gettimeofday(&_cmdSubPriority_time, NULL);
-			}
-
-			//printf("Timeout ***********SystemTimeoutFlag = %d, ********\n", ShmSysConfigAndInfo->SysInfo.SystemTimeoutFlag);
-			// 系統
-			switch(ShmSysConfigAndInfo->SysInfo.SystemTimeoutFlag)
-			{
-				case Timeout_SelftestChk:
-					if (GetTimeoutValue(ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer) >= 40000000)
-					{
-						_SelfTestTimeout();
-						StopSystemTimeoutDet();
-					}
-					break;
-				case Timeout_Authorizing:
-					if (GetTimeoutValue(ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer) >= 30000000)
-					{
-						_AuthorizedTimeout();
-						StopSystemTimeoutDet();
-					}
-					break;
-				case Timeout_VerifyFail:
-					if (GetTimeoutValue(ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer) >= 3000000)
-					{
-						_AutoReturnTimeout();
-						StopSystemTimeoutDet();
-					}
-					break;
-				case Timeout_VerifyComp:
-					if (GetTimeoutValue(ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer) >= 3000000)
-					{
-						_AutoReturnTimeout();
-						StopSystemTimeoutDet();
-					}
-					break;
-				case Timeout_WaitPlug:
-					if (GetTimeoutValue(ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer) >= _connectionTimeout * 1000000)
-					{
-						_DetectPlugInTimeout();
-						StopSystemTimeoutDet();
-					}
-					break;
-				case Timeout_ReturnToChargingGunDet:
-				{
-					if (GetTimeoutValue(ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer) >= 30000000)
-					{
-						DisplayChargingInfo();
-						StopSystemTimeoutDet();
-					}
-				}
-					break;
-				case Timeout_AuthorizingForStop:
-				{
-					if (GetTimeoutValue(ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer) >= 30000000)
-					{
-						strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
-						ClearAuthorizedFlag();
-						StopSystemTimeoutDet();
-					}
-				}
-					break;
-			}
-			// 各槍
-			for (byte gun_index = 0; gun_index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gun_index++)
-			{
-				//printf("Timeout ***********TimeoutFlag = %d, ********\n", chargingInfo[gun_index]->TimeoutFlag);
-				switch(chargingInfo[gun_index]->TimeoutFlag)
-				{
-					case Timeout_Preparing:
-					{
-						if (GetTimeoutValue(chargingInfo[gun_index]->TimeoutTimer) >= 30000000)
-						{
-							_PrepareTimeout(gun_index);
-							StopGunInfoTimeoutDet(gun_index);
-						}
-					}
-						break;
-					case Timeout_EvChargingDet:
-					{
-						if (GetTimeoutValue(chargingInfo[gun_index]->TimeoutTimer) >= 120000000)
-						{
-							_DetectEvChargingEnableTimeout(gun_index);
-							StopGunInfoTimeoutDet(gun_index);
-						}
-					}
-						break;
-					case Timeout_EvseChargingDet:
-					{
-						if (GetTimeoutValue(chargingInfo[gun_index]->TimeoutTimer) >= 60000000)
-						{
-							_DetectEvseChargingEnableTimeout(gun_index);
-							StopGunInfoTimeoutDet(gun_index);
-						}
-					}
-						break;
-					case Timeout_EvseCompleteDet:
-					{
-						if (GetTimeoutValue(chargingInfo[gun_index]->TimeoutTimer) >= 10000000)
-						{
-							StopGunInfoTimeoutDet(gun_index);
-						}
-					}
-						break;
-					case Timeout_ForCcsPrechargeDet:
-					{
-						if (GetTimeoutValue(chargingInfo[gun_index]->TimeoutTimer) >= 60000000)
-						{
-							_CcsPrechargeTimeout(gun_index);
-							StopGunInfoTimeoutDet(gun_index);
-						}
-					}
-						break;
-				}
-			}
-			sleep(1);
-		}
-	}
-}
-
-void GetSystemTime()
-{
-	struct timeb csuTime;
-	struct tm *tmCSU;
-
-	ftime(&csuTime);
-	tmCSU = localtime(&csuTime.time);
-	PRINTF_FUNC("Time : %04d-%02d-%02d %02d:%02d:%02d \n", tmCSU->tm_year + 1900,
-			tmCSU->tm_mon + 1, tmCSU->tm_mday, tmCSU->tm_hour, tmCSU->tm_min,
-			tmCSU->tm_sec);
-
-//	byte date[14];
-//
-//
-//		 //sprintf(&date, "%d", );
-//
-//		 date[0] = '0' + ((tmCSU->tm_year + 1900) / 1000 % 10);
-
-//	date[0] = (tmCSU->tm_year + 1900) / 1000 % 10;
-//	date[1] = (tmCSU->tm_year + 1900) / 100 % 10;
-//	date[2] = (tmCSU->tm_year + 1900) / 10 % 10;
-//	date[3] = (tmCSU->tm_year + 1900) / 1 % 10;
-//
-//	date[4] = (tmCSU->tm_mon + 1) / 10 % 10;
-//	date[5] = (tmCSU->tm_mon + 1) / 1 % 10;
-//
-//	date[6] = (tmCSU->tm_mday) / 10 % 10;
-//	date[7] = (tmCSU->tm_mday) / 1 % 10;
-//
-//	date[8] = (tmCSU->tm_hour) / 10 % 10;
-//	date[9] = (tmCSU->tm_hour) / 1 % 10;
-//
-//	date[10] = (tmCSU->tm_min) / 10 % 10;
-//	date[11] = (tmCSU->tm_min) / 1 % 10;
-//
-//	date[12] = (tmCSU->tm_sec) / 10 % 10;
-//	date[13] = (tmCSU->tm_sec) / 1 % 10;
-
-//	PRINTF_FUNC("%x, %x, %x, %x, %x, %x, %x, %x, %x, %x, %x, %x, %x, %x \n", date[0], date[1], date[2], date[3],
-//			date[4], date[5], date[6], date[7],
-//			date[8], date[9], date[10], date[11],
-//			date[12], date[13]);
-}
-
-void CheckFactoryConfigFunction()
-{
-	if(ShmSysConfigAndInfo->SysInfo.FactoryConfiguration)
-	{
-		system("cd /root;./FactoryConfig -m");
-		system("sync");
-		sleep(5);
-		system("reboot -f");
-		sleep(5);
-		system("reboot -f");
-	}
-}
-
-void CheckFwUpdateFunction()
-{
-	//PRINTF_FUNC("ShmSysConfigAndInfo->SysInfo.FirmwareUpdate = %d \n", ShmSysConfigAndInfo->SysInfo.FirmwareUpdate);
-	if (ShmSysConfigAndInfo->SysInfo.FirmwareUpdate == YES)
-	{
-		DEBUG_INFO_MSG("ftp : update start. \n");
-		KillTask();
-		if (CheckUpdateProcess() == PASS)
-			DEBUG_INFO_MSG("ftp : update complete. \n");
-		else
-			DEBUG_INFO_MSG("ftp : update fail. \n");
-
-		ShmSysConfigAndInfo->SysInfo.FirmwareUpdate = NO;
-		sleep(5);
-		system("reboot -f");
-	}
-	else if(ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq == YES)
-	{
-		ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = NO;
-	}
-	else if (strcmp((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "Downloaded") == EQUAL)
-	{
-		DEBUG_INFO_MSG("Backend : update start. \n");
-		strcpy((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "");
-		strcpy((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "Installing");
-		ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = YES;
-		KillTask();
-		if (CheckUpdateProcess() == PASS)
-		{
-			DEBUG_INFO_MSG("Backend : update complete. \n");
-			strcpy((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "Installed");
-		}
-		else
-		{
-			DEBUG_INFO_MSG("Backend : update fail. \n");
-			strcpy((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "InstallationFailed");
-		}
-
-		strcpy((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "Installed");
-		ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = YES;
-		sleep(5);
-		system("reboot -f");
-	}
-	else if (strcmp((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "DownloadFailed") == EQUAL)
-	{
-		DEBUG_ERROR_MSG("Backend to download file fail. \n");
-		strcpy((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "");
-		strcpy((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "InstallationFailed");
-		ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = YES;
-	}
-}
-
-//===============================================
-// Check reservation date is expired
-//===============================================
-int isReservationExpired(unsigned char gun_index)
-{
-	int result = NO;
-	struct tm expiredDate;
-	struct timeb expiredTime;
-
-	if (sscanf((char*) ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,
-			"%4d-%2d-%2dT%2d:%2d:%2d", &expiredDate.tm_year,
-			&expiredDate.tm_mon, &expiredDate.tm_mday, &expiredDate.tm_hour,
-			&expiredDate.tm_min, &expiredDate.tm_sec) == 6)
-	{
-		expiredDate.tm_year -= 1900;
-		expiredDate.tm_mon -= 1;
-
-		expiredTime.time = mktime(&expiredDate);
-		if (!CheckTimeOut(expiredTime))
-		{
-			result = YES;
-		}
-	}
-
-	return result;
-}
-
-//===============================================
-// OCPP
-//===============================================
-void CheckOcppStatus()
-{
-	if (ShmOCPP16Data->SpMsg.bits.BootNotificationConf == YES)
-	{
-		ShmOCPP16Data->SpMsg.bits.BootNotificationConf = NO;
-	}
-
-	if (ShmOCPP16Data->MsMsg.bits.ResetReq == YES)
-	{
-		bool canReset = true;
-		if (ShmSysConfigAndInfo->SysWarningInfo.Level != 2)
-		{
-			for (byte _index = 0; _index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _index++)
-			{
-				if (chargingInfo[_index]->SystemStatus != S_IDLE &&
-						chargingInfo[_index]->SystemStatus != S_RESERVATION &&
-						chargingInfo[_index]->SystemStatus != S_MAINTAIN)
-				{
-					canReset = false;
-					if (chargingInfo[_index]->SystemStatus >= S_REASSIGN && chargingInfo[_index]->SystemStatus < S_TERMINATING)
-					{
-						ChargingTerminalProcess(_index);
-					}
-				}
-			}
-		}
-
-		if (canReset)
-		{
-			ShmOCPP16Data->MsMsg.bits.ResetReq = NO;
-			sprintf((char*)ShmOCPP16Data->Reset.ResponseStatus, "Accepted");
-			if(strcmp((char *)ShmOCPP16Data->Reset.Type, "Hard") == EQUAL)
-			{
-				DEBUG_ERROR_MSG("****** Hard Reboot ****** \n");
-				ShmOCPP16Data->MsMsg.bits.ResetConf = YES;
-				sleep(3);
-				system("reboot -f");
-			}
-			else if (strcmp((char *)ShmOCPP16Data->Reset.Type, "Soft") == EQUAL)
-			{
-				DEBUG_ERROR_MSG("****** Soft Reboot ****** \n");
-				ShmOCPP16Data->MsMsg.bits.ResetConf = YES;
-				sleep(3);
-				system("killall OcppBackend &");
-				KillTask();
-				system("/usr/bin/run_evse_restart.sh");
-			}
-		}
-	}
-}
-
-void OcppStartTransation(byte gunIndex)
-{
-	if(strcmp((char *)chargingInfo[gunIndex]->StartUserId, "") == EQUAL)
-		strcpy((char *)ShmOCPP16Data->StartTransaction[gunIndex].IdTag, (char *)ShmOCPP16Data->StartTransaction[gunIndex].IdTag);
-	else
-		strcpy((char *)ShmOCPP16Data->StartTransaction[gunIndex].IdTag, (char *)chargingInfo[gunIndex]->StartUserId);
-
-	PRINTF_FUNC("IdTag = %s \n", ShmOCPP16Data->StartTransaction[gunIndex].IdTag);
-	ShmOCPP16Data->CpMsg.bits[gunIndex].StartTransactionReq = YES;
-}
-
-void OcppStopTransation(byte gunIndex)
-{
-	if(strcmp((char *)chargingInfo[gunIndex]->StartUserId, "") == EQUAL)
-		strcpy((char *)ShmOCPP16Data->StopTransaction[gunIndex].IdTag, (char *)ShmOCPP16Data->StopTransaction[gunIndex].IdTag);
-	else
-		strcpy((char *)ShmOCPP16Data->StopTransaction[gunIndex].IdTag, (char *)chargingInfo[gunIndex]->StartUserId);
-
-	PRINTF_FUNC("IdTag = %s \n", ShmOCPP16Data->StopTransaction[gunIndex].IdTag);
-	ShmOCPP16Data->CpMsg.bits[gunIndex].StopTransactionReq = YES;
-}
-
-bool OcppRemoteStop(byte gunIndex)
-{
-	byte acDirIndex = ShmSysConfigAndInfo->SysConfig.AcConnectorCount;
-
-	// 有 AC 槍的話
-	if (acDirIndex > 0 && gunIndex > 0)
-	{
-		gunIndex += acDirIndex;
-	}
-
-	bool result = ShmOCPP16Data->CsMsg.bits[gunIndex].RemoteStopTransactionReq;
-
-	if (ShmOCPP16Data->CsMsg.bits[gunIndex].RemoteStopTransactionReq == YES)
-	{
-		strcpy((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "Remote");
-		ShmOCPP16Data->CsMsg.bits[gunIndex].RemoteStopTransactionReq = NO;
-	}
-
-	return result;
-}
-
-void OcppRemoteStartChk()
-{
-	if (ShmSysConfigAndInfo->SysConfig.OfflinePolicy == _OFFLINE_POLICY_NO_CHARGING)
-	{}
-	else if(!isDetectPlugin())
-	{
-		// 如果有 AC 槍,則固定是第 2 把槍,所以索引固定為 1
-		byte acDirIndex = ShmSysConfigAndInfo->SysConfig.AcConnectorCount;
-
-		for (byte ac_index = 0; ac_index < ShmSysConfigAndInfo->SysConfig.AcConnectorCount; ac_index++)
-		{
-			if ((ac_chargingInfo[ac_index]->SystemStatus == S_IDLE || ac_chargingInfo[ac_index]->SystemStatus == S_RESERVATION)&&
-					ShmOCPP16Data->CsMsg.bits[acDirIndex].RemoteStartTransactionReq == YES)
-			{
-				ShmOCPP16Data->CsMsg.bits[acDirIndex].RemoteStartTransactionReq = NO;
-				ac_chargingInfo[ac_index]->RemoteStartFlag = YES;
-				ShmSysConfigAndInfo->SysInfo.OrderCharging = YES;
-				printf("RemoteStartFlag = %d \n", ac_chargingInfo[ac_index]->RemoteStartFlag);
-				//ShmSysConfigAndInfo->SysInfo.OrderCharging = DEFAULT_AC_INDEX;
-				ShmOCPP16Data->CsMsg.bits[ShmSysConfigAndInfo->SysConfig.TotalConnectorCount + ac_index].RemoteStartTransactionReq = NO;
-				DetectPluginStart();
-				return;
-			}
-		}
-
-		byte threeGunIndex = 0;
-
-		for (byte gun_index = 0; gun_index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gun_index++)
-		{
-			// 如果有 AC 槍,且 DC 槍也有兩把
-			if (acDirIndex == 1 && gun_index == 1)
-				threeGunIndex = 1;
-
-			if ((chargingInfo[gun_index]->SystemStatus == S_IDLE || chargingInfo[gun_index]->SystemStatus == S_RESERVATION)&&
-					ShmOCPP16Data->CsMsg.bits[gun_index + threeGunIndex].RemoteStartTransactionReq == YES)
-			{
-				chargingInfo[gun_index]->RemoteStartFlag = YES;
-				ShmSysConfigAndInfo->SysInfo.OrderCharging = YES;
-				//ShmSysConfigAndInfo->SysInfo.OrderCharging = gun_index;
-				ShmOCPP16Data->CsMsg.bits[gun_index + threeGunIndex].RemoteStartTransactionReq = NO;
-				DetectPluginStart();
-				break;
-			}
-		}
-	}
-}
-
-void ChkOcppStatus(byte gunIndex)
-{
-	if (chargingInfo[gunIndex]->SystemStatus == S_IDLE &&
-			ShmOCPP16Data->CsMsg.bits[gunIndex].ReserveNowReq == YES)
-	{
-		ShmOCPP16Data->CsMsg.bits[gunIndex].ReserveNowReq = NO;
-		if (isReservationExpired(gunIndex))
-		{
-			PRINTF_FUNC("***************ChkOcppStatus : OcppReservedStatus******************** \n");
-			DEBUG_ERROR_MSG("***************ChkOcppStatus : OcppReservedStatus******************** \n");
-			chargingInfo[gunIndex]->ReservationId = ShmOCPP16Data->ReserveNow[gunIndex].ReservationId;
-			chargingInfo[gunIndex]->SystemStatus = S_RESERVATION;
-		}
-		ShmOCPP16Data->CsMsg.bits[gunIndex].ReserveNowConf = YES;
-	}
-
-	if (chargingInfo[gunIndex]->SystemStatus == S_RESERVATION &&
-			ShmOCPP16Data->CsMsg.bits[gunIndex].CancelReservationReq == YES)
-	{
-		ShmOCPP16Data->CsMsg.bits[gunIndex].CancelReservationReq = NO;
-		if (isReservationExpired(gunIndex))
-		{
-			PRINTF_FUNC("***************ChkOcppStatus : Cancel OcppReservedStatus******************** \n");
-			DEBUG_ERROR_MSG("***************ChkOcppStatus : Cancel OcppReservedStatus******************** \n");
-			chargingInfo[gunIndex]->ReservationId = 0;
-			chargingInfo[gunIndex]->SystemStatus = S_IDLE;
-		}
-		ShmOCPP16Data->CsMsg.bits[gunIndex].CancelReservationConf = YES;
-	}
-
-	if (ShmOCPP16Data->CsMsg.bits[gunIndex].ChangeAvailabilityReq == YES)
-	{
-		PRINTF_FUNC("***************ChkOcppStatus : OcppChangeAvailability******************** \n");
-		DEBUG_ERROR_MSG("***************ChkOcppStatus : OcppChangeAvailability******************** \n");
-		ShmOCPP16Data->CsMsg.bits[gunIndex].ChangeAvailabilityReq = NO;
-		if(strcmp((char *)ShmOCPP16Data->ChangeAvailability[gunIndex].Type, "Operative") == EQUAL)
-		{
-			if (isDb_ready)
-				DB_Update_Operactive(localDb, gunIndex, true);
-
-			chargingInfo[gunIndex]->IsAvailable = YES;
-			if (chargingInfo[gunIndex]->SystemStatus == S_IDLE ||
-				chargingInfo[gunIndex]->SystemStatus == S_RESERVATION ||
-				chargingInfo[gunIndex]->SystemStatus == S_MAINTAIN)
-				setChargerMode(gunIndex, MODE_IDLE);
-		}
-		else if (strcmp((char *)ShmOCPP16Data->ChangeAvailability[gunIndex].Type, "Inoperative") == EQUAL)
-		{
-			if (isDb_ready)
-				DB_Update_Operactive(localDb, gunIndex, false);
-
-			chargingInfo[gunIndex]->IsAvailable = NO;
-			if (chargingInfo[gunIndex]->SystemStatus == S_IDLE ||
-				chargingInfo[gunIndex]->SystemStatus == S_RESERVATION ||
-				chargingInfo[gunIndex]->SystemStatus == S_MAINTAIN)
-				setChargerMode(gunIndex, MODE_MAINTAIN);
-		}
-	}
-
-	if (ShmOCPP16Data->CsMsg.bits[gunIndex].UnlockConnectorReq == YES)
-	{
-		ShmOCPP16Data->CsMsg.bits[gunIndex].UnlockConnectorReq = NO;
-		strcpy((char *)ShmOCPP16Data->UnlockConnector[gunIndex].ResponseStatus, "NotSupported");
-		ShmOCPP16Data->CsMsg.bits[gunIndex].UnlockConnectorConf = YES;
-	}
-}
-
-bool CheckBackendChargingTimeout(byte gunIndex)
-{
-	bool result = false;
-
-	if (ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_ENABLE)
-	{
-		if (ShmSysConfigAndInfo->SysConfig.MaxChargingDuration > 0)
-		{
-			if (chargingInfo[gunIndex]->PresentChargedDuration > (ShmSysConfigAndInfo->SysConfig.MaxChargingDuration * 60))
-				result = true;
-		}
-	}
-	else if (ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_DISABLE)
-	{
-		// 隨插即充電的要看 offline
-		if (ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeDuration > 0)
-		{
-			if (chargingInfo[gunIndex]->PresentChargedDuration > (ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeDuration * 60))
-				result = true;
-		}
-	}
-
-	return result;
-}
-
-bool CheckBackendChargingEnergy(byte gunIndex)
-{
-	bool result = false;
-
-	if (ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_ENABLE)
-	{
-		if (ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy > 0)
-		{
-			if (chargingInfo[gunIndex]->PresentChargedEnergy > ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy)
-				result = true;
-		}
-	}
-	else if (ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_DISABLE)
-	{
-		// 隨插即充電的要看 offline
-		if (ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy > 0)
-		{
-			if (chargingInfo[gunIndex]->PresentChargedEnergy > (ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy))
-				result = true;
-		}
-	}
-
-	return result;
-}
-
-//===============================================
-// SQLite3 related routine
-//===============================================
-int DB_Open(sqlite3 *db)
-{
-	int result = PASS;
-	char* errMsg = NULL;
-	char* createRecordSql="CREATE TABLE IF NOT EXISTS charging_record("
-					      "idx integer primary key AUTOINCREMENT, "
-						  "reservationId text, "
-						  "transactionId text, "
-						  "startMethod text, "
-						  "userId text, "
-						  "dateTimeStart text, "
-						  "dateTimeStop text,"
-						  "socStart text, "
-						  "socStop text, "
-						  "chargeEnergy text, "
-						  "stopReason text"
-						  ");";
-
-	char* createCfgSql="CREATE TABLE IF NOT EXISTS `config` ( "
-					   "`idx` INTEGER PRIMARY KEY AUTOINCREMENT, "
-					   "`IsAvailable` TEXT NOT NULL, "
-				       "`connector` INTEGER NOT NULL, "
-					   "`val` TEXT NOT NULL, unique(IsAvailable,connector) on conflict replace);";
-
-	if(sqlite3_open(DB_FILE, &db))
-	{
-		result = FAIL;
-		PRINTF_FUNC( "Can't open database: %s\r\n", sqlite3_errmsg(db));
-		sqlite3_close(db);
-	}
-	else
-	{
-		PRINTF_FUNC( "Local charging record database open successfully.\r\n");
-
-		if (sqlite3_exec(db, createRecordSql, 0, 0, &errMsg) != SQLITE_OK)
-		{
-			result = FAIL;
-			PRINTF_FUNC( "Create local charging record table error message: %s\n", errMsg);
-		}
-		else
-		{
-			PRINTF_FUNC( "Opened local charging record table successfully\n");
-		}
-
-		if (sqlite3_exec(db, createCfgSql, 0, 0, &errMsg) != SQLITE_OK)
-		{
-			result = FAIL;
-			PRINTF_FUNC( "Create local config table error message: %s\n", errMsg);
-		}
-		else
-		{
-			PRINTF_FUNC( "Opened local config table successfully\n");
-		}
-
-		sqlite3_close(db);
-	}
-
-	return result;
-}
-
-int DB_Insert_Record(sqlite3 *db, int gun_index)
-{
-	int result = PASS;
-	char* errMsg = NULL;
-	char insertSql[1024];
-
-	sprintf(insertSql, "insert into charging_record(reservationId, transactionId, startMethod, userId, dateTimeStart, dateTimeStop, socStart, socStop, chargeEnergy, stopReason) "
-					   "values('%d', '%d', '%d', '%s', '%s', '%s', '%d', '%d', '%f', '%s');",
-					   ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].ReservationId,
-					   ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId,
-					   ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartMethod,
-					   ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartUserId,
-					   ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartDateTime,
-					   ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StopDateTime,
-					   ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc,
-					   ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc,
-					   ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargedEnergy,
-					   ShmOCPP16Data->StopTransaction[gun_index].StopReason);
-
-	if(sqlite3_open("/Storage/ChargeLog/localCgargingRecord.db", &db))
-	{
-		result = FAIL;
-		PRINTF_FUNC( "Can't open database: %s\r\n", sqlite3_errmsg(db));
-		sqlite3_close(db);
-	}
-	else
-	{
-		PRINTF_FUNC( "Local charging record database open successfully.\r\n");
-		if (sqlite3_exec(db, insertSql, 0, 0, &errMsg) != SQLITE_OK)
-		{
-			result = FAIL;
-			PRINTF_FUNC( "Insert local charging record error message: %s\n", errMsg);
-		}
-		else
-		{
-			PRINTF_FUNC( "Insert local charging record successfully\n");
-		}
-		sqlite3_close(db);
-	}
-
-	return result;
-}
-
-int DB_Update_Operactive(sqlite3 *db, uint8_t gun_index, uint8_t IsAvailable)
-{
-	uint8_t result = false;
-	char* errMsg = NULL;
-	char sqlStr[1024];
-	srand(time(NULL));
-
-	if(sqlite3_open(DB_FILE, &db))
-	{
-		result = FAIL;
-		PRINTF_FUNC( "Can't open database: %s\r\n", sqlite3_errmsg(db));
-		sqlite3_close(db);
-	}
-	else
-	{
-		PRINTF_FUNC( "Local charging record database open successfully (%d).\r\n", IsAvailable);
-
-		sprintf(sqlStr, "insert or replace into config (IsAvailable, connector, val) values('IsAvailable', %d, %d);", gun_index, IsAvailable);
-		PRINTF_FUNC("sqlStr= %s\r\n", sqlStr);
-		if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
-		{
-			result = FAIL;
-			PRINTF_FUNC( "update config error message: %s\n", errMsg);
-		}
-		else
-		{
-			PRINTF_FUNC("update connector-%d config item isOperactive to %d\r\n", gun_index, IsAvailable);
-		}
-
-		sqlite3_close(db);
-	}
-
-	return result;
-}
-
-int DB_Get_Operactive(sqlite3 *db, uint8_t gun_index)
-{
-	uint8_t result = true;
-	char* errMsg = NULL;
-	char sqlStr[1024];
-	char **rs;
-	int	 rows, cols;
-
-	sprintf(sqlStr, "select * from config where IsAvailable='IsAvailable' and connector=%d;", gun_index);
-	//DEBUG_INFO("sqlStr= %s\r\n", sqlStr);
-
-	if(sqlite3_open(DB_FILE, &db))
-	{
-		result = FAIL;
-		PRINTF_FUNC( "Can't open database: %s\r\n", sqlite3_errmsg(db));
-		sqlite3_close(db);
-	}
-	else
-	{
-		PRINTF_FUNC( "Local config query database open successfully.\r\n");
-		sqlite3_get_table(db, sqlStr, &rs, &rows, &cols, &errMsg);
-		if(rows>0)
-		{
-			for(int idxRow=1;idxRow<=rows;idxRow++)
-			{
-				if(strcmp(rs[(idxRow*cols)+3], "0") == 0)
-				{
-					result = false;
-				}
-				PRINTF_FUNC("Query connector-%d isOperactive: %s\r\n", gun_index, rs[(idxRow*cols)+3]);
-			}
-		}
-		else
-		{
-			PRINTF_FUNC("Query connector-%d fail, set default value to operactive.\r\n", gun_index);
-		}
-
-		sqlite3_free_table(rs);
-		sqlite3_close(db);
-	}
-
-	return result;
-}
-
-//===============================================
-// Config process
-//===============================================
-void AddPlugInTimes(byte gunIndex)
-{
-	if (chargingInfo[gunIndex]->Type == _Type_Chademo)
-		ShmSysConfigAndInfo->SysConfig.ChademoPlugInTimes += 1;
-	else if(chargingInfo[gunIndex]->Type == _Type_CCS_2)
-		ShmSysConfigAndInfo->SysConfig.Ccs2PlugInTimes += 1;
-	else if(chargingInfo[gunIndex]->Type == _Type_GB)
-		ShmSysConfigAndInfo->SysConfig.GbPlugInTimes += 1;
-}
-
-void ChangeStartOrStopDateTime(byte isStart, byte gunIndex)
-{
-	char cmdBuf[32];
-	struct timeb csuTime;
-	struct tm *tmCSU;
-
-	ftime(&csuTime);
-	tmCSU = localtime(&csuTime.time);
-
-	sprintf(cmdBuf, "%04d-%02d-%02d %02d:%02d:%02d", tmCSU->tm_year + 1900,
-			tmCSU->tm_mon + 1, tmCSU->tm_mday, tmCSU->tm_hour, tmCSU->tm_min,
-			tmCSU->tm_sec);
-	if (isStart)
-		strcpy((char *)chargingInfo[gunIndex]->StartDateTime, cmdBuf);
-	else
-		strcpy((char *)chargingInfo[gunIndex]->StopDateTime, cmdBuf);
-}
-
-void zipLogFiles()
-{
-	const char* logPath = "/Storage/SystemLog";
-	// 獲取目錄
-	DIR* pDir = opendir(logPath);
-	if (pDir != NULL)
-	{
-		struct timeb csuTime;
-		struct tm *tmCSU;
-
-		ftime(&csuTime);
-		tmCSU = localtime(&csuTime.time);
-//		PRINTF_FUNC("Time : %04d-%02d-%02d %02d:%02d:%02d \n", tmCSU->tm_year + 1900,
-//			tmCSU->tm_mon + 1, tmCSU->tm_mday, tmCSU->tm_hour, tmCSU->tm_min,
-//			tmCSU->tm_sec);
-
-		// Read items inside the folder
-		struct dirent* pEntry = NULL;
-		while ((pEntry = readdir(pDir)) != NULL)
-		{
-			if (strcmp(pEntry->d_name, ".") != 0 &&
-					strcmp(pEntry->d_name, "..") != 0 &&
-					strncmp(pEntry->d_name, "[", 1) == 0 &&
-					strstr(pEntry->d_name, "tar") < 0)
-			{
-				char yearC[5];
-				unsigned short year = 0;
-				char monthC[3];
-				unsigned short month = 0;
-
-				yearC[4] = '\0';
-				strncpy(yearC, pEntry->d_name + 1, 4);
-				monthC[2] = '\0';
-				strncpy(monthC, pEntry->d_name + 6, 2);
-
-				year = atoi(yearC);
-				month = atoi(monthC);
-
-				if (year != 0)
-				{
-					if (year < tmCSU->tm_year + 1900 ||
-							(year >= tmCSU->tm_year + 1900 && month < tmCSU->tm_mon + 1))
-					{
-						DEBUG_INFO_MSG("tar file name : %s \n", pEntry->d_name);
-						char file[256];
-
-						memset(file, 0x00, sizeof(file));
-						strcat(file, "tar zcvf ");
-						strcat(file, logPath);
-						strncat(file, "/", 1);
-						strcat(file, pEntry->d_name);
-						strcat(file, ".tar");
-						strncat(file, " ", 1);
-						strcat(file, logPath);
-						strncat(file, "/", 1);
-						strcat(file, pEntry->d_name);
-						PRINTF_FUNC("zip = %s \n", file);
-						system(file);
-					}
-				}
-			}
-		}
-	}
-	// Close folder
-	closedir(pDir);
-}
-
-void ChangeGunSelectByIndex(byte sel)
-{
-	ShmSysConfigAndInfo->SysInfo.CurGunSelected = sel;
-	ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc = NO_DEFINE;
-}
-
-void CheckIsAlternatvieByModelName()
-{
-	// 黑白機 ?
-	if(strcmp((char *)ShmSysConfigAndInfo->SysConfig.ModelName, "DWWU301J0UT1PH") == EQUAL ||
-		strcmp((char *)ShmSysConfigAndInfo->SysConfig.ModelName, "DWYE301J0ET1PH") == EQUAL ||
-		strcmp((char *)ShmSysConfigAndInfo->SysConfig.ModelName, "DSYE301J3EW2PH") == EQUAL ||
-		strcmp((char *)ShmSysConfigAndInfo->SysConfig.ModelName, "DWYC301J0UW1PH") == EQUAL)
-		ShmSysConfigAndInfo->SysInfo.IsAlternatvieConf = YES;
-	else
-		ShmSysConfigAndInfo->SysInfo.IsAlternatvieConf = NO;
-}
-
-void StopProcessingLoop()
-{
-	for (;;)
-	{
-		CheckFactoryConfigFunction();
-		CheckFwUpdateFunction();
-		sleep(1);
-	}
-}
-
-void CreateWatchdog()
-{
-	if (ShmSysConfigAndInfo->SysConfig.SwitchDebugFlag == NO)
-	{
-		wtdFd = InitWatchDog();
-
-		if (wtdFd < 0)
-			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed = 1;
-	}
-}
-
-bool IsConnectorWholeIdle()
-{
-	bool result = true;
-
-	for (byte count = 0; count < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; count++)
-	{
-		if (chargingInfo[count]->SystemStatus != S_IDLE &&
-				chargingInfo[count]->SystemStatus != S_RESERVATION)
-		{
-			result = false;
-			break;
-		}
-	}
-
-	for (byte count = 0; count < ShmSysConfigAndInfo->SysConfig.AcConnectorCount; count++)
-	{
-		if (ac_chargingInfo[count]->SystemStatus != S_IDLE &&
-				ac_chargingInfo[count]->IsErrorOccur == NO)
-		{
-			result = false;
-			break;
-		}
-	}
-
-	return result;
-}
-
-void ClearAlarmCodeWhenAcOff()
-{
-	if (!ShmSysConfigAndInfo->SysInfo.AcContactorStatus)
-	{
-		ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuNoResource = NO;
-	}
-}
-
-//==========================================
-// Check task processing
-//==========================================
-void CheckTask()
-{
-	if(ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'T')
-	{
-		if(system("pidof -s Module_4g > /dev/null") != 0)
-		{
-			DEBUG_ERROR_MSG("Module_4g not running, restart it.\r\n");
-			system("/root/Module_4g &");
-		}
-	}
-	else if(ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'W')
-	{
-		if(system("pidof -s Module_Wifi > /dev/null") != 0)
-		{
-			DEBUG_ERROR_MSG("Module_Wifi not running, restart it.\r\n");
-			system("/root/Module_Wifi &");
-		}
-	}
-
-	if(strcmp((char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, "") != EQUAL &&
-			strcmp((char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId, "") != EQUAL)
-	{
-		if(system("pidof -s OcppBackend > /dev/null") != 0)
-		{
-			DEBUG_ERROR_MSG("OcppBackend not running, restart it.\r\n");
-			system("/root/OcppBackend &");
-		}
-	}
-
-	if(system("pidof -s Module_ProduceUtils > /dev/null") != 0)
-	{
-		DEBUG_ERROR_MSG("Module_ProduceUtils not running, restart it.\r\n");
-		system ("/root/Module_ProduceUtils &");
-	}
-}
-
-//==========================================
-// Check Smart Charging Profile
-//==========================================
-int GetStartScheduleTime(unsigned char *time)
-{
-	int result = -1;
-	struct tm tmScheduleStart;
-	struct timeb tbScheduleStart;
-
-	if((sscanf((char *)time, "%4d-%2d-%2dT%2d:%2d:%2d", &tmScheduleStart.tm_year, &tmScheduleStart.tm_mon, &tmScheduleStart.tm_mday, &tmScheduleStart.tm_hour, &tmScheduleStart.tm_min, &tmScheduleStart.tm_sec) == 6))
-	{
-		tmScheduleStart.tm_year -= 1900;
-		tmScheduleStart.tm_mon -= 1;
-		tbScheduleStart.time = mktime(&tmScheduleStart);
-		tbScheduleStart.millitm = 0;
-
-		result = DiffTimebWithNow(tbScheduleStart) / 1000;
-	}
-
-	return result;
-}
-
-void CheckSmartChargeProfile(byte _index)
-{
-	if (ShmOCPP16Data->CSUMsg.bits[_index].ChargingProfileConf == NO)
-	{
-		if (ShmOCPP16Data->CSUMsg.bits[_index].ChargingProfileReq == NO)
-			ShmOCPP16Data->CSUMsg.bits[_index].ChargingProfileReq = YES;
-	}
-	else
-	{
-		// Get Charging Profile
-		ShmOCPP16Data->CSUMsg.bits[_index].ChargingProfileConf = NO;
-		if (strcmp((char *)ShmOCPP16Data->SmartChargingProfile[_index].ChargingProfileKind, "Absolute") == EQUAL)
-		{
-			int _time = GetStartScheduleTime(ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.StartSchedule);
-			byte _startCount = NO_DEFINE;
-			byte _maxCount = ARRAY_SIZE(ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod);
-
-			for (byte _count = 0; _count < _maxCount; _count++)
-			{
-				// 預設最小輸出電流 (MIN_OUTPUT_CUR) A
-				if (_time >= ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[_count].StartPeriod &&
-						ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[_count].Limit > MIN_OUTPUT_CUR)
-				{
-					_startCount = _count;
-				}
-			}
-
-			PRINTF_FUNC("_startCount = %d \n", _startCount);
-			if (_startCount < _maxCount)
-			{
-				PRINTF_FUNC("*********Limit = %f \n", ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[_startCount].Limit);
-				chargingInfo[_index]->ChargingProfilePower = ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[_startCount].Limit * AC_OUTPUT_VOL;
-				if ((chargingInfo[_index]->EvBatterytargetVoltage * 10) > 0)
-				{
-					chargingInfo[_index]->ChargingProfileCurrent = chargingInfo[_index]->ChargingProfilePower / (chargingInfo[_index]->EvBatterytargetVoltage * 10);
-				}
-			}
-			else
-			{
-				chargingInfo[_index]->ChargingProfilePower = 0;
-				chargingInfo[_index]->ChargingProfileCurrent = 0;
-			}
-
-			PRINTF_FUNC("ChargingProfilePower = %f \n", chargingInfo[_index]->ChargingProfilePower);
-			PRINTF_FUNC("ChargingProfileCurrent = %f \n", chargingInfo[_index]->ChargingProfileCurrent);
-		}
-//
-//		printf("-------------Schedule------------\n");
-//		printf("index = %d \n", _index);
-//		printf("StartSchedule = %s \n", ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.StartSchedule);
-//		printf("ChargingRateUnit = %s \n", ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingRateUnit);
-//		printf("----------SchedulePeriod---------\n");
-//		for (int v = 0; v < 10; v++)
-//		{
-//			printf("StartPeriod = %d \n", ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[v].StartPeriod);
-//			printf("Limit = %f \n", ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[v].Limit);
-//		}
-//		printf("---------------------------------\n");
-	}
-}
-
-void CheckReturnToChargingConn()
-{
-	if ((ShmSysConfigAndInfo->SysConfig.TotalConnectorCount + ShmSysConfigAndInfo->SysConfig.AcConnectorCount) > 1 &&
-		ShmSysConfigAndInfo->SysInfo.PageIndex != _LCM_AUTHORIZING &&
-		ShmSysConfigAndInfo->SysInfo.PageIndex != _LCM_AUTHORIZ_FAIL &&
-		ShmSysConfigAndInfo->SysInfo.PageIndex != _LCM_AUTHORIZ_COMP &&
-		ShmSysConfigAndInfo->SysInfo.PageIndex != _LCM_WAIT_FOR_PLUG)
-	{
-		bool isReturnTimeout = false;
-		for (byte count = 0; count < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; count++)
-		{
-			if (count != ShmSysConfigAndInfo->SysInfo.CurGunSelected)
-			{
-				if ((chargingInfo[count]->SystemStatus >= S_REASSIGN_CHECK && chargingInfo[count]->SystemStatus <= S_COMPLETE) ||
-						(chargingInfo[count]->SystemStatus >= S_CCS_PRECHARGE_ST0 && chargingInfo[count]->SystemStatus <= S_CCS_PRECHARGE_ST1))
-				{
-					isReturnTimeout = true;
-					StartSystemTimeoutDet(Timeout_ReturnToChargingGunDet);
-				}
-			}
-		}
-
-		// AC 槍
-		if (!isReturnTimeout && ShmSysConfigAndInfo->SysConfig.AcConnectorCount > 0)
-		{
-			// 沒有選中 AC,且 AC 在充電中
-			if (ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc == NO_DEFINE &&
-					(ac_chargingInfo[0]->SystemStatus >= S_PREPARNING && ac_chargingInfo[0]->SystemStatus <= S_COMPLETE))
-			{
-				// 當前 DC 充電槍在 idle 狀態
-				if (chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus == S_IDLE ||
-						chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus == S_RESERVATION)
-				{
-					isReturnTimeout = true;
-					StartSystemTimeoutDet(Timeout_ReturnToChargingGunDet);
-				}
-			}
-			else if (ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc == DEFAULT_AC_INDEX &&
-						((chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus >= S_REASSIGN_CHECK && chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus <= S_COMPLETE) ||
-						(chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus >= S_CCS_PRECHARGE_ST0 && chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus <= S_CCS_PRECHARGE_ST1)))
-			{
-				// 當前 DC 充電槍在 idle 狀態
-				if (ac_chargingInfo[0]->SystemStatus == S_IDLE ||
-						ac_chargingInfo[0]->SystemStatus == S_RESERVATION)
-				{
-					isReturnTimeout = true;
-					StartSystemTimeoutDet(Timeout_ReturnToChargingGunDet);
-				}
-			}
-		}
-
-		if (!isReturnTimeout)
-			StopSystemTimeoutDet();
-	}
-}
-
-bool GetStartChargingByAlterMode(byte _gun)
-{
-	bool result = true;
-
-	if (ShmSysConfigAndInfo->SysConfig.TotalConnectorCount == 2 &&
-			ShmSysConfigAndInfo->SysInfo.IsAlternatvieConf == YES)
-	{
-		for (byte _select = 0; _select < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _select++)
-		{
-			if (_select != _gun)
-			{
-				if (chargingInfo[_select]->SystemStatus != S_IDLE &&
-						chargingInfo[_select]->SystemStatus != S_RESERVATION)
-				{
-					result = false;
-					break;
-				}
-			}
-		}
-	}
-
-	return result;
-}
-
-int main(void)
-{
-	if(CreateShareMemory() == 0)
-	{
-		#ifdef SystemLogMessage
-		DEBUG_ERROR_MSG("CreatShareMemory NG \n");
-		#endif
-		if(ShmStatusCodeData!=NULL)
-		{
-			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory = 1;
-		}
-		sleep(5);
-		system("reboot -f");
-		sleep(5);
-		system("reboot -f");
-	}
-
-	PRINTF_FUNC("Chademo = %d, CCS = %d, GB = %d, AC = %d \n",
-			CHAdeMO_QUANTITY, CCS_QUANTITY, GB_QUANTITY, AC_QUANTITY);
-	PRINTF_FUNC("\n"); PRINTF_FUNC("Initial SystemConfig and Info.......\n");
-	if (!InitialSystemDefaultConfig())
-	{
-		DEBUG_ERROR_MSG("InitialSystemDefaultConfig NG \n");
-		StopProcessingLoop();
-	}
-
-	PRINTF_FUNC("CheckConnectorTypeStatus. \n");
-	CheckGunTypeFromHw();
-	PRINTF_FUNC("CheckIsAlternatvieByModelName. \n");
-	CheckIsAlternatvieByModelName();
-	PRINTF_FUNC("ModelName = %s\n", ShmSysConfigAndInfo->SysConfig.ModelName);
-	PRINTF_FUNC("InitialShareMemoryInfo \n");
-	InitialShareMemoryInfo();
-	PRINTF_FUNC("ChargerType (IEC or UL) = %d \n", ShmSysConfigAndInfo->SysInfo.ChargerType);
-	ChangeLcmByIndex(_LCM_INIT);
-	if (!CheckConnectorTypeStatus())
-		isModelNameMatch = false;
-
-	Initialization();
-	PRINTF_FUNC("Spawn all Task. \n");
-	SpawnTask();
-	if (!isModelNameMatch)
-	{
-		PRINTF_FUNC("Module Name & HW info none match. \n");
-		ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ModelNameNoneMatchStestFail = YES;
-		ChangeLcmByIndex(_LCM_FIX);
-		// Module Name 與硬體對應不正確
-		DEBUG_ERROR_MSG("Module Name & HW info none match. \n");
-		sleep(3);
-		KillTask();
-		StopProcessingLoop();
-	}
-	PRINTF_FUNC("Module Name & HW info correct. Initialize.......\n");
-	CreateTimeoutFork();
-	PRINTF_FUNC("Self test. \n");
-	SelfTestRun();
-	StopSystemTimeoutDet();
-	PRINTF_FUNC("SelfTestSeq = %d, Work_Step = %d \n", ShmSysConfigAndInfo->SysInfo.SelfTestSeq, ShmPsuData->Work_Step);
-	if (ShmSysConfigAndInfo->SysInfo.SelfTestSeq == _STEST_FAIL ||
-			ShmPsuData->Work_Step == _NO_WORKING)
-	{
-		if (ShmSysConfigAndInfo->SysWarningInfo.Level != 2)
-			DisplaySelfTestFailReason();
-
-		for (byte gun_index = 0; gun_index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gun_index++)
-		{
-			setChargerMode(gun_index, MODE_ALARM);
-		}
-		ChangeLcmByIndex(_LCM_FIX);
-		sleep(3);
-		KillTask();
-		StopProcessingLoop();
-	}
-	else
-	{
-		for (byte gun_index = 0; gun_index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gun_index++)
-		{
-			setChargerMode(gun_index, MODE_IDLE);
-		}
-	}
-
-	// Local DB
-	if(DB_Open(localDb) != PASS)
-	{
-		PRINTF_FUNC("DB_Open fail. \n");
-		isDb_ready = false;
-	}
-	else
-	{
-		isDb_ready = true;
-		for(int _index=0; _index< ShmSysConfigAndInfo->SysConfig.TotalConnectorCount;_index++)
-		{
-			chargingInfo[_index]->IsAvailable = DB_Get_Operactive(localDb, _index);
-		}
-	}
-
-	ChangeLcmByIndex(_LCM_IDLE);
-	sleep(1);
-	//***** 須新增的偵測 *****//
-	// 1. Thernal - 控制風扇轉速
-	// 2. ouput fuse - 控制風扇轉速
-	CreateRfidFork();
-	// Create Watchdog
-	//CreateWatchdog();
-	// Main loop
-	PRINTF_FUNC("****************************Main Loop********************************** \n");
-	gettimeofday(&_cmdMainPriority_time, NULL);
-	for (;;)
-	{
-		CheckOcppStatus();
-		ChkPrimaryStatus();
-		if ((IsConnectorWholeIdle() || ShmSysConfigAndInfo->SysInfo.PageIndex == _LCM_FIX) &&
-				ShmSysConfigAndInfo->SysInfo.SystemTimeoutFlag != Timeout_ReturnToChargingGunDet)
-		{
-			CheckFactoryConfigFunction();
-
-			CheckFwUpdateFunction();
-		}
-
-		// OCPP 邏輯
-		OcppRemoteStartChk();
-		// 讀卡邏輯
-		ScannerCardProcess();
-		// 當 AC 沒有搭上時,清除一些錯誤碼
-		ClearAlarmCodeWhenAcOff();
-		// 確認是否要回到充電中的槍畫面邏輯判斷
-		CheckReturnToChargingConn();
-
-		if (_acgunIndex > 0 && isDetectPlugin() && !isCardScan)
-		{
-			ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_WAIT_FOR_PLUG;
-		}
-
-		if ((GetTimeoutValue(_cmdMainPriority_time) / 1000) > 5000)
-		{
-			CheckTask();
-			for (byte _index = 0; _index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _index++)
-			{
-				if (chargingInfo[_index]->SystemStatus == S_CHARGING)
-					CheckSmartChargeProfile(_index);
-			}
-
-			gettimeofday(&_cmdMainPriority_time, NULL);
-		}
-
-		for (byte gun_index = 0; gun_index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gun_index++)
-		{
-			CheckGpioInStatus();
-			CheckErrorOccurStatus(gun_index);
-			ChkOcppStatus(gun_index);
-
-			//PRINTF_FUNC("index = %d, ErrorCode = %s \n", gun_index, ShmOCPP16Data->StatusNotification[gun_index].ErrorCode);
-			switch(chargingInfo[gun_index]->SystemStatus)
-			{
-				case S_IDLE:
-				case S_RESERVATION:
-				case S_MAINTAIN:
-				{
-					if (chargingInfo[gun_index]->SystemStatus == S_IDLE &&
-							isModeChange(gun_index))
-					{
-						PRINTF_FUNC("S_IDLE================================== %x \n", gun_index);
-						chargingInfo[gun_index]->PresentChargedDuration = 0;
-						chargingInfo[gun_index]->RemainChargingDuration = 0;
-						strcpy((char *)chargingInfo[gun_index]->StartDateTime, "");
-						strcpy((char *)chargingInfo[gun_index]->StopDateTime, "");
-						strcpy((char *)chargingInfo[gun_index]->StartUserId, "");
-						strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "");
-					}
-					else if (chargingInfo[gun_index]->SystemStatus == S_RESERVATION &&
-							isModeChange(gun_index))
-					{
-						PRINTF_FUNC("S_RESERVATION....................%x \n", gun_index);
-						ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = YES;
-					}
-
-					if (chargingInfo[gun_index]->IsAvailable == NO)
-					{
-						setChargerMode(gun_index, MODE_MAINTAIN);
-					}
-
-					if (ShmSysConfigAndInfo->SysWarningInfo.Level == 2)
-					{
-						if (gun_index == ShmSysConfigAndInfo->SysInfo.CurGunSelected)
-						{
-							ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_FIX;
-						}
-						ClearDetectPluginFlag();
-					}
-					else if (ShmSysConfigAndInfo->SysConfig.OfflinePolicy == _OFFLINE_POLICY_NO_CHARGING)
-					{/* 							不給充電							*/}
-					else
-					{
-						if (ShmSysConfigAndInfo->SysInfo.SystemPage == _LCM_FIX)
-						{
-							ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
-						}
-
-						if (ShmSysConfigAndInfo->SysInfo.MainChargingMode == _MAIN_CHARGING_MODE_AVER)
-						{
-							if (ShmSysConfigAndInfo->SysInfo.AcContactorStatus == YES)
-							{
-								// 均充 -> 最大充
-								if (ShmSysConfigAndInfo->SysInfo.BridgeRelayStatus == NO)
-								{
-									if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag == _REASSIGNED_NONE)
-									{
-										PRINTF_FUNC("=============Smart Charging============= Step 11 \n");
-										ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_PREPARE_A_TO_M;
-									}
-								}
-								else if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag != _REASSIGNED_COMP &&
-										ShmSysConfigAndInfo->SysInfo.ReAssignedFlag != _REASSIGNED_WAITING)
-								{
-									PRINTF_FUNC("=============Smart Charging============= Step 14 \n");
-									ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_WAITING;
-								}
-								else if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag == _REASSIGNED_COMP)
-								{
-									ShmSysConfigAndInfo->SysInfo.MainChargingMode = _MAIN_CHARGING_MODE_MAX;
-									ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_NONE;
-								}
-							}
-							else
-							{
-								ShmSysConfigAndInfo->SysInfo.MainChargingMode = _MAIN_CHARGING_MODE_MAX;
-								ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_NONE;
-							}
-						}
-						else
-							ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_NONE;
-
-						{ // Idle 正常程序起點
-							// 判斷是否有啟用檢查插槍
-							if(isDetectPlugin())
-							{
-								// 卡號驗證成功後,等待充電槍插入充電車
-								if (chargingInfo[gun_index]->RemoteStartFlag == YES)
-								{
-									if (chargingInfo[gun_index]->ConnectorPlugIn == YES &&
-											chargingInfo[gun_index]->IsAvailable)
-									{
-										PRINTF_FUNC("-----------------1----------------- %d \n", gun_index);
-										chargingInfo[gun_index]->RemoteStartFlag = NO;
-										ChangeGunSelectByIndex(gun_index);
-										AddPlugInTimes(gun_index);
-										setChargerMode(gun_index, MODE_REASSIGN_CHECK);
-										strcpy((char *)chargingInfo[gun_index]->StartUserId, "");
-										ClearDetectPluginFlag();
-										continue;
-									}
-								}
-								else if (ShmSysConfigAndInfo->SysInfo.OrderCharging == NO_DEFINE)
-								{
-									if (chargingInfo[gun_index]->ConnectorPlugIn == YES && chargingInfo[gun_index]->IsAvailable &&
-											chargingInfo[gun_index]->SystemStatus == S_IDLE)
-									{
-										PRINTF_FUNC("-----------------2----------------- \n");
-										ChangeGunSelectByIndex(gun_index);
-										AddPlugInTimes(gun_index);
-										strcpy((char *)chargingInfo[gun_index]->StartUserId, (char *)ShmSysConfigAndInfo->SysConfig.UserId);
-										PRINTF_FUNC("index = %d, CardNumber = %s \n", gun_index, chargingInfo[gun_index]->StartUserId);
-										strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
-										// 當前操作的槍號,進入 Preparing
-										setChargerMode(gun_index, MODE_REASSIGN_CHECK);
-										ClearDetectPluginFlag();
-										continue;
-									}
-								}
-
-								if (!isCardScan)
-								{
-									// LCM => Waiting for plugging
-									ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_WAIT_FOR_PLUG;
-								}
-							}
-							else if (chargingInfo[gun_index]->SystemStatus == S_RESERVATION)
-							{
-								if (!isReservationExpired(gun_index))
-								{
-									chargingInfo[gun_index]->SystemStatus = S_IDLE;
-								}
-							}
-							else if (ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_DISABLE &&
-									(chargingInfo[gun_index]->ConnectorPlugIn == YES && chargingInfo[gun_index]->IsAvailable))
-							{
-								PRINTF_FUNC("-----------------3----------------- \n");
-								bool isCanStartChargingFlag = GetStartChargingByAlterMode(gun_index);
-
-								if (isCanStartChargingFlag)
-								{
-									ChangeGunSelectByIndex(gun_index);
-									AddPlugInTimes(gun_index);
-									setChargerMode(gun_index, MODE_REASSIGN_CHECK);
-									ClearDetectPluginFlag();
-									continue;
-								}
-							}
-							else
-							{
-								if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index)
-									ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_IDLE;
-							}
-						} // Idle 正常程序終點
-					}
-
-					ReleaseAlarmCode(gun_index);
-				}
-					break;
-				case S_REASSIGN_CHECK:
-				{
-					if (isModeChange(gun_index))
-					{
-						PRINTF_FUNC("S_REASSIGN_CHECK================================== %x \n", gun_index);
-						ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
-						if (ShmSysConfigAndInfo->SysInfo.OrderCharging != NO_DEFINE)
-							ShmSysConfigAndInfo->SysInfo.OrderCharging = NO_DEFINE;
-						StopSystemTimeoutDet();
-					}
-
-					bool isRessign = false;
-					if (ShmSysConfigAndInfo->SysConfig.TotalConnectorCount > 1 && ShmSysConfigAndInfo->SysInfo.IsAlternatvieConf == NO)
-					{
-						if (ShmSysConfigAndInfo->SysInfo.MainChargingMode == _MAIN_CHARGING_MODE_MAX)
-						{
-							for (byte index = 0; index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; index++)
-							{
-								// 有其他槍已經分配好 psu 模塊
-								if (ShmSysConfigAndInfo->SysInfo.CurGunSelected != index &&
-										chargingInfo[index]->SystemStatus >= S_PREPARNING)
-								{
-									PRINTF_FUNC("=============Smart Charging============= Step 1 \n");
-									ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_PREPARE_M_TO_A;
-									isRessign = true;
-									break;
-								}
-							}
-						}
-						else if (ShmSysConfigAndInfo->SysInfo.MainChargingMode == _MAIN_CHARGING_MODE_AVER &&
-								ShmSysConfigAndInfo->SysInfo.ReAssignedFlag != _REASSIGNED_NONE)
-						{
-							// 如果在切換最大充的過程中,需等待最大充切換完成後,在走均充流程
-							if (ShmSysConfigAndInfo->SysInfo.BridgeRelayStatus == YES)
-							{
-								if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag != _REASSIGNED_COMP &&
-										ShmSysConfigAndInfo->SysInfo.ReAssignedFlag != _REASSIGNED_WAITING)
-								{
-									PRINTF_FUNC("=============Smart Charging============= Step 14 \n");
-									ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_WAITING;
-								}
-								else if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag == _REASSIGNED_COMP)
-								{
-									ShmSysConfigAndInfo->SysInfo.MainChargingMode = _MAIN_CHARGING_MODE_MAX;
-									ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_NONE;
-								}
-							}
-
-							if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index)
-								ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_PRE_CHARGE;
-							continue;
-						}
-					}
-
-					if (isRessign)
-						setChargerMode(gun_index, MODE_REASSIGN);
-					else
-						setChargerMode(gun_index, MODE_PRECHARGE);
-
-					if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index)
-						ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_PRE_CHARGE;
-				}
-					break;
-				case S_REASSIGN:
-				{
-					if (isModeChange(gun_index))
-					{
-						PRINTF_FUNC("S_REASSIGN================================== %x \n", gun_index);
-						gettimeofday(&_toAverage_time, NULL);
-					}
-
-					// 重新分配,此階段主要是讓已經在充電或者準備進入充電前的緩衝
-					// 此狀態下~ 控制權在於 PSU 及 EV小板 Process
-					if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag == _REASSIGNED_NONE ||
-							ShmSysConfigAndInfo->SysInfo.MainChargingMode == _MAIN_CHARGING_MODE_AVER)
-					{
-						if (ShmSysConfigAndInfo->SysInfo.CanAverageCharging)
-							setChargerMode(gun_index, MODE_PRECHARGE);
-						else
-							setChargerMode(gun_index, MODE_IDLE);
-					}
-					else if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag == _REASSIGNED_RELAY_M_TO_A &&
-						ShmSysConfigAndInfo->SysInfo.BridgeRelayStatus == NO)
-					{
-						PRINTF_FUNC("=============Smart Charging : _REASSIGNED_COMP============= Step 6 \n");
-						ShmSysConfigAndInfo->SysInfo.MainChargingMode = _MAIN_CHARGING_MODE_AVER;
-						ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_NONE;
-					}
-
-					//PRINTF_FUNC("CurGunSelected = %d, gun_index = %d \n", ShmSysConfigAndInfo->SysInfo.CurGunSelected, gun_index);
-					if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index)
-						ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_PRE_CHARGE;
-				}
-					break;
-				case S_PREPARNING:
-				{
-					if (isModeChange(gun_index))
-					{
-						PRINTF_FUNC("S_PREPARNING================================== %x \n", gun_index);
-						StopGunInfoTimeoutDet(gun_index);
-						StartGunInfoTimeoutDet(gun_index, Timeout_Preparing);
-					}
-
-					if (ShmPsuData->SystemPresentPsuQuantity > 0 && ShmPsuData->SystemAvailablePower > 10 &&
-							GetTimeoutValue(chargingInfo[gun_index]->TimeoutTimer) >= 5000000)
-					{
-						setChargerMode(gun_index, MODE_PREPARE_FOR_EV);
-					}
-
-					if (isEvBoardStopChargeFlag(gun_index) == YES || OcppRemoteStop(gun_index) == YES)
-					{
-						// 板端或後臺要求停止
-						ChargingTerminalProcess(gun_index);
-					}
-
-					if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index)
-						ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_PRE_CHARGE;
-				}
-					break;
-				case S_PREPARING_FOR_EV: // 等待車端的通訊 (EV 小板),待車端回報後,開始樁端的測試
-				{
-					if (isModeChange(gun_index))
-					{
-						PRINTF_FUNC("S_PREPARING_FOR_EV================================== %x \n", gun_index);
-						//strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
-						StopGunInfoTimeoutDet(gun_index);
-						StartGunInfoTimeoutDet(gun_index, Timeout_EvChargingDet);
-					}
-
-					if (chargingInfo[gun_index]->Type == _Type_Chademo)
-					{
-						// 檢查車端的槍鎖是否為鎖上
-						if (isEvGunLocked_chademo(gun_index) == YES)
-						{
-							setChargerMode(gun_index, MODE_PREPARE_FOR_EVSE);
-						}
-					}
-					else if (chargingInfo[gun_index]->Type == _Type_GB)
-					{
-						// 檢查車端的 charging enable 是否為 1
-						if (isEvGunLocked_gb(gun_index) == YES)
-						{
-							setChargerMode(gun_index, MODE_PREPARE_FOR_EVSE);
-						}
-					}
-					else if (chargingInfo[gun_index]->Type == _Type_CCS_2)
-					{
-						// 檢查車端的 charging enable 是否為 1
-						if (isEvGunLocked_ccs(gun_index) == YES)
-						{
-							setChargerMode(gun_index, MODE_PREPARE_FOR_EVSE);
-						}
-					}
-
-					if (isEvBoardStopChargeFlag(gun_index) == YES  ||
-							OcppRemoteStop(gun_index) == YES)
-					{
-						// 板端或後臺要求停止
-						ChargingTerminalProcess(gun_index);
-					}
-
-					// LCM => Pre-charging
-					if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index)
-						ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_PRE_CHARGE;
-				}
-					break;
-				case S_PREPARING_FOR_EVSE: // 等待 RB 通訊及測試,並將狀態回報, CSU 確認 Pass 後,開始進入充電
-				{
-					if (isModeChange(gun_index))
-					{
-						PRINTF_FUNC("S_PREPARING_FOR_EVSE================================== %x \n", gun_index);
-						StopGunInfoTimeoutDet(gun_index);
-						StartGunInfoTimeoutDet(gun_index, Timeout_EvseChargingDet);
-					}
-
-					if (chargingInfo[gun_index]->Type == _Type_Chademo)
-					{
-						// 檢查樁端的 GFD 結果
-						if (isPrechargeStatus_chademo(gun_index) > 5 && isPrechargeStatus_chademo(gun_index) < 8)
-						{
-							// 當前操作的槍號,進入 Charging
-							setChargerMode(gun_index, MODE_CHARGING);
-						}
-
-						if (chargingInfo[gun_index]->GroundFaultStatus == GFD_FAIL)
-						{
-							// GFD 錯誤停止
-							RecordAlarmCode(gun_index, "012234");
-						}
-						else if (chargingInfo[gun_index]->GroundFaultStatus == GFD_WARNING)
-						{
-							// GFD 警告
-							RecordWarningCode(gun_index, "012296");
-						}
-					}
-					else if (chargingInfo[gun_index]->Type == _Type_GB)
-					{
-						// 檢查樁端的 GFD 結果
-						if (isPrechargeStatus_gb(gun_index) > 5 && isPrechargeStatus_gb(gun_index) < 9)
-						{
-							setChargerMode(gun_index, MODE_CHARGING);
-						}
-
-						if (chargingInfo[gun_index]->GroundFaultStatus == GFD_FAIL)
-						{
-							// GFD 錯誤停止
-							RecordAlarmCode(gun_index, "012236");
-						}
-						else if (chargingInfo[gun_index]->GroundFaultStatus == GFD_WARNING)
-						{
-							// GFD 警告
-							RecordWarningCode(gun_index, "012298");
-						}
-					}
-					else if (chargingInfo[gun_index]->Type == _Type_CCS_2)
-					{
-						// 檢查樁端的 GFD 結果
-						if ((chargingInfo[gun_index]->GroundFaultStatus == GFD_PASS ||
-								chargingInfo[gun_index]->GroundFaultStatus == GFD_WARNING))
-						{
-							setChargerMode(gun_index, MODE_CCS_PRECHARGE_STEP0);
-						}
-
-						if (chargingInfo[gun_index]->GroundFaultStatus == GFD_FAIL)
-						{
-							// GFD 錯誤停止
-							RecordAlarmCode(gun_index, "012235");
-						}
-						else if (chargingInfo[gun_index]->GroundFaultStatus == GFD_WARNING)
-						{
-							// GFD 警告
-							RecordWarningCode(gun_index, "012297");
-						}
-					}
-
-					if (isEvBoardStopChargeFlag(gun_index) == YES ||
-							chargingInfo[gun_index]->GroundFaultStatus == GFD_FAIL ||
-							OcppRemoteStop(gun_index) == YES)
-					{
-						// 板端或後臺要求停止
-						ChargingTerminalProcess(gun_index);
-					}
-
-					// LCM => Pre-charging
-					if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index)
-						ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_PRE_CHARGE;
-				}
-					break;
-				case S_CHARGING: // 剛進入充電狀態,等待 EV 小板要求的輸出電流後開始輸出
-				{
-					if (isModeChange(gun_index))
-					{
-						PRINTF_FUNC("S_CHARGING================================== %x \n", gun_index);
-						StopGunInfoTimeoutDet(gun_index);
-						ftime(&startChargingTime[gun_index]);
-						ChangeStartOrStopDateTime(YES, gun_index);
-						OcppStartTransation(gun_index);
-					}
-
-					if (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf)
-						ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = NO;
-
-					ftime(&endChargingTime[gun_index]);
-					chargingInfo[gun_index]->PresentChargedDuration = DiffTimeb(startChargingTime[gun_index], endChargingTime[gun_index]);
-
-					if (chargingInfo[gun_index]->Type == _Type_Chademo)
-					{
-						if (chargingInfo[gun_index]->GroundFaultStatus == GFD_FAIL)
-						{
-							// GFD 錯誤停止
-							RecordAlarmCode(gun_index, "012234");
-						}
-						else if (((chargingInfo[gun_index]->EvBatterytargetVoltage * 10) > 0 && chargingInfo[gun_index]->EvBatterytargetVoltage < SYSTEM_MIN_VOL) ||
-								(chargingInfo[gun_index]->PresentChargedDuration >= 10 && chargingInfo[gun_index]->PresentChargingVoltage < SYSTEM_MIN_VOL))
-						{
-							// UVP
-							RecordAlarmCode(gun_index, "012289");
-							ChargingTerminalProcess(gun_index);
-						}
-						else if (chargingInfo[gun_index]->GroundFaultStatus == GFD_WARNING)
-						{
-							// GFD 警告
-							RecordWarningCode(gun_index, "012296");
-						}
-						else
-							ReleaseWarningCodeByString(gun_index, "012296");
-					}
-					else if (chargingInfo[gun_index]->Type == _Type_GB)
-					{
-						if (chargingInfo[gun_index]->GroundFaultStatus == GFD_FAIL)
-						{
-							// GFD 錯誤停止
-							RecordAlarmCode(gun_index, "012236");
-						}
-						else if (isPrechargeStatus_gb(gun_index) == 10 &&
-								(((chargingInfo[gun_index]->EvBatterytargetVoltage * 10) > 0 && chargingInfo[gun_index]->EvBatterytargetVoltage < SYSTEM_MIN_VOL) ||
-								(chargingInfo[gun_index]->PresentChargedDuration >= 10 && chargingInfo[gun_index]->PresentChargingVoltage < SYSTEM_MIN_VOL)))
-						{
-							// UVP
-							RecordAlarmCode(gun_index, "012290");
-							ChargingTerminalProcess(gun_index);
-						}
-						else if (chargingInfo[gun_index]->GroundFaultStatus == GFD_WARNING)
-						{
-							// GFD 警告
-							RecordWarningCode(gun_index, "012298");
-						}
-						else
-							ReleaseWarningCodeByString(gun_index, "012298");
-					}
-					else if (chargingInfo[gun_index]->Type == _Type_CCS_2)
-					{
-						if (chargingInfo[gun_index]->GroundFaultStatus == GFD_FAIL)
-						{
-							// GFD 錯誤停止
-							RecordAlarmCode(gun_index, "012235");
-						}
-						else if (((chargingInfo[gun_index]->EvBatterytargetVoltage * 10) > 0 && chargingInfo[gun_index]->EvBatterytargetVoltage < SYSTEM_MIN_VOL) ||
-								(chargingInfo[gun_index]->PresentChargedDuration >= 10 && chargingInfo[gun_index]->PresentChargingVoltage < SYSTEM_MIN_VOL))
-						{
-							// UVP
-							RecordAlarmCode(gun_index, "012288");
-							ChargingTerminalProcess(gun_index);
-						}
-						else if (chargingInfo[gun_index]->GroundFaultStatus == GFD_WARNING)
-						{
-							// GFD 警告
-							RecordWarningCode(gun_index, "012297");
-						}
-						else
-							ReleaseWarningCodeByString(gun_index, "012297");
-					}
-
-					if (isEvBoardStopChargeFlag(gun_index) ||
-							chargingInfo[gun_index]->GroundFaultStatus == GFD_FAIL ||
-							OcppRemoteStop(gun_index) ||
-							CheckBackendChargingTimeout(gun_index) ||
-							CheckBackendChargingEnergy(gun_index))
-					{
-						PRINTF_FUNC("S_CHARGING=======Stop=========================== %f \n", (chargingInfo[gun_index]->EvBatterytargetVoltage * 10));
-						// 板端或後臺要求停止
-						ChargingTerminalProcess(gun_index);
-					}
-
-					// LCM => Charging
-					if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index)
-						ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_CHARGING;
-				}
-					break;
-				case S_TERMINATING:
-				{
-					if (isModeChange(gun_index))
-					{
-						PRINTF_FUNC ("terminating......................... %x \n", gun_index);
-						if (strcmp((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "Remote") != EQUAL)
-							strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "EVDisconnected");
-						StopGunInfoTimeoutDet(gun_index);
-					}
-
-					bool toComplete = false;
-					if (chargingInfo[gun_index]->Type == _Type_Chademo)
-					{
-						// 非車端的停止 : 需等待小板送出停止指令,讓車端解除槍
-						if (isEvStopCharging_chademo(gun_index) == YES ||
-								isPrechargeStatus_chademo(gun_index) <= 0)
-						{
-							toComplete = true;
-							setChargerMode(gun_index, MODE_COMPLETE);
-						}
-					}
-					else if (chargingInfo[gun_index]->Type == _Type_GB)
-					{
-						PRINTF_FUNC("************ GB lock Status = %d, status = %d \n", isEvStopCharging_gb(gun_index), isPrechargeStatus_gb(gun_index));
-						// 非車端的停止 : 需等待小板送出停止指令,讓車端解除槍
-						if (isEvStopCharging_gb(gun_index) == YES ||
-								isPrechargeStatus_gb(gun_index) <= 0)
-						{
-							toComplete = true;
-							setChargerMode(gun_index, MODE_COMPLETE);
-						}
-					}
-					else if (chargingInfo[gun_index]->Type == _Type_CCS_2)
-					{
-						// 非車端的停止 : 需等待小板送出停止指令,讓車端解除槍
-						if (isEvStopCharging_ccs(gun_index) == YES &&
-								(isPrechargeStatus_ccs(gun_index) >= 53 || isPrechargeStatus_ccs(gun_index) == 0 ||
-										isPrechargeStatus_ccs(gun_index) == 13 || isPrechargeStatus_ccs(gun_index) == 14))
-						{
-							toComplete = true;
-							setChargerMode(gun_index, MODE_COMPLETE);
-						}
-					}
-
-					if (!toComplete)
-					{
-						if (strcmp((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "Remote") != EQUAL)
-							strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "Local");
-					}
-
-
-					if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index)
-						ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_COMPLETE;
-				}
-					break;
-				case S_COMPLETE:
-				{
-					if (isModeChange(gun_index))
-					{
-						PRINTF_FUNC ("complete......................... %x \n", gun_index);
-						OcppStopTransation(gun_index);
-						ftime(&endChargingTime[gun_index]);
-						if (chargingInfo[gun_index]->PresentChargedDuration != 0)
-							chargingInfo[gun_index]->PresentChargedDuration = DiffTimeb(startChargingTime[gun_index], endChargingTime[gun_index]);
-
-						StopGunInfoTimeoutDet(gun_index);
-						StartGunInfoTimeoutDet(gun_index, Timeout_EvseCompleteDet);
-						ChangeStartOrStopDateTime(NO, gun_index);
-					}
-
-					if(chargingInfo[gun_index]->ConnectorPlugIn == NO &&
-							GetTimeoutValue(chargingInfo[gun_index]->TimeoutTimer) >= 10000000)
-					{
-						setChargerMode(gun_index, MODE_IDLE);
-					}
-
-					if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index)
-						ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_COMPLETE;
-				}
-					break;
-				case S_CCS_PRECHARGE_ST0:
-				{
-					if (isModeChange(gun_index))
-					{
-						PRINTF_FUNC("CCS Precharge Processing 1....................%x \n", gun_index);
-						StopGunInfoTimeoutDet(gun_index);
-						StartGunInfoTimeoutDet(gun_index, Timeout_ForCcsPrechargeDet);
-					}
-
-					if (chargingInfo[gun_index]->GroundFaultStatus == GFD_FAIL)
-					{
-						// GFD 錯誤停止
-						RecordAlarmCode(gun_index, "012235");
-					}
-
-					if (isEvBoardStopChargeFlag(gun_index) == YES ||
-							chargingInfo[gun_index]->GroundFaultStatus == GFD_FAIL)
-					{
-						// 板端要求停止
-						ChargingTerminalProcess(gun_index);
-					}
-
-					// 等待 EV 小板 (CCS) 通知可以開始 Precharge
-					// 切換 D+ Relay to Precharge Relay
-					if (isPrechargeStatus_ccs(gun_index) == 39 || isPrechargeStatus_ccs(gun_index) == 40)
-					{
-						if (chargingInfo[gun_index]->RelayKPK2Status == YES && chargingInfo[gun_index]->PrechargeStatus != PRECHARGE_READY)
-						//if (chargingInfo[gun_index]->PrechargeStatus != PRECHARGE_PRERELAY_PASS)
-						{
-							PRINTF_FUNC("Send precharge ready 1..........%x, status = %d \n", gun_index, isPrechargeStatus_ccs(gun_index));
-							chargingInfo[gun_index]->PrechargeStatus = PRECHARGE_READY;
-						}
-					}
-					else if (isPrechargeStatus_ccs(gun_index) == 45 || isPrechargeStatus_ccs(gun_index) == 46)
-					{
-						setChargerMode(gun_index, MODE_CCS_PRECHARGE_STEP1);
-					}
-
-					break;
-				}
-				case S_CCS_PRECHARGE_ST1:
-				{
-					if (isModeChange(gun_index))
-					{
-						PRINTF_FUNC("CCS Precharge Processing 2....................%x \n", gun_index);
-					}
-
-					if (chargingInfo[gun_index]->GroundFaultStatus == GFD_FAIL)
-					{
-						// GFD 錯誤停止
-						RecordAlarmCode(gun_index, "012235");
-					}
-
-					if (isEvBoardStopChargeFlag(gun_index) == YES ||
-							chargingInfo[gun_index]->GroundFaultStatus == GFD_FAIL)
-					{
-						// 板端要求停止
-						ChargingTerminalProcess(gun_index);
-					}
-
-					// 等待小板通知進入充電
-					// 切換 D+ Relay to Precharge Relay
-					if (chargingInfo[gun_index]->RelayK1K2Status == YES)
-					{
-						chargingInfo[gun_index]->PrechargeStatus = PRECHARGE_READY;
-						setChargerMode(gun_index, MODE_CHARGING);
-					}
-					break;
-				}
-			}
-		}
-
-		if (ShmSysConfigAndInfo->SysInfo.SystemPage != _LCM_NONE)
-		{
-			ChangeLcmByIndex(ShmSysConfigAndInfo->SysInfo.SystemPage);
-		}
-		else
-		{
-			bool dcPageRun = false;
-			if (_acgunIndex > 0 && ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc != NO_DEFINE)
-			{
-				if  (ac_chargingInfo[0]->SystemStatus == S_IDLE)
-					ChangeLcmByIndex(_LCM_IDLE);
-				else if (ac_chargingInfo[0]->SystemStatus == S_PREPARNING)
-					ChangeLcmByIndex(_LCM_PRE_CHARGE);
-				else if (ac_chargingInfo[0]->SystemStatus == S_CHARGING)
-					ChangeLcmByIndex(_LCM_CHARGING);
-				else if (ac_chargingInfo[0]->SystemStatus == S_TERMINATING ||
-						ac_chargingInfo[0]->SystemStatus == S_COMPLETE)
-					ChangeLcmByIndex(_LCM_COMPLETE);
-				else
-					dcPageRun = true;
-			}
-			else
-				dcPageRun = true;
-
-			if (dcPageRun)
-				ChangeLcmByIndex(ShmSysConfigAndInfo->SysInfo.ConnectorPage);
-		}
-
-		write(wtdFd, "a", 1);
-		usleep(whileLoopTime);
-	}
-
-	return FAIL;
-}
+/*
+ * main.c
+ *
+ *  Created on: 2020年9月10日
+ *      Author: Wendell
+ */
+
+#include    <sys/types.h>
+#include    <sys/stat.h>
+#include 	<sys/time.h>
+#include 	<sys/timeb.h>
+#include 	<sys/types.h>
+#include 	<sys/ioctl.h>
+#include 	<sys/socket.h>
+#include 	<sys/ipc.h>
+#include 	<sys/shm.h>
+#include 	<sys/mman.h>
+#include 	<linux/wireless.h>
+#include 	<arpa/inet.h>
+#include 	<netinet/in.h>
+
+#include 	<unistd.h>
+#include 	<stdarg.h>
+#include    <stdio.h>      /*標準輸入輸出定義*/
+#include    <stdlib.h>     /*標準函數庫定義*/
+#include    <unistd.h>     /*Unix 標準函數定義*/
+#include    <fcntl.h>      /*檔控制定義*/
+#include    <termios.h>    /*PPSIX 終端控制定義*/
+#include    <errno.h>      /*錯誤號定義*/
+#include 	<errno.h>
+#include 	<string.h>
+#include 	<stdint.h>
+#include	<time.h>
+#include	<ctype.h>
+#include 	<ifaddrs.h>
+#include 	<math.h>
+#include 	"../../define.h"
+#include 	"Config.h"
+#include 	<stdbool.h>
+#include 	<dirent.h>
+#include	"timeout.h"
+#include    "Module_EvComm.h"
+
+#define 	ARRAY_SIZE(A)		(sizeof(A) / sizeof(A[0]))
+#define 	PASS				1
+#define 	FAIL				-1
+#define 	BUFFER_SIZE			128
+#define 	YES					1
+#define 	NO					0
+#define 	NORMAL				0
+#define		ABNORMAL			1
+#define 	EQUAL				0
+#define 	BTN_RELEASE			0
+#define 	BTN_PRESS			1
+#define 	MAX_BUF 			64
+#define 	MtdBlockSize 		0x600000
+#define 	SYSFS_GPIO_DIR 		"/sys/class/gpio"
+#define		UPGRADE_FAN			0x02
+#define		UPGRADE_RB			0x03
+#define		UPGRADE_PRI			0x04
+#define		UPGRADE_AC			0x05
+#define		UPGRADE_LED			0x06
+#define		SYSTEM_MIN_VOL		150
+#define 	MIN_OUTPUT_CUR		0
+#define		AC_OUTPUT_VOL		220
+
+#define		NO_DEFINE			255
+#define 	DEFAULT_AC_INDEX	2
+#define  	PSU_MIN_CUR			100
+
+#define 	DB_FILE				"/Storage/ChargeLog/localCgargingRecord.db"
+
+#define 	uSEC_VAL				1000000
+#define		SELFTEST_TIMEOUT		45
+#define		AUTHORIZE_TIMEOUT		30
+#define 	AUTHORIZE_COMP_TIMEOUT	1
+#define 	AUTHORIZE_FAIL_TIMEOUT	3
+#define 	AUTHORIZE_STOP_TIMEOUT	30
+#define 	RETURN_TO_CHARGING_PAGE	30
+#define		GUN_PREPARE_TIMEOUT		30
+#define		GUN_EV_WAIT_TIMEOUT		120
+#define		GUN_EVSE_WAIT_TIMEOUT	60
+#define		GUN_COMP_WAIT_TIMEOUT	10
+#define		GUN_PRECHARGING_TIMEOUT	60
+
+char 	*valid_Internet[2] 	  = {"8.8.8.8", "180.76.76.76"};
+unsigned char mask_table[] = { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 };
+int whileLoopTime = 10000; // 10 ms
+int	wtdFd = -1;
+byte _authorizeIndex = NO_DEFINE;
+
+bool IsAuthorizingMode();
+void ClearAuthorizedFlag();
+bool isDetectPlugin();
+void ClearDetectPluginFlag();
+int mystrcmp(unsigned char *p1, unsigned char *p2);
+
+long long DiffTimebWithNow(struct timeb ST);
+unsigned char DetectBitValue(unsigned char _byte, unsigned char _bit);
+void SetBitValue(unsigned char *_byte, unsigned char _bit, unsigned char value);
+void ChargingTerminalProcess(byte gunIndex);
+void ChkPrimaryStatus();
+void StartSystemTimeoutDet(unsigned char flag);
+void StopSystemTimeoutDet();
+void StartGunInfoTimeoutDet(unsigned char gunIndex, unsigned char flag);
+void StopGunInfoTimeoutDet(unsigned char gunIndex);
+int StoreLogMsg_1(const char *fmt, ...);
+unsigned long GetTimeoutValue(struct timeval _sour_time);
+void gpio_set_value(unsigned int gpio, unsigned int value);
+void PRINTF_FUNC(char *string, ...);
+void ChangeGunSelectByIndex(byte sel);
+void InformOcppErrOccur(byte codeType);
+
+void RecordAlarmCode(byte gunIndex, char *code);
+void RecordWarningCode(byte gunIndex, char *code);
+void ReleaseWarningCodeByString(byte gunIndex, char *code);
+void ReleaseAlarmCode(byte gunIndex);
+
+int DB_Open(sqlite3 *db);
+int DB_Insert_Record(sqlite3 *db, int gun_index);
+int DB_Update_Operactive(sqlite3 *db, uint8_t gun_index, uint8_t IsAvailable);
+int DB_Get_Operactive(sqlite3 *db, uint8_t gun_index);
+void InitialDHCP();
+void InitialDispenserDhcpServerConfig(void);
+void StartDispenserDhcpServer(void);
+void _SelfTestTimeout(void);
+void CheckConnectionTimeout(void);
+
+#define DEBUG_INFO_MSG(format, args...) PRINTF_FUNC("[%s:%d][%s][Info] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
+#define DEBUG_WARN_MSG(format, args...) PRINTF_FUNC("[%s:%d][%s][Warn] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
+#define DEBUG_ERROR_MSG(format, args...) PRINTF_FUNC("[%s:%d][%s][Error] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
+
+struct SysConfigAndInfo			*ShmSysConfigAndInfo;
+struct StatusCodeData 			*ShmStatusCodeData;
+struct PsuData 					*ShmPsuData;
+struct CHAdeMOData				*ShmCHAdeMOData;
+struct GBTData					*ShmGBTData;
+struct CcsData					*ShmCcsData;
+struct PrimaryMcuData			*ShmPrimaryMcuData;
+struct FanModuleData			*ShmFanModuleData;
+struct RelayModuleData			*ShmRelayModuleData[2];
+struct LedModuleData			*ShmLedModuleData;
+struct OCPP16Data				*ShmOCPP16Data;
+
+struct ChargingInfoData			*chargingInfo[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY + GENERAL_GUN_QUANTITY];
+struct ChargingInfoData			*ac_chargingInfo[AC_QUANTITY];
+struct timeb 					startChargingTime[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
+struct timeb 					endChargingTime[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
+
+struct timeval                  _ConnectorAuthorizing_Time[CONNECTOR_QUANTITY];
+struct timeval                  _DispenserAuthorizing_Time[CONNECTOR_QUANTITY];
+
+// for initial index to check EV board type is correct
+byte _gunIndex = 0;
+byte _acgunIndex = 0;
+byte _chademoIndex = 0;
+byte _ccsIndex = 0;
+byte _gb_Index = 0;
+byte _ac_Index = 0;
+//byte bd0_1_status = 0;
+//byte bd0_2_status = 0;
+//byte bd1_1_status = 0;
+//byte bd1_2_status = 0;
+
+bool isCardScan = false;
+bool isModelNameMatch = true;
+
+//int rfidFd = -1;
+//char* rfidPortName = "/dev/ttyS2";
+char* fwVersion = "V0.02.00.0000.00";
+
+sqlite3 *localDb;
+bool isDb_ready;
+
+//================================================
+// initial can-bus
+//================================================
+int InitCanBus()
+{
+	int 					s0,nbytes;
+	struct timeval			tv;
+	struct ifreq 			ifr0;
+	struct sockaddr_can		addr0;
+
+	system("/sbin/ip link set can0 down");
+	system("/sbin/ip link set can0 type can bitrate 500000 restart-ms 100");
+	system("/sbin/ip link set can0 up");
+
+	s0 = socket(PF_CAN, SOCK_RAW, CAN_RAW);
+
+	tv.tv_sec = 0;
+	tv.tv_usec = 10000;
+   	if (setsockopt(s0, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv, sizeof(struct	timeval)) < 0)
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR_MSG("Set SO_RCVTIMEO NG");
+		#endif
+	}
+	nbytes=40960;
+	if (setsockopt(s0, SOL_SOCKET,  SO_RCVBUF, &nbytes, sizeof(int)) < 0)
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR_MSG("Set SO_RCVBUF NG");
+		#endif
+	}
+	nbytes=40960;
+	if (setsockopt(s0, SOL_SOCKET, SO_SNDBUF, &nbytes, sizeof(int)) < 0)
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR_MSG("Set SO_SNDBUF NG");
+		#endif
+	}
+
+   	strcpy(ifr0.ifr_name, "can0" );
+	ioctl(s0, SIOCGIFINDEX, &ifr0); /* ifr.ifr_ifindex gets filled with that device's index */
+	addr0.can_family = AF_CAN;
+	addr0.can_ifindex = ifr0.ifr_ifindex;
+	bind(s0, (struct sockaddr *)&addr0, sizeof(addr0));
+	return s0;
+}
+
+//================================================
+// initial uart port
+//================================================
+char *_priPortName = "/dev/ttyS1";
+char *_485PortName = "/dev/ttyS5";
+
+int InitComPort(byte target)
+{
+	int fd;
+	struct termios tios;
+
+	if(target == UPGRADE_PRI)
+		fd = open(_priPortName, O_RDWR);
+	else if (target == UPGRADE_FAN ||  target == UPGRADE_RB || target == UPGRADE_AC || target == UPGRADE_LED)
+		fd = open(_485PortName, O_RDWR);
+
+	if(fd<=0)
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR_MSG("open 407 Communication port NG \n");
+		#endif
+		return -1;
+	}
+	ioctl (fd, TCGETS, &tios);
+	tios.c_cflag = B115200| CS8 | CLOCAL | CREAD;
+	tios.c_lflag = 0;
+	tios.c_iflag = 0;
+	tios.c_oflag = 0;
+	tios.c_cc[VMIN]=0;
+	tios.c_cc[VTIME]=(unsigned char)1;
+	tios.c_lflag=0;
+	tcflush(fd, TCIFLUSH);
+	ioctl (fd, TCSETS, &tios);
+
+	return fd;
+}
+
+//=================================
+// Common routine
+//=================================
+void substr(char *dest, const char* src, unsigned int start, unsigned int cnt)
+{
+	strncpy(dest, src + start, cnt);
+	dest[cnt] = 0;
+}
+
+int InitWatchDog()
+{
+	int fd;
+	system("/usr/bin/fuser -k /dev/watchdog");
+	sleep(1);
+	system("echo V > /dev/watchdog");
+	sleep(1);
+	fd=open("/dev/watchdog", O_RDWR);
+
+	if(fd<=0)
+	{
+		DEBUG_ERROR_MSG("System watch dog initial fail.\r\n");
+	}
+	return fd;
+}
+
+int StoreLogMsg_1(const char *fmt, ...)
+{
+	char Buf[4096+256];
+	char buffer[4096];
+	va_list args;
+	struct timeb  SeqEndTime;
+	struct tm *tm;
+
+	va_start(args, fmt);
+	int rc = vsnprintf(buffer, sizeof(buffer), fmt, args);
+	va_end(args);
+
+	memset(Buf,0,sizeof(Buf));
+	ftime(&SeqEndTime);
+	SeqEndTime.time = time(NULL);
+	tm=localtime(&SeqEndTime.time);
+
+	if (ShmSysConfigAndInfo->SysConfig.SwitchDebugFlag == YES)
+	{
+		sprintf(Buf,"%02d:%02d:%02d:%03d - %s",
+			tm->tm_hour,tm->tm_min,tm->tm_sec,SeqEndTime.millitm, buffer);
+		printf("%s \n", Buf);
+	}
+	else
+	{
+		sprintf(Buf,"echo \"%04d-%02d-%02d %02d:%02d:%02d:%03d - %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,SeqEndTime.millitm,
+			buffer,
+			tm->tm_year+1900,tm->tm_mon+1);
+		system(Buf);
+	}
+
+	return rc;
+}
+
+unsigned long GetTimeoutValue(struct timeval _sour_time)
+{
+	struct timeval _end_time;
+	gettimeofday(&_end_time, NULL);
+
+	return 1000000 * (_end_time.tv_sec - _sour_time.tv_sec) + _end_time.tv_usec - _sour_time.tv_usec;
+}
+
+int mystrcmp(unsigned char *p1, unsigned char *p2)
+{
+    while(*p1==*p2)
+    {
+        if(*p1=='\0' || *p2=='\0')
+            break;
+        p1++;
+        p2++;
+    }
+    if(*p1=='\0' && *p2=='\0')
+        return(PASS);
+    else
+        return(FAIL);
+}
+
+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;
+	return (StopTime-StartTime);
+}
+
+bool CheckTimeOut(struct timeb ST)
+{
+	struct timeb ET;
+	unsigned int StartTime, StopTime;
+
+	ftime(&ET);
+	StartTime = (unsigned int) ST.time;
+	StopTime = (unsigned int) ET.time;
+	return (StopTime > StartTime)? YES : NO;
+}
+
+void setChargerMode(byte gun_index, byte mode)
+{
+	chargingInfo[gun_index]->SystemStatus = mode;
+}
+
+void PRINTF_FUNC(char *string, ...)
+{
+	va_list args;
+	char buffer[4096];
+	va_start(args, string);
+	vsnprintf(buffer, sizeof(buffer), string, args);
+	va_end(args);
+
+	printf("%s \n", buffer);
+}
+
+long long DiffTimebWithNow(struct timeb ST)
+{
+	//return milli-second
+	struct timeb ET;
+	long long StartTime,StopTime;
+
+	ftime(&ET);
+	StartTime=(long long)ST.time;
+	StopTime=(long long)ET.time;
+	return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
+}
+/*
+//==========================================
+// Check interface status
+//==========================================
+int isInterfaceUp(const char *interface)
+{
+	int result = FAIL;
+
+	FILE *fp;
+	char cmd[256];
+	char buf[512];
+
+	strcpy(cmd, "ifconfig");
+	fp = popen(cmd, "r");
+	if(fp != NULL)
+	{
+		while(fgets(buf, sizeof(buf), fp) != NULL)
+		{
+			if(strstr(buf, interface) > 0)
+			{
+				result = PASS;
+			}
+		}
+	}
+	pclose(fp);
+
+	return result;
+}
+*/
+//=================================
+// Create all share memory
+//=================================
+int CreateShareMemory()
+{
+	int MeterSMId;
+
+	if ((MeterSMId = shmget(ShmSysConfigAndInfoKey,	sizeof(struct SysConfigAndInfo), IPC_CREAT | 0777)) < 0)
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR_MSG("[main]CreatShareMemory:shmget ShmSysConfigAndInfo NG \n");
+		#endif
+		return 0;
+	}
+	else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0))	== (void *) -1)
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR_MSG("[main]CreatShareMemory:shmat ShmSysConfigAndInfo NG \n");
+		#endif
+		return 0;
+	}
+	memset(ShmSysConfigAndInfo, 0, sizeof(struct SysConfigAndInfo));
+
+	if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), IPC_CREAT | 0777)) < 0)
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR_MSG("[main]CreatShareMemory:shmget ShmStatusCodeData NG \n");
+		#endif
+		return 0;
+	}
+	else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR_MSG("[main]CreatShareMemory:shmat ShmStatusCodeData NG \n");
+		#endif
+		return 0;
+	}
+
+	memset(ShmStatusCodeData, 0, sizeof(struct StatusCodeData));
+
+	//creat ShmPsuData
+	if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), IPC_CREAT | 0777)) < 0)
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR_MSG("[main]CreatShareMemory:shmget ShmPsuData NG \n");
+		#endif
+		return 0;
+	}
+	else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR_MSG("[main]CreatShareMemory:shmat ShmPsuData NG \n");
+		#endif
+		return 0;
+	}
+	memset(ShmPsuData, 0, sizeof(struct PsuData));
+/*
+	if(CHAdeMO_QUANTITY > 0)
+	{
+		if ((MeterSMId = shmget(ShmCHAdeMOCommKey, sizeof(struct CHAdeMOData),	IPC_CREAT | 0777)) < 0)
+		{
+			#ifdef SystemLogMessage
+			DEBUG_ERROR_MSG("[main]CreatShareMemory:shmget ShmCHAdeMOData NG \n");
+			#endif
+			return 0;
+		}
+		else if ((ShmCHAdeMOData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
+		{
+			#ifdef SystemLogMessage
+			DEBUG_ERROR_MSG("[main]CreatShareMemory:shmat ShmCHAdeMOData NG \n");
+			#endif
+			return 0;
+		}
+		memset(ShmCHAdeMOData, 0, sizeof(struct CHAdeMOData));
+	}
+
+	if(GB_QUANTITY > 0)
+	{
+		if ((MeterSMId = shmget(ShmGBTCommKey, sizeof(struct GBTData),	IPC_CREAT | 0777)) < 0)
+		{
+			#ifdef SystemLogMessage
+			DEBUG_ERROR_MSG("[main]CreatShareMemory:shmget ShmGBTData NG \n");
+			#endif
+			return 0;
+		}
+		else if ((ShmGBTData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
+		{
+			#ifdef SystemLogMessage
+			DEBUG_ERROR_MSG("[main]CreatShareMemory:shmat ShmGBTData NG \n");
+			#endif
+			return 0;
+		}
+		memset(ShmGBTData, 0, sizeof(struct GBTData));
+	}
+
+	//creat ShmCcsData
+	if(CCS_QUANTITY > 0)
+	{
+		if ((MeterSMId = shmget(ShmCcsCommKey, sizeof(struct CcsData),	IPC_CREAT | 0777)) < 0)
+		{
+			#ifdef SystemLogMessage
+			DEBUG_ERROR_MSG("[main]CreatShareMemory:shmget ShmCcsData NG \n");
+			#endif
+			return 0;
+		}
+		else if ((ShmCcsData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
+		{
+			#ifdef SystemLogMessage
+			DEBUG_ERROR_MSG("[main]CreatShareMemory:shmat ShmCcsData NG \n");
+			#endif
+			return 0;
+		}
+		memset(ShmCcsData, 0, sizeof(struct CcsData));
+	}
+*/
+	//creat ShmPrimaryMcuData
+	if ((MeterSMId = shmget(ShmPrimaryMcuKey, sizeof(struct PrimaryMcuData), IPC_CREAT | 0777)) < 0)
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR_MSG("[main]CreatShareMemory:shmget ShmPrimaryMcuData NG \n");
+		#endif
+		return 0;
+	}
+	else if ((ShmPrimaryMcuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR_MSG("[main]CreatShareMemory:shmat ShmPrimaryMcuData NG \n");
+		#endif
+		return 0;
+	}
+	memset(ShmPrimaryMcuData, 0, sizeof(struct PrimaryMcuData));
+
+	//creat ShmFanModuleData
+	if ((MeterSMId = shmget(ShmFanBdKey, sizeof(struct FanModuleData),	IPC_CREAT | 0777)) < 0)
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR_MSG("[main]CreatShareMemory:shmget ShmFanModuleData NG \n");
+		#endif
+		return 0;
+	}
+	else if ((ShmFanModuleData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR_MSG("[main]CreatShareMemory:shmat ShmFanModuleData NG \n");
+		#endif
+		return 0;
+	}
+	memset(ShmFanModuleData, 0, sizeof(struct FanModuleData));
+
+	//creat ShmRelayModuleData
+	if ((MeterSMId = shmget(ShmRelayBdKey, sizeof(struct RelayModuleData),	IPC_CREAT | 0777)) < 0)
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR_MSG("[main]CreatShareMemory:shmget ShmRelayModuleData[0] NG \n");
+		#endif
+		return 0;
+	}
+	else if ((ShmRelayModuleData[0] = shmat(MeterSMId, NULL, 0)) == (void *) -1)
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR_MSG("[main]CreatShareMemory:shmat ShmRelayModuleData[0] NG \n");
+		#endif
+		return 0;
+	}
+	memset(ShmRelayModuleData[0], 0, sizeof(struct RelayModuleData));
+
+	// DO360 RC2
+	if ((MeterSMId = shmget(ShmRelay2BdKey, sizeof(struct RelayModuleData), IPC_CREAT | 0777)) < 0)
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR_MSG("[main]CreatShareMemory:shmget ShmRelayModuleData[1] NG \n");
+		#endif
+		return 0;
+	}
+	else if ((ShmRelayModuleData[1] = shmat(MeterSMId, NULL, 0)) == (void *) -1)
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR_MSG("[main]CreatShareMemory:shmat ShmRelayModuleData[1] NG \n");
+		#endif
+		return 0;
+	}
+	memset(ShmRelayModuleData[1], 0, sizeof(struct RelayModuleData));
+
+	if ((MeterSMId = shmget(ShmLedBdKey, sizeof(struct LedModuleData), IPC_CREAT | 0777)) < 0)
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR_MSG("[main]CreatShareMemory:shmget ShmLedModuleData NG \n");
+		#endif
+		return 0;
+	}
+	else if ((ShmLedModuleData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR_MSG("[main]CreatShareMemory:shmat ShmLedModuleData NG \n");
+		#endif
+		return 0;
+	}
+	memset(ShmLedModuleData, 0, sizeof(struct LedModuleData));
+
+	//creat ShmOCPP16Data
+	if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), IPC_CREAT | 0777)) < 0)
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR_MSG("[main]CreatShareMemory:shmget ShmOCPP16Data NG \n");
+		#endif
+		return 0;
+	}
+	else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR_MSG("[main]CreatShareMemory:shmat ShmOCPP16Data NG \n");
+		#endif
+		return 0;
+	}
+	// memset(ShmOCPP16Data,0,sizeof(struct OCPP16Data));
+	return 1;
+}
+
+//=================================
+// LCM Page
+//=================================
+void ChangeLcmByIndex(byte page_index)
+{
+	if (ShmSysConfigAndInfo->SysWarningInfo.Level != 2 ||
+			page_index == _LCM_COMPLETE || page_index == _LCM_FIX)
+	{
+		ShmSysConfigAndInfo->SysInfo.PageIndex = page_index;
+	}
+}
+
+//======================================================
+// Peripheral initial
+//======================================================
+void InitGPIO()
+{
+	/*****************0~3, 4 bank, bank x 32+ num*********************/
+	/***************************************************************/
+	/*************** GPIO 0 ***************************************/
+	/***************************************************************/
+	/* GPMC_AD8			=> 	GPIO0_22 *//*ID BD1_1*/					// no use
+	system("echo 22 > /sys/class/gpio/export");
+	system("echo \"in\" > /sys/class/gpio/gpio22/direction");
+	/* GPMC_AD9			=>	GPIO0_23 *//*ID BD1_2*/					// no use
+	system("echo 23 > /sys/class/gpio/export");
+	system("echo \"in\" > /sys/class/gpio/gpio23/direction");
+	/* GPMC_AD10		=>	GPIO0_26 *//*IO BD1_1*/					// no use
+	system("echo 26 > /sys/class/gpio/export");
+	system("echo \"out\" > /sys/class/gpio/gpio26/direction");
+	system("echo 1 > /sys/class/gpio/gpio26/value");
+	/* GPMC_AD11		=>	GPIO0_27 *//*IO BD1_2*/					// no use
+	system("echo 27 > /sys/class/gpio/export");
+	system("echo \"in\" > /sys/class/gpio/gpio27/direction");
+	/* RMII1_REF_CLK		=>	GPIO0_29 *//*USB 0 OCP detection*/
+	system("echo 29 > /sys/class/gpio/export");
+	system("echo \"in\" > /sys/class/gpio/gpio29/direction");
+	/*XDMA_EVENT_INTR0	=>	GPIO0_19 *//*AM_RFID_RST*/				// no use
+	system("echo 19 > /sys/class/gpio/export");
+	system("echo \"out\" > /sys/class/gpio/gpio19/direction");
+	system("echo 1 > /sys/class/gpio/gpio19/value");
+	/*XDMA_EVENT_INTR1	=>	GPIO0_20 *//*AM_RFID_ICC*/				// no use
+	system("echo 20 > /sys/class/gpio/export");
+	system("echo \"in\" > /sys/class/gpio/gpio20/direction");
+	/***************************************************************/
+	/*************** GPIO 1 ***************************************/
+	/***************************************************************/
+	/* GPMC_AD12	=> 	GPIO1_12 *//*ID BD2_1*/						// no use
+	system("echo 44 > /sys/class/gpio/export");
+	system("echo \"in\" > /sys/class/gpio/gpio44/direction");
+	/* GPMC_AD13	=>	GPIO1_13 *//*ID BD2_2*/						// no use
+	system("echo 45 > /sys/class/gpio/export");
+	system("echo \"in\" > /sys/class/gpio/gpio45/direction");
+	/* GPMC_AD14	=>	GPIO1_14 *//*IO BD2_1*/						// no use
+	system("echo 46 > /sys/class/gpio/export");
+	system("echo \"out\" > /sys/class/gpio/gpio46/direction");
+	system("echo 0 > /sys/class/gpio/gpio46/value");
+	/* GPMC_AD15	=>	GPIO1_15 *//*IO BD2_2*/						// no use
+	system("echo 47 > /sys/class/gpio/export");
+	system("echo \"in\" > /sys/class/gpio/gpio47/direction");
+	/***************************************************************/
+	/*************** GPIO 2 ***************************************/
+	/***************************************************************/
+	/*LCD_AC_BIAS_EN	=>	GPIO2_25*//*RS-485 for module DE control*/
+	system("echo 89 > /sys/class/gpio/export");
+	system("echo \"out\" > /sys/class/gpio/gpio89/direction");
+	system("echo 1 > /sys/class/gpio/gpio89/value");
+	/*LCD_HSYNC		=>	GPIO2_23*//*RS-485 for module RE control*/
+	system("echo 87 > /sys/class/gpio/export");
+	system("echo \"out\" > /sys/class/gpio/gpio87/direction");
+	system("echo 0 > /sys/class/gpio/gpio87/value");
+	/*LCD_PCLK		=>	GPIO2_24*//*CCS communication board 1 proximity*/		// no use
+	system("echo 88 > /sys/class/gpio/export");
+	system("echo \"in\" > /sys/class/gpio/gpio88/direction");
+	/*LCD_VSYNC		=>	GPIO2_22*//*CCS communication board 2 proximity*/		// no use
+	system("echo 86 > /sys/class/gpio/export");
+	system("echo \"in\" > /sys/class/gpio/gpio86/direction");
+	/***************************************************************/
+	/*************** GPIO 3 ***************************************/
+	/***************************************************************/
+	/*MCASP0_FSX		=>	GPIO3_15*//*Emergency Stop button detect*/
+	system("echo 111 > /sys/class/gpio/export");
+	system("echo \"in\" > /sys/class/gpio/gpio111/direction");
+	/*MCASP0_ACLKR	=>	GPIO3_18*//*USB1 OCP detect*/
+	system("echo 114 > /sys/class/gpio/export");
+	system("echo \"in\" > /sys/class/gpio/gpio114/direction");
+	/*MCASP0_AHCLKR	=>	GPIO3_17*//*Emergency IO for AM3352 and STM32F407*/
+	system("echo 113 > /sys/class/gpio/export");
+	system("echo \"in\" > /sys/class/gpio/gpio113/direction");
+	/*MCASP0_ACLKX	=>	GPIO3_14*//*Ethernet PHY reset*/
+	system("echo 110 > /sys/class/gpio/export");
+	system("echo \"out\" > /sys/class/gpio/gpio110/direction");
+	system("echo 0 > /sys/class/gpio/gpio110/value");
+	/* MCASP0_FSR		=>	GPIO3_19 *//*SMR Enable control_1 for Pskill_1*/	// no use
+	system("echo 115 > /sys/class/gpio/export");
+	system("echo \"out\" > /sys/class/gpio/gpio115/direction");
+	system("echo 0 > /sys/class/gpio/gpio115/value");
+	/* MCASP0_AXR0	=>	GPIO3_16 *//*CSU board function OK indicator.*/
+	system("echo 112 > /sys/class/gpio/export");
+	system("echo \"out\" > /sys/class/gpio/gpio112/direction");
+	system("echo 1 > /sys/class/gpio/gpio112/value");
+	/* MCASP0_AXR1	=>	GPIO3_20 *//*SMR Enable control_2 for Pskill_2*/		// no use
+	system("echo 116 > /sys/class/gpio/export");
+	system("echo \"out\" > /sys/class/gpio/gpio116/direction");
+	system("echo 0 > /sys/class/gpio/gpio116/value");
+	/* (C14) EMU0.gpio3[7] */  /*CP open/short feature enable/disable, pull low for default enable*/
+	system("echo 103 > /sys/class/gpio/export");
+	system("echo \"out\" > /sys/class/gpio/gpio103/direction");
+	system("echo 0 > /sys/class/gpio/gpio103/value");
+	/* (B14) EMU1.gpio3[8] */  /*4G module reset, pull high to reset when entry kernel, after Application start, it should be pull low.*/
+	system("echo 104 > /sys/class/gpio/export");
+	system("echo \"out\" > /sys/class/gpio/gpio104/direction");
+	system("echo 0 > /sys/class/gpio/gpio104/value");
+#ifdef SystemLogMessage
+	DEBUG_INFO_MSG("[main]InitGPIO: Initial GPIO OK");
+#endif
+}
+
+int LoadSysConfigAndInfo(struct SysConfigData *ptr)
+{
+	int fd,wrd;
+	unsigned char *buf;
+	unsigned int ChkSum,ChkSumOrg;
+
+	if((buf=malloc(MtdBlockSize))==NULL)
+	{
+		DEBUG_ERROR_MSG("malloc buffer NG,rebooting..\r\n");
+		if(ShmStatusCodeData!=NULL)
+		{
+			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed=1;
+		}
+		sleep(5);
+		system("reboot -f");
+		sleep(5);
+		system("reboot -f");
+	}
+	memset(buf, 0, MtdBlockSize);
+
+	//================================================
+	// Load configuration from mtdblock10
+	//================================================
+	fd = open("/dev/mtdblock10", O_RDWR);
+	if (fd < 0)
+	{
+		free(buf);
+		DEBUG_ERROR_MSG("open mtdblock10 NG,rebooting..\r\n");
+		if(ShmStatusCodeData!=NULL)
+		{
+			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed=1;
+		}
+		sleep(5);
+		system("reboot -f");
+		sleep(5);
+		system("reboot -f");
+	}
+
+	wrd=read(fd, buf, MtdBlockSize);
+	close(fd);
+	if(wrd<MtdBlockSize)
+	{
+		free(buf);
+		DEBUG_ERROR_MSG("read SysConfigData data NG,rebooting..\r\n");
+		if(ShmStatusCodeData!=NULL)
+		{
+			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed=1;
+		}
+		sleep(5);
+		system("reboot -f");
+		sleep(5);
+		system("reboot -f");
+	}
+	ChkSum=0;
+	for(wrd=0;wrd<MtdBlockSize-4;wrd++)
+	{
+		ChkSum+=buf[wrd];
+	}
+	memcpy(&ChkSumOrg,buf+(0x00600000-4),sizeof(ChkSumOrg));
+
+	//================================================
+	// Load configuration from mtdblock11
+	//================================================
+	if(ChkSum!=ChkSumOrg)
+	{
+		DEBUG_ERROR_MSG("Primary SysConfigData checksum NG, read backup\r\n");
+		fd = open("/dev/mtdblock11", O_RDWR);
+		if (fd < 0)
+		{
+			free(buf);
+			DEBUG_ERROR_MSG("open mtdblock11 (backup) NG,rebooting..\r\n");
+			if(ShmStatusCodeData!=NULL)
+			{
+				ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed=1;
+			}
+			sleep(5);
+			system("reboot -f");
+			sleep(5);
+			system("reboot -f");
+		}
+
+		memset(buf, 0, MtdBlockSize);
+	    wrd=read(fd, buf,MtdBlockSize);
+	    close(fd);
+		if(wrd<MtdBlockSize)
+		{
+			free(buf);
+			DEBUG_ERROR_MSG("read backup SysConfigData data NG,rebooting..\r\n");
+			if(ShmStatusCodeData!=NULL)
+			{
+				ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed=1;
+			}
+			sleep(5);
+			system("reboot -f");
+			sleep(5);
+			system("reboot -f");
+		}
+		ChkSum=0;
+		for(wrd=0;wrd<MtdBlockSize-4;wrd++)
+		{
+			ChkSum+=buf[wrd];
+		}
+		memcpy(&ChkSumOrg,buf+(0x00600000-4),sizeof(ChkSumOrg));
+
+		//================================================
+		// Load configuration from mtdblock12 (Factory default)
+		//================================================
+		if(ChkSum!=ChkSumOrg)
+		{
+			DEBUG_ERROR_MSG("backup SysConfigData checksum NG, read Factory default\r\n");
+			fd = open("/dev/mtdblock12", O_RDWR);
+			if (fd < 0)
+			{
+				free(buf);
+				DEBUG_ERROR_MSG("open mtdblock12 (Factory default) NG,rebooting..\r\n");
+				if(ShmStatusCodeData!=NULL)
+				{
+					ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed=1;
+				}
+				sleep(5);
+				system("reboot -f");
+				sleep(5);
+				system("reboot -f");
+		    }
+		    memset(buf, 0, MtdBlockSize);
+	   		wrd=read(fd, buf,MtdBlockSize);
+	    	close(fd);
+			if(wrd<MtdBlockSize)
+			{
+				free(buf);
+				DEBUG_ERROR_MSG("read factory default  SysConfigData data NG,rebooting..\r\n");
+				if(ShmStatusCodeData!=NULL)
+				{
+					ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed=1;
+				}
+				sleep(5);
+				system("reboot -f");
+				sleep(5);
+				system("reboot -f");
+			}
+			ChkSum=0;
+			for(wrd=0;wrd<MtdBlockSize-4;wrd++)
+			{
+				ChkSum+=buf[wrd];
+			}
+			memcpy(&ChkSumOrg,buf+(0x00600000-4),sizeof(ChkSumOrg));
+			if(ChkSum!=ChkSumOrg)
+			{
+				DEBUG_ERROR_MSG("factory default  SysConfigData checksum NG, restore factory default\r\n");
+				free(buf);
+				system("cd /root;./FactoryConfig -m");
+				system("sync");
+				sleep(5);
+				system("reboot -f");
+				sleep(5);
+				system("reboot -f");
+
+				return FAIL;
+			}
+		}
+	}
+
+	//load OK
+	memcpy((struct SysConfigData *)ptr,buf,sizeof(struct SysConfigData));
+	free(buf);
+	DEBUG_INFO_MSG("Load SysConfigData OK\r\n");
+	return PASS;
+}
+
+/*
+byte GetCurEthUsage()
+{
+	byte result = _ETHERNET_USAGE_NONE;
+	FILE *fp;
+	char cmd[256];
+	char buf[512];
+	byte targetC = 2;
+
+	strcpy(cmd, "route -n");
+	fp = popen(cmd, "r");
+
+	if (fp != NULL)
+	{
+		while(fgets(buf, sizeof(buf), fp) != NULL)
+		{
+			if (targetC-- == 0)
+			{
+				if (strstr(buf, "eth0") > 0)
+					result = _ETHERNET_USAGE_LAN;
+				else if (strstr(buf, "mlan0") > 0)
+					result = _ETHERNET_USAGE_WIFI;
+				else if (strstr(buf, "ppp0") > 0)
+					result = _ETHERNET_USAGE_3G_4g;
+				break;
+			}
+
+//			if (strstr(buf, "inet addr:") > 0)
+//			{
+//			}
+		}
+	}
+	pclose(fp);
+	memset(buf, 0x00, sizeof(buf));
+	return result;
+}
+*/
+
+int isRouteFail()
+{
+	int result = YES;
+	FILE *fp;
+	char buf[512];
+
+	fp = popen("route -n", "r");
+	if(fp != NULL)
+	{
+		while(fgets(buf, sizeof(buf), fp) != NULL)
+		{
+			if(strstr(buf, "eth0") != NULL)
+				result = NO;
+		}
+	}
+	pclose(fp);
+
+	return result;
+}
+
+int isReachableInternet()
+{
+	int result = FAIL;
+	FILE *fp;
+	char cmd[256];
+	char buf[512];
+	char tmp[512];
+
+//	if (ShmOCPP16Data->OcppConnStatus == PASS)
+//	{
+//		result = PASS;
+//	}
+//	else
+	{
+		strcpy(cmd, "ifconfig eth0");
+		fp = popen(cmd, "r");
+
+		if (fp != NULL)
+		{
+			while(fgets(buf, sizeof(buf), fp) != NULL)
+			{
+				if (strstr(buf, "inet addr:") > 0)
+				{
+					sscanf(buf, "%*s%s", tmp);
+					substr(tmp, tmp, strspn(tmp, "addr:"), strlen(buf)-strspn(tmp, "addr:"));
+
+					if (strcmp(tmp, (char *)ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthIpAddress) != EQUAL)
+					{
+						strcpy((char *) ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthIpAddress, tmp);
+					}
+				}
+			}
+		}
+		pclose(fp);
+		memset(buf, 0x00, sizeof(buf));
+
+		for(int idx=0;idx<ARRAY_SIZE(valid_Internet);idx++)
+		{
+			sprintf(cmd, "ping -c 1 -w 3 -I eth0 %s", valid_Internet[idx]);
+			fp = popen(cmd, "r");
+			if(fp != NULL)
+			{
+				while(fgets(buf, sizeof(buf), fp) != NULL)
+				{
+					if(strstr(buf, "transmitted") > 0)
+					{
+						//sscanf(buf, "%*s%*s%*s%*s%*s%*s%s", tmp);
+
+						if(strstr(buf,"100%") != NULL)
+						{
+						}
+						else
+						{
+							result = PASS;
+						}
+						//DEBUG_INFO("%s",buf);
+						//DEBUG_INFO("%s\n",tmp);
+					}
+				}
+			}
+			pclose(fp);
+		}
+	}
+
+	return result;
+}
+
+void InitEthernet()
+{
+	char tmpbuf[256];
+	// /sbin/ifconfig eth0 192.168.1.10 netmask 255.255.255.0 down
+	system("echo 1 > /sys/class/gpio/gpio110/value");//reset PHY
+	sleep(2);
+	//Init Eth0 for internet
+	memset(tmpbuf,0,256);
+	sprintf(tmpbuf,"/sbin/ifconfig eth0 %s netmask %s up",
+	ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthIpAddress,
+	ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthSubmaskAddress);
+	system(tmpbuf);
+
+	memset(tmpbuf,0,256);
+	sprintf(tmpbuf,"route add default gw %s eth0 ",
+	ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthGatewayAddress);
+	system(tmpbuf);
+	//system("ifconfig lo up");
+	//  /sbin/ifconfig eth0 192.168.1.10 netmask 255.255.255.0 up
+    //Init Eth1 for administrator tool
+	memset(tmpbuf,0,256);
+	sprintf(tmpbuf,"/sbin/ifconfig eth1 %s netmask %s up",
+	ShmSysConfigAndInfo->SysConfig.Eth1Interface.EthIpAddress,
+	ShmSysConfigAndInfo->SysConfig.Eth1Interface.EthSubmaskAddress);
+	system(tmpbuf);
+
+    //Run DHCP client if enabled
+	system("killall udhcpc");
+	system("rm -rf /etc/resolv.conf");
+	system("echo nameserver 8.8.8.8 > /etc/resolv.conf");		//Google DNS server
+	system("echo nameserver 180.76.76.76 > /etc/resolv.conf");	//Baidu DNS server
+	system("/sbin/ifconfig eth0 down;/sbin/ifconfig eth0 up");
+
+	if(ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthDhcpClient == 0)
+	{
+		sprintf(tmpbuf, "/sbin/udhcpc -i eth0 -x hostname:CSU3_%s -s /root/dhcp_script/eth0.script > /dev/null &", ShmSysConfigAndInfo->SysConfig.SystemId);
+		system(tmpbuf);
+	}
+
+	//Upgrade system id to /etc/hostname
+	sprintf(tmpbuf, "echo %s > /etc/hostname", ShmSysConfigAndInfo->SysConfig.SystemId);
+	system(tmpbuf);
+
+	// DO360 DHCP Server
+	InitialDispenserDhcpServerConfig();
+	StartDispenserDhcpServer();
+
+	pid_t pid = fork();
+	uint8_t cnt_pingDNS_Fail;
+
+	if(pid == 0)
+	{
+		for(;;)
+		{
+			if (isRouteFail())
+			{
+				PRINTF_FUNC("eth0 not in route, restart eht0. \n");
+				system("/sbin/ifconfig eth0 down;/sbin/ifconfig eth0 up");
+
+				if (ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthDhcpClient == 0)
+				{
+					InitialDHCP();
+				}
+			}
+
+			if(isReachableInternet() == PASS)
+			{
+				ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet= NO;
+				cnt_pingDNS_Fail = 0;
+			}
+			else
+			{
+				if(++cnt_pingDNS_Fail > 3)
+				{
+					ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet = YES;
+				}
+			}
+
+			bool ethResult = YES;
+
+			if(ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet)
+				ethResult = NO;
+			else
+			{
+				system("/sbin/ifmetric eth0 0");
+
+				if((ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'W') ||
+						(ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D'))
+					system("/sbin/ifmetric mlan0 1");
+
+				if((ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'T') ||
+						(ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D'))
+					system("/sbin/ifmetric ppp0 2");
+			}
+
+			if (!ethResult &&
+					(ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'W' || ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D'))
+			{
+				ethResult = !ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi;
+
+				if (ethResult)
+				{
+					if((ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D'))
+					{
+						system("/sbin/ifmetric eth0 1");
+						system("/sbin/ifmetric mlan0 0");
+					}
+
+					if((ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'T') || (ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D'))
+						system("/sbin/ifmetric ppp0 2");
+				}
+			}
+
+			if (!ethResult &&
+					(ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'T' || ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D'))
+			{
+				ethResult = !ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi;
+
+				if (ethResult)
+				{
+					if((ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D'))
+						system("/sbin/ifmetric mlan0 2");
+
+					if((ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'T') || (ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D'))
+					{
+						system("/sbin/ifmetric eth0 1");
+						system("/sbin/ifmetric ppp0 0");
+					}
+				}
+			}
+
+			ShmSysConfigAndInfo->SysInfo.InternetConn = ethResult;
+
+			sleep(5);
+		}
+	}
+
+	#ifdef SystemLogMessage
+	DEBUG_INFO_MSG("[main]InitEthernet: Initial Ethernet OK. \n");
+	#endif
+}
+
+/*
+int InitialRfidPort()
+{
+	int uartO2 = open(rfidPortName, O_RDWR);
+	struct termios tios;
+
+	if (uartO2 != FAIL)
+	{
+		ioctl (uartO2, TCGETS, &tios);
+		tios.c_cflag = B19200 | CS8 | CLOCAL | CREAD;
+		tios.c_lflag = 0;
+		tios.c_iflag = 0;
+		tios.c_oflag = 0;
+		tios.c_cc[VMIN] = 0;
+		tios.c_cc[VTIME] = (unsigned char) 1;
+		tios.c_lflag = 0;
+		tcflush(uartO2, TCIFLUSH);
+		ioctl(uartO2, TCSETS, &tios);
+	}
+
+	if (uartO2 < 0)
+	{
+		ShmStatusCodeData->AlarmCode.AlarmEvents.bits.RfidModuleCommFail = 1;
+	}
+
+	return uartO2;
+}
+*/
+
+void GetMacAddress()
+{
+	for (byte index = 0; index < 2; index++)
+	{
+		int fd;
+		struct ifreq ifr;
+		char tarEth[5];
+		char Mac[18];
+
+		sprintf(tarEth,"eth%d",index);
+		fd = socket(AF_INET, SOCK_DGRAM, 0);
+
+		ifr.ifr_addr.sa_family = AF_INET;
+		strncpy(ifr.ifr_name, tarEth, IFNAMSIZ - 1);
+
+		ioctl(fd, SIOCGIFHWADDR, &ifr);
+		close(fd);
+
+		sprintf(Mac, "%.2x:%.2x:%.2x:%.2x:%.2x:%.2x",
+				ifr.ifr_hwaddr.sa_data[0], ifr.ifr_hwaddr.sa_data[1], ifr.ifr_hwaddr.sa_data[2],
+				ifr.ifr_hwaddr.sa_data[3], ifr.ifr_hwaddr.sa_data[4], ifr.ifr_hwaddr.sa_data[5]);
+
+		if (index == 0)
+			strcpy((char *) ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthMacAddress, Mac);
+		else
+			strcpy((char *) ShmSysConfigAndInfo->SysConfig.Eth1Interface.EthMacAddress, Mac);
+	}
+}
+
+void GetFirmwareVersion()
+{
+	// Get CSU root file system version
+	sprintf((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev, fwVersion);
+
+	byte count = 0, chademo = 0, ccs = 0, gb = 0;
+	for(uint8_t idx=0;idx<3;idx++)
+	{
+		if (ShmSysConfigAndInfo->SysConfig.ModelName[7+idx] == 'J')
+		{
+			chademo++;
+			count++;
+		}
+		else  if (ShmSysConfigAndInfo->SysConfig.ModelName[7+idx] == 'G')
+		{
+			gb++;
+			count++;
+		}
+		else  if (ShmSysConfigAndInfo->SysConfig.ModelName[7+idx] == 'U' ||
+				ShmSysConfigAndInfo->SysConfig.ModelName[7+idx] == 'E')
+		{
+			ccs++;
+			count++;
+		}
+	}
+
+	if (count == 1)
+	{
+		if (chademo > 0)
+			ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[7] = '1';
+		else if (ccs > 0)
+			ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[7] = '2';
+		else if (gb > 0)
+			ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[7] = '3';
+	}
+	else
+	{
+		if (chademo > 0 && ccs > 0)
+			ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[7] = '4';
+		else if (chademo > 0 && gb > 0)
+			ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[7] = '5';
+		else if (ccs > 0 && gb > 0)
+			ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[7] = '6';
+	}
+
+	// Get network option from model name
+	switch(ShmSysConfigAndInfo->SysConfig.ModelName[10])
+	{
+		case 'B':
+		case 'U':
+			//Blue tooth
+			ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[9] = '3';
+			break;
+		case 'W':
+			// WIFI
+			ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[9] = '1';
+			break;
+		case 'T':
+			// 3G/4G
+			ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[9] = '2';
+			break;
+		default:
+			// LAN
+			ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[9] = '0';
+			break;
+	}
+	// Get rating power from model name
+	memcpy(&ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[10], &ShmSysConfigAndInfo->SysConfig.ModelName[4], 0x03);
+
+	// Get IEC or UL
+	char _buf[3] = {0};
+	memcpy(_buf, &ShmSysConfigAndInfo->SysConfig.ModelName[2], 2);
+
+	if (strcmp(_buf, "YE") == EQUAL || strcmp(_buf, "YC") == EQUAL)
+		ShmSysConfigAndInfo->SysInfo.ChargerType = _CHARGER_TYPE_IEC;
+	else if (strcmp(_buf, "WU") == EQUAL)
+		ShmSysConfigAndInfo->SysInfo.ChargerType = _CHARGER_TYPE_UL;
+}
+
+void InitialShareMemoryInfo()
+{
+	FILE *fp;
+	char cmd[512];
+	char buf[512];
+
+	sprintf((char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomApn, "Internet");
+	sprintf((char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapId, " ");
+	sprintf((char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapPwd, " ");
+
+	ShmSysConfigAndInfo->SysConfig.TotalConnectorCount = 0;
+	ShmSysConfigAndInfo->SysConfig.AcConnectorCount = 0;
+
+	ShmSysConfigAndInfo->SysInfo.FactoryConfiguration = 0;
+	ShmSysConfigAndInfo->SysInfo.InputVoltageR = 0;
+	ShmSysConfigAndInfo->SysInfo.InputVoltageS = 0;
+	ShmSysConfigAndInfo->SysInfo.InputVoltageT = 0;
+	ShmSysConfigAndInfo->SysInfo.SystemFanRotaSpeed = 0;
+	ShmSysConfigAndInfo->SysInfo.PsuFanRotaSpeed = 0;
+	ShmSysConfigAndInfo->SysInfo.AuxPower5V = 0;
+	ShmSysConfigAndInfo->SysInfo.AuxPower12V = 0;
+	ShmSysConfigAndInfo->SysInfo.AuxPower24V = 0;
+	ShmSysConfigAndInfo->SysInfo.AuxPower48V = 0;
+
+	sprintf((char *)ShmSysConfigAndInfo->SysInfo.CsuHwRev, "REV:5.0");
+	memcpy(ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev, ShmSysConfigAndInfo->SysConfig.CsuBootLoadFwRev, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.CsuBootLoadFwRev));
+
+	sprintf(cmd, "/bin/uname -r");
+	fp = popen(cmd, "r");
+	if(fp == NULL)
+		sprintf((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev, "Unknown version");
+	else
+	{
+		while(fgets(buf, sizeof(buf), fp) != NULL)
+		{
+			strcpy((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev, buf);
+		}
+	}
+
+	// 雙槍 CCS + Chademo
+	GetFirmwareVersion();
+	//sprintf((char *) ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev, fwVersion);
+	sprintf((char *) ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev, " ");
+
+	sprintf((char *) ShmSysConfigAndInfo->SysInfo.LcmHwRev, " ");
+	sprintf((char *) ShmSysConfigAndInfo->SysInfo.LcmFwRev, " ");
+	sprintf((char *) ShmSysConfigAndInfo->SysInfo.PsuHwRev, " ");
+	sprintf((char *) ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev, " ");
+	sprintf((char *) ShmSysConfigAndInfo->SysInfo.PsuSecFwRev, " ");
+	sprintf((char *) ShmSysConfigAndInfo->SysInfo.AuxPwrHwRev, " ");
+	sprintf((char *) ShmSysConfigAndInfo->SysInfo.AuxPwrFwRev, " ");
+	sprintf((char *) ShmSysConfigAndInfo->SysInfo.FanModuleHwRev, " ");
+	sprintf((char *) ShmSysConfigAndInfo->SysInfo.FanModuleFwRev, " ");
+	sprintf((char *) ShmSysConfigAndInfo->SysInfo.RelayModuleHwRev, " ");
+	sprintf((char *) ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev, " ");
+	sprintf((char *) ShmSysConfigAndInfo->SysInfo.Relay2ModuleHwRev, " ");		//DO360 RC2
+	sprintf((char *) ShmSysConfigAndInfo->SysInfo.Relay2ModuleFwRev, " ");		//DO360 RC2
+	sprintf((char *) ShmSysConfigAndInfo->SysInfo.TelcomModemFwRev, " ");
+	ShmSysConfigAndInfo->SysInfo.SystemAmbientTemp = 0;
+	ShmSysConfigAndInfo->SysInfo.SystemCriticalTemp = 0;
+	ShmSysConfigAndInfo->SysInfo.PsuAmbientTemp = 0;
+	ShmSysConfigAndInfo->SysInfo.CcsConnectorTemp = 0;
+	ShmSysConfigAndInfo->SysInfo.InternetConn = 0;
+	ShmSysConfigAndInfo->SysInfo.OcppConnStatus = 0;
+	ShmSysConfigAndInfo->SysInfo.OrderCharging = NO_DEFINE;
+
+	strcpy((char *) ShmSysConfigAndInfo->SysConfig.UserId, "");
+
+	ShmStatusCodeData->AlarmCode.AlarmEvents.bits.RelayboardStestFail = NO;
+	ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FanboardStestFail = NO;
+	ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PrimaryStestFail = NO;
+	ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoboardStestFail = NO;
+	ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CCSboardStestFail = NO;
+	ShmStatusCodeData->AlarmCode.AlarmEvents.bits.AcContactStestFail = NO;
+	ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuModuleStestFail = NO;
+
+	memset(ShmSysConfigAndInfo->SysInfo.FanModuleFwRev, 0, ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
+	memset(ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev, 0, ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
+	memset(ShmSysConfigAndInfo->SysInfo.Relay2ModuleFwRev, 0, ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.Relay2ModuleFwRev));	//DO360 RC2
+	ShmPrimaryMcuData->SelfTest_Comp = NO;
+	ShmRelayModuleData[0]->SelfTest_Comp = NO;
+	ShmRelayModuleData[1]->SelfTest_Comp = NO;
+	ShmFanModuleData->SelfTest_Comp = NO;
+	ShmLedModuleData->SelfTest_Comp = NO;
+	ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
+	ShmSysConfigAndInfo->SysInfo.MainChargingMode = _MAIN_CHARGING_MODE_MAX;
+	ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_NONE;
+	ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc = NO_DEFINE;
+
+	ShmFanModuleData->TestFanSpeed = 0;
+
+	ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ModelNameNoneMatchStestFail = NO;
+	ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuNoResource = NO;
+
+	char EvsePower[2];
+
+	EvsePower[2] = '\0';
+	unsigned short buf_pow = 0;
+	if (strlen((char *) ShmSysConfigAndInfo->SysConfig.ModelName) >= 6)
+	{
+		strncpy(EvsePower, (char *)(ShmSysConfigAndInfo->SysConfig.ModelName + 4), 2);
+		if (strcmp(EvsePower, "15") == EQUAL)
+			buf_pow = 150;
+		else if (strcmp(EvsePower, "30") == EQUAL)
+			buf_pow = 30;
+		else if (strcmp(EvsePower, "60") == EQUAL)
+			buf_pow = 60;
+		else if (strcmp(EvsePower, "12") == EQUAL)
+			buf_pow = 120;
+		else if (strcmp(EvsePower, "18") == EQUAL)
+			buf_pow = 180;
+		else if (strcmp(EvsePower, "36") == EQUAL)
+			buf_pow = 360;
+
+		ShmSysConfigAndInfo->SysConfig.RatingCurrent = (buf_pow / 30) * PSU_MIN_CUR;
+
+		if(ShmSysConfigAndInfo->SysConfig.MaxChargingPower == 0 ||
+				ShmSysConfigAndInfo->SysConfig.MaxChargingPower > buf_pow)
+			ShmSysConfigAndInfo->SysConfig.MaxChargingPower = buf_pow;
+	}
+	ShmSysConfigAndInfo->SysConfig.SwitchDebugFlag = NO;
+	ShmSysConfigAndInfo->SysConfig.AlwaysGfdFlag = NO;
+}
+
+int Initialization()
+{
+	// 初始化卡號驗證的 Flag
+	ClearAuthorizedFlag();
+	// 初始化插槍驗證的 Flag
+	ClearDetectPluginFlag();
+
+	// UART 2 for Rfid
+	//rfidFd = InitialRfidPort();
+
+//	int pinOut[2] = { 116, 115 };
+	for (byte count = 0; count < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; count++)
+	{
+		chargingInfo[count]->RemoteStartFlag = NO;
+//
+//		if (chargingInfo[count]->Type == _Type_Chademo)
+//		{
+//			gpio_set_value(pinOut[count], 0x00);
+//			ShmCHAdeMOData->evse[chargingInfo[count]->type_index].SelfTest_Comp = NO;
+//		}
+//		else if (chargingInfo[count]->Type == _Type_GB)
+//		{
+//			gpio_set_value(pinOut[count], 0x00);
+//			ShmGBTData->evse[chargingInfo[count]->type_index].SelfTest_Comp = NO;
+//		}
+//		else if (chargingInfo[count]->Type == _Type_CCS_2)
+//		{
+//			if (ShmCcsData->CommProtocol == _CCS_COMM_V2GMessage_DIN70121)
+//			{
+//				if (ShmSysConfigAndInfo->SysConfig.TotalConnectorCount == 1)
+//					gpio_set_value(pinOut[1], 0x01);
+//				else
+//					gpio_set_value(pinOut[count], 0x01);
+//				ShmCcsData->V2GMessage_DIN70121[chargingInfo[count]->type_index].SelfTest_Comp = NO;
+//			}
+//		}
+
+		strcpy((char *)ShmOCPP16Data->StatusNotification[count].ErrorCode, "NoError");
+	}
+
+	for (byte count = 0; count < ShmSysConfigAndInfo->SysConfig.AcConnectorCount; count++)
+	{
+		ac_chargingInfo[count]->RemoteStartFlag = NO;
+
+		if (ac_chargingInfo[count]->Type == _Type_AC)
+		{
+			ac_chargingInfo[count]->SelfTest_Comp = NO;
+			strcpy((char *)ShmOCPP16Data->StatusNotification[count + ShmSysConfigAndInfo->SysConfig.TotalConnectorCount].ErrorCode, "NoError");
+		}
+	}
+
+	PRINTF_FUNC("Initialization OK \n");
+	return PASS;
+}
+
+bool InitialSystemDefaultConfig()
+{
+	bool result = true;
+
+	LoadSysConfigAndInfo(&ShmSysConfigAndInfo->SysConfig);
+	InitGPIO();
+	InitEthernet();
+	GetMacAddress();
+
+//	system("echo 1 > /sys/class/gpio/gpio110/value"); //reset PHY
+//	sleep(3);
+//	system("/sbin/ifconfig eth0 192.168.1.10 netmask 255.255.255.0 down");
+//	sleep(1);
+//	system("/sbin/ifconfig eth1 192.168.0.10 netmask 255.255.255.0 up");
+
+	return result;
+}
+
+/*
+bool DisplaySelfTestFailReason()
+{
+	bool result = false;
+	// RB、FB、407、EV 小板中有些板子無回應
+	if (ShmRelayModuleData->SelfTest_Comp == NO)
+	{ ShmStatusCodeData->AlarmCode.AlarmEvents.bits.RelayboardStestFail = YES; result = true; }
+	if (ShmFanModuleData->SelfTest_Comp == NO)
+	{ ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FanboardStestFail = YES; result = true; }
+	if (ShmPrimaryMcuData->SelfTest_Comp == NO)
+	{ ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PrimaryStestFail = YES; result = true; }
+//	if (ShmLedModuleData->SelfTest_Comp == NO)
+//	{ ShmStatusCodeData->AlarmCode.AlarmEvents.bits.LedboardStestFail = YES; }
+	for (byte index = 0; index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; index++)
+	{
+		if (chargingInfo[index]->Type == _Type_Chademo)
+		{
+			if (ShmCHAdeMOData->evse[chargingInfo[index]->type_index].SelfTest_Comp == NO)
+			{ ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoboardStestFail = YES; result = true; }
+		}
+		else if (chargingInfo[index]->Type == _Type_GB)
+		{
+			if (ShmGBTData->evse[chargingInfo[index]->type_index].SelfTest_Comp == NO)
+			{ ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbtboardStestFail = YES; result = true; }
+		}
+		else if (chargingInfo[index]->Type == _Type_CCS_2)
+		{
+			if (ShmCcsData->CommProtocol == _CCS_COMM_V2GMessage_DIN70121)
+			{
+				if (ShmCcsData->V2GMessage_DIN70121[chargingInfo[index]->type_index].SelfTest_Comp == NO)
+				{ ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CCSboardStestFail = YES; result = true; }
+			}
+		}
+	}
+	for (byte index = 0; index < ShmSysConfigAndInfo->SysConfig.AcConnectorCount; index++)
+	{
+		// 先借 GBT 顯示
+		if (ac_chargingInfo[index]->SelfTest_Comp == NO)
+		{ ShmStatusCodeData->AlarmCode.AlarmEvents.bits.AcConnectorStestFail = YES; result = true; }
+	}
+
+	if (ShmSysConfigAndInfo->SysInfo.AcContactorStatus == NO)
+	{
+		// AC Contact 未搭上
+		ShmStatusCodeData->AlarmCode.AlarmEvents.bits.AcContactStestFail = YES;
+		result = true;
+	}
+	else if (ShmPsuData->SystemAvailablePower <= 0 && ShmPsuData->SystemAvailableCurrent <= 0)
+	{
+		// PSU 通訊問題
+		ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuModuleStestFail = YES;
+		result = true;
+	}
+
+	return result;
+}
+*/
+
+void SelfTestRun()
+{
+    struct timeval _selfTest_time;
+
+
+	ShmRelayModuleData[0]->SelfTest_Comp = NO;
+	ShmRelayModuleData[1]->SelfTest_Comp = NO;
+	ShmFanModuleData->SelfTest_Comp = NO;
+	ShmPrimaryMcuData->SelfTest_Comp = NO;
+
+	ShmSysConfigAndInfo->SysInfo.SelfTestSeq = _STEST_VERSION;
+	gettimeofday(&_selfTest_time, NULL);
+
+	while (ShmSysConfigAndInfo->SysInfo.SelfTestSeq != _STEST_COMPLETE)
+	{
+		ChkPrimaryStatus();
+		if (ShmSysConfigAndInfo->SysWarningInfo.Level == 2)
+		{
+			ShmSysConfigAndInfo->SysInfo.SelfTestSeq = _STEST_FAIL;
+			return;
+		}
+
+		if (ShmSysConfigAndInfo->SysConfig.TotalConnectorCount > 0)
+		{
+			if (ShmPsuData->Work_Step == _NO_WORKING ||
+					ShmSysConfigAndInfo->SysInfo.SelfTestSeq == _STEST_FAIL)
+			{
+				ShmSysConfigAndInfo->SysInfo.SelfTestSeq = _STEST_FAIL;
+				return;
+			}
+
+			switch(ShmSysConfigAndInfo->SysInfo.SelfTestSeq)
+			{
+				case _STEST_VERSION:
+				{
+					if (ShmFanModuleData->SelfTest_Comp &&
+							ShmRelayModuleData[0]->SelfTest_Comp && ShmRelayModuleData[0]->SelfTest_Comp &&
+							ShmPrimaryMcuData->SelfTest_Comp)
+					{
+						ShmSysConfigAndInfo->SysInfo.SelfTestSeq = _STEST_AC_CONTACTOR;
+						PRINTF_FUNC("Self test version check ok");
+					}
+				}
+					break;
+				case _STEST_AC_CONTACTOR:
+				{
+					//ShmPsuData->Work_Step = _TEST_COMPLETE;
+					// 因為 30KW 以下沒有 Relay feedback 功能,所以暫時先直接跳過
+					if (ShmSysConfigAndInfo->SysInfo.AcContactorStatus == YES)
+					{
+						ShmSysConfigAndInfo->SysInfo.SelfTestSeq = _STEST_PSU_DETECT;
+						PRINTF_FUNC("Communication board pass. \n");
+					}
+				}
+					break;
+				case _STEST_PSU_DETECT:
+				{
+					if (ShmPsuData->Work_Step >= GET_SYS_CAP)
+					{
+						ShmSysConfigAndInfo->SysInfo.SelfTestSeq = _STEST_PSU_CAP;
+					}
+				}
+					break;
+				case _STEST_PSU_CAP:
+				{
+					// 此測試是要確認當前總輸出能力
+					// 如果沒有 PSU 模組請 bypass
+					if (ShmPsuData->Work_Step == BOOTING_COMPLETE)
+					{
+						sleep(1);
+						ShmSysConfigAndInfo->SysInfo.SelfTestSeq = _STEST_COMPLETE;
+						ShmSysConfigAndInfo->SysInfo.BootingStatus = BOOT_COMPLETE;
+					}
+				}
+					break;
+			}
+		}
+		else
+			break;
+
+		usleep(100000);
+
+        if(GetTimeoutValue(_selfTest_time) / uSEC_VAL >= SELFTEST_TIMEOUT)
+        {
+            _SelfTestTimeout();
+            break;
+        }
+	}
+}
+
+int SpawnTask()
+{
+	sleep(2);
+	system("/root/Module_EventLogging &");
+	system("/root/Module_PrimaryComm &");
+	system("/root/Module_EvComm &");
+	//system("/root/Module_LcmControl &");
+	system("/root/Module_InternalComm &");
+	system("/root/Module_PsuComm &");
+	system("/root/Module_ProduceUtils &");
+
+	if(strcmp((char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, "") != EQUAL &&
+		strcmp((char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId, "") != EQUAL)
+	{
+		system("/root/OcppBackend &");
+	}
+
+	if(ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'T')
+	{
+		//system("/root/Module_4g &");
+	}
+
+	if(ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'W')
+	{
+		//system("/root/Module_Wifi &");
+	}
+
+	if(ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D')
+	{
+		//system("/root/Module_4g &");
+		//system("/root/Module_Wifi &");
+	}
+
+	return PASS;
+}
+
+int StoreUsrConfigData(struct SysConfigData *UsrData)
+{
+	int result = PASS;
+	int fd,wrd;
+	unsigned int i,Chk;
+	unsigned char *ptr, *BufTmp;
+
+	Chk=0;
+	ptr=(unsigned char *)UsrData;
+	if((BufTmp = malloc(MtdBlockSize)) != NULL)
+	{
+		memset(BufTmp, 0, MtdBlockSize);
+		memcpy(BufTmp, ptr, sizeof(struct SysConfigData));
+		for(i=0; i<MtdBlockSize-4; i++)
+			Chk+=*(ptr+i);
+
+		memcpy(BufTmp + MtdBlockSize-4, &Chk, 4);
+		fd = open("/dev/mtdblock10", O_RDWR);
+		if (fd > 0)
+		{
+			wrd=write(fd, BufTmp, MtdBlockSize);
+			close(fd);
+			if(wrd >= MtdBlockSize)
+			{
+				fd = open("/dev/mtdblock11", O_RDWR);
+				if (fd > 0)
+				{
+					wrd=write(fd, BufTmp, MtdBlockSize);
+	    			close(fd);
+					if(wrd < MtdBlockSize)
+					{
+						DEBUG_ERROR_MSG("write /dev/mtdblock11(backup) NG\r\n");
+					   	result = FAIL;
+					}
+				}
+				else
+				{
+					DEBUG_ERROR_MSG("open /dev/mtdblock11(backup) NG\r\n");
+					result = FAIL;
+				}
+			}
+			else
+			{
+				DEBUG_ERROR_MSG("write /dev/mtdblock10 NG\r\n");
+			    result = FAIL;
+			}
+
+		}
+		else
+		{
+			DEBUG_ERROR_MSG("open /dev/mtdblock10 NG\r\n");
+			result = FAIL;
+		}
+	}
+	else
+	{
+		DEBUG_ERROR_MSG("alloc BlockSize NG\r\n");
+	    result = FAIL;
+	}
+
+	if(BufTmp != NULL)
+		free(BufTmp);
+
+	return result;
+}
+
+//===============================================
+// Common Detect Chk - Stop Charging ?
+//===============================================
+bool isEvBoardStopChargeFlag(byte gunIndex)
+{
+	return chargingInfo[gunIndex]->StopChargeFlag;
+}
+
+//===============================================
+// 掃描插槍狀況
+//===============================================
+void ClearDetectPluginFlag()
+{
+	ShmSysConfigAndInfo->SysInfo.WaitForPlugit = NO;
+	for (byte gun_index = 0; gun_index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gun_index++)
+	{
+		if (chargingInfo[gun_index]->RemoteStartFlag == YES)
+			chargingInfo[gun_index]->RemoteStartFlag = NO;
+	}
+
+	if (ShmSysConfigAndInfo->SysInfo.OrderCharging != NO_DEFINE)
+		ShmSysConfigAndInfo->SysInfo.OrderCharging = NO_DEFINE;
+}
+
+void DetectPluginStart()
+{
+	ShmSysConfigAndInfo->SysInfo.WaitForPlugit = YES;
+}
+
+bool isDetectPlugin()
+{
+	if(ShmSysConfigAndInfo->SysInfo.WaitForPlugit == YES)
+		return YES;
+
+	return NO;
+}
+
+//===============================================
+// Common Detect Chk - Chademo
+//===============================================
+bool isEvGunLocked_chademo(byte gunIndex)
+{
+	return (DetectBitValue(chargingInfo[gunIndex]->GunLocked , 0) == 0)? NO : YES;
+}
+
+bool isEvContactorWelding_chademo(byte gunIndex)
+{
+	return DetectBitValue(ShmCHAdeMOData->ev[chargingInfo[gunIndex]->type_index].EvDetection, 3);
+}
+
+bool isEvStopReq_chademo(byte gunIndex)
+{
+	return DetectBitValue(ShmCHAdeMOData->ev[chargingInfo[gunIndex]->type_index].EvDetection, 4);
+}
+
+bool isEvStopCharging_chademo(byte gunIndex)
+{
+	if (isEvGunLocked_chademo(gunIndex) == NO)
+	{
+		// 無鎖槍 = 停止
+		PRINTF_FUNC("gun locked none (%d) \n", gunIndex);
+		return YES;
+	}
+
+	return NO;
+}
+
+byte isPrechargeStatus_chademo(byte gunIndex)
+{
+	byte result = 0x00;
+
+	result = ShmCHAdeMOData->ev[chargingInfo[gunIndex]->type_index].PresentMsgFlowStatus;
+
+	return result;
+}
+//===============================================
+// Common Detect Chk - GB
+//===============================================
+bool isEvGunLocked_gb(byte gunIndex)
+{
+	return (DetectBitValue(chargingInfo[gunIndex]->GunLocked , 0) == 0)? NO : YES;
+}
+
+bool isEvStopCharging_gb(byte gunIndex)
+{
+	if (isEvGunLocked_gb(gunIndex) == NO)
+	{
+		// 無鎖槍 = 停止
+		PRINTF_FUNC("gun locked none. \n");
+		return YES;
+	}
+
+	return NO;
+}
+
+byte isPrechargeStatus_gb(byte gunIndex)
+{
+	byte result = 0x00;
+
+	result = ShmGBTData->ev[chargingInfo[gunIndex]->type_index].PresentMsgFlowStatus;
+
+	return result;
+}
+
+//===============================================
+// Common Detect Chk - CCS
+//===============================================
+bool isEvGunLocked_ccs(byte gunIndex)
+{
+	return (DetectBitValue(chargingInfo[gunIndex]->GunLocked , 0) == 0)? NO : YES;
+}
+
+byte isPrechargeStatus_ccs(byte gunIndex)
+{
+	byte result = 0x00;
+
+	if (ShmCcsData->CommProtocol == _CCS_COMM_V2GMessage_DIN70121)
+	{
+		result = ShmCcsData->V2GMessage_DIN70121[chargingInfo[gunIndex]->type_index].PresentMsgFlowStatus;
+	}
+
+	return result;
+}
+
+bool isEvStopCharging_ccs(byte gunIndex)
+{
+	if (isEvGunLocked_ccs(gunIndex) == NO)
+	{
+		// 無鎖槍 = 停止
+		PRINTF_FUNC("gun locked none. \n");
+		return YES;
+	}
+
+	return NO;
+}
+
+//===============================================
+// Callback
+//===============================================
+void DisplayChargingInfo()
+{
+	PRINTF_FUNC("*********** DisplayChargingInfo *********** \n");
+	for (byte i = 0; i < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; i++)
+	{
+		if (chargingInfo[i]->SystemStatus != S_IDLE &&
+				chargingInfo[i]->SystemStatus != S_RESERVATION)
+		{
+			ChangeGunSelectByIndex(i);
+			return;
+		}
+	}
+
+	if (ShmSysConfigAndInfo->SysConfig.AcConnectorCount > 0 &&
+		ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc == NO_DEFINE &&
+		ac_chargingInfo[0]->SystemStatus >= S_PREPARNING && ac_chargingInfo[0]->SystemStatus <= S_COMPLETE)
+	{
+		ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc = DEFAULT_AC_INDEX;
+	}
+
+	usleep(50000);
+	ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
+}
+
+void _AutoReturnTimeout()
+{
+	PRINTF_FUNC("*********** _AutoReturnTimeout %d*********** \n", ShmSysConfigAndInfo->SysInfo.PageIndex);
+	if (ShmSysConfigAndInfo->SysInfo.PageIndex == _LCM_WAIT_FOR_PLUG)
+	{
+		ClearDetectPluginFlag();
+	}
+//	else if (ShmSysConfigAndInfo->SysInfo.PageIndex == _LCM_AUTHORIZ_COMP)
+//	{
+//		DetectPluginStart();
+//	}
+	usleep(50000);
+	ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
+}
+
+void _SelfTestTimeout(void)
+{
+	if (ShmSysConfigAndInfo->SysInfo.BootingStatus != BOOT_COMPLETE)
+	{
+		for (byte gun_index = 0; gun_index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gun_index++)
+		{
+			setChargerMode(gun_index, MODE_ALARM);
+		}
+	}
+	ShmPsuData->Work_Step = _NO_WORKING;
+	ShmSysConfigAndInfo->SysInfo.SelfTestSeq = _STEST_FAIL;
+	PRINTF_FUNC("Self test timeout. \n");
+}
+
+void _AuthorizedTimeout()
+{
+	if(IsAuthorizingMode())
+	{
+		PRINTF_FUNC("*********** _AuthorizedTimeout *********** \n");
+		isCardScan = false;
+		ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_AUTHORIZ_FAIL;
+		ChangeLcmByIndex(_LCM_AUTHORIZ_FAIL);
+		strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
+		ClearAuthorizedFlag();
+	}
+}
+
+void _DetectPlugInTimeout()
+{
+	PRINTF_FUNC("*********** _DetectPlugInTimeout *********** \n");
+	strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
+	ClearDetectPluginFlag();
+	usleep(50000);
+	ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
+}
+
+void _DetectEvChargingEnableTimeout(byte gunIndex)
+{
+	if (chargingInfo[gunIndex]->Type == _Type_Chademo)
+	{
+		if(!isEvGunLocked_chademo(gunIndex))
+		{
+			PRINTF_FUNC("*********** _DetectEvChargingEnableTimeout (chademo) ***********\n");
+		}
+	}
+	else if (chargingInfo[gunIndex]->Type == _Type_GB)
+	{
+		if(!isEvGunLocked_ccs(gunIndex))
+		{
+			PRINTF_FUNC("*********** _DetectEvChargingEnableTimeout (gb) ***********\n");
+		}
+	}
+	else if (chargingInfo[gunIndex]->Type == _Type_CCS_2)
+	{
+		if(!isEvGunLocked_ccs(gunIndex))
+		{
+			PRINTF_FUNC("*********** _DetectEvChargingEnableTimeout (ccs) ***********\n");
+		}
+	}
+	ChargingTerminalProcess(gunIndex);
+	_AutoReturnTimeout();
+}
+
+void _DetectEvseChargingEnableTimeout(byte gunIndex)
+{
+	PRINTF_FUNC("*********** _DetectEvseChargingEnableTimeout (GFD timeout) ***********\n");
+	//if (chargingInfo[gunIndex]->GroundFaultStatus != GFD_PASS)
+	{
+		setChargerMode(gunIndex, MODE_IDLE);
+		_AutoReturnTimeout();
+	}
+}
+
+void _PrepareTimeout(byte gunIndex)
+{
+	PRINTF_FUNC("*********** _PrepareTimeout ***********\n");
+	setChargerMode(gunIndex, MODE_IDLE);
+	ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuNoResource = YES;
+	_AutoReturnTimeout();
+}
+
+void _CcsPrechargeTimeout(byte gunIndex)
+{
+	PRINTF_FUNC("*********** _CcsPrechargeTimeout ***********\n");
+	setChargerMode(gunIndex, MODE_IDLE);
+}
+
+//===============================================
+// 取得卡號與卡號驗證
+//===============================================
+bool canStartCharging()
+{
+	char buf2[16] = "";
+	memset(buf2, 0, ARRAY_SIZE(buf2));
+
+	for (byte index = 0; index < strlen((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status); index++)
+	{
+		sprintf(buf2 + (index - 1) * 2, "%02X",	ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status[index]);
+	}
+	sprintf(buf2, "%s",	ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
+
+	// 因為無法得知實際的長度,所以只能用搜尋的方式
+	if(strcmp(buf2, "Accepted") == EQUAL)
+		return true;
+	else
+	{
+
+	}
+
+	return false;
+}
+
+void AuthorizingStart()
+{
+	ShmOCPP16Data->SpMsg.bits.AuthorizeReq = YES;
+	ShmSysConfigAndInfo->SysInfo.AuthorizeFlag = YES;
+}
+
+void ClearAuthorizedFlag()
+{
+	ShmOCPP16Data->SpMsg.bits.AuthorizeConf = NO;
+	ShmSysConfigAndInfo->SysInfo.AuthorizeFlag = NO;
+}
+
+bool isAuthorizedComplete()
+{
+	if (ShmOCPP16Data->SpMsg.bits.AuthorizeConf == NO)
+		return false;
+
+	return true;
+}
+
+bool IsAuthorizingMode()
+{
+	if(ShmSysConfigAndInfo->SysInfo.AuthorizeFlag == NO)
+		return false;
+
+	return true;
+}
+
+//===============================================
+// 紀錄 Alarm Code
+//===============================================
+void RecordAlarmCode(byte gunIndex, char *code)
+{
+	memcpy(chargingInfo[gunIndex]->ConnectorAlarmCode, code, 6);
+
+	if (strcmp(code, "012234") == EQUAL) ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoGfdTrip = YES;
+	if (strcmp(code, "012235") == EQUAL) ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsGfdTrip = YES;
+	if (strcmp(code, "012236") == EQUAL) ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbGfdTrip = YES;
+	if (strcmp(code, "012288") == EQUAL) ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsOutputUVPFail = YES;
+	if (strcmp(code, "012289") == EQUAL) ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoOutputUVPFail = YES;
+	if (strcmp(code, "012290") == EQUAL) ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbtOutputUVPFail = YES;
+}
+
+void RecordWarningCode(byte gunIndex, char *code)
+{
+	memcpy(chargingInfo[gunIndex]->ConnectorWarningCode, code, 6);
+
+	if (strcmp(code, "012296") == EQUAL) ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoGroundWarning = YES;
+	if (strcmp(code, "012297") == EQUAL) ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsGroundfaultWarning = YES;
+	if (strcmp(code, "012298") == EQUAL) ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbGroundfaultWarning = YES;
+}
+
+void ReleaseAlarmCode(byte gunIndex)
+{
+	bool isCleanCheck = false;
+	char code[7];
+
+	if (chargingInfo[gunIndex]->Type == _Type_Chademo)
+	{
+		if (strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012234", 6) == EQUAL &&
+			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoGfdTrip == YES)
+		{
+			memcpy(code, "012234", 6);
+			memcpy(chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6);
+			isCleanCheck = true;
+		}
+		else if (strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012289", 6) == EQUAL &&
+				ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoOutputUVPFail == YES)
+		{
+			memcpy(code, "012289", 6);
+			memcpy(chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6);
+			isCleanCheck = true;
+		}
+		else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoGroundWarning == YES)
+		{
+			ReleaseWarningCodeByString(gunIndex, "012296");
+		}
+	}
+	else if (chargingInfo[gunIndex]->Type == _Type_GB)
+	{
+		if (strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012236", 6) == EQUAL &&
+			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbGfdTrip == YES)
+		{
+			memcpy(code, "012236", 6);
+			memcpy(chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6);
+			isCleanCheck = true;
+		}
+		else if (strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012290", 6) == EQUAL &&
+				ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbtOutputUVPFail == YES)
+		{
+			memcpy(code, "012290", 6);
+			memcpy(chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6);
+			isCleanCheck = true;
+		}
+		else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbGroundfaultWarning == YES)
+		{
+			ReleaseWarningCodeByString(gunIndex, "012298");
+		}
+	}
+	else if (chargingInfo[gunIndex]->Type == _Type_CCS_2)
+	{
+		if (strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012235", 6) == EQUAL &&
+			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsGfdTrip == YES)
+		{
+			memcpy(code, "012235", 6);
+			memcpy(chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6);
+			isCleanCheck = true;
+		}
+		else if (strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012288", 6) == EQUAL &&
+				ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsOutputUVPFail == YES)
+		{
+			memcpy(code, "012288", 6);
+			memcpy(chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6);
+			isCleanCheck = true;
+		}
+		else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsGroundfaultWarning == YES)
+		{
+			ReleaseWarningCodeByString(gunIndex, "012297");
+		}
+	}
+
+	if (isCleanCheck)
+	{
+		for (byte index = 0; index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; index++)
+		{
+			if (index != gunIndex || ShmSysConfigAndInfo->SysConfig.TotalConnectorCount == 1)
+			{
+				if (strncmp((char *)chargingInfo[index]->ConnectorAlarmCode, code, 6) != EQUAL)
+				{
+					if (strncmp(code, "012234", 6) == EQUAL) ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoGfdTrip = NO;
+					if (strncmp(code, "012289", 6) == EQUAL) ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoOutputUVPFail = NO;
+
+					if (strncmp(code, "012236", 6) == EQUAL) ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbGfdTrip = NO;
+					if (strncmp(code, "012290", 6) == EQUAL) ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbtOutputUVPFail = NO;
+
+					if (strncmp(code, "012235", 6) == EQUAL) ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsGfdTrip = NO;
+					if (strncmp(code, "012288", 6) == EQUAL) ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsOutputUVPFail = NO;
+				}
+			}
+		}
+	}
+}
+
+void ReleaseWarningCodeByString(byte gunIndex, char *code)
+{
+	bool isCleanCheck = false;
+
+	if (strncmp((char *)chargingInfo[gunIndex]->ConnectorWarningCode, code, 6) == EQUAL &&
+			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoGroundWarning == YES)
+	{
+		memcpy(chargingInfo[gunIndex]->ConnectorWarningCode, "", 6);
+		isCleanCheck = true;
+	}
+	else if (strncmp((char *)chargingInfo[gunIndex]->ConnectorWarningCode, code, 6) == EQUAL &&
+			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsGroundfaultWarning == YES)
+	{
+		memcpy(chargingInfo[gunIndex]->ConnectorWarningCode, "", 6);
+		isCleanCheck = true;
+	}
+	else if (strncmp((char *)chargingInfo[gunIndex]->ConnectorWarningCode, code, 6) == EQUAL &&
+			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbGroundfaultWarning == YES)
+	{
+		memcpy(chargingInfo[gunIndex]->ConnectorWarningCode, "", 6);
+		isCleanCheck = true;
+	}
+
+	if (isCleanCheck)
+	{
+		for (byte index = 0; index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; index++)
+		{
+			if (index != gunIndex || ShmSysConfigAndInfo->SysConfig.TotalConnectorCount == 1)
+			{
+				if (strncmp((char *)chargingInfo[index]->ConnectorWarningCode, code, 6) != EQUAL)
+				{
+					if (strncmp(code, "012296", 6) == EQUAL) ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoGroundWarning = NO;
+					if (strncmp(code, "012297", 6) == EQUAL) ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsGroundfaultWarning = NO;
+					if (strncmp(code, "012298", 6) == EQUAL) ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbGroundfaultWarning = NO;
+				}
+			}
+		}
+	}
+}
+//===============================================
+// EmergencyStop and Charging Stop
+//===============================================
+void ChargingTerminalProcess(byte gunIndex)
+{
+	setChargerMode(gunIndex, MODE_TERMINATING);
+}
+
+void AcChargingTerminalProcess()
+{
+	ac_chargingInfo[0]->SystemStatus = MODE_TERMINATING;
+}
+
+void StopChargingProcessByString(byte level)
+{
+	if (level > ShmSysConfigAndInfo->SysWarningInfo.Level)
+	{
+		ShmSysConfigAndInfo->SysWarningInfo.Level = level;
+	}
+}
+
+void ReleaseChargingProcessByString(byte level)
+{
+	if (level >= ShmSysConfigAndInfo->SysWarningInfo.Level)
+		ShmSysConfigAndInfo->SysWarningInfo.Level = 0;
+}
+
+// 一般錯誤停止充電處理函式
+void BoardErrOccurByString(byte index, char *code)
+{
+	byte level = 1;
+	if ((chargingInfo[index]->SystemStatus > S_IDLE && chargingInfo[index]->SystemStatus < S_TERMINATING) ||
+			(chargingInfo[index]->SystemStatus >= S_CCS_PRECHARGE_ST0 && chargingInfo[index]->SystemStatus <= S_CCS_PRECHARGE_ST1))
+	{
+		if (strncmp(code, "023730", 6) == EQUAL && ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoChargerGetEmergencyStop == NO)
+		{
+			ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoChargerGetEmergencyStop = YES;
+		}
+		ChargingTerminalProcess(index);
+	}
+
+	StopChargingProcessByString(level);
+}
+
+// 急停狀況的停止充電處理函式
+void EmcOccureByString(char *code)
+{
+	byte level = 2;
+	// 嚴重的急停有以下幾種 : EMC 按鈕、Mainbreak、Dooropen
+	// 其錯誤等級為 2
+	if (strncmp(code, "012251", 6) == EQUAL || strncmp(code, "012252", 6) == EQUAL ||
+			strncmp(code, "012238", 6) == EQUAL)
+	{
+		for (byte gun = 0; gun < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gun++)
+		{
+			if ((chargingInfo[gun]->SystemStatus > S_IDLE && chargingInfo[gun]->SystemStatus < S_TERMINATING) ||
+					(chargingInfo[gun]->SystemStatus >= S_CCS_PRECHARGE_ST0 && chargingInfo[gun]->SystemStatus <= S_CCS_PRECHARGE_ST1))
+			{
+				ChargingTerminalProcess(gun);
+			}
+		}
+
+		StopChargingProcessByString(level);
+		InformOcppErrOccur(4);
+	}
+}
+
+void ReleaseBoardErrOccurByString(byte index, char *code)
+{
+	bool isTrigger = false;
+	byte level = 1;
+
+	if (strncmp(code, "023730", 6) == 0 && ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoChargerGetEmergencyStop == YES)
+	{
+		isTrigger = true;
+		ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoChargerGetEmergencyStop = NO;
+	}
+
+	if (isTrigger)
+	{
+		ReleaseChargingProcessByString(level);
+	}
+}
+
+void ReleaseEmsOccureByString(byte index, char *code)
+{
+	bool isTrigger = false;
+	byte level = 2;
+
+	if (strncmp(code, "012251", 6) == 0 && ShmStatusCodeData->AlarmCode.AlarmEvents.bits.EmergencyStopTrip == YES)
+	{
+		isTrigger = true;
+		ShmStatusCodeData->AlarmCode.AlarmEvents.bits.EmergencyStopTrip = NO;
+	}
+	else if (strncmp(code, "012252", 6) == 0 && ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DoorOpen == YES)
+	{
+		isTrigger = true;
+		ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DoorOpen = NO;
+	}
+	else if (strncmp(code, "012237", 6) == 0 && ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SpdTrip == YES)
+	{
+		isTrigger = true;
+		ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SpdTrip = NO;
+	}
+	else if (strncmp(code, "012238", 6) == 0 && ShmStatusCodeData->AlarmCode.AlarmEvents.bits.MainPowerBreakerTrip == YES)
+	{
+		isTrigger = true;
+		ShmStatusCodeData->AlarmCode.AlarmEvents.bits.MainPowerBreakerTrip = NO;
+	}
+
+	if (isTrigger)
+	{
+		ReleaseChargingProcessByString(level);
+		InformOcppErrOccur(6);
+	}
+}
+
+//===============================================
+// 確認硬體 (按鈕) 狀態
+//===============================================
+bool leftBtnPush = false;
+bool rightBtnPush = false;
+
+void ChkPrimaryStatus()
+{
+	if (ShmPrimaryMcuData->InputDet.bits.EmergencyButton == ABNORMAL)
+	{
+		ShmStatusCodeData->AlarmCode.AlarmEvents.bits.EmergencyStopTrip = YES;
+		EmcOccureByString("012251");
+	}
+	else
+		ReleaseEmsOccureByString(0, "012251");
+
+	if (ShmPrimaryMcuData->InputDet.bits.AcMainBreakerDetec == ABNORMAL)
+	{
+		ShmStatusCodeData->AlarmCode.AlarmEvents.bits.MainPowerBreakerTrip = YES;
+		EmcOccureByString("012238");
+	}
+	else
+		ReleaseEmsOccureByString(0, "012238");
+
+	if (ShmPrimaryMcuData->InputDet.bits.SpdDetec == ABNORMAL)
+	{
+		ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SpdTrip = YES;
+	}
+	else
+		ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SpdTrip = NO;
+
+	if (ShmPrimaryMcuData->InputDet.bits.DoorOpen == ABNORMAL)
+	{
+		ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DoorOpen = YES;
+		EmcOccureByString("012252");
+	}
+	else
+		ReleaseEmsOccureByString(0, "012252");
+/*
+	if (ShmPrimaryMcuData->InputDet.bits.Button1 == BTN_PRESS && !leftBtnPush)
+	{
+		if(!leftBtnPush)
+		{
+			leftBtnPush = true;
+			PRINTF_FUNC("left btn down............................... \n");
+			if (ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc != NO_DEFINE)
+			{
+				switch(ac_chargingInfo[0]->SystemStatus)
+				{
+				case S_IDLE:
+				{
+					if(isDetectPlugin())
+					{
+						_DetectPlugInTimeout();
+						StopSystemTimeoutDet();
+					}
+				}
+					break;
+				case S_REASSIGN_CHECK:
+				case S_REASSIGN:
+				case S_PREPARNING:
+				case S_PREPARING_FOR_EV:
+				case S_PREPARING_FOR_EVSE:
+				case S_CCS_PRECHARGE_ST0:
+				case S_CCS_PRECHARGE_ST1:
+				{
+					// 取消充電
+					AcChargingTerminalProcess();
+				}
+					break;
+				case S_CHARGING:
+				{
+					if (ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_DISABLE)
+					{
+						// 停止充電
+						AcChargingTerminalProcess();
+					}
+				}
+					break;
+				case S_COMPLETE:
+				{}
+					break;
+				}
+			}
+
+			switch(chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
+			{
+				case S_IDLE:
+				{
+					if(isDetectPlugin())
+					{
+						_DetectPlugInTimeout();
+						StopSystemTimeoutDet();
+					}
+				}
+					break;
+				case S_REASSIGN_CHECK:
+				case S_REASSIGN:
+				case S_PREPARNING:
+				case S_PREPARING_FOR_EV:
+				case S_PREPARING_FOR_EVSE:
+				case S_CCS_PRECHARGE_ST0:
+				case S_CCS_PRECHARGE_ST1:
+				{
+					// 取消充電
+					if (ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc != NO_DEFINE)
+						AcChargingTerminalProcess();
+					else
+						ChargingTerminalProcess(ShmSysConfigAndInfo->SysInfo.CurGunSelected);
+				}
+					break;
+				case S_CHARGING:
+				{
+					if (ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_DISABLE &&
+							chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->isRemoteStart == NO)
+					{
+						// 停止充電
+						ChargingTerminalProcess(ShmSysConfigAndInfo->SysInfo.CurGunSelected);
+					}
+				}
+					break;
+				case S_COMPLETE:
+				{
+					// 回 IDLE
+					//PRINTF_FUNC("right btn down.................S_COMPLETE \n");
+					//chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_IDLE;
+				}
+					break;
+			}
+		}
+	}
+	else if (ShmPrimaryMcuData->InputDet.bits.Button1 == BTN_RELEASE)
+	{
+		if(leftBtnPush)
+		{
+			leftBtnPush = false;
+			PRINTF_FUNC("left btn up............................... \n");
+		}
+	}
+
+	if (ShmPrimaryMcuData->InputDet.bits.Button2 == BTN_PRESS && !rightBtnPush)
+	{
+		if(!rightBtnPush)
+		{
+			rightBtnPush = true;
+			PRINTF_FUNC("right btn down............................... %d \n", ShmSysConfigAndInfo->SysInfo.CurGunSelected);
+			if (ShmSysConfigAndInfo->SysInfo.CurGunSelected + 1 < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount &&
+					ShmSysConfigAndInfo->SysInfo.IsAlternatvieConf == NO)
+			{
+				ShmSysConfigAndInfo->SysInfo.CurGunSelected++;
+				ChangeGunSelectByIndex(ShmSysConfigAndInfo->SysInfo.CurGunSelected);
+			}
+			else if (ShmSysConfigAndInfo->SysConfig.AcConnectorCount > 0 &&
+					ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc == NO_DEFINE)
+				ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc = DEFAULT_AC_INDEX;
+			else if (ShmSysConfigAndInfo->SysInfo.IsAlternatvieConf == YES)
+			{
+				for (byte _index = 0; _index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _index++)
+				{
+					if (chargingInfo[_index]->SystemStatus != S_BOOTING &&
+							chargingInfo[_index]->SystemStatus != S_IDLE &&
+							chargingInfo[_index]->SystemStatus != S_RESERVATION)
+					{
+						ShmSysConfigAndInfo->SysInfo.CurGunSelected = _index;
+						ChangeGunSelectByIndex(ShmSysConfigAndInfo->SysInfo.CurGunSelected);
+						return;
+					}
+				}
+
+				ShmSysConfigAndInfo->SysInfo.CurGunSelected = 0;
+				ChangeGunSelectByIndex(ShmSysConfigAndInfo->SysInfo.CurGunSelected);
+			}
+			else
+			{
+				ShmSysConfigAndInfo->SysInfo.CurGunSelected = 0;
+				ChangeGunSelectByIndex(ShmSysConfigAndInfo->SysInfo.CurGunSelected);
+			}
+		}
+	}
+	else if (ShmPrimaryMcuData->InputDet.bits.Button2 == BTN_RELEASE)
+	{
+		if(rightBtnPush)
+		{
+			rightBtnPush = false;
+			PRINTF_FUNC("right btn up............................... \n");
+		}
+	}
+*/
+}
+
+//===============================================
+// 確認各小板偵測的錯誤狀況
+//===============================================
+void CheckErrorOccurStatus(byte index)
+{
+	// 小板
+	if (chargingInfo[index]->Type == _Type_Chademo)
+	{
+		if (ShmStatusCodeData->FaultCode.FaultEvents.bits.ChademoOutputRelayDrivingFault == YES)
+			BoardErrOccurByString(index, "011012");
+//		else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoGfdTrip == YES)
+//			BoardErrOccurByString(index, "012234");
+	}
+	else if (chargingInfo[index]->Type == _Type_GB)
+	{
+		if (ShmStatusCodeData->FaultCode.FaultEvents.bits.GbOutputRelayDrivingFault == YES)
+			BoardErrOccurByString(index, "011016");
+//		else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbGfdTrip == YES)
+//			BoardErrOccurByString(index, "012236");
+	}
+	else if (chargingInfo[index]->Type == _Type_CCS_2)
+	{
+		if (ShmStatusCodeData->FaultCode.FaultEvents.bits.CcsOutputRelayDrivingFault == YES)
+			BoardErrOccurByString(index, "011014");
+//		else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsGfdTrip == YES)
+//			BoardErrOccurByString(index, "012235");
+	}
+
+	// RB
+	if (ShmSysConfigAndInfo->SysConfig.PhaseLossPolicy == YES)
+	{
+		if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputUVP == YES ||
+				ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputUVP == YES ||
+				ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputUVP == YES)
+		{
+			if (ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess == _EXTRA_ERR_PROCESS_NONE)
+			{
+				ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess = _EXTRA_ERR_PROCESS_INUVP;
+				StopChargingProcessByString(2);
+				InformOcppErrOccur(13);
+			}
+		}
+		else
+		{
+			if (ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess == _EXTRA_ERR_PROCESS_INUVP)
+			{
+				ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess = _EXTRA_ERR_PROCESS_NONE;
+				ReleaseChargingProcessByString(2);
+				InformOcppErrOccur(6);
+			}
+		}
+	}
+	else
+	{
+		if (ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess == _EXTRA_ERR_PROCESS_INUVP)
+		{
+			ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess = _EXTRA_ERR_PROCESS_NONE;
+			ReleaseChargingProcessByString(2);
+			InformOcppErrOccur(6);
+		}
+	}
+
+	if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputOVP == YES ||
+			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputOVP == YES ||
+			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputOVP == YES)
+	{
+		if (ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess == _EXTRA_ERR_PROCESS_NONE)
+		{
+			ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess = _EXTRA_ERR_PROCESS_INOVP;
+			StopChargingProcessByString(2);
+			InformOcppErrOccur(14);
+		}
+	}
+	else
+	{
+		if (ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess == _EXTRA_ERR_PROCESS_INOVP)
+		{
+			ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess = _EXTRA_ERR_PROCESS_NONE;
+			ReleaseChargingProcessByString(2);
+			InformOcppErrOccur(6);
+		}
+	}
+}
+
+/*
+//===============================================
+// 確認 GPIO 狀態
+//===============================================
+void gpio_set_value(unsigned int gpio, unsigned int value)
+{
+	int fd;
+	char buf[MAX_BUF];
+
+	snprintf(buf, sizeof(buf), SYSFS_GPIO_DIR "/gpio%d/value", gpio);
+	fd = open(buf, O_WRONLY);
+	if (fd < 0)
+	{
+	    perror("gpio/set-value");
+	    return;
+	}
+
+	if (value)
+		write(fd, "1", 2);
+	else
+	    write(fd, "0", 2);
+
+	close(fd);
+}
+
+int gpio_get_value(unsigned int gpio, unsigned int *value)
+{
+    int fd;
+    char buf[MAX_BUF];
+    char ch;
+
+    snprintf(buf, sizeof(buf), SYSFS_GPIO_DIR "/gpio%d/value", gpio);
+
+    fd = open(buf, O_RDONLY);
+    if (fd < 0) {
+        perror("gpio/get-value");
+        return fd;
+    }
+
+    read(fd, &ch, 1);
+
+    if (ch != '0') {
+        *value = 1;
+    } else {
+        *value = 0;
+    }
+
+    close(fd);
+    return 0;
+}
+
+void CheckGunTypeFromHw()
+{
+	int pinIn[4] = { 22, 23, 44, 45 };
+	unsigned int gpioValue = 0;
+
+	for (int i = 0; i < ARRAY_SIZE(pinIn); i++) {
+		gpio_get_value(pinIn[i], &gpioValue);
+		{
+			switch (pinIn[i])
+			{
+			case 22:
+				bd1_1_status = gpioValue;
+				break;
+			case 23:
+				bd1_2_status = gpioValue;
+				break;
+			case 44:
+				bd0_1_status = gpioValue;
+				break;
+			case 45:
+				bd0_2_status = gpioValue;
+				break;
+			}
+		}
+	}
+}
+
+void CheckGpioInStatus()
+{
+	int pinIn[2] = { 27, 47 };
+	unsigned int gpioValue = 0;
+
+	for (int i = 0; i < ARRAY_SIZE(pinIn); i++)
+	{
+		gpio_get_value(pinIn[i], &gpioValue);
+		if (gpioValue == 0x01)
+		{
+			switch(pinIn[i])
+			{
+				// 小板緊急停止
+				case 47:
+				{
+					for(int i = 0; i < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; i++)
+					{
+						if (chargingInfo[i]->slotsIndex == 1)
+						{
+							if (chargingInfo[i]->Type == _Type_Chademo)
+								BoardErrOccurByString(i, "023730");
+							else if (chargingInfo[i]->Type == _Type_CCS_2)
+								BoardErrOccurByString(i, "013627");
+							break;
+						}
+					}
+				}
+					break;
+				case 27:
+				{
+					for(int i = 0; i < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; i++)
+					{
+						if (chargingInfo[i]->slotsIndex == 3)
+						{
+							if (chargingInfo[i]->Type == _Type_Chademo)
+								BoardErrOccurByString(i, "023730");
+							else if (chargingInfo[i]->Type == _Type_CCS_2)
+								BoardErrOccurByString(i, "013627");
+							break;
+						}
+					}
+				}
+					break;
+			}
+		}
+		else
+		{
+			switch (pinIn[i])
+			{
+				// 小板解除緊急停止
+				case 47:
+				{
+					for(int i = 0; i < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; i++)
+					{
+						if (chargingInfo[i]->slotsIndex == 1)
+						{
+							if (chargingInfo[i]->Type == _Type_Chademo)
+								ReleaseBoardErrOccurByString(i, "023730");
+							else if (chargingInfo[i]->Type == _Type_CCS_2)
+								ReleaseBoardErrOccurByString(i, "013627");
+							break;
+						}
+					}
+				}
+					break;
+				case 27:
+				{
+					for (int i = 0; i < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; i++)
+					{
+						if (chargingInfo[i]->slotsIndex == 3)
+						{
+							if (chargingInfo[i]->Type == _Type_Chademo)
+								ReleaseBoardErrOccurByString(i, "023730");
+							else if (chargingInfo[i]->Type == _Type_CCS_2)
+								ReleaseBoardErrOccurByString(i, "013627");
+							break;
+						}
+					}
+				}
+				break;
+			}
+		}
+	}
+}
+*/
+
+//===============================================
+// Main process
+//===============================================
+// 檢查 Byte 中某個 Bit 的值
+// _byte : 欲改變的 byte
+// _bit : 該 byte 的第幾個 bit
+unsigned char DetectBitValue(unsigned char _byte, unsigned char _bit)
+{
+	return ( _byte & mask_table[_bit] ) != 0x00;
+}
+
+// 設定 Byte 中某個 Bit的值
+// _byte : 欲改變的 byte
+// _bit : 該 byte 的第幾個 bit
+// value : 修改的值為 0 or 1
+void SetBitValue(unsigned char *_byte, unsigned char _bit, unsigned char value)
+{
+	if(value == 1)
+		*_byte |= (1 << _bit);
+	else if (value == 0)
+		*_byte ^= (1 << _bit);
+}
+
+void UserScanFunction()
+{
+	bool idleReq = false;
+	unsigned char idleIndex = 255;
+//	unsigned char stopReq = 255;
+
+	// 當前非驗證的狀態
+	if(!IsAuthorizingMode())
+	{
+		// 先判斷現在是否可以提供刷卡
+		// 1. 如果當前沒有槍是閒置狀態,則無提供刷卡功能
+		// 2. 停止充電
+//		if (ShmSysConfigAndInfo->SysInfo.PageIndex == _LCM_FIX)
+//		{
+//			strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
+//			return;
+//		}
+
+		for (byte i = 0; i < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; i++)
+		{
+//			if (chargingInfo[i]->SystemStatus == S_CHARGING)
+//			{
+//				stopReq = i;
+//			}
+//			if ((chargingInfo[i]->SystemStatus == S_IDLE && chargingInfo[i]->IsAvailable == YES) ||
+//					(_acgunIndex > 0 && ac_chargingInfo[0]->SystemStatus == S_IDLE && ac_chargingInfo[0]->IsAvailable == YES))
+//			{
+//				idleReq = true;
+//				idleIndex = i;
+//			}
+			if(chargingInfo[i]->SystemStatus == S_IDLE && chargingInfo[i]->IsAvailable == YES)
+			{
+				idleReq = true;
+				idleIndex = i;
+			}
+		}
+
+//		if (_acgunIndex > 0 && ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc == DEFAULT_AC_INDEX &&
+//				ac_chargingInfo[0]->SystemStatus == S_CHARGING)
+//		{
+//			stopReq = DEFAULT_AC_INDEX;
+//		}
+
+		if (strlen((char *)ShmSysConfigAndInfo->SysConfig.UserId) > 0)
+		{
+//			if (_acgunIndex > 0 && stopReq == DEFAULT_AC_INDEX && ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc == DEFAULT_AC_INDEX)
+//			{
+//				char value[32];
+
+//				PRINTF_FUNC("ac stop charging \n");
+//				PRINTF_FUNC("index = %d, card number = %s, UserId = %s \n", ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc,
+//						ac_chargingInfo[0]->StartUserId, ShmSysConfigAndInfo->SysConfig.UserId);
+//				memcpy(value, (unsigned char *)ac_chargingInfo[0]->StartUserId,
+//					ARRAY_SIZE(ac_chargingInfo[0]->StartUserId));
+//				if (strcmp((char *)ShmSysConfigAndInfo->SysConfig.UserId, value) == EQUAL)
+//				{
+//					AcChargingTerminalProcess();
+//				}
+//				strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
+//			}
+/*
+			if (stopReq < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount &&
+					chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus == S_CHARGING &&
+					(_acgunIndex <= 0 || (_acgunIndex > 0 && ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc == NO_DEFINE)))
+			{
+				char value[32];
+
+				PRINTF_FUNC("stop charging \n");
+				PRINTF_FUNC("index = %d, card number = %s, UserId = %s \n", ShmSysConfigAndInfo->SysInfo.CurGunSelected,
+						chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->StartUserId, ShmSysConfigAndInfo->SysConfig.UserId);
+				memcpy(value, (unsigned char *)chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->StartUserId,
+						ARRAY_SIZE(chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->StartUserId));
+
+				// 同一張卡直接停掉
+				if (strcmp((char *)ShmSysConfigAndInfo->SysConfig.UserId, value) == EQUAL)
+				{
+					ChargingTerminalProcess(ShmSysConfigAndInfo->SysInfo.CurGunSelected);
+					strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
+				}
+				else
+				{
+					strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
+//					// 進驗證
+//					if (_acgunIndex > 0 && ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc == DEFAULT_AC_INDEX)
+//					{
+//						_authorizeIndex = ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc;
+//					}
+//					else
+//					{
+//						_authorizeIndex = ShmSysConfigAndInfo->SysInfo.CurGunSelected;
+//					}
+//
+//					StartSystemTimeoutDet(Timeout_AuthorizingForStop);
+//					AuthorizingStart();
+				}
+			}
+*/
+			if (idleReq)
+			{
+//				if (ShmSysConfigAndInfo->SysConfig.TotalConnectorCount > 1 &&
+//						stopReq != 255 &&
+//						ShmSysConfigAndInfo->SysInfo.IsAlternatvieConf == YES)
+//				{
+//					idleReq = false;
+//					strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
+//				}
+				if ((_acgunIndex > 0 && ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc == DEFAULT_AC_INDEX) ||
+						(idleIndex != 255 && chargingInfo[idleIndex]->SystemStatus == S_IDLE))
+				{
+					PRINTF_FUNC("// LCM => Authorizing \n");
+					// LCM => Authorizing
+					ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_AUTHORIZING;
+					// 進入確認卡號狀態
+					AuthorizingStart();
+				}
+				else
+					strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
+			}
+			else
+			{
+				strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
+			}
+		}
+	}
+	else
+	{
+		// 透過後臺停止充電的判斷
+		if (isAuthorizedComplete() ||
+				(ShmSysConfigAndInfo->SysInfo.OcppConnStatus == NO &&
+					ShmSysConfigAndInfo->SysConfig.OfflinePolicy == _OFFLINE_POLICY_FREE_CHARGING))
+		{
+			// 判斷後台回覆狀態
+			if(canStartCharging() ||
+				(ShmSysConfigAndInfo->SysInfo.OcppConnStatus == NO &&
+					ShmSysConfigAndInfo->SysConfig.OfflinePolicy == _OFFLINE_POLICY_FREE_CHARGING))
+			{
+				if (_authorizeIndex != NO_DEFINE)
+				{
+					// 先找 AC
+					if (_authorizeIndex == DEFAULT_AC_INDEX)
+					{
+						if (ShmSysConfigAndInfo->SysConfig.OfflinePolicy == _OFFLINE_POLICY_LOCAL_LIST &&
+								strcmp((char *)chargingInfo[_authorizeIndex]->StartUserId, "") != EQUAL)
+						{
+							AcChargingTerminalProcess();
+						}
+					}
+					else
+					{
+						if (ShmSysConfigAndInfo->SysConfig.OfflinePolicy == _OFFLINE_POLICY_LOCAL_LIST &&
+								strcmp((char *)chargingInfo[_authorizeIndex]->StartUserId, "") != EQUAL)
+						{
+							ChargingTerminalProcess(_authorizeIndex);
+						}
+					}
+					strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
+					_authorizeIndex = NO_DEFINE;
+				}
+			}
+			else
+				strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
+
+			PRINTF_FUNC("ClearAuthorizedFlag");
+			ClearAuthorizedFlag();
+		}
+		else if (ShmSysConfigAndInfo->SysConfig.OfflinePolicy == _OFFLINE_POLICY_LOCAL_LIST)
+		{
+			// 白名單驗證
+			for (int i = 0; i < 10; i++)
+			{
+				if (strcmp((char *)ShmSysConfigAndInfo->SysConfig.LocalWhiteCard[i], "") != EQUAL)
+				{
+					if (strcmp((char *)ShmSysConfigAndInfo->SysConfig.LocalWhiteCard[i], (char *)ShmSysConfigAndInfo->SysConfig.UserId) == EQUAL)
+					{
+						ChargingTerminalProcess(_authorizeIndex);
+						strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
+						ClearAuthorizedFlag();
+						break;
+					}
+				}
+			}
+		}
+	}
+}
+
+unsigned char isModeChange(unsigned char gun_index)
+{
+	unsigned char result = NO;
+
+	if(chargingInfo[gun_index]->SystemStatus != chargingInfo[gun_index]->PreviousSystemStatus)
+	{
+		result = YES;
+		chargingInfo[gun_index]->PreviousSystemStatus = chargingInfo[gun_index]->SystemStatus;
+	}
+
+	return result;
+}
+/*
+void ScannerCardProcess()
+{
+	if (!isDetectPlugin() && !isCardScan && ShmSysConfigAndInfo->SysWarningInfo.Level != 2 &&
+			ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_ENABLE)
+	{
+		isCardScan = true;
+		// 處理刷卡及驗證卡號的動作
+		UserScanFunction();
+	}
+
+	if (ShmSysConfigAndInfo->SysInfo.PageIndex == _LCM_AUTHORIZING)
+	{
+		StartSystemTimeoutDet(Timeout_Authorizing);
+
+		// 確認驗證卡號完成沒
+		if (isAuthorizedComplete() || ShmSysConfigAndInfo->SysConfig.OfflinePolicy == _OFFLINE_POLICY_FREE_CHARGING)
+		{
+			StopSystemTimeoutDet();
+			// 判斷後台回覆狀態
+			if(canStartCharging() || ShmSysConfigAndInfo->SysConfig.OfflinePolicy == _OFFLINE_POLICY_FREE_CHARGING)
+			{
+				// LCM => Authorize complete
+				ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_AUTHORIZ_COMP;
+				PRINTF_FUNC("User ID Authorized Completed");
+			}
+			else
+			{
+				// LCM => Authorize fail
+				ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_AUTHORIZ_FAIL;
+				strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
+			}
+			ClearAuthorizedFlag();
+		}
+		else if (ShmSysConfigAndInfo->SysConfig.OfflinePolicy == _OFFLINE_POLICY_LOCAL_LIST)
+		{
+			// 白名單驗證
+			for (int i = 0; i < 10; i++)
+			{
+				if (strcmp((char *)ShmSysConfigAndInfo->SysConfig.LocalWhiteCard[i], "") != EQUAL)
+				{
+					if (strcmp((char *)ShmSysConfigAndInfo->SysConfig.LocalWhiteCard[i], (char *)ShmSysConfigAndInfo->SysConfig.UserId) == EQUAL)
+					{
+						ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_AUTHORIZ_COMP;
+						ClearAuthorizedFlag();
+						break;
+					}
+				}
+			}
+		}
+	}
+	else if (ShmSysConfigAndInfo->SysInfo.PageIndex == _LCM_AUTHORIZ_FAIL)
+	{
+		StartSystemTimeoutDet(Timeout_VerifyFail);
+		isCardScan = false;
+	}
+	else if(ShmSysConfigAndInfo->SysInfo.PageIndex == _LCM_AUTHORIZ_COMP)
+	{
+		StartSystemTimeoutDet(Timeout_VerifyComp);
+	}
+	else if(ShmSysConfigAndInfo->SysInfo.PageIndex == _LCM_WAIT_FOR_PLUG)
+	{
+		StartSystemTimeoutDet(Timeout_WaitPlug);
+	}
+	else
+		isCardScan = false;
+}
+*/
+struct timeval _StartAuthorizing_Time;
+
+void PowerCabinetAuthorizingSettingInitial(void)
+{
+    ShmSysConfigAndInfo->SysInfo.CabinetSetting.bits.StartAuthorize = false;
+    ShmSysConfigAndInfo->SysInfo.CabinetSetting.bits.AuthorizingCompleted = false;
+    ShmSysConfigAndInfo->SysInfo.CabinetSetting.bits.AuthorizeTargetIndex = 0;
+}
+
+void AuthorizingSettingInitial(unsigned char index, unsigned char AuthorizeSrc)
+{
+    switch(AuthorizeSrc)
+    {
+        case _AuthorizeSrc_Local:
+            memset(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].UserId, 0x00, 32);
+            ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].AuthorizeStatus = _AuthorizeStatus_Idle;
+            ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].Setting.bits.AuthorizeRequest = false;
+            for(int i = 0; i < 2; i++)
+            {
+                if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].ConnectorID[i] != 0)
+                {
+                    unsigned char ConnectorIndex =  ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].ConnectorID[i] - 1;
+
+                    if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[ConnectorIndex].Parameter.bits.AuthorizeRequestType != _AuthorizeSrc_None)
+                    {
+                        PRINTF_FUNC("*********** Connector id %d AuthorizeReqClean ***********", ConnectorIndex + 1);
+                        ShmSysConfigAndInfo->SysInfo.ConnectorInfo[ConnectorIndex].Parameter.bits.AuthorizeRequestType = _AuthorizeSrc_None;
+                    }
+                }
+            }
+            break;
+        case _AuthorizeSrc_Remote:
+            memset(ShmOCPP16Data->RemoteStartTransaction[index].IdTag, 0x00, 20);
+            ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].AuthorizeStatus = _AuthorizeStatus_Idle;
+            ShmOCPP16Data->CsMsg.bits[index].RemoteStartTransactionReq = false;
+
+            if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].Parameter.bits.AuthorizeRequestType != _AuthorizeSrc_None)
+            {
+                PRINTF_FUNC("*********** Connector id %d AuthorizeReqClean ***********", index + 1);
+                ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].Parameter.bits.AuthorizeRequestType = _AuthorizeSrc_None;
+            }
+            break;
+    }
+}
+
+void SetAuthorizingTarget(unsigned char index, unsigned char AuthorizeSrc)
+{
+    BOOL valid = false;
+    switch(AuthorizeSrc)
+    {
+        case _AuthorizeSrc_Local:
+            valid = true;
+            PRINTF_FUNC("*********** Dispenser id %d  Local Authorize  ***********", index + 1);
+            memset(ShmSysConfigAndInfo->SysConfig.UserId, 0x00, 32);
+            memcpy(ShmSysConfigAndInfo->SysConfig.UserId, ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].UserId, 32);
+            ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].AuthorizeStatus = _AuthorizeStatus_Wait;
+            break;
+        case _AuthorizeSrc_Remote:
+            valid = true;
+            PRINTF_FUNC("*********** Connector id %d Remote Authorize  ***********", index + 1);
+            memset(ShmSysConfigAndInfo->SysConfig.UserId, 0x00, 32);
+            memcpy(ShmSysConfigAndInfo->SysConfig.UserId, ShmOCPP16Data->RemoteStartTransaction[index].IdTag, 20);
+            ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].AuthorizeStatus = _AuthorizeStatus_Wait;
+            break;
+    }
+
+    if(valid)
+    {
+        ShmSysConfigAndInfo->SysInfo.CabinetSetting.bits.StartAuthorize = true;
+        ShmSysConfigAndInfo->SysInfo.CabinetSetting.bits.AuthorizingCompleted = false;
+        ShmSysConfigAndInfo->SysInfo.CabinetSetting.bits.AuthorizeTargetIndex = index;
+        ShmSysConfigAndInfo->SysInfo.CabinetSetting.bits.AuthorizeSrc = AuthorizeSrc;
+    }
+}
+
+void SetConnectorAuthorizeOK(unsigned char index, unsigned char AuthorizeSrc)
+{
+    switch(AuthorizeSrc)
+    {
+        case _AuthorizeSrc_Local:
+            for(int i = 0; i < 2; i++)
+            {
+                if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].ConnectorID[i] != 0)
+                {
+                    unsigned char ConnectorIndex =  ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].ConnectorID[i] - 1;
+
+                    if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[ConnectorIndex].GeneralChargingData.SystemStatus == S_IDLE)
+                    {
+                        ShmSysConfigAndInfo->SysInfo.ConnectorInfo[ConnectorIndex].Parameter.bits.AuthorizeRequestType = _AuthorizeSrc_Local;
+                        memcpy(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[ConnectorIndex].GeneralChargingData.StartUserId, ShmSysConfigAndInfo->SysConfig.UserId, 32);
+                        PRINTF_FUNC("*********** Connector id %d LocalAuthorize OK ***********", ConnectorIndex + 1);
+                    }
+                }
+            }
+            break;
+
+        case _AuthorizeSrc_Remote:
+            if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == S_IDLE)
+            {
+                ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].Parameter.bits.AuthorizeRequestType = _AuthorizeSrc_Remote;
+                memcpy(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.StartUserId, ShmSysConfigAndInfo->SysConfig.UserId, 32);
+                PRINTF_FUNC("*********** Connector id %d RemoteAuthorize OK***********", index + 1);
+            }
+            break;
+    }
+}
+
+void OCPPAuthorizingStart(void)
+{
+    ShmOCPP16Data->SpMsg.bits.AuthorizeConf = false;
+    ShmOCPP16Data->SpMsg.bits.AuthorizeReq = true;
+}
+
+void AuthorizeTimeoutProcess(void)
+{
+    for(int index = 0; index < GENERAL_GUN_QUANTITY; index++)
+    {
+        switch(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].AuthorizeStatus)
+        {
+            case _AuthorizeStatus_Pass:
+                if(GetTimeoutValue(_ConnectorAuthorizing_Time[index]) / uSEC_VAL >= _connectionTimeout)
+                {
+                    PRINTF_FUNC("*********** Connector id %d  Plug In Timeout  ***********\n", index + 1);
+                    AuthorizingSettingInitial(index, _AuthorizeSrc_Remote);
+                }
+                break;
+
+            case _AuthorizeStatus_Fail:
+                if(GetTimeoutValue(_ConnectorAuthorizing_Time[index]) / uSEC_VAL >= AUTHORIZE_FAIL_TIMEOUT)
+                {
+                    PRINTF_FUNC("*********** Connector id %d Authorized Return ***********", index + 1);
+                    AuthorizingSettingInitial(index, _AuthorizeSrc_Remote);
+                }
+                break;
+
+            default:
+                // do nothing
+                break;
+        }
+
+        switch(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].AuthorizeStatus)
+        {
+            case _AuthorizeStatus_Pass:
+                if(GetTimeoutValue(_DispenserAuthorizing_Time[index]) / uSEC_VAL >= _connectionTimeout)
+                {
+                    PRINTF_FUNC("*********** Dispenser id %d  Plug In Timeout  ***********\n", index + 1);
+                    AuthorizingSettingInitial(index, _AuthorizeSrc_Local);
+                }
+                break;
+
+            case _AuthorizeStatus_Fail:
+                if(GetTimeoutValue(_DispenserAuthorizing_Time[index]) / uSEC_VAL >= AUTHORIZE_FAIL_TIMEOUT)
+                {
+                    PRINTF_FUNC("*********** Dispenser id %d Authorized Return ***********", index + 1);
+                    AuthorizingSettingInitial(index, _AuthorizeSrc_Local);
+                }
+                break;
+
+            default:
+                // do nothing
+                break;
+        }
+    }
+}
+
+void PowerCabinetAuthorizeProcess(void)
+{
+    char *str_auth_src[] = {AUTHORIZE_SRC_NONE_DEV, AUTHORIZE_SRC_LOCAL_DEV, AUTHORIZE_SRC_REMOTE_DEV};
+    BOOL FindRemoteStartRequest = false;
+
+    AuthorizeTimeoutProcess();
+
+    if(!ShmSysConfigAndInfo->SysInfo.CabinetSetting.bits.StartAuthorize)
+    {
+        for(int index = 0; index < GENERAL_GUN_QUANTITY; index++)
+        {
+            if(ShmOCPP16Data->CsMsg.bits[index].RemoteStartTransactionReq == true)
+            {
+                SetAuthorizingTarget(index, _AuthorizeSrc_Remote);
+                ShmOCPP16Data->CsMsg.bits[index].RemoteStartTransactionReq = false;
+                FindRemoteStartRequest = true;
+                break;
+            }
+        }
+
+        if(!FindRemoteStartRequest)
+        {
+            for(int index = 0; index < GENERAL_GUN_QUANTITY; index++)
+            {
+                if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].AuthorizeStatus == _AuthorizeStatus_Idle)
+                {
+                    if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].Setting.bits.AuthorizeRequest &&
+                        strlen((char *)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].UserId) > 0)
+                    {
+                        SetAuthorizingTarget(index, _AuthorizeSrc_Local);
+                        ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].Setting.bits.AuthorizeRequest = false;
+                        break;
+                    }
+                }
+            }
+        }
+    }
+
+    if(ShmSysConfigAndInfo->SysInfo.CabinetSetting.bits.StartAuthorize == true &&
+        ShmSysConfigAndInfo->SysInfo.CabinetSetting.bits.AuthorizingCompleted == false)
+    {
+        unsigned char target = ShmSysConfigAndInfo->SysInfo.CabinetSetting.bits.AuthorizeTargetIndex;
+        unsigned char *AuthorizeStatus;
+
+        switch(ShmSysConfigAndInfo->SysInfo.CabinetSetting.bits.AuthorizeSrc)
+        {
+            case _AuthorizeSrc_Local:
+                AuthorizeStatus = &ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[target].AuthorizeStatus;
+                break;
+            case _AuthorizeSrc_Remote:
+                AuthorizeStatus = &ShmSysConfigAndInfo->SysInfo.ConnectorInfo[target].AuthorizeStatus;
+                break;
+            default:
+                break;
+        }
+
+        if(ShmSysConfigAndInfo->SysInfo.CabinetSetting.bits.AuthorizeSrc != _AuthorizeSrc_None)
+        {
+            switch(*AuthorizeStatus)
+            {
+                case _AuthorizeStatus_Wait:
+                    *AuthorizeStatus = _AuthorizeStatus_Busy;
+                    PRINTF_FUNC("*********** %s id %d Start Authorizing ***********",
+                        str_auth_src[ShmSysConfigAndInfo->SysInfo.CabinetSetting.bits.AuthorizeSrc], target + 1);
+
+                    if(ShmOCPP16Data->OcppConnStatus)
+                    {
+                        PRINTF_FUNC("*********** %s id %d OPCC AuthorizeReq ***********",
+                            str_auth_src[ShmSysConfigAndInfo->SysInfo.CabinetSetting.bits.AuthorizeSrc], target + 1);
+                        OCPPAuthorizingStart();
+                    }
+
+                    // update start authorizing timeout
+                    gettimeofday(&_StartAuthorizing_Time, NULL);
+                    break;
+
+                case _AuthorizeStatus_Busy:
+                    if(GetTimeoutValue(_StartAuthorizing_Time) / uSEC_VAL >= AUTHORIZE_TIMEOUT)
+                    {
+                        PRINTF_FUNC("*********** %s ID %d Authorize Timeout ***********",
+                            str_auth_src[ShmSysConfigAndInfo->SysInfo.CabinetSetting.bits.AuthorizeSrc], target + 1);
+                        *AuthorizeStatus = _AuthorizeStatus_Fail;
+                    }
+                    else
+                    {
+                        if(ShmOCPP16Data->OcppConnStatus)
+                        {
+                            if(ShmOCPP16Data->SpMsg.bits.AuthorizeConf)
+                            {
+                                BOOL accept = false;
+                                if(strcmp((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted") == EQUAL)
+                                {
+                                    accept = true;
+                                }
+
+                                PRINTF_FUNC("*********** %s id %d OCPP Authorize %s ***********",
+                                    str_auth_src[ShmSysConfigAndInfo->SysInfo.CabinetSetting.bits.AuthorizeSrc], target + 1, accept ? "OK" : "NG");
+                                *AuthorizeStatus = accept ? _AuthorizeStatus_Pass : _AuthorizeStatus_Fail;
+                            }
+                        }
+                        else
+                        {
+                            if(ShmSysConfigAndInfo->SysConfig.OfflinePolicy == _OFFLINE_POLICY_NO_CHARGING)
+                            {
+                                PRINTF_FUNC("*********** %s id %d    No Charging    ***********",
+                                    str_auth_src[ShmSysConfigAndInfo->SysInfo.CabinetSetting.bits.AuthorizeSrc], target + 1);
+                                *AuthorizeStatus = _AuthorizeStatus_Fail;
+                            }
+                            else if(ShmSysConfigAndInfo->SysConfig.OfflinePolicy == _OFFLINE_POLICY_FREE_CHARGING)
+                            {
+                                // set authorize pass when offline policy is free charge
+                                PRINTF_FUNC("*********** %s id %d Free Charging OK  ***********",
+                                    str_auth_src[ShmSysConfigAndInfo->SysInfo.CabinetSetting.bits.AuthorizeSrc], target + 1);
+                                *AuthorizeStatus = _AuthorizeStatus_Pass;
+                            }
+                            else if(ShmSysConfigAndInfo->SysConfig.OfflinePolicy == _OFFLINE_POLICY_LOCAL_LIST)
+                            {
+                                BOOL find = false;
+
+                                // check white list
+                                for(int i = 0; i < 10; i++)
+                                {
+                                    if (strcmp((char *)ShmSysConfigAndInfo->SysConfig.LocalWhiteCard[i], "") != EQUAL)
+                                    {
+                                        if (strcmp((char *)ShmSysConfigAndInfo->SysConfig.LocalWhiteCard[i], (char *)ShmSysConfigAndInfo->SysConfig.UserId) == EQUAL)
+                                        {
+                                            find = true;
+                                            break;
+                                        }
+                                    }
+                                }
+
+                                PRINTF_FUNC("*********** %s id %d   White Card %s   ***********",
+                                    str_auth_src[ShmSysConfigAndInfo->SysInfo.CabinetSetting.bits.AuthorizeSrc], target + 1, find ? "OK" : "NG");
+                                *AuthorizeStatus = find ? _AuthorizeStatus_Pass : _AuthorizeStatus_Fail;
+                            }
+                            else
+                            {
+                                PRINTF_FUNC("*********** %s id %d  Invalid Policy   ***********",
+                                    str_auth_src[ShmSysConfigAndInfo->SysInfo.CabinetSetting.bits.AuthorizeSrc], target + 1);
+                                *AuthorizeStatus = _AuthorizeStatus_Fail;
+                            }
+                        }
+                    }
+
+                    if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[target].AuthorizeStatus != _AuthorizeStatus_Busy)
+                    {
+                        // authorize completed
+                        ShmSysConfigAndInfo->SysInfo.CabinetSetting.bits.AuthorizingCompleted = true;
+
+                        if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[target].AuthorizeStatus == _AuthorizeStatus_Pass)
+                        {
+                            SetConnectorAuthorizeOK(target, ShmSysConfigAndInfo->SysInfo.CabinetSetting.bits.AuthorizeSrc);
+                        }
+
+                        switch(ShmSysConfigAndInfo->SysInfo.CabinetSetting.bits.AuthorizeSrc)
+                        {
+                            case _AuthorizeSrc_Local:
+                                // update dispenser authorizing timeout (local start)
+                                gettimeofday(&_DispenserAuthorizing_Time[target], NULL);
+                                break;
+                            case _AuthorizeSrc_Remote:
+                                // update connector authorizing timeout (remote start)
+                                gettimeofday(&_ConnectorAuthorizing_Time[target], NULL);
+                                break;
+                            default:
+                                break;
+                        }
+
+                        // update authorizing completed timeout
+                        gettimeofday(&_StartAuthorizing_Time, NULL);
+
+                        CheckConnectionTimeout();
+                    }
+                    break;
+
+                case _AuthorizeStatus_Pass:
+                case _AuthorizeStatus_Fail:
+                    break;
+
+                default:
+                    ShmSysConfigAndInfo->SysInfo.CabinetSetting.bits.StartAuthorize = false;
+                    ShmSysConfigAndInfo->SysInfo.CabinetSetting.bits.AuthorizingCompleted = false;
+                    break;
+            }
+        }
+        else
+        {
+            PRINTF_FUNC("*********** PowerCabinet Authorize None Src  ***********");
+            // authorize completed
+            ShmSysConfigAndInfo->SysInfo.CabinetSetting.bits.AuthorizingCompleted = true;
+
+            // update authorizing completed timeout
+            gettimeofday(&_StartAuthorizing_Time, NULL);
+        }
+    }
+
+    if(ShmSysConfigAndInfo->SysInfo.CabinetSetting.bits.AuthorizingCompleted)
+    {
+        if(GetTimeoutValue(_StartAuthorizing_Time) / uSEC_VAL >= AUTHORIZE_COMP_TIMEOUT)
+        {
+            PRINTF_FUNC("*********** PowerCabinet Authorize Completed ***********");
+            PowerCabinetAuthorizingSettingInitial();
+        }
+        else
+        {
+            // do nothing
+        }
+    }
+}
+
+BOOL IsConnectorAuthorizeSuccess(unsigned char ConnectorIndex)
+{
+    BOOL success = false;
+
+    if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[ConnectorIndex].Parameter.bits.AuthorizeRequestType != _AuthorizeSrc_None)
+    {
+        success = true;
+    }
+
+    return success;
+}
+
+/*
+bool AddGunInfoByConnector(byte typeValue, byte slots)
+{
+	bool result = true;
+
+	switch (typeValue)
+	{
+		case '0': // none
+			break;
+		case '1': // IEC 62196-2 Type 1/SAE J1772 Plug
+			break;
+		case '2': // IEC 62196-2 Type 1/SAE J1772 Socket
+			break;
+		case '3': // IEC 62196-2 Type 2 Plug
+		case '4': // IEC 62196-2 Type 2 Socket
+			if (AC_QUANTITY > _ac_Index)
+			{
+				ac_chargingInfo[_acgunIndex] = &ShmSysConfigAndInfo->SysInfo.AcChargingData[_ac_Index];
+
+				// AC 固定 index
+				ac_chargingInfo[_acgunIndex]->Index = 0;
+				ac_chargingInfo[_acgunIndex]->ReservationId = -1;
+				ac_chargingInfo[_acgunIndex]->SystemStatus = S_IDLE;
+				ac_chargingInfo[_acgunIndex]->Type = _Type_AC;
+				ac_chargingInfo[_acgunIndex]->IsAvailable = YES;
+				_ac_Index++;
+				_acgunIndex++;
+			}
+			else
+				result = false;
+			break;
+		case '5': // GB/T AC Plug
+			break;
+		case '6': // GB/T AC Socket
+			break;
+		case 'J': // CHAdeMO
+		{
+			if (CHAdeMO_QUANTITY > _chademoIndex)
+			{
+				chargingInfo[_gunIndex] = &ShmSysConfigAndInfo->SysInfo.ChademoChargingData[_chademoIndex];
+				chargingInfo[_gunIndex]->Index = _gunIndex;
+				chargingInfo[_gunIndex]->ReservationId = -1;
+				chargingInfo[_gunIndex]->slotsIndex = slots;
+				chargingInfo[_gunIndex]->SystemStatus = S_BOOTING;
+				chargingInfo[_gunIndex]->Type = _Type_Chademo;
+				chargingInfo[_gunIndex]->type_index = _chademoIndex;
+				chargingInfo[_gunIndex]->IsAvailable = YES;
+				_chademoIndex++;
+				_gunIndex++;
+			}
+			else
+				result = false;
+		}
+			break;
+		case 'U': // CCS1 combo
+		case 'E': // CCS2 combo
+		{
+			if (CCS_QUANTITY > _ccsIndex)
+			{
+				chargingInfo[_gunIndex] = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[_ccsIndex];
+
+				chargingInfo[_gunIndex]->Index = _gunIndex;
+				chargingInfo[_gunIndex]->ReservationId = -1;
+				chargingInfo[_gunIndex]->slotsIndex = slots;
+				chargingInfo[_gunIndex]->SystemStatus = S_BOOTING;
+				chargingInfo[_gunIndex]->Type = _Type_CCS_2;
+				chargingInfo[_gunIndex]->type_index = _ccsIndex;
+				chargingInfo[_gunIndex]->IsAvailable = YES;
+				// 現階段預設為走 DIN70121
+				ShmCcsData->CommProtocol = _CCS_COMM_V2GMessage_DIN70121;
+				_ccsIndex++;
+				_gunIndex++;
+			}
+			else
+				result = false;
+		}
+			break;
+		case 'G': // GBT DC
+		{
+			if (GB_QUANTITY > _gb_Index)
+			{
+				chargingInfo[_gunIndex] = &ShmSysConfigAndInfo->SysInfo.GbChargingData[_gb_Index];
+
+				chargingInfo[_gunIndex]->Index = _gunIndex;
+				chargingInfo[_gunIndex]->ReservationId = -1;
+				chargingInfo[_gunIndex]->slotsIndex = slots;
+				chargingInfo[_gunIndex]->SystemStatus = S_BOOTING;
+				chargingInfo[_gunIndex]->Type = _Type_GB;
+				chargingInfo[_gunIndex]->type_index = _gb_Index;
+				chargingInfo[_gunIndex]->IsAvailable = YES;
+				_gb_Index++;
+				_gunIndex++;
+			}
+			else
+				result = false;
+		}
+			break;
+		case 'D': // GBT DC x 2
+			break;
+	}
+	return result;
+}
+*/
+
+bool CheckConnectorTypeStatus()
+{
+	bool result = true;
+
+//	PRINTF_FUNC("bd0_1_status = %d, bd0_2_status = %d, bd1_1_status = %d, bd1_2_status = %d \n",
+//			bd0_1_status, bd0_2_status, bd1_1_status, bd1_2_status);
+	if (strlen((char *) ShmSysConfigAndInfo->SysConfig.ModelName) >= 9)
+	{
+//		byte slots = 1;
+//		for (byte typeIndex = 7; typeIndex <= 9; typeIndex++)
+//		{
+//			if(!AddGunInfoByConnector(ShmSysConfigAndInfo->SysConfig.ModelName[typeIndex], slots))
+//			{
+//				return false;
+//			}
+
+//			slots++;
+//		}
+
+		// AC index 接在 DC 後面
+//		if (AC_QUANTITY > 0)
+//			ac_chargingInfo[0]->Index += _gunIndex;
+
+		// DO360 for Audi, two gun only
+		_gunIndex = 2;
+		_acgunIndex = 0;
+		ShmSysConfigAndInfo->SysConfig.TotalConnectorCount = _gunIndex;
+		ShmSysConfigAndInfo->SysConfig.AcConnectorCount = _acgunIndex;
+		PRINTF_FUNC("DC _gunCount = %d, AC _gunCount = %d \n",
+				ShmSysConfigAndInfo->SysConfig.TotalConnectorCount,
+				ShmSysConfigAndInfo->SysConfig.AcConnectorCount);
+
+		if (ShmSysConfigAndInfo->SysConfig.TotalConnectorCount == 0 &&
+				ShmSysConfigAndInfo->SysConfig.AcConnectorCount == 0)
+			result = false;
+
+		//DO360 charging info default setting
+		for(int i = 0; i < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; i++)
+		{
+			chargingInfo[i] = &ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].GeneralChargingData;
+			chargingInfo[i]->Index = i;
+			chargingInfo[i]->Evboard_id = 0x00;
+			chargingInfo[i]->ReservationId = -1;
+			chargingInfo[i]->slotsIndex = 0;
+			chargingInfo[i]->SystemStatus = S_BOOTING;
+			chargingInfo[i]->Type = _Type_Unknown;
+			chargingInfo[i]->type_index = 0;
+			chargingInfo[i]->IsAvailable = YES;
+		}
+/*
+		if (ShmSysConfigAndInfo->SysConfig.TotalConnectorCount == 1)
+		{
+			chargingInfo[0]->Evboard_id = 0x01;
+			PRINTF_FUNC("index = %d, Type = %d, Evboard_id = %d \n", 0, chargingInfo[0]->Type, chargingInfo[0]->Evboard_id);
+		}
+		else
+		{
+			// 偵測槍屬於哪個 slot : 可知道插在板上的Slot 0 或 1 是 Chademo 還是 CCS
+			for (byte gunIndex = 0; gunIndex < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gunIndex++)
+			{
+				if (gunIndex == 0 && bd0_1_status == 0 && bd0_2_status == 1)
+				{
+					// 與硬體相同 type : Chademo
+					if (chargingInfo[gunIndex]->Type == _Type_Chademo)
+					{
+						chargingInfo[gunIndex]->Evboard_id = 0x01;
+					}
+				}
+				else if (gunIndex == 0 && bd0_1_status == 1 && bd0_2_status == 0)
+				{
+					// 與硬體相同 type : CCS
+					if (chargingInfo[gunIndex]->Type == _Type_CCS_2)
+					{
+						chargingInfo[gunIndex]->Evboard_id = 0x01;
+					}
+				}
+				else if (gunIndex == 0 && bd0_1_status == 1 && bd0_2_status == 1)
+				{
+					// 與硬體相同 type : GB
+					if (chargingInfo[gunIndex]->Type == _Type_GB)
+					{
+						chargingInfo[gunIndex]->Evboard_id = 0x01;
+					}
+				}
+
+				if (gunIndex == 1 && bd1_1_status == 0 && bd1_2_status == 1)
+				{
+					// 與硬體相同 type : Chademo
+					if (chargingInfo[gunIndex]->Type == _Type_Chademo)
+					{
+						chargingInfo[gunIndex]->Evboard_id = 0x02;
+					}
+
+					if (ShmSysConfigAndInfo->SysConfig.TotalConnectorCount == 1)
+						chargingInfo[gunIndex]->Evboard_id = 0x01;
+				}
+				else if (gunIndex == 1 && bd1_1_status == 1 && bd1_2_status == 0)
+				{
+					// 與硬體相同 type : CCS
+					if (chargingInfo[gunIndex]->Type == _Type_CCS_2)
+					{
+						chargingInfo[gunIndex]->Evboard_id = 0x02;
+					}
+
+					if (ShmSysConfigAndInfo->SysConfig.TotalConnectorCount == 1)
+						chargingInfo[gunIndex]->Evboard_id = 0x01;
+				}
+				else if (gunIndex == 1 && bd1_1_status == 1 && bd1_2_status == 1)
+				{
+					// 與硬體相同 type : GB
+					if (chargingInfo[gunIndex]->Type == _Type_GB)
+					{
+						chargingInfo[gunIndex]->Evboard_id = 0x02;
+					}
+
+					if (ShmSysConfigAndInfo->SysConfig.TotalConnectorCount == 1)
+						chargingInfo[gunIndex]->Evboard_id = 0x01;
+				}
+
+				PRINTF_FUNC("index = %d, Type = %d, Evboard_id = %d \n", gunIndex, chargingInfo[gunIndex]->Type, chargingInfo[gunIndex]->Evboard_id);
+				if (chargingInfo[gunIndex]->Evboard_id == 0x00)
+					result = false;
+			}
+		}
+*/
+	}
+	else
+	{
+		// Module Name 不正確 - 告警
+		result = false;
+	}
+
+	return result;
+}
+
+void KillTask()
+{
+	ChangeLcmByIndex(_LCM_FIX);
+	system("killall Module_EventLogging");
+	system("killall Module_PrimaryComm");
+	system("killall Module_EvComm");
+	system("killall Module_LcmControl");
+	system("killall Module_InternalComm");
+	system("killall Module_PsuComm");
+	system("killall OcppBackend &");
+	system("killall Module_4g &");
+	system("killall Module_Wifi &");
+}
+
+char CheckUpdateProcess()
+{
+	DIR *d;
+	struct dirent *dir;
+	d = opendir("/mnt/");
+
+	if (d)
+	{
+		long int MaxLen=48*1024*1024, ImageLen = 0;
+		while ((dir = readdir(d)) != NULL)
+		{
+			char *new_str;
+			new_str = malloc(strlen("/mnt/")+strlen(dir->d_name)+1);
+			new_str[0] = '\0';
+			strcat(new_str, "/mnt/");
+			strcat(new_str, dir->d_name);
+			int fd = open(new_str, O_RDONLY);
+			if (fd < 0)
+			{
+				return FAIL;
+			}
+
+			unsigned char *ptr = malloc(MaxLen); //-48 is take out the header
+			memset(ptr, 0xFF, MaxLen);  //-48 is take out the header
+			//get the image length
+			ImageLen = read(fd, ptr, MaxLen);
+
+			if (ImageLen > 20)
+			{
+				unsigned int Type = (((unsigned int)ptr[16])<<24 | ((unsigned int)ptr[17])<<16 | ((unsigned int)ptr[18])<<8 | ((unsigned int)ptr[19]));
+			    PRINTF_FUNC("Typed...%x \r\n", Type);
+
+			    switch (Type)
+			    {
+			    	case 0x10000001:
+			    	case 0x10000002:
+			    	case 0x10000003:
+			    	case 0x10000004:
+			    	case 0x10000005:
+			    	{
+			    		if (Upgrade_Flash(Type, new_str, (char *)ShmSysConfigAndInfo->SysConfig.ModelName) == PASS)
+			    			return PASS;
+			    		else
+			    			return FAIL;
+			    	}
+			    	break;
+					case 0x10000007:
+					case 0x10000008:
+					case 0x10000009:
+					case 0x1000000A:
+					{
+						bool isPass = true;
+						int CanFd = InitCanBus();
+
+						if (CanFd > 0)
+						{
+							for(byte index = 0; index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; index++)
+							{
+								if (!isPass)
+						        break;
+
+						        if (chargingInfo[index]->Type == _Type_CCS_2)
+						        {
+						        	if (Upgrade_CCS(CanFd, Type, chargingInfo[index]->Evboard_id, new_str, (char *)ShmSysConfigAndInfo->SysConfig.ModelName) == FAIL)
+						            {
+						            	isPass = false;
+						            }
+						        }
+						    }
+						}
+						else
+						{
+						    printf("Upgrade CCS open CAN FD fail.\n");
+						    isPass = false;
+						}
+
+						return isPass;
+					}
+						break;
+			    	case 0x10000006:
+			    	case 0x1000000D:
+			    	case 0x1000000E:
+			    	case 0x20000002:
+			    	case 0x10000014:
+			    	{
+			    		// CSU_PRIMARY_CONTROLLER : 0x10000006
+			    		byte target = 0x00;
+
+			    		if (Type == 0x10000006)
+			    			target = UPGRADE_PRI;
+			    		else if (Type == 0x1000000D)
+			    			target = UPGRADE_RB;
+			    		else if (Type == 0x1000000E)
+			    			target = UPGRADE_FAN;
+			    		else if (Type == 0x20000002)
+			    			target = UPGRADE_AC;
+			    		else if (Type == 0x10000014)
+			    			target = UPGRADE_LED;
+
+			    		int fd = InitComPort(target);
+
+			    		if (Upgrade_UART(fd, Type, target, new_str, (char *)ShmSysConfigAndInfo->SysConfig.ModelName) == PASS)
+			    			return PASS;
+			    		else
+			    			return FAIL;
+
+			    		close(fd);
+			    	}
+			    	break;
+			    	case 0x1000000B:
+			    	case 0x1000000C:
+			    	{
+			    		// CHAdeMO_BOARD : 0x1000000B, GBT : 0x1000000C
+			    		bool isPass = true;
+			    		int CanFd = InitCanBus();
+
+			    		if (CanFd > 0)
+			    		{
+			    			for(byte index = 0; index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; index++)
+			    			{
+			    				if (!isPass)
+			    					break;
+
+			    				if ((Type == 0x1000000B && chargingInfo[index]->Type == _Type_Chademo) ||
+			    						(Type == 0x1000000C && chargingInfo[index]->Type == _Type_GB))
+			    				{
+			    					if (Upgrade_CAN(CanFd, Type, chargingInfo[index]->Evboard_id, new_str, (char *)ShmSysConfigAndInfo->SysConfig.ModelName) == PASS)
+			    						return PASS;
+			    					else
+			    						return FAIL;
+			    				}
+			    			}
+			    		}
+			    		else
+			    		{
+			    			PRINTF_FUNC("Upgrad FD fail. \n");
+			    			isPass = false;
+			    		}
+
+			    		return isPass;
+			    		break;
+			    	}
+			    }
+			}
+			free(new_str);
+			free(ptr);
+		}
+	}
+	free(dir);
+	closedir(d);
+	return FAIL;
+}
+
+/*
+void CreateRfidFork()
+{
+	pid_t rfidRecPid;
+
+	rfidRecPid = fork();
+	if (rfidRecPid == 0)
+	{
+		while(true)
+		{
+			// 刷卡判斷
+			RFID rfid;
+			if (ShmSysConfigAndInfo->SysConfig.OfflinePolicy == _OFFLINE_POLICY_NO_CHARGING ||
+					!ShmSysConfigAndInfo->SysConfig.isRFID)
+			{}
+			else if(getRequestCardSN(rfidFd, 0, &rfid))
+			{
+				PRINTF_FUNC("Get Card..-%s- \n", ShmSysConfigAndInfo->SysConfig.UserId);
+				if (strlen((char *)ShmSysConfigAndInfo->SysConfig.UserId) == 0)
+				{
+					if (ShmSysConfigAndInfo->SysConfig.RfidCardNumEndian == RFID_ENDIAN_LITTLE)
+					{
+						switch (rfid.snType)
+						{
+						case RFID_SN_TYPE_6BYTE:
+							sprintf((char *) ShmSysConfigAndInfo->SysConfig.UserId,
+									"%02X%02X%02X%02X%02X%02X",
+									rfid.currentCard[0], rfid.currentCard[1],
+									rfid.currentCard[2], rfid.currentCard[3],
+									rfid.currentCard[4], rfid.currentCard[5]);
+							break;
+						case RFID_SN_TYPE_7BYTE:
+							sprintf((char *) ShmSysConfigAndInfo->SysConfig.UserId,
+									"%02X%02X%02X%02X%02X%02X%02X",
+									rfid.currentCard[0], rfid.currentCard[1],
+									rfid.currentCard[2], rfid.currentCard[3],
+									rfid.currentCard[4], rfid.currentCard[5],
+									rfid.currentCard[6]);
+							break;
+						case RFID_SN_TYPE_10BYTE:
+							sprintf((char *) ShmSysConfigAndInfo->SysConfig.UserId,
+									"%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X",
+									rfid.currentCard[0], rfid.currentCard[1],
+									rfid.currentCard[2], rfid.currentCard[3],
+									rfid.currentCard[4], rfid.currentCard[5],
+									rfid.currentCard[6], rfid.currentCard[7],
+									rfid.currentCard[8], rfid.currentCard[9]);
+							break;
+						case RFID_SN_TYPE_4BYTE:
+							sprintf((char *) ShmSysConfigAndInfo->SysConfig.UserId,
+									"%02X%02X%02X%02X",
+									rfid.currentCard[0], rfid.currentCard[1],
+									rfid.currentCard[2], rfid.currentCard[3]);
+							break;
+						}
+					}
+					else if (ShmSysConfigAndInfo->SysConfig.RfidCardNumEndian == RFID_ENDIAN_BIG)
+					{
+						switch (rfid.snType)
+						{
+						case RFID_SN_TYPE_6BYTE:
+							sprintf((char *) ShmSysConfigAndInfo->SysConfig.UserId,
+									"%02X%02X%02X%02X%02X%02X",
+									rfid.currentCard[5], rfid.currentCard[4],
+									rfid.currentCard[3], rfid.currentCard[2],
+									rfid.currentCard[1], rfid.currentCard[0]);
+							break;
+						case RFID_SN_TYPE_7BYTE:
+							sprintf((char *) ShmSysConfigAndInfo->SysConfig.UserId,
+									"%02X%02X%02X%02X%02X%02X%02X",
+									rfid.currentCard[6], rfid.currentCard[5],
+									rfid.currentCard[4], rfid.currentCard[3],
+									rfid.currentCard[2], rfid.currentCard[1],
+									rfid.currentCard[0]);
+							break;
+						case RFID_SN_TYPE_10BYTE:
+							sprintf((char *) ShmSysConfigAndInfo->SysConfig.UserId,
+									"%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X",
+									rfid.currentCard[9], rfid.currentCard[8],
+									rfid.currentCard[7], rfid.currentCard[6],
+									rfid.currentCard[5], rfid.currentCard[4],
+									rfid.currentCard[3], rfid.currentCard[2],
+									rfid.currentCard[1], rfid.currentCard[0]);
+							break;
+						case RFID_SN_TYPE_4BYTE:
+							sprintf((char *) ShmSysConfigAndInfo->SysConfig.UserId,
+									"%02X%02X%02X%02X",
+									rfid.currentCard[3], rfid.currentCard[2],
+									rfid.currentCard[1], rfid.currentCard[0]);
+							break;
+						}
+					}
+
+					PRINTF_FUNC("card number = %s\n", ShmSysConfigAndInfo->SysConfig.UserId);
+				}
+			}
+			sleep(1);
+		}
+	}
+}
+*/
+
+void StartSystemTimeoutDet(unsigned char flag)
+{
+	if (ShmSysConfigAndInfo->SysInfo.SystemTimeoutFlag != flag)
+	{
+		gettimeofday(&ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer, NULL);
+	}
+	ShmSysConfigAndInfo->SysInfo.SystemTimeoutFlag = flag;
+}
+
+void StopSystemTimeoutDet()
+{
+	gettimeofday(&ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer, NULL);
+	ShmSysConfigAndInfo->SysInfo.SystemTimeoutFlag = Timeout_None;
+}
+
+void StartGunInfoTimeoutDet(unsigned char gunIndex, unsigned char flag)
+{
+	if (gunIndex < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount)
+	{
+		if (chargingInfo[gunIndex]->TimeoutFlag != flag)
+		{
+			gettimeofday(&chargingInfo[gunIndex]->TimeoutTimer, NULL);
+		}
+		chargingInfo[gunIndex]->TimeoutFlag = flag;
+	}
+}
+
+void StopGunInfoTimeoutDet(unsigned char gunIndex)
+{
+	if (gunIndex < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount)
+	{
+		chargingInfo[gunIndex]->TimeoutFlag = Timeout_None;
+	}
+}
+
+void CheckConnectionTimeout(void)
+{
+	if(system("pidof -s OcppBackend > /dev/null") != 0)
+	{
+		_connectionTimeout = CONN_PLUG_TIME_OUT;
+	}
+	else
+	{
+		if(strcmp((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData,"") != 0)
+		{
+			_connectionTimeout = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
+			if(_connectionTimeout <= 0)
+			{
+				_connectionTimeout = CONN_PLUG_TIME_OUT;
+			}
+		}
+		else
+		{
+			_connectionTimeout = CONN_PLUG_TIME_OUT;
+		}
+	}
+}
+
+void CreateTimeoutFork()
+{
+	pid_t timeoutPid;
+
+	timeoutPid = fork();
+	if (timeoutPid > 0)
+	{
+		gettimeofday(&_cmdSubPriority_time, NULL);
+		CheckConnectionTimeout();
+
+		while(true)
+		{
+			if ((GetTimeoutValue(_cmdSubPriority_time) / 1000) > 5000)
+			{
+				CheckConnectionTimeout();
+				gettimeofday(&_cmdSubPriority_time, NULL);
+			}
+
+			//printf("Timeout ***********SystemTimeoutFlag = %d, ********\n", ShmSysConfigAndInfo->SysInfo.SystemTimeoutFlag);
+			// 系統
+			switch(ShmSysConfigAndInfo->SysInfo.SystemTimeoutFlag)
+			{
+//				case Timeout_SelftestChk:
+//					if (GetTimeoutValue(ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer) / uSEC_VAL >= SELFTEST_TIMEOUT)
+//					{
+//						_SelfTestTimeout();
+//						StopSystemTimeoutDet();
+//					}
+//					break;
+//				case Timeout_Authorizing:
+//					if (GetTimeoutValue(ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer) / uSEC_VAL >= AUTHORIZE_TIMEOUT)
+//					{
+//						_AuthorizedTimeout();
+//						StopSystemTimeoutDet();
+//					}
+//					break;
+//				case Timeout_VerifyFail:
+//					if (GetTimeoutValue(ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer) / uSEC_VAL >= AUTHORIZE_FAIL_TIMEOUT)
+//					{
+//						_AutoReturnTimeout();
+//						StopSystemTimeoutDet();
+//					}
+//					break;
+//				case Timeout_VerifyComp:
+//					if (GetTimeoutValue(ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer) / uSEC_VAL >= AUTHORIZE_COMP_TIMEOUT)
+//					{
+//						_AutoReturnTimeout();
+//						StopSystemTimeoutDet();
+//					}
+//					break;
+				case Timeout_WaitPlug:
+					if (GetTimeoutValue(ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer) / uSEC_VAL >= _connectionTimeout)
+					{
+						_DetectPlugInTimeout();
+						StopSystemTimeoutDet();
+					}
+					break;
+				case Timeout_ReturnToChargingGunDet:
+				{
+					if (GetTimeoutValue(ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer) / uSEC_VAL >= RETURN_TO_CHARGING_PAGE)
+					{
+						DisplayChargingInfo();
+						StopSystemTimeoutDet();
+					}
+				}
+					break;
+				case Timeout_AuthorizingForStop:
+				{
+					if (GetTimeoutValue(ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer) / uSEC_VAL >= AUTHORIZE_STOP_TIMEOUT)
+					{
+						strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
+						ClearAuthorizedFlag();
+						StopSystemTimeoutDet();
+					}
+				}
+					break;
+			}
+			// 各槍
+			for (byte gun_index = 0; gun_index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gun_index++)
+			{
+				//printf("Timeout ***********TimeoutFlag = %d, ********\n", chargingInfo[gun_index]->TimeoutFlag);
+				switch(chargingInfo[gun_index]->TimeoutFlag)
+				{
+					case Timeout_Preparing:
+					{
+						if (GetTimeoutValue(chargingInfo[gun_index]->TimeoutTimer) / uSEC_VAL >= GUN_PREPARE_TIMEOUT)
+						{
+							_PrepareTimeout(gun_index);
+							StopGunInfoTimeoutDet(gun_index);
+						}
+					}
+						break;
+					case Timeout_EvChargingDet:
+					{
+						if (GetTimeoutValue(chargingInfo[gun_index]->TimeoutTimer) / uSEC_VAL >= GUN_EV_WAIT_TIMEOUT)
+						{
+							_DetectEvChargingEnableTimeout(gun_index);
+							StopGunInfoTimeoutDet(gun_index);
+						}
+					}
+						break;
+					case Timeout_EvseChargingDet:
+					{
+						if (GetTimeoutValue(chargingInfo[gun_index]->TimeoutTimer) / uSEC_VAL >= GUN_EVSE_WAIT_TIMEOUT)
+						{
+							_DetectEvseChargingEnableTimeout(gun_index);
+							StopGunInfoTimeoutDet(gun_index);
+						}
+					}
+						break;
+					case Timeout_EvseCompleteDet:
+					{
+						if (GetTimeoutValue(chargingInfo[gun_index]->TimeoutTimer) / uSEC_VAL >= GUN_COMP_WAIT_TIMEOUT)
+						{
+							StopGunInfoTimeoutDet(gun_index);
+						}
+					}
+						break;
+					case Timeout_ForCcsPrechargeDet:
+					{
+						if (GetTimeoutValue(chargingInfo[gun_index]->TimeoutTimer) / uSEC_VAL >= GUN_PRECHARGING_TIMEOUT)
+						{
+							_CcsPrechargeTimeout(gun_index);
+							StopGunInfoTimeoutDet(gun_index);
+						}
+					}
+						break;
+				}
+			}
+			sleep(1);
+		}
+	}
+}
+
+void GetSystemTime()
+{
+	struct timeb csuTime;
+	struct tm *tmCSU;
+
+	ftime(&csuTime);
+	tmCSU = localtime(&csuTime.time);
+	PRINTF_FUNC("Time : %04d-%02d-%02d %02d:%02d:%02d \n", tmCSU->tm_year + 1900,
+			tmCSU->tm_mon + 1, tmCSU->tm_mday, tmCSU->tm_hour, tmCSU->tm_min,
+			tmCSU->tm_sec);
+
+//	byte date[14];
+//
+//
+//		 //sprintf(&date, "%d", );
+//
+//		 date[0] = '0' + ((tmCSU->tm_year + 1900) / 1000 % 10);
+
+//	date[0] = (tmCSU->tm_year + 1900) / 1000 % 10;
+//	date[1] = (tmCSU->tm_year + 1900) / 100 % 10;
+//	date[2] = (tmCSU->tm_year + 1900) / 10 % 10;
+//	date[3] = (tmCSU->tm_year + 1900) / 1 % 10;
+//
+//	date[4] = (tmCSU->tm_mon + 1) / 10 % 10;
+//	date[5] = (tmCSU->tm_mon + 1) / 1 % 10;
+//
+//	date[6] = (tmCSU->tm_mday) / 10 % 10;
+//	date[7] = (tmCSU->tm_mday) / 1 % 10;
+//
+//	date[8] = (tmCSU->tm_hour) / 10 % 10;
+//	date[9] = (tmCSU->tm_hour) / 1 % 10;
+//
+//	date[10] = (tmCSU->tm_min) / 10 % 10;
+//	date[11] = (tmCSU->tm_min) / 1 % 10;
+//
+//	date[12] = (tmCSU->tm_sec) / 10 % 10;
+//	date[13] = (tmCSU->tm_sec) / 1 % 10;
+
+//	PRINTF_FUNC("%x, %x, %x, %x, %x, %x, %x, %x, %x, %x, %x, %x, %x, %x \n", date[0], date[1], date[2], date[3],
+//			date[4], date[5], date[6], date[7],
+//			date[8], date[9], date[10], date[11],
+//			date[12], date[13]);
+}
+
+void CheckFactoryConfigFunction()
+{
+	if(ShmSysConfigAndInfo->SysInfo.FactoryConfiguration)
+	{
+		system("cd /root;./FactoryConfig -m");
+		system("sync");
+		sleep(5);
+		system("reboot -f");
+		sleep(5);
+		system("reboot -f");
+	}
+}
+
+void CheckFwUpdateFunction()
+{
+	//PRINTF_FUNC("ShmSysConfigAndInfo->SysInfo.FirmwareUpdate = %d \n", ShmSysConfigAndInfo->SysInfo.FirmwareUpdate);
+	if (ShmSysConfigAndInfo->SysInfo.FirmwareUpdate == YES)
+	{
+		DEBUG_INFO_MSG("ftp : update start. \n");
+		KillTask();
+		if (CheckUpdateProcess() == PASS)
+			DEBUG_INFO_MSG("ftp : update complete. \n");
+		else
+			DEBUG_INFO_MSG("ftp : update fail. \n");
+
+		ShmSysConfigAndInfo->SysInfo.FirmwareUpdate = NO;
+		sleep(5);
+		system("reboot -f");
+	}
+	else if(ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq == YES)
+	{
+		ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = NO;
+
+		if (strcmp((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "Downloaded") == EQUAL)
+		{
+			DEBUG_INFO_MSG("Backend : update start. \n");
+			strcpy((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "");
+			strcpy((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "Installing");
+			ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = YES;
+			KillTask();
+
+			for (byte _index = 0; _index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _index++)
+			{
+				setChargerMode(_index, MODE_UPDATE);
+			}
+			for (byte _index = 0; _index < ShmSysConfigAndInfo->SysConfig.AcConnectorCount; _index++)
+			{
+				ac_chargingInfo[_index]->SystemStatus = MODE_UPDATE;
+			}
+
+			if (CheckUpdateProcess() == PASS)
+			{
+				DEBUG_INFO_MSG("Backend : update complete. \n");
+				strcpy((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "Installed");
+			}
+			else
+			{
+				DEBUG_INFO_MSG("Backend : update fail. \n");
+				strcpy((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "InstallationFailed");
+			}
+
+			strcpy((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "Installed");
+			ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = YES;
+			sleep(5);
+			system("reboot -f");
+		}
+	}
+}
+
+//===============================================
+// Check reservation date is expired
+//===============================================
+int isReservationExpired(unsigned char gun_index)
+{
+	int result = NO;
+	struct tm expiredDate;
+	struct timeb expiredTime;
+
+	if (sscanf((char*) ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,
+			"%4d-%2d-%2dT%2d:%2d:%2d", &expiredDate.tm_year,
+			&expiredDate.tm_mon, &expiredDate.tm_mday, &expiredDate.tm_hour,
+			&expiredDate.tm_min, &expiredDate.tm_sec) == 6)
+	{
+		expiredDate.tm_year -= 1900;
+		expiredDate.tm_mon -= 1;
+
+		expiredTime.time = mktime(&expiredDate);
+		if (!CheckTimeOut(expiredTime))
+		{
+			result = YES;
+		}
+	}
+
+	return result;
+}
+
+//===============================================
+// OCPP
+//===============================================
+void CheckOcppStatus()
+{
+	if (ShmOCPP16Data->SpMsg.bits.BootNotificationConf == YES)
+	{
+		ShmOCPP16Data->SpMsg.bits.BootNotificationConf = NO;
+		PRINTF_FUNC("*********************OCPP Boot Notification****************************\n");
+	}
+
+	if (ShmOCPP16Data->MsMsg.bits.ResetReq == YES)
+	{
+		bool canReset = true;
+		if (ShmSysConfigAndInfo->SysWarningInfo.Level != 2)
+		{
+			for (byte _index = 0; _index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _index++)
+			{
+				if (chargingInfo[_index]->SystemStatus != S_IDLE &&
+						chargingInfo[_index]->SystemStatus != S_RESERVATION &&
+						chargingInfo[_index]->SystemStatus != S_MAINTAIN)
+				{
+					canReset = false;
+					if (chargingInfo[_index]->SystemStatus >= S_REASSIGN && chargingInfo[_index]->SystemStatus < S_TERMINATING)
+					{
+						ChargingTerminalProcess(_index);
+					}
+				}
+			}
+		}
+
+		if (canReset)
+		{
+			ShmOCPP16Data->MsMsg.bits.ResetReq = NO;
+			sprintf((char*)ShmOCPP16Data->Reset.ResponseStatus, "Accepted");
+			if(strcmp((char *)ShmOCPP16Data->Reset.Type, "Hard") == EQUAL)
+			{
+				DEBUG_ERROR_MSG("****** Hard Reboot ****** \n");
+				ShmOCPP16Data->MsMsg.bits.ResetConf = YES;
+				sleep(3);
+				system("reboot -f");
+			}
+			else if (strcmp((char *)ShmOCPP16Data->Reset.Type, "Soft") == EQUAL)
+			{
+				DEBUG_ERROR_MSG("****** Soft Reboot ****** \n");
+				ShmOCPP16Data->MsMsg.bits.ResetConf = YES;
+				sleep(3);
+				system("killall OcppBackend &");
+				KillTask();
+				system("/usr/bin/run_evse_restart.sh");
+			}
+		}
+	}
+}
+
+void OcppStartTransation(byte gunIndex)
+{
+	byte _OcppGunIndex = gunIndex;
+
+	// 如果有 AC 槍,而現在是 DC 第二把槍進入充電
+	if (ShmSysConfigAndInfo->SysConfig.AcConnectorCount == 1 && gunIndex == 1)
+		_OcppGunIndex = 2;
+
+	if(strcmp((char *)chargingInfo[gunIndex]->StartUserId, "") == EQUAL)
+		strcpy((char *)ShmOCPP16Data->StartTransaction[_OcppGunIndex].IdTag, (char *)ShmOCPP16Data->StartTransaction[_OcppGunIndex].IdTag);
+	else
+		strcpy((char *)ShmOCPP16Data->StartTransaction[_OcppGunIndex].IdTag, (char *)chargingInfo[gunIndex]->StartUserId);
+
+	PRINTF_FUNC("IdTag = %s \n", ShmOCPP16Data->StartTransaction[_OcppGunIndex].IdTag);
+	ShmOCPP16Data->CpMsg.bits[_OcppGunIndex].StartTransactionReq = YES;
+}
+
+void OcppStopTransation(byte gunIndex)
+{
+	byte _OcppGunIndex = gunIndex;
+
+	// 如果有 AC 槍,而現在是 DC 第二把槍進入充電
+	if (ShmSysConfigAndInfo->SysConfig.AcConnectorCount == 1 && gunIndex == 1)
+		_OcppGunIndex = 2;
+
+	if(strcmp((char *)chargingInfo[gunIndex]->StartUserId, "") == EQUAL)
+		strcpy((char *)ShmOCPP16Data->StopTransaction[_OcppGunIndex].IdTag, (char *)ShmOCPP16Data->StopTransaction[_OcppGunIndex].IdTag);
+	else
+		strcpy((char *)ShmOCPP16Data->StopTransaction[_OcppGunIndex].IdTag, (char *)chargingInfo[gunIndex]->StartUserId);
+
+	PRINTF_FUNC("IdTag = %s \n", ShmOCPP16Data->StopTransaction[_OcppGunIndex].IdTag);
+	ShmOCPP16Data->CpMsg.bits[_OcppGunIndex].StopTransactionReq = YES;
+}
+
+bool OcppRemoteStop(byte gunIndex)
+{
+	byte acDirIndex = ShmSysConfigAndInfo->SysConfig.AcConnectorCount;
+
+	// 有 AC 槍的話
+	if (acDirIndex > 0 && gunIndex > 0)
+	{
+		gunIndex += acDirIndex;
+	}
+
+	bool result = ShmOCPP16Data->CsMsg.bits[gunIndex].RemoteStopTransactionReq;
+
+	if (ShmOCPP16Data->CsMsg.bits[gunIndex].RemoteStopTransactionReq == YES)
+	{
+		strcpy((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "Remote");
+		ShmOCPP16Data->CsMsg.bits[gunIndex].RemoteStopTransactionReq = NO;
+	}
+
+	return result;
+}
+
+void OcppRemoteStartChk()
+{
+	if (ShmSysConfigAndInfo->SysConfig.OfflinePolicy == _OFFLINE_POLICY_NO_CHARGING)
+	{}
+	else if(!isDetectPlugin())
+	{
+		// 如果有 AC 槍,則固定是第 2 把槍,所以索引固定為 1
+		byte acDirIndex = ShmSysConfigAndInfo->SysConfig.AcConnectorCount;
+
+		for (byte ac_index = 0; ac_index < ShmSysConfigAndInfo->SysConfig.AcConnectorCount; ac_index++)
+		{
+			if (ShmOCPP16Data->CsMsg.bits[acDirIndex].RemoteStartTransactionReq == YES)
+			{
+				if (ac_chargingInfo[ac_index]->SystemStatus == S_IDLE ||
+						ac_chargingInfo[ac_index]->SystemStatus == S_RESERVATION)
+				{
+					ShmOCPP16Data->CsMsg.bits[acDirIndex].RemoteStartTransactionReq = NO;
+					ac_chargingInfo[ac_index]->RemoteStartFlag = YES;
+					ShmSysConfigAndInfo->SysInfo.OrderCharging = YES;
+					//ShmSysConfigAndInfo->SysInfo.OrderCharging = DEFAULT_AC_INDEX;
+					ShmOCPP16Data->CsMsg.bits[ShmSysConfigAndInfo->SysConfig.TotalConnectorCount + ac_index].RemoteStartTransactionReq = NO;
+					DetectPluginStart();
+					return;
+				}
+				ShmOCPP16Data->CsMsg.bits[acDirIndex].RemoteStartTransactionReq = NO;
+			}
+		}
+
+		byte threeGunIndex = 0;
+		byte dcIndex = 0;
+		bool isGunUsingStatus = false;
+
+		for (byte _index = 0; _index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _index++)
+		{
+			// 如果有 AC 槍,且 DC 槍也有兩把
+			if (acDirIndex == 1 && _index == 1)
+				threeGunIndex = 1;
+
+			if (ShmOCPP16Data->CsMsg.bits[_index + threeGunIndex].RemoteStartTransactionReq == YES)
+				dcIndex = _index;
+
+			if (chargingInfo[_index]->SystemStatus != S_IDLE)
+			{
+				isGunUsingStatus = true;
+			}
+		}
+
+		// 如果是雙槍單模,只認閒置狀態的槍,如果有預約~ 則預約也算被使用
+		if (isGunUsingStatus && ShmSysConfigAndInfo->SysInfo.IsAlternatvieConf)
+		{
+			if (dcIndex == 0)
+				threeGunIndex = 0;
+
+			ShmOCPP16Data->CsMsg.bits[dcIndex + threeGunIndex].RemoteStartTransactionReq = NO;
+			return;
+		}
+
+		if (dcIndex == 0)
+			threeGunIndex = 0;
+
+		if (ShmOCPP16Data->CsMsg.bits[dcIndex + threeGunIndex].RemoteStartTransactionReq == YES)
+		{
+			if (chargingInfo[dcIndex]->SystemStatus == S_IDLE ||
+					chargingInfo[dcIndex]->SystemStatus == S_RESERVATION)
+			{
+				chargingInfo[dcIndex]->RemoteStartFlag = YES;
+				ShmSysConfigAndInfo->SysInfo.OrderCharging = YES;
+				//ShmSysConfigAndInfo->SysInfo.OrderCharging = gun_index;
+				ShmOCPP16Data->CsMsg.bits[dcIndex + threeGunIndex].RemoteStartTransactionReq = NO;
+				DetectPluginStart();
+			}
+			ShmOCPP16Data->CsMsg.bits[dcIndex + threeGunIndex].RemoteStartTransactionReq = NO;
+		}
+	}
+}
+
+void ChkOcppStatus(byte gunIndex)
+{
+	if (chargingInfo[gunIndex]->SystemStatus == S_IDLE &&
+			ShmOCPP16Data->CsMsg.bits[gunIndex].ReserveNowReq == YES)
+	{
+		ShmOCPP16Data->CsMsg.bits[gunIndex].ReserveNowReq = NO;
+		if (isReservationExpired(gunIndex))
+		{
+			PRINTF_FUNC("***************ChkOcppStatus : OcppReservedStatus******************** \n");
+			DEBUG_ERROR_MSG("***************ChkOcppStatus : OcppReservedStatus******************** \n");
+			chargingInfo[gunIndex]->ReservationId = ShmOCPP16Data->ReserveNow[gunIndex].ReservationId;
+			chargingInfo[gunIndex]->SystemStatus = S_RESERVATION;
+		}
+		ShmOCPP16Data->CsMsg.bits[gunIndex].ReserveNowConf = YES;
+	}
+
+	if (chargingInfo[gunIndex]->SystemStatus == S_RESERVATION &&
+			ShmOCPP16Data->CsMsg.bits[gunIndex].CancelReservationReq == YES)
+	{
+		ShmOCPP16Data->CsMsg.bits[gunIndex].CancelReservationReq = NO;
+		if (isReservationExpired(gunIndex))
+		{
+			PRINTF_FUNC("***************ChkOcppStatus : Cancel OcppReservedStatus******************** \n");
+			DEBUG_ERROR_MSG("***************ChkOcppStatus : Cancel OcppReservedStatus******************** \n");
+			chargingInfo[gunIndex]->ReservationId = 0;
+			chargingInfo[gunIndex]->SystemStatus = S_IDLE;
+		}
+		ShmOCPP16Data->CsMsg.bits[gunIndex].CancelReservationConf = YES;
+	}
+
+	if (ShmOCPP16Data->CsMsg.bits[gunIndex].ChangeAvailabilityReq == YES)
+	{
+		PRINTF_FUNC("***************ChkOcppStatus : OcppChangeAvailability******************** \n");
+		DEBUG_ERROR_MSG("***************ChkOcppStatus : OcppChangeAvailability******************** \n");
+		ShmOCPP16Data->CsMsg.bits[gunIndex].ChangeAvailabilityReq = NO;
+		if(strcmp((char *)ShmOCPP16Data->ChangeAvailability[gunIndex].Type, "Operative") == EQUAL)
+		{
+			if (chargingInfo[gunIndex]->SystemStatus == S_IDLE ||
+				chargingInfo[gunIndex]->SystemStatus == S_RESERVATION ||
+				chargingInfo[gunIndex]->SystemStatus == S_MAINTAIN)
+			{
+	            if (isDb_ready)
+	                DB_Update_Operactive(localDb, gunIndex, true);
+
+	            chargingInfo[gunIndex]->IsAvailable = YES;
+				setChargerMode(gunIndex, MODE_IDLE);
+			}
+		}
+		else if (strcmp((char *)ShmOCPP16Data->ChangeAvailability[gunIndex].Type, "Inoperative") == EQUAL)
+		{
+			if (chargingInfo[gunIndex]->SystemStatus == S_IDLE ||
+				chargingInfo[gunIndex]->SystemStatus == S_RESERVATION ||
+				chargingInfo[gunIndex]->SystemStatus == S_MAINTAIN)
+			{
+	            if (isDb_ready)
+	                DB_Update_Operactive(localDb, gunIndex, false);
+
+	            chargingInfo[gunIndex]->IsAvailable = NO;
+				setChargerMode(gunIndex, MODE_MAINTAIN);
+			}
+		}
+	}
+
+	if (ShmOCPP16Data->CsMsg.bits[gunIndex].UnlockConnectorReq == YES)
+	{
+		ShmOCPP16Data->CsMsg.bits[gunIndex].UnlockConnectorReq = NO;
+		if (chargingInfo[gunIndex]->SystemStatus >= S_REASSIGN_CHECK &&
+				chargingInfo[gunIndex]->SystemStatus <= S_CHARGING)
+		{
+			// 充電中,需停止充電
+			strcpy((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "UnlockCommand");
+			ChargingTerminalProcess(gunIndex);
+		}
+		strcpy((char *)ShmOCPP16Data->UnlockConnector[gunIndex].ResponseStatus, "Unlocked");
+		ShmOCPP16Data->CsMsg.bits[gunIndex].UnlockConnectorConf = YES;
+	}
+}
+
+bool CheckBackendChargingTimeout(byte gunIndex)
+{
+	bool result = false;
+
+	if (ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_ENABLE)
+	{
+		if (ShmSysConfigAndInfo->SysConfig.MaxChargingDuration > 0)
+		{
+			if (chargingInfo[gunIndex]->PresentChargedDuration > (ShmSysConfigAndInfo->SysConfig.MaxChargingDuration * 60))
+				result = true;
+		}
+	}
+	else if (ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_DISABLE)
+	{
+		// 隨插即充電的要看 offline
+		if (ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeDuration > 0)
+		{
+			if (chargingInfo[gunIndex]->PresentChargedDuration > (ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeDuration * 60))
+				result = true;
+		}
+	}
+
+	return result;
+}
+
+bool CheckBackendChargingEnergy(byte gunIndex)
+{
+	bool result = false;
+
+	if (ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_ENABLE)
+	{
+		if (ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy > 0)
+		{
+			if (chargingInfo[gunIndex]->PresentChargedEnergy > ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy)
+				result = true;
+		}
+	}
+	else if (ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_DISABLE)
+	{
+		// 隨插即充電的要看 offline
+		if (ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy > 0)
+		{
+			if (chargingInfo[gunIndex]->PresentChargedEnergy > (ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy))
+				result = true;
+		}
+	}
+
+	return result;
+}
+
+void InformOcppErrOccur(byte codeType)
+{
+	char _error[25];
+
+	switch(codeType)
+	{
+	case 4: strcpy(_error, "InternalError"); break;
+	case 6: strcpy(_error, "NoError"); break;
+	case 7: strcpy(_error, "OtherError"); break;
+	case 13: strcpy(_error, "UnderVoltage"); break;
+	case 14: strcpy(_error, "OverVoltage"); break;
+	}
+
+	for (byte gun_index = 0; gun_index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gun_index++)
+	{
+		strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, _error);
+	}
+}
+
+//===============================================
+// SQLite3 related routine
+//===============================================
+int DB_Open(sqlite3 *db)
+{
+	int result = PASS;
+	char* errMsg = NULL;
+	char* createRecordSql="CREATE TABLE IF NOT EXISTS charging_record("
+					      "idx integer primary key AUTOINCREMENT, "
+						  "reservationId text, "
+						  "transactionId text, "
+						  "startMethod text, "
+						  "userId text, "
+						  "dateTimeStart text, "
+						  "dateTimeStop text,"
+						  "socStart text, "
+						  "socStop text, "
+						  "chargeEnergy text, "
+						  "stopReason text"
+						  ");";
+
+	char* createCfgSql="CREATE TABLE IF NOT EXISTS `config` ( "
+					   "`idx` INTEGER PRIMARY KEY AUTOINCREMENT, "
+					   "`IsAvailable` TEXT NOT NULL, "
+				       "`connector` INTEGER NOT NULL, "
+					   "`val` TEXT NOT NULL, unique(IsAvailable,connector) on conflict replace);";
+
+	if(sqlite3_open(DB_FILE, &db))
+	{
+		result = FAIL;
+		PRINTF_FUNC( "Can't open database: %s\r\n", sqlite3_errmsg(db));
+		sqlite3_close(db);
+	}
+	else
+	{
+		PRINTF_FUNC( "Local charging record database open successfully.\r\n");
+
+		if (sqlite3_exec(db, createRecordSql, 0, 0, &errMsg) != SQLITE_OK)
+		{
+			result = FAIL;
+			PRINTF_FUNC( "Create local charging record table error message: %s\n", errMsg);
+		}
+		else
+		{
+			PRINTF_FUNC( "Opened local charging record table successfully\n");
+		}
+
+		if (sqlite3_exec(db, createCfgSql, 0, 0, &errMsg) != SQLITE_OK)
+		{
+			result = FAIL;
+			PRINTF_FUNC( "Create local config table error message: %s\n", errMsg);
+		}
+		else
+		{
+			PRINTF_FUNC( "Opened local config table successfully\n");
+		}
+
+		sqlite3_close(db);
+	}
+
+	return result;
+}
+
+int DB_Insert_Record(sqlite3 *db, int gun_index)
+{
+	int result = PASS;
+	char* errMsg = NULL;
+	char insertSql[1024];
+
+	sprintf(insertSql, "insert into charging_record(reservationId, transactionId, startMethod, userId, dateTimeStart, dateTimeStop, socStart, socStop, chargeEnergy, stopReason) "
+					   "values('%d', '%d', '%d', '%s', '%s', '%s', '%d', '%d', '%f', '%s');",
+					   ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].ReservationId,
+					   ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId,
+					   ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartMethod,
+					   ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartUserId,
+					   ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartDateTime,
+					   ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StopDateTime,
+					   ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc,
+					   ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc,
+					   ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargedEnergy,
+					   ShmOCPP16Data->StopTransaction[gun_index].StopReason);
+
+	if(sqlite3_open("/Storage/ChargeLog/localCgargingRecord.db", &db))
+	{
+		result = FAIL;
+		PRINTF_FUNC( "Can't open database: %s\r\n", sqlite3_errmsg(db));
+		sqlite3_close(db);
+	}
+	else
+	{
+		PRINTF_FUNC( "Local charging record database open successfully.\r\n");
+		if (sqlite3_exec(db, insertSql, 0, 0, &errMsg) != SQLITE_OK)
+		{
+			result = FAIL;
+			PRINTF_FUNC( "Insert local charging record error message: %s\n", errMsg);
+		}
+		else
+		{
+			PRINTF_FUNC( "Insert local charging record successfully\n");
+		}
+		sqlite3_close(db);
+	}
+
+	return result;
+}
+
+int DB_Update_Operactive(sqlite3 *db, uint8_t gun_index, uint8_t IsAvailable)
+{
+	uint8_t result = false;
+	char* errMsg = NULL;
+	char sqlStr[1024];
+	srand(time(NULL));
+
+	if(sqlite3_open(DB_FILE, &db))
+	{
+		result = FAIL;
+		PRINTF_FUNC( "Can't open database: %s\r\n", sqlite3_errmsg(db));
+		sqlite3_close(db);
+	}
+	else
+	{
+		PRINTF_FUNC( "Local charging record database open successfully (%d).\r\n", IsAvailable);
+
+		sprintf(sqlStr, "insert or replace into config (IsAvailable, connector, val) values('IsAvailable', %d, %d);", gun_index, IsAvailable);
+		PRINTF_FUNC("sqlStr= %s\r\n", sqlStr);
+		if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
+		{
+			result = FAIL;
+			PRINTF_FUNC( "update config error message: %s\n", errMsg);
+		}
+		else
+		{
+			PRINTF_FUNC("update connector-%d config item isOperactive to %d\r\n", gun_index, IsAvailable);
+		}
+
+		sqlite3_close(db);
+	}
+
+	return result;
+}
+
+int DB_Get_Operactive(sqlite3 *db, uint8_t gun_index)
+{
+	uint8_t result = true;
+	char* errMsg = NULL;
+	char sqlStr[1024];
+	char **rs;
+	int	 rows, cols;
+
+	sprintf(sqlStr, "select * from config where IsAvailable='IsAvailable' and connector=%d;", gun_index);
+	//DEBUG_INFO("sqlStr= %s\r\n", sqlStr);
+
+	if(sqlite3_open(DB_FILE, &db))
+	{
+		result = FAIL;
+		PRINTF_FUNC( "Can't open database: %s\r\n", sqlite3_errmsg(db));
+		sqlite3_close(db);
+	}
+	else
+	{
+		PRINTF_FUNC( "Local config query database open successfully.\r\n");
+		sqlite3_get_table(db, sqlStr, &rs, &rows, &cols, &errMsg);
+		if(rows>0)
+		{
+			for(int idxRow=1;idxRow<=rows;idxRow++)
+			{
+				if(strcmp(rs[(idxRow*cols)+3], "0") == 0)
+				{
+					result = false;
+				}
+				PRINTF_FUNC("Query connector-%d isOperactive: %s\r\n", gun_index, rs[(idxRow*cols)+3]);
+			}
+		}
+		else
+		{
+			PRINTF_FUNC("Query connector-%d fail, set default value to operactive.\r\n", gun_index);
+		}
+
+		sqlite3_free_table(rs);
+		sqlite3_close(db);
+	}
+
+	return result;
+}
+
+//===============================================
+// Config process
+//===============================================
+void AddPlugInTimes(byte gunIndex)
+{
+	if (chargingInfo[gunIndex]->Type == _Type_Chademo)
+		ShmSysConfigAndInfo->SysConfig.ChademoPlugInTimes += 1;
+	else if(chargingInfo[gunIndex]->Type == _Type_CCS_2)
+		ShmSysConfigAndInfo->SysConfig.Ccs2PlugInTimes += 1;
+	else if(chargingInfo[gunIndex]->Type == _Type_GB)
+		ShmSysConfigAndInfo->SysConfig.GbPlugInTimes += 1;
+}
+
+void ChangeStartOrStopDateTime(byte isStart, byte gunIndex)
+{
+	char cmdBuf[32];
+	struct timeb csuTime;
+	struct tm *tmCSU;
+
+	ftime(&csuTime);
+	tmCSU = localtime(&csuTime.time);
+
+	sprintf(cmdBuf, "%04d-%02d-%02d %02d:%02d:%02d", tmCSU->tm_year + 1900,
+			tmCSU->tm_mon + 1, tmCSU->tm_mday, tmCSU->tm_hour, tmCSU->tm_min,
+			tmCSU->tm_sec);
+	if (isStart)
+		strcpy((char *)chargingInfo[gunIndex]->StartDateTime, cmdBuf);
+	else
+		strcpy((char *)chargingInfo[gunIndex]->StopDateTime, cmdBuf);
+}
+
+void zipLogFiles()
+{
+	const char* logPath = "/Storage/SystemLog";
+	// 獲取目錄
+	DIR* pDir = opendir(logPath);
+	if (pDir != NULL)
+	{
+		struct timeb csuTime;
+		struct tm *tmCSU;
+
+		ftime(&csuTime);
+		tmCSU = localtime(&csuTime.time);
+//		PRINTF_FUNC("Time : %04d-%02d-%02d %02d:%02d:%02d \n", tmCSU->tm_year + 1900,
+//			tmCSU->tm_mon + 1, tmCSU->tm_mday, tmCSU->tm_hour, tmCSU->tm_min,
+//			tmCSU->tm_sec);
+
+		// Read items inside the folder
+		struct dirent* pEntry = NULL;
+		while ((pEntry = readdir(pDir)) != NULL)
+		{
+			if (strcmp(pEntry->d_name, ".") != 0 &&
+					strcmp(pEntry->d_name, "..") != 0 &&
+					strncmp(pEntry->d_name, "[", 1) == 0 &&
+					strstr(pEntry->d_name, "tar") < 0)
+			{
+				char yearC[5];
+				unsigned short year = 0;
+				char monthC[3];
+				unsigned short month = 0;
+
+				yearC[4] = '\0';
+				strncpy(yearC, pEntry->d_name + 1, 4);
+				monthC[2] = '\0';
+				strncpy(monthC, pEntry->d_name + 6, 2);
+
+				year = atoi(yearC);
+				month = atoi(monthC);
+
+				if (year != 0)
+				{
+					if (year < tmCSU->tm_year + 1900 ||
+							(year >= tmCSU->tm_year + 1900 && month < tmCSU->tm_mon + 1))
+					{
+						DEBUG_INFO_MSG("tar file name : %s \n", pEntry->d_name);
+						char file[256];
+
+						memset(file, 0x00, sizeof(file));
+						strcat(file, "tar zcvf ");
+						strcat(file, logPath);
+						strncat(file, "/", 1);
+						strcat(file, pEntry->d_name);
+						strcat(file, ".tar");
+						strncat(file, " ", 1);
+						strcat(file, logPath);
+						strncat(file, "/", 1);
+						strcat(file, pEntry->d_name);
+						PRINTF_FUNC("zip = %s \n", file);
+						system(file);
+					}
+				}
+			}
+		}
+	}
+	// Close folder
+	closedir(pDir);
+}
+
+void ChangeGunSelectByIndex(byte sel)
+{
+	ShmSysConfigAndInfo->SysInfo.CurGunSelected = sel;
+	ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc = NO_DEFINE;
+}
+
+void CheckIsAlternatvieByModelName()
+{
+	// 黑白機 ?
+	if(strcmp((char *)ShmSysConfigAndInfo->SysConfig.ModelName, "DWWU301J0UT1PH") == EQUAL ||
+		strcmp((char *)ShmSysConfigAndInfo->SysConfig.ModelName, "DWYE301J0ET1PH") == EQUAL ||
+		strcmp((char *)ShmSysConfigAndInfo->SysConfig.ModelName, "DSYE301J3EW2PH") == EQUAL ||
+		strcmp((char *)ShmSysConfigAndInfo->SysConfig.ModelName, "DWYC301J0UW1PH") == EQUAL ||
+		strcmp((char *)ShmSysConfigAndInfo->SysConfig.ModelName, "DWYC301J0UD1PH") == EQUAL)
+		ShmSysConfigAndInfo->SysInfo.IsAlternatvieConf = YES;
+	else
+		ShmSysConfigAndInfo->SysInfo.IsAlternatvieConf = NO;
+}
+
+void StopProcessingLoop()
+{
+	for (;;)
+	{
+		CheckFactoryConfigFunction();
+		CheckFwUpdateFunction();
+		sleep(1);
+	}
+}
+
+void CreateWatchdog()
+{
+	if (ShmSysConfigAndInfo->SysConfig.SwitchDebugFlag == NO)
+	{
+		wtdFd = InitWatchDog();
+
+		if (wtdFd < 0)
+			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed = 1;
+	}
+}
+
+bool IsConnectorWholeIdle()
+{
+	bool result = true;
+
+	for (byte count = 0; count < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; count++)
+	{
+		if (chargingInfo[count]->SystemStatus != S_IDLE &&
+				chargingInfo[count]->SystemStatus != S_RESERVATION)
+		{
+			result = false;
+			break;
+		}
+	}
+
+	for (byte count = 0; count < ShmSysConfigAndInfo->SysConfig.AcConnectorCount; count++)
+	{
+		if (ac_chargingInfo[count]->SystemStatus != S_IDLE &&
+				ac_chargingInfo[count]->IsErrorOccur == NO)
+		{
+			result = false;
+			break;
+		}
+	}
+
+	return result;
+}
+
+void ClearAlarmCodeWhenAcOff()
+{
+	if (!ShmSysConfigAndInfo->SysInfo.AcContactorStatus)
+	{
+		ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuNoResource = NO;
+	}
+}
+
+//==========================================
+// Check task processing
+//==========================================
+void CheckTask()
+{
+	if(ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'T')
+	{
+		if(system("pidof -s Module_4g > /dev/null") != 0)
+		{
+			DEBUG_ERROR_MSG("Module_4g not running, restart it.\r\n");
+			system("/root/Module_4g &");
+		}
+	}
+	else if(ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'W')
+	{
+		if(system("pidof -s Module_Wifi > /dev/null") != 0)
+		{
+			DEBUG_ERROR_MSG("Module_Wifi not running, restart it.\r\n");
+			system("/root/Module_Wifi &");
+		}
+	}
+
+	if(strcmp((char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, "") != EQUAL &&
+			strcmp((char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId, "") != EQUAL)
+	{
+		if(system("pidof -s OcppBackend > /dev/null") != 0)
+		{
+			DEBUG_ERROR_MSG("OcppBackend not running, restart it.\r\n");
+			system("/root/OcppBackend &");
+		}
+	}
+
+	if(system("pidof -s Module_ProduceUtils > /dev/null") != 0)
+	{
+		DEBUG_ERROR_MSG("Module_ProduceUtils not running, restart it.\r\n");
+		system ("/root/Module_ProduceUtils &");
+	}
+}
+
+void InitialDHCP()
+{
+	char tmpbuf[256];
+	memset(tmpbuf,0,256);
+	system("pgrep -f \"udhcpc -i eth0\" | xargs kill");
+	sprintf(tmpbuf, "/sbin/udhcpc -i eth0 -x hostname:CSU3_%s -s /root/dhcp_script/eth0.script > /dev/null &", ShmSysConfigAndInfo->SysConfig.SystemId);
+	system(tmpbuf);
+}
+
+void InitialDispenserDhcpServerConfig(void)
+{
+	system("echo 'start           192.168.100.10'        > /etc/udhcpd.conf");
+	system("echo 'end             192.168.100.20'        >> /etc/udhcpd.conf");
+	system("echo 'interface       eth1'                  >> /etc/udhcpd.conf");
+	system("echo 'opt             dns     8.8.8.8'       >> /etc/udhcpd.conf");
+	system("echo 'option          subnet  255.255.255.0' >> /etc/udhcpd.conf");
+	system("echo 'opt             router  192.168.100.1' >> /etc/udhcpd.conf");
+	system("echo 'option          domain  local'         >> /etc/udhcpd.conf");
+	system("echo 'option          lease   86400'         >> /etc/udhcpd.conf");
+
+	usleep(1000);
+}
+
+void StartDispenserDhcpServer(void)
+{
+	system("killall udhcpd");
+	system("/usr/sbin/udhcpd /etc/udhcpd.conf > /dev/null &");
+}
+
+//==========================================
+// Check Smart Charging Profile
+//==========================================
+int GetStartScheduleTime(unsigned char *time)
+{
+	int result = -1;
+	struct tm tmScheduleStart;
+	struct timeb tbScheduleStart;
+
+	if((sscanf((char *)time, "%4d-%2d-%2dT%2d:%2d:%2d", &tmScheduleStart.tm_year, &tmScheduleStart.tm_mon, &tmScheduleStart.tm_mday, &tmScheduleStart.tm_hour, &tmScheduleStart.tm_min, &tmScheduleStart.tm_sec) == 6))
+	{
+		tmScheduleStart.tm_year -= 1900;
+		tmScheduleStart.tm_mon -= 1;
+		tbScheduleStart.time = mktime(&tmScheduleStart);
+		tbScheduleStart.millitm = 0;
+
+		result = DiffTimebWithNow(tbScheduleStart) / 1000;
+	}
+
+	return result;
+}
+
+void CheckSmartChargeProfile(byte _index)
+{
+	if (ShmOCPP16Data->CSUMsg.bits[_index].ChargingProfileConf == NO)
+	{
+		if (ShmOCPP16Data->CSUMsg.bits[_index].ChargingProfileReq == NO)
+			ShmOCPP16Data->CSUMsg.bits[_index].ChargingProfileReq = YES;
+	}
+	else
+	{
+		// Get Charging Profile
+		ShmOCPP16Data->CSUMsg.bits[_index].ChargingProfileConf = NO;
+		if (strcmp((char *)ShmOCPP16Data->SmartChargingProfile[_index].ChargingProfileKind, "Absolute") == EQUAL)
+		{
+			int _time = GetStartScheduleTime(ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.StartSchedule);
+			byte _startCount = NO_DEFINE;
+			byte _maxCount = ARRAY_SIZE(ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod);
+
+			for (byte _count = 0; _count < _maxCount; _count++)
+			{
+				// 預設最小輸出電流 (MIN_OUTPUT_CUR) A
+				if (_time >= ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[_count].StartPeriod &&
+						ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[_count].Limit > MIN_OUTPUT_CUR)
+				{
+					_startCount = _count;
+				}
+			}
+
+			PRINTF_FUNC("_startCount = %d \n", _startCount);
+			if (_startCount < _maxCount)
+			{
+				PRINTF_FUNC("*********Limit = %f \n", ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[_startCount].Limit);
+				chargingInfo[_index]->ChargingProfileCurrent = ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[_startCount].Limit * 10;
+				chargingInfo[_index]->ChargingProfilePower = ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[_startCount].Limit * chargingInfo[_index]->EvBatterytargetVoltage / 100;
+
+				//chargingInfo[_index]->ChargingProfilePower = ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[_startCount].Limit * AC_OUTPUT_VOL;
+//				if ((chargingInfo[_index]->EvBatterytargetVoltage * 10) > 0)
+//				{
+//					chargingInfo[_index]->ChargingProfileCurrent = chargingInfo[_index]->ChargingProfilePower / (chargingInfo[_index]->EvBatterytargetVoltage * 10);
+//				}
+			}
+			else
+			{
+				chargingInfo[_index]->ChargingProfilePower = -1;
+				chargingInfo[_index]->ChargingProfileCurrent = -1;
+			}
+
+			PRINTF_FUNC("ChargingProfilePower = %f \n", chargingInfo[_index]->ChargingProfilePower);
+			PRINTF_FUNC("ChargingProfileCurrent = %f \n", chargingInfo[_index]->ChargingProfileCurrent);
+		}
+//
+//		printf("-------------Schedule------------\n");
+//		printf("index = %d \n", _index);
+//		printf("StartSchedule = %s \n", ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.StartSchedule);
+//		printf("ChargingRateUnit = %s \n", ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingRateUnit);
+//		printf("----------SchedulePeriod---------\n");
+//		for (int v = 0; v < 10; v++)
+//		{
+//			printf("StartPeriod = %d \n", ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[v].StartPeriod);
+//			printf("Limit = %f \n", ShmOCPP16Data->SmartChargingProfile[_index].ChargingSchedule.ChargingSchedulePeriod[v].Limit);
+//		}
+//		printf("---------------------------------\n");
+	}
+}
+
+void CheckReturnToChargingConn()
+{
+	if ((ShmSysConfigAndInfo->SysConfig.TotalConnectorCount + ShmSysConfigAndInfo->SysConfig.AcConnectorCount) > 1 &&
+		ShmSysConfigAndInfo->SysInfo.PageIndex != _LCM_AUTHORIZING &&
+		ShmSysConfigAndInfo->SysInfo.PageIndex != _LCM_AUTHORIZ_FAIL &&
+		ShmSysConfigAndInfo->SysInfo.PageIndex != _LCM_AUTHORIZ_COMP &&
+		ShmSysConfigAndInfo->SysInfo.PageIndex != _LCM_WAIT_FOR_PLUG)
+	{
+		bool isReturnTimeout = false;
+
+		for (byte count = 0; count < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; count++)
+		{
+			// 如果選的 DC 槍在充電~ 則 DC 槍不改變
+			if (count == ShmSysConfigAndInfo->SysInfo.CurGunSelected)
+			{
+				if ((chargingInfo[count]->SystemStatus >= S_REASSIGN_CHECK && chargingInfo[count]->SystemStatus <= S_COMPLETE) ||
+						(chargingInfo[count]->SystemStatus >= S_CCS_PRECHARGE_ST0 && chargingInfo[count]->SystemStatus <= S_CCS_PRECHARGE_ST1))
+				{
+					isReturnTimeout = false;
+					break;
+				}
+			}
+			else if (count != ShmSysConfigAndInfo->SysInfo.CurGunSelected)
+			{
+				if ((chargingInfo[count]->SystemStatus >= S_REASSIGN_CHECK && chargingInfo[count]->SystemStatus <= S_COMPLETE) ||
+						(chargingInfo[count]->SystemStatus >= S_CCS_PRECHARGE_ST0 && chargingInfo[count]->SystemStatus <= S_CCS_PRECHARGE_ST1))
+				{
+					isReturnTimeout = true;
+					StartSystemTimeoutDet(Timeout_ReturnToChargingGunDet);
+				}
+			}
+		}
+
+		// AC 槍
+		if (!isReturnTimeout && ShmSysConfigAndInfo->SysConfig.AcConnectorCount > 0)
+		{
+			// 沒有選中 AC,且 AC 在充電中
+			if (ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc == NO_DEFINE &&
+					(ac_chargingInfo[0]->SystemStatus >= S_PREPARNING && ac_chargingInfo[0]->SystemStatus <= S_COMPLETE))
+			{
+				// 當前 DC 充電槍在 idle 狀態
+				if (chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus == S_IDLE ||
+						chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus == S_RESERVATION)
+				{
+					isReturnTimeout = true;
+					StartSystemTimeoutDet(Timeout_ReturnToChargingGunDet);
+				}
+			}
+			else if (ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc == DEFAULT_AC_INDEX &&
+						((chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus >= S_REASSIGN_CHECK && chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus <= S_COMPLETE) ||
+						(chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus >= S_CCS_PRECHARGE_ST0 && chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus <= S_CCS_PRECHARGE_ST1)))
+			{
+				// 當前 DC 充電槍在 idle 狀態
+				if (ac_chargingInfo[0]->SystemStatus == S_IDLE ||
+						ac_chargingInfo[0]->SystemStatus == S_RESERVATION)
+				{
+					isReturnTimeout = true;
+					StartSystemTimeoutDet(Timeout_ReturnToChargingGunDet);
+				}
+			}
+		}
+
+		if (!isReturnTimeout)
+			StopSystemTimeoutDet();
+	}
+}
+
+bool GetStartChargingByAlterMode(byte _gun)
+{
+	bool result = true;
+
+	if (ShmSysConfigAndInfo->SysConfig.TotalConnectorCount == 2 &&
+			ShmSysConfigAndInfo->SysInfo.IsAlternatvieConf == YES)
+	{
+		for (byte _select = 0; _select < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _select++)
+		{
+			if (_select != _gun)
+			{
+				if (chargingInfo[_select]->SystemStatus != S_IDLE &&
+						chargingInfo[_select]->SystemStatus != S_RESERVATION)
+				{
+					result = false;
+					break;
+				}
+			}
+		}
+	}
+
+	return result;
+}
+
+
+
+
+
+
+
+
+
+int main(void)
+{
+	if(CreateShareMemory() == 0)
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR_MSG("CreatShareMemory NG \n");
+		#endif
+		if(ShmStatusCodeData!=NULL)
+		{
+			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory = 1;
+		}
+		sleep(5);
+		system("reboot -f");
+		sleep(5);
+		system("reboot -f");
+	}
+
+	if (!InitialSystemDefaultConfig())
+	{
+		DEBUG_ERROR_MSG("InitialSystemDefaultConfig NG \n");
+		StopProcessingLoop();
+	}
+
+	PRINTF_FUNC("SW Version = %s \n", fwVersion);
+	PRINTF_FUNC("Chademo = %d, CCS = %d, GB = %d, AC = %d, General: %d\n",
+			CHAdeMO_QUANTITY, CCS_QUANTITY, GB_QUANTITY, AC_QUANTITY, GENERAL_GUN_QUANTITY);
+
+	PRINTF_FUNC("CheckConnectorTypeStatus. \n");
+//	CheckGunTypeFromHw();
+	PRINTF_FUNC("CheckIsAlternatvie, ModelName = %s\n", ShmSysConfigAndInfo->SysConfig.ModelName);
+//	CheckIsAlternatvieByModelName();
+	PRINTF_FUNC("InitialShareMemoryInfo \n");
+	InitialShareMemoryInfo();
+
+	PRINTF_FUNC("ChargerType (IEC or UL) = %d \n", ShmSysConfigAndInfo->SysInfo.ChargerType);
+	ChangeLcmByIndex(_LCM_INIT);
+	if (!CheckConnectorTypeStatus())
+		isModelNameMatch = false;
+
+	Initialization();
+	PRINTF_FUNC("Spawn all Task. \n");
+	SpawnTask();
+
+	if (!isModelNameMatch)
+	{
+		PRINTF_FUNC("Module Name & HW info none match. \n");
+		ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ModelNameNoneMatchStestFail = YES;
+		ChangeLcmByIndex(_LCM_FIX);
+		// Module Name 與硬體對應不正確
+		DEBUG_ERROR_MSG("Module Name & HW info none match. \n");
+		sleep(3);
+		KillTask();
+		StopProcessingLoop();
+	}
+	PRINTF_FUNC("Module Name & HW info correct. Initialize.......\n");
+	CreateTimeoutFork();
+	PRINTF_FUNC("Self test. \n");
+	ShmPrimaryMcuData->OutputDrv.bits.SystemLed1Drv = true;         // green led
+	ShmPrimaryMcuData->OutputDrv.bits.SystemLed2Drv = true;         // red led
+	SelfTestRun();
+//	StopSystemTimeoutDet();
+
+	PRINTF_FUNC("SelfTestSeq = %d, Work_Step = %d \n", ShmSysConfigAndInfo->SysInfo.SelfTestSeq, ShmPsuData->Work_Step);
+	if (ShmSysConfigAndInfo->SysInfo.SelfTestSeq == _STEST_FAIL ||
+			ShmPsuData->Work_Step == _NO_WORKING)
+	{
+/*
+		if (ShmSysConfigAndInfo->SysWarningInfo.Level != 2)
+		{
+			if (!DisplaySelfTestFailReason())
+			{
+				PRINTF_FUNC("Soft reboot for retry self-tets. \n");
+				sleep(3);
+				system("killall OcppBackend &");
+				KillTask();
+				system("/usr/bin/run_evse_restart.sh");
+			}
+		}
+*/
+		for (byte gun_index = 0; gun_index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gun_index++)
+		{
+			setChargerMode(gun_index, MODE_ALARM);
+		}
+		ChangeLcmByIndex(_LCM_FIX);
+		sleep(3);
+		KillTask();
+		StopProcessingLoop();
+	}
+	else
+	{
+		for (byte gun_index = 0; gun_index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gun_index++)
+		{
+			setChargerMode(gun_index, MODE_IDLE);
+		}
+	}
+
+	// Local DB
+	if(DB_Open(localDb) != PASS)
+	{
+		PRINTF_FUNC("DB_Open fail. \n");
+		isDb_ready = false;
+	}
+	else
+	{
+		isDb_ready = true;
+		for(int _index=0; _index< ShmSysConfigAndInfo->SysConfig.TotalConnectorCount;_index++)
+		{
+			chargingInfo[_index]->IsAvailable = DB_Get_Operactive(localDb, _index);
+		}
+	}
+
+	ChangeLcmByIndex(_LCM_IDLE);
+	sleep(1);
+	//***** 須新增的偵測 *****//
+	// 1. Thernal - 控制風扇轉速
+	// 2. ouput fuse - 控制風扇轉速
+//	CreateRfidFork();
+	// Create Watchdog
+	//CreateWatchdog();
+	ShmPrimaryMcuData->OutputDrv.bits.SystemLed2Drv = false;
+	PRINTF_FUNC("**************************Wait Dispenser*******************************");
+	while(1)
+	{
+		if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.DispenserQuantity > 0)
+		{
+			break;
+		}
+	}
+
+	// Main loop
+	PRINTF_FUNC("****************************Main Loop********************************** \n");
+	gettimeofday(&_cmdMainPriority_time, NULL);
+	for (;;)
+	{
+		CheckOcppStatus();
+		ChkPrimaryStatus();
+		if ((IsConnectorWholeIdle() || ShmSysConfigAndInfo->SysInfo.PageIndex == _LCM_FIX) &&
+				ShmSysConfigAndInfo->SysInfo.SystemTimeoutFlag != Timeout_ReturnToChargingGunDet)
+		{
+			CheckFactoryConfigFunction();
+
+			CheckFwUpdateFunction();
+		}
+
+		// OCPP 邏輯
+		//OcppRemoteStartChk();
+		// 讀卡邏輯
+		//ScannerCardProcess();
+
+		PowerCabinetAuthorizeProcess();
+
+		// 當 AC 沒有搭上時,清除一些錯誤碼
+		ClearAlarmCodeWhenAcOff();
+		// 確認是否要回到充電中的槍畫面邏輯判斷
+		CheckReturnToChargingConn();
+
+//		if (_acgunIndex > 0 && isDetectPlugin() && !isCardScan)
+//		{
+//			ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_WAIT_FOR_PLUG;
+//		}
+
+		if ((GetTimeoutValue(_cmdMainPriority_time) / 1000) > 5000)
+		{
+			CheckTask();
+			for (byte _index = 0; _index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _index++)
+			{
+				if (chargingInfo[_index]->SystemStatus == S_CHARGING)
+					CheckSmartChargeProfile(_index);
+			}
+
+			gettimeofday(&_cmdMainPriority_time, NULL);
+
+			PRINTF_FUNC("Gun 1: %d(%s), Gun 2: %d(%s), OCPP: %s",
+                chargingInfo[0]->SystemStatus, chargingInfo[0]->IsAvailable ? "Operative" : "Inoperative",
+                chargingInfo[1]->SystemStatus, chargingInfo[1]->IsAvailable ? "Operative" : "Inoperative",
+                ShmOCPP16Data->OcppConnStatus ? "On" : "Off");
+		}
+
+		for (byte gun_index = 0; gun_index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gun_index++)
+		{
+			//CheckGpioInStatus();
+			CheckErrorOccurStatus(gun_index);
+			ChkOcppStatus(gun_index);
+
+			if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].Enable == false)
+			{
+				setChargerMode(gun_index, MODE_IDLE);
+			}
+
+			//PRINTF_FUNC("index = %d, ErrorCode = %s \n", gun_index, ShmOCPP16Data->StatusNotification[gun_index].ErrorCode);
+			switch(chargingInfo[gun_index]->SystemStatus)
+			{
+				case S_IDLE:
+				case S_RESERVATION:
+				case S_MAINTAIN:
+				case S_ALARM:
+				{
+					// clean ready to charge flag
+					ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].ReadyToCharge = false;
+
+					if (chargingInfo[gun_index]->SystemStatus == S_IDLE &&
+							isModeChange(gun_index))
+					{
+						PRINTF_FUNC("S_IDLE================================== %x \n", gun_index);
+						chargingInfo[gun_index]->PresentChargedDuration = 0;
+						chargingInfo[gun_index]->RemainChargingDuration = 0;
+						strcpy((char *)chargingInfo[gun_index]->StartDateTime, "");
+						strcpy((char *)chargingInfo[gun_index]->StopDateTime, "");
+						strcpy((char *)chargingInfo[gun_index]->StartUserId, "");
+						strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "");
+					}
+					else if (chargingInfo[gun_index]->SystemStatus == S_RESERVATION &&
+							isModeChange(gun_index))
+					{
+						PRINTF_FUNC("S_RESERVATION....................%x \n", gun_index);
+						ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = YES;
+					}
+
+					if (chargingInfo[gun_index]->IsAvailable == NO)
+					{
+						setChargerMode(gun_index, MODE_MAINTAIN);
+					}
+
+					if (ShmSysConfigAndInfo->SysWarningInfo.Level == 2)
+					{
+						if (gun_index == ShmSysConfigAndInfo->SysInfo.CurGunSelected)
+						{
+							ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_FIX;
+						}
+						ClearDetectPluginFlag();
+						setChargerMode(gun_index, MODE_ALARM);
+					}
+					else if (ShmSysConfigAndInfo->SysConfig.OfflinePolicy == _OFFLINE_POLICY_NO_CHARGING)
+					{
+						// 							不給充電
+					}
+					else
+					{
+						if (ShmSysConfigAndInfo->SysInfo.SystemPage == _LCM_FIX)
+						{
+							ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
+							for (byte g_index = 0; g_index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; g_index++)
+								setChargerMode(g_index, MODE_IDLE);
+						}
+
+						if (ShmSysConfigAndInfo->SysInfo.MainChargingMode == _MAIN_CHARGING_MODE_AVER)
+						{
+							if (ShmSysConfigAndInfo->SysInfo.AcContactorStatus == YES)
+							{
+								// 均充 -> 最大充
+								if (ShmSysConfigAndInfo->SysInfo.BridgeRelayStatus == NO)
+								{
+									if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag == _REASSIGNED_NONE)
+									{
+										PRINTF_FUNC("=============Smart Charging============= Step 11 \n");
+										ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_PREPARE_A_TO_M;
+									}
+								}
+								else if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag != _REASSIGNED_COMP &&
+										ShmSysConfigAndInfo->SysInfo.ReAssignedFlag != _REASSIGNED_WAITING)
+								{
+									PRINTF_FUNC("=============Smart Charging============= Step 14 \n");
+									ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_WAITING;
+								}
+								else if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag == _REASSIGNED_COMP)
+								{
+									ShmSysConfigAndInfo->SysInfo.MainChargingMode = _MAIN_CHARGING_MODE_MAX;
+									ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_NONE;
+								}
+							}
+							else
+							{
+								ShmSysConfigAndInfo->SysInfo.MainChargingMode = _MAIN_CHARGING_MODE_MAX;
+								ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_NONE;
+							}
+						}
+						else
+							ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_NONE;
+
+						// clean stop charge flag
+						chargingInfo[gun_index]->StopChargeFlag = false;
+
+						{ // Idle 正常程序起點
+							// 判斷是否有啟用檢查插槍
+							//if(isDetectPlugin())
+                            if(IsConnectorAuthorizeSuccess(gun_index))
+							{
+                                if(chargingInfo[gun_index]->ConnectorPlugIn &&
+                                    chargingInfo[gun_index]->IsAvailable &&
+                                    chargingInfo[gun_index]->SystemStatus == S_IDLE &&
+                                    ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].RemoteStatus == _CRS_Preparing)
+                                {
+                                    AddPlugInTimes(gun_index);
+                                    ChangeGunSelectByIndex(gun_index);
+                                    PRINTF_FUNC("index = %d, CardNumber = %s \n", gun_index, chargingInfo[gun_index]->StartUserId);
+                                    setChargerMode(gun_index, MODE_REASSIGN_CHECK);
+
+                                    AuthorizingSettingInitial(gun_index, ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].Parameter.bits.AuthorizeRequestType);
+                                    continue;
+                                }
+
+                                /*
+								// 卡號驗證成功後,等待充電槍插入充電車
+								if (chargingInfo[gun_index]->RemoteStartFlag == YES)
+								{
+									if (chargingInfo[gun_index]->ConnectorPlugIn == YES &&
+											chargingInfo[gun_index]->IsAvailable)
+									{
+										PRINTF_FUNC("-----------------1----------------- %d \n", gun_index);
+										chargingInfo[gun_index]->RemoteStartFlag = NO;
+										chargingInfo[gun_index]->isRemoteStart = YES;
+										ChangeGunSelectByIndex(gun_index);
+										AddPlugInTimes(gun_index);
+										setChargerMode(gun_index, MODE_REASSIGN_CHECK);
+										strcpy((char *)chargingInfo[gun_index]->StartUserId, "");
+										ClearDetectPluginFlag();
+										continue;
+									}
+								}
+								else if (ShmSysConfigAndInfo->SysInfo.OrderCharging == NO_DEFINE)
+								{
+									if (chargingInfo[gun_index]->ConnectorPlugIn == YES && chargingInfo[gun_index]->IsAvailable &&
+											chargingInfo[gun_index]->SystemStatus == S_IDLE)
+									{
+										PRINTF_FUNC("-----------------2----------------- \n");
+										ChangeGunSelectByIndex(gun_index);
+										AddPlugInTimes(gun_index);
+										strcpy((char *)chargingInfo[gun_index]->StartUserId, (char *)ShmSysConfigAndInfo->SysConfig.UserId);
+										PRINTF_FUNC("index = %d, CardNumber = %s \n", gun_index, chargingInfo[gun_index]->StartUserId);
+										strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
+										// 當前操作的槍號,進入 Preparing
+										setChargerMode(gun_index, MODE_REASSIGN_CHECK);
+										ClearDetectPluginFlag();
+										continue;
+									}
+								}
+*/
+//								if (!isCardScan)
+//								{
+									// LCM => Waiting for plugging
+//									ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_WAIT_FOR_PLUG;
+//								}
+							}
+							else if (chargingInfo[gun_index]->SystemStatus == S_RESERVATION)
+							{
+								if (!isReservationExpired(gun_index))
+								{
+									chargingInfo[gun_index]->SystemStatus = S_IDLE;
+								}
+							}
+							else if (ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_DISABLE &&
+									(chargingInfo[gun_index]->ConnectorPlugIn == YES && chargingInfo[gun_index]->IsAvailable))
+							{
+								PRINTF_FUNC("-----------------3----------------- \n");
+								bool isCanStartChargingFlag = GetStartChargingByAlterMode(gun_index);
+
+								if (isCanStartChargingFlag)
+								{
+									ChangeGunSelectByIndex(gun_index);
+									AddPlugInTimes(gun_index);
+									setChargerMode(gun_index, MODE_REASSIGN_CHECK);
+									ClearDetectPluginFlag();
+									continue;
+								}
+							}
+							else
+							{
+								if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index)
+									ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_IDLE;
+							}
+						} // Idle 正常程序終點
+					}
+
+					ReleaseAlarmCode(gun_index);
+				}
+					break;
+				case S_REASSIGN_CHECK:
+				{
+					if (isModeChange(gun_index))
+					{
+						PRINTF_FUNC("S_REASSIGN_CHECK================================== %x \n", gun_index);
+						ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
+						if (ShmSysConfigAndInfo->SysInfo.OrderCharging != NO_DEFINE)
+							ShmSysConfigAndInfo->SysInfo.OrderCharging = NO_DEFINE;
+						StopSystemTimeoutDet();
+					}
+
+					bool isRessign = false;
+					if (ShmSysConfigAndInfo->SysConfig.TotalConnectorCount > 1 && ShmSysConfigAndInfo->SysInfo.IsAlternatvieConf == NO)
+					{
+						if (ShmSysConfigAndInfo->SysInfo.MainChargingMode == _MAIN_CHARGING_MODE_MAX)
+						{
+							for (byte index = 0; index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; index++)
+							{
+								// 有其他槍已經分配好 psu 模塊
+								if (ShmSysConfigAndInfo->SysInfo.CurGunSelected != index &&
+										chargingInfo[index]->SystemStatus >= S_PREPARNING &&
+										chargingInfo[index]->SystemStatus != S_MAINTAIN)
+								{
+									PRINTF_FUNC("=============Smart Charging============= Step 1 \n");
+									ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_PREPARE_M_TO_A;
+									isRessign = true;
+									break;
+								}
+							}
+						}
+						else if (ShmSysConfigAndInfo->SysInfo.MainChargingMode == _MAIN_CHARGING_MODE_AVER &&
+								ShmSysConfigAndInfo->SysInfo.ReAssignedFlag != _REASSIGNED_NONE)
+						{
+							// 如果在切換最大充的過程中,需等待最大充切換完成後,在走均充流程
+							if (ShmSysConfigAndInfo->SysInfo.BridgeRelayStatus == YES)
+							{
+								if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag != _REASSIGNED_COMP &&
+										ShmSysConfigAndInfo->SysInfo.ReAssignedFlag != _REASSIGNED_WAITING)
+								{
+									PRINTF_FUNC("=============Smart Charging============= Step 14 \n");
+									ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_WAITING;
+								}
+								else if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag == _REASSIGNED_COMP)
+								{
+									ShmSysConfigAndInfo->SysInfo.MainChargingMode = _MAIN_CHARGING_MODE_MAX;
+									ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_NONE;
+									continue;
+								}
+							}
+
+							if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index)
+								ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_PRE_CHARGE;
+							continue;
+						}
+					}
+
+					if (isRessign)
+						setChargerMode(gun_index, MODE_REASSIGN);
+					else
+						setChargerMode(gun_index, MODE_PRECHARGE);
+
+					if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index)
+						ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_PRE_CHARGE;
+				}
+					break;
+				case S_REASSIGN:
+				{
+					if (isModeChange(gun_index))
+					{
+						PRINTF_FUNC("S_REASSIGN================================== %x \n", gun_index);
+						gettimeofday(&_toAverage_time, NULL);
+					}
+
+					// 重新分配,此階段主要是讓已經在充電或者準備進入充電前的緩衝
+					// 此狀態下~ 控制權在於 PSU 及 EV小板 Process
+					if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag == _REASSIGNED_NONE ||
+							ShmSysConfigAndInfo->SysInfo.MainChargingMode == _MAIN_CHARGING_MODE_AVER)
+					{
+						if (ShmSysConfigAndInfo->SysInfo.CanAverageCharging)
+							setChargerMode(gun_index, MODE_PRECHARGE);
+						else
+							setChargerMode(gun_index, MODE_IDLE);
+					}
+					else if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag == _REASSIGNED_RELAY_M_TO_A &&
+						ShmSysConfigAndInfo->SysInfo.BridgeRelayStatus == NO)
+					{
+						PRINTF_FUNC("=============Smart Charging : _REASSIGNED_COMP============= Step 6 \n");
+						ShmSysConfigAndInfo->SysInfo.MainChargingMode = _MAIN_CHARGING_MODE_AVER;
+						ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_NONE;
+					}
+
+					//PRINTF_FUNC("CurGunSelected = %d, gun_index = %d \n", ShmSysConfigAndInfo->SysInfo.CurGunSelected, gun_index);
+					if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index)
+						ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_PRE_CHARGE;
+				}
+					break;
+				case S_PREPARNING:
+				{
+					if (isModeChange(gun_index))
+					{
+						PRINTF_FUNC("S_PREPARNING================================== %x \n", gun_index);
+						StopGunInfoTimeoutDet(gun_index);
+						StartGunInfoTimeoutDet(gun_index, Timeout_Preparing);
+					}
+
+					if (ShmPsuData->SystemPresentPsuQuantity > 0 && ShmPsuData->SystemAvailablePower > 10 &&
+							GetTimeoutValue(chargingInfo[gun_index]->TimeoutTimer) >= 5000000)
+					{
+						setChargerMode(gun_index, MODE_PREPARE_FOR_EV);
+					}
+
+					if (isEvBoardStopChargeFlag(gun_index) == YES || OcppRemoteStop(gun_index) == YES)
+					{
+						// 板端或後臺要求停止
+					    PRINTF_FUNC("EvBoardStop: %d, OcppStop: %d \n", isEvBoardStopChargeFlag(gun_index), OcppRemoteStop(gun_index));
+						ChargingTerminalProcess(gun_index);
+					}
+
+					if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index)
+						ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_PRE_CHARGE;
+				}
+					break;
+				case S_PREPARING_FOR_EV: // 等待車端的通訊 (EV 小板),待車端回報後,開始樁端的測試
+				{
+					if (isModeChange(gun_index))
+					{
+						PRINTF_FUNC("S_PREPARING_FOR_EV================================== %x \n", gun_index);
+						//strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
+						StopGunInfoTimeoutDet(gun_index);
+						StartGunInfoTimeoutDet(gun_index, Timeout_EvChargingDet);
+					}
+/*
+					if (chargingInfo[gun_index]->Type == _Type_Chademo)
+					{
+						// 檢查車端的槍鎖是否為鎖上
+						if (isEvGunLocked_chademo(gun_index) == YES)
+						{
+							setChargerMode(gun_index, MODE_PREPARE_FOR_EVSE);
+						}
+					}
+					else if (chargingInfo[gun_index]->Type == _Type_GB)
+					{
+						// 檢查車端的 charging enable 是否為 1
+						if (isEvGunLocked_gb(gun_index) == YES)
+						{
+							setChargerMode(gun_index, MODE_PREPARE_FOR_EVSE);
+						}
+					}
+					else if (chargingInfo[gun_index]->Type == _Type_CCS_2)
+					{
+						// 檢查車端的 charging enable 是否為 1
+						if (isEvGunLocked_ccs(gun_index) == YES)
+						{
+							setChargerMode(gun_index, MODE_PREPARE_FOR_EVSE);
+						}
+					}
+*/
+					if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].ReadyToCharge)
+					{
+						setChargerMode(gun_index, MODE_CHARGING);
+					}
+
+					if (isEvBoardStopChargeFlag(gun_index) == YES  ||
+							OcppRemoteStop(gun_index) == YES)
+					{
+						// 板端或後臺要求停止
+						ChargingTerminalProcess(gun_index);
+					}
+
+					// LCM => Pre-charging
+					if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index)
+						ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_PRE_CHARGE;
+				}
+					break;
+				case S_PREPARING_FOR_EVSE: // 等待 RB 通訊及測試,並將狀態回報, CSU 確認 Pass 後,開始進入充電
+				{
+					if (isModeChange(gun_index))
+					{
+						PRINTF_FUNC("S_PREPARING_FOR_EVSE================================== %x \n", gun_index);
+						StopGunInfoTimeoutDet(gun_index);
+						StartGunInfoTimeoutDet(gun_index, Timeout_EvseChargingDet);
+					}
+
+					if (chargingInfo[gun_index]->Type == _Type_Chademo)
+					{
+						// 檢查樁端的 GFD 結果
+						if (isPrechargeStatus_chademo(gun_index) > 5 && isPrechargeStatus_chademo(gun_index) < 8)
+						{
+							// 當前操作的槍號,進入 Charging
+							setChargerMode(gun_index, MODE_CHARGING);
+						}
+
+						if (chargingInfo[gun_index]->GroundFaultStatus == GFD_FAIL)
+						{
+							// GFD 錯誤停止
+							RecordAlarmCode(gun_index, "012234");
+						}
+						else if (chargingInfo[gun_index]->GroundFaultStatus == GFD_WARNING)
+						{
+							// GFD 警告
+							RecordWarningCode(gun_index, "012296");
+						}
+					}
+					else if (chargingInfo[gun_index]->Type == _Type_GB)
+					{
+						// 檢查樁端的 GFD 結果
+						if (isPrechargeStatus_gb(gun_index) > 5 && isPrechargeStatus_gb(gun_index) < 9)
+						{
+							setChargerMode(gun_index, MODE_CHARGING);
+						}
+
+						if (chargingInfo[gun_index]->GroundFaultStatus == GFD_FAIL)
+						{
+							// GFD 錯誤停止
+							RecordAlarmCode(gun_index, "012236");
+						}
+						else if (chargingInfo[gun_index]->GroundFaultStatus == GFD_WARNING)
+						{
+							// GFD 警告
+							RecordWarningCode(gun_index, "012298");
+						}
+					}
+					else if (chargingInfo[gun_index]->Type == _Type_CCS_2)
+					{
+						// 檢查樁端的 GFD 結果
+						if ((chargingInfo[gun_index]->GroundFaultStatus == GFD_PASS ||
+								chargingInfo[gun_index]->GroundFaultStatus == GFD_WARNING))
+						{
+							setChargerMode(gun_index, MODE_CCS_PRECHARGE_STEP0);
+						}
+
+						if (chargingInfo[gun_index]->GroundFaultStatus == GFD_FAIL)
+						{
+							// GFD 錯誤停止
+							RecordAlarmCode(gun_index, "012235");
+						}
+						else if (chargingInfo[gun_index]->GroundFaultStatus == GFD_WARNING)
+						{
+							// GFD 警告
+							RecordWarningCode(gun_index, "012297");
+						}
+					}
+
+					if (isEvBoardStopChargeFlag(gun_index) == YES ||
+							OcppRemoteStop(gun_index) == YES)
+					{
+						// 板端或後臺要求停止
+						ChargingTerminalProcess(gun_index);
+					}
+
+					// LCM => Pre-charging
+					if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index)
+						ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_PRE_CHARGE;
+				}
+					break;
+				case S_CHARGING: // 剛進入充電狀態,等待 EV 小板要求的輸出電流後開始輸出
+				{
+					if (isModeChange(gun_index))
+					{
+						PRINTF_FUNC("S_CHARGING================================== %x \n", gun_index);
+						StopGunInfoTimeoutDet(gun_index);
+						ftime(&startChargingTime[gun_index]);
+						ChangeStartOrStopDateTime(YES, gun_index);
+						OcppStartTransation(gun_index);
+					}
+
+					if (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf)
+						ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = NO;
+
+					ftime(&endChargingTime[gun_index]);
+					chargingInfo[gun_index]->PresentChargedDuration = DiffTimeb(startChargingTime[gun_index], endChargingTime[gun_index]);
+
+					if (chargingInfo[gun_index]->Type == _Type_Chademo)
+					{
+						if (chargingInfo[gun_index]->GroundFaultStatus == GFD_FAIL)
+						{
+							// GFD 錯誤停止
+							RecordAlarmCode(gun_index, "012234");
+						}
+						//else if (((chargingInfo[gun_index]->EvBatterytargetVoltage * 10) > 0 && chargingInfo[gun_index]->EvBatterytargetVoltage < SYSTEM_MIN_VOL) ||
+						//		(chargingInfo[gun_index]->PresentChargedDuration >= 10 && chargingInfo[gun_index]->PresentChargingVoltage < SYSTEM_MIN_VOL))
+						//{
+							// UVP
+						//	RecordAlarmCode(gun_index, "012289");
+						//	ChargingTerminalProcess(gun_index);
+						//}
+						else if (chargingInfo[gun_index]->GroundFaultStatus == GFD_WARNING)
+						{
+							// GFD 警告
+							RecordWarningCode(gun_index, "012296");
+						}
+					}
+					else if (chargingInfo[gun_index]->Type == _Type_GB)
+					{
+						if (chargingInfo[gun_index]->GroundFaultStatus == GFD_FAIL)
+						{
+							// GFD 錯誤停止
+							RecordAlarmCode(gun_index, "012236");
+						}
+						//else if (isPrechargeStatus_gb(gun_index) == 10 &&
+						//		(((chargingInfo[gun_index]->EvBatterytargetVoltage * 10) > 0 && chargingInfo[gun_index]->EvBatterytargetVoltage < SYSTEM_MIN_VOL) ||
+						//		(chargingInfo[gun_index]->PresentChargedDuration >= 10 && chargingInfo[gun_index]->PresentChargingVoltage < SYSTEM_MIN_VOL)))
+						//{
+							// UVP
+						//	RecordAlarmCode(gun_index, "012290");
+						//	ChargingTerminalProcess(gun_index);
+						//}
+						else if (chargingInfo[gun_index]->GroundFaultStatus == GFD_WARNING)
+						{
+							// GFD 警告
+							RecordWarningCode(gun_index, "012298");
+						}
+					}
+					else if (chargingInfo[gun_index]->Type == _Type_CCS_2)
+					{
+						if (chargingInfo[gun_index]->GroundFaultStatus == GFD_FAIL)
+						{
+							// GFD 錯誤停止
+							RecordAlarmCode(gun_index, "012235");
+						}
+						//else if (((chargingInfo[gun_index]->EvBatterytargetVoltage * 10) > 0 && chargingInfo[gun_index]->EvBatterytargetVoltage < SYSTEM_MIN_VOL) ||
+						//		(chargingInfo[gun_index]->PresentChargedDuration >= 10 && chargingInfo[gun_index]->PresentChargingVoltage < SYSTEM_MIN_VOL))
+						//{
+							// UVP
+						//	RecordAlarmCode(gun_index, "012288");
+						//	ChargingTerminalProcess(gun_index);
+						//}
+						else if (chargingInfo[gun_index]->GroundFaultStatus == GFD_WARNING)
+						{
+							// GFD 警告
+							RecordWarningCode(gun_index, "012297");
+						}
+					}
+
+					if (isEvBoardStopChargeFlag(gun_index) ||
+							OcppRemoteStop(gun_index) ||
+							CheckBackendChargingTimeout(gun_index) ||
+							CheckBackendChargingEnergy(gun_index) ||
+							strcmp((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "Invalid") == EQUAL)
+					{
+						PRINTF_FUNC("S_CHARGING=======Stop=========================== %f \n", (chargingInfo[gun_index]->EvBatterytargetVoltage * 10));
+						// 板端或後臺要求停止
+						ChargingTerminalProcess(gun_index);
+					}
+
+					// LCM => Charging
+					if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index)
+						ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_CHARGING;
+				}
+					break;
+				case S_TERMINATING:
+				{
+					if (isModeChange(gun_index))
+					{
+						PRINTF_FUNC ("terminating......................... %x \n", gun_index);
+						StopGunInfoTimeoutDet(gun_index);
+					}
+
+					setChargerMode(gun_index, MODE_COMPLETE);
+/*
+					if (chargingInfo[gun_index]->Type == _Type_Chademo)
+					{
+						// 非車端的停止 : 需等待小板送出停止指令,讓車端解除槍
+						if (isEvStopCharging_chademo(gun_index) == YES)
+						{
+							if (strcmp((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "") == EQUAL)
+								strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "Local");
+						}
+
+						if (chargingInfo[gun_index]->GroundFaultStatus == GFD_FAIL)
+						{
+							// GFD 錯誤停止
+							RecordAlarmCode(gun_index, "012234");
+						}
+						else if (chargingInfo[gun_index]->GroundFaultStatus == GFD_WARNING)
+						{
+							// GFD 警告
+							RecordWarningCode(gun_index, "012296");
+						}
+
+						if (isEvStopCharging_chademo(gun_index) == YES ||
+								isPrechargeStatus_chademo(gun_index) <= 0)
+						{
+							setChargerMode(gun_index, MODE_COMPLETE);
+						}
+					}
+					else if (chargingInfo[gun_index]->Type == _Type_GB)
+					{
+						PRINTF_FUNC("************ GB lock Status = %d, status = %d \n", isEvStopCharging_gb(gun_index), isPrechargeStatus_gb(gun_index));
+						// 非車端的停止 : 需等待小板送出停止指令,讓車端解除槍
+						if (isEvStopCharging_chademo(gun_index) == YES)
+						{
+							if (strcmp((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "") == EQUAL)
+									strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "Local");
+						}
+
+						if (chargingInfo[gun_index]->GroundFaultStatus == GFD_FAIL)
+						{
+							// GFD 錯誤停止
+							RecordAlarmCode(gun_index, "012236");
+						}
+						else if (chargingInfo[gun_index]->GroundFaultStatus == GFD_WARNING)
+						{
+							// GFD 警告
+							RecordWarningCode(gun_index, "012298");
+						}
+
+						if (isEvStopCharging_gb(gun_index) == YES ||
+								isPrechargeStatus_gb(gun_index) <= 0)
+						{
+							setChargerMode(gun_index, MODE_COMPLETE);
+						}
+					}
+					else if (chargingInfo[gun_index]->Type == _Type_CCS_2)
+					{
+						// 非車端的停止 : 需等待小板送出停止指令,讓車端解除槍
+						if (isEvStopCharging_chademo(gun_index) == YES)
+						{
+							if (strcmp((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "") == EQUAL)
+									strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "Local");
+						}
+
+						if (chargingInfo[gun_index]->GroundFaultStatus == GFD_FAIL)
+						{
+							// GFD 錯誤停止
+							RecordAlarmCode(gun_index, "012235");
+						}
+						else if (chargingInfo[gun_index]->GroundFaultStatus == GFD_WARNING)
+						{
+							// GFD 警告
+							RecordWarningCode(gun_index, "012297");
+						}
+
+						if (isEvStopCharging_ccs(gun_index) == YES &&
+								(isPrechargeStatus_ccs(gun_index) >= 53 || isPrechargeStatus_ccs(gun_index) == 0 ||
+										isPrechargeStatus_ccs(gun_index) == 13 || isPrechargeStatus_ccs(gun_index) == 14))
+						{
+							setChargerMode(gun_index, MODE_COMPLETE);
+						}
+					}
+
+					// 車端的停止
+					if (strcmp((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "") == EQUAL)
+						strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, "EVDisconnected");
+*/
+					if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index)
+						ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_COMPLETE;
+				}
+					break;
+				case S_COMPLETE:
+				{
+					if (isModeChange(gun_index))
+					{
+						PRINTF_FUNC ("complete......................... %x \n", gun_index);
+						if (strcmp((char *)chargingInfo[gun_index]->StartDateTime, "") != EQUAL)
+						{
+							OcppStopTransation(gun_index);
+						}
+						ftime(&endChargingTime[gun_index]);
+						if (chargingInfo[gun_index]->PresentChargedDuration != 0)
+							chargingInfo[gun_index]->PresentChargedDuration = DiffTimeb(startChargingTime[gun_index], endChargingTime[gun_index]);
+
+						chargingInfo[gun_index]->isRemoteStart = NO;
+
+						StopGunInfoTimeoutDet(gun_index);
+						StartGunInfoTimeoutDet(gun_index, Timeout_EvseCompleteDet);
+						ChangeStartOrStopDateTime(NO, gun_index);
+					}
+
+					//if(chargingInfo[gun_index]->ConnectorPlugIn == NO &&
+					if(GetTimeoutValue(chargingInfo[gun_index]->TimeoutTimer) >= 10000000)
+					{
+						setChargerMode(gun_index, MODE_IDLE);
+					}
+
+					if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index)
+						ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_COMPLETE;
+				}
+					break;
+/*
+				case S_CCS_PRECHARGE_ST0:
+				{
+					if (isModeChange(gun_index))
+					{
+						PRINTF_FUNC("CCS Precharge Processing 1....................%x \n", gun_index);
+						StopGunInfoTimeoutDet(gun_index);
+						StartGunInfoTimeoutDet(gun_index, Timeout_ForCcsPrechargeDet);
+					}
+
+					if (chargingInfo[gun_index]->GroundFaultStatus == GFD_FAIL)
+					{
+						// GFD 錯誤停止
+						RecordAlarmCode(gun_index, "012235");
+					}
+
+					if (isEvBoardStopChargeFlag(gun_index) == YES)
+					{
+						// 板端要求停止
+						ChargingTerminalProcess(gun_index);
+					}
+
+					// 等待 EV 小板 (CCS) 通知可以開始 Precharge
+					// 切換 D+ Relay to Precharge Relay
+					if (isPrechargeStatus_ccs(gun_index) == 39 || isPrechargeStatus_ccs(gun_index) == 40)
+					{
+						if (chargingInfo[gun_index]->RelayKPK2Status == YES && chargingInfo[gun_index]->PrechargeStatus != PRECHARGE_READY)
+						//if (chargingInfo[gun_index]->PrechargeStatus != PRECHARGE_PRERELAY_PASS)
+						{
+							PRINTF_FUNC("Send precharge ready 1..........%x, status = %d \n", gun_index, isPrechargeStatus_ccs(gun_index));
+							chargingInfo[gun_index]->PrechargeStatus = PRECHARGE_READY;
+						}
+					}
+					else if (isPrechargeStatus_ccs(gun_index) == 45 || isPrechargeStatus_ccs(gun_index) == 46)
+					{
+						setChargerMode(gun_index, MODE_CCS_PRECHARGE_STEP1);
+					}
+
+					break;
+				}
+				case S_CCS_PRECHARGE_ST1:
+				{
+					if (isModeChange(gun_index))
+					{
+						PRINTF_FUNC("CCS Precharge Processing 2....................%x \n", gun_index);
+					}
+
+					if (chargingInfo[gun_index]->GroundFaultStatus == GFD_FAIL)
+					{
+						// GFD 錯誤停止
+						RecordAlarmCode(gun_index, "012235");
+					}
+
+					if (isEvBoardStopChargeFlag(gun_index) == YES)
+					{
+						// 板端要求停止
+						ChargingTerminalProcess(gun_index);
+					}
+
+					// 等待小板通知進入充電
+					// 切換 D+ Relay to Precharge Relay
+					if (chargingInfo[gun_index]->RelayK1K2Status == YES)
+					{
+						chargingInfo[gun_index]->PrechargeStatus = PRECHARGE_READY;
+						setChargerMode(gun_index, MODE_CHARGING);
+					}
+					break;
+				}
+*/
+			}
+		}
+
+		if (ShmSysConfigAndInfo->SysInfo.SystemPage != _LCM_NONE)
+		{
+			ChangeLcmByIndex(ShmSysConfigAndInfo->SysInfo.SystemPage);
+		}
+		else
+		{
+			bool dcPageRun = true;
+//			if (_acgunIndex > 0 && ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc != NO_DEFINE)
+//			{
+//				if  (ac_chargingInfo[0]->SystemStatus == S_IDLE)
+//					ChangeLcmByIndex(_LCM_IDLE);
+//				else if (ac_chargingInfo[0]->SystemStatus == S_PREPARNING)
+//					ChangeLcmByIndex(_LCM_PRE_CHARGE);
+//				else if (ac_chargingInfo[0]->SystemStatus == S_CHARGING)
+//					ChangeLcmByIndex(_LCM_CHARGING);
+//				else if (ac_chargingInfo[0]->SystemStatus == S_TERMINATING ||
+//						ac_chargingInfo[0]->SystemStatus == S_COMPLETE)
+//					ChangeLcmByIndex(_LCM_COMPLETE);
+//				else
+//					dcPageRun = true;
+//			}
+//			else
+//				dcPageRun = true;
+
+			if (dcPageRun)
+				ChangeLcmByIndex(ShmSysConfigAndInfo->SysInfo.ConnectorPage);
+		}
+
+		write(wtdFd, "a", 1);
+		usleep(whileLoopTime);
+	}
+
+	return FAIL;
+}

+ 64 - 21
EVSE/Projects/define.h

@@ -75,7 +75,7 @@ Storage							0x0A200000-0x7FFFFFFF		1886 MB
 #elif DS60120
 	#define MAX_PSU_QUANTITY        62
 	#define CHAdeMO_QUANTITY        2
-	#define CCS_QUANTITY           2
+	#define CCS_QUANTITY            2
 	#define GB_QUANTITY             2
 	#define AC_QUANTITY             1
     #define GENERAL_GUN_QUANTITY	0
@@ -445,9 +445,9 @@ struct ChargingInfoData
 	unsigned char		PreviousSystemStatus;		// 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault	
 	int 			ReservationId;
 	unsigned char 		IsAvailable;
-	float MaximumChargingVoltage;	//0~6553.5 volt
-	float AvailableChargingCurrent;	//0~6553.5 amp
-	float AvailableChargingPower;	//0~6553.5 kW
+	float MaximumChargingVoltage;	// unit 0.1V
+	float AvailableChargingCurrent;	// unit 0.1A
+	float AvailableChargingPower;	// unit .01kW
 	float DividChargingCurrent;		//0~6553.5 amp
 	float DeratingChargingCurrent;  //0~6553.5 amp
 	float DeratingChargingPower;	//0~6553.5 kW
@@ -517,6 +517,16 @@ struct ChargingInfoData
 	int 				EvBatteryStartSoc;				// 0~100%
 };
 
+typedef union
+{
+    unsigned int SettingValue;
+    struct
+    {
+        unsigned int AuthorizeRequest:1;        // 0: idle, 1: requesting
+        unsigned int res:31;
+    }bits;
+}DispenserSettingFlag;
+
 struct DispenserModule
 {
     unsigned char   LocalStatus;                // 0: None, 1: Identification, 2: Idle, 3: Alarm, 4: Charging, 5: _DS_Timeout
@@ -549,6 +559,10 @@ struct DispenserModule
     unsigned char   Connector1FwRev[32];        //Connector1 module firmware version
     unsigned char   Connector2FwRev[32];        //Connector2 module firmware version
     struct   LED    LedInfo;                    // LED configuration info
+
+                                                // 0: Authorize idle, 1: Authorize wait,   2: Authorizing
+    unsigned char           AuthorizeStatus;    // 3: Authorize ok,   4: Authorizing fail
+    DispenserSettingFlag    Setting;
 };
 
 struct ConnectionInfoData
@@ -569,14 +583,14 @@ struct DispenserInfoData
         unsigned char Status;
         struct
         {
-            unsigned char Dispenser1:1;             //1: ever checkin, 0: never checkin
-            unsigned char Dispenser2:1;             //1: ever checkin, 0: never checkin
-            unsigned char Dispenser3:1;             //1: ever checkin, 0: never checkin
-            unsigned char Dispenser4:1;             //1: ever checkin, 0: never checkin
-            unsigned char Dispenser5:1;             //1: ever checkin, 0: never checkin
-            unsigned char Dispenser6:1;             //1: ever checkin, 0: never checkin
-            unsigned char Dispenser7:1;             //1: ever checkin, 0: never checkin
-            unsigned char Dispenser8:1;             //1: ever checkin, 0: never checkin
+            unsigned char Dispenser1:1;             // 1: ever checkin, 0: never checkin
+            unsigned char Dispenser2:1;             // 1: ever checkin, 0: never checkin
+            unsigned char Dispenser3:1;             // 1: ever checkin, 0: never checkin
+            unsigned char Dispenser4:1;             // 1: ever checkin, 0: never checkin
+            unsigned char Dispenser5:1;             // 1: ever checkin, 0: never checkin
+            unsigned char Dispenser6:1;             // 1: ever checkin, 0: never checkin
+            unsigned char Dispenser7:1;             // 1: ever checkin, 0: never checkin
+            unsigned char Dispenser8:1;             // 1: ever checkin, 0: never checkin
         }Flag;
     }CheckInLog;                                                        // record dispenser checkin status
     unsigned char               ConnectorLog[GENERAL_GUN_QUANTITY];     // record connector quantity of dispenser
@@ -592,15 +606,43 @@ struct WARNING_CODE_INFO
     unsigned char ExtraErrProcess;                      // 0 : none, 1 : input uvp..
 };
 
+typedef union
+{
+    unsigned int Value;
+    struct
+    {
+        unsigned int  AuthorizeRequestType:4;           // 0: not authorize, 1: local authorized, 2: remote start authorized
+        unsigned int  PermissionRequest:1;              // 0: no request,    1: dispenser request to charging
+        unsigned int  res:27;
+    }bits;
+}ConnectorParameter;
+
 struct ConnectorInfoData
 {
     unsigned char RemoteStatus;                         // 0: Idle, 1: Preparing, 2: Charging, 3: Terminating
     unsigned char Enable;                               // 0: Disable, 1: Enable
     unsigned char ReadyToCharge;                        // 0: Not Ready, 1: Ready to Charge
-    struct ChargingInfoData GeneralChargingData;
+    unsigned char ParentDispensetIndex;                 // Parent Dispenser Index: 0 ~ 3
+    ConnectorParameter       Parameter;
+                                                        // 0: Authorize idle, 1: Authorize wait,   2: Authorizing
+    unsigned char            AuthorizeStatus;           // 3: Authorize ok,   4: Authorizing fail
+    struct ChargingInfoData  GeneralChargingData;
     struct WARNING_CODE_INFO WarningInfo;
 };
 
+typedef union
+{
+    unsigned int SettingValue;
+    struct
+    {
+        unsigned int StartAuthorize:1;          // 0: idle,    1: authorizing
+        unsigned int AuthorizingCompleted:1;    // 0: not yet, 1: authorizing completed
+        unsigned int AuthorizeTargetIndex:4;    // dispenser or connector index from 0 ~ 3
+        unsigned int AuthorizeSrc:4;            // 0: not authorize, 1: local authorize, 2: remote authorize
+        unsigned int res:22;
+    }bits;
+}CabinetSettingFlag;
+
 struct SysInfoData
 {
 	/**************System***************/
@@ -683,6 +725,7 @@ struct SysInfoData
     unsigned char Relay2ModuleFwRev[32];	//Relay control  module firmware version
     struct DispenserInfoData DispenserInfo;
     struct ConnectorInfoData ConnectorInfo[GENERAL_GUN_QUANTITY];
+    CabinetSettingFlag       CabinetSetting;
 };
 
 struct SysConfigAndInfo
@@ -3490,14 +3533,14 @@ struct PrimaryMcuData
 		struct
 		{
 			//OutputDrvValue[0]
-		    unsigned char AcContactorDrv:1;						//bit 0,	H: ON, 		L:OFF
-			unsigned char Button1LedDrv:1;						//bit 1,	H: ON, 		L:OFF
-			unsigned char Button2LedDrv:1; 						//bit 2,	H: ON, 		L:OFF
-			unsigned char SystemLed1Drv:1;						//bit 3,	H: ON, 		L:OFF
-			unsigned char SystemLed2Drv:1;						//bit 4,	H: ON, 		L:OFF
-			unsigned char SystemLed3Drv:1;						//bit 5,	H: ON, 		L:OFF
-			unsigned char SystemLed4Drv:1;						//bit 6,	H: ON, 		L:OFF
-			unsigned char:1;									//bit 7 reserved
+			unsigned char OnButtonLedDrv:1;                     //bit 0,    H: ON,      L:OFF
+			unsigned char OffButtonLedDrv:1;                    //bit 1,    H: ON,      L:OFF
+			unsigned char SystemLed1Drv:1;                      //bit 2,    H: ON,      L:OFF
+			unsigned char SystemLed2Drv:1;                      //bit 3,    H: ON,      L:OFF
+			unsigned char SystemLed3Drv:1;                      //bit 4,    H: ON,      L:OFF
+			unsigned char SystemLed4Drv:1;                      //bit 5,    H: ON,      L:OFF
+			unsigned char AcContactorDrv:1;                     //bit 6,    H: ON,      L:OFF
+			unsigned char:1;                                    //bit 7 reserved
 		}bits;
 	}OutputDrv;
 	union

برخی فایل ها در این مقایسه diff نمایش داده نمی شوند زیرا تعداد فایل ها بسیار زیاد است