Browse Source

Merge branch 'master' into DD360Audi

Jerry_Wang 3 years ago
parent
commit
8f41f96039
82 changed files with 3866 additions and 1374 deletions
  1. 131 439
      EVSE/GPL/curl-7.37.1/config.log
  2. 3 1
      EVSE/GPL/curl-7.37.1/config.status
  3. BIN
      EVSE/GPL/curl-7.37.1/lib/.libs/libcurl.a
  4. BIN
      EVSE/GPL/curl-7.37.1/lib/.libs/libcurl.so.4.3.0
  5. 4 4
      EVSE/GPL/curl-7.37.1/lib/curl_config.h
  6. BIN
      EVSE/GPL/curl-7.37.1/release/bin/curl
  7. BIN
      EVSE/GPL/curl-7.37.1/release/lib/libcurl.a
  8. BIN
      EVSE/GPL/curl-7.37.1/release/lib/libcurl.so.4.3.0
  9. BIN
      EVSE/GPL/curl-7.37.1/src/.libs/curl
  10. 2 2
      EVSE/GPL/curl-7.37.1/src/tool_hugehelp.c
  11. 193 0
      EVSE/Modularization/DcMeter/Module_DcMeter.c
  12. 57 0
      EVSE/Modularization/DcMeter/Module_DcMeter.h
  13. 66 0
      EVSE/Modularization/DcMeter/SystemLogMessage.c
  14. 10 0
      EVSE/Modularization/DcMeter/SystemLogMessage.h
  15. 405 0
      EVSE/Modularization/DcMeter/curlApi.c
  16. 28 0
      EVSE/Modularization/DcMeter/curlApi.h
  17. 222 0
      EVSE/Modularization/DcMeter/meterComm.c
  18. 63 0
      EVSE/Modularization/DcMeter/meterComm.h
  19. 9 3
      EVSE/Modularization/Makefile
  20. 85 6
      EVSE/Modularization/Module_EventLogging.c
  21. 14 5
      EVSE/Modularization/ocpp20/MessageHandler.c
  22. 9 5
      EVSE/Modularization/ocppfiles/MessageHandler.c
  23. 28 28
      EVSE/Projects/AW-CCS/Apps/LCM/Module_LcmControl.c
  24. 5 0
      EVSE/Projects/AW-CCS/Apps/LCM/lcmComm_dgus.h
  25. 3 2
      EVSE/Projects/AW-CCS/Apps/Makefile
  26. 56 20
      EVSE/Projects/AW-CCS/Apps/Module_AlarmDetect.c
  27. 83 1
      EVSE/Projects/AW-CCS/Apps/Module_ConfigTools.c
  28. 296 183
      EVSE/Projects/AW-CCS/Apps/Module_InternalComm.c
  29. 382 35
      EVSE/Projects/AW-CCS/Apps/main.c
  30. 2 0
      EVSE/Projects/AW-CCS/Apps/main.h
  31. BIN
      EVSE/Projects/AW-CCS/Images/FactoryDefaultConfig.bin
  32. BIN
      EVSE/Projects/AW-CCS/Images/MLO
  33. BIN
      EVSE/Projects/AW-CCS/Images/am335x-evm.dtb
  34. BIN
      EVSE/Projects/AW-CCS/Images/ramdisk.gz
  35. BIN
      EVSE/Projects/AW-CCS/Images/u-boot-spl.bin
  36. BIN
      EVSE/Projects/AW-CCS/Images/u-boot.img
  37. BIN
      EVSE/Projects/AW-CCS/Images/zImage
  38. 194 16
      EVSE/Projects/DO360/Apps/Config.h
  39. 15 6
      EVSE/Projects/DO360/Apps/FactoryConfig.c
  40. 135 27
      EVSE/Projects/DO360/Apps/Module_EvComm.c
  41. 2 0
      EVSE/Projects/DO360/Apps/Module_EvComm.h
  42. 24 3
      EVSE/Projects/DO360/Apps/Module_EventLogging.c
  43. 2 2
      EVSE/Projects/DO360/Apps/Module_InternalComm.c
  44. 24 0
      EVSE/Projects/DO360/Apps/Module_PsuComm.c
  45. 697 98
      EVSE/Projects/DO360/Apps/ReadCmdline.c
  46. 388 302
      EVSE/Projects/DO360/Apps/main.c
  47. BIN
      EVSE/Projects/DO360/Images/ramdisk.gz
  48. 8 5
      EVSE/Projects/Noodoe/Apps/main.c
  49. 188 158
      EVSE/Projects/define.h
  50. BIN
      EVSE/rootfs/bin/memtester
  51. BIN
      EVSE/rootfs/bin/nandwrite
  52. 3 3
      EVSE/rootfs/etc/init.d/rcS
  53. BIN
      EVSE/rootfs/lib/ld-2.19.so
  54. BIN
      EVSE/rootfs/lib/libBrokenLocale-2.19.so
  55. BIN
      EVSE/rootfs/lib/libanl-2.19.so
  56. BIN
      EVSE/rootfs/lib/libc-2.19.so
  57. BIN
      EVSE/rootfs/lib/libcrypt-2.19.so
  58. BIN
      EVSE/rootfs/lib/libdl-2.19.so
  59. BIN
      EVSE/rootfs/lib/libm-2.19.so
  60. BIN
      EVSE/rootfs/lib/libnsl-2.19.so
  61. BIN
      EVSE/rootfs/lib/libnss_compat-2.19.so
  62. BIN
      EVSE/rootfs/lib/libnss_dns-2.19.so
  63. BIN
      EVSE/rootfs/lib/libnss_files-2.19.so
  64. BIN
      EVSE/rootfs/lib/libpthread-2.19.so
  65. BIN
      EVSE/rootfs/lib/libresolv-2.19.so
  66. BIN
      EVSE/rootfs/lib/librt-2.19.so
  67. BIN
      EVSE/rootfs/lib/libutil-2.19.so
  68. 1 0
      EVSE/rootfs/root/.gitignore
  69. BIN
      EVSE/rootfs/root/Module_Payment
  70. BIN
      EVSE/rootfs/root/OcppBackend20
  71. BIN
      EVSE/rootfs/sbin/tcpdump
  72. 1 1
      EVSE/rootfs/var/www/settings
  73. 1 1
      board-support/linux-4.9.59+gitAUTOINC+a75d8e9305-ga75d8e9305/.tmp_System.map
  74. 1 1
      board-support/linux-4.9.59+gitAUTOINC+a75d8e9305-ga75d8e9305/.tmp_kallsyms1.S
  75. 1 1
      board-support/linux-4.9.59+gitAUTOINC+a75d8e9305-ga75d8e9305/.tmp_kallsyms2.S
  76. 1 1
      board-support/linux-4.9.59+gitAUTOINC+a75d8e9305-ga75d8e9305/.version
  77. 11 8
      board-support/linux-4.9.59+gitAUTOINC+a75d8e9305-ga75d8e9305/arch/arm/boot/dts/.am335x-evm.dtb.dts.tmp
  78. 5 2
      board-support/linux-4.9.59+gitAUTOINC+a75d8e9305-ga75d8e9305/arch/arm/boot/dts/[AW-CCS]am335x-evm.dts
  79. 5 2
      board-support/linux-4.9.59+gitAUTOINC+a75d8e9305-ga75d8e9305/arch/arm/boot/dts/am335x-evm.dts
  80. 1 1
      board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/arch/arm/dts/.am335x-evm.dtb.dts.tmp
  81. 1 1
      board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/arch/arm/dts/[AW-CCS]am335x-evm.dts
  82. 1 1
      board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/arch/arm/dts/am335x-evm.dts

File diff suppressed because it is too large
+ 131 - 439
EVSE/GPL/curl-7.37.1/config.log


+ 3 - 1
EVSE/GPL/curl-7.37.1/config.status

@@ -1143,6 +1143,7 @@ D["TIME_WITH_SYS_TIME"]=" 1"
 D["HAVE_SYS_TYPES_H"]=" 1"
 D["HAVE_SYS_TIME_H"]=" 1"
 D["HAVE_TIME_H"]=" 1"
+D["HAVE_CLOCK_GETTIME_MONOTONIC"]=" 1"
 D["HAVE_ZLIB_H"]=" 1"
 D["HAVE_LIBZ"]=" 1"
 D["CURL_DISABLE_LDAP"]=" 1"
@@ -1169,8 +1170,9 @@ D["HAVE_RAND_EGD"]=" 1"
 D["HAVE_ENGINE_CLEANUP"]=" 1"
 D["HAVE_CRYPTO_CLEANUP_ALL_EX_DATA"]=" 1"
 D["HAVE_SSL_GET_SHUTDOWN"]=" 1"
-D["HAVE_SSLV2_CLIENT_METHOD"]=" 1"
 D["HAVE_SSL_CTX_SET_NEXT_PROTO_SELECT_CB"]=" 1"
+D["HAVE_SSL_CTX_SET_ALPN_PROTOS"]=" 1"
+D["HAVE_SSL_CTX_SET_ALPN_SELECT_CB"]=" 1"
 D["HAVE_SSLEAY_SRP"]=" 1"
 D["STDC_HEADERS"]=" 1"
 D["HAVE_MALLOC_H"]=" 1"

BIN
EVSE/GPL/curl-7.37.1/lib/.libs/libcurl.a


BIN
EVSE/GPL/curl-7.37.1/lib/.libs/libcurl.so.4.3.0


+ 4 - 4
EVSE/GPL/curl-7.37.1/lib/curl_config.h

@@ -122,7 +122,7 @@
 #define HAVE_BOOL_T 1
 
 /* Define to 1 if you have the clock_gettime function and monotonic timer. */
-/* #undef HAVE_CLOCK_GETTIME_MONOTONIC */
+#define HAVE_CLOCK_GETTIME_MONOTONIC 1
 
 /* Define to 1 if you have the closesocket function. */
 /* #undef HAVE_CLOSESOCKET */
@@ -598,13 +598,13 @@
 #define HAVE_SSLEAY_SRP 1
 
 /* Define to 1 if you have the `SSLv2_client_method' function. */
-#define HAVE_SSLV2_CLIENT_METHOD 1
+/* #undef HAVE_SSLV2_CLIENT_METHOD */
 
 /* Define to 1 if you have the `SSL_CTX_set_alpn_protos' function. */
-/* #undef HAVE_SSL_CTX_SET_ALPN_PROTOS */
+#define HAVE_SSL_CTX_SET_ALPN_PROTOS 1
 
 /* Define to 1 if you have the `SSL_CTX_set_alpn_select_cb' function. */
-/* #undef HAVE_SSL_CTX_SET_ALPN_SELECT_CB */
+#define HAVE_SSL_CTX_SET_ALPN_SELECT_CB 1
 
 /* Define to 1 if you have the `SSL_CTX_set_next_proto_select_cb' function. */
 #define HAVE_SSL_CTX_SET_NEXT_PROTO_SELECT_CB 1

BIN
EVSE/GPL/curl-7.37.1/release/bin/curl


BIN
EVSE/GPL/curl-7.37.1/release/lib/libcurl.a


BIN
EVSE/GPL/curl-7.37.1/release/lib/libcurl.so.4.3.0


BIN
EVSE/GPL/curl-7.37.1/src/.libs/curl


+ 2 - 2
EVSE/GPL/curl-7.37.1/src/tool_hugehelp.c

@@ -2,7 +2,7 @@
 #ifndef HAVE_LIBZ
 /*
  * NEVER EVER edit this manually, fix the mkhelp.pl script instead!
- * Generation time: Sat Feb 29 14:44:54 2020
+ * Generation time: Sat Jun  5 10:04:45 2021
  */
 #ifdef USE_MANUAL
 #include "tool_hugehelp.h"
@@ -4207,7 +4207,7 @@ void hugehelp(void) {}
 #else
 /*
  * NEVER EVER edit this manually, fix the mkhelp.pl script instead!
- * Generation time: Sat Feb 29 14:44:54 2020
+ * Generation time: Sat Jun  5 10:04:46 2021
  */
 #ifdef USE_MANUAL
 #include "tool_hugehelp.h"

+ 193 - 0
EVSE/Modularization/DcMeter/Module_DcMeter.c

@@ -0,0 +1,193 @@
+/*
+ * Module_DcMeter.c
+ *
+ *  Created on: 2021/5/31
+ *      Author: foluswen
+ */
+#include "Module_DcMeter.h"
+#include "meterComm.h"
+
+/**
+ * Initial share memory
+ * @return
+ */
+int InitShareMemory()
+{
+	int result = PASS;
+	int MeterSMId;
+
+	//Initialize ShmSysConfigAndInfo
+	if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo),  0777)) < 0)
+    {
+		DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
+		result = FAIL;
+	}
+    else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
+    {
+    	DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
+    	result = FAIL;
+   	 }
+    else
+    {}
+
+   	//Initialize ShmStatusCodeData
+   	if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData),  0777)) < 0)
+    {
+   		DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
+   		result = FAIL;
+	}
+    else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
+    {
+    	DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
+    	result = FAIL;
+   	}
+    else
+    {}
+
+    return result;
+}
+
+//==========================================
+// Main loop
+//==========================================
+int main(void)
+{
+	Meter_Info meter_info;
+	uint8_t pollingIndex = 0;
+	uint8_t failCount = 0;
+
+#ifndef DEBUG_STANDALONG
+	// Initialize share memory
+	if(InitShareMemory() == FAIL)
+	{
+		DEBUG_ERROR("InitShareMemory NG\n");
+
+		if(ShmStatusCodeData!=NULL)
+		{
+			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=ON;
+		}
+		sleep(5);
+		return -1;
+	}
+#endif//DEBUG_STANDALONG
+
+	// Initialize DC meter model
+	/*
+	 *	TODO:
+	 *		1. Maybe need to parse configuration by model name
+	 */
+	meterInitialize(METER_MODEL_LEM_L18005A);
+
+	// Main loop
+	for(;;)
+	{
+		switch(pollingIndex)
+		{
+			case 0:
+				if(readCurrent(&meter_info))
+				{
+#ifndef DEBUG_STANDALONG
+					/*
+					 *	TODO:
+					 *		1. Synchronize data to share memory
+					 */
+#else
+					DEBUG_INFO("Output current: %.3f A\n", meter_info.presentCurrent);
+#endif//DEBUG_STANDALONG
+					pollingIndex++;
+					failCount = 0;
+				}
+				else
+				{
+					if(failCount < 10)
+						failCount++;
+				}
+				break;
+			case 1:
+				if(readVoltage(&meter_info))
+				{
+#ifndef DEBUG_STANDALONG
+					/*
+					 *	TODO:
+					 *		1. Synchronize data to share memory
+					 */
+#else
+					DEBUG_INFO("Output voltage: %.3f V\n", meter_info.presetVoltage);
+#endif//DEBUG_STANDALONG
+					pollingIndex++;
+					failCount = 0;
+				}
+				else
+				{
+					if(failCount < 10)
+						failCount++;
+				}
+				break;
+			case 2:
+				if(readPower(&meter_info))
+				{
+#ifndef DEBUG_STANDALONG
+					/*
+					 *	TODO:
+					 *		1. Synchronize data to share memory
+					 */
+#else
+					DEBUG_INFO("Output power: %.3f kw\n", meter_info.presentPower);
+#endif//DEBUG_STANDALONG
+					pollingIndex++;
+					failCount = 0;
+				}
+				else
+				{
+					if(failCount < 10)
+						failCount++;
+				}
+				break;
+			case 3:
+				if(readEnergy(&meter_info))
+				{
+#ifndef DEBUG_STANDALONG
+					/*
+					 *	TODO:
+					 *		1. Synchronize data to share memory
+					 */
+#else
+					DEBUG_INFO("Totalize import energy: %.3f kwh\n", meter_info.totlizeImportEnergy);
+					DEBUG_INFO("Totalize export energy: %.3f kwh\n", meter_info.totlizeExportEnergy);
+#endif//DEBUG_STANDALONG
+					pollingIndex++;
+					failCount = 0;
+				}
+				else
+				{
+					if(failCount < 10)
+						failCount++;
+				}
+				break;
+			default:
+				pollingIndex = 0;
+				break;
+		}
+
+		if(failCount >= 10)
+		{
+#ifndef DEBUG_STANDALONG
+			if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.MeterCommTimeout)
+			{
+				DEBUG_ERROR("Meter communication timeout");
+				ShmStatusCodeData->AlarmCode.AlarmEvents.bits.MeterCommTimeout = ON;
+			}
+#endif//DEBUG_STANDALONG
+		}
+		else
+		{
+#ifndef DEBUG_STANDALONG
+			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.MeterCommTimeout = OFF;
+#endif//DEBUG_STANDALONG
+		}
+
+		usleep(500000);
+	}
+
+	return -1;
+}

+ 57 - 0
EVSE/Modularization/DcMeter/Module_DcMeter.h

@@ -0,0 +1,57 @@
+/*
+ * Module_DcMeter.h
+ *
+ *  Created on: 2021/5/31
+ *      Author: foluswen
+ */
+
+#ifndef MODULE_DCMETER_H_
+#define MODULE_DCMETER_H_
+#include 	<sys/time.h>
+#include 	<sys/timeb.h>
+#include    <sys/types.h>
+#include    <sys/stat.h>
+#include 	<sys/types.h>
+#include 	<sys/ioctl.h>
+#include 	<sys/socket.h>
+#include 	<sys/ipc.h>
+#include 	<sys/shm.h>
+#include 	<sys/shm.h>
+#include 	<sys/mman.h>
+#include 	<linux/wireless.h>
+#include 	<arpa/inet.h>
+#include 	<netinet/in.h>
+
+#include 	<unistd.h>
+#include 	<stdarg.h>
+#include    <stdio.h>
+#include    <stdlib.h>
+#include    <unistd.h>
+#include    <fcntl.h>
+#include    <termios.h>
+#include    <errno.h>
+#include 	<errno.h>
+#include 	<string.h>
+#include	<time.h>
+#include	<ctype.h>
+#include 	<ifaddrs.h>
+#include    <signal.h>
+#include	"define.h"
+#include 	"SystemLogMessage.h"
+
+#define	DEBUG_STANDALONG
+
+#define ARRAY_SIZE(A)				(sizeof(A) / sizeof(A[0]))
+#define PASS						1
+#define FAIL			   			-1
+#define ON							1
+#define OFF							0
+#define YES							1
+#define NO							0
+#define TRUE			    		1
+#define FALSE						0
+
+struct SysConfigAndInfo			*ShmSysConfigAndInfo;
+struct StatusCodeData 			*ShmStatusCodeData;
+
+#endif /* MODULE_DCMETER_H_ */

+ 66 - 0
EVSE/Modularization/DcMeter/SystemLogMessage.c

@@ -0,0 +1,66 @@
+#include 	<sys/time.h>
+#include 	<sys/timeb.h>
+#include    <sys/types.h>
+#include    <sys/stat.h>
+#include 	<sys/types.h>
+#include 	<sys/ioctl.h>
+#include 	<sys/socket.h>
+#include 	<sys/ipc.h>
+#include 	<sys/shm.h>
+#include 	<sys/shm.h>
+#include 	<sys/mman.h>
+#include 	<linux/wireless.h>
+#include 	<arpa/inet.h>
+#include 	<netinet/in.h>
+
+#include 	<unistd.h>
+#include 	<stdarg.h>
+#include    <stdio.h>
+#include    <stdlib.h>
+#include    <unistd.h>
+#include    <fcntl.h>
+#include    <termios.h>
+#include    <errno.h>
+#include 	<errno.h>
+#include 	<string.h>
+#include	<time.h>
+#include	<ctype.h>
+#include 	<ifaddrs.h>
+#include    <signal.h>
+#include 	"SystemLogMessage.h"
+
+/**
+ * Output debug info
+ * @param fmt
+ * @return
+ */
+int StoreLogMsg(const char *fmt, ...)
+{
+	char Buf[4096+256];
+	char buffer[4096];
+	time_t CurrentTime;
+	struct tm *tm;
+	va_list args;
+
+	va_start(args, fmt);
+	int rc = vsnprintf(buffer, sizeof(buffer), fmt, args);
+	va_end(args);
+
+	memset(Buf,0,sizeof(Buf));
+	CurrentTime = time(NULL);
+	tm=localtime(&CurrentTime);
+	sprintf(Buf,"echo -n \"[%04d.%02d.%02d %02d:%02d:%02d] - %s\" >> /Storage/SystemLog/[%04d.%02d]Module_DcMeterLog",
+			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);
+
+	system(Buf);
+
+
+#ifdef ConsloePrintLog
+	printf("[%04d.%02d.%02d %02d:%02d:%02d] - %s", tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec, buffer);
+#endif
+
+	return rc;
+}
+

+ 10 - 0
EVSE/Modularization/DcMeter/SystemLogMessage.h

@@ -0,0 +1,10 @@
+#ifndef SystemLogMessage_H
+#define SystemLogMessage_H
+
+#define DEBUG_INFO(format, args...) StoreLogMsg("[%s:%d][%s][Info] "format, (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__), __LINE__, __FUNCTION__, ##args)
+#define DEBUG_WARN(format, args...) StoreLogMsg("[%s:%d][%s][Warn] "format, (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__), __LINE__, __FUNCTION__, ##args)
+#define DEBUG_ERROR(format, args...) StoreLogMsg("[%s:%d][%s][Error] "format, (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__), __LINE__, __FUNCTION__, ##args)
+
+extern int StoreLogMsg(const char *fmt, ...);
+
+#endif

+ 405 - 0
EVSE/Modularization/DcMeter/curlApi.c

@@ -0,0 +1,405 @@
+/*
+ * curlApi.c
+ *
+ *  Created on: 2021/6/1
+ *      Author: foluswen
+ */
+#include 	<sys/time.h>
+#include 	<sys/timeb.h>
+#include    <sys/types.h>
+#include    <sys/stat.h>
+#include 	<sys/types.h>
+#include 	<sys/ioctl.h>
+#include 	<sys/socket.h>
+#include 	<sys/ipc.h>
+#include 	<sys/shm.h>
+#include 	<sys/shm.h>
+#include 	<sys/mman.h>
+#include 	<linux/wireless.h>
+#include 	<arpa/inet.h>
+#include 	<netinet/in.h>
+
+#include 	<unistd.h>
+#include 	<stdarg.h>
+#include    <stdio.h>
+#include    <stdlib.h>
+#include    <unistd.h>
+#include    <fcntl.h>
+#include    <termios.h>
+#include    <errno.h>
+#include 	<errno.h>
+#include 	<string.h>
+#include	<time.h>
+#include	<ctype.h>
+#include 	<ifaddrs.h>
+#include    <signal.h>
+#include 	<curl/curl.h>
+#include 	<curl/easy.h>
+#include	"SystemLogMessage.h"
+#include	"curlApi.h"
+
+struct MemoryStruct
+{
+  uint8_t memory[4096];
+  size_t size;
+};
+
+struct MemoryStruct chunk;
+
+/**
+ * HTTP get/post data response callback
+ * @param contents
+ * @param size
+ * @param nmemb
+ * @param userp
+ */
+static size_t WriteMemoryCallback(void *contents, size_t size, size_t nmemb, void *userp)
+{
+	size_t realsize = size*nmemb;
+	struct MemoryStruct *mem = (struct MemoryStruct *)userp;
+
+	mem->size = realsize;;
+
+	memset(mem->memory, 0x00, ARRAY_SIZE(mem->memory));
+	chunk.size = realsize;
+	memcpy(mem->memory, contents, realsize);
+
+	return realsize;
+}
+
+/**
+ * HTTP get request/response
+ * @param url
+ * @param responseData
+ * @return
+ */
+int httpGet(uint8_t *url, uint8_t *responseData)
+{
+	int result = FAIL;
+	CURL *curl;
+	CURLcode res;
+
+	curl_global_init(CURL_GLOBAL_ALL);
+	curl = curl_easy_init();
+
+	if(curl)
+	{
+		 curl_easy_setopt(curl, CURLOPT_URL, (char*)url);
+		 curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteMemoryCallback);
+		 curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&chunk);
+		 //curl_easy_setopt(curl, CURLOPT_USERAGENT, "libcurl-agent/1.0");
+		 //curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, (long)strlen((char*)postData));
+		 curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, FALSE);
+		 //curl_easy_setopt(curl, CURLOPT_HTTPAUTH, (long)CURLAUTH_ANY);
+		 //curl_easy_setopt(curl, CURLOPT_USERPWD, "user:password");
+
+		 res = curl_easy_perform(curl);
+
+		 if(res != CURLE_OK)
+		 {
+			 DEBUG_ERROR("curl_easy_perform() failed: %s\n", curl_easy_strerror(res));
+		 }
+		 else
+		 {
+			 if(chunk.size > 0)
+			 {
+				 //DEBUG_INFO("Response content: %s\n", chunk.memory);
+				 memcpy(responseData, chunk.memory, ARRAY_SIZE(chunk.memory));
+			 }
+
+			 result = PASS;
+		 }
+		 curl_easy_cleanup(curl);
+	}
+	curl_global_cleanup();
+
+	return result;
+}
+
+/**
+ * HTTP post request/response
+ * @param url
+ * @param postData
+ * @return
+ */
+int httpPost(uint8_t *url, uint8_t *postData, uint8_t *responseData)
+{
+	int result = FAIL;
+	CURL *curl;
+	CURLcode res;
+
+	curl_global_init(CURL_GLOBAL_ALL);
+	curl = curl_easy_init();
+
+	if(curl)
+	{
+		 curl_easy_setopt(curl, CURLOPT_URL, (char*)url);
+		 curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteMemoryCallback);
+		 curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&chunk);
+		 //curl_easy_setopt(curl, CURLOPT_USERAGENT, "libcurl-agent/1.0");
+		 curl_easy_setopt(curl, CURLOPT_POSTFIELDS, (char*)postData);
+		 //curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, (long)strlen((char*)postData));
+		 curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, FALSE);
+		 //curl_easy_setopt(curl, CURLOPT_HTTPAUTH, (long)CURLAUTH_ANY);
+		 //curl_easy_setopt(curl, CURLOPT_USERPWD, "user:password");
+
+		 res = curl_easy_perform(curl);
+
+		 if(res != CURLE_OK)
+		 {
+			 DEBUG_ERROR("curl_easy_perform() failed: %s\n", curl_easy_strerror(res));
+		 }
+		 else
+		 {
+			 if(chunk.size > 0)
+			 {
+				 //DEBUG_INFO("Response content: %s\n", chunk.memory);
+				 memcpy(responseData, chunk.memory, ARRAY_SIZE(chunk.memory));
+			 }
+
+			 result = PASS;
+		 }
+		 curl_easy_cleanup(curl);
+	}
+	curl_global_cleanup();
+
+	return result;
+}
+
+/**
+ * HTTP put request
+ * @param url
+ * @param postData
+ * @return
+ */
+int httpPut(uint8_t *url, uint8_t *postData)
+{
+	int result = FAIL;
+	CURL *curl;
+	CURLcode res;
+
+	curl_global_init(CURL_GLOBAL_ALL);
+	curl = curl_easy_init();
+
+	if(curl)
+	{
+		struct curl_slist *headers = NULL;
+		headers = curl_slist_append(headers, "Content-Type: literature/classic");
+		curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
+		curl_easy_setopt(curl, CURLOPT_URL, (char*)url);
+		curl_easy_setopt(curl, CURLOPT_POSTFIELDS, (char*)postData);
+		curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "PUT");
+		curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, FALSE);
+		//curl_easy_setopt(curl, CURLOPT_HTTPAUTH, (long)CURLAUTH_ANY);
+		//curl_easy_setopt(curl, CURLOPT_USERPWD, "user:password");
+
+		res = curl_easy_perform(curl);
+
+		if(res != CURLE_OK)
+		{
+			 DEBUG_ERROR("curl_easy_perform() failed: %s\n", curl_easy_strerror(res));
+		}
+		else
+		{
+			result = PASS;
+		}
+		curl_easy_cleanup(curl);
+		curl_slist_free_all(headers);
+	}
+	curl_global_cleanup();
+
+	return result;
+}
+
+/**
+ * HTTP download response callback
+ * @param ptr
+ * @param size
+ * @param nmemb
+ * @param stream
+ * @return
+ */
+static size_t write_data(void *ptr, size_t size, size_t nmemb, void *stream)
+{
+  size_t written = fwrite(ptr, size, nmemb, (FILE *)stream);
+
+  return written;
+}
+
+/**
+ * Curl download request
+ * @param url
+ * @return
+ */
+int curlDownload(uint8_t *url, uint8_t *filename)
+{
+	int result = FAIL;
+	CURL *curl;
+	CURLcode res;
+	FILE *downloadFile;
+
+	curl_global_init(CURL_GLOBAL_ALL);
+	curl = curl_easy_init();
+
+	if(curl)
+	{
+		curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 30L);
+		curl_easy_setopt(curl, CURLOPT_URL, (char*)url);
+		curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
+		curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, FALSE);
+		//curl_easy_setopt(curl, CURLOPT_HTTPAUTH, (long)CURLAUTH_ANY);
+		//curl_easy_setopt(curl, CURLOPT_USERPWD, "user:password");
+
+		downloadFile = fopen((char*)filename, "wb");
+		if(downloadFile)
+		{
+			curl_easy_setopt(curl, CURLOPT_WRITEDATA, downloadFile);
+		    res = curl_easy_perform(curl);
+		    if(res != CURLE_OK)
+			{
+		    	DEBUG_ERROR("curl_easy_perform() failed: %s\n", curl_easy_strerror(res));
+			}
+			else
+			{
+				//DEBUG_INFO("Download %s success.\n", url);
+				result = PASS;
+			}
+
+		    fclose(downloadFile);
+		}
+		curl_easy_cleanup(curl);
+	}
+	curl_global_cleanup();
+
+	return result;
+}
+
+/**
+ * HTTP upload request
+ * @param url
+ * @param filename
+ * @return
+ */
+int httpUpload(uint8_t *url, uint8_t *filename)
+{
+	int result = FAIL;
+	CURL *curl;
+	CURLcode res;
+	FILE *upFile;
+	struct stat file_info;
+	curl_off_t speed_upload, total_time;
+
+	if((upFile = fopen((char*)filename, "rb")))
+	{
+		if(fstat(fileno(upFile), &file_info) == 0)
+		{
+			curl = curl_easy_init();
+			if(curl)
+			{
+				curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 30L);
+				curl_easy_setopt(curl, CURLOPT_URL, (char*)url);
+				curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L);
+				curl_easy_setopt(curl, CURLOPT_READDATA, upFile);
+				curl_easy_setopt(curl, CURLOPT_INFILESIZE_LARGE, (curl_off_t)file_info.st_size);
+				curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
+				//curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, FALSE);
+				//curl_easy_setopt(curl, CURLOPT_HTTPAUTH, (long)CURLAUTH_ANY);
+				//curl_easy_setopt(curl, CURLOPT_USERPWD, "user:password");
+
+				res = curl_easy_perform(curl);
+				if(res != CURLE_OK)
+				{
+					DEBUG_ERROR("curl_easy_perform() failed: %s\n", curl_easy_strerror(res));
+				}
+				else
+				{
+					curl_easy_getinfo(curl, CURLINFO_SPEED_UPLOAD, &speed_upload);
+					curl_easy_getinfo(curl, CURLINFO_TOTAL_TIME, &total_time);
+					/*DEBUG_INFO("Upload %s to %s success.\n", filename, url);
+					DEBUG_INFO("Speed: %" CURL_FORMAT_CURL_OFF_T " bytes/sec during %"
+					           CURL_FORMAT_CURL_OFF_T ".%06ld seconds\n",
+					           speed_upload,
+					           (total_time / 1000000), (long)(total_time % 1000000));*/
+
+					result = PASS;
+				}
+
+				fclose(upFile);
+
+				curl_easy_cleanup(curl);
+			}
+		}
+	}
+
+	return result;
+}
+
+/**
+ * File read callback
+ * @param ptr
+ * @param size
+ * @param nmemb
+ * @param stream
+ * @return
+ */
+static size_t read_callback(char *ptr, size_t size, size_t nmemb, void *stream)
+{
+  curl_off_t nread;
+  size_t retcode = fread(ptr, size, nmemb, stream);
+  nread = (curl_off_t)retcode;
+
+  DEBUG_INFO("Read %" CURL_FORMAT_CURL_OFF_T " bytes from file\n", nread);
+
+  return retcode;
+}
+/**
+ * FTP upload request
+ * @param url
+ * @param filename
+ * @return
+ */
+int ftpUpload(uint8_t *url, uint8_t *filename)
+{
+	int result = FAIL;
+	CURL *curl;
+	CURLcode res;
+	FILE *upFile;
+	struct stat file_info;
+	curl_off_t fsize;
+
+	curl_global_init(CURL_GLOBAL_ALL);
+	if(!stat((char*)filename, &file_info))
+	{
+		fsize = (curl_off_t)file_info.st_size;
+		DEBUG_INFO("%s size: %" CURL_FORMAT_CURL_OFF_T " bytes.\n", filename, fsize);
+
+		if((upFile = fopen((char*)filename, "rb")))
+		{
+			curl = curl_easy_init();
+			if(curl)
+			{
+				curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 30L);
+				curl_easy_setopt(curl, CURLOPT_READFUNCTION, read_callback);
+				curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L);
+				curl_easy_setopt(curl, CURLOPT_URL, url);
+				curl_easy_setopt(curl, CURLOPT_READDATA, upFile);
+				curl_easy_setopt(curl, CURLOPT_INFILESIZE_LARGE, (curl_off_t)fsize);
+				res = curl_easy_perform(curl);
+				if(res != CURLE_OK)
+				{
+					DEBUG_ERROR("curl_easy_perform() failed: %s\n", curl_easy_strerror(res));
+
+				}
+				else
+				{
+					//DEBUG_INFO("Upload %s success.\n", url);
+				}
+				curl_easy_cleanup(curl);
+			}
+			fclose(upFile);
+		}
+	}
+	curl_global_cleanup();
+
+	return result;
+}

