Quellcode durchsuchen

[Add][NoodoeDS][All]

2022.03.25 / Folus Wen

Actions:
1. Clone project from DS60-120 for Noodoe customization.

Files:
1. As follow commit history

Image version: D0.00.XX.XXXX.XX
Image checksum: XXXXXXXX

Hardware PWB P/N : XXXXXXX
Hardware Version : XXXXXXX
FolusWen vor 3 Jahren
Ursprung
Commit
9f5fcd68bc
54 geänderte Dateien mit 33113 neuen und 75 gelöschten Zeilen
  1. 1 1
      EVSE/Projects/AX80/Apps/CCS/define.h
  2. 133 0
      EVSE/Projects/NoodoeDS/Apps/CheckSystemTask.c
  3. 42 0
      EVSE/Projects/NoodoeDS/Apps/CheckSystemTask.h
  4. 438 0
      EVSE/Projects/NoodoeDS/Apps/Config.h
  5. 299 0
      EVSE/Projects/NoodoeDS/Apps/Ev_Comm.c
  6. BIN
      EVSE/Projects/NoodoeDS/Apps/FactoryConfig
  7. 421 0
      EVSE/Projects/NoodoeDS/Apps/FactoryConfig.c
  8. 101 0
      EVSE/Projects/NoodoeDS/Apps/Makefile
  9. BIN
      EVSE/Projects/NoodoeDS/Apps/Module_EvComm
  10. 4595 0
      EVSE/Projects/NoodoeDS/Apps/Module_EvComm.c
  11. 96 0
      EVSE/Projects/NoodoeDS/Apps/Module_EvComm.h
  12. BIN
      EVSE/Projects/NoodoeDS/Apps/Module_EventLogging
  13. 571 0
      EVSE/Projects/NoodoeDS/Apps/Module_EventLogging.c
  14. BIN
      EVSE/Projects/NoodoeDS/Apps/Module_InternalComm
  15. 3555 0
      EVSE/Projects/NoodoeDS/Apps/Module_InternalComm.c
  16. 235 0
      EVSE/Projects/NoodoeDS/Apps/Module_LcmContro.h
  17. BIN
      EVSE/Projects/NoodoeDS/Apps/Module_LcmControl
  18. 2023 0
      EVSE/Projects/NoodoeDS/Apps/Module_LcmControl.c
  19. BIN
      EVSE/Projects/NoodoeDS/Apps/Module_PrimaryComm
  20. 697 0
      EVSE/Projects/NoodoeDS/Apps/Module_PrimaryComm.c
  21. BIN
      EVSE/Projects/NoodoeDS/Apps/Module_PsuComm
  22. 2748 0
      EVSE/Projects/NoodoeDS/Apps/Module_PsuComm.c
  23. 88 0
      EVSE/Projects/NoodoeDS/Apps/Module_PsuComm.h
  24. 375 0
      EVSE/Projects/NoodoeDS/Apps/OutputTask.c
  25. 174 0
      EVSE/Projects/NoodoeDS/Apps/OutputTask.h
  26. 438 0
      EVSE/Projects/NoodoeDS/Apps/PrimaryComm.c
  27. 84 0
      EVSE/Projects/NoodoeDS/Apps/PrimaryComm.h
  28. BIN
      EVSE/Projects/NoodoeDS/Apps/ReadCmdline
  29. 1944 0
      EVSE/Projects/NoodoeDS/Apps/ReadCmdline.c
  30. BIN
      EVSE/Projects/NoodoeDS/Apps/UnsafetyOutputTask
  31. 315 0
      EVSE/Projects/NoodoeDS/Apps/cbmp.c
  32. 54 0
      EVSE/Projects/NoodoeDS/Apps/cbmp.h
  33. 11 0
      EVSE/Projects/NoodoeDS/Apps/init.sh
  34. 1294 0
      EVSE/Projects/NoodoeDS/Apps/internalComm.c
  35. 296 0
      EVSE/Projects/NoodoeDS/Apps/internalComm.h
  36. 7 0
      EVSE/Projects/NoodoeDS/Apps/kill.sh
  37. BIN
      EVSE/Projects/NoodoeDS/Apps/main
  38. 10368 0
      EVSE/Projects/NoodoeDS/Apps/main.c
  39. 6 0
      EVSE/Projects/NoodoeDS/Apps/timeout.c
  40. 68 0
      EVSE/Projects/NoodoeDS/Apps/timeout.h
  41. 1 0
      EVSE/Projects/NoodoeDS/Apps/web.sh
  42. BIN
      EVSE/Projects/NoodoeDS/Images/FactoryDefaultConfig.bin
  43. BIN
      EVSE/Projects/NoodoeDS/Images/MLO
  44. BIN
      EVSE/Projects/NoodoeDS/Images/am335x-evm.dtb
  45. BIN
      EVSE/Projects/NoodoeDS/Images/ramdisk.gz
  46. BIN
      EVSE/Projects/NoodoeDS/Images/u-boot-spl.bin
  47. BIN
      EVSE/Projects/NoodoeDS/Images/u-boot.img
  48. BIN
      EVSE/Projects/NoodoeDS/Images/zImage
  49. 72 73
      Makefile
  50. 713 0
      board-support/linux-4.9.59+gitAUTOINC+a75d8e9305-ga75d8e9305/arch/arm/boot/dts/[NoodoeDS]am335x-evm.dts
  51. 1 0
      board-support/linux-4.9.59+gitAUTOINC+a75d8e9305-ga75d8e9305/lib/.crc7.ko.cmd
  52. 46 0
      board-support/linux-4.9.59+gitAUTOINC+a75d8e9305-ga75d8e9305/lib/.gen_crc32table.cmd
  53. 802 0
      board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/arch/arm/dts/[NoodoeDS]am335x-evm.dts
  54. 1 1
      run_gen_make_script.sh

+ 1 - 1
EVSE/Projects/AX80/Apps/CCS/define.h

@@ -50,7 +50,7 @@
 /**************************************************************************************/
 /*********************************System Limitation**********************************/
 /**************************************************************************************/
-#ifdef AWCCS
+#ifdef AX80
 #undef CONNECTOR_TEMP_DETECTION
 #define CCS_ENERGY_TRANSFER_MODE                    MODE_AC_SINGLE_PHASE_CORE 
 #else

+ 133 - 0
EVSE/Projects/NoodoeDS/Apps/CheckSystemTask.c

@@ -0,0 +1,133 @@
+/*
+ * CheckTask.c
+ *
+ *  Created on: 2021年9月2日
+ *      Author: 7564
+ */
+
+#include "CheckSystemTask.h"
+#include "Config.h"
+
+#define	TASK_CNT_MAIN		5
+#define TASK_CNT_EV_COMM	2
+#define TASK_CNT_PSU_COMM	2
+
+bool Taskconutstring(char *src, char *taskname)
+{
+	bool result = false;
+
+	if (src == NULL || strlen(src) == 0)
+		return result;
+
+	if (strstr(src, taskname) != NULL &&
+		strstr(src, "grep") == NULL &&
+		strstr(src, "[") == NULL)
+	{
+		result = true;
+	}
+
+	return result;
+}
+
+int GetProcessCount(char *procName)
+{
+	int result = 0;
+	FILE *fp;
+	char cmd[256];
+	char buf[256];
+
+	sprintf(cmd, "ps -ef |grep %s", procName);
+	fp = popen(cmd, "r");
+	if(fp != NULL)
+	{
+		while(fgets(buf, sizeof(buf), fp) != NULL)
+		{
+			if (Taskconutstring(buf, procName))
+				result++;
+		}
+	}
+
+	pclose(fp);
+
+	return result;
+}
+
+unsigned char CheckSystemTask(unsigned char systemPage)
+{
+	unsigned char result = 0;
+	unsigned char count_main 		= GetProcessCount("Module_CSU");
+	unsigned char count_evComm 		= GetProcessCount("Module_EvComm");
+	unsigned char count_psuComm 	= GetProcessCount("Module_PsuComm");
+
+	if (count_main == 0)
+		count_main = GetProcessCount("main");
+
+//	printf("*************************** \n");
+//	printf("count_main = %d \n", count_main);
+//	printf("count_eventLog = %d \n", count_eventLog);
+//	printf("count_primary = %d \n", count_primary);
+//	printf("count_evComm = %d \n", count_evComm);
+//	printf("count_lcmCtrl = %d \n", count_lcmCtrl);
+//	printf("count_interComm = %d \n", count_interComm);
+//	printf("count_psuComm = %d \n", count_psuComm);
+//	printf("*************************** \n");
+
+	if (systemPage == _LCM_FIX || systemPage == _LCM_EMC)
+	{
+		if (count_main < TASK_CNT_MAIN || count_psuComm < TASK_CNT_PSU_COMM)
+		{
+			system("killall Module_EventLogging");
+			system("killall Module_PrimaryComm");
+			system("killall Module_EvComm");
+			system("killall Module_LcmControl");
+			system("killall Module_InternalComm");
+			system("killall Module_PsuComm");
+			system("killall OcppBackend &");
+			system("killall Module_4g &");
+			system("killall Module_Wifi &");
+			system("killall Module_DcMeter &");
+			sleep(3);
+			system("/usr/bin/run_evse_restart.sh");
+		}
+		else
+		{
+			if(system("pidof -s Module_EventLogging > /dev/null") != 0)
+				system("/root/Module_EventLogging &");
+
+			if(system("pidof -s Module_PrimaryComm > /dev/null") != 0)
+				system("/root/Module_PrimaryComm &");
+
+			if(system("pidof -s Module_LcmControl > /dev/null") != 0)
+				system("/root/Module_LcmControl &");
+
+			if(system("pidof -s Module_InternalComm > /dev/null") != 0)
+				system("/root/Module_InternalComm &");
+
+			if (count_evComm < TASK_CNT_EV_COMM)
+			{
+				system("killall Module_EvComm");
+				sleep(3);
+				system("/root/Module_EvComm &");
+			}
+		}
+
+		sleep(2);
+	}
+
+	if (count_main < TASK_CNT_MAIN)
+		result = _SYSTEM_TASK_LOST_ITEM_MAIN;
+	else if (count_evComm < TASK_CNT_EV_COMM)
+		result = _SYSTEM_TASK_LOST_ITEM_EVCOMM;
+	else if (count_psuComm < TASK_CNT_PSU_COMM)
+		result = _SYSTEM_TASK_LOST_ITEM_PSUCOMM;
+	else if (system("pidof -s Module_EventLogging > /dev/null") != 0)
+		result = _SYSTEM_TASK_LOST_ITEM_EVENTLOG;
+	else if (system("pidof -s Module_PrimaryComm > /dev/null") != 0)
+		result = _SYSTEM_TASK_LOST_ITEM_PRIMARYCOMM;
+	else if (system("pidof -s Module_LcmControl > /dev/null") != 0)
+		result = _SYSTEM_TASK_LOST_ITEM_LCMCONTROL;
+	else if (system("pidof -s Module_InternalComm > /dev/null") != 0)
+		result = _SYSTEM_TASK_LOST_ITEM_INTERCOMM;
+
+	return result;
+}

+ 42 - 0
EVSE/Projects/NoodoeDS/Apps/CheckSystemTask.h

@@ -0,0 +1,42 @@
+/*
+ * CheckTask.h
+ *
+ *  Created on: 2021年9月2日
+ *      Author: 7564
+ */
+
+#ifndef CHECKTASK_H_
+#define CHECKTASK_H_
+
+#include 	<sys/timeb.h>
+#include 	<sys/types.h>
+#include 	<sys/ioctl.h>
+#include 	<sys/socket.h>
+#include 	<sys/ipc.h>
+#include 	<sys/shm.h>
+#include 	<sys/mman.h>
+#include 	<linux/wireless.h>
+#include 	<arpa/inet.h>
+#include 	<netinet/in.h>
+
+#include 	<unistd.h>
+#include 	<stdarg.h>
+#include    <stdio.h>      /*標準輸入輸出定義*/
+#include    <stdlib.h>     /*標準函數庫定義*/
+#include    <unistd.h>     /*Unix 標準函數定義*/
+#include    <fcntl.h>      /*檔控制定義*/
+#include    <termios.h>    /*PPSIX 終端控制定義*/
+#include    <errno.h>      /*錯誤號定義*/
+#include 	<string.h>
+#include 	<stdint.h>
+#include	<time.h>
+#include	<ctype.h>
+#include 	<ifaddrs.h>
+#include 	<math.h>
+#include 	<stdbool.h>
+#include 	<dirent.h>
+#include 	"Config.h"
+
+unsigned char CheckSystemTask(unsigned char systemPage);
+
+#endif /* CHECKSYSTEMTASK_H_ */

+ 438 - 0
EVSE/Projects/NoodoeDS/Apps/Config.h

@@ -0,0 +1,438 @@
+/*
+ * Config.h
+ *
+ *  Created on: 2019年4月23日
+ *      Author: foluswen
+ */
+#ifndef CONFIG_H_
+#define CONFIG_H_
+
+#include    <sys/types.h>
+
+#define ShmCsuMeterKey			2001
+#define ShmCommonKey			2002
+
+typedef unsigned char			byte;
+
+#define TOTAL_QUANTITY_GUN			4				//Max Count
+#define DC_CONNECTOR_COUNT			2
+#define AC_CONNECTOR_COUNT			1
+
+#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
+
+#define	AC_MINIMUM_DUTY			6
+#define	AC_STOP_DUTY			100
+
+enum _AC_SYSTEM_STATUS
+{
+	AC_SYS_NONE = 	0,
+	AC_SYS_A,
+	AC_SYS_B,
+	AC_SYS_C,
+	AC_SYS_D,
+	AC_SYS_E,
+	AC_SYS_F
+};
+
+enum _GUN_TYPE
+{
+	_Type_Chademo = 		0,
+	_Type_CCS,
+	_Type_GB,
+	_Type_AC,
+};
+
+enum _CCS_TYPE
+{
+	_CCS_TYPE_CCS1 = 	0,
+	_CCS_TYPE_CCS2 = 	1,
+};
+
+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_EMC = 				0x0A,
+	_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,
+
+	_TEST_MODE			=		20,
+	_ALATON_MODE		= 		21,
+
+	_NO_WORKING			= 		254
+};
+
+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,
+};
+
+enum _SYS_WIFI_MODE
+{
+	_SYS_WIFI_MODE_DISABLE = 0,
+	_SYS_WIFI_MODE_STATION = 1,
+	_SYS_WIFI_MODE_AP = 2
+};
+
+enum _SYS_4G_MODE
+{
+	_SYS_4G_MODE_DISABLE = 0,
+	_SYS_4G_MODE_ENABLE = 1,
+};
+
+enum _LED_INTENSITY_LV
+{
+	_LED_INTENSITY_DARKEST 	 = 0,
+	_LED_INTENSITY_MEDIUM 	 = 1,
+	_LED_INTENSITY_BRIGHTEST = 2
+};
+
+enum _UPDATE_TYPE
+{
+	_UPDATE_TYPE_CSU_UBOOT 	 	= 0x10000001,
+	_UPDATE_TYPE_CSU_DTB 	 	= 0x10000002,
+	_UPDATE_TYPE_CSU_ZIMAGE 	= 0x10000003,
+	_UPDATE_TYPE_CSU_RFILES 	= 0x10000004,
+	_UPDATE_TYPE_CSU_CONFIG 	= 0x10000005,
+
+	_UPDATE_TYPE_CCS_UBOOT 	 	= 0x10000007,
+	_UPDATE_TYPE_CCS_DTB 		= 0x10000008,
+	_UPDATE_TYPE_CCS_ZIMAGE 	= 0x10000009,
+	_UPDATE_TYPE_CCS_RFILES 	= 0x1000000A,
+
+	_UPDATE_TYPE_DCM_ST407 		= 0x10000006,
+	_UPDATE_TYPE_RELAY_CTR 		= 0x1000000D,
+	_UPDATE_TYPE_FAN_CTR 		= 0x1000000E,
+	_UPDATE_TYPE_AC_WLMOUNT_CTR = 0x20000002,
+	_UPDATE_TYPE_LED_CTR		= 0x10000014,
+
+	_UPDATE_TYPE_CHADEMO 		= 0x1000000B,
+	_UPDATE_TYPE_GBT			= 0x1000000C,
+};
+
+enum _CCS_COMM_PROTOCOL
+{
+	_CCS_COMM_V2GMessage_DIN70121 		= 0x01,
+	_CCS_COMM_V2GMessage_ISO15118_2014 	= 0x02,
+	_CCS_COMM_V2GMessage_ISO15118_2018 	= 0x03
+};
+
+enum _ETHERNET_USAGE
+{
+	_ETHERNET_USAGE_NONE 	= 0,
+	_ETHERNET_USAGE_LAN,
+	_ETHERNET_USAGE_WIFI,
+	_ETHERNET_USAGE_3G_4g
+};
+
+enum _PRIMARY_CHECK_TAG
+{
+	_PRIMARY_CHECK_TAG_AC_CONTACT		= 0,
+	_PRIMARY_CHECK_TAG_MAIN_BREAKER		= 1,
+};
+
+enum _ALARM_LEVEL_TAG
+{
+	_ALARM_LEVEL_NORMAL 		= 0,
+	_ALARM_LEVEL_WARNING		= 1,
+	_ALARM_LEVEL_CRITICAL		= 2
+};
+
+enum _SYSTEM_TASK_LOST_ITEM
+{
+	_SYSTEM_TASK_LOST_ITEM_MAIN 		= 1,
+	_SYSTEM_TASK_LOST_ITEM_EVCOMM 		= 2,
+	_SYSTEM_TASK_LOST_ITEM_PSUCOMM		= 3,
+	_SYSTEM_TASK_LOST_ITEM_EVENTLOG		= 4,
+	_SYSTEM_TASK_LOST_ITEM_PRIMARYCOMM	= 5,
+	_SYSTEM_TASK_LOST_ITEM_LCMCONTROL	= 6,
+	_SYSTEM_TASK_LOST_ITEM_INTERCOMM	= 7
+};
+
+struct StructMeter
+{
+	float curMeterValue;
+	float newMeterValue;
+	byte isCalculation;
+	float _chargingValue;
+	float _curTotalCharging;
+};
+
+struct MeterInformation
+{
+	struct StructMeter _meter[DC_CONNECTOR_COUNT];
+	byte isWorking;
+};
+
+struct ConnectorBalanceInfo
+{
+	unsigned int UserPrice; // connector user's user price, unit: 0.01 (dollar / kWh)
+	unsigned int TotalCost; // connector user's total cost, unit: 0.01 dollar
+	int AccountBalance; // connector user's account balance, unit: 0.01 dollar
+};
+
+struct BalanceInfo
+{
+	unsigned int defaultPrice;
+	struct ConnectorBalanceInfo connectorBalanceInfo[3]; // Max count : DC * 2 + AC * 1
+};
+
+struct ChademoTryCommunicationKey
+{
+	byte try2CommunicationFlag;
+	struct timespec detectTimer;
+	byte elapsedTime;
+};
+
+enum _CCS_VERSION_CHECK_TAG
+{
+	_CCS_VERSION_CHECK_TAG_V015S0		= 0,
+	_CCS_VERSION_CHECK_TAG_V013S0		= 1,
+};
+
+enum RELAY_STATUS_ERROR_INDEX
+{
+	RELAY_SMR1_P_STATUS = 	0,
+	RELAY_SMR1_N_STATUS = 	1,
+	RELAY_SMR2_P_STATUS = 	2,
+	RELAY_SMR2_N_STATUS = 	3,
+	RELAY_PARA_P_STATUS = 	4,
+	RELAY_PARA_N_STATUS = 	5,
+};
+
+enum RELAY_STATUS_ERROR_TYPE
+{
+	RELAY_STATUS_ERROR_NONE = 0,
+	RELAY_STATUS_ERROR_WELDING = 10,
+	RELAY_STATUS_ERROR_DRIVING = 11,
+	RELAY_STATUS_ERROR_PARA_WELDING = 12,
+	RELAY_STATUS_ERROR_PARA_DRIVING = 13,
+};
+
+enum START_TRANSATION_STATUS
+{
+	START_TRANSATION_STATUS_WAIT = 0x00,
+	START_TRANSATION_STATUS_PASS = 0x01,
+	START_TRANSATION_STATUS_FAIL = 0x02,
+};
+
+enum CHARGER_TYPE
+{
+	CHARGER_TYPE_STANDARD 	= 0x00,
+	CHARGER_TYPE_SIMPLE 	= 0X01,
+};
+
+enum RESET_4G_STEP
+{
+	RESET_4G_STEP_NONE 				= 0x00,
+	RESET_4G_STEP_DELETE_TASK 		= 0x01,
+	RESET_4G_STEP_GPIO_HIGH			= 0x02,
+	RESET_4G_STEP_GPIO_LOW_COMP		= 0x03
+};
+
+enum _CCID_INDEX
+{
+	_CCID_GET 		= 0x01,
+	_CCID_CHECK		= 0x02,
+	_CCID_AUTH		= 0x03,
+	_CCID_AUTHCOMP	= 0x04,
+	_CCID_AUTHFAIL	= 0x05,
+	_CCID_NONE 		= 0xFF,
+};
+
+typedef union
+{
+    unsigned int GunErrMessage;
+    struct
+    {
+        unsigned char ChaGfdTrip:1;
+        unsigned char ChaUvpFail:1;
+        unsigned char ChaConnectOTP:1;
+        unsigned char ChaConnectOVP:1;
+        unsigned char ChaGfdWarning:1;
+        unsigned char ChaRelayWeldingFault:1;
+        unsigned char ChaRelayDrivingFault:1;
+        unsigned char ChaConnectTempSensorFail:1;
+
+        unsigned char CCSGfdTrip :1;
+		unsigned char CCSUvpFail :1;
+		unsigned char CCSConnectOTP :1;
+		unsigned char CCSConnectOVP :1;
+		unsigned char CCSGfdWarning :1;
+		unsigned char CCSRelayWeldingFault :1;
+		unsigned char CCSRelayDrivingFault :1;
+		unsigned char CCSConnectTempSensorFail :1;
+
+		unsigned char GBTGfdTrip :1;
+		unsigned char GBTUvpFail :1;
+		unsigned char GBTConnectOTP :1;
+		unsigned char GBTConnectOVP :1;
+		unsigned char GBTGfdWarning :1;
+		unsigned char GBTRelayWeldingFault :1;
+		unsigned char GBTRelayDrivingFault :1;
+		unsigned char GBTConnectTempSensorFail :1;
+
+		unsigned char ChaConnectUCP :1;
+		unsigned char CCSConnectUCP :1;
+		unsigned char GBTConnectUCP :1;
+		unsigned char ParallelRelayWeldingFault :1;
+		unsigned char ParallelRelayDrivingFault :1;
+		unsigned char :3;
+    }GunBits;
+}GunErr;
+
+struct DcCommonInformation
+{
+	byte rebootCount;
+	// charger type (standard、simple)
+	byte chargerType;
+	// minimun output current limit
+	float minOutputCur;
+	// check if the guns are of the same type
+	byte SysGunAreSameType;
+	// to check the ccs version
+	byte CcsVersion;
+	// for relay welding/driving check
+	char RelayCheckStatus[6];
+	char GunRelayWeldingOccur[DC_CONNECTOR_COUNT];
+	char GunRelayDrivingOccur[DC_CONNECTOR_COUNT];
+	char ParaRelayWeldingOccur;
+	char ParaRelayDrivingOccur;
+	byte ConnectorTemp1[DC_CONNECTOR_COUNT]; //0x00: -60¢XC  ~  0xFE: 194
+	byte ConnectorTemp2[DC_CONNECTOR_COUNT]; //0x00: -60¢XC  ~  0xFE: 194
+	// to check the ac contact status with psu communication
+	byte acContactSwitch;
+	byte psuKeepCommunication;
+	byte startTransactionFlag[DC_CONNECTOR_COUNT];
+
+	GunErr ConnectErrList[DC_CONNECTOR_COUNT];
+	byte CcsTypeSaved[DC_CONNECTOR_COUNT];
+
+	// Plugit Rack180 : for checking start/stop charging flag
+	byte StartToChargingFlag[DC_CONNECTOR_COUNT]; // 0 : Stop, 1 : Start by modbus
+	unsigned short LcmFwVersion;
+	byte ShowLogoFlag;
+
+	// ocpp offline policy
+	byte _isAllowChargingOnDisconnect;
+
+	// Billing Data extend
+	byte _hour_index;			//0 ~ 23
+	float energy_time_period[DC_CONNECTOR_COUNT][24];
+
+	// for OCPP Reserved
+	byte _reserved_UserId[DC_CONNECTOR_COUNT][32];
+	byte _reserved_ac_UserId[AC_CONNECTOR_COUNT][32];
+
+	// auto run flag
+	byte _isAutoRunTest;
+
+	// chademo try to communicaton flag (for tesla adapter)
+	struct ChademoTryCommunicationKey _cha_try_communication[DC_CONNECTOR_COUNT];
+
+	// if the psu communication timedout, reset the AC contact for 30s
+	struct timespec _psuComm_time;
+
+	// for reset ev board (GBT or Chademo)
+	byte evBoardResetFlag;
+
+	// Psu module split by connector
+	int connector[DC_CONNECTOR_COUNT][12];
+	byte conn_1_count;
+	byte conn_2_count;
+
+	// Use ccid to obtain authorization
+	byte enObtainAuthorizbyCCID;
+	byte _CcidAuthProcessStep;
+	byte _authWithCcidFlag[DC_CONNECTOR_COUNT];
+
+	// balance information - for tariff
+	struct BalanceInfo balanceInfo;
+
+	// the hold time before return idle
+	byte _returnIdleHoldFlag[DC_CONNECTOR_COUNT];
+
+	// isPsuError
+	byte _isPsuErrorOccur;
+
+	byte for_alston_test_1;
+	byte for_alston_test_2;
+	byte for_alston_test_3;
+};
+
+#endif /* CONFIG_H_ */

+ 299 - 0
EVSE/Projects/NoodoeDS/Apps/Ev_Comm.c

@@ -0,0 +1,299 @@
+#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(EvFrame cmd, byte *data, byte dataLen)
+{
+    struct can_frame frame;
+
+    frame.can_id = cmd.EvMessage;
+    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)
+{
+	EvFrame EvFrameMsg;
+
+	EvFrameMsg.EvMessage = 0;
+	EvFrameMsg.EvBdBits.SlaveAddress = index;
+	EvFrameMsg.EvBdBits.MessageID = EV_Command_AddressAssignment;
+	EvFrameMsg.EvMessage = PackageIdCmd(EvFrameMsg.EvMessage);
+
+	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(EvFrameMsg, data, 5);
+}
+
+void GetFirmwareVersion(byte gun_index, byte toId)
+{
+	EvFrame EvFrameMsg;
+
+	EvFrameMsg.EvMessage = 0;
+	EvFrameMsg.EvBdBits.SlaveAddress = toId;
+	EvFrameMsg.EvBdBits.MessageID = EV_Command_GetFwVersion;
+	EvFrameMsg.EvMessage = PackageIdCmd(EvFrameMsg.EvMessage);
+
+	byte data[8];
+
+	SendCmdToEvboard(EvFrameMsg, data, 0);
+}
+
+void SetConnectInfo(byte type, byte toId)
+{
+	EvFrame EvFrameMsg;
+
+	EvFrameMsg.EvMessage = 0;
+	EvFrameMsg.EvBdBits.SlaveAddress = toId;
+	EvFrameMsg.EvBdBits.MessageID = EV_Command_CCSconnectorInfo;
+	EvFrameMsg.EvMessage = PackageIdCmd(EvFrameMsg.EvMessage);
+
+	byte data[8];
+
+	data[0] = type;
+	SendCmdToEvboard(EvFrameMsg, data, 1);
+}
+
+void SyncRtcInfo(byte gun_index, byte toId, int epoch)
+{
+	EvFrame EvFrameMsg;
+
+	EvFrameMsg.EvMessage = 0;
+	EvFrameMsg.EvBdBits.SlaveAddress = toId;
+	EvFrameMsg.EvBdBits.MessageID = EV_Command_SyncRtcInfo;
+	EvFrameMsg.EvMessage = PackageIdCmd(EvFrameMsg.EvMessage);
+
+	byte data[8];
+
+	data[0] = epoch & 0xff;
+	data[1] = (epoch >> 8) & 0xff;
+	data[2] = (epoch >> 16) & 0xff;
+	data[3] = (epoch >> 24) & 0xff;
+
+	SendCmdToEvboard(EvFrameMsg, data, 4);
+}
+
+void GetHardwareVersion(byte gun_index, byte toId)
+{
+	EvFrame EvFrameMsg;
+
+	EvFrameMsg.EvMessage = 0;
+	EvFrameMsg.EvBdBits.SlaveAddress = toId;
+	EvFrameMsg.EvBdBits.MessageID = EV_Command_GetHwVersion;
+	EvFrameMsg.EvMessage = PackageIdCmd(EvFrameMsg.EvMessage);
+
+	byte data[8];
+
+	SendCmdToEvboard(EvFrameMsg, data, 0);
+}
+
+void SetChargingPermission(byte gun_index, byte permissionStatus, float aOutputPw, float aOutputCur, short aOutputVol, byte toId)
+{
+	EvFrame EvFrameMsg;
+
+	EvFrameMsg.EvMessage = 0;
+	EvFrameMsg.EvBdBits.SlaveAddress = toId;
+	EvFrameMsg.EvBdBits.MessageID = EV_Command_ChargingPermission;
+	EvFrameMsg.EvMessage = PackageIdCmd(EvFrameMsg.EvMessage);
+
+	byte data[8];
+
+	data[0] = permissionStatus;
+	data[1] = (short)aOutputPw & 0xff;
+	data[2] = ((short)aOutputPw >> 8) & 0xff;
+	data[3] = (short)aOutputCur & 0xff;
+	data[4] = ((short)aOutputCur >> 8) & 0xff;
+	data[5] = (short)aOutputVol & 0xff;
+	data[6] = ((short)aOutputVol >> 8) & 0xff;
+	data[7] = 0xf0;
+
+	SendCmdToEvboard(EvFrameMsg, data, sizeof(data));
+}
+
+void SetPresentOutputPower(short outputVol_b1, short outputCur_b1, short outputVol_b2, short outputCur_b2)
+{
+	EvFrame EvFrameMsg;
+
+	EvFrameMsg.EvMessage = 0;
+	EvFrameMsg.EvBdBits.SlaveAddress = 0;
+	EvFrameMsg.EvBdBits.MessageID = EV_Command_PresentOutputPow;
+	EvFrameMsg.EvMessage = PackageIdCmd(EvFrameMsg.EvMessage);
+
+	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(EvFrameMsg, data, 8);
+}
+
+void SetPresentOutputCapacity(short aOutputPw_b1, short aOutputCur_b1, short aOutputPw_b2, short aOutputCur_b2)
+{
+	EvFrame EvFrameMsg;
+
+	EvFrameMsg.EvMessage = 0;
+	EvFrameMsg.EvBdBits.SlaveAddress = 0;
+	EvFrameMsg.EvBdBits.MessageID = EV_Command_PresentOutputCap;
+	EvFrameMsg.EvMessage = PackageIdCmd(EvFrameMsg.EvMessage);
+
+	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(EvFrameMsg, data, 8);
+}
+
+void GetOutputReq(byte gun_index, byte toId)
+{
+	EvFrame EvFrameMsg;
+
+	EvFrameMsg.EvMessage = 0;
+	EvFrameMsg.EvBdBits.SlaveAddress = toId;
+	EvFrameMsg.EvBdBits.MessageID = EV_Command_GetOutputReq;
+	EvFrameMsg.EvMessage = PackageIdCmd(EvFrameMsg.EvMessage);
+
+	byte data[8];
+
+	SendCmdToEvboard(EvFrameMsg, data, 0);
+}
+
+void GetEvccIdReq(byte gun_index, byte toId)
+{
+	EvFrame EvFrameMsg;
+
+	EvFrameMsg.EvMessage = 0;
+	EvFrameMsg.EvBdBits.SlaveAddress = toId;
+	EvFrameMsg.EvBdBits.MessageID = EV_Command_EvccidReq;
+	EvFrameMsg.EvMessage = PackageIdCmd(EvFrameMsg.EvMessage);
+
+	byte data[8];
+
+	SendCmdToEvboard(EvFrameMsg, data, 0);
+}
+
+void GetEvBatteryInfo(byte gun_index, byte toId)
+{
+	EvFrame EvFrameMsg;
+
+	EvFrameMsg.EvMessage = 0;
+	EvFrameMsg.EvBdBits.SlaveAddress = toId;
+	EvFrameMsg.EvBdBits.MessageID = EV_Command_GetBetteryInfo;
+	EvFrameMsg.EvMessage = PackageIdCmd(EvFrameMsg.EvMessage);
+
+	byte data[8];
+
+	SendCmdToEvboard(EvFrameMsg, data, 0);
+}
+
+void EvseStopChargingEvent(byte stopResult, byte *stopReason, byte toId)
+{
+	EvFrame EvFrameMsg;
+
+	EvFrameMsg.EvMessage = 0;
+	EvFrameMsg.EvBdBits.SlaveAddress = toId;
+	EvFrameMsg.EvBdBits.MessageID = EV_Command_EvseStopCharging;
+	EvFrameMsg.EvMessage = PackageIdCmd(EvFrameMsg.EvMessage);
+
+	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(EvFrameMsg, data, 7);
+}
+
+void GetMiscellaneousInfo(byte gun_index, byte relayStatus, float power, float voltage, byte toId)
+{
+	EvFrame EvFrameMsg;
+
+	EvFrameMsg.EvMessage = 0;
+	EvFrameMsg.EvBdBits.SlaveAddress = toId;
+	EvFrameMsg.EvBdBits.MessageID = EV_Command_GetMiscellaneous;
+	EvFrameMsg.EvMessage = PackageIdCmd(EvFrameMsg.EvMessage);
+
+	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(EvFrameMsg, data, 5);
+}
+
+void SetIsolationStatus(byte gun_index, byte result, byte toId)
+{
+	EvFrame EvFrameMsg;
+
+	EvFrameMsg.EvMessage = 0;
+	EvFrameMsg.EvBdBits.SlaveAddress = toId;
+	EvFrameMsg.EvBdBits.MessageID = EV_Command_IsolationStatus;
+	EvFrameMsg.EvMessage = PackageIdCmd(EvFrameMsg.EvMessage);
+
+	byte data[8];
+
+	data[0] = result;
+	SendCmdToEvboard(EvFrameMsg, data, 1);
+}
+
+void SetEvsePrechargeInfo(byte gun_index, byte result, byte toId)
+{
+	EvFrame EvFrameMsg;
+
+	EvFrameMsg.EvMessage = 0;
+	EvFrameMsg.EvBdBits.SlaveAddress = toId;
+	EvFrameMsg.EvBdBits.MessageID = EV_Command_EvsePrechargeInfo;
+	EvFrameMsg.EvMessage = PackageIdCmd(EvFrameMsg.EvMessage);
+
+	byte data[8];
+
+	data[0] = result;
+	SendCmdToEvboard(EvFrameMsg, data, 1);
+}
+

BIN
EVSE/Projects/NoodoeDS/Apps/FactoryConfig


+ 421 - 0
EVSE/Projects/NoodoeDS/Apps/FactoryConfig.c

@@ -0,0 +1,421 @@
+#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/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 	<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
+#define EQUAL				0
+
+struct SysConfigData 			SysConfig;
+
+int StoreLogMsg(const char *fmt, ...);
+
+int StoreLogMsg(const char *fmt, ...)
+{
+	char Buf[4096+256];
+	char buffer[4096];
+	va_list args;
+	struct timeb  SeqEndTime;
+	struct tm *tm;
+
+	va_start(args, fmt);
+	int rc = vsnprintf(buffer, sizeof(buffer), fmt, args);
+	va_end(args);
+
+	memset(Buf,0,sizeof(Buf));
+	ftime(&SeqEndTime);
+	SeqEndTime.time = time(NULL);
+	tm=localtime(&SeqEndTime.time);
+
+	sprintf(Buf,"echo \"%04d-%02d-%02d %02d:%02d:%02d:%03d - %s\" >> /Storage/SystemLog/[%04d.%02d]SystemLog",
+			tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,SeqEndTime.millitm,
+			buffer,
+			tm->tm_year+1900,tm->tm_mon+1);
+	system(Buf);
+
+	return rc;
+}
+
+void 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");
+}
+
+int runShellCmd(const char*cmd)
+{
+	int result = FAIL;
+	char buf[256];
+	FILE *fp;
+
+	fp = popen(cmd, "r");
+	if(fp != NULL)
+	{
+		while(fgets(buf, sizeof(buf), fp) != NULL)
+		{
+			StoreLogMsg("%s\n", buf);
+		}
+
+		result = PASS;
+	}
+	pclose(fp);
+
+	return result;
+}
+
+void CustomChange(char *custom)
+{
+	if (strcmp(custom, "C0") == EQUAL)
+	{
+		// Bosch
+		SysConfig.AuthorisationMode = AUTH_MODE_DISABLE;
+		SysConfig.isRFID = 0;
+	}
+	else if (strcmp(custom, "N0") == EQUAL ||
+				strcmp(custom, "N1") == EQUAL)
+	{
+		// Noodoe (Shell)
+		SysConfig.isAPP = 0;
+	}
+	else if (strcmp(custom, "CL") == EQUAL)
+	{
+		// ChargeLab
+		SysConfig.AuthorisationMode = AUTH_MODE_ENABLE;
+		SysConfig.RfidCardNumEndian = RFID_ENDIAN_BIG;
+		strcpy((char *) SysConfig.OcppServerURL, "wss://ocpp.io");
+		sprintf((char *) SysConfig.ChargeBoxId, "%s%s", SysConfig.ModelName, SysConfig.SerialNumber);
+
+		strcpy((char *) SysConfig.TelecomInterface.TelcomApn, "m2minternet.apn");
+
+		strcpy((char *) SysConfig.AthInterface.WifiSsid, "ChargeLab-EVC");
+		strcpy((char *) SysConfig.AthInterface.WifiPassword, "evc-pwd-default-21");
+
+		SysConfig.OfflinePolicy = _OFFLINE_POLICY_LOCAL_LIST;
+		strcpy((char *)SysConfig.chargePointVendor, "ChargeLab");
+
+		SysConfig.AthInterface.WifiMode = 1;
+		SysConfig.TelecomInterface.TelcomEnabled = 1;
+	}
+}
+
+/**************************************************************************************/
+/************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 int MtdBlockSize = 0x300000;
+	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
+	//
+	if (argc == 4)
+	{
+		strcpy((char *)SysConfig.ModelName, argv[2]);
+		strcpy((char *)SysConfig.SerialNumber, argv[3]);
+	}
+	else
+	{
+		strcpy((char *)SysConfig.ModelName, "DSYE301E00D2PH");
+		strcpy((char *)SysConfig.SerialNumber, "NeedSetupSN");
+	}
+
+	memset(SysConfig.SystemId, 0x00, sizeof(SysConfig.SystemId));
+
+	strcat((char *)SysConfig.SystemId, (char *)SysConfig.ModelName);
+	strcat((char *)SysConfig.SystemId, (char *)SysConfig.SerialNumber);
+
+	strcpy((char *)SysConfig.SystemDateTime, "");
+	SysConfig.AuthorisationMode = AUTH_MODE_ENABLE;
+	SysConfig.DefaultLanguage = 0;
+	SysConfig.RfidCardNumEndian = RFID_ENDIAN_LITTLE;
+	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 = 200;		// 最大可輸出電流 (整樁)
+	SysConfig.MaxChargingDuration = 0;
+	SysConfig.AcMaxChargingCurrent = 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.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");
+//	if(SysConfig.ModelName[10] == 'W' || SysConfig.ModelName[10] == 'D')
+//		SysConfig.AthInterface.WifiMode = 2;
+//	else
+//		SysConfig.AthInterface.WifiMode = 0;
+	SysConfig.AthInterface.WifiMode = 0;
+	SysConfig.TelecomInterface.TelcomEnabled = 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 = _OFFLINE_POLICY_FREE_CHARGING;
+	SysConfig.OfflineMaxChargeEnergy = 0;
+	SysConfig.OfflineMaxChargeDuration = 0;
+	strcpy((char *) SysConfig.OcppServerURL, "");
+	strcpy((char *) SysConfig.ChargeBoxId, "");
+	strcpy((char *) SysConfig.MaintainServerURL, "wss://ocpp.phihong.com.tw:2013/");
+	SysConfig.LedInfo.Intensity = 2;
+
+	// ********** 客製化 ********** //
+	char _buf[3] = {0};
+	memcpy(_buf, &SysConfig.ModelName[12], 2);
+
+	CustomChange(_buf);
+
+	//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);
+//	}
+	for(i = ARRAY_SIZE(SysConfig.CsuBootLoadFwRev); 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);
+		fd = open("/mnt/FactoryDefaultConfig.bin", O_RDWR | O_CREAT | O_TRUNC);
+		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)
+		{
+			StoreLogMsg("Erase /dev/mtd10.\n");
+			runShellCmd("flash_erase /dev/mtd10 0 0");
+			StoreLogMsg("Write /dev/mtd10.\n");
+			runShellCmd("nandwrite -p /dev/mtd10 /mnt/FactoryDefaultConfig.bin");
+
+			StoreLogMsg("Erase /dev/mtd11.\n");
+			runShellCmd("flash_erase /dev/mtd11 0 0");
+			StoreLogMsg("Write /dev/mtd11.\n");
+			runShellCmd("nandwrite -p /dev/mtd11 /mnt/FactoryDefaultConfig.bin");
+
+			StoreLogMsg("Erase /dev/mtd12.\n");
+			runShellCmd("flash_erase /dev/mtd12 0 0");
+			StoreLogMsg("Write /dev/mtd12.\n");
+			runShellCmd("nandwrite -p /dev/mtd12 /mnt/FactoryDefaultConfig.bin");
+
+			system("rm -f /mnt/FactoryDefaultConfig.bin");
+
+			StoreLogMsg("FactoryConfig write to flash OK\n");
+		}
+		free(ptr);
+	}
+
+	/*
+	* 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;
+}
+

+ 101 - 0
EVSE/Projects/NoodoeDS/Apps/Makefile

@@ -0,0 +1,101 @@
+-include ../../../../Rules.make
+export PATH=/bin:/sbin:/usr/bin:$(SDK_PATH_TARGET)/usr/bin:$PATH
+
+#define library variable
+Internal485ProtocolLib = -L ../../../Modularization/Internal485Protocol -lInternal485Protocol
+#PsuCommProtocolLib = -L ../../../Modularization/PsuCommProtocol -lPsuCommProtocol
+
+#define library variable
+Lib_Module_RFID = "-L../../../Modularization" -lModule_RFID
+Lib_Module_Upgrade = "-L../../../Modularization" -lModule_Upgrade
+Lib_SQLite3 = "-L../../../Modularization/ocppfiles" -lsqlite3
+
+all: CopyFile apps
+#apps: Module_CSU Module_EvComm Module_EventLogging Module_InternalComm Module_LcmControl Module_PrimaryComm Module_PsuComm 
+# ReadCmdline kill.sh
+apps: MainTask EvCommTask EventLoggingTask InternalCommTask LcmControlTask PrimaryCommTask PsuCommTask ReadCmdlineTask UnsafetyOutputTool FactoryConfigApp OtherTools
+
+MainTask:
+	rm -f *.o
+	rm -f main;
+	$(CC) -D $(Project) -include../../../Modularization/ocppfiles/sqlite3.h -include../../../Modularization/Module_Upgrade.h -include../../../Modularization/Module_RFID.h -O0 -g3 -Wall -c -fmessage-length=0 -o main.o main.c
+	$(CC) -D $(Project) -include../../../Modularization/ocppfiles/sqlite3.h -include../../../Modularization/Module_Upgrade.h -include../../../Modularization/Module_RFID.h -O0 -g3 -Wall -c -fmessage-length=0 -o CheckSystemTask.o CheckSystemTask.c
+	$(CC) -D $(Project) -include../../../Modularization/ocppfiles/sqlite3.h -include../../../Modularization/Module_Upgrade.h -include../../../Modularization/Module_RFID.h -O0 -g3 -Wall -c -fmessage-length=0 -o timeout.o timeout.c
+	$(CC) -lrt -o main main.o CheckSystemTask.o timeout.o ${Lib_Module_RFID} ${Lib_Module_Upgrade} ${Lib_SQLite3}	
+	cp -f main ../Images/root
+
+EvCommTask:
+	rm -f Module_EvComm;
+	$(CC) -D $(Project) -includeConfig.h -O0 -g3 -Wall -c -fmessage-length=0 -o Ev_Comm.o Ev_Comm.c
+	$(CC) -D $(Project) -includeConfig.h -O0 -g3 -Wall -c -fmessage-length=0 -o Module_EvComm.o Module_EvComm.c
+	$(CC) -lrt -o Module_EvComm Ev_Comm.o Module_EvComm.o
+	cp -f Module_EvComm ../Images/root	
+	
+EventLoggingTask:
+	rm -f Module_EventLogging;
+	$(CC) -D $(Project) -include../../../Modularization/ocppfiles/sqlite3.h -includeConfig.h -O0 -g3 -Wall -c -fmessage-length=0 -o Module_EventLogging.o Module_EventLogging.c
+	$(CC) -lrt -o Module_EventLogging Module_EventLogging.o ${Lib_SQLite3}	
+	cp -f Module_EventLogging ../Images/root	
+	
+InternalCommTask:
+	rm -f Module_InternalComm; 
+	$(CC) -D $(Project) -includeConfig.h -O0 -g3 -Wall -c -fmessage-length=0 -o internalComm.o internalComm.c
+	$(CC) -D $(Project) -includeConfig.h -O0 -g3 -Wall -c -fmessage-length=0 -o Module_InternalComm.o Module_InternalComm.c
+	$(CC) -lrt -o Module_InternalComm Module_InternalComm.o internalComm.o 	
+	cp -f Module_InternalComm ../Images/root
+	
+LcmControlTask:
+	rm -f Module_LcmControl; 
+	$(CC) -D $(Project) -includeConfig.h -O0 -g3 -Wall -c -fmessage-length=0 -o Module_LcmControl.o Module_LcmControl.c
+	$(CC) -lrt -o Module_LcmControl Module_LcmControl.o
+	cp -f Module_LcmControl ../Images/root			
+
+PrimaryCommTask:
+	rm -f Module_PrimaryComm; 
+	$(CC) -D $(Project) -includeConfig.h -O0 -g3 -Wall -c -fmessage-length=0 -o Module_PrimaryComm.o Module_PrimaryComm.c
+	$(CC) -D $(Project) -includeConfig.h -O0 -g3 -Wall -c -fmessage-length=0 -o PrimaryComm.o PrimaryComm.c
+	$(CC) -lrt -o Module_PrimaryComm Module_PrimaryComm.o PrimaryComm.o
+	cp -f Module_PrimaryComm ../Images/root	
+
+PsuCommTask:
+	rm -f Module_PsuComm; 
+	$(CC) -D $(Project) -include../../../Modularization/Infypwr_PsuCommObj.h -includeConfig.h -O0 -g3 -Wall -c -fmessage-length=0 -o Module_PsuComm.o Module_PsuComm.c
+	$(CC) -lrt -o Module_PsuComm Module_PsuComm.o ../../../Modularization/libInfypwr_PsuCommObj.a
+	cp -f Module_PsuComm ../Images/root	
+	
+ReadCmdlineTask:
+	rm -f ReadCmdline; 
+	$(CC) -D $(Project) -includeConfig.h -O0 -g3 -Wall -c -fmessage-length=0 -o ReadCmdline.o ReadCmdline.c
+	$(CC) -lrt -o ReadCmdline ReadCmdline.o
+	cp -f ReadCmdline ../Images/root
+
+UnsafetyOutputTool:
+	rm -f UnsafetyOutputTask; 
+	$(CC) -D $(Project) -include../../../Modularization/Infypwr_PsuCommObj.h -O0 -g3 -Wall -c -fmessage-length=0 -o OutputTask.o OutputTask.c
+	$(CC) -lrt -o UnsafetyOutputTask OutputTask.o ../../../Modularization/libInfypwr_PsuCommObj.a
+	cp -f UnsafetyOutputTask ../Images/root	
+
+FactoryConfigApp:
+	@echo "===== Module_FactoryConfig_Task =================================="
+	rm -f FactoryConfig
+	gcc -D $(Project) "-I../../" -o FactoryConfig "./FactoryConfig.c"
+	mkdir -p /Storage/SystemLog	
+	./FactoryConfig -f;true
+	cp /mnt/FactoryDefaultConfig.bin ../Images
+	rm -f FactoryConfig; 
+	$(CC) -D $(Project) -O0 -g3 -Wall -c -fmessage-length=0 -o FactoryConfig.o FactoryConfig.c 
+	$(CC) -lrt -o FactoryConfig FactoryConfig.o 
+	cp -f FactoryConfig ../Images/root
+
+OtherTools:
+	cp -f init.sh ../Images/root
+	cp -f kill.sh ../Images/root
+	cp -f web.sh ../Images/root
+
+CopyFile: 
+	rm -rfv ../Images/root
+	mkdir -p ../Images/root
+
+
+
+	

BIN
EVSE/Projects/NoodoeDS/Apps/Module_EvComm


+ 4595 - 0
EVSE/Projects/NoodoeDS/Apps/Module_EvComm.c

@@ -0,0 +1,4595 @@
+#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/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 	<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 STOP				0
+#define START				1
+#define COMMUNICATION		2
+#define INITIALIZATION		3
+#define YES					1
+#define NO					0
+#define EQUAL				0
+#define CHK_VOL_RANGE		50
+#define CHK_CUR_RANGE		20
+#define PLUG				1
+#define UNPLUG				0
+#define UNDEFINED_TEMP		255
+#define ALLOW_COUNT_MAX		30
+#define VOUT_MIN_VOLTAGE	150
+#define CURR_MIN_CURRENT	0
+
+struct SysConfigAndInfo			*ShmSysConfigAndInfo;
+struct StatusCodeData 			*ShmStatusCodeData;
+struct FanModuleData			*ShmFanModuleData;
+struct CHAdeMOData				*ShmCHAdeMOData;
+struct GBTData					*ShmGBTData;
+struct CcsData					*ShmCcsData;
+struct PsuData 					*ShmPsuData;
+struct MeterInformation			*ShmCsuMeterData;
+struct DcCommonInformation		*ShmDcCommonData;
+
+byte gun_count;
+int chargingTime[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
+byte rtcChkCount = 0;
+bool printLogRecord;
+
+float LogInfo[2][10];
+bool _useOfflineNoCharging = false;
+
+// 限制最大充電電壓,因應不同 type 槍線來限制
+double Chademo_Simple = 5000;
+double GB_Simple = 7500;
+double CCS_Simple = 7500;
+// ---------------------------------------
+double Chademo_Standard= 5000;
+double GB_Standard = 7500;
+double CCS_Standard = 9500;
+
+//float maxChargingVol[2] = { 0, 0 };			// 限制最大充電電壓,如依照模塊則填上 0
+// 限制最大充電電流與能量透過 Web
+//float maxChargingCur[2] = { 0, 0 };			// 限制最大充電電流,如依照模塊則填上 0
+float maxChargingPow = 0;					// 限制最大充電能量,如依照模塊則填上 0
+
+// 允許當前輸出與需求落差超過 10A 的累積次數 (超過 ALLOW_COUNT_MAX 即給予當前值)
+byte curAllowCount[2] = { 0, 0 };
+float curTargetCur[2] = { 0, 0 };
+
+// 避免槍溫偵測誤判
+byte gunTempAllowCount[2] = {0, 0};
+
+// 槍資訊
+struct ChargingInfoData *_chargingData[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
+struct timespec _chk_ratingPower_timeout[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
+struct timespec _chk_chademo_permission_timeout[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
+bool chkChademoPermission[2] = { false, false };
+bool chkChademoPermissionSend[2] = { false, false };
+byte SendErrorCount[2] = { 0, 0};
+struct timespec delayToPrintLogTimeout;
+
+unsigned char mask_table[] = { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 };
+
+void PRINTF_FUNC(char *string, ...);
+
+void GetMaxVolAndCurMethod(byte index, float *vol, float *cur);
+void GetMaxPowerMethod(byte index, float *pow);
+int GetTimeoutValue(struct timespec *startTime);
+
+#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)
+
+int GetTimeoutValue(struct timespec *startTime)
+{
+	struct timespec endTime;
+
+	clock_gettime(CLOCK_MONOTONIC_COARSE, &endTime);
+	return endTime.tv_sec - startTime->tv_sec;
+}
+
+void GetTimespecFunc(struct timespec *time)
+{
+	clock_gettime(CLOCK_MONOTONIC_COARSE, time);
+}
+
+int StoreLogMsg(const char *fmt, ...)
+{
+	char Buf[4096+256];
+	char buffer[4096];
+	va_list args;
+	struct timeb  SeqEndTime;
+	struct tm *tm;
+
+	va_start(args, fmt);
+	int rc = vsnprintf(buffer, sizeof(buffer), fmt, args);
+	va_end(args);
+
+	memset(Buf,0,sizeof(Buf));
+	ftime(&SeqEndTime);
+	SeqEndTime.time = time(NULL);
+	tm=localtime(&SeqEndTime.time);
+
+	if (ShmSysConfigAndInfo->SysConfig.SwitchDebugFlag == YES)
+	{
+		sprintf(Buf,"%02d:%02d:%02d:%03d - %s",
+			tm->tm_hour,tm->tm_min,tm->tm_sec,SeqEndTime.millitm, buffer);
+		printf("%s \n", Buf);
+	}
+	else
+	{
+		sprintf(Buf,"echo \"%04d-%02d-%02d %02d:%02d:%02d:%03d - %s\" >> /Storage/SystemLog/[%04d.%02d]SystemLog_%s",
+			tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,SeqEndTime.millitm,
+			buffer,
+			tm->tm_year+1900,tm->tm_mon+1,
+			ShmSysConfigAndInfo->SysConfig.SerialNumber);
+		system(Buf);
+	}
+
+	return rc;
+}
+
+int DiffTimeb(struct timeb ST, struct timeb ET)
+{
+	//return milli-second
+	unsigned int StartTime,StopTime;
+
+	StartTime=(unsigned int)ST.time;
+	StopTime=(unsigned int)ET.time;
+	return (StopTime-StartTime)*1000+ET.millitm-ST.millitm;
+}
+
+void PRINTF_FUNC(char *string, ...)
+{
+	va_list args;
+	char buffer[4096];
+	va_start(args, string);
+	vsnprintf(buffer, sizeof(buffer), string, args);
+	va_end(args);
+
+	DEBUG_INFO("%s ", buffer);
+}
+
+//=================================
+// Common routine
+//=================================
+void getTimeString(char *buff)
+{
+	time_t timep;
+	struct tm *p;
+	time(&timep);
+	p=gmtime(&timep);
+
+	sprintf(buff, "[%04d-%02d-%02d %02d:%02d:%02d]", (1900+p->tm_year), (1+p->tm_mon), p->tm_mday, p->tm_hour, p->tm_hour, p->tm_sec);
+}
+
+//bool CheckUniqNumber(byte value)
+//{
+//	for (byte index = 0; index < gun_count; index++)
+//	{
+//		if (_chargingData[index]->Evboard_id == value)
+//		{
+//			struct timeval _end_time;
+//			gettimeofday(&_end_time, NULL);
+//			unsigned long diff = 1000000 *	(_end_time.tv_sec - _id_assign_time.tv_sec) + _end_time.tv_usec - _id_assign_time.tv_usec;
+//			if (diff >= 3000000)
+//			{
+//				gettimeofday(&_id_assign_time, NULL);
+//				return true;
+//			}
+//			else
+//			{
+//				return false;
+//			}
+//		}
+//	}
+//
+//	gettimeofday(&_id_assign_time, NULL);
+//	return true;
+//}
+
+//==========================================
+// Init all share memory
+//==========================================
+int InitShareMemory()
+{
+	int result = PASS;
+	int MeterSMId;
+
+	//initial ShmSysConfigAndInfo
+	if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo),  0777)) < 0)
+    {
+		#ifdef SystemLogMessage
+		DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
+		#endif
+		result = FAIL;
+	}
+    else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
+    {
+    	#ifdef SystemLogMessage
+    	DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
+		#endif
+    	result = FAIL;
+   	}
+
+   	//initial ShmStatusCodeData
+   	if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData),  0777)) < 0)
+    {
+		#ifdef SystemLogMessage
+   		DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
+		#endif
+   		result = FAIL;
+	}
+    else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
+    {
+    	#ifdef SystemLogMessage
+    	DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
+		#endif
+    	result = FAIL;
+   	}
+
+ 	//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;
+ 	}
+
+   	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;
+   		}
+   	}
+	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;
+	   	}
+	}
+
+   	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;
+   		}
+   	}
+
+   	if ((MeterSMId = shmget(ShmCsuMeterKey, sizeof(struct MeterInformation), IPC_CREAT | 0777)) < 0)
+   	{
+   		#ifdef SystemLogMessage
+   		DEBUG_ERROR("shmget ShmCsuMeterKey NG \n");
+   		#endif
+   		return 0;
+   	}
+   	else if ((ShmCsuMeterData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
+   	{
+   		#ifdef SystemLogMessage
+   		DEBUG_ERROR("shmat ShmCsuMeterData NG \n");
+   		#endif
+   		return 0;
+   	}
+
+   	if ((MeterSMId = shmget(ShmCommonKey, sizeof(struct DcCommonInformation), IPC_CREAT | 0777)) < 0)
+   	{
+   		#ifdef SystemLogMessage
+   		DEBUG_ERROR("shmget ShmCommonKey NG \n");
+   		#endif
+   		return 0;
+   	}
+   	else if ((ShmDcCommonData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
+   	{
+   		#ifdef SystemLogMessage
+   		DEBUG_ERROR("shmat ShmCommonKey NG \n");
+   		#endif
+   		return 0;
+   	}
+
+    return result;
+}
+
+//================================================
+// initial can-bus
+//================================================
+int InitCanBus()
+{
+	int 					s0,nbytes;
+	struct timeval			tv;
+	struct ifreq 			ifr0;
+	struct sockaddr_can		addr0;
+
+	system("/sbin/ip link set can0 down");
+	system("/sbin/ip link set can0 type can bitrate 500000 restart-ms 100");
+	system("/sbin/ip link set can0 up");
+
+	s0 = socket(PF_CAN, SOCK_RAW, CAN_RAW);
+
+	tv.tv_sec = 0;
+	tv.tv_usec = 10000;
+   	if (setsockopt(s0, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv, sizeof(struct	timeval)) < 0)
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR("Set SO_RCVTIMEO NG");
+		#endif
+	}
+	nbytes=40960;
+	if (setsockopt(s0, SOL_SOCKET,  SO_RCVBUF, &nbytes, sizeof(int)) < 0)
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR("Set SO_RCVBUF NG");
+		#endif
+	}
+	nbytes=40960;
+	if (setsockopt(s0, SOL_SOCKET, SO_SNDBUF, &nbytes, sizeof(int)) < 0)
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR("Set SO_SNDBUF NG");
+		#endif
+	}
+
+   	strcpy(ifr0.ifr_name, "can0" );
+	ioctl(s0, SIOCGIFINDEX, &ifr0); /* ifr.ifr_ifindex gets filled with that device's index */
+	addr0.can_family = AF_CAN;
+	addr0.can_ifindex = ifr0.ifr_ifindex;
+	bind(s0, (struct sockaddr *)&addr0, sizeof(addr0));
+	return s0;
+}
+
+//================================================
+//================================================
+// CANBUS receive task
+//================================================
+//================================================
+bool FindChargingInfoData(byte target, struct ChargingInfoData **chargingData)
+{
+	for (byte index = 0; index < CHAdeMO_QUANTITY; index++)
+	{
+		if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == target)
+		{
+			chargingData[target] = &ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index];
+			return true;
+		}
+	}
+
+	for (byte index = 0; index < CCS_QUANTITY; index++)
+	{
+		if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == target)
+		{
+			chargingData[target] = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[index];
+			return true;
+		}
+	}
+
+	for (byte index = 0; index < GB_QUANTITY; index++)
+	{
+		if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == target)
+		{
+			chargingData[target] = &ShmSysConfigAndInfo->SysInfo.GbChargingData[index];
+			return true;
+		}
+	}
+
+	return false;
+}
+
+void AddrAssignment(byte *data)
+{
+	byte target_number[8];
+	byte index = 0x00;
+
+	memcpy(target_number, data, sizeof(target_number));
+	index = *(data + 4);
+
+	if (gun_count == 1)
+		index = 0x01;
+//	if (CheckUniqNumber(index))
+	{
+		if (_chargingData[index - 1]->Type == _Type_Chademo)
+			PRINTF_FUNC("Set EV board info : (Chademo) TargetAddr = %d \n", index);
+		else if (_chargingData[index - 1]->Type == _Type_CCS)
+			PRINTF_FUNC("Set EV board info : (CCS) TargetAddr = %d \n", index);
+		else if (_chargingData[index - 1]->Type == _Type_GB)
+			PRINTF_FUNC("Set EV board info : (GB) TargetAddr = %d \n", index);
+
+		SetTargetAddr(target_number, index);
+	}
+}
+
+void ClearAbnormalStatus_Chademo(byte gun_index)
+{
+	bool isCleanCheck = false;
+	char code[7];
+
+	if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "", 6) == EQUAL)
+		return;
+
+	if (true)
+	{
+		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;
+		}
+		else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023980", 6) == EQUAL &&
+				ShmStatusCodeData->InfoCode.InfoEvents.bits.CHADEMO_BMS_CHARGE_ALLOW_ERROR == YES)
+		{
+			memcpy(code, "023980", 6);
+			memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
+			isCleanCheck = true;
+		}
+		else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023981", 6) == EQUAL &&
+				ShmStatusCodeData->InfoCode.InfoEvents.bits.CHADEMO_OUTPUT_VOLTAGE_MORE_THEN_10_PERCENT == YES)
+		{
+			memcpy(code, "023981", 6);
+			memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
+			isCleanCheck = true;
+		}
+
+		else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023982", 6) == EQUAL &&
+				ShmStatusCodeData->InfoCode.InfoEvents.bits.CHADEMO_ADC_LESS_THAN_10V == YES)
+		{
+			memcpy(code, "023982", 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;
+					if (strncmp(code, "023980", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CHADEMO_BMS_CHARGE_ALLOW_ERROR = NO;
+					if (strncmp(code, "023981", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CHADEMO_OUTPUT_VOLTAGE_MORE_THEN_10_PERCENT = NO;
+					if (strncmp(code, "023982", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CHADEMO_ADC_LESS_THAN_10V = NO;
+				}
+			}
+		}
+	}
+}
+
+void ClearAbnormalStatus_GB(byte gun_index)
+{
+	bool isCleanCheck = false;
+	char code[7];
+
+	if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "", 6) == EQUAL)
+		return;
+
+	if (true)
+	{
+		if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023702", 6) == EQUAL &&
+				ShmStatusCodeData->InfoCode.InfoEvents.bits.GbEvCommFail == YES)
+		{
+			memcpy(code, "023702", 6);
+			memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
+			isCleanCheck = true;
+		}
+		else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023900", 6) == EQUAL &&
+				ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_LOS_CC1 == YES)
+		{
+			memcpy(code, "023900", 6);
+			memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
+			isCleanCheck = true;
+		}
+		else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023901", 6) == EQUAL &&
+				ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_CONNECTOR_LOCK_FAIL == YES)
+		{
+			memcpy(code, "023901", 6);
+			memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
+			isCleanCheck = true;
+		}
+		else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023902", 6) == EQUAL &&
+				ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_BATTERY_INCOMPATIBLE == YES)
+		{
+			memcpy(code, "023902", 6);
+			memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
+			isCleanCheck = true;
+		}
+		else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023903", 6) == EQUAL &&
+				ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_BMS_BROAA_TIMEOUT == YES)
+		{
+			memcpy(code, "023903", 6);
+			memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
+			isCleanCheck = true;
+		}
+		else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023904", 6) == EQUAL &&
+				ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_CSU_PRECHARGE_TIMEOUT == YES)
+		{
+			memcpy(code, "023904", 6);
+			memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
+			isCleanCheck = true;
+		}
+		else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023905", 6) == EQUAL &&
+				ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_BMS_PRESENT_VOLTAGE_FAULT == YES)
+		{
+			memcpy(code, "023905", 6);
+			memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
+			isCleanCheck = true;
+		}
+		else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023906", 6) == EQUAL &&
+				ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_BMS_VOLTAGE_OVER_RANGE == YES)
+		{
+			memcpy(code, "023906", 6);
+			memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
+			isCleanCheck = true;
+		}
+		else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023907", 6) == EQUAL &&
+				ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_BSM_CHARGE_ALLOW_00_10MIN_COUUNTDONE == YES)
+		{
+			memcpy(code, "023907", 6);
+			memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
+			isCleanCheck = true;
+		}
+		else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023908", 6) == EQUAL &&
+				ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_WAIT_GROUNDFAULT_TIMEOUT == YES)
+		{
+			memcpy(code, "023908", 6);
+			memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
+			isCleanCheck = true;
+		}
+		else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023909", 6) == EQUAL &&
+				ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_ADC_MORE_THAN_10V == YES)
+		{
+			memcpy(code, "023909", 6);
+			memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
+			isCleanCheck = true;
+		}
+		else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023910", 6) == EQUAL &&
+				ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_ADC_MORE_THAN_60V == YES)
+		{
+			memcpy(code, "023910", 6);
+			memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
+			isCleanCheck = true;
+		}
+		else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023911", 6) == EQUAL &&
+				ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_CHARGER_GET_NORMAL_STOP_CMD == YES)
+		{
+			memcpy(code, "023911", 6);
+			memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
+			isCleanCheck = true;
+		}
+		else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023912", 6) == EQUAL &&
+				ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_CHARGER_GET_EMERGENCY_STOP_CMD == YES)
+		{
+			memcpy(code, "023912", 6);
+			memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
+			isCleanCheck = true;
+		}
+		else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023913", 6) == EQUAL &&
+				ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_ISOLATION_RESULT_FAIL == YES)
+		{
+			memcpy(code, "023913", 6);
+			memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
+			isCleanCheck = true;
+		}
+		else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023914", 6) == EQUAL &&
+				ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_MOTHER_BOARD_MISS_LINK == YES)
+		{
+			memcpy(code, "023914", 6);
+			memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
+			isCleanCheck = true;
+		}
+		else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023915", 6) == EQUAL &&
+				ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_OUTPUT_VOLTAGE_MORE_THAN_LIMIT == YES)
+		{
+			memcpy(code, "023915", 6);
+			memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
+			isCleanCheck = true;
+		}
+		else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023916", 6) == EQUAL &&
+				ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_REQ_CURRENT_MORE_THAN_LIMIT == YES)
+		{
+			memcpy(code, "023916", 6);
+			memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
+			isCleanCheck = true;
+		}
+		else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023917", 6) == EQUAL &&
+				ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_OUTPUT_VOLTAGE_MORE_THAN_10_PERCENT == YES)
+		{
+			memcpy(code, "023917", 6);
+			memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
+			isCleanCheck = true;
+		}
+		else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023918", 6) == EQUAL &&
+				ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_OUTPUT_VOLTAGE_DIFF_BCS_5_PERCENT == YES)
+		{
+			memcpy(code, "023918", 6);
+			memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
+			isCleanCheck = true;
+		}
+		else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023919", 6) == EQUAL &&
+				ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_STOP_ADC_MORE_THAN_10V == YES)
+		{
+			memcpy(code, "023919", 6);
+			memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
+			isCleanCheck = true;
+		}
+		else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023930", 6) == EQUAL &&
+				ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_CEM_BHM_TIMEOUT == YES)
+		{
+			memcpy(code, "023930", 6);
+			memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
+			isCleanCheck = true;
+		}
+		else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023931", 6) == EQUAL &&
+				ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_CEM_BRM_TIMEOUT == YES)
+		{
+			memcpy(code, "023931", 6);
+			memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
+			isCleanCheck = true;
+		}
+		else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023932", 6) == EQUAL &&
+				ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_CEM_BCP_TIMEOUT == YES)
+		{
+			memcpy(code, "023932", 6);
+			memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
+			isCleanCheck = true;
+		}
+		else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023933", 6) == EQUAL &&
+				ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_CEM_BRO_TIMEOUT == YES)
+		{
+			memcpy(code, "023933", 6);
+			memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
+			isCleanCheck = true;
+		}
+		else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023934", 6) == EQUAL &&
+				ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_CEM_BCL_TIMEOUT == YES)
+		{
+			memcpy(code, "023934", 6);
+			memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
+			isCleanCheck = true;
+		}
+		else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023935", 6) == EQUAL &&
+				ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_CEM_BCS_TIMEOUT == YES)
+		{
+			memcpy(code, "023935", 6);
+			memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
+			isCleanCheck = true;
+		}
+		else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023936", 6) == EQUAL &&
+				ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_CEM_BSM_TIMEOUT == YES)
+		{
+			memcpy(code, "023936", 6);
+			memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
+			isCleanCheck = true;
+		}
+		else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023937", 6) == EQUAL &&
+				ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_CEM_BST_TIMEOUT == YES)
+		{
+			memcpy(code, "023937", 6);
+			memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
+			isCleanCheck = true;
+		}
+		else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023938", 6) == EQUAL &&
+				ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_CEM_BSD_TIMEOUT == YES)
+		{
+			memcpy(code, "023938", 6);
+			memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
+			isCleanCheck = true;
+		}
+		else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023939", 6) == EQUAL &&
+				ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_CEM_BEM_OTHER_TIMEOUT == YES)
+		{
+			memcpy(code, "023939", 6);
+			memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
+			isCleanCheck = true;
+		}
+		else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023940", 6) == EQUAL &&
+				ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BEM_CRM_TIMEOUT == YES)
+		{
+			memcpy(code, "023940", 6);
+			memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
+			isCleanCheck = true;
+		}
+		else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023941", 6) == EQUAL &&
+				ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BEM_CRMAA_TIMEOUT == YES)
+		{
+			memcpy(code, "023941", 6);
+			memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
+			isCleanCheck = true;
+		}
+		else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023942", 6) == EQUAL &&
+				ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BEM_CTS_CML_TIMEOUT == YES)
+		{
+			memcpy(code, "023942", 6);
+			memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
+			isCleanCheck = true;
+		}
+		else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023943", 6) == EQUAL &&
+				ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BEM_CRO_TIMEOUT == YES)
+		{
+			memcpy(code, "023943", 6);
+			memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
+			isCleanCheck = true;
+		}
+		else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023944", 6) == EQUAL &&
+				ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BEM_CCS_TIMEOUT == YES)
+		{
+			memcpy(code, "023944", 6);
+			memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
+			isCleanCheck = true;
+		}
+		else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023945", 6) == EQUAL &&
+				ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BEM_CST_TIMEOUT == YES)
+		{
+			memcpy(code, "023945", 6);
+			memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
+			isCleanCheck = true;
+		}
+		else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023946", 6) == EQUAL &&
+				ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BEM_CSD_TIMEOUT == YES)
+		{
+			memcpy(code, "023946", 6);
+			memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
+			isCleanCheck = true;
+		}
+		else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023947", 6) == EQUAL &&
+				ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BEM_BEM_OTHER_TIMEOUT == YES)
+		{
+			memcpy(code, "023947", 6);
+			memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
+			isCleanCheck = true;
+		}
+		else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023950", 6) == EQUAL &&
+				ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_SOC_GOAL == YES)
+		{
+			memcpy(code, "023950", 6);
+			memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
+			isCleanCheck = true;
+		}
+		else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023951", 6) == EQUAL &&
+				ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_TOTAL_VOLTAGE_GOAL == YES)
+		{
+			memcpy(code, "023951", 6);
+			memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
+			isCleanCheck = true;
+		}
+		else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023952", 6) == EQUAL &&
+				ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_CELL_VOLTAGE_GOAL == YES)
+		{
+			memcpy(code, "023952", 6);
+			memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
+			isCleanCheck = true;
+		}
+		else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023953", 6) == EQUAL &&
+				ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_GET_CST == YES)
+		{
+			memcpy(code, "023953", 6);
+			memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
+			isCleanCheck = true;
+		}
+		else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023954", 6) == EQUAL &&
+				ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_ISOLATION == YES)
+		{
+			memcpy(code, "023954", 6);
+			memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
+			isCleanCheck = true;
+		}
+		else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023955", 6) == EQUAL &&
+				ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_OUTPUT_CONNECTOR_OTP == YES)
+		{
+			memcpy(code, "023955", 6);
+			memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
+			isCleanCheck = true;
+		}
+		else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023956", 6) == EQUAL &&
+				ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_COMPONENT == YES)
+		{
+			memcpy(code, "023956", 6);
+			memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
+			isCleanCheck = true;
+		}
+		else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023957", 6) == EQUAL &&
+				ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_CHARGE_CONNECTOR == YES)
+		{
+			memcpy(code, "023957", 6);
+			memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
+			isCleanCheck = true;
+		}
+		else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023958", 6) == EQUAL &&
+				ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_OTP == YES)
+		{
+			memcpy(code, "023958", 6);
+			memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
+			isCleanCheck = true;
+		}
+		else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023959", 6) == EQUAL &&
+				ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_OTHER == YES)
+		{
+			memcpy(code, "023959", 6);
+			memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
+			isCleanCheck = true;
+		}
+		else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023960", 6) == EQUAL &&
+				ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_HIGH_V == YES)
+		{
+			memcpy(code, "023960", 6);
+			memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
+			isCleanCheck = true;
+		}
+		else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023961", 6) == EQUAL &&
+				ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_CC2 == YES)
+		{
+			memcpy(code, "023961", 6);
+			memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
+			isCleanCheck = true;
+		}
+		else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023962", 6) == EQUAL &&
+				ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_CURRENT == YES)
+		{
+			memcpy(code, "023962", 6);
+			memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
+			isCleanCheck = true;
+		}
+		else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023963", 6) == EQUAL &&
+				ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_VOLTAGE == YES)
+		{
+			memcpy(code, "023963", 6);
+			memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
+			isCleanCheck = true;
+		}
+		else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023964", 6) == EQUAL &&
+				ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GET_BST_NO_REASON == YES)
+		{
+			memcpy(code, "023964", 6);
+			memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
+			isCleanCheck = true;
+		}
+		else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023970", 6) == EQUAL &&
+				ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BSM_CELL_OVER_VOLTAGE == YES)
+		{
+			memcpy(code, "023970", 6);
+			memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
+			isCleanCheck = true;
+		}
+		else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023971", 6) == EQUAL &&
+				ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BSM_CELL_UNDER_VOLTAGE == YES)
+		{
+			memcpy(code, "023971", 6);
+			memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
+			isCleanCheck = true;
+		}
+		else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023972", 6) == EQUAL &&
+				ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BSM_OVER_SOC == YES)
+		{
+			memcpy(code, "023972", 6);
+			memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
+			isCleanCheck = true;
+		}
+		else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023973", 6) == EQUAL &&
+				ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BSM_UNDER_SOC == YES)
+		{
+			memcpy(code, "023973", 6);
+			memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
+			isCleanCheck = true;
+		}
+		else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023974", 6) == EQUAL &&
+				ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BSM_CURRENT == YES)
+		{
+			memcpy(code, "023974", 6);
+			memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
+			isCleanCheck = true;
+		}
+		else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023975", 6) == EQUAL &&
+				ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BSM_TEMPERATURE == YES)
+		{
+			memcpy(code, "023975", 6);
+			memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
+			isCleanCheck = true;
+		}
+		else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023976", 6) == EQUAL &&
+				ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BSM_ISOLATE == YES)
+		{
+			memcpy(code, "023976", 6);
+			memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
+			isCleanCheck = true;
+		}
+		else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023977", 6) == EQUAL &&
+				ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BSM_OUTPUT_CONNECTOR == YES)
+		{
+			memcpy(code, "023977", 6);
+			memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
+			isCleanCheck = true;
+		}
+	}
+
+	if (isCleanCheck)
+	{
+		for (byte index = 0; index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; index++)
+		{
+			if (index != gun_index || ShmSysConfigAndInfo->SysConfig.TotalConnectorCount == 1)
+			{
+				PRINTF_FUNC("GBT clean error : index = %d, EvConnAlarmCode = %s, code = %s \n", index, _chargingData[index]->EvConnAlarmCode, code);
+				if (strncmp((char *)_chargingData[index]->EvConnAlarmCode, code, 6) != EQUAL)
+				{
+					if (strncmp(code, "023702", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.GbEvCommFail = NO;
+					if (strncmp(code, "023900", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_LOS_CC1 = NO;
+					if (strncmp(code, "023901", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_CONNECTOR_LOCK_FAIL = NO;
+					if (strncmp(code, "023902", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_BATTERY_INCOMPATIBLE = NO;
+					if (strncmp(code, "023903", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_BMS_BROAA_TIMEOUT = NO;
+					if (strncmp(code, "023904", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_CSU_PRECHARGE_TIMEOUT = NO;
+					if (strncmp(code, "023905", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_BMS_PRESENT_VOLTAGE_FAULT = NO;
+					if (strncmp(code, "023906", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_BMS_VOLTAGE_OVER_RANGE = NO;
+					if (strncmp(code, "023907", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_BSM_CHARGE_ALLOW_00_10MIN_COUUNTDONE = NO;
+					if (strncmp(code, "023908", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_WAIT_GROUNDFAULT_TIMEOUT = NO;
+					if (strncmp(code, "023909", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_ADC_MORE_THAN_10V = NO;
+					if (strncmp(code, "023910", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_ADC_MORE_THAN_60V = NO;
+					if (strncmp(code, "023911", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_CHARGER_GET_NORMAL_STOP_CMD = NO;
+					if (strncmp(code, "023912", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_CHARGER_GET_EMERGENCY_STOP_CMD = NO;
+					if (strncmp(code, "023913", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_ISOLATION_RESULT_FAIL = NO;
+					if (strncmp(code, "023914", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_MOTHER_BOARD_MISS_LINK = NO;
+					if (strncmp(code, "023915", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_OUTPUT_VOLTAGE_MORE_THAN_LIMIT = NO;
+					if (strncmp(code, "023916", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_REQ_CURRENT_MORE_THAN_LIMIT = NO;
+					if (strncmp(code, "023917", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_OUTPUT_VOLTAGE_MORE_THAN_10_PERCENT = NO;
+					if (strncmp(code, "023918", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_OUTPUT_VOLTAGE_DIFF_BCS_5_PERCENT = NO;
+					if (strncmp(code, "023919", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GBT_STOP_ADC_MORE_THAN_10V = NO;
+					if (strncmp(code, "023930", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_CEM_BHM_TIMEOUT = NO;
+					if (strncmp(code, "023931", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_CEM_BRM_TIMEOUT = NO;
+					if (strncmp(code, "023932", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_CEM_BCP_TIMEOUT = NO;
+					if (strncmp(code, "023933", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_CEM_BRO_TIMEOUT = NO;
+					if (strncmp(code, "023934", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_CEM_BCL_TIMEOUT = NO;
+					if (strncmp(code, "023935", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_CEM_BCS_TIMEOUT = NO;
+					if (strncmp(code, "023936", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_CEM_BSM_TIMEOUT = NO;
+					if (strncmp(code, "023937", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_CEM_BST_TIMEOUT = NO;
+					if (strncmp(code, "023938", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_CEM_BSD_TIMEOUT = NO;
+					if (strncmp(code, "023939", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_CEM_BEM_OTHER_TIMEOUT = NO;
+					if (strncmp(code, "023940", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BEM_CRM_TIMEOUT = NO;
+					if (strncmp(code, "023941", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BEM_CRMAA_TIMEOUT = NO;
+					if (strncmp(code, "023942", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BEM_CTS_CML_TIMEOUT = NO;
+					if (strncmp(code, "023943", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BEM_CRO_TIMEOUT = NO;
+					if (strncmp(code, "023944", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BEM_CCS_TIMEOUT = NO;
+					if (strncmp(code, "023945", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BEM_CST_TIMEOUT = NO;
+					if (strncmp(code, "023946", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BEM_CSD_TIMEOUT = NO;
+					if (strncmp(code, "023947", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BEM_BEM_OTHER_TIMEOUT = NO;
+					if (strncmp(code, "023950", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_SOC_GOAL = NO;
+					if (strncmp(code, "023951", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_TOTAL_VOLTAGE_GOAL = NO;
+					if (strncmp(code, "023952", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_CELL_VOLTAGE_GOAL = NO;
+					if (strncmp(code, "023953", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_GET_CST = NO;
+					if (strncmp(code, "023954", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_ISOLATION = NO;
+					if (strncmp(code, "023955", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_OUTPUT_CONNECTOR_OTP = NO;
+					if (strncmp(code, "023956", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_COMPONENT = NO;
+					if (strncmp(code, "023957", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_CHARGE_CONNECTOR = NO;
+					if (strncmp(code, "023958", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_OTP = NO;
+					if (strncmp(code, "023959", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_OTHER = NO;
+					if (strncmp(code, "023960", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_HIGH_V = NO;
+					if (strncmp(code, "023961", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_CC2 = NO;
+					if (strncmp(code, "023962", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_CURRENT = NO;
+					if (strncmp(code, "023963", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BST_VOLTAGE = NO;
+					if (strncmp(code, "023964", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_GET_BST_NO_REASON = NO;
+					if (strncmp(code, "023970", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BSM_CELL_OVER_VOLTAGE = NO;
+					if (strncmp(code, "023971", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BSM_CELL_UNDER_VOLTAGE = NO;
+					if (strncmp(code, "023972", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BSM_OVER_SOC = NO;
+					if (strncmp(code, "023973", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BSM_UNDER_SOC = NO;
+					if (strncmp(code, "023974", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BSM_CURRENT = NO;
+					if (strncmp(code, "023975", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BSM_TEMPERATURE = NO;
+					if (strncmp(code, "023976", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BSM_ISOLATE = NO;
+					if (strncmp(code, "023977", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.ERROR_CODE_BSM_OUTPUT_CONNECTOR = NO;
+				}
+			}
+		}
+	}
+}
+
+void ClearAbnormalStatus_CCS(byte gun_index)
+{
+	bool isCleanCheck = false;
+	char code[7];
+
+	if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "", 6) == EQUAL)
+		return;
+
+	if (true)
+	{
+		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, "023818", 6) == EQUAL &&
+				ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSeccSlacTimeoutCmMnbcSound == YES)
+		{
+			memcpy(code, "023818", 6);
+			memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
+			isCleanCheck = true;
+		}
+		else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023819", 6) == EQUAL &&
+				ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSeccSlacTimeoutCmValidateReq == YES)
+		{
+			memcpy(code, "023819", 6);
+			memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
+			isCleanCheck = true;
+		}
+		else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023823", 6) == EQUAL &&
+				ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsUDP_TT_match_join == YES)
+		{
+			memcpy(code, "023823", 6);
+			memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
+			isCleanCheck = true;
+		}
+		else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023824", 6) == EQUAL &&
+				ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTCP_TT_match_join == YES)
+		{
+			memcpy(code, "023824", 6);
+			memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
+			isCleanCheck = true;
+		}
+		else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023825", 6) == EQUAL &&
+				ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_amp_map_exchange == YES)
+		{
+			memcpy(code, "023825", 6);
+			memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
+			isCleanCheck = true;
+		}
+		else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023826", 6) == EQUAL &&
+				ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_link_ready_notification == YES)
+		{
+			memcpy(code, "023826", 6);
+			memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
+			isCleanCheck = true;
+		}
+		else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023832", 6) == EQUAL &&
+				ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSupportedAppProtocolRes == YES)
+		{
+			memcpy(code, "023832", 6);
+			memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
+			isCleanCheck = true;
+		}
+		else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023833", 6) == EQUAL &&
+				ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSessionSetupRes == YES)
+		{
+			memcpy(code, "023833", 6);
+			memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
+			isCleanCheck = true;
+		}
+		else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023834", 6) == EQUAL &&
+				ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsServiceDiscoveryRes == YES)
+		{
+			memcpy(code, "023834", 6);
+			memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
+			isCleanCheck = true;
+		}
+		else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023835", 6) == EQUAL &&
+				ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsServicePaymentSelectionRes == YES)
+		{
+			memcpy(code, "023835", 6);
+			memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
+			isCleanCheck = true;
+		}
+		else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023836", 6) == EQUAL &&
+				ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsContractAuthenticationRes == YES)
+		{
+			memcpy(code, "023836", 6);
+			memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
+			isCleanCheck = true;
+		}
+		else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023837", 6) == EQUAL &&
+				ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsChargeParameterDiscoveryRes == YES)
+		{
+			memcpy(code, "023837", 6);
+			memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
+			isCleanCheck = true;
+		}
+		else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023838", 6) == EQUAL &&
+				ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsPowerDeliveryRes == YES)
+		{
+			memcpy(code, "023838", 6);
+			memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
+			isCleanCheck = true;
+		}
+		else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023839", 6) == EQUAL &&
+				ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCableCheckRes == YES)
+		{
+			memcpy(code, "023839", 6);
+			memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
+			isCleanCheck = true;
+		}
+		else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023840", 6) == EQUAL &&
+				ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsPreChargeRes == YES)
+		{
+			memcpy(code, "023840", 6);
+			memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
+			isCleanCheck = true;
+		}
+		else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023841", 6) == EQUAL &&
+				ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCurrentDemandRes == YES)
+		{
+			memcpy(code, "023841", 6);
+			memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
+			isCleanCheck = true;
+		}
+		else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023842", 6) == EQUAL &&
+				ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsWeldingDetectionRes == YES)
+		{
+			memcpy(code, "023842", 6);
+			memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
+			isCleanCheck = true;
+		}
+		else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023843", 6) == EQUAL &&
+				ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSessionStopRes == YES)
+		{
+			memcpy(code, "023843", 6);
+			memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
+			isCleanCheck = true;
+		}
+		else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023844", 6) == EQUAL &&
+				ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSequence_Time == YES)
+		{
+			memcpy(code, "023844", 6);
+			memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
+			isCleanCheck = true;
+		}
+		else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023845", 6) == EQUAL &&
+				ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsReadyToCharge_Performance_Time == YES)
+		{
+			memcpy(code, "023845", 6);
+			memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
+			isCleanCheck = true;
+		}
+		else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023846", 6) == EQUAL &&
+				ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCommunicationSetup_Performance_Time == YES)
+		{
+			memcpy(code, "023846", 6);
+			memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
+			isCleanCheck = true;
+		}
+		else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023847", 6) == EQUAL &&
+				ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCableCheck_Performance_Time == YES)
+		{
+			memcpy(code, "023847", 6);
+			memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
+			isCleanCheck = true;
+		}
+		else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023848", 6) == EQUAL &&
+				ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCPState_Detection_Time == YES)
+		{
+			memcpy(code, "023848", 6);
+			memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
+			isCleanCheck = true;
+		}
+		else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023849", 6) == EQUAL &&
+				ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCPOscillator_Retain_Time == YES)
+		{
+			memcpy(code, "023849", 6);
+			memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
+			isCleanCheck = true;
+		}
+		else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023850", 6) == EQUAL &&
+				ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSeccTimeoutV2GPreChargePerformaceTime == YES)
+		{
+			memcpy(code, "023850", 6);
+			memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
+			isCleanCheck = true;
+		}
+		else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023855", 6) == EQUAL &&
+				ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_GET_EV_TARGET_INFO == YES)
+		{
+			memcpy(code, "023855", 6);
+			memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
+			isCleanCheck = true;
+		}
+		else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023856", 6) == EQUAL &&
+				ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_GET_EV_TARGET_INFO == YES)
+		{
+			memcpy(code, "023856", 6);
+			memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
+			isCleanCheck = true;
+		}
+		else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023857", 6) == EQUAL &&
+				ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_GET_EV_BATTERY_INFO == YES)
+		{
+			memcpy(code, "023857", 6);
+			memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
+			isCleanCheck = true;
+		}
+		else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023858", 6) == EQUAL &&
+				ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_GET_EV_BATTERY_INFO == YES)
+		{
+			memcpy(code, "023858", 6);
+			memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
+			isCleanCheck = true;
+		}
+		else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023859", 6) == EQUAL &&
+				ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_EV_STOP_EVENT == YES)
+		{
+			memcpy(code, "023859", 6);
+			memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
+			isCleanCheck = true;
+		}
+		else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023860", 6) == EQUAL &&
+				ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_EV_STOP_EVENT == YES)
+		{
+			memcpy(code, "023860", 6);
+			memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
+			isCleanCheck = true;
+		}
+		else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023861", 6) == EQUAL &&
+				ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_EVSE_STOP_EVENT == YES)
+		{
+			memcpy(code, "023861", 6);
+			memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
+			isCleanCheck = true;
+		}
+		else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023862", 6) == EQUAL &&
+				ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_EVSE_STOP_EVENT == YES)
+		{
+			memcpy(code, "023862", 6);
+			memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
+			isCleanCheck = true;
+		}
+		else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023863", 6) == EQUAL &&
+				ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_GET_MISC_INFO == YES)
+		{
+			memcpy(code, "023863", 6);
+			memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
+			isCleanCheck = true;
+		}
+		else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023864", 6) == EQUAL &&
+				ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_GET_MISC_INFO == YES)
+		{
+			memcpy(code, "023864", 6);
+			memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
+			isCleanCheck = true;
+		}
+		else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023865", 6) == EQUAL &&
+				ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_DOWNLOAD_REQUEST == YES)
+		{
+			memcpy(code, "023865", 6);
+			memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
+			isCleanCheck = true;
+		}
+		else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023866", 6) == EQUAL &&
+				ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_DOWNLOAD_REQUEST == YES)
+		{
+			memcpy(code, "023866", 6);
+			memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
+			isCleanCheck = true;
+		}
+		else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023867", 6) == EQUAL &&
+				ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_START_BLOCK_TRANSFER == YES)
+		{
+			memcpy(code, "023867", 6);
+			memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
+			isCleanCheck = true;
+		}
+		else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023868", 6) == EQUAL &&
+				ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_START_BLOCK_TRANSFER == YES)
+		{
+			memcpy(code, "023868", 6);
+			memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
+			isCleanCheck = true;
+		}
+		else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023869", 6) == EQUAL &&
+				ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_DATA_TRANSFER == YES)
+		{
+			memcpy(code, "023869", 6);
+			memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
+			isCleanCheck = true;
+		}
+		else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023870", 6) == EQUAL &&
+				ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_DATA_TRANSFER == YES)
+		{
+			memcpy(code, "023870", 6);
+			memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
+			isCleanCheck = true;
+		}
+		else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023871", 6) == EQUAL &&
+				ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_DOWNLOAD_FINISH == YES)
+		{
+			memcpy(code, "023871", 6);
+			memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
+			isCleanCheck = true;
+		}
+		else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023872", 6) == EQUAL &&
+				ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_DOWNLOAD_FINISH == YES)
+		{
+			memcpy(code, "023872", 6);
+			memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
+			isCleanCheck = true;
+		}
+		else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023873", 6) == EQUAL &&
+				ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_ISOLATION_STATUS == YES)
+		{
+			memcpy(code, "023873", 6);
+			memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
+			isCleanCheck = true;
+		}
+		else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023874", 6) == EQUAL &&
+				ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_ISOLATION_STATUS == YES)
+		{
+			memcpy(code, "023874", 6);
+			memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
+			isCleanCheck = true;
+		}
+		else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023875", 6) == EQUAL &&
+				ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_CONNECTOR_INFO == YES)
+		{
+			memcpy(code, "023875", 6);
+			memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
+			isCleanCheck = true;
+		}
+		else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023876", 6) == EQUAL &&
+				ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_CONNECTOR_INFO == YES)
+		{
+			memcpy(code, "023876", 6);
+			memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
+			isCleanCheck = true;
+		}
+		else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023877", 6) == EQUAL &&
+				ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_RTC_INFO == YES)
+		{
+			memcpy(code, "023877", 6);
+			memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
+			isCleanCheck = true;
+		}
+		else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023878", 6) == EQUAL &&
+				ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_RTC_INFO == YES)
+		{
+			memcpy(code, "023878", 6);
+			memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
+			isCleanCheck = true;
+		}
+		else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023879", 6) == EQUAL &&
+				ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_EVSE_PRECHARGE_INFO == YES)
+		{
+			memcpy(code, "023879", 6);
+			memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
+			isCleanCheck = true;
+		}
+		else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023880", 6) == EQUAL &&
+				ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_EVSE_PRECHARGE_INFO == YES)
+		{
+			memcpy(code, "023880", 6);
+			memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
+			isCleanCheck = true;
+		}
+		else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023881", 6) == EQUAL &&
+				ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsMSG_Sequence == YES)
+		{
+			memcpy(code, "023881", 6);
+			memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
+			isCleanCheck = true;
+		}
+		else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023882", 6) == EQUAL &&
+				ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCAN_MSG_Unrecognized_CMD_ID == YES)
+		{
+			memcpy(code, "023882", 6);
+			memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
+			isCleanCheck = true;
+		}
+		else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023883", 6) == EQUAL &&
+				ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsDIN_Msg_Decode_Error == YES)
+		{
+			memcpy(code, "023883", 6);
+			memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
+			isCleanCheck = true;
+		}
+		else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023884", 6) == EQUAL &&
+				ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsDIN_Msg_Encode_Error == YES)
+		{
+			memcpy(code, "023884", 6);
+			memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
+			isCleanCheck = true;
+		}
+		else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023885", 6) == EQUAL &&
+				ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsISO1_Msg_Decode_Error == YES)
+		{
+			memcpy(code, "023885", 6);
+			memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
+			isCleanCheck = true;
+		}
+		else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023886", 6) == EQUAL &&
+				ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsISO1_Msg_Encode_Error == YES)
+		{
+			memcpy(code, "023886", 6);
+			memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
+			isCleanCheck = true;
+		}
+		else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023887", 6) == EQUAL &&
+				ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsISO2_Msg_Decode_Error == YES)
+		{
+			memcpy(code, "023887", 6);
+			memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
+			isCleanCheck = true;
+		}
+		else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023888", 6) == EQUAL &&
+				ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsISO2_Msg_Encode_Error == YES)
+		{
+			memcpy(code, "023888", 6);
+			memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
+			isCleanCheck = true;
+		}
+		else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023889", 6) == EQUAL &&
+				ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCpStatus_Error == YES)
+		{
+			memcpy(code, "023889", 6);
+			memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
+			isCleanCheck = true;
+		}
+		else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023890", 6) == EQUAL &&
+				ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsUnexpectVolBeforeCharing_Error == YES)
+		{
+			memcpy(code, "023890", 6);
+			memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
+			isCleanCheck = true;
+		}
+		else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023891", 6) == EQUAL &&
+				ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSeccNotReadyForCharging == YES)
+		{
+			memcpy(code, "023891", 6);
+			memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
+			isCleanCheck = true;
+		}
+	//	else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023892", 6) == EQUAL &&
+	//			ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSeccTimeoutQCA7000Comm == YES)
+	//	{
+	//		memcpy(code, "023892", 6);
+	//		memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
+	//		isCleanCheck = true;
+	//	}
+		else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023893", 6) == EQUAL &&
+				ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSeccFailForQCA7000SetKey == YES)
+		{
+			memcpy(code, "023893", 6);
+			memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
+			isCleanCheck = true;
+		}
+		else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023979", 6) == EQUAL &&
+				ShmStatusCodeData->InfoCode.InfoEvents.bits.EV_Full_Charging == YES)
+		{
+			memcpy(code, "023979", 6);
+			memcpy(_chargingData[gun_index]->EvConnAlarmCode, "", 6);
+			isCleanCheck = true;
+		}
+		else if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "023983", 6) == EQUAL &&
+				ShmStatusCodeData->InfoCode.InfoEvents.bits.Stop_by_EV_with_unknow_reason == YES)
+		{
+			memcpy(code, "023983", 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, "023818", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSeccSlacTimeoutCmMnbcSound = NO;
+					if (strncmp(code, "023819", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSeccSlacTimeoutCmValidateReq = NO;
+					if (strncmp(code, "023823", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsUDP_TT_match_join = NO;
+					if (strncmp(code, "023824", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTCP_TT_match_join = NO;
+					if (strncmp(code, "023825", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_amp_map_exchange = NO;
+					if (strncmp(code, "023826", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_link_ready_notification = NO;
+					if (strncmp(code, "023832", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSupportedAppProtocolRes = NO;
+					if (strncmp(code, "023833", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSessionSetupRes = NO;
+					if (strncmp(code, "023834", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsServiceDiscoveryRes = NO;
+					if (strncmp(code, "023835", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsServicePaymentSelectionRes = NO;
+					if (strncmp(code, "023836", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsContractAuthenticationRes = NO;
+					if (strncmp(code, "023837", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsChargeParameterDiscoveryRes = NO;
+					if (strncmp(code, "023838", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsPowerDeliveryRes = NO;
+					if (strncmp(code, "023839", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCableCheckRes = NO;
+					if (strncmp(code, "023840", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsPreChargeRes = NO;
+					if (strncmp(code, "023841", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCurrentDemandRes = NO;
+					if (strncmp(code, "023842", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsWeldingDetectionRes = NO;
+					if (strncmp(code, "023843", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSessionStopRes = NO;
+					if (strncmp(code, "023844", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSequence_Time = NO;
+					if (strncmp(code, "023845", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsReadyToCharge_Performance_Time = NO;
+					if (strncmp(code, "023846", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCommunicationSetup_Performance_Time = NO;
+					if (strncmp(code, "023847", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCableCheck_Performance_Time = NO;
+					if (strncmp(code, "023848", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCPState_Detection_Time = NO;
+					if (strncmp(code, "023849", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCPOscillator_Retain_Time = NO;
+					if (strncmp(code, "023850", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSeccTimeoutV2GPreChargePerformaceTime = NO;
+					if (strncmp(code, "023855", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_GET_EV_TARGET_INFO = NO;
+					if (strncmp(code, "023856", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_GET_EV_TARGET_INFO = NO;
+					if (strncmp(code, "023857", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_GET_EV_BATTERY_INFO = NO;
+					if (strncmp(code, "023858", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_GET_EV_BATTERY_INFO = NO;
+					if (strncmp(code, "023859", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_EV_STOP_EVENT = NO;
+					if (strncmp(code, "023860", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_EV_STOP_EVENT = NO;
+					if (strncmp(code, "023861", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_EVSE_STOP_EVENT = NO;
+					if (strncmp(code, "023862", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_EVSE_STOP_EVENT = NO;
+					if (strncmp(code, "023863", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_GET_MISC_INFO = NO;
+					if (strncmp(code, "023864", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_GET_MISC_INFO = NO;
+					if (strncmp(code, "023865", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_DOWNLOAD_REQUEST = NO;
+					if (strncmp(code, "023866", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_DOWNLOAD_REQUEST = NO;
+					if (strncmp(code, "023867", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_START_BLOCK_TRANSFER = NO;
+					if (strncmp(code, "023868", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_START_BLOCK_TRANSFER = NO;
+					if (strncmp(code, "023869", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_DATA_TRANSFER = NO;
+					if (strncmp(code, "023870", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_DATA_TRANSFER = NO;
+					if (strncmp(code, "023871", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_DOWNLOAD_FINISH = NO;
+					if (strncmp(code, "023872", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_DOWNLOAD_FINISH = NO;
+					if (strncmp(code, "023873", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_ISOLATION_STATUS = NO;
+					if (strncmp(code, "023874", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_ISOLATION_STATUS = NO;
+					if (strncmp(code, "023875", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_CONNECTOR_INFO = NO;
+					if (strncmp(code, "023876", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_CONNECTOR_INFO = NO;
+					if (strncmp(code, "023877", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_RTC_INFO = NO;
+					if (strncmp(code, "023878", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_RTC_INFO = NO;
+					if (strncmp(code, "023879", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_EVSE_PRECHARGE_INFO = NO;
+					if (strncmp(code, "023880", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_EVSE_PRECHARGE_INFO = NO;
+					if (strncmp(code, "023881", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsMSG_Sequence = NO;
+					if (strncmp(code, "023882", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCAN_MSG_Unrecognized_CMD_ID = NO;
+					if (strncmp(code, "023883", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsDIN_Msg_Decode_Error = NO;
+					if (strncmp(code, "023884", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsDIN_Msg_Encode_Error = NO;
+					if (strncmp(code, "023885", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsISO1_Msg_Decode_Error = NO;
+					if (strncmp(code, "023886", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsISO1_Msg_Encode_Error = NO;
+					if (strncmp(code, "023887", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsISO2_Msg_Decode_Error = NO;
+					if (strncmp(code, "023888", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsISO2_Msg_Encode_Error = NO;
+					if (strncmp(code, "023889", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCpStatus_Error = NO;
+					if (strncmp(code, "023890", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsUnexpectVolBeforeCharing_Error = NO;
+					if (strncmp(code, "023891", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSeccNotReadyForCharging = NO;
+					//if (strncmp(code, "023892", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSeccTimeoutQCA7000Comm = NO;
+					if (strncmp(code, "023893", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSeccFailForQCA7000SetKey = NO;
+					if (strncmp(code, "023979", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.EV_Full_Charging = NO;
+					if (strncmp(code, "023983", 6) == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.Stop_by_EV_with_unknow_reason = NO;
+				}
+			}
+		}
+	}
+}
+
+bool AbnormalStopAnalysis(byte gun_index, byte *errCode)
+{
+	char string[7];
+	sprintf(string, "%d%d%d%d%d%d", *(errCode + 0), *(errCode + 1), *(errCode + 2), *(errCode + 3), *(errCode + 4), *(errCode + 5));
+
+	PRINTF_FUNC("NOTIFICATION_EV_STOP : Err Code = %s \n", string);
+	if (strncmp(string, "000000", 6) == EQUAL || strncmp(string, "012219", 6) == EQUAL)
+		return false;
+
+	if (strncmp((char *)_chargingData[gun_index]->EvConnAlarmCode, "", 6) != EQUAL)
+		return true;
+
+	memcpy(_chargingData[gun_index]->EvConnAlarmCode, string, 6);
+	PRINTF_FUNC("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, "023980") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CHADEMO_BMS_CHARGE_ALLOW_ERROR = YES;
+	if (strcmp(string, "023981") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CHADEMO_OUTPUT_VOLTAGE_MORE_THEN_10_PERCENT = YES;
+	if (strcmp(string, "023982") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CHADEMO_ADC_LESS_THAN_10V = YES;
+
+	if (strcmp(string, "012288") == EQUAL) ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsOutputUVPFail = 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, "023818") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSeccSlacTimeoutCmMnbcSound = YES;
+	if (strcmp(string, "023819") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSeccSlacTimeoutCmValidateReq = YES;
+	if (strcmp(string, "023823") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsUDP_TT_match_join = YES;
+	if (strcmp(string, "023824") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTCP_TT_match_join = YES;
+	if (strcmp(string, "023825") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_amp_map_exchange = YES;
+	if (strcmp(string, "023826") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_link_ready_notification = YES;
+	if (strcmp(string, "023832") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSupportedAppProtocolRes = YES;
+	if (strcmp(string, "023833") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSessionSetupRes = YES;
+	if (strcmp(string, "023834") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsServiceDiscoveryRes = YES;
+	if (strcmp(string, "023835") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsServicePaymentSelectionRes = YES;
+	if (strcmp(string, "023836") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsContractAuthenticationRes = YES;
+	if (strcmp(string, "023837") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsChargeParameterDiscoveryRes = YES;
+	if (strcmp(string, "023838") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsPowerDeliveryRes = YES;
+	if (strcmp(string, "023839") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCableCheckRes = YES;
+	if (strcmp(string, "023840") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsPreChargeRes = YES;
+	if (strcmp(string, "023841") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCurrentDemandRes = YES;
+	if (strcmp(string, "023842") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsWeldingDetectionRes = YES;
+	if (strcmp(string, "023843") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSessionStopRes = YES;
+	if (strcmp(string, "023844") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSequence_Time = YES;
+	if (strcmp(string, "023845") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsReadyToCharge_Performance_Time = YES;
+	if (strcmp(string, "023846") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCommunicationSetup_Performance_Time = YES;
+	if (strcmp(string, "023847") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCableCheck_Performance_Time = YES;
+	if (strcmp(string, "023848") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCPState_Detection_Time = YES;
+	if (strcmp(string, "023849") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCPOscillator_Retain_Time = YES;
+	if (strcmp(string, "023850") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSeccTimeoutV2GPreChargePerformaceTime = YES;
+	if (strcmp(string, "023855") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_GET_EV_TARGET_INFO = YES;
+	if (strcmp(string, "023856") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_GET_EV_TARGET_INFO = YES;
+	if (strcmp(string, "023857") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_GET_EV_BATTERY_INFO = YES;
+	if (strcmp(string, "023858") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_GET_EV_BATTERY_INFO = YES;
+	if (strcmp(string, "023859") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_EV_STOP_EVENT = YES;
+	if (strcmp(string, "023860") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_EV_STOP_EVENT = YES;
+	if (strcmp(string, "023861") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_EVSE_STOP_EVENT = YES;
+	if (strcmp(string, "023862") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_EVSE_STOP_EVENT = YES;
+	if (strcmp(string, "023863") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_GET_MISC_INFO = YES;
+	if (strcmp(string, "023864") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_GET_MISC_INFO = YES;
+	if (strcmp(string, "023865") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_DOWNLOAD_REQUEST = YES;
+	if (strcmp(string, "023866") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_DOWNLOAD_REQUEST = YES;
+	if (strcmp(string, "023867") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_START_BLOCK_TRANSFER = YES;
+	if (strcmp(string, "023868") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_START_BLOCK_TRANSFER = YES;
+	if (strcmp(string, "023869") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_DATA_TRANSFER = YES;
+	if (strcmp(string, "023870") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_DATA_TRANSFER = YES;
+	if (strcmp(string, "023871") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_DOWNLOAD_FINISH = YES;
+	if (strcmp(string, "023872") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_DOWNLOAD_FINISH = YES;
+	if (strcmp(string, "023873") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_ISOLATION_STATUS = YES;
+	if (strcmp(string, "023874") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_ISOLATION_STATUS = YES;
+	if (strcmp(string, "023875") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_CONNECTOR_INFO = YES;
+	if (strcmp(string, "023876") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_CONNECTOR_INFO = YES;
+	if (strcmp(string, "023877") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_RTC_INFO = YES;
+	if (strcmp(string, "023878") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_RTC_INFO = YES;
+	if (strcmp(string, "023879") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTP_EVSE_PRECHARGE_INFO = YES;
+	if (strcmp(string, "023880") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsTT_EVSE_PRECHARGE_INFO = YES;
+	if (strcmp(string, "023881") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsMSG_Sequence = YES;
+	if (strcmp(string, "023882") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCAN_MSG_Unrecognized_CMD_ID = YES;
+	if (strcmp(string, "023883") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsDIN_Msg_Decode_Error = YES;
+	if (strcmp(string, "023884") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsDIN_Msg_Encode_Error = YES;
+	if (strcmp(string, "023885") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsISO1_Msg_Decode_Error = YES;
+	if (strcmp(string, "023886") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsISO1_Msg_Encode_Error = YES;
+	if (strcmp(string, "023887") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsISO2_Msg_Decode_Error = YES;
+	if (strcmp(string, "023888") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsISO2_Msg_Encode_Error = YES;
+	if (strcmp(string, "023889") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsCpStatus_Error = YES;
+	if (strcmp(string, "023890") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsUnexpectVolBeforeCharing_Error = YES;
+	if (strcmp(string, "023891") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSeccNotReadyForCharging = YES;
+	if (strcmp(string, "023892") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSeccTimeoutQCA7000Comm = YES;
+	if (strcmp(string, "023893") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSeccFailForQCA7000SetKey = YES;
+	if (strcmp(string, "023979") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.EV_Full_Charging = YES;
+	if (strcmp(string, "023983") == EQUAL) ShmStatusCodeData->InfoCode.InfoEvents.bits.Stop_by_EV_with_unknow_reason = 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;
+
+	return true;
+}
+
+byte ReturnConnectTemp(byte temp1, byte temp2)
+{
+	byte result = 0;
+
+	if (temp1 == UNDEFINED_TEMP && temp2 == UNDEFINED_TEMP)
+		return UNDEFINED_TEMP;
+
+	if (temp1 != UNDEFINED_TEMP)
+		result = temp1;
+	else
+		temp1 = 0;
+
+	if (temp2 != UNDEFINED_TEMP)
+	{
+		if (temp2 > temp1)
+			result = temp2;
+	}
+
+	return result;
+}
+
+void CANReceiver()
+{
+	pid_t canRecPid;
+
+	canRecPid = fork();
+
+	if(canRecPid > 0)
+	{
+		int nbytes;
+		struct can_frame frame;
+		int intCmd;
+		bool isClearBuf = false;
+
+		// 槍資訊
+		struct ChargingInfoData *_chargingData[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
+
+		bool isPass = false;
+		gun_count = ShmSysConfigAndInfo->SysConfig.TotalConnectorCount;
+
+		while(!isPass)
+		{
+			isPass = true;
+			for (byte _index = 0; _index < gun_count; _index++)
+			{
+				if (!FindChargingInfoData(_index, &_chargingData[0]))
+				{
+					DEBUG_ERROR("EvComm (main) : FindChargingInfoData false \n");
+					isPass = false;
+					break;
+				}
+			}
+
+			sleep(1);
+		}
+
+		while (1)
+		{
+			memset(&frame, 0, sizeof(struct can_frame));
+			nbytes = read(CanFd, &frame, sizeof(struct can_frame));
+
+			if (nbytes > 0)
+			{
+				byte target;
+				byte targetGun = 0x00;
+				byte findIndex = 0x00;
+				EvFrame *EvFrameMsg;
+
+				EvFrameMsg = (EvFrame *)&frame.can_id;
+				intCmd = EvFrameMsg->EvBdBits.MessageID;
+
+				if (!isClearBuf)
+				{
+					continue;
+				}
+
+				if (intCmd == EV_Command_AddressReq)
+				{
+					ShmDcCommonData->CcsVersion = _CCS_VERSION_CHECK_TAG_V013S0;
+					AddrAssignment(frame.data);
+					continue;
+				}
+
+				target = EvFrameMsg->EvBdBits.SlaveAddress;		// 0x01 or 0x02
+
+				for (byte _index = 0; _index < gun_count; _index++)
+				{
+					// 假設有找到回應的 Index
+					findIndex = target;
+					if (gun_count == 1 &&
+							_chargingData[_index]->Type == _Type_CCS &&
+							ShmDcCommonData->CcsVersion == _CCS_VERSION_CHECK_TAG_V015S0)
+					{
+						target -= 1;
+					}
+
+					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 (gun_count == 1)
+				{
+					if (findIndex == 1)
+						ShmDcCommonData->CcsVersion = _CCS_VERSION_CHECK_TAG_V013S0;
+					else
+						ShmDcCommonData->CcsVersion = _CCS_VERSION_CHECK_TAG_V015S0;
+				}
+
+				if(intCmd == 256) { continue; }
+
+				switch (intCmd)
+				{
+					case EV_Command_EvStatusNotification:
+					{
+						if (_chargingData[targetGun]->ConnectorPlugIn != frame.data[0])
+						{
+							if (frame.data[0] == PLUG)
+								PRINTF_FUNC("Conn %d, Plugin. \n", targetGun);
+							else if (frame.data[0] == UNPLUG)
+								PRINTF_FUNC("Conn %d, Unplug. \n", targetGun);
+							else
+								PRINTF_FUNC("Conn %d, Plug None Check. (%d) \n", targetGun, frame.data[0]);
+						}
+
+						// for using ccid to authoriz.
+						if (ShmDcCommonData->_authWithCcidFlag[targetGun] == _CCID_AUTHFAIL &&
+								_chargingData[targetGun]->ConnectorPlugIn == UNPLUG)
+						{
+							ShmDcCommonData->_authWithCcidFlag[targetGun] = _CCID_NONE;
+						}
+
+						_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 EV_Command_GetFwVersion:
+					{
+						byte ver[16];
+
+						memset(ver, 0, sizeof(ver));
+						if (_chargingData[targetGun]->Type == _Type_Chademo)
+						{
+							memcpy(ver, frame.data, frame.can_dlc);
+							memcpy(ShmCHAdeMOData->evse[_chargingData[targetGun]->type_index].version, ver, ARRAY_SIZE(ver));
+							ShmCHAdeMOData->evse[_chargingData[targetGun]->type_index].SelfTest_Comp = PASS;
+							PRINTF_FUNC("Connector %d, Chadmoe Ver. : %s\n",
+									targetGun, ShmCHAdeMOData->evse[_chargingData[targetGun]->type_index].version);
+						}
+						else if (_chargingData[targetGun]->Type == _Type_GB)
+						{
+							memcpy(ver, frame.data, frame.can_dlc);
+							memcpy(ShmGBTData->evse[_chargingData[targetGun]->type_index].version, ver, ARRAY_SIZE(ver));
+							ShmGBTData->evse[_chargingData[targetGun]->type_index].SelfTest_Comp = PASS;
+							PRINTF_FUNC("Connector %d, GBT Ver. : %s\n",
+									targetGun, ShmGBTData->evse[_chargingData[targetGun]->type_index].version);
+						}
+						else if (_chargingData[targetGun]->Type == _Type_CCS)
+						{
+							if (ShmCcsData->CommProtocol == _CCS_COMM_V2GMessage_DIN70121)
+							{
+								memcpy(ver, frame.data, frame.can_dlc);
+								memcpy(&ShmCcsData->V2GMessage_DIN70121[_chargingData[targetGun]->type_index].version, ver, ARRAY_SIZE(ver));
+								ShmCcsData->V2GMessage_DIN70121[_chargingData[targetGun]->type_index].SelfTest_Comp = PASS;
+								PRINTF_FUNC("Connector %d, CCS Ver. = %s \n",
+										targetGun, ShmCcsData->V2GMessage_DIN70121[_chargingData[targetGun]->type_index].version);
+							}
+						}
+
+						if (targetGun == 0)
+						{
+							memset(ShmSysConfigAndInfo->SysInfo.Connector1FwRev, 0, sizeof(ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
+							memcpy(ShmSysConfigAndInfo->SysInfo.Connector1FwRev, ver, ARRAY_SIZE(ver));
+						}
+						else
+						{
+							memset(ShmSysConfigAndInfo->SysInfo.Connector2FwRev, 0, sizeof(ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
+							memcpy(ShmSysConfigAndInfo->SysInfo.Connector2FwRev, ver, ARRAY_SIZE(ver));
+						}
+					}
+						break;
+					case EV_Command_GetHwVersion:
+					{
+						//PRINTF_FUNC("Get EV HW = %s \n", frame.data);
+					}
+						break;
+					case EV_Command_GetOutputReq:
+					{
+						if ((_chargingData[targetGun]->SystemStatus >= SYS_MODE_PREPARE_FOR_EVSE &&
+								_chargingData[targetGun]->SystemStatus <= SYS_MODE_CHARGING) ||
+								(_chargingData[targetGun]->SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0 &&
+								_chargingData[targetGun]->SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))
+						{
+							if (_chargingData[targetGun]->EvBatteryStartSoc <= 0)
+								_chargingData[targetGun]->EvBatteryStartSoc = frame.data[1];
+
+							if (frame.data[1] > _chargingData[targetGun]->EvBatterySoc ||
+									_chargingData[targetGun]->SystemStatus == SYS_MODE_CHARGING)
+								_chargingData[targetGun]->EvBatterySoc = frame.data[1];
+						}
+
+						_chargingData[targetGun]->EvBatterytargetVoltage = (float)((frame.data[3] << 8) + frame.data[2]) / 10;
+						_chargingData[targetGun]->EvBatterytargetCurrent = (float)((frame.data[5] << 8) + frame.data[4]) / 10;
+						_chargingData[targetGun]->RemainChargingDuration = ((short) frame.data[7] << 8) + (short) frame.data[6];
+
+						if (_chargingData[targetGun]->Type == _Type_Chademo)
+						{
+							//if (ShmCHAdeMOData->ev[_chargingData[targetGun]->type_index].EvDetection != frame.data[0])
+							{
+								ShmCHAdeMOData->ev[_chargingData[targetGun]->type_index].PresentMsgFlowStatus = frame.data[0];
+							}
+
+							ShmCHAdeMOData->ev[_chargingData[targetGun]->type_index].EvDetection = frame.data[0];
+							ShmCHAdeMOData->ev[_chargingData[targetGun]->type_index].SOC = _chargingData[targetGun]->EvBatterySoc;
+							ShmCHAdeMOData->ev[_chargingData[targetGun]->type_index].TargetBatteryVoltage = (_chargingData[targetGun]->EvBatterytargetVoltage * 10);
+							ShmCHAdeMOData->ev[_chargingData[targetGun]->type_index].ChargingCurrentRequest = (_chargingData[targetGun]->EvBatterytargetCurrent * 10);
+						}
+						else if (_chargingData[targetGun]->Type == _Type_GB)
+						{
+							//if (ShmGBTData->ev[_chargingData[targetGun]->type_index].EvDetection != frame.data[0])
+							{
+								ShmGBTData->ev[_chargingData[targetGun]->type_index].PresentMsgFlowStatus = frame.data[0];
+							}
+
+							ShmGBTData->ev[_chargingData[targetGun]->type_index].EvDetection = frame.data[0];
+							ShmGBTData->ev[_chargingData[targetGun]->type_index].SOC = _chargingData[targetGun]->EvBatterySoc;
+							ShmGBTData->ev[_chargingData[targetGun]->type_index].TargetBatteryVoltage = (_chargingData[targetGun]->EvBatterytargetVoltage * 10);
+							ShmGBTData->ev[_chargingData[targetGun]->type_index].ChargingCurrentRequest = (_chargingData[targetGun]->EvBatterytargetCurrent * 10);
+						}
+						else if (_chargingData[targetGun]->Type == _Type_CCS)
+						{
+							if(ShmCcsData->CommProtocol == _CCS_COMM_V2GMessage_DIN70121)
+							{
+								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 EV_Command_GetBetteryInfo:
+					{
+						//_chargingData[target].EvACorDCcharging = frame.data[0];
+						//_chargingData[target]->TotalBatteryCap = ((float) frame.data[4] << 8) + (short) frame.data[3];
+						_chargingData[targetGun]->EvBatteryMaxVoltage = (((short) frame.data[4] << 8) + (short) frame.data[3]) / 10;
+						//_chargingData[target]->EvBatteryMaxCurrent = ((float) frame.data[4] << 8) + (short) frame.data[3];
+						//_chargingData[target].MaxiBatteryCurrent = ((short) frame.data[6] << 8) + (short) frame.data[5];
+
+						if (_chargingData[targetGun]->Type == _Type_Chademo)
+						{
+							ShmCHAdeMOData->ev[_chargingData[targetGun]->type_index].TotalBatteryCapacity = ((short) frame.data[2] << 8) + (short) frame.data[1];
+							ShmCHAdeMOData->ev[_chargingData[targetGun]->type_index].MaxiBatteryVoltage = _chargingData[targetGun]->EvBatteryMaxVoltage;
+
+							//PRINTF_FUNC("EvBatteryMaxVoltage = %f \n", _chargingData[target]->EvBatteryMaxVoltage);
+							//PRINTF_FUNC("TotalBatteryCapacity = %d \n", ShmCHAdeMOData->ev[_chargingData[target]->type_index].TotalBatteryCapacity);
+							//PRINTF_FUNC("MaxiBatteryVoltage = %d \n", ShmCHAdeMOData->ev[_chargingData[target]->type_index].MaxiBatteryVoltage);
+						}
+						else if (_chargingData[targetGun]->Type == _Type_GB)
+						{
+							ShmGBTData->ev[_chargingData[targetGun]->type_index].TotalBatteryCapacity = ((short) frame.data[2] << 8) + (short) frame.data[1];
+							ShmGBTData->ev[_chargingData[targetGun]->type_index].MaxiBatteryVoltage = _chargingData[targetGun]->EvBatteryMaxVoltage;
+						}
+						else if (_chargingData[targetGun]->Type == _Type_CCS)
+						{
+
+						}
+					}
+						break;
+					case EV_Command_GetMiscellaneous:
+					{
+						_chargingData[targetGun]->GunLocked = frame.data[0];
+						_chargingData[targetGun]->PilotVoltage = (float)(-120 + frame.data[3]) / 10;
+
+						ShmDcCommonData->ConnectorTemp1[targetGun] = frame.data[1];
+						ShmDcCommonData->ConnectorTemp2[targetGun] = frame.data[2];
+
+						if (_chargingData[targetGun]->Type == _Type_Chademo)
+						{
+							// 200A 以上的槍才會有 cha 槍溫
+							_chargingData[targetGun]->ConnectorTemp = UNDEFINED_TEMP;
+							ShmCHAdeMOData->evse[_chargingData[targetGun]->type_index].ConnectorTemperatureP = frame.data[1];
+							ShmCHAdeMOData->evse[_chargingData[targetGun]->type_index].ConnectorTemperatureN = frame.data[2];
+							ShmCHAdeMOData->evse[_chargingData[targetGun]->type_index].EvboardStatus = frame.data[7];
+						}
+						else if (_chargingData[targetGun]->Type == _Type_GB)
+						{
+							_chargingData[targetGun]->ConnectorTemp = ReturnConnectTemp(frame.data[1], frame.data[2]);
+							ShmGBTData->evse[_chargingData[targetGun]->type_index].ConnectorTemperatureP = frame.data[1];
+							ShmGBTData->evse[_chargingData[targetGun]->type_index].ConnectorTemperatureN = frame.data[2];
+							ShmGBTData->evse[_chargingData[targetGun]->type_index].EvboardStatus = frame.data[7];
+						}
+						else if (_chargingData[targetGun]->Type == _Type_CCS)
+						{
+							_chargingData[targetGun]->ConnectorTemp = ReturnConnectTemp(frame.data[1], frame.data[2]);
+							if (ShmCcsData->CommProtocol == _CCS_COMM_V2GMessage_DIN70121)
+							{
+								//ShmCcsData->V2GMessage_DIN70121[_chargingData[targetGun]->type_index]. .ConnectorTemperatureP = frame.data[1];
+								//ShmCcsData->V2GMessage_DIN70121[_chargingData[targetGun]->type_index]. .ConnectorTemperatureN = frame.data[2];
+							}
+						}
+
+						//PRINTF_FUNC("EvboardStatus = %x \n", ShmCHAdeMOData->evse[_chargingData[target]->type_index].EvboardStatus);
+						//PRINTF_FUNC("ConnectorPlug locked = %x \n", frame.data[0]);
+						//PRINTF_FUNC("ConnectorTemp 0= %d \n", ShmCHAdeMOData->evse[_chargingData[target]->type_index].ConnectorTemperatureP);
+						//PRINTF_FUNC("ConnectorTemp 1= %d \n", ShmCHAdeMOData->evse[_chargingData[target]->type_index].ConnectorTemperatureN);
+						//PRINTF_FUNC("PilotVoltage = %x \n", (-120 + frame.data[3]) / 10);
+					}
+						break;
+					case EV_Command_IsolationStatus:{}
+						break;
+					case EV_Command_EvccidReq:
+					{
+						if (frame.can_dlc > 0 &&
+								strcmp((char *)_chargingData[targetGun]->EVCCID, "") == EQUAL)
+						{
+							if (_chargingData[targetGun]->Type == _Type_CCS)
+							{
+								if (ShmCcsData->CommProtocol == _CCS_COMM_V2GMessage_DIN70121)
+								{
+									memset(ShmCcsData->V2GMessage_DIN70121[_chargingData[targetGun]->type_index].SessionSetupRequest.EVCCID, 0, sizeof(ShmCcsData->V2GMessage_DIN70121[_chargingData[targetGun]->type_index].SessionSetupRequest.EVCCID));
+									memcpy(ShmCcsData->V2GMessage_DIN70121[_chargingData[targetGun]->type_index].SessionSetupRequest.EVCCID, frame.data, frame.can_dlc);
+								}
+							}
+
+							sprintf((char *)_chargingData[targetGun]->EVCCID, "%.2x%.2x%.2x%.2x%.2x%.2x",
+									frame.data[0], frame.data[1], frame.data[2], frame.data[3],
+									frame.data[4], frame.data[5]);
+
+							_chargingData[targetGun]->EVCCID[17] = '\0';
+							PRINTF_FUNC("*******Gun %d->EVCCID = %s \n", targetGun, _chargingData[targetGun]->EVCCID);
+						}
+					}
+						break;
+					case EV_Command_EvsePrechargeInfo:
+					{
+						_chargingData[targetGun]->PrechargeStatus = frame.data[0];
+					}
+						break;
+					case EV_Command_EvStopNotification:
+					{
+						// 車端要求停止
+						if ((_chargingData[targetGun]->SystemStatus >= SYS_MODE_MODE_REASSIGN_CHECK &&
+								_chargingData[targetGun]->SystemStatus <= SYS_MODE_CHARGING) ||
+								(_chargingData[targetGun]->SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0 &&
+								_chargingData[targetGun]->SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))
+						{
+							// frame.data[0] : 0x01 => normal stop, 0x02 => ev emergency stop
+							if (frame.data[0] == 0x02)
+							{
+								PRINTF_FUNC("Gun_%d, ** Emc Level **, Stop charging by EV. \n", targetGun);
+								if (AbnormalStopAnalysis(targetGun, frame.data + 1))
+								{
+									_chargingData[targetGun]->StopChargeFlag = YES;
+								}
+								else
+								{
+									// 六個蛋
+									_chargingData[targetGun]->NormalStopChargeFlag = YES;
+								}
+							}
+							else
+							{
+								AbnormalStopAnalysis(targetGun, frame.data + 1);
+
+								PRINTF_FUNC("Gun_%d, ** Normal Level **, Stop charging by EV. \n", targetGun);
+								_chargingData[targetGun]->NormalStopChargeFlag = YES;
+							}
+						}
+					}
+						break;
+					default:
+						PRINTF_FUNC("EV board = %d, Ack none defined. intCmd = %d  \n", targetGun, intCmd);
+						break;
+				}
+			}
+			else
+			{
+				isClearBuf = true;
+				usleep(10000);
+			}
+		}
+	}
+}
+
+//================================================
+// Main process
+//================================================
+// 檢查 Byte 中某個 Bit 的值
+// _byte : 欲改變的 byte
+// _bit : 該 byte 的第幾個 bit
+unsigned char EvDetectionStatus(unsigned char _byte, unsigned char _bit)
+{
+	return ( _byte & mask_table[_bit] ) != 0x00;
+}
+
+bool IsConnectorPlugIn(struct ChargingInfoData *chargingData)
+{
+	return (chargingData->ConnectorPlugIn == 0x01) ? true : false;
+}
+
+void SetPresentChargingOutputPower(struct ChargingInfoData *chargingData_1, struct ChargingInfoData *chargingData_2)
+{
+	float vol1 = 0, cur1 = 0;
+	float vol2 = 0, cur2 = 0;
+
+//	if (ShmGBTData->ev[chargingData_1->type_index].PresentMsgFlowStatus == 10)
+//		vol1 = ShmPsuData->PsuGroup[0].GroupTargetOutputVoltage;
+//	else
+
+	vol1 = chargingData_1->FireChargingVoltage;
+
+	cur1 = (chargingData_1->PresentChargingCurrent * 10);
+
+	float targetCur = chargingData_1->EvBatterytargetCurrent * 10;
+	if (curTargetCur[0] != chargingData_1->EvBatterytargetCurrent * 10)
+	{
+		curTargetCur[0] = chargingData_1->EvBatterytargetCurrent * 10;
+		curAllowCount[0] = 0;
+	}
+
+	if (curAllowCount[0] < ALLOW_COUNT_MAX &&
+			chargingData_1->Type == _Type_CCS)
+	{
+		if (cur1 > targetCur + 100 || cur1 < targetCur - 100)
+		{
+			cur1 = targetCur;
+			curAllowCount[0]++;
+		}
+		else
+			curAllowCount[0] = 0;
+	}
+
+//	if (ShmGBTData->ev[chargingData_2->type_index].PresentMsgFlowStatus == 10)
+//		vol2 = ShmPsuData->PsuGroup[1].GroupTargetOutputVoltage;
+//	else
+
+	vol2 = chargingData_2->FireChargingVoltage;
+
+	cur2 = (chargingData_2->PresentChargingCurrent * 10);
+
+	if ((chargingData_1->SystemStatus >= SYS_MODE_PREPARING && chargingData_1->SystemStatus <= SYS_MODE_CHARGING) ||
+			(chargingData_1->SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0 && chargingData_1->SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))
+	{
+		if ((LogInfo[0][EV_LOG_NOW_OUTPUT_VOL] >= vol1 + CHK_VOL_RANGE) || (LogInfo[0][EV_LOG_NOW_OUTPUT_VOL] <= vol1 - CHK_VOL_RANGE) ||
+				(LogInfo[0][EV_LOG_NOW_OUTPUT_CUR] >= cur1 + CHK_CUR_RANGE) || (LogInfo[0][EV_LOG_NOW_OUTPUT_CUR] <= cur1 - CHK_CUR_RANGE))
+		{
+			PRINTF_FUNC("G_0 -> Output Vol = %.1f, Output Cur = %.1f \n", vol1 / 10, cur1 / 10);
+			LogInfo [0] [EV_LOG_NOW_OUTPUT_VOL] = vol1;
+			LogInfo [0] [EV_LOG_NOW_OUTPUT_CUR] = cur1;
+		}
+	}
+
+	if ((chargingData_2->SystemStatus >= SYS_MODE_PREPARING && chargingData_2->SystemStatus <= SYS_MODE_CHARGING) ||
+			(chargingData_2->SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0 && chargingData_2->SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))
+	{
+		if ((LogInfo[1][EV_LOG_NOW_OUTPUT_VOL] >= vol2 + CHK_VOL_RANGE) || (LogInfo[1][EV_LOG_NOW_OUTPUT_VOL] <= vol2 - CHK_VOL_RANGE) ||
+			(LogInfo[1][EV_LOG_NOW_OUTPUT_CUR] >= cur2 + CHK_CUR_RANGE) || (LogInfo[1][EV_LOG_NOW_OUTPUT_CUR] <= cur2 - CHK_CUR_RANGE))
+		{
+			PRINTF_FUNC("G_1 -> Output Vol = %.1f, Output Cur = %.1f \n", vol2 / 10, cur2 / 10);
+			LogInfo[1][EV_LOG_NOW_OUTPUT_VOL] = vol2;
+			LogInfo[1][EV_LOG_NOW_OUTPUT_CUR] = cur2;
+		}
+	}
+
+	targetCur = chargingData_2->EvBatterytargetCurrent * 10;
+	if (curTargetCur[1] != chargingData_2->EvBatterytargetCurrent * 10)
+	{
+		curTargetCur[1] = chargingData_2->EvBatterytargetCurrent * 10;
+		curAllowCount[1] = 0;
+	}
+
+	if (curAllowCount[1] < ALLOW_COUNT_MAX &&
+			chargingData_2->Type == _Type_CCS)
+	{
+		if (cur2 > targetCur + 100 || cur2 < targetCur - 100)
+		{
+			cur2 = targetCur;
+			curAllowCount[1]++;
+		}
+		else
+			curAllowCount[1] = 0;
+	}
+
+	if (!_useOfflineNoCharging)
+	{
+		if (ShmSysConfigAndInfo->SysInfo.OcppConnStatus == NO &&
+				ShmSysConfigAndInfo->SysConfig.OfflinePolicy == _OFFLINE_POLICY_NO_CHARGING)
+		{
+			PRINTF_FUNC("Offline Policy : No Charing... \n");
+			_useOfflineNoCharging = true;
+			cur1 = cur2 = 0;
+		}
+	}
+	else
+	{
+		if (ShmSysConfigAndInfo->SysInfo.OcppConnStatus == YES)
+			_useOfflineNoCharging = false;
+	}
+
+	SetPresentOutputPower(vol1, cur1, vol2, cur2);
+}
+
+void SetPresentChargingOutputCap(struct ChargingInfoData *chargingData_1, struct ChargingInfoData *chargingData_2)
+{
+	float pow1 = 0, cur1 = 0;
+	float pow2 = 0, cur2 = 0;
+	float vol = 0;
+
+	pow1 = chargingData_1->AvailableChargingPower;
+	cur1 = chargingData_1->AvailableChargingCurrent;
+	vol = chargingData_1->MaximumChargingVoltage;
+
+	if ((chargingData_1->SystemStatus >= SYS_MODE_PREPARING && chargingData_1->SystemStatus <= SYS_MODE_CHARGING) ||
+			(chargingData_1->SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0 && chargingData_1->SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))
+	{
+		GetMaxVolAndCurMethod(chargingData_1->Index, &vol, &cur1);
+		GetMaxPowerMethod(chargingData_1->Index, &pow1);
+		if (pow1 <= 0)
+			cur1 = 0;
+		else
+		{
+			if (chargingData_1->SystemStatus == SYS_MODE_CHARGING &&
+					chargingData_1->FireChargingVoltage > 1500)
+			{
+				float maxCur = 0;
+				maxCur = (pow1 * 1000) / chargingData_1->FireChargingVoltage;
+
+				if (maxCur * 10 <= cur1)
+				{
+					//PRINTF_FUNC("Gun1 -> MaxCharging Current = %f, Cap Current = %f \n", (maxCur * 10), cur1);
+					cur1 = maxCur * 10;
+				}
+			}
+		}
+	}
+	else
+	{
+		cur1 = chargingData_1->ConnectorMaxCurrent;
+	}
+
+	pow2 = chargingData_2->AvailableChargingPower;
+	cur2 = chargingData_2->AvailableChargingCurrent;
+	vol = chargingData_2->MaximumChargingVoltage;
+
+	if ((chargingData_2->SystemStatus >= SYS_MODE_PREPARING && chargingData_2->SystemStatus <= SYS_MODE_CHARGING) ||
+			(chargingData_2->SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0 && chargingData_2->SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))
+	{
+		GetMaxVolAndCurMethod(chargingData_2->Index, &vol, &cur2);
+		GetMaxPowerMethod(chargingData_2->Index, &pow2);
+		if (pow2 <= 0)
+			cur2 = 0;
+		else
+		{
+			if (chargingData_2->SystemStatus == SYS_MODE_CHARGING &&
+					chargingData_2->FireChargingVoltage > 1500)
+			{
+				float maxCur = 0;
+				maxCur = (pow2 * 1000) / chargingData_2->FireChargingVoltage;
+
+				if (maxCur * 10 <= cur2)
+				{
+					//PRINTF_FUNC("Gun2 -> MaxCharging Current = %f, Cap Current = %f \n", (maxCur * 10), cur2);
+					cur2 = maxCur * 10;
+				}
+			}
+		}
+	}
+	else
+	{
+		cur2 = chargingData_2->ConnectorMaxCurrent;
+	}
+
+	if ((LogInfo[0][EV_LOG_OUTPUT_CAP_POW] <= pow1 - 5 || LogInfo[0][EV_LOG_OUTPUT_CAP_POW] >= pow1 + 5) ||
+		(LogInfo[0][EV_LOG_OUTPUT_CAP_CUR] <= cur1 - 5 || LogInfo[0][EV_LOG_OUTPUT_CAP_CUR] >= cur1 + 5) ||
+		(LogInfo[1][EV_LOG_OUTPUT_CAP_POW] <= pow2 - 5 || LogInfo[1][EV_LOG_OUTPUT_CAP_POW] >= pow2 + 5) ||
+		(LogInfo[1][EV_LOG_OUTPUT_CAP_CUR] <= cur2 - 5 || LogInfo[1][EV_LOG_OUTPUT_CAP_CUR] >= cur2 + 5))
+	{
+		PRINTF_FUNC("----------------------------------------------------- \n");
+		PRINTF_FUNC("To EV (Real) Power_1 = %.1f, Cur_1 = %.1f, Power_2 = %.1f, Cur_2 = %.1f \n",
+				pow1 / 10, cur1 / 10, pow2 / 10, cur2 / 10);
+		PRINTF_FUNC("----------------------------------------------------- \n");
+
+		LogInfo[0][EV_LOG_OUTPUT_CAP_POW] = pow1;
+		LogInfo[0][EV_LOG_OUTPUT_CAP_CUR] = cur1;
+		LogInfo[1][EV_LOG_OUTPUT_CAP_POW] = pow2;
+		LogInfo[1][EV_LOG_OUTPUT_CAP_CUR] = cur2;
+		chargingData_1->RealMaxCurrent = cur1;
+		chargingData_1->RealMaxPower = pow1;
+
+		if (gun_count == 2)
+		{
+			chargingData_2->RealMaxCurrent = cur2;
+			chargingData_2->RealMaxPower = pow2;
+		}
+	}
+
+	SetPresentOutputCapacity(pow1, cur1, pow2, cur2);
+}
+
+void Initialization()
+{
+	bool isPass = false;
+	while(!isPass)
+	{
+		isPass = true;
+		for (byte _index = 0; _index < gun_count; _index++)
+		{
+			if (!FindChargingInfoData(_index, &_chargingData[0]))
+			{
+				DEBUG_ERROR("EvComm (main) : FindChargingInfoData false \n");
+				isPass = false;
+				break;
+			}
+		}
+		sleep(1);
+	}
+
+	GetTimespecFunc(&delayToPrintLogTimeout);
+}
+
+void GetMaxVolAndCurMethod(byte index, float *vol, float *cur)
+{
+//	unsigned short configCurrent = ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent * 10;
+//
+//	if (ShmSysConfigAndInfo->SysInfo.MainChargingMode == _MAIN_CHARGING_MODE_AVER)
+//		configCurrent /= 2;
+//
+//	if (configCurrent != 0 && configCurrent < *cur)
+//		*cur = configCurrent;
+
+	if (_chargingData[index]->ConnectorMaxVoltage != 0 &&
+			_chargingData[index]->ConnectorMaxVoltage <= *vol)
+		*vol = _chargingData[index]->ConnectorMaxVoltage;
+
+	if (_chargingData[index]->ConnectorMaxCurrent != 0 &&
+			_chargingData[index]->ConnectorMaxCurrent <= *cur)
+		*cur = _chargingData[index]->ConnectorMaxCurrent;
+
+	if (((_chargingData[index]->SystemStatus >= SYS_MODE_PREPARE_FOR_EVSE && _chargingData[index]->SystemStatus <= SYS_MODE_CHARGING) ||
+			(_chargingData[index]->SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0 && _chargingData[index]->SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1)) &&
+			_chargingData[index]->ChargingProfileCurrent >= 0 &&
+			_chargingData[index]->ChargingProfileCurrent <= *cur)
+	{
+		*cur = _chargingData[index]->ChargingProfileCurrent;
+	}
+}
+
+void GetMaxPowerMethod(byte index, float *pow)
+{
+	if (maxChargingPow != 0 && maxChargingPow <= *pow)
+		*pow = maxChargingPow;
+
+	if (_chargingData[index]->RealRatingPower * 10 != 0 && _chargingData[index]->RealRatingPower * 10 <= *pow)
+		*pow = _chargingData[index]->RealRatingPower * 10;
+
+	// 100 = (/ 1000 * 10)
+	if (((_chargingData[index]->SystemStatus >= SYS_MODE_PREPARE_FOR_EVSE && _chargingData[index]->SystemStatus <= SYS_MODE_CHARGING) ||
+			(_chargingData[index]->SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0 && _chargingData[index]->SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1)) &&
+			(_chargingData[index]->ChargingProfilePower / 100) >= 0 &&
+			(_chargingData[index]->ChargingProfilePower / 100) <= *pow)
+	{
+		*pow = (float)(_chargingData[index]->ChargingProfilePower / 100);
+	}
+}
+
+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 + 0)  = '0';
+		*(reason + 1)  = '1';
+		*(reason + 2)  = '2';
+		*(reason + 3)  = '2';
+		*(reason + 4)  = '5';
+		*(reason + 5)  = '1';
+		result = YES;
+	}
+	else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DoorOpen == 0x01)
+	{
+		// 012251
+		*(reason + 0)  = '0';
+		*(reason + 1)  = '1';
+		*(reason + 2)  = '2';
+		*(reason + 3)  = '2';
+		*(reason + 4)  = '5';
+		*(reason + 5)  = '2';
+		result = YES;
+	}
+
+	if (_chargingData[gunIndex]->Type == _Type_Chademo)
+	{
+		if (ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaRelayDrivingFault == YES)
+		{
+			// 011012
+			*(reason + 0) = '0';
+			*(reason + 1) = '1';
+			*(reason + 2) = '1';
+			*(reason + 3) = '0';
+			*(reason + 4) = '1';
+			*(reason + 5) = '2';
+			result = YES;
+		}
+		else if (ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaUvpFail == YES)
+		{
+			// 012289
+			*(reason + 0) = '0';
+			*(reason + 1) = '1';
+			*(reason + 2) = '2';
+			*(reason + 3) = '2';
+			*(reason + 4) = '8';
+			*(reason + 5) = '9';
+			result = YES;
+		}
+		else if (ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaGfdTrip == YES)
+		{
+			// 012234
+			*(reason + 0) = '0';
+			*(reason + 1) = '1';
+			*(reason + 2) = '2';
+			*(reason + 3) = '2';
+			*(reason + 4) = '3';
+			*(reason + 5) = '4';
+			result = YES;
+		}
+		else if (ShmSysConfigAndInfo->SysConfig.PhaseLossPolicy == YES &&
+				(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputUVP == YES ||
+						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputUVP == YES ||
+						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputUVP == YES))
+		{
+			// 012203-012204-012205
+			* (reason + 0) = '0';
+			* (reason + 1) = '1';
+			* (reason + 2) = '2';
+			* (reason + 3) = '2';
+			* (reason + 4) = '0';
+			* (reason + 5) = '3';
+			result = YES;
+		}
+	}
+	else if (_chargingData[gunIndex]->Type == _Type_GB)
+	{
+		if (ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTRelayDrivingFault == YES)
+		{
+			// 012290
+			*(reason + 0) = '0';
+			*(reason + 1) = '1';
+			*(reason + 2) = '2';
+			*(reason + 3) = '2';
+			*(reason + 4) = '9';
+			*(reason + 5) = '0';
+			result = YES;
+		}
+		else if (ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTUvpFail == YES)
+		{
+			// 012290
+			*(reason + 0) = '0';
+			*(reason + 1) = '1';
+			*(reason + 2) = '2';
+			*(reason + 3) = '2';
+			*(reason + 4) = '9';
+			*(reason + 5) = '0';
+			result = YES;
+		}
+		else if (ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTGfdTrip == YES)
+		{
+			// 012236
+			*(reason + 0) = '0';
+			*(reason + 1) = '1';
+			*(reason + 2) = '2';
+			*(reason + 3) = '2';
+			*(reason + 4) = '3';
+			*(reason + 5) = '6';
+			result = YES;
+		}
+	}
+	else if (_chargingData[gunIndex]->Type == _Type_CCS)
+	{
+		if (ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSRelayDrivingFault == YES)
+		{
+			// 011014
+			*(reason + 0) = '0';
+			*(reason + 1) = '1';
+			*(reason + 2) = '1';
+			*(reason + 3) = '0';
+			*(reason + 4) = '1';
+			*(reason + 5) = '4';
+			result = YES;
+		}
+		else if (ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSUvpFail == YES)
+		{
+			// 012288
+			*(reason + 0) = '0';
+			*(reason + 1) = '1';
+			*(reason + 2) = '2';
+			*(reason + 3) = '2';
+			*(reason + 4) = '8';
+			*(reason + 5) = '8';
+			result = YES;
+		}
+		else if (ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSGfdTrip == YES)
+		{
+			// 012235
+			*(reason + 0) = '0';
+			*(reason + 1) = '1';
+			*(reason + 2) = '2';
+			*(reason + 3) = '2';
+			*(reason + 4) = '3';
+			*(reason + 5) = '5';
+			result = YES;
+		}
+	}
+
+	return result;
+}
+
+void SendCommunicationOnly(byte index)
+{
+	byte targetID = _chargingData[index]->Evboard_id;
+
+	if (gun_count == 1 &&
+			_chargingData[index]->Type == _Type_CCS &&
+			ShmDcCommonData->CcsVersion == _CCS_VERSION_CHECK_TAG_V015S0)
+	{
+		targetID += 1;
+	}
+
+	SetChargingPermission(index, COMMUNICATION,
+		_chargingData[index]->AvailableChargingPower,
+		0,
+		0,
+		targetID);
+}
+
+void SendStopOnly(byte index)
+{
+	byte targetID = _chargingData[index]->Evboard_id;
+
+	if (gun_count == 1 &&
+			_chargingData[index]->Type == _Type_CCS &&
+			ShmDcCommonData->CcsVersion == _CCS_VERSION_CHECK_TAG_V015S0)
+	{
+		targetID += 1;
+	}
+
+	SetChargingPermission(index, STOP,
+		_chargingData[index]->AvailableChargingPower,
+		0,
+		0,
+		targetID);
+}
+
+void InitialConnectorStatus(byte index)
+{
+	SetChargingPermission(index, INITIALIZATION,
+		0,
+		0,
+		0,
+		_chargingData[index]->Evboard_id);
+}
+
+void FormatVoltageAndCurrent()
+{
+	char isLowCur = 0x00;
+	char EvsePower[2];
+
+	EvsePower[2] = '\0';
+	if (strlen((char *) ShmSysConfigAndInfo->SysConfig.ModelName) >= 6)
+	{
+		strncpy(EvsePower, (char *)(ShmSysConfigAndInfo->SysConfig.ModelName + 4), 2);
+
+		if (strcmp(EvsePower, "30") == EQUAL)
+		{
+			isLowCur = 0x00;
+		}
+		else if (strcmp(EvsePower, "60") == EQUAL)
+		{
+			isLowCur = 0x01;
+		}
+		else
+		{
+			// 60KW 以上的系統
+			isLowCur = 0x02;
+		}
+	}
+
+	for (byte _index = 0; _index < gun_count; _index++)
+	{
+		if (_chargingData[_index]->Type == _Type_Chademo)
+		{
+			if (ShmDcCommonData->chargerType == CHARGER_TYPE_STANDARD)
+				_chargingData[_index]->ConnectorMaxVoltage = Chademo_Standard;
+			else
+				_chargingData[_index]->ConnectorMaxVoltage = Chademo_Simple;
+		}
+		else if (_chargingData[_index]->Type == _Type_CCS)
+		{
+			if (ShmDcCommonData->chargerType == CHARGER_TYPE_STANDARD)
+				_chargingData[_index]->ConnectorMaxVoltage = CCS_Standard;
+			else
+				_chargingData[_index]->ConnectorMaxVoltage = CCS_Simple;
+		}
+		else if (_chargingData[_index]->Type == _Type_GB)
+		{
+			if (ShmDcCommonData->chargerType == CHARGER_TYPE_STANDARD)
+				_chargingData[_index]->ConnectorMaxVoltage = GB_Standard;
+			else
+				_chargingData[_index]->ConnectorMaxVoltage = GB_Simple;
+		}
+
+		if (isLowCur == 0x00)
+		{
+			if (_chargingData[_index]->Type == _Type_Chademo)
+			{
+				if (_chargingData[_index]->ModelType == 'L')
+					_chargingData[_index]->ConnectorMaxCurrent = 800;
+				else
+					_chargingData[_index]->ConnectorMaxCurrent = 600;
+			}
+			else if (_chargingData[_index]->Type == _Type_CCS)
+			{
+				if (_chargingData[_index]->ModelType == 'M' ||
+						_chargingData[_index]->ModelType == 'N')
+					_chargingData[_index]->ConnectorMaxCurrent = 800;
+				else
+					_chargingData[_index]->ConnectorMaxCurrent = 600;
+			}
+			else if (_chargingData[_index]->Type == _Type_GB)
+			{
+				_chargingData[_index]->ConnectorMaxCurrent = 800;
+			}
+		}
+		else if (isLowCur == 0x01)
+		{
+			if (_chargingData[_index]->Type == _Type_Chademo)
+			{
+				_chargingData[_index]->ConnectorMaxCurrent = 1200;
+			}
+			else if (_chargingData[_index]->Type == _Type_CCS)
+			{
+				if (_chargingData [_index]->ModelType == 'Y' ||
+						_chargingData [_index]->ModelType == 'Z')
+					_chargingData [_index]->ConnectorMaxCurrent = 1500;
+				else
+					_chargingData [_index]->ConnectorMaxCurrent = 1200;
+			}
+			else if (_chargingData[_index]->Type == _Type_GB)
+			{
+				_chargingData[_index]->ConnectorMaxCurrent = 1200;
+			}
+		}
+		else
+		{
+			if (_chargingData[_index]->Type == _Type_Chademo)
+			{
+				if (_chargingData[_index]->ModelType == 'K')
+					_chargingData[_index]->ConnectorMaxCurrent = 2000;
+				else
+					_chargingData[_index]->ConnectorMaxCurrent = 1200;
+			}
+			else if (_chargingData[_index]->Type == _Type_CCS)
+			{
+				if (_chargingData [_index]->ModelType == 'V' ||
+						_chargingData [_index]->ModelType == 'F')
+					_chargingData [_index]->ConnectorMaxCurrent = 5000;
+				if (_chargingData [_index]->ModelType == 'T' ||
+						_chargingData [_index]->ModelType == 'D')
+					_chargingData [_index]->ConnectorMaxCurrent = 3000;
+				else if (_chargingData [_index]->ModelType == 'R')
+					_chargingData [_index]->ConnectorMaxCurrent = 2500;
+				else
+					_chargingData [_index]->ConnectorMaxCurrent = 2000;
+			}
+			else if (_chargingData[_index]->Type == _Type_GB)
+			{
+				_chargingData[_index]->ConnectorMaxCurrent = 2500;
+			}
+		}
+	}
+
+	if (ShmDcCommonData->chargerType == CHARGER_TYPE_SIMPLE &&
+			strcmp(EvsePower, "18") == EQUAL)
+	{
+		// 簡易版且180KW -> 限制最小輸出電流 50A
+		ShmDcCommonData->minOutputCur = 50;
+	}
+}
+
+// 如果是使用 Meter 計算的話
+void CalOutputPowerAndEnergy(int _index)
+{
+	if(ShmSysConfigAndInfo->SysConfig.ModelName[3] == 'M' ||
+			ShmSysConfigAndInfo->SysConfig.ModelName[3] == 'L')
+	{
+		// AC Meter
+		//printf("(%d), totalChargingValue = %f \n", _index, ShmCsuMeterData->_meter[_index]._curTotalCharging / 100);
+		float totalChargingValue = ShmCsuMeterData->_meter[_index]._curTotalCharging / 100;
+
+		if (totalChargingValue > _chargingData[_index]->PresentChargedEnergy)
+		{
+			ShmDcCommonData->energy_time_period[_index][ShmDcCommonData->_hour_index] += totalChargingValue - _chargingData[_index]->PresentChargedEnergy;
+			_chargingData[_index]->PowerConsumption += totalChargingValue - _chargingData[_index]->PresentChargedEnergy;
+		}
+
+		_chargingData[_index]->PresentChargedEnergy = totalChargingValue;
+
+		if (ShmSysConfigAndInfo->SysConfig.BillingData.isBilling)
+		{
+			if(strcmp((char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, "") == EQUAL ||
+				strcmp((char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId, "") == EQUAL)
+				_chargingData[_index]->ChargingFee = totalChargingValue * ShmSysConfigAndInfo->SysConfig.BillingData.Cur_fee;
+		}
+	}
+	else if (ShmSysConfigAndInfo->SysConfig.ModelName[3] == 'P')
+	{
+		// DC Meter
+		if (ShmCsuMeterData->_meter[_index].curMeterValue == 0)
+				ShmCsuMeterData->_meter[_index].curMeterValue = ShmSysConfigAndInfo->SysInfo.DcMeterInfo[_index].totlizeImportEnergy;
+		else
+		{
+			if (ShmSysConfigAndInfo->SysInfo.DcMeterInfo[_index].totlizeImportEnergy > ShmCsuMeterData->_meter[_index].curMeterValue)
+			{
+				ShmCsuMeterData->_meter[_index]._curTotalCharging += ShmSysConfigAndInfo->SysInfo.DcMeterInfo[_index].totlizeImportEnergy - ShmCsuMeterData->_meter[_index].curMeterValue;
+				float totalChargingValue = ShmCsuMeterData->_meter[_index]._curTotalCharging;
+
+				if (totalChargingValue > _chargingData[_index]->PresentChargedEnergy)
+				{
+					ShmDcCommonData->energy_time_period[_index][ShmDcCommonData->_hour_index] += totalChargingValue - _chargingData[_index]->PresentChargedEnergy;
+					_chargingData[_index]->PowerConsumption += totalChargingValue - _chargingData[_index]->PresentChargedEnergy;
+				}
+
+				_chargingData[_index]->PresentChargedEnergy = totalChargingValue;
+
+				if (ShmSysConfigAndInfo->SysConfig.BillingData.isBilling)
+				{
+					if(strcmp((char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, "") == EQUAL ||
+						strcmp((char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId, "") == EQUAL)
+						_chargingData[_index]->ChargingFee = totalChargingValue * ShmSysConfigAndInfo->SysConfig.BillingData.Cur_fee;
+				}
+
+				ShmCsuMeterData->_meter[_index].curMeterValue = ShmSysConfigAndInfo->SysInfo.DcMeterInfo[_index].totlizeImportEnergy;
+			}
+		}
+	}
+	else
+	{
+		if (chargingTime[_index] == 0 ||
+			chargingTime[_index] > _chargingData[_index]->PresentChargedDuration)
+		{
+			chargingTime[_index] = _chargingData[_index]->PresentChargedDuration;
+		}
+		else
+		{
+			int passTime = _chargingData[_index]->PresentChargedDuration - chargingTime[_index];
+
+			if (passTime > 0)
+			{
+				float changingPow = (_chargingData[_index]->PresentChargingPower) * passTime / 3600;
+				if (ShmSysConfigAndInfo->SysConfig.BillingData.isBilling)
+				{
+					ShmDcCommonData->energy_time_period[_index][ShmDcCommonData->_hour_index] += changingPow;
+
+					if(strcmp((char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, "") == EQUAL ||
+						strcmp((char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId, "") == EQUAL)
+						_chargingData[_index]->ChargingFee += changingPow * ShmSysConfigAndInfo->SysConfig.BillingData.Cur_fee;
+				}
+
+				_chargingData[_index]->PowerConsumption += changingPow;
+				_chargingData[_index]->PresentChargedEnergy += changingPow;
+				chargingTime[_index] = _chargingData[_index]->PresentChargedDuration;
+			}
+		}
+	}
+}
+
+void ConnectorOTP(byte _index)
+{
+	bool isOTP = false;
+
+	if (_chargingData[_index]->Type == _Type_Chademo)
+	{
+		if (ShmDcCommonData->ConnectErrList[_index].GunBits.ChaConnectOTP)
+			isOTP = true;
+	}
+	else if (_chargingData[_index]->Type == _Type_CCS)
+	{
+		if (ShmDcCommonData->ConnectErrList[_index].GunBits.CCSConnectOTP)
+			isOTP = true;
+	}
+	else if (_chargingData[_index]->Type == _Type_GB)
+	{
+		if (ShmDcCommonData->ConnectErrList[_index].GunBits.GBTConnectOTP)
+			isOTP = true;
+	}
+
+	if (isOTP)
+	{
+		if (gunTempAllowCount[_index] >= 2)
+			_chargingData[_index]->StopChargeFlag = YES;
+		else
+			gunTempAllowCount[_index] += 1;
+	}
+	else
+		gunTempAllowCount[_index] = 0;
+}
+
+void OfferCurrentAndPowerRecord(byte _index)
+{
+	// 網頁設定值
+	unsigned short maxCurBuf = ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent * 10;
+	unsigned short maxPowBuf = ShmSysConfigAndInfo->SysConfig.MaxChargingPower * 10;
+
+	//_chargingData[_index]->CurrentOffered = 1200;
+	//_chargingData [_index]->PowerOffered = 300;
+	//{"value":"120","context":"Sample.Periodic","format":"Raw","measurand":"Current.Offered","location":"Outlet","unit":"A"}
+	//{"value":"30000","context":"Sample.Periodic","format":"Raw","measurand":"Power.Offered","location":"Outlet","unit":"W"}
+	if (ShmSysConfigAndInfo->SysInfo.MainChargingMode == _MAIN_CHARGING_MODE_AVER)
+	{
+		maxCurBuf /= 2; maxPowBuf /= 2;
+	}
+
+	if (_index == 1 && ShmSysConfigAndInfo->SysInfo.IsAlternatvieConf)
+	{
+		_chargingData [1]->PowerOffered = _chargingData [0]->PowerOffered;
+		_chargingData [1]->CurrentOffered = _chargingData [0]->CurrentOffered;
+	}
+	else
+	{
+		if (_chargingData[_index]->ConnectorMaxCurrent > 0)
+		{
+			if (maxCurBuf == 0)
+				_chargingData[_index]->CurrentOffered = _chargingData[_index]->ConnectorMaxCurrent;
+			else
+				_chargingData[_index]->ConnectorMaxCurrent >= maxCurBuf ?
+						(_chargingData[_index]->CurrentOffered = maxCurBuf) :
+						(_chargingData[_index]->CurrentOffered = _chargingData[_index]->ConnectorMaxCurrent);
+		}
+		else
+			_chargingData[_index]->CurrentOffered = 0;
+
+		if (ShmPsuData->PsuGroup [_index].GroupAvailablePower > 0)
+		{
+			if (maxPowBuf == 0)
+			{
+				if (ShmSysConfigAndInfo->SysInfo.MainChargingMode == _MAIN_CHARGING_MODE_AVER)
+					_chargingData [_index]->PowerOffered = ShmPsuData->PsuGroup [_index].GroupAvailablePower;
+				else
+					_chargingData [_index]->PowerOffered = ShmPsuData->SystemAvailablePower;
+			}
+			else
+			{
+				if (ShmSysConfigAndInfo->SysInfo.MainChargingMode == _MAIN_CHARGING_MODE_AVER)
+				{
+					ShmPsuData->PsuGroup[_index].GroupAvailablePower >= maxPowBuf ?
+							(_chargingData [_index]->PowerOffered = maxPowBuf) :
+							(_chargingData [_index]->PowerOffered = ShmPsuData->PsuGroup [_index].GroupAvailablePower);
+				}
+				else
+				{
+					ShmPsuData->SystemAvailablePower >= maxPowBuf ?
+							(_chargingData [_index]->PowerOffered = maxPowBuf) :
+							(_chargingData [_index]->PowerOffered = ShmPsuData->SystemAvailablePower);
+				}
+			}
+		}
+		else
+			_chargingData [_index]->PowerOffered = 0;
+	}
+}
+
+bool IsTimeToPrintLog()
+{
+	bool result = false;
+
+	int _timebuf = GetTimeoutValue(&delayToPrintLogTimeout);
+
+	if (_timebuf < 0)
+		GetTimespecFunc (&delayToPrintLogTimeout);
+	else
+	{
+		if (_timebuf >= 5)
+			result = true;
+	}
+
+	return result;
+}
+
+void InitTimeToPrintLog()
+{
+	GetTimespecFunc (&delayToPrintLogTimeout);
+}
+
+void AuthorizeByCcid(byte _index)
+{
+	if (_chargingData[_index]->Type == _Type_CCS &&
+			_chargingData [_index]->IsAvailable &&
+			ShmDcCommonData->enObtainAuthorizbyCCID &&
+			strcmp ( (char *) _chargingData[_index]->StartUserId, "") == EQUAL)
+	{
+		if (_chargingData [_index]->ConnectorPlugIn)
+		{
+			if (ShmDcCommonData->_authWithCcidFlag [_index] == _CCID_NONE)
+			{
+				if (printLogRecord)
+					PRINTF_FUNC ( "index = %d, Wait for CCID. \n", _index );
+
+				if (strcmp ( (char *) _chargingData [_index]->EVCCID, "" ) == EQUAL)
+				{
+					SendCommunicationOnly ( _index );
+					GetEvccIdReq ( _index, _chargingData [_index]->Evboard_id );
+				}
+				else
+					ShmDcCommonData->_authWithCcidFlag [_index] = _CCID_GET;
+			}
+			else if (ShmDcCommonData->_authWithCcidFlag [_index] == _CCID_AUTHFAIL)
+			{
+				SendStopOnly ( _index );
+				strcpy ( (char *) _chargingData [_index]->EVCCID, "" );
+			}
+		}
+		else
+		{
+			SendStopOnly ( _index );
+		}
+	}
+}
+
+int main(int argc, char *argv[])
+{
+	if(InitShareMemory() == FAIL)
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR("InitShareMemory NG\n");
+		#endif
+		if(ShmStatusCodeData != NULL)
+		{
+			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
+		}
+		sleep(5);
+		return 0;
+	}
+
+	gun_count = ShmSysConfigAndInfo->SysConfig.TotalConnectorCount;
+	Initialization();
+	// 根據輸出能量與槍別給予當前最大耐壓耐流
+	FormatVoltageAndCurrent();
+	CanFd = InitCanBus();
+	CANReceiver();
+
+	byte priorityLow = 1;
+	time_t rtc = GetRtcInfoForEpoch();
+
+	for (byte _index = 0; _index < gun_count; _index++)
+	{
+		if (_chargingData[_index]->Type == _Type_Chademo)
+		{
+			PRINTF_FUNC("Conn %d (Chademo), MaxVol = %f, MaxCur = %f \n",
+				_index,
+				_chargingData[_index]->ConnectorMaxVoltage,
+				_chargingData[_index]->ConnectorMaxCurrent);
+		}
+		else if (_chargingData[_index]->Type == _Type_CCS)
+		{
+			PRINTF_FUNC("Conn %d (CCS), MaxVol = %f, MaxCur = %f \n",
+				_index,
+				_chargingData[_index]->ConnectorMaxVoltage,
+				_chargingData[_index]->ConnectorMaxCurrent);
+		}
+		else if (_chargingData[_index]->Type == _Type_GB)
+		{
+			PRINTF_FUNC("Conn %d (GBT), MaxVol = %f, MaxCur = %f \n",
+				_index,
+				_chargingData[_index]->ConnectorMaxVoltage,
+				_chargingData[_index]->ConnectorMaxCurrent);
+		}
+	}
+
+	int _timeBuf = 0;
+
+	while(CanFd)
+	{
+		printLogRecord = IsTimeToPrintLog();
+
+		for(byte _index = 0; _index < gun_count; _index++)
+		{
+			byte targetID = _chargingData[_index]->Evboard_id;
+
+			if (gun_count == 1 &&
+					_chargingData[_index]->Type == _Type_CCS &&
+					ShmDcCommonData->CcsVersion == _CCS_VERSION_CHECK_TAG_V015S0)
+			{
+				targetID += 1;
+			}
+
+			if (priorityLow == 1)
+			{
+				// 優先權較低 - 只要有回應即不會再詢問
+				if (_chargingData[_index]->Type == _Type_Chademo)
+				{
+					if (ShmCHAdeMOData->evse[_chargingData[_index]->type_index].SelfTest_Comp != PASS)
+					{
+						if (rtcChkCount == 0)
+							SyncRtcInfo(_index, _chargingData[_index]->Evboard_id, (int)rtc);
+						GetFirmwareVersion(_index, _chargingData[_index]->Evboard_id);
+					}
+
+					if (ShmDcCommonData->evBoardResetFlag)
+						InitialConnectorStatus(_index);
+				}
+				else if (_chargingData[_index]->Type == _Type_GB)
+				{
+					if (ShmGBTData->evse[_chargingData[_index]->type_index].SelfTest_Comp != PASS)
+					{
+						if (rtcChkCount == 0)
+							SyncRtcInfo(_index, _chargingData[_index]->Evboard_id, (int)rtc);
+						GetFirmwareVersion(_index, _chargingData[_index]->Evboard_id);
+					}
+
+					if (ShmDcCommonData->evBoardResetFlag)
+						InitialConnectorStatus(_index);
+				}
+				else if (_chargingData[_index]->Type == _Type_CCS)
+				{
+					if (ShmCcsData->CommProtocol == _CCS_COMM_V2GMessage_DIN70121 &&
+						ShmCcsData->V2GMessage_DIN70121[_chargingData[_index]->type_index].SelfTest_Comp != PASS)
+					{
+						if (rtcChkCount == 0)
+							SyncRtcInfo(_index, targetID, (int)rtc);
+						GetFirmwareVersion(_index, targetID);
+						SetConnectInfo(ShmDcCommonData->CcsTypeSaved[_index], targetID);
+					}
+				}
+
+				if (rtcChkCount >= 2)
+					rtcChkCount = 0;
+				else
+					rtcChkCount++;
+
+				// 固定要取得的資訊 : 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),
+						targetID);
+
+				ConnectorOTP(_index);
+
+				OfferCurrentAndPowerRecord(_index);
+			}
+
+			switch (_chargingData[_index]->SystemStatus)
+			{
+				case SYS_MODE_IDLE:
+				case SYS_MODE_RESERVATION:
+					if (_chargingData[_index]->Type == _Type_Chademo)
+					{
+						ClearAbnormalStatus_Chademo(_index);
+						if (ShmSysConfigAndInfo->SysInfo.PageIndex == _LCM_WAIT_FOR_PLUG ||
+								ShmDcCommonData->_cha_try_communication[_index].try2CommunicationFlag)
+						{
+							if (!chkChademoPermission[_index])
+							{
+								chkChademoPermission[_index] = true;
+								GetTimespecFunc(&_chk_chademo_permission_timeout[_index]);
+								SendStopOnly(_index);
+								chkChademoPermissionSend[_index] = NO;
+							}
+							else
+							{
+								_timeBuf = GetTimeoutValue(&_chk_chademo_permission_timeout[_index]);
+
+								if (_timeBuf < 0)
+									GetTimespecFunc(&_chk_chademo_permission_timeout[_index]);
+								else
+								{
+									if (_timeBuf > 2)
+									{
+										if (chkChademoPermissionSend[_index] == NO)
+										{
+											chkChademoPermissionSend[_index] = YES;
+											SendCommunicationOnly(_index);
+										}
+										if (_timeBuf > 10)
+										{
+											chkChademoPermissionSend[_index] = NO;
+											GetTimespecFunc(&_chk_chademo_permission_timeout[_index]);
+										}
+									}
+								}
+							}
+						}
+						else if (chkChademoPermission[_index])
+						{
+							chkChademoPermission[_index] = false;
+							//SendStopOnly(_index);
+						}
+
+						if (ShmDcCommonData->ConnectErrList[_index].GunBits.ChaConnectOTP == NO)
+							_chargingData[_index]->StopChargeFlag = NO;
+
+					}
+					else if (_chargingData[_index]->Type == _Type_GB)
+					{
+						ClearAbnormalStatus_GB(_index);
+
+						if (ShmDcCommonData->ConnectErrList[_index].GunBits.GBTConnectOTP == NO)
+							_chargingData[_index]->StopChargeFlag = NO;
+					}
+					else if (_chargingData[_index]->Type == _Type_CCS)
+					{
+						ClearAbnormalStatus_CCS(_index);
+
+						if (ShmDcCommonData->ConnectErrList[_index].GunBits.CCSConnectOTP == NO)
+							_chargingData[_index]->StopChargeFlag = NO;
+					}
+
+					if (priorityLow == 1 || printLogRecord)
+					{
+						_chargingData[_index]->PresentChargedEnergy = 0;
+						_chargingData[_index]->PresentChargingPower = 0;
+						_chargingData[_index]->GroundFaultStatus = GFD_WAIT;
+						_chargingData[_index]->RealRatingPower = 0;
+						_chargingData[_index]->NormalStopChargeFlag = NO;
+						_chargingData[_index]->ChargingFee = 0.0;
+						_chargingData[_index]->EvBatterySoc = 0;
+						_chargingData[_index]->EvBatteryStartSoc = 0;
+						_chargingData[_index]->EvBatteryMaxVoltage = 0;
+						_chargingData[_index]->ChargingProfilePower = -1;
+						_chargingData[_index]->ChargingProfileCurrent = -1;
+						curAllowCount[_index] = 0;
+						curTargetCur[_index] = 0;
+
+						if (ShmSysConfigAndInfo->SysInfo.MainChargingMode == _MAIN_CHARGING_MODE_MAX)
+						{
+							_chargingData[_index]->PresentChargingVoltage = 0;
+							_chargingData[_index]->PresentChargingCurrent = 0;
+						}
+
+						chargingTime[_index] = 0;
+						SendErrorCount[_index] = 0;
+
+						// 使用 Meter 狀況
+						if(ShmSysConfigAndInfo->SysConfig.ModelName[3] == 'M' ||
+								ShmSysConfigAndInfo->SysConfig.ModelName[3] == 'L')
+						{
+							if (ShmCsuMeterData->_meter[_index].isCalculation == NO)
+							{
+								if (ShmCsuMeterData->_meter[_index].curMeterValue != 0 ||
+									ShmCsuMeterData->_meter[_index]._chargingValue != 0 ||
+									ShmCsuMeterData->_meter[_index]._curTotalCharging != 0 )
+								{
+									ShmCsuMeterData->_meter[_index].curMeterValue = 0;
+									ShmCsuMeterData->_meter[_index]._chargingValue = 0;
+									ShmCsuMeterData->_meter[_index]._curTotalCharging = 0;
+								}
+							}
+						}
+
+						//maxChargingPow = ShmSysConfigAndInfo->SysConfig.MaxChargingPower * 10;
+						// ShmPsuData->SystemAvailablePower 已是 * 10
+						maxChargingPow = ShmPsuData->SystemAvailablePower;
+						if (ShmSysConfigAndInfo->SysConfig.MaxChargingPower * 10 != 0 &&
+								ShmSysConfigAndInfo->SysConfig.MaxChargingPower * 10 < maxChargingPow)
+							maxChargingPow = ShmSysConfigAndInfo->SysConfig.MaxChargingPower * 10;
+
+						LogInfo[_index][EV_LOG_EVSE_MAX_VOL] = 0;
+						LogInfo[_index][EV_LOG_EVSE_MAX_CUR] = 0;
+						LogInfo[_index][EV_LOG_MAX_BATT_VOL] = 0;
+						LogInfo[_index][EV_LOG_REAL_CAP_POW] = 0;
+						LogInfo[_index][EV_LOG_SOC] = 0;
+
+						if (gun_count == 1)
+							SetPresentChargingOutputPower(_chargingData[0], _chargingData[0]);
+						else if (gun_count == 2)
+							SetPresentChargingOutputPower(_chargingData[0], _chargingData[1]);
+					}
+					break;
+				case SYS_MODE_PREPARING:
+				{
+					chkChademoPermission[_index] = false;
+					// 設定當前輸出
+					if (gun_count == 1)
+						SetPresentChargingOutputPower(_chargingData[0], _chargingData[0]);
+					else if (gun_count == 2)
+						SetPresentChargingOutputPower(_chargingData[0], _chargingData[1]);
+				}
+					break;
+				case SYS_MODE_PREPARE_FOR_EV:
+				{
+					AuthorizeByCcid(_index);
+
+					if (ShmDcCommonData->startTransactionFlag[_index] == START_TRANSATION_STATUS_WAIT)
+						continue;
+
+					if (_chargingData[_index]->Type == _Type_CCS)
+						GetEvccIdReq(_index, _chargingData[_index]->Evboard_id);
+
+					// 開始確認車端是否同意開始充電 : 1.SOC, 2.Target Vol, 3.Target Cur, 4.Charging remaining time
+					GetOutputReq(_index, targetID);
+
+					// 設定當前輸出
+					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);
+
+						if (LogInfo[_index][EV_LOG_EVSE_MAX_VOL] != maxVol ||
+								LogInfo[_index][EV_LOG_EVSE_MAX_CUR] != maxCur)
+						{
+							LogInfo[_index][EV_LOG_EVSE_MAX_VOL] = maxVol;
+							LogInfo[_index][EV_LOG_EVSE_MAX_CUR] = maxCur;
+
+							PRINTF_FUNC("To EV_%d Max_Vol = %.1f, Cap_Cur = %.1f, Cap_Pow = %.1f \n",
+								_index, maxVol / 10, maxCur / 10, _chargingData[_index]->AvailableChargingPower / 10);
+						}
+
+						_chargingData[_index]->RealMaxVoltage = maxVol;
+						SetChargingPermission ( _index, START,
+							_chargingData [_index]->AvailableChargingPower,
+							maxCur,  maxVol, targetID );
+
+						// 取得車端電池資訊 : 1.AC or DC ? 2.Total battery cap, 3.Max battery vol, 4.Max battery cur
+						GetEvBatteryInfo(_index, targetID);
+					}
+					GetTimespecFunc(&_chk_ratingPower_timeout[_index]);
+				}
+					break;
+				case SYS_MODE_PREPARE_FOR_EVSE:
+				case SYS_MODE_CCS_PRECHARGE_STEP0:
+				case SYS_MODE_CCS_PRECHARGE_STEP1:
+				{
+					// 開始確認車端是否同意開始充電
+					GetOutputReq(_index, targetID);
+
+					// 設定當前輸出
+					if (gun_count == 1)
+						SetPresentChargingOutputPower(_chargingData[0], _chargingData[0]);
+					else if (gun_count == 2)
+						SetPresentChargingOutputPower(_chargingData[0], _chargingData[1]);
+
+					if (priorityLow % 5 == 1)
+					{
+						if (_chargingData[_index]->Type == _Type_CCS)
+							GetEvccIdReq(_index, _chargingData[_index]->Evboard_id);
+
+						// 取得車端電池資訊 : 1.AC or DC ? 2.Total battery cap, 3.Max battery vol, 4.Max battery cur
+						GetEvBatteryInfo(_index, targetID);
+
+						// 樁端輸出能力改變
+						if (gun_count == 1)
+							SetPresentChargingOutputCap(_chargingData[0], _chargingData[0]);
+						else if (gun_count == 2)
+							SetPresentChargingOutputCap(_chargingData[0], _chargingData[1]);
+					}
+
+					if (LogInfo[_index][EV_LOG_MAX_BATT_VOL] != _chargingData[_index]->EvBatteryMaxVoltage)
+					{
+						LogInfo[_index][EV_LOG_MAX_BATT_VOL] = _chargingData[_index]->EvBatteryMaxVoltage;
+						PRINTF_FUNC("index = %d, Ev Maximum Battery Voltage = %f \n", _index, _chargingData[_index]->EvBatteryMaxVoltage);
+					}
+
+					if (LogInfo[_index][EV_LOG_SOC] != _chargingData[_index]->EvBatterySoc)
+					{
+						LogInfo[_index][EV_LOG_SOC] = _chargingData[_index]->EvBatterySoc;
+						PRINTF_FUNC("index = %d, SOC = %d \n", _index, _chargingData[_index]->EvBatterySoc);
+					}
+
+					// 持續通知 Isolation 測試狀態
+					if (priorityLow == 1)
+					{
+						// 拉 500 V 如果在一秒鐘內 GFD 都符合則 PASS
+//						if (_chargingData[_index]->FireChargingVoltage >= 3500)
+//							_chargingData[_index]->GroundFaultStatus = GFD_PASS;
+
+						//PRINTF_FUNC("To EV_%d GFD = %d \n",	_index, _chargingData[_index]->GroundFaultStatus);
+						//if(_chargingData[_index]->GroundFaultStatus != GFD_WAIT)
+						{
+							//if ((GetTimeoutValue(_derating_time) / 1000) > 1000)
+							unsigned char _result = _chargingData[_index]->GroundFaultStatus;
+
+							// GB & Chademo ~ Warning 也先算 Pass,因為 CCS 認證會驗 Warning 故不可更動
+							if(_chargingData[_index]->Type == _Type_Chademo ||
+								_chargingData[_index]->Type == _Type_GB)
+							{
+								if (_result == GFD_WARNING)
+								{
+									_result = GFD_PASS;
+								}
+							}
+
+							if (_result == GFD_WARNING || _result == GFD_PASS)
+							{
+								_timeBuf = GetTimeoutValue(&_chk_ratingPower_timeout[_index]);
+								if (_timeBuf < 0)
+								{
+									GetTimespecFunc(&_chk_ratingPower_timeout[_index]);
+								}
+								else
+								{
+									if ((_timeBuf > 12 &&
+											_chargingData[_index]->RealRatingPower > 0) ||
+											_timeBuf > 14)
+									{
+										if (LogInfo[_index][EV_LOG_REAL_CAP_POW] != _chargingData[_index]->RealRatingPower)
+										{
+											LogInfo[_index][EV_LOG_REAL_CAP_POW] = _chargingData[_index]->RealRatingPower;
+											PRINTF_FUNC("Conn %d, RealRatingPower = %d \n",
+												_index, _chargingData[_index]->RealRatingPower);
+										}
+									}
+									else
+										_result = GFD_WAIT;
+								}
+							}
+
+							SetIsolationStatus(_index, _result, targetID);
+						}
+
+						if(_chargingData[_index]->SystemStatus == SYS_MODE_CCS_PRECHARGE_STEP0 &&
+							_chargingData[_index]->PrechargeStatus == PRECHARGE_READY)
+						{
+							SetEvsePrechargeInfo(_index, PRECHARGE_PRERELAY_PASS, targetID);
+						}
+					}
+				}
+					break;
+				case SYS_MODE_CHARGING:
+				{
+					// 當前 Power
+					_chargingData[_index]->PresentChargingPower = ((float)((_chargingData[_index]->PresentChargingVoltage) * (_chargingData[_index]->PresentChargingCurrent)) / 1000);
+
+					CalOutputPowerAndEnergy(_index);
+
+					// 開始確認車端是否同意開始充電
+					GetOutputReq(_index, targetID);
+
+					if (LogInfo[_index][EV_LOG_MAX_BATT_VOL] != _chargingData[_index]->EvBatteryMaxVoltage)
+					{
+						LogInfo[_index][EV_LOG_MAX_BATT_VOL] = _chargingData[_index]->EvBatteryMaxVoltage;
+						PRINTF_FUNC("index = %d, Ev Maximum Battery Voltage = %f \n", _index, _chargingData[_index]->EvBatteryMaxVoltage);
+					}
+
+					if (LogInfo[_index][EV_LOG_SOC] != _chargingData[_index]->EvBatterySoc)
+					{
+						LogInfo[_index][EV_LOG_SOC] = _chargingData[_index]->EvBatterySoc;
+						PRINTF_FUNC("index = %d, SOC = %d \n", _index, _chargingData[_index]->EvBatterySoc);
+					}
+
+					// 設定當前輸出
+					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(_chargingData[_index]->GroundFaultStatus == GFD_FAIL ||
+							_chargingData[_index]->Type == _Type_CCS)
+					{
+						SetIsolationStatus(_index, _chargingData[_index]->GroundFaultStatus, targetID);
+					}
+
+					if (priorityLow == 1)
+					{
+						if(_chargingData[_index]->Type == _Type_CCS &&
+							_chargingData[_index]->PrechargeStatus == PRECHARGE_READY)
+						{
+							SetEvsePrechargeInfo(_index, PRECHARGE_CHARELAY_PASS, targetID);
+						}
+
+						// 取得車端電池資訊 : 1.AC or DC ? 2.Total battery cap, 3.Max battery vol, 4.Max battery cur
+						GetEvBatteryInfo(_index, targetID);
+					}
+				}
+					break;
+				case SYS_MODE_ALARM:
+				case SYS_MODE_TERMINATING:
+				{
+					// 當前 Power
+					_chargingData[_index]->PresentChargingPower = ((float)((_chargingData[_index]->PresentChargingVoltage) * (_chargingData[_index]->PresentChargingCurrent)) / 1000);
+
+					CalOutputPowerAndEnergy(_index);
+
+					// 設定當前輸出
+					if (gun_count == 1)
+					{
+						if (_chargingData[0]->FireChargingVoltage <= VOUT_MIN_VOLTAGE)
+							_chargingData[0]->PresentChargingCurrent = CURR_MIN_CURRENT;
+
+						SetPresentChargingOutputPower(_chargingData[0], _chargingData[0]);
+					}
+					else if (gun_count == 2)
+					{
+						if (_chargingData[0]->FireChargingVoltage <= VOUT_MIN_VOLTAGE)
+							_chargingData[0]->PresentChargingCurrent = CURR_MIN_CURRENT;
+						if (_chargingData[1]->FireChargingVoltage <= VOUT_MIN_VOLTAGE)
+							_chargingData[1]->PresentChargingCurrent = CURR_MIN_CURRENT;
+
+						SetPresentChargingOutputPower(_chargingData[0], _chargingData[1]);
+					}
+					// 槍鎖還在,則代表是樁端要求的停止
+					if (SendErrorCount[_index] < 3 &&
+							(_chargingData[_index]->GunLocked == START ||
+							_chargingData[_index]->Type == _Type_CCS))
+					{
+						byte normalStop = 0x01;
+						byte stopReason[7] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
+
+						if (GetStopChargingReasonByEvse(_index, stopReason))
+						{
+							normalStop = 0x02;
+						}
+
+						if (SendErrorCount[_index] == 0)
+						{
+							if (normalStop == 0x01)
+								PRINTF_FUNC("EVSE : Normal Stop (%d). \n", _index);
+							else
+								PRINTF_FUNC("EVSE : EMC Stop : (%d) - (%s) \n", _index, stopReason);
+						}
+
+						EvseStopChargingEvent(normalStop, stopReason, targetID);
+						SendErrorCount[_index] += 1;
+					}
+
+					if(_chargingData[_index]->Type == _Type_CCS)
+					{
+						SetIsolationStatus(_index, _chargingData[_index]->GroundFaultStatus, targetID);
+					}
+
+					GetOutputReq(_index, targetID);
+
+					if (_chargingData[_index]->SystemStatus == SYS_MODE_ALARM)
+					{
+						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,
+									targetID);
+						}
+					}
+				}
+					break;
+				case SYS_MODE_COMPLETE:
+				{
+					// 設定當前輸出
+					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);
+						SetChargingPermission(_index, STOP,
+								_chargingData[_index]->AvailableChargingPower,
+								maxCur,
+								maxVol,
+								targetID);
+					}
+				}
+					break;
+			}
+		}
+
+		if (printLogRecord)
+			InitTimeToPrintLog();
+
+		priorityLow >= 20 ? priorityLow = 1 : priorityLow++;
+		usleep(45000); //EV 小板通訊 (50 ms)
+	}
+	DEBUG_INFO("Module_EvComm : Can-bus port = %d \n", CanFd);
+	return FAIL;
+}

+ 96 - 0
EVSE/Projects/NoodoeDS/Apps/Module_EvComm.h

@@ -0,0 +1,96 @@
+#ifndef MODULE_EVCOMM_H_
+#define MODULE_EVCOMM_H_
+
+#include 	<stdbool.h>
+
+int CanFd;
+
+typedef unsigned char 		byte;
+
+
+typedef enum
+{
+    EV_Slave_Address_Broadcast  	= 0xFF,
+	EV_Slave_Address_Bd1       		= 0x01,
+	EV_Slave_Address_Bd2      		= 0x02
+}EvSlaveAddr;
+
+typedef enum
+{
+	EV_Command_AddressReq 			= 0x01,
+    EV_Command_AddressAssignment  	= 0x02,
+	EV_Command_EvStatusNotification	= 0x03,
+	EV_Command_GetFwVersion       	= 0x04,
+	EV_Command_GetHwVersion      	= 0x05,
+	EV_Command_ChargingPermission  	= 0x06,
+	EV_Command_PresentOutputPow   	= 0x07,
+	EV_Command_PresentOutputCap    	= 0x08,
+	EV_Command_GetOutputReq	    	= 0x09,
+	EV_Command_GetBetteryInfo    	= 0x0A,
+	EV_Command_EvStopNotification	= 0x0B,
+	EV_Command_EvseStopCharging    	= 0x0C,
+	EV_Command_GetMiscellaneous    	= 0x0D,
+	EV_Command_IsolationStatus    	= 0x12,
+	EV_Command_CCSconnectorInfo   	= 0x13,
+	EV_Command_SyncRtcInfo      	= 0x14,
+	EV_Command_EvsePrechargeInfo  	= 0x15,
+	EV_Command_EvccidReq	      	= 0x16,
+}EvCmd;
+
+typedef union
+{
+    unsigned int EvMessage;
+    struct
+    {
+        unsigned int SlaveAddress:8;
+        unsigned int MessageID:8;
+        unsigned int Rsv:11;
+        unsigned int Dir:1;
+        unsigned int res:4;
+    }EvBdBits;
+}EvFrame;
+
+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 SetConnectInfo(byte type, byte toId);
+void GetHardwareVersion(byte gun_index, byte toId);
+void SetChargingPermission(byte gun_index, byte permissionStatus, float aOutputPw, float 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 GetEvccIdReq(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 EV_LOG_INDEX
+{
+	EV_LOG_OUTPUT_CAP_POW = 0,
+	EV_LOG_OUTPUT_CAP_CUR = 1,
+	EV_LOG_NOW_OUTPUT_VOL = 2,
+	EV_LOG_NOW_OUTPUT_CUR = 3,
+	EV_LOG_EVSE_MAX_VOL = 	4,
+	EV_LOG_EVSE_MAX_CUR = 	5,
+	EV_LOG_MAX_BATT_VOL	= 	6,
+	EV_LOG_REAL_CAP_POW	= 	7,
+	EV_LOG_SOC = 			8
+};
+
+#endif /* MODULE_EVCOMM_H_ */
+

BIN
EVSE/Projects/NoodoeDS/Apps/Module_EventLogging


+ 571 - 0
EVSE/Projects/NoodoeDS/Apps/Module_EventLogging.c

@@ -0,0 +1,571 @@
+#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/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 	<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 YES					1
+#define NO					0
+#define CHANGED				1
+#define UNCHANGED			0
+
+struct network_previous_status
+{
+	int		rssiWifi;
+	int		rssi4g;
+	uint8_t	isInternet:1;
+	uint8_t	isOcppConnected:1;
+	uint8_t	ethIsInternet:1;
+	uint8_t	maln0IsInternet:1;
+	uint8_t	ppp0IsInternet:1;
+}netPreviousStatus;
+
+struct SysConfigAndInfo			*ShmSysConfigAndInfo;
+struct StatusCodeData 			*ShmStatusCodeData;
+
+sqlite3 *localDb;
+#define DB_FILE				"/Storage/ChargeLog/localCgargingRecord.db"
+
+sqlite3 *networkDb;
+#define	NETWORK_DB_FILE		"/Storage/EventLog/Eventlog.db"
+
+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)
+#define EVENT_INFO(format, args...) StoreEventLogMsg("[%s:%d][%s][Info] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
+
+int StoreLogMsg(const char *fmt, ...)
+{
+	char Buf[4096+256];
+	char buffer[4096];
+	va_list args;
+	struct timeb  SeqEndTime;
+	struct tm *tm;
+
+	va_start(args, fmt);
+	int rc = vsnprintf(buffer, sizeof(buffer), fmt, args);
+	va_end(args);
+
+	memset(Buf,0,sizeof(Buf));
+	ftime(&SeqEndTime);
+	SeqEndTime.time = time(NULL);
+	tm=localtime(&SeqEndTime.time);
+
+	if (ShmSysConfigAndInfo->SysConfig.SwitchDebugFlag == YES)
+	{
+		sprintf(Buf,"%02d:%02d:%02d:%03d - %s",
+			tm->tm_hour,tm->tm_min,tm->tm_sec,SeqEndTime.millitm, buffer);
+		printf("%s \n", Buf);
+	}
+	else
+	{
+		sprintf(Buf,"echo \"%04d-%02d-%02d %02d:%02d:%02d:%03d - %s\" >> /Storage/SystemLog/[%04d.%02d]SystemLog_%s",
+			tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,SeqEndTime.millitm,
+			buffer,
+			tm->tm_year+1900,tm->tm_mon+1,
+			ShmSysConfigAndInfo->SysConfig.SerialNumber);
+		system(Buf);
+	}
+
+	return rc;
+}
+
+int StoreEventLogMsg(const char *fmt, ...)
+{
+	char Buf[4096+256];
+	char buffer[4096];
+	time_t CurrentTime;
+	struct tm *tm;
+	struct timeval tv;
+	va_list args;
+
+	va_start(args, fmt);
+	int rc = vsnprintf(buffer, sizeof(buffer), fmt, args);
+	va_end(args);
+
+	memset(Buf,0,sizeof(Buf));
+	CurrentTime = time(NULL);
+	tm=localtime(&CurrentTime);
+	gettimeofday(&tv, NULL); // get microseconds, 10^-6
+
+	if((ShmSysConfigAndInfo->SysConfig.ModelName != NULL) && (ShmSysConfigAndInfo->SysConfig.SerialNumber != NULL) && (strlen((char*)ShmSysConfigAndInfo->SysConfig.ModelName) >= 14))
+	{
+		sprintf(Buf,"echo -n \"[%04d.%02d.%02d %02d:%02d:%02d.%06ld]%s\" >> /Storage/EventLog/[%04d.%02d]%s_%s_EventLog",
+					tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,tv.tv_usec,
+					buffer,
+					tm->tm_year+1900,tm->tm_mon+1,
+					ShmSysConfigAndInfo->SysConfig.ModelName,
+					ShmSysConfigAndInfo->SysConfig.SerialNumber);
+	}
+	else
+	{
+		sprintf(Buf,"echo -n \"[%04d.%02d.%02d %02d:%02d:%02d.%06ld]%s\" >> /Storage/EventLog/[%04d.%02d]EventLog",
+					tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,tv.tv_usec,
+					buffer,
+					tm->tm_year+1900,tm->tm_mon+1);
+	}
+
+#ifdef SystemLogMessage
+	system(Buf);
+#endif
+
+#ifdef ConsloePrintLog
+	printf("[%04d.%02d.%02d %02d:%02d:%02d.%06ld]%s", tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,tv.tv_usec, buffer);
+#endif
+
+	return rc;
+}
+
+int DiffTimeb(struct timeb ST, struct timeb ET)
+{
+	//return milli-second
+	unsigned int StartTime,StopTime;
+
+	StartTime=(unsigned int)ST.time;
+	StopTime=(unsigned int)ET.time;
+	return (StopTime-StartTime)*1000+ET.millitm-ST.millitm;
+}
+
+void PRINTF_FUNC(char *string, ...)
+{
+	va_list args;
+	char buffer[4096];
+	va_start(args, string);
+	vsnprintf(buffer, sizeof(buffer), string, args);
+	va_end(args);
+
+	DEBUG_INFO("%s ", 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;
+}
+
+//==========================================
+// Init all share memory
+//==========================================
+int InitShareMemory()
+{
+	int result = PASS;
+	int MeterSMId;
+
+	//creat ShmSysConfigAndInfo
+	if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo),  0777)) < 0)
+    {
+		#ifdef SystemLogMessage
+		DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
+		#endif
+		result = FAIL;
+	}
+    else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
+    {
+    	#ifdef SystemLogMessage
+    	DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
+		#endif
+    	result = FAIL;
+   	}
+
+   	//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;
+   	}
+
+    return result;
+}
+
+//================================================
+// Main process
+//================================================
+void AddFaultCodeToBuf(unsigned char *Code)
+{
+	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 = 0x01;
+	char _code[7];
+	sprintf(_code,"%s", Code);
+
+	// 把相關的錯誤碼一次移除,避免重複顯示
+	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
+			{
+				memcpy(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i - 1][0],
+					&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], 7);
+			}
+		}
+
+		if (find)
+		{
+			ShmSysConfigAndInfo->SysWarningInfo.WarningCount--;
+		}
+	}
+}
+
+//==========================================
+// SQLite routne
+//==========================================
+int DB_Insert_Record(sqlite3 *db, uint8_t *statusCode)
+{
+	int result = PASS;
+	char* errMsg = NULL;
+	char sqlStr[1024];
+
+	sprintf(sqlStr, "insert into event_record(occurDatetime, statusCode) values(CURRENT_TIMESTAMP, '%s');", statusCode);
+
+	// 0 : open successfully, else fail.
+	if(sqlite3_open(DB_FILE, &db))
+	{
+		result = FAIL;
+		DEBUG_INFO( "Can't open database: %s\n", sqlite3_errmsg(db));
+		sqlite3_close(db);
+	}
+	else
+	{
+		DEBUG_INFO( "Local event record database open successfully.\n");
+		if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
+		{
+			result = FAIL;
+			DEBUG_INFO( "Insert local event record error message: %s\n", errMsg);
+		}
+		else
+		{
+			DEBUG_INFO( "Insert local event record successfully\n");
+		}
+
+		sprintf(sqlStr, "delete from event_record where idx < (select idx from event_record order by idx desc limit 1)-2000;");
+		if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
+		{
+			result = FAIL;
+			DEBUG_INFO( "delete local event_record error message: %s\n", errMsg);
+		}
+		else
+		{
+			DEBUG_INFO( "delete local event record successfully\n");
+		}
+
+		sqlite3_close(db);
+	}
+
+	return result;
+}
+
+int DB_Network_Insert_Record(sqlite3 *db)
+{
+	int result = PASS;
+	char* errMsg = NULL;
+	char sqlStr[1024];
+
+	if(ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D')
+	{
+		sprintf(sqlStr, "insert into network_record(occurDatetime, isInternet, isOcppConnected, isEth0Internet, isMlan0Internet, isPpp0Internet, rssiMlan0, rssiPpp0) values(CURRENT_TIMESTAMP, '%d', '%d', '%d', '%d', '%d', '%d', '%d');",
+				ShmSysConfigAndInfo->SysInfo.InternetConn,
+				ShmSysConfigAndInfo->SysInfo.OcppConnStatus,
+				!ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet,
+				!ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi,
+				!ShmStatusCodeData->InfoCode.InfoEvents.bits.ApnDisconnectVia4Gi,
+				ShmSysConfigAndInfo->SysConfig.AthInterface.WifiRssi,
+				ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomRssi);
+	}
+	else if(ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'W')
+	{
+		sprintf(sqlStr, "insert into network_record(occurDatetime, isInternet, isOcppConnected, isEth0Internet, isMlan0Internet, isPpp0Internet, rssiMlan0, rssiPpp0) values(CURRENT_TIMESTAMP, '%d', '%d', '%d', '%d', '%d', '%d', '%d');",
+				ShmSysConfigAndInfo->SysInfo.InternetConn,
+				ShmSysConfigAndInfo->SysInfo.OcppConnStatus,
+				!ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet,
+				!ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi,
+				0,
+				ShmSysConfigAndInfo->SysConfig.AthInterface.WifiRssi,
+				0);
+	}
+	else if(ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'T')
+	{
+		sprintf(sqlStr, "insert into network_record(occurDatetime, isInternet, isOcppConnected, isEth0Internet, isMlan0Internet, isPpp0Internet, rssiMlan0, rssiPpp0) values(CURRENT_TIMESTAMP, '%d', '%d', '%d', '%d', '%d', '%d', '%d');",
+				ShmSysConfigAndInfo->SysInfo.InternetConn,
+				ShmSysConfigAndInfo->SysInfo.OcppConnStatus,
+				!ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet,
+				0,
+				!ShmStatusCodeData->InfoCode.InfoEvents.bits.ApnDisconnectVia4Gi,
+				0,
+				ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomRssi);
+	}
+	else
+	{
+		sprintf(sqlStr, "insert into network_record(occurDatetime, isInternet, isOcppConnected, isEth0Internet, isMlan0Internet, isPpp0Internet, rssiMlan0, rssiPpp0) values(CURRENT_TIMESTAMP, '%d', '%d', '%d', '%d', '%d', '%d', '%d');",
+				ShmSysConfigAndInfo->SysInfo.InternetConn,
+				ShmSysConfigAndInfo->SysInfo.OcppConnStatus,
+				!ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet,
+				0,
+				0,
+				0,
+				0);
+	}
+
+	if(sqlite3_open(NETWORK_DB_FILE, &db))
+	{
+		result = FAIL;
+		DEBUG_INFO( "Can't open database: %s\n", sqlite3_errmsg(db));
+		sqlite3_close(db);
+	}
+	else
+	{
+		if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
+		{
+			result = FAIL;
+			DEBUG_INFO( "Insert local network status record error message: %s\n", errMsg);
+		}
+
+		sprintf(sqlStr, "delete from network_record where idx < (select idx from network_record order by idx desc limit 1)-20000;");
+		if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
+		{
+			result = FAIL;
+			DEBUG_INFO( "delete local network_record error message: %s\n", errMsg);
+		}
+
+		sqlite3_close(db);
+	}
+
+	return result;
+}
+
+int main(void)
+{
+	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;
+	}
+
+	byte isChanged;
+
+	for(;;)
+	{
+		isChanged = UNCHANGED;
+
+		//check Fault Status
+		for(ByteCount=0;ByteCount<ARRAY_SIZE(ShmStatusCodeData->FaultCode.FaultEvents.FaultVal);ByteCount++)
+		{
+			if (isChanged == CHANGED)
+				break;
+
+			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 (isChanged == CHANGED)
+						break;
+
+					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);
+							EventCodeTmp[0] = '1';
+							isChanged = CHANGED;
+						}
+						else
+						{
+							DEBUG_INFO("Fault Code = %s\n", EventCodeTmp);
+							ShmStatusCodeData->FaultCode.PreviousFaultVal[ByteCount] |= (1<<BitCount);
+							AddFaultCodeToBuf(EventCodeTmp);
+							isChanged = CHANGED;
+						}
+
+						EVENT_INFO("%s\n", EventCodeTmp);
+						DB_Insert_Record(localDb, EventCodeTmp);
+					}
+				}
+			}
+		}
+
+		//check Alarm Status
+		for(ByteCount=0;ByteCount<ARRAY_SIZE(ShmStatusCodeData->AlarmCode.AlarmEvents.AlarmVal);ByteCount++)
+		{
+			if (isChanged == CHANGED)
+				break;
+
+			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 (isChanged == CHANGED)
+						break;
+
+					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);
+							EventCodeTmp[0] = '1';
+							isChanged = CHANGED;
+						}
+						else
+						{
+							DEBUG_INFO("Alarm Code = %s\n", EventCodeTmp);
+							ShmStatusCodeData->AlarmCode.PreviousAlarmVal[ByteCount] |= (1<<BitCount);
+							AddFaultCodeToBuf(EventCodeTmp);
+							isChanged = CHANGED;
+						}
+
+						EVENT_INFO("%s\n", EventCodeTmp);
+						DB_Insert_Record(localDb, EventCodeTmp);
+					}
+				}
+			}
+		}
+
+		//check Info Status
+		for(ByteCount=0;ByteCount<ARRAY_SIZE(ShmStatusCodeData->InfoCode.InfoEvents.InfoVal);ByteCount++)
+		{
+			if (isChanged == CHANGED)
+				break;
+
+			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 (isChanged == CHANGED)
+						break;
+
+					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);
+							EventCodeTmp[0] = '1';
+							isChanged = CHANGED;
+						}
+						else
+						{
+							DEBUG_INFO("Info Code = %s\n", EventCodeTmp);
+							ShmStatusCodeData->InfoCode.PreviousInfoVal[ByteCount] |= (1<<BitCount);
+							AddFaultCodeToBuf(EventCodeTmp);
+							isChanged = CHANGED;
+						}
+
+						EVENT_INFO("%s\n", EventCodeTmp);
+						DB_Insert_Record(localDb, EventCodeTmp);
+					}
+				}
+			}
+		}
+
+		if((netPreviousStatus.isInternet != ShmSysConfigAndInfo->SysInfo.InternetConn) ||
+				(netPreviousStatus.isOcppConnected != ShmSysConfigAndInfo->SysInfo.OcppConnStatus) ||
+				(netPreviousStatus.ethIsInternet != ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet) ||
+				(netPreviousStatus.maln0IsInternet != ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi) ||
+				(netPreviousStatus.ppp0IsInternet != ShmStatusCodeData->InfoCode.InfoEvents.bits.ApnDisconnectVia4Gi) ||
+				(netPreviousStatus.rssiWifi != ShmSysConfigAndInfo->SysConfig.AthInterface.WifiRssi) ||
+				(netPreviousStatus.rssi4g != ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomRssi))
+		{
+
+			DB_Network_Insert_Record(networkDb);
+			netPreviousStatus.isInternet = ShmSysConfigAndInfo->SysInfo.InternetConn;
+			netPreviousStatus.isOcppConnected = ShmSysConfigAndInfo->SysInfo.OcppConnStatus;
+			netPreviousStatus.ethIsInternet = ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet;
+			netPreviousStatus.maln0IsInternet = ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi;
+			netPreviousStatus.ppp0IsInternet = ShmStatusCodeData->InfoCode.InfoEvents.bits.ApnDisconnectVia4Gi;
+			netPreviousStatus.rssiWifi = ShmSysConfigAndInfo->SysConfig.AthInterface.WifiRssi;
+			netPreviousStatus.rssi4g = ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomRssi;
+		}
+
+		usleep(500000);
+	}
+
+	return FAIL;
+}

BIN
EVSE/Projects/NoodoeDS/Apps/Module_InternalComm


+ 3555 - 0
EVSE/Projects/NoodoeDS/Apps/Module_InternalComm.c

@@ -0,0 +1,3555 @@
+#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/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 	<string.h>
+#include	<time.h>
+#include	<ctype.h>
+#include 	<ifaddrs.h>
+#include 	<math.h>
+#include	"../../define.h"
+#include	"internalComm.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
+#define STOP				0
+#define START				1
+#define NORMAL				0
+#define	ABNORMAL			1
+#define RELAY_CHECK_TIME	5		// s
+#define OUTPUT_VOL_CHK_TIME	200 	// ms
+#define TEN_MINUTES			600		// s
+//#define TEN_MINUTES			10		// s
+#define FORCE_STOP_TIME		30
+//#define TEN_MINUTES			5
+#define ENV_TEMP_MIN		45
+#define ENV_TEMP_MAX		50
+#define DEFAULT_AC_INDEX	2
+#define EQUAL				0
+#define COLOR_MAX_LV		100
+#define COLOR_MIN_LV		0
+#define MIN_OUTPUT_CUR		0
+#define	AC_OUTPUT_VOL		220
+
+#define	NO_DEFINE			255
+#define	NDEFAULT_AC_INDEX	2
+
+#define OVP_UVP_CHK_COUNT 	3
+
+struct SysConfigAndInfo			*ShmSysConfigAndInfo;
+struct StatusCodeData 			*ShmStatusCodeData;
+struct FanModuleData			*ShmFanModuleData;
+struct RelayModuleData			*ShmRelayModuleData;
+struct LedModuleData			*ShmLedModuleData;
+struct CcsData					*ShmCcsData;
+struct PsuData 					*ShmPsuData;
+struct OCPP16Data				*ShmOCPP16Data;
+struct OCPP20Data				*ShmOCPP20Data;
+struct PrimaryMcuData			*ShmPrimaryMcuData;
+struct DcCommonInformation		*ShmDcCommonData;
+
+#define VIN_MAX_VOLTAGE_IEC			285	// 大於該值 : OVP
+#define VIN_MAX_REV_VOLTAGE_IEC		275	// 小於賦歸 OVP
+#define VIN_MIN_VOLTAGE_IEC			160	// 小於該值 : UVP
+#define VIN_MIN_REV_VOLTAGE_IEC		170	// 大於賦歸 UVP
+
+#define VIN_MAX_VOLTAGE_UL			315	// 大於該值 : OVP // 美規 (W)
+#define VIN_MAX_REV_VOLTAGE_UL		305	// 小於賦歸 OVP
+#define VIN_MIN_VOLTAGE_UL			210	// 小於該值 : UVP
+#define VIN_MIN_REV_VOLTAGE_UL 		220	// 大於賦歸 UVP
+
+#define VIN_DROP_VOLTAGE	150	// 小於該值 : ac drop
+
+#define VOUT_MAX_VOLTAGE	995
+#define VOUT_MIN_VOLTAGE	150
+#define IOUT_MAX_CURRENT	50
+
+#define MAX_FAN_SPEED		14000
+#define MIN_FAN_SPEED		3000
+#define NORMAL_FAN_SPEED	7000
+
+// GFD Status
+#define GFD_IDLE			0
+#define GFD_CABLECHK		1
+#define GFD_PRECHARGE		2
+#define GFD_CHARGING		3
+
+// LED Intensity (rate)
+#define LED_INTENSITY_DARKEST		0.2
+#define LED_INTENSITY_MEDIUM		0.6
+#define LED_INTENSITY_BRIGHTEST		1
+
+// EE Spec
+#define LED_BRIGHTNESS_LV_HIGH		1
+#define LED_BRIGHTNESS_LV_MID		0.5
+#define LED_BRIGHTNESS_LV_LOW		0.2
+
+// 最小切換 Relay 電壓
+#define SELF_TO_CHANGE_RELAY_STATUS			600
+// 透過電壓確認 Relay 是否搭上的依據電壓
+#define CHECK_RELAY_STATUS					300
+#define CHECK_RELAY_STATUS_GAP				100
+// 安全在停止充電程序中斷開 Relay 的電流
+#define SEFETY_SWITCH_RELAY_CUR				50
+// 確認 Relay Welding 電壓
+#define RELAY_WELDING_DET					300
+// CCS minimum precharge voltage
+#define CCS_PRECHARGE_VOL					2000
+#define CCS_PRECHARGE_STARTU				40
+
+unsigned int _acErrRecord;
+
+byte gunCount;
+byte acgunCount;
+// 槍資訊
+struct ChargingInfoData *_chargingData[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
+struct ChargingInfoData *ac_chargingInfo[AC_QUANTITY];
+unsigned short AcChargingRatingCurrent;
+
+float _ChargingProfilePwBuffer[AC_QUANTITY];
+
+byte ac_startTransationFlag;
+Relay acOutputRelay;
+
+bool _isOutputNoneMatch[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
+struct timespec _checkOutputNoneMatchTimer[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
+
+//bool _isRelayWelding[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
+//struct timeval _checkRelayWeldingTimer[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
+bool _isOvpChkTimeFlag[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
+struct timespec _checkOutputVolProtectTimer[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
+
+// SMR1 *2 + SMR2 * 2 + Parallel * 2
+struct timespec _relayStateChkTimer[6];
+
+byte _threePhaseOvp[3] = {0, 0, 0};
+byte _threePhaseUvp[3] = {0, 0, 0};
+
+bool FindChargingInfoData(byte target, struct ChargingInfoData **chargingData);
+
+int Uart5Fd;
+char *relayRs485PortName = "/dev/ttyS5";
+unsigned short fanSpeedSmoothValue = 500;
+
+bool isStopChargingCount = false;
+struct timespec _close_ac_contactor;
+
+struct timespec _priority_time;
+struct timespec _led_priority_time;
+struct timespec _led_blink_time;
+
+struct timespec	_ac_charging_comp;
+struct timespec	_ac_preparing;
+struct timeb 	_ac_startChargingTime;
+struct timeb 	_ac_endChargingTime;
+byte 			_ac_duty;
+
+bool isCriticalStop;
+struct timespec	_psuCriticalStop;
+
+unsigned short _setFanSpeed = 0;
+float _beforeChargingTotalEnergy = 0.0;
+byte _checkLedChanged = 3;
+byte relayMatchFlag = 0;
+
+Ver ver;
+PresentInputVoltage inputVoltage;
+PresentOutputVoltage outputVoltage;
+FanSpeed fanSpeed;
+Temperature temperature;
+AuxPower auxPower;
+Gfd gfd_adc;
+Gfd_config gfd_config;
+Gpio_in gpio_in;
+Gpio_out gpio_out;
+Relay outputRelay;
+Relay regRelay;
+Rtc rtc;
+Led_Color cur_led_color;
+Led_Color led_color;
+
+Ac_Status acStatus;
+Ac_Led_Status ledStatus;
+Ac_Alarm_code acAlarmCode;
+Ac_Charging_energy acChargingEnergy;
+Ac_Charging_current acChargingCurrent;
+PresentInputVoltage acChargingVoltage;
+
+bool isAcModuleInitComp;
+int mask_table[] = {
+		0x00000001, 0x00000002, 0x00000004, 0x00000008,
+		0x00000010, 0x00000020, 0x00000040, 0x00000080,
+		0x00000100, 0x00000200, 0x00000400, 0x00000800,
+		0x00001000, 0x00002000, 0x00004000, 0x00008000,
+		0x00010000, 0x00020000, 0x00040000, 0x00080000,
+		0x00100000, 0x00200000, 0x00400000, 0x00800000,
+		0x01000000, 0x02000000, 0x04000000, 0x08000000,
+		0x10000000, 0x20000000, 0x40000000, 0x80000000
+};
+
+#define L1_AC_OVP						0
+#define L1_AC_UVP						1
+#define L1_AC_OCP						2
+#define AC_OTP							3
+#define AC_GMI_FAULT					4
+#define AC_CP_ERROR						5
+#define AC_AC_LEAKAGE					6
+#define AC_DC_LEAKAGE					7
+#define AC_SYSTEM_SELFTEST_FAULT		8
+#define AC_HANDSHAKE_TIMEOUT			9
+#define AC_EMC_STOP						10
+#define AC_RELAY_WELDING				11
+#define AC_LEAK_MODULE_FAULT			12
+#define AC_SHUTTER_FAULT				13
+#define AC_LOCKER_FAULT					14
+#define AC_POWER_DROP					15
+#define L1_AC_CIRCUIT_SHORT				16
+#define AC_ROTARY_SWITCH_FAULT			17
+#define AC_RELAY_DRIVE_FAULT			18
+#define RESERVED_1						19
+#define L2_AC_OVP						20
+#define L3_AC_OVP						21
+#define L2_AC_UVP						22
+#define L3_AC_UVP						23
+#define L2_AC_OCP						24
+#define L3_AC_OCP						25
+#define L2_AC_CIRCUIT_SHORT				26
+#define L3_AC_CIRCUIT_SHORT				27
+#define AC_METER_TIMEOUT				28
+#define AC_METER_IC_COMM_TIMEOUT		29
+#define AC_CP_NEGATIVE_ERR				30
+#define RESERVED_2						31
+
+void PRINTF_FUNC(char *string, ...);
+
+int StoreLogMsg(const char *fmt, ...);
+int GetTimeoutValue(struct timespec *startTime);
+
+void ocpp_ac_clear_errorCode_cmd(bool isError);
+
+#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)
+
+long int GetTimeoutMValue(struct timespec *startTime)
+{
+	struct timespec endTime;
+
+	clock_gettime(CLOCK_MONOTONIC, &endTime);
+	return 1000 * (endTime.tv_sec - startTime->tv_sec) + (endTime.tv_nsec - startTime->tv_nsec) / 1000000;
+}
+
+void GetTimespecMFunc(struct timespec *time)
+{
+	clock_gettime(CLOCK_MONOTONIC, time);
+}
+
+int GetTimeoutValue(struct timespec *startTime)
+{
+	struct timespec endTime;
+
+	clock_gettime(CLOCK_MONOTONIC_COARSE, &endTime);
+	return endTime.tv_sec - startTime->tv_sec;
+}
+
+void GetTimespecFunc(struct timespec *time)
+{
+	clock_gettime(CLOCK_MONOTONIC_COARSE, time);
+}
+
+int StoreLogMsg(const char *fmt, ...)
+{
+	char Buf[4096+256];
+	char buffer[4096];
+	va_list args;
+	struct timeb  SeqEndTime;
+	struct tm *tm;
+
+	va_start(args, fmt);
+	int rc = vsnprintf(buffer, sizeof(buffer), fmt, args);
+	va_end(args);
+
+	memset(Buf,0,sizeof(Buf));
+	ftime(&SeqEndTime);
+	SeqEndTime.time = time(NULL);
+	tm=localtime(&SeqEndTime.time);
+
+	if (ShmSysConfigAndInfo->SysConfig.SwitchDebugFlag == YES)
+	{
+		sprintf(Buf,"%02d:%02d:%02d:%03d - %s",
+			tm->tm_hour,tm->tm_min,tm->tm_sec,SeqEndTime.millitm, buffer);
+		printf("%s \n", Buf);
+	}
+	else
+	{
+		sprintf(Buf,"echo \"%04d-%02d-%02d %02d:%02d:%02d:%03d - %s\" >> /Storage/SystemLog/[%04d.%02d]SystemLog_%s",
+			tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,SeqEndTime.millitm,
+			buffer,
+			tm->tm_year+1900,tm->tm_mon+1,
+			ShmSysConfigAndInfo->SysConfig.SerialNumber);
+		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;
+	return (StopTime - StartTime);
+}
+
+unsigned short MaxValue(unsigned short value1, unsigned short value2)
+{
+	return value1 >= value2 ? value1 : value2;
+}
+
+void PRINTF_FUNC(char *string, ...)
+{
+	va_list args;
+	char buffer[4096];
+	va_start(args, string);
+	vsnprintf(buffer, sizeof(buffer), string, args);
+	va_end(args);
+
+	DEBUG_INFO("%s ", buffer);
+}
+
+//==========================================
+// Communication Function
+//==========================================
+void GetFwAndHwVersion_Fan()
+{
+	if(Query_FW_Ver(Uart5Fd, Addr.Fan, &ver) == PASS)
+	{
+		// FanModuleData
+		strcpy((char *) ShmFanModuleData->version, ver.Version_FW);
+		// SystemInfo
+		strcpy((char *) ShmSysConfigAndInfo->SysInfo.FanModuleFwRev, ver.Version_FW);
+		//PRINTF_FUNC("GetFwAndHwVersion_Fan s1 = %s \n", ver.Version_FW);
+	}
+
+	if (Query_HW_Ver(Uart5Fd, Addr.Fan, &ver) == PASS)
+	{
+		// SystemInfo
+		strcpy((char *) ShmSysConfigAndInfo->SysInfo.FanModuleHwRev, ver.Version_FW);
+		//PRINTF_FUNC("GetFwAndHwVersion_Fan s2 = %s \n", ver.Version_HW);
+	}
+}
+
+void GetFwAndHwVersion_Relay()
+{
+	if (Query_FW_Ver(Uart5Fd, Addr.Relay, &ver) == PASS)
+	{
+		// RelayModuleData
+		strcpy((char *) ShmRelayModuleData->version, ver.Version_FW);
+		// SystemInfo
+		strcpy((char *) ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev, ver.Version_FW);
+		//PRINTF_FUNC("GetFwAndHwVersion_Relay s1 = %s \n", ver.Version_FW);
+	}
+
+	if (Query_HW_Ver(Uart5Fd, Addr.Relay, &ver) == PASS)
+	{
+		// SystemInfo
+		strcpy((char *) ShmSysConfigAndInfo->SysInfo.RelayModuleHwRev, ver.Version_FW);
+		//PRINTF_FUNC("GetFwAndHwVersion_Relay s2 = %s \n", ver.Version_HW);
+	}
+}
+
+void GetFwAndHwVersion_Led()
+{
+	if (Query_FW_Ver(Uart5Fd, Addr.Led, &ver) == PASS)
+	{
+		// LedModuleData
+		strcpy((char *) ShmLedModuleData->version, ver.Version_FW);
+		// SystemInfo
+		strcpy((char *) ShmSysConfigAndInfo->SysInfo.LedModuleFwRev, ver.Version_FW);
+		ShmLedModuleData->SelfTest_Comp = YES;
+	}
+	else
+	{
+		//PRINTF_FUNC("GetFwAndHwVersion_Led fail \n");
+	}
+
+//	if (Query_HW_Ver(Uart5Fd, Addr.Led, &ver) == PASS)
+//	{
+//		// SystemInfo
+//		strcpy((char *) ShmSysConfigAndInfo->SysInfo.RelayModuleHwRev, ver.Version_FW);
+//		//PRINTF_FUNC("GetFwAndHwVersion_Relay s2 = %s \n", ver.Version_HW);
+//	}
+}
+
+void GetFwVersion_AC()
+{
+	if (Query_FW_Ver(Uart5Fd, Addr.AcPlug, &ver) == PASS)
+	{
+		ac_chargingInfo[0]->SelfTest_Comp = YES;
+		strcpy((char *) ac_chargingInfo[0]->version, ver.Version_FW);
+	}
+}
+
+void GetAcModelName()
+{
+	memset(ShmSysConfigAndInfo->SysConfig.AcModelName, 0x00, sizeof(ShmSysConfigAndInfo->SysConfig.AcModelName));
+	if (Query_Model_Name(Uart5Fd, Addr.AcPlug, ShmSysConfigAndInfo->SysConfig.AcModelName) == PASS)
+	{
+		PRINTF_FUNC("ac model name = %s \n", ShmSysConfigAndInfo->SysConfig.AcModelName);
+	}
+}
+
+void SetRtcData_Relay()
+{
+	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);
+
+	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[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[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;
+
+	if (Config_Rtc_Data(Uart5Fd, Addr.Relay, &rtc) == PASS)
+	{
+		//PRINTF_FUNC("SetRtc (RB) sucessfully. \n");
+	}
+}
+
+void SetModelName_Relay()
+{
+	if (Config_Model_Name(Uart5Fd, Addr.Relay, ShmSysConfigAndInfo->SysConfig.ModelName) == PASS)
+	{
+		//PRINTF_FUNC("Set Model name (RB) PASS = %s \n", ShmSysConfigAndInfo->SysConfig.ModelName);
+	}
+}
+
+void SetRtcData_Fan()
+{
+	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);
+
+	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[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[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;
+
+	if (Config_Rtc_Data(Uart5Fd, Addr.Fan, &rtc) == PASS)
+	{
+		//PRINTF_FUNC("SetRtc (FB) sucessfully. \n");
+	}
+}
+
+void SetModelName_Fan()
+{
+	if (Config_Model_Name(Uart5Fd, Addr.Fan, ShmSysConfigAndInfo->SysConfig.ModelName) == PASS)
+	{
+		//PRINTF_FUNC("Set Model name (FAN) PASS = %s \n", ShmSysConfigAndInfo->SysConfig.ModelName);
+	}
+}
+
+// AC 三相輸入電壓
+void GetPresentInputVol()
+{
+	if (Query_Present_InputVoltage(Uart5Fd, Addr.Relay, &inputVoltage) == PASS)
+	{
+		// resolution : 0.1
+		ShmSysConfigAndInfo->SysInfo.InputVoltageR = ShmRelayModuleData->InputL1Volt = inputVoltage.L1N_L12;
+		ShmSysConfigAndInfo->SysInfo.InputVoltageS = ShmRelayModuleData->InputL2Volt = inputVoltage.L2N_L23;
+		ShmSysConfigAndInfo->SysInfo.InputVoltageT = ShmRelayModuleData->InputL3Volt = inputVoltage.L3N_L31;
+
+		//********************************************************************************************************//
+		// Vin (UVP)
+		if (ShmSysConfigAndInfo->SysInfo.ChargerType == _CHARGER_TYPE_IEC)
+		{
+			if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputUVP == NO)
+			{
+				if (inputVoltage.L1N_L12 < VIN_MIN_VOLTAGE_IEC)
+				{
+					PRINTF_FUNC("In Uvp L1N_L12 = %f \n", inputVoltage.L1N_L12);
+					if (_threePhaseUvp[0] >= OVP_UVP_CHK_COUNT)
+						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputUVP = YES;
+					else
+						_threePhaseUvp[0] += 1;
+				}
+			}
+			else
+			{
+				if (inputVoltage.L1N_L12 > VIN_MIN_REV_VOLTAGE_IEC)
+				{
+					ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputUVP = NO;
+					_threePhaseUvp[0] = 0;
+				}
+			}
+
+			if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputUVP == NO)
+			{
+				if (inputVoltage.L2N_L23 < VIN_MIN_VOLTAGE_IEC)
+				{
+					PRINTF_FUNC("In Uvp L2N_L23 = %f \n", inputVoltage.L2N_L23);
+					if (_threePhaseUvp[1] >= OVP_UVP_CHK_COUNT)
+						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputUVP = YES;
+					else
+						_threePhaseUvp[1] += 1;
+				}
+			}
+			else
+			{
+				if (inputVoltage.L2N_L23 > VIN_MIN_REV_VOLTAGE_IEC)
+				{
+					ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputUVP = NO;
+					_threePhaseUvp[1] = 0;
+				}
+			}
+
+			if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputUVP == NO)
+			{
+				if (inputVoltage.L3N_L31 < VIN_MIN_VOLTAGE_IEC)
+				{
+					PRINTF_FUNC("In Uvp L3N_L31 = %f \n", inputVoltage.L3N_L31);
+					if (_threePhaseUvp[2] >= OVP_UVP_CHK_COUNT)
+						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputUVP = YES;
+					else
+						_threePhaseUvp[2] += 1;
+				}
+			}
+			else
+			{
+				if (inputVoltage.L3N_L31 > VIN_MIN_REV_VOLTAGE_IEC)
+				{
+					ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputUVP = NO;
+					_threePhaseUvp[2] = 0;
+				}
+			}
+		}
+		else if (ShmSysConfigAndInfo->SysInfo.ChargerType == _CHARGER_TYPE_UL)
+		{
+			if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputUVP == NO)
+			{
+				if (inputVoltage.L1N_L12 < VIN_MIN_VOLTAGE_UL)
+				{
+					PRINTF_FUNC("In Uvp L1N_L12 = %f \n", inputVoltage.L1N_L12);
+					if (_threePhaseUvp[0] >= OVP_UVP_CHK_COUNT)
+						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputUVP = YES;
+					else
+						_threePhaseUvp[0] += 1;
+				}
+			}
+			else
+			{
+				if (inputVoltage.L1N_L12 > VIN_MIN_REV_VOLTAGE_UL)
+				{
+					ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputUVP = NO;
+					_threePhaseUvp[0] = 0;
+				}
+			}
+
+			if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputUVP == NO)
+			{
+				if (inputVoltage.L2N_L23 < VIN_MIN_VOLTAGE_UL)
+				{
+					PRINTF_FUNC("In Uvp L2N_L23 = %f \n", inputVoltage.L2N_L23);
+					if (_threePhaseUvp[1] >= OVP_UVP_CHK_COUNT)
+						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputUVP = YES;
+					else
+						_threePhaseUvp[1] += 1;
+				}
+			}
+			else
+			{
+				if (inputVoltage.L2N_L23 > VIN_MIN_REV_VOLTAGE_UL)
+				{
+					ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputUVP = NO;
+					_threePhaseUvp[1] = 0;
+				}
+			}
+
+			if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputUVP == NO)
+			{
+				if (inputVoltage.L3N_L31 < VIN_MIN_VOLTAGE_UL)
+				{
+					PRINTF_FUNC("In Uvp L3N_L31 = %f \n", inputVoltage.L3N_L31);
+					if (_threePhaseUvp[2] >= OVP_UVP_CHK_COUNT)
+						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputUVP = YES;
+					else
+						_threePhaseUvp[2] += 1;
+				}
+			}
+			else
+			{
+				if (inputVoltage.L3N_L31 > VIN_MIN_REV_VOLTAGE_UL)
+				{
+					ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputUVP = NO;
+					_threePhaseUvp[2] = 0;
+				}
+			}
+		}
+		//********************************************************************************************************//
+		// Vin (OVP)
+		if (ShmSysConfigAndInfo->SysInfo.ChargerType == _CHARGER_TYPE_IEC)
+		{
+			if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputOVP == NO)
+			{
+				if (inputVoltage.L1N_L12 > VIN_MAX_VOLTAGE_IEC)
+				{
+					PRINTF_FUNC("In Ovp L1N_L12 = %f \n", inputVoltage.L1N_L12);
+					if (_threePhaseOvp[0] >= OVP_UVP_CHK_COUNT)
+						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputOVP = YES;
+					else
+						_threePhaseOvp[0] += 1;
+				}
+			}
+			else
+			{
+				if (inputVoltage.L1N_L12 < VIN_MAX_REV_VOLTAGE_IEC)
+				{
+					ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputOVP = NO;
+					_threePhaseOvp[0] = 0;
+				}
+			}
+
+			if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputOVP == NO)
+			{
+				if (inputVoltage.L2N_L23 > VIN_MAX_VOLTAGE_IEC)
+				{
+					PRINTF_FUNC("In Ovp L2N_L23 = %f \n", inputVoltage.L2N_L23);
+					if (_threePhaseOvp[1] >= OVP_UVP_CHK_COUNT)
+						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputOVP = YES;
+					else
+						_threePhaseOvp[1] += 1;
+				}
+			}
+			else
+			{
+				if (inputVoltage.L2N_L23 < VIN_MAX_REV_VOLTAGE_IEC)
+				{
+					ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputOVP = NO;
+					_threePhaseOvp[1] = 0;
+				}
+			}
+
+			if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputOVP == NO)
+			{
+				if (inputVoltage.L3N_L31 > VIN_MAX_VOLTAGE_IEC)
+				{
+					PRINTF_FUNC("In Ovp L3N_L31 = %f \n", inputVoltage.L3N_L31);
+					if (_threePhaseOvp[2] >= OVP_UVP_CHK_COUNT)
+						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputOVP = YES;
+					else
+						_threePhaseOvp[2] += 1;
+				}
+			}
+			else
+			{
+				if (inputVoltage.L3N_L31 < VIN_MAX_REV_VOLTAGE_IEC)
+				{
+					ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputOVP = NO;
+					_threePhaseOvp[2] = 0;
+				}
+			}
+		}
+		else if (ShmSysConfigAndInfo->SysInfo.ChargerType == _CHARGER_TYPE_UL)
+		{
+			if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputOVP == NO)
+			{
+				if (inputVoltage.L1N_L12 > VIN_MAX_VOLTAGE_UL)
+				{
+					PRINTF_FUNC("In Ovp L1N_L12 = %f \n", inputVoltage.L1N_L12);
+					if (_threePhaseOvp[0] >= OVP_UVP_CHK_COUNT)
+						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputOVP = YES;
+					else
+						_threePhaseOvp[0] += 0;
+				}
+			}
+			else
+			{
+				if (inputVoltage.L1N_L12 < VIN_MAX_REV_VOLTAGE_UL)
+				{
+					ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputOVP = NO;
+					_threePhaseOvp[0] = 0;
+				}
+			}
+
+			if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputOVP == NO)
+			{
+				if (inputVoltage.L2N_L23 > VIN_MAX_VOLTAGE_UL)
+				{
+					PRINTF_FUNC("In Ovp L2N_L23 = %f \n", inputVoltage.L2N_L23);
+					if (_threePhaseOvp[1] >= OVP_UVP_CHK_COUNT)
+						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputOVP = YES;
+					else
+						_threePhaseOvp[1] += 0;
+				}
+			}
+			else
+			{
+				if (inputVoltage.L2N_L23 < VIN_MAX_REV_VOLTAGE_UL)
+				{
+					ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputOVP = NO;
+					_threePhaseOvp[1] = 0;
+				}
+			}
+
+			if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputOVP == NO)
+			{
+				if (inputVoltage.L3N_L31 > VIN_MAX_VOLTAGE_UL)
+				{
+					PRINTF_FUNC("In Ovp L3N_L31 = %f \n", inputVoltage.L3N_L31);
+					if (_threePhaseOvp[2] >= OVP_UVP_CHK_COUNT)
+						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputOVP = YES;
+					else
+						_threePhaseOvp[2] += 1;
+				}
+			}
+			else
+			{
+				if (inputVoltage.L3N_L31 < VIN_MAX_REV_VOLTAGE_UL)
+				{
+					ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputOVP = NO;
+					_threePhaseOvp[2] = 0;
+				}
+			}
+		}
+	}
+}
+
+// 左右槍的 Relay 前後的輸出電壓
+void GetPersentOutputVol()
+{
+	if (Query_Present_OutputVoltage(Uart5Fd, Addr.Relay, &outputVoltage) == PASS)
+	{
+//		PRINTF_FUNC("Conn1 fuse 1 = %f \n", outputVoltage.behindFuse_Voltage_C1);
+//		PRINTF_FUNC("Conn1 relay 1 = %f \n", outputVoltage.behindRelay_Voltage_C1);
+//		PRINTF_FUNC("Conn2 fuse 2 = %f \n", outputVoltage.behindFuse_Voltage_C2);
+//		PRINTF_FUNC("Conn2 relay 2 = %f \n", outputVoltage.behindRelay_Voltage_C2);
+
+		//PRINTF_FUNC("outputVoltage.behindFuse_Voltage_C1 = %f \n", outputVoltage.behindFuse_Voltage_C1);
+		//PRINTF_FUNC("outputVoltage.behindFuse_Voltage_C2 = %f \n", outputVoltage.behindFuse_Voltage_C2);
+
+		ShmRelayModuleData->Gun1FuseOutputVolt = outputVoltage.behindFuse_Voltage_C1;
+		ShmRelayModuleData->Gun1RelayOutputVolt = outputVoltage.behindRelay_Voltage_C1;
+		ShmRelayModuleData->Gun2FuseOutputVolt = outputVoltage.behindFuse_Voltage_C2;
+		ShmRelayModuleData->Gun2RelayOutputVolt = outputVoltage.behindRelay_Voltage_C2;
+
+		for (int index = 0; index < gunCount; index++)
+		{
+			if (index == 0)
+			{
+				if (_chargingData[index]->Evboard_id == 0x01)
+				{
+					_chargingData[index]->FuseChargingVoltage = ShmRelayModuleData->Gun1FuseOutputVolt;
+					_chargingData[index]->FireChargingVoltage = ShmRelayModuleData->Gun1RelayOutputVolt;
+				}
+				else if (_chargingData[index]->Evboard_id == 0x02)
+				{
+					_chargingData[index]->FuseChargingVoltage = ShmRelayModuleData->Gun2FuseOutputVolt;
+					_chargingData[index]->FireChargingVoltage = ShmRelayModuleData->Gun2RelayOutputVolt;
+				}
+			}
+			else if (index == 1)
+			{
+				_chargingData[index]->FuseChargingVoltage = ShmRelayModuleData->Gun2FuseOutputVolt;
+				_chargingData[index]->FireChargingVoltage = ShmRelayModuleData->Gun2RelayOutputVolt;
+			}
+
+			//unsigned short Ovp = 0;
+			//unsigned short Ocp = 0;
+			//Ovp = MIN [VOUT_MAX_VOLTAGE, EV_BATTERY_VOLTAGE] 	// 最大輸出電壓與電池電壓最大值
+			//Ocp = MIN [IOUT_MAX_CURRENT, EV_CURRENT_REQ]		// 最大輸出電流與需求電流最小值
+			if (_chargingData[index]->Type == _Type_Chademo)
+			{
+				//Ovp = MaxValue(_chargingData[index]->MaximumChargingVoltage, _chargingData[index]->EvBatteryMaxVoltage);
+				//Ocp = MaxValue(_chargingData[index]->PresentChargingCurrent, ShmCHAdeMOData->ev[_chargingData[index]->type_index].ChargingCurrentRequest);
+			}
+			else if (_chargingData[index]->Type == _Type_CCS)
+			{
+
+			}
+		}
+	}
+}
+
+// 風扇速度
+void GetFanSpeed()
+{
+	//PRINTF_FUNC("Get fan board speed \n");
+	if (Query_Fan_Speed(Uart5Fd, Addr.Fan, &fanSpeed) == PASS)
+	{
+		ShmFanModuleData->PresentFan1Speed = fanSpeed.speed[0];
+		ShmFanModuleData->PresentFan2Speed = fanSpeed.speed[1];
+		ShmFanModuleData->PresentFan3Speed = fanSpeed.speed[2];
+		ShmFanModuleData->PresentFan4Speed = fanSpeed.speed[3];
+//		PRINTF_FUNC("SystemFanRotaSpeed_1 = %d \n", fanSpeed.speed[0]);
+//		PRINTF_FUNC("SystemFanRotaSpeed_2 = %d \n", fanSpeed.speed[1]);
+//		PRINTF_FUNC("SystemFanRotaSpeed_3 = %d \n", fanSpeed.speed[2]);
+//		PRINTF_FUNC("SystemFanRotaSpeed_4 = %d \n", fanSpeed.speed[3]);
+		// Config_Fan_Speed(Uart5Fd, Addr.Fan, &fanSpeed[0]);
+		//SysInfoData (SystemFanRotaSpeed)
+	}
+}
+
+// 讀取 Relay 狀態
+void GetRelayOutputStatus()
+{
+	if (Query_Relay_Output(Uart5Fd, Addr.Relay, &regRelay) == PASS)
+	{
+		//regRelay.relay_event.bits.AC_Contactor = ShmSysConfigAndInfo->SysInfo.AcContactorStatus;
+	}
+}
+
+// 確認 K1 K2 relay 的狀態
+void CheckK1K2RelayOutput(byte index)
+{
+	if (index == 0)
+	{
+		if (_chargingData[index]->Evboard_id == 0x01)
+		{
+			if (regRelay.relay_event.bits.Gun1_N == YES && regRelay.relay_event.bits.Gun1_P == YES)
+				_chargingData[index]->RelayK1K2Status = YES;
+			else
+				_chargingData[index]->RelayK1K2Status = NO;
+
+			if(_chargingData[index]->Type == _Type_CCS)
+			{
+//				if (gunCount == 1)
+//				{
+//					if (regRelay.relay_event.bits.Gun1_N == YES	&& regRelay.relay_event.bits.CCS_Precharge == YES)
+//						_chargingData[index]->RelayKPK2Status = YES;
+//					else
+//						_chargingData[index]->RelayKPK2Status = NO;
+//				}
+//				else
+				{
+					if (_chargingData[index]->SystemStatus == SYS_MODE_CCS_PRECHARGE_STEP0)
+						_chargingData[index]->RelayKPK2Status = YES;
+					else
+						_chargingData[index]->RelayKPK2Status = NO;
+				}
+			}
+		}
+		else if (_chargingData[index]->Evboard_id == 0x02)
+		{
+			if (regRelay.relay_event.bits.Gun2_N == YES && regRelay.relay_event.bits.Gun2_P == YES)
+				_chargingData[index]->RelayK1K2Status = YES;
+			else
+				_chargingData[index]->RelayK1K2Status = NO;
+
+			if(_chargingData[index]->Type == _Type_CCS)
+			{
+//				if (regRelay.relay_event.bits.Gun2_N == YES	&& regRelay.relay_event.bits.CCS_Precharge == YES)
+//					_chargingData[index]->RelayKPK2Status = YES;
+//				else
+//					_chargingData[index]->RelayKPK2Status = NO;
+
+				if (_chargingData[index]->SystemStatus == SYS_MODE_CCS_PRECHARGE_STEP0)
+					_chargingData[index]->RelayKPK2Status = YES;
+				else
+					_chargingData[index]->RelayKPK2Status = NO;
+			}
+		}
+	}
+	else if (index == 1)
+	{
+		if (regRelay.relay_event.bits.Gun2_N == YES && regRelay.relay_event.bits.Gun2_P == YES)
+			_chargingData[index]->RelayK1K2Status = YES;
+		else
+			_chargingData[index]->RelayK1K2Status = NO;
+
+		if(_chargingData[index]->Type == _Type_CCS)
+		{
+//			if (regRelay.relay_event.bits.Gun2_N == YES && regRelay.relay_event.bits.CCS_Precharge == YES)
+//				_chargingData[index]->RelayKPK2Status = YES;
+//			else
+//				_chargingData[index]->RelayKPK2Status = NO;
+
+			if (_chargingData[index]->SystemStatus == SYS_MODE_CCS_PRECHARGE_STEP0)
+				_chargingData[index]->RelayKPK2Status = YES;
+			else
+				_chargingData[index]->RelayKPK2Status = NO;
+		}
+	}
+
+	if (ShmSysConfigAndInfo->SysInfo.BridgeRelayStatus == YES)
+	{
+		if (regRelay.relay_event.bits.Gun1_Parallel_N == NO &&
+				regRelay.relay_event.bits.Gun1_Parallel_P == NO)
+			ShmSysConfigAndInfo->SysInfo.BridgeRelayStatus = NO;
+	}
+	else if (ShmSysConfigAndInfo->SysInfo.BridgeRelayStatus == NO)
+	{
+		if (regRelay.relay_event.bits.Gun1_Parallel_N == YES &&
+				regRelay.relay_event.bits.Gun1_Parallel_P == YES)
+				ShmSysConfigAndInfo->SysInfo.BridgeRelayStatus = YES;
+	}
+
+//	PRINTF_FUNC("Check Relay Output. index = %d, RelayKPK2Status = %d, BridgeRelayStatus = %d \n",
+//			index, _chargingData[index]->RelayKPK2Status, ShmSysConfigAndInfo->SysInfo.BridgeRelayStatus);
+}
+
+void GetGfdAdc()
+{
+	// define : 每 0.2 ~ 1 秒一次
+	// occur : <= 75k 歐姆 @ 150 - 750 Vdc
+	// warning : >= 100 歐姆 && <= 500 歐姆 @ 150-750 Vdc
+	if (Query_Gfd_Adc(Uart5Fd, Addr.Relay, &gfd_adc) == PASS)
+	{
+		for (int i = 0; i < gunCount; i++)
+		{
+			if (_chargingData[i]->Type == 0x09 && !ShmSysConfigAndInfo->SysConfig.AlwaysGfdFlag)
+			{
+				if (_chargingData[i]->FireChargingVoltage >= VOUT_MIN_VOLTAGE)
+					_chargingData[i]->GroundFaultStatus = GFD_PASS;
+				continue;
+			}
+
+			if (i == 0)
+			{
+				_chargingData[i]->GroundFaultStatus = gfd_adc.result_conn1;
+//				PRINTF_FUNC("GFD ******** Result = %d, Step = %d, R = %d, Vol = %d \n",
+//						_chargingData[i]->GroundFaultStatus, gfd_adc.rb_step_1, gfd_adc.Resister_conn1, gfd_adc.voltage_conn1);
+				if (_chargingData[i]->GroundFaultStatus == GFD_FAIL)
+				{
+					PRINTF_FUNC("GFD Fail. index = %d, Step = %d, R = %d, Vol = %d \n",
+							i, gfd_adc.rb_step_1, gfd_adc.Resister_conn1, gfd_adc.voltage_conn1);
+				}
+				else if (_chargingData[i]->GroundFaultStatus == GFD_PASS ||
+						_chargingData[i]->GroundFaultStatus == GFD_WARNING)
+				{
+					if (_chargingData[i]->GroundFaultStatus == GFD_WARNING)
+					{
+						PRINTF_FUNC("GFD Warning. index = %d, Result = %d, R = %d, Vol = %d \n",
+								i, _chargingData[i]->GroundFaultStatus, gfd_adc.Resister_conn1, gfd_adc.voltage_conn1);
+					}
+				}
+			}
+			else if (i == 1)
+			{
+				_chargingData[i]->GroundFaultStatus = gfd_adc.result_conn2;
+				if (_chargingData[i]->GroundFaultStatus == GFD_FAIL)
+				{
+					PRINTF_FUNC("GFD Fail. index = %d, Step = %d, R = %d, Vol = %d \n",
+							i, gfd_adc.rb_step_2, gfd_adc.Resister_conn2, gfd_adc.voltage_conn2);
+				}
+				else if (_chargingData[i]->GroundFaultStatus == GFD_PASS ||
+						_chargingData[i]->GroundFaultStatus == GFD_WARNING)
+				{
+					if (_chargingData[i]->GroundFaultStatus == GFD_WARNING)
+					{
+						PRINTF_FUNC("GFD Warning. index = %d, Result = %d, R = %d, Vol = %d \n",
+							i, _chargingData[i]->GroundFaultStatus, gfd_adc.Resister_conn1, gfd_adc.voltage_conn1);
+					}
+				}
+			}
+		}
+	}
+}
+
+void GetGpioInput()
+{
+	if (Query_Gpio_Input(Uart5Fd, Addr.Aux, &gpio_in) == PASS)
+	{
+		// AC Contactor Status
+		if (gpio_in.AC_MainBreaker == 1)
+		{
+			// AC Main Breaker ON
+			PRINTF_FUNC("RB AC Main Breaker. \n");
+		}
+
+		if (gpio_in.SPD == 1)
+		{
+			// SPD (雷擊保護) ON
+			PRINTF_FUNC("RB SPD. \n");
+		}
+
+		if (gpio_in.Door_Open == 1)
+		{
+			// Door Open
+			PRINTF_FUNC("RB Door Open. \n");
+		}
+
+		if (gpio_in.GFD[0] == 1)
+		{
+			// GFD_1 Trigger
+		}
+
+		if (gpio_in.GFD[1] == 1)
+		{
+			// GFD_2 Trigger
+		}
+
+		if (gpio_in.AC_Drop == 1)
+		{
+			// AC Drop
+			PRINTF_FUNC("RB AC Drop. \n");
+		}
+
+		if (gpio_in.Emergency_IO == 1)
+		{
+			// Emergency IO ON
+			PRINTF_FUNC("RB Emergency IO ON. \n");
+		}
+
+		if (gpio_in.Button_Emergency_Press == 1)
+		{
+			// Emergency button Press
+		}
+
+		if (gpio_in.Button_On_Press == 1)
+		{
+			// On button Press
+		}
+
+		if (gpio_in.Button_Off_Press == 1)
+		{
+			// Off button Press
+		}
+
+		if (gpio_in.Key_1_Press == 1)
+		{
+			// key 1 press
+		}
+
+		if (gpio_in.Key_2_Press == 1)
+		{
+			// key 2 press
+		}
+
+		if (gpio_in.Key_3_Press == 1)
+		{
+			// key 3 press
+		}
+
+		if (gpio_in.Key_4_Press == 1)
+		{
+			// key 4 press
+		}
+	}
+}
+
+// 5V 12V 24V 48V
+void GetAuxPower()
+{
+	if (Query_Aux_PowerVoltage(Uart5Fd, Addr.Fan, &auxPower) == PASS)
+	{
+		ShmSysConfigAndInfo->SysInfo.AuxPower48V = auxPower.voltage[0];
+		ShmSysConfigAndInfo->SysInfo.AuxPower24V = auxPower.voltage[1];
+		//ShmSysConfigAndInfo->SysInfo.AuxPower12V = auxPower.voltage[4];
+		//ShmSysConfigAndInfo->SysInfo.AuxPower5V = auxPower.voltage[6];
+		// aux power voltage
+		//PRINTF_FUNC("aux1 = %x, \n", auxPower.voltage[0]);
+		//PRINTF_FUNC("aux2 = %x, \n", auxPower.voltage[1]);
+	}
+}
+
+void SetFanModuleSpeed()
+{
+	{
+		FanSpeed _fanSpeed;
+
+		_setFanSpeed += fanSpeedSmoothValue;
+
+		if (_setFanSpeed >= ShmFanModuleData->SetFan1Speed)
+			_setFanSpeed = ShmFanModuleData->SetFan1Speed;
+
+		//printf("_setFanSpeed = %d \n", _setFanSpeed);
+		_fanSpeed.speed[0] = _setFanSpeed;
+
+		_fanSpeed.speed[1] = _setFanSpeed;
+
+		_fanSpeed.speed[2] = _setFanSpeed;
+
+		_fanSpeed.speed[3] = _setFanSpeed;
+
+		if (Config_Fan_Speed(Uart5Fd, Addr.Fan, &_fanSpeed) == PASS)
+		{
+			//PRINTF_FUNC("successfully Fan\n");
+		}
+	}
+}
+
+//==========================================
+// Common Function
+//==========================================
+void SetK1K2RelayStatus(byte index)
+{
+	if (ShmPsuData->Work_Step >= _TEST_MODE && ShmPsuData->Work_Step <= _TEST_MODE)
+	{
+		if(regRelay.relay_event.bits.Gun1_N == NO)
+			outputRelay.relay_event.bits.Gun1_N = YES;
+		else if (regRelay.relay_event.bits.Gun1_P == NO)
+			outputRelay.relay_event.bits.Gun1_P = YES;
+		return;
+	}
+
+	if (_chargingData[index]->SystemStatus < SYS_MODE_PREPARE_FOR_EVSE ||
+			_chargingData[index]->SystemStatus == SYS_MODE_FAULT)
+	{
+		if (_chargingData[index]->Evboard_id == 0x01)
+		{
+			outputRelay.relay_event.bits.Gun1_P = NO;
+			outputRelay.relay_event.bits.Gun1_N = NO;
+
+			if (gunCount == 1 && _chargingData[index]->Type == _Type_CCS)
+			{
+				if(regRelay.relay_event.bits.CCS_Precharge == YES)
+					outputRelay.relay_event.bits.CCS_Precharge = NO;
+			}
+		}
+		else if (_chargingData[index]->Evboard_id == 0x02)
+		{
+			outputRelay.relay_event.bits.Gun2_P = NO;
+			outputRelay.relay_event.bits.Gun2_N = NO;
+
+			if (_chargingData[index]->Type == _Type_CCS)
+			{
+				if(regRelay.relay_event.bits.CCS_Precharge == YES)
+					outputRelay.relay_event.bits.CCS_Precharge = NO;
+			}
+		}
+	}
+	else if ((_chargingData[index]->SystemStatus >= SYS_MODE_PREPARE_FOR_EVSE &&
+			_chargingData[index]->SystemStatus <= SYS_MODE_CHARGING))
+	{
+		//if (_chargingData[index]->RelayWeldingCheck == YES)
+		{
+			if (_chargingData[index]->Evboard_id == 0x01)
+			{
+				if(regRelay.relay_event.bits.Gun1_N == NO)
+					outputRelay.relay_event.bits.Gun1_N = YES;
+				else if (regRelay.relay_event.bits.Gun1_P == NO)
+					outputRelay.relay_event.bits.Gun1_P = YES;
+			}
+			else if (_chargingData[index]->Evboard_id == 0x02)
+			{
+				if(regRelay.relay_event.bits.Gun2_N == NO)
+					outputRelay.relay_event.bits.Gun2_N = YES;
+				else if (regRelay.relay_event.bits.Gun2_P == NO)
+					outputRelay.relay_event.bits.Gun2_P = YES;
+			}
+		}
+	}
+	else if (_chargingData[index]->SystemStatus >= SYS_MODE_TERMINATING &&
+			_chargingData[index]->SystemStatus <= SYS_MODE_ALARM)
+	{
+		if ((_chargingData[index]->PresentChargingCurrent * 10) <= SEFETY_SWITCH_RELAY_CUR)
+		{
+			if (_chargingData[index]->Evboard_id == 0x01)
+			{
+				if(regRelay.relay_event.bits.Gun1_P == YES)
+					outputRelay.relay_event.bits.Gun1_P = NO;
+				else if (regRelay.relay_event.bits.Gun1_N == YES)
+					outputRelay.relay_event.bits.Gun1_N = NO;
+			}
+			else if (_chargingData[index]->Evboard_id == 0x02)
+			{
+				if(regRelay.relay_event.bits.Gun2_P == YES)
+					outputRelay.relay_event.bits.Gun2_P = NO;
+				else if (regRelay.relay_event.bits.Gun2_N == YES)
+					outputRelay.relay_event.bits.Gun2_N = NO;
+			}
+		}
+	}
+	else if (_chargingData[index]->SystemStatus == SYS_MODE_CCS_PRECHARGE_STEP0)
+	{
+//		if (_chargingData[index]->Evboard_id == 0x01)
+//		{
+//			if (_chargingData[index]->Type == _Type_CCS_2)
+//			{
+//				if (gunCount == 1)
+//				{
+//					if (regRelay.relay_event.bits.CCS_Precharge == NO)
+//						outputRelay.relay_event.bits.CCS_Precharge = YES;
+//					else if (regRelay.relay_event.bits.CCS_Precharge == YES)
+//						outputRelay.relay_event.bits.Gun1_P = NO;
+//				}
+//			}
+//		}
+//		else if (_chargingData[index]->Evboard_id == 0x02)
+//		{
+//			if (_chargingData[index]->Type == _Type_CCS_2)
+//			{
+//				if (regRelay.relay_event.bits.CCS_Precharge == NO)
+//					outputRelay.relay_event.bits.CCS_Precharge = YES;
+//				else if (regRelay.relay_event.bits.CCS_Precharge == YES)
+//					outputRelay.relay_event.bits.Gun2_P = NO;
+//			}
+//		}
+	}
+	else if (_chargingData[index]->SystemStatus == SYS_MODE_CCS_PRECHARGE_STEP1)
+	{
+//		if (_chargingData[index]->Evboard_id == 0x01)
+//		{
+//			if (_chargingData[index]->Type == _Type_CCS_2)
+//			{
+//				if (gunCount == 1)
+//				{
+//					if (regRelay.relay_event.bits.Gun1_P == NO)
+//						outputRelay.relay_event.bits.Gun1_P = YES;
+//					else if(regRelay.relay_event.bits.Gun1_P == YES)
+//						outputRelay.relay_event.bits.CCS_Precharge = NO;
+//				}
+//			}
+//		}
+//		else if (_chargingData[index]->Evboard_id == 0x02)
+//		{
+//			if (_chargingData[index]->Type == _Type_CCS_2)
+//			{
+//				if (regRelay.relay_event.bits.Gun2_P == NO)
+//					outputRelay.relay_event.bits.Gun2_P = YES;
+//				else if(regRelay.relay_event.bits.Gun2_P == YES)
+//					outputRelay.relay_event.bits.CCS_Precharge = NO;
+//			}
+//		}
+	}
+}
+
+void SetParalleRelayStatus()
+{
+	// 之後雙槍單模機種,橋接都會上
+	if (gunCount >= 2 && ShmSysConfigAndInfo->SysInfo.IsAlternatvieConf == NO)
+	{
+		if (_chargingData[0]->SystemStatus == SYS_MODE_BOOTING || _chargingData[1]->SystemStatus == SYS_MODE_BOOTING ||
+				ShmSysConfigAndInfo->SysWarningInfo.Level == _ALARM_LEVEL_CRITICAL ||
+				((_chargingData[0]->SystemStatus == SYS_MODE_IDLE || _chargingData[0]->SystemStatus == SYS_MODE_MAINTAIN) &&
+				(_chargingData[1]->SystemStatus == SYS_MODE_IDLE || _chargingData[1]->SystemStatus == SYS_MODE_MAINTAIN)))
+		{
+			// 初始化~ 不搭橋接
+			if (regRelay.relay_event.bits.Gun1_Parallel_P == YES)
+				outputRelay.relay_event.bits.Gun1_Parallel_P = NO;
+			else if (regRelay.relay_event.bits.Gun1_Parallel_N == YES)
+				outputRelay.relay_event.bits.Gun1_Parallel_N = NO;
+		}
+		else
+		{
+			if (_chargingData[0]->IsReadyToCharging == YES ||
+					_chargingData[1]->IsReadyToCharging == YES)
+			{
+				// ************需考慮在切換中 - 切開 relay 與搭回 relay 的時機點************
+				if (ShmSysConfigAndInfo->SysInfo.MainChargingMode == _MAIN_CHARGING_MODE_MAX)
+				{
+					if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag < _REASSIGNED_RELAY_M_TO_A)
+					{
+						// 最大充 - 搭上橋接
+						if (regRelay.relay_event.bits.Gun1_Parallel_N == NO)
+							outputRelay.relay_event.bits.Gun1_Parallel_N = YES;
+						else if (regRelay.relay_event.bits.Gun1_Parallel_P == NO)
+							outputRelay.relay_event.bits.Gun1_Parallel_P = YES;
+					}
+					else
+					{
+						// 平均充 - 不搭
+						if (regRelay.relay_event.bits.Gun1_Parallel_P == YES)
+							outputRelay.relay_event.bits.Gun1_Parallel_P = NO;
+						else if (regRelay.relay_event.bits.Gun1_Parallel_N == YES)
+							outputRelay.relay_event.bits.Gun1_Parallel_N = NO;
+					}
+				}
+				else if (ShmSysConfigAndInfo->SysInfo.MainChargingMode == _MAIN_CHARGING_MODE_AVER)
+				{
+					if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag < _REASSIGNED_RELAY_A_TO_M)
+					{
+						// 平均充 - 不搭
+						if (regRelay.relay_event.bits.Gun1_Parallel_P == YES)
+							outputRelay.relay_event.bits.Gun1_Parallel_P = NO;
+						else if (regRelay.relay_event.bits.Gun1_Parallel_N == YES)
+							outputRelay.relay_event.bits.Gun1_Parallel_N = NO;
+					}
+					else
+					{
+						// 最大充 - 搭上橋接
+						if (regRelay.relay_event.bits.Gun1_Parallel_N == NO)
+							outputRelay.relay_event.bits.Gun1_Parallel_N = YES;
+						else if (regRelay.relay_event.bits.Gun1_Parallel_P == NO)
+							outputRelay.relay_event.bits.Gun1_Parallel_P = YES;
+					}
+				}
+			}
+		}
+	}
+}
+
+unsigned char DetectBitValue(int _value, unsigned char _bit)
+{
+	return ( _value & mask_table[_bit] ) != 0x00;
+}
+
+bool CheckAlarmOccur()
+{
+	bool isErr = false;
+	for(byte count = 0; count < sizeof(mask_table)/sizeof(mask_table[0]); count++)
+	{
+		byte value = DetectBitValue(acAlarmCode.AcAlarmCode, count);
+		if (value == 1)
+		{
+			isErr = true;
+			switch(count)
+			{
+				case L1_AC_OVP: ShmStatusCodeData->AlarmCode.AlarmEvents.bits.AcSystemInputOVP = YES; break;
+				case L1_AC_UVP: ShmStatusCodeData->AlarmCode.AlarmEvents.bits.AcSystemInputUVP = YES; break;
+				case L1_AC_OCP: ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAcOutputOCP = YES; break;
+				case AC_OTP: ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAmbientOTP = YES; break;
+				case AC_GMI_FAULT: ShmStatusCodeData->AlarmCode.AlarmEvents.bits.AcGroundfaultFail = YES; break;
+				case AC_CP_ERROR: ShmStatusCodeData->InfoCode.InfoEvents.bits.PilotFault = YES; break;
+				case AC_AC_LEAKAGE: ShmStatusCodeData->AlarmCode.AlarmEvents.bits.RcdTrip = YES; break;
+				case AC_DC_LEAKAGE: ShmStatusCodeData->AlarmCode.AlarmEvents.bits.RcdTrip = YES; break;
+				case AC_SYSTEM_SELFTEST_FAULT: ShmStatusCodeData->AlarmCode.AlarmEvents.bits.McuSelftestFail = YES; break;
+				case AC_HANDSHAKE_TIMEOUT: break;
+				case AC_EMC_STOP: ShmStatusCodeData->AlarmCode.AlarmEvents.bits.EmergencyStopTrip = YES; break;
+				case AC_RELAY_WELDING: ShmStatusCodeData->FaultCode.FaultEvents.bits.AcOutputRelayWelding = YES; break;
+				case AC_LEAK_MODULE_FAULT: ShmStatusCodeData->FaultCode.FaultEvents.bits.RcdSelfTestFail = YES; break;
+				case AC_SHUTTER_FAULT: ShmStatusCodeData->FaultCode.FaultEvents.bits.ShutterFault = YES; break;
+				case AC_LOCKER_FAULT: ShmStatusCodeData->FaultCode.FaultEvents.bits.AcConnectorLockFail = YES; break;
+				case AC_POWER_DROP: ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputDrop = YES; break;
+				case L1_AC_CIRCUIT_SHORT: ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CircuitShort = YES; break;
+				case AC_ROTARY_SWITCH_FAULT: ShmStatusCodeData->FaultCode.FaultEvents.bits.RotarySwitchFault = YES; break;
+				case AC_RELAY_DRIVE_FAULT: ShmStatusCodeData->FaultCode.FaultEvents.bits.AcOutputRelayDrivingFault = YES;break;
+				case RESERVED_1: break;
+				case L2_AC_OVP: ShmStatusCodeData->AlarmCode.AlarmEvents.bits.AcSystemInputOVP = YES; break;
+				case L3_AC_OVP: ShmStatusCodeData->AlarmCode.AlarmEvents.bits.AcSystemInputOVP = YES; break;
+				case L2_AC_UVP: ShmStatusCodeData->AlarmCode.AlarmEvents.bits.AcSystemInputUVP = YES; break;
+				case L3_AC_UVP: ShmStatusCodeData->AlarmCode.AlarmEvents.bits.AcSystemInputUVP = YES; break;
+				case L2_AC_OCP: ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAcOutputOCP = YES; break;
+				case L3_AC_OCP: ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAcOutputOCP = YES; break;
+				case L2_AC_CIRCUIT_SHORT: ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CircuitShort = YES; break;
+				case L3_AC_CIRCUIT_SHORT: ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CircuitShort = YES; break;
+				case AC_METER_TIMEOUT: ShmStatusCodeData->AlarmCode.AlarmEvents.bits.MeterCommTimeout = YES; break;
+				case AC_METER_IC_COMM_TIMEOUT: ShmStatusCodeData->AlarmCode.AlarmEvents.bits.MeterIcCommTimeout = YES; break;
+				case AC_CP_NEGATIVE_ERR: ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PilotNegativeError = YES; break;
+				case RESERVED_2: break;
+			}
+		}
+	}
+
+	if (!isErr)
+	{
+		if (ac_chargingInfo[0]->SystemStatus == SYS_MODE_IDLE ||
+							ac_chargingInfo [0]->SystemStatus == SYS_MODE_MAINTAIN ||
+							ac_chargingInfo [0]->SystemStatus == SYS_MODE_RESERVATION)
+		{
+			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.AcSystemInputOVP = NO;
+			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.AcSystemInputUVP = NO;
+			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAcOutputOCP = NO;
+			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAmbientOTP = NO;
+			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.AcGroundfaultFail = NO;
+			ShmStatusCodeData->InfoCode.InfoEvents.bits.PilotFault = NO;
+			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.RcdTrip = NO;
+			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.McuSelftestFail = NO;
+			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.EmergencyStopTrip = NO;
+			ShmStatusCodeData->FaultCode.FaultEvents.bits.AcOutputRelayWelding = NO;
+			ShmStatusCodeData->FaultCode.FaultEvents.bits.RcdSelfTestFail = NO;
+			ShmStatusCodeData->FaultCode.FaultEvents.bits.ShutterFault = NO;
+			ShmStatusCodeData->FaultCode.FaultEvents.bits.AcConnectorLockFail = NO;
+			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputDrop = NO;
+			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CircuitShort = NO;
+			ShmStatusCodeData->FaultCode.FaultEvents.bits.RotarySwitchFault = NO;
+			ShmStatusCodeData->FaultCode.FaultEvents.bits.AcOutputRelayDrivingFault = NO;
+			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.MeterCommTimeout = NO;
+			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.MeterIcCommTimeout = NO;
+			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PilotNegativeError = NO;
+		}
+	}
+
+	ac_chargingInfo[0]->IsErrorOccur = isErr;
+	return isErr;
+}
+
+bool IsNoneMatchLedColor()
+{
+	bool result = false;
+
+	if (cur_led_color.Connect_1_Red != led_color.Connect_1_Red ||
+		cur_led_color.Connect_1_Green != led_color.Connect_1_Green ||
+		cur_led_color.Connect_1_Blue != led_color.Connect_1_Blue ||
+		cur_led_color.Connect_2_Red != led_color.Connect_2_Red ||
+		cur_led_color.Connect_2_Green != led_color.Connect_2_Green ||
+		cur_led_color.Connect_2_Blue != led_color.Connect_2_Blue)
+	{
+		result = true;
+	}
+
+	return result;
+}
+
+void SetLedColor(struct ChargingInfoData *chargingData_1, struct ChargingInfoData *chargingData_2)
+{
+	byte _colorBuf = COLOR_MAX_LV * LED_INTENSITY_BRIGHTEST;
+
+	if (ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity == _LED_INTENSITY_DARKEST)
+		_colorBuf = COLOR_MAX_LV * LED_INTENSITY_DARKEST;
+	else if (ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity == _LED_INTENSITY_MEDIUM)
+		_colorBuf = COLOR_MAX_LV * LED_INTENSITY_MEDIUM;
+
+	if (ShmSysConfigAndInfo->SysWarningInfo.Level == _ALARM_LEVEL_CRITICAL ||
+			(chargingData_1->SystemStatus == SYS_MODE_UPDATE && chargingData_2->SystemStatus == SYS_MODE_UPDATE))
+	{
+		led_color.Connect_1_Green = COLOR_MIN_LV;
+		led_color.Connect_1_Blue = COLOR_MIN_LV;
+		led_color.Connect_1_Red = _colorBuf;
+		led_color.Connect_2_Green = COLOR_MIN_LV;
+		led_color.Connect_2_Blue = COLOR_MIN_LV;
+		led_color.Connect_2_Red = _colorBuf;
+	}
+	else
+	{
+		if (ShmSysConfigAndInfo->SysInfo.IsAlternatvieConf)
+		{
+			if (ShmDcCommonData->_isPsuErrorOccur)
+			{
+				led_color.Connect_1_Green = COLOR_MIN_LV;
+				led_color.Connect_1_Blue = COLOR_MIN_LV;
+				led_color.Connect_1_Red = _colorBuf;
+				led_color.Connect_2_Green = COLOR_MIN_LV;
+				led_color.Connect_2_Blue = COLOR_MIN_LV;
+				led_color.Connect_2_Red = _colorBuf;
+			}
+			else if ((chargingData_1->SystemStatus == SYS_MODE_BOOTING || chargingData_1->SystemStatus == SYS_MODE_IDLE || chargingData_1->SystemStatus == SYS_MODE_RESERVATION || chargingData_1->SystemStatus == SYS_MODE_MAINTAIN) &&
+					(chargingData_2->SystemStatus == SYS_MODE_BOOTING || chargingData_2->SystemStatus == SYS_MODE_IDLE || chargingData_2->SystemStatus == SYS_MODE_RESERVATION || chargingData_2->SystemStatus == SYS_MODE_MAINTAIN))
+			{
+				led_color.Connect_1_Green = _colorBuf;
+				led_color.Connect_1_Blue = COLOR_MIN_LV;
+				led_color.Connect_1_Red = COLOR_MIN_LV;
+				led_color.Connect_2_Green = _colorBuf;
+				led_color.Connect_2_Blue = COLOR_MIN_LV;
+				led_color.Connect_2_Red = COLOR_MIN_LV;
+
+				if (chargingData_1->SystemStatus == SYS_MODE_RESERVATION ||
+						chargingData_2->SystemStatus == SYS_MODE_RESERVATION)
+				{
+					if (GetTimeoutValue(&_led_blink_time) > 3)
+					{
+						led_color.Connect_1_Green = COLOR_MIN_LV;
+						led_color.Connect_2_Green = COLOR_MIN_LV;
+					}
+				}
+				else if (chargingData_1->SystemStatus == SYS_MODE_MAINTAIN ||
+						chargingData_2->SystemStatus == SYS_MODE_MAINTAIN)
+				{
+					led_color.Connect_1_Green = COLOR_MIN_LV;
+					led_color.Connect_2_Green = COLOR_MIN_LV;
+					led_color.Connect_1_Red = _colorBuf;
+					led_color.Connect_2_Red = _colorBuf;
+				}
+			}
+			else if ((chargingData_1->SystemStatus >= SYS_MODE_AUTHORIZING && chargingData_1->SystemStatus <= SYS_MODE_COMPLETE) ||
+				     	(chargingData_1->SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0 && chargingData_1->SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) ||
+						(chargingData_2->SystemStatus >= SYS_MODE_AUTHORIZING && chargingData_2->SystemStatus <= SYS_MODE_COMPLETE) ||
+						(chargingData_2->SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0 && chargingData_2->SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))
+			{
+				led_color.Connect_1_Green = COLOR_MIN_LV;
+				led_color.Connect_1_Blue = _colorBuf;
+				led_color.Connect_1_Red = COLOR_MIN_LV;
+				led_color.Connect_2_Green = COLOR_MIN_LV;
+				led_color.Connect_2_Blue = _colorBuf;
+				led_color.Connect_2_Red = COLOR_MIN_LV;
+			}
+		}
+		else
+		{
+			if (ShmDcCommonData->_isPsuErrorOccur)
+			{
+				if (chargingData_1->SystemStatus == SYS_MODE_BOOTING ||
+						chargingData_1->SystemStatus == SYS_MODE_IDLE ||
+						chargingData_1->SystemStatus == SYS_MODE_RESERVATION ||
+						chargingData_1->SystemStatus == SYS_MODE_MAINTAIN)
+				{
+					led_color.Connect_1_Green = COLOR_MIN_LV;
+					led_color.Connect_1_Blue = COLOR_MIN_LV;
+					led_color.Connect_1_Red = _colorBuf;
+				}
+			}
+			else if (chargingData_1->SystemStatus == SYS_MODE_BOOTING ||
+					chargingData_1->SystemStatus == SYS_MODE_IDLE ||
+					chargingData_1->SystemStatus == SYS_MODE_RESERVATION ||
+					chargingData_1->SystemStatus == SYS_MODE_MAINTAIN)
+			{
+				led_color.Connect_1_Green = _colorBuf;
+				led_color.Connect_1_Blue = COLOR_MIN_LV;
+				led_color.Connect_1_Red = COLOR_MIN_LV;
+
+				if (chargingData_1->SystemStatus == SYS_MODE_RESERVATION)
+				{
+					if (GetTimeoutValue(&_led_blink_time) > 3)
+					{
+						led_color.Connect_1_Green = COLOR_MIN_LV;
+					}
+				}
+				else if (chargingData_1->SystemStatus == SYS_MODE_MAINTAIN)
+				{
+					led_color.Connect_1_Green = COLOR_MIN_LV;
+					led_color.Connect_1_Red = _colorBuf;
+				}
+			}
+			else if ((chargingData_1->SystemStatus >= SYS_MODE_AUTHORIZING && chargingData_1->SystemStatus <= SYS_MODE_COMPLETE) ||
+						(chargingData_1->SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0 && chargingData_1->SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))
+			{
+				led_color.Connect_1_Green = COLOR_MIN_LV;
+				led_color.Connect_1_Blue = _colorBuf;
+				led_color.Connect_1_Red = COLOR_MIN_LV;
+			}
+
+			// --------------------------------------------------------------------------
+			if (ShmDcCommonData->_isPsuErrorOccur)
+			{
+				if (chargingData_2->SystemStatus == SYS_MODE_BOOTING ||
+						chargingData_2->SystemStatus == SYS_MODE_IDLE ||
+						chargingData_2->SystemStatus == SYS_MODE_RESERVATION ||
+						chargingData_2->SystemStatus == SYS_MODE_MAINTAIN)
+				{
+					led_color.Connect_2_Green = COLOR_MIN_LV;
+					led_color.Connect_2_Blue = COLOR_MIN_LV;
+					led_color.Connect_2_Red = _colorBuf;
+				}
+			}
+			else if (chargingData_2->SystemStatus == SYS_MODE_BOOTING ||
+					chargingData_2->SystemStatus == SYS_MODE_IDLE ||
+					chargingData_2->SystemStatus == SYS_MODE_RESERVATION ||
+					chargingData_2->SystemStatus == SYS_MODE_MAINTAIN)
+			{
+				led_color.Connect_2_Green = _colorBuf;
+				led_color.Connect_2_Blue = COLOR_MIN_LV;
+				led_color.Connect_2_Red = COLOR_MIN_LV;
+
+				if (chargingData_2->SystemStatus == SYS_MODE_RESERVATION)
+				{
+					if (GetTimeoutValue(&_led_blink_time) > 3)
+					{
+						led_color.Connect_2_Green = COLOR_MIN_LV;
+					}
+				}
+				else if (chargingData_2->SystemStatus == SYS_MODE_MAINTAIN)
+				{
+					led_color.Connect_2_Green = COLOR_MIN_LV;
+					led_color.Connect_2_Red = _colorBuf;
+				}
+			}
+			else if ((chargingData_2->SystemStatus >= SYS_MODE_AUTHORIZING && chargingData_2->SystemStatus <= SYS_MODE_COMPLETE) ||
+						(chargingData_2->SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0 && chargingData_2->SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))
+			{
+				led_color.Connect_2_Green = COLOR_MIN_LV;
+				led_color.Connect_2_Blue = _colorBuf;
+				led_color.Connect_2_Red = COLOR_MIN_LV;
+			}
+		}
+	}
+
+	if (_checkLedChanged > 0)
+	{
+		if (Config_Led_Color(Uart5Fd, Addr.Led, &led_color) == PASS)
+		{
+			_checkLedChanged--;
+
+			cur_led_color.Connect_1_Red 	= led_color.Connect_1_Red;
+			cur_led_color.Connect_1_Green 	= led_color.Connect_1_Green;
+			cur_led_color.Connect_1_Blue 	= led_color.Connect_1_Blue;
+			cur_led_color.Connect_2_Red 	= led_color.Connect_2_Red;
+			cur_led_color.Connect_2_Green	= led_color.Connect_2_Green;
+			cur_led_color.Connect_2_Blue 	= led_color.Connect_2_Blue;
+		}
+	}
+	else if (IsNoneMatchLedColor())
+		_checkLedChanged = 3;
+}
+//==========================================
+// Init all share memory
+//==========================================
+int InitShareMemory()
+{
+	int result = PASS;
+	int MeterSMId;
+
+	if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo),  0777)) < 0)
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
+		#endif
+		result = FAIL;
+	}
+	else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR("[shmat ShmSysConfigAndInfo NG\n");
+		#endif
+		result = FAIL;
+	}
+
+	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;
+	}
+
+	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;
+	   	}
+	}
+
+	if ((MeterSMId = shmget(ShmFanBdKey, sizeof(struct FanModuleData),  0777)) < 0)
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR("shmget ShmFanModuleData NG\n");
+		#endif
+		result = FAIL;
+	}
+	else if ((ShmFanModuleData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR("shmat ShmFanModuleData NG\n");
+		#endif
+		result = FAIL;
+	}
+
+	if ((MeterSMId = shmget(ShmRelayBdKey, sizeof(struct RelayModuleData),  0777)) < 0)
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR("shmget ShmRelayModuleData NG\n");
+		#endif
+		result = FAIL;
+	}
+	else if ((ShmRelayModuleData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR("shmat ShmRelayModuleData NG\n");
+		#endif
+		result = FAIL;
+	}
+
+	if ((MeterSMId = shmget(ShmLedBdKey, sizeof(struct LedModuleData),  0777)) < 0)
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR("shmget ShmLedModuleData NG\n");
+		#endif
+		result = FAIL;
+	}
+	else if ((ShmLedModuleData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR("shmat ShmLedModuleData NG\n");
+		#endif
+		result = FAIL;
+	}
+
+	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;
+	}
+
+	if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR("shmat ShmOCPP16Data NG \n");
+		#endif
+		result = FAIL;
+	}
+	else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR("shmat ShmOCPP16Data NG \n");
+		#endif
+		result = FAIL;
+	}
+
+	if ((MeterSMId = shmget(ShmOcpp20ModuleKey, sizeof(struct OCPP20Data), IPC_CREAT | 0777)) < 0)
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR("shmat ShmOCPP20Data NG \n");
+		#endif
+		result = FAIL;
+	}
+	else if ((ShmOCPP20Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR("shmat ShmOCPP20Data NG \n");
+		#endif
+		result = FAIL;
+	}
+
+	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;
+	}
+
+	if ((MeterSMId = shmget(ShmCommonKey, sizeof(struct DcCommonInformation), IPC_CREAT | 0777)) < 0)
+   	{
+   		#ifdef SystemLogMessage
+   		DEBUG_ERROR("shmget ShmCommonKey NG \n");
+   		#endif
+   		return 0;
+   	}
+   	else if ((ShmDcCommonData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
+   	{
+   		#ifdef SystemLogMessage
+   		DEBUG_ERROR("shmat ShmCommonKey NG \n");
+   		#endif
+   		return 0;
+   	}
+
+	return result;
+}
+
+int InitComPort()
+{
+	int fd;
+	struct termios tios;
+
+	fd = open(relayRs485PortName, O_RDWR);
+	if(fd <= 0)
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR("Module_InternalComm. InitComPort NG\n");
+		#endif
+		if(ShmStatusCodeData!=NULL)
+		{
+			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed=1;
+		}
+		sleep(5);
+		return -1;
+	}
+	ioctl (fd, TCGETS, &tios);
+	tios.c_cflag = B115200 | CS8 | CLOCAL | CREAD;
+	tios.c_lflag = 0;
+	tios.c_iflag = 0;
+	tios.c_oflag = 0;
+	tios.c_cc[VMIN]=0;
+	tios.c_cc[VTIME]=(byte)0;		// timeout 0.5 second
+	tios.c_lflag=0;
+	tcflush(fd, TCIFLUSH);
+	ioctl (fd, TCSETS, &tios);
+
+	return fd;
+}
+
+//================================================
+// Main process
+//================================================
+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;
+}
+
+void Initialization()
+{
+	bool isPass = false;
+
+	isAcModuleInitComp = false;
+	for (byte index = 0; index < ARRAY_SIZE(outputRelay.relay_event.relay_status); index++)
+	{
+		outputRelay.relay_event.relay_status[index] = 0x00;
+	}
+
+	while(!isPass)
+	{
+		isPass = true;
+		for (byte _index = 0; _index < gunCount; _index++)
+		{
+			if (!FindChargingInfoData(_index, &_chargingData[0]))
+			{
+				DEBUG_ERROR("InternalComm : FindChargingInfoData false (%d) \n", gunCount);
+				isPass = false;
+				break;
+			}
+		}
+
+		sleep(1);
+	}
+
+	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;
+				}
+			}
+
+			sleep(1);
+		}
+	}
+}
+
+void StartCheckRelayInfo(byte _chkIndex, byte toState)
+{
+	if (ShmDcCommonData->RelayCheckStatus[_chkIndex] == STOP)
+	{
+		GetTimespecFunc(&_relayStateChkTimer[_chkIndex]);
+		ShmDcCommonData->RelayCheckStatus[_chkIndex] = START;
+	}
+	else
+	{
+		int _timebuf = GetTimeoutValue(&_relayStateChkTimer[_chkIndex]);
+
+		if (_timebuf < 0)
+			GetTimespecFunc(&_relayStateChkTimer[_chkIndex]);
+		else
+		{
+			if (_timebuf > RELAY_CHECK_TIME)
+			{
+				//PRINTF_FUNC ("relay welding or driving fault = %d \n", _chkIndex);
+				if (toState == 1)
+					ShmDcCommonData->RelayCheckStatus[_chkIndex] = RELAY_STATUS_ERROR_DRIVING;
+				else
+					ShmDcCommonData->RelayCheckStatus[_chkIndex] = RELAY_STATUS_ERROR_WELDING;
+			}
+		}
+	}
+}
+
+void StopCheckRelayInfo(byte _chkIndex)
+{
+	if (ShmDcCommonData->RelayCheckStatus[_chkIndex] != STOP)
+	{
+		ShmDcCommonData->RelayCheckStatus[_chkIndex] = STOP;
+	}
+}
+
+bool IsNoneMatchRelayStatus()
+{
+	bool result = false;
+
+	if ((regRelay.relay_event.bits.AC_Contactor != outputRelay.relay_event.bits.AC_Contactor) ||
+		(regRelay.relay_event.bits.CCS_Precharge != outputRelay.relay_event.bits.CCS_Precharge) ||
+		(regRelay.relay_event.bits.Gun1_P != outputRelay.relay_event.bits.Gun1_P) ||
+		(regRelay.relay_event.bits.Gun1_N != outputRelay.relay_event.bits.Gun1_N) ||
+		(regRelay.relay_event.bits.Gun2_P != outputRelay.relay_event.bits.Gun2_P) ||
+		(regRelay.relay_event.bits.Gun2_N != outputRelay.relay_event.bits.Gun2_N) ||
+		(regRelay.relay_event.bits.Gun1_Parallel_P != outputRelay.relay_event.bits.Gun1_Parallel_P) ||
+		(regRelay.relay_event.bits.Gun1_Parallel_N != outputRelay.relay_event.bits.Gun1_Parallel_N))
+	{
+		result = true;
+	}
+
+	if (regRelay.relay_event.bits.AC_Contactor != outputRelay.relay_event.bits.AC_Contactor)
+	{
+		//PRINTF_FUNC("AC Contact Relay none match, try to switch to %d \n", outputRelay.relay_event.bits.AC_Contactor);
+	}
+
+	if (regRelay.relay_event.bits.CCS_Precharge != outputRelay.relay_event.bits.CCS_Precharge)
+	{
+		//PRINTF_FUNC("CCS Precharge Relay none match, try to switch to %d \n", outputRelay.relay_event.bits.CCS_Precharge);
+	}
+
+	if (regRelay.relay_event.bits.Gun1_P != outputRelay.relay_event.bits.Gun1_P)
+	{
+		StartCheckRelayInfo(RELAY_SMR1_P_STATUS, outputRelay.relay_event.bits.Gun1_P);
+		//PRINTF_FUNC("SMR1:D+ Relay none match, try to switch to %d \n", outputRelay.relay_event.bits.Gun1_P);
+	}
+	else
+	{
+		StopCheckRelayInfo(RELAY_SMR1_P_STATUS);
+		//PRINTF_FUNC("SMR1:D+ Release %d \n");
+	}
+
+	if (regRelay.relay_event.bits.Gun1_N != outputRelay.relay_event.bits.Gun1_N)
+	{
+		StartCheckRelayInfo(RELAY_SMR1_N_STATUS, outputRelay.relay_event.bits.Gun1_N);
+		//PRINTF_FUNC("SMR1:D- Relay none match, try to switch to %d \n", outputRelay.relay_event.bits.Gun1_N);
+	}
+	else
+	{
+		StopCheckRelayInfo(RELAY_SMR1_N_STATUS);
+	}
+
+	if (regRelay.relay_event.bits.Gun2_P != outputRelay.relay_event.bits.Gun2_P)
+	{
+		StartCheckRelayInfo(RELAY_SMR2_P_STATUS, outputRelay.relay_event.bits.Gun2_P);
+		//PRINTF_FUNC("SMR2:D+ Relay none match, try to switch to %d \n", outputRelay.relay_event.bits.Gun2_P);
+	}
+	else
+	{
+		StopCheckRelayInfo(RELAY_SMR2_P_STATUS);
+	}
+
+	if (regRelay.relay_event.bits.Gun2_N != outputRelay.relay_event.bits.Gun2_N)
+	{
+		StartCheckRelayInfo(RELAY_SMR2_N_STATUS, outputRelay.relay_event.bits.Gun2_N);
+		//PRINTF_FUNC("SMR2:D- Relay none match, try to switch to %d \n", outputRelay.relay_event.bits.Gun2_N);
+	}
+	else
+	{
+		StopCheckRelayInfo(RELAY_SMR2_N_STATUS);
+	}
+
+	if (regRelay.relay_event.bits.Gun1_Parallel_P != outputRelay.relay_event.bits.Gun1_Parallel_P)
+	{
+		StartCheckRelayInfo(RELAY_PARA_P_STATUS, outputRelay.relay_event.bits.Gun1_Parallel_P);
+		//PRINTF_FUNC("Parallel:D+ Relay none match, try to switch to %d \n", outputRelay.relay_event.bits.Gun1_Parallel_P);
+	}
+	else
+	{
+		StopCheckRelayInfo(RELAY_PARA_P_STATUS);
+	}
+
+	if (regRelay.relay_event.bits.Gun1_Parallel_N != outputRelay.relay_event.bits.Gun1_Parallel_N)
+	{
+		StartCheckRelayInfo(RELAY_PARA_N_STATUS, outputRelay.relay_event.bits.Gun1_Parallel_N);
+		//PRINTF_FUNC("Parallel:D- Relay none match, try to switch to %d \n", outputRelay.relay_event.bits.Gun1_Parallel_N);
+	}
+	else
+	{
+		StopCheckRelayInfo(RELAY_PARA_N_STATUS);
+	}
+
+	return result;
+}
+
+void MatchRelayStatus()
+{
+	// 因為 AC Contactor 沒有 Feedback,所以暫時先這樣處理
+	//regRelay.relay_event.bits.AC_Contactor = outputRelay.relay_event.bits.AC_Contactor;
+	ShmSysConfigAndInfo->SysInfo.AcContactorStatus  = regRelay.relay_event.bits.AC_Contactor = outputRelay.relay_event.bits.AC_Contactor;
+	regRelay.relay_event.bits.CCS_Precharge = outputRelay.relay_event.bits.CCS_Precharge;
+	regRelay.relay_event.bits.Gun1_P = outputRelay.relay_event.bits.Gun1_P;
+	regRelay.relay_event.bits.Gun1_N = outputRelay.relay_event.bits.Gun1_N;
+	regRelay.relay_event.bits.Gun2_P = outputRelay.relay_event.bits.Gun2_P;
+	regRelay.relay_event.bits.Gun2_N = outputRelay.relay_event.bits.Gun2_N;
+	regRelay.relay_event.bits.Gun1_Parallel_P = outputRelay.relay_event.bits.Gun1_Parallel_P;
+	regRelay.relay_event.bits.Gun1_Parallel_N = outputRelay.relay_event.bits.Gun1_Parallel_N;
+}
+
+void CheckRelayStatusByADC()
+{
+	if (ShmRelayModuleData->Gun1FuseOutputVolt > 0 && ShmRelayModuleData->Gun1RelayOutputVolt > 0 &&
+			(ShmRelayModuleData->Gun1FuseOutputVolt == ShmRelayModuleData->Gun1RelayOutputVolt))
+	{
+		// Relay 前後電壓一致
+		_chargingData[0]->RelayK1K2Status = 0x01;
+	}
+	else
+		_chargingData[0]->RelayK1K2Status = 0x00;
+
+	if (ShmRelayModuleData->Gun2FuseOutputVolt > 0 && ShmRelayModuleData->Gun2RelayOutputVolt > 0 &&
+				(ShmRelayModuleData->Gun2FuseOutputVolt == ShmRelayModuleData->Gun2RelayOutputVolt))
+	{
+		// Relay 前後電壓一致
+		_chargingData[1]->RelayK1K2Status = 0x01;
+	}
+	else
+		_chargingData[1]->RelayK1K2Status = 0x00;
+}
+
+void SetGfdConfig(byte index, byte resister)
+{
+	gfd_config.index = index;
+	gfd_config.state = resister;
+
+	//PRINTF_FUNC("************************GFD Vol = %d, GFD Res = %d \n", gfd_config.reqVol, gfd_config.resister);
+	if (Config_Gfd_Value(Uart5Fd, Addr.Relay, &gfd_config) == PASS)
+	{
+//		PRINTF_FUNC("Set reqVol = %f, resister = %d \n",
+//				gfd_config.reqVol,
+//				gfd_config.resister);
+	}
+}
+
+//===============================================
+// Common Detect Chk - CCS
+//===============================================
+byte isPrechargeStatus_ccs(byte gunIndex)
+{
+	byte result = 0x00;
+
+	if (ShmCcsData->CommProtocol == _CCS_COMM_V2GMessage_DIN70121)
+	{
+		result = ShmCcsData->V2GMessage_DIN70121[_chargingData[gunIndex]->type_index].PresentMsgFlowStatus;
+	}
+
+	return result;
+}
+
+void CableCheckDetected(byte index)
+{
+	// Cable Check
+	// 當火線上的電壓 = 車端要求的電壓電流
+	// _chargingData[targetGun]->EvBatterytargetVoltage
+	// 主要驗證阻值為 100 與 500 當小於 100 * 950 時,為 Alarm,介於 100 * 950 與 500 * 950 時為 Warning
+	// 950 為系統最大電壓
+	// Alarm : Rgfd <= 95K
+	// Warning : 95K < Rgfd <= 475
+	// Normal : Rgfd > 475K
+	if ((_chargingData[index]->Type >= _Type_Chademo && _chargingData[index]->Type <= _Type_GB) ||
+			(_chargingData[index]->Type == 0x09 && ShmSysConfigAndInfo->SysConfig.AlwaysGfdFlag))
+	{
+		if ((_chargingData[index]->SystemStatus >= SYS_MODE_PREPARE_FOR_EVSE && _chargingData[index]->SystemStatus < SYS_MODE_TERMINATING) ||
+			(_chargingData[index]->SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0 && _chargingData[index]->SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))
+		{
+			if (_chargingData[index]->SystemStatus == SYS_MODE_PREPARE_FOR_EVSE)
+			{
+				SetGfdConfig(index, GFD_CABLECHK);
+			}
+			else if (_chargingData[index]->SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0 &&
+					_chargingData[index]->SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1 &&
+					_chargingData[index]->PresentChargingVoltage >= CCS_PRECHARGE_VOL &&
+					isPrechargeStatus_ccs(index) >= CCS_PRECHARGE_STARTU)
+			{
+				SetGfdConfig(index, GFD_PRECHARGE);
+			}
+			else if (_chargingData[index]->SystemStatus >= SYS_MODE_CHARGING &&
+					_chargingData[index]->SystemStatus < SYS_MODE_TERMINATING)
+			{
+				if (_chargingData[index]->Type == _Type_GB || _chargingData[index]->Type == _Type_Chademo)
+					SetGfdConfig(index, GFD_IDLE);
+				else
+					SetGfdConfig(index, GFD_CHARGING);
+			}
+		}
+		else
+		{
+			SetGfdConfig(index, GFD_IDLE);
+		}
+	}
+}
+
+void CheckOutputPowerOverCarReq(byte index)
+{
+	float fireV = _chargingData[index]->FireChargingVoltage;
+	float carV = _chargingData[index]->EvBatteryMaxVoltage * 10 > _chargingData[index]->ConnectorMaxVoltage ?
+			_chargingData[index]->ConnectorMaxVoltage : _chargingData[index]->EvBatteryMaxVoltage * 10;
+
+	if ((_chargingData[index]->EvBatterytargetVoltage * 10) > 1500 &&
+			(_chargingData[index]->Type == _Type_Chademo ||
+				_chargingData[index]->Type == _Type_CCS ||
+				_chargingData[index]->Type == _Type_GB))
+	{
+		if (fireV >= (carV + (carV * 0.02)))
+		{
+			if (!_isOvpChkTimeFlag[index])
+			{
+				if ((_chargingData[index]->PresentChargingVoltage * 10) >= VOUT_MIN_VOLTAGE * 10)
+				{
+					GetTimespecMFunc(&_checkOutputVolProtectTimer[index]);
+					_isOvpChkTimeFlag[index] = YES;
+					PRINTF_FUNC("First time : CheckOutputPowerOverCarReq NG : fire = %f, req = %f, max-battery = %f \n",
+							_chargingData[index]->FireChargingVoltage, (_chargingData[index]->EvBatterytargetVoltage * 10), carV);
+				}
+			}
+			else
+			{
+				int _timebuf = GetTimeoutMValue(&_checkOutputVolProtectTimer[index]);
+
+				if (_timebuf < 0)
+					GetTimespecMFunc(&_checkOutputVolProtectTimer[index]);
+				else
+				{
+					if (GetTimeoutMValue(&_checkOutputVolProtectTimer[index]) >= OUTPUT_VOL_CHK_TIME)
+					{
+						PRINTF_FUNC("[Module_InternalComm]CheckOutputPowerOverCarReq NG : fire = %f, req = %f, max-battery = %f \n",
+								_chargingData[index]->FireChargingVoltage, (_chargingData[index]->EvBatterytargetVoltage * 10), carV);
+						DEBUG_ERROR("[Module_InternalComm]CheckOutputPowerOverCarReq NG : fire = %f, req = %f, max-battery = %f \n",
+								_chargingData[index]->FireChargingVoltage, (_chargingData[index]->EvBatterytargetVoltage * 10), carV);
+
+						if (_chargingData[index]->Type == _Type_Chademo)
+						{
+							ShmDcCommonData->ConnectErrList[index].GunBits.ChaConnectOVP = YES;
+							if (strncmp((char *)_chargingData[index]->ConnectorAlarmCode, "", 6) == EQUAL)
+								memcpy(_chargingData[index]->ConnectorAlarmCode, "012217", 6);
+						}
+						else if (_chargingData[index]->Type == _Type_CCS)
+						{
+							ShmDcCommonData->ConnectErrList[index].GunBits.CCSConnectOVP = YES;
+							if (strncmp((char *)_chargingData[index]->ConnectorAlarmCode, "", 6) == EQUAL)
+								memcpy(_chargingData[index]->ConnectorAlarmCode, "012219", 6);
+						}
+						else if (_chargingData[index]->Type == _Type_GB)
+						{
+							ShmDcCommonData->ConnectErrList[index].GunBits.GBTConnectOVP = YES;
+							if (strncmp((char *)_chargingData[index]->ConnectorAlarmCode, "", 6) == EQUAL)
+								memcpy(_chargingData[index]->ConnectorAlarmCode, "012221", 6);
+						}
+
+						_chargingData[index]->StopChargeFlag = YES;
+					}
+				}
+			}
+		}
+		else
+			_isOvpChkTimeFlag[index] = NO;
+	}
+}
+
+void CheckOutputVolNoneMatchFire(byte index)
+{
+	if (((_chargingData[index]->EvBatterytargetVoltage * 10) > 1500 ||
+			_chargingData[index]->RelayK1K2Status == NO) &&
+			(_chargingData[index]->Type == _Type_CCS))
+	{
+		if (((_chargingData[index]->PresentChargingVoltage * 10) < _chargingData[index]->FireChargingVoltage - 300) ||
+				((_chargingData[index]->PresentChargingVoltage * 10) > _chargingData[index]->FireChargingVoltage + 300))
+		{
+			if (!_isOutputNoneMatch[index])
+			{
+				_isOutputNoneMatch[index] = YES;
+				GetTimespecFunc(&_checkOutputNoneMatchTimer[index]);
+			}
+			else
+			{
+				if (GetTimeoutValue(&_checkOutputNoneMatchTimer[index]) >= 2)
+				{
+					PRINTF_FUNC("Abnormal voltage on the Output at the stage of GFD. (%d) : pre = %.1f, fire = %.1f \n",
+							index, (_chargingData[index]->PresentChargingVoltage * 10), _chargingData[index]->FireChargingVoltage);
+
+					if (index == 0)
+					{
+						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.AbnormalVoltageOnOutputLine_1 = YES;
+						if (strncmp((char *)_chargingData[index]->ConnectorAlarmCode, "", 6) == EQUAL)
+								memcpy(_chargingData[index]->ConnectorAlarmCode, "012324", 6);
+					}
+					else if (index == 1)
+					{
+						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.AbnormalVoltageOnOutputLine_2 = YES;
+						if (strncmp((char *)_chargingData[index]->ConnectorAlarmCode, "", 6) == EQUAL)
+								memcpy(_chargingData[index]->ConnectorAlarmCode, "012325", 6);
+					}
+
+					_chargingData[index]->StopChargeFlag = YES;
+				}
+			}
+		}
+		else
+			_isOutputNoneMatch[index] = NO;
+	}
+}
+
+void GetPsuTempForFanSpeed()
+{
+	char temp = 0;
+
+	for (byte index = 0; index < ShmPsuData->GroupCount; index++)
+	{
+		for (byte count = 0; count < ShmPsuData->PsuGroup[index].GroupPresentPsuQuantity; count++)
+		{
+			if (temp < ShmPsuData->PsuGroup[index].PsuModule[count].ExletTemp)
+				temp = ShmPsuData->PsuGroup[index].PsuModule[count].ExletTemp;
+		}
+	}
+
+	ShmSysConfigAndInfo->SysInfo.SystemAmbientTemp = temp;
+
+	if (ShmSysConfigAndInfo->SysConfig.SwitchDebugFlag == NO)
+	{
+		if (ShmFanModuleData->TestFanSpeed == NORMAL_FAN_SPEED)
+		{
+			if (temp >= ENV_TEMP_MAX)
+				ShmFanModuleData->TestFanSpeed = MAX_FAN_SPEED;
+		}
+		else if (ShmFanModuleData->TestFanSpeed == MAX_FAN_SPEED)
+		{
+			if (temp <= ENV_TEMP_MIN)
+				ShmFanModuleData->TestFanSpeed = NORMAL_FAN_SPEED;
+		}
+		else
+			ShmFanModuleData->TestFanSpeed = NORMAL_FAN_SPEED;
+	}
+}
+
+void GetFanSpeedByFunction()
+{
+	// 風控修改 :
+	// ******************************************************* //
+	//
+	//       當前PSU輸出總 KW       PSU Temp
+	// 50 x -------------------- x ---------- + 0.5 x (PSU Temp - 70)
+	//       當前樁最大功率 KW         50
+	//
+	// ******************************************************* //
+
+	// 當前樁最大功率 KW : ShmPsuData->SystemAvailablePower
+	unsigned int _maxPower = ShmPsuData->SystemAvailablePower;
+	// 當前PSU輸出總 KW & PSU Temp :
+	unsigned char temp = 0;
+	float power = 0;
+
+	for (byte index = 0; index < ShmPsuData->GroupCount; index++)
+	{
+		for (byte count = 0; count < ShmPsuData->PsuGroup[index].GroupPresentPsuQuantity; count++)
+		{
+			if (temp < ShmPsuData->PsuGroup[index].PsuModule[count].ExletTemp)
+				temp = ShmPsuData->PsuGroup[index].PsuModule[count].ExletTemp;
+		}
+	}
+
+	for (byte gunIndex = 0; gunIndex < gunCount; gunIndex++)
+	{
+		power += (_chargingData[gunIndex]->PresentChargingPower * 10);
+	}
+
+	double _pw_rate = 0;
+	if (_maxPower > 0)
+		_pw_rate = power / (double)_maxPower;
+	double _temp_rate = 0;
+	if (temp > 0)
+		_temp_rate = (double)temp / 50;
+	unsigned char _temp_diff = 0;
+	if (temp > 70)
+		_temp_diff = temp - 70;
+
+	// debug mode 直接印出資訊後離開
+	if (ShmSysConfigAndInfo->SysConfig.SwitchDebugFlag == YES)
+	{
+//		printf("Fan Speed Information: power = %f, _maxPower = %d, temp = %d -- _pw_rate = %f, _temp_rate = %f, _temp_diff = %d \n",
+//				power, _maxPower, temp, _pw_rate, _temp_rate, _temp_diff);
+		return;
+	}
+
+	ShmFanModuleData->TestFanSpeed = (((50 * _pw_rate * _temp_rate) + (0.5 * _temp_diff)) / 100) * MAX_FAN_SPEED;
+
+	if (ShmFanModuleData->TestFanSpeed > MAX_FAN_SPEED)
+		ShmFanModuleData->TestFanSpeed = MAX_FAN_SPEED;
+
+	if (ShmFanModuleData->TestFanSpeed < 0)
+			ShmFanModuleData->TestFanSpeed = 0;
+
+// -----------------------------------------------------------------------
+//	printf("power = %f \n", power);
+//	printf("_maxPower = %d \n", _maxPower);
+//	printf("temp = %d \n", temp);
+//
+//	printf("_pw_rate = %f \n", _pw_rate);
+//	printf("_temp_rate = %f \n", _temp_rate);
+//	printf("_temp_diff = %d \n", _temp_diff);
+//	printf("fan rate = %f \n", (30 * _pw_rate * _temp_rate + 14 * _temp_diff));
+//	printf("ShmFanModuleData->TestFanSpeed = %d \n", ShmFanModuleData->TestFanSpeed);
+}
+
+bool GetAcStatus()
+{
+	bool isPass = false;
+	if (Query_AC_Status(Uart5Fd, Addr.AcPlug, &acStatus) == PASS)
+	{
+		if (acStatus.CpStatus != AC_SYS_NONE)
+		{
+			ShmSysConfigAndInfo->SysConfig.AcRatingCurrent = (unsigned short)acStatus.MaxCurrent;
+
+			//if(ShmSysConfigAndInfo->SysConfig.AcMaxChargingCurrent == 0)
+			//ShmSysConfigAndInfo->SysConfig.AcMaxChargingCurrent = ShmSysConfigAndInfo->SysConfig.AcRatingCurrent;
+			AcChargingRatingCurrent = ShmSysConfigAndInfo->SysConfig.AcRatingCurrent;
+
+			ac_chargingInfo[0]->ConnectorPlugIn = acStatus.CpStatus;
+			ShmSysConfigAndInfo->SysInfo.AcChargingData[0].PilotState = acStatus.CpStatus;
+			isPass = true;
+		}
+
+//		if (acStatus.CpStatus == AC_SYS_F)
+//		{
+//			printf("PilotVol_P = %d \n", acStatus.PilotVol_P);
+//			printf("PilotVol_N = %d \n", acStatus.PilotVol_N);
+//		}
+//		PRINTF_FUNC("CpStatus = %d \n", acStatus.CpStatus);
+//					printf("CurLimit = %d \n", acStatus.CurLimit);
+//					printf("PilotVol_P = %d \n", acStatus.PilotVol_P);
+//					printf("PilotVol_N = %d \n", acStatus.PilotVol_N);
+//					printf("LockStatus = %d \n", acStatus.LockStatus);
+//					printf("RelayStatus = %d \n", acStatus.RelayStatus);
+//					printf("ShutterStatus = %d \n", acStatus.ShutterStatus);
+//					printf("MeterStatus = %d \n", acStatus.MeterStatus);
+//					printf("PpStatus = %d \n", acStatus.PpStatus);
+//					printf("MaxCurrent = %d \n", acStatus.MaxCurrent);
+//					printf("RotateSwitchStatus = %d \n", acStatus.RelayStatus);
+//					printf("============================== \n");
+
+					//ac_chargingInfo[0]->SystemStatus = acStatus.CpStatus;
+	}
+//	else
+//		PRINTF_FUNC("GetAcStatus return fail. \n");
+	return isPass;
+}
+
+void GetAcAlarmCode()
+{
+	if (Query_AC_Alarm_Code(Uart5Fd, Addr.AcPlug, &acAlarmCode) == PASS)
+	{
+		ocpp_ac_clear_errorCode_cmd(CheckAlarmOccur());
+	}
+}
+
+unsigned char GetChargingEnergy()
+{
+	return Query_Charging_Energy(Uart5Fd, Addr.AcPlug, &acChargingEnergy);
+}
+
+unsigned char GetAcChargingVoltage()
+{
+	return Query_Present_InputVoltage(Uart5Fd, Addr.AcPlug, &acChargingVoltage);
+}
+
+unsigned char GetAcChargingCurrent()
+{
+	return Query_Charging_Current(Uart5Fd, Addr.AcPlug, &acChargingCurrent);
+}
+
+void ChangeLedStatus()
+{
+	if (ac_chargingInfo[0]->SystemStatus == SYS_MODE_IDLE)
+		ledStatus.ActionMode = 1;
+	else if (ac_chargingInfo[0]->SystemStatus == SYS_MODE_PREPARING)
+		ledStatus.ActionMode = 3;
+	else if (ac_chargingInfo[0]->SystemStatus == SYS_MODE_CHARGING)
+		ledStatus.ActionMode = 4;
+
+	Config_LED_Status(Uart5Fd, Addr.AcPlug, &ledStatus);
+}
+
+void SetLegacyReq(byte _switch)
+{
+	if (Config_Legacy_Req(Uart5Fd, Addr.AcPlug, _switch))
+	{
+		PRINTF_FUNC("SetLegacyReq Pass. \n");
+	}
+	else
+	{
+		PRINTF_FUNC("SetLegacyReq Fail. \n");
+	}
+}
+
+void SetCpDuty(byte _value)
+{
+	if (_ac_duty != _value)
+	{
+		_ac_duty = _value;
+		PRINTF_FUNC("********Duty : %d \n", _ac_duty);
+	}
+
+	Config_Ac_Duty(Uart5Fd, Addr.AcPlug, _value);
+}
+
+void SetModelName_AC()
+{
+	if (Config_Model_Name(Uart5Fd, Addr.AcPlug, ShmSysConfigAndInfo->SysConfig.ModelName) == PASS)
+	{
+		PRINTF_FUNC("Set Model name (AC) PASS = %s \n", ShmSysConfigAndInfo->SysConfig.ModelName);
+	}
+}
+
+void ChangeToCsuMode()
+{
+	ac_chargingInfo[0]->IsModeChagned = Config_CSU_Mode(Uart5Fd, Addr.AcPlug);
+
+//	if (ac_chargingInfo[0]->IsModeChagned == PASS)
+//	{
+//		Config_Reset_MCU(Uart5Fd, Addr.AcPlug);
+//	}
+}
+
+void ChangeStartOrStopDateTime(byte isStart)
+{
+	char cmdBuf[32];
+	struct timeb csuTime;
+	struct tm *tmCSU;
+
+	ftime(&csuTime);
+	tmCSU = localtime(&csuTime.time);
+
+	sprintf(cmdBuf, "%04d-%02d-%02d %02d:%02d:%02d", tmCSU->tm_year + 1900,
+			tmCSU->tm_mon + 1, tmCSU->tm_mday, tmCSU->tm_hour, tmCSU->tm_min,
+			tmCSU->tm_sec);
+	if (isStart)
+		strcpy((char *)ac_chargingInfo[0]->StartDateTime, cmdBuf);
+	else
+		strcpy((char *)ac_chargingInfo[0]->StopDateTime, cmdBuf);
+}
+
+unsigned char isModeChange()
+{
+	unsigned char result = NO;
+
+	if(ac_chargingInfo[0]->SystemStatus != ac_chargingInfo[0]->PreviousSystemStatus)
+	{
+		result = YES;
+		ac_chargingInfo[0]->PreviousSystemStatus = ac_chargingInfo[0]->SystemStatus;
+	}
+
+	return result;
+}
+
+void SetAcModuleRelay(byte value)
+{
+	acOutputRelay.relay_event.bits.AC_L1_Relay = value;
+	acOutputRelay.relay_event.bits.AC_L2_Relay = value;
+	acOutputRelay.relay_event.bits.AC_L3_Relay = value;
+
+	Config_Relay_Output(Uart5Fd, Addr.AcPlug, &acOutputRelay);
+}
+
+//===============================================
+// AC OCPP routine
+//===============================================
+
+void ocpp_ac_startTransation_cmd()
+{
+	byte hasDc = ((ShmSysConfigAndInfo->SysConfig.TotalConnectorCount > 0) ? 1 : 0);
+
+	if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
+	{
+		if(strcmp((char *)ac_chargingInfo[0]->StartUserId, "") == EQUAL)
+			strcpy((char *)ac_chargingInfo[0]->StartUserId, (char *)ShmOCPP16Data->StartTransaction[hasDc].IdTag);
+		else
+			strcpy((char *)ShmOCPP16Data->StartTransaction[hasDc].IdTag, (char *)ac_chargingInfo[0]->StartUserId);
+
+		PRINTF_FUNC("AC IdTag = %s \n", ShmOCPP16Data->StartTransaction[hasDc].IdTag);
+		ShmOCPP16Data->CpMsg.bits[hasDc].StartTransactionReq = YES;
+	}
+	else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
+	{
+		if(strcmp((char *)ac_chargingInfo[0]->StartUserId, "") == EQUAL)
+			strcpy((char *)ShmOCPP20Data->TransactionEvent[hasDc].idToken.idToken, (char *)ShmOCPP20Data->TransactionEvent[hasDc].idToken.idToken);
+		else
+			strcpy((char *)ShmOCPP20Data->TransactionEvent[hasDc].idToken.idToken, (char *)ac_chargingInfo[0]->StartUserId);
+
+		PRINTF_FUNC("AC IdTag = %s \n", ShmOCPP20Data->TransactionEvent[hasDc].idToken.idToken);
+		ShmOCPP20Data->CpMsg.bits[hasDc].TransactionEventReq = YES;
+	}
+}
+
+void ocpp_ac_stopTransation_cmd()
+{
+	byte hasDc = ((ShmSysConfigAndInfo->SysConfig.TotalConnectorCount > 0) ? 1 : 0);
+
+	if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
+	{
+		if(strcmp((char *)ac_chargingInfo[0]->StartUserId, "") == EQUAL)
+			strcpy((char *)ShmOCPP16Data->StopTransaction[hasDc].IdTag, (char *)ShmOCPP16Data->StopTransaction[hasDc].IdTag);
+		else
+			strcpy((char *)ShmOCPP16Data->StopTransaction[hasDc].IdTag, (char *)ac_chargingInfo[0]->StartUserId);
+
+		PRINTF_FUNC("AC IdTag = %s \n", ShmOCPP16Data->StopTransaction[hasDc].IdTag);
+		ShmOCPP16Data->CpMsg.bits[hasDc].StopTransactionReq = YES;
+	}
+	else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
+	{
+		if(strcmp((char *)ac_chargingInfo[0]->StartUserId, "") == EQUAL)
+			strcpy((char *)ShmOCPP20Data->TransactionEvent[hasDc].idToken.idToken, (char *)ShmOCPP20Data->TransactionEvent[hasDc].idToken.idToken);
+		else
+			strcpy((char *)ShmOCPP20Data->TransactionEvent[hasDc].idToken.idToken, (char *)ac_chargingInfo[0]->StartUserId);
+
+		PRINTF_FUNC("AC IdTag = %s \n", ShmOCPP20Data->TransactionEvent[hasDc].idToken.idToken);
+		ShmOCPP20Data->CpMsg.bits[hasDc].TransactionEventReq = YES;
+	}
+}
+
+bool ocpp_ac_remoteStopReq_cmd()
+{
+	byte hasDc = ((ShmSysConfigAndInfo->SysConfig.TotalConnectorCount > 0) ? 1 : 0);
+	bool result = false;
+
+	if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
+	{
+		result = ShmOCPP16Data->CsMsg.bits[hasDc].RemoteStopTransactionReq;
+
+		if (ShmOCPP16Data->CsMsg.bits[hasDc].RemoteStopTransactionReq == YES)
+		{
+			strcpy((char *)ShmOCPP16Data->StopTransaction[hasDc].StopReason, "Remote");
+			ShmOCPP16Data->CsMsg.bits[hasDc].RemoteStopTransactionReq = NO;
+		}
+	}
+	else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
+	{
+		result = ShmOCPP20Data->CsMsg.bits[hasDc].RequestStopTransactionReq;
+
+		if (ShmOCPP20Data->CsMsg.bits[hasDc].RequestStopTransactionReq == YES)
+		{
+			strcpy((char *)ShmOCPP20Data->TransactionEvent[hasDc].transactionInfo.stoppedReason, "Remote");
+			ShmOCPP20Data->CsMsg.bits[hasDc].RequestStopTransactionReq = NO;
+		}
+	}
+	return result;
+}
+
+bool ocpp_ac_is_resPass_StartTransationConf()
+{
+	bool result = false;
+	byte hasDc = ((ShmSysConfigAndInfo->SysConfig.TotalConnectorCount > 0) ? 1 : 0);
+
+	if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
+	{
+		result = ShmOCPP16Data->CpMsg.bits[hasDc].StartTransactionConf;
+	}
+	else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
+	{
+		result = ShmOCPP20Data->CpMsg.bits[hasDc].TransactionEventConf;
+	}
+
+	return result;
+}
+
+bool ocpp_ac_chk_invalid_id_cmd()
+{
+	byte hasDc = ((ShmSysConfigAndInfo->SysConfig.TotalConnectorCount > 0) ? 1 : 0);
+
+	if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
+	{
+		if (strstr((char *) ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "TRUE"))
+		{
+			if (strcmp((char *)ShmOCPP16Data->StartTransaction[hasDc].ResponseIdTagInfo.Status, "Blocked") == EQUAL ||
+					strcmp((char *)ShmOCPP16Data->StartTransaction[hasDc].ResponseIdTagInfo.Status, "Expired") == EQUAL ||
+					strcmp((char *)ShmOCPP16Data->StartTransaction[hasDc].ResponseIdTagInfo.Status, "Invalid") == EQUAL)
+				return true;
+		}
+	}
+	else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
+	{
+		if (strstr((char *) ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnInvalidId].variableAttribute[0].value, "TRUE"))
+		{
+			if (strcmp((char *)ShmOCPP20Data->TransactionEvent[hasDc].Response_idTokenInfo.status, "Blocked") == EQUAL ||
+					strcmp((char *)ShmOCPP20Data->TransactionEvent[hasDc].Response_idTokenInfo.status, "Expired") == EQUAL ||
+					strcmp((char *)ShmOCPP20Data->TransactionEvent[hasDc].Response_idTokenInfo.status, "Invalid") == EQUAL ||
+					strcmp((char *)ShmOCPP20Data->TransactionEvent[hasDc].Response_idTokenInfo.status, "NoCredit") == EQUAL ||
+					strcmp((char *)ShmOCPP20Data->TransactionEvent[hasDc].Response_idTokenInfo.status, "NotAllowedTypeEVSE") == EQUAL ||
+					strcmp((char *)ShmOCPP20Data->TransactionEvent[hasDc].Response_idTokenInfo.status, "NotAtThisLocation") == EQUAL ||
+					strcmp((char *)ShmOCPP20Data->TransactionEvent[hasDc].Response_idTokenInfo.status, "NotAtThisTime") == EQUAL ||
+					strcmp((char *)ShmOCPP20Data->TransactionEvent[hasDc].Response_idTokenInfo.status, "Unknown") == EQUAL)
+				return true;
+		}
+	}
+
+	return false;
+}
+
+bool ocpp_ac_get_startTransation_req()
+{
+	bool result = false;
+	byte hasDc = ((ShmSysConfigAndInfo->SysConfig.TotalConnectorCount > 0) ? 1 : 0);
+
+	// 如果有 AC 槍,而現在是 DC 第二把槍進入充電
+	if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
+	{
+		result = ShmOCPP16Data->CpMsg.bits[hasDc].StartTransactionReq;
+	}
+	else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
+	{
+		result = ShmOCPP20Data->CpMsg.bits[hasDc].TransactionEventReq;
+	}
+
+	return result;
+}
+
+void ocpp_ac_set_stopReason_by_cmd(char *reason)
+{
+	byte hasDc = ((ShmSysConfigAndInfo->SysConfig.TotalConnectorCount > 0) ? 1 : 0);
+
+	if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
+	{
+		if (strcmp((char *)ShmOCPP16Data->StopTransaction[hasDc].StopReason, "") == EQUAL)
+		{
+			strcpy((char *)ShmOCPP16Data->StopTransaction[hasDc].StopReason, reason);
+		}
+	}
+	else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
+	{
+		if (strcmp((char *)ShmOCPP20Data->TransactionEvent[hasDc].transactionInfo.stoppedReason, "") == EQUAL)
+		{
+			strcpy((char *)ShmOCPP20Data->TransactionEvent[hasDc].transactionInfo.stoppedReason, reason);
+		}
+	}
+}
+
+void ocpp_ac_auto_response_StartTransationConf()
+{
+	byte hasDc = ((ShmSysConfigAndInfo->SysConfig.TotalConnectorCount > 0) ? 1 : 0);
+
+	if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
+	{
+		if (ShmOCPP16Data->CpMsg.bits[hasDc].StartTransactionConf)
+			ShmOCPP16Data->CpMsg.bits[hasDc].StartTransactionConf = NO;
+	}
+	else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
+	{
+		if (ShmOCPP20Data->CpMsg.bits[hasDc].TransactionEventConf)
+			ShmOCPP20Data->CpMsg.bits[hasDc].TransactionEventConf = NO;
+	}
+}
+
+void ocpp_ac_set_errCode_cmd()
+{
+	byte hasDc = ((ShmSysConfigAndInfo->SysConfig.TotalConnectorCount > 0) ? 1 : 0);
+
+	if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
+	{
+		strcpy((char *)ShmOCPP16Data->StatusNotification[hasDc].ErrorCode, "InternalError");
+		strcpy((char *)ShmOCPP16Data->StatusNotification[hasDc].VendorErrorCode, (char *)ac_chargingInfo[0]->ConnectorAlarmCode);
+	}
+	else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
+	{
+
+	}
+}
+
+void ocpp_ac_clear_errorCode_cmd(bool isError)
+{
+	byte hasDc = ((ShmSysConfigAndInfo->SysConfig.TotalConnectorCount > 0) ? 1 : 0);
+
+	if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
+	{
+		if (strcmp((char *)ShmOCPP16Data->StatusNotification[hasDc].ErrorCode, "NoError") != EQUAL)
+			strcpy((char *)ShmOCPP16Data->StatusNotification[hasDc].ErrorCode, "NoError");
+
+		if (strcmp((char *)ShmOCPP16Data->StatusNotification[hasDc].VendorErrorCode, "") != EQUAL)
+			strcpy((char *)ShmOCPP16Data->StatusNotification[hasDc].VendorErrorCode, "");
+	}
+	else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
+	{
+
+	}
+}
+
+void ocpp_ac_clear_stopReason()
+{
+	byte hasDc = ((ShmSysConfigAndInfo->SysConfig.TotalConnectorCount > 0) ? 1 : 0);
+
+	if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
+		strcpy((char *)ShmOCPP16Data->StopTransaction[hasDc].StopReason, "");
+	else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
+		strcpy((char *)ShmOCPP20Data->TransactionEvent[hasDc].transactionInfo.stoppedReason, "");
+}
+
+//===============================================
+// AC Main Process
+//===============================================
+byte _SystemStatus = 255;
+byte _CpStatus = 255;
+
+byte GetMaxChargingDuty()
+{
+	// 一開始先設定最大電流為硬體最大可支援電流
+	byte result = AcChargingRatingCurrent;
+
+	// ChargingProfileCurrent => charging profile
+	// AcMaxChargingCurrent => 網頁
+	// AcChargingRatingCurrent => 硬體限制最大可輸出電流
+	if (ShmSysConfigAndInfo->SysConfig.AcMaxChargingCurrent > 0)
+	{
+		if (ShmSysConfigAndInfo->SysConfig.AcMaxChargingCurrent <= result)
+			result = ShmSysConfigAndInfo->SysConfig.AcMaxChargingCurrent;
+	}
+
+	if (ac_chargingInfo[0]->ChargingProfileCurrent > 0)
+	{
+		if (ac_chargingInfo[0]->ChargingProfileCurrent <= result)
+			result = ac_chargingInfo[0]->ChargingProfileCurrent;
+	}
+
+	if (result >= 1 && result <= 5)
+		result = AC_MINIMUM_DUTY;
+	else if (result == 0)
+		result = AC_STOP_DUTY;
+
+	return result;
+}
+
+void AcChargeTypeProcess()
+{
+	if (acgunCount > 0)
+	{
+		//ac_chargingInfo[0]->SelfTest_Comp = YES;
+		//ac_chargingInfo[0]->IsModeChagned = PASS;
+		//---------------------------------------------
+		if (ac_chargingInfo[0]->SelfTest_Comp == NO)
+		{
+			ac_chargingInfo[0]->IsModeChagned = NO;
+			SetModelName_AC();
+			GetFwVersion_AC();
+			GetAcModelName();
+		}
+		else if (ac_chargingInfo[0]->SelfTest_Comp == YES)
+		{
+			if (isAcModuleInitComp == NO)
+			{
+				isAcModuleInitComp = YES;
+				ac_chargingInfo[0]->SystemStatus = SYS_MODE_IDLE;
+			}
+
+			GetAcAlarmCode();
+
+			if (GetAcStatus())
+			{
+				byte _status = SYS_MODE_BOOTING;
+
+				if (ac_chargingInfo[0]->IsAvailable == NO)
+				{
+					_status = SYS_MODE_MAINTAIN;
+				}
+
+				//printf("SystemStatus = %d, err = %d \n", ac_chargingInfo[0]->SystemStatus, ac_chargingInfo[0]->IsErrorOccur);
+				if ((ac_chargingInfo[0]->SystemStatus == SYS_MODE_IDLE || ac_chargingInfo[0]->SystemStatus == SYS_MODE_MAINTAIN) &&
+						ac_chargingInfo[0]->IsErrorOccur)
+				{
+					_status = SYS_MODE_FAULT;
+				}
+				else if (ac_chargingInfo[0]->SystemStatus == SYS_MODE_CHARGING &&
+						ac_chargingInfo[0]->IsErrorOccur)
+				{
+					_status = SYS_MODE_ALARM;
+				}
+				else if (_status == SYS_MODE_MAINTAIN)
+				{
+					// do nothing
+				}
+				else if (acStatus.CpStatus == AC_SYS_A)
+				{
+					if (ac_chargingInfo[0]->IsErrorOccur &&
+							(ac_chargingInfo[0]->SystemStatus >= SYS_MODE_PREPARING ||
+							ac_chargingInfo[0]->SystemStatus <= SYS_MODE_CHARGING))
+						_status = SYS_MODE_ALARM;
+					else if (!ac_chargingInfo[0]->IsErrorOccur &&
+							(ac_chargingInfo[0]->SystemStatus >= SYS_MODE_TERMINATING ||
+							ac_chargingInfo[0]->SystemStatus <= SYS_MODE_ALARM))
+					{
+						if (GetTimeoutValue(&_ac_charging_comp) >= 10 && acStatus.CpStatus == AC_SYS_A)
+							_status = SYS_MODE_IDLE;
+					}
+				}
+				else if (ac_chargingInfo[0]->SystemStatus >= SYS_MODE_PREPARING &&
+							ac_chargingInfo[0]->SystemStatus < SYS_MODE_CHARGING)
+				{
+					if (acStatus.CpStatus == AC_SYS_C)
+						_status = SYS_MODE_CHARGING;
+					else if (GetTimeoutValue(&_ac_preparing) >= 120)
+						_status = SYS_MODE_IDLE;
+				}
+				else if ((acStatus.CpStatus == AC_SYS_B || ac_chargingInfo[0]->ConnectorPlugIn == AC_SYS_B) &&
+						ac_chargingInfo[0]->IsAvailable &&
+						!ac_chargingInfo[0]->IsErrorOccur &&
+						ac_chargingInfo[0]->SystemStatus == SYS_MODE_IDLE &&
+						(ShmSysConfigAndInfo->SysInfo.WaitForPlugit == YES ||
+							ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_DISABLE))
+				{
+					if (ac_chargingInfo[0]->RemoteStartFlag == YES)
+					{
+						PRINTF_FUNC("** AC Remote \n");
+						ac_chargingInfo[0]->RemoteStartFlag = NO;
+						ac_chargingInfo[0]->isRemoteStart = YES;
+						strcpy((char *)ac_chargingInfo[0]->StartUserId, "");
+						ShmSysConfigAndInfo->SysInfo.WaitForPlugit = NO;
+						_status = SYS_MODE_PREPARING;
+					}
+					else if (ac_chargingInfo[0]->ReservedStartFlag == YES)
+					{
+						ac_chargingInfo[0]->ReservedStartFlag = NO;
+						strcpy ( (char *) ac_chargingInfo[0]->StartUserId,
+								(char *) ShmDcCommonData->_reserved_ac_UserId [0] );
+						PRINTF_FUNC ( "AC Start Charging : Reserved CardNumber = %s \n", ac_chargingInfo[0]->StartUserId );
+						strcpy ( (char *) ShmSysConfigAndInfo->SysConfig.UserId, "" );
+						strcpy ( (char *) ShmDcCommonData->_reserved_ac_UserId [0], "" );
+						// 當前操作的槍號,進入 Preparing
+						ShmSysConfigAndInfo->SysInfo.WaitForPlugit = NO;
+					}
+					else if (ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_DISABLE)
+					{
+						PRINTF_FUNC ( "Conn AC Start Charging : Plug and charing \n" );
+						byte hasDc = ((ShmSysConfigAndInfo->SysConfig.TotalConnectorCount > 0) ? 1 : 0);
+
+						strncpy ( (char *) ShmOCPP16Data->StartTransaction [hasDc].IdTag,
+								(char *) ShmSysConfigAndInfo->SysConfig.SerialNumber,
+								sizeof(ShmOCPP16Data->StartTransaction [hasDc].IdTag) );
+
+						ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc = DEFAULT_AC_INDEX;
+						_status = SYS_MODE_PREPARING;
+					}
+					else if (ShmSysConfigAndInfo->SysInfo.OrderCharging == NO_DEFINE)
+					{
+						PRINTF_FUNC("** UserId = %s \n", ShmSysConfigAndInfo->SysConfig.UserId);
+						strcpy((char *)ac_chargingInfo[0]->StartUserId, (char *)ShmSysConfigAndInfo->SysConfig.UserId);
+						PRINTF_FUNC("** CardNumber = %s \n", ac_chargingInfo[0]->StartUserId);
+						strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
+						ShmSysConfigAndInfo->SysInfo.WaitForPlugit = NO;
+						_status = SYS_MODE_PREPARING;
+					}
+				}
+
+				if (ac_chargingInfo[0]->SystemStatus == SYS_MODE_PREPARING ||
+						ac_chargingInfo[0]->SystemStatus == SYS_MODE_CHARGING)
+				{
+					if (ocpp_ac_remoteStopReq_cmd())
+					{
+						ocpp_ac_set_stopReason_by_cmd("Remote");
+						_status = SYS_MODE_TERMINATING;
+					}
+					else if (ac_chargingInfo[0]->StopChargeFlag ||
+							acStatus.CpStatus == AC_SYS_F)
+					{
+						_status = SYS_MODE_TERMINATING;
+					}
+				}
+
+				if (_status != SYS_MODE_BOOTING && ac_chargingInfo[0]->SystemStatus != _status)
+				{
+					ac_chargingInfo[0]->SystemStatus = _status;
+
+					if (ac_chargingInfo [0]->SystemStatus != _SystemStatus)
+					{
+						PRINTF_FUNC ( "ac_chargingInfo[0]->SystemStatus = %d \n", ac_chargingInfo [0]->SystemStatus );
+						_SystemStatus = ac_chargingInfo [0]->SystemStatus;
+					}
+				}
+
+				if (acStatus.CpStatus != _CpStatus &&
+						_CpStatus != SYS_MODE_BOOTING)
+				{
+					PRINTF_FUNC("acStatus.CpStatus = %d", acStatus.CpStatus);
+					_CpStatus = acStatus.CpStatus;
+				}
+
+				// 設定限制最大充電電流 >= 6 ~ <= 32
+				switch(ac_chargingInfo[0]->SystemStatus)
+				{
+					case SYS_MODE_IDLE:
+					case SYS_MODE_MAINTAIN:
+					case SYS_MODE_RESERVATION:
+					case SYS_MODE_FAULT:
+					{
+						if (isModeChange())
+						{
+							if (ac_chargingInfo[0]->SystemStatus == SYS_MODE_IDLE)
+							{
+								PRINTF_FUNC("================== SYS_MODE_IDLE (AC Gun) ================ \n");
+								ac_chargingInfo [0]->ReservationId = -1;
+							}
+							else if (ac_chargingInfo[0]->SystemStatus == SYS_MODE_MAINTAIN)
+								PRINTF_FUNC("================== SYS_MODE_MAINTAIN (AC Gun) ================ \n");
+							else if (ac_chargingInfo[0]->SystemStatus == SYS_MODE_RESERVATION)
+							{
+								PRINTF_FUNC("================== SYS_MODE_RESERVATION (AC Gun) ================ \n");
+								PRINTF_FUNC("================= Id : %s ================  \n", ShmDcCommonData->_reserved_ac_UserId[0]);
+							}
+							else if (ac_chargingInfo[0]->SystemStatus == SYS_MODE_FAULT)
+								PRINTF_FUNC("================== SYS_MODE_FAULT (AC Gun) ================ \n");
+
+							SetCpDuty(100);
+
+							ac_chargingInfo [0]->PresentChargedDuration = 0;
+							ac_chargingInfo [0]->RemainChargingDuration = 0;
+							ac_chargingInfo [0]->PresentChargingCurrent = 0;
+							ac_chargingInfo[0]->PresentChargedEnergy = 0.0;
+							ac_chargingInfo[0]->PresentChargingVoltage = 0;
+							ac_chargingInfo[0]->ChargingFee = 0.0;
+							ac_chargingInfo[0]->isRemoteStart = NO;
+							strcpy((char *)ac_chargingInfo[0]->StartDateTime, "");
+							strcpy((char *)ac_chargingInfo[0]->StopDateTime, "");
+							strcpy ( (char *) ac_chargingInfo [0]->StartUserId, "" );
+							_beforeChargingTotalEnergy = 0.0;
+							ocpp_ac_clear_stopReason();
+							ocpp_ac_auto_response_StartTransationConf();
+							ac_startTransationFlag = START_TRANSATION_STATUS_WAIT;
+						}
+
+						ac_chargingInfo[0]->ChargingProfilePower = -1;
+						ac_chargingInfo[0]->ChargingProfileCurrent = -1;
+
+						ac_chargingInfo[0]->StopChargeFlag = NO;
+						ChangeLedStatus();
+					}
+						break;
+					case SYS_MODE_PREPARING:
+					{
+						if (isModeChange())
+						{
+							PRINTF_FUNC("================== SYS_MODE_PREPARING (AC Gun) ================ \n");
+
+							SetLegacyReq(YES);
+							ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
+							ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc = DEFAULT_AC_INDEX;
+							if (ShmSysConfigAndInfo->SysInfo.OrderCharging != NO_DEFINE)
+								ShmSysConfigAndInfo->SysInfo.OrderCharging = NO_DEFINE;
+
+							ocpp_ac_startTransation_cmd();
+							GetTimespecFunc(&_ac_preparing);
+						}
+
+						if (GetChargingEnergy() == PASS)
+						{
+							//ac_chargingInfo[0]->PresentChargedEnergy = acChargingEnergy.Energy / 100;
+							_beforeChargingTotalEnergy = ((float)acChargingEnergy.Energy) / 10000;
+						}
+
+						ac_startTransationFlag = ocpp_ac_is_resPass_StartTransationConf();
+
+						if (ac_startTransationFlag == START_TRANSATION_STATUS_PASS)
+						{
+							if (ocpp_ac_chk_invalid_id_cmd())
+								ac_startTransationFlag = START_TRANSATION_STATUS_FAIL;
+						}
+						else
+						{
+							if (ShmSysConfigAndInfo->SysInfo.OcppConnStatus == NO)
+							{
+								if (ShmSysConfigAndInfo->SysConfig.OfflinePolicy == _OFFLINE_POLICY_FREE_CHARGING ||
+										ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_DISABLE ||
+										!ocpp_ac_get_startTransation_req() ||
+										strcmp((char *)ac_chargingInfo[0]->StartUserId, "") != EQUAL)
+								{
+									ac_startTransationFlag = START_TRANSATION_STATUS_PASS;
+								}
+							}
+						}
+
+						if (ac_startTransationFlag == START_TRANSATION_STATUS_PASS)
+						{
+							// 充電前須給 duty : 依照 Charging profile
+							SetCpDuty(GetMaxChargingDuty());
+						}
+						else if (ac_startTransationFlag == START_TRANSATION_STATUS_FAIL ||
+								(ac_startTransationFlag == START_TRANSATION_STATUS_WAIT && GetTimeoutValue(&_ac_preparing) > 10))
+						{
+							PRINTF_FUNC("StartTransaction Fail / Timeout. \n");
+							ac_chargingInfo[0]->StopChargeFlag = YES;
+						}
+						ChangeLedStatus();
+					}
+						break;
+					case SYS_MODE_CHARGING:
+					{
+						if (isModeChange())
+						{
+							PRINTF_FUNC("================== SYS_MODE_CHARGING (AC Gun) ================ \n");
+							ftime(&_ac_startChargingTime);
+							ChangeStartOrStopDateTime(YES);
+							ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc = DEFAULT_AC_INDEX;
+						}
+						// 用以判斷是否有在輸出
+						ac_chargingInfo[0]->IsCharging = acStatus.RelayStatus;
+
+						ftime(&_ac_endChargingTime);
+						ac_chargingInfo[0]->PresentChargedDuration = DiffTimeb(_ac_startChargingTime, _ac_endChargingTime);
+
+						if (ac_chargingInfo[0]->IsCharging)
+						{
+							if (GetChargingEnergy() == PASS)
+							{
+								if ((acChargingEnergy.Energy - _beforeChargingTotalEnergy) > 0)
+								{
+									// 小數點取兩位
+									ac_chargingInfo[0]->PresentChargedEnergy += (((float)acChargingEnergy.Energy) / 10000 - _beforeChargingTotalEnergy);
+									if (ShmSysConfigAndInfo->SysConfig.BillingData.isBilling)
+									{
+										ac_chargingInfo[0]->ChargingFee += ac_chargingInfo[0]->PresentChargedEnergy * ShmSysConfigAndInfo->SysConfig.BillingData.Cur_fee;
+									}
+								}
+
+								_beforeChargingTotalEnergy = ((float)acChargingEnergy.Energy) / 10000;
+							}
+
+							//GetAcChargingPower();
+							GetAcChargingVoltage();
+							GetAcChargingCurrent();
+
+							{
+	//							PRINTF_FUNC("L1N_L12 = %f, L1N_L12 = %f, L1N_L12 = %f \n",
+	//									acChargingVoltage.L1N_L12,
+	//									acChargingVoltage.L2N_L23,
+	//									acChargingVoltage.L3N_L31);
+	//							PRINTF_FUNC("c1 = %d, c2 = %d, c3 = %d \n",
+	//									acChargingCurrent.OuputCurrentL1,
+	//									acChargingCurrent.OuputCurrentL2,
+	//									acChargingCurrent.OuputCurrentL3);
+
+								// 即時輸出功率
+								ac_chargingInfo[0]->PresentChargingPower =
+										(float)(acChargingVoltage.L1N_L12 * acChargingCurrent.OuputCurrentL1 +
+										acChargingVoltage.L2N_L23 * acChargingCurrent.OuputCurrentL2 +
+										acChargingVoltage.L3N_L31 * acChargingCurrent.OuputCurrentL3) / 1000;
+							}
+							// 累積輸出功率
+							//ac_chargingInfo[0]->PresentChargedEnergy
+							ac_chargingInfo[0]->PresentChargingVoltage = (float)acChargingVoltage.L1N_L12;
+							ac_chargingInfo[0]->PresentChargingCurrent = (float)(acChargingCurrent.OuputCurrentL1 + acChargingCurrent.OuputCurrentL2 + acChargingCurrent.OuputCurrentL3);
+
+							// 充電中須給 duty : 依照 Charging profile
+							SetCpDuty(GetMaxChargingDuty());
+						}
+						else
+						{
+							// 搭上 relay
+							if (acStatus.CpStatus == AC_SYS_C &&
+									!ac_chargingInfo[0]->IsErrorOccur)
+							{
+								PRINTF_FUNC("Set relay ON (AC Type). \n");
+								SetAcModuleRelay(YES);
+							}
+						}
+
+						ChangeLedStatus();
+					}
+						break;
+					case SYS_MODE_TERMINATING:
+					case SYS_MODE_ALARM:
+					{
+						//ocpp_set_errCode_cmd
+						if (isModeChange())
+						{
+							if (ac_chargingInfo[0]->SystemStatus == SYS_MODE_TERMINATING)
+								PRINTF_FUNC("================== SYS_MODE_TERMINATING (AC Gun) ================ \n");
+							else if (ac_chargingInfo[0]->SystemStatus == SYS_MODE_ALARM)
+								PRINTF_FUNC("================== SYS_MODE_ALARM (AC Gun) ================ \n");
+
+							ChangeStartOrStopDateTime(NO);
+							GetTimespecFunc(&_ac_charging_comp);
+							ocpp_ac_set_stopReason_by_cmd("Local");
+							SetCpDuty(100);
+
+							if (ac_chargingInfo[0]->SystemStatus == SYS_MODE_TERMINATING)
+								PRINTF_FUNC("================== SYS_MODE_TERMINATING (AC Gun) ================ \n");
+							else if (ac_chargingInfo[0]->SystemStatus == SYS_MODE_ALARM)
+							{
+								ftime(&_ac_endChargingTime);
+
+								ocpp_ac_set_errCode_cmd();
+								if (strcmp((char *)ac_chargingInfo[0]->StartDateTime, "") != EQUAL)
+								{
+									ocpp_ac_auto_response_StartTransationConf();
+									// AC 固定為第2把槍
+									ocpp_ac_stopTransation_cmd();
+								}
+							}
+						}
+
+						SetLegacyReq(NO);
+						if (acStatus.RelayStatus == NO)
+						{
+							if (ac_chargingInfo[0]->SystemStatus == SYS_MODE_TERMINATING)
+								ac_chargingInfo[0]->SystemStatus = SYS_MODE_COMPLETE;
+						}
+						else
+						{
+							// 搭上 relay
+							PRINTF_FUNC("Set relay OFF (AC Type). \n");
+							SetAcModuleRelay(NO);
+						}
+
+						if (ac_chargingInfo[0]->SystemStatus == SYS_MODE_ALARM)
+							ac_chargingInfo[0]->PresentChargedDuration = DiffTimeb(_ac_startChargingTime, _ac_endChargingTime);
+					}
+						break;
+					case SYS_MODE_COMPLETE:
+					{
+						if (isModeChange())
+						{
+							PRINTF_FUNC("================== SYS_MODE_COMPLETE (AC Gun) ================ \n");
+
+							GetTimespecFunc(&_ac_charging_comp);
+							ftime(&_ac_endChargingTime);
+							ocpp_ac_set_errCode_cmd();
+							if (strcmp((char *)ac_chargingInfo[0]->StartDateTime, "") != EQUAL)
+							{
+								ocpp_ac_auto_response_StartTransationConf();
+								// AC 固定為第2把槍
+								ocpp_ac_stopTransation_cmd();
+							}
+
+							ChangeStartOrStopDateTime(NO);
+							ac_chargingInfo[0]->PresentChargedDuration = DiffTimeb(_ac_startChargingTime, _ac_endChargingTime);
+						}
+					}
+						break;
+				}
+			}
+		}
+	}
+}
+
+void RunForceStopProcess()
+{
+	if (isCriticalStop == NO)
+	{
+		isCriticalStop = YES;
+		GetTimespecFunc(&_psuCriticalStop);
+	}
+	else
+	{
+		int _timebuf = GetTimeoutValue(&_psuCriticalStop);
+
+		if (_timebuf < 0)
+			GetTimespecFunc(&_psuCriticalStop);
+		else
+		{
+			if (_timebuf >= FORCE_STOP_TIME)
+			{
+				isCriticalStop = NO;
+				ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuFailureAlarm = NORMAL;
+				ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuComminicationErrWithCSU = NORMAL;
+				system("/usr/bin/run_evse_restart.sh");
+			}
+		}
+	}
+}
+
+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;
+	}
+
+	gunCount = ShmSysConfigAndInfo->SysConfig.TotalConnectorCount;
+	acgunCount = ShmSysConfigAndInfo->SysConfig.AcConnectorCount;
+	// Open Uart5 for RB
+	Uart5Fd = InitComPort();
+	Initialization();
+	sleep(1);
+
+	if(Uart5Fd < 0)
+	{
+		PRINTF_FUNC("(Internal) open port error. \n");
+		return 0;
+	}
+
+	if (acgunCount > 0)
+	{
+		acOutputRelay.relay_event.bits.AC_L1_Relay = 0x00;
+		acOutputRelay.relay_event.bits.AC_L2_Relay = 0x00;
+		acOutputRelay.relay_event.bits.AC_L3_Relay = 0x00;
+		Config_Relay_Output(Uart5Fd, Addr.AcPlug, &acOutputRelay);
+	}
+
+	outputRelay.relay_event.bits.AC_Contactor = 0x00;
+	outputRelay.relay_event.bits.CCS_Precharge = 0x00;
+	outputRelay.relay_event.bits.Gun1_Parallel_P = 0x00;
+	outputRelay.relay_event.bits.Gun1_Parallel_N = 0x00;
+	outputRelay.relay_event.bits.Gun1_P = 0x00;
+	outputRelay.relay_event.bits.Gun1_N = 0x00;
+	outputRelay.relay_event.bits.Gun2_N = 0x00;
+	outputRelay.relay_event.bits.Gun2_P = 0x00;
+	if(Config_Relay_Output(Uart5Fd, Addr.Relay, &outputRelay) != PASS)
+		PRINTF_FUNC("Config_Relay_Output fail \n");
+
+	cur_led_color.Connect_1_Red = COLOR_MIN_LV;
+	cur_led_color.Connect_1_Green = COLOR_MIN_LV;
+	cur_led_color.Connect_1_Blue = COLOR_MIN_LV;
+	cur_led_color.Connect_2_Red = COLOR_MIN_LV;
+	cur_led_color.Connect_2_Green = COLOR_MIN_LV;
+	cur_led_color.Connect_2_Blue = COLOR_MIN_LV;
+
+	relayMatchFlag = NO;
+	isCriticalStop = NO;
+	GetTimespecFunc(&_led_blink_time);
+
+	for(;;)
+	{
+		bool isCharging = false;
+		// 程序開始之前~ 必須先確定 FW 版本與硬體版本,確認後!!~ 該模組才算是真正的 Initial Comp.
+		if (ShmRelayModuleData->SelfTest_Comp == NO)
+		{
+			GetFwAndHwVersion_Relay();
+			SetModelName_Relay();
+			SetRtcData_Relay();
+			sleep(1);
+		}
+
+		if (ShmFanModuleData->SelfTest_Comp == NO)
+		{
+			GetFwAndHwVersion_Fan();
+			SetModelName_Fan();
+			SetRtcData_Fan();
+			sleep(1);
+			GetTimespecFunc(&_priority_time);
+		}
+
+		// 自檢階段處理,自檢階段如果讀不到版號則代表該系統沒有掛燈板
+		if (ShmLedModuleData->SelfTest_Comp == NO)
+		{
+			// 自檢階段
+			if (ShmSysConfigAndInfo->SysInfo.SelfTestSeq <= _STEST_PSU_CAP)
+			{
+				GetFwAndHwVersion_Led();
+				sleep(1);
+				GetTimespecFunc(&_led_priority_time);
+			}
+			else
+			{
+				// 自檢階段沒有問到版號
+				if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.LedboardStestFail == NO)
+					ShmStatusCodeData->AlarmCode.AlarmEvents.bits.LedboardStestFail = YES;
+			}
+		}
+
+		AcChargeTypeProcess();
+
+		if (ShmRelayModuleData->SelfTest_Comp == YES)
+		{
+			// ==============優先權最高 10 ms ==============
+			// 輸出電壓
+			GetPersentOutputVol();
+
+			// 三相輸入電壓
+			GetPresentInputVol();
+
+			// 讀取當前 AC relay 狀態
+			regRelay.relay_event.bits.AC_Contactor = ShmSysConfigAndInfo->SysInfo.AcContactorStatus;
+			GetRelayOutputStatus();
+
+			for (int i = 0; i < gunCount; i++)
+			{
+				// Cable check (Set)
+				CableCheckDetected(i);
+
+				// check k1 k2 relay 狀態
+				CheckK1K2RelayOutput(i);
+
+				// 依據當前各槍的狀態選擇 搭上/放開 Relay
+				SetK1K2RelayStatus(i);
+
+				if (_chargingData[i]->SystemStatus == SYS_MODE_IDLE ||
+						_chargingData[i]->SystemStatus == SYS_MODE_RESERVATION ||
+						_chargingData[i]->SystemStatus == SYS_MODE_MAINTAIN)
+				{
+					_isOvpChkTimeFlag[i] = NO;
+				}
+
+				if (_chargingData[i]->SystemStatus == SYS_MODE_BOOTING	||
+					(_chargingData[i]->SystemStatus >= SYS_MODE_MODE_REASSIGN_CHECK && _chargingData[i]->SystemStatus <= SYS_MODE_ALARM) ||
+					(_chargingData[i]->SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0 && _chargingData[i]->SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) ||
+					ShmSysConfigAndInfo->SysInfo.WaitForPlugit == YES ||
+					(ShmSysConfigAndInfo->SysInfo.PageIndex >= _LCM_AUTHORIZING && ShmSysConfigAndInfo->SysInfo.PageIndex <= _LCM_WAIT_FOR_PLUG))
+				{
+					_chargingData[i]->IsReadyToCharging = YES;
+					isCharging = true;
+
+					if (_chargingData[i]->SystemStatus == SYS_MODE_CHARGING)
+					{
+						// OVP
+						CheckOutputPowerOverCarReq(i);
+					}
+					else if (_chargingData[i]->SystemStatus == SYS_MODE_PREPARE_FOR_EVSE)
+					{
+						// abnormal voltage at the stage of GFD
+						CheckOutputVolNoneMatchFire(i);
+					}
+					else
+						_isOutputNoneMatch[i] = NO;
+				}
+				else
+					_chargingData[i]->IsReadyToCharging = NO;
+			}
+			// Cable check (Get)
+			GetGfdAdc();
+
+			// 橋接 relay
+			SetParalleRelayStatus();
+
+			// 搭上 AC Contactor
+//			if (isCharging)
+//				outputRelay.relay_event.bits.AC_Contactor = YES;
+//			else
+//				outputRelay.relay_event.bits.AC_Contactor = NO;
+
+			if (isCharging || (ShmPsuData->Work_Step == _TEST_MODE))
+			{
+				isStopChargingCount = false;
+				outputRelay.relay_event.bits.AC_Contactor = YES;
+			}
+			else
+			{
+				if (!isStopChargingCount)
+				{
+					GetTimespecFunc(&_close_ac_contactor);
+					isStopChargingCount = true;
+				}
+				else
+				{
+					if ((outputRelay.relay_event.bits.AC_Contactor == YES && GetTimeoutValue(&_close_ac_contactor) >= TEN_MINUTES))
+					{
+						outputRelay.relay_event.bits.AC_Contactor = NO;
+					}
+				}
+			}
+
+			if (ShmPrimaryMcuData->InputDet.bits.EmergencyButton == ABNORMAL ||
+					ShmPrimaryMcuData->InputDet.bits.DoorOpen == ABNORMAL)
+				outputRelay.relay_event.bits.AC_Contactor = NO;
+
+			if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuFailureAlarm == ABNORMAL ||
+					ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuComminicationErrWithCSU == ABNORMAL)
+			{
+				RunForceStopProcess();
+				outputRelay.relay_event.bits.AC_Contactor = NO;
+			}
+
+			ShmDcCommonData->acContactSwitch = outputRelay.relay_event.bits.AC_Contactor;
+
+			if (ShmPsuData->Work_Step >= _TEST_MODE && ShmPsuData->Work_Step <= _TEST_MODE)
+				outputRelay.relay_event.bits.Gun1_N = outputRelay.relay_event.bits.Gun1_P = YES;
+
+			// 搭上/鬆開 Relay
+			if(IsNoneMatchRelayStatus())
+			{
+				relayMatchFlag = NO;
+
+				if (Config_Relay_Output(Uart5Fd, Addr.Relay, &outputRelay))
+				{
+					//regRelay.relay_event.bits.AC_Contactor = ShmSysConfigAndInfo->SysInfo.AcContactorStatus;
+//					regRelay.relay_event.bits.CCS_Precharge = outputRelay.relay_event.bits.CCS_Precharge;
+//					regRelay.relay_event.bits.Gun1_P = outputRelay.relay_event.bits.Gun1_P;
+//					regRelay.relay_event.bits.Gun1_N = outputRelay.relay_event.bits.Gun1_N;
+//					regRelay.relay_event.bits.Gun2_P = outputRelay.relay_event.bits.Gun2_P;
+//					regRelay.relay_event.bits.Gun2_N = outputRelay.relay_event.bits.Gun2_N;
+//					regRelay.relay_event.bits.Gun1_Parallel_P = outputRelay.relay_event.bits.Gun1_Parallel_P;
+//					regRelay.relay_event.bits.Gun1_Parallel_N = outputRelay.relay_event.bits.Gun1_Parallel_N;
+				}
+			}
+			else if (relayMatchFlag == NO)
+			{
+				relayMatchFlag = YES;
+				PRINTF_FUNC("======== Relay Status Start========\n");
+				if (regRelay.relay_event.bits.AC_Contactor == YES)
+					PRINTF_FUNC("AC Power : ON \n");
+				else
+					PRINTF_FUNC("AC Power : OFF \n");
+
+				if (regRelay.relay_event.bits.Gun1_P == YES)
+					PRINTF_FUNC("Conn1(+) : ON \n");
+				else
+					PRINTF_FUNC("Conn1(+) : OFF \n");
+
+				if (regRelay.relay_event.bits.Gun1_N == YES)
+					PRINTF_FUNC("Conn1(-) : ON \n");
+				else
+					PRINTF_FUNC("Conn1(-) : OFF \n");
+
+				if (regRelay.relay_event.bits.Gun2_P == YES)
+					PRINTF_FUNC("Conn2(+) : ON \n");
+				else
+					PRINTF_FUNC("Conn2(+) : OFF \n");
+
+				if (regRelay.relay_event.bits.Gun2_N == YES)
+					PRINTF_FUNC("Conn2(-) : ON \n");
+				else
+					PRINTF_FUNC("Conn2(-) : OFF \n");
+
+				if (regRelay.relay_event.bits.CCS_Precharge == YES)
+					PRINTF_FUNC("Precharge : ON \n");
+				else
+					PRINTF_FUNC("Precharge : OFF \n");
+
+				if (regRelay.relay_event.bits.Gun1_Parallel_P == YES)
+					PRINTF_FUNC("Parallel(+) : ON \n");
+				else
+					PRINTF_FUNC("Parallel(+) : OFF \n");
+
+				if (regRelay.relay_event.bits.Gun1_Parallel_N == YES)
+					PRINTF_FUNC("Parallel(-) : ON \n");
+				else
+					PRINTF_FUNC("Parallel(-) : OFF \n");
+				PRINTF_FUNC("======== Relay Status End========\n");
+			}
+		}
+
+		if (ShmFanModuleData->SelfTest_Comp == YES ||
+				strlen((char *)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev) != 0 ||
+				ShmSysConfigAndInfo->SysInfo.FanModuleFwRev[0] != '\0')
+		{
+			ShmFanModuleData->SelfTest_Comp = YES;
+
+			int _timebuf = GetTimeoutValue(&_priority_time);
+
+			if (_timebuf < 0)
+				GetTimespecFunc(&_priority_time);
+			else
+			{
+				if (_timebuf >= 1)
+				{
+					//GetPsuTempForFanSpeed();
+					GetFanSpeedByFunction();
+					GetFanSpeed();
+					ShmSysConfigAndInfo->SysInfo.SystemFanRotaSpeed = _setFanSpeed;
+					GetTimespecFunc(&_priority_time);
+
+					ShmFanModuleData->SetFan1Speed = ShmFanModuleData->TestFanSpeed;
+					ShmFanModuleData->SetFan2Speed = ShmFanModuleData->TestFanSpeed;
+					ShmFanModuleData->SetFan3Speed = ShmFanModuleData->TestFanSpeed;
+					ShmFanModuleData->SetFan4Speed = ShmFanModuleData->TestFanSpeed;
+
+					//PRINTF_FUNC("set fan = %d \n", ShmFanModuleData->SetFan1Speed);
+					SetFanModuleSpeed();
+				}
+			}
+		}
+
+		if (ShmLedModuleData->SelfTest_Comp == YES)
+		{
+			int _timebuf = GetTimeoutValue(&_led_priority_time);
+			if (_timebuf < 0)
+				GetTimespecFunc(&_led_priority_time);
+			else
+			{
+				if (GetTimeoutValue(&_led_blink_time) > 6)
+					GetTimespecFunc(&_led_blink_time);
+
+				if (_timebuf >= 1)
+				{
+					if(gunCount == 1)
+					{
+						SetLedColor(_chargingData[0], _chargingData[0]);
+					}
+					else if (gunCount == 2)
+					{
+						SetLedColor(_chargingData[0], _chargingData[1]);
+					}
+
+					GetTimespecFunc(&_led_priority_time);
+				}
+			}
+		}
+
+		usleep(10000);
+	}
+
+	return FAIL;
+}

+ 235 - 0
EVSE/Projects/NoodoeDS/Apps/Module_LcmContro.h

@@ -0,0 +1,235 @@
+#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/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 	<string.h>
+#include	<time.h>
+#include	<ctype.h>
+#include 	<ifaddrs.h>
+#include 	<stdbool.h>
+#include 	<dirent.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
+#define EQUAL				0
+
+typedef unsigned char 			byte;
+
+struct SysConfigAndInfo			*ShmSysConfigAndInfo;
+struct StatusCodeData 			*ShmStatusCodeData;
+struct FanModuleData			*ShmFanModuleData;
+struct DcCommonInformation		*ShmDcCommonData;
+
+#define NO_DEFINE			255
+#define DEFAULT_AC_INDEX	2
+
+#define TIME_MAX_SEC		2592000 // 一個月,秒數
+#define POWER_MAX_KW		5000
+#define ENERGY_MAX_KWH		5000
+
+#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
+
+//=======================================
+// Register Control type
+//=======================================
+#define REG_TYPE_CONTROL					0x00
+#define REG_TYPE_RAM						0x01
+#define REG_TYPE_SPECIAL_CONTROL			0x02
+
+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 Uart1Fd;
+//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;
+bool _battery_display_ani = false;
+byte _curPage_index = 0;
+bool _page_reload = false;
+byte QRCodeBuf[128];
+
+// LCM - HW
+byte _everyPageRollChange = 0;
+short __logo = 0x0000;
+short __conn_status = 0x0030;
+short __ethernet_status = 0x0032;
+short __3G4G_status = 0x0036;
+short __3G4G_move_status = 0x0038;
+short __wifi_status = 0x003C;
+
+short __sel_gun_btn = 0x0040;
+short __ret_home_btn = 0x0042;
+short __stop_method_btn = 0x0044;
+short __phihong_string = 0x0046;
+
+short __lcm_version = 0x004A;
+
+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 __cmp_gun_type_index = 0x0080;
+short __qr_code_pre = 0x0280;
+
+short __batt_map_empty = 0x0090;
+
+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 __trp_remain_time_map = 0x0116;
+short __trp_power_map = 0x0118;
+short __trp_energy_map = 0x011A;
+
+short __output_eng_tx = 0x0120;
+short __total_out_eng_tx = 0x0130;
+short __conn_line_comp = 0x0140;
+short __charging_fee_map = 0x0146;
+short __logo_cmp = 0x014A;
+short __charging_fee_tx = 0x0150;
+
+short __money_by_rate = 0x0200;
+short __money_rate = 0x0220;
+short __money_rate_map = 0x0230;
+
+short __csu_ver_string = 0x0300;
+short __csu_ver_value = 0x0310;
+short __fan_speed_string = 0x0390;
+short __fan_speed_value = 0x0400;
+
+short __dc1_ver_string = 0x0320;
+short __dc1_ver_value = 0x0330;
+short __dc2_ver_string = 0x0340;
+short __dc2_ver_value = 0x0350;
+short __eth0_ip_string = 0x0360;
+short __eth0_ip_value = 0x0370;
+short __sn_string = 0x0410;
+short __sn_value = 0x0420;
+
+// ICON ID
+byte _disappear = 0;
+byte _disconnect = 1;
+byte _connect = 2;
+byte _warning = 3;
+byte _arrow_dark = 4;
+byte _arrow_light = 5;
+byte _3G4G_disconnect = 6;
+byte _3G4G_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 _ethernet_disconnect = 52;
+byte _ethernet_connect = 53;
+byte _chademo_dark_cmp = 54;
+byte _ccs_dark_cmp = 55;
+byte _gbt_dark_cmp = 56;
+byte _actype_dark_cmp = 57;
+byte _chademo_light_cmp = 58;
+byte _ccs_light_cmp = 59;
+byte _gbt_light_cmp = 60;
+byte _actype_light_cmp = 61;
+byte _logo_cmp = 62;
+byte _battery_eng_trp_map = 63;
+byte _money_trp_map = 64;
+byte _elapse_time_trp_map = 65;
+byte _phihong_string_map = 66;

BIN
EVSE/Projects/NoodoeDS/Apps/Module_LcmControl


+ 2023 - 0
EVSE/Projects/NoodoeDS/Apps/Module_LcmControl.c

@@ -0,0 +1,2023 @@
+#include "Module_LcmContro.h"
+
+bool needReloadQr = true;
+
+bool _isShow = false;
+byte _showInformIndex = 0;
+
+byte _btn_pressed = 0xF0;
+
+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)
+
+char* getTimeString(void);
+
+//=================================
+// Common routine
+//=================================
+int StoreLogMsg(const char *fmt, ...)
+{
+	char Buf[4096+256];
+	char buffer[4096];
+	va_list args;
+	struct timeb  SeqEndTime;
+	struct tm *tm;
+
+	va_start(args, fmt);
+	int rc = vsnprintf(buffer, sizeof(buffer), fmt, args);
+	va_end(args);
+
+	memset(Buf,0,sizeof(Buf));
+	ftime(&SeqEndTime);
+	SeqEndTime.time = time(NULL);
+	tm=localtime(&SeqEndTime.time);
+
+	if (ShmSysConfigAndInfo->SysConfig.SwitchDebugFlag == YES)
+	{
+		sprintf(Buf,"%02d:%02d:%02d:%03d - %s",
+			tm->tm_hour,tm->tm_min,tm->tm_sec,SeqEndTime.millitm, buffer);
+		printf("%s \n", Buf);
+	}
+	else
+	{
+		sprintf(Buf,"echo \"%04d-%02d-%02d %02d:%02d:%02d:%03d - %s\" >> /Storage/SystemLog/[%04d.%02d]SystemLog_%s",
+			tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,SeqEndTime.millitm,
+			buffer,
+			tm->tm_year+1900,tm->tm_mon+1,
+			ShmSysConfigAndInfo->SysConfig.SerialNumber);
+		system(Buf);
+	}
+
+	return rc;
+}
+
+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 PRINTF_FUNC(char *string, ...)
+{
+	va_list args;
+	char buffer[4096];
+	va_start(args, string);
+	vsnprintf(buffer, sizeof(buffer), string, args);
+	va_end(args);
+
+	DEBUG_INFO("%s ", buffer);
+}
+
+//==========================================
+// Init all share memory
+//==========================================
+int InitShareMemory()
+{
+	int result = PASS;
+	int MeterSMId;
+
+	//creat ShmSysConfigAndInfo
+	if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo),  0777)) < 0)
+    {
+		#ifdef SystemLogMessage
+		DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
+		#endif
+		result = FAIL;
+	}
+    else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
+    {
+    	#ifdef SystemLogMessage
+    	DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
+		#endif
+    	result = FAIL;
+   	}
+
+   	//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;
+   	}
+
+ 	if ((MeterSMId = shmget(ShmCommonKey, sizeof(struct DcCommonInformation), IPC_CREAT | 0777)) < 0)
+    {
+    	#ifdef SystemLogMessage
+    	DEBUG_ERROR("shmget ShmCommonKey NG \n");
+    	#endif
+    	return 0;
+    }
+    else if ((ShmDcCommonData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
+    {
+    	#ifdef SystemLogMessage
+    	DEBUG_ERROR("shmat ShmCommonKey NG \n");
+    	#endif
+    	return 0;
+    }
+
+    return result;
+}
+
+//==========================================
+// Open and Close RS232 and R/W
+//==========================================
+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;
+}
+
+void CloseCommunicationLcmPort()
+{
+	close(Uart1Fd);
+}
+
+void WriteCmdToLcm(byte *cmd, byte cmdLen)
+{
+	int len = write(Uart1Fd, cmd, cmdLen);
+	if(len >= sizeof(cmd))
+	{
+		//PRINTF_FUNC("Write cmd to LCM successfully. \n");
+	}
+}
+
+void ReadMsgFromLcm(byte *msg, byte readLen)
+{
+	read(Uart1Fd, msg, readLen);
+
+//	5a : CMD_TITLE_1
+//	a5 : CMD_TITLE_2
+//	5
+//	81 : CMD_WRITE
+//	3  : CMD_REGISTER
+//	2  : Data length
+//	0  : High byte
+//	1  : Low byte
+
+//	printf("-------------------------------------------- \n");
+//	printf("msg = %x \n", *msg);			// A5
+//	printf("msg = %x \n", *(msg + 1));		// 5A
+//	printf("msg = %x \n", *(msg + 2));		// Len : [3] ~ [6] + Data Len
+//	printf("msg = %x \n", *(msg + 3));		// cmd : 0x83
+//	printf("msg = %x \n", *(msg + 4));		// addr : H
+//	printf("msg = %x \n", *(msg + 5));		// addr : L
+//	printf("msg = %x \n", *(msg + 6));		// Data Len
+//
+//	printf("msg = %x \n", *(msg + 7));
+//	printf("msg = %x \n", *(msg + 8));
+//	printf("msg = %x \n", *(msg + 9));
+//	printf("msg = %x \n", *(msg + 10));
+//	printf("msg = %x \n", *(msg + 11));
+//	printf("msg = %x \n", *(msg + 12));
+//	printf("msg = %x \n", *(msg + 13));
+//	printf("msg = %x \n", *(msg + 14));
+
+	if(*msg == CMD_TITLE_1 && *(msg + 1) == CMD_TITLE_2)
+	{
+		if(*(msg + 3) == CMD_WRITE)
+		{
+			switch (*(msg + 4))
+			{
+				case CMD_REGISTER:
+				{
+					// 頁面
+					if(strcmp((char *)ShmSysConfigAndInfo->SysInfo.LcmHwRev, "") != EQUAL)
+						strcpy((char *)ShmSysConfigAndInfo->SysInfo.LcmHwRev, moduleName);
+
+					_currentPage = *(msg + 7);
+//					if (_currentPage != 1 && _currentPage != 5 && _currentPage != 6 && _currentPage != 7 && _currentPage != 8)
+//						printf("_currentPage = %d \n", _currentPage);
+				}
+				break;
+			}
+		}
+		else if (*(msg + 3) == CMD_MULTI_READ)
+		{
+			short key = ((short)(*(msg + 4) << 8) + *(msg + 5));
+			if (key == __lcm_version)
+			{
+				ShmDcCommonData->LcmFwVersion = atoi((char *)(msg + 7));
+				//printf("msg = %d \n", atoi((char *)(msg + 7)));
+//				printf("msg = %x \n", *(msg + 7));
+//				printf("msg = %x \n", *(msg + 8));
+//				printf("msg = %x \n", *(msg + 9));
+			}
+		}
+	}
+}
+
+//================================================
+// Function
+//================================================
+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);
+}
+
+void ChangeBackLight(bool islight)
+{
+	byte value = 0x01;
+
+	// 0x00 ~ 0x40
+	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(10000);
+	ReadMsgFromLcm(msg, ARRAY_SIZE(msg));
+}
+
+void DisplayValueToLcm(short address, byte *data, byte len)
+{
+	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;
+
+	for(byte count = 0; count < len; count++)
+	{
+		cmd[6 + count] = *(data + count);
+	}
+
+	WriteCmdToLcm(cmd, cmd[2] + 3);
+}
+
+void ChangeDisplay2Value(short address, short value)
+{
+	byte data[2];
+	data[0] = value >> 8;
+	data[1] = value & 0x00FF;
+
+	DisplayValueToLcm(address, data, sizeof(data));
+}
+
+void GetDeviceInfoStatus(short address, byte len)
+{
+	byte cmd[8];
+	memset(cmd, 0x00, sizeof(cmd));
+	byte msg[40];
+	memset(msg, 0x00, sizeof(msg));
+
+	cmd[0] = CMD_TITLE_1;
+	cmd[1] = CMD_TITLE_2;
+	cmd[2] = 0x04;
+	cmd[3] = CMD_MULTI_READ;
+	cmd[4] = (address >> 8) & 0xff;
+	cmd[5] = (address >> 0) & 0xff;
+	cmd[6] = len;
+
+	WriteCmdToLcm(cmd, ARRAY_SIZE(cmd));
+	usleep(10000);
+	ReadMsgFromLcm(msg, ARRAY_SIZE(msg));
+}
+
+//================================================
+// Warning process
+//================================================
+void string2ByteArray(unsigned char *input, byte *output)
+{
+    int loop;
+    int i;
+
+    loop = 0;
+    i = 0;
+
+    while(input[loop] != '\0')
+    {
+        output[i++] = input[loop++];
+    }
+    output[loop] = '\0';
+}
+
+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);
+	}
+}
+
+//================================================
+// QR Code process
+//================================================
+void ChangeQrCode_Idle(char *input, byte len)
+{
+	byte cmd[len];
+	int loop = 0;
+
+	input[len] = '\0';
+	cmd[len] = '\0';
+	while(input[loop] != '\0')
+	{
+		cmd[loop] = input[loop];
+		loop++;
+	}
+
+	//printf("cmd = %s, len = %d \n", cmd, len + 1);
+	DisplayValueToLcm(__qr_code, cmd, len + 1);
+}
+
+void ChangeQrCode_Charge(char *input, byte len)
+{
+	byte cmd[len];
+	int loop = 0;
+
+	input[len] = '\0';
+	cmd[len] = '\0';
+	while(input[loop] != '\0')
+	{
+		cmd[loop] = input[loop];
+		loop++;
+	}
+
+	//printf("2 - cmd = %s, len = %d \n", cmd, len + 1);
+	DisplayValueToLcm(__qr_code_pre, cmd, len + 1);
+}
+
+//================================================
+// Change current page
+//================================================
+void ChangeCurPage()
+{
+	//PRINTF_FUNC("cur = %d, new = %d \n", _currentPage, ShmSysConfigAndInfo->SysInfo.PageIndex);
+	if (_currentPage != ShmSysConfigAndInfo->SysInfo.PageIndex)
+	{
+		//_currentPage = ShmSysConfigAndInfo->SysInfo.PageIndex;
+		ChangeToOtherPage(ShmSysConfigAndInfo->SysInfo.PageIndex);
+		_everyPageRollChange = 0;
+	}
+}
+
+//================================================
+// Main process
+//================================================
+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++;
+}
+
+//================================================
+// Main process
+//================================================
+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;
+}
+
+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)
+{
+//	srand(time(NULL));
+//	int min = 10;
+//	int max = 90;
+//	soc = rand() % (max - min + 1) + min;
+
+	if (page == _LCM_PRE_CHARGE)
+	{
+		ChangeDisplay2Value(__batt_map_empty, _battery_empty);
+	}
+	else 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)
+		{
+			if (_battery_display_ani)
+				ChangeDisplay2Value(__batt_map, _battery_cap_80);
+			else
+				ChangeDisplay2Value(__batt_map, _battery_cap_100);
+		}
+		else if (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[5];
+	byte value[5];
+
+	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 ChangeRemainTime(int sec)
+{
+	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));
+}
+
+void ChangeChargingEnergyValue(float energy)
+{
+	byte cmd[10];
+	byte value[10];
+
+	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];
+
+	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];
+
+	memset(cmd, 0x00, sizeof(cmd));
+
+	sprintf((char *) value, "%.2f", fee);
+	string2ByteArray(value, cmd);
+	DisplayValueToLcm(__charging_fee_tx, cmd, sizeof(cmd));
+}
+
+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[8];
+	byte buf[8];
+
+	memset(cmd, 0x00, sizeof(cmd));
+	memcpy((char *) buf, cur, 3);
+	memcpy((char *) buf + 3, "/kWh", 4);
+	buf[7] = '\0';
+	string2ByteArray(buf, cmd);
+	DisplayValueToLcm(__money_rate, cmd, sizeof(cmd));
+}
+
+void RefreshPageAnimation(byte value)
+{
+	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;
+	}
+}
+
+void RefreshConnStatus()
+{
+	// eth
+	if (ShmSysConfigAndInfo->SysInfo.ethInternetConn == YES)
+	{ ChangeDisplay2Value(__ethernet_status, _ethernet_connect); }
+	else
+	{ ChangeDisplay2Value(__ethernet_status, _ethernet_disconnect); }
+
+	// Wifi
+	if((ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'W' || ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D') &&
+			ShmSysConfigAndInfo->SysConfig.AthInterface.WifiMode != _SYS_WIFI_MODE_DISABLE)
+	{
+		if (ShmSysConfigAndInfo->SysConfig.AthInterface.WifiNetworkConn == YES ||
+				ShmSysConfigAndInfo->SysConfig.AthInterface.WifiMode == _SYS_WIFI_MODE_AP)
+		{ ChangeDisplay2Value(__wifi_status, _wifi_connect); }
+		else
+		{ ChangeDisplay2Value(__wifi_status, _wifi_disconnect); }
+	}
+	else
+	{
+		ShmSysConfigAndInfo->SysConfig.AthInterface.WifiRssi = 0;
+		ChangeDisplay2Value(__wifi_status, _disappear);
+	}
+
+	if((ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'T' || ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D') &&
+			ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomEnabled != _SYS_4G_MODE_DISABLE)
+	{
+		if (ShmSysConfigAndInfo->SysConfig.AthInterface.WifiMode == _SYS_WIFI_MODE_DISABLE)
+		{
+			ChangeDisplay2Value(__3G4G_status, _disappear);
+			// 3G/4G
+			if (ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomNetworkConn == YES)
+			{ ChangeDisplay2Value(__3G4G_move_status, _3G4G_connect); }
+			else
+			{ ChangeDisplay2Value(__3G4G_move_status, _3G4G_disconnect); }
+		}
+		else
+		{
+			ChangeDisplay2Value(__3G4G_move_status, _disappear);
+			// 3G/4G
+			if (ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomNetworkConn == YES)
+			{ ChangeDisplay2Value(__3G4G_status, _3G4G_connect); }
+			else
+			{ ChangeDisplay2Value(__3G4G_status, _3G4G_disconnect); }
+		}
+	}
+	else
+	{
+		ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomRssi = 0;
+		ChangeDisplay2Value(__3G4G_status, _disappear);
+		ChangeDisplay2Value(__3G4G_move_status, _disappear);
+	}
+
+	// 連線到後台
+	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;
+}
+
+bool IsPageReloadChk()
+{
+	bool result = false;
+
+	if (ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc == NO_DEFINE)
+	{
+		if (_curPage_index != ShmSysConfigAndInfo->SysInfo.CurGunSelected)
+		{
+			_curPage_index = ShmSysConfigAndInfo->SysInfo.CurGunSelected;
+			result = true;
+		}
+	}
+	else
+	{
+		if (_curPage_index != ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc)
+		{
+			_curPage_index = ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc;
+			result = true;
+		}
+	}
+
+	return result;
+}
+
+bool IsConfigReloadChk()
+{
+	bool result = false;
+
+	if (ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode == NO)
+	{
+		if (strcmp((char *)QRCodeBuf, (char *)ShmSysConfigAndInfo->SysConfig.SystemId) != EQUAL)
+			result = true;
+	}
+	else
+	{
+		if (strcmp((char *)QRCodeBuf, (char *)ShmSysConfigAndInfo->SysConfig.QRCodeContent) != EQUAL)
+			result = true;
+	}
+
+	return result;
+}
+
+void SaveQrcodeToBuf(byte *qrcode)
+{
+	strncpy((char *)QRCodeBuf, (char *)qrcode, sizeof(QRCodeBuf));
+}
+
+void ClearDisplayInfo()
+{
+	ChangeDisplay2Value(__csu_ver_string, _disappear);
+	ChangeDisplay2Value(__csu_ver_value, _disappear);
+
+	ChangeDisplay2Value(__eth0_ip_string, _disappear);
+	ChangeDisplay2Value(__eth0_ip_value, _disappear);
+
+	ChangeDisplay2Value(__sn_string, _disappear);
+	ChangeDisplay2Value(__sn_value, _disappear);
+
+	ChangeDisplay2Value(__dc1_ver_string, _disappear);
+	ChangeDisplay2Value(__dc1_ver_value, _disappear);
+
+	ChangeDisplay2Value(__dc2_ver_string, _disappear);
+	ChangeDisplay2Value(__dc2_ver_value, _disappear);
+
+	ChangeDisplay2Value(__fan_speed_string, _disappear);
+	ChangeDisplay2Value(__fan_speed_value, _disappear);
+}
+
+void DisplayInfoCsuVer(bool isShow, unsigned char *modelName)
+{
+	if (isShow)
+	{
+		byte value[10];
+
+		memset(value, 0x00, sizeof(value));
+		strcpy((char *)value, "CSU Ver >");
+		DisplayValueToLcm(__csu_ver_string, value, sizeof(value));
+		memset(value, 0x00, sizeof(value));
+		strncpy((char *)value, (char *)modelName, 5);
+		DisplayValueToLcm(__csu_ver_value, value, sizeof(value));
+	}
+	else
+	{
+		ChangeDisplay2Value(__csu_ver_string, _disappear);
+		ChangeDisplay2Value(__csu_ver_value, _disappear);
+	}
+}
+
+void ShowWifiMode(bool isShow, unsigned char mode)
+{
+	if (isShow)
+	{
+		byte value[20];
+
+		memset(value, 0x00, sizeof(value));
+		strcpy((char *) value, "Wifi Mo. >");
+		DisplayValueToLcm(__csu_ver_string, value, sizeof(value));
+		memset(value, 0x00, sizeof(value));
+		if (mode == 0)
+			sprintf((char *)value, "disable");
+		else if (mode == 1)
+			sprintf((char *)value, "station");
+		else if (mode == 2)
+			sprintf((char *)value, "AP");
+
+		DisplayValueToLcm(__csu_ver_value, value, sizeof(value));
+	}
+	else
+	{
+		ChangeDisplay2Value(__csu_ver_string, _disappear);
+		ChangeDisplay2Value(__csu_ver_value, _disappear);
+	}
+}
+
+void DisplayInfoEthIp(bool isShow, unsigned char *ip)
+{
+	if (isShow)
+	{
+		byte value[20];
+
+		memset(value, 0x00, sizeof(value));
+		strcpy((char *) value, "Eth IP >");
+		DisplayValueToLcm(__eth0_ip_string, value, sizeof(value));
+		memset(value, 0x00, sizeof(value));
+		strcpy((char *) value, (char *) ip);
+		DisplayValueToLcm(__eth0_ip_value, value, sizeof(value));
+	}
+	else
+	{
+		ChangeDisplay2Value(__eth0_ip_string, _disappear);
+		ChangeDisplay2Value(__eth0_ip_value, _disappear);
+	}
+}
+
+void Show4GRssi(bool isShow, int dbValue)
+{
+	if (isShow)
+	{
+		byte value[20];
+
+		memset(value, 0x00, sizeof(value));
+		strcpy((char *) value, "RSSI >");
+		DisplayValueToLcm(__dc2_ver_string, value, sizeof(value));
+		memset(value, 0x00, sizeof(value));
+		sprintf((char *)value, "%d dBm", dbValue);
+		DisplayValueToLcm(__dc2_ver_value, value, sizeof(value));
+	}
+	else
+	{
+		ChangeDisplay2Value(__dc2_ver_string, _disappear);
+		ChangeDisplay2Value(__dc2_ver_value, _disappear);
+	}
+}
+
+void DisplayInfoSN(bool isShow, unsigned char *sn)
+{
+	if (isShow)
+	{
+		byte value[30];
+
+		memset(value, 0x00, sizeof(value));
+		strcpy((char *) value, "SN >");
+		DisplayValueToLcm(__sn_string, value, sizeof(value));
+		memset(value, 0x00, sizeof(value));
+		strcpy((char *) value, (char *) sn);
+		DisplayValueToLcm(__sn_value, value, sizeof(value));
+	}
+	else
+	{
+		ChangeDisplay2Value(__sn_string, _disappear);
+		ChangeDisplay2Value(__sn_value, _disappear);
+	}
+}
+
+void ShowWifiRssi(bool isShow, int dbValue)
+{
+	if (isShow)
+	{
+		byte value[20];
+
+		memset(value, 0x00, sizeof(value));
+		strcpy((char *) value, "RSSI >");
+		DisplayValueToLcm(__fan_speed_string, value, sizeof(value));
+		memset(value, 0x00, sizeof(value));
+		sprintf((char *)value, "%d dBm", dbValue);
+		DisplayValueToLcm(__fan_speed_value, value, sizeof(value));
+	}
+	else
+	{
+		ChangeDisplay2Value(__fan_speed_string, _disappear);
+		ChangeDisplay2Value(__fan_speed_value, _disappear);
+	}
+}
+
+void DisplayInfoGun1Ver(bool isShow, unsigned char *version)
+{
+	if (isShow)
+	{
+		byte value[10];
+
+		memset(value, 0x00, sizeof(value));
+		strcpy((char *) value, "Ct1 Ver >");
+		DisplayValueToLcm(__dc1_ver_string, value, sizeof(value));
+		memset(value, 0x00, sizeof(value));
+		strcpy((char *) value, (char *) version);
+		DisplayValueToLcm(__dc1_ver_value, value, sizeof(value));
+	}
+	else
+	{
+		ChangeDisplay2Value(__dc1_ver_string, _disappear);
+		ChangeDisplay2Value(__dc1_ver_value, _disappear);
+	}
+}
+
+void Show4GMode(bool isShow, unsigned char mode)
+{
+	if (isShow)
+	{
+		byte value[20];
+
+		memset(value, 0x00, sizeof(value));
+		strcpy((char *) value, "3/4G Mo. >");
+		DisplayValueToLcm(__dc1_ver_string, value, sizeof(value));
+		memset(value, 0x00, sizeof(value));
+		if (mode == 0)
+			sprintf((char *)value, "disable");
+		else if (mode == 1)
+			sprintf((char *)value, "enable");
+
+		DisplayValueToLcm(__dc1_ver_value, value, sizeof(value));
+	}
+	else
+	{
+		ChangeDisplay2Value(__dc1_ver_string, _disappear);
+		ChangeDisplay2Value(__dc1_ver_value, _disappear);
+	}
+}
+
+void DisplayInfoGun2Ver(bool isShow, unsigned char *version)
+{
+	if (isShow)
+	{
+		byte value[10];
+
+		memset(value, 0x00, sizeof(value));
+		strcpy((char *) value, "Ct2 Ver >");
+		DisplayValueToLcm(__dc2_ver_string, value, sizeof(value));
+		memset(value, 0x00, sizeof(value));
+		strcpy((char *) value, (char *) version);
+		DisplayValueToLcm(__dc2_ver_value, value, sizeof(value));
+	}
+	else
+	{
+		ChangeDisplay2Value(__dc2_ver_string, _disappear);
+		ChangeDisplay2Value(__dc2_ver_value, _disappear);
+	}
+}
+
+void Show4GIP(bool isShow, unsigned char *ip)
+{
+	if (isShow)
+	{
+		byte value[20];
+
+		memset(value, 0x00, sizeof(value));
+		strcpy((char *) value, "3/4G IP ");
+		DisplayValueToLcm(__eth0_ip_string, value, sizeof(value));
+		memset(value, 0x00, sizeof(value));
+		strcpy((char *) value, (char *) ip);
+		DisplayValueToLcm(__eth0_ip_value, value, sizeof(value));
+	}
+	else
+	{
+		ChangeDisplay2Value(__eth0_ip_string, _disappear);
+		ChangeDisplay2Value(__eth0_ip_value, _disappear);
+	}
+}
+
+void DisplayInfoSpeed(bool isShow, unsigned int fan)
+{
+	if (isShow)
+	{
+		byte value[10];
+
+		memset(value, 0x00, sizeof(value));
+		strcpy((char *) value, "Fan Spd >");
+		DisplayValueToLcm(__fan_speed_string, value, sizeof(value));
+		memset(value, 0x00, sizeof(value));
+		sprintf((char *)value, "%d", fan);
+		DisplayValueToLcm(__fan_speed_value, value, sizeof(value));
+	}
+	else
+	{
+		ChangeDisplay2Value(__fan_speed_string, _disappear);
+		ChangeDisplay2Value(__fan_speed_value, _disappear);
+	}
+}
+
+void ShowWifiIP(bool isShow, unsigned char *ip)
+{
+	if (isShow)
+	{
+		byte value[20];
+
+		memset(value, 0x00, sizeof(value));
+		strcpy((char *) value, "Wifi IP ");
+		DisplayValueToLcm(__sn_string, value, sizeof(value));
+		memset(value, 0x00, sizeof(value));
+		strcpy((char *) value, (char *) ip);
+		DisplayValueToLcm(__sn_value, value, sizeof(value));
+	}
+	else
+	{
+		ChangeDisplay2Value(__sn_string, _disappear);
+		ChangeDisplay2Value(__sn_value, _disappear);
+	}
+}
+
+void InformationShow()
+{
+	if(ShmSysConfigAndInfo->SysConfig.ShowInformation == YES)
+	{
+		bool show = _isShow = true;
+		if (_showInformIndex == 0)
+		{
+			DisplayInfoCsuVer(show, ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
+			DisplayInfoSpeed(show, ShmSysConfigAndInfo->SysInfo.SystemFanRotaSpeed);
+			DisplayInfoSN(show, ShmSysConfigAndInfo->SysConfig.SerialNumber);
+
+			DisplayInfoEthIp(show, ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthIpAddress);
+			DisplayInfoGun1Ver(show, ShmSysConfigAndInfo->SysInfo.Connector1FwRev);
+			if (_totalCount > 1)
+				DisplayInfoGun2Ver(show, ShmSysConfigAndInfo->SysInfo.Connector2FwRev);
+			else
+			{
+				DisplayInfoGun2Ver(false, ShmSysConfigAndInfo->SysInfo.Connector2FwRev);
+			}
+		}
+		else if (_showInformIndex == 1)
+		{
+			ShowWifiMode(show, ShmSysConfigAndInfo->SysConfig.AthInterface.WifiMode);
+			ShowWifiRssi(show, ShmSysConfigAndInfo->SysConfig.AthInterface.WifiRssi);
+			ShowWifiIP(show, ShmSysConfigAndInfo->SysConfig.AthInterface.WifiIpAddress);
+
+			Show4GMode(show, ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomEnabled);
+			Show4GRssi(show, ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomRssi);
+			Show4GIP(show, ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomIpAddress);
+		}
+	}
+	else
+	{
+		ClearDisplayInfo();
+
+		if (_isShow)
+		{
+			_isShow = false;
+			_showInformIndex++;
+			if (_showInformIndex >= 2)
+				_showInformIndex = 0;
+		}
+	}
+}
+
+void ProcessPageInfo()
+{
+	_page_reload = IsPageReloadChk();
+
+	if (!_page_reload)
+		_page_reload = IsConfigReloadChk();
+
+	// 隨插即充 - 可省略該按鈕
+//	if (ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_ENABLE)
+//	{
+//		ChangeDisplay2Value(__ret_home_btn, _back_home_btn);
+//		if (_totalCount >= 2 && ShmSysConfigAndInfo->SysInfo.IsAlternatvieConf == NO)
+//			ChangeDisplay2Value(__sel_gun_btn, _sel_gun_btn);
+//		else
+//			ChangeDisplay2Value(__sel_gun_btn, _disappear);
+//	}
+	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 || _page_reload)
+			{
+				if (ShmSysConfigAndInfo->SysConfig.isQRCode)
+				{
+					needReloadQr = false;
+					if (ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode == NO)
+					{
+						byte len = strlen((char *)ShmSysConfigAndInfo->SysConfig.SystemId);
+						SaveQrcodeToBuf(ShmSysConfigAndInfo->SysConfig.SystemId);
+						ChangeQrCode_Idle((char *)ShmSysConfigAndInfo->SysConfig.SystemId, len);
+					}
+					else
+					{
+						byte len = strlen((char *)ShmSysConfigAndInfo->SysConfig.QRCodeContent);
+						SaveQrcodeToBuf(ShmSysConfigAndInfo->SysConfig.QRCodeContent);
+						ChangeQrCode_Idle((char *)ShmSysConfigAndInfo->SysConfig.QRCodeContent, len);
+					}
+				}
+			}
+
+			bool isCharging = false;
+			for(byte i = 0; i < _totalCount; i++)
+			{
+				if (_chargingInfoData[i]->SystemStatus == SYS_MODE_IDLE)
+					continue;
+
+				isCharging = true;
+				break;
+			}
+
+			if (isCharging && ShmSysConfigAndInfo->SysInfo.IsAlternatvieConf == NO)
+			{
+				ChangeDisplay2Value(__sel_gun_btn, _sel_gun_btn);
+			}
+			else
+			{
+				ChangeDisplay2Value(__sel_gun_btn, _disappear);
+			}
+		}
+			break;
+		case _LCM_AUTHORIZING:
+		case _LCM_AUTHORIZ_COMP:
+		case _LCM_AUTHORIZ_FAIL:
+		{
+			FirstPageChanged();
+		}
+			break;
+		case _LCM_WAIT_FOR_PLUG:
+		{
+			FirstPageChanged();
+//			bool isCharging = false;
+//			for(byte i = 0; i < _totalCount; i++)
+//			{
+//				if (_chargingInfoData[i]->SystemStatus == SYS_MODE_IDLE ||
+//						_chargingInfoData[i]->SystemStatus == SYS_MODE_MAINTAIN ||
+//						_chargingInfoData[i]->SystemStatus == SYS_MODE_RESERVATION)
+//					continue;
+//
+//				isCharging = true;
+//				break;
+//			}
+
+			if (ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_DISABLE)
+			{
+				// 新增隨插即充功能預設在等待插槍頁面在開啟
+				ChangeDisplay2Value(__ret_home_btn, _disappear);
+			}
+			else
+				ChangeDisplay2Value(__ret_home_btn, _back_home_btn);
+
+//			if (isCharging && ShmSysConfigAndInfo->SysInfo.IsAlternatvieConf == NO)
+//			{
+//				ChangeDisplay2Value(__sel_gun_btn, _sel_gun_btn);
+//			}
+//			else
+			{
+				ChangeDisplay2Value(__sel_gun_btn, _disappear);
+			}
+		}
+			break;
+		case _LCM_PRE_CHARGE:
+		case _LCM_CHARGING:
+		case _LCM_COMPLETE:
+		{
+			bool isShowAc = false;
+			byte gunTargetIndex = 0;
+
+			ChangeDisplay2Value(__ret_home_btn, _back_home_btn);
+
+			if (acgunCount > 0)
+			{
+				gunTargetIndex = 2;
+				if (ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc != NO_DEFINE)
+				{
+					isShowAc = true;
+					if (_currentPage == _LCM_COMPLETE)
+						ChangeDisplay2Value(__cmp_gun_type_index + (gunTargetIndex * 2), _actype_light_cmp);
+					else
+						ChangeDisplay2Value(__gun_type_index + (gunTargetIndex * 2), _actype_light);
+
+					if (_currentPage == _LCM_CHARGING)
+					{
+						ChangeAcBattMapAndValue(_LCM_CHARGING);
+						if (ac_chargingInfo[0]->PresentChargedDuration >= 0 &&
+								ac_chargingInfo[0]->PresentChargedDuration <= TIME_MAX_SEC)
+							ChangeRemainTime(ac_chargingInfo[0]->PresentChargedDuration);
+						else
+							ChangeRemainTime(0);
+
+						if (ac_chargingInfo[0]->PresentChargingPower >= 0.1 &&
+								ac_chargingInfo[0]->PresentChargingPower <= POWER_MAX_KW)
+							ChangeChargingPowerValue(ac_chargingInfo[0]->PresentChargingPower);
+						else
+							ChangeChargingPowerValue(0);
+
+						if (ac_chargingInfo[0]->PresentChargedEnergy >= 0.1 &&
+								ac_chargingInfo[0]->PresentChargedEnergy <= ENERGY_MAX_KWH)
+							ChangeChargingEnergyValue(ac_chargingInfo[0]->PresentChargedEnergy);
+						else
+							ChangeChargingEnergyValue(0);
+
+						if (ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_DISABLE ||
+								strcmp((char *)ac_chargingInfo[0]->StartUserId, "") == 0 ||
+								ShmSysConfigAndInfo->SysConfig.StopChargingByButton == YES ||
+								ac_chargingInfo[0]->isRemoteStart)
+							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]->PresentChargedDuration >= 0 &&
+								ac_chargingInfo[0]->PresentChargedDuration <= TIME_MAX_SEC)
+							ChangeRemainTime(ac_chargingInfo[0]->PresentChargedDuration);
+						else
+							ChangeRemainTime(0);
+
+						if (ac_chargingInfo[0]->PresentChargingPower >= 0.1 &&
+								ac_chargingInfo[0]->PresentChargingPower <= POWER_MAX_KW)
+							ChangeChargingPowerValue(ac_chargingInfo[0]->PresentChargingPower);
+						else
+							ChangeChargingPowerValue(0);
+
+						if ((ac_chargingInfo[0]->PresentChargedEnergy >= 0.1 &&
+								ac_chargingInfo[0]->PresentChargedEnergy <= ENERGY_MAX_KWH) ||
+								(strcmp((char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, "") != EQUAL &&
+										strcmp((char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId, "") != EQUAL))
+						{
+							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
+				{
+					if (_currentPage == _LCM_COMPLETE)
+						ChangeDisplay2Value(__cmp_gun_type_index + (gunTargetIndex * 2), _actype_dark_cmp);
+					else
+						ChangeDisplay2Value(__gun_type_index + (gunTargetIndex * 2), _actype_dark);
+				}
+			}
+			else
+			{
+				if (_totalCount > 1)
+				{
+					gunTargetIndex = 2;
+					ChangeDisplay2Value(__cmp_gun_type_index + (gunTargetIndex * 2), _disappear);
+					ChangeDisplay2Value(__gun_type_index + (gunTargetIndex * 2), _disappear);
+				}
+			}
+
+			gunTargetIndex = 0;
+			for(byte i = 0; i < _totalCount; i++)
+			{
+				if (_totalCount == 1 && acgunCount <= 0)
+					gunTargetIndex = 2;
+				else
+					gunTargetIndex = i;
+
+				switch(_chargingInfoData[i]->Type)
+				{
+					case _Type_Chademo:
+					{
+						if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == i && !isShowAc)
+						{
+							if (_currentPage == _LCM_COMPLETE)
+								ChangeDisplay2Value(__cmp_gun_type_index + (gunTargetIndex * 2), _chademo_light_cmp);
+							else
+								ChangeDisplay2Value(__gun_type_index + (gunTargetIndex * 2), _chademo_light);
+						}
+						else
+						{
+							if (_currentPage == _LCM_COMPLETE)
+								ChangeDisplay2Value(__cmp_gun_type_index + (gunTargetIndex * 2), _chademo_dark_cmp);
+							else
+								ChangeDisplay2Value(__gun_type_index + (gunTargetIndex * 2), _chademo_dark);
+						}
+					}
+						break;
+					case _Type_GB:
+					{
+						if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == i && !isShowAc)
+						{
+							if (_currentPage == _LCM_COMPLETE)
+								ChangeDisplay2Value(__cmp_gun_type_index + (gunTargetIndex * 2), _gbt_light_cmp);
+							else
+								ChangeDisplay2Value(__gun_type_index + (gunTargetIndex * 2), _gbt_light);
+						}
+						else
+						{
+							if (_currentPage == _LCM_COMPLETE)
+								ChangeDisplay2Value(__cmp_gun_type_index + (gunTargetIndex * 2), _gbt_dark_cmp);
+							else
+								ChangeDisplay2Value(__gun_type_index + (gunTargetIndex * 2), _gbt_dark);
+						}
+					}
+						break;
+					case _Type_CCS:
+					{
+						if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == i && !isShowAc)
+						{
+							if (_currentPage == _LCM_COMPLETE)
+								ChangeDisplay2Value(__cmp_gun_type_index + (gunTargetIndex * 2), _ccs_light_cmp);
+							else
+								ChangeDisplay2Value(__gun_type_index + (gunTargetIndex * 2), _ccs_light);
+						}
+						else
+						{
+							if (_currentPage == _LCM_COMPLETE)
+								ChangeDisplay2Value(__cmp_gun_type_index + (gunTargetIndex * 2), _ccs_dark_cmp);
+							else
+								ChangeDisplay2Value(__gun_type_index + (gunTargetIndex * 2), _ccs_dark);
+						}
+					}
+						break;
+				}
+
+				if (_currentPage == _LCM_PRE_CHARGE && !isShowAc)
+				{
+					if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == i)
+					{
+						ChangeBattMapAndValue(_currentPage, _chargingInfoData[i]->EvBatterySoc);
+					}
+				}
+				else if (_currentPage == _LCM_CHARGING && !isShowAc)
+				{
+					if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == i)
+					{
+						ChangeBattMapAndValue(_currentPage, _chargingInfoData[i]->EvBatterySoc);
+						if (_chargingInfoData[i]->PresentChargedDuration >= 0 &&
+								_chargingInfoData[i]->PresentChargedDuration <= TIME_MAX_SEC)
+							ChangeRemainTime(_chargingInfoData[i]->PresentChargedDuration);
+						else
+							ChangeRemainTime(0);
+
+						if (_chargingInfoData[i]->PresentChargingPower >= 0 &&
+								_chargingInfoData[i]->PresentChargingPower <= POWER_MAX_KW)
+							ChangeChargingPowerValue(_chargingInfoData[i]->PresentChargingPower);
+						else
+							ChangeChargingPowerValue(0);
+
+						if (_chargingInfoData[i]->PresentChargedEnergy >= 0.1 &&
+								_chargingInfoData[i]->PresentChargedEnergy <= ENERGY_MAX_KWH)
+							ChangeChargingEnergyValue(_chargingInfoData[i]->PresentChargedEnergy);
+						else
+							ChangeChargingEnergyValue(0);
+
+						if (ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_DISABLE ||
+								strcmp((char *)_chargingInfoData[i]->StartUserId, "") == 0 ||
+								ShmSysConfigAndInfo->SysConfig.StopChargingByButton == YES ||
+								_chargingInfoData[i]->isRemoteStart ||
+								ShmDcCommonData->_authWithCcidFlag [i] == _CCID_AUTHCOMP)
+							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(_currentPage, _chargingInfoData[i]->EvBatterySoc);
+						if (_chargingInfoData[i]->PresentChargedDuration >= 0 &&
+								_chargingInfoData[i]->PresentChargedDuration <= TIME_MAX_SEC)
+							ChangeRemainTime(_chargingInfoData[i]->PresentChargedDuration);
+						else
+							ChangeRemainTime(0);
+
+						if (_chargingInfoData[i]->PresentChargingPower >= 0 &&
+								_chargingInfoData[i]->PresentChargingPower <= POWER_MAX_KW)
+							ChangeChargingPowerValue(_chargingInfoData[i]->PresentChargingPower);
+						else
+							ChangeChargingPowerValue(0);
+
+						if ((_chargingInfoData[i]->PresentChargedEnergy >= 0.1 &&
+								_chargingInfoData[i]->PresentChargedEnergy <= ENERGY_MAX_KWH) ||
+								(strcmp((char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, "") != EQUAL &&
+									strcmp((char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId, "") != EQUAL))
+						{
+							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);
+						}
+					}
+				}
+			}
+
+			if (_totalCount > 1 &&
+					ShmSysConfigAndInfo->SysInfo.IsAlternatvieConf == NO)
+			{
+				ChangeDisplay2Value(__sel_gun_btn, _sel_gun_btn);
+			}
+			else
+			{
+				ChangeDisplay2Value(__sel_gun_btn, _disappear);
+			}
+
+			// 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 == SYS_MODE_IDLE ||
+						_chargingInfoData[index]->SystemStatus == SYS_MODE_RESERVATION ||
+						_chargingInfoData[index]->SystemStatus == SYS_MODE_BOOTING)
+				{
+					if (FirstPageChanged() == YES || needReloadQr || _page_reload)
+					{
+						if (ShmSysConfigAndInfo->SysConfig.isQRCode)
+						{
+							needReloadQr = false;
+							if (ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode == NO)
+							{
+								byte len = strlen((char *)ShmSysConfigAndInfo->SysConfig.SystemId);
+								ChangeQrCode_Charge((char *)ShmSysConfigAndInfo->SysConfig.SystemId, len);
+							}
+							else
+							{
+								byte len = strlen((char *)ShmSysConfigAndInfo->SysConfig.QRCodeContent);
+								ChangeQrCode_Charge((char *)ShmSysConfigAndInfo->SysConfig.QRCodeContent, len);
+							}
+						}
+					}
+				}
+			}
+		}
+			break;
+	}
+}
+
+void ChangeDisplayMoneyInfoWithoutBackend()
+{
+	struct timeb csuTime;
+	struct tm *tmCSU;
+
+	ftime(&csuTime);
+	tmCSU = localtime(&csuTime.time);
+
+	ChangeDisplay2Value(__money_rate_map, _charging_money);
+
+	if (tmCSU->tm_hour <= 23)
+	{
+		ShmDcCommonData->_hour_index = tmCSU->tm_hour;
+		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]);
+	}
+}
+
+void ChangeDisplayMoneyInfo()
+{
+	struct timeb csuTime;
+	struct tm *tmCSU;
+
+	ftime(&csuTime);
+	tmCSU = localtime(&csuTime.time);
+
+	ChangeDisplay2Value(__money_rate_map, _charging_money);
+	ShmDcCommonData->_hour_index = tmCSU->tm_hour;
+	if (ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc == DEFAULT_AC_INDEX)
+	{
+		if (ac_chargingInfo[0]->SystemStatus == SYS_MODE_IDLE ||
+				ac_chargingInfo[0]->SystemStatus == SYS_MODE_MAINTAIN ||
+				ac_chargingInfo[0]->SystemStatus == SYS_MODE_RESERVATION)
+		{
+			ShmSysConfigAndInfo->SysConfig.BillingData.Cur_fee = (float)ShmDcCommonData->balanceInfo.defaultPrice / 100;
+		}
+		else
+		{
+			if (ShmSysConfigAndInfo->SysConfig.TotalConnectorCount > 0)
+			{
+				if (ShmDcCommonData->balanceInfo.connectorBalanceInfo[1].UserPrice == 0)
+					ShmSysConfigAndInfo->SysConfig.BillingData.Cur_fee = (float)ShmDcCommonData->balanceInfo.defaultPrice / 100;
+				else
+				{
+					ShmSysConfigAndInfo->SysConfig.BillingData.Cur_fee =
+							(float)ShmDcCommonData->balanceInfo.connectorBalanceInfo[1].UserPrice / 100;
+				}
+
+				if (ShmDcCommonData->balanceInfo.connectorBalanceInfo[1].AccountBalance > 0)
+					ac_chargingInfo[0]->ChargingFee = (float)ShmDcCommonData->balanceInfo.connectorBalanceInfo[1].AccountBalance / 100;
+				else
+					ac_chargingInfo[0]->ChargingFee = 0;
+			}
+			else
+			{
+				if (ShmDcCommonData->balanceInfo.connectorBalanceInfo[0].UserPrice == 0)
+					ShmSysConfigAndInfo->SysConfig.BillingData.Cur_fee = (float)ShmDcCommonData->balanceInfo.defaultPrice / 100;
+				else
+					ShmSysConfigAndInfo->SysConfig.BillingData.Cur_fee = ShmDcCommonData->balanceInfo.connectorBalanceInfo[0].UserPrice;
+
+				if (ShmDcCommonData->balanceInfo.connectorBalanceInfo[0].AccountBalance > 0)
+					ac_chargingInfo[0]->ChargingFee = (float)ShmDcCommonData->balanceInfo.connectorBalanceInfo[0].AccountBalance / 100;
+				else
+					ac_chargingInfo[0]->ChargingFee = 0;
+			}
+		}
+		DisplayMoneyRate(ShmSysConfigAndInfo->SysConfig.BillingData.Cur_fee);
+	}
+	else
+	{
+		if (_chargingInfoData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus == SYS_MODE_IDLE ||
+				_chargingInfoData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus == SYS_MODE_MAINTAIN ||
+				_chargingInfoData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus == SYS_MODE_RESERVATION)
+		{
+			ShmSysConfigAndInfo->SysConfig.BillingData.Cur_fee = (float)ShmDcCommonData->balanceInfo.defaultPrice / 100;
+		}
+		else
+		{
+			byte acGunIndex = 0;
+
+			if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == 1)
+				acGunIndex = ShmSysConfigAndInfo->SysConfig.AcConnectorCount;
+
+			if (ShmDcCommonData->balanceInfo.connectorBalanceInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected + acGunIndex].UserPrice == 0)
+			{
+				ShmSysConfigAndInfo->SysConfig.BillingData.Cur_fee = (float)ShmDcCommonData->balanceInfo.defaultPrice / 100;
+			}
+			else
+			{
+				ShmSysConfigAndInfo->SysConfig.BillingData.Cur_fee =
+					(float)ShmDcCommonData->balanceInfo.connectorBalanceInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected + acGunIndex].UserPrice / 100;
+			}
+
+			if (ShmDcCommonData->balanceInfo.connectorBalanceInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected + acGunIndex].AccountBalance > 0)
+			{
+				_chargingInfoData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->ChargingFee =
+						(float)ShmDcCommonData->balanceInfo.connectorBalanceInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected + acGunIndex].AccountBalance / 100;
+			}
+			else
+			{
+				_chargingInfoData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->ChargingFee = 0;
+			}
+		}
+		DisplayMoneyRate(ShmSysConfigAndInfo->SysConfig.BillingData.Cur_fee);
+	}
+
+	if (ShmSysConfigAndInfo->SysConfig.BillingData.Currency <= 53)
+	{
+		DisplayMoneyCur((byte *)Currency[ShmSysConfigAndInfo->SysConfig.BillingData.Currency]);
+	}
+}
+
+void Initialization()
+{
+	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("LcmComm (main) : FindChargingInfoData false \n");
+				isPass = false;
+				count--;
+				break;
+			}
+		}
+
+		sleep(1);
+	}
+
+	isPass = false;
+
+	if (acgunCount > 0)
+	{
+		while(!isPass)
+		{
+			isPass = true;
+			for (byte _index = 0; _index < acgunCount; _index++)
+			{
+				if (!FindAcChargingInfoData(_index, &ac_chargingInfo[0]))
+				{
+					DEBUG_ERROR("LcmComm : FindAcChargingInfoData false \n");
+					isPass = false;
+					break;
+				}
+			}
+
+			sleep(1);
+		}
+	}
+
+	if (count == 0)
+		PRINTF_FUNC("LCM Initialization Gun Fail.............\n");
+}
+
+void DefaultIconStatus()
+{
+	for(byte i = 0; i < 3; i++)
+		ChangeDisplay2Value(__gun_type_index + (i * 2), _disappear);
+
+	if (ShmSysConfigAndInfo->SysInfo.IsAlternatvieConf == YES || _totalCount == 1)
+		ChangeDisplay2Value(__sel_gun_btn, _disappear);
+	else
+		ChangeDisplay2Value(__sel_gun_btn, _sel_gun_btn);
+
+	if (ShmDcCommonData->ShowLogoFlag)
+	{
+		ChangeDisplay2Value(__logo, _logo);
+		ChangeDisplay2Value(__logo_cmp, _logo_cmp);
+	}
+	else
+	{
+		ChangeDisplay2Value(__logo, _disappear);
+		ChangeDisplay2Value(__logo_cmp, _disappear);
+	}
+
+	char _buf[3] = {0};
+	memcpy(_buf, &ShmSysConfigAndInfo->SysConfig.ModelName[12], 2);
+
+	// N0 : 拓連
+//	if (ShmDcCommonData->ShowLogoFlag &&
+//			strcmp(_buf, "N0") != EQUAL)
+	if (strcmp(_buf, "N0") != EQUAL)
+	{
+		ChangeDisplay2Value(__phihong_string, _phihong_string_map);
+	}
+	else
+	{
+		ChangeDisplay2Value(__phihong_string, _disappear);
+	}
+}
+
+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 = CreateCommunicationLcmPort();
+	byte changeWarningPriority = 0;
+	byte curWarningCount = 255;
+	ChangeBackLight(true);
+	_totalCount = ShmSysConfigAndInfo->SysConfig.TotalConnectorCount;
+	acgunCount = ShmSysConfigAndInfo->SysConfig.AcConnectorCount;
+
+	Initialization();
+
+	//	ChangeToOtherPage(_LCM_IDLE);
+	//	ChangeDisplay2Value(__phihong_string, _disappear);
+	//	return -1;
+
+	DefaultIconStatus();
+
+//	int xxx = 3;
+//	while(xxx > 0 && Uart1Fd != -1)
+//	{
+//		if (xxx == 1)
+//		{
+//			printf("---------------------------- \n");
+//			downloadBMP(1, "/tmp/1_idle.bmp");
+//			printf("---------------------------- end \n");
+//			return -1;
+//		}
+//		sleep(1);
+//		xxx--;
+//	}
+//	return -1;
+
+	byte _verShowCount = 3;
+	while(Uart1Fd != -1)
+	{
+		if (strcmp((char *)ShmSysConfigAndInfo->SysInfo.LcmHwRev, moduleName) != EQUAL ||
+				_verShowCount > 0)
+		{
+			GetDeviceInfoStatus(__lcm_version, 3);
+			GetCurrentPage();
+			sleep(1);
+
+			if (_verShowCount > 0)
+			{
+				PRINTF_FUNC("LCM Version = V.%03d \n", ShmDcCommonData->LcmFwVersion);
+				_verShowCount--;
+			}
+
+			if (ShmDcCommonData->LcmFwVersion >= 2)
+			{
+				ChangeDisplay2Value ( __logo, _logo );
+				ChangeDisplay2Value ( __logo_cmp, _logo_cmp );
+			}
+		}
+		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();
+			// 換頁處理
+			GetCurrentPage();
+			ChangeCurPage();
+
+			RefreshPageAnimation(_everyPageRollChange);
+
+			if (changeWarningPriority == 0)
+			{
+				if (ShmSysConfigAndInfo->SysConfig.BillingData.isBilling)
+				{
+					if(strcmp((char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, "") != EQUAL &&
+							strcmp((char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId, "") != EQUAL)
+					{
+						ChangeDisplayMoneyInfo();
+					}
+					else
+						ChangeDisplayMoneyInfoWithoutBackend();
+				}
+				else
+				{
+					ChangeDisplay2Value(__money_rate_map, _disappear);
+					ChangeDisplay2Value(__money_by_rate, _disappear);
+					ChangeDisplay2Value(__money_rate, _disappear);
+				}
+
+				InformationShow();
+			}
+
+			changeWarningPriority >= 15 ? (_battery_display_ani = true) : (_battery_display_ani = false);
+			changeWarningPriority >= 30 ? changeWarningPriority = 0 : changeWarningPriority++;
+			usleep(100000);
+		}
+	}
+
+	CloseCommunicationLcmPort();
+	return FAIL;
+}

BIN
EVSE/Projects/NoodoeDS/Apps/Module_PrimaryComm


+ 697 - 0
EVSE/Projects/NoodoeDS/Apps/Module_PrimaryComm.c

@@ -0,0 +1,697 @@
+#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/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 	<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
+#define EQUAL				0
+#define NORMAL				0
+#define	ABNORMAL			1
+
+typedef unsigned char 		byte;
+
+struct SysConfigAndInfo			*ShmSysConfigAndInfo;
+struct StatusCodeData 			*ShmStatusCodeData;
+struct PrimaryMcuData			*ShmPrimaryMcuData;
+struct MeterInformation			*ShmCsuMeterData;
+struct DcCommonInformation		*ShmDcCommonData;
+
+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);
+
+int Uart1Fd;
+char *priPortName = "/dev/ttyS1";
+Ver ver;
+Gpio_in gpio_in;
+Rtc rtc;
+
+struct timespec _flash_time;
+byte flash = NO;
+
+byte gun_count;
+
+byte _curDeviceStatus[3] = {0, 0, 0};
+byte _reCheckCount[3] = {0, 0, 0};
+
+struct ChargingInfoData *_chargingData[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
+
+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)
+
+int StoreLogMsg(const char *fmt, ...)
+{
+	char Buf[4096+256];
+	char buffer[4096];
+	va_list args;
+	struct timeb  SeqEndTime;
+	struct tm *tm;
+
+	va_start(args, fmt);
+	int rc = vsnprintf(buffer, sizeof(buffer), fmt, args);
+	va_end(args);
+
+	memset(Buf,0,sizeof(Buf));
+	ftime(&SeqEndTime);
+	SeqEndTime.time = time(NULL);
+	tm=localtime(&SeqEndTime.time);
+
+	if (ShmSysConfigAndInfo->SysConfig.SwitchDebugFlag == YES)
+	{
+		sprintf(Buf,"%02d:%02d:%02d:%03d - %s",
+			tm->tm_hour,tm->tm_min,tm->tm_sec,SeqEndTime.millitm, buffer);
+		printf("%s \n", Buf);
+	}
+	else
+	{
+		sprintf(Buf,"echo \"%04d-%02d-%02d %02d:%02d:%02d:%03d - %s\" >> /Storage/SystemLog/[%04d.%02d]SystemLog_%s",
+			tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,SeqEndTime.millitm,
+			buffer,
+			tm->tm_year+1900,tm->tm_mon+1,
+			ShmSysConfigAndInfo->SysConfig.SerialNumber);
+		system(Buf);
+	}
+
+	return rc;
+}
+
+int DiffTimeb(struct timeb ST, struct timeb ET)
+{
+	//return milli-second
+	unsigned int StartTime,StopTime;
+
+	StartTime=(unsigned int)ST.time;
+	StopTime=(unsigned int)ET.time;
+	return (StopTime-StartTime)*1000+ET.millitm-ST.millitm;
+}
+
+void PRINTF_FUNC(char *string, ...)
+{
+	va_list args;
+	char buffer[4096];
+	va_start(args, string);
+	vsnprintf(buffer, sizeof(buffer), string, args);
+	va_end(args);
+
+	DEBUG_INFO("%s ", 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);
+	}
+}
+
+//==========================================
+// Init all share memory
+//==========================================
+int InitShareMemory()
+{
+	int result = PASS;
+	int MeterSMId;
+
+	//creat ShmSysConfigAndInfo
+	if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo),  0777)) < 0)
+    {
+		#ifdef SystemLogMessage
+		DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
+		#endif
+		result = FAIL;
+	}
+    else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
+    {
+    	#ifdef SystemLogMessage
+    	DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
+		#endif
+    	result = FAIL;
+   	}
+
+   	//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;
+   	}
+
+	//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;
+	}
+
+	if ((MeterSMId = shmget(ShmCsuMeterKey, sizeof(struct MeterInformation), IPC_CREAT | 0777)) < 0)
+   	{
+   		#ifdef SystemLogMessage
+   		DEBUG_ERROR("shmget ShmCsuMeterKey NG \n");
+   		#endif
+   		result = FAIL;
+   	}
+   	else if ((ShmCsuMeterData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
+   	{
+   		#ifdef SystemLogMessage
+   		DEBUG_ERROR("shmat ShmCsuMeterData NG \n");
+   		#endif
+   		result = FAIL;
+   	}
+
+	if ((MeterSMId = shmget(ShmCommonKey, sizeof(struct DcCommonInformation), IPC_CREAT | 0777)) < 0)
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR("shmget ShmCommonKey NG \n");
+		#endif
+		result = FAIL;
+	}
+	else if ((ShmDcCommonData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR("shmat ShmCommonKey NG \n");
+		#endif
+		result = FAIL;
+	}
+
+    return result;
+}
+
+//================================================
+// Function
+//================================================
+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);
+	}
+}
+
+void GetInputGpioStatus()
+{
+	if (Query_Gpio_Input(Uart1Fd, Addr.IoExtend, &gpio_in) == PASS)
+	{
+		if (_curDeviceStatus[_PRIMARY_CHECK_TAG_AC_CONTACT] != gpio_in.AC_Connector ||
+				_curDeviceStatus[_PRIMARY_CHECK_TAG_AC_CONTACT] != ShmDcCommonData->psuKeepCommunication)
+		{
+			if (_reCheckCount[_PRIMARY_CHECK_TAG_AC_CONTACT] >= 3)
+			{
+				if (ShmPrimaryMcuData->InputDet.bits.EmergencyButton == NORMAL &&
+					ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuFailureAlarm == NORMAL &&
+					ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuComminicationErrWithCSU == NORMAL &&
+					ShmPrimaryMcuData->InputDet.bits.DoorOpen == NORMAL &&
+						(ShmDcCommonData->psuKeepCommunication == YES ||
+						gpio_in.AC_Connector == YES))
+				{
+					ShmSysConfigAndInfo->SysInfo.AcContactorStatus =
+						ShmPrimaryMcuData->InputDet.bits.AcContactorDetec = YES;
+
+					_curDeviceStatus[_PRIMARY_CHECK_TAG_AC_CONTACT] = YES;
+				}
+				else
+				{
+					ShmSysConfigAndInfo->SysInfo.AcContactorStatus =
+						ShmPrimaryMcuData->InputDet.bits.AcContactorDetec = NO;
+
+					_curDeviceStatus[_PRIMARY_CHECK_TAG_AC_CONTACT] = NO;
+				}
+			}
+			else
+				_reCheckCount[_PRIMARY_CHECK_TAG_AC_CONTACT]++;
+		}
+		else
+			_reCheckCount[_PRIMARY_CHECK_TAG_AC_CONTACT] = 0;
+
+		if (_reCheckCount[_PRIMARY_CHECK_TAG_AC_CONTACT] >= 3 &&
+				ShmDcCommonData->psuKeepCommunication == YES &&
+				gpio_in.AC_Connector == NO)
+		{
+			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.AcContactStestFail = YES;
+		}
+		else
+		{
+			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.AcContactStestFail = NO;
+		}
+		// -------------------------------------------------------------------
+		if (_curDeviceStatus[_PRIMARY_CHECK_TAG_MAIN_BREAKER] != gpio_in.AC_MainBreaker)
+		{
+			if (_reCheckCount[_PRIMARY_CHECK_TAG_MAIN_BREAKER] >= 3)
+			{
+				_curDeviceStatus[_PRIMARY_CHECK_TAG_MAIN_BREAKER] = gpio_in.AC_MainBreaker;
+				ShmPrimaryMcuData->InputDet.bits.AcMainBreakerDetec = gpio_in.AC_MainBreaker;
+			}
+			else
+				_reCheckCount[_PRIMARY_CHECK_TAG_MAIN_BREAKER]++;
+		}
+		else
+			_reCheckCount[_PRIMARY_CHECK_TAG_MAIN_BREAKER] = 0;
+
+		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 GetMeterConsumption(byte index)
+{
+	if (Query_Meter_value(Uart1Fd, Addr.IoExtend, &ShmCsuMeterData->_meter[index], &ShmCsuMeterData->isWorking, index) == PASS)
+	{
+		// meter value (Resolution) : 10
+		if (!ShmCsuMeterData->isWorking)
+		{
+			//ShmStatusCodeData->AlarmCode.AlarmEvents.bits.MeterCommTimeout = YES;
+			return;
+		}
+
+		if (ShmCsuMeterData->_meter[index].isCalculation == YES)
+		{
+//			printf("Meter%d, Comsumption = %.1f, curMeterValue = %.1f \n",
+//					index,
+//					ShmCsuMeterData->_meter[index].newMeterValue,
+//					ShmCsuMeterData->_meter[index].curMeterValue);
+
+			if (ShmCsuMeterData->_meter[index].curMeterValue == 0)
+				ShmCsuMeterData->_meter[index].curMeterValue = ShmCsuMeterData->_meter[index].newMeterValue;
+			else
+			{
+				// 最大充時,兩個都會累加,但只輸出給一槍使用
+				ShmCsuMeterData->_meter[index]._chargingValue += ShmCsuMeterData->_meter[index].newMeterValue - ShmCsuMeterData->_meter[index].curMeterValue;
+
+				if (ShmSysConfigAndInfo->SysInfo.MainChargingMode == _MAIN_CHARGING_MODE_MAX ||
+					(ShmSysConfigAndInfo->SysInfo.MainChargingMode == _MAIN_CHARGING_MODE_AVER &&
+					ShmSysConfigAndInfo->SysInfo.ReAssignedFlag >= _REASSIGNED_RELAY_A_TO_M))
+				{
+					for (byte subIndex = 0; subIndex < gun_count; subIndex++)
+					{
+						if (_chargingData[subIndex]->SystemStatus == SYS_MODE_CHARGING)
+						{
+							ShmCsuMeterData->_meter[subIndex]._curTotalCharging += ShmCsuMeterData->_meter[index].newMeterValue - ShmCsuMeterData->_meter[index].curMeterValue;
+							break;
+						}
+					}
+				}
+				else
+				{
+					ShmCsuMeterData->_meter[index]._curTotalCharging += ShmCsuMeterData->_meter[index].newMeterValue - ShmCsuMeterData->_meter[index].curMeterValue;
+				}
+
+				ShmCsuMeterData->_meter[index].curMeterValue = ShmCsuMeterData->_meter[index].newMeterValue;
+			}
+		}
+	}
+}
+
+void SetOutputGpio(byte flash)
+{
+	Gpio_out gpio;
+	// 藍燈
+	gpio.Button_LED[0] = flash;
+	// 綠燈
+	gpio.Button_LED[1] = flash;
+	//gpio.Button_LED[1] = 0x00;
+
+	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;
+
+	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[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[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[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");
+	}
+}
+
+void SetModelName()
+{
+	if (Config_Model_Name(Uart1Fd, Addr.IoExtend, ShmSysConfigAndInfo->SysConfig.ModelName) == PASS)
+	{
+	}
+}
+//================================================
+// Main process
+//================================================
+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 GetTimeoutValue(struct timespec *startTime)
+{
+	struct timespec endTime;
+
+	clock_gettime(CLOCK_MONOTONIC_COARSE, &endTime);
+	return endTime.tv_sec - startTime->tv_sec;
+}
+
+void GetTimespecFunc(struct timespec *time)
+{
+	clock_gettime(CLOCK_MONOTONIC_COARSE, time);
+}
+
+//================================================
+//================================================
+// CANBUS receive task
+//================================================
+//================================================
+bool FindChargingInfoData(byte target, struct ChargingInfoData **chargingData)
+{
+	for (byte index = 0; index < CHAdeMO_QUANTITY; index++)
+	{
+		if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == target)
+		{
+			chargingData[target] = &ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index];
+			return true;
+		}
+	}
+
+	for (byte index = 0; index < CCS_QUANTITY; index++)
+	{
+		if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == target)
+		{
+			chargingData[target] = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[index];
+			return true;
+		}
+	}
+
+	for (byte index = 0; index < GB_QUANTITY; index++)
+	{
+		if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == target)
+		{
+			chargingData[target] = &ShmSysConfigAndInfo->SysInfo.GbChargingData[index];
+			return true;
+		}
+	}
+
+	return false;
+}
+
+void Initialization()
+{
+	bool isPass = false;
+	while(!isPass)
+	{
+		isPass = true;
+		for (byte _index = 0; _index < gun_count; _index++)
+		{
+			if (!FindChargingInfoData(_index, &_chargingData[0]))
+			{
+				DEBUG_ERROR("EvComm (main) : FindChargingInfoData false \n");
+				isPass = false;
+				break;
+			}
+		}
+		sleep(1);
+	}
+}
+
+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();
+
+	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();
+	SetModelName();
+	GetTimespecFunc(&_flash_time);
+	gun_count = ShmSysConfigAndInfo->SysConfig.TotalConnectorCount;
+	Initialization();
+	byte _count = 0;
+
+	for(;;)
+	{
+		if (strcmp((char *)ShmSysConfigAndInfo->SysInfo.LcmHwRev, " ") == EQUAL)
+		{
+			if (GetTimeoutValue(&_flash_time) > 1)
+			{
+				if (flash == NO)
+					flash = YES;
+				else
+					flash = NO;
+				SetOutputGpio(flash);
+				GetTimespecFunc(&_flash_time);
+			}
+		}
+		else
+		{
+			if (GetTimeoutValue(&_flash_time) > 5)
+			{
+				if (flash == NO)
+					flash = YES;
+
+				SetOutputGpio(flash);
+				GetTimespecFunc(&_flash_time);
+			}
+		}
+
+		// 程序開始之前~ 必須先確定 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();
+
+			if(ShmSysConfigAndInfo->SysConfig.ModelName[3] == 'M' ||
+					ShmSysConfigAndInfo->SysConfig.ModelName[3] == 'L')
+			{
+				GetMeterConsumption(_count);
+				_count++;
+				if (_count >= gun_count)
+					_count = 0;
+			}
+		}
+
+		usleep(100000);
+	}
+
+	return FAIL;
+}
+
+
+
+

BIN
EVSE/Projects/NoodoeDS/Apps/Module_PsuComm


+ 2748 - 0
EVSE/Projects/NoodoeDS/Apps/Module_PsuComm.c

@@ -0,0 +1,2748 @@
+
+#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_COUNT		30
+#define DERATING_GAP		30
+#define ELEMENT_NOT_FIND	255
+#define CHK_VOL_RANGE		50
+#define CHK_CUR_RANGE		10
+#define DERATING_RANGE		100
+#define MIN_1A_CURRENT		10			// 該值須保持最小為 1A
+#define MIN_5V_VOLTAGE		50
+#define STOP_CURRENT		30
+#define PSU_MIN_CUR			1000
+#define PSU_MIN_VOL			1500
+#define PRE_CHARG_STEP_CUR	30
+#define PRE_CHARG_RANGE		50
+#define EQUAL				0
+#define CMD_DELAY_TIME 		25000
+#define LOG_VOL_GAP			50
+#define LOG_CUR_GAP			5
+#define PSU_MIN_OUTPUT_CUR	1
+#define SHUTDOWN_OUTPUT		0
+
+struct SysConfigAndInfo			*ShmSysConfigAndInfo;
+struct StatusCodeData 			*ShmStatusCodeData;
+struct PsuData 					*ShmPsuData;
+struct DcCommonInformation		*ShmDcCommonData;
+
+bool libInitialize = false;
+byte getAvailableCapOffset = 5;
+byte deratingKeepCount = 0;
+byte step3KeepCount = 0;
+byte psuCmdSeq = _PSU_CMD_CAP;
+
+byte startModuleFlag = false;
+
+float chargingOutputLogInfo[2][4];
+
+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)
+
+int GetTimeoutValue(struct timespec *startTime);
+
+long int GetTimeoutMValue(struct timespec *startTime)
+{
+	struct timespec endTime;
+
+	clock_gettime(CLOCK_MONOTONIC, &endTime);
+	return 1000 * (endTime.tv_sec - startTime->tv_sec) + (endTime.tv_nsec - startTime->tv_nsec) / 1000000;
+}
+
+void GetTimespecMFunc(struct timespec *time)
+{
+	clock_gettime(CLOCK_MONOTONIC, time);
+}
+
+int GetTimeoutValue(struct timespec *startTime)
+{
+	struct timespec endTime;
+
+	clock_gettime(CLOCK_MONOTONIC_COARSE, &endTime);
+	return endTime.tv_sec - startTime->tv_sec;
+}
+
+void GetTimespecFunc(struct timespec *time)
+{
+	clock_gettime(CLOCK_MONOTONIC_COARSE, time);
+}
+
+int StoreLogMsg(const char *fmt, ...)
+{
+	char Buf[4096+256];
+	char buffer[4096];
+	va_list args;
+	struct timeb  SeqEndTime;
+	struct tm *tm;
+
+	va_start(args, fmt);
+	int rc = vsnprintf(buffer, sizeof(buffer), fmt, args);
+	va_end(args);
+
+	memset(Buf,0,sizeof(Buf));
+	ftime(&SeqEndTime);
+	SeqEndTime.time = time(NULL);
+	tm=localtime(&SeqEndTime.time);
+
+	if (ShmSysConfigAndInfo->SysConfig.SwitchDebugFlag == YES)
+	{
+		sprintf(Buf,"%02d:%02d:%02d:%03d - %s",
+			tm->tm_hour,tm->tm_min,tm->tm_sec,SeqEndTime.millitm, buffer);
+		printf("%s \n", Buf);
+	}
+	else
+	{
+		sprintf(Buf,"echo \"%04d-%02d-%02d %02d:%02d:%02d:%03d - %s\" >> /Storage/SystemLog/[%04d.%02d]SystemLog_%s",
+			tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,SeqEndTime.millitm,
+			buffer,
+			tm->tm_year+1900,tm->tm_mon+1,
+			ShmSysConfigAndInfo->SysConfig.SerialNumber);
+		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);
+
+	DEBUG_INFO("%s ", 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(ShmDcCommonData->connector[0], ShmPsuData->PsuGroup[0].GroupPresentPsuQuantity, address, 0);
+
+		if (_group == ELEMENT_NOT_FIND)
+			_group = FindIndex(ShmDcCommonData->connector[1], ShmPsuData->PsuGroup[1].GroupPresentPsuQuantity, address, 1);
+	}
+
+	return _group;
+}
+
+byte FindRealAddr(byte group, byte address)
+{
+	byte _addr = 0;
+	byte index = 0;
+
+	if (group == 0)
+	{
+		while (index < ShmDcCommonData->conn_1_count)
+		{
+			if (ShmDcCommonData->connector[group][index] == address)
+			{
+				_addr = index;
+				break;
+			}
+			++index;
+		}
+	}
+	else if (group == 1)
+	{
+		while (index < ShmDcCommonData->conn_2_count)
+		{
+			if (ShmDcCommonData->connector [group][index] == address)
+			{
+				_addr = index;
+				break;
+			}
+			++ index;
+		}
+	}
+	return _addr;
+}
+
+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
+//=================================
+// 檢查 Byte 中某個 Bit 的值
+// _byte : 欲改變的 byte
+// _bit : 該 byte 的第幾個 bit
+int mask_table[] = {
+		0x00000001, 0x00000002, 0x00000004, 0x00000008,
+		0x00000010, 0x00000020, 0x00000040, 0x00000080,
+		0x00000100, 0x00000200, 0x00000400, 0x00000800,
+		0x00001000, 0x00002000, 0x00004000, 0x00008000,
+		0x00010000, 0x00020000, 0x00040000, 0x00080000,
+		0x00100000, 0x00200000, 0x00400000, 0x00800000,
+		0x01000000, 0x02000000, 0x04000000, 0x08000000,
+		0x10000000, 0x20000000, 0x40000000, 0x80000000
+};
+
+#define NONE_DEFINE_1					0
+#define NONE_DEFINE_2					1
+#define FUSE_BURN_OUT					2
+#define PFC_DC_COMM_FAIL				3
+#define NONE_DEFINE_3					4
+#define NONE_DEFINE_4					5
+#define UNBALANCE_POSI_NEGA_BUS_VOL		6
+#define BUS_OVER_VOL					7
+#define BUS_ABNORMAL_VOL				8
+#define PHASE_OVP						9
+#define ID_REPETITION					10
+#define BUS_UVP							11
+#define PHASE_LOSE						12
+#define NONE_DEFINE_5					13
+#define PHASE_UVP						14
+#define NONE_DEFINE_6					15
+#define CAN_COMM_FAULT					16
+#define DC_DC_UNEVEN_CUR_SHARING		17
+#define NONE_DEFINE_7					18
+#define PFC_POW_OFF						19
+#define NONE_DEFINE_8					20
+#define FULL_SPEED_OF_FAN				21
+#define DC_DC_POW_OFF					22
+#define MODULE_UNDER_POW_LIMIT			23
+#define TEMP_POW_LIMIT					24
+#define AC_POW_LIMIT					25
+#define DC_DC_EEPROM_FAULT				26
+#define FAN_FAULT						27
+#define DC_DC_SHORT_CIRCUIT				28
+#define PFC_EEPROM_FAULT				29
+#define DC_DC_OTP						30
+#define DC_DC_OVP						31
+
+unsigned char DetectBitValue(int _value, unsigned char _bit)
+{
+	return ( _value & mask_table[_bit] ) != 0x00;
+}
+
+bool AbnormalStopAnalysis(byte gun_index, int errCode)
+{
+	bool isErr = false;
+	for(byte count = 0; count < sizeof(mask_table)/sizeof(mask_table[0]); count++)
+	{
+		byte value = DetectBitValue(errCode, count);
+
+		if (value == 1)
+		{
+			switch(count)
+			{
+				case NONE_DEFINE_1 : {} break;
+				case NONE_DEFINE_2 : {} break;
+				case FUSE_BURN_OUT :
+				{
+					if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuFuseBurnOut == NO)
+					{
+						PRINTF_FUNC("PSU AbnormalStop : FUSE_BURN_OUT \n");
+						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuFuseBurnOut = YES;
+					}
+				} break;
+				case PFC_DC_COMM_FAIL :
+				{
+					if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuPfcAndDcdcCommFault == NO)
+					{
+						PRINTF_FUNC ( "PSU AbnormalStop : PFC_DC_COMM_FAIL \n" );
+						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuPfcAndDcdcCommFault = YES;
+					}
+				} break;
+				case NONE_DEFINE_3 : {} break;
+				case NONE_DEFINE_4 : {} break;
+				case UNBALANCE_POSI_NEGA_BUS_VOL :
+				{
+					if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuBusVoltageUnbalance == NO)
+					{
+						PRINTF_FUNC ( "PSU AbnormalStop : UNBALANCE_POSI_NEGA_BUS_VOL \n" );
+						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuBusVoltageUnbalance = YES;
+					}
+				} break;
+				case BUS_OVER_VOL :
+				{
+					if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuBusOverVoltage == NO)
+					{
+						PRINTF_FUNC ( "PSU AbnormalStop : BUS_OVER_VOL \n" );
+						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuBusOverVoltage = YES;
+					}
+				} break;
+				case BUS_ABNORMAL_VOL :
+				{
+					if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuBusVoltageAbnormal == NO)
+					{
+						PRINTF_FUNC ( "PSU AbnormalStop : BUS_ABNORMAL_VOL \n" );
+						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuBusVoltageAbnormal = YES;
+					}
+				} break;
+				case PHASE_OVP :
+				{
+					if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DcInputOVP == NO)
+					{
+						PRINTF_FUNC ( "PSU AbnormalStop : PHASE_OVP \n" );
+						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DcInputOVP = YES;
+					}
+				} break;
+				case ID_REPETITION :
+				{
+					isErr = true;
+					if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuIdRepeat == NO)
+					{
+						PRINTF_FUNC ( "PSU AbnormalStop : ID_REPETITION \n" );
+						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuIdRepeat = YES;
+					}
+				} break;
+				case BUS_UVP :
+				{
+					if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuBusUnderVoltage == NO)
+					{
+						PRINTF_FUNC ( "PSU AbnormalStop : BUS_UVP \n" );
+						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuBusUnderVoltage = YES;
+					}
+				} break;
+				case PHASE_LOSE :
+				{
+					if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuInputPhaseLoss == NO)
+					{
+						PRINTF_FUNC ( "PSU AbnormalStop : PHASE_LOSE \n" );
+						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuInputPhaseLoss = YES;
+					}
+				} break;
+				case NONE_DEFINE_5 : {} break;
+				case PHASE_UVP :
+				{
+					if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DcInputUVP == NO)
+					{
+						PRINTF_FUNC ( "PSU AbnormalStop : PHASE_UVP \n" );
+						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DcInputUVP = YES;
+					}
+				} break;
+				case NONE_DEFINE_6 : {} break;
+				case CAN_COMM_FAULT :
+				{
+					if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuCanCommFault == NO)
+					{
+						PRINTF_FUNC ( "PSU AbnormalStop : CAN_COMM_FAULT \n" );
+						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuCanCommFault = YES;
+					}
+				} break;
+				case DC_DC_UNEVEN_CUR_SHARING :
+				{
+					if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuSevereUnevenCurrent == NO)
+					{
+						PRINTF_FUNC ( "PSU AbnormalStop : DC_DC_UNEVEN_CUR_SHARING \n" );
+						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuSevereUnevenCurrent = YES;
+					}
+				} break;
+				case NONE_DEFINE_7 : {} break;
+				case PFC_POW_OFF :
+				{
+					//if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuPfcPowOff == NO)
+					{
+						//PRINTF_FUNC ( "PSU AbnormalStop : PFC_POW_OFF \n" );
+						//ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuPfcPowOff = YES;
+					}
+				} break;
+				case NONE_DEFINE_8 : {} break;
+				case FULL_SPEED_OF_FAN :
+				{
+					if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuFanFullSpeed == NO)
+					{
+						PRINTF_FUNC ( "PSU AbnormalStop : FULL_SPEED_OF_FAN \n" );
+						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuFanFullSpeed = YES;
+					}
+				} break;
+				case DC_DC_POW_OFF :
+				{
+					//if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuDcDcPowOff == NO)
+					{
+						//PRINTF_FUNC ( "PSU AbnormalStop : DC_DC_POW_OFF \n" );
+						//ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuDcDcPowOff = YES;
+					}
+				} break;
+				case MODULE_UNDER_POW_LIMIT :
+				{
+					if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuPowerLimitedState == NO)
+					{
+						PRINTF_FUNC("PSU AbnormalStop : MODULE_UNDER_POW_LIMIT \n");
+						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuPowerLimitedState = YES;
+					}
+				} break;
+				case TEMP_POW_LIMIT :
+				{
+					if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuTemperaturePowerLimit == NO)
+					{
+						PRINTF_FUNC ( "PSU AbnormalStop : TEMP_POW_LIMIT \n" );
+						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuTemperaturePowerLimit = YES;
+					}
+				} break;
+				case AC_POW_LIMIT :
+				{
+					if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuAcPowerLimit == NO)
+					{
+						PRINTF_FUNC ( "PSU AbnormalStop : AC_POW_LIMIT \n" );
+						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuAcPowerLimit = YES;
+					}
+				} break;
+				case DC_DC_EEPROM_FAULT :
+				{
+					if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuDcdcEepromFault == NO)
+					{
+						PRINTF_FUNC ( "PSU AbnormalStop : DC_DC_EEPROM_FAULT \n" );
+						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuDcdcEepromFault = YES;
+					}
+				} break;
+				case FAN_FAULT :
+				{
+					isErr = true;
+					if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuFanFailureAlarm == NO)
+					{
+						PRINTF_FUNC ( "PSU AbnormalStop : FAN_FAULT \n" );
+						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuFanFailureAlarm = YES;
+					}
+				} break;
+				case DC_DC_SHORT_CIRCUIT :
+				{
+					isErr = true;
+					if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuOutputShortCircuit == NO)
+					{
+						PRINTF_FUNC ( "PSU AbnormalStop : DC_DC_SHORT_CIRCUIT \n" );
+						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuOutputShortCircuit = YES;
+					}
+				} break;
+				case PFC_EEPROM_FAULT :
+				{
+					if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuPfcEepromFault == NO)
+					{
+						PRINTF_FUNC ( "PSU AbnormalStop : PFC_EEPROM_FAULT \n" );
+						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuPfcEepromFault = YES;
+					}
+				} break;
+				case DC_DC_OTP :
+				{
+					if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuDcDcOtp == NO)
+					{
+						PRINTF_FUNC ( "PSU AbnormalStop : DC_DC_OTP \n" );
+						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuDcDcOtp = YES;
+					}
+				} break;
+				case DC_DC_OVP :
+				{
+					isErr = true;
+					if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuDcDcOvp == NO)
+					{
+						PRINTF_FUNC ( "PSU AbnormalStop : DC_DC_OVP \n" );
+						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuDcDcOvp = YES;
+					}
+				} break;
+			}
+		}
+		else if (value == 0)
+		{
+			switch(count)
+			{
+				case NONE_DEFINE_1 : {} break;
+				case NONE_DEFINE_2 : {} break;
+				case FUSE_BURN_OUT :
+				{
+					if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuFuseBurnOut == YES)
+					{
+						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuFuseBurnOut = NO;
+					}
+				} break;
+				case PFC_DC_COMM_FAIL :
+				{
+					if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuPfcAndDcdcCommFault == YES)
+					{
+						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuPfcAndDcdcCommFault = NO;
+					}
+				} break;
+				case NONE_DEFINE_3 : {} break;
+				case NONE_DEFINE_4 : {} break;
+				case UNBALANCE_POSI_NEGA_BUS_VOL :
+				{
+					if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuBusVoltageUnbalance == YES)
+					{
+						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuBusVoltageUnbalance = NO;
+					}
+				} break;
+				case BUS_OVER_VOL :
+				{
+					if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuBusOverVoltage == YES)
+					{
+						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuBusOverVoltage = NO;
+					}
+				} break;
+				case BUS_ABNORMAL_VOL :
+				{
+					if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuBusVoltageAbnormal == YES)
+					{
+						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuBusVoltageAbnormal = NO;
+					}
+				} break;
+				case PHASE_OVP :
+				{
+					if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DcInputOVP == YES)
+					{
+						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DcInputOVP = NO;
+					}
+				} break;
+				case ID_REPETITION :
+				{
+					if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuIdRepeat == YES)
+					{
+						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuIdRepeat = NO;
+					}
+				} break;
+				case BUS_UVP :
+				{
+					if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuBusUnderVoltage == YES)
+					{
+						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuBusUnderVoltage = NO;
+					}
+				} break;
+				case PHASE_LOSE :
+				{
+					if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuInputPhaseLoss == YES)
+					{
+						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuInputPhaseLoss = NO;
+					}
+				} break;
+				case NONE_DEFINE_5 : {} break;
+				case PHASE_UVP :
+				{
+					if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DcInputUVP == YES)
+					{
+						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DcInputUVP = NO;
+					}
+				} break;
+				case NONE_DEFINE_6 : {} break;
+				case CAN_COMM_FAULT :
+				{
+					if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuCanCommFault == YES)
+					{
+						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuCanCommFault = NO;
+					}
+				} break;
+				case DC_DC_UNEVEN_CUR_SHARING :
+				{
+					if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuSevereUnevenCurrent == YES)
+					{
+						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuSevereUnevenCurrent = NO;
+					}
+				} break;
+				case NONE_DEFINE_7 : {} break;
+				case PFC_POW_OFF :
+				{
+					if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuFfcSideShutDown == YES)
+					{
+						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuFfcSideShutDown = NO;
+					}
+				} break;
+				case NONE_DEFINE_8 : {} break;
+				case FULL_SPEED_OF_FAN :
+				{
+					if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuFanFullSpeed == YES)
+					{
+						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuFanFullSpeed = NO;
+					}
+				} break;
+				case DC_DC_POW_OFF :
+				{
+					if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuDcSideShutDown == YES)
+					{
+						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuDcSideShutDown = NO;
+					}
+				} break;
+				case MODULE_UNDER_POW_LIMIT :
+				{
+					if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuPowerLimitedState == YES)
+					{
+						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuPowerLimitedState = NO;
+					}
+				} break;
+				case TEMP_POW_LIMIT :
+				{
+					if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuTemperaturePowerLimit == YES)
+					{
+						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuTemperaturePowerLimit = NO;
+					}
+				} break;
+				case AC_POW_LIMIT :
+				{
+					if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuAcPowerLimit == YES)
+					{
+						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuAcPowerLimit = NO;
+					}
+				} break;
+				case DC_DC_EEPROM_FAULT :
+				{
+					if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuDcdcEepromFault == YES)
+					{
+						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuDcdcEepromFault = NO;
+					}
+				} break;
+				case FAN_FAULT :
+				{
+					if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuFanFailureAlarm == YES)
+					{
+						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuFanFailureAlarm = NO;
+					}
+				} break;
+				case DC_DC_SHORT_CIRCUIT :
+				{
+					if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuOutputShortCircuit == YES)
+					{
+						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuOutputShortCircuit = NO;
+					}
+				} break;
+				case PFC_EEPROM_FAULT :
+				{
+					if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuPfcEepromFault == YES)
+					{
+						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuPfcEepromFault = NO;
+					}
+				} break;
+				case DC_DC_OTP :
+				{
+					if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuDcDcOtp == YES)
+					{
+						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuDcDcOtp = NO;
+					}
+				} break;
+				case DC_DC_OVP :
+				{
+					if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuDcDcOvp == YES)
+					{
+						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuDcDcOvp = NO;
+					}
+				} break;
+			}
+		}
+	}
+
+	return isErr;
+}
+
+//=================================
+// Callback Function
+//=================================
+// no using -- GetOutputAndTempCallback
+void GetStatusCallback(byte group, byte SN, byte temp, int alarm)
+{
+	bool isFind = false;
+	bool isComp = false;
+
+	if ((ShmDcCommonData->conn_1_count + ShmDcCommonData->conn_2_count) != ShmPsuData->SystemPresentPsuQuantity)
+	{
+		if (group == 0)
+		{
+			for(byte psuIndex = 0; psuIndex < ShmDcCommonData->conn_1_count; psuIndex++)
+			{
+				if (ShmDcCommonData->connector[0][psuIndex] == SN)
+				{
+					isFind = true;
+					break;
+				}
+			}
+
+			if(!isFind)
+			{
+				ShmDcCommonData->connector[0][ShmDcCommonData->conn_1_count] = SN;
+				ShmDcCommonData->conn_1_count++;
+			}
+		}
+		else if (group == 1)
+		{
+			for(byte psuIndex = 0; psuIndex < ShmDcCommonData->conn_2_count; psuIndex++)
+			{
+				if (ShmDcCommonData->connector[1][psuIndex] == SN)
+				{
+					isFind = true;
+					break;
+				}
+			}
+
+			if(!isFind)
+			{
+				ShmDcCommonData->connector[1][ShmDcCommonData->conn_2_count] = SN;
+				ShmDcCommonData->conn_2_count++;
+			}
+		}
+	}
+	else
+	{
+		isComp = true;
+	}
+
+	if ((ShmDcCommonData->conn_1_count + ShmDcCommonData->conn_2_count) == ShmPsuData->SystemPresentPsuQuantity)
+	{
+		// Arrangment
+//		for(byte psuIndex = 0; psuIndex < ShmDcCommonData->conn_1_count; psuIndex++)
+//		{
+//			ShmDcCommonData->connector[0][psuIndex] = psuIndex;
+//		}
+//
+//		for(byte psuIndex = 0; psuIndex < ShmDcCommonData->conn_2_count; psuIndex++)
+//		{
+//			ShmDcCommonData->connector[1][psuIndex] = ShmDcCommonData->conn_1_count + psuIndex;
+//		}
+		if (!isComp)
+		{
+			for(byte psuIndex = 0; psuIndex < ShmDcCommonData->conn_1_count; psuIndex++)
+				PRINTF_FUNC("DC Left Gun - PSU Number = %d \n", ShmDcCommonData->connector[0][psuIndex]);
+
+			for(byte psuIndex = 0; psuIndex < ShmDcCommonData->conn_2_count; psuIndex++)
+				PRINTF_FUNC("DC Right Gun - PSU Number = %d \n", ShmDcCommonData->connector[1][psuIndex]);
+		}
+
+		if (ShmSysConfigAndInfo->SysConfig.TotalConnectorCount > 1 &&
+				ShmDcCommonData->chargerType == CHARGER_TYPE_STANDARD)
+		{
+			// 雙槍才需要考慮是否模塊 switch 撥錯了
+			char EvsePower[2];
+			byte maxCount = 0;
+			int power = 0;
+
+			EvsePower[2] = '\0';
+			if (strlen((char *) ShmSysConfigAndInfo->SysConfig.ModelName) >= 6)
+			{
+				strncpy(EvsePower, (char *)(ShmSysConfigAndInfo->SysConfig.ModelName + 4), 2);
+				power = atoi(EvsePower);
+			}
+
+			// 超過 90 KW 或 360 KW
+			if (power < 30 || power == 36)
+				power *= 10;
+
+			maxCount = ((power / 30) + 1) / 2;
+
+			if (ShmDcCommonData->conn_1_count > maxCount ||
+					ShmDcCommonData->conn_2_count > maxCount)
+			{
+				ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuDipSwitchStestFail = YES;
+			}
+		}
+	}
+}
+// no using -- GetOutputAndTempCallback End
+
+void GetModuleCountCallback(byte group, byte count)
+{
+	if (group == SYSTEM_CMD)
+		ShmPsuData->SystemPresentPsuQuantity = count;
+	else
+	{
+		if (group >= ShmSysConfigAndInfo->SysConfig.TotalConnectorCount)
+			return;
+
+		ShmPsuData->PsuGroup[group].GroupPresentPsuQuantity = count;
+	}
+}
+
+void GetMaxPowerAndCur(unsigned char mode, int ratingCur, int *pow, int *cur)
+{
+	if (ShmPsuData->Work_Step < GET_SYS_CAP)
+		return;
+
+	unsigned short maxCurrent = ShmPsuData->SystemAvailableCurrent;
+	unsigned short maxPower = ShmPsuData->SystemAvailablePower;
+
+	if (ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent * 10 != 0 &&
+			ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent * 10 < maxCurrent)
+		maxCurrent = ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent * 10;
+
+	if (ShmSysConfigAndInfo->SysConfig.MaxChargingPower * 10 != 0 &&
+			ShmSysConfigAndInfo->SysConfig.MaxChargingPower * 10 < maxPower)
+		maxPower = ShmSysConfigAndInfo->SysConfig.MaxChargingPower * 10;
+
+	if (mode == _MAIN_CHARGING_MODE_AVER)
+	{
+		maxCurrent /= 2;
+		maxPower /= 2;
+	}
+
+	if (ShmSysConfigAndInfo->SysInfo.MaxChargingProfilePower >= 0 &&
+			maxPower > ShmSysConfigAndInfo->SysInfo.MaxChargingProfilePower)
+		maxPower = ShmSysConfigAndInfo->SysInfo.MaxChargingProfilePower;
+
+	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)
+{
+	if (ShmPsuData->Work_Step < GET_SYS_CAP)
+		return;
+
+	int _groupPower = 0, _groupCurrent = 0;
+	byte group = FindTargetGroup(address);
+	byte addr = FindRealAddr(group, address);
+	float _chargingVol = 0, _targetVol = 0;
+
+//	if (group == 1)
+//		address -= ShmPsuData->PsuGroup[group - 1].GroupPresentPsuQuantity;
+
+	if (ShmSysConfigAndInfo->SysInfo.MainChargingMode == _MAIN_CHARGING_MODE_MAX)
+	{
+		for (byte groupIndex = 0; groupIndex < _gunCount; groupIndex++)
+		{
+			if (chargingInfo[groupIndex]->EvBatteryMaxVoltage > 0)
+			{
+				_chargingVol = chargingInfo[groupIndex]->EvBatteryMaxVoltage;
+				_targetVol = chargingInfo[groupIndex]->EvBatterytargetVoltage;
+				break;
+			}
+		}
+	}
+
+	if (chargingInfo[group]->DeratingChargingCurrent == 0)
+	{
+		// 在還沒取得真正可輸出的電流前,依照 GFD 階段得到的真正 POWER / 模塊個數 / 車子電池最大電壓
+		if (ShmPsuData->PsuGroup[group].GroupRealOutputPower > 0 && _chargingVol > 0)
+		{
+			ShmPsuData->PsuGroup[group].PsuModule[addr].AvailableCurrent =
+					((ShmPsuData->PsuGroup[group].GroupRealOutputPower / ShmPsuData->PsuGroup[group].GroupPresentPsuQuantity) * 1000 / (int)_chargingVol) * 10;
+		}
+		else
+		{
+			// 注一 : 獲取模塊最大輸出能力 (忽視 Derating 狀態),所以這邊需要限制實際可輸出的電流
+			if (ShmPsuData->PsuGroup[group].PsuModule[addr].AvailableCurrent <= 0)
+				ShmPsuData->PsuGroup[group].PsuModule[addr].AvailableCurrent = PSU_MIN_CUR;
+		}
+	}
+	else
+	{
+		ShmPsuData->PsuGroup[group].PsuModule[addr].AvailableCurrent = maxCur;
+	}
+
+	ShmPsuData->PsuGroup[group].PsuModule[addr].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;
+	}
+
+	// 各群得到最大輸出能力 (電流、Power)
+	ShmPsuData->PsuGroup[group].GroupAvailableCurrent = _groupCurrent;
+	ShmPsuData->PsuGroup[group].GroupAvailablePower = _groupPower;
+
+	if (chargingInfo[group]->MaximumChargingVoltage != maxVol)
+	{
+		PRINTF_FUNC("G_%d -> Max Vol = %d \n", group, maxVol / 10);
+		chargingInfo[group]->MaximumChargingVoltage = maxVol;
+	}
+
+	int _power = 0, _current = 0, _ratingcurrent = 0, _sysRealPower = 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;
+		_sysRealPower += ShmPsuData->PsuGroup[index].GroupRealOutputPower;
+		if (ShmPsuData->PsuGroup[index].GroupPresentOutputVoltage >= PSU_MIN_VOL &&
+				chargingInfo[index]->DeratingChargingCurrent == 0)
+			isGetAllDeratingCurrent = false;
+	}
+
+	// 如果不是所有群都得到 Derating current,則先不採樣該次的 ratingCurrent
+	if (!isGetAllDeratingCurrent) _ratingcurrent = 0;
+	// 因應注一,為避免一值改變通知車子電樁最大可輸出電流所做的限制
+	// 而因為 rating value 一般都會小於模塊的最大可輸出電流
+	// 所以如果該值大於在注一所限制的輸出電流,則以此值為主
+	if (_ratingcurrent != 0) _current = _ratingcurrent;
+
+	if (ShmSysConfigAndInfo->SysInfo.BootingStatus == BOOTTING)
+	{
+		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;
+		int gpRealPow = ShmPsuData->PsuGroup[group].GroupRealOutputPower;
+
+		if ((ShmSysConfigAndInfo->SysInfo.ReAssignedFlag >= _REASSIGNED_GET_NEW_CAP &&
+				ShmSysConfigAndInfo->SysInfo.ReAssignedFlag <= _REASSIGNED_RELAY_M_TO_A))
+		{
+			if (chargingInfo[group]->DividChargingCurrent == 0)
+				return;
+			else
+			{
+				halfCur = chargingInfo[group]->DividChargingCurrent;
+				ratingCur = 0;
+			}
+		}
+
+		GetMaxPowerAndCur(_MAIN_CHARGING_MODE_AVER, ratingCur, &halfPow, &halfCur);
+
+		{
+			// 以下狀況 -> 槍資訊中的最大輸出能力,為該群的輸出能力
+			// 1. 如不是最大充
+			// 2. 智能切換成均充過程
+			chargingInfo[group]->AvailableChargingCurrent =	halfCur;
+			chargingInfo[group]->AvailableChargingPower = halfPow;
+			chargingInfo[group]->RealRatingPower = gpRealPow;
+
+			if(chargingInfo[group]->DeratingChargingCurrent > 0)
+			{
+				unsigned short _powBuf = 0;
+				_powBuf = ((chargingInfo[group]->DeratingChargingCurrent / 10) * ShmPsuData->PsuGroup[group].GroupPresentOutputVoltage / 10) / 1000; // 單位是 KW
+
+				if (_powBuf > ShmPsuData->PsuGroup[group].GroupRealOutputPower ||
+						chargingInfo[group]->EvBatterytargetVoltage > 0)
+				{
+					ShmPsuData->PsuGroup[group].GroupRealOutputPower = _powBuf;
+				}
+			}
+		}
+	}
+	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;
+				chargingInfo[count]->RealRatingPower = _sysRealPower;
+			}
+		}
+		else
+		{
+			// 如果是最大充,該槍資訊中的輸出能力為各群輸出能力的和
+			chargingInfo[group]->AvailableChargingCurrent =	_current;
+			chargingInfo[group]->AvailableChargingPower = _power;
+			chargingInfo[group]->RealRatingPower = _sysRealPower;
+		}
+
+		if(chargingInfo[group]->DeratingChargingCurrent > 0)
+		{
+			unsigned short _powBuf = 0;
+			_powBuf = ((chargingInfo[group]->DeratingChargingCurrent / 10) * ShmPsuData->PsuGroup[group].GroupPresentOutputVoltage / 10) / 1000; // 單位是 KW
+
+			if (_powBuf > ShmPsuData->PsuGroup[group].GroupRealOutputPower ||
+					chargingInfo[group]->EvBatterytargetVoltage > 0 ||
+					_targetVol > 0)
+			{
+				ShmPsuData->PsuGroup[group].GroupRealOutputPower = _powBuf;
+			}
+		}
+	}
+}
+
+void GetFwCallback(byte address, short dcSwVer, short pfcSwVer, short hwVer)
+{
+	if (ShmPsuData->Work_Step < GET_SYS_CAP)
+		return;
+
+	if (IsOverModuleCount(address))
+		return;
+
+	byte group = FindTargetGroup(address);
+	byte addr = FindRealAddr(group, 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[addr].FwVersion, "DC %d.%02d", (dcSwVer & 0xFF00) >> 8, dcSwVer & 0xFF);
+	//DEBUG_INFO("fw Ver. = %s \n", ShmPsuData->PsuGroup[group].PsuModule[address].FwVersion);
+}
+
+// no using -- GetInputVoltageCallback
+void GetInputVoltageCallback(byte address, unsigned short vol1, unsigned short vol2, unsigned short vol3)
+{
+//	if (ShmPsuData->Work_Step < GET_SYS_CAP)
+//		return;
+//
+//	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;
+//
+//	PRINTF_FUNC("***Input*** address = %d, R = %d, S = %d, T = %d, gp = %d \n",
+//				address, vol1, vol2, vol3, group);
+}
+// no using -- GetInputVoltageCallback End
+
+// no using -- GetOutputAndTempCallback
+void GetPresentOutputCallback(byte group, unsigned short outVol, unsigned short outCur)
+{
+//	if (ShmPsuData->Work_Step < GET_SYS_CAP)
+//		return;
+
+	//if (outCur != ShmPsuData->PsuGroup[group].GroupPresentOutputCurrent)
+	//{
+	//	PRINTF_FUNC("Gp_%d, gp output cur = %d \n", group, outCur);
+	//}
+
+//	// PSU Group - 電壓
+//	ShmPsuData->PsuGroup[group].GroupPresentOutputVoltage = outVol;
+//	// PSU Group - 電流
+//	ShmPsuData->PsuGroup[group].GroupPresentOutputCurrent = outCur;
+//
+//	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))
+//		)
+//	{
+//		unsigned short outputVol = 0;
+//		unsigned short outputCur = 0;
+//
+//		for (byte index = 0; index < ShmPsuData->GroupCount; index++)
+//		{
+//			bool needtoAdd = true;
+//
+//			if (ShmPsuData->PsuGroup[index].GroupPresentOutputVoltage > outputVol)
+//				outputVol = ShmPsuData->PsuGroup[index].GroupPresentOutputVoltage;
+//
+//			if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag >= _REASSIGNED_ADJUST_M_TO_A &&
+//					ShmSysConfigAndInfo->SysInfo.ReAssignedFlag <= _REASSIGNED_RELAY_M_TO_A)
+//			{
+////				PRINTF_FUNC("Gp_%d, DividChargingCurrent = %d \n", index,
+////						chargingInfo[index]->DividChargingCurrent);
+//				if (chargingInfo[index]->DividChargingCurrent == 0)
+//					needtoAdd = false;
+//			}
+//
+//			if (needtoAdd)
+//				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 >= SYS_MODE_PREPARE_FOR_EVSE && chargingInfo[group]->SystemStatus <= SYS_MODE_COMPLETE) ||
+//			(chargingInfo[group]->SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0 && chargingInfo[group]->SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))
+//		{
+//			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, PresentChargingVoltage = %f, PresentChargingCurrent = %f \n", group,
+//			chargingInfo[group]->PresentChargingVoltage,
+//			chargingInfo[group]->PresentChargingCurrent);
+}
+// no using -- GetOutputAndTempCallback End
+
+void GetMisCallback(byte address, unsigned int value, byte type)
+{
+	if (ShmPsuData->Work_Step < GET_SYS_CAP)
+		return;
+
+	if (IsOverModuleCount(address))
+		return;
+
+	byte group = FindTargetGroup(address);
+	byte addr = FindRealAddr(group, address);
+//	if (group == 1)
+//		address -= ShmPsuData->PsuGroup[group - 1].GroupPresentPsuQuantity;
+
+	if (type == 1)
+	{
+		ShmPsuData->PsuGroup[group].PsuModule[addr].FanSpeed_1 = value;
+		ShmPsuData->PsuGroup[group].PsuModule[addr].FanSpeed_2 = value;
+		ShmPsuData->PsuGroup[group].PsuModule[addr].FanSpeed_3 = value;
+		ShmPsuData->PsuGroup[group].PsuModule[addr].FanSpeed_4 = value;
+	}
+	else if (type == 2)
+	{
+		//printf("DC - group = %d, index = %d, value = %d \n", group, address, value);
+//		ShmPsuData->PsuGroup[group].PsuModule[addr].CriticalTemp1 = value;
+//		ShmPsuData->PsuGroup[group].PsuModule[addr].CriticalTemp2 = value;
+//		ShmPsuData->PsuGroup[group].PsuModule[addr].CriticalTemp3 = value;
+		ShmPsuData->PsuGroup[group].PsuModule[addr].ExletTemp = value;
+	}
+	else if (type == 3)
+	{
+		printf("PFC - group = %d, index = %d, value = %d \n", group, address, value);
+	}
+}
+
+void GetIavailableCallback(byte address, unsigned short Iavail, unsigned short Vext)
+{
+	if (ShmPsuData->Work_Step < GET_SYS_CAP)
+		return;
+
+	if (IsOverModuleCount(address))
+		return;
+
+	// 經度 0.1
+	byte group = FindTargetGroup(address);
+	byte addr = FindRealAddr(group, address);
+//	if (group == 1)
+//		address -= ShmPsuData->PsuGroup[group - 1].GroupPresentPsuQuantity;
+
+	ShmPsuData->PsuGroup[group].PsuModule[addr].IAvailableCurrent = Iavail;
+
+	bool isPass = true;
+	int totalCur = 0;
+	byte sampleCount = 8;
+
+	if (Iavail == 0)
+	{
+		for (byte count = 0; count < sampleCount; 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 < sampleCount; 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)
+	{
+		chargingInfo[group]->DeratingChargingCurrent = totalCur;
+	}
+}
+
+void GetPresentOutputFCallback(byte group, float outVol, float outCur)
+{
+	// isinf : -1 = 負無窮,1 = 正無窮,0 = 其他
+	if (isinf(outVol) == 0)
+		ShmPsuData->PsuGroup[group].GroupPresentOutputVoltage = (unsigned short)(outVol * 10);
+	else
+		ShmPsuData->PsuGroup[group].GroupPresentOutputVoltage = 0;
+
+	if (isinf(outCur) == 0)
+		ShmPsuData->PsuGroup[group].GroupPresentOutputCurrent = (unsigned short)(outCur * 10);
+	else
+		ShmPsuData->PsuGroup[group].GroupPresentOutputCurrent = 0;
+
+	//printf("group = %d, Current = %d \n", group, ShmPsuData->PsuGroup[group].GroupPresentOutputCurrent);
+
+	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))
+			)
+		{
+			unsigned short outputVol = 0;
+			unsigned short outputCur = 0;
+			unsigned char _maxTOaver = 0;
+
+			for (byte index = 0; index < ShmPsuData->GroupCount; index++)
+			{
+				bool needtoAdd = true;
+
+				if (ShmPsuData->PsuGroup[index].GroupPresentOutputVoltage > outputVol)
+					outputVol = ShmPsuData->PsuGroup[index].GroupPresentOutputVoltage;
+
+				if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag >= _REASSIGNED_ADJUST_M_TO_A &&
+						ShmSysConfigAndInfo->SysInfo.ReAssignedFlag <= _REASSIGNED_RELAY_M_TO_A)
+				{
+					if (chargingInfo[index]->DividChargingCurrent == 0)
+						needtoAdd = false;
+					else
+						_maxTOaver = index;
+				}
+
+				if (needtoAdd)
+					outputCur += ShmPsuData->PsuGroup[index].GroupPresentOutputCurrent;
+			}
+
+			if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag >= _REASSIGNED_ADJUST_M_TO_A &&
+					ShmSysConfigAndInfo->SysInfo.ReAssignedFlag <= _REASSIGNED_RELAY_M_TO_A)
+			{
+				if (chargingInfo[_maxTOaver]->DividChargingCurrent != 0)
+				{
+					float _cur_buf = outputCur;
+					_cur_buf /= 10;
+					chargingInfo[_maxTOaver]->PresentChargingCurrent = _cur_buf;
+				}
+			}
+
+			// 黑白機
+			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;
+
+					_cur_buf /= 10;
+					chargingInfo[count]->PresentChargingCurrent = _cur_buf;
+				}
+			}
+
+			if ((chargingInfo[group]->SystemStatus >= SYS_MODE_PREPARE_FOR_EVSE && chargingInfo[group]->SystemStatus <= SYS_MODE_COMPLETE) ||
+					(chargingInfo[group]->SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0 && chargingInfo[group]->SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) ||
+					chargingInfo[group]->SystemStatus == SYS_MODE_ALARM)
+			{
+				float _vol_buf = outputVol;
+				float _cur_buf = outputCur;
+
+				// EVSE - 電壓
+				_vol_buf /= 10;
+				chargingInfo[group]->PresentChargingVoltage = _vol_buf;
+
+				if (chargingInfo[group]->SystemStatus == SYS_MODE_COMPLETE ||
+						chargingInfo[group]->SystemStatus == SYS_MODE_ALARM)
+				{
+					chargingInfo[group]->PresentChargingCurrent = 0;
+				}
+				else
+				{
+					_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;
+
+			_cur_buf /= 10;
+			chargingInfo[group]->PresentChargingCurrent = _cur_buf;
+		}
+}
+
+//==========================================
+// 特規用指令
+//==========================================
+void GetOutputAndTempCallback(byte address, unsigned short outputVol_s,
+		unsigned short outputCur_s, unsigned short outputPower, unsigned char Temperature)
+{
+	if (ShmPsuData->Work_Step < GET_SYS_CAP)
+		return;
+
+	if (IsOverModuleCount(address))
+		return;
+
+	byte group = FindTargetGroup(address);
+	byte addr = FindRealAddr(group, address);
+//	if (group == 1)
+//		address -= ShmPsuData->PsuGroup[group - 1].GroupPresentPsuQuantity;
+
+	ShmPsuData->PsuGroup[group].PsuModule[addr].CriticalTemp1 = Temperature;
+	ShmPsuData->PsuGroup[group].PsuModule[addr].CriticalTemp2 = Temperature;
+	ShmPsuData->PsuGroup[group].PsuModule[addr].CriticalTemp3 = Temperature;
+//	ShmPsuData->PsuGroup[group].PsuModule[address].ExletTemp = Temperature;
+
+//	PRINTF_FUNC("***Output Value and Temp*** group = %d, Vol = %d, Cur = %d \n",
+//			group, outputVol_s, outputCur_s);
+}
+
+void GetModuleStatusCallback(byte address, unsigned char isErr, unsigned char status,
+		unsigned char err1, unsigned char err2, unsigned char err3, unsigned char err4)
+{
+	ShmDcCommonData->psuKeepCommunication = ShmDcCommonData->acContactSwitch;
+	int _timebuf = GetTimeoutValue(&ShmDcCommonData->_psuComm_time);
+
+	if (_timebuf > 1 || _timebuf < 0)
+	{
+		GetTimespecFunc(&ShmDcCommonData->_psuComm_time);
+	}
+
+	if (ShmPsuData->Work_Step < GET_SYS_CAP)
+		return;
+
+	if (IsOverModuleCount(address))
+		return;
+
+	byte group1 = FindTargetGroup(address);
+	byte addr = FindRealAddr(group1, address);
+
+	int alarm = err1 | (err2 << 8) | (err3 << 16) | (err4 << 24);
+
+	ShmPsuData->PsuGroup[group1].PsuModule[addr].AlarmCode = alarm;
+
+	if(AbnormalStopAnalysis(group1, alarm))
+	{
+		if (!ShmPsuData->PsuGroup[group1].GroupErrorFlag.bits.PsuFailure)
+		{
+			ShmPsuData->PsuGroup[group1].GroupErrorFlag.bits.PsuFailure = YES;
+			ShmPsuData->PsuStopChargeFlag = YES;
+			ShmDcCommonData->_isPsuErrorOccur = YES;
+			PRINTF_FUNC("Group_%d - Address_%d, PSU Error Occurred. \n", group1, addr);
+		}
+	}
+}
+
+void GetModuleInputCallback(byte address, unsigned short inputR,
+		unsigned short inputS, unsigned short inputT)
+{
+	if (ShmPsuData->Work_Step < GET_SYS_CAP)
+		return;
+
+	if (IsOverModuleCount(address))
+		return;
+
+	byte group = FindTargetGroup(address);
+	byte addr = FindRealAddr(group, address);
+//	if (group == 1)
+//		address -= ShmPsuData->PsuGroup[group - 1].GroupPresentPsuQuantity;
+
+	ShmPsuData->PsuGroup[group].PsuModule[addr].InputVoltageL1 = inputR;
+	ShmPsuData->PsuGroup[group].PsuModule[addr].InputVoltageL2 = inputS;
+	ShmPsuData->PsuGroup[group].PsuModule[addr].InputVoltageL3 = inputT;
+
+	//PRINTF_FUNC("***Input*** address = %d, R = %d, S = %d, T = %d \n",
+	//		address, inputR, inputS, inputT);
+}
+
+//==========================================
+// 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;
+   	}
+
+   	//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;
+   	}
+
+   	//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;
+	}
+
+	if ((MeterSMId = shmget(ShmCommonKey, sizeof(struct DcCommonInformation), IPC_CREAT | 0777)) < 0)
+	{
+		#ifdef SystemLogMessage
+	   	DEBUG_ERROR("shmget ShmCommonKey NG \n");
+	   	#endif
+	   	result = FAIL;
+	}
+	else if ((ShmDcCommonData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
+	{
+		#ifdef SystemLogMessage
+	   	DEBUG_ERROR("shmat ShmCommonKey NG \n");
+	   	#endif
+	   	result = FAIL;
+	}
+
+    return result;
+}
+
+//================================================
+// Log function
+//================================================
+void OutputChargingLogFuncion(byte groupIndex)
+{
+	// 列印時機 : 需求改變或輸出電壓與紀錄落差超過 5V 或者輸出電流與紀錄落差超過 0.5A
+	if (chargingOutputLogInfo[groupIndex][_CHARGING_LOG_NEED_VOL] != chargingInfo[groupIndex]->EvBatterytargetVoltage * 10 ||
+			(chargingInfo[groupIndex]->FireChargingVoltage <= chargingOutputLogInfo[groupIndex][_CHARGING_LOG_OUTPUT_VOL] - LOG_VOL_GAP ||
+					chargingInfo[groupIndex]->FireChargingVoltage >= chargingOutputLogInfo[groupIndex][_CHARGING_LOG_OUTPUT_VOL] + LOG_VOL_GAP))
+	{
+		chargingOutputLogInfo[groupIndex][_CHARGING_LOG_NEED_VOL] = chargingInfo[groupIndex]->EvBatterytargetVoltage * 10;
+		chargingOutputLogInfo[groupIndex][_CHARGING_LOG_OUTPUT_VOL] = chargingInfo[groupIndex]->FireChargingVoltage;
+
+		PRINTF_FUNC("Conn %d, EV Req Voltage : %.1f, EVSE Output Voltage = %.1f \n", groupIndex,
+				chargingOutputLogInfo[groupIndex][_CHARGING_LOG_NEED_VOL] / 10,
+				chargingOutputLogInfo[groupIndex][_CHARGING_LOG_OUTPUT_VOL] / 10);
+	}
+
+	if (chargingOutputLogInfo[groupIndex][_CHARGING_LOG_NEED_CUR] != chargingInfo[groupIndex]->EvBatterytargetCurrent * 10 ||
+			(chargingInfo[groupIndex]->PresentChargingCurrent <= chargingOutputLogInfo[groupIndex][_CHARGING_LOG_OUTPUT_CUR] - LOG_CUR_GAP ||
+					chargingInfo[groupIndex]->PresentChargingCurrent >= chargingOutputLogInfo[groupIndex][_CHARGING_LOG_OUTPUT_CUR] + LOG_CUR_GAP))
+	{
+		chargingOutputLogInfo[groupIndex][_CHARGING_LOG_NEED_CUR] = chargingInfo[groupIndex]->EvBatterytargetCurrent * 10;
+		chargingOutputLogInfo[groupIndex][_CHARGING_LOG_OUTPUT_CUR] = chargingInfo[groupIndex]->PresentChargingCurrent;
+
+		PRINTF_FUNC("Conn %d, EV Req Current : %.1f, EVSE Output Current = %.1f \n", groupIndex,
+				chargingOutputLogInfo[groupIndex][_CHARGING_LOG_NEED_CUR] / 10,
+				chargingOutputLogInfo[groupIndex][_CHARGING_LOG_OUTPUT_CUR]);
+	}
+}
+
+//================================================
+// Main process
+//================================================
+void InitialPsuData()
+{
+	ShmPsuData->SystemPresentPsuQuantity = 0;
+
+	PRINTF_FUNC("InitialPsuData : PSU Group = %d \n", ShmPsuData->GroupCount);
+	for (byte _groupCount = 0; _groupCount < ShmPsuData->GroupCount; _groupCount++)
+	{
+		ShmPsuData->PsuGroup[_groupCount].GroupAvailablePower = 0;
+		ShmPsuData->PsuGroup[_groupCount].GroupAvailableCurrent = 0;
+
+		chargingInfo[_groupCount]->PresentChargingVoltage = 0;
+		chargingInfo[_groupCount]->PresentChargingCurrent = 0;
+
+		ShmPsuData->PsuGroup[_groupCount].GroupErrorFlag.bits.PsuFailure = NO;
+	}
+	ShmPsuData->PsuStopChargeFlag = NO;
+	ShmDcCommonData->_isPsuErrorOccur = NO;
+}
+
+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;
+			}
+		}
+		sleep(1);
+	}
+
+	if (ShmSysConfigAndInfo->SysInfo.IsAlternatvieConf == YES)
+		ShmPsuData->GroupCount = 1;
+	else
+		ShmPsuData->GroupCount = _gunCount;
+
+	ShmPsuData->SystemAvailableCurrent = 0;
+	ShmPsuData->SystemAvailablePower = 0;
+
+	GetTimespecFunc(&ShmDcCommonData->_psuComm_time);
+}
+
+void CheckSmartChargingStep(byte chargingStatus)
+{
+	// 跑切換均充的邏輯
+	if (ShmSysConfigAndInfo->SysInfo.MainChargingMode == _MAIN_CHARGING_MODE_MAX)
+	{
+		// 確認 A 槍是否已經進入充電階段
+		if (chargingStatus == _CHARGING_GUN_STATUS_CHARGING)
+		{
+			if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag == _REASSIGNED_PREPARE_M_TO_A)
+			{
+				PRINTF_FUNC("======= Max -> Aver : Update new charging capacity. (Step 2) ======= \n");
+				ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_GET_NEW_CAP;
+			}
+		}
+		else if (chargingStatus == _CHARGING_GUN_STATUS_STOP)
+		{
+			if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag != _REASSIGNED_NONE)
+			{
+				PRINTF_FUNC("============= Max -> Aver : Charging mode = MAX. (Step 0) ============= \n");
+				ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_NONE;
+			}
+		}
+	}
+	// 跑切換最大充邏輯
+	else if (ShmSysConfigAndInfo->SysInfo.MainChargingMode == _MAIN_CHARGING_MODE_AVER)
+	{
+		if (chargingStatus == _CHARGING_GUN_STATUS_CHARGING)
+		{
+			if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag == _REASSIGNED_PREPARE_A_TO_M)
+			{
+				PRINTF_FUNC("======= Aver -> Max : switch on the psu voltage. (Step 12) ======= \n");
+				preChargingCur = preChargingTarget = 0;
+				GetTimespecMFunc(&_max_time);
+				ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_ADJUST_A_TO_M;
+			}
+		}
+		else if (chargingStatus == _CHARGING_GUN_STATUS_STOP &&
+				ShmSysConfigAndInfo->SysInfo.ReAssignedFlag != _REASSIGNED_COMP)
+		{
+			PRINTF_FUNC("======= Aver -> Max : Charging mode = MAX. (Step 15) ======= \n");
+			ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_COMP;
+		}
+	}
+
+
+//	if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag == _REASSIGNED_PREPARE_M_TO_A)
+//	{
+//		if (isWaitingAver)
+//		{
+//			if (ShmSysConfigAndInfo->SysInfo.MainChargingMode == _MAIN_CHARGING_MODE_MAX)
+//			{
+//				ShmSysConfigAndInfo->SysInfo.CanAverageCharging = canAverageCharging;
+//
+//				if (canAverageCharging)
+//				{
+//					PRINTF_FUNC("======= Only to get the charging side capacity (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
+//			{
+//				PRINTF_FUNC("=============Smart Charging Aver mode : _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("======= To raise voltage of idle module to charging voltage (Step 12) ======= \n");
+//				preChargingCur = preChargingTarget = 0;
+//				gettimeofday(&_max_time, NULL);
+//				ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_ADJUST_A_TO_M;
+//			}
+//			else
+//			{
+//				PRINTF_FUNC("======= The Change to maximum charge mode is complete. (Step 15) ======= \n");
+//				ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_COMP;
+//			}
+//		}
+//		else
+//		{
+//			PRINTF_FUNC("======= The Change to maximum charge mode is complete. (Step 15) ======= \n");
+//			ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_COMP;
+//		}
+//	}
+}
+
+void PreCheckSmartChargingStep()
+{
+	_maxChargingStatus = _CHARGING_GUN_STATUS_NONE;
+	isReadyToCharging = false;
+
+	for (byte index = 0; index < ShmPsuData->GroupCount; index++)
+	{
+		if ((chargingInfo[index]->SystemStatus >= SYS_MODE_PREPARE_FOR_EVSE && chargingInfo[index]->SystemStatus <= SYS_MODE_CHARGING) ||
+				(chargingInfo[index]->SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0 && chargingInfo[index]->SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))
+		{
+			isReadyToCharging = true;
+		}
+	}
+
+	for (byte index = 0; index < ShmPsuData->GroupCount; index++)
+	{
+		if ((chargingInfo[index]->SystemStatus >= SYS_MODE_PREPARE_FOR_EVSE && chargingInfo[index]->SystemStatus < SYS_MODE_CHARGING) ||
+				(chargingInfo[index]->SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0 && chargingInfo[index]->SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))
+		{
+			_maxChargingStatus = _CHARGING_GUN_STATUS_COMM;
+		}
+		else if (chargingInfo[index]->SystemStatus == SYS_MODE_CHARGING)
+		{
+			_maxChargingStatus = _CHARGING_GUN_STATUS_CHARGING;
+			break;
+		}
+		else if (chargingInfo[index]->SystemStatus == SYS_MODE_COMPLETE ||
+						chargingInfo[index]->SystemStatus == SYS_MODE_ALARM)
+		{
+			_maxChargingStatus = _CHARGING_GUN_STATUS_STOP;
+		}
+	}
+
+	CheckSmartChargingStep(_maxChargingStatus);
+}
+
+void Await()
+{
+	usleep(CMD_DELAY_TIME);
+}
+
+bool MaxToAverChargingProc(byte groupIndex)
+{
+	// 智能判斷 Start -----------------------------------------------------------
+	if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag >= _REASSIGNED_GET_NEW_CAP &&
+			ShmSysConfigAndInfo->SysInfo.ReAssignedFlag <= _REASSIGNED_RELAY_M_TO_A)
+	{
+		if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag == _REASSIGNED_GET_NEW_CAP)
+		{
+			if (chargingInfo[groupIndex]->DividChargingCurrent == 0)
+			{
+				chargingInfo[groupIndex]->DividChargingCurrent = ShmPsuData->PsuGroup[groupIndex].GroupPresentOutputCurrent;
+				PRINTF_FUNC("Index = %d, DividChargingCurrent = %.1f \n", groupIndex, chargingInfo[groupIndex]->DividChargingCurrent);
+			}
+
+			// 車端要求電流為該充電槍的額定輸出電流的範圍內
+			if ((chargingInfo[groupIndex]->EvBatterytargetCurrent * 10) <= ShmPsuData->PsuGroup[groupIndex].GroupPresentOutputCurrent + DERATING_GAP ||
+					deratingKeepCount >= DERATING_COUNT)
+			{
+				// 車端降載完成
+				PRINTF_FUNC("Index = %d, newEvCurrent = %f \n", groupIndex, (chargingInfo[groupIndex]->EvBatterytargetCurrent * 10));
+				PRINTF_FUNC("======= Max -> Aver : wait the target current is down. (Step 3) ======= \n");
+				ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_ADJUST_M_TO_A;
+				GetTimespecMFunc(&_derating_time);
+				deratingKeepCount = 0;
+				step3KeepCount = 0;
+			}
+			else
+			{
+				deratingKeepCount++;
+				if (deratingKeepCount % 3 == 0)
+				{
+					PRINTF_FUNC("Max To Ava mode (2) : Index = %d, EvBatterytargetCurrent = %f, TargetCurrent = %d, Count = %d \n",
+					groupIndex,
+					(chargingInfo[groupIndex]->EvBatterytargetCurrent * 10),
+					(ShmPsuData->PsuGroup[groupIndex].GroupPresentOutputCurrent + DERATING_GAP),
+					deratingKeepCount);
+				}
+			}
+		}
+		else if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag == _REASSIGNED_ADJUST_M_TO_A)
+		{
+			bool isChanged = false;
+
+			if (chargingInfo[groupIndex]->DividChargingCurrent == 0 ||
+					(chargingInfo[groupIndex]->DividChargingCurrent != 0 &&
+					(chargingInfo[groupIndex]->DividChargingCurrent == chargingInfo[groupIndex]->AvailableChargingCurrent) &&
+					chargingInfo[groupIndex]->AvailableChargingCurrent >= (chargingInfo[groupIndex]->EvBatterytargetCurrent * 10)))
+			{
+				for (byte subIndex = 0; subIndex < ShmPsuData->GroupCount; subIndex++)
+				{
+					if (chargingInfo[subIndex]->SystemStatus == SYS_MODE_REASSIGN)
+					{
+						// 當 B 模塊輸出電流小於 5A 及退開 relay
+						if ((ShmPsuData->PsuGroup[subIndex].GroupPresentOutputCurrent) <= 50)
+								isChanged = true;
+						break;
+					}
+				}
+			}
+			else if (chargingInfo[groupIndex]->PresentChargingCurrent == 0)
+			{
+				for (byte subIndex = 0; subIndex < ShmPsuData->GroupCount; subIndex++)
+				{
+					if (chargingInfo[subIndex]->SystemStatus == SYS_MODE_REASSIGN)
+					{
+						if ((ShmPsuData->PsuGroup[subIndex].GroupPresentOutputCurrent) <= CHK_CUR_RANGE)
+								isChanged = true;
+						break;
+					}
+				}
+			}
+
+			if (!isChanged)
+			{
+				if (step3KeepCount < DERATING_COUNT)
+					step3KeepCount++;
+				else
+					isChanged = true;
+			}
+
+			if (isChanged)
+			{
+				PRINTF_FUNC("Max To Ava mode (3-2) : Gun_%d, PresentChargingCurrent = %f, GroupPresentOutputCurrent = %d \n", groupIndex,
+					(chargingInfo[groupIndex]->PresentChargingCurrent * 10),
+					ShmPsuData->PsuGroup[groupIndex].GroupPresentOutputCurrent);
+
+				// 輸出端與車端要求電流接近
+				PRINTF_FUNC("======= Max -> Aver : off the Parallel relay. (Step 4) ======= \n");
+					ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_RELAY_M_TO_A;
+			}
+			else
+			{
+				int _t = GetTimeoutMValue(&_derating_time);
+
+				if (_t > 1000 || _t < 0)
+				{
+					PRINTF_FUNC("Max To Ava mode (3-1) : Gun_%d, AvailableChargingCurrent = %f, EvBatterytargetCurrent = %f, step3KeepCount = %d \n",
+						groupIndex,
+						chargingInfo[groupIndex]->AvailableChargingCurrent,
+						(chargingInfo[groupIndex]->EvBatterytargetCurrent * 10),
+						step3KeepCount);
+
+					PRINTF_FUNC("Max To Ava mode (3-1) : Gun_%d, PresentChargingCurrent = %f, GroupPresentOutputCurrent = %d, GroupCount = %d \n",
+						groupIndex,
+						(chargingInfo[groupIndex]->PresentChargingCurrent * 10),
+						ShmPsuData->PsuGroup[groupIndex].GroupPresentOutputCurrent,
+						ShmPsuData->GroupCount);
+
+					GetTimespecMFunc(&_derating_time);
+				}
+			}
+		}
+	}
+	else
+	{
+		chargingInfo[groupIndex]->DividChargingCurrent = 0;
+		chargingInfo[groupIndex]->MaxChargingToAverPassFlag = 0;
+	}
+
+	// 調整輸出電流 : 漸進調整方式
+	if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag >= _REASSIGNED_GET_NEW_CAP &&
+		ShmSysConfigAndInfo->SysInfo.ReAssignedFlag < _REASSIGNED_RELAY_M_TO_A)
+	{
+		if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag >= _REASSIGNED_ADJUST_M_TO_A)
+		{
+			// 當前充電中的目標電壓
+			float targetVol = (chargingInfo[groupIndex]->EvBatterytargetVoltage * 10);
+			byte reassignIndex = ELEMENT_NOT_FIND;
+
+			// 找到等待分配的槍
+			for (byte subIndex = 0; subIndex < ShmPsuData->GroupCount; subIndex++)
+			{
+				if (chargingInfo[subIndex]->SystemStatus == SYS_MODE_REASSIGN)
+				{
+					reassignIndex = subIndex;
+					break;
+				}
+			}
+
+			if (reassignIndex != ELEMENT_NOT_FIND)
+			{
+				if (GetTimeoutMValue(&_derating_time) <= 150 ||
+						chargingInfo[groupIndex]->MaxChargingToAverPassFlag == 0)
+				{
+					chargingInfo[groupIndex]->MaxChargingToAverPassFlag = 1;
+
+					if(chargingInfo[groupIndex]->EvBatterytargetCurrent <= PSU_MIN_OUTPUT_CUR)
+						chargingInfo[groupIndex]->EvBatterytargetCurrent = PSU_MIN_OUTPUT_CUR;
+					PresentOutputVol(groupIndex, targetVol, (chargingInfo[groupIndex]->EvBatterytargetCurrent * 10)); Await();
+
+					PresentOutputVol(reassignIndex, targetVol, CHK_CUR_RANGE); Await();
+				}
+			}
+		}
+
+		if ((chargingInfo[groupIndex]->EvBatterytargetVoltage * 10) == 0)
+		{
+			bool isNeedToClosePower = false;
+			for (byte index = 0; index < ShmPsuData->GroupCount; index++)
+			{
+				if (isStartOutputSwitch[index])
+				{
+					isNeedToClosePower = true;
+				}
+				isStartOutputSwitch[index] = false;
+			}
+
+			if (isNeedToClosePower)
+			{
+				SwitchPower(SYSTEM_CMD, PSU_POWER_OFF);
+				FlashLed(SYSTEM_CMD, PSU_FLASH_NORMAL);
+			}
+		}
+	}
+	else if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag >= _REASSIGNED_RELAY_M_TO_A)
+	{
+		//PRINTF_FUNC("set out (%d) value = %f******** 3 \n", groupIndex, chargingInfo[groupIndex]->EvBatterytargetCurrent);
+		if(chargingInfo[groupIndex]->EvBatterytargetCurrent <= PSU_MIN_OUTPUT_CUR)
+			chargingInfo[groupIndex]->EvBatterytargetCurrent = PSU_MIN_OUTPUT_CUR;
+
+		PresentOutputVol(groupIndex,
+			(chargingInfo[groupIndex]->EvBatterytargetVoltage * 10),
+			(chargingInfo[groupIndex]->EvBatterytargetCurrent * 10)); Await();
+	}
+	else
+	{
+		return false;
+	}
+
+	return true;
+}
+
+bool AverToMaxChargingProc(byte groupIndex)
+{
+	if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag >= _REASSIGNED_ADJUST_A_TO_M)
+	{
+		byte reassignIndex = ELEMENT_NOT_FIND;
+
+		for (byte subIndex = 0; subIndex < ShmPsuData->GroupCount; subIndex++)
+		{
+			if (chargingInfo[subIndex]->SystemStatus == SYS_MODE_IDLE ||
+					chargingInfo[subIndex]->SystemStatus == SYS_MODE_RESERVATION ||
+					chargingInfo[subIndex]->SystemStatus == SYS_MODE_FAULT ||
+					chargingInfo[subIndex]->SystemStatus == SYS_MODE_MODE_REASSIGN_CHECK ||
+					chargingInfo[subIndex]->SystemStatus == SYS_MODE_COMPLETE ||
+					chargingInfo[subIndex]->SystemStatus == SYS_MODE_ALARM)
+			{
+				reassignIndex = subIndex;
+
+				if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag >= _REASSIGNED_WAITING)
+				{
+					preChargingCur = ShmPsuData->PsuGroup[subIndex].GroupPresentOutputCurrent;
+				}
+				else
+					preChargingCur = 0;
+			}
+			else
+			{
+				if ((ShmSysConfigAndInfo->SysInfo.ReAssignedFlag >= _REASSIGNED_WAITING) &&
+						(preChargingCur >= preChargingTarget - MIN_1A_CURRENT))
+						preChargingTarget += PRE_CHARG_STEP_CUR;
+
+				if (preChargingTarget >= (chargingInfo[subIndex]->EvBatterytargetCurrent * 10) / 2)
+						preChargingTarget = (chargingInfo[subIndex]->EvBatterytargetCurrent * 10) / 2;
+			}
+		}
+
+		if (reassignIndex != ELEMENT_NOT_FIND)
+		{
+			if (GetTimeoutMValue(&_max_time) <= 150)
+			{
+				//PRINTF_FUNC("set out (%d) value = %d******** 5 \n", reassignIndex, MIN_1A_CURRENT + preChargingTarget);
+				// 閒置模塊升壓,另對剛分配近來的模塊,預上升電流值 (preChargingCur)
+				PresentOutputVol(reassignIndex,
+					(chargingInfo[groupIndex]->EvBatterytargetVoltage * 10),
+					MIN_1A_CURRENT + preChargingTarget); Await();
+			}
+
+			byte _ovCahrgingCur = 0;
+			if (preChargingCur > PRE_CHARG_STEP_CUR)
+				_ovCahrgingCur = PRE_CHARG_STEP_CUR;
+
+			PresentOutputVol(groupIndex,
+				(chargingInfo[groupIndex]->EvBatterytargetVoltage * 10),
+				(chargingInfo[groupIndex]->EvBatterytargetCurrent * 10) - preChargingCur - _ovCahrgingCur); Await();
+		}
+
+		if ((chargingInfo[groupIndex]->EvBatterytargetVoltage * 10) == 0)
+		{
+			bool isNeedToClosePower = false;
+			for (byte index = 0; index < ShmPsuData->GroupCount; index++)
+			{
+				if (isStartOutputSwitch[index])
+				{
+					isNeedToClosePower = true;
+				}
+				isStartOutputSwitch[index] = false;
+			}
+
+			if (isNeedToClosePower)
+			{
+				SwitchPower(SYSTEM_CMD, PSU_POWER_OFF);
+				FlashLed(SYSTEM_CMD, PSU_FLASH_NORMAL);
+			}
+		}
+		else
+		{
+			bool isNeedToOpenPower = false;
+			for (byte index = 0; index < ShmPsuData->GroupCount; index++)
+			{
+				if (!isStartOutputSwitch[index])
+				{
+					isNeedToOpenPower = true;
+				}
+				isStartOutputSwitch[index] = true;
+			}
+
+			if (isNeedToOpenPower)
+			{
+				SwitchPower(SYSTEM_CMD, PSU_POWER_ON);
+				FlashLed(SYSTEM_CMD, PSU_FLASH_ON);
+			}
+		}
+
+		if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag == _REASSIGNED_ADJUST_A_TO_M)
+		{
+			bool balanceVol = true;
+			byte subIndex;
+
+			for (subIndex = 0; subIndex < ShmPsuData->GroupCount; subIndex++)
+			{
+				if (chargingInfo[subIndex]->SystemStatus == SYS_MODE_IDLE ||
+						chargingInfo[subIndex]->SystemStatus == SYS_MODE_FAULT ||
+						chargingInfo[subIndex]->SystemStatus == SYS_MODE_RESERVATION ||
+						chargingInfo[subIndex]->SystemStatus == SYS_MODE_COMPLETE ||
+						chargingInfo[subIndex]->SystemStatus == SYS_MODE_ALARM)
+				{
+					// 各群電壓接近平衡
+					if (((chargingInfo[subIndex]->PresentChargingVoltage * 10) < (chargingInfo[groupIndex]->PresentChargingVoltage * 10) - MIN_5V_VOLTAGE) ||
+							((chargingInfo[subIndex]->PresentChargingVoltage * 10) < (chargingInfo[groupIndex]->EvBatterytargetVoltage * 10) - CHK_VOL_RANGE))
+					{
+						balanceVol = false;
+					}
+					break;
+				}
+			}
+
+			if (balanceVol)
+			{
+				// 閒置端與車端要求電壓接近
+				PRINTF_FUNC("======= Aver -> Max : switch on the Parallel relay. (Step 13) ======= \n");
+				ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_RELAY_A_TO_M;
+			}
+			else
+			{
+				int _tMax_1 = GetTimeoutMValue(&_max_time);
+
+				if (_tMax_1 > 500 || _tMax_1 < 0)
+				{
+					PRINTF_FUNC("Ava To Max mode (12) : Gun_%d, PresentChargingVoltage = %f, PresentChargingVoltage_V = %f, EvBatterytargetVoltage = %f \n", subIndex,
+						(chargingInfo[subIndex]->PresentChargingVoltage * 10),
+						((chargingInfo[groupIndex]->PresentChargingVoltage * 10) - MIN_5V_VOLTAGE),
+						((chargingInfo[groupIndex]->EvBatterytargetVoltage * 10) - CHK_VOL_RANGE));
+					GetTimespecMFunc(&_max_time);
+				}
+			}
+		}
+		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 == SYS_MODE_IDLE ||
+						chargingInfo[subIndex]->SystemStatus == SYS_MODE_RESERVATION ||
+						chargingInfo[subIndex]->SystemStatus == SYS_MODE_FAULT ||
+						chargingInfo[subIndex]->SystemStatus == SYS_MODE_MODE_REASSIGN_CHECK)
+					idleCurrent = ShmPsuData->PsuGroup[subIndex].GroupPresentOutputCurrent;
+				else
+				{
+					chargingCurrent = ShmPsuData->PsuGroup[subIndex].GroupPresentOutputCurrent;
+				}
+			}
+
+			if (idleCurrent >= chargingCurrent - PRE_CHARG_RANGE)
+			{
+				PRINTF_FUNC("======= Aver -> Max : Charging mode = MAX. (Step 15) ======= \n");
+				ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_COMP;
+			}
+			else
+			{
+				int _tMax_2 = GetTimeoutMValue(&_max_time);
+
+				if (_tMax_2 > 300 || _tMax_2 < 0)
+				{
+					GetTimespecMFunc(&_max_time);
+				}
+			}
+		}
+	}
+	else
+	{
+		return false;
+	}
+	return true;
+}
+
+void SwitchOffPowerCheck(byte groupIndex)
+{
+	_maxChargingStatus = _CHARGING_GUN_STATUS_STOP;
+
+	for (byte index = 0; index < ShmPsuData->GroupCount; index++)
+	{
+		// 判斷另一把槍的狀態
+		if (index != groupIndex)
+		{
+			if ((chargingInfo[index]->SystemStatus >= SYS_MODE_PREPARE_FOR_EV && chargingInfo[index]->SystemStatus <= SYS_MODE_CHARGING) ||
+					(chargingInfo[index]->SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0 && chargingInfo[index]->SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))
+				_maxChargingStatus = _CHARGING_GUN_STATUS_CHARGING;
+			else
+				_maxChargingStatus = _CHARGING_GUN_STATUS_STOP;
+		}
+	}
+}
+
+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);
+	RefreshMisInfo(&GetMisCallback);
+	RefreshIavailable(&GetIavailableCallback);
+	RefreshGetOutputF(&GetPresentOutputFCallback);
+
+	// GetPresentOutputCallback & GetStatusCallback
+	AutoMode_RefreshOutputAndTemp(&GetOutputAndTempCallback);
+	// GetStatusCallback
+	AutoMode_RefreshModuleStatus(&GetModuleStatusCallback);
+	// GetInputVoltageCallback
+	AutoMode_RefreshModuleInput(&GetModuleInputCallback);
+
+	sleep(2);
+	_gunCount = ShmSysConfigAndInfo->SysConfig.TotalConnectorCount;
+	// initial object
+	InitialPsuData();
+	Initialization();
+	libInitialize = InitialCommunication();
+    byte isInitialComp = NO;
+    if (ShmSysConfigAndInfo->SysInfo.IsAlternatvieConf == YES)
+    {
+    	PRINTF_FUNC("Alter native mode. \n");
+    }
+
+	//main loop
+	while (libInitialize)
+	{
+		// 斷電狀態
+		if (ShmSysConfigAndInfo->SysInfo.AcContactorStatus == NO)
+		{
+			//一但 AC Off PSU 斷電全部的 PSU Group ID 會全部清 0
+			if (!isInitialComp)
+			{
+				ShmPsuData->Work_Step = INITIAL_START;
+				psuCmdSeq = _PSU_CMD_STATUS;
+				sleep(2);
+				InitialPsuData();
+				isInitialComp = YES;
+			}
+
+			ShmDcCommonData->psuKeepCommunication = ShmDcCommonData->acContactSwitch;
+			sleep(1);
+			continue;
+		}
+		else
+		{
+			if (isInitialComp)
+				GetTimespecFunc(&ShmDcCommonData->_psuComm_time);
+
+			isInitialComp = NO;
+		}
+
+		// 自檢失敗
+		if (ShmPsuData->Work_Step == _NO_WORKING)
+		{
+			PRINTF_FUNC("== PSU == self test fail. \n");
+			sleep(5);
+		}
+		else if (ShmDcCommonData->rebootCount < 1)
+		{
+			int _time = GetTimeoutValue(&ShmDcCommonData->_psuComm_time);
+			if (_time < 0)
+				GetTimespecFunc(&ShmDcCommonData->_psuComm_time);
+
+			if (_time > 30)
+			{
+				if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuComminicationErrWithCSU == NO)
+				{
+					ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuComminicationErrWithCSU = YES;
+					ShmDcCommonData->rebootCount = 1;
+					PRINTF_FUNC("Psu is gone, reset one time. \n");
+				}
+			}
+		}
+
+		switch(ShmPsuData->Work_Step)
+		{
+			case INITIAL_START:
+			{
+				PRINTF_FUNC("== PSU == INITIAL_START \n");
+				GetTimespecMFunc(&_cmdSubPsuPriority_time);
+				sleep(5);
+				SwitchPower(SYSTEM_CMD, PSU_POWER_OFF);
+				SetWalkInConfig(SYSTEM_CMD, NO, 0);
+				for (byte index = 0; index < ShmPsuData->GroupCount; index++)
+				{
+					ShmPsuData->PsuGroup[index].GroupPresentPsuQuantity = 0;
+					isStartOutputSwitch[index] = false;
+				}
+				ShmPsuData->Work_Step = GET_PSU_COUNT;
+			}
+				break;
+			case GET_PSU_COUNT:
+			{
+				int time = GetTimeoutMValue(&_cmdSubPsuPriority_time);
+				byte moduleCount = 0;
+
+				if (time < 0)
+					GetTimespecMFunc(&_cmdSubPsuPriority_time);
+				// 發送取得目前全部模組數量
+				GetModuleCount(SYSTEM_CMD);
+
+				if (time > 1000)
+				{
+					if (psuCmdSeq == _PSU_CMD_STATUS)
+					{
+						// 取得狀態 : 支援模塊不須按照順序功能
+						for (byte index = 0; index < ShmPsuData->GroupCount; index++)
+						{
+							GetStatus(index);
+						}
+
+						Await();
+					}
+					else if (psuCmdSeq == _PSU_CMD_GETCOUNT)
+					{
+						// 分別取各群模組數量
+						for (byte index = 0; index < ShmPsuData->GroupCount; index++)
+						{
+							// 總和各群模組數量
+							moduleCount += ShmPsuData->PsuGroup[index].GroupPresentPsuQuantity;
+
+							// 取各群模組數量
+							GetModuleCount(index);
+						}
+						PRINTF_FUNC("== PSU == Connector Count = %d, moduleCount = %d, sysCount = %d\n",
+								ShmPsuData->GroupCount, moduleCount, ShmPsuData->SystemPresentPsuQuantity);
+
+						// 判斷系統數量與各群數量一致
+						if(moduleCount == ShmPsuData->SystemPresentPsuQuantity && moduleCount > 0)
+						{
+							_delayCount = 8;
+							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;
+							}
+						}
+					}
+
+					if (psuCmdSeq == _PSU_CMD_STATUS)
+						psuCmdSeq = _PSU_CMD_GETCOUNT;
+					else
+						psuCmdSeq = _PSU_CMD_STATUS;
+
+					GetTimespecMFunc(&_cmdSubPsuPriority_time);
+				}
+			}
+				break;
+			case GET_SYS_CAP:
+			{
+				int time = GetTimeoutMValue(&_cmdSubPsuPriority_time);
+
+				if (time < 0)
+					GetTimespecMFunc(&_cmdSubPsuPriority_time);
+
+				if (time > 500)
+				{
+					bool isFinish = true;
+					for (byte psuCount = 0; psuCount < ShmPsuData->SystemPresentPsuQuantity; psuCount++)
+					{
+						if (strcmp((char *)ShmPsuData->PsuVersion[psuCount].FwPrimaryVersion, "") == EQUAL ||
+								ShmPsuData->SystemAvailablePower <= 0 || ShmPsuData->SystemAvailableCurrent <= 0)
+						{
+							isFinish = false;
+							break;
+						}
+					}
+
+					if (!isFinish || _delayCount > 0)
+					{
+						for (byte index = 0; index < ShmPsuData->GroupCount; index++)
+						{
+							if (psuCmdSeq == _PSU_CMD_STATUS)
+							{
+								// 取得狀態 : 支援模塊不須按照順序功能
+								GetStatus(index);
+							}
+							else if (psuCmdSeq == _PSU_CMD_CAP)
+							{
+								_delayCount--;
+								// 取系統總輸出能力
+								GetModuleCap(index);
+							}
+							else if (psuCmdSeq == _PSU_CMD_VERSION)
+							{
+								// 取版號
+								GetModuleVer(index);
+							}
+						}
+
+						if (psuCmdSeq == _PSU_CMD_STATUS)
+							psuCmdSeq = _PSU_CMD_CAP;
+						else if (psuCmdSeq == _PSU_CMD_CAP)
+							psuCmdSeq = _PSU_CMD_VERSION;
+						else
+							psuCmdSeq = _PSU_CMD_STATUS;
+					}
+					else
+					{
+						// 判斷系統輸出額定功率與電流
+						PRINTF_FUNC("SystemAvailableCurrent = %d, SystemAvailablePower = %d \n",
+							ShmPsuData->SystemAvailableCurrent, ShmPsuData->SystemAvailablePower);
+
+						PRINTF_FUNC("== PSU == BOOTING_COMPLETE \n");
+						ShmPsuData->Work_Step = BOOTING_COMPLETE;
+					}
+
+					GetTimespecMFunc(&_cmdSubPsuPriority_time);
+					//GetTimespecFunc(&_log_time);
+				}
+			}
+				break;
+			case BOOTING_COMPLETE:
+			{
+				bool isSelfTestPass = true;
+				for (byte groupIndex = 0; groupIndex < _gunCount; groupIndex++)
+				{
+					if (chargingInfo[groupIndex]->SystemStatus == SYS_MODE_BOOTING)
+					{
+						isSelfTestPass = false;
+					}
+				}
+
+				if (isSelfTestPass)
+					ShmPsuData->Work_Step = _WORK_CHARGING;
+				sleep(1);
+			}
+				break;
+			case _WORK_CHARGING:
+			{
+				int time = GetTimeoutMValue(&_cmdSubPsuPriority_time);
+				//int _timebuf = 0;
+
+				if (time < 0)
+					GetTimespecMFunc(&_cmdSubPsuPriority_time);
+
+				// 低 Priority 的指令
+				if (time > 1500)
+				{
+					PreCheckSmartChargingStep();
+					startModuleFlag = true;
+					GetTimespecMFunc(&_cmdSubPsuPriority_time);
+				}
+
+				for (byte groupIndex = 0; groupIndex < _gunCount; groupIndex++)
+				{
+					if (psuCmdSeq == _PSU_CMD_CAP)
+					{
+						// 取系統總輸出能力
+						GetModuleCap(groupIndex);
+					}
+					else if (psuCmdSeq == _PSU_CMD_OUTPUT)
+					{
+						// 取各群輸出電壓電流 (float)
+						GetModuleOutputF(groupIndex);
+					}
+					else if (psuCmdSeq == _PSU_CMD_IVAILIABLE)
+					{
+						// 取得模塊輸出額定電流能力
+						GetModuleIavailable(groupIndex);
+					}
+					else if (psuCmdSeq == _PSU_CMD_TEMP)
+					{
+						// 取得模塊溫度
+						GetDcTemperature(groupIndex);
+					}
+				}
+
+				Await();
+
+				if (psuCmdSeq == _PSU_CMD_CAP)
+					psuCmdSeq = _PSU_CMD_OUTPUT;
+				else if (psuCmdSeq == _PSU_CMD_OUTPUT)
+					psuCmdSeq = _PSU_CMD_IVAILIABLE;
+				else if (psuCmdSeq == _PSU_CMD_IVAILIABLE)
+					psuCmdSeq = _PSU_CMD_TEMP;
+				else
+					psuCmdSeq = _PSU_CMD_CAP;
+
+				for (byte groupIndex = 0; groupIndex < _gunCount; groupIndex++)
+				{
+					// 針對各槍當前狀態,傳送需要回傳的資料指令
+					if (((chargingInfo[groupIndex]->SystemStatus >= SYS_MODE_PREPARE_FOR_EVSE && chargingInfo[groupIndex]->SystemStatus <= SYS_MODE_CHARGING) && chargingInfo[groupIndex]->RelayK1K2Status) ||
+							(chargingInfo[groupIndex]->SystemStatus >= SYS_MODE_PREPARE_FOR_EVSE && chargingInfo[groupIndex]->SystemStatus <= SYS_MODE_CHARGING && chargingInfo[groupIndex]->Type == _Type_GB) ||
+							(chargingInfo[groupIndex]->SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0 && chargingInfo[groupIndex]->SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))
+					{
+//						_timebuf = GetTimeoutValue(&_log_time);
+//						if (_timebuf < 0)
+//							GetTimespecFunc(&_log_time);
+//
+//						if (_timebuf > 1)
+						{
+							OutputChargingLogFuncion(groupIndex);
+							//GetTimespecFunc(&_log_time);
+						}
+
+						if (ShmSysConfigAndInfo->SysInfo.MainChargingMode == _MAIN_CHARGING_MODE_MAX)
+						{
+							if (!MaxToAverChargingProc(groupIndex))
+							{
+								if(chargingInfo[groupIndex]->EvBatterytargetCurrent <= PSU_MIN_OUTPUT_CUR)
+									chargingInfo[groupIndex]->EvBatterytargetCurrent = PSU_MIN_OUTPUT_CUR;
+
+								PresentOutputVol(SYSTEM_CMD,
+								(chargingInfo[groupIndex]->EvBatterytargetVoltage * 10),
+								(chargingInfo[groupIndex]->EvBatterytargetCurrent * 10));
+
+								if ((chargingInfo[groupIndex]->EvBatterytargetVoltage * 10) == 0)
+								{
+									bool isNeedToClosePower = false;
+									for (byte index = 0; index < ShmPsuData->GroupCount; index++)
+									{
+										if (isStartOutputSwitch[index])
+										{
+											isNeedToClosePower = true;
+										}
+										isStartOutputSwitch[index] = false;
+									}
+
+									if (isNeedToClosePower)
+									{
+										SwitchPower(SYSTEM_CMD, PSU_POWER_OFF);
+										FlashLed(SYSTEM_CMD, PSU_FLASH_NORMAL);
+									}
+								}
+								else
+								{
+									{
+										bool isNeedToOpenPower = false;
+										for (byte index = 0; index < ShmPsuData->GroupCount; index++)
+										{
+											if (!isStartOutputSwitch[index])
+											{
+												isNeedToOpenPower = true;
+											}
+											isStartOutputSwitch[index] = true;
+										}
+
+										if (isNeedToOpenPower || startModuleFlag)
+										{
+											SwitchPower(SYSTEM_CMD, PSU_POWER_ON);
+											FlashLed(SYSTEM_CMD, PSU_FLASH_ON);
+										}
+									}
+								}
+							}
+						}
+						else if (ShmSysConfigAndInfo->SysInfo.MainChargingMode == _MAIN_CHARGING_MODE_AVER)
+						{
+							if (!AverToMaxChargingProc(groupIndex))
+							{
+								if (chargingInfo[groupIndex]->AvailableChargingCurrent > 0)
+								{
+									//PRINTF_FUNC("set out (%d) value = %f******** 7 \n", groupIndex, chargingInfo[groupIndex]->EvBatterytargetCurrent);
+									if(chargingInfo[groupIndex]->EvBatterytargetCurrent <= PSU_MIN_OUTPUT_CUR)
+											chargingInfo[groupIndex]->EvBatterytargetCurrent = PSU_MIN_OUTPUT_CUR;
+
+									PresentOutputVol(groupIndex,
+									(chargingInfo[groupIndex]->EvBatterytargetVoltage * 10),
+									(chargingInfo[groupIndex]->EvBatterytargetCurrent * 10)); Await();
+
+									if ((chargingInfo[groupIndex]->EvBatterytargetVoltage * 10) == 0)
+									{
+										if (isStartOutputSwitch[groupIndex])
+										{
+											isStartOutputSwitch[groupIndex] = false;
+											SwitchPower(groupIndex, PSU_POWER_OFF); Await();
+											FlashLed(groupIndex, PSU_FLASH_NORMAL); Await();
+										}
+									}
+									else
+									{
+//										if (chargingInfo[groupIndex]->SystemStatus == SYS_MODE_PREPARE_FOR_EVSE)
+//										{
+//											if (startModuleFlag)
+//											{
+//												isStartOutputSwitch[groupIndex] = true;
+//												SwitchSinglePower(ShmDcCommonData->connector[groupIndex][0], PSU_POWER_ON);
+//												FlashSingleLed(ShmDcCommonData->connector[groupIndex][0], PSU_FLASH_ON);
+//											}
+//										}
+//										else
+										{
+											if (!isStartOutputSwitch[groupIndex] || startModuleFlag)
+											{
+												isStartOutputSwitch[groupIndex] = true;
+												SwitchPower(groupIndex, PSU_POWER_ON); Await();
+												FlashLed(groupIndex, PSU_FLASH_ON); Await();
+											}
+										}
+									}
+								}
+							}
+						}
+					}
+					else if (chargingInfo[groupIndex]->SystemStatus >= SYS_MODE_TERMINATING &&
+								chargingInfo[groupIndex]->SystemStatus <= SYS_MODE_ALARM)
+					{
+						if (ShmSysConfigAndInfo->SysInfo.MainChargingMode == _MAIN_CHARGING_MODE_MAX)
+						{
+							SwitchOffPowerCheck(groupIndex);
+							if (_maxChargingStatus == _CHARGING_GUN_STATUS_STOP)
+							{
+								bool isNeedToClosePower = false;
+								for (byte index = 0; index < ShmPsuData->GroupCount; index++)
+								{
+									if (isStartOutputSwitch[index])
+									{
+										isNeedToClosePower = true;
+									}
+									isStartOutputSwitch[index] = false;
+								}
+
+								if (isNeedToClosePower)
+								{
+									SwitchPower(SYSTEM_CMD, PSU_POWER_OFF);
+									FlashLed(SYSTEM_CMD, PSU_FLASH_NORMAL);
+								}
+
+								if (chargingInfo[groupIndex]->SystemStatus == SYS_MODE_COMPLETE ||
+										chargingInfo[groupIndex]->SystemStatus == SYS_MODE_ALARM)
+								{
+									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 == SYS_MODE_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 (!isReadyToCharging)
+//							{
+//								bool isNeedToClosePower = false;
+//								for (byte index = 0; index < ShmPsuData->GroupCount; index++)
+//								{
+//									if (isStartOutputSwitch[index])
+//									{
+//										isNeedToClosePower = true;
+//									}
+//									isStartOutputSwitch[index] = false;
+//								}
+//
+//								if (isNeedToClosePower)
+//								{
+//									SwitchPower(SYSTEM_CMD, PSU_POWER_OFF);
+//									FlashLed(SYSTEM_CMD, PSU_FLASH_NORMAL);
+//								}
+//							}
+//							else
+//							{
+								if (isStartOutputSwitch[groupIndex] &&
+										ShmSysConfigAndInfo->SysInfo.ReAssignedFlag == _REASSIGNED_NONE)
+								{
+									isStartOutputSwitch[groupIndex] = false;
+									SwitchPower(groupIndex, PSU_POWER_OFF); Await();
+									FlashLed(groupIndex, PSU_FLASH_NORMAL); Await();
+								}
+							//}
+
+							if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag >= _REASSIGNED_WAITING)
+								ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_COMP;
+						}
+					}
+					else if ((chargingInfo[groupIndex]->SystemStatus >= SYS_MODE_PREPARING && chargingInfo[groupIndex]->SystemStatus <= SYS_MODE_PREPARE_FOR_EV) &&
+						ShmSysConfigAndInfo->SysInfo.MainChargingMode == _MAIN_CHARGING_MODE_AVER)
+					{
+						//PRINTF_FUNC("%d ******** 7 \n", groupIndex);
+						if (isStartOutputSwitch[groupIndex])
+						{
+							isStartOutputSwitch[groupIndex] = false;
+							SwitchPower(groupIndex, PSU_POWER_OFF); Await();
+							FlashLed(groupIndex, PSU_FLASH_NORMAL); Await();
+						}
+					}
+				}
+
+				startModuleFlag = false;
+				break;
+			}
+			case _ALATON_MODE:
+			{
+//				int time = GetTimeoutMValue ( & _cmdSubPsuPriority_time );
+//
+//				if (time < 0)
+//					GetTimespecMFunc ( & _cmdSubPsuPriority_time );
+//
+//				// 低 Priority 的指令
+//				if (time > 1500)
+//				{
+//					PreCheckSmartChargingStep ();
+//					startModuleFlag = true;
+//					GetTimespecMFunc ( & _cmdSubPsuPriority_time );
+//				}
+//
+//				for (byte groupIndex = 0; groupIndex < _gunCount; groupIndex ++)
+//				{
+//					if (psuCmdSeq == _PSU_CMD_CAP)
+//					{
+//						// 取系統總輸出能力
+//						GetModuleCap ( groupIndex );
+//					}
+//					else if (psuCmdSeq == _PSU_CMD_OUTPUT)
+//					{
+//						// 取各群輸出電壓電流 (float)
+//						GetModuleOutputF ( groupIndex );
+//					}
+//					else if (psuCmdSeq == _PSU_CMD_IVAILIABLE)
+//					{
+//						// 取得模塊輸出額定電流能力
+//						GetModuleIavailable ( groupIndex );
+//					}
+//					else if (psuCmdSeq == _PSU_CMD_TEMP)
+//					{
+//						// 取得模塊溫度
+//						GetDcTemperature ( groupIndex );
+//					}
+//				}
+//
+//				Await ();
+//
+//				if (psuCmdSeq == _PSU_CMD_CAP)
+//					psuCmdSeq = _PSU_CMD_OUTPUT;
+//				else if (psuCmdSeq == _PSU_CMD_OUTPUT)
+//					psuCmdSeq = _PSU_CMD_IVAILIABLE;
+//				else if (psuCmdSeq == _PSU_CMD_IVAILIABLE)
+//					psuCmdSeq = _PSU_CMD_TEMP;
+//				else
+//					psuCmdSeq = _PSU_CMD_CAP;
+//
+//				for (byte psu = 0; psu < ShmPsuData->SystemPresentPsuQuantity; psu++)
+//				{
+//					if (psu == ShmDcCommonData->for_alston_test_1)
+//					{
+//						FlashSingleLed(psu, PSU_FLASH_NORMAL);
+//					}
+//					else
+//					{
+//						FlashSingleLed(psu, PSU_FLASH_ON);
+//					}
+//				}
+			}
+				break;
+			case _TEST_MODE:
+			{
+				// 在測試模式中,保持與模塊的通訊
+				int time = GetTimeoutMValue(&_cmdSubPsuPriority_time);
+
+				if (time < 0)
+					GetTimespecMFunc(&_cmdSubPsuPriority_time);
+
+				if (time > 1500)
+				{
+					for (byte index = 0; index < ShmPsuData->GroupCount; index++)
+					{
+						// 取系統總輸出能力
+						GetModuleCap(index); Await();
+
+						// 取各群輸出電壓電流 (float)
+						GetModuleOutputF(index); Await();
+					}
+
+					GetTimespecMFunc(&_cmdSubPsuPriority_time);
+				}
+
+				byte _switch = 0x00;
+				if ((chargingInfo[0]->EvBatterytargetVoltage * 10) > 0 && (chargingInfo[0]->EvBatterytargetCurrent * 10) > 0)
+					_switch = 0x01;
+
+				for (byte _groupCount_1 = 0; _groupCount_1 < ShmDcCommonData->conn_1_count; _groupCount_1++)
+				{
+					SetDirModulePresentOutput(ShmDcCommonData->connector[0][_groupCount_1],
+						(chargingInfo[0]->EvBatterytargetVoltage * 10),
+						(chargingInfo[0]->EvBatterytargetCurrent * 10),
+						_switch, _switch); Await();
+				}
+
+				for (byte _groupCount_2 = 0; _groupCount_2 < ShmDcCommonData->conn_2_count; _groupCount_2++)
+				{
+					SetDirModulePresentOutput(ShmDcCommonData->connector[1][_groupCount_2],
+						(chargingInfo[0]->EvBatterytargetVoltage * 10),
+						(chargingInfo[0]->EvBatterytargetCurrent * 10),
+						_switch, _switch); Await();
+				}
+			}
+				break;
+		}
+		usleep(20000);
+	}
+	return FAIL;
+}

+ 88 - 0
EVSE/Projects/NoodoeDS/Apps/Module_PsuComm.h

@@ -0,0 +1,88 @@
+#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/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 	<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];
+bool isStartOutputSwitch[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
+
+struct timespec _cmdSubPsuPriority_time;
+struct timespec _derating_time;
+struct timespec _max_time;
+struct timespec _log_time;
+
+byte _maxChargingStatus;
+bool isReadyToCharging = false;
+int preChargingTarget;
+int preChargingCur;
+
+float toAverVolPoint;
+byte toAverVolCount;
+
+byte _delayCount;
+
+//int connector_1[12];
+//int connector_2[12];
+//int connector[2][12];
+//byte conn_1_count = 0;
+//byte conn_2_count = 0;
+
+enum _CHARGING_GUN_STATUS
+{
+	_CHARGING_GUN_STATUS_NONE		= 0,
+	_CHARGING_GUN_STATUS_COMM,
+	_CHARGING_GUN_STATUS_CHARGING,
+	_CHARGING_GUN_STATUS_STOP
+};
+
+enum _PSU_CMD_SEQ
+{
+	_PSU_CMD_STATUS		= 1,
+	_PSU_CMD_VERSION	= 2,
+
+	_PSU_CMD_CAP		= 10,
+	_PSU_CMD_OUTPUT		= 11,
+	_PSU_CMD_IVAILIABLE	= 12,
+	_PSU_CMD_TEMP		= 13,
+	_PSU_CMD_GETCOUNT	= 14,
+};
+
+enum _CHARGING_LOG_INDEX
+{
+	_CHARGING_LOG_NEED_VOL = 0,
+	_CHARGING_LOG_NEED_CUR = 1,
+	_CHARGING_LOG_OUTPUT_VOL = 2,
+	_CHARGING_LOG_OUTPUT_CUR = 3
+};

+ 375 - 0
EVSE/Projects/NoodoeDS/Apps/OutputTask.c

@@ -0,0 +1,375 @@
+/*
+ * OutputTask.c
+ *
+ *  Created on: 2020年2月25日
+ *      Author: 7564
+ */
+
+#include 	"OutputTask.h"
+
+bool isOpen;
+
+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;
+}
+
+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;
+}
+
+void ShowMainMsg()
+{
+	printf("Max Vol : %f, Max Cur : %d, POW : %d \n", UnSafeDataInfo->PSU_VOLTAGE,
+			UnSafeDataInfo->PSU_CURRENT, UnSafeDataInfo->PSU_POWER);
+	printf("=> ");
+}
+
+void ChkButtonStatus()
+{
+	if (Button1 == PRESS && !leftBtnPush)
+	{
+		if(!leftBtnPush)
+		{
+			leftBtnPush = true;
+			if (_charging_mode == CHARGING_MODE_STOP)
+			{
+				_charging_mode = CHARGING_MODE_START;
+				printf("****************** Switch to Charging Mode ******************\n");
+			}
+		}
+		else if (Button1 == RELEASE)
+		{
+			if(leftBtnPush)
+			{
+				leftBtnPush = false;
+			}
+		}
+	}
+
+	if (Button2 == PRESS && !rightBtnPush)
+	{
+		if(!rightBtnPush)
+		{
+			rightBtnPush = true;
+			if (_charging_mode == CHARGING_MODE_START)
+			{
+				_charging_mode = CHARGING_MODE_TERMINATING;
+				printf("****************** Switch to Stop Mode ******************\n");
+			}
+		}
+		else if (Button2 == RELEASE)
+		{
+			if(rightBtnPush)
+			{
+				rightBtnPush = false;
+			}
+		}
+	}
+}
+
+void GetModuleCountCallback(byte group, byte count)
+{
+	//printf("group = %d, count = %d \n", group, count);
+	if (group == SYSTEM_CMD)
+		UnSafeDataInfo->PSU_COUNT = count;
+}
+
+void GetAvailableCapCallback(byte address, short maxVol, short minVol, short maxCur, short totalPow)
+{
+	int _groupPower = 0, _groupCurrent = 0;
+
+	UnSafeDataInfo->PsuModule[address].PSU_VOLTAGE_INFO = maxVol;
+	UnSafeDataInfo->PsuModule[address].PSU_CURRENT_INFO = maxCur;
+	UnSafeDataInfo->PsuModule[address].PSU_POWER_INFO = totalPow;
+
+	for (byte index = 0; index < UnSafeDataInfo->PSU_COUNT; index++)
+	{
+		_groupCurrent += UnSafeDataInfo->PsuModule[address].PSU_CURRENT_INFO;
+		_groupPower += UnSafeDataInfo->PsuModule[address].PSU_POWER_INFO;
+	}
+
+	UnSafeDataInfo->PSU_VOLTAGE = maxVol;
+	UnSafeDataInfo->PSU_CURRENT = _groupCurrent;
+	UnSafeDataInfo->PSU_POWER = _groupPower;
+}
+
+void GetStatusCallback(byte group, byte address, byte temp, int alarm)
+{
+	//printf("alarm = %d \n", alarm);
+}
+
+void GetInputVoltageCallback(byte address, unsigned short vol1, unsigned short vol2, unsigned short vol3)
+{
+	//printf("vol1 = %d, vol2 = %d, vol3 = %d \n", vol1, vol2, vol3);
+}
+
+int CreateShareMemory()
+{
+	int MeterSMId;
+
+	if ((MeterSMId = shmget(ShmTestKey,	sizeof(struct UnSafeData), IPC_CREAT | 0777)) < 0)
+	{
+		return 0;
+	}
+	else if ((UnSafeDataInfo = shmat(MeterSMId, NULL, 0))	== (void *) -1)
+	{
+		return 0;
+	}
+	memset(UnSafeDataInfo, 0, sizeof(struct UnSafeData));
+
+	return 1;
+}
+
+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 GetInputString()
+{
+	char word[128];
+	char newString[7][10];
+	int i, j, ctr;
+
+	get_char(word);
+
+	if (strlen(word) == 0)
+	    return;
+	//fgets(word, sizeof(word), stdin);
+
+	j = 0;
+	ctr = 0;
+	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++;
+		}
+	}
+
+	VOLTAGE = atof(newString[0]);
+	CURRENT = atof(newString[1]);
+	if (VOLTAGE <= UnSafeDataInfo->PSU_VOLTAGE && CURRENT <= UnSafeDataInfo->PSU_CURRENT)
+	{
+		//printf("OutputVol = %f, OutputCur = %f \n", VOLTAGE, CURRENT);
+	}
+	else
+	{
+		ShowMainMsg();
+	}
+}
+
+void GetIavailableCallback(byte address, unsigned short Iavail, unsigned short Vext)
+{
+	//printf("address = %d, Iavail = %d, Vext = %d \n", address, Iavail, Vext);
+}
+
+void GetOutputAndTempCallback(byte address, unsigned short outputVol,
+		unsigned short outputCur, unsigned short outputPower, unsigned char Temperature)
+{
+	//printf("***Output Value and Temp*** address = %d, Vol = %d, Cur = %d, Pow = %d, Temp = %d \n",
+	//		address, outputVol, outputCur, outputPower, Temperature);
+}
+
+void GetModuleStatusCallback(byte address, unsigned char isErr, unsigned char status,
+		unsigned char err1, unsigned char err2, unsigned char err3, unsigned char err4)
+{
+	//int alarm = (err2 << 24) | (err3 << 16) | (err4 << 8);
+
+	// err2 == state 2
+	// err3 == state 1
+	// err4 == state 0
+	//printf("***Status*** address = %d, alarm = %d \n", address, alarm);
+//	printf("***Status*** address = %d, err1 = %d, err2 = %d, err3 = %d, err4 = %d \n",
+//			address, err1,err2,err3,err4);
+}
+
+void GetModuleInputCallback(byte address, unsigned short inputR,
+		unsigned short inputS, unsigned short inputT)
+{
+
+}
+
+int main(void)
+{
+	isOpen =false;
+
+	if(CreateShareMemory() == 0)
+	{
+		printf("CreateShareMemory fail. \n");
+		return 0;
+	}
+	RefreshModuleCount(&GetModuleCountCallback);
+	RefreshAvailableCap(&GetAvailableCapCallback);
+
+	RefreshStatus(&GetStatusCallback);
+	RefreshInputVol(&GetInputVoltageCallback);
+
+	RefreshIavailable(&GetIavailableCallback);
+
+	AutoMode_RefreshOutputAndTemp(&GetOutputAndTempCallback);
+	AutoMode_RefreshModuleStatus(&GetModuleStatusCallback);
+	AutoMode_RefreshModuleInput(&GetModuleInputCallback);
+
+	Uart1Fd = InitComPort();
+	libInitialize = InitialCommunication();
+
+	if (Uart1Fd < 0 || !libInitialize)
+	{
+		printf("Initial port fail. \n");
+		return 0;
+	}
+
+	sleep(5);
+	gettimeofday(&_cmdSubUnSafetyPriority_time, NULL);
+	VOLTAGE = 0.0;
+	CURRENT = 0.0;
+
+	SwitchPower(SYSTEM_CMD, PSU_POWER_OFF);
+//	while (1)
+//	{
+//		printf("++++++++++++++2++++++++++++++++++++++++++++++++++++++\n");
+//		SetWalkInConfig(0, YES, 0);
+//		SetWalkInConfig(1, NO, 0);
+//		printf("++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
+//		sleep(1);
+//	}
+//
+//	sleep(1);
+//		printf("++++++++++++++2++++++++++++++++++++++++++++++++++++++\n");
+//		SetWalkInConfig(SYSTEM_CMD, NO, 0);
+//		printf("++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
+//	return 0;
+	while (1)
+	{
+		GetInputGpioStatus();
+		//ChkButtonStatus();
+		// 切換 Walk-in mode (default 5s -> 2s)
+		SetWalkInConfig(SYSTEM_CMD, NO, 0);
+
+		int time = GetTimeoutValue(_cmdSubUnSafetyPriority_time) / 1000;
+		while(isGetCount == YES)
+		{
+			if (_charging_mode == CHARGING_MODE_START)
+			{
+				// 取得模塊輸出額定電流能力
+				GetModuleIavailable(0);
+			}
+
+			GetInputString();
+			if (VOLTAGE > 150 && CURRENT >= 0)
+				_charging_mode = CHARGING_MODE_START;
+			else
+				_charging_mode = CHARGING_MODE_TERMINATING;
+			//printf("_charging_mode = %d \n", _charging_mode);
+			switch(_charging_mode)
+			{
+				case CHARGING_MODE_START:
+				{
+					if (!isOpen)
+					{
+						SwitchPower(SYSTEM_CMD, PSU_POWER_ON);
+						FlashLed(SYSTEM_CMD, PSU_FLASH_ON);
+						isOpen = true;
+//						SetDirModulePresentOutput(0,
+//												VOLTAGE * 10,
+//												CURRENT * 10,
+//												0x01,
+//												0x01);
+					}
+					PresentOutputVol(SYSTEM_CMD, VOLTAGE * 10, CURRENT * 10);
+				}
+					break;
+				case CHARGING_MODE_TERMINATING:
+				{
+					if (isOpen)
+					{
+//						SetDirModulePresentOutput(0,
+//							VOLTAGE * 10,
+//							CURRENT * 10,
+//							0x00,
+//							0x01);
+						SwitchPower(SYSTEM_CMD, PSU_POWER_OFF);
+						FlashLed(SYSTEM_CMD, PSU_FLASH_NORMAL);
+						isOpen = false;
+					}
+				}
+					break;
+			}
+			//GetStatus(0);
+			//GetModuleInput(0);
+			sleep(1);
+		}
+
+		if (UnSafeDataInfo->PSU_COUNT <= 0)
+		{
+			if (time > 1000)
+			{
+				printf("Step 1 : GetModuleCount...... \n");
+				GetModuleCount(SYSTEM_CMD);
+				gettimeofday(&_cmdSubUnSafetyPriority_time, NULL);
+			}
+		}
+		else if (time < 5000)
+		{
+			printf("Step 2 : GetModuleCap...... \n");
+			GetModuleCap(0);
+
+			SwitchPower(SYSTEM_CMD, PSU_POWER_OFF);
+			FlashLed(SYSTEM_CMD, PSU_FLASH_NORMAL);
+		}
+		else
+		{
+			ShowMainMsg();
+			isGetCount = YES;
+		}
+
+		sleep(1);
+	}
+
+	return 0;
+}
+
+

+ 174 - 0
EVSE/Projects/NoodoeDS/Apps/OutputTask.h

@@ -0,0 +1,174 @@
+/*
+ * OutputTask.h
+ *
+ *  Created on: 2020¦~2¤ë25¤é
+ *      Author: 7564
+ */
+
+#ifndef OUTPUTTASK_H_
+#define OUTPUTTASK_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>
+#include 	<stdbool.h>
+
+#define ShmTestKey	2001
+
+#define ARRAY_SIZE(A)		(sizeof(A) / sizeof(A[0]))
+#define PASS				1
+#define FAIL				-1
+#define YES					1
+#define NO					0
+#define PRESS				1
+#define RELEASE				0
+#define MAX_PSU_QUANTITY        62
+
+int Uart1Fd = -1;
+char *priPortName = "/dev/ttyS1";
+
+bool libInitialize = false;
+struct timeval _cmdSubUnSafetyPriority_time;
+
+unsigned char Button1 = RELEASE;
+unsigned char Button2 = RELEASE;
+bool leftBtnPush = false;
+bool rightBtnPush = false;
+
+unsigned char _psuCount = 0;
+unsigned char isGetCount = NO;
+
+float VOLTAGE;
+float CURRENT;
+
+struct PsuModuleInfo
+{
+	unsigned int 	PSU_POWER_INFO;
+	float			PSU_VOLTAGE_INFO;
+	unsigned short	PSU_CURRENT_INFO;
+};
+
+struct UnSafeData
+{
+	unsigned char 			PSU_COUNT;
+	struct PsuModuleInfo 	PsuModule[MAX_PSU_QUANTITY];
+	unsigned int 			PSU_POWER;
+	float					PSU_VOLTAGE;
+	unsigned short			PSU_CURRENT;
+};
+
+struct UnSafeData			*UnSafeDataInfo;
+
+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;
+
+Gpio_in gpio_in;
+
+enum CHARGING_MODE
+{
+	CHARGING_MODE_STOP = 			0x00,
+	CHARGING_MODE_START = 			0x01,
+	CHARGING_MODE_TERMINATING = 	0x10,
+};
+
+unsigned char _charging_mode = CHARGING_MODE_STOP;
+
+int tranceive(int fd, unsigned char* cmd, unsigned char cmd_len, unsigned char* rx)
+{
+	int len;
+	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_Gpio_Input(unsigned char fd, unsigned char targetAddr, Gpio_in *Ret_Buf)
+{
+	unsigned char result = FAIL;
+	unsigned char tx[7] = {0xaa, 0x00, targetAddr, 0x0a, 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->Button[0] 			= (rx[7] >> 1) & 0x01;
+			Ret_Buf->Button[1] 			= (rx[7] >> 2) & 0x01;
+
+			result = PASS;
+		}
+	}
+
+	return result;
+}
+
+void GetInputGpioStatus()
+{
+	if (Query_Gpio_Input(Uart1Fd, 0x04, &gpio_in) == PASS)
+	{
+		Button1 = gpio_in.Button[0];
+		Button2 = gpio_in.Button[1];
+	}
+}
+
+#endif /* OUTPUTTASK_H_ */

+ 438 - 0
EVSE/Projects/NoodoeDS/Apps/PrimaryComm.c

@@ -0,0 +1,438 @@
+#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/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 	<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,0x2C,0x83,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 Query_Meter_value(unsigned char fd, unsigned char targetAddr, struct StructMeter *Ret_Buf, byte *isWork, unsigned char index)
+{
+	unsigned char result = FAIL;
+	unsigned char tx[8] = {0xaa, 0x00, targetAddr, Cmd.query_charging_power, 0x01, 0x00, index, 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;
+
+	unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
+	if(len > 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]))
+		{
+			Ret_Buf->newMeterValue = (rx[6] | (rx[7]<<8) | (rx[8]<<8) | (rx[9]<<8));
+			*isWork = rx[23];
+			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 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] == PASS)
+		{
+			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;
+}
+

+ 84 - 0
EVSE/Projects/NoodoeDS/Apps/PrimaryComm.h

@@ -0,0 +1,84 @@
+#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 query_charging_power;	// 0x2C
+
+	unsigned char config_Model_Name;			//0x83
+	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 Query_Meter_value(unsigned char fd, unsigned char targetAddr, struct StructMeter *Ret_Buf, byte *isWork, unsigned char index);
+
+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);
+unsigned char Config_Model_Name(unsigned char fd, unsigned char targetAddr, unsigned char *modelname);
+// 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_ */

BIN
EVSE/Projects/NoodoeDS/Apps/ReadCmdline


+ 1944 - 0
EVSE/Projects/NoodoeDS/Apps/ReadCmdline.c

@@ -0,0 +1,1944 @@
+/*
+ * 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 EQUAL				0
+#define ARRAY_SIZE(A)		(sizeof(A) / sizeof(A[0]))
+#define NO_DEFINE			255
+#define DEFAULT_AC_INDEX	2
+#define YES					1
+#define NO					0
+
+#define AUTORUN_STEP1_TIME_START			140				// Minutes
+#define AUTORUN_STEP1_TIME_END				150
+#define AUTORUN_STEP2_TIME_START			210
+#define AUTORUN_STEP2_TIME_END				410
+#define AUTORUN_END_TIME					480
+#define AUTORUN_CYCLE_COUNT					30
+
+#define TTY_PATH            "/dev/tty"
+#define STTY_US             "stty raw -echo -F "
+#define STTY_DEF            "stty -raw echo -F "
+
+byte _curAutoRunCount = 0;
+byte _usingAutoRun = 0;
+struct timeval _autoTime;
+
+struct timeb 					startChargingTime;
+struct timeb 					endChargingTime;
+int 							_presentChargingTimeBuf;
+int 							chargingTime;
+//struct timeval 					_printf_time;
+
+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 LedModuleData			*ShmLedModuleData;
+struct PsuData 					*ShmPsuData;
+struct DcCommonInformation		*ShmDcCommonData;
+struct OCPP16Data				*ShmOCPP16Data;
+
+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;
+   	}
+
+   	//initial ShmStatusCodeData
+   	if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData),  0777)) < 0)
+    {
+   		result = FAIL;
+	}
+    else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
+    {
+    	result = FAIL;
+   	}
+
+	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;
+		}
+	}
+
+   	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(ShmLedBdKey, sizeof(struct LedModuleData),  0777)) < 0)
+   	{
+   		result = FAIL;
+   	}
+   	else if ((ShmLedModuleData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
+   	{
+   		result = FAIL;
+   	}
+
+   	if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
+   	{
+   		result = FAIL;
+   	}
+   	else if ((ShmOCPP16Data = 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;
+   	}
+
+   	if ((MeterSMId = shmget(ShmCommonKey, sizeof(struct DcCommonInformation), IPC_CREAT | 0777)) < 0)
+   	{
+   		result = FAIL;
+   	}
+   	else if ((ShmDcCommonData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
+   	{
+   		result = FAIL;
+   	}
+
+    return result;
+}
+
+unsigned long GetTimeoutValue(struct timeval _sour_time)
+{
+	struct timeval _end_time;
+	gettimeofday(&_end_time, NULL);
+
+	return (_end_time.tv_sec - _sour_time.tv_sec);
+}
+
+void PrintConnectorState(byte state)
+{
+	switch(state)
+	{
+		case SYS_MODE_BOOTING: printf("Status = Booting.... \n"); break;
+		case SYS_MODE_IDLE: printf("Status = Idle \n"); break;
+		case SYS_MODE_AUTHORIZING: printf("Status = Authorized \n"); break;
+		case SYS_MODE_MODE_REASSIGN_CHECK: printf("Status = check to change to balance mode \n"); break;
+		case SYS_MODE_REASSIGN: printf("Status = Waiting to change the balance mode \n"); break;
+		case SYS_MODE_PREPARING: printf("Status = Preparing \n"); break;
+		case SYS_MODE_PREPARE_FOR_EV: printf("Status = Waiting for EV side (slac...) \n"); break;
+		case SYS_MODE_PREPARE_FOR_EVSE : printf ( "Status = Waiting for GFD \n" ); break;
+		case SYS_MODE_CHARGING : printf ( "Status = Charging \n" ); break;
+		case SYS_MODE_TERMINATING : printf ( "Status = Terminating \n" ); break;
+		case SYS_MODE_COMPLETE : printf ( "Status = Complete \n" ); break;
+		case SYS_MODE_ALARM : printf ( "Status = Alarm \n" ); break;
+		case SYS_MODE_FAULT : printf ( "Status = Fault \n" ); break;
+		case SYS_MODE_RESERVATION : printf ( "Status = Reserved \n" ); break;
+		case SYS_MODE_MAINTAIN : printf ( "Status = Maintain \n" ); break;
+		case SYS_MODE_CCS_PRECHARGE_STEP0 : printf ( "Status = Precahrge Start \n" ); break;
+		case SYS_MODE_CCS_PRECHARGE_STEP1 : printf ( "Status = Precharge End \n" ); break;
+		case SYS_MODE_UPDATE : printf ( "Status = Updating ....  \n" ); break;
+	}
+}
+
+void PrintChargingMode(byte mode)
+{
+	switch(mode)
+	{
+		case _MAIN_CHARGING_MODE_MAX: printf("Charging mode = Max \n"); break;
+		case _MAIN_CHARGING_MODE_AVER: printf("Charging mode = Balance \n"); break;
+	}
+}
+
+void PrintLcmPageName(byte page)
+{
+	switch(page)
+	{
+		case _LCM_INIT: 			printf ( "LCM Page = Init \n" ); break;
+		case _LCM_IDLE: 			printf ( "LCM Page = Idle \n" ); break;
+		case _LCM_WAIT_FOR_PLUG: 	printf ( "LCM Page = Waiting for plug \n" ); break;
+		case _LCM_PRE_CHARGE: 		printf ( "LCM Page = Precharge \n" ); break;
+		case _LCM_CHARGING: 		printf ( "LCM Page = Charging \n" ); break;
+		case _LCM_COMPLETE: 		printf ( "LCM Page = Complete \n" ); break;
+		case _LCM_FIX: 				printf ( "LCM Page = Fix \n" ); break;
+		case _LCM_EMC: 				printf ( "LCM Page = EMC \n" ); break;
+	}
+}
+
+void PrintAcCpStatus(byte cp)
+{
+	switch(cp)
+	{
+		case AC_SYS_A: printf ( "AC CpStatus = State A \n" ); break;
+		case AC_SYS_B: printf ( "AC CpStatus = State B \n" ); break;
+		case AC_SYS_C: printf ( "AC CpStatus = State C \n" ); break;
+		case AC_SYS_F: printf ( "AC CpStatus = State F \n" ); break;
+	}
+}
+
+void RunStatusProc(char *v1, char *v2)
+{
+	if (strcmp(v1, "ac") == 0)
+	{
+		if (!FindAcChargingInfoData(0, &ac_chargingInfo[0]))
+		{
+			printf("FindChargingInfoData (AC) false \n");
+		}
+		PrintConnectorState(ac_chargingInfo[0]->SystemStatus);
+		PrintAcCpStatus(ac_chargingInfo[0]->ConnectorPlugIn);
+		return;
+	}
+
+	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
+			PrintConnectorState(_chargingData[_index]->SystemStatus);
+			PrintChargingMode(ShmSysConfigAndInfo->SysInfo.MainChargingMode);
+			PrintLcmPageName(ShmSysConfigAndInfo->SysInfo.PageIndex);
+			printf ("SystemTimeoutFlag = %d\n", ShmSysConfigAndInfo->SysInfo.SystemTimeoutFlag );
+			printf ("SOC = %d \n", _chargingData[_index]->EvBatterySoc);
+			printf ("Maximum battery Voltage = %f \n", _chargingData[_index]->EvBatteryMaxVoltage);
+			printf("maxTemp = %d, temp-I = %d, temp-II = %d \n",
+				_chargingData[_index]->ConnectorTemp - 60,
+				ShmDcCommonData->ConnectorTemp1[_index] - 60,
+				ShmDcCommonData->ConnectorTemp2[_index] - 60);
+			printf ("index = %x, Available = %d \n", _index, _chargingData[_index]->IsAvailable);
+		}
+		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);
+		}
+	}
+
+	printf("OrderCharging = %d \n", ShmSysConfigAndInfo->SysInfo.OrderCharging);
+	printf("WaitForPlugit = %d \n", ShmSysConfigAndInfo->SysInfo.WaitForPlugit);
+}
+
+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
+	{
+		strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
+		memcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, v1, strlen(v1));
+		ShmSysConfigAndInfo->SysConfig.UserId[strlen(v1)] = '\0';
+		printf("StartUserId = %s \n", ShmSysConfigAndInfo->SysConfig.UserId);
+	}
+}
+
+void RunGunPlugitProc(char *v1, char *v2)
+{
+	if (strcmp(v1, "ac") == 0)
+	{
+		if (!FindAcChargingInfoData(0, &ac_chargingInfo[0]))
+		{
+			printf("FindChargingInfoData (AC) false \n");
+		}
+
+		if (strcmp(v2, "-1") == 0 || strcmp(v2, "") == 0)
+		{
+			// get
+			printf("ConnectorPlugIn = %d \n", ac_chargingInfo[0]->ConnectorPlugIn);
+		}
+		else
+		{
+			// set
+			ac_chargingInfo[0]->ConnectorPlugIn = atoi(v2);
+		}
+		return;
+	}
+
+	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;
+	}
+	if (strcmp(v2, "-1") != 0 && strcmp(v2, "") != 0)
+	{
+		_chargingData[_index]->GunLocked = atoi(v2);
+	}
+
+	printf("Gun Locked Status = %d \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 || strcmp(v1, "1") == 0)
+	{
+		int _index = atoi(v1);
+
+		if (_index == 0)
+			printf("Gun 0 FW Version = %s \n", ShmSysConfigAndInfo->SysInfo.Connector1FwRev);
+		else if (_index == 1)
+			printf("Gun 1 FW Version = %s \n", ShmSysConfigAndInfo->SysInfo.Connector2FwRev);
+	}
+	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, "led") == 0)
+	{
+		printf("LED Version = %s \n", ShmSysConfigAndInfo->SysInfo.LedModuleFwRev);
+	}
+	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);
+	}
+	else if (strcmp(v1, "all") == 0)
+	{
+		printf("DC Main Version = %s \n", ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
+		printf("407 FW Version = %s \n", ShmPrimaryMcuData->version);
+		printf("Gun 0 FW Version = %s \n", ShmSysConfigAndInfo->SysInfo.Connector1FwRev);
+		printf("Gun 1 FW Version = %s \n", ShmSysConfigAndInfo->SysInfo.Connector2FwRev);
+		printf("RB Version = %s \n", ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev);
+		printf("FAN Version = %s \n", ShmSysConfigAndInfo->SysInfo.FanModuleFwRev);
+		printf("LED Version = %s \n", ShmSysConfigAndInfo->SysInfo.LedModuleFwRev);
+		if (!FindAcChargingInfoData(0, &ac_chargingInfo[0]))
+		{
+			printf("FindChargingInfoData (AC) false \n");
+		}
+		printf("AC Version = %s \n", ac_chargingInfo[0]->version);
+		printf("LcmHwRev = %s \n", ShmSysConfigAndInfo->SysInfo.LcmHwRev);
+	}
+}
+
+void CreateOneError()
+{
+	for (byte i = 0; i < ShmSysConfigAndInfo->SysWarningInfo.WarningCount; i++)
+	{
+		printf("(%d). %s \n", i, &ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0]);
+	}
+
+}
+
+void GetAuthorizeFlag(char *v1)
+{
+	if (strcmp(v1, "-1") == 0|| strcmp(v1, "") == 0)
+		printf("AuthorizeFlag = %d \n", ShmSysConfigAndInfo->SysInfo.AuthorizeFlag);
+	else
+		ShmSysConfigAndInfo->SysInfo.AuthorizeFlag = atoi(v1);
+}
+
+void GetRelayStatus(char *v1)
+{
+	int _index = atoi(v1);
+	if (!FindChargingInfoData(_index, &_chargingData[0]))
+	{
+		printf("FindChargingInfoData error\n");
+		return;
+	}
+
+	printf("RelayK1K2Status = %d \n", _chargingData[_index]->RelayK1K2Status);
+	printf("RelayKPK2Status = %d \n", _chargingData[_index]->RelayKPK2Status);
+}
+
+void GetSOC(char *v1)
+{
+	int _index = atoi(v1);
+	if (!FindChargingInfoData(_index, &_chargingData[0]))
+	{
+		printf("FindChargingInfoData error\n");
+		return;
+	}
+
+	printf("Soc = %d \n", _chargingData[_index]->EvBatterySoc);
+}
+
+void FwUpdateFlagProc()
+{
+	ShmSysConfigAndInfo->SysInfo.FirmwareUpdate = 0x01;
+}
+
+void CheckAcStatus(char *v1)
+{
+	if (strcmp(v1, "-1") == 0|| strcmp(v1, "") == 0)
+	{
+		printf("AC 1Status = %d \n", ShmSysConfigAndInfo->SysInfo.AcContactorStatus);
+		printf("AC 2Status = %d \n", ShmPrimaryMcuData->InputDet.bits.AcContactorDetec);
+		printf("AC 3Status = %d \n", ShmDcCommonData->psuKeepCommunication);
+		printf("AC EmergencyButton = %d \n", ShmPrimaryMcuData->InputDet.bits.EmergencyButton);
+		printf("AC acContactSwitch = %d \n", ShmDcCommonData->acContactSwitch);
+	}
+	else
+		ShmSysConfigAndInfo->SysInfo.AcContactorStatus = atoi(v1);
+}
+
+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 SetChargingInfoCCID(char *v1, char* v2)
+{
+	int _index = atoi(v1);
+	if (!FindChargingInfoData(_index, &_chargingData[0]))
+	{
+		printf ("FindChargingInfoData error\n");
+		return;
+	}
+
+	memcpy(_chargingData[_index]->EVCCID, v2, strlen(v2));
+	_chargingData[_index]->EVCCID[strlen(v2)] = '\0';
+}
+
+void GetGunTemp(char *v1)
+{
+	int _index = atoi(v1);
+	if (!FindChargingInfoData(_index, &_chargingData[0]))
+	{
+		printf ("FindChargingInfoData error\n");
+		return;
+	}
+
+	printf("Gun_%d, maxTemp = %d, temp 1 = %d, temp 2 = %d \n",
+			_index,
+			_chargingData[_index]->ConnectorTemp - 60,
+			ShmDcCommonData->ConnectorTemp1[_index] - 60,
+			ShmDcCommonData->ConnectorTemp2[_index] - 60);
+}
+
+void GetOffered(char *v1)
+{
+	int _index = atoi(v1);
+	if (!FindChargingInfoData(_index, &_chargingData[0]))
+	{
+		printf ("FindChargingInfoData error\n");
+		return;
+	}
+
+	printf("Gun_%d, PowerOffered = %f, CurrentOffered = %f \n",
+			_index,
+			_chargingData[_index]->PowerOffered,
+			_chargingData[_index]->CurrentOffered);
+}
+
+void GetEvStatus(char *v1)
+{
+	int _index = atoi(v1);
+	if (!FindChargingInfoData(_index, &_chargingData[0]))
+	{
+		printf ("FindChargingInfoData error\n");
+		return;
+	}
+
+	if (_chargingData[_index]->Type == _Type_Chademo)
+		printf ("Chademo status= %d \n", ShmCHAdeMOData->evse[_chargingData[_index]->type_index].EvboardStatus);
+	else if (_chargingData[_index]->Type == _Type_CCS)
+		printf ("CCS status= %d \n", ShmCcsData->V2GMessage_DIN70121[_chargingData[_index]->type_index].PresentMsgFlowStatus);
+	else if (_chargingData[_index]->Type == _Type_GB)
+		printf ("GBT status = %d \n", ShmGBTData->evse[_chargingData[_index]->type_index].EvboardStatus);
+}
+
+void GetDcMeterInfor(char *v1)
+{
+	int _index = atoi(v1);
+	if (!FindChargingInfoData(_index, &_chargingData[0]))
+	{
+		printf ("FindChargingInfoData error\n");
+		return;
+	}
+
+	printf("Index = %d, LinkStatus = %d presetVoltage = %f, presentCurrent = %f, presentPower = %f, totlizeImportEnergy = %f, totlizeExportEnergy = %f \n",
+			_index,
+			ShmSysConfigAndInfo->SysInfo.DcMeterInfo[_index].LinkStatus,
+			ShmSysConfigAndInfo->SysInfo.DcMeterInfo[_index].presetVoltage,
+			ShmSysConfigAndInfo->SysInfo.DcMeterInfo[_index].presentCurrent,
+			ShmSysConfigAndInfo->SysInfo.DcMeterInfo[_index].presentPower,
+			ShmSysConfigAndInfo->SysInfo.DcMeterInfo[_index].totlizeImportEnergy,
+			ShmSysConfigAndInfo->SysInfo.DcMeterInfo[_index].totlizeExportEnergy);
+}
+
+void GetPowerValue()
+{
+	for (byte index = 0; index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; index++)
+	{
+		if (!FindChargingInfoData(index, &_chargingData[0]))
+		{
+			printf ("FindChargingInfoData error\n");
+			return;
+		}
+
+		printf ("index = %d, PresentChargingPower = %f \n", index, _chargingData[index]->PresentChargingPower);
+	}
+}
+
+void GetSystemInfo()
+{
+	printf ("ModelName = %s \n", ShmSysConfigAndInfo->SysConfig.ModelName);
+	printf ("SerialNumber = %s \n", ShmSysConfigAndInfo->SysConfig.SerialNumber);
+	printf ("InternetConn = %d \n", ShmSysConfigAndInfo->SysInfo.InternetConn);
+
+	printf ("PSU : MaxChargingPower = %d, MaxChargingCurrent = %d \n",
+			ShmPsuData->SystemAvailablePower / 10,
+			ShmPsuData->SystemAvailableCurrent / 10
+			);
+
+	printf ("Config : ChargingPower = %d, ChargingCurrent = %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 ShowSysInformation()
+{
+	if (!ShmSysConfigAndInfo->SysConfig.ShowInformation)
+		ShmSysConfigAndInfo->SysConfig.ShowInformation = 0x01;
+	else
+		ShmSysConfigAndInfo->SysConfig.ShowInformation = 0x00;
+
+	printf("Show inform = %d \n", ShmSysConfigAndInfo->SysConfig.ShowInformation);
+}
+
+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()
+{
+	char _ex_maxTemp = 0;
+	char _cr_maxTemp = 0;
+
+	for (byte index = 0; index < ShmPsuData->GroupCount; index++)
+	{
+		_ex_maxTemp = 0;
+		_cr_maxTemp = 0;
+		for (byte count = 0; count < ShmPsuData->PsuGroup[index].GroupPresentPsuQuantity; count++)
+		{
+			if (ShmPsuData->PsuGroup[index].PsuModule[count].ExletTemp > _ex_maxTemp)
+				_ex_maxTemp = ShmPsuData->PsuGroup[index].PsuModule[count].ExletTemp;
+			if (ShmPsuData->PsuGroup[index].PsuModule[count].CriticalTemp1 > _cr_maxTemp)
+				_cr_maxTemp = ShmPsuData->PsuGroup[index].PsuModule[count].CriticalTemp1;
+		}
+		printf("D.D. Temp = %d ------ Env Temp = %d \n", _ex_maxTemp, _cr_maxTemp);
+	}
+}
+
+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, char *v2, char *v3)
+{
+	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, "input") == 0)
+	{
+		for (int i = 0; i < ShmPsuData->GroupCount; i++)
+		{
+			for (byte count = 0; count < ShmPsuData->PsuGroup[i].GroupPresentPsuQuantity; count++)
+			{
+				printf("gp = %d, Index = %d, volR = %d, volS = %d, volT = %d \n",
+						i, count,
+						ShmPsuData->PsuGroup[i].PsuModule[count].InputVoltageL1,
+						ShmPsuData->PsuGroup[i].PsuModule[count].InputVoltageL2,
+						ShmPsuData->PsuGroup[i].PsuModule[count].InputVoltageL3);
+			}
+		}
+	}
+	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);
+		}
+
+		for (int i = 0; i < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; i++)
+		{
+			if (!FindChargingInfoData(i, &_chargingData[0]))
+			{
+				printf ("FindChargingInfoData error\n");
+				continue;
+			}
+
+			printf("From RB : Group Index = %d, OutputV = %f \n",
+				i, _chargingData[i]->FireChargingVoltage);
+		}
+	}
+	else if (strcmp(v1, "test") == 0)
+	{
+		int mode = atoi(v2);
+
+		if (mode >= _TEST_MODE && mode <= _TEST_MODE)
+		{
+			ShmPsuData->Work_Step = mode;
+		}
+	}
+	else if (strcmp(v1, "out") == 0)
+	{
+		float vol = atof(v2);
+		float cur = atof(v3);
+
+		if (ShmPsuData->Work_Step >= _TEST_MODE && ShmPsuData->Work_Step <= _TEST_MODE)
+		{
+			if (!FindChargingInfoData(0, &_chargingData[0]))
+			{
+				printf ("FindChargingInfoData error\n");
+				return;
+			}
+			_chargingData[0]->EvBatterytargetVoltage = vol;
+			_chargingData[0]->EvBatterytargetCurrent = cur;
+		}
+	}
+	else if (strcmp(v1, "force") == 0)
+	{
+		ShmPsuData->Work_Step = _ALATON_MODE;
+		byte id = atof(v2);
+
+		ShmDcCommonData->for_alston_test_1 = id;
+	}
+	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 AverageCharging(char *g1_vol, char *g1_cur, char *g2_vol, char *g2_cur)
+{
+	float _Voltage[2];
+	float _Current[2];
+
+	_Voltage[0] = atof(g1_vol);
+	_Current[0] = atof(g1_cur);
+
+	_Voltage[1] = atof(g2_vol);
+	_Current[1] = atof(g2_cur);
+
+	printf ("g1_vol = %f, g1_cur = %f pow1 = %f (KW) \n", _Voltage[0], _Current[0], (_Voltage[0] * _Current[0]) / 1000);
+	printf ("g2_vol = %f, g2_cur = %f pow2 = %f (KW) \n", _Voltage[1], _Current[1], (_Voltage[1] * _Current[1]) / 1000);
+
+	if(_Voltage[0] > 1000 || _Voltage[0] < 50 ||
+			_Voltage[1] > 1000 || _Voltage[1] < 50)
+	{
+		printf ("Input Voltage over range\n");
+	    return;
+	}
+
+	for (byte _index = 0; _index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _index++)
+	{
+		if (!FindChargingInfoData(_index, &_chargingData[0]))
+		{
+			printf("AverageCharging : FindChargingInfoData false \n");
+			return;
+		}
+		//不論是什麼 type 的槍都固意設成 Chademo 不跑 Prechage step
+		_chargingData[_index]->Type = 9;
+	}
+	sleep(1);
+	system("killall Module_EvComm");
+
+	unsigned char PreviousSystemStatus[2] = {0xff, 0xff};
+	bool isComplete[2] = {false, false};
+
+	while(1)
+	{
+		for (byte gun_index = 0; gun_index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gun_index++)
+		{
+			switch(_chargingData[gun_index]->SystemStatus)
+			{
+				case SYS_MODE_IDLE:
+				{
+					if(PreviousSystemStatus[gun_index] != _chargingData[gun_index]->SystemStatus)
+					{
+						PreviousSystemStatus[gun_index] = _chargingData[gun_index]->SystemStatus;
+					    printf ("[AverageCharging (%d) - SYS_MODE_IDLE] \n", gun_index);
+					}
+
+					ShmDcCommonData->StartToChargingFlag[gun_index] = 0x01;
+					_chargingData[gun_index]->SystemStatus = SYS_MODE_PREPARING;
+				}
+					break;
+				case SYS_MODE_PREPARING:
+				{
+					if(PreviousSystemStatus[gun_index] != _chargingData[gun_index]->SystemStatus)
+				    {
+						PreviousSystemStatus[gun_index] = _chargingData[gun_index]->SystemStatus;
+						printf ("[AverageCharging (%d) - S_PREPARNIN] \n", gun_index);
+
+						//等待 AC Relay 搭上且找到模組 (main 在此 statue 其它 task 會去做完)
+				        printf ("wait find module\n");
+				    }
+
+					ShmSysConfigAndInfo->SysInfo.MainChargingMode = _MAIN_CHARGING_MODE_AVER;
+				    //清除 main timeout 機制
+					_chargingData[gun_index]->TimeoutFlag = 0;
+				}
+					break;
+				case SYS_MODE_PREPARE_FOR_EV:
+				{
+					if(PreviousSystemStatus[gun_index] != _chargingData[gun_index]->SystemStatus)
+				    {
+				    	PreviousSystemStatus[gun_index] = _chargingData[gun_index]->SystemStatus;
+				        printf ("[AverageCharging (%d) - SYS_MODE_PREPARE_FOR_EV] \n", gun_index);
+				        printf ("ReqVoltage = %f, ReqCurrent = %f \n", _Voltage[gun_index] * 10, _Current[gun_index] * 10);
+				    }
+				    //清除 main timeout 機制
+				    _chargingData[gun_index]->TimeoutFlag = 0;
+				    //不論是什麼 type 的槍都固意設成 Chademo 不跑 Prechage step
+				    _chargingData[gun_index]->Type = 9;
+
+				    //充電電壓電流
+				    _chargingData[gun_index]->EvBatterySoc = 50;
+				   	_chargingData[gun_index]->EvBatterytargetVoltage = 500;
+				    _chargingData[gun_index]->EvBatterytargetCurrent = 2;
+				    _chargingData[gun_index]->AvailableChargingCurrent = 1000;
+
+				    //****** 注意~此行為是防止 K1K2 先開導到無法升壓 ( Relay Board 在此 state 還未搭上 K1K2 )
+				    //確定模組己升壓完成
+				    //if(_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingVoltage <=  (3000+500) &&
+				    		 //  _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingVoltage >=  (3000-500) )
+				    {
+				    	printf ("Preparing Done = %f \n", _chargingData[gun_index]->PresentChargingVoltage);
+				    	//EV done
+				    	_chargingData[gun_index]->SystemStatus = SYS_MODE_PREPARE_FOR_EVSE;
+				    }
+				}
+					break;
+				case SYS_MODE_PREPARE_FOR_EVSE:
+				{
+					if(PreviousSystemStatus[gun_index] != _chargingData[gun_index]->SystemStatus)
+					{
+						PreviousSystemStatus[gun_index] = _chargingData[gun_index]->SystemStatus;
+						printf ("[AverageCharging (%d) - SYS_MODE_PREPARE_FOR_EVSE]\n", gun_index);
+					}
+
+					//printf ("tar vol = %d \n", _Voltage);
+					//printf ("tar cur = %d \n", _Current);
+
+					//清除 main timeout 機制
+					_chargingData[gun_index]->TimeoutFlag = 0;
+					//不論是什麼 type 的槍都固意設成 Chademo 不跑 Prechage step
+					_chargingData[gun_index]->Type = 9;
+
+					//充電電壓電流
+					_chargingData[gun_index]->EvBatterySoc = 50;
+					_chargingData[gun_index]->EvBatterytargetVoltage = 500;
+					_chargingData[gun_index]->EvBatterytargetCurrent = 2;
+					_chargingData[gun_index]->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[gun_index]->GroundFaultStatus == 0x01 ||
+						_chargingData[gun_index]->GroundFaultStatus == 0x03)
+					{
+						printf ("First Ground Fault State (%d)\n",_chargingData[gun_index]->GroundFaultStatus);
+						printf ("Wait K1K2 = %f \n", _chargingData[gun_index]->PresentChargingVoltage);
+						sleep(5);
+						//EV done
+						_chargingData[gun_index]->SystemStatus = SYS_MODE_CHARGING;
+					}
+					else if (_chargingData[gun_index]->GroundFaultStatus > 0x02)
+					{
+						printf ("First Ground Fault check Fail (%d)\n",_chargingData[gun_index]->GroundFaultStatus);
+						_chargingData[gun_index]->SystemStatus = SYS_MODE_TERMINATING;
+					}
+				}
+					break;
+				case SYS_MODE_CHARGING:
+				{
+					if(PreviousSystemStatus[gun_index] != _chargingData[gun_index]->SystemStatus)
+				    {
+				        PreviousSystemStatus[gun_index] = _chargingData[gun_index]->SystemStatus;
+
+				        //充電電壓電流
+				        _chargingData[gun_index]->EvBatterytargetVoltage = _Voltage[gun_index];
+				        _chargingData[gun_index]->EvBatterytargetCurrent = _Current[gun_index];
+				        _chargingData[gun_index]->EvBatterySoc = 50;
+				        _chargingData[gun_index]->AvailableChargingCurrent = 1000;
+
+				        printf ("[AverageCharging (%d) - SYS_MODE_CHARGING]\n", gun_index);
+				    }
+
+				    //ev task do this
+				    _chargingData[gun_index]->PresentChargingPower =
+				    ((float)((_chargingData[gun_index]->PresentChargingVoltage) * (_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingCurrent)) / 1000);
+
+				    if (_chargingData[gun_index]->GroundFaultStatus == 0x02)
+				    {
+				    	printf ("Charging Ground Fault check Fail (%d)\n",_chargingData[gun_index]->GroundFaultStatus);
+				    	_chargingData[gun_index]->SystemStatus = SYS_MODE_TERMINATING;
+				    }
+				}
+				    break;
+				case SYS_MODE_TERMINATING:
+				{
+					if(PreviousSystemStatus[gun_index] != _chargingData[gun_index]->SystemStatus)
+				    {
+						PreviousSystemStatus[gun_index] = _chargingData[gun_index]->SystemStatus;
+				        printf ("[AverageCharging (%d) - SYS_MODE_TERMINATING] \n", gun_index);
+				        //無阻塞偵測 keybaord 結束
+				        system(STTY_DEF TTY_PATH);
+				    }
+
+				    sleep(3);
+				    _chargingData[gun_index]->SystemStatus = SYS_MODE_COMPLETE;
+				}
+				    break;
+				case SYS_MODE_COMPLETE:
+				{
+				    if(PreviousSystemStatus[gun_index] != _chargingData[gun_index]->SystemStatus)
+				    {
+				    	PreviousSystemStatus[gun_index] = _chargingData[gun_index]->SystemStatus;
+				    	printf ("[AverageCharging (%d) - SYS_MODE_COMPLETE] \n", gun_index);
+				    }
+
+				    _chargingData[gun_index]->PresentChargingPower = 0;
+				    isComplete[gun_index] = true;
+				    sleep(3);
+				}
+				    break;
+			}
+		}
+
+		if (isComplete[0] == true && isComplete[1] == true)
+			return;
+
+		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], "c") == 0)
+		{
+			for (byte gun_index = 0; gun_index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gun_index++)
+			{
+				ShmDcCommonData->StartToChargingFlag[gun_index] = 0x00;
+				_chargingData[gun_index]->SystemStatus = SYS_MODE_TERMINATING;
+			}
+			printf("stop \n\r");
+		}
+
+		usleep(100000);
+	}
+}
+
+int DiffTimeb(struct timeb ST, struct timeb ET)
+{
+	//return milli-second
+	unsigned int StartTime,StopTime;
+
+	StartTime=(unsigned int)ST.time;
+	StopTime=(unsigned int)ET.time;
+	//return (StopTime-StartTime)*1000+ET.millitm-ST.millitm;
+	return (StopTime-StartTime);
+}
+
+void CalcPresentChargedDuration(byte gun_index)
+{
+	int _diffTime = 0;
+
+	ftime(&endChargingTime);
+	_diffTime = DiffTimeb(startChargingTime, endChargingTime);
+
+	// below 0 or over 5 sec is abnormal
+	if (_diffTime < 0 ||
+			_diffTime > _chargingData[gun_index]->PresentChargedDuration + 5)
+	{
+		_presentChargingTimeBuf = _chargingData[gun_index]->PresentChargedDuration;
+		ftime(&startChargingTime);
+	}
+	else
+		_chargingData[gun_index]->PresentChargedDuration = _presentChargingTimeBuf + _diffTime;
+}
+
+void CalcPresentChargingPower(byte _index)
+{
+	if (chargingTime == 0 ||
+			chargingTime > _chargingData [_index]->PresentChargedDuration)
+	{
+		chargingTime = _chargingData [_index]->PresentChargedDuration;
+	}
+	else
+	{
+		int passTime = _chargingData [_index]->PresentChargedDuration - chargingTime;
+
+		if (passTime > 0)
+		{
+			float changingPow = (_chargingData [_index]->PresentChargingPower) * passTime / 3600;
+			_chargingData [_index]->PresentChargedEnergy += changingPow;
+			chargingTime = _chargingData [_index]->PresentChargedDuration;
+		}
+	}
+}
+
+void RunUnconditionalChargeIndex1(char *v1, char *v2, char *v3)
+{
+	int _GunIndex;
+	float _Voltage;
+	float _Current;
+
+	if (strcmp(v1, "auto") == EQUAL)
+	{
+		_usingAutoRun = 0x01;
+		_GunIndex = atoi(v2);
+		_Voltage = 500;
+		_Current = (ShmSysConfigAndInfo->SysConfig.MaxChargingPower * 1000) / _Voltage;
+	}
+	else
+	{
+		_usingAutoRun = 0x00;
+		_GunIndex = atoi(v1);
+		_Voltage = atof(v2);
+		_Current = atof(v3);
+	}
+
+	unsigned char PreviousSystemStatus = 0xff;
+	if (!FindChargingInfoData(_GunIndex, &_chargingData[0]))
+	{
+		printf ("FindChargingInfoData error\n");
+		return;
+	}
+
+    printf ("Power = %d, ReqVoltage = %f, ReqCurrent = %f\n",
+    		ShmSysConfigAndInfo->SysConfig.MaxChargingPower, _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;
+    ShmSysConfigAndInfo->SysInfo.CurGunSelected = _GunIndex;
+    _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->Type = 9;
+    sleep(1);
+    //kill ev task
+    system("killall Module_EvComm");
+
+    //_Voltage = (_Voltage * 10);
+    //_Current = (_Current * 10);
+
+    //system(STTY_US TTY_PATH);
+
+    while(true)
+    {
+        //fix gun 1
+    	switch(_chargingData[_GunIndex]->SystemStatus)
+    	{
+            case SYS_MODE_IDLE:
+    		{
+        	    if(PreviousSystemStatus != _chargingData[_GunIndex]->SystemStatus)
+        	    {
+        	        PreviousSystemStatus = _chargingData[_GunIndex]->SystemStatus;
+
+        	        printf ("[UnconditionalCharge - SYS_MODE_IDLE]\n");
+        	    }
+
+        	    chargingTime = 0;
+        	    ShmDcCommonData->StartToChargingFlag[_GunIndex] = 0x01;
+                _chargingData[_GunIndex]->SystemStatus = SYS_MODE_PREPARING;
+    		}
+    		break;
+
+    		case SYS_MODE_PREPARING:
+    		{
+        	    if(PreviousSystemStatus != _chargingData[_GunIndex]->SystemStatus)
+        	    {
+        	        PreviousSystemStatus = _chargingData[_GunIndex]->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[_GunIndex]->TimeoutFlag = 0;
+    		    //不論是什麼 type 的槍都固意設成 Chademo 不跑 Prechage step
+    		    _chargingData[_GunIndex]->Type = 9;
+
+    		}
+    		break;
+
+    		case SYS_MODE_PREPARE_FOR_EV:
+    		{
+        	    if(PreviousSystemStatus != _chargingData[_GunIndex]->SystemStatus)
+        	    {
+        	        PreviousSystemStatus = _chargingData[_GunIndex]->SystemStatus;
+
+        	        printf ("[UnconditionalCharge - SYS_MODE_PREPARE_FOR_EV]\n");
+        	        printf ("ReqVoltage = %f, ReqCurrent = %f \n", _Voltage * 10,_Current * 10);
+
+        	    }
+    		    //清除 main timeout 機制
+    		    _chargingData[_GunIndex]->TimeoutFlag = 0;
+    		    //不論是什麼 type 的槍都固意設成 Chademo 不跑 Prechage step
+    		    _chargingData[_GunIndex]->Type = 9;
+
+    		    //充電電壓電流
+    		    _chargingData[_GunIndex]->EvBatterySoc = 50;
+   		        _chargingData[_GunIndex]->EvBatterytargetVoltage = 500;
+    		    _chargingData[_GunIndex]->EvBatterytargetCurrent = 2;
+    		    _chargingData[_GunIndex]->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[_GunIndex]->PresentChargingVoltage);
+    		        //EV done
+    		        _chargingData[_GunIndex]->SystemStatus = SYS_MODE_PREPARE_FOR_EVSE;
+    		    }
+    		}
+    		break;
+
+    		case SYS_MODE_PREPARE_FOR_EVSE:
+    		{
+        	    if(PreviousSystemStatus != _chargingData[_GunIndex]->SystemStatus)
+        	    {
+        	        PreviousSystemStatus = _chargingData[_GunIndex]->SystemStatus;
+
+        	        printf ("[UnconditionalCharge - SYS_MODE_PREPARE_FOR_EVSE]\n");
+
+        	    }
+        	    //printf ("tar vol = %d \n", _Voltage);
+        	    //printf ("tar cur = %d \n", _Current);
+
+    		    //清除 main timeout 機制
+    		    _chargingData[_GunIndex]->TimeoutFlag = 0;
+    		    //不論是什麼 type 的槍都固意設成 Chademo 不跑 Prechage step
+    		    _chargingData[_GunIndex]->Type = 9;
+
+    		    //充電電壓電流
+    		    _chargingData[_GunIndex]->EvBatterySoc = 50;
+    		    _chargingData[_GunIndex]->EvBatterytargetVoltage = 500;
+    		    _chargingData[_GunIndex]->EvBatterytargetCurrent = 2;
+    		    _chargingData[_GunIndex]->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 )
+    		    //確定模組己升壓完成
+				//#define GFD_WAIT			0
+				//#define GFD_PASS			1
+				//#define GFD_FAIL			2
+				//#define GFD_WARNING		3
+    		    if(_chargingData[_GunIndex]->GroundFaultStatus == 0x01 ||
+    		        _chargingData[_GunIndex]->GroundFaultStatus == 0x03)
+    		    {
+    		        printf ("First Ground Fault State (%d)\n",_chargingData[_GunIndex]->GroundFaultStatus);
+    		        printf ("Wait K1K2 = %f \n", _chargingData[_GunIndex]->PresentChargingVoltage);
+    		        sleep(5);
+    		        //EV done
+    		        _chargingData[_GunIndex]->SystemStatus = SYS_MODE_CHARGING;
+    		    }
+    		    else if (_chargingData[_GunIndex]->GroundFaultStatus > 0x02)
+    		    {
+    		        printf ("First Ground Fault check Fail (%d)\n",_chargingData[_GunIndex]->GroundFaultStatus);
+    		        _chargingData[_GunIndex]->SystemStatus = SYS_MODE_TERMINATING;
+    		    }
+
+    		}
+    		break;
+
+    		case SYS_MODE_CHARGING:
+    		{
+        	    if(PreviousSystemStatus != _chargingData[_GunIndex]->SystemStatus)
+        	    {
+        	        PreviousSystemStatus = _chargingData[_GunIndex]->SystemStatus;
+
+        	        if (_usingAutoRun == 0x00)
+        	        {
+        	        	//充電電壓電流
+        	        	_chargingData[_GunIndex]->EvBatterytargetVoltage = _Voltage;
+        	        	_chargingData[_GunIndex]->EvBatterytargetCurrent = _Current;
+        	        }
+        	        else
+        	        {
+        	        	_curAutoRunCount = 0;
+        	        	gettimeofday(&_autoTime, NULL);
+        	        }
+
+        	        _chargingData[_GunIndex]->EvBatterySoc = 50;
+        	        _chargingData[_GunIndex]->AvailableChargingCurrent = 1000;
+
+        	        ftime(&startChargingTime);
+        	        //gettimeofday(&_printf_time, NULL);
+        	        printf ("[UnconditionalCharge - SYS_MODE_CHARGING]\n");
+        	    }
+
+				CalcPresentChargedDuration(_GunIndex);
+
+        	    if (_usingAutoRun == 0x01)
+        	    {
+        	    	if (((GetTimeoutValue(_autoTime)) >= AUTORUN_STEP1_TIME_START * 60 && (GetTimeoutValue(_autoTime)) <= AUTORUN_STEP1_TIME_END * 60) ||
+        	    			((GetTimeoutValue(_autoTime)) >= AUTORUN_STEP2_TIME_START * 60 && (GetTimeoutValue(_autoTime)) <= AUTORUN_STEP2_TIME_END * 60))
+        	    	{
+        	    		_chargingData[_GunIndex]->EvBatterytargetVoltage = _Voltage;
+        	    		_chargingData[_GunIndex]->EvBatterytargetCurrent = _Current;
+        	    	}
+        	    	else if ((GetTimeoutValue(_autoTime)) >= AUTORUN_END_TIME * 60)
+        	    	{
+        	    		_curAutoRunCount++;
+        	    		if (_curAutoRunCount >= AUTORUN_CYCLE_COUNT)
+        	    			_chargingData[_GunIndex]->SystemStatus = SYS_MODE_TERMINATING;
+        	    		else
+        	    			gettimeofday(&_autoTime, NULL);
+        	    	}
+        	    	else
+        	    	{
+        	    		_chargingData[_GunIndex]->EvBatterytargetVoltage = 0;
+        	    		_chargingData[_GunIndex]->EvBatterytargetCurrent = 0;
+        	    	}
+        	    }
+
+//        	    printf("out : vol = %f, cur = %f \n",
+//        	    		_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage,
+//						_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent);
+    		    //ev task do this
+    		    _chargingData[_GunIndex]->PresentChargingPower =
+    		    		((float)((_chargingData[_GunIndex]->PresentChargingVoltage) * (_chargingData[_GunIndex]->PresentChargingCurrent)) / 1000);
+
+    		    CalcPresentChargingPower(_GunIndex);
+
+    		    if (_chargingData[_GunIndex]->GroundFaultStatus == 0x02){
+    		         printf ("Charging Ground Fault check Fail (%d)\n",_chargingData[_GunIndex]->GroundFaultStatus);
+    		        _chargingData[_GunIndex]->SystemStatus = SYS_MODE_TERMINATING;
+    		    }
+
+//    		    if (GetTimeoutValue(_printf_time) >= 3)
+//    		    {
+//    		    	printf("PresentChargedEnergy = %.3f \n", _chargingData [_GunIndex]->PresentChargedEnergy);
+//    		    	gettimeofday(&_printf_time, NULL);
+//    		    }
+    		}
+    		break;
+
+     		case SYS_MODE_TERMINATING:
+    		{
+        	    if(PreviousSystemStatus != _chargingData[_GunIndex]->SystemStatus)
+        	    {
+        	        PreviousSystemStatus = _chargingData[_GunIndex]->SystemStatus;
+        	        system("/root/Module_EvComm &");
+
+        	        printf ("[UnconditionalCharge - SYS_MODE_TERMINATING]\n");
+        	        //無阻塞偵測 keybaord 結束
+        	        system(STTY_DEF TTY_PATH);
+        	    }
+
+        	    sleep(3);
+        	    _chargingData[_GunIndex]->SystemStatus = SYS_MODE_COMPLETE;
+        	    return;
+    		}
+    		break;
+
+    		case SYS_MODE_COMPLETE:
+    		{
+        	    if(PreviousSystemStatus != _chargingData[_GunIndex]->SystemStatus)
+        	    {
+        	        PreviousSystemStatus = _chargingData[_GunIndex]->SystemStatus;
+
+        	        printf ("[UnconditionalCharge - SYS_MODE_COMPLETE]\n");
+        	    }
+
+        	    _chargingData[_GunIndex]->PresentChargingPower = 0;
+        	    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[_GunIndex]->EvBatterytargetVoltage = _vol;
+    		_chargingData[_GunIndex]->EvBatterytargetCurrent = _cur;
+    	}
+    	else if (strcmp(newString[0], "c") == 0)
+    	{
+    		printf("stop \n\r");
+    		ShmDcCommonData->StartToChargingFlag[_GunIndex] = 0x00;
+    		_chargingData[_GunIndex]->SystemStatus = SYS_MODE_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 || strcmp(newString[0], "st") == 0)
+		{
+			if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
+				continue;
+
+			// 槍狀態
+			printf("=========================== \n");
+			RunStatusProc(newString[1], newString[2]);
+			printf("=========================== \n");
+		}
+		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)
+		{
+			// get output power
+			GetPowerValue();
+		}
+		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], "show") == 0)
+		{
+			ShowSysInformation();
+		}
+		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], newString[2], newString[3]);
+		}
+		else if (strcmp(newString[0], "cap") == 0)
+		{
+			GetConnectorCapInfo(newString[1]);
+		}
+		else if(strcmp(newString[0], "error") == 0)
+		{
+			CreateOneError();
+		}
+		else if (strcmp(newString[0], "auth") == 0)
+		{
+			GetAuthorizeFlag(newString[1]);
+		}
+		else if (strcmp(newString[0], "relay") == 0)
+		{
+			GetRelayStatus(newString[1]);
+		}
+		else if (strcmp(newString[0], "ccid") == 0)
+		{
+			if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0 ||
+				strcmp(newString[2], "-1") == 0 || strcmp(newString[2], "") == 0)
+			{
+				printf ("Input ccid fail.\n");
+				continue;
+			}
+			SetChargingInfoCCID(newString[1], newString[2]);
+		}
+		else if (strcmp(newString[0], "guntemp") == 0)
+		{
+			if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
+			{
+				printf ("Input guntemp fail.\n");
+				continue;
+			}
+			GetGunTemp(newString[1]);
+		}
+		else if (strcmp(newString[0], "offer") == 0)
+		{
+			if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
+			{
+				printf ("offer fail.\n");
+				continue;
+			}
+			GetOffered(newString[1]);
+		}
+		else if (strcmp(newString[0], "evstate") == 0)
+		{
+			if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
+			{
+				printf ("evstate fail.\n");
+				continue;
+			}
+			GetEvStatus(newString[1]);
+		}
+		else if (strcmp(newString[0], "meter") == 0)
+		{
+			// DC meter infor
+			if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
+			{
+				printf ("meter cmd fail.\n");
+				continue;
+			}
+			GetDcMeterInfor(newString[1]);
+		}
+		else if (strcmp(newString[0], "soc") == 0)
+		{
+			GetSOC(newString[1]);
+		}
+		else if (strcmp(newString[0], "run") == 0)
+		{
+			if (ShmDcCommonData->_isAutoRunTest == YES)
+				ShmDcCommonData->_isAutoRunTest = NO;
+			else
+				ShmDcCommonData->_isAutoRunTest = YES;
+
+			printf ("_isAutoRunTest = %d \n", ShmDcCommonData->_isAutoRunTest);
+		}
+		else if (strcmp(newString[0], "test") == 0)
+		{
+			if (!FindChargingInfoData(1, &_chargingData[0]))
+			{
+				printf("FindChargingInfoData error\n");
+			}
+
+			// Test Command
+			ShmPsuData->PsuGroup[0].GroupErrorFlag.bits.PsuFailure = YES;
+			ShmPsuData->PsuStopChargeFlag = YES;
+			ShmDcCommonData->_isPsuErrorOccur = YES;
+//			ShmDcCommonData->Customer_SwipToChargingByTime += 10;
+//			printf("Charging Time = %u \n", ShmDcCommonData->Customer_SwipToChargingByTime);
+		}
+		else if (strcmp(newString[0], "ocpp") == 0)
+		{
+			if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
+			{
+				if (strlen ( (char *) ShmOCPP16Data->ConfigurationTable.CoreProfile [ConfigurationVersion].ItemData ) > 0)
+				{
+					printf ( "OCPP Version. = %s",
+							ShmOCPP16Data->ConfigurationTable.CoreProfile [ConfigurationVersion].ItemData );
+				}
+			}
+			else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
+			{
+
+			}
+		}
+		else if(strcmp(newString[0], "strchg") == 0)
+		{
+			//如果連一個參數都沒有 (此命令不理會) 加上判斷第二參數
+			if (strcmp(newString[1], "auto") == 0)
+			{
+				newString[3][0] = 0;
+			}
+			else 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 if(strcmp(newString[0], "avechg") == 0)
+		{
+			// 雙槍同時忙充輸出
+			if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0 ||
+					strcmp(newString[2], "-1") == 0 || strcmp(newString[2], "") == 0 ||
+					strcmp(newString[3], "-1") == 0 || strcmp(newString[3], "") == 0 ||
+					strcmp(newString[4], "-1") == 0 || strcmp(newString[4], "") == 0)
+			{
+				printf ("Input cmd fail ------  avechg\n");
+				continue;
+			}
+
+			if (ShmSysConfigAndInfo->SysConfig.TotalConnectorCount < 2 ||
+					ShmSysConfigAndInfo->SysInfo.IsAlternatvieConf == 1)
+			{
+				printf ("Sorry, This is single gun system. \n");
+				continue;
+			}
+
+			AverageCharging(newString[1], newString[2], newString[3], newString[4]);
+		}
+		else
+			printf ("%s\n", msg);
+		usleep(100000);
+	}
+
+	return 0;
+}

BIN
EVSE/Projects/NoodoeDS/Apps/UnsafetyOutputTask


+ 315 - 0
EVSE/Projects/NoodoeDS/Apps/cbmp.c

@@ -0,0 +1,315 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include "cbmp.h"
+
+// Constants
+
+#define BITS_PER_BYTE 8
+
+#define BLUE 0
+#define GREEN 1
+#define RED 2
+#define ALPHA 3
+
+#define PIXEL_ARRAY_START_BYTES 4
+#define PIXEL_ARRAY_START_OFFSET 10
+
+#define WIDTH_BYTES 4
+#define WIDTH_OFFSET 18
+
+#define HEIGHT_BYTES 4
+#define HEIGHT_OFFSET 22
+
+#define DEPTH_BYTES 2
+#define DEPTH_OFFSET 28
+
+// Private function declarations
+
+void _throw_error(char* message);
+unsigned int _get_int_from_buffer(unsigned int bytes, 
+                                  unsigned int offset, 
+                                  unsigned char* buffer);
+unsigned int _get_file_byte_number(FILE* fp);
+unsigned char* _get_file_byte_contents(FILE* fp, unsigned int file_byte_number);
+int _validate_file_type(unsigned char* file_byte_contents);
+int _validate_depth(unsigned int depth);
+unsigned int _get_pixel_array_start(unsigned char* file_byte_contents);
+int _get_width(unsigned char* file_byte_contents);
+int _get_height(unsigned char* file_byte_contents);
+unsigned int _get_depth(unsigned char* file_byte_contents);
+void _update_file_byte_contents(BMP* bmp, int index, int offset, int channel);
+void _populate_pixel_array(BMP* bmp);
+void _map(BMP* bmp, void (*f)(BMP* bmp, int, int, int));
+void _get_pixel(BMP* bmp, int index, int offset, int channel);
+
+// Public function implementations
+
+BMP* bopen(char* file_path)
+{
+    FILE* fp = fopen(file_path, "rb");
+  
+    if (fp == NULL)
+    {
+        perror("Error opening file");
+        exit(EXIT_FAILURE);
+    }
+
+    BMP* bmp = (BMP*) malloc(sizeof(BMP));
+    bmp->file_byte_number = _get_file_byte_number(fp);
+    bmp->file_byte_contents = _get_file_byte_contents(fp, bmp->file_byte_number);
+    fclose(fp);
+
+    if(!_validate_file_type(bmp->file_byte_contents))
+    {
+        _throw_error("Invalid file type");
+    }
+
+    bmp->pixel_array_start = _get_pixel_array_start(bmp->file_byte_contents);
+
+    bmp->width = _get_width(bmp->file_byte_contents);
+    bmp->height = _get_height(bmp->file_byte_contents);
+    bmp->depth = _get_depth(bmp->file_byte_contents);
+
+    if(!_validate_depth(bmp->depth))
+    {
+        _throw_error("Invalid file depth");
+    }
+
+    _populate_pixel_array(bmp);
+
+    return bmp;
+}
+
+BMP* b_deep_copy(BMP* to_copy)
+{
+    BMP* copy = (BMP*) malloc(sizeof(BMP));
+    copy->file_byte_number = to_copy->file_byte_number;
+    copy->pixel_array_start = to_copy->pixel_array_start;
+    copy->width = to_copy->width;
+    copy->height = to_copy->height;
+    copy->depth = to_copy->depth;
+
+    copy->file_byte_contents = (unsigned char*) malloc(copy->file_byte_number * sizeof(unsigned char));
+
+    unsigned int i;
+    for (i = 0; i < copy->file_byte_number; i++)
+    {
+        copy->file_byte_contents[i] = to_copy->file_byte_contents[i];
+    }
+
+    copy->pixels = (pixel*) malloc(copy->width * copy->height * sizeof(pixel));
+
+    unsigned int x, y;
+    int index;
+    for (y = 0; y < copy->height; y++)
+    {
+        for (x = 0; x < copy->width; x++)
+        {
+            index = y * copy->width + x;
+            copy->pixels[index].red = to_copy->pixels[index].red;
+            copy->pixels[index].green = to_copy->pixels[index].green;
+            copy->pixels[index].blue = to_copy->pixels[index].blue;
+            copy->pixels[index].alpha = to_copy->pixels[index].alpha;
+        }
+    }
+
+    return copy;
+}
+
+int get_width(BMP* bmp)
+{
+    return bmp->width;
+}
+
+int get_height(BMP* bmp)
+{
+    return bmp->height;
+}
+
+unsigned int get_depth(BMP* bmp)
+{
+    return bmp->depth;
+}
+
+void get_pixel_rgb(BMP* bmp, int x, int y, unsigned char* r, unsigned char* g, unsigned char* b)
+{
+    int index = y * bmp->width + x;
+    *r = bmp->pixels[index].red;
+    *g = bmp->pixels[index].green;
+    *b = bmp->pixels[index].blue;
+}
+
+void set_pixel_rgb(BMP* bmp, int x, int y, unsigned char r, unsigned char g, unsigned char b)
+{
+    int index = y * bmp->width + x;
+    bmp->pixels[index].red = r;
+    bmp->pixels[index].green = g;
+    bmp->pixels[index].blue = b;
+}
+
+void bwrite(BMP* bmp, char* file_name)
+{
+    _map(bmp, _update_file_byte_contents);
+
+    FILE* fp = fopen(file_name, "wb");
+    fwrite(bmp->file_byte_contents, sizeof(char), bmp->file_byte_number, fp);
+    fclose(fp);
+}
+
+void bclose(BMP* bmp)
+{
+    free(bmp->pixels);
+    bmp->pixels = NULL;
+    free(bmp->file_byte_contents);
+    bmp->file_byte_contents = NULL;
+    free(bmp);
+    bmp = NULL;
+}
+
+
+// Private function implementations
+
+void _throw_error(char* message)
+{
+    fprintf(stderr, "%s\n", message);
+    exit(1);
+}
+
+unsigned int _get_int_from_buffer(unsigned int bytes, 
+                                  unsigned int offset, 
+                                  unsigned char* buffer)
+{
+    unsigned char* _buffer = (unsigned char*) malloc(bytes * sizeof(unsigned char));
+
+    unsigned int i;
+    for (i = 0; i < bytes; i++)
+    {
+        _buffer[i] = buffer[i + offset];
+    }
+
+    unsigned int value = *(unsigned int*) _buffer;
+    free(_buffer);
+    return value;
+}
+
+unsigned int _get_file_byte_number(FILE* fp)
+{
+    unsigned int byte_number;
+    fseek(fp, 0, SEEK_END);
+    byte_number = ftell(fp);
+    rewind(fp);
+    return byte_number;
+}
+
+unsigned char* _get_file_byte_contents(FILE* fp, unsigned int file_byte_number)
+{
+    unsigned char* buffer = (unsigned char*) malloc(file_byte_number * sizeof(char));
+    unsigned int result = fread(buffer, 1, file_byte_number, fp);
+
+    if (result != file_byte_number)
+    {
+        _throw_error("There was a problem reading the file");
+    }
+
+
+    return buffer;
+}
+
+int _validate_file_type(unsigned char* file_byte_contents)
+{
+    return file_byte_contents[0] == 'B' && file_byte_contents[1] == 'M';
+}
+
+int _validate_depth(unsigned int depth)
+{
+    return depth == 24 || depth == 32;
+}
+
+unsigned int _get_pixel_array_start(unsigned char* file_byte_contents)
+{
+    return _get_int_from_buffer(PIXEL_ARRAY_START_BYTES, PIXEL_ARRAY_START_OFFSET, file_byte_contents);
+}
+
+int _get_width(unsigned char* file_byte_contents)
+{
+    return (int) _get_int_from_buffer(WIDTH_BYTES, WIDTH_OFFSET, file_byte_contents);
+}
+
+int _get_height(unsigned char* file_byte_contents)
+{
+    return (int) _get_int_from_buffer(HEIGHT_BYTES, HEIGHT_OFFSET, file_byte_contents);
+}
+
+unsigned int _get_depth(unsigned char* file_byte_contents)
+{
+    return _get_int_from_buffer(DEPTH_BYTES, DEPTH_OFFSET, file_byte_contents);
+}
+
+void _update_file_byte_contents(BMP* bmp, int index, int offset, int channel)
+{
+    char value;
+    switch(channel)
+    {
+        case BLUE:
+            value = bmp->pixels[index].blue;
+            break;
+        case GREEN:
+            value = bmp->pixels[index].green;
+            break;
+        case RED:
+            value = bmp->pixels[index].red;
+            break;
+        case ALPHA:
+            value = bmp->pixels[index].alpha;
+            break;
+    }
+    bmp->file_byte_contents[offset + channel] = value;
+}
+
+void _populate_pixel_array(BMP* bmp)
+{
+    bmp->pixels = (pixel*) malloc(bmp->width * bmp->height * sizeof(pixel));
+    _map(bmp, _get_pixel);
+}
+
+void _map(BMP* bmp, void (*f)(BMP*, int, int, int))
+{
+    int channels = bmp->depth / (sizeof(unsigned char) * BITS_PER_BYTE);
+    int row_size = ((int) (bmp->depth * bmp->width + 31) / 32) * 4;
+    int padding = row_size - bmp->width * channels;
+
+    int c;
+    unsigned int x, y, index, offset;
+    for (y = 0; y < bmp->height; y++)
+    {
+        for (x = 0; x < bmp->width; x++)
+        {
+            index = y * bmp->width + x;
+            offset = bmp->pixel_array_start + index * channels + y * padding;
+            for (c = 0; c < channels; c++)
+            {
+                (*f)(bmp, index, offset, c);
+            }
+        }
+    }
+}
+
+void _get_pixel(BMP* bmp, int index, int offset, int channel)
+{
+    unsigned char value = _get_int_from_buffer(sizeof(unsigned char), offset + channel, bmp->file_byte_contents);
+    switch(channel)
+    {
+        case BLUE:
+            bmp->pixels[index].blue = value;
+            break;
+        case GREEN:
+            bmp->pixels[index].green = value;
+            break;
+        case RED:
+            bmp->pixels[index].red = value;
+            break;
+        case ALPHA:
+            bmp->pixels[index].alpha = value;
+            break;
+    }
+}

+ 54 - 0
EVSE/Projects/NoodoeDS/Apps/cbmp.h

@@ -0,0 +1,54 @@
+#ifndef CBMP_CBMP_H
+#define CBMP_CBMP_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+// Pixel structure
+// Not meant to be edited directly
+// Please use the API
+
+typedef struct pixel_data
+{
+    unsigned char red;
+    unsigned char green;
+    unsigned char blue;
+    unsigned char alpha;
+} pixel;
+
+// BMP structure
+// Not meant to be edited directly
+// Please use the API
+
+typedef struct BMP_data
+{
+    unsigned int file_byte_number;
+    unsigned char* file_byte_contents;
+
+    unsigned int pixel_array_start;
+
+    unsigned int width;
+    unsigned int height;
+    unsigned int depth;
+
+    pixel* pixels;
+} BMP;
+
+// Public function declarations
+
+BMP* bopen(char* file_path);
+BMP* b_deep_copy(BMP* to_copy);
+int get_width(BMP* bmp);
+int get_height(BMP* bmp);
+unsigned int get_depth(BMP* bmp);
+void get_pixel_rgb(BMP* bmp, int x, int y, unsigned char* r, unsigned char* g, unsigned char* b);
+void set_pixel_rgb(BMP* bmp, int x, int y, unsigned char r, unsigned char g, unsigned char b);
+void bwrite(BMP* bmp, char* file_name);
+void bclose(BMP* bmp);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif // CBMP_CBMP_H

+ 11 - 0
EVSE/Projects/NoodoeDS/Apps/init.sh

@@ -0,0 +1,11 @@
+chmod 777 Module_CSU
+chmod 777 Module_PrimaryComm
+chmod 777 Module_LcmControl
+chmod 777 Module_InternalComm
+chmod 777 Module_EventLogging
+chmod 777 Module_EvComm
+chmod 777 Module_PsuComm
+chmod 777 OcppBackend
+chmod 777 kill.sh
+chmod 777 ReadCmdline
+

+ 1294 - 0
EVSE/Projects/NoodoeDS/Apps/internalComm.c

@@ -0,0 +1,1294 @@
+/*
+ * internalComm.c
+ *
+ *  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/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,0x35,0x81,0x83,
+		0x85,0x86,0x87,0x88,0x089,0x8A,0x8B,0x8C,0x90,0x93,0xe0,0xe1,0xe2,0xe3};
+
+int tranceiveRelDelayTime(int fd, unsigned char* cmd, unsigned char cmd_len, unsigned char* rx, unsigned short _delay)
+{
+	int len;
+	//sleep(2); //required to make flush work, for some reason
+	tcflush(fd,TCIOFLUSH);
+
+	if(write(fd, cmd, cmd_len) >= cmd_len)
+	{
+		usleep(_delay * 1000);
+		len = read(fd, rx, 512);
+	}
+	else
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR("Serial command %s response fail.\n", cmd);
+		#endif
+	}
+
+	return len;
+}
+
+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(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);
+
+//		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]))
+		{
+			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 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 > 13)
+	{
+		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]) &&
+		   chksum != 0)
+		{
+			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;
+
+			if (Ret_Buf->L1N_L12 >= 320 ||
+					Ret_Buf->L2N_L23 >= 320 ||
+					Ret_Buf->L3N_L31 >= 320)
+			{
+				result = FAIL;
+			}
+			else
+				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 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);
+
+	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 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 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 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 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 Query_Model_Name(unsigned char fd, unsigned char targetAddr, unsigned char *modelname)
+{
+	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;
+}
+
+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]) &&
+		   rx[6] == PASS)
+		{
+			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[11] = {0xaa, 0x00, targetAddr, Cmd.config_Relay_Output, 0x04, 0x00, Set_Buf->relay_event.relay_status[0], Set_Buf->relay_event.relay_status[1], Set_Buf->relay_event.relay_status[2], Set_Buf->relay_event.relay_status[3]};
+	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;
+
+//	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("get 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] == PASS)
+		{
+			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]))
+		{
+			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]))
+		{
+			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] == PASS)
+		{
+			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] == PASS)
+		{
+			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;
+
+	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;
+}
+
+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 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;
+}
+
+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;
+}
+
+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 = tranceiveRelDelayTime(fd, tx, sizeof(tx), rx, 100);
+
+	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;
+}
+
+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 = tranceiveRelDelayTime(fd, tx, sizeof(tx), rx, 100);
+
+	if(len > 6)
+	{
+		if (len < 6 + (rx[4] | rx[5] << 8) || (rx[4] | rx[5] << 8) < 4)
+			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);
+//			if (Ret_Buf->AcAlarmCode != 0)
+//			{
+//				printf("rx[1] = %x, rx[2] = %x, rx[3] = %x, rx[4] = %x, rx[5] = %x \n",
+//						rx[1], rx[2], rx[3], rx[4], rx[5]);
+//				printf("rx[6] = %x, rx[7] = %x, rx[8] = %x, rx[9] = %x \n",
+//						rx[6], rx[7], rx[8], rx[9]);
+//			}
+			result = PASS;
+		}
+	}
+
+	return result;
+}
+
+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.query_ac_output_energy, 0x00, 0x00,0x00};
+	unsigned char rx[512];
+	unsigned char chksum = 0x00;
+	unsigned char len = tranceiveRelDelayTime(fd, tx, sizeof(tx), rx, 100);
+
+	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;
+}
+
+unsigned char Query_AC_Charging_Power(unsigned char fd, unsigned char targetAddr, Ac_Charging_power *Ret_Buf)
+{
+	unsigned char result = FAIL;
+	unsigned char tx[7] = {0xaa, 0x00, targetAddr, Cmd.query_ac_output_power, 0x00, 0x00, 0x00};
+	unsigned char rx[512];
+	unsigned char chksum = 0x00;
+	unsigned char len = tranceiveRelDelayTime(fd, tx, sizeof(tx), rx, 100);
+
+	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->AWATT = rx[54] + (rx[55] << 8) + (rx[56] << 8) + (rx[57] << 8);
+			Ret_Buf->BWATT = rx[58] + (rx[59] << 8) + (rx[60] << 8) + (rx[61] << 8);
+			Ret_Buf->CWATT = rx[62] + (rx[63] << 8) + (rx[64] << 8) + (rx[65] << 8);
+			result = PASS;
+		}
+	}
+
+	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 = tranceiveRelDelayTime(fd, tx, sizeof(tx), rx, 100);
+
+	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];
+		}
+
+//		for(int i = 0; i < len; i++)
+//			printf ("rx = %x \n", rx[i]);
+
+		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)) / 10;
+			Ret_Buf->OuputCurrentL2 = (rx[8] + (rx[9] << 8)) / 10;
+			Ret_Buf->OuputCurrentL3 = (rx[10] + (rx[11] << 8)) / 10;
+			result = PASS;
+		}
+	}
+
+	return result;
+}
+
+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 (tranceiveRelDelayTime(fd, tx, sizeof(tx), rx, 100) > 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;
+}
+
+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 (tranceiveRelDelayTime(fd, tx, sizeof(tx), rx, 100) > 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;
+}
+
+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 (tranceiveRelDelayTime(fd, tx, sizeof(tx), rx, 100) > 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;
+}
+
+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 (tranceiveRelDelayTime(fd, tx, sizeof(tx), rx, 100) > 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;
+}
+
+unsigned char Config_Reset_MCU(unsigned char fd, unsigned char targetAddr)
+{
+	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 (tranceiveRelDelayTime(fd, tx, sizeof(tx), rx, 100) > 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;
+}
+
+unsigned char Config_Led_Color(unsigned char fd, unsigned char targetAddr, Led_Color *Ret_Buf)
+{
+	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[12] = chksum;
+
+//	for(int i = 0; i < 13; 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;
+
+		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;
+}
+

+ 296 - 0
EVSE/Projects/NoodoeDS/Apps/internalComm.h

@@ -0,0 +1,296 @@
+/*
+ * internalComm.h
+ *
+ *  Created on: 2019¦~5¤ë7¤é
+ *      Author: foluswen
+ */
+
+#ifndef INTERNALCOMM_H_
+#define INTERNALCOMM_H_
+
+extern struct Address
+{
+	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 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 query_ac_output_power;		//0x35
+
+	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];
+}Ver;
+
+typedef struct PRESENTINPUTVOLTAGE
+{
+	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;
+}PresentOutputVoltage;
+
+typedef struct FANSPEED
+{
+	unsigned short int speed[8];
+}FanSpeed;
+
+typedef struct TEMPERATURE
+{
+	unsigned char temperature[8];
+}Temperature;
+
+typedef struct AUXPOWER
+{
+	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
+
+			unsigned char AC_L1_Relay :1;		//bit 0
+			unsigned char AC_L2_Relay :1;		//bit 1
+			unsigned char AC_L3_Relay :1; 		//bit 2
+			unsigned char AC_TypeE_Socket :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
+		}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_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;
+}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
+}Gpio_in;
+
+typedef struct GPIO_OUT
+{
+	unsigned char AC_Connector;
+	unsigned char Button_LED[2];
+	unsigned char System_LED[4];
+}Gpio_out;
+
+typedef struct RTC
+{
+	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;
+
+typedef struct AC_Charging_Power
+{
+	float		AWATT;
+	float		BWATT;
+	float		CWATT;
+}
+Ac_Charging_power;
+
+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);
+extern unsigned char Query_Present_OutputVoltage(unsigned char fd, unsigned char targetAddr, PresentOutputVoltage *Ret_Buf);
+extern unsigned char Query_Fan_Speed(unsigned char fd, unsigned char targetAddr, FanSpeed *Ret_Buf);
+extern unsigned char Query_Temperature(unsigned char fd, unsigned char targetAddr, Temperature *Ret_Buf);
+extern unsigned char Query_Aux_PowerVoltage(unsigned char fd, unsigned char targetAddr, AuxPower *Ret_Buf);
+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);
+extern unsigned char Config_Gpio_Output(unsigned char fd, unsigned char targetAddr, Gpio_out *Set_Buf);
+extern unsigned char Config_Gfd_Value(unsigned char fd, unsigned char targetAddr, Gfd_config *Set_Buf);
+extern unsigned char Config_Model_Name(unsigned char fd, unsigned char targetAddr, unsigned char *modelname);
+extern unsigned char Config_Rtc_Data(unsigned char fd, unsigned char targetAddr, Rtc *Set_Buf);
+
+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);
+
+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 Query_AC_Charging_Power(unsigned char fd, unsigned char targetAddr, Ac_Charging_power *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_ */

+ 7 - 0
EVSE/Projects/NoodoeDS/Apps/kill.sh

@@ -0,0 +1,7 @@
+#!/bin/sh
+pkill main
+pkill Module_
+pkill OcppBackend
+fuser -k /dev/watchdog
+sleep 1
+echo V > /dev/watchdog

BIN
EVSE/Projects/NoodoeDS/Apps/main


+ 10368 - 0
EVSE/Projects/NoodoeDS/Apps/main.c

@@ -0,0 +1,10368 @@
+#include    <sys/types.h>
+#include    <sys/stat.h>
+#include 	<sys/time.h>
+#include 	<sys/timeb.h>
+#include 	<sys/types.h>
+#include 	<sys/ioctl.h>
+#include 	<sys/socket.h>
+#include 	<sys/ipc.h>
+#include 	<sys/shm.h>
+#include 	<sys/mman.h>
+#include 	<linux/wireless.h>
+#include 	<arpa/inet.h>
+#include 	<netinet/in.h>
+
+#include 	<unistd.h>
+#include 	<stdarg.h>
+#include    <stdio.h>      /*標準輸入輸出定義*/
+#include    <stdlib.h>     /*標準函數庫定義*/
+#include    <unistd.h>     /*Unix 標準函數定義*/
+#include    <fcntl.h>      /*檔控制定義*/
+#include    <termios.h>    /*PPSIX 終端控制定義*/
+#include    <errno.h>      /*錯誤號定義*/
+#include 	<string.h>
+#include 	<stdint.h>
+#include	<time.h>
+#include	<ctype.h>
+#include 	<ifaddrs.h>
+#include 	<math.h>
+#include 	<stdbool.h>
+#include 	<dirent.h>
+
+#include 	"../../define.h"
+#include "CheckSystemTask.h"
+#include 	"Config.h"
+#include	"timeout.h"
+
+#define		DEBUG_ALSTON		0
+#define 	ARRAY_SIZE(A)		(sizeof(A) / sizeof(A[0]))
+#define 	PASS				1
+#define 	FAIL				-1
+#define 	MODELNAME_FAIL		0
+#define 	BUFFER_SIZE			128
+#define 	YES					1
+#define 	NO					0
+#define 	NORMAL				0
+#define		ABNORMAL			1
+#define 	EQUAL				0
+#define 	BTN_RELEASE			0
+#define 	BTN_PRESS			1
+#define 	MAX_BUF 			64
+//#define 	MtdBlockSize 		0x600000
+#define 	MtdBlockSize 		0x300000
+#define 	SYSFS_GPIO_DIR 		"/sys/class/gpio"
+#define		UPGRADE_FAN			0x02
+#define		UPGRADE_RB			0x03
+#define		UPGRADE_PRI			0x04
+#define		UPGRADE_AC			0x05
+#define		UPGRADE_LED			0x06
+#define		SYSTEM_MIN_VOL		80
+#define 	MIN_OUTPUT_CUR		0
+#define		AC_OUTPUT_VOL		220
+
+#define		NO_DEFINE			255
+#define 	DEFAULT_AC_INDEX	2
+#define  	PSU_MIN_CUR			100
+
+#define 	DB_FILE				"/Storage/ChargeLog/localCgargingRecord.db"
+#define		NETWORK_DB_FILE		"/Storage/EventLog/Eventlog.db"
+
+#define		GUN_OTP_VALUE		150
+#define		GUN_OTP_RECOVERY	140
+#define 	UNDEFINED_TEMP		255
+
+#define 	uSEC_VAL				1000000
+#define		SELFTEST_TIMEOUT		60
+#define		AUTHORIZE_TIMEOUT		15
+#define 	AUTHORIZE_COMP_TIMEOUT	3
+#define 	AUTHORIZE_FAIL_TIMEOUT	3
+#define 	AUTHORIZE_STOP_TIMEOUT	30
+#define 	RETURN_TO_CHARGING_PAGE	30
+#define		GUN_PREPARE_TIMEOUT		30
+#define		GUN_EV_WAIT_TIMEOUT		120
+#define		GUN_EVSE_WAIT_TIMEOUT	60
+#define		GUN_COMP_WAIT_TIMEOUT	3
+#define		GUN_PRECHARGING_TIMEOUT	60
+
+#define 	TIMEOUT_SPEC_HANDSHAKING				180000
+
+char 	*valid_Internet[2] = {"8.8.8.8", "180.76.76.76"};
+unsigned char mask_table[] = { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 };
+int whileLoopTime = 10000; // 10 ms
+int	wtdFd = -1;
+byte _authorizeIndex = NO_DEFINE;
+
+bool IsAuthorizingMode();
+void ClearAuthorizedFlag();
+bool isDetectPlugin();
+void ClearDetectPluginFlag();
+int mystrcmp(unsigned char *p1, unsigned char *p2);
+void CheckTask();
+
+long long DiffTimebWithNow(struct timeb ST);
+unsigned char DetectBitValue(unsigned char _byte, unsigned char _bit);
+void SetBitValue(unsigned char *_byte, unsigned char _bit, unsigned char value);
+void ChargingTerminalProcess(byte gunIndex);
+void ChkPrimaryStatus();
+void StartSystemTimeoutDet(unsigned char flag);
+void StopSystemTimeoutDet();
+void StartGunInfoTimeoutDet(unsigned char gunIndex, unsigned char flag);
+void StopGunInfoTimeoutDet(unsigned char gunIndex);
+int StoreLogMsg_1(const char *fmt, ...);
+int GetTimeoutValue(struct timespec *startTime);
+void gpio_set_value(unsigned int gpio, unsigned int value);
+void PRINTF_FUNC(char *string, ...);
+void ChangeGunSelectByIndex(byte sel);
+void ChargingAlarmProcess(byte gunIndex);
+void CheckSystemErrorFunction(byte index);
+
+int opcc_chk_reserve_expired(byte gunIndex);
+void ocpp_process_start();
+void ocpp_auto_response_BootNotification();
+void ocpp_auto_response_StartTransationConf(byte gunIndex);
+bool ocpp_chk_authrization_cmd();
+void ocpp_chk_reset_cmd(byte isforce);
+void ocpp_chk_reserved_cmd(byte gunIndex);
+void ocpp_chk_availability_cmd(byte gunIndex);
+void ocpp_chk_unlock_cmd(byte gunIndex);
+bool ocpp_chk_remoteStop_cmd(byte gunIndex);
+void ocpp_chk_remoteStart_cmd();
+void ocpp_chk_update_cmd();
+bool ocpp_chk_invalid_id_cmd(byte gunIndex);
+
+void ocpp_set_startTransation_cmd(byte gunIndex);
+void ocpp_set_stopTransation_cmd(byte gunIndex);
+void ocpp_set_noErrorCode_cmd(byte gunIndex, char *errString);
+void ocpp_set_stopReason_by_cmd(byte gunIndex, char *reason);
+void ocpp_set_authorizeReq_cmd(byte value);
+void ocpp_set_authorizeConf_cmd(byte value);
+void ocpp_set_errCode_cmd(byte gunIndex);
+
+void ocpp_clear_errorCode_cmd(byte gunIndex);
+void ocpp_clear_idTag_cmd(byte gun_index);
+void ocpp_clear_stopReason(byte gun_index);
+
+bool ocpp_get_authorize_conf();
+unsigned short _ocpp_get_connect_timeout();
+
+void ocpp_chargingProfile_process(byte gun_index);
+
+void RecordAlarmCode(byte gunIndex, char *code);
+void ReleaseSysAlarmCode(byte gunIndex);
+void ReviewCriticalAlarm();
+
+int DB_Open(sqlite3 *db);
+int DB_Insert_Record(sqlite3 *db, int gun_index);
+int DB_Update_Operactive(sqlite3 *db, uint8_t gun_index, uint8_t IsAvailable);
+int DB_Get_Operactive(sqlite3 *db, uint8_t gun_index);
+void InitialDHCP();
+int GetStartScheduleTime(unsigned char *time);
+void KillAllTask();
+void CheckSystemTaskAlive();
+
+#define DEBUG_INFO_MSG(format, args...) StoreLogMsg_1("[%s:%d][%s][Info] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
+#define DEBUG_WARN_MSG(format, args...) StoreLogMsg_1("[%s:%d][%s][Warn] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
+#define DEBUG_ERROR_MSG(format, args...) StoreLogMsg_1("[%s:%d][%s][Error] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
+
+struct SysConfigAndInfo			*ShmSysConfigAndInfo;
+struct StatusCodeData 			*ShmStatusCodeData;
+struct PsuData 					*ShmPsuData;
+struct CHAdeMOData				*ShmCHAdeMOData;
+struct GBTData					*ShmGBTData;
+struct CcsData					*ShmCcsData;
+struct PrimaryMcuData			*ShmPrimaryMcuData;
+struct FanModuleData			*ShmFanModuleData;
+struct RelayModuleData			*ShmRelayModuleData;
+struct LedModuleData			*ShmLedModuleData;
+struct OCPP16Data				*ShmOCPP16Data;
+struct OCPP20Data				*ShmOCPP20Data;
+struct MeterInformation			*ShmCsuMeterData;
+struct DcCommonInformation		*ShmDcCommonData;
+
+struct ChargingInfoData			*chargingInfo[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
+struct ChargingInfoData			*ac_chargingInfo[AC_QUANTITY];
+
+struct timeb 					startChargingTime[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
+struct timeb 					endChargingTime[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
+int 							_presentChargingTimeBuf[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
+
+struct timespec 				_startTransation_time[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
+
+float gunOutputVol [CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
+
+float _ChargingProfilePwBuffer[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
+float _AcChargingProfileCurBuffer;
+
+bool _isSendStartTransaction[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
+
+GunErr errCollect;
+
+struct timespec _autoRuntestTime;
+byte _isTestRun = NO;
+
+// for initial index to check EV board type is correct
+byte _gunIndex = 0;
+byte _acgunIndex = 0;
+byte _chademoIndex = 0;
+byte _ccsIndex = 0;
+byte _gb_Index = 0;
+byte _ac_Index = 0;
+byte bd0_1_status = 0;
+byte bd0_2_status = 0;
+byte bd1_1_status = 0;
+byte bd1_2_status = 0;
+
+bool isCardScan = false;
+bool isModelNameMatch = true;
+
+int rfidFd = -1;
+char* rfidPortName = "/dev/ttyS2";
+char* fwVersion = "V2.05.00.0000.00";
+
+sqlite3 *localDb;
+bool isDb_ready;
+
+sqlite3 *networkDb;
+
+char MyDefaultPriceString[128];
+byte reset4gStep = RESET_4G_STEP_NONE;
+
+//================================================
+// initial can-bus
+//================================================
+int InitCanBus()
+{
+	int 					s0,nbytes;
+	struct timeval			tv;
+	struct ifreq 			ifr0;
+	struct sockaddr_can		addr0;
+
+	system("/sbin/ip link set can0 down");
+	system("/sbin/ip link set can0 type can bitrate 500000 restart-ms 100");
+	system("/sbin/ip link set can0 up");
+
+	s0 = socket(PF_CAN, SOCK_RAW, CAN_RAW);
+
+	tv.tv_sec = 0;
+	tv.tv_usec = 10000;
+   	if (setsockopt(s0, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv, sizeof(struct	timeval)) < 0)
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR_MSG("Set SO_RCVTIMEO NG");
+		#endif
+	}
+	nbytes=40960;
+	if (setsockopt(s0, SOL_SOCKET,  SO_RCVBUF, &nbytes, sizeof(int)) < 0)
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR_MSG("Set SO_RCVBUF NG");
+		#endif
+	}
+	nbytes=40960;
+	if (setsockopt(s0, SOL_SOCKET, SO_SNDBUF, &nbytes, sizeof(int)) < 0)
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR_MSG("Set SO_SNDBUF NG");
+		#endif
+	}
+
+   	strcpy(ifr0.ifr_name, "can0" );
+	ioctl(s0, SIOCGIFINDEX, &ifr0); /* ifr.ifr_ifindex gets filled with that device's index */
+	addr0.can_family = AF_CAN;
+	addr0.can_ifindex = ifr0.ifr_ifindex;
+	bind(s0, (struct sockaddr *)&addr0, sizeof(addr0));
+	return s0;
+}
+
+//================================================
+// initial uart port
+//================================================
+char *_priPortName = "/dev/ttyS1";
+char *_485PortName = "/dev/ttyS5";
+
+int InitComPort(byte target)
+{
+	int fd;
+	struct termios tios;
+
+	if(target == UPGRADE_PRI)
+		fd = open(_priPortName, O_RDWR);
+	else if (target == UPGRADE_FAN ||  target == UPGRADE_RB || target == UPGRADE_AC || target == UPGRADE_LED)
+		fd = open(_485PortName, O_RDWR);
+
+	if(fd<=0)
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR_MSG("open 407 Communication port NG \n");
+		#endif
+		return -1;
+	}
+	ioctl (fd, TCGETS, &tios);
+	tios.c_cflag = B115200| CS8 | CLOCAL | CREAD;
+	tios.c_lflag = 0;
+	tios.c_iflag = 0;
+	tios.c_oflag = 0;
+	tios.c_cc[VMIN]=0;
+	tios.c_cc[VTIME]=(unsigned char)5;
+	tios.c_lflag=0;
+	tcflush(fd, TCIFLUSH);
+	ioctl (fd, TCSETS, &tios);
+
+	return fd;
+}
+
+//=================================
+// Common routine
+//=================================
+void substr(char *dest, const char* src, unsigned int start, unsigned int cnt)
+{
+	strncpy(dest, src + start, cnt);
+	dest[cnt] = 0;
+}
+
+int InitWatchDog()
+{
+	int fd;
+	int timeout = 180;
+
+	system("/usr/bin/fuser -k /dev/watchdog");
+	sleep(1);
+	system("echo V > /dev/watchdog");
+	sleep(1);
+	fd = open("/dev/watchdog", O_RDWR);
+
+	if(fd <= 0)
+	{
+		DEBUG_ERROR_MSG("System watch dog initial fail.\r\n");
+	}
+	ioctl(fd, _IOWR('W', 6, int), &timeout);
+
+	return fd;
+}
+
+void CloseWatchDog()
+{
+	if (wtdFd > 0)
+	{
+		close(wtdFd);
+		sleep(1);
+		system("/usr/bin/fuser -k /dev/watchdog");
+		sleep(1);
+		system("echo V > /dev/watchdog");
+		sleep(1);
+	}
+}
+
+int StoreLogMsg_1(const char *fmt, ...)
+{
+	char Buf[4096+256];
+	char buffer[4096];
+	va_list args;
+	struct timeb  SeqEndTime;
+	struct tm *tm;
+
+	va_start(args, fmt);
+	int rc = vsnprintf(buffer, sizeof(buffer), fmt, args);
+	va_end(args);
+
+	memset(Buf,0,sizeof(Buf));
+	ftime(&SeqEndTime);
+	SeqEndTime.time = time(NULL);
+	tm=localtime(&SeqEndTime.time);
+
+	if (ShmSysConfigAndInfo->SysConfig.SwitchDebugFlag == YES ||
+			DEBUG_ALSTON)
+	{
+		sprintf(Buf,"%02d:%02d:%02d:%03d - %s",
+			tm->tm_hour,tm->tm_min,tm->tm_sec,SeqEndTime.millitm, buffer);
+		printf("%s \n", Buf);
+	}
+	else
+	{
+		sprintf(Buf,"echo \"%04d-%02d-%02d %02d:%02d:%02d:%03d - %s\" >> /Storage/SystemLog/[%04d.%02d]SystemLog_%s",
+			tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,SeqEndTime.millitm,
+			buffer,
+			tm->tm_year+1900,tm->tm_mon+1,
+			ShmSysConfigAndInfo->SysConfig.SerialNumber);
+		system(Buf);
+	}
+
+	return rc;
+}
+
+//unsigned long GetTimeoutValue(struct timeval _sour_time)
+//{
+//	struct timeval _end_time;
+//	gettimeofday(&_end_time, NULL);
+//
+//	return 1000000 * (_end_time.tv_sec - _sour_time.tv_sec) + _end_time.tv_usec - _sour_time.tv_usec;
+//}
+
+int GetTimeoutValue(struct timespec *startTime)
+{
+	struct timespec endTime;
+
+	clock_gettime(CLOCK_MONOTONIC_COARSE, &endTime);
+	return endTime.tv_sec - startTime->tv_sec;
+}
+
+void GetTimespecFunc(struct timespec *time)
+{
+	clock_gettime(CLOCK_MONOTONIC_COARSE, time);
+}
+
+int mystrcmp(unsigned char *p1, unsigned char *p2)
+{
+    while(*p1==*p2)
+    {
+        if(*p1=='\0' || *p2=='\0')
+            break;
+        p1++;
+        p2++;
+    }
+    if(*p1=='\0' && *p2=='\0')
+        return(PASS);
+    else
+        return(FAIL);
+}
+
+int DiffTimeb(struct timeb ST, struct timeb ET)
+{
+	//return milli-second
+	unsigned int StartTime,StopTime;
+
+	StartTime=(unsigned int)ST.time;
+	StopTime=(unsigned int)ET.time;
+	//return (StopTime-StartTime)*1000+ET.millitm-ST.millitm;
+	return (StopTime-StartTime);
+}
+
+int DiffTimebWithNowSec(struct timeb ST)
+{
+	//return milli-second
+	struct timeb ET;
+	unsigned int StartTime,StopTime;
+
+	ftime(&ET);
+	StartTime=(unsigned int)ST.time;
+	StopTime=(unsigned int)ET.time;
+	return (StopTime-StartTime);
+}
+
+int CheckTimeOut(uint8_t *start)
+{
+	int result = YES;
+	struct ParsingResult
+	{
+		int result;
+		int scanedElement;
+		int year;
+		int month;
+		int mday;
+		int hour;
+		int min;
+		int sec;
+		int tz_hour;
+		int tz_min;
+		float minSec;
+	}parsingResult;
+
+	struct tm tmStart;
+	struct timeb tbStart;
+
+	memset(&parsingResult, 0x00, sizeof(struct ParsingResult));
+
+	if(strstr((char*)start, ".") != NULL)
+	{
+		// Original data with mini second
+		if(strstr((char*)start, "Z") != NULL)
+		{
+			// Original data with Z
+			parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
+																&parsingResult.year,
+																&parsingResult.month,
+																&parsingResult.mday,
+																&parsingResult.hour,
+																&parsingResult.min,
+																&parsingResult.sec,
+																&parsingResult.minSec);
+		}
+		else
+		{
+			// Original data without Z
+			parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
+												&parsingResult.year,
+												&parsingResult.month,
+												&parsingResult.mday,
+												&parsingResult.hour,
+												&parsingResult.min,
+												&parsingResult.sec,
+												&parsingResult.minSec,
+												&parsingResult.tz_hour,
+												&parsingResult.tz_min);
+		}
+	}
+	else
+	{
+		// Original data without mini second
+		if(strstr((char*)start, "Z") != NULL)
+		{
+			// Original data with Z
+			parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
+												&parsingResult.year,
+												&parsingResult.month,
+												&parsingResult.mday,
+												&parsingResult.hour,
+												&parsingResult.min,
+												&parsingResult.sec);
+		}
+		else
+		{
+			// Original data without Z
+			parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
+												&parsingResult.year,
+												&parsingResult.month,
+												&parsingResult.mday,
+												&parsingResult.hour,
+												&parsingResult.min,
+												&parsingResult.sec,
+												&parsingResult.tz_hour,
+												&parsingResult.tz_min);
+		}
+	}
+
+	if(parsingResult.scanedElement >= 6)
+	{
+		tmStart.tm_year = parsingResult.year - 1900;
+		tmStart.tm_mon = parsingResult.month - 1;
+		tmStart.tm_mday = parsingResult.mday;
+		tmStart.tm_hour = parsingResult.hour;
+		tmStart.tm_min = parsingResult.min;
+		tmStart.tm_sec = parsingResult.sec;
+		tmStart.tm_gmtoff = 0;
+		tbStart.time = mktime(&tmStart);
+		tbStart.timezone = 0;
+		tbStart.millitm = 0;
+
+		tbStart.time -= (parsingResult.tz_hour*3600) + (parsingResult.tz_min*60*(parsingResult.tz_hour>=0?1:-1));
+
+		if(DiffTimebWithNowSec(tbStart) <= 0)
+			result = NO;
+		else
+			result = YES;
+	}
+	else
+	{
+		PRINTF_FUNC("Start date parsing error.\n");
+	}
+
+	return result;
+}
+
+void setChargerMode(byte gun_index, byte mode)
+{
+	chargingInfo[gun_index]->SystemStatus = mode;
+}
+
+void PRINTF_FUNC(char *string, ...)
+{
+	va_list args;
+	char buffer[4096];
+	va_start(args, string);
+	vsnprintf(buffer, sizeof(buffer), string, args);
+	va_end(args);
+
+	DEBUG_INFO_MSG("%s ", buffer);
+}
+
+long long DiffTimebWithNow(struct timeb ST)
+{
+	//return milli-second
+	struct timeb ET;
+	long long StartTime, StopTime;
+
+	ftime(&ET);
+	StartTime = (long long)ST.time;
+	StopTime = (long long)ET.time;
+	return ((StopTime - StartTime)*1000) + (ET.millitm - ST.millitm);
+}
+
+bool CheckBackendChargingTimeout(byte gunIndex)
+{
+	bool result = false;
+
+	if (ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_ENABLE)
+	{
+		if (ShmSysConfigAndInfo->SysConfig.MaxChargingDuration > 0)
+		{
+			if (chargingInfo[gunIndex]->PresentChargedDuration >= (ShmSysConfigAndInfo->SysConfig.MaxChargingDuration * 60))
+				result = true;
+		}
+	}
+	else if (ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_DISABLE)
+	{
+		// 隨插即充電的要看 offline
+		if (ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeDuration > 0)
+		{
+			if (chargingInfo[gunIndex]->PresentChargedDuration >= (ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeDuration * 60))
+				result = true;
+		}
+	}
+
+	return result;
+}
+
+bool CheckBackendChargingEnergy(byte gunIndex)
+{
+	bool result = false;
+
+	if (ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_ENABLE)
+	{
+		if (ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy > 0)
+		{
+			if (chargingInfo[gunIndex]->PresentChargedEnergy >= ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy)
+				result = true;
+		}
+	}
+	else if (ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_DISABLE)
+	{
+		// 隨插即充電的要看 offline
+		if (ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy > 0)
+		{
+			if (chargingInfo[gunIndex]->PresentChargedEnergy >= (ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy))
+				result = true;
+		}
+	}
+
+	return result;
+}
+
+bool CheckOcppChargingTimeout(byte gunIndex)
+{
+	bool result = false;
+
+	if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
+	{
+		if (ShmOCPP16Data->SessionTarget[gunIndex].targetDuration > 0)
+		{
+			if (chargingInfo[gunIndex]->PresentChargedDuration >= (ShmOCPP16Data->SessionTarget[gunIndex].targetDuration * 60))
+			{
+				PRINTF_FUNC("CheckOcppChargingTimeout. G_(%d) - (%d) \n", gunIndex,
+						chargingInfo[gunIndex]->PresentChargedDuration);
+				result = true;
+			}
+		}
+	}
+	else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
+	{
+		if (ShmOCPP20Data->SessionTarget[gunIndex].targetDuration > 0)
+		{
+			if (chargingInfo [gunIndex]->PresentChargedDuration >= (ShmOCPP20Data->SessionTarget[gunIndex].targetDuration * 60))
+			{
+				PRINTF_FUNC ( "CheckOcppChargingTimeout. G_(%d) - (%d) \n", gunIndex,
+						chargingInfo [gunIndex]->PresentChargedDuration );
+				result = true;
+			}
+		}
+	}
+
+	return result;
+}
+
+bool CheckOcppChargingEnergy(byte gunIndex)
+{
+	bool result = false;
+
+	if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
+	{
+		if (ShmOCPP16Data->SessionTarget[gunIndex].targetEnergy > 0)
+		{
+			if (chargingInfo[gunIndex]->PresentChargedEnergy >= ShmOCPP16Data->SessionTarget[gunIndex].targetEnergy)
+			{
+				PRINTF_FUNC ( "CheckOcppChargingEnergy. G_(%d) - (%f) \n", gunIndex,
+						chargingInfo[gunIndex]->PresentChargedEnergy );
+				result = true;
+			}
+		}
+	}
+	else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
+	{
+		if (ShmOCPP20Data->SessionTarget[gunIndex].targetEnergy > 0)
+		{
+			if (chargingInfo [gunIndex]->PresentChargedEnergy >= ShmOCPP20Data->SessionTarget[gunIndex].targetEnergy)
+			{
+				PRINTF_FUNC ( "CheckOcppChargingEnergy. G_(%d) - (%f) \n", gunIndex,
+						chargingInfo [gunIndex]->PresentChargedEnergy );
+				result = true;
+			}
+		}
+	}
+
+	return result;
+}
+
+bool CheckOcppChargingSOC(byte gunIndex)
+{
+	bool result = false;
+
+	if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
+	{
+		if (ShmOCPP16Data->SessionTarget[gunIndex].targetSoc > 0)
+		{
+			if (chargingInfo [gunIndex]->EvBatterySoc >= (ShmOCPP16Data->SessionTarget[gunIndex].targetSoc))
+			{
+				PRINTF_FUNC ( "CheckOcppChargingSOC. G_(%d) - (%d) \n", gunIndex,
+						chargingInfo [gunIndex]->PresentChargedDuration );
+				result = true;
+			}
+		}
+	}
+	else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
+	{
+		if (ShmOCPP20Data->SessionTarget[gunIndex].targetSoc > 0)
+		{
+			if (chargingInfo [gunIndex]->EvBatterySoc >= (ShmOCPP20Data->SessionTarget[gunIndex].targetSoc))
+			{
+				PRINTF_FUNC ( "CheckOcppChargingSOC. G_(%d) - (%d) \n", gunIndex,
+						chargingInfo [gunIndex]->PresentChargedDuration );
+				result = true;
+			}
+		}
+	}
+
+	return result;
+}
+
+bool IsGunUsing(byte dcGunIndex)
+{
+	bool result = false;
+
+	if((chargingInfo[dcGunIndex]->SystemStatus >= SYS_MODE_MODE_REASSIGN_CHECK &&
+			chargingInfo[dcGunIndex]->SystemStatus <= SYS_MODE_ALARM) ||
+			(chargingInfo[dcGunIndex]->SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0 &&
+			chargingInfo[dcGunIndex]->SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))
+	{
+		result = true;
+	}
+	return result;
+}
+
+//==========================================
+// Log
+//==========================================
+void CheckFwSlotStatusLog()
+{
+	if (bd0_1_status == 0 && bd0_2_status == 1)
+		PRINTF_FUNC("Connector 1 : Chademo");
+	else if (bd0_1_status == 1 && bd0_2_status == 0)
+		PRINTF_FUNC("Connector 1 : CCS");
+	else if (bd0_1_status == 1 && bd0_2_status == 1)
+		PRINTF_FUNC("Connector 1 : GB");
+
+	if (bd1_1_status == 0 && bd1_2_status == 1)
+		PRINTF_FUNC("Connector 2 : Chademo");
+	else if (bd1_1_status == 1 && bd1_2_status == 0)
+		PRINTF_FUNC("Connector 2 : CCS");
+	else if (bd1_1_status == 1 && bd1_2_status == 1)
+		PRINTF_FUNC("Connector 2 : GB");
+}
+
+void CheckHwSlotStatusLog(byte index)
+{
+	if (chargingInfo[index]->Type == _Type_Chademo)
+	{
+		PRINTF_FUNC("Hw check : Connector %d, Type : Chademo, Evboard_id = %d \n",
+			index, chargingInfo[index]->Evboard_id);
+	}
+	else if (chargingInfo[index]->Type == _Type_CCS)
+	{
+		PRINTF_FUNC("Hw check : Connector %d, Type : CCS, Evboard_id = %d \n",
+			index, chargingInfo[index]->Evboard_id);
+	}
+	else if (chargingInfo[index]->Type == _Type_GB)
+	{
+		PRINTF_FUNC("Hw check : Connector %d, Type : GB, Evboard_id = %d \n",
+			index, chargingInfo[index]->Evboard_id);
+	}
+}
+//==========================================
+// Check interface status
+//==========================================
+int isInterfaceUp(const char *interface)
+{
+	int result = FAIL;
+
+	FILE *fp;
+	char cmd[256];
+	char buf[512];
+
+	strcpy(cmd, "ifconfig");
+	fp = popen(cmd, "r");
+	if(fp != NULL)
+	{
+		while(fgets(buf, sizeof(buf), fp) != NULL)
+		{
+			if(strstr(buf, interface) > 0)
+			{
+				result = PASS;
+			}
+		}
+	}
+	pclose(fp);
+
+	return result;
+}
+
+//=================================
+// Create all share memory
+//=================================
+int CreateShareMemory()
+{
+	int MeterSMId;
+
+	if ((MeterSMId = shmget(ShmSysConfigAndInfoKey,	sizeof(struct SysConfigAndInfo), IPC_CREAT | 0777)) < 0)
+	{
+		DEBUG_ERROR_MSG("[main]CreatShareMemory:shmget ShmSysConfigAndInfo NG \n");
+		return 0;
+	}
+	else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0))	== (void *) -1)
+	{
+		DEBUG_ERROR_MSG("[main]CreatShareMemory:shmat ShmSysConfigAndInfo NG \n");
+		return 0;
+	}
+	memset(ShmSysConfigAndInfo, 0, sizeof(struct SysConfigAndInfo));
+
+	if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), IPC_CREAT | 0777)) < 0)
+	{
+		DEBUG_ERROR_MSG("[main]CreatShareMemory:shmget ShmStatusCodeData NG \n");
+		return 0;
+	}
+	else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
+	{
+		DEBUG_ERROR_MSG("[main]CreatShareMemory:shmat ShmStatusCodeData NG \n");
+		return 0;
+	}
+	memset(ShmStatusCodeData, 0, sizeof(struct StatusCodeData));
+
+	//creat ShmPsuData
+	if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), IPC_CREAT | 0777)) < 0)
+	{
+		DEBUG_ERROR_MSG("[main]CreatShareMemory:shmget ShmPsuData NG \n");
+		return 0;
+	}
+	else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
+	{
+		DEBUG_ERROR_MSG("[main]CreatShareMemory:shmat ShmPsuData NG \n");
+		return 0;
+	}
+	memset(ShmPsuData, 0, sizeof(struct PsuData));
+
+	if(CHAdeMO_QUANTITY > 0)
+	{
+		if ((MeterSMId = shmget(ShmCHAdeMOCommKey, sizeof(struct CHAdeMOData),	IPC_CREAT | 0777)) < 0)
+		{
+			DEBUG_ERROR_MSG("[main]CreatShareMemory:shmget ShmCHAdeMOData NG \n");
+			return 0;
+		}
+		else if ((ShmCHAdeMOData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
+		{
+			DEBUG_ERROR_MSG("[main]CreatShareMemory:shmat ShmCHAdeMOData NG \n");
+			return 0;
+		}
+		memset(ShmCHAdeMOData, 0, sizeof(struct CHAdeMOData));
+	}
+
+	if(GB_QUANTITY > 0)
+	{
+		if ((MeterSMId = shmget(ShmGBTCommKey, sizeof(struct GBTData),	IPC_CREAT | 0777)) < 0)
+		{
+			DEBUG_ERROR_MSG("[main]CreatShareMemory:shmget ShmGBTData NG \n");
+			return 0;
+		}
+		else if ((ShmGBTData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
+		{
+			DEBUG_ERROR_MSG("[main]CreatShareMemory:shmat ShmGBTData NG \n");
+			return 0;
+		}
+		memset(ShmGBTData, 0, sizeof(struct GBTData));
+	}
+
+	//creat ShmCcsData
+	if(CCS_QUANTITY > 0)
+	{
+		if ((MeterSMId = shmget(ShmCcsCommKey, sizeof(struct CcsData),	IPC_CREAT | 0777)) < 0)
+		{
+			DEBUG_ERROR_MSG("[main]CreatShareMemory:shmget ShmCcsData NG \n");
+			return 0;
+		}
+		else if ((ShmCcsData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
+		{
+			DEBUG_ERROR_MSG("[main]CreatShareMemory:shmat ShmCcsData NG \n");
+			return 0;
+		}
+		memset(ShmCcsData, 0, sizeof(struct CcsData));
+	}
+
+	//creat ShmPrimaryMcuData
+	if ((MeterSMId = shmget(ShmPrimaryMcuKey, sizeof(struct PrimaryMcuData), IPC_CREAT | 0777)) < 0)
+	{
+		DEBUG_ERROR_MSG("[main]CreatShareMemory:shmget ShmPrimaryMcuData NG \n");
+		return 0;
+	}
+	else if ((ShmPrimaryMcuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
+	{
+		DEBUG_ERROR_MSG("[main]CreatShareMemory:shmat ShmPrimaryMcuData NG \n");
+		return 0;
+	}
+	memset(ShmPrimaryMcuData, 0, sizeof(struct PrimaryMcuData));
+
+	//creat ShmFanModuleData
+	if ((MeterSMId = shmget(ShmFanBdKey, sizeof(struct FanModuleData),	IPC_CREAT | 0777)) < 0)
+	{
+		DEBUG_ERROR_MSG("[main]CreatShareMemory:shmget ShmFanModuleData NG \n");
+		return 0;
+	}
+	else if ((ShmFanModuleData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
+	{
+		DEBUG_ERROR_MSG("[main]CreatShareMemory:shmat ShmFanModuleData NG \n");
+		return 0;
+	}
+	memset(ShmFanModuleData, 0, sizeof(struct FanModuleData));
+
+	//creat ShmRelayModuleData
+	if ((MeterSMId = shmget(ShmRelayBdKey, sizeof(struct RelayModuleData),	IPC_CREAT | 0777)) < 0)
+	{
+		DEBUG_ERROR_MSG("[main]CreatShareMemory:shmget ShmRelayModuleData NG \n");
+		return 0;
+	}
+	else if ((ShmRelayModuleData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
+	{
+		DEBUG_ERROR_MSG("[main]CreatShareMemory:shmat ShmRelayModuleData NG \n");
+		return 0;
+	}
+	memset(ShmRelayModuleData, 0, sizeof(struct RelayModuleData));
+
+	if ((MeterSMId = shmget(ShmLedBdKey, sizeof(struct LedModuleData), IPC_CREAT | 0777)) < 0)
+	{
+		DEBUG_ERROR_MSG("[main]CreatShareMemory:shmget ShmLedModuleData NG \n");
+		return 0;
+	}
+	else if ((ShmLedModuleData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
+	{
+		DEBUG_ERROR_MSG("[main]CreatShareMemory:shmat ShmLedModuleData NG \n");
+		return 0;
+	}
+	memset(ShmLedModuleData, 0, sizeof(struct LedModuleData));
+
+	//creat ShmOCPP16Data
+	if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), IPC_CREAT | 0777)) < 0)
+	{
+		DEBUG_ERROR_MSG("[main]CreatShareMemory:shmget ShmOCPP16Data NG \n");
+		return 0;
+	}
+	else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
+	{
+		DEBUG_ERROR_MSG("[main]CreatShareMemory:shmat ShmOCPP16Data NG \n");
+		return 0;
+	}
+	memset(ShmOCPP16Data,0,sizeof(struct OCPP16Data));
+
+	if ((MeterSMId = shmget(ShmOcpp20ModuleKey, sizeof(struct OCPP20Data), IPC_CREAT | 0777)) < 0)
+	{
+		DEBUG_ERROR_MSG("[main]CreatShareMemory:shmget OCPP20Data NG\n");
+		return 0;
+	}
+	else if ((ShmOCPP20Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
+	{
+		DEBUG_ERROR_MSG("[main]CreatShareMemory:shmat OCPP20Data NG\n");
+		return 0;
+	}
+	memset(ShmOCPP20Data,0,sizeof(struct OCPP20Data));
+
+	if ((MeterSMId = shmget(ShmCsuMeterKey, sizeof(struct MeterInformation), IPC_CREAT | 0777)) < 0)
+	{
+		DEBUG_ERROR_MSG("[main]CreatShareMemory:shmget ShmCsuMeterKey NG \n");
+		return 0;
+	}
+	else if ((ShmCsuMeterData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
+	{
+		DEBUG_ERROR_MSG("[main]CreatShareMemory:shmat ShmCsuMeterData NG \n");
+		return 0;
+	}
+	memset(ShmCsuMeterData, 0, sizeof(struct MeterInformation));
+
+	if ((MeterSMId = shmget(ShmCommonKey, sizeof(struct DcCommonInformation), IPC_CREAT | 0777)) < 0)
+	{
+		DEBUG_ERROR_MSG("[main]CreatShareMemory:shmget ShmCommonKey NG \n");
+		return 0;
+	}
+	else if ((ShmDcCommonData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
+	{
+		DEBUG_ERROR_MSG("[main]CreatShareMemory:shmat ShmCommonKey NG \n");
+		return 0;
+	}
+	byte buf = 0;
+	if (ShmDcCommonData->rebootCount == 1)
+		buf = ShmDcCommonData->rebootCount;
+	memset(ShmDcCommonData, 0, sizeof(struct DcCommonInformation));
+
+	ShmDcCommonData->rebootCount = buf;
+	return 1;
+}
+
+void SetupRebootCount(byte value)
+{
+	int MeterSMId;
+
+	if ((MeterSMId = shmget(ShmCommonKey, sizeof(struct DcCommonInformation), IPC_CREAT | 0777)) < 0)
+	{
+		DEBUG_ERROR_MSG("[main]RecordRebootCount:shmget ShmCommonKey NG \n");
+	}
+	else
+	{
+		ShmDcCommonData->rebootCount = value;
+		shmctl(MeterSMId, IPC_SET, 0);
+	}
+}
+
+//=================================
+// LCM Page
+//=================================
+void ChangeLcmByIndex(byte page_index)
+{
+	if (ShmSysConfigAndInfo->SysWarningInfo.Level != _ALARM_LEVEL_CRITICAL ||
+			page_index == _LCM_COMPLETE || page_index == _LCM_FIX || page_index == _LCM_EMC)
+	{
+		if (ShmSysConfigAndInfo->SysConfig.TotalConnectorCount > 0 &&
+				(page_index == _LCM_FIX || page_index == _LCM_EMC))
+		{
+			bool isUpdate = false;
+			for (byte _index = 0; _index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _index++)
+			{
+				if (chargingInfo[_index]->SystemStatus != SYS_MODE_RESERVATION &&
+						chargingInfo[_index]->SystemStatus != SYS_MODE_MAINTAIN)
+				{
+					isUpdate = true;
+				}
+			}
+
+			if (isUpdate &&
+					ShmDcCommonData->LcmFwVersion > 0 &&
+					ShmStatusCodeData->AlarmCode.AlarmEvents.bits.EmergencyStopTrip == YES)
+				ShmSysConfigAndInfo->SysInfo.PageIndex = _LCM_EMC;
+			else
+				ShmSysConfigAndInfo->SysInfo.PageIndex = _LCM_FIX;
+		}
+		else
+			ShmSysConfigAndInfo->SysInfo.PageIndex = page_index;
+	}
+}
+
+//======================================================
+// Peripheral initial
+//======================================================
+void InitGPIO()
+{
+	/*****************0~3, 4 bank, bank x 32+ num*********************/
+	/***************************************************************/
+	/*************** GPIO 0 ***************************************/
+	/***************************************************************/
+	/* GPMC_AD8			=> 	GPIO0_22 *//*ID BD1_1*/
+	system("echo 22 > /sys/class/gpio/export");
+	system("echo \"in\" > /sys/class/gpio/gpio22/direction");
+	/* GPMC_AD9			=>	GPIO0_23 *//*ID BD1_2*/
+	system("echo 23 > /sys/class/gpio/export");
+	system("echo \"in\" > /sys/class/gpio/gpio23/direction");
+	/* GPMC_AD10		=>	GPIO0_26 *//*IO BD1_1*/
+	system("echo 26 > /sys/class/gpio/export");
+	system("echo \"out\" > /sys/class/gpio/gpio26/direction");
+	system("echo 1 > /sys/class/gpio/gpio26/value");
+	/* GPMC_AD11		=>	GPIO0_27 *//*IO BD1_2*/
+	system("echo 27 > /sys/class/gpio/export");
+	system("echo \"in\" > /sys/class/gpio/gpio27/direction");
+	/* RMII1_REF_CLK		=>	GPIO0_29 *//*USB 0 OCP detection*/
+	system("echo 29 > /sys/class/gpio/export");
+	system("echo \"in\" > /sys/class/gpio/gpio29/direction");
+	/*XDMA_EVENT_INTR0	=>	GPIO0_19 *//*AM_RFID_RST*/
+	system("echo 19 > /sys/class/gpio/export");
+	system("echo \"out\" > /sys/class/gpio/gpio19/direction");
+	system("echo 1 > /sys/class/gpio/gpio19/value");
+	/*XDMA_EVENT_INTR1	=>	GPIO0_20 *//*AM_RFID_ICC*/
+	system("echo 20 > /sys/class/gpio/export");
+	system("echo \"in\" > /sys/class/gpio/gpio20/direction");
+	/***************************************************************/
+	/*************** GPIO 1 ***************************************/
+	/***************************************************************/
+	/* GPMC_AD12	=> 	GPIO1_12 *//*ID BD2_1*/
+	system("echo 44 > /sys/class/gpio/export");
+	system("echo \"in\" > /sys/class/gpio/gpio44/direction");
+	/* GPMC_AD13	=>	GPIO1_13 *//*ID BD2_2*/
+	system("echo 45 > /sys/class/gpio/export");
+	system("echo \"in\" > /sys/class/gpio/gpio45/direction");
+	/* GPMC_AD14	=>	GPIO1_14 *//*IO BD2_1*/
+	system("echo 46 > /sys/class/gpio/export");
+	system("echo \"out\" > /sys/class/gpio/gpio46/direction");
+	system("echo 0 > /sys/class/gpio/gpio46/value");
+	/* GPMC_AD15	=>	GPIO1_15 *//*IO BD2_2*/
+	system("echo 47 > /sys/class/gpio/export");
+	system("echo \"in\" > /sys/class/gpio/gpio47/direction");
+	/***************************************************************/
+	/*************** GPIO 2 ***************************************/
+	/***************************************************************/
+	/*LCD_AC_BIAS_EN	=>	GPIO2_25*//*RS-485 for module DE control*/
+	system("echo 89 > /sys/class/gpio/export");
+	system("echo \"out\" > /sys/class/gpio/gpio89/direction");
+	system("echo 1 > /sys/class/gpio/gpio89/value");
+	/*LCD_HSYNC		=>	GPIO2_23*//*RS-485 for module RE control*/
+	system("echo 87 > /sys/class/gpio/export");
+	system("echo \"out\" > /sys/class/gpio/gpio87/direction");
+	system("echo 0 > /sys/class/gpio/gpio87/value");
+	/*LCD_PCLK		=>	GPIO2_24*//*CCS communication board 1 proximity*/
+	system("echo 88 > /sys/class/gpio/export");
+	system("echo \"in\" > /sys/class/gpio/gpio88/direction");
+	/*LCD_VSYNC		=>	GPIO2_22*//*CCS communication board 2 proximity*/
+	system("echo 86 > /sys/class/gpio/export");
+	system("echo \"in\" > /sys/class/gpio/gpio86/direction");
+	/***************************************************************/
+	/*************** GPIO 3 ***************************************/
+	/***************************************************************/
+	/*MCASP0_FSX		=>	GPIO3_15*//*Emergency Stop button detect*/
+	system("echo 111 > /sys/class/gpio/export");
+	system("echo \"in\" > /sys/class/gpio/gpio111/direction");
+	/*MCASP0_ACLKR	=>	GPIO3_18*//*USB1 OCP detect*/
+	system("echo 114 > /sys/class/gpio/export");
+	system("echo \"in\" > /sys/class/gpio/gpio114/direction");
+	/*MCASP0_AHCLKR	=>	GPIO3_17*//*Emergency IO for AM3352 and STM32F407*/
+	system("echo 113 > /sys/class/gpio/export");
+	system("echo \"in\" > /sys/class/gpio/gpio113/direction");
+	/*MCASP0_ACLKX	=>	GPIO3_14*//*Ethernet PHY reset*/
+	system("echo 110 > /sys/class/gpio/export");
+	system("echo \"out\" > /sys/class/gpio/gpio110/direction");
+	system("echo 0 > /sys/class/gpio/gpio110/value");
+	/* MCASP0_FSR		=>	GPIO3_19 *//*SMR Enable control_1 for Pskill_1*/
+	system("echo 115 > /sys/class/gpio/export");
+	system("echo \"out\" > /sys/class/gpio/gpio115/direction");
+	system("echo 0 > /sys/class/gpio/gpio115/value");
+	/* MCASP0_AXR0	=>	GPIO3_16 *//*CSU board function OK indicator.*/
+	system("echo 112 > /sys/class/gpio/export");
+	system("echo \"out\" > /sys/class/gpio/gpio112/direction");
+	system("echo 1 > /sys/class/gpio/gpio112/value");
+	/* MCASP0_AXR1	=>	GPIO3_20 *//*SMR Enable control_2 for Pskill_2*/
+	system("echo 116 > /sys/class/gpio/export");
+	system("echo \"out\" > /sys/class/gpio/gpio116/direction");
+	system("echo 0 > /sys/class/gpio/gpio116/value");
+	/* (C14) EMU0.gpio3[7] */  /*CP open/short feature enable/disable, pull low for default enable*/
+	system("echo 103 > /sys/class/gpio/export");
+	system("echo \"out\" > /sys/class/gpio/gpio103/direction");
+	system("echo 0 > /sys/class/gpio/gpio103/value");
+	/* (B14) EMU1.gpio3[8] */  /*4G module reset, pull high to reset when entry kernel, after Application start, it should be pull low.*/
+	system("echo 104 > /sys/class/gpio/export");
+	system("echo \"out\" > /sys/class/gpio/gpio104/direction");
+	system("echo 0 > /sys/class/gpio/gpio104/value");
+#ifdef SystemLogMessage
+	DEBUG_INFO_MSG("[main]InitGPIO: Initial GPIO OK \n");
+#endif
+}
+
+int LoadSysConfigAndInfo(struct SysConfigData *ptr)
+{
+	int fd,wrd;
+	unsigned char *buf;
+	unsigned int ChkSum,ChkSumOrg;
+
+	if((buf=malloc(MtdBlockSize))==NULL)
+	{
+		DEBUG_ERROR_MSG("malloc buffer NG,rebooting..\r\n");
+		if(ShmStatusCodeData!=NULL)
+		{
+			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed=1;
+		}
+		sleep(5);
+		system("reboot -f");
+		sleep(5);
+		system("reboot -f");
+	}
+	memset(buf, 0, MtdBlockSize);
+
+	//================================================
+	// Load configuration from mtdblock10
+	//================================================
+	system("nanddump /dev/mtd10 -f /mnt/EvseConfig.bin");
+	//fd = open("/dev/mtdblock10", O_RDWR);
+	fd = open("/mnt/EvseConfig.bin", O_RDWR);
+	if (fd < 0)
+	{
+		free(buf);
+		DEBUG_ERROR_MSG("open mtdblock10 NG,rebooting..\r\n");
+		if(ShmStatusCodeData!=NULL)
+		{
+			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed=1;
+		}
+		sleep(5);
+		system("reboot -f");
+		sleep(5);
+		system("reboot -f");
+	}
+
+	wrd=read(fd, buf, MtdBlockSize);
+	close(fd);
+	if(wrd<MtdBlockSize)
+	{
+		free(buf);
+		DEBUG_ERROR_MSG("read SysConfigData data NG,rebooting..\r\n");
+		if(ShmStatusCodeData!=NULL)
+		{
+			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed=1;
+		}
+		sleep(5);
+		system("reboot -f");
+		sleep(5);
+		system("reboot -f");
+	}
+	ChkSum=0;
+
+//	for(wrd=0;wrd<MtdBlockSize-4;wrd++)
+//	{
+//		ChkSum+=buf[wrd];
+//	}
+//	memcpy(&ChkSumOrg,buf+(0x00600000-4),sizeof(ChkSumOrg));
+	for(wrd=ARRAY_SIZE(ptr->CsuBootLoadFwRev);wrd<MtdBlockSize-4;wrd++)
+	{
+		ChkSum+=buf[wrd];
+	}
+	memcpy(&ChkSumOrg,buf+(MtdBlockSize-4),sizeof(ChkSumOrg));
+	memcpy(&ptr->ModelName,buf+(ARRAY_SIZE(ptr->CsuBootLoadFwRev)),ARRAY_SIZE(ptr->ModelName));
+	memcpy(&ptr->SerialNumber,buf+(ARRAY_SIZE(ptr->CsuBootLoadFwRev)+ARRAY_SIZE(ptr->ModelName)+ARRAY_SIZE(ptr->AcModelName)),ARRAY_SIZE(ptr->SerialNumber));
+
+	//================================================
+	// Load configuration from mtdblock11
+	//================================================
+	if(ChkSum!=ChkSumOrg)
+	{
+		DEBUG_ERROR_MSG("Primary SysConfigData checksum NG, read backup\r\n");
+		system("nanddump /dev/mtd11 -f /mnt/EvseConfig.bin");
+		//fd = open("/dev/mtdblock11", O_RDWR);
+		fd = open("/mnt/EvseConfig.bin", O_RDWR);
+		if (fd < 0)
+		{
+			free(buf);
+			DEBUG_ERROR_MSG("open mtdblock11 (backup) NG,rebooting..\r\n");
+			if(ShmStatusCodeData!=NULL)
+			{
+				ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed=1;
+			}
+			sleep(5);
+			system("reboot -f");
+			sleep(5);
+			system("reboot -f");
+		}
+
+		memset(buf, 0, MtdBlockSize);
+	    wrd=read(fd, buf,MtdBlockSize);
+	    close(fd);
+		if(wrd<MtdBlockSize)
+		{
+			free(buf);
+			DEBUG_ERROR_MSG("read backup SysConfigData data NG,rebooting..\r\n");
+			if(ShmStatusCodeData!=NULL)
+			{
+				ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed=1;
+			}
+			sleep(5);
+			system("reboot -f");
+			sleep(5);
+			system("reboot -f");
+		}
+		ChkSum=0;
+//		for(wrd=0;wrd<MtdBlockSize-4;wrd++)
+//		{
+//			ChkSum+=buf[wrd];
+//		}
+//		memcpy(&ChkSumOrg,buf+(0x00600000-4),sizeof(ChkSumOrg));
+		for(wrd=ARRAY_SIZE(ptr->CsuBootLoadFwRev);wrd<MtdBlockSize-4;wrd++)
+		{
+			ChkSum+=buf[wrd];
+		}
+		memcpy(&ChkSumOrg,buf+(MtdBlockSize-4),sizeof(ChkSumOrg));
+
+		//================================================
+		// Load configuration from mtdblock12 (Factory default)
+		//================================================
+		if(ChkSum!=ChkSumOrg)
+		{
+			DEBUG_ERROR_MSG("backup SysConfigData checksum NG, read Factory default\r\n");
+			system("nanddump /dev/mtd12 -f /mnt/EvseConfig.bin");
+			//fd = open("/dev/mtdblock12", O_RDWR);
+			fd = open("/mnt/EvseConfig.bin", O_RDWR);
+			if (fd < 0)
+			{
+				free(buf);
+				DEBUG_ERROR_MSG("open mtdblock12 (Factory default) NG,rebooting..\r\n");
+				if(ShmStatusCodeData!=NULL)
+				{
+					ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed=1;
+				}
+				sleep(5);
+				system("reboot -f");
+				sleep(5);
+				system("reboot -f");
+		    }
+		    memset(buf, 0, MtdBlockSize);
+	   		wrd=read(fd, buf,MtdBlockSize);
+	    	close(fd);
+			if(wrd<MtdBlockSize)
+			{
+				free(buf);
+				DEBUG_ERROR_MSG("read factory default  SysConfigData data NG,rebooting..\r\n");
+				if(ShmStatusCodeData!=NULL)
+				{
+					ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed=1;
+				}
+				sleep(5);
+				system("reboot -f");
+				sleep(5);
+				system("reboot -f");
+			}
+			ChkSum=0;
+//			for(wrd=0;wrd<MtdBlockSize-4;wrd++)
+//			{
+//				ChkSum+=buf[wrd];
+//			}
+//			memcpy(&ChkSumOrg,buf+(0x00600000-4),sizeof(ChkSumOrg));
+			for(wrd=ARRAY_SIZE(ptr->CsuBootLoadFwRev);wrd<MtdBlockSize-4;wrd++)
+			{
+				ChkSum+=buf[wrd];
+			}
+			memcpy(&ChkSumOrg,buf+(MtdBlockSize-4),sizeof(ChkSumOrg));
+			memcpy(buf+(ARRAY_SIZE(ptr->CsuBootLoadFwRev)), &ptr->ModelName, ARRAY_SIZE(ptr->ModelName));
+			memcpy(buf+(ARRAY_SIZE(ptr->CsuBootLoadFwRev)+ARRAY_SIZE(ptr->ModelName)+ARRAY_SIZE(ptr->AcModelName)), &ptr->SerialNumber, ARRAY_SIZE(ptr->SerialNumber));
+
+			if(ChkSum!=ChkSumOrg)
+			{
+				DEBUG_ERROR_MSG("factory default  SysConfigData checksum NG, restore factory default\r\n");
+				free(buf);
+				//system("cd /root;./FactoryConfig -m");
+
+				sleep(5);
+				char facBuf[256];
+				sprintf(facBuf, "cd /root;./FactoryConfig -m %s %s",
+						ShmSysConfigAndInfo->SysConfig.ModelName,
+						ShmSysConfigAndInfo->SysConfig.SerialNumber);
+				system(facBuf);
+
+				system("rm -f /Storage/OCPP/OCPPConfiguration");
+				system("sync");
+				sleep(5);
+				system("reboot -f");
+				sleep(5);
+				system("reboot -f");
+
+				return FAIL;
+			}
+		}
+	}
+
+	//load OK
+	memcpy((struct SysConfigData *)ptr,buf,sizeof(struct SysConfigData));
+	free(buf);
+
+	system("rm -f /mnt/EvseConfig.bin");
+
+	// SysConfig in flash is empty (0xffffffff)
+	if((strlen((char*)ShmSysConfigAndInfo->SysConfig.ModelName) > ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.ModelName)) ||
+		   (strlen((char*)ShmSysConfigAndInfo->SysConfig.SerialNumber) > ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.SerialNumber)) ||
+		   (strlen((char*)ShmSysConfigAndInfo->SysConfig.SystemId) > ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.SystemId)) ||
+		   (ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthDhcpClient == 0xff))
+	{
+		if(strlen((char*)ShmSysConfigAndInfo->SysConfig.ModelName) > ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.ModelName))
+		{
+			PRINTF_FUNC("Model name over length.\n");
+			memset(ShmSysConfigAndInfo->SysConfig.ModelName, 0x00, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.ModelName));
+		}
+
+		if(strlen((char*)ShmSysConfigAndInfo->SysConfig.SerialNumber) > ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.SerialNumber))
+		{
+			PRINTF_FUNC("Model serial number over length.\n");
+			memset(ShmSysConfigAndInfo->SysConfig.SerialNumber, 0x00, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.SerialNumber));
+		}
+
+		if(strlen((char*)ShmSysConfigAndInfo->SysConfig.SystemId) > ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.SystemId))
+		{
+			PRINTF_FUNC("System id over length.\n");
+			memset(ShmSysConfigAndInfo->SysConfig.SystemId, 0x00, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.SystemId));
+		}
+
+		if(ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthDhcpClient == 0xff)
+		{
+			PRINTF_FUNC("Ethernet dhcp config is null.\n");
+		}
+
+		system("cd /root;./Module_FactoryConfig -m");
+		sleep(3);
+		system("/usr/bin/run_evse_restart.sh");
+	}
+
+	PRINTF_FUNC("*********************************************************** \n");
+	DEBUG_INFO_MSG("Load SysConfigData OK\r\n");
+
+	if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
+	{
+		memcpy((char*)ShmOCPP16Data->ChargeBoxId,
+				(char*)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,
+				ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.ChargeBoxId));
+	}
+	else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
+	{
+		memcpy((char*)ShmOCPP20Data->ChargeBoxId,
+				(char*)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,
+				ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.ChargeBoxId));
+	}
+
+	return PASS;
+}
+
+int isRouteFail()
+{
+	int result = YES;
+	FILE *fp;
+	char buf[512];
+
+	fp = popen("route -n", "r");
+	if(fp != NULL)
+	{
+		while(fgets(buf, sizeof(buf), fp) != NULL)
+		{
+			if(strstr(buf, "eth0") != NULL)
+				result = NO;
+		}
+	}
+	pclose(fp);
+
+	return result;
+}
+
+int isReachableInternet()
+{
+	int result = FAIL;
+	FILE *fp;
+	char cmd[256];
+	char buf[512];
+	char tmp[512];
+
+//	if (ShmOCPP16Data->OcppConnStatus == PASS)
+//	{
+//		result = PASS;
+//	}
+//	else
+	{
+		strcpy(cmd, "ifconfig eth0");
+		fp = popen(cmd, "r");
+
+		if (fp != NULL)
+		{
+			while(fgets(buf, sizeof(buf), fp) != NULL)
+			{
+				if (strstr(buf, "inet addr:") > 0)
+				{
+					sscanf(buf, "%*s%s", tmp);
+					substr(tmp, tmp, strspn(tmp, "addr:"), strlen(buf)-strspn(tmp, "addr:"));
+
+					if (strcmp(tmp, (char *)ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthIpAddress) != EQUAL)
+					{
+						strcpy((char *) ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthIpAddress, tmp);
+					}
+
+					sscanf(buf, "%*s%*s%*s%s", tmp);
+					substr(tmp, tmp, strspn(tmp, "Mask:"), strlen(buf)-strspn(tmp, "Mask:"));
+					if (strcmp(tmp, (char *)ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthSubmaskAddress) != 0)
+					{
+						strcpy((char *) ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthSubmaskAddress, tmp);
+					}
+				}
+			}
+		}
+		pclose(fp);
+		memset(buf, 0x00, sizeof(buf));
+
+		for(int idx=0;idx<ARRAY_SIZE(valid_Internet);idx++)
+		{
+			sprintf(cmd, "ping -c 1 -w 3 -I eth0 %s", valid_Internet[idx]);
+			fp = popen(cmd, "r");
+			if(fp != NULL)
+			{
+				while(fgets(buf, sizeof(buf), fp) != NULL)
+				{
+					if(strstr(buf, "transmitted") > 0)
+					{
+						//sscanf(buf, "%*s%*s%*s%*s%*s%*s%s", tmp);
+
+						if(strstr(buf,"100%") != NULL)
+						{
+						}
+						else
+						{
+							result = PASS;
+						}
+						//DEBUG_INFO("%s",buf);
+						//DEBUG_INFO("%s\n",tmp);
+					}
+				}
+			}
+			pclose(fp);
+		}
+	}
+
+	return result;
+}
+
+void InitEthernet()
+{
+	system("ifconfig eth0 down");// eth0 down
+	system("ifconfig eth1 down");// eth1 down
+	sleep(2);
+	char tmpbuf[256];
+	// /sbin/ifconfig eth0 192.168.1.10 netmask 255.255.255.0 down
+	system("echo 1 > /sys/class/gpio/gpio110/value");//reset PHY
+	sleep(2);
+	//Init Eth0 for internet
+	memset(tmpbuf,0,256);
+	sprintf(tmpbuf,"/sbin/ifconfig eth0 %s netmask %s up",
+	ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthIpAddress,
+	ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthSubmaskAddress);
+	system(tmpbuf);
+
+	memset(tmpbuf,0,256);
+	sprintf(tmpbuf,"route add default gw %s eth0 ",
+	ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthGatewayAddress);
+	system(tmpbuf);
+
+	//system("ifconfig lo up");
+	//  /sbin/ifconfig eth0 192.168.1.10 netmask 255.255.255.0 up
+    //Init Eth1 for administrator tool
+	memset(tmpbuf,0,256);
+	sprintf(tmpbuf,"/sbin/ifconfig eth1 %s netmask %s up",
+	ShmSysConfigAndInfo->SysConfig.Eth1Interface.EthIpAddress,
+	ShmSysConfigAndInfo->SysConfig.Eth1Interface.EthSubmaskAddress);
+	system(tmpbuf);
+
+    //Run DHCP client if enabled
+	system("killall udhcpc");
+	system("rm -rf /etc/resolv.conf");
+	system("echo nameserver 8.8.8.8 > /etc/resolv.conf");		//Google DNS server
+	system("echo nameserver 180.76.76.76 > /etc/resolv.conf");	//Baidu DNS server
+	//system("/sbin/ifconfig eth0 down;/sbin/ifconfig eth0 up");
+
+	if(ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthDhcpClient == 0)
+	{
+		sprintf(tmpbuf, "/sbin/udhcpc -i eth0 -x hostname:CSU3_%s -s /root/dhcp_script/eth0.script > /dev/null &", ShmSysConfigAndInfo->SysConfig.SystemId);
+		system(tmpbuf);
+	}
+
+	//Upgrade system id to /etc/hostname
+	sprintf(tmpbuf, "echo %s > /etc/hostname", ShmSysConfigAndInfo->SysConfig.SystemId);
+	system(tmpbuf);
+
+	pid_t pid = fork();
+	uint8_t cnt_pingDNS_Fail;
+
+	if(pid == 0)
+	{
+		for(;;)
+		{
+			if (isRouteFail())
+			{
+				//PRINTF_FUNC("eth0 not in route, restart eht0. \n");
+				system("/sbin/ifconfig eth0 down;/sbin/ifconfig eth0 up");
+
+				if (ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthDhcpClient == 0)
+				{
+					InitialDHCP();
+				}
+				else
+				{
+					system("pgrep -f \"udhcpc -i eth0\" | xargs kill");
+					memset(tmpbuf,0,256);
+					sprintf(tmpbuf,"/sbin/ifconfig eth0 %s netmask %s up &",
+						ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthIpAddress,
+						ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthSubmaskAddress);
+					system(tmpbuf);
+					memset(tmpbuf,0,256);
+					sprintf(tmpbuf,"route add default gw %s eth0 &",
+					ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthGatewayAddress);
+					system(tmpbuf);
+				}
+			}
+
+			if(isReachableInternet() == PASS)
+			{
+				ShmSysConfigAndInfo->SysInfo.ethInternetConn = YES;
+				cnt_pingDNS_Fail = 0;
+			}
+			else
+			{
+				if(++cnt_pingDNS_Fail > 3)
+				{
+					ShmSysConfigAndInfo->SysInfo.ethInternetConn = NO;
+					if((ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthDhcpClient==0))
+					{
+						system("pgrep -f \"udhcpc -i eth0\" | xargs kill");
+						sprintf(tmpbuf, "/sbin/udhcpc -i eth0 -x hostname:CSU3_%s -s /root/dhcp_script/eth0.script > /dev/null &", ShmSysConfigAndInfo->SysConfig.SystemId);
+						system(tmpbuf);
+					}
+					else
+					{
+						system("pgrep -f \"udhcpc -i eth0\" | xargs kill");
+						memset(tmpbuf,0,256);
+						sprintf(tmpbuf,"/sbin/ifconfig eth0 %s netmask %s up &",
+								ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthIpAddress,
+								ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthSubmaskAddress);
+						system(tmpbuf);
+						memset(tmpbuf,0,256);
+						sprintf(tmpbuf,"route add default gw %s eth0 &",
+						ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthGatewayAddress);
+						system(tmpbuf);
+					}
+					cnt_pingDNS_Fail = 0;
+				}
+			}
+
+			bool ethResult = ShmSysConfigAndInfo->SysInfo.ethInternetConn;
+
+			if(ethResult == YES)
+			{
+				system("/sbin/ifmetric eth0 0");
+
+				if((ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'W') ||
+						(ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D'))
+					system("/sbin/ifmetric mlan0 1");
+
+				if((ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'T') ||
+						(ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D'))
+					system("/sbin/ifmetric ppp0 2");
+			}
+
+			if (!ethResult &&
+					ShmSysConfigAndInfo->SysConfig.AthInterface.WifiMode != _SYS_WIFI_MODE_DISABLE &&
+					(ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'W' || ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D'))
+			{
+				//ethResult = ShmSysConfigAndInfo->SysConfig.AthInterface.WifiNetworkConn;
+				ethResult = ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi == YES ? NO : YES;
+
+				if (ethResult)
+				{
+					if((ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D'))
+					{
+						system("/sbin/ifmetric eth0 1");
+						system("/sbin/ifmetric mlan0 0");
+					}
+
+					if((ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'T') || (ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D'))
+						system("/sbin/ifmetric ppp0 2");
+				}
+			}
+
+			if (!ethResult &&
+					ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomEnabled == YES &&
+					(ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'T' || ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D'))
+			{
+				//ethResult = ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomNetworkConn;
+				ethResult = ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi == YES ? NO : YES;
+
+				if (ethResult)
+				{
+					if((ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D'))
+						system("/sbin/ifmetric mlan0 2");
+
+					if((ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'T') || (ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D'))
+					{
+						system("/sbin/ifmetric eth0 1");
+						system("/sbin/ifmetric ppp0 0");
+					}
+				}
+			}
+
+			ShmSysConfigAndInfo->SysInfo.InternetConn = ethResult;
+			sleep(5);
+		}
+	}
+
+	#ifdef SystemLogMessage
+	DEBUG_INFO_MSG("[main]InitEthernet: Initial Ethernet OK. \n");
+	#endif
+}
+
+int InitialRfidPort()
+{
+	int uartO2 = open(rfidPortName, O_RDWR);
+	struct termios tios;
+
+	if (uartO2 != FAIL)
+	{
+		ioctl (uartO2, TCGETS, &tios);
+		tios.c_cflag = B19200 | CS8 | CLOCAL | CREAD;
+		tios.c_lflag = 0;
+		tios.c_iflag = 0;
+		tios.c_oflag = 0;
+		tios.c_cc[VMIN] = 0;
+		tios.c_cc[VTIME] = (unsigned char) 1;
+		tios.c_lflag = 0;
+		tcflush(uartO2, TCIFLUSH);
+		ioctl(uartO2, TCSETS, &tios);
+	}
+
+	if (uartO2 < 0)
+	{
+		ShmStatusCodeData->AlarmCode.AlarmEvents.bits.RfidModuleCommFail = 1;
+	}
+
+	return uartO2;
+}
+
+void GetMacAddress()
+{
+	for (byte index = 0; index < 2; index++)
+	{
+		int fd;
+		struct ifreq ifr;
+		char tarEth[5];
+		char Mac[18];
+
+		sprintf(tarEth,"eth%d",index);
+		fd = socket(AF_INET, SOCK_DGRAM, 0);
+
+		ifr.ifr_addr.sa_family = AF_INET;
+		strncpy(ifr.ifr_name, tarEth, IFNAMSIZ - 1);
+
+		ioctl(fd, SIOCGIFHWADDR, &ifr);
+		close(fd);
+
+		sprintf(Mac, "%.2x:%.2x:%.2x:%.2x:%.2x:%.2x",
+				ifr.ifr_hwaddr.sa_data[0], ifr.ifr_hwaddr.sa_data[1], ifr.ifr_hwaddr.sa_data[2],
+				ifr.ifr_hwaddr.sa_data[3], ifr.ifr_hwaddr.sa_data[4], ifr.ifr_hwaddr.sa_data[5]);
+
+		if (index == 0)
+			strcpy((char *) ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthMacAddress, Mac);
+		else
+			strcpy((char *) ShmSysConfigAndInfo->SysConfig.Eth1Interface.EthMacAddress, Mac);
+	}
+}
+
+void GetFirmwareVersion()
+{
+	// Get CSU root file system version
+	sprintf((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev, fwVersion);
+
+	byte count = 0, chademo = 0, ccs = 0, gb = 0;
+	for(uint8_t idx=0;idx<3;idx++)
+	{
+		if (ShmSysConfigAndInfo->SysConfig.ModelName[7+idx] == 'J' ||
+				ShmSysConfigAndInfo->SysConfig.ModelName[7+idx] == 'K' ||
+				ShmSysConfigAndInfo->SysConfig.ModelName[7+idx] == 'L')
+		{
+			chademo++;
+			count++;
+		}
+		else  if (ShmSysConfigAndInfo->SysConfig.ModelName[7+idx] == 'G')
+		{
+			gb++;
+			count++;
+		}
+		else  if (ShmSysConfigAndInfo->SysConfig.ModelName[7+idx] == 'U' ||
+				ShmSysConfigAndInfo->SysConfig.ModelName[7+idx] == 'E' ||
+				ShmSysConfigAndInfo->SysConfig.ModelName[7+idx] == 'T' ||
+				ShmSysConfigAndInfo->SysConfig.ModelName[7+idx] == 'D' ||
+				ShmSysConfigAndInfo->SysConfig.ModelName[7+idx] == 'M' ||
+				ShmSysConfigAndInfo->SysConfig.ModelName[7+idx] == 'N' ||
+				ShmSysConfigAndInfo->SysConfig.ModelName[7+idx] == 'R' ||
+				ShmSysConfigAndInfo->SysConfig.ModelName [7 + idx] == 'V' ||
+				ShmSysConfigAndInfo->SysConfig.ModelName [7 + idx] == 'F' ||
+				ShmSysConfigAndInfo->SysConfig.ModelName [7 + idx] == 'Y' ||
+				ShmSysConfigAndInfo->SysConfig.ModelName [7 + idx] == 'Z' )
+		{
+			ccs++;
+			count++;
+		}
+	}
+
+	if (count == 1)
+	{
+		if (chademo > 0)
+			ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[7] = '1';
+		else if (ccs > 0)
+			ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[7] = '2';
+		else if (gb > 0)
+			ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[7] = '3';
+	}
+	else
+	{
+		if (chademo == 1 && ccs == 1)
+			ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[7] = '4';
+		else if (chademo == 1 && gb == 1)
+			ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[7] = '5';
+		else if (ccs == 1 && gb == 1)
+			ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[7] = '6';
+		else if (chademo == 2)
+			ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[7] = '7';
+		else if (ccs == 2)
+			ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[7] = '8';
+		else if (gb == 2)
+			ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[7] = '9';
+	}
+
+	// Get network option from model name
+	switch(ShmSysConfigAndInfo->SysConfig.ModelName[10])
+	{
+		case 'B':
+		case 'U':
+			//Blue tooth
+			ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[9] = '3';
+			break;
+		case 'W':
+			// WIFI
+			ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[9] = '1';
+			break;
+		case 'T':
+			// 3G/4G
+			ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[9] = '2';
+			break;
+		case 'D':
+			ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[9] = '5';
+			break;
+		default:
+			// LAN
+			ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[9] = '0';
+			break;
+	}
+	// Get rating power from model name
+	memcpy(&ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[10], &ShmSysConfigAndInfo->SysConfig.ModelName[4], 0x03);
+
+	// Get IEC or UL
+	char _buf[3] = {0};
+	memcpy(_buf, &ShmSysConfigAndInfo->SysConfig.ModelName[2], 1);
+
+	if (strcmp(_buf, "Y") == EQUAL || strcmp(_buf, "Y") == EQUAL)
+		ShmSysConfigAndInfo->SysInfo.ChargerType = _CHARGER_TYPE_IEC;
+	else if (strcmp(_buf, "W") == EQUAL)
+		ShmSysConfigAndInfo->SysInfo.ChargerType = _CHARGER_TYPE_UL;
+
+	memcpy(_buf, &ShmSysConfigAndInfo->SysConfig.ModelName[12], 2);
+	memcpy(&ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev[14], &ShmSysConfigAndInfo->SysConfig.ModelName[12], 2);
+
+	if (strcmp(_buf, "PN") == EQUAL ||
+			strcmp(_buf, "N7") == EQUAL ||
+			strcmp(_buf, "NX") == EQUAL ||
+			strcmp(_buf, "OL") == EQUAL ||
+			strcmp(_buf, "DE") == EQUAL)
+		ShmDcCommonData->ShowLogoFlag = NO;
+	else
+		ShmDcCommonData->ShowLogoFlag = YES;
+
+	if (ShmSysConfigAndInfo->SysConfig.ModelName[3] == 'G')
+		ShmDcCommonData->chargerType = CHARGER_TYPE_SIMPLE;
+	else
+		ShmDcCommonData->chargerType = CHARGER_TYPE_STANDARD;
+}
+
+void InitialGunIndexToUnUse()
+{
+	for (byte index = 0; index < CHAdeMO_QUANTITY; index++)
+	{
+		ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index = NO_DEFINE;
+	}
+
+	for (byte index = 0; index < CCS_QUANTITY; index++)
+	{
+		ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index = NO_DEFINE;
+	}
+
+	for (byte index = 0; index < GB_QUANTITY; index++)
+	{
+		ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index = NO_DEFINE;
+	}
+
+	for (byte index = 0; index < AC_QUANTITY; index++)
+	{
+		ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index = NO_DEFINE;
+	}
+}
+
+void InitialShareMemoryInfo()
+{
+	FILE *fp;
+	char cmd[512];
+	char buf[512];
+
+//	sprintf((char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomApn, "Internet");
+//	sprintf((char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapId, " ");
+//	sprintf((char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapPwd, " ");
+
+	ShmSysConfigAndInfo->SysConfig.TotalConnectorCount = 0;
+	ShmSysConfigAndInfo->SysConfig.AcConnectorCount = 0;
+
+	ShmSysConfigAndInfo->SysInfo.FactoryConfiguration = 0;
+	ShmSysConfigAndInfo->SysInfo.InputVoltageR = 0;
+	ShmSysConfigAndInfo->SysInfo.InputVoltageS = 0;
+	ShmSysConfigAndInfo->SysInfo.InputVoltageT = 0;
+	ShmSysConfigAndInfo->SysInfo.SystemFanRotaSpeed = 0;
+	ShmSysConfigAndInfo->SysInfo.PsuFanRotaSpeed = 0;
+	ShmSysConfigAndInfo->SysInfo.AuxPower5V = 0;
+	ShmSysConfigAndInfo->SysInfo.AuxPower12V = 0;
+	ShmSysConfigAndInfo->SysInfo.AuxPower24V = 0;
+	ShmSysConfigAndInfo->SysInfo.AuxPower48V = 0;
+
+	sprintf((char *)ShmSysConfigAndInfo->SysInfo.CsuHwRev, "REV:5.0");
+	memcpy(ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev, ShmSysConfigAndInfo->SysConfig.CsuBootLoadFwRev, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.CsuBootLoadFwRev));
+
+	sprintf(cmd, "/bin/uname -r");
+	fp = popen(cmd, "r");
+	if(fp == NULL)
+		sprintf((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev, "Unknown version");
+	else
+	{
+		while(fgets(buf, sizeof(buf), fp) != NULL)
+		{
+			strcpy((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev, buf);
+		}
+	}
+
+	GetFirmwareVersion();
+	//sprintf((char *) ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev, fwVersion);
+	sprintf((char *) ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev, " ");
+
+	sprintf((char *) ShmSysConfigAndInfo->SysInfo.LcmHwRev, " ");
+	sprintf((char *) ShmSysConfigAndInfo->SysInfo.LcmFwRev, " ");
+	sprintf((char *) ShmSysConfigAndInfo->SysInfo.PsuHwRev, " ");
+	sprintf((char *) ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev, " ");
+	sprintf((char *) ShmSysConfigAndInfo->SysInfo.PsuSecFwRev, " ");
+	sprintf((char *) ShmSysConfigAndInfo->SysInfo.AuxPwrHwRev, " ");
+	sprintf((char *) ShmSysConfigAndInfo->SysInfo.AuxPwrFwRev, " ");
+	sprintf((char *) ShmSysConfigAndInfo->SysInfo.FanModuleHwRev, " ");
+	sprintf((char *) ShmSysConfigAndInfo->SysInfo.FanModuleFwRev, " ");
+	sprintf((char *) ShmSysConfigAndInfo->SysInfo.RelayModuleHwRev, " ");
+	sprintf((char *) ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev, " ");
+	sprintf((char *) ShmSysConfigAndInfo->SysInfo.TelcomModemFwRev, " ");
+	ShmSysConfigAndInfo->SysInfo.SystemAmbientTemp = 0;
+	ShmSysConfigAndInfo->SysInfo.SystemCriticalTemp = 0;
+	ShmSysConfigAndInfo->SysInfo.PsuAmbientTemp = 0;
+	ShmSysConfigAndInfo->SysInfo.CcsConnectorTemp = 0;
+	ShmSysConfigAndInfo->SysInfo.InternetConn = NO;
+	ShmSysConfigAndInfo->SysInfo.OcppConnStatus = NO;
+	ShmSysConfigAndInfo->SysInfo.OrderCharging = NO_DEFINE;
+
+	strcpy((char *) ShmSysConfigAndInfo->SysConfig.UserId, "");
+
+	ShmStatusCodeData->AlarmCode.AlarmEvents.bits.RelayboardStestFail = NO;
+	ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FanboardStestFail = NO;
+	ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PrimaryStestFail = NO;
+	ShmStatusCodeData->AlarmCode.AlarmEvents.bits.LedboardStestFail = NO;
+	ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoboardStestFail = NO;
+	ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CCSboardStestFail = NO;
+	ShmStatusCodeData->AlarmCode.AlarmEvents.bits.AcContactStestFail = NO;
+	ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuModuleStestFail = NO;
+	ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuDipSwitchStestFail = NO;
+
+	memset(ShmSysConfigAndInfo->SysInfo.FanModuleFwRev, 0, ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
+	memset(ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev, 0, ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
+	ShmPrimaryMcuData->SelfTest_Comp = NO;
+	ShmRelayModuleData->SelfTest_Comp = NO;
+	ShmFanModuleData->SelfTest_Comp = NO;
+	ShmLedModuleData->SelfTest_Comp = NO;
+	ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
+	ShmSysConfigAndInfo->SysInfo.MainChargingMode = _MAIN_CHARGING_MODE_MAX;
+	ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_NONE;
+	ShmSysConfigAndInfo->SysInfo.CurGunSelected = 0;
+	ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc = NO_DEFINE;
+	ShmSysConfigAndInfo->SysInfo.BootingStatus = BOOTTING;
+	ShmSysConfigAndInfo->SysInfo.MaxChargingProfilePower = -1;
+
+	ShmFanModuleData->TestFanSpeed = 0;
+
+	ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ModelNameNoneMatchStestFail = NO;
+	ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuNoResource = NO;
+	InitialGunIndexToUnUse();
+
+	ShmSysConfigAndInfo->SysConfig.AlwaysGfdFlag = NO;
+
+	ShmDcCommonData->CcsVersion = _CCS_VERSION_CHECK_TAG_V015S0;
+	ShmDcCommonData->psuKeepCommunication = NO;
+	ShmDcCommonData->acContactSwitch = NO;
+	ShmDcCommonData->ConnectErrList[0].GunErrMessage = 0;
+	ShmDcCommonData->ConnectErrList[1].GunErrMessage = 0;
+	ShmDcCommonData->LcmFwVersion = 0;
+	ShmDcCommonData->minOutputCur = 0;
+	ShmDcCommonData->evBoardResetFlag = NO;
+	ShmDcCommonData->enObtainAuthorizbyCCID = NO;
+	ShmDcCommonData->_CcidAuthProcessStep = _CCID_NONE;
+	ShmDcCommonData->_isPsuErrorOccur = NO;
+	ShmSysConfigAndInfo->SysConfig.SwitchDebugFlag = NO;
+}
+
+int Initialization()
+{
+	// 初始化卡號驗證的 Flag
+	ClearAuthorizedFlag();
+	// 初始化插槍驗證的 Flag
+	ClearDetectPluginFlag();
+
+	// UART 2 for Rfid
+	rfidFd = InitialRfidPort();
+
+	int pinOut[2] = { 116, 115 }; //D13(Cha)、C13(CCS)
+	for (byte count = 0; count < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; count++)
+	{
+		chargingInfo[count]->RemoteStartFlag = NO;
+		chargingInfo[count]->ReservedStartFlag = NO;
+
+		if (chargingInfo[count]->Type == _Type_Chademo)
+		{
+			gpio_set_value(pinOut[count], 0x00);
+			ShmCHAdeMOData->evse[chargingInfo[count]->type_index].SelfTest_Comp = NO;
+		}
+		else if (chargingInfo[count]->Type == _Type_GB)
+		{
+			gpio_set_value(pinOut[count], 0x00);
+			ShmGBTData->evse[chargingInfo[count]->type_index].SelfTest_Comp = NO;
+		}
+		else if (chargingInfo[count]->Type == _Type_CCS)
+		{
+			if (ShmSysConfigAndInfo->SysConfig.TotalConnectorCount == 1)
+				gpio_set_value(pinOut[1], 0x00);
+			else
+				gpio_set_value(pinOut[count], 0x00);
+			ShmCcsData->V2GMessage_DIN70121[chargingInfo[count]->type_index].SelfTest_Comp = NO;
+		}
+
+		strcpy((char *)ShmDcCommonData->_reserved_UserId[count], "");
+	}
+
+	byte acDirIndex = 0;
+	for (byte count = 0; count < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; count++)
+	{
+		if (count == 1)
+			acDirIndex = ShmSysConfigAndInfo->SysConfig.AcConnectorCount;
+
+		ocpp_set_noErrorCode_cmd(count + acDirIndex, "NoError");
+	}
+
+	byte hasDc = ((ShmSysConfigAndInfo->SysConfig.TotalConnectorCount > 0) ? 1 : 0);
+	for (byte count = 0; count < ShmSysConfigAndInfo->SysConfig.AcConnectorCount; count++)
+	{
+		ac_chargingInfo[count]->RemoteStartFlag = NO;
+
+		if (ac_chargingInfo[count]->Type == _Type_AC)
+		{
+			ac_chargingInfo[count]->SelfTest_Comp = NO;
+			ocpp_set_noErrorCode_cmd(count + hasDc, "NoError");
+		}
+	}
+
+	PRINTF_FUNC("Information check done \n");
+	return PASS;
+}
+
+bool InitialSystemDefaultConfig()
+{
+	bool result = true;
+
+	LoadSysConfigAndInfo(&ShmSysConfigAndInfo->SysConfig);
+	PRINTF_FUNC("ModelName = %s", ShmSysConfigAndInfo->SysConfig.ModelName);
+	InitGPIO();
+	InitEthernet();
+	GetMacAddress();
+
+//	system("echo 1 > /sys/class/gpio/gpio110/value"); //reset PHY
+//	sleep(3);
+//	system("/sbin/ifconfig eth0 192.168.1.10 netmask 255.255.255.0 down");
+//	sleep(1);
+//	system("/sbin/ifconfig eth1 192.168.0.10 netmask 255.255.255.0 up");
+
+	return result;
+}
+
+bool DisplaySelfTestFailReason()
+{
+	bool result = false;
+	// RB、FB、407、EV 小板中有些板子無回應
+	if (ShmRelayModuleData->SelfTest_Comp == NO)
+	{ ShmStatusCodeData->AlarmCode.AlarmEvents.bits.RelayboardStestFail = YES; result = true; }
+	if (ShmFanModuleData->SelfTest_Comp == NO)
+	{ ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FanboardStestFail = YES; result = true; }
+	if (ShmPrimaryMcuData->SelfTest_Comp == NO)
+	{ ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PrimaryStestFail = YES; result = true; }
+//	if (ShmLedModuleData->SelfTest_Comp == NO)
+//	{ ShmStatusCodeData->AlarmCode.AlarmEvents.bits.LedboardStestFail = YES; }
+	if (ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSeccTimeoutQCA7000Comm == YES)
+	{ result = true; }
+	for (byte index = 0; index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; index++)
+	{
+		if (chargingInfo[index]->Type == _Type_Chademo)
+		{
+			if (ShmCHAdeMOData->evse[chargingInfo[index]->type_index].SelfTest_Comp == NO)
+			{ ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoboardStestFail = YES; result = true; }
+		}
+		else if (chargingInfo[index]->Type == _Type_GB)
+		{
+			if (ShmGBTData->evse[chargingInfo[index]->type_index].SelfTest_Comp == NO)
+			{ ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbtboardStestFail = YES; result = true; }
+		}
+		else if (chargingInfo[index]->Type == _Type_CCS)
+		{
+			if (ShmCcsData->CommProtocol == _CCS_COMM_V2GMessage_DIN70121)
+			{
+				if (ShmCcsData->V2GMessage_DIN70121[chargingInfo[index]->type_index].SelfTest_Comp == NO)
+				{ ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CCSboardStestFail = YES; result = true; }
+			}
+		}
+	}
+	for (byte index = 0; index < ShmSysConfigAndInfo->SysConfig.AcConnectorCount; index++)
+	{
+		// 先借 GBT 顯示
+		if (ac_chargingInfo[index]->SelfTest_Comp == NO)
+		{ ShmStatusCodeData->AlarmCode.AlarmEvents.bits.AcConnectorStestFail = YES; result = true; }
+	}
+
+	if (ShmSysConfigAndInfo->SysInfo.AcContactorStatus == NO)
+	{
+		// AC Contact 未搭上
+		ShmStatusCodeData->AlarmCode.AlarmEvents.bits.AcContactStestFail = YES;
+		result = true;
+	}
+	else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuDipSwitchStestFail == YES)
+	{
+		result = true;
+	}
+	else if (ShmPsuData->SystemAvailablePower <= 0 && ShmPsuData->SystemAvailableCurrent <= 0)
+	{
+		// PSU 通訊問題
+		ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuModuleStestFail = YES;
+		result = true;
+	}
+
+	return result;
+}
+
+void SelfTestRun()
+{
+	bool evInitFlag = false;
+
+	StartSystemTimeoutDet(Timeout_SelftestChk);
+	ShmSysConfigAndInfo->SysInfo.SelfTestSeq = _STEST_VERSION;
+	while (ShmSysConfigAndInfo->SysInfo.SelfTestSeq != _STEST_COMPLETE ||
+			GetTimeoutValue(&ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer) <= 20)
+	{
+		ReviewCriticalAlarm();
+		ChkPrimaryStatus();
+		if (ShmSysConfigAndInfo->SysWarningInfo.Level == _ALARM_LEVEL_CRITICAL ||
+				ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuDipSwitchStestFail == YES)
+		{
+			ShmSysConfigAndInfo->SysInfo.SelfTestSeq = _STEST_FAIL;
+			return;
+		}
+
+		if (ShmSysConfigAndInfo->SysConfig.TotalConnectorCount > 0)
+		{
+			if (ShmPsuData->Work_Step == _NO_WORKING ||
+					ShmSysConfigAndInfo->SysInfo.SelfTestSeq == _STEST_FAIL)
+			{
+				ShmSysConfigAndInfo->SysInfo.SelfTestSeq = _STEST_FAIL;
+				return;
+			}
+
+			switch(ShmSysConfigAndInfo->SysInfo.SelfTestSeq)
+			{
+				case _STEST_VERSION:
+				{
+					if (strlen((char *)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev) != 0 ||
+							ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev[0] != '\0')
+					{
+						//PRINTF_FUNC("RB pass \n");
+						ShmRelayModuleData->SelfTest_Comp = YES;
+					}
+
+					if  (strlen((char *)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev) != 0 ||
+							ShmSysConfigAndInfo->SysInfo.FanModuleFwRev[0] != '\0')
+					{
+						//PRINTF_FUNC("Fan pass \n");
+						ShmFanModuleData->SelfTest_Comp = YES;
+					}
+
+					if (strlen((char *)ShmPrimaryMcuData->version) != 0 ||
+							ShmPrimaryMcuData->version[0] != '\0')
+					{
+						//PRINTF_FUNC("407 pass \n");
+						ShmPrimaryMcuData->SelfTest_Comp = YES;
+					}
+					// EV 小板
+					if (!evInitFlag)
+					{
+						evInitFlag = YES;
+						for (byte index = 0; index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; index++)
+						{
+							if (chargingInfo[index]->Type == _Type_Chademo)
+							{
+								if (strlen((char *)ShmCHAdeMOData->evse[chargingInfo[index]->type_index].version) != 0 ||
+										ShmCHAdeMOData->evse[chargingInfo[index]->type_index].version[0] != '\0')
+								{
+									//PRINTF_FUNC("chademo pass \n");
+									ShmCHAdeMOData->evse[chargingInfo[index]->type_index].SelfTest_Comp = YES;
+								}
+								else
+								{
+									//PRINTF_FUNC("chademo fw lose...... %s \n", ShmCHAdeMOData->evse[chargingInfo[index]->type_index].version);
+									evInitFlag = NO;
+								}
+							}
+							else if (chargingInfo[index]->Type == _Type_GB)
+							{
+								if (strlen((char *)ShmGBTData->evse[chargingInfo[index]->type_index].version) != 0 ||
+										ShmGBTData->evse[chargingInfo[index]->type_index].version[0] != '\0')
+								{
+									//PRINTF_FUNC("GBT pass \n");
+									ShmGBTData->evse[chargingInfo[index]->type_index].SelfTest_Comp = YES;
+								}
+								else
+								{
+									//PRINTF_FUNC("GBT fw lose...... %s \n", ShmCHAdeMOData->evse[chargingInfo[index]->type_index].version);
+									evInitFlag = NO;
+								}
+							}
+							else if (chargingInfo[index]->Type == _Type_CCS)
+							{
+								if (ShmCcsData->CommProtocol == _CCS_COMM_V2GMessage_DIN70121)
+								{
+									if (strlen((char *)ShmCcsData->V2GMessage_DIN70121[chargingInfo[index]->type_index].version) != 0 ||
+										ShmCcsData->V2GMessage_DIN70121[chargingInfo[index]->type_index].version[0] != '\0')
+									{
+										//PRINTF_FUNC("ccs fw =  %s \n", ShmCcsData->V2GMessage_DIN70121[chargingInfo[index]->type_index].version);
+										ShmCcsData->V2GMessage_DIN70121[chargingInfo[index]->type_index].SelfTest_Comp = YES;
+									}
+									else
+									{
+										//PRINTF_FUNC("ccs fw lose...... %s \n", ShmCcsData->V2GMessage_DIN70121[chargingInfo[index]->type_index].version);
+										evInitFlag = NO;
+									}
+								}
+							}
+						}
+
+						for (byte index = 0; index < ShmSysConfigAndInfo->SysConfig.AcConnectorCount; index++)
+						{
+							if (ac_chargingInfo[index]->Type == _Type_AC)
+							{
+								if (strlen((char *)ac_chargingInfo[index]->version) != 0 ||
+										ac_chargingInfo[index]->version[0] != '\0')
+								{
+									ac_chargingInfo[index]->SelfTest_Comp = YES;
+								}
+								else
+								{
+									evInitFlag = NO;
+								}
+							}
+						}
+					}
+
+					if (ShmFanModuleData->SelfTest_Comp &&
+							ShmRelayModuleData->SelfTest_Comp &&
+							ShmPrimaryMcuData->SelfTest_Comp &&
+							evInitFlag)
+					{
+						ShmSysConfigAndInfo->SysInfo.SelfTestSeq = _STEST_AC_CONTACTOR;
+					}
+				}
+					break;
+				case _STEST_AC_CONTACTOR:
+				{
+					//ShmPsuData->Work_Step = _TEST_COMPLETE;
+					// 因為 30KW 以下沒有 Relay feedback 功能,所以暫時先直接跳過
+					if (ShmSysConfigAndInfo->SysInfo.AcContactorStatus == YES)
+					{
+						ShmSysConfigAndInfo->SysInfo.SelfTestSeq = _STEST_PSU_DETECT;
+						PRINTF_FUNC("Communication board pass. \n");
+					}
+				}
+					break;
+				case _STEST_PSU_DETECT:
+				{
+					if (ShmPsuData->Work_Step >= GET_SYS_CAP)
+					{
+						ShmSysConfigAndInfo->SysInfo.SelfTestSeq = _STEST_PSU_CAP;
+					}
+				}
+					break;
+				case _STEST_PSU_CAP:
+				{
+					// 此測試是要確認當前總輸出能力
+					// 如果沒有 PSU 模組請 bypass
+					if (ShmPsuData->Work_Step == BOOTING_COMPLETE)
+					{
+						sleep(1);
+						ShmSysConfigAndInfo->SysInfo.SelfTestSeq = _STEST_COMPLETE;
+						ShmSysConfigAndInfo->SysInfo.BootingStatus = BOOT_COMPLETE;
+					}
+				}
+					break;
+			}
+		}
+		else
+			break;
+
+		usleep(100000);
+	}
+}
+
+int SpawnTask()
+{
+	sleep(2);
+	system("/root/Module_EventLogging &");
+	system("/root/Module_PrimaryComm &");
+	system("/root/Module_EvComm &");
+	system("/root/Module_LcmControl &");
+	system("/root/Module_InternalComm &");
+	system("/root/Module_PsuComm &");
+	system("/root/Module_ProduceUtils &");
+	ocpp_process_start();
+
+	if(ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'T')
+	{
+		system("/root/Module_4g &");
+	}
+
+	if(ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'W')
+	{
+		system("/root/Module_Wifi &");
+	}
+
+	if(ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D')
+	{
+		system("/root/Module_4g &");
+		system("/root/Module_Wifi &");
+	}
+
+	return PASS;
+}
+
+int StoreUsrConfigData(struct SysConfigData *UsrData)
+{
+	int result = PASS;
+	int fd,wrd;
+	unsigned int i,Chk;
+	unsigned char *ptr, *BufTmp;
+
+	Chk=0;
+	ptr=(unsigned char *)UsrData;
+	if((BufTmp = malloc(MtdBlockSize)) != NULL)
+	{
+		memset(BufTmp, 0, MtdBlockSize);
+		memcpy(BufTmp, ptr, sizeof(struct SysConfigData));
+		for(i=0; i<MtdBlockSize-4; i++)
+			Chk+=*(ptr+i);
+
+		memcpy(BufTmp + MtdBlockSize-4, &Chk, 4);
+		fd = open("/dev/mtdblock10", O_RDWR);
+		if (fd > 0)
+		{
+			wrd=write(fd, BufTmp, MtdBlockSize);
+			close(fd);
+			if(wrd >= MtdBlockSize)
+			{
+				fd = open("/dev/mtdblock11", O_RDWR);
+				if (fd > 0)
+				{
+					wrd=write(fd, BufTmp, MtdBlockSize);
+	    			close(fd);
+					if(wrd < MtdBlockSize)
+					{
+						DEBUG_ERROR_MSG("write /dev/mtdblock11(backup) NG\r\n");
+					   	result = FAIL;
+					}
+				}
+				else
+				{
+					DEBUG_ERROR_MSG("open /dev/mtdblock11(backup) NG\r\n");
+					result = FAIL;
+				}
+			}
+			else
+			{
+				DEBUG_ERROR_MSG("write /dev/mtdblock10 NG\r\n");
+			    result = FAIL;
+			}
+
+		}
+		else
+		{
+			DEBUG_ERROR_MSG("open /dev/mtdblock10 NG\r\n");
+			result = FAIL;
+		}
+	}
+	else
+	{
+		DEBUG_ERROR_MSG("alloc BlockSize NG\r\n");
+	    result = FAIL;
+	}
+
+	if(BufTmp != NULL)
+		free(BufTmp);
+
+	return result;
+}
+
+//===============================================
+// Common Detect Chk - Stop Charging ?
+//===============================================
+bool isEvBoardStopChargeFlag(byte gunIndex)
+{
+	return chargingInfo[gunIndex]->StopChargeFlag;
+}
+
+bool isEvBoardNormalStopChargeFlag(byte gunIndex)
+{
+	return chargingInfo[gunIndex]->NormalStopChargeFlag;
+}
+//===============================================
+// 插槍鎖槍狀況
+//===============================================
+void ClearDetectPluginFlag()
+{
+	ShmSysConfigAndInfo->SysInfo.WaitForPlugit = NO;
+	for (byte gun_index = 0; gun_index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gun_index++)
+	{
+		if (chargingInfo[gun_index]->RemoteStartFlag == YES)
+			chargingInfo[gun_index]->RemoteStartFlag = NO;
+
+		if (chargingInfo[gun_index]->ReservedStartFlag == YES)
+			chargingInfo[gun_index]->ReservedStartFlag = NO;
+	}
+
+	if (ShmSysConfigAndInfo->SysInfo.OrderCharging != NO_DEFINE)
+		ShmSysConfigAndInfo->SysInfo.OrderCharging = NO_DEFINE;
+}
+
+void DetectPluginStart()
+{
+	ShmSysConfigAndInfo->SysInfo.WaitForPlugit = YES;
+}
+
+bool isDetectPlugin()
+{
+	if(ShmSysConfigAndInfo->SysInfo.WaitForPlugit == YES)
+		return YES;
+
+	return NO;
+}
+
+bool isEvGunLocked(byte gunIndex)
+{
+	return chargingInfo[gunIndex]->GunLocked;
+}
+
+//===============================================
+// Common Detect Chk - Chademo
+//===============================================
+bool isEvContactorWelding_chademo(byte gunIndex)
+{
+	return DetectBitValue(ShmCHAdeMOData->ev[chargingInfo[gunIndex]->type_index].EvDetection, 3);
+}
+
+bool isEvStopReq_chademo(byte gunIndex)
+{
+	return DetectBitValue(ShmCHAdeMOData->ev[chargingInfo[gunIndex]->type_index].EvDetection, 4);
+}
+
+byte isPrechargeStatus_chademo(byte gunIndex)
+{
+	byte result = 0x00;
+
+	result = ShmCHAdeMOData->ev[chargingInfo[gunIndex]->type_index].PresentMsgFlowStatus;
+
+	return result;
+}
+//===============================================
+// Common Detect Chk - GB
+//===============================================
+byte isPrechargeStatus_gb(byte gunIndex)
+{
+	byte result = 0x00;
+
+	result = ShmGBTData->ev[chargingInfo[gunIndex]->type_index].PresentMsgFlowStatus;
+
+	return result;
+}
+
+//===============================================
+// Common Detect Chk - CCS
+//===============================================
+byte isPrechargeStatus_ccs(byte gunIndex)
+{
+	byte result = 0x00;
+
+	if (ShmCcsData->CommProtocol == _CCS_COMM_V2GMessage_DIN70121)
+	{
+		result = ShmCcsData->V2GMessage_DIN70121[chargingInfo[gunIndex]->type_index].PresentMsgFlowStatus;
+	}
+
+	return result;
+}
+
+//===============================================
+// Callback
+//===============================================
+void DisplayChargingInfo()
+{
+	PRINTF_FUNC("*********** DisplayChargingInfo *********** \n");
+	for (byte i = 0; i < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; i++)
+	{
+		if (chargingInfo[i]->SystemStatus != SYS_MODE_IDLE &&
+				chargingInfo[i]->SystemStatus != SYS_MODE_RESERVATION)
+		{
+			ChangeGunSelectByIndex(i);
+			usleep(50000);
+			ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
+			return;
+		}
+	}
+
+	if (ShmSysConfigAndInfo->SysConfig.AcConnectorCount > 0 &&
+		ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc == NO_DEFINE &&
+		ac_chargingInfo[0]->SystemStatus >= SYS_MODE_PREPARING && ac_chargingInfo[0]->SystemStatus <= SYS_MODE_COMPLETE)
+	{
+		ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc = DEFAULT_AC_INDEX;
+	}
+
+	usleep(50000);
+	ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
+}
+
+void _AutoReturnTimeout()
+{
+	PRINTF_FUNC("*********** _AutoReturnTimeout %d*********** \n", ShmSysConfigAndInfo->SysInfo.PageIndex);
+	if (ShmSysConfigAndInfo->SysInfo.PageIndex == _LCM_WAIT_FOR_PLUG)
+	{
+		ClearDetectPluginFlag();
+	}
+	else if (ShmSysConfigAndInfo->SysInfo.PageIndex == _LCM_AUTHORIZ_COMP)
+	{
+		bool needPluginDet = true;
+
+		if (ShmDcCommonData->enObtainAuthorizbyCCID)
+		{
+			for (byte gun_index = 0; gun_index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gun_index++)
+			{
+				if (ShmDcCommonData->_authWithCcidFlag [gun_index] == _CCID_CHECK)
+				{
+					needPluginDet = false;
+					break;
+				}
+			}
+		}
+
+		if (needPluginDet)
+			DetectPluginStart();
+
+		ShmDcCommonData->_CcidAuthProcessStep = _CCID_AUTHCOMP;
+	}
+	else if (ShmSysConfigAndInfo->SysInfo.PageIndex == _LCM_AUTHORIZ_FAIL)
+	{
+		ShmDcCommonData->_CcidAuthProcessStep = _CCID_AUTHFAIL;
+	}
+
+	usleep(50000);
+	stopChargingChkByCard = false;
+	ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
+}
+
+void _SelfTestTimeout()
+{
+	if (ShmSysConfigAndInfo->SysInfo.BootingStatus != BOOT_COMPLETE)
+	{
+		for (byte gun_index = 0; gun_index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gun_index++)
+		{
+			ChargingAlarmProcess(gun_index);
+		}
+	}
+	ShmPsuData->Work_Step = _NO_WORKING;
+	ShmSysConfigAndInfo->SysInfo.SelfTestSeq = _STEST_FAIL;
+	PRINTF_FUNC("Self test timeout. \n");
+}
+
+void _AuthorizedTimeout()
+{
+	//if(IsAuthorizingMode())
+	{
+		PRINTF_FUNC("*********** _AuthorizedTimeout *********** \n");
+		isCardScan = false;
+		ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_AUTHORIZ_FAIL;
+		ShmDcCommonData->_CcidAuthProcessStep = _CCID_AUTHFAIL;
+		//ChangeLcmByIndex(_LCM_AUTHORIZ_FAIL);
+		strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
+		ClearAuthorizedFlag();
+	}
+}
+
+void _DetectPlugInTimeout()
+{
+	PRINTF_FUNC("*********** _DetectPlugInTimeout (%d)*********** \n", _connectionTimeout);
+	strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
+	ClearDetectPluginFlag();
+	usleep(50000);
+	ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
+}
+
+void _DetectEvChargingEnableTimeout(byte gunIndex)
+{
+	if (chargingInfo[gunIndex]->Type == _Type_Chademo)
+	{
+		if(!isEvGunLocked(gunIndex))
+		{
+			PRINTF_FUNC("*********** _DetectEvChargingEnableTimeout (chademo) ***********\n");
+		}
+	}
+	else if (chargingInfo[gunIndex]->Type == _Type_GB)
+	{
+		if(!isEvGunLocked(gunIndex))
+		{
+			PRINTF_FUNC("*********** _DetectEvChargingEnableTimeout (gb) ***********\n");
+		}
+	}
+	else if (chargingInfo[gunIndex]->Type == _Type_CCS)
+	{
+		if(!isEvGunLocked(gunIndex))
+		{
+			PRINTF_FUNC("*********** _DetectEvChargingEnableTimeout (ccs) ***********\n");
+		}
+	}
+	ChargingTerminalProcess(gunIndex);
+	_AutoReturnTimeout();
+}
+
+void _DetectEvseChargingEnableTimeout(byte gunIndex)
+{
+	PRINTF_FUNC("*********** _DetectEvseChargingEnableTimeout (GFD timeout) ***********\n");
+	//if (chargingInfo[gunIndex]->GroundFaultStatus != GFD_PASS)
+	{
+		setChargerMode(gunIndex, SYS_MODE_IDLE);
+		_AutoReturnTimeout();
+	}
+}
+
+void _PrepareTimeout(byte gunIndex)
+{
+	PRINTF_FUNC("*********** _PrepareTimeout ***********\n");
+	setChargerMode(gunIndex, SYS_MODE_IDLE);
+	ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuNoResource = YES;
+	_AutoReturnTimeout();
+}
+
+void _CcsPrechargeTimeout(byte gunIndex)
+{
+	PRINTF_FUNC("*********** _CcsPrechargeTimeout ***********\n");
+	setChargerMode(gunIndex, SYS_MODE_IDLE);
+}
+
+//===============================================
+// 卡號驗證
+//===============================================
+void AuthorizingStart()
+{
+	ocpp_set_authorizeReq_cmd(YES);
+	ShmSysConfigAndInfo->SysInfo.AuthorizeFlag = YES;
+}
+
+void ClearAuthorizedFlag()
+{
+	ocpp_set_authorizeConf_cmd(NO);
+	ShmSysConfigAndInfo->SysInfo.AuthorizeFlag = NO;
+}
+
+bool isAuthorizedComplete()
+{
+	return ocpp_get_authorize_conf();
+}
+
+bool IsAuthorizingMode()
+{
+	if(ShmSysConfigAndInfo->SysInfo.AuthorizeFlag == NO)
+		return false;
+
+	return true;
+}
+
+//===============================================
+// 紀錄 Alarm Code
+//===============================================
+void RecordAlarmCode(byte gunIndex, char *code)
+{
+	if (strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6) == EQUAL)
+		memcpy(chargingInfo[gunIndex]->ConnectorAlarmCode, code, 6);
+
+	if (strcmp(code, "012234") == EQUAL) ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaGfdTrip = YES;
+	else if (strcmp(code, "012235") == EQUAL) ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSGfdTrip = YES;
+	else if (strcmp(code, "012236") == EQUAL) ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTGfdTrip = YES;
+	else if (strcmp(code, "012288") == EQUAL) ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSUvpFail = YES;
+	else if (strcmp(code, "012289") == EQUAL) ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaUvpFail = YES;
+	else if (strcmp(code, "012290") == EQUAL) ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTUvpFail = YES;
+	else if (strcmp(code, "012229") == EQUAL) ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaConnectOTP = YES;
+	else if (strcmp(code, "012230") == EQUAL) ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSConnectOTP = YES;
+	else if (strcmp(code, "012231") == EQUAL) ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTConnectOTP = YES;
+	else if (strcmp(code, "012296") == EQUAL) ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaGfdWarning = YES;
+	else if (strcmp(code, "012297") == EQUAL) ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSGfdWarning = YES;
+	else if (strcmp(code, "012298") == EQUAL) ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTGfdWarning = YES;
+	else if (strcmp(code, "011011") == EQUAL) ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaRelayWeldingFault = YES;
+	else if (strcmp(code, "011013") == EQUAL) ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSRelayWeldingFault = YES;
+	else if (strcmp(code, "011015") == EQUAL) ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTRelayWeldingFault = YES;
+	else if (strcmp(code, "011012") == EQUAL) ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaRelayDrivingFault = YES;
+	else if (strcmp(code, "011014") == EQUAL) ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSRelayDrivingFault = YES;
+	else if (strcmp(code, "011016") == EQUAL) ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTRelayDrivingFault = YES;
+	else if (strcmp(code, "011018") == EQUAL) ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaConnectTempSensorFail = YES;
+	else if (strcmp(code, "011019") == EQUAL) ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSConnectTempSensorFail = YES;
+	else if (strcmp(code, "011020") == EQUAL) ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTConnectTempSensorFail = YES;
+	else if (strcmp(code, "012320") == EQUAL) ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaConnectUCP = YES;
+	else if (strcmp(code, "012321") == EQUAL) ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSConnectUCP = YES;
+	else if (strcmp(code, "012322") == EQUAL) ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTConnectUCP = YES;
+	else if (strcmp(code, "011039") == EQUAL) ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ParallelRelayWeldingFault = YES;
+	else if (strcmp(code, "011040") == EQUAL) ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ParallelRelayDrivingFault = YES;
+}
+
+void ResetChargerAlarmCode(byte gunIndex, char *code)
+{
+	if (strcmp(code, "012229") == EQUAL) ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaConnectOTP = NO;
+	else if (strcmp(code, "012230") == EQUAL) ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSConnectOTP = NO;
+	else if (strcmp(code, "012231") == EQUAL) ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTConnectOTP = NO;
+	else if (strcmp(code, "011011") == EQUAL) ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaRelayWeldingFault = NO;
+	else if (strcmp(code, "011013") == EQUAL) ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSRelayWeldingFault = NO;
+	else if (strcmp(code, "011015") == EQUAL) ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTRelayWeldingFault = NO;
+	else if (strcmp(code, "011012") == EQUAL) ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaRelayDrivingFault = NO;
+	else if (strcmp(code, "011014") == EQUAL) ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSRelayDrivingFault = NO;
+	else if (strcmp(code, "011016") == EQUAL) ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTRelayDrivingFault = NO;
+	else if (strcmp(code, "011018") == EQUAL) ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaConnectTempSensorFail = NO;
+	else if (strcmp(code, "011019") == EQUAL) ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSConnectTempSensorFail = NO;
+	else if (strcmp(code, "011020") == EQUAL) ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTConnectTempSensorFail = NO;
+	else if (strcmp(code, "012320") == EQUAL) ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaConnectUCP = NO;
+	else if (strcmp(code, "012321") == EQUAL) ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSConnectUCP = NO;
+	else if (strcmp(code, "012322") == EQUAL) ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTConnectUCP = NO;
+	else if (strcmp(code, "011039") == EQUAL) ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ParallelRelayWeldingFault = NO;
+	else if (strcmp(code, "011040") == EQUAL) ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ParallelRelayDrivingFault = NO;
+
+	if (strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6) != EQUAL)
+	{
+		if (strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012229", 6) == EQUAL ||
+				strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012230", 6) == EQUAL ||
+				strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012231", 6) == EQUAL ||
+				strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "011011", 6) == EQUAL ||
+				strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "011013", 6) == EQUAL ||
+				strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "011015", 6) == EQUAL ||
+				strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "011012", 6) == EQUAL ||
+				strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "011014", 6) == EQUAL ||
+				strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "011016", 6) == EQUAL ||
+				strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "011018", 6) == EQUAL ||
+				strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "011019", 6) == EQUAL ||
+				strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "011020", 6) == EQUAL ||
+				strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012320", 6) == EQUAL ||
+				strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012321", 6) == EQUAL ||
+				strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012322", 6) == EQUAL ||
+				strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "011039", 6) == EQUAL ||
+				strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "011040", 6) == EQUAL)
+		{
+			memcpy(chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6);
+		}
+	}
+}
+
+void ReleaseSysAlarmCode(byte gunIndex)
+{
+	// 回 idle 後主要清除  GFD Trip、UVP、OVP、GFD Warning,PSU fail
+	if (strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6) != EQUAL)
+	{
+		if (strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012251", 6) == EQUAL ||
+				strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012252", 6) == EQUAL ||
+				strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012324", 6) == EQUAL ||
+				strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012325", 6) == EQUAL ||
+				strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012267", 6) == EQUAL ||
+				strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012346", 6) == EQUAL)
+		{
+			memcpy(chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6);
+		}
+	}
+
+	if (gunIndex == 0)
+		ShmStatusCodeData->AlarmCode.AlarmEvents.bits.AbnormalVoltageOnOutputLine_1 = NO;
+	else if (gunIndex == 1)
+		ShmStatusCodeData->AlarmCode.AlarmEvents.bits.AbnormalVoltageOnOutputLine_2 = NO;
+
+	if (chargingInfo[gunIndex]->Type == _Type_Chademo)
+	{
+		ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaGfdTrip = NO;
+		ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaUvpFail = NO;
+		ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaConnectOVP = NO;
+		ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaGfdWarning = NO;
+		ShmDcCommonData->ConnectErrList[gunIndex].GunBits.ChaConnectUCP = NO;
+
+		if (strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6) != EQUAL)
+		{
+			if (strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012234", 6) == EQUAL ||
+					strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012289", 6) == EQUAL ||
+					strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012217", 6) == EQUAL ||
+					strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012296", 6) == EQUAL)
+			{
+				memcpy(chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6);
+			}
+		}
+	}
+	else if (chargingInfo[gunIndex]->Type == _Type_CCS)
+	{
+		ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSGfdTrip = NO;
+		ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSUvpFail = NO;
+		ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSConnectOVP = NO;
+		ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSGfdWarning = NO;
+		ShmDcCommonData->ConnectErrList[gunIndex].GunBits.CCSConnectUCP = NO;
+
+		if (strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6) != EQUAL)
+		{
+			if (strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012235", 6) == EQUAL ||
+					strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012288", 6) == EQUAL ||
+					strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012219", 6) == EQUAL ||
+					strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012297", 6) == EQUAL)
+			{
+				memcpy(chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6);
+			}
+		}
+	}
+	else if (chargingInfo[gunIndex]->Type == _Type_GB)
+	{
+		ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTGfdTrip = NO;
+		ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTUvpFail = NO;
+		ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTConnectOVP = NO;
+		ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTGfdWarning = NO;
+		ShmDcCommonData->ConnectErrList[gunIndex].GunBits.GBTConnectUCP = NO;
+
+		if (strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6) != EQUAL)
+		{
+			if (strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012236", 6) == EQUAL ||
+					strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012290", 6) == EQUAL ||
+					strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012221", 6) == EQUAL ||
+					strncmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "012298", 6) == EQUAL)
+			{
+				memcpy(chargingInfo[gunIndex]->ConnectorAlarmCode, "", 6);
+			}
+		}
+	}
+
+	ocpp_clear_errorCode_cmd(gunIndex);
+}
+
+void NormalStop(byte gunIndex)
+{
+	PRINTF_FUNC("NormalStop (%d) \n", gunIndex);
+}
+
+//===============================================
+// EmergencyStop and Charging Stop
+//===============================================
+void ChargingTerminalProcess(byte gunIndex)
+{
+	setChargerMode(gunIndex, SYS_MODE_TERMINATING);
+}
+
+void ChargingAlarmProcess(byte gunIndex)
+{
+	CheckSystemErrorFunction(gunIndex);
+	ocpp_set_errCode_cmd(gunIndex);
+	setChargerMode(gunIndex, SYS_MODE_ALARM);
+}
+
+void AcChargingTerminalProcess()
+{
+	ac_chargingInfo[0]->SystemStatus = SYS_MODE_TERMINATING;
+}
+
+//void StopChargingProcessByString(byte level)
+//{
+//	if (level > ShmSysConfigAndInfo->SysWarningInfo.Level)
+//	{
+//		ShmSysConfigAndInfo->SysWarningInfo.Level = level;
+//	}
+//}
+
+//void ReleaseChargingProcessByString(byte level)
+//{
+//	if (level >= ShmSysConfigAndInfo->SysWarningInfo.Level)
+//		ShmSysConfigAndInfo->SysWarningInfo.Level = 0;
+//}
+
+// 一般錯誤停止充電處理函式
+void BoardErrOccurByString(byte index, char *code)
+{
+	//byte level = 1;
+	if ((chargingInfo[index]->SystemStatus > SYS_MODE_IDLE && chargingInfo[index]->SystemStatus < SYS_MODE_TERMINATING) ||
+			(chargingInfo[index]->SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0 && chargingInfo[index]->SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))
+	{
+		PRINTF_FUNC("BoardErrOccurByString (%d) - (%s) \n", index, code);
+		if (strncmp(code, "023730", 6) == EQUAL &&
+				ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoChargerGetEmergencyStop == NO)
+		{
+			ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoChargerGetEmergencyStop = YES;
+		}
+		ChargingAlarmProcess(index);
+	}
+
+	//60StopChargingProcessByString(level);
+}
+
+// 急停狀況的停止充電處理函式
+void EmcOccurThenStopCharging()
+{
+	//byte level = 2;
+	// 嚴重的急停有以下幾種 : EMC 按鈕、Mainbreak、Dooropen...
+	// 其錯誤等級為 2
+	for (byte gun = 0; gun < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gun++)
+	{
+		if ((chargingInfo[gun]->SystemStatus > SYS_MODE_IDLE && chargingInfo[gun]->SystemStatus < SYS_MODE_TERMINATING) ||
+				(chargingInfo[gun]->SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0 && chargingInfo[gun]->SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))
+		{
+			ChargingAlarmProcess(gun);
+		}
+	}
+
+	//StopChargingProcessByString(level);
+}
+
+void ReleaseBoardErrOccurByString(byte index, char *code)
+{
+	if (strncmp(code, "023730", 6) == 0 && ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoChargerGetEmergencyStop == YES)
+	{
+		ShmStatusCodeData->InfoCode.InfoEvents.bits.ChademoChargerGetEmergencyStop = NO;
+	}
+}
+
+void ReleaseEmsOccureByString(byte index, char *code)
+{
+	if (strncmp(code, "012251", 6) == 0 && ShmStatusCodeData->AlarmCode.AlarmEvents.bits.EmergencyStopTrip == YES)
+	{
+		ShmStatusCodeData->AlarmCode.AlarmEvents.bits.EmergencyStopTrip = NO;
+	}
+	else if (strncmp(code, "012252", 6) == 0 && ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DoorOpen == YES)
+	{
+		ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DoorOpen = NO;
+	}
+	else if (strncmp(code, "012237", 6) == 0 && ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SpdTrip == YES)
+	{
+		ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SpdTrip = NO;
+	}
+	else if (strncmp(code, "012238", 6) == 0 && ShmStatusCodeData->AlarmCode.AlarmEvents.bits.MainPowerBreakerTrip == YES)
+	{
+		ShmStatusCodeData->AlarmCode.AlarmEvents.bits.MainPowerBreakerTrip = NO;
+	}
+}
+
+//===============================================
+// 確認硬體 (按鈕) 狀態
+//===============================================
+bool leftBtnPush = false;
+bool rightBtnPush = false;
+
+void ButtonTriggerEvent()
+{
+	if (ShmPrimaryMcuData->InputDet.bits.Button1 == BTN_PRESS &&
+			ShmPrimaryMcuData->InputDet.bits.Button2 == BTN_PRESS)
+		ShmSysConfigAndInfo->SysConfig.ShowInformation = YES;
+	else
+		ShmSysConfigAndInfo->SysConfig.ShowInformation = NO;
+
+	if (ShmPrimaryMcuData->InputDet.bits.Button1 == BTN_PRESS && !leftBtnPush)
+	{
+		if(!leftBtnPush)
+		{
+			leftBtnPush = BTN_PRESS;
+			PRINTF_FUNC("left btn down............................... \n");
+			if (ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc != NO_DEFINE)
+			{
+				switch(ac_chargingInfo[0]->SystemStatus)
+				{
+				case SYS_MODE_IDLE:
+				case SYS_MODE_MAINTAIN:
+				case SYS_MODE_RESERVATION:
+				{
+					if(isDetectPlugin())
+					{
+						_DetectPlugInTimeout();
+						StopSystemTimeoutDet();
+					}
+				}
+					break;
+				case SYS_MODE_MODE_REASSIGN_CHECK:
+				case SYS_MODE_REASSIGN:
+				case SYS_MODE_PREPARING:
+				case SYS_MODE_PREPARE_FOR_EV:
+				case SYS_MODE_PREPARE_FOR_EVSE:
+				case SYS_MODE_CCS_PRECHARGE_STEP0:
+				case SYS_MODE_CCS_PRECHARGE_STEP1:
+				{
+					// 取消充電
+					AcChargingTerminalProcess();
+				}
+					break;
+				case SYS_MODE_CHARGING:
+				{
+					if (ShmSysConfigAndInfo->SysConfig.StopChargingByButton == YES ||
+							(ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_DISABLE &&
+							ac_chargingInfo[0]->isRemoteStart == NO) ||
+							ac_chargingInfo[0]->isRemoteStart)
+					{
+						// 停止充電
+						AcChargingTerminalProcess();
+					}
+				}
+					break;
+				case SYS_MODE_COMPLETE:
+				{}
+					break;
+				}
+			}
+			else
+			{
+				switch(chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
+				{
+					case SYS_MODE_IDLE:
+					case SYS_MODE_MAINTAIN:
+					case SYS_MODE_RESERVATION:
+					{
+						if(isDetectPlugin())
+						{
+							_DetectPlugInTimeout();
+							StopSystemTimeoutDet();
+						}
+					}
+						break;
+					case SYS_MODE_MODE_REASSIGN_CHECK:
+					case SYS_MODE_REASSIGN:
+					case SYS_MODE_PREPARING:
+					case SYS_MODE_PREPARE_FOR_EV:
+					case SYS_MODE_PREPARE_FOR_EVSE:
+					case SYS_MODE_CCS_PRECHARGE_STEP0:
+					case SYS_MODE_CCS_PRECHARGE_STEP1:
+					{
+						// 按鈕 - 取消充電
+	//					if (ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc != NO_DEFINE)
+	//						AcChargingTerminalProcess();
+	//					else
+						ChargingTerminalProcess(ShmSysConfigAndInfo->SysInfo.CurGunSelected);
+					}
+						break;
+					case SYS_MODE_CHARGING:
+					{
+						if (ShmSysConfigAndInfo->SysConfig.StopChargingByButton == YES ||
+								ShmDcCommonData->_authWithCcidFlag [ShmSysConfigAndInfo->SysInfo.CurGunSelected] == _CCID_AUTHCOMP ||
+								(ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_DISABLE &&
+								chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->isRemoteStart == NO) ||
+								chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->isRemoteStart)
+						{
+							// 按鈕 - 停止充電
+							NormalStop(ShmSysConfigAndInfo->SysInfo.CurGunSelected);
+							ChargingTerminalProcess(ShmSysConfigAndInfo->SysInfo.CurGunSelected);
+						}
+					}
+						break;
+					case SYS_MODE_COMPLETE:
+					{
+						// 回 IDLE
+						//PRINTF_FUNC("right btn down.................SYS_MODE_COMPLETE \n");
+						//chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = SYS_MODE_IDLE;
+					}
+						break;
+				}
+			}
+		}
+	}
+	else if (ShmPrimaryMcuData->InputDet.bits.Button1 == BTN_RELEASE)
+	{
+		if(leftBtnPush)
+		{
+			leftBtnPush = BTN_RELEASE;
+			PRINTF_FUNC("left btn up............................... \n");
+		}
+	}
+
+	if (ShmPrimaryMcuData->InputDet.bits.Button2 == BTN_PRESS && !rightBtnPush)
+	{
+		if(!rightBtnPush)
+		{
+			rightBtnPush = BTN_PRESS;
+			PRINTF_FUNC("right btn down .................... %d \n", ShmSysConfigAndInfo->SysInfo.CurGunSelected);
+			if (ShmSysConfigAndInfo->SysInfo.PageIndex == _LCM_WAIT_FOR_PLUG &&
+					ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_ENABLE)
+				return;
+
+			if (ShmSysConfigAndInfo->SysConfig.AcConnectorCount > 0 &&
+					ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc == NO_DEFINE &&
+					ShmSysConfigAndInfo->SysInfo.CurGunSelected + 1 == ShmSysConfigAndInfo->SysConfig.TotalConnectorCount)
+			{
+				ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc = DEFAULT_AC_INDEX;
+			}
+			else if (ShmSysConfigAndInfo->SysInfo.CurGunSelected + 1 < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount &&
+					ShmSysConfigAndInfo->SysInfo.IsAlternatvieConf == NO)
+			{
+				ShmSysConfigAndInfo->SysInfo.CurGunSelected++;
+				ChangeGunSelectByIndex(ShmSysConfigAndInfo->SysInfo.CurGunSelected);
+			}
+			else if (ShmSysConfigAndInfo->SysInfo.IsAlternatvieConf == YES)
+			{
+				for (byte _index = 0; _index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _index++)
+				{
+					if (chargingInfo[_index]->SystemStatus != SYS_MODE_BOOTING &&
+							chargingInfo[_index]->SystemStatus != SYS_MODE_IDLE &&
+							chargingInfo[_index]->SystemStatus != SYS_MODE_RESERVATION)
+					{
+						ShmSysConfigAndInfo->SysInfo.CurGunSelected = _index;
+						ChangeGunSelectByIndex(ShmSysConfigAndInfo->SysInfo.CurGunSelected);
+						return;
+					}
+				}
+
+				ShmSysConfigAndInfo->SysInfo.CurGunSelected = 0;
+				ChangeGunSelectByIndex(ShmSysConfigAndInfo->SysInfo.CurGunSelected);
+			}
+			else
+			{
+				ShmSysConfigAndInfo->SysInfo.CurGunSelected = 0;
+				ChangeGunSelectByIndex(ShmSysConfigAndInfo->SysInfo.CurGunSelected);
+			}
+		}
+	}
+	else if (ShmPrimaryMcuData->InputDet.bits.Button2 == BTN_RELEASE)
+	{
+		if(rightBtnPush)
+		{
+			rightBtnPush = BTN_RELEASE;
+			PRINTF_FUNC("right btn up............................... \n");
+		}
+	}
+
+}
+
+void ChkPrimaryStatus()
+{
+	if (ShmPrimaryMcuData->InputDet.bits.EmergencyButton == ABNORMAL)
+	{
+		ShmStatusCodeData->AlarmCode.AlarmEvents.bits.EmergencyStopTrip = YES;
+		EmcOccurThenStopCharging();
+	}
+	else
+		ReleaseEmsOccureByString(0, "012251");
+
+	if (ShmPrimaryMcuData->InputDet.bits.AcMainBreakerDetec == ABNORMAL)
+	{
+		ShmStatusCodeData->AlarmCode.AlarmEvents.bits.MainPowerBreakerTrip = YES;
+		EmcOccurThenStopCharging();
+	}
+	else
+		ReleaseEmsOccureByString(0, "012238");
+
+	if (ShmPrimaryMcuData->InputDet.bits.SpdDetec == ABNORMAL)
+		ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SpdTrip = YES;
+	else
+		ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SpdTrip = NO;
+
+	if (ShmPrimaryMcuData->InputDet.bits.DoorOpen == ABNORMAL)
+	{
+		ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DoorOpen = YES;
+		EmcOccurThenStopCharging();
+	}
+	else
+		ReleaseEmsOccureByString(0, "012252");
+
+	if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuFailureAlarm)
+	{
+		EmcOccurThenStopCharging();
+	}
+	else
+		ReleaseEmsOccureByString(0, "012267");
+
+	if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuComminicationErrWithCSU)
+	{
+		EmcOccurThenStopCharging ();
+	}
+	else
+		ReleaseEmsOccureByString (0,"012346");
+}
+
+//===============================================
+// 確認各小板偵測的錯誤狀況
+//===============================================
+void CheckSystemErrorFunction(byte index)
+{
+	// System
+	if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.EmergencyStopTrip)
+		RecordAlarmCode(index, "012251");
+
+	if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.MainPowerBreakerTrip)
+		RecordAlarmCode(index, "012238");
+
+	if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DoorOpen)
+		RecordAlarmCode(index, "012252");
+
+	if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuFailureAlarm)
+		RecordAlarmCode(index, "012267");
+
+	if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuComminicationErrWithCSU)
+		RecordAlarmCode(index, "012346");
+
+	if (ShmSysConfigAndInfo->SysConfig.PhaseLossPolicy == YES)
+	{
+		if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputUVP == YES ||
+				ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputUVP == YES ||
+				ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputUVP == YES)
+		{
+			if (ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess == _EXTRA_ERR_PROCESS_NONE)
+			{
+				ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess = _EXTRA_ERR_PROCESS_INUVP;
+			}
+
+			if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputUVP == YES)
+				RecordAlarmCode(index, "012203");
+			else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputUVP == YES)
+				RecordAlarmCode(index, "012204");
+			else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputUVP == YES)
+				RecordAlarmCode(index, "012205");
+
+			chargingInfo[index]->StopChargeFlag = YES;
+		}
+		else
+		{
+			if (ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess == _EXTRA_ERR_PROCESS_INUVP)
+			{
+				ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess = _EXTRA_ERR_PROCESS_NONE;
+			}
+		}
+	}
+	else
+	{
+		if (ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess == _EXTRA_ERR_PROCESS_INUVP)
+		{
+			ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess = _EXTRA_ERR_PROCESS_NONE;
+		}
+	}
+
+	if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputOVP == YES ||
+			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputOVP == YES ||
+			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputOVP == YES)
+	{
+		if (ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess == _EXTRA_ERR_PROCESS_NONE)
+		{
+			ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess = _EXTRA_ERR_PROCESS_INOVP;
+		}
+
+		if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputOVP == YES)
+			RecordAlarmCode(index, "012200");
+		else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputOVP == YES)
+			RecordAlarmCode(index, "012201");
+		else if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputOVP == YES)
+			RecordAlarmCode(index, "012202");
+
+		chargingInfo[index]->StopChargeFlag = YES;
+	}
+	else
+	{
+		if (ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess == _EXTRA_ERR_PROCESS_INOVP)
+		{
+			ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess = _EXTRA_ERR_PROCESS_NONE;
+		}
+	}
+}
+
+//===============================================
+// 確認 GPIO 狀態
+//===============================================
+void gpio_set_value(unsigned int gpio, unsigned int value)
+{
+	int fd;
+	char buf[MAX_BUF];
+
+	snprintf(buf, sizeof(buf), SYSFS_GPIO_DIR "/gpio%d/value", gpio);
+	fd = open(buf, O_WRONLY);
+	if (fd < 0)
+	{
+	    perror("gpio/set-value");
+	    return;
+	}
+
+	if (value)
+		write(fd, "1", 2);
+	else
+	    write(fd, "0", 2);
+
+	close(fd);
+}
+
+int gpio_get_value(unsigned int gpio, unsigned int *value)
+{
+    int fd;
+    char buf[MAX_BUF];
+    char ch;
+
+    snprintf(buf, sizeof(buf), SYSFS_GPIO_DIR "/gpio%d/value", gpio);
+
+    fd = open(buf, O_RDONLY);
+    if (fd < 0) {
+        perror("gpio/get-value");
+        return fd;
+    }
+
+    read(fd, &ch, 1);
+
+    if (ch != '0') {
+        *value = 1;
+    } else {
+        *value = 0;
+    }
+
+    close(fd);
+    return 0;
+}
+
+void CheckGunTypeFromHw()
+{
+	int pinIn[4] = { 22, 23, 44, 45 };
+	unsigned int gpioValue = 0;
+
+	for (int i = 0; i < ARRAY_SIZE(pinIn); i++) {
+		gpio_get_value(pinIn[i], &gpioValue);
+		{
+			switch (pinIn[i])
+			{
+			case 22:
+				bd1_1_status = gpioValue;
+				break;
+			case 23:
+				bd1_2_status = gpioValue;
+				break;
+			case 44:
+				bd0_1_status = gpioValue;
+				break;
+			case 45:
+				bd0_2_status = gpioValue;
+				break;
+			}
+		}
+	}
+}
+
+// Bypass useless functions
+void CheckGpioInStatus()
+{
+	int pinIn[2] = { 27, 47 };
+	unsigned int gpioValue = 0;
+
+	for (int i = 0; i < ARRAY_SIZE(pinIn); i++)
+	{
+		gpio_get_value(pinIn[i], &gpioValue);
+		if (gpioValue == 0x01)
+		{
+			switch(pinIn[i])
+			{
+				// 小板緊急停止
+				case 47:
+				{
+					for(int i = 0; i < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; i++)
+					{
+						if (chargingInfo[i]->slotsIndex == 1)
+						{
+//							if (chargingInfo[i]->Type == _Type_Chademo)
+//								BoardErrOccurByString(i, "023730");
+//							else if (chargingInfo[i]->Type == _Type_CCS)
+//								BoardErrOccurByString(i, "013627");
+							break;
+						}
+					}
+				}
+					break;
+				case 27:
+				{
+					for(int i = 0; i < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; i++)
+					{
+						if (chargingInfo[i]->slotsIndex == 3)
+						{
+//							if (chargingInfo[i]->Type == _Type_Chademo)
+//								BoardErrOccurByString(i, "023730");
+//							else if (chargingInfo[i]->Type == _Type_CCS)
+//								BoardErrOccurByString(i, "013627");
+							break;
+						}
+					}
+				}
+					break;
+			}
+		}
+		else
+		{
+			switch (pinIn[i])
+			{
+				// 小板解除緊急停止
+				case 47:
+				{
+					for(int i = 0; i < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; i++)
+					{
+						if (chargingInfo[i]->slotsIndex == 1)
+						{
+							if (chargingInfo[i]->Type == _Type_Chademo)
+								ReleaseBoardErrOccurByString(i, "023730");
+//							else if (chargingInfo[i]->Type == _Type_CCS)
+//								ReleaseBoardErrOccurByString(i, "013627");
+							break;
+						}
+					}
+				}
+					break;
+				case 27:
+				{
+					for (int i = 0; i < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; i++)
+					{
+						if (chargingInfo[i]->slotsIndex == 3)
+						{
+							if (chargingInfo[i]->Type == _Type_Chademo)
+								ReleaseBoardErrOccurByString(i, "023730");
+//							else if (chargingInfo[i]->Type == _Type_CCS)
+//								ReleaseBoardErrOccurByString(i, "013627");
+							break;
+						}
+					}
+				}
+				break;
+			}
+		}
+	}
+}
+
+//===============================================
+// Main process
+//===============================================
+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;
+}
+
+// 檢查 Byte 中某個 Bit 的值
+// _byte : 欲改變的 byte
+// _bit : 該 byte 的第幾個 bit
+unsigned char DetectBitValue(unsigned char _byte, unsigned char _bit)
+{
+	return ( _byte & mask_table[_bit] ) != 0x00;
+}
+
+// 設定 Byte 中某個 Bit的值
+// _byte : 欲改變的 byte
+// _bit : 該 byte 的第幾個 bit
+// value : 修改的值為 0 or 1
+void SetBitValue(unsigned char *_byte, unsigned char _bit, unsigned char value)
+{
+	if(value == 1)
+		*_byte |= (1 << _bit);
+	else if (value == 0)
+		*_byte ^= (1 << _bit);
+}
+
+void GetCcidAuthPossible(bool *idleReq, byte *idleIndex)
+{
+	for (byte gun_index = 0;
+			gun_index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount;
+			gun_index ++)
+	{
+		if (chargingInfo [gun_index]->SystemStatus == SYS_MODE_PREPARE_FOR_EV &&
+				ShmDcCommonData->_authWithCcidFlag [gun_index] == _CCID_CHECK)
+		{
+			*idleIndex = gun_index;
+			*idleReq = true;
+			break;
+		}
+	}
+}
+
+void UserScanFunction()
+{
+	bool idleReq = false;
+	unsigned char idleIndex = 255;
+	//unsigned char stopReq = 255;
+	bool hasGunUsing = false;
+	bool isReservedCard = false;
+
+	// 當前非驗證的狀態
+	if(!IsAuthorizingMode())
+	{
+		// 先判斷現在是否可以提供刷卡
+		// 1. 如果當前沒有槍是閒置狀態,則無提供刷卡功能
+		// 2. 停止充電
+		if (ShmSysConfigAndInfo->SysInfo.PageIndex == _LCM_FIX ||
+				ShmSysConfigAndInfo->SysInfo.PageIndex == _LCM_EMC)
+		{
+			strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
+			return;
+		}
+
+		if (strlen((char *)ShmSysConfigAndInfo->SysConfig.UserId) > 0)
+		{
+			if (_acgunIndex > 0 && ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc == DEFAULT_AC_INDEX &&
+					ac_chargingInfo[0]->SystemStatus != SYS_MODE_ALARM)
+			{
+				// 如果選 AC 槍
+				if (ac_chargingInfo[0]->SystemStatus >= SYS_MODE_MODE_REASSIGN_CHECK &&
+						ac_chargingInfo[0]->SystemStatus < SYS_MODE_ALARM)
+				{
+					if (ac_chargingInfo[0]->SystemStatus == SYS_MODE_CHARGING)
+					{
+						char value[32];
+
+						PRINTF_FUNC("ac stop charging \n");
+						PRINTF_FUNC("index = %d, card number = %s, UserId = %s \n", ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc,
+								ac_chargingInfo[0]->StartUserId, ShmSysConfigAndInfo->SysConfig.UserId);
+						memcpy(value, (unsigned char *)ac_chargingInfo[0]->StartUserId, ARRAY_SIZE(ac_chargingInfo[0]->StartUserId));
+						if (strcmp((char *)ShmSysConfigAndInfo->SysConfig.UserId, value) == EQUAL)
+						{
+							AcChargingTerminalProcess();
+						}
+						strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
+					}
+				}
+				else if (ac_chargingInfo[0]->SystemStatus == SYS_MODE_IDLE ||
+						ac_chargingInfo[0]->SystemStatus == SYS_MODE_RESERVATION)
+				{
+					idleReq = true;
+				}
+			}
+			else
+			{
+				if (IsGunUsing(ShmSysConfigAndInfo->SysInfo.CurGunSelected))
+				{
+					if (chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus == SYS_MODE_CHARGING)
+					{
+						char value[32];
+
+						PRINTF_FUNC("stop charging \n");
+						PRINTF_FUNC("index = %d, card number = %s, UserId = %s \n", ShmSysConfigAndInfo->SysInfo.CurGunSelected,
+								chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->StartUserId, ShmSysConfigAndInfo->SysConfig.UserId);
+						memcpy(value, (unsigned char *)chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->StartUserId,
+								ARRAY_SIZE(chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->StartUserId));
+
+						// 同一張卡直接停掉
+						if (strcmp((char *)ShmSysConfigAndInfo->SysConfig.UserId, value) == EQUAL)
+						{
+							NormalStop(ShmSysConfigAndInfo->SysInfo.CurGunSelected);
+							ChargingTerminalProcess(ShmSysConfigAndInfo->SysInfo.CurGunSelected);
+							strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
+						}
+						else
+						{
+							if (ShmDcCommonData->enObtainAuthorizbyCCID)
+							{
+								GetCcidAuthPossible(&idleReq, &idleIndex);
+							}
+
+							if (!idleReq)
+							{
+								PRINTF_FUNC ( "_LCM_AUTHORIZ_FAIL \n" );
+								stopChargingChkByCard = true;
+								strcpy ( (char *) ShmSysConfigAndInfo->SysConfig.UserId, "" );
+								ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_AUTHORIZ_FAIL;
+							}
+						}
+					}
+					else
+					{
+						if (ShmDcCommonData->enObtainAuthorizbyCCID)
+						{
+							GetCcidAuthPossible(&idleReq, &idleIndex);
+						}
+					}
+				}
+//				else if (chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus == SYS_MODE_IDLE ||
+//						chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus == SYS_MODE_RESERVATION)
+//				{
+//					idleIndex = ShmSysConfigAndInfo->SysInfo.CurGunSelected;
+//					idleReq = true;
+//				}
+				else
+				{
+					if (ShmDcCommonData->enObtainAuthorizbyCCID &&
+							(ShmSysConfigAndInfo->SysInfo.SystemPage == _LCM_AUTHORIZING ||
+							ShmSysConfigAndInfo->SysInfo.SystemPage == _LCM_AUTHORIZ_COMP ||
+							ShmSysConfigAndInfo->SysInfo.SystemPage == _LCM_AUTHORIZ_FAIL))
+						return;
+
+					for (byte gun_index = 0; gun_index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gun_index++)
+					{
+						if (chargingInfo[gun_index]->SystemStatus == SYS_MODE_IDLE)
+						{
+							idleIndex = gun_index;
+							idleReq = true;
+						}
+						else if (chargingInfo[gun_index]->SystemStatus == SYS_MODE_RESERVATION)
+						{
+							idleReq = true;
+						}
+						else
+						{
+							hasGunUsing = IsGunUsing(gun_index);
+						}
+					}
+
+					// 壁掛不給充 - 已經有至少一把槍在充電
+					if (ShmSysConfigAndInfo->SysInfo.IsAlternatvieConf == YES &&
+							hasGunUsing)
+					{
+						PRINTF_FUNC("DW Serial not support dual charging. \n");
+						idleReq = false;
+						strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
+					}
+				}
+			}
+
+			if (idleReq)
+			{
+//				if (ShmSysConfigAndInfo->SysConfig.TotalConnectorCount > 1 &&
+//					stopReq != 255 &&
+//					ShmSysConfigAndInfo->SysInfo.IsAlternatvieConf == YES)
+//				{
+//					idleReq = false;
+//					strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
+//				}
+//				else
+				{
+					for (byte gun_index = 0; gun_index < ShmSysConfigAndInfo->SysConfig.AcConnectorCount; gun_index++)
+					{
+						if (ac_chargingInfo[gun_index]->SystemStatus == SYS_MODE_RESERVATION)
+						{
+							if (strcmp ( (char *) ShmSysConfigAndInfo->SysConfig.UserId,
+									(char *) ShmDcCommonData->_reserved_ac_UserId [gun_index] ) == EQUAL)
+							{
+								isReservedCard = true;
+								// 驗證通過
+								ac_chargingInfo[gun_index]->ReservedStartFlag = YES;
+								ShmSysConfigAndInfo->SysInfo.OrderCharging = YES;
+								strcpy ( (char *) ShmSysConfigAndInfo->SysConfig.UserId, "" );
+								ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_AUTHORIZ_COMP;
+								break;
+							}
+						}
+					}
+
+					if (!isReservedCard)
+					{
+						for (byte gun_index = 0; gun_index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gun_index++)
+						{
+							if (chargingInfo[gun_index]->SystemStatus == SYS_MODE_RESERVATION)
+							{
+								if (strcmp((char *)ShmSysConfigAndInfo->SysConfig.UserId,
+										(char *)ShmDcCommonData->_reserved_UserId[gun_index]) == EQUAL)
+								{
+									isReservedCard = true;
+									// 驗證通過
+									chargingInfo[gun_index]->ReservedStartFlag = YES;
+									ShmSysConfigAndInfo->SysInfo.OrderCharging = YES;
+									strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
+									ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_AUTHORIZ_COMP;
+									break;
+								}
+							}
+						}
+					}
+
+					if (!isReservedCard &&
+							((_acgunIndex > 0 && ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc == DEFAULT_AC_INDEX) ||
+							(idleIndex != 255 && (chargingInfo[idleIndex]->SystemStatus == SYS_MODE_IDLE || chargingInfo[idleIndex]->SystemStatus == SYS_MODE_PREPARE_FOR_EV))))
+					{
+						if (ShmDcCommonData->_CcidAuthProcessStep != _CCID_AUTH)
+						{
+							PRINTF_FUNC("Start Authorizing... \n");
+							// LCM => Authorizing
+							if (ShmDcCommonData->enObtainAuthorizbyCCID &&
+									ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc != DEFAULT_AC_INDEX)
+							{
+								ShmSysConfigAndInfo->SysInfo.CurGunSelected = idleIndex;
+							}
+							ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_AUTHORIZING;
+							ShmDcCommonData->_CcidAuthProcessStep = _CCID_AUTH;
+							// 進入確認卡號狀態
+							AuthorizingStart();
+						}
+					}
+					else
+						strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
+				}
+			}
+			else
+			{
+				strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
+			}
+		}
+	}
+}
+
+unsigned char isModeChange(unsigned char gun_index)
+{
+	unsigned char result = NO;
+
+	if(chargingInfo[gun_index]->SystemStatus != chargingInfo[gun_index]->PreviousSystemStatus)
+	{
+		result = YES;
+		chargingInfo[gun_index]->PreviousSystemStatus = chargingInfo[gun_index]->SystemStatus;
+	}
+
+	return result;
+}
+
+void ScannerCardProcess()
+{
+	if (!isDetectPlugin() && !isCardScan && ShmSysConfigAndInfo->SysWarningInfo.Level != _ALARM_LEVEL_CRITICAL &&
+				ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_ENABLE)
+	{
+		isCardScan = true;
+		// 處理刷卡及驗證卡號的動作
+		UserScanFunction();
+	}
+	else if (ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_DISABLE)
+		strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
+
+	if (ShmSysConfigAndInfo->SysInfo.PageIndex == _LCM_AUTHORIZING)
+	{
+		StartSystemTimeoutDet(Timeout_Authorizing);
+
+		if (ShmSysConfigAndInfo->SysConfig.OfflinePolicy == _OFFLINE_POLICY_LOCAL_LIST)
+		{
+			// 白名單驗證
+			for (int i = 0; i < 10; i++)
+			{
+				if (strcmp((char *)ShmSysConfigAndInfo->SysConfig.LocalWhiteCard[i], "") != EQUAL)
+				{
+					if (strcmp((char *)ShmSysConfigAndInfo->SysConfig.LocalWhiteCard[i], (char *)ShmSysConfigAndInfo->SysConfig.UserId) == EQUAL)
+					{
+						PRINTF_FUNC("White Card Pass (%s)... \n", ShmSysConfigAndInfo->SysConfig.UserId);
+						ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_AUTHORIZ_COMP;
+						ClearAuthorizedFlag();
+						break;
+					}
+				}
+			}
+		}
+		// 確認驗證卡號完成沒
+		if (isAuthorizedComplete() || (ShmSysConfigAndInfo->SysInfo.OcppConnStatus == NO &&
+				ShmSysConfigAndInfo->SysConfig.OfflinePolicy == _OFFLINE_POLICY_FREE_CHARGING))
+		{
+			StopSystemTimeoutDet();
+			// 判斷後台回覆狀態
+			if(ocpp_chk_authrization_cmd() || (ShmSysConfigAndInfo->SysInfo.OcppConnStatus == NO &&
+					ShmSysConfigAndInfo->SysConfig.OfflinePolicy == _OFFLINE_POLICY_FREE_CHARGING))
+			{
+				// LCM => Authorize complete
+				PRINTF_FUNC("_LCM_AUTHORIZ_COMP \n");
+				ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_AUTHORIZ_COMP;
+			}
+			else
+			{
+				// LCM => Authorize fail
+				ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_AUTHORIZ_FAIL;
+				strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
+			}
+			ClearAuthorizedFlag();
+		}
+	}
+	else if (ShmSysConfigAndInfo->SysInfo.PageIndex == _LCM_AUTHORIZ_FAIL)
+	{
+		StartSystemTimeoutDet(Timeout_VerifyFail);
+		isCardScan = false;
+	}
+	else if(ShmSysConfigAndInfo->SysInfo.PageIndex == _LCM_AUTHORIZ_COMP)
+	{
+		StartSystemTimeoutDet(Timeout_VerifyComp);
+	}
+	else if(ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_ENABLE &&
+			ShmSysConfigAndInfo->SysInfo.PageIndex == _LCM_WAIT_FOR_PLUG)
+	{
+		StartSystemTimeoutDet(Timeout_WaitPlug);
+	}
+	else
+	{
+		isCardScan = false;
+	}
+}
+
+bool AddGunInfoByConnector(byte typeValue, byte slots)
+{
+	bool result = true;
+
+	switch (typeValue)
+	{
+		case '0': // none
+			break;
+		case '1': // IEC 62196-2 Type 1/SAE J1772 Plug
+			break;
+		case '2': // IEC 62196-2 Type 1/SAE J1772 Socket
+			break;
+		case '3': // IEC 62196-2 Type 2 Plug
+		case '4': // IEC 62196-2 Type 2 Socket
+			if (AC_QUANTITY > _ac_Index)
+			{
+				ac_chargingInfo[_acgunIndex] = &ShmSysConfigAndInfo->SysInfo.AcChargingData[_ac_Index];
+
+				// AC 固定 index
+				ac_chargingInfo[_acgunIndex]->Index = DEFAULT_AC_INDEX;
+				ac_chargingInfo[_acgunIndex]->ReservationId = -1;
+				ac_chargingInfo[_acgunIndex]->SystemStatus = SYS_MODE_BOOTING;
+				ac_chargingInfo[_acgunIndex]->Type = _Type_AC;
+				ac_chargingInfo[_acgunIndex]->IsAvailable = YES;
+				ac_chargingInfo[_acgunIndex]->schedule.isTriggerStart = NO;
+				ac_chargingInfo[_acgunIndex]->schedule.isTriggerStop = NO;
+				_ac_Index++;
+				_acgunIndex++;
+			}
+			else
+				result = false;
+			break;
+		case '5': // GB/T AC Plug
+			break;
+		case '6': // GB/T AC Socket
+			break;
+		case 'J': // CHAdeMO - 60A
+		case 'K': // CHAdeMO - 200A / 500V
+		case 'L': // CHAdeMO - 80A
+		{
+			if (CHAdeMO_QUANTITY > _chademoIndex)
+			{
+				chargingInfo[_gunIndex] = &ShmSysConfigAndInfo->SysInfo.ChademoChargingData[_chademoIndex];
+				chargingInfo[_gunIndex]->Index = _gunIndex;
+				chargingInfo[_gunIndex]->ReservationId = -1;
+				chargingInfo[_gunIndex]->slotsIndex = slots;
+				chargingInfo[_gunIndex]->SystemStatus = SYS_MODE_BOOTING;
+				chargingInfo[_gunIndex]->Type = _Type_Chademo;
+				chargingInfo[_gunIndex]->type_index = _chademoIndex;
+				chargingInfo[_gunIndex]->IsAvailable = YES;
+				chargingInfo[_acgunIndex]->schedule.isTriggerStart = NO;
+				chargingInfo[_acgunIndex]->schedule.isTriggerStop = NO;
+				chargingInfo[_gunIndex]->ModelType = typeValue;
+				_chademoIndex++;
+				_gunIndex++;
+			}
+			else
+				result = false;
+		}
+			break;
+		case 'U': // Natural cooling CCS1
+		case 'E': // Natural cooling CCS2
+		case 'T': // Rema CCS1 - 300A
+		case 'D': // Rema CCS2 - 300A
+		case 'M': // CCS2 - 80A
+		case 'N': // CCS1 - 80A
+		case 'R': // CCS2 - 250A
+		case 'V' : // Liquid cooling CCS1 - 500A
+		case 'F' : // Liquid cooling CCS2 - 500A
+		case 'Y' : // CCS1 - 150A
+		case 'Z' : // CCS2 - 150A
+		{
+			if (CCS_QUANTITY > _ccsIndex)
+			{
+				chargingInfo[_gunIndex] = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[_ccsIndex];
+
+				chargingInfo[_gunIndex]->Index = _gunIndex;
+				chargingInfo[_gunIndex]->ReservationId = -1;
+				chargingInfo[_gunIndex]->slotsIndex = slots;
+				chargingInfo[_gunIndex]->SystemStatus = SYS_MODE_BOOTING;
+				chargingInfo[_gunIndex]->Type = _Type_CCS;
+				chargingInfo[_gunIndex]->type_index = _ccsIndex;
+				chargingInfo[_gunIndex]->IsAvailable = YES;
+				chargingInfo[_acgunIndex]->schedule.isTriggerStart = NO;
+				chargingInfo[_acgunIndex]->schedule.isTriggerStop = NO;
+				chargingInfo[_gunIndex]->ModelType = typeValue;
+				// 現階段預設為走 DIN70121
+
+				ShmCcsData->CommProtocol = _CCS_COMM_V2GMessage_DIN70121;
+				if (typeValue == 'U' || typeValue == 'T' || typeValue == 'N' || typeValue == 'V' || typeValue == 'Y')
+					ShmDcCommonData->CcsTypeSaved [_gunIndex] = _CCS_TYPE_CCS1;
+				else if (typeValue == 'E' || typeValue == 'D' || typeValue == 'M' || typeValue == 'R' || typeValue == 'F' || typeValue == 'Z')
+					ShmDcCommonData->CcsTypeSaved [_gunIndex] = _CCS_TYPE_CCS2;
+
+				_ccsIndex++;
+				_gunIndex++;
+			}
+			else
+				result = false;
+		}
+			break;
+		case 'G': // GBT DC
+		case 'B':
+		{
+			if (GB_QUANTITY > _gb_Index)
+			{
+				chargingInfo[_gunIndex] = &ShmSysConfigAndInfo->SysInfo.GbChargingData[_gb_Index];
+
+				chargingInfo[_gunIndex]->Index = _gunIndex;
+				chargingInfo[_gunIndex]->ReservationId = -1;
+				chargingInfo[_gunIndex]->slotsIndex = slots;
+				chargingInfo[_gunIndex]->SystemStatus = SYS_MODE_BOOTING;
+				chargingInfo[_gunIndex]->Type = _Type_GB;
+				chargingInfo[_gunIndex]->type_index = _gb_Index;
+				chargingInfo[_gunIndex]->IsAvailable = YES;
+				chargingInfo[_acgunIndex]->schedule.isTriggerStart = NO;
+				chargingInfo[_acgunIndex]->schedule.isTriggerStop = NO;
+				chargingInfo[_gunIndex]->ModelType = typeValue;
+				_gb_Index++;
+				_gunIndex++;
+			}
+			else
+				result = false;
+		}
+			break;
+	}
+	return result;
+}
+
+bool CheckConnectorTypeStatus()
+{
+	bool result = true;
+
+	// 硬體 0 1 => CCS,1 0 => Chademo,1 1 => GB
+	//CheckFwSlotSta.tusLog();
+	if (strlen((char *) ShmSysConfigAndInfo->SysConfig.ModelName) >= 9)
+	{
+		byte slots = 1;
+		for (byte typeIndex = 7; typeIndex <= 9; typeIndex++)
+		{
+			if(!AddGunInfoByConnector(ShmSysConfigAndInfo->SysConfig.ModelName[typeIndex], slots))
+			{
+				return false;
+			}
+
+			slots++;
+		}
+
+		// AC index 接在 DC 後面
+//		if (_ac_Index > 0)
+//			ac_chargingInfo[0]->Index += _gunIndex;
+
+		ShmSysConfigAndInfo->SysConfig.TotalConnectorCount = _gunIndex;
+		ShmSysConfigAndInfo->SysConfig.AcConnectorCount = _acgunIndex;
+		PRINTF_FUNC("Charger Count => DC-Count = %d, AC-Count = %d \n",
+				ShmSysConfigAndInfo->SysConfig.TotalConnectorCount,
+				ShmSysConfigAndInfo->SysConfig.AcConnectorCount);
+
+		if (ShmSysConfigAndInfo->SysConfig.TotalConnectorCount == 0 &&
+				ShmSysConfigAndInfo->SysConfig.AcConnectorCount == 0)
+			result = false;
+
+		if (ShmSysConfigAndInfo->SysConfig.TotalConnectorCount == 1)
+		{
+			bool isFind = false;
+			if (chargingInfo[0]->Type == _Type_Chademo)
+			{
+				if ((bd0_1_status == 0 && bd0_2_status == 1) ||
+						(bd1_1_status == 0 && bd1_2_status == 1))
+				{
+					isFind = true;
+				}
+			}
+			else if (chargingInfo[0]->Type == _Type_CCS)
+			{
+				if ((bd0_1_status == 1 && bd0_2_status == 0) ||
+						(bd1_1_status == 1 && bd1_2_status == 0))
+				{
+					isFind = true;
+				}
+			}
+			else if (chargingInfo[0]->Type == _Type_GB)
+			{
+				if ((bd0_1_status == 1 && bd0_2_status == 1) ||
+						(bd1_1_status == 1 && bd1_2_status == 1))
+				{
+					isFind = true;
+				}
+			}
+
+			if (isFind)
+			{
+				chargingInfo[0]->Evboard_id = 0x01;
+				CheckHwSlotStatusLog(0);
+			}
+			else
+				result = false;
+		}
+		else
+		{
+			char type = NO_DEFINE;
+
+			// 偵測槍屬於哪個 slot : 可知道插在板上的Slot 0 或 1 是 Chademo 還是 CCS
+			for (byte gunIndex = 0; gunIndex < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gunIndex++)
+			{
+				if (gunIndex == 0 && bd0_1_status == 0 && bd0_2_status == 1)
+				{
+					PRINTF_FUNC("HW Conn %d (Chademo) \n", gunIndex);
+					// 與硬體相同 type : Chademo
+					if (chargingInfo[gunIndex]->Type == _Type_Chademo)
+					{
+						chargingInfo[gunIndex]->Evboard_id = 0x01;
+					}
+				}
+				else if (gunIndex == 0 && bd0_1_status == 1 && bd0_2_status == 0)
+				{
+					PRINTF_FUNC("HW Conn %d (CCS) \n", gunIndex);
+					// 與硬體相同 type : CCS
+					if (chargingInfo[gunIndex]->Type == _Type_CCS)
+					{
+						chargingInfo[gunIndex]->Evboard_id = 0x01;
+					}
+				}
+				else if (gunIndex == 0 && bd0_1_status == 1 && bd0_2_status == 1)
+				{
+					PRINTF_FUNC("HW Conn %d (GB) \n", gunIndex);
+					// 與硬體相同 type : GB
+					if (chargingInfo[gunIndex]->Type == _Type_GB)
+					{
+						chargingInfo[gunIndex]->Evboard_id = 0x01;
+					}
+				}
+				else if (gunIndex == 0)
+				{
+					PRINTF_FUNC("HW Conn fail, Gun_%d, Flag1 = %d, Flag2 = %d \n",
+							gunIndex, bd0_1_status, bd0_2_status);
+				}
+
+				if (gunIndex == 1 && bd1_1_status == 0 && bd1_2_status == 1)
+				{
+					PRINTF_FUNC("HW Conn %d (Chademo) \n", gunIndex);
+					// 與硬體相同 type : Chademo
+					if (chargingInfo[gunIndex]->Type == _Type_Chademo)
+					{
+						chargingInfo[gunIndex]->Evboard_id = 0x02;
+					}
+
+					if (ShmSysConfigAndInfo->SysConfig.TotalConnectorCount == 1)
+						chargingInfo[gunIndex]->Evboard_id = 0x01;
+				}
+				else if (gunIndex == 1 && bd1_1_status == 1 && bd1_2_status == 0)
+				{
+					PRINTF_FUNC("HW Conn %d (CCS) \n", gunIndex);
+					// 與硬體相同 type : CCS
+					if (chargingInfo[gunIndex]->Type == _Type_CCS)
+					{
+						chargingInfo[gunIndex]->Evboard_id = 0x02;
+					}
+
+					if (ShmSysConfigAndInfo->SysConfig.TotalConnectorCount == 1)
+						chargingInfo[gunIndex]->Evboard_id = 0x01;
+				}
+				else if (gunIndex == 1 && bd1_1_status == 1 && bd1_2_status == 1)
+				{
+					PRINTF_FUNC("HW Conn %d (GB) \n", gunIndex);
+					// 與硬體相同 type : GB
+					if (chargingInfo[gunIndex]->Type == _Type_GB)
+					{
+						chargingInfo[gunIndex]->Evboard_id = 0x02;
+					}
+
+					if (ShmSysConfigAndInfo->SysConfig.TotalConnectorCount == 1)
+						chargingInfo[gunIndex]->Evboard_id = 0x01;
+				}
+				else if (gunIndex == 1)
+				{
+					PRINTF_FUNC("HW Conn fail, Gun_%d, Flag1 = %d, Flag2 = %d \n",
+							gunIndex, bd1_1_status, bd1_2_status);
+				}
+
+				CheckHwSlotStatusLog(gunIndex);
+
+				if (type == NO_DEFINE)
+					type = chargingInfo[gunIndex]->Type;
+				else
+				{
+					// 雙槍都是同一個 type
+					if (type == chargingInfo[gunIndex]->Type)
+						ShmDcCommonData->SysGunAreSameType = YES;
+				}
+
+				if (chargingInfo[gunIndex]->Evboard_id == 0x00)
+					result = false;
+			}
+		}
+	}
+	else
+	{
+		// Module Name 不正確 - 告警
+		result = false;
+	}
+
+	return result;
+}
+
+void KillTask()
+{
+	ChangeLcmByIndex(_LCM_FIX);
+	system("killall Module_EventLogging");
+	system("killall Module_PrimaryComm");
+	system("killall Module_EvComm");
+	system("killall Module_InternalComm");
+	system("killall Module_PsuComm");
+	system("killall Module_4g &");
+	system("killall Module_Wifi &");
+}
+
+void KillTaskExceptDetectTask()
+{
+	ChangeLcmByIndex(_LCM_FIX);
+	sleep(3);
+	system("killall Module_EvComm");
+	//system("killall Module_InternalComm");
+	system("killall Module_PsuComm");
+	system("killall Module_4g &");
+	system("killall Module_Wifi &");
+}
+
+void KillAllTask()
+{
+	ChangeLcmByIndex(_LCM_FIX);
+	system("killall Module_EventLogging");
+	system("killall Module_PrimaryComm");
+	system("killall Module_EvComm");
+	system("killall Module_LcmControl");
+	system("killall Module_InternalComm");
+	system("killall Module_PsuComm");
+	system("killall OcppBackend &");
+	system("killall Module_4g &");
+	system("killall Module_Wifi &");
+	system("killall Module_DcMeter &");
+}
+
+void LogUpgradeType(unsigned int type)
+{
+	switch (type)
+	{
+		case _UPDATE_TYPE_CSU_UBOOT: 	PRINTF_FUNC("CSU bootloader (uboot) \n"); break;
+		case _UPDATE_TYPE_CSU_DTB: 		PRINTF_FUNC("CSU kernel configuration (dtb) \n"); break;
+		case _UPDATE_TYPE_CSU_ZIMAGE: 	PRINTF_FUNC("CSU kernel image (zImage) \n"); break;
+		case _UPDATE_TYPE_CSU_RFILES: 	PRINTF_FUNC("CSU root file system (ramdisk.gz) \n"); break;
+		case _UPDATE_TYPE_CSU_CONFIG: 	PRINTF_FUNC("CSU user configuration (bin) \n"); break;
+
+		case _UPDATE_TYPE_CCS_UBOOT: 	PRINTF_FUNC("CCS board bootloader (uboot) \n"); break;
+		case _UPDATE_TYPE_CCS_DTB: 		PRINTF_FUNC("CCS board kernel configuration (dtb) \n"); break;
+		case _UPDATE_TYPE_CCS_ZIMAGE: 	PRINTF_FUNC("CCS board kernel image (zImage) \n"); break;
+		case _UPDATE_TYPE_CCS_RFILES: 	PRINTF_FUNC("CCS board file system (ramdisk.gz) \n"); break;
+
+		case _UPDATE_TYPE_DCM_ST407: 	PRINTF_FUNC("DCM 407 primary controller \n"); break;
+		case _UPDATE_TYPE_RELAY_CTR: 	PRINTF_FUNC("Relay control board \n"); break;
+		case _UPDATE_TYPE_FAN_CTR: 		PRINTF_FUNC("Fan control board \n"); break;
+		case _UPDATE_TYPE_AC_WLMOUNT_CTR: PRINTF_FUNC("AC wall-mount (low-end) controller \n"); break;
+		case _UPDATE_TYPE_LED_CTR: 		PRINTF_FUNC("LED control board \n"); break;
+
+		case _UPDATE_TYPE_CHADEMO: 		PRINTF_FUNC("CAHdeMO board \n"); break;
+		case _UPDATE_TYPE_GBT: 			PRINTF_FUNC("GBT board \n"); break;
+	}
+}
+
+int CheckUpdateProcess(void)
+{
+    //bool isPass = true;
+    uint8_t retSucc = 0;
+    uint8_t retFail = 0;
+    byte index = 0;
+    byte target = 0;
+    char new_str[256];
+    unsigned char *ptr = NULL;
+    int fd = 0;
+    int CanFd = 0;
+    int uartFd = 0;
+    unsigned int Type = 0;
+    long int MaxLen = 48 * 1024 * 1024, ImageLen = 0;
+    DIR *d;
+    struct dirent *dir;
+    byte result = PASS;
+    char Buf[256];
+
+    d = opendir("/mnt/");
+    if (d)
+    {
+        while ((dir = readdir(d)) != NULL)
+        {
+            if (strcmp(dir->d_name, ".") == 0 || strcmp(dir->d_name, "..") == 0)
+            {
+                continue;
+            }
+
+            memset(new_str, 0x00, sizeof(new_str));
+            strcat(new_str, "/mnt/");
+            strcat(new_str, dir->d_name);
+            PRINTF_FUNC("%s \n", new_str);
+            fd = open(new_str, O_RDONLY);
+            if (fd < 0)
+            {
+            	close(fd);
+            	result = FAIL;
+            	sleep(1);
+            	continue;
+            }
+
+            ptr = malloc(MaxLen); //-48 is take out the header
+            //memset(ptr, 0xFF, MaxLen);  //-48 is take out the header
+
+            //get the image length
+            ImageLen = read(fd, ptr, MaxLen);
+            bool isModelNameFail = false;
+
+            // DS-----J0E-2PH
+            if((ShmSysConfigAndInfo->SysConfig.ModelName[0] != ptr[0]) ||
+            	   (ShmSysConfigAndInfo->SysConfig.ModelName[1] != ptr[1]) ||
+            	   (ShmSysConfigAndInfo->SysConfig.ModelName[7] != ptr[7]) ||
+            	   (ShmSysConfigAndInfo->SysConfig.ModelName[8] != ptr[8]) ||
+            	   (ShmSysConfigAndInfo->SysConfig.ModelName[9] != ptr[9]) ||
+            	   (ShmSysConfigAndInfo->SysConfig.ModelName[11] != ptr[11]) ||
+            	   (ShmSysConfigAndInfo->SysConfig.ModelName[12] != ptr[12]) ||
+            	   (ShmSysConfigAndInfo->SysConfig.ModelName[13] != ptr[13]))
+            {
+            	result = MODELNAME_FAIL;
+            	isModelNameFail = true;
+            }
+
+            if (isModelNameFail)
+            {
+            	close(fd);
+            	continue;
+            }
+
+            PRINTF_FUNC("model name check pass. \n");
+            if (ImageLen > 20) {
+                Type = (((unsigned int)ptr[16]) << 24 |
+                        ((unsigned int)ptr[17]) << 16 |
+                        ((unsigned int)ptr[18]) << 8  |
+                        ((unsigned int)ptr[19]));
+
+                LogUpgradeType(Type);
+                PRINTF_FUNC("Upgrade Status : PASS : %d, FAIL : %d \n", retSucc, retFail);
+                free(ptr);
+
+                switch (Type)
+                {
+                case _UPDATE_TYPE_CSU_UBOOT:
+                case _UPDATE_TYPE_CSU_DTB:
+                case _UPDATE_TYPE_CSU_ZIMAGE:
+                case _UPDATE_TYPE_CSU_RFILES:
+                case _UPDATE_TYPE_CSU_CONFIG:
+                	system("echo 3 > /proc/sys/vm/drop_caches");
+                	sleep(2);
+                    if (Upgrade_Flash(Type, new_str, (char *)ShmSysConfigAndInfo->SysConfig.ModelName) == PASS)
+                        retSucc++;
+                    else
+                    {
+                    	PRINTF_FUNC("Upgrade CSU Failed (%d) \n", Type);
+                    	retFail++;
+                    }
+                    memset(Buf, 0, sizeof(Buf));
+                    sprintf(Buf, "rm -rvf /mnt/%s", new_str);
+                    system(Buf);
+                    break;
+
+                case _UPDATE_TYPE_CCS_UBOOT:
+                case _UPDATE_TYPE_CCS_DTB:
+                case _UPDATE_TYPE_CCS_ZIMAGE:
+                case _UPDATE_TYPE_CCS_RFILES:
+                    CanFd = InitCanBus();
+                    if (CanFd > 0)
+                    {
+                        for (index = 0; index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; index++)
+                        {
+                            if (chargingInfo[index]->Type == _Type_CCS)
+                            {
+                            	byte targetID = chargingInfo[index]->Evboard_id;
+
+                            	if (ShmSysConfigAndInfo->SysConfig.TotalConnectorCount == 1 &&
+                            		ShmDcCommonData->CcsVersion == _CCS_VERSION_CHECK_TAG_V015S0)
+                            	{
+                            		targetID += 1;
+                            	}
+
+                            	system("echo 3 > /proc/sys/vm/drop_caches");
+                            	sleep(2);
+                            	PRINTF_FUNC("Upgrade CCS Processing..target id = %d \n", targetID);
+                                if (Upgrade_CCS(CanFd, Type, targetID, new_str, (char *)ShmSysConfigAndInfo->SysConfig.ModelName) == FAIL)
+                                {
+                                    PRINTF_FUNC("Upgrade CCS Failed \n");
+                                    retFail++;
+                                }
+                                else
+                                	retSucc++;
+                            }
+                        }
+                        close(CanFd);
+                    }
+                    memset(Buf, 0, sizeof(Buf));
+                    sprintf(Buf, "rm -rvf /mnt/%s", new_str);
+                    system(Buf);
+                    break;
+
+                case _UPDATE_TYPE_DCM_ST407:
+                case _UPDATE_TYPE_RELAY_CTR:
+                case _UPDATE_TYPE_FAN_CTR:
+                case _UPDATE_TYPE_AC_WLMOUNT_CTR:
+                case _UPDATE_TYPE_LED_CTR:
+                    target = 0x00;
+
+                    if (Type == _UPDATE_TYPE_DCM_ST407) {
+                        target = UPGRADE_PRI;
+                    } else if (Type == _UPDATE_TYPE_RELAY_CTR) {
+                        target = UPGRADE_RB;
+                    } else if (Type == _UPDATE_TYPE_FAN_CTR) {
+                        target = UPGRADE_FAN;
+                    } else if (Type == _UPDATE_TYPE_AC_WLMOUNT_CTR) {
+                        target = UPGRADE_AC;
+                    } else if (Type == _UPDATE_TYPE_LED_CTR) {
+                        target = UPGRADE_LED;
+                    }
+
+                    uartFd = InitComPort(target);
+
+                    if (Upgrade_UART(uartFd, Type, target, new_str, (char *)ShmSysConfigAndInfo->SysConfig.ModelName) == PASS)
+                    {
+                        retSucc++;
+                    }
+                    else
+                    {
+                        PRINTF_FUNC("Upgrade %x Failed\r\n", Type);
+                        retFail++;
+                    }
+
+                    if (uartFd > 0)
+                    {
+                        close(uartFd);
+                    }
+                    memset(Buf, 0, sizeof(Buf));
+                    sprintf(Buf, "rm -rvf /mnt/%s", new_str);
+                    system(Buf);
+                    break;
+
+                case _UPDATE_TYPE_CHADEMO:
+                case _UPDATE_TYPE_GBT:
+                    CanFd = InitCanBus();
+                    if (CanFd > 0)
+                    {
+                        for (index = 0; index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; index++)
+                        {
+                            if ((Type == _UPDATE_TYPE_CHADEMO && chargingInfo[index]->Type == _Type_Chademo) ||
+                                    (Type == _UPDATE_TYPE_GBT && chargingInfo[index]->Type == _Type_GB))
+                            {
+                            	PRINTF_FUNC("Upgrade GBT / Chademo Processing..target id = %d \n", chargingInfo[index]->Evboard_id);
+                                if (Upgrade_CAN(CanFd, Type, chargingInfo[index]->Evboard_id, new_str, (char *)ShmSysConfigAndInfo->SysConfig.ModelName) == PASS)
+                                    retSucc++;
+                                else
+                                {
+                                	if (chargingInfo[index]->Type == _Type_Chademo)
+                                		PRINTF_FUNC("Upgrade Chademo Failed \n");
+                                	else
+                                		PRINTF_FUNC("Upgrade GBT Failed \n");
+                                    retFail++;
+                                }
+                            }
+                        }
+                        close(CanFd);
+                    }
+                    memset(Buf, 0, sizeof(Buf));
+                    sprintf(Buf, "rm -rvf /mnt/%s", new_str);
+                    system(Buf);
+                    break;
+                }
+            }
+            close(fd);
+        }
+    }
+    free(dir);
+    closedir(d);
+
+    PRINTF_FUNC("Upgrade Result : PASS : %d, FAIL : %d \n", retSucc, retFail);
+    sleep(1);
+    system("rm -rvf /mnt/* ");
+    if (retFail != 0)
+    {
+    	result = FAIL;
+    }
+
+    return result;
+}
+
+void CreateRfidFork()
+{
+	pid_t rfidRecPid;
+
+	rfidRecPid = fork();
+	if (rfidRecPid == 0)
+	{
+		while(true)
+		{
+			// 刷卡判斷
+			RFID rfid;
+			if (!ShmSysConfigAndInfo->SysConfig.isRFID)
+			{}
+			else if(getRequestCardSN(rfidFd, 0, &rfid))
+			{
+				//PRINTF_FUNC("Get Card..-%s- \n", ShmSysConfigAndInfo->SysConfig.UserId);
+				if (strlen((char *)ShmSysConfigAndInfo->SysConfig.UserId) == 0)
+				{
+					if (ShmSysConfigAndInfo->SysConfig.RfidCardNumEndian == RFID_ENDIAN_BIG)
+					{
+						switch (rfid.snType)
+						{
+						case RFID_SN_TYPE_6BYTE:
+							sprintf((char *) ShmSysConfigAndInfo->SysConfig.UserId,
+									"%02X%02X%02X%02X%02X%02X",
+									rfid.currentCard[0], rfid.currentCard[1],
+									rfid.currentCard[2], rfid.currentCard[3],
+									rfid.currentCard[4], rfid.currentCard[5]);
+							break;
+						case RFID_SN_TYPE_7BYTE:
+							sprintf((char *) ShmSysConfigAndInfo->SysConfig.UserId,
+									"%02X%02X%02X%02X%02X%02X%02X",
+									rfid.currentCard[0], rfid.currentCard[1],
+									rfid.currentCard[2], rfid.currentCard[3],
+									rfid.currentCard[4], rfid.currentCard[5],
+									rfid.currentCard[6]);
+							break;
+						case RFID_SN_TYPE_10BYTE:
+							sprintf((char *) ShmSysConfigAndInfo->SysConfig.UserId,
+									"%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X",
+									rfid.currentCard[0], rfid.currentCard[1],
+									rfid.currentCard[2], rfid.currentCard[3],
+									rfid.currentCard[4], rfid.currentCard[5],
+									rfid.currentCard[6], rfid.currentCard[7],
+									rfid.currentCard[8], rfid.currentCard[9]);
+							break;
+						case RFID_SN_TYPE_4BYTE:
+							sprintf((char *) ShmSysConfigAndInfo->SysConfig.UserId,
+									"%02X%02X%02X%02X",
+									rfid.currentCard[0], rfid.currentCard[1],
+									rfid.currentCard[2], rfid.currentCard[3]);
+							break;
+						}
+					}
+					else if (ShmSysConfigAndInfo->SysConfig.RfidCardNumEndian == RFID_ENDIAN_LITTLE)
+					{
+						switch (rfid.snType)
+						{
+						case RFID_SN_TYPE_6BYTE:
+							sprintf((char *) ShmSysConfigAndInfo->SysConfig.UserId,
+									"%02X%02X%02X%02X%02X%02X",
+									rfid.currentCard[5], rfid.currentCard[4],
+									rfid.currentCard[3], rfid.currentCard[2],
+									rfid.currentCard[1], rfid.currentCard[0]);
+							break;
+						case RFID_SN_TYPE_7BYTE:
+							sprintf((char *) ShmSysConfigAndInfo->SysConfig.UserId,
+									"%02X%02X%02X%02X%02X%02X%02X",
+									rfid.currentCard[6], rfid.currentCard[5],
+									rfid.currentCard[4], rfid.currentCard[3],
+									rfid.currentCard[2], rfid.currentCard[1],
+									rfid.currentCard[0]);
+							break;
+						case RFID_SN_TYPE_10BYTE:
+							sprintf((char *) ShmSysConfigAndInfo->SysConfig.UserId,
+									"%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X",
+									rfid.currentCard[9], rfid.currentCard[8],
+									rfid.currentCard[7], rfid.currentCard[6],
+									rfid.currentCard[5], rfid.currentCard[4],
+									rfid.currentCard[3], rfid.currentCard[2],
+									rfid.currentCard[1], rfid.currentCard[0]);
+							break;
+						case RFID_SN_TYPE_4BYTE:
+							sprintf((char *) ShmSysConfigAndInfo->SysConfig.UserId,
+									"%02X%02X%02X%02X",
+									rfid.currentCard[3], rfid.currentCard[2],
+									rfid.currentCard[1], rfid.currentCard[0]);
+							break;
+						}
+					}
+
+					PRINTF_FUNC("RFID : Get card number = %s\n", ShmSysConfigAndInfo->SysConfig.UserId);
+				}
+			}
+			sleep(1);
+		}
+	}
+}
+
+void CreateCheckSystemTaskFork()
+{
+	pid_t taskPid;
+
+	taskPid = fork();
+	if (taskPid == 0)
+	{
+		bool stopToDet = false;
+		while(true)
+		{
+			if (!stopToDet)
+			{
+				for (byte _index = 0; _index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _index++)
+				{
+					if (chargingInfo[_index]->SystemStatus == SYS_MODE_UPDATE ||
+							chargingInfo[_index]->Type == 0x09)
+					{
+						stopToDet = true;
+						continue;
+					}
+				}
+
+				if (!stopToDet)
+					CheckSystemTaskAlive();
+			}
+
+			sleep(5);
+		}
+	}
+}
+
+void StartSystemTimeoutDet(unsigned char flag)
+{
+	if (ShmSysConfigAndInfo->SysInfo.SystemTimeoutFlag != flag)
+	{
+		GetTimespecFunc(&ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer);
+	}
+	ShmSysConfigAndInfo->SysInfo.SystemTimeoutFlag = flag;
+}
+
+void StopSystemTimeoutDet()
+{
+	GetTimespecFunc(&ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer);
+	ShmSysConfigAndInfo->SysInfo.SystemTimeoutFlag = Timeout_None;
+}
+
+void StartGunInfoTimeoutDet(unsigned char gunIndex, unsigned char flag)
+{
+	if (gunIndex < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount)
+	{
+		if (chargingInfo[gunIndex]->TimeoutFlag != flag)
+		{
+			GetTimespecFunc(&chargingInfo[gunIndex]->ConnectorTimeout);
+		}
+		chargingInfo[gunIndex]->TimeoutFlag = flag;
+	}
+}
+
+void StopGunInfoTimeoutDet(unsigned char gunIndex)
+{
+	if (gunIndex < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount)
+	{
+		chargingInfo[gunIndex]->TimeoutFlag = Timeout_None;
+	}
+}
+
+void CheckConnectionTimeout()
+{
+	if(system("pidof -s OcppBackend > /dev/null") != 0)
+	{
+		_connectionTimeout = CONN_PLUG_TIME_OUT;
+	}
+	else
+	{
+		_connectionTimeout = _ocpp_get_connect_timeout();
+		if(_connectionTimeout <= 0)
+		{
+			_connectionTimeout = CONN_PLUG_TIME_OUT;
+		}
+	}
+}
+
+void CreateTimeoutFork()
+{
+	pid_t timeoutPid;
+
+	timeoutPid = fork();
+	if (timeoutPid > 0)
+	{
+		GetTimespecFunc(&_cmdSubPriority_time);
+		CheckConnectionTimeout();
+
+		int _timebuf = 0;
+
+		while(true)
+		{
+			_timebuf = GetTimeoutValue(&_cmdSubPriority_time);
+			if (_timebuf < 0)
+			{
+				GetTimespecFunc(&_cmdSubPriority_time);
+			}
+			else
+			{
+				if (_timebuf >= 5)
+				{
+					CheckConnectionTimeout();
+					GetTimespecFunc(&_cmdSubPriority_time);
+				}
+			}
+
+			//printf("Timeout ***********SystemTimeoutFlag = %d, ********\n", ShmSysConfigAndInfo->SysInfo.SystemTimeoutFlag);
+			// 系統
+			if (ShmSysConfigAndInfo->SysInfo.SystemTimeoutFlag != Timeout_None)
+			{
+				_timebuf = GetTimeoutValue(&ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer);
+				if (_timebuf < 0)
+				{
+					GetTimespecFunc(&ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer);
+				}
+				else
+				{
+					switch(ShmSysConfigAndInfo->SysInfo.SystemTimeoutFlag)
+					{
+						case Timeout_SelftestChk:
+							if (_timebuf >= SELFTEST_TIMEOUT)
+							{
+								_SelfTestTimeout();
+								StopSystemTimeoutDet();
+							}
+							break;
+						case Timeout_Authorizing:
+							if (_timebuf >= AUTHORIZE_TIMEOUT)
+							{
+								_AuthorizedTimeout();
+								StopSystemTimeoutDet();
+							}
+							break;
+						case Timeout_VerifyFail:
+							if (_timebuf >= AUTHORIZE_FAIL_TIMEOUT)
+							{
+								_AutoReturnTimeout();
+								StopSystemTimeoutDet();
+							}
+							break;
+						case Timeout_VerifyComp:
+							if (_timebuf >= AUTHORIZE_COMP_TIMEOUT)
+							{
+								_AutoReturnTimeout();
+								StopSystemTimeoutDet();
+							}
+							break;
+						case Timeout_WaitPlug:
+							if (_timebuf >= _connectionTimeout)
+							{
+								_DetectPlugInTimeout();
+								StopSystemTimeoutDet();
+							}
+							break;
+						case Timeout_ReturnToChargingGunDet:
+						{
+							if (_timebuf >= RETURN_TO_CHARGING_PAGE)
+							{
+								DisplayChargingInfo();
+								StopSystemTimeoutDet();
+							}
+						}
+							break;
+	//					case Timeout_AuthorizingForStop:
+	//					{
+	//						if (_timebuf / uSEC_VAL >= AUTHORIZE_STOP_TIMEOUT)
+	//						{
+	//							strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
+	//							ClearAuthorizedFlag();
+	//							StopSystemTimeoutDet();
+	//						}
+	//					}
+	//						break;
+					}
+				}
+			}
+
+			// 各槍
+			for (byte gun_index = 0; gun_index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gun_index++)
+			{
+				if (chargingInfo[gun_index]->TimeoutFlag != Timeout_None)
+				{
+					_timebuf = GetTimeoutValue(&chargingInfo[gun_index]->ConnectorTimeout);
+					if (_timebuf < 0)
+					{
+						GetTimespecFunc(&chargingInfo[gun_index]->ConnectorTimeout);
+					}
+					else
+					{
+						//printf("Timeout ***********TimeoutFlag = %d, ********\n", chargingInfo[gun_index]->TimeoutFlag);
+						switch(chargingInfo[gun_index]->TimeoutFlag)
+						{
+							case Timeout_Preparing:
+							{
+								if (_timebuf >= GUN_PREPARE_TIMEOUT)
+								{
+									_PrepareTimeout(gun_index);
+									StopGunInfoTimeoutDet(gun_index);
+								}
+							}
+								break;
+							case Timeout_EvChargingDet:
+							{
+								if (_timebuf >= GUN_EV_WAIT_TIMEOUT)
+								{
+									_DetectEvChargingEnableTimeout(gun_index);
+									StopGunInfoTimeoutDet(gun_index);
+								}
+							}
+								break;
+							case Timeout_EvseChargingDet:
+							{
+								if (chargingInfo[gun_index]->Type == _Type_GB)
+								{
+									if (_timebuf >= GUN_EVSE_WAIT_TIMEOUT * 3)
+									{
+										_DetectEvseChargingEnableTimeout(gun_index);
+										StopGunInfoTimeoutDet(gun_index);
+									}
+								}
+								else
+								{
+									if (_timebuf >= GUN_EVSE_WAIT_TIMEOUT)
+									{
+										_DetectEvseChargingEnableTimeout(gun_index);
+										StopGunInfoTimeoutDet(gun_index);
+									}
+								}
+							}
+								break;
+							case Timeout_EvseCompleteDet:
+							{
+								if (_timebuf >= GUN_COMP_WAIT_TIMEOUT)
+								{
+									StopGunInfoTimeoutDet(gun_index);
+								}
+							}
+								break;
+							case Timeout_ForCcsPrechargeDet:
+							{
+								if (_timebuf >= GUN_PRECHARGING_TIMEOUT)
+								{
+									_CcsPrechargeTimeout(gun_index);
+									StopGunInfoTimeoutDet(gun_index);
+								}
+							}
+								break;
+						}
+					}
+				}
+			}
+			sleep(1);
+		}
+	}
+}
+
+void GetSystemTime()
+{
+	struct timeb csuTime;
+	struct tm *tmCSU;
+
+	ftime(&csuTime);
+	tmCSU = localtime(&csuTime.time);
+	PRINTF_FUNC("Time : %04d-%02d-%02d %02d:%02d:%02d \n", tmCSU->tm_year + 1900,
+			tmCSU->tm_mon + 1, tmCSU->tm_mday, tmCSU->tm_hour, tmCSU->tm_min,
+			tmCSU->tm_sec);
+
+//	byte date[14];
+//
+//
+//		 //sprintf(&date, "%d", );
+//
+//		 date[0] = '0' + ((tmCSU->tm_year + 1900) / 1000 % 10);
+
+//	date[0] = (tmCSU->tm_year + 1900) / 1000 % 10;
+//	date[1] = (tmCSU->tm_year + 1900) / 100 % 10;
+//	date[2] = (tmCSU->tm_year + 1900) / 10 % 10;
+//	date[3] = (tmCSU->tm_year + 1900) / 1 % 10;
+//
+//	date[4] = (tmCSU->tm_mon + 1) / 10 % 10;
+//	date[5] = (tmCSU->tm_mon + 1) / 1 % 10;
+//
+//	date[6] = (tmCSU->tm_mday) / 10 % 10;
+//	date[7] = (tmCSU->tm_mday) / 1 % 10;
+//
+//	date[8] = (tmCSU->tm_hour) / 10 % 10;
+//	date[9] = (tmCSU->tm_hour) / 1 % 10;
+//
+//	date[10] = (tmCSU->tm_min) / 10 % 10;
+//	date[11] = (tmCSU->tm_min) / 1 % 10;
+//
+//	date[12] = (tmCSU->tm_sec) / 10 % 10;
+//	date[13] = (tmCSU->tm_sec) / 1 % 10;
+
+//	PRINTF_FUNC("%x, %x, %x, %x, %x, %x, %x, %x, %x, %x, %x, %x, %x, %x \n", date[0], date[1], date[2], date[3],
+//			date[4], date[5], date[6], date[7],
+//			date[8], date[9], date[10], date[11],
+//			date[12], date[13]);
+}
+
+void CheckFactoryConfigFunction()
+{
+	if(ShmSysConfigAndInfo->SysInfo.FactoryConfiguration)
+	{
+		char Buf[256];
+
+		sleep(5);
+		sprintf(Buf, "cd /root;./FactoryConfig -m %s %s",
+				ShmSysConfigAndInfo->SysConfig.ModelName,
+				ShmSysConfigAndInfo->SysConfig.SerialNumber);
+		system(Buf);
+
+		system("rm -f /Storage/OCPP/OCPPConfiguration");
+		system("sync");
+		sleep(5);
+		system("reboot -f");
+		sleep(5);
+		system("reboot -f");
+	}
+}
+
+void CheckFwUpdateFunction()
+{
+	//PRINTF_FUNC("ShmSysConfigAndInfo->SysInfo.FirmwareUpdate = %d \n", ShmSysConfigAndInfo->SysInfo.FirmwareUpdate);
+	if (ShmSysConfigAndInfo->SysInfo.FirmwareUpdate == YES)
+	{
+		DEBUG_INFO_MSG("ftp : update start. \n");
+		for (byte gun_index = 0; gun_index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gun_index++)
+		{
+			setChargerMode(gun_index, SYS_MODE_UPDATE);
+		}
+		CloseWatchDog();
+		sleep(2);
+		KillTask();
+		byte updateResult = CheckUpdateProcess();
+
+		if (updateResult == PASS)
+			DEBUG_INFO_MSG("ftp : update complete. \n");
+		else if (updateResult == MODELNAME_FAIL)
+		{
+			DEBUG_INFO_MSG("ftp : model name is none match. \n");
+			KillAllTask();
+			ShmSysConfigAndInfo->SysInfo.FirmwareUpdate = NO;
+			sleep(5);
+			system("/usr/bin/run_evse_restart.sh");
+			return;
+		}
+		else
+			DEBUG_INFO_MSG("ftp : update fail. \n");
+
+		ShmSysConfigAndInfo->SysInfo.FirmwareUpdate = NO;
+		sleep(5);
+		system("reboot -f");
+	}
+	else
+	{
+		ocpp_chk_update_cmd();
+	}
+}
+
+int TariffParsing(char *StringItem, char *TariffCode)
+{
+    char *ptrSave, *ptrToken;
+    char strSource[128];
+    int fee = 0;
+
+    memcpy(strSource, StringItem, 128);
+    ptrToken = strtok_r(strSource, ";", &ptrSave);
+    while(ptrToken != NULL)
+    {
+        char *strTariff = strstr(ptrToken, TariffCode);
+        if(strTariff != NULL)
+        {
+            char *strFee = strstr(strTariff, "$");
+            if(strFee != NULL)
+            {
+                strFee++;
+                float fFee = atof(strFee);
+                fee = (int)(fFee * 100);
+                break;
+            }
+        }
+        ptrToken = strtok_r(NULL, ";", &ptrSave);
+    }
+    return fee;
+}
+
+void DefaultPriceHandlerOcpp16(char *StrDefaultPrice)
+{
+	unsigned int connectionFee = 0, currentRate = 0, occupancyFee = 0;
+
+	PRINTF_FUNC("DefaultPriceHandler - StrDefaultPrice = %s \n", StrDefaultPrice);
+	connectionFee = TariffParsing(StrDefaultPrice, "Connection Fee");
+	currentRate = TariffParsing(StrDefaultPrice, "Current Rate");
+	occupancyFee = TariffParsing(StrDefaultPrice, "Occupancy Fee");
+
+	PRINTF_FUNC("***  Connection Fee: %d.%02d ***", (connectionFee / 100), (connectionFee % 100));
+	PRINTF_FUNC("***  Current Rate: %d.%02d ***", (currentRate / 100), (currentRate % 100));
+	PRINTF_FUNC("***  Occupancy Fee: %d.%02d ***", (occupancyFee / 100), (occupancyFee % 100));
+
+	ShmDcCommonData->balanceInfo.defaultPrice = currentRate;
+}
+
+void UserPriceHandlerOcpp16(char *UserId, char *UserPrice)
+{
+	unsigned int connectionFee = 0, currentRate = 0, occupancyFee = 0;
+	int accountBalance = 0;
+	byte acGunIndex = 0;
+
+	for (byte gunIndex = 0; gunIndex < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gunIndex++)
+	{
+		if (gunIndex == 1)
+			acGunIndex = ShmSysConfigAndInfo->SysConfig.AcConnectorCount;
+		else
+			acGunIndex = 0;
+
+		if((chargingInfo[gunIndex]->SystemStatus >= SYS_MODE_MODE_REASSIGN_CHECK &&
+				chargingInfo[gunIndex]->SystemStatus <= SYS_MODE_CHARGING) &&
+				strcmp((char *)chargingInfo[gunIndex]->StartUserId, UserId) == EQUAL)
+		{
+			connectionFee = TariffParsing((char *)ShmOCPP16Data->Cost.SetUserPrice.price, "Connection Fee");
+			currentRate = TariffParsing((char *)ShmOCPP16Data->Cost.SetUserPrice.price, "Current Rate");
+			occupancyFee = TariffParsing((char *)ShmOCPP16Data->Cost.SetUserPrice.price, "Occupancy Fee");
+			accountBalance = TariffParsing((char *)ShmOCPP16Data->Cost.SetUserPrice.price, "Account Balance");
+
+			if (ShmDcCommonData->balanceInfo.connectorBalanceInfo[gunIndex + acGunIndex].UserPrice != currentRate ||
+					ShmDcCommonData->balanceInfo.connectorBalanceInfo[gunIndex + acGunIndex].AccountBalance != accountBalance)
+			{
+				PRINTF_FUNC("***  Connection Fee: %d.%02d ***", (connectionFee / 100), (connectionFee % 100));
+				PRINTF_FUNC("***  Current Rate: %d.%02d ***", (currentRate / 100), (currentRate % 100));
+				PRINTF_FUNC("***  Occupancy Fee: %d.%02d ***", (occupancyFee / 100), (occupancyFee % 100));
+				PRINTF_FUNC("***  Account Balance: %d.%02d ***", (accountBalance / 100), (accountBalance % 100));
+
+				PRINTF_FUNC("*** Connector Id %d User Price %d.%02d, Account Balance %d.%02d ***",
+						(gunIndex), (currentRate / 100), (currentRate % 100), (accountBalance / 100), (accountBalance % 100));
+			}
+
+			ShmDcCommonData->balanceInfo.connectorBalanceInfo[gunIndex + acGunIndex].UserPrice = currentRate;
+			ShmDcCommonData->balanceInfo.connectorBalanceInfo[gunIndex + acGunIndex].AccountBalance = accountBalance;
+		}
+	}
+
+	for (byte gunIndex = 0; gunIndex < ShmSysConfigAndInfo->SysConfig.AcConnectorCount; gunIndex++)
+	{
+		acGunIndex = ShmSysConfigAndInfo->SysConfig.AcConnectorCount;
+
+		if(strcmp((char *)ac_chargingInfo[gunIndex]->StartUserId, UserId) == EQUAL)
+		{
+			if (ShmDcCommonData->balanceInfo.connectorBalanceInfo[acGunIndex].UserPrice != currentRate ||
+					ShmDcCommonData->balanceInfo.connectorBalanceInfo[acGunIndex].AccountBalance != accountBalance)
+			{
+				PRINTF_FUNC("*** AC Connector User Price %d.%02d, Account Balance %d.%02d ***",
+						(currentRate / 100), (currentRate % 100), (accountBalance / 100), (accountBalance % 100));
+			}
+
+			ShmDcCommonData->balanceInfo.connectorBalanceInfo[acGunIndex].UserPrice = currentRate;
+			ShmDcCommonData->balanceInfo.connectorBalanceInfo[acGunIndex].AccountBalance = accountBalance;
+		}
+	}
+}
+
+void RunningFinalCostHandlerOcpp16()
+{
+	unsigned int connectionFee = 0, sessionFee = 0, occupancyFee = 0, totalCost = 0;
+	int accountBalance = 0;
+	byte acGunIndex = 0;
+	bool isFind = false;
+
+	for (byte gunIndex = 0; gunIndex < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gunIndex++)
+	{
+		isFind = false;
+
+		if (gunIndex == 1)
+			acGunIndex = ShmSysConfigAndInfo->SysConfig.AcConnectorCount;
+		else
+			acGunIndex = 0;
+
+//		PRINTF_FUNC("*** gunIndex = %d, description = %s *** \n", gunIndex + acGunIndex,
+//							ShmOCPP16Data->Cost.RunningCost[gunIndex + acGunIndex].description);
+//		PRINTF_FUNC("*** gunIndex = %d, f description = %s *** \n", gunIndex + acGunIndex,
+//							ShmOCPP16Data->Cost.FinalCost[gunIndex + acGunIndex].description);
+		if (chargingInfo[gunIndex]->SystemStatus >= SYS_MODE_MODE_REASSIGN_CHECK &&
+				chargingInfo[gunIndex]->SystemStatus <= SYS_MODE_ALARM)
+		{
+			if(strlen((char *)ShmOCPP16Data->Cost.RunningCost[gunIndex + acGunIndex].description) > 0)
+			{
+				connectionFee = TariffParsing((char *)ShmOCPP16Data->Cost.RunningCost[gunIndex + acGunIndex].description, "Connection Fee");
+				sessionFee = TariffParsing((char *)ShmOCPP16Data->Cost.RunningCost[gunIndex + acGunIndex].description, "Session Fee");
+				occupancyFee = TariffParsing((char *)ShmOCPP16Data->Cost.RunningCost[gunIndex + acGunIndex].description, "Occupancy Fee");
+				totalCost = TariffParsing((char *)ShmOCPP16Data->Cost.RunningCost[gunIndex + acGunIndex].description, "Total Cost");
+				accountBalance = TariffParsing((char *)ShmOCPP16Data->Cost.RunningCost[gunIndex + acGunIndex].description, "Account Balance");
+
+				PRINTF_FUNC("*** Connector Id: %d Running Cost *** \n", gunIndex);
+				isFind = true;
+				memset(&ShmOCPP16Data->Cost.RunningCost[gunIndex + acGunIndex], 0x00, sizeof(struct StrcutRunningCost));
+			}
+
+			if(strlen((char *)ShmOCPP16Data->Cost.FinalCost[gunIndex + acGunIndex].description) > 0)
+			{
+				connectionFee = TariffParsing((char *)ShmOCPP16Data->Cost.FinalCost[gunIndex + acGunIndex].description, "Connection Fee");
+				sessionFee = TariffParsing((char *)ShmOCPP16Data->Cost.FinalCost[gunIndex + acGunIndex].description, "Session Fee");
+				occupancyFee = TariffParsing((char *)ShmOCPP16Data->Cost.FinalCost[gunIndex + acGunIndex].description, "Occupancy Fee");
+				totalCost = TariffParsing((char *)ShmOCPP16Data->Cost.FinalCost[gunIndex + acGunIndex].description, "Total Cost");
+				accountBalance = TariffParsing((char *)ShmOCPP16Data->Cost.FinalCost[gunIndex + acGunIndex].description, "Account Balance");
+
+				PRINTF_FUNC("********** Connector Id: %d Final Cost ********** \n", gunIndex);
+				isFind = true;
+				memset(&ShmOCPP16Data->Cost.FinalCost[gunIndex + acGunIndex], 0x00, sizeof(struct StrcutFinalCost));
+			}
+
+			if (isFind)
+			{
+				PRINTF_FUNC("*** Connection Fee: %d.%02d *** \n", (connectionFee / 100), (connectionFee % 100));
+				PRINTF_FUNC("*** Session Fee: %d.%02d *** \n", (sessionFee / 100), (sessionFee % 100));
+				PRINTF_FUNC("*** Occupancy Fee: %d.%02d *** \n", (occupancyFee / 100), (occupancyFee % 100));
+				PRINTF_FUNC("*** Total Cost: %d.%02d *** \n", (totalCost / 100), (totalCost % 100));
+				PRINTF_FUNC("*** Account Balance: %d.%02d *** \n", (accountBalance / 100), (accountBalance % 100));
+
+				if (ShmDcCommonData->balanceInfo.connectorBalanceInfo[gunIndex + acGunIndex].TotalCost != totalCost ||
+						ShmDcCommonData->balanceInfo.connectorBalanceInfo[gunIndex + acGunIndex].AccountBalance != accountBalance)
+				{
+					PRINTF_FUNC("*** Connector Id %d Total Cost %d.%02d, Account Balance %d.%02d *** \n",
+						(gunIndex), (totalCost / 100), (totalCost % 100), (accountBalance / 100), (accountBalance % 100));
+				}
+
+				ShmDcCommonData->balanceInfo.connectorBalanceInfo[gunIndex + acGunIndex].TotalCost = totalCost;
+				ShmDcCommonData->balanceInfo.connectorBalanceInfo[gunIndex + acGunIndex].AccountBalance = accountBalance;
+			}
+		}
+	}
+
+	for (byte gunIndex = 0; gunIndex < ShmSysConfigAndInfo->SysConfig.AcConnectorCount; gunIndex++)
+	{
+		isFind = false;
+
+		acGunIndex = ShmSysConfigAndInfo->SysConfig.AcConnectorCount;
+
+		if (ac_chargingInfo[gunIndex]->SystemStatus >= SYS_MODE_PREPARING &&
+				ac_chargingInfo[gunIndex]->SystemStatus <= SYS_MODE_ALARM)
+		{
+			if(strlen((char *)ShmOCPP16Data->Cost.RunningCost[acGunIndex].description) > 0)
+			{
+				connectionFee = TariffParsing((char *)ShmOCPP16Data->Cost.RunningCost[acGunIndex].description, "Connection Fee");
+				sessionFee = TariffParsing((char *)ShmOCPP16Data->Cost.RunningCost[acGunIndex].description, "Session Fee");
+				occupancyFee = TariffParsing((char *)ShmOCPP16Data->Cost.RunningCost[acGunIndex].description, "Occupancy Fee");
+				totalCost = TariffParsing((char *)ShmOCPP16Data->Cost.RunningCost[acGunIndex].description, "Total Cost");
+				accountBalance = TariffParsing((char *)ShmOCPP16Data->Cost.RunningCost[acGunIndex].description, "Account Balance");
+
+				PRINTF_FUNC("*** AC Connector : Running Cost ***\n");
+				isFind = true;
+				memset(&ShmOCPP16Data->Cost.RunningCost[acGunIndex], 0x00, sizeof(struct StrcutRunningCost));
+			}
+
+			if(strlen((char *)ShmOCPP16Data->Cost.FinalCost[acGunIndex].description) > 0)
+			{
+				connectionFee = TariffParsing((char *)ShmOCPP16Data->Cost.FinalCost[acGunIndex].description, "Connection Fee");
+				sessionFee = TariffParsing((char *)ShmOCPP16Data->Cost.FinalCost[acGunIndex].description, "Session Fee");
+				occupancyFee = TariffParsing((char *)ShmOCPP16Data->Cost.FinalCost[acGunIndex].description, "Occupancy Fee");
+				totalCost = TariffParsing((char *)ShmOCPP16Data->Cost.FinalCost[acGunIndex].description, "Total Cost");
+				accountBalance = TariffParsing((char *)ShmOCPP16Data->Cost.FinalCost[acGunIndex].description, "Account Balance");
+
+				PRINTF_FUNC("*** AC Connector : Final Cost ***\n");
+				isFind = true;
+				memset(&ShmOCPP16Data->Cost.FinalCost[acGunIndex], 0x00, sizeof(struct StrcutFinalCost));
+			}
+
+			if (isFind)
+			{
+				PRINTF_FUNC("*** Connection Fee: %d.%02d ***\n", (connectionFee / 100), (connectionFee % 100));
+				PRINTF_FUNC("*** Session Fee: %d.%02d ***\n", (sessionFee / 100), (sessionFee % 100));
+				PRINTF_FUNC("*** Occupancy Fee: %d.%02d ***\n", (occupancyFee / 100), (occupancyFee % 100));
+				PRINTF_FUNC("*** Total Cost: %d.%02d ***\n", (totalCost / 100), (totalCost % 100));
+				PRINTF_FUNC("*** Account Balance: %d.%02d ***\n", (accountBalance / 100), (accountBalance % 100));
+
+				if (ShmDcCommonData->balanceInfo.connectorBalanceInfo[gunIndex + acGunIndex].TotalCost != totalCost ||
+						ShmDcCommonData->balanceInfo.connectorBalanceInfo[gunIndex + acGunIndex].AccountBalance != accountBalance)
+				{
+					PRINTF_FUNC("*** Connector Id %d Total Cost %d.%02d, Account Balance %d.%02d ***\n",
+						(gunIndex), (totalCost / 100), (totalCost % 100), (accountBalance / 100), (accountBalance % 100));
+				}
+
+				ShmDcCommonData->balanceInfo.connectorBalanceInfo[acGunIndex].TotalCost = totalCost;
+				ShmDcCommonData->balanceInfo.connectorBalanceInfo[acGunIndex].AccountBalance = accountBalance;
+			}
+		}
+	}
+}
+
+//===============================================
+// ocpp key
+//===============================================
+bool ocpp_authorizeRemoteTxReqChk_key()
+{
+	bool result = false;
+
+	if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
+	{
+		if (strstr((char *) ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE"))
+			result = true;
+	}
+	else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
+	{
+
+	}
+
+	return result;
+}
+
+//===============================================
+// Check reservation date is expired
+//===============================================
+int opcc_chk_reserve_expired(byte gun_index)
+{
+	int result = NO;
+	byte acDirIndex = 0;
+
+	if (gun_index == 1)
+		acDirIndex = ShmSysConfigAndInfo->SysConfig.AcConnectorCount;
+
+	if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
+	{
+		if(chargingInfo[gun_index]->SystemStatus != SYS_MODE_RESERVATION)
+			PRINTF_FUNC("%s \n", ShmOCPP16Data->ReserveNow[gun_index + acDirIndex].ExpiryDate);
+
+		if (CheckTimeOut(ShmOCPP16Data->ReserveNow[gun_index + acDirIndex].ExpiryDate))
+			result = YES;
+	}
+	else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
+	{
+		if(chargingInfo[gun_index]->SystemStatus != SYS_MODE_RESERVATION)
+			PRINTF_FUNC("%s \n", ShmOCPP20Data->ReserveNow[gun_index + acDirIndex].expiryDateTime);
+
+		if (CheckTimeOut(ShmOCPP20Data->ReserveNow[gun_index + acDirIndex].expiryDateTime))
+			result = YES;
+	}
+	return result;
+}
+
+//===============================================
+// AC OCPP routine
+//===============================================
+void ocpp_ac_chk_availability_cmd()
+{
+	byte hasDc = ((ShmSysConfigAndInfo->SysConfig.TotalConnectorCount > 0) ? 1 : 0);
+	byte type = 0;
+
+	// 如果有 DC 槍~ 則 AC 槍在 index = 1 的位置~ 如果沒有 DC 槍則在 index = 0 的位置
+	if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
+	{
+		if (ShmOCPP16Data->CsMsg.bits[hasDc].ChangeAvailabilityReq == YES)
+		{
+			PRINTF_FUNC("***************ChkOcppStatus : AC OcppChangeAvailability******************** \n");
+			DEBUG_ERROR_MSG("***************ChkOcppStatus : AC OcppChangeAvailability******************** \n");
+			ShmOCPP16Data->CsMsg.bits[hasDc].ChangeAvailabilityReq = NO;
+			if(strcmp((char *)ShmOCPP16Data->ChangeAvailability[hasDc].Type, "Operative") == EQUAL)
+			{
+				if (isDb_ready)
+					DB_Update_Operactive(localDb, hasDc, true);
+
+				type = 1;
+			}
+			else if (strcmp((char *)ShmOCPP16Data->ChangeAvailability[hasDc].Type, "Inoperative") == EQUAL)
+			{
+				if (isDb_ready)
+					DB_Update_Operactive(localDb, hasDc, false);
+
+				type = 2;
+			}
+		}
+	}
+	else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
+	{
+		if (ShmOCPP20Data->CsMsg.bits[hasDc].ChangeAvailabilityReq == YES)
+		{
+			PRINTF_FUNC("***************ChkOcppStatus : OcppChangeAvailability******************** \n");
+			DEBUG_ERROR_MSG("***************ChkOcppStatus : OcppChangeAvailability******************** \n");
+			ShmOCPP20Data->CsMsg.bits[hasDc].ChangeAvailabilityReq = NO;
+			if(strcmp((char *)ShmOCPP20Data->ChangeAvailability[hasDc].operationalStatus, "Operative") == EQUAL)
+			{
+				if (isDb_ready)
+					DB_Update_Operactive(localDb, hasDc, true);
+
+				type = 1;
+			}
+			else if (strcmp((char *)ShmOCPP20Data->ChangeAvailability[hasDc].operationalStatus, "Inoperative") == EQUAL)
+			{
+				if (isDb_ready)
+					DB_Update_Operactive(localDb, hasDc, false);
+
+				type = 2;
+			}
+		}
+	}
+
+	if (type == 1)
+	{
+		ac_chargingInfo[0]->IsAvailable = YES;
+	}
+	else if (type == 2)
+	{
+		ac_chargingInfo[0]->IsAvailable = NO;
+	}
+}
+
+void ocpp_ac_chk_unlock_cmd()
+{
+	byte hasDc = ((ShmSysConfigAndInfo->SysConfig.TotalConnectorCount > 0) ? 1 : 0);
+
+	// 如果有 DC 槍~ 則 AC 槍在 index = 1 的位置~ 如果沒有 DC 槍則在 index = 0 的位置
+	if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
+	{
+		if (ShmOCPP16Data->CsMsg.bits[hasDc].UnlockConnectorReq == YES)
+		{
+			ShmOCPP16Data->CsMsg.bits[hasDc].UnlockConnectorReq = NO;
+			if (ac_chargingInfo[0]->SystemStatus >= SYS_MODE_MODE_REASSIGN_CHECK &&
+					ac_chargingInfo[0]->SystemStatus <= SYS_MODE_CHARGING)
+			{
+				// Unlocked - 充電中,需停止充電
+				strcpy((char *)ShmOCPP16Data->StopTransaction[hasDc].StopReason, "UnlockCommand");
+				ac_chargingInfo[0]->StopChargeFlag = YES;
+			}
+			strcpy((char *)ShmOCPP16Data->UnlockConnector[hasDc].ResponseStatus, "Unlocked");
+			ShmOCPP16Data->CsMsg.bits[hasDc].UnlockConnectorConf = YES;
+		}
+	}
+	else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
+	{
+		if (ShmOCPP20Data->CsMsg.bits[hasDc].UnlockConnectorReq == YES)
+		{
+			ShmOCPP20Data->CsMsg.bits[hasDc].UnlockConnectorReq = NO;
+			if (ac_chargingInfo[0]->SystemStatus >= SYS_MODE_MODE_REASSIGN_CHECK &&
+					ac_chargingInfo[0]->SystemStatus <= SYS_MODE_CHARGING)
+			{
+				// Unlocked - 充電中,需停止充電
+				strcpy((char *)ShmOCPP20Data->TransactionEvent[hasDc].transactionInfo.stoppedReason, "UnlockCommand");
+				ac_chargingInfo[0]->StopChargeFlag = YES;
+			}
+			strcpy((char*)ShmOCPP20Data->UnlockConnector[hasDc].Response_status, "Unlocked");
+			ShmOCPP20Data->CsMsg.bits[hasDc].UnlockConnectorConf = YES;
+		}
+	}
+}
+
+void ocpp_ac_chk_profileConf_cmd()
+{
+	byte hasDc = ((ShmSysConfigAndInfo->SysConfig.TotalConnectorCount > 0) ? 1 : 0);
+
+	if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
+	{
+		if (ShmOCPP16Data->CSUMsg.bits[hasDc].ChargingProfileConf == YES)
+		{
+			ShmOCPP16Data->CSUMsg.bits[hasDc].ChargingProfileConf = NO;
+		}
+	}
+	else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
+	{
+		if (ShmOCPP20Data->CSUMsg.bits[hasDc].ChargingProfileConf == YES)
+		{
+			ShmOCPP20Data->CSUMsg.bits[hasDc].ChargingProfileConf = NO;
+		}
+	}
+}
+
+void ocpp_ac_chargingProfile_process()
+{
+	int _time = 0;
+	int _startCount = NO_DEFINE;
+	int _maxCount = 0;
+
+	byte hasDc = ((ShmSysConfigAndInfo->SysConfig.TotalConnectorCount > 0) ? 1 : 0);
+
+	if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
+	{
+		if (strcmp((char *)ShmOCPP16Data->SmartChargingProfile[hasDc].ChargingProfileKind, "Absolute") == EQUAL &&
+				ShmOCPP16Data->SmartChargingProfile[hasDc].ChargingProfileId == YES)
+		{
+			_time = GetStartScheduleTime(ShmOCPP16Data->SmartChargingProfile[hasDc].ChargingSchedule.StartSchedule);
+
+			if (_time > -1)
+			{
+				_maxCount = ARRAY_SIZE(ShmOCPP16Data->SmartChargingProfile[hasDc].ChargingSchedule.ChargingSchedulePeriod);
+				_startCount = NO_DEFINE;
+
+				for (byte _count = 0; _count < _maxCount; _count++)
+				{
+					// 預設最小輸出電流 (MIN_OUTPUT_CUR) A
+					if (_time >= ShmOCPP16Data->SmartChargingProfile[hasDc].ChargingSchedule.ChargingSchedulePeriod[_count].StartPeriod)
+					{
+						if ((_count == 0 && ShmOCPP16Data->SmartChargingProfile[hasDc].ChargingSchedule.ChargingSchedulePeriod[_count].Limit >= MIN_OUTPUT_CUR) ||
+								ShmOCPP16Data->SmartChargingProfile[hasDc].ChargingSchedule.ChargingSchedulePeriod[_count].Limit > MIN_OUTPUT_CUR)
+						{
+							_startCount = _count;
+						}
+					}
+				}
+
+				if (_startCount < _maxCount)
+				{
+					//PRINTF_FUNC("AC - Gun_%d, Get Profile - Profile Index = %d \n", hasDc, _startCount);
+					//PRINTF_FUNC("Profile Limit = %.2f \n", ShmOCPP16Data->SmartChargingProfile[hasDc].ChargingSchedule.ChargingSchedulePeriod[_startCount].Limit);
+					if (ShmOCPP16Data->SmartChargingProfile[hasDc].ChargingSchedule.ChargingSchedulePeriod[_startCount].Limit >= 1 &&
+							ShmOCPP16Data->SmartChargingProfile[hasDc].ChargingSchedule.ChargingSchedulePeriod[_startCount].Limit <= 5)
+					{
+						ac_chargingInfo[0]->ChargingProfileCurrent = AC_MINIMUM_DUTY;
+					}
+					else if (ShmOCPP16Data->SmartChargingProfile[hasDc].ChargingSchedule.ChargingSchedulePeriod[_startCount].Limit == 0)
+					{
+						ac_chargingInfo[0]->ChargingProfileCurrent = AC_STOP_DUTY;
+					}
+					else
+					{
+						ac_chargingInfo[0]->ChargingProfileCurrent = ShmOCPP16Data->SmartChargingProfile[hasDc].ChargingSchedule.ChargingSchedulePeriod[_startCount].Limit;
+					}
+				}
+				else
+				{
+					ac_chargingInfo[0]->ChargingProfilePower = -1;
+					ac_chargingInfo[0]->ChargingProfileCurrent = -1;
+				}
+			}
+			else
+			{
+				ac_chargingInfo[0]->ChargingProfilePower = -1;
+				ac_chargingInfo[0]->ChargingProfileCurrent = -1;
+			}
+		}
+		else
+		{
+			ac_chargingInfo[0]->ChargingProfilePower = -1;
+			ac_chargingInfo[0]->ChargingProfileCurrent = -1;
+		}
+	}
+	else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
+	{
+		if (strcmp((char *)ShmOCPP20Data->SmartChargingProfile[hasDc].chargingProfileKind, "Absolute") == EQUAL &&
+				ShmOCPP20Data->SmartChargingProfile[hasDc].id == YES)
+		{
+			_time = GetStartScheduleTime(ShmOCPP20Data->SmartChargingProfile[hasDc].chargingSchedule[0].startSchedule);
+			_maxCount = ARRAY_SIZE(ShmOCPP20Data->SmartChargingProfile[hasDc].chargingSchedule[0].chargingSchedulePeriod);
+			_startCount = NO_DEFINE;
+
+			for (byte _count = 0; _count < _maxCount; _count++)
+			{
+				// 預設最小輸出電流 (MIN_OUTPUT_CUR) A
+				if (_time >= ShmOCPP20Data->SmartChargingProfile[hasDc].chargingSchedule[0].chargingSchedulePeriod[_count].startPeriod)
+				{
+					if ((_count == 0 && ShmOCPP20Data->SmartChargingProfile[hasDc].chargingSchedule[0].chargingSchedulePeriod[_count].limit >= MIN_OUTPUT_CUR) ||
+							ShmOCPP20Data->SmartChargingProfile[hasDc].chargingSchedule[0].chargingSchedulePeriod[_count].limit > MIN_OUTPUT_CUR)
+					{
+						_startCount = _count;
+					}
+				}
+			}
+
+			if (_startCount < _maxCount)
+			{
+				//PRINTF_FUNC("Gun_%d, Get Profile - Profile Index = %d \n", 1, _startCount);
+				//PRINTF_FUNC("Profile Limit = %.2f \n", ShmOCPP20Data->SmartChargingProfile[hasDc].chargingSchedule[0].chargingSchedulePeriod[_startCount].limit);
+				if (ShmOCPP20Data->SmartChargingProfile[hasDc].chargingSchedule[0].chargingSchedulePeriod[_startCount].limit >= 1 &&
+						ShmOCPP20Data->SmartChargingProfile[hasDc].chargingSchedule[0].chargingSchedulePeriod[_startCount].limit <= 5)
+				{
+					ac_chargingInfo [0]->ChargingProfileCurrent = AC_MINIMUM_DUTY;
+				}
+				else if (ShmOCPP20Data->SmartChargingProfile[hasDc].chargingSchedule[0].chargingSchedulePeriod[_startCount].limit == 0)
+				{
+					ac_chargingInfo [0]->ChargingProfileCurrent = AC_STOP_DUTY;
+				}
+				else
+				{
+					ac_chargingInfo [0]->ChargingProfileCurrent = ShmOCPP20Data->SmartChargingProfile[hasDc].chargingSchedule[0].chargingSchedulePeriod[_startCount].limit;
+				}
+			}
+			else
+			{
+				ac_chargingInfo[0]->ChargingProfilePower = -1;
+				ac_chargingInfo[0]->ChargingProfileCurrent = -1;
+			}
+		}
+		else
+		{
+			ac_chargingInfo[0]->ChargingProfilePower = -1;
+			ac_chargingInfo[0]->ChargingProfileCurrent = -1;
+		}
+	}
+	else
+	{
+		ac_chargingInfo[0]->ChargingProfilePower = -1;
+		ac_chargingInfo[0]->ChargingProfileCurrent = -1;
+	}
+
+	if (ac_chargingInfo[0]->ChargingProfileCurrent >= 0 &&
+			_AcChargingProfileCurBuffer != ac_chargingInfo[0]->ChargingProfileCurrent)
+	{
+		_AcChargingProfileCurBuffer = ac_chargingInfo[0]->ChargingProfileCurrent;
+		PRINTF_FUNC ( "AC Profile (duty) : ChargingProfileCurrent = %.2f \n", ac_chargingInfo[0]->ChargingProfileCurrent);
+	}
+}
+
+void ocpp_ac_lift_profileReq_cmd(byte gunIndex)
+{
+	byte hasDc = ((ShmSysConfigAndInfo->SysConfig.TotalConnectorCount > 0) ? 1 : 0);
+
+	if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
+	{
+		if (ShmOCPP16Data->CSUMsg.bits[hasDc].ChargingProfileConf == NO)
+		{
+			if (ShmOCPP16Data->CSUMsg.bits[hasDc].ChargingProfileReq == NO)
+				ShmOCPP16Data->CSUMsg.bits[hasDc].ChargingProfileReq = YES;
+		}
+	}
+	else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
+	{
+		if (ShmOCPP20Data->CSUMsg.bits[hasDc].ChargingProfileConf == NO)
+		{
+			if (ShmOCPP20Data->CSUMsg.bits[hasDc].ChargingProfileReq == NO)
+				ShmOCPP20Data->CSUMsg.bits[hasDc].ChargingProfileReq = YES;
+		}
+	}
+}
+
+int opcc_ac_chk_reserve_expired()
+{
+	int result = NO;
+	byte hasDc = ((ShmSysConfigAndInfo->SysConfig.TotalConnectorCount > 0) ? 1 : 0);
+
+	if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
+	{
+		if(ac_chargingInfo [0]->SystemStatus != SYS_MODE_RESERVATION)
+			PRINTF_FUNC("%s \n", ShmOCPP16Data->ReserveNow[hasDc].ExpiryDate);
+
+		if (CheckTimeOut(ShmOCPP16Data->ReserveNow[hasDc].ExpiryDate))
+			result = YES;
+	}
+	else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
+	{
+		if(ac_chargingInfo [0]->SystemStatus != SYS_MODE_RESERVATION)
+			PRINTF_FUNC("%s \n", ShmOCPP20Data->ReserveNow[hasDc].expiryDateTime);
+
+		if (CheckTimeOut(ShmOCPP20Data->ReserveNow[hasDc].expiryDateTime))
+			result = YES;
+	}
+	return result;
+}
+
+void ocpp_ac_chk_reserved_cmd()
+{
+	byte hasDc = ((ShmSysConfigAndInfo->SysConfig.TotalConnectorCount > 0) ? 1 : 0);
+
+	if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
+	{
+		if (ac_chargingInfo [0]->SystemStatus == SYS_MODE_IDLE &&
+				ShmOCPP16Data->CsMsg.bits [hasDc].ReserveNowReq == YES)
+		{
+			PRINTF_FUNC ( "***************ChkOcppStatus : (AC) OcppReservedStatus******************** \n" );
+			ShmOCPP16Data->CsMsg.bits [hasDc].ReserveNowReq = NO;
+			if ( ! opcc_ac_chk_reserve_expired ())
+			{
+				PRINTF_FUNC ( "ReservationId = %d \n", ShmOCPP16Data->ReserveNow [hasDc].ReservationId );
+				PRINTF_FUNC ( "IdTag = %s \n", ShmOCPP16Data->ReserveNow [hasDc].IdTag );
+				PRINTF_FUNC ( "*************ChkOcppStatus : (AC) OcppReservedStatus End****************** \n" );
+				ac_chargingInfo [0]->ReservationId = ShmOCPP16Data->ReserveNow [hasDc].ReservationId;
+				ac_chargingInfo [0]->SystemStatus = SYS_MODE_RESERVATION;
+
+				strcpy ( (char *) ShmDcCommonData->_reserved_ac_UserId[0],
+						(char *) ShmOCPP16Data->ReserveNow [hasDc].IdTag );
+			}
+			ShmOCPP16Data->CsMsg.bits [hasDc].ReserveNowConf = YES;
+		}
+
+		if (ac_chargingInfo [0]->SystemStatus == SYS_MODE_RESERVATION &&
+				ShmOCPP16Data->CsMsg.bits [hasDc].CancelReservationReq == YES)
+		{
+			ShmOCPP16Data->CsMsg.bits [hasDc].CancelReservationReq = NO;
+			if (ShmOCPP16Data->ReserveNow [hasDc].ReservationId == ac_chargingInfo [0]->ReservationId)
+			{
+				PRINTF_FUNC ( "***************ChkOcppStatus : (AC) OcppReservedStatus******************** \n" );
+				PRINTF_FUNC ( "ReservationId = %d \n", ShmOCPP16Data->ReserveNow [hasDc].ReservationId );
+				PRINTF_FUNC ( "***********ChkOcppStatus : (AC) Cancel OcppReservedStatus End**************** \n" );
+				ac_chargingInfo [0]->ReservationId = -1;
+				ac_chargingInfo [0]->SystemStatus = SYS_MODE_IDLE;
+
+				strcpy ( (char *) ShmDcCommonData->_reserved_ac_UserId[0], "" );
+				ShmOCPP16Data->CsMsg.bits [hasDc].CancelReservationConf = YES;
+			}
+		}
+	}
+	else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
+	{
+		if (ac_chargingInfo [0]->SystemStatus == SYS_MODE_IDLE &&
+				ShmOCPP20Data->CsMsg.bits [hasDc].ReserveNowReq == YES)
+		{
+			PRINTF_FUNC ( "***************ChkOcppStatus : (AC) OcppReservedStatus******************** \n" );
+			ShmOCPP20Data->CsMsg.bits [hasDc].ReserveNowReq = NO;
+			if ( ! opcc_ac_chk_reserve_expired ())
+			{
+				PRINTF_FUNC ( "id = %d \n", ShmOCPP20Data->ReserveNow [hasDc].id );
+				PRINTF_FUNC ( "idToken = %s \n", ShmOCPP20Data->ReserveNow [hasDc].idToken.idToken );
+				PRINTF_FUNC ( "*************ChkOcppStatus : (AC) OcppReservedStatus End****************** \n" );
+				ac_chargingInfo [0]->ReservationId = ShmOCPP20Data->ReserveNow [hasDc].id;
+				ac_chargingInfo [0]->SystemStatus = SYS_MODE_RESERVATION;
+
+				strncpy ( (char *) ShmDcCommonData->_reserved_UserId,
+						(char *) ShmOCPP20Data->ReserveNow [hasDc].idToken.idToken, 30 );
+			}
+			ShmOCPP20Data->CsMsg.bits [hasDc].ReserveNowConf = YES;
+		}
+
+		if (ac_chargingInfo [0]->SystemStatus == SYS_MODE_RESERVATION &&
+				ShmOCPP20Data->CsMsg.bits [hasDc].CancelReservationReq == YES)
+		{
+			ShmOCPP20Data->CsMsg.bits [hasDc].CancelReservationReq = NO;
+			if (ShmOCPP20Data->ReserveNow [hasDc].id == ac_chargingInfo [0]->ReservationId)
+			{
+				PRINTF_FUNC ( "***************ChkOcppStatus : (AC) OcppReservedStatus******************** \n" );
+				PRINTF_FUNC ( "ReservationId = %d \n", ShmOCPP20Data->ReserveNow [hasDc].id );
+				PRINTF_FUNC ( "***********ChkOcppStatus : (AC) Cancel OcppReservedStatus End**************** \n" );
+				ac_chargingInfo [0]->ReservationId = -1;
+				ac_chargingInfo [0]->SystemStatus = SYS_MODE_IDLE;
+
+				strcpy ( (char *) ShmDcCommonData->_reserved_UserId, "" );
+				ShmOCPP20Data->CsMsg.bits [hasDc].CancelReservationConf = YES;
+			}
+		}
+	}
+}
+
+//===============================================
+// OCPP routine
+//===============================================
+void ocpp_process_start()
+{
+	if(strcmp((char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, "") != EQUAL &&
+			strcmp((char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId, "") != EQUAL)
+	{
+		if(system("pidof -s OcppBackend > /dev/null") != 0)
+		{
+			DEBUG_ERROR_MSG("OcppBackend not running, restart it.\r\n");
+			if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
+				system("/root/OcppBackend &");
+			else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
+				system("/root/OcppBackend20 &");
+		}
+
+		if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
+		{
+			if((time((time_t*)NULL) - ShmOCPP16Data->procDogTime) > 180)
+			{
+				DEBUG_ERROR_MSG("OcppBackend watch dog timeout task restart.\n");
+				ShmOCPP16Data->procDogTime =  time((time_t*)NULL);
+				system("pkill OcppBackend");
+			}
+		}
+		if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
+		{
+			if((time((time_t*)NULL) - ShmOCPP20Data->procDogTime) > 180)
+			{
+				DEBUG_ERROR_MSG("OcppBackend20 watch dog timeout task restart.\n");
+				ShmOCPP16Data->procDogTime =  time((time_t*)NULL);
+				system("pkill OcppBackend20");
+			}
+		}
+	}
+
+	if(strcmp((char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, "") != EQUAL)
+	{
+		if(system("pidof -s OcppBackendPH > /dev/null") != 0)
+		{
+			DEBUG_ERROR_MSG("OcppBackendPH not running, restart it.\r\n");
+			system("/root/OcppBackendPH &");
+		}
+	}
+}
+
+void ocpp_auto_response_BootNotification()
+{
+	if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
+	{
+		if (ShmOCPP16Data->SpMsg.bits.BootNotificationConf == YES)
+			ShmOCPP16Data->SpMsg.bits.BootNotificationConf = NO;
+	}
+	else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
+	{
+		if (ShmOCPP20Data->SpMsg.bits.BootNotificationConf == YES)
+			ShmOCPP20Data->SpMsg.bits.BootNotificationConf = NO;
+	}
+}
+
+bool ocpp_is_resPass_StartTransactionConf(byte gun_index)
+{
+	bool result = false;
+	byte acDirIndex = 0;
+
+	// 如果有 AC 槍,則固定是第 2 把槍,所以索引固定為 1 (只會影響右槍所以考慮右槍狀況)
+	if (gun_index == 1)
+		acDirIndex = ShmSysConfigAndInfo->SysConfig.AcConnectorCount;
+
+	if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
+	{
+		result = ShmOCPP16Data->CpMsg.bits[gun_index + acDirIndex].StartTransactionConf;
+	}
+	else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
+	{
+		result = ShmOCPP20Data->CpMsg.bits[gun_index + acDirIndex].TransactionEventConf;
+	}
+
+	return result;
+}
+
+void ocpp_auto_response_StartTransationConf(byte gun_index)
+{
+	byte acDirIndex = 0;
+
+	// 如果有 AC 槍,則固定是第 2 把槍,所以索引固定為 1 (只會影響右槍所以考慮右槍狀況)
+	if (gun_index == 1)
+		acDirIndex = ShmSysConfigAndInfo->SysConfig.AcConnectorCount;
+
+	if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
+	{
+		if (ShmOCPP16Data->CpMsg.bits[gun_index + acDirIndex].StartTransactionConf)
+			ShmOCPP16Data->CpMsg.bits[gun_index + acDirIndex].StartTransactionConf = NO;
+	}
+	else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
+	{
+		if (ShmOCPP20Data->CpMsg.bits[gun_index + acDirIndex].TransactionEventConf)
+			ShmOCPP20Data->CpMsg.bits[gun_index + acDirIndex].TransactionEventConf = NO;
+	}
+}
+
+void ocpp_auto_response_ReserveConf(byte gun_index)
+{
+	byte acDirIndex = 0;
+
+	// 如果有 AC 槍,則固定是第 2 把槍,所以索引固定為 1 (只會影響右槍所以考慮右槍狀況)
+	if (gun_index == 1)
+		acDirIndex = ShmSysConfigAndInfo->SysConfig.AcConnectorCount;
+
+	if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
+		ShmOCPP16Data->CsMsg.bits[gun_index + acDirIndex].ReserveNowConf = YES;
+	else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
+		ShmOCPP20Data->CsMsg.bits[gun_index + acDirIndex].ReserveNowConf = YES;
+}
+
+bool ocpp_chk_authrization_cmd()
+{
+	char buf2[16] = "";
+	memset(buf2, 0, ARRAY_SIZE(buf2));
+
+	if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
+		sprintf(buf2, "%s",	ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
+	else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
+		sprintf(buf2, "%s",	ShmOCPP20Data->Authorize.Response_idTokenInfo.status);
+	// 因為無法得知實際的長度,所以只能用搜尋的方式
+	if(strcmp(buf2, "Accepted") == EQUAL)
+		return true;
+
+	return false;
+}
+
+bool opcc_sub_get_reset_req()
+{
+	bool result = false;
+
+	if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
+		result = ShmOCPP16Data->MsMsg.bits.ResetReq;
+	else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
+		result = ShmOCPP20Data->MsMsg.bits.ResetReq;
+
+	return result;
+}
+
+void ocpp_sub_run_reset(bool canReset)
+{
+	if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
+	{
+		if(canReset && strcmp((char *)ShmOCPP16Data->Reset.Type, "Hard") == EQUAL)
+		{
+			DEBUG_ERROR_MSG("****** Hard Reboot ****** \n");
+			sprintf((char*)ShmOCPP16Data->Reset.ResponseStatus, "Accepted");
+			ShmOCPP16Data->MsMsg.bits.ResetReq = NO;
+			ShmOCPP16Data->MsMsg.bits.ResetConf = YES;
+			sleep(3);
+			system("reboot -f");
+		}
+		else if (canReset && strcmp((char *)ShmOCPP16Data->Reset.Type, "Soft") == EQUAL)
+		{
+			DEBUG_ERROR_MSG("****** Soft Reboot ****** \n");
+			sprintf((char*)ShmOCPP16Data->Reset.ResponseStatus, "Accepted");
+			ShmOCPP16Data->MsMsg.bits.ResetReq = NO;
+			ShmOCPP16Data->MsMsg.bits.ResetConf = YES;
+			sleep(3);
+			KillAllTask();
+			CloseWatchDog();
+			system("/usr/bin/run_evse_restart.sh");
+		}
+	}
+	else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
+	{
+		if(canReset && strcmp((char *)ShmOCPP20Data->Reset.type, "Immediate") == EQUAL)
+		{
+			DEBUG_ERROR_MSG("****** Hard Reboot ****** \n");
+			sprintf((char*)ShmOCPP20Data->Reset.Response_status, "Accepted");
+			ShmOCPP20Data->MsMsg.bits.ResetReq = NO;
+			ShmOCPP20Data->MsMsg.bits.ResetConf = YES;
+			sleep(3);
+			system("reboot -f");
+		}
+		else if (canReset && strcmp((char *)ShmOCPP20Data->Reset.type, "OnIdle") == EQUAL)
+		{
+			DEBUG_ERROR_MSG("****** Soft Reboot ****** \n");
+			sprintf((char*)ShmOCPP20Data->Reset.Response_status, "Accepted");
+			ShmOCPP20Data->MsMsg.bits.ResetReq = NO;
+			ShmOCPP20Data->MsMsg.bits.ResetConf = YES;
+			sleep(3);
+			KillAllTask();
+			CloseWatchDog();
+			system("/usr/bin/run_evse_restart.sh");
+		}
+	}
+}
+
+void ocpp_chk_reset_cmd(byte isforce)
+{
+	if (opcc_sub_get_reset_req())
+	{
+		bool canReset = true;
+
+		if (ShmSysConfigAndInfo->SysWarningInfo.Level != _ALARM_LEVEL_CRITICAL)
+		{
+			for (byte _index = 0; _index < ShmSysConfigAndInfo->SysConfig.AcConnectorCount; _index++)
+			{
+				if (ac_chargingInfo[0]->SystemStatus >= SYS_MODE_MODE_REASSIGN_CHECK &&
+						ac_chargingInfo[0]->SystemStatus <= SYS_MODE_CHARGING)
+				{
+					// Reset - AC 先停止充電
+					ac_chargingInfo[0]->StopChargeFlag = YES;
+					GetTimespecFunc(&_resetChkTime);
+				}
+			}
+
+			for (byte _index = 0; _index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _index++)
+			{
+				if (chargingInfo[_index]->SystemStatus >= SYS_MODE_REASSIGN &&
+						chargingInfo[_index]->SystemStatus <= SYS_MODE_TERMINATING)
+				{
+					canReset = false;
+					// Reset 系統先停止充電
+					if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
+					{
+						if(strcmp((char *)ShmOCPP16Data->Reset.Type, "Hard") == EQUAL)
+							ocpp_set_stopReason_by_cmd(_index, "HardReset");
+						else
+							ocpp_set_stopReason_by_cmd(_index, "SoftReset");
+					}
+					else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
+					{
+						if(strcmp((char *)ShmOCPP20Data->Reset.type, "Immediate") == EQUAL)
+							ocpp_set_stopReason_by_cmd(_index, "HardReset");
+						else
+							ocpp_set_stopReason_by_cmd(_index, "SoftReset");
+					}
+
+					ChargingTerminalProcess(_index);
+					GetTimespecFunc(&_resetChkTime);
+				}
+			}
+		}
+
+		if (canReset)
+		{
+			if (GetTimeoutValue(&_resetChkTime) < 0)
+				GetTimespecFunc(&_resetChkTime);
+
+			if (GetTimeoutValue(&_resetChkTime) >= 5)
+			{
+				ShmDcCommonData->evBoardResetFlag = YES;
+				// Reset -> change status to maintain.
+				for (byte _index = 0; _index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _index++)
+				{
+					setChargerMode(_index, SYS_MODE_MAINTAIN);
+				}
+				ChangeLcmByIndex(_LCM_FIX);
+			}
+			else
+				canReset = false;
+		}
+		else
+			GetTimespecFunc(&_resetChkTime);
+
+		if (isforce == YES)
+			canReset = true;
+
+		ocpp_sub_run_reset(canReset);
+	}
+}
+
+void ocpp_chk_reserved_cmd(byte gunIndex)
+{
+	byte acDirIndex = 0;
+
+	// 如果有 AC 槍,則固定是第 2 把槍,所以索引固定為 1 (只會影響右槍所以考慮右槍狀況)
+	if (gunIndex == 1)
+		acDirIndex = ShmSysConfigAndInfo->SysConfig.AcConnectorCount;
+
+	if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
+	{
+		if (chargingInfo[gunIndex]->SystemStatus == SYS_MODE_IDLE &&
+				ShmOCPP16Data->CsMsg.bits[gunIndex + acDirIndex].ReserveNowReq == YES)
+		{
+			PRINTF_FUNC("***************ChkOcppStatus : OcppReservedStatus******************** \n");
+			ShmOCPP16Data->CsMsg.bits[gunIndex + acDirIndex].ReserveNowReq = NO;
+			if (!opcc_chk_reserve_expired(gunIndex))
+			{
+				PRINTF_FUNC("ReservationId = %d \n", ShmOCPP16Data->ReserveNow[gunIndex + acDirIndex].ReservationId);
+				PRINTF_FUNC("IdTag = %s \n", ShmOCPP16Data->ReserveNow[gunIndex + acDirIndex].IdTag);
+				PRINTF_FUNC("*************ChkOcppStatus : OcppReservedStatus End****************** \n");
+				chargingInfo[gunIndex]->ReservationId = ShmOCPP16Data->ReserveNow[gunIndex].ReservationId;
+				chargingInfo[gunIndex]->SystemStatus = SYS_MODE_RESERVATION;
+
+				strcpy((char *)ShmDcCommonData->_reserved_UserId[gunIndex],
+						(char *)ShmOCPP16Data->ReserveNow[gunIndex + acDirIndex].IdTag);
+			}
+			ShmOCPP16Data->CsMsg.bits[gunIndex + acDirIndex].ReserveNowConf = YES;
+		}
+
+		if (chargingInfo[gunIndex]->SystemStatus == SYS_MODE_RESERVATION &&
+				ShmOCPP16Data->CsMsg.bits[gunIndex + acDirIndex].CancelReservationReq == YES)
+		{
+			ShmOCPP16Data->CsMsg.bits[gunIndex + acDirIndex].CancelReservationReq = NO;
+			if (ShmOCPP16Data->ReserveNow[gunIndex + acDirIndex].ReservationId == chargingInfo[gunIndex]->ReservationId)
+			{
+				PRINTF_FUNC("***************ChkOcppStatus : OcppReservedStatus******************** \n");
+				PRINTF_FUNC("ReservationId = %d \n", ShmOCPP16Data->ReserveNow[gunIndex + acDirIndex].ReservationId);
+				PRINTF_FUNC("***********ChkOcppStatus : Cancel OcppReservedStatus End**************** \n");
+				chargingInfo[gunIndex]->ReservationId = -1;
+				chargingInfo[gunIndex]->SystemStatus = SYS_MODE_IDLE;
+
+				strcpy((char *)ShmDcCommonData->_reserved_UserId[gunIndex], "");
+				ShmOCPP16Data->CsMsg.bits[gunIndex + acDirIndex].CancelReservationConf = YES;
+			}
+		}
+	}
+	else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
+	{
+		if (chargingInfo[gunIndex]->SystemStatus == SYS_MODE_IDLE &&
+				ShmOCPP20Data->CsMsg.bits[gunIndex + acDirIndex].ReserveNowReq == YES)
+		{
+			PRINTF_FUNC("***************ChkOcppStatus : OcppReservedStatus******************** \n");
+			ShmOCPP20Data->CsMsg.bits[gunIndex + acDirIndex].ReserveNowReq = NO;
+			if (!opcc_chk_reserve_expired(gunIndex))
+			{
+				PRINTF_FUNC("id = %d \n", ShmOCPP20Data->ReserveNow[gunIndex + acDirIndex].id);
+				PRINTF_FUNC("idToken = %s \n", ShmOCPP20Data->ReserveNow[gunIndex + acDirIndex].idToken.idToken);
+				PRINTF_FUNC("*************ChkOcppStatus : OcppReservedStatus End****************** \n");
+				chargingInfo[gunIndex]->ReservationId = ShmOCPP20Data->ReserveNow[gunIndex].id;
+				chargingInfo[gunIndex]->SystemStatus = SYS_MODE_RESERVATION;
+
+				strncpy((char *)ShmDcCommonData->_reserved_UserId[gunIndex],
+					(char *)ShmOCPP20Data->ReserveNow[gunIndex + acDirIndex].idToken.idToken, 30);
+			}
+			ShmOCPP20Data->CsMsg.bits[gunIndex + acDirIndex].ReserveNowConf = YES;
+		}
+
+		if (chargingInfo[gunIndex]->SystemStatus == SYS_MODE_RESERVATION &&
+				ShmOCPP20Data->CsMsg.bits[gunIndex + acDirIndex].CancelReservationReq == YES)
+		{
+			ShmOCPP20Data->CsMsg.bits[gunIndex + acDirIndex].CancelReservationReq = NO;
+			if (ShmOCPP20Data->ReserveNow[gunIndex + acDirIndex].id == chargingInfo[gunIndex]->ReservationId)
+			{
+				PRINTF_FUNC("***************ChkOcppStatus : OcppReservedStatus******************** \n");
+				PRINTF_FUNC("ReservationId = %d \n", ShmOCPP20Data->ReserveNow[gunIndex + acDirIndex].id);
+				PRINTF_FUNC("***********ChkOcppStatus : Cancel OcppReservedStatus End**************** \n");
+				chargingInfo[gunIndex]->ReservationId = -1;
+				chargingInfo[gunIndex]->SystemStatus = SYS_MODE_IDLE;
+
+				strcpy((char *)ShmDcCommonData->_reserved_UserId[gunIndex], "");
+				ShmOCPP20Data->CsMsg.bits[gunIndex + acDirIndex].CancelReservationConf = YES;
+			}
+		}
+	}
+}
+
+void ocpp_chk_availability_cmd(byte gunIndex)
+{
+	byte type = 0; // 0 : none, 1 : operative, 2 inoperative
+	byte acDirIndex = 0;
+
+	// 如果有 AC 槍,則固定是第 2 把槍,所以索引固定為 1 (只會影響右槍所以考慮右槍狀況)
+	if (gunIndex == 1)
+		acDirIndex = ShmSysConfigAndInfo->SysConfig.AcConnectorCount;
+
+	if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
+	{
+		if (ShmOCPP16Data->CsMsg.bits[gunIndex + acDirIndex].ChangeAvailabilityReq == YES)
+		{
+			PRINTF_FUNC("***************ChkOcppStatus : OcppChangeAvailability******************** \n");
+			DEBUG_ERROR_MSG("***************ChkOcppStatus : OcppChangeAvailability******************** \n");
+			ShmOCPP16Data->CsMsg.bits[gunIndex + acDirIndex].ChangeAvailabilityReq = NO;
+			if(strcmp((char *)ShmOCPP16Data->ChangeAvailability[gunIndex + acDirIndex].Type, "Operative") == EQUAL)
+			{
+				if (isDb_ready)
+					DB_Update_Operactive(localDb, gunIndex + acDirIndex, true);
+
+				type = 1;
+			}
+			else if (strcmp((char *)ShmOCPP16Data->ChangeAvailability[gunIndex + acDirIndex].Type, "Inoperative") == EQUAL)
+			{
+				if (isDb_ready)
+					DB_Update_Operactive(localDb, gunIndex + acDirIndex, false);
+
+				type = 2;
+			}
+		}
+	}
+	else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
+	{
+		if (ShmOCPP20Data->CsMsg.bits[gunIndex + acDirIndex].ChangeAvailabilityReq == YES)
+		{
+			PRINTF_FUNC("***************ChkOcppStatus : OcppChangeAvailability******************** \n");
+			DEBUG_ERROR_MSG("***************ChkOcppStatus : OcppChangeAvailability******************** \n");
+			ShmOCPP20Data->CsMsg.bits[gunIndex + acDirIndex].ChangeAvailabilityReq = NO;
+			if(strcmp((char *)ShmOCPP20Data->ChangeAvailability[gunIndex + acDirIndex].operationalStatus, "Operative") == EQUAL)
+			{
+				if (isDb_ready)
+					DB_Update_Operactive(localDb, gunIndex + acDirIndex, true);
+
+				type = 1;
+			}
+			else if (strcmp((char *)ShmOCPP20Data->ChangeAvailability[gunIndex + acDirIndex].operationalStatus, "Inoperative") == EQUAL)
+			{
+				if (isDb_ready)
+					DB_Update_Operactive(localDb, gunIndex + acDirIndex, false);
+
+				type = 2;
+			}
+		}
+	}
+
+	if (type == 1)
+	{
+		chargingInfo[gunIndex]->IsAvailable = YES;
+		if (chargingInfo[gunIndex]->SystemStatus == SYS_MODE_IDLE ||
+			chargingInfo[gunIndex]->SystemStatus == SYS_MODE_RESERVATION ||
+			chargingInfo[gunIndex]->SystemStatus == SYS_MODE_MAINTAIN)
+		{
+			setChargerMode(gunIndex, SYS_MODE_IDLE);
+		}
+	}
+	else if (type == 2)
+	{
+		chargingInfo[gunIndex]->IsAvailable = NO;
+		if (chargingInfo[gunIndex]->SystemStatus == SYS_MODE_IDLE ||
+			chargingInfo[gunIndex]->SystemStatus == SYS_MODE_RESERVATION ||
+			chargingInfo[gunIndex]->SystemStatus == SYS_MODE_MAINTAIN)
+		{
+			setChargerMode(gunIndex, SYS_MODE_MAINTAIN);
+		}
+	}
+}
+
+void ocpp_chk_unlock_cmd(byte gunIndex)
+{
+	byte acDirIndex = 0;
+
+	// 如果有 AC 槍,則固定是第 2 把槍,所以索引固定為 1 (只會影響右槍所以考慮右槍狀況)
+	if (gunIndex == 1)
+		acDirIndex = ShmSysConfigAndInfo->SysConfig.AcConnectorCount;
+
+	if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
+	{
+		if (ShmOCPP16Data->CsMsg.bits[gunIndex + acDirIndex].UnlockConnectorReq == YES)
+		{
+			ShmOCPP16Data->CsMsg.bits[gunIndex + acDirIndex].UnlockConnectorReq = NO;
+			if ((chargingInfo[gunIndex]->SystemStatus >= SYS_MODE_MODE_REASSIGN_CHECK &&
+					chargingInfo[gunIndex]->SystemStatus <= SYS_MODE_CHARGING) ||
+					(chargingInfo[gunIndex]->SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0 &&
+					chargingInfo[gunIndex]->SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))
+			{
+				// Unlocked - 充電中,需停止充電
+				strcpy((char *)ShmOCPP16Data->StopTransaction[gunIndex + acDirIndex].StopReason, "UnlockCommand");
+				ChargingTerminalProcess(gunIndex);
+			}
+			if (chargingInfo[gunIndex]->Type == _Type_Chademo ||
+					chargingInfo[gunIndex]->Type == _Type_GB)
+				strcpy((char *)ShmOCPP16Data->UnlockConnector[gunIndex + acDirIndex].ResponseStatus, "Unlocked");
+			else
+				strcpy((char *)ShmOCPP16Data->UnlockConnector[gunIndex + acDirIndex].ResponseStatus, "Unlocked");
+			ShmOCPP16Data->CsMsg.bits[gunIndex + acDirIndex].UnlockConnectorConf = YES;
+		}
+	}
+	else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
+	{
+		if (ShmOCPP20Data->CsMsg.bits[gunIndex + acDirIndex].UnlockConnectorReq == YES)
+		{
+			ShmOCPP20Data->CsMsg.bits[gunIndex + acDirIndex].UnlockConnectorReq = NO;
+			if ((chargingInfo[gunIndex]->SystemStatus >= SYS_MODE_MODE_REASSIGN_CHECK &&
+					chargingInfo[gunIndex]->SystemStatus <= SYS_MODE_CHARGING) ||
+					(chargingInfo[gunIndex]->SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0 &&
+					chargingInfo[gunIndex]->SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))
+			{
+				// Unlocked - 充電中,需停止充電
+				strcpy((char *)ShmOCPP20Data->TransactionEvent[gunIndex + acDirIndex].transactionInfo.stoppedReason, "UnlockCommand");
+				ChargingTerminalProcess(gunIndex);
+			}
+			if (chargingInfo[gunIndex]->Type == _Type_Chademo ||
+					chargingInfo[gunIndex]->Type == _Type_GB)
+				strcpy((char*)ShmOCPP20Data->UnlockConnector[gunIndex + acDirIndex].Response_status, "Unlocked");
+			else
+				strcpy((char *)ShmOCPP16Data->UnlockConnector[gunIndex + acDirIndex].ResponseStatus, "Unlocked");
+			ShmOCPP20Data->CsMsg.bits[gunIndex + acDirIndex].UnlockConnectorConf = YES;
+		}
+	}
+}
+
+bool ocpp_chk_remoteStop_cmd(byte gunIndex)
+{
+	bool result = false;
+	byte acDirIndex = 0;
+
+	// 如果有 AC 槍,則固定是第 2 把槍,所以索引固定為 1 (只會影響右槍所以考慮右槍狀況)
+	if (gunIndex == 1)
+		acDirIndex = ShmSysConfigAndInfo->SysConfig.AcConnectorCount;
+
+	if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
+		result = ShmOCPP16Data->CsMsg.bits[gunIndex + acDirIndex].RemoteStopTransactionReq;
+	else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
+		result = ShmOCPP20Data->CsMsg.bits[gunIndex + acDirIndex].RequestStopTransactionReq;
+
+	if (result)
+	{
+		DEBUG_INFO_MSG("Remote Stop by OCPP (%d) \n", gunIndex + acDirIndex);
+		if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
+		{
+			strcpy((char *)ShmOCPP16Data->StopTransaction[gunIndex + acDirIndex].StopReason, "Remote");
+			ShmOCPP16Data->CsMsg.bits[gunIndex + acDirIndex].RemoteStopTransactionReq = NO;
+		}
+		else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
+		{
+			strcpy((char *)ShmOCPP20Data->TransactionEvent[gunIndex + acDirIndex].transactionInfo.stoppedReason, "Remote");
+			ShmOCPP20Data->CsMsg.bits[gunIndex + acDirIndex].RequestStopTransactionReq = NO;
+		}
+	}
+
+	return result;
+}
+
+bool ocpp_sub_get_remote_start_transaction_req(byte gun_index)
+{
+	bool result = false;
+
+	if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
+	{
+		result = ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStartTransactionReq;
+	}
+	else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
+	{
+		result = ShmOCPP20Data->CsMsg.bits[gun_index].RequestStartTransactionReq;
+	}
+
+	if (result && ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
+	{
+		strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,
+				(char *)ShmOCPP16Data->RemoteStartTransaction[gun_index].IdTag);
+	}
+
+	return result;
+}
+
+void ocpp_sub_set_remote_start_transaction_req(byte gunIndex, bool result)
+{
+	if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
+		ShmOCPP16Data->CsMsg.bits[gunIndex].RemoteStartTransactionReq = result;
+	else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
+		ShmOCPP20Data->CsMsg.bits[gunIndex].RequestStartTransactionReq = result;
+}
+
+void ocpp_chk_remoteStart_cmd()
+{
+	if(!isDetectPlugin())
+	{
+		// 如果有 AC 槍,則固定是第 2 把槍,所以索引固定為 1
+		byte acDirIndex = ShmSysConfigAndInfo->SysConfig.AcConnectorCount;
+
+		for (byte ac_index = 0; ac_index < ShmSysConfigAndInfo->SysConfig.AcConnectorCount; ac_index++)
+		{
+			if (ocpp_sub_get_remote_start_transaction_req(acDirIndex))
+			{
+				if (ac_chargingInfo[ac_index]->SystemStatus == SYS_MODE_IDLE ||
+						ac_chargingInfo[ac_index]->SystemStatus == SYS_MODE_RESERVATION)
+				{
+					ac_chargingInfo[ac_index]->RemoteStartFlag = YES;
+					ShmSysConfigAndInfo->SysInfo.OrderCharging = YES;
+					ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc = DEFAULT_AC_INDEX;
+					//ShmSysConfigAndInfo->SysInfo.OrderCharging = DEFAULT_AC_INDEX;
+					//ShmOCPP16Data->CsMsg.bits[ShmSysConfigAndInfo->SysConfig.TotalConnectorCount + ac_index].RemoteStartTransactionReq = NO;
+					DetectPluginStart();
+					return;
+				}
+				ocpp_sub_set_remote_start_transaction_req(acDirIndex, NO);
+			}
+		}
+
+		byte threeGunIndex = 0;
+		byte dcIndex = 0;
+		bool isGunUsingStatus = false;
+		byte scheduleIndex = 0;
+
+		for (byte _index = 0; _index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _index++)
+		{
+			// 如果有 AC 槍,且 DC 槍也有兩把
+			if (acDirIndex == 1 && _index == 1)
+				threeGunIndex = 1;
+
+			if (ocpp_sub_get_remote_start_transaction_req(_index + threeGunIndex))
+				dcIndex = _index;
+
+			if (chargingInfo[_index]->SystemStatus != SYS_MODE_IDLE)
+			{
+				isGunUsingStatus = true;
+			}
+
+			if (chargingInfo[_index]->schedule.isTriggerStart)
+				scheduleIndex = _index;
+		}
+
+		// 如果是雙槍單模,只認閒置狀態的槍,如果有預約~ 則預約也算被使用
+		if (isGunUsingStatus && ShmSysConfigAndInfo->SysInfo.IsAlternatvieConf)
+		{
+			if (dcIndex == 0)
+				threeGunIndex = 0;
+
+			//ocpp_sub_set_remote_start_transaction_req(dcIndex + threeGunIndex, NO);
+			return;
+		}
+
+		if (dcIndex == 0)
+			threeGunIndex = 0;
+
+		if (ocpp_sub_get_remote_start_transaction_req(dcIndex + threeGunIndex))
+		{
+			if (chargingInfo[dcIndex]->SystemStatus == SYS_MODE_IDLE ||
+					chargingInfo[dcIndex]->SystemStatus == SYS_MODE_RESERVATION)
+			{
+				if (ocpp_authorizeRemoteTxReqChk_key())
+				{
+					strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId,
+							(char *)ShmOCPP16Data->RemoteStartTransaction[dcIndex + threeGunIndex].IdTag);
+				}
+				else
+				{
+					chargingInfo[dcIndex]->RemoteStartFlag = YES;
+					ShmSysConfigAndInfo->SysInfo.OrderCharging = YES;
+					ChangeGunSelectByIndex(dcIndex);
+					//ShmSysConfigAndInfo->SysInfo.OrderCharging = gun_index;
+					DetectPluginStart();
+				}
+			}
+			ocpp_sub_set_remote_start_transaction_req(dcIndex + threeGunIndex, NO);
+		}
+		else if (chargingInfo[scheduleIndex]->schedule.isTriggerStart)
+		{
+			if (chargingInfo[scheduleIndex]->SystemStatus == SYS_MODE_IDLE ||
+					chargingInfo[scheduleIndex]->SystemStatus == SYS_MODE_RESERVATION)
+			{
+				chargingInfo[scheduleIndex]->RemoteStartFlag = YES;
+				ShmSysConfigAndInfo->SysInfo.OrderCharging = YES;
+				DetectPluginStart();
+			}
+			chargingInfo[scheduleIndex]->schedule.isTriggerStart = NO;
+		}
+	}
+}
+
+bool ocpp_remote_start_wait_cmd()
+{
+	bool result = false;
+
+	if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
+	{
+		result = ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq;
+	}
+	else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
+	{
+		result = ShmOCPP20Data->MsMsg.bits.isRemoteStartWaitReq;
+	}
+
+	return result;
+}
+
+void ocpp_chk_update_cmd()
+{
+	if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
+	{
+		if(ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq == YES)
+		{
+			ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = NO;
+
+			if (strcmp((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "Downloaded") == EQUAL)
+			{
+				DEBUG_INFO_MSG("Backend : update start. \n");
+				sleep(2);
+				strcpy((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "");
+				strcpy((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "Installing");
+				ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = YES;
+
+				for (byte _index = 0; _index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _index++)
+				{
+					setChargerMode(_index, SYS_MODE_UPDATE);
+				}
+				for (byte _index = 0; _index < ShmSysConfigAndInfo->SysConfig.AcConnectorCount; _index++)
+				{
+					ac_chargingInfo[_index]->SystemStatus = SYS_MODE_UPDATE;
+				}
+
+				CloseWatchDog();
+				sleep(2);
+				KillTask();
+				byte updateResult = CheckUpdateProcess();
+
+				if (updateResult == PASS)
+				{
+					DEBUG_INFO_MSG("Backend : update complete. \n");
+					strcpy((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "Installed");
+				}
+				else if (updateResult == MODELNAME_FAIL)
+				{
+					DEBUG_INFO_MSG("Backend : model name is none match. \n");
+					strcpy((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "InstallationFailed");
+					ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = YES;
+					sleep(5);
+					KillAllTask();
+					system("/usr/bin/run_evse_restart.sh");
+					return;
+				}
+				else
+				{
+					DEBUG_INFO_MSG("Backend : update fail. \n");
+					strcpy((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "InstallationFailed");
+				}
+
+				strcpy((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "Installed");
+				ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = YES;
+				sleep(5);
+				system("reboot -f");
+			}
+		}
+	}
+	else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
+	{
+		if(ShmOCPP20Data->MsMsg.bits.UpdateFirmwareReq == YES)
+		{
+			ShmOCPP20Data->MsMsg.bits.UpdateFirmwareReq = NO;
+
+			if (strcmp((char *)ShmOCPP20Data->FirmwareStatusNotification.status, "Downloaded") == EQUAL)
+			{
+				DEBUG_INFO_MSG("Backend : update start. \n");
+				sleep(2);
+				strcpy((char *)ShmOCPP20Data->FirmwareStatusNotification.status, "");
+				strcpy((char *)ShmOCPP20Data->FirmwareStatusNotification.status, "Installing");
+				ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = YES;
+
+				for (byte _index = 0; _index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _index++)
+				{
+					setChargerMode(_index, SYS_MODE_UPDATE);
+				}
+				for (byte _index = 0; _index < ShmSysConfigAndInfo->SysConfig.AcConnectorCount; _index++)
+				{
+					ac_chargingInfo[_index]->SystemStatus = SYS_MODE_UPDATE;
+				}
+
+				CloseWatchDog();
+				sleep(2);
+				KillTask();
+				byte updateResult = CheckUpdateProcess();
+
+				if (updateResult == PASS)
+				{
+					DEBUG_INFO_MSG("Backend : update complete. \n");
+					strcpy((char *)ShmOCPP20Data->FirmwareStatusNotification.status, "Installed");
+				}
+				else if (updateResult == MODELNAME_FAIL)
+				{
+					DEBUG_INFO_MSG("Backend : model name is none match. \n");
+					strcpy((char *)ShmOCPP20Data->FirmwareStatusNotification.status, "InstallationFailed");
+					ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = YES;
+					sleep(5);
+					KillAllTask();
+					system("/usr/bin/run_evse_restart.sh");
+					return;
+				}
+				else
+				{
+					DEBUG_INFO_MSG("Backend : update fail. \n");
+					strcpy((char *)ShmOCPP20Data->FirmwareStatusNotification.status, "InstallationFailed");
+				}
+
+				strcpy((char *)ShmOCPP20Data->FirmwareStatusNotification.status, "Installed");
+				ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = YES;
+				sleep(5);
+				system("reboot -f");
+			}
+		}
+	}
+}
+
+bool ocpp_chk_invalid_id_cmd(byte gunIndex)
+{
+	byte acDirIndex = 0;
+
+	// 如果有 AC 槍,則固定是第 2 把槍,所以索引固定為 1 (只會影響右槍所以考慮右槍狀況)
+	if (gunIndex == 1)
+		acDirIndex = ShmSysConfigAndInfo->SysConfig.AcConnectorCount;
+
+	if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
+	{
+		if (strstr((char *) ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "TRUE"))
+		{
+			if (strcmp((char *)ShmOCPP16Data->StartTransaction[gunIndex + acDirIndex].ResponseIdTagInfo.Status, "Blocked") == EQUAL ||
+					strcmp((char *)ShmOCPP16Data->StartTransaction[gunIndex + acDirIndex].ResponseIdTagInfo.Status, "Expired") == EQUAL ||
+					strcmp((char *)ShmOCPP16Data->StartTransaction[gunIndex + acDirIndex].ResponseIdTagInfo.Status, "Invalid") == EQUAL)
+				return true;
+		}
+	}
+	else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
+	{
+		if (strstr((char *) ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnInvalidId].variableAttribute[0].value, "TRUE"))
+		{
+			if (strcmp((char *)ShmOCPP20Data->TransactionEvent[gunIndex + acDirIndex].Response_idTokenInfo.status, "Blocked") == EQUAL ||
+					strcmp((char *)ShmOCPP20Data->TransactionEvent[gunIndex + acDirIndex].Response_idTokenInfo.status, "Expired") == EQUAL ||
+					strcmp((char *)ShmOCPP20Data->TransactionEvent[gunIndex + acDirIndex].Response_idTokenInfo.status, "Invalid") == EQUAL ||
+					strcmp((char *)ShmOCPP20Data->TransactionEvent[gunIndex + acDirIndex].Response_idTokenInfo.status, "NoCredit") == EQUAL ||
+					strcmp((char *)ShmOCPP20Data->TransactionEvent[gunIndex + acDirIndex].Response_idTokenInfo.status, "NotAllowedTypeEVSE") == EQUAL ||
+					strcmp((char *)ShmOCPP20Data->TransactionEvent[gunIndex + acDirIndex].Response_idTokenInfo.status, "NotAtThisLocation") == EQUAL ||
+					strcmp((char *)ShmOCPP20Data->TransactionEvent[gunIndex + acDirIndex].Response_idTokenInfo.status, "NotAtThisTime") == EQUAL ||
+					strcmp((char *)ShmOCPP20Data->TransactionEvent[gunIndex + acDirIndex].Response_idTokenInfo.status, "Unknown") == EQUAL)
+				return true;
+		}
+	}
+
+	return false;
+}
+
+bool ocpp_chk_profileConf_cmd(byte gunIndex)
+{
+	byte acDirIndex = 0;
+
+	// 如果有 AC 槍,則固定是第 2 把槍,所以索引固定為 1 (只會影響右槍所以考慮右槍狀況)
+	if (gunIndex == 1)
+		acDirIndex = ShmSysConfigAndInfo->SysConfig.AcConnectorCount;
+
+	if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
+	{
+		if (ShmOCPP16Data->CSUMsg.bits[gunIndex + acDirIndex].ChargingProfileConf == YES)
+		{
+			ShmOCPP16Data->CSUMsg.bits[gunIndex + acDirIndex].ChargingProfileConf = NO;
+			return true;
+		}
+	}
+	else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
+	{
+		if (ShmOCPP20Data->CSUMsg.bits[gunIndex + acDirIndex].ChargingProfileConf == YES)
+		{
+			ShmOCPP20Data->CSUMsg.bits[gunIndex + acDirIndex].ChargingProfileConf = NO;
+			return true;
+		}
+	}
+
+	return false;
+}
+
+void ocpp_chk_notificationMessage_cmd(byte gunIndex)
+{
+	byte acDirIndex = 0;
+
+	// 如果有 AC 槍,則固定是第 2 把槍,所以索引固定為 1 (只會影響右槍所以考慮右槍狀況)
+	if (gunIndex == 1)
+		acDirIndex = ShmSysConfigAndInfo->SysConfig.AcConnectorCount;
+
+	if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
+	{
+		if (ShmOCPP16Data->CsMsg.bits[gunIndex + acDirIndex].TriggerMessageReq == YES)
+		{
+			if (chargingInfo[gunIndex]->Type == _Type_Chademo &&
+					(chargingInfo[gunIndex]->SystemStatus == SYS_MODE_IDLE ||
+						chargingInfo[gunIndex]->SystemStatus ==SYS_MODE_RESERVATION ||
+						chargingInfo[gunIndex]->SystemStatus ==SYS_MODE_MAINTAIN))
+			{
+				if (ShmDcCommonData->_cha_try_communication[gunIndex].try2CommunicationFlag == NO)
+				{
+					PRINTF_FUNC("Trigger msg (StatusNotification) = %d (chademo) \n", gunIndex);
+					ShmDcCommonData->_cha_try_communication[gunIndex].elapsedTime = 0;
+					GetTimespecFunc(&ShmDcCommonData->_cha_try_communication[gunIndex].detectTimer);
+					ShmDcCommonData->_cha_try_communication[gunIndex].try2CommunicationFlag = YES;
+				}
+			}
+			else if (chargingInfo[gunIndex]->Type == _Type_CCS ||
+					chargingInfo[gunIndex]->Type == _Type_GB ||
+					chargingInfo[gunIndex]->Type == _Type_AC)
+			{
+				PRINTF_FUNC("Trigger msg (StatusNotification) = %d (ccs) \n", gunIndex);
+			}
+			ShmOCPP16Data->CsMsg.bits[gunIndex + acDirIndex].TriggerMessageReq = NO;
+		}
+	}
+	else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
+	{
+
+	}
+
+	if (ShmDcCommonData->_cha_try_communication[gunIndex].try2CommunicationFlag)
+	{
+		int _timeBuf = GetTimeoutValue(&ShmDcCommonData->_cha_try_communication[gunIndex].detectTimer);
+
+		if (_timeBuf < 0)
+		{
+			ShmDcCommonData->_cha_try_communication[gunIndex].elapsedTime = 0;
+			GetTimespecFunc(&ShmDcCommonData->_cha_try_communication[gunIndex].detectTimer);
+		}
+
+		if (_timeBuf > 30 ||
+				(_timeBuf > 2 &&
+				chargingInfo[gunIndex]->ConnectorPlugIn))
+		{
+			PRINTF_FUNC("Trigger msg - timeout or Plugin. \n");
+			ShmDcCommonData->_cha_try_communication[gunIndex].try2CommunicationFlag = NO;
+		}
+		else
+			ShmDcCommonData->_cha_try_communication[gunIndex].elapsedTime = (_timeBuf / uSEC_VAL);
+	}
+}
+
+void ocpp_lift_profileReq_cmd(byte gunIndex)
+{
+	byte acDirIndex = 0;
+
+	// 如果有 AC 槍,則固定是第 2 把槍,所以索引固定為 1 (只會影響右槍所以考慮右槍狀況)
+	if (gunIndex == 1)
+		acDirIndex = ShmSysConfigAndInfo->SysConfig.AcConnectorCount;
+
+	if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
+	{
+		if (ShmOCPP16Data->CSUMsg.bits[gunIndex + acDirIndex].ChargingProfileConf == NO)
+		{
+			if (ShmOCPP16Data->CSUMsg.bits[gunIndex + acDirIndex].ChargingProfileReq == NO)
+				ShmOCPP16Data->CSUMsg.bits[gunIndex + acDirIndex].ChargingProfileReq = YES;
+		}
+	}
+	else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
+	{
+		if (ShmOCPP20Data->CSUMsg.bits[gunIndex + acDirIndex].ChargingProfileConf == NO)
+		{
+			if (ShmOCPP20Data->CSUMsg.bits[gunIndex + acDirIndex].ChargingProfileReq == NO)
+				ShmOCPP20Data->CSUMsg.bits[gunIndex + acDirIndex].ChargingProfileReq = YES;
+		}
+	}
+}
+
+void ocpp_set_startTransation_cmd(byte gunIndex)
+{
+	byte _OcppGunIndex = gunIndex;
+
+	// 如果有 AC 槍,而現在是 DC 第二把槍進入充電
+	if (ShmSysConfigAndInfo->SysConfig.AcConnectorCount == 1 && gunIndex == 1)
+		_OcppGunIndex = 2;
+
+	if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
+	{
+		if(strcmp((char *)chargingInfo[gunIndex]->StartUserId, "") == EQUAL)
+			strcpy((char *)chargingInfo[gunIndex]->StartUserId, (char *)ShmOCPP16Data->StartTransaction[_OcppGunIndex].IdTag);
+		else
+			strcpy((char *)ShmOCPP16Data->StartTransaction[_OcppGunIndex].IdTag, (char *)chargingInfo[gunIndex]->StartUserId);
+
+		if (strcmp((char *)ShmOCPP16Data->StartTransaction[_OcppGunIndex].IdTag, "") == EQUAL)
+			strcpy((char *)ShmOCPP16Data->StartTransaction[_OcppGunIndex].IdTag, (char *)chargingInfo[gunIndex]->StartUserId);
+
+		PRINTF_FUNC("IdTag = %s \n", chargingInfo[gunIndex]->StartUserId);
+		ShmOCPP16Data->CpMsg.bits[_OcppGunIndex].StartTransactionReq = YES;
+	}
+	else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
+	{
+		if(strcmp((char *)chargingInfo[gunIndex]->StartUserId, "") == EQUAL)
+			strcpy((char *)ShmOCPP20Data->TransactionEvent[_OcppGunIndex].idToken.idToken, (char *)ShmOCPP20Data->TransactionEvent[_OcppGunIndex].idToken.idToken);
+		else
+			strcpy((char *)ShmOCPP20Data->TransactionEvent[_OcppGunIndex].idToken.idToken, (char *)chargingInfo[gunIndex]->StartUserId);
+
+		PRINTF_FUNC("IdTag = %s \n", ShmOCPP20Data->TransactionEvent[_OcppGunIndex].idToken.idToken);
+		ShmOCPP20Data->CpMsg.bits[_OcppGunIndex].TransactionEventReq = YES;
+	}
+}
+
+void ocpp_set_stopTransation_cmd(byte gunIndex)
+{
+	byte _OcppGunIndex = gunIndex;
+
+	// 如果有 AC 槍,而現在是 DC 第二把槍進入充電
+	if (ShmSysConfigAndInfo->SysConfig.AcConnectorCount == 1 && gunIndex == 1)
+		_OcppGunIndex = 2;
+
+	if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
+	{
+		if(strcmp((char *)chargingInfo[gunIndex]->StartUserId, "") == EQUAL)
+			strcpy((char *)ShmOCPP16Data->StopTransaction[_OcppGunIndex].IdTag, (char *)ShmOCPP16Data->StopTransaction[_OcppGunIndex].IdTag);
+		else
+			strcpy((char *)ShmOCPP16Data->StopTransaction[_OcppGunIndex].IdTag, (char *)chargingInfo[gunIndex]->StartUserId);
+
+		PRINTF_FUNC("IdTag = %s \n", ShmOCPP16Data->StopTransaction[_OcppGunIndex].IdTag);
+		ShmOCPP16Data->CpMsg.bits[_OcppGunIndex].StopTransactionReq = YES;
+	}
+	else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
+	{
+		if(strcmp((char *)chargingInfo[gunIndex]->StartUserId, "") == EQUAL)
+			strcpy((char *)ShmOCPP20Data->TransactionEvent[_OcppGunIndex].idToken.idToken, (char *)ShmOCPP20Data->TransactionEvent[_OcppGunIndex].idToken.idToken);
+		else
+			strcpy((char *)ShmOCPP20Data->TransactionEvent[_OcppGunIndex].idToken.idToken, (char *)chargingInfo[gunIndex]->StartUserId);
+
+		PRINTF_FUNC("IdTag = %s \n", ShmOCPP20Data->TransactionEvent[_OcppGunIndex].idToken.idToken);
+		ShmOCPP20Data->CpMsg.bits[_OcppGunIndex].TransactionEventReq = YES;
+	}
+}
+
+void ocpp_set_noErrorCode_cmd(byte gunIndex, char *errString)
+{
+	// 參數 gunIndex 已包含 AC 槍
+	if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
+		strcpy((char *)ShmOCPP16Data->StatusNotification[gunIndex].ErrorCode, errString);
+	else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
+	{
+
+	}
+}
+
+void ocpp_set_stopReason_by_cmd(byte gunIndex, char *reason)
+{
+	byte acDirIndex = 0;
+
+	// 如果有 AC 槍,則固定是第 2 把槍,所以索引固定為 1 (只會影響右槍所以考慮右槍狀況)
+	if (gunIndex == 1)
+		acDirIndex = ShmSysConfigAndInfo->SysConfig.AcConnectorCount;
+
+	if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
+	{
+		if (strcmp((char *)ShmOCPP16Data->StopTransaction[gunIndex + acDirIndex].StopReason, "") == EQUAL)
+		{
+			strcpy((char *)ShmOCPP16Data->StopTransaction[gunIndex + acDirIndex].StopReason, reason);
+		}
+	}
+	else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
+	{
+		if (strcmp((char *)ShmOCPP20Data->TransactionEvent[gunIndex + acDirIndex].transactionInfo.stoppedReason, "") == EQUAL)
+		{
+			strcpy((char *)ShmOCPP20Data->TransactionEvent[gunIndex + acDirIndex].transactionInfo.stoppedReason, reason);
+		}
+	}
+}
+
+void ocpp_set_authorizeReq_cmd(byte value)
+{
+	if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
+		ShmOCPP16Data->SpMsg.bits.AuthorizeReq = value;
+	else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
+		ShmOCPP20Data->SpMsg.bits.AuthorizeReq = value;
+}
+
+void ocpp_set_authorizeConf_cmd(byte value)
+{
+	if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
+		ShmOCPP16Data->SpMsg.bits.AuthorizeConf = value;
+	else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
+		ShmOCPP20Data->SpMsg.bits.AuthorizeConf = value;
+}
+
+void ocpp_set_errCode_cmd(byte gunIndex)
+{
+	byte acDirIndex = 0;
+
+	// 如果有 AC 槍,則固定是第 2 把槍,所以索引固定為 1 (只會影響右槍所以考慮右槍狀況)
+	if (gunIndex == 1)
+		acDirIndex = ShmSysConfigAndInfo->SysConfig.AcConnectorCount;
+
+	if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
+	{
+		if (strcmp((char *)chargingInfo[gunIndex]->ConnectorAlarmCode, "") != EQUAL)
+		{
+			strcpy((char *)ShmOCPP16Data->StatusNotification[gunIndex + acDirIndex].ErrorCode, "InternalError");
+			strcpy((char *)ShmOCPP16Data->StatusNotification[gunIndex + acDirIndex].VendorErrorCode, (char *)chargingInfo[gunIndex]->ConnectorAlarmCode);
+		}
+		else if (strcmp((char *)chargingInfo[gunIndex]->EvConnAlarmCode, "") != EQUAL)
+		{
+			strcpy((char *)ShmOCPP16Data->StatusNotification[gunIndex + acDirIndex].ErrorCode, "OtherError");
+			strcpy((char *)ShmOCPP16Data->StatusNotification[gunIndex + acDirIndex].VendorErrorCode, (char *)chargingInfo[gunIndex]->EvConnAlarmCode);
+		}
+		else
+		{
+			strcpy((char *)ShmOCPP16Data->StatusNotification[gunIndex + acDirIndex].ErrorCode, "NoError");
+			strcpy((char *)ShmOCPP16Data->StatusNotification[gunIndex + acDirIndex].VendorErrorCode, "");
+		}
+	}
+	else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
+	{
+
+	}
+}
+
+void ocpp_clear_errorCode_cmd(byte gunIndex)
+{
+	byte acDirIndex = 0;
+
+	// 如果有 AC 槍,則固定是第 2 把槍,所以索引固定為 1 (只會影響右槍所以考慮右槍狀況)
+	if (gunIndex == 1)
+		acDirIndex = ShmSysConfigAndInfo->SysConfig.AcConnectorCount;
+
+	if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
+	{
+		if (strcmp((char *)ShmOCPP16Data->StatusNotification[gunIndex + acDirIndex].ErrorCode, "NoError") != EQUAL)
+			strcpy((char *)ShmOCPP16Data->StatusNotification[gunIndex + acDirIndex].ErrorCode, "NoError");
+
+		if (strcmp((char *)ShmOCPP16Data->StatusNotification[gunIndex + acDirIndex].VendorErrorCode, "") != EQUAL)
+			strcpy((char *)ShmOCPP16Data->StatusNotification[gunIndex + acDirIndex].VendorErrorCode, "");
+	}
+	else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
+	{
+
+	}
+}
+
+void ocpp_clear_idTag_cmd(byte gun_index)
+{
+	byte acDirIndex = 0;
+
+	// 如果有 AC 槍,則固定是第 2 把槍,所以索引固定為 1 (只會影響右槍所以考慮右槍狀況)
+	if (gun_index == 1)
+		acDirIndex = ShmSysConfigAndInfo->SysConfig.AcConnectorCount;
+
+	if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
+		strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index + acDirIndex].ResponseIdTagInfo.Status, "");
+	else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
+		strcpy((char *)ShmOCPP20Data->TransactionEvent[gun_index + acDirIndex].Response_idTokenInfo.status, "");
+}
+
+void ocpp_clear_stopReason(byte gun_index)
+{
+	byte acDirIndex = 0;
+
+	// 如果有 AC 槍,則固定是第 2 把槍,所以索引固定為 1 (只會影響右槍所以考慮右槍狀況)
+	if (gun_index == 1)
+		acDirIndex = ShmSysConfigAndInfo->SysConfig.AcConnectorCount;
+
+	if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
+		strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index + acDirIndex].StopReason, "");
+	else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
+		strcpy((char *)ShmOCPP20Data->TransactionEvent[gun_index + acDirIndex].transactionInfo.stoppedReason, "");
+}
+
+unsigned short _ocpp_get_connect_timeout()
+{
+	uint16_t result = (TIMEOUT_SPEC_HANDSHAKING / 1000);
+
+	if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
+	{
+		if(strcmp((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData,"") != 0)
+			result = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
+	}
+
+	else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
+	{
+		if(strcmp((char *)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variableAttribute[0].value,"") != 0)
+			result = atoi((char *)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variableAttribute[0].value);
+	}
+
+	return result;
+}
+
+bool ocpp_get_authorize_conf()
+{
+	if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
+		return ShmOCPP16Data->SpMsg.bits.AuthorizeConf;
+	else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
+		return ShmOCPP20Data->SpMsg.bits.AuthorizeConf;
+
+	return false;
+}
+
+bool ocpp_get_startTransation_req(byte gunIndex)
+{
+	bool result = false;
+	byte acDirIndex = 0;
+
+	// 如果有 AC 槍,則固定是第 2 把槍,所以索引固定為 1 (只會影響右槍所以考慮右槍狀況)
+	if (gunIndex == 1)
+		acDirIndex = ShmSysConfigAndInfo->SysConfig.AcConnectorCount;
+
+	// 如果有 AC 槍,而現在是 DC 第二把槍進入充電
+	if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
+	{
+		result = ShmOCPP16Data->CpMsg.bits[gunIndex + acDirIndex].StartTransactionReq;
+	}
+	else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
+	{
+		result = ShmOCPP20Data->CpMsg.bits[gunIndex + acDirIndex].TransactionEventReq;
+	}
+
+	return result;
+}
+
+void ocpp_get_freeVendor(byte gunIndex)
+{
+	byte _OcppGunIndex = gunIndex;
+
+	// 如果有 AC 槍,而現在是 DC 第二把槍進入充電
+	if (ShmSysConfigAndInfo->SysConfig.AcConnectorCount == 1 && gunIndex == 1)
+		_OcppGunIndex = 2;
+
+	if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
+	{
+		strcpy((char *)ShmOCPP16Data->StartTransaction[_OcppGunIndex].IdTag, "");
+
+		if (strlen((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData) > 0)
+		{
+			strcpy((char *)ShmOCPP16Data->StartTransaction[_OcppGunIndex].IdTag,
+					(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
+		}
+		else
+		{
+			strcpy((char *)ShmOCPP16Data->StartTransaction[_OcppGunIndex].IdTag,
+						(char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
+		}
+	}
+	else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
+	{
+		if (strlen((char *)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVendIdtag].variableAttribute[0].value) > 0)
+		{
+		}
+		else
+		{
+		}
+	}
+}
+
+void ocpp_parsing_DT_defaultPrice_cmd()
+{
+	if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
+	{
+		if(strcmp(MyDefaultPriceString, (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData) != EQUAL)
+		{
+			DefaultPriceHandlerOcpp16((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
+
+		    memcpy(MyDefaultPriceString, ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, 128);
+		}
+	}
+	else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
+	{
+		//ShmOCPP20Data->CostUpdated
+	}
+}
+
+void ocpp_parsing_DT_userPrice_cmd()
+{
+	if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
+	{
+		if (strlen((char *)ShmOCPP16Data->Cost.SetUserPrice.idToken) > 0 &&
+				strlen((char *)ShmOCPP16Data->Cost.SetUserPrice.price) > 0)
+		{
+			UserPriceHandlerOcpp16((char *)ShmOCPP16Data->Cost.SetUserPrice.idToken,
+					(char *)ShmOCPP16Data->Cost.SetUserPrice.price);
+
+			//memset(&ShmOCPP16Data->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
+		}
+	}
+	else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
+	{
+		//ShmOCPP20Data->CostUpdated
+	}
+}
+
+void ocpp_parsing_DT_running_final_cmd()
+{
+	if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
+	{
+		RunningFinalCostHandlerOcpp16();
+	}
+	else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
+	{
+		//ShmOCPP20Data->CostUpdated
+	}
+}
+
+void ocpp_chargingProfile_process(byte _index)
+{
+	int _time = 0;
+	int _startCount = NO_DEFINE;
+	int _maxCount = 0;
+	byte acDirIndex = 0;
+
+	// 如果有 AC 槍,則固定是第 2 把槍,所以索引固定為 1 (只會影響右槍所以考慮右槍狀況)
+	if (_index == 1)
+		acDirIndex = ShmSysConfigAndInfo->SysConfig.AcConnectorCount;
+
+	if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
+	{
+		if (strcmp((char *)ShmOCPP16Data->SmartChargingProfile[_index + acDirIndex].ChargingProfileKind, "Absolute") == EQUAL &&
+				ShmOCPP16Data->SmartChargingProfile[_index + acDirIndex].ChargingProfileId == YES)
+		{
+			_time = GetStartScheduleTime(ShmOCPP16Data->SmartChargingProfile[_index + acDirIndex].ChargingSchedule.StartSchedule);
+			if (_time > -1)
+			{
+				_maxCount = ARRAY_SIZE(ShmOCPP16Data->SmartChargingProfile[_index + acDirIndex].ChargingSchedule.ChargingSchedulePeriod);
+				_startCount = NO_DEFINE;
+
+				for (byte _count = 0; _count < _maxCount; _count++)
+				{
+					// 預設最小輸出電流 (MIN_OUTPUT_CUR) A
+					if (_time >= ShmOCPP16Data->SmartChargingProfile[_index + acDirIndex].ChargingSchedule.ChargingSchedulePeriod[_count].StartPeriod)
+					{
+						if ((_count == 0 && ShmOCPP16Data->SmartChargingProfile[_index + acDirIndex].ChargingSchedule.ChargingSchedulePeriod[_count].Limit >= MIN_OUTPUT_CUR) ||
+								ShmOCPP16Data->SmartChargingProfile[_index + acDirIndex].ChargingSchedule.ChargingSchedulePeriod[_count].Limit > MIN_OUTPUT_CUR)
+						{
+							_startCount = _count;
+						}
+					}
+				}
+
+				if (_startCount < _maxCount)
+				{
+					//PRINTF_FUNC("Gun_%d, Get Profile - Profile Index = %d \n", _index + acDirIndex, _startCount);
+					chargingInfo[_index]->ChargingProfilePower = ShmOCPP16Data->SmartChargingProfile[_index + acDirIndex].ChargingSchedule.ChargingSchedulePeriod[_startCount].Limit * AC_OUTPUT_VOL * ShmOCPP16Data->SmartChargingProfile[_index + acDirIndex].ChargingSchedule.ChargingSchedulePeriod[_startCount].NumberPhases;
+					if (chargingInfo[_index]->EvBatterytargetVoltage > 0 &&
+							chargingInfo[_index]->PresentChargingVoltage > 0)
+						chargingInfo[_index]->ChargingProfileCurrent = (chargingInfo[_index]->ChargingProfilePower / chargingInfo[_index]->PresentChargingVoltage) * 10;
+					else
+						chargingInfo[_index]->ChargingProfileCurrent = 0;
+				}
+				else
+				{
+					chargingInfo[_index]->ChargingProfilePower = -1;
+					chargingInfo[_index]->ChargingProfileCurrent = -1;
+				}
+			}
+			else
+			{
+				chargingInfo[_index]->ChargingProfilePower = -1;
+				chargingInfo[_index]->ChargingProfileCurrent = -1;
+			}
+		}
+		else
+		{
+			chargingInfo[_index]->ChargingProfilePower = -1;
+			chargingInfo[_index]->ChargingProfileCurrent = -1;
+		}
+
+		if (strcmp((char *)ShmOCPP16Data->MaxChargingProfile.ChargingProfileKind, "Absolute") == EQUAL &&
+				ShmOCPP16Data->MaxChargingProfile.ChargingProfileId == YES)
+		{
+			_time = GetStartScheduleTime(ShmOCPP16Data->MaxChargingProfile.ChargingSchedule.StartSchedule);
+			if (_time > -1)
+			{
+				_maxCount = ARRAY_SIZE(ShmOCPP16Data->MaxChargingProfile.ChargingSchedule.ChargingSchedulePeriod);
+				_startCount = NO_DEFINE;
+
+				for (byte _count = 0; _count < _maxCount; _count++)
+				{
+					if (_time >= ShmOCPP16Data->MaxChargingProfile.ChargingSchedule.ChargingSchedulePeriod[_count].StartPeriod)
+					{
+						if ((_count == 0 && ShmOCPP16Data->MaxChargingProfile.ChargingSchedule.ChargingSchedulePeriod[_count].Limit >= MIN_OUTPUT_CUR) ||
+								ShmOCPP16Data->MaxChargingProfile.ChargingSchedule.ChargingSchedulePeriod[_count].Limit > MIN_OUTPUT_CUR)
+						{
+							_startCount = _count;
+						}
+					}
+				}
+				//PRINTF_FUNC("_startCount = %d, Max Profile Limit = %f \n", _startCount, ShmOCPP16Data->MaxChargingProfile.ChargingSchedule.ChargingSchedulePeriod[_startCount].Limit);
+				if (_startCount < _maxCount)
+				{
+					float maxChargingProfilePow = ShmOCPP16Data->MaxChargingProfile.ChargingSchedule.ChargingSchedulePeriod[_startCount].Limit * AC_OUTPUT_VOL * ShmOCPP16Data->MaxChargingProfile.ChargingSchedule.ChargingSchedulePeriod[_startCount].NumberPhases;
+
+					if (ShmSysConfigAndInfo->SysInfo.MainChargingMode == _MAIN_CHARGING_MODE_AVER)
+						maxChargingProfilePow /= 2;
+
+					ShmSysConfigAndInfo->SysInfo.MaxChargingProfilePower = maxChargingProfilePow;
+				}
+				else
+					ShmSysConfigAndInfo->SysInfo.MaxChargingProfilePower = -1;
+			}
+		}
+		else
+			ShmSysConfigAndInfo->SysInfo.MaxChargingProfilePower = -1;
+	}
+	else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
+	{
+		if (strcmp((char *)ShmOCPP20Data->SmartChargingProfile[_index + acDirIndex].chargingProfileKind, "Absolute") == EQUAL &&
+				ShmOCPP20Data->SmartChargingProfile[_index + acDirIndex].id == YES)
+		{
+			_time = GetStartScheduleTime(ShmOCPP20Data->SmartChargingProfile[_index + acDirIndex].chargingSchedule[0].startSchedule);
+			_maxCount = ARRAY_SIZE(ShmOCPP20Data->SmartChargingProfile[_index + acDirIndex].chargingSchedule[0].chargingSchedulePeriod);
+			_startCount = NO_DEFINE;
+
+			for (byte _count = 0; _count < _maxCount; _count++)
+			{
+				// 預設最小輸出電流 (MIN_OUTPUT_CUR) A
+				if (_time >= ShmOCPP20Data->SmartChargingProfile[_index + acDirIndex].chargingSchedule[0].chargingSchedulePeriod[_count].startPeriod)
+				{
+					if ((_count == 0 && ShmOCPP20Data->SmartChargingProfile[_index + acDirIndex].chargingSchedule[0].chargingSchedulePeriod[_count].limit >= MIN_OUTPUT_CUR) ||
+							ShmOCPP20Data->SmartChargingProfile[_index + acDirIndex].chargingSchedule[0].chargingSchedulePeriod[_count].limit > MIN_OUTPUT_CUR)
+					{
+						_startCount = _count;
+					}
+				}
+			}
+
+			if (_startCount < _maxCount)
+			{
+				//PRINTF_FUNC("Gun_%d, Get Profile - Profile Index = %d \n", _index + acDirIndex, _startCount);
+				//PRINTF_FUNC("Profile Limit = %f \n", ShmOCPP20Data->SmartChargingProfile[_index + acDirIndex].chargingSchedule[0].chargingSchedulePeriod[_startCount].limit);
+				chargingInfo[_index]->ChargingProfilePower = ShmOCPP20Data->SmartChargingProfile[_index + acDirIndex].chargingSchedule[0].chargingSchedulePeriod[_startCount].limit * AC_OUTPUT_VOL;
+
+				if (chargingInfo[_index]->EvBatterytargetVoltage > 0 && chargingInfo[_index]->PresentChargingVoltage > 0)
+					chargingInfo[_index]->ChargingProfileCurrent = (chargingInfo[_index]->ChargingProfilePower / chargingInfo[_index]->PresentChargingVoltage) * 10;
+				else
+					chargingInfo[_index]->ChargingProfileCurrent = 0;
+			}
+			else
+			{
+				chargingInfo[_index]->ChargingProfilePower = -1;
+				chargingInfo[_index]->ChargingProfileCurrent = -1;
+			}
+		}
+		else
+		{
+			chargingInfo[_index]->ChargingProfilePower = -1;
+			chargingInfo[_index]->ChargingProfileCurrent = -1;
+		}
+	}
+	else
+	{
+		chargingInfo[_index]->ChargingProfilePower = -1;
+		chargingInfo[_index]->ChargingProfileCurrent = -1;
+	}
+
+	if (chargingInfo[_index]->ChargingProfilePower >= 0 &&
+			_ChargingProfilePwBuffer[_index] != chargingInfo[_index]->ChargingProfilePower)
+	{
+		_ChargingProfilePwBuffer[_index] = chargingInfo[_index]->ChargingProfilePower;
+		PRINTF_FUNC("Profile : ChargingProfilePower = %.2f \n", chargingInfo[_index]->ChargingProfilePower);
+		PRINTF_FUNC("Profile : ChargingProfileCurrent = %.2f \n", chargingInfo[_index]->ChargingProfileCurrent);
+	}
+}
+
+void CheckOcppProfileConfirm(byte gun_index)
+{
+	if ((chargingInfo [gun_index]->SystemStatus >= SYS_MODE_PREPARE_FOR_EVSE && chargingInfo [gun_index]->SystemStatus <= SYS_MODE_CHARGING) ||
+			(chargingInfo [gun_index]->SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0 && chargingInfo [gun_index]->SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))
+	{
+		if (chargingInfo [gun_index]->SystemStatus == SYS_MODE_CHARGING)
+		{
+			// 進充電後,如果輸出電壓落差大於 10V 則直接繼續看 ChargingProfile
+			if (chargingInfo [gun_index]->PresentChargingVoltage >= gunOutputVol [gun_index] + 10 ||
+					chargingInfo [gun_index]->PresentChargingVoltage <= gunOutputVol [gun_index] - 10)
+			{
+				gunOutputVol [gun_index] = chargingInfo [gun_index]->PresentChargingVoltage;
+			}
+		}
+		ocpp_chk_profileConf_cmd ( gun_index );
+	}
+
+}
+
+void CheckAcOcppProfileConfirm()
+{
+	if (ac_chargingInfo[0]->SystemStatus >= SYS_MODE_PREPARING &&
+			ac_chargingInfo[0]->SystemStatus <= SYS_MODE_CHARGING)
+	{
+		ocpp_ac_chk_profileConf_cmd();
+	}
+}
+
+//===============================================
+// wifi schedule
+//===============================================
+bool WifiScheduleStop(byte gunIndex)
+{
+	bool result = false;
+
+	result = chargingInfo[gunIndex]->schedule.isTriggerStop;
+	chargingInfo[gunIndex]->schedule.isTriggerStop = NO;
+	return result;
+}
+
+//===============================================
+// SQLite3 related routine
+//===============================================
+int NetworkDB_Open(sqlite3 *db)
+{
+	int result = PASS;
+	char* errMsg = NULL;
+	char* createNerRecordSql="CREATE TABLE IF NOT EXISTS network_record("
+						      "idx integer primary key AUTOINCREMENT, "
+							  "occurDatetime text NOT NULL, "
+							  "isInternet text NOT NULL, "
+							  "isOcppConnected text NOT NULL, "
+				              "isEth0Internet text NOT NULL, "
+							  "isMlan0Internet text NOT NULL, "
+							  "isPpp0Internet text NOT NULL, "
+							  "rssiMlan0 text NOT NULL, "
+							  "rssiPpp0 text NOT NULL"
+							  ");";
+
+	//sqlite3_config(SQLITE_CONFIG_URI, 1);
+	if(sqlite3_open(NETWORK_DB_FILE, &db))
+	{
+		result = FAIL;
+		PRINTF_FUNC( "Can't open database (Net) : %s\n", sqlite3_errmsg(db));
+		sqlite3_close(db);
+	}
+	else
+	{
+		PRINTF_FUNC( "Local network status record database open successfully.\n");
+		if (sqlite3_exec(db, createNerRecordSql, 0, 0, &errMsg) != SQLITE_OK)
+		{
+			result = FAIL;
+			PRINTF_FUNC( "Create local network status record table error message: %s\n", errMsg);
+		}
+		else
+		{
+			PRINTF_FUNC( "Opened local network status record table successfully\n");
+		}
+
+		sqlite3_close(db);
+	}
+
+	return result;
+}
+
+int DB_Open(sqlite3 *db)
+{
+	int result = PASS;
+	char* errMsg = NULL;
+	char* createRecordSql="CREATE TABLE IF NOT EXISTS charging_record("
+					      "idx integer primary key AUTOINCREMENT, "
+						  "reservationId text, "
+						  "transactionId text, "
+						  "startMethod text, "
+						  "userId text, "
+						  "dateTimeStart text, "
+						  "dateTimeStop text,"
+						  "socStart text, "
+						  "socStop text, "
+						  "chargeEnergy text, "
+						  "stopReason text,"
+						  "vincode text"
+						  ");";
+
+	char* createCfgSql="CREATE TABLE IF NOT EXISTS `config` ( "
+					   "`idx` INTEGER PRIMARY KEY AUTOINCREMENT, "
+					   "`item` TEXT NOT NULL, "
+				       "`connector` INTEGER NOT NULL, "
+					   "`val` TEXT NOT NULL, unique(item,connector) on conflict replace);";
+
+	char* creatererrecordSql="CREATE TABLE IF NOT EXISTS `event_record` ( "
+						   "`idx` INTEGER PRIMARY KEY AUTOINCREMENT, "
+						   "`occurDatetime` TEXT NOT NULL, "
+					       "`statusCode` TEXT NOT NULL, unique(occurDatetime,statusCode) on conflict replace);";
+
+	char* createrebootSql="CREATE TABLE IF NOT EXISTS `reboot_record` ( "
+							   "`idx` INTEGER PRIMARY KEY AUTOINCREMENT, "
+							   "`rebootDatetime` TEXT NOT NULL, unique(rebootDatetime) on conflict replace);";
+
+	char * createconsumptionSql = "CREATE TABLE IF NOT EXISTS `power_consumption` ( "
+			   	   	   	   	   	   "`idx` INTEGER PRIMARY KEY AUTOINCREMENT, "
+		       	   	   	   	   	   "`connector` INTEGER NOT NULL, "
+			   	   	   	   	   	   "`val` TEXT NOT NULL, unique(connector) on conflict replace);";
+
+//	char * createTestSql = "CREATE TABLE IF NOT EXISTS `for_test` ( "
+//				   	   	   	   	   "`idx` INTEGER PRIMARY KEY AUTOINCREMENT, "
+//			       	   	   	   	   "`connector` INTEGER NOT NULL, "
+//								   "`testID` TEXT, "
+//			 	 	 	 	 	   "`checkStatus` INTEGER NOT NULL "
+//								   ");";
+
+	if(sqlite3_open(DB_FILE, &db))
+	{
+		result = FAIL;
+		PRINTF_FUNC( "Can't open database: %s\r\n", sqlite3_errmsg(db));
+		sqlite3_close(db);
+	}
+	else
+	{
+		PRINTF_FUNC( "Local charging record database open successfully.\r\n");
+
+		if (sqlite3_exec(db, createRecordSql, 0, 0, &errMsg) != SQLITE_OK)
+		{
+			result = FAIL;
+			PRINTF_FUNC( "Create local charging record table error message: %s\n", errMsg);
+		}
+		else
+		{
+			PRINTF_FUNC( "Opened local charging record table successfully\n");
+		}
+
+		if (sqlite3_exec(db, createCfgSql, 0, 0, &errMsg) != SQLITE_OK)
+		{
+			result = FAIL;
+			PRINTF_FUNC( "Create local config table error message: %s\n", errMsg);
+		}
+		else
+		{
+			PRINTF_FUNC( "Opened local config table successfully\n");
+		}
+
+		if (sqlite3_exec(db, creatererrecordSql, 0, 0, &errMsg) != SQLITE_OK)
+		{
+			result = FAIL;
+			PRINTF_FUNC( "Create local record table error message: %s\n", errMsg);
+		}
+		else
+		{
+			PRINTF_FUNC( "Opened local record table successfully\n");
+		}
+
+		if (sqlite3_exec(db, createrebootSql, 0, 0, &errMsg) != SQLITE_OK)
+		{
+			result = FAIL;
+			PRINTF_FUNC( "Create reboot record table error message: %s\n", errMsg);
+		}
+		else
+		{
+			PRINTF_FUNC( "Opened reboot record table successfully\n");
+		}
+
+		if (sqlite3_exec(db, createconsumptionSql, 0, 0, &errMsg) != SQLITE_OK)
+		{
+			result = FAIL;
+			PRINTF_FUNC( "Create power consumption record table error message: %s\n", errMsg);
+		}
+		else
+		{
+			PRINTF_FUNC( "Opened power consumption record table successfully\n");
+		}
+
+//		if (sqlite3_exec(db, createTestSql, 0, 0, &errMsg) != SQLITE_OK)
+//		{
+//			result = FAIL;
+//			printf( "Create test table error message: %s\n", errMsg);
+//		}
+//		else
+//		{
+//			printf( "Opened test table successfully\n");
+//		}
+
+		sqlite3_close(db);
+	}
+
+	return result;
+}
+
+int DB_Insert_Record(sqlite3 *db, int gun_index)
+{
+	int result = PASS;
+	char* errMsg = NULL;
+	char insertSql[1024];
+
+	if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
+	{
+		sprintf(insertSql, "insert into charging_record(reservationId, transactionId, startMethod, userId, dateTimeStart, dateTimeStop, socStart, socStop, chargeEnergy, stopReason, vincode) "
+						   "values('%d', '%d', '%d', '%s', '%s', '%s', '%d', '%d', '%f', '%s', '%s');",
+						   chargingInfo[gun_index]->ReservationId,
+						   ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId,
+						   chargingInfo[gun_index]->StartMethod,
+						   chargingInfo[gun_index]->StartUserId,
+						   chargingInfo[gun_index]->StartDateTime,
+						   chargingInfo[gun_index]->StopDateTime,
+						   chargingInfo[gun_index]->EvBatteryStartSoc,
+						   chargingInfo[gun_index]->EvBatterySoc,
+						   chargingInfo[gun_index]->PresentChargedEnergy,
+						   ShmOCPP16Data->StopTransaction[gun_index].StopReason,
+						   chargingInfo[gun_index]->EVCCID);
+	}
+	else if (ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
+	{
+		sprintf(insertSql, "insert into charging_record(reservationId, transactionId, startMethod, userId, dateTimeStart, dateTimeStop, socStart, socStop, chargeEnergy, stopReason) "
+						   "values('%d', '%s', '%d', '%s', '%s', '%s', '%d', '%d', '%f', '%s');",
+						   chargingInfo[gun_index]->ReservationId,
+						   ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId,
+						   chargingInfo[gun_index]->StartMethod,
+						   chargingInfo[gun_index]->StartUserId,
+						   chargingInfo[gun_index]->StartDateTime,
+						   chargingInfo[gun_index]->StopDateTime,
+						   chargingInfo[gun_index]->EvBatteryStartSoc,
+						   chargingInfo[gun_index]->EvBatterySoc,
+						   chargingInfo[gun_index]->PresentChargedEnergy,
+						   ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.stoppedReason);
+	}
+
+	if(sqlite3_open(DB_FILE, &db))
+	{
+		result = FAIL;
+		PRINTF_FUNC( "Can't open database: %s\n", sqlite3_errmsg(db));
+		sqlite3_close(db);
+	}
+	else
+	{
+		PRINTF_FUNC( "Local charging record database open successfully.\n");
+		if (sqlite3_exec(db, insertSql, 0, 0, &errMsg) != SQLITE_OK)
+		{
+			result = FAIL;
+			PRINTF_FUNC( "Insert local charging record error message: %s\n", errMsg);
+		}
+		else
+		{
+			PRINTF_FUNC( "Insert local charging record successfully\n");
+		}
+
+		sprintf(insertSql, "delete from charging_record where idx < (select idx from charging_record order by idx desc limit 1)-2000;");
+		if (sqlite3_exec(db, insertSql, 0, 0, &errMsg) != SQLITE_OK)
+		{
+			result = FAIL;
+			PRINTF_FUNC( "delete local charging error message: %s\n", errMsg);
+		}
+		else
+		{
+			PRINTF_FUNC( "delete local charging record successfully\n");
+		}
+
+		sqlite3_close(db);
+	}
+
+	return result;
+}
+
+int DB_Update_Operactive(sqlite3 *db, uint8_t gun_index, uint8_t IsAvailable)
+{
+	uint8_t result = false;
+	char* errMsg = NULL;
+	char sqlStr[1024];
+	srand(time(NULL));
+
+	if(sqlite3_open(DB_FILE, &db))
+	{
+		result = FAIL;
+		PRINTF_FUNC( "Can't open database: %s\r\n", sqlite3_errmsg(db));
+		sqlite3_close(db);
+	}
+	else
+	{
+		PRINTF_FUNC( "Local charging record database open successfully (%d).\r\n", IsAvailable);
+		sprintf(sqlStr, "insert or replace into config (item, connector, val) values('IsAvailable', %d, %d);", gun_index, IsAvailable);
+		PRINTF_FUNC("sqlStr= %s\r\n", sqlStr);
+		if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
+		{
+			result = FAIL;
+			PRINTF_FUNC( "update config error message: %s\n", errMsg);
+		}
+		else
+		{
+			PRINTF_FUNC("update connector-%d config item isOperactive to %d\r\n", gun_index, IsAvailable);
+		}
+
+		sqlite3_close(db);
+	}
+
+	return result;
+}
+
+int DB_Get_Operactive(sqlite3 *db, uint8_t gun_index)
+{
+	uint8_t result = true;
+	char* errMsg = NULL;
+	char sqlStr[1024];
+	char **rs;
+	int	 rows, cols;
+
+	sprintf(sqlStr, "select * from config where item='IsAvailable' and connector=%d;", gun_index);
+	//DEBUG_INFO("sqlStr= %s\r\n", sqlStr);
+
+	if(sqlite3_open(DB_FILE, &db))
+	{
+		result = FAIL;
+		PRINTF_FUNC( "Can't open database: %s\r\n", sqlite3_errmsg(db));
+		sqlite3_close(db);
+	}
+	else
+	{
+		PRINTF_FUNC( "Local config query database open successfully.\r\n");
+		sqlite3_get_table(db, sqlStr, &rs, &rows, &cols, &errMsg);
+		if(rows>0)
+		{
+			for(int idxRow=1;idxRow<=rows;idxRow++)
+			{
+				if(strcmp(rs[(idxRow*cols)+3], "0") == 0)
+				{
+					result = false;
+				}
+				PRINTF_FUNC("Query connector-%d isOperactive: %s\r\n", gun_index, rs[(idxRow*cols)+3]);
+			}
+		}
+		else
+		{
+			PRINTF_FUNC("Query connector-%d fail, set default value to operactive.\r\n", gun_index);
+		}
+
+		sqlite3_free_table(rs);
+		sqlite3_close(db);
+	}
+
+	return result;
+}
+
+void DB_Update_PowerConsumption(sqlite3 *db, uint8_t gun_index, float value)
+{
+	char* errMsg = NULL;
+	char sqlStr[1024];
+	srand(time(NULL));
+
+	if(sqlite3_open(DB_FILE, &db))
+	{
+		PRINTF_FUNC( "Can't open database: %s\r\n", sqlite3_errmsg(db));
+		sqlite3_close(db);
+	}
+	else
+	{
+		sprintf(sqlStr, "insert or replace into power_consumption (connector, val) values(%d, %f);", gun_index, value);
+		if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
+		{
+			PRINTF_FUNC( "update power_consumption error message: %s\n", errMsg);
+		}
+		else
+		{
+			//PRINTF_FUNC("update connector-%d power_consumption item consumption to %f \r\n", gun_index, value);
+		}
+
+		sqlite3_close(db);
+	}
+}
+
+float DB_Get_PowerConsumption(sqlite3 *db, uint8_t gun_index)
+{
+	float result = 0;
+	char* errMsg = NULL;
+	char sqlStr[1024];
+	char **rs;
+	int rows, cols;
+
+	sprintf(sqlStr, "select * from power_consumption where connector=%d;", gun_index);
+
+	if (sqlite3_open(DB_FILE, &db))
+	{
+		result = FAIL;
+		PRINTF_FUNC("Can't open database: %s\r\n", sqlite3_errmsg(db));
+		sqlite3_close(db);
+	}
+	else
+	{
+		PRINTF_FUNC("Local config query database open successfully.\r\n");
+		sqlite3_get_table(db, sqlStr, &rs, &rows, &cols, &errMsg);
+		if (rows > 0)
+		{
+			for (int idxRow = 1; idxRow <= rows; idxRow++)
+			{
+				result = atof(rs[(idxRow * cols) + 2]);
+			}
+		}
+		else
+		{
+			PRINTF_FUNC( "Query connector-%d fail, set default value to consumption.\r\n", gun_index);
+		}
+
+		sqlite3_free_table(rs);
+		sqlite3_close(db);
+	}
+
+	return result;
+}
+
+int DB_Reboot_Record(sqlite3 *db)
+{
+	int result = PASS;
+	char* errMsg = NULL;
+	char insertSql[256];
+
+	sprintf(insertSql, "insert into reboot_record(rebootDatetime) values(CURRENT_TIMESTAMP);");
+
+	if(sqlite3_open(DB_FILE, &db))
+	{
+		result = FAIL;
+		PRINTF_FUNC( "Can't open database: %s\n", sqlite3_errmsg(db));
+		sqlite3_close(db);
+	}
+	else
+	{
+		PRINTF_FUNC( "Local charging record database open successfully.\n");
+		if (sqlite3_exec(db, insertSql, 0, 0, &errMsg) != SQLITE_OK)
+		{
+			result = FAIL;
+			PRINTF_FUNC( "Insert reboot record error message: %s\n", errMsg);
+		}
+		else
+		{
+			PRINTF_FUNC( "Insert reboot record successfully\n");
+		}
+
+		sprintf(insertSql, "delete from reboot_record where idx < (select idx from charging_record order by idx desc limit 1)-2000;");
+		if (sqlite3_exec(db, insertSql, 0, 0, &errMsg) != SQLITE_OK)
+		{
+			result = FAIL;
+			PRINTF_FUNC( "delete reboot record error message: %s\n", errMsg);
+		}
+		else
+		{
+			PRINTF_FUNC( "delete reboot record successfully\n");
+		}
+
+		sqlite3_close(db);
+	}
+
+	return result;
+}
+
+int DB_Insert_test_Record(sqlite3 *db, uint8_t gun_index, char *textID)
+{
+	int result = PASS;
+	char* errMsg = NULL;
+	char insertSql[1024];
+
+	sprintf(insertSql, "insert into for_test (connector, testID, checkStatus) values(%d, %s, 0);",
+							   gun_index, textID);
+
+	if(sqlite3_open(DB_FILE, &db))
+	{
+		result = FAIL;
+		PRINTF_FUNC( "Can't open database: %s\n", sqlite3_errmsg(db));
+		sqlite3_close(db);
+	}
+	else
+	{
+		if (sqlite3_exec(db, insertSql, 0, 0, &errMsg) != SQLITE_OK)
+		{
+			result = FAIL;
+			PRINTF_FUNC( "Insert sdlu test error message : %s\n", errMsg);
+		}
+		else
+		{
+			PRINTF_FUNC( "Insert sdlu test successfully\n");
+		}
+
+		sqlite3_close(db);
+	}
+
+	return result;
+}
+
+int DB_delete_test_Record(sqlite3 *db, uint8_t gun_index, char *textID)
+{
+	int result = PASS;
+	char* errMsg = NULL;
+	char insertSql[1024];
+
+	sprintf(insertSql, "delete from for_test where testID = %s", textID);
+
+	if (sqlite3_open(DB_FILE, &db))
+	{
+		result = FAIL;
+		PRINTF_FUNC("Can't open database: %s\n", sqlite3_errmsg(db));
+		sqlite3_close(db);
+	}
+	else
+	{
+		if (sqlite3_exec(db, insertSql, 0, 0, &errMsg) != SQLITE_OK)
+		{
+			result = FAIL;
+			PRINTF_FUNC( "Test message 2: %s\n", errMsg);
+		}
+		else
+		{
+			PRINTF_FUNC( "Test message 2 successfully\n");
+		}
+
+		sqlite3_close(db);
+	}
+
+	return result;
+}
+
+int DB_sql_test(sqlite3 *db, uint8_t gun_index)
+{
+	int result = PASS;
+	char* errMsg = NULL;
+	char insertSql[1024];
+	char valueStr[128];
+	char **rs;
+	int rows, cols;
+
+	sprintf(insertSql, "select testID from for_test where checkStatus=0;");
+
+	if (sqlite3_open(DB_FILE, &db))
+	{
+		result = FAIL;
+		PRINTF_FUNC("Can't open database: %s\r\n", sqlite3_errmsg(db));
+		sqlite3_close(db);
+	}
+	else
+	{
+		PRINTF_FUNC("Local for_test query database open successfully.\r\n");
+		sqlite3_get_table(db, insertSql, &rs, &rows, &cols, &errMsg);
+		if (rows > 0)
+		{
+			for (int idxRow = 1; idxRow <= rows; idxRow++)
+			{
+				strcpy(valueStr, rs[(idxRow * cols)]);
+				printf("valueStr = %s \n", valueStr);
+			}
+		}
+		else
+		{
+			PRINTF_FUNC("select testID from for_test fail \r\n");
+		}
+
+		sqlite3_free_table(rs);
+		sqlite3_close(db);
+	}
+
+	return result;
+}
+
+//===============================================
+// Config process
+//===============================================
+void AddPlugInTimes(byte gunIndex)
+{
+	if (chargingInfo[gunIndex]->Type == _Type_Chademo)
+		ShmSysConfigAndInfo->SysConfig.ChademoPlugInTimes += 1;
+	else if(chargingInfo[gunIndex]->Type == _Type_CCS)
+		ShmSysConfigAndInfo->SysConfig.Ccs2PlugInTimes += 1;
+	else if(chargingInfo[gunIndex]->Type == _Type_GB)
+		ShmSysConfigAndInfo->SysConfig.GbPlugInTimes += 1;
+}
+
+void ChangeStartOrStopDateTime(byte isStart, byte gunIndex)
+{
+	char cmdBuf[32];
+	struct timeb csuTime;
+	struct tm *tmCSU;
+
+	ftime(&csuTime);
+	tmCSU = localtime(&csuTime.time);
+
+	sprintf(cmdBuf, "%04d-%02d-%02d %02d:%02d:%02d", tmCSU->tm_year + 1900,
+			tmCSU->tm_mon + 1, tmCSU->tm_mday, tmCSU->tm_hour, tmCSU->tm_min,
+			tmCSU->tm_sec);
+	if (isStart)
+		strcpy((char *)chargingInfo[gunIndex]->StartDateTime, cmdBuf);
+	else
+	{
+		if (strcmp((char *)chargingInfo[gunIndex]->StartDateTime, "00:00:00") != EQUAL)
+			strcpy((char *)chargingInfo[gunIndex]->StopDateTime, cmdBuf);
+	}
+}
+
+void zipLogFiles()
+{
+	const char* logPath = "/Storage/SystemLog";
+	// 獲取目錄
+	DIR* pDir = opendir(logPath);
+	if (pDir != NULL)
+	{
+		struct timeb csuTime;
+		struct tm *tmCSU;
+
+		ftime(&csuTime);
+		tmCSU = localtime(&csuTime.time);
+//		PRINTF_FUNC("Time : %04d-%02d-%02d %02d:%02d:%02d \n", tmCSU->tm_year + 1900,
+//			tmCSU->tm_mon + 1, tmCSU->tm_mday, tmCSU->tm_hour, tmCSU->tm_min,
+//			tmCSU->tm_sec);
+
+		// Read items inside the folder
+		struct dirent* pEntry = NULL;
+		while ((pEntry = readdir(pDir)) != NULL)
+		{
+			if (strcmp(pEntry->d_name, ".") != 0 &&
+					strcmp(pEntry->d_name, "..") != 0 &&
+					strncmp(pEntry->d_name, "[", 1) == 0 &&
+					strstr(pEntry->d_name, "tar") < 0)
+			{
+				char yearC[5];
+				unsigned short year = 0;
+				char monthC[3];
+				unsigned short month = 0;
+
+				yearC[4] = '\0';
+				strncpy(yearC, pEntry->d_name + 1, 4);
+				monthC[2] = '\0';
+				strncpy(monthC, pEntry->d_name + 6, 2);
+
+				year = atoi(yearC);
+				month = atoi(monthC);
+
+				if (year != 0)
+				{
+					if (year < tmCSU->tm_year + 1900 ||
+							(year >= tmCSU->tm_year + 1900 && month < tmCSU->tm_mon + 1))
+					{
+						DEBUG_INFO_MSG("tar file name : %s \n", pEntry->d_name);
+						char file[256];
+
+						memset(file, 0x00, sizeof(file));
+						strcat(file, "tar zcvf ");
+						strcat(file, logPath);
+						strncat(file, "/", 1);
+						strcat(file, pEntry->d_name);
+						strcat(file, ".tar");
+						strncat(file, " ", 1);
+						strcat(file, logPath);
+						strncat(file, "/", 1);
+						strcat(file, pEntry->d_name);
+						PRINTF_FUNC("zip = %s \n", file);
+						system(file);
+					}
+				}
+			}
+		}
+	}
+	// Close folder
+	closedir(pDir);
+}
+
+void ChangeGunSelectByIndex(byte sel)
+{
+	ShmSysConfigAndInfo->SysInfo.CurGunSelected = sel;
+	ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc = NO_DEFINE;
+}
+
+void CheckIsAlternatvieByModelName()
+{
+	if(ShmSysConfigAndInfo->SysConfig.ModelName[1] == 'W')
+	{
+		// 壁掛
+		ShmSysConfigAndInfo->SysInfo.IsAlternatvieConf = YES;
+	}
+	else
+		ShmSysConfigAndInfo->SysInfo.IsAlternatvieConf = NO;
+}
+
+void StopProcessingLoop()
+{
+	ocpp_process_start();
+
+	for (;;)
+	{
+		CheckTask();
+		CheckFactoryConfigFunction();
+		CheckFwUpdateFunction();
+		ocpp_chk_reset_cmd(YES);
+		if (ShmSysConfigAndInfo->SysWarningInfo.Level == _ALARM_LEVEL_CRITICAL)
+		{
+			// 經過底下的 function 後,ShmSysConfigAndInfo->SysWarningInfo.Level 會再被更新一次
+			ChkPrimaryStatus();
+			ButtonTriggerEvent();
+			ReviewCriticalAlarm();
+			if (ShmSysConfigAndInfo->SysWarningInfo.Level == _ALARM_LEVEL_NORMAL &&
+					ShmDcCommonData->rebootCount < 1)
+			{
+				PRINTF_FUNC("Soft reboot for retry self-test (Primary). \n");
+				SetupRebootCount(1);
+				KillAllTask();
+				sleep(3);
+				system("/usr/bin/run_evse_restart.sh");
+				return;
+			}
+		}
+		sleep(1);
+	}
+}
+
+void CreateWatchdog()
+{
+	if (ShmSysConfigAndInfo->SysConfig.SwitchDebugFlag == NO)
+	{
+		wtdFd = InitWatchDog();
+
+		if (wtdFd < 0)
+			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed = 1;
+	}
+}
+
+bool IsConnectorWholeIdle()
+{
+	bool result = true;
+
+	for (byte count = 0; count < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; count++)
+	{
+		if (chargingInfo[count]->SystemStatus != SYS_MODE_IDLE &&
+				chargingInfo[count]->SystemStatus != SYS_MODE_RESERVATION)
+		{
+			result = false;
+			break;
+		}
+	}
+
+	for (byte count = 0; count < ShmSysConfigAndInfo->SysConfig.AcConnectorCount; count++)
+	{
+		if (ac_chargingInfo[count]->SystemStatus != SYS_MODE_IDLE &&
+				ac_chargingInfo[count]->IsErrorOccur == NO)
+		{
+			result = false;
+			break;
+		}
+	}
+
+	return result;
+}
+
+void ClearAlarmCodeWhenAcOff()
+{
+	if (!ShmSysConfigAndInfo->SysInfo.AcContactorStatus)
+	{
+		ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuNoResource = NO;
+	}
+}
+
+//==========================================
+// Check task processing
+//==========================================
+void CheckTask()
+{
+	if(reset4gStep == RESET_4G_STEP_NONE &&
+			(ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'T' ||
+			ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D'))
+	{
+		if(system("pidof -s Module_4g > /dev/null") != 0)
+		{
+			DEBUG_ERROR_MSG("Module_4g not running, restart it.\r\n");
+			system("/root/Module_4g &");
+		}
+	}
+
+	if(reset4gStep == RESET_4G_STEP_NONE &&
+			(ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'W' ||
+			ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D'))
+	{
+		if(system("pidof -s Module_Wifi > /dev/null") != 0)
+		{
+			DEBUG_ERROR_MSG("Module_Wifi not running, restart it.\r\n");
+			system("/root/Module_Wifi &");
+		}
+	}
+
+	if(ShmSysConfigAndInfo->SysConfig.ModelName[3] == 'P')
+	{
+		if(system("pidof -s Module_DcMeter > /dev/null") != 0)
+		{
+			DEBUG_ERROR_MSG("Module_DcMeter not running, restart it.\r\n");
+			system("/root/Module_DcMeter &");
+		}
+	}
+
+	ocpp_process_start();
+
+	if(system("pidof -s Module_ProduceUtils > /dev/null") != 0)
+	{
+		DEBUG_ERROR_MSG("Module_ProduceUtils not running, restart it.\r\n");
+		system ("/root/Module_ProduceUtils &");
+	}
+}
+
+void Check267Alarm()
+{
+	bool canRun = true;
+
+	for (byte _index = 0; _index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _index++)
+	{
+		if((chargingInfo[_index]->SystemStatus > SYS_MODE_IDLE && chargingInfo[_index]->SystemStatus < SYS_MODE_TERMINATING) ||
+				(chargingInfo[_index]->SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0 && chargingInfo[_index]->SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))
+		{
+			canRun = false;
+			break;
+		}
+	}
+
+	if (canRun)
+	{
+		if ( ! ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuFailureAlarm)
+		{
+			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuFailureAlarm = YES;
+		}
+	}
+}
+
+void CheckSystemTaskAlive()
+{
+	unsigned char lostId = CheckSystemTask(ShmSysConfigAndInfo->SysInfo.SystemPage);
+	if (lostId != 0)
+	{
+		if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemTaskLost == NO)
+		{
+			EmcOccurThenStopCharging();
+			sleep(2);
+			if (lostId == _SYSTEM_TASK_LOST_ITEM_MAIN) PRINTF_FUNC ( "System task lost (CSU). \n" );
+			else if (lostId == _SYSTEM_TASK_LOST_ITEM_EVCOMM)
+			{
+
+				PRINTF_FUNC ( "System task lost (EVComm). \n" );
+				for (byte gun = 0; gun < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gun ++)
+				{
+					chargingInfo [gun]->ConnectorPlugIn = NO;
+				}
+			}
+			else if (lostId == _SYSTEM_TASK_LOST_ITEM_PSUCOMM) PRINTF_FUNC ( "System task lost (PSU Task). \n" );
+			else if (lostId == _SYSTEM_TASK_LOST_ITEM_EVENTLOG) PRINTF_FUNC ( "System task lost (Event log). \n" );
+			else if (lostId == _SYSTEM_TASK_LOST_ITEM_PRIMARYCOMM) PRINTF_FUNC ( "System task lost (Primary). \n" );
+			else if (lostId == _SYSTEM_TASK_LOST_ITEM_LCMCONTROL) PRINTF_FUNC ( "System task lost (LCM Comm). \n" );
+			else if (lostId == 	_SYSTEM_TASK_LOST_ITEM_INTERCOMM) PRINTF_FUNC("System task lost (Internal Comm). \n");
+
+			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemTaskLost = YES;
+		}
+	}
+	else
+		ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemTaskLost = NO;
+}
+
+void InitialDHCP()
+{
+	char tmpbuf[256];
+	memset(tmpbuf,0,256);
+	system("pgrep -f \"udhcpc -i eth0\" | xargs kill");
+	sprintf(tmpbuf, "/sbin/udhcpc -i eth0 -x hostname:CSU3_%s -s /root/dhcp_script/eth0.script > /dev/null &", ShmSysConfigAndInfo->SysConfig.SystemId);
+	system(tmpbuf);
+}
+
+void Run4gResetProc()
+{
+	if (ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomEnabled == _SYS_4G_MODE_ENABLE ||
+			ShmSysConfigAndInfo->SysConfig.AthInterface.WifiMode == _SYS_WIFI_MODE_STATION)
+	{
+		if (!ShmSysConfigAndInfo->SysInfo.OcppConnStatus &&
+				!ShmSysConfigAndInfo->SysInfo.InternetConn)
+		{
+			if (reset4gStep == RESET_4G_STEP_NONE)
+			{
+				if ((ShmStatusCodeData->FaultCode.FaultEvents.bits.Telecom4GModuleBroken == YES && _4gResetChkFlag >= 12) ||
+					_4gResetChkFlag >= 60)
+				{
+					PRINTF_FUNC("Reset 4G/Wifi module. \n");
+					reset4gStep = RESET_4G_STEP_DELETE_TASK;
+				}
+				else
+					_4gResetChkFlag++;
+			}
+		}
+		else
+			_4gResetChkFlag = 0;
+
+		switch(reset4gStep)
+		{
+			case RESET_4G_STEP_DELETE_TASK:
+			{
+				PRINTF_FUNC("Killall 4G / Wifi task. \n");
+				system("killall Module_4g &");
+				system("killall Module_Wifi &");
+				reset4gStep = RESET_4G_STEP_GPIO_HIGH;
+			}
+				break;
+			case RESET_4G_STEP_GPIO_HIGH:
+			{
+				PRINTF_FUNC("Disable 4G/Wifi. GPIO-104 -> High. \n");
+				system("echo 1 > /sys/class/gpio/gpio104/value");
+				reset4gStep = RESET_4G_STEP_GPIO_LOW_COMP;
+			}
+				break;
+			case RESET_4G_STEP_GPIO_LOW_COMP:
+			{
+				PRINTF_FUNC("Enable 4G/Wifi. GPIO-104 -> Low. \n");
+				system("echo 0 > /sys/class/gpio/gpio104/value");
+				reset4gStep = RESET_4G_STEP_NONE;
+				_4gResetChkFlag = 0;
+			}
+				break;
+		}
+	}
+	else
+	{
+		if (reset4gStep != RESET_4G_STEP_NONE)
+			system("echo 0 > /sys/class/gpio/gpio104/value");
+		reset4gStep = RESET_4G_STEP_NONE;
+		_4gResetChkFlag = 0;
+	}
+}
+//==========================================
+// Check Smart Charging Profile
+//==========================================
+int GetStartScheduleTime(unsigned char *time)
+{
+	int result = -1;
+	struct tm tmScheduleStart;
+	struct timeb tbScheduleStart;
+
+	if((sscanf((char *)time, "%4d-%2d-%2dT%2d:%2d:%2d", &tmScheduleStart.tm_year, &tmScheduleStart.tm_mon, &tmScheduleStart.tm_mday, &tmScheduleStart.tm_hour, &tmScheduleStart.tm_min, &tmScheduleStart.tm_sec) == 6))
+	{
+		tmScheduleStart.tm_year -= 1900;
+		tmScheduleStart.tm_mon -= 1;
+
+		tbScheduleStart.time = mktime(&tmScheduleStart);
+		tbScheduleStart.millitm = 0;
+
+		result = DiffTimebWithNow(tbScheduleStart) / 1000;
+	}
+
+	return result;
+}
+
+//==========================================
+// sub function
+//==========================================
+void CheckReturnToChargingConn()
+{
+	if ((ShmSysConfigAndInfo->SysConfig.TotalConnectorCount + ShmSysConfigAndInfo->SysConfig.AcConnectorCount) > 1 &&
+		ShmSysConfigAndInfo->SysInfo.PageIndex != _LCM_AUTHORIZING &&
+		ShmSysConfigAndInfo->SysInfo.PageIndex != _LCM_AUTHORIZ_FAIL &&
+		ShmSysConfigAndInfo->SysInfo.PageIndex != _LCM_AUTHORIZ_COMP &&
+		ShmSysConfigAndInfo->SysInfo.PageIndex != _LCM_WAIT_FOR_PLUG)
+	{
+		bool isReturnTimeout = false;
+
+		for (byte count = 0; count < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; count++)
+		{
+			// 如果選的 DC 槍在充電~ 則 DC 槍不改變
+			if (count == ShmSysConfigAndInfo->SysInfo.CurGunSelected)
+			{
+				if ((chargingInfo[count]->SystemStatus >= SYS_MODE_MODE_REASSIGN_CHECK && chargingInfo[count]->SystemStatus <= SYS_MODE_COMPLETE) ||
+						(chargingInfo[count]->SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0 && chargingInfo[count]->SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))
+				{
+					isReturnTimeout = false;
+					break;
+				}
+			}
+			else if (count != ShmSysConfigAndInfo->SysInfo.CurGunSelected)
+			{
+				if ((chargingInfo[count]->SystemStatus >= SYS_MODE_MODE_REASSIGN_CHECK && chargingInfo[count]->SystemStatus <= SYS_MODE_COMPLETE) ||
+						(chargingInfo[count]->SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0 && chargingInfo[count]->SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))
+				{
+					isReturnTimeout = true;
+					StartSystemTimeoutDet(Timeout_ReturnToChargingGunDet);
+				}
+			}
+		}
+
+		// AC 槍
+		if (!isReturnTimeout && ShmSysConfigAndInfo->SysConfig.AcConnectorCount > 0)
+		{
+			// 沒有選中 AC,且 AC 在充電中
+			if (ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc == NO_DEFINE &&
+					(ac_chargingInfo[0]->SystemStatus >= SYS_MODE_PREPARING && ac_chargingInfo[0]->SystemStatus <= SYS_MODE_COMPLETE))
+			{
+				// 當前 DC 充電槍在 idle 狀態
+				if (chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus == SYS_MODE_IDLE ||
+						chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus == SYS_MODE_RESERVATION)
+				{
+					isReturnTimeout = true;
+					StartSystemTimeoutDet(Timeout_ReturnToChargingGunDet);
+				}
+			}
+			else if (ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc == DEFAULT_AC_INDEX &&
+						((chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus >= SYS_MODE_MODE_REASSIGN_CHECK && chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus <= SYS_MODE_COMPLETE) ||
+						(chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0 && chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1)))
+			{
+				// 當前 DC 充電槍在 idle 狀態
+				if (ac_chargingInfo[0]->SystemStatus == SYS_MODE_IDLE ||
+						ac_chargingInfo[0]->SystemStatus == SYS_MODE_RESERVATION)
+				{
+					isReturnTimeout = true;
+					StartSystemTimeoutDet(Timeout_ReturnToChargingGunDet);
+				}
+			}
+		}
+
+		if (!isReturnTimeout)
+			StopSystemTimeoutDet();
+	}
+}
+
+bool GetStartChargingByAlterMode(byte _gun)
+{
+	bool result = true;
+
+	if (ShmSysConfigAndInfo->SysConfig.TotalConnectorCount == 2 &&
+			ShmSysConfigAndInfo->SysInfo.IsAlternatvieConf == YES)
+	{
+		for (byte _select = 0; _select < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _select++)
+		{
+			if (_select != _gun)
+			{
+				if (chargingInfo[_select]->SystemStatus != SYS_MODE_IDLE &&
+						chargingInfo[_select]->SystemStatus != SYS_MODE_RESERVATION)
+				{
+					result = false;
+					break;
+				}
+			}
+		}
+	}
+
+	return result;
+}
+
+void TheEndCharging(byte gun_index)
+{
+	chargingInfo[gun_index]->isRemoteStart = NO;
+
+	StopGunInfoTimeoutDet(gun_index);
+	StartGunInfoTimeoutDet(gun_index, Timeout_EvseCompleteDet);
+	ChangeStartOrStopDateTime(NO, gun_index);
+	DB_Insert_Record(localDb, gun_index);
+}
+
+void AdjustChargerCurrent()
+{
+	ShmSysConfigAndInfo->SysConfig.RatingCurrent = ShmPsuData->SystemAvailableCurrent / 10;
+
+	// 設定的電流~ 如超過可輸出的電流,則 bypass
+	if (ShmSysConfigAndInfo->SysConfig.RatingCurrent < ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent ||
+			ShmSysConfigAndInfo->SysConfig.RatingCurrent == 0)
+	{
+		ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = 0;
+	}
+
+	PRINTF_FUNC ("PSU : MaxChargingPower = %d, MaxChargingCurrent = %d",
+			ShmPsuData->SystemAvailablePower / 10,
+			ShmPsuData->SystemAvailableCurrent / 10
+			);
+
+	PRINTF_FUNC ("Config : ChargingPower = %d, ChargingCurrent = %d",
+			ShmSysConfigAndInfo->SysConfig.MaxChargingPower,
+			ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent
+			);
+}
+
+void CheckStatusOfMeter()
+{
+	// 橋接如果搭上~ 則兩個電表都是使用狀態
+	// 如橋接沒有搭上~ 則視該火線 relay 狀態為電表使用狀態
+	if (ShmSysConfigAndInfo->SysInfo.BridgeRelayStatus == YES)
+	{
+		for (byte mIndex = 0; mIndex < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; mIndex++)
+			ShmCsuMeterData->_meter[mIndex].isCalculation = YES;
+	}
+	else
+	{
+		for (byte mIndex = 0; mIndex < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; mIndex++)
+		{
+			if (chargingInfo[mIndex]->RelayKPK2Status == YES || chargingInfo[mIndex]->RelayK1K2Status)
+				ShmCsuMeterData->_meter[mIndex].isCalculation = YES;
+			else
+				ShmCsuMeterData->_meter[mIndex].isCalculation = NO;
+		}
+	}
+}
+
+void ReviewCriticalAlarm()
+{
+	if (ShmDcCommonData->GunRelayDrivingOccur[0] == YES ||
+			ShmDcCommonData->GunRelayDrivingOccur[1] == YES ||
+			ShmDcCommonData->GunRelayWeldingOccur[0] == YES ||
+			ShmDcCommonData->GunRelayWeldingOccur[1] == YES ||
+			ShmDcCommonData->ParaRelayWeldingOccur == YES ||
+			ShmDcCommonData->ParaRelayDrivingOccur == YES ||
+			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.EmergencyStopTrip ||
+			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.MainPowerBreakerTrip ||
+			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DoorOpen ||
+			ShmSysConfigAndInfo->SysWarningInfo.ExtraErrProcess != _EXTRA_ERR_PROCESS_NONE ||
+			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuFailureAlarm ||
+			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuComminicationErrWithCSU ||
+			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemTaskLost)
+	{
+		ShmSysConfigAndInfo->SysWarningInfo.Level = _ALARM_LEVEL_CRITICAL;
+	}
+	else
+		ShmSysConfigAndInfo->SysWarningInfo.Level = _ALARM_LEVEL_NORMAL;
+}
+
+void CheckRelayWeldingOrDrivingFault(byte gun_index)
+{
+	// relay welding fault then stop the charging process.
+	byte faultCode = RELAY_STATUS_ERROR_NONE;
+
+	if (gun_index == 0)
+	{
+		if (ShmDcCommonData->RelayCheckStatus[RELAY_SMR1_P_STATUS] == RELAY_STATUS_ERROR_WELDING ||
+				ShmDcCommonData->RelayCheckStatus[RELAY_SMR1_N_STATUS] == RELAY_STATUS_ERROR_WELDING)
+		{
+			faultCode = RELAY_STATUS_ERROR_WELDING;
+		}
+		else if (ShmDcCommonData->RelayCheckStatus[RELAY_SMR1_P_STATUS] == RELAY_STATUS_ERROR_DRIVING ||
+				ShmDcCommonData->RelayCheckStatus[RELAY_SMR1_N_STATUS] == RELAY_STATUS_ERROR_DRIVING)
+		{
+			faultCode = RELAY_STATUS_ERROR_DRIVING;
+		}
+	}
+	else if (gun_index == 1)
+	{
+		if (ShmDcCommonData->RelayCheckStatus[RELAY_SMR2_P_STATUS] == RELAY_STATUS_ERROR_WELDING ||
+				ShmDcCommonData->RelayCheckStatus[RELAY_SMR2_N_STATUS] == RELAY_STATUS_ERROR_WELDING)
+		{
+			faultCode = RELAY_STATUS_ERROR_WELDING;
+		}
+		else if (ShmDcCommonData->RelayCheckStatus[RELAY_SMR2_P_STATUS] == RELAY_STATUS_ERROR_DRIVING ||
+				ShmDcCommonData->RelayCheckStatus[RELAY_SMR2_N_STATUS] == RELAY_STATUS_ERROR_DRIVING)
+		{
+			faultCode = RELAY_STATUS_ERROR_DRIVING;
+		}
+	}
+
+	if (ShmSysConfigAndInfo->SysConfig.TotalConnectorCount >= 2 &&
+			!ShmSysConfigAndInfo->SysInfo.IsAlternatvieConf)
+	{
+		// 橋接
+		if (ShmDcCommonData->RelayCheckStatus[RELAY_PARA_P_STATUS] == RELAY_STATUS_ERROR_WELDING ||
+				ShmDcCommonData->RelayCheckStatus[RELAY_PARA_N_STATUS] == RELAY_STATUS_ERROR_WELDING)
+		{
+			faultCode = RELAY_STATUS_ERROR_PARA_WELDING;
+		}
+		else if (ShmDcCommonData->RelayCheckStatus[RELAY_PARA_P_STATUS] == RELAY_STATUS_ERROR_DRIVING ||
+				ShmDcCommonData->RelayCheckStatus[RELAY_PARA_N_STATUS] == RELAY_STATUS_ERROR_DRIVING)
+		{
+			faultCode = RELAY_STATUS_ERROR_PARA_DRIVING;
+		}
+	}
+
+	if (faultCode == RELAY_STATUS_ERROR_WELDING)
+	{
+		// welding
+		if (chargingInfo[gun_index]->Type == _Type_Chademo)
+			RecordAlarmCode(gun_index, "011011");
+		else if (chargingInfo[gun_index]->Type == _Type_GB)
+			RecordAlarmCode(gun_index, "011015");
+		else if (chargingInfo[gun_index]->Type == _Type_CCS)
+			RecordAlarmCode(gun_index, "011013");
+
+		ShmDcCommonData->GunRelayWeldingOccur[gun_index] = YES;
+		EmcOccurThenStopCharging();
+	}
+	else if (faultCode == RELAY_STATUS_ERROR_DRIVING)
+	{
+		// driving
+		if (chargingInfo[gun_index]->Type == _Type_Chademo)
+			RecordAlarmCode(gun_index, "011012");
+		else if (chargingInfo[gun_index]->Type == _Type_GB)
+			RecordAlarmCode(gun_index, "011016");
+		else if (chargingInfo[gun_index]->Type == _Type_CCS)
+			RecordAlarmCode(gun_index, "011014");
+
+		ShmDcCommonData->GunRelayDrivingOccur[gun_index] = YES;
+		EmcOccurThenStopCharging();
+	}
+	else
+	{
+		if (chargingInfo[gun_index]->SystemStatus <= SYS_MODE_TERMINATING ||
+				chargingInfo[gun_index]->SystemStatus >= SYS_MODE_ALARM)
+		{
+			ShmDcCommonData->GunRelayWeldingOccur[gun_index] = NO;
+			ShmDcCommonData->GunRelayDrivingOccur[gun_index] = NO;
+
+			if (chargingInfo[gun_index]->Type == _Type_Chademo)
+			{
+				ResetChargerAlarmCode(gun_index, "011012");
+				ResetChargerAlarmCode(gun_index, "011011");
+			}
+			else if (chargingInfo[gun_index]->Type == _Type_CCS)
+			{
+				ResetChargerAlarmCode(gun_index, "011014");
+				ResetChargerAlarmCode(gun_index, "011013");
+			}
+			else if (chargingInfo[gun_index]->Type == _Type_GB)
+			{
+				ResetChargerAlarmCode(gun_index, "011016");
+				ResetChargerAlarmCode(gun_index, "011015");
+			}
+		}
+	}
+
+	if (ShmSysConfigAndInfo->SysConfig.TotalConnectorCount == 2)
+	{
+		if ((chargingInfo[0]->SystemStatus <= SYS_MODE_TERMINATING ||
+				chargingInfo[0]->SystemStatus >= SYS_MODE_ALARM) &&
+			(chargingInfo[1]->SystemStatus <= SYS_MODE_TERMINATING ||
+				chargingInfo[1]->SystemStatus >= SYS_MODE_ALARM))
+		{
+			if (faultCode == RELAY_STATUS_ERROR_PARA_WELDING)
+			{
+				// parallel welding
+				RecordAlarmCode ( gun_index, "011039" );
+
+				ShmDcCommonData->ParaRelayWeldingOccur = YES;
+				EmcOccurThenStopCharging ();
+			}
+			else if (faultCode == RELAY_STATUS_ERROR_PARA_DRIVING)
+			{
+				// parallel driving
+				RecordAlarmCode ( gun_index, "011040" );
+
+				ShmDcCommonData->ParaRelayDrivingOccur = YES;
+				EmcOccurThenStopCharging ();
+			}
+			else
+			{
+				ShmDcCommonData->ParaRelayWeldingOccur = NO;
+				ShmDcCommonData->ParaRelayDrivingOccur = NO;
+
+				ResetChargerAlarmCode ( gun_index, "011039" );
+				ResetChargerAlarmCode ( gun_index, "011040" );
+			}
+		}
+	}
+}
+
+bool PrecheckIsPass(byte gun_index)
+{
+	bool result = true;
+
+	// relay welding or driving 是反向
+	if (result)
+		result = !ShmDcCommonData->GunRelayWeldingOccur[gun_index];
+
+	if (result)
+		result = !ShmDcCommonData->ParaRelayWeldingOccur;
+
+	return result;
+}
+
+void CollectError(byte gun_index)
+{
+	errCollect.GunErrMessage |= ShmDcCommonData->ConnectErrList[gun_index].GunErrMessage;
+}
+
+void AlarmCheck(byte type)
+{
+	// type : Cha = 0、CCS = 1、GBT = 2
+	if (type == _Type_Chademo)
+	{
+		// GFD Trip
+		if (DetectBitValue(errCollect.GunErrMessage >> (8 * type), 0))
+			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoGfdTrip = YES;
+		else
+			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoGfdTrip = NO;
+
+		// UVP
+		if (DetectBitValue(errCollect.GunErrMessage >> (8 * type), 1))
+			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoOutputUVPFail = YES;
+		else
+			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoOutputUVPFail = NO;
+
+		// OTP
+		if (DetectBitValue(errCollect.GunErrMessage >> (8 * type), 2))
+			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoConnectorOTP = YES;
+		else
+			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoConnectorOTP = NO;
+
+		// OVP
+		if (DetectBitValue(errCollect.GunErrMessage >> (8 * type), 3))
+			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemChademoOutputOVP = YES;
+		else
+			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemChademoOutputOVP = NO;
+
+		// GFD Warning
+		if (DetectBitValue(errCollect.GunErrMessage >> (8 * type), 4))
+			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoGroundWarning = YES;
+		else
+			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ChademoGroundWarning = NO;
+
+		// Relay Welding
+		if (DetectBitValue(errCollect.GunErrMessage >> (8 * type), 5))
+			ShmStatusCodeData->FaultCode.FaultEvents.bits.ChademoOutputRelayWelding = YES;
+		else
+			ShmStatusCodeData->FaultCode.FaultEvents.bits.ChademoOutputRelayWelding = NO;
+
+		// Relay Driving
+		if (DetectBitValue(errCollect.GunErrMessage >> (8 * type), 6))
+			ShmStatusCodeData->FaultCode.FaultEvents.bits.ChademoOutputRelayDrivingFault = YES;
+		else
+			ShmStatusCodeData->FaultCode.FaultEvents.bits.ChademoOutputRelayDrivingFault = NO;
+
+		// Connect temp Sensor broken
+		if (DetectBitValue(errCollect.GunErrMessage >> (8 * type), 7))
+			ShmStatusCodeData->FaultCode.FaultEvents.bits.ChademoConnectorTempSensorBroken = YES;
+		else
+			ShmStatusCodeData->FaultCode.FaultEvents.bits.ChademoConnectorTempSensorBroken = NO;
+
+		// Output UCP
+		if (DetectBitValue(errCollect.GunErrMessage >> (8 * 3), 0))
+			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemChademoOutputUCP = YES;
+		else
+			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemChademoOutputUCP = NO;
+	}
+	else if (type == _Type_CCS)
+	{
+		// GFD Trip
+		if (DetectBitValue(errCollect.GunErrMessage >> (8 * type), 0))
+			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsGfdTrip = YES;
+		else
+			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsGfdTrip = NO;
+
+		// UVP
+		if (DetectBitValue(errCollect.GunErrMessage >> (8 * type), 1))
+			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsOutputUVPFail = YES;
+		else
+			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsOutputUVPFail = NO;
+
+		// OTP
+		if (DetectBitValue(errCollect.GunErrMessage >> (8 * type), 2))
+			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsConnectorOTP = YES;
+		else
+			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsConnectorOTP = NO;
+
+		// OVP
+		if (DetectBitValue(errCollect.GunErrMessage >> (8 * type), 3))
+			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemCcsOutputOVP = YES;
+		else
+			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemCcsOutputOVP = NO;
+
+		// GFD Warning
+		if (DetectBitValue(errCollect.GunErrMessage >> (8 * type), 4))
+			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsGroundfaultWarning = YES;
+		else
+			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsGroundfaultWarning = NO;
+
+		// Relay Welding
+		if (DetectBitValue(errCollect.GunErrMessage >> (8 * type), 5))
+			ShmStatusCodeData->FaultCode.FaultEvents.bits.CcsOutputRelayWelding = YES;
+		else
+			ShmStatusCodeData->FaultCode.FaultEvents.bits.CcsOutputRelayWelding = NO;
+
+		// Relay Driving
+		if (DetectBitValue(errCollect.GunErrMessage >> (8 * type), 6))
+			ShmStatusCodeData->FaultCode.FaultEvents.bits.CcsOutputRelayDrivingFault = YES;
+		else
+			ShmStatusCodeData->FaultCode.FaultEvents.bits.CcsOutputRelayDrivingFault = NO;
+
+		// Connect temp Sensor broken
+		if (DetectBitValue(errCollect.GunErrMessage >> (8 * type), 7))
+			ShmStatusCodeData->FaultCode.FaultEvents.bits.CcsConnectorTempSensorBroken = YES;
+		else
+			ShmStatusCodeData->FaultCode.FaultEvents.bits.CcsConnectorTempSensorBroken = NO;
+
+		// Output UCP
+		if (DetectBitValue(errCollect.GunErrMessage >> (8 * 3), 1))
+			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemCCSOutputUCP = YES;
+		else
+			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemCCSOutputUCP = NO;
+	}
+	else if (type == _Type_GB)
+	{
+		// GFD Trip
+		if (DetectBitValue(errCollect.GunErrMessage >> (8 * type), 0))
+			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbGfdTrip = YES;
+		else
+			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbGfdTrip = NO;
+
+		// UVP
+		if (DetectBitValue(errCollect.GunErrMessage >> (8 * type), 1))
+			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbtOutputUVPFail = YES;
+		else
+			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbtOutputUVPFail = NO;
+
+		// OTP
+		if (DetectBitValue(errCollect.GunErrMessage >> (8 * type), 2))
+			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbConnectorOTP = YES;
+		else
+			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbConnectorOTP = NO;
+
+		// OVP
+		if (DetectBitValue(errCollect.GunErrMessage >> (8 * type), 3))
+			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemGbOutputOVP = YES;
+		else
+			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemGbOutputOVP = NO;
+
+		// GFD Warning
+		if (DetectBitValue(errCollect.GunErrMessage >> (8 * type), 4))
+			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbGroundfaultWarning = YES;
+		else
+			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.GbGroundfaultWarning = NO;
+
+		// Relay Welding
+		if (DetectBitValue(errCollect.GunErrMessage >> (8 * type), 5))
+			ShmStatusCodeData->FaultCode.FaultEvents.bits.GbOutputRelayWelding = YES;
+		else
+			ShmStatusCodeData->FaultCode.FaultEvents.bits.GbOutputRelayWelding = NO;
+
+		// Relay Driving
+		if (DetectBitValue(errCollect.GunErrMessage >> (8 * type), 6))
+			ShmStatusCodeData->FaultCode.FaultEvents.bits.GbOutputRelayDrivingFault = YES;
+		else
+			ShmStatusCodeData->FaultCode.FaultEvents.bits.GbOutputRelayDrivingFault = NO;
+
+		// Connect temp Sensor broken
+		if (DetectBitValue(errCollect.GunErrMessage >> (8 * type), 7))
+			ShmStatusCodeData->FaultCode.FaultEvents.bits.GbConnectorTempSensorBroken = YES;
+		else
+			ShmStatusCodeData->FaultCode.FaultEvents.bits.GbConnectorTempSensorBroken = NO;
+
+		// Output UCP
+		if (DetectBitValue(errCollect.GunErrMessage >> (8 * 3), 2))
+			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemGBTOutputUCP = YES;
+		else
+			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemGBTOutputUCP = NO;
+	}
+}
+
+void SystemAlarmCheck()
+{
+	byte system = 3;
+	// Parallel Welding
+	if (DetectBitValue(errCollect.GunErrMessage >> (8 * system), 3))
+		ShmStatusCodeData->FaultCode.FaultEvents.bits.ParallelRelayWelding = YES;
+	else
+		ShmStatusCodeData->FaultCode.FaultEvents.bits.ParallelRelayWelding = NO;
+
+	// Parallel Driving
+	if (DetectBitValue(errCollect.GunErrMessage >> (8 * system), 4))
+		ShmStatusCodeData->FaultCode.FaultEvents.bits.ParallelRelayDriving = YES;
+	else
+		ShmStatusCodeData->FaultCode.FaultEvents.bits.ParallelRelayDriving = NO;
+}
+
+void SavePresentChargedDuration(byte gun_index)
+{
+	int _diffTime = 0;
+
+	ftime(&endChargingTime[gun_index]);
+	_diffTime = DiffTimeb(startChargingTime[gun_index], endChargingTime[gun_index]);
+
+	// below 0 or over 5 sec is abnormal
+	if (_diffTime < 0 ||
+			_diffTime > chargingInfo[gun_index]->PresentChargedDuration + 5)
+	{
+		_presentChargingTimeBuf[gun_index] = chargingInfo[gun_index]->PresentChargedDuration;
+		ftime(&startChargingTime[gun_index]);
+		PRINTF_FUNC("TimeZone changed (%d) \n", gun_index);
+	}
+	else
+		chargingInfo[gun_index]->PresentChargedDuration = _presentChargingTimeBuf[gun_index] + _diffTime;
+}
+
+void ClearEnergyTimePeriod(byte gun_index)
+{
+	for (int i = 0; i < 24; i++)
+	{
+		ShmDcCommonData->energy_time_period[gun_index][i] = 0;
+	}
+}
+
+void ChangeToMaxChargingMode()
+{
+	if (ShmSysConfigAndInfo->SysInfo.MainChargingMode == _MAIN_CHARGING_MODE_AVER &&
+			ShmPsuData->PsuStopChargeFlag == NO)
+	{
+		if (ShmSysConfigAndInfo->SysInfo.AcContactorStatus == YES)
+		{
+			// 均充 -> 最大充
+			if (ShmSysConfigAndInfo->SysInfo.BridgeRelayStatus == NO)
+			{
+				if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag == _REASSIGNED_NONE)
+				{
+					// 切換最大充起始位置
+					PRINTF_FUNC("======= Aver -> Max : Preparing. (Step 11) ======= \n");
+					ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_PREPARE_A_TO_M;
+				}
+			}
+			else if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag != _REASSIGNED_COMP &&
+					ShmSysConfigAndInfo->SysInfo.ReAssignedFlag != _REASSIGNED_WAITING)
+			{
+				PRINTF_FUNC("======= Aver -> Max : Current Balancing. (Step 14) ======= \n");
+				ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_WAITING;
+			}
+			else if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag == _REASSIGNED_COMP)
+			{
+				PRINTF_FUNC("======= Aver -> Max : Charging mode = MAX ======= \n");
+				ShmSysConfigAndInfo->SysInfo.MainChargingMode = _MAIN_CHARGING_MODE_MAX;
+				ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_NONE;
+			}
+		}
+		else
+		{
+			ShmSysConfigAndInfo->SysInfo.MainChargingMode = _MAIN_CHARGING_MODE_MAX;
+			ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_NONE;
+		}
+	}
+	else
+	{
+		// 需考量如果再切換均充過程 ? (預計要進入充電的臨時取消充電)
+		ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_NONE;
+	}
+}
+
+void CheckOcppCostAndPrice()
+{
+	if (ShmSysConfigAndInfo->SysConfig.BillingData.isBilling &&
+			strcmp((char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, "") != EQUAL &&
+			strcmp((char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId, "") != EQUAL)
+	{
+		ocpp_parsing_DT_defaultPrice_cmd();
+
+		ocpp_parsing_DT_userPrice_cmd();
+
+		ocpp_parsing_DT_running_final_cmd();
+	}
+}
+
+void CheckAuthrizeByEvccid()
+{
+	if (ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_ENABLE &&
+			ShmSysConfigAndInfo->SysConfig.isAuthrizeByEVCCID)
+		ShmDcCommonData->enObtainAuthorizbyCCID = YES;
+	else
+		ShmDcCommonData->enObtainAuthorizbyCCID = NO;
+
+}
+
+void CheckConnectorOTP(byte _index)
+{
+	if (chargingInfo[_index]->Type == _Type_Chademo)
+	{
+	//	if (chargingInfo[_index]->ConnectorTemp != UNDEFINED_TEMP)
+	//	{
+	// 		ResetChargerAlarmCode(_index, "011018");
+
+	//		if (chargingInfo[_index]->ConnectorTemp >= GUN_OTP_VALUE)
+	//			RecordAlarmCode(_index, "012229");
+	//		else if (chargingInfo[_index]->ConnectorTemp != 0 &&
+	//				chargingInfo[_index]->ConnectorTemp < GUN_OTP_RECOVERY)
+	//			ResetChargerAlarmCode(_index, "012229");
+	//	}
+	//	else
+	//	{
+	//		// 沒接上 Sensor or 異常
+	//		//RecordAlarmCode(_index, "011018");
+	//		ResetChargerAlarmCode(_index, "012229");
+	//	}
+	}
+	else if (chargingInfo[_index]->Type == _Type_CCS)
+	{
+		// CCS 不管甚麼輸出都會有槍溫偵測!!~
+		if (chargingInfo[_index]->ConnectorTemp != UNDEFINED_TEMP)
+		{
+			ResetChargerAlarmCode(_index, "011019");
+
+			if(chargingInfo[_index]->ConnectorTemp >= GUN_OTP_VALUE)
+				RecordAlarmCode(_index, "012230");
+			else if (chargingInfo[_index]->ConnectorTemp != 0 &&
+				chargingInfo[_index]->ConnectorTemp < GUN_OTP_RECOVERY)
+			ResetChargerAlarmCode(_index, "012230");
+		}
+		else
+		{
+			// 沒接上 Sensor or 異常
+			RecordAlarmCode(_index, "011019");
+			ResetChargerAlarmCode(_index, "012230");
+		}
+	}
+	else if (chargingInfo[_index]->Type == _Type_GB &&
+			chargingInfo[_index]->ModelType == 'B')
+	{
+		if (chargingInfo[_index]->ConnectorTemp != UNDEFINED_TEMP)
+		{
+			ResetChargerAlarmCode(_index, "011020");
+
+			if(chargingInfo[_index]->ConnectorTemp >= GUN_OTP_VALUE)
+				RecordAlarmCode(_index, "012231");
+			else if (chargingInfo[_index]->ConnectorTemp != 0 &&
+				chargingInfo[_index]->ConnectorTemp < GUN_OTP_RECOVERY)
+			ResetChargerAlarmCode(_index, "012231");
+		}
+		else
+		{
+			// 沒接上 Sensor or 異常
+			RecordAlarmCode(_index, "011020");
+			ResetChargerAlarmCode(_index, "012231");
+		}
+	}
+}
+
+void ChkConnectorBoardStop(byte index)
+{
+	if (isEvBoardStopChargeFlag(index) == YES)
+	{
+		// 板端要求停止 (錯誤)
+		ocpp_set_stopReason_by_cmd(index, "EVDisconnected");
+		ChargingAlarmProcess(index);
+	}
+	else if (isEvBoardNormalStopChargeFlag(index) == YES)
+	{
+		// 板端要求停止 (正常)
+		ocpp_set_stopReason_by_cmd(index, "EVDisconnected");
+		ChargingTerminalProcess(index);
+	}
+}
+
+void ChkPsuErrorStop(byte index)
+{
+	if (ShmPsuData->PsuGroup[index].GroupErrorFlag.bits.PsuFailure == YES ||
+			(ShmSysConfigAndInfo->SysInfo.IsAlternatvieConf && ShmPsuData->PsuGroup[0].GroupErrorFlag.bits.PsuFailure))
+	{
+		if (ShmSysConfigAndInfo->SysInfo.MainChargingMode == _MAIN_CHARGING_MODE_MAX)
+		{
+			for (byte gun_index = 0; gun_index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gun_index++)
+			{
+				if (chargingInfo[gun_index]->PresentChargingCurrent <= 5 &&
+						((chargingInfo[gun_index]->SystemStatus >= SYS_MODE_PREPARE_FOR_EVSE && chargingInfo[gun_index]->SystemStatus <= SYS_MODE_CHARGING) ||
+						(chargingInfo[gun_index]->SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0 && chargingInfo[gun_index]->SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1)))
+				{
+					ocpp_set_stopReason_by_cmd(gun_index, "Local");
+					ChargingAlarmProcess(gun_index);
+				}
+			}
+		}
+		else if (ShmSysConfigAndInfo->SysInfo.MainChargingMode == _MAIN_CHARGING_MODE_AVER)
+		{
+			if (chargingInfo[index]->PresentChargingCurrent <= 5)
+			{
+				ocpp_set_stopReason_by_cmd(index, "Local");
+				ChargingAlarmProcess(index);
+			}
+		}
+	}
+}
+
+void ChkBackendStop(byte index)
+{
+	if (ocpp_chk_invalid_id_cmd(index))
+	{
+		// Start Transaction Stop
+		ocpp_set_stopReason_by_cmd(index, "DeAuthorized");
+		ChargingTerminalProcess(index);
+	}
+	else if (ocpp_chk_remoteStop_cmd(index) == YES ||
+			WifiScheduleStop(index))
+	{
+		// 後臺要求停止
+		ChargingTerminalProcess(index);
+	}
+}
+
+void ChkConfigurationStop(byte index)
+{
+	if (CheckBackendChargingTimeout(index) ||
+			CheckBackendChargingEnergy(index))
+	{
+		// 網頁設定
+		PRINTF_FUNC("CheckBackendCharging stop charging (%d) \n", index);
+		ChargingTerminalProcess(index);
+		return;
+	}
+
+	if (CheckOcppChargingTimeout(index) ||
+			CheckOcppChargingEnergy(index) ||
+			CheckOcppChargingSOC(index))
+	{
+		// OCPP 設定
+		PRINTF_FUNC("CheckOcppCharging stop charging (%d) \n", index);
+		ChargingTerminalProcess(index);
+	}
+}
+
+void RecordGfdResult(byte index)
+{
+	if (chargingInfo[index]->Type == _Type_Chademo)
+	{
+		if (chargingInfo[index]->GroundFaultStatus == GFD_FAIL)
+		{
+			// GFD 錯誤停止
+			RecordAlarmCode(index, "012234");
+		}
+		else if (chargingInfo[index]->GroundFaultStatus == GFD_WARNING)
+		{
+			// GFD 警告
+			RecordAlarmCode(index, "012296");
+		}
+	}
+	else if (chargingInfo[index]->Type == _Type_GB)
+	{
+		if (chargingInfo[index]->GroundFaultStatus == GFD_FAIL)
+		{
+			// GFD 錯誤停止
+			RecordAlarmCode(index, "012236");
+		}
+		else if (chargingInfo[index]->GroundFaultStatus == GFD_WARNING)
+		{
+			// GFD 警告
+			RecordAlarmCode(index, "012298");
+		}
+	}
+	else if (chargingInfo[index]->Type == _Type_CCS)
+	{
+		if (chargingInfo[index]->GroundFaultStatus == GFD_FAIL)
+		{
+			// GFD 錯誤停止
+			RecordAlarmCode(index, "012235");
+		}
+		else if (chargingInfo[index]->GroundFaultStatus == GFD_WARNING)
+		{
+			// GFD 警告
+			RecordAlarmCode(index, "012297");
+		}
+	}
+}
+
+void CcidAuthorizationProcessing(byte gun_index)
+{
+	if (chargingInfo [gun_index]->Type == _Type_CCS &&
+			chargingInfo [gun_index]->IsAvailable &&
+			ShmDcCommonData->enObtainAuthorizbyCCID &&
+			chargingInfo[gun_index]->ConnectorPlugIn &&
+			strcmp ((char *)ShmSysConfigAndInfo->SysConfig.UserId, "") == EQUAL)
+	{
+		AddPlugInTimes(gun_index);
+		PRINTF_FUNC("CcidAuthorizationProcessing. \n");
+		ChangeGunSelectByIndex(gun_index);
+		setChargerMode(gun_index, SYS_MODE_MODE_REASSIGN_CHECK);
+	}
+}
+
+void CheckCcidAuthorizationFunction(byte gun_index)
+{
+	if (chargingInfo [gun_index]->Type == _Type_CCS &&
+			ShmDcCommonData->enObtainAuthorizbyCCID)
+	{
+		if (ShmDcCommonData->_authWithCcidFlag [gun_index] == _CCID_GET &&
+				ShmDcCommonData->_CcidAuthProcessStep == _CCID_NONE &&
+				strcmp ( (char *) ShmSysConfigAndInfo->SysConfig.UserId, "" ) == EQUAL)
+		{
+			PRINTF_FUNC ( "index = %d, Get for CCID (main).  \n", gun_index );
+			ShmDcCommonData->_authWithCcidFlag [gun_index] = _CCID_CHECK;
+			ShmDcCommonData->_CcidAuthProcessStep = _CCID_CHECK;
+			memcpy ( ShmSysConfigAndInfo->SysConfig.UserId, chargingInfo [gun_index]->EVCCID,
+					sizeof(chargingInfo [gun_index]->EVCCID) );
+		}
+		else if (ShmDcCommonData->_authWithCcidFlag [gun_index] == _CCID_CHECK)
+		{
+			if (ShmDcCommonData->_CcidAuthProcessStep == _CCID_AUTHFAIL)
+			{
+				PRINTF_FUNC ( "index = %d, _CCID_AUTHFAIL.  \n", gun_index );
+				ShmDcCommonData->_authWithCcidFlag [gun_index] = ShmDcCommonData->_CcidAuthProcessStep;
+				ShmDcCommonData->_CcidAuthProcessStep = _CCID_NONE;
+			}
+			else if (ShmDcCommonData->_CcidAuthProcessStep == _CCID_AUTHCOMP)
+			{
+				PRINTF_FUNC ( "index = %d, _CCID_AUTHCOMP.  \n", gun_index );
+				ShmDcCommonData->_authWithCcidFlag [gun_index] = ShmDcCommonData->_CcidAuthProcessStep;
+				strcpy((char *)chargingInfo[gun_index]->StartUserId, (char *)ShmSysConfigAndInfo->SysConfig.UserId);
+				strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
+				ShmDcCommonData->_CcidAuthProcessStep = _CCID_NONE;
+			}
+		}
+	}
+}
+
+bool isCcidEnterToCharging(byte gun_index)
+{
+	bool result = false;
+
+	if (ShmDcCommonData->enObtainAuthorizbyCCID)
+	{
+		if (ShmDcCommonData->_CcidAuthProcessStep == _CCID_AUTHCOMP)
+		{
+			for (byte _index = 0; _index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _index++)
+			{
+				if (chargingInfo [_index]->Type == _Type_CCS &&
+						chargingInfo [_index]->IsAvailable &&
+						ShmDcCommonData->_authWithCcidFlag [_index] == _CCID_CHECK)
+				{
+					if (_index != gun_index)
+						result = true;
+					break;
+				}
+			}
+			if (!result)
+				ShmDcCommonData->_CcidAuthProcessStep = _CCID_NONE;
+		}
+	}
+
+	return result;
+}
+
+bool IsNoneSelectAcModule()
+{
+	bool result = false;
+	if (ShmSysConfigAndInfo->SysConfig.AcConnectorCount == 0 ||
+			(ShmSysConfigAndInfo->SysConfig.AcConnectorCount > 0 &&
+			ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc == NO_DEFINE))
+	{
+		result = true;
+	}
+	return result;
+}
+
+bool IsSelectAcModule()
+{
+	bool result = false;
+	if (ShmSysConfigAndInfo->SysConfig.AcConnectorCount == 0)
+		return result;
+	else if (ShmSysConfigAndInfo->SysConfig.AcConnectorCount > 0 &&
+			ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc == DEFAULT_AC_INDEX)
+	{
+		result = true;
+	}
+	return result;
+}
+
+void DisplayPageChkByAcModule()
+{
+	if (IsSelectAcModule())
+	{
+		if (ac_chargingInfo [0]->ConnectorPlugIn == AC_SYS_A)
+		{
+			ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_WAIT_FOR_PLUG;
+		}
+		else
+		{
+			ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
+		}
+	}
+}
+
+int main(void)
+{
+	if(CreateShareMemory() == 0)
+	{
+		#ifdef SystemLogMessage
+		DEBUG_ERROR_MSG("CreatShareMemory NG \n");
+		#endif
+		if(ShmStatusCodeData!=NULL)
+		{
+			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory = 1;
+		}
+		sleep(5);
+		system("reboot -f");
+		sleep(5);
+		system("reboot -f");
+	}
+
+	PRINTF_FUNC("===== Boot and Initialization start ===== \n");
+	if (!InitialSystemDefaultConfig())
+	{
+		DEBUG_ERROR_MSG("InitialSystemDefaultConfig NG \n");
+		StopProcessingLoop();
+	}
+
+	PRINTF_FUNC("CheckConnectorTypeStatus and CheckIsAlternatvie \n");
+	CheckGunTypeFromHw();
+	CheckIsAlternatvieByModelName();
+	InitialShareMemoryInfo();
+
+	PRINTF_FUNC("InitialShareMemoryInfo OK. \n");
+	if (ShmSysConfigAndInfo->SysInfo.ChargerType == _CHARGER_TYPE_IEC)
+		PRINTF_FUNC("ChargerType (IEC or UL) = IEC \n");
+	else
+		PRINTF_FUNC("ChargerType (IEC or UL) = UL \n");
+	ChangeLcmByIndex(_LCM_INIT);
+	if (!CheckConnectorTypeStatus())
+		isModelNameMatch = false;
+
+	Initialization();
+	PRINTF_FUNC("===== Initial Complete ===== \n");
+
+	PRINTF_FUNC("===== Spawn all Task and self test start ===== \n");
+	SpawnTask();
+
+	if (!isModelNameMatch)
+	{
+		// Module Name 與硬體對應不正確
+		PRINTF_FUNC("*** Module Name & HW info none match : Please check if the Model name and HW are matched. ***\n");
+		ShmStatusCodeData->AlarmCode.AlarmEvents.bits.ModelNameNoneMatchStestFail = YES;
+		ChangeLcmByIndex(_LCM_FIX);
+		sleep(3);
+		KillTask();
+		StopProcessingLoop();
+	}
+
+	PRINTF_FUNC("Module Name & HW info correct. \n");
+	CreateTimeoutFork();
+	if (!DEBUG_ALSTON)
+	{
+		PRINTF_FUNC("Self test run..\n");
+		SelfTestRun();
+	}
+	else
+	{
+		sleep(3);
+		ShmSysConfigAndInfo->SysInfo.SelfTestSeq = _STEST_COMPLETE;
+	}
+	StopSystemTimeoutDet();
+
+	if (!DEBUG_ALSTON &&
+			(ShmSysConfigAndInfo->SysInfo.SelfTestSeq == _STEST_FAIL ||
+			ShmPsuData->Work_Step == _NO_WORKING ||
+			ShmStatusCodeData->InfoCode.InfoEvents.bits.CcsSeccTimeoutQCA7000Comm == YES ||
+			strcmp((char *)ShmSysConfigAndInfo->SysInfo.LcmHwRev, " ") == EQUAL))
+	{
+		if (ShmSysConfigAndInfo->SysWarningInfo.Level != _ALARM_LEVEL_CRITICAL)
+		{
+			if (!DisplaySelfTestFailReason() &&
+					ShmDcCommonData->rebootCount < 1)
+			{
+				PRINTF_FUNC("=======Soft reboot for retry self-test======= \n");
+				SetupRebootCount(1);
+				sleep(3);
+				KillAllTask();
+				system("/usr/bin/run_evse_restart.sh");
+			}
+			else if (ShmDcCommonData->rebootCount < 1)
+			{
+				PRINTF_FUNC("=======Soft reboot for retry self-test (Normal)======= \n");
+				SetupRebootCount(1);
+				sleep(3);
+				KillAllTask();
+				system("/usr/bin/run_evse_restart.sh");
+			}
+			else
+				SetupRebootCount(0);
+		}
+
+		for (byte gun_index = 0; gun_index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gun_index++)
+		{
+			ChargingAlarmProcess(gun_index);
+		}
+
+		//ChangeLcmByIndex(_LCM_FIX);
+		sleep(3);
+		//if (ShmSysConfigAndInfo->SysWarningInfo.Level == 2)
+		//{
+			KillTaskExceptDetectTask();
+		//}
+		//else
+		//	KillTask();
+
+		StopProcessingLoop();
+	}
+	else
+	{
+		for (byte gun_index = 0; gun_index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gun_index++)
+		{
+			setChargerMode(gun_index, SYS_MODE_IDLE);
+		}
+
+		SetupRebootCount(0);
+	}
+	PRINTF_FUNC("===== Self Test Complete ===== \n");
+
+	PRINTF_FUNC("===== Finally Create DB ===== \n");
+	// Local DB
+	if(DB_Open(localDb) != PASS)
+	{
+		PRINTF_FUNC("DB_Open fail. \n");
+		isDb_ready = false;
+	}
+	else
+	{
+		isDb_ready = true;
+		for (int _acIndex = 0; _acIndex < ShmSysConfigAndInfo->SysConfig.AcConnectorCount; _acIndex++)
+		{
+			byte hasDc = ((ShmSysConfigAndInfo->SysConfig.TotalConnectorCount > 0) ? 1 : 0);
+			ac_chargingInfo[0]->IsAvailable = DB_Get_Operactive(localDb, _acIndex + hasDc);
+		}
+
+		for(int _index=0; _index< ShmSysConfigAndInfo->SysConfig.TotalConnectorCount;_index++)
+		{
+			chargingInfo[_index]->IsAvailable = DB_Get_Operactive(localDb, _index);
+			chargingInfo[_index]->PowerConsumption = DB_Get_PowerConsumption(localDb, _index);
+		}
+		DB_Reboot_Record(localDb);
+	}
+
+	if (NetworkDB_Open(networkDb) != PASS)
+	{
+		PRINTF_FUNC("NetworkDB_Open fail. \n");
+	}
+
+	ChangeLcmByIndex(_LCM_IDLE);
+	sleep(1);
+	CreateRfidFork();
+	sleep(1);
+	if (!DEBUG_ALSTON)
+	{
+		PRINTF_FUNC("===== Create chk system Task ===== \n");
+		CreateCheckSystemTaskFork();
+	}
+	PRINTF_FUNC("===== Create DB End ===== \n");
+
+	PRINTF_FUNC("===== Charger info ===== ");
+	PRINTF_FUNC("SW Version = %s", ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
+	PRINTF_FUNC("ModelName = %s", ShmSysConfigAndInfo->SysConfig.ModelName);
+	CheckFwSlotStatusLog();
+	AdjustChargerCurrent();
+
+	GetTimespecFunc(&_cmdMainPriority_time);
+	_ocppProfileChkFlag_1 = 0;
+	_ocppProfileChkFlag_2 = 0;
+
+	if(strcmp((char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, "") == EQUAL)
+	{
+		DEBUG_ERROR_MSG("URL is empty kill Module_OcppBackend...\n");
+		system ("pkill OcppBackend");
+	}
+
+	int _mainTimebuf = 0;
+
+	for (;;)
+	{
+		if (ShmDcCommonData->_isAutoRunTest != _isTestRun)
+		{
+			if (ShmDcCommonData->_isAutoRunTest == YES)
+			{
+				GetTimespecFunc(&_autoRuntestTime);
+			}
+
+			_isTestRun = ShmDcCommonData->_isAutoRunTest;
+		}
+
+		if (ShmSysConfigAndInfo->SysConfig.AcConnectorCount > 0)
+		{
+			ocpp_ac_chk_availability_cmd();
+			ocpp_ac_chk_unlock_cmd();
+		}
+
+		ocpp_auto_response_BootNotification();
+		ocpp_chk_reset_cmd(NO);
+		ButtonTriggerEvent();
+
+		if (!DEBUG_ALSTON)
+			ChkPrimaryStatus();
+
+		if ((IsConnectorWholeIdle() ||
+				ShmSysConfigAndInfo->SysInfo.PageIndex == _LCM_FIX))
+		{
+			CheckFactoryConfigFunction();
+
+			CheckFwUpdateFunction();
+		}
+		if (ShmSysConfigAndInfo->SysConfig.TotalConnectorCount == 0)
+		{
+			sleep(1);
+			continue;
+		}
+
+		// OCPP 邏輯
+		ocpp_chk_remoteStart_cmd();
+		// 讀卡邏輯
+		ScannerCardProcess();
+		// 當 AC 沒有搭上時,清除一些錯誤碼
+		ClearAlarmCodeWhenAcOff();
+		// 確認是否要回到充電中的槍畫面邏輯判斷
+		CheckReturnToChargingConn();
+
+		if ((_acgunIndex > 0 && isDetectPlugin() && !isCardScan))
+		{
+			ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_WAIT_FOR_PLUG;
+		}
+
+		_mainTimebuf = GetTimeoutValue(&_cmdMainPriority_time);
+
+		if (_mainTimebuf < 0)
+			GetTimespecFunc(&_cmdMainPriority_time);
+
+		if (GetTimeoutValue(&_cmdMainPriority_time) >= 5)
+		{
+			if (ShmPsuData->PsuStopChargeFlag)
+				Check267Alarm();
+
+			CheckTask();
+
+			Run4gResetProc();
+
+			for (byte _index = 0; _index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _index++)
+			{
+				if ((chargingInfo[_index]->SystemStatus >= SYS_MODE_PREPARE_FOR_EVSE && chargingInfo[_index]->SystemStatus <= SYS_MODE_CHARGING) ||
+						(chargingInfo[_index]->SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0 && chargingInfo[_index]->SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))
+				{
+					ocpp_chargingProfile_process(_index);
+
+					if (chargingInfo[_index]->SystemStatus == SYS_MODE_CHARGING &&
+							((_index == 0 && _ocppProfileChkFlag_1 >= 12) ||
+							(_index == 1 && _ocppProfileChkFlag_2 >= 12)))
+					{
+						ocpp_lift_profileReq_cmd(_index);
+						gunOutputVol[_index] = chargingInfo[_index]->PresentChargingVoltage;
+						if (_index == 0)
+							_ocppProfileChkFlag_1 = 0;
+						else if (_index == 1)
+							_ocppProfileChkFlag_2 = 0;
+					}
+					else if (chargingInfo[_index]->SystemStatus != SYS_MODE_CHARGING)
+					{
+						ocpp_lift_profileReq_cmd(_index);
+						if (_index == 0)
+							_ocppProfileChkFlag_1 = 0;
+						else if (_index == 1)
+							_ocppProfileChkFlag_2 = 0;
+					}
+					else
+					{
+						if (_index == 0)
+							_ocppProfileChkFlag_1++;
+						else if (_index == 1)
+							_ocppProfileChkFlag_2++;
+					}
+
+					if (chargingInfo[_index]->SystemStatus >= SYS_MODE_CHARGING &&
+							chargingInfo[_index]->SystemStatus <= SYS_MODE_ALARM)
+					{
+						DB_Update_PowerConsumption(localDb, _index, chargingInfo[_index]->PowerConsumption);
+					}
+				}
+
+				if (chargingInfo[_index]->SystemStatus == SYS_MODE_RESERVATION)
+				{
+					if (opcc_chk_reserve_expired(_index))
+					{
+						chargingInfo[_index]->SystemStatus = SYS_MODE_IDLE;
+					}
+				}
+
+				// OTP
+				CheckConnectorOTP(_index);
+			}
+
+			for (byte _index = 0; _index < ShmSysConfigAndInfo->SysConfig.AcConnectorCount; _index++)
+			{
+				if ((ac_chargingInfo[0]->SystemStatus >= SYS_MODE_PREPARE_FOR_EVSE && ac_chargingInfo[0]->SystemStatus <= SYS_MODE_CHARGING) ||
+						(ac_chargingInfo[0]->SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0 && ac_chargingInfo[0]->SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))
+				{
+					ocpp_ac_chargingProfile_process();
+				}
+
+				if ((ac_chargingInfo[_index]->SystemStatus >= SYS_MODE_PREPARING &&
+						ac_chargingInfo[_index]->SystemStatus <= SYS_MODE_CHARGING))
+				{
+					if (ac_chargingInfo[_index]->SystemStatus == SYS_MODE_CHARGING &&
+							_ac_ocppProfileChkFlag == 12)
+					{
+						ocpp_ac_lift_profileReq_cmd(_index);
+						_ac_ocppProfileChkFlag = 0;
+					}
+					else if (ac_chargingInfo[_index]->SystemStatus != SYS_MODE_CHARGING)
+					{
+						ocpp_ac_lift_profileReq_cmd(_index);
+						_ac_ocppProfileChkFlag = 0;
+					}
+					else
+						_ac_ocppProfileChkFlag++;
+				}
+			}
+
+			CheckOcppCostAndPrice();
+
+			CheckAuthrizeByEvccid();
+
+			GetTimespecFunc(&_cmdMainPriority_time);
+
+			if (!DEBUG_ALSTON && wtdFd == -1)
+			{
+				PRINTF_FUNC("===== Create crazy dog ===== \n");
+				CreateWatchdog();
+			}
+		}
+
+		if(ShmSysConfigAndInfo->SysConfig.ModelName[3] == 'M' ||
+				ShmSysConfigAndInfo->SysConfig.ModelName[3] == 'L')
+			CheckStatusOfMeter();
+
+		// 確認當前錯誤 Level = 2 ?
+		ReviewCriticalAlarm();
+		errCollect.GunErrMessage = 0;
+
+		if (ShmSysConfigAndInfo->SysConfig.AcConnectorCount > 0)
+		{
+			CheckAcOcppProfileConfirm();
+			ocpp_ac_chk_reserved_cmd();
+		}
+
+		for (byte gun_index = 0; gun_index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gun_index++)
+		{
+			//CheckGpioInStatus();
+			// 確認系統的錯誤狀態
+			CheckSystemErrorFunction(gun_index);
+			// 確認 Relay Welding or Driving Fault
+			CheckRelayWeldingOrDrivingFault(gun_index);
+
+			// 收集各槍的錯誤狀態
+			CollectError(gun_index);
+
+			ocpp_chk_reserved_cmd(gun_index);
+			ocpp_chk_availability_cmd(gun_index);
+			ocpp_chk_unlock_cmd(gun_index);
+
+			// check charging profile confirm flag
+			CheckOcppProfileConfirm(gun_index);
+
+			//PRINTF_FUNC("index = %d, ErrorCode = %s \n", gun_index, ShmOCPP16Data->StatusNotification[gun_index].ErrorCode);
+			switch(chargingInfo[gun_index]->SystemStatus)
+			{
+				case SYS_MODE_IDLE:
+				case SYS_MODE_RESERVATION:
+				case SYS_MODE_MAINTAIN:
+				case SYS_MODE_FAULT:
+				{
+					if ((chargingInfo[gun_index]->SystemStatus == SYS_MODE_IDLE ||
+							chargingInfo[gun_index]->SystemStatus == SYS_MODE_RESERVATION) &&
+							isModeChange(gun_index))
+					{
+						if (chargingInfo[gun_index]->SystemStatus == SYS_MODE_IDLE)
+						{
+							PRINTF_FUNC("================= SYS_MODE_IDLE (%x) ================  \n", gun_index);
+							chargingInfo[gun_index]->ReservationId = -1;
+						}
+						else if (chargingInfo[gun_index]->SystemStatus == SYS_MODE_RESERVATION)
+						{
+							PRINTF_FUNC("================= SYS_MODE_RESERVATION (%x) ================  \n", gun_index);
+							PRINTF_FUNC("================= Id : %s ================  \n", ShmDcCommonData->_reserved_UserId[gun_index]);
+						}
+						chargingInfo[gun_index]->PresentChargedDuration = 0;
+						chargingInfo[gun_index]->RemainChargingDuration = 0;
+						chargingInfo[gun_index]->PresentChargingVoltage = 0;
+						chargingInfo[gun_index]->PresentChargingCurrent = 0;
+						strcpy((char *)chargingInfo[gun_index]->StartDateTime, "00:00:00");
+						strcpy((char *)chargingInfo[gun_index]->StopDateTime, "00:00:00");
+						strcpy((char *)chargingInfo[gun_index]->StartUserId, "");
+						strcpy((char *)chargingInfo[gun_index]->EVCCID, "");
+						_isSendStartTransaction[gun_index] = false;
+						ClearEnergyTimePeriod(gun_index);
+						gunOutputVol[gun_index] = 0.0;
+						ocpp_clear_stopReason(gun_index);
+
+						ocpp_auto_response_StartTransationConf(gun_index);
+						ShmDcCommonData->startTransactionFlag[gun_index] = START_TRANSATION_STATUS_WAIT;
+						ShmDcCommonData->_authWithCcidFlag[gun_index] = _CCID_NONE;
+					}
+
+					if (chargingInfo[gun_index]->IsAvailable == NO)
+					{
+						setChargerMode(gun_index, SYS_MODE_MAINTAIN);
+					}
+
+					if (ShmSysConfigAndInfo->SysWarningInfo.Level == _ALARM_LEVEL_CRITICAL)
+					{
+						if (gun_index == ShmSysConfigAndInfo->SysInfo.CurGunSelected)
+							ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_FIX;
+						else if (chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus != SYS_MODE_IDLE &&
+								chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus != SYS_MODE_RESERVATION &&
+								chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus != SYS_MODE_MAINTAIN &&
+								chargingInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus != SYS_MODE_FAULT)
+							ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
+
+						ClearDetectPluginFlag();
+						ocpp_set_errCode_cmd(gun_index);
+						setChargerMode(gun_index, SYS_MODE_FAULT);
+					}
+					else
+					{
+						ChangeToMaxChargingMode();
+
+						if (PrecheckIsPass(gun_index))
+						{
+							if (chargingInfo[gun_index]->SystemStatus == SYS_MODE_FAULT)
+							{
+								ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
+								setChargerMode(gun_index, SYS_MODE_IDLE);
+							}
+
+							CcidAuthorizationProcessing(gun_index);
+
+							//
+							{
+								// Idle 正常程序起點
+								// 判斷是否有啟用檢查插槍
+								if(isDetectPlugin())
+								{
+									// 卡號驗證成功後,等待充電槍插入充電車
+									if (chargingInfo[gun_index]->RemoteStartFlag == YES)
+									{
+										if (chargingInfo[gun_index]->ConnectorPlugIn == YES &&
+												chargingInfo[gun_index]->IsAvailable)
+										{
+											PRINTF_FUNC("Conn %d Start Charging : Remote \n", gun_index);
+											chargingInfo[gun_index]->RemoteStartFlag = NO;
+											chargingInfo[gun_index]->isRemoteStart = YES;
+											ChangeGunSelectByIndex(gun_index);
+											AddPlugInTimes(gun_index);
+											setChargerMode(gun_index, SYS_MODE_MODE_REASSIGN_CHECK);
+											strcpy((char *)chargingInfo[gun_index]->StartUserId, "");
+											ClearDetectPluginFlag();
+											continue;
+										}
+									}
+									else if (chargingInfo[gun_index]->ReservedStartFlag == YES)
+									{
+										if (chargingInfo[gun_index]->ConnectorPlugIn == YES &&
+												chargingInfo[gun_index]->IsAvailable)
+										{
+											chargingInfo[gun_index]->ReservedStartFlag = NO;
+											ChangeGunSelectByIndex(gun_index);
+											AddPlugInTimes(gun_index);
+											strcpy((char *)chargingInfo[gun_index]->StartUserId, (char *)ShmDcCommonData->_reserved_UserId[gun_index]);
+											PRINTF_FUNC("Conn %d Start Charging : Reserved CardNumber = %s \n", gun_index, chargingInfo[gun_index]->StartUserId);
+											strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
+											strcpy((char *)ShmDcCommonData->_reserved_UserId[gun_index], "");
+											// 當前操作的槍號,進入 Preparing
+											setChargerMode(gun_index, SYS_MODE_MODE_REASSIGN_CHECK);
+											ClearDetectPluginFlag();
+											continue;
+										}
+									}
+									else if (ShmSysConfigAndInfo->SysInfo.OrderCharging == NO_DEFINE)
+									{
+										if (chargingInfo[gun_index]->ConnectorPlugIn == YES &&
+												chargingInfo[gun_index]->IsAvailable &&
+												chargingInfo[gun_index]->SystemStatus == SYS_MODE_IDLE)
+										{
+											ChangeGunSelectByIndex(gun_index);
+											AddPlugInTimes(gun_index);
+											strcpy((char *)chargingInfo[gun_index]->StartUserId, (char *)ShmSysConfigAndInfo->SysConfig.UserId);
+											PRINTF_FUNC("Conn %d Start Charging : RFID CardNumber = %s \n", gun_index, chargingInfo[gun_index]->StartUserId);
+											strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
+											// 當前操作的槍號,進入 Preparing
+											setChargerMode(gun_index, SYS_MODE_MODE_REASSIGN_CHECK);
+											ClearDetectPluginFlag();
+											continue;
+										}
+									}
+
+									if (!isCardScan &&
+											(gun_index == ShmSysConfigAndInfo->SysInfo.CurGunSelected ||
+											(ShmSysConfigAndInfo->SysConfig.AcConnectorCount > 0 && ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc != NO_DEFINE)))
+									{
+										// LCM => Waiting for plugging
+										ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_WAIT_FOR_PLUG;
+									}
+								}
+								else if (ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_DISABLE &&
+										(chargingInfo[gun_index]->ConnectorPlugIn == YES && chargingInfo[gun_index]->IsAvailable))
+								{
+									PRINTF_FUNC("Conn %d Start Charging : Plug and charing \n", gun_index);
+									bool isCanStartChargingFlag = GetStartChargingByAlterMode(gun_index);
+
+									if (isCanStartChargingFlag)
+									{
+										ChangeGunSelectByIndex(gun_index);
+										AddPlugInTimes(gun_index);
+										setChargerMode(gun_index, SYS_MODE_MODE_REASSIGN_CHECK);
+										ClearDetectPluginFlag();
+										ocpp_get_freeVendor(gun_index);
+										continue;
+									}
+								}
+								else
+								{
+									if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index)
+									{
+										if ((ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_DISABLE ||
+												ocpp_remote_start_wait_cmd()))
+										{
+											if (ShmSysConfigAndInfo->SysConfig.AcConnectorCount > 0 &&
+													ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc == DEFAULT_AC_INDEX)
+											{
+												if (ac_chargingInfo[0]->ConnectorPlugIn == AC_SYS_A)
+												{
+													ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_WAIT_FOR_PLUG;
+												}
+												else
+												{
+													ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
+												}
+											}
+											else
+											{
+												ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_WAIT_FOR_PLUG;
+											}
+										}
+										else if (ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_ENABLE &&
+												ShmSysConfigAndInfo->SysInfo.SystemPage == _LCM_WAIT_FOR_PLUG)
+										{
+											ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
+										}
+//										else if (ChkAcModuleStatusIsNone() &&
+//												(ShmSysConfigAndInfo->SysInfo.SystemPage <= _LCM_AUTHORIZING && ShmSysConfigAndInfo->SysInfo.SystemPage >= _LCM_AUTHORIZ_FAIL))
+//										{
+//											ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
+//										}
+										ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_IDLE;
+									}
+								}
+							} // Idle 正常程序終點
+						}
+						else
+						{
+							setChargerMode(gun_index, SYS_MODE_FAULT);
+							if (gun_index == ShmSysConfigAndInfo->SysInfo.CurGunSelected)
+								ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_FIX;
+						}
+
+						ReleaseSysAlarmCode(gun_index);
+					}
+				}
+					break;
+				case SYS_MODE_MODE_REASSIGN_CHECK:
+				{
+					if (isModeChange(gun_index))
+					{
+						PRINTF_FUNC("================= SYS_MODE_MODE_REASSIGN_CHECK (%x) ================ \n", gun_index);
+						ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
+						if (ShmSysConfigAndInfo->SysInfo.OrderCharging != NO_DEFINE)
+							ShmSysConfigAndInfo->SysInfo.OrderCharging = NO_DEFINE;
+						StopSystemTimeoutDet();
+					}
+
+					ocpp_clear_errorCode_cmd(gun_index);
+					bool isRessign = false;
+					if (ShmSysConfigAndInfo->SysConfig.TotalConnectorCount > 1 && ShmSysConfigAndInfo->SysInfo.IsAlternatvieConf == NO)
+					{
+						if (ShmSysConfigAndInfo->SysInfo.MainChargingMode == _MAIN_CHARGING_MODE_MAX)
+						{
+							for (byte index = 0; index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; index++)
+							{
+								if (chargingInfo[index]->SystemStatus != SYS_MODE_MODE_REASSIGN_CHECK)
+								{
+									if (((chargingInfo[index]->SystemStatus >= SYS_MODE_PREPARING && chargingInfo[index]->SystemStatus <= SYS_MODE_CHARGING) ||
+											(chargingInfo[index]->SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0 && chargingInfo[index]->SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1)) &&
+											chargingInfo[index]->SystemStatus != SYS_MODE_MAINTAIN &&
+											chargingInfo[index]->SystemStatus != SYS_MODE_RESERVATION)
+									{
+										// A 槍在充電過程中 - 進行分配動作
+										PRINTF_FUNC("======= Max -> Aver : Preparing. (Step 1) ======= \n");
+										ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_PREPARE_M_TO_A;
+										isRessign = true;
+										break;
+									}
+									else
+									{
+										// A 槍已結束充電 - 直接回 B 槍最大充
+										PRINTF_FUNC("======= Max -> Aver : Charging mode = MAX (Keep) ======= \n");
+										//ShmSysConfigAndInfo->SysInfo.MainChargingMode = _MAIN_CHARGING_MODE_AVER;
+										break;
+									}
+								}
+							}
+						}
+						else if (ShmSysConfigAndInfo->SysInfo.MainChargingMode == _MAIN_CHARGING_MODE_AVER)
+						{
+							// 如果在切換最大充的過程中,需等待最大充切換完成後,再走均充流程
+							if (ShmSysConfigAndInfo->SysInfo.BridgeRelayStatus == YES)
+							{
+								if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag != _REASSIGNED_COMP &&
+										ShmSysConfigAndInfo->SysInfo.ReAssignedFlag != _REASSIGNED_WAITING)
+								{
+									PRINTF_FUNC("======= Aver -> Max : Aver -> Max : Current Balancing. (Step 14) ======= \n");
+									ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_WAITING;
+								}
+								else if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag == _REASSIGNED_COMP)
+								{
+									PRINTF_FUNC("======= Aver -> Max : Charging mode = MAX ======= \n");
+									ShmSysConfigAndInfo->SysInfo.MainChargingMode = _MAIN_CHARGING_MODE_MAX;
+									ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_NONE;
+									continue;
+								}
+							}
+							else
+							{
+								setChargerMode(gun_index, SYS_MODE_PREPARING);
+							}
+
+							if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index)
+								ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_PRE_CHARGE;
+							continue;
+						}
+					}
+
+					if (isRessign)
+						setChargerMode(gun_index, SYS_MODE_REASSIGN);
+					else
+						setChargerMode(gun_index, SYS_MODE_PREPARING);
+
+					if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index &&
+							ShmSysConfigAndInfo->SysConfig.AcConnectorCount > 0)
+					{
+						if (IsNoneSelectAcModule())
+						{
+							if (ShmSysConfigAndInfo->SysInfo.SystemPage <= _LCM_AUTHORIZING ||
+									ShmSysConfigAndInfo->SysInfo.SystemPage >= _LCM_AUTHORIZ_FAIL)
+							{
+								ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
+							}
+						}
+						else
+						{
+							if ((ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_DISABLE ||
+									ocpp_remote_start_wait_cmd ()))
+							{
+								DisplayPageChkByAcModule();
+							}
+						}
+
+						ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_PRE_CHARGE;
+					}
+					else if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index)
+					{
+						ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_PRE_CHARGE;
+						ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
+					}
+				}
+					break;
+				case SYS_MODE_REASSIGN:
+				{
+					if (isModeChange(gun_index))
+					{
+						PRINTF_FUNC("================== SYS_MODE_REASSIGN (%x) ================ \n", gun_index);
+					}
+
+					ocpp_clear_errorCode_cmd(gun_index);
+
+					// 重新分配,此階段主要是讓已經在充電或者準備進入充電前的緩衝
+					// 此狀態下~ 控制權在於 PSU 及 EV小板 Process
+					if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag == _REASSIGNED_RELAY_M_TO_A &&
+							ShmSysConfigAndInfo->SysInfo.BridgeRelayStatus == NO)
+					{
+						PRINTF_FUNC("======= Max -> Aver : Charging mode = AVER ======= \n");
+						ShmSysConfigAndInfo->SysInfo.MainChargingMode = _MAIN_CHARGING_MODE_AVER;
+						ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_NONE;
+					}
+
+					if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag == _REASSIGNED_NONE)
+					{
+						if ((ShmSysConfigAndInfo->SysInfo.BridgeRelayStatus == NO &&
+								ShmSysConfigAndInfo->SysInfo.MainChargingMode == _MAIN_CHARGING_MODE_AVER) ||
+							(ShmSysConfigAndInfo->SysInfo.BridgeRelayStatus == YES &&
+								ShmSysConfigAndInfo->SysInfo.MainChargingMode == _MAIN_CHARGING_MODE_MAX))
+						{
+							setChargerMode(gun_index, SYS_MODE_PREPARING);
+						}
+					}
+
+					if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index &&
+							ShmSysConfigAndInfo->SysConfig.AcConnectorCount > 0)
+					{
+						if (IsNoneSelectAcModule())
+						{
+							if (ShmSysConfigAndInfo->SysInfo.SystemPage <= _LCM_AUTHORIZING ||
+									ShmSysConfigAndInfo->SysInfo.SystemPage >= _LCM_AUTHORIZ_FAIL)
+							{
+								ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
+							}
+						}
+						else
+						{
+							if ((ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_DISABLE ||
+									ocpp_remote_start_wait_cmd ()))
+							{
+								DisplayPageChkByAcModule();
+							}
+						}
+						ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_PRE_CHARGE;
+					}
+					else if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index)
+					{
+						ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_PRE_CHARGE;
+						ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
+					}
+				}
+					break;
+				case SYS_MODE_PREPARING:
+				{
+					if (isModeChange(gun_index))
+					{
+						PRINTF_FUNC("=================== SYS_MODE_PREPARING (%x) =============== \n", gun_index);
+						StopGunInfoTimeoutDet(gun_index);
+						StartGunInfoTimeoutDet(gun_index, Timeout_Preparing);
+					}
+
+					ocpp_clear_errorCode_cmd(gun_index);
+
+					if (ShmPsuData->SystemPresentPsuQuantity > 0 && ShmPsuData->SystemAvailablePower > 10 &&
+							ShmPsuData->Work_Step == _WORK_CHARGING &&
+							GetTimeoutValue(&chargingInfo[gun_index]->ConnectorTimeout) >= 5)
+					{
+						setChargerMode(gun_index, SYS_MODE_PREPARE_FOR_EV);
+					}
+
+					if (ShmSysConfigAndInfo->SysConfig.TotalConnectorCount >= 2)
+					{
+						bool oughtAver = true;
+						for (byte index = 0; index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; index++)
+						{
+							// 共同進入充電邏輯
+							if (chargingInfo[index]->SystemStatus != SYS_MODE_PREPARING)
+							{
+								oughtAver = false;
+								break;
+							}
+						}
+
+						if (oughtAver)
+						{
+							PRINTF_FUNC("********* Smart Charging : _REASSIGNED_NONE (AVER) ********** \n");
+							ShmSysConfigAndInfo->SysInfo.MainChargingMode = _MAIN_CHARGING_MODE_AVER;
+							ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_NONE;
+						}
+					}
+
+					if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index &&
+							ShmSysConfigAndInfo->SysConfig.AcConnectorCount > 0)
+					{
+						if (IsNoneSelectAcModule())
+						{
+							if (ShmSysConfigAndInfo->SysInfo.SystemPage <= _LCM_AUTHORIZING ||
+									ShmSysConfigAndInfo->SysInfo.SystemPage >= _LCM_AUTHORIZ_FAIL)
+							{
+								ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
+								}
+						}
+						else
+						{
+							if ((ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_DISABLE ||
+									ocpp_remote_start_wait_cmd ()))
+							{
+								DisplayPageChkByAcModule();
+							}
+						}
+						ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_PRE_CHARGE;
+					}
+					else if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index)
+					{
+						ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_PRE_CHARGE;
+						ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
+					}
+				}
+					break;
+				case SYS_MODE_PREPARE_FOR_EV: // 等待車端的通訊 (EV 小板),待車端回報後,開始樁端的測試
+				{
+					if (isModeChange(gun_index))
+					{
+						PRINTF_FUNC("================== SYS_MODE_PREPARE_FOR_EV (%x) ================ \n", gun_index);
+						_presentChargingTimeBuf[gun_index] = 0;
+						//strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
+						StopGunInfoTimeoutDet(gun_index);
+						StartGunInfoTimeoutDet(gun_index, Timeout_EvChargingDet);
+						ShmDcCommonData->startTransactionFlag[gun_index] = START_TRANSATION_STATUS_WAIT;
+
+						// Start Transation
+						printf("StartUserId = %s \n", chargingInfo[gun_index]->StartUserId);
+						if (ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_DISABLE ||
+								strcmp((char *)chargingInfo[gun_index]->StartUserId, "") != EQUAL ||
+								chargingInfo[gun_index]->isRemoteStart == YES)
+						{
+							_isSendStartTransaction[gun_index] = true;
+							ocpp_set_startTransation_cmd(gun_index);
+							GetTimespecFunc(&_startTransation_time[gun_index]);
+						}
+						ShmDcCommonData->_CcidAuthProcessStep = _CCID_NONE;
+					}
+
+					ocpp_clear_errorCode_cmd(gun_index);
+
+					CheckCcidAuthorizationFunction(gun_index);
+
+					if (!_isSendStartTransaction[gun_index] &&
+							chargingInfo [gun_index]->Type == _Type_CCS &&
+							ShmDcCommonData->enObtainAuthorizbyCCID)
+					{
+						if (ShmDcCommonData->_authWithCcidFlag [gun_index] == _CCID_AUTHCOMP)
+						{
+							PRINTF_FUNC("_CCID_AUTHCOMP \n");
+
+							_isSendStartTransaction[gun_index] = true;
+							ocpp_set_startTransation_cmd(gun_index);
+							GetTimespecFunc(&_startTransation_time[gun_index]);
+						}
+						else if (ShmDcCommonData->_authWithCcidFlag [gun_index] == _CCID_AUTHFAIL)
+						{
+							PRINTF_FUNC("_CCID_AUTHFAIL \n");
+							ChargingTerminalProcess(gun_index);
+						}
+					}
+
+//					if (isCcidEnterToCharging(gun_index))
+//					{
+//
+//					}
+
+					ShmDcCommonData->startTransactionFlag[gun_index] = ocpp_is_resPass_StartTransactionConf(gun_index);
+
+					if (ShmDcCommonData->startTransactionFlag[gun_index] == START_TRANSATION_STATUS_PASS)
+					{
+						if (ocpp_chk_invalid_id_cmd(gun_index))
+							ShmDcCommonData->startTransactionFlag[gun_index] = START_TRANSATION_STATUS_FAIL;
+					}
+					else
+					{
+						if (ShmSysConfigAndInfo->SysInfo.OcppConnStatus == NO)
+						{
+							if (ShmSysConfigAndInfo->SysConfig.OfflinePolicy == _OFFLINE_POLICY_FREE_CHARGING ||
+									ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_DISABLE ||
+									!ocpp_get_startTransation_req(gun_index) ||
+									strcmp((char *)chargingInfo[gun_index]->StartUserId, "") != EQUAL ||
+									_isTestRun)
+							{
+								ShmDcCommonData->startTransactionFlag[gun_index] = START_TRANSATION_STATUS_PASS;
+							}
+						}
+					}
+
+					// 小板停止
+					ChkConnectorBoardStop(gun_index);
+
+					// psu 停止
+					ChkPsuErrorStop(gun_index);
+
+					if (ocpp_chk_remoteStop_cmd(gun_index) == YES ||
+						WifiScheduleStop(gun_index) ||
+						(_isSendStartTransaction[gun_index] && ShmDcCommonData->startTransactionFlag[gun_index] == START_TRANSATION_STATUS_FAIL) ||
+						(_isSendStartTransaction[gun_index] && ShmDcCommonData->startTransactionFlag[gun_index] == START_TRANSATION_STATUS_WAIT && GetTimeoutValue(&_startTransation_time[gun_index]) > 45))
+					{
+						// 後臺要求停止
+						ChargingTerminalProcess(gun_index);
+
+						if (ShmDcCommonData->startTransactionFlag[gun_index] == START_TRANSATION_STATUS_FAIL)
+							PRINTF_FUNC("StartTransaction req fail. (%d) \n", gun_index);
+						else if (ShmDcCommonData->startTransactionFlag[gun_index] == START_TRANSATION_STATUS_WAIT)
+							PRINTF_FUNC("StartTransaction req timeout. (%d) \n", gun_index);
+					}
+
+					// 檢查車端的槍鎖是否為鎖上
+					if (isEvGunLocked(gun_index) == YES)
+					{
+						setChargerMode(gun_index, SYS_MODE_PREPARE_FOR_EVSE);
+					}
+
+					// LCM => Pre-charging
+					if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index &&
+							ShmSysConfigAndInfo->SysConfig.AcConnectorCount > 0)
+					{
+						if (IsNoneSelectAcModule())
+						{
+//							if (ShmSysConfigAndInfo->SysInfo.SystemPage <= _LCM_AUTHORIZING ||
+//									ShmSysConfigAndInfo->SysInfo.SystemPage >= _LCM_AUTHORIZ_FAIL)
+//							{
+//								ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
+//							}
+							if (ShmSysConfigAndInfo->SysInfo.SystemPage >= _LCM_AUTHORIZING ||
+									ShmSysConfigAndInfo->SysInfo.SystemPage <= _LCM_AUTHORIZ_FAIL)
+							{ }
+							else
+							{
+								ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
+							}
+						}
+						else
+						{
+							if ((ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_DISABLE ||
+									ocpp_remote_start_wait_cmd ()))
+							{
+								DisplayPageChkByAcModule();
+							}
+						}
+						if (ShmSysConfigAndInfo->SysInfo.SystemPage == _LCM_NONE)
+							ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_PRE_CHARGE;
+					}
+					else if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index)
+					{
+						if (ShmSysConfigAndInfo->SysInfo.SystemPage >= _LCM_AUTHORIZING ||
+							ShmSysConfigAndInfo->SysInfo.SystemPage <= _LCM_AUTHORIZ_FAIL)
+						{}
+						else
+						{
+							ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
+						}
+
+						ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_PRE_CHARGE;
+					}
+				}
+					break;
+				case SYS_MODE_PREPARE_FOR_EVSE: // 等待 RB 通訊及測試,並將狀態回報, CSU 確認 Pass 後,開始進入充電
+				{
+					if (isModeChange(gun_index))
+					{
+						PRINTF_FUNC("================== SYS_MODE_PREPARE_FOR_EVSE (%x) ================ \n", gun_index);
+						StopGunInfoTimeoutDet(gun_index);
+						StartGunInfoTimeoutDet(gun_index, Timeout_EvseChargingDet);
+					}
+
+					ocpp_clear_errorCode_cmd(gun_index);
+
+					if (chargingInfo[gun_index]->Type == _Type_Chademo)
+					{
+						// 檢查樁端的 GFD 結果
+						if (isPrechargeStatus_chademo(gun_index) >= 6)
+						{
+							// 當前操作的槍號,進入 Charging
+							setChargerMode(gun_index, SYS_MODE_CHARGING);
+						}
+					}
+					else if (chargingInfo[gun_index]->Type == _Type_GB)
+					{
+						// 檢查樁端的 GFD 結果
+						if (isPrechargeStatus_gb(gun_index) >= 6)
+						{
+							setChargerMode(gun_index, SYS_MODE_CHARGING);
+						}
+					}
+					else if (chargingInfo[gun_index]->Type == _Type_CCS)
+					{
+						// 檢查樁端的 GFD 結果
+						if ((chargingInfo[gun_index]->GroundFaultStatus == GFD_PASS ||
+								chargingInfo[gun_index]->GroundFaultStatus == GFD_WARNING))
+						{
+							setChargerMode(gun_index, SYS_MODE_CCS_PRECHARGE_STEP0);
+						}
+					}
+					RecordGfdResult(gun_index);
+
+					// 小板停止
+					ChkConnectorBoardStop(gun_index);
+
+					// psu 停止
+					ChkPsuErrorStop(gun_index);
+
+					// 後台要求停止
+					ChkBackendStop(gun_index);
+
+					// LCM => Pre-charging
+					if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index &&
+							ShmSysConfigAndInfo->SysConfig.AcConnectorCount > 0)
+					{
+						if (IsNoneSelectAcModule())
+						{
+							if (ShmSysConfigAndInfo->SysInfo.SystemPage <= _LCM_AUTHORIZING ||
+									ShmSysConfigAndInfo->SysInfo.SystemPage >= _LCM_AUTHORIZ_FAIL)
+							{
+								ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
+							}
+						}
+						else
+						{
+							if ((ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_DISABLE ||
+									ocpp_remote_start_wait_cmd ()))
+							{
+								DisplayPageChkByAcModule();
+							}
+						}
+						ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_PRE_CHARGE;
+					}
+					else if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index)
+					{
+						ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_PRE_CHARGE;
+						ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
+					}
+				}
+					break;
+				case SYS_MODE_CHARGING: // 剛進入充電狀態,等待 EV 小板要求的輸出電流後開始輸出
+				{
+					if (isModeChange(gun_index))
+					{
+						PRINTF_FUNC("================== SYS_MODE_CHARGING (%x) ================ \n", gun_index);
+						StopGunInfoTimeoutDet(gun_index);
+						ftime(&startChargingTime[gun_index]);
+						ocpp_clear_idTag_cmd(gun_index);
+						ChangeStartOrStopDateTime(YES, gun_index);
+
+						if (_isTestRun == YES)
+						{
+							GetTimespecFunc(&_autoRuntestTime);
+						}
+					}
+
+					ocpp_clear_errorCode_cmd(gun_index);
+
+					if (_isTestRun == YES)
+					{
+						if (GetTimeoutValue(&_autoRuntestTime) > 60)
+						{
+							ChargingTerminalProcess(gun_index);
+						}
+					}
+
+					SavePresentChargedDuration(gun_index);
+
+					if (chargingInfo[gun_index]->Type == _Type_Chademo)
+					{
+						if (ShmDcCommonData->minOutputCur != 0 &&
+								chargingInfo[gun_index]->PresentChargedDuration >= 10 &&
+								chargingInfo[gun_index]->PresentChargingCurrent < ShmDcCommonData->minOutputCur)
+						{
+							// UCP
+							RecordAlarmCode(gun_index, "012320");
+							ChargingTerminalProcess(gun_index);
+						}
+					}
+					else if (chargingInfo[gun_index]->Type == _Type_GB)
+					{
+						if (ShmDcCommonData->minOutputCur != 0 &&
+								chargingInfo[gun_index]->PresentChargedDuration >= 10 &&
+								chargingInfo[gun_index]->PresentChargingCurrent < ShmDcCommonData->minOutputCur)
+						{
+							// UCP
+							RecordAlarmCode(gun_index, "012322");
+							ChargingTerminalProcess(gun_index);
+						}
+					}
+					else if (chargingInfo[gun_index]->Type == _Type_CCS)
+					{
+						if (ShmDcCommonData->minOutputCur != 0 &&
+								chargingInfo[gun_index]->PresentChargedDuration >= 10 &&
+								chargingInfo[gun_index]->PresentChargingCurrent < ShmDcCommonData->minOutputCur)
+						{
+							// UCP
+							RecordAlarmCode(gun_index, "012321");
+							ChargingTerminalProcess(gun_index);
+						}
+					}
+					RecordGfdResult(gun_index);
+
+					// 小板停止
+					ChkConnectorBoardStop(gun_index);
+
+					// psu 停止
+					ChkPsuErrorStop(gun_index);
+
+					// 後台要求停止
+					ChkBackendStop(gun_index);
+
+					// 設定停止
+					ChkConfigurationStop(gun_index);
+
+					// LCM => Charging
+					if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index &&
+							ShmSysConfigAndInfo->SysConfig.AcConnectorCount > 0)
+					{
+						if (IsNoneSelectAcModule() || !stopChargingChkByCard)
+						{
+//							if (ShmSysConfigAndInfo->SysInfo.SystemPage <= _LCM_AUTHORIZING ||
+//									ShmSysConfigAndInfo->SysInfo.SystemPage >= _LCM_AUTHORIZ_FAIL)
+//							{
+//								ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
+//							}
+							if (ShmSysConfigAndInfo->SysInfo.SystemPage >= _LCM_AUTHORIZING ||
+									ShmSysConfigAndInfo->SysInfo.SystemPage <= _LCM_AUTHORIZ_FAIL)
+							{ }
+							else
+							{
+								ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
+							}
+						}
+						else
+						{
+							if ((ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_DISABLE ||
+									ocpp_remote_start_wait_cmd ()))
+							{
+								DisplayPageChkByAcModule();
+							}
+						}
+						ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_CHARGING;
+					}
+					else if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index)
+					{
+						ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_CHARGING;
+						if (!stopChargingChkByCard)
+							ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
+					}
+				}
+					break;
+				case SYS_MODE_ALARM:
+				case SYS_MODE_TERMINATING:
+				{
+					if (isModeChange(gun_index))
+					{
+						if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.EmergencyStopTrip ||
+								ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DoorOpen)
+							ocpp_set_stopReason_by_cmd(gun_index, "EmergencyStop");
+						else
+							ocpp_set_stopReason_by_cmd(gun_index, "Local");
+
+						if (chargingInfo[gun_index]->SystemStatus == SYS_MODE_ALARM)
+						{
+							PRINTF_FUNC("================== SYS_MODE_ALARM (%x) ================ \n", gun_index);
+							if (strcmp((char *)chargingInfo[gun_index]->StartDateTime, "") != EQUAL)
+							{
+								ocpp_auto_response_StartTransationConf(gun_index);
+								ocpp_set_stopTransation_cmd(gun_index);
+							}
+
+							TheEndCharging(gun_index);
+						}
+						else
+						{
+							PRINTF_FUNC("================== SYS_MODE_TERMINATING (%x) ================ \n", gun_index);
+						}
+
+						ShmDcCommonData->_returnIdleHoldFlag[gun_index] = NO;
+						StopGunInfoTimeoutDet(gun_index);
+					}
+
+					if (chargingInfo[gun_index]->SystemStatus == SYS_MODE_ALARM)
+					{
+						ChangeToMaxChargingMode();
+
+						ocpp_set_errCode_cmd(gun_index);
+					}
+
+					if (chargingInfo[gun_index]->Type == _Type_Chademo) { }
+					else if (chargingInfo[gun_index]->Type == _Type_GB) { }
+					else if (chargingInfo[gun_index]->Type == _Type_CCS) { }
+
+					if (chargingInfo[gun_index]->SystemStatus == SYS_MODE_ALARM)
+					{
+						if (chargingInfo [gun_index]->ConnectorPlugIn == NO)
+						{
+							if (ShmDcCommonData->_returnIdleHoldFlag [gun_index] == NO &&
+									GetTimeoutValue ( & chargingInfo [gun_index]->ConnectorTimeout ) >= 10)
+							{
+								ShmDcCommonData->_returnIdleHoldFlag [gun_index] = YES;
+								StopGunInfoTimeoutDet ( gun_index );
+								StartGunInfoTimeoutDet ( gun_index, Timeout_EvseCompleteDet );
+							}
+							else if (ShmDcCommonData->_returnIdleHoldFlag [gun_index] == YES &&
+									GetTimeoutValue ( & chargingInfo [gun_index]->ConnectorTimeout ) >= 2)
+							{
+								setChargerMode ( gun_index, SYS_MODE_IDLE );
+							}
+						}
+						else if (_isTestRun == YES &&
+								GetTimeoutValue(&chargingInfo[gun_index]->ConnectorTimeout) >= 10)
+						{
+							setChargerMode(gun_index, SYS_MODE_IDLE);
+						}
+					}
+					else
+					{
+						if (chargingInfo[gun_index]->Type == _Type_Chademo)
+						{
+							if (isEvGunLocked(gun_index) == NO ||
+									isPrechargeStatus_chademo(gun_index) <= 0)
+							{
+								setChargerMode(gun_index, SYS_MODE_COMPLETE);
+							}
+						}
+						else if (chargingInfo[gun_index]->Type == _Type_GB)
+						{
+							if (isEvGunLocked(gun_index) == NO ||
+									isPrechargeStatus_gb(gun_index) <= 0)
+							{
+								setChargerMode(gun_index, SYS_MODE_COMPLETE);
+							}
+						}
+						else if (chargingInfo[gun_index]->Type == _Type_CCS)
+						{
+							if (isEvGunLocked(gun_index) == NO &&
+									(isPrechargeStatus_ccs(gun_index) >= 53 || isPrechargeStatus_ccs(gun_index) == 0 ||
+										isPrechargeStatus_ccs(gun_index) == 13 || isPrechargeStatus_ccs(gun_index) == 14))
+							{
+								setChargerMode(gun_index, SYS_MODE_COMPLETE);
+							}
+						}
+					}
+					if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index &&
+							ShmSysConfigAndInfo->SysConfig.AcConnectorCount > 0)
+					{
+						if (IsNoneSelectAcModule())
+						{
+							if (ShmSysConfigAndInfo->SysInfo.SystemPage <= _LCM_AUTHORIZING ||
+									ShmSysConfigAndInfo->SysInfo.SystemPage >= _LCM_AUTHORIZ_FAIL)
+							{
+								ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
+							}
+						}
+						else
+						{
+							if ((ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_DISABLE ||
+									ocpp_remote_start_wait_cmd ()))
+							{
+								DisplayPageChkByAcModule();
+							}
+						}
+						ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_COMPLETE;
+					}
+					else if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index)
+					{
+						ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_COMPLETE;
+						ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
+					}
+				}
+					break;
+				case SYS_MODE_COMPLETE:
+				{
+					if (isModeChange(gun_index))
+					{
+						PRINTF_FUNC("================== SYS_MODE_COMPLETE (%x) ================ \n", gun_index);
+						if (strcmp((char *)chargingInfo[gun_index]->StartDateTime, "") != EQUAL)
+						{
+							ocpp_set_errCode_cmd(gun_index);
+							ocpp_auto_response_StartTransationConf(gun_index);
+							ocpp_set_stopTransation_cmd(gun_index);
+						}
+						TheEndCharging(gun_index);
+						ShmDcCommonData->_returnIdleHoldFlag[gun_index] = NO;
+					}
+
+					ocpp_clear_errorCode_cmd(gun_index);
+
+					ChangeToMaxChargingMode();
+					if (chargingInfo[gun_index]->ConnectorPlugIn == NO)
+					{
+						if (ShmDcCommonData->_returnIdleHoldFlag[gun_index] == NO &&
+								GetTimeoutValue(&chargingInfo[gun_index]->ConnectorTimeout) >= 10)
+						{
+							ShmDcCommonData->_returnIdleHoldFlag[gun_index] = YES;
+							StopGunInfoTimeoutDet(gun_index);
+							StartGunInfoTimeoutDet(gun_index, Timeout_EvseCompleteDet);
+						}
+						else if (ShmDcCommonData->_returnIdleHoldFlag[gun_index] == YES &&
+								GetTimeoutValue(&chargingInfo[gun_index]->ConnectorTimeout) >= 2)
+						{
+							setChargerMode(gun_index, SYS_MODE_IDLE);
+						}
+					}
+					else if (_isTestRun == YES &&
+							GetTimeoutValue(&chargingInfo[gun_index]->ConnectorTimeout) >= 10)
+					{
+						setChargerMode(gun_index, SYS_MODE_IDLE);
+					}
+
+					if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index &&
+							ShmSysConfigAndInfo->SysConfig.AcConnectorCount > 0)
+					{
+						if (IsNoneSelectAcModule())
+						{
+							if (ShmSysConfigAndInfo->SysInfo.SystemPage <= _LCM_AUTHORIZING ||
+									ShmSysConfigAndInfo->SysInfo.SystemPage >= _LCM_AUTHORIZ_FAIL)
+							{
+								ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
+							}
+						}
+						else
+						{
+							if ((ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_DISABLE ||
+									ocpp_remote_start_wait_cmd ()))
+							{
+								DisplayPageChkByAcModule();
+							}
+						}
+						ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_COMPLETE;
+					}
+					else if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index)
+					{
+						ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_COMPLETE;
+						ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
+					}
+				}
+					break;
+				case SYS_MODE_CCS_PRECHARGE_STEP0:
+				{
+					if (isModeChange(gun_index))
+					{
+						PRINTF_FUNC("================== SYS_MODE_CCS_PRECHARGE_STEP0 (%x) ================ \n", gun_index);
+						StopGunInfoTimeoutDet(gun_index);
+						StartGunInfoTimeoutDet(gun_index, Timeout_ForCcsPrechargeDet);
+					}
+
+					ocpp_clear_errorCode_cmd(gun_index);
+
+					RecordGfdResult(gun_index);
+
+					// 小板停止
+					ChkConnectorBoardStop(gun_index);
+
+					// psu 停止
+					ChkPsuErrorStop(gun_index);
+
+					// 後台要求停止
+					ChkBackendStop(gun_index);
+
+					// 等待 EV 小板 (CCS) 通知可以開始 Precharge
+					// 切換 D+ Relay to Precharge Relay
+					if (isPrechargeStatus_ccs(gun_index) == 39 || isPrechargeStatus_ccs(gun_index) == 40)
+					{
+						if (chargingInfo[gun_index]->RelayKPK2Status == YES && chargingInfo[gun_index]->PrechargeStatus != PRECHARGE_READY)
+						//if (chargingInfo[gun_index]->PrechargeStatus != PRECHARGE_PRERELAY_PASS)
+						{
+							if (isPrechargeStatus_ccs(gun_index) == 39)
+								PRINTF_FUNC("Conn %x, Precharge ready, CCS status = PreChargeResponse (%d) \n", gun_index, isPrechargeStatus_ccs(gun_index));
+							else if (isPrechargeStatus_ccs(gun_index) == 40)
+								PRINTF_FUNC("Conn %x, Precharge ready, CCS status = PowerDeliveryRequest start (%d) \n", gun_index, isPrechargeStatus_ccs(gun_index));
+
+							chargingInfo[gun_index]->PrechargeStatus = PRECHARGE_READY;
+						}
+					}
+					else if (isPrechargeStatus_ccs(gun_index) == 45 || isPrechargeStatus_ccs(gun_index) == 46)
+					{
+						setChargerMode(gun_index, SYS_MODE_CCS_PRECHARGE_STEP1);
+					}
+
+					if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index &&
+							ShmSysConfigAndInfo->SysConfig.AcConnectorCount > 0)
+					{
+						if (IsNoneSelectAcModule())
+						{
+							if (ShmSysConfigAndInfo->SysInfo.SystemPage <= _LCM_AUTHORIZING ||
+									ShmSysConfigAndInfo->SysInfo.SystemPage >= _LCM_AUTHORIZ_FAIL)
+							{
+								ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
+							}
+						}
+						else
+						{
+							if ((ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_DISABLE ||
+									ocpp_remote_start_wait_cmd ()))
+							{
+								DisplayPageChkByAcModule();
+							}
+						}
+						ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_PRE_CHARGE;
+					}
+					else if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index)
+					{
+						ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_PRE_CHARGE;
+						ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
+					}
+					break;
+				}
+				case SYS_MODE_CCS_PRECHARGE_STEP1:
+				{
+					if (isModeChange(gun_index))
+					{
+						PRINTF_FUNC("================== SYS_MODE_CCS_PRECHARGE_STEP1 (%x) ================ \n", gun_index);
+					}
+
+					ocpp_clear_errorCode_cmd(gun_index);
+
+					RecordGfdResult(gun_index);
+
+					// 小板停止
+					ChkConnectorBoardStop(gun_index);
+
+					// psu 停止
+					ChkPsuErrorStop(gun_index);
+
+					// 後台要求停止
+					ChkBackendStop(gun_index);
+
+					// 等待小板通知進入充電
+					// 切換 D+ Relay to Precharge Relay
+					if (chargingInfo[gun_index]->RelayK1K2Status == YES)
+					{
+						chargingInfo[gun_index]->PrechargeStatus = PRECHARGE_READY;
+						setChargerMode(gun_index, SYS_MODE_CHARGING);
+					}
+
+					if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index &&
+							ShmSysConfigAndInfo->SysConfig.AcConnectorCount > 0)
+					{
+						if (IsNoneSelectAcModule())
+						{
+							if (ShmSysConfigAndInfo->SysInfo.SystemPage <= _LCM_AUTHORIZING ||
+									ShmSysConfigAndInfo->SysInfo.SystemPage >= _LCM_AUTHORIZ_FAIL)
+							{
+								ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
+							}
+						}
+						else
+						{
+							if ((ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_DISABLE ||
+									ocpp_remote_start_wait_cmd ()))
+							{
+								DisplayPageChkByAcModule();
+							}
+						}
+						ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_PRE_CHARGE;
+					}
+					else if (ShmSysConfigAndInfo->SysInfo.CurGunSelected == gun_index)
+					{
+						ShmSysConfigAndInfo->SysInfo.ConnectorPage = _LCM_PRE_CHARGE;
+						ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_NONE;
+					}
+					break;
+				}
+			}
+
+			if (chargingInfo[gun_index]->SystemStatus == SYS_MODE_IDLE ||
+					chargingInfo[gun_index]->SystemStatus == SYS_MODE_RESERVATION ||
+					chargingInfo[gun_index]->SystemStatus == SYS_MODE_MAINTAIN ||
+					chargingInfo[gun_index]->SystemStatus == SYS_MODE_FAULT)
+			{
+				ocpp_chk_notificationMessage_cmd(gun_index);
+			}
+		}
+
+		if (ShmSysConfigAndInfo->SysInfo.SystemPage != _LCM_NONE)
+		{
+			ChangeLcmByIndex(ShmSysConfigAndInfo->SysInfo.SystemPage);
+		}
+		else
+		{
+			bool dcPageRun = false;
+			if (_acgunIndex > 0 && ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc != NO_DEFINE)
+			{
+				if  (ac_chargingInfo[0]->SystemStatus == SYS_MODE_IDLE)
+					ChangeLcmByIndex(_LCM_IDLE);
+				else if (ac_chargingInfo[0]->SystemStatus == SYS_MODE_PREPARING)
+					ChangeLcmByIndex(_LCM_PRE_CHARGE);
+				else if (ac_chargingInfo[0]->SystemStatus == SYS_MODE_CHARGING)
+					ChangeLcmByIndex(_LCM_CHARGING);
+				else if (ac_chargingInfo[0]->SystemStatus == SYS_MODE_TERMINATING ||
+						ac_chargingInfo[0]->SystemStatus == SYS_MODE_COMPLETE)
+					ChangeLcmByIndex(_LCM_COMPLETE);
+				else
+					dcPageRun = true;
+			}
+			else
+				dcPageRun = true;
+
+			if (dcPageRun)
+				ChangeLcmByIndex(ShmSysConfigAndInfo->SysInfo.ConnectorPage);
+		}
+
+		bool isCharging = false;
+
+		SystemAlarmCheck();
+		for (byte gun_index = 0; gun_index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gun_index++)
+		{
+			AlarmCheck(chargingInfo[gun_index]->Type);
+
+			if (_isTestRun == YES)
+			{
+				if (IsGunUsing(gun_index))
+				{
+					isCharging = true;
+					if (chargingInfo[gun_index]->SystemStatus == SYS_MODE_COMPLETE ||
+							chargingInfo[gun_index]->SystemStatus == SYS_MODE_ALARM)
+					{
+						GetTimespecFunc(&_autoRuntestTime);
+					}
+				}
+			}
+		}
+
+		if (_isTestRun == YES)
+		{
+			if (!isCharging)
+			{
+				if (GetTimeoutValue(&_autoRuntestTime) >= 60)
+				{
+					DetectPluginStart();
+					GetTimespecFunc(&_autoRuntestTime);
+				}
+			}
+			else
+			{
+				ClearDetectPluginFlag();
+			}
+		}
+
+		write(wtdFd, "a", 1);
+		usleep(whileLoopTime);
+	}
+
+	return FAIL;
+}

+ 6 - 0
EVSE/Projects/NoodoeDS/Apps/timeout.c

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

+ 68 - 0
EVSE/Projects/NoodoeDS/Apps/timeout.h

@@ -0,0 +1,68 @@
+#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>
+
+#define CONN_PLUG_TIME_OUT			40
+
+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,
+	Timeout_AuthorizingForStop = 		12
+};
+
+// for timeout fork
+struct timespec _cmdSubPriority_time;
+unsigned short _connectionTimeout;
+
+// for main
+struct timespec _cmdMainPriority_time;
+struct timespec _resetChkTime;
+unsigned char _ocppProfileChkFlag_1;
+unsigned char _ocppProfileChkFlag_2;
+unsigned char _ac_ocppProfileChkFlag;
+unsigned char _4gResetChkFlag;
+bool stopChargingChkByCard;
+
+#endif /* TIMEOUT_H_ */

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

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

BIN
EVSE/Projects/NoodoeDS/Images/FactoryDefaultConfig.bin


BIN
EVSE/Projects/NoodoeDS/Images/MLO


BIN
EVSE/Projects/NoodoeDS/Images/am335x-evm.dtb


BIN
EVSE/Projects/NoodoeDS/Images/ramdisk.gz


BIN
EVSE/Projects/NoodoeDS/Images/u-boot-spl.bin


BIN
EVSE/Projects/NoodoeDS/Images/u-boot.img


BIN
EVSE/Projects/NoodoeDS/Images/zImage


+ 72 - 73
Makefile

@@ -1931,37 +1931,36 @@ DD360Tcci-rootfs:
 
 DD360Tcci-all: DD360Tcci-uboot DD360Tcci-linux DD360Tcci-rootfs
 
+NoodoeAX-uboot-default: u-boot_clean u-boot
+	@cp -f $(UBOOT_INSTALL_DIR)/MLO EVSE/Projects/NoodoeAX/Images/
+	@cp -f $(UBOOT_INSTALL_DIR)/u-boot.img EVSE/Projects/NoodoeAX/Images/
 
-DD360Tcci-uboot-default: u-boot_clean u-boot
-	@cp -f $(UBOOT_INSTALL_DIR)/MLO EVSE/Projects/DD360Tcci/Images/
-	@cp -f $(UBOOT_INSTALL_DIR)/u-boot.img EVSE/Projects/DD360Tcci/Images/
-
-DD360Tcci-uboot-menuconfig:
+NoodoeAX-uboot-menuconfig:
 	@echo ===================================
 	@echo    Building U-boot menuconfig
 	@echo ===================================
 	$(MAKE) -j $(MAKE_JOBS) -C $(UBOOT_INSTALL_DIR) CROSS_COMPILE=$(CROSS_COMPILE) menuconfig
 
-DD360Tcci-uboot:
+NoodoeAX-uboot:
 	@echo ===================================
 	@echo    Building U-boot
 	@echo ===================================
-	@cp -f $(UBOOT_INSTALL_DIR)/arch/arm/dts/[DD360Tcci]am335x-evm.dts $(UBOOT_INSTALL_DIR)/arch/arm/dts/am335x-evm.dts
-	$(MAKE) -j $(MAKE_JOBS) -C $(UBOOT_INSTALL_DIR) CROSS_COMPILE=$(CROSS_COMPILE) FLASH_IC=MT29F16G08_BCH16 DDR_IC=MT41K256M16HA125E_303
-	@cp -f $(UBOOT_INSTALL_DIR)/MLO EVSE/Projects/DD360Tcci/Images/
-	@cp -f $(UBOOT_INSTALL_DIR)/u-boot.img EVSE/Projects/DD360Tcci/Images/
-	@cp -f $(UBOOT_INSTALL_DIR)/spl/u-boot-spl.bin EVSE/Projects/DD360Tcci/Images/
+	@cp -f $(UBOOT_INSTALL_DIR)/arch/arm/dts/[NoodoeAX]am335x-evm.dts $(UBOOT_INSTALL_DIR)/arch/arm/dts/am335x-evm.dts
+	$(MAKE) -j $(MAKE_JOBS) -C $(UBOOT_INSTALL_DIR) CROSS_COMPILE=$(CROSS_COMPILE) FLASH_IC=MT29F8G08_BCH16 DDR_IC=MT41K256M16HA125E_303
+	@cp -f $(UBOOT_INSTALL_DIR)/MLO EVSE/Projects/NoodoeAX/Images/
+	@cp -f $(UBOOT_INSTALL_DIR)/u-boot.img EVSE/Projects/NoodoeAX/Images/
+	@cp -f $(UBOOT_INSTALL_DIR)/spl/u-boot-spl.bin EVSE/Projects/NoodoeAX/Images/
 
-DD360Tcci-linux-default: linux_clean linux
-	@cp -f $(LINUXKERNEL_INSTALL_DIR)/arch/arm/boot/zImage EVSE/Projects/DD360Tcci/Images/
-	@cp -f $(LINUXKERNEL_INSTALL_DIR)/arch/arm/boot/dts/am335x-evm.dtb EVSE/Projects/DD360Tcci/Images/
+NoodoeAX-linux-default: linux_clean linux
+	@cp -f $(LINUXKERNEL_INSTALL_DIR)/arch/arm/boot/zImage EVSE/Projects/NoodoeAX/Images/
+	@cp -f $(LINUXKERNEL_INSTALL_DIR)/arch/arm/boot/dts/am335x-evm.dtb EVSE/Projects/NoodoeAX/Images/
 
-DD360Tcci-linux:
+NoodoeAX-linux:
 	@echo =====================================
 	@echo     Building the Linux Kernel DTBs
 	@echo =====================================
 	@rm -f $(LINUXKERNEL_INSTALL_DIR)/arch/arm/boot/dts/am335x-evm.dtb
-	@cp -f $(LINUXKERNEL_INSTALL_DIR)/arch/arm/boot/dts/[DD360Tcci]am335x-evm.dts $(LINUXKERNEL_INSTALL_DIR)/arch/arm/boot/dts/am335x-evm.dts
+	@cp -f $(LINUXKERNEL_INSTALL_DIR)/arch/arm/boot/dts/[NoodoeAX]am335x-evm.dts $(LINUXKERNEL_INSTALL_DIR)/arch/arm/boot/dts/am335x-evm.dts
 	$(MAKE) -j $(MAKE_JOBS) -C $(LINUXKERNEL_INSTALL_DIR) ARCH=arm CROSS_COMPILE=$(CROSS_COMPILE) am335x-evm.dtb
 	@echo =================================
 	@echo     Building User Linux Kernel
@@ -1969,72 +1968,72 @@ DD360Tcci-linux:
 	@rm -f $(LINUXKERNEL_INSTALL_DIR)/arch/arm/boot/zImage
 	$(MAKE) -j $(MAKE_JOBS) -C $(LINUXKERNEL_INSTALL_DIR) ARCH=arm CROSS_COMPILE=$(CROSS_COMPILE) zImage
 	$(MAKE) -j $(MAKE_JOBS) -C $(LINUXKERNEL_INSTALL_DIR) ARCH=arm CROSS_COMPILE=$(CROSS_COMPILE) modules
-	@cp -f $(LINUXKERNEL_INSTALL_DIR)/arch/arm/boot/zImage EVSE/Projects/DD360Tcci/Images/
-	@cp -f $(LINUXKERNEL_INSTALL_DIR)/arch/arm/boot/dts/am335x-evm.dtb EVSE/Projects/DD360Tcci/Images/
+	@cp -f $(LINUXKERNEL_INSTALL_DIR)/arch/arm/boot/zImage EVSE/Projects/NoodoeAX/Images/
+	@cp -f $(LINUXKERNEL_INSTALL_DIR)/arch/arm/boot/dts/am335x-evm.dtb EVSE/Projects/NoodoeAX/Images/
 	@cp -f $(LINUXKERNEL_INSTALL_DIR)/drivers/net/ethernet/qualcomm/qcaspi.ko EVSE/rootfs/lib/
 
-DD360Tcci-rootfs:
+NoodoeAX-rootfs:
 	@echo =================================
 	@echo     Building User rootfs
 	@echo =================================
-#	@cd EVSE/GPL;make Project=DD360Tcci all
-	@cd EVSE/Modularization;make TLS_EXPIRED=TLS_VALID_CERT_EXPIRED Project=DD360Tcci all
-	@cd EVSE/Projects/DD360Tcci/Apps;make Project=DD360Tcci all
-	@rm -f EVSE/Projects/DD360Tcci/Images/ramdisk.gz
+#	@cd EVSE/GPL;make Project=NoodoeAX all
+	@cd EVSE/Modularization;make TLS_EXPIRED=TLS_VALID_CERT_EXPIRED Project=NoodoeAX all
+	@cd EVSE/Projects/NoodoeAX/Apps;make Project=NoodoeAX all
+	@rm -f EVSE/Projects/NoodoeAX/Images/ramdisk.gz
 	@dd if=/dev/zero of=/dev/ram0 bs=1k count=131072
 	@mke2fs -vm0 /dev/ram0 131072
 	@tune2fs -c 0 /dev/ram0
-	@dd if=/dev/ram0 bs=1k count=131072 | gzip -v9 > EVSE/Projects/DD360Tcci/Images/ramdisk.gz
-	@mkdir -p EVSE/Projects/DD360Tcci/Images/mnt
-	@gunzip EVSE/Projects/DD360Tcci/Images/ramdisk.gz
+	@dd if=/dev/ram0 bs=1k count=131072 | gzip -v9 > EVSE/Projects/NoodoeAX/Images/ramdisk.gz
+	@mkdir -p EVSE/Projects/NoodoeAX/Images/mnt
+	@gunzip EVSE/Projects/NoodoeAX/Images/ramdisk.gz
 	@sync
-	@mount -o loop EVSE/Projects/DD360Tcci/Images/ramdisk EVSE/Projects/DD360Tcci/Images/mnt
-	@cp -rfv EVSE/rootfs/* EVSE/Projects/DD360Tcci/Images/mnt/
-	@chown www-data:www-data EVSE/Projects/DD360Tcci/Images/mnt/var/www -R
-	@chmod 777 EVSE/Projects/DD360Tcci/Images/mnt/var/log -R
-	@chmod 777 EVSE/Projects/DD360Tcci/Images/mnt/var/run -R
-	@cp -rfv EVSE/Projects/DD360Tcci/Images/root/* EVSE/Projects/DD360Tcci/Images/mnt/root
+	@mount -o loop EVSE/Projects/NoodoeAX/Images/ramdisk EVSE/Projects/NoodoeAX/Images/mnt
+	@cp -rfv EVSE/rootfs/* EVSE/Projects/NoodoeAX/Images/mnt/
+	@chown www-data:www-data EVSE/Projects/NoodoeAX/Images/mnt/var/www -R
+	@chmod 777 EVSE/Projects/NoodoeAX/Images/mnt/var/log -R
+	@chmod 777 EVSE/Projects/NoodoeAX/Images/mnt/var/run -R
+	@cp -rfv EVSE/Projects/NoodoeAX/Images/root/* EVSE/Projects/NoodoeAX/Images/mnt/root
 	@sync
 	@sleep 3
-	@umount EVSE/Projects/DD360Tcci/Images/mnt
+	@umount EVSE/Projects/NoodoeAX/Images/mnt
 	@sync
-	@gzip -v9 EVSE/Projects/DD360Tcci/Images/ramdisk
-	@rm -rfv EVSE/Projects/DD360Tcci/Images/root
-	@rm -rfv EVSE/Projects/DD360Tcci/Images/mnt
+	@gzip -v9 EVSE/Projects/NoodoeAX/Images/ramdisk
+	@rm -rfv EVSE/Projects/NoodoeAX/Images/root
+	@rm -rfv EVSE/Projects/NoodoeAX/Images/mnt
 
-DD360Tcci-all: DD360Tcci-uboot DD360Tcci-linux DD360Tcci-rootfs
+NoodoeAX-all: NoodoeAX-uboot NoodoeAX-linux NoodoeAX-rootfs
 
 
-NoodoeAX-uboot-default: u-boot_clean u-boot
-	@cp -f $(UBOOT_INSTALL_DIR)/MLO EVSE/Projects/NoodoeAX/Images/
-	@cp -f $(UBOOT_INSTALL_DIR)/u-boot.img EVSE/Projects/NoodoeAX/Images/
+NoodoeDS-uboot-default: u-boot_clean u-boot
+	@cp -f $(UBOOT_INSTALL_DIR)/MLO EVSE/Projects/NoodoeDS/Images/
+	@cp -f $(UBOOT_INSTALL_DIR)/u-boot.img EVSE/Projects/NoodoeDS/Images/
 
-NoodoeAX-uboot-menuconfig:
+NoodoeDS-uboot-menuconfig:
 	@echo ===================================
 	@echo    Building U-boot menuconfig
 	@echo ===================================
 	$(MAKE) -j $(MAKE_JOBS) -C $(UBOOT_INSTALL_DIR) CROSS_COMPILE=$(CROSS_COMPILE) menuconfig
 
-NoodoeAX-uboot:
+NoodoeDS-uboot:
 	@echo ===================================
 	@echo    Building U-boot
 	@echo ===================================
-	@cp -f $(UBOOT_INSTALL_DIR)/arch/arm/dts/[NoodoeAX]am335x-evm.dts $(UBOOT_INSTALL_DIR)/arch/arm/dts/am335x-evm.dts
-	$(MAKE) -j $(MAKE_JOBS) -C $(UBOOT_INSTALL_DIR) CROSS_COMPILE=$(CROSS_COMPILE) FLASH_IC=MT29F8G08_BCH16 DDR_IC=MT41K256M16HA125E_303
-	@cp -f $(UBOOT_INSTALL_DIR)/MLO EVSE/Projects/NoodoeAX/Images/
-	@cp -f $(UBOOT_INSTALL_DIR)/u-boot.img EVSE/Projects/NoodoeAX/Images/
-	@cp -f $(UBOOT_INSTALL_DIR)/spl/u-boot-spl.bin EVSE/Projects/NoodoeAX/Images/
+	@cp -f $(UBOOT_INSTALL_DIR)/arch/arm/dts/[NoodoeDS]am335x-evm.dts $(UBOOT_INSTALL_DIR)/arch/arm/dts/am335x-evm.dts
+	$(MAKE) -j $(MAKE_JOBS) -C $(UBOOT_INSTALL_DIR) CROSS_COMPILE=$(CROSS_COMPILE) FLASH_IC=MT29F16G08_BCH16 DDR_IC=MT41K256M16HA125E_303
+	@cp -f $(UBOOT_INSTALL_DIR)/MLO EVSE/Projects/NoodoeDS/Images/
+	@cp -f $(UBOOT_INSTALL_DIR)/u-boot.img EVSE/Projects/NoodoeDS/Images/
+	@cp -f $(UBOOT_INSTALL_DIR)/spl/u-boot-spl.bin EVSE/Projects/NoodoeDS/Images/
 
-NoodoeAX-linux-default: linux_clean linux
-	@cp -f $(LINUXKERNEL_INSTALL_DIR)/arch/arm/boot/zImage EVSE/Projects/NoodoeAX/Images/
-	@cp -f $(LINUXKERNEL_INSTALL_DIR)/arch/arm/boot/dts/am335x-evm.dtb EVSE/Projects/NoodoeAX/Images/
+NoodoeDS-linux-default: linux_clean linux
+	@cp -f $(LINUXKERNEL_INSTALL_DIR)/arch/arm/boot/zImage EVSE/Projects/NoodoeDS/Images/
+	@cp -f $(LINUXKERNEL_INSTALL_DIR)/arch/arm/boot/dts/am335x-evm.dtb EVSE/Projects/NoodoeDS/Images/
 
-NoodoeAX-linux:
+NoodoeDS-linux:
 	@echo =====================================
 	@echo     Building the Linux Kernel DTBs
 	@echo =====================================
 	@rm -f $(LINUXKERNEL_INSTALL_DIR)/arch/arm/boot/dts/am335x-evm.dtb
-	@cp -f $(LINUXKERNEL_INSTALL_DIR)/arch/arm/boot/dts/[NoodoeAX]am335x-evm.dts $(LINUXKERNEL_INSTALL_DIR)/arch/arm/boot/dts/am335x-evm.dts
+	@cp -f $(LINUXKERNEL_INSTALL_DIR)/arch/arm/boot/dts/[NoodoeDS]am335x-evm.dts $(LINUXKERNEL_INSTALL_DIR)/arch/arm/boot/dts/am335x-evm.dts
 	$(MAKE) -j $(MAKE_JOBS) -C $(LINUXKERNEL_INSTALL_DIR) ARCH=arm CROSS_COMPILE=$(CROSS_COMPILE) am335x-evm.dtb
 	@echo =================================
 	@echo     Building User Linux Kernel
@@ -2042,38 +2041,38 @@ NoodoeAX-linux:
 	@rm -f $(LINUXKERNEL_INSTALL_DIR)/arch/arm/boot/zImage
 	$(MAKE) -j $(MAKE_JOBS) -C $(LINUXKERNEL_INSTALL_DIR) ARCH=arm CROSS_COMPILE=$(CROSS_COMPILE) zImage
 	$(MAKE) -j $(MAKE_JOBS) -C $(LINUXKERNEL_INSTALL_DIR) ARCH=arm CROSS_COMPILE=$(CROSS_COMPILE) modules
-	@cp -f $(LINUXKERNEL_INSTALL_DIR)/arch/arm/boot/zImage EVSE/Projects/NoodoeAX/Images/
-	@cp -f $(LINUXKERNEL_INSTALL_DIR)/arch/arm/boot/dts/am335x-evm.dtb EVSE/Projects/NoodoeAX/Images/
+	@cp -f $(LINUXKERNEL_INSTALL_DIR)/arch/arm/boot/zImage EVSE/Projects/NoodoeDS/Images/
+	@cp -f $(LINUXKERNEL_INSTALL_DIR)/arch/arm/boot/dts/am335x-evm.dtb EVSE/Projects/NoodoeDS/Images/
 	@cp -f $(LINUXKERNEL_INSTALL_DIR)/drivers/net/ethernet/qualcomm/qcaspi.ko EVSE/rootfs/lib/
 
-NoodoeAX-rootfs:
+NoodoeDS-rootfs:
 	@echo =================================
 	@echo     Building User rootfs
 	@echo =================================
-#	@cd EVSE/GPL;make Project=NoodoeAX all
-	@cd EVSE/Modularization;make TLS_EXPIRED=TLS_VALID_CERT_EXPIRED Project=NoodoeAX all
-	@cd EVSE/Projects/NoodoeAX/Apps;make Project=NoodoeAX all
-	@rm -f EVSE/Projects/NoodoeAX/Images/ramdisk.gz
+#	@cd EVSE/GPL;make Project=NoodoeDS all
+	@cd EVSE/Modularization;make TLS_EXPIRED=TLS_VALID_CERT_EXPIRED Project=NoodoeDS all
+	@cd EVSE/Projects/NoodoeDS/Apps;make Project=NoodoeDS all
+	@rm -f EVSE/Projects/NoodoeDS/Images/ramdisk.gz
 	@dd if=/dev/zero of=/dev/ram0 bs=1k count=131072
 	@mke2fs -vm0 /dev/ram0 131072
 	@tune2fs -c 0 /dev/ram0
-	@dd if=/dev/ram0 bs=1k count=131072 | gzip -v9 > EVSE/Projects/NoodoeAX/Images/ramdisk.gz
-	@mkdir -p EVSE/Projects/NoodoeAX/Images/mnt
-	@gunzip EVSE/Projects/NoodoeAX/Images/ramdisk.gz
+	@dd if=/dev/ram0 bs=1k count=131072 | gzip -v9 > EVSE/Projects/NoodoeDS/Images/ramdisk.gz
+	@mkdir -p EVSE/Projects/NoodoeDS/Images/mnt
+	@gunzip EVSE/Projects/NoodoeDS/Images/ramdisk.gz
 	@sync
-	@mount -o loop EVSE/Projects/NoodoeAX/Images/ramdisk EVSE/Projects/NoodoeAX/Images/mnt
-	@cp -rfv EVSE/rootfs/* EVSE/Projects/NoodoeAX/Images/mnt/
-	@chown www-data:www-data EVSE/Projects/NoodoeAX/Images/mnt/var/www -R
-	@chmod 777 EVSE/Projects/NoodoeAX/Images/mnt/var/log -R
-	@chmod 777 EVSE/Projects/NoodoeAX/Images/mnt/var/run -R
-	@cp -rfv EVSE/Projects/NoodoeAX/Images/root/* EVSE/Projects/NoodoeAX/Images/mnt/root
+	@mount -o loop EVSE/Projects/NoodoeDS/Images/ramdisk EVSE/Projects/NoodoeDS/Images/mnt
+	@cp -rfv EVSE/rootfs/* EVSE/Projects/NoodoeDS/Images/mnt/
+	@chown www-data:www-data EVSE/Projects/NoodoeDS/Images/mnt/var/www -R
+	@chmod 777 EVSE/Projects/NoodoeDS/Images/mnt/var/log -R
+	@chmod 777 EVSE/Projects/NoodoeDS/Images/mnt/var/run -R
+	@cp -rfv EVSE/Projects/NoodoeDS/Images/root/* EVSE/Projects/NoodoeDS/Images/mnt/root
 	@sync
 	@sleep 3
-	@umount EVSE/Projects/NoodoeAX/Images/mnt
+	@umount EVSE/Projects/NoodoeDS/Images/mnt
 	@sync
-	@gzip -v9 EVSE/Projects/NoodoeAX/Images/ramdisk
-	@rm -rfv EVSE/Projects/NoodoeAX/Images/root
-	@rm -rfv EVSE/Projects/NoodoeAX/Images/mnt
+	@gzip -v9 EVSE/Projects/NoodoeDS/Images/ramdisk
+	@rm -rfv EVSE/Projects/NoodoeDS/Images/root
+	@rm -rfv EVSE/Projects/NoodoeDS/Images/mnt
 
-NoodoeAX-all: NoodoeAX-uboot NoodoeAX-linux NoodoeAX-rootfs
+NoodoeDS-all: NoodoeDS-uboot NoodoeDS-linux NoodoeDS-rootfs
 

+ 713 - 0
board-support/linux-4.9.59+gitAUTOINC+a75d8e9305-ga75d8e9305/arch/arm/boot/dts/[NoodoeDS]am335x-evm.dts

@@ -0,0 +1,713 @@
+/*
+ * Copyright (C) 2012 Texas Instruments Incorporated - http://www.ti.com/
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ 
+#define PIN_OUTPUT		(PULL_DISABLE)
+#define PIN_OUTPUT_PULLUP	(PULL_UP)
+#define PIN_OUTPUT_PULLDOWN	0
+#define PIN_INPUT		(INPUT_EN | PULL_DISABLE)
+#define PIN_INPUT_PULLUP	(INPUT_EN | PULL_UP)
+#define PIN_INPUT_PULLDOWN	(INPUT_EN)
+
+
+ */
+/dts-v1/;
+
+#include "am33xx.dtsi"
+#include <dt-bindings/interrupt-controller/irq.h>
+
+/ {
+	model = "TI AM335x EVM";
+	compatible = "ti,am335x-evm", "ti,am33xx";
+
+	cpus {
+		cpu@0 {
+			cpu0-supply = <&vdd1_reg>;
+		};
+	};
+
+	memory {
+		device_type = "memory";
+		/*reg = <0x80000000 0x10000000>;*/ /* 256 MB */
+		reg = <0x80000000 0x20000000>; /* 512 MB */ /* +++ vern,512MB DDR ,20181030 ---*/
+	};
+	/* +++ vern,ramdisk,20181030 +++*/
+	chosen {  
+		bootargs = "console=ttyS0,115200n8 root=/dev/ram0";  
+	};  
+	/* --- vern,ramdisk ,20181030 ---*/
+	vbat: fixedregulator@0 {
+		compatible = "regulator-fixed";
+		regulator-name = "vbat";
+		regulator-min-microvolt = <5000000>;
+		regulator-max-microvolt = <5000000>;
+		regulator-boot-on;
+	};
+
+	lis3_reg: fixedregulator@1 {
+		compatible = "regulator-fixed";
+		regulator-name = "lis3_reg";
+		regulator-boot-on;
+	};
+};
+
+/******************** Pin Mux ********************/
+&am33xx_pinmux {
+	pinctrl-names = "default";
+	pinctrl-0 = <&InitialGPIO>; 
+	pinctrl-1 = <&clkout2_pin>;
+	
+	InitialGPIO: InitialGPIO {
+		pinctrl-single,pins = <
+		
+			/** Offset: 0x800 */
+			/** GPIO 0 */   
+			0x020 (PIN_INPUT | MUX_MODE7)			/* GPMC_AD8			=> 	GPIO0_22 */	/*ID BD1_1*/
+			0x024 (PIN_INPUT | MUX_MODE7)    			/* GPMC_AD9			=>	GPIO0_23 */	/*ID BD1_2*/
+			0x028 (PIN_INPUT | MUX_MODE7)    			/* GPMC_AD10		=>	GPIO0_26 */	/*IO BD1_1*/
+			0x02C (PIN_INPUT | MUX_MODE7)    		/* GPMC_AD11		=>	GPIO0_27 */	/*IO BD1_2*/
+			0x144 (PIN_INPUT | MUX_MODE7)    			/* RMII1_REF_CLK		=>	GPIO0_29 */	/*USB 0 OCP detection*/
+			0x1B0 (PIN_OUTPUT | MUX_MODE7)			/*XDMA_EVENT_INTR0	=>	GPIO0_19 */	/*AM_RFID_RST*/
+			0x1B4 (PIN_INPUT | MUX_MODE7)			/*XDMA_EVENT_INTR1	=>	GPIO0_20 */	/*AM_RFID_ICC*/
+			
+			/** GPIO 1 */
+			0x030 (PIN_INPUT | MUX_MODE7)			/* GPMC_AD12	=> 	GPIO1_12 */	/*ID BD2_1*/
+			0x034 (PIN_INPUT | MUX_MODE7)    			/* GPMC_AD13	=>	GPIO1_13 */	/*ID BD2_2*/
+			0x038 (PIN_INPUT | MUX_MODE7)    			/* GPMC_AD14	=>	GPIO1_14 */	/*IO BD2_1*/
+			0x03C (PIN_INPUT | MUX_MODE7)    		/* GPMC_AD15	=>	GPIO1_15 */	/*IO BD2_2*/
+			
+			/** GPIO 2 */
+			0x0EC (PIN_OUTPUT | MUX_MODE7)			/*LCD_AC_BIAS_EN	=>	GPIO2_25*/	/*RS-485 for module DE control*/
+			0x0E4 (PIN_OUTPUT | MUX_MODE7)			/*LCD_HSYNC		=>	GPIO2_23*/	/*RS-485 for module RE control*/
+			0x0E8 (PIN_INPUT | MUX_MODE7)			/*LCD_PCLK		=>	GPIO2_24*/	/*CCS communication board 1 proximity*/
+			0x0E0 (PIN_INPUT | MUX_MODE7)			/*LCD_VSYNC		=>	GPIO2_22*/	/*CCS communication board 2 proximity*/
+			
+			/** GPIO 3 */
+ 			AM33XX_IOPAD(0x9e4, PIN_OUTPUT_PULLDOWN | MUX_MODE7) /* (C14) EMU0.gpio3[7] */  /*CP open/short feature enable/disable, pull low for default enable*/
+           			AM33XX_IOPAD(0x9e8, PIN_OUTPUT_PULLUP | MUX_MODE7)   /* (B14) EMU1.gpio3[8] */  /*4G module reset, pull high to reset when entry kernel, after Application start, it should be pull low.*/
+			0x194 (PIN_INPUT | MUX_MODE7)			/*MCASP0_FSX		=>	GPIO3_15*/	/*Emergency Stop button detect*/
+			0x1A0 (PIN_INPUT | MUX_MODE7)			/*MCASP0_ACLKR	=>	GPIO3_18*/	/*USB1 OCP detect*/
+			0x19C (PIN_INPUT | MUX_MODE7)			/*MCASP0_AHCLKR	=>	GPIO3_17*/	/*Emergency IO for AM3352 and STM32F407*/
+			0x190 (PIN_OUTPUT | MUX_MODE7)			/*MCASP0_ACLKX	=>	GPIO3_14*/	/*Ethernet PHY reset*/
+			0x1A4 (PIN_OUTPUT | MUX_MODE7)			/* MCASP0_FSR		=>	GPIO3_19 */	/*SMR Enable control_1*/
+			0x198 (PIN_OUTPUT | MUX_MODE7)			/* MCASP0_AXR0	=>	GPIO3_16 */	/*CSU board function OK indicator.*/
+			0x1A8 (PIN_OUTPUT | MUX_MODE7)			/* MCASP0_AXR1	=>	GPIO3_20 */	/*SMR Enable control_2*/
+			
+		>;
+	};
+	
+	i2c0_pins: pinmux_i2c0_pins {
+		pinctrl-single,pins = <
+			0x188 (PIN_INPUT_PULLUP | MUX_MODE0)	/* i2c0_sda.i2c0_sda */
+			0x18c (PIN_INPUT_PULLUP | MUX_MODE0)	/* i2c0_scl.i2c0_scl */
+		>;
+	};
+#if 1
+	i2c1_pins: pinmux_i2c1_pins {
+		pinctrl-single,pins = <
+			0x158 (PIN_INPUT_PULLUP | MUX_MODE2)	/* spi0_d1.i2c1_sda */
+			0x15c (PIN_INPUT_PULLUP | MUX_MODE2)	/* spi0_cs0.i2c1_scl */
+		>;
+	};
+#endif
+	uart0_pins: pinmux_uart0_pins {
+		pinctrl-single,pins = <
+			0x170 (PIN_INPUT_PULLUP | MUX_MODE0)		/* uart0_rxd	=>	uart0_rxd */
+			0x174 (PIN_OUTPUT_PULLDOWN | MUX_MODE0)	/* uart0_txd	=>	uart0_txd */
+		>;
+	};
+	
+	uart1_pins: pinmux_uart1_pins {
+		pinctrl-single,pins = <
+			0x184 (PIN_OUTPUT_PULLDOWN | MUX_MODE0) 		/* uart1_txd	=>	uart1_txd */
+			0x180 (PIN_INPUT_PULLUP | MUX_MODE0)			/* uart1_rxd	=>	uart1_rxd */
+		>;
+	};
+
+	uart2_pins: pinmux_uart2_pins {
+		pinctrl-single,pins = <
+			0x150 (PIN_INPUT_PULLUP | MUX_MODE1)			/* SPI0_SCLK	=>	UART2_RXD */
+			0x154 (PIN_OUTPUT_PULLDOWN | MUX_MODE1)		/* SPI0_D0	=>	UART2_TXD */
+		>;
+	};
+	
+	uart3_pins: pinmux_uart3_pins {
+		pinctrl-single,pins = <
+			0x160 (PIN_INPUT_PULLUP | MUX_MODE1)		/* SPI0_CS1				=>	uart3_rxd */
+			0x164 (PIN_OUTPUT_PULLDOWN | MUX_MODE1)	/* ECAP0_IN_PWM0_OUT		=>	uart3_txd */
+		>;
+	};
+
+	uart5_pins: pinmux_uart5_pins {
+		pinctrl-single,pins = <
+			0x0C0 (PIN_OUTPUT_PULLDOWN | MUX_MODE4)		/* LCD_DATA8	=>	DUART5_TX*/
+			0x0C4 (PIN_INPUT_PULLUP | MUX_MODE4)			/* LCD_DATA9	=>	UART5_RX*/
+		>;
+	};
+	
+	clkout2_pin: pinmux_clkout2_pin {
+		pinctrl-single,pins = <
+			0x1b4 (PIN_OUTPUT_PULLDOWN | MUX_MODE3)	/* xdma_event_intr1.clkout2 */
+		>;
+	};
+
+	nandflash_pins_default: nandflash_pins_default {
+		pinctrl-single,pins = <
+			0x0 (PIN_INPUT_PULLUP | MUX_MODE0)	/* gpmc_ad0.gpmc_ad0 */
+			0x4 (PIN_INPUT_PULLUP | MUX_MODE0)	/* gpmc_ad1.gpmc_ad1 */
+			0x8 (PIN_INPUT_PULLUP | MUX_MODE0)	/* gpmc_ad2.gpmc_ad2 */
+			0xc (PIN_INPUT_PULLUP | MUX_MODE0)	/* gpmc_ad3.gpmc_ad3 */
+			0x10 (PIN_INPUT_PULLUP | MUX_MODE0)	/* gpmc_ad4.gpmc_ad4 */
+			0x14 (PIN_INPUT_PULLUP | MUX_MODE0)	/* gpmc_ad5.gpmc_ad5 */
+			0x18 (PIN_INPUT_PULLUP | MUX_MODE0)	/* gpmc_ad6.gpmc_ad6 */
+			0x1c (PIN_INPUT_PULLUP | MUX_MODE0)	/* gpmc_ad7.gpmc_ad7 */
+			0x70 (PIN_INPUT_PULLUP | MUX_MODE0)	/* gpmc_wait0.gpmc_wait0 */
+			0x74 (PIN_INPUT_PULLUP | MUX_MODE7)	/* gpmc_wpn.gpio0_31 */
+			0x7c (PIN_OUTPUT | MUX_MODE0)		/* gpmc_csn0.gpmc_csn0  */
+			0x90 (PIN_OUTPUT | MUX_MODE0)		/* gpmc_advn_ale.gpmc_advn_ale */
+			0x94 (PIN_OUTPUT | MUX_MODE0)		/* gpmc_oen_ren.gpmc_oen_ren */
+			0x98 (PIN_OUTPUT | MUX_MODE0)		/* gpmc_wen.gpmc_wen */
+			0x9c (PIN_OUTPUT | MUX_MODE0)		/* gpmc_be0n_cle.gpmc_be0n_cle */
+		>;
+	};
+
+	nandflash_pins_sleep: nandflash_pins_sleep {
+		pinctrl-single,pins = <
+			0x0 (PIN_INPUT_PULLDOWN | MUX_MODE7)
+			0x4 (PIN_INPUT_PULLDOWN | MUX_MODE7)
+			0x8 (PIN_INPUT_PULLDOWN | MUX_MODE7)
+			0xc (PIN_INPUT_PULLDOWN | MUX_MODE7)
+			0x10 (PIN_INPUT_PULLDOWN | MUX_MODE7)
+			0x14 (PIN_INPUT_PULLDOWN | MUX_MODE7)
+			0x18 (PIN_INPUT_PULLDOWN | MUX_MODE7)
+			0x1c (PIN_INPUT_PULLDOWN | MUX_MODE7)
+			0x70 (PIN_INPUT_PULLDOWN | MUX_MODE7)
+			0x74 (PIN_INPUT_PULLDOWN | MUX_MODE7)
+			0x7c (PIN_INPUT_PULLDOWN | MUX_MODE7)
+			0x90 (PIN_INPUT_PULLDOWN | MUX_MODE7)
+			0x94 (PIN_INPUT_PULLDOWN | MUX_MODE7)
+			0x98 (PIN_INPUT_PULLDOWN | MUX_MODE7)
+			0x9c (PIN_INPUT_PULLDOWN | MUX_MODE7)
+		>;
+	};
+
+	cpsw_default: cpsw_default {
+		pinctrl-single,pins = <					
+		
+			/* Slave 1 */
+			0x108 (PIN_INPUT_PULLUP | MUX_MODE0)		/* MII1_COL.gmii1_col */
+			0x10C(PIN_INPUT_PULLUP | MUX_MODE0)		/* MII1_CRS.MII1_CRS */
+			0x110 (PIN_INPUT_PULLUP | MUX_MODE0)		/* MII1_RX_ER.gmii1_rxerr */
+			0x12c (PIN_INPUT_PULLUP | MUX_MODE0)		/* mii1_txclk.mii1_txclk */
+			0x130 (PIN_INPUT_PULLUP | MUX_MODE0)		/* mii1_rxclk.mii1_rxclk */
+			0x118 (PIN_INPUT_PULLUP | MUX_MODE0)		/* mii1_rxdv.mii1_rxdv */
+			0x134 (PIN_INPUT_PULLUP | MUX_MODE0)		/* mii1_rxd3.rgmii1_rd3 */
+			0x138 (PIN_INPUT_PULLUP | MUX_MODE0)		/* mii1_rxd2.rgmii1_rd2 */
+			0x13c (PIN_INPUT_PULLUP | MUX_MODE0)		/* mii1_rxd1.rgmii1_rd1 */
+			0x140 (PIN_INPUT_PULLUP | MUX_MODE0)		/* mii1_rxd0.rgmii1_rd0 */	
+			0x114 (PIN_OUTPUT_PULLDOWN | MUX_MODE0)		/* mii1_txen.mii1_txen */
+			0x11c (PIN_OUTPUT_PULLDOWN | MUX_MODE0)		/* mii1_txd3.rgmii1_td3 */
+			0x120 (PIN_OUTPUT_PULLDOWN | MUX_MODE0)		/* mii1_txd2.rgmii1_td2 */
+			0x124 (PIN_OUTPUT_PULLDOWN | MUX_MODE0)		/* mii1_txd1.rgmii1_td1 */
+			0x128 (PIN_OUTPUT_PULLDOWN | MUX_MODE0)		/* mii1_txd0.rgmii1_td0 */      	
+			
+			/* Slave 2 */
+			AM33XX_IOPAD(0x878, PIN_INPUT_PULLUP | MUX_MODE1)					/* gpmc_ben1.mii2_col */
+			AM33XX_IOPAD(0x888, PIN_INPUT_PULLUP | MUX_MODE2)					/* GPMC_CSn3.rmii2_crs_dv*/								
+			/*AM33XX_IOPAD(0x874, PIN_INPUT_PULLUP | MUX_MODE1)*/					/* gpmc_wpn.mii2_rxerr */
+			AM33XX_IOPAD(0x858, PIN_INPUT_PULLUP | MUX_MODE1)					/* gpmc_a6.mii2_txclk */
+			AM33XX_IOPAD(0x85c, PIN_INPUT_PULLUP | MUX_MODE1)					/* gpmc_a7.mii2_rxclk */
+			AM33XX_IOPAD(0x844, PIN_INPUT_PULLUP | MUX_MODE1)					/* gpmc_a1.mii2_rxdv */
+			AM33XX_IOPAD(0x860, PIN_INPUT_PULLUP | MUX_MODE1)					/* gpmc_a8.mii2_rxd3 */
+			AM33XX_IOPAD(0x864, PIN_INPUT_PULLUP | MUX_MODE1)					/* gpmc_a9.mii2_rxd2 */
+			AM33XX_IOPAD(0x868, PIN_INPUT_PULLUP | MUX_MODE1)					/* gpmc_a10.mii2_rxd1 */
+			AM33XX_IOPAD(0x86c, PIN_INPUT_PULLUP | MUX_MODE1)					/* gpmc_a11.mii2_rxd0 */
+			AM33XX_IOPAD(0x840, PIN_OUTPUT_PULLDOWN | MUX_MODE1)				/* gpmc_a0.mii2_txen */
+			AM33XX_IOPAD(0x848, PIN_OUTPUT_PULLDOWN | MUX_MODE1)				/* gpmc_a2.mii2_txd3 */
+			AM33XX_IOPAD(0x84c, PIN_OUTPUT_PULLDOWN | MUX_MODE1)				/* gpmc_a3.mii2_txd2 */
+			AM33XX_IOPAD(0x850, PIN_OUTPUT_PULLDOWN | MUX_MODE1)				/* gpmc_a4.mii2_txd1 */
+			AM33XX_IOPAD(0x854, PIN_OUTPUT_PULLDOWN | MUX_MODE1)				/* gpmc_a5.mii2_txd0 */
+
+		>;
+	};
+
+	cpsw_sleep: cpsw_sleep {
+		pinctrl-single,pins = <
+			/* Slave 1 reset value */
+			0x114 (PIN_INPUT_PULLDOWN | MUX_MODE7)
+			0x118 (PIN_INPUT_PULLDOWN | MUX_MODE7)
+			0x11c (PIN_INPUT_PULLDOWN | MUX_MODE7)
+			0x120 (PIN_INPUT_PULLDOWN | MUX_MODE7)
+			0x124 (PIN_INPUT_PULLDOWN | MUX_MODE7)
+			0x128 (PIN_INPUT_PULLDOWN | MUX_MODE7)
+			0x12c (PIN_INPUT_PULLDOWN | MUX_MODE7)
+			0x130 (PIN_INPUT_PULLDOWN | MUX_MODE7)
+			0x134 (PIN_INPUT_PULLDOWN | MUX_MODE7)
+			0x138 (PIN_INPUT_PULLDOWN | MUX_MODE7)
+			0x13c (PIN_INPUT_PULLDOWN | MUX_MODE7)
+			0x140 (PIN_INPUT_PULLDOWN | MUX_MODE7)		
+			
+			/* Slave 2 */
+			AM33XX_IOPAD(0x888, PIN_INPUT_PULLDOWN | MUX_MODE7)					/* GPMC_CSn3.rmii2_crs_dv*/	
+			AM33XX_IOPAD(0x840, PIN_INPUT_PULLDOWN | MUX_MODE7)				/* gpmc_a0.mii2_txen */
+			AM33XX_IOPAD(0x844, PIN_INPUT_PULLDOWN | MUX_MODE7)	/* gpmc_a1.mii2_rxdv */
+			AM33XX_IOPAD(0x848, PIN_INPUT_PULLDOWN | MUX_MODE7)				/* gpmc_a2.mii2_txd3 */
+			AM33XX_IOPAD(0x84c, PIN_INPUT_PULLDOWN | MUX_MODE7)			/* gpmc_a3.mii2_txd2 */
+			AM33XX_IOPAD(0x850, PIN_INPUT_PULLDOWN | MUX_MODE7)				/* gpmc_a4.mii2_txd1 */
+			AM33XX_IOPAD(0x854, PIN_INPUT_PULLDOWN | MUX_MODE7)				/* gpmc_a5.mii2_txd0 */
+			AM33XX_IOPAD(0x858, PIN_INPUT_PULLDOWN | MUX_MODE7)	/* gpmc_a6.mii2_txclk */
+			AM33XX_IOPAD(0x85c, PIN_INPUT_PULLDOWN | MUX_MODE7)	/* gpmc_a7.mii2_rxclk */
+			AM33XX_IOPAD(0x860, PIN_INPUT_PULLDOWN | MUX_MODE7)	/* gpmc_a8.mii2_rxd3 */
+			AM33XX_IOPAD(0x864, PIN_INPUT_PULLDOWN | MUX_MODE7)	/* gpmc_a9.mii2_rxd2 */
+			AM33XX_IOPAD(0x868, PIN_INPUT_PULLDOWN | MUX_MODE7)	/* gpmc_a10.mii2_rxd1 */
+			AM33XX_IOPAD(0x86c, PIN_INPUT_PULLDOWN | MUX_MODE7)	/* gpmc_a11.mii2_rxd0 */
+			/*AM33XX_IOPAD(0x874, PIN_INPUT_PULLDOWN | MUX_MODE7)*/	/* gpmc_wpn.mii2_rxerr */
+			AM33XX_IOPAD(0x878, PIN_INPUT_PULLDOWN | MUX_MODE7)	/* gpmc_ben1.mii2_col */
+			
+		>;
+	};
+
+
+	davinci_mdio_default: davinci_mdio_default {
+		pinctrl-single,pins = <
+			/* MDIO */
+			0x148 (PIN_INPUT_PULLUP | SLEWCTRL_FAST | MUX_MODE0)	/* mdio_data.mdio_data */
+			0x14c (PIN_OUTPUT_PULLUP | MUX_MODE0)			/* mdio_clk.mdio_clk */
+		>;
+	};
+
+	davinci_mdio_sleep: davinci_mdio_sleep {
+		pinctrl-single,pins = <
+			/* MDIO reset value */
+			0x148 (PIN_INPUT_PULLDOWN | MUX_MODE7)
+			0x14c (PIN_INPUT_PULLDOWN | MUX_MODE7)
+		>;
+	};
+
+	mmc1_pins_default: pinmux_mmc1_pins {
+		pinctrl-single,pins = <
+			0x0F0 (PIN_INPUT_PULLUP | MUX_MODE0)    	/* mmc0_dat3.mmc0_dat3 */
+			0x0F4 (PIN_INPUT_PULLUP | MUX_MODE0)    	/* mmc0_dat2.mmc0_dat2 */
+			0x0F8 (PIN_INPUT_PULLUP | MUX_MODE0)    	/* mmc0_dat1.mmc0_dat1 */
+			0x0FC (PIN_INPUT_PULLUP | MUX_MODE0)    	/* mmc0_dat0.mmc0_dat0 */
+			0x100 (PIN_INPUT_PULLUP | MUX_MODE0)    	/* mmc0_clk.mmc0_clk */
+			0x104 (PIN_INPUT_PULLUP | MUX_MODE0)    	/* mmc0_cmd.mmc0_cmd */
+			0x1AC (PIN_INPUT_PULLUP | MUX_MODE7)	/* MCASP0_AHCLKX.GPIO3_21 */
+		>;
+	};
+
+	dcan0_pins_default: dcan0_pins_default {
+		pinctrl-single,pins = <		
+			0x178 (PIN_OUTPUT_PULLUP | MUX_MODE2)			/* uart1_ctsn	=>	d_can0_tx */
+			0x17C (PIN_INPUT_PULLDOWN | MUX_MODE2)		/* uart1_rtsn	=>	d_can0_rx */
+		>;
+	};
+	
+	dcan1_pins_default: dcan1_pins_default {
+		pinctrl-single,pins = <
+			0x168 (PIN_OUTPUT_PULLUP | MUX_MODE2)		/* UART0_CTSn		=>	d_can1_tx */
+			0x16C (PIN_INPUT_PULLDOWN | MUX_MODE2)	/* UART0_RTSn		=>	d_can1_rx */
+		>;
+	};
+#if 0
+	ehrpwm1_pins: ehrpwm1_pins {
+		pinctrl-single,pins = <			
+			0x0C8 (PIN_OUTPUT | MUX_MODE2) /* LCD_DATA10.eHRPWM1A */
+		>;
+	};
+	
+	ehrpwm2_pins: ehrpwm2_pins {
+		pinctrl-single,pins =< 
+			0x0A4 (PIN_OUTPUT | MUX_MODE3)	/* LCD_DATA1.eHRPWM2B */
+		>;                
+    };	
+	 
+#endif  
+};
+
+
+/******************** Peripheral Init ********************/			
+&uart0 {
+	pinctrl-names = "default";
+	pinctrl-0 = <&uart0_pins>;
+
+	status = "okay";
+};
+
+&uart1 {
+	pinctrl-names = "default";
+	pinctrl-0 = <&uart1_pins>;
+
+	status = "okay";
+};
+
+&uart2 {
+	pinctrl-names = "default";
+	pinctrl-0 = <&uart2_pins>;
+
+	status = "okay";
+};
+
+&uart3 {
+	pinctrl-names = "default";
+	pinctrl-0 = <&uart3_pins>;
+
+	status = "okay";
+};
+
+&uart5 {
+	pinctrl-names = "default";
+	pinctrl-0 = <&uart5_pins>;
+
+	status = "okay";
+};
+
+&i2c0 {
+	pinctrl-names = "default";
+	pinctrl-0 = <&i2c0_pins>;
+
+	status = "okay";
+	clock-frequency = <400000>;
+
+	tps: tps@2d {
+		reg = <0x2d>;
+	};
+	
+/*	rtc0: rtc@51 {
+                compatible = "nxp,pcf85063";
+                reg = <0x51>;
+        };*/	
+};
+#if 1
+&i2c1 {
+	pinctrl-names = "default";
+	pinctrl-0 = <&i2c1_pins>;
+
+	status = "okay";
+	clock-frequency = <400000>;
+
+	rtc0: rtc@51 {
+                compatible = "nxp,pcf85063";
+                reg = <0x51>;
+        };
+};
+#endif
+&usb {
+	status = "okay";
+};
+
+&usb_ctrl_mod {
+	status = "okay";
+};
+
+&usb0_phy {
+	status = "okay";
+};
+
+&usb1_phy {
+	status = "okay";
+};
+
+&usb0 {
+	status = "okay";
+};
+
+&usb1 {
+	status = "okay";
+	dr_mode = "host";
+};
+
+&cppi41dma  {
+	status = "okay";
+};
+
+&elm {
+	status = "okay";
+};
+#if 0
+&epwmss1 {
+	status = "okay";      
+
+	ehrpwm1: pwm@48302200 {
+		status = "okay";
+		pinctrl-names = "default";
+		pinctrl-0 = <&ehrpwm1_pins>;
+	};
+};
+
+&epwmss2 {
+	status = "okay";   
+
+	ehrpwm2: pwm@48304200 {
+		status = "okay";
+		pinctrl-names = "default";
+		pinctrl-0 = <&ehrpwm2_pins>;
+	};	   
+};
+#endif
+&gpmc {
+	status = "okay";
+	pinctrl-names = "default", "sleep";
+	pinctrl-0 = <&nandflash_pins_default>;
+	pinctrl-1 = <&nandflash_pins_sleep>;
+	/*ranges = <0 0 0x08000000 0x10000000>;*/	/* CS0: NAND */
+	ranges = <0 0 0x08000000 0x80000000>;	/*+++ vern,NAND,20181030 ---*/
+	nand@0,0 {
+		compatible = "ti,omap2-nand";
+		reg = <0 0 4>; /* CS0, offset 0, IO size 4 */
+		interrupt-parent = <&gpmc>;
+		interrupts = <0 IRQ_TYPE_NONE>, /* fifoevent */
+                    <1 IRQ_TYPE_NONE>;	/* termcount */
+		rb-gpios = <&gpmc 0 GPIO_ACTIVE_HIGH>; /* gpmc_wait0 */
+		ti,nand-ecc-opt = "bch16";
+		ti,elm-id = <&elm>;
+		nand-bus-width = <8>;
+		gpmc,device-width = <1>;
+		gpmc,sync-clk-ps = <0>;
+		gpmc,cs-on-ns = <0>;
+		gpmc,cs-rd-off-ns = <44>;
+		gpmc,cs-wr-off-ns = <44>;
+		gpmc,adv-on-ns = <6>;
+		gpmc,adv-rd-off-ns = <34>;
+		gpmc,adv-wr-off-ns = <44>;
+		gpmc,we-on-ns = <0>;
+		gpmc,we-off-ns = <40>;
+		gpmc,oe-on-ns = <0>;
+		gpmc,oe-off-ns = <54>;
+		gpmc,access-ns = <64>;
+		gpmc,rd-cycle-ns = <82>;
+		gpmc,wr-cycle-ns = <82>;
+		gpmc,wait-on-read = "true";
+		gpmc,wait-on-write = "true";
+		gpmc,bus-turnaround-ns = <0>;
+		gpmc,cycle2cycle-delay-ns = <0>;
+		gpmc,clk-activation-ns = <0>;
+		gpmc,wait-monitoring-ns = <0>;
+		gpmc,wr-access-ns = <40>;
+		gpmc,wr-data-mux-bus-ns = <0>;
+		/* MTD partition table */
+		/* All SPL-* partitions are sized to minimal length
+		 * which can be independently programmable. For
+		 * NAND flash this is equal to size of erase-block */
+		#address-cells = <1>;
+		#size-cells = <1>;
+		partition@0 {
+			label = "SPL";
+			reg = <0x00000000 0x00080000>;
+		};
+		partition@1 {
+			label = "Primary u-boot";
+			reg = <0x00080000 0x00100000>;
+		};
+		partition@2 {
+			label = "u-boot-env";
+			reg = <0x00180000 0x00080000>;
+		};
+		partition@3 {
+			label = "Secondary u-boot";
+			reg = <0x00200000 0x00100000>;
+		};
+		partition@4 {
+			label = "Primary dtb";
+			reg = <0x00300000 0x00080000>;
+		};
+		partition@5 {
+			label = "Secondary dtb";
+			reg = <0x00380000 0x00080000>;
+		};
+		partition@6 {
+			label = "Primary kernel";
+			reg = <0x00400000 0x00A00000>;
+		};
+		partition@7 {
+			label = "Secondary kernel";
+			reg = <0x00E00000 0x00A00000>;
+		};
+		partition@8 {
+			label = "Primary rootfs";
+			reg = <0x03000000 0x03000000>;
+		};
+		partition@9 {
+			label = "Secondary rootfs";
+			reg = <0x06000000 0x03000000>;
+		};
+		partition@10 {
+			label = "Primary user configuration";
+			reg = <0x09000000 0x00600000>;
+		};
+		partition@11 {
+			label = "Secondary user configuration";
+			reg = <0x09600000 0x00600000>;
+		};
+		partition@12 {
+			label = "Factory default configuration";
+			reg = <0x09C00000 0x00600000>;
+		};
+		partition@13 {
+			label = "Storage";
+			reg = <0x0A200000 0x75E00000>;
+		};
+	};
+};
+
+#include "tps65910.dtsi"
+
+&tps {
+	vcc1-supply = <&vbat>;
+	vcc2-supply = <&vbat>;
+	vcc3-supply = <&vbat>;
+	vcc4-supply = <&vbat>;
+	vcc5-supply = <&vbat>;
+	vcc6-supply = <&vbat>;
+	vcc7-supply = <&vbat>;
+	vccio-supply = <&vbat>;
+
+	regulators {
+		vrtc_reg: regulator@0 {
+			regulator-always-on;
+		};
+
+		vio_reg: regulator@1 {
+			regulator-always-on;
+		};
+
+		vdd1_reg: regulator@2 {
+			/* VDD_MPU voltage limits 0.95V - 1.325V with +/-4% tolerance */
+			regulator-name = "vdd_mpu";
+			regulator-min-microvolt = <912500>;
+			regulator-max-microvolt = <1378000>;
+			regulator-boot-on;
+			regulator-always-on;
+		};
+
+		vdd2_reg: regulator@3 {
+			/* VDD_CORE voltage limits 0.95V - 1.1V with +/-4% tolerance */
+			regulator-name = "vdd_core";
+			regulator-min-microvolt = <912500>;
+			regulator-max-microvolt = <1150000>;
+			regulator-boot-on;
+			regulator-always-on;
+		};
+
+		vdd3_reg: regulator@4 {
+			regulator-always-on;
+		};
+
+		vdig1_reg: regulator@5 {
+			regulator-always-on;
+		};
+
+		vdig2_reg: regulator@6 {
+			regulator-always-on;
+		};
+
+		vpll_reg: regulator@7 {
+			regulator-always-on;
+		};
+
+		vdac_reg: regulator@8 {
+			regulator-always-on;
+		};
+
+		vaux1_reg: regulator@9 {
+			regulator-always-on;
+		};
+
+		vaux2_reg: regulator@10 {
+			regulator-always-on;
+		};
+
+		vaux33_reg: regulator@11 {
+			regulator-always-on;
+		};
+
+		vmmc_reg: regulator@12 {
+			regulator-min-microvolt = <1800000>;
+			regulator-max-microvolt = <3300000>;
+			regulator-always-on;
+		};
+	};
+};
+
+&mac {
+	pinctrl-names = "default", "sleep";
+	pinctrl-0 = <&cpsw_default>;
+	pinctrl-1 = <&cpsw_sleep>;
+	dual_emac = <1>;
+	status = "okay";
+};
+
+&davinci_mdio {
+	pinctrl-names = "default", "sleep";
+	pinctrl-0 = <&davinci_mdio_default>;
+	pinctrl-1 = <&davinci_mdio_sleep>;
+	status = "okay";
+};
+
+&cpsw_emac0 {
+	phy_id = <&davinci_mdio>, <1>;
+ 	phy-mode = "mii";
+ 	dual_emac_res_vlan = <1>;
+};
+
+&cpsw_emac1 {
+	phy_id = <&davinci_mdio>, <2>;
+ 	phy-mode = "mii";
+ 	dual_emac_res_vlan = <2>;
+};
+
+&tscadc {
+	status = "okay";
+	/*tsc {
+		ti,wires = <4>;
+		ti,x-plate-resistance = <200>;
+		ti,coordinate-readouts = <5>;
+		ti,wire-config = <0x00 0x11 0x22 0x33>;
+	};*/
+
+	adc {
+		ti,adc-channels = <0 1 2 3 4 5 6 7>;
+	};
+};
+
+&mmc1 {
+	status = "okay";
+	vmmc-supply = <&vmmc_reg>;
+	bus-width = <4>;
+	pinctrl-names = "default";
+	pinctrl-0 = <&mmc1_pins_default>;
+	cd-gpios = <&gpio3 21 GPIO_ACTIVE_LOW>;
+};
+
+&edma {
+	ti,edma-xbar-event-map = /bits/ 16 <1 12
+					    2 13>;
+};
+
+
+&sham {
+	status = "okay";
+};
+
+&aes {
+	status = "okay";
+};
+
+&wkup_m3 {
+	ti,scale-data-fw = "am335x-evm-scale-data.bin";
+};
+
+&dcan0 {
+	status = "okay";	
+	pinctrl-names = "default";
+	pinctrl-0 = <&dcan0_pins_default>;
+};
+
+&dcan1 {
+	status = "okay";	
+	pinctrl-names = "default";
+	pinctrl-0 = <&dcan1_pins_default>;
+};

+ 1 - 0
board-support/linux-4.9.59+gitAUTOINC+a75d8e9305-ga75d8e9305/lib/.crc7.ko.cmd

@@ -0,0 +1 @@
+cmd_lib/crc7.ko := /opt/ti-processor-sdk-linux-am335x-evm-04.02.00.09/linux-devkit/sysroots/x86_64-arago-linux/usr/bin/arm-linux-gnueabihf-ld -EL -r  -T ./scripts/module-common.lds --build-id  -o lib/crc7.ko lib/crc7.o lib/crc7.mod.o ;  true

+ 46 - 0
board-support/linux-4.9.59+gitAUTOINC+a75d8e9305-ga75d8e9305/lib/.gen_crc32table.cmd

@@ -0,0 +1,46 @@
+cmd_lib/gen_crc32table := gcc -Wp,-MD,lib/.gen_crc32table.d -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer -std=gnu89     -o lib/gen_crc32table lib/gen_crc32table.c  
+
+source_lib/gen_crc32table := lib/gen_crc32table.c
+
+deps_lib/gen_crc32table := \
+  /usr/include/stdc-predef.h \
+  /usr/include/stdio.h \
+  /usr/include/x86_64-linux-gnu/bits/libc-header-start.h \
+  /usr/include/features.h \
+  /usr/include/x86_64-linux-gnu/sys/cdefs.h \
+  /usr/include/x86_64-linux-gnu/bits/wordsize.h \
+  /usr/include/x86_64-linux-gnu/bits/long-double.h \
+  /usr/include/x86_64-linux-gnu/gnu/stubs.h \
+  /usr/include/x86_64-linux-gnu/gnu/stubs-64.h \
+  /usr/lib/gcc/x86_64-linux-gnu/9/include/stddef.h \
+  /usr/lib/gcc/x86_64-linux-gnu/9/include/stdarg.h \
+  /usr/include/x86_64-linux-gnu/bits/types.h \
+  /usr/include/x86_64-linux-gnu/bits/timesize.h \
+  /usr/include/x86_64-linux-gnu/bits/typesizes.h \
+  /usr/include/x86_64-linux-gnu/bits/time64.h \
+  /usr/include/x86_64-linux-gnu/bits/types/__fpos_t.h \
+  /usr/include/x86_64-linux-gnu/bits/types/__mbstate_t.h \
+  /usr/include/x86_64-linux-gnu/bits/types/__fpos64_t.h \
+  /usr/include/x86_64-linux-gnu/bits/types/__FILE.h \
+  /usr/include/x86_64-linux-gnu/bits/types/FILE.h \
+  /usr/include/x86_64-linux-gnu/bits/types/struct_FILE.h \
+  /usr/include/x86_64-linux-gnu/bits/stdio_lim.h \
+  /usr/include/x86_64-linux-gnu/bits/sys_errlist.h \
+  /usr/include/x86_64-linux-gnu/bits/stdio.h \
+  /usr/include/x86_64-linux-gnu/bits/stdio2.h \
+  lib/crc32defs.h \
+    $(wildcard include/config/crc32/sliceby8.h) \
+    $(wildcard include/config/crc32/sliceby4.h) \
+    $(wildcard include/config/crc32/sarwate.h) \
+    $(wildcard include/config/crc32/bit.h) \
+    $(wildcard include/config/64bit.h) \
+  /usr/include/inttypes.h \
+  /usr/lib/gcc/x86_64-linux-gnu/9/include/stdint.h \
+  /usr/include/stdint.h \
+  /usr/include/x86_64-linux-gnu/bits/wchar.h \
+  /usr/include/x86_64-linux-gnu/bits/stdint-intn.h \
+  /usr/include/x86_64-linux-gnu/bits/stdint-uintn.h \
+
+lib/gen_crc32table: $(deps_lib/gen_crc32table)
+
+$(deps_lib/gen_crc32table):

+ 802 - 0
board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/arch/arm/dts/[NoodoeDS]am335x-evm.dts

@@ -0,0 +1,802 @@
+/*
+ * Copyright (C) 2012 Texas Instruments Incorporated - http://www.ti.com/
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+/dts-v1/;
+
+#include "am33xx.dtsi"
+#include <dt-bindings/interrupt-controller/irq.h>
+
+/ {
+	model = "TI AM335x EVM";
+	compatible = "ti,am335x-evm", "ti,am33xx";
+
+	chosen {
+		stdout-path = &uart0;
+		tick-timer = &timer2;
+	};
+
+	cpus {
+		cpu@0 {
+			cpu0-supply = <&vdd1_reg>;
+		};
+	};
+
+	memory {
+		device_type = "memory";
+		//reg = <0x80000000 0x10000000>; /* 256 MB */
+		reg = <0x80000000 0x20000000>; /* 512 MB */ /* +++ vern,512MB DDR ,20181030 ---*/
+	};
+
+	vbat: fixedregulator@0 {
+		compatible = "regulator-fixed";
+		regulator-name = "vbat";
+		regulator-min-microvolt = <5000000>;
+		regulator-max-microvolt = <5000000>;
+		regulator-boot-on;
+	};
+
+	lis3_reg: fixedregulator@1 {
+		compatible = "regulator-fixed";
+		regulator-name = "lis3_reg";
+		regulator-boot-on;
+	};
+
+	wlan_en_reg: fixedregulator@2 {
+		compatible = "regulator-fixed";
+		regulator-name = "wlan-en-regulator";
+		regulator-min-microvolt = <1800000>;
+		regulator-max-microvolt = <1800000>;
+
+		/* WLAN_EN GPIO for this board - Bank1, pin16 */
+		gpio = <&gpio1 16 0>;
+
+		/* WLAN card specific delay */
+		startup-delay-us = <70000>;
+		enable-active-high;
+	};
+
+	matrix_keypad: matrix_keypad@0 {
+		compatible = "gpio-matrix-keypad";
+		debounce-delay-ms = <5>;
+		col-scan-delay-us = <2>;
+
+		row-gpios = <&gpio1 25 GPIO_ACTIVE_HIGH		/* Bank1, pin25 */
+			     &gpio1 26 GPIO_ACTIVE_HIGH		/* Bank1, pin26 */
+			     &gpio1 27 GPIO_ACTIVE_HIGH>;	/* Bank1, pin27 */
+
+		col-gpios = <&gpio1 21 GPIO_ACTIVE_HIGH		/* Bank1, pin21 */
+			     &gpio1 22 GPIO_ACTIVE_HIGH>;	/* Bank1, pin22 */
+
+		linux,keymap = <0x0000008b	/* MENU */
+				0x0100009e	/* BACK */
+				0x02000069	/* LEFT */
+				0x0001006a	/* RIGHT */
+				0x0101001c	/* ENTER */
+				0x0201006c>;	/* DOWN */
+	};
+
+	gpio_keys: volume_keys@0 {
+		compatible = "gpio-keys";
+		#address-cells = <1>;
+		#size-cells = <0>;
+		autorepeat;
+
+		switch@9 {
+			label = "volume-up";
+			linux,code = <115>;
+			gpios = <&gpio0 2 GPIO_ACTIVE_LOW>;
+			gpio-key,wakeup;
+		};
+
+		switch@10 {
+			label = "volume-down";
+			linux,code = <114>;
+			gpios = <&gpio0 3 GPIO_ACTIVE_LOW>;
+			gpio-key,wakeup;
+		};
+	};
+
+	backlight {
+		compatible = "pwm-backlight";
+		pwms = <&ecap0 0 50000 0>;
+		brightness-levels = <0 51 53 56 62 75 101 152 255>;
+		default-brightness-level = <8>;
+	};
+
+	panel {
+		compatible = "ti,tilcdc,panel";
+		status = "okay";
+		pinctrl-names = "default";
+		pinctrl-0 = <&lcd_pins_s0>;
+		panel-info {
+			ac-bias           = <255>;
+			ac-bias-intrpt    = <0>;
+			dma-burst-sz      = <16>;
+			bpp               = <32>;
+			fdd               = <0x80>;
+			sync-edge         = <0>;
+			sync-ctrl         = <1>;
+			raster-order      = <0>;
+			fifo-th           = <0>;
+		};
+
+		display-timings {
+			800x480p62 {
+				clock-frequency = <30000000>;
+				hactive = <800>;
+				vactive = <480>;
+				hfront-porch = <39>;
+				hback-porch = <39>;
+				hsync-len = <47>;
+				vback-porch = <29>;
+				vfront-porch = <13>;
+				vsync-len = <2>;
+				hsync-active = <1>;
+				vsync-active = <1>;
+			};
+		};
+	};
+
+	sound {
+		compatible = "ti,da830-evm-audio";
+		ti,model = "AM335x-EVM";
+		ti,audio-codec = <&tlv320aic3106>;
+		ti,mcasp-controller = <&mcasp1>;
+		ti,codec-clock-rate = <12000000>;
+		ti,audio-routing =
+			"Headphone Jack",       "HPLOUT",
+			"Headphone Jack",       "HPROUT",
+			"LINE1L",               "Line In",
+			"LINE1R",               "Line In";
+	};
+};
+
+&am33xx_pinmux {
+	pinctrl-names = "default";
+	pinctrl-0 = <&matrix_keypad_s0 &volume_keys_s0 &clkout2_pin>;
+
+	matrix_keypad_s0: matrix_keypad_s0 {
+		pinctrl-single,pins = <
+			0x54 (PIN_OUTPUT_PULLDOWN | MUX_MODE7)	/* gpmc_a5.gpio1_21 */
+			0x58 (PIN_OUTPUT_PULLDOWN | MUX_MODE7)	/* gpmc_a6.gpio1_22 */
+			0x64 (PIN_INPUT_PULLDOWN | MUX_MODE7)	/* gpmc_a9.gpio1_25 */
+			0x68 (PIN_INPUT_PULLDOWN | MUX_MODE7)	/* gpmc_a10.gpio1_26 */
+			0x6c (PIN_INPUT_PULLDOWN | MUX_MODE7)	/* gpmc_a11.gpio1_27 */
+		>;
+	};
+
+	volume_keys_s0: volume_keys_s0 {
+		pinctrl-single,pins = <
+			0x150 (PIN_INPUT_PULLDOWN | MUX_MODE7)	/* spi0_sclk.gpio0_2 */
+			0x154 (PIN_INPUT_PULLDOWN | MUX_MODE7)	/* spi0_d0.gpio0_3 */
+		>;
+	};
+
+	i2c0_pins: pinmux_i2c0_pins {
+		pinctrl-single,pins = <
+			0x188 (PIN_INPUT_PULLUP | MUX_MODE0)	/* i2c0_sda.i2c0_sda */
+			0x18c (PIN_INPUT_PULLUP | MUX_MODE0)	/* i2c0_scl.i2c0_scl */
+		>;
+	};
+
+	i2c1_pins: pinmux_i2c1_pins {
+		pinctrl-single,pins = <
+			0x158 (PIN_INPUT_PULLUP | MUX_MODE2)	/* spi0_d1.i2c1_sda */
+			0x15c (PIN_INPUT_PULLUP | MUX_MODE2)	/* spi0_cs0.i2c1_scl */
+		>;
+	};
+
+	uart0_pins: pinmux_uart0_pins {
+		pinctrl-single,pins = <
+			0x170 (PIN_INPUT_PULLUP | MUX_MODE0)	/* uart0_rxd.uart0_rxd */
+			0x174 (PIN_OUTPUT_PULLDOWN | MUX_MODE0)	/* uart0_txd.uart0_txd */
+		>;
+	};
+
+	uart1_pins: pinmux_uart1_pins {
+		pinctrl-single,pins = <
+			0x178 (PIN_INPUT | MUX_MODE0)		/* uart1_ctsn.uart1_ctsn */
+			0x17C (PIN_OUTPUT_PULLDOWN | MUX_MODE0)	/* uart1_rtsn.uart1_rtsn */
+			0x180 (PIN_INPUT_PULLUP | MUX_MODE0)	/* uart1_rxd.uart1_rxd */
+			0x184 (PIN_OUTPUT_PULLDOWN | MUX_MODE0)	/* uart1_txd.uart1_txd */
+		>;
+	};
+
+	clkout2_pin: pinmux_clkout2_pin {
+		pinctrl-single,pins = <
+			0x1b4 (PIN_OUTPUT_PULLDOWN | MUX_MODE3)	/* xdma_event_intr1.clkout2 */
+		>;
+	};
+
+	nandflash_pins_s0: nandflash_pins_s0 {
+		pinctrl-single,pins = <
+			0x0 (PIN_INPUT_PULLUP | MUX_MODE0)	/* gpmc_ad0.gpmc_ad0 */
+			0x4 (PIN_INPUT_PULLUP | MUX_MODE0)	/* gpmc_ad1.gpmc_ad1 */
+			0x8 (PIN_INPUT_PULLUP | MUX_MODE0)	/* gpmc_ad2.gpmc_ad2 */
+			0xc (PIN_INPUT_PULLUP | MUX_MODE0)	/* gpmc_ad3.gpmc_ad3 */
+			0x10 (PIN_INPUT_PULLUP | MUX_MODE0)	/* gpmc_ad4.gpmc_ad4 */
+			0x14 (PIN_INPUT_PULLUP | MUX_MODE0)	/* gpmc_ad5.gpmc_ad5 */
+			0x18 (PIN_INPUT_PULLUP | MUX_MODE0)	/* gpmc_ad6.gpmc_ad6 */
+			0x1c (PIN_INPUT_PULLUP | MUX_MODE0)	/* gpmc_ad7.gpmc_ad7 */
+			0x70 (PIN_INPUT_PULLUP | MUX_MODE0)	/* gpmc_wait0.gpmc_wait0 */
+			0x74 (PIN_INPUT_PULLUP | MUX_MODE7)	/* gpmc_wpn.gpio0_30 */
+			0x7c (PIN_OUTPUT | MUX_MODE0)		/* gpmc_csn0.gpmc_csn0  */
+			0x90 (PIN_OUTPUT | MUX_MODE0)		/* gpmc_advn_ale.gpmc_advn_ale */
+			0x94 (PIN_OUTPUT | MUX_MODE0)		/* gpmc_oen_ren.gpmc_oen_ren */
+			0x98 (PIN_OUTPUT | MUX_MODE0)		/* gpmc_wen.gpmc_wen */
+			0x9c (PIN_OUTPUT | MUX_MODE0)		/* gpmc_be0n_cle.gpmc_be0n_cle */
+		>;
+	};
+
+	ecap0_pins: backlight_pins {
+		pinctrl-single,pins = <
+			0x164 0x0	/* eCAP0_in_PWM0_out.eCAP0_in_PWM0_out MODE0 */
+		>;
+	};
+
+	cpsw_default: cpsw_default {
+		pinctrl-single,pins = <
+			/* Slave 1 */
+			0x110 (PIN_INPUT_PULLDOWN | MUX_MODE0)		/* MII1_RX_ER.gmii1_rxerr */
+			0x118 (PIN_INPUT_PULLDOWN | MUX_MODE0)		/* mii1_rxdv.mii1_rxdv */
+			0x12c (PIN_INPUT_PULLDOWN | MUX_MODE0)		/* mii1_txclk.mii1_txclk */
+			0x130 (PIN_INPUT_PULLDOWN | MUX_MODE0)		/* mii1_rxclk.mii1_rxclk */
+			0x134 (PIN_INPUT_PULLDOWN | MUX_MODE0)		/* mii1_rxd3.rgmii1_rd3 */
+			0x138 (PIN_INPUT_PULLDOWN | MUX_MODE0)		/* mii1_rxd2.rgmii1_rd2 */
+			0x13c (PIN_INPUT_PULLDOWN | MUX_MODE0)		/* mii1_rxd1.rgmii1_rd1 */
+			0x140 (PIN_INPUT_PULLDOWN | MUX_MODE0)		/* mii1_rxd0.rgmii1_rd0 */	
+			0x114 (PIN_OUTPUT_PULLDOWN | MUX_MODE0)		/* mii1_txen.mii1_txen */
+			0x11c (PIN_OUTPUT_PULLDOWN | MUX_MODE0)		/* mii1_txd3.rgmii1_td3 */
+			0x120 (PIN_OUTPUT_PULLDOWN | MUX_MODE0)		/* mii1_txd2.rgmii1_td2 */
+			0x124 (PIN_OUTPUT_PULLDOWN | MUX_MODE0)		/* mii1_txd1.rgmii1_td1 */
+			0x128 (PIN_OUTPUT_PULLDOWN | MUX_MODE0)		/* mii1_txd0.rgmii1_td0 */      
+		>;
+	};
+
+	cpsw_sleep: cpsw_sleep {
+		pinctrl-single,pins = <
+			/* Slave 1 reset value */
+			0x110 (PIN_INPUT_PULLDOWN | MUX_MODE7)		/* MII1_RX_ER.gmii1_rxerr */
+			//0x108 (PIN_INPUT_PULLDOWN | MUX_MODE7)		/* MII1_COL.gmii1_col */
+			//0x10C (PIN_INPUT_PULLDOWN | MUX_MODE7)	/* MII1_CRS.gmii1_crs */
+			0x114 (PIN_INPUT_PULLDOWN | MUX_MODE7)
+			0x118 (PIN_INPUT_PULLDOWN | MUX_MODE7)
+			0x11c (PIN_INPUT_PULLDOWN | MUX_MODE7)
+			0x120 (PIN_INPUT_PULLDOWN | MUX_MODE7)
+			0x124 (PIN_INPUT_PULLDOWN | MUX_MODE7)
+			0x128 (PIN_INPUT_PULLDOWN | MUX_MODE7)
+			0x12c (PIN_INPUT_PULLDOWN | MUX_MODE7)
+			0x130 (PIN_INPUT_PULLDOWN | MUX_MODE7)
+			0x134 (PIN_INPUT_PULLDOWN | MUX_MODE7)
+			0x138 (PIN_INPUT_PULLDOWN | MUX_MODE7)
+			0x13c (PIN_INPUT_PULLDOWN | MUX_MODE7)
+			0x140 (PIN_INPUT_PULLDOWN | MUX_MODE7)
+		>;
+	};
+
+	davinci_mdio_default: davinci_mdio_default {
+		pinctrl-single,pins = <
+			/* MDIO */
+			0x148 (PIN_INPUT_PULLUP | SLEWCTRL_FAST | MUX_MODE0)	/* mdio_data.mdio_data */
+			0x14c (PIN_OUTPUT_PULLUP | MUX_MODE0)			/* mdio_clk.mdio_clk */
+		>;
+	};
+
+	davinci_mdio_sleep: davinci_mdio_sleep {
+		pinctrl-single,pins = <
+			/* MDIO reset value */
+			0x148 (PIN_INPUT_PULLDOWN | MUX_MODE7)
+			0x14c (PIN_INPUT_PULLDOWN | MUX_MODE7)
+		>;
+	};
+
+	#if 0
+	mmc1_pins: pinmux_mmc1_pins {
+		pinctrl-single,pins = <
+			0x160 (PIN_INPUT | MUX_MODE7) /* spi0_cs1.gpio0_6 */
+		>;
+	};
+	#endif
+	mmc1_pins_default: pinmux_mmc1_pins {
+		pinctrl-single,pins = <
+			0x0F0 (PIN_INPUT_PULLUP | MUX_MODE0)    /* mmc0_dat3.mmc0_dat3 */
+			0x0F4 (PIN_INPUT_PULLUP | MUX_MODE0)    /* mmc0_dat2.mmc0_dat2 */
+			0x0F8 (PIN_INPUT_PULLUP | MUX_MODE0)    /* mmc0_dat1.mmc0_dat1 */
+			0x0FC (PIN_INPUT_PULLUP | MUX_MODE0)    /* mmc0_dat0.mmc0_dat0 */
+			0x100 (PIN_INPUT_PULLUP | MUX_MODE0)    /* mmc0_clk.mmc0_clk */
+			0x104 (PIN_INPUT_PULLUP | MUX_MODE0)    /* mmc0_cmd.mmc0_cmd */
+			/*0x0A8 (PIN_INPUT | MUX_MODE7)*/	        /* LCD_DATA2.GPIO2_8 */
+			0x08C (PIN_INPUT | MUX_MODE7)	        /* GPMC_CLK.GPIO2_1 */
+		>;
+	};
+	mmc3_pins: pinmux_mmc3_pins {
+		pinctrl-single,pins = <
+			0x44 (PIN_INPUT_PULLUP | MUX_MODE3)	/* gpmc_a1.mmc2_dat0, INPUT_PULLUP | MODE3 */
+			0x48 (PIN_INPUT_PULLUP | MUX_MODE3)	/* gpmc_a2.mmc2_dat1, INPUT_PULLUP | MODE3 */
+			0x4C (PIN_INPUT_PULLUP | MUX_MODE3)	/* gpmc_a3.mmc2_dat2, INPUT_PULLUP | MODE3 */
+			0x78 (PIN_INPUT_PULLUP | MUX_MODE3)	/* gpmc_ben1.mmc2_dat3, INPUT_PULLUP | MODE3 */
+			0x88 (PIN_INPUT_PULLUP | MUX_MODE3)	/* gpmc_csn3.mmc2_cmd, INPUT_PULLUP | MODE3 */
+			0x8C (PIN_INPUT_PULLUP | MUX_MODE3)	/* gpmc_clk.mmc2_clk, INPUT_PULLUP | MODE3 */
+		>;
+	};
+
+	wlan_pins: pinmux_wlan_pins {
+		pinctrl-single,pins = <
+			0x40 (PIN_OUTPUT_PULLDOWN | MUX_MODE7)	/* gpmc_a0.gpio1_16 */
+			0x19C (PIN_INPUT | MUX_MODE7)		/* mcasp0_ahclkr.gpio3_17 */
+			0x1AC (PIN_OUTPUT_PULLDOWN | MUX_MODE7)	/* mcasp0_ahclkx.gpio3_21 */
+		>;
+	};
+
+	lcd_pins_s0: lcd_pins_s0 {
+		pinctrl-single,pins = <
+			0x20 (PIN_OUTPUT | MUX_MODE1)		/* gpmc_ad8.lcd_data23 */
+			0x24 (PIN_OUTPUT | MUX_MODE1)		/* gpmc_ad9.lcd_data22 */
+			0x28 (PIN_OUTPUT | MUX_MODE1)		/* gpmc_ad10.lcd_data21 */
+			0x2c (PIN_OUTPUT | MUX_MODE1)		/* gpmc_ad11.lcd_data20 */
+			0x30 (PIN_OUTPUT | MUX_MODE1)		/* gpmc_ad12.lcd_data19 */
+			0x34 (PIN_OUTPUT | MUX_MODE1)		/* gpmc_ad13.lcd_data18 */
+			0x38 (PIN_OUTPUT | MUX_MODE1)		/* gpmc_ad14.lcd_data17 */
+			0x3c (PIN_OUTPUT | MUX_MODE1)		/* gpmc_ad15.lcd_data16 */
+			0xa0 (PIN_OUTPUT | MUX_MODE0)		/* lcd_data0.lcd_data0 */
+			0xa4 (PIN_OUTPUT | MUX_MODE0)		/* lcd_data1.lcd_data1 */
+			0xa8 (PIN_OUTPUT | MUX_MODE0)		/* lcd_data2.lcd_data2 */
+			0xac (PIN_OUTPUT | MUX_MODE0)		/* lcd_data3.lcd_data3 */
+			0xb0 (PIN_OUTPUT | MUX_MODE0)		/* lcd_data4.lcd_data4 */
+			0xb4 (PIN_OUTPUT | MUX_MODE0)		/* lcd_data5.lcd_data5 */
+			0xb8 (PIN_OUTPUT | MUX_MODE0)		/* lcd_data6.lcd_data6 */
+			0xbc (PIN_OUTPUT | MUX_MODE0)		/* lcd_data7.lcd_data7 */
+			0xc0 (PIN_OUTPUT | MUX_MODE0)		/* lcd_data8.lcd_data8 */
+			0xc4 (PIN_OUTPUT | MUX_MODE0)		/* lcd_data9.lcd_data9 */
+			0xc8 (PIN_OUTPUT | MUX_MODE0)		/* lcd_data10.lcd_data10 */
+			0xcc (PIN_OUTPUT | MUX_MODE0)		/* lcd_data11.lcd_data11 */
+			0xd0 (PIN_OUTPUT | MUX_MODE0)		/* lcd_data12.lcd_data12 */
+			0xd4 (PIN_OUTPUT | MUX_MODE0)		/* lcd_data13.lcd_data13 */
+			0xd8 (PIN_OUTPUT | MUX_MODE0)		/* lcd_data14.lcd_data14 */
+			0xdc (PIN_OUTPUT | MUX_MODE0)		/* lcd_data15.lcd_data15 */
+			0xe0 (PIN_OUTPUT | MUX_MODE0)		/* lcd_vsync.lcd_vsync */
+			0xe4 (PIN_OUTPUT | MUX_MODE0)		/* lcd_hsync.lcd_hsync */
+			0xe8 (PIN_OUTPUT | MUX_MODE0)		/* lcd_pclk.lcd_pclk */
+			0xec (PIN_OUTPUT | MUX_MODE0)		/* lcd_ac_bias_en.lcd_ac_bias_en */
+		>;
+	};
+#if 0
+	am335x_evm_audio_pins: am335x_evm_audio_pins {
+		pinctrl-single,pins = <
+			0x10c (PIN_INPUT_PULLDOWN | MUX_MODE4) /* mii1_crs.mcasp1_aclkx */
+			0x110 (PIN_INPUT_PULLDOWN | MUX_MODE4) /* mii1_rxerr.mcasp1_fsx */
+			0x108 (PIN_OUTPUT_PULLDOWN | MUX_MODE4) /* mii1_col.mcasp1_axr2 */
+			0x144 (PIN_INPUT_PULLDOWN | MUX_MODE4) /* rmii1_ref_clk.mcasp1_axr3 */
+		>;
+	};
+#endif
+	dcan1_pins_default: dcan1_pins_default {
+		pinctrl-single,pins = <
+			0x168 (PIN_OUTPUT | MUX_MODE2) /* uart0_ctsn.d_can1_tx */
+			0x16c (PIN_INPUT_PULLDOWN | MUX_MODE2) /* uart0_rtsn.d_can1_rx */
+		>;
+	};
+};
+
+&uart0 {
+	pinctrl-names = "default";
+	pinctrl-0 = <&uart0_pins>;
+
+	status = "okay";
+};
+
+&uart1 {
+	pinctrl-names = "default";
+	pinctrl-0 = <&uart1_pins>;
+
+	status = "okay";
+};
+
+&i2c0 {
+	pinctrl-names = "default";
+	pinctrl-0 = <&i2c0_pins>;
+
+	status = "okay";
+	clock-frequency = <400000>;
+
+	tps: tps@2d {
+		reg = <0x2d>;
+	};
+};
+
+&usb {
+	status = "okay";
+};
+
+&usb_ctrl_mod {
+	status = "okay";
+};
+
+&usb0_phy {
+	status = "okay";
+};
+
+&usb1_phy {
+	status = "okay";
+};
+
+&usb0 {
+	status = "okay";
+};
+
+&usb1 {
+	status = "okay";
+	dr_mode = "host";
+};
+
+&cppi41dma  {
+	status = "okay";
+};
+
+&i2c1 {
+	pinctrl-names = "default";
+	pinctrl-0 = <&i2c1_pins>;
+
+	status = "okay";
+	clock-frequency = <100000>;
+
+	lis331dlh: lis331dlh@18 {
+		compatible = "st,lis331dlh", "st,lis3lv02d";
+		reg = <0x18>;
+		Vdd-supply = <&lis3_reg>;
+		Vdd_IO-supply = <&lis3_reg>;
+
+		st,click-single-x;
+		st,click-single-y;
+		st,click-single-z;
+		st,click-thresh-x = <10>;
+		st,click-thresh-y = <10>;
+		st,click-thresh-z = <10>;
+		st,irq1-click;
+		st,irq2-click;
+		st,wakeup-x-lo;
+		st,wakeup-x-hi;
+		st,wakeup-y-lo;
+		st,wakeup-y-hi;
+		st,wakeup-z-lo;
+		st,wakeup-z-hi;
+		st,min-limit-x = <120>;
+		st,min-limit-y = <120>;
+		st,min-limit-z = <140>;
+		st,max-limit-x = <550>;
+		st,max-limit-y = <550>;
+		st,max-limit-z = <750>;
+	};
+
+	tsl2550: tsl2550@39 {
+		compatible = "taos,tsl2550";
+		reg = <0x39>;
+	};
+
+	tmp275: tmp275@48 {
+		compatible = "ti,tmp275";
+		reg = <0x48>;
+	};
+
+	tlv320aic3106: tlv320aic3106@1b {
+		compatible = "ti,tlv320aic3106";
+		reg = <0x1b>;
+		status = "okay";
+
+		/* Regulators */
+		AVDD-supply = <&vaux2_reg>;
+		IOVDD-supply = <&vaux2_reg>;
+		DRVDD-supply = <&vaux2_reg>;
+		DVDD-supply = <&vbat>;
+	};
+};
+
+&lcdc {
+	status = "okay";
+};
+
+&elm {
+	status = "okay";
+};
+
+&epwmss0 {
+	status = "okay";
+
+	ecap0: ecap@48300100 {
+		status = "okay";
+		pinctrl-names = "default";
+		pinctrl-0 = <&ecap0_pins>;
+	};
+};
+
+&gpmc {
+	status = "okay";
+	pinctrl-names = "default";
+	pinctrl-0 = <&nandflash_pins_s0>;
+	/*ranges = <0 0 0x08000000 0x1000000>;*/	/* CS0: 16MB for NAND */
+	ranges = <0 0 0x08000000 0x80000000>;	/*+++ vern,NAND,20181030 ---*/
+	nand@0,0 {
+		reg = <0 0 4>; /* CS0, offset 0, IO size 4 */
+		ti,nand-ecc-opt = "bch16";
+		ti,elm-id = <&elm>;
+		nand-bus-width = <8>;
+		gpmc,device-width = <1>;
+		gpmc,sync-clk-ps = <0>;
+		gpmc,cs-on-ns = <0>;
+		gpmc,cs-rd-off-ns = <44>;
+		gpmc,cs-wr-off-ns = <44>;
+		gpmc,adv-on-ns = <6>;
+		gpmc,adv-rd-off-ns = <34>;
+		gpmc,adv-wr-off-ns = <44>;
+		gpmc,we-on-ns = <0>;
+		gpmc,we-off-ns = <40>;
+		gpmc,oe-on-ns = <0>;
+		gpmc,oe-off-ns = <54>;
+		gpmc,access-ns = <64>;
+		gpmc,rd-cycle-ns = <82>;
+		gpmc,wr-cycle-ns = <82>;
+		gpmc,wait-on-read = "true";
+		gpmc,wait-on-write = "true";
+		gpmc,bus-turnaround-ns = <0>;
+		gpmc,cycle2cycle-delay-ns = <0>;
+		gpmc,clk-activation-ns = <0>;
+		gpmc,wait-monitoring-ns = <0>;
+		gpmc,wr-access-ns = <40>;
+		gpmc,wr-data-mux-bus-ns = <0>;
+		/* MTD partition table */
+		/* All SPL-* partitions are sized to minimal length
+		 * which can be independently programmable. For
+		 * NAND flash this is equal to size of erase-block */
+		#address-cells = <1>;
+		#size-cells = <1>;
+		partition@0 {
+			label = "SPL";
+			reg = <0x00000000 0x00080000>;
+		};
+		partition@1 {
+			label = "Primary u-boot";
+			reg = <0x00080000 0x00100000>;
+		};
+		partition@2 {
+			label = "u-boot-env";
+			reg = <0x00180000 0x00080000>;
+		};
+		partition@3 {
+			label = "Secondary u-boot";
+			reg = <0x00200000 0x00100000>;
+		};
+		partition@4 {
+			label = "Primary dtb";
+			reg = <0x00300000 0x00080000>;
+		};
+		partition@5 {
+			label = "Secondary dtb";
+			reg = <0x00380000 0x00080000>;
+		};
+		partition@6 {
+			label = "Primary kernel";
+			reg = <0x00400000 0x00A00000>;
+		};
+		partition@7 {
+			label = "Secondary kernel";
+			reg = <0x00E00000 0x00A00000>;
+		};
+		partition@8 {
+			label = "Primary rootfs";
+			reg = <0x03000000 0x03000000>;
+		};
+		partition@9 {
+			label = "Secondary rootfs";
+			reg = <0x06000000 0x03000000>;
+		};
+		partition@10 {
+			label = "Primary user configuration";
+			reg = <0x09000000 0x00600000>;
+		};
+		partition@11 {
+			label = "Secondary user configuration";
+			reg = <0x09600000 0x00600000>;
+		};
+		partition@12 {
+			label = "Factory default configuration";
+			reg = <0x09C00000 0x00600000>;
+		};
+		partition@13 {
+			label = "Storage";
+			reg = <0x0A200000 0x75E00000>;
+		};
+	};
+};
+
+#include "tps65910.dtsi"
+#if 0
+&mcasp1 {
+		pinctrl-names = "default";
+		pinctrl-0 = <&am335x_evm_audio_pins>;
+
+		status = "okay";
+
+		op-mode = <0>;          /* MCASP_IIS_MODE */
+		tdm-slots = <2>;
+		/* 4 serializers */
+		serial-dir = <  /* 0: INACTIVE, 1: TX, 2: RX */
+			0 0 1 2
+		>;
+		tx-num-evt = <32>;
+		rx-num-evt = <32>;
+};
+#endif
+&tps {
+	vcc1-supply = <&vbat>;
+	vcc2-supply = <&vbat>;
+	vcc3-supply = <&vbat>;
+	vcc4-supply = <&vbat>;
+	vcc5-supply = <&vbat>;
+	vcc6-supply = <&vbat>;
+	vcc7-supply = <&vbat>;
+	vccio-supply = <&vbat>;
+
+	regulators {
+		vrtc_reg: regulator@0 {
+			regulator-always-on;
+		};
+
+		vio_reg: regulator@1 {
+			regulator-always-on;
+		};
+
+		vdd1_reg: regulator@2 {
+			/* VDD_MPU voltage limits 0.95V - 1.26V with +/-4% tolerance */
+			regulator-name = "vdd_mpu";
+			regulator-min-microvolt = <912500>;
+			regulator-max-microvolt = <1312500>;
+			regulator-boot-on;
+			regulator-always-on;
+		};
+
+		vdd2_reg: regulator@3 {
+			/* VDD_CORE voltage limits 0.95V - 1.1V with +/-4% tolerance */
+			regulator-name = "vdd_core";
+			regulator-min-microvolt = <912500>;
+			regulator-max-microvolt = <1150000>;
+			regulator-boot-on;
+			regulator-always-on;
+		};
+
+		vdd3_reg: regulator@4 {
+			regulator-always-on;
+		};
+
+		vdig1_reg: regulator@5 {
+			regulator-always-on;
+		};
+
+		vdig2_reg: regulator@6 {
+			regulator-always-on;
+		};
+
+		vpll_reg: regulator@7 {
+			regulator-always-on;
+		};
+
+		vdac_reg: regulator@8 {
+			regulator-always-on;
+		};
+
+		vaux1_reg: regulator@9 {
+			regulator-always-on;
+		};
+
+		vaux2_reg: regulator@10 {
+			regulator-always-on;
+		};
+
+		vaux33_reg: regulator@11 {
+			regulator-always-on;
+		};
+
+		vmmc_reg: regulator@12 {
+			regulator-min-microvolt = <1800000>;
+			regulator-max-microvolt = <3300000>;
+			regulator-always-on;
+		};
+	};
+};
+
+&mac {
+	pinctrl-names = "default", "sleep";
+	pinctrl-0 = <&cpsw_default>;
+	pinctrl-1 = <&cpsw_sleep>;
+	status = "okay";
+};
+
+&davinci_mdio {
+	pinctrl-names = "default", "sleep";
+	pinctrl-0 = <&davinci_mdio_default>;
+	pinctrl-1 = <&davinci_mdio_sleep>;
+	status = "okay";
+};
+
+&cpsw_emac0 {
+	phy_id = <&davinci_mdio>, <1>;
+	phy-mode = "mii";
+};
+
+&cpsw_emac1 {
+	phy_id = <&davinci_mdio>, <2>;
+	phy-mode = "mii";
+};
+
+&tscadc {
+	status = "okay";
+	tsc {
+		ti,wires = <4>;
+		ti,x-plate-resistance = <200>;
+		ti,coordinate-readouts = <5>;
+		ti,wire-config = <0x00 0x11 0x22 0x33>;
+		ti,charge-delay = <0x400>;
+	};
+
+	adc {
+		ti,adc-channels = <4 5 6 7>;
+	};
+};
+
+&mmc1 {
+	status = "okay";
+	vmmc-supply = <&vmmc_reg>;
+	bus-width = <4>;
+	pinctrl-names = "default";
+	pinctrl-0 = <&mmc1_pins_default>;
+	cd-gpios = <&gpio2 1 GPIO_ACTIVE_LOW>;
+};
+
+
+&mmc3 {
+	/* these are on the crossbar and are outlined in the
+	   xbar-event-map element */
+	dmas = <&edma 12
+		&edma 13>;
+	dma-names = "tx", "rx";
+	status = "okay";
+	vmmc-supply = <&wlan_en_reg>;
+	bus-width = <4>;
+	pinctrl-names = "default";
+	pinctrl-0 = <&mmc3_pins &wlan_pins>;
+	ti,non-removable;
+	ti,needs-special-hs-handling;
+	cap-power-off-card;
+	keep-power-in-suspend;
+
+	#address-cells = <1>;
+	#size-cells = <0>;
+	wlcore: wlcore@0 {
+		compatible = "ti,wl1835";
+		reg = <2>;
+		interrupt-parent = <&gpio3>;
+		interrupts = <17 IRQ_TYPE_LEVEL_HIGH>;
+	};
+};
+
+&edma {
+	ti,edma-xbar-event-map = /bits/ 16 <1 12
+					    2 13>;
+};
+
+&sham {
+	status = "okay";
+};
+
+&aes {
+	status = "okay";
+};
+
+&dcan1 {
+	status = "disabled";	/* Enable only if Profile 1 is selected */
+	pinctrl-names = "default";
+	pinctrl-0 = <&dcan1_pins_default>;
+};

+ 1 - 1
run_gen_make_script.sh

@@ -14,7 +14,7 @@ echo -e "$1-uboot:"
 echo -e "\t@echo ==================================="
 echo -e "\t@echo    Building U-boot"
 echo -e "\t@echo ==================================="
-echo -e "\t@cp -f \$(UBOOT_INSTALL_DIR)/arch/arm/dts/[$1]am335x-evm.dts\$(UBOOT_INSTALL_DIR)/arch/arm/dts/am335x-evm.dts"
+echo -e "\t@cp -f \$(UBOOT_INSTALL_DIR)/arch/arm/dts/[$1]am335x-evm.dts \$(UBOOT_INSTALL_DIR)/arch/arm/dts/am335x-evm.dts"
 echo -e "\t\$(MAKE) -j \$(MAKE_JOBS) -C \$(UBOOT_INSTALL_DIR) CROSS_COMPILE=\$(CROSS_COMPILE) FLASH_IC=MT29F16G08_BCH16 DDR_IC=MT41K256M16HA125E_303"
 echo -e "\t@cp -f \$(UBOOT_INSTALL_DIR)/MLO EVSE/Projects/$1/Images/"
 echo -e "\t@cp -f \$(UBOOT_INSTALL_DIR)/u-boot.img EVSE/Projects/$1/Images/"