浏览代码

fixed merge master

Jerry_Wang 4 年之前
父节点
当前提交
a10e260cec
共有 76 个文件被更改,包括 3782 次插入2030 次删除
  1. 2 2
      EVSE/Modularization/Makefile
  2. 63 45
      EVSE/Modularization/Module_Upgrade.c
  3. 36 8
      EVSE/Modularization/Module_Wifi.c
  4. 270 44
      EVSE/Modularization/ocpp20/MessageHandler.c
  5. 30 7
      EVSE/Modularization/ocpp20/Module_OcppBackend20.c
  6. 1 0
      EVSE/Modularization/ocpp20/Module_OcppBackend20.h
  7. 1 1
      EVSE/Modularization/ocpp20/SystemLogMessage.c
  8. 34 22
      EVSE/Modularization/ocppfiles/MessageHandler.c
  9. 33 9
      EVSE/Modularization/ocppfiles/Module_OcppBackend.c
  10. 3 3
      EVSE/Modularization/ocppfiles/Module_OcppBackend.h
  11. 21 44
      EVSE/Projects/AW-CCS/Apps/CCS/Module_CCS.c
  12. 19 17
      EVSE/Projects/AW-CCS/Apps/CCS/Module_CCS.h
  13. 17 0
      EVSE/Projects/AW-CCS/Apps/Module_InternalComm.c
  14. 138 109
      EVSE/Projects/AW-CCS/Apps/main.c
  15. 2 0
      EVSE/Projects/AW-CCS/Apps/main.h
  16. 31 1
      EVSE/Projects/AW-Regular/Apps/main.c
  17. 二进制
      EVSE/Projects/AW-Regular/Images/ramdisk.gz
  18. 59 13
      EVSE/Projects/CCS/Apps/FWUpdate.c
  19. 二进制
      EVSE/Projects/CCS/Apps/SeccComm
  20. 2 1
      EVSE/Projects/CCS/Apps/SeccComm.c
  21. 33 1
      EVSE/Projects/CCS/Apps/main.c
  22. 1 1
      EVSE/Projects/CCS/Apps/version.h
  23. 二进制
      EVSE/Projects/CCS/Images/ramdisk.gz
  24. 1 0
      EVSE/Projects/DD360Audi/Apps/main.c
  25. 二进制
      EVSE/Projects/DD360Audi/Images/ramdisk.gz
  26. 二进制
      EVSE/Projects/DD360Audi/output/DoComm
  27. 二进制
      EVSE/Projects/DD360Audi/output/FactoryConfig
  28. 二进制
      EVSE/Projects/DD360Audi/output/Module_EvComm
  29. 二进制
      EVSE/Projects/DD360Audi/output/Module_EventLogging
  30. 二进制
      EVSE/Projects/DD360Audi/output/Module_InternalComm
  31. 二进制
      EVSE/Projects/DD360Audi/output/Module_LcmControl
  32. 二进制
      EVSE/Projects/DD360Audi/output/Module_PrimaryComm
  33. 二进制
      EVSE/Projects/DD360Audi/output/ReadCmdline
  34. 二进制
      EVSE/Projects/DD360Audi/output/main
  35. 1 1
      EVSE/Projects/DO360/Apps/FactoryConfig.c
  36. 194 27
      EVSE/Projects/DO360/Apps/Module_EvComm.c
  37. 10 0
      EVSE/Projects/DO360/Apps/Module_EvComm.h
  38. 218 360
      EVSE/Projects/DO360/Apps/Module_InternalComm.c
  39. 20 42
      EVSE/Projects/DO360/Apps/Module_PrimaryComm.c
  40. 11 5
      EVSE/Projects/DO360/Apps/Module_PsuComm.c
  41. 330 168
      EVSE/Projects/DO360/Apps/main.c
  42. 二进制
      EVSE/Projects/DO360/Images/FactoryDefaultConfig.bin
  43. 二进制
      EVSE/Projects/DO360/Images/ramdisk.gz
  44. 51 17
      EVSE/Projects/DS60-120/Apps/Config.h
  45. 二进制
      EVSE/Projects/DS60-120/Apps/FactoryConfig
  46. 6 4
      EVSE/Projects/DS60-120/Apps/FactoryConfig.c
  47. 二进制
      EVSE/Projects/DS60-120/Apps/Module_EvComm
  48. 231 88
      EVSE/Projects/DS60-120/Apps/Module_EvComm.c
  49. 二进制
      EVSE/Projects/DS60-120/Apps/Module_EventLogging
  50. 8 4
      EVSE/Projects/DS60-120/Apps/Module_EventLogging.c
  51. 二进制
      EVSE/Projects/DS60-120/Apps/Module_InternalComm
  52. 851 715
      EVSE/Projects/DS60-120/Apps/Module_InternalComm.c
  53. 二进制
      EVSE/Projects/DS60-120/Apps/Module_LcmControl
  54. 39 26
      EVSE/Projects/DS60-120/Apps/Module_LcmControl.c
  55. 二进制
      EVSE/Projects/DS60-120/Apps/Module_PrimaryComm
  56. 140 3
      EVSE/Projects/DS60-120/Apps/Module_PrimaryComm.c
  57. 二进制
      EVSE/Projects/DS60-120/Apps/Module_PsuComm
  58. 98 32
      EVSE/Projects/DS60-120/Apps/Module_PsuComm.c
  59. 35 1
      EVSE/Projects/DS60-120/Apps/PrimaryComm.c
  60. 3 0
      EVSE/Projects/DS60-120/Apps/PrimaryComm.h
  61. 二进制
      EVSE/Projects/DS60-120/Apps/ReadCmdline
  62. 20 2
      EVSE/Projects/DS60-120/Apps/ReadCmdline.c
  63. 二进制
      EVSE/Projects/DS60-120/Apps/UnsafetyOutputTask
  64. 二进制
      EVSE/Projects/DS60-120/Apps/main
  65. 466 173
      EVSE/Projects/DS60-120/Apps/main.c
  66. 二进制
      EVSE/Projects/DS60-120/Images/FactoryDefaultConfig.bin
  67. 二进制
      EVSE/Projects/DS60-120/Images/ramdisk.gz
  68. 193 3
      EVSE/Projects/Noodoe/Apps/main.c
  69. 1 0
      EVSE/Projects/Noodoe/Apps/main.h
  70. 二进制
      EVSE/Projects/Noodoe/Images/ramdisk.gz
  71. 39 13
      EVSE/Projects/define.h
  72. 1 0
      EVSE/rootfs/root/.gitignore
  73. 二进制
      EVSE/rootfs/root/OcppBackend20
  74. 二进制
      EVSE/rootfs/usr/bin/phyreg
  75. 18 17
      Makefile
  76. 1 1
      run_gen_make_script.sh

+ 2 - 2
EVSE/Modularization/Makefile

@@ -61,12 +61,12 @@ WebServiceLib:
 
 Ocpp16:
 	rm -f OcppBackend; 
-	$(CC) -D $(Project) -D__USE_XOPEN -D_GNU_SOURCE ./ocppfiles/Module_OcppBackend.c ./ocppfiles/MessageHandler.c ./ocppfiles/JsonParser.c ./ocppfiles/SystemLogMessage.c ./ocppfiles/hashmap.c ./ocppfiles/common.c -I ../Projects -I ../GPL/libwebsockets-2.2.2-stable/release/include -I ../GPL/json-c-json-c-0.13.1-20180305/release/include -L ../GPL/libwebsockets-2.2.2-stable/release/lib -L ../GPL/openssl-1.0.2g/release/lib -L ../GPL/json-c-json-c-0.13.1-20180305/release/lib -lwebsockets -luuid -lpthread -lc -lsqlite3 -ljson-c -o OcppBackend
+	$(CC) -D $(TLS_EXPIRED) -D $(Project) -D__USE_XOPEN -D_GNU_SOURCE ./ocppfiles/Module_OcppBackend.c ./ocppfiles/MessageHandler.c ./ocppfiles/JsonParser.c ./ocppfiles/SystemLogMessage.c ./ocppfiles/hashmap.c ./ocppfiles/common.c -I ../Projects -I ../GPL/libwebsockets-2.2.2-stable/release/include -I ../GPL/json-c-json-c-0.13.1-20180305/release/include -L ../GPL/libwebsockets-2.2.2-stable/release/lib -L ../GPL/openssl-1.0.2g/release/lib -L ../GPL/json-c-json-c-0.13.1-20180305/release/lib -lwebsockets -luuid -lpthread -lc -lsqlite3 -ljson-c -o OcppBackend
 	mv -f OcppBackend ../rootfs/root/
 
 Ocpp20:
 	rm -f OcppBackend20;
-	$(CC) -D $(Project) -D__USE_XOPEN -D_GNU_SOURCE ./ocpp20/Module_OcppBackend20.c ./ocpp20/MessageHandler.c ./ocpp20/JsonParser.c ./ocpp20/SystemLogMessage.c ./ocpp20/hashmap.c ./ocpp20/common.c -I ../Projects -I ../GPL/libwebsockets-2.2.2-stable/release/include -I ../GPL/json-c-json-c-0.13.1-20180305/release/include -L ../GPL/libwebsockets-2.2.2-stable/release/lib -L ../GPL/openssl-1.0.2g/release/lib -L ../GPL/json-c-json-c-0.13.1-20180305/release/lib -lwebsockets -luuid -lpthread -lc -lsqlite3 -ljson-c -o OcppBackend20
+	$(CC) -D $(TLS_EXPIRED) -D $(Project) -D__USE_XOPEN -D_GNU_SOURCE ./ocpp20/Module_OcppBackend20.c ./ocpp20/MessageHandler.c ./ocpp20/JsonParser.c ./ocpp20/SystemLogMessage.c ./ocpp20/hashmap.c ./ocpp20/common.c -I ../Projects -I ../GPL/libwebsockets-2.2.2-stable/release/include -I ../GPL/json-c-json-c-0.13.1-20180305/release/include -L ../GPL/libwebsockets-2.2.2-stable/release/lib -L ../GPL/openssl-1.0.2g/release/lib -L ../GPL/json-c-json-c-0.13.1-20180305/release/lib -lwebsockets -luuid -lpthread -lc -lsqlite3 -ljson-c -o OcppBackend20
 	mv -f OcppBackend20 ../rootfs/root/
 
 

+ 63 - 45
EVSE/Modularization/Module_Upgrade.c

@@ -484,7 +484,7 @@ int uart_tranceive(int fd, unsigned char* cmd, unsigned char* rx, int len, unsig
     return rxLen;
 }
 
-unsigned char uart_update_start(unsigned char fd, unsigned char targetAddr, unsigned int crc32)
+unsigned char uart_update_start(int fd, unsigned char targetAddr, unsigned int crc32)
 {
     unsigned char result = FAIL;
     unsigned char tx[11] = {0xaa, 0x00, targetAddr, UART_CMD_UPDATE_START, 0x04, 0x00, (crc32>>0)&0xff, (crc32>>8)&0xff, (crc32>>16)&0xff, (crc32>>24)&0xff, 0x00};
@@ -525,7 +525,7 @@ unsigned char uart_update_start(unsigned char fd, unsigned char targetAddr, unsi
     return result;
 }
 
-unsigned char uart_update_abord(unsigned char fd, unsigned char targetAddr)
+unsigned char uart_update_abord(int fd, unsigned char targetAddr)
 {
     unsigned char result = FAIL;
     unsigned char tx[7] = {0xaa, 0x00, targetAddr, UART_CMD_UPDATE_ABORD, 0x00, 0x00, 0x00};
@@ -562,7 +562,7 @@ unsigned char uart_update_abord(unsigned char fd, unsigned char targetAddr)
     return result;
 }
 
-unsigned char uart_update_transfer(unsigned char fd, unsigned char targetAddr, unsigned int startAddr, unsigned char *data, unsigned short int length)
+unsigned char uart_update_transfer(int fd, unsigned char targetAddr, unsigned int startAddr, unsigned char *data, unsigned short int length)
 {
     unsigned char result = FAIL;
     unsigned char tx[11 + length];
@@ -610,7 +610,7 @@ unsigned char uart_update_transfer(unsigned char fd, unsigned char targetAddr, u
     return result;
 }
 
-unsigned char uart_update_finish(unsigned char fd, unsigned char targetAddr)
+unsigned char uart_update_finish(int fd, unsigned char targetAddr)
 {
     unsigned char result = FAIL;
     unsigned char tx[7] = {0xaa, 0x00, targetAddr, UART_CMD_UPDATE_FINISH, 0x00, 0x00, 0x00};
@@ -647,7 +647,7 @@ unsigned char uart_update_finish(unsigned char fd, unsigned char targetAddr)
     return result;
 }
 
-unsigned char uart_config_timeout(unsigned char uartfd)
+unsigned char uart_config_timeout(int uartfd)
 {
 	struct termios tios;
 
@@ -712,52 +712,70 @@ int Upgrade_UART(int uartfdOrd,unsigned int Type,unsigned char TargetAddr,char *
                 DEBUG_INFO("CRC32 by calculation: 0x%08X\n",crc32(ptr,ImageLen));
                 if(crc32(ptr,ImageLen) == ImageCRC)
                 {
-                    if(uart_update_start(uartfd, TargetAddr, crc32(ptr+48,DataLength))==PASS)
+                    if(YES)
                     {
                         int CNT_Fail = 0;
                         int CNT_Trans = 0;
+
                         do
                         {
-                            if(uart_update_transfer(uartfd, TargetAddr, CNT_Trans*1024, ptr+48+(CNT_Trans*1024), 1024)==PASS)
-                            {
-                                CNT_Fail = 0;
-                                CNT_Trans++;
-                                DEBUG_INFO("Upgrade progress:%.2f%%\n", ((float)(CNT_Trans*1024))/(DataLength)*100);
-                            }
-                            else
-                            {
-                                DEBUG_WARN("Data transfer fail, retry %d \n", ++CNT_Fail);
-                                sleep(1);
-                            }
-                        }while(DataLength-(CNT_Trans*1024)>0 && CNT_Fail<10);
+                        	if(uart_update_start(uartfd, TargetAddr, crc32(ptr+48,DataLength))==PASS)
+                        		break;
+							else
+								DEBUG_WARN("Upgrade start fail, retry %d \n", ++CNT_Fail);
+                        }while(CNT_Fail<10);
 
                         if(CNT_Fail>=10)
-                        {
-                            uart_update_abord(uartfd, TargetAddr);
-                            DEBUG_ERROR("UART upgrade transfer retry > limits, aboard upgrade.\n");
-                        }
-                        else
-                        {
-                        	do
-                        	{
-                        		if(uart_update_finish(uartfd, TargetAddr)==PASS)
-                        			break;
-                        		else
-                        			DEBUG_WARN("Upgrade finish fail, retry %d \n", ++CNT_Fail);
-                        	}while(CNT_Fail<10);
-
-                        	if(CNT_Fail>=10)
-                        	{
-                        		uart_update_abord(uartfd, TargetAddr);
-                        		DEBUG_ERROR("UART upgrade finish retry > limits, aboard upgrade.\n");
-                        	}
-                        	else
-                        	{
-                        		result = PASS;
-                        		printf("UART upgrade success.\n");
-                        	}
-
-                        }
+						{
+							uart_update_abord(uartfd, TargetAddr);
+							DEBUG_ERROR("UART upgrade start retry > limits, aboard upgrade.\n");
+						}
+						else
+						{
+							CNT_Fail = 0;
+							do
+							{
+								if(uart_update_transfer(uartfd, TargetAddr, CNT_Trans*1024, ptr+48+(CNT_Trans*1024), 1024)==PASS)
+								{
+									CNT_Fail = 0;
+									CNT_Trans++;
+									DEBUG_INFO("Upgrade progress:%.2f%%\n", ((float)(CNT_Trans*1024))/(DataLength)*100);
+								}
+								else
+								{
+									DEBUG_WARN("Data transfer fail, retry %d \n", ++CNT_Fail);
+									sleep(1);
+								}
+							}while(DataLength-(CNT_Trans*1024)>0 && CNT_Fail<10);
+
+							if(CNT_Fail>=10)
+							{
+								uart_update_abord(uartfd, TargetAddr);
+								DEBUG_ERROR("UART upgrade transfer retry > limits, aboard upgrade.\n");
+							}
+							else
+							{
+								CNT_Fail = 0;
+								do
+								{
+									if(uart_update_finish(uartfd, TargetAddr)==PASS)
+										break;
+									else
+										DEBUG_WARN("Upgrade finish fail, retry %d \n", ++CNT_Fail);
+								}while(CNT_Fail<10);
+
+								if(CNT_Fail>=10)
+								{
+									uart_update_abord(uartfd, TargetAddr);
+									DEBUG_ERROR("UART upgrade finish retry > limits, aboard upgrade.\n");
+								}
+								else
+								{
+									result = PASS;
+									printf("UART upgrade success.\n");
+								}
+							}
+						}
                     }
                     else
                         DEBUG_ERROR("UART upgrade request failed.\n");
@@ -1170,7 +1188,7 @@ int Send_CCS_download_finish(int canfd,unsigned int Slave_Addr)
 
         struct timeval timer;
         gettimeofday(&timer, NULL);
-        unsigned long ack_timeout = 30 * 60 * 1000 * 1000;  //30 minutes
+        unsigned long ack_timeout = 5 * 60 * 1000 * 1000;  //5 minutes
 
         while (getTimeoutValue(timer) < ack_timeout)
         {

+ 36 - 8
EVSE/Modularization/Module_Wifi.c

@@ -260,7 +260,7 @@ int isValidCheckSum(uint8_t *message);
 char *Support_InterfaceSTA[2]	= {"mlan0", "wlan0"};
 char *Support_InterfaceAP[1]	= {"uap0"};
 char *valid_Internet[2]			= {"8.8.8.8", "180.76.76.76"};
-char *Version_And_Date[2]		= {"V0.15","2020-11-26"};
+char *Version_And_Date[2]		= {"V0.16","2021-01-13"};
 int protocol_Version [] 		= {0,7,0};
 
 int StoreLogMsg(const char *fmt, ...)
@@ -470,8 +470,6 @@ int isFindInterface()
 
 	struct ifaddrs *ifaddr, *ifa;
 
-	//refreshUSB();
-
 	if(ShmSysConfigAndInfo->SysConfig.AthInterface.WifiMode == WIFI_MODE_AP)
 	{
 		if (getifaddrs(&ifaddr) != FAIL)
@@ -569,11 +567,17 @@ int getInterfaceInfo()
 	{
 		while(fgets(buf, sizeof(buf), fp) != NULL)
 		{
-			if(strncmp(buf, "default", strlen("default")) == 0)
+#ifdef UBLOX
+			if((strstr(buf, "default") != NULL) && (strstr(buf, "mlan0") != NULL))
+#endif
+
+#ifdef MT7601U
+			if((strstr(buf, "default") != NULL) && (strstr(buf, "wlan0") != NULL))
+#endif
 				break;
 		}
 		
-		if(strncmp(buf, "default", strlen("default")) == 0)
+		if(strstr(buf, "default") != NULL)
 		{
 			sscanf(buf, "%*s%*s%s", tmp);
 			substr(Wifi.currentGateway, tmp, 0, strlen(tmp));
@@ -4399,6 +4403,27 @@ int restartWPA(void)
 	return result;
 }
 
+int resetModule(void)
+{
+	//refreshUSB();
+
+	#ifdef UBLOX
+		system("ifconfig mlan0 down");
+		sleep(1);
+		system("ifconfig mlan0 up");
+	#endif
+
+	#ifdef MT7601U
+		system("ifconfig wlan0 down");
+		sleep(1);
+		system("ifconfig wlan0 up");
+	#endif
+
+	DEBUG_WARN("Wifi interface restart.\n");
+
+	return PASS;
+}
+
 void proc_sta()
 {
 	switch(Wifi_module_sts)
@@ -4410,6 +4435,7 @@ void proc_sta()
 
 			ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi=1;
 			ShmStatusCodeData->InfoCode.InfoEvents.bits.ApDisconnectViaWiFi=1;
+			ShmSysConfigAndInfo->SysConfig.AthInterface.WifiNetworkConn=0;
 			isSetWPA_OK = false;
 			// check interface
 			if((strlen((const char*)Wifi_A.ssid)>0) && (isFindInterface() == PASS))
@@ -4431,13 +4457,13 @@ void proc_sta()
 			if(!isSetWPA_OK && (setWPAconf() == PASS))
 			{
 				isSetWPA_OK = true;
-				ShmStatusCodeData->AlarmCode.AlarmEvents.bits.WiFiModuleCommFail=0;
 				sleep(5);
 			}
 			else if((isSetWPA_OK == true) && (isConnectAP() == PASS))
 			{
 				Wifi_module_sts = STA_STATE_AP_CONNECTED;
 				ShmStatusCodeData->InfoCode.InfoEvents.bits.ApDisconnectViaWiFi=0;
+				ShmStatusCodeData->AlarmCode.AlarmEvents.bits.WiFiModuleCommFail=0;
 				DEBUG_INFO("=================[State 2]===================\n");
 			}
 			else
@@ -4446,6 +4472,7 @@ void proc_sta()
 				DEBUG_INFO("Fail to connect to the AP %d times...\n",cnt_getAP_Fail);
 				if(cnt_getAP_Fail>=3)
 				{
+					resetModule();
 					Wifi_module_sts = STA_STATE_INIT;
 					cnt_getAP_Fail = 0;
 
@@ -4491,6 +4518,7 @@ void proc_sta()
 				memset(ShmSysConfigAndInfo->SysConfig.AthInterface.WifiGatewayAddress, 0, sizeof ShmSysConfigAndInfo->SysConfig.AthInterface.WifiGatewayAddress);
 				memset(ShmSysConfigAndInfo->SysConfig.AthInterface.WifiMacAddress, 0, sizeof ShmSysConfigAndInfo->SysConfig.AthInterface.WifiMacAddress);
 
+				resetModule();
 				if(isFindInterface() == PASS)
 				{
 					DEBUG_INFO("Wifi interface: %s\n", Wifi.currentInterface);
@@ -4548,7 +4576,6 @@ void proc_ap()
 			if(!isSetWPA_OK && (setWPAconf() == PASS))
 			{
 				isSetWPA_OK = true;
-				ShmStatusCodeData->AlarmCode.AlarmEvents.bits.WiFiModuleCommFail=0;
 				sleep(5);
 			}
 			else if(isSetWPA_OK && (isStartUpAP() == PASS))
@@ -4557,6 +4584,7 @@ void proc_ap()
 				ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi=1;
 				ShmStatusCodeData->InfoCode.InfoEvents.bits.ApDisconnectViaWiFi=0;
 				ShmSysConfigAndInfo->SysConfig.AthInterface.WifiNetworkConn=0;
+				ShmStatusCodeData->AlarmCode.AlarmEvents.bits.WiFiModuleCommFail=0;
 				DEBUG_INFO("=================[State 2]===================\n");
 			}
 			else
@@ -4689,7 +4717,7 @@ unsigned int isKernelSupportNAT()
 		if(fgets(buf, sizeof(buf), fp) != NULL)
 		{
 			sscanf(buf, "#%d", &version);
-			DEBUG_INFO("Kernel version: %d\n", result);
+			DEBUG_INFO("Kernel version: %d\n", version);
 
 			if(version >= 30)
 				result = YES;

+ 270 - 44
EVSE/Modularization/ocpp20/MessageHandler.c

@@ -1,6 +1,5 @@
 #include "Module_OcppBackend20.h"
 #include "define.h"
-//#define TEST_OCPP20
 
 static char *APNAuthenticationEnumTypeStr[] = {
 	MACROSTR(CHAP),
@@ -787,7 +786,7 @@ static int localversion=0;
 //===============================
 static int server_sign					= FALSE;
 int server_pending 						= FALSE;
-static int BootNotificationInterval 	= 0;
+static int BootNotificationInterval 	= 10;
 static int SystemInitial 				= 0;//= CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY;	// System Boot UP
 
 //===============================
@@ -933,7 +932,12 @@ int DB_Initial()
 							 "unique(componentName, componentInstance,variableName, variableInstance) on conflict replace);";
 
 	char *sqlBootType 	  =  "create table if not exists ocpp20_boot_type (idx integer primary key,"
-							 "type);";
+							 "type text);";
+
+
+	char *sqlNetworkProfile	= "create table if not exists ocpp20_networkprofile (idx integer primary key,"
+								 "slot integer UNIQUE, connectionData text);";
+
 
 	//sqlite3_config(SQLITE_CONFIG_URI, 1);
 	if(sqlite3_open(OCPP_LOCAL_DB_FILE, &db))
@@ -986,13 +990,23 @@ int DB_Initial()
 			DEBUG_INFO( "Create OCPP 2.0 boot_type table successfully\n");
 		}
 
+		if (sqlite3_exec(db, sqlNetworkProfile, 0, 0, &errMsg) != SQLITE_OK)
+		{
+			result = FAIL;
+			DEBUG_ERROR( "Create OCPP 2.0 ocpp20_networkprofile table error message: %s\n", errMsg);
+		}
+		else
+		{
+			DEBUG_INFO( "Create OCPP 2.0 ocpp20_networkprofile table successfully\n");
+		}
+
 		//sqlite3_close(db);
 	}
 
 	return result;
 }
 
-int versionCallback(void *para, int columnCount, char **columnValue, char **columnName)
+int DB_cbGetVersion(void *para, int columnCount, char **columnValue, char **columnName)
 {
    localversion = columnValue[12] ? atoi(columnValue[12]) : 0;
 
@@ -1007,13 +1021,13 @@ void DB_getListVerion()
     strcpy(sql, "select * from ocpp20_auth_local order by version desc, idx desc limit 1");
 
     /* Execute SQL statement */
-    if( sqlite3_exec(db, sql, versionCallback, 0, &errMsg) != SQLITE_OK )
+    if( sqlite3_exec(db, sql, DB_cbGetVersion, 0, &errMsg) != SQLITE_OK )
     {
     	DEBUG_INFO("SQL error: %s", errMsg);
     }
 }
 
-int IdTagCallback(void *para, int columnCount, char **columnValue, char **columnName)
+int DB_cbGetIdTag(void *para, int columnCount, char **columnValue, char **columnName)
 {
    sprintf((char*)idTagQuery.idToken.idToken,"%s", columnValue[1] ? columnValue[1] : "NULL");
    sprintf((char*)idTagQuery.idToken.type,"%s", columnValue[2] ? columnValue[2] : "NULL");
@@ -1042,13 +1056,13 @@ void DB_getIdTag(char idTag[], uint8_t isQueryFromCache)
     	sprintf(sql,"select * from ocpp20_auth_local where idToken='%s'", idTag);
 
     /* Execute SQL statement */
-    if(sqlite3_exec(db, sql, IdTagCallback, 0, &errMsg) != SQLITE_OK )
+    if(sqlite3_exec(db, sql, DB_cbGetIdTag, 0, &errMsg) != SQLITE_OK )
     {
     	DEBUG_INFO("SQL error: %s", errMsg);
     }
 }
 
-int sqlite3_exec_callback(void *para, int columnCount, char **columnValue, char **columnName)
+int DB_cbTableAuthlocalAllData(void *para, int columnCount, char **columnValue, char **columnName)
 {
     for (int i = 0; i < columnCount; i++)
     {
@@ -1066,13 +1080,13 @@ void DB_get_TableAuthlocalAllData(void)
     sprintf(sql,"select * from ocpp20_auth_local;");
 
     /* Execute SQL statement */
-    if(sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&errMsg) != SQLITE_OK)
+    if(sqlite3_exec(db, sql, DB_cbTableAuthlocalAllData, 0,&errMsg) != SQLITE_OK)
     {
     	DEBUG_INFO("SQL error: %s", errMsg);
     }
 }
 
-int listCallback(void *para, int columnCount, char **columnValue, char **columnName)
+int DB_cbAddLocalListCache(void *para, int columnCount, char **columnValue, char **columnName)
 {
    for(int i = 0; i<columnCount; i++)
    {
@@ -1101,7 +1115,7 @@ int DB_addLocalList(int listVersion, struct AuthorizationData *data)
 				 listVersion);
 
 	 //* Execute SQL statement */
-	 if(sqlite3_exec(db, sql, listCallback, 0, &errMsg) != SQLITE_OK)
+	 if(sqlite3_exec(db, sql, DB_cbAddLocalListCache, 0, &errMsg) != SQLITE_OK)
 	 {
 		 DEBUG_INFO("SQL error: %s\n", errMsg);
 		 result = FAIL;
@@ -1138,7 +1152,7 @@ int DB_addLocalCache(struct IdTokenType *idToken, struct IdTokenInfoType *idToke
 				 idTokenInfo->groupIdToken.type);
 
 	 //* Execute SQL statement */
-	 if(sqlite3_exec(db, sql, listCallback, 0, &errMsg) != SQLITE_OK)
+	 if(sqlite3_exec(db, sql, DB_cbAddLocalListCache, 0, &errMsg) != SQLITE_OK)
 	 {
 		 DEBUG_INFO("SQL error: %s\n", errMsg);
 		 result = FAIL;
@@ -1147,7 +1161,7 @@ int DB_addLocalCache(struct IdTokenType *idToken, struct IdTokenInfoType *idToke
 	 return result;
 }
 
-static int deleteIdTagcallback(void *para, int columnCount, char **columnValue, char **columnName)
+int deleteIdTagcallback(void *para, int columnCount, char **columnValue, char **columnName)
 {
 //   localversion = argv[5] ? atoi(columnValue[5]) : 0;
 //   printf("localversion=%d\n", localversion);
@@ -1219,6 +1233,16 @@ void DB_getBooType()
     }
 }
 
+int DB_cbUpdateBootType(void *para, int columnCount, char **columnValue, char **columnName)
+{
+   for(int i = 0; i<columnCount; i++)
+   {
+     // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
+   }
+
+   return 0;
+}
+
 int DB_updateBootType(BootReasonEnumType reason)
 {
 	int result = PASS;
@@ -1228,7 +1252,7 @@ int DB_updateBootType(BootReasonEnumType reason)
 	 sprintf(sql,"insert or replace into ocpp20_boot_type (idx, type) VALUES(1, '%s');", BootReasonEnumTypeStr[reason>BootReasonEnumType_Watchdog?BootReasonEnumType_PowerUp:reason]);
 
 	 //* Execute SQL statement */
-	 if(sqlite3_exec(db, sql, listCallback, 0, &errMsg) != SQLITE_OK)
+	 if(sqlite3_exec(db, sql, DB_cbUpdateBootType, 0, &errMsg) != SQLITE_OK)
 	 {
 		 DEBUG_INFO("SQL error: %s\n", errMsg);
 		 result = FAIL;
@@ -1237,9 +1261,19 @@ int DB_updateBootType(BootReasonEnumType reason)
 	 return result;
 }
 
-uint8_t DB_variableSaveToDb(struct ReportDataType *variable)
+int DB_cbVariableSaveToDb(void *para, int columnCount, char **columnValue, char **columnName)
 {
-	uint8_t result = FAIL;
+   for(int i = 0; i<columnCount; i++)
+   {
+     // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
+   }
+
+   return 0;
+}
+
+int DB_variableSaveToDb(struct ReportDataType *variable)
+{
+	int result = FAIL;
 
 	char sql[4096];
 	char* errMsg = NULL;
@@ -1257,7 +1291,7 @@ uint8_t DB_variableSaveToDb(struct ReportDataType *variable)
 				 variable->variableAttribute[0].value);
 
 	//* Execute SQL statement */
-	if(sqlite3_exec(db, sql, listCallback, 0, &errMsg) != SQLITE_OK)
+	if(sqlite3_exec(db, sql, DB_cbVariableSaveToDb, 0, &errMsg) != SQLITE_OK)
 	{
 		DEBUG_INFO("SQL error: %s\n", errMsg);
 		result = FAIL;
@@ -1266,7 +1300,7 @@ uint8_t DB_variableSaveToDb(struct ReportDataType *variable)
 	return result;
 }
 
-int cbVariableIsCreate(void *para, int columnCount, char **columnValue, char **columnName)
+int DB_cbVariableIsCreate(void *para, int columnCount, char **columnValue, char **columnName)
 {
 	memset(&ShmOCPP20Data->ControllerComponentVariable[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->ControllerComponentVariable));
 
@@ -1876,7 +1910,7 @@ int cbVariableIsCreate(void *para, int columnCount, char **columnValue, char **c
 		sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_SequenceList]);
 		sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
 		sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
-		sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority].variableAttribute[0].value, "LAN,WIFI,4G");
+		sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority].variableAttribute[0].value, "[0]");
 		DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority]);
 
 		sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkProfileConnectionAttempts].component.name, "OCPPCommCtrlr");
@@ -2738,13 +2772,13 @@ void DB_variableIsCreate()
     sprintf(sql,"select count(idx) as quantity from ocpp20_variable;");
 
     /* Execute SQL statement */
-    if(sqlite3_exec(db, sql, cbVariableIsCreate, 0, &errMsg) != SQLITE_OK )
+    if(sqlite3_exec(db, sql, DB_cbVariableIsCreate, 0, &errMsg) != SQLITE_OK )
     {
     	DEBUG_INFO("SQL error: %s\n", errMsg);
     }
 }
 
-int cbVariableLoadFromDb(void *para, int columnCount, char **columnValue, char **columnName)
+int DB_cbVariableLoadFromDb(void *para, int columnCount, char **columnValue, char **columnName)
 {
 	for(int idx=0;idx<CtrlrVariable_CNT;idx++)
 	{
@@ -2773,12 +2807,155 @@ void DB_variableLoadFromDb()
 	sprintf(sql,"select * from ocpp20_variable;");
 
 	/* Execute SQL statement */
-	if(sqlite3_exec(db, sql, cbVariableLoadFromDb, 0, &errMsg) != SQLITE_OK )
+	if(sqlite3_exec(db, sql, DB_cbVariableLoadFromDb, 0, &errMsg) != SQLITE_OK )
+	{
+		DEBUG_INFO("SQL error: %s\n", errMsg);
+	}
+}
+
+int DB_cbGetNetworkProfileFromDb(void *para, int columnCount, char **columnValue, char **columnName)
+{
+	memset(&ShmOCPP20Data->NetworkConnectionProfile[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->NetworkConnectionProfile));
+
+	if(columnCount > 0)
+	{
+		for(int idx=0;idx<columnCount;idx++)
+		{
+			json_object *SetNetworkProfile;
+
+			SetNetworkProfile = json_tokener_parse(columnValue[2]);
+			if(!is_error(SetNetworkProfile))
+			{
+				// Required data
+				if(json_object_object_get(SetNetworkProfile, "ocppVersion") != NULL)
+					sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.ocppVersion, "%s", json_object_get_string(json_object_object_get(SetNetworkProfile, "ocppVersion")));
+
+				if(json_object_object_get(SetNetworkProfile, "ocppTransport") != NULL)
+					sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.ocppTransport, "%s", json_object_get_string(json_object_object_get(SetNetworkProfile, "ocppTransport")));
+
+				if(json_object_object_get(SetNetworkProfile, "ocppCsmsUrl") != NULL)
+					sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.ocppCsmsUrl, "%s", json_object_get_string(json_object_object_get(SetNetworkProfile, "ocppCsmsUrl")));
+
+				if(json_object_object_get(SetNetworkProfile, "messageTimeout") != NULL)
+					ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.messageTimeout = json_object_get_int(json_object_object_get(SetNetworkProfile, "messageTimeout"));
+
+				if(json_object_object_get(SetNetworkProfile, "ocppInterface") != NULL)
+					sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.ocppInterface, "%s", json_object_get_string(json_object_object_get(SetNetworkProfile, "ocppInterface")));
+
+				if(json_object_object_get(SetNetworkProfile, "vpn") != NULL)
+				{
+					if(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "server") != NULL)
+						sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.vpn.server, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "server")));
+
+					if(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "user") != NULL)
+						sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.vpn.user, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "user")));
+
+					if(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "group") != NULL)
+						sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.vpn.group, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "group")));
+
+					if(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "password") != NULL)
+						sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.vpn.password, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "password")));
+
+					if(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "key") != NULL)
+						sprintf((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.key, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "key")));
+
+					if(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "type") != NULL)
+						sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.vpn.type, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "type")));
+				}
+
+				if(json_object_object_get(SetNetworkProfile, "apn") != NULL)
+				{
+					if(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "apn") != NULL)
+					{
+						memset(ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apn, 0x00, ARRAY_SIZE(ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apn));
+						sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apn, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "apn")));
+					}
+
+					if(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "apnUserName") != NULL)
+					{
+						memset(ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apnUserName, 0x00, ARRAY_SIZE(ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apnUserName));
+						sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apnUserName, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "apnUserName")));
+					}
+
+					if(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "apnPassword") != NULL)
+					{
+						memset(ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apnPassword, 0x00, ARRAY_SIZE(ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apnPassword));
+						sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apnPassword, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "apnPassword")));
+					}
+
+					if(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "simPin") != NULL)
+						ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.simPin = json_object_get_int(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "simPin"));
+
+					if(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "preferredNetwork") != NULL)
+						sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.preferredNetwork, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "preferredNetwork")));
+
+					if(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "useOnlyPreferredNetwork") != NULL)
+						ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.useOnlyPreferredNetwork = json_object_get_boolean(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "useOnlyPreferredNetwork"));
+
+					if(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "apnAuthentication") != NULL)
+						sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apnAuthentication, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "apnAuthentication")));
+				}
+			}
+			json_object_put(SetNetworkProfile);
+
+			ShmOCPP20Data->NetworkConnectionProfile[idx].slot = atoi(columnValue[1]);
+		}
+	}
+
+	return 0;
+}
+
+void DB_getNetworkProfileFromDb()
+{
+	char sql[512];
+	char* errMsg = NULL;
+
+	sprintf(sql,"select * from ocpp20_networkprofile order by slot;");
+
+	/* Execute SQL statement */
+	if(sqlite3_exec(db, sql, DB_cbGetNetworkProfileFromDb, 0, &errMsg) != SQLITE_OK )
 	{
 		DEBUG_INFO("SQL error: %s\n", errMsg);
 	}
 }
 
+int DB_addNetworkProfile(int slot, char *data)
+{
+	 int result = PASS;
+	 char sql[512];
+	 char* errMsg = NULL;
+
+	 sprintf(sql,"insert or replace into ocpp20_networkprofile (slot, connectionData) VALUES('%d', '%s');  SELECT * from ocpp20_networkprofile order by slot;",
+			 	 slot,
+				 data);
+
+	 //* Execute SQL statement */
+	 if(sqlite3_exec(db, sql, DB_cbGetNetworkProfileFromDb, 0, &errMsg) != SQLITE_OK)
+	 {
+		 DEBUG_INFO("SQL error: %s\n", errMsg);
+		 result = FAIL;
+	 }
+
+	 return result;
+}
+
+int DB_deleteNetworkProfile(int slot)
+{
+	int result = PASS;
+	char sql[512];
+	char* errMsg = NULL;
+
+	sprintf(sql,"DELETE from ocpp20_networkprofile where slot=%d; SELECT * from ocpp20_networkprofile order by slot;", slot);
+
+	//* Execute SQL statement */
+	if( sqlite3_exec(db, sql, DB_cbGetNetworkProfileFromDb, 0, &errMsg) != SQLITE_OK )
+	{
+		DEBUG_INFO("SQL error: %s", errMsg);
+		result = FAIL;
+	}
+
+	return result;
+}
 
 //==========================================
 // Check time passed since today
@@ -4664,6 +4841,44 @@ int isOFFline(void)
 	}
 }
 
+void checkNetworkProfile(void)
+{
+	uint8_t isGetProfile = FALSE;
+
+	json_object *priority;
+	priority = json_tokener_parse((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority].variableAttribute[0].value);
+	if(!is_error(priority))
+	{
+		for(uint8_t idxPriority=0;idxPriority<json_object_array_length(priority);idxPriority++)
+		{
+			for(uint8_t idx=0;idx<ARRAY_SIZE(ShmOCPP20Data->NetworkConnectionProfile);idx++)
+			{
+				if((ShmOCPP20Data->NetworkConnectionProfile[idx].slot == json_object_get_int(json_object_array_get_idx(priority, idxPriority))) &&
+				   (strlen((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.ocppCsmsUrl) > 0) &&
+				   (ShmOCPP20Data->NetworkConnectionProfile[idx].retryCount < 3))
+				{
+					memcpy(ShmOCPP20Data->OcppServerURL, ShmSysConfigAndInfo->SysConfig.OcppServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.OcppServerURL));
+					memcpy(ShmSysConfigAndInfo->SysConfig.OcppServerURL, ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.ocppCsmsUrl, ARRAY_SIZE(ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.ocppCsmsUrl));
+
+					isGetProfile = TRUE;
+					ShmOCPP20Data->NetworkConnectionProfile[idx].retryCount++;
+
+					break;
+				}
+			}
+		}
+	}
+	json_object_put(priority);
+
+
+	if(!isGetProfile && (strlen((char*)ShmOCPP20Data->OcppServerURL) > 0))
+	{
+		memcpy(ShmSysConfigAndInfo->SysConfig.OcppServerURL, ShmOCPP20Data->OcppServerURL, ARRAY_SIZE(ShmOCPP20Data->OcppServerURL));
+	}
+
+	DEBUG_INFO("Get network profile URL: %s\n", ShmSysConfigAndInfo->SysConfig.OcppServerURL);
+}
+
 void CheckSystemValue(void)
 {
 	char filenmae[100]={0};
@@ -4703,7 +4918,7 @@ void CheckSystemValue(void)
 	//===============================
 	// CSU Trigger Reset Conf
 	//===============================
-	if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->MsMsg.bits.ResetConf == ON))
+	if(isWebsocketSendable && (ShmOCPP20Data->MsMsg.bits.ResetConf == ON))
 	{
 		sendResetConfirmation((char *)ShmOCPP20Data->Reset.guid);
 	}
@@ -4728,7 +4943,7 @@ void CheckSystemValue(void)
 			(authorizeRetryTimes >= 3))
 	{
 		authorizeRetryTimes = 0;
-		ShmOCPP20Data->OcppConnStatus = 0;  // ocpp off-line
+		SetOcppConnStatus(FALSE);
 		server_sign = FALSE;
 	}
 	else if((server_sign == FALSE) &&
@@ -7721,7 +7936,7 @@ int sendTransactionEventRequest(int gun_index)
 				else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
 				{
 					if(strlen((char*)ShmOCPP20Data->TransactionEvent[index].transactionInfo.transactionId) == 0)
-						random_uuid(ShmOCPP20Data->TransactionEvent[index].transactionInfo.transactionId);
+						random_uuid((char*)ShmOCPP20Data->TransactionEvent[index].transactionInfo.transactionId);
 
 					sprintf((char*)ShmOCPP20Data->TransactionEvent[index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].StartUserId);
 
@@ -7826,7 +8041,7 @@ int sendTransactionEventRequest(int gun_index)
 				else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
 				{
 					if(strlen((char*)ShmOCPP20Data->TransactionEvent[index].transactionInfo.transactionId) == 0)
-						random_uuid(ShmOCPP20Data->TransactionEvent[index].transactionInfo.transactionId);
+						random_uuid((char*)ShmOCPP20Data->TransactionEvent[index].transactionInfo.transactionId);
 
 					sprintf((char*)ShmOCPP20Data->TransactionEvent[index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].StartUserId);
 
@@ -7930,7 +8145,7 @@ int sendTransactionEventRequest(int gun_index)
 				else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
 				{
 					if(strlen((char*)ShmOCPP20Data->TransactionEvent[index].transactionInfo.transactionId) == 0)
-						random_uuid(ShmOCPP20Data->TransactionEvent[index].transactionInfo.transactionId);
+						random_uuid((char*)ShmOCPP20Data->TransactionEvent[index].transactionInfo.transactionId);
 
 					sprintf((char*)ShmOCPP20Data->TransactionEvent[index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.GbChargingData[index].StartUserId);
 
@@ -8027,7 +8242,7 @@ int sendTransactionEventRequest(int gun_index)
 				else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
 				{
 					if(strlen((char*)ShmOCPP20Data->TransactionEvent[index].transactionInfo.transactionId) == 0)
-						random_uuid(ShmOCPP20Data->TransactionEvent[index].transactionInfo.transactionId);
+						random_uuid((char*)ShmOCPP20Data->TransactionEvent[index].transactionInfo.transactionId);
 
 					sprintf((char*)ShmOCPP20Data->TransactionEvent[index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.StartUserId);
 
@@ -8130,7 +8345,7 @@ int sendTransactionEventRequest(int gun_index)
 				else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
 				{
 					if(strlen((char*)ShmOCPP20Data->TransactionEvent[index].transactionInfo.transactionId) == 0)
-						random_uuid(ShmOCPP20Data->TransactionEvent[index].transactionInfo.transactionId);
+						random_uuid((char*)ShmOCPP20Data->TransactionEvent[index].transactionInfo.transactionId);
 
 					sprintf((char*)ShmOCPP20Data->TransactionEvent[index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.AcChargingData[index].StartUserId);
 
@@ -13457,8 +13672,12 @@ int handleSetNetworkProfileRequest(char *uuid, char *payload)
 				sprintf((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppTransport, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "ocppTransport")));
 
 			if(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "ocppCsmsUrl") != NULL)
+			{
 				sprintf((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppCsmsUrl, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "ocppCsmsUrl")));
 
+				memcpy((char*)ShmSysConfigAndInfo->SysConfig.OcppServerURL, (char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppCsmsUrl, ARRAY_SIZE(ShmOCPP20Data->SetNetworkProfile.connectionData.ocppCsmsUrl));
+			}
+
 			if(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "messageTimeout") != NULL)
 				ShmOCPP20Data->SetNetworkProfile.connectionData.messageTimeout = json_object_get_int(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "messageTimeout"));
 
@@ -13521,6 +13740,8 @@ int handleSetNetworkProfileRequest(char *uuid, char *payload)
 				if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "apn"), "apnAuthentication") != NULL)
 					sprintf((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnAuthentication, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "apn"), "apnAuthentication")));
 			}
+
+			DB_addNetworkProfile(ShmOCPP20Data->SetNetworkProfile.configurationSlot, (char*)json_object_get_string(json_object_object_get(SetNetworkProfile, "connectionData")));
 		}
 	}
 	json_object_put(SetNetworkProfile);
@@ -13820,20 +14041,24 @@ int handleSetVariablesRequest(char *uuid, char *payload)
 				{
 					sprintf((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue, "%s", json_object_get_string(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "attributeValue")));
 
+					strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_UnknownComponent]);
 					for(uint8_t idx_var=0;idx_var<CtrlrVariable_CNT;idx_var++)
 					{
-						if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, (char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].component.name) != NULL) &&
+						if((strstr((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].component.name, (char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name) != NULL) &&
 						   (strlen((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.instance)>0?(strstr((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].component.instance, (char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.instance) != NULL):TRUE) &&
-						   (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, (char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variable.name) != NULL) &&
+						   (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variable.name, (char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name) != NULL) &&
 						   (strlen((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.instance)>0?(strstr((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variable.instance, (char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.instance) != NULL):TRUE))
 						{
-							strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]);
 							strcpy((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableAttribute[0].value, (char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue);
 							DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[idx_var]);
-						}
-						else
-						{
-							strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_UnknownComponent]);
+
+
+							if(((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "OCPPCommCtrlr") != NULL)) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "NetworkConfigurationPriority") != NULL))
+							{
+								strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_RebootRequired]);
+							}
+							else
+								strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]);
 						}
 					}
 				}
@@ -14491,7 +14716,7 @@ void handleBootNotificationResponse(char *payload, int gun_index)
 	//==============================================
 	system("/sbin/hwclock -w --systohc");
 
-	ShmOCPP20Data->OcppConnStatus = ON; ////0: disconnected, 1: connected
+	SetOcppConnStatus(TRUE);
 	ShmOCPP20Data->SpMsg.bits.BootNotificationConf = ON;
 }
 
@@ -14883,6 +15108,7 @@ int initialConfigurationTable(void)
 	memset(&ShmOCPP20Data->ControllerComponentVariable[0], 0, ARRAY_SIZE(ShmOCPP20Data->ControllerComponentVariable));
 	DB_variableIsCreate();
 	DB_variableLoadFromDb();
+	DB_getNetworkProfileFromDb();
 
 	return 0;
 }
@@ -14978,6 +15204,7 @@ int httpDownLoadFile(char *location, char *path, char *filename,char *url)
 	//DEBUG_INFO("filename=%s\n",filename);
 	//DEBUG_INFO("url=%s\n",url);
 	sprintf(FilePath,"/mnt/%s",filename);
+	system("ping 8.8.8.8 &");
 
 	if((access(FilePath,F_OK))!=-1)
 	{
@@ -14997,6 +15224,7 @@ int httpDownLoadFile(char *location, char *path, char *filename,char *url)
 		return FALSE;
 	}
 
+	system("pkill ping");
 	return TRUE;
 }
 
@@ -15008,6 +15236,7 @@ int ftpDownLoadFile(char *location, char *user, char *password, int port, char *
 	int systemresult;
 	//char temp[100];
 	sprintf(FilePath,"/mnt/%s",filename);
+	system("ping 8.8.8.8 &");
 
 	if((access(FilePath,F_OK))!=-1)
 	{
@@ -15031,6 +15260,7 @@ int ftpDownLoadFile(char *location, char *user, char *password, int port, char *
 		return FALSE;
 	}
 
+	system("pkill ping");
 	return TRUE;
 
 }
@@ -15131,9 +15361,7 @@ int GetOcppServerURL()
 	if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
 	{
 		memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.OcppServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.OcppServerURL));
-#ifdef TEST_OCPP20
-		sprintf(urlStr, "ws://172.17.20.19:8080/"); // For test
-#endif
+
 		if(yuarel_parse(&url, urlStr) != -1)
 		{
 			sprintf(OcppProtocol, "%s", url.scheme);
@@ -15231,9 +15459,7 @@ int GetOcppPath()
 	{
 		strcpy(OcppPath,"");
 	}
-#ifdef TEST_OCPP20
-	sprintf(OcppPath,"/AWLU770001D1P0D19520001A0"); // For test
-#endif
+
 	return result;
 }
 
@@ -15535,7 +15761,7 @@ void InitialSystemValue(void)
 	gunTotalNumber=0;
 	SystemInitial = 0;
 	localversion=0;
-	BootNotificationInterval = 0;
+	BootNotificationInterval = 10;
 	authorizeRetryTimes = 0;
 	GunStatusInterval = 10;
 	TransactionMessageAttemptsValue = atoi((char *)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variableAttribute[0].value);

+ 30 - 7
EVSE/Modularization/ocpp20/Module_OcppBackend20.c

@@ -27,7 +27,6 @@ static int TransactionQueueNum = 0;
 static int OfflineTransactionQueueNum = 0;  // Number of offline transactions
 static int OfflineTransaction = 0;
 static int IsUsing = FALSE;
-int defaultWaitingTime = 10; //10 second
 
 char OcppPath[160]={0};
 char OcppProtocol[10]={0},OcppHost[50]={0}, OcppTempPath[50]={0};
@@ -323,6 +322,9 @@ static int OCPP20Callback(struct lws *wsi, enum lws_callback_reasons reason, voi
 		case LWS_CALLBACK_PROTOCOL_DESTROY:
 			DEBUG_INFO("LWS_CALLBACK_PROTOCOL_DESTROY\n");
 			break;
+		case LWS_CALLBACK_RECEIVE_PONG:
+			DEBUG_INFO("LWS_CALLBACK_RECEIVE_PONG\n");
+			break;
 		default:
 			DEBUG_INFO("Reason = %d\n", reason);
 			break;
@@ -350,7 +352,6 @@ static struct lws_protocols protocols[] =
 	}
 };
 
-
 void* ConnectWsServer(void* data)  //int ConnectWsServer()
 {
 
@@ -358,6 +359,16 @@ void* ConnectWsServer(void* data)  //int ConnectWsServer()
 	struct lws_client_connect_info ConnInfo;
 	int use_ssl=0;
 
+	// If internet available synchronize datetime with ntp server
+	if(GetInternetConn() == 1)
+	{
+		system("pkill ntpd");
+		DEBUG_INFO("NTP synchronize with Microsoft\n", system("/usr/sbin/ntpd -nqp time.windows.com &"));
+		DEBUG_INFO("NTP synchronize with China\n", system("/usr/sbin/ntpd -nqp cn.ntp.org.cn &"));
+		DEBUG_INFO("NTP synchronize with Taiwan\n", system("/usr/sbin/ntpd -nqp tock.stdtime.gov.tw &"));
+		DEBUG_INFO("NTP synchronize with Europe\n", system("/usr/sbin/ntpd -nqp 0.europe.pool.ntp.org &"));
+	}
+
 	if(context!=NULL)
 	{
 		pthread_detach(pthread_self());
@@ -366,6 +377,8 @@ void* ConnectWsServer(void* data)  //int ConnectWsServer()
 		context = NULL;
 	}
 
+	checkNetworkProfile();
+
 	memset(&ContextInfo, 0, sizeof(struct lws_context_creation_info));
 	if((GetOcppServerURL()==0) || (GetOcppPort() == 0) || (GetOcppPath()==0))
 	{
@@ -401,6 +414,10 @@ void* ConnectWsServer(void* data)  //int ConnectWsServer()
 	ContextInfo.protocols = protocols;
 	ContextInfo.timeout_secs = GetWebSocketPingInterval();//WebSocketPingInterval;//30;//9999;//30;
 	ContextInfo.ws_ping_pong_interval = GetWebSocketPingInterval();//WebSocketPingInterval;//30;//0 for none, else interval in seconds
+	ContextInfo.ka_time = 20;
+	ContextInfo.keepalive_timeout = 5;
+	ContextInfo.ka_probes = 2;
+	ContextInfo.ka_interval = 5;
 	context = lws_create_context(&ContextInfo);
 	if (context == NULL)
 	{
@@ -431,7 +448,15 @@ void* ConnectWsServer(void* data)  //int ConnectWsServer()
 	ConnInfo.ietf_version_or_minus_one = -1;
 
 	if(use_ssl)
+	{
+#ifdef TLS_VALID_CERT_EXPIRED
+		ConnInfo.ssl_connection = LCCSCF_USE_SSL | LCCSCF_ALLOW_SELFSIGNED | LCCSCF_SKIP_SERVER_CERT_HOSTNAME_CHECK;
+		DEBUG_INFO("TLS does not allow expired certification.\n");
+#else
 		ConnInfo.ssl_connection = LCCSCF_USE_SSL | LCCSCF_ALLOW_SELFSIGNED | LCCSCF_SKIP_SERVER_CERT_HOSTNAME_CHECK | LCCSCF_ALLOW_EXPIRED;
+		DEBUG_INFO("TLS allow expired certification.\n");
+#endif
+	}
 
 	wsi_client = lws_client_connect_via_info(&ConnInfo);
 	if (!wsi_client)
@@ -1146,7 +1171,7 @@ int main(void)
 		{
 			// Sign in
 			if((GetServerSign() == FALSE) &&
-			   ( ((GetBootNotificationInterval() != 0)  && ((time((time_t*)NULL)-startTime.bootNotification)>= GetBootNotificationInterval())) || ((time((time_t*)NULL)-startTime.bootNotification) >= defaultWaitingTime) ) )
+			   ((GetBootNotificationInterval() >= 0) && ((time((time_t*)NULL)-startTime.bootNotification)>= GetBootNotificationInterval())))
 			{
 				sendBootNotificationRequest();
 				startTime.bootNotification=time((time_t*)NULL);
@@ -1155,8 +1180,6 @@ int main(void)
 			// On line operation
 			if(GetServerSign() == TRUE)
 			{
-				SetOcppConnStatus(TRUE);
-
 				// Send message from queue
 				if((req_SendQueue == 1) && isWebsocketSendable)
 				{
@@ -1175,9 +1198,9 @@ int main(void)
 					SetHeartBeatWithNOResponse();
 				}
 
-				if((changeChageWebSocketPingInterval == TRUE) || (GetInternetConn() == 0))
+				if((changeChageWebSocketPingInterval == TRUE) || (GetOcppConnStatus() == 0))
 				{
-					DEBUG_INFO("GetInternetConn() = %d\n", GetInternetConn());
+					DEBUG_INFO("GetOcppConnStatus() = %d\n", GetOcppConnStatus());
 					changeChageWebSocketPingInterval = FALSE;
 					lws_context_destroy(context);
 					ConnectionEstablished = 0;

+ 1 - 0
EVSE/Modularization/ocpp20/Module_OcppBackend20.h

@@ -106,6 +106,7 @@ extern int yuarel_parse_query(char *query, char delimiter, struct yuarel_param *
 
 
 extern void CheckSystemValue(void);
+extern void checkNetworkProfile(void);
 extern int FirstHeartBeatResponse(void);
 extern void OCPP_get_TableAuthlocalAllData(void);
 extern int TransactionMessageAttemptsGet(void);

+ 1 - 1
EVSE/Modularization/ocpp20/SystemLogMessage.c

@@ -51,7 +51,7 @@ int StoreOcppMsg(const char *fmt, ...)
 	tm=localtime(&CurrentTime);
 	gettimeofday(&tv, NULL); // get microseconds, 10^-6
 
-	sprintf(Buf,"echo -n \"[%04d.%02d.%02d %02d:%02d:%02d.%06ld]%s\" >>  /Storage/OCPP/[%04d.%02d]Ocpp20MessageLog",
+	sprintf(Buf,"echo -n \'[%04d.%02d.%02d %02d:%02d:%02d.%06ld]%s\' >>  /Storage/OCPP/[%04d.%02d]Ocpp20MessageLog",
 			tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,tv.tv_usec,
 			buffer,
 			tm->tm_year+1900,tm->tm_mon+1);

+ 34 - 22
EVSE/Modularization/ocppfiles/MessageHandler.c

@@ -2345,7 +2345,7 @@ void CheckSystemValue(void)
 		else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
 		{
 			authorizeRetryTimes = 0;
-			ShmOCPP16Data->OcppConnStatus = 0;  // ocpp offline
+			SetOcppConnStatus(FALSE);
 			server_sign = FALSE;
 		}
 		else if((server_sign == FALSE) && (strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)&&(ShmOCPP16Data->OcppConnStatus == 0)&& (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1))
@@ -2371,6 +2371,7 @@ void CheckSystemValue(void)
 			sendStartTransactionRequest(gun_index);
 			clientTime.StartTransaction = time((time_t*)NULL);
 			clientTime.MeterValues[gun_index] = time((time_t*)NULL);
+			storeTempStopTransaction(gun_index);
 		}
 
 		//==============================================
@@ -2909,7 +2910,7 @@ void CheckSystemValue(void)
 					// 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
 					if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
 					{
-						if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)
+						if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
 						{
 							reqSampleMeter[gun_index] = 1;
 						}
@@ -4841,7 +4842,9 @@ int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
 	memset(&ShmOCPP16Data->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
 	//set value
 	ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
-	ShmOCPP16Data->MeterValues[gun_index].TransactionId = ((strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Charging") != NULL) ? ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId : -1);
+	ShmOCPP16Data->MeterValues[gun_index].TransactionId = (((strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Charging") != NULL) || (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "SuspendedEV") != NULL) || (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "SuspendedEVSE") != NULL) )?
+															ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId :
+															-1);
 
 	random_uuid(guid);
 
@@ -4988,7 +4991,7 @@ int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
 			{
 				if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
 				{
-					sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
+					sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
 				}
 			}
 
@@ -5009,7 +5012,7 @@ int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
 			{
 				if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
 				{
-					sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
+					sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
 				}
 			}
 
@@ -5030,7 +5033,7 @@ int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
 			{
 				if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
 				{
-					sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
+					sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
 				}
 			}
 
@@ -5045,7 +5048,7 @@ int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
 			{
 				if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
 				{
-					sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
+					sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
 				}
 			}
 
@@ -5066,7 +5069,7 @@ int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
 			{
 				if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
 				{
-					sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
+					sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
 				}
 			}
 
@@ -5099,7 +5102,7 @@ int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
 		{
 			if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
 			{
-				sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
+				sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
 			}
 		} // END OF FOR CHAdeMO_QUANTITY
 
@@ -5120,7 +5123,7 @@ int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
 		{
 			if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
 			{
-			   sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
+			   sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
 			}
 		} // END OF CCS_QUANTITY
 
@@ -5141,7 +5144,7 @@ int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
 		{
 			if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
 			{
-				sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
+				sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
 			}
 		} // END OF GB_QUANTITY
 
@@ -5155,7 +5158,7 @@ int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
 		{
 			if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
 			{
-				sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy);
+				sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy);
 			}
 		}
 
@@ -5176,7 +5179,7 @@ int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
 		{
 			if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
 			{
-				sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
+				sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
 			}
 		 }
 
@@ -9967,7 +9970,8 @@ int handleSetChargingProfileRequest(char *uuid, char *payload)
 			{
 				if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
 				{
-					if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
+					if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
+					   (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
 					{
 						if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
 						{
@@ -9993,7 +9997,8 @@ int handleSetChargingProfileRequest(char *uuid, char *payload)
 			{
 				if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
 				{
-					if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
+					if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
+					   (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
 					{
 						if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
 						{
@@ -10020,7 +10025,8 @@ int handleSetChargingProfileRequest(char *uuid, char *payload)
 			{
 				if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
 				{
-					if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
+					if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
+					   (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
 					{
 						if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
 						{
@@ -10039,7 +10045,8 @@ int handleSetChargingProfileRequest(char *uuid, char *payload)
 			{
 				if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
 				{
-					if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
+					if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
+					   (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
 					{
 						if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
 						{
@@ -10066,7 +10073,8 @@ int handleSetChargingProfileRequest(char *uuid, char *payload)
 			{
 				if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
 				{
-					if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
+					if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
+					   (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
 					{
 						if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
 						{
@@ -11013,7 +11021,7 @@ void handleBootNotificationResponse(char *payload, int gun_index)
 	//==============================================
 	system("/sbin/hwclock -w --systohc");
 
-	ShmOCPP16Data->OcppConnStatus = 1; ////0: disconnected, 1: connected
+	SetOcppConnStatus(TRUE);
 	ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
 }
 
@@ -14609,6 +14617,7 @@ int httpDownLoadFile(char *location, char *path, char *filename,char *url)
 	//DEBUG_INFO("filename=%s\n",filename);
 	//DEBUG_INFO("url=%s\n",url);
 	sprintf(FilePath,"/mnt/%s",filename);
+	system("ping 8.8.8.8 &");
 
 	if((access(FilePath,F_OK))!=-1)
 	{
@@ -14627,6 +14636,7 @@ int httpDownLoadFile(char *location, char *path, char *filename,char *url)
 		DEBUG_INFO("http DownLoad error!\n");
 		return FALSE;
 	}
+	system("pkill ping");
 
 	return TRUE;
 }
@@ -14639,6 +14649,7 @@ int ftpDownLoadFile(char *location, char *user, char *password, int port, char *
 	int systemresult;
 	//char temp[100];
 	sprintf(FilePath,"/mnt/%s",filename);
+	system("ping 8.8.8.8 &");
 
 	if((access(FilePath,F_OK))!=-1)
 	{
@@ -14662,6 +14673,7 @@ int ftpDownLoadFile(char *location, char *user, char *password, int port, char *
 		return FALSE;
 	}
 
+	system("pkill ping");
 	return TRUE;
 
 }
@@ -15228,7 +15240,7 @@ int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransact
 
 	temptransactionId = 0;
 
-	if((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0'))
+	if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
 	{
 		DEBUG_INFO("IdTag is empty.\n");
 		return temptransactionId;
@@ -16403,11 +16415,11 @@ void SetOcppVersion(uint8_t *version)
 	DEBUG_INFO("ocpp version: %s\n", version);
 	if(strstr((char*)version, "ocpp1.6") != NULL)
 	{
-		ShmSysConfigAndInfo->SysConfig.OcppRunningVer = OCPP_RUNNING_VERSION_16;
+		ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
 	}
 	else if(strstr((char*)version, "ocpp2.0") != NULL)
 	{
-		ShmSysConfigAndInfo->SysConfig.OcppRunningVer = OCPP_RUNNING_VERSION_20;
+		ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
 		system("pkill OcppBackend");
 	}
 }

+ 33 - 9
EVSE/Modularization/ocppfiles/Module_OcppBackend.c

@@ -29,8 +29,8 @@ static int OfflineTransaction = 0;
 static int IsUsing = FALSE;
 int defaultWaitingTime = 10; //10 second
 
-char OcppPath[160]={0};
-char OcppProtocol[10]={0},OcppHost[50]={0}, OcppTempPath[50]={0};
+char OcppPath[384]={0};
+char OcppProtocol[10]={0},OcppHost[128]={0}, OcppTempPath[256]={0};
 int OcppPort=0;
 unsigned char StartTransactionIdTagTemp[20]={0};
 uint32_t startTimeDog;
@@ -373,6 +373,9 @@ static int OCPP16Callback(struct lws *wsi, enum lws_callback_reasons reason, voi
 		case LWS_CALLBACK_PROTOCOL_DESTROY:
 			DEBUG_INFO("LWS_CALLBACK_PROTOCOL_DESTROY\n");
 			break;
+		case LWS_CALLBACK_RECEIVE_PONG:
+			DEBUG_INFO("LWS_CALLBACK_RECEIVE_PONG\n");
+			break;
 		default:
 			DEBUG_INFO("Reason = %d\n", reason);
 			break;
@@ -410,11 +413,20 @@ static struct lws_protocols protocols[] =
 
 void* ConnectWsServer(void* data)  //int ConnectWsServer()
 {
-
 	struct lws_context_creation_info ContextInfo;
 	struct lws_client_connect_info ConnInfo;
 	int use_ssl=0;
 
+	// If internet available synchronize datetime with ntp server
+	if(GetInternetConn() == 1)
+	{
+		system("pkill ntpd");
+		DEBUG_INFO("NTP synchronize with Microsoft\n", system("/usr/sbin/ntpd -nqp time.windows.com &"));
+		DEBUG_INFO("NTP synchronize with China\n", system("/usr/sbin/ntpd -nqp cn.ntp.org.cn &"));
+		DEBUG_INFO("NTP synchronize with Taiwan\n", system("/usr/sbin/ntpd -nqp tock.stdtime.gov.tw &"));
+		DEBUG_INFO("NTP synchronize with Europe\n", system("/usr/sbin/ntpd -nqp 0.europe.pool.ntp.org &"));
+	}
+
 	if(context!=NULL)
 	{
 		pthread_detach(pthread_self());
@@ -458,6 +470,11 @@ void* ConnectWsServer(void* data)  //int ConnectWsServer()
 	ContextInfo.protocols = protocols;
 	ContextInfo.timeout_secs = GetWebSocketPingInterval();//WebSocketPingInterval;//30;//9999;//30;
 	ContextInfo.ws_ping_pong_interval = GetWebSocketPingInterval();//WebSocketPingInterval;//30;//0 for none, else interval in seconds
+	ContextInfo.ka_time = 20;
+	ContextInfo.keepalive_timeout = 5;
+	ContextInfo.ka_probes = 2;
+	ContextInfo.ka_interval = 5;
+
 	context = lws_create_context(&ContextInfo);
 	if (context == NULL)
 	{
@@ -488,7 +505,16 @@ void* ConnectWsServer(void* data)  //int ConnectWsServer()
 	ConnInfo.ietf_version_or_minus_one = -1;
 
 	if(use_ssl)
+	{
+#ifdef TLS_VALID_CERT_EXPIRED
+		ConnInfo.ssl_connection = LCCSCF_USE_SSL | LCCSCF_ALLOW_SELFSIGNED | LCCSCF_SKIP_SERVER_CERT_HOSTNAME_CHECK;
+		DEBUG_INFO("TLS does not allow expired certification.\n");
+#else
 		ConnInfo.ssl_connection = LCCSCF_USE_SSL | LCCSCF_ALLOW_SELFSIGNED | LCCSCF_SKIP_SERVER_CERT_HOSTNAME_CHECK | LCCSCF_ALLOW_EXPIRED;
+		DEBUG_INFO("TLS allow expired certification.\n");
+#endif
+	}
+
 
 	wsi_client = lws_client_connect_via_info(&ConnInfo);
 	if (!wsi_client)
@@ -1089,12 +1115,12 @@ int sentqueue(){
 
 			//Get IdTag from StartTransaction , store to StartTransactionIdTagTemp, For StopTransaction usage in Queue (StartTransaction. StopTransaction user id different), get actual TransactionId
 			GetStartTransactionIdTag(tempconnectorId-1);
-			gettransactionId = GetTransactionId(tempconnectorId, (uint8_t *)StartTransactionIdTagTemp, IsStopTransaction);
+			gettransactionId = GetTransactionId(tempconnectorId, IdtagStr, IsStopTransaction);
 
 			DEBUG_INFO("queue map transactionId   = %d\n", gettransactionId);
 			DEBUG_INFO("original  connectorId     = %d\n", tempconnectorId);
 			DEBUG_INFO("original  transactionId   = %d\n", temptransactionId);
-			DEBUG_INFO("StartTransactionIdTagTemp = %s\n", StartTransactionIdTagTemp);
+			DEBUG_INFO("original  IdtagStr        = %s\n", IdtagStr);
 			if((gettransactionId != 0)&&(temptransactionId != gettransactionId))
 			{
 				//replace transactionId of metervalue or stopTransaction
@@ -1468,8 +1494,6 @@ int main(void)
 			// On line operation
 			if(GetServerSign() == TRUE)
 			{
-				SetOcppConnStatus(TRUE);
-
 				// Send message from queue
 				if((req_SendQueue == 1) && isWebsocketSendable)
 				{
@@ -1489,9 +1513,9 @@ int main(void)
 					DEBUG_WARN("Heartbeat re-send over 30 count.\n");
 				}
 
-				if((changeChageWebSocketPingInterval == TRUE) || ((GetInternetConn() == 0) && (GetOcppConnStatus() == 0)))
+				if((changeChageWebSocketPingInterval == TRUE) || (GetOcppConnStatus() == 0))
 				{
-					DEBUG_INFO("GetInternetConn() = %d\n", GetInternetConn());
+					DEBUG_INFO("GetOcppConnStatus() = %d\n", GetOcppConnStatus());
 
 					if(changeChageWebSocketPingInterval)
 					{

+ 3 - 3
EVSE/Modularization/ocppfiles/Module_OcppBackend.h

@@ -135,10 +135,10 @@ extern struct lws 					*wsi_client;
 extern struct lws_context 			*context;
 extern unsigned char 				SendBuffer[4096];
 extern int 							SendBufLen;
-extern char 						OcppPath[160];
+extern char 						OcppPath[384];
 extern char 						OcppProtocol[10];
-extern char 						OcppHost[50];
-extern char 						OcppTempPath[50];
+extern char 						OcppHost[128];
+extern char 						OcppTempPath[256];
 extern int 							OcppPort;
 extern unsigned char 				StartTransactionIdTagTemp[20];
 extern pthread_mutex_t 				lock_send;

+ 21 - 44
EVSE/Projects/AW-CCS/Apps/CCS/Module_CCS.c

@@ -701,49 +701,6 @@ double DiffTimeb_fork2_Error_Monitor(struct timeb ST, struct timeb ET)
     return t_diff;
 }
 
-int CreateShareMemory()
-{
-    int MeterSMId;
-
-    //create ShmSysConfigAndInfo
-    if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), IPC_CREAT | 0777)) < 0)
-    {
-        SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[main]CreateShareMemory:shmget ShmSysConfigAndInfo NG");
-        return 0;
-    }
-    else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
-    {
-        SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[main]CreateShareMemory:shmat ShmSysConfigAndInfo NG");
-        return 0;
-    }
-    memset(ShmSysConfigAndInfo,0,sizeof(struct SysConfigAndInfo));
-    //create ShmStatusCodeData
-    if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), IPC_CREAT | 0777)) < 0)
-    {
-        SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[main]CreateShareMemory:shmget ShmStatusCodeData NG");
-        return 0;
-    }
-    else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
-    {
-        SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[main]CreateShareMemory:shmat ShmStatusCodeData NG");
-        return 0;
-    }
-    memset(ShmStatusCodeData,0,sizeof(struct StatusCodeData));
-    //create ShmCcsData
-    if ((MeterSMId = shmget(ShmCcsCommKey, sizeof(struct CcsData), IPC_CREAT | 0777)) < 0)
-    {
-        SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[main]CreateShareMemory:shmget ShmCcsData NG");
-        return 0;
-    }
-    else if ((ShmCcsData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
-    {
-        SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[main]CreateShareMemory:shmat ShmCcsData NG");
-        return 0;
-    }
-    memset(ShmCcsData,0,sizeof(struct CcsData));
-    return 1;
-}
-
 /*===========================================================================
 FUNCTION: ShareMemory_Init
 DESCRIPTION:
@@ -1028,7 +985,7 @@ GLOBAL VARIABLES:
 =============================================================================*/
 void Qca7kPowerReset()
 {
-    printf("\n[CCS Board]Reset QCA7000...\n");
+    //printf("\n[CCS Board]Reset QCA7000...\n");
     system("echo 1 > /sys/class/gpio/gpio88/value");
     usleep(500000);
     system("echo 0 > /sys/class/gpio/gpio88/value");
@@ -3900,6 +3857,26 @@ int MmeProcess(unsigned char *Buffer, int DataLength)
             break;
 		}
 
+	    case MMTYPE_VENDOR_VS_PL_LNK_STATUS_CNF:
+		{
+			struct QcaVendorMmeHeader *RecvPacket;
+			RecvPacket = (struct QcaVendorMmeHeader *)Buffer;
+
+			if(RecvPacket->MBODY[1]==0)
+			{
+				//PLC disconnected
+				sprintf((char*)buf_log_evcomm,
+					"[QCA7K][Rx][MMTYPE_VENDOR_VS_PL_LNK_STATUS_CNF]Got PLC Link Status:%d",
+					RecvPacket->MBODY[1]);
+				SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
+				Update_V2G_Flow_Status(Other_Fault);
+			}
+			else
+				Update_V2G_Flow_Status(CM_SET_KEY_REQ);
+		ftime(&SeqStartTime);
+			break;
+		}
+
 	    default:
 		{
 	        break;

+ 19 - 17
EVSE/Projects/AW-CCS/Apps/CCS/Module_CCS.h

@@ -67,24 +67,26 @@
 /***********************************************/
 /*** MMTYPE (Management Message Type) **/
 /**********************************************/
-#define MMTYPE_CM_SET_KEY_REQ				0x6008
-#define MMTYPE_CM_SET_KEY_CNF				0x6009
-#define MMTYPE_CM_SLAC_PARM_REQ				0x6064
-#define MMTYPE_CM_SLAC_PARM_CNF				0x6065
-#define MMTYPE_CM_START_ATTEN_CHAR_IND		0x606A
-#define MMTYPE_CM_MNBC_SOUND_IND			0x6076
-#define MMTYPE_CM_ATTEN_CHAR_IND			0x606E
-#define MMTYPE_CM_ATTEN_CHAR_RSP			0x606F
-#define MMTYPE_CM_VALIDATE_REQ				0x6078
-#define MMTYPE_CM_VALIDATE_CNF				0x6079
-#define MMTYPE_CM_SLAC_MATCH_REQ			0x607C
-#define MMTYPE_CM_SLAC_MATCH_CNF			0x607D
-#define MMTYPE_CM_ATTEN_PROFILE_IND			0x6086
+#define MMTYPE_CM_SET_KEY_REQ					0x6008
+#define MMTYPE_CM_SET_KEY_CNF					0x6009
+#define MMTYPE_CM_SLAC_PARM_REQ					0x6064
+#define MMTYPE_CM_SLAC_PARM_CNF					0x6065
+#define MMTYPE_CM_START_ATTEN_CHAR_IND			0x606A
+#define MMTYPE_CM_MNBC_SOUND_IND				0x6076
+#define MMTYPE_CM_ATTEN_CHAR_IND				0x606E
+#define MMTYPE_CM_ATTEN_CHAR_RSP				0x606F
+#define MMTYPE_CM_VALIDATE_REQ					0x6078
+#define MMTYPE_CM_VALIDATE_CNF					0x6079
+#define MMTYPE_CM_SLAC_MATCH_REQ				0x607C
+#define MMTYPE_CM_SLAC_MATCH_CNF				0x607D
+#define MMTYPE_CM_ATTEN_PROFILE_IND				0x6086
 //following are the vendor specific type
-#define MMTYPE_VENDOR_VS_HOST_ACTION	 	0xA062		//Embedded Host Action Requested Indication MME
-#define MMTYPE_VENDOR_ATTEN_CHAR			0xA14E		//Attenuation Characteristics MME (VS_ATTEN_CHAR)
-#define MMTYPE_VENDOR_VS_NW_INFO			0xA038		//Network Info MME
-#define MMTYPE_VENDOR_VS_NW_INFO_CNF		0xA039		//Network Info MME
+#define MMTYPE_VENDOR_VS_HOST_ACTION	 		0xA062		//Embedded Host Action Requested Indication MME
+#define MMTYPE_VENDOR_ATTEN_CHAR				0xA14E		//Attenuation Characteristics MME (VS_ATTEN_CHAR)
+#define MMTYPE_VENDOR_VS_NW_INFO				0xA038		//Network Info MME
+#define MMTYPE_VENDOR_VS_NW_INFO_CNF			0xA039		//Network Info MME
+#define MMTYPE_VENDOR_VS_PL_LNK_STATUS       	0xA0B8      //Powerline Link Status /*+++ 20200808, vern, for PLC connection monitoring ---*/
+#define MMTYPE_VENDOR_VS_PL_LNK_STATUS_CNF    	0xA0B9      //Powerline Link Status /*+++ 20200808, vern, for PLC connection monitoring ---*/
 
 /***********************************************/
 /************** V2GTP Payload Type ************/

+ 17 - 0
EVSE/Projects/AW-CCS/Apps/Module_InternalComm.c

@@ -660,6 +660,7 @@ unsigned char Query_Gpio_Input(unsigned char fd, unsigned char targetAddr, Gpio_
 			Ret_Buf->Button[0] 			= (rx[6] >> 6) & 0x01;
 			Ret_Buf->Button[1] 			= (rx[6] >> 7) & 0x01;
 			Ret_Buf->Button_Emergency	= (rx[7] >> 0) & 0x01;
+			Ret_Buf->Button_Mode_Switch = (rx[7] >> 7) & 0x01;
 
 			result = PASS;
 		}
@@ -2248,6 +2249,22 @@ int main(void)
 					}
 				}
 
+				//===============================
+				// Case 9 : Query GPIO
+				//===============================
+				if(Query_Gpio_Input(Uart1Fd, (gun_index>0?ADDR_AC_PRIMARY_2:ADDR_AC_PRIMARY_1), &ShmCharger->gun_info[gun_index].GPIO_Input))
+				{
+					failCount[gun_index] = 0;
+				}
+				else
+				{
+					DEBUG_WARN("MCU-%d get GPIO input fail...%d\n", gun_index, failCount[gun_index]);
+					if(failCount[gun_index]<USHRT_MAX)
+						failCount[gun_index]++;
+					else
+						failCount[gun_index] = FAIL_SPEC_COMM;
+				}
+
 				//==========================================================
 				// High priority polling log print out
 				//==========================================================

+ 138 - 109
EVSE/Projects/AW-CCS/Apps/main.c

@@ -246,7 +246,7 @@ unsigned int isKernelSupportNAT()
 		if(fgets(buf, sizeof(buf), fp) != NULL)
 		{
 			sscanf(buf, "#%d", &version);
-			DEBUG_INFO("Kernel version: %d\n", version);
+			//DEBUG_INFO("Kernel version: %d\n", version);
 
 			if(version >= 30)
 				result = YES;
@@ -261,9 +261,9 @@ unsigned int isKernelSupportNAT()
 //======================================================
 void ocpp_process_start()
 {
-	if(ShmSysConfigAndInfo->SysConfig.OcppRunningVer == OCPP_RUNNING_VERSION_16)
+	if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
 		system("/root/OcppBackend &");
-	else if(ShmSysConfigAndInfo->SysConfig.OcppRunningVer == OCPP_RUNNING_VERSION_20)
+	else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
 		system("/root/OcppBackend20 &");
 }
 
@@ -271,11 +271,11 @@ uint8_t ocpp_get_connection_status()
 {
 	uint8_t result = OFF;
 
-	if(ShmSysConfigAndInfo->SysConfig.OcppRunningVer == OCPP_RUNNING_VERSION_16)
+	if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
 	{
 		result = ShmOCPP16Data->OcppConnStatus;
 	}
-	else if(ShmSysConfigAndInfo->SysConfig.OcppRunningVer == OCPP_RUNNING_VERSION_20)
+	else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
 	{
 		result = ShmOCPP20Data->OcppConnStatus;
 	}
@@ -287,14 +287,14 @@ uint16_t ocpp_get_connection_timeout()
 {
 	uint16_t result = (TIMEOUT_SPEC_HANDSHAKING/1000);
 
-	if(ShmSysConfigAndInfo->SysConfig.OcppRunningVer == OCPP_RUNNING_VERSION_16)
+	if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
 	{
 		if(strcmp((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData,"") != 0)
 		{
 			result = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
 		}
 	}
-	else if(ShmSysConfigAndInfo->SysConfig.OcppRunningVer == OCPP_RUNNING_VERSION_20)
+	else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
 	{
 		if(strcmp((char *)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variableAttribute[0].value,"") != 0)
 		{
@@ -309,11 +309,11 @@ uint8_t ocpp_get_update_firmware_req()
 {
 	uint8_t result = NO;
 
-	if(ShmSysConfigAndInfo->SysConfig.OcppRunningVer == OCPP_RUNNING_VERSION_16)
+	if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
 	{
 		result = ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq;
 	}
-	else if(ShmSysConfigAndInfo->SysConfig.OcppRunningVer == OCPP_RUNNING_VERSION_20)
+	else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
 	{
 		result = ShmOCPP20Data->MsMsg.bits.UpdateFirmwareReq;
 	}
@@ -325,11 +325,11 @@ uint8_t ocpp_get_reset_req()
 {
 	uint8_t result = NO;
 
-	if(ShmSysConfigAndInfo->SysConfig.OcppRunningVer == OCPP_RUNNING_VERSION_16)
+	if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
 	{
 		result = ShmOCPP16Data->MsMsg.bits.ResetReq;
 	}
-	else if(ShmSysConfigAndInfo->SysConfig.OcppRunningVer == OCPP_RUNNING_VERSION_20)
+	else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
 	{
 		result = ShmOCPP20Data->MsMsg.bits.ResetReq;
 	}
@@ -339,7 +339,7 @@ uint8_t ocpp_get_reset_req()
 
 void ocpp_boot_info_sync()
 {
-	if(ShmSysConfigAndInfo->SysConfig.OcppRunningVer == OCPP_RUNNING_VERSION_16)
+	if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
 	{
 		memcpy((char*)ShmOCPP16Data->OcppServerURL, (char*)ShmSysConfigAndInfo->SysConfig.OcppServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.OcppServerURL));
 		memcpy((char*)ShmOCPP16Data->ChargeBoxId, (char*)ShmSysConfigAndInfo->SysConfig.ChargeBoxId, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.ChargeBoxId));
@@ -351,7 +351,7 @@ void ocpp_boot_info_sync()
 		DEBUG_INFO("CpMeterSerialNumber: %s\n",ShmOCPP16Data->BootNotification.CpMeterSerialNumber);
 		DEBUG_INFO("CpMeterType: %s\n",ShmOCPP16Data->BootNotification.CpMeterType);
 	}
-	else if(ShmSysConfigAndInfo->SysConfig.OcppRunningVer == OCPP_RUNNING_VERSION_20)
+	else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
 	{
 		memcpy((char*)ShmOCPP20Data->OcppServerURL, (char*)ShmSysConfigAndInfo->SysConfig.OcppServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.OcppServerURL));
 		memcpy((char*)ShmOCPP20Data->ChargeBoxId, (char*)ShmSysConfigAndInfo->SysConfig.ChargeBoxId, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.ChargeBoxId));
@@ -361,12 +361,12 @@ void ocpp_boot_info_sync()
 
 void ocpp_set_remotestart(uint8_t gun_index, uint8_t status)
 {
-	if(ShmSysConfigAndInfo->SysConfig.OcppRunningVer == OCPP_RUNNING_VERSION_16)
+	if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
 	{
 		if(ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStartTransactionReq != status)
 			ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStartTransactionReq = status;
 	}
-	else if(ShmSysConfigAndInfo->SysConfig.OcppRunningVer == OCPP_RUNNING_VERSION_20)
+	else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
 	{
 		if(ShmOCPP20Data->CsMsg.bits[gun_index].RequestStartTransactionReq != status)
 			ShmOCPP20Data->CsMsg.bits[gun_index].RequestStartTransactionReq = status;
@@ -375,12 +375,12 @@ void ocpp_set_remotestart(uint8_t gun_index, uint8_t status)
 
 void ocpp_set_remotestop(uint8_t gun_index, uint8_t status)
 {
-	if(ShmSysConfigAndInfo->SysConfig.OcppRunningVer == OCPP_RUNNING_VERSION_16)
+	if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
 	{
 		if(ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStopTransactionReq != status)
 			ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStopTransactionReq = status;
 	}
-	else if(ShmSysConfigAndInfo->SysConfig.OcppRunningVer == OCPP_RUNNING_VERSION_20)
+	else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
 	{
 		if(ShmOCPP20Data->CsMsg.bits[gun_index].RequestStopTransactionReq != status)
 			ShmOCPP20Data->CsMsg.bits[gun_index].RequestStopTransactionReq = status;
@@ -391,11 +391,11 @@ uint8_t ocpp_get_remotestart(uint8_t gun_index)
 {
 	uint8_t result = OFF;
 
-	if(ShmSysConfigAndInfo->SysConfig.OcppRunningVer == OCPP_RUNNING_VERSION_16)
+	if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
 	{
 		result = ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStartTransactionReq;
 	}
-	else if(ShmSysConfigAndInfo->SysConfig.OcppRunningVer == OCPP_RUNNING_VERSION_20)
+	else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
 	{
 		result = ShmOCPP20Data->CsMsg.bits[gun_index].RequestStartTransactionReq;
 	}
@@ -405,11 +405,11 @@ uint8_t ocpp_get_remotestart(uint8_t gun_index)
 
 void ocpp_copy_userid_from_remotestart(uint8_t gun_index)
 {
-	if(ShmSysConfigAndInfo->SysConfig.OcppRunningVer == OCPP_RUNNING_VERSION_16)
+	if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
 	{
 		memcpy(ShmSysConfigAndInfo->SysConfig.UserId, ShmOCPP16Data->RemoteStartTransaction[gun_index].IdTag, ARRAY_SIZE(ShmOCPP16Data->RemoteStartTransaction[gun_index].IdTag));
 	}
-	else if(ShmSysConfigAndInfo->SysConfig.OcppRunningVer == OCPP_RUNNING_VERSION_20)
+	else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
 	{
 		memcpy(ShmSysConfigAndInfo->SysConfig.UserId, ShmOCPP20Data->RequestStartTransaction[gun_index].idToken.idToken, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.UserId));
 	}
@@ -419,11 +419,11 @@ uint8_t ocpp_get_remotestop(uint8_t gun_index)
 {
 	uint8_t result = OFF;
 
-	if(ShmSysConfigAndInfo->SysConfig.OcppRunningVer == OCPP_RUNNING_VERSION_16)
+	if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
 	{
 		result = ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStopTransactionReq;
 	}
-	else if(ShmSysConfigAndInfo->SysConfig.OcppRunningVer == OCPP_RUNNING_VERSION_20)
+	else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
 	{
 		result = ShmOCPP20Data->CsMsg.bits[gun_index].RequestStopTransactionReq;
 	}
@@ -433,7 +433,7 @@ uint8_t ocpp_get_remotestop(uint8_t gun_index)
 
 void ocpp_set_auth_req(uint8_t status)
 {
-	if(ShmSysConfigAndInfo->SysConfig.OcppRunningVer == OCPP_RUNNING_VERSION_16)
+	if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
 	{
 		if(ShmOCPP16Data->SpMsg.bits.AuthorizeReq != status)
 		{
@@ -443,7 +443,7 @@ void ocpp_set_auth_req(uint8_t status)
 			ShmOCPP16Data->SpMsg.bits.AuthorizeReq = status;
 		}
 	}
-	else if(ShmSysConfigAndInfo->SysConfig.OcppRunningVer == OCPP_RUNNING_VERSION_20)
+	else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
 	{
 		if(ShmOCPP20Data->SpMsg.bits.AuthorizeReq != status)
 		{
@@ -459,11 +459,11 @@ uint8_t ocpp_get_auth_req()
 {
 	uint8_t result = OFF;
 
-	if(ShmSysConfigAndInfo->SysConfig.OcppRunningVer == OCPP_RUNNING_VERSION_16)
+	if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
 	{
 		result = ShmOCPP16Data->SpMsg.bits.AuthorizeReq;
 	}
-	else if(ShmSysConfigAndInfo->SysConfig.OcppRunningVer == OCPP_RUNNING_VERSION_20)
+	else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
 	{
 		result = ShmOCPP20Data->SpMsg.bits.AuthorizeReq;
 	}
@@ -473,12 +473,12 @@ uint8_t ocpp_get_auth_req()
 
 void ocpp_set_auth_conf(uint8_t status)
 {
-	if(ShmSysConfigAndInfo->SysConfig.OcppRunningVer == OCPP_RUNNING_VERSION_16)
+	if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
 	{
 		if(ShmOCPP16Data->SpMsg.bits.AuthorizeConf != status)
 			ShmOCPP16Data->SpMsg.bits.AuthorizeConf = status;
 	}
-	else if(ShmSysConfigAndInfo->SysConfig.OcppRunningVer == OCPP_RUNNING_VERSION_20)
+	else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
 	{
 		if(ShmOCPP20Data->SpMsg.bits.AuthorizeConf != status)
 			ShmOCPP20Data->SpMsg.bits.AuthorizeConf = status;
@@ -489,11 +489,11 @@ uint8_t ocpp_get_auth_conf()
 {
 	uint8_t result = OFF;
 
-	if(ShmSysConfigAndInfo->SysConfig.OcppRunningVer == OCPP_RUNNING_VERSION_16)
+	if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
 	{
 		result = ShmOCPP16Data->SpMsg.bits.AuthorizeConf;
 	}
-	else if(ShmSysConfigAndInfo->SysConfig.OcppRunningVer == OCPP_RUNNING_VERSION_20)
+	else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
 	{
 		result = ShmOCPP20Data->SpMsg.bits.AuthorizeConf;
 	}
@@ -505,12 +505,12 @@ uint8_t ocpp_get_auth_result()
 {
 	uint8_t result = OFF;
 
-	if(ShmSysConfigAndInfo->SysConfig.OcppRunningVer == OCPP_RUNNING_VERSION_16)
+	if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
 	{
 		if((strcmp((char*)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted")==0))
 			result = PASS;
 	}
-	else if(ShmSysConfigAndInfo->SysConfig.OcppRunningVer == OCPP_RUNNING_VERSION_20)
+	else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
 	{
 		if((strcmp((char*)ShmOCPP20Data->Authorize.Response_idTokenInfo.status, "Accepted")==0))
 			result = PASS;
@@ -523,11 +523,11 @@ uint8_t ocpp_get_unlocker_req(uint8_t gun_index)
 {
 	uint8_t result = OFF;
 
-	if(ShmSysConfigAndInfo->SysConfig.OcppRunningVer == OCPP_RUNNING_VERSION_16)
+	if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
 	{
 		result = ShmCharger->gun_info[ShmOCPP16Data->UnlockConnector[gun_index].ConnectorId-1].isUnlockerConnetor;
 	}
-	else if(ShmSysConfigAndInfo->SysConfig.OcppRunningVer == OCPP_RUNNING_VERSION_20)
+	else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
 	{
 		result = ShmCharger->gun_info[ShmOCPP20Data->UnlockConnector[gun_index].connectorId-1].isUnlockerConnetor;
 	}
@@ -537,12 +537,12 @@ uint8_t ocpp_get_unlocker_req(uint8_t gun_index)
 
 void ocpp_set_unlocker_req(uint8_t gun_index, uint8_t status)
 {
-	if(ShmSysConfigAndInfo->SysConfig.OcppRunningVer == OCPP_RUNNING_VERSION_16)
+	if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
 	{
 		if(ShmCharger->gun_info[ShmOCPP16Data->UnlockConnector[gun_index].ConnectorId-1].isUnlockerConnetor != status)
 			ShmCharger->gun_info[ShmOCPP16Data->UnlockConnector[gun_index].ConnectorId-1].isUnlockerConnetor = status;
 	}
-	else if(ShmSysConfigAndInfo->SysConfig.OcppRunningVer == OCPP_RUNNING_VERSION_20)
+	else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
 	{
 		if(ShmCharger->gun_info[ShmOCPP20Data->UnlockConnector[gun_index].connectorId-1].isUnlockerConnetor != status)
 			ShmCharger->gun_info[ShmOCPP20Data->UnlockConnector[gun_index].connectorId-1].isUnlockerConnetor = status;
@@ -551,12 +551,12 @@ void ocpp_set_unlocker_req(uint8_t gun_index, uint8_t status)
 
 void ocpp_set_starttransaction_req(uint8_t gun_index, uint8_t status)
 {
-	if(ShmSysConfigAndInfo->SysConfig.OcppRunningVer == OCPP_RUNNING_VERSION_16)
+	if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
 	{
 		if(ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq != status)
 			ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = status;
 	}
-	else if(ShmSysConfigAndInfo->SysConfig.OcppRunningVer == OCPP_RUNNING_VERSION_20)
+	else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
 	{
 		if(ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq != status)
 			ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq = status;
@@ -565,12 +565,12 @@ void ocpp_set_starttransaction_req(uint8_t gun_index, uint8_t status)
 
 void ocpp_set_starttransaction_conf(uint8_t gun_index, uint8_t status)
 {
-	if(ShmSysConfigAndInfo->SysConfig.OcppRunningVer == OCPP_RUNNING_VERSION_16)
+	if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
 	{
 		if(ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf != status)
 			ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = status;
 	}
-	else if(ShmSysConfigAndInfo->SysConfig.OcppRunningVer == OCPP_RUNNING_VERSION_20)
+	else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
 	{
 		if(ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventConf != status)
 			ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventConf = status;
@@ -579,12 +579,12 @@ void ocpp_set_starttransaction_conf(uint8_t gun_index, uint8_t status)
 
 void ocpp_set_stoptransaction_req(uint8_t gun_index, uint8_t status)
 {
-	if(ShmSysConfigAndInfo->SysConfig.OcppRunningVer == OCPP_RUNNING_VERSION_16)
+	if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
 	{
 		if(ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq != status)
 			ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = status;
 	}
-	else if(ShmSysConfigAndInfo->SysConfig.OcppRunningVer == OCPP_RUNNING_VERSION_20)
+	else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
 	{
 		if(ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq != status)
 			ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq = status;
@@ -593,14 +593,14 @@ void ocpp_set_stoptransaction_req(uint8_t gun_index, uint8_t status)
 
 void ocpp_set_stoptransaction_conf(uint8_t gun_index, uint8_t status)
 {
-	if(ShmSysConfigAndInfo->SysConfig.OcppRunningVer == OCPP_RUNNING_VERSION_16)
+	if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
 	{
 		if(ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf != status)
 		{
 			ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = status;
 		}
 	}
-	else if(ShmSysConfigAndInfo->SysConfig.OcppRunningVer == OCPP_RUNNING_VERSION_20)
+	else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
 	{
 		if(ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventConf != status)
 		{
@@ -611,11 +611,11 @@ void ocpp_set_stoptransaction_conf(uint8_t gun_index, uint8_t status)
 
 void ocpp_copy_userid_to_starttransaction(uint8_t gun_index)
 {
-	if(ShmSysConfigAndInfo->SysConfig.OcppRunningVer == OCPP_RUNNING_VERSION_16)
+	if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
 	{
 		memcpy((char*)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (char*)ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartUserId, ARRAY_SIZE(ShmOCPP16Data->StartTransaction[gun_index].IdTag));
 	}
-	else if(ShmSysConfigAndInfo->SysConfig.OcppRunningVer == OCPP_RUNNING_VERSION_20)
+	else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
 	{
 		memcpy((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, (char*)ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartUserId, ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartUserId));
 	}
@@ -625,11 +625,11 @@ uint8_t ocpp_get_smartcharging_profileId(uint8_t gun_index)
 {
 	uint8_t result = 0;
 
-	if(ShmSysConfigAndInfo->SysConfig.OcppRunningVer == OCPP_RUNNING_VERSION_16)
+	if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
 	{
 		result = ShmOCPP16Data->SmartChargingProfile[gun_index].ChargingProfileId;
 	}
-	else if(ShmSysConfigAndInfo->SysConfig.OcppRunningVer == OCPP_RUNNING_VERSION_20)
+	else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
 	{
 		result = ShmOCPP20Data->SmartChargingProfile[gun_index].id;
 	}
@@ -639,11 +639,11 @@ uint8_t ocpp_get_smartcharging_profileId(uint8_t gun_index)
 
 void ocpp_reset_smartcharging_profileId(uint8_t gun_index)
 {
-	if(ShmSysConfigAndInfo->SysConfig.OcppRunningVer == OCPP_RUNNING_VERSION_16)
+	if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
 	{
 		ShmOCPP16Data->SmartChargingProfile[gun_index].ChargingProfileId = 0;
 	}
-	else if(ShmSysConfigAndInfo->SysConfig.OcppRunningVer == OCPP_RUNNING_VERSION_20)
+	else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
 	{
 		ShmOCPP20Data->SmartChargingProfile[gun_index].id = 0;
 	}
@@ -653,11 +653,11 @@ uint8_t ocpp_get_profile_req(uint8_t gun_index)
 {
 	uint8_t result = OFF;
 
-	if(ShmSysConfigAndInfo->SysConfig.OcppRunningVer == OCPP_RUNNING_VERSION_16)
+	if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
 	{
 		result = ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq;
 	}
-	else if(ShmSysConfigAndInfo->SysConfig.OcppRunningVer == OCPP_RUNNING_VERSION_20)
+	else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
 	{
 		result = ShmOCPP20Data->CSUMsg.bits[gun_index].ChargingProfileReq;
 	}
@@ -667,12 +667,12 @@ uint8_t ocpp_get_profile_req(uint8_t gun_index)
 
 void ocpp_set_profile_req(uint8_t gun_index, uint8_t status)
 {
-	if(ShmSysConfigAndInfo->SysConfig.OcppRunningVer == OCPP_RUNNING_VERSION_16)
+	if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
 	{
 		if(ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq != status)
 			ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = status;
 	}
-	else if(ShmSysConfigAndInfo->SysConfig.OcppRunningVer == OCPP_RUNNING_VERSION_20)
+	else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
 	{
 		if(ShmOCPP20Data->CSUMsg.bits[gun_index].ChargingProfileReq != status)
 			ShmOCPP20Data->CSUMsg.bits[gun_index].ChargingProfileReq = status;
@@ -683,11 +683,11 @@ uint8_t ocpp_get_profile_conf(uint8_t gun_index)
 {
 	uint8_t result = OFF;
 
-	if(ShmSysConfigAndInfo->SysConfig.OcppRunningVer == OCPP_RUNNING_VERSION_16)
+	if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
 	{
 		result = ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileConf;
 	}
-	else if(ShmSysConfigAndInfo->SysConfig.OcppRunningVer == OCPP_RUNNING_VERSION_20)
+	else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
 	{
 		result = ShmOCPP20Data->CSUMsg.bits[gun_index].ChargingProfileConf;
 	}
@@ -697,12 +697,12 @@ uint8_t ocpp_get_profile_conf(uint8_t gun_index)
 
 void ocpp_set_profile_conf(uint8_t gun_index, uint8_t status)
 {
-	if(ShmSysConfigAndInfo->SysConfig.OcppRunningVer == OCPP_RUNNING_VERSION_16)
+	if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
 	{
 		if(ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileConf != status)
 			ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileConf = status;
 	}
-	else if(ShmSysConfigAndInfo->SysConfig.OcppRunningVer == OCPP_RUNNING_VERSION_20)
+	else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
 	{
 		if(ShmOCPP20Data->CSUMsg.bits[gun_index].ChargingProfileConf != status)
 			ShmOCPP20Data->CSUMsg.bits[gun_index].ChargingProfileConf = status;
@@ -713,12 +713,12 @@ uint8_t ocpp_get_StopTransactionOnEVSideDisconnect()
 {
 	uint8_t result = OFF;
 
-	if(ShmSysConfigAndInfo->SysConfig.OcppRunningVer == OCPP_RUNNING_VERSION_16)
+	if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
 	{
 		if(strcmp((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE") == 0)
 			result = ON;
 	}
-	else if(ShmSysConfigAndInfo->SysConfig.OcppRunningVer == OCPP_RUNNING_VERSION_20)
+	else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
 	{
 		if(strcmp((char *)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnEVSideDisconnect].variableAttribute[0].value, "TRUE") == 0)
 			result = ON;
@@ -731,11 +731,11 @@ uint8_t ocpp_get_cancelreservation_req(uint8_t gun_index)
 {
 	uint8_t result = OFF;
 
-	if(ShmSysConfigAndInfo->SysConfig.OcppRunningVer == OCPP_RUNNING_VERSION_16)
+	if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
 	{
 		result = ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationReq;
 	}
-	else if(ShmSysConfigAndInfo->SysConfig.OcppRunningVer == OCPP_RUNNING_VERSION_20)
+	else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
 	{
 		result = ShmOCPP20Data->CsMsg.bits[gun_index].CancelReservationReq;
 	}
@@ -745,7 +745,7 @@ uint8_t ocpp_get_cancelreservation_req(uint8_t gun_index)
 
 void ocpp_set_cancelreservation_req(uint8_t gun_index, uint8_t status)
 {
-	if(ShmSysConfigAndInfo->SysConfig.OcppRunningVer == OCPP_RUNNING_VERSION_16)
+	if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
 	{
 		if(ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationReq != status)
 			ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationReq = status;
@@ -753,7 +753,7 @@ void ocpp_set_cancelreservation_req(uint8_t gun_index, uint8_t status)
 		if(ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationReq == OFF)
 			ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf = ON;
 	}
-	else if(ShmSysConfigAndInfo->SysConfig.OcppRunningVer == OCPP_RUNNING_VERSION_20)
+	else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
 	{
 		if(ShmOCPP20Data->CsMsg.bits[gun_index].CancelReservationReq != status)
 			ShmOCPP20Data->CsMsg.bits[gun_index].CancelReservationReq = status;
@@ -767,12 +767,12 @@ uint8_t ocpp_compare_reserve_id_with_user(uint8_t gun_index)
 {
 	uint8_t result = OFF;
 
-	if(ShmSysConfigAndInfo->SysConfig.OcppRunningVer == OCPP_RUNNING_VERSION_16)
+	if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
 	{
 		if(strcmp((char*)ShmSysConfigAndInfo->SysConfig.UserId, (char*)ShmOCPP16Data->ReserveNow[gun_index].IdTag) == 0)
 			result = ON;
 	}
-	else if(ShmSysConfigAndInfo->SysConfig.OcppRunningVer == OCPP_RUNNING_VERSION_20)
+	else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
 	{
 		if(strcmp((char*)ShmSysConfigAndInfo->SysConfig.UserId, (char*)ShmOCPP20Data->ReserveNow[gun_index].idToken.idToken) == 0)
 			result = ON;
@@ -785,7 +785,7 @@ uint8_t ocpp_compare_reserve_id_with_remote_user(uint8_t gun_index)
 {
 	uint8_t result = OFF;
 
-	if(ShmSysConfigAndInfo->SysConfig.OcppRunningVer == OCPP_RUNNING_VERSION_16)
+	if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
 	{
 		if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].IdTag, (char*)ShmOCPP16Data->ReserveNow[gun_index].IdTag) == 0)
 		{
@@ -793,7 +793,7 @@ uint8_t ocpp_compare_reserve_id_with_remote_user(uint8_t gun_index)
 			memcpy(ShmSysConfigAndInfo->SysConfig.UserId, ShmOCPP16Data->RemoteStartTransaction[gun_index].IdTag, ARRAY_SIZE(ShmOCPP16Data->RemoteStartTransaction[gun_index].IdTag));
 		}
 	}
-	else if(ShmSysConfigAndInfo->SysConfig.OcppRunningVer == OCPP_RUNNING_VERSION_20)
+	else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
 	{
 		if(strcmp((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].idToken.idToken, (char*)ShmOCPP20Data->ReserveNow[gun_index].idToken.idToken) == 0)
 		{
@@ -1027,6 +1027,7 @@ int CreatShareMemory()
    	}
    	memset(ShmCharger,0,sizeof(struct Charger));
 
+   	ShmSysConfigAndInfo->SysInfo.InternetConn = OFF;
     return result;
 }
 
@@ -1582,6 +1583,7 @@ void InitEthernet()
 	system(tmpbuf);
 	system("ifconfig lo up &");
 	system("/sbin/ifconfig eth0:1 192.168.201.201 netmask 255.255.255.248 up &");
+	system("/sbin/ethtool -s eth0 speed 10 duplex full autoneg off");
 
     //Run DHCP client if enabled
 	system("killall udhcpc");
@@ -2009,7 +2011,7 @@ void get_firmware_version(unsigned char gun_index)
 	strcpy((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev, ShmCharger->gun_info[gun_index].ver.Version_FW);
 
 	// Get CSU root file system version
-	sprintf((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev, "D0.44.00.0000.00");
+	sprintf((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev, "D0.45.00.0000.00");
 
 	// Get AC connector type from model name
 	for(uint8_t idx=0;idx<3;idx++)
@@ -2504,10 +2506,9 @@ int isReachableInternet()
 	char buf[512];
 	char tmp[512];
 	
-
+	// Get ip address & net mask
 	strcpy(cmd, "ifconfig eth0");
 	fp = popen(cmd, "r");
-
 	if (fp != NULL)
 	{
 		while(fgets(buf, sizeof(buf), fp) != NULL)
@@ -2516,17 +2517,45 @@ int isReachableInternet()
 			{
 				sscanf(buf, "%*s%s", tmp);
 				substr(tmp, tmp, strspn(tmp, "addr:"), strlen(buf)-strspn(tmp, "addr:"));
-
 				if (strcmp(tmp, (char *)ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthIpAddress) != 0)
 				{
 					strcpy((char *) ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthIpAddress, tmp);
 				}
+
+				sscanf(buf, "%*s%*s%*s%s", tmp);
+				substr(tmp, tmp, strspn(tmp, "Mask:"), strlen(buf)-strspn(tmp, "Mask:"));
+				if (strcmp(tmp, (char *)ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthSubmaskAddress) != 0)
+				{
+					strcpy((char *) ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthSubmaskAddress, tmp);
+				}
 			}
 		}
 	}
 	pclose(fp);
 	memset(buf, 0x00, sizeof(buf));
 
+	// Get gateway
+	fp = popen("ip route", "r");
+	if(fp == NULL)
+		result = FAIL;
+	else
+	{
+		while(fgets(buf, sizeof(buf), fp) != NULL)
+		{
+			if((strstr(buf, "default") != NULL) && (strstr(buf, "eth0") != NULL))
+				break;
+		}
+
+		if(strstr(buf, "default") != NULL)
+		{
+			sscanf(buf, "%*s%*s%s", tmp);
+			substr((char*)ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthGatewayAddress, tmp, 0, strlen(tmp));
+		}
+	}
+	pclose(fp);
+	memset(buf, 0x00, sizeof(buf));
+
+
 	for(int idx=0;idx<ARRAY_SIZE(valid_Internet);idx++)
 	{
 		sprintf(cmd, "ping -c 1 -w 3 -I eth0 %s", valid_Internet[idx]);
@@ -2588,7 +2617,7 @@ int isReservationExpired(unsigned char gun_index)
 	struct tm expiredDate;
 	struct timeb expiredTime;
 
-	if(ShmSysConfigAndInfo->SysConfig.OcppRunningVer == OCPP_RUNNING_VERSION_16)
+	if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
 	{
 		if(sscanf((char*)ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate, "%4d-%2d-%2dT%2d:%2d:%2d", &expiredDate.tm_year, &expiredDate.tm_mon, &expiredDate.tm_mday, &expiredDate.tm_hour, &expiredDate.tm_min, &expiredDate.tm_sec) == 6)
 		{
@@ -2608,7 +2637,7 @@ int isReservationExpired(unsigned char gun_index)
 			result = YES;
 		}
 	}
-	else if(ShmSysConfigAndInfo->SysConfig.OcppRunningVer == OCPP_RUNNING_VERSION_20)
+	else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
 	{
 		if(sscanf((char*)ShmOCPP20Data->ReserveNow[gun_index].expiryDateTime, "%4d-%2d-%2dT%2d:%2d:%2d", &expiredDate.tm_year, &expiredDate.tm_mon, &expiredDate.tm_mday, &expiredDate.tm_hour, &expiredDate.tm_min, &expiredDate.tm_sec) == 6)
 		{
@@ -2641,7 +2670,7 @@ int isProfileValid(uint8_t gun_index)
 	struct tm tmFrom, tmTo;
 	struct timeb tbFrom, tbTo;
 
-	if(ShmSysConfigAndInfo->SysConfig.OcppRunningVer == OCPP_RUNNING_VERSION_16)
+	if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
 	{
 		if((sscanf((char*)ShmOCPP16Data->SmartChargingProfile[gun_index].ValidFrom, "%4d-%2d-%2dT%2d:%2d:%2d", &tmFrom.tm_year, &tmFrom.tm_mon, &tmFrom.tm_mday, &tmFrom.tm_hour, &tmFrom.tm_min, &tmFrom.tm_sec) == 6) &&
 		   (sscanf((char*)ShmOCPP16Data->SmartChargingProfile[gun_index].ValidTo, "%4d-%2d-%2dT%2d:%2d:%2d", &tmTo.tm_year, &tmTo.tm_mon, &tmTo.tm_mday, &tmTo.tm_hour, &tmTo.tm_min, &tmTo.tm_sec) == 6))
@@ -2666,7 +2695,7 @@ int isProfileValid(uint8_t gun_index)
 			DEBUG_WARN("ValidFrom or ValidTo date parsing error.\n");
 		}
 	}
-	else if(ShmSysConfigAndInfo->SysConfig.OcppRunningVer == OCPP_RUNNING_VERSION_20)
+	else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
 	{
 		if((sscanf((char*)ShmOCPP20Data->SmartChargingProfile[gun_index].validFrom, "%4d-%2d-%2dT%2d:%2d:%2d", &tmFrom.tm_year, &tmFrom.tm_mon, &tmFrom.tm_mday, &tmFrom.tm_hour, &tmFrom.tm_min, &tmFrom.tm_sec) == 6) &&
 		   (sscanf((char*)ShmOCPP20Data->SmartChargingProfile[gun_index].validTo, "%4d-%2d-%2dT%2d:%2d:%2d", &tmTo.tm_year, &tmTo.tm_mon, &tmTo.tm_mday, &tmTo.tm_hour, &tmTo.tm_min, &tmTo.tm_sec) == 6))
@@ -2701,7 +2730,7 @@ int getScheduleStart(int gun_index)
 	struct tm tmScheduleStart;;
 	struct timeb tbScheduleStart;
 
-	if(ShmSysConfigAndInfo->SysConfig.OcppRunningVer == OCPP_RUNNING_VERSION_16)
+	if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
 	{
 		if((sscanf((char*)ShmOCPP16Data->SmartChargingProfile[gun_index].ChargingSchedule.StartSchedule, "%4d-%2d-%2dT%2d:%2d:%2d", &tmScheduleStart.tm_year, &tmScheduleStart.tm_mon, &tmScheduleStart.tm_mday, &tmScheduleStart.tm_hour, &tmScheduleStart.tm_min, &tmScheduleStart.tm_sec) == 6))
 		{
@@ -2718,7 +2747,7 @@ int getScheduleStart(int gun_index)
 			DEBUG_WARN("Schedule start date parsing error.\n");
 		}
 	}
-	else if(ShmSysConfigAndInfo->SysConfig.OcppRunningVer == OCPP_RUNNING_VERSION_20)
+	else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
 	{
 		if((sscanf((char*)ShmOCPP20Data->SmartChargingProfile[gun_index].chargingSchedule[0].startSchedule, "%4d-%2d-%2dT%2d:%2d:%2d", &tmScheduleStart.tm_year, &tmScheduleStart.tm_mon, &tmScheduleStart.tm_mday, &tmScheduleStart.tm_hour, &tmScheduleStart.tm_min, &tmScheduleStart.tm_sec) == 6))
 		{
@@ -2867,7 +2896,7 @@ void checkTask()
 
 	if(strcmp((char *)&ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0)
 	{
-		if(ShmSysConfigAndInfo->SysConfig.OcppRunningVer == OCPP_RUNNING_VERSION_16)
+		if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
 		{
 			if(system("pidof -s OcppBackend > /dev/null") != 0)
 			{
@@ -2875,7 +2904,7 @@ void checkTask()
 				ocpp_process_start();
 			}
 		}
-		else if(ShmSysConfigAndInfo->SysConfig.OcppRunningVer == OCPP_RUNNING_VERSION_20)
+		else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
 		{
 			if(system("pidof -s OcppBackend20 > /dev/null") != 0)
 			{
@@ -2942,7 +2971,7 @@ void checkConnectionTimeout()
 
 void checkReset()
 {
-	if(ShmSysConfigAndInfo->SysConfig.OcppRunningVer == OCPP_RUNNING_VERSION_16)
+	if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
 	{
 		if(ShmOCPP16Data->MsMsg.bits.ResetReq)
 		{
@@ -2970,7 +2999,7 @@ void checkReset()
 			}
 		}
 	}
-	else if(ShmSysConfigAndInfo->SysConfig.OcppRunningVer == OCPP_RUNNING_VERSION_20)
+	else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
 	{
 		if(ShmOCPP20Data->MsMsg.bits.ResetReq)
 		{
@@ -2981,7 +3010,7 @@ void checkReset()
 				sprintf((char*)ShmOCPP16Data->Reset.ResponseStatus, "Accepted");
 				ShmOCPP20Data->MsMsg.bits.ResetConf = ON;
 
-				if(strcmp((char*)ShmOCPP20Data->Reset.type, "Hard") == 0)
+				if(strcmp((char*)ShmOCPP20Data->Reset.type, "Immediate") == 0)
 				{
 					system("sync");
 					sleep(5);
@@ -3002,7 +3031,7 @@ void checkReset()
 
 void checkReservation(uint8_t gun_index)
 {
-	if(ShmSysConfigAndInfo->SysConfig.OcppRunningVer == OCPP_RUNNING_VERSION_16)
+	if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
 	{
 		if(ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowReq)
 		{
@@ -3016,7 +3045,7 @@ void checkReservation(uint8_t gun_index)
 			ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = ON;
 		}
 	}
-	else if(ShmSysConfigAndInfo->SysConfig.OcppRunningVer == OCPP_RUNNING_VERSION_20)
+	else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
 	{
 		if(ShmOCPP20Data->CsMsg.bits[gun_index].ReserveNowReq)
 		{
@@ -3034,7 +3063,7 @@ void checkReservation(uint8_t gun_index)
 
 void checkUnlocker(uint8_t gun_index)
 {
-	if(ShmSysConfigAndInfo->SysConfig.OcppRunningVer == OCPP_RUNNING_VERSION_16)
+	if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
 	{
 		if(ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorReq == ON)
 		{
@@ -3046,7 +3075,7 @@ void checkUnlocker(uint8_t gun_index)
 			ShmCharger->gun_info[ShmOCPP16Data->UnlockConnector[gun_index].ConnectorId-1].isUnlockerConnetor = ON;
 		}
 	}
-	else if(ShmSysConfigAndInfo->SysConfig.OcppRunningVer == OCPP_RUNNING_VERSION_20)
+	else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
 	{
 		if(ShmOCPP20Data->CsMsg.bits[gun_index].UnlockConnectorReq == ON)
 		{
@@ -3062,7 +3091,7 @@ void checkUnlocker(uint8_t gun_index)
 
 void checkAvailability(uint8_t gun_index)
 {
-	if(ShmSysConfigAndInfo->SysConfig.OcppRunningVer == OCPP_RUNNING_VERSION_16)
+	if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
 	{
 		if(ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityReq)
 		{
@@ -3080,7 +3109,7 @@ void checkAvailability(uint8_t gun_index)
 			ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityReq = OFF;
 		}
 	}
-	else if(ShmSysConfigAndInfo->SysConfig.OcppRunningVer == OCPP_RUNNING_VERSION_20)
+	else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
 	{
 		if(ShmOCPP20Data->CsMsg.bits[gun_index].ChangeAvailabilityReq)
 		{
@@ -3102,7 +3131,7 @@ void checkAvailability(uint8_t gun_index)
 
 void checkChargingProfileLimit(uint8_t gun_index)
 {
-	if(ShmSysConfigAndInfo->SysConfig.OcppRunningVer == OCPP_RUNNING_VERSION_16)
+	if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
 	{
 		if((ocpp_get_smartcharging_profileId(gun_index) > 0) &&
 		   (ocpp_get_profile_req(gun_index) != ON)	&&
@@ -3151,7 +3180,7 @@ void checkChargingProfileLimit(uint8_t gun_index)
 			ShmCharger->gun_info[gun_index].targetCurrent = ShmCharger->gun_info[gun_index].primaryMcuState.rating_current;
 		}
 	}
-	else if(ShmSysConfigAndInfo->SysConfig.OcppRunningVer == OCPP_RUNNING_VERSION_20)
+	else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
 	{
 		if((ocpp_get_smartcharging_profileId(gun_index) > 0) &&
 		   (ocpp_get_profile_req(gun_index) != ON)	&&
@@ -3204,7 +3233,7 @@ void checkChargingProfileLimit(uint8_t gun_index)
 
 void checkStopReason(uint8_t gun_index)
 {
-	if(ShmSysConfigAndInfo->SysConfig.OcppRunningVer == OCPP_RUNNING_VERSION_16)
+	if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
 	{
 		if(ShmOCPP16Data->MsMsg.bits.ResetReq)
 		{
@@ -3236,10 +3265,10 @@ void checkStopReason(uint8_t gun_index)
 		DEBUG_INFO("Gun-%d : StopReason [ %s ]...\n.",gun_index,ShmOCPP16Data->StopTransaction[gun_index].StopReason);
 
 		memcpy((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag, (char*)ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartUserId, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].IdTag));
-		ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PowerConsumption = (ShmCharger->gun_info[gun_index].powerConsumptionTotal.power_consumption/100);
+		ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PowerConsumption = (ShmCharger->gun_info[gun_index].powerConsumptionTotal.power_consumption/100.0);
 		ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = ON;
 	}
-	else if(ShmSysConfigAndInfo->SysConfig.OcppRunningVer == OCPP_RUNNING_VERSION_20)
+	else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
 	{
 		if(ShmOCPP20Data->MsMsg.bits.ResetReq)
 		{
@@ -3271,14 +3300,14 @@ void checkStopReason(uint8_t gun_index)
 		DEBUG_INFO("Gun-%d : StopReason [ %s ]...\n.", gun_index, ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.stoppedReason);
 
 		memcpy((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, (char*)ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartUserId, ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartUserId));
-		ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PowerConsumption = (ShmCharger->gun_info[gun_index].powerConsumptionTotal.power_consumption/100);
+		ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PowerConsumption = (ShmCharger->gun_info[gun_index].powerConsumptionTotal.power_consumption/100.0);
 		ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq = ON;
 	}
 }
 
 void checkRemoteUpgradeStatus()
 {
-	if(ShmSysConfigAndInfo->SysConfig.OcppRunningVer == OCPP_RUNNING_VERSION_16)
+	if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
 	{
 		if(strcmp((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "DownloadFailed")==0)
 		{
@@ -3315,7 +3344,7 @@ void checkRemoteUpgradeStatus()
 		else
 		{}
 	}
-	else if(ShmSysConfigAndInfo->SysConfig.OcppRunningVer == OCPP_RUNNING_VERSION_20)
+	else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
 	{
 		if(strcmp((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "DownloadFailed")==0)
 		{
@@ -4033,12 +4062,12 @@ int main(void)
 									ShmCharger->gun_info[gun_index].powerConsumption[1].power_consumption_at_start = ShmCharger->gun_info[gun_index].powerConsumption[1].power_consumption;
 									ShmCharger->gun_info[gun_index].powerConsumption[2].power_consumption_at_start = ShmCharger->gun_info[gun_index].powerConsumption[2].power_consumption;
 									if(ShmSysConfigAndInfo->SysConfig.AcPhaseCount==1)
-										ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PowerConsumption = (ShmCharger->gun_info[gun_index].powerConsumptionTotal.power_consumption/100);
+										ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PowerConsumption = (ShmCharger->gun_info[gun_index].powerConsumptionTotal.power_consumption/100.0);
 									else
 									{
-										//ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PowerConsumption[0] = (ShmCharger->gun_info[gun_index].powerConsumption[0].power_consumption/100);
-										//ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PowerConsumption[1] = (ShmCharger->gun_info[gun_index].powerConsumption[1].power_consumption/100);
-										//ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PowerConsumption[2] = (ShmCharger->gun_info[gun_index].powerConsumption[2].power_consumption/100);
+										//ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PowerConsumption[0] = (ShmCharger->gun_info[gun_index].powerConsumption[0].power_consumption/100.0);
+										//ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PowerConsumption[1] = (ShmCharger->gun_info[gun_index].powerConsumption[1].power_consumption/100.0);
+										//ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PowerConsumption[2] = (ShmCharger->gun_info[gun_index].powerConsumption[2].power_consumption/100.0);
 									}
 
 									memcpy((char*)ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartUserId, ShmSysConfigAndInfo->SysConfig.UserId, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.UserId));
@@ -4133,7 +4162,7 @@ int main(void)
 									ShmCharger->gun_info[gun_index].powerConsumption[1].power_consumption_at_start = ShmCharger->gun_info[gun_index].powerConsumption[1].power_consumption;
 									ShmCharger->gun_info[gun_index].powerConsumption[2].power_consumption_at_start = ShmCharger->gun_info[gun_index].powerConsumption[2].power_consumption;
 									if(ShmSysConfigAndInfo->SysConfig.AcPhaseCount==1)
-										ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PowerConsumption = (ShmCharger->gun_info[gun_index].powerConsumptionTotal.power_consumption/100);
+										ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PowerConsumption = (ShmCharger->gun_info[gun_index].powerConsumptionTotal.power_consumption/100.0);
 									else
 									{
 										//ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PowerConsumption[0] = (ShmCharger->gun_info[gun_index].powerConsumption[0].power_consumption/100);
@@ -4430,7 +4459,7 @@ int main(void)
 					{
 						setLedMotion(gun_index,LED_ACTION_CHARGING);
 						if(ShmSysConfigAndInfo->SysConfig.AcPhaseCount==1)
-							ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PowerConsumption = (ShmCharger->gun_info[gun_index].powerConsumptionTotal.power_consumption/100);
+							ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PowerConsumption = (ShmCharger->gun_info[gun_index].powerConsumptionTotal.power_consumption/100.0);
 						else
 						{
 							//ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PowerConsumption[0] = (ShmCharger->gun_info[gun_index].powerConsumption[0].power_consumption/100);
@@ -4441,12 +4470,12 @@ int main(void)
 						ftime(&endChargingTime[gun_index]);
 						ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargedDuration = DiffTimeb(startChargingTime[gun_index], endChargingTime[gun_index])/1000;
 						if(ShmSysConfigAndInfo->SysConfig.AcPhaseCount==1)
-							ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargedEnergy = ((float)(ShmCharger->gun_info[gun_index].powerConsumptionTotal.power_consumption - ShmCharger->gun_info[gun_index].powerConsumptionTotal.power_consumption_at_start))/100;
+							ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargedEnergy = ((float)(ShmCharger->gun_info[gun_index].powerConsumptionTotal.power_consumption - ShmCharger->gun_info[gun_index].powerConsumptionTotal.power_consumption_at_start))/100.0;
 						else
 						{
-							//ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargedEnergy[0] = ((float)(ShmCharger->gun_info[gun_index].powerConsumption[0].power_consumption - ShmCharger->gun_info[gun_index].powerConsumption[0].power_consumption_at_start))/100;
-							//ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargedEnergy[1] = ((float)(ShmCharger->gun_info[gun_index].powerConsumption[1].power_consumption - ShmCharger->gun_info[gun_index].powerConsumption[1].power_consumption_at_start))/100;
-							//ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargedEnergy[2] = ((float)(ShmCharger->gun_info[gun_index].powerConsumption[2].power_consumption - ShmCharger->gun_info[gun_index].powerConsumption[2].power_consumption_at_start))/100;
+							//ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargedEnergy[0] = ((float)(ShmCharger->gun_info[gun_index].powerConsumption[0].power_consumption - ShmCharger->gun_info[gun_index].powerConsumption[0].power_consumption_at_start))/100.0;
+							//ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargedEnergy[1] = ((float)(ShmCharger->gun_info[gun_index].powerConsumption[1].power_consumption - ShmCharger->gun_info[gun_index].powerConsumption[1].power_consumption_at_start))/100.0;
+							//ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargedEnergy[2] = ((float)(ShmCharger->gun_info[gun_index].powerConsumption[2].power_consumption - ShmCharger->gun_info[gun_index].powerConsumption[2].power_consumption_at_start))/100.0;
 						}
 
 						// Response StartTransactionConf
@@ -4850,7 +4879,7 @@ int main(void)
 							}
 						}
 
-						if((((ShmCharger->gun_info[gun_index].chargingMode != CHARGING_MODE_SOCKETE) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PilotState == CP_STATE_C)) || ((ShmCharger->gun_info[gun_index].chargingMode != CHARGING_MODE_SOCKETE) && ShmCharger->gun_info[gun_index].primaryMcuState.socket_e.isSocketEPinOn)) &&
+						if((((ShmCharger->gun_info[gun_index].chargingMode != CHARGING_MODE_SOCKETE) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PilotState == CP_STATE_C)) || ((ShmCharger->gun_info[gun_index].chargingMode == CHARGING_MODE_SOCKETE) && ShmCharger->gun_info[gun_index].primaryMcuState.socket_e.isSocketEPinOn)) &&
 						   (ShmCharger->gun_info[gun_index].rfidReq != ON) &&
 						   (ShmCharger->gun_info[gun_index].bleConfigData.isRequestStop != ON)  &&
 						   !ocpp_get_remotestop(gun_index) &&

+ 2 - 0
EVSE/Projects/AW-CCS/Apps/main.h

@@ -293,6 +293,7 @@ typedef struct GPIO_IN
 	unsigned char GFD[2];
 	unsigned char Button[2];
 	unsigned char Button_Emergency;
+	unsigned char Button_Mode_Switch;
 }Gpio_in;
 
 typedef struct GPIO_OUT
@@ -674,6 +675,7 @@ typedef struct GUN_INFO
 	Set_Breathe_Led_Timing							setBreatheLedTiming;
 	Set_Led_Brightness								setLedBrightness;
 	Set_Aux_Power_Switch							setAuxPowerSwitch;
+	Gpio_in											GPIO_Input;
 	Ac_Ccs_Info										acCcsInfo;
 	uint8_t											ccsHandshakeState;
 	uint8_t											PreviousEVChargeProgress;	

+ 31 - 1
EVSE/Projects/AW-Regular/Apps/main.c

@@ -948,6 +948,7 @@ void InitEthernet()
 	system(tmpbuf);
 	system("/sbin/ifconfig eth0:1 192.168.201.201 netmask 255.255.255.248 up &");
 	system("ifconfig lo up &");
+	system("/sbin/ethtool -s eth0 speed 10 duplex full autoneg off");
 
 	if(isInterfaceUp("eth1")==PASS)
 	{
@@ -1270,7 +1271,7 @@ void get_firmware_version(unsigned char gun_index)
 	strcpy((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev, ShmCharger->gun_info[gun_index].ver.Version_FW);
 
 	// Get CSU root file system version
-	sprintf((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev, "V0.63.00.0000.00");
+	sprintf((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev, "V0.65.00.0000.00");
 
 	// Get AC connector type from model name
 	for(uint8_t idx=0;idx<3;idx++)
@@ -1744,12 +1745,40 @@ int isReachableInternet()
 				{
 					strcpy((char *) ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthIpAddress, tmp);
 				}
+
+				sscanf(buf, "%*s%*s%*s%s", tmp);
+				substr(tmp, tmp, strspn(tmp, "Mask:"), strlen(buf)-strspn(tmp, "Mask:"));
+				if (strcmp(tmp, (char *)ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthSubmaskAddress) != 0)
+				{
+					strcpy((char *) ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthSubmaskAddress, tmp);
+				}
 			}
 		}
 	}
 	pclose(fp);
 	memset(buf, 0x00, sizeof(buf));
 
+	// Get gateway
+	fp = popen("ip route", "r");
+	if(fp == NULL)
+		result = FAIL;
+	else
+	{
+		while(fgets(buf, sizeof(buf), fp) != NULL)
+		{
+			if((strstr(buf, "default") != NULL) && (strstr(buf, "eth0") != NULL))
+				break;
+		}
+
+		if(strstr(buf, "default") != NULL)
+		{
+			sscanf(buf, "%*s%*s%s", tmp);
+			substr((char*)ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthGatewayAddress, tmp, 0, strlen(tmp));
+		}
+	}
+	pclose(fp);
+	memset(buf, 0x00, sizeof(buf));
+
 	for(int idx=0;idx<ARRAY_SIZE(valid_Internet);idx++)
 	{
 		sprintf(cmd, "ping -c 1 -w 3 -I eth0 %s", valid_Internet[idx]);
@@ -2401,6 +2430,7 @@ int main(void)
 						{
 							DEBUG_INFO("URL is empty kill Module_OcppBackend...\n");
 							system ("pkill OcppBackend");
+							LoadSysConfigAndInfo(&ShmSysConfigAndInfo->SysConfig);
 						}
 
 						// If rotate switch equal zero, the system needs to change Debug mode

二进制
EVSE/Projects/AW-Regular/Images/ramdisk.gz


+ 59 - 13
EVSE/Projects/CCS/Apps/FWUpdate.c

@@ -388,14 +388,22 @@ unsigned char Update_uboot()
 
         // Write image to flash
         SAVE_SYS_LOG_MSG_FWUPDATE("[uboot]Writing image to mtdblock1...");
-        fread(ptr, sizeof(unsigned char), file_length, file);
-        wrd = write(fd, ptr, file_length);
+     //   fread(ptr, sizeof(unsigned char), file_length, file);
+      
+        //wrd = write(fd, ptr, file_length);
 
         close(fd);
         fclose(file);
+                
+        system("/bin/flash_erase /dev/mtd1 0 2");
+	system("/usr/sbin/nandwrite -p /dev/mtd1 /root/u-boot.img");
+	system("/bin/flash_erase /dev/mtd3 0 2");
+	system("/usr/sbin/nandwrite -p /dev/mtd3 /root/u-boot.img");
+
+        
         sprintf(buf_log_fwupdate, "[uboot]mtdblock1 - written length: %d bytes\n", wrd);
         SAVE_SYS_LOG_MSG_FWUPDATE(buf_log_fwupdate);
-
+#if 0
         if(wrd != file_length)
         {
             free(ptr);
@@ -434,6 +442,7 @@ unsigned char Update_uboot()
                 }
             }
         }
+#endif    
     }
     return result;
 }
@@ -489,14 +498,22 @@ unsigned char Update_DTB()
 
         // Write image to flash
         SAVE_SYS_LOG_MSG_FWUPDATE("[DTB]Writing image to mtdblock4...");
-        fread(ptr, sizeof(unsigned char), file_length, file);
-        wrd = write(fd, ptr, file_length);
+      //  fread(ptr, sizeof(unsigned char), file_length, file);
+      //  wrd = write(fd, ptr, file_length);
 
         close(fd);
         fclose(file);
+        
+        system("/bin/flash_erase /dev/mtd4 0 1");
+	system("/usr/sbin/nandwrite -p /dev/mtd4 /root/am335x-evm.dtb");
+
+	system("/bin/flash_erase /dev/mtd5 0 1");
+	system("/usr/sbin/nandwrite -p /dev/mtd5 /root/am335x-evm.dtb");
+        
+        
         sprintf(buf_log_fwupdate, "[DTB]mtdblock4 - written length: %d bytes\n", wrd);
         SAVE_SYS_LOG_MSG_FWUPDATE(buf_log_fwupdate);
-
+#if 0
         if(wrd != file_length)
         {
             free(ptr);
@@ -527,6 +544,7 @@ unsigned char Update_DTB()
                 }
             }
         }
+#endif        
     }
     return result;
 }
@@ -582,14 +600,22 @@ unsigned char Update_zImage()
 
         // Write image to flash
         SAVE_SYS_LOG_MSG_FWUPDATE("[zImage]Writing image to mtdblock6...");
-        fread(ptr, sizeof(unsigned char), file_length, file);
-        wrd = write(fd, ptr, file_length);
+      //  fread(ptr, sizeof(unsigned char), file_length, file);
+       // wrd = write(fd, ptr, file_length);
 
         close(fd);
         fclose(file);
+        
+	
+	system("/bin/flash_erase /dev/mtd6 0 20");
+	system("/usr/sbin/nandwrite -p /dev/mtd6 /root/zImage");
+
+	system("/bin/flash_erase /dev/mtd7 0 20");
+	system("/usr/sbin/nandwrite -p /dev/mtd7 /root/zImage");
+        
         sprintf(buf_log_fwupdate, "[zImage]mtdblock6 - written length: %d bytes\n", wrd);
         SAVE_SYS_LOG_MSG_FWUPDATE(buf_log_fwupdate);
-
+#if 0
         if(wrd != file_length)
         {
             free(ptr);
@@ -620,6 +646,7 @@ unsigned char Update_zImage()
                 }
             }
         }
+#endif        
     }
     return result;
 }
@@ -672,12 +699,22 @@ unsigned char Update_ramdisk()
         system("killall SeccComm");
 
         SAVE_SYS_LOG_MSG_FWUPDATE("[ramdisk]Writing image to mtdblock8...");
-        fread(ptr, sizeof(unsigned char), file_length, file);
-        wrd = write(fd, ptr, file_length);
+        //fread(ptr, sizeof(unsigned char), file_length, file);
+        //wrd = write(fd, ptr, file_length);
         close(fd);
         fclose(file);
+        
+
+       system("/bin/flash_erase /dev/mtd8 0 96");
+       system("/usr/sbin/nandwrite -p /dev/mtd8 /root/ramdisk.gz");
+
+       system("/bin/flash_erase /dev/mtd9 0 96");
+       system("/usr/sbin/nandwrite -p /dev/mtd9 /root/ramdisk.gz");
+                                	
+                                	
         sprintf(buf_log_fwupdate, "[ramdisk]mtdblock8 - written length: %d bytes\n", wrd);
         SAVE_SYS_LOG_MSG_FWUPDATE(buf_log_fwupdate);
+#if 0      
         if(wrd != file_length)
         {
             free(ptr);
@@ -719,6 +756,7 @@ unsigned char Update_ramdisk()
                 #endif
             }
         }
+#endif        
     }
     return result;
 }
@@ -776,14 +814,21 @@ unsigned char Update_user_config()
 
         // Write image to flash
         SAVE_SYS_LOG_MSG_FWUPDATE("[user_config]Writing image to mtdblock10...");
-        fread(ptr, sizeof(unsigned char), file_length, file);
-        wrd = write(fd, ptr, file_length);
+      //  fread(ptr, sizeof(unsigned char), file_length, file);
+        //wrd = write(fd, ptr, file_length);
         close(fd);
         fclose(file);
+        system("/bin/flash_erase /dev/mtd10 0 12");
+	system("/usr/sbin/nandwrite -p /dev/mtd10 /root/FactoryConfig.bin");
+
+	system("/bin/flash_erase /dev/mtd11 0 12");
+	system("/usr/sbin/nandwrite -p /dev/mtd11 /root/FactoryConfig.bin");
+									
         sprintf(buf_log_fwupdate,
                 "[user_config]mtdblock10 - written length: %d bytes\n",
                 wrd);
         SAVE_SYS_LOG_MSG_FWUPDATE(buf_log_fwupdate);
+#if 0      
         if(wrd != file_length)
         {
             free(ptr);
@@ -816,6 +861,7 @@ unsigned char Update_user_config()
                 }
             }
         }
+#endif        
     }
     return result;
 }

二进制
EVSE/Projects/CCS/Apps/SeccComm


+ 2 - 1
EVSE/Projects/CCS/Apps/SeccComm.c

@@ -1908,6 +1908,7 @@ void Error_Monitor()
             EVCOMM_SYS_INFO.EvBatteryMaxVoltage != 0)
         {
             //Part A: OVP Protection
+            #if 0
             if (EVCOMM_SYS_INFO.PresentChargingVoltage >= (EVCOMM_SYS_INFO.EvBatteryMaxVoltage * 1.02)) // 2%
             {
                 sprintf(buf_log_evcomm_fork2,
@@ -1929,7 +1930,7 @@ void Error_Monitor()
                 Proc_EVStopRes(ShmInternalComm->FD_CAN_Socket);
                 End_Process();
             }
-
+	    #endif
             //Part B: Over Voltage Request Protection
             if (EVCOMM_SYS_INFO.EvBatterytargetVoltage >= (EVCOMM_SYS_INFO.EvBatteryMaxVoltage * 1.02))
             {

+ 33 - 1
EVSE/Projects/CCS/Apps/main.c

@@ -51,6 +51,34 @@ int LoadSysConfigAndInfo(struct SysConfigData *ptr);
 int SpawnTask();
 int StoreUsrConfigData(struct SysConfigData *UsrData);
 
+
+unsigned int isKernelSupportNAT()
+{
+	unsigned int result = 0;
+	unsigned int version = 0;
+	FILE *fp;
+	char cmd[256];
+	char buf[512];
+
+	// Get IP address & net mask
+	strcpy(cmd, "uname -v");
+	fp = popen(cmd, "r");
+	if(fp != NULL)
+	{
+		if(fgets(buf, sizeof(buf), fp) != NULL)
+		{
+			sscanf(buf, "#%d", &version);
+		//	DEBUG_INFO("Kernel version: %d\n", version);
+
+			if(version >= 30)
+				result = 1;
+		}
+	}
+	pclose(fp);
+
+	return result;
+}
+
 /*===========================================================================
 FUNCTION: main
 DESCRIPTION:
@@ -195,7 +223,11 @@ void System_Init()
     Eth0_PortSetting_Base(ETH0_PORT_BASE); //192.168.0.20
 
     // ---------- Hardware Init ---------
-    system("/sbin/insmod /lib/qcaspi.ko");
+    if(isKernelSupportNAT() == 1)
+		system("/sbin/insmod /lib/qcaspi_nat.ko");
+	else
+		system("/sbin/insmod /lib/qcaspi.ko");
+   // system("/sbin/insmod /lib/qcaspi.ko");
     sleep(2);
     system("/sbin/ifconfig eth1 192.168.0.11 netmask 255.255.255.0 up");
     sleep(1);

+ 1 - 1
EVSE/Projects/CCS/Apps/version.h

@@ -5,7 +5,7 @@
                      initiated by Joseph D. Anderson
                            (since 2019/12/03)
 =============================================================================*/
-#define FIRMWARE_VERSION            "D0.16.S0"   //8-Byte(ASCII Code), “tx.yz.ab.cd”
+#define FIRMWARE_VERSION            "D0.18.S0"   //8-Byte(ASCII Code), “tx.yz.ab.cd”
 #define HARDWARE_VERSION            "CCS_8.0x"      //8-Byte(ASCII Code): CSU-03-RW, CCS_Board, REV:5.0
 #define LINUX_IMAGE_VERSION         "dd2da761d59f2cdd4064c9d95f8c302a442d33f3 (2019-01-04)"
 #define RTC_DEFAULT_TIME            1595486300      //Epoch time (decimal)

二进制
EVSE/Projects/CCS/Images/ramdisk.gz


+ 1 - 0
EVSE/Projects/DD360Audi/Apps/main.c

@@ -3092,6 +3092,7 @@ bool CheckConnectorTypeStatus()
             bd0_1_status, bd0_2_status, bd1_1_status, bd1_2_status);
     */
     if (strlen((char *) ShmSysConfigAndInfo->SysConfig.ModelName) >= 9) {
+        printf("1 CheckConnectorTypeStatus\r\n");
         byte slots = 1;
         for (byte typeIndex = 7; typeIndex <= 9; typeIndex++) {
             if (!AddGunInfoByConnector(ShmSysConfigAndInfo->SysConfig.ModelName[typeIndex], slots)) {

二进制
EVSE/Projects/DD360Audi/Images/ramdisk.gz


二进制
EVSE/Projects/DD360Audi/output/DoComm


二进制
EVSE/Projects/DD360Audi/output/FactoryConfig


二进制
EVSE/Projects/DD360Audi/output/Module_EvComm


二进制
EVSE/Projects/DD360Audi/output/Module_EventLogging


二进制
EVSE/Projects/DD360Audi/output/Module_InternalComm


二进制
EVSE/Projects/DD360Audi/output/Module_LcmControl


二进制
EVSE/Projects/DD360Audi/output/Module_PrimaryComm


二进制
EVSE/Projects/DD360Audi/output/ReadCmdline


二进制
EVSE/Projects/DD360Audi/output/main


+ 1 - 1
EVSE/Projects/DO360/Apps/FactoryConfig.c

@@ -129,7 +129,7 @@ int main(int argc,char *argv[])
 	SysConfig.isRFID = 1;
 	//********** Charging **********//
 	SysConfig.MaxChargingEnergy = 0;
-	SysConfig.MaxChargingCurrent = 200;		// 最大可輸出電流 (整樁)
+	SysConfig.MaxChargingCurrent = 0;		// 最大可輸出電流 (整樁)
 	SysConfig.MaxChargingDuration = 0;
 	SysConfig.AcMaxChargingCurrent = 0;
 	SysConfig.PhaseLossPolicy = 0;

+ 194 - 27
EVSE/Projects/DO360/Apps/Module_EvComm.c

@@ -879,7 +879,7 @@ BOOL IsAvalibleGunType(char name, unsigned char *type)
 	return false;
 }
 
-unsigned char ConnectorQuantityTypeParsing(unsigned char *modelName, unsigned char *type)
+unsigned char ConnectorQuantityTypeParsing(unsigned char *modelName, unsigned char *type, unsigned char *physical)
 {
 	unsigned char quantity = 0;
 
@@ -887,6 +887,7 @@ unsigned char ConnectorQuantityTypeParsing(unsigned char *modelName, unsigned ch
 	{
 		if(IsAvalibleGunType(modelName[7 + i], &type[quantity]))
 		{
+		    physical[quantity] = modelName[7 + i];
 			if(quantity < 2)
 			{
 				quantity++;
@@ -978,6 +979,33 @@ void DispenserStatusResponse(int socket, struct PACKET_STRUCTURE *packet, unsign
 
 struct ChargingCapabilityResponse ConnectorCapability[GENERAL_GUN_QUANTITY];
 
+void GetPhysicalLimitVoltageAndCurrent(byte index, unsigned short *voltage, unsigned short *currrent)
+{
+    if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].RemoteMaxPhysicalVoltage != 0 &&
+        ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].RemoteMaxPhysicalVoltage <= *voltage)
+    {
+        *voltage = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].RemoteMaxPhysicalVoltage;
+    }
+
+    if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].RemoteMaxPhysicalCurrent != 0 &&
+        ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].RemoteMaxPhysicalCurrent <= *currrent)
+    {
+        *currrent = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].RemoteMaxPhysicalCurrent;
+    }
+}
+
+void GetConfigLimitVoltageAndCurrent(byte index, unsigned short *voltage, unsigned short *currrent)
+{
+    unsigned short limitCurrent = ShmSysConfigAndInfo->SysInfo.MainChargingMode == _MAIN_CHARGING_MODE_MAX ?
+            (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].MaxTotalChargingCurrent) :
+            (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].MaxTotalChargingCurrent / 2);
+
+    if(limitCurrent != 0 && limitCurrent <= *currrent)
+    {
+        *currrent = limitCurrent;
+    }
+}
+
 void ChargingCapabilityResponse(int socket, struct PACKET_STRUCTURE *packet)
 {
 	struct PACKET_STRUCTURE sendBuffer;
@@ -990,6 +1018,9 @@ void ChargingCapabilityResponse(int socket, struct PACKET_STRUCTURE *packet)
 	current = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].GeneralChargingData.AvailableChargingCurrent;
 	power = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].GeneralChargingData.AvailableChargingPower;
 
+	GetPhysicalLimitVoltageAndCurrent(packet->Header.id - 1, &voltage, &current);
+	GetConfigLimitVoltageAndCurrent(packet->Header.id - 1, &voltage, &current);
+
 	currency = ShmSysConfigAndInfo->SysInfo.DispenserInfo.Currency;
 	price = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].UserPrice;
 	cost = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].TotalCost;
@@ -1062,7 +1093,7 @@ void ChargingTargetResponse(int socket, struct PACKET_STRUCTURE *packet, unsigne
 	send(socket, &sendBuffer, sendBuffer.Header.len + 4, 0);
 }
 
-void FirmwareUpgradeResponse(int socket, struct PACKET_STRUCTURE *packet, unsigned char result)
+void FirmwareUpgradeResponse(int socket, struct PACKET_STRUCTURE *packet, unsigned char dispenserIndex, unsigned char result)
 {
     struct PACKET_STRUCTURE sendBuffer;
 
@@ -1070,11 +1101,18 @@ void FirmwareUpgradeResponse(int socket, struct PACKET_STRUCTURE *packet, unsign
     sendBuffer.Header.se = packet->Header.se;
     sendBuffer.Header.id = packet->Header.id;
     sendBuffer.Header.op = _Header_Response;
-    sendBuffer.Header.len = 2;
+    sendBuffer.Header.len = 3;
     sendBuffer.Payload.reg = _Reg_Software_Update;
     sendBuffer.Payload.data[0] = _R_OK;
     sendBuffer.Payload.data[1] = result;
 
+    if(result == _R_NeedUpgrade)
+    {
+        int length = strlen(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].FwFileName);
+        memcpy(&sendBuffer.Payload.data[2], ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].FwFileName, length);
+        sendBuffer.Header.len += length;
+    }
+
     send(socket, &sendBuffer, sendBuffer.Header.len + 4, 0);
 }
 
@@ -1369,7 +1407,43 @@ BOOL FindConnectorID(unsigned char dispenserIndex, unsigned char id)
 	return find;
 }
 
-void ConnectorTypeBindingHandler(unsigned char dispenserIndex, unsigned char *type)
+void ConnectorPhysicalLimitBindingHandler(unsigned char connectorIndex, unsigned char physical)
+{
+    //char modelList[6] = {'J', 'U', 'E', 'G', 'V', 'F'};
+    //unsigned char typeList[6] = {0, 1, 1, 2, 1, 1};     // 0 : Chademo, 1: CCS, 2: GB
+
+    switch(physical)
+    {
+        case 'J':
+            ShmSysConfigAndInfo->SysInfo.ConnectorInfo[connectorIndex].RemoteMaxPhysicalVoltage = CHA_MAX_PHYSICAL_VOLTAGE;
+            ShmSysConfigAndInfo->SysInfo.ConnectorInfo[connectorIndex].RemoteMaxPhysicalCurrent = CHA_NATURAL_MAX_CURRENT;
+            break;
+
+        case 'U':
+        case 'E':
+            ShmSysConfigAndInfo->SysInfo.ConnectorInfo[connectorIndex].RemoteMaxPhysicalVoltage = CCS_MAX_PHYSICAL_VOLTAGE;
+            ShmSysConfigAndInfo->SysInfo.ConnectorInfo[connectorIndex].RemoteMaxPhysicalCurrent = CCS_NATURAL_MAX_CURRENT;
+            break;
+
+        case 'G':
+            ShmSysConfigAndInfo->SysInfo.ConnectorInfo[connectorIndex].RemoteMaxPhysicalVoltage = GBT_MAX_PHYSICAL_VOLTAGE;
+            ShmSysConfigAndInfo->SysInfo.ConnectorInfo[connectorIndex].RemoteMaxPhysicalCurrent = GBT_NATURAL_MAX_CURRENT;
+            break;
+
+        case 'V':
+        case 'F':
+            ShmSysConfigAndInfo->SysInfo.ConnectorInfo[connectorIndex].RemoteMaxPhysicalVoltage = CCS_MAX_PHYSICAL_VOLTAGE;
+            ShmSysConfigAndInfo->SysInfo.ConnectorInfo[connectorIndex].RemoteMaxPhysicalCurrent = CCS_LIQUID_MAX_CURRENT;
+            break;
+
+        default:
+            ShmSysConfigAndInfo->SysInfo.ConnectorInfo[connectorIndex].RemoteMaxPhysicalVoltage = 0;
+            ShmSysConfigAndInfo->SysInfo.ConnectorInfo[connectorIndex].RemoteMaxPhysicalCurrent = 0;
+            break;
+    }
+}
+
+void ConnectorTypeBindingHandler(unsigned char dispenserIndex, unsigned char *type, unsigned char *physicalType)
 {
     char *str_gun_type[] = {STR_GUN_TYPE_CHADEMO, STR_GUN_TYPE_CCS, STR_GUN_TYPE_GBT};
 
@@ -1379,8 +1453,12 @@ void ConnectorTypeBindingHandler(unsigned char dispenserIndex, unsigned char *ty
 		ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gunIndex].ParentDispensetIndex = dispenserIndex;
 		ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gunIndex].GeneralChargingData.Index = gunIndex;
 		ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gunIndex].GeneralChargingData.Type = type[i];
+        ConnectorPhysicalLimitBindingHandler(gunIndex, physicalType[i]);
 
-		PRINTF_FUNC("Dispenser id %d Connector %d type %s", dispenserIndex + 1, gunIndex + 1, str_gun_type[type[i]]);
+		PRINTF_FUNC("Dispenser %d Connector %d type %s, MaxVol: %4d, MaxCur: %4d",
+            dispenserIndex + 1, gunIndex + 1, str_gun_type[type[i]],
+            ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gunIndex].RemoteMaxPhysicalVoltage,
+            ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gunIndex].RemoteMaxPhysicalCurrent);
 	}
 }
 
@@ -1468,8 +1546,9 @@ BOOL DispenserIdentificationHandler(struct PACKET_STRUCTURE *packet, unsigned ch
 	unsigned char quantity = 0;
 
 	unsigned char connectorType[2] = {0, 0};
+	unsigned char physicalType[2] = {0, 0};
 
-	quantity = ConnectorQuantityTypeParsing(modelName, connectorType);
+	quantity = ConnectorQuantityTypeParsing(modelName, connectorType, physicalType);
 
 	if(quantity > 0)
 	{
@@ -1488,7 +1567,7 @@ BOOL DispenserIdentificationHandler(struct PACKET_STRUCTURE *packet, unsigned ch
 			SetConnectorID(dispenserIndex, quantity);
 			memcpy(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].ModelName, packet->Payload.data, (packet->Header.len - 2));
 
-			ConnectorTypeBindingHandler(dispenserIndex, connectorType);
+			ConnectorTypeBindingHandler(dispenserIndex, connectorType, physicalType);
 
 			PRINTF_FUNC("Dispenser id %d identified, Connector quantity: %d\n", dispenserIndex + 1, quantity);
 
@@ -1588,23 +1667,60 @@ BOOL ConnectorChargingTargetHandler(struct PACKET_STRUCTURE *packet, unsigned ch
 {
 	BOOL find = FindConnectorID(dispenserIndex, packet->Header.id);
 	BOOL done = false;
-	float voltage = 0, current = 0;
+	unsigned short voltage = 0, current = 0;
 
 	if(find)
 	{
-		voltage = (float)((packet->Payload.data[0] << 8) + packet->Payload.data[1]) / 10;
-		current = (float)((packet->Payload.data[2] << 8) + packet->Payload.data[3]) / 10;
+		voltage = ((packet->Payload.data[0] << 8) + packet->Payload.data[1]);
+		current = ((packet->Payload.data[2] << 8) + packet->Payload.data[3]);
+
+		if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].RemoteTargetVoltage != voltage ||
+            ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].RemoteTargetCurrent != current)
+		{
+		    ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].RemoteTargetVoltage = voltage;
+		    ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].RemoteTargetCurrent = current;
+		    if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].Parameter.bits.OutputLimitEnable)
+		    {
+		        PRINTF_FUNC("Connector %d Remote Voltage: %d, Remote Current: %d", packet->Header.id, voltage, current);
+		    }
+		}
+
+		GetPhysicalLimitVoltageAndCurrent(packet->Header.id - 1, &voltage, &current);
+		GetConfigLimitVoltageAndCurrent(packet->Header.id - 1, &voltage, &current);
+
+		if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].RemoteTargetVoltage != voltage ||
+            ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].RemoteTargetCurrent != current)
+		{
+		    if(!ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].Parameter.bits.OutputLimitEnable)
+		    {
+		        ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].Parameter.bits.OutputLimitEnable = true;
+		        PRINTF_FUNC("Connector %d Remote Voltage: %d, Remote Current: %d", packet->Header.id,
+                    ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].RemoteTargetVoltage,
+                    ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].RemoteTargetCurrent);
+		        PRINTF_FUNC("Connector %d Limit Voltage: %d, Limit Current: %d", packet->Header.id, voltage, current);
+		    }
+		}
+		else
+		{
+		    ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].Parameter.bits.OutputLimitEnable = false;
+		}
+		ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].RemoteLimitVoltage = voltage;
+		ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].RemoteLimitCurrent = current;
 
 		if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].GeneralChargingData.SystemStatus == S_CHARGING)
 		{
-			if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].GeneralChargingData.EvBatterytargetVoltage != voltage ||
-				ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].GeneralChargingData.EvBatterytargetCurrent != current)
+		    float targetVol = (float)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].RemoteLimitVoltage / 10);
+		    float targetCur = (float)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].RemoteLimitCurrent / 10);
+
+			if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].GeneralChargingData.EvBatterytargetVoltage != targetVol ||
+				ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].GeneralChargingData.EvBatterytargetCurrent != targetCur)
 			{
-				PRINTF_FUNC("Connector %d Target Voltage: %d, Current: %d", packet->Header.id, (int)(voltage * 10), (int)(current * 10));
+				PRINTF_FUNC("Connector %d Target Voltage: %d, Current: %d",
+                    packet->Header.id, (int)(targetVol * 10), (int)(targetCur * 10));
 			}
 
-			ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].GeneralChargingData.EvBatterytargetVoltage = (float)voltage;
-			ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].GeneralChargingData.EvBatterytargetCurrent = (float)current;
+			ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].GeneralChargingData.EvBatterytargetVoltage = targetVol;
+			ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].GeneralChargingData.EvBatterytargetCurrent = targetCur;
 
 			done = true;
 		}
@@ -1629,7 +1745,43 @@ BOOL ConnectorChargingTargetHandler(struct PACKET_STRUCTURE *packet, unsigned ch
 
 unsigned char FirmwareUpgradeHandler(struct PACKET_STRUCTURE *packet, unsigned char dispenserIndex)
 {
-    return _R_NoUpgrade;
+    unsigned char UpgradeResponse = _R_NoUpgrade;
+
+    if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].ConnectorID[0] == packet->Header.id)
+    {
+        if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].Setting.bits.FirmwareUpdateRequest)
+        {
+            if(packet->Payload.data[0] == 0)
+            {
+                UpgradeResponse = _R_NeedUpgrade;
+            }
+            else
+            {
+                if(!ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].Setting.bits.FirmwareUpdateConfirm)
+                {
+                    ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].Setting.bits.FirmwareUpdateConfirm = true;
+                    ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].Setting.bits.FirmwareUpdateRequest = false;
+                    PRINTF_FUNC("Dispenser %d Updating...", dispenserIndex + 1);
+                }
+            }
+        }
+        else
+        {
+            if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].Setting.bits.FirmwareUpdateConfirm)
+            {
+                if(packet->Payload.data[0] == 0)
+                {
+                    if(!ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].Setting.bits.FirmwareUpdateCompleted)
+                    {
+                        ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].Setting.bits.FirmwareUpdateCompleted = true;
+                        PRINTF_FUNC("Dispenser %d Upgrade Completed", dispenserIndex + 1);
+                    }
+                }
+            }
+        }
+    }
+
+    return UpgradeResponse;
 }
 
 BOOL ConnectorPlugInHandler(struct PACKET_STRUCTURE *packet, unsigned char dispenserIndex)
@@ -1741,9 +1893,11 @@ unsigned char ChargingPermissionHandler(struct PACKET_STRUCTURE *packet, unsigne
                 else
                 {
                     permission = _DAS_NotAllowed;
-                    PRINTF_FUNC("Cabinet status idle, not allow dispenser id %d connector id %d charging",
-                                        dispenserIndex + 1, packet->Header.id);
-                    PRINTF_FUNC("RemoteStop or UnlockStop, not allow dispenser index %d connector id %d preparing to charge", dispenserIndex, packet->Header.id);
+                    if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].Parameter.bits.ChargingPermission != permission)
+                    {
+                        PRINTF_FUNC("Cabinet status idle, not allow dispenser %d connector %d charging",
+                            dispenserIndex + 1, packet->Header.id);
+                    }
                 }
                 break;
 
@@ -1752,7 +1906,10 @@ unsigned char ChargingPermissionHandler(struct PACKET_STRUCTURE *packet, unsigne
                     ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].Parameter.bits.UnlockStopRequest)
                 {
                     permission = _DAS_NotAllowed;
-                    PRINTF_FUNC("RemoteStop or UnlockStop, not allow dispenser index %d connector id %d preparing to charge", dispenserIndex, packet->Header.id);
+                    if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].Parameter.bits.ChargingPermission != permission)
+                    {
+                        PRINTF_FUNC("RemoteStop or UnlockStop, not allow dispenser index %d connector id %d preparing to charge", dispenserIndex, packet->Header.id);
+                    }
                 }
                 else if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].RemoteStatus >= _CRS_Preparing &&
                     ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].RemoteStatus <= _CRS_Charging)
@@ -1780,7 +1937,10 @@ unsigned char ChargingPermissionHandler(struct PACKET_STRUCTURE *packet, unsigne
                     ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].Parameter.bits.UnlockStopRequest)
                 {
                     permission = _DAS_NotAllowed;
-                    PRINTF_FUNC("RemoteStop or UnlockStop, not allow dispenser index %d connector id %d charging", dispenserIndex, packet->Header.id);
+                    if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].Parameter.bits.ChargingPermission != permission)
+                    {
+                        PRINTF_FUNC("RemoteStop or UnlockStop, not allow dispenser index %d connector id %d charging", dispenserIndex, packet->Header.id);
+                    }
                 }
                 else if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].RemoteStatus == _CRS_Preparing ||
                     ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].RemoteStatus == _CRS_Charging)
@@ -1790,7 +1950,10 @@ unsigned char ChargingPermissionHandler(struct PACKET_STRUCTURE *packet, unsigne
                 else
                 {
                     permission = _DAS_NotAllowed;
-                    PRINTF_FUNC("Dispenser index %d connector id %d remote status not in charging mode", dispenserIndex, packet->Header.id);
+                    if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].Parameter.bits.ChargingPermission != permission)
+                    {
+                        PRINTF_FUNC("Dispenser index %d connector id %d remote status not in charging mode", dispenserIndex, packet->Header.id);
+                    }
                 }
                 break;
 
@@ -1800,9 +1963,12 @@ unsigned char ChargingPermissionHandler(struct PACKET_STRUCTURE *packet, unsigne
             case S_RESERVATION:
             case S_MAINTAIN:
                 permission = _DAS_NotAllowed;
-                PRINTF_FUNC("Cabinet status(%d) not match, not allow dispenser index %d connector id %d charging",
-                    ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].GeneralChargingData.SystemStatus,
-                    dispenserIndex, packet->Header.id);
+                if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].Parameter.bits.ChargingPermission != permission)
+                {
+                    PRINTF_FUNC("Cabinet status(%d) not match, not allow dispenser index %d connector id %d charging",
+                        ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].GeneralChargingData.SystemStatus,
+                        dispenserIndex, packet->Header.id);
+                }
                 break;
 
             default:
@@ -1815,6 +1981,8 @@ unsigned char ChargingPermissionHandler(struct PACKET_STRUCTURE *packet, unsigne
 	    permission = _DAS_NotAllowed;
 	}
 
+	ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].Parameter.bits.ChargingPermission = permission;
+
 //	PRINTF_FUNC("Dispenser %d Permission %s, Gun Status: %d, Connector Status: %d, Wait Plug: %d, PlugIn: %d, Available: %d, Order: %d", dispenserIndex, permission == true ? "OK" : "NG",
 //		ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].GeneralChargingData.SystemStatus,
 //		ShmSysConfigAndInfo->SysInfo.ConnectorInfo[packet->Header.id - 1].RemoteStatus,
@@ -2161,8 +2329,7 @@ void DispenserSocketProcess(int socketFd, struct sockaddr_in clientInfo, unsigne
 					if(receiveBuffer.Header.op == _Header_Read && receiveBuffer.Payload.reg == _Reg_Software_Update)
 					{
 					    unsigned char NeedUpgrade = FirmwareUpgradeHandler(&receiveBuffer, dispenserIndex);
-
-                        FirmwareUpgradeResponse(socketFd, &receiveBuffer, NeedUpgrade);
+                        FirmwareUpgradeResponse(socketFd, &receiveBuffer, dispenserIndex, NeedUpgrade);
 					}
 
 					// Reg: 0x08, Plug-in status

+ 10 - 0
EVSE/Projects/DO360/Apps/Module_EvComm.h

@@ -26,6 +26,16 @@
 #define	CONNECTION_LIMIT				5
 #define MAXIMUM_CONNECT_QUANTITY		2
 
+#define CCS_MAX_PHYSICAL_VOLTAGE        9500
+#define CCS_NATURAL_MAX_CURRENT         2000
+#define CCS_LIQUID_MAX_CURRENT          5000
+
+#define CHA_MAX_PHYSICAL_VOLTAGE        5000
+#define CHA_NATURAL_MAX_CURRENT         2000
+
+#define GBT_MAX_PHYSICAL_VOLTAGE        7500
+#define GBT_NATURAL_MAX_CURRENT         2500
+
 struct Message
 {
 	int				size;

+ 218 - 360
EVSE/Projects/DO360/Apps/Module_InternalComm.c

@@ -2423,387 +2423,245 @@ int main(void)
 	//bool printRelayStatus = true;
 	for(;;)
 	{
-		bool isCharging = false;
-		// 程序開始之前~ 必須先確定 FW 版本與硬體版本,確認後!!~ 該模組才算是真正的 Initial Comp.
-		if (ShmRelayModuleData[0]->SelfTest_Comp == NO)
-		{
-		    // clena fw version
-		    memset(ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev, 0x00, 32);
-
-			GetFwAndHwVersion_Relay();
-			SetRtcData_Relay(0);
-			sleep(1);
-
-            if(strlen((char *)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev))
+	    if(!ShmSysConfigAndInfo->SysInfo.FirmwareUpdate)
+	    {
+            bool isCharging = false;
+            // 程序開始之前~ 必須先確定 FW 版本與硬體版本,確認後!!~ 該模組才算是真正的 Initial Comp.
+            if (ShmRelayModuleData[0]->SelfTest_Comp == NO)
             {
-                ShmRelayModuleData[0]->SelfTest_Comp = YES;
-            }
-		}
-
-		// DO360 RC2
-		if (ShmRelayModuleData[1]->SelfTest_Comp == NO)
-		{
-		    // clena fw version
-		    memset(ShmSysConfigAndInfo->SysInfo.Relay2ModuleFwRev, 0x00, 32);
+                // clena fw version
+                memset(ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev, 0x00, 32);
 
-			GetFwAndHwVersion_Relay2();
-			SetRtcData_Relay(1);
-			sleep(1);
+                GetFwAndHwVersion_Relay();
+                SetRtcData_Relay(0);
+                sleep(1);
 
-            if (strlen((char *)ShmSysConfigAndInfo->SysInfo.Relay2ModuleFwRev) != 0)
-            {
-                ShmRelayModuleData[1]->SelfTest_Comp = YES;
+                if(strlen((char *)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev))
+                {
+                    ShmRelayModuleData[0]->SelfTest_Comp = YES;
+                }
             }
-		}
 
-		if (ShmFanModuleData->SelfTest_Comp == NO)
-		{
-		    // clena fw version
-		    memset(ShmSysConfigAndInfo->SysInfo.FanModuleFwRev, 0x00, 32);
-
-			GetFwAndHwVersion_Fan();
-			SetModelName_Fan();
-			SetRtcData_Fan();
-			sleep(1);
-			gettimeofday(&_priority_time, NULL);
-
-            if(strlen((char *)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev) != 0)
+            // DO360 RC2
+            if (ShmRelayModuleData[1]->SelfTest_Comp == NO)
             {
-                ShmFanModuleData->SelfTest_Comp = YES;
-            }
-		}
-
-		// 自檢階段處理,自檢階段如果讀不到版號則代表該系統沒有掛燈板
-//		if (ShmLedModuleData->SelfTest_Comp == NO)
-//		{
-			// 自檢階段
-//			if (ShmSysConfigAndInfo->SysInfo.SelfTestSeq <= _STEST_PSU_CAP)
-//			{
-//				GetFwAndHwVersion_Led();
-//				sleep(1);
-//				gettimeofday(&_led_priority_time, NULL);
-//			}
-//			else
-//			{
-				// 自檢階段沒有問到版號
-//				if (ShmStatusCodeData->AlarmCode.AlarmEvents.bits.LedboardStestFail == NO)
-//					ShmStatusCodeData->AlarmCode.AlarmEvents.bits.LedboardStestFail = YES;
-//			}
-//		}
-
-		//AcChargeTypeProcess();
-
-		if (ShmRelayModuleData[0]->SelfTest_Comp == YES && ShmRelayModuleData[1]->SelfTest_Comp == YES)
-		{
-			// ==============優先權最高 10 ms ==============
-			// 輸出電壓
-			GetPersentOutputVol();
-
-			// 三相輸入電壓
-			GetPresentInputVol();
-
-			// 讀取當前 AC relay 狀態
-			regRelay[0].relay_event.bits.AC_Contactor = ShmSysConfigAndInfo->SysInfo.AcContactorStatus;
-			regRelay[1].relay_event.bits.AC_Contactor = ShmSysConfigAndInfo->SysInfo.AcContactorStatus;
-			//GetRelayOutputStatus();
-
-			for (int i = 0; i < gunCount; i++)
-			{
-				// Cable check (Set)
-				//CableCheckDetected(i);
-
-				// check k1 k2 relay 狀態
-				CheckK1K2RelayOutput(i);
-
-				// 依據當前各槍的狀態選擇 搭上/放開 Relay
-				SetK1K2RelayStatus(i);
+                // clena fw version
+                memset(ShmSysConfigAndInfo->SysInfo.Relay2ModuleFwRev, 0x00, 32);
 
-				if (ShmSysConfigAndInfo->SysConfig.PhaseLossPolicy == YES)
-					CheckPhaseLossStatus(i);
+                GetFwAndHwVersion_Relay2();
+                SetRtcData_Relay(1);
+                sleep(1);
 
-				CheckAcInputOvpStatus(i);
-
-				if (_chargingData[i]->SystemStatus == S_IDLE)
-				{
-					_chargingData[i]->RelayWeldingCheck = NO;
-					_isRelayWelding[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) ||
-					ShmSysConfigAndInfo->SysInfo.WaitForPlugit == YES ||
-					(ShmSysConfigAndInfo->SysInfo.PageIndex >= _LCM_AUTHORIZING && ShmSysConfigAndInfo->SysInfo.PageIndex <= _LCM_WAIT_FOR_PLUG))
-				{
-					_chargingData[i]->IsReadyToCharging = YES;
-					isCharging = true;
-
-					// 限定只有在槍類別為 GBT 的時候才做 relay welding 的判斷
-					if (_chargingData[i]->Type == _Type_GB)
-					{
-						if (_chargingData[i]->SystemStatus >= S_PREPARING_FOR_EVSE &&
-							_chargingData[i]->RelayWeldingCheck == NO)
-							CheckRelayWeldingStatus(i);
-					}
-					else
-						_chargingData[i]->RelayWeldingCheck = YES;
-
-					if (_chargingData[i]->SystemStatus == S_CHARGING)
-					{
-					    // DO360 do not check under voltage output & any voltage difference
-						//CheckOutputPowerOverCarReq(i);
-						//CheckOutputVolNoneMatchFire(i);
-					}
-					else
-						_isOutputNoneMatch[i] = NO;
-				}
-				else
-					_chargingData[i]->IsReadyToCharging = NO;
-			}
-
-			// Cable check (Get)
-			//GetGfdAdc();
-
-			// 橋接 relay
-			SetParalleRelayStatus();
+                if (strlen((char *)ShmSysConfigAndInfo->SysInfo.Relay2ModuleFwRev) != 0)
+                {
+                    ShmRelayModuleData[1]->SelfTest_Comp = YES;
+                }
+            }
 
-			// 搭上 AC Contactor
-//			if (isCharging)
-//				outputRelay.relay_event.bits.AC_Contactor = YES;
-//			else
-//				outputRelay.relay_event.bits.AC_Contactor = NO;
+            if (ShmFanModuleData->SelfTest_Comp == NO)
+            {
+                // clena fw version
+                memset(ShmSysConfigAndInfo->SysInfo.FanModuleFwRev, 0x00, 32);
 
-			if (isCharging ||
-				(ShmPsuData->Work_Step >= _TEST_MODE && ShmPsuData->Work_Step <= _TEST_MODE))
-			{
-				isStopChargingCount = false;
-				outputRelay[0].relay_event.bits.AC_Contactor = YES;
-				outputRelay[1].relay_event.bits.AC_Contactor = YES;
-			}
-			else
-			{
-				if (!isStopChargingCount)
-				{
-					gettimeofday(&_close_ac_contactor, NULL);
-					isStopChargingCount = true;
-				}
-				else
-				{
-					if (((outputRelay[0].relay_event.bits.AC_Contactor == YES || outputRelay[1].relay_event.bits.AC_Contactor == YES)&&
-							GetTimeoutValue(_close_ac_contactor) / 1000 >= (TEN_MINUTES * 1000)))
-					{
-						outputRelay[0].relay_event.bits.AC_Contactor = NO;
-						outputRelay[1].relay_event.bits.AC_Contactor = NO;
-					}
-				}
-			}
+                GetFwAndHwVersion_Fan();
+                SetModelName_Fan();
+                SetRtcData_Fan();
+                sleep(1);
+                gettimeofday(&_priority_time, NULL);
 
-			if (ShmPsuData->Work_Step >= _TEST_MODE && ShmPsuData->Work_Step <= _TEST_MODE)
-			{
-				outputRelay[0].relay_event.bits.Gun1_N = outputRelay[0].relay_event.bits.Gun1_P = YES;
-			}
+                if(strlen((char *)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev) != 0)
+                {
+                    ShmFanModuleData->SelfTest_Comp = YES;
+                }
+            }
 
-			// 搭上/鬆開 Relay
-			if(IsNoneMatchRelayStatus(0))
-			{
-				if (Config_Relay_Output(Uart5Fd, Addr.DO360_RC1, &outputRelay[0]))
-				{
-					//regRelay.relay_event.bits.AC_Contactor = ShmSysConfigAndInfo->SysInfo.AcContactorStatus;
-					regRelay[0].relay_event.bits.CCS_Precharge = outputRelay[0].relay_event.bits.CCS_Precharge;
-					regRelay[0].relay_event.bits.Gun1_P = outputRelay[0].relay_event.bits.Gun1_P;
-					regRelay[0].relay_event.bits.Gun1_N = outputRelay[0].relay_event.bits.Gun1_N;
-					regRelay[0].relay_event.bits.Gun2_P = outputRelay[0].relay_event.bits.Gun2_P;
-					regRelay[0].relay_event.bits.Gun2_N = outputRelay[0].relay_event.bits.Gun2_N;
-					regRelay[0].relay_event.bits.Gun1_Parallel_P = outputRelay[0].relay_event.bits.Gun1_Parallel_P;
-					regRelay[0].relay_event.bits.Gun1_Parallel_N = outputRelay[0].relay_event.bits.Gun1_Parallel_N;
-					regRelay[0].relay_event.bits.Gun2_Parallel_P = outputRelay[0].relay_event.bits.Gun2_Parallel_P;
-					regRelay[0].relay_event.bits.Gun2_Parallel_N = outputRelay[0].relay_event.bits.Gun2_Parallel_N;
-
-					PRINTF_FUNC("Match Relay, AC = %x, g1_p = %x, g1_n = %x, g2_p = %x, g2_n = %x, pre = %x, bri_p = %x, bri_n = %x, bri2_p = %x, bri2_n = %x \n",
-							regRelay[0].relay_event.bits.AC_Contactor,
-							regRelay[0].relay_event.bits.Gun1_P,
-							regRelay[0].relay_event.bits.Gun1_N,
-							regRelay[0].relay_event.bits.Gun2_P,
-							regRelay[0].relay_event.bits.Gun2_N,
-							regRelay[0].relay_event.bits.CCS_Precharge,
-							regRelay[0].relay_event.bits.Gun1_Parallel_P,
-							regRelay[0].relay_event.bits.Gun1_Parallel_N,
-							regRelay[0].relay_event.bits.Gun2_Parallel_P,
-							regRelay[0].relay_event.bits.Gun2_Parallel_N);
-				}
-			}
+            if (ShmRelayModuleData[0]->SelfTest_Comp == YES && ShmRelayModuleData[1]->SelfTest_Comp == YES)
+            {
+                // ==============優先權最高 10 ms ==============
+                // 輸出電壓
+                GetPersentOutputVol();
 
-			// 搭上/鬆開 Relay
-			if(IsNoneMatchRelayStatus(1))
-			{
-				if (Config_Relay_Output(Uart5Fd, Addr.DO360_RC2, &outputRelay[1]))
-				{
-					//regRelay.relay_event.bits.AC_Contactor = ShmSysConfigAndInfo->SysInfo.AcContactorStatus;
-					regRelay[1].relay_event.bits.CCS_Precharge = outputRelay[1].relay_event.bits.CCS_Precharge;
-					regRelay[1].relay_event.bits.Gun1_P = outputRelay[1].relay_event.bits.Gun1_P;
-					regRelay[1].relay_event.bits.Gun1_N = outputRelay[1].relay_event.bits.Gun1_N;
-					regRelay[1].relay_event.bits.Gun2_P = outputRelay[1].relay_event.bits.Gun2_P;
-					regRelay[1].relay_event.bits.Gun2_N = outputRelay[1].relay_event.bits.Gun2_N;
-					regRelay[1].relay_event.bits.Gun1_Parallel_P = outputRelay[1].relay_event.bits.Gun1_Parallel_P;
-					regRelay[1].relay_event.bits.Gun1_Parallel_N = outputRelay[1].relay_event.bits.Gun1_Parallel_N;
-					regRelay[1].relay_event.bits.Gun2_Parallel_P = outputRelay[1].relay_event.bits.Gun2_Parallel_P;
-					regRelay[1].relay_event.bits.Gun2_Parallel_N = outputRelay[1].relay_event.bits.Gun2_Parallel_N;
-
-					PRINTF_FUNC("Match Relay2, AC = %x, g1_p = %x, g1_n = %x, g2_p = %x, g2_n = %x, pre = %x, bri_p = %x, bri_n = %x, bri2_p = %x, bri2_n = %x \n",
-							regRelay[1].relay_event.bits.AC_Contactor,
-							regRelay[1].relay_event.bits.Gun1_P,
-							regRelay[1].relay_event.bits.Gun1_N,
-							regRelay[1].relay_event.bits.Gun2_P,
-							regRelay[1].relay_event.bits.Gun2_N,
-							regRelay[1].relay_event.bits.CCS_Precharge,
-							regRelay[1].relay_event.bits.Gun1_Parallel_P,
-							regRelay[1].relay_event.bits.Gun1_Parallel_N,
-							regRelay[1].relay_event.bits.Gun2_Parallel_P,
-							regRelay[1].relay_event.bits.Gun2_Parallel_N);
-				}
-			}
+                // 三相輸入電壓
+                GetPresentInputVol();
 
+                // 讀取當前 AC relay 狀態
+                regRelay[0].relay_event.bits.AC_Contactor = ShmSysConfigAndInfo->SysInfo.AcContactorStatus;
+                regRelay[1].relay_event.bits.AC_Contactor = ShmSysConfigAndInfo->SysInfo.AcContactorStatus;
+                //GetRelayOutputStatus();
 
-//			if(IsNoneMatchRelayStatus())
-//			{
-//				if (printRelayStatus)
-//				{
-////					PRINTF_FUNC("Match Relay Target, AC = %x, g1_p = %x, g1_n = %x, g2_p = %x, g2_n = %x, pre = %x, bri_p = %x, bri_n = %x \n",
-////							outputRelay.relay_event.bits.AC_Contactor,
-////							outputRelay.relay_event.bits.Gun1_P,
-////							outputRelay.relay_event.bits.Gun1_N,
-////							outputRelay.relay_event.bits.Gun2_P,
-////							outputRelay.relay_event.bits.Gun2_N,
-////							outputRelay.relay_event.bits.CCS_Precharge,
-////							outputRelay.relay_event.bits.Gun1_Parallel_P,
-////							outputRelay.relay_event.bits.Gun1_Parallel_N);
-//				}
-//				printRelayStatus = false;
-//				if (Config_Relay_Output(Uart5Fd, Addr.Relay, &outputRelay))
-//				{
-//					PRINTF_FUNC("Match Relay Target, AC = %x, g1_p = %x, g1_n = %x, g2_p = %x, g2_n = %x, pre = %x, bri_p = %x, bri_n = %x \n",
-//							outputRelay.relay_event.bits.AC_Contactor,
-//							outputRelay.relay_event.bits.Gun1_P,
-//							outputRelay.relay_event.bits.Gun1_N,
-//							outputRelay.relay_event.bits.Gun2_P,
-//							outputRelay.relay_event.bits.Gun2_N,
-//							outputRelay.relay_event.bits.CCS_Precharge,
-//							outputRelay.relay_event.bits.Gun1_Parallel_P,
-//							outputRelay.relay_event.bits.Gun1_Parallel_N);
-//				}
-//			}
-//			else
-//			{
-//				if (!printRelayStatus)
-//				{
-//					PRINTF_FUNC("Match Relay, AC = %x, g1_p = %x, g1_n = %x, g2_p = %x, g2_n = %x, pre = %x, bri_p = %x, bri_n = %x \n",
-//							regRelay.relay_event.bits.AC_Contactor,
-//							regRelay.relay_event.bits.Gun1_P,
-//							regRelay.relay_event.bits.Gun1_N,
-//							regRelay.relay_event.bits.Gun2_P,
-//							regRelay.relay_event.bits.Gun2_N,
-//							regRelay.relay_event.bits.CCS_Precharge,
-//							regRelay.relay_event.bits.Gun1_Parallel_P,
-//							regRelay.relay_event.bits.Gun1_Parallel_N);
-//				}
-//				printRelayStatus = true;
-//			}
-		}
-
-		if (ShmFanModuleData->SelfTest_Comp == YES ||
-				strlen((char *)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev) != 0 ||
-				ShmSysConfigAndInfo->SysInfo.FanModuleFwRev[0] != '\0')
-		{
-			if (GetTimeoutValue(_priority_time) / 1000 >= 1000)
-			{
-				//GetPsuTempForFanSpeed();
-				GetFanSpeedByFunction();
-				GetFanSpeed();
-				ShmSysConfigAndInfo->SysInfo.SystemFanRotaSpeed = _setFanSpeed;
-				gettimeofday(&_priority_time, NULL);
+                for (int i = 0; i < gunCount; i++)
+                {
+                    // check k1 k2 relay 狀態
+                    CheckK1K2RelayOutput(i);
+
+                    // 依據當前各槍的狀態選擇 搭上/放開 Relay
+                    SetK1K2RelayStatus(i);
+
+                    if (ShmSysConfigAndInfo->SysConfig.PhaseLossPolicy == YES)
+                        CheckPhaseLossStatus(i);
+
+                    CheckAcInputOvpStatus(i);
+
+                    if (_chargingData[i]->SystemStatus == S_IDLE)
+                    {
+                        _chargingData[i]->RelayWeldingCheck = NO;
+                        _isRelayWelding[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) ||
+                        ShmSysConfigAndInfo->SysInfo.WaitForPlugit == YES ||
+                        (ShmSysConfigAndInfo->SysInfo.PageIndex >= _LCM_AUTHORIZING && ShmSysConfigAndInfo->SysInfo.PageIndex <= _LCM_WAIT_FOR_PLUG))
+                    {
+                        _chargingData[i]->IsReadyToCharging = YES;
+                        isCharging = true;
+
+                        // 限定只有在槍類別為 GBT 的時候才做 relay welding 的判斷
+                        if (_chargingData[i]->Type == _Type_GB)
+                        {
+                            if (_chargingData[i]->SystemStatus >= S_PREPARING_FOR_EVSE &&
+                                _chargingData[i]->RelayWeldingCheck == NO)
+                                CheckRelayWeldingStatus(i);
+                        }
+                        else
+                            _chargingData[i]->RelayWeldingCheck = YES;
+
+                        if (_chargingData[i]->SystemStatus == S_CHARGING)
+                        {
+                            // DO360 do not check under voltage output & any voltage difference
+                            //CheckOutputPowerOverCarReq(i);
+                            //CheckOutputVolNoneMatchFire(i);
+                        }
+                        else
+                            _isOutputNoneMatch[i] = NO;
+                    }
+                    else
+                        _chargingData[i]->IsReadyToCharging = NO;
+                }
 
-				unsigned short TargetSpeed = ShmFanModuleData->TestFanSpeed;
+                // 橋接 relay
+                SetParalleRelayStatus();
 
-				if(TargetSpeed != 0 && TargetSpeed < MIN_FAN_SPEED)
-				{
-				    TargetSpeed = MIN_FAN_SPEED;
-				}
-				ShmFanModuleData->SetFan1Speed = TargetSpeed;
-				ShmFanModuleData->SetFan2Speed = TargetSpeed;
-				ShmFanModuleData->SetFan3Speed = TargetSpeed;
-				ShmFanModuleData->SetFan4Speed = TargetSpeed;
+                if (isCharging ||
+                    (ShmPsuData->Work_Step >= _TEST_MODE && ShmPsuData->Work_Step <= _TEST_MODE))
+                {
+                    isStopChargingCount = false;
+                    outputRelay[0].relay_event.bits.AC_Contactor = YES;
+                    outputRelay[1].relay_event.bits.AC_Contactor = YES;
+                }
+                else
+                {
+                    if (!isStopChargingCount)
+                    {
+                        gettimeofday(&_close_ac_contactor, NULL);
+                        isStopChargingCount = true;
+                    }
+                    else
+                    {
+                        if (((outputRelay[0].relay_event.bits.AC_Contactor == YES || outputRelay[1].relay_event.bits.AC_Contactor == YES)&&
+                                GetTimeoutValue(_close_ac_contactor) / 1000 >= (TEN_MINUTES * 1000)))
+                        {
+                            outputRelay[0].relay_event.bits.AC_Contactor = NO;
+                            outputRelay[1].relay_event.bits.AC_Contactor = NO;
+                        }
+                    }
+                }
 
-//				if (isCharging)
-//				{
-////					if (ShmFanModuleData->PresentFan1Speed < MAX_FAN_SPEED ||
-////						ShmFanModuleData->PresentFan2Speed < MAX_FAN_SPEED ||
-////						ShmFanModuleData->PresentFan3Speed < MAX_FAN_SPEED ||
-////						ShmFanModuleData->PresentFan4Speed < MAX_FAN_SPEED)
-////					{
-////						ShmFanModuleData->SetFan1Speed = MAX_FAN_SPEED;
-////						ShmFanModuleData->SetFan2Speed = MAX_FAN_SPEED;
-////						ShmFanModuleData->SetFan3Speed = MAX_FAN_SPEED;
-////						ShmFanModuleData->SetFan4Speed = MAX_FAN_SPEED;
-////					}
-//
-//					// 在還沒問到 PSU 溫度~ 還是要有個最小轉速
-//					ShmFanModuleData->SetFan1Speed = MIN_FAN_SPEED;
-//					ShmFanModuleData->SetFan2Speed = MIN_FAN_SPEED;
-//					ShmFanModuleData->SetFan3Speed = MIN_FAN_SPEED;
-//					ShmFanModuleData->SetFan4Speed = MIN_FAN_SPEED;
-//
-//					if (ShmFanModuleData->TestFanSpeed > 0)
-//					{
-//						ShmFanModuleData->SetFan1Speed = ShmFanModuleData->TestFanSpeed;
-//						ShmFanModuleData->SetFan2Speed = ShmFanModuleData->TestFanSpeed;
-//						ShmFanModuleData->SetFan3Speed = ShmFanModuleData->TestFanSpeed;
-//						ShmFanModuleData->SetFan4Speed = ShmFanModuleData->TestFanSpeed;
-//					}
-//				}
-//				else
-//				{
-////					if (ShmFanModuleData->PresentFan1Speed > MIN_FAN_SPEED ||
-////						ShmFanModuleData->PresentFan2Speed > MIN_FAN_SPEED ||
-////						ShmFanModuleData->PresentFan3Speed > MIN_FAN_SPEED ||
-////						ShmFanModuleData->PresentFan4Speed > MIN_FAN_SPEED)
-////					{
-//						ShmFanModuleData->SetFan1Speed = MIN_FAN_SPEED;
-//						ShmFanModuleData->SetFan2Speed = MIN_FAN_SPEED;
-//						ShmFanModuleData->SetFan3Speed = MIN_FAN_SPEED;
-//						ShmFanModuleData->SetFan4Speed = MIN_FAN_SPEED;
-////					}
-//
-//					// 停止時,如溫度還是很高,則需要維持該轉速直到溫度降低
-//					if (ShmFanModuleData->TestFanSpeed >= MAX_FAN_SPEED)
-//					{
-//						ShmFanModuleData->SetFan1Speed = ShmFanModuleData->TestFanSpeed;
-//						ShmFanModuleData->SetFan2Speed = ShmFanModuleData->TestFanSpeed;
-//						ShmFanModuleData->SetFan3Speed = ShmFanModuleData->TestFanSpeed;
-//						ShmFanModuleData->SetFan4Speed = ShmFanModuleData->TestFanSpeed;
-//					}
-//				}
+                if (ShmPsuData->Work_Step >= _TEST_MODE && ShmPsuData->Work_Step <= _TEST_MODE)
+                {
+                    outputRelay[0].relay_event.bits.Gun1_N = outputRelay[0].relay_event.bits.Gun1_P = YES;
+                }
 
-				//PRINTF_FUNC("set fan = %d \n", ShmFanModuleData->SetFan1Speed);
-				SetFanModuleSpeed();
-			}
-		}
+                // 搭上/鬆開 Relay
+                if(IsNoneMatchRelayStatus(0))
+                {
+                    if (Config_Relay_Output(Uart5Fd, Addr.DO360_RC1, &outputRelay[0]))
+                    {
+                        //regRelay.relay_event.bits.AC_Contactor = ShmSysConfigAndInfo->SysInfo.AcContactorStatus;
+                        regRelay[0].relay_event.bits.CCS_Precharge = outputRelay[0].relay_event.bits.CCS_Precharge;
+                        regRelay[0].relay_event.bits.Gun1_P = outputRelay[0].relay_event.bits.Gun1_P;
+                        regRelay[0].relay_event.bits.Gun1_N = outputRelay[0].relay_event.bits.Gun1_N;
+                        regRelay[0].relay_event.bits.Gun2_P = outputRelay[0].relay_event.bits.Gun2_P;
+                        regRelay[0].relay_event.bits.Gun2_N = outputRelay[0].relay_event.bits.Gun2_N;
+                        regRelay[0].relay_event.bits.Gun1_Parallel_P = outputRelay[0].relay_event.bits.Gun1_Parallel_P;
+                        regRelay[0].relay_event.bits.Gun1_Parallel_N = outputRelay[0].relay_event.bits.Gun1_Parallel_N;
+                        regRelay[0].relay_event.bits.Gun2_Parallel_P = outputRelay[0].relay_event.bits.Gun2_Parallel_P;
+                        regRelay[0].relay_event.bits.Gun2_Parallel_N = outputRelay[0].relay_event.bits.Gun2_Parallel_N;
+
+                        PRINTF_FUNC("Match Relay, AC = %x, g1_p = %x, g1_n = %x, g2_p = %x, g2_n = %x, pre = %x, bri_p = %x, bri_n = %x, bri2_p = %x, bri2_n = %x \n",
+                                regRelay[0].relay_event.bits.AC_Contactor,
+                                regRelay[0].relay_event.bits.Gun1_P,
+                                regRelay[0].relay_event.bits.Gun1_N,
+                                regRelay[0].relay_event.bits.Gun2_P,
+                                regRelay[0].relay_event.bits.Gun2_N,
+                                regRelay[0].relay_event.bits.CCS_Precharge,
+                                regRelay[0].relay_event.bits.Gun1_Parallel_P,
+                                regRelay[0].relay_event.bits.Gun1_Parallel_N,
+                                regRelay[0].relay_event.bits.Gun2_Parallel_P,
+                                regRelay[0].relay_event.bits.Gun2_Parallel_N);
+                    }
+                }
 
-//		if (ShmLedModuleData->SelfTest_Comp == YES)
-//		{
-//			if (GetTimeoutValue(_led_priority_time) / 1000 >= 1000)
-//			{
-//				if(gunCount == 1)
-//				{
-//					SetLedColor(_chargingData[0], _chargingData[0]);
-//				}
-//				else if (gunCount == 2)
-//				{
-//					SetLedColor(_chargingData[0], _chargingData[1]);
-//				}
+                // 搭上/鬆開 Relay
+                if(IsNoneMatchRelayStatus(1))
+                {
+                    if (Config_Relay_Output(Uart5Fd, Addr.DO360_RC2, &outputRelay[1]))
+                    {
+                        //regRelay.relay_event.bits.AC_Contactor = ShmSysConfigAndInfo->SysInfo.AcContactorStatus;
+                        regRelay[1].relay_event.bits.CCS_Precharge = outputRelay[1].relay_event.bits.CCS_Precharge;
+                        regRelay[1].relay_event.bits.Gun1_P = outputRelay[1].relay_event.bits.Gun1_P;
+                        regRelay[1].relay_event.bits.Gun1_N = outputRelay[1].relay_event.bits.Gun1_N;
+                        regRelay[1].relay_event.bits.Gun2_P = outputRelay[1].relay_event.bits.Gun2_P;
+                        regRelay[1].relay_event.bits.Gun2_N = outputRelay[1].relay_event.bits.Gun2_N;
+                        regRelay[1].relay_event.bits.Gun1_Parallel_P = outputRelay[1].relay_event.bits.Gun1_Parallel_P;
+                        regRelay[1].relay_event.bits.Gun1_Parallel_N = outputRelay[1].relay_event.bits.Gun1_Parallel_N;
+                        regRelay[1].relay_event.bits.Gun2_Parallel_P = outputRelay[1].relay_event.bits.Gun2_Parallel_P;
+                        regRelay[1].relay_event.bits.Gun2_Parallel_N = outputRelay[1].relay_event.bits.Gun2_Parallel_N;
+
+                        PRINTF_FUNC("Match Relay2, AC = %x, g1_p = %x, g1_n = %x, g2_p = %x, g2_n = %x, pre = %x, bri_p = %x, bri_n = %x, bri2_p = %x, bri2_n = %x \n",
+                                regRelay[1].relay_event.bits.AC_Contactor,
+                                regRelay[1].relay_event.bits.Gun1_P,
+                                regRelay[1].relay_event.bits.Gun1_N,
+                                regRelay[1].relay_event.bits.Gun2_P,
+                                regRelay[1].relay_event.bits.Gun2_N,
+                                regRelay[1].relay_event.bits.CCS_Precharge,
+                                regRelay[1].relay_event.bits.Gun1_Parallel_P,
+                                regRelay[1].relay_event.bits.Gun1_Parallel_N,
+                                regRelay[1].relay_event.bits.Gun2_Parallel_P,
+                                regRelay[1].relay_event.bits.Gun2_Parallel_N);
+                    }
+                }
+            }
 
-//				gettimeofday(&_led_priority_time, NULL);
-//			}
-//		}
+            if (ShmFanModuleData->SelfTest_Comp == YES ||
+                    strlen((char *)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev) != 0 ||
+                    ShmSysConfigAndInfo->SysInfo.FanModuleFwRev[0] != '\0')
+            {
+                if (GetTimeoutValue(_priority_time) / 1000 >= 1000)
+                {
+                    //GetPsuTempForFanSpeed();
+                    GetFanSpeedByFunction();
+                    GetFanSpeed();
+                    ShmSysConfigAndInfo->SysInfo.SystemFanRotaSpeed = _setFanSpeed;
+                    gettimeofday(&_priority_time, NULL);
+
+                    unsigned short TargetSpeed = ShmFanModuleData->TestFanSpeed;
+
+                    if(TargetSpeed != 0 && TargetSpeed < MIN_FAN_SPEED)
+                    {
+                        TargetSpeed = MIN_FAN_SPEED;
+                    }
+                    ShmFanModuleData->SetFan1Speed = TargetSpeed;
+                    ShmFanModuleData->SetFan2Speed = TargetSpeed;
+                    ShmFanModuleData->SetFan3Speed = TargetSpeed;
+                    ShmFanModuleData->SetFan4Speed = TargetSpeed;
+
+                    //PRINTF_FUNC("set fan = %d \n", ShmFanModuleData->SetFan1Speed);
+                    SetFanModuleSpeed();
+                }
+            }
+	    }
 
 		usleep(10000);
 	}

+ 20 - 42
EVSE/Projects/DO360/Apps/Module_PrimaryComm.c

@@ -462,52 +462,30 @@ int main(void)
 
 	for(;;)
 	{
-//		if (strcmp((char *)ShmSysConfigAndInfo->SysInfo.LcmHwRev, " ") == 0x00)
-//		{
-//			if ((GetTimeoutValue(_flash_time) / 1000) > 1000)
-//			{
-//				if (flash == NO)
-//					flash = YES;
-//				else
-//					flash = NO;
-//				SetOutputGpio(flash);
-//				gettimeofday(&_flash_time, NULL);
-//			}
-//		}
-//		else
-//		{
-//			if ((GetTimeoutValue(_flash_time) / 1000) > 5000)
-//			{
-//				if (flash == NO)
-//					flash = YES;
-
-//				SetOutputGpio(flash);
-//				gettimeofday(&_flash_time, NULL);
-//			}
-//		}
-
-		// 程序開始之前~ 必須先確定 FW 版本與硬體版本,確認後!!~ 該模組才算是真正的 Initial Comp.
-		// 模組更新 FW 後,需重新做
-		if(ShmPrimaryMcuData->SelfTest_Comp != PASS)
-		{
-		    memset(ShmPrimaryMcuData->version, 0x00, 16);
+	    if(!ShmSysConfigAndInfo->SysInfo.FirmwareUpdate)
+	    {
+            // 程序開始之前~ 必須先確定 FW 版本與硬體版本,確認後!!~ 該模組才算是真正的 Initial Comp.
+            // 模組更新 FW 後,需重新做
+            if(ShmPrimaryMcuData->SelfTest_Comp != PASS)
+            {
+                memset(ShmPrimaryMcuData->version, 0x00, 16);
 
-			GetFwAndHwVersion();
-			sleep(1);
+                GetFwAndHwVersion();
+                sleep(1);
 
-            if(strlen((char *)ShmPrimaryMcuData->version) != 0)
-            {
-                ShmPrimaryMcuData->SelfTest_Comp = YES;
+                if(strlen((char *)ShmPrimaryMcuData->version) != 0)
+                {
+                    ShmPrimaryMcuData->SelfTest_Comp = YES;
+                }
             }
-		}
-		else
-		{
-			GetInputGpioStatus();
-			//PRINTF_FUNC("Input Status: %02X %02X", ShmPrimaryMcuData->InputDet.InputDetValue[1], ShmPrimaryMcuData->InputDet.InputDetValue[0]);
-
-			SetOutputGpio(ShmPrimaryMcuData->OutputDrv.OutputDrvValue[0]);
-		}
+            else
+            {
+                GetInputGpioStatus();
+                //PRINTF_FUNC("Input Status: %02X %02X", ShmPrimaryMcuData->InputDet.InputDetValue[1], ShmPrimaryMcuData->InputDet.InputDetValue[0]);
 
+                SetOutputGpio(ShmPrimaryMcuData->OutputDrv.OutputDrvValue[0]);
+            }
+	    }
 		usleep(100000);
 	}
 

+ 11 - 5
EVSE/Projects/DO360/Apps/Module_PsuComm.c

@@ -1574,18 +1574,24 @@ int main(void)
 						if (chargingInfo[groupIndex]->PresentChargingVoltage > 0 &&
 								evseOutVol[groupIndex] != chargingInfo[groupIndex]->PresentChargingVoltage)
 						{
+						    if((int)evseOutVol[groupIndex] != (int)chargingInfo[groupIndex]->PresentChargingVoltage)
+						    {
+	                            PRINTF_FUNC("groupIndex = %d, ev need vol = %.1fV, evse output vol = %.1fV, fire voltage vol = %.1fV \n",
+	                                groupIndex, chargingInfo[groupIndex]->EvBatterytargetVoltage,
+	                                chargingInfo[groupIndex]->PresentChargingVoltage, chargingInfo[groupIndex]->FireChargingVoltage);
+						    }
 							evseOutVol[groupIndex] = chargingInfo[groupIndex]->PresentChargingVoltage;
-							PRINTF_FUNC("groupIndex = %d, ev need vol = %.1fV, evse output vol = %.1fV, fire voltage vol = %.1fV \n",
-                                groupIndex,	chargingInfo[groupIndex]->EvBatterytargetVoltage,
-								chargingInfo[groupIndex]->PresentChargingVoltage, chargingInfo[groupIndex]->FireChargingVoltage);
 						}
 
 						if (chargingInfo[groupIndex]->PresentChargingCurrent > 0 &&
 							evseOutCur[groupIndex] != chargingInfo[groupIndex]->PresentChargingCurrent)
 						{
+							if((int)evseOutCur[groupIndex] != (int)chargingInfo[groupIndex]->PresentChargingCurrent)
+							{
+                                PRINTF_FUNC("groupIndex = %d, ev need cur = %.1fA, evse output cur = %.1fA \n", groupIndex,
+                                    chargingInfo[groupIndex]->EvBatterytargetCurrent, chargingInfo[groupIndex]->PresentChargingCurrent);
+							}
 							evseOutCur[groupIndex] = chargingInfo[groupIndex]->PresentChargingCurrent;
-							PRINTF_FUNC("groupIndex = %d, ev need cur = %.1fA, evse output cur = %.1fA \n", groupIndex,
-								chargingInfo[groupIndex]->EvBatterytargetCurrent, chargingInfo[groupIndex]->PresentChargingCurrent);
 						}
 
 						if (ShmSysConfigAndInfo->SysInfo.MainChargingMode == _MAIN_CHARGING_MODE_MAX)

+ 330 - 168
EVSE/Projects/DO360/Apps/main.c

@@ -60,6 +60,9 @@
 #define		UPGRADE_PRI			0x04
 #define		UPGRADE_AC			0x05
 #define		UPGRADE_LED			0x06
+#define     UPGRADE_DORC1       0x07
+#define     UPGRADE_DORC2       0x08
+#define     UPGRADE_DDRB        0x09
 #define		SYSTEM_MIN_VOL		150
 #define 	MIN_OUTPUT_CUR		0
 #define		AC_OUTPUT_VOL		220
@@ -89,12 +92,14 @@
 #define     DISPENSER_RECONNECTE_TIME   30
 #define     DISPENSER_AUTH_COMP_TIME    3
 #define     FORCE_BALANCE_TIME          5
+#define     DISPENSER_UPGRADE_TIME      600
 
 char 	*valid_Internet[2] 	  = {"8.8.8.8", "180.76.76.76"};
 unsigned char mask_table[] = { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 };
 int whileLoopTime = 10000; // 10 ms
 int	wtdFd = -1;
 byte _authorizeIndex = NO_DEFINE;
+BOOL _UpgradeNeedReboot = FALSE;
 
 bool IsAuthorizingMode();
 void ClearAuthorizedFlag();
@@ -158,6 +163,7 @@ struct timeval                  _ConnectorAuthorizing_Time[CONNECTOR_QUANTITY];
 struct timeval                  _ConnectorAuthorizeFail_Time[CONNECTOR_QUANTITY];
 struct timeval                  _DispenserAuthorizing_Time[CONNECTOR_QUANTITY];
 int chargingTime[CONNECTOR_QUANTITY];
+struct timeval                  _DispenserUpgrade_time;
 
 // for initial index to check EV board type is correct
 byte _gunIndex = 0;
@@ -176,7 +182,7 @@ bool isModelNameMatch = true;
 
 //int rfidFd = -1;
 //char* rfidPortName = "/dev/ttyS2";
-char* fwVersion = "D0.07.00.0000.00";
+char* fwVersion = "D0.08.00.0000.00";
 
 sqlite3 *localDb;
 bool isDb_ready;
@@ -1137,11 +1143,11 @@ void InitEthernet()
 				}
 			}
 
-			bool ethResult = YES;
+            bool ethResult = YES;
 
-			if(ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet)
-				ethResult = NO;
-			else
+            if(ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet)
+                ethResult = NO;
+            else
 			{
 				system("/sbin/ifmetric eth0 0");
 
@@ -1348,6 +1354,8 @@ void InitialShareMemoryInfo()
 	char cmd[512];
 	char buf[512];
 
+	_UpgradeNeedReboot = FALSE;
+
 	sprintf((char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomApn, "Internet");
 	sprintf((char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapId, " ");
 	sprintf((char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapPwd, " ");
@@ -3121,15 +3129,19 @@ void PowerCabinetAuthorizingSettingInitial(void)
     ShmSysConfigAndInfo->SysInfo.CabinetSetting.bits.BackendAuthorized = false;
 }
 
+void AnnounceAccountBalance(unsigned char index, int balance)
+{
+    ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].Parameter.bits.AnnounceBalance = true;
+    ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].AccountBalance = balance;
+    ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].Parameter.bits.AccountBalanceRequest = true;
+    PRINTF_FUNC("Announce Account Balance %d To Connector %d", balance, index + 1);
+}
+
 void FouceAnnounceAccountBalance(unsigned char index)
 {
     if(!ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].Parameter.bits.AnnounceBalance)
     {
-        ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].Parameter.bits.AnnounceBalance = true;
-
-        ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].AccountBalance = 0;
-        ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].Parameter.bits.AccountBalanceRequest = true;
-        PRINTF_FUNC("Force Announce Account Balance To Connector %d", index + 1);
+        AnnounceAccountBalance(index, 0);
     }
 }
 
@@ -3799,157 +3811,272 @@ void KillTask()
 	system("killall Module_Wifi &");
 }
 
-char CheckUpdateProcess()
+int PutDispenserImage(char *IpAddress, char *SourcePath)
 {
-	DIR *d;
-	struct dirent *dir;
-	d = opendir("/mnt/");
+    int isPass = PASS;
+    unsigned char ftpcmdbuf[256];
 
-	if (d)
-	{
-		long int MaxLen=48*1024*1024, ImageLen = 0;
-		while ((dir = readdir(d)) != NULL)
+    PRINTF_FUNC("Transfer image(%s) to ip: %s ", SourcePath, IpAddress);
+    //Using ftpput command to transfer upgrade image,
+    //User name     : root
+    //User password : y42j/4cj84
+    //Destination   : as same as source path
+    sprintf((char*)ftpcmdbuf,"ftpput -u root -p y42j/4cj84 %s %s %s", IpAddress, SourcePath, SourcePath);
+
+    if(system((char*)ftpcmdbuf) != 0)
+    {
+        isPass = FAIL;
+        PRINTF_FUNC("Transfer Image NG - FTP put upgrade image to fail");
+    }
+    else
+    {
+        PRINTF_FUNC("FTP put Image OK");
+    }
+
+    return isPass;
+}
+
+void TriggerDispenserUpgrade(unsigned char index, char *FileName)
+{
+    memset(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].FwFileName, 0x00, 128);
+    memcpy(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].FwFileName, FileName, strlen(FileName));
+    ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[index].Setting.bits.FirmwareUpdateRequest = true;
+    PRINTF_FUNC("Trigger dispenser %d to update image %s", index + 1, FileName);
+}
+
+BOOL PutImageToAllDispenser(char *SourcePath, char *FileName)
+{
+    int isPass = FAIL;
+    BOOL transferred = FALSE;
+
+    for(int i = 0; i < GENERAL_GUN_QUANTITY; i++)
+    {
+        if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[i].Status == _CNS_DispenserMatched)
+        {
+            char DispenserIpAddress[16];
+            memset((char*)DispenserIpAddress, 0x00, 16);
+            sprintf((char*)DispenserIpAddress, "%d.%d.%d.%d",
+                ((ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[i].IpAddress >>  0) & 0xFF),
+                ((ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[i].IpAddress >>  8) & 0xFF),
+                ((ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[i].IpAddress >> 16) & 0xFF),
+                ((ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[i].IpAddress >> 24) & 0xFF));
+
+            isPass = PutDispenserImage(DispenserIpAddress, SourcePath);
+            if(isPass == PASS)
+            {
+                TriggerDispenserUpgrade(ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[i].DispenserIndex, FileName);
+            }
+            transferred = true;
+        }
+    }
+
+    return transferred;
+}
+
+BOOL WaitAllDispenserUpgradeCompleted(void)
+{
+    BOOL completed = TRUE;
+
+    gettimeofday(&_DispenserUpgrade_time, NULL);
+    do
+    {
+        completed = TRUE;
+        for(int i = 0; i < GENERAL_GUN_QUANTITY; i++)
+        {
+            if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].Setting.bits.FirmwareUpdateRequest ||
+                ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].Setting.bits.FirmwareUpdateConfirm)
+            {
+                if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].Setting.bits.FirmwareUpdateCompleted)
+                {
+                    ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].Setting.bits.FirmwareUpdateRequest = false;
+                    ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].Setting.bits.FirmwareUpdateConfirm = false;
+                    ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].Setting.bits.FirmwareUpdateCompleted = false;
+                    PRINTF_FUNC("Dispenser %d Upgrade Success", i + 1);
+                }
+                else
+                {
+                    completed = FALSE;
+                }
+            }
+        }
+
+        if(GetTimeoutValue(_DispenserUpgrade_time) / uSEC_VAL >= DISPENSER_UPGRADE_TIME)
+        {
+            PRINTF_FUNC("Wait Upgrade Timeout");
+            completed = FALSE;
+            break;
+        }
+
+        if(completed == FALSE)
+        {
+            sleep(1);
+        }
+    }while(!completed);
+
+    return completed;
+}
+
+char CheckUpdateProcess()
+{
+    char model[32];
+    bool support = false;
+    bool OneImageOnly = false;
+    int isPass = true;
+    uint8_t retSucc = 0;
+    uint8_t retFail = 0;
+    byte target = 0;
+    char *new_str = NULL;
+    unsigned char *ptr = NULL;
+    int fd = 0;
+    int uartFd = 0;
+    unsigned int Type = 0;
+    long int MaxLen = 48 * 1024 * 1024, ImageLen = 0;
+    DIR *d;
+    struct dirent *dir;
+    char cmdBuf[128];
+
+    d = opendir("/mnt/");
+
+	if(d)
+	{
+		while((dir = readdir(d)) != NULL && !OneImageOnly)
 		{
-			char *new_str;
-			new_str = malloc(strlen("/mnt/")+strlen(dir->d_name)+1);
-			new_str[0] = '\0';
+            if (strcmp(dir->d_name, ".") == 0 || strcmp(dir->d_name, "..") == 0) {
+                continue;
+            }
+
+		    new_str = calloc(strlen("/mnt/") + strlen(dir->d_name) + 1, sizeof(char));
 			strcat(new_str, "/mnt/");
 			strcat(new_str, dir->d_name);
-			int fd = open(new_str, O_RDONLY);
-			if (fd < 0)
+			fd = open(new_str, O_RDONLY);
+			if(fd < 0)
 			{
-				return FAIL;
+	            free(new_str);
+			    continue;
 			}
 
-			unsigned char *ptr = malloc(MaxLen); //-48 is take out the header
-			memset(ptr, 0xFF, MaxLen);  //-48 is take out the header
+			DEBUG_INFO_MSG("%s\n", new_str);
+
+			ptr = calloc(MaxLen, sizeof(char));     //-48 is take out the header
+			memset(ptr, 0xFF, MaxLen);              //-48 is take out the header
 			//get the image length
 			ImageLen = read(fd, ptr, MaxLen);
 
 			if (ImageLen > 20)
 			{
-				unsigned int Type = (((unsigned int)ptr[16])<<24 | ((unsigned int)ptr[17])<<16 | ((unsigned int)ptr[18])<<8 | ((unsigned int)ptr[19]));
-			    PRINTF_FUNC("Typed...%x \r\n", Type);
+			    support = false;
+			    memcpy(model, ptr, 16);
+			    PRINTF_FUNC("Model: %s", model);
+				Type = (((unsigned int)ptr[16]) << 24 | ((unsigned int)ptr[17]) << 16 | ((unsigned int)ptr[18]) << 8 | ((unsigned int)ptr[19]));
+			    PRINTF_FUNC("Typed...%x", Type);
 
-			    switch (Type)
+			    if(strcmp(model, (char *)ShmSysConfigAndInfo->SysConfig.ModelName) == EQUAL)
 			    {
-			    	case 0x10000001:
-			    	case 0x10000002:
-			    	case 0x10000003:
-			    	case 0x10000004:
-			    	case 0x10000005:
-			    	{
-			    		if (Upgrade_Flash(Type, new_str, (char *)ShmSysConfigAndInfo->SysConfig.ModelName) == PASS)
-			    			return PASS;
-			    		else
-			    			return FAIL;
-			    	}
-			    	break;
-					case 0x10000007:
-					case 0x10000008:
-					case 0x10000009:
-					case 0x1000000A:
-					{
-						bool isPass = true;
-						int CanFd = InitCanBus();
+                    switch (Type)
+                    {
+                        case 0x10000001:
+                        case 0x10000002:
+                        case 0x10000003:
+                        case 0x10000004:
+                        case 0x10000005:
+                            support = true;
+                            _UpgradeNeedReboot = TRUE;
+                            isPass = Upgrade_Flash(Type, new_str, (char *)ShmSysConfigAndInfo->SysConfig.ModelName);
+                            break;
+
+                        case 0x10000006:            // primary mcu
+                        case 0x1000000D:            // relay board
+                        case 0x1000000E:            // fan board
+                        case 0x10000014:            // led board
+                            support = true;
+                            target = 0x00;
+
+                            if (Type == 0x10000006)
+                            {
+                                target = UPGRADE_PRI;
+                            }
+                            else if (Type == 0x1000000D)
+                            {
+                                target = UPGRADE_RB;
+                            }
+                            else if (Type == 0x1000000E)
+                            {
+                                target = UPGRADE_FAN;
+                            }
+                            else if (Type == 0x10000014)
+                            {
+                                target = UPGRADE_LED;
+                            }
 
-						if (CanFd > 0)
-						{
-							for(byte index = 0; index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; index++)
-							{
-								if (!isPass)
-						        break;
-
-						        if (chargingInfo[index]->Type == _Type_CCS_2)
-						        {
-						        	if (Upgrade_CCS(CanFd, Type, chargingInfo[index]->Evboard_id, new_str, (char *)ShmSysConfigAndInfo->SysConfig.ModelName) == FAIL)
-						            {
-						            	isPass = false;
-						            }
-						        }
-						    }
-						}
-						else
-						{
-						    printf("Upgrade CCS open CAN FD fail.\n");
-						    isPass = false;
-						}
+                            uartFd = InitComPort(target);
 
-						return isPass;
-					}
-						break;
-			    	case 0x10000006:
-			    	case 0x1000000D:
-			    	case 0x1000000E:
-			    	case 0x20000002:
-			    	case 0x10000014:
-			    	{
-			    		// CSU_PRIMARY_CONTROLLER : 0x10000006
-			    		byte target = 0x00;
-
-			    		if (Type == 0x10000006)
-			    			target = UPGRADE_PRI;
-			    		else if (Type == 0x1000000D)
-			    			target = UPGRADE_RB;
-			    		else if (Type == 0x1000000E)
-			    			target = UPGRADE_FAN;
-			    		else if (Type == 0x20000002)
-			    			target = UPGRADE_AC;
-			    		else if (Type == 0x10000014)
-			    			target = UPGRADE_LED;
-
-			    		int fd = InitComPort(target);
-
-			    		if (Upgrade_UART(fd, Type, target, new_str, (char *)ShmSysConfigAndInfo->SysConfig.ModelName) == PASS)
-			    			return PASS;
-			    		else
-			    			return FAIL;
-
-			    		close(fd);
-			    	}
-			    	break;
-			    	case 0x1000000B:
-			    	case 0x1000000C:
-			    	{
-			    		// CHAdeMO_BOARD : 0x1000000B, GBT : 0x1000000C
-			    		bool isPass = true;
-			    		int CanFd = InitCanBus();
-
-			    		if (CanFd > 0)
-			    		{
-			    			for(byte index = 0; index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; index++)
-			    			{
-			    				if (!isPass)
-			    					break;
-
-			    				if ((Type == 0x1000000B && chargingInfo[index]->Type == _Type_Chademo) ||
-			    						(Type == 0x1000000C && chargingInfo[index]->Type == _Type_GB))
-			    				{
-			    					if (Upgrade_CAN(CanFd, Type, chargingInfo[index]->Evboard_id, new_str, (char *)ShmSysConfigAndInfo->SysConfig.ModelName) == PASS)
-			    						return PASS;
-			    					else
-			    						return FAIL;
-			    				}
-			    			}
-			    		}
-			    		else
-			    		{
-			    			PRINTF_FUNC("Upgrad FD fail. \n");
-			    			isPass = false;
-			    		}
-
-			    		return isPass;
-			    		break;
-			    	}
+                            if(target == UPGRADE_RB)
+                            {
+                                isPass = Upgrade_UART(uartFd, Type, UPGRADE_DORC1, new_str, (char *)ShmSysConfigAndInfo->SysConfig.ModelName);
+                                if(isPass == PASS)
+                                {
+                                    retSucc++;
+                                }
+                                else
+                                {
+                                    retFail++;
+                                }
+                                PRINTF_FUNC("Upgrade %s", isPass == PASS ? "Success" : "Fail");
+                                sleep(3);
+                                isPass = Upgrade_UART(uartFd, Type, UPGRADE_DORC2, new_str, (char *)ShmSysConfigAndInfo->SysConfig.ModelName);
+                            }
+                            else
+                            {
+                                isPass = Upgrade_UART(uartFd, Type, target, new_str, (char *)ShmSysConfigAndInfo->SysConfig.ModelName);
+                            }
+
+                            close(fd);
+                            break;
+                    }
+
+                    if(support)
+                    {
+                        if(isPass == PASS)
+                        {
+                            retSucc++;
+                        }
+                        else
+                        {
+                            retFail++;
+                        }
+                        PRINTF_FUNC("Upgrade %s", isPass == PASS ? "Success" : "Fail");
+                    }
+			    }
+			    else
+			    {
+			        if(model[0] == 'D' && model[1] == 'D')
+			        {
+			            OneImageOnly = true;
+			            _UpgradeNeedReboot = TRUE;
+			            PRINTF_FUNC("Start Put Image To All Dispenser");
+			            PutImageToAllDispenser(new_str, dir->d_name);
+			            WaitAllDispenserUpgradeCompleted();
+			            PRINTF_FUNC("All Dispenser Upgrade Completed");
+			        }
 			    }
 			}
-			free(new_str);
-			free(ptr);
+
+		    sprintf(cmdBuf, "rm -f %s", new_str);
+		    system(cmdBuf);
+
+            free(new_str);
+            free(ptr);
 		}
 	}
 	free(dir);
 	closedir(d);
-	return FAIL;
+
+    if(retFail != 0)
+    {
+        return FAIL;
+    }
+
+    return PASS;
 }
 
 /*
@@ -4333,16 +4460,28 @@ void CheckFwUpdateFunction()
 	//PRINTF_FUNC("ShmSysConfigAndInfo->SysInfo.FirmwareUpdate = %d \n", ShmSysConfigAndInfo->SysInfo.FirmwareUpdate);
 	if (ShmSysConfigAndInfo->SysInfo.FirmwareUpdate == YES)
 	{
-		DEBUG_INFO_MSG("ftp : update start. \n");
-		KillTask();
+		DEBUG_INFO_MSG("ftp : update start.");
+		//KillTask();
+	    ChangeLcmByIndex(_LCM_FIX);
+	    system("killall Module_PrimaryComm");
+	    system("killall Module_InternalComm");
+
 		if (CheckUpdateProcess() == PASS)
-			DEBUG_INFO_MSG("ftp : update complete. \n");
+			DEBUG_INFO_MSG("ftp : update complete.");
 		else
-			DEBUG_INFO_MSG("ftp : update fail. \n");
+			DEBUG_INFO_MSG("ftp : update fail.");
 
 		ShmSysConfigAndInfo->SysInfo.FirmwareUpdate = NO;
 		sleep(5);
-		system("reboot -f");
+		if(_UpgradeNeedReboot)
+		{
+		    system("reboot -f");
+		}
+		else
+		{
+            KillTask();
+            system("/usr/bin/run_evse_restart.sh");
+		}
 	}
 	else if(ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq == YES)
 	{
@@ -4354,16 +4493,14 @@ void CheckFwUpdateFunction()
 			strcpy((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "");
 			strcpy((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "Installing");
 			ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = YES;
-			KillTask();
+			//KillTask();
+	        system("killall Module_PrimaryComm");
+	        system("killall Module_InternalComm");
 
 			for (byte _index = 0; _index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _index++)
 			{
 				setChargerMode(_index, MODE_UPDATE);
 			}
-			for (byte _index = 0; _index < ShmSysConfigAndInfo->SysConfig.AcConnectorCount; _index++)
-			{
-				ac_chargingInfo[_index]->SystemStatus = MODE_UPDATE;
-			}
 
 			if (CheckUpdateProcess() == PASS)
 			{
@@ -4379,7 +4516,16 @@ void CheckFwUpdateFunction()
 			strcpy((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "Installed");
 			ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = YES;
 			sleep(5);
-			system("reboot -f");
+
+	        if(_UpgradeNeedReboot)
+	        {
+	            system("reboot -f");
+	        }
+	        else
+	        {
+	            KillTask();
+	            system("/usr/bin/run_evse_restart.sh");
+	        }
 		}
 	}
 }
@@ -4607,12 +4753,9 @@ void UserPriceHandler(char *UserId, char *UserPrice)
             ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].UserPrice = CurrentRate;
             ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].AccountBalance = AccountBalance;
 
-            int DispenserIndex = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].ParentDispensetIndex;
-
-            if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[DispenserIndex].AuthorizeStatus == _AuthorizeStatus_Pass &&
-                ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].Parameter.bits.AuthorizeRequestType == _AuthorizeSrc_Local)
+            if(chargingInfo[i]->SystemStatus == S_AUTHORIZING)
             {
-                ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].Parameter.bits.AccountBalanceRequest = true;
+                AnnounceAccountBalance(i, AccountBalance);
             }
         }
     }
@@ -5687,25 +5830,27 @@ void CheckMiscCommandRequirement(void)
 {
     BOOL NeedAnnouncement = FALSE;
 
-    for(int i = 0; i < CONNECTOR_QUANTITY; i++)
+    if(ShmSysConfigAndInfo->SysInfo.FirmwareUpdate != YES)
     {
-        if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].Parameter.bits.AvailabilityRequest ||
-            ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].Parameter.bits.RemoteStartRequest ||
-            ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].Parameter.bits.AccountBalanceRequest)
+        for(int i = 0; i < CONNECTOR_QUANTITY; i++)
         {
-            NeedAnnouncement = TRUE;
-        }
+            if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].Parameter.bits.AvailabilityRequest ||
+                ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].Parameter.bits.RemoteStartRequest ||
+                ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].Parameter.bits.AccountBalanceRequest)
+            {
+                NeedAnnouncement = TRUE;
+            }
 
-        if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].Setting.bits.ConnectorTimeoutConfigRequest ||
-            ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].Setting.bits.DefaultPriceConfigRequest ||
-            ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].Setting.bits.CurrencyConfigRequest ||
-            ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].Setting.bits.HardwareRebootRequest ||
-            ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].Setting.bits.SoftwareResetRequest)
-        {
-            NeedAnnouncement = TRUE;
+            if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].Setting.bits.ConnectorTimeoutConfigRequest ||
+                ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].Setting.bits.DefaultPriceConfigRequest ||
+                ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].Setting.bits.CurrencyConfigRequest ||
+                ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].Setting.bits.HardwareRebootRequest ||
+                ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].Setting.bits.SoftwareResetRequest)
+            {
+                NeedAnnouncement = TRUE;
+            }
         }
     }
-
     ShmSysConfigAndInfo->SysInfo.CabinetSetting.bits.MiscNeedAnnouncement = NeedAnnouncement;
 }
 
@@ -6008,6 +6153,12 @@ int main(void)
 
 						ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].Parameter.bits.StartWaitPlug = false;
 						ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].Parameter.bits.NeedCleanAuthorizeInfo = false;
+						ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].Parameter.bits.OutputLimitEnable = false;
+
+						chargingInfo[gun_index]->EvBatterytargetVoltage = 0;
+						chargingInfo[gun_index]->EvBatterytargetCurrent = 0;
+						ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].RemoteTargetVoltage = 0;
+						ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].RemoteTargetCurrent = 0;
 					}
 					else if (chargingInfo[gun_index]->SystemStatus == S_RESERVATION &&
 							isModeChange(gun_index))
@@ -6253,6 +6404,16 @@ int main(void)
 							ShmSysConfigAndInfo->SysInfo.OrderCharging = NO_DEFINE;
 						StopSystemTimeoutDet();
 						ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].Parameter.bits.PsuReleasable = false;
+						ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].MaxTotalChargingCurrent = ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent * 10;
+						ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].MaxTotalChargingPower = ShmSysConfigAndInfo->SysConfig.MaxChargingPower * 10;
+						ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].MaxOutputEnergy = ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy;
+						ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].MaxOutputDuration = ShmSysConfigAndInfo->SysConfig.MaxChargingDuration;
+
+						PRINTF_FUNC("Max Total Current %d, Max Total Power %d, Total Energy %d, Total Duration %d",
+                            ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].MaxTotalChargingCurrent,
+                            ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].MaxTotalChargingPower,
+                            ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].MaxOutputEnergy,
+                            ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun_index].MaxOutputDuration);
 					}
 
 					bool isRessign = false;
@@ -6333,6 +6494,7 @@ int main(void)
 						PRINTF_FUNC("=============Smart Charging : _REASSIGNED_COMP============= Step 6 \n");
 						ShmSysConfigAndInfo->SysInfo.MainChargingMode = _MAIN_CHARGING_MODE_AVER;
 						ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_NONE;
+						setChargerMode(gun_index, MODE_PRECHARGE);
 					}
 
 					//PRINTF_FUNC("CurGunSelected = %d, gun_index = %d \n", ShmSysConfigAndInfo->SysInfo.CurGunSelected, gun_index);

二进制
EVSE/Projects/DO360/Images/FactoryDefaultConfig.bin


二进制
EVSE/Projects/DO360/Images/ramdisk.gz


+ 51 - 17
EVSE/Projects/DS60-120/Apps/Config.h

@@ -7,6 +7,9 @@
 #ifndef CONFIG_H_
 #define CONFIG_H_
 
+#define ShmCsuMeterKey			2001
+#define ShmCommonKey			2002
+
 typedef unsigned char			byte;
 
 #define TOTAL_QUANTITY_GUN			4				//Max Count
@@ -88,21 +91,6 @@ enum _GUN_TYPE
 	_Type_AC,
 };
 
-//enum _LCM_INDEX
-//{
-//	_LCM_INIT = 			0x00,
-//	_LCM_IDLE = 			0x01,
-//	_LCM_AUTHORIZING = 		0x04,
-//	_LCM_AUTHORIZ_COMP = 	0x05,
-//	_LCM_AUTHORIZ_FAIL = 	0x06,
-//	_LCM_WAIT_FOR_PLUG = 	0x07,
-//	_LCM_PRE_CHARGE = 		0x08,
-//	_LCM_CHARGING = 		0x09,
-//	_LCM_COMPLETE = 		0x0A,
-//	_LCM_FIX = 				0x0B,
-//	_LCM_NONE = 			0xFF,
-//};
-
 enum _LCM_INDEX
 {
 	_LCM_INIT = 			0x00,
@@ -139,8 +127,7 @@ enum _MODULE_PSU_WORK_STEP
 
 	_TEST_MODE			=		20,
 
-	_NO_WORKING			= 		254,
-	_INIT_PSU_STATUS	= 		255
+	_NO_WORKING			= 		254
 };
 
 enum _OFFLINE_POLICY
@@ -220,4 +207,51 @@ enum _PRIMARY_CHECK_TAG
 	_PRIMARY_CHECK_TAG_MAIN_BREAKER		= 1,
 };
 
+struct StructMeter
+{
+	float curMeterValue;
+	float newMeterValue;
+	byte isCalculation;
+	float _chargingValue;
+	float _curTotalCharging;
+};
+
+struct MeterInformation
+{
+	struct StructMeter _meter[2];
+	byte isWorking;
+};
+
+enum _CCS_VERSION_CHECK_TAG
+{
+	_CCS_VERSION_CHECK_TAG_V015S0		= 0,
+	_CCS_VERSION_CHECK_TAG_V013S0		= 1,
+};
+
+enum RELAY_STATUS_ERROR_INDEX
+{
+	RELAY_SMR1_P_STATUS = 	0,
+	RELAY_SMR1_N_STATUS = 	1,
+	RELAY_SMR2_P_STATUS = 	2,
+	RELAY_SMR2_N_STATUS = 	3,
+	RELAY_PARA_P_STATUS = 	4,
+	RELAY_PARA_N_STATUS = 	5,
+};
+
+enum RELAY_STATUS_ERROR_TYPE
+{
+	RELAY_STATUS_ERROR_NONE = 0,
+	RELAY_STATUS_ERROR_WELDING = 10,
+	RELAY_STATUS_ERROR_DRIVING = 11
+};
+
+struct DcCommonInformation
+{
+	byte SysGunAreSameType;
+	byte CcsVersion;
+	char RelayCheckStatus[6];
+	char GunRelayWeldingOccur[2];
+	char GunRelayDrivingOccur[2];
+};
+
 #endif /* CONFIG_H_ */

二进制
EVSE/Projects/DS60-120/Apps/FactoryConfig


+ 6 - 4
EVSE/Projects/DS60-120/Apps/FactoryConfig.c

@@ -155,10 +155,12 @@ int main(int argc,char *argv[])
 	strcpy((char *) SysConfig.Eth1Interface.EthIpAddress, "192.168.0.10");
 	strcpy((char *) SysConfig.Eth1Interface.EthSubmaskAddress, "255.255.255.0");
 	strcpy((char *) SysConfig.Eth1Interface.EthGatewayAddress, "192.168.0.254");
-	if(SysConfig.ModelName[10] == 'W' || SysConfig.ModelName[10] == 'D')
-		SysConfig.AthInterface.WifiMode = 2;
-	else
-		SysConfig.AthInterface.WifiMode = 0;
+//	if(SysConfig.ModelName[10] == 'W' || SysConfig.ModelName[10] == 'D')
+//		SysConfig.AthInterface.WifiMode = 2;
+//	else
+//		SysConfig.AthInterface.WifiMode = 0;
+	SysConfig.AthInterface.WifiMode = 0;
+	SysConfig.TelecomInterface.TelcomEnabled = 0;
 	strcpy((char *) SysConfig.AthInterface.WifiSsid, "");
 	strcpy((char *) SysConfig.AthInterface.WifiPassword, "");
 	SysConfig.AthInterface.WifiRssi = 0;

二进制
EVSE/Projects/DS60-120/Apps/Module_EvComm


+ 231 - 88
EVSE/Projects/DS60-120/Apps/Module_EvComm.c

@@ -50,6 +50,8 @@ struct CHAdeMOData				*ShmCHAdeMOData;
 struct GBTData					*ShmGBTData;
 struct CcsData					*ShmCcsData;
 struct PsuData 					*ShmPsuData;
+struct MeterInformation			*ShmCsuMeterData;
+struct DcCommonInformation		*ShmDcCommonData;
 
 byte gun_count;
 int chargingTime[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
@@ -143,10 +145,11 @@ int StoreLogMsg(const char *fmt, ...)
 	}
 	else
 	{
-		sprintf(Buf,"echo \"%04d-%02d-%02d %02d:%02d:%02d:%03d - %s\" >> /Storage/SystemLog/[%04d.%02d]SystemLog",
+		sprintf(Buf,"echo \"%04d-%02d-%02d %02d:%02d:%02d:%03d - %s\" >> /Storage/SystemLog/[%04d.%02d]SystemLog_%s",
 			tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,SeqEndTime.millitm,
 			buffer,
-			tm->tm_year+1900,tm->tm_mon+1);
+			tm->tm_year+1900,tm->tm_mon+1,
+			ShmSysConfigAndInfo->SysConfig.SerialNumber);
 		system(Buf);
 	}
 
@@ -187,30 +190,30 @@ void getTimeString(char *buff)
 	sprintf(buff, "[%04d-%02d-%02d %02d:%02d:%02d]", (1900+p->tm_year), (1+p->tm_mon), p->tm_mday, p->tm_hour, p->tm_hour, p->tm_sec);
 }
 
-bool CheckUniqNumber(byte value)
-{
-	for (byte index = 0; index < gun_count; index++)
-	{
-		if (_chargingData[index]->Evboard_id == value)
-		{
-			struct timeval _end_time;
-			gettimeofday(&_end_time, NULL);
-			unsigned long diff = 1000000 *	(_end_time.tv_sec - _id_assign_time.tv_sec) + _end_time.tv_usec - _id_assign_time.tv_usec;
-			if (diff >= 3000000)
-			{
-				gettimeofday(&_id_assign_time, NULL);
-				return true;
-			}
-			else
-			{
-				return false;
-			}
-		}
-	}
-
-	gettimeofday(&_id_assign_time, NULL);
-	return true;
-}
+//bool CheckUniqNumber(byte value)
+//{
+//	for (byte index = 0; index < gun_count; index++)
+//	{
+//		if (_chargingData[index]->Evboard_id == value)
+//		{
+//			struct timeval _end_time;
+//			gettimeofday(&_end_time, NULL);
+//			unsigned long diff = 1000000 *	(_end_time.tv_sec - _id_assign_time.tv_sec) + _end_time.tv_usec - _id_assign_time.tv_usec;
+//			if (diff >= 3000000)
+//			{
+//				gettimeofday(&_id_assign_time, NULL);
+//				return true;
+//			}
+//			else
+//			{
+//				return false;
+//			}
+//		}
+//	}
+//
+//	gettimeofday(&_id_assign_time, NULL);
+//	return true;
+//}
 
 //==========================================
 // Init all share memory
@@ -234,12 +237,10 @@ int InitShareMemory()
     	DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
 		#endif
     	result = FAIL;
-   	 }
-    else
-    {}
+   	}
 
-   	 //initial ShmStatusCodeData
-   	 if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData),  0777)) < 0)
+   	//initial ShmStatusCodeData
+   	if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData),  0777)) < 0)
     {
 		#ifdef SystemLogMessage
    		DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
@@ -253,8 +254,6 @@ int InitShareMemory()
 		#endif
     	result = FAIL;
    	}
-    else
-    {}
 
  	//creat ShmPsuData
  	if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData),  0777)) < 0)
@@ -288,8 +287,6 @@ int InitShareMemory()
    			#endif
    			return FAIL;
    		}
-   		else
-   		{}
    	}
 	if(GB_QUANTITY > 0)
 	{
@@ -307,8 +304,6 @@ int InitShareMemory()
 	   		#endif
 	   		return FAIL;
 	   	}
-	   	else
-	   	{}
 	}
 
    	if(CCS_QUANTITY > 0)
@@ -326,8 +321,36 @@ int InitShareMemory()
    			#endif
    			return FAIL;
    		}
-   		else
-   		{}
+   	}
+
+   	if ((MeterSMId = shmget(ShmCsuMeterKey, sizeof(struct MeterInformation), IPC_CREAT | 0777)) < 0)
+   	{
+   		#ifdef SystemLogMessage
+   		DEBUG_ERROR("shmget ShmCsuMeterKey NG \n");
+   		#endif
+   		return 0;
+   	}
+   	else if ((ShmCsuMeterData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
+   	{
+   		#ifdef SystemLogMessage
+   		DEBUG_ERROR("shmat ShmCsuMeterData NG \n");
+   		#endif
+   		return 0;
+   	}
+
+   	if ((MeterSMId = shmget(ShmCommonKey, sizeof(struct DcCommonInformation), IPC_CREAT | 0777)) < 0)
+   	{
+   		#ifdef SystemLogMessage
+   		DEBUG_ERROR("shmget ShmCommonKey NG \n");
+   		#endif
+   		return 0;
+   	}
+   	else if ((ShmDcCommonData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
+   	{
+   		#ifdef SystemLogMessage
+   		DEBUG_ERROR("shmat ShmCommonKey NG \n");
+   		#endif
+   		return 0;
    	}
 
     return result;
@@ -2686,6 +2709,7 @@ void CANReceiver()
 		int nbytes;
 		struct can_frame frame;
 		int intCmd;
+		bool isClearBuf = false;
 
 		// 槍資訊
 		struct ChargingInfoData *_chargingData[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
@@ -2731,10 +2755,18 @@ void CANReceiver()
 			{
 				byte target;
 				byte targetGun = 0x00;
+				byte findIndex = 0x00;
+
 				intCmd = (int) (frame.can_id & CAN_EFF_MASK);
 
+				if (!isClearBuf)
+				{
+					continue;
+				}
+
 				if (intCmd == ADDRESS_REQ)
 				{
+					ShmDcCommonData->CcsVersion = _CCS_VERSION_CHECK_TAG_V013S0;
 					AddrAssignment(frame.data);
 					continue;
 				}
@@ -2743,6 +2775,15 @@ void CANReceiver()
 
 				for (byte _index = 0; _index < gun_count; _index++)
 				{
+					// 假設有找到回應的 Index
+					findIndex = target;
+					if (gun_count == 1 &&
+							_chargingData[_index]->Type == _Type_CCS_2 &&
+							ShmDcCommonData->CcsVersion == _CCS_VERSION_CHECK_TAG_V015S0)
+					{
+						target -= 1;
+					}
+
 					if (_chargingData[_index]->Evboard_id == target)
 					{
 						targetGun = _index;
@@ -2755,6 +2796,13 @@ void CANReceiver()
 					PRINTF_FUNC("EvComm (CANReceiver) : Target index = %x is < 0 or > QUANTITY \n", targetGun);
 					continue;
 				}
+				else if (gun_count == 1 && targetGun == 0 && findIndex == 1 &&
+						ShmDcCommonData->CcsVersion == _CCS_VERSION_CHECK_TAG_V015S0)
+				{
+					// 這樣的條件下~ 也是單槍 CCS 舊版本的狀況 : 因為舊版 CCS 不會 timeout, then send request id
+					ShmDcCommonData->CcsVersion = _CCS_VERSION_CHECK_TAG_V013S0;
+				}
+
 				if(intCmd == 256)
 				{
 					continue;
@@ -2980,7 +3028,10 @@ void CANReceiver()
 				}
 			}
 			else
+			{
+				isClearBuf = true;
 				usleep(10000);
+			}
 		}
 	}
 }
@@ -3020,7 +3071,6 @@ void SetPresentChargingOutputPower(struct ChargingInfoData *chargingData_1, stru
 
 	cur2 = (chargingData_2->PresentChargingCurrent * 10);
 
-
 	if (
 		(LogInfo[0][EV_LOG_NOW_OUTPUT_VOL] >= vol1 + CHK_VOL_RANGE) || (LogInfo[0][EV_LOG_NOW_OUTPUT_VOL] <= vol1 - CHK_VOL_RANGE) ||
 		(LogInfo[0][EV_LOG_NOW_OUTPUT_CUR] >= cur1 + CHK_CUR_RANGE) || (LogInfo[0][EV_LOG_NOW_OUTPUT_CUR] <= cur1 - CHK_CUR_RANGE) ||
@@ -3094,10 +3144,10 @@ void SetPresentChargingOutputCap(struct ChargingInfoData *chargingData_1, struct
 		}
 	}
 
-	if ((LogInfo[0][EV_LOG_OUTPUT_CAP_POW] <= pow1 - 0.5 || LogInfo[0][EV_LOG_OUTPUT_CAP_POW] >= pow1 + 0.5) ||
-		(LogInfo[0][EV_LOG_OUTPUT_CAP_CUR] <= cur1 - 0.5 || LogInfo[0][EV_LOG_OUTPUT_CAP_CUR] >= cur1+ 0.5) ||
-		(LogInfo[1][EV_LOG_OUTPUT_CAP_POW] <=  pow2 - 0.5 || LogInfo[1][EV_LOG_OUTPUT_CAP_POW] >=  pow2 + 0.5) ||
-		(LogInfo[1][EV_LOG_OUTPUT_CAP_CUR] <=  cur2 - 0.5 || LogInfo[1][EV_LOG_OUTPUT_CAP_CUR] >=  cur2 + 0.5))
+	if ((LogInfo[0][EV_LOG_OUTPUT_CAP_POW] <= pow1 - 5 || LogInfo[0][EV_LOG_OUTPUT_CAP_POW] >= pow1 + 5) ||
+		(LogInfo[0][EV_LOG_OUTPUT_CAP_CUR] <= cur1 - 5 || LogInfo[0][EV_LOG_OUTPUT_CAP_CUR] >= cur1 + 5) ||
+		(LogInfo[1][EV_LOG_OUTPUT_CAP_POW] <= pow2 - 5 || LogInfo[1][EV_LOG_OUTPUT_CAP_POW] >= pow2 + 5) ||
+		(LogInfo[1][EV_LOG_OUTPUT_CAP_CUR] <= cur2 - 5 || LogInfo[1][EV_LOG_OUTPUT_CAP_CUR] >= cur2 + 5))
 	{
 		PRINTF_FUNC("----------------------------------------------------- \n");
 		PRINTF_FUNC("To EV (Real) Power_1 = %.1f, Cur_1 = %.1f, Power_2 = %.1f, Cur_2 = %.1f \n",
@@ -3312,20 +3362,38 @@ byte GetStopChargingReasonByEvse(byte gunIndex, byte *reason)
 
 void SendCommunicationOnly(byte index)
 {
+	byte targetID = _chargingData[index]->Evboard_id;
+
+	if (gun_count == 1 &&
+			_chargingData[index]->Type == _Type_CCS_2 &&
+			ShmDcCommonData->CcsVersion == _CCS_VERSION_CHECK_TAG_V015S0)
+	{
+		targetID += 1;
+	}
+
 	SetChargingPermission(index, COMMUNICATION,
 		_chargingData[index]->AvailableChargingPower,
 		0,
 		0,
-		_chargingData[index]->Evboard_id);
+		targetID);
 }
 
 void SendStopOnly(byte index)
 {
+	byte targetID = _chargingData[index]->Evboard_id;
+
+	if (gun_count == 1 &&
+			_chargingData[index]->Type == _Type_CCS_2 &&
+			ShmDcCommonData->CcsVersion == _CCS_VERSION_CHECK_TAG_V015S0)
+	{
+		targetID += 1;
+	}
+
 	SetChargingPermission(index, STOP,
 		_chargingData[index]->AvailableChargingPower,
 		0,
 		0,
-		_chargingData[index]->Evboard_id);
+		targetID);
 }
 
 void FormatVoltageAndCurrent()
@@ -3415,6 +3483,49 @@ void FormatVoltageAndCurrent()
 	}
 }
 
+// 如果是使用 Meter 計算的話
+void CalOutputPowerAndEnergy(int _index)
+{
+	if(ShmSysConfigAndInfo->SysConfig.ModelName[3] == 'M')
+	{
+		//printf("(%d), totalChargingValue = %f \n", _index, ShmCsuMeterData->_meter[_index]._curTotalCharging / 100);
+		float totalChargingValue = ShmCsuMeterData->_meter[_index]._curTotalCharging / 100;
+
+		_chargingData[_index]->PresentChargedEnergy = totalChargingValue;
+		_chargingData[_index]->PowerConsumption = totalChargingValue;
+
+		if (ShmSysConfigAndInfo->SysConfig.BillingData.isBilling)
+		{
+			_chargingData[_index]->ChargingFee = totalChargingValue * ShmSysConfigAndInfo->SysConfig.BillingData.Cur_fee;
+		}
+	}
+	else
+	{
+		if (chargingTime[_index] == 0 ||
+			chargingTime[_index] > _chargingData[_index]->PresentChargedDuration)
+		{
+			chargingTime[_index] = _chargingData[_index]->PresentChargedDuration;
+		}
+		else
+		{
+			int passTime = _chargingData[_index]->PresentChargedDuration - chargingTime[_index];
+
+			if (passTime > 0)
+			{
+				float changingPow = (_chargingData[_index]->PresentChargingPower) * passTime / 3600;
+				if (ShmSysConfigAndInfo->SysConfig.BillingData.isBilling)
+				{
+					_chargingData[_index]->ChargingFee += changingPow * ShmSysConfigAndInfo->SysConfig.BillingData.Cur_fee;
+				}
+
+				_chargingData[_index]->PresentChargedEnergy += changingPow;
+				_chargingData[_index]->PowerConsumption += changingPow;
+				chargingTime[_index] = _chargingData[_index]->PresentChargedDuration;
+			}
+		}
+	}
+}
+
 int main(int argc, char *argv[])
 {
 	if(InitShareMemory() == FAIL)
@@ -3463,6 +3574,15 @@ int main(int argc, char *argv[])
 	{
 		for(byte _index = 0; _index < gun_count; _index++)
 		{
+			byte targetID = _chargingData[_index]->Evboard_id;
+
+			if (gun_count == 1 &&
+					_chargingData[_index]->Type == _Type_CCS_2 &&
+					ShmDcCommonData->CcsVersion == _CCS_VERSION_CHECK_TAG_V015S0)
+			{
+				targetID += 1;
+			}
+
 			if (priorityLow == 1)
 			{
 				// 優先權較低 - 只要有回應即不會再詢問
@@ -3483,18 +3603,19 @@ int main(int argc, char *argv[])
 					if (ShmCcsData->CommProtocol == _CCS_COMM_V2GMessage_DIN70121 &&
 						ShmCcsData->V2GMessage_DIN70121[_chargingData[_index]->type_index].SelfTest_Comp != PASS)
 					{
-						SyncRtcInfo(_index, _chargingData[_index]->Evboard_id, (int)rtc);
-						GetFirmwareVersion(_index, _chargingData[_index]->Evboard_id);
+						SyncRtcInfo(_index, targetID, (int)rtc);
+						GetFirmwareVersion(_index, targetID);
 					}
 				}
 
 				// 固定要取得的資訊 : 1.槍鎖狀態, 2."Connector 1" 溫度, 3."Connector 2" 溫度, 4.Pilot Voltage
 				//PRINTF_FUNC("GetMiscellaneousInfo. index = %d, Eid = %d \n", _index, _chargingData[_index]->Evboard_id);
+
 				GetMiscellaneousInfo(_index,
 						_chargingData[_index]->RelayK1K2Status,
 						_chargingData[_index]->PresentChargedEnergy,
 						(_chargingData[_index]->PresentChargingVoltage * 10),
-						_chargingData[_index]->Evboard_id);
+						targetID);
 			}
 
 			switch (_chargingData[_index]->SystemStatus)
@@ -3560,6 +3681,22 @@ int main(int argc, char *argv[])
 						chargingTime[_index] = 0;
 						SendErrorCount[_index] = 0;
 
+						// 使用 Meter 狀況
+						if(ShmSysConfigAndInfo->SysConfig.ModelName[3] == 'M')
+						{
+							if (ShmCsuMeterData->_meter[_index].isCalculation == NO)
+							{
+								if (ShmCsuMeterData->_meter[_index].curMeterValue != 0 ||
+									ShmCsuMeterData->_meter[_index]._chargingValue != 0 ||
+									ShmCsuMeterData->_meter[_index]._curTotalCharging != 0 )
+								{
+									ShmCsuMeterData->_meter[_index].curMeterValue = 0;
+									ShmCsuMeterData->_meter[_index]._chargingValue = 0;
+									ShmCsuMeterData->_meter[_index]._curTotalCharging = 0;
+								}
+							}
+						}
+
 						//maxChargingPow = ShmSysConfigAndInfo->SysConfig.MaxChargingPower * 10;
 						// ShmPsuData->SystemAvailablePower 已是 * 10
 						maxChargingPow = ShmPsuData->SystemAvailablePower;
@@ -3572,6 +3709,11 @@ int main(int argc, char *argv[])
 						LogInfo[_index][EV_LOG_MAX_BATT_VOL] = 0;
 						LogInfo[_index][EV_LOG_REAL_CAP_POW] = 0;
 						LogInfo[_index][EV_LOG_SOC] = 0;
+
+						if (gun_count == 1)
+							SetPresentChargingOutputPower(_chargingData[0], _chargingData[0]);
+						else if (gun_count == 2)
+							SetPresentChargingOutputPower(_chargingData[0], _chargingData[1]);
 					}
 					break;
 				case S_PREPARNING:
@@ -3589,7 +3731,7 @@ int main(int argc, char *argv[])
 				case S_PREPARING_FOR_EV:
 				{
 					// 開始確認車端是否同意開始充電 : 1.SOC, 2.Target Vol, 3.Target Cur, 4.Charging remaining time
-					GetOutputReq(_index, _chargingData[_index]->Evboard_id);
+					GetOutputReq(_index, targetID);
 
 					// 設定當前輸出
 					if (gun_count == 1)
@@ -3622,10 +3764,10 @@ int main(int argc, char *argv[])
 						_chargingData[_index]->AvailableChargingPower,
 								maxCur,
 								maxVol,
-								_chargingData[_index]->Evboard_id);
+								targetID);
 
 						// 取得車端電池資訊 : 1.AC or DC ? 2.Total battery cap, 3.Max battery vol, 4.Max battery cur
-						GetEvBatteryInfo(_index, _chargingData[_index]->Evboard_id);
+						GetEvBatteryInfo(_index, targetID);
 					}
 					gettimeofday(&_chk_ratingPower_timeout[_index], NULL);
 				}
@@ -3635,7 +3777,7 @@ int main(int argc, char *argv[])
 				case S_CCS_PRECHARGE_ST1:
 				{
 					// 開始確認車端是否同意開始充電
-					GetOutputReq(_index, _chargingData[_index]->Evboard_id);
+					GetOutputReq(_index, targetID);
 
 					// 設定當前輸出
 					if (gun_count == 1)
@@ -3704,47 +3846,26 @@ int main(int argc, char *argv[])
 									_result = GFD_WAIT;
 							}
 
-							SetIsolationStatus(_index, _result, _chargingData[_index]->Evboard_id);
+							SetIsolationStatus(_index, _result, targetID);
 						}
 
 						if(_chargingData[_index]->SystemStatus == S_CCS_PRECHARGE_ST0 &&
 							_chargingData[_index]->PrechargeStatus == PRECHARGE_READY)
 						{
-							SetEvsePrechargeInfo(_index, PRECHARGE_PRERELAY_PASS, _chargingData[_index]->Evboard_id);
+							SetEvsePrechargeInfo(_index, PRECHARGE_PRERELAY_PASS, targetID);
 						}
 					}
 				}
 					break;
 				case S_CHARGING:
 				{
-					// 計算 Power
+					// 當前 Power
 					_chargingData[_index]->PresentChargingPower = ((float)((_chargingData[_index]->PresentChargingVoltage) * (_chargingData[_index]->PresentChargingCurrent)) / 1000);
 
-					if (chargingTime[_index] == 0 ||
-							chargingTime[_index] > _chargingData[_index]->PresentChargedDuration)
-					{
-						chargingTime[_index] = _chargingData[_index]->PresentChargedDuration;
-					}
-					else
-					{
-						int passTime = _chargingData[_index]->PresentChargedDuration - chargingTime[_index];
-
-						if (passTime > 0)
-						{
-							float changingPow = (_chargingData[_index]->PresentChargingPower) * passTime / 3600;
-							if (ShmSysConfigAndInfo->SysConfig.BillingData.isBilling)
-							{
-								_chargingData[_index]->ChargingFee += changingPow * ShmSysConfigAndInfo->SysConfig.BillingData.Cur_fee;
-							}
-
-							_chargingData[_index]->PresentChargedEnergy += changingPow;
-							_chargingData[_index]->PowerConsumption += changingPow;
-							chargingTime[_index] = _chargingData[_index]->PresentChargedDuration;
-						}
-					}
+					CalOutputPowerAndEnergy(_index);
 
 					// 開始確認車端是否同意開始充電
-					GetOutputReq(_index, _chargingData[_index]->Evboard_id);
+					GetOutputReq(_index, targetID);
 
 					if (LogInfo[_index][EV_LOG_MAX_BATT_VOL] != _chargingData[_index]->EvBatteryMaxVoltage)
 					{
@@ -3776,11 +3897,11 @@ int main(int argc, char *argv[])
 
 					if(_chargingData[_index]->GroundFaultStatus == GFD_FAIL)
 					{
-						SetIsolationStatus(_index, _chargingData[_index]->GroundFaultStatus, _chargingData[_index]->Evboard_id);
+						SetIsolationStatus(_index, _chargingData[_index]->GroundFaultStatus, targetID);
 					}
 					else if(_chargingData[_index]->Type == _Type_CCS_2)
 					{
-						SetIsolationStatus(_index, _chargingData[_index]->GroundFaultStatus, _chargingData[_index]->Evboard_id);
+						SetIsolationStatus(_index, _chargingData[_index]->GroundFaultStatus, targetID);
 					}
 
 					// GFD 失敗再通知
@@ -3789,7 +3910,7 @@ int main(int argc, char *argv[])
 						if(_chargingData[_index]->Type == _Type_CCS_2 &&
 							_chargingData[_index]->PrechargeStatus == PRECHARGE_READY)
 						{
-							SetEvsePrechargeInfo(_index, PRECHARGE_CHARELAY_PASS, _chargingData[_index]->Evboard_id);
+							SetEvsePrechargeInfo(_index, PRECHARGE_CHARELAY_PASS, targetID);
 						}
 					}
 				}
@@ -3799,10 +3920,21 @@ int main(int argc, char *argv[])
 				{
 					// 設定當前輸出
 					if (gun_count == 1)
+					{
+						if (_chargingData[0]->FireChargingVoltage <= 500)
+							_chargingData[0]->PresentChargingCurrent = 0;
+
 						SetPresentChargingOutputPower(_chargingData[0], _chargingData[0]);
+					}
 					else if (gun_count == 2)
-						SetPresentChargingOutputPower(_chargingData[0], _chargingData[1]);
+					{
+						if (_chargingData[0]->FireChargingVoltage <= 500)
+							_chargingData[0]->PresentChargingCurrent = 0;
+						if (_chargingData[1]->FireChargingVoltage <= 500)
+							_chargingData[1]->PresentChargingCurrent = 0;
 
+						SetPresentChargingOutputPower(_chargingData[0], _chargingData[1]);
+					}
 					// 槍鎖還在,則代表是樁端要求的停止
 					if (SendErrorCount[_index] < 3 &&
 							(_chargingData[_index]->GunLocked == START ||
@@ -3816,16 +3948,16 @@ int main(int argc, char *argv[])
 							normalStop = 0x02;
 						}
 
-						EvseStopChargingEvent(normalStop, stopReason, _chargingData[_index]->Evboard_id);
+						EvseStopChargingEvent(normalStop, stopReason, targetID);
 						SendErrorCount[_index] += 1;
 					}
 
 					if(_chargingData[_index]->Type == _Type_CCS_2)
 					{
-						SetIsolationStatus(_index, _chargingData[_index]->GroundFaultStatus, _chargingData[_index]->Evboard_id);
+						SetIsolationStatus(_index, _chargingData[_index]->GroundFaultStatus, targetID);
 					}
 
-					GetOutputReq(_index, _chargingData[_index]->Evboard_id);
+					GetOutputReq(_index, targetID);
 
 					if (_chargingData[_index]->SystemStatus == S_ALARM)
 					{
@@ -3842,7 +3974,7 @@ int main(int argc, char *argv[])
 									_chargingData[_index]->AvailableChargingPower,
 									maxCur,
 									maxVol,
-									_chargingData[_index]->Evboard_id);
+									targetID);
 						}
 					}
 				}
@@ -3868,7 +4000,18 @@ int main(int argc, char *argv[])
 								_chargingData[_index]->AvailableChargingPower,
 								maxCur,
 								maxVol,
-								_chargingData[_index]->Evboard_id);
+								targetID);
+
+						if (_chargingData[_index]->EvBatterySoc >= 100)
+						{
+							//滿電,則直接清掉錯誤
+							if (_chargingData[_index]->Type == _Type_Chademo)
+								ClearAbnormalStatus_Chademo(_index);
+							else if (_chargingData[_index]->Type == _Type_GB)
+								ClearAbnormalStatus_GB(_index);
+							else if (_chargingData[_index]->Type == _Type_CCS_2)
+								ClearAbnormalStatus_CCS(_index);
+						}
 					}
 				}
 					break;

二进制
EVSE/Projects/DS60-120/Apps/Module_EventLogging


+ 8 - 4
EVSE/Projects/DS60-120/Apps/Module_EventLogging.c

@@ -73,10 +73,11 @@ int StoreLogMsg(const char *fmt, ...)
 	}
 	else
 	{
-		sprintf(Buf,"echo \"%04d-%02d-%02d %02d:%02d:%02d:%03d - %s\" >> /Storage/SystemLog/[%04d.%02d]SystemLog",
+		sprintf(Buf,"echo \"%04d-%02d-%02d %02d:%02d:%02d:%03d - %s\" >> /Storage/SystemLog/[%04d.%02d]SystemLog_%s",
 			tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,SeqEndTime.millitm,
 			buffer,
-			tm->tm_year+1900,tm->tm_mon+1);
+			tm->tm_year+1900,tm->tm_mon+1,
+			ShmSysConfigAndInfo->SysConfig.SerialNumber);
 		system(Buf);
 	}
 
@@ -379,6 +380,7 @@ int main(void)
 							DEBUG_INFO("Recovery Fault Code = %s\n", EventCodeTmp);
 							ShmStatusCodeData->FaultCode.PreviousFaultVal[ByteCount] &= ~(1<<BitCount);
 							RemoveFaultCodeToBuf(EventCodeTmp);
+							EventCodeTmp[0] = '1';
 						}
 						else
 						{
@@ -395,7 +397,7 @@ int main(void)
 		}
 
 		//check Alarm Status
-		for(ByteCount=0;ByteCount<13;ByteCount++)
+		for(ByteCount=0;ByteCount<14;ByteCount++)
 		{
 			if(ShmStatusCodeData->AlarmCode.AlarmEvents.AlarmVal[ByteCount] != ShmStatusCodeData->AlarmCode.PreviousAlarmVal[ByteCount])
 			{
@@ -405,13 +407,14 @@ int main(void)
 					if(((tmp>>BitCount)&0x01) != ((ShmStatusCodeData->AlarmCode.PreviousAlarmVal[ByteCount]>>BitCount)&0x01))
 					{
 						memset(EventCodeTmp,0,sizeof(EventCodeTmp));
-						memcpy(EventCodeTmp,AlarmStatusCode[ByteCount*8+BitCount],sizeof(EventCodeTmp)-1);
+						memcpy(EventCodeTmp, AlarmStatusCode[ByteCount*8+BitCount],sizeof(EventCodeTmp)-1);
 						if(((tmp>>BitCount)&0x01)==0)//Recovered
 						{
 							//EventCodeTmp[0]=1;
 							DEBUG_INFO("Recovery Alarm Code = %s\n", EventCodeTmp);
 							ShmStatusCodeData->AlarmCode.PreviousAlarmVal[ByteCount] &= ~(1<<BitCount);
 							RemoveFaultCodeToBuf(EventCodeTmp);
+							EventCodeTmp[0] = '1';
 						}
 						else
 						{
@@ -445,6 +448,7 @@ int main(void)
 							DEBUG_INFO("Recovery Info Code = %s\n", EventCodeTmp);
 							ShmStatusCodeData->InfoCode.PreviousInfoVal[ByteCount] &= ~(1<<BitCount);
 							RemoveFaultCodeToBuf(EventCodeTmp);
+							EventCodeTmp[0] = '1';
 						}
 						else
 						{

二进制
EVSE/Projects/DS60-120/Apps/Module_InternalComm


文件差异内容过多而无法显示
+ 851 - 715
EVSE/Projects/DS60-120/Apps/Module_InternalComm.c


二进制
EVSE/Projects/DS60-120/Apps/Module_LcmControl


+ 39 - 26
EVSE/Projects/DS60-120/Apps/Module_LcmControl.c

@@ -39,10 +39,11 @@ int StoreLogMsg(const char *fmt, ...)
 	}
 	else
 	{
-		sprintf(Buf,"echo \"%04d-%02d-%02d %02d:%02d:%02d:%03d - %s\" >> /Storage/SystemLog/[%04d.%02d]SystemLog",
+		sprintf(Buf,"echo \"%04d-%02d-%02d %02d:%02d:%02d:%03d - %s\" >> /Storage/SystemLog/[%04d.%02d]SystemLog_%s",
 			tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,SeqEndTime.millitm,
 			buffer,
-			tm->tm_year+1900,tm->tm_mon+1);
+			tm->tm_year+1900,tm->tm_mon+1,
+			ShmSysConfigAndInfo->SysConfig.SerialNumber);
 		system(Buf);
 	}
 
@@ -373,36 +374,38 @@ void ChangeWarningFunc()
 //================================================
 // QR Code process
 //================================================
-void ChangeQrCode_Idle(char *input)
+void ChangeQrCode_Idle(char *input, byte len)
 {
-	int len = strlen(input);
 	byte cmd[len];
-
 	int loop = 0;
-	int i = 0;
 
+	input[len] = '\0';
+	cmd[len] = '\0';
 	while(input[loop] != '\0')
 	{
-		cmd[i++] = input[loop++];
+		cmd[loop] = input[loop];
+		loop++;
 	}
 
-	DisplayValueToLcm(__qr_code, cmd, len);
+	//printf("cmd = %s, len = %d \n", cmd, len + 1);
+	DisplayValueToLcm(__qr_code, cmd, len + 1);
 }
 
-void ChangeQrCode_Charge(char *input)
+void ChangeQrCode_Charge(char *input, byte len)
 {
-	int len = strlen(input);
 	byte cmd[len];
-
 	int loop = 0;
-	int i = 0;
 
+	input[len] = '\0';
+	cmd[len] = '\0';
 	while(input[loop] != '\0')
 	{
-		cmd[i++] = input[loop++];
+		cmd[loop] = input[loop];
+		loop++;
 	}
 
-	DisplayValueToLcm(__qr_code_pre, cmd, len);
+	//printf("2 - cmd = %s, len = %d \n", cmd, len + 1);
+	DisplayValueToLcm(__qr_code_pre, cmd, len + 1);
 }
 
 //================================================
@@ -1061,7 +1064,16 @@ void ProcessPageInfo()
 				if (ShmSysConfigAndInfo->SysConfig.isQRCode)
 				{
 					needReloadQr = false;
-					ChangeQrCode_Idle((char *)ShmSysConfigAndInfo->SysConfig.SystemId);
+					if (ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode == NO)
+					{
+						byte len = strlen((char *)ShmSysConfigAndInfo->SysConfig.SystemId);
+						ChangeQrCode_Idle((char *)ShmSysConfigAndInfo->SysConfig.SystemId, len);
+					}
+					else
+					{
+						byte len = strlen((char *)ShmSysConfigAndInfo->SysConfig.QRCodeContent);
+						ChangeQrCode_Idle((char *)ShmSysConfigAndInfo->SysConfig.QRCodeContent, len);
+					}
 				}
 			}
 		}
@@ -1378,7 +1390,16 @@ void ProcessPageInfo()
 						if (ShmSysConfigAndInfo->SysConfig.isQRCode)
 						{
 							needReloadQr = false;
-							ChangeQrCode_Charge((char *)ShmSysConfigAndInfo->SysConfig.SystemId);
+							if (ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode == NO)
+							{
+								byte len = strlen((char *)ShmSysConfigAndInfo->SysConfig.SystemId);
+								ChangeQrCode_Charge((char *)ShmSysConfigAndInfo->SysConfig.SystemId, len);
+							}
+							else
+							{
+								byte len = strlen((char *)ShmSysConfigAndInfo->SysConfig.QRCodeContent);
+								ChangeQrCode_Charge((char *)ShmSysConfigAndInfo->SysConfig.QRCodeContent, len);
+							}
 						}
 					}
 				}
@@ -1498,16 +1519,8 @@ int main(void)
 	Initialization();
 
 //	ChangeToOtherPage(_LCM_IDLE);
-//	ChangeDisplay2Value(__conn_status, _connect);
-//	ChangeDisplay2Value(__ethernet_status, _eth_connect);
-//	ChangeDisplay2Value(__wifi_status, _wifi_connect);
-//	ChangeDisplay2Value(__3G4G_status, _3G4G_connect);
-//
-//	ChangeDisplay2Value(__conn_status, _disconnect);
-//	ChangeDisplay2Value(__ethernet_status, _eth_disconnect);
-//	ChangeDisplay2Value(__wifi_status, _wifi_disconnect);
-//	ChangeDisplay2Value(__3G4G_status, _3G4G_disconnect);
-//	return 0;
+
+//	return -1;
 	DefaultIconStatus();
 
 	while(_port != -1)

二进制
EVSE/Projects/DS60-120/Apps/Module_PrimaryComm


+ 140 - 3
EVSE/Projects/DS60-120/Apps/Module_PrimaryComm.c

@@ -42,6 +42,7 @@ typedef unsigned char 		byte;
 struct SysConfigAndInfo			*ShmSysConfigAndInfo;
 struct StatusCodeData 			*ShmStatusCodeData;
 struct PrimaryMcuData			*ShmPrimaryMcuData;
+struct MeterInformation			*ShmCsuMeterData;
 
 void trim(char *s);
 int mystrcmp(char *p1,char *p2);
@@ -57,9 +58,13 @@ Rtc rtc;
 struct timeval _flash_time;
 byte flash = NO;
 
+byte gun_count;
+
 byte _curDeviceStatus[3] = {0, 0, 0};
 byte _reCheckCount[3] = {0, 0, 0};
 
+struct ChargingInfoData *_chargingData[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
+
 void PRINTF_FUNC(char *string, ...);
 
 int StoreLogMsg(const char *fmt, ...);
@@ -92,10 +97,11 @@ int StoreLogMsg(const char *fmt, ...)
 	}
 	else
 	{
-		sprintf(Buf,"echo \"%04d-%02d-%02d %02d:%02d:%02d:%03d - %s\" >> /Storage/SystemLog/[%04d.%02d]SystemLog",
+		sprintf(Buf,"echo \"%04d-%02d-%02d %02d:%02d:%02d:%03d - %s\" >> /Storage/SystemLog/[%04d.%02d]SystemLog_%s",
 			tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,SeqEndTime.millitm,
 			buffer,
-			tm->tm_year+1900,tm->tm_mon+1);
+			tm->tm_year+1900,tm->tm_mon+1,
+			ShmSysConfigAndInfo->SysConfig.SerialNumber);
 		system(Buf);
 	}
 
@@ -245,6 +251,21 @@ int InitShareMemory()
 		result = FAIL;
 	}
 
+	if ((MeterSMId = shmget(ShmCsuMeterKey, sizeof(struct MeterInformation), IPC_CREAT | 0777)) < 0)
+   	{
+   		#ifdef SystemLogMessage
+   		DEBUG_ERROR("shmget ShmCsuMeterKey NG \n");
+   		#endif
+   		return 0;
+   	}
+   	else if ((ShmCsuMeterData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
+   	{
+   		#ifdef SystemLogMessage
+   		DEBUG_ERROR("shmat ShmCsuMeterData NG \n");
+   		#endif
+   		return 0;
+   	}
+
     return result;
 }
 
@@ -313,6 +334,54 @@ void GetInputGpioStatus()
 	}
 }
 
+void GetMeterConsumption(byte index)
+{
+	if (Query_Meter_value(Uart1Fd, Addr.IoExtend, &ShmCsuMeterData->_meter[index], &ShmCsuMeterData->isWorking, index) == PASS)
+	{
+		if (!ShmCsuMeterData->isWorking)
+		{
+			//ShmStatusCodeData->AlarmCode.AlarmEvents.bits.MeterCommTimeout = YES;
+			return;
+		}
+
+		if (ShmCsuMeterData->_meter[index].isCalculation == YES)
+		{
+//			printf("Meter%d, Comsumption = %.1f, curMeterValue = %.1f \n",
+//					index,
+//					ShmCsuMeterData->_meter[index].newMeterValue,
+//					ShmCsuMeterData->_meter[index].curMeterValue);
+
+			if (ShmCsuMeterData->_meter[index].curMeterValue == 0)
+				ShmCsuMeterData->_meter[index].curMeterValue = ShmCsuMeterData->_meter[index].newMeterValue;
+			else
+			{
+				// 最大充時,兩個都會累加,但只輸出給一槍使用
+				ShmCsuMeterData->_meter[index]._chargingValue += ShmCsuMeterData->_meter[index].newMeterValue - ShmCsuMeterData->_meter[index].curMeterValue;
+
+				if (ShmSysConfigAndInfo->SysInfo.MainChargingMode == _MAIN_CHARGING_MODE_MAX ||
+					(ShmSysConfigAndInfo->SysInfo.MainChargingMode == _MAIN_CHARGING_MODE_AVER &&
+					ShmSysConfigAndInfo->SysInfo.ReAssignedFlag >= _REASSIGNED_RELAY_A_TO_M))
+				{
+					for (byte subIndex = 0; subIndex < gun_count; subIndex++)
+					{
+						if (_chargingData[subIndex]->SystemStatus == S_CHARGING)
+						{
+							ShmCsuMeterData->_meter[subIndex]._curTotalCharging += ShmCsuMeterData->_meter[index].newMeterValue - ShmCsuMeterData->_meter[index].curMeterValue;
+							break;
+						}
+					}
+				}
+				else
+				{
+					ShmCsuMeterData->_meter[index]._curTotalCharging += ShmCsuMeterData->_meter[index].newMeterValue - ShmCsuMeterData->_meter[index].curMeterValue;
+				}
+
+				ShmCsuMeterData->_meter[index].curMeterValue = ShmCsuMeterData->_meter[index].newMeterValue;
+			}
+		}
+	}
+}
+
 void SetOutputGpio(byte flash)
 {
 	Gpio_out gpio;
@@ -422,6 +491,62 @@ unsigned long GetTimeoutValue(struct timeval _sour_time)
 	return 1000000 * (_end_time.tv_sec - _sour_time.tv_sec) + _end_time.tv_usec - _sour_time.tv_usec;
 }
 
+//================================================
+//================================================
+// CANBUS receive task
+//================================================
+//================================================
+bool FindChargingInfoData(byte target, struct ChargingInfoData **chargingData)
+{
+	for (byte index = 0; index < CHAdeMO_QUANTITY; index++)
+	{
+		if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == target)
+		{
+			chargingData[target] = &ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index];
+			return true;
+		}
+	}
+
+	for (byte index = 0; index < CCS_QUANTITY; index++)
+	{
+		if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == target)
+		{
+			chargingData[target] = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[index];
+			return true;
+		}
+	}
+
+	for (byte index = 0; index < GB_QUANTITY; index++)
+	{
+		if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == target)
+		{
+			chargingData[target] = &ShmSysConfigAndInfo->SysInfo.GbChargingData[index];
+			return true;
+		}
+	}
+
+	return false;
+}
+
+void Initialization()
+{
+	bool isPass = false;
+	while(!isPass)
+	{
+		isPass = true;
+		for (byte _index = 0; _index < gun_count; _index++)
+		{
+			if (!FindChargingInfoData(_index, &_chargingData[0]))
+			{
+				DEBUG_ERROR("EvComm (main) : FindChargingInfoData false \n");
+				isPass = false;
+				break;
+			}
+		}
+		sleep(1);
+	}
+}
+
 int main(void)
 {
 	if(InitShareMemory() == FAIL)
@@ -453,8 +578,12 @@ int main(void)
 	}
 
 	SetRtcData();
-	//SetModelName();
+	SetModelName();
 	gettimeofday(&_flash_time, NULL);
+	gun_count = ShmSysConfigAndInfo->SysConfig.TotalConnectorCount;
+	Initialization();
+	byte _count = 0;
+
 	for(;;)
 	{
 		if (strcmp((char *)ShmSysConfigAndInfo->SysInfo.LcmHwRev, " ") == 0x00)
@@ -493,6 +622,14 @@ int main(void)
 		else
 		{
 			GetInputGpioStatus();
+
+			if(ShmSysConfigAndInfo->SysConfig.ModelName[3] == 'M')
+			{
+				GetMeterConsumption(_count);
+				_count++;
+				if (_count >= gun_count)
+					_count = 0;
+			}
 		}
 
 		usleep(100000);

二进制
EVSE/Projects/DS60-120/Apps/Module_PsuComm


+ 98 - 32
EVSE/Projects/DS60-120/Apps/Module_PsuComm.c

@@ -34,6 +34,8 @@ byte getAvailableCapOffset = 5;
 byte deratingKeepCount = 0;
 byte psuCmdSeq = _PSU_CMD_CAP;
 
+byte startModuleFlag = false;
+
 float chargingOutputLogInfo[2][4];
 
 void PRINTF_FUNC(char *string, ...);
@@ -78,10 +80,11 @@ int StoreLogMsg(const char *fmt, ...)
 	}
 	else
 	{
-		sprintf(Buf,"echo \"%04d-%02d-%02d %02d:%02d:%02d:%03d - %s\" >> /Storage/SystemLog/[%04d.%02d]SystemLog",
+		sprintf(Buf,"echo \"%04d-%02d-%02d %02d:%02d:%02d:%03d - %s\" >> /Storage/SystemLog/[%04d.%02d]SystemLog_%s",
 			tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,SeqEndTime.millitm,
 			buffer,
-			tm->tm_year+1900,tm->tm_mon+1);
+			tm->tm_year+1900,tm->tm_mon+1,
+			ShmSysConfigAndInfo->SysConfig.SerialNumber);
 		system(Buf);
 	}
 
@@ -192,7 +195,7 @@ void AbnormalStopAnalysis(byte gun_index, int errCode)
 		{
 			if(DetectBitValue(byteIndex , bitIndex) == 1)
 			{
-				switch(byteIndex)
+				switch(i)
 				{
 					case 0:
 					{
@@ -340,10 +343,37 @@ void GetStatusCallback(byte group, byte SN, byte temp, int alarm)
 		}
 
 		for(byte psuIndex = 0; psuIndex < conn_1_count; psuIndex++)
-			PRINTF_FUNC("Connector 1 - PSU Number = %d \n", connector_1[psuIndex]);
+			PRINTF_FUNC("DC Left Gun - PSU Number = %d \n", connector_1[psuIndex]);
 
 		for(byte psuIndex = 0; psuIndex < conn_2_count; psuIndex++)
-			PRINTF_FUNC("Connector 2 - PSU Number = %d \n", connector_2[psuIndex]);
+			PRINTF_FUNC("DC Right Gun - PSU Number = %d \n", connector_2[psuIndex]);
+
+		if (ShmSysConfigAndInfo->SysConfig.TotalConnectorCount > 1)
+		{
+			// 雙槍才需要考慮是否模塊 switch 撥錯了
+			char EvsePower[2];
+			byte maxCount = 0;
+			int power = 0;
+
+			EvsePower[2] = '\0';
+			if (strlen((char *) ShmSysConfigAndInfo->SysConfig.ModelName) >= 6)
+			{
+				strncpy(EvsePower, (char *)(ShmSysConfigAndInfo->SysConfig.ModelName + 4), 2);
+				power = atoi(EvsePower);
+			}
+
+			// 超過 90 KW 或 360 KW
+			if (power < 30 || power == 36)
+				power *= 10;
+
+			maxCount = ((power / 30) + 1) / 2;
+
+			if (conn_1_count > maxCount ||
+					conn_2_count > maxCount)
+			{
+				ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PsuDipSwitchStestFail = YES;
+			}
+		}
 	}
 }
 // no using -- GetOutputAndTempCallback End
@@ -1063,7 +1093,7 @@ void GetModuleStatusCallback(byte address, unsigned char isErr, unsigned char st
 	int alarm = (err2 << 24) | (err3 << 16) | (err4 << 8);
 
 	ShmPsuData->PsuGroup[group1].PsuModule[address].AlarmCode = alarm;
-	AbnormalStopAnalysis(group1, alarm);
+	//AbnormalStopAnalysis(group1, alarm);
 }
 
 void GetModuleInputCallback(byte address, unsigned short inputR,
@@ -1087,6 +1117,7 @@ void GetModuleInputCallback(byte address, unsigned short inputR,
 	//PRINTF_FUNC("***Input*** address = %d, R = %d, S = %d, T = %d \n",
 	//		address, inputR, inputS, inputT);
 }
+
 //==========================================
 // Init all share memory
 //==========================================
@@ -1146,7 +1177,6 @@ int InitShareMemory()
 		#endif
 		result = FAIL;
 	 }
-	memset(ShmPsuData,0,sizeof(struct PsuData));
 
     return result;
 }
@@ -1251,7 +1281,7 @@ void CheckSmartChargingStep(bool isWaitingAver, bool isCharging, bool canAverage
 			}
 			else
 			{
-				PRINTF_FUNC("=============Smart Charging : _REASSIGNED_NONE============= Step 0 \n");
+				PRINTF_FUNC("=============Smart Charging Aver mode : _REASSIGNED_NONE============= Step 0 \n");
 				ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_NONE;
 			}
 		}
@@ -1304,8 +1334,9 @@ void PreCheckSmartChargingStep()
 				if (toAverVolPoint == (chargingInfo[index]->EvBatterytargetCurrent * 10))
 				{
 					// 欲最大充 -> 均充需要等待充電中的輸出電流拉高到目標電流
-					if ((chargingInfo[index]->PresentChargingCurrent * 10) >=
-							(chargingInfo[index]->EvBatterytargetCurrent * 10) - CHK_CUR_RANGE)
+//					chargingInfo[index]->PresentChargingCurrent = 60;
+//					if ((chargingInfo[index]->PresentChargingCurrent * 10) >=
+//							(chargingInfo[index]->EvBatterytargetCurrent * 10) - CHK_CUR_RANGE)
 					{
 						if (toAverVolCount == 0)
 							isWaitingAver = true;
@@ -1325,6 +1356,14 @@ void PreCheckSmartChargingStep()
 				toAverVolCount = 3;
 			}
 		}
+		else if (chargingInfo[index]->SystemStatus == S_COMPLETE ||
+				chargingInfo[index]->SystemStatus == S_ALARM)
+		{
+			if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag == _REASSIGNED_PREPARE_M_TO_A)
+			{
+				ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_RELAY_M_TO_A;
+			}
+		}
 
 		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))
@@ -1332,10 +1371,11 @@ void PreCheckSmartChargingStep()
 			isReadToCharging = true;
 		}
 
-		if (chargingInfo[index]->DeratingChargingCurrent < STOP_CURRENT)
-		{
-			CanAverageCharging = false;
-		}
+		// 不可用 : 因為電壓拔升過程~ 也是 < STOP_CURRENT
+//		if (chargingInfo[index]->DeratingChargingCurrent < STOP_CURRENT)
+//		{
+//			CanAverageCharging = false;
+//		}
 	}
 
 	CheckSmartChargingStep(isWaitingAver, isCharging, CanAverageCharging);
@@ -1563,6 +1603,7 @@ int main(void)
 				if (time > 1500)
 				{
 					PreCheckSmartChargingStep();
+					startModuleFlag = true;
 					gettimeofday(&_cmdSubPriority_time, NULL);
 				}
 
@@ -1641,7 +1682,7 @@ int main(void)
 
 							if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag == _REASSIGNED_GET_NEW_CAP)
 							{
-								if (ShmPsuData->SystemAvailableCurrent != chargingInfo[groupIndex]->AvailableChargingCurrent)
+								//if (ShmPsuData->SystemAvailableCurrent != chargingInfo[groupIndex]->AvailableChargingCurrent)
 								{
 									// 車端要求電流為該充電槍的額定輸出電流的範圍內
 									if ((chargingInfo[groupIndex]->EvBatterytargetCurrent * 10) <= ShmPsuData->PsuGroup[groupIndex].GroupPresentOutputCurrent + DERATING_GAP ||
@@ -1669,13 +1710,14 @@ int main(void)
 							{
 								bool isChanged = false;
 
+								PRINTF_FUNC("Max To Ava mode (3-1) : Gun_%d, PresentChargingCurrent = %f, AvailableChargingCurrent = %f, EvBatterytargetCurrent = %f, GroupPresentOutputCurrent = %d \n", groupIndex,
+									(chargingInfo[groupIndex]->PresentChargingCurrent * 10),
+									chargingInfo[groupIndex]->AvailableChargingCurrent,
+									(chargingInfo[groupIndex]->EvBatterytargetCurrent * 10),
+									ShmPsuData->PsuGroup[groupIndex].GroupPresentOutputCurrent);
+
 								if (chargingInfo[groupIndex]->AvailableChargingCurrent <= (chargingInfo[groupIndex]->EvBatterytargetCurrent * 10))
 								{
-									PRINTF_FUNC("Max To Ava mode (3-1) : Gun_%d, PresentChargingCurrent = %f, AvailableChargingCurrent = %f, EvBatterytargetCurrent = %f \n", groupIndex,
-										(chargingInfo[groupIndex]->PresentChargingCurrent * 10),
-										chargingInfo[groupIndex]->AvailableChargingCurrent,
-										(chargingInfo[groupIndex]->EvBatterytargetCurrent * 10));
-
 									for (byte subIndex = 0; subIndex < ShmPsuData->GroupCount; subIndex++)
 									{
 										if (chargingInfo[subIndex]->SystemStatus == S_REASSIGN)
@@ -1687,8 +1729,9 @@ int main(void)
 										}
 									}
 								}
-								else if (((chargingInfo[groupIndex]->PresentChargingCurrent * 10) >= ShmPsuData->PsuGroup[groupIndex].GroupPresentOutputCurrent - CHK_CUR_RANGE) &&
-									((chargingInfo[groupIndex]->PresentChargingCurrent * 10) <= ShmPsuData->PsuGroup[groupIndex].GroupPresentOutputCurrent + CHK_CUR_RANGE))
+//								else if (((chargingInfo[groupIndex]->PresentChargingCurrent * 10) >= ShmPsuData->PsuGroup[groupIndex].GroupPresentOutputCurrent - CHK_CUR_RANGE) &&
+//									((chargingInfo[groupIndex]->PresentChargingCurrent * 10) <= ShmPsuData->PsuGroup[groupIndex].GroupPresentOutputCurrent + CHK_CUR_RANGE))
+								else if (chargingInfo[groupIndex]->PresentChargingCurrent == 0)
 								{
 									for (byte subIndex = 0; subIndex < ShmPsuData->GroupCount; subIndex++)
 									{
@@ -1742,7 +1785,7 @@ int main(void)
 
 									if (reassignIndex != ELEMENT_NOT_FIND)
 									{
-										if ((GetTimeoutValue(_derating_time) / 1000) <= 50 ||
+										if ((GetTimeoutValue(_derating_time) / 1000) <= 150 ||
 											chargingInfo[groupIndex]->MaxChargingToAverPassFlag == 0)
 										{
 											chargingInfo[groupIndex]->MaxChargingToAverPassFlag = 1;
@@ -1823,7 +1866,7 @@ int main(void)
 										isStartOutputSwitch[index] = true;
 									}
 
-									if (isNeedToOpenPower)
+									if (isNeedToOpenPower || startModuleFlag)
 									{
 										SwitchPower(SYSTEM_CMD, PSU_POWER_ON);
 										FlashLed(SYSTEM_CMD, PSU_FLASH_ON);
@@ -1833,6 +1876,8 @@ int main(void)
 						}
 						else if (ShmSysConfigAndInfo->SysInfo.MainChargingMode == _MAIN_CHARGING_MODE_AVER)
 						{
+							bool abnormalOutput = false;
+
 							// 智能判斷 Start -----------------------------------------------------------
 							if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag == _REASSIGNED_ADJUST_A_TO_M)
 							{
@@ -1841,6 +1886,7 @@ int main(void)
 								for (byte subIndex = 0; subIndex < ShmPsuData->GroupCount; subIndex++)
 								{
 									if (chargingInfo[subIndex]->SystemStatus == S_IDLE ||
+											chargingInfo[subIndex]->SystemStatus == S_FAULT ||
 											chargingInfo[subIndex]->SystemStatus == S_RESERVATION)
 									{
 										// 各群電壓接近平衡
@@ -1875,17 +1921,26 @@ int main(void)
 							{
 								int idleCurrent = 0;
 								int chargingCurrent = 0;
+								float outCurrent = 0;
 
 								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)
 										idleCurrent = ShmPsuData->PsuGroup[subIndex].GroupPresentOutputCurrent;
 									else
+									{
 										chargingCurrent = ShmPsuData->PsuGroup[subIndex].GroupPresentOutputCurrent;
+										outCurrent = chargingInfo[groupIndex]->EvBatterytargetVoltage * 10;
+									}
 								}
 
+								// 電樁輸出電流不足狀態
+								if (chargingCurrent + idleCurrent <= outCurrent - PRE_CHARG_RANGE)
+									abnormalOutput = true;
+
 								if (idleCurrent >= chargingCurrent - PRE_CHARG_RANGE)
 								{
 									PRINTF_FUNC("======= The Change to maximum charge mode is complete. (Step 15) ======= \n");
@@ -1893,7 +1948,7 @@ int main(void)
 								}
 								else
 								{
-									if ((GetTimeoutValue(_max_time) / 1000) > 500)
+									if ((GetTimeoutValue(_max_time) / 1000) > 300)
 									{
 										gettimeofday(&_max_time, NULL);
 									}
@@ -1910,6 +1965,7 @@ int main(void)
 									{
 										if (chargingInfo[subIndex]->SystemStatus == S_IDLE ||
 												chargingInfo[subIndex]->SystemStatus == S_RESERVATION ||
+												chargingInfo[subIndex]->SystemStatus == S_FAULT ||
 												chargingInfo[subIndex]->SystemStatus == S_REASSIGN_CHECK)
 										{
 											reassignIndex = subIndex;
@@ -1934,19 +1990,28 @@ int main(void)
 
 									if (reassignIndex != ELEMENT_NOT_FIND)
 									{
-										if ((GetTimeoutValue(_max_time) / 1000) <= 50)
+										if ((GetTimeoutValue(_max_time) / 1000) <= 150)
 										{
 											//PRINTF_FUNC("set out (%d) value = %d******** 5 \n", reassignIndex, ZERO_CURRENT + preChargingTarget);
 											// 閒置模塊升壓,另對剛分配近來的模塊,預上升電流值 (preChargingCur)
 											PresentOutputVol(reassignIndex,
 												(chargingInfo[groupIndex]->EvBatterytargetVoltage * 10),
 												ZERO_CURRENT + preChargingTarget); Await();
+										}
 
-											byte _ovCahrgingCur = 0;
-											if (preChargingCur > PRE_CHARG_STEP_CUR)
-												_ovCahrgingCur = PRE_CHARG_STEP_CUR;
-
-											//PRINTF_FUNC("set out (%d) value = %f******** 6 \n", groupIndex, chargingInfo[groupIndex]->EvBatterytargetCurrent - preChargingCur - _ovCahrgingCur);
+										byte _ovCahrgingCur = 0;
+										if (preChargingCur > PRE_CHARG_STEP_CUR)
+											_ovCahrgingCur = PRE_CHARG_STEP_CUR;
+
+//										if (abnormalOutput)
+//										{
+//											PRINTF_FUNC("set out (%d) value = %f******** 6 \n", groupIndex, chargingInfo[groupIndex]->EvBatterytargetCurrent - preChargingCur - _ovCahrgingCur);
+//											PresentOutputVol(groupIndex,
+//												(chargingInfo[groupIndex]->EvBatterytargetVoltage * 10),
+//												ShmPsuData->PsuGroup[groupIndex].GroupPresentOutputCurrent - preChargingCur - _ovCahrgingCur); Await();
+//										}
+//										else
+										{
 											PresentOutputVol(groupIndex,
 												(chargingInfo[groupIndex]->EvBatterytargetVoltage * 10),
 												(chargingInfo[groupIndex]->EvBatterytargetCurrent * 10) - preChargingCur - _ovCahrgingCur); Await();
@@ -2011,7 +2076,7 @@ int main(void)
 									}
 									else
 									{
-										if (!isStartOutputSwitch[groupIndex])
+										if (!isStartOutputSwitch[groupIndex] || startModuleFlag)
 										{
 											isStartOutputSwitch[groupIndex] = true;
 											SwitchPower(groupIndex, PSU_POWER_ON); Await();
@@ -2116,6 +2181,7 @@ int main(void)
 					}
 				}
 
+				startModuleFlag = false;
 				break;
 			}
 			case _TEST_MODE:

+ 35 - 1
EVSE/Projects/DS60-120/Apps/PrimaryComm.c

@@ -33,7 +33,7 @@
 #define FAIL				-1
 
 struct Address Addr={0x01,0x02,0x03,0x04,0xFF};
-struct Command Cmd={0x01,0x02,0x0a,0x83,0x86,0x87,0xe0,0xe1,0xe2,0xe3};
+struct Command Cmd={0x01,0x02,0x0a,0x2C,0x83,0x86,0x87,0xe0,0xe1,0xe2,0xe3};
 
 int tranceive(int fd, unsigned char* cmd, unsigned char cmd_len, unsigned char* rx)
 {
@@ -156,6 +156,40 @@ unsigned char Query_Gpio_Input(unsigned char fd, unsigned char targetAddr, Gpio_
 	return result;
 }
 
+unsigned char Query_Meter_value(unsigned char fd, unsigned char targetAddr, struct StructMeter *Ret_Buf, byte *isWork, unsigned char index)
+{
+	unsigned char result = FAIL;
+	unsigned char tx[8] = {0xaa, 0x00, targetAddr, Cmd.query_charging_power, 0x01, 0x00, index, 0x00};
+	unsigned char rx[512];
+	unsigned char chksum = 0x00;
+
+	for (int idx = 0; idx < (tx[4] | tx[5] << 8); idx++)
+			chksum ^= tx[6 + idx];
+	tx[7] = chksum;
+
+	unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
+	if(len > 0)
+	{
+		chksum = 0x00;
+		for (int idx = 0; idx < (rx[4] | rx[5] << 8); idx++)
+		{
+			chksum ^= rx[6+idx];
+		}
+
+		if((chksum == rx[6+(rx[4] | rx[5]<<8)]) &&
+		   (rx[2] == tx[1]) &&
+		   (rx[1] == tx[2]) &&
+		   (rx[3] == tx[3]))
+		{
+			Ret_Buf->newMeterValue = (rx[6] | (rx[7]<<8) | (rx[8]<<8) | (rx[9]<<8));
+			*isWork = rx[23];
+			result = PASS;
+		}
+	}
+
+	return result;
+}
+
 unsigned char Config_Gpio_Output(unsigned char fd, unsigned char targetAddr, Gpio_out *Set_Buf)
 {
 	unsigned char result = FAIL;

+ 3 - 0
EVSE/Projects/DS60-120/Apps/PrimaryComm.h

@@ -16,6 +16,8 @@ extern struct Command
 	unsigned char query_HW_Ver;		//0x02
 	unsigned char query_Gpio_In;		//0x0a
 
+	unsigned char query_charging_power;	// 0x2C
+
 	unsigned char config_Model_Name;			//0x83
 	unsigned char config_Gpio_Output;	//0x86
 	unsigned char config_Rtc_Data;		//0x87
@@ -64,6 +66,7 @@ typedef struct RTC
 extern unsigned char Query_FW_Ver(unsigned char fd, unsigned char targetAddr, Ver *Ret_Buf);
 extern unsigned char Query_HW_Ver(unsigned char fd, unsigned char targetAddr, Ver *Ret_Buf);
 extern unsigned char Query_Gpio_Input(unsigned char fd, unsigned char targetAddr, Gpio_in *Ret_Buf);
+extern unsigned char Query_Meter_value(unsigned char fd, unsigned char targetAddr, struct StructMeter *Ret_Buf, byte *isWork, unsigned char index);
 
 extern unsigned char Config_Gpio_Output(unsigned char fd, unsigned char targetAddr, Gpio_out *Set_Buf);
 extern unsigned char Config_Rtc_Data(unsigned char fd, unsigned char targetAddr, Rtc *Set_Buf);

二进制
EVSE/Projects/DS60-120/Apps/ReadCmdline


+ 20 - 2
EVSE/Projects/DS60-120/Apps/ReadCmdline.c

@@ -71,6 +71,7 @@ struct FanModuleData			*ShmFanModuleData;
 struct RelayModuleData			*ShmRelayModuleData;
 struct LedModuleData			*ShmLedModuleData;
 struct PsuData 					*ShmPsuData;
+struct DcCommonInformation		*ShmDcCommonData;
 
 struct ChargingInfoData 		*_chargingData[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
 struct ChargingInfoData 		*ac_chargingInfo[AC_QUANTITY];
@@ -231,6 +232,15 @@ int InitShareMemory()
    		result = FAIL;
    	}
 
+   	if ((MeterSMId = shmget(ShmCommonKey, sizeof(struct DcCommonInformation), IPC_CREAT | 0777)) < 0)
+   	{
+   		result = FAIL;
+   	}
+   	else if ((ShmDcCommonData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
+   	{
+   		result = FAIL;
+   	}
+
     return result;
 }
 
@@ -271,6 +281,8 @@ void RunStatusProc(char *v1, char *v2)
 			printf ("index = %x, status = %x (%d)\n", _index, _chargingData[_index]->SystemStatus, _chargingData[_index]->IsAvailable);
 			printf ("SystemTimeoutFlag = %d, PageIndex = %d\n",
 					ShmSysConfigAndInfo->SysInfo.SystemTimeoutFlag, ShmSysConfigAndInfo->SysInfo.PageIndex);
+			printf ("SOC = %d \n", _chargingData[_index]->EvBatterySoc);
+			printf("Charging mode = %d \n", ShmSysConfigAndInfo->SysInfo.MainChargingMode);
 		}
 		else
 		{
@@ -435,7 +447,7 @@ void CreateOneError(char *v1)
 {
 	int value = atoi(v1);
 
-	ShmStatusCodeData->FaultCode.FaultEvents.bits.ChademoOutputRelayWelding = value;
+	ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsConnectorOTP = value;
 	//ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputOVP = value;
 	//ShmSysConfigAndInfo->SysConfig.BillingData.isBilling = value;
 }
@@ -1147,13 +1159,15 @@ int main(void)
 			}
 		}
 
-		if(strcmp(newString[0], "state") == 0)
+		if(strcmp(newString[0], "state") == 0 || strcmp(newString[0], "st") == 0)
 		{
 			if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
 				continue;
 
 			// ºjª¬ºA
+			printf("=========================== \n");
 			RunStatusProc(newString[1], newString[2]);
+			printf("=========================== \n");
 		}
 		else if(strcmp(newString[0], "card") == 0)
 		{
@@ -1308,6 +1322,10 @@ int main(void)
 				printf ("FindChargingInfoData error\n");
 				continue;
 			}
+			printf("FirmwareUpdate = %d \n", ShmSysConfigAndInfo->SysInfo.FirmwareUpdate);
+			printf("ShmSysConfigAndInfo->SysInfo.WaitForPlugit = %d \n", ShmSysConfigAndInfo->SysInfo.WaitForPlugit);
+			printf("ShmSysConfigAndInfo->SysConfig.UserId = %s \n", ShmSysConfigAndInfo->SysConfig.UserId);
+			printf("ShmSysConfigAndInfo->SysInfo.AuthorizeFlag = %d \n", ShmSysConfigAndInfo->SysInfo.AuthorizeFlag);
 		}
 		else if(strcmp(newString[0], "strchg") == 0)
 		{

二进制
EVSE/Projects/DS60-120/Apps/UnsafetyOutputTask


二进制
EVSE/Projects/DS60-120/Apps/main


文件差异内容过多而无法显示
+ 466 - 173
EVSE/Projects/DS60-120/Apps/main.c


二进制
EVSE/Projects/DS60-120/Images/FactoryDefaultConfig.bin


二进制
EVSE/Projects/DS60-120/Images/ramdisk.gz


+ 193 - 3
EVSE/Projects/Noodoe/Apps/main.c

@@ -52,6 +52,8 @@ int GetCardSerialNumber();
 void setLedMotion(unsigned char gun_index,unsigned char led_mode);
 void setRelay(unsigned char gun_index,unsigned char isOn);
 void setSpeaker(unsigned char isOn, unsigned char speaker_mode);
+void setLightIntensity(unsigned char gun_index);
+void initialLightIntensity(unsigned char gun_index);
 
 //==========================
 // Declare RFID module type
@@ -941,6 +943,8 @@ void InitEthernet()
 	sprintf(tmpbuf,"/sbin/ifconfig eth0 %s netmask %s up &",
 	ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthIpAddress,
 	ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthSubmaskAddress);
+	DEBUG_INFO("eth0 config as ip: %s, netmask: %s\n", ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthIpAddress,
+													   ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthSubmaskAddress);
 	system(tmpbuf);
 	memset(tmpbuf,0,256);
 	sprintf(tmpbuf,"route add default gw %s eth0 &",
@@ -948,6 +952,7 @@ void InitEthernet()
 	system(tmpbuf);
 	system("/sbin/ifconfig eth0:1 192.168.201.201 netmask 255.255.255.248 up &");
 	system("ifconfig lo up &");
+	system("/sbin/ethtool -s eth0 speed 10 duplex full autoneg off");
 
 	if(isInterfaceUp("eth1")==PASS)
 	{
@@ -1270,7 +1275,7 @@ void get_firmware_version(unsigned char gun_index)
 	strcpy((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev, ShmCharger->gun_info[gun_index].ver.Version_FW);
 
 	// Get CSU root file system version
-	sprintf((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev, "V0.47.00.0000.00");
+	sprintf((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev, "V0.49.00.0000.00");
 
 	// Get AC connector type from model name
 	for(uint8_t idx=0;idx<3;idx++)
@@ -1728,9 +1733,9 @@ int isReachableInternet()
 	char buf[512];
 	char tmp[512];
 	
+	// Get ip address & net mask
 	strcpy(cmd, "ifconfig eth0");
 	fp = popen(cmd, "r");
-
 	if(fp != NULL)
 	{
 		while(fgets(buf, sizeof(buf), fp) != NULL)
@@ -1739,16 +1744,43 @@ int isReachableInternet()
 			{
 				sscanf(buf, "%*s%s", tmp);
 				substr(tmp, tmp, strspn(tmp, "addr:"), strlen(buf)-strspn(tmp, "addr:"));
-
 				if (strcmp(tmp, (char *)ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthIpAddress) != 0)
 				{
 					strcpy((char *) ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthIpAddress, tmp);
 				}
+
+				sscanf(buf, "%*s%*s%*s%s", tmp);
+				substr(tmp, tmp, strspn(tmp, "Mask:"), strlen(buf)-strspn(tmp, "Mask:"));
+				if (strcmp(tmp, (char *)ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthSubmaskAddress) != 0)
+				{
+					strcpy((char *) ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthSubmaskAddress, tmp);
+				}
 			}
 		}
 	}
 	pclose(fp);
 	memset(buf, 0x00, sizeof(buf));
+	
+	// Get gateway
+	fp = popen("ip route", "r");
+	if(fp == NULL)
+		result = FAIL;
+	else
+	{
+		while(fgets(buf, sizeof(buf), fp) != NULL)
+		{
+			if((strstr(buf, "default") != NULL) && (strstr(buf, "eth0") != NULL))
+				break;
+		}
+
+		if(strstr(buf, "default") != NULL)
+		{
+			sscanf(buf, "%*s%*s%s", tmp);
+			substr((char*)ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthGatewayAddress, tmp, 0, strlen(tmp));
+		}
+	}
+	pclose(fp);
+	memset(buf, 0x00, sizeof(buf));
 
 	for(int idx=0;idx<ARRAY_SIZE(valid_Internet);idx++)
 	{
@@ -2091,6 +2123,153 @@ void checkConnectionTimeout()
 	}
 }
 
+//===============================================
+// Set Light Internsity from ocpp
+//===============================================
+void setLightIntensity(unsigned char gun_index)
+{
+	switch(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData))
+	{
+		case 0 ... 15:		
+			if(ShmCharger->gun_info[gun_index].LightIntensityLevel != 0x00)
+			{
+				// 12 sector change to level 0
+				ShmCharger->gun_info[gun_index].setLedBrightness.sector_1  = 0x00;
+				ShmCharger->gun_info[gun_index].setLedBrightness.sector_2  = 0x00;
+				ShmCharger->gun_info[gun_index].setLedBrightness.sector_3  = 0x00;
+				ShmCharger->gun_info[gun_index].setLedBrightness.sector_4  = 0x00;
+				ShmCharger->gun_info[gun_index].setLedBrightness.sector_5  = 0x00;
+				ShmCharger->gun_info[gun_index].setLedBrightness.sector_6  = 0x00;
+				ShmCharger->gun_info[gun_index].setLedBrightness.sector_7  = 0x00;
+				ShmCharger->gun_info[gun_index].setLedBrightness.sector_8  = 0x00;
+				ShmCharger->gun_info[gun_index].setLedBrightness.sector_9  = 0x00;
+				ShmCharger->gun_info[gun_index].setLedBrightness.sector_10 = 0x00;
+				ShmCharger->gun_info[gun_index].setLedBrightness.sector_11 = 0x00;
+				ShmCharger->gun_info[gun_index].setLedBrightness.sector_12 = 0x00;
+				
+				ShmCharger->gun_info[gun_index].LightIntensityLevel = 0x00;
+				ShmCharger->gun_info[gun_index].isSetLedBrightness = ON;
+				
+				DEBUG_INFO("Light intensity level : [%X] == Level 0.\r\n", ShmCharger->gun_info[gun_index].LightIntensityLevel);
+			}
+			
+			break;
+		case 16 ... 35:
+			if(ShmCharger->gun_info[gun_index].LightIntensityLevel != 0x11)
+			{
+				// 12 sector change to level 1
+				ShmCharger->gun_info[gun_index].setLedBrightness.sector_1  = 0x11;
+				ShmCharger->gun_info[gun_index].setLedBrightness.sector_2  = 0x11;
+				ShmCharger->gun_info[gun_index].setLedBrightness.sector_3  = 0x11;
+				ShmCharger->gun_info[gun_index].setLedBrightness.sector_4  = 0x11;
+				ShmCharger->gun_info[gun_index].setLedBrightness.sector_5  = 0x11;
+				ShmCharger->gun_info[gun_index].setLedBrightness.sector_6  = 0x11;
+				ShmCharger->gun_info[gun_index].setLedBrightness.sector_7  = 0x11;
+				ShmCharger->gun_info[gun_index].setLedBrightness.sector_8  = 0x11;
+				ShmCharger->gun_info[gun_index].setLedBrightness.sector_9  = 0x11;
+				ShmCharger->gun_info[gun_index].setLedBrightness.sector_10 = 0x11;
+				ShmCharger->gun_info[gun_index].setLedBrightness.sector_11 = 0x11;
+				ShmCharger->gun_info[gun_index].setLedBrightness.sector_12 = 0x11;
+				
+				ShmCharger->gun_info[gun_index].LightIntensityLevel = 0x11;
+				ShmCharger->gun_info[gun_index].isSetLedBrightness = ON;
+				
+				DEBUG_INFO("Light intensity level : [%X] == Level 1.\r\n", ShmCharger->gun_info[gun_index].LightIntensityLevel);
+			}
+			break;
+		case 36 ... 75:
+			if(ShmCharger->gun_info[gun_index].LightIntensityLevel != 0x22)
+			{
+				// 12 sector change to level 2
+				ShmCharger->gun_info[gun_index].setLedBrightness.sector_1  = 0x22;
+				ShmCharger->gun_info[gun_index].setLedBrightness.sector_2  = 0x22;
+				ShmCharger->gun_info[gun_index].setLedBrightness.sector_3  = 0x22;
+				ShmCharger->gun_info[gun_index].setLedBrightness.sector_4  = 0x22;
+				ShmCharger->gun_info[gun_index].setLedBrightness.sector_5  = 0x22;
+				ShmCharger->gun_info[gun_index].setLedBrightness.sector_6  = 0x22;
+				ShmCharger->gun_info[gun_index].setLedBrightness.sector_7  = 0x22;
+				ShmCharger->gun_info[gun_index].setLedBrightness.sector_8  = 0x22;
+				ShmCharger->gun_info[gun_index].setLedBrightness.sector_9  = 0x22;
+				ShmCharger->gun_info[gun_index].setLedBrightness.sector_10 = 0x22;
+				ShmCharger->gun_info[gun_index].setLedBrightness.sector_11 = 0x22;
+				ShmCharger->gun_info[gun_index].setLedBrightness.sector_12 = 0x22;
+				
+				ShmCharger->gun_info[gun_index].LightIntensityLevel = 0x22;
+				ShmCharger->gun_info[gun_index].isSetLedBrightness = ON;
+				
+				DEBUG_INFO("Light intensity level : [%X] == Level 2.\r\n", ShmCharger->gun_info[gun_index].LightIntensityLevel);
+			}
+			break;
+		case 76 ... 100:
+			if(ShmCharger->gun_info[gun_index].LightIntensityLevel != 0x33)
+			{
+				// 12 sector change to level 3
+				ShmCharger->gun_info[gun_index].setLedBrightness.sector_1  = 0x33;
+				ShmCharger->gun_info[gun_index].setLedBrightness.sector_2  = 0x33;
+				ShmCharger->gun_info[gun_index].setLedBrightness.sector_3  = 0x33;
+				ShmCharger->gun_info[gun_index].setLedBrightness.sector_4  = 0x33;
+				ShmCharger->gun_info[gun_index].setLedBrightness.sector_5  = 0x33;
+				ShmCharger->gun_info[gun_index].setLedBrightness.sector_6  = 0x33;
+				ShmCharger->gun_info[gun_index].setLedBrightness.sector_7  = 0x33;
+				ShmCharger->gun_info[gun_index].setLedBrightness.sector_8  = 0x33;
+				ShmCharger->gun_info[gun_index].setLedBrightness.sector_9  = 0x33;
+				ShmCharger->gun_info[gun_index].setLedBrightness.sector_10 = 0x33;
+				ShmCharger->gun_info[gun_index].setLedBrightness.sector_11 = 0x33;
+				ShmCharger->gun_info[gun_index].setLedBrightness.sector_12 = 0x33;
+				
+				ShmCharger->gun_info[gun_index].LightIntensityLevel = 0x33;
+				ShmCharger->gun_info[gun_index].isSetLedBrightness = ON;
+				
+				DEBUG_INFO("Light intensity level : [%X] == Level 3.\r\n", ShmCharger->gun_info[gun_index].LightIntensityLevel);
+			}
+			break;
+		default:
+			if(ShmCharger->gun_info[gun_index].LightIntensityLevel != 2)
+			{
+				// 12 sector change to level 2
+				ShmCharger->gun_info[gun_index].setLedBrightness.sector_1  = 0x22;
+				ShmCharger->gun_info[gun_index].setLedBrightness.sector_2  = 0x22;
+				ShmCharger->gun_info[gun_index].setLedBrightness.sector_3  = 0x22;
+				ShmCharger->gun_info[gun_index].setLedBrightness.sector_4  = 0x22;
+				ShmCharger->gun_info[gun_index].setLedBrightness.sector_5  = 0x22;
+				ShmCharger->gun_info[gun_index].setLedBrightness.sector_6  = 0x22;
+				ShmCharger->gun_info[gun_index].setLedBrightness.sector_7  = 0x22;
+				ShmCharger->gun_info[gun_index].setLedBrightness.sector_8  = 0x22;
+				ShmCharger->gun_info[gun_index].setLedBrightness.sector_9  = 0x22;
+				ShmCharger->gun_info[gun_index].setLedBrightness.sector_10 = 0x22;
+				ShmCharger->gun_info[gun_index].setLedBrightness.sector_11 = 0x22;
+				ShmCharger->gun_info[gun_index].setLedBrightness.sector_12 = 0x22;
+				
+				ShmCharger->gun_info[gun_index].LightIntensityLevel = 0x22;
+				ShmCharger->gun_info[gun_index].isSetLedBrightness = ON;
+				
+				DEBUG_INFO("Default light intensity level : [%X] == Level 2.\r\n", ShmCharger->gun_info[gun_index].LightIntensityLevel);
+			}
+		break;
+	}
+}
+
+void initialLightIntensity(unsigned char gun_index)
+{	
+	ShmCharger->gun_info[gun_index].setLedBrightness.sector_1  = 0xff;
+	ShmCharger->gun_info[gun_index].setLedBrightness.sector_2  = 0xff;
+	ShmCharger->gun_info[gun_index].setLedBrightness.sector_3  = 0xff;
+	ShmCharger->gun_info[gun_index].setLedBrightness.sector_4  = 0xff;
+	ShmCharger->gun_info[gun_index].setLedBrightness.sector_5  = 0xff;
+	ShmCharger->gun_info[gun_index].setLedBrightness.sector_6  = 0xff;
+	ShmCharger->gun_info[gun_index].setLedBrightness.sector_7  = 0xff;
+	ShmCharger->gun_info[gun_index].setLedBrightness.sector_8  = 0xff;
+	ShmCharger->gun_info[gun_index].setLedBrightness.sector_9  = 0xff;
+	ShmCharger->gun_info[gun_index].setLedBrightness.sector_10 = 0xff;
+	ShmCharger->gun_info[gun_index].setLedBrightness.sector_11 = 0xff;
+	ShmCharger->gun_info[gun_index].setLedBrightness.sector_12 = 0xff;
+	
+	
+	ShmCharger->gun_info[gun_index].LightIntensityLevel = 0xff;
+	DEBUG_INFO("Initial light intensity gun_index %d to : [%X] .\r\n", gun_index, ShmCharger->gun_info[0].LightIntensityLevel);
+}
+
+
 //===============================================
 // Main process
 //===============================================
@@ -2122,6 +2301,7 @@ int main(void)
 		ShmCharger->gun_info[gun_index].isInitialPass = NO;
 		ShmCharger->gun_info[gun_index].isSetBreatheLedTiming = OFF;
 		ShmCharger->gun_info[gun_index].isSetLedBrightness = OFF;
+		initialLightIntensity(gun_index);
 	}
 
 	// Main loop
@@ -2250,6 +2430,9 @@ int main(void)
 			{
 				setChargerMode(gun_index, SYS_MODE_BOOTING);
 			}
+			
+			// Set light intensity
+			setLightIntensity(gun_index);
 
 			// Check initialization "PASS" or "FAIL"
 			if(ShmCharger->gun_info[gun_index].isInitialPass == YES)
@@ -2401,6 +2584,7 @@ int main(void)
 						{
 							DEBUG_INFO("URL is empty kill Module_OcppBackend...\n");
 							system ("pkill OcppBackend");
+							LoadSysConfigAndInfo(&ShmSysConfigAndInfo->SysConfig);
 						}
 
 						// If rotate switch equal zero, the system needs to change Debug mode
@@ -2579,6 +2763,9 @@ int main(void)
 					{
 						// Authorization timeout process.
 						ShmCharger->gun_info[gun_index].rfidReq = OFF;
+						setSpeaker(ON,SPEAKER_INTERVAL_3COUNT);
+						setLedMotion(gun_index,LED_ACTION_RFID_FAIL);
+						sleep(3);
 						setChargerMode(gun_index, SYS_MODE_IDLE);
 						DEBUG_WARN("Authorize timeout !!!\n");
 					}
@@ -3483,6 +3670,9 @@ int main(void)
 								sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "InstallationFailed");
 								ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
 								DEBUG_WARN("Firmware upgrade fail.\n");
+								
+								sleep(1);
+								system("rm -rvf /mnt/* ");
 								close(wtdFd);
 								system("/usr/bin/run_evse_restart.sh");
 							}

+ 1 - 0
EVSE/Projects/Noodoe/Apps/main.h

@@ -422,6 +422,7 @@ typedef struct GUN_INFO
 	uint16_t										isUnlockerConnetor:1;
 	uint16_t										isOperactive:1;
 	uint16_t										isChargerStopByCondition:1;
+	uint16_t										LightIntensityLevel;
 }Gun_Info;
 
 struct Charger

二进制
EVSE/Projects/Noodoe/Images/ramdisk.gz


+ 39 - 13
EVSE/Projects/define.h

@@ -116,7 +116,7 @@ Storage							0x0A200000-0x7FFFFFFF		1886 MB
     #define AC_QUANTITY             0
     #define GENERAL_GUN_QUANTITY	0
     #define PSU_QUANTITY            2
-    #define ONE_CONNECTOR_USE       
+    #define ONE_CONNECTOR_USE       0
 #elif DO360
     #define MAX_PSU_QUANTITY        62
     #define CHAdeMO_QUANTITY        0
@@ -444,7 +444,6 @@ struct SysConfigData
 	unsigned int 			Checksum;					//4 bytes checksum
 	struct LED				LedInfo;					// LED configuration info
 	unsigned char			ShowInformation;
-	unsigned char           OcppRunningVer;             // 0: 1.6J      1:2.0
 };
 
 struct ChargingInfoData
@@ -547,7 +546,10 @@ typedef union
         unsigned int SoftwareResetRequest:1;            // 0: no request,   1: software reset request               (    ocpp   -> cabinet -> dispenser)
         unsigned int SoftwareResetConfirm:1;            // 0: no effect,    1: dispenser confirmed
         unsigned int AuthorizeTargetID:8;               // authorize target connector id
-        unsigned int res:15;
+        unsigned int FirmwareUpdateRequest:1;           // firmware update request
+        unsigned int FirmwareUpdateConfirm:1;           // firmware update start
+        unsigned int FirmwareUpdateCompleted:1;         // firmware update completed
+        unsigned int res:12;
     }bits;
 }DispenserSettingFlag;
 
@@ -587,6 +589,7 @@ struct DispenserModule
                                                 // 0: Authorize idle, 1: Authorize wait,   2: Authorizing
     unsigned char           AuthorizeStatus;    // 3: Authorize ok,   4: Authorizing fail
     DispenserSettingFlag    Setting;
+    char                    FwFileName[128];
 };
 
 struct ConnectionInfoData
@@ -654,7 +657,9 @@ typedef union
         unsigned int  NeedCleanAuthorizeInfo:1;         //
         unsigned int  AuthorizeRequest:1;               // 0: idle,         1: requesting                                       ( dispenser -> cabinet)
         unsigned int  SwipeRfidConfirm:1;
-        unsigned int  res:14;
+        unsigned int  OutputLimitEnable:1;              // 0: disable,      1: enable
+        unsigned int  ChargingPermission:2;             // 0: not allowed,  1: allowed,         2: wait
+        unsigned int  res:11;
     }bits;
 }ConnectorParameter;
 
@@ -675,6 +680,18 @@ struct ConnectorInfoData
     unsigned int            RemoteRemainChargingDuration;   // remain charging duration from connector, unit: 1s
     unsigned char           RemoteSoc;                      // ev battery soc from connector, unit: 1%
 
+    unsigned short          RemoteMaxPhysicalVoltage;       // max physical voltage from connector, unit: 0.1V
+    unsigned short          RemoteMaxPhysicalCurrent;       // max physical current from connector, unit: 0.1A
+    unsigned short          RemoteTargetVoltage;            // target voltage from connector, unit: 0.1V
+    unsigned short          RemoteTargetCurrent;            // target current from connector, unit: 0.1A
+    unsigned short          RemoteLimitVoltage;             // limit voltage to psu voltage command, unit: 0.1V
+    unsigned short          RemoteLimitCurrent;             // limit current to psu current command, unit: 0.1A
+
+    unsigned short          MaxTotalChargingCurrent;        // max total output current, unit: 0.1A
+    unsigned short          MaxTotalChargingPower;          // max total output power, unit: 0.1kw
+    unsigned short          MaxOutputEnergy;                //0: no limit,  1 ~ 65535   kWh
+    unsigned short          MaxOutputDuration;              //0: no limit,  1 ~ 65535   minutes
+
     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
@@ -700,6 +717,7 @@ typedef union
 struct SysInfoData
 {
 	/**************System***************/
+	unsigned char OcppRunningVer;			// 0: 1.6J      1:2.0
 	unsigned char BootingStatus;			// 0 : booting, 1 : Initializing Complete.
 	unsigned char AuthorizeFlag;			// 0 : None, 1 : Authorizing
 	unsigned char FactoryConfiguration;	//0: normal, 1: trigger, charger will return the configuration to factory default if trigger
@@ -1065,10 +1083,10 @@ char AlarmStatusCode[128][6]=
 	"012300",	// System AC output OCP L3
 	"012301",	// Circuit Short L2
 	"012302",	// Circuit Short L3
-	"012303",	// CCS liquid chiller water level warning
-	"012304",	// connection disconnected from power cabinet
-	"012305",	// Meter communication timeout
-	"012306",	// The dip switch of the PSU may be incorrect
+	"012303",   // CCS liquid chiller water level warning
+	"012304",   // connection disconnected from power cabinet
+	"012305",   // Meter communication timeout
+	"012306",   // The dip switch of the PSU may be incorrect
 };
 struct AlarmCodeData
 {
@@ -1194,12 +1212,12 @@ struct AlarmCodeData
 			unsigned char SystemAcOutputOCPL3:1;					//bit 4
 			unsigned char CircuitShortL2:1;							//bit 5
 			unsigned char CircuitShortL3:1;							//bit 6
-			unsigned char CcsLiquidChillerWaterLevelWarning:1;		//bit 7
+			unsigned char CcsLiquidChillerWaterLevelWarning:1;      //bit 7
 			//AlarmVal[13]
-			unsigned char DisconnectedFromDo :1;					//bit 0
-			unsigned char MeterCommTimeout:1;						//bit 1
-			unsigned char PsuDipSwitchStestFail:1; 					//bit 1
-			unsigned char Reserved :5;								//bit 3~bit7
+            unsigned char DisconnectedFromDo:1;                     //bit 0
+            unsigned char MeterCommTimeout:1;                       //bit 1
+            unsigned char PsuDipSwitchStestFail:1;                  //bit 2
+            unsigned char Reserved:5;                               //bit 3~bit7
 		}bits;
 	}AlarmEvents;
 };
@@ -5346,6 +5364,13 @@ struct UpdateFirmware_20
 	unsigned char guid[37];											// Save guid from server request
 };
 
+struct NetworkConnectionProfile_20
+{
+	unsigned int slot;
+	unsigned char retryCount;
+	struct NetworkConnectionProfileType connectionData;
+};
+
 struct OCPP20Data
 {
 	unsigned char 							OcppServerURL[512];		//http: non-secure OCPP 1.5-S, https: secure OCPP 1.5-S, ws: non-secure OCPP 1.6-J, wss: secure OCPP 1.6-J"
@@ -5354,6 +5379,7 @@ struct OCPP20Data
 	unsigned int 							Timeout_Secs;
 	unsigned short 							Ping_Pong_Interval;
 	struct ReportDataType                   ControllerComponentVariable[CtrlrVariable_CNT];
+	struct NetworkConnectionProfile_20		NetworkConnectionProfile[10];
 
 	union
 	{

+ 1 - 0
EVSE/rootfs/root/.gitignore

@@ -3,6 +3,7 @@ Module_4g
 WebService
 logPackTools
 OcppBackend
+OcppBackend20
 Module_ProduceUtils
 Module_EventLogging
 Module_PhBackend

二进制
EVSE/rootfs/root/OcppBackend20


二进制
EVSE/rootfs/usr/bin/phyreg


+ 18 - 17
Makefile

@@ -53,7 +53,7 @@ Taurus-rootfs:
 	@echo     Building User rootfs
 	@echo =================================
 #	@cd EVSE/GPL;make all
-	@cd EVSE/Modularization;make all
+	@cd EVSE/Modularization;make TLS_EXPIRED=TLS_PASS_CERT_EXPIRED all
 	@cd EVSE/Projects/Taurus/Apps;make all
 	@rm -f EVSE/Projects/Taurus/Images/ramdisk.gz
 	@dd if=/dev/zero of=/dev/ram0 bs=1k count=131072
@@ -128,7 +128,7 @@ DD360-rootfs:
 	@echo     Building User rootfs
 	@echo =================================
 #	@cd EVSE/GPL;make Project=DD360 all
-	@cd EVSE/Modularization;make Project=DD360 all
+	@cd EVSE/Modularization;make TLS_EXPIRED=TLS_PASS_CERT_EXPIRED Project=DD360 all
 	@cd EVSE/Projects/DD360/Apps;make Project=DD360 all
 	@rm -f EVSE/Projects/DD360/Images/ramdisk.gz
 	@dd if=/dev/zero of=EVSE/Projects/DD360/Images/ramdisk bs=1k count=131072
@@ -249,6 +249,7 @@ CCS-rootfs:
 	@mount -o loop EVSE/Projects/CCS/Images/ramdisk EVSE/Projects/CCS/Images/mnt
 	@cp -rfv EVSE/rootfs/* EVSE/Projects/CCS/Images/mnt/
 	@cp -rfv EVSE/Projects/CCS/Images/root/* EVSE/Projects/CCS/Images/mnt/root
+	@cp -rfv EVSE/Projects/CCS/sh/rcS EVSE/Projects/CCS/Images/mnt/etc/init.d/
 	@chown www-data:www-data EVSE/Projects/CCS/Images/mnt/var/www -R
 	@chmod 777 EVSE/Projects/CCS/Images/mnt/var/log -R
 	@chmod 777 EVSE/Projects/CCS/Images/mnt/var/run -R
@@ -307,7 +308,7 @@ DM30-rootfs:
 	@echo     Building User rootfs
 	@echo =================================
 #	@cd EVSE/GPL;make all
-	@cd EVSE/Modularization;make Project=DM30 all
+	@cd EVSE/Modularization;make TLS_EXPIRED=TLS_PASS_CERT_EXPIRED Project=DM30 all
 	@cd EVSE/Projects/DM30/Apps;make Project=DM30 Project_Debug_Option=0 all
 	@rm -f EVSE/Projects/DM30/Images/ramdisk.gz
 	@dd if=/dev/zero of=/dev/ram0 bs=1k count=131072
@@ -335,7 +336,7 @@ DM30-DEBUG-rootfs:
 	@echo =================================
 	@echo     Building DM30 debug rootfs
 	@echo =================================
-	@cd EVSE/Modularization;make Project=DM30 all
+	@cd EVSE/Modularization;make TLS_EXPIRED=TLS_PASS_CERT_EXPIRED Project=DM30 all
 	@cd EVSE/Projects/DM30/Apps;make Project=DM30 Project_Debug_Option=1 all
 	@rm -f EVSE/Projects/DM30/Images/ramdisk.gz
 	@dd if=/dev/zero of=/dev/ram0 bs=1k count=131072
@@ -402,7 +403,7 @@ DW30-rootfs:
 	@echo     Building User rootfs
 	@echo =================================
 #	@cd EVSE/GPL;make all
-	@cd EVSE/Modularization;make Project=DW30 all
+	@cd EVSE/Modularization;make TLS_EXPIRED=TLS_PASS_CERT_EXPIRED Project=DW30 all
 	@cd EVSE/Projects/DW30/Apps;make Project=DW30 Project_Debug_Option=0 all
 	@rm -f EVSE/Projects/DW30/Images/ramdisk.gz
 	@dd if=/dev/zero of=/dev/ram0 bs=1k count=131072
@@ -430,7 +431,7 @@ DW30-DEBUG-rootfs:
 	@echo =================================
 	@echo     Building DW30 debug rootfs
 	@echo =================================
-	@cd EVSE/Modularization;make Project=DW30 all
+	@cd EVSE/Modularization;make TLS_EXPIRED=TLS_PASS_CERT_EXPIRED Project=DW30 all
 	@cd EVSE/Projects/DW30/Apps;make Project=DW30 Project_Debug_Option=1 all
 	@rm -f EVSE/Projects/DW30/Images/ramdisk.gz
 	@dd if=/dev/zero of=/dev/ram0 bs=1k count=131072
@@ -501,7 +502,7 @@ DS60-120-rootfs:
 	@echo     Building User rootfs
 	@echo =================================
 #	@cd EVSE/GPL;make all
-	@cd EVSE/Modularization;make Project=DS60120 all
+	@cd EVSE/Modularization;make TLS_EXPIRED=TLS_PASS_CERT_EXPIRED Project=DS60120 all
 	@cd EVSE/Projects/DS60-120/Apps;make Project=DS60120 all
 	@rm -f EVSE/Projects/DS60-120/Images/ramdisk.gz
 	@dd if=/dev/zero of=/dev/ram0 bs=1k count=131072
@@ -572,7 +573,7 @@ AW-Regular-rootfs:
 	@echo     Building User rootfs
 	@echo =================================
 #	@cd EVSE/GPL;make all
-	@cd EVSE/Modularization;make Project=AWRegular all
+	@cd EVSE/Modularization;make TLS_EXPIRED=TLS_PASS_CERT_EXPIRED Project=AWRegular all
 	@cd EVSE/Projects/AW-Regular/Apps;make Project=AWRegular all
 	@rm -f EVSE/Projects/AW-Regular/Images/ramdisk.gz
 	@dd if=/dev/zero of=/dev/ram0 bs=1k count=131072
@@ -643,7 +644,7 @@ BYTON-GB-rootfs:
 	@echo     Building User rootfs
 	@echo =================================
 #	@cd EVSE/GPL;make all
-	@cd EVSE/Modularization;make Project=BYTONGB all
+	@cd EVSE/Modularization;make TLS_EXPIRED=TLS_PASS_CERT_EXPIRED Project=BYTONGB all
 	@cd EVSE/Projects/BYTON-GB/Apps;make Project=BYTONGB all
 	@rm -f EVSE/Projects/BYTON-GB/Images/ramdisk.gz
 	@dd if=/dev/zero of=/dev/ram0 bs=1k count=131072
@@ -1067,7 +1068,7 @@ Noodoe-rootfs:
 	@echo     Building User rootfs
 	@echo =================================
 #	@cd EVSE/GPL;make Project=Noodoe all
-	@cd EVSE/Modularization;make Project=Noodoe all
+	@cd EVSE/Modularization;make TLS_EXPIRED=TLS_VALID_CERT_EXPIRED Project=Noodoe all
 	@cd EVSE/Projects/Noodoe/Apps;make Project=Noodoe all
 	@rm -f EVSE/Projects/Noodoe/Images/ramdisk.gz
 	@dd if=/dev/zero of=/dev/ram0 bs=1k count=131072
@@ -1140,7 +1141,7 @@ PlugIt360-rootfs:
 	@echo     Building User rootfs
 	@echo =================================
 #	@cd EVSE/GPL;make Project=PlugIt360 all
-	@cd EVSE/Modularization;make Project=PlugIt360 all
+	@cd EVSE/Modularization;make TLS_EXPIRED=TLS_PASS_CERT_EXPIRED Project=PlugIt360 all
 	@cd EVSE/Projects/PlugIt360/Apps;make Project=PlugIt360 all
 	@rm -f EVSE/Projects/PlugIt360/Images/ramdisk.gz
 	@dd if=/dev/zero of=/dev/ram0 bs=1k count=131072
@@ -1213,7 +1214,7 @@ AW-CCS-rootfs:
 	@echo     Building User rootfs
 	@echo =================================
 #	@cd EVSE/GPL;make Project=AWCCS all
-	@cd EVSE/Modularization;make Project=AWCCS all
+	@cd EVSE/Modularization;make TLS_EXPIRED=TLS_PASS_CERT_EXPIRED Project=AWCCS all
 	@cd EVSE/Projects/AW-CCS/Apps;make Project=AWCCS all
 	@rm -f EVSE/Projects/AW-CCS/Images/ramdisk.gz
 	@dd if=/dev/zero of=/dev/ram0 bs=1k count=131072
@@ -1285,7 +1286,7 @@ DO360-rootfs:
 	@echo     Building User rootfs
 	@echo =================================
 #	@cd EVSE/GPL;make Project=DO360 all
-	@cd EVSE/Modularization;make Project=DO360 all
+	@cd EVSE/Modularization;make TLS_EXPIRED=TLS_PASS_CERT_EXPIRED Project=DO360 all
 	@cd EVSE/Projects/DO360/Apps;make Project=DO360 all
 	@rm -f EVSE/Projects/DO360/Images/ramdisk.gz
 	@dd if=/dev/zero of=/dev/ram0 bs=1k count=131072
@@ -1358,7 +1359,7 @@ ATE-rootfs:
 	@echo     Building User rootfs
 	@echo =================================
 #	@cd EVSE/GPL;make Project=ATE all
-	@cd EVSE/Modularization;make Project=ATE all
+	@cd EVSE/Modularization;make TLS_EXPIRED=TLS_PASS_CERT_EXPIRED Project=ATE all
 	@cd EVSE/Projects/ATE/Apps;make Project=ATE all
 	@rm -f EVSE/Projects/ATE/Images/ramdisk.gz
 	@dd if=/dev/zero of=/dev/ram0 bs=1k count=131072
@@ -1431,7 +1432,7 @@ Zanobe-rootfs:
 	@echo     Building User rootfs
 	@echo =================================
 #	@cd EVSE/GPL;make Project=Zanobe all
-	@cd EVSE/Modularization;make Project=Zanobe all
+	@cd EVSE/Modularization;make TLS_EXPIRED=TLS_PASS_CERT_EXPIRED Project=Zanobe all
 	@cd EVSE/Projects/Zanobe/Apps;make Project=Zanobe all
 	@rm -f EVSE/Projects/Zanobe/Images/ramdisk.gz
 	@dd if=/dev/zero of=/dev/ram0 bs=1k count=131072
@@ -1504,7 +1505,7 @@ e4you-rootfs:
 	@echo     Building User rootfs
 	@echo =================================
 #	@cd EVSE/GPL;make Project=e4you all
-	@cd EVSE/Modularization;make Project=e4you all
+	@cd EVSE/Modularization;make TLS_EXPIRED=TLS_PASS_CERT_EXPIRED Project=e4you all
 	@cd EVSE/Projects/e4you/Apps;make Project=e4you all
 	@rm -f EVSE/Projects/e4you/Images/ramdisk.gz
 	@dd if=/dev/zero of=/dev/ram0 bs=1k count=131072
@@ -1577,7 +1578,7 @@ DD360Audi-rootfs:
 	@echo     Building User rootfs
 	@echo =================================
 #	@cd EVSE/GPL;make Project=DD360Audi all
-	@cd EVSE/Modularization;make Project=DD360Audi all
+	@cd EVSE/Modularization;make TLS_EXPIRED=TLS_VALID_CERT_EXPIRED Project=DD360Audi all
 	@cd EVSE/Projects/DD360Audi/Apps;make Project=DD360Audi all
 	@rm -f EVSE/Projects/DD360Audi/Images/ramdisk.gz
 	@dd if=/dev/zero of=/dev/ram0 bs=1k count=131072

+ 1 - 1
run_gen_make_script.sh

@@ -46,7 +46,7 @@ echo -e "\t@echo ================================="
 echo -e "\t@echo     Building User rootfs"
 echo -e "\t@echo ================================="
 echo -e "#\t@cd EVSE/GPL;make Project=$1 all"
-echo -e "\t@cd EVSE/Modularization;make Project=$1 all"
+echo -e "\t@cd EVSE/Modularization;make TLS_EXPIRED=TLS_PASS_CERT_EXPIRED Project=$1 all"
 echo -e "\t@cd EVSE/Projects/$1/Apps;make Project=$1 all"
 echo -e "\t@rm -f EVSE/Projects/$1/Images/ramdisk.gz"
 echo -e "\t@dd if=/dev/zero of=/dev/ram0 bs=1k count=131072"

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