+ 28 - 0
EVSE/Modularization/DcMeter/curlApi.h

@@ -0,0 +1,28 @@
+/*
+ * curlApi.h
+ *
+ *  Created on: 2021/6/1
+ *      Author: foluswen
+ */
+
+#ifndef CURLAPI_H_
+#define CURLAPI_H_
+
+#define ARRAY_SIZE(A)				(sizeof(A) / sizeof(A[0]))
+#define PASS						1
+#define FAIL			   			-1
+#define ON							1
+#define OFF							0
+#define YES							1
+#define NO							0
+#define TRUE			    		1
+#define FALSE						0
+
+extern int httpGet(uint8_t *url, uint8_t *responseData);
+extern int httpPost(uint8_t *url, uint8_t *postData, uint8_t *responseData);
+extern int httpPut(uint8_t *url, uint8_t *postData);
+extern int curlDownload(uint8_t *url, uint8_t *filename);
+extern int httpUpload(uint8_t *url, uint8_t *filename);
+extern int ftpUpload(uint8_t *url, uint8_t *filename);
+
+#endif /* CURLAPI_H_ */

+ 222 - 0
EVSE/Modularization/DcMeter/meterComm.c

@@ -0,0 +1,222 @@
+/*
+ * MeterDriver.c
+ *
+ *  Created on: 2021/6/4
+ *      Author: foluswen
+ */
+#include 	"meterComm.h"
+#include 	"curlApi.h"
+#include 	"SystemLogMessage.h"
+#include	"json-c/json.h"
+
+#define is_error(ptr) 			((unsigned long)ptr > (unsigned long)-4000L)
+
+unsigned char 	meterModel = 0;
+char			meterApiAddress[128];
+
+
+/**
+ * Meter driver initialize
+ * @param model
+ */
+void meterInitialize(uint8_t model)
+{
+	meterModel = model;
+
+	switch(meterModel)
+	{
+		case METER_MODEL_LEM_L18005A:
+		default:
+			/*
+			 * TODO:
+			 * 	1. Check meter actual API address.
+			 */
+			//sprintf(meterApiAddress, "http://192.168.1.2/livemeasure");
+			sprintf(meterApiAddress, "https://foluswen.com/tmate/livemeasure.php"); // Simulator by web server
+
+			break;
+	}
+}
+
+/**
+ * Output voltage read
+ * @param meter_info
+ * @return
+ */
+int readVoltage(Meter_Info *meter_info)
+{
+	int result = FAIL;
+	uint8_t	data[4096];
+
+	switch(meterModel)
+	{
+
+		case METER_MODEL_LEM_L18005A:
+		default:
+			if(httpGet((uint8_t*)meterApiAddress, data))
+			{
+				json_object *livemeasure;
+				livemeasure = json_tokener_parse((char*)data);
+				if(!is_error(livemeasure))
+				{
+					if(json_object_object_get(livemeasure, "voltage") != NULL)
+						meter_info->presetVoltage = json_object_get_double(json_object_object_get(livemeasure, "voltage"));
+
+					if(json_object_object_get(livemeasure, "current") != NULL)
+						meter_info->presentCurrent = json_object_get_double(json_object_object_get(livemeasure, "current"));
+
+					if(json_object_object_get(livemeasure, "power") != NULL)
+						meter_info->presentPower = json_object_get_double(json_object_object_get(livemeasure, "power"));
+
+					if(json_object_object_get(livemeasure, "energyImportTotal") != NULL)
+						meter_info->totlizeImportEnergy = json_object_get_double(json_object_object_get(livemeasure, "energyImportTotal"));
+
+					if(json_object_object_get(livemeasure, "energyExportTotal") != NULL)
+						meter_info->totlizeExportEnergy = json_object_get_double(json_object_object_get(livemeasure, "energyExportTotal"));
+
+					result = PASS;
+				}
+				json_object_put(livemeasure);
+			}
+
+			break;
+	}
+
+	return result;
+}
+
+/**
+ * Output current read
+ * @param meter_info
+ * @return
+ */
+int readCurrent(Meter_Info *meter_info)
+{
+	int result = FAIL;
+	uint8_t	data[4096];
+
+	switch(meterModel)
+	{
+		case METER_MODEL_LEM_L18005A:
+		default:
+			if(httpGet((uint8_t*)meterApiAddress, data))
+			{
+				json_object *livemeasure;
+				livemeasure = json_tokener_parse((char*)data);
+				if(!is_error(livemeasure))
+				{
+					if(json_object_object_get(livemeasure, "voltage") != NULL)
+						meter_info->presetVoltage = json_object_get_double(json_object_object_get(livemeasure, "voltage"));
+
+					if(json_object_object_get(livemeasure, "current") != NULL)
+						meter_info->presentCurrent = json_object_get_double(json_object_object_get(livemeasure, "current"));
+
+					if(json_object_object_get(livemeasure, "power") != NULL)
+						meter_info->presentPower = json_object_get_double(json_object_object_get(livemeasure, "power"));
+
+					if(json_object_object_get(livemeasure, "energyImportTotal") != NULL)
+						meter_info->totlizeImportEnergy = json_object_get_double(json_object_object_get(livemeasure, "energyImportTotal"));
+
+					if(json_object_object_get(livemeasure, "energyExportTotal") != NULL)
+						meter_info->totlizeExportEnergy = json_object_get_double(json_object_object_get(livemeasure, "energyExportTotal"));
+
+					result = PASS;
+				}
+				json_object_put(livemeasure);
+			}
+			break;
+	}
+
+	return result;
+}
+
+/**
+ * Output power read
+ * @param meter_info
+ * @return
+ */
+int readPower(Meter_Info *meter_info)
+{
+	int result = FAIL;
+	uint8_t	data[4096];
+
+	switch(meterModel)
+	{
+		case METER_MODEL_LEM_L18005A:
+		default:
+			if(httpGet((uint8_t*)meterApiAddress, data))
+			{
+				json_object *livemeasure;
+				livemeasure = json_tokener_parse((char*)data);
+				if(!is_error(livemeasure))
+				{
+					if(json_object_object_get(livemeasure, "voltage") != NULL)
+						meter_info->presetVoltage = json_object_get_double(json_object_object_get(livemeasure, "voltage"));
+
+					if(json_object_object_get(livemeasure, "current") != NULL)
+						meter_info->presentCurrent = json_object_get_double(json_object_object_get(livemeasure, "current"));
+
+					if(json_object_object_get(livemeasure, "power") != NULL)
+						meter_info->presentPower = json_object_get_double(json_object_object_get(livemeasure, "power"));
+
+					if(json_object_object_get(livemeasure, "energyImportTotal") != NULL)
+						meter_info->totlizeImportEnergy = json_object_get_double(json_object_object_get(livemeasure, "energyImportTotal"));
+
+					if(json_object_object_get(livemeasure, "energyExportTotal") != NULL)
+						meter_info->totlizeExportEnergy = json_object_get_double(json_object_object_get(livemeasure, "energyExportTotal"));
+
+					result = PASS;
+				}
+				json_object_put(livemeasure);
+			}
+			break;
+	}
+
+	return result;
+}
+
+/**
+ * Export & import totalize energy read
+ * @param meter_info
+ * @return
+ */
+int readEnergy(Meter_Info *meter_info)
+{
+	int result = FAIL;
+	uint8_t	data[4096];
+
+	switch(meterModel)
+	{
+		case METER_MODEL_LEM_L18005A:
+		default:
+			if(httpGet((uint8_t*)meterApiAddress, data))
+			{
+				json_object *livemeasure;
+				livemeasure = json_tokener_parse((char*)data);
+				if(!is_error(livemeasure))
+				{
+					if(json_object_object_get(livemeasure, "voltage") != NULL)
+						meter_info->presetVoltage = json_object_get_double(json_object_object_get(livemeasure, "voltage"));
+
+					if(json_object_object_get(livemeasure, "current") != NULL)
+						meter_info->presentCurrent = json_object_get_double(json_object_object_get(livemeasure, "current"));
+
+					if(json_object_object_get(livemeasure, "power") != NULL)
+						meter_info->presentPower = json_object_get_double(json_object_object_get(livemeasure, "power"));
+
+					if(json_object_object_get(livemeasure, "energyImportTotal") != NULL)
+						meter_info->totlizeImportEnergy = json_object_get_double(json_object_object_get(livemeasure, "energyImportTotal"));
+
+					if(json_object_object_get(livemeasure, "energyExportTotal") != NULL)
+						meter_info->totlizeExportEnergy = json_object_get_double(json_object_object_get(livemeasure, "energyExportTotal"));
+
+					result = PASS;
+				}
+				json_object_put(livemeasure);
+			}
+			break;
+	}
+
+	return result;
+}
+

+ 63 - 0
EVSE/Modularization/DcMeter/meterComm.h

@@ -0,0 +1,63 @@
+/*
+ * meterComm.h
+ *
+ *  Created on: 2021/6/4
+ *      Author: foluswen
+ */
+
+#ifndef HEADER_METERCOMM_H_
+#define HEADER_METERCOMM_H_
+#include 	<sys/time.h>
+#include 	<sys/timeb.h>
+#include    <sys/types.h>
+#include    <sys/stat.h>
+#include 	<sys/types.h>
+#include 	<sys/ioctl.h>
+#include 	<sys/socket.h>
+#include 	<sys/ipc.h>
+#include 	<sys/shm.h>
+#include 	<sys/shm.h>
+#include 	<sys/mman.h>
+#include 	<linux/wireless.h>
+#include 	<arpa/inet.h>
+#include 	<netinet/in.h>
+
+#include 	<unistd.h>
+#include 	<stdarg.h>
+#include    <stdio.h>
+#include    <stdlib.h>
+#include    <unistd.h>
+#include    <fcntl.h>
+#include    <termios.h>
+#include    <errno.h>
+#include 	<errno.h>
+#include 	<string.h>
+#include	<time.h>
+#include	<ctype.h>
+#include 	<ifaddrs.h>
+#include    <signal.h>
+
+typedef struct METER_INFO
+{
+	double presetVoltage;		// resolution: 1v
+	double presentCurrent;		// resolution: 1a
+	double presentPower;		// resolution: 1kw
+	double totlizeImportEnergy;	// resolution: 1kwh
+	double totlizeExportEnergy;	// resolution: 1kwh
+}Meter_Info;
+
+enum METER_MODEL
+{
+	METER_MODEL_LEM_L18005A=0,
+};
+
+extern void meterInitialize(uint8_t model);
+extern int readVoltage(Meter_Info *meter_info);
+extern int readCurrent(Meter_Info *meter_info);
+extern int readPower(Meter_Info *meter_info);
+extern int readEnergy(Meter_Info *meter_info);
+
+extern unsigned char 	meterModel;
+extern char				meterApiAddress[];
+
+#endif /* HEADER_METERCOMM_H_ */

+ 9 - 3
EVSE/Modularization/Makefile

@@ -7,9 +7,8 @@ Lib_SQLite3 = "-L../../../Modularization/ocppfiles" -lsqlite3
 all: clean Module_RFIDLib Module_Wifi WebServiceLib Ocpp16 \
      Phihong_PsuCommObj Module_4g Module_UpgradeLib Infypwr_PsuCommObj \
      Module_EventLogging Module_ProduceUtils Module_PhBackend \
-     Ocpp20 Module_InitUpgrade Module_RatedCurrentLib Module_Payment
-
-
+     Ocpp20 Module_InitUpgrade Module_RatedCurrentLib Module_Payment \
+     Module_DcMeter
 
 clean:
 	rm -f libModule_RFID.a
@@ -24,6 +23,7 @@ clean:
 	rm -f Module_ProduceUtils
 	rm -f Module_PhBackend
 	rm -f OcppBackend20
+	rm -f Module_DcMeter
 
 Module_ProduceUtils:
 	rm -f Module_ProduceUtils
@@ -126,3 +126,9 @@ Module_Payment:
 	$(CC) -o Module_Payment Module_Payment.o
 	rm -f Module_Payment.o
 	mv -f Module_Payment ../rootfs/root
+
+Module_DcMeter:
+	rm -f Module_DcMeter;
+	$(CC) -D $(Project) "-Wl,-rpath-link,../rootfs/lib" ./DcMeter/Module_DcMeter.c ./DcMeter/meterComm.c ./DcMeter/curlApi.c ./DcMeter/SystemLogMessage.c -I ../Projects -I ../GPL/curl-7.37.1/release/include -I ../GPL/json-c-json-c-0.13.1-20180305/release/include -L ../GPL/json-c-json-c-0.13.1-20180305/release/lib -L ../GPL/curl-7.37.1/release/lib -ljson-c -lcurl -lssl -o Module_DcMeter
+	mv -f Module_DcMeter ../rootfs/root/
+

+ 85 - 6
EVSE/Modularization/Module_EventLogging.c

@@ -506,6 +506,84 @@ int DB_Network_Insert_Record(sqlite3 *db)
 	return result;
 }
 
+//================================================
+// Common routin
+//================================================
+char* getSystemModeName(unsigned char mode)
+{
+	char* result;
+
+	switch(mode)
+	{
+		case SYS_MODE_BOOTING:
+			result = "booting";
+			break;
+		case SYS_MODE_IDLE:
+			result = "idle";
+			break;
+		case SYS_MODE_AUTHORIZING:
+			result = "authorizing";
+			break;
+		case SYS_MODE_PREPARING:
+			result = "preparing";
+			break;
+		case SYS_MODE_CHARGING:
+			result = "charging";
+			break;
+		case SYS_MODE_TERMINATING:
+			result = "terminating";
+			break;
+		case SYS_MODE_COMPLETE:
+			result = "complete";
+			break;
+		case SYS_MODE_ALARM:
+			result = "alarm";
+			break;
+		case SYS_MODE_FAULT:
+			result = "fault";
+			break;
+		case SYS_MODE_MAINTAIN:
+			result = "maintain";
+			break;
+		case SYS_MODE_RESERVATION:
+			result = "reservation";
+			break;
+		case SYS_MODE_BOOKING:
+			result = "booking";
+			break;
+		case SYS_MODE_DEBUG:
+			result = "debug";
+			break;
+		case SYS_MODE_UPDATE:
+			result = "upgrade";
+			break;
+		default:
+			result = "unknown";
+			break;
+	}
+
+	return result;
+}
+
+int getConnectorStatus(char *status)
+{
+	int result = FAIL;
+
+	sprintf(status, " ");
+	if(ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'A')
+	{
+		for(uint8_t gun_index=0;gun_index<AC_QUANTITY;gun_index++)
+		{
+			if(ShmSysConfigAndInfo->SysConfig.ModelName[9+(gun_index*-1)] != '0')
+			{
+				sprintf(status, "%s, Gun-%d: %s", status, (gun_index+1), getSystemModeName(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].SystemStatus));
+			}
+		}
+	}
+
+	return result;
+}
+
 //================================================
 // Main process
 //================================================
@@ -513,12 +591,11 @@ int main(void)
 {
 	int ByteCount,BitCount;
 	unsigned char tmp, EventCodeTmp[7], EventCodeDisp[7];
+	char connectorStatus[512];
 
 	if(InitShareMemory() == FAIL)
 	{
-		#ifdef SystemLogMessage
 		DEBUG_ERROR("InitShareMemory NG\n");
-		#endif
 		if(ShmStatusCodeData!=NULL)
 		{
 			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
@@ -564,8 +641,8 @@ int main(void)
 							ShmStatusCodeData->FaultCode.PreviousFaultVal[ByteCount]|=(1<<BitCount);
 							AddFaultCodeToBuf(EventCodeDisp);
 						}
-
-						EVENT_INFO("%s\n", EventCodeTmp);
+						getConnectorStatus(connectorStatus);
+						EVENT_INFO("%s%s\n", EventCodeTmp, connectorStatus);
 						DB_Event_Insert_Record(localDb, EventCodeTmp);
 					}
 				}
@@ -597,7 +674,8 @@ int main(void)
 							ShmStatusCodeData->AlarmCode.PreviousAlarmVal[ByteCount]|=(1<<BitCount);
 							AddFaultCodeToBuf(EventCodeDisp);
 						}
-						EVENT_INFO("%s\n", EventCodeTmp);
+						getConnectorStatus(connectorStatus);
+						EVENT_INFO("%s%s\n", EventCodeTmp, connectorStatus);
 						DB_Event_Insert_Record(localDb, EventCodeTmp);
 					}
 				}
@@ -629,7 +707,8 @@ int main(void)
 							ShmStatusCodeData->InfoCode.PreviousInfoVal[ByteCount]|=(1<<BitCount);
 							AddFaultCodeToBuf(EventCodeDisp);
 						}
-						EVENT_INFO("%s\n", EventCodeTmp);
+						getConnectorStatus(connectorStatus);
+						EVENT_INFO("%s%s\n", EventCodeTmp, connectorStatus);
 						DB_Event_Insert_Record(localDb, EventCodeTmp);
 					}
 				}

+ 14 - 5
EVSE/Modularization/ocpp20/MessageHandler.c

@@ -3355,8 +3355,8 @@ void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct Ch
 	defaultTxProfile.chargingSchedule[idxSchedule].duration = -1;
 	txProfile.chargingSchedule[idxSchedule].duration = -1;
 
-	system("yes|rm /tmp/*.json");
-	system("cp /Storage/OCPP/*.json /tmp");
+	system("rm -f /tmp/*.json");
+	system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
 	/*
 	 * Search valid charging profile
 	 */
@@ -8083,6 +8083,8 @@ int sendStatusNotificationRequest(int gun_index)
 	char buf[28];//, usec_buf[6];
 	char tempdata[65]={0};
 	int tempIndex = 0;
+	uint8_t isStateChanged = TRUE;
+
 	DEBUG_INFO("sendStatusNotificationRequest...\n");
 
 	gettimeofday(&tmnow, NULL);
@@ -8446,8 +8448,15 @@ S_FAULT                 =12
 
 		}//end of for AC_QUANTITY
 	}
-	strcpy((char *)ShmOCPP20Data->StatusNotification[gun_index].connectorStatus, ConnectorStatusEnumTypeStr[currentStatus]);
+	//it's option
+	if((strstr((char *)ShmOCPP20Data->StatusNotification[gun_index].connectorStatus, ConnectorStatusEnumTypeStr[currentStatus]) != NULL) &&
+		!ShmOCPP20Data->CsMsg.bits[gun_index].TriggerMessageReq)
+	{
+		isStateChanged = FALSE;
+	}
+	ShmOCPP20Data->CsMsg.bits[gun_index].TriggerMessageReq = 0;
 
+	strcpy((char *)ShmOCPP20Data->StatusNotification[gun_index].connectorStatus, ConnectorStatusEnumTypeStr[currentStatus]);
 	random_uuid(guid);
 	sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"evseId\":%d,\"connectorStatus\":\"%s\",\"timestamp\":\"%s\"}]"
 					, MESSAGE_TYPE_CALL
@@ -8457,7 +8466,7 @@ S_FAULT                 =12
 					, ShmOCPP20Data->StatusNotification[gun_index].connectorStatus
 					, ShmOCPP20Data->StatusNotification[gun_index].timestamp);
 
-	if((server_sign == TRUE))
+	if((server_sign == TRUE) && isStateChanged)
 	{
 		LWS_Send(message);
 
@@ -9193,7 +9202,7 @@ int sendCancelReservationConfirmation(char *uuid, unsigned char gun_index)
 								,uuid
 								,json_object_to_json_string_ext(CancelReservation, JSON_C_TO_STRING_PLAIN));
 	json_object_put(CancelReservation);
-	ShmOCPP20Data->CsMsg.bits[0].CancelReservationConf = OFF;
+	ShmOCPP20Data->CsMsg.bits[gun_index].CancelReservationConf = OFF;
 	LWS_Send(message);
 	result = TRUE;
 	return result;

+ 9 - 5
EVSE/Modularization/ocppfiles/MessageHandler.c

@@ -1033,8 +1033,8 @@ void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct St
 	defaultTxProfile.ChargingSchedule.Duration = -1;
 	txProfile.ChargingSchedule.Duration = -1;
 
-	system("yes|rm /tmp/*.json");
-	system("cp /Storage/OCPP/*.json /tmp");
+	system("rm -f /tmp/*.json");
+	system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
 	/*
 	 * Search valid charging profile
 	 */
@@ -3436,6 +3436,7 @@ void CheckSystemValue(void)
 		if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
 		{
 			sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
+			ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf = 0;
 		}
 
 		//==========================================
@@ -4305,7 +4306,10 @@ S_FAULT                 =12
 				}
 				else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING   ---> SuspendedEV
 				{
-					currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
+					if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B))
+						currentStatus = SuspendedEV; 	//OCPP Status: SuspendedEV
+					else
+						currentStatus = SuspendedEVSE;	//OCPP Status: SuspendedEVSE
 				}
 				else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_UPDATE)) //   ---> Unavailable
 				{
@@ -4325,7 +4329,7 @@ S_FAULT                 =12
 	}
 
 	//it's option
-	if((strstr((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]) != NULL) &&
+	if(((strstr((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]) != NULL) || (((currentStatus == SuspendedEV) || (currentStatus == SuspendedEVSE)) && ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStopTransactionReq)) &&
 		!ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq)
 	{
 		isStateChanged = FALSE;
@@ -6382,7 +6386,7 @@ int sendCancelReservationConfirmation(char *uuid,char *payload)
 	sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
 	LWS_Send(message);
 	result = TRUE;
-	ShmOCPP16Data->CsMsg.bits[0].CancelReservationConf = 0;
+
 	return result;
 }
 

+ 28 - 28
EVSE/Projects/AW-CCS/Apps/LCM/Module_LcmControl.c

@@ -36,7 +36,7 @@ void string2ByteArray(uint8_t *input, uint8_t *output);
 //=======================================
 uint8_t getCurrentPage();
 void setCurrentPage(uint8_t page);
-void setCurrencyFromWebsite(char *unit);
+void setCurrencyFromWebsite(uint8_t unit);
 void setWarningStatus(uint8_t gun_index);
 void setAuthorizationPage(uint8_t gun_index);
 void setPriceFromWebsite(float monry_rate);
@@ -813,7 +813,7 @@ void setBillingFromWebsite()
 		// CURRENCY UNIT ( 53 COUNTRIES )
 		if(ShmSysConfigAndInfo->SysConfig.BillingData.Currency <= 53)
 		{
-			setCurrencyFromWebsite((char *)Currency[ShmSysConfigAndInfo->SysConfig.BillingData.Currency]);
+			setCurrencyFromWebsite(ShmSysConfigAndInfo->SysConfig.BillingData.Currency);
 		}
 	}
 	else
@@ -827,19 +827,21 @@ void setBillingFromWebsite()
 //=======================================
 // Setting currency ( WEB PAGE )
 //=======================================
-void setCurrencyFromWebsite(char *unit)
+void setCurrencyFromWebsite(uint8_t unit)
 {
 	uint8_t data[16];
 	uint8_t currency[16];
 	unsigned char kWh [16];
+	uint8_t final_currency[16];
 
 	memset(data, 0x00, ARRAY_SIZE(data));
 	memset(currency, 0x00, ARRAY_SIZE(currency));
+	memset(final_currency, 0x00, ARRAY_SIZE(final_currency));
 	strcpy((char*)kWh, "/kWh");
+	memcpy((char*)currency, Currency[unit], 3);
 
-	*(unit + 3) = '\0';
-	sprintf((char *) currency, "%s%s", unit,kWh);
-	string2ByteArray(currency, data);
+	sprintf((char *)final_currency, "%s%s", currency,kWh);
+	string2ByteArray(final_currency, data);
 	lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, TEXT_CURRENCY_UNIT, data, ARRAY_SIZE(data));
 }
 
@@ -883,7 +885,7 @@ float getPresentFinalCost(uint8_t gun_index)
 
 	for(int idx=0;idx<ARRAY_SIZE(ShmCharger->gun_info[gun_index].presentChargedEnergyPeriod);idx++)
 	{
-		result += ((ShmCharger->gun_info[gun_index].presentChargedEnergyPeriod[idx]/10) * ShmSysConfigAndInfo->SysConfig.BillingData.Fee[idx]);
+		result += ((ShmCharger->gun_info[gun_index].presentChargedEnergyPeriod[idx]) * ShmSysConfigAndInfo->SysConfig.BillingData.Fee[idx]);
 	}
 
 	return result;
@@ -891,7 +893,7 @@ float getPresentFinalCost(uint8_t gun_index)
 
 //=======================================
 // Setting billing ( BACKEND )
