Переглянути джерело

2021-10-07 / Alston Lin
Actions
1. Support north america ocpp function (DataTransfer、DefaultPrice key、CustomIdleFeeAfterStop key) - Tariff function
2. Reset the Wifi/4G module when 4G/Wifi is enabled but disconnected from the backend
3. Trigger chademo to try to communicate with EV when receiving status notification message
4. Change the reason for stopping charging when stopped from local to emcStop
5. Support max charging profile
6. Modify the check timeout function
7. Add the interval for detecting psu communication, force to disconnect AC for 30s when it timeout
8. Add watch dog function
9. Create a fork to check if the entire task is alive
10. To use only one PSU to check the GFD function
11. System Optimization

Files
1. As follow commit history

alston 3 роки тому
батько
коміт
ffc9a8621c

+ 128 - 0
EVSE/Projects/DS60-120/Apps/CheckSystemTask.c

@@ -0,0 +1,128 @@
+/*
+ * CheckTask.c
+ *
+ *  Created on: 2021年9月2日
+ *      Author: 7564
+ */
+
+#include "CheckSystemTask.h"
+
+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 == 0x09 || systemPage == 0x0A)
+	{
+		if (count_main < 5 || count_psuComm < 2)
+		{
+			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 < 2)
+			{
+				system("killall Module_EvComm");
+				sleep(3);
+				system("/root/Module_EvComm &");
+			}
+		}
+
+		sleep(2);
+	}
+
+	if (count_main < 5)
+		result = 1;
+	else if (count_evComm < 2)
+		result = 2;
+	else if (count_psuComm < 2)
+		result = 3;
+	else if (system("pidof -s Module_EventLogging > /dev/null") != 0)
+		result = 4;
+	else if (system("pidof -s Module_PrimaryComm > /dev/null") != 0)
+		result = 5;
+	else if (system("pidof -s Module_LcmControl > /dev/null") != 0)
+		result = 6;
+	else if (system("pidof -s Module_InternalComm > /dev/null") != 0)
+		result = 7;
+
+	return result;
+}

+ 41 - 0
EVSE/Projects/DS60-120/Apps/CheckSystemTask.h

@@ -0,0 +1,41 @@
+/*
+ * 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>
+
+unsigned char CheckSystemTask(unsigned char systemPage);
+
+#endif /* CHECKSYSTEMTASK_H_ */

+ 68 - 46
EVSE/Projects/DS60-120/Apps/Config.h

@@ -7,6 +7,8 @@
 #ifndef CONFIG_H_
 #define CONFIG_H_
 
+#include    <sys/types.h>
+
 #define ShmCsuMeterKey			2001
 #define ShmCommonKey			2002
 
@@ -14,27 +16,6 @@ typedef unsigned char			byte;
 
 #define TOTAL_QUANTITY_GUN			4				//Max Count
 
-#define MODE_BOOT					0
-#define MODE_IDLE					1
-#define MODE_AUTHORIZING			2
-#define MODE_REASSIGN_CHECK			3
-#define MODE_REASSIGN				4
-#define MODE_PRECHARGE				5
-#define MODE_PREPARE_FOR_EV			6
-#define MODE_PREPARE_FOR_EVSE		7
-#define MODE_CHARGING				8
-#define MODE_TERMINATING			9
-#define MODE_COMPLETE				10
-#define MODE_ALARM					11
-#define MODE_FAULT					12
-#define MODE_RESERVATION			13
-#define MODE_BOOKING				14
-#define MODE_MAINTAIN				15
-#define MODE_DEBUG					16
-#define MODE_CCS_PRECHARGE_STEP0	17 	// ready for ccs precharge processing, For D+ relay to precharge relay
-#define MODE_CCS_PRECHARGE_STEP1	18	// waitting for ev board inform to enter to charging, For precharge relay to D+ relay
-#define MODE_UPDATE					19
-
 #define GFD_WAIT			0
 #define GFD_PASS			1
 #define GFD_FAIL			2
@@ -48,31 +29,6 @@ typedef unsigned char			byte;
 #define BOOTTING			0
 #define BOOT_COMPLETE		1
 
-enum _SYSTEM_STATUS
-{
-	S_BOOTING = 						0,
-    S_IDLE,
-	S_AUTHORIZING,
-	S_REASSIGN_CHECK,
-	S_REASSIGN,
-	S_PREPARNING,
-	S_PREPARING_FOR_EV,
-	S_PREPARING_FOR_EVSE,
-    S_CHARGING,
-	S_TERMINATING,
-	S_COMPLETE,
-	S_ALARM,
-	S_FAULT,
-	S_RESERVATION,
-	S_BOOKING,
-	S_MAINTAIN,
-	S_DEBUG,
-	S_CCS_PRECHARGE_ST0,
-	S_CCS_PRECHARGE_ST1,
-	S_UPDATE,
-	S_NONE,
-};
-
 enum _AC_SYSTEM_STATUS
 {
 	AC_SYS_NONE = 	0,
@@ -187,6 +143,12 @@ enum _SYS_WIFI_MODE
 	_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,
@@ -222,6 +184,17 @@ enum _ALARM_LEVEL_TAG
 	_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;
@@ -237,6 +210,26 @@ struct MeterInformation
 	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,
@@ -273,6 +266,14 @@ enum CHARGER_TYPE
 	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
+};
+
 typedef union
 {
     unsigned int GunErrMessage;
@@ -354,6 +355,27 @@ struct DcCommonInformation
 
 	// auto run flag
 	byte _isAutoRunTest;
+
+	// chademo try to communicaton flag (for tesla adapter)
+	struct ChademoTryCommunicationKey _cha_try_communication[2];
+
+	// 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[2][12];
+	byte conn_1_count;
+	byte conn_2_count;
+
+	// Use ccid to obtain authorization
+	byte enObtainAuthorizbyCCID;
+	byte isSendStartTransation[2];
+
+	// balance information - for tariff
+	struct BalanceInfo balanceInfo;
 };
 
 #endif /* CONFIG_H_ */

+ 7 - 7
EVSE/Projects/DS60-120/Apps/Ev_Comm.c

@@ -112,7 +112,7 @@ void GetHardwareVersion(byte gun_index, byte toId)
 	SendCmdToEvboard(EvFrameMsg, data, 0);
 }
 
-void SetChargingPermission(byte gun_index, byte permissionStatus, short aOutputPw, short aOutputCur, short aOutputVol, byte toId)
+void SetChargingPermission(byte gun_index, byte permissionStatus, float aOutputPw, float aOutputCur, short aOutputVol, byte toId)
 {
 	EvFrame EvFrameMsg;
 
@@ -124,12 +124,12 @@ void SetChargingPermission(byte gun_index, byte permissionStatus, short aOutputP
 	byte data[8];
 
 	data[0] = permissionStatus;
-	data[1] = aOutputPw & 0xff;
-	data[2] = (aOutputPw >> 8) & 0xff;
-	data[3] = aOutputCur & 0xff;
-	data[4] = (aOutputCur >> 8) & 0xff;
-	data[5] = aOutputVol & 0xff;
-	data[6] = (aOutputVol >> 8) & 0xff;
+	data[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));

+ 15 - 0
EVSE/Projects/DS60-120/Apps/FactoryConfig.c

@@ -98,6 +98,15 @@ int runShellCmd(const char*cmd)
 	return result;
 }
 
+void CustomChange(char *custom)
+{
+	if (strcmp(custom, "C0") == EQUAL)
+	{
+		SysConfig.AuthorisationMode = AUTH_MODE_DISABLE;
+		SysConfig.isRFID = 0;
+	}
+}
+
 /**************************************************************************************/
 /************This task will create Factory default confgiuration file *****************/
  /***********and store it into mtdblock 10,11,12                               ****************/
@@ -215,6 +224,12 @@ int main(int argc,char *argv[])
 	strcpy((char *) SysConfig.ChargeBoxId, "");
 	SysConfig.LedInfo.Intensity = 2;
 
+	// ********** «È»s¤Æ ********** //
+	char _buf[3] = {0};
+	memcpy(_buf, &SysConfig.ModelName[12], 2);
+
+	CustomChange(_buf);
+
 	//copy default configuration to pointer
 	memcpy(ptr,&SysConfig,sizeof(struct SysConfigData));
 

+ 11 - 10
EVSE/Projects/DS60-120/Apps/Makefile

@@ -19,59 +19,60 @@ 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) -o main main.o timeout.o ${Lib_Module_RFID} ${Lib_Module_Upgrade} ${Lib_SQLite3}	
+	$(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) -o Module_EvComm Ev_Comm.o Module_EvComm.o
+	$(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) -o Module_EventLogging Module_EventLogging.o ${Lib_SQLite3}	
+	$(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) -o Module_InternalComm Module_InternalComm.o internalComm.o 	
+	$(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) -o Module_LcmControl Module_LcmControl.o
+	$(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) -o Module_PrimaryComm Module_PrimaryComm.o PrimaryComm.o
+	$(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) -o Module_PsuComm Module_PsuComm.o ../../../Modularization/libInfypwr_PsuCommObj.a
+	$(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) -o ReadCmdline ReadCmdline.o
+	$(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) -o UnsafetyOutputTask OutputTask.o ../../../Modularization/libInfypwr_PsuCommObj.a
+	$(CC) -lrt -o UnsafetyOutputTask OutputTask.o ../../../Modularization/libInfypwr_PsuCommObj.a
 	cp -f UnsafetyOutputTask ../Images/root	
 
 FactoryConfigApp:
@@ -83,7 +84,7 @@ FactoryConfigApp:
 	cp /mnt/FactoryDefaultConfig.bin ../Images
 	rm -f FactoryConfig; 
 	$(CC) -D $(Project) -O0 -g3 -Wall -c -fmessage-length=0 -o FactoryConfig.o FactoryConfig.c 
-	$(CC) -o FactoryConfig FactoryConfig.o 
+	$(CC) -lrt -o FactoryConfig FactoryConfig.o 
 	cp -f FactoryConfig ../Images/root
 
 OtherTools:

+ 202 - 115
EVSE/Projects/DS60-120/Apps/Module_EvComm.c

@@ -32,9 +32,10 @@
 #define ARRAY_SIZE(A)		(sizeof(A) / sizeof(A[0]))
 #define PASS				1
 #define FAIL				-1
-#define START				1
 #define STOP				0
+#define START				1
 #define COMMUNICATION		2
+#define INITIALIZATION		3
 #define YES					1
 #define NO					0
 #define EQUAL				0
@@ -43,7 +44,7 @@
 #define PLUG				1
 #define UNPLUG				0
 #define UNDEFINED_TEMP		255
-#define ALLOW_COUNT_MAX		10
+#define ALLOW_COUNT_MAX		30
 
 struct SysConfigAndInfo			*ShmSysConfigAndInfo;
 struct StatusCodeData 			*ShmStatusCodeData;
@@ -78,15 +79,17 @@ float maxChargingPow = 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 timeval _chk_ratingPower_timeout[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
-struct timeval _chk_chademo_permission_timeout[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};
 
 unsigned char mask_table[] = { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 };
@@ -95,18 +98,23 @@ void PRINTF_FUNC(char *string, ...);
 
 void GetMaxVolAndCurMethod(byte index, float *vol, float *cur);
 void GetMaxPowerMethod(byte index, float *pow);
-unsigned long GetTimeoutValue(struct timeval _sour_time);
+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)
 
-unsigned long GetTimeoutValue(struct timeval _sour_time)
+int GetTimeoutValue(struct timespec *startTime)
 {
-	struct timeval _end_time;
-	gettimeofday(&_end_time, NULL);
+	struct timespec endTime;
+
+	clock_gettime(CLOCK_MONOTONIC_COARSE, &endTime);
+	return endTime.tv_sec - startTime->tv_sec;
+}
 
-	return 1000000 * (_end_time.tv_sec - _sour_time.tv_sec) + _end_time.tv_usec - _sour_time.tv_usec;
+void GetTimespecFunc(struct timespec *time)
+{
+	clock_gettime(CLOCK_MONOTONIC_COARSE, time);
 }
 
 int StoreLogMsg(const char *fmt, ...)
