浏览代码

2020.06.01 / TC Hsu

Actions: Copy DM30 ver D5.14 application files to DW30 application folder

Image version    : N/A
Image checksum   : N/A

Hardware PWB P/N : N/A
Hardware Version : N/A

Files:

	modified:   EVSE/Projects/DW30/Apps/Config.h
	modified:   EVSE/Projects/DW30/Apps/Ev_Comm.c
	modified:   EVSE/Projects/DW30/Apps/FactoryConfig.c
	modified:   EVSE/Projects/DW30/Apps/Module_EvComm.c
	modified:   EVSE/Projects/DW30/Apps/Module_EvComm.h
	modified:   EVSE/Projects/DW30/Apps/Module_EventLogging.c
	modified:   EVSE/Projects/DW30/Apps/Module_InternalComm.c
	deleted:    EVSE/Projects/DW30/Apps/Module_LcmContro.h
	modified:   EVSE/Projects/DW30/Apps/Module_LcmControl.c
	new file:   EVSE/Projects/DW30/Apps/Module_LcmControl.h
	modified:   EVSE/Projects/DW30/Apps/Module_PrimaryComm.c
	modified:   EVSE/Projects/DW30/Apps/Module_PsuComm.c
	modified:   EVSE/Projects/DW30/Apps/Module_PsuComm.h
	modified:   EVSE/Projects/DW30/Apps/PrimaryComm.c
	modified:   EVSE/Projects/DW30/Apps/PrimaryComm.h
	modified:   EVSE/Projects/DW30/Apps/ReadCmdline.c
	modified:   EVSE/Projects/DW30/Apps/init.sh
	modified:   EVSE/Projects/DW30/Apps/internalComm.c
	modified:   EVSE/Projects/DW30/Apps/internalComm.h
	modified:   EVSE/Projects/DW30/Apps/kill.sh
	modified:   EVSE/Projects/DW30/Apps/main.c
	modified:   EVSE/Projects/DW30/Apps/timeout.c
	modified:   EVSE/Projects/DW30/Apps/timeout.h
	new file:   EVSE/Projects/DW30/Apps/web.sh
TC_Hsu 4 年之前
父节点
当前提交
70bc72b5b9

+ 169 - 165
EVSE/Projects/DW30/Apps/Config.h

@@ -1,165 +1,169 @@
-/*
- * Config.h
- *
- *  Created on: 2019年4月23日
- *      Author: foluswen
- */
-#ifndef CONFIG_H_
-#define CONFIG_H_
-
-typedef unsigned char			byte;
-
-#define TOTAL_QUANTITY_GUN			4				//Max Count
-
-#ifdef DEBUG_OPTION
-    #if (DEBUG_OPTION == 1)
-        #define DEBUG               1
-    #else
-        #define DEBUG               0
-    #endif
-#else
-    #define DEBUG                   0
-#endif
-
-#define MODE_BOOT					0
-#define MODE_IDLE					1
-#define MODE_AUTHORIZING			2
-#define MODE_REASSIGN_CHECK			3
-#define MODE_REASSIGN				4
-#define MODE_PRECHARGE				5
-#define MODE_PREPARE_FOR_EV			6
-#define MODE_PREPARE_FOR_EVSE		7
-#define MODE_CHARGING				8
-#define MODE_TERMINATING			9
-#define MODE_COMPLETE				10
-#define MODE_ALARM					11
-#define MODE_FAULT					12
-#define MODE_RESERVATION			13
-#define MODE_BOOKING				14
-#define MODE_MAINTAIN				15
-#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 GFD_WAIT			0
-#define GFD_PASS			1
-#define GFD_FAIL			2
-#define GFD_WARNING			3
-
-#define PRECHARGE_WAIT				0
-#define PRECHARGE_READY				1
-#define PRECHARGE_PRERELAY_PASS		2
-#define PRECHARGE_CHARELAY_PASS		3
-
-#define BOOTTING			0
-#define BOOT_COMPLETE		1
-
-enum _SYSTEM_STATUS
-{
-	S_BOOTING = 						0,
-    S_IDLE,
-	S_AUTHORIZING,
-	S_REASSIGN_CHECK,
-	S_REASSIGN,
-	S_PREPARNING,
-	S_PREPARING_FOR_EV,
-	S_PREPARING_FOR_EVSE,
-    S_CHARGING,
-	S_TERMINATING,
-	S_COMPLETE,
-	S_ALARM,
-	S_FAULT,
-	S_RESERVATION,
-	S_BOOKING,
-	S_MAINTAIN,
-	S_DEBUG,
-	S_CCS_PRECHARGE_ST0,
-	S_CCS_PRECHARGE_ST1,
-	S_SINGLE_RUN,
-	S_NONE,
-};
-
-enum _GUN_TYPE
-{
-	_Type_Chademo = 		0,
-	_Type_CCS_2,
-	_Type_GB,
-
-};
-
-enum _LCM_INDEX
-{
-	_LCM_INIT = 			0x00,
-	_LCM_IDLE = 			0x01,
-	_LCM_AUTHORIZING = 		0x04,
-	_LCM_AUTHORIZ_COMP = 	0x05,
-	_LCM_AUTHORIZ_FAIL = 	0x06,
-	_LCM_WAIT_FOR_PLUG = 	0x07,
-	_LCM_PRE_CHARGE = 		0x08,
-	_LCM_CHARGING = 		0x09,
-	_LCM_COMPLETE = 		0x0A,
-	_LCM_FIX = 				0x0B,
-	_LCM_NONE = 			0xFF,
-};
-
-enum _SELF_TEST_SEQ
-{
-	_STEST_VERSION = 0x00,
-	_STEST_AC_CONTACTOR = 0x01,
-	_STEST_PSU_DETECT = 0x02,
-	_STEST_PSU_CAP = 0x03,
-	_STEST_FAIL = 0x04,
-	_STEST_COMPLETE = 0xFE,
-};
-
-enum _MODULE_PSU_WORK_STEP
-{
-	ASSIGN_START 	= 			0,
-	ASSIGN_COMP 	= 			1,
-	ENABLE_POW		=			2,
-	_TEST_LINE_STEP 	= 		3,
-	_TEST_POWER_STEP 	= 		4,
-	_TEST_COMPLETE 		= 		5,
-
-	_WORK_CHARGING 	= 			10,
-
-	_NO_WORKING			= 		254,
-	_INIT_PSU_STATUS	= 		255
-};
-
-enum _OFFLINE_POLICY
-{
-	_OFFLINE_POLICY_LOCAL_LIST = 0x00,
-	_OFFLINE_POLICY_PHIHONG_RFID_TAG = 0x01,
-	_OFFLINE_POLICY_FREE_CHARGING = 0x02,
-	_OFFLINE_POLICY_NO_CHARGING = 0x03,
-};
-
-enum _SYS_AUTHORIZE_MODE
-{
-	_SYS_AUTHORIZE_OCPP = 0x00,
-	_SYS_AUTHORIZE_FREE = 0x01
-};
-
-enum _REASSIGNED_RESOURCE_STEP
-{
-	_REASSIGNED_NONE = 			0,	//
-	_REASSIGNED_PREPARE = 		1,	// 系統收到需要降載需求 (輸出總電流降低),PSU Task 收到將狀態切換至下個狀態
-	_REASSIGNED_GET_NEW_CAP = 	2,	// 充電中的重新取得屬於自己火線上的總能量並透過小板通知車端 - 超過10秒直接跳下一步
-	_REASSIGNED_MAIN = 			3,  // 重新分配 PSU
-	_REASSIGNED_ADJUST = 		4,	// 模塊重新分配完成
-	_REASSIGNED_RELAY = 		5,	// 切斷橋接的 Relay
-	_REASSIGNED_COMP = 			6,	// 完成
-	_REASSIGNED_M_RELAY = 		7,	// 搭接橋接的 Relay
-	_REASSIGNED_M_MAIN = 		8,	// 重新分配 PSU (最大充)
-	_REASSIGNED_M_GET_NEW_CAP = 9	// 取得新的 CAP 並通知車端
-};
-
-enum _MAIN_CHARGING_MODE
-{
-	_MAIN_CHARGING_MODE_MAX = 0,
-	_MAIN_CHARGING_MODE_AVER = 1,
-};
-
-#endif /* CONFIG_H_ */
+/*
+ * Config.h
+ *
+ *  Created on: 2019年4月23日
+ *      Author: foluswen
+ */
+#ifndef CONFIG_H_
+#define CONFIG_H_
+
+typedef unsigned char           byte;
+
+#define TOTAL_QUANTITY_GUN          4   //Max Count
+
+#define MODE_BOOT                   0
+#define MODE_IDLE                   1
+#define MODE_AUTHORIZING            2
+#define MODE_REASSIGN_CHECK         3
+#define MODE_REASSIGN               4
+#define MODE_PRECHARGE              5
+#define MODE_PREPARE_FOR_EV         6
+#define MODE_PREPARE_FOR_EVSE       7
+#define MODE_CHARGING               8
+#define MODE_TERMINATING            9
+#define MODE_COMPLETE               10
+#define MODE_ALARM                  11
+#define MODE_FAULT                  12
+#define MODE_RESERVATION            13
+#define MODE_BOOKING                14
+#define MODE_MAINTAIN               15
+#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 GFD_WAIT                    0
+#define GFD_PASS                    1
+#define GFD_FAIL                    2
+#define GFD_WARNING                 3
+
+#define PRECHARGE_WAIT              0
+#define PRECHARGE_READY             1
+#define PRECHARGE_PRERELAY_PASS     2
+#define PRECHARGE_CHARELAY_PASS     3
+
+#define BOOTTING                    0
+#define BOOT_COMPLETE               1
+
+enum _SYSTEM_STATUS
+{
+    S_BOOTING                           = 0,
+    S_IDLE                              = 1,
+    S_AUTHORIZING                       = 2,
+    S_REASSIGN_CHECK                    = 3,
+    S_REASSIGN                          = 4,
+    S_PREPARNING                        = 5,
+    S_PREPARING_FOR_EV                  = 6,
+    S_PREPARING_FOR_EVSE                = 7,
+    S_CHARGING                          = 8,
+    S_TERMINATING                       = 9,
+    S_COMPLETE                          = 10,
+    S_ALARM                             = 11,
+    S_FAULT                             = 12,
+    S_RESERVATION                       = 13,
+    S_BOOKING                           = 14,
+    S_MAINTAIN                          = 15,
+    S_DEBUG                             = 16,
+    S_CCS_PRECHARGE_ST0                 = 17,
+    S_CCS_PRECHARGE_ST1                 = 18,
+    S_SINGLE_RUN                        = 19,
+    S_NONE                              = 20,
+};
+
+enum _AC_SYSTEM_STATUS
+{
+    AC_SYS_NONE                         = 0,
+    AC_SYS_A                            = 1,
+    AC_SYS_B                            = 2,
+    AC_SYS_C                            = 3,
+    AC_SYS_D                            = 4,
+    AC_SYS_E                            = 5,
+};
+
+enum _GUN_TYPE
+{
+    _Type_Chademo                       = 0,
+    _Type_CCS_2                         = 1,
+    _Type_GB                            = 2,
+    _Type_AC                            = 3,
+};
+
+enum _LCM_INDEX
+{
+    _LCM_INIT                           = 0x00,
+    _LCM_IDLE                           = 0x01,
+    _LCM_AUTHORIZING                    = 0x02,
+    _LCM_AUTHORIZ_COMP                  = 0x03,
+    _LCM_AUTHORIZ_FAIL                  = 0x04,
+    _LCM_WAIT_FOR_PLUG                  = 0x05,
+    _LCM_PRE_CHARGE                     = 0x06,
+    _LCM_CHARGING                       = 0x07,
+    _LCM_COMPLETE                       = 0x08,
+    _LCM_FIX                            = 0x09,
+    _LCM_NONE                           = 0xFF,
+};
+
+enum _SELF_TEST_SEQ
+{
+    _STEST_VERSION                      = 0x00,
+    _STEST_AC_CONTACTOR                 = 0x01,
+    _STEST_PSU_DETECT                   = 0x02,
+    _STEST_PSU_CAP                      = 0x03,
+    _STEST_FAIL                         = 0x04,
+    _STEST_COMPLETE                     = 0xEE,
+};
+
+enum _MODULE_PSU_WORK_STEP
+{
+    INITIAL_START                       = 0,
+    GET_PSU_COUNT                       = 1,
+    GET_SYS_CAP                         = 2,
+    BOOTING_COMPLETE                    = 3,
+    _WORK_CHARGING                      = 10,
+    _NO_WORKING                         = 254,
+    _INIT_PSU_STATUS                    = 255,
+};
+
+enum _OFFLINE_POLICY
+{
+    _OFFLINE_POLICY_LOCAL_LIST          = 0x00,
+    _OFFLINE_POLICY_PHIHONG_RFID_TAG    = 0x01,
+    _OFFLINE_POLICY_FREE_CHARGING       = 0x02,
+    _OFFLINE_POLICY_NO_CHARGING         = 0x03,
+};
+
+enum _REASSIGNED_RESOURCE_STEP
+{
+    _REASSIGNED_NONE                    = 0,  //
+    _REASSIGNED_PREPARE_M_TO_A          = 1,  // 系統收到需要降載需求 (輸出總電流降低),PSU Task 收到將狀態切換至下個狀態
+    _REASSIGNED_GET_NEW_CAP             = 2,  // 充電中的重新取得屬於自己火線上的總能量並透過小板通知車端 - 超過10秒直接跳下一步
+    _REASSIGNED_ADJUST_M_TO_A           = 3,  // 模塊重新分配完成
+    _REASSIGNED_RELAY_M_TO_A            = 4,  // 切斷橋接的 Relay
+
+    _REASSIGNED_PREPARE_A_TO_M          = 11,
+    _REASSIGNED_ADJUST_A_TO_M           = 12, // 模塊升壓
+    _REASSIGNED_RELAY_A_TO_M            = 13, // 搭接橋接的 Relay
+    _REASSIGNED_WAITING                 = 14,
+    _REASSIGNED_COMP                    = 15,
+};
+
+enum _MAIN_CHARGING_MODE
+{
+    _MAIN_CHARGING_MODE_MAX             = 0,
+    _MAIN_CHARGING_MODE_AVER            = 1,
+};
+
+enum _EXTRA_ERR_PROCESS
+{
+    _EXTRA_ERR_PROCESS_NONE             = 0,
+    _EXTRA_ERR_PROCESS_INUVP            = 1,
+    _EXTRA_ERR_PROCESS_INOVP            = 2,
+};
+
+enum _CHARGER_TYPE
+{
+    _CHARGER_TYPE_IEC                   = 0,
+    _CHARGER_TYPE_UL                    = 1,
+};
+
+#endif /* CONFIG_H_ */

+ 195 - 175
EVSE/Projects/DW30/Apps/Ev_Comm.c

@@ -1,175 +1,195 @@
-#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*/
-
-//================================================
-//================================================
-// 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 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] = 0xff;
-
-	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 toId)
-{
-	int id = PackageIdCmd(Ev_Cmd.get_miscellaneous_info + toId);
-	byte data[8];
-
-	SendCmdToEvboard(id, data, 0);
-}
-
-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);
-}
-
+#include "Module_EvComm.h"
+#include <linux/can.h>
+#include <linux/can/raw.h>
+#include <string.h>
+#include <stdio.h>      /*讓呎コ冶シク蜈・霈ク蜃コ螳夂セゥ*/
+#include <stdlib.h>     /*讓呎コ門�謨ク蠎ォ螳夂セゥ*/
+#include <unistd.h>     /*Unix 讓呎コ門�謨ク螳夂セゥ*/
+#include <fcntl.h>      /*讙疲而蛻カ螳夂セゥ*/
+#include <termios.h>    /*PPSIX 邨らォッ謗ァ蛻カ螳夂セゥ*/
+#include <errno.h>      /*骭ッ隱、陌溷ョ夂セゥ*/
+
+//================================================
+//================================================
+// 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] = 0xff;
+
+    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);
+}

+ 314 - 313
EVSE/Projects/DW30/Apps/FactoryConfig.c

@@ -1,313 +1,314 @@
-#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 	"Config.h"
-
-#define Debug
-#define ARRAY_SIZE(A)		(sizeof(A) / sizeof(A[0]))
-#define PASS				1
-#define FAIL				-1
-#define OUTPUT_FLASH		0x01
-#define OUTPUT_FILE			0x02
-
-struct SysConfigData 			SysConfig;
-
-int StoreLogMsg(const char *fmt, ...);
-
-int StoreLogMsg(const char *fmt, ...)
-{
-	char Buf[4096+256];
-	char buffer[4096];
-	time_t CurrentTime;
-	struct tm *tm;
-	va_list args;
-
-	va_start(args, fmt);
-	int rc = vsnprintf(buffer, sizeof(buffer), fmt, args);
-	va_end(args);
-
-	memset(Buf,0,sizeof(Buf));
-	CurrentTime = time(NULL);
-	tm=localtime(&CurrentTime);
-	sprintf(Buf,"echo \"%04d-%02d-%02d %02d:%02d:%02d - %s\" >> /Storage/SystemLog/[%04d.%02d]SystemLog",
-			tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,
-			buffer,
-			tm->tm_year+1900,tm->tm_mon+1);
-	system(Buf);
-
-	return rc;
-}
-
-void helpOutput(void)
-{
-	printf("Usage: Module_FactoryConfig [OPTION]...\r\n\r\n");
-	printf("Generate factory default configuration value\r\n\r\n");
-	printf("OPTION:\r\n");
-	printf("	-a Write to file(/mnt) & flash\r\n");
-	printf("	-f Write to file(/mnt)\r\n");
-	printf("	-m Write to flash\r\n");
-}
-
-/**************************************************************************************/
-/************This task will create Factory default confgiuration file *****************/
- /***********and store it into mtdblock 10,11,12                               ****************/
-/**************************************************************************************/
-int main(int argc,char *argv[])
-{
-	unsigned char outType=0;
-	unsigned int i,Chk, MtdBlockSize=0x600000;
-	unsigned char *ptr;
-	int fd,wrd;
-
-	ptr=malloc(MtdBlockSize);
-	if(ptr==NULL)
-	{
-		#ifdef SystemLogMessage
-		StoreLogMsg("[FactoryConfig]main: malloc for SysConfigData NG");
-		#endif
-		return 0;
-	}
-	memset(ptr, 0, MtdBlockSize);
-	memset(&SysConfig, 0, sizeof(struct SysConfigData));
-
-	/*
-	 * TODO: Set factory default configuration
-	*/
-	//********** System **********// udhcpc -i eth1 -s ./dhcp_script/eth1.script
-	//
-	strcpy((char *)SysConfig.ModelName, "DWYE301J0EW2PH");
-	strcpy((char *)SysConfig.SerialNumber, "");
-
-	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, "");
-	SysConfig.AuthorisationMode = _SYS_AUTHORIZE_OCPP;
-	SysConfig.DefaultLanguage = 0;
-	SysConfig.RfidCardNumEndian = 0;
-	SysConfig.AcPlugInTimes = 0;
-	SysConfig.GbPlugInTimes = 0;
-	SysConfig.Ccs1PlugInTime = 0;
-	SysConfig.Ccs2PlugInTimes = 0;
-	SysConfig.ChademoPlugInTimes = 0;
-	//********** Charging **********//
-	SysConfig.RatingCurrent = 600;			// 最大可輸出電流 120 A
-	SysConfig.MaxChargingEnergy = 0;
-	SysConfig.MaxChargingPower = 300; 		// 最大功率 : 跟著 model name 跑
-	SysConfig.MaxChargingCurrent = 600;		// 最大可輸出電流 120 A
-	SysConfig.MaxChargingDuration = 0;
-	SysConfig.PhaseLossPolicy = 0;
-	for(unsigned char i = 0; i < 10; i++)
-		strcpy((char *)SysConfig.LocalWhiteCard, "");
-
-	strcpy((char *)SysConfig.UserId, "");
-	//********** Network **********//
-	strcpy((char *)SysConfig.FtpServer, "");
-	SysConfig.Eth0Interface.EthDhcpClient = 0;
-	strcpy((char *) SysConfig.Eth0Interface.EthMacAddress, "AA:BB:CC:DD:EE:FF");
-	strcpy((char *) SysConfig.Eth0Interface.EthIpAddress, "192.168.1.10");
-	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.EthMacAddress, "AA:BB:CC:DD:EE:FF");
-	strcpy((char *) SysConfig.Eth1Interface.EthIpAddress, "192.168.0.10");
-	strcpy((char *) SysConfig.Eth1Interface.EthSubmaskAddress, "255.255.255.0");
-	strcpy((char *) SysConfig.Eth1Interface.EthGatewayAddress, "192.168.0.254");
-	SysConfig.AthInterface.WifiMode = 0;
-	strcpy((char *) SysConfig.AthInterface.WifiSsid, "");
-	strcpy((char *) SysConfig.AthInterface.WifiPassword, "");
-	SysConfig.AthInterface.WifiRssi = 0;
-	SysConfig.AthInterface.WifiDhcpServer = 0;
-	SysConfig.AthInterface.WifiDhcpClient = 0;
-	strcpy((char *) SysConfig.AthInterface.WifiMacAddress, "");
-	strcpy((char *) SysConfig.AthInterface.WifiIpAddress, "");
-	strcpy((char *) SysConfig.AthInterface.WifiSubmaskAddress, "");
-	strcpy((char *) SysConfig.AthInterface.WifiGatewayAddress, "");
-	SysConfig.AthInterface.WifiNetworkConn = 0;
-	strcpy((char *) SysConfig.TelecomInterface.TelcomModelName, "");
-	strcpy((char *) SysConfig.TelecomInterface.TelcomSoftwareVer, "");
-	strcpy((char *) SysConfig.TelecomInterface.TelcomApn, "Internet");
-	SysConfig.TelecomInterface.TelcomRssi = 0;
-	strcpy((char *) SysConfig.TelecomInterface.TelcomChapPapId, " ");
-	strcpy((char *) SysConfig.TelecomInterface.TelcomChapPapPwd, " ");
-	strcpy((char *) SysConfig.TelecomInterface.TelcomModemImei, "");
-	strcpy((char *) SysConfig.TelecomInterface.TelcomSimImsi, "");
-	strcpy((char *) SysConfig.TelecomInterface.TelcomSimIccid, "");
-	SysConfig.TelecomInterface.TelcomSimStatus = 0;
-	SysConfig.TelecomInterface.TelcomModemMode = 0;
-	strcpy((char *) SysConfig.TelecomInterface.TelcomIpAddress, "");
-	SysConfig.TelecomInterface.TelcomNetworkConn = 0;
-	strcpy((char *)SysConfig.chargePointVendor, "Phihong Technology");
-	//********** Backend **********//
-	SysConfig.BackendConnTimeout = 300; //300 seconds
-	SysConfig.OfflinePolicy = 0;
-	SysConfig.OfflineMaxChargeEnergy = 0;
-	SysConfig.OfflineMaxChargeDuration = 0;
-	strcpy((char *) SysConfig.OcppServerURL, "ws://test.evsocket.phihong.com.cn:2012/ocpp/");
-	strcpy((char *) SysConfig.ChargeBoxId, "DemoDC_Alston");
-
-	//copy default configuration to pointer
-	memcpy(ptr,&SysConfig,sizeof(struct SysConfigData));
-
-	//calculate CRC
-	Chk=0;
-	for(i=0;i<(MtdBlockSize-4);i++)
-	{
-		Chk+=*(ptr+i);
-	}
-	memcpy(	ptr+MtdBlockSize-4,&Chk,4);
-
-	/*
-	* Parameter process
-	*/
-	if (argc > 1)
-	{
-		char *arg = argv[1];
-		switch (arg[0])
-		{
-		case '-':
-			switch (arg[1])
-			{
-				case 'a':
-					outType |= OUTPUT_FILE;
-					outType |= OUTPUT_FLASH;
-					break;
-				case 'f':
-					outType |= OUTPUT_FILE;
-					break;
-				case 'm':
-					outType |= OUTPUT_FLASH;
-					break;
-				default:
-					helpOutput();
-					break;
-			}
-				break;
-			default:
-				helpOutput();
-				break;
-		}
-	}
-	else
-	{
-		helpOutput();
-	}
-
-	/*
-	 * Configuration bin file generate
-	*/
-	if((outType&OUTPUT_FILE)>0)
-	{
-		fd = open("/mnt/FactoryDefaultConfig.bin", O_RDWR | O_CREAT);
-		if (fd < 0)
-		{
-			StoreLogMsg("[FactoryConfig]main: open /mnt/FactoryDefaultConfig.bin NG");
-			free(ptr);
-			return 0;
-		}
-		wrd=write(fd, ptr, MtdBlockSize);
-		close(fd);
-		if(wrd<MtdBlockSize)
-		{
-			StoreLogMsg("write /mnt/FactoryDefaultConfig.bin NG\r\n");
-			free(ptr);
-			return 0;
-		}
-		StoreLogMsg("FactoryConfig write to file in /mnt OK.\r\n");
-	}
-
-	/*
-	* Flash memory write
-	*/
-	if((outType&OUTPUT_FLASH)>0)
-	{
-		// Save factory default setting value to flash factory default setting block
-		fd = open("/dev/mtdblock12", O_RDWR);
-		if (fd < 0)
-		{
-			StoreLogMsg("open /dev/mtdblock12 NG\r\n");
-			free(ptr);
-			return 0;
-		}
-		wrd=write(fd, ptr, MtdBlockSize);
-		close(fd);
-		if(wrd<MtdBlockSize)
-		{
-			StoreLogMsg("write /dev/mtdblock12 NG\r\n");
-			free(ptr);
-			return 0;
-		}
-
-		// Save factory default setting value to flash backup setting block
-		fd = open("/dev/mtdblock11", O_RDWR);
-		if (fd < 0)
-		{
-			StoreLogMsg("open /dev/mtdblock11 NG\r\n");
-			free(ptr);
-			return 0;
-		}
-		wrd=write(fd, ptr, MtdBlockSize);
-		close(fd);
-		if(wrd<MtdBlockSize)
-		{
-			StoreLogMsg("write /dev/mtdblock11 NG\r\n");
-			free(ptr);
-			return 0;
-		}
-
-		// Save factory default setting value to flash setting block
-		fd = open("/dev/mtdblock10", O_RDWR);
-		if (fd < 0)
-		{
-			StoreLogMsg("open /dev/mtdblock10 NG\r\n");
-			free(ptr);
-			return 0;
-		}
-		wrd=write(fd, ptr, MtdBlockSize);
-		close(fd);
-		if(wrd<MtdBlockSize)
-		{
-			StoreLogMsg("write /dev/mtdblock10 NG\r\n");
-			free(ptr);
-			return 0;
-		}
-		StoreLogMsg("FactoryConfig write to flash OK\r\n");
-	}
-
-	free(ptr);
-
-	return FAIL;
-}
-
+#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 "Config.h"
+
+#define Debug
+#define ARRAY_SIZE(A)       (sizeof(A) / sizeof(A[0]))
+#define PASS                1
+#define FAIL                -1
+#define OUTPUT_FLASH        0x01
+#define OUTPUT_FILE         0x02
+
+struct SysConfigData            SysConfig;
+
+int StoreLogMsg(const char *fmt, ...);
+
+int StoreLogMsg(const char *fmt, ...)
+{
+    char Buf[4096+256];
+    char buffer[4096];
+    time_t CurrentTime;
+    struct tm *tm;
+    va_list args;
+
+    va_start(args, fmt);
+    int rc = vsnprintf(buffer, sizeof(buffer), fmt, args);
+    va_end(args);
+
+    memset(Buf,0,sizeof(Buf));
+    CurrentTime = time(NULL);
+    tm=localtime(&CurrentTime);
+    sprintf(Buf,"echo \"%04d-%02d-%02d %02d:%02d:%02d - %s\" >> /Storage/SystemLog/[%04d.%02d]SystemLog",
+            tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,
+            buffer,
+            tm->tm_year+1900,tm->tm_mon+1);
+    system(Buf);
+
+    return rc;
+}
+
+void helpOutput(void)
+{
+    printf("Usage: Module_FactoryConfig [OPTION]...\r\n\r\n");
+    printf("Generate factory default configuration value\r\n\r\n");
+    printf("OPTION:\r\n");
+    printf("    -a Write to file(/mnt) & flash\r\n");
+    printf("    -f Write to file(/mnt)\r\n");
+    printf("    -m Write to flash\r\n");
+}
+
+/**************************************************************************************/
+/************This task will create Factory default confgiuration file *****************/
+/************and store it into mtdblock 10,11,12                       ****************/
+/**************************************************************************************/
+int main(int argc,char *argv[])
+{
+    unsigned char outType=0;
+    unsigned int i,Chk, MtdBlockSize=0x600000;
+    unsigned char *ptr;
+    int fd,wrd;
+
+    ptr=malloc(MtdBlockSize);
+    if(ptr==NULL)
+    {
+        #ifdef SystemLogMessage
+        StoreLogMsg("[FactoryConfig]main: malloc for SysConfigData NG");
+        #endif
+        return 0;
+    }
+    memset(ptr, 0, MtdBlockSize);
+    memset(&SysConfig, 0, sizeof(struct SysConfigData));
+
+    /*
+     * TODO: Set factory default configuration
+     */
+    //********** System **********// udhcpc -i eth1 -s ./dhcp_script/eth1.script
+    //
+    strcpy((char *)SysConfig.ModelName, "DMYE301E00W2PH");
+    strcpy((char *)SysConfig.SerialNumber, "");
+
+    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, "");
+    SysConfig.AuthorisationMode = AUTH_MODE_ENABLE;
+    SysConfig.DefaultLanguage = 0;
+    SysConfig.RfidCardNumEndian = 0;
+    SysConfig.AcPlugInTimes = 0;
+    SysConfig.GbPlugInTimes = 0;
+    SysConfig.Ccs1PlugInTime = 0;
+    SysConfig.Ccs2PlugInTimes = 0;
+    SysConfig.ChademoPlugInTimes = 0;
+    SysConfig.BillingData.isBilling = 0;
+    SysConfig.isAPP = 1;
+    SysConfig.isQRCode = 1;
+    SysConfig.isRFID = 1;
+    //********** Charging **********//
+    SysConfig.MaxChargingEnergy = 0;
+    SysConfig.MaxChargingCurrent = 60;      // ��憭批虾頛詨枂�餅�
+    SysConfig.MaxChargingDuration = 0;
+    SysConfig.AcMaxChargingCurrent = 0;
+    SysConfig.PhaseLossPolicy = LOSS_POLICY_STOP;
+    for(unsigned char i = 0; i < 10; i++)
+        strcpy((char *)SysConfig.LocalWhiteCard, "");
+
+    strcpy((char *)SysConfig.UserId, "");
+    //********** Network **********//
+    strcpy((char *)SysConfig.FtpServer, "");
+    SysConfig.Eth0Interface.EthDhcpClient = 0;
+    strcpy((char *) SysConfig.Eth0Interface.EthIpAddress, "192.168.1.10");
+    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.EthSubmaskAddress, "255.255.255.0");
+    strcpy((char *) SysConfig.Eth1Interface.EthGatewayAddress, "192.168.0.254");
+    SysConfig.AthInterface.WifiMode = 0;
+    strcpy((char *) SysConfig.AthInterface.WifiSsid, "");
+    strcpy((char *) SysConfig.AthInterface.WifiPassword, "");
+    SysConfig.AthInterface.WifiRssi = 0;
+    SysConfig.AthInterface.WifiDhcpServer = 0;
+    SysConfig.AthInterface.WifiDhcpClient = 0;
+    strcpy((char *) SysConfig.AthInterface.WifiMacAddress, "");
+    strcpy((char *) SysConfig.AthInterface.WifiIpAddress, "");
+    strcpy((char *) SysConfig.AthInterface.WifiSubmaskAddress, "");
+    strcpy((char *) SysConfig.AthInterface.WifiGatewayAddress, "");
+    SysConfig.AthInterface.WifiNetworkConn = 0;
+    strcpy((char *) SysConfig.TelecomInterface.TelcomModelName, "");
+    strcpy((char *) SysConfig.TelecomInterface.TelcomSoftwareVer, "");
+    //strcpy((char *) SysConfig.TelecomInterface.TelcomApn, "Internet");
+    strcpy((char *) SysConfig.TelecomInterface.TelcomApn, "");
+    SysConfig.TelecomInterface.TelcomRssi = 0;
+    strcpy((char *) SysConfig.TelecomInterface.TelcomChapPapId, " ");
+    strcpy((char *) SysConfig.TelecomInterface.TelcomChapPapPwd, " ");
+    strcpy((char *) SysConfig.TelecomInterface.TelcomModemImei, "");
+    strcpy((char *) SysConfig.TelecomInterface.TelcomSimImsi, "");
+    strcpy((char *) SysConfig.TelecomInterface.TelcomSimIccid, "");
+    SysConfig.TelecomInterface.TelcomSimStatus = 0;
+    SysConfig.TelecomInterface.TelcomModemMode = 0;
+    strcpy((char *) SysConfig.TelecomInterface.TelcomIpAddress, "");
+    SysConfig.TelecomInterface.TelcomNetworkConn = 0;
+    strcpy((char *)SysConfig.chargePointVendor, "Phihong Technology");
+    //********** Backend **********//
+    SysConfig.BackendConnTimeout = 300; //300 seconds
+    SysConfig.OfflinePolicy = OFF_POLICY_FREE;
+    SysConfig.OfflineMaxChargeEnergy = 0;
+    SysConfig.OfflineMaxChargeDuration = 0;
+    strcpy((char *) SysConfig.OcppServerURL, "");
+    strcpy((char *) SysConfig.ChargeBoxId, "");
+
+    //copy default configuration to pointer
+    memcpy(ptr,&SysConfig,sizeof(struct SysConfigData));
+
+    //calculate CRC
+    Chk=0;
+    for(i=0;i<(MtdBlockSize-4);i++)
+    {
+        Chk+=*(ptr+i);
+    }
+    memcpy( ptr+MtdBlockSize-4,&Chk,4);
+
+    /*
+     * Parameter process
+     */
+    if (argc > 1)
+    {
+        char *arg = argv[1];
+        switch (arg[0])
+        {
+        case '-':
+            switch (arg[1])
+            {
+                case 'a':
+                    outType |= OUTPUT_FILE;
+                    outType |= OUTPUT_FLASH;
+                    break;
+                case 'f':
+                    outType |= OUTPUT_FILE;
+                    break;
+                case 'm':
+                    outType |= OUTPUT_FLASH;
+                    break;
+                default:
+                    helpOutput();
+                    break;
+            }
+                break;
+            default:
+                helpOutput();
+                break;
+        }
+    }
+    else
+    {
+        helpOutput();
+    }
+
+    /*
+     * Configuration bin file generate
+     */
+    if((outType&OUTPUT_FILE)>0)
+    {
+        fd = open("/mnt/FactoryDefaultConfig.bin", O_RDWR | O_CREAT);
+        if (fd < 0)
+        {
+            StoreLogMsg("[FactoryConfig]main: open /mnt/FactoryDefaultConfig.bin NG");
+            free(ptr);
+            return 0;
+        }
+        wrd=write(fd, ptr, MtdBlockSize);
+        close(fd);
+        if(wrd<MtdBlockSize)
+        {
+            StoreLogMsg("write /mnt/FactoryDefaultConfig.bin NG\r\n");
+            free(ptr);
+            return 0;
+        }
+        StoreLogMsg("FactoryConfig write to file in /mnt OK.\r\n");
+    }
+
+    /*
+     * Flash memory write
+     */
+    if((outType&OUTPUT_FLASH)>0)
+    {
+        // Save factory default setting value to flash factory default setting block
+        fd = open("/dev/mtdblock12", O_RDWR);
+        if (fd < 0)
+        {
+            StoreLogMsg("open /dev/mtdblock12 NG\r\n");
+            free(ptr);
+            return 0;
+        }
+        wrd=write(fd, ptr, MtdBlockSize);
+        close(fd);
+        if(wrd<MtdBlockSize)
+        {
+            StoreLogMsg("write /dev/mtdblock12 NG\r\n");
+            free(ptr);
+            return 0;
+        }
+
+        // Save factory default setting value to flash backup setting block
+        fd = open("/dev/mtdblock11", O_RDWR);
+        if (fd < 0)
+        {
+            StoreLogMsg("open /dev/mtdblock11 NG\r\n");
+            free(ptr);
+            return 0;
+        }
+        wrd=write(fd, ptr, MtdBlockSize);
+        close(fd);
+        if(wrd<MtdBlockSize)
+        {
+            StoreLogMsg("write /dev/mtdblock11 NG\r\n");
+            free(ptr);
+            return 0;
+        }
+
+        // Save factory default setting value to flash setting block
+        fd = open("/dev/mtdblock10", O_RDWR);
+        if (fd < 0)
+        {
+            StoreLogMsg("open /dev/mtdblock10 NG\r\n");
+            free(ptr);
+            return 0;
+        }
+        wrd=write(fd, ptr, MtdBlockSize);
+        close(fd);
+        if(wrd<MtdBlockSize)
+        {
+            StoreLogMsg("write /dev/mtdblock10 NG\r\n");
+            free(ptr);
+            return 0;
+        }
+        StoreLogMsg("FactoryConfig write to flash OK\r\n");
+    }
+
+    free(ptr);
+
+    return FAIL;
+}

+ 3273 - 1232
EVSE/Projects/DW30/Apps/Module_EvComm.c

@@ -1,83 +1,92 @@
-#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
-
-struct SysConfigAndInfo			*ShmSysConfigAndInfo;
-struct StatusCodeData 			*ShmStatusCodeData;
-struct FanModuleData			*ShmFanModuleData;
-struct CHAdeMOData				*ShmCHAdeMOData;
-struct CcsData					*ShmCcsData;
-
-byte gun_count = CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY;
+#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];
 
-// 限制最大充電電壓,因應不同 type 槍線來限制
-// Chademo : 500V, CCS : 950V
-float maxChargingVol[2] = { 5000, 9500 };			// 限制最大充電電壓,如依照模塊則填上 0
-// 限制最大充電電流與能量透過 Web
-float maxChargingCur[2] = { 0, 0 };					// 限制最大充電電流,如依照模塊則填上 0
-float maxChargingPow = 0;							// 限制最大充電能量,如依照模塊則填上 0
+float _pow_1 = 0;
+float _cur_1 = 0;
+float _pow_2 = 0;
+float _cur_2 = 0;
 
-// 槍資訊
+// �𣂼���憭批��駁𤓖憯橒��䭾�銝滚� type 瑽滨�靘����
+// Chademo : 500V, GB : 750, CCS : 950V
+//TODO: change maximum charging voltage by connector type
+float maxChargingVol[2] = { 9500, 9500 };           // �𣂼���憭批��駁𤓖憯橒�憒���扳芋憛𠰴�憛思� 0
+// �𣂼���憭批��駁𤓖瘚���賡��誯� Web
+float maxChargingCur[2] = { 600, 600 };             // �𣂼���憭批��駁𤓖瘚��憒���扳芋憛𠰴�憛思� 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,
-		0x00001500,
+        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 };
@@ -94,58 +103,58 @@ unsigned long GetTimeoutValue(struct timeval _sour_time);
 
 unsigned long GetTimeoutValue(struct timeval _sour_time)
 {
-	struct timeval _end_time;
-	gettimeofday(&_end_time, NULL);
+    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;
+    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];
-	time_t CurrentTime;
-	struct tm *tm;
-	va_list args;
-
-	va_start(args, fmt);
-	int rc = vsnprintf(buffer, sizeof(buffer), fmt, args);
-	va_end(args);
-
-	memset(Buf,0,sizeof(Buf));
-	CurrentTime = time(NULL);
-	tm=localtime(&CurrentTime);
-	sprintf(Buf,"echo \"%04d-%02d-%02d %02d:%02d:%02d - %s\" >> /Storage/SystemLog/[%04d.%02d]SystemLog",
-			tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,
-			buffer,
-			tm->tm_year+1900,tm->tm_mon+1);
-	system(Buf);
-
-	return rc;
+    char Buf[4096+256];
+    char buffer[4096];
+    time_t CurrentTime;
+    struct tm *tm;
+    va_list args;
+
+    va_start(args, fmt);
+    int rc = vsnprintf(buffer, sizeof(buffer), fmt, args);
+    va_end(args);
+
+    memset(Buf,0,sizeof(Buf));
+    CurrentTime = time(NULL);
+    tm=localtime(&CurrentTime);
+    sprintf(Buf,"echo \"%04d-%02d-%02d %02d:%02d:%02d - %s\" >> /Storage/SystemLog/[%04d.%02d]SystemLog",
+            tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,
+            buffer,
+            tm->tm_year+1900,tm->tm_mon+1);
+    system(Buf);
+
+    return rc;
 }
 
 int DiffTimeb(struct timeb ST, struct timeb ET)
 {
-	//return milli-second
-	unsigned int StartTime,StopTime;
+    //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;
+    StartTime=(unsigned int)ST.time;
+    StopTime=(unsigned int)ET.time;
+    return (StopTime-StartTime)*1000+ET.millitm-ST.millitm;
 }
 
 void PRINTF_FUNC(char *string, ...)
 {
-	if (DEBUG)
-	{
-		va_list args;
-		char buffer[4096];
-
-		va_start(args, string);
-		vsnprintf(buffer, sizeof(buffer), string, args);
-		va_end(args);
-		printf("%s \n", buffer);
-	}
+    va_list args;
+    char buffer[4096];
+    va_start(args, string);
+    vsnprintf(buffer, sizeof(buffer), string, args);
+    va_end(args);
+
+    if (ShmSysConfigAndInfo->SysConfig.SwitchDebugFlag == YES)
+        printf("%s \n", buffer);
+    else
+        DEBUG_INFO("%s \n", buffer);
 }
 
 //=================================
@@ -153,37 +162,37 @@ void PRINTF_FUNC(char *string, ...)
 //=================================
 void getTimeString(char *buff)
 {
-	time_t timep;
-	struct tm *p;
-	time(&timep);
-	p=gmtime(&timep);
+    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);
+    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;
+    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;
 }
 
 //==========================================
@@ -191,83 +200,102 @@ bool CheckUniqNumber(byte value)
 //==========================================
 int InitShareMemory()
 {
-	int result = PASS;
-	int MeterSMId;
+    int result = PASS;
+    int MeterSMId;
 
-	//initial ShmSysConfigAndInfo
-	if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo),  0777)) < 0)
+    //initial ShmSysConfigAndInfo
+    if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo),  0777)) < 0)
     {
-		#ifdef SystemLogMessage
-		DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
-		#endif
-		result = FAIL;
-	}
+        #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;
-   	 }
+        #ifdef SystemLogMessage
+        DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
+        #endif
+        result = FAIL;
+     }
     else
     {}
 
-   	 //initial ShmStatusCodeData
-   	 if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData),  0777)) < 0)
+     //initial ShmStatusCodeData
+     if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData),  0777)) < 0)
     {
-		#ifdef SystemLogMessage
-   		DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
-		#endif
-   		result = FAIL;
-	}
+        #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;
-   	}
+        #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(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
-   		{}
-   	}
+    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;
 }
@@ -277,46 +305,46 @@ int InitShareMemory()
 //================================================
 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;
+    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;
 }
 
 //================================================
@@ -326,1059 +354,3072 @@ int InitCanBus()
 //================================================
 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;
+    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 (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);
-	}
+    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)
 {
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoEvCommFail = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.PilotFault = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBatteryMalfun = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoNoPermission = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBatteryIncompatibility = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBatteryOVP = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBatteryUVP = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBatteryOTP = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBatteryCurrentDiff = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBatteryVoltageDiff = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoShiftPosition = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBatteryOtherFault = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoChargingSystemError = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoEvNormalStop = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoTempSensorBroken = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoConnectorLockFail = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoD1OnNoReceive = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBmsKtoJTimeout = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBmsChargeAllowTimeout = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoWaitGfdTimeout = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBmsEvRelayTimeout = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBmsReqCurrentTimeout = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBmsKtoJOffTimeout = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBmsEvRelayOffTimeout = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoAdcMoreThan10V = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoAdcMoreThan20V = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBmsChargeBeforeStop = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoChargerGetNormalStop = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoChargerGetEmergencyStop = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoIsolationResultFail = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoMissLinkWithMotherBoard = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoOutputVolMoreThanLimit = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoReqCurrentMoreThanLimit = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoReCapBmsEqrCurrentExceed = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoChargeRemainCountDown = 0x00;
+    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)
 {
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsRESTemperatureInhibit = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsEVShiftPosition = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsChargerConnectorLockFault = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsEVRESSMalfunction = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsChargingCurrentdifferential = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsChargingVoltageOutOfRange = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsChargingSystemIncompatibility = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsEmergencyEvent = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsBreaker = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsNoData = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_DIN_A = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_DIN_B = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_DIN_C = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_ISO_1 = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_ISO_2 = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_ISO_3 = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_OEM_1 = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_OEM_2 = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_OEM_3 = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_OEM_4 = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_OEM_5 = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSequenceError = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSignatureError = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsUnknownSession = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsServiceIDInvalid = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsPaymentSelectionInvalid = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsIdentificationSelectionInvalid = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsServiceSelectionInvalid = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCertificateExpired = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCertificateNotYetValid = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCertificateRevoked = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsNoCertificateAvailable = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCertChainError = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCertValidationError = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCertVerificationError = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsContractCanceled = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsChallengeInvalid = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsWrongEnergyTransferMode = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsWrongChargeParameter = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsChargingProfileInvalid = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTariffSelectionInvalid = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsEVSEPresentVoltageToLow = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsPowerDeliveryNotApplied = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsMeteringSignatureNotValid = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsNoChargeServiceSelected = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsContactorError = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCertificateNotAllowedAtThisEVSE = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsGAChargeStop = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsAlignmentError = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsACDError = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsAssociationError = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsEVSEChargeAbort = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsNoSupportedAppProtocol = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsContractNotAccepted = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsMOUnknown = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsOEM_Prov_CertificateRevoke = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsOEM_SubCA1_CertificateRevoked = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsOEM_SubCA2_CertificateRevoked = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsOEM_RootCA_CertificateRevoked = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsMO_Prov_CertificateRevoked = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsMO_SubCA1_CertificateRevoked = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsMO_SubCA2_CertificateRevoked = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsMO_RootCA_CertificateRevoked = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCPS_Prov_CertificateRevoked = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCPS_SubCA1_CertificateRevoked = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCPS_SubCA2_CertificateRevoked = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCPS_RootCA_CertificateRevoked = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_EVSE_SLAC_init = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_match_response = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_match_sequence = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_EVSE_match_MNBC = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_EVSE_avg_atten_calc = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_match_response = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_EVSE_match_session = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_EVSE_assoc_session = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_EVSE_vald_toggle = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsUDP_TT_match_join = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTCP_TT_match_join = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_amp_map_exchange = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_link_ready_notification = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSupportedAppProtocolRes = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSessionSetupRes = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsServiceDiscoveryRes = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsServicePaymentSelectionRes = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsContractAuthenticationRes = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsChargeParameterDiscoveryRes = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsPowerDeliveryRes = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCableCheckRes = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsPreChargeRes = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCurrentDemandRes = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsWeldingDetectionRes = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSessionStopRes = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSequence_Time = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsReadyToCharge_Performance_Time = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCommunicationSetup_Performance_Time = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCableCheck_Performance_Time = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCPState_Detection_Time = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCPOscillator_Retain_Time = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_GET_EV_TARGET_INFO = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_GET_EV_TARGET_INFO = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_GET_EV_BATTERY_INFO = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_GET_EV_BATTERY_INFO = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_EV_STOP_EVENT = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_EV_STOP_EVENT = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_EVSE_STOP_EVENT = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_EVSE_STOP_EVENT = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_GET_MISC_INFO = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_GET_MISC_INFO = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_DOWNLOAD_REQUEST = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_DOWNLOAD_REQUEST = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_START_BLOCK_TRANSFER = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_START_BLOCK_TRANSFER = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_DATA_TRANSFER = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_DATA_TRANSFER = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_DOWNLOAD_FINISH = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_DOWNLOAD_FINISH = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_ISOLATION_STATUS = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_ISOLATION_STATUS = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_CONNECTOR_INFO = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_CONNECTOR_INFO = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_RTC_INFO = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_RTC_INFO = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_EVSE_PRECHARGE_INFO = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_EVSE_PRECHARGE_INFO = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsMSG_Sequence = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCAN_MSG_Unrecognized_CMD_ID = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsDIN_Msg_Decode_Error = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsDIN_Msg_Encode_Error = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsISO1_Msg_Decode_Error = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsISO1_Msg_Encode_Error = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsISO2_Msg_Decode_Error = 0x00;
-	ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsISO2_Msg_Encode_Error = 0x00;
+    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, "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;
+    }
+
+    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, "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;
+                }
+            }
+        }
+    }
 }
 
 void AbnormalStopAnalysis(byte gun_index, byte *errCode)
 {
-	char string[7];
-	sprintf(string, "%d%d%d%d%d%d", *(errCode + 5), *(errCode + 4), *(errCode + 3), *(errCode + 2), *(errCode + 1), *(errCode + 0));
-
-	PRINTF_FUNC("NOTIFICATION_EV_STOP : Err Code = %s \n", string);
-
-	if (strcmp(string, "023700") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoEvCommFail = 0x01;
-	if (strcmp(string, "023701") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsEvCommFail = 0x01;
-	if (strcmp(string, "023702") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.GbEvCommFail = 0x01;
-	if (strcmp(string, "023703") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.PilotFault = 0x01;
-	if (strcmp(string, "023704") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBatteryMalfun = 0x01;
-	if (strcmp(string, "023705") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoNoPermission = 0x01;
-	if (strcmp(string, "023706") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBatteryIncompatibility = 0x01;
-	if (strcmp(string, "023707") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBatteryOVP = 0x01;
-	if (strcmp(string, "023708") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBatteryUVP = 0x01;
-	if (strcmp(string, "023709") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBatteryOTP = 0x01;
-	if (strcmp(string, "023710") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBatteryCurrentDiff = 0x01;
-	if (strcmp(string, "023711") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBatteryVoltageDiff = 0x01;
-	if (strcmp(string, "023712") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoShiftPosition = 0x01;
-	if (strcmp(string, "023713") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBatteryOtherFault = 0x01;
-	if (strcmp(string, "023714") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoChargingSystemError = 0x01;
-	if (strcmp(string, "023715") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoEvNormalStop = 0x01;
-	if (strcmp(string, "023716") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoTempSensorBroken = 0x01;
-	if (strcmp(string, "023717") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoConnectorLockFail = 0x01;
-	if (strcmp(string, "023718") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoD1OnNoReceive = 0x01;
-	if (strcmp(string, "023719") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBmsKtoJTimeout = 0x01;
-	if (strcmp(string, "023720") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBmsChargeAllowTimeout = 0x01;
-	if (strcmp(string, "023721") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoWaitGfdTimeout = 0x01;
-	if (strcmp(string, "023722") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBmsEvRelayTimeout = 0x01;
-	if (strcmp(string, "023723") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBmsReqCurrentTimeout = 0x01;
-	if (strcmp(string, "023724") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBmsKtoJOffTimeout = 0x01;
-	if (strcmp(string, "023725") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBmsEvRelayOffTimeout = 0x01;
-	if (strcmp(string, "023726") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoAdcMoreThan10V = 0x01;
-	if (strcmp(string, "023727") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoAdcMoreThan20V = 0x01;
-	if (strcmp(string, "023728") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoBmsChargeBeforeStop = 0x01;
-	if (strcmp(string, "023729") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoChargerGetNormalStop = 0x01;
-	if (strcmp(string, "023730") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoChargerGetEmergencyStop = 0x01;
-	if (strcmp(string, "023731") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoIsolationResultFail = 0x01;
-	if (strcmp(string, "023732") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoMissLinkWithMotherBoard = 0x01;
-	if (strcmp(string, "023733") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoOutputVolMoreThanLimit = 0x01;
-	if (strcmp(string, "023734") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoReqCurrentMoreThanLimit = 0x01;
-	if (strcmp(string, "023735") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoReCapBmsEqrCurrentExceed = 0x01;
-	if (strcmp(string, "023736") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoChargeRemainCountDown = 0x01;
-
-	if (strcmp(string, "23737") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsRESTemperatureInhibit = 0x01;
-	if (strcmp(string, "23738") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsEVShiftPosition = 0x01;
-	if (strcmp(string, "23739") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsChargerConnectorLockFault = 0x01;
-	if (strcmp(string, "23740") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsEVRESSMalfunction = 0x01;
-	if (strcmp(string, "23741") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsChargingCurrentdifferential = 0x01;
-	if (strcmp(string, "23742") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsChargingVoltageOutOfRange = 0x01;
-	if (strcmp(string, "23743") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsChargingSystemIncompatibility = 0x01;
-	if (strcmp(string, "23744") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsEmergencyEvent = 0x01;
-	if (strcmp(string, "23745") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsBreaker = 0x01;
-	if (strcmp(string, "23746") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsNoData = 0x01;
-	if (strcmp(string, "23747") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_DIN_A = 0x01;
-	if (strcmp(string, "23748") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_DIN_B = 0x01;
-	if (strcmp(string, "23749") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_DIN_C = 0x01;
-	if (strcmp(string, "23750") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_ISO_1 = 0x01;
-	if (strcmp(string, "23751") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_ISO_2 = 0x01;
-	if (strcmp(string, "23752") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_ISO_3 = 0x01;
-	if (strcmp(string, "23753") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_OEM_1 = 0x01;
-	if (strcmp(string, "23754") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_OEM_2 = 0x01;
-	if (strcmp(string, "23755") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_OEM_3 = 0x01;
-	if (strcmp(string, "23756") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_OEM_4 = 0x01;
-	if (strcmp(string, "23757") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.Ccsreserved_by_OEM_5 = 0x01;
-	if (strcmp(string, "23758") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSequenceError = 0x01;
-	if (strcmp(string, "23759") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSignatureError = 0x01;
-	if (strcmp(string, "23760") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsUnknownSession = 0x01;
-	if (strcmp(string, "23761") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsServiceIDInvalid = 0x01;
-	if (strcmp(string, "23762") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsPaymentSelectionInvalid = 0x01;
-	if (strcmp(string, "23763") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsIdentificationSelectionInvalid = 0x01;
-	if (strcmp(string, "23764") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsServiceSelectionInvalid = 0x01;
-	if (strcmp(string, "23765") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCertificateExpired = 0x01;
-	if (strcmp(string, "23766") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCertificateNotYetValid = 0x01;
-	if (strcmp(string, "23767") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCertificateRevoked = 0x01;
-	if (strcmp(string, "23768") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsNoCertificateAvailable = 0x01;
-	if (strcmp(string, "23769") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCertChainError = 0x01;
-	if (strcmp(string, "23770") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCertValidationError = 0x01;
-	if (strcmp(string, "23771") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCertVerificationError = 0x01;
-	if (strcmp(string, "23772") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsContractCanceled = 0x01;
-	if (strcmp(string, "23773") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsChallengeInvalid = 0x01;
-	if (strcmp(string, "23774") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsWrongEnergyTransferMode = 0x01;
-	if (strcmp(string, "23775") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsWrongChargeParameter = 0x01;
-	if (strcmp(string, "23776") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsChargingProfileInvalid = 0x01;
-	if (strcmp(string, "23777") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTariffSelectionInvalid = 0x01;
-	if (strcmp(string, "23778") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsEVSEPresentVoltageToLow = 0x01;
-	if (strcmp(string, "23779") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsPowerDeliveryNotApplied = 0x01;
-	if (strcmp(string, "23780") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsMeteringSignatureNotValid = 0x01;
-	if (strcmp(string, "23781") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsNoChargeServiceSelected = 0x01;
-	if (strcmp(string, "23782") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsContactorError = 0x01;
-	if (strcmp(string, "23783") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCertificateNotAllowedAtThisEVSE = 0x01;
-	if (strcmp(string, "23784") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsGAChargeStop = 0x01;
-	if (strcmp(string, "23785") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsAlignmentError = 0x01;
-	if (strcmp(string, "23786") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsACDError = 0x01;
-	if (strcmp(string, "23787") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsAssociationError = 0x01;
-	if (strcmp(string, "23788") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsEVSEChargeAbort = 0x01;
-	if (strcmp(string, "23789") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsNoSupportedAppProtocol = 0x01;
-	if (strcmp(string, "23790") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsContractNotAccepted = 0x01;
-	if (strcmp(string, "23791") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsMOUnknown = 0x01;
-	if (strcmp(string, "23792") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsOEM_Prov_CertificateRevoke = 0x01;
-	if (strcmp(string, "23793") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsOEM_SubCA1_CertificateRevoked = 0x01;
-	if (strcmp(string, "23794") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsOEM_SubCA2_CertificateRevoked = 0x01;
-	if (strcmp(string, "23795") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsOEM_RootCA_CertificateRevoked = 0x01;
-	if (strcmp(string, "23796") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsMO_Prov_CertificateRevoked = 0x01;
-	if (strcmp(string, "23797") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsMO_SubCA1_CertificateRevoked = 0x01;
-	if (strcmp(string, "23798") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsMO_SubCA2_CertificateRevoked = 0x01;
-	if (strcmp(string, "23799") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsMO_RootCA_CertificateRevoked = 0x01;
-	if (strcmp(string, "23800") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCPS_Prov_CertificateRevoked = 0x01;
-	if (strcmp(string, "23801") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCPS_SubCA1_CertificateRevoked = 0x01;
-	if (strcmp(string, "23802") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCPS_SubCA2_CertificateRevoked = 0x01;
-	if (strcmp(string, "23803") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCPS_RootCA_CertificateRevoked = 0x01;
-	if (strcmp(string, "23809") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_EVSE_SLAC_init = 0x01;
-	if (strcmp(string, "23810") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_match_response = 0x01;
-	if (strcmp(string, "23811") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_match_sequence = 0x01;
-	if (strcmp(string, "23812") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_EVSE_match_MNBC = 0x01;
-	if (strcmp(string, "23813") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_EVSE_avg_atten_calc = 0x01;
-	if (strcmp(string, "23814") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_match_response = 0x01;
-	if (strcmp(string, "23815") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_EVSE_match_session = 0x01;
-	if (strcmp(string, "23816") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_EVSE_assoc_session = 0x01;
-	if (strcmp(string, "23817") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_EVSE_vald_toggle = 0x01;
-	if (strcmp(string, "23823") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsUDP_TT_match_join = 0x01;
-	if (strcmp(string, "23824") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTCP_TT_match_join = 0x01;
-	if (strcmp(string, "23825") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_amp_map_exchange = 0x01;
-	if (strcmp(string, "23826") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_link_ready_notification = 0x01;
-	if (strcmp(string, "23832") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSupportedAppProtocolRes = 0x01;
-	if (strcmp(string, "23833") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSessionSetupRes = 0x01;
-	if (strcmp(string, "23834") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsServiceDiscoveryRes = 0x01;
-	if (strcmp(string, "23835") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsServicePaymentSelectionRes = 0x01;
-	if (strcmp(string, "23836") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsContractAuthenticationRes = 0x01;
-	if (strcmp(string, "23837") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsChargeParameterDiscoveryRes = 0x01;
-	if (strcmp(string, "23838") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsPowerDeliveryRes = 0x01;
-	if (strcmp(string, "23839") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCableCheckRes = 0x01;
-	if (strcmp(string, "23840") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsPreChargeRes = 0x01;
-	if (strcmp(string, "23841") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCurrentDemandRes = 0x01;
-	if (strcmp(string, "23842") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsWeldingDetectionRes = 0x01;
-	if (strcmp(string, "23843") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSessionStopRes = 0x01;
-	if (strcmp(string, "23844") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSequence_Time = 0x01;
-	if (strcmp(string, "23845") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsReadyToCharge_Performance_Time = 0x01;
-	if (strcmp(string, "23846") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCommunicationSetup_Performance_Time = 0x01;
-	if (strcmp(string, "23847") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCableCheck_Performance_Time = 0x01;
-	if (strcmp(string, "23848") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCPState_Detection_Time = 0x01;
-	if (strcmp(string, "23849") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCPOscillator_Retain_Time = 0x01;
-	if (strcmp(string, "23855") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_GET_EV_TARGET_INFO = 0x01;
-	if (strcmp(string, "23856") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_GET_EV_TARGET_INFO = 0x01;
-	if (strcmp(string, "23857") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_GET_EV_BATTERY_INFO = 0x01;
-	if (strcmp(string, "23858") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_GET_EV_BATTERY_INFO = 0x01;
-	if (strcmp(string, "23859") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_EV_STOP_EVENT = 0x01;
-	if (strcmp(string, "23860") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_EV_STOP_EVENT = 0x01;
-	if (strcmp(string, "23861") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_EVSE_STOP_EVENT = 0x01;
-	if (strcmp(string, "23862") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_EVSE_STOP_EVENT = 0x01;
-	if (strcmp(string, "23863") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_GET_MISC_INFO = 0x01;
-	if (strcmp(string, "23864") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_GET_MISC_INFO = 0x01;
-	if (strcmp(string, "23865") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_DOWNLOAD_REQUEST = 0x01;
-	if (strcmp(string, "23866") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_DOWNLOAD_REQUEST = 0x01;
-	if (strcmp(string, "23867") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_START_BLOCK_TRANSFER = 0x01;
-	if (strcmp(string, "23868") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_START_BLOCK_TRANSFER = 0x01;
-	if (strcmp(string, "23869") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_DATA_TRANSFER = 0x01;
-	if (strcmp(string, "23870") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_DATA_TRANSFER = 0x01;
-	if (strcmp(string, "23871") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_DOWNLOAD_FINISH = 0x01;
-	if (strcmp(string, "23872") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_DOWNLOAD_FINISH = 0x01;
-	if (strcmp(string, "23873") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_ISOLATION_STATUS = 0x01;
-	if (strcmp(string, "23874") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_ISOLATION_STATUS = 0x01;
-	if (strcmp(string, "23875") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_CONNECTOR_INFO = 0x01;
-	if (strcmp(string, "23876") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_CONNECTOR_INFO = 0x01;
-	if (strcmp(string, "23877") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_RTC_INFO = 0x01;
-	if (strcmp(string, "23878") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_RTC_INFO = 0x01;
-	if (strcmp(string, "23879") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_EVSE_PRECHARGE_INFO = 0x01;
-	if (strcmp(string, "23880") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_EVSE_PRECHARGE_INFO = 0x01;
-	if (strcmp(string, "23881") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsMSG_Sequence = 0x01;
-	if (strcmp(string, "23882") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCAN_MSG_Unrecognized_CMD_ID = 0x01;
-	if (strcmp(string, "23883") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsDIN_Msg_Decode_Error = 0x01;
-	if (strcmp(string, "23884") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsDIN_Msg_Encode_Error = 0x01;
-	if (strcmp(string, "23885") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsISO1_Msg_Decode_Error = 0x01;
-	if (strcmp(string, "23886") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsISO1_Msg_Encode_Error = 0x01;
-	if (strcmp(string, "23887") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsISO2_Msg_Decode_Error = 0x01;
-	if (strcmp(string, "23888") == 0) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsISO2_Msg_Encode_Error = 0x01;
+    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((char *)_chargingData[gun_index]->EvConnAlarmCode, "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, "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, "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;
-		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;
-				}
-			}
-		}
-
-		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:
-					{
-						_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:
-					{
-						if (_chargingData[targetGun]->Type == _Type_Chademo)
-						{
-							memcpy(ShmCHAdeMOData->evse[_chargingData[targetGun]->type_index].version, frame.data, ARRAY_SIZE(frame.data));
-							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_CCS_2)
-						{
-							if (ShmCcsData->CommProtocol == 0x01)
-							{
-								memcpy(&ShmCcsData->V2GMessage_DIN70121[_chargingData[targetGun]->type_index].version, frame.data, ARRAY_SIZE(frame.data));
-								ShmCcsData->V2GMessage_DIN70121[_chargingData[targetGun]->type_index].SelfTest_Comp = PASS;
-								PRINTF_FUNC("CCS FW = %s \n", ShmCcsData->V2GMessage_DIN70121[_chargingData[targetGun]->type_index].version);
-							}
-						}
-					}
-						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];
-						_chargingData[targetGun]->EvBatterytargetCurrent = ((short) frame.data[5] << 8) + (short) frame.data[4];
-						_chargingData[targetGun]->PresentChargedDuration = ((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;
-							ShmCHAdeMOData->ev[_chargingData[targetGun]->type_index].ChargingCurrentRequest = _chargingData[targetGun]->EvBatterytargetCurrent;
-						}
-						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];
-						//_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_CCS_2)
-						{
-
-						}
-					}
-						break;
-					case ACK_GET_MISCELLANEOUS_INFO:
-					{
-						if (_chargingData[targetGun]->Type == _Type_Chademo)
-						{
-							_chargingData[targetGun]->GunLocked = frame.data[0];
-							ShmCHAdeMOData->evse[_chargingData[targetGun]->type_index].ConnectorTemperatureP = frame.data[1];
-							ShmCHAdeMOData->evse[_chargingData[targetGun]->type_index].ConnectorTemperatureN = frame.data[2];
-							_chargingData[targetGun]->PilotVoltage = (float)(-120 + frame.data[3]) / 10;
-							ShmCHAdeMOData->evse[_chargingData[targetGun]->type_index].EvboardStatus = frame.data[7];
-						}
-						else if (_chargingData[targetGun]->Type == _Type_CCS_2)
-						{
-							if (ShmCcsData->CommProtocol == 0x01)
-							{
-								_chargingData[targetGun]->GunLocked = frame.data[0];
-								//ShmCcsData->V2GMessage_DIN70121[_chargingData[targetGun]->type_index]. .ConnectorTemperatureP = frame.data[1];
-								//ShmCcsData->V2GMessage_DIN70121[_chargingData[targetGun]->type_index]. .ConnectorTemperatureN = frame.data[2];
-								_chargingData[targetGun]->PilotVoltage = (float)(-120 + frame.data[3]) / 10;
-							}
-						}
-
-						//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("NOTIFICATION_EV_STOP -----------------------------\n");
-						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);
-		}
-	}
+    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;
+                }
+            }
+        }
+
+        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:
+                    {
+                        if (_chargingData[targetGun]->Type == _Type_Chademo)
+                        {
+                            memcpy(ShmCHAdeMOData->evse[_chargingData[targetGun]->type_index].version, frame.data, frame.can_dlc);
+                            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(ShmGBTData->evse[_chargingData[targetGun]->type_index].version, frame.data, ARRAY_SIZE(frame.data));
+                            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)
+                            {
+                                memcpy(&ShmCcsData->V2GMessage_DIN70121[_chargingData[targetGun]->type_index].version, frame.data, frame.can_dlc);
+                                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, frame.data, frame.can_dlc);
+                        }
+                        else
+                        {
+                            memset(ShmSysConfigAndInfo->SysInfo.Connector2FwRev, 0, sizeof(ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
+                            memcpy(ShmSysConfigAndInfo->SysInfo.Connector2FwRev, frame.data, frame.can_dlc);
+                        }
+                    }
+                        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];
+                        _chargingData[targetGun]->EvBatterytargetCurrent = ((short) frame.data[5] << 8) + (short) frame.data[4];
+                        _chargingData[targetGun]->PresentChargedDuration = ((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;
+                            ShmCHAdeMOData->ev[_chargingData[targetGun]->type_index].ChargingCurrentRequest = _chargingData[targetGun]->EvBatterytargetCurrent;
+                        }
+                        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;
+                            ShmGBTData->ev[_chargingData[targetGun]->type_index].ChargingCurrentRequest = _chargingData[targetGun]->EvBatterytargetCurrent;
+                        }
+                        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];
+                        //_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:
+                    {
+                        if (_chargingData[targetGun]->Type == _Type_Chademo)
+                        {
+                            _chargingData[targetGun]->GunLocked = frame.data[0];
+                            ShmCHAdeMOData->evse[_chargingData[targetGun]->type_index].ConnectorTemperatureP = frame.data[1];
+                            ShmCHAdeMOData->evse[_chargingData[targetGun]->type_index].ConnectorTemperatureN = frame.data[2];
+                            _chargingData[targetGun]->PilotVoltage = (float)(-120 + frame.data[3]) / 10;
+                            ShmCHAdeMOData->evse[_chargingData[targetGun]->type_index].EvboardStatus = frame.data[7];
+                        }
+                        else if (_chargingData[targetGun]->Type == _Type_GB)
+                        {
+                            _chargingData[targetGun]->GunLocked = frame.data[0];
+                            ShmGBTData->evse[_chargingData[targetGun]->type_index].ConnectorTemperatureP = frame.data[1];
+                            ShmGBTData->evse[_chargingData[targetGun]->type_index].ConnectorTemperatureN = frame.data[2];
+                            _chargingData[targetGun]->PilotVoltage = (float)(-120 + frame.data[3]) / 10;
+                            ShmGBTData->evse[_chargingData[targetGun]->type_index].EvboardStatus = frame.data[7];
+                        }
+                        else if (_chargingData[targetGun]->Type == _Type_CCS_2)
+                        {
+                            if (ShmCcsData->CommProtocol == 0x01)
+                            {
+                                _chargingData[targetGun]->GunLocked = frame.data[0];
+                                //ShmCcsData->V2GMessage_DIN70121[_chargingData[targetGun]->type_index]. .ConnectorTemperatureP = frame.data[1];
+                                //ShmCcsData->V2GMessage_DIN70121[_chargingData[targetGun]->type_index]. .ConnectorTemperatureN = frame.data[2];
+                                _chargingData[targetGun]->PilotVoltage = (float)(-120 + frame.data[3]) / 10;
+                            }
+                        }
+
+                        //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]);
+
+                        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
+// 瑼X䰻 Byte 銝剜��� Bit ����
+// _byte : 甈脫㺿霈羓� byte
+// _bit : 閰� byte ��洵撟曉�� bit
 unsigned char EvDetectionStatus(unsigned char _byte, unsigned char _bit)
 {
-	return ( _byte & mask_table[_bit] ) != 0x00;
+    return ( _byte & mask_table[_bit] ) != 0x00;
 }
 
 bool IsConnectorPlugIn(struct ChargingInfoData *chargingData)
 {
-	return (chargingData->ConnectorPlugIn == 0x01) ? true : false;
+    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;
+    float vol1 = 0, cur1 = 0;
+    float vol2 = 0, cur2 = 0;
 
-	//PRINTF_FUNC("f vol - 0 = %f \n", chargingData_1->FireChargingVoltage);
-	//PRINTF_FUNC("f cur - 0 = %f \n", chargingData_1->PresentChargingCurrent);
-	//PRINTF_FUNC("***********************f vol - 1 = %f \n", chargingData_2->FireChargingVoltage);
-	//PRINTF_FUNC("***********************f cur - 1 = %f \n", chargingData_2->PresentChargingCurrent);
+    //PRINTF_FUNC("f vol - 0 = %f \n", chargingData_1->FireChargingVoltage);
+    //PRINTF_FUNC("f cur - 0 = %f \n", chargingData_1->PresentChargingCurrent);
+    //PRINTF_FUNC("***********************f vol - 1 = %f \n", chargingData_2->FireChargingVoltage);
+    //PRINTF_FUNC("***********************f cur - 1 = %f \n", chargingData_2->PresentChargingCurrent);
 
-	vol1 = chargingData_1->FireChargingVoltage;
-	cur1 = chargingData_1->PresentChargingCurrent;
+    vol1 = chargingData_1->FireChargingVoltage;
+    cur1 = (chargingData_1->PresentChargingCurrent * 10);
 
-	vol2 = chargingData_2->FireChargingVoltage;
-	cur2 = chargingData_2->PresentChargingCurrent;
+    vol2 = chargingData_2->FireChargingVoltage;
+    cur2 = (chargingData_2->PresentChargingCurrent * 10);
 
-	SetPresentOutputPower(vol1, cur1, vol2, 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;
-
-	if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag != _REASSIGNED_NONE)
-	{
-		pow1 = chargingData_1->DeratingChargingPower;
-		cur1 = chargingData_1->DeratingChargingCurrent;
-	}
-	else
-	{
-		pow1 = chargingData_1->AvailableChargingPower;
-		cur1 = chargingData_1->AvailableChargingCurrent;
-	}
-	vol = chargingData_1->MaximumChargingVoltage;
-	GetMaxVolAndCurMethod(chargingData_1->Index, &vol, &cur1);
-	GetMaxPowerMethod(&pow1);
-
-	if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag != _REASSIGNED_NONE)
-	{
-		pow2 = chargingData_2->DeratingChargingPower;
-		cur2 = chargingData_2->DeratingChargingCurrent;
-	}
-	else
-	{
-		pow2 = chargingData_2->AvailableChargingPower;
-		cur2 = chargingData_2->AvailableChargingCurrent;
-	}
-	vol = chargingData_2->MaximumChargingVoltage;
-	GetMaxVolAndCurMethod(chargingData_2->Index, &vol, &cur2);
-	GetMaxPowerMethod(&pow2);
-
-	PRINTF_FUNC("To EV Power_1 = %f, Cur_1 = %f, Power_2 = %f, Cur_2 = %f \n", pow1, cur1, pow2, cur2);
-	SetPresentOutputCapacity(pow1, cur1, pow2, cur2);
+    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;
-			}
-		}
-	}
+    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;
+            }
+        }
+    }
 }
 
 void GetMaxVolAndCurMethod(byte index, float *vol, float *cur)
 {
-	if (maxChargingVol[index] != 0 && maxChargingVol[index] <= *vol)
-		*vol = maxChargingVol[index];
+    if (maxChargingVol[index] != 0 && maxChargingVol[index] <= *vol)
+        *vol = maxChargingVol[index];
 
-	if (maxChargingCur[index] != 0 && maxChargingCur[index] <= *cur)
-		*cur = maxChargingCur[index];
+    if (maxChargingCur[index] != 0 && maxChargingCur[index] <= *cur)
+        *cur = maxChargingCur[index];
 }
 
 void GetMaxPowerMethod(float *pow)
 {
-	if (maxChargingPow != 0 && maxChargingPow <= *pow)
-		*pow = maxChargingPow;
+    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;
-	}
-	else if (_chargingData[gunIndex]->Type == _Type_Chademo &&
-			ShmStatusCodeData->FaultCode.FaultEvents.bits.ChademoOutputRelayDrivingFault == 0x01)
-	{
-		// 011012
-		*(reason + 5) = 0;
-		*(reason + 4) = 1;
-		*(reason + 3) = 1;
-		*(reason + 2) = 0;
-		*(reason + 1) = 1;
-		*(reason + 0) = 2;
-		result = YES;
-	}
-	else if (_chargingData[gunIndex]->Type == _Type_CCS_2 &&
-			ShmStatusCodeData->FaultCode.FaultEvents.bits.CcsOutputRelayDrivingFault == 0x01)
-	{
-		// 011014
-		*(reason + 5) = 0;
-		*(reason + 4) = 1;
-		*(reason + 3) = 1;
-		*(reason + 2) = 0;
-		*(reason + 1) = 1;
-		*(reason + 0) = 4;
-		result = YES;
-	}
-
-	return result;
+    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;
-	}
-
-	Initialization();
-	CanFd = InitCanBus();
-	CANReceiver();
-
-	byte priorityLow = 1;
-	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)
-				{
-					GetFirmwareVersion(_index, _chargingData[_index]->Evboard_id);
-					GetHardwareVersion(_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)
-					{
-						GetFirmwareVersion(_index, _chargingData[_index]->Evboard_id);
-						GetHardwareVersion(_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]->Evboard_id);
-			}
-
-			switch (_chargingData[_index]->SystemStatus)
-			{
-				case S_IDLE:
-				case S_RESERVATION:
-					_chargingData[_index]->PresentChargedEnergy = 0;
-					_chargingData[_index]->PresentChargingPower = 0;
-					_chargingData[_index]->GroundFaultStatus = GFD_WAIT;
-					_chargingData[_index]->StopChargeFlag = NO;
-					chargingTime[_index] = 0;
-
-					if (_chargingData[_index]->Type == _Type_Chademo)
-					{
-						ClearAbnormalStatus_Chademo(_index);
-					}
-					else if (_chargingData[_index]->Type == _Type_CCS_2)
-					{
-						ClearAbnormalStatus_CCS(_index);
-					}
-
-					if (priorityLow == 1)
-					{
-						maxChargingCur[_index] = ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent;
-						maxChargingPow = ShmSysConfigAndInfo->SysConfig.MaxChargingPower;
-					}
-					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;
-						// 樁端輸出能力
-						if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag != _REASSIGNED_NONE)
-						{
-							maxVol = _chargingData[_index]->MaximumChargingVoltage;
-							maxCur = _chargingData[_index]->DeratingChargingCurrent;
-						}
-						else
-						{
-							maxVol = _chargingData[_index]->MaximumChargingVoltage;
-							maxCur = _chargingData[_index]->AvailableChargingCurrent;
-						}
-						GetMaxVolAndCurMethod(_index, &maxVol, &maxCur);
-
-						PRINTF_FUNC("To EV Max_Vol = %f, Cap_Cur = %f \n", maxVol, maxCur);
-						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);
-					}
-				}
-					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]->GroundFaultStatus != GFD_WAIT)
-						{
-							SetIsolationStatus(_index, _chargingData[_index]->GroundFaultStatus, _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 / 10) * (_chargingData[_index]->PresentChargingCurrent / 10)) / 1000);
-
-					if (chargingTime[_index] == 0)
-					{
-						chargingTime[_index] = _chargingData[_index]->RemainChargingDuration;
-					}
-					else
-					{
-						int passTime = _chargingData[_index]->RemainChargingDuration - chargingTime[_index];
-
-						if (passTime > 0)
-						{
-							_chargingData[_index]->PresentChargedEnergy += (_chargingData[_index]->PresentChargingPower) * passTime / 3600;
-							chargingTime[_index] = _chargingData[_index]->RemainChargingDuration;
-						}
-					}
-
-					// 開始確認車端是否同意開始充電
-					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)
-					{
-						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;
-
-						// 樁端輸出能力
-						if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag != _REASSIGNED_NONE)
-						{
-							maxVol = _chargingData[_index]->MaximumChargingVoltage;
-							maxCur = _chargingData[_index]->DeratingChargingCurrent;
-						}
-						else
-						{
-							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;
+    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:
+                    _chargingData[_index]->PresentChargedEnergy = 0;
+                    _chargingData[_index]->PresentChargingPower = 0;
+                    _chargingData[_index]->GroundFaultStatus = GFD_WAIT;
+                    _chargingData[_index]->StopChargeFlag = NO;
+                    _chargingData[_index]->ChargingFee = 0.0;
+                    chargingTime[_index] = 0;
+
+                    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)
+                    {
+                        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);
+                    }
+                }
+                    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)
+                        {
+                            unsigned char _result = _chargingData[_index]->GroundFaultStatus;
+
+                            if(_chargingData[_index]->Type == _Type_Chademo || _chargingData[_index]->Type == _Type_GB)
+                            {
+                                if (_result == GFD_WARNING)
+                                {
+                                    _result = GFD_PASS;
+                                }
+                                SetIsolationStatus(_index, _result, _chargingData[_index]->Evboard_id);
+                            }
+                            else if(_chargingData[_index]->Type == _Type_CCS_2)
+                            {
+                                SetIsolationStatus(_index, _result, _chargingData[_index]->Evboard_id);
+                            }
+                            else
+                            {
+                                //NULL
+                            }
+                        }
+
+                        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]->RemainChargingDuration;
+                    }
+                    else
+                    {
+                        int passTime = _chargingData[_index]->RemainChargingDuration - 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]->RemainChargingDuration;
+                        }
+                    }
+
+                    // �见�蝣箄�頠羓垢�臬炏�峕��见���𤓖
+                    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]);
+                    }
+
+                    if (priorityLow == 1)
+                    {
+                        // Chademo & GB/T GFD 憭望��漤�𡁶䰻
+                        if(_chargingData[_index]->Type == _Type_Chademo || _chargingData[_index]->Type == _Type_GB)
+                        {
+                            if(_chargingData[_index]->GroundFaultStatus == GFD_FAIL)
+                            {
+                                SetIsolationStatus(_index, _chargingData[_index]->GroundFaultStatus, _chargingData[_index]->Evboard_id);
+                            }
+                        }
+                        // CCS will be continuous notify GFD state
+                        else if(_chargingData[_index]->Type == _Type_CCS_2)
+                        {
+                            SetIsolationStatus(_index, _chargingData[_index]->GroundFaultStatus, _chargingData[_index]->Evboard_id);
+                        }
+                        else
+                        {
+                            //NULL
+                        }
+
+                        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;
 }

+ 78 - 77
EVSE/Projects/DW30/Apps/Module_EvComm.h

@@ -1,77 +1,78 @@
-#ifndef MODULE_EVCOMM_H_
-#define MODULE_EVCOMM_H_
-
-#include 	<stdbool.h>
-
-int CanFd;
-
-typedef unsigned char 		byte;
-
-extern struct Ev_Board_Cmd
-{
-	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 evse_precharge_info;			// 0x00001500
-}Ev_Cmd;
-
-extern struct Ev_Cmd_Dir
-{
-	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 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 toId);
-void SetIsolationStatus(byte gun_index, byte result, byte toId);
-void SetEvsePrechargeInfo(byte gun_index, byte result, byte toId);
-// µo°e¹q¼Î¥D°Ê°±¤î¥R¹qµ²ªG¤Î­ì¦]
-void EvseStopChargingEvent(byte stopResult, byte *stopReason, byte toId);
-
-// Receive msg From can-bus.
-
-enum Receieve_PSU_msgf
-{
-	// ¨®ºÝ¥D°Ê
-	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,
-};
-
-#endif /* MODULE_EVCOMM_H_ */
-
+#ifndef MODULE_EVCOMM_H_
+#define MODULE_EVCOMM_H_
+
+#include <stdbool.h>
+
+int CanFd;
+
+typedef unsigned char       byte;
+
+extern struct Ev_Board_Cmd
+{
+    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
+{
+    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
+{
+    // 車端主動
+    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,
+};
+
+#endif /* MODULE_EVCOMM_H_ */

+ 242 - 234
EVSE/Projects/DW30/Apps/Module_EventLogging.c

@@ -1,39 +1,41 @@
-#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/wireless.h>
-#include 	<arpa/inet.h>
-#include 	<netinet/in.h>
+#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/wireless.h>
+#include <arpa/inet.h>
+#include <netinet/in.h>
 
-#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 	<errno.h>
-#include 	<string.h>
-#include	<time.h>
-#include	<ctype.h>
-#include 	<ifaddrs.h>
-#include	"../../define.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"
 
-#define ARRAY_SIZE(A)		(sizeof(A) / sizeof(A[0]))
-#define PASS				1
-#define FAIL				-1
+#define ARRAY_SIZE(A)       (sizeof(A) / sizeof(A[0]))
+#define PASS                1
+#define FAIL                -1
+#define YES                 1
+#define NO                  0
 
-struct SysConfigAndInfo			*ShmSysConfigAndInfo;
-struct StatusCodeData 			*ShmStatusCodeData;
+struct SysConfigAndInfo         *ShmSysConfigAndInfo;
+struct StatusCodeData           *ShmStatusCodeData;
 
 void PRINTF_FUNC(char *string, ...);
 
@@ -44,50 +46,50 @@ int StoreLogMsg(const char *fmt, ...);
 
 int StoreLogMsg(const char *fmt, ...)
 {
-	char Buf[4096+256];
-	char buffer[4096];
-	time_t CurrentTime;
-	struct tm *tm;
-	va_list args;
+    char Buf[4096+256];
+    char buffer[4096];
+    time_t CurrentTime;
+    struct tm *tm;
+    va_list args;
 
-	va_start(args, fmt);
-	int rc = vsnprintf(buffer, sizeof(buffer), fmt, args);
-	va_end(args);
+    va_start(args, fmt);
+    int rc = vsnprintf(buffer, sizeof(buffer), fmt, args);
+    va_end(args);
 
-	memset(Buf,0,sizeof(Buf));
-	CurrentTime = time(NULL);
-	tm=localtime(&CurrentTime);
-	sprintf(Buf,"echo \"%04d-%02d-%02d %02d:%02d:%02d - %s\" >> /Storage/SystemLog/[%04d.%02d]SystemLog",
-			tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,
-			buffer,
-			tm->tm_year+1900,tm->tm_mon+1);
-	system(Buf);
+    memset(Buf,0,sizeof(Buf));
+    CurrentTime = time(NULL);
+    tm=localtime(&CurrentTime);
+    sprintf(Buf,"echo \"%04d-%02d-%02d %02d:%02d:%02d - %s\" >> /Storage/SystemLog/[%04d.%02d]SystemLog",
+            tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,
+            buffer,
+            tm->tm_year+1900,tm->tm_mon+1);
+    system(Buf);
 
-	return rc;
+    return rc;
 }
 
 int DiffTimeb(struct timeb ST, struct timeb ET)
 {
-	//return milli-second
-	unsigned int StartTime,StopTime;
+    //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;
+    StartTime=(unsigned int)ST.time;
+    StopTime=(unsigned int)ET.time;
+    return (StopTime-StartTime)*1000+ET.millitm-ST.millitm;
 }
 
 void PRINTF_FUNC(char *string, ...)
 {
-	if (DEBUG)
-	{
-		va_list args;
-		char buffer[4096];
+    va_list args;
+    char buffer[4096];
+    va_start(args, string);
+    vsnprintf(buffer, sizeof(buffer), string, args);
+    va_end(args);
 
-		va_start(args, string);
-		vsnprintf(buffer, sizeof(buffer), string, args);
-		va_end(args);
-		printf("%s \n", buffer);
-	}
+    if (ShmSysConfigAndInfo->SysConfig.SwitchDebugFlag == YES)
+        printf("%s \n", buffer);
+    else
+        DEBUG_INFO("%s \n", buffer);
 }
 
 //=================================
@@ -95,15 +97,15 @@ void PRINTF_FUNC(char *string, ...)
 //=================================
 char* getTimeString(void)
 {
-	char *result=malloc(21);
-	time_t timep;
-	struct tm *p;
-	time(&timep);
-	p=gmtime(&timep);
+    char *result=malloc(21);
+    time_t timep;
+    struct tm *p;
+    time(&timep);
+    p=gmtime(&timep);
 
-	sprintf(result, "[%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);
+    sprintf(result, "[%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);
 
-	return result;
+    return result;
 }
 
 //==========================================
@@ -111,42 +113,42 @@ char* getTimeString(void)
 //==========================================
 int InitShareMemory()
 {
-	int result = PASS;
-	int MeterSMId;
+    int result = PASS;
+    int MeterSMId;
 
-	//creat ShmSysConfigAndInfo
-	if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo),  0777)) < 0)
+    //creat ShmSysConfigAndInfo
+    if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo),  0777)) < 0)
     {
-		#ifdef SystemLogMessage
-		DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
-		#endif
-		result = FAIL;
-	}
+        #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;
-   	 }
+        #ifdef SystemLogMessage
+        DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
+        #endif
+        result = FAIL;
+     }
     else
     {}
 
-   	 //creat ShmStatusCodeData
-   	 if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData),  0777)) < 0)
+     //creat ShmStatusCodeData
+     if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData),  0777)) < 0)
     {
-		#ifdef SystemLogMessage
-   		DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
-		#endif
-   		result = FAIL;
-	}
+        #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;
-   	}
+        #ifdef SystemLogMessage
+        DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
+        #endif
+        result = FAIL;
+    }
     else
     {}
 
@@ -158,156 +160,162 @@ int InitShareMemory()
 //================================================
 void AddFaultCodeToBuf(unsigned char *Code)
 {
-	if(ShmSysConfigAndInfo->SysWarningInfo.WarningCount < 10)
-	{
-		memcpy(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[ShmSysConfigAndInfo->SysWarningInfo.WarningCount][0], Code, 7);
-		ShmSysConfigAndInfo->SysWarningInfo.WarningCount++;
-	}
+    if(ShmSysConfigAndInfo->SysWarningInfo.WarningCount < 10)
+    {
+        memcpy(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[ShmSysConfigAndInfo->SysWarningInfo.WarningCount][0], Code, 7);
+        ShmSysConfigAndInfo->SysWarningInfo.WarningCount++;
+    }
 }
 
 void RemoveFaultCodeToBuf(unsigned char *Code)
 {
-	unsigned char find = 0x00;
-	char _code[7];
-	sprintf(_code,"%s", Code);
+    unsigned char find = 0x01;
+    char _code[7];
+    sprintf(_code,"%s", Code);
 
-	for(unsigned char i = 0; i < ShmSysConfigAndInfo->SysWarningInfo.WarningCount; i++)
-	{
-		if (find == 0x00)
-		{
-			if(memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], _code, 7) != 0)
-			{
-				find = 0x01;
-			}
-		}
-		else
-		{
-			if(i == ShmSysConfigAndInfo->SysWarningInfo.WarningCount - 1)
-			{
-				memcpy(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], "", 7);
-			}
-			else
-			{
-				memcpy(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0],
-						&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i + 1][0], 7);
-			}
-		}
-	}
+    // 把相關的錯誤碼一次移除,���複顯示
+    while(find)
+    {
+        find = 0x00;
+        for(unsigned char i = 0; i < ShmSysConfigAndInfo->SysWarningInfo.WarningCount; i++)
+        {
+            if (find == 0x00)
+            {
+                if(memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], _code, 7) == 0)
+                {
+                    find = 0x01;
+                }
+            }
+            else
+            {
+                if(i == ShmSysConfigAndInfo->SysWarningInfo.WarningCount - 1)
+                {
+                    memcpy(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], "", 7);
+                }
+                else
+                {
+                    memcpy(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0],
+                            &ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i + 1][0], 7);
+                }
+            }
+        }
 
-	ShmSysConfigAndInfo->SysWarningInfo.WarningCount--;
+        if (find)
+            ShmSysConfigAndInfo->SysWarningInfo.WarningCount--;
+    }
 }
 
 int main(void)
 {
-	int ByteCount,BitCount;
-	unsigned char tmp, EventCodeTmp[7];
+    int ByteCount,BitCount;
+    unsigned char tmp, EventCodeTmp[7];
 
-	if(InitShareMemory() == FAIL)
-	{
-		#ifdef SystemLogMessage
-		DEBUG_ERROR("InitShareMemory NG\n");
-		#endif
-		if(ShmStatusCodeData!=NULL)
-		{
-			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
-		}
-		sleep(5);
-		return 0;
-	}
+    if(InitShareMemory() == FAIL)
+    {
+        #ifdef SystemLogMessage
+        DEBUG_ERROR("InitShareMemory NG\n");
+        #endif
+        if(ShmStatusCodeData!=NULL)
+        {
+            ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
+        }
+        sleep(5);
+        return 0;
+    }
 
-	for(;;)
-	{
-		//check Fault Status
-		for(ByteCount=0;ByteCount<4;ByteCount++)
-		{
-			if(ShmStatusCodeData->FaultCode.FaultEvents.FaultVal[ByteCount] != ShmStatusCodeData->FaultCode.PreviousFaultVal[ByteCount])
-			{
-				tmp=ShmStatusCodeData->FaultCode.FaultEvents.FaultVal[ByteCount]; //prevent be modified during following process
-				for(BitCount=0;BitCount<8;BitCount++)
-				{
-					if(((tmp>>BitCount)&0x01) != ((ShmStatusCodeData->FaultCode.PreviousFaultVal[ByteCount]>>BitCount)&0x01))
-					{
-						memset(EventCodeTmp,0,sizeof(EventCodeTmp));
-						memcpy(EventCodeTmp,FaultStatusCode[ByteCount*8+BitCount],sizeof(EventCodeTmp)-1);
-						if(((tmp>>BitCount)&0x01)==0)//Recovered
-						{
-							//EventCodeTmp[0]=1;
-							DEBUG_INFO("Recovery Fault Code = %s\n", EventCodeTmp);
-							ShmStatusCodeData->FaultCode.PreviousFaultVal[ByteCount] &= ~(1<<BitCount);
-							RemoveFaultCodeToBuf(EventCodeTmp);
-						}
-						else
-						{
-							DEBUG_INFO("Fault Code = %s\n", EventCodeTmp);
-							ShmStatusCodeData->FaultCode.PreviousFaultVal[ByteCount] |= (1<<BitCount);
-							AddFaultCodeToBuf(EventCodeTmp);
-						}
-					}
-				}
-			}
-		}
+    for(;;)
+    {
+        //check Fault Status
+        for(ByteCount=0;ByteCount<4;ByteCount++)
+        {
+            if(ShmStatusCodeData->FaultCode.FaultEvents.FaultVal[ByteCount] != ShmStatusCodeData->FaultCode.PreviousFaultVal[ByteCount])
+            {
+                tmp=ShmStatusCodeData->FaultCode.FaultEvents.FaultVal[ByteCount]; //prevent be modified during following process
+                for(BitCount=0;BitCount<8;BitCount++)
+                {
+                    if(((tmp>>BitCount)&0x01) != ((ShmStatusCodeData->FaultCode.PreviousFaultVal[ByteCount]>>BitCount)&0x01))
+                    {
+                        memset(EventCodeTmp,0,sizeof(EventCodeTmp));
+                        memcpy(EventCodeTmp,FaultStatusCode[ByteCount*8+BitCount],sizeof(EventCodeTmp)-1);
+                        if(((tmp>>BitCount)&0x01)==0)//Recovered
+                        {
+                            //EventCodeTmp[0]=1;
+                            DEBUG_INFO("Recovery Fault Code = %s\n", EventCodeTmp);
+                            ShmStatusCodeData->FaultCode.PreviousFaultVal[ByteCount] &= ~(1<<BitCount);
+                            RemoveFaultCodeToBuf(EventCodeTmp);
+                        }
+                        else
+                        {
+                            DEBUG_INFO("Fault Code = %s\n", EventCodeTmp);
+                            ShmStatusCodeData->FaultCode.PreviousFaultVal[ByteCount] |= (1<<BitCount);
+                            AddFaultCodeToBuf(EventCodeTmp);
+                        }
+                    }
+                }
+            }
+        }
 
-		//check Alarm Status
-		for(ByteCount=0;ByteCount<11;ByteCount++)
-		{
-			if(ShmStatusCodeData->AlarmCode.AlarmEvents.AlarmVal[ByteCount] != ShmStatusCodeData->AlarmCode.PreviousAlarmVal[ByteCount])
-			{
-				tmp=ShmStatusCodeData->AlarmCode.AlarmEvents.AlarmVal[ByteCount]; //prevent be modified during following process
-				for(BitCount=0;BitCount<8;BitCount++)
-				{
-					if(((tmp>>BitCount)&0x01) != ((ShmStatusCodeData->AlarmCode.PreviousAlarmVal[ByteCount]>>BitCount)&0x01))
-					{
-						memset(EventCodeTmp,0,sizeof(EventCodeTmp));
-						memcpy(EventCodeTmp,AlarmStatusCode[ByteCount*8+BitCount],sizeof(EventCodeTmp)-1);
-						if(((tmp>>BitCount)&0x01)==0)//Recovered
-						{
-							//EventCodeTmp[0]=1;
-							DEBUG_INFO("Recovery Alarm Code = %s\n", EventCodeTmp);
-							ShmStatusCodeData->AlarmCode.PreviousAlarmVal[ByteCount] &= ~(1<<BitCount);
-							RemoveFaultCodeToBuf(EventCodeTmp);
-						}
-						else
-						{
-							DEBUG_INFO("Alarm Code = %s\n", EventCodeTmp);
-							ShmStatusCodeData->AlarmCode.PreviousAlarmVal[ByteCount] |= (1<<BitCount);
-							AddFaultCodeToBuf(EventCodeTmp);
-						}
-					}
-				}
-			}
-		}
+        //check Alarm Status
+        for(ByteCount=0;ByteCount<13;ByteCount++)
+        {
+            if(ShmStatusCodeData->AlarmCode.AlarmEvents.AlarmVal[ByteCount] != ShmStatusCodeData->AlarmCode.PreviousAlarmVal[ByteCount])
+            {
+                tmp=ShmStatusCodeData->AlarmCode.AlarmEvents.AlarmVal[ByteCount]; //prevent be modified during following process
+                for(BitCount=0;BitCount<8;BitCount++)
+                {
+                    if(((tmp>>BitCount)&0x01) != ((ShmStatusCodeData->AlarmCode.PreviousAlarmVal[ByteCount]>>BitCount)&0x01))
+                    {
+                        memset(EventCodeTmp,0,sizeof(EventCodeTmp));
+                        memcpy(EventCodeTmp,AlarmStatusCode[ByteCount*8+BitCount],sizeof(EventCodeTmp)-1);
+                        if(((tmp>>BitCount)&0x01)==0)//Recovered
+                        {
+                            //EventCodeTmp[0]=1;
+                            DEBUG_INFO("Recovery Alarm Code = %s\n", EventCodeTmp);
+                            ShmStatusCodeData->AlarmCode.PreviousAlarmVal[ByteCount] &= ~(1<<BitCount);
+                            RemoveFaultCodeToBuf(EventCodeTmp);
+                        }
+                        else
+                        {
+                            DEBUG_INFO("Alarm Code = %s\n", EventCodeTmp);
+                            ShmStatusCodeData->AlarmCode.PreviousAlarmVal[ByteCount] |= (1<<BitCount);
+                            AddFaultCodeToBuf(EventCodeTmp);
+                        }
+                    }
+                }
+            }
+        }
 
-		//check Info Status
-		for(ByteCount=0;ByteCount<29;ByteCount++)
-		{
-			if(ShmStatusCodeData->InfoCode.InfoEvents.InfoVal[ByteCount] != ShmStatusCodeData->InfoCode.PreviousInfoVal[ByteCount])
-			{
-				tmp=ShmStatusCodeData->InfoCode.InfoEvents.InfoVal[ByteCount]; //prevent be modified during following process
-				for(BitCount=0;BitCount<8;BitCount++)
-				{
-					if(((tmp>>BitCount)&0x01) != ((ShmStatusCodeData->InfoCode.PreviousInfoVal[ByteCount]>>BitCount)&0x01))
-					{
-						memset(EventCodeTmp,0,sizeof(EventCodeTmp));
-						memcpy(EventCodeTmp,InfoStatusCode[ByteCount*8+BitCount],sizeof(EventCodeTmp)-1);
-						if(((tmp>>BitCount)&0x01)==0)//Recovered
-						{
-							//EventCodeTmp[0]=1;
-							DEBUG_INFO("Recovery Info Code = %s\n", EventCodeTmp);
-							ShmStatusCodeData->InfoCode.PreviousInfoVal[ByteCount] &= ~(1<<BitCount);
-							RemoveFaultCodeToBuf(EventCodeTmp);
-						}
-						else
-						{
-							DEBUG_INFO("Info Code = %s\n", EventCodeTmp);
-							ShmStatusCodeData->InfoCode.PreviousInfoVal[ByteCount] |= (1<<BitCount);
-							AddFaultCodeToBuf(EventCodeTmp);
-						}
-					}
-				}
-			}
-		}
-		usleep(500000);
-	}
+        //check Info Status
+        for(ByteCount=0;ByteCount<40;ByteCount++)
+        {
+            if(ShmStatusCodeData->InfoCode.InfoEvents.InfoVal[ByteCount] != ShmStatusCodeData->InfoCode.PreviousInfoVal[ByteCount])
+            {
+                tmp=ShmStatusCodeData->InfoCode.InfoEvents.InfoVal[ByteCount]; //prevent be modified during following process
+                for(BitCount=0;BitCount<8;BitCount++)
+                {
+                    if(((tmp>>BitCount)&0x01) != ((ShmStatusCodeData->InfoCode.PreviousInfoVal[ByteCount]>>BitCount)&0x01))
+                    {
+                        memset(EventCodeTmp,0,sizeof(EventCodeTmp));
+                        memcpy(EventCodeTmp,InfoStatusCode[ByteCount*8+BitCount],sizeof(EventCodeTmp)-1);
+                        if(((tmp>>BitCount)&0x01)==0)//Recovered
+                        {
+                            //EventCodeTmp[0]=1;
+                            DEBUG_INFO("Recovery Info Code = %s\n", EventCodeTmp);
+                            ShmStatusCodeData->InfoCode.PreviousInfoVal[ByteCount] &= ~(1<<BitCount);
+                            RemoveFaultCodeToBuf(EventCodeTmp);
+                        }
+                        else
+                        {
+                            DEBUG_INFO("Info Code = %s\n", EventCodeTmp);
+                            ShmStatusCodeData->InfoCode.PreviousInfoVal[ByteCount] |= (1<<BitCount);
+                            AddFaultCodeToBuf(EventCodeTmp);
+                        }
+                    }
+                }
+            }
+        }
+        usleep(500000);
+    }
 
-	return FAIL;
+    return FAIL;
 }

文件差异内容过多而无法显示
+ 1177 - 890
EVSE/Projects/DW30/Apps/Module_InternalComm.c


+ 0 - 151
EVSE/Projects/DW30/Apps/Module_LcmContro.h

@@ -1,151 +0,0 @@
-#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/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 	<stdbool.h>
-#include	"../../define.h"
-
-#define ARRAY_SIZE(A)		(sizeof(A) / sizeof(A[0]))
-#define PASS				1
-#define FAIL				-1
-#define YES					1
-#define NO					0
-
-typedef unsigned char 			byte;
-
-struct SysConfigAndInfo			*ShmSysConfigAndInfo;
-struct StatusCodeData 			*ShmStatusCodeData;
-struct FanModuleData			*ShmFanModuleData;
-
-#define CMD_TITLE_1				0x5A
-#define CMD_TITLE_2				0xA5
-#define CMD_READ				0x80
-#define CMD_WRITE				0x81
-#define CMD_MULTI_WRITE			0x82
-#define CMD_MULTI_READ			0x83
-
-#define CMD_BACKLIGHT			0x01
-#define CMD_REGISTER			0x03
-
-int _port;
-//char* pPortName = "/dev/ttyO2";
-char* pPortName = "/dev/ttyS3";
-char* moduleName = "DMT80480T070_09WT";
-byte _totalCount = CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY;
-struct ChargingInfoData *_chargingInfoData[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
-
-// 當前選擇的槍號
-short _currentPage = _LCM_NONE;
-byte _gunIndex = 0;
-byte _idlePageRotate = 1;
-bool _backend_conn_status = false;
-bool _wifi_conn_status = false;
-
-// LCM - HW
-byte _everyPageRollChange = 0;
-short __conn_status = 0x0030;
-short __ethernet_status = 0x0036;
-short __wifi_status = 0x003C;
-
-short __sel_gun_btn = 0x0040;
-short __ret_home_btn = 0x0042;
-short __stop_method_btn = 0x0044;
-
-short __qr_code = 0x0050;
-
-short __plug_in_arrow = 0x0060;
-
-short __conn_line = 0x0066;
-
-short __gun_type_index = 0x0070;
-short __qr_code_pre = 0x0080;
-
-short __side_top = 0x0090;
-short __side_down = 0x0092;
-
-short __conn_line_chag = 0x0096;
-short __batt_map = 0x0100;
-short __soc_value_charging = 0x0102;
-short __remain_time_map = 0x0106;
-short __power_map = 0x0108;
-short __energy_map = 0x010A;
-short __remain_time_tx = 0x0110;
-short __output_eng_tx = 0x0120;
-short __total_out_eng_tx = 0x0130;
-short __conn_line_comp = 0x0140;
-
-// ICON ID
-byte _disappear = 0;
-byte _disconnect = 1;
-byte _connect = 2;
-byte _warning = 3;
-byte _arrow_dark = 4;
-byte _arrow_light = 5;
-byte _ethernet_disconnect = 6;
-byte _ethernet_connect = 7;
-byte _wifi_disconnect = 8;
-byte _wifi_connect = 9;
-byte _logo = 10;
-byte _conn_map1 = 11;
-byte _conn_map2 = 12;
-byte _sel_gun_btn = 13;
-byte _back_home_btn = 14;
-byte _stop_charging_btn = 15;
-byte _stop_charging_btn_scan = 16;
-byte _chademo_dark = 17;
-byte _ccs_dark = 18;
-byte _actype_dark = 19;
-byte _chademo_light = 20;
-byte _ccs_light = 21;
-byte _actype_light = 22;
-byte _side_rfid_1 = 23;
-byte _side_qr_1 = 24;
-byte _side_app_1 = 25;
-byte _side_rfid_2 = 26;
-byte _side_qr_2 = 27;
-byte _side_app_2 = 28;
-byte _charging_map1 = 29;
-byte _charging_map2 = 30;
-byte _battery_cap_20 = 31;
-byte _battery_cap_40 = 32;
-byte _battery_cap_60 = 33;
-byte _battery_cap_80 = 34;
-byte _battery_cap_100 = 35;
-byte _battery_map = 36;
-byte _power_map = 37;
-byte _time_map = 38;
-byte _complete_map = 39;
-byte _battery_soc_20 = 40;
-byte _battery_soc_40 = 41;
-byte _battery_soc_60 = 42;
-byte _battery_soc_80 = 43;
-byte _battery_soc_100 = 44;
-byte _battery_eng_map = 45;
-byte _money_map = 46;
-byte _elapse_time_map = 47;
-
-

+ 1059 - 700
EVSE/Projects/DW30/Apps/Module_LcmControl.c

@@ -1,4 +1,6 @@
-#include "Module_LcmContro.h"
+#include "Module_LcmControl.h"
+
+bool needReloadQr = true;
 
 void PRINTF_FUNC(char *string, ...);
 
@@ -14,53 +16,53 @@ char* getTimeString(void);
 //=================================
 int StoreLogMsg(const char *fmt, ...)
 {
-	char Buf[4096+256];
-	char buffer[4096];
-	time_t CurrentTime;
-	struct tm *tm;
-	va_list args;
-
-	va_start(args, fmt);
-	int rc = vsnprintf(buffer, sizeof(buffer), fmt, args);
-	va_end(args);
-
-	memset(Buf,0,sizeof(Buf));
-	CurrentTime = time(NULL);
-	tm=localtime(&CurrentTime);
-	sprintf(Buf,"echo \"%04d-%02d-%02d %02d:%02d:%02d - %s\" >> /Storage/SystemLog/[%04d.%02d]SystemLog",
-			tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,
-			buffer,
-			tm->tm_year+1900,tm->tm_mon+1);
-	system(Buf);
-
-	return rc;
+    char Buf[4096+256];
+    char buffer[4096];
+    time_t CurrentTime;
+    struct tm *tm;
+    va_list args;
+
+    va_start(args, fmt);
+    int rc = vsnprintf(buffer, sizeof(buffer), fmt, args);
+    va_end(args);
+
+    memset(Buf,0,sizeof(Buf));
+    CurrentTime = time(NULL);
+    tm=localtime(&CurrentTime);
+    sprintf(Buf,"echo \"%04d-%02d-%02d %02d:%02d:%02d - %s\" >> /Storage/SystemLog/[%04d.%02d]SystemLog",
+            tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,
+            buffer,
+            tm->tm_year+1900,tm->tm_mon+1);
+    system(Buf);
+
+    return rc;
 }
 
 char* getTimeString(void)
 {
-	char *result=malloc(21);
-	time_t timep;
-	struct tm *p;
-	time(&timep);
-	p=gmtime(&timep);
+    char *result=malloc(21);
+    time_t timep;
+    struct tm *p;
+    time(&timep);
+    p=gmtime(&timep);
 
-	sprintf(result, "[%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);
+    sprintf(result, "[%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);
 
-	return result;
+    return result;
 }
 
 void PRINTF_FUNC(char *string, ...)
 {
-	if (DEBUG)
-	{
-		va_list args;
-		char buffer[4096];
-
-		va_start(args, string);
-		vsnprintf(buffer, sizeof(buffer), string, args);
-		va_end(args);
-		printf("%s \n", buffer);
-	}
+    va_list args;
+    char buffer[4096];
+    va_start(args, string);
+    vsnprintf(buffer, sizeof(buffer), string, args);
+    va_end(args);
+
+    if (ShmSysConfigAndInfo->SysConfig.SwitchDebugFlag == YES)
+        printf("%s \n", buffer);
+    else
+        DEBUG_INFO("%s \n", buffer);
 }
 
 //==========================================
@@ -68,42 +70,42 @@ void PRINTF_FUNC(char *string, ...)
 //==========================================
 int InitShareMemory()
 {
-	int result = PASS;
-	int MeterSMId;
+    int result = PASS;
+    int MeterSMId;
 
-	//creat ShmSysConfigAndInfo
-	if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo),  0777)) < 0)
+    //creat ShmSysConfigAndInfo
+    if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo),  0777)) < 0)
     {
-		#ifdef SystemLogMessage
-		DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
-		#endif
-		result = FAIL;
-	}
+        #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;
-   	 }
+        #ifdef SystemLogMessage
+        DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
+        #endif
+        result = FAIL;
+     }
     else
     {}
 
-   	 //creat ShmStatusCodeData
-   	 if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData),  0777)) < 0)
+     //creat ShmStatusCodeData
+     if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData),  0777)) < 0)
     {
-		#ifdef SystemLogMessage
-   		DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
-		#endif
-   		result = FAIL;
-	}
+        #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;
-   	}
+        #ifdef SystemLogMessage
+        DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
+        #endif
+        result = FAIL;
+    }
     else
     {}
 
@@ -115,78 +117,75 @@ int InitShareMemory()
 //==========================================
 int CreateCommunicationLcmPort()
 {
-	int fd;
-	struct termios tios;
-
-	fd = open(pPortName, O_RDWR);
-	if (fd <= 0) {
-		#ifdef SystemLogMessage
-		DEBUG_ERROR("open /dev/ttyS3 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) 5;
-	tios.c_lflag = 0;
-	tcflush(fd, TCIFLUSH);
-	ioctl(fd, TCSETS, &tios);
-
-	return fd;
+    int fd;
+    struct termios tios;
+
+    fd = open(pPortName, O_RDWR);
+    if (fd <= 0) {
+        #ifdef SystemLogMessage
+        DEBUG_ERROR("open /dev/ttyS3 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) 5;
+    tios.c_lflag = 0;
+    tcflush(fd, TCIFLUSH);
+    ioctl(fd, TCSETS, &tios);
+
+    return fd;
 }
 
 void CloseCommunicationLcmPort()
 {
-	close(_port);
+    close(_port);
 }
 
 void WriteCmdToLcm(byte *cmd, byte cmdLen)
 {
-	int len = write(_port, cmd, cmdLen);
-	if(len >= sizeof(cmd))
-	{
-		//PRINTF_FUNC("Write cmd to LCM successfully. \n");
-	}
+    int len = write(_port, cmd, cmdLen);
+    if(len >= sizeof(cmd))
+    {
+        //PRINTF_FUNC("Write cmd to LCM successfully. \n");
+    }
 }
 
 void ReadMsgFromLcm(byte *msg, byte readLen)
 {
-	read(_port, msg, readLen);
-
-	if(*msg == CMD_TITLE_1 && *(msg + 1) == CMD_TITLE_2)
-	{
-		if(*(msg + 3) == CMD_WRITE)
-		{
-			switch (*(msg + 4))
-			{
-				case CMD_REGISTER:
-				{
-					// 頁面
-					_currentPage = (unsigned short) (*(msg + 6) << 8) + (unsigned short) *(msg + 7);
-				}
-				break;
-			}
-		}
-		else if (*(msg + 3) == CMD_MULTI_READ)
-		{
-//			switch ((unsigned short) (*(msg + 4) << 8) + (unsigned short) *(msg + 5))
-//			{
-//				case BUTTON_GUN_INDEX:
-//				{
-//					// 當前選的槍號
-//					_curGunIndex = (*(msg + 8));
-//				}
-//				break;
-//			}
-		}
-	}
-
-//	for (byte idx = 0; idx < len; idx++)
-//		PRINTF_FUNC("[system_command]-RX: %X\n", *(msg + idx));
+    read(_port, msg, readLen);
+
+    if(*msg == CMD_TITLE_1 && *(msg + 1) == CMD_TITLE_2)
+    {
+        if(*(msg + 3) == CMD_WRITE)
+        {
+            switch (*(msg + 4))
+            {
+                case CMD_REGISTER:
+                {
+                    // ��𢒰
+                    strcpy((char *)ShmSysConfigAndInfo->SysInfo.LcmHwRev, moduleName);
+                }
+                break;
+            }
+        }
+        else if (*(msg + 3) == CMD_MULTI_READ)
+        {
+//          switch ((unsigned short) (*(msg + 4) << 8) + (unsigned short) *(msg + 5))
+//          {
+//              case BUTTON_GUN_INDEX:
+//              {
+//                  // �嗅��貊�瑽滩�
+//                  _curGunIndex = (*(msg + 8));
+//              }
+//              break;
+//          }
+        }
+    }
 }
 
 //================================================
@@ -194,109 +193,109 @@ void ReadMsgFromLcm(byte *msg, byte readLen)
 //================================================
 void ChangeToOtherPage(short newPage)
 {
-	byte cmd[7];
-	memset(cmd, 0x00, sizeof(cmd));
-
-	cmd[0] = CMD_TITLE_1;
-	cmd[1] = CMD_TITLE_2;
-	cmd[2] = 0x02 + sizeof(newPage);
-	cmd[3] = CMD_READ;
-	cmd[4] = CMD_REGISTER;
-	cmd[5] = newPage >> 8;
-	cmd[6] = newPage & 0x00FF;
-
-	WriteCmdToLcm(cmd, ARRAY_SIZE(cmd));
-	usleep(100000);
+    byte cmd[7];
+    memset(cmd, 0x00, sizeof(cmd));
+
+    cmd[0] = CMD_TITLE_1;
+    cmd[1] = CMD_TITLE_2;
+    cmd[2] = 0x02 + sizeof(newPage);
+    cmd[3] = CMD_READ;
+    cmd[4] = CMD_REGISTER;
+    cmd[5] = newPage >> 8;
+    cmd[6] = newPage & 0x00FF;
+
+    WriteCmdToLcm(cmd, ARRAY_SIZE(cmd));
+    usleep(100000);
 }
 
 void ChangeBackLight(bool islight)
 {
-	byte value = 0x01;
-
-	if (islight)
-	{
-		value = 0x20;
-	}
-	byte cmd[7];
-	memset(cmd, 0x00, sizeof(cmd));
-
-	cmd[0] = CMD_TITLE_1;
-	cmd[1] = CMD_TITLE_2;
-	cmd[2] = 0x03;
-	cmd[3] = CMD_READ;
-	cmd[4] = CMD_BACKLIGHT;
-	cmd[5] = value;
+    byte value = 0x01;
 
-	WriteCmdToLcm(cmd, ARRAY_SIZE(cmd));
-	usleep(100000);
+    if (islight)
+    {
+        value = 0x20;
+    }
+    byte cmd[7];
+    memset(cmd, 0x00, sizeof(cmd));
+
+    cmd[0] = CMD_TITLE_1;
+    cmd[1] = CMD_TITLE_2;
+    cmd[2] = 0x03;
+    cmd[3] = CMD_READ;
+    cmd[4] = CMD_BACKLIGHT;
+    cmd[5] = value;
+
+    WriteCmdToLcm(cmd, ARRAY_SIZE(cmd));
+    usleep(100000);
 }
 
 void GetCurrentPage()
 {
-	byte cmd[6];
-	memset(cmd, 0x00, sizeof(cmd));
-	byte msg[8];
-	memset(msg, 0x00, sizeof(msg));
-
-	cmd[0] = CMD_TITLE_1;
-	cmd[1] = CMD_TITLE_2;
-	cmd[2] = 0x03;				// 底下總長度
-	cmd[3] = CMD_WRITE;
-	cmd[4] = CMD_REGISTER;
-	cmd[5] = 0x02;
-
-	WriteCmdToLcm(cmd, ARRAY_SIZE(cmd));
-	usleep(100000);
-	ReadMsgFromLcm(msg, ARRAY_SIZE(msg));
+    byte cmd[6];
+    memset(cmd, 0x00, sizeof(cmd));
+    byte msg[8];
+    memset(msg, 0x00, sizeof(msg));
+
+    cmd[0] = CMD_TITLE_1;
+    cmd[1] = CMD_TITLE_2;
+    cmd[2] = 0x03;              // 摨蓥�蝮賡𩑈摨�
+    cmd[3] = CMD_WRITE;
+    cmd[4] = CMD_REGISTER;
+    cmd[5] = 0x02;
+
+    WriteCmdToLcm(cmd, ARRAY_SIZE(cmd));
+    usleep(100000);
+    ReadMsgFromLcm(msg, ARRAY_SIZE(msg));
 }
 
 void DisplayValueToLcm(short address, byte *data, byte len)
 {
-	byte cmd[256];
-	memset(cmd, 0x00, sizeof(cmd));
+    byte cmd[256];
+    memset(cmd, 0x00, sizeof(cmd));
 
-	cmd[0] = CMD_TITLE_1;
-	cmd[1] = CMD_TITLE_2;
-	cmd[2] = 0x03 + len;
-	cmd[3] = CMD_MULTI_WRITE;
-	cmd[4] = address >> 8;
-	cmd[5] = address & 0x00FF;
+    cmd[0] = CMD_TITLE_1;
+    cmd[1] = CMD_TITLE_2;
+    cmd[2] = 0x03 + len;
+    cmd[3] = CMD_MULTI_WRITE;
+    cmd[4] = address >> 8;
+    cmd[5] = address & 0x00FF;
 
-	for(byte count = 0; count < len; count++)
-	{
-		cmd[6 + count] = *(data + count);
-	}
+    for(byte count = 0; count < len; count++)
+    {
+        cmd[6 + count] = *(data + count);
+    }
 
-	WriteCmdToLcm(cmd, cmd[2] + 3);
+    WriteCmdToLcm(cmd, cmd[2] + 3);
 }
 
 void ChangeDisplay2Value(short address, short value)
 {
-	byte data[2];
-	data[0] = value >> 8;
-	data[1] = value & 0x00FF;
+    byte data[2];
+    data[0] = value >> 8;
+    data[1] = value & 0x00FF;
 
-	DisplayValueToLcm(address, data, sizeof(data));
+    DisplayValueToLcm(address, data, sizeof(data));
 }
 
 void GetBtnStatus(short address, byte len)
 {
-	byte cmd[8];
-	memset(cmd, 0x00, sizeof(cmd));
-	byte msg[8];
-	memset(msg, 0x00, sizeof(msg));
-
-	cmd[0] = CMD_TITLE_1;
-	cmd[1] = CMD_TITLE_2;
-	cmd[2] = 0x03 + len;
-	cmd[3] = CMD_MULTI_READ;
-	cmd[4] = address >> 8;
-	cmd[5] = address & 0x00FF;
-	cmd[6] = 0x00 + len;
-
-	WriteCmdToLcm(cmd, cmd[2] + 3);
-	usleep(100000);
-	ReadMsgFromLcm(msg, (len * 2) + sizeof(msg));
+    byte cmd[8];
+    memset(cmd, 0x00, sizeof(cmd));
+    byte msg[8];
+    memset(msg, 0x00, sizeof(msg));
+
+    cmd[0] = CMD_TITLE_1;
+    cmd[1] = CMD_TITLE_2;
+    cmd[2] = 0x03 + len;
+    cmd[3] = CMD_MULTI_READ;
+    cmd[4] = address >> 8;
+    cmd[5] = address & 0x00FF;
+    cmd[6] = 0x00 + len;
+
+    WriteCmdToLcm(cmd, cmd[2] + 3);
+    usleep(100000);
+    ReadMsgFromLcm(msg, (len * 2) + sizeof(msg));
 }
 
 //================================================
@@ -319,36 +318,36 @@ void string2ByteArray(unsigned char *input, byte *output)
 
 void ChangeWarningFunc()
 {
-	byte cmd[7];
-	byte i = 0;
-	//PRINTF_FUNC("ChangeWarningFunc \n");
-	// 最多一次五筆
-	//PRINTF_FUNC("LCM PageIndex = %d \n", ShmSysConfigAndInfo->SysWarningInfo.PageIndex);
-	//PRINTF_FUNC("WarningCount = %d \n", ShmSysConfigAndInfo->SysWarningInfo.WarningCount);
-	for(i = 0; (i + ShmSysConfigAndInfo->SysWarningInfo.PageIndex * 5) < ShmSysConfigAndInfo->SysWarningInfo.WarningCount; i++)
-	{
-		memset(cmd, 0x00, sizeof(cmd));
-		if(i >= 5)
-		{
-			break;
-		}
-		//error code
-		string2ByteArray(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i + ShmSysConfigAndInfo->SysWarningInfo.PageIndex * 5][0], cmd);
-		DisplayValueToLcm(0x0010 + (i * 6), cmd, sizeof(cmd));
-		//警告標示
-		memset(cmd, 0x00, sizeof(cmd));
-
-		cmd[0] = 0x00;
-		cmd[1] = 0x01;
-		DisplayValueToLcm(0x0002 + (i * 2), cmd, 2);
-	}
-
-	memset(cmd, 0x00, sizeof(cmd));
-	for(; i < 5; i++)
-	{
-		DisplayValueToLcm(0x0010 + (i * 6), cmd, sizeof(cmd));
-		DisplayValueToLcm(0x0002 + (i * 2), cmd, 2);
-	}
+    byte cmd[7];
+    byte i = 0;
+    //PRINTF_FUNC("ChangeWarningFunc \n");
+    // ��憭帋�甈∩�蝑�
+    //PRINTF_FUNC("LCM PageIndex = %d \n", ShmSysConfigAndInfo->SysWarningInfo.PageIndex);
+    //PRINTF_FUNC("WarningCount = %d \n", ShmSysConfigAndInfo->SysWarningInfo.WarningCount);
+    for(i = 0; (i + ShmSysConfigAndInfo->SysWarningInfo.PageIndex * 5) < ShmSysConfigAndInfo->SysWarningInfo.WarningCount; i++)
+    {
+        memset(cmd, 0x00, sizeof(cmd));
+        if(i >= 5)
+        {
+            break;
+        }
+        //error code
+        string2ByteArray(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i + ShmSysConfigAndInfo->SysWarningInfo.PageIndex * 5][0], cmd);
+        DisplayValueToLcm(0x0010 + (i * 6), cmd, sizeof(cmd));
+        //霅血�璅嗵內
+        memset(cmd, 0x00, sizeof(cmd));
+
+        cmd[0] = 0x00;
+        cmd[1] = 0x01;
+        DisplayValueToLcm(0x0002 + (i * 2), cmd, 2);
+    }
+
+    memset(cmd, 0x00, sizeof(cmd));
+    for(; i < 5; i++)
+    {
+        DisplayValueToLcm(0x0010 + (i * 6), cmd, sizeof(cmd));
+        DisplayValueToLcm(0x0002 + (i * 2), cmd, 2);
+    }
 }
 
 //================================================
@@ -356,34 +355,34 @@ void ChangeWarningFunc()
 //================================================
 void ChangeQrCode_Idle(char *input)
 {
-	int len = strlen(input);
-	byte cmd[len];
+    int len = strlen(input);
+    byte cmd[len];
 
-	int loop = 0;
-	int i = 0;
+    int loop = 0;
+    int i = 0;
 
-	while(input[loop] != '\0')
-	{
-		cmd[i++] = input[loop++];
-	}
+    while(input[loop] != '\0')
+    {
+        cmd[i++] = input[loop++];
+    }
 
-	DisplayValueToLcm(__qr_code, cmd, len);
+    DisplayValueToLcm(__qr_code, cmd, len);
 }
 
 void ChangeQrCode_Charge(char *input)
 {
-	int len = strlen(input);
-	byte cmd[len];
+    int len = strlen(input);
+    byte cmd[len];
 
-	int loop = 0;
-	int i = 0;
+    int loop = 0;
+    int i = 0;
 
-	while(input[loop] != '\0')
-	{
-		cmd[i++] = input[loop++];
-	}
+    while(input[loop] != '\0')
+    {
+        cmd[i++] = input[loop++];
+    }
 
-	DisplayValueToLcm(__qr_code_pre, cmd, len);
+    DisplayValueToLcm(__qr_code_pre, cmd, len);
 }
 
 //================================================
@@ -391,13 +390,13 @@ void ChangeQrCode_Charge(char *input)
 //================================================
 void ChangeCurPage()
 {
-	//PRINTF_FUNC("cur = %d, new = %d \n", _currentPage, ShmSysConfigAndInfo->SysInfo.PageIndex);
-	if (_currentPage != ShmSysConfigAndInfo->SysInfo.PageIndex)
-	{
-		_currentPage = ShmSysConfigAndInfo->SysInfo.PageIndex;
-		ChangeToOtherPage(_currentPage);
-		_everyPageRollChange = 0;
-	}
+    //PRINTF_FUNC("cur = %d, new = %d \n", _currentPage, ShmSysConfigAndInfo->SysInfo.PageIndex);
+    if (_currentPage != ShmSysConfigAndInfo->SysInfo.PageIndex)
+    {
+        _currentPage = ShmSysConfigAndInfo->SysInfo.PageIndex;
+        ChangeToOtherPage(_currentPage);
+        _everyPageRollChange = 0;
+    }
 }
 
 //================================================
@@ -406,35 +405,35 @@ void ChangeCurPage()
 byte demoCount = 0;
 void DemoFunction()
 {
-	if (demoCount == 0)
-	{
-		ShmSysConfigAndInfo->SysWarningInfo.WarningCount = 6;
-		memcpy(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[0][0], "000001", 7);
-		memcpy(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[1][0], "000002", 7);
-		memcpy(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[2][0], "000003", 7);
-		memcpy(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[3][0], "000004", 7);
-		memcpy(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[4][0], "000005", 7);
-		memcpy(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[5][0], "000006", 7);
-	}
-	else
-	{
-		if (demoCount == 20) {
-			ShmSysConfigAndInfo->SysInfo.PageIndex = _LCM_IDLE;
-		} else if (demoCount == 80) {
-			ShmSysConfigAndInfo->SysInfo.PageIndex = _LCM_AUTHORIZING;
-		} else if (demoCount == 100) {
-			ShmSysConfigAndInfo->SysInfo.PageIndex = _LCM_AUTHORIZ_COMP;
-		} else if (demoCount == 120) {
-			ShmSysConfigAndInfo->SysInfo.PageIndex = _LCM_AUTHORIZ_FAIL;
-		} else if (demoCount == 140) {
-			ShmSysConfigAndInfo->SysInfo.PageIndex = _LCM_PRE_CHARGE;
-		} else if (demoCount == 180) {
-			ShmSysConfigAndInfo->SysInfo.PageIndex = _LCM_CHARGING;
-		}
-	}
-
-	if (demoCount < 180)
-		demoCount++;
+    if (demoCount == 0)
+    {
+        ShmSysConfigAndInfo->SysWarningInfo.WarningCount = 6;
+        memcpy(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[0][0], "000001", 7);
+        memcpy(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[1][0], "000002", 7);
+        memcpy(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[2][0], "000003", 7);
+        memcpy(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[3][0], "000004", 7);
+        memcpy(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[4][0], "000005", 7);
+        memcpy(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[5][0], "000006", 7);
+    }
+    else
+    {
+        if (demoCount == 20) {
+            ShmSysConfigAndInfo->SysInfo.PageIndex = _LCM_IDLE;
+        } else if (demoCount == 80) {
+            ShmSysConfigAndInfo->SysInfo.PageIndex = _LCM_AUTHORIZING;
+        } else if (demoCount == 100) {
+            ShmSysConfigAndInfo->SysInfo.PageIndex = _LCM_AUTHORIZ_COMP;
+        } else if (demoCount == 120) {
+            ShmSysConfigAndInfo->SysInfo.PageIndex = _LCM_AUTHORIZ_FAIL;
+        } else if (demoCount == 140) {
+            ShmSysConfigAndInfo->SysInfo.PageIndex = _LCM_PRE_CHARGE;
+        } else if (demoCount == 180) {
+            ShmSysConfigAndInfo->SysInfo.PageIndex = _LCM_CHARGING;
+        }
+    }
+
+    if (demoCount < 180)
+        demoCount++;
 }
 
 //================================================
@@ -442,463 +441,823 @@ void DemoFunction()
 //================================================
 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;
+    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 ChangeBattMapAndValue(short page, int soc)
+bool FindAcChargingInfoData(byte target, struct ChargingInfoData **acChargingData)
 {
-//	srand(time(NULL));
-//	int min = 10;
-//	int max = 90;
-//	soc = rand() % (max - min + 1) + min;
-
-	if (page == _LCM_CHARGING)
-	{
-		if (soc < 20)
-			ChangeDisplay2Value(__batt_map, _battery_cap_20);
-		else if (soc >= 20 && soc < 40)
-			ChangeDisplay2Value(__batt_map, _battery_cap_40);
-		else if (soc >= 40 && soc < 60)
-			ChangeDisplay2Value(__batt_map, _battery_cap_60);
-		else if (soc >= 60 && soc < 80)
-			ChangeDisplay2Value(__batt_map, _battery_cap_80);
-		else if (soc >= 80 && soc <= 100)
-			ChangeDisplay2Value(__batt_map, _battery_cap_100);
-	}
-	else if (page == _LCM_COMPLETE)
-	{
-		if (soc < 20)
-			ChangeDisplay2Value(__batt_map, _battery_soc_20);
-		else if (soc >= 20 && soc < 40)
-			ChangeDisplay2Value(__batt_map, _battery_soc_40);
-		else if (soc >= 40 && soc < 60)
-			ChangeDisplay2Value(__batt_map, _battery_soc_60);
-		else if (soc >= 60 && soc < 80)
-			ChangeDisplay2Value(__batt_map, _battery_soc_80);
-		else if (soc >= 80 && soc <= 100)
-			ChangeDisplay2Value(__batt_map, _battery_soc_100);
-	}
-
-	byte cmd[4];
-	byte value[4];
-
-	memset(cmd, 0x00, sizeof(cmd));
-	sprintf((char *)value, "%d%%", soc);
-	string2ByteArray(value, cmd);
-	DisplayValueToLcm(__soc_value_charging, cmd, sizeof(cmd));
+    if (target < AC_QUANTITY)
+    {
+        acChargingData[target] = &ShmSysConfigAndInfo->SysInfo.AcChargingData[target];
+        return true;
+    }
+
+    return false;
 }
 
-void ChangeRemainTime(int sec)
+void ChangeAcBattMapAndValue(short page)
+{
+    if (page == _LCM_CHARGING)
+    {
+        if (isDiffStatus != _battery_display_ani)
+        {
+            isChangeBattMap = false;
+            isDiffStatus = _battery_display_ani;
+        }
+
+        if (ac_chargingInfo[0]->IsCharging && !isChangeBattMap)
+        {
+            isChangeBattMap = true;
+            if (ac_ani_battery_level == _BATTERY_LEVEL_FOR_MAP_LV5)
+            {
+                ChangeDisplay2Value(__batt_map, _battery_empty);
+                ac_ani_battery_level = _BATTERY_LEVEL_FOR_MAP_EMP;
+            }
+            else if (ac_ani_battery_level == _BATTERY_LEVEL_FOR_MAP_EMP)
+            {
+                ChangeDisplay2Value(__batt_map, _battery_cap_20);
+                ac_ani_battery_level = _BATTERY_LEVEL_FOR_MAP_LV1;
+            }
+            else if (ac_ani_battery_level == _BATTERY_LEVEL_FOR_MAP_LV1)
+            {
+                ChangeDisplay2Value(__batt_map, _battery_cap_40);
+                ac_ani_battery_level = _BATTERY_LEVEL_FOR_MAP_LV2;
+            }
+            else if (ac_ani_battery_level == _BATTERY_LEVEL_FOR_MAP_LV2)
+            {
+                ChangeDisplay2Value(__batt_map, _battery_cap_60);
+                ac_ani_battery_level = _BATTERY_LEVEL_FOR_MAP_LV3;
+            }
+            else if (ac_ani_battery_level == _BATTERY_LEVEL_FOR_MAP_LV3)
+            {
+                ChangeDisplay2Value(__batt_map, _battery_cap_80);
+                ac_ani_battery_level = _BATTERY_LEVEL_FOR_MAP_LV4;
+            }
+            else if (ac_ani_battery_level == _BATTERY_LEVEL_FOR_MAP_LV4)
+            {
+                ChangeDisplay2Value(__batt_map, _battery_cap_100);
+                ac_ani_battery_level = _BATTERY_LEVEL_FOR_MAP_LV5;
+            }
+        }
+    }
+    else if (page == _LCM_COMPLETE)
+    {
+        if (ac_ani_battery_level == _BATTERY_LEVEL_FOR_MAP_LV5)
+            ChangeDisplay2Value(__batt_map, _battery_soc_20);
+        else if (ac_ani_battery_level == _BATTERY_LEVEL_FOR_MAP_EMP)
+            ChangeDisplay2Value(__batt_map, _battery_soc_20);
+        else if (ac_ani_battery_level == _BATTERY_LEVEL_FOR_MAP_LV1)
+            ChangeDisplay2Value(__batt_map, _battery_soc_40);
+        else if (ac_ani_battery_level == _BATTERY_LEVEL_FOR_MAP_LV2)
+            ChangeDisplay2Value(__batt_map, _battery_soc_60);
+        else if (ac_ani_battery_level == _BATTERY_LEVEL_FOR_MAP_LV3)
+            ChangeDisplay2Value(__batt_map, _battery_soc_80);
+        else if (ac_ani_battery_level == _BATTERY_LEVEL_FOR_MAP_LV4)
+            ChangeDisplay2Value(__batt_map, _battery_soc_100);
+    }
+
+    ChangeDisplay2Value(__soc_value_charging, _disappear);
+}
+
+void ChangeBattMapAndValue(short page, int soc)
 {
-	int h, m, s;
-	byte cmd[10];
-	byte value[10];
+//  srand(time(NULL));
+//  int min = 10;
+//  int max = 90;
+//  soc = rand() % (max - min + 1) + min;
 
-	memset(cmd, 0x00, sizeof(cmd));
+    if (page == _LCM_CHARGING)
+    {
+        if (soc < 20)
+        {
+            if (_battery_display_ani)
+                ChangeDisplay2Value(__batt_map, _battery_empty);
+            else
+            ChangeDisplay2Value(__batt_map, _battery_cap_20);
+        }
+        else if (soc >= 20 && soc < 40)
+        {
+            if (_battery_display_ani)
+                ChangeDisplay2Value(__batt_map, _battery_cap_20);
+            else
+            ChangeDisplay2Value(__batt_map, _battery_cap_40);
+        }
+        else if (soc >= 40 && soc < 60)
+        {
+            if (_battery_display_ani)
+                ChangeDisplay2Value(__batt_map, _battery_cap_40);
+            else
+            ChangeDisplay2Value(__batt_map, _battery_cap_60);
+        }
+        else if (soc >= 60 && soc < 80)
+        {
+            if (_battery_display_ani)
+                ChangeDisplay2Value(__batt_map, _battery_cap_60);
+            else
+            ChangeDisplay2Value(__batt_map, _battery_cap_80);
+        }
+        else if (soc >= 80 && soc <= 100)
+            ChangeDisplay2Value(__batt_map, _battery_cap_100);
+    }
+    else if (page == _LCM_COMPLETE)
+    {
+        if (soc < 20)
+            ChangeDisplay2Value(__batt_map, _battery_soc_20);
+        else if (soc >= 20 && soc < 40)
+            ChangeDisplay2Value(__batt_map, _battery_soc_40);
+        else if (soc >= 40 && soc < 60)
+            ChangeDisplay2Value(__batt_map, _battery_soc_60);
+        else if (soc >= 60 && soc < 80)
+            ChangeDisplay2Value(__batt_map, _battery_soc_80);
+        else if (soc >= 80 && soc <= 100)
+            ChangeDisplay2Value(__batt_map, _battery_soc_100);
+    }
 
-//	srand(time(NULL));
-//	int min = 0;
-//	int max = 65536;
-//	sec = rand() % (max - min + 1) + min;
+    byte cmd[5];
+    byte value[5];
 
-	h = (sec / 3600);
-	m = (sec - (3600 * h)) / 60;
-	s = (sec - (3600 * h) - (m * 60));
-	sprintf((char *)value, "%02d:%02d:%02d", h, m, s);
-	string2ByteArray(value, cmd);
-	DisplayValueToLcm(__remain_time_tx, cmd, sizeof(cmd));
+    memset(cmd, 0x00, sizeof(cmd));
+    memset(value, 0x00, sizeof(value));
+    sprintf((char *)value, "%d%%", soc);
+    string2ByteArray(value, cmd);
+    DisplayValueToLcm(__soc_value_charging, cmd, sizeof(cmd));
 }
 
-void ChangeChargingEnergyValue(float energy)
+void ChangeRemainTime(int sec)
 {
-	byte cmd[10];
-	byte value[10];
+    int h, m, s;
+    byte cmd[10];
+    byte value[10];
+
+    memset(cmd, 0x00, sizeof(cmd));
+
+//  srand(time(NULL));
+//  int min = 0;
+//  int max = 65536;
+//  sec = rand() % (max - min + 1) + min;
+
+    h = (sec / 3600);
+    m = (sec - (3600 * h)) / 60;
+    s = (sec - (3600 * h) - (m * 60));
+    sprintf((char *)value, "%02d:%02d:%02d", h, m, s);
+    string2ByteArray(value, cmd);
+    DisplayValueToLcm(__remain_time_tx, cmd, sizeof(cmd));
+}
 
-	memset(cmd, 0x00, sizeof(cmd));
+void ChangeChargingEnergyValue(float energy)
+{
+    byte cmd[10];
+    byte value[10];
 
-	sprintf((char *) value, "%.1f kWh", energy);
-	string2ByteArray(value, cmd);
-	DisplayValueToLcm(__total_out_eng_tx, cmd, sizeof(cmd));
+    memset(cmd, 0x00, sizeof(cmd));
+    if (energy >= 0.05)
+    {
+        energy -= 0.05;
+    }
+    sprintf((char *) value, "%.1f kWh", energy);
+    string2ByteArray(value, cmd);
+    DisplayValueToLcm(__total_out_eng_tx, cmd, sizeof(cmd));
 }
 
 void ChangeChargingPowerValue(float pow)
 {
-	byte cmd[10];
-	byte value[10];
+    byte cmd[10];
+    byte value[10];
 
-	memset(cmd, 0x00, sizeof(cmd));
+    memset(cmd, 0x00, sizeof(cmd));
+
+//  float min = 0.0;
+//  float max = 50;
+//  pow = (max - min) * rand() / (RAND_MAX + 1.0) + min;
+    sprintf((char *) value, "%.1f kW", pow);
+    string2ByteArray(value, cmd);
+    DisplayValueToLcm(__output_eng_tx, cmd, sizeof(cmd));
+}
+
+void ChangeChargingFeeValue(float fee)
+{
+    byte cmd[10];
+    byte value[10];
 
-//	float min = 0.0;
-//	float max = 50;
-//	pow = (max - min) * rand() / (RAND_MAX + 1.0) + min;
+    memset(cmd, 0x00, sizeof(cmd));
 
-	sprintf((char *) value, "%.1f kW", pow);
-	string2ByteArray(value, cmd);
-	DisplayValueToLcm(__output_eng_tx, cmd, sizeof(cmd));
+    sprintf((char *) value, "%.2f", fee);
+    string2ByteArray(value, cmd);
+    DisplayValueToLcm(__charging_fee_tx, cmd, sizeof(cmd));
 }
 
-void ChangeStopMap(byte value)
+void DisplayMoneyRate(float money)
 {
+    byte cmd[8];
+    byte value[8];
 
+    memset(cmd, 0x00, sizeof(cmd));
+
+    sprintf((char *) value, "%.2f", money);
+    string2ByteArray(value, cmd);
+    DisplayValueToLcm(__money_by_rate, cmd, sizeof(cmd));
+}
+
+void DisplayMoneyCur(byte *cur)
+{
+    byte cmd[5];
+    byte buf[5];
+
+    *(cur + 3) = '\0';
+    memset(cmd, 0x00, sizeof(cmd));
+    sprintf((char *) buf, "%s", cur);
+    string2ByteArray(buf, cmd);
+    DisplayValueToLcm(__money_rate, cmd, sizeof(cmd));
 }
 
 void RefreshPageAnimation(byte value)
 {
-	switch(_currentPage)
-	{
-		case _LCM_IDLE:
-		{
-			if (value == 0)
-			{
-				ChangeToOtherPage(_currentPage);
-			}
-			else if (value == 15)
-			{
-				ChangeToOtherPage(_currentPage + 1);
-			}
-			else if (value == 30)
-			{
-				ChangeToOtherPage(_currentPage + 2);
-			}
-
-			_everyPageRollChange > 45 ? _everyPageRollChange = 0 : _everyPageRollChange++;
-		}
-			break;
-		case _LCM_WAIT_FOR_PLUG:
-		{
-			if(_everyPageRollChange == 0)
-				ChangeDisplay2Value(__plug_in_arrow, _arrow_dark);
-			else if(_everyPageRollChange == 15)
-				ChangeDisplay2Value(__plug_in_arrow, _arrow_light);
-
-			_everyPageRollChange > 30 ? _everyPageRollChange = 0 : _everyPageRollChange++;
-		}
-			break;
-		case _LCM_PRE_CHARGE:
-		case _LCM_CHARGING:
-		case _LCM_COMPLETE:
-		{
-			if (_currentPage == _LCM_PRE_CHARGE)
-			{
-				if (_everyPageRollChange == 0 || _everyPageRollChange == 22)
-					ChangeDisplay2Value(__conn_line, _conn_map1);
-				else if (_everyPageRollChange == 11 || _everyPageRollChange == 33)
-					ChangeDisplay2Value(__conn_line, _conn_map2);
-			}
-			else if (_currentPage == _LCM_CHARGING)
-			{
-				if (_everyPageRollChange == 0 || _everyPageRollChange == 22)
-					ChangeDisplay2Value(__conn_line_chag, _charging_map1);
-				else if (_everyPageRollChange == 11 || _everyPageRollChange == 33)
-					ChangeDisplay2Value(__conn_line_chag, _charging_map2);
-			}
-			else if (_currentPage == _LCM_COMPLETE)
-			{
-				if (_everyPageRollChange == 0)
-					ChangeDisplay2Value(__conn_line_comp, _complete_map);
-			}
-
-			if (_totalCount == 2 && _currentPage != _LCM_PRE_CHARGE)
-			{
-				byte index = 0;
-				for (index = 0; index < _totalCount; index++) {
-					if (ShmSysConfigAndInfo->SysInfo.CurGunSelected != index)
-					{
-						break;
-					}
-				}
-
-				ChangeDisplay2Value(__sel_gun_btn, _sel_gun_btn);
-				if (_chargingInfoData[index]->SystemStatus == S_IDLE ||
-						_chargingInfoData[index]->SystemStatus == S_RESERVATION)
-				{
-					if(value == 0)
-					{
-						ChangeDisplay2Value(__side_top, _side_rfid_1);
-						ChangeDisplay2Value(__side_down, _side_rfid_2);
-					}
-					else if (value == 15)
-					{
-						ChangeDisplay2Value(__side_top, _side_qr_1);
-						ChangeDisplay2Value(__side_down, _side_qr_2);
-					}
-					else if (value == 30)
-					{
-						ChangeDisplay2Value(__side_top, _side_app_1);
-						ChangeDisplay2Value(__side_down, _side_app_2);
-					}
-				}
-				else
-				{
-					ChangeDisplay2Value(__side_top, _disappear);
-					ChangeDisplay2Value(__side_down, _disappear);
-					ChangeDisplay2Value(__qr_code_pre, _disappear);
-				}
-			}
-			else
-			{
-				ChangeDisplay2Value(__sel_gun_btn, _disappear);
-				ChangeDisplay2Value(__side_top, _disappear);
-				ChangeDisplay2Value(__side_down, _disappear);
-				ChangeDisplay2Value(__qr_code_pre, _disappear);
-			}
-
-			_everyPageRollChange >= 45 ? _everyPageRollChange = 0 : _everyPageRollChange++;
-		}
-			break;
-	}
+    switch(_currentPage)
+    {
+        case _LCM_IDLE:
+        {
+
+        }
+            break;
+        case _LCM_WAIT_FOR_PLUG:
+        {
+            if(_everyPageRollChange == 0)
+                ChangeDisplay2Value(__plug_in_arrow, _arrow_dark);
+            else if(_everyPageRollChange == 15)
+                ChangeDisplay2Value(__plug_in_arrow, _arrow_light);
+
+            _everyPageRollChange > 30 ? _everyPageRollChange = 0 : _everyPageRollChange++;
+        }
+            break;
+        case _LCM_PRE_CHARGE:
+        case _LCM_CHARGING:
+        case _LCM_COMPLETE:
+        {
+            if (_currentPage == _LCM_PRE_CHARGE)
+            {
+                if (_everyPageRollChange == 0 || _everyPageRollChange == 22)
+                    ChangeDisplay2Value(__conn_line, _conn_map1);
+                else if (_everyPageRollChange == 11 || _everyPageRollChange == 33)
+                    ChangeDisplay2Value(__conn_line, _conn_map2);
+            }
+            else if (_currentPage == _LCM_CHARGING)
+            {
+                if (_everyPageRollChange == 0 || _everyPageRollChange == 22)
+                    ChangeDisplay2Value(__conn_line_chag, _charging_map1);
+                else if (_everyPageRollChange == 11 || _everyPageRollChange == 33)
+                    ChangeDisplay2Value(__conn_line_chag, _charging_map2);
+            }
+            else if (_currentPage == _LCM_COMPLETE)
+            {
+                if (_everyPageRollChange == 0)
+                    ChangeDisplay2Value(__conn_line_comp, _complete_map);
+            }
+
+            _everyPageRollChange >= 45 ? _everyPageRollChange = 0 : _everyPageRollChange++;
+        }
+            break;
+    }
 }
 
+#define WIFI_MODE_DISABLE           0
+#define WIFI_MODE_STA               1
+#define WIFI_MODE_AP                2
+#define WIFI_MODE_ADHOC             3
+
 void RefreshConnStatus()
 {
-	// Wifi priority is higher than Ethernet
-	if (ShmSysConfigAndInfo->SysConfig.AthInterface.WifiNetworkConn == YES)
-	{
-		_wifi_conn_status = true;
-		ChangeDisplay2Value(__wifi_status, _wifi_connect);
-		ChangeDisplay2Value(__ethernet_status, _disappear);
-	}
-	else
-	{
-		_wifi_conn_status = false;
-		ChangeDisplay2Value(__wifi_status, _disappear);
-	}
-
-	if (!_wifi_conn_status)
-	{
-		if (ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomNetworkConn == YES)
-		{
-			ChangeDisplay2Value(__ethernet_status, _ethernet_connect);
-		}
-		else
-		{
-			ChangeDisplay2Value(__ethernet_status, _ethernet_disconnect);
-		}
-	}
-
-	// 連線到後台
-	if (ShmSysConfigAndInfo->SysInfo.OcppConnStatus == YES)
-		ChangeDisplay2Value(__conn_status, _connect);
-	else
-		ChangeDisplay2Value(__conn_status, _disconnect);
+    // Wifi priority is higher than Ethernet
+    if(ShmSysConfigAndInfo->SysConfig.AthInterface.WifiMode == WIFI_MODE_STA)
+    {
+        if (ShmSysConfigAndInfo->SysConfig.AthInterface.WifiNetworkConn == YES)
+        {
+            _wifi_conn_status = true;
+            ChangeDisplay2Value(__ethernet_status, _disappear);
+            ChangeDisplay2Value(__wifi_status, _wifi_connect);
+        }
+        else
+        {
+            _wifi_conn_status = false;
+            if(ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomNetworkConn == YES)
+            {
+                ChangeDisplay2Value(__wifi_status, _disappear);
+                ChangeDisplay2Value(__ethernet_status, _ethernet_connect);
+            }
+            else
+            {
+                ChangeDisplay2Value(__ethernet_status, _disappear);
+                ChangeDisplay2Value(__wifi_status, _wifi_disconnect);
+            }
+        }
+    }
+    else
+    {
+        _wifi_conn_status = false;
+        ChangeDisplay2Value(__wifi_status, _disappear);
+ 
+        if (ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomNetworkConn == YES)
+        {
+            ChangeDisplay2Value(__ethernet_status, _ethernet_connect);
+        }
+        else
+        {
+            ChangeDisplay2Value(__ethernet_status, _ethernet_disconnect);
+        }
+    }
+
+    // ����啣���
+    if (ShmSysConfigAndInfo->SysInfo.OcppConnStatus == YES)
+        ChangeDisplay2Value(__conn_status, _connect);
+    else
+        ChangeDisplay2Value(__conn_status, _disconnect);
+}
+
+byte FirstPageChanged()
+{
+    byte result = NO;
+
+    if (_currentPage != _oldPage)
+    {
+        result = YES;
+        _oldPage = _currentPage;
+    }
+
+    return result;
 }
 
 void ProcessPageInfo()
 {
-	switch(_currentPage)
-	{
-		case _LCM_IDLE:
-		{
-			// QR Code 處理
-			ChangeQrCode_Idle("http://google.com.tw");
-		}
-			break;
-		case _LCM_PRE_CHARGE:
-		case _LCM_CHARGING:
-		case _LCM_COMPLETE:
-		{
-			// gun type and charging info
-			for(byte i = 0; i < _totalCount; i++)
-			{
-				switch(_chargingInfoData[i]->Type)
-				{
-					case _Type_Chademo:
-					{
-						if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == i)
-						{
-							ChangeDisplay2Value(__gun_type_index + (i * 2), _chademo_light);
-						}
-						else
-						{
-							ChangeDisplay2Value(__gun_type_index + (i * 2), _chademo_dark);
-						}
-					}
-						break;
-					case _Type_CCS_2:
-					{
-						if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == i)
-						{
-							ChangeDisplay2Value(__gun_type_index + (i * 2), _ccs_light);
-						}
-						else
-						{
-							ChangeDisplay2Value(__gun_type_index + (i * 2), _ccs_dark);
-						}
-					}
-						break;
-				}
-
-				if (_currentPage == _LCM_CHARGING)
-				{
-					if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == i)
-					{
-						ChangeBattMapAndValue(_LCM_CHARGING, _chargingInfoData[i]->EvBatterySoc);
-						if (_chargingInfoData[i]->RemainChargingDuration >= 0)
-							ChangeRemainTime(_chargingInfoData[i]->RemainChargingDuration);
-						if (_chargingInfoData[i]->PresentChargingPower >= 0)
-							ChangeChargingPowerValue(_chargingInfoData[i]->PresentChargingPower);
-						if (_chargingInfoData[i]->PresentChargedEnergy >= 0)
-							ChangeChargingEnergyValue(_chargingInfoData[i]->PresentChargedEnergy);
-
-						if (strcmp((char *)_chargingInfoData[i]->StartUserId, "") == 0)
-							ChangeDisplay2Value(__stop_method_btn, _stop_charging_btn);
-						else
-							ChangeDisplay2Value(__stop_method_btn, _stop_charging_btn_scan);
-					}
-				}
-				else if (_currentPage == _LCM_COMPLETE)
-				{
-					if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == i)
-					{
-						ChangeBattMapAndValue(_LCM_COMPLETE, _chargingInfoData[i]->EvBatterySoc);
-						if (_chargingInfoData[i]->RemainChargingDuration >= 0)
-							ChangeRemainTime(_chargingInfoData[i]->RemainChargingDuration);
-						if (_chargingInfoData[i]->PresentChargingPower >= 0)
-							ChangeChargingPowerValue(_chargingInfoData[i]->PresentChargingPower);
-						if (_chargingInfoData[i]->PresentChargedEnergy >= 0)
-							ChangeChargingEnergyValue(_chargingInfoData[i]->PresentChargedEnergy);
-					}
-				}
-			}
-
-			// gun btn and QR code
-			if (_totalCount == 2 && _currentPage != _LCM_PRE_CHARGE)
-			{
-				byte index = 0;
-				for(index = 0; index < _totalCount; index++)
-				{
-					if(ShmSysConfigAndInfo->SysInfo.CurGunSelected != index)
-					{
-						break;
-					}
-				}
-
-				if (_chargingInfoData[index]->SystemStatus == S_IDLE ||
-						_chargingInfoData[index]->SystemStatus == S_RESERVATION ||
-						_chargingInfoData[index]->SystemStatus == S_BOOTING)
-				{
-					// QR Code 處理
-					ChangeQrCode_Charge("http://google.com.tw");
-				}
-			}
-		}
-			break;
-	}
+    switch(_currentPage)
+    {
+        case _LCM_IDLE:
+        {
+            if (ShmSysConfigAndInfo->SysConfig.isRFID)
+                ChangeDisplay2Value(__main_rfid, _main_rfid);
+            else
+                ChangeDisplay2Value(__main_rfid, _main_none_rfid);
+
+            if (ShmSysConfigAndInfo->SysConfig.isQRCode)
+                ChangeDisplay2Value(__main_qr, _main_qr);
+            else
+            {
+                ChangeDisplay2Value(__qr_code, _disappear);
+                ChangeDisplay2Value(__main_qr, _main_none_qr);
+                needReloadQr = true;
+            }
+
+            if (ShmSysConfigAndInfo->SysConfig.isAPP)
+                ChangeDisplay2Value(__main_app, _main_app);
+            else
+                ChangeDisplay2Value(__main_app, _main_none_app);
+
+            if (FirstPageChanged() == YES || needReloadQr)
+            {
+                if (ShmSysConfigAndInfo->SysConfig.isQRCode)
+                {
+                    needReloadQr = false;
+                    ChangeQrCode_Idle("http://google.com.tw");
+                }
+            }
+        }
+            break;
+        case _LCM_AUTHORIZING:
+        case _LCM_AUTHORIZ_COMP:
+        case _LCM_AUTHORIZ_FAIL:
+        case _LCM_WAIT_FOR_PLUG:
+        {
+            FirstPageChanged();
+        }
+            break;
+        case _LCM_PRE_CHARGE:
+        case _LCM_CHARGING:
+        case _LCM_COMPLETE:
+        {
+            if (_totalCount + acgunCount >= 2)
+            {
+                ChangeDisplay2Value(__sel_gun_btn, _sel_gun_btn);
+
+                if (ShmSysConfigAndInfo->SysConfig.isRFID)
+                    ChangeDisplay2Value(__side_top, _side_rfid);
+                else
+                    ChangeDisplay2Value(__side_top, _side_none_rfid);
+
+                if (ShmSysConfigAndInfo->SysConfig.isQRCode)
+                    ChangeDisplay2Value(__side_mid, _side_qr);
+                else
+                {
+                    ChangeDisplay2Value(__qr_code_pre, _disappear);
+                    ChangeDisplay2Value(__side_mid, _side_none_qr);
+                    needReloadQr = true;
+                }
+
+                if (ShmSysConfigAndInfo->SysConfig.isAPP)
+                    ChangeDisplay2Value(__side_down, _side_app);
+                else
+                    ChangeDisplay2Value(__side_down, _side_none_app);
+            }
+            else
+            {
+                ChangeDisplay2Value(__side_top, _disappear);
+                ChangeDisplay2Value(__side_mid, _disappear);
+                ChangeDisplay2Value(__side_down, _disappear);
+                ChangeDisplay2Value(__sel_gun_btn, _disappear);
+            }
+
+            bool isShowAc = false;
+            if (acgunCount > 0)
+            {
+                if (ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc != NO_DEFINE)
+                {
+                    isShowAc = true;
+                    ChangeDisplay2Value(__gun_type_index + (2 * 2), _actype_light);
+
+                    if (_currentPage == _LCM_CHARGING)
+                    {
+                        ChangeAcBattMapAndValue(_LCM_CHARGING);
+                        if (ac_chargingInfo[0]->RemainChargingDuration >= 0)
+                            ChangeRemainTime(ac_chargingInfo[0]->RemainChargingDuration);
+                        else
+                            ChangeRemainTime(0);
+
+                        if (ac_chargingInfo[0]->PresentChargingPower >= 0.1)
+                            ChangeChargingPowerValue(ac_chargingInfo[0]->PresentChargingPower);
+                        else
+                            ChangeChargingPowerValue(0);
+
+                        if (ac_chargingInfo[0]->PresentChargedEnergy >= 0.1)
+                            ChangeChargingEnergyValue(ac_chargingInfo[0]->PresentChargedEnergy);
+                        else
+                            ChangeChargingEnergyValue(0);
+
+                        if (strcmp((char *)ac_chargingInfo[0]->StartUserId, "") == 0)
+                            ChangeDisplay2Value(__stop_method_btn, _stop_charging_btn);
+                        else
+                            ChangeDisplay2Value(__stop_method_btn, _stop_charging_btn_scan);
+                    }
+                    else if (_currentPage == _LCM_COMPLETE)
+                    {
+                        ChangeAcBattMapAndValue(_LCM_COMPLETE);
+                        if (ac_chargingInfo[0]->RemainChargingDuration >= 0)
+                            ChangeRemainTime(ac_chargingInfo[0]->RemainChargingDuration);
+                        else
+                            ChangeRemainTime(0);
+
+                        if (ac_chargingInfo[0]->PresentChargingPower >= 0.1)
+                            ChangeChargingPowerValue(ac_chargingInfo[0]->PresentChargingPower);
+                        else
+                            ChangeChargingPowerValue(0);
+
+                        if (ac_chargingInfo[0]->PresentChargedEnergy >= 0.1)
+                        {
+                            ChangeChargingEnergyValue(ac_chargingInfo[0]->PresentChargedEnergy);
+
+                            if (ShmSysConfigAndInfo->SysConfig.BillingData.isBilling &&
+                                    ac_chargingInfo[0]->ChargingFee >= 0)
+                            {
+                                ChangeChargingFeeValue(ac_chargingInfo[0]->ChargingFee);
+                            }
+                        }
+                        else
+                        {
+                            ChangeChargingEnergyValue(0);
+                            if (ShmSysConfigAndInfo->SysConfig.BillingData.isBilling)
+                                ChangeChargingFeeValue(0);
+                        }
+
+                        if(!ShmSysConfigAndInfo->SysConfig.BillingData.isBilling)
+                        {
+                            ChangeDisplay2Value(__charging_fee_map, _disappear);
+                            ChangeDisplay2Value(__charging_fee_tx, _disappear);
+                        }
+                        else
+                        {
+                            ChangeDisplay2Value(__charging_fee_map, _money_map);
+                        }
+                    }
+                }
+                else
+                    ChangeDisplay2Value(__gun_type_index + (2 * 2), _actype_dark);
+            }
+            else
+                ChangeDisplay2Value(__gun_type_index + (2 * 2), _disappear);
+
+            for(byte i = 0; i < _totalCount; i++)
+            {
+                switch(_chargingInfoData[i]->Type)
+                {
+                    case _Type_Chademo:
+                    {
+                        if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == i && !isShowAc)
+                        {
+                            ChangeDisplay2Value(__gun_type_index + (i * 2), _chademo_light);
+                        }
+                        else
+                        {
+                            ChangeDisplay2Value(__gun_type_index + (i * 2), _chademo_dark);
+                        }
+                    }
+                        break;
+                    case _Type_GB:
+                    {
+                        if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == i && !isShowAc)
+                        {
+                            ChangeDisplay2Value(__gun_type_index + (i * 2), _gbt_light);
+                        }
+                        else
+                        {
+                            ChangeDisplay2Value(__gun_type_index + (i * 2), _gbt_dark);
+                        }
+                    }
+                        break;
+                    case _Type_CCS_2:
+                    {
+                        if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == i && !isShowAc)
+                        {
+                            ChangeDisplay2Value(__gun_type_index + (i * 2), _ccs_light);
+                        }
+                        else
+                        {
+                            ChangeDisplay2Value(__gun_type_index + (i * 2), _ccs_dark);
+                        }
+                    }
+                        break;
+                }
+
+                if (_currentPage == _LCM_CHARGING && !isShowAc)
+                {
+                    if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == i)
+                    {
+                        ChangeBattMapAndValue(_LCM_CHARGING, _chargingInfoData[i]->EvBatterySoc);
+                        if (_chargingInfoData[i]->RemainChargingDuration >= 0)
+                            ChangeRemainTime(_chargingInfoData[i]->RemainChargingDuration);
+                        else
+                            ChangeRemainTime(0);
+
+                        if (_chargingInfoData[i]->PresentChargingPower >= 0)
+                            ChangeChargingPowerValue(_chargingInfoData[i]->PresentChargingPower);
+                        else
+                            ChangeChargingPowerValue(0);
+
+                        if (_chargingInfoData[i]->PresentChargedEnergy >= 0.1)
+                            ChangeChargingEnergyValue(_chargingInfoData[i]->PresentChargedEnergy);
+                        else
+                            ChangeChargingEnergyValue(0);
+
+                        if (strcmp((char *)_chargingInfoData[i]->StartUserId, "") == 0)
+                            ChangeDisplay2Value(__stop_method_btn, _stop_charging_btn);
+                        else
+                            ChangeDisplay2Value(__stop_method_btn, _stop_charging_btn_scan);
+                    }
+                }
+                else if (_currentPage == _LCM_COMPLETE && !isShowAc)
+                {
+                    if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == i)
+                    {
+                        ChangeBattMapAndValue(_LCM_COMPLETE, _chargingInfoData[i]->EvBatterySoc);
+                        if (_chargingInfoData[i]->RemainChargingDuration >= 0)
+                            ChangeRemainTime(_chargingInfoData[i]->RemainChargingDuration);
+                        else
+                            ChangeRemainTime(0);
+
+                        if (_chargingInfoData[i]->PresentChargingPower >= 0)
+                            ChangeChargingPowerValue(_chargingInfoData[i]->PresentChargingPower);
+                        else
+                            ChangeChargingPowerValue(0);
+
+                        if (_chargingInfoData[i]->PresentChargedEnergy >= 0.1)
+                        {
+                            ChangeChargingEnergyValue(_chargingInfoData[i]->PresentChargedEnergy);
+
+                            if (ShmSysConfigAndInfo->SysConfig.BillingData.isBilling &&
+                                _chargingInfoData[i]->ChargingFee >= 0)
+                            {
+                                ChangeChargingFeeValue(_chargingInfoData[i]->ChargingFee);
+                            }
+                        }
+                        else
+                        {
+                            ChangeChargingEnergyValue(0);
+                            if (ShmSysConfigAndInfo->SysConfig.BillingData.isBilling)
+                            ChangeChargingFeeValue(0);
+                        }
+
+                        if(!ShmSysConfigAndInfo->SysConfig.BillingData.isBilling)
+                        {
+                            ChangeDisplay2Value(__charging_fee_map, _disappear);
+                            ChangeDisplay2Value(__charging_fee_tx, _disappear);
+                        }
+                        else
+                        {
+                            ChangeDisplay2Value(__charging_fee_map, _money_map);
+                        }
+                    }
+                }
+            }
+
+            // gun btn and QR code
+            if (_totalCount + acgunCount >= 2 && _currentPage)
+            {
+                byte index = 0;
+                for(index = 0; index < _totalCount; index++)
+                {
+                    if(ShmSysConfigAndInfo->SysInfo.CurGunSelected != index)
+                    {
+                        break;
+                    }
+                }
+
+                if (_chargingInfoData[index]->SystemStatus == S_IDLE ||
+                        _chargingInfoData[index]->SystemStatus == S_RESERVATION ||
+                        _chargingInfoData[index]->SystemStatus == S_BOOTING)
+                {
+                    if (FirstPageChanged() == YES || needReloadQr)
+                    {
+                        if (ShmSysConfigAndInfo->SysConfig.isQRCode)
+                        {
+                            needReloadQr = false;
+                            ChangeQrCode_Charge("http://google.com.tw");
+                        }
+                    }
+                }
+            }
+        }
+            break;
+    }
+}
+
+void ChangeDisplayMoneyInfo()
+{
+    if (ShmSysConfigAndInfo->SysConfig.BillingData.isBilling)
+    {
+        struct timeb csuTime;
+        struct tm *tmCSU;
+
+        ftime(&csuTime);
+        tmCSU = localtime(&csuTime.time);
+
+        ChangeDisplay2Value(__money_rate_map, _charging_money);
+
+        if (tmCSU->tm_hour <= 23)
+        {
+            ShmSysConfigAndInfo->SysConfig.BillingData.Cur_fee = ShmSysConfigAndInfo->SysConfig.BillingData.Fee[tmCSU->tm_hour];
+            DisplayMoneyRate(ShmSysConfigAndInfo->SysConfig.BillingData.Cur_fee);
+        }
+
+        if (ShmSysConfigAndInfo->SysConfig.BillingData.Currency <= 53)
+            DisplayMoneyCur((byte *)Currency[ShmSysConfigAndInfo->SysConfig.BillingData.Currency]);
+    }
+    else
+    {
+        ChangeDisplay2Value(__money_rate_map, _disappear);
+        ChangeDisplay2Value(__money_by_rate, _disappear);
+        ChangeDisplay2Value(__money_rate, _disappear);
+    }
 }
 
 void Initialization()
 {
-	strcpy((char *)ShmSysConfigAndInfo->SysInfo.LcmHwRev, moduleName);
-
-	bool isPass = false;
-	byte count = 5;
-	while(!isPass && count > 0)
-	{
-		isPass = true;
-		for (byte _index = 0; _index < _totalCount; _index++)
-		{
-			if (!FindChargingInfoData(_index, &_chargingInfoData[0]))
-			{
-				DEBUG_ERROR("EvComm (main) : FindChargingInfoData false \n");
-				isPass = false;
-				count--;
-				break;
-			}
-		}
-	}
-
-	if (count == 0)
-		PRINTF_FUNC("LCM Initialization Gun Fail.............\n");
+    bool isPass = false;
+    byte count = 5;
+    while(!isPass && count > 0)
+    {
+        isPass = true;
+        for (byte _index = 0; _index < _totalCount; _index++)
+        {
+            if (!FindChargingInfoData(_index, &_chargingInfoData[0]))
+            {
+                DEBUG_ERROR("EvComm (main) : FindChargingInfoData false \n");
+                isPass = false;
+                count--;
+                break;
+            }
+        }
+    }
+
+    isPass = false;
+
+    if (acgunCount > 0)
+    {
+        while(!isPass)
+        {
+            isPass = true;
+            for (byte _index = 0; _index < acgunCount; _index++)
+            {
+                if (!FindAcChargingInfoData(_index, &ac_chargingInfo[0]))
+                {
+                    DEBUG_ERROR("EvComm : FindAcChargingInfoData false \n");
+                    isPass = false;
+                    break;
+                }
+            }
+        }
+    }
+
+    if (count == 0)
+        PRINTF_FUNC("LCM Initialization Gun Fail.............\n");
 }
 
 int main(void)
 {
-	if(InitShareMemory() == FAIL)
-	{
-		#ifdef SystemLogMessage
-		DEBUG_ERROR("InitShareMemory NG\n");
-		#endif
-		if (ShmStatusCodeData != NULL)
-		{
-			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory =	1;
-		}
-		sleep(5);
-		return 0;
-	}
-
-	_port = CreateCommunicationLcmPort();
-	byte changeWarningPriority = 0;
-	byte curWarningCount = 255;
-	//ChangeBackLight(true);
-	Initialization();
-
-//	ChangeToOtherPage(_LCM_FIX);
-//	return 0;
-	while(_port != -1)
-	{
-		//DemoFunction();
-
-		// Warning 處理
-		if(curWarningCount != ShmSysConfigAndInfo->SysWarningInfo.WarningCount)
-		{
-			changeWarningPriority = 0;
-			ShmSysConfigAndInfo->SysWarningInfo.PageIndex = 0;
-			curWarningCount = ShmSysConfigAndInfo->SysWarningInfo.WarningCount;
-			ChangeWarningFunc();
-		}
-		else if (ShmSysConfigAndInfo->SysWarningInfo.WarningCount > 5 && changeWarningPriority == 0)
-		{
-			// 當有兩頁 Warning 則每隔三秒改變一次
-			if(ShmSysConfigAndInfo->SysWarningInfo.PageIndex == 0)
-				ShmSysConfigAndInfo->SysWarningInfo.PageIndex = 1;
-			else
-				ShmSysConfigAndInfo->SysWarningInfo.PageIndex = 0;
-
-			ChangeWarningFunc();
-		}
-
-		// 頁面資訊處理
-		ProcessPageInfo();
-
-		// 網路 - wifi - 連線訊號處理
-		RefreshConnStatus();
-
-		// 換頁處理
-		ChangeCurPage();
-
-		RefreshPageAnimation(_everyPageRollChange);
-
-		changeWarningPriority >= 30 ? changeWarningPriority = 0 : changeWarningPriority++;
-		usleep(100000);
-	}
-
-	CloseCommunicationLcmPort();
-	return FAIL;
+    if(InitShareMemory() == FAIL)
+    {
+        #ifdef SystemLogMessage
+        DEBUG_ERROR("InitShareMemory NG\n");
+        #endif
+        if (ShmStatusCodeData != NULL)
+        {
+            ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory = 1;
+        }
+        sleep(5);
+        return 0;
+    }
+
+    _port = CreateCommunicationLcmPort();
+    byte changeWarningPriority = 0;
+    byte curWarningCount = 255;
+    ChangeBackLight(true);
+    _totalCount = ShmSysConfigAndInfo->SysConfig.TotalConnectorCount;
+    acgunCount = ShmSysConfigAndInfo->SysConfig.AcConnectorCount;
+    Initialization();
+
+    //return 0;
+
+    while(_port != -1)
+    {
+        if (strcmp((char *)ShmSysConfigAndInfo->SysInfo.LcmHwRev, moduleName) != 0x00)
+        {
+            GetCurrentPage();
+            sleep(1);
+        }
+        else
+        {
+            //DemoFunction();
+
+            // Warning �閧�
+            if(curWarningCount != ShmSysConfigAndInfo->SysWarningInfo.WarningCount)
+            {
+                changeWarningPriority = 0;
+                ShmSysConfigAndInfo->SysWarningInfo.PageIndex = 0;
+                curWarningCount = ShmSysConfigAndInfo->SysWarningInfo.WarningCount;
+                ChangeWarningFunc();
+            }
+            else if (ShmSysConfigAndInfo->SysWarningInfo.WarningCount > 5 && changeWarningPriority == 0)
+            {
+                // �嗆��拚� Warning ����𥪯�蝘埝㺿霈𠹺�甈�
+                if(ShmSysConfigAndInfo->SysWarningInfo.PageIndex == 0)
+                    ShmSysConfigAndInfo->SysWarningInfo.PageIndex = 1;
+                else
+                    ShmSysConfigAndInfo->SysWarningInfo.PageIndex = 0;
+
+                ChangeWarningFunc();
+            }
+
+            // ��𢒰鞈���閧�
+            ProcessPageInfo();
+
+            // 蝬脰楝 - wifi - ���閮𡃏��閧�
+            RefreshConnStatus();
+
+            // �偦��閧�
+            ChangeCurPage();
+
+            RefreshPageAnimation(_everyPageRollChange);
+
+            if (changeWarningPriority == 0)
+                ChangeDisplayMoneyInfo();
+
+            changeWarningPriority >= 15 ? (_battery_display_ani = true) : (_battery_display_ani = false);
+            changeWarningPriority >= 30 ? changeWarningPriority = 0 : changeWarningPriority++;
+            usleep(100000);
+        }
+    }
+
+    CloseCommunicationLcmPort();
+    return FAIL;
 }

+ 188 - 0
EVSE/Projects/DW30/Apps/Module_LcmControl.h

@@ -0,0 +1,188 @@
+#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/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 <stdbool.h>
+#include "../../define.h"
+
+#define ARRAY_SIZE(A)       (sizeof(A) / sizeof(A[0]))
+#define PASS                1
+#define FAIL                -1
+#define YES                 1
+#define NO                  0
+
+typedef unsigned char           byte;
+
+struct SysConfigAndInfo         *ShmSysConfigAndInfo;
+struct StatusCodeData           *ShmStatusCodeData;
+struct FanModuleData            *ShmFanModuleData;
+
+#define NO_DEFINE           255
+
+#define CMD_TITLE_1             0x5A
+#define CMD_TITLE_2             0xA5
+#define CMD_READ                0x80
+#define CMD_WRITE               0x81
+#define CMD_MULTI_WRITE         0x82
+#define CMD_MULTI_READ          0x83
+
+#define CMD_BACKLIGHT           0x01
+#define CMD_REGISTER            0x03
+
+enum _BATTERY_LEVEL_FOR_MAP
+{
+    _BATTERY_LEVEL_FOR_MAP_EMP = 0x00,
+    _BATTERY_LEVEL_FOR_MAP_LV1 = 0x01,
+    _BATTERY_LEVEL_FOR_MAP_LV2 = 0x02,
+    _BATTERY_LEVEL_FOR_MAP_LV3 = 0x03,
+    _BATTERY_LEVEL_FOR_MAP_LV4 = 0x04,
+    _BATTERY_LEVEL_FOR_MAP_LV5 = 0x05,
+};
+
+int _port;
+//char* pPortName = "/dev/ttyO2";
+char* pPortName = "/dev/ttyS3";
+char* moduleName = "DMT80480T070_09WT";
+byte _totalCount;
+byte acgunCount;
+struct ChargingInfoData *_chargingInfoData[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
+struct ChargingInfoData *ac_chargingInfo[AC_QUANTITY];
+
+byte ac_ani_battery_level = _BATTERY_LEVEL_FOR_MAP_LV5;
+byte isDiffStatus = false;
+byte isChangeBattMap = false;
+// 當前選擇的槍號
+short _currentPage = _LCM_NONE;
+short _oldPage = _LCM_NONE;
+byte _gunIndex = 0;
+byte _idlePageRotate = 1;
+bool _backend_conn_status = false;
+bool _wifi_conn_status = false;
+bool _battery_display_ani = false;
+
+// LCM - HW
+byte _everyPageRollChange = 0;
+short __conn_status = 0x0030;
+short __ethernet_status = 0x0036;
+short __wifi_status = 0x003C;
+
+short __sel_gun_btn = 0x0040;
+short __ret_home_btn = 0x0042;
+short __stop_method_btn = 0x0044;
+
+short __qr_code = 0x0250;
+short __main_rfid = 0x0052;
+short __main_qr = 0x0054;
+short __main_app = 0x0056;
+
+short __plug_in_arrow = 0x0060;
+
+short __conn_line = 0x0066;
+
+short __gun_type_index = 0x0070;
+short __qr_code_pre = 0x0280;
+
+short __side_top = 0x0090;
+short __side_down = 0x0092;
+short __side_mid = 0x0094;
+
+short __conn_line_chag = 0x0096;
+short __batt_map = 0x0100;
+short __soc_value_charging = 0x0102;
+short __remain_time_map = 0x0106;
+short __power_map = 0x0108;
+short __energy_map = 0x010A;
+short __remain_time_tx = 0x0110;
+short __output_eng_tx = 0x0120;
+short __total_out_eng_tx = 0x0130;
+short __conn_line_comp = 0x0140;
+short __charging_fee_map = 0x0146;
+short __charging_fee_tx = 0x0150;
+
+short __money_by_rate = 0x0200;
+short __money_rate = 0x0220;
+short __money_rate_map = 0x0230;
+
+// ICON ID
+byte _disappear = 0;
+byte _disconnect = 1;
+byte _connect = 2;
+byte _warning = 3;
+byte _arrow_dark = 4;
+byte _arrow_light = 5;
+byte _ethernet_disconnect = 6;
+byte _ethernet_connect = 7;
+byte _wifi_disconnect = 8;
+byte _wifi_connect = 9;
+byte _logo = 10;
+byte _conn_map1 = 11;
+byte _conn_map2 = 12;
+byte _sel_gun_btn = 13;
+byte _back_home_btn = 14;
+byte _stop_charging_btn = 15;
+byte _stop_charging_btn_scan = 16;
+byte _chademo_dark = 17;
+byte _ccs_dark = 18;
+byte _gbt_dark = 19;
+byte _actype_dark = 20;
+byte _chademo_light = 21;
+byte _ccs_light = 22;
+byte _gbt_light = 23;
+byte _actype_light = 24;
+byte _main_none_rfid = 25;
+byte _main_rfid = 26;
+byte _main_none_app = 27;
+byte _main_app = 28;
+byte _main_none_qr = 29;
+byte _main_qr = 30;
+byte _charging_map1 = 31;
+byte _charging_map2 = 32;
+byte _battery_empty = 33;
+byte _battery_cap_20 = 34;
+byte _battery_cap_40 = 35;
+byte _battery_cap_60 = 36;
+byte _battery_cap_80 = 37;
+byte _battery_cap_100 = 38;
+byte _battery_map = 39;
+byte _power_map = 40;
+byte _time_map = 41;
+byte _complete_map = 42;
+byte _battery_soc_20 = 43;
+byte _battery_soc_40 = 44;
+byte _battery_soc_60 = 45;
+byte _battery_soc_80 = 46;
+byte _battery_soc_100 = 47;
+byte _battery_eng_map = 48;
+byte _money_map = 49;
+byte _elapse_time_map = 50;
+byte _charging_money = 51;
+byte _side_none_rfid = 52;
+byte _side_rfid = 53;
+byte _side_none_app = 54;
+byte _side_app = 55;
+byte _side_none_qr = 56;
+byte _side_qr = 57;

+ 319 - 281
EVSE/Projects/DW30/Apps/Module_PrimaryComm.c

@@ -1,47 +1,47 @@
-#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/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 	<math.h>
-#include	"../../define.h"
-#include	"PrimaryComm.h"
-#include 	<stdbool.h>
-
-#define ARRAY_SIZE(A)		(sizeof(A) / sizeof(A[0]))
-#define PASS				1
-#define FAIL				-1
-#define YES					1
-#define NO					0
-
-typedef unsigned char 		byte;
-
-struct SysConfigAndInfo			*ShmSysConfigAndInfo;
-struct StatusCodeData 			*ShmStatusCodeData;
-struct PrimaryMcuData			*ShmPrimaryMcuData;
+#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/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 <math.h>
+#include "../../define.h"
+#include "PrimaryComm.h"
+#include <stdbool.h>
+
+#define ARRAY_SIZE(A)       (sizeof(A) / sizeof(A[0]))
+#define PASS                1
+#define FAIL                -1
+#define YES                 1
+#define NO                  0
+
+typedef unsigned char       byte;
+
+struct SysConfigAndInfo         *ShmSysConfigAndInfo;
+struct StatusCodeData           *ShmStatusCodeData;
+struct PrimaryMcuData           *ShmPrimaryMcuData;
 
 void trim(char *s);
 int mystrcmp(char *p1,char *p2);
@@ -54,6 +54,9 @@ Ver ver;
 Gpio_in gpio_in;
 Rtc rtc;
 
+struct timeval _flash_time;
+byte flash = NO;
+
 void PRINTF_FUNC(char *string, ...);
 
 int StoreLogMsg(const char *fmt, ...);
@@ -63,65 +66,65 @@ int StoreLogMsg(const char *fmt, ...);
 
 int StoreLogMsg(const char *fmt, ...)
 {
-	char Buf[4096+256];
-	char buffer[4096];
-	time_t CurrentTime;
-	struct tm *tm;
-	va_list args;
-
-	va_start(args, fmt);
-	int rc = vsnprintf(buffer, sizeof(buffer), fmt, args);
-	va_end(args);
-
-	memset(Buf,0,sizeof(Buf));
-	CurrentTime = time(NULL);
-	tm=localtime(&CurrentTime);
-	sprintf(Buf,"echo \"%04d-%02d-%02d %02d:%02d:%02d - %s\" >> /Storage/SystemLog/[%04d.%02d]SystemLog",
-			tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,
-			buffer,
-			tm->tm_year+1900,tm->tm_mon+1);
-	system(Buf);
-
-	return rc;
+    char Buf[4096+256];
+    char buffer[4096];
+    time_t CurrentTime;
+    struct tm *tm;
+    va_list args;
+
+    va_start(args, fmt);
+    int rc = vsnprintf(buffer, sizeof(buffer), fmt, args);
+    va_end(args);
+
+    memset(Buf,0,sizeof(Buf));
+    CurrentTime = time(NULL);
+    tm=localtime(&CurrentTime);
+    sprintf(Buf,"echo \"%04d-%02d-%02d %02d:%02d:%02d - %s\" >> /Storage/SystemLog/[%04d.%02d]SystemLog",
+            tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,
+            buffer,
+            tm->tm_year+1900,tm->tm_mon+1);
+    system(Buf);
+
+    return rc;
 }
 
 int DiffTimeb(struct timeb ST, struct timeb ET)
 {
-	//return milli-second
-	unsigned int StartTime,StopTime;
+    //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;
+    StartTime=(unsigned int)ST.time;
+    StopTime=(unsigned int)ET.time;
+    return (StopTime-StartTime)*1000+ET.millitm-ST.millitm;
 }
 
 void PRINTF_FUNC(char *string, ...)
 {
-	if (DEBUG)
-	{
-		va_list args;
-		char buffer[4096];
-
-		va_start(args, string);
-		vsnprintf(buffer, sizeof(buffer), string, args);
-		va_end(args);
-		printf("%s \n", buffer);
-	}
+    va_list args;
+    char buffer[4096];
+    va_start(args, string);
+    vsnprintf(buffer, sizeof(buffer), string, args);
+    va_end(args);
+
+    if (ShmSysConfigAndInfo->SysConfig.SwitchDebugFlag == YES)
+        printf("%s \n", buffer);
+    else
+        DEBUG_INFO("%s \n", buffer);
 }
 //=================================
 // Common routine
 //=================================
 char* getTimeString(void)
 {
-	char *result=malloc(21);
-	time_t timep;
-	struct tm *p;
-	time(&timep);
-	p=gmtime(&timep);
+    char *result=malloc(21);
+    time_t timep;
+    struct tm *p;
+    time(&timep);
+    p=gmtime(&timep);
 
-	sprintf(result, "[%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);
+    sprintf(result, "[%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);
 
-	return result;
+    return result;
 }
 
 void trim(char *s)
@@ -160,19 +163,19 @@ int mystrcmp(char *p1,char *p2)
 
 void substr(char *dest, const char* src, unsigned int start, unsigned int cnt)
 {
-	strncpy(dest, src + start, cnt);
-	dest[cnt] = 0;
+    strncpy(dest, src + start, cnt);
+    dest[cnt] = 0;
 }
 
 void split(char **arr, char *str, const char *del)
 {
-	char *s = strtok(str, del);
+    char *s = strtok(str, del);
 
-	while(s != NULL)
-	{
-		*arr++ = s;
-		s = strtok(NULL, del);
-	}
+    while(s != NULL)
+    {
+        *arr++ = s;
+        s = strtok(NULL, del);
+    }
 }
 
 //==========================================
@@ -180,56 +183,56 @@ void split(char **arr, char *str, const char *del)
 //==========================================
 int InitShareMemory()
 {
-	int result = PASS;
-	int MeterSMId;
+    int result = PASS;
+    int MeterSMId;
 
-	//creat ShmSysConfigAndInfo
-	if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo),  0777)) < 0)
+    //creat ShmSysConfigAndInfo
+    if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo),  0777)) < 0)
     {
-		#ifdef SystemLogMessage
-		DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
-		#endif
-		result = FAIL;
-	}
+        #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;
-   	 }
-
-   	 //creat ShmStatusCodeData
-   	 if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData),  0777)) < 0)
+        #ifdef SystemLogMessage
+        DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
+        #endif
+        result = FAIL;
+     }
+
+     //creat ShmStatusCodeData
+     if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData),  0777)) < 0)
     {
-		#ifdef SystemLogMessage
-   		DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
-		#endif
-   		result = FAIL;
-	}
+        #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;
-   	}
-
-	//creat ShmStatusCodeData
-	if ((MeterSMId = shmget(ShmPrimaryMcuKey, sizeof(struct PrimaryMcuData), 0777)) < 0)
-	{
-		#ifdef SystemLogMessage
-		DEBUG_ERROR("shmget ShmPrimaryMcuData NG\n");
-		#endif
-		result = FAIL;
-	}
-	else if ((ShmPrimaryMcuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
-	{
-		#ifdef ShmPrimaryMcuData
-		DEBUG_ERROR("shmat ShmPrimaryMcuData NG\n");
-		#endif
-		result = FAIL;
-	}
+        #ifdef SystemLogMessage
+        DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
+        #endif
+        result = FAIL;
+    }
+
+    //creat ShmStatusCodeData
+    if ((MeterSMId = shmget(ShmPrimaryMcuKey, sizeof(struct PrimaryMcuData), 0777)) < 0)
+    {
+        #ifdef SystemLogMessage
+        DEBUG_ERROR("shmget ShmPrimaryMcuData NG\n");
+        #endif
+        result = FAIL;
+    }
+    else if ((ShmPrimaryMcuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
+    {
+        #ifdef ShmPrimaryMcuData
+        DEBUG_ERROR("shmat ShmPrimaryMcuData NG\n");
+        #endif
+        result = FAIL;
+    }
 
     return result;
 }
@@ -239,94 +242,102 @@ int InitShareMemory()
 //================================================
 void GetFwAndHwVersion()
 {
-	if(Query_FW_Ver(Uart1Fd, Addr.IoExtend, &ver) == PASS)
-	{
-		PRINTF_FUNC("s1 = %s \n", ver.Version_FW);
-		strcpy((char *)ShmPrimaryMcuData->version, ver.Version_FW);
-		strcpy((char *) ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev, ver.Version_FW);
-	}
-
-	if (Query_HW_Ver(Uart1Fd, Addr.IoExtend, &ver) == PASS)
-		PRINTF_FUNC("s2 = %s \n", ver.Version_HW);
+    if(Query_FW_Ver(Uart1Fd, Addr.IoExtend, &ver) == PASS)
+    {
+        PRINTF_FUNC("s1 = %s \n", ver.Version_FW);
+        strcpy((char *)ShmPrimaryMcuData->version, ver.Version_FW);
+        strcpy((char *) ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev, ver.Version_FW);
+    }
+
+    if (Query_HW_Ver(Uart1Fd, Addr.IoExtend, &ver) == PASS)
+        PRINTF_FUNC("s2 = %s \n", ver.Version_HW);
 }
 
 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;
-		ShmPrimaryMcuData->InputDet.bits.AcMainBreakerDetec = gpio_in.AC_MainBreaker;
-		ShmPrimaryMcuData->InputDet.bits.SpdDetec = gpio_in.SPD;
-		ShmPrimaryMcuData->InputDet.bits.DoorOpen = gpio_in.Door_Open;
-
-		ShmPrimaryMcuData->InputDet.bits.Button1 = gpio_in.Button[0];
-		ShmPrimaryMcuData->InputDet.bits.Button2 = gpio_in.Button[1];
-		ShmPrimaryMcuData->InputDet.bits.EmergencyButton = gpio_in.Emergency_Btn;
-
-		//PRINTF_FUNC("left = %d \n", ShmPrimaryMcuData->InputDet.bits.Button1);
-		//PRINTF_FUNC("right = %d \n", ShmPrimaryMcuData->InputDet.bits.Button2);
-		//PRINTF_FUNC("ShmSysConfigAndInfo->SysInfo.AcContactorStatus = %d \n", ShmSysConfigAndInfo->SysInfo.AcContactorStatus);
-		if (ShmPrimaryMcuData->InputDet.bits.AcMainBreakerDetec == YES)
-			DEBUG_ERROR("AC Mainbreaker occur. \n");
-	}
+    //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;
+        ShmPrimaryMcuData->InputDet.bits.AcMainBreakerDetec = gpio_in.AC_MainBreaker;
+        ShmPrimaryMcuData->InputDet.bits.SpdDetec = gpio_in.SPD;
+        ShmPrimaryMcuData->InputDet.bits.DoorOpen = gpio_in.Door_Open;
+
+        ShmPrimaryMcuData->InputDet.bits.Button1 = gpio_in.Button[0];
+        ShmPrimaryMcuData->InputDet.bits.Button2 = gpio_in.Button[1];
+        ShmPrimaryMcuData->InputDet.bits.EmergencyButton = gpio_in.Emergency_Btn;
+
+        //PRINTF_FUNC("left = %d \n", ShmPrimaryMcuData->InputDet.bits.Button1);
+        //PRINTF_FUNC("right = %d \n", ShmPrimaryMcuData->InputDet.bits.Button2);
+        //PRINTF_FUNC("ShmSysConfigAndInfo->SysInfo.AcContactorStatus = %d \n", ShmSysConfigAndInfo->SysInfo.AcContactorStatus);
+        if (ShmPrimaryMcuData->InputDet.bits.AcMainBreakerDetec == YES)
+            DEBUG_ERROR("AC Mainbreaker occur. \n");
+    }
 }
 
-void SetOutputGpio()
+void SetOutputGpio(byte flash)
 {
-	Gpio_out gpio;
-	gpio.Button_LED[0] = 0x01;
-	gpio.Button_LED[1] = 0x01;
-
-	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)
-		PRINTF_FUNC("SetOutputGpio sucessfully. \n");
-	else
-		PRINTF_FUNC("SetOutputGpio fail. \n");
+    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)
+    {
+        //PRINTF_FUNC("SetOutputGpio sucessfully. %d \n", flash);
+    }
+    else
+    {
+        //PRINTF_FUNC("SetOutputGpio fail. \n");
+    }
 }
 
 void SetRtcData()
 {
-	struct timeb csuTime;
-	struct tm *tmCSU;
+    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);
+    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);
 
-	rtc.RtcData[0] = '0' + (tmCSU->tm_year + 1900) / 1000 % 10;
-	rtc.RtcData[1] = '0' + (tmCSU->tm_year + 1900) / 100 % 10;
-	rtc.RtcData[2] = '0' + (tmCSU->tm_year + 1900) / 10 % 10;
-	rtc.RtcData[3] = '0' + (tmCSU->tm_year + 1900) / 1 % 10;
+    rtc.RtcData[0] = '0' + (tmCSU->tm_year + 1900) / 1000 % 10;
+    rtc.RtcData[1] = '0' + (tmCSU->tm_year + 1900) / 100 % 10;
+    rtc.RtcData[2] = '0' + (tmCSU->tm_year + 1900) / 10 % 10;
+    rtc.RtcData[3] = '0' + (tmCSU->tm_year + 1900) / 1 % 10;
 
-	rtc.RtcData[4] = '0' + (tmCSU->tm_mon + 1) / 10 % 10;
-	rtc.RtcData[5] = '0' + (tmCSU->tm_mon + 1) / 1 % 10;
+    rtc.RtcData[4] = '0' + (tmCSU->tm_mon + 1) / 10 % 10;
+    rtc.RtcData[5] = '0' + (tmCSU->tm_mon + 1) / 1 % 10;
 
-	rtc.RtcData[6] = '0' + (tmCSU->tm_mday) / 10 % 10;
-	rtc.RtcData[7] = '0' + (tmCSU->tm_mday) / 1 % 10;
+    rtc.RtcData[6] = '0' + (tmCSU->tm_mday) / 10 % 10;
+    rtc.RtcData[7] = '0' + (tmCSU->tm_mday) / 1 % 10;
 
-	rtc.RtcData[8] = '0' + (tmCSU->tm_hour) / 10 % 10;
-	rtc.RtcData[9] = '0' + (tmCSU->tm_hour) / 1 % 10;
+    rtc.RtcData[8] = '0' + (tmCSU->tm_hour) / 10 % 10;
+    rtc.RtcData[9] = '0' + (tmCSU->tm_hour) / 1 % 10;
 
-	rtc.RtcData[10] = '0' + (tmCSU->tm_min) / 10 % 10;
-	rtc.RtcData[11] = '0' + (tmCSU->tm_min) / 1 % 10;
+    rtc.RtcData[10] = '0' + (tmCSU->tm_min) / 10 % 10;
+    rtc.RtcData[11] = '0' + (tmCSU->tm_min) / 1 % 10;
 
-	rtc.RtcData[12] = '0' + (tmCSU->tm_sec) / 10 % 10;
-	rtc.RtcData[13] = '0' + (tmCSU->tm_sec) / 1 % 10;
+    rtc.RtcData[12] = '0' + (tmCSU->tm_sec) / 10 % 10;
+    rtc.RtcData[13] = '0' + (tmCSU->tm_sec) / 1 % 10;
 
-	if (Config_Rtc_Data(Uart1Fd, Addr.IoExtend, &rtc) == PASS)
-		PRINTF_FUNC("SetRtc sucessfully. \n");
-	else
-		PRINTF_FUNC("SetRtc fail. \n");
+    if (Config_Rtc_Data(Uart1Fd, Addr.IoExtend, &rtc) == PASS)
+    {
+        //PRINTF_FUNC("SetRtc sucessfully. \n");
+    }
+    else
+    {
+        //PRINTF_FUNC("SetRtc fail. \n");
+    }
 }
 
 //================================================
@@ -334,86 +345,113 @@ void SetRtcData()
 //================================================
 int InitComPort()
 {
-	int fd;
-	struct termios tios;
-
-	fd = open(priPortName, O_RDWR);
-	if(fd<=0)
-	{
-		#ifdef SystemLogMessage
-		DEBUG_ERROR("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;
+    int fd;
+    struct termios tios;
+
+    fd = open(priPortName, O_RDWR);
+    if(fd<=0)
+    {
+        #ifdef SystemLogMessage
+        DEBUG_ERROR("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;
 }
 
-int main(void)
+unsigned long GetTimeoutValue(struct timeval _sour_time)
 {
-	if(InitShareMemory() == FAIL)
-	{
-		#ifdef SystemLogMessage
-		DEBUG_ERROR("InitShareMemory NG\n");
-		#endif
-		if(ShmStatusCodeData!=NULL)
-		{
-			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory = 1;
-		}
-		sleep(5);
-		return 0;
-	}
-	Uart1Fd = InitComPort();
-	PRINTF_FUNC("407 Port id = %d \n", Uart1Fd);
-
-	if(Uart1Fd < 0)
-	{
-		#ifdef SystemLogMessage
-		DEBUG_ERROR("InitComPort (Uart1 : AM3352 - STM32) NG");
-		#endif
-
-		if (ShmStatusCodeData != NULL)
-		{
-			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed = 1;
-		}
-		sleep(5);
-		return 0;
-	}
-
-	SetOutputGpio();
-	SetRtcData();
-	for(;;)
-	{
-		// 程序開始之前~ 必須先確定 FW 版本與硬體版本,確認後!!~ 該模組才算是真正的 Initial Comp.
-		// 模組更新 FW 後,需重新做
-		if(ShmPrimaryMcuData->SelfTest_Comp != PASS)
-		{
-			PRINTF_FUNC("(407) Get Fw and Hw Ver. \n");
-			GetFwAndHwVersion();
-			usleep(1000000);
-			ShmPrimaryMcuData->SelfTest_Comp = PASS;
-		}
-		else
-		{
-			GetInputGpioStatus();
-		}
-
-		usleep(100000);
-	}
-
-	return FAIL;
+    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 main(void)
+{
+    if(InitShareMemory() == FAIL)
+    {
+        #ifdef SystemLogMessage
+        DEBUG_ERROR("InitShareMemory NG\n");
+        #endif
+        if(ShmStatusCodeData!=NULL)
+        {
+            ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory = 1;
+        }
+        sleep(5);
+        return 0;
+    }
+    Uart1Fd = InitComPort();
+    PRINTF_FUNC("407 Port id = %d \n", Uart1Fd);
 
+    if(Uart1Fd < 0)
+    {
+        #ifdef SystemLogMessage
+        DEBUG_ERROR("InitComPort (Uart1 : AM3352 - STM32) NG");
+        #endif
+
+        if (ShmStatusCodeData != NULL)
+        {
+            ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed = 1;
+        }
+        sleep(5);
+        return 0;
+    }
 
+    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)
+            {
+                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");
+            GetFwAndHwVersion();
+            sleep(1);
+            ShmPrimaryMcuData->SelfTest_Comp = PASS;
+        }
+        else
+        {
+            GetInputGpioStatus();
+        }
+
+        usleep(100000);
+    }
 
+    return FAIL;
+}

+ 1408 - 1244
EVSE/Projects/DW30/Apps/Module_PsuComm.c

@@ -1,1244 +1,1408 @@
-
-#include 	"Module_PsuComm.h"
-
-#define ARRAY_SIZE(A)		(sizeof(A) / sizeof(A[0]))
-#define PASS				1
-#define FAIL				-1
-#define YES					1
-#define NO					0
-#define DERATING			10
-
-#define SELF_TEST			0
-
-struct SysConfigAndInfo			*ShmSysConfigAndInfo;
-struct StatusCodeData 			*ShmStatusCodeData;
-struct PsuData 					*ShmPsuData;
-
-void trim(char *s);
-int mystrcmp(char *p1,char *p2);
-void substr(char *dest, const char* src, unsigned int start, unsigned int cnt);
-void split(char **arr, char *str, const char *del);
-
-bool libInitialize = false;
-byte gun_count = CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY;
-byte getAvailableCapOffset = 5;
-byte deratingKeepCount = 0;
-
-float carReqVol = 0;
-float carReqCur = 0;
-float evseOutVol = 0;
-float evseOutCur = 0;
-
-int cmdDelayTime = 20000;
-
-void PRINTF_FUNC(char *string, ...);
-
-int StoreLogMsg(const char *fmt, ...);
-#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);
-
-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];
-	time_t CurrentTime;
-	struct tm *tm;
-	va_list args;
-
-	va_start(args, fmt);
-	int rc = vsnprintf(buffer, sizeof(buffer), fmt, args);
-	va_end(args);
-
-	memset(Buf,0,sizeof(Buf));
-	CurrentTime = time(NULL);
-	tm=localtime(&CurrentTime);
-	sprintf(Buf,"echo \"%04d-%02d-%02d %02d:%02d:%02d - %s\" >> /Storage/SystemLog/[%04d.%02d]SystemLog",
-			tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,
-			buffer,
-			tm->tm_year+1900,tm->tm_mon+1);
-	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, ...)
-{
-	if (DEBUG)
-	{
-		va_list args;
-		char buffer[4096];
-
-		va_start(args, string);
-		vsnprintf(buffer, sizeof(buffer), string, args);
-		va_end(args);
-		printf("%s \n", buffer);
-	}
-}
-//=================================
-// Common routine
-//=================================
-char* getTimeString(void)
-{
-	char *result=malloc(21);
-	time_t timep;
-	struct tm *p;
-	time(&timep);
-	p=gmtime(&timep);
-
-	sprintf(result, "[%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);
-
-	return result;
-}
-
-void trim(char *s)
-{
-    int i=0, j, k, l=0;
-
-    while((s[i]==' ')||(s[i]=='\t')||(s[i]=='\n'))
-        i++;
-
-    j = strlen(s)-1;
-    while((s[j]==' ')||(s[j]=='\t')||(s[j]=='\n'))
-        j--;
-
-    if(i==0 && j==strlen(s)-1) { }
-    else if(i==0) s[j+1] = '\0';
-    else {
-        for(k=i; k<=j; k++) s[l++] = s[k];
-        s[l] = '\0';
-    }
-}
-
-int mystrcmp(char *p1,char *p2)
-{
-    while(*p1==*p2)
-    {
-        if(*p1=='\0' || *p2=='\0')
-            break;
-        p1++;
-        p2++;
-    }
-    if(*p1=='\0' && *p2=='\0')
-        return(PASS);
-    else
-        return(FAIL);
-}
-
-void substr(char *dest, const char* src, unsigned int start, unsigned int cnt)
-{
-	strncpy(dest, src + start, cnt);
-	dest[cnt] = 0;
-}
-
-void split(char **arr, char *str, const char *del)
-{
-	char *s = strtok(str, del);
-
-	while(s != NULL)
-	{
-		*arr++ = s;
-		s = strtok(NULL, del);
-	}
-}
-
-//=================================
-// ReAssigned PSU Function
-//=================================
-void ReAssignedResource()
-{
-	int index = 0;
-	struct PsuModuleData PsuModule[ShmPsuData->SystemPresentPsuQuantity];
-
-	for (byte i = 0; i < 4; i++)
-	{
-		for(byte psuCount = 0; psuCount < ShmPsuData->PsuGroup[i].GroupPresentPsuQuantity; psuCount++)
-		{
-			memcpy(&PsuModule[index], &ShmPsuData->PsuGroup[i].PsuModule[psuCount], sizeof(struct PsuModuleData));
-			index++;
-		}
-		ShmPsuData->PsuGroup[i].GroupPresentPsuQuantity = 0;
-	}
-
-	for(int i = 0; i < ShmPsuData->SystemPresentPsuQuantity; i++)
-	{
-		byte group = PsuModule[i].FireWireIndex;
-
-		memcpy(&ShmPsuData->PsuGroup[group].PsuModule[ShmPsuData->PsuGroup[group].GroupPresentPsuQuantity],
-				&PsuModule[i], sizeof(struct PsuModuleData));
-
-		PRINTF_FUNC("ReAssignedResource : PhysicalID = %d, Address = %d, group = %d \n",
-				ShmPsuData->PsuGroup[group].PsuModule[ShmPsuData->PsuGroup[group].GroupPresentPsuQuantity].PhysicalID,
-				ShmPsuData->PsuGroup[group].PsuModule[ShmPsuData->PsuGroup[group].GroupPresentPsuQuantity].Address,
-				group);
-//		printf("ReAssignedResource : PhysicalID = %d, Address = %d, group = %d \n",
-//				ShmPsuData->PsuGroup[group].PsuModule[ShmPsuData->PsuGroup[group].GroupPresentPsuQuantity].PhysicalID,
-//				ShmPsuData->PsuGroup[group].PsuModule[ShmPsuData->PsuGroup[group].GroupPresentPsuQuantity].Address,
-//				group);
-
-		PsuAddressAssignment(ShmPsuData->PsuGroup[group].PsuModule[ShmPsuData->PsuGroup[group].GroupPresentPsuQuantity].PhysicalID,
-				group);
-		ShmPsuData->PsuGroup[group].GroupPresentPsuQuantity++;
-	}
-}
-
-//=================================
-// Save data to share memory Function
-//=================================
-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;
-}
-
-//=================================
-// Alarm code mapping to share memory Function
-//=================================
-// 檢查 Byte 中某個 Bit 的值
-// _byte : 欲改變的 byte
-// _bit : 該 byte 的第幾個 bit
-unsigned char mask_table[] = { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 };
-unsigned char DetectBitValue(unsigned char _byte, unsigned char _bit)
-{
-	return ( _byte & mask_table[_bit] ) != 0x00;
-}
-
-void AbnormalStopAnalysis(byte gun_index, int errCode)
-{
-	for (char i = 0; i < 3; i++)
-	{
-		unsigned char byteIndex = (errCode >> (8 * i)) & 0xff;
-
-		for (char bitIndex = 0; bitIndex < 8; bitIndex++)
-		{
-			if(DetectBitValue(byteIndex , bitIndex) == 1)
-			{
-				switch(byteIndex)
-				{
-					case 0:
-					{
-						if (bitIndex == 0)
-							ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuOutputShortCircuit = YES;
-						else if (bitIndex == 5)
-							ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuDcSideShutDown = YES;
-					}
-						break;
-				case 1:
-					{
-						if (bitIndex == 1)
-							ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuFailureAlarm = YES;
-						else if (bitIndex == 2)
-							ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuProtectionAlarm = YES;
-						else if (bitIndex == 3)
-							ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuFanFailureAlarm = YES;
-						else if (bitIndex == 4)
-							ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuCriticalPointOTP = YES;
-						else if (bitIndex == 5)
-							ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuDcSideShutDown = YES;
-					}
-					break;
-				case 2:
-					{
-						if (bitIndex == 1)
-							ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuDuplicateID = YES;
-						if (bitIndex == 2)
-							ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuThreePhaseOnputImbalance = YES;
-						else if (bitIndex == 3)
-							ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuThreePhaseInputInadequate = YES;
-						else if (bitIndex == 4)
-							ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuThreePhaseInputInadequate = YES;
-						else if (bitIndex == 5)
-							ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuInputUVP = YES;
-						else if (bitIndex == 6)
-							ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuInputOVP = YES;
-					}
-					break;
-				}
-			}
-			else
-			{
-				switch (byteIndex) {
-				case 0: {
-					if (bitIndex == 0)
-						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuOutputShortCircuit = NO;
-					else if (bitIndex == 5)
-						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuDcSideShutDown = NO;
-				}
-					break;
-				case 1: {
-					if (bitIndex == 1)
-						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuFailureAlarm = NO;
-					else if (bitIndex == 2)
-						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuProtectionAlarm = NO;
-					else if (bitIndex == 3)
-						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuFanFailureAlarm = NO;
-					else if (bitIndex == 4)
-						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuCriticalPointOTP = NO;
-					else if (bitIndex == 5)
-						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuDcSideShutDown = NO;
-				}
-					break;
-				case 2: {
-					if (bitIndex == 1)
-						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuDuplicateID = NO;
-					if (bitIndex == 2)
-						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuThreePhaseOnputImbalance = NO;
-					else if (bitIndex == 3)
-						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuThreePhaseInputInadequate = NO;
-					else if (bitIndex == 4)
-						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuThreePhaseInputInadequate = NO;
-					else if (bitIndex == 5)
-						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuInputUVP = NO;
-					else if (bitIndex == 6)
-						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuInputOVP = NO;
-				}
-					break;
-				}
-			}
-		}
-	}
-}
-
-//=================================
-// Callback Function
-//=================================
-void GetPsuRequestCallback(byte phy_id, char *serial_number)
-{
-	if (ShmSysConfigAndInfo->SysInfo.AcContactorStatus == NO)
-		return;
-
-	// ********************** 每次送電後,需判斷要把所有的模塊分配到哪個 Group **********************
-	byte group = 0;
-	if(ShmSysConfigAndInfo->SysInfo.BootingStatus == BOOTTING || gun_count == 1)
-	{
-		// 初始化狀態,則直接先分配到同個群
-		group = 0;
-	}
-	else
-	{
-		group = ShmSysConfigAndInfo->SysInfo.CurGunSelected;
-	}
-
-	bool isNewPsu = true;
-	for (byte index = 0; index < ShmPsuData->PsuGroup[group].GroupPresentPsuQuantity; index++)
-	{
-		if (ShmPsuData->PsuGroup[group].PsuModule[index].PhysicalID == phy_id &&
-			strncmp((char *)ShmPsuData->PsuGroup[group].PsuModule[index].SerialNumber, serial_number, 7) == 0)
-		{
-			isNewPsu = false;
-		}
-	}
-
-	if (isNewPsu)
-	{
-		ShmPsuData->SystemPresentPsuQuantity++;
-		PRINTF_FUNC("get psu********Membar = %d, group = %d \n", ShmPsuData->SystemPresentPsuQuantity, group);
-
-		if (ShmPsuData->Work_Step >= _TEST_LINE_STEP && ShmPsuData->Work_Step <= _TEST_COMPLETE)
-		{
-			// 已經進入火線上的驗證動作
-			//ShmPsuData->NeedBackTest = YES;
-		}
-		else if (ShmPsuData->Work_Step == _WORK_CHARGING)
-		{
-			// 一旦進入火線,分配一個不會用到的給該模塊
-			group++;
-		}
-
-		ShmPsuData->PsuGroup[group].PsuModule[ShmPsuData->PsuGroup[group].GroupPresentPsuQuantity].Address = ShmPsuData->SystemPresentPsuQuantity;
-		ShmPsuData->PsuGroup[group].PsuModule[ShmPsuData->PsuGroup[group].GroupPresentPsuQuantity].PhysicalID = phy_id;
-		ShmPsuData->PsuGroup[group].PsuModule[ShmPsuData->PsuGroup[group].GroupPresentPsuQuantity].AssignID = (group >> 6) + ShmPsuData->SystemPresentPsuQuantity;
-		strcpy((char *)ShmPsuData->PsuGroup[group].PsuModule[ShmPsuData->PsuGroup[group].GroupPresentPsuQuantity].SerialNumber, serial_number);
-		ShmPsuData->PsuGroup[group].GroupPresentPsuQuantity++;
-
-		byte isFind = false;
-		for (byte index = 0; index < conn_1_count; index++)
-		{
-			PRINTF_FUNC("connector_1[%d] = %d, phy_id = %d \n", index, connector_1[index], phy_id);
-			if (connector_1[index] == phy_id)
-			{
-				isFind = true;
-				ShmPsuData->PsuGroup[group].PsuModule[ShmPsuData->PsuGroup[group].GroupPresentPsuQuantity].FireWireIndex = 0;
-				break;
-			}
-		}
-
-		if (!isFind)
-		{
-			for (byte index = 0; index < conn_2_count; index++)
-			{
-				PRINTF_FUNC("connector_2[%d] = %d, phy_id = %d \n", index, connector_2[index], phy_id);
-				if (connector_2[index] == phy_id)
-				{
-					isFind = true;
-					ShmPsuData->PsuGroup[group].PsuModule[ShmPsuData->PsuGroup[group].GroupPresentPsuQuantity].FireWireIndex = 1;
-					break;
-				}
-			}
-		}
-
-		//PsuAddressAssignment(phy_id, serial_number, ShmPsuData->SystemPresentPsuQuantity, group);
-		PsuAddressAssignment(phy_id, group);
-
-		if (ShmPsuData->Work_Step != _WORK_CHARGING)
-		{
-			ShmPsuData->GroupCount = group + 1;
-		}
-	}
-}
-
-void SaveStatusCallback(byte group, byte address, char cri_temp1, int alarm)
-{
-	//EVSE
-	for (byte index = 0; index < ShmPsuData->PsuGroup[group].GroupPresentPsuQuantity; index++)
-	{
-		if (ShmPsuData->PsuGroup[group].PsuModule[index].PhysicalID == address)
-	    {
-			ShmPsuData->PsuGroup[group].PsuModule[index].CriticalTemp1 = cri_temp1;
-	    	ShmPsuData->PsuGroup[group].PsuModule[index].AlarmCode = alarm;
-	    	AbnormalStopAnalysis(group, alarm);
-	    	break;
-	    }
-	}
-}
-
-//模組三向輸入電壓
-void SavePresentInputVoltageCallback(byte address, unsigned short vol1, unsigned short vol2, unsigned short vol3)
-{
-	//EVSE
-	//search group
-    for (byte groupIndex = 0; groupIndex < ShmPsuData->GroupCount; groupIndex++)
-    { 
-    	for (byte index = 0; index < ShmPsuData->PsuGroup[groupIndex].GroupPresentPsuQuantity; index++)
-    	{
-    	    //search id
-    		if (ShmPsuData->PsuGroup[groupIndex].PsuModule[index].PhysicalID == address)
-    		{
-    		    //update module msg
-    			ShmPsuData->PsuGroup[groupIndex].PsuModule[index].InputVoltageL1 = vol1;
-    			ShmPsuData->PsuGroup[groupIndex].PsuModule[index].InputVoltageL2 = vol2;
-    			ShmPsuData->PsuGroup[groupIndex].PsuModule[index].InputVoltageL3 = vol3;
-    			break;
-    		}
-    	}
-    }
-}
-
-// 模塊輸出的電壓電流
-void SavePresentOutputCallback(byte address, unsigned short out_vol, unsigned short out_cur)
-{
-	unsigned short outputVol = 0;
-	unsigned short outputCur = 0;
-	unsigned short group = 0;
-	bool isChange = false;
-
-	// PSU
-	for (byte groupIndex = 0; groupIndex < ShmPsuData->GroupCount; groupIndex++)
-    {
-    	for (int index = 0; index < ShmPsuData->PsuGroup[groupIndex].GroupPresentPsuQuantity; index++)
-    	{
-    		if (ShmPsuData->PsuGroup[groupIndex].PsuModule[index].PhysicalID == address)
-    		{
-    		    //如果英飛源模組不是 ver1.09 版使用模組輸出電壓
-    		    /*
-    			if(InfyPwrModelVerIs109 == 0)
-    			{
-    			    ShmPsuData->PsuGroup[groupIndex].PsuModule[index].PresentOutputVoltage = out_vol;
-    			}
-    			*/
-    			ShmPsuData->PsuGroup[groupIndex].PsuModule[index].PresentOutputVoltage = out_vol;
-    			ShmPsuData->PsuGroup[groupIndex].PsuModule[index].PresentOutputCurrent = out_cur;   			
-    			
-    		    for (int loop = 0; loop < ShmPsuData->PsuGroup[groupIndex].GroupPresentPsuQuantity; loop++)
-    		    {
-    		        //update voltage
-   		            if (ShmPsuData->PsuGroup[groupIndex].PsuModule[loop].PresentOutputVoltage > outputVol)
-   		            {
-    			        outputVol = ShmPsuData->PsuGroup[groupIndex].PsuModule[loop].PresentOutputVoltage;
-    			    }
-    			    //update total current
-    			    outputCur += ShmPsuData->PsuGroup[groupIndex].PsuModule[index].PresentOutputCurrent;
-    			    group = groupIndex;
-    			    isChange = true;
-    		    }
-    		}
-
-            /*
-    		if (ShmPsuData->PsuGroup[group].PsuModule[index].PresentOutputVoltage > outputVol)
-    			outputVol = ShmPsuData->PsuGroup[group].PsuModule[index].PresentOutputVoltage;
-
-    		outputCur += ShmPsuData->PsuGroup[group].PsuModule[index].PresentOutputCurrent;
-    		*/
-    	}
-    }
-
-	if (isChange)
-	{
-		// PSU Group
-		// 電壓
-		ShmPsuData->PsuGroup[group].GroupPresentOutputVoltage = outputVol;
-		// 電流
-		ShmPsuData->PsuGroup[group].GroupPresentOutputCurrent = outputCur;
-
-		//EVSE - 槍端的輸出電壓
-		chargingInfo[group]->PresentChargingVoltage = ShmPsuData->PsuGroup[group].GroupPresentOutputVoltage;
-		//EVSE - 槍端的輸出電流
-		chargingInfo[group]->PresentChargingCurrent = ShmPsuData->PsuGroup[group].GroupPresentOutputCurrent;
-	}
-
-	//printf("GroupPresentOutputVoltage = %d \n", ShmPsuData->PsuGroup[group].GroupPresentOutputVoltage);
-	//printf("GroupPresentOutputCurrent = %d \n", ShmPsuData->PsuGroup[group].GroupPresentOutputCurrent);
-}
-
-//PSU able_power = KW (單位 0.1) exp. 300 = 30kw
-//PSU able_cur = A (單位 0.1) exp. 400 = 40A
-void SaveAvailableCapCallback(byte address, unsigned short maxv, unsigned short minv, unsigned short able_cur, unsigned short able_power)
-{
-	unsigned int power = 0;
-	unsigned int current = 0;
-	unsigned int power_derating = 0;
-	unsigned int current_derating = 0;
-	unsigned int group = 0;
-	bool isChange = false;
-	//bool sameGroup = false;
-
-    //search group
-	//printf("GroupCount = %d \n", ShmPsuData->GroupCount);
-    for (byte groupIndex = 0; groupIndex < ShmPsuData->GroupCount; groupIndex++)
-    {        
-    	//printf("GroupPresentPsuQuantity = %d \n", ShmPsuData->PsuGroup[groupIndex].GroupPresentPsuQuantity);
-    	for (int index = 0; index < ShmPsuData->PsuGroup[groupIndex].GroupPresentPsuQuantity; index++)
-    	{
-    	    //search group-id
-    		//printf("PhysicalID = %d, address = %d \n", ShmPsuData->PsuGroup[groupIndex].PsuModule[index].PhysicalID, address);
-    		if (ShmPsuData->PsuGroup[groupIndex].PsuModule[index].PhysicalID == address)
-    		{
-    		    //先更新該模組資訊    
-    			ShmPsuData->PsuGroup[groupIndex].PsuModule[index].AvailablePower = able_power;
-
-    			//電壓在 150V 時使用額定電流
-    			if(ShmPsuData->PsuGroup[groupIndex].PsuModule[index].PresentOutputVoltage < 1500)
-    			{
-    			    ShmPsuData->PsuGroup[groupIndex].PsuModule[index].AvailableCurrent = able_cur;
-    			}
-    			//如果英飛源模組不是 ver1.09 版 或 (如果英飛源模組是 ver1.09 版但回應可輸出電流有誤則使用額定報文可輸出電流)
-    			/*
-    			if(InfyPwrModelVerIs109 == 0 ||
-    			    (InfyPwrModelVerIs109 == 1 && ShmPsuData->PsuGroup[groupIndex].PsuModule[index].AvailableCurrent == 0))
-    			{
-    			        ShmPsuData->PsuGroup[groupIndex].PsuModule[index].AvailableCurrent = able_cur;
-    			}
-    			*/
-    		    //該對應的模組群重新計算總合		    
-    		    for (int loop = 0; loop < ShmPsuData->PsuGroup[groupIndex].GroupPresentPsuQuantity; loop++)
-    		    {
-    		    	// 降載
-//    		    	if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag >= _REASSIGNED_GET_NEW_CAP &&
-//    		    			ShmSysConfigAndInfo->SysInfo.ReAssignedFlag < _REASSIGNED_COMP)
-//    		    	{
-//    		    		if (ShmPsuData->PsuGroup[group].PsuModule[index].FireWireIndex == group)
-//    		    		{
-//    		    			power_derating += ShmPsuData->PsuGroup[group].PsuModule[index].AvailablePower;
-//    		    			current_derating += ShmPsuData->PsuGroup[group].PsuModule[index].AvailableCurrent;
-//    		    		}
-//    		    	}
-
-    		        power += ShmPsuData->PsuGroup[groupIndex].PsuModule[loop].AvailablePower;
-    			    current += ShmPsuData->PsuGroup[groupIndex].PsuModule[loop].AvailableCurrent;
-    			    group = groupIndex;
-    			    isChange = true;
-    		    }
-    		}
-    	}
-    }
-    
-    if (current_derating == 0)
-    {
-    	current_derating = current;
-    }
-
-    if (power_derating == 0)
-    {
-    	power_derating = power;
-    }
-
-	if (isChange)
-	{
-		// PSU Group
-		// Available Power
-		ShmPsuData->PsuGroup[group].GroupAvailablePower = power;
-		// Available Current
-		ShmPsuData->PsuGroup[group].GroupAvailableCurrent = current;
-
-		chargingInfo[group]->MaximumChargingVoltage = maxv;
-		chargingInfo[group]->AvailableChargingCurrent =	ShmPsuData->PsuGroup[group].GroupAvailableCurrent;
-		chargingInfo[group]->AvailableChargingPower = ShmPsuData->PsuGroup[group].GroupAvailablePower;
-		chargingInfo[group]->DeratingChargingCurrent = current_derating;
-		chargingInfo[group]->DeratingChargingPower = power_derating;
-
-		PRINTF_FUNC("group = %d, AvailableChargingCurrent = %f, GroupAvailablePower = %f, DeratingChargingCurrent = %f, DeratingChargingPower = %f \n",
-							group, chargingInfo[group]->AvailableChargingCurrent, chargingInfo[group]->AvailableChargingPower,
-							chargingInfo[group]->DeratingChargingCurrent, chargingInfo[group]->DeratingChargingPower);
-	}
-}
-
-void GetBarCodeCallback(byte address, char *serial_number , unsigned short module_ver)
-{
-	//EVSE
-	for (byte groupIndex = 0; groupIndex < ShmPsuData->GroupCount; groupIndex++)
-	{
-    	for (byte index = 0; index < ShmPsuData->PsuGroup[groupIndex].GroupPresentPsuQuantity; index++)
-    	{
-    		if (ShmPsuData->PsuGroup[groupIndex].PsuModule[index].PhysicalID == address)
-    		{
-    		    ShmPsuData->PsuGroup[groupIndex].PsuModule[index].FwVersion[0] = (module_ver >> 8) & 0xFF;
-    			ShmPsuData->PsuGroup[groupIndex].PsuModule[index].FwVersion[1] = (module_ver) & 0xFF;
-    		    //strcpy((char *)ShmPsuData->PsuGroup[groupIndex].PsuModule[ShmPsuData->PsuGroup[groupIndex].GroupPresentPsuQuantity].SerialNumber, serial_number);
-    		}
-    	}
-	}
-}
-
-void GetMiscInfoCallback(byte address, unsigned short CmdType , unsigned int value)
-{
-	//EVSE
-	for (byte groupIndex = 0; groupIndex < ShmPsuData->GroupCount; groupIndex++)
-    {
-    	for (byte index = 0; index < ShmPsuData->PsuGroup[groupIndex].GroupPresentPsuQuantity; index++)
-    	{
-    		if (ShmPsuData->PsuGroup[groupIndex].PsuModule[index].PhysicalID == address)
-    		{
-    		    if(CmdType == MISC_REQCMD_DC_BOARD_TMP){
-    		        //數值未處理
-    		        ShmPsuData->PsuGroup[groupIndex].PsuModule[index].CriticalTemp2 = (byte)value;
-    		    }else if(CmdType == MISC_REQCMD_PFC_BOARD_TMP){
-    		        //數值未處理
-    		        ShmPsuData->PsuGroup[groupIndex].PsuModule[index].CriticalTemp3 = (byte)value;
-    		    }else if(CmdType == MISC_REQCMD_FAN_SPEED){
-    		        //數值未處理
-    		        ShmPsuData->PsuGroup[groupIndex].PsuModule[index].FanSpeed_1 = (unsigned short)value;
-    		    }
-    		}
-    	}
-	}
-
-	//暫定如果有回 misc 就認定英飛源為 1.9 版
-	//InfyPwrModelVerIs109 = 1;
-	//printf("Get Misc : %d \n",InfyPwrModelVerIs109);
-}
-
-void SaveHardwareVersion(byte group, byte address, int hw_ver)
-{
-	//EVSE
-	for (byte index = 0; index < ShmPsuData->PsuGroup[group].GroupPresentPsuQuantity; index++)
-	{
-		if (ShmPsuData->PsuGroup[group].PsuModule[index].Address == address)
-		{
-			ShmPsuData->PsuGroup[group].PsuModule[index].FwVersion[0] = (hw_ver >> 24) & 0xFF;
-			ShmPsuData->PsuGroup[group].PsuModule[index].FwVersion[1] = (hw_ver >> 16) & 0xFF;
-			ShmPsuData->PsuGroup[group].PsuModule[index].FwVersion[2] = (hw_ver >> 8) & 0xFF;
-			ShmPsuData->PsuGroup[group].PsuModule[index].FwVersion[3] = hw_ver & 0xFF;
-			break;
-		}
-	}
-}
-
-
-//Vext      模組二極體後電壓
-//Iavail    模組目前因環境因素的真實能輸出電流
-void SavePresentModeleVextIavailCallback(byte address, unsigned short Vext, unsigned short Iavail)
-{
-	//EVSE
-	//search group
-    for (byte groupIndex = 0; groupIndex < ShmPsuData->GroupCount; groupIndex++)
-    {
-    	for (byte index = 0; index < ShmPsuData->PsuGroup[groupIndex].GroupPresentPsuQuantity; index++)
-    	{
-    	    //search id
-    		if (ShmPsuData->PsuGroup[groupIndex].PsuModule[index].PhysicalID == address)
-    		{
-    		    //update module msg
-    		    //ShmPsuData->PsuGroup[groupIndex].PsuModule[index].PresentOutputVoltage = Vext;
-    		    //
-    		    if(ShmPsuData->PsuGroup[groupIndex].PsuModule[index].PresentOutputVoltage >= 1500)
-    		    {
-    			    ShmPsuData->PsuGroup[groupIndex].PsuModule[index].AvailableCurrent = Iavail;
-    			}
-    			//printf("Vext = %d I = %d \n", Vext,Iavail);
-    			break;
-    		}
-    	}
-    }
-}
-
-void GetOutputPowerSwitchStatusCallback(byte address, unsigned char value)
-{
-    for (byte groupIndex = 0; groupIndex < ShmPsuData->GroupCount; groupIndex++)
-    {
-    	for (byte index = 0; index < ShmPsuData->PsuGroup[groupIndex].GroupPresentPsuQuantity; index++)
-    	{
-    		if (ShmPsuData->PsuGroup[groupIndex].PsuModule[index].PhysicalID == address)
-    		{
-    			//printf("PowerSwitch = %d, group = %d, address = %d \n", value, group, address);
-    			if(value){
-    			    ShmPsuData->PsuGroup[groupIndex].PsuModule[index].OutputPowerSwitch = 0x00;
-    			}else{
-    			    ShmPsuData->PsuGroup[groupIndex].PsuModule[index].OutputPowerSwitch = 0x01;
-    			}
-    			
-    			break;
-    		}
-    	}
-    }
-}
-
-//==========================================
-// Init all share memory
-//==========================================
-int InitShareMemory()
-{
-	int result = PASS;
-	int MeterSMId;
-
-	//creat ShmSysConfigAndInfo
-	if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo),  0777)) < 0)
-    {
-		#ifdef SystemLogMessage
-		DEBUG_ERROR("shmget ShmSysConfigAndInfo NG %d \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 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;
-}
-
-//================================================
-// Main process
-//================================================
-void InitialPsuData()
-{
-	ShmPsuData->SystemPresentPsuQuantity = 0;
-
-	for (byte _groupCount = 0; _groupCount < ARRAY_SIZE(ShmPsuData->PsuGroup);	_groupCount++)
-	{
-		ShmPsuData->PsuGroup[_groupCount].GroupPresentPsuQuantity = 0;
-		ShmPsuData->PsuGroup[_groupCount].GroupAvailablePower = 0;
-		ShmPsuData->PsuGroup[_groupCount].GroupAvailableCurrent = 0;
-	}
-	
-	ShmPsuData->Work_Step = _INIT_PSU_STATUS;
-}
-
-void Initialization()
-{
-	bool isPass = false;
-	while(!isPass)
-	{
-		isPass = true;
-		for (byte _index = 0; _index < _gunCount; _index++)
-		{
-			if (!FindChargingInfoData(_index, &chargingInfo[0]))
-			{
-				DEBUG_ERROR("EvComm (main) : FindChargingInfoData false \n");
-				isPass = false;
-				break;
-			}
-		}
-	}
-	conn_1_count = sizeof(connector_1)/sizeof(connector_1[0]);
-	conn_2_count = sizeof(connector_2)/sizeof(connector_2[0]);
-}
-
-int main(void)
-{
-	PRINTF_FUNC("Psu Task boot .... \n");
-	if(InitShareMemory() == FAIL)
-	{
-		#ifdef SystemLogMessage
-		DEBUG_ERROR("InitShareMemory NG\n");
-		#endif
-		if(ShmStatusCodeData != NULL)
-		{
-			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory = 1;
-		}
-		sleep(5);
-		return 0;
-	}
-
-	PRINTF_FUNC("InitShareMemory OK\n");
-
-	// register callback function
-	GetPsuAddressReq(&GetPsuRequestCallback);
-	RefreshSerialNumber(&GetBarCodeCallback);
-	RefreshVextAndIavail(&SavePresentModeleVextIavailCallback);
-	RefreshMiscInfo(&GetMiscInfoCallback);
-
-	RefreshStatus(&SaveStatusCallback);
-	RefreshInputVol(&SavePresentInputVoltageCallback);
-	RefreshGetOutput(&SavePresentOutputCallback);
-	RefreshAvailableCap(&SaveAvailableCapCallback);
-	RefreshOutputPowerSwitch(&GetOutputPowerSwitchStatusCallback);
-
-	// initial object
-	InitialPsuData();
-	Initialization();
-	libInitialize = InitialCommunication();
-
-    byte priorityLow = 1;
-    byte isInitialComp = NO;
-	//main loop
-	while (libInitialize)
-	{
-		// 斷電狀態
-		if (ShmSysConfigAndInfo->SysInfo.AcContactorStatus == NO)
-		{
-			//一但 AC Off PSU 斷電全部的 PSU Group ID 會全部清 0
-			if (!isInitialComp)
-			{
-				InitialPsuData();
-				ShmPsuData->Work_Step = ASSIGN_START;
-				isInitialComp = YES;
-			}
-			sleep(1);
-			continue;
-		}
-		else
-			isInitialComp = NO;
-
-		// update psu fw req
-//		if(psu update req ?)
-//		{
-//
-//			continue;
-//		}
-
-		// 自檢失敗
-		if (ShmPsuData->Work_Step == _NO_WORKING)
-		{
-			PRINTF_FUNC("== PSU == self test fail. \n");
-			sleep(5);
-		}
-
-		switch(ShmPsuData->Work_Step)
-		{
-			case ASSIGN_START:
-			{
-				PRINTF_FUNC("== PSU == ASSIGN_COMP \n");
-				sleep(5);
-				gettimeofday(&_id_assign_time, NULL);
-				ShmPsuData->Work_Step = ASSIGN_COMP;
-			}
-				break;
-			case ASSIGN_COMP:
-			{
-				if (priorityLow == 1)
-				{
-					//如果還未取得模組數量
-					if(ShmPsuData->SystemPresentPsuQuantity == 0)
-					{
-						EnableDipAddrMode();
-						usleep(cmdDelayTime);
-				        //發送取得目前全部模組數量 (英飛源開機須等待讓模組互相通訊)
-				        RequestModuleTotalMumbert();
-				        usleep(cmdDelayTime);
-					}
-					//己取得模組數量 (目前還未分配群組所以都使用預設 0)
-					else
-					{
-				    	for (byte psuIndex = 0;	psuIndex < ShmPsuData->PsuGroup[0].GroupPresentPsuQuantity;	psuIndex++)
-				    	{
-				            //get status
-				    		GetStatus(0, NONE_CARE_ADDRESS);
-				    		usleep(cmdDelayTime);
-				            //get barcode & ver
-				    		GetSerialNumber(0, NONE_CARE_ADDRESS);
-				    		usleep(cmdDelayTime);
-
-				    		GetMiscInfo(0, NONE_CARE_ADDRESS, MISC_REQCMD_DC_BOARD_TMP);
-				    		usleep(cmdDelayTime);
-				    		GetMiscInfo(0, NONE_CARE_ADDRESS, MISC_REQCMD_PFC_BOARD_TMP);
-				    		usleep(cmdDelayTime);
-				    		GetMiscInfo(0, NONE_CARE_ADDRESS, MISC_REQCMD_PFC_BOARD_TMP);
-				    		usleep(cmdDelayTime);
-				    	}
-					}
-					//printf("Get Misc2 : %d \n",InfyPwrModelVerIs109);
-				}
-
-				priorityLow >= 20 ? priorityLow = 1 : priorityLow++;
-				// 等待 10 秒
-				if (GetTimeoutValue(_id_assign_time) >= 10000000)
-				{
-					ShmPsuData->Work_Step = ENABLE_POW;
-					PRINTF_FUNC("INFYPWR Num = %d \n", ShmPsuData->SystemPresentPsuQuantity);
-					PRINTF_FUNC("== PSU == ENABLE_POW \n");
-				}
-			}
-				break;
-			case ENABLE_POW:
-			{
-				if (ShmSysConfigAndInfo->SysInfo.BootingStatus == BOOTTING)
-				{
-					// 電樁在 Booting 的狀態 - 自檢
-					PRINTF_FUNC("== PSU == _TEST_LINE_STEP \n");
-					ShmPsuData->Work_Step = _TEST_LINE_STEP;
-				}
-				else
-				{
-					PRINTF_FUNC("== PSU == _WORK_CHARGING \n");
-					ShmPsuData->Work_Step = _WORK_CHARGING;
-					gettimeofday(&_workModePriority_time, NULL);
-				}
-			}
-				break;
-			case _TEST_LINE_STEP:
-			{
-				PRINTF_FUNC("cur total psu count = %d \n", ShmPsuData->SystemPresentPsuQuantity);
-				if (ShmPsuData->PsuGroup[0].GroupPresentPsuQuantity <= 0)
-				{
-					sleep(1);
-					// 顯示錯誤
-					ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuNoResource = YES;
-					continue;
-				}
-
-				ShmPsuData->Work_Step = _TEST_POWER_STEP;
-			}
-				break;
-			case _TEST_POWER_STEP:
-			{
-				if(!_chkTotalCapStart)
-				{
-					_chkTotalCapStart = true;
-					gettimeofday(&_chk_cap_time, NULL);
-				}
-
-				// 初始化、關閉所有的模塊
-				//EnableOutputPower(0, NONE_CARE_ADDRESS, SWITCH_OFF);
-				for (byte groupIndex = 0; groupIndex < ShmPsuData->GroupCount; groupIndex++)
-				{
-					GetStatus(groupIndex, NONE_CARE_ADDRESS);
-					usleep(cmdDelayTime);
-				}
-
-				for (byte psuCount = 0; psuCount < ShmPsuData->SystemPresentPsuQuantity; psuCount++)
-				{
-					GetAvailableCap(psuCount, NONE_CARE_ADDRESS,  0);
-				}
-
-				usleep(cmdDelayTime);
-				if (GetTimeoutValue(_chk_cap_time) >= 2000000)
-				{
-					PRINTF_FUNC("AvailableChargingCurrent = %f, AvailableChargingPower = %f \n",
-							chargingInfo[0]->AvailableChargingCurrent, chargingInfo[0]->AvailableChargingPower);
-					for (byte index = 0; index < ShmPsuData->PsuGroup[0].GroupPresentPsuQuantity; index++)
-					{
-						PRINTF_FUNC("index = %d, fire index = %d, phy addr = %d \n",
-								index, recordPsuData[index]._fire_index, recordPsuData[index]._phy_addr);
-					}
-
-					PRINTF_FUNC("== PSU == TEST_COMPLETE \n");
-					ShmPsuData->Work_Step = _TEST_COMPLETE;
-				}
-			}
-				break;
-			case _TEST_COMPLETE:
-			{
-			    priorityLow = 1;
-				sleep(1);
-			}
-				break;
-			case _WORK_CHARGING:
-			{
-				int time = GetTimeoutValue(_workModePriority_time) / 1000;
-				//printf("GroupCount = %d \n", ShmPsuData->GroupCount);
-				//printf("cur total psu count = %d \n", ShmPsuData->SystemPresentPsuQuantity);
-
-				// 智能分配 : 檢查該槍是否有模塊有用,有則無須重新分配直接進入充電
-				if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag == _REASSIGNED_PREPARE)
-				{
-					if (ShmPsuData->PsuGroup[ShmSysConfigAndInfo->SysInfo.CurGunSelected].GroupPresentPsuQuantity > 0)
-					{
-						PRINTF_FUNC("=============Smart Charging : _REASSIGNED_NONE============= Step 0 \n");
-						ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_NONE;
-					}
-					else
-					{
-						PRINTF_FUNC("=============Smart Charging : _REASSIGNED_GET_NEW_CAP============= Step 2 \n");
-						ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_GET_NEW_CAP;
-					}
-				}
-
-				if (time > 1000)
-				{
-					for (byte psuCount = 0; psuCount < ShmPsuData->GroupCount; psuCount++)
-					{
-						GetAvailableCap(psuCount, NONE_CARE_ADDRESS,  0);
-					}
-					usleep(cmdDelayTime);
-				}
-
-				for (byte groupIndex = 0; groupIndex < ShmPsuData->GroupCount; groupIndex++)
-				{
-					if (time > 1000)
-					{
-						GetStatus(groupIndex, NONE_CARE_ADDRESS);
-						usleep(cmdDelayTime);
-					    /*
-    					GetMiscInfo(SET_GROUP_CMD, 0, MISC_REQCMD_DC_BOARD_TMP);
-    					usleep(cmdDelayTime);
-    					GetMiscInfo(SET_GROUP_CMD, 0, MISC_REQCMD_PFC_BOARD_TMP);
-    					usleep(cmdDelayTime);
-    					GetMiscInfo(SET_GROUP_CMD, 0, MISC_REQCMD_PFC_BOARD_TMP);
-    					usleep(cmdDelayTime);
-    					*/
-//						if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag == _REASSIGNED_GET_NEW_CAP)
-//						{
-//							if (groupIndex != ShmSysConfigAndInfo->SysInfo.CurGunSelected)
-//							{
-//								if (chargingInfo[groupIndex]->SystemStatus >= S_CHARGING &&	chargingInfo[groupIndex]->SystemStatus <= S_COMPLETE)
-//								{
-//									if (chargingInfo[groupIndex]->DeratingChargingCurrent < chargingInfo[groupIndex]->AvailableChargingCurrent)
-//									{
-//										// 車端需求電流降低至降載的電流
-//										PRINTF_FUNC("Smart Charging : index = %d, EvBatterytargetCurrent = %f, DeratingChargingCurrent = %f \n",
-//										groupIndex, chargingInfo[groupIndex]->EvBatterytargetCurrent, chargingInfo[groupIndex]->DeratingChargingCurrent);
-//
-//										if ((chargingInfo[groupIndex]->EvBatterytargetCurrent <= chargingInfo[groupIndex]->DeratingChargingCurrent) ||
-//											deratingKeepCount >= DERATING)
-//										{
-//											// 車端降載完成
-//											PRINTF_FUNC("=============Smart Charging : _REASSIGNED_MAIN============= Step 3 \n");
-//											ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_MAIN;
-//										}
-//										else
-//										{
-//											deratingKeepCount++;
-//										}
-//									}
-//								}
-//							}
-//						}
-//						else
-//							deratingKeepCount = 0;
-//
-//						if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag == _REASSIGNED_MAIN)
-//						{
-//							PRINTF_FUNC("=============Smart Charging : _REASSIGNED_ADJUST============= Step 4 \n");
-//							//重新分配模組
-//							ReAssignedResource();
-//							gettimeofday(&_derating_time, NULL);
-//							ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_ADJUST;
-//						}
-
-						gettimeofday(&_workModePriority_time, NULL);
-					}
-
-					GetPresentOutput(groupIndex, NONE_CARE_ADDRESS);
-					usleep(cmdDelayTime);
-					//GetVextAndIavail(SET_MODULE_CMD, 0);
-
-					if (chargingInfo[groupIndex]->EvBatterytargetVoltage > 0 &&
-							carReqVol != chargingInfo[groupIndex]->EvBatterytargetVoltage)
-					{
-						carReqVol = chargingInfo[groupIndex]->EvBatterytargetVoltage;
-						DEBUG_INFO("ev need vol = %f \n", chargingInfo[groupIndex]->EvBatterytargetVoltage);
-					}
-
-					if (chargingInfo[groupIndex]->EvBatterytargetCurrent > 0 &&
-							carReqCur != chargingInfo[groupIndex]->EvBatterytargetCurrent)
-					{
-						carReqCur = chargingInfo[groupIndex]->EvBatterytargetCurrent;
-						DEBUG_INFO("ev need cur = %f \n", chargingInfo[groupIndex]->EvBatterytargetCurrent);
-					}
-
-					if (chargingInfo[groupIndex]->FireChargingVoltage > 0 &&
-							evseOutVol != chargingInfo[groupIndex]->FireChargingVoltage)
-					{
-						evseOutVol = chargingInfo[groupIndex]->FireChargingVoltage;
-						PRINTF_FUNC("groupIndex = %d, evse output vol = %f \n", groupIndex,	chargingInfo[groupIndex]->FireChargingVoltage);
-					}
-
-					if (chargingInfo[groupIndex]->PresentChargingCurrent > 0 &&
-							evseOutCur != chargingInfo[groupIndex]->PresentChargingCurrent)
-					{
-						evseOutCur = chargingInfo[groupIndex]->PresentChargingCurrent;
-						PRINTF_FUNC("groupIndex = %d, evse output cur = %f \n", groupIndex, chargingInfo[groupIndex]->PresentChargingCurrent);
-					}
-
-					// 針對各槍當前狀態,傳送需要回傳的資料指令
-					if (((chargingInfo[groupIndex]->SystemStatus >= S_PREPARING_FOR_EVSE && chargingInfo[groupIndex]->SystemStatus <= S_CHARGING) && chargingInfo[groupIndex]->RelayK1K2Status) ||
-							chargingInfo[groupIndex]->SystemStatus == S_REASSIGN ||
-							(chargingInfo[groupIndex]->SystemStatus >= S_CCS_PRECHARGE_ST0 && chargingInfo[groupIndex]->SystemStatus <= S_CCS_PRECHARGE_ST1))
-					{
-						if (ShmPsuData->PsuGroup[groupIndex].GroupAvailableCurrent > 0)
-						{
-//							if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag >= _REASSIGNED_ADJUST &&
-//									ShmSysConfigAndInfo->SysInfo.ReAssignedFlag < _REASSIGNED_COMP )
-//							{
-//								// 如果車端要求的電流超過降載,則以降載電流為主
-//								if (chargingInfo[groupIndex]->EvBatterytargetCurrent >= chargingInfo[groupIndex]->DeratingChargingCurrent)
-//								{
-//									chargingInfo[groupIndex]->EvBatterytargetCurrent = chargingInfo[groupIndex]->DeratingChargingCurrent;
-//								}
-//
-//								if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag == _REASSIGNED_ADJUST)
-//								{
-//									deratingTime = GetTimeoutValue(_derating_time) / 1000;
-//									if (deratingTime > 3000)
-//									{
-//										deratingTime = 0;
-//										PRINTF_FUNC("=============Smart Charging : _REASSIGNED_RELAY============= Step 5 \n");
-//										ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_RELAY;
-//									}
-//
-//									for(int i = 0; i < ShmPsuData->PsuGroup[groupIndex].GroupPresentPsuQuantity; i++)
-//									{
-//										PRINTF_FUNC("*********_REASSIGNED_ADJUST : groupIndex = %d, outputCur = %d, outputVol = %d \n",
-//											groupIndex,
-//										ShmPsuData->PsuGroup[groupIndex].PsuModule[i].PresentOutputCurrent,
-//										ShmPsuData->PsuGroup[groupIndex].PsuModule[i].PresentOutputVoltage);
-//									}
-//								}
-//
-//								// 該充電槍的目標電壓與目標電流
-//								SetPresentOutput(groupIndex, NONE_CARE_ADDRESS,
-//										chargingInfo[groupIndex]->EvBatterytargetVoltage,
-//										chargingInfo[groupIndex]->EvBatterytargetCurrent,
-//										chargingInfo[groupIndex]->DeratingChargingCurrent);
-//								usleep(cmdDelayTime);
-//							}
-//							else
-							{
-								// 該充電槍的目標電壓與目標電流
-								SetPresentOutput(groupIndex, NONE_CARE_ADDRESS,
-										chargingInfo[groupIndex]->EvBatterytargetVoltage,
-										chargingInfo[groupIndex]->EvBatterytargetCurrent,
-										chargingInfo[groupIndex]->AvailableChargingCurrent);
-								usleep(cmdDelayTime);
-							}
-						}
-
-						if (chargingInfo[groupIndex]->EvBatterytargetVoltage == 0)
-						{
-							EnableOutputPower(groupIndex, NONE_CARE_ADDRESS, SWITCH_OFF);
-							usleep(cmdDelayTime);
-							EnableGreenLedFlash(groupIndex , NONE_CARE_ADDRESS , SWITCH_OFF);
-							usleep(cmdDelayTime);
-						}
-						else
-						{
-							EnableOutputPower(groupIndex, NONE_CARE_ADDRESS, SWITCH_ON);
-							usleep(cmdDelayTime);
-							EnableGreenLedFlash(groupIndex , NONE_CARE_ADDRESS, SWITCH_ON);
-							usleep(cmdDelayTime);
-						}
-					}
-					else if (chargingInfo[groupIndex]->SystemStatus >= S_TERMINATING &&
-							chargingInfo[groupIndex]->SystemStatus <= S_COMPLETE)
-					{
-						SetPresentOutput(groupIndex, NONE_CARE_ADDRESS, ZERO_VOL, ZERO_CUR, chargingInfo[groupIndex]->AvailableChargingCurrent);
-						usleep(cmdDelayTime);
-						EnableGreenLedFlash(groupIndex , NONE_CARE_ADDRESS , SWITCH_OFF);
-						usleep(cmdDelayTime);
-						EnableOutputPower(groupIndex, NONE_CARE_ADDRESS, SWITCH_OFF);
-						usleep(cmdDelayTime);
-					}
-				}
-				priorityLow >= 200 ? priorityLow = 1 : priorityLow++;
-				break;
-			}
-		}
-	}
-	return FAIL;
-}
+#include "Module_PsuComm.h"
+
+#define ARRAY_SIZE(A)       (sizeof(A) / sizeof(A[0]))
+#define PASS                1
+#define FAIL                -1
+#define YES                 1
+#define NO                  0
+#define DERATING            30
+#define ELEMENT_NOT_FIND    255
+#define CHK_VOL_RANGE       50
+#define CHK_CUR_RANGE       10
+#define DERATING_RANGE      100
+#define ZERO_CURRENT        10          // 閰脣�潮�靽脲���撠讐� 1A
+#define ZERO_VOLTAGE        50
+#define STOP_CURRENT        30
+#define PSU_MIN_CUR         1000
+#define PRE_CHARG_STEP_CUR  30
+#define PRE_CHARG_RANGE     5
+#define EQUAL               0
+
+struct SysConfigAndInfo         *ShmSysConfigAndInfo;
+struct StatusCodeData           *ShmStatusCodeData;
+struct PsuData                  *ShmPsuData;
+
+bool libInitialize = false;
+byte getAvailableCapOffset = 5;
+byte deratingKeepCount = 0;
+
+float carReqVol = 0;
+float carReqCur = 0;
+float evseOutVol = 0;
+float evseOutCur = 0;
+
+void PRINTF_FUNC(char *string, ...);
+
+int StoreLogMsg(const char *fmt, ...);
+#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);
+
+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];
+    time_t CurrentTime;
+    struct tm *tm;
+    va_list args;
+
+    va_start(args, fmt);
+    int rc = vsnprintf(buffer, sizeof(buffer), fmt, args);
+    va_end(args);
+
+    memset(Buf,0,sizeof(Buf));
+    CurrentTime = time(NULL);
+    tm=localtime(&CurrentTime);
+    sprintf(Buf,"echo \"%04d-%02d-%02d %02d:%02d:%02d - %s\" >> /Storage/SystemLog/[%04d.%02d]SystemLog",
+            tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,
+            buffer,
+            tm->tm_year+1900,tm->tm_mon+1);
+    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);
+
+    if (ShmSysConfigAndInfo->SysConfig.SwitchDebugFlag == YES)
+        printf("%s \n", buffer);
+    else
+        DEBUG_INFO("%s \n", buffer);
+}
+//=================================
+// Common routine
+//=================================
+size_t FindIndex(const int a[], size_t size, int value, byte group)
+{
+    size_t index = 0;
+
+    while ( index < size && a[index] != value ) ++index;
+    return (index == size ? ELEMENT_NOT_FIND : group);
+}
+
+byte FindTargetGroup(byte address)
+{
+    byte _group = ELEMENT_NOT_FIND;
+
+    if (ShmPsuData->GroupCount == 1)
+        _group = 0;
+    else
+    {
+        _group = FindIndex(connector_1, ShmPsuData->PsuGroup[0].GroupPresentPsuQuantity, address, 0);
+
+        if (_group == ELEMENT_NOT_FIND)
+            _group = FindIndex(connector_2, ShmPsuData->PsuGroup[1].GroupPresentPsuQuantity, address, 1);
+    }
+
+    return _group;
+}
+
+bool IsOverModuleCount(byte count)
+{
+    bool result = false;
+
+    if (count >= ShmPsuData->SystemPresentPsuQuantity)
+        result = true;
+
+    return result;
+}
+//=================================
+// Save data to share memory Function
+//=================================
+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;
+}
+
+//=================================
+// Alarm code mapping to share memory Function
+//=================================
+// 瑼X䰻 Byte 銝剜��� Bit ����
+// _byte : 甈脫㺿霈羓� byte
+// _bit : 閰� byte ��洵撟曉�� bit
+unsigned char mask_table[] = { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 };
+unsigned char DetectBitValue(unsigned char _byte, unsigned char _bit)
+{
+    return ( _byte & mask_table[_bit] ) != 0x00;
+}
+
+void AbnormalStopAnalysis(byte gun_index, int errCode)
+{
+    for (char i = 0; i < 3; i++)
+    {
+        unsigned char byteIndex = (errCode >> (8 * i)) & 0xff;
+
+        for (char bitIndex = 0; bitIndex < 8; bitIndex++)
+        {
+            if(DetectBitValue(byteIndex , bitIndex) == 1)
+            {
+                switch(byteIndex)
+                {
+                    case 0:
+                    {
+                        if (bitIndex == 0)
+                            ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuOutputShortCircuit = YES;
+                        else if (bitIndex == 5)
+                            ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuDcSideShutDown = YES;
+                    }
+                        break;
+                    case 1:
+                    {
+                        if (bitIndex == 1)
+                            ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuFailureAlarm = YES;
+                        else if (bitIndex == 2)
+                            ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuProtectionAlarm = YES;
+                        else if (bitIndex == 3)
+                            ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuFanFailureAlarm = YES;
+                        else if (bitIndex == 4)
+                            ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuCriticalPointOTP = YES;
+                        else if (bitIndex == 5)
+                            ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuDcSideShutDown = YES;
+                    }
+                    break;
+                    case 2:
+                    {
+                        if (bitIndex == 0)
+                            ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuPowerLimitedState = YES;
+                        else if (bitIndex == 1)
+                            ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuDuplicateID = YES;
+                        else if (bitIndex == 2)
+                            ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuThreePhaseOnputImbalance = YES;
+                        else if (bitIndex == 3)
+                            ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuThreePhaseInputInadequate = YES;
+                        else if (bitIndex == 4)
+                            ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuThreePhaseInputInadequate = YES;
+                        else if (bitIndex == 5)
+                            ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuInputUVP = YES;
+                        else if (bitIndex == 6)
+                            ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuInputOVP = YES;
+                    }
+                    break;
+                }
+            }
+//          else
+//          {
+//              switch (byteIndex) {
+//              case 0: {
+//                  if (bitIndex == 0)
+//                      ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuOutputShortCircuit = NO;
+//                  else if (bitIndex == 5)
+//                      ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuDcSideShutDown = NO;
+//              }
+//                  break;
+//              case 1: {
+//                  if (bitIndex == 1)
+//                      ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuFailureAlarm = NO;
+//                  else if (bitIndex == 2)
+//                      ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuProtectionAlarm = NO;
+//                  else if (bitIndex == 3)
+//                      ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuFanFailureAlarm = NO;
+//                  else if (bitIndex == 4)
+//                      ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuCriticalPointOTP = NO;
+//                  else if (bitIndex == 5)
+//                      ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuDcSideShutDown = NO;
+//              }
+//                  break;
+//              case 2: {
+//                  if (bitIndex == 1)
+//                      ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuDuplicateID = NO;
+//                  if (bitIndex == 2)
+//                      ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuThreePhaseOnputImbalance = NO;
+//                  else if (bitIndex == 3)
+//                      ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuThreePhaseInputInadequate = NO;
+//                  else if (bitIndex == 4)
+//                      ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuThreePhaseInputInadequate = NO;
+//                  else if (bitIndex == 5)
+//                      ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuInputUVP = NO;
+//                  else if (bitIndex == 6)
+//                      ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuInputOVP = NO;
+//              }
+//                  break;
+//              }
+//          }
+        }
+    }
+}
+
+//=================================
+// Callback Function
+//=================================
+void GetStatusCallback(byte group, byte address, byte temp, int alarm)
+{
+    if (IsOverModuleCount(address))
+        return;
+
+    byte group1 = FindTargetGroup(address);
+
+    if (group1 == 1)
+        address -= ShmPsuData->PsuGroup[group1 - 1].GroupPresentPsuQuantity;
+
+    ShmPsuData->PsuGroup[group1].PsuModule[address].CriticalTemp1 = temp;
+    ShmPsuData->PsuGroup[group1].PsuModule[address].CriticalTemp2 = temp;
+    ShmPsuData->PsuGroup[group1].PsuModule[address].CriticalTemp3 = temp;
+    ShmPsuData->PsuGroup[group1].PsuModule[address].ExletTemp = temp;
+    ShmPsuData->PsuGroup[group1].PsuModule[address].AlarmCode = alarm;
+    AbnormalStopAnalysis(group1, alarm);
+    //printf("alarm = %d \n", alarm);
+}
+
+void GetModuleCountCallback(byte group, byte count)
+{
+    if (group == SYSTEM_CMD)
+        ShmPsuData->SystemPresentPsuQuantity = count;
+    else
+    {
+        ShmPsuData->PsuGroup[group].GroupPresentPsuQuantity = count;
+    }
+}
+
+void GetMaxPowerAndCur(unsigned char mode, int ratingCur, int *pow, int *cur)
+{
+    unsigned short maxCurrent = ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent * 10;
+    unsigned short maxPower = ShmSysConfigAndInfo->SysConfig.MaxChargingPower * 10;
+
+    if (mode == _MAIN_CHARGING_MODE_AVER)
+    {
+        maxCurrent /= 2;
+        maxPower /= 2;
+    }
+
+    if (maxPower != 0 && maxPower <= *pow)
+        *pow = maxPower;
+
+    if (maxCurrent != 0 && maxCurrent <= *cur)
+        *cur = maxCurrent;
+
+    if (ratingCur != 0 && ratingCur <= *cur)
+        *cur = ratingCur;
+}
+
+void GetAvailableCapCallback(byte address, short maxVol, short minVol, short maxCur, short totalPow)
+{
+    int _groupPower = 0, _groupCurrent = 0;
+    byte group = FindTargetGroup(address);
+
+    if (group == 1)
+        address -= ShmPsuData->PsuGroup[group - 1].GroupPresentPsuQuantity;
+
+    if (chargingInfo[group]->DeratingChargingCurrent == 0)
+        ShmPsuData->PsuGroup[group].PsuModule[address].AvailableCurrent = PSU_MIN_CUR;
+    else
+        ShmPsuData->PsuGroup[group].PsuModule[address].AvailableCurrent = maxCur;
+
+    ShmPsuData->PsuGroup[group].PsuModule[address].AvailablePower = totalPow;
+    // 蝮賢�閰� Group ��虾頛詨枂�餅�
+    for (byte index = 0; index < ShmPsuData->PsuGroup[group].GroupPresentPsuQuantity; index++)
+    {
+        _groupCurrent += ShmPsuData->PsuGroup[group].PsuModule[index].AvailableCurrent;
+        _groupPower += ShmPsuData->PsuGroup[group].PsuModule[index].AvailablePower;
+    }
+
+    // ��黎敺堒���憭扯撓�箄��� (�餅���ower)
+    ShmPsuData->PsuGroup[group].GroupAvailableCurrent = _groupCurrent;
+    ShmPsuData->PsuGroup[group].GroupAvailablePower = _groupPower;
+
+    chargingInfo[group]->MaximumChargingVoltage = maxVol;
+
+    int _power = 0, _current = 0, _ratingcurrent = 0;
+    bool isGetAllDeratingCurrent = true;
+
+    for (byte index = 0; index < ShmPsuData->GroupCount; index++)
+    {
+        _power += ShmPsuData->PsuGroup[index].GroupAvailablePower;
+        _current += ShmPsuData->PsuGroup[index].GroupAvailableCurrent;
+        _ratingcurrent += chargingInfo[index]->DeratingChargingCurrent;
+        if (chargingInfo[index]->DeratingChargingCurrent == 0)
+            isGetAllDeratingCurrent = false;
+    }
+
+    // 憒��銝齿糓���厩黎�賢��� Derating current嚗������⊥見閰脫活�� ratingCurrent
+    if (!isGetAllDeratingCurrent) _ratingcurrent = 0;
+
+    ShmPsuData->SystemAvailableCurrent = _current;
+    ShmPsuData->SystemAvailablePower = _power;
+
+    if (ShmSysConfigAndInfo->SysInfo.MainChargingMode == _MAIN_CHARGING_MODE_AVER ||
+        (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag >= _REASSIGNED_GET_NEW_CAP &&
+        ShmSysConfigAndInfo->SysInfo.ReAssignedFlag <= _REASSIGNED_RELAY_M_TO_A))
+    {
+        int halfPow = ShmPsuData->PsuGroup[group].GroupAvailablePower;
+        int halfCur = ShmPsuData->PsuGroup[group].GroupAvailableCurrent;
+        int ratingCur = chargingInfo[group]->DeratingChargingCurrent;
+
+        GetMaxPowerAndCur(_MAIN_CHARGING_MODE_AVER, ratingCur, &halfPow, &halfCur);
+
+//      if ((ShmSysConfigAndInfo->SysInfo.ReAssignedFlag >= _REASSIGNED_GET_NEW_CAP &&
+//               ShmSysConfigAndInfo->SysInfo.ReAssignedFlag <= _REASSIGNED_RELAY_M_TO_A))
+//      {
+//          chargingInfo[group]->AvailableChargingCurrent = DERATING_RANGE;
+//          chargingInfo[group]->AvailableChargingPower = ShmPsuData->PsuGroup[group].GroupAvailablePower;
+//      }
+//      else
+        {
+            // 隞乩���瘜� -> 瑽滩�閮𠹺葉���憭扯撓�箄��𨥈��箄府蝢斤�頛詨枂�賢�
+            // 1. 憒���舀�憭批�
+            // 2. �箄�����𣂼����蝔�
+            chargingInfo[group]->AvailableChargingCurrent = halfCur;
+            chargingInfo[group]->AvailableChargingPower = halfPow;
+        }
+    }
+    else if (ShmSysConfigAndInfo->SysInfo.MainChargingMode == _MAIN_CHARGING_MODE_MAX)
+    {
+        GetMaxPowerAndCur(_MAIN_CHARGING_MODE_MAX, _ratingcurrent, &_power, &_current);
+
+        if (ShmSysConfigAndInfo->SysInfo.IsAlternatvieConf == YES)
+        {
+            for (byte count = 0; count < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; count++)
+            {
+                chargingInfo[count]->MaximumChargingVoltage = maxVol;
+                chargingInfo[count]->AvailableChargingCurrent = _current;
+                chargingInfo[count]->AvailableChargingPower = _power;
+            }
+        }
+        else
+        {
+            // 憒���舀�憭批�嚗諹府瑽滩�閮𠹺葉��撓�箄��𤤿���黎頛詨枂�賢����
+            chargingInfo[group]->AvailableChargingCurrent = _current;
+            chargingInfo[group]->AvailableChargingPower = _power;
+        }
+    }
+}
+
+void GetFwCallback(byte address, short dcSwVer, short pfcSwVer, short hwVer)
+{
+    if (IsOverModuleCount(address))
+        return;
+
+    byte group = FindTargetGroup(address);
+
+    sprintf((char *)ShmPsuData->PsuVersion[address].FwPrimaryVersion, "DC %d.%02d", (dcSwVer & 0xFF00) >> 8, dcSwVer & 0xFF);
+    sprintf((char *)ShmPsuData->PsuVersion[address].FwSecondVersion, "PFC %d.%02d", (pfcSwVer & 0xFF00) >> 8, pfcSwVer & 0xFF);
+    if (group == 1)
+        address -= ShmPsuData->PsuGroup[group - 1].GroupPresentPsuQuantity;
+    sprintf((char *)ShmPsuData->PsuGroup[group].PsuModule[address].FwVersion, "DC %d.%02d", (dcSwVer & 0xFF00) >> 8, dcSwVer & 0xFF);
+    //DEBUG_INFO("fw Ver. = %s \n", ShmPsuData->PsuGroup[group].PsuModule[address].FwVersion);
+}
+
+void GetInputVoltageCallback(byte address, unsigned short vol1, unsigned short vol2, unsigned short vol3)
+{
+    if (IsOverModuleCount(address))
+        return;
+
+    byte group = FindTargetGroup(address);
+
+    if (group == 1)
+        address -= ShmPsuData->PsuGroup[group - 1].GroupPresentPsuQuantity;
+
+    ShmPsuData->PsuGroup[group].PsuModule[address].InputVoltageL1 = vol1;
+    ShmPsuData->PsuGroup[group].PsuModule[address].InputVoltageL2 = vol2;
+    ShmPsuData->PsuGroup[group].PsuModule[address].InputVoltageL3 = vol3;
+}
+
+void GetPresentOutputCallback(byte group, unsigned short outVol, unsigned short outCur)
+{
+    unsigned short outputVol = outVol;
+    unsigned short outputCur = outCur;
+
+    // PSU Group - �餃�
+    ShmPsuData->PsuGroup[group].GroupPresentOutputVoltage = outputVol;
+    // PSU Group - �餅�
+    ShmPsuData->PsuGroup[group].GroupPresentOutputCurrent = outputCur;
+
+    if (ShmSysConfigAndInfo->SysInfo.MainChargingMode == _MAIN_CHARGING_MODE_MAX ||
+        (ShmSysConfigAndInfo->SysInfo.MainChargingMode == _MAIN_CHARGING_MODE_AVER &&
+        (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag >= _REASSIGNED_WAITING &&
+        ShmSysConfigAndInfo->SysInfo.ReAssignedFlag <= _REASSIGNED_COMP))
+        )
+    {
+        outputVol = 0;
+        outputCur = 0;
+
+        for (byte index = 0; index < ShmPsuData->GroupCount; index++)
+        {
+            if (ShmPsuData->PsuGroup[index].GroupPresentOutputVoltage > outputVol)
+                outputVol = ShmPsuData->PsuGroup[index].GroupPresentOutputVoltage;
+
+            outputCur += ShmPsuData->PsuGroup[index].GroupPresentOutputCurrent;
+        }
+
+        // 暺𤑳蒾璈�
+        if (ShmSysConfigAndInfo->SysInfo.IsAlternatvieConf == YES)
+        {
+            for (byte count = 0; count < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; count++)
+            {
+                float _vol_buf = outputVol;
+                float _cur_buf = outputCur;
+
+                // EVSE - �餃�
+                _vol_buf /= 10;
+                chargingInfo[count]->PresentChargingVoltage = _vol_buf;
+                // EVSE - �餅�
+                _cur_buf /= 10;
+                chargingInfo[count]->PresentChargingCurrent = _cur_buf;
+            }
+        }
+
+        if ((chargingInfo[group]->SystemStatus >= S_PREPARING_FOR_EVSE && chargingInfo[group]->SystemStatus <= S_COMPLETE) ||
+            (chargingInfo[group]->SystemStatus >= S_CCS_PRECHARGE_ST0 && chargingInfo[group]->SystemStatus <= S_CCS_PRECHARGE_ST1))
+        {
+            float _vol_buf = outputVol;
+            float _cur_buf = outputCur;
+
+            // EVSE - �餃�
+            _vol_buf /= 10;
+            chargingInfo[group]->PresentChargingVoltage = _vol_buf;
+            // EVSE - �餅�
+            _cur_buf /= 10;
+            chargingInfo[group]->PresentChargingCurrent = _cur_buf;
+        }
+    }
+    else
+    {
+        float _vol_buf = ShmPsuData->PsuGroup[group].GroupPresentOutputVoltage;
+        float _cur_buf = ShmPsuData->PsuGroup[group].GroupPresentOutputCurrent;
+
+        // EVSE - �餃�
+        _vol_buf /= 10;
+        chargingInfo[group]->PresentChargingVoltage = _vol_buf;
+        // EVSE - �餅�
+        _cur_buf /= 10;
+        chargingInfo[group]->PresentChargingCurrent = _cur_buf;
+    }
+
+//  PRINTF_FUNC("Gun_%d, PresentChargingCurrent = %f \n", group,
+//          chargingInfo[group]->PresentChargingCurrent);
+}
+
+void GetFanSpeedCallback(byte address, unsigned int fanSpeed)
+{
+    if (IsOverModuleCount(address))
+        return;
+
+    byte group = FindTargetGroup(address);
+
+    if (group == 1)
+        address -= ShmPsuData->PsuGroup[group - 1].GroupPresentPsuQuantity;
+
+    ShmPsuData->PsuGroup[group].PsuModule[address].FanSpeed_1 = fanSpeed;
+    ShmPsuData->PsuGroup[group].PsuModule[address].FanSpeed_2 = fanSpeed;
+    ShmPsuData->PsuGroup[group].PsuModule[address].FanSpeed_3 = fanSpeed;
+    ShmPsuData->PsuGroup[group].PsuModule[address].FanSpeed_4 = fanSpeed;
+}
+
+void GetIavailableCallback(byte address, unsigned short Iavail, unsigned short Vext)
+{
+    if (IsOverModuleCount(address))
+        return;
+
+    //PRINTF_FUNC("address = %d, Iavail = %d \n", address, Iavail);
+    byte group = FindTargetGroup(address);
+
+    if (group == 1)
+        address -= ShmPsuData->PsuGroup[group - 1].GroupPresentPsuQuantity;
+
+    //PRINTF_FUNC("group = %d, address_%d, Iavail = %d \n", group, address, Iavail);
+    ShmPsuData->PsuGroup[group].PsuModule[address].IAvailableCurrent = Iavail;
+
+    bool isPass = true;
+    int totalCur = 0;
+
+    if (Iavail == 0)
+    {
+        for (byte count = 0; count < 2; count++)
+        {
+            chargingInfo[group]->SampleChargingCur[count] = Iavail;
+        }
+    }
+    else
+    {
+        // 閰脩黎��虾頛詨枂�餅�
+        for (byte index = 0; index < ShmPsuData->PsuGroup[group].GroupPresentPsuQuantity; index++)
+        {
+            totalCur += ShmPsuData->PsuGroup[group].PsuModule[index].IAvailableCurrent;
+        }
+
+        for (byte count = 0; count < 2; count++)
+        {
+            if (chargingInfo[group]->SampleChargingCur[count] == 0)
+            {
+                chargingInfo[group]->SampleChargingCur[count] = totalCur;
+                return;
+            }
+            else
+            {
+                if (chargingInfo[group]->SampleChargingCur[count] != totalCur)
+                {
+                    chargingInfo[group]->SampleChargingCur[count] = totalCur;
+                    isPass = false;
+                    break;
+                }
+            }
+        }
+    }
+
+    if (isPass)
+    {
+        //PRINTF_FUNC("rating pass value = %d \n", totalCur);
+        chargingInfo[group]->DeratingChargingCurrent = totalCur;
+    }
+}
+
+//==========================================
+// Init all share memory
+//==========================================
+int InitShareMemory()
+{
+    int result = PASS;
+    int MeterSMId;
+
+    //creat ShmSysConfigAndInfo
+    if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo),  0777)) < 0)
+    {
+        #ifdef SystemLogMessage
+        DEBUG_ERROR("shmget ShmSysConfigAndInfo NG %d \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 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;
+}
+
+//================================================
+// Main process
+//================================================
+void InitialPsuData()
+{
+    ShmPsuData->SystemPresentPsuQuantity = 0;
+
+    for (byte _groupCount = 0; _groupCount < ARRAY_SIZE(ShmPsuData->PsuGroup);  _groupCount++)
+    {
+        ShmPsuData->PsuGroup[_groupCount].GroupPresentPsuQuantity = 0;
+        ShmPsuData->PsuGroup[_groupCount].GroupAvailablePower = 0;
+        ShmPsuData->PsuGroup[_groupCount].GroupAvailableCurrent = 0;
+    }
+
+    ShmPsuData->Work_Step = _INIT_PSU_STATUS;
+}
+
+void Initialization()
+{
+    bool isPass = false;
+    while(!isPass)
+    {
+        isPass = true;
+        for (byte _index = 0; _index < _gunCount; _index++)
+        {
+            if (!FindChargingInfoData(_index, &chargingInfo[0]))
+            {
+                DEBUG_ERROR("Module_PsuComm : FindChargingInfoData false \n");
+                isPass = false;
+                break;
+            }
+        }
+    }
+
+    if (ShmSysConfigAndInfo->SysInfo.IsAlternatvieConf == YES)
+        ShmPsuData->GroupCount = 1;
+    else
+        ShmPsuData->GroupCount = _gunCount;
+
+    char EvsePower[2];
+
+    EvsePower[2] = '\0';
+    char count = 0;
+    byte psuTarIndex = 0;
+    // 閫�� ModelName �硋�������撟曉�� PSU �羓楊��
+    if (strlen((char *) ShmSysConfigAndInfo->SysConfig.ModelName) >= 6)
+    {
+        strncpy(EvsePower, (char *)(ShmSysConfigAndInfo->SysConfig.ModelName + 4), 2);
+        if (strcmp(EvsePower, "15") == EQUAL)
+            count = 5;
+        else if (strcmp(EvsePower, "30") == EQUAL)
+            count = 1;
+        else if (strcmp(EvsePower, "60") == EQUAL)
+            count = 2;
+        else if (strcmp(EvsePower, "18") == EQUAL)
+            count = 6;
+        else if (strcmp(EvsePower, "36") == EQUAL)
+            count = 12;
+
+        if (count > 0)
+        {
+            if (ShmPsuData->GroupCount == 1)
+                conn_1_count = count;
+            else if (ShmPsuData->GroupCount == 2)
+            {
+                if(count % 2 > 0)
+                    conn_1_count = (count / 2) + 1;
+                else
+                    conn_1_count = (count / 2);
+
+                conn_2_count = count - conn_1_count;
+            }
+
+            for(byte psuIndex = 0; psuIndex < conn_1_count; psuIndex++)
+            {
+                connector_1[psuIndex] = psuTarIndex;
+                psuTarIndex++;
+            }
+
+            for(byte psuIndex = 0; psuIndex < conn_2_count; psuIndex++)
+            {
+                connector_2[psuIndex] = psuTarIndex;
+                psuTarIndex++;
+            }
+
+            for(byte psuIndex = 0; psuIndex < conn_1_count; psuIndex++)
+                PRINTF_FUNC("Connector 1 - Number = %d \n", connector_1[psuIndex]);
+
+            for(byte psuIndex = 0; psuIndex < conn_2_count; psuIndex++)
+                PRINTF_FUNC("Connector 2 - Number = %d \n", connector_2[psuIndex]);
+        }
+        else
+            DEBUG_ERROR("Module_PsuComm : Can't parsing model name. \n");
+    }
+}
+
+void CheckSmartChargingStep(bool isWaitingAver, bool isCharging)
+{
+    if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag == _REASSIGNED_PREPARE_M_TO_A)
+    {
+        if (isWaitingAver)
+        {
+            if (ShmSysConfigAndInfo->SysInfo.MainChargingMode == _MAIN_CHARGING_MODE_MAX)
+            {
+                PRINTF_FUNC("=============Smart Charging : _REASSIGNED_GET_NEW_CAP============= Step 2 \n");
+                ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_GET_NEW_CAP;
+            }
+            else
+            {
+                PRINTF_FUNC("=============Smart Charging : _REASSIGNED_NONE============= Step 0 \n");
+                ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_NONE;
+            }
+        }
+    }
+    else  if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag ==  _REASSIGNED_PREPARE_A_TO_M)
+    {
+        if (isCharging)
+        {
+            if (ShmSysConfigAndInfo->SysInfo.MainChargingMode == _MAIN_CHARGING_MODE_AVER)
+            {
+                PRINTF_FUNC("=============Smart Charging : _REASSIGNED_ADJUST_A_TO_M============= Step 12 \n");
+                ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_ADJUST_A_TO_M;
+            }
+            else
+            {
+                PRINTF_FUNC("=============Smart Charging_1  : _REASSIGNED_COMP============= Step 15 \n");
+                ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_COMP;
+            }
+        }
+        else
+        {
+            PRINTF_FUNC("=============Smart Charging_2 : _REASSIGNED_COMP============= Step 15 \n");
+            ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_COMP;
+        }
+    }
+}
+
+int main(void)
+{
+    if(InitShareMemory() == FAIL)
+    {
+        #ifdef SystemLogMessage
+        DEBUG_ERROR("InitShareMemory NG\n");
+        #endif
+        if(ShmStatusCodeData != NULL)
+        {
+            ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory = 1;
+        }
+        sleep(5);
+        return 0;
+    }
+
+    PRINTF_FUNC("InitShareMemory OK\n");
+
+    // register callback function
+    RefreshStatus(&GetStatusCallback);
+    RefreshModuleCount(&GetModuleCountCallback);
+    RefreshAvailableCap(&GetAvailableCapCallback);
+    RefreshFwVersion(&GetFwCallback);
+    RefreshInputVol(&GetInputVoltageCallback);
+    RefreshGetOutput(&GetPresentOutputCallback);
+    RefreshFanInfo(&GetFanSpeedCallback);
+    RefreshIavailable(&GetIavailableCallback);
+
+    sleep(2);
+    _gunCount = ShmSysConfigAndInfo->SysConfig.TotalConnectorCount;
+    // initial object
+    InitialPsuData();
+    Initialization();
+    libInitialize = InitialCommunication();
+    byte isInitialComp = NO;
+    PRINTF_FUNC("ALTERNATIVE_CONG = %d \n", ShmSysConfigAndInfo->SysInfo.IsAlternatvieConf);
+    //main loop
+    while (libInitialize)
+    {
+        // �琿𤓖����
+        if (ShmSysConfigAndInfo->SysInfo.AcContactorStatus == NO)
+        {
+            //銝�雿� AC Off PSU �琿𤓖�券��� PSU Group ID ����冽� 0
+            if (!isInitialComp)
+            {
+                InitialPsuData();
+                ShmPsuData->Work_Step = INITIAL_START;
+                isInitialComp = YES;
+            }
+            sleep(1);
+            continue;
+        }
+        else
+            isInitialComp = NO;
+
+        // �芣炎憭望�
+        if (ShmPsuData->Work_Step == _NO_WORKING)
+        {
+            PRINTF_FUNC("== PSU == self test fail. \n");
+            sleep(5);
+        }
+
+        switch(ShmPsuData->Work_Step)
+        {
+            case INITIAL_START:
+            {
+                PRINTF_FUNC("== PSU == INITIAL_START \n");
+                gettimeofday(&_cmdSubPriority_time, NULL);
+                sleep(5);
+                SwitchPower(SYSTEM_CMD, PSU_POWER_OFF);
+                ShmPsuData->Work_Step = GET_PSU_COUNT;
+            }
+                break;
+            case GET_PSU_COUNT:
+            {
+                int time = GetTimeoutValue(_cmdSubPriority_time) / 1000;
+                byte moduleCount = 0;
+
+                if (time > 2000)
+                {
+                    PRINTF_FUNC("== PSU == indexCount = %d, moduleCount = %d, sysCount = %d\n",
+                            ShmPsuData->GroupCount, moduleCount, ShmPsuData->SystemPresentPsuQuantity);
+//                  if (ShmPsuData->GroupCount == 0)
+//                      ShmPsuData->GroupCount = ShmSysConfigAndInfo->SysConfig.TotalConnectorCount;
+                    // ��ê̌�硋�蝢斗芋蝯�彍��
+                    for (byte index = 0; index < ShmPsuData->GroupCount; index++)
+                    {
+                        // 蝮賢���黎璅∠��賊�
+                        moduleCount += ShmPsuData->PsuGroup[index].GroupPresentPsuQuantity;
+
+                        // �硋�蝢斗芋蝯�彍��
+                        GetModuleCount(index);
+
+                        // �𣇉���
+                        GetModuleVer(index);
+                    }
+
+                    // �潮���敺㛖𤌍�滚��冽芋蝯�彍��
+                    GetModuleCount(SYSTEM_CMD);
+
+                    // �斗𪃾蝟餌絞�賊����蝢斗彍�譍���
+                    if(moduleCount == ShmPsuData->SystemPresentPsuQuantity && moduleCount > 0)
+                    {
+                        PRINTF_FUNC("Psu Count = %d \n", moduleCount);
+                        if (ShmSysConfigAndInfo->SysInfo.BootingStatus == BOOTTING)
+                        {
+                            // �餅��� Booting ����� - �芣炎
+                            PRINTF_FUNC("== PSU == GET_SYS_CAP \n");
+                            ShmPsuData->Work_Step = GET_SYS_CAP;
+                        }
+                        else
+                        {
+                            PRINTF_FUNC("== PSU == _WORK_CHARGING \n");
+                            ShmPsuData->Work_Step = _WORK_CHARGING;
+
+                            //sdlu test
+                            gettimeofday(&_test_time, NULL);
+                        }
+                    }
+
+                    _getCapDelayCount = 3;
+                    gettimeofday(&_cmdSubPriority_time, NULL);
+                }
+            }
+                break;
+            case GET_SYS_CAP:
+            {
+                int time = GetTimeoutValue(_cmdSubPriority_time) / 1000;
+
+                if (time > 1000)
+                {
+                    for (byte index = 0; index < ShmPsuData->GroupCount; index++)
+                    {
+                        // Pooling Status
+                        GetStatus(index);
+
+                        // �𣇉頂蝯梁蜇頛詨枂�賢�
+                        GetModuleCap(index);
+                    }
+                    _getCapDelayCount--;
+                    gettimeofday(&_cmdSubPriority_time, NULL);
+                }
+
+                // �斗𪃾蝟餌絞頛詨枂憿滚��毺���𤓖瘚�
+                if (ShmPsuData->SystemAvailablePower > 0 && ShmPsuData->SystemAvailableCurrent > 0 &&
+                        _getCapDelayCount <= 0)
+                {
+                    PRINTF_FUNC("SystemAvailableCurrent = %d, SystemAvailablePower = %d \n",
+                            ShmPsuData->SystemAvailableCurrent, ShmPsuData->SystemAvailablePower);
+
+                    PRINTF_FUNC("== PSU == BOOTING_COMPLETE \n");
+                    ShmPsuData->Work_Step = BOOTING_COMPLETE;
+                }
+            }
+                break;
+            case BOOTING_COMPLETE:
+            {
+                bool isSelfTestPass = true;
+                for (byte groupIndex = 0; groupIndex < _gunCount; groupIndex++)
+                {
+                    if (chargingInfo[groupIndex]->SystemStatus == S_BOOTING)
+                    {
+                        isSelfTestPass = false;
+                    }
+                }
+
+                if (isSelfTestPass)
+                    ShmPsuData->Work_Step = _WORK_CHARGING;
+                sleep(1);
+            }
+                break;
+            case _WORK_CHARGING:
+            {
+                int time = GetTimeoutValue(_cmdSubPriority_time) / 1000;
+
+                // 雿� Priority ���隞�
+                if (time > 1500)
+                {
+                    isCharging = false;
+                    isWaitingAver = false;
+                    isReadToCharging = false;
+                    for (byte index = 0; index < ShmPsuData->GroupCount; index++)
+                    {
+                        // Pooling Status
+                        GetStatus(index);
+
+                        // �𣇉頂蝯梁蜇頛詨枂�賢�
+                        GetModuleCap(index);
+
+                        // �硋�璅∪�頛詨��餃�
+                        GetModuleInput(index);
+
+                        // �硋�璅∪�頛詨枂憿滚��餅��賢�
+                        GetModuleIavailable(index);
+
+                        if (chargingInfo[index]->SystemStatus == S_CHARGING)
+                        {
+                            isCharging = true;
+                            if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag == _REASSIGNED_PREPARE_M_TO_A)
+                            {
+                                if (toAverVolPoint > 0 &&
+                                        toAverVolPoint == chargingInfo[index]->EvBatterytargetCurrent)
+                                {
+                                    // 甈脫�憭批� -> �����閬��敺���颱葉��撓�粹𤓖瘚��擃睃��格��餅�
+                                    if ((chargingInfo[index]->PresentChargingCurrent * 10) >=
+                                        chargingInfo[index]->EvBatterytargetCurrent - CHK_CUR_RANGE)
+                                    {
+                                        if (toAverVolCount == 0)
+                                            isWaitingAver = true;
+                                        else
+                                            toAverVolCount--;
+                                    }
+                                }
+                                else
+                                {
+                                    toAverVolPoint = chargingInfo[index]->EvBatterytargetCurrent;
+                                    toAverVolCount = 3;
+                                }
+                            }
+                            else
+                            {
+                                toAverVolPoint = 0;
+                                toAverVolCount = 3;
+                            }
+                        }
+
+                        if ((chargingInfo[index]->SystemStatus >= S_PREPARING_FOR_EVSE && chargingInfo[index]->SystemStatus <= S_CHARGING) ||
+                            (chargingInfo[index]->SystemStatus >= S_CCS_PRECHARGE_ST0 && chargingInfo[index]->SystemStatus <= S_CCS_PRECHARGE_ST1))
+                        {
+                            isReadToCharging = true;
+                        }
+                    }
+
+                    gettimeofday(&_cmdSubPriority_time, NULL);
+                    CheckSmartChargingStep(isWaitingAver, isCharging);
+                }
+
+                for (byte groupIndex = 0; groupIndex < _gunCount; groupIndex++)
+                {
+                    GetModuleOutput(groupIndex);
+                    // �嘥�����嗅����页��喲���閬���喟�鞈����誘
+                    if (((chargingInfo[groupIndex]->SystemStatus >= S_PREPARING_FOR_EVSE && chargingInfo[groupIndex]->SystemStatus <= S_CHARGING) && chargingInfo[groupIndex]->RelayK1K2Status) ||
+                        (chargingInfo[groupIndex]->SystemStatus >= S_PREPARING_FOR_EVSE && chargingInfo[groupIndex]->SystemStatus <= S_CHARGING && chargingInfo[groupIndex]->Type == _Type_GB) ||
+                        (chargingInfo[groupIndex]->SystemStatus >= S_CCS_PRECHARGE_ST0 && chargingInfo[groupIndex]->SystemStatus <= S_CCS_PRECHARGE_ST1))
+                    {
+                        if (chargingInfo[groupIndex]->EvBatterytargetVoltage > 0 &&
+                            carReqVol != chargingInfo[groupIndex]->EvBatterytargetVoltage)
+                        {
+                            carReqVol = chargingInfo[groupIndex]->EvBatterytargetVoltage;
+                            DEBUG_INFO("ev need vol = %f \n", chargingInfo[groupIndex]->EvBatterytargetVoltage);
+                        }
+
+                        if (chargingInfo[groupIndex]->EvBatterytargetCurrent > 0 &&
+                            carReqCur != chargingInfo[groupIndex]->EvBatterytargetCurrent)
+                        {
+                            carReqCur = chargingInfo[groupIndex]->EvBatterytargetCurrent;
+                            DEBUG_INFO("ev need cur = %f \n", chargingInfo[groupIndex]->EvBatterytargetCurrent);
+                        }
+
+                        if (time > 1500)
+                        {
+                            if (chargingInfo[groupIndex]->FireChargingVoltage > 0 &&
+                                evseOutVol != (chargingInfo[groupIndex]->FireChargingVoltage / 10))
+                            {
+                                evseOutVol = (chargingInfo[groupIndex]->FireChargingVoltage / 10);
+                                PRINTF_FUNC("groupIndex = %d, evse output vol = %f \n", groupIndex,
+                                    chargingInfo[groupIndex]->FireChargingVoltage);
+                            }
+
+                            if ((chargingInfo[groupIndex]->PresentChargingCurrent * 10) > 0 &&
+                                evseOutCur != (chargingInfo[groupIndex]->PresentChargingCurrent * 10))
+                            {
+                                evseOutCur = (chargingInfo[groupIndex]->PresentChargingCurrent * 10);
+                                PRINTF_FUNC("groupIndex = %d, evse output cur = %f \n", groupIndex,
+                                    (chargingInfo[groupIndex]->PresentChargingCurrent * 10));
+                            }
+                        }
+
+                        if (ShmSysConfigAndInfo->SysInfo.MainChargingMode == _MAIN_CHARGING_MODE_MAX)
+                        {
+//                          PRINTF_FUNC("index = %d, SystemStatus = %d, Ev = %f, curCur = %f \n", groupIndex,
+//                                  chargingInfo[groupIndex]->SystemStatus, chargingInfo[groupIndex]->EvBatterytargetCurrent,
+//                                  (chargingInfo[groupIndex]->PresentChargingCurrent * 10));
+                            // �箄��斗𪃾 Start -----------------------------------------------------------
+                            if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag == _REASSIGNED_GET_NEW_CAP)
+                            {
+                                if (ShmPsuData->SystemAvailableCurrent != chargingInfo[groupIndex]->AvailableChargingCurrent)
+                                {
+                                    // 頠羓垢閬���餅��箄府��𤓖瑽滨�憿滚�頛詨枂�餅�����滚�
+                                    if (chargingInfo[groupIndex]->EvBatterytargetCurrent <= chargingInfo[groupIndex]->AvailableChargingCurrent ||
+                                        deratingKeepCount >= DERATING)
+                                    {
+                                        // 頠羓垢�滩�摰峕�
+                                        PRINTF_FUNC("=============Smart Charging : _REASSIGNED_ADJUST_M_TO_A============= Step 3 \n");
+                                        ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_ADJUST_M_TO_A;
+                                        gettimeofday(&_derating_time, NULL);
+                                        deratingKeepCount = 0;
+                                    }
+                                    else
+                                    {
+                                        deratingKeepCount++;
+                                    }
+                                }
+
+                            }
+                            else if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag == _REASSIGNED_ADJUST_M_TO_A)
+                            {
+                                bool isChanged = false;
+
+                                // ��瘙�𤓖瘚���滢����瘜�� -> 靘萘�閬��
+                                if (chargingInfo[groupIndex]->AvailableChargingCurrent < chargingInfo[groupIndex]->EvBatterytargetCurrent)
+                                {
+                                    PRINTF_FUNC("** _REASSIGNED_ADJUST_M_TO_A ** Gun_%d, AvailableChargingCurrent = %f, EvBatterytargetCurrent = %f \n", groupIndex,
+                                            (chargingInfo[groupIndex]->PresentChargingCurrent * 10),
+                                            chargingInfo[groupIndex]->AvailableChargingCurrent);
+                                    for (byte subIndex = 0; subIndex < ShmPsuData->GroupCount; subIndex++)
+                                    {
+                                        if (chargingInfo[subIndex]->SystemStatus == S_REASSIGN)
+                                        {
+                                            if ((ShmPsuData->PsuGroup[subIndex].GroupPresentOutputCurrent) <= CHK_CUR_RANGE)
+                                                isChanged = true;
+                                            break;
+                                        }
+                                    }
+
+                                    // �嗵�瘜��頛詨枂蝡舐��餅�頛㗇遛頛㕑����瘜��嚗䔶蒂銝齿��漤𤓖瘚�
+                                    // ��隞亙蘨�賣�頛匧�閰脫�蝡舐���憭扯撓�箄���
+//                                  if ((chargingInfo[groupIndex]->PresentChargingCurrent * 10) >= chargingInfo[groupIndex]->AvailableChargingCurrent - CHK_CUR_RANGE ||
+//                                          (chargingInfo[groupIndex]->PresentChargingCurrent * 10) <= CHK_CUR_RANGE)
+//                                  {
+//                                      isChanged = true;
+//                                  }
+                                }
+                                else if (((chargingInfo[groupIndex]->PresentChargingCurrent * 10) >= ShmPsuData->PsuGroup[groupIndex].GroupPresentOutputCurrent - CHK_CUR_RANGE) &&
+                                        ((chargingInfo[groupIndex]->PresentChargingCurrent * 10) <= ShmPsuData->PsuGroup[groupIndex].GroupPresentOutputCurrent + CHK_CUR_RANGE))
+                                {
+                                    for (byte subIndex = 0; subIndex < ShmPsuData->GroupCount; subIndex++)
+                                    {
+                                        if (chargingInfo[subIndex]->SystemStatus == S_REASSIGN)
+                                        {
+                                            if ((ShmPsuData->PsuGroup[subIndex].GroupPresentOutputCurrent) <= CHK_CUR_RANGE)
+                                                isChanged = true;
+                                            break;
+                                        }
+                                    }
+                                }
+
+                                if (isChanged)
+                                {
+                                    PRINTF_FUNC("** _REASSIGNED_ADJUST_M_TO_A ** Gun_%d, PresentChargingCurrent = %f, GroupPresentOutputCurrent = %d \n", groupIndex,
+                                        (chargingInfo[groupIndex]->PresentChargingCurrent * 10),
+                                        ShmPsuData->PsuGroup[groupIndex].GroupPresentOutputCurrent);
+
+                                    // 頛詨枂蝡航�頠羓垢閬���餅��亥�
+                                    PRINTF_FUNC("=============Smart Charging : _REASSIGNED_RELAY_M_TO_A============= Step 4 \n");
+                                    ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_RELAY_M_TO_A;
+                                }
+                            }
+
+                            if (ShmPsuData->SystemAvailablePower > 0)
+                            {
+                                // 隤踵㟲頛詨枂�餅� : 瞍賊�脰矽�湔䲮撘�
+                                if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag >= _REASSIGNED_ADJUST_M_TO_A)
+                                {
+                                    // �嗅���𤓖銝剔��格��餃�
+                                    float targetVol = chargingInfo[groupIndex]->EvBatterytargetVoltage;
+                                    // �嗅���𤓖銝剔��格��餅�
+                                    //float targetCur = 0;
+                                    // 皞硋���枂�餌�璅∪��餅�
+                                    float deratingCur = 0;
+
+                                    byte reassignIndex = ELEMENT_NOT_FIND;
+                                    // �曉�蝑匧�������
+                                    for (byte subIndex = 0; subIndex < ShmPsuData->GroupCount; subIndex++)
+                                    {
+                                        if (chargingInfo[subIndex]->SystemStatus == S_REASSIGN)
+                                        {
+                                            reassignIndex = subIndex;
+                                        }
+                                    }
+
+                                    if (reassignIndex != ELEMENT_NOT_FIND)
+                                    {
+                                        //int derating = GetTimeoutValue(_derating_time) / 1000;
+
+                                        //if (derating > 1000)
+                                        {
+                                            if (ShmPsuData->PsuGroup[reassignIndex].GroupPresentOutputCurrent > 0)
+                                            {
+                                                deratingCur = ShmPsuData->PsuGroup[reassignIndex].GroupPresentOutputCurrent - DERATING_RANGE;
+                                                if (deratingCur <= CHK_CUR_RANGE)
+                                                    deratingCur = CHK_CUR_RANGE;
+
+                                                PresentOutputVol(reassignIndex, targetVol, deratingCur);
+                                                gettimeofday(&_derating_time, NULL);
+                                            }
+                                        }
+
+                                        // ***********�湔𦻖�滢�閬�宏�斤�璅∪��餅��喳虾*************
+                                        // �删��祉��笔漲瘝埝��滨��笔漲敹恬���隞交繧�拙�漤�笔漲�砍�
+//                                      targetCur = ShmPsuData->PsuGroup[groupIndex].GroupPresentOutputCurrent + (DERATING_RANGE * 2);
+//                                      if (targetCur >= chargingInfo[groupIndex]->EvBatterytargetCurrent)
+//                                              targetCur = chargingInfo[groupIndex]->EvBatterytargetCurrent;
+
+                                        if (targetVol == 0)
+                                        {
+                                            SwitchPower(SYSTEM_CMD, PSU_POWER_OFF);
+                                            FlashLed(SYSTEM_CMD, PSU_FLASH_NORMAL);
+                                        }
+                                        else
+                                        {
+                                            SwitchPower(SYSTEM_CMD, PSU_POWER_ON);
+                                            FlashLed(SYSTEM_CMD, PSU_FLASH_ON);
+                                        }
+                                    }
+                                }
+                                else
+                                {
+                                    // 閰脣��餅���𤌍璅䠷𤓖憯栞��格��餅�
+                                    PresentOutputVol(SYSTEM_CMD,
+                                        chargingInfo[groupIndex]->EvBatterytargetVoltage,
+                                        chargingInfo[groupIndex]->EvBatterytargetCurrent);
+
+                                    if (chargingInfo[groupIndex]->EvBatterytargetVoltage == 0)
+                                    {
+                                        SwitchPower(SYSTEM_CMD, PSU_POWER_OFF);
+                                        FlashLed(SYSTEM_CMD, PSU_FLASH_NORMAL);
+                                    }
+                                    else
+                                    {
+                                        SwitchPower(SYSTEM_CMD, PSU_POWER_ON);
+                                        FlashLed(SYSTEM_CMD, PSU_FLASH_ON);
+                                    }
+                                }
+                            }
+                        }
+                        else if (ShmSysConfigAndInfo->SysInfo.MainChargingMode == _MAIN_CHARGING_MODE_AVER)
+                        {
+                            // �箄��斗𪃾 Start -----------------------------------------------------------
+                            if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag == _REASSIGNED_ADJUST_A_TO_M)
+                            {
+                                bool balanceVol = true;
+
+                                for (byte subIndex = 0; subIndex < ShmPsuData->GroupCount; subIndex++)
+                                {
+                                    if (chargingInfo[subIndex]->SystemStatus == S_IDLE ||
+                                        chargingInfo[subIndex]->SystemStatus == S_RESERVATION)
+                                    {
+                                        // ��黎�餃��亥�撟唾﹛
+                                        if (((chargingInfo[subIndex]->PresentChargingVoltage * 10) < (chargingInfo[groupIndex]->PresentChargingVoltage * 10) - ZERO_VOLTAGE) ||
+                                            ((chargingInfo[subIndex]->PresentChargingVoltage * 10) < chargingInfo[groupIndex]->EvBatterytargetVoltage - CHK_VOL_RANGE))
+                                        {
+                                            PRINTF_FUNC("** _REASSIGNED_ADJUST_A_TO_M ** Gun_%d, PresentChargingVoltage = %f, PresentChargingVoltage_V = %f, EvBatterytargetVoltage = %f \n", subIndex,
+                                                (chargingInfo[subIndex]->PresentChargingVoltage * 10),
+                                                ((chargingInfo[groupIndex]->PresentChargingVoltage * 10) - ZERO_VOLTAGE),
+                                                (chargingInfo[groupIndex]->EvBatterytargetVoltage - CHK_VOL_RANGE));
+                                            balanceVol = false;
+                                        }
+                                        break;
+                                    }
+                                }
+
+                                if (balanceVol)
+                                {
+                                    // �垍蔭蝡航�頠羓垢閬���餃��亥�
+                                    PRINTF_FUNC("=============Smart Charging : _REASSIGNED_RELAY_A_TO_M============= Step 13 \n");
+                                    preChargingCur = preChargingTarget = 0;
+                                    ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_RELAY_A_TO_M;
+                                }
+                            }
+                            else if(ShmSysConfigAndInfo->SysInfo.ReAssignedFlag == _REASSIGNED_WAITING)
+                            {
+                                int idleCurrent = 0;
+                                int chargingCurrent = 0;
+
+                                for (byte subIndex = 0; subIndex < ShmPsuData->GroupCount; subIndex++)
+                                {
+                                    if (chargingInfo[subIndex]->SystemStatus == S_IDLE ||
+                                        chargingInfo[subIndex]->SystemStatus == S_RESERVATION ||
+                                        chargingInfo[subIndex]->SystemStatus == S_REASSIGN_CHECK)
+                                        idleCurrent = ShmPsuData->PsuGroup[subIndex].GroupPresentOutputCurrent;
+                                    else
+                                        chargingCurrent = ShmPsuData->PsuGroup[subIndex].GroupPresentOutputCurrent;
+                                }
+
+                                if (idleCurrent >= chargingCurrent - PRE_CHARG_RANGE)
+                                {
+                                    PRINTF_FUNC("=============Smart Charging_0 : _REASSIGNED_COMP============= Step 15 \n");
+                                    ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_COMP;
+                                }
+                            }
+
+                            if (chargingInfo[groupIndex]->AvailableChargingCurrent > 0)
+                            {
+                                if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag >= _REASSIGNED_ADJUST_A_TO_M)
+                                {
+                                    for (byte subIndex = 0; subIndex < ShmPsuData->GroupCount; subIndex++)
+                                    {
+                                        if (chargingInfo[subIndex]->SystemStatus == S_IDLE ||
+                                            chargingInfo[subIndex]->SystemStatus == S_RESERVATION ||
+                                            chargingInfo[subIndex]->SystemStatus == S_REASSIGN_CHECK)
+                                        {
+                                            // �垍蔭璅∪����嚗�𡖂撠滚����餈睲���芋憛𠺪��𣂷���𤓖瘚��� (preChargingCur)
+                                            PresentOutputVol(subIndex,
+                                                    chargingInfo[groupIndex]->EvBatterytargetVoltage,
+                                                    ZERO_CURRENT + preChargingTarget);
+
+                                            preChargingCur = ShmPsuData->PsuGroup[subIndex].GroupPresentOutputCurrent;
+                                        }
+                                        else
+                                        {
+                                            PRINTF_FUNC("CurOutputCurrent = %d \n", ShmPsuData->PsuGroup[subIndex].GroupPresentOutputCurrent + preChargingCur);
+                                            // ��𤓖銝剔�璅∪�蝬剜�頛詨枂
+                                            PresentOutputVol(subIndex,
+                                                chargingInfo[subIndex]->EvBatterytargetVoltage,
+                                                chargingInfo[subIndex]->EvBatterytargetCurrent - preChargingCur);
+
+                                            if ((ShmSysConfigAndInfo->SysInfo.ReAssignedFlag >= _REASSIGNED_WAITING) &&
+                                                (preChargingCur >= preChargingTarget - ZERO_CURRENT))
+                                                preChargingTarget += PRE_CHARG_STEP_CUR;
+
+                                            if (preChargingTarget >= chargingInfo[subIndex]->EvBatterytargetCurrent / 2)
+                                                preChargingTarget = chargingInfo[subIndex]->EvBatterytargetCurrent / 2;
+                                        }
+
+                                        if (chargingInfo[groupIndex]->EvBatterytargetVoltage == 0)
+                                        {
+                                            SwitchPower(subIndex, PSU_POWER_OFF);
+                                            FlashLed(subIndex, PSU_FLASH_NORMAL);
+                                        }
+                                        else
+                                        {
+                                            SwitchPower(subIndex, PSU_POWER_ON);
+                                            FlashLed(subIndex, PSU_FLASH_ON);
+                                        }
+                                    }
+                                }
+                                else
+                                {
+                                    PresentOutputVol(groupIndex,
+                                        chargingInfo[groupIndex]->EvBatterytargetVoltage,
+                                        chargingInfo[groupIndex]->EvBatterytargetCurrent);
+
+                                    if (chargingInfo[groupIndex]->EvBatterytargetVoltage == 0)
+                                    {
+                                        SwitchPower(groupIndex, PSU_POWER_OFF);
+                                        FlashLed(groupIndex, PSU_FLASH_NORMAL);
+                                    }
+                                    else
+                                    {
+                                        SwitchPower(groupIndex, PSU_POWER_ON);
+                                        FlashLed(groupIndex, PSU_FLASH_ON);
+                                    }
+                                }
+                            }
+                        }
+                    }
+                    else if (chargingInfo[groupIndex]->SystemStatus >= S_TERMINATING &&
+                             chargingInfo[groupIndex]->SystemStatus <= S_COMPLETE)
+                    {
+                        if (ShmSysConfigAndInfo->SysInfo.MainChargingMode == _MAIN_CHARGING_MODE_MAX)
+                        {
+                            if (!isCharging)
+                            {
+                                SwitchPower(SYSTEM_CMD, PSU_POWER_OFF);
+                                FlashLed(SYSTEM_CMD, PSU_FLASH_NORMAL);
+
+                                if (chargingInfo[groupIndex]->SystemStatus == S_COMPLETE)
+                                {
+                                    if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag >= _REASSIGNED_PREPARE_M_TO_A &&
+                                        ShmSysConfigAndInfo->SysInfo.ReAssignedFlag <= _REASSIGNED_RELAY_M_TO_A)
+                                    {
+                                        // 隞�”�典��𤤿��𡒊�銝哨��𨀣迫��𤓖鈭�
+                                        if ((chargingInfo[groupIndex]->PresentChargingCurrent * 10) <= STOP_CURRENT)
+                                            ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_RELAY_M_TO_A;
+                                    }
+                                }
+                            }
+                            else if (chargingInfo[groupIndex]->SystemStatus == S_COMPLETE)
+                            {
+                                // 隞�”��𤓖���靘肽��典��鳴�甈脤�脣���𤓖����𡝗���𤓖鈭�
+                                if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag >= _REASSIGNED_PREPARE_M_TO_A &&
+                                    ShmSysConfigAndInfo->SysInfo.ReAssignedFlag <= _REASSIGNED_RELAY_M_TO_A)
+                                {
+                                    ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_NONE;
+                                }
+                            }
+                        }
+                        else if (ShmSysConfigAndInfo->SysInfo.MainChargingMode == _MAIN_CHARGING_MODE_AVER)
+                        {
+                            if (!isReadToCharging)
+                            {
+                                SwitchPower(SYSTEM_CMD, PSU_POWER_OFF);
+                                FlashLed(SYSTEM_CMD, PSU_FLASH_NORMAL);
+                            }
+                            else
+                            {
+                                SwitchPower(groupIndex, PSU_POWER_OFF);
+                                FlashLed(groupIndex, PSU_FLASH_NORMAL);
+                            }
+
+                            if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag >= _REASSIGNED_WAITING)
+                                ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_COMP;
+                            else
+                                ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_NONE;
+                        }
+                    }
+                }
+                    break;
+            }
+        }
+        usleep(20000);
+    }
+    return FAIL;
+}

+ 60 - 91
EVSE/Projects/DW30/Apps/Module_PsuComm.h

@@ -1,91 +1,60 @@
-#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/wireless.h>
-#include 	<linux/can.h>
-#include 	<linux/can/raw.h>
-#include 	<arpa/inet.h>
-#include 	<netinet/in.h>
-
-#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 	<errno.h>
-#include 	<string.h>
-#include	<time.h>
-#include	<ctype.h>
-#include 	<ifaddrs.h>
-#include	<math.h>
-#include	"../../define.h"
-#include 	<stdbool.h>
-
-
-typedef unsigned char 		byte;
-typedef unsigned short 		word;
-typedef unsigned int 		unit;
-
-#define SELF_TEST_VOL				1600
-#define SELF_TEST_CUR				10
-#define ZERO_VOL					0
-#define ZERO_CUR					0
-#define NONE_CARE_ADDRESS			0
-#define SWITCH_ON		2
-#define SWITCH_OFF		0
-
-
-#define SET_MODULE_CMD              0
-#define SET_GROUP_CMD              1
-
-enum _FIRMWARE_TYPE
-{
-	_Fw_pri_app = 		0,
-	_Fw_sec_app,
-	_Fw_pri_bootload,
-	_Fw_sec_bootload
-};
-
-struct _RecordPsuData
-{
-	byte 				_phy_addr;
-	char 				_serial_num[32];
-	byte 				_fire_index;
-
-};
-
-unsigned char _gunCount = CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY;
-struct ChargingInfoData *chargingInfo[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
-bool rework = false;
-
-struct timeval _id_assign_time;
-struct timeval _chk_output_time;
-bool isCheckOutputTimeStart = false;
-
-byte _curCheckPsuIndexForFireLine = 0x00;
-struct _RecordPsuData recordPsuData[PSU_QUANTITY];
-
-struct timeval _chk_cap_time;
-bool _chkTotalCapStart = false;
-
-bool isUpgradeFlag = false;
-
-struct timeval _workModePriority_time;
-struct timeval _derating_time;
-int deratingTime = 0;
-
-int connector_1[] = {0};
-int connector_2[] = {1};
-int conn_1_count = 0;
-int conn_2_count = 0;
+#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/wireless.h>
+#include <linux/can.h>
+#include <linux/can/raw.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 <math.h>
+#include "../../define.h"
+#include <stdbool.h>
+
+typedef unsigned char       byte;
+typedef unsigned short      word;
+typedef unsigned int        unit;
+
+unsigned char _gunCount;
+struct ChargingInfoData *chargingInfo[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
+
+struct timeval _cmdSubPriority_time;
+byte _getCapDelayCount;
+struct timeval _derating_time;
+
+struct timeval _test_time;
+
+bool isCharging = false;
+bool isWaitingAver = false;
+bool isReadToCharging = false;
+int preChargingTarget;
+int preChargingCur;
+
+float toAverVolPoint;
+byte toAverVolCount;
+
+int connector_1[12];
+int connector_2[12];
+byte conn_1_count = 0;
+byte conn_2_count = 0;

+ 362 - 363
EVSE/Projects/DW30/Apps/PrimaryComm.c

@@ -1,363 +1,362 @@
-#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/wireless.h>
-#include 	<arpa/inet.h>
-#include 	<netinet/in.h>
-
-#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 	<errno.h>
-#include 	<string.h>
-#include	<time.h>
-#include	<ctype.h>
-#include 	<ifaddrs.h>
-#include 	<math.h>
-#include 	"PrimaryComm.h"
-
-#define PASS				1
-#define FAIL				-1
-
-struct Address Addr={0x01,0x02,0x03,0x04,0xFF};
-struct Command Cmd={0x01,0x02,0x0a,0x86,0x87,0xe0,0xe1,0xe2,0xe3};
-
-int tranceive(int fd, unsigned char* cmd, unsigned char cmd_len, unsigned char* rx)
-{
-	int len;
-	//sleep(2); //required to make flush work, for some reason
-	tcflush(fd,TCIOFLUSH);
-	if(write(fd, cmd, cmd_len) >= cmd_len)
-	{
-		usleep(50000);
-		len = read(fd, rx, 512);
-	}
-	else
-	{
-		#ifdef SystemLogMessage
-		DEBUG_ERROR("Serial command %s response fail.\n", cmd);
-		#endif
-	}
-
-	return len;
-}
-
-unsigned char Query_FW_Ver(unsigned char fd, unsigned char targetAddr, Ver *Ret_Buf)
-{
-	unsigned char result = FAIL;
-	unsigned char tx[7] = {0xaa, 0x00, targetAddr, Cmd.query_FW_Ver, 0x00, 0x00, 0x00};
-	unsigned char rx[512];
-	unsigned char chksum = 0x00;
-	unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
-
-	if(len > 0)
-	{
-		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]))
-		{
-			memcpy(Ret_Buf->Version_FW, (char *)rx+6, (rx[4] | rx[5]<<8));
-			*(Ret_Buf->Version_FW + 8) = 0x00;
-			result = PASS;
-		}
-	}
-
-	return result;
-}
-
-unsigned char Query_HW_Ver(unsigned char fd, unsigned char targetAddr, Ver *Ret_Buf)
-{
-	unsigned char result = FAIL;
-	unsigned char tx[7] = {0xaa, 0x00, targetAddr, Cmd.query_HW_Ver, 0x00, 0x00, 0x00};
-	unsigned char rx[512];
-	unsigned char chksum = 0x00;
-
-	if(tranceive(fd, tx, sizeof(tx), rx) >0)
-	{
-		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]))
-		{
-			memcpy(Ret_Buf->Version_HW, (char *)rx+6, (rx[4] | rx[5]<<8));
-			//*(Ret_Buf->Version_HW + 8) = 0x00;
-			result = PASS;
-		}
-	}
-
-	return result;
-}
-
-unsigned char Query_Gpio_Input(unsigned char fd, unsigned char targetAddr, Gpio_in *Ret_Buf)
-{
-	unsigned char result = FAIL;
-	unsigned char tx[7] = {0xaa, 0x00, targetAddr, Cmd.query_Gpio_In, 0x00, 0x00, 0x00};
-	unsigned char rx[512];
-	unsigned char chksum = 0x00;
-	unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
-
-	if(len > 0)
-	{
-		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]))
-		{
-			Ret_Buf->AC_Connector 		= (rx[6] >> 0) & 0x01;
-			Ret_Buf->AC_MainBreaker 	= (rx[6] >> 1) & 0x01;
-			Ret_Buf->SPD 				= (rx[6] >> 2) & 0x01;
-			Ret_Buf->Door_Open 			= (rx[6] >> 3) & 0x01;
-			Ret_Buf->GFD[0] 			= (rx[6] >> 4) & 0x01;
-			Ret_Buf->GFD[1] 			= (rx[6] >> 5) & 0x01;
-			Ret_Buf->AC_Drop 			= (rx[6] >> 6) & 0x01;
-			Ret_Buf->Emergency_IO 		= (rx[6] >> 7) & 0x01;
-
-			Ret_Buf->Emergency_Btn		= (rx[7] >> 0) & 0x01;
-			Ret_Buf->Button[0] 			= (rx[7] >> 1) & 0x01;
-			Ret_Buf->Button[1] 			= (rx[7] >> 2) & 0x01;
-			Ret_Buf->Key[0]				= (rx[7] >> 3) & 0x01;
-			Ret_Buf->Key[1]				= (rx[7] >> 4) & 0x01;
-			Ret_Buf->Key[2]				= (rx[7] >> 5) & 0x01;
-			Ret_Buf->Key[3]				= (rx[7] >> 6) & 0x01;
-
-			result = PASS;
-		}
-	}
-
-	return result;
-}
-
-unsigned char Config_Gpio_Output(unsigned char fd, unsigned char targetAddr, Gpio_out *Set_Buf)
-{
-	unsigned char result = FAIL;
-	unsigned char tx[9] = {0xaa, 0x00, targetAddr, Cmd.config_Gpio_Output, 0x01, 0x00, 0x00, 0x00};
-	unsigned char rx[512];
-	unsigned char chksum = 0x00;
-
-	for (int idx = 0; idx < 2; idx++)
-		tx[6] |= (Set_Buf->Button_LED[idx] ? 0x01:0x00) << (0+idx);
-
-	for (int idx = 0; idx < 4; idx++)
-			tx[6] |= (Set_Buf->System_LED[idx] ? 0x01:0x00) << (2+idx);
-
-	tx[6] |= (Set_Buf->AC_Connector ? 0x01:0x00) << 6;
-	tx[6] |= (Set_Buf->AC_Breaker ? 0x01:0x00) << 7;
-
-	for (int idx = 0; idx < (tx[4] | tx[5] << 8); idx++)
-		chksum ^= tx[6+idx];
-	tx[7] = chksum;
-
-	if (tranceive(fd, tx, sizeof(tx), rx) > 0)
-	{
-		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] == tx[6]))
-		{
-			result = PASS;
-		}
-	}
-
-	return result;
-}
-
-unsigned char Config_Rtc_Data(unsigned char fd, unsigned char targetAddr, Rtc *Set_Buf)
-{
-	unsigned char result = FAIL;
-	unsigned char tx[21] = { 0xaa, 0x00, targetAddr, Cmd.config_Rtc_Data, 0x0E, 0x00, Set_Buf->RtcData[0], Set_Buf->RtcData[1],
-			Set_Buf->RtcData[2], Set_Buf->RtcData[3], Set_Buf->RtcData[4], Set_Buf->RtcData[5], Set_Buf->RtcData[6], Set_Buf->RtcData[7],
-			Set_Buf->RtcData[8], Set_Buf->RtcData[9], Set_Buf->RtcData[10], Set_Buf->RtcData[11], Set_Buf->RtcData[12], Set_Buf->RtcData[13]};
-	unsigned char rx[512];
-	unsigned char chksum = 0x00;
-
-	for (int idx = 0; idx < (tx[4] | tx[5] << 8); idx++)
-		chksum ^= tx[6 + idx];
-	tx[20] = chksum;
-
-	if (tranceive(fd, tx, sizeof(tx), rx) > 0)
-	{
-		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] == tx[6]))
-		{
-			result = PASS;
-		}
-	}
-
-	return result;
-}
-
-unsigned char Update_Start(unsigned char fd, unsigned char targetAddr, unsigned int crc32)
-{
-	unsigned char result = FAIL;
-	unsigned char tx[11] = {0xaa, 0x00, targetAddr, Cmd.update_Start, 0x04, 0x00, (crc32>>0)&0xff, (crc32>>8)&0xff, (crc32>>16)&0xff, (crc32>>24)&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[10] = chksum;
-
-
-	if(tranceive(fd, tx, sizeof(tx), rx) > 0)
-	{
-		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] == 0x00))
-		{
-			result = PASS;
-		}
-	}
-
-	return result;
-}
-
-unsigned char Update_Abord(unsigned char fd, unsigned char targetAddr)
-{
-	unsigned char result = FAIL;
-	unsigned char tx[7] = {0xaa, 0x00, targetAddr, Cmd.update_Start, 0x04, 0x00, 0x00};
-	unsigned char rx[512];
-	unsigned char chksum = 0x00;
-
-	if(tranceive(fd, tx, sizeof(tx), rx) >0)
-	{
-		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] == 0x00))
-		{
-			result = PASS;
-		}
-	}
-
-	return result;
-}
-
-unsigned char Update_Transfer(unsigned char fd, unsigned char targetAddr, unsigned int startAddr, unsigned char *data, unsigned short int length)
-{
-	unsigned char result = FAIL;
-	unsigned char tx[11 + length];
-	unsigned char rx[512];
-	unsigned char chksum = 0x00;
-
-	tx[0] = 0xaa;
-	tx[1] = 0x00;
-	tx[2] = targetAddr;
-	tx[3] = Cmd.update_Transfer;
-	tx[4] = (4 + length) & 0xff;
-	tx[5] = ((4 + length)>>8) & 0xff;
-	tx[6] = (startAddr>>0) & 0xff;
-	tx[7] = (startAddr>>8) & 0xff;
-	tx[8] = (startAddr>>16) & 0xff;
-	tx[9] = (startAddr>>24) & 0xff;
-	memcpy(tx+10, data, length);
-
-	for (int idx = 0; idx < (tx[4] | tx[5] << 8); idx++)
-		chksum ^= tx[6+idx];
-	tx[sizeof(tx)-1] = chksum;
-
-	if(tranceive(fd, tx, sizeof(tx), rx) >0)
-	{
-		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] == 0x00))
-		{
-			result = PASS;
-		}
-	}
-
-	return result;
-}
-
-unsigned char Update_Finish(unsigned char fd, unsigned char targetAddr)
-{
-	unsigned char result = FAIL;
-	unsigned char tx[7] = {0xaa, 0x00, targetAddr, Cmd.update_Finish, 0x04, 0x00, 0x00};
-	unsigned char rx[512];
-	unsigned char chksum = 0x00;
-
-	if(tranceive(fd, tx, sizeof(tx), rx) >0)
-	{
-		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] == 0x00))
-		{
-			result = PASS;
-		}
-	}
-
-	return result;
-}
-
+#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/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 <math.h>
+#include "PrimaryComm.h"
+
+#define PASS                1
+#define FAIL                -1
+
+struct Address Addr={0x01,0x02,0x03,0x04,0xFF};
+struct Command Cmd={0x01,0x02,0x0a,0x86,0x87,0xe0,0xe1,0xe2,0xe3};
+
+int tranceive(int fd, unsigned char* cmd, unsigned char cmd_len, unsigned char* rx)
+{
+    int len;
+    //sleep(2); //required to make flush work, for some reason
+    tcflush(fd,TCIOFLUSH);
+    if(write(fd, cmd, cmd_len) >= cmd_len)
+    {
+        usleep(50000);
+        len = read(fd, rx, 512);
+    }
+    else
+    {
+        #ifdef SystemLogMessage
+        DEBUG_ERROR("Serial command %s response fail.\n", cmd);
+        #endif
+    }
+
+    return len;
+}
+
+unsigned char Query_FW_Ver(unsigned char fd, unsigned char targetAddr, Ver *Ret_Buf)
+{
+    unsigned char result = FAIL;
+    unsigned char tx[7] = {0xaa, 0x00, targetAddr, Cmd.query_FW_Ver, 0x00, 0x00, 0x00};
+    unsigned char rx[512];
+    unsigned char chksum = 0x00;
+    unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
+
+    if(len > 0)
+    {
+        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]))
+        {
+            memcpy(Ret_Buf->Version_FW, (char *)rx+6, (rx[4] | rx[5]<<8));
+            *(Ret_Buf->Version_FW + 8) = 0x00;
+            result = PASS;
+        }
+    }
+
+    return result;
+}
+
+unsigned char Query_HW_Ver(unsigned char fd, unsigned char targetAddr, Ver *Ret_Buf)
+{
+    unsigned char result = FAIL;
+    unsigned char tx[7] = {0xaa, 0x00, targetAddr, Cmd.query_HW_Ver, 0x00, 0x00, 0x00};
+    unsigned char rx[512];
+    unsigned char chksum = 0x00;
+
+    if(tranceive(fd, tx, sizeof(tx), rx) >0)
+    {
+        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]))
+        {
+            memcpy(Ret_Buf->Version_HW, (char *)rx+6, (rx[4] | rx[5]<<8));
+            //*(Ret_Buf->Version_HW + 8) = 0x00;
+            result = PASS;
+        }
+    }
+
+    return result;
+}
+
+unsigned char Query_Gpio_Input(unsigned char fd, unsigned char targetAddr, Gpio_in *Ret_Buf)
+{
+    unsigned char result = FAIL;
+    unsigned char tx[7] = {0xaa, 0x00, targetAddr, Cmd.query_Gpio_In, 0x00, 0x00, 0x00};
+    unsigned char rx[512];
+    unsigned char chksum = 0x00;
+    unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
+
+    if(len > 0)
+    {
+        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]))
+        {
+            Ret_Buf->AC_Connector       = (rx[6] >> 0) & 0x01;
+            Ret_Buf->AC_MainBreaker     = (rx[6] >> 1) & 0x01;
+            Ret_Buf->SPD                = (rx[6] >> 2) & 0x01;
+            Ret_Buf->Door_Open          = (rx[6] >> 3) & 0x01;
+            Ret_Buf->GFD[0]             = (rx[6] >> 4) & 0x01;
+            Ret_Buf->GFD[1]             = (rx[6] >> 5) & 0x01;
+            Ret_Buf->AC_Drop            = (rx[6] >> 6) & 0x01;
+            Ret_Buf->Emergency_IO       = (rx[6] >> 7) & 0x01;
+
+            Ret_Buf->Emergency_Btn      = (rx[7] >> 0) & 0x01;
+            Ret_Buf->Button[0]          = (rx[7] >> 1) & 0x01;
+            Ret_Buf->Button[1]          = (rx[7] >> 2) & 0x01;
+            Ret_Buf->Key[0]             = (rx[7] >> 3) & 0x01;
+            Ret_Buf->Key[1]             = (rx[7] >> 4) & 0x01;
+            Ret_Buf->Key[2]             = (rx[7] >> 5) & 0x01;
+            Ret_Buf->Key[3]             = (rx[7] >> 6) & 0x01;
+
+            result = PASS;
+        }
+    }
+
+    return result;
+}
+
+unsigned char Config_Gpio_Output(unsigned char fd, unsigned char targetAddr, Gpio_out *Set_Buf)
+{
+    unsigned char result = FAIL;
+    unsigned char tx[9] = {0xaa, 0x00, targetAddr, Cmd.config_Gpio_Output, 0x01, 0x00, 0x00, 0x00};
+    unsigned char rx[512];
+    unsigned char chksum = 0x00;
+
+    for (int idx = 0; idx < 2; idx++)
+        tx[6] |= (Set_Buf->Button_LED[idx] ? 0x01:0x00) << (0+idx);
+
+    for (int idx = 0; idx < 4; idx++)
+            tx[6] |= (Set_Buf->System_LED[idx] ? 0x01:0x00) << (2+idx);
+
+    tx[6] |= (Set_Buf->AC_Connector ? 0x01:0x00) << 6;
+    tx[6] |= (Set_Buf->AC_Breaker ? 0x01:0x00) << 7;
+
+    for (int idx = 0; idx < (tx[4] | tx[5] << 8); idx++)
+        chksum ^= tx[6+idx];
+    tx[7] = chksum;
+
+    if (tranceive(fd, tx, sizeof(tx), rx) > 0)
+    {
+        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] == tx[6]))
+        {
+            result = PASS;
+        }
+    }
+
+    return result;
+}
+
+unsigned char Config_Rtc_Data(unsigned char fd, unsigned char targetAddr, Rtc *Set_Buf)
+{
+    unsigned char result = FAIL;
+    unsigned char tx[21] = { 0xaa, 0x00, targetAddr, Cmd.config_Rtc_Data, 0x0E, 0x00, Set_Buf->RtcData[0], Set_Buf->RtcData[1],
+            Set_Buf->RtcData[2], Set_Buf->RtcData[3], Set_Buf->RtcData[4], Set_Buf->RtcData[5], Set_Buf->RtcData[6], Set_Buf->RtcData[7],
+            Set_Buf->RtcData[8], Set_Buf->RtcData[9], Set_Buf->RtcData[10], Set_Buf->RtcData[11], Set_Buf->RtcData[12], Set_Buf->RtcData[13]};
+    unsigned char rx[512];
+    unsigned char chksum = 0x00;
+
+    for (int idx = 0; idx < (tx[4] | tx[5] << 8); idx++)
+        chksum ^= tx[6 + idx];
+    tx[20] = chksum;
+
+    if (tranceive(fd, tx, sizeof(tx), rx) > 0)
+    {
+        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] == tx[6]))
+        {
+            result = PASS;
+        }
+    }
+
+    return result;
+}
+
+unsigned char Update_Start(unsigned char fd, unsigned char targetAddr, unsigned int crc32)
+{
+    unsigned char result = FAIL;
+    unsigned char tx[11] = {0xaa, 0x00, targetAddr, Cmd.update_Start, 0x04, 0x00, (crc32>>0)&0xff, (crc32>>8)&0xff, (crc32>>16)&0xff, (crc32>>24)&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[10] = chksum;
+
+
+    if(tranceive(fd, tx, sizeof(tx), rx) > 0)
+    {
+        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] == 0x00))
+        {
+            result = PASS;
+        }
+    }
+
+    return result;
+}
+
+unsigned char Update_Abord(unsigned char fd, unsigned char targetAddr)
+{
+    unsigned char result = FAIL;
+    unsigned char tx[7] = {0xaa, 0x00, targetAddr, Cmd.update_Start, 0x04, 0x00, 0x00};
+    unsigned char rx[512];
+    unsigned char chksum = 0x00;
+
+    if(tranceive(fd, tx, sizeof(tx), rx) >0)
+    {
+        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] == 0x00))
+        {
+            result = PASS;
+        }
+    }
+
+    return result;
+}
+
+unsigned char Update_Transfer(unsigned char fd, unsigned char targetAddr, unsigned int startAddr, unsigned char *data, unsigned short int length)
+{
+    unsigned char result = FAIL;
+    unsigned char tx[11 + length];
+    unsigned char rx[512];
+    unsigned char chksum = 0x00;
+
+    tx[0] = 0xaa;
+    tx[1] = 0x00;
+    tx[2] = targetAddr;
+    tx[3] = Cmd.update_Transfer;
+    tx[4] = (4 + length) & 0xff;
+    tx[5] = ((4 + length)>>8) & 0xff;
+    tx[6] = (startAddr>>0) & 0xff;
+    tx[7] = (startAddr>>8) & 0xff;
+    tx[8] = (startAddr>>16) & 0xff;
+    tx[9] = (startAddr>>24) & 0xff;
+    memcpy(tx+10, data, length);
+
+    for (int idx = 0; idx < (tx[4] | tx[5] << 8); idx++)
+        chksum ^= tx[6+idx];
+    tx[sizeof(tx)-1] = chksum;
+
+    if(tranceive(fd, tx, sizeof(tx), rx) >0)
+    {
+        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] == 0x00))
+        {
+            result = PASS;
+        }
+    }
+
+    return result;
+}
+
+unsigned char Update_Finish(unsigned char fd, unsigned char targetAddr)
+{
+    unsigned char result = FAIL;
+    unsigned char tx[7] = {0xaa, 0x00, targetAddr, Cmd.update_Finish, 0x04, 0x00, 0x00};
+    unsigned char rx[512];
+    unsigned char chksum = 0x00;
+
+    if(tranceive(fd, tx, sizeof(tx), rx) >0)
+    {
+        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] == 0x00))
+        {
+            result = PASS;
+        }
+    }
+
+    return result;
+}

+ 79 - 79
EVSE/Projects/DW30/Apps/PrimaryComm.h

@@ -1,79 +1,79 @@
-#ifndef PRIMARYCOMM_H_
-#define PRIMARYCOMM_H_
-
-extern struct Address
-{
-	unsigned char Aux;
-	unsigned char Fan;
-	unsigned char Relay;
-	unsigned char IoExtend;
-	unsigned char Broadcast;
-}Addr;
-
-extern struct Command
-{
-	unsigned char query_FW_Ver; 		//0x01
-	unsigned char query_HW_Ver;		//0x02
-	unsigned char query_Gpio_In;		//0x0a
-
-	unsigned char config_Gpio_Output;	//0x86
-	unsigned char config_Rtc_Data;		//0x87
-
-	unsigned char update_Start;		//0xe0
-	unsigned char update_Abort;		//0xe1
-	unsigned char update_Transfer;		//0xe2
-	unsigned char update_Finish;		//0xe3
-
-}Cmd;
-
-typedef struct Verion
-{
-	char Version_FW[16];
-	char Version_HW[16];
-}Ver;
-
-typedef struct GPIO_IN
-{
-	unsigned char AC_Connector;
-	unsigned char AC_MainBreaker;
-	unsigned char SPD;
-	unsigned char Door_Open;
-	unsigned char GFD[2];
-	unsigned char AC_Drop;
-	unsigned char Emergency_IO;
-
-	unsigned char Emergency_Btn;
-	unsigned char Button[2];
-	unsigned char Key[4];
-}Gpio_in;
-
-typedef struct GPIO_OUT
-{
-	unsigned char Button_LED[2];
-	unsigned char System_LED[4];
-	unsigned char AC_Connector;
-	unsigned char AC_Breaker;
-}Gpio_out;
-
-typedef struct RTC
-{
-	unsigned char RtcData[14];
-}Rtc;
-
-extern unsigned char Query_FW_Ver(unsigned char fd, unsigned char targetAddr, Ver *Ret_Buf);
-extern unsigned char Query_HW_Ver(unsigned char fd, unsigned char targetAddr, Ver *Ret_Buf);
-extern unsigned char Query_Gpio_Input(unsigned char fd, unsigned char targetAddr, Gpio_in *Ret_Buf);
-
-extern unsigned char Config_Gpio_Output(unsigned char fd, unsigned char targetAddr, Gpio_out *Set_Buf);
-extern unsigned char Config_Rtc_Data(unsigned char fd, unsigned char targetAddr, Rtc *Set_Buf);
-// 13 bytes
-// year : 4, month : 2, day : 2, hour : 2, min : 2, sec : 2
-//extern unsigned char Config_RTC();
-
-extern unsigned char Update_Start(unsigned char fd, unsigned char targetAddr, unsigned int crc32);
-extern unsigned char Update_Abord(unsigned char fd, unsigned char targetAddr);
-extern unsigned char Update_Transfer(unsigned char fd, unsigned char targetAddr, unsigned int startAddr, unsigned char *data, unsigned short int length);
-extern unsigned char Update_Finish(unsigned char fd, unsigned char targetAddr);
-
-
-#endif /* PRIMARYCOMM_H_ */
+#ifndef PRIMARYCOMM_H_
+#define PRIMARYCOMM_H_
+
+extern struct Address
+{
+    unsigned char Aux;
+    unsigned char Fan;
+    unsigned char Relay;
+    unsigned char IoExtend;
+    unsigned char Broadcast;
+}Addr;
+
+extern struct Command
+{
+    unsigned char query_FW_Ver;         //0x01
+    unsigned char query_HW_Ver;         //0x02
+    unsigned char query_Gpio_In;        //0x0a
+
+    unsigned char config_Gpio_Output;   //0x86
+    unsigned char config_Rtc_Data;      //0x87
+
+    unsigned char update_Start;         //0xe0
+    unsigned char update_Abort;         //0xe1
+    unsigned char update_Transfer;      //0xe2
+    unsigned char update_Finish;        //0xe3
+
+}Cmd;
+
+typedef struct Verion
+{
+    char Version_FW[16];
+    char Version_HW[16];
+}Ver;
+
+typedef struct GPIO_IN
+{
+    unsigned char AC_Connector;
+    unsigned char AC_MainBreaker;
+    unsigned char SPD;
+    unsigned char Door_Open;
+    unsigned char GFD[2];
+    unsigned char AC_Drop;
+    unsigned char Emergency_IO;
+
+    unsigned char Emergency_Btn;
+    unsigned char Button[2];
+    unsigned char Key[4];
+}Gpio_in;
+
+typedef struct GPIO_OUT
+{
+    unsigned char Button_LED[2];
+    unsigned char System_LED[4];
+    unsigned char AC_Connector;
+    unsigned char AC_Breaker;
+}Gpio_out;
+
+typedef struct RTC
+{
+    unsigned char RtcData[14];
+}Rtc;
+
+extern unsigned char Query_FW_Ver(unsigned char fd, unsigned char targetAddr, Ver *Ret_Buf);
+extern unsigned char Query_HW_Ver(unsigned char fd, unsigned char targetAddr, Ver *Ret_Buf);
+extern unsigned char Query_Gpio_Input(unsigned char fd, unsigned char targetAddr, Gpio_in *Ret_Buf);
+
+extern unsigned char Config_Gpio_Output(unsigned char fd, unsigned char targetAddr, Gpio_out *Set_Buf);
+extern unsigned char Config_Rtc_Data(unsigned char fd, unsigned char targetAddr, Rtc *Set_Buf);
+// 13 bytes
+// year : 4, month : 2, day : 2, hour : 2, min : 2, sec : 2
+//extern unsigned char Config_RTC();
+
+extern unsigned char Update_Start(unsigned char fd, unsigned char targetAddr, unsigned int crc32);
+extern unsigned char Update_Abord(unsigned char fd, unsigned char targetAddr);
+extern unsigned char Update_Transfer(unsigned char fd, unsigned char targetAddr, unsigned int startAddr, unsigned char *data, unsigned short int length);
+extern unsigned char Update_Finish(unsigned char fd, unsigned char targetAddr);
+
+
+#endif /* PRIMARYCOMM_H_ */

+ 1089 - 865
EVSE/Projects/DW30/Apps/ReadCmdline.c

@@ -1,865 +1,1089 @@
-/*
- * Main.c
- *
- *  Created on: 2019年8月6日
- *      Author: 7564
- */
-
-
-#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/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 	<math.h>
-#include 	<stdbool.h>
-#include 	"../../define.h"
-
-typedef unsigned char			byte;
-#define PASS				1
-#define FAIL				-1
-#define ARRAY_SIZE(A)		(sizeof(A) / sizeof(A[0]))
-
-#define TTY_PATH            "/dev/tty"
-#define STTY_US             "stty raw -echo -F "
-#define STTY_DEF            "stty -raw echo -F "
-
-struct SysConfigAndInfo			*ShmSysConfigAndInfo;
-struct StatusCodeData 			*ShmStatusCodeData;
-struct PrimaryMcuData			*ShmPrimaryMcuData;
-struct CHAdeMOData				*ShmCHAdeMOData;
-struct CcsData					*ShmCcsData;
-struct FanModuleData			*ShmFanModuleData;
-struct RelayModuleData			*ShmRelayModuleData;
-struct PsuData 					*ShmPsuData;
-
-struct ChargingInfoData 		*_chargingData[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
-int gunCount = CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY;
-
-char *msg = "state : get gun state (index) \n"
-		"card : scanning card (x) : \n"
-		"gun : get gun plugit state (index) \n"
-		"lock : get gun locked state (index) \n"
-		"self : self test state (x) \n"
-		"ver : ver of board (407 or index or rb or fan) \n"
-		"ac : get ac relay state (x) \n";
-
-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;
-}
-
-int InitShareMemory()
-{
-	int result = PASS;
-	int MeterSMId;
-
-	//initial ShmSysConfigAndInfo
-	if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo),  0777)) < 0)
-    {
-		result = FAIL;
-	}
-    else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
-    {
-    	result = FAIL;
-   	 }
-    else
-    {}
-
-   	//initial ShmStatusCodeData
-   	if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData),  0777)) < 0)
-    {
-   		result = FAIL;
-	}
-    else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
-    {
-    	result = FAIL;
-   	}
-    else
-    {}
-
-   	if(CHAdeMO_QUANTITY > 0)
-   	{
-		if ((MeterSMId = shmget(ShmCHAdeMOCommKey, sizeof(struct CHAdeMOData),
-				IPC_CREAT | 0777)) < 0) {
-			result = FAIL;
-		} else if ((ShmCHAdeMOData = shmat(MeterSMId, NULL, 0))
-				== (void *) -1) {
-			result = FAIL;
-		} else {
-		}
-   	}
-
-   	if(CCS_QUANTITY > 0)
-   	{
-		if ((MeterSMId = shmget(ShmCcsCommKey, sizeof(struct CcsData),
-				IPC_CREAT | 0777)) < 0) {
-			result = FAIL;
-		} else if ((ShmCcsData = shmat(MeterSMId, NULL, 0)) == (void *) -1) {
-			result = FAIL;
-		} else {
-		}
-   	}
-
-   	if ((MeterSMId = shmget(ShmPrimaryMcuKey, sizeof(struct PrimaryMcuData), IPC_CREAT | 0777)) < 0)
-   	{
-   		result = FAIL;
-   	}
-   	else if ((ShmPrimaryMcuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
-   	{
-   		result = FAIL;
-   	}
-
-   	if ((MeterSMId = shmget(ShmFanBdKey, sizeof(struct FanModuleData),	IPC_CREAT | 0777)) < 0)
-   	{
-   		result = FAIL;
-   	}
-   	else if ((ShmFanModuleData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
-   	{
-   		result = FAIL;
-   	}
-
-   	if ((MeterSMId = shmget(ShmRelayBdKey, sizeof(struct RelayModuleData),	IPC_CREAT | 0777)) < 0)
-   	{
-   		result = FAIL;
-   	}
-   	else if ((ShmRelayModuleData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
-   	{
-   		result = FAIL;
-   	}
-
-   	if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData),	IPC_CREAT | 0777)) < 0)
-   	{
-   		result = FAIL;
-   	}
-   	else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
-   	{
-   		result = FAIL;
-   	}
-
-    return result;
-}
-
-void RunStatusProc(char *v1, char *v2)
-{
-	int _index = atoi(v1);
-	if (!FindChargingInfoData(_index, &_chargingData[0]))
-	{
-		printf ("FindChargingInfoData error\n");
-		return;
-	}
-
-	if (strcmp(v2, "-1") == 0 || strcmp(v2, "") == 0)
-	{
-		// get
-		printf ("index = %x, status = %x (%d)\n", _index, _chargingData[_index]->SystemStatus, _chargingData[_index]->IsAvailable);
-	}
-	else
-	{
-		// set
-		_chargingData[_index]->SystemStatus = atoi(v2);
-	}
-}
-
-void RunCardProc(char *v1, char *v2)
-{
-	if (ShmSysConfigAndInfo->SysInfo.WaitForPlugit)
-	{
-		ShmSysConfigAndInfo->SysInfo.WaitForPlugit = 0x00;
-		printf ("SysInfo.WaitForPlugit = %x \n", ShmSysConfigAndInfo->SysInfo.WaitForPlugit);
-	}
-	else
-	{
-		ShmSysConfigAndInfo->SysInfo.WaitForPlugit = 0x01;
-		printf ("SysInfo.WaitForPlugit = %x \n", ShmSysConfigAndInfo->SysInfo.WaitForPlugit);
-	}
-}
-
-void RunGunPlugitProc(char *v1, char *v2)
-{
-	int _index = atoi(v1);
-	if (!FindChargingInfoData(_index, &_chargingData[0]))
-	{
-		printf("FindChargingInfoData error\n");
-		return;
-	}
-
-	if (strcmp(v2, "-1") == 0 || strcmp(v2, "") == 0)
-	{
-		// get
-		printf("index = %x, plug it = %x\n", _index, _chargingData[_index]->ConnectorPlugIn);
-	}
-	else
-	{
-		// set
-		_chargingData[_index]->ConnectorPlugIn = atoi(v2);
-	}
-}
-
-void GetGunLockStatusProc(char *v1, char *v2)
-{
-	if (strcmp(v1, "0") == 0)
-	{
-		printf("Gun Locked Status = %x \n", _chargingData[0]->GunLocked);
-	}
-
-	if (strcmp(v1, "1") == 0)
-	{
-		printf("Gun Locked Status = %x \n", _chargingData[1]->GunLocked);
-	}
-}
-
-void SetSystemIDProc()
-{
-	char *systemId = "Alston_Test";
-	memcpy(&ShmSysConfigAndInfo->SysConfig.SystemId, systemId, strlen(systemId));
-}
-
-void RunSelfProc()
-{
-	printf("self test status = %x\n", ShmSysConfigAndInfo->SysInfo.SelfTestSeq);
-}
-
-void GetFwVerProc(char *v1)
-{
-	if (strcmp(v1, "407") == 0)
-	{
-		printf("407 FW Version = %s \n", ShmPrimaryMcuData->version);
-	}
-	else if (strcmp(v1, "0") == 0)
-	{
-		printf("Ev board 1 FW Version = %s \n", ShmCHAdeMOData->evse[0].version);
-		printf("Ev board 1 FW Version = %s \n", ShmCcsData->V2GMessage_DIN70121->version);
-	}
-	else if (strcmp(v1, "1") == 0)
-	{
-		printf("Ev board 2 FW Version = %s \n", ShmCHAdeMOData->evse[1].version);
-		printf("Ev board 2 FW Version = %s \n", ShmCcsData->V2GMessage_DIN70121->version);
-	}
-	else if (strcmp(v1, "rb") == 0)
-	{
-		printf("RB Version = %s \n", ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev);
-	}
-	else if (strcmp(v1, "fan") == 0)
-	{
-		printf("FAN Version = %s \n", ShmSysConfigAndInfo->SysInfo.FanModuleFwRev);
-	}
-	else if (strcmp(v1, "dc") == 0)
-	{
-		printf("DC Main Version = %s \n", ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
-	}
-}
-
-void FwUpdateFlagProc()
-{
-	ShmSysConfigAndInfo->SysInfo.FirmwareUpdate = 0x01;
-}
-
-void CheckAcStatus(char *v1)
-{
-	if (strcmp(v1, "-1") == 0|| strcmp(v1, "") == 0)
-	{
-		printf("AC Status = %d \n", ShmSysConfigAndInfo->SysInfo.AcContactorStatus);
-	}
-}
-
-void SetCableChkStatus(char *v1, char *v2)
-{
-	int _index = atoi(v1);
-	if (!FindChargingInfoData(_index, &_chargingData[0]))
-	{
-		printf ("FindChargingInfoData error\n");
-		return;
-	}
-
-	_chargingData[_index]->GroundFaultStatus = atoi(v2);
-}
-
-void SetPowerValue(char *v1, char *v2)
-{
-//	int _index = atoi(v1);
-//	if (!FindChargingInfoData(_index, &_chargingData[0])) {
-//		printf("FindChargingInfoData error\n");
-//		return;
-//	}
-//
-//	if (strcmp(v2, "-1") == 0 || strcmp(v2, "") == 0) {
-//		// get
-//		printf("index = %x, max cur = %f\n", _index,
-//				_chargingData[_index]->MaxChargingCurrentForTest);
-//	} else {
-//		// set
-//		_chargingData[_index]->MaxChargingCurrentForTest = atoi(v2);
-//	}
-}
-
-void GetGunSelectedNum(char *v1)
-{
-	if (strcmp(v1, "-1") == 0 || strcmp(v1, "") == 0)
-		printf("connector selected = %d \n", ShmSysConfigAndInfo->SysInfo.CurGunSelected);
-	else
-	{
-		int _index = atoi(v1);
-		ShmSysConfigAndInfo->SysInfo.CurGunSelected = _index;
-		printf("connector select changed = %d \n", _index);
-	}
-}
-
-void SetFanSpeed(char *v1)
-{
-	int speed = atoi(v1);
-
-	ShmFanModuleData->TestFanSpeed = speed;
-}
-
-void GetFanSpeed()
-{
-	printf("ShmFanModuleData->PresentFan1Speed = %d \n", ShmFanModuleData->PresentFan1Speed);
-	printf("ShmFanModuleData->PresentFan2Speed = %d \n", ShmFanModuleData->PresentFan2Speed);
-	printf("ShmFanModuleData->PresentFan3Speed = %d \n", ShmFanModuleData->PresentFan3Speed);
-	printf("ShmFanModuleData->PresentFan4Speed = %d \n", ShmFanModuleData->PresentFan4Speed);
-}
-
-void GetPsuInformation(char *v1)
-{
-	printf("*************************************************\n");
-	if(strcmp(v1, "count") == 0)
-	{
-		for (int i = 0; i < 4; i++)
-		{
-			printf("Group Index = %d, Module Count = %d \n", i, ShmPsuData->PsuGroup[i].GroupPresentPsuQuantity);
-		}
-	}
-	else if(strcmp(v1, "ver") == 0)
-	{
-		for (int i = 0; i < ShmPsuData->GroupCount; i++)
-		{
-			for (int j = 0; j < ShmPsuData->PsuGroup[i].GroupPresentPsuQuantity; j++)
-			{
-				printf("Group Index = %d, Psu Index = %d, Version = %s \n",
-					i, j, ShmPsuData->PsuGroup[i].PsuModule[j].FwVersion);
-			}
-		}
-	}
-	else if(strcmp(v1, "cap") == 0)
-	{
-		for (int i = 0; i < ShmPsuData->GroupCount; i++)
-		{
-			printf("Group Index = %d, MaxCur = %d, Power = %d \n",
-					i, ShmPsuData->PsuGroup[i].GroupAvailableCurrent, ShmPsuData->PsuGroup[i].GroupAvailablePower);
-		}
-	}
-	else if (strcmp(v1, "output") == 0)
-	{
-		for (int i = 0; i < ShmPsuData->GroupCount; i++)
-		{
-			printf("Group Index = %d, OutputV = %d, OutputC = %d \n",
-					i, ShmPsuData->PsuGroup[i].GroupPresentOutputVoltage, ShmPsuData->PsuGroup[i].GroupPresentOutputCurrent);
-		}
-	}
-	printf("*************************************************\n");
-}
-
-static int get_char()
-{
-    fd_set rfds;
-    struct timeval tv;
-    int ch = 0;
-
-    FD_ZERO(&rfds);
-    FD_SET(0, &rfds);
-    tv.tv_sec = 0;
-    tv.tv_usec = 10; //wait input timout time
-
-    //if input
-    if (select(1, &rfds, NULL, NULL, &tv) > 0)
-    {
-        ch = getchar();
-    }
-
-    return ch;
-}
-
-void RunUnconditionalChargeIndex1(char *v1, char *v2, char *v3)
-{
-	int _GunIndex = atoi(v1);
-	float _Voltage = atof(v2);
-	int _Current = atoi(v3);
-	unsigned char PreviousSystemStatus = 0xff;
-	int ch = 0;
-
-	if (!FindChargingInfoData(_GunIndex, &_chargingData[0]))
-	{
-		printf ("FindChargingInfoData error\n");
-		return;
-	}
-
-    printf ("ReqVoltage = %f, ReqCurrent = %d\n", _Voltage,_Current);
-
-    if(_Voltage > 1000 || _Voltage < 150){
-
-        printf ("Input Voltage over range\n");
-        return;
-    }
-
-//    if(_Current > 100 || _Current < 2){
-//
-//        printf ("Input Current over range\n");
-//        return;
-//    }
-
-    //測試期間先跳過自我測試 _STEST_COMPLETE = 0xfe
-    //ShmSysConfigAndInfo->SysInfo.SelfTestSeq = 0xfe;
-
-    //kill ev task
-    system("killall Module_EvComm");
-
-    _Voltage = (_Voltage * 10);
-    _Current = (_Current * 10);
-
-    //system(STTY_US TTY_PATH);
-
-    while(true)
-    {
-        //fix gun 1
-        ShmSysConfigAndInfo->SysInfo.CurGunSelected = _GunIndex;
-
-    	switch(_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
-    	{
-            case S_IDLE:
-    		{
-        	    if(PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
-        	    {
-        	        PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
-
-        	        printf ("[UnconditionalCharge - S_IDLE]\n");
-
-        	    }
-
-                _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_PREPARNING;
-    		}
-    		break;
-
-
-    		case S_PREPARNING:
-    		{
-        	    if(PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
-        	    {
-        	        PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
-
-        	        printf ("[UnconditionalCharge - S_PREPARNIN]\n");
-
-        	        //等待 AC Relay 搭上且找到模組 (main 在此 statue 其它 task 會去做完)
-        	        printf ("wait find module\n");
-
-        	    }
-    		    //main 會在此階段判斷以下資料跳到下一個 state
-    		    //用來得知 AC 是否有搭上 (搭上模組的資訊才會出來) 因為每次  AC_Contactor
-
-
-    		    //ShmPsuData->SystemPresentPsuQuantity;
-    		    //ShmPsuData->PsuGroup[gun_index].GroupPresentPsuQuantity;
-    		    //ShmPsuData->PsuGroup[gun_index].GroupAvailablePower;
-    		    //_chargingData[gun_index]->AvailableChargingPower;
-
-    		    //等待 AC Relay 搭上且找到模組 (main 在此 statue 其它 task 會去做完)
-    		    //sleep(10);
-
-    		    //清除 main timeout 機制
-    		    _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->TimeoutFlag = 0;
-    		    //不論是什麼 type 的槍都固意設成 Chademo 不跑 Prechage step
-    		    _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->Type = 9;
-
-    		}
-    		break;
-
-    		case S_PREPARING_FOR_EV:
-    		{
-        	    if(PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
-        	    {
-        	        PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
-
-        	        printf ("[UnconditionalCharge - S_PREPARING_FOR_EV]\n");
-        	        printf ("ReqVoltage = %f, ReqCurrent = %d\n", _Voltage,_Current);
-
-        	    }
-    		    //清除 main timeout 機制
-    		    _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->TimeoutFlag = 0;
-    		    //不論是什麼 type 的槍都固意設成 Chademo 不跑 Prechage step
-    		    _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->Type = 9;
-
-    		    //充電電壓電流
-    		    _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterySoc = 50;
-   		        _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage = 5000;
-    		    _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent = 20;
-    		    _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->AvailableChargingCurrent = 1000;
-
-    		    //****** 注意~此行為是防止 K1K2 先開導到無法升壓 ( Relay Board 在此 state 還未搭上 K1K2 )
-    		    //確定模組己升壓完成
-    		    //if(_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingVoltage <=  (3000+500) &&
-    		    //  _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingVoltage >=  (3000-500) )
-    		    {
-    		        printf ("Precharge Done = %f \n", _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingVoltage);
-    		        //EV done
-    		        _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_PREPARING_FOR_EVSE;
-    		    }
-
-    		}
-    		break;
-
-
-    		case S_PREPARING_FOR_EVSE:
-    		{
-        	    if(PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
-        	    {
-        	        PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
-
-        	        printf ("[UnconditionalCharge - S_PREPARING_FOR_EVSE]\n");
-
-        	    }
-        	    //printf ("tar vol = %d \n", _Voltage);
-        	    //printf ("tar cur = %d \n", _Current);
-
-    		    //清除 main timeout 機制
-    		    _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->TimeoutFlag = 0;
-    		    //不論是什麼 type 的槍都固意設成 Chademo 不跑 Prechage step
-    		    _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->Type = 9;
-
-    		    //充電電壓電流
-    		    _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterySoc = 50;
-    		    _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage = 5000;
-    		    _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent = 20;
-    		    _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->AvailableChargingCurrent = 1000;
-
-    		    //printf ("tar vol_ = %d \n", _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage);
-        	   // printf ("tar cur_ = %d \n", _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent);
-
-    		    //****** 注意~此行為是防止 K1K2 先開導到無法升壓 ( Relay Board 在此 state 還未搭上 K1K2 )
-    		    //確定模組己升壓完成
-    		    if(_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus == 0x01 ||
-    		        _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus == 0x03)
-    		    {
-    		        printf ("First Ground Fault State (%d)\n",_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus);
-    		        printf ("Wait K1K2 = %f \n", _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingVoltage);
-    		        sleep(5);
-    		        //EV done
-    		        _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_CHARGING;
-    		    }
-    		    else if (_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus > 0x02)
-    		    {
-    		             printf ("First Ground Fault check Fail (%d)\n",_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus);
-    		            _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_TERMINATING;
-    		    }
-
-    		}
-    		break;
-
-    		case S_CHARGING:
-    		{
-        	    if(PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
-        	    {
-        	        PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
-
-        	        printf ("[UnconditionalCharge - S_CHARGING]\n");
-
-        	    }
-    		    //充電電壓電流
-    		    _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterySoc = 50;
-    		    _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage = _Voltage;
-    		    _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent = _Current;
-    		    _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->AvailableChargingCurrent = 1000;
-
-    		    //ev task do this
-    		    _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingPower = ((float)((_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingVoltage / 10) * (_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingCurrent / 10)) / 1000);
-
-    		    if (_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus == 0x02){
-    		         printf ("Charging Ground Fault check Fail (%d)\n",_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus);
-    		        _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_TERMINATING;
-    		    }
-
-    		    if (_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus == 0x03){
-    		         printf ("Charging Ground Fault Warning (%d)\n",_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus);
-    		        _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_TERMINATING;
-    		    }
-
-    		}
-    		break;
-
-     		case S_TERMINATING:
-    		{
-        	    if(PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
-        	    {
-        	        PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
-        	        system("/root/Module_EvComm &");
-
-        	        printf ("[UnconditionalCharge - S_TERMINATING]\n");
-        	        //無阻塞偵測 keybaord 結束
-        	        system(STTY_DEF TTY_PATH);
-
-        	    }
-
-        	    sleep(3);
-        	    _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_COMPLETE;
-        	    return;
-    		}
-    		break;
-
-    		case S_COMPLETE:
-    		{
-        	    if(PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
-        	    {
-        	        PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
-
-        	        printf ("[UnconditionalCharge - S_COMPLETE]\n");
-
-        	    }
-        	    sleep(3);
-        	    return;
-    		}
-    		break;
-    	}
-
-    	/*
-    	//使用 Keyboard input 阻塞方法
-        fgets(InputChar, sizeof(InputChar), stdin);
-
-        if (InputChar[0] == 's' && InputChar[1] == 't' && InputChar[2] == 'o' && InputChar[3] == 'p')
-        {
-           printf ("Precharge Done\n");
-           _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_TERMINATING;
-
-        }
-        */
-
-        //使用 keybaord input 非阻塞方法
-        ch = get_char();
-        if (ch)
-        {
-            printf("%c \n\r", ch);
-
-            switch (ch)
-            {
-                //Ctrl + C
-                case 3:
-                    //system(STTY_DEF TTY_PATH);
-                        return;
-                //input c or C
-                case 'c':
-                case 'C':
-                    printf("stop \n\r");
-                    //system(STTY_DEF TTY_PATH);
-                    _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_TERMINATING;
-                    break;
-            }
-        }
-
-    }
-
-}
-
-int main(void)
-{
-	if(InitShareMemory() == FAIL)
-	{
-		printf ("InitShareMemory = FAIL \n");
-		if(ShmStatusCodeData != NULL)
-		{
-			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
-		}
-		sleep(5);
-		return 0;
-	}
-
-	for(;;)
-	{
-		char word[128];
-		char newString[7][10];
-		int i,j,ctr;
-
-		fgets(word, sizeof(word), stdin);
-
-		j=0; ctr=0;
-		strcpy(newString[1], "-1");
-		strcpy(newString[2], "-1");
-		for (i = 0; i <= (strlen(word)); i++)
-		{
-			if (word[i] == ' ' || word[i] == '\0' || word[i] == 10)
-			{
-				newString[ctr][j] = '\0';
-				ctr++;
-				j = 0;
-			}
-			else
-			{
-				newString[ctr][j] = word[i];
-				j++;
-			}
-		}
-
-		if(strcmp(newString[0], "state") == 0)
-		{
-			if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
-				continue;
-
-			// 槍狀態
-			RunStatusProc(newString[1], newString[2]);
-		}
-		else if(strcmp(newString[0], "card") == 0)
-		{
-			// 刷卡狀態
-			RunCardProc(newString[1], newString[2]);
-		}
-		else if(strcmp(newString[0], "gun") == 0)
-		{
-			if (strcmp(newString[1], "-1") == 0	|| strcmp(newString[1], "") == 0)
-				continue;
-
-			// 插槍狀態
-			RunGunPlugitProc(newString[1], newString[2]);
-		}
-		else if(strcmp(newString[0], "lock") == 0)
-		{
-			if (strcmp(newString[1], "-1") == 0	|| strcmp(newString[1], "") == 0)
-				continue;
-
-			// 插槍狀態
-			GetGunLockStatusProc(newString[1], newString[2]);
-		}
-		else if(strcmp(newString[0], "sysid") == 0)
-		{
-			// 測試 sys id
-			SetSystemIDProc();
-		}
-		else if(strcmp(newString[0], "self") == 0)
-		{
-			// CSU 自我檢測狀態
-			RunSelfProc(newString[1]);
-		}
-		else if(strcmp(newString[0], "ver") == 0)
-		{
-			if (strcmp(newString[1], "-1") == 0	|| strcmp(newString[1], "") == 0)
-				continue;
-			// 取 FW 版號
-			GetFwVerProc(newString[1]);
-		}
-		else if (strcmp(newString[0], "update") == 0)
-		{
-			// 更新
-			FwUpdateFlagProc(newString[1]);
-		}
-		else if (strcmp(newString[0], "ac") == 0)
-		{
-			// AC contactor 狀態
-			CheckAcStatus(newString[1]);
-		}
-		else if (strcmp(newString[0], "cable") == 0)
-		{
-			if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
-				continue;
-			// cable check pass
-			SetCableChkStatus(newString[1], newString[2]);
-		}
-		else if (strcmp(newString[0], "pow") == 0)
-		{
-			if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
-				continue;
-			// cable check pass
-			SetPowerValue(newString[1], newString[2]);
-		}
-		else if(strcmp(newString[0], "select") == 0)
-		{
-			// 取得當前選的槍號
-			GetGunSelectedNum(newString[1]);
-		}
-		else if(strcmp(newString[0], "fan") == 0)
-		{
-			// 設定風扇速度
-			SetFanSpeed(newString[1]);
-		}
-		else if(strcmp(newString[0], "speed") == 0)
-		{
-			// 取得風扇速度
-			GetFanSpeed();
-		}
-		else if(strcmp(newString[0], "psu") == 0)
-		{
-			//如果連一個參數都沒有 (此命令不理會) 加上判斷第二參數
-			if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
-			{
-				printf ("PSU : Param fail..Please retry again......\n");
-				continue;
-			}
-
-			// 取得 PSU 資訊
-			GetPsuInformation(newString[1]);
-		}
-		else if(strcmp(newString[0], "strchg") == 0)
-		{
-			//如果連一個參數都沒有 (此命令不理會) 加上判斷第二參數
-			if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0 ||
-					strcmp(newString[2], "-1") == 0 || strcmp(newString[2], "") == 0)
-			{
-				printf ("Input cmd fail ------  strchg [vol 150-1000] [cru 2-100]\n");
-				continue;
-			}
-
-			// 槍狀態
-			RunUnconditionalChargeIndex1(newString[1], newString[2], newString[3]);
-		}
-
-		printf ("%s\n", msg);
-		usleep(100000);
-	}
-
-	return 0;
-}
+/*
+ * Main.c
+ *
+ *  Created on: 2019撟�8��6��
+ *      Author: 7564
+ */
+
+
+#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/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 <math.h>
+#include <stdbool.h>
+#include "../../define.h"
+
+typedef unsigned char           byte;
+#define PASS                1
+#define FAIL                -1
+#define ARRAY_SIZE(A)       (sizeof(A) / sizeof(A[0]))
+#define NO_DEFINE           255
+#define DEFAULT_AC_INDEX    2
+
+#define TTY_PATH            "/dev/tty"
+#define STTY_US             "stty raw -echo -F "
+#define STTY_DEF            "stty -raw echo -F "
+
+struct SysConfigAndInfo         *ShmSysConfigAndInfo;
+struct StatusCodeData           *ShmStatusCodeData;
+struct PrimaryMcuData           *ShmPrimaryMcuData;
+struct CHAdeMOData              *ShmCHAdeMOData;
+struct CcsData                  *ShmCcsData;
+struct GBTData                  *ShmGBTData;
+struct FanModuleData            *ShmFanModuleData;
+struct RelayModuleData          *ShmRelayModuleData;
+struct PsuData                  *ShmPsuData;
+
+struct ChargingInfoData         *_chargingData[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
+struct ChargingInfoData         *ac_chargingInfo[AC_QUANTITY];
+
+char *msg = "state : get gun state (index) \n"
+        "card : scanning card (x) : \n"
+        "gun : get gun plugit state (index) \n"
+        "lock : get gun locked state (index) \n"
+        "self : self test state (x) \n"
+        "ver : ver of board (407 or index or rb or fan) \n"
+        "ac : get ac relay state (x) \n";
+
+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;
+}
+
+bool FindAcChargingInfoData(byte target, struct ChargingInfoData **acChargingData)
+{
+    if (target < AC_QUANTITY)
+    {
+        acChargingData[target] = &ShmSysConfigAndInfo->SysInfo.AcChargingData[target];
+        return true;
+    }
+
+    return false;
+}
+
+int InitShareMemory()
+{
+    int result = PASS;
+    int MeterSMId;
+
+    //initial ShmSysConfigAndInfo
+    if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo),  0777)) < 0)
+    {
+        result = FAIL;
+    }
+    else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
+    {
+        result = FAIL;
+    }
+    else
+    {}
+
+    //initial ShmStatusCodeData
+    if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData),  0777)) < 0)
+    {
+        result = FAIL;
+    }
+    else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
+    {
+        result = FAIL;
+    }
+    else
+    {}
+
+    if (CHAdeMO_QUANTITY > 0) {
+        if ((MeterSMId = shmget(ShmCHAdeMOCommKey, sizeof(struct CHAdeMOData),
+        IPC_CREAT | 0777)) < 0) {
+            result = FAIL;
+        } else if ((ShmCHAdeMOData = shmat(MeterSMId, NULL, 0))
+                == (void *) -1) {
+            result = FAIL;
+        } else {
+        }
+    }
+
+    if (CCS_QUANTITY > 0) {
+        if ((MeterSMId = shmget(ShmCcsCommKey, sizeof(struct CcsData),
+        IPC_CREAT | 0777)) < 0) {
+            result = FAIL;
+        } else if ((ShmCcsData = shmat(MeterSMId, NULL, 0)) == (void *) -1) {
+            result = FAIL;
+        } else {
+        }
+    }
+
+    if (GB_QUANTITY > 0) {
+        if ((MeterSMId = shmget(ShmGBTCommKey, sizeof(struct GBTData),
+        IPC_CREAT | 0777)) < 0) {
+            return 0;
+        } else if ((ShmGBTData = shmat(MeterSMId, NULL, 0)) == (void *) -1) {
+            return 0;
+        }
+        memset(ShmGBTData, 0, sizeof(struct GBTData));
+    }
+
+    if ((MeterSMId = shmget(ShmPrimaryMcuKey, sizeof(struct PrimaryMcuData), IPC_CREAT | 0777)) < 0)
+    {
+        result = FAIL;
+    }
+    else if ((ShmPrimaryMcuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
+    {
+        result = FAIL;
+    }
+
+    if ((MeterSMId = shmget(ShmFanBdKey, sizeof(struct FanModuleData),  IPC_CREAT | 0777)) < 0)
+    {
+        result = FAIL;
+    }
+    else if ((ShmFanModuleData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
+    {
+        result = FAIL;
+    }
+
+    if ((MeterSMId = shmget(ShmRelayBdKey, sizeof(struct RelayModuleData),  IPC_CREAT | 0777)) < 0)
+    {
+        result = FAIL;
+    }
+    else if ((ShmRelayModuleData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
+    {
+        result = FAIL;
+    }
+
+    if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData),  IPC_CREAT | 0777)) < 0)
+    {
+        result = FAIL;
+    }
+    else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
+    {
+        result = FAIL;
+    }
+
+    return result;
+}
+
+void RunStatusProc(char *v1, char *v2)
+{
+    int _index = atoi(v1);
+    if (_index <= 1)
+    {
+        if (!FindChargingInfoData(_index, &_chargingData[0]))
+        {
+            printf ("FindChargingInfoData error\n");
+            return;
+        }
+
+        if (strcmp(v2, "-1") == 0 || strcmp(v2, "") == 0)
+        {
+            // get
+            printf ("index = %x, status = %x (%d)\n", _index, _chargingData[_index]->SystemStatus, _chargingData[_index]->IsAvailable);
+            printf ("SystemTimeoutFlag = %d, PageIndex = %d\n",
+                    ShmSysConfigAndInfo->SysInfo.SystemTimeoutFlag, ShmSysConfigAndInfo->SysInfo.PageIndex);
+        }
+        else
+        {
+            // set
+            _chargingData[_index]->SystemStatus = atoi(v2);
+        }
+    }
+    else
+    {
+        if (!FindAcChargingInfoData(0, &ac_chargingInfo[0]))
+        {
+            printf("FindChargingInfoData (AC) false \n");
+        }
+
+        if (strcmp(v2, "-1") == 0 || strcmp(v2, "") == 0)
+        {
+            // get
+            printf ("AC Type, status = %x (%d)\n", ac_chargingInfo[0]->SystemStatus, ac_chargingInfo[0]->IsAvailable);
+        }
+        else
+        {
+            // set
+            ac_chargingInfo[0]->SystemStatus = atoi(v2);
+        }
+    }
+}
+
+void RunCardProc(char *v1, char *v2)
+{
+    if (strcmp(v1, "-1") == 0 || strcmp(v1, "") == 0)
+    {
+        if (ShmSysConfigAndInfo->SysInfo.WaitForPlugit)
+        {
+            ShmSysConfigAndInfo->SysInfo.WaitForPlugit = 0x00;
+            printf ("SysInfo.WaitForPlugit = %x \n", ShmSysConfigAndInfo->SysInfo.WaitForPlugit);
+        }
+        else
+        {
+            ShmSysConfigAndInfo->SysInfo.WaitForPlugit = 0x01;
+            printf ("SysInfo.WaitForPlugit = %x \n", ShmSysConfigAndInfo->SysInfo.WaitForPlugit);
+        }
+    }
+    else
+    {
+        memcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, v1, ARRAY_SIZE(v1));
+        printf("StartUserId = %s \n", ShmSysConfigAndInfo->SysConfig.UserId);
+    }
+}
+
+void RunGunPlugitProc(char *v1, char *v2)
+{
+    int _index = atoi(v1);
+    if (!FindChargingInfoData(_index, &_chargingData[0]))
+    {
+        printf("FindChargingInfoData error\n");
+        return;
+    }
+
+    if (strcmp(v2, "-1") == 0 || strcmp(v2, "") == 0)
+    {
+        // get
+        printf("index = %x, plug it = %x\n", _index, _chargingData[_index]->ConnectorPlugIn);
+    }
+    else
+    {
+        // set
+        _chargingData[_index]->ConnectorPlugIn = atoi(v2);
+    }
+}
+
+void GetGunLockStatusProc(char *v1, char *v2)
+{
+    int _index = atoi(v1);
+    if (!FindChargingInfoData(_index, &_chargingData[0]))
+    {
+        printf("FindChargingInfoData error\n");
+        return;
+    }
+
+    printf("Gun Locked Status = %x \n", _chargingData[_index]->GunLocked);
+}
+
+void SetSystemIDProc()
+{
+    char *systemId = "Alston_Test";
+    memcpy(&ShmSysConfigAndInfo->SysConfig.SystemId, systemId, strlen(systemId));
+}
+
+void RunSelfProc()
+{
+    printf("self test status = %x\n", ShmSysConfigAndInfo->SysInfo.SelfTestSeq);
+}
+
+void GetFwVerProc(char *v1)
+{
+    if (strcmp(v1, "407") == 0)
+    {
+        printf("407 FW Version = %s \n", ShmPrimaryMcuData->version);
+    }
+    else if (strcmp(v1, "0") == 0)
+    {
+        printf("Ev board 0 FW Version = %s \n", ShmCHAdeMOData->evse[0].version);
+    }
+    else if (strcmp(v1, "1") == 0)
+    {
+        printf("Ev board 1 FW Version = %s \n", ShmCcsData->V2GMessage_DIN70121->version);
+    }
+    else if (strcmp(v1, "2") == 0)
+    {
+        printf("Ev board 2 FW Version = %s \n", ShmGBTData->evse[0].version);
+    }
+    else if (strcmp(v1, "rb") == 0)
+    {
+        printf("RB Version = %s \n", ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev);
+    }
+    else if (strcmp(v1, "fan") == 0)
+    {
+        printf("FAN Version = %s \n", ShmSysConfigAndInfo->SysInfo.FanModuleFwRev);
+    }
+    else if (strcmp(v1, "dc") == 0)
+    {
+        printf("DC Main Version = %s \n", ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
+    }
+    else if (strcmp(v1, "ac") == 0)
+    {
+        if (!FindAcChargingInfoData(0, &ac_chargingInfo[0]))
+        {
+            printf("FindChargingInfoData (AC) false \n");
+        }
+        printf("AC Version = %s \n", ac_chargingInfo[0]->version);
+    }
+}
+
+void CreateOneError(char *v1)
+{
+    int value = atoi(v1);
+
+    ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PrimaryStestFail = value;
+    ShmSysConfigAndInfo->SysConfig.BillingData.isBilling = value;
+}
+
+void FwUpdateFlagProc()
+{
+    ShmSysConfigAndInfo->SysInfo.FirmwareUpdate = 0x01;
+}
+
+void CheckAcStatus(char *v1)
+{
+    if (strcmp(v1, "-1") == 0|| strcmp(v1, "") == 0)
+    {
+        printf("AC Status = %d \n", ShmSysConfigAndInfo->SysInfo.AcContactorStatus);
+    }
+}
+
+void SetCableChkStatus(char *v1, char *v2)
+{
+    int _index = atoi(v1);
+    if (!FindChargingInfoData(_index, &_chargingData[0]))
+    {
+        printf ("FindChargingInfoData error\n");
+        return;
+    }
+
+    _chargingData[_index]->GroundFaultStatus = atoi(v2);
+}
+
+void SetPowerValue(char *v1, char *v2)
+{
+    int _index = atoi(v1);
+    float _Current = atof(v2);
+    // �脫�����蹱���迂雿輻鍂~
+    if (_chargingData[_index]->Type != 9)
+        return;
+
+    if (!FindChargingInfoData(_index, &_chargingData[0]))
+    {
+        printf ("FindChargingInfoData error\n");
+        return;
+    }
+
+    _chargingData[_index]->EvBatterytargetCurrent = _Current * 10;
+}
+
+void GetSystemInfo()
+{
+    printf ("ModelName = %s \n", ShmSysConfigAndInfo->SysConfig.ModelName);
+    printf ("MaxChargingPower = %d, MaxChargingCurrent = %d \n",
+            ShmSysConfigAndInfo->SysConfig.MaxChargingPower,
+            ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
+}
+
+void ChangeGunNum()
+{
+    if (ShmSysConfigAndInfo->SysInfo.CurGunSelected + 1 < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount)
+    {
+        ShmSysConfigAndInfo->SysInfo.CurGunSelected += 1;
+        ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc = NO_DEFINE;
+    }
+    else if (ShmSysConfigAndInfo->SysConfig.AcConnectorCount > 0 &&
+            ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc == NO_DEFINE)
+        ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc = DEFAULT_AC_INDEX;
+    else
+    {
+        ShmSysConfigAndInfo->SysInfo.CurGunSelected = 0;
+        ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc = NO_DEFINE;
+    }
+}
+
+void GetGunSelectedNum(char *v1)
+{
+    if (strcmp(v1, "-1") == 0 || strcmp(v1, "") == 0)
+    {
+        if (AC_QUANTITY > 0 &&
+            ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc != NO_DEFINE)
+        {
+            printf("connector select changed = AC \n");
+        }
+        else
+            printf("connector selected = %d \n", ShmSysConfigAndInfo->SysInfo.CurGunSelected);
+    }
+    else
+    {
+        int _index = atoi(v1);
+        if (_index <= 1)
+        {
+            ShmSysConfigAndInfo->SysInfo.CurGunSelected = _index;
+            ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc = NO_DEFINE;
+            printf("connector select changed = %d \n", _index);
+        }
+        else if (AC_QUANTITY > 0)
+        {
+            ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc = DEFAULT_AC_INDEX;
+            printf("connector select changed = AC \n");
+        }
+    }
+}
+
+void SetFanSpeed(char *v1)
+{
+    int speed = atoi(v1);
+
+    ShmFanModuleData->TestFanSpeed = speed;
+}
+
+void GetFanSpeed()
+{
+    printf("ShmFanModuleData->PresentFan1Speed = %d \n", ShmFanModuleData->PresentFan1Speed);
+    printf("ShmFanModuleData->PresentFan2Speed = %d \n", ShmFanModuleData->PresentFan2Speed);
+    printf("ShmFanModuleData->PresentFan3Speed = %d \n", ShmFanModuleData->PresentFan3Speed);
+    printf("ShmFanModuleData->PresentFan4Speed = %d \n", ShmFanModuleData->PresentFan4Speed);
+}
+
+void SetDebugMode(char *v1)
+{
+    int mode = atoi(v1);
+
+    ShmSysConfigAndInfo->SysConfig.SwitchDebugFlag = mode;
+}
+
+void SetGFDMode(char *v1)
+{
+    int mode = atoi(v1);
+
+    ShmSysConfigAndInfo->SysConfig.AlwaysGfdFlag = mode;
+}
+
+void GetPsuTemp()
+{
+    for (byte index = 0; index < ShmPsuData->GroupCount; index++)
+    {
+        for (byte count = 0; count < ShmPsuData->PsuGroup[index].GroupPresentPsuQuantity; count++)
+        {
+            printf("PSU Temp = %d \n", ShmPsuData->PsuGroup[index].PsuModule[count].ExletTemp);
+        }
+    }
+}
+
+void GetAcInputVol()
+{
+    printf("L1N_L12 = %f, L2N_L23 = %f, L3N_L31 = %f \n",
+            ShmSysConfigAndInfo->SysInfo.InputVoltageR,
+            ShmSysConfigAndInfo->SysInfo.InputVoltageS,
+            ShmSysConfigAndInfo->SysInfo.InputVoltageT);
+}
+
+void GetPsuInformation(char *v1)
+{
+    printf("**********************AC Contact needed*************************\n");
+    if(strcmp(v1, "count") == 0)
+    {
+        for (int i = 0; i < 4; i++)
+        {
+            printf("Group Index = %d, Module Count = %d \n", i, ShmPsuData->PsuGroup[i].GroupPresentPsuQuantity);
+        }
+    }
+    else if(strcmp(v1, "ver") == 0)
+    {
+        for (int i = 0; i < ShmPsuData->SystemPresentPsuQuantity; i++)
+        {
+            printf("Psu Index = %d, PriVersion = %s, SecVersion = %s \n",
+                    i, ShmPsuData->PsuVersion[i].FwPrimaryVersion, ShmPsuData->PsuVersion[i].FwSecondVersion);
+        }
+
+        for (int i = 0; i < ShmPsuData->GroupCount; i++)
+        {
+            for (int j = 0; j < ShmPsuData->PsuGroup[i].GroupPresentPsuQuantity; j++)
+            {
+                printf("Group Index = %d, Psu Index = %d, Version = %s \n",
+                    i, j, ShmPsuData->PsuGroup[i].PsuModule[j].FwVersion);
+            }
+        }
+    }
+    else if(strcmp(v1, "cap") == 0)
+    {
+        for (int i = 0; i < ShmPsuData->GroupCount; i++)
+        {
+            printf("Group Index = %d, MaxCur = %d, Power = %d \n",
+                    i, ShmPsuData->PsuGroup[i].GroupAvailableCurrent, ShmPsuData->PsuGroup[i].GroupAvailablePower);
+        }
+    }
+    else if (strcmp(v1, "output") == 0)
+    {
+        for (int i = 0; i < ShmPsuData->GroupCount; i++)
+        {
+            printf("Group Index = %d, OutputV = %d, OutputC = %d \n",
+                    i, ShmPsuData->PsuGroup[i].GroupPresentOutputVoltage, ShmPsuData->PsuGroup[i].GroupPresentOutputCurrent);
+        }
+    }
+    printf("*************************************************\n");
+}
+
+void GetConnectorCapInfo(char *v1)
+{
+    int _GunIndex = atoi(v1);
+
+    if (!FindChargingInfoData(_GunIndex, &_chargingData[0]))
+    {
+        printf ("FindChargingInfoData error\n");
+        return;
+    }
+
+    printf ("Charger Max Current = %d, Max Power = %d \n",
+            ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent * 10,
+            ShmSysConfigAndInfo->SysConfig.MaxChargingPower * 10);
+
+    printf ("Index = %d, MaxPow = %f, MaxVol = %f, MaxCur = %f\n",
+            _GunIndex,
+            _chargingData[_GunIndex]->RealMaxPower,
+            _chargingData[_GunIndex]->RealMaxVoltage,
+            _chargingData[_GunIndex]->RealMaxCurrent);
+}
+
+static void get_char(char *word)
+{
+    fd_set rfds;
+    struct timeval tv;
+
+    FD_ZERO(&rfds);
+    FD_SET(0, &rfds);
+    tv.tv_sec = 0;
+    tv.tv_usec = 10; //wait input timout time
+
+    //if input
+    if (select(1, &rfds, NULL, NULL, &tv) > 0)
+    {
+        fgets(word, 128, stdin);
+    }
+}
+
+void RunUnconditionalChargeIndex1(char *v1, char *v2, char *v3)
+{
+    int _GunIndex = atoi(v1);
+    float _Voltage = atof(v2);
+    float _Current = atof(v3);
+    unsigned char PreviousSystemStatus = 0xff;
+
+    if (!FindChargingInfoData(_GunIndex, &_chargingData[0]))
+    {
+        printf ("FindChargingInfoData error\n");
+        return;
+    }
+
+    printf ("ReqVoltage = %f, ReqCurrent = %f\n", _Voltage, _Current);
+
+    if(_Voltage > 1000 || _Voltage < 50)
+    {
+
+        printf ("Input Voltage over range\n");
+        return;
+    }
+
+//    if(_Current > 100 || _Current < 2){
+//
+//        printf ("Input Current over range\n");
+//        return;
+//    }
+
+    //皜祈岫�罸���歲�舘䌊�烐葫閰� _STEST_COMPLETE = 0xfe
+    //ShmSysConfigAndInfo->SysInfo.SelfTestSeq = 0xfe;
+
+    //kill ev task
+    system("killall Module_EvComm");
+
+    _Voltage = (_Voltage * 10);
+    _Current = (_Current * 10);
+
+    //system(STTY_US TTY_PATH);
+
+    while(true)
+    {
+        //fix gun 1
+        ShmSysConfigAndInfo->SysInfo.CurGunSelected = _GunIndex;
+
+        switch(_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
+        {
+            case S_IDLE:
+            {
+                if(PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
+                {
+                    PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
+
+                    printf ("[UnconditionalCharge - S_IDLE]\n");
+
+                }
+
+                ShmSysConfigAndInfo->SysInfo.StartToChargingFlag = 0x01;
+                _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_PREPARNING;
+            }
+            break;
+
+
+            case S_PREPARNING:
+            {
+                if(PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
+                {
+                    PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
+
+                    printf ("[UnconditionalCharge - S_PREPARNIN]\n");
+
+                    //蝑匧� AC Relay �凋�銝娍𪄳�唳芋蝯� (main �冽迨 statue �嗅� task ��縧�𡁜�)
+                    printf ("wait find module\n");
+
+                }
+                //main ��銁甇日�畾萄ế�瑚誑銝贝��躰歲�唬�銝��� state
+                //�其�敺㛖䰻 AC �臬炏�㗇𨰹銝� (�凋�璅∠����閮𦠜���枂靘�) �删�瘥𤩺活  AC_Contactor
+
+
+                //ShmPsuData->SystemPresentPsuQuantity;
+                //ShmPsuData->PsuGroup[gun_index].GroupPresentPsuQuantity;
+                //ShmPsuData->PsuGroup[gun_index].GroupAvailablePower;
+                //_chargingData[gun_index]->AvailableChargingPower;
+
+                //蝑匧� AC Relay �凋�銝娍𪄳�唳芋蝯� (main �冽迨 statue �嗅� task ��縧�𡁜�)
+                //sleep(10);
+
+                //皜�膄 main timeout 璈笔�
+                _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->TimeoutFlag = 0;
+                //銝滩��臭�暻� type ����賢𤐄�讛身�� Chademo 銝滩� Prechage step
+                _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->Type = 9;
+
+            }
+            break;
+
+            case S_PREPARING_FOR_EV:
+            {
+                if(PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
+                {
+                    PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
+
+                    printf ("[UnconditionalCharge - S_PREPARING_FOR_EV]\n");
+                    printf ("ReqVoltage = %f, ReqCurrent = %f \n", _Voltage,_Current);
+
+                }
+                //皜�膄 main timeout 璈笔�
+                _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->TimeoutFlag = 0;
+                //銝滩��臭�暻� type ����賢𤐄�讛身�� Chademo 銝滩� Prechage step
+                _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->Type = 9;
+
+                //��𤓖�餃��餅�
+                _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterySoc = 50;
+                _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage = 5000;
+                _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent = 20;
+                _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->AvailableChargingCurrent = 1000;
+
+                //****** 瘜冽�~甇方��箸糓�脫迫 K1K2 ���撠𤾸��⊥���� ( Relay Board �冽迨 state ��𧊋�凋� K1K2 )
+                //蝣箏�璅∠�撌勗�憯枏���
+                //if(_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingVoltage <=  (3000+500) &&
+                //  _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingVoltage >=  (3000-500) )
+                {
+                    printf ("Precharge Done = %f \n", _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingVoltage);
+                    //EV done
+                    _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_PREPARING_FOR_EVSE;
+                }
+
+            }
+            break;
+
+
+            case S_PREPARING_FOR_EVSE:
+            {
+                if(PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
+                {
+                    PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
+
+                    printf ("[UnconditionalCharge - S_PREPARING_FOR_EVSE]\n");
+
+                }
+                //printf ("tar vol = %d \n", _Voltage);
+                //printf ("tar cur = %d \n", _Current);
+
+                //皜�膄 main timeout 璈笔�
+                _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->TimeoutFlag = 0;
+                //銝滩��臭�暻� type ����賢𤐄�讛身�� Chademo 銝滩� Prechage step
+                _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->Type = 9;
+
+                //��𤓖�餃��餅�
+                _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterySoc = 50;
+                _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage = 5000;
+                _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent = 20;
+                _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->AvailableChargingCurrent = 1000;
+
+                //printf ("tar vol_ = %d \n", _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage);
+               // printf ("tar cur_ = %d \n", _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent);
+
+                //****** 瘜冽�~甇方��箸糓�脫迫 K1K2 ���撠𤾸��⊥���� ( Relay Board �冽迨 state ��𧊋�凋� K1K2 )
+                //蝣箏�璅∠�撌勗�憯枏���
+                if(_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus == 0x01 ||
+                    _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus == 0x03)
+                {
+                    printf ("First Ground Fault State (%d)\n",_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus);
+                    printf ("Wait K1K2 = %f \n", _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingVoltage);
+                    sleep(5);
+                    //EV done
+                    _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_CHARGING;
+                }
+                else if (_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus > 0x02)
+                {
+                    printf ("First Ground Fault check Fail (%d)\n",_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus);
+                    _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_TERMINATING;
+                }
+
+            }
+            break;
+
+            case S_CHARGING:
+            {
+                if(PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
+                {
+                    PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
+
+                    //��𤓖�餃��餅�
+                    _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterySoc = 50;
+                    _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage = _Voltage;
+                    _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent = _Current;
+                    _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->AvailableChargingCurrent = 1000;
+
+                    printf ("[UnconditionalCharge - S_CHARGING]\n");
+                }
+
+                //ev task do this
+                _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingPower =
+                        ((float)((_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingVoltage) * (_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingCurrent)) / 1000);
+
+                if (_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus == 0x02){
+                     printf ("Charging Ground Fault check Fail (%d)\n",_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus);
+                    _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_TERMINATING;
+                }
+
+                if (_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus == 0x03){
+                     printf ("Charging Ground Fault Warning (%d)\n",_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus);
+                    _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_TERMINATING;
+                }
+
+            }
+            break;
+
+            case S_TERMINATING:
+            {
+                if(PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
+                {
+                    PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
+                    system("/root/Module_EvComm &");
+
+                    printf ("[UnconditionalCharge - S_TERMINATING]\n");
+                    //�⊿獈憛𧼮�皜� keybaord 蝯鞉�
+                    system(STTY_DEF TTY_PATH);
+
+                }
+
+                sleep(3);
+                _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_COMPLETE;
+                return;
+            }
+            break;
+
+            case S_COMPLETE:
+            {
+                if(PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
+                {
+                    PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
+
+                    printf ("[UnconditionalCharge - S_COMPLETE]\n");
+                }
+                sleep(3);
+                return;
+            }
+            break;
+        }
+
+        char word[128];
+        char newString[7][10];
+        int i,j,ctr;
+
+        memset(word, 0x00, sizeof(word));
+        get_char(word);
+
+        if (strlen(word) == 0)
+            continue;
+
+        j=0; ctr=0;
+        strcpy(newString[1], "-1");
+        strcpy(newString[2], "-1");
+        for (i = 0; i <= (strlen(word)); i++)
+        {
+            if (word[i] == ' ' || word[i] == '\0' || word[i] == 10)
+            {
+                newString[ctr][j] = '\0';
+                ctr++;
+                j = 0;
+            }
+            else
+            {
+                newString[ctr][j] = word[i];
+                j++;
+            }
+        }
+
+        if(strcmp(newString[0], "chg") == 0)
+        {
+            if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
+               continue;
+            if (strcmp(newString[2], "-1") == 0 || strcmp(newString[2], "") == 0)
+               continue;
+
+            float _vol = atof(newString[1]);
+            float _cur = atof(newString[2]);
+
+            if (_cur <= 0 || _cur <= 0)
+               continue;
+
+            printf("vol = %f, cur = %f \n", _vol, _cur);
+            _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage = _vol * 10;
+            _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent = _cur * 10;
+        }
+        else if (strcmp(newString[0], "c") == 0)
+        {
+            printf("stop \n\r");
+            ShmSysConfigAndInfo->SysInfo.StartToChargingFlag = 0x00;
+            _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_TERMINATING;
+        }
+
+        usleep(100000);
+    }
+}
+
+int main(void)
+{
+    if(InitShareMemory() == FAIL)
+    {
+        printf ("InitShareMemory = FAIL \n");
+        if(ShmStatusCodeData != NULL)
+        {
+            ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
+        }
+        sleep(5);
+        return 0;
+    }
+
+    for(;;)
+    {
+        char word[128];
+        char newString[7][10];
+        int i,j,ctr;
+
+        fgets(word, sizeof(word), stdin);
+
+        j=0; ctr=0;
+        strcpy(newString[1], "-1");
+        strcpy(newString[2], "-1");
+        for (i = 0; i <= (strlen(word)); i++)
+        {
+            if (word[i] == ' ' || word[i] == '\0' || word[i] == 10)
+            {
+                newString[ctr][j] = '\0';
+                ctr++;
+                j = 0;
+            }
+            else
+            {
+                newString[ctr][j] = word[i];
+                j++;
+            }
+        }
+
+        if(strcmp(newString[0], "state") == 0)
+        {
+            if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
+                continue;
+
+            // 瑽滨���
+            RunStatusProc(newString[1], newString[2]);
+        }
+        else if(strcmp(newString[0], "card") == 0)
+        {
+            // �瑕㨃����
+            RunCardProc(newString[1], newString[2]);
+        }
+        else if(strcmp(newString[0], "gun") == 0)
+        {
+            if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
+                continue;
+
+            // �埝�����
+            RunGunPlugitProc(newString[1], newString[2]);
+        }
+        else if(strcmp(newString[0], "lock") == 0)
+        {
+            if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
+                continue;
+
+            // �埝�����
+            GetGunLockStatusProc(newString[1], newString[2]);
+        }
+        else if(strcmp(newString[0], "sysid") == 0)
+        {
+            // 皜祈岫 sys id
+            SetSystemIDProc();
+        }
+        else if(strcmp(newString[0], "self") == 0)
+        {
+            // CSU �芣�瑼X葫����
+            RunSelfProc(newString[1]);
+        }
+        else if(strcmp(newString[0], "ver") == 0)
+        {
+            if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
+                continue;
+            // �� FW ���
+            GetFwVerProc(newString[1]);
+        }
+        else if (strcmp(newString[0], "update") == 0)
+        {
+            // �湔鰵
+            FwUpdateFlagProc(newString[1]);
+        }
+        else if (strcmp(newString[0], "ac") == 0)
+        {
+            // AC contactor ����
+            CheckAcStatus(newString[1]);
+        }
+        else if (strcmp(newString[0], "cable") == 0)
+        {
+            if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
+                continue;
+            // cable check pass
+            SetCableChkStatus(newString[1], newString[2]);
+        }
+        else if (strcmp(newString[0], "pow") == 0)
+        {
+            if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
+                continue;
+            // cable check pass
+            SetPowerValue(newString[1], newString[2]);
+        }
+        else if (strcmp(newString[0], "model") == 0)
+        {
+            GetSystemInfo();
+        }
+        else if(strcmp(newString[0], "select") == 0)
+        {
+            // �硋� / 閮剖� �嗅��貊�瑽滩�
+            GetGunSelectedNum(newString[1]);
+        }
+        else if(strcmp(newString[0], "change") == 0)
+        {
+            // 璅⊥挱�厰��寡��豢�
+            ChangeGunNum();
+        }
+        else if(strcmp(newString[0], "fan") == 0)
+        {
+            // 閮剖�憸冽��笔漲
+            SetFanSpeed(newString[1]);
+        }
+        else if(strcmp(newString[0], "speed") == 0)
+        {
+            // �硋�憸冽��笔漲
+            GetFanSpeed();
+        }
+        else if(strcmp(newString[0], "debug") == 0)
+        {
+            // 閮剖� debug mode
+            SetDebugMode(newString[1]);
+        }
+        else if (strcmp(newString[0], "gfd") == 0)
+        {
+            // 閮剖��脫�雿輻鍂 GFD �蠘�
+            SetGFDMode(newString[1]);
+        }
+        else if(strcmp(newString[0], "temp") == 0)
+        {
+            // �硋� PSU 皞怠漲
+            GetPsuTemp();
+        }
+        else if(strcmp(newString[0], "acin") == 0)
+        {
+            // �硋�銝匧�頛詨��餃�
+            GetAcInputVol();
+        }
+        else if(strcmp(newString[0], "psu") == 0)
+        {
+            //憒������见��賊�瘝埝� (甇文𦶢隞支����) �牐��斗𪃾蝚砌���彍
+            if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
+            {
+                printf ("PSU : Param fail..Please retry again......\n");
+                continue;
+            }
+
+            // �硋� PSU 鞈��
+            GetPsuInformation(newString[1]);
+        }
+        else if (strcmp(newString[0], "cap") == 0)
+        {
+            GetConnectorCapInfo(newString[1]);
+        }
+        else if(strcmp(newString[0], "error") == 0)
+        {
+            CreateOneError(newString[1]);
+        }
+        else if(strcmp(newString[0], "strchg") == 0)
+        {
+            //憒������见��賊�瘝埝� (甇文𦶢隞支����) �牐��斗𪃾蝚砌���彍
+            if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0 ||
+                    strcmp(newString[2], "-1") == 0 || strcmp(newString[2], "") == 0)
+            {
+                printf ("Input cmd fail ------  strchg [vol 150-1000] [cru 2-100]\n");
+                continue;
+            }
+
+            // 瑽滨���
+            RunUnconditionalChargeIndex1(newString[1], newString[2], newString[3]);
+        }
+        else
+            printf ("%s\n", msg);
+        usleep(100000);
+    }
+
+    return 0;
+}

+ 0 - 1
EVSE/Projects/DW30/Apps/init.sh

@@ -8,4 +8,3 @@ chmod 777 Module_PsuComm
 chmod 777 OcppBackend
 chmod 777 kill.sh
 chmod 777 ReadCmdline
-

+ 1103 - 740
EVSE/Projects/DW30/Apps/internalComm.c

@@ -1,835 +1,1198 @@
 /*
  * internalComm.c
  *
- *  Created on: 2019¦~5¤ë7¤é
+ *  Created on: 2019年5月7日
  *      Author: foluswen
  */
-#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/wireless.h>
-#include 	<arpa/inet.h>
-#include 	<netinet/in.h>
-
-#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 	<errno.h>
-#include 	<string.h>
-#include	<time.h>
-#include	<ctype.h>
-#include 	<ifaddrs.h>
-#include 	<math.h>
-#include 	"internalComm.h"
-
-#define PASS				1
-#define FAIL				-1
-
-struct Address Addr={0x01,0x02,0x03,0xFF};
-struct Command Cmd={0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x81,0x83,0x85,0x86, 0x87,0x8B,0xe0,0xe1,0xe2,0xe3};
+#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/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 <math.h>
+#include "internalComm.h"
+
+#define PASS                1
+#define FAIL                -1
+
+struct Address Addr={0x01,0x02,0x03,0x05,0x06,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};
 
 int tranceive(int fd, unsigned char* cmd, unsigned char cmd_len, unsigned char* rx)
 {
-	int len;
-	//sleep(2); //required to make flush work, for some reason
-	tcflush(fd,TCIOFLUSH);
-	if(write(fd, cmd, cmd_len) >= cmd_len)
-	{
-		usleep(10000);
-		len = read(fd, rx, 512);
-	}
-	else
-	{
-		#ifdef SystemLogMessage
-		DEBUG_ERROR("Serial command %s response fail.\n", cmd);
-		#endif
-	}
-
-	return len;
+    int len;
+    //sleep(2); //required to make flush work, for some reason
+    tcflush(fd,TCIOFLUSH);
+    if(write(fd, cmd, cmd_len) >= cmd_len)
+    {
+        usleep(15000);
+        len = read(fd, rx, 512);
+    }
+    else
+    {
+        #ifdef SystemLogMessage
+        DEBUG_ERROR("Serial command %s response fail.\n", cmd);
+        #endif
+    }
+
+    return len;
 }
 
 unsigned char Query_FW_Ver(unsigned char fd, unsigned char targetAddr, Ver *Ret_Buf)
 {
-	unsigned char result = FAIL;
-	unsigned char tx[7] = {0xaa, 0x00, targetAddr, Cmd.query_FW_Ver, 0x00, 0x00, 0x00};
-	unsigned char rx[512];
-	unsigned char chksum = 0x00;
-	unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
-
-	if(len > 6)
-	{
-		if (len < 6+(rx[4] | rx[5]<<8))
-			return result;
-
-		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]))
-		{
-			memcpy(Ret_Buf->Version_FW, (char *)rx+6, (rx[4] | rx[5]<<8));
-			*(Ret_Buf->Version_FW + 8) = 0x00;
-			result = PASS;
-		}
-	}
-
-	return result;
+    unsigned char result = FAIL;
+    unsigned char tx[7] = {0xaa, 0x00, targetAddr, Cmd.query_FW_Ver, 0x00, 0x00, 0x00};
+    unsigned char rx[512];
+    unsigned char chksum = 0x00;
+    unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
+
+    if(len > 6)
+    {
+        if (len < 6+(rx[4] | rx[5]<<8))
+            return result;
+
+        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]))
+        {
+            memcpy(Ret_Buf->Version_FW, (char *)rx+6, (rx[4] | rx[5]<<8));
+            *(Ret_Buf->Version_FW + 8) = 0x00;
+            result = PASS;
+        }
+    }
+
+    return result;
 }
 
 unsigned char Query_HW_Ver(unsigned char fd, unsigned char targetAddr, Ver *Ret_Buf)
 {
-	unsigned char result = FAIL;
-	unsigned char tx[7] = {0xaa, 0x00, targetAddr, Cmd.query_HW_Ver, 0x00, 0x00, 0x00};
-	unsigned char rx[512];
-	unsigned char chksum = 0x00;
-	unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
-
-	if(len > 6)
-	{
-		if (len < 6+(rx[4] | rx[5]<<8))
-			return result;
-
-		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]))
-		{
-			memcpy(Ret_Buf->Version_HW, (char *)rx+6, (rx[4] | rx[5]<<8));
-			*(Ret_Buf->Version_HW + 8) = 0x00;
-			result = PASS;
-		}
-	}
-
-	return result;
+    unsigned char result = FAIL;
+    unsigned char tx[7] = {0xaa, 0x00, targetAddr, Cmd.query_HW_Ver, 0x00, 0x00, 0x00};
+    unsigned char rx[512];
+    unsigned char chksum = 0x00;
+    unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
+
+    if(len > 6)
+    {
+        if (len < 6+(rx[4] | rx[5]<<8))
+            return result;
+
+        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]))
+        {
+            memcpy(Ret_Buf->Version_HW, (char *)rx+6, (rx[4] | rx[5]<<8));
+            *(Ret_Buf->Version_HW + 8) = 0x00;
+            result = PASS;
+        }
+    }
+
+    return result;
 }
 
 unsigned char Query_Present_InputVoltage(unsigned char fd, unsigned char targetAddr, PresentInputVoltage *Ret_Buf)
 {
-	unsigned char result = FAIL;
-	unsigned char tx[7] = {0xaa, 0x00, targetAddr, Cmd.query_Present_InputVoltage, 0x00, 0x00, 0x00};
-	unsigned char rx[512];
-	unsigned char chksum = 0x00;
-	unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
-
-	if(len > 6)
-	{
-		if (len < 6+(rx[4] | rx[5]<<8))
-			return result;
-
-		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]))
-		{
-			Ret_Buf->inputType = rx[6];
-			Ret_Buf->L1N_L12 =(rx[7] | (rx[8]<<8))/10.0;
-			Ret_Buf->L2N_L23 =(rx[9] | (rx[10]<<8))/10.0;
-			Ret_Buf->L3N_L31 =(rx[11] | (rx[12]<<8))/10.0;
-
-			result = PASS;
-		}
-	}
-
-	return result;
+    unsigned char result = FAIL;
+    unsigned char tx[7] = {0xaa, 0x00, targetAddr, Cmd.query_Present_InputVoltage, 0x00, 0x00, 0x00};
+    unsigned char rx[512];
+    unsigned char chksum = 0x00;
+    unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
+
+    if(len > 6)
+    {
+        if (len < 6+(rx[4] | rx[5]<<8))
+            return result;
+
+        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]))
+        {
+            Ret_Buf->inputType = rx[6];
+            Ret_Buf->L1N_L12 =(rx[7] | (rx[8]<<8))/10.0;
+            Ret_Buf->L2N_L23 =(rx[9] | (rx[10]<<8))/10.0;
+            Ret_Buf->L3N_L31 =(rx[11] | (rx[12]<<8))/10.0;
+
+            result = PASS;
+        }
+    }
+
+    return result;
 }
 
 unsigned char Query_Present_OutputVoltage(unsigned char fd, unsigned char targetAddr, PresentOutputVoltage *Ret_Buf)
 {
-	unsigned char result = FAIL;
-	unsigned char tx[7] = {0xaa, 0x00, targetAddr, Cmd.query_Present_OutputVoltage, 0x00, 0x00, 0x00};
-	unsigned char rx[512];
-	unsigned char chksum = 0x00;
-	unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
-
-	if(len > 6)
-	{
-		if (len < 6+(rx[4] | rx[5]<<8))
-			return result;
-
-		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]))
-		{
-
-			Ret_Buf->behindFuse_Voltage_C1 =(rx[6] | (rx[7]<<8));
-			Ret_Buf->behindRelay_Voltage_C1 =(rx[8] | (rx[9]<<8));
-			if((rx[4] | rx[5]<<8) > 4)
-			{
-				Ret_Buf->behindFuse_Voltage_C2 =(rx[10] | (rx[11]<<8));
-				Ret_Buf->behindRelay_Voltage_C2 =(rx[12] | (rx[13]<<8));
-			}
-			result = PASS;
-		}
-	}
-
-	return result;
+    unsigned char result = FAIL;
+    unsigned char tx[7] = {0xaa, 0x00, targetAddr, Cmd.query_Present_OutputVoltage, 0x00, 0x00, 0x00};
+    unsigned char rx[512];
+    unsigned char chksum = 0x00;
+    unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
+
+    if(len > 6)
+    {
+        if (len < 6+(rx[4] | rx[5]<<8))
+            return result;
+
+        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]))
+        {
+
+            Ret_Buf->behindFuse_Voltage_C1 =(rx[6] | (rx[7]<<8));
+            Ret_Buf->behindRelay_Voltage_C1 =(rx[8] | (rx[9]<<8));
+            if((rx[4] | rx[5]<<8) > 4)
+            {
+                Ret_Buf->behindFuse_Voltage_C2 =(rx[10] | (rx[11]<<8));
+                Ret_Buf->behindRelay_Voltage_C2 =(rx[12] | (rx[13]<<8));
+            }
+            result = PASS;
+        }
+    }
+
+    return result;
 }
 
 unsigned char Query_Fan_Speed(unsigned char fd, unsigned char targetAddr, FanSpeed *Ret_Buf)
 {
-	unsigned char result = FAIL;
-	unsigned char tx[7] = {0xaa, 0x00, targetAddr, Cmd.query_Fan_Speed, 0x00, 0x00, 0x00};
-	unsigned char rx[512];
-	unsigned char chksum = 0x00;
-	unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
-
-//		for (int i = 0; i < 7; i++)
-//			printf("tx = %x \n", tx[i]);
-//		for (int i = 0; i < len; i++)
-//			printf("rx = %x \n", rx[i]);
-
-	if(len > 6)
-	{
-		if (len < 6+(rx[4] | rx[5]<<8))
-			return result;
-
-		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]))
-		{
-			for(int idx=0;idx < 4;idx++)
-				Ret_Buf->speed[idx] = (rx[6+(2*idx)] | (rx[6+(2*idx)+1]<<8));
-
-			result = PASS;
-		}
-	}
-
-	return result;
+    unsigned char result = FAIL;
+    unsigned char tx[7] = {0xaa, 0x00, targetAddr, Cmd.query_Fan_Speed, 0x00, 0x00, 0x00};
+    unsigned char rx[512];
+    unsigned char chksum = 0x00;
+    unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
+
+    if(len > 6)
+    {
+        if (len < 6+(rx[4] | rx[5]<<8))
+            return result;
+
+        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]))
+        {
+            for(int idx=0;idx < 4;idx++)
+                Ret_Buf->speed[idx] = (rx[6+(2*idx)] | (rx[6+(2*idx)+1]<<8));
+
+            result = PASS;
+        }
+    }
+
+    return result;
 }
 
 unsigned char Query_Temperature(unsigned char fd, unsigned char targetAddr, Temperature *Ret_Buf)
 {
-	unsigned char result = FAIL;
-	unsigned char tx[7] = {0xaa, 0x00, targetAddr, Cmd.query_Temperature, 0x00, 0x00, 0x00};
-	unsigned char rx[512];
-	unsigned char chksum = 0x00;
-	unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
-
-	if(len > 6)
-	{
-		if (len < 6+(rx[4] | rx[5]<<8))
-			return result;
-
-		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]))
-		{
-			for(int idx=0;idx < 4;idx++)
-				Ret_Buf->temperature[idx] = rx[6+idx] - 60;
-
-			result = PASS;
-		}
-	}
-
-
-	return result;
+    unsigned char result = FAIL;
+    unsigned char tx[7] = {0xaa, 0x00, targetAddr, Cmd.query_Temperature, 0x00, 0x00, 0x00};
+    unsigned char rx[512];
+    unsigned char chksum = 0x00;
+    unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
+
+    if(len > 6)
+    {
+        if (len < 6+(rx[4] | rx[5]<<8))
+            return result;
+
+        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]))
+        {
+            for(int idx=0;idx < 4;idx++)
+                Ret_Buf->temperature[idx] = rx[6+idx] - 60;
+
+            result = PASS;
+        }
+    }
+
+
+    return result;
 }
 
 unsigned char Query_Aux_PowerVoltage(unsigned char fd, unsigned char targetAddr, AuxPower *Ret_Buf)
 {
-	unsigned char result = FAIL;
-	unsigned char tx[7] = {0xaa, 0x00, targetAddr, Cmd.query_Aux_PowerVoltage, 0x00, 0x00, 0x00};
-	unsigned char rx[512];
-	unsigned char chksum = 0x00;
-	unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
-
-	if(len > 6)
-	{
-		if (len < 6+(rx[4] | rx[5]<<8))
-			return result;
-
-		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]))
-		{
-			for(int idx=0;idx<(rx[4] | rx[5]<<8);idx++)
-				Ret_Buf->voltage[idx] = rx[6+idx];
-
-			result = PASS;
-		}
-	}
-
-	return result;
+    unsigned char result = FAIL;
+    unsigned char tx[7] = {0xaa, 0x00, targetAddr, Cmd.query_Aux_PowerVoltage, 0x00, 0x00, 0x00};
+    unsigned char rx[512];
+    unsigned char chksum = 0x00;
+    unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
+
+    if(len > 6)
+    {
+        if (len < 6+(rx[4] | rx[5]<<8))
+            return result;
+
+        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]))
+        {
+            for(int idx=0;idx<(rx[4] | rx[5]<<8);idx++)
+                Ret_Buf->voltage[idx] = rx[6+idx];
+
+            result = PASS;
+        }
+    }
+
+    return result;
 }
 
 unsigned char Query_Relay_Output(unsigned char fd, unsigned char targetAddr, Relay *Ret_Buf)
 {
-	unsigned char result = FAIL;
-	unsigned char tx[7] = {0xaa, 0x00, targetAddr, Cmd.query_Relay_Output, 0x00, 0x00, 0x00};
-	unsigned char rx[512];
-	unsigned char chksum = 0x00;
-	unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
-
-//	for (int i = 0; i < 7; i++)
-//		printf("tx = %x \n", tx[i]);
-//	for (int i = 0; i < len; i++)
-//		printf("rx = %x \n", rx[i]);
-
-	if(len > 6)
-	{
-		if (len < 6+(rx[4] | rx[5]<<8))
-			return result;
-
-		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]))
-		{
-			Ret_Buf->relay_event.bits.AC_Contactor = (rx[6] >> 0) & 0x01;
-			Ret_Buf->relay_event.bits.CCS_Precharge = (rx[6] >> 1) & 0x01;
-
-			Ret_Buf->relay_event.bits.Gun1_N = (rx[7] >> 0) & 0x01;
-			Ret_Buf->relay_event.bits.Gun1_P = (rx[7] >> 1) & 0x01;
-			Ret_Buf->relay_event.bits.Gun1_Parallel_N = (rx[7] >> 2) & 0x01;
-			Ret_Buf->relay_event.bits.Gun1_Parallel_P = (rx[7] >> 3) & 0x01;
-
-			Ret_Buf->relay_event.bits.Gun2_N = (rx[8] >> 0) & 0x01;
-			Ret_Buf->relay_event.bits.Gun2_P = (rx[8] >> 1) & 0x01;
-			result = PASS;
-		}
-	}
-
-	return result;
+    unsigned char result = FAIL;
+    unsigned char tx[7] = {0xaa, 0x00, targetAddr, Cmd.query_Relay_Output, 0x00, 0x00, 0x00};
+    unsigned char rx[512];
+    unsigned char chksum = 0x00;
+    unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
+
+//  for (int i = 0; i < 7; i++)
+//      printf("tx = %x \n", tx[i]);
+//  for (int i = 0; i < len; i++)
+//      printf("rx = %x \n", rx[i]);
+
+    if(len > 6)
+    {
+        if (len < 6+(rx[4] | rx[5]<<8))
+            return result;
+
+        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]))
+        {
+            Ret_Buf->relay_event.bits.AC_Contactor = (rx[6] >> 0) & 0x01;
+            Ret_Buf->relay_event.bits.CCS_Precharge = (rx[6] >> 1) & 0x01;
+
+            Ret_Buf->relay_event.bits.Gun1_N = (rx[7] >> 0) & 0x01;
+            Ret_Buf->relay_event.bits.Gun1_P = (rx[7] >> 1) & 0x01;
+            Ret_Buf->relay_event.bits.Gun1_Parallel_N = (rx[7] >> 2) & 0x01;
+            Ret_Buf->relay_event.bits.Gun1_Parallel_P = (rx[7] >> 3) & 0x01;
+
+            Ret_Buf->relay_event.bits.Gun2_N = (rx[8] >> 0) & 0x01;
+            Ret_Buf->relay_event.bits.Gun2_P = (rx[8] >> 1) & 0x01;
+            result = PASS;
+        }
+    }
+
+    return result;
 }
 
 unsigned char Query_Gfd_Adc(unsigned char fd, unsigned char targetAddr, Gfd *Ret_Buf)
 {
-	unsigned char result = FAIL;
-	unsigned char tx[7] = {0xaa, 0x00, targetAddr, Cmd.query_Gfd_Adc, 0x00, 0x00, 0x00};
-	unsigned char rx[512];
-	unsigned char chksum = 0x00;
-	unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
-
-//	for(int i = 0; i < 7; i++)
-//		printf ("tx = %d \n", tx[i]);
-	if(len > 6)
-	{
-		if (len < 6+(rx[4] | rx[5]<<8))
-		{
-			//printf("Query_Gfd_Adc fail \n");
-			return result;
-		}
-
-//		for(int i = 0; i < len; i++)
-//			printf ("rx = %d \n", rx[i]);
-
-		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]))
-		{
-			Ret_Buf->Resister_conn1 = (rx[6] | (rx[7] << 8));
-			Ret_Buf->voltage_conn1 = (rx[8] | (rx[9] << 8));
-			Ret_Buf->result_conn1 = rx[10];
-			Ret_Buf->rb_step_1 = rx[11];
-
-			Ret_Buf->Resister_conn2 = (rx[12] | (rx[13] << 8));
-			Ret_Buf->voltage_conn2 = (rx[14] | (rx[15] << 8));
-			Ret_Buf->result_conn2 = rx[16];
-			Ret_Buf->rb_step_2 = rx[17];
-
-			result = PASS;
-		}
-	}
-
-	return result;
+    unsigned char result = FAIL;
+    unsigned char tx[7] = {0xaa, 0x00, targetAddr, Cmd.query_Gfd_Adc, 0x00, 0x00, 0x00};
+    unsigned char rx[512];
+    unsigned char chksum = 0x00;
+    unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
+
+//  for(int i = 0; i < 7; i++)
+//      printf ("tx = %d \n", tx[i]);
+    if(len > 6)
+    {
+        if (len < 6+(rx[4] | rx[5]<<8))
+        {
+            //printf("Query_Gfd_Adc fail \n");
+            return result;
+        }
+
+//      for(int i = 0; i < len; i++)
+//          printf ("rx = %d \n", rx[i]);
+
+        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]))
+        {
+            Ret_Buf->Resister_conn1 = (rx[6] | (rx[7] << 8));
+            Ret_Buf->voltage_conn1 = (rx[8] | (rx[9] << 8));
+            Ret_Buf->result_conn1 = rx[10];
+            Ret_Buf->rb_step_1 = rx[11];
+
+            Ret_Buf->Resister_conn2 = (rx[12] | (rx[13] << 8));
+            Ret_Buf->voltage_conn2 = (rx[14] | (rx[15] << 8));
+            Ret_Buf->result_conn2 = rx[16];
+            Ret_Buf->rb_step_2 = rx[17];
+
+            result = PASS;
+        }
+    }
+
+    return result;
 }
 
 unsigned char Query_Gpio_Input(unsigned char fd, unsigned char targetAddr, Gpio_in *Ret_Buf)
 {
-	unsigned char result = FAIL;
-	unsigned char tx[7] = {0xaa, 0x00, targetAddr, Cmd.query_Gpio_In, 0x00, 0x00, 0x00};
-	unsigned char rx[512];
-	unsigned char chksum = 0x00;
-	unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
-
-	if(len > 6)
-	{
-		if (len < 6+(rx[4] | rx[5]<<8))
-			return result;
-
-		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]))
-		{
-			Ret_Buf->AC_Connector 		= (rx[6] >> 0) & 0x01;
-			Ret_Buf->AC_MainBreaker 	= (rx[6] >> 1) & 0x01;
-			Ret_Buf->SPD 				= (rx[6] >> 2) & 0x01;
-			Ret_Buf->Door_Open 			= (rx[6] >> 3) & 0x01;
-			Ret_Buf->GFD[0] 			= (rx[6] >> 4) & 0x01;
-			Ret_Buf->GFD[1] 			= (rx[6] >> 5) & 0x01;
-			Ret_Buf->AC_Drop 			= (rx[6] >> 6) & 0x01;
-
-			Ret_Buf->Emergency_IO		= (rx[7] >> 0) & 0x01;
-
-			Ret_Buf->Button_Emergency_Press	= (rx[8] >> 0) & 0x01;
-			Ret_Buf->Button_On_Press 	= (rx[8] >> 1) & 0x01;
-			Ret_Buf->Button_Off_Press	= (rx[8] >> 2) & 0x01;
-			Ret_Buf->Key_1_Press 		= (rx[8] >> 3) & 0x01;
-			Ret_Buf->Key_2_Press 		= (rx[8] >> 4) & 0x01;
-			Ret_Buf->Key_3_Press 		= (rx[8] >> 5) & 0x01;
-			Ret_Buf->Key_4_Press 		= (rx[8] >> 6) & 0x01;
-
-			result = PASS;
-		}
-	}
-
-	return result;
+    unsigned char result = FAIL;
+    unsigned char tx[7] = {0xaa, 0x00, targetAddr, Cmd.query_Gpio_In, 0x00, 0x00, 0x00};
+    unsigned char rx[512];
+    unsigned char chksum = 0x00;
+    unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
+
+    if(len > 6)
+    {
+        if (len < 6+(rx[4] | rx[5]<<8))
+            return result;
+
+        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]))
+        {
+            Ret_Buf->AC_Connector       = (rx[6] >> 0) & 0x01;
+            Ret_Buf->AC_MainBreaker     = (rx[6] >> 1) & 0x01;
+            Ret_Buf->SPD                = (rx[6] >> 2) & 0x01;
+            Ret_Buf->Door_Open          = (rx[6] >> 3) & 0x01;
+            Ret_Buf->GFD[0]             = (rx[6] >> 4) & 0x01;
+            Ret_Buf->GFD[1]             = (rx[6] >> 5) & 0x01;
+            Ret_Buf->AC_Drop            = (rx[6] >> 6) & 0x01;
+
+            Ret_Buf->Emergency_IO       = (rx[7] >> 0) & 0x01;
+
+            Ret_Buf->Button_Emergency_Press = (rx[8] >> 0) & 0x01;
+            Ret_Buf->Button_On_Press    = (rx[8] >> 1) & 0x01;
+            Ret_Buf->Button_Off_Press   = (rx[8] >> 2) & 0x01;
+            Ret_Buf->Key_1_Press        = (rx[8] >> 3) & 0x01;
+            Ret_Buf->Key_2_Press        = (rx[8] >> 4) & 0x01;
+            Ret_Buf->Key_3_Press        = (rx[8] >> 5) & 0x01;
+            Ret_Buf->Key_4_Press        = (rx[8] >> 6) & 0x01;
+
+            result = PASS;
+        }
+    }
+
+    return result;
 }
 
-unsigned char Config_Fan_Speed(unsigned char fd, unsigned char targetAddr, FanSpeed *Set_Buf)
+unsigned char Query_Model_Name(unsigned char fd, unsigned char targetAddr, unsigned char *modelname)
 {
-	unsigned char result = FAIL;
-	unsigned char tx[15] = {0xaa, 0x00, targetAddr, Cmd.config_Fan_Speed, 0x08, 0x00, Set_Buf->speed[0]&0xff, (Set_Buf->speed[0]>>8)&0xff, Set_Buf->speed[1]&0xff, (Set_Buf->speed[1]>>8)&0xff, Set_Buf->speed[2]&0xff, (Set_Buf->speed[2]>>8)&0xff, Set_Buf->speed[3]&0xff, (Set_Buf->speed[3]>>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;
-
-//		for(int i = 0; i < 15; i++)
-//			printf ("tx = %x \n", tx[i]);
-
-	unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
-//	for(int i = 0; i < len; i++)
-//				printf ("rx = %x \n", rx[i]);
-	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]))
-		{
-			result = PASS;
-		}
-	}
+    unsigned char result = FAIL;
+    unsigned char tx[7] = {0xaa, 0x00, targetAddr, Cmd.query_Model_Name, 0x00, 0x00, 0x00};
+    unsigned char rx[512];
+    unsigned char chksum = 0x00;
+    unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
+
+    if(len > 6)
+    {
+        if (len < 6+(rx[4] | rx[5]<<8))
+            return result;
+
+        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]))
+        {
+            strncpy((char *)modelname, (char *)(rx + 6), (rx[4] | rx[5]<<8));
+            result = PASS;
+        }
+    }
+
+    return result;
+}
 
-	return result;
+unsigned char Config_Fan_Speed(unsigned char fd, unsigned char targetAddr, FanSpeed *Set_Buf)
+{
+    unsigned char result = FAIL;
+    unsigned char tx[15] = {0xaa, 0x00, targetAddr, Cmd.config_Fan_Speed, 0x08, 0x00, Set_Buf->speed[0]&0xff, (Set_Buf->speed[0]>>8)&0xff, Set_Buf->speed[1]&0xff, (Set_Buf->speed[1]>>8)&0xff, Set_Buf->speed[2]&0xff, (Set_Buf->speed[2]>>8)&0xff, Set_Buf->speed[3]&0xff, (Set_Buf->speed[3]>>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]))
+        {
+            result = PASS;
+        }
+    }
+
+    return result;
 }
 
 unsigned char Config_Relay_Output(unsigned char fd, unsigned char targetAddr, Relay *Set_Buf)
 {
-	unsigned char result = FAIL;
-	unsigned char tx[10] = {0xaa, 0x00, targetAddr, Cmd.config_Relay_Output, 0x03, 0x00, Set_Buf->relay_event.relay_status[0], Set_Buf->relay_event.relay_status[1], Set_Buf->relay_event.relay_status[2]};
-	unsigned char rx[512];
-	unsigned char chksum = 0x00;
-
-	for(int idx = 0;idx<(tx[4] | tx[5]<<8);idx++)
-		chksum ^= tx[6 + idx];
-	tx[9] = chksum;
-
-//	for (int i = 0; i < 10; i++)
-//		printf("set relay cmd : tx = %x \n", tx[i]);
-
-	unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
-
-	if(len > 6)
-	{
-		if (len < 6+(rx[4] | rx[5]<<8))
-			return result;
-
-//		for (int i = 0; i < len; i++)
-//			printf("set relay cmd : rx = %x \n", rx[i]);
-
-		chksum = 0x00;
-		for(int idx = 0;idx<(rx[4] | rx[5]<<8);idx++)
-		{
-			chksum ^= rx[6+idx];
-		}
-
-		if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
-		   (rx[2] == tx[1]) &&
-		   (rx[1] == tx[2]) &&
-		   (rx[3] == tx[3]) &&
-		   (rx[6] == 0x01))
-		{
-			result = PASS;
-		}
-	}
-
-	return result;
+    unsigned char result = FAIL;
+    unsigned char tx[10] = {0xaa, 0x00, targetAddr, Cmd.config_Relay_Output, 0x03, 0x00, Set_Buf->relay_event.relay_status[0], Set_Buf->relay_event.relay_status[1], Set_Buf->relay_event.relay_status[2]};
+    unsigned char rx[512];
+    unsigned char chksum = 0x00;
+
+    for(int idx = 0;idx<(tx[4] | tx[5]<<8);idx++)
+        chksum ^= tx[6 + idx];
+    tx[9] = chksum;
+
+//  for (int i = 0; i < 10; i++)
+//      printf("set relay cmd : tx = %x \n", tx[i]);
+
+    unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
+
+    if(len > 6)
+    {
+        if (len < 6+(rx[4] | rx[5]<<8))
+            return result;
+
+//      for (int i = 0; i < len; i++)
+//          printf("set relay cmd : rx = %x \n", rx[i]);
+
+        chksum = 0x00;
+        for(int idx = 0;idx<(rx[4] | rx[5]<<8);idx++)
+        {
+            chksum ^= rx[6+idx];
+        }
+
+        if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
+           (rx[2] == tx[1]) &&
+           (rx[1] == tx[2]) &&
+           (rx[3] == tx[3]) &&
+           (rx[6] == 0x01))
+        {
+            result = PASS;
+        }
+    }
+
+    return result;
 }
 
 unsigned char Config_Gpio_Output(unsigned char fd, unsigned char targetAddr, Gpio_out *Set_Buf)
 {
-	unsigned char result = FAIL;
-	unsigned char tx[9] = {0xaa, 0x00, targetAddr, Cmd.config_Gpio_Output, 0x01, 0x00, 0x00, 0x00};
-	unsigned char rx[512];
-	unsigned char chksum = 0x00;
-
-	tx[6] |= (Set_Buf->AC_Connector?0x01:0x00);
-
-	for(int idx = 0;idx<2;idx++)
-		tx[6] |= (Set_Buf->Button_LED[idx]?0x01:0x00)<<(1+idx);
-
-	for(int idx = 0;idx<4;idx++)
-			tx[6] |= (Set_Buf->System_LED[idx]?0x01:0x00)<<(3+idx);
-
-	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] == tx[6]))
-		{
-			result = PASS;
-		}
-	}
-
-	return result;
+    unsigned char result = FAIL;
+    unsigned char tx[9] = {0xaa, 0x00, targetAddr, Cmd.config_Gpio_Output, 0x01, 0x00, 0x00, 0x00};
+    unsigned char rx[512];
+    unsigned char chksum = 0x00;
+
+    tx[6] |= (Set_Buf->AC_Connector?0x01:0x00);
+
+    for(int idx = 0;idx<2;idx++)
+        tx[6] |= (Set_Buf->Button_LED[idx]?0x01:0x00)<<(1+idx);
+
+    for(int idx = 0;idx<4;idx++)
+            tx[6] |= (Set_Buf->System_LED[idx]?0x01:0x00)<<(3+idx);
+
+    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]))
+        {
+            result = PASS;
+        }
+    }
+
+    return result;
 }
 
 unsigned char Config_Gfd_Value(unsigned char fd, unsigned char targetAddr, Gfd_config *Set_Buf)
 {
-	unsigned char result = FAIL;
-	unsigned char tx[9] = {0xaa, 0x00, targetAddr, Cmd.config_Gfd_Value, 0x02, 0x00, 0x00, 0x00, 0x00};
-	unsigned char rx[512];
-	unsigned char chksum = 0x00;
-
-	tx[6] = Set_Buf->index;
-	tx[7] = Set_Buf->state;
-
-	for(int idx = 0; idx<(tx[4] | tx[5]<<8);idx++)
-		chksum ^= tx[6+idx];
-	tx[8] = chksum;
-
-	unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
-
-	if(len > 6)
-	{
-		if (len < 6+(rx[4] | rx[5]<<8))
-			return result;
-
-		chksum = 0x00;
-		for(int idx = 0;idx<(rx[4] | rx[5]<<8);idx++)
-		{
-			chksum ^= rx[6+idx];
-		}
-
-		if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
-		   (rx[2] == tx[1]) &&
-		   (rx[1] == tx[2]) &&
-		   (rx[3] == tx[3]) &&
-		   (rx[6] == tx[6]))
-		{
-			result = PASS;
-		}
-	}
-
-	return result;
+    unsigned char result = FAIL;
+    unsigned char tx[9] = {0xaa, 0x00, targetAddr, Cmd.config_Gfd_Value, 0x02, 0x00, 0x00, 0x00, 0x00};
+    unsigned char rx[512];
+    unsigned char chksum = 0x00;
+
+    tx[6] = Set_Buf->index;
+    tx[7] = Set_Buf->state;
+
+    for(int idx = 0; idx<(tx[4] | tx[5]<<8);idx++)
+        chksum ^= tx[6+idx];
+    tx[8] = chksum;
+
+    unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
+
+    if(len > 6)
+    {
+        if (len < 6+(rx[4] | rx[5]<<8))
+            return result;
+
+        chksum = 0x00;
+        for(int idx = 0;idx<(rx[4] | rx[5]<<8);idx++)
+        {
+            chksum ^= rx[6+idx];
+        }
+
+        if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
+           (rx[2] == tx[1]) &&
+           (rx[1] == tx[2]) &&
+           (rx[3] == tx[3]))
+        {
+            result = PASS;
+        }
+    }
+
+    return result;
 }
 
 unsigned char Config_Model_Name(unsigned char fd, unsigned char targetAddr, unsigned char *modelname)
 {
-	unsigned char result = FAIL;
-	unsigned char tx[21] = {0xaa, 0x00, targetAddr, Cmd.config_Model_Name, 0x0E, 0x00,
-			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
-	unsigned char rx[512];
-	unsigned char chksum = 0x00;
-
-	memcpy(tx + 6, modelname, 14);
-
-	for(int idx = 0; idx<(tx[4] | tx[5]<<8);idx++)
-		chksum ^= tx[6+idx];
-	tx[20] = chksum;
-
-//	for(int i = 0; i < 21; i++)
-//				printf ("tx = %x \n", tx[i]);
-	unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
-//	for(int i = 0; i < len; i++)
-//					printf ("rx = %x \n", rx[i]);
-	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] == tx[6]))
-		{
-			result = PASS;
-		}
-	}
-
-	return result;
+    unsigned char result = FAIL;
+    unsigned char tx[21] = {0xaa, 0x00, targetAddr, Cmd.config_Model_Name, 0x0E, 0x00,
+            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
+    unsigned char rx[512];
+    unsigned char chksum = 0x00;
+
+    memcpy(tx + 6, modelname, 14);
+
+    for(int idx = 0; idx<(tx[4] | tx[5]<<8);idx++)
+        chksum ^= tx[6+idx];
+    tx[20] = chksum;
+
+//  for(int i = 0; i < 21; i++)
+//              printf ("tx = %x \n", tx[i]);
+    unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
+//  for(int i = 0; i < len; i++)
+//                  printf ("rx = %x \n", rx[i]);
+    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]))
+        {
+            result = PASS;
+        }
+    }
+
+    return result;
 }
 
 unsigned char Config_Rtc_Data(unsigned char fd, unsigned char targetAddr, Rtc *Set_Buf)
 {
-	unsigned char result = FAIL;
-	unsigned char tx[21] = { 0xaa, 0x00, targetAddr, Cmd.config_Rtc_Data, 0x0E, 0x00, Set_Buf->RtcData[0], Set_Buf->RtcData[1],
-			Set_Buf->RtcData[2], Set_Buf->RtcData[3], Set_Buf->RtcData[4], Set_Buf->RtcData[5], Set_Buf->RtcData[6], Set_Buf->RtcData[7],
-			Set_Buf->RtcData[8], Set_Buf->RtcData[9], Set_Buf->RtcData[10], Set_Buf->RtcData[11], Set_Buf->RtcData[12], Set_Buf->RtcData[13]};
-	unsigned char rx[512];
-	unsigned char chksum = 0x00;
-
-	for (int idx = 0; idx < (tx[4] | tx[5] << 8); idx++)
-		chksum ^= tx[6 + idx];
-	tx[20] = chksum;
-
-	if (tranceive(fd, tx, sizeof(tx), rx) > 0)
-	{
-		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] == tx[6]))
-		{
-			result = PASS;
-		}
-	}
-
-	return result;
+    unsigned char result = FAIL;
+    unsigned char tx[21] = { 0xaa, 0x00, targetAddr, Cmd.config_Rtc_Data, 0x0E, 0x00, Set_Buf->RtcData[0], Set_Buf->RtcData[1],
+            Set_Buf->RtcData[2], Set_Buf->RtcData[3], Set_Buf->RtcData[4], Set_Buf->RtcData[5], Set_Buf->RtcData[6], Set_Buf->RtcData[7],
+            Set_Buf->RtcData[8], Set_Buf->RtcData[9], Set_Buf->RtcData[10], Set_Buf->RtcData[11], Set_Buf->RtcData[12], Set_Buf->RtcData[13]};
+    unsigned char rx[512];
+    unsigned char chksum = 0x00;
+
+    for (int idx = 0; idx < (tx[4] | tx[5] << 8); idx++)
+        chksum ^= tx[6 + idx];
+    tx[20] = chksum;
+
+    if (tranceive(fd, tx, sizeof(tx), rx) > 0)
+    {
+        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]))
+        {
+            result = PASS;
+        }
+    }
+
+    return result;
 }
 
 unsigned char Update_Start(unsigned char fd, unsigned char targetAddr, unsigned int crc32)
 {
-	unsigned char result = FAIL;
-	unsigned char tx[11] = {0xaa, 0x00, targetAddr, Cmd.update_Start, 0x04, 0x00, (crc32>>0)&0xff, (crc32>>8)&0xff, (crc32>>16)&0xff, (crc32>>24)&0xff, 0x00};
-	unsigned char rx[512];
-	unsigned char chksum = 0x00;
+    unsigned char result = FAIL;
+    unsigned char tx[11] = {0xaa, 0x00, targetAddr, Cmd.update_Start, 0x04, 0x00, (crc32>>0)&0xff, (crc32>>8)&0xff, (crc32>>16)&0xff, (crc32>>24)&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[10] = 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] == 0x00))
+        {
+            result = PASS;
+        }
+    }
+
+    return result;
+}
 
-	for(int idx = 0;idx<(tx[4] | tx[5]<<8);idx++)
-		chksum ^= tx[6+idx];
-	tx[10] = chksum;
+unsigned char Update_Abord(unsigned char fd, unsigned char targetAddr)
+{
+    unsigned char result = FAIL;
+    unsigned char tx[7] = {0xaa, 0x00, targetAddr, Cmd.update_Start, 0x04, 0x00, 0x00};
+    unsigned char rx[512];
+    unsigned char chksum = 0x00;
+    unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
+
+    if(len > 6)
+    {
+        if (len < 6+(rx[4] | rx[5]<<8))
+            return result;
+
+        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] == 0x00))
+        {
+            result = PASS;
+        }
+    }
+
+    return result;
+}
 
-	unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
-	if(len > 6)
-	{
-		if (len < 6+(rx[4] | rx[5]<<8))
-			return result;
+unsigned char Update_Transfer(unsigned char fd, unsigned char targetAddr, unsigned int startAddr, unsigned char *data, unsigned short int length)
+{
+    unsigned char result = FAIL;
+    unsigned char tx[11 + length];
+    unsigned char rx[512];
+    unsigned char chksum = 0x00;
+
+    tx[0] = 0xaa;
+    tx[1] = 0x00;
+    tx[2] = targetAddr;
+    tx[3] = Cmd.update_Transfer;
+    tx[4] = (4 + length) & 0xff;
+    tx[5] = ((4 + length)>>8) & 0xff;
+    tx[6] = (startAddr>>0) & 0xff;
+    tx[7] = (startAddr>>8) & 0xff;
+    tx[8] = (startAddr>>16) & 0xff;
+    tx[9] = (startAddr>>24) & 0xff;
+    memcpy(tx+10, data, length);
+
+    for(int idx = 0;idx<(tx[4] | tx[5]<<8);idx++)
+        chksum ^= tx[6+idx];
+    tx[sizeof(tx)-1] = chksum;
+
+    unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
+
+    if(len > 6)
+    {
+        if (len < 6+(rx[4] | rx[5]<<8))
+            return result;
+
+        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] == 0x00))
+        {
+            result = PASS;
+        }
+    }
+
+    return result;
+}
 
-		chksum = 0x00;
-		for(int idx = 0;idx<(rx[4] | rx[5]<<8);idx++)
-		{
-			chksum ^= rx[6+idx];
-		}
+unsigned char Update_Finish(unsigned char fd, unsigned char targetAddr)
+{
+    unsigned char result = FAIL;
+    unsigned char tx[7] = {0xaa, 0x00, targetAddr, Cmd.update_Finish, 0x04, 0x00, 0x00};
+    unsigned char rx[512];
+    unsigned char chksum = 0x00;
+    unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
+
+    if(len > 6)
+    {
+        if (len < 6+(rx[4] | rx[5]<<8))
+            return result;
+
+        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] == 0x00))
+        {
+            result = PASS;
+        }
+    }
+
+    return result;
+}
 
-		if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
-		   (rx[2] == tx[1]) &&
-		   (rx[1] == tx[2]) &&
-		   (rx[3] == tx[3]) &&
-		   (rx[6] == 0x00))
-		{
-			result = PASS;
-		}
-	}
+unsigned char Query_AC_Status(unsigned char fd, unsigned char targetAddr, Ac_Status *Ret_Buf)
+{
+    unsigned char result = FAIL;
+    unsigned char tx[7] = {0xaa, 0x00, targetAddr, Cmd.query_ac_status, 0x00, 0x00, 0x00};
+    unsigned char rx[512];
+    unsigned char chksum = 0x00;
+    unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
+
+    if(len > 6)
+    {
+        if (len < 6+(rx[4] | rx[5]<<8))
+            return result;
+
+        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]))
+        {
+            Ret_Buf->CpStatus = rx[6];
+            Ret_Buf->CurLimit = (rx[7] | (rx[8] << 8));
+            Ret_Buf->PilotVol_P = (rx[9] | (rx[10] << 8));
+            Ret_Buf->PilotVol_N = (rx[11] | (rx[12] << 8));
+            Ret_Buf->LockStatus = rx[13];
+            Ret_Buf->RelayStatus = rx[14];
+            Ret_Buf->ShutterStatus = rx[15];
+            Ret_Buf->MeterStatus = rx[16];
+            Ret_Buf->PpStatus = rx[17];
+            Ret_Buf->MaxCurrent = rx[18];
+            Ret_Buf->RotateSwitchStatus = rx[19];
+//
+//          Ret_Buf->AC_Connector       = (rx[6] >> 0) & 0x01;
+//          Ret_Buf->AC_MainBreaker     = (rx[6] >> 1) & 0x01;
+//          Ret_Buf->SPD                = (rx[6] >> 2) & 0x01;
+//          Ret_Buf->Door_Open          = (rx[6] >> 3) & 0x01;
+//          Ret_Buf->GFD[0]             = (rx[6] >> 4) & 0x01;
+//          Ret_Buf->GFD[1]             = (rx[6] >> 5) & 0x01;
+//          Ret_Buf->AC_Drop            = (rx[6] >> 6) & 0x01;
+//
+//          Ret_Buf->Emergency_IO       = (rx[7] >> 0) & 0x01;
+//
+//          Ret_Buf->Button_Emergency_Press = (rx[8] >> 0) & 0x01;
+//          Ret_Buf->Button_On_Press    = (rx[8] >> 1) & 0x01;
+//          Ret_Buf->Button_Off_Press   = (rx[8] >> 2) & 0x01;
+//          Ret_Buf->Key_1_Press        = (rx[8] >> 3) & 0x01;
+//          Ret_Buf->Key_2_Press        = (rx[8] >> 4) & 0x01;
+//          Ret_Buf->Key_3_Press        = (rx[8] >> 5) & 0x01;
+//          Ret_Buf->Key_4_Press        = (rx[8] >> 6) & 0x01;
+
+            result = PASS;
+        }
+    }
+
+    return result;
+}
 
-	return result;
+unsigned char Query_AC_Alarm_Code(unsigned char fd, unsigned char targetAddr, Ac_Alarm_code *Ret_Buf)
+{
+    unsigned char result = FAIL;
+    unsigned char tx[7] = {0xaa, 0x00, targetAddr, Cmd.query_ac_alarm_code, 0x00, 0x00};
+    unsigned char rx[512];
+    unsigned char chksum = 0x00;
+    unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
+
+    if(len > 6)
+    {
+        if (len < 6+(rx[4] | rx[5]<<8))
+            return result;
+
+        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]))
+        {
+            Ret_Buf->AcAlarmCode = rx[6] + (rx[7] << 8) + (rx[8] << 16) + (rx[9] << 24);
+            result = PASS;
+        }
+    }
+
+    return result;
 }
 
-unsigned char Update_Abord(unsigned char fd, unsigned char targetAddr)
+unsigned char Query_Charging_Energy(unsigned char fd, unsigned char targetAddr, Ac_Charging_energy *Ret_Buf)
 {
-	unsigned char result = FAIL;
-	unsigned char tx[7] = {0xaa, 0x00, targetAddr, Cmd.update_Start, 0x04, 0x00, 0x00};
-	unsigned char rx[512];
-	unsigned char chksum = 0x00;
-	unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
+    unsigned char result = FAIL;
+    unsigned char tx[7] = {0xaa, 0x00, targetAddr, Cmd.query_ac_output_energy, 0x00, 0x00,0x00};
+    unsigned char rx[512];
+    unsigned char chksum = 0x00;
+    unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
+
+    if(len > 6)
+    {
+        if (len < 6+(rx[4] | rx[5]<<8))
+            return result;
+
+        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]))
+        {
+            Ret_Buf->Energy = rx[6] + (rx[7] << 8) + (rx[8] << 16) + (rx[9] << 24);
+            result = PASS;
+        }
+    }
+
+    return result;
+}
 
-	if(len > 6)
-	{
-		if (len < 6+(rx[4] | rx[5]<<8))
-			return result;
+unsigned char Query_Charging_Current(unsigned char fd, unsigned char targetAddr, Ac_Charging_current *Ret_Buf)
+{
+    unsigned char result = FAIL;
+    unsigned char tx[7] = {0xaa, 0x00, targetAddr, Cmd.query_ac_output_current, 0x00, 0x00, 0x00};
+    unsigned char rx[512];
+    unsigned char chksum = 0x00;
+    unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
+
+    if(len > 6)
+    {
+        if (len < 6+(rx[4] | rx[5]<<8))
+            return result;
+
+        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]))
+        {
+            Ret_Buf->OuputCurrentL1 = rx[6] + (rx[7] << 8);
+            Ret_Buf->OuputCurrentL2 = rx[8] + (rx[9] << 8);
+            Ret_Buf->OuputCurrentL3 = rx[10] + (rx[11] << 8);
+            result = PASS;
+        }
+    }
+
+    return result;
+}
 
-		for(int idx = 0;idx<(rx[4] | rx[5]<<8);idx++)
-		{
-			chksum ^= rx[6+idx];
-		}
+unsigned char Config_LED_Status(unsigned char fd, unsigned char targetAddr, Ac_Led_Status *Ret_Buf)
+{
+    unsigned char result = FAIL;
+    unsigned char tx[12] = {0xaa, 0x00, targetAddr, Cmd.config_ac_led_status, 0x05, 0x00, Ret_Buf->ActionMode, (Ret_Buf->AcAlarmCode >> 0) & 0xFF,
+            (Ret_Buf->AcAlarmCode >> 8) & 0xFF, (Ret_Buf->AcAlarmCode >> 16) & 0xFF, (Ret_Buf->AcAlarmCode >> 24) & 0xFF};
+    unsigned char rx[512];
+    unsigned char chksum = 0x00;
+
+    for (int idx = 0; idx < (tx[4] | tx[5] << 8); idx++)
+        chksum ^= tx[6 + idx];
+    tx[11] = chksum;
+
+    if (tranceive(fd, tx, sizeof(tx), rx) > 0)
+    {
+        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]))
+        {
+            result = PASS;
+        }
+    }
+
+    return result;
+}
+
+unsigned char Config_Legacy_Req(unsigned char fd, unsigned char targetAddr, unsigned char _switch)
+{
+    unsigned char result = FAIL;
+    unsigned char tx[9] = {0xaa, 0x00, targetAddr, Cmd.config_Legacy_Req, 0x02, 0x00, _switch, 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[8] = chksum;
+
+    if (tranceive(fd, tx, sizeof(tx), rx) > 0)
+    {
+        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]))
+        {
+            result = PASS;
+        }
+    }
+
+    return result;
+}
 
-		if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
-		   (rx[2] == tx[1]) &&
-		   (rx[1] == tx[2]) &&
-		   (rx[3] == tx[3]) &&
-		   (rx[6] == 0x00))
-		{
-			result = PASS;
-		}
-	}
+unsigned char Config_Ac_Duty(unsigned char fd, unsigned char targetAddr, unsigned char _value)
+{
+    unsigned char result = FAIL;
+    unsigned char tx[8] = {0xaa, 0x00, targetAddr, Cmd.config_ac_duty, 0x01, 0x00, _value};
+    unsigned char rx[512];
+    unsigned char chksum = 0x00;
+
+    for (int idx = 0; idx < (tx[4] | tx[5] << 8); idx++)
+        chksum ^= tx[6 + idx];
+    tx[7] = chksum;
+
+    if (tranceive(fd, tx, sizeof(tx), rx) > 0)
+    {
+        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]))
+        {
+            result = PASS;
+        }
+    }
+
+    return result;
+}
 
-	return result;
+unsigned char Config_CSU_Mode(unsigned char fd, unsigned char targetAddr)
+{
+    unsigned char result = FAIL;
+    unsigned char tx[9] = {0xaa, 0x00, targetAddr, Cmd.config_csu_mode, 0x02, 0x00, 0x01, 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[7] = chksum;
+
+    if (tranceive(fd, tx, sizeof(tx), rx) > 0)
+    {
+        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]))
+        {
+            result = PASS;
+        }
+    }
+
+    return result;
 }
 
-unsigned char Update_Transfer(unsigned char fd, unsigned char targetAddr, unsigned int startAddr, unsigned char *data, unsigned short int length)
+unsigned char Config_Reset_MCU(unsigned char fd, unsigned char targetAddr)
 {
-	unsigned char result = FAIL;
-	unsigned char tx[11 + length];
-	unsigned char rx[512];
-	unsigned char chksum = 0x00;
-
-	tx[0] = 0xaa;
-	tx[1] = 0x00;
-	tx[2] = targetAddr;
-	tx[3] = Cmd.update_Transfer;
-	tx[4] = (4 + length) & 0xff;
-	tx[5] = ((4 + length)>>8) & 0xff;
-	tx[6] = (startAddr>>0) & 0xff;
-	tx[7] = (startAddr>>8) & 0xff;
-	tx[8] = (startAddr>>16) & 0xff;
-	tx[9] = (startAddr>>24) & 0xff;
-	memcpy(tx+10, data, length);
-
-	for(int idx = 0;idx<(tx[4] | tx[5]<<8);idx++)
-		chksum ^= tx[6+idx];
-	tx[sizeof(tx)-1] = chksum;
-
-	unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
-
-	if(len > 6)
-	{
-		if (len < 6+(rx[4] | rx[5]<<8))
-			return result;
-
-		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] == 0x00))
-		{
-			result = PASS;
-		}
-	}
-
-	return result;
+    unsigned char result = FAIL;
+    unsigned char tx[9] = {0xaa, 0x00, targetAddr, Cmd.config_reset_mcu, 0x02, 0x00, 0x01, 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[7] = chksum;
+
+    if (tranceive(fd, tx, sizeof(tx), rx) > 0)
+    {
+        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]))
+        {
+            result = PASS;
+        }
+    }
+
+    return result;
 }
 
-unsigned char Update_Finish(unsigned char fd, unsigned char targetAddr)
+unsigned char Config_Led_Color(unsigned char fd, unsigned char targetAddr, Led_Color *Ret_Buf)
 {
-	unsigned char result = FAIL;
-	unsigned char tx[7] = {0xaa, 0x00, targetAddr, Cmd.update_Finish, 0x04, 0x00, 0x00};
-	unsigned char rx[512];
-	unsigned char chksum = 0x00;
-	unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
-
-	if(len > 6)
-	{
-		if (len < 6+(rx[4] | rx[5]<<8))
-			return result;
-
-		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] == 0x00))
-		{
-			result = PASS;
-		}
-	}
-
-	return result;
+    unsigned char result = FAIL;
+    unsigned char tx[13] = {0xaa, 0x00, targetAddr, Cmd.config_led_color, 0x06, 0x00,
+            Ret_Buf->Connect_1_Red, Ret_Buf->Connect_1_Green, Ret_Buf->Connect_1_Blue,
+            Ret_Buf->Connect_2_Red, Ret_Buf->Connect_2_Green, Ret_Buf->Connect_2_Blue};
+    unsigned char rx[512];
+    unsigned char chksum = 0x00;
+
+    for (int idx = 0; idx < (tx[4] | tx[5] << 8); idx++)
+        chksum ^= tx[6 + idx];
+    tx[13] = chksum;
+
+    if (tranceive(fd, tx, sizeof(tx), rx) > 0)
+    {
+        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;
 }

+ 185 - 103
EVSE/Projects/DW30/Apps/internalComm.h

@@ -1,7 +1,7 @@
 /*
  * internalComm.h
  *
- *  Created on: 2019¦~5¤ë7¤é
+ *  Created on: 2019年5月7日
  *      Author: foluswen
  */
 
@@ -10,164 +10,235 @@
 
 extern struct Address
 {
-	unsigned char Aux;
-	unsigned char Fan;
-	unsigned char Relay;
-	unsigned char Broadcast;
+    unsigned char Aux;
+    unsigned char Fan;
+    unsigned char Relay;
+    unsigned char AcPlug;
+    unsigned char Led;
+    unsigned char Broadcast;
 }Addr;
 
 extern struct Command
 {
-	unsigned char query_FW_Ver; 				//0x01
-	unsigned char query_HW_Ver; 				//0x02
-	unsigned char query_Present_InputVoltage;	//0x03
-	unsigned char query_Present_OutputVoltage;	//0x04
-	unsigned char query_Fan_Speed;				//0x05
-	unsigned char query_Temperature;			//0x06
-	unsigned char query_Aux_PowerVoltage;		//0x07
-	unsigned char query_Relay_Output;			//0x08
-	unsigned char query_Gfd_Adc;				//0x09
-	unsigned char query_Gpio_In;				//0x0a
-
-	unsigned char config_Fan_Speed;			//0x81
-	unsigned char config_Model_Name;			//0x83
-	unsigned char config_Relay_Output;			//0x85
-	unsigned char config_Gpio_Output;			//0x86
-	unsigned char config_Rtc_Data;				//0x87
-	unsigned char config_Gfd_Value;			//0x8B
-
-	unsigned char update_Start;				//0xe0
-	unsigned char update_Abort;				//0xe1
-	unsigned char update_Transfer;				//0xe2
-	unsigned char update_Finish;				//0xe3
+    unsigned char query_FW_Ver;                 //0x01
+    unsigned char query_HW_Ver;                 //0x02
+    unsigned char query_Present_InputVoltage;   //0x03
+    unsigned char query_Present_OutputVoltage;  //0x04
+    unsigned char query_Fan_Speed;              //0x05
+    unsigned char query_Temperature;            //0x06
+    unsigned char query_Aux_PowerVoltage;       //0x07
+    unsigned char query_Relay_Output;           //0x08
+    unsigned char query_Gfd_Adc;                //0x09
+    unsigned char query_Gpio_In;                //0x0a
+
+    unsigned char query_Model_Name;             //0x24
+    unsigned char query_ac_output_current;      //0x27
+    unsigned char query_ac_status;              //0x28
+    unsigned char query_ac_alarm_code;          //0x29
+
+    unsigned char query_ac_output_energy;       //0x2C
+
+    unsigned char config_Fan_Speed;             //0x81
+    unsigned char config_Model_Name;            //0x83
+    unsigned char config_Relay_Output;          //0x85
+    unsigned char config_Gpio_Output;           //0x86
+    unsigned char config_Rtc_Data;              //0x87
+    unsigned char config_ac_led_status;         //0x88
+
+    unsigned char config_ac_duty;               //0x89
+    unsigned char config_Legacy_Req;            //0x8A
+    unsigned char config_Gfd_Value;             //0x8B
+    unsigned char config_reset_mcu;             //0x8C
+
+    unsigned char config_csu_mode;              //0x90
+
+    unsigned char config_led_color;             //0x93
+
+    unsigned char update_Start;                 //0xe0
+    unsigned char update_Abort;                 //0xe1
+    unsigned char update_Transfer;              //0xe2
+    unsigned char update_Finish;                //0xe3
 
 }Cmd;
 
 typedef struct Verion
 {
-	char Version_FW[9];
-	char Version_HW[9];
+    char Version_FW[9];
+    char Version_HW[9];
 }Ver;
 
 typedef struct PRESENTINPUTVOLTAGE
 {
-	unsigned char inputType;	// 0x00: Line to Line       0x01: Line to Neutral
-	double L1N_L12;
-	double L2N_L23;
-	double L3N_L31;
+    unsigned char inputType;    // 0x00: Line to Line       0x01: Line to Neutral
+    double L1N_L12;
+    double L2N_L23;
+    double L3N_L31;
 }PresentInputVoltage;
 
 typedef struct PRESENTOUTPUTVOLTAGE
 {
-	double behindFuse_Voltage_C1;
-	double behindRelay_Voltage_C1;
-	double behindFuse_Voltage_C2;
-	double behindRelay_Voltage_C2;
+    double behindFuse_Voltage_C1;
+    double behindRelay_Voltage_C1;
+    double behindFuse_Voltage_C2;
+    double behindRelay_Voltage_C2;
 }PresentOutputVoltage;
 
 typedef struct FANSPEED
 {
-	unsigned short int speed[8];
+    unsigned short int speed[8];
 }FanSpeed;
 
 typedef struct TEMPERATURE
 {
-	unsigned char temperature[8];
+    unsigned char temperature[8];
 }Temperature;
 
 typedef struct AUXPOWER
 {
-	unsigned char voltage[8];
+    unsigned char voltage[8];
 }AuxPower;
 
 typedef struct RELAY
 {
-	union
-	{
-		unsigned char relay_status[8];
-		struct
-		{
-			unsigned char AC_Contactor :1;		//bit 0
-			unsigned char CCS_Precharge :1;	//bit 1
-			unsigned char :1;  				//bit 2 reserved
-			unsigned char :1;					//bit 3 reserved
-			unsigned char :1;					//bit 4 reserved
-			unsigned char :1;					//bit 5 reserved
-			unsigned char :1;					//bit 6 reserved
-			unsigned char :1;					//bit 7 reserved
-
-			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_P :1;	//bit 3
-			unsigned char :1;					//bit 4 reserved
-			unsigned char :1;					//bit 5 reserved
-			unsigned char :1;					//bit 6 reserved
-			unsigned char :1;					//bit 7 reserved
-
-			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 :1;					//bit 4 reserved
-			unsigned char :1;					//bit 5 reserved
-			unsigned char :1;					//bit 6 reserved
-			unsigned char :1;					//bit 7 reserved
-		}bits;
-	}relay_event;
+    union
+    {
+        unsigned char relay_status[8];
+        struct
+        {
+            unsigned char AC_Contactor :1;      //bit 0
+            unsigned char CCS_Precharge :1;     //bit 1
+            unsigned char :1;                   //bit 2 reserved
+            unsigned char :1;                   //bit 3 reserved
+            unsigned char :1;                   //bit 4 reserved
+            unsigned char :1;                   //bit 5 reserved
+            unsigned char :1;                   //bit 6 reserved
+            unsigned char :1;                   //bit 7 reserved
+
+            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_P :1;   //bit 3
+            unsigned char :1;                   //bit 4 reserved
+            unsigned char :1;                   //bit 5 reserved
+            unsigned char :1;                   //bit 6 reserved
+            unsigned char :1;                   //bit 7 reserved
+
+            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 :1;                   //bit 4 reserved
+            unsigned char :1;                   //bit 5 reserved
+            unsigned char :1;                   //bit 6 reserved
+            unsigned char :1;                   //bit 7 reserved
+        }bits;
+    }relay_event;
 }Relay;
 
 typedef struct GFD
 {
-	unsigned short Resister_conn1;
-	unsigned short voltage_conn1;
-	unsigned char result_conn1;
-	unsigned char rb_step_1;
+    unsigned short Resister_conn1;
+    unsigned short voltage_conn1;
+    unsigned char result_conn1;
+    unsigned char rb_step_1;
 
-	unsigned short Resister_conn2;
-	unsigned short voltage_conn2;
-	unsigned char result_conn2;
-	unsigned char rb_step_2;
+    unsigned short Resister_conn2;
+    unsigned short voltage_conn2;
+    unsigned char result_conn2;
+    unsigned char rb_step_2;
 }Gfd;
 
 typedef struct Gfd_CONFIG
 {
-	unsigned char index;
-	unsigned char state;
+    unsigned char index;
+    unsigned char state;
 }Gfd_config;
 
 typedef struct GPIO_IN
 {
-	unsigned char AC_Connector;			// bit 0
-	unsigned char AC_MainBreaker;			// bit 1
-	unsigned char SPD;						// bit 2
-	unsigned char Door_Open;				// bit 3
-	unsigned char GFD[2];					// bit 4,5
-	unsigned char AC_Drop;					// bit 6
-
-	unsigned char Emergency_IO;			// bit 0
-
-	unsigned char Button_Emergency_Press;	// bit 0
-	unsigned char Button_On_Press;			// bit 1
-	unsigned char Button_Off_Press;		// bit 2
-	unsigned char Key_1_Press;				// bit 3
-	unsigned char Key_2_Press;				// bit 4
-	unsigned char Key_3_Press;				// bit 5
-	unsigned char Key_4_Press;				// bit 6
+    unsigned char AC_Connector;             // bit 0
+    unsigned char AC_MainBreaker;           // bit 1
+    unsigned char SPD;                      // bit 2
+    unsigned char Door_Open;                // bit 3
+    unsigned char GFD[2];                   // bit 4,5
+    unsigned char AC_Drop;                  // bit 6
+
+    unsigned char Emergency_IO;             // bit 0
+
+    unsigned char Button_Emergency_Press;   // bit 0
+    unsigned char Button_On_Press;          // bit 1
+    unsigned char Button_Off_Press;         // bit 2
+    unsigned char Key_1_Press;              // bit 3
+    unsigned char Key_2_Press;              // bit 4
+    unsigned char Key_3_Press;              // bit 5
+    unsigned char Key_4_Press;              // bit 6
 }Gpio_in;
 
 typedef struct GPIO_OUT
 {
-	unsigned char AC_Connector;
-	unsigned char Button_LED[2];
-	unsigned char System_LED[4];
+    unsigned char AC_Connector;
+    unsigned char Button_LED[2];
+    unsigned char System_LED[4];
 }Gpio_out;
 
 typedef struct RTC
 {
-	unsigned char RtcData[14];
+    unsigned char RtcData[14];
 }Rtc;
 
+typedef struct LED_Color
+{
+    unsigned char Connect_1_Red;
+    unsigned char Connect_1_Green;
+    unsigned char Connect_1_Blue;
+    unsigned char Connect_2_Red;
+    unsigned char Connect_2_Green;
+    unsigned char Connect_2_Blue;
+}Led_Color;
+
+typedef struct AC_Status
+{
+    unsigned char       CpStatus;
+    unsigned short      CurLimit;
+    short               PilotVol_P;
+    short               PilotVol_N;
+    unsigned char       LockStatus;
+    unsigned char       RelayStatus;
+    unsigned char       ShutterStatus;
+    unsigned char       MeterStatus;
+    unsigned char       PpStatus;
+    unsigned char       MaxCurrent;
+    unsigned char       RotateSwitchStatus;
+}
+Ac_Status;
+
+typedef struct AC_LED_Status
+{
+    unsigned char       ActionMode;
+    unsigned long       AcAlarmCode;
+}
+Ac_Led_Status;
+
+typedef struct AC_Alarm_Code
+{
+    unsigned int        AcAlarmCode;
+}
+Ac_Alarm_code;
+
+typedef struct AC_Charging_Energy
+{
+    unsigned int        Energy;
+}
+Ac_Charging_energy;
+
+typedef struct AC_Charging_Current
+{
+    unsigned short      OuputCurrentL1;
+    unsigned short      OuputCurrentL2;
+    unsigned short      OuputCurrentL3;
+}
+Ac_Charging_current;
+
 extern unsigned char Query_FW_Ver(unsigned char fd, unsigned char targetAddr, Ver *Ret_Buf);
 extern unsigned char Query_HW_Ver(unsigned char fd, unsigned char targetAddr, Ver *Ret_Buf);
 extern unsigned char Query_Present_InputVoltage(unsigned char fd, unsigned char targetAddr, PresentInputVoltage *Ret_Buf);
@@ -178,6 +249,7 @@ extern unsigned char Query_Aux_PowerVoltage(unsigned char fd, unsigned char targ
 extern unsigned char Query_Relay_Output(unsigned char fd, unsigned char targetAddr, Relay *Ret_Buf);
 extern unsigned char Query_Gfd_Adc(unsigned char fd, unsigned char targetAddr, Gfd *Ret_Buf);
 extern unsigned char Query_Gpio_Input(unsigned char fd, unsigned char targetAddr, Gpio_in *Ret_Buf);
+extern unsigned char Query_Model_Name(unsigned char fd, unsigned char targetAddr, unsigned char *modelname);
 
 extern unsigned char Config_Fan_Speed(unsigned char fd, unsigned char targetAddr, FanSpeed *Set_Buf);
 extern unsigned char Config_Relay_Output(unsigned char fd, unsigned char targetAddr, Relay *Set_Buf);
@@ -191,4 +263,14 @@ extern unsigned char Update_Abord(unsigned char fd, unsigned char targetAddr);
 extern unsigned char Update_Transfer(unsigned char fd, unsigned char targetAddr, unsigned int startAddr, unsigned char *data, unsigned short int length);
 extern unsigned char Update_Finish(unsigned char fd, unsigned char targetAddr);
 
+extern unsigned char Query_AC_Status(unsigned char fd, unsigned char targetAddr, Ac_Status *Ret_Buf);
+extern unsigned char Query_AC_Alarm_Code(unsigned char fd, unsigned char targetAddr, Ac_Alarm_code *Ret_Buf);
+extern unsigned char Query_Charging_Energy(unsigned char fd, unsigned char targetAddr, Ac_Charging_energy *Ret_Buf);
+extern unsigned char Query_Charging_Current(unsigned char fd, unsigned char targetAddr, Ac_Charging_current *Ret_Buf);
+extern unsigned char Config_LED_Status(unsigned char fd, unsigned char targetAddr, Ac_Led_Status *Ret_Buf);
+extern unsigned char Config_Legacy_Req(unsigned char fd, unsigned char targetAddr, unsigned char _switch);
+extern unsigned char Config_Ac_Duty(unsigned char fd, unsigned char targetAddr, unsigned char _value);
+extern unsigned char Config_CSU_Mode(unsigned char fd, unsigned char targetAddr);
+extern unsigned char Config_Reset_MCU(unsigned char fd, unsigned char targetAddr);
+extern unsigned char Config_Led_Color(unsigned char fd, unsigned char targetAddr, Led_Color *Ret_Buf);
 #endif /* INTERNALCOMM_H_ */

+ 0 - 1
EVSE/Projects/DW30/Apps/kill.sh

@@ -9,4 +9,3 @@ pkill Module_4g
 pkill Module_Wifi
 pkill OcppBackend
 pkill main
-

文件差异内容过多而无法显示
+ 1370 - 1130
EVSE/Projects/DW30/Apps/main.c


+ 5 - 5
EVSE/Projects/DW30/Apps/timeout.c

@@ -1,5 +1,5 @@
-#include "timeout.h"
-
-//===============================================
-// Initial Callback function
-//===============================================
+#include "timeout.h"
+
+//===============================================
+// Initial Callback function
+//===============================================

+ 52 - 53
EVSE/Projects/DW30/Apps/timeout.h

@@ -1,53 +1,52 @@
-#ifndef TIMEOUT_H_
-#define TIMEOUT_H_
-
-#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/wireless.h>
-#include 	<linux/can.h>
-#include 	<linux/can/raw.h>
-#include 	<arpa/inet.h>
-#include 	<netinet/in.h>
-
-#include 	<unistd.h>
-#include 	<stdarg.h>
-#include    <stdio.h>
-#include    <stdlib.h>
-#include    <unistd.h>
-#include    <fcntl.h>
-#include    <termios.h>
-#include    <errno.h>
-#include 	<errno.h>
-#include 	<string.h>
-#include	<time.h>
-#include	<ctype.h>
-#include 	<ifaddrs.h>
-
-enum Timeout_flag
-{
-	Timeout_None =						0,
-	Timeout_SelftestChk = 				1,
-	Timeout_Authorizing = 				2,
-	Timeout_VerifyFail = 				3,
-	Timeout_VerifyComp = 				4,
-	Timeout_WaitPlug = 					5,
-
-	Timeout_Preparing = 				6,
-	Timeout_EvChargingDet = 			7,
-	Timeout_EvseChargingDet = 			8,
-	Timeout_WaitforCompleteDet = 		9,
-
-	Timeout_ForCcsPrechargeDet = 		10,
-	Timeout_ReturnToChargingGunDet = 	11
-};
-
-#endif /* TIMEOUT_H_ */
+#ifndef TIMEOUT_H_
+#define TIMEOUT_H_
+
+#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/wireless.h>
+#include <linux/can.h>
+#include <linux/can/raw.h>
+#include <arpa/inet.h>
+#include <netinet/in.h>
+
+#include <unistd.h>
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <termios.h>
+#include <errno.h>
+#include <errno.h>
+#include <string.h>
+#include <time.h>
+#include <ctype.h>
+#include <ifaddrs.h>
+
+enum Timeout_flag
+{
+    Timeout_None =                      0,
+    Timeout_SelftestChk =               1,
+    Timeout_Authorizing =               2,
+    Timeout_VerifyFail =                3,
+    Timeout_VerifyComp =                4,
+    Timeout_WaitPlug =                  5,
+
+    Timeout_Preparing =                 6,
+    Timeout_EvChargingDet =             7,
+    Timeout_EvseChargingDet =           8,
+    Timeout_EvseCompleteDet =           9,
+    Timeout_ForCcsPrechargeDet =        10,
+    Timeout_ReturnToChargingGunDet =    11
+};
+
+#endif /* TIMEOUT_H_ */

+ 1 - 0
EVSE/Projects/DW30/Apps/web.sh

@@ -0,0 +1 @@
+/sbin/lighttpd -f /etc/lighttpd/lighttpd.conf  -m /lib

部分文件因为文件数量过多而无法显示