Эх сурвалжийг харах

2021-10-01/Liwi Yang
action
1.merge

Liwei 3 жил өмнө
parent
commit
e71ce28425
34 өөрчлөгдсөн 2622 нэмэгдсэн , 1262 устгасан
  1. 126 0
      EVSE/Projects/DS60-120/Apps/CheckSystemTask.c
  2. 41 0
      EVSE/Projects/DS60-120/Apps/CheckSystemTask.h
  3. 105 24
      EVSE/Projects/DS60-120/Apps/Config.h
  4. 7 7
      EVSE/Projects/DS60-120/Apps/Ev_Comm.c
  5. BIN
      EVSE/Projects/DS60-120/Apps/FactoryConfig
  6. 15 0
      EVSE/Projects/DS60-120/Apps/FactoryConfig.c
  7. 11 10
      EVSE/Projects/DS60-120/Apps/Makefile
  8. BIN
      EVSE/Projects/DS60-120/Apps/Module_EvComm
  9. 427 418
      EVSE/Projects/DS60-120/Apps/Module_EvComm.c
  10. 1 1
      EVSE/Projects/DS60-120/Apps/Module_EvComm.h
  11. BIN
      EVSE/Projects/DS60-120/Apps/Module_EventLogging
  12. 3 7
      EVSE/Projects/DS60-120/Apps/Module_EventLogging.c
  13. BIN
      EVSE/Projects/DS60-120/Apps/Module_InternalComm
  14. 218 224
      EVSE/Projects/DS60-120/Apps/Module_InternalComm.c
  15. BIN
      EVSE/Projects/DS60-120/Apps/Module_LcmControl
  16. 465 37
      EVSE/Projects/DS60-120/Apps/Module_LcmControl.c
  17. BIN
      EVSE/Projects/DS60-120/Apps/Module_PrimaryComm
  18. 22 14
      EVSE/Projects/DS60-120/Apps/Module_PrimaryComm.c
  19. BIN
      EVSE/Projects/DS60-120/Apps/Module_PsuComm
  20. 134 87
      EVSE/Projects/DS60-120/Apps/Module_PsuComm.c
  21. 4 4
      EVSE/Projects/DS60-120/Apps/Module_PsuComm.h
  22. 3 3
      EVSE/Projects/DS60-120/Apps/OutputTask.c
  23. 1 1
      EVSE/Projects/DS60-120/Apps/OutputTask.h
  24. BIN
      EVSE/Projects/DS60-120/Apps/ReadCmdline
  25. 239 116
      EVSE/Projects/DS60-120/Apps/ReadCmdline.c
  26. BIN
      EVSE/Projects/DS60-120/Apps/UnsafetyOutputTask
  27. 315 0
      EVSE/Projects/DS60-120/Apps/cbmp.c
  28. 54 0
      EVSE/Projects/DS60-120/Apps/cbmp.h
  29. 6 12
      EVSE/Projects/DS60-120/Apps/kill.sh
  30. BIN
      EVSE/Projects/DS60-120/Apps/main
  31. 419 293
      EVSE/Projects/DS60-120/Apps/main.c
  32. 6 4
      EVSE/Projects/DS60-120/Apps/timeout.h
  33. BIN
      EVSE/Projects/DS60-120/Images/FactoryDefaultConfig.bin
  34. BIN
      EVSE/Projects/DS60-120/Images/ramdisk.gz

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

@@ -0,0 +1,126 @@
+/*
+ * 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("main");
+	//unsigned char count_main 		= GetProcessCount("Module_CSU");
+	unsigned char count_evComm 		= GetProcessCount("Module_EvComm");
+	unsigned char count_psuComm 	= GetProcessCount("Module_PsuComm");
+
+//	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_ */

+ 105 - 24
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,9 +29,13 @@ typedef unsigned char			byte;
 #define BOOTTING			0
 #define BOOT_COMPLETE		1
 
+//LWN_Zanobe
+#define  LW_DEBUG_INFO   0
+
+
 enum _SYSTEM_STATUS
 {
-	S_BOOTING = 						0,
+	/*S_BOOTING = 						0,
     S_IDLE,
 	S_AUTHORIZING,
 	S_REASSIGN_CHECK,
@@ -69,8 +54,8 @@ enum _SYSTEM_STATUS
 	S_DEBUG,
 	S_CCS_PRECHARGE_ST0,
 	S_CCS_PRECHARGE_ST1,
-	S_UPDATE,
-	S_NONE,
+	S_UPDATE,*/
+	S_NONE = 20
 };
 
 enum _AC_SYSTEM_STATUS
@@ -187,6 +172,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 +213,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 +239,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 +295,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;
@@ -312,6 +342,33 @@ typedef union
     }GunBits;
 }GunErr;
 
+//LWN_Debug
+#ifdef LW_DEBUG_INFO
+typedef union
+{
+    unsigned short infoFlag;
+    struct
+    {
+        unsigned char Index_0:1;
+        unsigned char Index_1:1;
+        unsigned char Index_2:1;
+        unsigned char Index_3:1;
+        unsigned char Index_4:1;
+        unsigned char Index_5:1;
+        unsigned char Index_6:1;
+        unsigned char Index_7:1;
+        unsigned char:8;
+    }Msg;
+
+	struct timespec	Timer_0;
+	struct timespec	Timer_1;
+	struct timespec	Timer_2;
+	struct timespec	Timer_3;
+	struct timespec	Timer_4;
+
+}DebugInfoMsg;
+#endif
+
 struct DcCommonInformation
 {
 	byte rebootCount;
@@ -354,6 +411,30 @@ struct DcCommonInformation
 
 	// auto run flag
 	byte _isAutoRunTest;
+
+	// chademo try to communicaton flag (for tesla adapter)
+	struct ChademoTryCommunicationKey _cha_try_communication[2];
+
+	// for max charging profile
+	float ocppMaxChargingProfilePow;
+
+	// if the psu communication timedout, reset the AC contact for 30s
+	struct timespec _psuComm_time;
+
+	// for reset ev board (GBT or Chademo)
+	byte evBoardResetFlag;
+
+	// balance information
+	struct BalanceInfo balanceInfo;
+
+	// LWN_Zanobe
+	// the autorization state for plug and charge
+	byte PlugAndCharge_AuthStatus;
+
+#ifdef LW_DEBUG_INFO
+	//LWN_Debug
+	DebugInfoMsg DbgInfo;
+#endif
 };
 
 #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));

BIN
EVSE/Projects/DS60-120/Apps/FactoryConfig


+ 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:

BIN
EVSE/Projects/DS60-120/Apps/Module_EvComm


Файлын зөрүү хэтэрхий том тул дарагдсан байна
+ 427 - 418
EVSE/Projects/DS60-120/Apps/Module_EvComm.c


+ 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);

BIN
EVSE/Projects/DS60-120/Apps/Module_EventLogging


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

BIN
EVSE/Projects/DS60-120/Apps/Module_InternalComm


+ 218 - 224
EVSE/Projects/DS60-120/Apps/Module_InternalComm.c