-//=======================================
+//=======================================-
 void setBillingFromBackend(uint8_t gun_index, uint8_t system_mode)
 {
 	if((system("pidof -s OcppBackend > /dev/null") != 0))
@@ -973,7 +975,6 @@ void setBillingFromBackend(uint8_t gun_index, uint8_t system_mode)
 void setUserPrice(uint8_t type)
 {
 	uint8_t length;
-	uint8_t Split_String_Count;
 	uint8_t output_data[32];
 	char input_data[32];
 	char tmp[256];
@@ -996,7 +997,7 @@ void setUserPrice(uint8_t type)
 
 				// APPEAR PRICE TEXT
 				strcpy((char*)tmp,(char *)ShmOCPP16Data->Cost.SetUserPrice.price);
-				Split_String_Count = split((char**)splitString, tmp, Symbol);
+				split((char**)splitString, tmp, Symbol);
 				memcpy(input_data, splitString[1], strlen(splitString[1]));
 				length = strlen(input_data);
 				trim_string(input_data,length);
@@ -1020,7 +1021,7 @@ void setUserPrice(uint8_t type)
 
 				// APPEAR ACCOUNT BALANCE TEXT
 				strcpy((char*)tmp,(char *)ShmOCPP16Data->Cost.SetUserPrice.price);
-				Split_String_Count = split((char**)splitString, tmp, Symbol);
+				split((char**)splitString, tmp, Symbol);
 				memcpy(input_data, splitString[3], strlen(splitString[3]));
 				length = strlen(input_data);
 				trim_string(input_data,length);
@@ -1045,7 +1046,6 @@ void setUserPrice(uint8_t type)
 void setDefaultPrice(uint8_t type)
 {
 	uint8_t length;
-	uint8_t Split_String_Count;
 	uint8_t output_data[32];
 	char input_data[32];
 	char tmp[256];
@@ -1068,7 +1068,7 @@ void setDefaultPrice(uint8_t type)
 
 				// APPEAR PRICE TEXT
 				strcpy((char*)tmp,(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
-				Split_String_Count = split((char**)splitString, tmp, Symbol);
+				split((char**)splitString, tmp, Symbol);
 				memcpy(input_data, splitString[1], strlen(splitString[1]));
 				length = strlen(input_data);
 				trim_string(input_data,length);
@@ -1094,7 +1094,6 @@ void setDefaultPrice(uint8_t type)
 void setFinalCost(uint8_t gun_index, uint8_t type)
 {
 	uint8_t length;
-	uint8_t Split_String_Count;
 	uint8_t output_data[32];
 	char input_data[32];
 	char tmp[256];
@@ -1121,7 +1120,7 @@ void setFinalCost(uint8_t gun_index, uint8_t type)
 
 				// APPEAR COST TEXT
 				strcpy((char*)tmp,(char*)ShmOCPP16Data->Cost.FinalCost[gun_index].description);
-				Split_String_Count = split((char**)splitString, tmp, Symbol);
+				split((char**)splitString, tmp, Symbol);
 				memcpy(input_data, splitString[3], strlen(splitString[3]));
 				length = strlen(input_data);
 				trim_string(input_data,length);
@@ -1144,7 +1143,7 @@ void setFinalCost(uint8_t gun_index, uint8_t type)
 
 				// APPEAR BALANCE TEXT
 				strcpy((char*)tmp,(char*)ShmOCPP16Data->Cost.FinalCost[gun_index].description);
-				Split_String_Count = split((char**)splitString, tmp, Symbol);
+				split((char**)splitString, tmp, Symbol);
 				memcpy(input_data, splitString[4], strlen(splitString[4]));
 				length = strlen(input_data);
 				trim_string(input_data,length);
@@ -1176,7 +1175,6 @@ void setFinalCost(uint8_t gun_index, uint8_t type)
 void setCurrencyAndUnitFromBackend(uint8_t type_price ,uint8_t type_currency_unit,uint8_t gun_index)
 {
 	uint8_t length;
-	uint8_t Split_String_Count;
 	uint8_t output_data[32];
 	char input_data[32];
 	char tmp[256];
@@ -1197,7 +1195,7 @@ void setCurrencyAndUnitFromBackend(uint8_t type_price ,uint8_t type_currency_uni
 				if(strstr((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "Current Rate:") > 0)
 				{
 					strcpy((char*)tmp,(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
-					Split_String_Count = split((char**)splitString, tmp, Symbol);
+					split((char**)splitString, tmp, Symbol);
 					memcpy(input_data, splitString[1], strlen(splitString[1]));
 					length = strlen(input_data);
 					memcpy(output_data , input_data+(length-7), 7);
@@ -1224,7 +1222,7 @@ void setCurrencyAndUnitFromBackend(uint8_t type_price ,uint8_t type_currency_uni
 				if(strstr((char *)ShmOCPP16Data->Cost.SetUserPrice.price, "Current Rate:") > 0)
 				{
 					strcpy((char*)tmp,(char *)ShmOCPP16Data->Cost.SetUserPrice.price);
-					Split_String_Count = split((char**)splitString, tmp, Symbol);
+					split((char**)splitString, tmp, Symbol);
 					memcpy(input_data, splitString[1], strlen(splitString[1]));
 					length = strlen(input_data);
 					memcpy(output_data , input_data+(length-7), 7);
@@ -1259,7 +1257,7 @@ void setCurrencyAndUnitFromBackend(uint8_t type_price ,uint8_t type_currency_uni
 				if((strstr((char*)ShmOCPP16Data->Cost.FinalCost[gun_index].description, "Account Balance:") > 0))
 				{
 					strcpy((char*)tmp,(char*)ShmOCPP16Data->Cost.FinalCost[gun_index].description);
-					Split_String_Count = split((char**)splitString, tmp, Symbol);
+					split((char**)splitString, tmp, Symbol);
 					memcpy(input_data, splitString[4], strlen(splitString[4]));
 					length = strlen(input_data);
 					memcpy(output_data , input_data+(length-3), 3);
@@ -1726,8 +1724,13 @@ void setConnectionAnimation(uint8_t gun_index, uint8_t system_mode)
 //=======================================
 void setGunPluginAnimation(uint8_t gun_index)
 {
-	if((ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PilotState != CP_STATE_B) ||
-	   (!ShmCharger->gun_info[gun_index].primaryMcuState.socket_e.isSocketEPinOn))
+	if((ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PilotState == CP_STATE_B) ||
+	   (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PilotState == CP_STATE_C) ||
+	   (ShmCharger->gun_info[gun_index].primaryMcuState.socket_e.isSocketEPinOn == ON))
+	{
+		setDisplayValue(ICON_PLUGIN_ARROW, PLUGIN_ARROW_2);
+	}
+	else
 	{
 		if((GUN_PLUGING_LEVEL_STATUS ==  GUN_PLUGING_LEVEL_0) && (DiffTimebWithNow(startTime[gun_index][TMR_IDX_PLUGIN]) > (TIME_ANIMATION_PLUGIN)))
 		{
@@ -1741,10 +1744,6 @@ void setGunPluginAnimation(uint8_t gun_index)
 			ftime(&startTime[gun_index][TMR_IDX_PLUGIN]);
 		}
 	}
-	else
-	{
-		setDisplayValue(ICON_PLUGIN_ARROW, PLUGIN_ARROW_2);
-	}
 }
 
 //=======================================
@@ -1805,7 +1804,7 @@ void setPresentChargedDuration(uint8_t gun_index)
 	uint16_t hour;
 	uint16_t minute;
 	uint16_t second;
-	uint16_t PresentChargedDuration = ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargedDuration;
+	uint32_t PresentChargedDuration = ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargedDuration;
 
 	memset(data, 0x00, ARRAY_SIZE(data));
 	memset(time, 0x00, ARRAY_SIZE(time));
@@ -2128,7 +2127,8 @@ int main(void)
 					page_update();
 					break;
 				case SYS_MODE_RESERVATION:
-					page_reservation();
+					//page_reservation();
+					page_idle(ShmCharger->gun_selectd, ShmSysConfigAndInfo->SysInfo.AcChargingData[ShmCharger->gun_selectd].SystemStatus);
 					break;
 				case SYS_MODE_BOOKING:
 					page_booking();

+ 5 - 0
EVSE/Projects/AW-CCS/Apps/LCM/lcmComm_dgus.h

@@ -178,6 +178,9 @@
 #define ICON_COST_COMPLETE					0X101B
 #define ICON_ENERGY_COMPLETE				0X101C
 #define ICON_BALANCE_WALLET					0x101D
+#define ICON_DEFAULT_START_PRICE			0x101E
+#define ICON_DEFAULT_ENERGY					0x101F
+
 #define ICON_LOGO							0x1500
 #define ICON_LOGO_CHARGING					0x1501
 
@@ -201,6 +204,8 @@
 #define TEXT_BALANCE						0x20B8 // size 16
 #define TEXT_PERCENTAGE						0x20C8 // size 6
 #define TEXT_CURRENCY_COMPLETE				0x20CE // size 16
+#define TEXT_DEFUALT_START_PRICE			0x20DE // size 16
+#define TEXT_DEFAULT_ENERGY					0x20EE // size 16
 
 #define TEXT_RTC							0X2500 // size 32
 

+ 3 - 2
EVSE/Projects/AW-CCS/Apps/Makefile

@@ -6,6 +6,7 @@ Lib_Module_RFID = "-L../../../Modularization" -lModule_RFID
 Lib_Module_Upgrade = "-L../../../Modularization" -lModule_Upgrade
 Lib_Module_RatedCurrent = "-L../../../Modularization" -lModule_RatedCurrent
 Lib_SQLite3 = "-L../../../Modularization/ocppfiles" -lsqlite3
+Lib_JSONC = "-L../../../GPL/json-c-json-c-0.13.1-20180305/release/lib" -ljson-c
 
 EXI_ENGINE= CCS/v2g/api/api.c \
 	    CCS/v2g/appHandshake/appHandEXIDatatypes.c \
@@ -103,8 +104,8 @@ Module_AlarmDetect_Task:
 Module_CSU_Task:
 	@echo "===== Module_CSU_Task ============================================"
 	rm -f main 
-	$(CC) -D $(Project) "-I../../" "-include../../../Modularization/ocppfiles/sqlite3.h" "-include../../../Modularization/Module_Upgrade.h" "-include../../../Modularization/Module_RFID.h" "-include../../../Modularization/Module_RatedCurrent.h" -O0 -g3 -Wall -c -fmessage-length=0 -o main.o "./main.c"
-	$(CC) -o main main.o ${Lib_Module_RFID} ${Lib_Module_Upgrade} ${Lib_SQLite3} ${Lib_Module_RatedCurrent}
+	$(CC) -D $(Project) "-I../../" "-include../../../GPL/json-c-json-c-0.13.1-20180305/release/include/json-c/json.h" "-include../../../Modularization/ocppfiles/sqlite3.h" "-include../../../Modularization/Module_Upgrade.h" "-include../../../Modularization/Module_RFID.h" "-include../../../Modularization/Module_RatedCurrent.h" -O0 -g3 -Wall -c -fmessage-length=0 -o main.o "./main.c"
+	$(CC) -o main main.o ${Lib_Module_RFID} ${Lib_Module_Upgrade} ${Lib_SQLite3} ${Lib_Module_RatedCurrent} ${Lib_JSONC}
 	rm -f *.o
 	mv -f main ../Images/root		
 	@echo \

+ 56 - 20
EVSE/Projects/AW-CCS/Apps/Module_AlarmDetect.c

@@ -1012,47 +1012,70 @@ int main(void)
 				(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_L2_OVER_VOLTAGE) ||
 				(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_L3_OVER_VOLTAGE))
 			{
-				sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode , "OverVoltage");
+				sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode , "OtherError");
+				if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputOVP == ON)
+					sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode , "012200");
+				else if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputOVP == ON)
+					sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode , "012201");
+				else if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputOVP == ON)
+					sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode , "012202");
+				
 			}
 			else if((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_L1_UNDER_VOLTAGE) ||
 					(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_L2_UNDER_VOLTAGE) ||
 					(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_L3_UNDER_VOLTAGE))
-			{
-				sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode , "UnderVoltage");
+			{	
+				sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode , "OtherError");
+				if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputUVP == ON)
+					sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode , "012203");
+				else if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputUVP == ON)
+					sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode , "012204");
+				else if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputUVP == ON)
+					sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode , "012205");
+
 			}
 			else if((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_L1_OVER_CURRENT) ||
 					(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_L2_OVER_CURRENT) ||
 					(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_L3_OVER_CURRENT))
 			{
-				sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode , "OverCurrentFailure");
+				sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode , "OtherError");
+				if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAcOutputOCP == ON)
+					sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode , "012216");
+				else if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAcOutputOCPL2 == ON)
+					sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode , "012299");
+				else if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemAcOutputOCPL3 == ON)
+					sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode , "012300");
+				
 			}
 			else if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_OVER_TEMPERATURE)
 			{
-				sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode , "HighTemperature");
+				sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode , "OtherError");
+				sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode , "012223");
 			}
 			else if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_GROUND_FAIL)
 			{
-				sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode , "GroundFailure");
+				sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode , "OtherError");
+				sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode , "012256");
 			}
 			else if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_CP_ERROR)
 			{
 				sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode , "OtherError");
-				sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode , "CpError");
+				sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode , "023703");
 			}
 			else if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_CURRENT_LEAK_AC)
 			{
 				sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode , "OtherError");
-				sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode , "ACLeakage");
+				sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode , "012233");
 			}
 			else if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_CURRENT_LEAK_DC)
 			{
 				sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode , "OtherError");
-				sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode , "DCLeakage");
+				sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode , "012233");
 			}
 			else if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_MCU_TESTFAIL)
 			{
 				sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode , "OtherError");
-				sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode , "McuTestFail");
+				sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode , "012257");
 			}
 			else if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_HANDSHAKE_TIMEOUT)
 			{
@@ -1062,53 +1085,66 @@ int main(void)
 			else if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_EMERGENCY_STOP)
 			{
 				sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode , "OtherError");
-				sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode , "EmergencyStop");
+				sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode , "012251");
 			}
 			else if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_RELAY_WELDING)
 			{
 				sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode , "OtherError");
-				sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode , "RelayWelding");
+				sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode , "011009");
 			}
 			else if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_LEAK_MODULE_FAIL)
 			{
 				sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode , "OtherError");
-				sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode , "LeakageModuleFail");
+				sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode , "011004");
 			}
 			else if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_SHUTTER_FAULT)
 			{
 				sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode , "OtherError");
-				sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode , "ShutterFault");
+				sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode , "011034");
 			}
 			else if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_LOCKER_FAULT)
 			{
-				sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode , "ConnectorLockFailure");
+				sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode , "OtherError");
+				sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode , "011027");
 			}
 			else if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_POWER_DROP)
 			{
 				sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode , "OtherError");
-				sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode , "PowerDrop");
+				if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputDrop == ON)
+					sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode , "012212");
+				else if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL2InputDrop == ON)
+					sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode , "012213");
+				else if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL3InputDrop == ON)
+					sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode , "012214");
+
 			}
 			else if((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_L1_CIRCUIT_SHORT) ||
 					(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_L2_CIRCUIT_SHORT) ||
 					(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_L3_CIRCUIT_SHORT))
 			{
 				sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode , "OtherError");
-				sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode , "CircuitShort");
+				if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CircuitShort == ON)
+					sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode , "012262");
+				else if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CircuitShortL2 == ON)
+					sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode , "012301");
+				else if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CircuitShortL3 == ON)
+					sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode , "012302");
+
 			}
 			else if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_ROTATORY_SWITCH_FAULT)
 			{
 				sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode , "OtherError");
-				sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode , "RotatorySwitchFault");
+				sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode , "011036");
 			}
 			else if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_RELAY_DRIVE_FAULT)
 			{
 				sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode , "OtherError");
-				sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode , "RelayDriveFault");
+				sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode , "011010");
 			}
 			else if(ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode & ALARM_METER_TIMEOUT)
 			{
 				sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode , "OtherError");
-				sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode , "MeterCommTimeout");
+				sprintf((char*)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode , "012305");
 			}
 			else
 			{

+ 83 - 1
EVSE/Projects/AW-CCS/Apps/Module_ConfigTools.c

@@ -262,6 +262,8 @@ int main(void)
 			printf("\n ***** system configuration menu ******************");
 			printf("\n  modelname: EVSE model name.");
 			printf("\n  serialnumber: EVSE serial number.");
+			printf("\n  authentication: Authentication function.");
+			printf("\n  rfidendian: RFID read endian.");
 			printf("\n *************************************************");
 			printf("\n  Please input operation item: ");
 			scanf("%s", &cmd[0]);
@@ -306,6 +308,34 @@ int main(void)
 					strcpy((char*)&ShmSysConfigAndInfo->SysConfig.SerialNumber[0], (char*)&cmd[0]);
 				}
 			}
+			else if(strcmp(cmd, "authentication") == 0)
+			{
+				memset(cmd, 0x00, ARRAY_SIZE(cmd));
+				printf("\n *************************************************");
+				printf("\n  0: Enable.");
+				printf("\n  1: Disable.");
+				printf("\n *************************************************");
+
+				printf("\n  Current mode: %d", ShmSysConfigAndInfo->SysConfig.AuthorisationMode);
+				printf("\n  Please input authentication mode: ");
+				scanf("%s", &cmd[0]);
+
+				ShmSysConfigAndInfo->SysConfig.AuthorisationMode = ((0<=atoi(cmd))&&(atoi(cmd)<=1)?atoi(cmd):0);
+			}
+			else if(strcmp(cmd, "rfidendian") == 0)
+			{
+				memset(cmd, 0x00, ARRAY_SIZE(cmd));
+				printf("\n *************************************************");
+				printf("\n  0: Little endian.");
+				printf("\n  1: Big endian.");
+				printf("\n *************************************************");
+
+				printf("\n  Current mode: %d", ShmSysConfigAndInfo->SysConfig.RfidCardNumEndian);
+				printf("\n  Please input rfid endian mode: ");
+				scanf("%s", &cmd[0]);
+
+				ShmSysConfigAndInfo->SysConfig.RfidCardNumEndian = ((0<=atoi(cmd))&&(atoi(cmd)<=1)?atoi(cmd):0);
+			}
 		}
 		else if(strcmp(cmd, "ocpp") == 0)
 		{
@@ -313,6 +343,9 @@ int main(void)
 			printf("\n *************************************************");
 			printf("\n  ocppurl: OCPP backend server url.");
 			printf("\n  cboxid: Charger box id.");
+			printf("\n  vender: Charger point vender.");
+			printf("\n  offlinepolicy: Charger off line policy.");
+			printf("\n  localloadbalance: Charger local load balance.");
 			printf("\n *************************************************");
 			printf("\n  Please input operation item: ");
 			scanf("%s", &cmd[0]);
@@ -357,7 +390,56 @@ int main(void)
 					strcpy((char*)&ShmSysConfigAndInfo->SysConfig.ChargeBoxId[0], (char*)&cmd[0]);
 				}
 			}
