Sfoglia il codice sorgente

Merge branch 'master' into DD360Audi

Jerry_Wang 4 anni fa
parent
commit
5ab47b3f05
51 ha cambiato i file con 767 aggiunte e 370 eliminazioni
  1. 1 1
      EVSE/GPL/Makefile
  2. 2 2
      EVSE/GPL/libnl-1.1.4/config.log
  3. BIN
      EVSE/GPL/wpa_supplicant-2.6/release/usr/local/sbin/wpa_passphrase
  4. BIN
      EVSE/GPL/wpa_supplicant-2.6/release/usr/local/sbin/wpa_supplicant
  5. 2 0
      EVSE/GPL/wpa_supplicant-2.6/wpa_supplicant/.config
  6. 20 0
      EVSE/GPL/wpa_supplicant-2.6/wpa_supplicant/bgscan.d
  7. 21 0
      EVSE/GPL/wpa_supplicant-2.6/wpa_supplicant/bgscan_learn.d
  8. 20 0
      EVSE/GPL/wpa_supplicant-2.6/wpa_supplicant/bgscan_simple.d
  9. 2 0
      EVSE/GPL/wpa_supplicant-2.6/wpa_supplicant/defconfig
  10. BIN
      EVSE/GPL/wpa_supplicant-2.6/wpa_supplicant/events.o
  11. BIN
      EVSE/GPL/wpa_supplicant-2.6/wpa_supplicant/wpa_passphrase
  12. BIN
      EVSE/GPL/wpa_supplicant-2.6/wpa_supplicant/wpa_supplicant
  13. BIN
      EVSE/GPL/wpa_supplicant-2.6/wpa_supplicant/wpa_supplicant.o
  14. 42 11
      EVSE/Modularization/Module_4g.c
  15. 1 1
      EVSE/Modularization/Module_PhBackend.c
  16. 49 28
      EVSE/Modularization/Module_Upgrade.c
  17. 6 2
      EVSE/Modularization/Module_Wifi.c
  18. 4 4
      EVSE/Modularization/WebService.c
  19. 100 0
      EVSE/Modularization/ocpp20/MessageHandler.c
  20. 1 0
      EVSE/Modularization/ocpp20/MessageHandler.h
  21. 1 0
      EVSE/Modularization/ocpp20/Module_OcppBackend20.c
  22. 100 0
      EVSE/Modularization/ocppfiles/MessageHandler.c
  23. 1 0
      EVSE/Modularization/ocppfiles/MessageHandler.h
  24. 1 0
      EVSE/Modularization/ocppfiles/Module_OcppBackend.c
  25. 1 1
      EVSE/Projects/AW-CCS/Apps/Module_Debug.c
  26. BIN
      EVSE/Projects/AW-CCS/Apps/Module_PowerSharing
  27. 282 287
      EVSE/Projects/AW-CCS/Apps/Module_PowerSharing.c
  28. 15 10
      EVSE/Projects/AW-CCS/Apps/Module_PowerSharing.h
  29. 3 2
      EVSE/Projects/AW-CCS/Apps/main.c
  30. 1 1
      EVSE/Projects/AW-Regular/Apps/Module_Debug.c
  31. 1 1
      EVSE/Projects/AW-Regular/Apps/Module_InternalComm.c
  32. 5 2
      EVSE/Projects/AW-Regular/Apps/main.c
  33. BIN
      EVSE/Projects/AW-Regular/Images/FactoryDefaultConfig.bin
  34. BIN
      EVSE/Projects/AW-Regular/Images/ramdisk.gz
  35. 1 1
      EVSE/Projects/Noodoe/Apps/Module_Debug.c
  36. 1 1
      EVSE/Projects/Noodoe/Apps/Module_InternalComm.c
  37. 2 2
      EVSE/Projects/Noodoe/Apps/main.c
  38. BIN
      EVSE/Projects/Noodoe/Images/FactoryDefaultConfig.bin
  39. BIN
      EVSE/Projects/Noodoe/Images/ramdisk.gz
  40. 1 0
      EVSE/Projects/define.h
  41. 4 0
      EVSE/rootfs/bin/flash_eraseall
  42. 14 1
      EVSE/rootfs/etc/init.d/rcS
  43. 1 1
      EVSE/rootfs/etc/logrotate.d/evse
  44. BIN
      EVSE/rootfs/root/OcppBackend20
  45. BIN
      EVSE/rootfs/root/wpa_supplicant
  46. 28 0
      EVSE/rootfs/usr/bin/run_log_clear.sh
  47. 16 0
      EVSE/rootfs/usr/bin/run_scan_net.sh
  48. 1 0
      EVSE/rootfs/var/spool/cron/crontabs/root
  49. 8 3
      EVSE/rootfs/var/www/head.php
  50. 4 4
      EVSE/rootfs/var/www/set_charging.php
  51. 4 4
      EVSE/rootfs/var/www/set_system.php

+ 1 - 1
EVSE/GPL/Makefile

@@ -77,7 +77,7 @@ WPA :
 	cp wpa_supplicant-2.6/wpa_supplicant/wpa_supplicant.conf ../rootfs/root/
 	cd hostapd-2.6/hostapd;make CC=$(CROSS_COMPILE)gcc
 	cd hostapd-2.6/hostapd;make install DESTDIR=$(shell pwd)/hostapd-2.6/release
-	cp hostapd-2.6/release/release/usr/local/bin/hostapd ../rootfs/usr/bin/
+	cp hostapd-2.6/release/usr/local/bin/hostapd ../rootfs/usr/bin/
 
 WirelessTool :
 	echo "wireless_tools.29"

+ 2 - 2
EVSE/GPL/libnl-1.1.4/config.log

@@ -12,9 +12,9 @@ generated by GNU Autoconf 2.68.  Invocation command line was
 
 hostname = am335x_ide
 uname -m = x86_64
-uname -r = 4.15.0-88-generic
+uname -r = 4.15.0-136-generic
 uname -s = Linux
-uname -v = #88-Ubuntu SMP Tue Feb 11 20:11:34 UTC 2020
+uname -v = #140-Ubuntu SMP Thu Jan 28 05:20:47 UTC 2021
 
 /usr/bin/uname -p = unknown
 /bin/uname -X     = unknown

BIN
EVSE/GPL/wpa_supplicant-2.6/release/usr/local/sbin/wpa_passphrase


BIN
EVSE/GPL/wpa_supplicant-2.6/release/usr/local/sbin/wpa_supplicant


+ 2 - 0
EVSE/GPL/wpa_supplicant-2.6/wpa_supplicant/.config

@@ -548,3 +548,5 @@ CONFIG_PEERKEY=y
 
 # Support Multi Band Operation
 #CONFIG_MBO=y
+CONFIG_BGSCAN_SIMPLE=y
+CONFIG_BGSCAN_LEARN=y

+ 20 - 0
EVSE/GPL/wpa_supplicant-2.6/wpa_supplicant/bgscan.d

@@ -0,0 +1,20 @@
+bgscan.o: bgscan.c \
+ /opt/ti-processor-sdk-linux-am335x-evm-04.02.00.09/EVSE/GPL/wpa_supplicant-2.6/src/utils/includes.h \
+ /opt/ti-processor-sdk-linux-am335x-evm-04.02.00.09/EVSE/GPL/wpa_supplicant-2.6/src/utils/build_config.h \
+ /opt/ti-processor-sdk-linux-am335x-evm-04.02.00.09/EVSE/GPL/wpa_supplicant-2.6/src/utils/common.h \
+ /opt/ti-processor-sdk-linux-am335x-evm-04.02.00.09/EVSE/GPL/wpa_supplicant-2.6/src/utils/os.h \
+ /opt/ti-processor-sdk-linux-am335x-evm-04.02.00.09/EVSE/GPL/wpa_supplicant-2.6/src/utils/wpa_debug.h \
+ /opt/ti-processor-sdk-linux-am335x-evm-04.02.00.09/EVSE/GPL/wpa_supplicant-2.6/src/utils/wpabuf.h \
+ wpa_supplicant_i.h \
+ /opt/ti-processor-sdk-linux-am335x-evm-04.02.00.09/EVSE/GPL/wpa_supplicant-2.6/src/utils/list.h \
+ /opt/ti-processor-sdk-linux-am335x-evm-04.02.00.09/EVSE/GPL/wpa_supplicant-2.6/src/common/defs.h \
+ /opt/ti-processor-sdk-linux-am335x-evm-04.02.00.09/EVSE/GPL/wpa_supplicant-2.6/src/common/sae.h \
+ /opt/ti-processor-sdk-linux-am335x-evm-04.02.00.09/EVSE/GPL/wpa_supplicant-2.6/src/common/wpa_ctrl.h \
+ /opt/ti-processor-sdk-linux-am335x-evm-04.02.00.09/EVSE/GPL/wpa_supplicant-2.6/src/wps/wps_defs.h \
+ config_ssid.h \
+ /opt/ti-processor-sdk-linux-am335x-evm-04.02.00.09/EVSE/GPL/wpa_supplicant-2.6/src/eap_peer/eap_config.h \
+ wmm_ac.h \
+ /opt/ti-processor-sdk-linux-am335x-evm-04.02.00.09/EVSE/GPL/wpa_supplicant-2.6/src/common/ieee802_11_defs.h \
+ /opt/ti-processor-sdk-linux-am335x-evm-04.02.00.09/EVSE/GPL/wpa_supplicant-2.6/src/utils/common.h \
+ /opt/ti-processor-sdk-linux-am335x-evm-04.02.00.09/EVSE/GPL/wpa_supplicant-2.6/src/drivers/driver.h \
+ bgscan.h

+ 21 - 0
EVSE/GPL/wpa_supplicant-2.6/wpa_supplicant/bgscan_learn.d