@@ -2770,7 +2778,6 @@ void CANReceiver()
 
 		// 槍資訊
 		struct ChargingInfoData *_chargingData[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
-		struct timeval _cmd_ack_timeout[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
 
 		bool isPass = false;
 		gun_count = ShmSysConfigAndInfo->SysConfig.TotalConnectorCount;
@@ -2791,23 +2798,11 @@ void CANReceiver()
 			sleep(1);
 		}
 
-		for (byte _index = 0; _index < gun_count; _index++)
-			gettimeofday(&_cmd_ack_timeout[_index], NULL);
-
 		while (1)
 		{
 			memset(&frame, 0, sizeof(struct can_frame));
 			nbytes = read(CanFd, &frame, sizeof(struct can_frame));
 
-//			for (byte _index = 0; _index < gun_count; _index++)
-//			{
-//				if (GetTimeoutValue(_cmd_ack_timeout[_index]) >= 5000000)
-//				{
-//					// ACK timeout
-//					//PRINTF_FUNC("gun = %x, ack timeout \n", _index);
-//				}
-//			}
-
 			if (nbytes > 0)
 			{
 				byte target;
@@ -2866,7 +2861,6 @@ void CANReceiver()
 
 				if(intCmd == 256) { continue; }
 
-				gettimeofday(&_cmd_ack_timeout[targetGun], NULL);
 				switch (intCmd)
 				{
 					case EV_Command_EvStatusNotification:
@@ -2940,16 +2934,16 @@ void CANReceiver()
 						break;
 					case EV_Command_GetOutputReq:
 					{
-						if ((_chargingData[targetGun]->SystemStatus >= S_PREPARING_FOR_EV &&
-								_chargingData[targetGun]->SystemStatus <= S_CHARGING) ||
-								(_chargingData[targetGun]->SystemStatus >= S_CCS_PRECHARGE_ST0 &&
-								_chargingData[targetGun]->SystemStatus <= S_CCS_PRECHARGE_ST1))
+						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 == S_CHARGING)
+									_chargingData[targetGun]->SystemStatus == SYS_MODE_CHARGING)
 								_chargingData[targetGun]->EvBatterySoc = frame.data[1];
 						}
 
@@ -3096,10 +3090,10 @@ void CANReceiver()
 					case EV_Command_EvStopNotification:
 					{
 						// 車端要求停止
-						if ((_chargingData[targetGun]->SystemStatus >= S_REASSIGN_CHECK &&
-								_chargingData[targetGun]->SystemStatus <= S_TERMINATING) ||
-								(_chargingData[targetGun]->SystemStatus >= S_CCS_PRECHARGE_ST0 &&
-								_chargingData[targetGun]->SystemStatus <= S_CCS_PRECHARGE_ST1))
+						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)
@@ -3168,10 +3162,20 @@ void SetPresentChargingOutputPower(struct ChargingInfoData *chargingData_1, stru
 	cur1 = (chargingData_1->PresentChargingCurrent * 10);
 
 	float targetCur = chargingData_1->EvBatterytargetCurrent * 10;
-	if (curAllowCount[0] < ALLOW_COUNT_MAX)
+	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;
 	}
@@ -3200,10 +3204,20 @@ void SetPresentChargingOutputPower(struct ChargingInfoData *chargingData_1, stru
 	}
 
 	targetCur = chargingData_2->EvBatterytargetCurrent * 10;
-	if (curAllowCount[1] < ALLOW_COUNT_MAX)
+	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;
 	}
@@ -3243,7 +3257,7 @@ void SetPresentChargingOutputCap(struct ChargingInfoData *chargingData_1, struct
 		cur1 = 0;
 	else
 	{
-		if (chargingData_1->SystemStatus == S_CHARGING &&
+		if (chargingData_1->SystemStatus == SYS_MODE_CHARGING &&
 				chargingData_1->FireChargingVoltage > 1500)
 		{
 			float maxCur = 0;
@@ -3267,7 +3281,7 @@ void SetPresentChargingOutputCap(struct ChargingInfoData *chargingData_1, struct
 		cur2 = 0;
 	else
 	{
-		if (chargingData_2->SystemStatus == S_CHARGING &&
+		if (chargingData_2->SystemStatus == SYS_MODE_CHARGING &&
 				chargingData_2->FireChargingVoltage > 1500)
 		{
 			float maxCur = 0;
@@ -3337,8 +3351,8 @@ void GetMaxVolAndCurMethod(byte index, float *vol, float *cur)
 			_chargingData[index]->ConnectorMaxCurrent <= *cur)
 		*cur = _chargingData[index]->ConnectorMaxCurrent;
 
-	if (((_chargingData[index]->SystemStatus >= S_PREPARING_FOR_EVSE && _chargingData[index]->SystemStatus <= S_CHARGING) ||
-			(_chargingData[index]->SystemStatus >= S_CCS_PRECHARGE_ST0 && _chargingData[index]->SystemStatus <= S_CCS_PRECHARGE_ST1)) &&
+	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)
 	{
@@ -3351,8 +3365,8 @@ void GetMaxPowerMethod(byte index, float *pow)
 	if (maxChargingPow != 0 && maxChargingPow <= *pow)
 		*pow = maxChargingPow;
 
-	if (((_chargingData[index]->SystemStatus >= S_PREPARING_FOR_EVSE && _chargingData[index]->SystemStatus <= S_CHARGING) ||
-			(_chargingData[index]->SystemStatus >= S_CCS_PRECHARGE_ST0 && _chargingData[index]->SystemStatus <= S_CCS_PRECHARGE_ST1)) &&
+	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 / 1000) >= 0 &&
 			(_chargingData[index]->ChargingProfilePower / 1000) <= *pow)
 	{
@@ -3546,6 +3560,15 @@ void SendStopOnly(byte index)
 		targetID);
 }
 
+void InitialConnectorStatus(byte index)
+{
+	SetChargingPermission(index, INITIALIZATION,
+		0,
+		0,
+		0,
+		_chargingData[index]->Evboard_id);
+}
+
 void FormatVoltageAndCurrent()
 {
 	char isLowCur = 0x00;
@@ -3674,7 +3697,9 @@ void CalOutputPowerAndEnergy(int _index)
 
 		if (ShmSysConfigAndInfo->SysConfig.BillingData.isBilling)
 		{
-			_chargingData[_index]->ChargingFee = totalChargingValue * ShmSysConfigAndInfo->SysConfig.BillingData.Cur_fee;
+			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')
@@ -3687,7 +3712,7 @@ void CalOutputPowerAndEnergy(int _index)
 			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 / 100;
+				float totalChargingValue = ShmCsuMeterData->_meter[_index]._curTotalCharging;
 
 				if (totalChargingValue > _chargingData[_index]->PresentChargedEnergy)
 				{
@@ -3699,7 +3724,9 @@ void CalOutputPowerAndEnergy(int _index)
 
 				if (ShmSysConfigAndInfo->SysConfig.BillingData.isBilling)
 				{
-					_chargingData[_index]->ChargingFee = totalChargingValue * ShmSysConfigAndInfo->SysConfig.BillingData.Cur_fee;
+					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;
@@ -3723,7 +3750,10 @@ void CalOutputPowerAndEnergy(int _index)
 				if (ShmSysConfigAndInfo->SysConfig.BillingData.isBilling)
 				{
 					ShmDcCommonData->energy_time_period[_index][ShmDcCommonData->_hour_index] += changingPow;
-					_chargingData[_index]->ChargingFee += changingPow * ShmSysConfigAndInfo->SysConfig.BillingData.Cur_fee;
+
+					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;
@@ -3734,6 +3764,72 @@ void CalOutputPowerAndEnergy(int _index)
 	}
 }
 
+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;
+
+	if (ShmSysConfigAndInfo->SysInfo.MainChargingMode == _MAIN_CHARGING_MODE_AVER)
+	{
+		maxCurBuf /= 2; maxPowBuf /= 2;
+	}
+
+	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)
+				_chargingData[_index]->PowerOffered = ShmPsuData->PsuGroup[_index].GroupAvailablePower;
+			else
+				_chargingData[_index]->ConnectorMaxCurrent >= maxPowBuf ?
+						(_chargingData[_index]->PowerOffered = maxPowBuf) :
+						(_chargingData[_index]->PowerOffered = ShmPsuData->PsuGroup[_index].GroupAvailablePower);
+		}
+		else
+			_chargingData[_index]->PowerOffered = 0;
+}
+
 int main(int argc, char *argv[])
 {
 	if(InitShareMemory() == FAIL)
@@ -3784,7 +3880,7 @@ int main(int argc, char *argv[])
 		}
 	}
 
-	unsigned long _timeBuf = 0;
+	int _timeBuf = 0;
 
 	while(CanFd)
 	{
@@ -3802,19 +3898,29 @@ int main(int argc, char *argv[])
 			if (priorityLow == 1)
 			{
 				// 優先權較低 - 只要有回應即不會再詢問
-				if (_chargingData[_index]->Type == _Type_Chademo &&
-						ShmCHAdeMOData->evse[_chargingData[_index]->type_index].SelfTest_Comp != PASS)
+				if (_chargingData[_index]->Type == _Type_Chademo)
 				{
-					if (rtcChkCount == 0)
-						SyncRtcInfo(_index, _chargingData[_index]->Evboard_id, (int)rtc);
-					GetFirmwareVersion(_index, _chargingData[_index]->Evboard_id);
+					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 &&
-						ShmGBTData->evse[_chargingData[_index]->type_index].SelfTest_Comp != PASS)
+				else if (_chargingData[_index]->Type == _Type_GB)
 				{
-					if (rtcChkCount == 0)
-						SyncRtcInfo(_index, _chargingData[_index]->Evboard_id, (int)rtc);
-					GetFirmwareVersion(_index, _chargingData[_index]->Evboard_id);
+					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)
 				{
@@ -3842,68 +3948,48 @@ int main(int argc, char *argv[])
 						(_chargingData[_index]->PresentChargingVoltage * 10),
 						targetID);
 
-				bool isOTP = false;
+				ConnectorOTP(_index);
 
-				if (_chargingData[_index]->Type == _Type_Chademo)
-				{
-					if (ShmDcCommonData->ConnectErrList[_index].GunBits.ChaConnectOTP)
-						isOTP = true;
-					else
-						isOTP = false;
-				}
-				else if (_chargingData[_index]->Type == _Type_CCS)
-				{
-					if (ShmDcCommonData->ConnectErrList[_index].GunBits.CCSConnectOTP)
-						isOTP = true;
-					else
-						isOTP = false;
-				}
-				else if (_chargingData[_index]->Type == _Type_GB)
-				{
-					if (ShmDcCommonData->ConnectErrList[_index].GunBits.GBTConnectOTP)
-						isOTP = true;
-					else
-						isOTP = false;
-				}
-
-				if (isOTP)
-				{
-					if (gunTempAllowCount[_index] >= 2)
-						_chargingData[_index]->StopChargeFlag = YES;
-					else
-						gunTempAllowCount[_index] += 1;
-				}
-				else
-					gunTempAllowCount[_index] = 0;
+				OfferCurrentAndPowerRecord(_index);
 			}
 
 			switch (_chargingData[_index]->SystemStatus)
 			{
-				case S_IDLE:
-				case S_RESERVATION:
+				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)
+						if (ShmSysConfigAndInfo->SysInfo.PageIndex == _LCM_WAIT_FOR_PLUG ||
+								ShmDcCommonData->_cha_try_communication[_index].try2CommunicationFlag)
 						{
 							if (!chkChademoPermission[_index])
 							{
 								chkChademoPermission[_index] = true;
-								gettimeofday(&_chk_chademo_permission_timeout[_index], NULL);
-								SendCommunicationOnly(_index);
+								GetTimespecFunc(&_chk_chademo_permission_timeout[_index]);
+								SendStopOnly(_index);
+								chkChademoPermissionSend[_index] = NO;
 							}
 							else
 							{
-								_timeBuf = GetTimeoutValue(_chk_chademo_permission_timeout[_index]);
+								_timeBuf = GetTimeoutValue(&_chk_chademo_permission_timeout[_index]);
 
 								if (_timeBuf < 0)
-									gettimeofday(&_chk_chademo_permission_timeout[_index], NULL);
+									GetTimespecFunc(&_chk_chademo_permission_timeout[_index]);
 								else
 								{
-									if (_timeBuf / 1000 > 10000)
+									if (_timeBuf > 2)
 									{
-										SendCommunicationOnly(_index);
-										gettimeofday(&_chk_chademo_permission_timeout[_index], NULL);
+										if (chkChademoPermissionSend[_index] == NO)
+										{
+											chkChademoPermissionSend[_index] = YES;
+											SendCommunicationOnly(_index);
+										}
+										if (_timeBuf > 10)
+										{
+											chkChademoPermissionSend[_index] = NO;
+											GetTimespecFunc(&_chk_chademo_permission_timeout[_index]);
+										}
 									}
 								}
 							}
@@ -3911,7 +3997,7 @@ int main(int argc, char *argv[])
 						else if (chkChademoPermission[_index])
 						{
 							chkChademoPermission[_index] = false;
-							SendStopOnly(_index);
+							//SendStopOnly(_index);
 						}
 
 						if (ShmDcCommonData->ConnectErrList[_index].GunBits.ChaConnectOTP == NO)
@@ -3947,6 +4033,7 @@ int main(int argc, char *argv[])
 						_chargingData[_index]->ChargingProfilePower = -1;
 						_chargingData[_index]->ChargingProfileCurrent = -1;
 						curAllowCount[_index] = 0;
+						curTargetCur[_index] = 0;
 
 						if (ShmSysConfigAndInfo->SysInfo.MainChargingMode == _MAIN_CHARGING_MODE_MAX)
 						{
@@ -3993,7 +4080,7 @@ int main(int argc, char *argv[])
 							SetPresentChargingOutputPower(_chargingData[0], _chargingData[1]);
 					}
 					break;
-				case S_PREPARNING:
+				case SYS_MODE_PREPARING:
 				{
 					chkChademoPermission[_index] = false;
 					// 設定當前輸出
@@ -4003,7 +4090,7 @@ int main(int argc, char *argv[])
 						SetPresentChargingOutputPower(_chargingData[0], _chargingData[1]);
 				}
 					break;
-				case S_PREPARING_FOR_EV:
+				case SYS_MODE_PREPARE_FOR_EV:
 				{
 					if (ShmDcCommonData->startTransactionFlag[_index] == START_TRANSATION_STATUS_WAIT)
 						continue;
@@ -4050,12 +4137,12 @@ int main(int argc, char *argv[])
 						// 取得車端電池資訊 : 1.AC or DC ? 2.Total battery cap, 3.Max battery vol, 4.Max battery cur
 						GetEvBatteryInfo(_index, targetID);
 					}
-					gettimeofday(&_chk_ratingPower_timeout[_index], NULL);
+					GetTimespecFunc(&_chk_ratingPower_timeout[_index]);
 				}
 					break;
-				case S_PREPARING_FOR_EVSE:
-				case S_CCS_PRECHARGE_ST0:
-				case S_CCS_PRECHARGE_ST1:
+				case SYS_MODE_PREPARE_FOR_EVSE:
+				case SYS_MODE_CCS_PRECHARGE_STEP0:
+				case SYS_MODE_CCS_PRECHARGE_STEP1:
 				{
 					// 開始確認車端是否同意開始充電
 					GetOutputReq(_index, targetID);
@@ -4118,16 +4205,16 @@ int main(int argc, char *argv[])
 
 							if (_result == GFD_WARNING || _result == GFD_PASS)
 							{
-								_timeBuf = GetTimeoutValue(_chk_ratingPower_timeout[_index]);
+								_timeBuf = GetTimeoutValue(&_chk_ratingPower_timeout[_index]);
 								if (_timeBuf < 0)
 								{
-									gettimeofday(&_chk_ratingPower_timeout[_index], NULL);
+									GetTimespecFunc(&_chk_ratingPower_timeout[_index]);
 								}
 								else
 								{
-									if (((_timeBuf / 1000) > 12000 &&
+									if ((_timeBuf > 12 &&
 											_chargingData[_index]->RealRatingPower > 0) ||
-											(_timeBuf / 1000) > 14000)
+											_timeBuf > 14)
 									{
 										if (LogInfo[_index][EV_LOG_REAL_CAP_POW] != _chargingData[_index]->RealRatingPower)
 										{
@@ -4144,7 +4231,7 @@ int main(int argc, char *argv[])
 							SetIsolationStatus(_index, _result, targetID);
 						}
 
-						if(_chargingData[_index]->SystemStatus == S_CCS_PRECHARGE_ST0 &&
+						if(_chargingData[_index]->SystemStatus == SYS_MODE_CCS_PRECHARGE_STEP0 &&
 							_chargingData[_index]->PrechargeStatus == PRECHARGE_READY)
 						{
 							SetEvsePrechargeInfo(_index, PRECHARGE_PRERELAY_PASS, targetID);
@@ -4152,7 +4239,7 @@ int main(int argc, char *argv[])
 					}
 				}
 					break;
-				case S_CHARGING:
+				case SYS_MODE_CHARGING:
 				{
 					// 當前 Power
 					_chargingData[_index]->PresentChargingPower = ((float)((_chargingData[_index]->PresentChargingVoltage) * (_chargingData[_index]->PresentChargingCurrent)) / 1000);
@@ -4190,13 +4277,13 @@ int main(int argc, char *argv[])
 							SetPresentChargingOutputCap(_chargingData[0], _chargingData[1]);
 					}
 
+					// GFD 失敗再通知
 					if(_chargingData[_index]->GroundFaultStatus == GFD_FAIL ||
 							_chargingData[_index]->Type == _Type_CCS)
 					{
 						SetIsolationStatus(_index, _chargingData[_index]->GroundFaultStatus, targetID);
 					}
 
-					// GFD 失敗再通知
 					if (priorityLow == 1)
 					{
 						if(_chargingData[_index]->Type == _Type_CCS &&
@@ -4210,8 +4297,8 @@ int main(int argc, char *argv[])
 					}
 				}
 					break;
-				case S_ALARM:
-				case S_TERMINATING:
+				case SYS_MODE_ALARM:
+				case SYS_MODE_TERMINATING:
 				{
 					// 當前 Power
 					_chargingData[_index]->PresentChargingPower = ((float)((_chargingData[_index]->PresentChargingVoltage) * (_chargingData[_index]->PresentChargingCurrent)) / 1000);
@@ -4267,7 +4354,7 @@ int main(int argc, char *argv[])
 
 					GetOutputReq(_index, targetID);
 
-					if (_chargingData[_index]->SystemStatus == S_ALARM)
+					if (_chargingData[_index]->SystemStatus == SYS_MODE_ALARM)
 					{
 						if (priorityLow == 1)
 						{
@@ -4287,7 +4374,7 @@ int main(int argc, char *argv[])
 					}
 				}
 					break;
-				case S_COMPLETE:
+				case SYS_MODE_COMPLETE:
 				{
 					// 設定當前輸出
 					if (gun_count == 1)

+ 1 - 1
EVSE/Projects/DS60-120/Apps/Module_EvComm.h

@@ -65,7 +65,7 @@ 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, short aOutputPw, short aOutputVol, short aOutputCur, 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);

+ 3 - 7
EVSE/Projects/DS60-120/Apps/Module_EventLogging.c

@@ -203,12 +203,10 @@ int InitShareMemory()
     	DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
 		#endif
     	result = FAIL;
-   	 }
-    else
-    {}
+   	}
 
-   	 //creat ShmStatusCodeData
-   	 if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData),  0777)) < 0)
+   	//creat ShmStatusCodeData
+   	if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData),  0777)) < 0)
     {
 		#ifdef SystemLogMessage
    		DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
@@ -222,8 +220,6 @@ int InitShareMemory()
 		#endif
     	result = FAIL;
    	}
-    else
-    {}
 
     return result;
 }

Різницю між файлами не показано, бо вона завелика
+ 261 - 229
EVSE/Projects/DS60-120/Apps/Module_InternalComm.c


+ 152 - 34
EVSE/Projects/DS60-120/Apps/Module_LcmControl.c

@@ -778,12 +778,13 @@ void DisplayMoneyRate(float money)
 
 void DisplayMoneyCur(byte *cur)
 {
-	byte cmd[5];
-	byte buf[5];
+	byte cmd[8];
+	byte buf[8];
 
 	memset(cmd, 0x00, sizeof(cmd));
 	memcpy((char *) buf, cur, 3);
-	buf[3] = '\0';
+	memcpy((char *) buf + 3, "/kWh", 4);
+	buf[7] = '\0';
 	string2ByteArray(buf, cmd);
 	DisplayValueToLcm(__money_rate, cmd, sizeof(cmd));
 }
@@ -862,7 +863,7 @@ void RefreshConnStatus()
 	}
 
 	if((ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'T' || ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D') &&
-			ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomEnabled != NO)
+			ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomEnabled != _SYS_4G_MODE_DISABLE)
 	{
 		if (ShmSysConfigAndInfo->SysConfig.AthInterface.WifiMode == _SYS_WIFI_MODE_DISABLE)
 		{
@@ -1335,7 +1336,7 @@ void ProcessPageInfo()
 			bool isCharging = false;
 			for(byte i = 0; i < _totalCount; i++)
 			{
-				if (_chargingInfoData[i]->SystemStatus == S_IDLE)
+				if (_chargingInfoData[i]->SystemStatus == SYS_MODE_IDLE)
 					continue;
 
 				isCharging = true;
@@ -1365,9 +1366,9 @@ void ProcessPageInfo()
 			bool isCharging = false;
 			for(byte i = 0; i < _totalCount; i++)
 			{
-				if (_chargingInfoData[i]->SystemStatus == S_IDLE ||
-						_chargingInfoData[i]->SystemStatus == S_MAINTAIN ||
-						_chargingInfoData[i]->SystemStatus == S_RESERVATION)
+				if (_chargingInfoData[i]->SystemStatus == SYS_MODE_IDLE ||
+						_chargingInfoData[i]->SystemStatus == SYS_MODE_MAINTAIN ||
+						_chargingInfoData[i]->SystemStatus == SYS_MODE_RESERVATION)
 					continue;
 
 				isCharging = true;
@@ -1454,8 +1455,10 @@ void ProcessPageInfo()
 						else
 							ChangeChargingPowerValue(0);
 
-						if (ac_chargingInfo[0]->PresentChargedEnergy >= 0.1 &&
-								ac_chargingInfo[0]->PresentChargedEnergy <= ENERGY_MAX_KWH)
+						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);
 
@@ -1621,8 +1624,10 @@ void ProcessPageInfo()
 						else
 							ChangeChargingPowerValue(0);
 
-						if (_chargingInfoData[i]->PresentChargedEnergy >= 0.1 &&
-								_chargingInfoData[i]->PresentChargedEnergy <= ENERGY_MAX_KWH)
+						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);
 
@@ -1674,9 +1679,9 @@ void ProcessPageInfo()
 					}
 				}
 
-				if (_chargingInfoData[index]->SystemStatus == S_IDLE ||
-						_chargingInfoData[index]->SystemStatus == S_RESERVATION ||
-						_chargingInfoData[index]->SystemStatus == S_BOOTING)
+				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)
 					{
@@ -1702,35 +1707,120 @@ void ProcessPageInfo()
 	}
 }
 