-		}
+			else if(strcmp(cmd, "vender") == 0)
+			{
+				memset(cmd, 0x00, ARRAY_SIZE(cmd));
+				printf("\n *************************************************");
+				printf("\n  Current OCPP vender: %s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
+				printf("\n  0: Keep current config.");
+				printf("\n  1: Input new charger box id.");
+				printf("\n *************************************************");
+				printf("\n  Please input operation item: ");
+				scanf("%s", &cmd[0]);
+
+				if(atoi(cmd) == 1)
+				{
+					printf("\n  Please input OCPP vender: ");
+					scanf("%s", &cmd[0]);
+
+					memset(&ShmSysConfigAndInfo->SysConfig.chargePointVendor[0], 0x00, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.chargePointVendor));
+					strcpy((char*)&ShmSysConfigAndInfo->SysConfig.chargePointVendor[0], (char*)&cmd[0]);
+				}
+			}
+			else if(strcmp(cmd, "offlinepolicy") == 0)
+			{
+				memset(cmd, 0x00, ARRAY_SIZE(cmd));
+				printf("\n *************************************************");
+				printf("\n  0: Local list.");
+				printf("\n  2: Free charging.");
+				printf("\n  3: Deny charging.");
+				printf("\n *************************************************");
+
+				printf("\n  Current mode: %d", ShmSysConfigAndInfo->SysConfig.OfflinePolicy);
+				printf("\n  Please input off line policy mode: ");
+				scanf("%s", &cmd[0]);
+
+				ShmSysConfigAndInfo->SysConfig.OfflinePolicy = ((0<=atoi(cmd))&&(atoi(cmd)<=3)&&(atoi(cmd)!=1)?atoi(cmd):0);
+			}
+			else if(strcmp(cmd, "localloadbalance") == 0)
+			{
+				memset(cmd, 0x00, ARRAY_SIZE(cmd));
+				printf("\n *************************************************");
+				printf("\n  0: Disable.");
+				printf("\n  1: Enable.");
+				printf("\n *************************************************");
+
+				printf("\n  Current mode: %d", ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharging);
+				printf("\n  Please input local load balance mode: ");
+				scanf("%s", &cmd[0]);
+
+				ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharging = ((0<=atoi(cmd))&&(atoi(cmd)<=1)?atoi(cmd):0);
+			}
+}
 		else if(strcmp(cmd, "network") == 0)
 		{
 			memset(cmd, 0x00, ARRAY_SIZE(cmd));

+ 296 - 183
EVSE/Projects/AW-CCS/Apps/Module_InternalComm.c

@@ -51,7 +51,7 @@ struct Charger					*ShmCharger;
 
 uint16_t						stepIndex=21, logIndex;
 long long						tsLast, tsNow, tsPrintLog[2];
-double							tmpPowerConsumption;
+uint64_t						tmpPowerConsumption;
 
 void trim(char *s);
 int mystrcmp(char *p1,char *p2);
@@ -329,7 +329,7 @@ unsigned char Query_FW_Ver(unsigned char fd, unsigned char targetAddr, Ver *Ret_
 
 	if(len > 6)
 	{
-		if (len < 6+(rx[4] | rx[5]<<8))
+		if(len < 6+(rx[4] | rx[5]<<8))
 			return result;
 
 		for(int idx = 0;idx<(rx[4] | rx[5]<<8);idx++)
@@ -360,7 +360,7 @@ unsigned char Query_HW_Ver(unsigned char fd, unsigned char targetAddr, Ver *Ret_
 
 	if(len > 6)
 	{
-		if (len < 6+(rx[4] | rx[5]<<8))
+		if(len < 6+(rx[4] | rx[5]<<8))
 			return result;
 
 		for(int idx = 0;idx<(rx[4] | rx[5]<<8);idx++)
@@ -391,7 +391,7 @@ unsigned char Query_Present_InputVoltage(unsigned char fd, unsigned char targetA
 
 	if(len > 6)
 	{
-		if (len < 6+(rx[4] | rx[5]<<8))
+		if(len < 6+(rx[4] | rx[5]<<8))
 			return result;
 
 		for(int idx = 0;idx<(rx[4] | rx[5]<<8);idx++)
@@ -430,7 +430,7 @@ unsigned char Query_Present_OutputVoltage(unsigned char fd, unsigned char target
 
 	if(len > 6)
 	{
-		if (len < 6+(rx[4] | rx[5]<<8))
+		if(len < 6+(rx[4] | rx[5]<<8))
 			return result;
 
 		for(int idx = 0;idx<(rx[4] | rx[5]<<8);idx++)
@@ -467,7 +467,7 @@ unsigned char Query_Fan_Speed(unsigned char fd, unsigned char targetAddr, FanSpe
 
 	if(len > 6)
 	{
-		if (len < 6+(rx[4] | rx[5]<<8))
+		if(len < 6+(rx[4] | rx[5]<<8))
 			return result;
 
 		for(int idx = 0;idx<(rx[4] | rx[5]<<8);idx++)
@@ -500,7 +500,7 @@ unsigned char Query_Temperature(unsigned char fd, unsigned char targetAddr, Temp
 
 	if(len > 6)
 	{
-		if (len < 6+(rx[4] | rx[5]<<8))
+		if(len < 6+(rx[4] | rx[5]<<8))
 			return result;
 
 		for(int idx = 0;idx<(rx[4] | rx[5]<<8);idx++)
@@ -533,7 +533,7 @@ unsigned char Query_Aux_PowerVoltage(unsigned char fd, unsigned char targetAddr,
 
 	if(len > 6)
 	{
-		if (len < 6+(rx[4] | rx[5]<<8))
+		if(len < 6+(rx[4] | rx[5]<<8))
 			return result;
 
 		for(int idx = 0;idx<(rx[4] | rx[5]<<8);idx++)
@@ -566,7 +566,7 @@ unsigned char Query_Relay_Output(unsigned char fd, unsigned char targetAddr, Rel
 
 	if(len > 6)
 	{
-		if (len < 6+(rx[4] | rx[5]<<8))
+		if(len < 6+(rx[4] | rx[5]<<8))
 			return result;
 
 		for(int idx = 0;idx<(rx[4] | rx[5]<<8);idx++)
@@ -602,7 +602,7 @@ unsigned char Query_Gfd_Adc(unsigned char fd, unsigned char targetAddr, Gfd *Ret
 
 	if(len > 6)
 	{
-		if (len < 6+(rx[4] | rx[5]<<8))
+		if(len < 6+(rx[4] | rx[5]<<8))
 			return result;
 
 		for(int idx = 0;idx<(rx[4] | rx[5]<<8);idx++)
@@ -638,7 +638,7 @@ unsigned char Query_Gpio_Input(unsigned char fd, unsigned char targetAddr, Gpio_
 
 	if(len > 6)
 	{
-		if (len < 6+(rx[4] | rx[5]<<8))
+		if(len < 6+(rx[4] | rx[5]<<8))
 			return result;
 
 		for(int idx = 0;idx<(rx[4] | rx[5]<<8);idx++)
@@ -679,7 +679,7 @@ unsigned char Query_Alarm_Log(unsigned char fd, unsigned char targetAddr, Alarm_
 
 	if(len > 6)
 	{
-		if (len < 6+(rx[4] | rx[5]<<8))
+		if(len < 6+(rx[4] | rx[5]<<8))
 			return result;
 
 		for(int idx=0;idx<(rx[4] | rx[5]<<8);idx++)
@@ -711,7 +711,7 @@ unsigned char Query_RTC(unsigned char fd, unsigned char targetAddr, Rtc *Ret_Buf
 
 	if(len > 6)
 	{
-		if (len < 6+(rx[4] | rx[5]<<8))
+		if(len < 6+(rx[4] | rx[5]<<8))
 			return result;
 
 		for(int idx=0;idx<(rx[4] | rx[5]<<8);idx++)
@@ -748,7 +748,7 @@ unsigned char Query_AC_MCU_Status(unsigned char fd, unsigned char targetAddr, Ac
 
 	if(len > 6)
 	{
-		if (len < 6+(rx[4] | rx[5]<<8))
+		if(len < 6+(rx[4] | rx[5]<<8))
 			return result;
 
 		for(int idx=0;idx<(rx[4] | rx[5]<<8);idx++)
@@ -792,7 +792,7 @@ unsigned char Query_AC_MCU_Alarm(unsigned char fd, unsigned char targetAddr, Ac_
 
 	if(len > 6)
 	{
-		if (len < 6+(rx[4] | rx[5]<<8))
+		if(len < 6+(rx[4] | rx[5]<<8))
 			return result;
 
 		for(int idx=0;idx<(rx[4] | rx[5]<<8);idx++)
@@ -837,7 +837,7 @@ unsigned char Query_AC_MCU_Alarm(unsigned char fd, unsigned char targetAddr, Ac_
 				Ret_Buf->bits.UVP_L3 = (((rx[8]>>7)&0x01)?1:0);
 			}
 
-			//rx[9] bit 5~7 reserved
+			//rx[9] bits 6 & 7 Reserved
 			if(ShmSysConfigAndInfo->SysConfig.AcPhaseCount == 3)
 			{
 				Ret_Buf->bits.OCP_L2 = (((rx[9]>>0)&0x01)?1:0);
@@ -846,6 +846,7 @@ unsigned char Query_AC_MCU_Alarm(unsigned char fd, unsigned char targetAddr, Ac_
 				Ret_Buf->bits.short_circuit_L3 = (((rx[9]>>3)&0x01)?1:0);
 			}
 			Ret_Buf->bits.meter_comm_timeout = (((rx[9]>>4)&0x01)?1:0);
+			Ret_Buf->bits.meter_ic_comm_timeout = (((rx[9]>>5)&0x01)?1:0);
 
 			result = PASS;
 		}
@@ -999,8 +1000,8 @@ unsigned char Query_Power_Consumption(unsigned char fd, unsigned char targetAddr
 
 #else	//SIMULATION
 			tsNow = current_timestamp();
-			tmpPowerConsumption += (ShmSysConfigAndInfo->SysInfo.AcChargingData[0].PresentChargingVoltage*ShmSysConfigAndInfo->SysInfo.AcChargingData[0].PresentChargingCurrent)*((tsNow-tsLast)/36000000.0);
-			Ret_Buf_T-> power_consumption = (uint64_t)tmpPowerConsumption;
+			tmpPowerConsumption += (uint64_t)((ShmSysConfigAndInfo->SysInfo.AcChargingData[0].PresentChargingVoltage*ShmSysConfigAndInfo->SysInfo.AcChargingData[0].PresentChargingCurrent)*((tsNow-tsLast)/360000.0));
+			Ret_Buf_T-> power_consumption = tmpPowerConsumption;
 			tsLast = tsNow;
 #endif	//SIMULATION
 			result = PASS;
@@ -1025,7 +1026,7 @@ unsigned char Config_Fan_Speed(unsigned char fd, unsigned char targetAddr, FanSp
 
 	if(len > 6)
 	{
-		if (len < 6+(rx[4] | rx[5]<<8))
+		if(len < 6+(rx[4] | rx[5]<<8))
 				return result;
 
 		chksum = 0x00;
@@ -1064,7 +1065,7 @@ unsigned char Config_Serial_Number(unsigned char fd, unsigned char targetAddr, E
 
 	if(len > 6)
 	{
-		if (len < 6+(rx[4] | rx[5]<<8))
+		if(len < 6+(rx[4] | rx[5]<<8))
 			return result;
 
 		chksum = 0x00;
@@ -1103,7 +1104,7 @@ unsigned char Config_Model_Name(unsigned char fd, unsigned char targetAddr, Evse
 
 	if(len > 6)
 	{
-		if (len < 6+(rx[4] | rx[5]<<8))
+		if(len < 6+(rx[4] | rx[5]<<8))
 			return result;
 
 		chksum = 0x00;
@@ -1128,23 +1129,40 @@ unsigned char Config_Model_Name(unsigned char fd, unsigned char targetAddr, Evse
 unsigned char Config_Relay_Output(unsigned char fd, unsigned char targetAddr, Relay *Set_Buf)
 {
 	unsigned char result = FAIL;
-	unsigned char tx[9] = {0xaa, 0x00, targetAddr, CMD_CONFIG_RELAY_OUTPUT, 0x02, 0x00, 0x00, 0x00, 0x00};
+	unsigned char tx[15] = {0};
 	unsigned char rx[512];
 	unsigned char chksum = 0x00;
 
+	tx[0] = 0xaa;
+	tx[1] = 0x00;
+	tx[2] = targetAddr;
+	tx[3] = CMD_CONFIG_RELAY_OUTPUT;
+	tx[4] = 0x08;
+	tx[5] = 0x00;
+	tx[6] = 0x00;
+	tx[7] = 0x00;
+	tx[8] = 0x00;
+
 	for(int idx_connector=0;idx_connector<2;idx_connector++)
 		for(int idx = 0;idx<8;idx++)
-			tx[6+idx_connector] |= ((Set_Buf->relay_status[idx_connector][idx]?0x01:0x00)<<idx);
+			tx[9+idx_connector] |= ((Set_Buf->relay_status[idx_connector][idx]?0x01:0x00)<<idx);
+
+	tx[11] = 0x00;
+	tx[12] = 0x00;
+	tx[13] = 0x00;
 
 	for(int idx=0;idx<(tx[4] | tx[5]<<8);idx++)
 		chksum ^= tx[6+idx];
-	tx[8] = chksum;
+	tx[14] = chksum;
+
+	//for(int count = 0; count < ARRAY_SIZE(tx); count++)
+		//printf("TX[%d] : %x \n",count, tx[count]);
 
 	unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
 
 	if(len > 6)
 	{
-		if (len < 6+(rx[4] | rx[5]<<8))
+		if(len < 6+(rx[4] | rx[5]<<8))
 			return result;
 
 		chksum = 0x00;
@@ -1189,7 +1207,7 @@ unsigned char Config_Gpio_Output(unsigned char fd, unsigned char targetAddr, Gpi
 
 	if(len > 6)
 	{
-		if (len < 6+(rx[4] | rx[5]<<8))
+		if(len < 6+(rx[4] | rx[5]<<8))
 			return result;
 
 		chksum = 0x00;
@@ -1214,11 +1232,10 @@ unsigned char Config_Gpio_Output(unsigned char fd, unsigned char targetAddr, Gpi
 unsigned char Config_RTC(unsigned char fd, unsigned char targetAddr, Rtc *Set_Buf)
 {
 	unsigned char result = FAIL;
-	unsigned char tx[21];
+	unsigned char tx[21] = {0};
 	unsigned char rx[512];
 	unsigned char chksum = 0x00;
 
-
 	tx[0] = 0xaa;
 	tx[1] = 0x00;
 	tx[2] = targetAddr;
@@ -1248,7 +1265,7 @@ unsigned char Config_RTC(unsigned char fd, unsigned char targetAddr, Rtc *Set_Bu
 
 	if(len > 6)
 	{
-		if (len < 6+(rx[4] | rx[5]<<8))
+		if(len < 6+(rx[4] | rx[5]<<8))
 			return result;
 
 		chksum = 0x00;
@@ -1273,7 +1290,7 @@ unsigned char Config_RTC(unsigned char fd, unsigned char targetAddr, Rtc *Set_Bu
 unsigned char Config_AC_MCU_LED(unsigned char fd, unsigned char targetAddr, Ac_Primary_Mcu_Led *Set_Buf)
 {
 	unsigned char result = FAIL;
-	unsigned char tx[12] ;
+	unsigned char tx[12] = {0};
 	unsigned char rx[512];
 	unsigned char chksum = 0x00;
 
@@ -1297,7 +1314,7 @@ unsigned char Config_AC_MCU_LED(unsigned char fd, unsigned char targetAddr, Ac_P
 
 	if(len > 6)
 	{
-		if (len < 6+(rx[4] | rx[5]<<8))
+		if(len < 6+(rx[4] | rx[5]<<8))
 			return result;
 
 		chksum = 0x00;
@@ -1322,7 +1339,7 @@ unsigned char Config_AC_MCU_LED(unsigned char fd, unsigned char targetAddr, Ac_P
 unsigned char Config_AC_MCU_LEGACY_REQUEST(unsigned char fd, unsigned char targetAddr, Legacy_Request *Set_Buf)
 {
 	unsigned char result = FAIL;
-	unsigned char tx[9];
+	unsigned char tx[9] = {0};
 	unsigned char rx[512];
 	unsigned char chksum = 0x00;
 
@@ -1343,7 +1360,7 @@ unsigned char Config_AC_MCU_LEGACY_REQUEST(unsigned char fd, unsigned char targe
 
 	if(len > 6)
 	{
-		if (len < 6+(rx[4] | rx[5]<<8))
+		if(len < 6+(rx[4] | rx[5]<<8))
 			return result;
 
 		chksum = 0x00;
@@ -1369,7 +1386,7 @@ unsigned char Config_AC_MCU_LEGACY_REQUEST(unsigned char fd, unsigned char targe
 unsigned char Config_AC_MCU_RESET_REQUEST(unsigned char fd, unsigned char targetAddr, Mcu_Reset_Request *Set_Buf)
 {
 	unsigned char result = FAIL;
-	unsigned char tx[9];
+	unsigned char tx[9] = {0};
 	unsigned char rx[512];
 	unsigned char chksum = 0x00;
 
@@ -1390,7 +1407,7 @@ unsigned char Config_AC_MCU_RESET_REQUEST(unsigned char fd, unsigned char target
 
 	if(len > 6)
 	{
-		if (len < 6+(rx[4] | rx[5]<<8))
+		if(len < 6+(rx[4] | rx[5]<<8))
 			return result;
 
 		chksum = 0x00;
@@ -1446,7 +1463,7 @@ unsigned char Query_AC_GUN_PLUGIN_TIMES(unsigned char fd, unsigned char targetAd
 unsigned char Config_AC_MaxCurrent_And_CpPwmDuty(unsigned char fd, unsigned char targetAddr, Ac_Primary_Mcu_Cp_Pwm_Duty *Set_Buf)
 {
 	unsigned char result = FAIL;
-	unsigned char tx[8];
+	unsigned char tx[8] = {0};
 	unsigned char rx[512];
 	unsigned char chksum = 0x00;
 
@@ -1491,7 +1508,7 @@ unsigned char Config_AC_MaxCurrent_And_CpPwmDuty(unsigned char fd, unsigned char
 unsigned char Config_AC_Set_Breathe_Led_Timing(unsigned char fd, unsigned char targetAddr,Set_Breathe_Led_Timing *Set_Buf)
 {
 	unsigned char result = FAIL;
-	unsigned char tx[19];
+	unsigned char tx[19] = {0};
 	unsigned char rx[512];
 	unsigned char chksum = 0x00;
 
@@ -1559,7 +1576,7 @@ unsigned char Config_AC_Set_Breathe_Led_Timing(unsigned char fd, unsigned char t
 unsigned char Config_AC_Set_Led_Brightness(unsigned char fd, unsigned char targetAddr,Set_Led_Brightness *Set_Buf)
 {
 	unsigned char result = FAIL;
-	unsigned char tx[19];
+	unsigned char tx[19] = {0};
 	unsigned char rx[512];
 	unsigned char chksum = 0x00;
 
@@ -1672,7 +1689,7 @@ unsigned char Update_Start(unsigned char fd, unsigned char targetAddr, unsigned
 	unsigned char len = tranceive(fd, tx, sizeof(tx), rx);
 	if(len > 6)
 	{
-		if (len < 6+(rx[4] | rx[5]<<8))
+		if(len < 6+(rx[4] | rx[5]<<8))
 			return result;
 
 		chksum = 0x00;
@@ -1704,7 +1721,7 @@ unsigned char Update_Abord(unsigned char fd, unsigned char targetAddr)
 
 	if(len > 6)
 	{
-		if (len < 6+(rx[4] | rx[5]<<8))
+		if(len < 6+(rx[4] | rx[5]<<8))
 			return result;
 
 		for(int idx = 0;idx<(rx[4] | rx[5]<<8);idx++)
@@ -1752,7 +1769,7 @@ unsigned char Update_Transfer(unsigned char fd, unsigned char targetAddr, unsign
 
 	if(len > 6)
 	{
-		if (len < 6+(rx[4] | rx[5]<<8))
+		if(len < 6+(rx[4] | rx[5]<<8))
 			return result;
 
 		for(int idx = 0;idx<(rx[4] | rx[5]<<8);idx++)
@@ -1783,7 +1800,7 @@ unsigned char Update_Finish(unsigned char fd, unsigned char targetAddr)
 
 	if(len > 6)
 	{
-		if (len < 6+(rx[4] | rx[5]<<8))
+		if(len < 6+(rx[4] | rx[5]<<8))
 			return result;
 
 		for(int idx=0;idx<(rx[4] | rx[5]<<8);idx++)
@@ -1810,8 +1827,8 @@ unsigned char Update_Finish(unsigned char fd, unsigned char targetAddr)
 int main(void)
 {
 	int Uart1Fd;
-
 	unsigned short int failCount[2] = {0,0};
+	struct Charger previousCharger;
 
 	if(InitShareMemory() == FAIL)
 	{
@@ -1998,8 +2015,8 @@ int main(void)
 					//================================================
 					// Byte[6]
 					// Byte[7]
-					// Byte[8] Alarm code 3~7 bits Reserved
-					// Byte[9] Alarm code 0~7 bits Reserved
+					// Byte[8] bits 3 Reserved
+					// Byte[9] bits 6 & 7 Reserved
 					//================================================
 
 					//================================================
@@ -2154,6 +2171,11 @@ int main(void)
 					else
 						ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode &= ~(1<<28);
 
+					if(ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.meter_ic_comm_timeout == 0x01)
+						ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode |= 1<<29;
+					else
+						ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode &= ~(1<<29);
+
 					failCount[gun_index] = 0;
 					
 					ShmCharger->gun_info[gun_index].acCcsInfo.CSUAlarmStatusCode = ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode;
@@ -2270,7 +2292,7 @@ int main(void)
 					else
 						failCount[gun_index] = FAIL_SPEC_COMM;
 				}
-				
+
 				//===============================
 				// Case 10 : Query primary MCU power consumption
 				//===============================
@@ -2286,7 +2308,7 @@ int main(void)
 					else
 						failCount[gun_index] = FAIL_SPEC_COMM;
 				}
-				
+
 				//==========================================================
 				// High priority polling log print out
 				//==========================================================
@@ -2297,121 +2319,188 @@ int main(void)
 					//===============================
 					// Config primary MCU LED
 					//===============================
-					DEBUG_INFO("*******************************************\n");
-					DEBUG_INFO("***** High priority polling : Case 1 ******\n");
-					DEBUG_INFO("*******************************************\n");
-					DEBUG_INFO("MCU-%d set Led mode : %d\n",gun_index, ShmCharger->gun_info[gun_index].primaryMcuLed.mode);
-					DEBUG_INFO("MCU-%d set Alarm code : %x\n",gun_index, ShmCharger->gun_info[gun_index].primaryMcuLed.alarm_code);
+					if((previousCharger.gun_info[gun_index].primaryMcuLed.mode != ShmCharger->gun_info[gun_index].primaryMcuLed.mode) ||
+					   (previousCharger.gun_info[gun_index].primaryMcuLed.alarm_code != ShmCharger->gun_info[gun_index].primaryMcuLed.alarm_code))
+					{
+						DEBUG_INFO("*******************************************\n");
+						DEBUG_INFO("***** High priority polling : Case 1 ******\n");
+						DEBUG_INFO("*******************************************\n");
+						DEBUG_INFO("MCU-%d set Led mode : %d\n",gun_index, ShmCharger->gun_info[gun_index].primaryMcuLed.mode);
+						DEBUG_INFO("MCU-%d set Alarm code : %x\n",gun_index, ShmCharger->gun_info[gun_index].primaryMcuLed.alarm_code);
+
+						previousCharger.gun_info[gun_index].primaryMcuLed.mode = ShmCharger->gun_info[gun_index].primaryMcuLed.mode;
+						previousCharger.gun_info[gun_index].primaryMcuLed.alarm_code = ShmCharger->gun_info[gun_index].primaryMcuLed.alarm_code;
+					}
 
 					//===============================
 					// Config primary Legacy request
 					//===============================
-					DEBUG_INFO("*******************************************\n");
-					DEBUG_INFO("***** High priority polling : Case 2 ******\n");
-					DEBUG_INFO("*******************************************\n");
-					DEBUG_INFO("MCU-%d set relay request : %d\n", gun_index, ShmCharger->gun_info[gun_index].legacyRequest.isLegacyRequest);
+					if(previousCharger.gun_info[gun_index].legacyRequest.isLegacyRequest != ShmCharger->gun_info[gun_index].legacyRequest.isLegacyRequest)
+					{
+						DEBUG_INFO("*******************************************\n");
+						DEBUG_INFO("***** High priority polling : Case 2 ******\n");
+						DEBUG_INFO("*******************************************\n");
+						DEBUG_INFO("MCU-%d set relay request : %d\n", gun_index, ShmCharger->gun_info[gun_index].legacyRequest.isLegacyRequest);
+
+						previousCharger.gun_info[gun_index].legacyRequest.isLegacyRequest = ShmCharger->gun_info[gun_index].legacyRequest.isLegacyRequest;
+					}
 
 					//===============================
 					// Query primary MCU status
 					//===============================
-					DEBUG_INFO("*******************************************\n");
-					DEBUG_INFO("***** High priority polling : Case 3 ******\n");
-					DEBUG_INFO("*******************************************\n");
-					DEBUG_INFO("MCU-%d get Pilot State : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuState.cp_state);
-					DEBUG_INFO("MCU-%d get Pilot Duty : %.2f\n", gun_index, (float)ShmCharger->gun_info[gun_index].primaryMcuState.current_limit);
-					DEBUG_INFO("MCU-%d get Pilot Voltage Positive : %.2f\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuState.cp_voltage_positive);
-					DEBUG_INFO("MCU-%d get Pilot Voltage Negative : %.2f\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuState.cp_voltage_negtive);
-					DEBUG_INFO("MCU-%d get Relay State : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuState.relay_state);
-					DEBUG_INFO("MCU-%d get Rating Current : %.2f\n", gun_index, (float)ShmCharger->gun_info[gun_index].primaryMcuState.rating_current);
-					DEBUG_INFO("MCU-%d get Rotary switch : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuState.rotatory_switch);
-					DEBUG_INFO("MCU-%d get is on Socket-E mode : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuState.socket_e.isSocketEMode);
-					DEBUG_INFO("MCU-%d get Socket-E detect pin : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuState.socket_e.isSocketEPinOn);
-
-					/*
-					DEBUG_INFO("MCU-%d get Locker State : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuState.locker_state);
-					DEBUG_INFO("MCU-%d get Shutter State : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuState.shutter_state);
-					DEBUG_INFO("MCU-%d get Meter State : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuState.meter_state);
-					DEBUG_INFO("MCU-%d get PP State : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuState.pp_state);
-										*/
+					if((previousCharger.gun_info[gun_index].primaryMcuState.cp_state != ShmCharger->gun_info[gun_index].primaryMcuState.cp_state) ||
+					   (previousCharger.gun_info[gun_index].primaryMcuState.current_limit != ShmCharger->gun_info[gun_index].primaryMcuState.current_limit) ||
+					   (previousCharger.gun_info[gun_index].primaryMcuState.relay_state != ShmCharger->gun_info[gun_index].primaryMcuState.relay_state) ||
+					   (previousCharger.gun_info[gun_index].primaryMcuState.socket_e.isSocketEMode != ShmCharger->gun_info[gun_index].primaryMcuState.socket_e.isSocketEMode) ||
+					   (previousCharger.gun_info[gun_index].primaryMcuState.socket_e.isSocketEPinOn != ShmCharger->gun_info[gun_index].primaryMcuState.socket_e.isSocketEPinOn))
+					{
+						DEBUG_INFO("*******************************************\n");
+						DEBUG_INFO("***** High priority polling : Case 3 ******\n");
+						DEBUG_INFO("*******************************************\n");
+						DEBUG_INFO("MCU-%d get Pilot State : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuState.cp_state);
+						DEBUG_INFO("MCU-%d get Pilot Duty : %.2f\n", gun_index, (float)ShmCharger->gun_info[gun_index].primaryMcuState.current_limit);
+						DEBUG_INFO("MCU-%d get Pilot Voltage Positive : %.2f\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuState.cp_voltage_positive);
+						DEBUG_INFO("MCU-%d get Pilot Voltage Negative : %.2f\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuState.cp_voltage_negtive);
+
+						if(ShmCharger->gun_info[gun_index].primaryMcuState.socket_e.isSocketEPinOn == ON)
+							DEBUG_INFO("Relay on mode : CHARGING_MODE_SOCKETE. \n");
+						else
+							DEBUG_INFO("Relay on mode : CHARGING_MODE_BS / CHARGING_MODE_HLC. \n");
+
+						DEBUG_INFO("MCU-%d get Relay State : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuState.relay_state);
+						DEBUG_INFO("MCU-%d get Rating Current : %.2f\n", gun_index, (float)ShmCharger->gun_info[gun_index].primaryMcuState.rating_current);
+						DEBUG_INFO("MCU-%d get Rotary switch : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuState.rotatory_switch);
+						DEBUG_INFO("MCU-%d get is on Socket-E mode : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuState.socket_e.isSocketEMode);
+						DEBUG_INFO("MCU-%d get Socket-E detect pin : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuState.socket_e.isSocketEPinOn);
+
+						//===============================
+						// Query primary MCU power consumption
+						//===============================
+						DEBUG_INFO("*******************************************\n");
+						DEBUG_INFO("***** High priority polling : Case 10 *****\n");
+						DEBUG_INFO("*******************************************\n");
+						DEBUG_INFO("MCU-%d get total power consumption : %f kWh\n",gun_index, ((float)ShmCharger->gun_info[gun_index].powerConsumptionTotal.power_consumption/10000.0));
+						DEBUG_INFO("MCU-%d get L1N_L12 power consumption : %f kWh\n",gun_index, ((float)ShmCharger->gun_info[gun_index].powerConsumption[0].power_consumption/10000.0));
+						if(ShmSysConfigAndInfo->SysConfig.AcPhaseCount == 3)
+						{
+							DEBUG_INFO("MCU-%d get L2N_L23 power consumption : %f kWh\n",gun_index, ((float)ShmCharger->gun_info[gun_index].powerConsumption[1].power_consumption/10000.0));
+							DEBUG_INFO("MCU-%d get L3N_L31 power consumption : %f kWh\n",gun_index, ((float)ShmCharger->gun_info[gun_index].powerConsumption[2].power_consumption/10000.0));
+						}
+						
+						/*
+						DEBUG_INFO("MCU-%d get Locker State : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuState.locker_state);
+						DEBUG_INFO("MCU-%d get Shutter State : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuState.shutter_state);
+						DEBUG_INFO("MCU-%d get Meter State : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuState.meter_state);
+						DEBUG_INFO("MCU-%d get PP State : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuState.pp_state);
+						*/
+
+						previousCharger.gun_info[gun_index].primaryMcuState.cp_state = ShmCharger->gun_info[gun_index].primaryMcuState.cp_state;
+						previousCharger.gun_info[gun_index].primaryMcuState.current_limit = ShmCharger->gun_info[gun_index].primaryMcuState.current_limit;
+						previousCharger.gun_info[gun_index].primaryMcuState.relay_state = ShmCharger->gun_info[gun_index].primaryMcuState.relay_state;
+						previousCharger.gun_info[gun_index].primaryMcuState.socket_e.isSocketEMode = ShmCharger->gun_info[gun_index].primaryMcuState.socket_e.isSocketEMode;
+						previousCharger.gun_info[gun_index].primaryMcuState.socket_e.isSocketEPinOn = ShmCharger->gun_info[gun_index].primaryMcuState.socket_e.isSocketEPinOn;
+					}
 
 					//===============================
 					// Query primary MCU Alarm code
 					//===============================
-					if((ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode>0))
+					if((previousCharger.gun_info[gun_index].primaryMcuAlarm.InputAlarmCode != ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode))
 					{
-						DEBUG_INFO("*******************************************\n");
-						DEBUG_INFO("***** High priority polling : Case 4 ******\n");
-						DEBUG_INFO("*******************************************\n");
-						DEBUG_INFO("MCU-%d get OVP_L1 : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.OVP_L1);
-						DEBUG_INFO("MCU-%d get UVP_L1 : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.UVP_L1);
-						DEBUG_INFO("MCU-%d get OCP_L1 : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.OCP_L1);
-						if(ShmSysConfigAndInfo->SysConfig.AcPhaseCount == 3)
+						if((ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode>0))
 						{
-							DEBUG_INFO("MCU-%d get OVP_L2 : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.OVP_L2);
-							DEBUG_INFO("MCU-%d get UVP_L2 : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.UVP_L2);
-							DEBUG_INFO("MCU-%d get OCP_L2 : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.OCP_L2);
-							DEBUG_INFO("MCU-%d get OVP_L3 : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.OVP_L3);
-							DEBUG_INFO("MCU-%d get UVP_L3 : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.UVP_L3);
-							DEBUG_INFO("MCU-%d get OCP_L3 : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.OCP_L3);
+							DEBUG_INFO("*******************************************\n");
+							DEBUG_INFO("***** High priority polling : Case 4 ******\n");
+							DEBUG_INFO("*******************************************\n");
+							DEBUG_INFO("MCU-%d get OVP_L1 : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.OVP_L1);
+							DEBUG_INFO("MCU-%d get UVP_L1 : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.UVP_L1);
+							DEBUG_INFO("MCU-%d get OCP_L1 : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.OCP_L1);
+							if(ShmSysConfigAndInfo->SysConfig.AcPhaseCount == 3)
+							{
+								DEBUG_INFO("MCU-%d get OVP_L2 : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.OVP_L2);
+								DEBUG_INFO("MCU-%d get UVP_L2 : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.UVP_L2);
+								DEBUG_INFO("MCU-%d get OCP_L2 : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.OCP_L2);
+								DEBUG_INFO("MCU-%d get OVP_L3 : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.OVP_L3);
+								DEBUG_INFO("MCU-%d get UVP_L3 : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.UVP_L3);
+								DEBUG_INFO("MCU-%d get OCP_L3 : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.OCP_L3);
+							}
+							DEBUG_INFO("MCU-%d get OTP : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.OTP);
+							DEBUG_INFO("MCU-%d get gmi_fault : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.gmi_fault);
+							DEBUG_INFO("MCU-%d get cp_fault : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.cp_fault);
+							DEBUG_INFO("MCU-%d get ac_leak : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.ac_leak);
+							DEBUG_INFO("MCU-%d get dc_leak : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.dc_leak);
+							DEBUG_INFO("MCU-%d get mcu_selftest_fail : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.mcu_selftest_fail);
+							DEBUG_INFO("MCU-%d get handshaking_timeout : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.handshaking_timeout);
+							DEBUG_INFO("MCU-%d get emergency_stop : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.emergency_stop);
+							DEBUG_INFO("MCU-%d get relay_welding : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.relay_welding);
+							DEBUG_INFO("MCU-%d get leak_module_fail : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.leak_module_fail);
+							DEBUG_INFO("MCU-%d get shutter_fault : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.shutter_fault);
+							DEBUG_INFO("MCU-%d get locker_fault : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.locker_fault);
+							DEBUG_INFO("MCU-%d get power_drop : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.power_drop);
+							DEBUG_INFO("MCU-%d get rotate_switch_fault : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.rotate_switch_fault);
+							DEBUG_INFO("MCU-%d get short_circuit_L1 : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.short_circuit_L1);
+							if(ShmSysConfigAndInfo->SysConfig.AcPhaseCount == 3)
+							{
+								DEBUG_INFO("MCU-%d get short_circuit_L2 : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.short_circuit_L2);
+								DEBUG_INFO("MCU-%d get short_circuit_L3 : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.short_circuit_L3);
+							}
+							DEBUG_INFO("MCU-%d get relay_drive_fault : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.relay_drive_fault);
+							DEBUG_INFO("MCU-%d get meter_comm_timeout : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.meter_comm_timeout);
+							DEBUG_INFO("MCU-%d get meter_ic_comm_timeout : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.meter_ic_comm_timeout);
+							DEBUG_INFO("MCU-%d get InputAlarmCode : %x\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode);
 						}
-						DEBUG_INFO("MCU-%d get OTP : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.OTP);
-						DEBUG_INFO("MCU-%d get gmi_fault : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.gmi_fault);
-						DEBUG_INFO("MCU-%d get cp_fault : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.cp_fault);
-						DEBUG_INFO("MCU-%d get ac_leak : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.ac_leak);
-						DEBUG_INFO("MCU-%d get dc_leak : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.dc_leak);
-						DEBUG_INFO("MCU-%d get mcu_selftest_fail : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.mcu_selftest_fail);
-						DEBUG_INFO("MCU-%d get handshaking_timeout : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.handshaking_timeout);
-						DEBUG_INFO("MCU-%d get emergency_stop : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.emergency_stop);
-						DEBUG_INFO("MCU-%d get relay_welding : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.relay_welding);
-						DEBUG_INFO("MCU-%d get leak_module_fail : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.leak_module_fail);
-						DEBUG_INFO("MCU-%d get shutter_fault : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.shutter_fault);
-						DEBUG_INFO("MCU-%d get locker_fault : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.locker_fault);
-						DEBUG_INFO("MCU-%d get power_drop : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.power_drop);
-						DEBUG_INFO("MCU-%d get rotate_switch_fault : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.rotate_switch_fault);
-						DEBUG_INFO("MCU-%d get short_circuit_L1 : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.short_circuit_L1);
+
+						DEBUG_INFO("===========================================\n");
+						DEBUG_INFO("==== Normal priority polling : Case 1 =====\n");
+						DEBUG_INFO("===========================================\n");
+						DEBUG_INFO("MCU-%d get Input voltage L1: %.2f\n", gun_index, (float)ShmCharger->gun_info[gun_index].inputVoltage.L1N_L12);
+						DEBUG_INFO("MCU-%d get PresentChargingVoltage L1: %.2f\n", gun_index, (float)ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargingVoltage);
 						if(ShmSysConfigAndInfo->SysConfig.AcPhaseCount == 3)
 						{
-							DEBUG_INFO("MCU-%d get short_circuit_L2 : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.short_circuit_L2);
-							DEBUG_INFO("MCU-%d get short_circuit_L3 : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.short_circuit_L3);
+							DEBUG_INFO("MCU-%d get Input voltage L2: %f\n", gun_index, (float)ShmCharger->gun_info[gun_index].inputVoltage.L2N_L23);
+							DEBUG_INFO("MCU-%d get PresentChargingVoltage L2: %.2f\n", gun_index, (float)ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargingVoltageL2);
+							DEBUG_INFO("MCU-%d get Input voltage L3: %f\n", gun_index, (float)ShmCharger->gun_info[gun_index].inputVoltage.L3N_L31);
+							DEBUG_INFO("MCU-%d get PresentChargingVoltage L3: %.2f\n", gun_index, (float)ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargingVoltageL3);
 						}
-						DEBUG_INFO("MCU-%d get relay_drive_fault : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.relay_drive_fault);
-						DEBUG_INFO("MCU-%d get meter_comm_timeout : %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.bits.meter_comm_timeout);
-						DEBUG_INFO("MCU-%d get InputAlarmCode : %x\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode);
+
+						previousCharger.gun_info[gun_index].primaryMcuAlarm.InputAlarmCode = ShmCharger->gun_info[gun_index].primaryMcuAlarm.InputAlarmCode;
 					}
 
 					//===============================
 					// Query primary MCU BLE config
 					//===============================
-					if(ShmCharger->gun_info[gun_index].bleConfigData.isLogin == ON)
+					if((previousCharger.gun_info[gun_index].bleConfigData.isLogin != ShmCharger->gun_info[gun_index].bleConfigData.isLogin) ||
+					   (previousCharger.gun_info[gun_index].bleConfigData.isRequestStart != ShmCharger->gun_info[gun_index].bleConfigData.isRequestStart) ||
+					   (previousCharger.gun_info[gun_index].bleConfigData.isRequestStop != ShmCharger->gun_info[gun_index].bleConfigData.isRequestStop))
 					{
-						DEBUG_INFO("*******************************************\n");
-						DEBUG_INFO("***** High priority polling : Case 5 ******\n");
-						DEBUG_INFO("*******************************************\n");
-						DEBUG_INFO("MCU-%d get isUserLogin : %d\n", gun_index, ShmCharger->gun_info[gun_index].bleConfigData.isLogin);
-						DEBUG_INFO("MCU-%d get isRequestStartCharger : %d\n", gun_index, ShmCharger->gun_info[gun_index].bleConfigData.isRequestStart);
-						DEBUG_INFO("MCU-%d get isRequestStopCharger : %d\n", gun_index, ShmCharger->gun_info[gun_index].bleConfigData.isRequestStop);
+						if(ShmCharger->gun_info[gun_index].bleConfigData.isLogin == ON)
+						{
+							DEBUG_INFO("*******************************************\n");
+							DEBUG_INFO("***** High priority polling : Case 5 ******\n");
+							DEBUG_INFO("*******************************************\n");
+							DEBUG_INFO("MCU-%d get isUserLogin : %d\n", gun_index, ShmCharger->gun_info[gun_index].bleConfigData.isLogin);
+							DEBUG_INFO("MCU-%d get isRequestStartCharger : %d\n", gun_index, ShmCharger->gun_info[gun_index].bleConfigData.isRequestStart);
+							DEBUG_INFO("MCU-%d get isRequestStopCharger : %d\n", gun_index, ShmCharger->gun_info[gun_index].bleConfigData.isRequestStop);
+						}
+
+						previousCharger.gun_info[gun_index].bleConfigData.isLogin = ShmCharger->gun_info[gun_index].bleConfigData.isLogin;
+						previousCharger.gun_info[gun_index].bleConfigData.isRequestStart = ShmCharger->gun_info[gun_index].bleConfigData.isRequestStart;
+						previousCharger.gun_info[gun_index].bleConfigData.isRequestStop = ShmCharger->gun_info[gun_index].bleConfigData.isRequestStop;
 					}
 
 					//===============================
 					// Query primary MCU ble login id
 					//===============================
-					if(strcmp((char *)&ShmCharger->gun_info[gun_index].bleLoginCentralId.id,"") != 0)
+					if((strcmp((char *)&previousCharger.gun_info[gun_index].bleLoginCentralId.id,(char *)&ShmCharger->gun_info[gun_index].bleLoginCentralId.id) != 0))
 					{
-						DEBUG_INFO("*******************************************\n");
-						DEBUG_INFO("***** High priority polling : Case 6 ******\n");
-						DEBUG_INFO("*******************************************\n");
-						DEBUG_INFO("MCU-%d get ble central id : %s\n", gun_index, ShmCharger->gun_info[gun_index].bleLoginCentralId.id);
-					}
-					
-					DEBUG_INFO("*******************************************\n");
-					DEBUG_INFO("**** High priority polling : Case 10 ****\n");
-					DEBUG_INFO("*******************************************\n");
-					DEBUG_INFO("MCU-%d get total power consumption : %f kWh\n",gun_index, ((float)ShmCharger->gun_info[gun_index].powerConsumptionTotal.power_consumption/10000.0));
-					DEBUG_INFO("MCU-%d get L1N_L12 power consumption : %f kWh\n",gun_index, ((float)ShmCharger->gun_info[gun_index].powerConsumption[0].power_consumption/10000.0));
-					if(ShmSysConfigAndInfo->SysConfig.AcPhaseCount == 3)
-					{
-						DEBUG_INFO("MCU-%d get L2N_L23 power consumption : %f kWh\n",gun_index, ((float)ShmCharger->gun_info[gun_index].powerConsumption[1].power_consumption/10000.0));
-						DEBUG_INFO("MCU-%d get L3N_L31 power consumption : %f kWh\n",gun_index, ((float)ShmCharger->gun_info[gun_index].powerConsumption[2].power_consumption/10000.0));
+						if(strcmp((char *)&ShmCharger->gun_info[gun_index].bleLoginCentralId.id,"") != 0)
+						{
+							DEBUG_INFO("*******************************************\n");
+							DEBUG_INFO("***** High priority polling : Case 6 ******\n");
+							DEBUG_INFO("*******************************************\n");
+							DEBUG_INFO("MCU-%d get ble central id : %s\n", gun_index, ShmCharger->gun_info[gun_index].bleLoginCentralId.id);
+						}
+
+						memcpy(&previousCharger.gun_info[gun_index].bleLoginCentralId.id, ShmCharger->gun_info[gun_index].bleLoginCentralId.id, ARRAY_SIZE(ShmCharger->gun_info[gun_index].bleLoginCentralId.id));
 					}
 				}
 			}
@@ -2469,9 +2558,13 @@ int main(void)
 							ShmCharger->gun_info[gun_index].acCcsInfo.EVSEPresentCurrent[1] = (float)ShmCharger->gun_info[gun_index].outputCurrent.L1N_L12[0];
 							ShmCharger->gun_info[gun_index].acCcsInfo.EVSEPresentCurrent[2] = (float)ShmCharger->gun_info[gun_index].outputCurrent.L1N_L12[0];							
 #else	//SIMULATION
-						ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargingCurrent = (float)(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].SystemStatus==SYS_MODE_CHARGING?(((rand()%10)+((ShmCharger->gun_info[gun_index].targetCurrent*10)-5))/10.0):0) ;
+						ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargingCurrent = (float)(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].SystemStatus==SYS_MODE_CHARGING?(((rand()%10)+((ShmCharger->gun_info[gun_index].targetCurrent*10)-5))/10.0):0);
+						if(ShmSysConfigAndInfo->SysConfig.AcPhaseCount == 3)
+						{
+							ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargingCurrentL2 = (float)(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].SystemStatus==SYS_MODE_CHARGING?(((rand()%10)+((ShmCharger->gun_info[gun_index].targetCurrent*10)-5))/10.0):0);
+							ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargingCurrentL3 = (float)(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].SystemStatus==SYS_MODE_CHARGING?(((rand()%10)+((ShmCharger->gun_info[gun_index].targetCurrent*10)-5))/10.0):0);
+						}
 #endif	//SIMULATION
-
 							failCount[gun_index] = 0;
 						}
 						else
@@ -2584,23 +2677,6 @@ int main(void)
 						}
 						break;
 					case 11:
-						//===============================
-						// Query primary MCU power consumption
-						//===============================
-						/*
-						if(Query_Power_Consumption(Uart1Fd, (gun_index>0?ADDR_AC_PRIMARY_2:ADDR_AC_PRIMARY_1), &ShmCharger->gun_info[gun_index].powerConsumptionTotal, &ShmCharger->gun_info[gun_index].powerConsumption[0], &ShmCharger->gun_info[gun_index].powerConsumption[1], &ShmCharger->gun_info[gun_index].powerConsumption[2]))
-						{
-							failCount[gun_index] = 0;
-						}
-						else
-						{
-							DEBUG_WARN("MCU-%d get power consumption fail...%d\n", gun_index, failCount[gun_index]);
-							if(failCount[gun_index]<USHRT_MAX)
-								failCount[gun_index]++;
-							else
-								failCount[gun_index] = FAIL_SPEC_COMM;
-						}
-						*/
 						break;
 					case 13:
 						//===============================
@@ -2789,33 +2865,61 @@ int main(void)
 					switch(logIndex)
 					{
 						case 1:
-							DEBUG_INFO("===========================================\n");
-							DEBUG_INFO("==== Normal priority polling : Case 3 =====\n");
-							DEBUG_INFO("===========================================\n");
-							DEBUG_INFO("MCU-%d get output current L1: %f\n", gun_index, (float)ShmCharger->gun_info[gun_index].outputCurrent.L1N_L12[0]);
-							if(ShmSysConfigAndInfo->SysConfig.AcPhaseCount == 3)
+							if((previousCharger.gun_info[gun_index].outputCurrent.L1N_L12[0] != ShmCharger->gun_info[gun_index].outputCurrent.L1N_L12[0]) ||
+							   (previousCharger.gun_info[gun_index].outputCurrent.L2N_L23[0] != ShmCharger->gun_info[gun_index].outputCurrent.L2N_L23[0]) ||
+							   (previousCharger.gun_info[gun_index].outputCurrent.L3N_L31[0] != ShmCharger->gun_info[gun_index].outputCurrent.L3N_L31[0]))
 							{
-								DEBUG_INFO("MCU-%d get output current L2: %f\n", gun_index, (float)ShmCharger->gun_info[gun_index].outputCurrent.L2N_L23[0]);
-								DEBUG_INFO("MCU-%d get output current L3: %f\n", gun_index, (float)ShmCharger->gun_info[gun_index].outputCurrent.L3N_L31[0]);
+								DEBUG_INFO("===========================================\n");
+								DEBUG_INFO("==== Normal priority polling : Case 3 =====\n");
+								DEBUG_INFO("===========================================\n");
+								DEBUG_INFO("MCU-%d get output current L1: %f\n", gun_index, (float)ShmCharger->gun_info[gun_index].outputCurrent.L1N_L12[0]);
+								if(ShmSysConfigAndInfo->SysConfig.AcPhaseCount == 3)
+								{
+									DEBUG_INFO("MCU-%d get output current L2: %f\n", gun_index, (float)ShmCharger->gun_info[gun_index].outputCurrent.L2N_L23[0]);
+									DEBUG_INFO("MCU-%d get output current L3: %f\n", gun_index, (float)ShmCharger->gun_info[gun_index].outputCurrent.L3N_L31[0]);
+								}
+
+								previousCharger.gun_info[gun_index].outputCurrent.L1N_L12[0] = ShmCharger->gun_info[gun_index].outputCurrent.L1N_L12[0];
+								previousCharger.gun_info[gun_index].outputCurrent.L2N_L23[0] = ShmCharger->gun_info[gun_index].outputCurrent.L2N_L23[0];
+								previousCharger.gun_info[gun_index].outputCurrent.L3N_L31[0] = ShmCharger->gun_info[gun_index].outputCurrent.L3N_L31[0];
 							}
+
 							break;
 						case 2:
-							DEBUG_INFO("===========================================\n");
-							DEBUG_INFO("==== Normal priority polling : Case 5 =====\n");
-							DEBUG_INFO("===========================================\n");
-							DEBUG_INFO("MCU-%d get gun plugin times : %ld\n", gun_index, (long)ShmCharger->gun_info[gun_index].gunPluginTimes.GunPluginTimes);
+							if(previousCharger.gun_info[gun_index].gunPluginTimes.GunPluginTimes != ShmCharger->gun_info[gun_index].gunPluginTimes.GunPluginTimes)
+							{
+								DEBUG_INFO("===========================================\n");
+								DEBUG_INFO("==== Normal priority polling : Case 5 =====\n");
+								DEBUG_INFO("===========================================\n");
+								DEBUG_INFO("MCU-%d get gun plugin times : %ld\n", gun_index, (long)ShmCharger->gun_info[gun_index].gunPluginTimes.GunPluginTimes);
+
+								previousCharger.gun_info[gun_index].gunPluginTimes.GunPluginTimes = ShmCharger->gun_info[gun_index].gunPluginTimes.GunPluginTimes;
+							}
+
 							break;
 						case 3:
-							DEBUG_INFO("===========================================\n");
-							DEBUG_INFO("==== Normal priority polling : Case 7 =====\n");
-							DEBUG_INFO("===========================================\n");
-							DEBUG_INFO("MCU-%d get temperature : %d\n", gun_index, ShmCharger->gun_info[gun_index].temperature.point[0]);
+							if(previousCharger.gun_info[gun_index].temperature.point[0] != ShmCharger->gun_info[gun_index].temperature.point[0])
+							{
+								DEBUG_INFO("===========================================\n");
+								DEBUG_INFO("==== Normal priority polling : Case 7 =====\n");
+								DEBUG_INFO("===========================================\n");
+								DEBUG_INFO("MCU-%d get temperature : %d\n", gun_index, ShmCharger->gun_info[gun_index].temperature.point[0]);
+
+								previousCharger.gun_info[gun_index].temperature.point[0] = ShmCharger->gun_info[gun_index].temperature.point[0];
+							}
+
 							break;
 						case 4:
-							DEBUG_INFO("===========================================\n");
-							DEBUG_INFO("==== Normal priority polling : Case 9 =====\n");
-							DEBUG_INFO("===========================================\n");
-							DEBUG_INFO("MCU-%d set cp pwn duty : %d\n",gun_index, ShmCharger->gun_info[gun_index].primaryMcuCp_Pwn_Duty.max_current);
+							if(previousCharger.gun_info[gun_index].primaryMcuCp_Pwn_Duty.max_current != ShmCharger->gun_info[gun_index].primaryMcuCp_Pwn_Duty.max_current)
+							{
+								DEBUG_INFO("===========================================\n");
+								DEBUG_INFO("==== Normal priority polling : Case 9 =====\n");
+								DEBUG_INFO("===========================================\n");
+								DEBUG_INFO("MCU-%d set cp pwn duty : %d\n",gun_index, ShmCharger->gun_info[gun_index].primaryMcuCp_Pwn_Duty.max_current);
+
+								previousCharger.gun_info[gun_index].primaryMcuCp_Pwn_Duty.max_current = ShmCharger->gun_info[gun_index].primaryMcuCp_Pwn_Duty.max_current;
+							}
+
 							break;
 						case 5:
 							DEBUG_INFO("===========================================\n");
@@ -2830,8 +2934,6 @@ int main(void)
 																												  ShmCharger->gun_info[gun_index].rtc.hour,
 																												  ShmCharger->gun_info[gun_index].rtc.min,
 																												  ShmCharger->gun_info[gun_index].rtc.sec);
-
-
 							}
 							else
 							{
@@ -2881,19 +2983,30 @@ int main(void)
 							}
 							break;
 						default:
-							DEBUG_INFO("===========================================\n");
-							DEBUG_INFO("==== Normal priority polling : Case 1 =====\n");
-							DEBUG_INFO("===========================================\n");
-							DEBUG_INFO("MCU-%d get input voltage L1: %f\n", gun_index, (float)ShmCharger->gun_info[gun_index].inputVoltage.L1N_L12);
-							DEBUG_INFO("MCU-%d get PresentChargingVoltage L1: %.2f\n", gun_index, (float)ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargingVoltage);
-
-							if(ShmSysConfigAndInfo->SysConfig.AcPhaseCount == 3)
+							/*
+							if((previousCharger.gun_info[gun_index].inputVoltage.L1N_L12 != ShmCharger->gun_info[gun_index].inputVoltage.L1N_L12) ||
+							   (previousCharger.gun_info[gun_index].inputVoltage.L2N_L23 != ShmCharger->gun_info[gun_index].inputVoltage.L2N_L23) ||
+							   (previousCharger.gun_info[gun_index].inputVoltage.L3N_L31 != ShmCharger->gun_info[gun_index].inputVoltage.L3N_L31))
 							{
-								DEBUG_INFO("MCU-%d get input voltage L2: %f\n", gun_index, (float)ShmCharger->gun_info[gun_index].inputVoltage.L2N_L23);
-								DEBUG_INFO("MCU-%d get PresentChargingVoltage L2: %.2f\n", gun_index, (float)ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargingVoltageL2);
-								DEBUG_INFO("MCU-%d get input voltage L3: %f\n", gun_index, (float)ShmCharger->gun_info[gun_index].inputVoltage.L3N_L31);
-								DEBUG_INFO("MCU-%d get PresentChargingVoltage L3: %.2f\n", gun_index, (float)ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargingVoltageL3);
+								DEBUG_INFO("===========================================\n");
+								DEBUG_INFO("==== Normal priority polling : Case 1 =====\n");
+								DEBUG_INFO("===========================================\n");
+								DEBUG_INFO("MCU-%d get Input voltage L1: %.2f\n", gun_index, (float)ShmCharger->gun_info[gun_index].inputVoltage.L1N_L12);
+								DEBUG_INFO("MCU-%d get PresentChargingVoltage L1: %.2f\n", gun_index, (float)ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargingVoltage);
+
+								if(ShmSysConfigAndInfo->SysConfig.AcPhaseCount == 3)
+								{
+									DEBUG_INFO("MCU-%d get Input voltage L2: %f\n", gun_index, (float)ShmCharger->gun_info[gun_index].inputVoltage.L2N_L23);
+									DEBUG_INFO("MCU-%d get PresentChargingVoltage L2: %.2f\n", gun_index, (float)ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargingVoltageL2);
+									DEBUG_INFO("MCU-%d get Input voltage L3: %f\n", gun_index, (float)ShmCharger->gun_info[gun_index].inputVoltage.L3N_L31);
+									DEBUG_INFO("MCU-%d get PresentChargingVoltage L3: %.2f\n", gun_index, (float)ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargingVoltageL3);
+								}
+
+								previousCharger.gun_info[gun_index].inputVoltage.L1N_L12 = ShmCharger->gun_info[gun_index].inputVoltage.L1N_L12;
+								previousCharger.gun_info[gun_index].inputVoltage.L2N_L23 = ShmCharger->gun_info[gun_index].inputVoltage.L2N_L23;
+								previousCharger.gun_info[gun_index].inputVoltage.L3N_L31 = ShmCharger->gun_info[gun_index].inputVoltage.L3N_L31;
 							}
+							*/
 
 							logIndex = 0;
 							break;

+ 382 - 35
EVSE/Projects/AW-CCS/Apps/main.c

@@ -37,6 +37,7 @@
 #define GPIO_OUT_RST_RFID				62
 #define GPIO_OUT_RST_4G					114
 #define GPIO_OUT_RST_QCA				115
+#define GPIO_OUT_RST_ETH				89
 
 #define MtdBlockSize 					0x600000
 
@@ -1194,6 +1195,43 @@ int CreatShareMemory()
 //===============================================
 // SQLite3 related routine
 //===============================================
+int getReceiptInfo(uint8_t gun_index, char *receiptInfo)
+{
+	int result = PASS;
+	double totalEnergy=0.0;
+	double totalPrice=0.0;
+
+	json_object *receipt = json_object_new_object();
+	json_object *receiptAry = json_object_new_array();
+
+	for(uint8_t idxHour=0;idxHour<ARRAY_SIZE(ShmCharger->gun_info[gun_index].presentChargedEnergyPeriod);idxHour++)
+	{
+		json_object *receiptDetail = json_object_new_object();
+
+		json_object_object_add(receiptDetail, "hour", json_object_new_int(idxHour));
+		json_object_object_add(receiptDetail, "chargedEnergy", json_object_new_double(ShmCharger->gun_info[gun_index].presentChargedEnergyPeriod[idxHour]));
+		json_object_object_add(receiptDetail, "unitPrice", json_object_new_double(ShmSysConfigAndInfo->SysConfig.BillingData.Fee[idxHour]));
+		json_object_object_add(receiptDetail, "periodPrice", json_object_new_double(ShmCharger->gun_info[gun_index].presentChargedEnergyPeriod[idxHour]*ShmSysConfigAndInfo->SysConfig.BillingData.Fee[idxHour]));
+
+		totalEnergy += ShmCharger->gun_info[gun_index].presentChargedEnergyPeriod[idxHour];
+		totalPrice += ShmCharger->gun_info[gun_index].presentChargedEnergyPeriod[idxHour]*ShmSysConfigAndInfo->SysConfig.BillingData.Fee[idxHour];
+
+		json_object_array_add(receiptAry, receiptDetail);
+	}
+	json_object_object_add(receipt, "receiptDetail", receiptAry);
+	json_object_object_add(receipt, "totalChargedEnergy", json_object_new_double(totalEnergy));
+	json_object_object_add(receipt, "totalPrice", json_object_new_double(totalPrice));
+	json_object_object_add(receipt, "serviceProvider", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor));
+	json_object_object_add(receipt, "serviceProviderAddress", json_object_new_string("Address"));
+	json_object_object_add(receipt, "serviceProviderTel", json_object_new_string("TEL"));
+	json_object_object_add(receipt, "chargerBoxId", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.ChargeBoxId));
+
+	sprintf(receiptInfo, "%s", json_object_to_json_string_ext(receipt, JSON_C_TO_STRING_PLAIN));
+	json_object_put(receipt);
+
+	return result;
+}
+
 int DB_Open(sqlite3 *db)
 {
 	int result = PASS;
@@ -1213,6 +1251,20 @@ int DB_Open(sqlite3 *db)
 						  "finalCost text"
 						  ");";
 
+	char* createRecordBufSql="CREATE TABLE IF NOT EXISTS charging_record_buffer("
+						  "reservationId text, "
+						  "transactionId text, "
+						  "startMethod text, "
+						  "userId text, "
+						  "dateTimeStart text, "
+						  "dateTimeStop text,"
+						  "socStart text, "
+						  "socStop text, "
+						  "chargeEnergy text, "
+						  "stopReason text, "
+						  "finalCost text"
+						  ");";
+
 	char* createCfgSql="CREATE TABLE IF NOT EXISTS `config` ( "
 					   "`idx` INTEGER PRIMARY KEY AUTOINCREMENT, "
 					   "`item` TEXT NOT NULL, "
@@ -1240,6 +1292,16 @@ int DB_Open(sqlite3 *db)
 			DEBUG_INFO( "Opened local charging record table successfully\n");
 		}
 
+		if (sqlite3_exec(db, createRecordBufSql, 0, 0, &errMsg) != SQLITE_OK)
+		{
+			result = FAIL;
+			DEBUG_ERROR( "Create local charging record buffer table error message: %s\n", errMsg);
+		}
+		else
+		{
+			DEBUG_INFO( "Opened local charging record buffer table successfully\n");
+		}
+
 		if (sqlite3_exec(db, createCfgSql, 0, 0, &errMsg) != SQLITE_OK)
 		{
 			result = FAIL;
@@ -1256,11 +1318,166 @@ int DB_Open(sqlite3 *db)
 	return result;
 }
 
+int DB_Check_Record_Buf(sqlite3 *db, int gun_index)
+{
+	int result = PASS;
+	char* errMsg = NULL;
+	char sqlStr[4096];
+	char **rs;
+	int	 rows, cols;
+
+	if(sqlite3_open(DB_FILE, &db))
+	{
+		result = FAIL;
+		DEBUG_INFO( "Can't open database: %s\n", sqlite3_errmsg(db));
+		sqlite3_close(db);
+	}
+	else
+	{
+		sqlite3_get_table(db, "select * from charging_record_buffer", &rs, &rows, &cols, &errMsg);
+
+		if(rows>0)
+		{
+			// Copy record buffer
+			for(int idxRow=1;idxRow<=rows;idxRow++)
+			{
+				if(strcmp(rs[(idxRow*cols)+3], "0") == 0)
+				{
+					result = false;
+				}
+
+				sprintf(sqlStr, "insert into charging_record(reservationId, transactionId, startMethod, userId, dateTimeStart, dateTimeStop, socStart, socStop, chargeEnergy, stopReason, finalCost) "
+		 					    "values('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s');",
+								rs[(idxRow*cols)+0],
+								rs[(idxRow*cols)+1],
+								rs[(idxRow*cols)+2],
+								rs[(idxRow*cols)+3],
+								rs[(idxRow*cols)+4],
+								rs[(idxRow*cols)+5],
+								rs[(idxRow*cols)+6],
+								rs[(idxRow*cols)+7],
+								rs[(idxRow*cols)+8],
+								rs[(idxRow*cols)+9],
+								rs[(idxRow*cols)+10]);
+
+				if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
+				{
+					result = FAIL;
+					DEBUG_INFO( "Copy local charging record buffer error message: %s\n", errMsg);
+				}
+				else
+				{
+					DEBUG_INFO( "Copy local charging record buffer successfully\n");
+				}
+			}
+
+			// Delete buffer
+			if (sqlite3_exec(db, "delete from charging_record_buffer", 0, 0, &errMsg) != SQLITE_OK)
+			{
+				result = FAIL;
+				DEBUG_INFO( "Delete local charging record buffer error message: %s\n", errMsg);
+			}
+			else
+			{
+				DEBUG_INFO( "Delete local charging record buffer successfully\n");
+			}
+		}
+		else
+		{
+			DEBUG_INFO("There is not any charging record buffer.\n", gun_index);
+		}
+
+		sqlite3_free_table(rs);
+		sqlite3_close(db);
+	}
+
+	return result;
+}
+
+int DB_Update_Record_Buf(sqlite3 *db, int gun_index)
+{
+	int result = PASS;
+	char* errMsg = NULL;
+	char sqlStr[4096];
+
+	if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
+	{
+		sprintf(sqlStr, "insert into charging_record_buffer(reservationId, transactionId, startMethod, userId, dateTimeStart, dateTimeStop, socStart, socStop, chargeEnergy, stopReason, finalCost) "
+ 					    "values('%d', '%d', '%d', '%s', '%s', '%s', '%d', '%d', '%f', '%s', '%s');",
+					    ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].ReservationId,
+					    ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId,
+					    ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartMethod,
+					    ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartUserId,
+					    ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartDateTime,
+					    ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StopDateTime,
+					    ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc,
+					    ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc,
+					    ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargedEnergy,
+					    "Power Loss",
+					    ShmOCPP16Data->Cost.FinalCost[gun_index].description);
+	}
+	else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
+	{
+		sprintf(sqlStr, "insert into charging_record_buffer(reservationId, transactionId, startMethod, userId, dateTimeStart, dateTimeStop, socStart, socStop, chargeEnergy, stopReason, finalCost) "
+ 					    "values('%d', '%s', '%d', '%s', '%s', '%s', '%d', '%d', '%f', '%s', '%f');",
+					    ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].ReservationId,
+					    ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId,
+					    ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartMethod,
+					    ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartUserId,
+					    ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartDateTime,
+					    ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StopDateTime,
+					    ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc,
+					    ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].EvBatterySoc,
+					    ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PresentChargedEnergy,
+					    "Power Loss",
+					    ShmOCPP20Data->CostUpdated.totalCost);
+	}
+
+	if(sqlite3_open(DB_FILE, &db))
+	{
+		result = FAIL;
+		DEBUG_INFO( "Can't open database: %s\n", sqlite3_errmsg(db));
+		sqlite3_close(db);
+	}
+	else
+	{
+		// Delete buffer
+		if (sqlite3_exec(db, "delete from charging_record_buffer", 0, 0, &errMsg) != SQLITE_OK)
+		{
+			result = FAIL;
+			DEBUG_INFO( "Delete local charging record buffer error message: %s\n", errMsg);
+		}
+		else
+		{
+			//DEBUG_INFO( "Delete local charging record buffer successfully\n");
+		}
+
+		// Insert record buffer
+		if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
+		{
+			result = FAIL;
+			DEBUG_INFO( "Insert local charging record buffer error message: %s\n", errMsg);
+		}
+		else
+		{
+			//DEBUG_INFO( "Insert local charging record buffer successfully\n");
+		}
+
+		sqlite3_close(db);
+	}
+
+	return result;
+}
+
 int DB_Insert_Record(sqlite3 *db, int gun_index)
 {
 	int result = PASS;
 	char* errMsg = NULL;
-	char sqlStr[1024];
+	char sqlStr[4096];
+	char receiptInfo[2048];
+
+	getReceiptInfo(gun_index, receiptInfo);
+	DEBUG_INFO("Receipt Info: %s\n", receiptInfo);
 
 	if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
 	{
@@ -1294,6 +1511,7 @@ int DB_Insert_Record(sqlite3 *db, int gun_index)
 					    ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.stoppedReason,
 					    ShmOCPP20Data->CostUpdated.totalCost);
 	}
+	//DEBUG_INFO("sqlStr= %s\n", sqlStr);
 
 	if(sqlite3_open(DB_FILE, &db))
 	{
@@ -1303,7 +1521,18 @@ int DB_Insert_Record(sqlite3 *db, int gun_index)
 	}
 	else
 	{
-		DEBUG_INFO( "Local charging record database open successfully.\n");
+		// Delete buffer
+		if (sqlite3_exec(db, "delete from charging_record_buffer", 0, 0, &errMsg) != SQLITE_OK)
+		{
+			result = FAIL;
+			DEBUG_INFO( "Delete local charging record buffer error message: %s\n", errMsg);
+		}
+		else
+		{
+			DEBUG_INFO( "Delete local charging record buffer successfully\n");
+		}
+
+		// Insert charging record
 		if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
 		{
 			result = FAIL;
@@ -1346,10 +1575,8 @@ int DB_Update_Operactive(sqlite3 *db, uint8_t gun_index, uint8_t isOperactive)
 	}
 	else
 	{
-		DEBUG_INFO( "Local charging record database open successfully.\n");
-
 		sprintf(sqlStr, "insert or replace into config (item, connector, val) values('isOperactive', %d, %d);", gun_index, isOperactive);
-		DEBUG_INFO("sqlStr= %s\n", sqlStr);
+		//DEBUG_INFO("sqlStr= %s\n", sqlStr);
 		if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
 		{
 			result = FAIL;
@@ -1385,7 +1612,6 @@ int DB_Get_Operactive(sqlite3 *db, uint8_t gun_index)
 	}
 	else
 	{
-		DEBUG_INFO( "Local config query database open successfully.\n");
 		sqlite3_get_table(db, sqlStr, &rs, &rows, &cols, &errMsg);
 
 		if(rows>0)
@@ -1411,6 +1637,7 @@ int DB_Get_Operactive(sqlite3 *db, uint8_t gun_index)
 	return result;
 }
 
+
 //======================================================
 // Peripheral initial
 //======================================================
@@ -1458,6 +1685,13 @@ void InitGPIO()
 	system("echo \"out\" > /sys/class/gpio/gpio65/direction");
 	system("echo 0 > /sys/class/gpio/gpio65/value");
 
+	/*Ethernet RST:GPIO2_25 => H:ON; L:OFF*/
+	system("echo 89 > /sys/class/gpio/export");
+	system("echo \"out\" > /sys/class/gpio/gpio89/direction");
+	system("echo 0 > /sys/class/gpio/gpio89/value");
+	sleep(3);
+	system("echo 1 > /sys/class/gpio/gpio89/value");
+
 	/*4G/Wifi RST:GPIO3_18 => H:ON; L:OFF*/
 	system("echo 114 > /sys/class/gpio/export");
 	system("echo \"out\" > /sys/class/gpio/gpio114/direction");
@@ -1479,13 +1713,13 @@ void InitGPIO()
 	system("echo 0 > /sys/class/gpio/gpio115/value");
 	sleep(3);
 	system("echo 1 > /sys/class/gpio/gpio115/value");
-	sleep(1);
 
 	/*RFID RST: GPIO1_30 => H:OFF; L:ON*/
 	system("echo 62 > /sys/class/gpio/export");
 	system("echo \"out\" > /sys/class/gpio/gpio62/direction");
 	system("echo 0 > /sys/class/gpio/gpio62/value");
 
+	sleep(1);
 	DEBUG_INFO("Initial GPIO OK\n");
 }
 
@@ -2330,7 +2564,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.53.00.0000.00");
+	sprintf((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev, "D0.54.00.0000.00");
 
 	// Get AC connector type from model name
 	for(uint8_t idx=0;idx<3;idx++)
@@ -2608,6 +2842,54 @@ int isMatchStartUser(unsigned char gun_index)
 	return ((strcmp((char*)tmpUser, (char*)ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartUserId)==0)?YES:NO);
 }
 
+int isMatchPresentUser()
+{
+	uint8_t tmpUser[32];
+
+	if(ShmSysConfigAndInfo->SysConfig.RfidCardNumEndian)
+	{
+		// Big endian
+		switch(rfid.snType)
+		{
+			case RFID_SN_TYPE_6BYTE:
+				sprintf((char*)tmpUser, "%02X%02X%02X%02X%02X%02X", rfid.currentCard[0], rfid.currentCard[1], rfid.currentCard[2], rfid.currentCard[3], rfid.currentCard[4], rfid.currentCard[5]);
+				break;
+			case RFID_SN_TYPE_7BYTE:
+				sprintf((char*)tmpUser, "%02X%02X%02X%02X%02X%02X%02X", rfid.currentCard[0], rfid.currentCard[1], rfid.currentCard[2], rfid.currentCard[3], rfid.currentCard[4], rfid.currentCard[5], rfid.currentCard[6]);
+				break;
+			case RFID_SN_TYPE_10BYTE:
+				sprintf((char*)tmpUser, "%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X", rfid.currentCard[0], rfid.currentCard[1], rfid.currentCard[2], rfid.currentCard[3], rfid.currentCard[4], rfid.currentCard[5], rfid.currentCard[6], rfid.currentCard[7], rfid.currentCard[8], rfid.currentCard[9]);
+				break;
+			case RFID_SN_TYPE_4BYTE:
+			default:
+				sprintf((char*)tmpUser, "%02X%02X%02X%02X", rfid.currentCard[0], rfid.currentCard[1], rfid.currentCard[2], rfid.currentCard[3]);
+				break;
+		}
+	}
+	else
+	{
+		// Little endian
+		switch(rfid.snType)
+		{
+			case RFID_SN_TYPE_6BYTE:
+				sprintf((char*)tmpUser, "%02X%02X%02X%02X%02X%02X", rfid.currentCard[5], rfid.currentCard[4], rfid.currentCard[3], rfid.currentCard[2], rfid.currentCard[1], rfid.currentCard[0]);
+				break;
+			case RFID_SN_TYPE_7BYTE:
+				sprintf((char*)tmpUser, "%02X%02X%02X%02X%02X%02X%02X", rfid.currentCard[6], rfid.currentCard[5], rfid.currentCard[4], rfid.currentCard[3], rfid.currentCard[2], rfid.currentCard[1], rfid.currentCard[0]);
+				break;
+			case RFID_SN_TYPE_10BYTE:
+				sprintf((char*)tmpUser, "%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X", rfid.currentCard[9], rfid.currentCard[8], rfid.currentCard[7], rfid.currentCard[6], rfid.currentCard[5], rfid.currentCard[4], rfid.currentCard[3], rfid.currentCard[2], rfid.currentCard[1], rfid.currentCard[0]);
+				break;
+			case RFID_SN_TYPE_4BYTE:
+			default:
+				sprintf((char*)tmpUser, "%02X%02X%02X%02X", rfid.currentCard[3], rfid.currentCard[2], rfid.currentCard[1], rfid.currentCard[0]);
+				break;
+		}
+	}
+
+	return ((strcmp((char*)tmpUser, (char*)ShmSysConfigAndInfo->SysConfig.UserId)==0)?YES:NO);
+}
+
 //===============================================
 //	Read RFID Serial Number
 //===============================================
@@ -2722,7 +3004,7 @@ void setRequest(unsigned char gun_index,unsigned char isOn)
 		if(ShmCharger->gun_info[gun_index].legacyRequest.isLegacyRequest == OFF)
 		{
 			ShmCharger->gun_info[gun_index].legacyRequest.isLegacyRequest = ON;
-			DEBUG_INFO("Gun-%d Output relay sts: ON \n",gun_index);
+			DEBUG_INFO("Gun-%d permission request: ON \n",gun_index);
 		}
 	}
 	else
@@ -2730,7 +3012,7 @@ void setRequest(unsigned char gun_index,unsigned char isOn)
 		if(ShmCharger->gun_info[gun_index].legacyRequest.isLegacyRequest == ON)
 		{
 			ShmCharger->gun_info[gun_index].legacyRequest.isLegacyRequest = OFF;
-			DEBUG_INFO("Gun-%d Output relay sts: OFF \n",gun_index);
+			DEBUG_INFO("Gun-%d permission request: OFF \n",gun_index);
 		}
 	}
 }
@@ -2752,22 +3034,69 @@ void setRelay(unsigned char gun_index,unsigned char isOn)
 	{
 		if(ShmCharger->gun_info[gun_index].legacyRequest.isRelayOn == OFF)
 		{
-			ShmCharger->gun_info[gun_index].legacyRequest.isRelayOn = ON;
-			ShmCharger->gun_info[gun_index].primaryMcuState.relayState.relay_status[0][0] = 0x01;
-			ShmCharger->gun_info[gun_index].primaryMcuState.relayState.relay_status[0][1] = 0x01;
-			ShmCharger->gun_info[gun_index].primaryMcuState.relayState.relay_status[0][2] = 0x01;
-			DEBUG_INFO("Gun-%d Output relay sts: ON \n",gun_index);
+			switch(ShmCharger->gun_info[gun_index].chargingMode)
+			{
+				case CHARGING_MODE_BS:
+				case CHARGING_MODE_HLC:
+					ShmCharger->gun_info[gun_index].legacyRequest.isRelayOn = ON;
+					ShmCharger->gun_info[gun_index].primaryMcuState.relayState.relay_status[0][0] = 0x01;
+					ShmCharger->gun_info[gun_index].primaryMcuState.relayState.relay_status[0][1] = 0x01;
+					ShmCharger->gun_info[gun_index].primaryMcuState.relayState.relay_status[0][2] = 0x01;
+
+					if(ShmCharger->gun_info[gun_index].chargingMode == CHARGING_MODE_BS)
+						DEBUG_INFO("Gun-%d Output relay status: ON. [CHARGING_MODE_BS] \n",gun_index);
+					else if(ShmCharger->gun_info[gun_index].chargingMode == CHARGING_MODE_HLC)
+						DEBUG_INFO("Gun-%d Output relay status: ON. [CHARGING_MODE_HLC] \n",gun_index);
+
+					break;
+				case CHARGING_MODE_SOCKETE:
+					ShmCharger->gun_info[gun_index].legacyRequest.isRelayOn = ON;
+					ShmCharger->gun_info[gun_index].primaryMcuState.relayState.relay_status[0][3] = 0x01;
+					DEBUG_INFO("Gun-%d Output relay status: ON. [CHARGING_MODE_SOCKETE] \n",gun_index);
+					break;
+				default:
+					ShmCharger->gun_info[gun_index].legacyRequest.isRelayOn = ON;
+					ShmCharger->gun_info[gun_index].primaryMcuState.relayState.relay_status[0][0] = 0x01;
+					ShmCharger->gun_info[gun_index].primaryMcuState.relayState.relay_status[0][1] = 0x01;
+					ShmCharger->gun_info[gun_index].primaryMcuState.relayState.relay_status[0][2] = 0x01;
+					DEBUG_INFO("Gun-%d Output relay status: ON. [DEFFAULT] \n",gun_index);
+					break;
+			}
 		}
 	}
 	else
 	{
 		if(ShmCharger->gun_info[gun_index].legacyRequest.isRelayOn == ON)
 		{
-			ShmCharger->gun_info[gun_index].legacyRequest.isRelayOn = OFF;
-			ShmCharger->gun_info[gun_index].primaryMcuState.relayState.relay_status[0][0] = 0;
-			ShmCharger->gun_info[gun_index].primaryMcuState.relayState.relay_status[0][1] = 0;
-			ShmCharger->gun_info[gun_index].primaryMcuState.relayState.relay_status[0][2] = 0;
-			DEBUG_INFO("Gun-%d Output relay sts: OFF \n",gun_index);
+			switch(ShmCharger->gun_info[gun_index].chargingMode)
+			{
+				case CHARGING_MODE_BS:
+				case CHARGING_MODE_HLC:
+					ShmCharger->gun_info[gun_index].legacyRequest.isRelayOn = OFF;
+					ShmCharger->gun_info[gun_index].primaryMcuState.relayState.relay_status[0][0] = 0;
+					ShmCharger->gun_info[gun_index].primaryMcuState.relayState.relay_status[0][1] = 0;
+					ShmCharger->gun_info[gun_index].primaryMcuState.relayState.relay_status[0][2] = 0;
+
+					if(ShmCharger->gun_info[gun_index].chargingMode == CHARGING_MODE_BS)
+						DEBUG_INFO("Gun-%d Output relay status: OFF. [CHARGING_MODE_BS] \n",gun_index);
+					else if(ShmCharger->gun_info[gun_index].chargingMode == CHARGING_MODE_HLC)
+						DEBUG_INFO("Gun-%d Output relay status: OFF. [CHARGING_MODE_HLC] \n",gun_index);
+
+					DEBUG_INFO("Gun-%d Output relay status: OFF. \n",gun_index);
+					break;
+				case CHARGING_MODE_SOCKETE:
+					ShmCharger->gun_info[gun_index].legacyRequest.isRelayOn = OFF;
+					ShmCharger->gun_info[gun_index].primaryMcuState.relayState.relay_status[0][3] = 0;
+					DEBUG_INFO("Gun-%d Output relay status: OFF. [CHARGING_MODE_SOCKETE] \n",gun_index);
+					break;
+				default:
+					ShmCharger->gun_info[gun_index].legacyRequest.isRelayOn = OFF;
+					ShmCharger->gun_info[gun_index].primaryMcuState.relayState.relay_status[0][0] = 0;
+					ShmCharger->gun_info[gun_index].primaryMcuState.relayState.relay_status[0][1] = 0;
+					ShmCharger->gun_info[gun_index].primaryMcuState.relayState.relay_status[0][2] = 0;
+					DEBUG_INFO("Gun-%d Output relay status: OFF. [DEFFAULT] \n",gun_index);
+					break;
+			}
 		}
 	}
 }
@@ -3901,6 +4230,15 @@ void checkRfidAuthrize()
 
 					if(DiffTimebWithNow(startTime[0][TMR_IDX_GUN_DETECT]) < (ocpp_get_connection_timeout()*1000))
 					{
+						if(GetCardSerialNumber() != FAIL)
+						{
+							if(isMatchPresentUser())
+							{
+								DEBUG_INFO("Cancel present user.\n");
+								ShmCharger->isAuthrizing = FALSE;
+							}
+						}
+
 						for(int gun_index = 0;gun_index<AC_QUANTITY;gun_index++)
 						{
 							if(DiffTimebWithNow(startTime[0][TMR_IDX_GUN_DETECT]) < 3000)
@@ -3908,7 +4246,7 @@ void checkRfidAuthrize()
 							else
 								setLedMotion(gun_index,LED_ACTION_AUTHED);
 
-							if((((ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].SystemStatus == SYS_MODE_IDLE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].SystemStatus == SYS_MODE_RESERVATION)) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PilotState == CP_STATE_B) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PilotState == CP_STATE_C))) ||
+							if((((ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].SystemStatus == SYS_MODE_IDLE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].SystemStatus == SYS_MODE_RESERVATION)) && (((ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PilotState == CP_STATE_B) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PilotState == CP_STATE_C)) || (ShmCharger->gun_info[gun_index].primaryMcuState.socket_e.isSocketEPinOn == ON))) ||
 							   (((ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].SystemStatus == SYS_MODE_TERMINATING)) && (ShmCharger->gun_selectd == gun_index))
 							   )
 							{
@@ -4014,8 +4352,8 @@ int main(void)
 		//==============================================
 		// Something need run in Idle mode
 		//==============================================
-		if(((ShmSysConfigAndInfo->SysInfo.AcChargingData[0].SystemStatus==SYS_MODE_IDLE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[0].SystemStatus==SYS_MODE_ALARM)) &&
-		   (AC_QUANTITY>1?((ShmSysConfigAndInfo->SysInfo.AcChargingData[1].SystemStatus==SYS_MODE_IDLE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[1].SystemStatus==SYS_MODE_ALARM)):true))
+		if(((ShmSysConfigAndInfo->SysInfo.AcChargingData[0].SystemStatus==SYS_MODE_IDLE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[0].SystemStatus==SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[0].SystemStatus==SYS_MODE_DEBUG)) &&
+		   (AC_QUANTITY>1?((ShmSysConfigAndInfo->SysInfo.AcChargingData[1].SystemStatus==SYS_MODE_IDLE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[1].SystemStatus==SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[1].SystemStatus==SYS_MODE_DEBUG)):true))
 		{
 			// Check restore factory setting request
 			if(ShmSysConfigAndInfo->SysInfo.FactoryConfiguration)
@@ -4372,6 +4710,7 @@ int main(void)
 						ShmCharger->gun_info[gun_index].isDoEvReadyOnce = OFF;
 						ShmCharger->gun_info[gun_index].resultAuthorization = DEFAULT_RFID;
 						if(ShmCharger->isCcsEnable)system("pkill Module_CCS");
+						DB_Check_Record_Buf(localDb, gun_index);
 					}
 
 					if(((ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_DISABLE) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PilotState == CP_STATE_B)) ||
@@ -4575,9 +4914,9 @@ int main(void)
 										ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PowerConsumption = (ShmCharger->gun_info[gun_index].powerConsumptionTotal.power_consumption/10000.0);
 									else
 									{
-										//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);
+										//ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PowerConsumption[0] = (ShmCharger->gun_info[gun_index].powerConsumption[0].power_consumption/10000.0);
+										//ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PowerConsumption[1] = (ShmCharger->gun_info[gun_index].powerConsumption[1].power_consumption/10000.0);
+										//ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PowerConsumption[2] = (ShmCharger->gun_info[gun_index].powerConsumption[2].power_consumption/10000.0);
 									}
 
 									memcpy((char*)ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartUserId, ShmSysConfigAndInfo->SysConfig.UserId, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.UserId));
@@ -4676,9 +5015,9 @@ int main(void)
 										ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PowerConsumption = (ShmCharger->gun_info[gun_index].powerConsumptionTotal.power_consumption/10000.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/10000.0);
+										//ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PowerConsumption[1] = (ShmCharger->gun_info[gun_index].powerConsumption[1].power_consumption/10000.0);
+										//ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PowerConsumption[2] = (ShmCharger->gun_info[gun_index].powerConsumption[2].power_consumption/10000.0);
 									}
 
 									memcpy((char*)ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartUserId, ShmSysConfigAndInfo->SysConfig.UserId, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.UserId));
@@ -4842,9 +5181,9 @@ int main(void)
 							ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PowerConsumption = (ShmCharger->gun_info[gun_index].powerConsumptionTotal.power_consumption/10000.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/10000.0);
+							//ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PowerConsumption[1] = (ShmCharger->gun_info[gun_index].powerConsumption[1].power_consumption/10000.0);
+							//ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PowerConsumption[2] = (ShmCharger->gun_info[gun_index].powerConsumption[2].power_consumption/10000.0);
 						}
 
 						ftime(&endChargingTime[gun_index]);
@@ -5046,12 +5385,15 @@ int main(void)
 						// Debug information
 						if(DiffTimebWithNow(startTime[gun_index][TMR_IDX_LOGPPRINTOUT]) > TIMEOUT_SPEC_LOGPPRINTOUT)
 						{
-							DEBUG_INFO("===============================================================\n");
+							DEBUG_INFO("==============================================================\n");
 							DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent: %d \n", ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
 							DEBUG_INFO("ShmCharger->gun_info[%d].primaryMcuCp_Pwn_Duty.max_current: %d\n", gun_index, ShmCharger->gun_info[gun_index].primaryMcuCp_Pwn_Duty.max_current);
 							DEBUG_INFO("ShmCharger->gun_info[%d].targetCurrent: %d\n", gun_index, ShmCharger->gun_info[gun_index].targetCurrent);
-							DEBUG_INFO("===============================================================\n");
+							DEBUG_INFO("==============================================================\n");
 							ftime(&startTime[gun_index][TMR_IDX_LOGPPRINTOUT]);
+							
+							getDateTimeString((char*)ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StopDateTime);
+							DB_Update_Record_Buf(localDb, gun_index);
 						}
 					}
 
@@ -5111,6 +5453,10 @@ int main(void)
 							setRelay(gun_index,OFF);
 							ShmCharger->gun_info[gun_index].isCCSWaitChangeDuty = ON;
 						}
+						else
+						{
+							setChargerMode(gun_index, SYS_MODE_COMPLETE);
+						}
 					}
 					else
 					{
@@ -5166,7 +5512,8 @@ int main(void)
 					}
 					
 					if(((ShmCharger->gun_info[gun_index].chargingMode != CHARGING_MODE_SOCKETE) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PilotState == CP_STATE_A)) ||
-					   ((ShmCharger->gun_info[gun_index].chargingMode == CHARGING_MODE_SOCKETE) && (!ShmCharger->gun_info[gun_index].primaryMcuState.socket_e.isSocketEPinOn)))
+					   ((ShmCharger->gun_info[gun_index].chargingMode == CHARGING_MODE_SOCKETE) && (!ShmCharger->gun_info[gun_index].primaryMcuState.socket_e.isSocketEPinOn)) ||
+					   ocpp_get_reset_req())
 					{
 						ShmCharger->gun_info[gun_index].rfidReq = OFF;
 						ShmCharger->gun_info[gun_index].bleConfigData.isRequestStop = OFF;

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

@@ -76,6 +76,7 @@
 #define ALARM_L2_CIRCUIT_SHORT                  0x04000000
 #define ALARM_L3_CIRCUIT_SHORT                  0x08000000
 #define ALARM_METER_TIMEOUT						0x10000000
+#define ALARM_METER_IC_TIMEOUT					0x20000000
 
 //=================================
 //CCS related define
@@ -418,6 +419,7 @@ typedef struct AC_PRIMARY_MCU_ALARM
 			unsigned long short_circuit_L2:1;
 			unsigned long short_circuit_L3:1;
 			unsigned long meter_comm_timeout:1;
+			unsigned long meter_ic_comm_timeout:1;
 		}bits;
 	};
 }Ac_Primary_Mcu_Alarm;

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


BIN
EVSE/Projects/AW-CCS/Images/MLO


BIN
EVSE/Projects/AW-CCS/Images/am335x-evm.dtb


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


BIN
EVSE/Projects/AW-CCS/Images/u-boot-spl.bin


BIN
EVSE/Projects/AW-CCS/Images/u-boot.img


BIN
EVSE/Projects/AW-CCS/Images/zImage


+ 194 - 16
EVSE/Projects/DO360/Apps/Config.h

@@ -11,8 +11,7 @@
 
 typedef unsigned char			    byte;
 
-#define TOTAL_QUANTITY_GUN			4				//Max Count
-
+
 #define MODE_BOOT					0
 #define MODE_IDLE					1
 #define MODE_AUTHORIZING			2
@@ -56,12 +55,19 @@ typedef unsigned char			    byte;
 
 // **********  Audi ********** //
 // Model Name: DOYC182000D2AD
+// Model Name: DDYC182V0UE2AD
 
 // ********** e4you ********** //
 // Model Name: DKYE182000D1E4
+// Model Name: DXYE182E00E1E4
 
 // ********** xpeng ********** //
 // Model Name: DOYE362000D2XP
+// Model Name: DDYE362F0KE2XP
+
+// *********** BYD *********** //
+// Model Name: DOYE242000D2BD
+// Model Name: DDYE242V0UE2BD
 
 enum _SYSTEM_STATUS
 {
@@ -294,6 +300,8 @@ typedef union
     unsigned int CtrlValue;
     struct
     {
+        unsigned int NeedSoftReset:1;               // 0: no effect,                1: system need soft reset
+        unsigned int NeedHardReset:1;               // 0: no effect,                1: system need hard reset
         unsigned int SelfTestOK:1;                  // 0: self test not completed,  1: self test ok
         unsigned int PrimaryDisable:1;              // 0: primary enable,           1: primary disable
         unsigned int RelayBoardDisable:1;           // 0: relay board enable,       1: relay board disable
@@ -302,10 +310,49 @@ typedef union
         unsigned int SecondRelayBoardEnable:1;      // 0: second relay disable,     1: second relay enable
         unsigned int StandardLedIndication:1;       // 0: no led indication,        1: enable standard led indication
         unsigned int E4YOULedIndication:1;          // 0: no led indication,        1: enable e4you led indication
-        unsigned int res:24;
+        unsigned int res:22;
     }bits;
 }SystemControl;
 
+typedef union
+{
+    unsigned int CtrlValue;
+    struct
+    {
+        unsigned int DisableBalance:1;              // 0: no effect,                1: disable announce balance
+        unsigned int FastStandbyTime:1;             // 0: no effect,                1: enable fast standby time
+        unsigned int ChargingSimulation:1;          // 0: no effect,                1: enable charging simulation
+        unsigned int res:29;
+    }bits;
+}TestControl;
+
+typedef union
+{
+    unsigned int CtrlValue;
+    struct
+    {
+        unsigned int res:32;
+    }bits;
+}DebugControl;
+
+typedef union
+{
+    unsigned int CtrlValue;
+    struct
+    {
+        unsigned int EnableForceCharging:1;         // 0: disable,                  1: enable force charging
+        unsigned int StartForceCharging:1;          // 0: disable,                  1: start force charging
+        unsigned int res:30;
+    }bits;
+}ForceChargingControl;
+
+typedef struct
+{
+    ForceChargingControl    FCtrl;
+    unsigned short          FTargetVoltage;         // target voltage, unit: 0.1V
+    unsigned short          FTargetCurrent;         // target current, unit: 0.1A
+}ForceCharging;
+
 typedef union
 {
     unsigned int AuthFlag;
@@ -387,12 +434,17 @@ typedef union
 
 typedef struct
 {
+    unsigned char   MaxDispenser;
+    unsigned char   MaxConnector;
     SystemControl   SysCtrl;
+    TestControl     TestCtrl;
+    DebugControl    DebugCtrl;
     PrimaryControl  PrimaryCtrl;
     RelayControl    RelayCtrl;
     FanControl      FanCtrl;
     LedFanControl   LedCtrl;
     PsuControl      PsuCtrl;
+    ForceCharging   FCharging[MAX_GROUP_QUANTITY];
 }SysControl;
 // ************************************************************************************************* //
 typedef struct
@@ -400,7 +452,7 @@ typedef struct
     bool          CheckIn;
     unsigned char Address;
     unsigned char GroupNo;
-    unsigned char Index;
+    unsigned char GIndex;
 }PsuAddressInfoData;
 
 typedef struct
@@ -420,32 +472,158 @@ typedef struct
 // ************************************************************************************************* //
 typedef enum
 {
-    _GROLE_IDLE             = 0,
-    _GROLE_MASTER           = 1,
-    _GROLE_SLAVE            = 2,
-    _GROLE_SWITCH_TO_IDLE   = 10,
-    _GROLE_SWITCH_IDLE_OK   = 11,
-    _GROLE_SWITCH_TO_MASTER = 20,
-    _GROLE_SWITCH_MASTER_OK = 21,
-    _GROLE_SWITCH_TO_SLAVE  = 30,
-    _GROLE_SWITCH_SLAVE_OK  = 31,
+    _GROLE_IDLE                 = 0,
+    _GROLE_MASTER               = 1,
+    _GROLE_SLAVE                = 2,
+    _GROLE_PREPARE_SWITCH_OFF   = 10,           // reduce output current capability
+    _GROLE_SLAVE_POWER_OFF      = 11,           // power off
+    _GROLE_SWITCH_OFF_OK        = 12,           // power off completed
+    _GROLE_WAIT_IDLE            = 13,           // wait a while to change to idle, open parallel relay at this state
+    _GROLE_WAIT_SLAVE           = 14,           // wait a while to change to slave
+    _GROLE_PREPARE_ATTACH_ON    = 20,           // raise voltage to master output voltage
+    _GROLE_PRECHARGE_READY      = 21,           // extend pre-charge ready
+    _GROLE_EXTEND_STOP          = 22,           // extend capability stop
+    _GROLE_REQUEST_TO_CHARGING  = 30,
+    _GROLE_TERMINATE            = 40,
+    _GROLE_WAIT_TERMINATED      = 41,
+    _GROLE_NONE                 = 99,
 }_GROUP_ROLE;
 
+typedef union
+{
+    unsigned int CtrlValue[6];
+    struct
+    {
+        unsigned int IdleCtrlValue;
+        unsigned int MasterCtrlValue;
+        unsigned int StopChargingCtrlValue;
+        unsigned int DeratingCtrlValue;
+        unsigned int ExtendCapabilityCtrlValue;
+        unsigned int SlaveCtrlValue;
+    }RoleCtrl;
+    struct
+    {
+        // IdleCtrlValue
+        unsigned int ChargingRequest:1;                         // 0: no effect,                1: charging request from main.c
+        unsigned int ChargingRequestConfirmed:1;                // 0: no effect,                1: request confirmed by psu task
+        unsigned int GroupShareCheck:1;                         // 0: no effect,                1: check is there any psu can share
+        unsigned int ShareConfirmed:1;                          // 0: no effect,                1: psu share confirmed
+        unsigned int GrabGroupWait:1;                           // 0: no effect,                1: need to wait grab psu
+        unsigned int ShareCheckDone:1;                          // 0: no effect,                1: psu share completed
+        unsigned int FindGroupPartner:1;                        // 0: no effect,                1: find available group partner
+        unsigned int ParallelRelayOn:1;                         // 0: no effect,                1: set parallel relay on
+        unsigned int ParallelRelayConfirmed:1;                  // 0: no effect,                1: parallel relay confirmed
+        unsigned int GroupingDone:1;                            // 0: no effect,                1: grouping completed
+        unsigned int IdleCtrlRes:22;
+
+        // MasterCtrlValue
+        unsigned int AlreadyInChargingMode:1;                   // 0: no effect,                1: system status ever enter charging mode
+        unsigned int ExtendAvailable:1;                         // 0: no effect,                1: extend capability is available
+        unsigned int NeedCurrentBalanceCheck:1;                 // 0: no effect,                1: need to current balance
+        unsigned int OutputCurrentStable:1;                     // 0: no effect,                1: output current is stable
+        unsigned int MasterCtrlRes:28;
+
+        // StopChargingCtrlValue
+        unsigned int StopChargingRequest:1;                     // 0: no effect,                1: master need to stop
+        unsigned int StopChargingConfirmed:1;                   // 0: no effect,                1: stop charging confirmed
+        unsigned int AllPowerOffDone:1;                         // 0: no effect,                1: all member power off done
+        unsigned int AllParallelRelayOff:1;                     // 0: no effect,                1: all member's parallel relay off
+        unsigned int AllParallelRelayConfirmed:1;               // 0: no effect,                1: all member's parallel relay off confirmed
+        unsigned int AllMemberStopCompleted:1;                  // 0: no effect,                1: all member stop completed
+        unsigned int StopChargingCompleted:1;                   // 0: no effect,                1: stop charging completed
+        unsigned int StopChargingCtrlRes:25;
+
+        // DeratingCtrlValue
+        unsigned int NeedDerating:1;                            // 0: no effect,                1: need derating
+        unsigned int DeratingConfirmed:1;                       // 0: no effect,                1: derating confirmed
+        unsigned int DeratingStart:1;                           // 0: no effect,                1: derating start
+        unsigned int DeratingPowerOffDone:1;                    // 0: no effect,                1: derating member power off done
+        unsigned int DeratingRelayOff:1;                        // 0: no effect,                1: set derating member parallel relay off
+        unsigned int DeratingRelayConfirmed:1;                  // 0: no effect,                1: derating member parallel relay confirmed
+        unsigned int DeratingCompleted:1;                       // 0: no effect,                1: derating completed
+        unsigned int DeratingCtrlRes:25;
+
+        // ExtendCapabilityCtrlValue
+        unsigned int MorePowerRequest:1;                        // 0: no effect,                1: need to request more psu
+        unsigned int MorePowerConfirmed:1;                      // 0: no effect,                1: request more psu confirmed
+        unsigned int ExtendPrecharge:1;                         // 0: no effect,                1: extend group need to pre-charge
+        unsigned int ExtendPrechargeDone:1;                     // 0: no effect,                1: extend group pre-charge completed
+        unsigned int ExtendRelayOn:1;                           // 0: no effect,                1: extend group parallel relay on
+        unsigned int ExtendRelayConfirmed:1;                    // 0: no effect,                1: extend group parallel relay confirmed
+        unsigned int ExtendCompleted:1;                         // 0: no effect,                1: extend capability completed
+        unsigned int ExtendCapabilityCtrlRes:25;
+
+        // SlaveCtrlValue
+        unsigned int SlaveChargingRequest:1;                    // 0: no effect,                1: request slave to charging after power off
+        unsigned int SlavePowerOffRequest:1;                    // 0: no effect,                1: request slave to power off
+        unsigned int SlavePowerOffConfirmed:1;                  // 0: no effect,                1: slave power off confirmed
+        unsigned int SlaveCtrlRes:29;
+    }bits;
+}PsuGroupControl;
+
+typedef struct
+{
+    unsigned short          Quantity;
+    unsigned char           Member[MAX_GROUP_QUANTITY];         // record slave group index
+}PsuGroupPartner;
+
 typedef struct
 {
     unsigned char           Index;
     unsigned char           Role;
+    unsigned char           PreRole;
     unsigned char           Location;
-    unsigned char           GroupMemberQuantity;
-    unsigned char           GroupMember[MAX_GROUP_QUANTITY];
-    unsigned char           TargetGroup;                        // group index + 1
+    PsuGroupPartner         Partner;                            // record slave group information
+    PsuGroupPartner         PossibleMember;                     // record possible slave group information
+    unsigned char           TargetGroup;                        // target group index + 1
+    unsigned char           ReservedTarget;                     // reserved target group index + 1
+    PsuGroupControl         GroupCtrl;
+    unsigned short          ReAssignAvailableCurrent;           // group available current when reassign, unit: 0.1A
+    unsigned short          ParallelCheck;
+    unsigned char           ParallelConfig[MAX_GROUP_QUANTITY]; // group parallel relay setting
+    unsigned short          GunLoading;                         // gun output loading, unit: 0.01%
 }PsuGroupCollectionData;
 
+typedef struct
+{
+    unsigned short          GTargetVoltage;                     // group target voltage config, unit: 0.1V
+    unsigned short          GTargetCurrent;                     // group target current config, unit: 0.1A
+    unsigned short          OutputLoading;                      // group output loading, unit: 0.01%
+}GroupOutputConfigInfo;
+
+typedef union
+{
+    unsigned short CtrlValue;
+    struct
+    {
+        unsigned short Output_N:1;                              // 0: set Output_N off,         1: set Output_N on
+        unsigned short Output_P:1;                              // 0: set Output_P off,         1: set Output_P on
+        unsigned short res:14;
+    }bits;
+}PsuGroupOutputRelay;
+
+typedef union
+{
+    unsigned short CtrlValue;
+    struct
+    {
+        unsigned short Location_1_2:1;                          // 0: set parallel off,         1: set parallel on
+        unsigned short Location_2_3:1;                          // 0: set parallel off,         1: set parallel on
+        unsigned short Location_3_4:1;                          // 0: set parallel off,         1: set parallel on
+        unsigned short res:13;
+    }bits;
+}PsuGroupParallelRelay;
+
 typedef struct
 {
     byte                    Location[MAX_GROUP_QUANTITY];
     byte                    Layout[MAX_GROUP_QUANTITY];
     PsuGroupCollectionData  GroupCollection[MAX_GROUP_QUANTITY];
+    GroupOutputConfigInfo   GroupOutput[MAX_GROUP_QUANTITY];
+    PsuGroupOutputRelay     OutputRelayConfig[MAX_GROUP_QUANTITY];
+    PsuGroupOutputRelay     OutputRelayConfirmed[MAX_GROUP_QUANTITY];
+    PsuGroupParallelRelay   ParallelRelayConfig;
+    PsuGroupParallelRelay   ParallelRelayConfirmed;
 }PsuGroupingInfoData;
 // ************************************************************************************************* //
 

+ 15 - 6
EVSE/Projects/DO360/Apps/FactoryConfig.c

@@ -105,8 +105,16 @@ int main(int argc,char *argv[])
 	*/
 	//********** System **********// udhcpc -i eth1 -s ./dhcp_script/eth1.script
 	//
-	strcpy((char *)SysConfig.ModelName, "DOYC182000D2AD");
-	strcpy((char *)SysConfig.SerialNumber, "NeedSetupSN");
+    if (argc == 4)
+    {
+        strcpy((char *)SysConfig.ModelName, argv[2]);
+        strcpy((char *)SysConfig.SerialNumber, argv[3]);
+    }
+    else
+    {
+        strcpy((char *)SysConfig.ModelName, "DOYC182000D2AD");
+        strcpy((char *)SysConfig.SerialNumber, "NeedSetupSN");
+    }
 
 	memset(SysConfig.SystemId, 0x00, sizeof(SysConfig.SystemId));
 
@@ -147,10 +155,8 @@ int main(int argc,char *argv[])
 	strcpy((char *) SysConfig.Eth1Interface.EthIpAddress, "192.168.100.1");
 	strcpy((char *) SysConfig.Eth1Interface.EthSubmaskAddress, "255.255.255.0");
 	strcpy((char *) SysConfig.Eth1Interface.EthGatewayAddress, "192.168.0.254");
-	if(SysConfig.ModelName[10] == 'W')
-		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;
@@ -185,6 +191,9 @@ int main(int argc,char *argv[])
 	strcpy((char *) SysConfig.ChargeBoxId, "");
 	SysConfig.LedInfo.Intensity = 2;
 
+	// clean power cabinet wiring info
+	memset((char *)&SysConfig.WiringInfo, 0x00, sizeof(WiringInfoData));
+
 	//copy default configuration to pointer
 	memcpy(ptr,&SysConfig,sizeof(struct SysConfigData));
 

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

@@ -951,6 +951,9 @@ void ConnectorIDResponse(int socket, struct PACKET_STRUCTURE *packet, unsigned c
 	send(socket, &sendBuffer, sendBuffer.Header.len + 4, 0);
 }
 
+// more message for debug
+struct PACKET_STRUCTURE CabinetStatusToDispenser[4];
+
 void PowerCabinetStatusResponse(int socket, struct PACKET_STRUCTURE *packet, unsigned char dispenserIndex)
 {
 	struct PACKET_STRUCTURE sendBuffer;
@@ -985,6 +988,40 @@ void PowerCabinetStatusResponse(int socket, struct PACKET_STRUCTURE *packet, uns
         memcpy(&sendBuffer.Payload.data[1 + (ShmSysConfigAndInfo->SysWarningInfo.WarningCount * 6)], &MiscEventCode[0], 6);
     }
 
+    bool need_copy = false;
+    if(sendBuffer.Header.len != CabinetStatusToDispenser[sendBuffer.Header.id].Header.len ||
+        sendBuffer.Header.op != CabinetStatusToDispenser[sendBuffer.Header.id].Header.op ||
+        sendBuffer.Payload.reg != CabinetStatusToDispenser[sendBuffer.Header.id].Payload.reg ||
+        sendBuffer.Payload.data[0] != CabinetStatusToDispenser[sendBuffer.Header.id].Payload.data[0])
+    {
+        need_copy = true;
+    }
+    else
+    {
+        for(int i = 0; i < sendBuffer.Header.len - 2; i++)
+        {
+            if(sendBuffer.Payload.data[1 + i] != CabinetStatusToDispenser[sendBuffer.Header.id].Payload.data[1 + i])
+            {
+                need_copy = true;
+            }
+        }
+    }
+    if(need_copy)
+    {
+        char str[256];
+        memcpy(&CabinetStatusToDispenser[sendBuffer.Header.id], &sendBuffer, sizeof(struct PACKET_STRUCTURE));
+
+        sprintf(str, "Status Code Update To %d:", sendBuffer.Header.id);
+
+        for(int i = 0; i < CabinetStatusToDispenser[sendBuffer.Header.id].Header.len - 2; i++)
+        {
+            char temp[8];
+            sprintf(temp, " %02X", CabinetStatusToDispenser[sendBuffer.Header.id].Payload.data[1 + i]);
+            strcat(str, temp);
+        }
+        PRINTF_FUNC("%s", str);
+    }
+
 	send(socket, &sendBuffer, sendBuffer.Header.len + 4, 0);
 }
 
@@ -1284,6 +1321,7 @@ void MiscControlResponse(int socket, struct PACKET_STRUCTURE *packet, unsigned c
             AddMiscCommand(&sendBuffer, &misc);
         }
 
+        // announce misc command to first connector of the dispenser
         if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].ConnectorID[0] == packet->Header.id)
         {
             if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].Setting.bits.ConnectorTimeoutConfigRequest)
@@ -1322,7 +1360,7 @@ void MiscControlResponse(int socket, struct PACKET_STRUCTURE *packet, unsigned c
                 misc.Command = _MiscCmd_BackendStatus;
                 misc.Value = ShmSysConfigAndInfo->SysInfo.CabinetMicsStatus.BackendStatus;
 
-                PRINTF_FUNC("Announce Connector %d BackendStatus: %d", packet->Header.id, (misc.Value));
+                PRINTF_FUNC("Announce Dispenser %d BackendStatus: %d", dispenserIndex + 1, (misc.Value));
                 AddMiscCommand(&sendBuffer, &misc);
             }
 
@@ -1332,7 +1370,7 @@ void MiscControlResponse(int socket, struct PACKET_STRUCTURE *packet, unsigned c
                 misc.Command = _MiscCmd_EthernetStatus;
                 misc.Value = ShmSysConfigAndInfo->SysInfo.CabinetMicsStatus.EthernetStatus;
 
-                PRINTF_FUNC("Announce Connector %d EthernetStatus: %d", packet->Header.id, (misc.Value));
+                PRINTF_FUNC("Announce Dispenser %d EthernetStatus: %d", dispenserIndex + 1, (misc.Value));
                 AddMiscCommand(&sendBuffer, &misc);
             }
 
@@ -1342,7 +1380,7 @@ void MiscControlResponse(int socket, struct PACKET_STRUCTURE *packet, unsigned c
                 misc.Command = _MiscCmd_WiFiStatus;
                 misc.Value = ShmSysConfigAndInfo->SysInfo.CabinetMicsStatus.WiFiStatus;
 
-                PRINTF_FUNC("Announce Connector %d WiFiStatus: %d", packet->Header.id, (misc.Value));
+                PRINTF_FUNC("Announce Dispenser %d WiFiStatus: %d", dispenserIndex + 1, (misc.Value));
                 AddMiscCommand(&sendBuffer, &misc);
             }
 
@@ -1352,7 +1390,27 @@ void MiscControlResponse(int socket, struct PACKET_STRUCTURE *packet, unsigned c
                 misc.Command = _MiscCmd_4GStatus;
                 misc.Value = ShmSysConfigAndInfo->SysInfo.CabinetMicsStatus.TelcomModemStatus;
 
-                PRINTF_FUNC("Announce Connector %d TelcomModemStatus: %d", packet->Header.id, (misc.Value));
+                PRINTF_FUNC("Announce Dispenser %d TelcomModemStatus: %d", dispenserIndex + 1, (misc.Value));
+                AddMiscCommand(&sendBuffer, &misc);
+            }
+
+            if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].Setting.bits.BillingStatusRequest)
+            {
+                ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].Setting.bits.BillingStatusRequest = false;
+                misc.Command = _MiscCmd_Billing;
+                misc.Value = ShmSysConfigAndInfo->SysInfo.CabinetMicsStatus.BillingStatus;
+
+                PRINTF_FUNC("Announce Dispenser %d %s Billing Information", dispenserIndex + 1, misc.Value ? "Enable" : "Disable");
+                AddMiscCommand(&sendBuffer, &misc);
+            }
+
+            if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].Setting.bits.StopButtonStatusRequest)
+            {
+                ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].Setting.bits.StopButtonStatusRequest = false;
+                misc.Command = _MiscCmd_StopButton;
+                misc.Value = ShmSysConfigAndInfo->SysInfo.CabinetMicsStatus.StopChargingButton;
+
+                PRINTF_FUNC("Announce Dispenser %d %s Stop Charging Button", dispenserIndex + 1, misc.Value ? "Enable" : "Disable");
                 AddMiscCommand(&sendBuffer, &misc);
             }
 
@@ -1618,25 +1676,23 @@ void DispenserCheckInInfoUpdate(void)
 			ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].LocalStatus != _DS_Timeout)
 		{
 			dispenser++;
-			ShmSysConfigAndInfo->SysInfo.DispenserInfo.CheckInLog.Status |= (1 << i);
-			ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectorLog[i] = ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].ConnectorQuantity;
 			connector += ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].ConnectorQuantity;
 		}
 	}
 
-	if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.DispenserQuantity != dispenser ||
-		ShmSysConfigAndInfo->SysInfo.DispenserInfo.TotalConnectorQuantity != connector)
+	if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.PresentDispenserQuantity != dispenser ||
+		ShmSysConfigAndInfo->SysInfo.DispenserInfo.PresentConnectorQuantity != connector)
 	{
 		change = true;
 	}
-	ShmSysConfigAndInfo->SysInfo.DispenserInfo.DispenserQuantity = dispenser;
-	ShmSysConfigAndInfo->SysInfo.DispenserInfo.TotalConnectorQuantity = connector;
+	ShmSysConfigAndInfo->SysInfo.DispenserInfo.PresentDispenserQuantity = dispenser;
+	ShmSysConfigAndInfo->SysInfo.DispenserInfo.PresentConnectorQuantity = connector;
 
 	if(change)
 	{
 		PRINTF_FUNC("Total Dispenser: %d, Total Connector: %d\n",
-			ShmSysConfigAndInfo->SysInfo.DispenserInfo.DispenserQuantity,
-			ShmSysConfigAndInfo->SysInfo.DispenserInfo.TotalConnectorQuantity);
+			ShmSysConfigAndInfo->SysInfo.DispenserInfo.PresentDispenserQuantity,
+			ShmSysConfigAndInfo->SysInfo.DispenserInfo.PresentConnectorQuantity);
 	}
 }
 
@@ -1660,6 +1716,29 @@ void SetConnectorID(unsigned char dispenserIndex, unsigned char quantity)
 	}
 }
 
+BOOL CheckNewDispenserSequence(unsigned char index, unsigned char quantity)
+{
+    if(index == ShmSysConfigAndInfo->SysConfig.WiringInfo.DispenserSequence)
+    {
+        PRINTF_FUNC("Get New Dispenser %d, Connector Quantity: %d\n", index + 1, quantity);
+
+        ShmSysConfigAndInfo->SysInfo.DispenserInfo.CheckInLog.Status |= (1 << index);
+        ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectorLog[index] = quantity;
+
+        ShmSysConfigAndInfo->SysConfig.WiringInfo.DispenserSequence = index + 1;
+        ShmSysConfigAndInfo->SysConfig.WiringInfo.MaxConnectorQuantity += quantity;
+        ShmSysConfigAndInfo->SysConfig.WiringInfo.WiringSetting[index] = quantity;
+        ShmSysConfigAndInfo->SysInfo.CabinetSetting.bits.WiringInfoChanged = true;
+
+        ShmSysConfigAndInfo->SysInfo.DispenserInfo.DispenserQuantity = ShmSysConfigAndInfo->SysConfig.WiringInfo.DispenserSequence;
+        ShmSysConfigAndInfo->SysInfo.DispenserInfo.TotalConnectorQuantity = ShmSysConfigAndInfo->SysConfig.WiringInfo.MaxConnectorQuantity;
+
+        return true;
+    }
+
+    return false;
+}
+
 BOOL DispenserIdentificationHandler(struct PACKET_STRUCTURE *packet, unsigned char dispenserIndex, unsigned char *modelName)
 {
 	unsigned char quantity = 0;
@@ -1671,18 +1750,27 @@ BOOL DispenserIdentificationHandler(struct PACKET_STRUCTURE *packet, unsigned ch
 
 	if(quantity > 0)
 	{
-		if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].LocalStatus == _DS_Timeout &&
+		if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectorLog[dispenserIndex] != 0 &&
 			quantity != ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectorLog[dispenserIndex])
 		{
 			PRINTF_FUNC("The same dispenser id (%d) but connector quantity not match", dispenserIndex + 1);
 			return false;
 		}
+        if(dispenserIndex == ShmSysConfigAndInfo->SysConfig.WiringInfo.DispenserSequence &&
+            (quantity + ShmSysConfigAndInfo->SysInfo.DispenserInfo.TotalConnectorQuantity) > ShmChargerInfo->Control.MaxConnector)
+        {
+            PRINTF_FUNC("Dispenser %d connector quantity %d over range, total quantity: %d",
+                dispenserIndex + 1, quantity, ShmSysConfigAndInfo->SysInfo.DispenserInfo.TotalConnectorQuantity);
+            return false;
+        }
 		if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].LocalStatus == _DS_None ||
 			ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].LocalStatus == _DS_Timeout)
 		{
+            CheckNewDispenserSequence(dispenserIndex, quantity);
+
 			ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].LocalStatus = _DS_Identification;
 			ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].ConnectorQuantity = quantity;
-			ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectorLog[dispenserIndex] = quantity;
+
 			SetConnectorID(dispenserIndex, quantity);
 			memcpy(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].ModelName, packet->Payload.data, (packet->Header.len - 2));
 
@@ -1701,7 +1789,7 @@ BOOL DispenserIdentificationHandler(struct PACKET_STRUCTURE *packet, unsigned ch
 	}
 	else
 	{
-		PRINTF_FUNC("Connector quantity fail, model name: %s", modelName);
+        PRINTF_FUNC("Connector quantity fail, model name: %s", modelName);
 	}
 	return false;
 }
@@ -2399,7 +2487,8 @@ void DispenserSocketProcess(int socketFd, struct sockaddr_in clientInfo, unsigne
 						memset(modelName, 0x00, 64);
 						dispenserID = receiveBuffer.Payload.data[receiveBuffer.Header.len - 2];
 
-						if(dispenserID > 0 && dispenserID <= GENERAL_GUN_QUANTITY)
+						if(dispenserID > 0 && dispenserID <= GENERAL_GUN_QUANTITY &&
+                            dispenserID <= ShmChargerInfo->Control.MaxDispenser)
 						{
 						    dispenserIndex = dispenserID - 1;
 						    memcpy(modelName, receiveBuffer.Payload.data, receiveBuffer.Header.len - 2);
@@ -2466,13 +2555,15 @@ void DispenserSocketProcess(int socketFd, struct sockaddr_in clientInfo, unsigne
                                 ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].Setting.bits.DispenserConfigSync = true;
 
                                 PRINTF_FUNC("Dispenser ID %d Configuration Need To Synchronize", dispenserID);
-                                ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].Setting.bits.ConnectorTimeoutConfigRequest = 1;
-                                ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].Setting.bits.DefaultPriceConfigRequest = 1;
-                                ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].Setting.bits.CurrencyConfigRequest = 1;
-                                ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].Setting.bits.BackendStatusRequest = 1;
-                                ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].Setting.bits.EthernetStatusRequest = 1;
-                                ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].Setting.bits.WiFiStatusRequest = 1;
-                                ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].Setting.bits.TelcomModemStatusRequest = 1;
+                                ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].Setting.bits.ConnectorTimeoutConfigRequest = true;
+                                ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].Setting.bits.DefaultPriceConfigRequest = true;
+                                ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].Setting.bits.CurrencyConfigRequest = true;
+                                ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].Setting.bits.BackendStatusRequest = true;
+                                ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].Setting.bits.EthernetStatusRequest = true;
+                                ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].Setting.bits.WiFiStatusRequest = true;
+                                ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].Setting.bits.TelcomModemStatusRequest = true;
+                                ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].Setting.bits.BillingStatusRequest = true;
+                                ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenserIndex].Setting.bits.StopButtonStatusRequest = true;
                             }
 						}
 					}
@@ -2737,8 +2828,10 @@ void InitDispenserInfo(void)
 	}
 
     //memset(&ShmSysConfigAndInfo->SysInfo.DispenserInfo, 0x00, sizeof(struct DispenserInfoData));
-    ShmSysConfigAndInfo->SysInfo.DispenserInfo.DispenserQuantity = 0;
-    ShmSysConfigAndInfo->SysInfo.DispenserInfo.TotalConnectorQuantity = 0;
+    ShmSysConfigAndInfo->SysInfo.DispenserInfo.DispenserQuantity = ShmSysConfigAndInfo->SysConfig.WiringInfo.DispenserSequence;
+    ShmSysConfigAndInfo->SysInfo.DispenserInfo.TotalConnectorQuantity = ShmSysConfigAndInfo->SysConfig.WiringInfo.MaxConnectorQuantity;
+    ShmSysConfigAndInfo->SysInfo.DispenserInfo.PresentDispenserQuantity = 0;
+    ShmSysConfigAndInfo->SysInfo.DispenserInfo.PresentConnectorQuantity = 0;
     for(int i = 0; i < GENERAL_GUN_QUANTITY; i++)
     {
         unsigned char localStatus = 0;
@@ -2746,8 +2839,23 @@ void InitDispenserInfo(void)
         memset(&ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i], 0x00, sizeof(struct DispenserModule));
         ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].LocalStatus = localStatus;
     }
-    //ShmSysConfigAndInfo->SysInfo.DispenserInfo.CheckInLog.Status = 0;
-    //memset(ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectorLog, 0x00, sizeof(ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectorLog));
+
+    // initial CheckInLog from WiringInfo.DispenserSequence
+    ShmSysConfigAndInfo->SysInfo.DispenserInfo.CheckInLog.Status = 0;
+    for(int i = 0; i < ShmSysConfigAndInfo->SysConfig.WiringInfo.DispenserSequence; i++)
+    {
+        ShmSysConfigAndInfo->SysInfo.DispenserInfo.CheckInLog.Status |= (1 << i);
+    }
+
+    // initial ConnectorLog from WiringInfo.WiringSetting
+    memset(ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectorLog, 0x00, sizeof(ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectorLog));
+    for(int i = 0; i < ShmSysConfigAndInfo->SysConfig.WiringInfo.DispenserSequence; i++)
+    {
+        if(i < GENERAL_GUN_QUANTITY)
+        {
+            ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectorLog[i] = ShmSysConfigAndInfo->SysConfig.WiringInfo.WiringSetting[i];
+        }
+    }
     memset(ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo, 0x00, sizeof(ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo));
     ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectorTimeout = 0;
     ShmSysConfigAndInfo->SysInfo.DispenserInfo.DefaultPrice = 0;

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

@@ -175,6 +175,8 @@ enum MiscCommand
     _MiscCmd_EthernetStatus     = 0x0007,
     _MiscCmd_WiFiStatus         = 0x0008,
     _MiscCmd_4GStatus           = 0x0009,
+    _MiscCmd_Billing            = 0x000A,
+    _MiscCmd_StopButton         = 0x000B,
     _MiscCmd_HardwareReboot     = 0x0101,
     _MiscCmd_SoftwareRestart    = 0x0102,
     _MiscCmd_RemoteStart        = 0x0103,

+ 24 - 3
EVSE/Projects/DO360/Apps/Module_EventLogging.c

@@ -267,7 +267,7 @@ int main(void)
 	for(;;)
 	{
 		//check Fault Status
-		for(ByteCount=0;ByteCount<4;ByteCount++)
+		for(ByteCount=0;ByteCount<FaultCodeLength;ByteCount++)
 		{
 			if(ShmStatusCodeData->FaultCode.FaultEvents.FaultVal[ByteCount] != ShmStatusCodeData->FaultCode.PreviousFaultVal[ByteCount])
 			{
@@ -278,6 +278,13 @@ int main(void)
 					{
 						memset(EventCodeTmp,0,sizeof(EventCodeTmp));
 						memcpy(EventCodeTmp,FaultStatusCode[ByteCount*8+BitCount],sizeof(EventCodeTmp)-1);
+
+                        // modify power cabinet status code X1XXXX to X4XXXX
+                        if(EventCodeTmp[1] == '1')
+                        {
+                            EventCodeTmp[1] = '4';
+                        }
+
 						if(((tmp>>BitCount)&0x01)==0)//Recovered
 						{
 							//EventCodeTmp[0]=1;
@@ -297,7 +304,7 @@ int main(void)
 		}
 
 		//check Alarm Status
-		for(ByteCount=0;ByteCount<16;ByteCount++)
+		for(ByteCount=0;ByteCount<AlarmCodeLength;ByteCount++)
 		{
 			if(ShmStatusCodeData->AlarmCode.AlarmEvents.AlarmVal[ByteCount] != ShmStatusCodeData->AlarmCode.PreviousAlarmVal[ByteCount])
 			{
@@ -308,6 +315,13 @@ int main(void)
 					{
 						memset(EventCodeTmp,0,sizeof(EventCodeTmp));
 						memcpy(EventCodeTmp,AlarmStatusCode[ByteCount*8+BitCount],sizeof(EventCodeTmp)-1);
+
+                        // modify power cabinet status code X1XXXX to X4XXXX
+                        if(EventCodeTmp[1] == '1')
+                        {
+                            EventCodeTmp[1] = '4';
+                        }
+
 						if(((tmp>>BitCount)&0x01)==0)//Recovered
 						{
 							//EventCodeTmp[0]=1;
@@ -333,7 +347,7 @@ int main(void)
 		}
 
 		//check Info Status
-		for(ByteCount=0;ByteCount<40;ByteCount++)
+		for(ByteCount=0;ByteCount<InfoCodeLength;ByteCount++)
 		{
 			if(ShmStatusCodeData->InfoCode.InfoEvents.InfoVal[ByteCount] != ShmStatusCodeData->InfoCode.PreviousInfoVal[ByteCount])
 			{
@@ -344,6 +358,13 @@ int main(void)
 					{
 						memset(EventCodeTmp,0,sizeof(EventCodeTmp));
 						memcpy(EventCodeTmp,InfoStatusCode[ByteCount*8+BitCount],sizeof(EventCodeTmp)-1);
+
+                        // modify power cabinet status code X1XXXX to X4XXXX
+                        if(EventCodeTmp[1] == '1')
+                        {
+                            EventCodeTmp[1] = '4';
+                        }
+
 						if(((tmp>>BitCount)&0x01)==0)//Recovered
 						{
 							//EventCodeTmp[0]=1;

+ 2 - 2
EVSE/Projects/DO360/Apps/Module_InternalComm.c

@@ -851,7 +851,7 @@ void CheckK1K2RelayOutput(byte index)
                 _chargingData[index]->RelayK1K2Status = NO;
         }
 
-        if (regRelay[0].relay_event.bits.Gun1_Parallel_N == YES && regRelay[0].relay_event.bits.Gun1_Parallel_P == YES)
+        if (regRelay[0].relay_event.bits.Gun1_Parallel_N == YES && regRelay[0].relay_event.bits.Gun2_Parallel_N == YES)
             ShmSysConfigAndInfo->SysInfo.BridgeRelayStatus = YES;
         else
             ShmSysConfigAndInfo->SysInfo.BridgeRelayStatus = NO;
@@ -1189,7 +1189,7 @@ void SetParalleRelayStatus()
 	{
 		if (_chargingData[0]->SystemStatus == S_BOOTING || _chargingData[1]->SystemStatus == S_BOOTING ||
 				((_chargingData[0]->SystemStatus == S_IDLE || _chargingData[0]->SystemStatus == S_MAINTAIN || _chargingData[0]->SystemStatus == S_FAULT) &&
-				(_chargingData[1]->SystemStatus == S_IDLE || _chargingData[1]->SystemStatus == S_MAINTAIN || _chargingData[0]->SystemStatus == S_FAULT)))
+				(_chargingData[1]->SystemStatus == S_IDLE || _chargingData[1]->SystemStatus == S_MAINTAIN || _chargingData[1]->SystemStatus == S_FAULT)))
 		{
             if(ShmChargerInfo->Control.SysCtrl.bits.SecondRelayBoardEnable)
             {

+ 24 - 0
EVSE/Projects/DO360/Apps/Module_PsuComm.c

@@ -40,6 +40,9 @@ bool psuReceiveRecovery = false;
 float evseOutVol[CONNECTOR_QUANTITY] = {0, 0, 0, 0};
 float evseOutCur[CONNECTOR_QUANTITY] = {0, 0, 0, 0};
 struct timeval _PsuReceiveRecoveryCheck_time;
+int _initialCurrentDiff = 0;
+int _balanceCurrentDiff = 0;
+int _balanceDelay = 0;
 
 void PRINTF_FUNC(char *string, ...);
 
@@ -2094,6 +2097,9 @@ int main(void)
 							if (ShmSysConfigAndInfo->SysInfo.ReAssignedFlag == _REASSIGNED_ADJUST_A_TO_M)
 							{
 								bool balanceVol = true;
+								_initialCurrentDiff = 0;
+								_balanceCurrentDiff = 0;
+								_balanceDelay = 0;
 
 								for (byte subIndex = 0; subIndex < ShmPsuData->GroupCount; subIndex++)
 								{
@@ -2145,6 +2151,12 @@ int main(void)
 										chargingCurrent = ShmPsuData->PsuGroup[subIndex].GroupPresentOutputCurrent;
 								}
 
+								_balanceCurrentDiff = (chargingCurrent >= idleCurrent) ? (chargingCurrent - idleCurrent) : (idleCurrent - chargingCurrent);
+								if(_initialCurrentDiff == 0)
+								{
+								    _initialCurrentDiff = _balanceCurrentDiff;
+								}
+
 								if (idleCurrent >= chargingCurrent - PRE_CHARG_RANGE)
 								{
 									PRINTF_FUNC("=============Smart Charging_0 : _REASSIGNED_COMP============= Step 15 \n");
@@ -2155,6 +2167,18 @@ int main(void)
 									if ((GetTimeoutValue(_max_time) / 1000) > 500)
 									{
 										gettimeofday(&_max_time, NULL);
+										_balanceDelay++;
+										// 3s
+										if(_balanceDelay > 6)
+										{
+										    _balanceDelay = 0;
+										    int _changeDiff = (_initialCurrentDiff >= _balanceCurrentDiff) ? _initialCurrentDiff - _balanceCurrentDiff : _balanceCurrentDiff - _initialCurrentDiff;
+										    if(_changeDiff <= PRE_CHARG_RANGE)
+										    {
+										        PRINTF_FUNC("=============Smart Charging_0 : Current Change Difference %d Step 15\n", _changeDiff);
+			                                    ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_COMP;
+										    }
+										}
 									}
 								}
 							}

File diff suppressed because it is too large
+ 697 - 98
EVSE/Projects/DO360/Apps/ReadCmdline.c


File diff suppressed because it is too large
+ 388 - 302
EVSE/Projects/DO360/Apps/main.c


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


+ 8 - 5
EVSE/Projects/Noodoe/Apps/main.c

@@ -2466,7 +2466,10 @@ int main(void)
 				ShmOCPP16Data->MsMsg.bits.ResetReq = OFF;
 				sprintf((char*)ShmOCPP16Data->Reset.ResponseStatus, "Accepted");
 				ShmOCPP16Data->MsMsg.bits.ResetConf = ON;
-
+				
+				DEBUG_INFO("%s reset request by OCPP.\n", ShmOCPP16Data->Reset.Type);
+				for(int gun_index = 0;gun_index<AC_QUANTITY;gun_index++)
+					setChargerMode(gun_index, SYS_MODE_BOOTING);
 				if(strcmp((char*)ShmOCPP16Data->Reset.Type, "Hard") == 0)
 				{
 					system("sync");
@@ -3183,7 +3186,7 @@ int main(void)
 										   (((ShmOCPP16Data->SmartChargingProfile[gun_index].ChargingSchedule.ChargingSchedulePeriod[idx_period].StartPeriod == 0) && (ShmOCPP16Data->SmartChargingProfile[gun_index].ChargingSchedule.ChargingSchedulePeriod[idx_period].Limit != 0)) || (ShmOCPP16Data->SmartChargingProfile[gun_index].ChargingSchedule.ChargingSchedulePeriod[idx_period].StartPeriod > 0)))
 										{
 											ShmCharger->gun_info[gun_index].targetCurrent = (mystrcmp((char*)ShmOCPP16Data->SmartChargingProfile[gun_index].ChargingSchedule.ChargingRateUnit,"W")==PASS?ShmOCPP16Data->SmartChargingProfile[gun_index].ChargingSchedule.ChargingSchedulePeriod[idx_period].Limit/220:ShmOCPP16Data->SmartChargingProfile[gun_index].ChargingSchedule.ChargingSchedulePeriod[idx_period].Limit);
-											DEBUG_INFO("ShmCharger->gun_info[%d].targetCurrent on period[%d]: %d\n", gun_index, idx_period, ShmCharger->gun_info[gun_index].targetCurrent);
+											//DEBUG_INFO("ShmCharger->gun_info[%d].targetCurrent on period[%d]: %d\n", gun_index, idx_period, ShmCharger->gun_info[gun_index].targetCurrent);
 										}
 										else
 											break;
@@ -3203,7 +3206,7 @@ int main(void)
 										   (((ShmOCPP16Data->SmartChargingProfile[gun_index].ChargingSchedule.ChargingSchedulePeriod[idx_period].StartPeriod == 0) && (ShmOCPP16Data->SmartChargingProfile[gun_index].ChargingSchedule.ChargingSchedulePeriod[idx_period].Limit != 0)) || (ShmOCPP16Data->SmartChargingProfile[gun_index].ChargingSchedule.ChargingSchedulePeriod[idx_period].StartPeriod > 0)))
 										{
 											ShmCharger->gun_info[gun_index].targetCurrent = (mystrcmp((char*)ShmOCPP16Data->SmartChargingProfile[gun_index].ChargingSchedule.ChargingRateUnit,"W")==PASS?ShmOCPP16Data->SmartChargingProfile[gun_index].ChargingSchedule.ChargingSchedulePeriod[idx_period].Limit/220:ShmOCPP16Data->SmartChargingProfile[gun_index].ChargingSchedule.ChargingSchedulePeriod[idx_period].Limit);
-											DEBUG_INFO("ShmCharger->gun_info[%d].targetCurrent on period[%d]: %d\n", gun_index, idx_period, ShmCharger->gun_info[gun_index].targetCurrent);
+											//DEBUG_INFO("ShmCharger->gun_info[%d].targetCurrent on period[%d]: %d\n", gun_index, idx_period, ShmCharger->gun_info[gun_index].targetCurrent);
 										}
 										else
 											break;
@@ -3225,7 +3228,7 @@ int main(void)
 											   (((ShmOCPP16Data->SmartChargingProfile[gun_index].ChargingSchedule.ChargingSchedulePeriod[idx_period].StartPeriod == 0) && (ShmOCPP16Data->SmartChargingProfile[gun_index].ChargingSchedule.ChargingSchedulePeriod[idx_period].Limit != 0)) || (ShmOCPP16Data->SmartChargingProfile[gun_index].ChargingSchedule.ChargingSchedulePeriod[idx_period].StartPeriod > 0)))
 											{
 												ShmCharger->gun_info[gun_index].targetCurrent = (mystrcmp((char*)ShmOCPP16Data->SmartChargingProfile[gun_index].ChargingSchedule.ChargingRateUnit,"W")==PASS?ShmOCPP16Data->SmartChargingProfile[gun_index].ChargingSchedule.ChargingSchedulePeriod[idx_period].Limit/220:ShmOCPP16Data->SmartChargingProfile[gun_index].ChargingSchedule.ChargingSchedulePeriod[idx_period].Limit);
-												DEBUG_INFO("ShmCharger->gun_info[%d].targetCurrent on period[%d]: %d\n", gun_index, idx_period, ShmCharger->gun_info[gun_index].targetCurrent);
+												//DEBUG_INFO("ShmCharger->gun_info[%d].targetCurrent on period[%d]: %d\n", gun_index, idx_period, ShmCharger->gun_info[gun_index].targetCurrent);
 											}
 											else
 												break;
@@ -3240,7 +3243,7 @@ int main(void)
 											   (((ShmOCPP16Data->SmartChargingProfile[gun_index].ChargingSchedule.ChargingSchedulePeriod[idx_period].StartPeriod == 0) && (ShmOCPP16Data->SmartChargingProfile[gun_index].ChargingSchedule.ChargingSchedulePeriod[idx_period].Limit != 0)) || (ShmOCPP16Data->SmartChargingProfile[gun_index].ChargingSchedule.ChargingSchedulePeriod[idx_period].StartPeriod > 0)))
 											{
 												ShmCharger->gun_info[gun_index].targetCurrent = (mystrcmp((char*)ShmOCPP16Data->SmartChargingProfile[gun_index].ChargingSchedule.ChargingRateUnit,"W")==PASS?ShmOCPP16Data->SmartChargingProfile[gun_index].ChargingSchedule.ChargingSchedulePeriod[idx_period].Limit/220:ShmOCPP16Data->SmartChargingProfile[gun_index].ChargingSchedule.ChargingSchedulePeriod[idx_period].Limit);
-												DEBUG_INFO("ShmCharger->gun_info[%d].targetCurrent on period[%d]: %d\n", gun_index, idx_period, ShmCharger->gun_info[gun_index].targetCurrent);
+												//DEBUG_INFO("ShmCharger->gun_info[%d].targetCurrent on period[%d]: %d\n", gun_index, idx_period, ShmCharger->gun_info[gun_index].targetCurrent);
 											}
 											else
 												break;

+ 188 - 158
EVSE/Projects/define.h

@@ -169,6 +169,10 @@ Storage							0x0A200000-0x7FFFFFFF		1886 MB
 #define ShmOcpp20ModuleKey		1012
 #define ShmRelay2BdKey			1013
 
+#define FaultCodeLength         5
+#define AlarmCodeLength         16
+#define InfoCodeLength          41
+
 /**************************************************************************************/
 /****************** Share memory configuration value constant define ******************/
 /**************************************************************************************/
@@ -289,7 +293,7 @@ enum CoreProfile {
      DefaultPrice,
      CustomDisplayCostAndPrice,
      CustomIdleFeeAfterStop,
-	 ConfigurationVersion,
+     ConfigurationVersion,
 	 _CoreProfile_CNT
 };
 
@@ -401,10 +405,19 @@ typedef union
         unsigned int NormalStop:1;                  // 0: no effect,    1: normal stop
         unsigned int AlarmStop:1;                   // 0: no effect,    1: alarm stop
         unsigned int BackendStop:1;                 // 0: no effect,    1: backend stop
-        unsigned int res:29;
+        unsigned int ManualStop:1;                  // 0: no effect,    1: manual stop
+        unsigned int res:28;
     }bits;
 }ChargingStop;
 
+typedef struct
+{
+    unsigned char DispenserSequence;                    // dispenser sequence
+    unsigned char MaxConnectorQuantity;                 // max connector quantity
+    unsigned char WiringSetting[8];                     // record connector quantity of dispenser
+    unsigned char PowerCabinetReserved[32];
+}WiringInfoData;
+
 struct SysConfigData
 {
 	/**************System***************/
@@ -465,7 +478,10 @@ struct SysConfigData
 	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
-	unsigned char			StopChargingByButton;		//0: Disable  1: Enable
+	unsigned char           StopChargingByButton;       //0: Disable  1: Enable
+
+    /************PowerCabinet************/
+    WiringInfoData          WiringInfo;
 };
 
 struct ChargingInfoData
@@ -580,7 +596,9 @@ typedef union
         unsigned int EthernetStatusRequest:1;           // 0: no request,   1: ethernet connection status has changed           ( cabinet -> dispenser)
         unsigned int WiFiStatusRequest:1;               // 0: no request,   1: wifi connection status has changed               ( cabinet -> dispenser)
         unsigned int TelcomModemStatusRequest:1;        // 0: no request,   1: 4g connection status has changed                 ( cabinet -> dispenser)
-        unsigned int res:11;
+        unsigned int BillingStatusRequest:1;            // 0: no request,   1: billing status has changed                       ( cabinet -> dispenser)
+        unsigned int StopButtonStatusRequest:1;         // 0: no request,   1: stop charging button status has changed          ( cabinet -> dispenser)
+        unsigned int res:9;
     }bits;
 }DispenserSettingFlag;
 
@@ -636,10 +654,13 @@ struct ConnectionInfoData
 
 struct DispenserInfoData
 {
-    unsigned char               DispenserQuantity;
-    unsigned char               TotalConnectorQuantity;
+    unsigned char               DispenserQuantity;                  // record max dispenser quantity
+    unsigned char               TotalConnectorQuantity;             // record max connector quantity
     struct DispenserModule      Dispenser[GENERAL_GUN_QUANTITY];
 
+    unsigned char               PresentDispenserQuantity;
+    unsigned char               PresentConnectorQuantity;
+
     union
     {
         unsigned char Status;
@@ -747,7 +768,10 @@ typedef union
         unsigned int AuthorizingCompleted:1;    // 0: not yet, 1: authorizing completed
         unsigned int DispenserDisconnection:1;  // 0: no connection,  1: dispenser connected
         unsigned int BackendAuthorized:1;       // 0: local authorized, 1: backend authorized
-        unsigned int res:28;
+        unsigned int WiringInfoChanged:1;       // 0: no effect, 1: wiring info has changed
+        unsigned int EnableWriteWiringInfo:1;   // 0: no effect, 1: enable write wiring info after timeout
+        unsigned int CleanWiringInfo:1;         // 0: no effect, 1: clean wiring info
+        unsigned int res:25;
     }bits;
 }CabinetSettingFlag;
 
@@ -760,6 +784,8 @@ typedef struct
     unsigned int EthernetStatus;                // 0: disable, 1: connected, 2: disconnected
     unsigned int WiFiStatus;                    // 0: disable, 1: connected, 2: disconnected
     unsigned int TelcomModemStatus;             // 0: disable, 1: connected, 2: disconnected
+    unsigned int BillingStatus;                 // 0: disable, 1: enable
+    unsigned int StopChargingButton;            // 0: disable, 1: enable
     unsigned int HardwareReboot;                // 1: HardwareReboot, Other value: no effect
     unsigned int SoftwareRestart;               // 1: SoftwareRestart, Other value: no effect
 }CabinetMiscCommand;
@@ -982,10 +1008,10 @@ char FaultStatusCode[40][6]=
 
 struct FaultCodeData
 {
-	unsigned char PreviousFaultVal[5];
+	unsigned char PreviousFaultVal[FaultCodeLength];
 	union
 	{
-		unsigned char FaultVal[5];
+		unsigned char FaultVal[FaultCodeLength];
 		struct
 		{
 			//FaultVal[0]
@@ -1168,10 +1194,10 @@ char AlarmStatusCode[128][6]=
 };
 struct AlarmCodeData
 {
-	unsigned char PreviousAlarmVal[16];
+	unsigned char PreviousAlarmVal[AlarmCodeLength];
 	union
 	{
-		unsigned char AlarmVal[16];
+		unsigned char AlarmVal[AlarmCodeLength];
 		struct
 		{
 			//AlarmVal[0]
@@ -1650,10 +1676,10 @@ char InfoStatusCode[384][6]=
 };
 struct InfoCodeData
 {
-	unsigned char PreviousInfoVal[41];
+	unsigned char PreviousInfoVal[InfoCodeLength];
 	union
 	{
-		unsigned char InfoVal[41];
+		unsigned char InfoVal[InfoCodeLength];
 		struct
 		{
 			//InfoVal[0]
@@ -2075,6 +2101,10 @@ struct PsuGroupData
 	unsigned int            GroupPresentOutputPower;        //Watt
 	struct PsuModuleData 	PsuModule[MAX_PSU_QUANTITY];
 	PsuGroupError           GroupErrorFlag;
+    unsigned short          TotalIAvailableCurrent;         // unit: 0.1A
+    unsigned short          TempIAvailableCurrent;          // unit: 0.1A
+    unsigned short          StableIAvailableCurrent;        // unit: 0.1A
+    unsigned short          StableCurrentCounter;           // stable current counter
 };
 
 /*Following is the information for system all PSU*/
@@ -4222,104 +4252,104 @@ struct StructCost
 
 struct CertificateHashDataType
 {
-	unsigned char hashAlgorithm[8];								// Required. Used algorithms for the hashes provided.
-	unsigned char issuerNameHash[129];							// Required. hashed value of the IssuerName.
-	unsigned char issuerKeyHash[129];							// Required. Hashed value of the issuers public key
-	unsigned char serialNumber[41];								// Required. The serial number of the certificate.
+    unsigned char hashAlgorithm[8];                             // Required. Used algorithms for the hashes provided.
+    unsigned char issuerNameHash[129];                          // Required. hashed value of the IssuerName.
+    unsigned char issuerKeyHash[129];                           // Required. Hashed value of the issuers public key
+    unsigned char serialNumber[41];                             // Required. The serial number of the certificate.
 };
 
 struct LogParametersType
 {
-	unsigned char remoteLocation[513];								// Required. The URL of the location at the remote system where the log should be stored.
-	unsigned char oldestTimestamp[36];								// Optional. This contains the date and time of the oldest logging information to include in the diagnostics.
-	unsigned char latestTimestamp[36];								// Optional. This contains the date and time of the latest logging information to include in the diagnostics.
+    unsigned char remoteLocation[513];                              // Required. The URL of the location at the remote system where the log should be stored.
+    unsigned char oldestTimestamp[36];                              // Optional. This contains the date and time of the oldest logging information to include in the diagnostics.
+    unsigned char latestTimestamp[36];                              // Optional. This contains the date and time of the latest logging information to include in the diagnostics.
 };
 
 struct FirmwareType
 {
-	unsigned char location[513];									// Required. URI defining the origin of the firmware.
-	unsigned char retrieveDateTime[36];								// Required. Date and time at which the firmware shall be retrieved.
-	unsigned char installDateTime[36];								// Optional. Date and time at which the firmware shall be installed.
-	unsigned char signingCertificate[5501];							// Optional. Certificate with which the firmware was signed. X.509 certificate, first DER encoded into binary, and then Base64 encoded.
-	unsigned char signature[801];									// Optional. Base64 encoded firmware signature.
+    unsigned char location[513];                                    // Required. URI defining the origin of the firmware.
+    unsigned char retrieveDateTime[36];                             // Required. Date and time at which the firmware shall be retrieved.
+    unsigned char installDateTime[36];                              // Optional. Date and time at which the firmware shall be installed.
+    unsigned char signingCertificate[5501];                         // Optional. Certificate with which the firmware was signed. X.509 certificate, first DER encoded into binary, and then Base64 encoded.
+    unsigned char signature[801];                                   // Optional. Base64 encoded firmware signature.
 };
 
 struct StructCertificateSigned
 {
-	unsigned char certificateChain[10001];
-	unsigned char Response_status[16];
+    unsigned char certificateChain[10001];
+    unsigned char Response_status[16];
 };
 
 struct StructDeleteCertificate
 {
-	struct CertificateHashDataType certificateHashData;
-	unsigned char Response_status[16];
+    struct CertificateHashDataType certificateHashData;
+    unsigned char Response_status[16];
 };
 
 struct StructExtendedTrigger
 {
-	unsigned char requestedMessage[32];
-	int connectorId;
-	unsigned char Response_status[16];
+    unsigned char requestedMessage[32];
+    int connectorId;
+    unsigned char Response_status[16];
 };
 
 struct StructGetInstalledCertificateIds
 {
-	unsigned char certificateType[32];
-	unsigned char Response_status[16];
-	struct CertificateHashDataType Response_certificateHashData[3];
+    unsigned char certificateType[32];
+    unsigned char Response_status[16];
+    struct CertificateHashDataType Response_certificateHashData[3];
 };
 
 struct StructGetLog
 {
-	unsigned char logType[16];
-	int requestId;
-	int retries;
-	int retryInterval;
-	struct LogParametersType log;
-	unsigned char Response_status[16];
-	unsigned char Response_filename[256];
+    unsigned char logType[16];
+    int requestId;
+    int retries;
+    int retryInterval;
+    struct LogParametersType log;
+    unsigned char Response_status[16];
+    unsigned char Response_filename[256];
 };
 
 struct StructInstallCertificate
 {
-	unsigned char certificateType[32];
-	unsigned char certificate[5501];
-	unsigned char Response_status[16];
+    unsigned char certificateType[32];
+    unsigned char certificate[5501];
+    unsigned char Response_status[16];
 };
 
 struct StructSignedUpdateFirmware
 {
-	int retries;
-	int retryInterval;
-	int requestId;
-	struct FirmwareType firmware;
-	unsigned char Response_status[16];
+    int retries;
+    int retryInterval;
+    int requestId;
+    struct FirmwareType firmware;
+    unsigned char Response_status[16];
 };
 
 struct StructLogStatusNotification
 {
-	unsigned char status[32];
-	int requestId;
+    unsigned char status[32];
+    int requestId;
 };
 
 struct StructSecurityEventNotification
 {
-	unsigned char type[51];
-	unsigned char timestamp[28];
-	unsigned char techInfo[256];
+    unsigned char type[51];
+    unsigned char timestamp[28];
+    unsigned char techInfo[256];
 };
 
 struct StructSignCertificate
 {
-	unsigned char csr[5501];
-	unsigned char Response_status[16];
+    unsigned char csr[5501];
+    unsigned char Response_status[16];
 };
 
 struct StructSignedFirmwareStatusNotification
 {
-	unsigned char status[32];
-	int requestId;
+    unsigned char status[32];
+    int requestId;
 };
 
 struct OCPP16Data
@@ -4354,23 +4384,23 @@ struct OCPP16Data
         struct
         {
             //SpMsgValue[0]
-            unsigned char BootNotificationReq :1;               	//bit 0,
-            unsigned char BootNotificationConf :1;              	//bit 1,
-            unsigned char AuthorizeReq :1;                      	//bit 2,
-            unsigned char AuthorizeConf :1;                     	//bit 3,
-            unsigned char DiagnosticsStatusNotificationReq :1;  	//bit 4,
-            unsigned char DiagnosticsStatusNotificationConf :1; 	//bit 5,
-            unsigned char FirmwareStatusNotificationReq :1;     	//bit 6,
-            unsigned char FirmwareStatusNotificationConf :1;   	 	//bit 7,
+            unsigned char BootNotificationReq :1;                   //bit 0,
+            unsigned char BootNotificationConf :1;                  //bit 1,
+            unsigned char AuthorizeReq :1;                          //bit 2,
+            unsigned char AuthorizeConf :1;                         //bit 3,
+            unsigned char DiagnosticsStatusNotificationReq :1;      //bit 4,
+            unsigned char DiagnosticsStatusNotificationConf :1;     //bit 5,
+            unsigned char FirmwareStatusNotificationReq :1;         //bit 6,
+            unsigned char FirmwareStatusNotificationConf :1;        //bit 7,
             //SpMsgValue[1]
             unsigned char LogStatusNotificationReq :1;              //bit 0,
-			unsigned char LogStatusNotificationConf :1;             //bit 1,
-			unsigned char SecurityEventNotificationReq :1;          //bit 2,
-			unsigned char SecurityEventNotificationConf :1;         //bit 3,
-			unsigned char SignCertificateReq :1;  					//bit 4,
-			unsigned char SignCertificateConf :1; 					//bit 5,
-			unsigned char SignedFirmwareStatusNotificationReq :1;   //bit 6,
-			unsigned char SignedFirmwareStatusNotificationConf :1;	//bit 7,
+            unsigned char LogStatusNotificationConf :1;             //bit 1,
+            unsigned char SecurityEventNotificationReq :1;          //bit 2,
+            unsigned char SecurityEventNotificationConf :1;         //bit 3,
+            unsigned char SignCertificateReq :1;                    //bit 4,
+            unsigned char SignCertificateConf :1;                   //bit 5,
+            unsigned char SignedFirmwareStatusNotificationReq :1;   //bit 6,
+            unsigned char SignedFirmwareStatusNotificationConf :1;  //bit 7,
         } bits;
     } SpMsg;
 
@@ -4416,40 +4446,40 @@ struct OCPP16Data
         struct
         {
             //CsMsgValue[0]
-            unsigned char ChangeConfigurationReq :1;    			//bit 0,
-            unsigned char ChangeConfigurationConf :1;   			//bit 1,
-            unsigned char ClearCacheReq :1;             			//bit 2,
-            unsigned char ClearCacheConf :1;            			//bit 3,
-            unsigned char GetConfigurationReq :1;       			//bit 4,
-            unsigned char GetConfigurationConf :1;      			//bit 5,
-            unsigned char UpdateFirmwareReq :1;         			//bit 6,
-            unsigned char UpdateFirmwareConf :1;        			//bit 7,
+            unsigned char ChangeConfigurationReq :1;                //bit 0,
+            unsigned char ChangeConfigurationConf :1;               //bit 1,
+            unsigned char ClearCacheReq :1;                         //bit 2,
+            unsigned char ClearCacheConf :1;                        //bit 3,
+            unsigned char GetConfigurationReq :1;                   //bit 4,
+            unsigned char GetConfigurationConf :1;                  //bit 5,
+            unsigned char UpdateFirmwareReq :1;                     //bit 6,
+            unsigned char UpdateFirmwareConf :1;                    //bit 7,
             //CsMsgValue[1]
-            unsigned char GetDiagnosticsReq :1;         			//bit 0,
-            unsigned char GetDiagnosticsConf :1;        			//bit 1,
-            unsigned char GetLocalListVersionReq :1;   				//bit 2,
-            unsigned char GetLocalListVersionConf :1;   			//bit 3,
-            unsigned char ResetReq :1;                  			//bit 4,
-            unsigned char ResetConf :1;                 			//bit 5,
-            unsigned char SendLocalListReq :1;         				//bit 6,
-            unsigned char SendLocalListConf :1;         			//bit 7,
+            unsigned char GetDiagnosticsReq :1;                     //bit 0,
+            unsigned char GetDiagnosticsConf :1;                    //bit 1,
+            unsigned char GetLocalListVersionReq :1;                //bit 2,
+            unsigned char GetLocalListVersionConf :1;               //bit 3,
+            unsigned char ResetReq :1;                              //bit 4,
+            unsigned char ResetConf :1;                             //bit 5,
+            unsigned char SendLocalListReq :1;                      //bit 6,
+            unsigned char SendLocalListConf :1;                     //bit 7,
             //CsMsgValue[2]
-            unsigned char CertificateSignedReq :1;					//bit 0
-            unsigned char CertificateSignedConf :1;					//bit 1
-            unsigned char DeleteCertificateReq :1;					//bit 2
-            unsigned char DeleteCertificateConf :1;					//bit 3
-            unsigned char ExtendedTriggerMessageReq :1;				//bit 4
-            unsigned char ExtendedTriggerMessageConf :1;			//bit 5
-            unsigned char GetInstalledCertificateIdsReq :1;			//bit 6
-            unsigned char GetInstalledCertificateIdsConf :1;		//bit 7
+            unsigned char CertificateSignedReq :1;                  //bit 0
+            unsigned char CertificateSignedConf :1;                 //bit 1
+            unsigned char DeleteCertificateReq :1;                  //bit 2
+            unsigned char DeleteCertificateConf :1;                 //bit 3
+            unsigned char ExtendedTriggerMessageReq :1;             //bit 4
+            unsigned char ExtendedTriggerMessageConf :1;            //bit 5
+            unsigned char GetInstalledCertificateIdsReq :1;         //bit 6
+            unsigned char GetInstalledCertificateIdsConf :1;        //bit 7
             //CsMsgValue[3]
-            unsigned char GetLogReq :1;								//bit 0
-            unsigned char GetLogConf :1;							//bit 1
-            unsigned char InstallCertificateReq :1;					//bit 2
-            unsigned char InstallCertificateConf :1;				//bit 3
-            unsigned char SignedUpdateFirmwareReq :1;				//bit 4
-            unsigned char SignedUpdateFirmwareConf :1;				//bit 5
-            unsigned char :2;										//bit 6 & 7
+            unsigned char GetLogReq :1;                             //bit 0
+            unsigned char GetLogConf :1;                            //bit 1
+            unsigned char InstallCertificateReq :1;                 //bit 2
+            unsigned char InstallCertificateConf :1;                //bit 3
+            unsigned char SignedUpdateFirmwareReq :1;               //bit 4
+            unsigned char SignedUpdateFirmwareConf :1;              //bit 5
+            unsigned char :2;                                       //bit 6 & 7
         } bits;
     } MsMsg;
 
@@ -4466,48 +4496,48 @@ struct OCPP16Data
         } bits[CONNECTOR_QUANTITY];
     }CSUMsg;
 
-    struct StructBootNotification               	BootNotification;
-    struct StructHeartbeat                     	 	Heartbeat;
-    struct StructAuthorize                      	Authorize;
-    struct StructStartTransaction               	StartTransaction[CONNECTOR_QUANTITY];
-    struct StructStopTransaction                	StopTransaction[CONNECTOR_QUANTITY];
-    struct StructStatusNotification             	StatusNotification[CONNECTOR_QUANTITY];
-    struct StructCancelReservation              	CancelReservation[CONNECTOR_QUANTITY];
-    struct StructChangeAvailability             	ChangeAvailability[CONNECTOR_QUANTITY];
-    struct StructChangeConfiguration            	ChangeConfiguration;
-    struct StructClearCache                     	ClearCache;
-    struct StructClearChargingProfile           	ClearChargingProfile[CONNECTOR_QUANTITY];
-    struct StructDataTransfer                   	DataTransfer[CONNECTOR_QUANTITY];
-    struct StructDiagnosticsStatusNotification  	DiagnosticsStatusNotification;
-    struct StructFirmwareStatusNotification     	FirmwareStatusNotification;
-    struct StructGetCompositeSchedule           	GetCompositeSchedule[CONNECTOR_QUANTITY];
-    struct StructGetConfiguration               	GetConfiguration;
-    struct StructGetDiagnostics                 	GetDiagnostics;
-    struct StructGetLocalListVersion            	GetLocalListVersion;
-    struct StructMeterValues                    	MeterValues[CONNECTOR_QUANTITY];
-    struct StructRemoteStartTransaction         	RemoteStartTransaction[CONNECTOR_QUANTITY];
-    struct StructRemoteStopTransaction          	RemoteStopTransaction[CONNECTOR_QUANTITY];
-    struct StructReserveNow                     	ReserveNow[CONNECTOR_QUANTITY];
-    struct StructReset                          	Reset;
-    struct StructSendLocalList                  	SendLocalList;
-    struct StructSetChargingProfile            		SetChargingProfile[CONNECTOR_QUANTITY];
-    struct StructTriggerMessage                 	TriggerMessage[CONNECTOR_QUANTITY];
-    struct StructUnlockConnector                	UnlockConnector[CONNECTOR_QUANTITY];
-    struct StructUpdateFirmware                 	UpdateFirmware;
-    struct OCPP16ConfigurationTable             	ConfigurationTable;
-    struct StructChargingProfile                	SmartChargingProfile[CONNECTOR_QUANTITY];
-    struct StructCost                           	Cost;
-    struct StructCertificateSigned					CertificateSigned;
-    struct StructDeleteCertificate					DeleteCertificate;
-    struct StructExtendedTrigger					ExtendedTriggerMessage;
-    struct StructGetInstalledCertificateIds			GetInstalledCertificateIds;
-    struct StructGetLog								GetLog;
-    struct StructInstallCertificate					InstallCertificate;
-    struct StructSignedUpdateFirmware				SignedUpdateFirmware;
-    struct StructLogStatusNotification				LogStatusNotification;
-    struct StructSecurityEventNotification			SecurityEventNotification;
-    struct StructSignCertificate					SignCertificate;
-    struct StructSignedFirmwareStatusNotification 	SignedFirmwareStatusNotification;
+    struct StructBootNotification                   BootNotification;
+    struct StructHeartbeat                          Heartbeat;
+    struct StructAuthorize                          Authorize;
+    struct StructStartTransaction                   StartTransaction[CONNECTOR_QUANTITY];
+    struct StructStopTransaction                    StopTransaction[CONNECTOR_QUANTITY];
+    struct StructStatusNotification                 StatusNotification[CONNECTOR_QUANTITY];
+    struct StructCancelReservation                  CancelReservation[CONNECTOR_QUANTITY];
+    struct StructChangeAvailability                 ChangeAvailability[CONNECTOR_QUANTITY];
+    struct StructChangeConfiguration                ChangeConfiguration;
+    struct StructClearCache                         ClearCache;
+    struct StructClearChargingProfile               ClearChargingProfile[CONNECTOR_QUANTITY];
+    struct StructDataTransfer                       DataTransfer[CONNECTOR_QUANTITY];
+    struct StructDiagnosticsStatusNotification      DiagnosticsStatusNotification;
+    struct StructFirmwareStatusNotification         FirmwareStatusNotification;
+    struct StructGetCompositeSchedule               GetCompositeSchedule[CONNECTOR_QUANTITY];
+    struct StructGetConfiguration                   GetConfiguration;
+    struct StructGetDiagnostics                     GetDiagnostics;
+    struct StructGetLocalListVersion                GetLocalListVersion;
+    struct StructMeterValues                        MeterValues[CONNECTOR_QUANTITY];
+    struct StructRemoteStartTransaction             RemoteStartTransaction[CONNECTOR_QUANTITY];
+    struct StructRemoteStopTransaction              RemoteStopTransaction[CONNECTOR_QUANTITY];
+    struct StructReserveNow                         ReserveNow[CONNECTOR_QUANTITY];
+    struct StructReset                              Reset;
+    struct StructSendLocalList                      SendLocalList;
+    struct StructSetChargingProfile                 SetChargingProfile[CONNECTOR_QUANTITY];
+    struct StructTriggerMessage                     TriggerMessage[CONNECTOR_QUANTITY];
+    struct StructUnlockConnector                    UnlockConnector[CONNECTOR_QUANTITY];
+    struct StructUpdateFirmware                     UpdateFirmware;
+    struct OCPP16ConfigurationTable                 ConfigurationTable;
+    struct StructChargingProfile                    SmartChargingProfile[CONNECTOR_QUANTITY];
+    struct StructCost                               Cost;
+    struct StructCertificateSigned                  CertificateSigned;
+    struct StructDeleteCertificate                  DeleteCertificate;
+    struct StructExtendedTrigger                    ExtendedTriggerMessage;
+    struct StructGetInstalledCertificateIds         GetInstalledCertificateIds;
+    struct StructGetLog                             GetLog;
+    struct StructInstallCertificate                 InstallCertificate;
+    struct StructSignedUpdateFirmware               SignedUpdateFirmware;
+    struct StructLogStatusNotification              LogStatusNotification;
+    struct StructSecurityEventNotification          SecurityEventNotification;
+    struct StructSignCertificate                    SignCertificate;
+    struct StructSignedFirmwareStatusNotification   SignedFirmwareStatusNotification;
 };
 
 
@@ -5074,8 +5104,8 @@ struct TransactionType
 
 struct StatusInfoType
 {
-	unsigned char reasonCode[21];									// Required. A predefined code for the reason why thestatus is returned in this response. The string is case-insensitive.
-	unsigned char additionalInfo[513];								// Optional. Additional text to provide detailed information.
+    unsigned char reasonCode[21];                                   // Required. A predefined code for the reason why thestatus is returned in this response. The string is case-insensitive.
+    unsigned char additionalInfo[513];                              // Optional. Additional text to provide detailed information.
 };
 /*
  * =============== Message ===============
@@ -5106,11 +5136,11 @@ struct CancelReservation_20
 
 struct CertificateSigned_20
 {
-	unsigned char certificateChain[10001];							// Required. Required. The signed PEM encoded X.509 certificate.This can also contain the necessary sub CA certificates.In that case, the order of the bundle should follow thecertificate chain, starting from the leaf certificate.The Configuration Variable MaxCertificateChainSize canbe used to limit the maximum size of this field.
-	unsigned char certificateType[32];								// Optional. Indicates the type of the signed certificate that is returned.
-	unsigned char Response_status[16];								// Required. Returns whether certificate signing has been accepted, otherwise rejected.
-	struct StatusInfoType Response_statusInfo;						// Optional. Detailed status information.
-	unsigned char guid[37];											// Save guid from server request
+    unsigned char certificateChain[10001];                          // Required. Required. The signed PEM encoded X.509 certificate.This can also contain the necessary sub CA certificates.In that case, the order of the bundle should follow thecertificate chain, starting from the leaf certificate.The Configuration Variable MaxCertificateChainSize canbe used to limit the maximum size of this field.
+    unsigned char certificateType[32];                              // Optional. Indicates the type of the signed certificate that is returned.
+    unsigned char Response_status[16];                              // Required. Returns whether certificate signing has been accepted, otherwise rejected.
+    struct StatusInfoType Response_statusInfo;                      // Optional. Detailed status information.
+    unsigned char guid[37];                                         // Save guid from server request
 };
 
 struct ChangeAvailability_20
@@ -5540,10 +5570,10 @@ struct SetVariables_20
 
 struct SignCertificate_20
 {
-	unsigned char csr[5501];										// Required. The Charging Station SHALL send the public key in form of a Certificate Signing Request (CSR) as described in RFC 2986 [22] using the SignCertificateRequest message.
-	unsigned char certificateType[32];								// Optional. Indicates the type of certificate that is to be signed. When omitted the certificate is to be used for both the 15118 connection (if implemented) and the Charging Station to CSMS connection.
-	unsigned char Response_status[16];								// Required. Specifies whether the CSMS can process the request.
-	struct StatusInfoType Response_statusInfo;						// Optional. Detailed status information.
+    unsigned char csr[5501];                                        // Required. The Charging Station SHALL send the public key in form of a Certificate Signing Request (CSR) as described in RFC 2986 [22] using the SignCertificateRequest message.
+    unsigned char certificateType[32];                              // Optional. Indicates the type of certificate that is to be signed. When omitted the certificate is to be used for both the 15118 connection (if implemented) and the Charging Station to CSMS connection.
+    unsigned char Response_status[16];                              // Required. Specifies whether the CSMS can process the request.
+    struct StatusInfoType Response_statusInfo;                      // Optional. Detailed status information.
 };
 
 struct StatusNotification_20

BIN
EVSE/rootfs/bin/memtester


BIN
EVSE/rootfs/bin/nandwrite


+ 3 - 3
EVSE/rootfs/etc/init.d/rcS

@@ -113,7 +113,7 @@ ln -sf libbz2.so.1.0.6 libbz2.so.1
 #   Enable auto reboot when kernel panic occur
 #   ---------------------------------------------
 echo 3 > /proc/sys/kernel/panic
-echo 1 > /proc/sys/kernel/panic_on_oops
-echo 1 > /proc/sys/kernel/panic_on_warn
-echo 1 > /proc/sys/kernel/panic_on_rcu_stall
+#echo 1 > /proc/sys/kernel/panic_on_oops
+#echo 1 > /proc/sys/kernel/panic_on_warn
+#echo 1 > /proc/sys/kernel/panic_on_rcu_stall
 

BIN
EVSE/rootfs/lib/ld-2.19.so


BIN
EVSE/rootfs/lib/libBrokenLocale-2.19.so


BIN
EVSE/rootfs/lib/libanl-2.19.so


BIN
EVSE/rootfs/lib/libc-2.19.so


BIN
EVSE/rootfs/lib/libcrypt-2.19.so


BIN
EVSE/rootfs/lib/libdl-2.19.so


BIN
EVSE/rootfs/lib/libm-2.19.so


BIN
EVSE/rootfs/lib/libnsl-2.19.so


BIN
EVSE/rootfs/lib/libnss_compat-2.19.so


BIN
EVSE/rootfs/lib/libnss_dns-2.19.so


BIN
EVSE/rootfs/lib/libnss_files-2.19.so


BIN
EVSE/rootfs/lib/libpthread-2.19.so


BIN
EVSE/rootfs/lib/libresolv-2.19.so


BIN
EVSE/rootfs/lib/librt-2.19.so


BIN
EVSE/rootfs/lib/libutil-2.19.so


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

@@ -9,3 +9,4 @@ Module_EventLogging
 Module_PhBackend
 Module_InitUpgrade
 Module_Payment
+Module_DcMeter

BIN
EVSE/rootfs/root/Module_Payment


BIN
EVSE/rootfs/root/OcppBackend20


BIN
EVSE/rootfs/sbin/tcpdump


+ 1 - 1
EVSE/rootfs/var/www/settings

@@ -1 +1 @@
-{"adc_v_x2":"260","server":"evsocket.phihong.com.tw","adc_v_x1":"0","apn_name":"internet","meter_v_x1":"0","meter_v_x2":"260","latitude":"25.042693","Money_Rate":"1","adc_c_x1":"0","adc_c_x2":"40","web_lang":"ENG","lan_ip":"0","meter_c_x2":"40","powerPhase":"3","ID":"AC_PLATFORM","UUID":"","longitude":"121.382915","meter_c_x1":"0","adc_c_a":0,"isMeter":"1","adc_c_b":0,"mDongle":"EC21","gun_count":"2","adc_v_a":0,"lcd_lang":"2","server_port":"9999","adc_v_b":0,"FW_Ver":"P1.4_0709","powerAllSum_0":0,"powerAllSum_1":0,"Current":0}
+{"web_lang":"ENG"}

+ 1 - 1
board-support/linux-4.9.59+gitAUTOINC+a75d8e9305-ga75d8e9305/.tmp_System.map

@@ -72062,7 +72062,7 @@ c0d4d918 T __initramfs_start
 c0d4d918 t __irf_start
 c0d4d918 T __security_initcall_end
 c0d4d918 T __security_initcall_start
-c0d4d99f t __irf_end
+c0d4d99d t __irf_end
 c0d4d9a0 T __initramfs_size
 c0e00000 D __data_loc
 c0e00000 D __init_end

+ 1 - 1
board-support/linux-4.9.59+gitAUTOINC+a75d8e9305-ga75d8e9305/.tmp_kallsyms1.S

@@ -72066,7 +72066,7 @@ kallsyms_offsets:
 	.long	0xc45918
 	.long	0xc45918
 	.long	0xc45918
-	.long	0xc4599f
+	.long	0xc4599d
 	.long	0xc459a0
 	.long	0xcf8000
 	.long	0xcf8000

+ 1 - 1
board-support/linux-4.9.59+gitAUTOINC+a75d8e9305-ga75d8e9305/.tmp_kallsyms2.S

@@ -72066,7 +72066,7 @@ kallsyms_offsets:
 	.long	0xd45918
 	.long	0xd45918
 	.long	0xd45918
-	.long	0xd4599f
+	.long	0xd4599d
 	.long	0xd459a0
 	.long	0xdf8000
 	.long	0xdf8000

+ 1 - 1
board-support/linux-4.9.59+gitAUTOINC+a75d8e9305-ga75d8e9305/.version

@@ -1 +1 @@
-31
+32

+ 11 - 8
board-support/linux-4.9.59+gitAUTOINC+a75d8e9305-ga75d8e9305/arch/arm/boot/dts/.am335x-evm.dtb.dts.tmp

@@ -1214,8 +1214,11 @@
    0x0B4 (((1 << 3)) | 7)
    0x0E8 (((1 << 5) | (1 << 3)) | 7)
    0x0E0 (((1 << 3)) | 7)
+   0x0EC (((1 << 3)) | 7)
+
 
    0x1A0 (((1 << 3)) | 7)
+   0x1A4 (((1 << 3)) | 7)
    0x1A8 (((1 << 3)) | 7)
   >;
  };
@@ -1261,7 +1264,7 @@
    0x164 (0 | 1)
   >;
  };
-# 138 "arch/arm/boot/dts/am335x-evm.dts"
+# 141 "arch/arm/boot/dts/am335x-evm.dts"
  clkout2_pin: pinmux_clkout2_pin {
   pinctrl-single,pins = <
    0x1b4 (0 | 3)
@@ -1385,7 +1388,7 @@
    0x17C (((1 << 5)) | 2)
   >;
  };
-# 281 "arch/arm/boot/dts/am335x-evm.dts"
+# 284 "arch/arm/boot/dts/am335x-evm.dts"
  spi1_pins: spi1_pins {
                 pinctrl-single,pins = <
                         ((((0x990)) & 0xffff) - (0x0800)) (((1 << 5) | (1 << 4)) | 3)
@@ -1425,7 +1428,7 @@
 
  status = "okay";
 };
-# 328 "arch/arm/boot/dts/am335x-evm.dts"
+# 331 "arch/arm/boot/dts/am335x-evm.dts"
 &i2c0 {
  pinctrl-names = "default";
  pinctrl-0 = <&i2c0_pins>;
@@ -1489,14 +1492,14 @@
 &elm {
  status = "okay";
 };
-# 412 "arch/arm/boot/dts/am335x-evm.dts"
+# 415 "arch/arm/boot/dts/am335x-evm.dts"
 &gpmc {
  status = "okay";
  pinctrl-names = "default", "sleep";
  pinctrl-0 = <&nandflash_pins_default>;
  pinctrl-1 = <&nandflash_pins_sleep>;
 
- ranges = <0 0 0x08000000 0x80000000>;
+ ranges = <0 0 0x08000000 0x40000000>;
  nand@0,0 {
   compatible = "ti,omap2-nand";
   reg = <0 0 4>;
@@ -1675,7 +1678,7 @@
   };
  };
 };
-# 518 "arch/arm/boot/dts/am335x-evm.dts" 2
+# 521 "arch/arm/boot/dts/am335x-evm.dts" 2
 
 &tps {
  vcc1-supply = <&vbat>;
@@ -1774,7 +1777,7 @@
   phy-mode = "mii";
 
 };
-# 624 "arch/arm/boot/dts/am335x-evm.dts"
+# 628 "arch/arm/boot/dts/am335x-evm.dts"
 &tscadc {
  status = "okay";
 
@@ -1821,7 +1824,7 @@
  pinctrl-names = "default";
  pinctrl-0 = <&dcan0_pins_default>;
 };
-# 685 "arch/arm/boot/dts/am335x-evm.dts"
+# 689 "arch/arm/boot/dts/am335x-evm.dts"
 &spi1 {
         status = "okay";
         pinctrl-names = "default";

+ 5 - 2
board-support/linux-4.9.59+gitAUTOINC+a75d8e9305-ga75d8e9305/arch/arm/boot/dts/[AW-CCS]am335x-evm.dts

@@ -80,8 +80,11 @@
 			0x0B4 (PIN_OUTPUT | MUX_MODE7)			/*LCD_DATA5	=>	GPIO2_11*/	/*Panel LED control-BB_LEDB2*/
 			0x0E8 (PIN_INPUT | MUX_MODE7)			/*LCD_PCLK	=>	GPIO2_24*/	/*communication board proximity*/
 			0x0E0 (PIN_OUTPUT | MUX_MODE7)			/*LCD_VSYNC	=>	GPIO2_22*/	/*Breath LED*/
+			0x0EC (PIN_OUTPUT | MUX_MODE7)			/* CCSEthernet-Reset=>LCD_AC_BIAS_EN.GPIO2_25*/
+			
 			/** GPIO 3 */
 			0x1A0 (PIN_OUTPUT | MUX_MODE7)                  /* MCASP0_AXR1  =>      GPIO3_18 */     /*control 4G reset pin*/
+			0x1A4 (PIN_OUTPUT | MUX_MODE7)			/* MCASP0_FSR.GPIO3_19 */
 			0x1A8 (PIN_OUTPUT | MUX_MODE7)			/* MCASP0_AXR1	=>	GPIO3_20 */	/*control MCU to output CP PWM*/
 		>;
 	};
@@ -415,7 +418,7 @@
 	pinctrl-0 = <&nandflash_pins_default>;
 	pinctrl-1 = <&nandflash_pins_sleep>;
 	/*ranges = <0 0 0x08000000 0x10000000>;*/	/* CS0: NAND */
-	ranges = <0 0 0x08000000 0x80000000>;	/*+++ vern,NAND,20181030 ---*/
+	ranges = <0 0 0x08000000 0x40000000>;	/*+++ vern,NAND,20181030 ---*/
 	nand@0,0 {
 		compatible = "ti,omap2-nand";
 		reg = <0 0 4>; /* CS0, offset 0, IO size 4 */
@@ -613,6 +616,7 @@
  	phy-mode = "mii";
 
 };
+
 #if 0
 &cpsw_emac1 {
 	phy_id = <&davinci_mdio>, <2>;
@@ -698,4 +702,3 @@ The SPI should be used in burst mode, meaning that the chip select is held low d
         };
 };
 
-

+ 5 - 2
board-support/linux-4.9.59+gitAUTOINC+a75d8e9305-ga75d8e9305/arch/arm/boot/dts/am335x-evm.dts

@@ -80,8 +80,11 @@
 			0x0B4 (PIN_OUTPUT | MUX_MODE7)			/*LCD_DATA5	=>	GPIO2_11*/	/*Panel LED control-BB_LEDB2*/
 			0x0E8 (PIN_INPUT | MUX_MODE7)			/*LCD_PCLK	=>	GPIO2_24*/	/*communication board proximity*/
 			0x0E0 (PIN_OUTPUT | MUX_MODE7)			/*LCD_VSYNC	=>	GPIO2_22*/	/*Breath LED*/
+			0x0EC (PIN_OUTPUT | MUX_MODE7)			/* CCSEthernet-Reset=>LCD_AC_BIAS_EN.GPIO2_25*/
+			
 			/** GPIO 3 */
 			0x1A0 (PIN_OUTPUT | MUX_MODE7)                  /* MCASP0_AXR1  =>      GPIO3_18 */     /*control 4G reset pin*/
+			0x1A4 (PIN_OUTPUT | MUX_MODE7)			/* MCASP0_FSR.GPIO3_19 */
 			0x1A8 (PIN_OUTPUT | MUX_MODE7)			/* MCASP0_AXR1	=>	GPIO3_20 */	/*control MCU to output CP PWM*/
 		>;
 	};
@@ -415,7 +418,7 @@
 	pinctrl-0 = <&nandflash_pins_default>;
 	pinctrl-1 = <&nandflash_pins_sleep>;
 	/*ranges = <0 0 0x08000000 0x10000000>;*/	/* CS0: NAND */
-	ranges = <0 0 0x08000000 0x80000000>;	/*+++ vern,NAND,20181030 ---*/
+	ranges = <0 0 0x08000000 0x40000000>;	/*+++ vern,NAND,20181030 ---*/
 	nand@0,0 {
 		compatible = "ti,omap2-nand";
 		reg = <0 0 4>; /* CS0, offset 0, IO size 4 */
@@ -613,6 +616,7 @@
  	phy-mode = "mii";
 
 };
+
 #if 0
 &cpsw_emac1 {
 	phy_id = <&davinci_mdio>, <2>;
@@ -698,4 +702,3 @@ The SPI should be used in burst mode, meaning that the chip select is held low d
         };
 };
 
-

+ 1 - 1
board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/arch/arm/dts/.am335x-evm.dtb.dts.tmp

@@ -1406,7 +1406,7 @@
  pinctrl-names = "default";
  pinctrl-0 = <&nandflash_pins_s0>;
 
- ranges = <0 0 0x08000000 0x80000000>;
+ ranges = <0 0 0x08000000 0x40000000>;
  nand@0,0 {
   reg = <0 0 4>;
   ti,nand-ecc-opt = "bch8";

+ 1 - 1
board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/arch/arm/dts/[AW-CCS]am335x-evm.dts

@@ -518,7 +518,7 @@
 	pinctrl-names = "default";
 	pinctrl-0 = <&nandflash_pins_s0>;
 	/*ranges = <0 0 0x08000000 0x1000000>;*/	/* CS0: 16MB for NAND */
-	ranges = <0 0 0x08000000 0x80000000>;	/*+++ vern,NAND,20181030 ---*/
+	ranges = <0 0 0x08000000 0x40000000>;	/*+++ vern,NAND,20181030 ---*/
 	nand@0,0 {
 		reg = <0 0 4>; /* CS0, offset 0, IO size 4 */
 		ti,nand-ecc-opt = "bch8";

+ 1 - 1
board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/arch/arm/dts/am335x-evm.dts

@@ -518,7 +518,7 @@
 	pinctrl-names = "default";
 	pinctrl-0 = <&nandflash_pins_s0>;
 	/*ranges = <0 0 0x08000000 0x1000000>;*/	/* CS0: 16MB for NAND */
-	ranges = <0 0 0x08000000 0x80000000>;	/*+++ vern,NAND,20181030 ---*/
+	ranges = <0 0 0x08000000 0x40000000>;	/*+++ vern,NAND,20181030 ---*/
 	nand@0,0 {
 		reg = <0 0 4>; /* CS0, offset 0, IO size 4 */
 		ti,nand-ecc-opt = "bch8";

Some files were not shown because too many files changed in this diff