@@ -124,15 +124,15 @@ byte ac_startTransationFlag;
 Relay acOutputRelay;
 
 bool _isOutputNoneMatch[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
-struct timeval _checkOutputNoneMatchTimer[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
+struct timespec _checkOutputNoneMatchTimer[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
 
 //bool _isRelayWelding[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
 //struct timeval _checkRelayWeldingTimer[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
 bool _isOvpChkTimeFlag[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
-struct timeval _checkOutputVolProtectTimer[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
+struct timespec _checkOutputVolProtectTimer[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
 
 // SMR1 *2 + SMR2 * 2 + Parallel * 2
-struct timeval _relayStateChkTimer[6];
+struct timespec _relayStateChkTimer[6];
 
 byte _threePhaseOvp[3] = {0, 0, 0};
 byte _threePhaseUvp[3] = {0, 0, 0};
@@ -144,20 +144,20 @@ char *relayRs485PortName = "/dev/ttyS5";
 unsigned short fanSpeedSmoothValue = 500;
 
 bool isStopChargingCount = false;
-struct timeval _close_ac_contactor;
+struct timespec _close_ac_contactor;
 
-struct timeval _priority_time;
-struct timeval _led_priority_time;
-struct timeval _led_blink_time;
+struct timespec _priority_time;
+struct timespec _led_priority_time;
+struct timespec _led_blink_time;
 
-struct timeval	_ac_charging_comp;
-struct timeval	_ac_preparing;
+struct timespec	_ac_charging_comp;
+struct timespec	_ac_preparing;
 struct timeb 	_ac_startChargingTime;
 struct timeb 	_ac_endChargingTime;
 byte 			_ac_duty;
 
 bool isCriticalStop;
-struct timeval	_psuCriticalStop;
+struct timespec	_psuCriticalStop;
 
 unsigned short _setFanSpeed = 0;
 float _beforeChargingTotalEnergy = 0.0;
@@ -227,18 +227,36 @@ int _alarm_code[] = {L1_AC_OVP, L1_AC_UVP, L1_AC_OCP, AC_OTP, AC_GMI_FAULT, AC_C
 void PRINTF_FUNC(char *string, ...);
 
 int StoreLogMsg(const char *fmt, ...);
-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)
+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, ...)
@@ -848,7 +866,7 @@ void CheckK1K2RelayOutput(byte index)
 //				}
 //				else
 				{
-					if (_chargingData[index]->SystemStatus == S_CCS_PRECHARGE_ST0)
+					if (_chargingData[index]->SystemStatus == SYS_MODE_CCS_PRECHARGE_STEP0)
 						_chargingData[index]->RelayKPK2Status = YES;
 					else
 						_chargingData[index]->RelayKPK2Status = NO;
@@ -869,7 +887,7 @@ void CheckK1K2RelayOutput(byte index)
 //				else
 //					_chargingData[index]->RelayKPK2Status = NO;
 
-				if (_chargingData[index]->SystemStatus == S_CCS_PRECHARGE_ST0)
+				if (_chargingData[index]->SystemStatus == SYS_MODE_CCS_PRECHARGE_STEP0)
 					_chargingData[index]->RelayKPK2Status = YES;
 				else
 					_chargingData[index]->RelayKPK2Status = NO;
@@ -890,7 +908,7 @@ void CheckK1K2RelayOutput(byte index)
 //			else
 //				_chargingData[index]->RelayKPK2Status = NO;
 
-			if (_chargingData[index]->SystemStatus == S_CCS_PRECHARGE_ST0)
+			if (_chargingData[index]->SystemStatus == SYS_MODE_CCS_PRECHARGE_STEP0)
 				_chargingData[index]->RelayKPK2Status = YES;
 			else
 				_chargingData[index]->RelayKPK2Status = NO;
@@ -1109,8 +1127,8 @@ void SetK1K2RelayStatus(byte index)
 		return;
 	}
 
-	if (_chargingData[index]->SystemStatus < S_PREPARING_FOR_EVSE ||
-			_chargingData[index]->SystemStatus == S_FAULT)
+	if (_chargingData[index]->SystemStatus < SYS_MODE_PREPARE_FOR_EVSE ||
+			_chargingData[index]->SystemStatus == SYS_MODE_FAULT)
 	{
 		if (_chargingData[index]->Evboard_id == 0x01)
 		{
@@ -1135,8 +1153,8 @@ void SetK1K2RelayStatus(byte index)
 			}
 		}
 	}
-	else if ((_chargingData[index]->SystemStatus >= S_PREPARING_FOR_EVSE &&
-			_chargingData[index]->SystemStatus <= S_CHARGING))
+	else if ((_chargingData[index]->SystemStatus >= SYS_MODE_PREPARE_FOR_EVSE &&
+			_chargingData[index]->SystemStatus <= SYS_MODE_CHARGING))
 	{
 		//if (_chargingData[index]->RelayWeldingCheck == YES)
 		{
@@ -1156,8 +1174,8 @@ void SetK1K2RelayStatus(byte index)
 			}
 		}
 	}
-	else if (_chargingData[index]->SystemStatus >= S_TERMINATING &&
-			_chargingData[index]->SystemStatus <= S_ALARM)
+	else if (_chargingData[index]->SystemStatus >= SYS_MODE_TERMINATING &&
+			_chargingData[index]->SystemStatus <= SYS_MODE_ALARM)
 	{
 		if ((_chargingData[index]->PresentChargingCurrent * 10) <= SEFETY_SWITCH_RELAY_CUR)
 		{
@@ -1177,7 +1195,7 @@ void SetK1K2RelayStatus(byte index)
 			}
 		}
 	}
-	else if (_chargingData[index]->SystemStatus == S_CCS_PRECHARGE_ST0)
+	else if (_chargingData[index]->SystemStatus == SYS_MODE_CCS_PRECHARGE_STEP0)
 	{
 //		if (_chargingData[index]->Evboard_id == 0x01)
 //		{
@@ -1203,7 +1221,7 @@ void SetK1K2RelayStatus(byte index)
 //			}
 //		}
 	}
-	else if (_chargingData[index]->SystemStatus == S_CCS_PRECHARGE_ST1)
+	else if (_chargingData[index]->SystemStatus == SYS_MODE_CCS_PRECHARGE_STEP1)
 	{
 //		if (_chargingData[index]->Evboard_id == 0x01)
 //		{
@@ -1236,9 +1254,9 @@ void SetParalleRelayStatus()
 	// 之後雙槍單模機種,橋接都會上
 	if (gunCount >= 2 && ShmSysConfigAndInfo->SysInfo.IsAlternatvieConf == NO)
 	{
-		if (_chargingData[0]->SystemStatus == S_BOOTING || _chargingData[1]->SystemStatus == S_BOOTING ||
-				((_chargingData[0]->SystemStatus == S_IDLE || _chargingData[0]->SystemStatus == S_MAINTAIN) &&
-				(_chargingData[1]->SystemStatus == S_IDLE || _chargingData[1]->SystemStatus == S_MAINTAIN)))
+		if (_chargingData[0]->SystemStatus == SYS_MODE_BOOTING || _chargingData[1]->SystemStatus == SYS_MODE_BOOTING ||
+				((_chargingData[0]->SystemStatus == SYS_MODE_IDLE || _chargingData[0]->SystemStatus == SYS_MODE_MAINTAIN) &&
+				(_chargingData[1]->SystemStatus == SYS_MODE_IDLE || _chargingData[1]->SystemStatus == SYS_MODE_MAINTAIN)))
 		{
 			// 初始化~ 不搭橋接
 			if (regRelay.relay_event.bits.Gun1_Parallel_P == YES)
@@ -1395,7 +1413,7 @@ void SetLedColor(struct ChargingInfoData *chargingData_1, struct ChargingInfoDat
 		_colorBuf = COLOR_MAX_LV * LED_INTENSITY_MEDIUM;
 
 	if (ShmSysConfigAndInfo->SysWarningInfo.Level == _ALARM_LEVEL_CRITICAL ||
-			(chargingData_1->SystemStatus == S_UPDATE && chargingData_2->SystemStatus == S_UPDATE))
+			(chargingData_1->SystemStatus == SYS_MODE_UPDATE && chargingData_2->SystemStatus == SYS_MODE_UPDATE))
 	{
 		led_color.Connect_1_Green = COLOR_MIN_LV;
 		led_color.Connect_1_Blue = COLOR_MIN_LV;
@@ -1408,8 +1426,8 @@ void SetLedColor(struct ChargingInfoData *chargingData_1, struct ChargingInfoDat
 	{
 		if (ShmSysConfigAndInfo->SysInfo.IsAlternatvieConf)
 		{
-			if ((chargingData_1->SystemStatus == S_BOOTING || chargingData_1->SystemStatus == S_IDLE || chargingData_1->SystemStatus == S_RESERVATION || chargingData_1->SystemStatus == S_MAINTAIN) &&
-					(chargingData_2->SystemStatus == S_BOOTING || chargingData_2->SystemStatus == S_IDLE || chargingData_2->SystemStatus == S_RESERVATION || chargingData_2->SystemStatus == S_MAINTAIN))
+			if ((chargingData_1->SystemStatus == SYS_MODE_BOOTING || chargingData_1->SystemStatus == SYS_MODE_IDLE || chargingData_1->SystemStatus == SYS_MODE_RESERVATION || chargingData_1->SystemStatus == SYS_MODE_MAINTAIN) &&
+					(chargingData_2->SystemStatus == SYS_MODE_BOOTING || chargingData_2->SystemStatus == SYS_MODE_IDLE || chargingData_2->SystemStatus == SYS_MODE_RESERVATION || chargingData_2->SystemStatus == SYS_MODE_MAINTAIN))
 			{
 				led_color.Connect_1_Green = _colorBuf;
 				led_color.Connect_1_Blue = COLOR_MIN_LV;
@@ -1418,17 +1436,17 @@ void SetLedColor(struct ChargingInfoData *chargingData_1, struct ChargingInfoDat
 				led_color.Connect_2_Blue = COLOR_MIN_LV;
 				led_color.Connect_2_Red = COLOR_MIN_LV;
 
-				if (chargingData_1->SystemStatus == S_RESERVATION ||
-						chargingData_2->SystemStatus == S_RESERVATION)
+				if (chargingData_1->SystemStatus == SYS_MODE_RESERVATION ||
+						chargingData_2->SystemStatus == SYS_MODE_RESERVATION)
 				{
-					if (GetTimeoutValue(_led_blink_time) / 1000 > 3000)
+					if (GetTimeoutValue(&_led_blink_time) > 3)
 					{
 						led_color.Connect_1_Green = COLOR_MIN_LV;
 						led_color.Connect_2_Green = COLOR_MIN_LV;
 					}
 				}
-				else if (chargingData_1->SystemStatus == S_MAINTAIN ||
-						chargingData_2->SystemStatus == S_MAINTAIN)
+				else if (chargingData_1->SystemStatus == SYS_MODE_MAINTAIN ||
+						chargingData_2->SystemStatus == SYS_MODE_MAINTAIN)
 				{
 					led_color.Connect_1_Green = COLOR_MIN_LV;
 					led_color.Connect_2_Green = COLOR_MIN_LV;
@@ -1436,10 +1454,10 @@ void SetLedColor(struct ChargingInfoData *chargingData_1, struct ChargingInfoDat
 					led_color.Connect_2_Red = _colorBuf;
 				}
 			}
-			else if ((chargingData_1->SystemStatus >= S_AUTHORIZING && chargingData_1->SystemStatus <= S_COMPLETE) ||
-				     	(chargingData_1->SystemStatus >= S_CCS_PRECHARGE_ST0 && chargingData_1->SystemStatus <= S_CCS_PRECHARGE_ST1) ||
-						(chargingData_2->SystemStatus >= S_AUTHORIZING && chargingData_2->SystemStatus <= S_COMPLETE) ||
-						(chargingData_2->SystemStatus >= S_CCS_PRECHARGE_ST0 && chargingData_2->SystemStatus <= S_CCS_PRECHARGE_ST1))
+			else if ((chargingData_1->SystemStatus >= SYS_MODE_AUTHORIZING && chargingData_1->SystemStatus <= SYS_MODE_COMPLETE) ||
+				     	(chargingData_1->SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0 && chargingData_1->SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) ||
+						(chargingData_2->SystemStatus >= SYS_MODE_AUTHORIZING && chargingData_2->SystemStatus <= SYS_MODE_COMPLETE) ||
+						(chargingData_2->SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0 && chargingData_2->SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))
 			{
 				led_color.Connect_1_Green = COLOR_MIN_LV;
 				led_color.Connect_1_Blue = _colorBuf;
@@ -1451,30 +1469,30 @@ void SetLedColor(struct ChargingInfoData *chargingData_1, struct ChargingInfoDat
 		}
 		else
 		{
-			if (chargingData_1->SystemStatus == S_BOOTING ||
-					chargingData_1->SystemStatus == S_IDLE ||
-					chargingData_1->SystemStatus == S_RESERVATION ||
-					chargingData_1->SystemStatus == S_MAINTAIN)
+			if (chargingData_1->SystemStatus == SYS_MODE_BOOTING ||
+					chargingData_1->SystemStatus == SYS_MODE_IDLE ||
+					chargingData_1->SystemStatus == SYS_MODE_RESERVATION ||
+					chargingData_1->SystemStatus == SYS_MODE_MAINTAIN)
 			{
 				led_color.Connect_1_Green = _colorBuf;
 				led_color.Connect_1_Blue = COLOR_MIN_LV;
 				led_color.Connect_1_Red = COLOR_MIN_LV;
 
-				if (chargingData_1->SystemStatus == S_RESERVATION)
+				if (chargingData_1->SystemStatus == SYS_MODE_RESERVATION)
 				{
-					if (GetTimeoutValue(_led_blink_time) / 1000 > 3000)
+					if (GetTimeoutValue(&_led_blink_time) > 3)
 					{
 						led_color.Connect_1_Green = COLOR_MIN_LV;
 					}
 				}
-				else if (chargingData_1->SystemStatus == S_MAINTAIN)
+				else if (chargingData_1->SystemStatus == SYS_MODE_MAINTAIN)
 				{
 					led_color.Connect_1_Green = COLOR_MIN_LV;
 					led_color.Connect_1_Red = _colorBuf;
 				}
 			}
-			else if ((chargingData_1->SystemStatus >= S_AUTHORIZING && chargingData_1->SystemStatus <= S_COMPLETE) ||
-						(chargingData_1->SystemStatus >= S_CCS_PRECHARGE_ST0 && chargingData_1->SystemStatus <= S_CCS_PRECHARGE_ST1))
+			else if ((chargingData_1->SystemStatus >= SYS_MODE_AUTHORIZING && chargingData_1->SystemStatus <= SYS_MODE_COMPLETE) ||
+						(chargingData_1->SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0 && chargingData_1->SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))
 			{
 				led_color.Connect_1_Green = COLOR_MIN_LV;
 				led_color.Connect_1_Blue = _colorBuf;
@@ -1482,30 +1500,30 @@ void SetLedColor(struct ChargingInfoData *chargingData_1, struct ChargingInfoDat
 			}
 
 			// --------------------------------------------------------------------------
-			if (chargingData_2->SystemStatus == S_BOOTING ||
-					chargingData_2->SystemStatus == S_IDLE ||
-					chargingData_2->SystemStatus == S_RESERVATION ||
-					chargingData_2->SystemStatus == S_MAINTAIN)
+			if (chargingData_2->SystemStatus == SYS_MODE_BOOTING ||
+					chargingData_2->SystemStatus == SYS_MODE_IDLE ||
+					chargingData_2->SystemStatus == SYS_MODE_RESERVATION ||
+					chargingData_2->SystemStatus == SYS_MODE_MAINTAIN)
 			{
 				led_color.Connect_2_Green = _colorBuf;
 				led_color.Connect_2_Blue = COLOR_MIN_LV;
 				led_color.Connect_2_Red = COLOR_MIN_LV;
 
-				if (chargingData_2->SystemStatus == S_RESERVATION)
+				if (chargingData_2->SystemStatus == SYS_MODE_RESERVATION)
 				{
-					if (GetTimeoutValue(_led_blink_time) / 1000 > 3000)
+					if (GetTimeoutValue(&_led_blink_time) > 3)
 					{
 						led_color.Connect_2_Green = COLOR_MIN_LV;
 					}
 				}
-				else if (chargingData_2->SystemStatus == S_MAINTAIN)
+				else if (chargingData_2->SystemStatus == SYS_MODE_MAINTAIN)
 				{
 					led_color.Connect_2_Green = COLOR_MIN_LV;
 					led_color.Connect_2_Red = _colorBuf;
 				}
 			}
-			else if ((chargingData_2->SystemStatus >= S_AUTHORIZING && chargingData_2->SystemStatus <= S_COMPLETE) ||
-						(chargingData_2->SystemStatus >= S_CCS_PRECHARGE_ST0 && chargingData_2->SystemStatus <= S_CCS_PRECHARGE_ST1))
+			else if ((chargingData_2->SystemStatus >= SYS_MODE_AUTHORIZING && chargingData_2->SystemStatus <= SYS_MODE_COMPLETE) ||
+						(chargingData_2->SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0 && chargingData_2->SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))
 			{
 				led_color.Connect_2_Green = COLOR_MIN_LV;
 				led_color.Connect_2_Blue = _colorBuf;
@@ -1583,7 +1601,6 @@ int InitShareMemory()
 		#endif
 		result = FAIL;
 	}
-	memset(ShmFanModuleData,0,sizeof(struct FanModuleData));
 
 	if ((MeterSMId = shmget(ShmRelayBdKey, sizeof(struct RelayModuleData),  0777)) < 0)
 	{
@@ -1599,7 +1616,6 @@ int InitShareMemory()
 		#endif
 		result = FAIL;
 	}
-	memset(ShmRelayModuleData,0,sizeof(struct RelayModuleData));
 
 	if ((MeterSMId = shmget(ShmLedBdKey, sizeof(struct LedModuleData),  0777)) < 0)
 	{
@@ -1615,7 +1631,6 @@ int InitShareMemory()
 		#endif
 		result = FAIL;
 	}
-	memset(ShmLedModuleData,0,sizeof(struct LedModuleData));
 
 	if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData),  0777)) < 0)
 	{
@@ -1824,18 +1839,18 @@ void StartCheckRelayInfo(byte _chkIndex, byte toState)
 {
 	if (ShmDcCommonData->RelayCheckStatus[_chkIndex] == STOP)
 	{
-		gettimeofday(&_relayStateChkTimer[_chkIndex], NULL);
+		GetTimespecFunc(&_relayStateChkTimer[_chkIndex]);
 		ShmDcCommonData->RelayCheckStatus[_chkIndex] = START;
 	}
 	else
 	{
-		unsigned long _timebuf = GetTimeoutValue(_relayStateChkTimer[_chkIndex]);
+		int _timebuf = GetTimeoutValue(&_relayStateChkTimer[_chkIndex]);
 
 		if (_timebuf < 0)
-			gettimeofday(&_relayStateChkTimer[_chkIndex], NULL);
+			GetTimespecFunc(&_relayStateChkTimer[_chkIndex]);
 		else
 		{
-			if ((_timebuf / 1000) > RELAY_CHECK_TIME * 1000)
+			if (_timebuf > RELAY_CHECK_TIME)
 			{
 				//PRINTF_FUNC ("relay welding or driving fault = %d \n", _chkIndex);
 				if (toState == 1)
@@ -2007,20 +2022,20 @@ void CableCheckDetected(byte index)
 	if ((_chargingData[index]->Type >= _Type_Chademo && _chargingData[index]->Type <= _Type_GB) ||
 			(_chargingData[index]->Type == 0x09 && ShmSysConfigAndInfo->SysConfig.AlwaysGfdFlag))
 	{
-		if ((_chargingData[index]->SystemStatus >= S_PREPARING_FOR_EVSE && _chargingData[index]->SystemStatus < S_TERMINATING) ||
-			(_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_TERMINATING) ||
+			(_chargingData[index]->SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0 && _chargingData[index]->SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))
 		{
-			if (_chargingData[index]->SystemStatus == S_PREPARING_FOR_EVSE)
+			if (_chargingData[index]->SystemStatus == SYS_MODE_PREPARE_FOR_EVSE)
 			{
 				SetGfdConfig(index, GFD_CABLECHK);
 			}
-			else if (_chargingData[index]->SystemStatus >= S_CCS_PRECHARGE_ST0 &&
-					_chargingData[index]->SystemStatus <= S_CCS_PRECHARGE_ST1)
+			else if (_chargingData[index]->SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0 &&
+					_chargingData[index]->SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1)
 			{
 				SetGfdConfig(index, GFD_PRECHARGE);
 			}
-			else if (_chargingData[index]->SystemStatus >= S_CHARGING &&
-					_chargingData[index]->SystemStatus < S_TERMINATING)
+			else if (_chargingData[index]->SystemStatus >= SYS_MODE_CHARGING &&
+					_chargingData[index]->SystemStatus < SYS_MODE_TERMINATING)
 			{
 				if (_chargingData[index]->Type == _Type_GB || _chargingData[index]->Type == _Type_Chademo)
 					SetGfdConfig(index, GFD_IDLE);
@@ -2052,7 +2067,7 @@ void CheckOutputPowerOverCarReq(byte index)
 			{
 				if ((_chargingData[index]->PresentChargingVoltage * 10) >= VOUT_MIN_VOLTAGE * 10)
 				{
-					gettimeofday(&_checkOutputVolProtectTimer[index], NULL);
+					GetTimespecMFunc(&_checkOutputVolProtectTimer[index]);
 					_isOvpChkTimeFlag[index] = YES;
 					PRINTF_FUNC("First time : CheckOutputPowerOverCarReq NG : fire = %f, req = %f, max-battery = %f \n",
 							_chargingData[index]->FireChargingVoltage, (_chargingData[index]->EvBatterytargetVoltage * 10), carV);
@@ -2060,13 +2075,13 @@ void CheckOutputPowerOverCarReq(byte index)
 			}
 			else
 			{
-				unsigned long _timebuf = GetTimeoutValue(_checkOutputVolProtectTimer[index]);
+				int _timebuf = GetTimeoutMValue(&_checkOutputVolProtectTimer[index]);
 
 				if (_timebuf < 0)
-					gettimeofday(&_checkOutputVolProtectTimer[index], NULL);
+					GetTimespecMFunc(&_checkOutputVolProtectTimer[index]);
 				else
 				{
-					if ((GetTimeoutValue(_checkOutputVolProtectTimer[index]) / 1000) >= OUTPUT_VOL_CHK_TIME)
+					if (GetTimeoutMValue(&_checkOutputVolProtectTimer[index]) >= OUTPUT_VOL_CHK_TIME)
 					{
 						PRINTF_FUNC("[Module_InternalComm]CheckOutputPowerOverCarReq NG : fire = %f, req = %f, max-battery = %f \n",
 								_chargingData[index]->FireChargingVoltage, (_chargingData[index]->EvBatterytargetVoltage * 10), carV);
@@ -2102,77 +2117,49 @@ void CheckOutputPowerOverCarReq(byte index)
 	}
 }
 
-//void CheckOutputVolNoneMatchFire(byte index)
-//{
-//	if ((_chargingData[index]->EvBatterytargetVoltage * 10) > 1500 &&
-//			(_chargingData[index]->Type == _Type_Chademo ||
-//					_chargingData[index]->Type == _Type_CCS_2 ||
-//					_chargingData[index]->Type == _Type_GB))
-//	{
-//		if (((_chargingData[index]->PresentChargingVoltage * 10) < _chargingData[index]->FireChargingVoltage - 300) ||
-//				((_chargingData[index]->PresentChargingVoltage * 10) > _chargingData[index]->FireChargingVoltage + 300))
-//		{
-//			if (!_isOutputNoneMatch[index])
-//			{
-//				_isOutputNoneMatch[index] = YES;
-//				gettimeofday(&_checkOutputNoneMatchTimer[index], NULL);
-//			}
-//			else
-//			{
-//				if ((GetTimeoutValue(_checkOutputNoneMatchTimer[index]) / 1000) >= 5000)
-//				{
-//					PRINTF_FUNC("[Module_InternalComm]CheckOutputVolNoneMatchFire NG (%d) : pre = %f, fire = %f \n",
-//							index, (_chargingData[index]->PresentChargingVoltage * 10), _chargingData[index]->FireChargingVoltage);
-//					DEBUG_ERROR("[Module_InternalComm]CheckOutputVolNoneMatchFire NG (%d): pre = %f, fire = %f \n",
-//							index, (_chargingData[index]->PresentChargingVoltage * 10), _chargingData[index]->FireChargingVoltage);
-//
-//					if (_chargingData[index]->Type == _Type_Chademo)
-//						ShmStatusCodeData->FaultCode.FaultEvents.bits.ChademoOutputRelayDrivingFault = YES;
-//					else if (_chargingData[index]->Type == _Type_GB)
-//						ShmStatusCodeData->FaultCode.FaultEvents.bits.GbOutputRelayDrivingFault = YES;
-//					else if (_chargingData[index]->Type == _Type_CCS_2)
-//						ShmStatusCodeData->FaultCode.FaultEvents.bits.CcsOutputRelayDrivingFault = YES;
-//
-//					_chargingData[index]->StopChargeFlag = YES;
-//				}
-//			}
-//		}
-//		else
-//			_isOutputNoneMatch[index] = NO;
-//	}
-//}
-
-void CheckRelayWeldingStatus(byte index)
+void CheckOutputVolNoneMatchFire(byte index)
 {
-//	if (!_isRelayWelding[index])
-//	{
-//		if ((_chargingData[index]->PresentChargingVoltage * 10) >= VOUT_MIN_VOLTAGE * 10)
-//		{
-//			gettimeofday(&_checkRelayWeldingTimer[index], NULL);
-//			_isRelayWelding[index] = YES;
-//		}
-//	}
-//	else
-//	{
-//		if ((GetTimeoutValue(_checkRelayWeldingTimer[index]) / 1000) >= 1000)
-//		{
-//			_chargingData[index]->RelayWeldingCheck = YES;
-//			return;
-//		}
-//
-//		if (_chargingData[index]->FireChargingVoltage >= VOUT_MIN_VOLTAGE)
-//		{
-//			if (_chargingData[index]->Type == _Type_Chademo)
-//				ShmStatusCodeData->FaultCode.FaultEvents.bits.ChademoOutputRelayWelding = YES;
-//			else if (_chargingData[index]->Type == _Type_GB)
-//				ShmStatusCodeData->FaultCode.FaultEvents.bits.GbOutputRelayWelding = YES;
-//			else if (_chargingData[index]->Type == _Type_CCS_2)
-//				ShmStatusCodeData->FaultCode.FaultEvents.bits.CcsOutputRelayWelding = YES;
-//
-//			PRINTF_FUNC("CheckRelayWeldingStatus : fail \n");
-//			_chargingData[index]->StopChargeFlag = YES;
-//		}
-//	}
+	if (((_chargingData[index]->EvBatterytargetVoltage * 10) > 1500 ||
+			_chargingData[index]->RelayK1K2Status == NO) &&
+			(_chargingData[index]->Type == _Type_Chademo ||
+					_chargingData[index]->Type == _Type_CCS ||
+					_chargingData[index]->Type == _Type_GB))
+	{
+		if (((_chargingData[index]->PresentChargingVoltage * 10) < _chargingData[index]->FireChargingVoltage - 300) ||
+				((_chargingData[index]->PresentChargingVoltage * 10) > _chargingData[index]->FireChargingVoltage + 300))
+		{
+			if (!_isOutputNoneMatch[index])
+			{
+				_isOutputNoneMatch[index] = YES;
+				GetTimespecFunc(&_checkOutputNoneMatchTimer[index]);
+			}
+			else
+			{
+				if (GetTimeoutValue(&_checkOutputNoneMatchTimer[index]) >= 2)
+				{
+					PRINTF_FUNC("Abnormal voltage on the Output at the stage of GFD. (%d) : pre = %.1f, fire = %.1f \n",
+							index, (_chargingData[index]->PresentChargingVoltage * 10), _chargingData[index]->FireChargingVoltage);
+
+					if (index == 0)
+					{
+						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.AbnormalVoltageOnOutputLine_1 = YES;
+						if (strncmp((char *)_chargingData[index]->ConnectorAlarmCode, "", 6) == EQUAL)
+								memcpy(_chargingData[index]->ConnectorAlarmCode, "012324", 6);
+					}
+					else if (index == 1)
+					{
+						ShmStatusCodeData->AlarmCode.AlarmEvents.bits.AbnormalVoltageOnOutputLine_2 = YES;
+						if (strncmp((char *)_chargingData[index]->ConnectorAlarmCode, "", 6) == EQUAL)
+								memcpy(_chargingData[index]->ConnectorAlarmCode, "012325", 6);
+					}
+
+					_chargingData[index]->StopChargeFlag = YES;
+				}
+			}
+		}
+		else
+			_isOutputNoneMatch[index] = NO;
+	}
 }
 
 void GetPsuTempForFanSpeed()
@@ -2336,11 +2323,11 @@ unsigned char GetAcChargingCurrent()
 
 void ChangeLedStatus()
 {
-	if (ac_chargingInfo[0]->SystemStatus == S_IDLE)
+	if (ac_chargingInfo[0]->SystemStatus == SYS_MODE_IDLE)
 		ledStatus.ActionMode = 1;
-	else if (ac_chargingInfo[0]->SystemStatus == S_PREPARNING)
+	else if (ac_chargingInfo[0]->SystemStatus == SYS_MODE_PREPARING)
 		ledStatus.ActionMode = 3;
-	else if (ac_chargingInfo[0]->SystemStatus == S_CHARGING)
+	else if (ac_chargingInfo[0]->SystemStatus == SYS_MODE_CHARGING)
 		ledStatus.ActionMode = 4;
 
 	Config_LED_Status(Uart5Fd, Addr.AcPlug, &ledStatus);
@@ -2658,42 +2645,42 @@ void AcChargeTypeProcess()
 
 			if (ac_chargingInfo[0]->IsAvailable == NO)
 			{
-				_status = S_MAINTAIN;
+				_status = SYS_MODE_MAINTAIN;
 			}
 
 			//printf("SystemStatus = %d, err = %d \n", ac_chargingInfo[0]->SystemStatus, ac_chargingInfo[0]->IsErrorOccur);
-			if ((ac_chargingInfo[0]->SystemStatus == S_IDLE || ac_chargingInfo[0]->SystemStatus == S_MAINTAIN) &&
+			if ((ac_chargingInfo[0]->SystemStatus == SYS_MODE_IDLE || ac_chargingInfo[0]->SystemStatus == SYS_MODE_MAINTAIN) &&
 					ac_chargingInfo[0]->IsErrorOccur)
 			{
-				_status = S_FAULT;
+				_status = SYS_MODE_FAULT;
 			}
-			else if (_status == S_MAINTAIN)
+			else if (_status == SYS_MODE_MAINTAIN)
 			{
 				// do nothing
 			}
 			else if (acStatus.CpStatus == AC_SYS_A)
 			{
 				if (ac_chargingInfo[0]->IsErrorOccur &&
-						(ac_chargingInfo[0]->SystemStatus >= S_PREPARNING ||
-						ac_chargingInfo[0]->SystemStatus <= S_CHARGING))
-					_status = S_ALARM;
+						(ac_chargingInfo[0]->SystemStatus >= SYS_MODE_PREPARING ||
+						ac_chargingInfo[0]->SystemStatus <= SYS_MODE_CHARGING))
+					_status = SYS_MODE_ALARM;
 				else if (!ac_chargingInfo[0]->IsErrorOccur &&
-						(ac_chargingInfo[0]->SystemStatus >= S_TERMINATING ||
-						ac_chargingInfo[0]->SystemStatus <= S_ALARM))
+						(ac_chargingInfo[0]->SystemStatus >= SYS_MODE_TERMINATING ||
+						ac_chargingInfo[0]->SystemStatus <= SYS_MODE_ALARM))
 				{
-					if (GetTimeoutValue(_ac_charging_comp) >= 10000000 && acStatus.CpStatus == AC_SYS_A)
-						_status = S_IDLE;
+					if (GetTimeoutValue(&_ac_charging_comp) >= 10 && acStatus.CpStatus == AC_SYS_A)
+						_status = SYS_MODE_IDLE;
 				}
 //				else
-//					_status = S_IDLE;
+//					_status = SYS_MODE_IDLE;
 			}
-			else if (ac_chargingInfo[0]->SystemStatus >= S_PREPARNING &&
-					ac_chargingInfo[0]->SystemStatus < S_CHARGING)
+			else if (ac_chargingInfo[0]->SystemStatus >= SYS_MODE_PREPARING &&
+					ac_chargingInfo[0]->SystemStatus < SYS_MODE_CHARGING)
 			{
 				if (acStatus.CpStatus == AC_SYS_C)
-					_status = S_CHARGING;
-				else if (GetTimeoutValue(_ac_preparing) >= 120000000)
-					_status = S_IDLE;
+					_status = SYS_MODE_CHARGING;
+				else if (GetTimeoutValue(&_ac_preparing) >= 120)
+					_status = SYS_MODE_IDLE;
 			}
 			else if ((acStatus.CpStatus == AC_SYS_B || ac_chargingInfo[0]->ConnectorPlugIn == AC_SYS_B) &&
 					ac_chargingInfo[0]->IsAvailable &&
@@ -2707,7 +2694,7 @@ void AcChargeTypeProcess()
 					ac_chargingInfo[0]->RemoteStartFlag = NO;
 					strcpy((char *)ac_chargingInfo[0]->StartUserId, "");
 					ShmSysConfigAndInfo->SysInfo.WaitForPlugit = NO;
-					_status = S_PREPARNING;
+					_status = SYS_MODE_PREPARING;
 				}
 				else if (ShmSysConfigAndInfo->SysInfo.OrderCharging == NO_DEFINE)
 				{
@@ -2716,22 +2703,22 @@ void AcChargeTypeProcess()
 					PRINTF_FUNC("** CardNumber = %s \n", ac_chargingInfo[0]->StartUserId);
 					strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
 					ShmSysConfigAndInfo->SysInfo.WaitForPlugit = NO;
-					_status = S_PREPARNING;
+					_status = SYS_MODE_PREPARING;
 				}
 			}
 
-			if (ac_chargingInfo[0]->SystemStatus == S_PREPARNING ||
-					ac_chargingInfo[0]->SystemStatus == S_CHARGING)
+			if (ac_chargingInfo[0]->SystemStatus == SYS_MODE_PREPARING ||
+					ac_chargingInfo[0]->SystemStatus == SYS_MODE_CHARGING)
 			{
 				if (ocpp_ac_remoteStopReq_cmd())
 				{
 					ocpp_ac_set_stopReason_by_cmd("Remote");
-					_status = S_TERMINATING;
+					_status = SYS_MODE_TERMINATING;
 				}
 				else if (ac_chargingInfo[0]->StopChargeFlag ||
 						acStatus.CpStatus == AC_SYS_F)
 				{
-					_status = S_TERMINATING;
+					_status = SYS_MODE_TERMINATING;
 				}
 			}
 
@@ -2755,17 +2742,18 @@ void AcChargeTypeProcess()
 			// 設定限制最大充電電流 >= 6 ~ <= 32
 			switch(ac_chargingInfo[0]->SystemStatus)
 			{
-				case S_IDLE:
-				case S_MAINTAIN:
-				case S_FAULT:
+				case SYS_MODE_IDLE:
+				case SYS_MODE_MAINTAIN:
+				case SYS_MODE_RESERVATION:
+				case SYS_MODE_FAULT:
 				{
 					if (isModeChange())
 					{
-						if (ac_chargingInfo[0]->SystemStatus == S_IDLE)
+						if (ac_chargingInfo[0]->SystemStatus == SYS_MODE_IDLE)
 							PRINTF_FUNC("================== S_IDLE (AC Gun) ================ \n");
-						else if (ac_chargingInfo[0]->SystemStatus == S_MAINTAIN)
+						else if (ac_chargingInfo[0]->SystemStatus == SYS_MODE_MAINTAIN)
 							PRINTF_FUNC("================== S_MAINTAIN (AC Gun) ================ \n");
-						else if (ac_chargingInfo[0]->SystemStatus == S_FAULT)
+						else if (ac_chargingInfo[0]->SystemStatus == SYS_MODE_FAULT)
 							PRINTF_FUNC("================== S_FAULT (AC Gun) ================ \n");
 
 						SetCpDuty(100);
@@ -2785,7 +2773,7 @@ void AcChargeTypeProcess()
 					ChangeLedStatus();
 				}
 					break;
-				case S_PREPARNING:
+				case SYS_MODE_PREPARING:
 				{
 					if (isModeChange())
 					{
@@ -2796,7 +2784,7 @@ void AcChargeTypeProcess()
 						ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc = DEFAULT_AC_INDEX;
 						if (ShmSysConfigAndInfo->SysInfo.OrderCharging != NO_DEFINE)
 							ShmSysConfigAndInfo->SysInfo.OrderCharging = NO_DEFINE;
-						gettimeofday(&_ac_preparing, NULL);
+						GetTimespecFunc(&_ac_preparing);
 					}
 
 					if (GetChargingEnergy() == PASS)
@@ -2836,7 +2824,7 @@ void AcChargeTypeProcess()
 							SetCpDuty(ShmSysConfigAndInfo->SysConfig.AcMaxChargingCurrent);
 					}
 					else if (ac_startTransationFlag == START_TRANSATION_STATUS_FAIL ||
-							(ac_startTransationFlag == START_TRANSATION_STATUS_WAIT && (GetTimeoutValue(_ac_preparing) / 1000) > 10000))
+							(ac_startTransationFlag == START_TRANSATION_STATUS_WAIT && GetTimeoutValue(&_ac_preparing) > 10))
 					{
 						PRINTF_FUNC("StartTransaction Fail / Timeout. \n");
 						ac_chargingInfo[0]->StopChargeFlag = YES;
@@ -2844,7 +2832,7 @@ void AcChargeTypeProcess()
 					ChangeLedStatus();
 				}
 					break;
-				case S_CHARGING:
+				case SYS_MODE_CHARGING:
 				{
 					if (isModeChange())
 					{
@@ -2919,25 +2907,25 @@ void AcChargeTypeProcess()
 					ChangeLedStatus();
 				}
 					break;
-				case S_TERMINATING:
-				case S_ALARM:
+				case SYS_MODE_TERMINATING:
+				case SYS_MODE_ALARM:
 				{
 					//ocpp_set_errCode_cmd
 					if (isModeChange())
 					{
-						if (ac_chargingInfo[0]->SystemStatus == S_TERMINATING)
+						if (ac_chargingInfo[0]->SystemStatus == SYS_MODE_TERMINATING)
 							PRINTF_FUNC("================== S_TERMINATING (AC Gun) ================ \n");
-						else if (ac_chargingInfo[0]->SystemStatus == S_ALARM)
+						else if (ac_chargingInfo[0]->SystemStatus == SYS_MODE_ALARM)
 							PRINTF_FUNC("================== S_ALARM (AC Gun) ================ \n");
 
 						ChangeStartOrStopDateTime(NO);
-						gettimeofday(&_ac_charging_comp, NULL);
+						GetTimespecFunc(&_ac_charging_comp);
 						ocpp_ac_set_stopReason_by_cmd("Local");
 						SetCpDuty(100);
 
-						if (ac_chargingInfo[0]->SystemStatus == S_TERMINATING)
+						if (ac_chargingInfo[0]->SystemStatus == SYS_MODE_TERMINATING)
 							PRINTF_FUNC("================== S_TERMINATING (AC Gun) ================ \n");
-						else if (ac_chargingInfo[0]->SystemStatus == S_ALARM)
+						else if (ac_chargingInfo[0]->SystemStatus == SYS_MODE_ALARM)
 						{
 							ftime(&_ac_endChargingTime);
 
@@ -2954,8 +2942,8 @@ void AcChargeTypeProcess()
 					SetLegacyReq(NO);
 					if (acStatus.RelayStatus == NO)
 					{
-						if (ac_chargingInfo[0]->SystemStatus == S_TERMINATING)
-							ac_chargingInfo[0]->SystemStatus = S_COMPLETE;
+						if (ac_chargingInfo[0]->SystemStatus == SYS_MODE_TERMINATING)
+							ac_chargingInfo[0]->SystemStatus = SYS_MODE_COMPLETE;
 					}
 					else
 					{
@@ -2964,17 +2952,17 @@ void AcChargeTypeProcess()
 						SetAcModuleRelay(NO);
 					}
 
-					if (ac_chargingInfo[0]->SystemStatus == S_ALARM)
+					if (ac_chargingInfo[0]->SystemStatus == SYS_MODE_ALARM)
 						ac_chargingInfo[0]->PresentChargedDuration = DiffTimeb(_ac_startChargingTime, _ac_endChargingTime);
 				}
 					break;
-				case S_COMPLETE:
+				case SYS_MODE_COMPLETE:
 				{
 					if (isModeChange())
 					{
 						PRINTF_FUNC("================== S_COMPLETE (AC Gun) ================ \n");
 
-						gettimeofday(&_ac_charging_comp, NULL);
+						GetTimespecFunc(&_ac_charging_comp);
 						ftime(&_ac_endChargingTime);
 						ocpp_ac_set_errCode_cmd();
 						if (strcmp((char *)ac_chargingInfo[0]->StartDateTime, "") != EQUAL)
@@ -2999,17 +2987,17 @@ void RunForceStopProcess()
 	if (isCriticalStop == NO)
 	{
 		isCriticalStop = YES;
-		gettimeofday(&_psuCriticalStop, NULL);
+		GetTimespecFunc(&_psuCriticalStop);
 	}
 	else
 	{
-		unsigned long _timebuf = GetTimeoutValue(_psuCriticalStop);
+		int _timebuf = GetTimeoutValue(&_psuCriticalStop);
 
 		if (_timebuf < 0)
-			gettimeofday(&_psuCriticalStop, NULL);
+			GetTimespecFunc(&_psuCriticalStop);
 		else
 		{
-			if (_timebuf / 1000 >= (FORCE_STOP_TIME * 1000))
+			if (_timebuf >= FORCE_STOP_TIME)
 			{
 				isCriticalStop = NO;
 				ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuFailureAlarm = NORMAL;
@@ -3074,7 +3062,7 @@ int main(void)
 
 	relayMatchFlag = NO;
 	isCriticalStop = NO;
-	gettimeofday(&_led_blink_time, NULL);
+	GetTimespecFunc(&_led_blink_time);
 	for(;;)
 	{
 		bool isCharging = false;
@@ -3093,7 +3081,7 @@ int main(void)
 			SetModelName_Fan();
 			SetRtcData_Fan();
 			sleep(1);
-			gettimeofday(&_priority_time, NULL);
+			GetTimespecFunc(&_priority_time);
 		}
 
 		// 自檢階段處理,自檢階段如果讀不到版號則代表該系統沒有掛燈板
@@ -3104,7 +3092,7 @@ int main(void)
 			{
 				GetFwAndHwVersion_Led();
 				sleep(1);
-				gettimeofday(&_led_priority_time, NULL);
+				GetTimespecFunc(&_led_priority_time);
 			}
 			else
 			{
@@ -3140,27 +3128,31 @@ int main(void)
 				// 依據當前各槍的狀態選擇 搭上/放開 Relay
 				SetK1K2RelayStatus(i);
 
-				if (_chargingData[i]->SystemStatus == S_IDLE ||
-						_chargingData[i]->SystemStatus == S_RESERVATION ||
-						_chargingData[i]->SystemStatus == S_MAINTAIN)
+				if (_chargingData[i]->SystemStatus == SYS_MODE_IDLE ||
+						_chargingData[i]->SystemStatus == SYS_MODE_RESERVATION ||
+						_chargingData[i]->SystemStatus == SYS_MODE_MAINTAIN)
 				{
-					//_chargingData[i]->RelayWeldingCheck = NO;
 					_isOvpChkTimeFlag[i] = NO;
 				}
 
-				if (_chargingData[i]->SystemStatus == S_BOOTING	||
-					(_chargingData[i]->SystemStatus >= S_REASSIGN_CHECK && _chargingData[i]->SystemStatus <= S_COMPLETE) ||
-					(_chargingData[i]->SystemStatus >= S_CCS_PRECHARGE_ST0 && _chargingData[i]->SystemStatus <= S_CCS_PRECHARGE_ST1) ||
+				if (_chargingData[i]->SystemStatus == SYS_MODE_BOOTING	||
+					(_chargingData[i]->SystemStatus >= SYS_MODE_MODE_REASSIGN_CHECK && _chargingData[i]->SystemStatus <= SYS_MODE_COMPLETE) ||
+					(_chargingData[i]->SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0 && _chargingData[i]->SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) ||
 					ShmSysConfigAndInfo->SysInfo.WaitForPlugit == YES ||
 					(ShmSysConfigAndInfo->SysInfo.PageIndex >= _LCM_AUTHORIZING && ShmSysConfigAndInfo->SysInfo.PageIndex <= _LCM_WAIT_FOR_PLUG))
 				{
 					_chargingData[i]->IsReadyToCharging = YES;
 					isCharging = true;
 
-					if (_chargingData[i]->SystemStatus == S_CHARGING)
+					if (_chargingData[i]->SystemStatus == SYS_MODE_CHARGING)
 					{
-						CheckOutputPowerOverCarReq(i);    // load dump
-						//CheckOutputVolNoneMatchFire(i);
+						// OVP
+						CheckOutputPowerOverCarReq(i);
+					}
+					else if (_chargingData[i]->SystemStatus == SYS_MODE_PREPARE_FOR_EVSE)
+					{
+						// abnormal voltage at the stage of GFD
+						CheckOutputVolNoneMatchFire(i);
 					}
 					else
 						_isOutputNoneMatch[i] = NO;
@@ -3189,12 +3181,12 @@ int main(void)
 			{
 				if (!isStopChargingCount)
 				{
-					gettimeofday(&_close_ac_contactor, NULL);
+					GetTimespecFunc(&_close_ac_contactor);
 					isStopChargingCount = true;
 				}
 				else
 				{
-					if ((outputRelay.relay_event.bits.AC_Contactor == YES && GetTimeoutValue(_close_ac_contactor) / 1000 >= (TEN_MINUTES * 1000)))
+					if ((outputRelay.relay_event.bits.AC_Contactor == YES && GetTimeoutValue(&_close_ac_contactor) >= TEN_MINUTES))
 						outputRelay.relay_event.bits.AC_Contactor = NO;
 				}
 			}
@@ -3214,9 +3206,11 @@ int main(void)
 				outputRelay.relay_event.bits.Gun1_N = outputRelay.relay_event.bits.Gun1_P = YES;
 
 			// 搭上/鬆開 Relay
+
 			if(IsNoneMatchRelayStatus())
 			{
 				relayMatchFlag = NO;
+
 				if (Config_Relay_Output(Uart5Fd, Addr.Relay, &outputRelay))
 				{
 					//regRelay.relay_event.bits.AC_Contactor = ShmSysConfigAndInfo->SysInfo.AcContactorStatus;
@@ -3282,19 +3276,19 @@ int main(void)
 		{
 			ShmFanModuleData->SelfTest_Comp = YES;
 
-			unsigned long _timebuf = GetTimeoutValue(_priority_time);
+			int _timebuf = GetTimeoutValue(&_priority_time);
 
 			if (_timebuf < 0)
-				gettimeofday(&_priority_time, NULL);
+				GetTimespecFunc(&_priority_time);
 			else
 			{
-				if (_timebuf / 1000 >= 1000)
+				if (_timebuf >= 1)
 				{
 					//GetPsuTempForFanSpeed();
 					GetFanSpeedByFunction();
 					GetFanSpeed();
 					ShmSysConfigAndInfo->SysInfo.SystemFanRotaSpeed = _setFanSpeed;
-					gettimeofday(&_priority_time, NULL);
+					GetTimespecFunc(&_priority_time);
 
 					ShmFanModuleData->SetFan1Speed = ShmFanModuleData->TestFanSpeed;
 					ShmFanModuleData->SetFan2Speed = ShmFanModuleData->TestFanSpeed;
@@ -3309,15 +3303,15 @@ int main(void)
 
 		if (ShmLedModuleData->SelfTest_Comp == YES)
 		{
-			unsigned long _timebuf = GetTimeoutValue(_led_priority_time);
+			int _timebuf = GetTimeoutValue(&_led_priority_time);
 			if (_timebuf < 0)
-				gettimeofday(&_led_priority_time, NULL);
+				GetTimespecFunc(&_led_priority_time);
 			else
 			{
-				if (GetTimeoutValue(_led_blink_time) / 1000 > 6000)
-					gettimeofday(&_led_blink_time, NULL);
+				if (GetTimeoutValue(&_led_blink_time) > 6)
+					GetTimespecFunc(&_led_blink_time);
 
-				if (_timebuf / 1000 >= 1000)
+				if (_timebuf >= 1)
 				{
 					if(gunCount == 1)
 					{
@@ -3328,7 +3322,7 @@ int main(void)
 						SetLedColor(_chargingData[0], _chargingData[1]);
 					}
 
-					gettimeofday(&_led_priority_time, NULL);
+					GetTimespecFunc(&_led_priority_time);
 				}
 			}
 		}

BIN
EVSE/Projects/DS60-120/Apps/Module_LcmControl


+ 465 - 37
EVSE/Projects/DS60-120/Apps/Module_LcmControl.c

@@ -1,4 +1,20 @@
 #include "Module_LcmContro.h"
+#include "cbmp.h"
+
+#define CMD_HEADER_1						0x5A
+#define CMD_HEADER_2						0xA5
+#define CMD_REG_WRITE						0x80
+#define CMD_REG_READ						0x81
+#define CMD_REG_WRITE_DATA					0x82
+#define CMD_REG_READ_DATA					0x83
+
+#define REG_ADDRESS_READ_VERSION			0x0F
+#define REG_ADDRESS_READ_RTC				0x10
+#define REG_ADDRESS_READ_PAGE_ID			0x14
+#define REG_ADDRESS_READ_BRIGHTNESS       	0x31
+#define REG_ADDRESS_WRITE_BRIGHTNESS		0X82
+#define REG_ADDRESS_SET_PAGE_ID				0x84
+#define REG_ADDRESS_SET_RTC					0x9C
 
 bool needReloadQr = true;
 
@@ -778,12 +794,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 +879,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 +1352,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 +1382,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 +1471,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 +1640,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 +1695,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 +1723,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)
+	{
+		ShmDcCommonData->_hour_index = tmCSU->tm_hour;
+		ShmSysConfigAndInfo->SysConfig.BillingData.Cur_fee = ShmSysConfigAndInfo->SysConfig.BillingData.Fee[tmCSU->tm_hour];
+		DisplayMoneyRate(ShmSysConfigAndInfo->SysConfig.BillingData.Cur_fee);
+	}
+
+	if (ShmSysConfigAndInfo->SysConfig.BillingData.Currency <= 53)
 	{
-		struct timeb csuTime;
-		struct tm *tmCSU;
+		DisplayMoneyCur((byte *)Currency[ShmSysConfigAndInfo->SysConfig.BillingData.Currency]);
+	}
+}
 
-		ftime(&csuTime);
-		tmCSU = localtime(&csuTime.time);
+void ChangeDisplayMoneyInfo()
+{
+	struct timeb csuTime;
+	struct tm *tmCSU;
 
-		ChangeDisplay2Value(__money_rate_map, _charging_money);
+	ftime(&csuTime);
+	tmCSU = localtime(&csuTime.time);
 
-		if (tmCSU->tm_hour <= 23)
+	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,16 +1900,305 @@ 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);
 	}
 }
 
+//=======================================
+// Download image
+//=======================================
+//char lcdRegisterWrite(byte command, short address, byte *data, byte len)
+//{
+//	byte cmd[256];
+//	memset(cmd, 0x00, sizeof(cmd));
+//	char result = FAIL;
+//
+//	cmd[0] = CMD_TITLE_1;
+//	cmd[1] = CMD_TITLE_2;
+//	cmd[2] = 0x03 + len;
+//	cmd[3] = command;
+//	cmd[4] = address >> 8;
+//	cmd[5] = address & 0x00FF;
+//
+//	for(byte count = 0; count < len; count++)
+//	{
+//		cmd[6 + count] = *(data + count);
+//	}
+//
+//	//WriteCmdToLcm(cmd, cmd[2] + 3);
+//	int slen = write(Uart1Fd, cmd, cmd[2] + 3);
+//	printf("%d \n", slen);
+//	if(slen >= cmd[2] + 3)
+//	{
+//		printf("Pass. \n");
+//		result = PASS;
+//	}
+//	else
+//	{
+//		result = FAIL;
+//		printf("Fail. \n");
+//	}
+//
+//	return result;
+//}
+
+void displayMessageDgus(uint8_t *data, uint16_t len, uint8_t isRX)
+{
+	uint8_t output[8192];
+
+	memset(output, 0x00, ARRAY_SIZE(output));
+	sprintf((char*)output, "%s", (isRX?"RX: ":"TX: "));
+	for(uint16_t idx = 0;idx<len;idx++)
+	{
+		sprintf((char*)output, "%s%02x ", output, data[idx]);
+	}
+
+	#ifdef isDebugPrint
+	DEBUG_INFO("%s\n", output);
+	#endif
+}
+
+int transceiverDgus(int32_t fd, uint8_t *tx, uint16_t tx_len, uint8_t *rx, uint16_t rx_len)
+{
+	int result = FAIL;
+	int len;
+
+	tcflush(fd,TCIOFLUSH);
+
+	#ifdef isDebugPrint
+	displayMessageDgus(tx, tx_len, NO);
+	#endif
+
+	usleep(10000);
+
+	if(write(fd, tx, tx_len) >= ARRAY_SIZE(tx))
+	{
+		if(tx[3] == CMD_REG_WRITE_DATA)
+		{
+			len = read(fd, rx, rx_len);
+			if(len > 0)
+			{
+				if((rx[0] == CMD_HEADER_1) && (rx[1] == CMD_HEADER_2))
+				{
+					if((rx[3] == CMD_REG_WRITE_DATA) && (rx[4] == 0x4f) && (rx[5] == 0x4b))
+					{
+						displayMessageDgus(rx, len, YES);
+						result = PASS;
+					}
+				}
+			}
+		}
+		else if(tx[3] == CMD_REG_READ_DATA)
+		{
+			len = read(fd, rx, rx_len);
+			if(len > 0)
+			{
+				if((rx[0] == CMD_HEADER_1) && (rx[1] == CMD_HEADER_2))
+				{
+					if(rx[3] == CMD_REG_READ_DATA)
+					{
+
+						displayMessageDgus(rx, len, YES);
+
+						result = PASS;
+					}
+					else
+					{}
+				}
+				else
+				{}
+			}
+			else
+			{}
+		}
+		else
+		{}
+	}
+	else
+	{}
+
+	return result;
+}
+
+int8_t lcdRegisterWrite(int32_t fd, uint8_t regType, uint16_t address, uint8_t *data, uint16_t dataLen)
+{
+	int8_t result = FAIL;
+	uint8_t tx[(regType == REG_TYPE_CONTROL? 8 : 6) + dataLen];
+	uint8_t rx[6];
+
+	memset(tx, 0x00, sizeof(tx));
+	memset(rx, 0x00, sizeof(rx));
+
+	tx[0] = CMD_HEADER_1;
+	tx[1] = CMD_HEADER_2;
+	tx[2] = (regType == REG_TYPE_CONTROL? 7 : (3 + dataLen));
+	tx[3] = CMD_REG_WRITE_DATA;
+	tx[4] = (address >> 8) & 0xff;
+	tx[5] = (address >> 0) & 0xff;
+
+	if(regType == REG_TYPE_CONTROL)
+	{
+		if(address == REG_ADDRESS_SET_PAGE_ID)
+		{
+			tx[6] = 0x5A;
+			tx[7] = 0x01;
+
+			memcpy(&tx[8], data, dataLen);
+		}
+	}
+	else
+	{
+		memcpy(&tx[6], data, dataLen);
+	}
+
+	if(fd > 0)
+	{
+		if(transceiverDgus(fd, tx, ARRAY_SIZE(tx), rx, ARRAY_SIZE(rx)) == PASS)
+		{
+			result = PASS;
+		}
+		else
+		{}
+	}
+	else
+	{}
+
+	return result;
+}
+
+//int downloadBMP(uint8_t picIdx, char *filename)
+//{
+//    int result = PASS;
+//    BMP *bmp;
+//    struct stat fileSt;
+//    uint32_t pageSize = 0xf0;
+//    uint32_t pixelSize;
+//    uint32_t transferedByte=0;
+//    uint16_t bufferRamAddr = 0x8000;
+//
+//    // Reset LCD
+//    uint8_t cmd_reset[] = {0x55, 0xaa, 0x5a, 0xa5};
+//    if(lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, 0x04, cmd_reset, ARRAY_SIZE(cmd_reset)) == FAIL)
+//    {
+//        printf("LCD reset fail.\n");
+//        return -1;
+//    }
+//
+//
+//
+//    // Get image file size
+//    stat(filename, &fileSt);
+//    bmp = bopen(filename);
+//    uint8_t buf[bmp->width*bmp->height*2];
+//
+//
+//
+//    printf("Image filename: %s\n", filename);
+//    printf("Image width: %d height: %d\n", bmp->width, bmp->height);
+//    printf("Image data size: %d\n", ARRAY_SIZE(buf));
+//
+//
+//
+//    // Get bmp pixel data and convert to 16 bit color
+//    for(uint16_t idxY=0 ; idxY<bmp->height ; idxY++)
+//    {
+//        for(uint16_t idxX=0 ; idxX<bmp->width ; idxX++)
+//        {
+//            uint8_t r, g, b;
+//            get_pixel_rgb(bmp, idxX, (bmp->height-idxY-1), &r, &g, &b);
+//            buf[(2*((idxY*bmp->width) + idxX)) + 0] = ((((r>>3)<<11) | ((g>>2)<<5) | (b>>3)) >> 8) & 0xff;
+//            buf[(2*((idxY*bmp->width) + idxX)) + 1] = ((((r>>3)<<11) | ((g>>2)<<5) | (b>>3)) >> 0) & 0xff;
+//        }
+//    }
+//    bclose(bmp);
+//
+//
+//
+//    // Transfer pixel to screen page
+//    pixelSize = ARRAY_SIZE(buf);
+//    for(uint16_t idxSrcData=0;idxSrcData<(((pixelSize%pageSize)==0)?(pixelSize/pageSize):(pixelSize/pageSize)+1);idxSrcData++)
+//    {
+//        //DEBUG_INFO("Buffer start data address: 0x%08X\n", (idxSrcData*pageSize));
+//        //DEBUG_INFO("  Image start ram address: 0x%08X\n", ((idxSrcData*pageSize) >> 1));
+//        uint8_t display_cmd[] ={0x5a, (bufferRamAddr>>8)&0xff, (bufferRamAddr>>0)&0xff, 0x00, 0x00, 0x00, 0x00, 0x00};
+//
+//
+//
+//        if((idxSrcData+1) != (((pixelSize%pageSize)==0)?(pixelSize/pageSize):(pixelSize/pageSize)+1))
+//        {
+//            // Data transfer
+//            if(lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, bufferRamAddr, &buf[(idxSrcData*pageSize)], pageSize))
+//                transferedByte += pageSize;
+//
+//
+//
+//            display_cmd[3] = ((pageSize>>1) >> 8) & 0xff;                            // Data length high byte
+//            display_cmd[4] = ((pageSize>>1) >> 0) & 0xff;                            // Data length low byte
+//            display_cmd[5] = (((idxSrcData*pageSize)>>1) >> 16) & 0xff;                // Screen on ram address 1st byte
+//            display_cmd[6] = (((idxSrcData*pageSize)>>1) >> 8) & 0xff;                // Screen on ram address 2nd byte
+//            display_cmd[7] = (((idxSrcData*pageSize)>>1) >> 0) & 0xff;                // Screen on ram address 3th byte
+//        }
+//        else
+//        {
+//            // Last data transfer
+//            if(lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, bufferRamAddr, &buf[(idxSrcData*pageSize)], (pixelSize-(idxSrcData*pageSize))))
+//                transferedByte += (pixelSize-(idxSrcData*pageSize));
+//
+//
+//
+//
+//            display_cmd[3] = (((pixelSize-(idxSrcData*pageSize))>>1) >> 8) & 0xff;    // Data length high byte
+//            display_cmd[4] = (((pixelSize-(idxSrcData*pageSize))>>1) >> 0) & 0xff;    // Data length low byte
+//            display_cmd[5] = (((idxSrcData*pageSize)>>1) >> 16) & 0xff;                // Screen on ram address 1st byte
+//            display_cmd[6] = (((idxSrcData*pageSize)>>1) >> 8) & 0xff;                // Screen on ram address 2nd byte
+//            display_cmd[7] = (((idxSrcData*pageSize)>>1) >> 0) & 0xff;                // Screen on ram address 3th byte
+//        }
+//        usleep(60000); // Very important, wait protocol data move to ram
+//
+//
+//
+//        // Move data from ram to flash
+//        if(lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, 0xa2, display_cmd, ARRAY_SIZE(display_cmd)) == FAIL)
+//        {
+//        	printf("Transfered %d bytes fail.\n", transferedByte);
+//        }
+//    }
+//
+//
+//
+//    // Save image to target address
+//    uint8_t save_cmd[] ={0x5a, 0x02, ((picIdx>>8)&0xff), (picIdx&0xff)};
+//    if(lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, 0x84, save_cmd, ARRAY_SIZE(save_cmd)))
+//    {
+//        usleep(20000); // Very important, wait display buffer save to target image address
+//        printf("Save image success.\n");
+//    }
+//    else
+//    	printf("Save image fail.\n");
+//
+//
+//
+//    return result;
+//}
+
 int main(void)
 {
 	if(InitShareMemory() == FAIL)
@@ -1828,12 +2223,26 @@ int main(void)
 
 	Initialization();
 
-	//	ChangeToOtherPage(_LCM_INIT);
-	//	ChangeDisplay2Value(__phihong_string, _disappear);
-	//	return -1;
+	//ChangeToOtherPage(_LCM_IDLE);
+//	return -1;
 
 	DefaultIconStatus();
 
+//	int xxx = 3;
+//	while(xxx > 0 && Uart1Fd != -1)
+//	{
+//		if (xxx == 1)
+//		{
+//			printf("---------------------------- \n");
+//			downloadBMP(1, "/tmp/1_idle.bmp");
+//			printf("---------------------------- end \n");
+//			return -1;
+//		}
+//		sleep(1);
+//		xxx--;
+//	}
+//	return -1;
+
 	byte _verShowCount = 3;
 
 	while(Uart1Fd != -1)
@@ -1887,10 +2296,29 @@ 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();
 			}
 
+			// ±½«ö¶s
+			//GetDeviceInfoStatus(0x0600, 1);
+
 			changeWarningPriority >= 15 ? (_battery_display_ani = true) : (_battery_display_ani = false);
 			changeWarningPriority >= 30 ? changeWarningPriority = 0 : changeWarningPriority++;
 			usleep(100000);

BIN
EVSE/Projects/DS60-120/Apps/Module_PrimaryComm


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

BIN
EVSE/Projects/DS60-120/Apps/Module_PsuComm


+ 134 - 87
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, ...)
@@ -447,6 +465,10 @@ void GetMaxPowerAndCur(unsigned char mode, int ratingCur, int *pow, int *cur)
 		maxPower /= 2;
 	}
 
+	if (ShmDcCommonData->ocppMaxChargingProfilePow >= 0 &&
+			maxPower > ShmDcCommonData->ocppMaxChargingProfilePow)
+		maxPower = ShmDcCommonData->ocppMaxChargingProfilePow;
+
 	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 <= S_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;
@@ -1079,8 +1101,8 @@ void GetOutputAndTempCallback(byte address, unsigned short outputVol_s,
 //			}
 //		}
 //
-//		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 <= S_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;
@@ -1119,6 +1141,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 +1221,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 +1238,6 @@ int InitShareMemory()
 		#endif
     	result = FAIL;
    	}
-    else
-    {}
 
    	//creat ShmPsuData
 	if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData),  0777)) < 0)
@@ -1323,6 +1348,8 @@ void Initialization()
 
 	ShmPsuData->SystemAvailableCurrent = 0;
 	ShmPsuData->SystemAvailablePower = 0;
+
+	GetTimespecFunc(&ShmDcCommonData->_psuComm_time);
 }
 
 void CheckSmartChargingStep(byte chargingStatus)
@@ -1357,7 +1384,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 +1454,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 +1506,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 +1533,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 +1546,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 +1567,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 +1582,7 @@ bool MaxToAverChargingProc(byte groupIndex)
 						ShmPsuData->PsuGroup[groupIndex].GroupPresentOutputCurrent,
 						ShmPsuData->GroupCount);
 
-					gettimeofday(&_derating_time, NULL);
+					GetTimespecMFunc(&_derating_time);
 				}
 			}
 		}
@@ -1579,7 +1606,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 +1615,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 +1674,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 +1703,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 +1765,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 +1789,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 +1808,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 +1826,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 +1844,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 +1928,12 @@ int main(void)
 			continue;
 		}
 		else
+		{
+			if (isInitialComp)
+				GetTimespecFunc(&ShmDcCommonData->_psuComm_time);
+
 			isInitialComp = NO;
+		}
 
 		// 自檢失敗
 		if (ShmPsuData->Work_Step == _NO_WORKING)
@@ -1909,13 +1941,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 +1973,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 +2013,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 +2075,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 +2085,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 +2098,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 +2150,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)
@@ -2202,8 +2249,8 @@ int main(void)
 							}
 						}
 					}
-					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 +2273,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 +2285,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 +2330,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 +2349,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,7 +2365,7 @@ int main(void)
 						GetModuleOutputF(index); Await();
 					}
 
-					gettimeofday(&_cmdSubPriority_time, NULL);
+					GetTimespecMFunc(&_cmdSubPsuPriority_time);
 				}
 
 				byte _switch = 0x00;

+ 4 - 4
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;

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

BIN
EVSE/Projects/DS60-120/Apps/ReadCmdline


+ 239 - 116
EVSE/Projects/DS60-120/Apps/ReadCmdline.c

@@ -37,6 +37,7 @@
 #include 	<math.h>
 #include 	<stdbool.h>
 #include 	"../../define.h"
+//#include    "../Module_CSU/Config.h"
 
 typedef unsigned char			byte;
 #define PASS				1
@@ -143,9 +144,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 +155,6 @@ int InitShareMemory()
     {
     	result = FAIL;
    	}
-    else
-    {}
 
 	if (CHAdeMO_QUANTITY > 0) {
 		if ((MeterSMId = shmget(ShmCHAdeMOCommKey, sizeof(struct CHAdeMOData),
@@ -187,7 +184,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 +478,7 @@ void CreateOneError()
 	{
 		printf("(%d). %s \n", i, &ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0]);
 	}
+
 }
 
 void GetAuthorizeFlag(char *v1)
@@ -571,6 +568,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 +609,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 +918,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 +925,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,7 +940,7 @@ 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)
 					{
@@ -915,10 +948,10 @@ void AverageCharging(char *g1_vol, char *g1_cur, char *g2_vol, char *g2_cur)
 					    printf ("[AverageCharging (%d) - S_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,11 +965,9 @@ 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)
 				    {
@@ -962,16 +993,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 +1031,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)
 				    {
@@ -1031,11 +1062,11 @@ 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)
 				    {
@@ -1046,10 +1077,10 @@ void AverageCharging(char *g1_vol, char *g1_cur, char *g2_vol, char *g2_cur)
 				    }
 
 				    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)
 				    {
@@ -1101,7 +1132,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 +1186,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 +1200,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;
+        	        PreviousSystemStatus = _chargingData[_GunIndex]->SystemStatus;
 
         	        printf ("[UnconditionalCharge - S_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,51 +1239,51 @@ 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 ("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");
 
@@ -1262,50 +1292,50 @@ void RunUnconditionalChargeIndex1(char *v1, char *v2, char *v3)
         	    //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,8 +1343,8 @@ 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");
         	    }
@@ -1324,21 +1354,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[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->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,21 +1376,21 @@ 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[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->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");
@@ -1369,21 +1399,21 @@ void RunUnconditionalChargeIndex1(char *v1, char *v2, char *v3)
         	    }
 
         	    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");
         	    }
 
-        	    _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingPower = 0;
+        	    _chargingData[_GunIndex]->PresentChargingPower = 0;
         	    sleep(3);
         	    return;
     		}
@@ -1432,20 +1462,107 @@ 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);
     }
 }
 
+//LWN_Debug
+#ifdef LW_DEBUG_INFO
+void PrintDebugInfo(char *v1)
+{
+	int Index = 0;
+	bool PrintAll = false;
+
+	if (strcmp(v1, "-1") == 0 || strcmp(v1, "") == 0)
+	{
+		PrintAll = true;
+		Index = 8;
+	}
+	else
+		Index = atoi(v1);
+
+	for (int i = 0; i < Index + 1; i++)
+	{
+		//command後面有帶value, print該state的info; 未帶值, print all of info.
+		if (PrintAll == false)
+			if (i != Index)
+				continue;
+
+		switch (i)
+		{
+			case 0:
+			{
+				if (ShmDcCommonData->DbgInfo.Msg.Index_0 == TRUE)
+					printf("[LWTEST]test debyg info print - 0\n");
+			}
+				break;
+
+			case 1:
+			{
+				if (ShmDcCommonData->DbgInfo.Msg.Index_1 == TRUE)
+					printf("[LWTEST]test debyg info print - 1\n");
+			}
+				break;
+
+			case 2:
+			{
+				if (ShmDcCommonData->DbgInfo.Msg.Index_2 == TRUE)
+					printf("[LWTEST]test debyg info print - 2\n");
+			}
+				break;
+
+			case 3:
+			{
+				if (ShmDcCommonData->DbgInfo.Msg.Index_3 == TRUE)
+					printf("[LWTEST]test debyg info print - 3\n");
+			}
+				break;
+
+			case 4:
+			{
+				if (ShmDcCommonData->DbgInfo.Msg.Index_4 == TRUE)
+					printf("[LWTEST]test debyg info print - 4\n");
+			}
+				break;
+
+			case 5:
+			{
+				if (ShmDcCommonData->DbgInfo.Msg.Index_5 == TRUE)
+					printf("[LWTEST]test debyg info print - 5\n");
+			}
+				break;
+
+			case 6:
+			{
+				if (ShmDcCommonData->DbgInfo.Msg.Index_6 == TRUE)
+					printf("[LWTEST]test debyg info print - 6\n");
+			}
+				break;
+
+			case 7:
+			{
+				if (ShmDcCommonData->DbgInfo.Msg.Index_7 == TRUE)
+					printf("[LWTEST]test debyg info print - 7\n");
+			}
+				break;
+
+			default:
+				break;
+		}
+	}
+}
+#endif
+
 int main(void)
 {
 	if(InitShareMemory() == FAIL)
@@ -1650,6 +1767,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 +1810,6 @@ 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);
 		}
 		else if(strcmp(newString[0], "strchg") == 0)
 		{
@@ -1731,6 +1848,12 @@ int main(void)
 
 			AverageCharging(newString[1], newString[2], newString[3], newString[4]);
 		}
+#ifdef LW_DEBUG_INFO
+		else if (strcmp(newString[0], "lwdebug") == 0)
+		{
+			PrintDebugInfo(newString[1]);
+		}
+#endif
 		else
 			printf ("%s\n", msg);
 		usleep(100000);

BIN
EVSE/Projects/DS60-120/Apps/UnsafetyOutputTask


+ 315 - 0
EVSE/Projects/DS60-120/Apps/cbmp.c

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

+ 54 - 0
EVSE/Projects/DS60-120/Apps/cbmp.h

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

+ 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

BIN
EVSE/Projects/DS60-120/Apps/main


Файлын зөрүү хэтэрхий том тул дарагдсан байна
+ 419 - 293
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_ */

BIN
EVSE/Projects/DS60-120/Images/FactoryDefaultConfig.bin


BIN
EVSE/Projects/DS60-120/Images/ramdisk.gz


Энэ ялгаанд хэт олон файл өөрчлөгдсөн тул зарим файлыг харуулаагүй болно