-void ChangeDisplayMoneyInfo()
+void ChangeDisplayMoneyInfoWithoutBackend()
 {
-	if (ShmSysConfigAndInfo->SysConfig.BillingData.isBilling)
+	struct timeb csuTime;
+	struct tm *tmCSU;
+
+	ftime(&csuTime);
+	tmCSU = localtime(&csuTime.time);
+
+	ChangeDisplay2Value(__money_rate_map, _charging_money);
+
+	if (tmCSU->tm_hour <= 23)
 	{
-		struct timeb csuTime;
-		struct tm *tmCSU;
+		ShmDcCommonData->_hour_index = tmCSU->tm_hour;
+		ShmSysConfigAndInfo->SysConfig.BillingData.Cur_fee = ShmSysConfigAndInfo->SysConfig.BillingData.Fee[tmCSU->tm_hour];
+		DisplayMoneyRate(ShmSysConfigAndInfo->SysConfig.BillingData.Cur_fee);
+	}
 
-		ftime(&csuTime);
-		tmCSU = localtime(&csuTime.time);
+	if (ShmSysConfigAndInfo->SysConfig.BillingData.Currency <= 53)
+	{
+		DisplayMoneyCur((byte *)Currency[ShmSysConfigAndInfo->SysConfig.BillingData.Currency]);
+	}
+}
 
-		ChangeDisplay2Value(__money_rate_map, _charging_money);
+void ChangeDisplayMoneyInfo()
+{
+	struct timeb csuTime;
+	struct tm *tmCSU;
 
-		if (tmCSU->tm_hour <= 23)
+	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)
 		{
-			ShmDcCommonData->_hour_index = tmCSU->tm_hour;
-			ShmSysConfigAndInfo->SysConfig.BillingData.Cur_fee = ShmSysConfigAndInfo->SysConfig.BillingData.Fee[tmCSU->tm_hour];
-			DisplayMoneyRate(ShmSysConfigAndInfo->SysConfig.BillingData.Cur_fee);
+			ShmSysConfigAndInfo->SysConfig.BillingData.Cur_fee = (float)ShmDcCommonData->balanceInfo.defaultPrice / 100;
 		}
-
-		if (ShmSysConfigAndInfo->SysConfig.BillingData.Currency <= 53)
+		else
 		{
-			DisplayMoneyCur((byte *)Currency[ShmSysConfigAndInfo->SysConfig.BillingData.Currency]);
+			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
 	{
-		ChangeDisplay2Value(__money_rate_map, _disappear);
-		ChangeDisplay2Value(__money_by_rate, _disappear);
-		ChangeDisplay2Value(__money_rate, _disappear);
+		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]);
 	}
 }
 
@@ -1794,12 +1884,24 @@ void DefaultIconStatus()
 	{
 		ChangeDisplay2Value(__logo, _logo);
 		ChangeDisplay2Value(__logo_cmp, _logo_cmp);
-		ChangeDisplay2Value(__phihong_string, _phihong_string_map);
 	}
 	else
 	{
 		ChangeDisplay2Value(__logo, _disappear);
 		ChangeDisplay2Value(__logo_cmp, _disappear);
+	}
+
+	char _buf[3] = {0};
+	memcpy(_buf, &ShmSysConfigAndInfo->SysConfig.ModelName[12], 2);
+
+	// N0 : ©Ý³s
+	if (ShmDcCommonData->ShowLogoFlag &&
+			strcmp(_buf, "N0") != EQUAL)
+	{
+		ChangeDisplay2Value(__phihong_string, _phihong_string_map);
+	}
+	else
+	{
 		ChangeDisplay2Value(__phihong_string, _disappear);
 	}
 }