@@ -0,0 +1,21 @@
+bgscan_learn.o: bgscan_learn.c \
+ /opt/ti-processor-sdk-linux-am335x-evm-04.02.00.09/EVSE/GPL/wpa_supplicant-2.6/src/utils/includes.h \
+ /opt/ti-processor-sdk-linux-am335x-evm-04.02.00.09/EVSE/GPL/wpa_supplicant-2.6/src/utils/build_config.h \
+ /opt/ti-processor-sdk-linux-am335x-evm-04.02.00.09/EVSE/GPL/wpa_supplicant-2.6/src/utils/common.h \
+ /opt/ti-processor-sdk-linux-am335x-evm-04.02.00.09/EVSE/GPL/wpa_supplicant-2.6/src/utils/os.h \
+ /opt/ti-processor-sdk-linux-am335x-evm-04.02.00.09/EVSE/GPL/wpa_supplicant-2.6/src/utils/wpa_debug.h \
+ /opt/ti-processor-sdk-linux-am335x-evm-04.02.00.09/EVSE/GPL/wpa_supplicant-2.6/src/utils/wpabuf.h \
+ /opt/ti-processor-sdk-linux-am335x-evm-04.02.00.09/EVSE/GPL/wpa_supplicant-2.6/src/utils/eloop.h \
+ /opt/ti-processor-sdk-linux-am335x-evm-04.02.00.09/EVSE/GPL/wpa_supplicant-2.6/src/utils/list.h \
+ /opt/ti-processor-sdk-linux-am335x-evm-04.02.00.09/EVSE/GPL/wpa_supplicant-2.6/src/common/ieee802_11_defs.h \
+ /opt/ti-processor-sdk-linux-am335x-evm-04.02.00.09/EVSE/GPL/wpa_supplicant-2.6/src/utils/common.h \
+ /opt/ti-processor-sdk-linux-am335x-evm-04.02.00.09/EVSE/GPL/wpa_supplicant-2.6/src/drivers/driver.h \
+ /opt/ti-processor-sdk-linux-am335x-evm-04.02.00.09/EVSE/GPL/wpa_supplicant-2.6/src/common/defs.h \
+ /opt/ti-processor-sdk-linux-am335x-evm-04.02.00.09/EVSE/GPL/wpa_supplicant-2.6/src/utils/list.h \
+ config_ssid.h \
+ /opt/ti-processor-sdk-linux-am335x-evm-04.02.00.09/EVSE/GPL/wpa_supplicant-2.6/src/eap_peer/eap_config.h \
+ wpa_supplicant_i.h \
+ /opt/ti-processor-sdk-linux-am335x-evm-04.02.00.09/EVSE/GPL/wpa_supplicant-2.6/src/common/sae.h \
+ /opt/ti-processor-sdk-linux-am335x-evm-04.02.00.09/EVSE/GPL/wpa_supplicant-2.6/src/common/wpa_ctrl.h \
+ /opt/ti-processor-sdk-linux-am335x-evm-04.02.00.09/EVSE/GPL/wpa_supplicant-2.6/src/wps/wps_defs.h \
+ wmm_ac.h driver_i.h scan.h bgscan.h

+ 20 - 0
EVSE/GPL/wpa_supplicant-2.6/wpa_supplicant/bgscan_simple.d

@@ -0,0 +1,20 @@
+bgscan_simple.o: bgscan_simple.c \
+ /opt/ti-processor-sdk-linux-am335x-evm-04.02.00.09/EVSE/GPL/wpa_supplicant-2.6/src/utils/includes.h \
+ /opt/ti-processor-sdk-linux-am335x-evm-04.02.00.09/EVSE/GPL/wpa_supplicant-2.6/src/utils/build_config.h \
+ /opt/ti-processor-sdk-linux-am335x-evm-04.02.00.09/EVSE/GPL/wpa_supplicant-2.6/src/utils/common.h \
+ /opt/ti-processor-sdk-linux-am335x-evm-04.02.00.09/EVSE/GPL/wpa_supplicant-2.6/src/utils/os.h \
+ /opt/ti-processor-sdk-linux-am335x-evm-04.02.00.09/EVSE/GPL/wpa_supplicant-2.6/src/utils/wpa_debug.h \
+ /opt/ti-processor-sdk-linux-am335x-evm-04.02.00.09/EVSE/GPL/wpa_supplicant-2.6/src/utils/wpabuf.h \
+ /opt/ti-processor-sdk-linux-am335x-evm-04.02.00.09/EVSE/GPL/wpa_supplicant-2.6/src/utils/eloop.h \
+ /opt/ti-processor-sdk-linux-am335x-evm-04.02.00.09/EVSE/GPL/wpa_supplicant-2.6/src/drivers/driver.h \
+ /opt/ti-processor-sdk-linux-am335x-evm-04.02.00.09/EVSE/GPL/wpa_supplicant-2.6/src/common/defs.h \
+ /opt/ti-processor-sdk-linux-am335x-evm-04.02.00.09/EVSE/GPL/wpa_supplicant-2.6/src/common/ieee802_11_defs.h \
+ /opt/ti-processor-sdk-linux-am335x-evm-04.02.00.09/EVSE/GPL/wpa_supplicant-2.6/src/utils/common.h \
+ /opt/ti-processor-sdk-linux-am335x-evm-04.02.00.09/EVSE/GPL/wpa_supplicant-2.6/src/utils/list.h \
+ config_ssid.h \
+ /opt/ti-processor-sdk-linux-am335x-evm-04.02.00.09/EVSE/GPL/wpa_supplicant-2.6/src/eap_peer/eap_config.h \
+ wpa_supplicant_i.h \
+ /opt/ti-processor-sdk-linux-am335x-evm-04.02.00.09/EVSE/GPL/wpa_supplicant-2.6/src/common/sae.h \
+ /opt/ti-processor-sdk-linux-am335x-evm-04.02.00.09/EVSE/GPL/wpa_supplicant-2.6/src/common/wpa_ctrl.h \
+ /opt/ti-processor-sdk-linux-am335x-evm-04.02.00.09/EVSE/GPL/wpa_supplicant-2.6/src/wps/wps_defs.h \
+ wmm_ac.h driver_i.h scan.h bgscan.h

+ 2 - 0
EVSE/GPL/wpa_supplicant-2.6/wpa_supplicant/defconfig

@@ -548,3 +548,5 @@ CONFIG_PEERKEY=y
 
 # Support Multi Band Operation
 #CONFIG_MBO=y
+CONFIG_BGSCAN_SIMPLE=y
+CONFIG_BGSCAN_LEARN=y

BIN
EVSE/GPL/wpa_supplicant-2.6/wpa_supplicant/events.o


BIN
EVSE/GPL/wpa_supplicant-2.6/wpa_supplicant/wpa_passphrase


BIN
EVSE/GPL/wpa_supplicant-2.6/wpa_supplicant/wpa_supplicant


BIN
EVSE/GPL/wpa_supplicant-2.6/wpa_supplicant/wpa_supplicant.o


+ 42 - 11
EVSE/Modularization/Module_4g.c

@@ -80,7 +80,7 @@ void substr(char *dest, const char* src, unsigned int start, unsigned int cnt);
 
 char *portName[3] 				= {"/dev/ttyUSB2", "/dev/ttyUSB2", "/dev/ttyACM2"};
 char *valid_Internet[2] 		= {"8.8.8.8", "180.76.76.76"};
-char *Version_And_Date[2]		= {"V0.08","2021-02-23"};
+char *Version_And_Date[2]		= {"V0.09","2021-03-11"};
 pid_t	pid;
 
 struct dongle_info
@@ -227,11 +227,11 @@ int Check4GModem(void)
 
     if(result == DONGLE_QUECTEL)
     {
-    	DEBUG_WARN("Quectel 4G modem be found\n");
+    	DEBUG_INFO("Quectel 4G modem be found\n");
     }
     else if(result == DONGLE_UBLOX)
     {
-    	DEBUG_WARN("Ublox 4G modem be found\n");
+    	DEBUG_INFO("Ublox 4G modem be found\n");
     }
     else
     {
@@ -879,7 +879,8 @@ int isReachableInternet(void)
 	FILE *fp;
 	char cmd[256];
 	char buf[512];
-	//char tmp[512];
+	char tmp[256];
+	char isPppGetGw = FALSE;
 
 	for(int idx=0;idx<ARRAY_SIZE(valid_Internet);idx++)
 	{
@@ -894,9 +895,7 @@ int isReachableInternet(void)
 					//sscanf(buf, "%*s%*s%*s%*s%*s%s", tmp);
 
 					if(strstr(buf,"100%") != NULL)
-					{
-
-					}
+					{}
 					else
 					{
 						result = PASS;
@@ -906,10 +905,44 @@ int isReachableInternet(void)
 				}
 			}
 		}
-		
 		pclose(fp);
 	}
 	
+	// Check ppp0 gateway
+	if(result == TRUE)
+	{
+		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, "ppp0") != NULL))
+				{
+					isPppGetGw = TRUE;
+					break;
+				}
+
+				if(strstr(buf, "ppp0") != NULL)
+				{
+					break;
+				}
+			}
+
+			if((isPppGetGw == FALSE) && (strstr(buf, "ppp0") != NULL))
+			{
+				sscanf(buf, "%s", tmp);
+				DEBUG_INFO("ppp0 does not get default route gateway force assign to %s\n", tmp);
+
+				sprintf(cmd,"route add default gw %s ppp0 &", tmp);
+				system(cmd);
+			}
+		}
+		pclose(fp);
+		memset(buf, 0x00, sizeof(buf));
+	}
+
 	return result;
 }
 
@@ -1171,8 +1204,7 @@ int main(void)
 	
 	for(;;)
 	{
-		TOP:
-		
+TOP:
 		switch(ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomEnabled)
 		{
 			case ENABLE_4G:
@@ -1475,7 +1507,6 @@ int main(void)
 				break;
 			
 		}
-		//sleep(SystemInterval);
 	}
 
 	return 0;

+ 1 - 1
EVSE/Modularization/Module_PhBackend.c

@@ -21,7 +21,7 @@ int StoreLogMsg(const char *fmt, ...)
 	memset(Buf,0,sizeof(Buf));
 	CurrentTime = time(NULL);
 	tm=localtime(&CurrentTime);