@@ -1887,7 +1989,23 @@ int main(void)
 
 			if (changeWarningPriority == 0)
 			{
-				ChangeDisplayMoneyInfo();
+				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();
 			}
 

+ 22 - 14
EVSE/Projects/DS60-120/Apps/Module_PrimaryComm.c

@@ -55,7 +55,7 @@ Ver ver;
 Gpio_in gpio_in;
 Rtc rtc;
 
-struct timeval _flash_time;
+struct timespec _flash_time;
 byte flash = NO;
 
 byte gun_count;
@@ -217,10 +217,10 @@ int InitShareMemory()
     	DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
 		#endif
     	result = FAIL;
-   	 }
+   	}
 
-   	 //creat ShmStatusCodeData
-   	 if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData),  0777)) < 0)
+   	//creat ShmStatusCodeData
+   	if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData),  0777)) < 0)
     {
 		#ifdef SystemLogMessage
    		DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
@@ -403,7 +403,7 @@ void GetMeterConsumption(byte index)
 				{
 					for (byte subIndex = 0; subIndex < gun_count; subIndex++)
 					{
-						if (_chargingData[subIndex]->SystemStatus == S_CHARGING)
+						if (_chargingData[subIndex]->SystemStatus == SYS_MODE_CHARGING)
 						{
 							ShmCsuMeterData->_meter[subIndex]._curTotalCharging += ShmCsuMeterData->_meter[index].newMeterValue - ShmCsuMeterData->_meter[index].curMeterValue;
 							break;
@@ -424,8 +424,11 @@ void GetMeterConsumption(byte index)
 void SetOutputGpio(byte flash)
 {
 	Gpio_out gpio;
+	// ÂÅ¿O
 	gpio.Button_LED[0] = flash;
+	// ºñ¿O
 	gpio.Button_LED[1] = flash;
+	//gpio.Button_LED[1] = 0x00;
 
 	gpio.System_LED[0] = 0x00;
 	gpio.System_LED[1] = 0x00;
@@ -522,12 +525,17 @@ int InitComPort()
 	return fd;
 }
 
-unsigned long GetTimeoutValue(struct timeval _sour_time)
+int GetTimeoutValue(struct timespec *startTime)
 {
-	struct timeval _end_time;
-	gettimeofday(&_end_time, NULL);
+	struct timespec endTime;
+
+	clock_gettime(CLOCK_MONOTONIC_COARSE, &endTime);
+	return endTime.tv_sec - startTime->tv_sec;
+}
 
-	return 1000000 * (_end_time.tv_sec - _sour_time.tv_sec) + _end_time.tv_usec - _sour_time.tv_usec;
+void GetTimespecFunc(struct timespec *time)
+{
+	clock_gettime(CLOCK_MONOTONIC_COARSE, time);
 }
 
 //================================================
@@ -618,7 +626,7 @@ int main(void)
 
 	SetRtcData();
 	SetModelName();
-	gettimeofday(&_flash_time, NULL);
+	GetTimespecFunc(&_flash_time);
 	gun_count = ShmSysConfigAndInfo->SysConfig.TotalConnectorCount;
 	Initialization();
 	byte _count = 0;
@@ -627,25 +635,25 @@ int main(void)
 	{
 		if (strcmp((char *)ShmSysConfigAndInfo->SysInfo.LcmHwRev, " ") == EQUAL)
 		{
-			if ((GetTimeoutValue(_flash_time) / 1000) > 1000)
+			if (GetTimeoutValue(&_flash_time) > 1)
 			{
 				if (flash == NO)
 					flash = YES;
 				else
 					flash = NO;
 				SetOutputGpio(flash);
-				gettimeofday(&_flash_time, NULL);
+				GetTimespecFunc(&_flash_time);
 			}
 		}
 		else
 		{
-			if ((GetTimeoutValue(_flash_time) / 1000) > 5000)
+			if (GetTimeoutValue(&_flash_time) > 5)
 			{
 				if (flash == NO)
 					flash = YES;
 
 				SetOutputGpio(flash);
-				gettimeofday(&_flash_time, NULL);
+				GetTimespecFunc(&_flash_time);
 			}
 		}
 

+ 204 - 219
EVSE/Projects/DS60-120/Apps/Module_PsuComm.c

@@ -46,14 +46,32 @@ int StoreLogMsg(const char *fmt, ...);
 #define DEBUG_WARN(format, args...) StoreLogMsg("[%s:%d][%s][Warn] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
 #define DEBUG_ERROR(format, args...) StoreLogMsg("[%s:%d][%s][Error] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
 
-unsigned long GetTimeoutValue(struct timeval _sour_time);
+int GetTimeoutValue(struct timespec *startTime);
 
-unsigned long GetTimeoutValue(struct timeval _sour_time)
+long int GetTimeoutMValue(struct timespec *startTime)
 {
-	struct timeval _end_time;
-	gettimeofday(&_end_time, NULL);
+	struct timespec endTime;
 
-	return 1000000 * (_end_time.tv_sec - _sour_time.tv_sec) + _end_time.tv_usec - _sour_time.tv_usec;
+	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, ...)
@@ -121,10 +139,10 @@ byte FindTargetGroup(byte address)
 		_group = 0;
 	else
 	{
-		_group = FindIndex(connector_1, ShmPsuData->PsuGroup[0].GroupPresentPsuQuantity, address, 0);
+		_group = FindIndex(ShmDcCommonData->connector[0], ShmPsuData->PsuGroup[0].GroupPresentPsuQuantity, address, 0);
 
 		if (_group == ELEMENT_NOT_FIND)
-			_group = FindIndex(connector_2, ShmPsuData->PsuGroup[1].GroupPresentPsuQuantity, address, 1);
+			_group = FindIndex(ShmDcCommonData->connector[1], ShmPsuData->PsuGroup[1].GroupPresentPsuQuantity, address, 1);
 	}
 
 	return _group;
@@ -322,13 +340,13 @@ void GetStatusCallback(byte group, byte SN, byte temp, int alarm)
 {
 	bool isFind = false;
 
-	if ((conn_1_count + conn_2_count) != ShmPsuData->SystemPresentPsuQuantity)
+	if ((ShmDcCommonData->conn_1_count + ShmDcCommonData->conn_2_count) != ShmPsuData->SystemPresentPsuQuantity)
 	{
 		if (group == 0)
 		{
-			for(byte psuIndex = 0; psuIndex < conn_1_count; psuIndex++)
+			for(byte psuIndex = 0; psuIndex < ShmDcCommonData->conn_1_count; psuIndex++)
 			{
-				if (connector_1[psuIndex] == SN)
+				if (ShmDcCommonData->connector[0][psuIndex] == SN)
 				{
 					isFind = true;
 					break;
@@ -337,15 +355,15 @@ void GetStatusCallback(byte group, byte SN, byte temp, int alarm)
 
 			if(!isFind)
 			{
-				connector_1[conn_1_count] = SN;
-				conn_1_count++;
+				ShmDcCommonData->connector[0][ShmDcCommonData->conn_1_count] = SN;
+				ShmDcCommonData->conn_1_count++;
 			}
 		}
 		else if (group == 1)
 		{
-			for(byte psuIndex = 0; psuIndex < conn_2_count; psuIndex++)
+			for(byte psuIndex = 0; psuIndex < ShmDcCommonData->conn_2_count; psuIndex++)
 			{
-				if (connector_2[psuIndex] == SN)
+				if (ShmDcCommonData->connector[1][psuIndex] == SN)
 				{
 					isFind = true;
 					break;
@@ -354,30 +372,30 @@ void GetStatusCallback(byte group, byte SN, byte temp, int alarm)
 
 			if(!isFind)
 			{
-				connector_2[conn_2_count] = SN;
-				conn_2_count++;
+				ShmDcCommonData->connector[1][ShmDcCommonData->conn_2_count] = SN;
+				ShmDcCommonData->conn_2_count++;
 			}
 		}
 	}
 
-	if ((conn_1_count + conn_2_count) == ShmPsuData->SystemPresentPsuQuantity)
+	if ((ShmDcCommonData->conn_1_count + ShmDcCommonData->conn_2_count) == ShmPsuData->SystemPresentPsuQuantity)
 	{
 		// Arrangment
-		for(byte psuIndex = 0; psuIndex < conn_1_count; psuIndex++)
+		for(byte psuIndex = 0; psuIndex < ShmDcCommonData->conn_1_count; psuIndex++)
 		{
-			connector_1[psuIndex] = psuIndex;
+			ShmDcCommonData->connector[0][psuIndex] = psuIndex;
 		}
 
-		for(byte psuIndex = 0; psuIndex < conn_2_count; psuIndex++)
+		for(byte psuIndex = 0; psuIndex < ShmDcCommonData->conn_2_count; psuIndex++)
 		{
-			connector_2[psuIndex] = conn_1_count + psuIndex;
+			ShmDcCommonData->connector[1][psuIndex] = ShmDcCommonData->conn_1_count + psuIndex;
 		}
 
-		for(byte psuIndex = 0; psuIndex < conn_1_count; psuIndex++)
-			PRINTF_FUNC("DC Left Gun - PSU Number = %d \n", connector_1[psuIndex]);
+		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 < conn_2_count; psuIndex++)
-			PRINTF_FUNC("DC Right Gun - PSU Number = %d \n", connector_2[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)
@@ -400,8 +418,8 @@ void GetStatusCallback(byte group, byte SN, byte temp, int alarm)
 
 			maxCount = ((power / 30) + 1) / 2;
 
-			if (conn_1_count > maxCount ||
-					conn_2_count > maxCount)
+			if (ShmDcCommonData->conn_1_count > maxCount ||
+					ShmDcCommonData->conn_2_count > maxCount)
 			{
 				ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuDipSwitchStestFail = YES;
 			}
@@ -447,6 +465,10 @@ void GetMaxPowerAndCur(unsigned char mode, int ratingCur, int *pow, int *cur)
 		maxPower /= 2;
 	}
 
+	if (ShmSysConfigAndInfo->SysInfo.MaxChargingProfilePower >= 0 &&
+			maxPower > ShmSysConfigAndInfo->SysInfo.MaxChargingProfilePower)
+		maxPower = ShmSysConfigAndInfo->SysInfo.MaxChargingProfilePower;
+
 	if (maxPower != 0 && maxPower <= *pow)
 		*pow = maxPower;
 
@@ -759,8 +781,8 @@ void GetPresentOutputCallback(byte group, unsigned short outVol, unsigned short
 //			}
 //		}
 //
-//		if ((chargingInfo[group]->SystemStatus >= S_PREPARING_FOR_EVSE && chargingInfo[group]->SystemStatus <= S_COMPLETE) ||
-//			(chargingInfo[group]->SystemStatus >= S_CCS_PRECHARGE_ST0 && chargingInfo[group]->SystemStatus <= S_CCS_PRECHARGE_ST1))
+//		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;
@@ -965,9 +987,9 @@ void GetPresentOutputFCallback(byte group, float outVol, float outCur)
 				}
 			}
 
-			if ((chargingInfo[group]->SystemStatus >= S_PREPARING_FOR_EVSE && chargingInfo[group]->SystemStatus <= S_COMPLETE) ||
-					(chargingInfo[group]->SystemStatus >= S_CCS_PRECHARGE_ST0 && chargingInfo[group]->SystemStatus <= S_CCS_PRECHARGE_ST1) ||
-					chargingInfo[group]->SystemStatus == S_ALARM)
+			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;
@@ -1003,9 +1025,6 @@ void GetOutputAndTempCallback(byte address, unsigned short outputVol_s,
 	if (ShmPsuData->Work_Step < GET_SYS_CAP)
 		return;
 
-	//unsigned short outVol = outputVol_s;
-	//unsigned short outCur = outputCur_s;
-
 	if (IsOverModuleCount(address))
 		return;
 
@@ -1014,98 +1033,6 @@ void GetOutputAndTempCallback(byte address, unsigned short outputVol_s,
 	if (group == 1)
 		address -= ShmPsuData->PsuGroup[group - 1].GroupPresentPsuQuantity;
 
-//	// PSU Group - 電壓
-//	ShmPsuData->PsuGroup[group].GroupPresentOutputVoltage = outVol;
-//	// PSU Group - 電流
-//	ShmPsuData->PsuGroup[group].GroupPresentOutputCurrent = outCur;
-//	// PSU Group - 能量
-//	ShmPsuData->PsuGroup[group].GroupPresentOutputPower = outVol * 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;
-//		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 >= S_PREPARING_FOR_EVSE && chargingInfo[group]->SystemStatus <= S_COMPLETE) ||
-//			(chargingInfo[group]->SystemStatus >= S_CCS_PRECHARGE_ST0 && chargingInfo[group]->SystemStatus <= S_CCS_PRECHARGE_ST1))
-//		{
-//			float _vol_buf = outputVol;
-//			float _cur_buf = outputCur;
-//
-//			// EVSE - 電壓
-//			_vol_buf /= 10;
-//			chargingInfo[group]->PresentChargingVoltage = _vol_buf;
-//
-//			_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;
-//	}
-
 	ShmPsuData->PsuGroup[group].PsuModule[address].CriticalTemp1 = Temperature;
 	ShmPsuData->PsuGroup[group].PsuModule[address].CriticalTemp2 = Temperature;
 	ShmPsuData->PsuGroup[group].PsuModule[address].CriticalTemp3 = Temperature;
@@ -1119,6 +1046,13 @@ void GetModuleStatusCallback(byte address, unsigned char isErr, unsigned char st
 		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;
@@ -1192,9 +1126,7 @@ int InitShareMemory()
     	DEBUG_ERROR("shmat ShmSysConfigAndInfo NG \n");
 		#endif
     	result = FAIL;
-   	 }
-    else
-    {}
+   	}
 
    	//creat ShmStatusCodeData
    	if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData),  0777)) < 0)
@@ -1211,8 +1143,6 @@ int InitShareMemory()
 		#endif
     	result = FAIL;
    	}
-    else
-    {}
 
    	//creat ShmPsuData
 	if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData),  0777)) < 0)
@@ -1323,6 +1253,8 @@ void Initialization()
 
 	ShmPsuData->SystemAvailableCurrent = 0;
 	ShmPsuData->SystemAvailablePower = 0;
+
+	GetTimespecFunc(&ShmDcCommonData->_psuComm_time);
 }
 
 void CheckSmartChargingStep(byte chargingStatus)
@@ -1357,7 +1289,7 @@ void CheckSmartChargingStep(byte chargingStatus)
 			{
 				PRINTF_FUNC("======= Aver -> Max : switch on the psu voltage. (Step 12) ======= \n");
 				preChargingCur = preChargingTarget = 0;
-				gettimeofday(&_max_time, NULL);
+				GetTimespecMFunc(&_max_time);
 				ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_ADJUST_A_TO_M;
 			}
 		}
@@ -1427,23 +1359,23 @@ void PreCheckSmartChargingStep()
 
 	for (byte index = 0; index < ShmPsuData->GroupCount; index++)
 	{
-		if ((chargingInfo[index]->SystemStatus >= S_PREPARING_FOR_EVSE && chargingInfo[index]->SystemStatus < S_CHARGING) ||
-				(chargingInfo[index]->SystemStatus >= S_CCS_PRECHARGE_ST0 && chargingInfo[index]->SystemStatus <= S_CCS_PRECHARGE_ST1))
+		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 == S_CHARGING)
+		else if (chargingInfo[index]->SystemStatus == SYS_MODE_CHARGING)
 		{
 			_maxChargingStatus = _CHARGING_GUN_STATUS_CHARGING;
 		}
-		else if (chargingInfo[index]->SystemStatus == S_COMPLETE ||
-						chargingInfo[index]->SystemStatus == S_ALARM)
+		else if (chargingInfo[index]->SystemStatus == SYS_MODE_COMPLETE ||
+						chargingInfo[index]->SystemStatus == SYS_MODE_ALARM)
 		{
 			_maxChargingStatus = _CHARGING_GUN_STATUS_STOP;
 		}
 
-		if ((chargingInfo[index]->SystemStatus >= S_PREPARING_FOR_EVSE && chargingInfo[index]->SystemStatus <= S_CHARGING) ||
-				(chargingInfo[index]->SystemStatus >= S_CCS_PRECHARGE_ST0 && chargingInfo[index]->SystemStatus <= S_CCS_PRECHARGE_ST1))
+		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;
 		}
@@ -1479,7 +1411,7 @@ bool MaxToAverChargingProc(byte groupIndex)
 				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;
-				gettimeofday(&_derating_time, NULL);
+				GetTimespecMFunc(&_derating_time);
 				deratingKeepCount = 0;
 			}
 			else
@@ -1506,7 +1438,7 @@ bool MaxToAverChargingProc(byte groupIndex)
 			{
 				for (byte subIndex = 0; subIndex < ShmPsuData->GroupCount; subIndex++)
 				{
-					if (chargingInfo[subIndex]->SystemStatus == S_REASSIGN)
+					if (chargingInfo[subIndex]->SystemStatus == SYS_MODE_REASSIGN)
 					{
 						// 當 B 模塊輸出電流小於 5A 及退開 relay
 						if ((ShmPsuData->PsuGroup[subIndex].GroupPresentOutputCurrent) <= 50)
@@ -1519,7 +1451,7 @@ bool MaxToAverChargingProc(byte groupIndex)
 			{
 				for (byte subIndex = 0; subIndex < ShmPsuData->GroupCount; subIndex++)
 				{
-					if (chargingInfo[subIndex]->SystemStatus == S_REASSIGN)
+					if (chargingInfo[subIndex]->SystemStatus == SYS_MODE_REASSIGN)
 					{
 						if ((ShmPsuData->PsuGroup[subIndex].GroupPresentOutputCurrent) <= CHK_CUR_RANGE)
 								isChanged = true;
@@ -1540,9 +1472,9 @@ bool MaxToAverChargingProc(byte groupIndex)
 			}
 			else
 			{
-				int _t = GetTimeoutValue(_derating_time);
+				int _t = GetTimeoutMValue(&_derating_time);
 
-				if ((_t / 1000) > 1000 || _t < 0)
+				if (_t > 1000 || _t < 0)
 				{
 					PRINTF_FUNC("Max To Ava mode (3-1) : Gun_%d, AvailableChargingCurrent = %f, EvBatterytargetCurrent = %f \n",
 						groupIndex,
@@ -1555,7 +1487,7 @@ bool MaxToAverChargingProc(byte groupIndex)
 						ShmPsuData->PsuGroup[groupIndex].GroupPresentOutputCurrent,
 						ShmPsuData->GroupCount);
 
-					gettimeofday(&_derating_time, NULL);
+					GetTimespecMFunc(&_derating_time);
 				}
 			}
 		}
@@ -1579,7 +1511,7 @@ bool MaxToAverChargingProc(byte groupIndex)
 			// 找到等待分配的槍
 			for (byte subIndex = 0; subIndex < ShmPsuData->GroupCount; subIndex++)
 			{
-				if (chargingInfo[subIndex]->SystemStatus == S_REASSIGN)
+				if (chargingInfo[subIndex]->SystemStatus == SYS_MODE_REASSIGN)
 				{
 					reassignIndex = subIndex;
 					break;
@@ -1588,7 +1520,7 @@ bool MaxToAverChargingProc(byte groupIndex)
 
 			if (reassignIndex != ELEMENT_NOT_FIND)
 			{
-				if ((GetTimeoutValue(_derating_time) / 1000) <= 150 ||
+				if (GetTimeoutMValue(&_derating_time) <= 150 ||
 						chargingInfo[groupIndex]->MaxChargingToAverPassFlag == 0)
 				{
 					chargingInfo[groupIndex]->MaxChargingToAverPassFlag = 1;
@@ -1647,12 +1579,12 @@ bool AverToMaxChargingProc(byte groupIndex)
 
 		for (byte subIndex = 0; subIndex < ShmPsuData->GroupCount; subIndex++)
 		{
-			if (chargingInfo[subIndex]->SystemStatus == S_IDLE ||
-					chargingInfo[subIndex]->SystemStatus == S_RESERVATION ||
-					chargingInfo[subIndex]->SystemStatus == S_FAULT ||
-					chargingInfo[subIndex]->SystemStatus == S_REASSIGN_CHECK ||
-					chargingInfo[subIndex]->SystemStatus == S_COMPLETE ||
-					chargingInfo[subIndex]->SystemStatus == S_ALARM)
+			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;
 
@@ -1676,7 +1608,7 @@ bool AverToMaxChargingProc(byte groupIndex)
 
 		if (reassignIndex != ELEMENT_NOT_FIND)
 		{
-			if ((GetTimeoutValue(_max_time) / 1000) <= 150)
+			if (GetTimeoutMValue(&_max_time) <= 150)
 			{
 				//PRINTF_FUNC("set out (%d) value = %d******** 5 \n", reassignIndex, ZERO_CURRENT + preChargingTarget);
 				// 閒置模塊升壓,另對剛分配近來的模塊,預上升電流值 (preChargingCur)
@@ -1738,11 +1670,11 @@ bool AverToMaxChargingProc(byte groupIndex)
 
 			for (subIndex = 0; subIndex < ShmPsuData->GroupCount; subIndex++)
 			{
-				if (chargingInfo[subIndex]->SystemStatus == S_IDLE ||
-						chargingInfo[subIndex]->SystemStatus == S_FAULT ||
-						chargingInfo[subIndex]->SystemStatus == S_RESERVATION ||
-						chargingInfo[subIndex]->SystemStatus == S_COMPLETE ||
-						chargingInfo[subIndex]->SystemStatus == S_ALARM)
+				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) - ZERO_VOLTAGE) ||
@@ -1762,15 +1694,15 @@ bool AverToMaxChargingProc(byte groupIndex)
 			}
 			else
 			{
-				int _tMax_1 = GetTimeoutValue(_max_time);
+				int _tMax_1 = GetTimeoutMValue(&_max_time);
 
-				if ((_tMax_1 / 1000) > 500 || _tMax_1 < 0)
+				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) - ZERO_VOLTAGE),
 						((chargingInfo[groupIndex]->EvBatterytargetVoltage * 10) - CHK_VOL_RANGE));
-					gettimeofday(&_max_time, NULL);
+					GetTimespecMFunc(&_max_time);
 				}
 			}
 		}
@@ -1781,10 +1713,10 @@ bool AverToMaxChargingProc(byte groupIndex)
 
 			for (byte subIndex = 0; subIndex < ShmPsuData->GroupCount; subIndex++)
 			{
-				if (chargingInfo[subIndex]->SystemStatus == S_IDLE ||
-						chargingInfo[subIndex]->SystemStatus == S_RESERVATION ||
-						chargingInfo[subIndex]->SystemStatus == S_FAULT ||
-						chargingInfo[subIndex]->SystemStatus == S_REASSIGN_CHECK)
+				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
 				{
@@ -1799,11 +1731,11 @@ bool AverToMaxChargingProc(byte groupIndex)
 			}
 			else
 			{
-				int _tMax_2 = GetTimeoutValue(_max_time);
+				int _tMax_2 = GetTimeoutMValue(&_max_time);
 
-				if ((_tMax_2 / 1000) > 300 || _tMax_2 < 0)
+				if (_tMax_2 > 300 || _tMax_2 < 0)
 				{
-					gettimeofday(&_max_time, NULL);
+					GetTimespecMFunc(&_max_time);
 				}
 			}
 		}
@@ -1817,15 +1749,15 @@ bool AverToMaxChargingProc(byte groupIndex)
 
 void SwitchOffPowerCheck(byte groupIndex)
 {
-	_maxChargingStatus = _CHARGING_GUN_STATUS_NONE;
+	_maxChargingStatus = _CHARGING_GUN_STATUS_STOP;
 
 	for (byte index = 0; index < ShmPsuData->GroupCount; index++)
 	{
 		// 判斷另一把槍的狀態
 		if (index != groupIndex)
 		{
-			if ((chargingInfo[index]->SystemStatus >= S_PREPARING_FOR_EV && chargingInfo[index]->SystemStatus <= S_CHARGING) ||
-					(chargingInfo[index]->SystemStatus >= S_CCS_PRECHARGE_ST0 && chargingInfo[index]->SystemStatus <= S_CCS_PRECHARGE_ST1))
+			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;
@@ -1901,7 +1833,12 @@ int main(void)
 			continue;
 		}
 		else
+		{
+			if (isInitialComp)
+				GetTimespecFunc(&ShmDcCommonData->_psuComm_time);
+
 			isInitialComp = NO;
+		}
 
 		// 自檢失敗
 		if (ShmPsuData->Work_Step == _NO_WORKING)
@@ -1909,13 +1846,28 @@ int main(void)
 			PRINTF_FUNC("== PSU == self test fail. \n");
 			sleep(5);
 		}
+		else
+		{
+			int _time = GetTimeoutValue(&ShmDcCommonData->_psuComm_time);
+			if (_time < 0)
+				GetTimespecFunc(&ShmDcCommonData->_psuComm_time);
+
+			if (_time > 30)
+			{
+				if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuFailureAlarm == NO)
+				{
+					ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuFailureAlarm = YES;
+					PRINTF_FUNC("Psu is gone, reset one time. \n");
+				}
+			}
+		}
 
 		switch(ShmPsuData->Work_Step)
 		{
 			case INITIAL_START:
 			{
 				PRINTF_FUNC("== PSU == INITIAL_START \n");
-				gettimeofday(&_cmdSubPriority_time, NULL);
+				GetTimespecMFunc(&_cmdSubPsuPriority_time);
 				sleep(5);
 				SwitchPower(SYSTEM_CMD, PSU_POWER_OFF);
 				SetWalkInConfig(SYSTEM_CMD, NO, 0);
@@ -1926,11 +1878,11 @@ int main(void)
 				break;
 			case GET_PSU_COUNT:
 			{
-				int time = GetTimeoutValue(_cmdSubPriority_time) / 1000;
+				int time = GetTimeoutMValue(&_cmdSubPsuPriority_time);
 				byte moduleCount = 0;
 
 				if (time < 0)
-					gettimeofday(&_cmdSubPriority_time, NULL);
+					GetTimespecMFunc(&_cmdSubPsuPriority_time);
 				// 發送取得目前全部模組數量
 				GetModuleCount(SYSTEM_CMD);
 
@@ -1966,16 +1918,16 @@ int main(void)
 						}
 					}
 
-					gettimeofday(&_cmdSubPriority_time, NULL);
+					GetTimespecMFunc(&_cmdSubPsuPriority_time);
 				}
 			}
 				break;
 			case GET_SYS_CAP:
 			{
-				int time = GetTimeoutValue(_cmdSubPriority_time) / 1000;
+				int time = GetTimeoutMValue(&_cmdSubPsuPriority_time);
 
 				if (time < 0)
-					gettimeofday(&_cmdSubPriority_time, NULL);
+					GetTimespecMFunc(&_cmdSubPsuPriority_time);
 
 				if (time > 500)
 				{
@@ -2028,8 +1980,8 @@ int main(void)
 						ShmPsuData->Work_Step = BOOTING_COMPLETE;
 					}
 
-					gettimeofday(&_cmdSubPriority_time, NULL);
-					gettimeofday(&_log_time, NULL);
+					GetTimespecMFunc(&_cmdSubPsuPriority_time);
+					GetTimespecFunc(&_log_time);
 				}
 			}
 				break;
@@ -2038,7 +1990,7 @@ int main(void)
 				bool isSelfTestPass = true;
 				for (byte groupIndex = 0; groupIndex < _gunCount; groupIndex++)
 				{
-					if (chargingInfo[groupIndex]->SystemStatus == S_BOOTING)
+					if (chargingInfo[groupIndex]->SystemStatus == SYS_MODE_BOOTING)
 					{
 						isSelfTestPass = false;
 					}
@@ -2051,18 +2003,18 @@ int main(void)
 				break;
 			case _WORK_CHARGING:
 			{
-				int time = GetTimeoutValue(_cmdSubPriority_time) / 1000;
-				unsigned long _timebuf = 0;
+				int time = GetTimeoutMValue(&_cmdSubPsuPriority_time);
+				int _timebuf = 0;
 
 				if (time < 0)
-					gettimeofday(&_cmdSubPriority_time, NULL);
+					GetTimespecMFunc(&_cmdSubPsuPriority_time);
 
 				// 低 Priority 的指令
 				if (time > 1500)
 				{
 					PreCheckSmartChargingStep();
 					startModuleFlag = true;
-					gettimeofday(&_cmdSubPriority_time, NULL);
+					GetTimespecMFunc(&_cmdSubPsuPriority_time);
 				}
 
 				for (byte groupIndex = 0; groupIndex < _gunCount; groupIndex++)
@@ -2103,18 +2055,18 @@ int main(void)
 				for (byte groupIndex = 0; groupIndex < _gunCount; groupIndex++)
 				{
 					// 針對各槍當前狀態,傳送需要回傳的資料指令
-					if (((chargingInfo[groupIndex]->SystemStatus >= S_PREPARING_FOR_EVSE && chargingInfo[groupIndex]->SystemStatus <= S_CHARGING) && chargingInfo[groupIndex]->RelayK1K2Status) ||
-							(chargingInfo[groupIndex]->SystemStatus >= S_PREPARING_FOR_EVSE && chargingInfo[groupIndex]->SystemStatus <= S_CHARGING && chargingInfo[groupIndex]->Type == _Type_GB) ||
-							(chargingInfo[groupIndex]->SystemStatus >= S_CCS_PRECHARGE_ST0 && chargingInfo[groupIndex]->SystemStatus <= S_CCS_PRECHARGE_ST1))
+					if (((chargingInfo[groupIndex]->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);
+						_timebuf = GetTimeoutValue(&_log_time);
 						if (_timebuf < 0)
-							gettimeofday(&_log_time, NULL);
+							GetTimespecFunc(&_log_time);
 
-						if (_timebuf / 1000 > 1000)
+						if (_timebuf > 1)
 						{
 							OutputChargingLogFuncion(groupIndex);
-							gettimeofday(&_log_time, NULL);
+							GetTimespecFunc(&_log_time);
 						}
 
 						if (ShmSysConfigAndInfo->SysInfo.MainChargingMode == _MAIN_CHARGING_MODE_MAX)
@@ -2148,20 +2100,41 @@ int main(void)
 								}
 								else
 								{
-									bool isNeedToOpenPower = false;
-									for (byte index = 0; index < ShmPsuData->GroupCount; index++)
+									if (chargingInfo[groupIndex]->SystemStatus == SYS_MODE_PREPARE_FOR_EVSE)
 									{
-										if (!isStartOutputSwitch[index])
+										if (startModuleFlag)
 										{
-											isNeedToOpenPower = true;
+											if (ShmSysConfigAndInfo->SysInfo.IsAlternatvieConf == YES)
+											{
+												isStartOutputSwitch[0] = true;
+												SwitchSinglePower(ShmDcCommonData->connector[0][0], PSU_POWER_ON);
+												FlashSingleLed(ShmDcCommonData->connector[0][0], PSU_FLASH_ON);
+											}
+											else
+											{
+												isStartOutputSwitch[groupIndex] = true;
+												SwitchSinglePower(ShmDcCommonData->connector[groupIndex][0], PSU_POWER_ON);
+												FlashSingleLed(ShmDcCommonData->connector[groupIndex][0], PSU_FLASH_ON);
+											}
 										}
-										isStartOutputSwitch[index] = true;
 									}
-
-									if (isNeedToOpenPower || startModuleFlag)
+									else
 									{
-										SwitchPower(SYSTEM_CMD, PSU_POWER_ON);
-										FlashLed(SYSTEM_CMD, PSU_FLASH_ON);
+										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);
+										}
 									}
 								}
 							}
@@ -2191,19 +2164,31 @@ int main(void)
 									}
 									else
 									{
-										if (!isStartOutputSwitch[groupIndex] || startModuleFlag)
+										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
 										{
-											isStartOutputSwitch[groupIndex] = true;
-											SwitchPower(groupIndex, PSU_POWER_ON); Await();
-											FlashLed(groupIndex, PSU_FLASH_ON); Await();
+											if (!isStartOutputSwitch[groupIndex] || startModuleFlag)
+											{
+												isStartOutputSwitch[groupIndex] = true;
+												SwitchPower(groupIndex, PSU_POWER_ON); Await();
+												FlashLed(groupIndex, PSU_FLASH_ON); Await();
+											}
 										}
 									}
 								}
 							}
 						}
 					}