-	sprintf(Buf,"echo -n \"[%04d.%02d.%02d %02d:%02d:%02d] - %s\" >> /Storage/SystemLog/[%04d.%02d]Module_PhBackend",
+	sprintf(Buf,"echo -n \"[%04d.%02d.%02d %02d:%02d:%02d] - %s\" >> /Storage/SystemLog/[%04d.%02d]Module_PhBackendLog",
 			tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,
 			buffer,
 			tm->tm_year+1900,tm->tm_mon+1);

+ 49 - 28
EVSE/Modularization/Module_Upgrade.c

@@ -177,15 +177,20 @@ int Upgrade_Flash(unsigned int Type,char *SourcePath,char *ModelName)
     DEBUG_INFO("Delete source file.\n");
 
     //read out the header
-    int i;
     int isModelNameOK = PASS;
-    for(i=0;i<16;i++)
-    {
-        if(ModelName[i] != ptr[i])
-        {
-            isModelNameOK = FAIL;
-        }
-    }
+
+	if((ModelName[0] != ptr[0]) ||
+	   (ModelName[1] != ptr[1]) ||
+	   (ModelName[7] != ptr[7]) ||
+	   (ModelName[8] != ptr[8]) ||
+	   (ModelName[9] != ptr[9]) ||
+	   (ModelName[11] != ptr[11]) ||
+	   (ModelName[12] != ptr[12]) ||
+	   (ModelName[13] != ptr[13]))
+	{
+		isModelNameOK = FAIL;
+	}
+
 
     if(isModelNameOK == FAIL)
     {
@@ -681,15 +686,20 @@ int Upgrade_UART(int uartfdOrd,unsigned int Type,unsigned char TargetAddr,char *
     ImageLen = read(fd,ptr,MaxLen);
     close(fd);
     //read out the header
-    int i;
     int isModelNameOK = PASS;
-    for(i=0;i<16;i++)
-    {
-        if(ModelName[i] != ptr[i])
-        {
-            isModelNameOK = FAIL;
-        }
-    }
+
+    if((ModelName[0] != ptr[0]) ||
+	   (ModelName[1] != ptr[1]) ||
+	   (ModelName[7] != ptr[7]) ||
+	   (ModelName[8] != ptr[8]) ||
+	   (ModelName[9] != ptr[9]) ||
+	   (ModelName[11] != ptr[11]) ||
+	   (ModelName[12] != ptr[12]) ||
+	   (ModelName[13] != ptr[13]))
+	{
+		isModelNameOK = FAIL;
+	}
+
 
     if(isModelNameOK == FAIL)
     {
@@ -970,13 +980,20 @@ int Upgrade_CAN(int canfd,unsigned int Type,unsigned char TargetAddr,char *Sourc
     ImageLen = read(fd,ptr,MaxLen);
     close(fd);
     //read out the header
-    int i;
     int isModelNameOK = PASS;
-    for(i=0;i<16;i++) {
-        if(ModelName[i] != ptr[i]){
-            isModelNameOK = FAIL;
-        }
-    }
+
+    if((ModelName[0] != ptr[0]) ||
+	   (ModelName[1] != ptr[1]) ||
+	   (ModelName[7] != ptr[7]) ||
+	   (ModelName[8] != ptr[8]) ||
+	   (ModelName[9] != ptr[9]) ||
+	   (ModelName[11] != ptr[11]) ||
+	   (ModelName[12] != ptr[12]) ||
+	   (ModelName[13] != ptr[13]))
+	{
+		isModelNameOK = FAIL;
+	}
+
 
     if(isModelNameOK == FAIL)
     {
@@ -1096,14 +1113,18 @@ int Check_CCS_image_header(unsigned int Type,char *SourcePath,char *ModelName)
     ImageLen = read(fd,ptr,MaxLen);
     close(fd);
     //read out the header
-    int i;
     int isModelNameOK = PASS;
-	for(i=0;i<16;i++)
+
+    if((ModelName[0] != ptr[0]) ||
+	   (ModelName[1] != ptr[1]) ||
+	   (ModelName[7] != ptr[7]) ||
+	   (ModelName[8] != ptr[8]) ||
+	   (ModelName[9] != ptr[9]) ||
+	   (ModelName[11] != ptr[11]) ||
+	   (ModelName[12] != ptr[12]) ||
+	   (ModelName[13] != ptr[13]))
 	{
-		if(ModelName[i] != ptr[i])
-		{
-			isModelNameOK = FAIL;
-		}
+		isModelNameOK = FAIL;
 	}
 
 	if(isModelNameOK == FAIL)

+ 6 - 2
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.16","2021-01-13"};
+char *Version_And_Date[2]		= {"V0.17","2021-03-15"};
 int protocol_Version [] 		= {0,7,0};
 
 int StoreLogMsg(const char *fmt, ...)
@@ -782,6 +782,7 @@ int setWPAconf()
 					strcat(buffer, "network={\n    ssid=\"");
 					strcat(buffer, (char*)Wifi_A.ssid);
 					strcat(buffer, "\"\n    key_mgmt=WPA-EAP WPA-PSK \n");
+					strcat(buffer, "    bgscan=\"simple:10:-65:60\" \n");
 					strcat(buffer, "    psk=\"");
 					strcat(buffer, (char*)Wifi_A.passwd);
 					strcat(buffer, "\"\n}\n\n");
@@ -795,12 +796,14 @@ int setWPAconf()
 					strcat(buffer, "    wep_key0=\"");
 					strcat(buffer, (char*)Wifi_A.passwd);
 					strcat(buffer, "\"\n    auth_alg=OPEN SHARED\n");
+					strcat(buffer, "    bgscan=\"simple:10:-65:60\"\n");
 					strcat(buffer, "\n}\n\n");
 				}
 
 				strcat(buffer, "network={\n    ssid=\"");
 				strcat(buffer, (char*)Wifi_A.ssid);
 				strcat(buffer, "\"\n    key_mgmt=NONE");
+				strcat(buffer, "\n    bgscan=\"simple:10:-65:60\"");
 				strcat(buffer, "\n}");
 			}
 			else
@@ -808,6 +811,7 @@ int setWPAconf()
 				strcat(buffer, "network={\n    ssid=\"");
 				strcat(buffer, (char*)Wifi_A.ssid);
 				strcat(buffer, "\"\n    key_mgmt=NONE");
+				strcat(buffer, "\n    bgscan=\"simple:10:-65:60\"");
 				strcat(buffer, "\n}");
 			}
 
@@ -4513,7 +4517,7 @@ void proc_sta()
 				ShmSysConfigAndInfo->SysConfig.AthInterface.WifiNetworkConn=0;
 				cnt_pingDNS_Fail = 0;
 
-				DEBUG_INFO("Ping DNS failed...");
+				DEBUG_INFO("Ping DNS failed...\n");
 				memset(ShmSysConfigAndInfo->SysConfig.AthInterface.WifiSubmaskAddress, 0, sizeof ShmSysConfigAndInfo->SysConfig.AthInterface.WifiSubmaskAddress);
 				memset(ShmSysConfigAndInfo->SysConfig.AthInterface.WifiGatewayAddress, 0, sizeof ShmSysConfigAndInfo->SysConfig.AthInterface.WifiGatewayAddress);
 				memset(ShmSysConfigAndInfo->SysConfig.AthInterface.WifiMacAddress, 0, sizeof ShmSysConfigAndInfo->SysConfig.AthInterface.WifiMacAddress);

+ 4 - 4
EVSE/Modularization/WebService.c

@@ -193,16 +193,16 @@ int ConnectorType(char* connector){
 	if(strcmp(connector, "0") == 0){
 		result= 0;
 	}
-	else if(strcmp(connector, "U") == 0 || strcmp(connector, "E") == 0){
+	else if(strcmp(connector, "U") == 0 || strcmp(connector, "V") == 0 || strcmp(connector, "E") == 0 || strcmp(connector, "F") == 0 || strcmp(connector, "T") == 0 || strcmp(connector, "D") == 0 || strcmp(connector, "M") == 0 || strcmp(connector, "N") == 0 || strcmp(connector, "P") == 0 || strcmp(connector, "R") == 0){
 		result= 1;//CCS
 	}
-	else if(strcmp(connector, "G") == 0 || strcmp(connector, "D") == 0){
+	else if(strcmp(connector, "G") == 0){
 		result= 2;//GB
 	}
-	else if(strcmp(connector, "J") == 0){
+	else if(strcmp(connector, "J") == 0 || strcmp(connector, "K") == 0){
 		result= 3;//CHAdeMO
 	}
-	else if(strcmp(connector, "1") == 0 || strcmp(connector, "2") == 0 || strcmp(connector, "3") == 0 || strcmp(connector, "4") == 0 || strcmp(connector, "5") == 0 || strcmp(connector, "6") == 0){
+	else if(strcmp(connector, "1") == 0 || strcmp(connector, "2") == 0 || strcmp(connector, "3") == 0 || strcmp(connector, "4") == 0 || strcmp(connector, "5") == 0 || strcmp(connector, "6") == 0 || strcmp(connector, "7") == 0 || strcmp(connector, "8") == 0){
 		result= 4;//AC
 	}
 	else{

+ 100 - 0
EVSE/Modularization/ocpp20/MessageHandler.c

@@ -16538,6 +16538,106 @@ int GetInternetConn(void)
 	return ShmSysConfigAndInfo->SysInfo.InternetConn;
 }
 
+int isConnectorInitMode(int gun_index)
+{
+	int tempIndex = 0;
+	int result = TRUE;
+
+	//J: CHAdeMO  U: CCS1 combo  E: CCS2 combo  G: GBT DCcc
+	if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
+	{
+		if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
+		{
+			tempIndex = ((gun_index==2) ? 1: 0);
+		}
+		else
+		{
+			tempIndex = gun_index;
+		}
+
+		for (int index = 0; index < CHAdeMO_QUANTITY; index++)
+		{
+			if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
+			{
+				result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
+			} //end of the same index
+		}//end of for CHAdeMO_QUANTITY
+
+	}
+	else if(gunType[gun_index] == GUN_TYPE_CCS)
+	{
+		if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
+		{
+			tempIndex = ((gun_index==2) ? 1: 0);
+		}
+		else
+		{
+			tempIndex = gun_index;
+		}
+
+		for (int index = 0; index < CCS_QUANTITY; index++)
+		{
+			if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
+			{
+				result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
+			} //end of the same index
+		} // end of for CCS_QUANTITY
+	}
+	else if(gunType[gun_index] == GUN_TYPE_GBT)
+	{
+		if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
+		{
+			tempIndex = ((gun_index==2) ? 1: 0);
+		}
+		else
+		{
+			tempIndex = gun_index;
+		}
+
+		for (int index = 0; index < GB_QUANTITY; index++)
+		{
+			if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
+			{
+				result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
+			} //end of the same index
+		} // end of for GB_QUANTITY
+	}
+	else if(gunType[gun_index] == GUN_TYPE_DO)
+	{
+		tempIndex = gun_index;
+
+		for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
+		{
+			if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
+			{
+				result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
+			} //end of the same index
+		}
+	}
+	else
+	{
+		if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
+		{
+			tempIndex = 2;
+		}
+		else
+		{
+			tempIndex = gun_index;
+		}
+
+		for (int index = 0; index < AC_QUANTITY; index++)
+		{
+			if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
+			{
+				result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
+			}//end of the same index
+
+		}//end of for AC_QUANTITY
+	}
+
+	return result;
+}
+
 void InitialSystemValue(void)
 {
 	int connectorIndex = 0;

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

@@ -1005,6 +1005,7 @@ void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart
 void splitstring(char *src,const char *separator,char **dest,int *num);
 int GetWebSocketPingInterval(void);
 int GetInternetConn(void);
+int isConnectorInitMode(int gun_index);
 int GetServerSign(void);
 void SetServerSign(int value);
 int GetBootNotificationInterval(void);

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

@@ -1182,6 +1182,7 @@ int main(void)
 		{
 			// Sign in
 			if((GetServerSign() == FALSE) &&
+			   (isConnectorInitMode(0) != TRUE) &&
 			   ((GetBootNotificationInterval() >= 0) && ((time((time_t*)NULL)-startTime.bootNotification)>= GetBootNotificationInterval())))
 			{
 				sendBootNotificationRequest();

+ 100 - 0
EVSE/Modularization/ocppfiles/MessageHandler.c

@@ -16595,6 +16595,106 @@ int GetInternetConn(void)
 	return ShmSysConfigAndInfo->SysInfo.InternetConn;
 }
 
+int isConnectorInitMode(int gun_index)
+{
+	int tempIndex = 0;
+	int result = TRUE;
+
+	//J: CHAdeMO  U: CCS1 combo  E: CCS2 combo  G: GBT DCcc
+	if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
+	{
+		if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
+		{
+			tempIndex = ((gun_index==2) ? 1: 0);
+		}
+		else
+		{
+			tempIndex = gun_index;
+		}
+
+		for (int index = 0; index < CHAdeMO_QUANTITY; index++)
+		{
+			if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
+			{
+				result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
+			} //end of the same index
+		}//end of for CHAdeMO_QUANTITY
+
+	}
+	else if(gunType[gun_index] == GUN_TYPE_CCS)
+	{
+		if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
+		{
+			tempIndex = ((gun_index==2) ? 1: 0);
+		}
+		else
+		{
+			tempIndex = gun_index;
+		}
+
+		for (int index = 0; index < CCS_QUANTITY; index++)
+		{
+			if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
+			{
+				result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
+			} //end of the same index
+		} // end of for CCS_QUANTITY
+	}
+	else if(gunType[gun_index] == GUN_TYPE_GBT)
+	{
+		if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
+		{
+			tempIndex = ((gun_index==2) ? 1: 0);
+		}
+		else
+		{
+			tempIndex = gun_index;
+		}
+
+		for (int index = 0; index < GB_QUANTITY; index++)
+		{
+			if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
+			{
+				result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
+			} //end of the same index
+		} // end of for GB_QUANTITY
+	}
+	else if(gunType[gun_index] == GUN_TYPE_DO)
+	{
+		tempIndex = gun_index;
+
+		for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
+		{
+			if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
+			{
+				result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
+			} //end of the same index
+		}
+	}
+	else
+	{
+		if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
+		{
+			tempIndex = 2;
+		}
+		else
+		{
+			tempIndex = gun_index;
+		}
+
+		for (int index = 0; index < AC_QUANTITY; index++)
+		{
+			if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
+			{
+				result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
+			}//end of the same index
+
+		}//end of for AC_QUANTITY
+	}
+
+	return result;
+}
+
 void InitialSystemValue(void)
 {
 	int connectorIndex = 0;

+ 1 - 0
EVSE/Modularization/ocppfiles/MessageHandler.h

@@ -551,6 +551,7 @@ void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart
 void splitstring(char *src,const char *separator,char **dest,int *num);
 int GetWebSocketPingInterval(void);
 int GetInternetConn(void);
+int isConnectorInitMode(int gun_index);
 int GetServerSign(void);
 void SetServerSign(int value);
 int GetBootNotificationInterval(void);

+ 1 - 0
EVSE/Modularization/ocppfiles/Module_OcppBackend.c

@@ -1496,6 +1496,7 @@ int main(void)
 		{
 			// Sign in
 			if((GetServerSign() == FALSE) &&
+			   (isConnectorInitMode(0) != TRUE) &&
 			   ( ((GetBootNotificationInterval() != 0)  && ((time((time_t*)NULL)-startTime.bootNotification)>= GetBootNotificationInterval())) || ((time((time_t*)NULL)-startTime.bootNotification) >= defaultWaitingTime) ) )
 			{
 				sendBootNotificationRequest();

+ 1 - 1
EVSE/Projects/AW-CCS/Apps/Module_Debug.c

@@ -62,7 +62,7 @@ int StoreLogMsg(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/SystemLog/[%04d.%02d]Module_Debug",
+	sprintf(Buf,"echo -n \"[%04d.%02d.%02d %02d:%02d:%02d.%06ld]%s\" >> /Storage/SystemLog/[%04d.%02d]Module_DebugLog",
 				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);

BIN
EVSE/Projects/AW-CCS/Apps/Module_PowerSharing


+ 282 - 287
EVSE/Projects/AW-CCS/Apps/Module_PowerSharing.c

@@ -103,21 +103,21 @@ int isValidCheckSum(struct Message *message)
 {
 	uint8_t chksum = 0x00;
 
-	for(int idx=0;idx<(((message->buffer[2]) | message->buffer[3]<<8)>ARRAY_SIZE(message->buffer)?ARRAY_SIZE(message->buffer):((message->buffer[2]) | message->buffer[3]<<8));idx++)
+	for(int idx=0;idx<((message->buffer[1]+3)>ARRAY_SIZE(message->buffer)?ARRAY_SIZE(message->buffer):(message->buffer[1]+3));idx++)
 	{
-		chksum ^= message->buffer[4+idx];
+		chksum ^= message->buffer[idx];
 	}
 
-	return ((chksum == message->buffer[4+((message->buffer[2] | message->buffer[3]<<8)>ARRAY_SIZE(message->buffer)?ARRAY_SIZE(message->buffer):(message->buffer[2] | message->buffer[3]<<8))]) ? PASS : FAIL);
+	return ((chksum == message->buffer[((message->buffer[1]+3)>ARRAY_SIZE(message->buffer)?ARRAY_SIZE(message->buffer):(message->buffer[1]+3))]) ? PASS : FAIL);
 }
 
 uint8_t chksumCal(struct Message *message)
 {
 	uint8_t chksum=0;
 
-	for(int idx=0;idx<(((message->buffer[2]) | message->buffer[3]<<8)>ARRAY_SIZE(message->buffer)?ARRAY_SIZE(message->buffer):((message->buffer[2]) | message->buffer[3]<<8));idx++)
+	for(int idx=0;idx<((message->buffer[1]+3)>ARRAY_SIZE(message->buffer)?ARRAY_SIZE(message->buffer):(message->buffer[1]+3));idx++)
 	{
-		chksum ^= message->buffer[4+idx];
+		chksum ^= message->buffer[idx];
 	}
 
 	return chksum & 0xff;
@@ -206,77 +206,6 @@ int InitShareMemory()
     return result;
 }
 
-//==========================================
-// UDP socket server routine
-//==========================================
-int udpSocketServerStart(void)
-{
-	int sockFd;
-	struct sockaddr_in servaddr;
-	struct sockaddr_in peeraddr;
-	socklen_t 			peerlen = sizeof(peeraddr);
-	uint8_t 			inputBuffer[2048] = {};
-	uint8_t 			outBuffer[2048] = {};
-	int16_t				read_size;
-	int16_t				tx_size;
-
-	memset(&servaddr, 0, sizeof(servaddr));
-	servaddr.sin_family = AF_INET;
-	servaddr.sin_port = htons(LISTEN_PORT_UDP);
-	servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
-
-	if ((sockFd = socket(PF_INET, SOCK_DGRAM, 0)) < 0)
-	{
-		DEBUG_ERROR("UDP server socket create fail.\n");
-		return FAIL;
-	}
-
-	if (bind(sockFd, (struct sockaddr *)&servaddr, sizeof(servaddr)) < 0)
-	{
-		DEBUG_ERROR("UDP server socket bind fail.\n");
-	    return FAIL;
-	}
-	else
-		DEBUG_INFO("UDP server initial.\n");
-
-	for(;;)
-	{
-		if((read_size = recvfrom(sockFd, inputBuffer, sizeof(inputBuffer), 0, (struct sockaddr *)&peeraddr, &peerlen)) > 0)
-		{
-			DEBUG_INFO("Revieve from: %s:%d\n", inet_ntoa(peeraddr.sin_addr), htons(peeraddr.sin_port));
-			DEBUG_INFO("read_size: %d\n",read_size);
-			dM(inputBuffer, read_size, YES);
-
-			if(read_size>=6)
-			{
-				/*
-				 *	TODO:
-				 *	1. Protocol validation
-				 *	2. Protocol message parsing
-				 */
-
-				if(TRUE)
-				{
-					DEBUG_INFO("Receive UDP broadcast command.\n");
-					memset(outBuffer, 0x00, ARRAY_SIZE(outBuffer));
-					tx_size = 41;
-
-					outBuffer[0] = 0xff;
-					outBuffer[1] = 0xff;
-					outBuffer[2] = (0x25 << 0x08) & 0xff;
-					outBuffer[3] = 0x25 & 0xff;
-					outBuffer[4] = 0x00;
-
-					dM(outBuffer, tx_size, NO);
-					sendto(sockFd, outBuffer, tx_size, 0, (struct sockaddr *)&peeraddr, peerlen);
-				}
-			}
-		}
-	}
-
-	return FAIL;
-}
-
 //==========================================
 // TCP socket server routine
 //==========================================
@@ -286,7 +215,7 @@ int conn_getDupFd(void)
 
 	for(uint8_t idx=0;idx<CONNECTION_LIMIT;idx++)
 	{
-		if(!ShmPowerSharing->Connection_Info[idx].isConnected)
+		if(!ShmPowerSharing->Connection_Info[idx].isSocketConnected)
 		{
 			result = ShmPowerSharing->Connection_Info[idx].socketFd;
 			break;
@@ -302,10 +231,10 @@ int conn_register(int socketFd)
 
 	for(uint8_t idx=0;idx<CONNECTION_LIMIT;idx++)
 	{
-		if(!ShmPowerSharing->Connection_Info[idx].isConnected)
+		if(!ShmPowerSharing->Connection_Info[idx].isSocketConnected)
 		{
 			DEBUG_INFO("Dupfd-%d register to conn-%d.\n", socketFd, idx);
-			ShmPowerSharing->Connection_Info[idx].isConnected = TRUE;
+			ShmPowerSharing->Connection_Info[idx].isSocketConnected = TRUE;
 			ShmPowerSharing->Connection_Info[idx].socketFd = socketFd;
 			ShmPowerSharing->Connection_Info[idx].lastHeartBeatTime = time((time_t*)NULL);
 			result = PASS;
@@ -325,8 +254,8 @@ int conn_reject(int socketFd)
 		if(ShmPowerSharing->Connection_Info[idx].socketFd == socketFd)
 		{
 			DEBUG_INFO("Dupfd-%d register from conn_info-%d.\n", socketFd, idx);
-			ShmPowerSharing->Connection_Info[idx].isConnected = FALSE;
-			ShmPowerSharing->Connection_Info[idx].isCharging = FALSE;
+			ShmPowerSharing->Connection_Info[idx].isSocketConnected = FALSE;
+			ShmPowerSharing->Connection_Info[idx].isGunConnected = FALSE;
 			result = PASS;
 			break;
 		}
@@ -342,7 +271,7 @@ int conn_getConectedQuantity(void)
 
 	for(uint8_t idx=0;idx<CONNECTION_LIMIT;idx++)
 	{
-		if(ShmPowerSharing->Connection_Info[idx].isConnected)
+		if(ShmPowerSharing->Connection_Info[idx].isSocketConnected)
 		{
 			result += 1;
 		}
@@ -353,64 +282,66 @@ int conn_getConectedQuantity(void)
 	return result;
 }
 
-int conn_getChargingQuantity(void)
+int conn_updateHeartBeatTime(int socketFd)
 {
-	int result = 0;
+	int result = FAIL;
 
 	for(uint8_t idx=0;idx<CONNECTION_LIMIT;idx++)
 	{
-		if(ShmPowerSharing->Connection_Info[idx].isCharging)
+		if(ShmPowerSharing->Connection_Info[idx].socketFd == socketFd)
 		{
-			result += 1;
+			//DEBUG_INFO("Dupfd-%d register from conn_info-%d update heart beat time.\n", socketFd, idx);
+			ShmPowerSharing->Connection_Info[idx].lastHeartBeatTime = time((time_t*)NULL);
+			result = PASS;
+			break;
 		}
 	}
 
-	//DEBUG_INFO("Charging quantity: %d\n", result);
 	return result;
 }
 
-int conn_getTotalAvailableSharingCurrent(void)
+int conn_getStatusStarttime(int socketFd)
 {
 	int result = 0;
 
 	for(uint8_t idx=0;idx<CONNECTION_LIMIT;idx++)
 	{
-		if(ShmPowerSharing->Connection_Info[idx].isConnected)
+		if(ShmPowerSharing->Connection_Info[idx].socketFd == socketFd)
 		{
-			result += ShmPowerSharing->Connection_Info[idx].availableSharingCurrent;
+			result = ShmPowerSharing->Connection_Info[idx].lastGetStatusTime;
+			break;
 		}
 	}
 
-	DEBUG_INFO("Total sharing current: %d\n", result);
 	return result;
 }
 
-int conn_getTotalPresentOutputCurrent(void)
+int conn_getStatusStarttimeUpdate(int socketFd)
 {
-	int result = 0;
+	int result = FAIL;
 
 	for(uint8_t idx=0;idx<CONNECTION_LIMIT;idx++)
 	{
-		if(ShmPowerSharing->Connection_Info[idx].isConnected && ShmPowerSharing->Connection_Info[idx].isCharging)
+		if(ShmPowerSharing->Connection_Info[idx].socketFd == socketFd)
 		{
-			result += ShmPowerSharing->Connection_Info[idx].presentOutputCurrent;
+			ShmPowerSharing->Connection_Info[idx].lastGetStatusTime = time((time_t*)NULL);;
+			result = PASS;
+			break;
 		}
 	}
 
-	DEBUG_INFO("Total actual current: %d\n", result);
 	return result;
 }
 
-uint16_t conn_querySharingCurrent(int socketFd)
+int conn_setCapacityStarttime(int socketFd)
 {
-	uint16_t result = 0x00;
+	int result = 0;
 
 	for(uint8_t idx=0;idx<CONNECTION_LIMIT;idx++)
 	{
 		if(ShmPowerSharing->Connection_Info[idx].socketFd == socketFd)
 		{
-			//DEBUG_INFO("Dupfd-%d on conn_info-%d query sharing current(0.1A): %d\n", socketFd, idx, ShmPowerSharing->Connection_Info[idx].sharingCurrent);
-			result = ShmPowerSharing->Connection_Info[idx].availableSharingCurrent;
+			result = ShmPowerSharing->Connection_Info[idx].lastSetCapacityTime;
 			break;
 		}
 	}
@@ -418,7 +349,7 @@ uint16_t conn_querySharingCurrent(int socketFd)
 	return result;
 }
 
-int conn_updateHeartBeatTime(int socketFd)
+int conn_setCapacityStarttimeUpdate(int socketFd)
 {
 	int result = FAIL;
 
@@ -426,8 +357,7 @@ int conn_updateHeartBeatTime(int socketFd)
 	{
 		if(ShmPowerSharing->Connection_Info[idx].socketFd == socketFd)
 		{
-			//DEBUG_INFO("Dupfd-%d register from conn_info-%d update heart beat time.\n", socketFd, idx);
-			ShmPowerSharing->Connection_Info[idx].lastHeartBeatTime = time((time_t*)NULL);
+			ShmPowerSharing->Connection_Info[idx].lastSetCapacityTime = time((time_t*)NULL);;
 			result = PASS;
 			break;
 		}
@@ -436,16 +366,33 @@ int conn_updateHeartBeatTime(int socketFd)
 	return result;
 }
 
-int conn_updatePresentCurrentOutput(int socketFd, uint8_t isCharging, uint16_t outputCurrent)
+int conn_update_status(int socketFd, uint8_t pilotState, uint8_t availableCurrent, uint8_t presentCurrent, uint16_t acPhase)
 {
 	int result = FAIL;
 	for(uint8_t idx=0;idx<CONNECTION_LIMIT;idx++)
 	{
 		if(ShmPowerSharing->Connection_Info[idx].socketFd == socketFd)
 		{
-			//DEBUG_INFO("Dupfd-%d on conn_info-%d update actual output current(0.1A): %d\n", socketFd, idx, outputCurrent);
-			ShmPowerSharing->Connection_Info[idx].isCharging = isCharging;
-			ShmPowerSharing->Connection_Info[idx].presentOutputCurrent = outputCurrent;
+			if(!ShmPowerSharing->Connection_Info[idx].isGunConnected &&
+			   (2<=pilotState) &&
+			   (pilotState<=7))
+			{
+				ShmPowerSharing->hasNewConn = YES;
+			}
+
+			if((ShmPowerSharing->Connection_Info[idx].isGunConnected != (2<=pilotState)&&(pilotState<=7)?YES:NO) ||
+			   (ShmPowerSharing->Connection_Info[idx].presentOutputCurrent != presentCurrent) ||
+			   (ShmPowerSharing->Connection_Info[idx].acPhase != acPhase))
+			{
+				DEBUG_INFO("Connection-%d pilot state: %d \n", idx, pilotState);
+				DEBUG_INFO("Connection-%d available current: %d \n", idx, availableCurrent);
+				DEBUG_INFO("Connection-%d preset output current: %d \n", idx, presentCurrent);
+				DEBUG_INFO("Connection-%d ac power phase: %d \n", idx, acPhase);
+			}
+
+			ShmPowerSharing->Connection_Info[idx].isGunConnected = (2<=pilotState)&&(pilotState<=7)?YES:NO;
+			ShmPowerSharing->Connection_Info[idx].presentOutputCurrent = presentCurrent;
+			ShmPowerSharing->Connection_Info[idx].acPhase = acPhase;
 			result = PASS;
 		}
 	}
@@ -453,48 +400,54 @@ int conn_updatePresentCurrentOutput(int socketFd, uint8_t isCharging, uint16_t o
 	return result;
 }
 
-int conn_check_loop(void)
+int conn_getOnHandCurrent(void)
 {
-	for(;;)
+	int result = 0;
+
+	for(uint8_t idx=0;idx<CONNECTION_LIMIT;idx++)
 	{
-		// Check conn heart beat
-		for(uint8_t idx=0;idx<CONNECTION_LIMIT;idx++)
+		if(ShmPowerSharing->Connection_Info[idx].isSocketConnected)
 		{
-			if(ShmPowerSharing->Connection_Info[idx].isConnected &&
-			   (difftime(time((time_t*)NULL), ShmPowerSharing->Connection_Info[idx].lastHeartBeatTime) > 300))
-			{
-				DEBUG_INFO("SocketFd-%d heart beat is over 300 seconds.\n", ShmPowerSharing->Connection_Info[idx].socketFd);
-				ShmPowerSharing->Connection_Info[idx].isCharging = FALSE;
-				ShmPowerSharing->Connection_Info[idx].isConnected = FALSE;
-			}
+			result += ShmPowerSharing->Connection_Info[idx].availableSharingCurrent;
 		}
+	}
 
-		// Check available power
-		for(uint8_t idx=0;idx<CONNECTION_LIMIT;idx++)
+	result = ShmCharger->gun_info[0].primaryMcuState.rating_current - result;
+
+	DEBUG_INFO("Total on hand available current: %d\n", result);
+	return result;
+}
+
+void create_cmd_getStatus(struct Message *out)
+{
+	memset(out->buffer, 0, ARRAY_SIZE(out->buffer));
+
+	out->size = 4;
+	out->buffer[0] = 0x55;
+	out->buffer[1] = 0x00;
+	out->buffer[2] = SHARING_CMD_GET_STATUS;
+	out->buffer[3] = chksumCal(out);
+
+	dM(out->buffer, out->size, FALSE);
+}
+
+void create_cmd_SetAvailableCurrent(struct Message *out, int socketFd)
+{
+	memset(out->buffer, 0, ARRAY_SIZE(out->buffer));
+
+	out->size = 5;
+	out->buffer[0] = 0x55;
+	out->buffer[1] = 0x01;
+	out->buffer[2] = SHARING_CMD_SET_CAPACITY;
+	for(uint8_t idx=0;idx<CONNECTION_LIMIT;idx++)
+	{
+		if(ShmPowerSharing->Connection_Info[idx].socketFd == socketFd)
 		{
-			if(ShmPowerSharing->Connection_Info[idx].isConnected &&
-			   ShmPowerSharing->Connection_Info[idx].isCharging)
-			{
-				if(ShmPowerSharing->Connection_Info[idx].availableSharingCurrent != ((ShmCharger->gun_info[0].primaryMcuState.rating_current*10) / conn_getChargingQuantity()))
-				{
-					DEBUG_INFO("Dupfd-%d on conn_info-%d update sharing current(0.1A): %d\n", ShmPowerSharing->Connection_Info[idx].socketFd, idx, ((ShmCharger->gun_info[0].primaryMcuState.rating_current*10) / conn_getChargingQuantity()));
-				}
-				ShmPowerSharing->Connection_Info[idx].availableSharingCurrent = (ShmCharger->gun_info[0].primaryMcuState.rating_current*10) / conn_getChargingQuantity();
-			}
-			else
-			{
-				if(ShmPowerSharing->Connection_Info[idx].availableSharingCurrent != 0)
-				{
-					DEBUG_INFO("Dupfd-%d on conn_info-%d update sharing current(0.1A): 0\n", ShmPowerSharing->Connection_Info[idx].socketFd, idx);
-				}
-				ShmPowerSharing->Connection_Info[idx].availableSharingCurrent = 0;
-			}
+			out->buffer[3] = ShmPowerSharing->Connection_Info[idx].availableSharingCurrent;
 		}
-
-		sleep(1);
 	}
-
-	return FAIL;
+	out->buffer[4] = chksumCal(out);
+	dM(out->buffer, out->size, FALSE);
 }
 
 int tcpSocketServerStart(void)
@@ -506,7 +459,6 @@ int tcpSocketServerStart(void)
 	struct Message		output;
 	struct sockaddr_in 	serverInfo, clientInfo;
 	socklen_t 			addrlen = sizeof(clientInfo);
-	uint16_t 			sharingCurrent=0;
 
 	sockFd = socket(AF_INET , SOCK_STREAM , 0);
 	if(sockFd == -1)
@@ -544,92 +496,88 @@ int tcpSocketServerStart(void)
 				// Fork a child process to handle the new conn
 				if(fork()==0)
 				{
+					uint8_t idxStep = 0;
+					uint8_t socketEnable = YES;
+					struct timeval	tv;
+					tv.tv_sec = 0;
+					tv.tv_usec = 500000;
+					setsockopt(clientSockFd, SOL_SOCKET, SO_RCVTIMEO, (const char*)&tv, sizeof tv);
 					// Assign socket handle as available handle in conn info pool
 					dupFd = dup2(clientSockFd, conn_getDupFd());
 					conn_register(dupFd);
-					while((input.size = recv(dupFd, input.buffer, sizeof(input.buffer), 0)) > 0)
-					{
-						dM(input.buffer, input.size, YES);
 
-						if(isValidCheckSum(&input))
+					while(socketEnable)
+					{
+						if((input.size = recv(dupFd, input.buffer, sizeof(input.buffer), 0)) > 0)
 						{
-							conn_updateHeartBeatTime(dupFd);
+							dM(input.buffer, input.size, YES);
 
-							memset(output.buffer, 0x00, ARRAY_SIZE(output.buffer));
-							switch(input.buffer[1])
+							if(isValidCheckSum(&input))
 							{
-								case SHARING_CMD_QUERY_SHARING:
-									sharingCurrent = conn_querySharingCurrent(dupFd);
-									output.size = 7;
-									output.buffer[0] = 0xaa;
-									output.buffer[1] = SHARING_CMD_QUERY_SHARING;
-									output.buffer[2] = 0x02;
-									output.buffer[3] = 0x00;
-									output.buffer[4] = ((sharingCurrent>>0) & 0xff);
-									output.buffer[5] = ((sharingCurrent>>8) & 0xff);
-									output.buffer[6] = chksumCal(&output);
-									break;
+								conn_updateHeartBeatTime(dupFd);
 
-								case SHARING_CMD_SYNC_INFO:
-									conn_updatePresentCurrentOutput(dupFd, input.buffer[4], (input.buffer[5] | (input.buffer[6]<<0x08)));
-									output.size = 6;
-									output.buffer[0] = 0xaa;
-									output.buffer[1] = SHARING_CMD_SYNC_INFO;
-									output.buffer[2] = 0x01;
-									output.buffer[3] = 0x00;
-									output.buffer[4] = 0x01;
-									output.buffer[5] = chksumCal(&output);
+								memset(output.buffer, 0x00, ARRAY_SIZE(output.buffer));
+								switch(input.buffer[2])
+								{
+									case SHARING_CMD_GET_STATUS:
+										conn_update_status(dupFd, input.buffer[3], input.buffer[4], input.buffer[5], input.buffer[6]);
 
-									break;
+										break;
 
-								default:
-									DEBUG_WARN("Receive unknown command.\n");
-									output.size = 5;
-									output.buffer[0] = 0xaa;
-									output.buffer[1] = SHARING_CMD_UNKNOWN;
-									output.buffer[2] = 0x00;
-									output.buffer[3] = 0x00;
-									output.buffer[4] = chksumCal(&output);
+									case SHARING_CMD_SET_CAPACITY:
+										if(!input.buffer[3])
+											DEBUG_INFO("Set connection-%d available current fail \n");
+										break;
 
-									break;
+									default:
+										DEBUG_WARN("Receive unknown command.\n");
+										break;
+								}
+							}
+							else
+							{
+								DEBUG_WARN("Receive command check sum error.\n");
 							}
 						}
-						else
+						else if(input.size == 0)
 						{
-							DEBUG_WARN("Receive command check sum error.\n");
-							output.size = 5;
-							output.buffer[0] = 0xaa;
-							output.buffer[1] = SHARING_CMD_CHKSUM_ERROR;
-							output.buffer[2] = 0x00;
-							output.buffer[3] = 0x00;
-							output.buffer[4] = chksumCal(&output);
+							DEBUG_INFO("Client disSocketConnected.\n");
+							conn_reject(dupFd);
+							socketEnable = NO;
+							close(dupFd);
+							close(clientSockFd);
+							fflush(stdout);
+						}
+						else if(input.size == -1)
+						{
+							// Server slave handler
+							switch(idxStep)
+							{
+								case 0:
+									if(difftime(time((time_t*)NULL), conn_getStatusStarttime(dupFd)) >= 3)
+									{
+										create_cmd_getStatus(&output);
+										conn_getStatusStarttimeUpdate(dupFd);
+										send(clientSockFd, output.buffer, output.size, 0);
+									}
+
+									idxStep++;
+									break;
+								default:
+									if((difftime(time((time_t*)NULL), conn_setCapacityStarttime(dupFd)) >= 1))
+									{
+										create_cmd_SetAvailableCurrent(&output, dupFd);
+										conn_setCapacityStarttimeUpdate(dupFd);
+										send(clientSockFd, output.buffer, output.size, 0);
+									}
+
+									idxStep = 0;
+									break;
+							}
 						}
-
-						dM(output.buffer, output.size, NO);
-						send(clientSockFd, output.buffer, output.size, 0);
-					}
-
-					if(input.size == 0)
-					{
-						DEBUG_INFO("Client disconnected.\n");
-
-						conn_reject(dupFd);
-						close(dupFd);
-						close(clientSockFd);
-						fflush(stdout);
-					}
-					else if(input.size == -1)
-					{
-						DEBUG_ERROR("Socket recv failed.\n");
-
-						conn_reject(dupFd);
-						close(dupFd);
-						close(clientSockFd);
-						fflush(stdout);
 					}
 
 					conn_getConectedQuantity();
-
 					exit(0);
 				}
 				else
@@ -641,12 +589,11 @@ int tcpSocketServerStart(void)
 			else
 			{
 				DEBUG_WARN("Connection is over limit.\n");
-				output.size = 5;
-				output.buffer[0] = 0xaa;
-				output.buffer[1] = SHARING_CMD_CONNECTION_FULL;
-				output.buffer[2] = 0x00;
-				output.buffer[3] = 0x00;
-				output.buffer[4] = chksumCal(&output);
+				output.size = 4;
+				output.buffer[0] = 0x55;
+				output.buffer[1] = 0x00;
+				output.buffer[2] = SHARING_CMD_CONNECTION_FULL;
+				output.buffer[3] = chksumCal(&output);
 				send(clientSockFd, output.buffer, output.size, 0);
 				close(clientSockFd);
 			}
@@ -661,36 +608,6 @@ int tcpSocketServerStart(void)
 //==========================================
 // Client routine
 //==========================================
-void create_cmd_sync(struct Message *out)
-{
-	memset(out->buffer, 0, ARRAY_SIZE(out->buffer));
-
-	out->size = 8;
-	out->buffer[0] = 0xaa;
-	out->buffer[1] = SHARING_CMD_SYNC_INFO;
-	out->buffer[2] = 0x03;
-	out->buffer[3] = 0x00;
-	out->buffer[4] = (ShmSysConfigAndInfo->SysInfo.AcChargingData[0].SystemStatus == SYS_MODE_CHARGING?YES:NO);
-	out->buffer[5] = (((uint16_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[0].PresentChargingCurrent*10))>>0) & 0xff;
-	out->buffer[6] = (((uint16_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[0].PresentChargingCurrent*10))>>8) & 0xff;
-	out->buffer[7] = chksumCal(out);
-
-	dM(out->buffer, out->size, FALSE);
-}
-
-void create_cmd_query(struct Message *out)
-{
-	memset(out->buffer, 0, ARRAY_SIZE(out->buffer));
-
-	out->size = 5;
-	out->buffer[0] = 0xaa;
-	out->buffer[1] = SHARING_CMD_QUERY_SHARING;
-	out->buffer[2] = 0x00;
-	out->buffer[3] = 0x00;
-	out->buffer[4] = chksumCal(out);
-	dM(out->buffer, out->size, FALSE);
-}
-
 int tcpSocketClientStart(void)
 {
 	int 				sockfd;
@@ -702,8 +619,6 @@ int tcpSocketClientStart(void)
 	struct Message		input;
 	struct Message		output;
 
-	uint8_t				cmdIdx;
-
 	bzero(&info,sizeof(info));
 	ghbn = gethostbyname((char*)"192.168.10.10");
 	info.sin_family = PF_INET;
@@ -732,6 +647,7 @@ int tcpSocketClientStart(void)
 		tv.tv_usec = 500000;
 		setsockopt(sockfd, SOL_SOCKET, SO_RCVTIMEO, (const char*)&tv, sizeof tv);
 		socketEnable = ON;
+		ShmSysConfigAndInfo->SysInfo.localSharingInfo.isConnectedSharingServer = ON;
 	}
 
 	while(socketEnable)
@@ -740,64 +656,154 @@ int tcpSocketClientStart(void)
 		if((input.size = recv(sockfd, input.buffer, ARRAY_SIZE(input.buffer), 0)) > 0)
 		{
 			//DEBUG_INFO("Receive size: %d.\n", input.size);
-			dM(input.buffer, input.size, TRUE);
+			dM(input.buffer, input.size, YES);
 
 			if(isValidCheckSum(&input))
 			{
-				switch(input.buffer[1])
+				switch(input.buffer[2])
 				{
-					case SHARING_CMD_QUERY_SHARING:
-						if(ShmSysConfigAndInfo->SysInfo.localSharingInfo.AvailableShargingCurrent != ((input.buffer[4] | (input.buffer[5] << 8))/10))
-						{
-							ShmSysConfigAndInfo->SysInfo.localSharingInfo.AvailableShargingCurrent = ((input.buffer[4] | (input.buffer[5] << 8))/10);
-							DEBUG_INFO("Update available sharing current(A): %d\n", ShmSysConfigAndInfo->SysInfo.localSharingInfo.AvailableShargingCurrent);
-						}
-						ShmSysConfigAndInfo->SysInfo.localSharingInfo.isConnectedSharingServer = ON;
+					case SHARING_CMD_GET_STATUS:
+						output.size = 8;
+						output.buffer[0] = 0x55;
+						output.buffer[1] = 0x04;
+						output.buffer[2] = input.buffer[2];
+						output.buffer[3] = ShmSysConfigAndInfo->SysInfo.AcChargingData[0].PilotState;
+						output.buffer[4] = ShmSysConfigAndInfo->SysInfo.localSharingInfo.AvailableShargingCurrent;
+						output.buffer[5] = ShmSysConfigAndInfo->SysInfo.AcChargingData[0].PresentChargingCurrent;
+						output.buffer[6] = ShmSysConfigAndInfo->SysConfig.AcPhaseCount;
+						output.buffer[7] = chksumCal(&output);
 
 						break;
 
-					case SHARING_CMD_SYNC_INFO:
-						if(!input.buffer[4])
-							DEBUG_INFO("Charger status sync reject.\n");
-
+					case SHARING_CMD_SET_CAPACITY:
+						output.size = 5;
+						output.buffer[0] = 0x55;
+						output.buffer[1] = 0x01;
+						output.buffer[2] = input.buffer[2];
+						output.buffer[3] = 0x01;
+						output.buffer[4] = chksumCal(&output);
+						if(ShmSysConfigAndInfo->SysInfo.localSharingInfo.AvailableShargingCurrent != input.buffer[3])
+						{
+							ShmSysConfigAndInfo->SysInfo.localSharingInfo.AvailableShargingCurrent = input.buffer[3];
+							DEBUG_INFO("Get available current from server: %d\n", ShmSysConfigAndInfo->SysInfo.localSharingInfo.AvailableShargingCurrent);
+						}
 						break;
 
 					default:
 						DEBUG_WARN("Receive unknown command.\n");
+						output.size = 4;
+						output.buffer[0] = 0x55;
+						output.buffer[1] = 0x00;
+						output.buffer[2] = SHARING_CMD_UNKNOWN;
+						output.buffer[3] = chksumCal(&output);
 						break;
 				}
 			}
 			else
 			{
 				DEBUG_WARN("Receive command check sum error.\n");
+				output.size = 4;
+				output.buffer[0] = 0x55;
+				output.buffer[1] = 0x00;
+				output.buffer[2] = SHARING_CMD_CHKSUM_ERROR;
+				output.buffer[3] = chksumCal(&output);
 			}
+
+			dM(output.buffer, output.size, NO);
+			send(sockfd, output.buffer, output.size, 0);
 		}
 		else if(input.size == 0)
 		{
-			DEBUG_INFO("Disconnected.\n");
+			DEBUG_INFO("DisSocketConnected.\n");
 			fflush(stdout);
 
 			socketEnable = OFF;
 			ShmSysConfigAndInfo->SysInfo.localSharingInfo.isConnectedSharingServer = OFF;
 		}
 		else if(input.size == -1)
+		{}
+		usleep(1000000);
+	}
+	close(sockfd);
+
+	return FAIL;
+}
+
+//==========================================
+// Local loading balance check
+//==========================================
+int balance_check_loop(void)
+{
+	for(;;)
+	{
+		// Check conn heart beat
+		for(uint8_t idx=0;idx<CONNECTION_LIMIT;idx++)
 		{
-			switch(cmdIdx)
+			if(ShmPowerSharing->Connection_Info[idx].isSocketConnected &&
+			   (difftime(time((time_t*)NULL), ShmPowerSharing->Connection_Info[idx].lastHeartBeatTime) > 300))
 			{
-				case 0:
-					create_cmd_sync(&output);
-					cmdIdx += 1;
-					break;
-				default:
-					create_cmd_query(&output);
-					cmdIdx = 0;
-					break;
+				DEBUG_INFO("SocketFd-%d heart beat is over 300 seconds.\n", ShmPowerSharing->Connection_Info[idx].socketFd);
+				ShmPowerSharing->Connection_Info[idx].isGunConnected = FALSE;
+				ShmPowerSharing->Connection_Info[idx].isSocketConnected = FALSE;
 			}
-			send(sockfd, output.buffer, output.size, 0);
 		}
-		usleep(1000000);
+
+		// Check available power
+		if(ShmPowerSharing->hasNewConn)
+		{
+			DEBUG_INFO("New connection gun connected and re-allocate available current to each connection.\n");
+
+			for(uint8_t idx=0;idx<CONNECTION_LIMIT;idx++)
+			{
+				if(ShmPowerSharing->Connection_Info[idx].isSocketConnected &&
+				   ShmPowerSharing->Connection_Info[idx].isGunConnected)
+				{
+					ShmPowerSharing->Connection_Info[idx].availableSharingCurrent = 6;
+				}
+				else
+				{
+					ShmPowerSharing->Connection_Info[idx].availableSharingCurrent = 0;
+				}
+			}
+
+			ShmPowerSharing->hasNewConn = NO;
+		}
+
+		for(uint8_t idx=0;idx<CONNECTION_LIMIT;idx++)
+		{
+			if(ShmPowerSharing->Connection_Info[idx].isSocketConnected &&
+			   ShmPowerSharing->Connection_Info[idx].isGunConnected)
+			{
+				if((difftime(time((time_t*)NULL), ShmPowerSharing->Connection_Info[idx].lastCheckCapacityTime) > 10))
+				{
+					if(ShmPowerSharing->Connection_Info[idx].availableSharingCurrent >= (ShmPowerSharing->Connection_Info[idx].presentOutputCurrent+2))
+					{
+						if(ShmPowerSharing->Connection_Info[idx].availableSharingCurrent >= 8)
+							ShmPowerSharing->Connection_Info[idx].availableSharingCurrent -= 2;
+					}
+					else if(((ShmPowerSharing->Connection_Info[idx].presentOutputCurrent-1) < ShmPowerSharing->Connection_Info[idx].availableSharingCurrent) &&
+							(ShmPowerSharing->Connection_Info[idx].availableSharingCurrent < (ShmPowerSharing->Connection_Info[idx].presentOutputCurrent+1)) &&
+							(conn_getOnHandCurrent() > 2))
+					{
+						ShmPowerSharing->Connection_Info[idx].availableSharingCurrent += 2;
+					}
+					else
+					{}
+					ShmPowerSharing->Connection_Info[idx].lastCheckCapacityTime = time((time_t*)NULL);
+				}
+			}
+			else
+			{
+				if(ShmPowerSharing->Connection_Info[idx].availableSharingCurrent != 0)
+				{
+					DEBUG_INFO("Dupfd-%d on conn_info-%d update sharing current(A): 0\n", ShmPowerSharing->Connection_Info[idx].socketFd, idx);
+				}
+				ShmPowerSharing->Connection_Info[idx].availableSharingCurrent = 0;
+			}
+		}
+
+		sleep(1);
 	}
-	close(sockfd);
 
 	return FAIL;
 }
@@ -826,17 +832,6 @@ int main(void)
 	if((ShmCharger->gun_info[0].primaryMcuState.rotatory_switch != SWITCH_F_SLAVE) &&
 	   (AC_QUANTITY==1?TRUE:(ShmCharger->gun_info[1].primaryMcuState.rotatory_switch != SWITCH_F_SLAVE)))
 	{
-		// UDP socket server start
-		/*
-		if(fork() == 0)
-		{
-			if(udpSocketServerStart() == FAIL)
-			{
-				DEBUG_ERROR("UDP socket server down.\n");
-				return 0;
-			}
-		}*/
-
 		// TCP socket server start
 		if(fork() == 0)
 		{
@@ -850,9 +845,9 @@ int main(void)
 		// Connection check loop
 		if(fork() == 0)
 		{
-			if(conn_check_loop() == FAIL)
+			if(balance_check_loop() == FAIL)
 			{
-				DEBUG_ERROR("Connection check loop fail.\n");
+				DEBUG_ERROR("Local loading balance check loop fail.\n");
 				return 0;
 			}
 		}

+ 15 - 10
EVSE/Projects/AW-CCS/Apps/Module_PowerSharing.h

@@ -57,11 +57,10 @@
 #define true			    		1
 #define false						0
 
-#define LISTEN_PORT_UDP				8421
-#define LISTEN_PORT_TCP				8422
-#define	CONNECTION_LIMIT			8
+#define LISTEN_PORT_TCP				118
+#define	CONNECTION_LIMIT			5
 
-#define ShmPowerShargingKey			LISTEN_PORT_TCP
+#define ShmPowerShargingKey			LISTEN_PORT_TCP+8000
 
 enum ROTARY_SWITCH_LIMIT
 {
@@ -85,8 +84,8 @@ enum ROTARY_SWITCH_LIMIT
 
 enum SHARING_COMMAND
 {
-	SHARING_CMD_QUERY_SHARING=0x01,
-	SHARING_CMD_SYNC_INFO=0x81,
+	SHARING_CMD_GET_STATUS=0x01,
+	SHARING_CMD_SET_CAPACITY=0x02,
 	SHARING_CMD_CONNECTION_FULL=0xfd,
 	SHARING_CMD_CHKSUM_ERROR=0xfe,
 	SHARING_CMD_UNKNOWN=0xff
@@ -101,19 +100,25 @@ struct Message
 struct CONNECTION_INFO
 {
 	int 		socketFd;					// Socket file description
-	uint16_t	availableSharingCurrent;	// Each connection available sharing current, resolution: 0.1A
-	uint16_t	presentOutputCurrent;		// Each connection preset output current, resolution: 0.1A
+	uint16_t	availableSharingCurrent;	// Each connection available sharing current, resolution: 1A
+	uint16_t	presentOutputCurrent;		// Each connection preset output current, resolution: 1A
+	uint8_t		acPhase;					// Each connection ac power phase
 	uint16_t	SOC;						// Each connection preset SOC, resolution: 0.1%
 	uint16_t	remindTime;					// Each connection remind charging time, resolution: 1min
 	time_t		lastHeartBeatTime;			// Each connection latest get heart beat start time
-	uint8_t		isConnected:1;				// Each connection connected flag
-	uint8_t 	isCharging:1;				// Each connection charging state flag
+	time_t		lastGetStatusTime;			// Each connection latest get status start time
+	time_t		lastSetCapacityTime;		// Each connection latest set capacity start time
+	time_t		lastCheckCapacityTime;		// Each connection latest check capacity start time
+	uint8_t		isSocketConnected:1;		// Each connection socket connected flag
+	uint8_t		isGunConnected:1;			// Each connection gun connected flag
 };
 
 struct POWER_SHARING
 {
 	uint8_t					connectedQty;
+	uint16_t				onHandCurrent;
 	struct CONNECTION_INFO	Connection_Info[CONNECTION_LIMIT];
+	uint8_t					hasNewConn:1;
 };
 
 #endif /* MODULE_POWERSHARING_H_ */

+ 3 - 2
EVSE/Projects/AW-CCS/Apps/main.c

@@ -2122,7 +2122,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.47.00.0000.00");
+	sprintf((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev, "D0.48.00.0000.00");
 
 	// Get AC connector type from model name
 	for(uint8_t idx=0;idx<3;idx++)
@@ -3021,7 +3021,8 @@ void checkTask()
 		system ("/root/Module_LcmControl &");
 	}
 
-	if(system("pidof -s Module_PowerSharing > /dev/null") != 0)
+	if((system("pidof -s Module_PowerSharing > /dev/null") != 0) &&
+		ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharging)
 	{
 		DEBUG_INFO("Module_PowerSharing not running, restart it.\n");
 		system ("/root/Module_PowerSharing &");

+ 1 - 1
EVSE/Projects/AW-Regular/Apps/Module_Debug.c

@@ -62,7 +62,7 @@ int StoreLogMsg(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/SystemLog/[%04d.%02d]Module_Debug",
+	sprintf(Buf,"echo -n \"[%04d.%02d.%02d %02d:%02d:%02d.%06ld]%s\" >> /Storage/SystemLog/[%04d.%02d]Module_DebugLog",
 				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);

+ 1 - 1
EVSE/Projects/AW-Regular/Apps/Module_InternalComm.c

@@ -79,7 +79,7 @@ int StoreLogMsg(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/SystemLog/[%04d.%02d]Module_InterComm",
+	sprintf(Buf,"echo -n \"[%04d.%02d.%02d %02d:%02d:%02d.%06ld]%s\" >> /Storage/SystemLog/[%04d.%02d]Module_InterCommLog",
 				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);

+ 5 - 2
EVSE/Projects/AW-Regular/Apps/main.c

@@ -2028,7 +2028,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.66.00.0000.00");
+	sprintf((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev, "V0.67.00.0000.00");
 
 	// Get AC connector type from model name
 	for(uint8_t idx=0;idx<3;idx++)
@@ -3741,6 +3741,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");
 					}
@@ -4480,7 +4483,7 @@ int main(void)
 								ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
 								DEBUG_WARN("Firmware upgrade fail.\n");
 								
-								sleep(1);
+								sleep(5);
 								system("rm -rvf /mnt/* ");
 								close(wtdFd);
 								system("/usr/bin/run_evse_restart.sh");

BIN
EVSE/Projects/AW-Regular/Images/FactoryDefaultConfig.bin


BIN
EVSE/Projects/AW-Regular/Images/ramdisk.gz


+ 1 - 1
EVSE/Projects/Noodoe/Apps/Module_Debug.c

@@ -60,7 +60,7 @@ int StoreLogMsg(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/SystemLog/[%04d.%02d]Module_Debug",
+	sprintf(Buf,"echo -n \"[%04d.%02d.%02d %02d:%02d:%02d.%06ld]%s\" >> /Storage/SystemLog/[%04d.%02d]Module_DebugLog",
 				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);

+ 1 - 1
EVSE/Projects/Noodoe/Apps/Module_InternalComm.c

@@ -79,7 +79,7 @@ int StoreLogMsg(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/SystemLog/[%04d.%02d]Module_InterComm",
+	sprintf(Buf,"echo -n \"[%04d.%02d.%02d %02d:%02d:%02d.%06ld]%s\" >> /Storage/SystemLog/[%04d.%02d]Module_InterCommLog",
 				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);

+ 2 - 2
EVSE/Projects/Noodoe/Apps/main.c

@@ -1288,7 +1288,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.50.00.0000.00");
+	sprintf((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev, "V0.51.00.0000.00");
 
 	// Get AC connector type from model name
 	for(uint8_t idx=0;idx<3;idx++)
@@ -3684,7 +3684,7 @@ int main(void)
 								ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
 								DEBUG_WARN("Firmware upgrade fail.\n");
 								
-								sleep(1);
+								sleep(5);
 								system("rm -rvf /mnt/* ");
 								close(wtdFd);
 								system("/usr/bin/run_evse_restart.sh");

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


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


+ 1 - 0
EVSE/Projects/define.h

@@ -463,6 +463,7 @@ struct SysConfigData
 	struct LED				LedInfo;					// LED configuration info
 	unsigned char			ShowInformation;
 	unsigned char           isReqFirstUpgrade;          //EVSE is request first upgrade from PH server
+	unsigned char			isEnableLocalPowerSharging; //0: Disable power sharing	1: Enable power sharing
 };
 
 struct ChargingInfoData

+ 4 - 0
EVSE/rootfs/bin/flash_eraseall

@@ -0,0 +1,4 @@
+#!/bin/sh
+echo "${0##*/} has been replaced by \`flash_erase <mtddev> 0 0\`; please use it" 1>&2
+[ $# -ne 0 ] && set -- "$@" 0 0
+exec flash_erase "$@"

+ 14 - 1
EVSE/rootfs/etc/init.d/rcS

@@ -35,7 +35,20 @@ mount -a
 mount -t tmpfs tmpfs /mnt
 
 chmod 777 /Storage
-mount -t jffs2 /dev/mtdblock13 /Storage
+#mount -t jffs2 /dev/mtdblock13 /Storage
+ubiattach /dev/ubi_ctrl -m 13
+if [ "$?" -eq "0" ]
+then
+   echo "Success."
+else
+   echo "Erase /dev/mtd13 jffs2 block"
+   flash_eraseall /dev/mtd13
+   ubiattach /dev/ubi_ctrl -m 13
+fi
+
+ubimkvol /dev/ubi0 -N ubiNandFs -m
+mount -t ubifs ubi0:ubiNandFs /Storage
+
 mkdir -p /Storage/EventLog
 mkdir -p /Storage/ChargeLog
 mkdir -p /Storage/SystemLog

+ 1 - 1
EVSE/rootfs/etc/logrotate.d/evse

@@ -1,6 +1,6 @@
 /Storage/**/*Log /Storage/**/*.log{
 	weekly
-        rotate 24
+        rotate 10
 	size 10M
         missingok
         compress

BIN
EVSE/rootfs/root/OcppBackend20


BIN
EVSE/rootfs/root/wpa_supplicant


+ 28 - 0
EVSE/rootfs/usr/bin/run_log_clear.sh

@@ -0,0 +1,28 @@
+#!/bin/sh
+if [ $# -lt 2 ]; then
+        echo "Usage:  run_log_clear.sh [start month before] [end month before]"
+        echo "        start month >= 6 at least"
+        echo "        end month > start month"
+        echo "Sample: run_log_clear.sh 6 12 "
+        echo "        (Clear log before now 6 to 12 month)"
+        exit 0;
+else
+        if [ "$2" -lt "$1" ]
+        then
+                echo "Usage:  run_log_clear.sh [start month before] [end month before]"
+                echo "        start month >= 6 at least"
+                echo "        end month > start month"
+                exit 0
+        fi
+
+        for idx in $(seq $1 $2)
+        do
+                now=$(( `date +%s`-(($idx*30)*86400)))
+                target=`date -D '%s' +%Y.%m -d "$now"`
+                echo $target
+                `/bin/rm -f /Storage/System/[$target\]*`
+                `/bin/rm -f /Storage/OCPP/[$target\]*`
+        done
+
+fi
+

+ 16 - 0
EVSE/rootfs/usr/bin/run_scan_net.sh

@@ -0,0 +1,16 @@
+#!/bin/sh
+if [ $# -lt 2 ]; then
+        echo "Usage sample:  run_scan_net.sh [interface] [scan class C]"
+        echo "               run_scan_net.sh eth0 192.168.1"
+        exit 0;
+else
+        for ip in $(seq 1 255)
+        do
+                echo Scan ip $2.$ip
+                `arp -i $1 -d $2.$ip > /dev/null 2>&1`
+                `ping -I $1 -c 5 $2.$ip > /dev/null 2>&1 &`
+        done
+
+        wait
+        arp -n | grep -v incomplete
+fi

+ 1 - 0
EVSE/rootfs/var/spool/cron/crontabs/root

@@ -23,3 +23,4 @@
 0 0 * * * cat "" > /Storage/SystemLog/check_tmate.log
 #* * * * * /usr/bin/check_tmate.sh >> /Storage/SystemLog/check_tmate.log 2>&1
 0 * * * * /sbin/logrotate /etc/logrotate.conf
+0 1 * * * /usr/bin/run_log_clear.sh 6 18

+ 8 - 3
EVSE/rootfs/var/www/head.php

@@ -43,7 +43,7 @@
 	}
 	$model=json_decode(trim($output[0]))->{'ModelName'};
 	if(substr($model,0,1)=="A"){
-		if(substr($model,10,1)=="E" || substr($model,10,1)=="W" || substr($model,10,1)=="T" || substr($model,10,1)=="U"){
+		if(substr($model,10,1)=="E" || substr($model,10,1)=="W" || substr($model,10,1)=="T" || substr($model,10,1)=="U" || substr($model,10,1)=="D" || substr($model,10,1)=="A" || substr($model,10,1)=="F"){
 			$ModelName='AC Net';
 		}
 		else if(substr($model,10,1)=="0" || substr($model,10,1)=="R" || substr($model,10,1)=="B"){
@@ -57,7 +57,7 @@
 			$ModelName='DC';
 		}
 	}
-	if(substr($model,10,1)=="E"){
+	if(substr($model,10,1)=="E" || substr($model,10,1)=="U"){
 		$showEthernet="block";
 		$showWifi="none";
 		$showTelcom="none";
@@ -72,11 +72,16 @@
 		$showWifi="none";
 		$showTelcom="block";
 	}
-	if(substr($model,10,1)=="D"){
+	if(substr($model,10,1)=="D" || substr($model,10,1)=="A"){
 		$showEthernet="block";
 		$showWifi="block";
 		$showTelcom="block";
 	}
+	if(substr($model,10,1)=="F"){
+		$showEthernet="none";
+		$showWifi="block";
+		$showTelcom="none";
+	}
 	
 	//$ModelName='AC Net';
 	 //$ModelName='AC Eco';

+ 4 - 4
EVSE/rootfs/var/www/set_charging.php

@@ -492,16 +492,16 @@
 		if($connector == "0"){
 			$result= "";
 		}
-		else if($connector == "U" || $connector == "E"){
+		else if($connector == "U" || $connector == "V" || $connector == "E" || $connector == "F" || $connector == "T" || $connector == "D" || $connector == "M" || $connector == "N" || $connector == "P" || $connector == "R"){
 			$result= "CCS";
 		}
-		else if($connector == "G" || $connector == "D"){
+		else if($connector == "G"){
 			$result= "GB";
 		}
-		else if($connector == "J"){
+		else if($connector == "J" || $connector == "K"){
 			$result= "CHAdeMO";
 		}
-		else if($connector == "1" || $connector == "2" || $connector == "3" || $connector == "4" || $connector == "5" || $connector == "6"){
+		else if($connector == "1" || $connector == "2" || $connector == "3" || $connector == "4" || $connector == "5" || $connector == "6" || $connector == "7" || $connector == "8"){
 			$result= "AC";
 		}
 		else{

+ 4 - 4
EVSE/rootfs/var/www/set_system.php

@@ -35,16 +35,16 @@
 		if($connector == "0"){
 			$result= "";
 		}
-		else if($connector == "U" || $connector == "E"){
+		else if($connector == "U" || $connector == "V" || $connector == "E" || $connector == "F" || $connector == "T" || $connector == "D" || $connector == "M" || $connector == "N" || $connector == "P" || $connector == "R"){
 			$result= "CCS";
 		}
-		else if($connector == "G" || $connector == "D"){
+		else if($connector == "G"){
 			$result= "GB";
 		}
-		else if($connector == "J"){
+		else if($connector == "J" || $connector == "K"){
 			$result= "CHAdeMO";
 		}
-		else if($connector == "1" || $connector == "2" || $connector == "3" || $connector == "4" || $connector == "5" || $connector == "6"){
+		else if($connector == "1" || $connector == "2" || $connector == "3" || $connector == "4" || $connector == "5" || $connector == "6" || $connector == "7" || $connector == "8"){
 			$result= "AC";
 		}
 		else{