-					else if (chargingInfo[groupIndex]->SystemStatus >= S_TERMINATING &&
-								chargingInfo[groupIndex]->SystemStatus <= S_ALARM)
+					else if (chargingInfo[groupIndex]->SystemStatus >= SYS_MODE_TERMINATING &&
+								chargingInfo[groupIndex]->SystemStatus <= SYS_MODE_ALARM)
 					{
 						if (ShmSysConfigAndInfo->SysInfo.MainChargingMode == _MAIN_CHARGING_MODE_MAX)
 						{
@@ -2226,8 +2211,8 @@ int main(void)
 									FlashLed(SYSTEM_CMD, PSU_FLASH_NORMAL);
 								}
 
-								if (chargingInfo[groupIndex]->SystemStatus == S_COMPLETE ||
-										chargingInfo[groupIndex]->SystemStatus == S_ALARM)
+								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)
@@ -2238,7 +2223,7 @@ int main(void)
 									}
 								}
 							}
-							else if (chargingInfo[groupIndex]->SystemStatus == S_COMPLETE)
+							else if (chargingInfo[groupIndex]->SystemStatus == SYS_MODE_COMPLETE)
 							{
 								// 代表充電的槍依舊在充電,欲進入充電的槍取消充電了
 								if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag >= _REASSIGNED_PREPARE_M_TO_A &&
@@ -2283,7 +2268,7 @@ int main(void)
 								ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_COMP;
 						}
 					}
-					else if ((chargingInfo[groupIndex]->SystemStatus >= S_PREPARNING && chargingInfo[groupIndex]->SystemStatus <= S_PREPARING_FOR_EV) &&
+					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);
@@ -2302,10 +2287,10 @@ int main(void)
 			case _TEST_MODE:
 			{
 				// 在測試模式中,保持與模塊的通訊
-				int time = GetTimeoutValue(_cmdSubPriority_time) / 1000;
+				int time = GetTimeoutMValue(&_cmdSubPsuPriority_time);
 
 				if (time < 0)
-					gettimeofday(&_cmdSubPriority_time, NULL);
+					GetTimespecMFunc(&_cmdSubPsuPriority_time);
 
 				if (time > 1500)
 				{
@@ -2318,24 +2303,24 @@ int main(void)
 						GetModuleOutputF(index); Await();
 					}
 
-					gettimeofday(&_cmdSubPriority_time, NULL);
+					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 < conn_1_count; _groupCount_1++)
+				for (byte _groupCount_1 = 0; _groupCount_1 < ShmDcCommonData->conn_1_count; _groupCount_1++)
 				{
-					SetDirModulePresentOutput(connector_1[_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 < conn_2_count; _groupCount_2++)
+				for (byte _groupCount_2 = 0; _groupCount_2 < ShmDcCommonData->conn_2_count; _groupCount_2++)
 				{
-					SetDirModulePresentOutput(connector_2[_groupCount_2],
+					SetDirModulePresentOutput(ShmDcCommonData->connector[1][_groupCount_2],
 						(chargingInfo[0]->EvBatterytargetVoltage * 10),
 						(chargingInfo[0]->EvBatterytargetCurrent * 10),
 						_switch, _switch); Await();

+ 9 - 8
EVSE/Projects/DS60-120/Apps/Module_PsuComm.h

@@ -38,10 +38,10 @@ unsigned char _gunCount;
 struct ChargingInfoData *chargingInfo[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
 bool isStartOutputSwitch[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
 
-struct timeval _cmdSubPriority_time;
-struct timeval _derating_time;
-struct timeval _max_time;
-struct timeval _log_time;
+struct timespec _cmdSubPsuPriority_time;
+struct timespec _derating_time;
+struct timespec _max_time;
+struct timespec _log_time;
 
 byte _maxChargingStatus;
 bool isReadyToCharging = false;
@@ -51,10 +51,11 @@ int preChargingCur;
 float toAverVolPoint;
 byte toAverVolCount;
 
-int connector_1[12];
-int connector_2[12];
-byte conn_1_count = 0;
-byte conn_2_count = 0;
+//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
 {

+ 3 - 3
EVSE/Projects/DS60-120/Apps/OutputTask.c

@@ -263,7 +263,7 @@ int main(void)
 	}
 
 	sleep(5);
-	gettimeofday(&_cmdSubPriority_time, NULL);
+	gettimeofday(&_cmdSubUnSafetyPriority_time, NULL);
 	VOLTAGE = 0.0;
 	CURRENT = 0.0;
 
@@ -289,7 +289,7 @@ int main(void)
 		// ¤Á´« Walk-in mode (default 5s -> 2s)
 		SetWalkInConfig(SYSTEM_CMD, NO, 0);
 
-		int time = GetTimeoutValue(_cmdSubPriority_time) / 1000;
+		int time = GetTimeoutValue(_cmdSubUnSafetyPriority_time) / 1000;
 		while(isGetCount == YES)
 		{
 			if (_charging_mode == CHARGING_MODE_START)
@@ -349,7 +349,7 @@ int main(void)
 			{
 				printf("Step 1 : GetModuleCount...... \n");
 				GetModuleCount(SYSTEM_CMD);
-				gettimeofday(&_cmdSubPriority_time, NULL);
+				gettimeofday(&_cmdSubUnSafetyPriority_time, NULL);
 			}
 		}
 		else if (time < 5000)

+ 1 - 1
EVSE/Projects/DS60-120/Apps/OutputTask.h

@@ -56,7 +56,7 @@ int Uart1Fd = -1;
 char *priPortName = "/dev/ttyS1";
 
 bool libInitialize = false;
-struct timeval _cmdSubPriority_time;
+struct timeval _cmdSubUnSafetyPriority_time;
 
 unsigned char Button1 = RELEASE;
 unsigned char Button2 = RELEASE;

+ 164 - 129
EVSE/Projects/DS60-120/Apps/ReadCmdline.c

@@ -143,9 +143,7 @@ int InitShareMemory()
     else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
     {
     	result = FAIL;
-   	 }
-    else
-    {}
+   	}
 
    	//initial ShmStatusCodeData
    	if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData),  0777)) < 0)
@@ -156,8 +154,6 @@ int InitShareMemory()
     {
     	result = FAIL;
    	}
-    else
-    {}
 
 	if (CHAdeMO_QUANTITY > 0) {
 		if ((MeterSMId = shmget(ShmCHAdeMOCommKey, sizeof(struct CHAdeMOData),
@@ -187,7 +183,6 @@ int InitShareMemory()
 		} else if ((ShmGBTData = shmat(MeterSMId, NULL, 0)) == (void *) -1) {
 			return 0;
 		}
-		memset(ShmGBTData, 0, sizeof(struct GBTData));
 	}
 
    	if ((MeterSMId = shmget(ShmPrimaryMcuKey, sizeof(struct PrimaryMcuData), IPC_CREAT | 0777)) < 0)
@@ -482,6 +477,7 @@ void CreateOneError()
 	{
 		printf("(%d). %s \n", i, &ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0]);
 	}
+
 }
 
 void GetAuthorizeFlag(char *v1)
@@ -528,6 +524,8 @@ void CheckAcStatus(char *v1)
 	{
 		printf("AC Status = %d \n", ShmSysConfigAndInfo->SysInfo.AcContactorStatus);
 	}
+	else
+		ShmSysConfigAndInfo->SysInfo.AcContactorStatus = atoi(v1);
 }
 
 void SetCableChkStatus(char *v1, char *v2)
@@ -551,8 +549,8 @@ void SetChargingInfoCCID(char *v1, char* v2)
 		return;
 	}
 
-	memcpy(_chargingData[_index]->EVCCID, v2, 8);
-	_chargingData[_index]->EVCCID[8] = '\0';
+	memcpy(_chargingData[_index]->EVCCID, v2, strlen(v2));
+	_chargingData[_index]->EVCCID[strlen(v2)] = '\0';
 }
 
 void GetGunTemp(char *v1)
@@ -571,6 +569,38 @@ void GetGunTemp(char *v1)
 			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);
@@ -580,8 +610,9 @@ void GetDcMeterInfor(char *v1)
 		return;
 	}
 
-	printf("Index = %d, presetVoltage = %f, presentCurrent = %f, presentPower = %f, totlizeImportEnergy = %f, totlizeExportEnergy = %f \n",
+	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,
@@ -888,8 +919,6 @@ void AverageCharging(char *g1_vol, char *g1_cur, char *g2_vol, char *g2_cur)
 	    return;
 	}
 
-	system("killall Module_EvComm");
-
 	for (byte _index = 0; _index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _index++)
 	{
 		if (!FindChargingInfoData(_index, &_chargingData[0]))
@@ -897,7 +926,12 @@ void AverageCharging(char *g1_vol, char *g1_cur, char *g2_vol, char *g2_cur)
 			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};
 
@@ -907,18 +941,18 @@ void AverageCharging(char *g1_vol, char *g1_cur, char *g2_vol, char *g2_cur)
 		{
 			switch(_chargingData[gun_index]->SystemStatus)
 			{
-				case S_IDLE:
+				case SYS_MODE_IDLE:
 				{
 					if(PreviousSystemStatus[gun_index] != _chargingData[gun_index]->SystemStatus)
 					{
 						PreviousSystemStatus[gun_index] = _chargingData[gun_index]->SystemStatus;
-					    printf ("[AverageCharging (%d) - S_IDLE] \n", gun_index);
+					    printf ("[AverageCharging (%d) - SYS_MODE_IDLE] \n", gun_index);
 					}
 
-					_chargingData[gun_index]->SystemStatus = S_PREPARNING;
+					_chargingData[gun_index]->SystemStatus = SYS_MODE_PREPARING;
 				}
 					break;
-				case S_PREPARNING:
+				case SYS_MODE_PREPARING:
 				{
 					if(PreviousSystemStatus[gun_index] != _chargingData[gun_index]->SystemStatus)
 				    {
@@ -932,16 +966,14 @@ void AverageCharging(char *g1_vol, char *g1_cur, char *g2_vol, char *g2_cur)
 					ShmSysConfigAndInfo->SysInfo.MainChargingMode = _MAIN_CHARGING_MODE_AVER;
 				    //清除 main timeout 機制
 					_chargingData[gun_index]->TimeoutFlag = 0;
-					//不論是什麼 type 的槍都固意設成 Chademo 不跑 Prechage step
-				    _chargingData[gun_index]->Type = 9;
 				}
 					break;
-				case S_PREPARING_FOR_EV:
+				case SYS_MODE_PREPARE_FOR_EV:
 				{
 					if(PreviousSystemStatus[gun_index] != _chargingData[gun_index]->SystemStatus)
 				    {
 				    	PreviousSystemStatus[gun_index] = _chargingData[gun_index]->SystemStatus;
-				        printf ("[AverageCharging (%d) - S_PREPARING_FOR_EV] \n", gun_index);
+				        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 機制
@@ -962,16 +994,16 @@ void AverageCharging(char *g1_vol, char *g1_cur, char *g2_vol, char *g2_cur)
 				    {
 				    	printf ("Preparing Done = %f \n", _chargingData[gun_index]->PresentChargingVoltage);
 				    	//EV done
-				    	_chargingData[gun_index]->SystemStatus = S_PREPARING_FOR_EVSE;
+				    	_chargingData[gun_index]->SystemStatus = SYS_MODE_PREPARE_FOR_EVSE;
 				    }
 				}
 					break;
-				case S_PREPARING_FOR_EVSE:
+				case SYS_MODE_PREPARE_FOR_EVSE:
 				{
 					if(PreviousSystemStatus[gun_index] != _chargingData[gun_index]->SystemStatus)
 					{
 						PreviousSystemStatus[gun_index] = _chargingData[gun_index]->SystemStatus;
-						printf ("[AverageCharging (%d) - S_PREPARING_FOR_EVSE]\n", gun_index);
+						printf ("[AverageCharging (%d) - SYS_MODE_PREPARE_FOR_EVSE]\n", gun_index);
 					}
 
 					//printf ("tar vol = %d \n", _Voltage);
@@ -1000,16 +1032,16 @@ void AverageCharging(char *g1_vol, char *g1_cur, char *g2_vol, char *g2_cur)
 						printf ("Wait K1K2 = %f \n", _chargingData[gun_index]->PresentChargingVoltage);
 						sleep(5);
 						//EV done
-						_chargingData[gun_index]->SystemStatus = S_CHARGING;
+						_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 = S_TERMINATING;
+						_chargingData[gun_index]->SystemStatus = SYS_MODE_TERMINATING;
 					}
 				}
 					break;
-				case S_CHARGING:
+				case SYS_MODE_CHARGING:
 				{
 					if(PreviousSystemStatus[gun_index] != _chargingData[gun_index]->SystemStatus)
 				    {
@@ -1021,7 +1053,7 @@ void AverageCharging(char *g1_vol, char *g1_cur, char *g2_vol, char *g2_cur)
 				        _chargingData[gun_index]->EvBatterySoc = 50;
 				        _chargingData[gun_index]->AvailableChargingCurrent = 1000;
 
-				        printf ("[AverageCharging (%d) - S_CHARGING]\n", gun_index);
+				        printf ("[AverageCharging (%d) - SYS_MODE_CHARGING]\n", gun_index);
 				    }
 
 				    //ev task do this
@@ -1031,30 +1063,30 @@ void AverageCharging(char *g1_vol, char *g1_cur, char *g2_vol, char *g2_cur)
 				    if (_chargingData[gun_index]->GroundFaultStatus == 0x02)
 				    {
 				    	printf ("Charging Ground Fault check Fail (%d)\n",_chargingData[gun_index]->GroundFaultStatus);
-				    	_chargingData[gun_index]->SystemStatus = S_TERMINATING;
+				    	_chargingData[gun_index]->SystemStatus = SYS_MODE_TERMINATING;
 				    }
 				}
 				    break;
-				case S_TERMINATING:
+				case SYS_MODE_TERMINATING:
 				{
 					if(PreviousSystemStatus[gun_index] != _chargingData[gun_index]->SystemStatus)
 				    {
 						PreviousSystemStatus[gun_index] = _chargingData[gun_index]->SystemStatus;
-				        printf ("[AverageCharging (%d) - S_TERMINATING] \n", gun_index);
+				        printf ("[AverageCharging (%d) - SYS_MODE_TERMINATING] \n", gun_index);
 				        //無阻塞偵測 keybaord 結束
 				        system(STTY_DEF TTY_PATH);
 				    }
 
 				    sleep(3);
-				    _chargingData[gun_index]->SystemStatus = S_COMPLETE;
+				    _chargingData[gun_index]->SystemStatus = SYS_MODE_COMPLETE;
 				}
 				    break;
-				case S_COMPLETE:
+				case SYS_MODE_COMPLETE:
 				{
 				    if(PreviousSystemStatus[gun_index] != _chargingData[gun_index]->SystemStatus)
 				    {
 				    	PreviousSystemStatus[gun_index] = _chargingData[gun_index]->SystemStatus;
-				    	printf ("[AverageCharging (%d) - S_COMPLETE] \n", gun_index);
+				    	printf ("[AverageCharging (%d) - SYS_MODE_COMPLETE] \n", gun_index);
 				    }
 
 				    _chargingData[gun_index]->PresentChargingPower = 0;
@@ -1101,7 +1133,7 @@ void AverageCharging(char *g1_vol, char *g1_cur, char *g2_vol, char *g2_cur)
 			for (byte gun_index = 0; gun_index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gun_index++)
 			{
 				ShmDcCommonData->StartToChargingFlag[gun_index] = 0x00;
-				_chargingData[gun_index]->SystemStatus = S_TERMINATING;
+				_chargingData[gun_index]->SystemStatus = SYS_MODE_TERMINATING;
 			}
 			printf("stop \n\r");
 		}
@@ -1155,7 +1187,9 @@ void RunUnconditionalChargeIndex1(char *v1, char *v2, char *v3)
 
     //測試期間先跳過自我測試 _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");
 
@@ -1167,30 +1201,27 @@ void RunUnconditionalChargeIndex1(char *v1, char *v2, char *v3)
     while(true)
     {
         //fix gun 1
-        ShmSysConfigAndInfo->SysInfo.CurGunSelected = _GunIndex;
-
-    	switch(_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
+    	switch(_chargingData[_GunIndex]->SystemStatus)
     	{
-            case S_IDLE:
+            case SYS_MODE_IDLE:
     		{
-        	    if(PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
+        	    if(PreviousSystemStatus != _chargingData[_GunIndex]->SystemStatus)
         	    {
-        	        PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
-
-        	        printf ("[UnconditionalCharge - S_IDLE]\n");
+        	        PreviousSystemStatus = _chargingData[_GunIndex]->SystemStatus;
 
+        	        printf ("[UnconditionalCharge - SYS_MODE_IDLE]\n");
         	    }
 
-        	    ShmDcCommonData->StartToChargingFlag[ShmSysConfigAndInfo->SysInfo.CurGunSelected] = 0x01;
-                _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_PREPARNING;
+        	    ShmDcCommonData->StartToChargingFlag[_GunIndex] = 0x01;
+                _chargingData[_GunIndex]->SystemStatus = SYS_MODE_PREPARING;
     		}
     		break;
 
-    		case S_PREPARNING:
+    		case SYS_MODE_PREPARING:
     		{
-        	    if(PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
+        	    if(PreviousSystemStatus != _chargingData[_GunIndex]->SystemStatus)
         	    {
-        	        PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
+        	        PreviousSystemStatus = _chargingData[_GunIndex]->SystemStatus;
 
         	        printf ("[UnconditionalCharge - S_PREPARNIN]\n");
 
@@ -1209,103 +1240,103 @@ void RunUnconditionalChargeIndex1(char *v1, char *v2, char *v3)
     		    //sleep(10);
 
     		    //清除 main timeout 機制
-    		    _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->TimeoutFlag = 0;
+    		    _chargingData[_GunIndex]->TimeoutFlag = 0;
     		    //不論是什麼 type 的槍都固意設成 Chademo 不跑 Prechage step
-    		    _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->Type = 9;
+    		    _chargingData[_GunIndex]->Type = 9;
 
     		}
     		break;
 
-    		case S_PREPARING_FOR_EV:
+    		case SYS_MODE_PREPARE_FOR_EV:
     		{
-        	    if(PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
+        	    if(PreviousSystemStatus != _chargingData[_GunIndex]->SystemStatus)
         	    {
-        	        PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
+        	        PreviousSystemStatus = _chargingData[_GunIndex]->SystemStatus;
 
-        	        printf ("[UnconditionalCharge - S_PREPARING_FOR_EV]\n");
+        	        printf ("[UnconditionalCharge - SYS_MODE_PREPARE_FOR_EV]\n");
         	        printf ("ReqVoltage = %f, ReqCurrent = %f \n", _Voltage * 10,_Current * 10);
 
         	    }
     		    //清除 main timeout 機制
-    		    _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->TimeoutFlag = 0;
+    		    _chargingData[_GunIndex]->TimeoutFlag = 0;
     		    //不論是什麼 type 的槍都固意設成 Chademo 不跑 Prechage step
-    		    _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->Type = 9;
+    		    _chargingData[_GunIndex]->Type = 9;
 
     		    //充電電壓電流
-    		    _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterySoc = 50;
-   		        _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage = 500;
-    		    _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent = 2;
-    		    _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->AvailableChargingCurrent = 1000;
+    		    _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[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingVoltage);
+    		        printf ("Precharge Done = %f \n", _chargingData[_GunIndex]->PresentChargingVoltage);
     		        //EV done
-    		        _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_PREPARING_FOR_EVSE;
+    		        _chargingData[_GunIndex]->SystemStatus = SYS_MODE_PREPARE_FOR_EVSE;
     		    }
     		}
     		break;
 
-    		case S_PREPARING_FOR_EVSE:
+    		case SYS_MODE_PREPARE_FOR_EVSE:
     		{
-        	    if(PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
+        	    if(PreviousSystemStatus != _chargingData[_GunIndex]->SystemStatus)
         	    {
-        	        PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
+        	        PreviousSystemStatus = _chargingData[_GunIndex]->SystemStatus;
 
-        	        printf ("[UnconditionalCharge - S_PREPARING_FOR_EVSE]\n");
+        	        printf ("[UnconditionalCharge - SYS_MODE_PREPARE_FOR_EVSE]\n");
 
         	    }
         	    //printf ("tar vol = %d \n", _Voltage);
         	    //printf ("tar cur = %d \n", _Current);
 
     		    //清除 main timeout 機制
-    		    _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->TimeoutFlag = 0;
+    		    _chargingData[_GunIndex]->TimeoutFlag = 0;
     		    //不論是什麼 type 的槍都固意設成 Chademo 不跑 Prechage step
-    		    _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->Type = 9;
+    		    _chargingData[_GunIndex]->Type = 9;
 
     		    //充電電壓電流
-    		    _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterySoc = 50;
-    		    _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage = 500;
-    		    _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent = 2;
-    		    _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->AvailableChargingCurrent = 1000;
+    		    _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 )
     		    //確定模組己升壓完成
-    		    if(_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus == 0x01 ||
-    		        _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus == 0x03)
+    		    if(_chargingData[_GunIndex]->GroundFaultStatus == 0x01 ||
+    		        _chargingData[_GunIndex]->GroundFaultStatus == 0x03)
     		    {
-    		        printf ("First Ground Fault State (%d)\n",_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus);
-    		        printf ("Wait K1K2 = %f \n", _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingVoltage);
+    		        printf ("First Ground Fault State (%d)\n",_chargingData[_GunIndex]->GroundFaultStatus);
+    		        printf ("Wait K1K2 = %f \n", _chargingData[_GunIndex]->PresentChargingVoltage);
     		        sleep(5);
     		        //EV done
-    		        _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_CHARGING;
+    		        _chargingData[_GunIndex]->SystemStatus = SYS_MODE_CHARGING;
     		    }
-    		    else if (_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus > 0x02)
+    		    else if (_chargingData[_GunIndex]->GroundFaultStatus > 0x02)
     		    {
-    		        printf ("First Ground Fault check Fail (%d)\n",_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus);
-    		        _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_TERMINATING;
+    		        printf ("First Ground Fault check Fail (%d)\n",_chargingData[_GunIndex]->GroundFaultStatus);
+    		        _chargingData[_GunIndex]->SystemStatus = SYS_MODE_TERMINATING;
     		    }
 
     		}
     		break;
 
-    		case S_CHARGING:
+    		case SYS_MODE_CHARGING:
     		{
-        	    if(PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
+        	    if(PreviousSystemStatus != _chargingData[_GunIndex]->SystemStatus)
         	    {
-        	        PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
+        	        PreviousSystemStatus = _chargingData[_GunIndex]->SystemStatus;
 
         	        if (_usingAutoRun == 0x00)
         	        {
         	        	//充電電壓電流
-        	        	_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage = _Voltage;
-        	        	_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent = _Current;
+        	        	_chargingData[_GunIndex]->EvBatterytargetVoltage = _Voltage;
+        	        	_chargingData[_GunIndex]->EvBatterytargetCurrent = _Current;
         	        }
         	        else
         	        {
@@ -1313,10 +1344,10 @@ void RunUnconditionalChargeIndex1(char *v1, char *v2, char *v3)
         	        	gettimeofday(&_autoTime, NULL);
         	        }
 
-        	        _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterySoc = 50;
-        	        _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->AvailableChargingCurrent = 1000;
+        	        _chargingData[_GunIndex]->EvBatterySoc = 50;
+        	        _chargingData[_GunIndex]->AvailableChargingCurrent = 1000;
 
-        	        printf ("[UnconditionalCharge - S_CHARGING]\n");
+        	        printf ("[UnconditionalCharge - SYS_MODE_CHARGING]\n");
         	    }
 
         	    if (_usingAutoRun == 0x01)
@@ -1324,21 +1355,21 @@ void RunUnconditionalChargeIndex1(char *v1, char *v2, char *v3)
         	    	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[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage = _Voltage;
-        	    		_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent = _Current;
+        	    		_chargingData[_GunIndex]->EvBatterytargetVoltage = _Voltage;
+        	    		_chargingData[_GunIndex]->EvBatterytargetCurrent = _Current;
         	    	}
         	    	else if ((GetTimeoutValue(_autoTime)) >= AUTORUN_END_TIME * 60)
         	    	{
         	    		_curAutoRunCount++;
         	    		if (_curAutoRunCount >= AUTORUN_CYCLE_COUNT)
-        	    			_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_TERMINATING;
+        	    			_chargingData[_GunIndex]->SystemStatus = SYS_MODE_TERMINATING;
         	    		else
         	    			gettimeofday(&_autoTime, NULL);
         	    	}
         	    	else
         	    	{
-        	    		_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage = 0;
-        	    		_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent = 0;
+        	    		_chargingData[_GunIndex]->EvBatterytargetVoltage = 0;
+        	    		_chargingData[_GunIndex]->EvBatterytargetCurrent = 0;
         	    	}
         	    }
 
@@ -1346,44 +1377,44 @@ void RunUnconditionalChargeIndex1(char *v1, char *v2, char *v3)
 //        	    		_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage,
 //						_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent);
     		    //ev task do this
-    		    _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingPower =
-    		    		((float)((_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingVoltage) * (_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingCurrent)) / 1000);
+    		    _chargingData[_GunIndex]->PresentChargingPower =
+    		    		((float)((_chargingData[_GunIndex]->PresentChargingVoltage) * (_chargingData[_GunIndex]->PresentChargingCurrent)) / 1000);
 
-    		    if (_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus == 0x02){
-    		         printf ("Charging Ground Fault check Fail (%d)\n",_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus);
-    		        _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_TERMINATING;
+    		    if (_chargingData[_GunIndex]->GroundFaultStatus == 0x02){
+    		         printf ("Charging Ground Fault check Fail (%d)\n",_chargingData[_GunIndex]->GroundFaultStatus);
+    		        _chargingData[_GunIndex]->SystemStatus = SYS_MODE_TERMINATING;
     		    }
     		}
     		break;
 
-     		case S_TERMINATING:
+     		case SYS_MODE_TERMINATING:
     		{
-        	    if(PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
+        	    if(PreviousSystemStatus != _chargingData[_GunIndex]->SystemStatus)
         	    {
-        	        PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
+        	        PreviousSystemStatus = _chargingData[_GunIndex]->SystemStatus;
         	        system("/root/Module_EvComm &");
 
-        	        printf ("[UnconditionalCharge - S_TERMINATING]\n");
+        	        printf ("[UnconditionalCharge - SYS_MODE_TERMINATING]\n");
         	        //無阻塞偵測 keybaord 結束
         	        system(STTY_DEF TTY_PATH);
         	    }
 
         	    sleep(3);
-        	    _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_COMPLETE;
+        	    _chargingData[_GunIndex]->SystemStatus = SYS_MODE_COMPLETE;
         	    return;
     		}
     		break;
 
-    		case S_COMPLETE:
+    		case SYS_MODE_COMPLETE:
     		{
-        	    if(PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
+        	    if(PreviousSystemStatus != _chargingData[_GunIndex]->SystemStatus)
         	    {
-        	        PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
+        	        PreviousSystemStatus = _chargingData[_GunIndex]->SystemStatus;
 
-        	        printf ("[UnconditionalCharge - S_COMPLETE]\n");
+        	        printf ("[UnconditionalCharge - SYS_MODE_COMPLETE]\n");
         	    }
 
-        	    _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingPower = 0;
+        	    _chargingData[_GunIndex]->PresentChargingPower = 0;
         	    sleep(3);
         	    return;
     		}
@@ -1432,14 +1463,14 @@ void RunUnconditionalChargeIndex1(char *v1, char *v2, char *v3)
     		   continue;
 
     		printf("vol = %f, cur = %f \n", _vol, _cur);
-    		_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage = _vol;
-    		_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent = _cur;
+    		_chargingData[_GunIndex]->EvBatterytargetVoltage = _vol;
+    		_chargingData[_GunIndex]->EvBatterytargetCurrent = _cur;
     	}
     	else if (strcmp(newString[0], "c") == 0)
     	{
     		printf("stop \n\r");
-    		ShmDcCommonData->StartToChargingFlag[ShmSysConfigAndInfo->SysInfo.CurGunSelected] = 0x00;
-    		_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_TERMINATING;
+    		ShmDcCommonData->StartToChargingFlag[_GunIndex] = 0x00;
+    		_chargingData[_GunIndex]->SystemStatus = SYS_MODE_TERMINATING;
     	}
 
     	usleep(100000);
@@ -1650,6 +1681,24 @@ int main(void)
 			}
 			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
@@ -1675,24 +1724,10 @@ int main(void)
 		}
 		else if (strcmp(newString[0], "test") == 0)
 		{
-//			if (!FindChargingInfoData(0, &_chargingData[0]))
-//			{
-//				printf ("FindChargingInfoData error\n");
-//				continue;
-//			}
-//			_chargingData[0]->PresentChargingVoltage = 900;
-//			_chargingData[0]->PresentChargingCurrent = 200;
-//
-//			if (!FindChargingInfoData(1, &_chargingData[0]))
-//			{
-//				printf ("FindChargingInfoData error\n");
-//				continue;
-//			}
-//			_chargingData[1]->PresentChargingVoltage = 500;
-//			_chargingData[1]->PresentChargingCurrent = 60;
-			ShmSysConfigAndInfo->SysInfo.MainChargingMode = 0;
-			printf("ShmSysConfigAndInfo->SysInfo.MainChargingMode = %d \n",
-					ShmSysConfigAndInfo->SysInfo.MainChargingMode);
+			// Test Command
+			printf ("mode = %d \n", ShmSysConfigAndInfo->SysInfo.MainChargingMode);
+			ShmSysConfigAndInfo->SysInfo.MainChargingMode = _MAIN_CHARGING_MODE_AVER;
+			printf ("mode = %d \n", ShmSysConfigAndInfo->SysInfo.MainChargingMode);
 		}
 		else if(strcmp(newString[0], "strchg") == 0)
 		{

+ 6 - 12
EVSE/Projects/DS60-120/Apps/kill.sh

@@ -1,13 +1,7 @@
-pkill Module_CSU
-pkill Module_PrimaryComm
-pkill Module_LcmControl
-pkill Module_InternalComm
-pkill Module_EventLogging
-pkill Module_EvComm
-pkill Module_PsuComm
-pkill Module_4g
-pkill Module_Wifi
-pkill OcppBackend
-pkill Module_ProduceUtils
+#!/bin/sh
 pkill main
-
+pkill Module_
+pkill OcppBackend
+fuser -k /dev/watchdog
+sleep 1
+echo V > /dev/watchdog

Різницю між файлами не показано, бо вона завелика
+ 307 - 205
EVSE/Projects/DS60-120/Apps/main.c


+ 6 - 4
EVSE/Projects/DS60-120/Apps/timeout.h

@@ -53,14 +53,16 @@ enum Timeout_flag
 };
 
 // for timeout fork
-struct timeval _cmdSubPriority_time;
+struct timespec _cmdSubPriority_time;
 unsigned short _connectionTimeout;
 
 // for main
-struct timeval _cmdMainPriority_time;
-struct timeval _toAverage_time;
-unsigned char _ocppProfileChkFlag;
+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_ */

Деякі файли не було показано, через те що забагато файлів було змінено