Explorar o código

2021.06.25 / Jerry Wang

Actions:
1. Debug internalComm.c Config_Led_Color() tx[13] = checksum overflow issue.
2. Debug ReadCmdline configure temperature function.
3. Modify Module_DoComm.c and Module_PrimaryComm.c source code.

Files:
1. As follow as commit history.
Jerry_Wang %!s(int64=3) %!d(string=hai) anos
pai
achega
34d338db6d
Modificáronse 100 ficheiros con 6711 adicións e 2606 borrados
  1. 117 99
      EVSE/Modularization/DcMeter/Module_DcMeter.c
  2. 9 2
      EVSE/Modularization/DcMeter/meterComm.c
  3. 1 0
      EVSE/Modularization/DcMeter/meterComm.h
  4. 6 6
      EVSE/Modularization/Makefile
  5. 4 4
      EVSE/Modularization/Module_InitUpgrade.c
  6. 2669 190
      EVSE/Modularization/Module_PhBackend.c
  7. 1 1
      EVSE/Modularization/Module_PhBackend.h
  8. 2 2
      EVSE/Modularization/Module_ProduceUtils.c
  9. 59 38
      EVSE/Modularization/Module_Wifi.c
  10. 12 12
      EVSE/Modularization/WebService.c
  11. 52 6
      EVSE/Modularization/ocpp20/MessageHandler.c
  12. 1 0
      EVSE/Modularization/ocpp20/MessageHandler.h
  13. 2 2
      EVSE/Modularization/ocpp20/Module_OcppBackend20.c
  14. 52 6
      EVSE/Modularization/ocppfiles/MessageHandler.c
  15. 1 0
      EVSE/Modularization/ocppfiles/MessageHandler.h
  16. 2 2
      EVSE/Modularization/ocppfiles/Module_OcppBackend.c
  17. 250 37
      EVSE/Projects/AW-CCS/Apps/LCM/Module_LcmControl.c
  18. 315 0
      EVSE/Projects/AW-CCS/Apps/LCM/cbmp.c
  19. 54 0
      EVSE/Projects/AW-CCS/Apps/LCM/cbmp.h
  20. 25 5
      EVSE/Projects/AW-CCS/Apps/LCM/lcmComm_dgus.c
  21. 3 1
      EVSE/Projects/AW-CCS/Apps/LCM/lcmComm_dgus.h
  22. 2 2
      EVSE/Projects/AW-CCS/Apps/Module_ConfigTools.c
  23. 3 3
      EVSE/Projects/AW-CCS/Apps/Module_FactoryConfig.c
  24. 17 19
      EVSE/Projects/AW-CCS/Apps/main.c
  25. BIN=BIN
      EVSE/Projects/AW-CCS/Images/FactoryDefaultConfig.bin
  26. BIN=BIN
      EVSE/Projects/AW-CCS/Images/ramdisk.gz
  27. 2 2
      EVSE/Projects/AW-ChargeLab/Apps/Module_ConfigTools.c
  28. 7 19
      EVSE/Projects/AW-ChargeLab/Apps/Module_FactoryConfig.c
  29. 10 5
      EVSE/Projects/AW-ChargeLab/Apps/main.c
  30. 2 2
      EVSE/Projects/AW-Regular/Apps/Module_ConfigTools.c
  31. 7 19
      EVSE/Projects/AW-Regular/Apps/Module_FactoryConfig.c
  32. 10 5
      EVSE/Projects/AW-Regular/Apps/main.c
  33. BIN=BIN
      EVSE/Projects/AW-Regular/Images/FactoryDefaultConfig.bin
  34. BIN=BIN
      EVSE/Projects/AW-Regular/Images/ramdisk.gz
  35. 2 1
      EVSE/Projects/DD360/Apps/CSU/RFID.c
  36. 104 70
      EVSE/Projects/DD360/Apps/CSU/main.c
  37. 1 0
      EVSE/Projects/DD360/Apps/DataBase/DataBase.c
  38. 4 0
      EVSE/Projects/DD360/Apps/Define/define.h
  39. 69 7
      EVSE/Projects/DD360/Apps/FactoryConfig.c
  40. 61 0
      EVSE/Projects/DD360/Apps/Log/log.c
  41. 2 0
      EVSE/Projects/DD360/Apps/Log/log.h
  42. 31 13
      EVSE/Projects/DD360/Apps/Makefile
  43. 212 172
      EVSE/Projects/DD360/Apps/ModuleDoComm/DoComm.c
  44. 134 87
      EVSE/Projects/DD360/Apps/ModuleEventLog/Module_EventLogging.c
  45. 13 4
      EVSE/Projects/DD360/Apps/ModuleInternalComm/internalComm.c
  46. 413 187
      EVSE/Projects/DD360/Apps/ModuleLcmCtrl/Module_LcmControl.c
  47. 19 238
      EVSE/Projects/DD360/Apps/ModuleLcmCtrl/Module_LcmControl.h
  48. 191 173
      EVSE/Projects/DD360/Apps/ModulePrimary/Module_PrimaryComm.c
  49. 4 4
      EVSE/Projects/DD360/Apps/ModulePrimary/Module_PrimaryComm.h
  50. 2 1
      EVSE/Projects/DD360/Apps/ModulePrimary/PrimaryComm.c
  51. 93 52
      EVSE/Projects/DD360/Apps/ReadCmdline.c
  52. 3 2
      EVSE/Projects/DD360/Apps/Readme.md
  53. 12 2
      EVSE/Projects/DD360/Apps/ShareMemory/shmMem.c
  54. BIN=BIN
      EVSE/Projects/DD360/Images/ramdisk.gz
  55. BIN=BIN
      EVSE/Projects/DD360/output/FactoryConfig
  56. BIN=BIN
      EVSE/Projects/DD360/output/Module_DoComm
  57. BIN=BIN
      EVSE/Projects/DD360/output/Module_EvComm
  58. BIN=BIN
      EVSE/Projects/DD360/output/Module_EventLogging
  59. BIN=BIN
      EVSE/Projects/DD360/output/Module_InternalComm
  60. BIN=BIN
      EVSE/Projects/DD360/output/Module_LcmControl
  61. BIN=BIN
      EVSE/Projects/DD360/output/Module_PrimaryComm
  62. BIN=BIN
      EVSE/Projects/DD360/output/ReadCmdline
  63. BIN=BIN
      EVSE/Projects/DD360/output/main
  64. 2 1
      EVSE/Projects/DD360Audi/Apps/CSU/RFID.c
  65. 104 70
      EVSE/Projects/DD360Audi/Apps/CSU/main.c
  66. 1 0
      EVSE/Projects/DD360Audi/Apps/DataBase/DataBase.c
  67. 4 0
      EVSE/Projects/DD360Audi/Apps/Define/define.h
  68. 69 7
      EVSE/Projects/DD360Audi/Apps/FactoryConfig.c
  69. 61 0
      EVSE/Projects/DD360Audi/Apps/Log/log.c
  70. 2 0
      EVSE/Projects/DD360Audi/Apps/Log/log.h
  71. 31 13
      EVSE/Projects/DD360Audi/Apps/Makefile
  72. 212 172
      EVSE/Projects/DD360Audi/Apps/ModuleDoComm/DoComm.c
  73. 134 87
      EVSE/Projects/DD360Audi/Apps/ModuleEventLog/Module_EventLogging.c
  74. 13 4
      EVSE/Projects/DD360Audi/Apps/ModuleInternalComm/internalComm.c
  75. 413 187
      EVSE/Projects/DD360Audi/Apps/ModuleLcmCtrl/Module_LcmControl.c
  76. 19 238
      EVSE/Projects/DD360Audi/Apps/ModuleLcmCtrl/Module_LcmControl.h
  77. 191 173
      EVSE/Projects/DD360Audi/Apps/ModulePrimary/Module_PrimaryComm.c
  78. 4 4
      EVSE/Projects/DD360Audi/Apps/ModulePrimary/Module_PrimaryComm.h
  79. 2 1
      EVSE/Projects/DD360Audi/Apps/ModulePrimary/PrimaryComm.c
  80. 93 52
      EVSE/Projects/DD360Audi/Apps/ReadCmdline.c
  81. 3 2
      EVSE/Projects/DD360Audi/Apps/Readme.md
  82. 12 2
      EVSE/Projects/DD360Audi/Apps/ShareMemory/shmMem.c
  83. BIN=BIN
      EVSE/Projects/DD360Audi/Images/ramdisk.gz
  84. BIN=BIN
      EVSE/Projects/DD360Audi/output/FactoryConfig
  85. BIN=BIN
      EVSE/Projects/DD360Audi/output/Module_DoComm
  86. BIN=BIN
      EVSE/Projects/DD360Audi/output/Module_EvComm
  87. BIN=BIN
      EVSE/Projects/DD360Audi/output/Module_EventLogging
  88. BIN=BIN
      EVSE/Projects/DD360Audi/output/Module_InternalComm
  89. BIN=BIN
      EVSE/Projects/DD360Audi/output/Module_LcmControl
  90. BIN=BIN
      EVSE/Projects/DD360Audi/output/Module_PrimaryComm
  91. BIN=BIN
      EVSE/Projects/DD360Audi/output/ReadCmdline
  92. BIN=BIN
      EVSE/Projects/DD360Audi/output/main
  93. 2 1
      EVSE/Projects/DD360ComBox/Apps/CSU/RFID.c
  94. 104 70
      EVSE/Projects/DD360ComBox/Apps/CSU/main.c
  95. 1 0
      EVSE/Projects/DD360ComBox/Apps/DataBase/DataBase.c
  96. 4 0
      EVSE/Projects/DD360ComBox/Apps/Define/define.h
  97. 69 7
      EVSE/Projects/DD360ComBox/Apps/FactoryConfig.c
  98. 61 0
      EVSE/Projects/DD360ComBox/Apps/Log/log.c
  99. 2 0
      EVSE/Projects/DD360ComBox/Apps/Log/log.h
  100. 31 13
      EVSE/Projects/DD360ComBox/Apps/Makefile

+ 117 - 99
EVSE/Modularization/DcMeter/Module_DcMeter.c

@@ -6,6 +6,7 @@
  */
 #include "Module_DcMeter.h"
 #include "meterComm.h"
+#include "Module_RatedCurrent.h"
 
 /**
  * Initial share memory
@@ -52,8 +53,10 @@ int InitShareMemory()
 //==========================================
 int main(void)
 {
-	Meter_Info meter_info;
+	ParsingRatedCur modelnameInfo = {0};
+	Meter_Info meter_info = {0};
 	uint8_t pollingIndex = 0;
+	uint8_t	meterIndex = 0;
 	uint8_t failCount = 0;
 
 #ifndef DEBUG_STANDALONG
@@ -69,6 +72,8 @@ int main(void)
 		sleep(5);
 		return -1;
 	}
+
+	RatedCurrentParsing((char*)ShmSysConfigAndInfo->SysConfig.ModelName, &modelnameInfo);
 #endif//DEBUG_STANDALONG
 
 	// Initialize DC meter model
@@ -81,113 +86,126 @@ int main(void)
 	// Main loop
 	for(;;)
 	{
-		switch(pollingIndex)
+		for(uint8_t gun_index=0;gun_index<modelnameInfo.GetGunCount;gun_index++)
 		{
-			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))
+			if(gun_index == 0)
+				meterIndex = 0;
+
+			if(modelnameInfo.ParsingInfo[gun_index].GunType != Gun_Type_AC)
+			{
+				meterApiAssign(meterIndex);
+				switch(pollingIndex)
 				{
-#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;
+					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;
 				}
-				else
+
+				meterIndex++;
+			}
+
+			if(failCount >= 10)
+			{
+				#ifndef DEBUG_STANDALONG
+				if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.MeterCommTimeout)
 				{
-					if(failCount < 10)
-						failCount++;
+					DEBUG_ERROR("Meter communication timeout");
+					ShmStatusCodeData->AlarmCode.AlarmEvents.bits.MeterCommTimeout = ON;
 				}
-				break;
-			default:
-				pollingIndex = 0;
-				break;
-		}
-
-		if(failCount >= 10)
-		{
-#ifndef DEBUG_STANDALONG
-			if(ShmStatusCodeData->AlarmCode.AlarmEvents.bits.MeterCommTimeout)
+				#endif//DEBUG_STANDALONG
+			}
+			else
 			{
-				DEBUG_ERROR("Meter communication timeout");
-				ShmStatusCodeData->AlarmCode.AlarmEvents.bits.MeterCommTimeout = ON;
+				#ifndef DEBUG_STANDALONG
+				ShmStatusCodeData->AlarmCode.AlarmEvents.bits.MeterCommTimeout = OFF;
+				#endif//DEBUG_STANDALONG
 			}
-#endif//DEBUG_STANDALONG
-		}
-		else
-		{
-#ifndef DEBUG_STANDALONG
-			ShmStatusCodeData->AlarmCode.AlarmEvents.bits.MeterCommTimeout = OFF;
-#endif//DEBUG_STANDALONG
+			usleep(500000);
 		}
-
-		usleep(500000);
 	}
 
+
+
 	return -1;
 }

+ 9 - 2
EVSE/Modularization/DcMeter/meterComm.c

@@ -16,13 +16,20 @@ char			meterApiAddress[128];
 
 
 /**
- * Meter driver initialize
+ * Meter model initialize
  * @param model
  */
 void meterInitialize(uint8_t model)
 {
 	meterModel = model;
+}
 
+/**
+ * Meter api address assign
+ * @param meterIndex
+ */
+void meterApiAssign(uint8_t meterIndex)
+{
 	switch(meterModel)
 	{
 		case METER_MODEL_LEM_L18005A:
@@ -31,7 +38,7 @@ void meterInitialize(uint8_t model)
 			 * TODO:
 			 * 	1. Check meter actual API address.
 			 */
-			//sprintf(meterApiAddress, "http://192.168.1.2/livemeasure");
+			//sprintf(meterApiAddress, "http://192.168.0.%d/livemeasure", (31 + meterIndex));
 			sprintf(meterApiAddress, "https://foluswen.com/tmate/livemeasure.php"); // Simulator by web server
 
 			break;

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

@@ -52,6 +52,7 @@ enum METER_MODEL
 };
 
 extern void meterInitialize(uint8_t model);
+extern void meterApiAssign(uint8_t meterIndex);
 extern int readVoltage(Meter_Info *meter_info);
 extern int readCurrent(Meter_Info *meter_info);
 extern int readPower(Meter_Info *meter_info);

+ 6 - 6
EVSE/Modularization/Makefile

@@ -3,12 +3,12 @@ export PATH=/bin:/sbin:/usr/bin:$(SDK_PATH_TARGET)/usr/bin:$PATH
 
 #define library variable
 Lib_SQLite3 = "-L../../../Modularization/ocppfiles" -lsqlite3
+Lib_RatedCurrentLib = "-L./" -lModule_RatedCurrent
 
-all: clean Module_RFIDLib Module_Wifi WebServiceLib Ocpp16 \
-     Phihong_PsuCommObj Module_4g Module_UpgradeLib Infypwr_PsuCommObj \
+all: clean Module_RFIDLib Module_RatedCurrentLib Module_UpgradeLib Module_Wifi \
+     WebServiceLib Ocpp16 Phihong_PsuCommObj Module_4g Infypwr_PsuCommObj \
      Module_EventLogging Module_ProduceUtils Module_PhBackend \
-     Ocpp20 Module_InitUpgrade Module_RatedCurrentLib Module_Payment \
-     Module_DcMeter
+     Ocpp20 Module_InitUpgrade Module_Payment Module_DcMeter
 
 clean:
 	rm -f libModule_RFID.a
@@ -109,7 +109,7 @@ Module_EventLogging:
 Module_PhBackend:
 	rm -f Module_Phbackend
 	$(CC) -D $(Project) -I ../Projects -O0 -g3 -Wall -c -fmessage-length=0 -o Module_PhBackend.o Module_PhBackend.c
-	$(CC) -o Module_PhBackend Module_PhBackend.o
+	$(CC) -o Module_PhBackend Module_PhBackend.o ${Lib_RatedCurrentLib}
 	rm -f Module_PhBackend.o
 	mv -f Module_PhBackend ../rootfs/root
 
@@ -129,6 +129,6 @@ Module_Payment:
 
 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
+	$(CC) -D $(Project) "-Wl,-rpath-link,../rootfs/lib" ./DcMeter/Module_DcMeter.c ./DcMeter/meterComm.c ./DcMeter/curlApi.c ./DcMeter/SystemLogMessage.c -I ./ -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 ${Lib_RatedCurrentLib}
 	mv -f Module_DcMeter ../rootfs/root/
 

+ 4 - 4
EVSE/Modularization/Module_InitUpgrade.c

@@ -55,7 +55,7 @@
 #define NO							0
 #define true			    		1
 #define false						0
-#define MtdBlockSize				0x600000
+#define MtdBlockSize				0x300000
 
 struct SysConfigAndInfo		*ShmSysConfigAndInfo;
 struct StatusCodeData 		*ShmStatusCodeData;
@@ -143,7 +143,7 @@ int StoreUsrConfigData(struct SysConfigData *UsrData)
 	{
 		memset(BufTmp,0,MtdBlockSize);
 		memcpy(BufTmp,ptr,sizeof(struct SysConfigData));
-		for(i=0;i<MtdBlockSize-4;i++)
+		for(i=ARRAY_SIZE(UsrData->CsuBootLoadFwRev);i<MtdBlockSize-4;i++)
 			Chk+=*(BufTmp+i);
 		memcpy(BufTmp+MtdBlockSize-4, &Chk, 4);
 
@@ -169,12 +169,12 @@ int StoreUsrConfigData(struct SysConfigData *UsrData)
 
 
 		DEBUG_INFO("Erase /dev/mtd10.\n");
-		runShellCmd("flash_erase /dev/mtd10 0 12");
+		runShellCmd("flash_erase /dev/mtd10 0 0");
 		DEBUG_INFO("Write /dev/mtd10.\n");
 		runShellCmd("nandwrite -p /dev/mtd10 /mnt/EvseConfig.bin");
 
 		DEBUG_INFO("Erase /dev/mtd11.\n");
-		runShellCmd("flash_erase /dev/mtd11 0 12");
+		runShellCmd("flash_erase /dev/mtd11 0 0");
 		DEBUG_INFO("Write /dev/mtd11.\n");
 		runShellCmd("nandwrite -p /dev/mtd11 /mnt/EvseConfig.bin");
 

A diferenza do arquivo foi suprimida porque é demasiado grande
+ 2669 - 190
EVSE/Modularization/Module_PhBackend.c


+ 1 - 1
EVSE/Modularization/Module_PhBackend.h

@@ -65,7 +65,7 @@ struct Message
 struct PH_Backend_Info
 {
 	uint32_t	st_hearbeat;
-	uint32_t	st_status;
+	uint32_t	st_status[3];
 
 	uint32_t	interval_heartbeat;
 	uint32_t	interval_status;

+ 2 - 2
EVSE/Modularization/Module_ProduceUtils.c

@@ -36,7 +36,7 @@
 #define FAIL					0
 #define ON						1
 #define OFF						0
-#define MtdBlockSize			0x600000
+#define MtdBlockSize			0x300000
 
 #define LISTEN_PORT				8234
 #define	CONNECTION_LIMIT		3
@@ -214,7 +214,7 @@ int StoreUsrConfigData(struct SysConfigData *UsrData)
 		{
 			memset(BufTmp,0,MtdBlockSize);
 			memcpy(BufTmp,ptr,sizeof(struct SysConfigData));
-			for(i=0;i<MtdBlockSize-4;i++)
+			for(i=ARRAY_SIZE(UsrData->CsuBootLoadFwRev);i<MtdBlockSize-4;i++)
 				Chk+=*(BufTmp+i);
 			memcpy(BufTmp+MtdBlockSize-4, &Chk, 4);
 

+ 59 - 38
EVSE/Modularization/Module_Wifi.c

@@ -86,7 +86,7 @@
 #define LISTEN_PORT_TCP				54089
 
 #define	CONNECTION_LIMIT			3
-#define MtdBlockSize				0x600000
+#define MtdBlockSize				0x300000
 
 #define REGISTER					0x01
 #define CLEAR_REGISTER				0x02
@@ -342,6 +342,27 @@ void displayMessage(uint8_t *data, uint16_t len, uint8_t isRX)
 #endif
 }
 
+int runShellCmd(const char*cmd)
+{
+	int result = FAIL;
+	char buf[256];
+	FILE *fp;
+
+	fp = popen(cmd, "r");
+	if(fp != NULL)
+	{
+		while(fgets(buf, sizeof(buf), fp) != NULL)
+		{
+			DEBUG_INFO("%s\n", buf);
+		}
+
+		result = PASS;
+	}
+	pclose(fp);
+
+	return result;
+}
+
 //==========================================
 // Init all share memory
 //==========================================
@@ -1636,58 +1657,58 @@ int StoreUsrConfigData(struct SysConfigData *UsrData)
 	int fd,wrd;
 	unsigned int i,Chk;
 	unsigned char *ptr, *BufTmp;
-	
+
 	Chk=0;
 	ptr=(unsigned char *)UsrData;
 	if((BufTmp=malloc(MtdBlockSize))!=NULL)
 	{
 		memset(BufTmp,0,MtdBlockSize);
 		memcpy(BufTmp,ptr,sizeof(struct SysConfigData));
-		for(i=0;i<MtdBlockSize-4;i++)
+		for(i=ARRAY_SIZE(UsrData->CsuBootLoadFwRev);i<MtdBlockSize-4;i++)
 			Chk+=*(BufTmp+i);
-		memcpy(	BufTmp+MtdBlockSize-4,&Chk,4);
-		fd = open("/dev/mtdblock10", O_RDWR);
-		if (fd>0)
+		memcpy(BufTmp+MtdBlockSize-4, &Chk, 4);
+
+		// Output configuration to file.
+		fd = open("/mnt/EvseConfig.bin", O_RDWR|O_CREAT);
+		if (fd < 0)
 		{
-			wrd=write(fd, BufTmp, MtdBlockSize);
-			close(fd);
-			if(wrd>=MtdBlockSize)
-			{
-				fd = open("/dev/mtdblock11", O_RDWR);
-				if (fd>0)
-				{
-					wrd=write(fd, BufTmp, MtdBlockSize);
-    				close(fd);
-				    if(wrd<MtdBlockSize)
-					{
-						DEBUG_ERROR("write /dev/mtdblock11(backup) NG\n");
-				   		result = FAIL;
-					}
-				}
-				else
-				{
-					DEBUG_ERROR("open /dev/mtdblock11(backup) NG\n");
-					result = FAIL;
-				}
-			}
-			else
-			{
-		    	DEBUG_ERROR("write /dev/mtdblock10 NG\n");
-		    	result = FAIL;
-			}
+			DEBUG_ERROR("open /mnt/EvseConfig.bin NG\n");
+
+			free(BufTmp);
+			return 0;
 		}
-		else
+		wrd=write(fd, BufTmp, MtdBlockSize);
+		close(fd);
+		if(wrd<MtdBlockSize)
 		{
-			DEBUG_ERROR("open /dev/mtdblock10 NG\n");
-			result = FAIL;
+			DEBUG_ERROR("write /mnt/EvseConfig.bin NG\n");
+
+			free(BufTmp);
+			return 0;
 		}
+		DEBUG_INFO("EvseConfig write to file in /mnt OK.\n");
+
+
+		DEBUG_INFO("Erase /dev/mtd10.\n");
+		runShellCmd("flash_erase /dev/mtd10 0 0");
+		DEBUG_INFO("Write /dev/mtd10.\n");
+		runShellCmd("nandwrite -p /dev/mtd10 /mnt/EvseConfig.bin");
+
+		DEBUG_INFO("Erase /dev/mtd11.\n");
+		runShellCmd("flash_erase /dev/mtd11 0 0");
+		DEBUG_INFO("Write /dev/mtd11.\n");
+		runShellCmd("nandwrite -p /dev/mtd11 /mnt/EvseConfig.bin");
+
+
+		system("rm -f /mnt/EvseConfig.bin");
+		DEBUG_INFO("EvseConfig write to flash OK\n");
 	}
 	else
 	{
-		DEBUG_ERROR("alloc BlockSize NG\n");
-    	result = FAIL;
+		DEBUG_ERROR("alloc BlockSize NG\r\n");
+			result = FAIL;
 	}
-	
+
 	if(BufTmp!=NULL)
 		free(BufTmp);
 

+ 12 - 12
EVSE/Modularization/WebService.c

@@ -41,7 +41,7 @@
 #define PASS				1
 #define FAIL				-1
 
-#define MtdBlockSize 0x600000
+#define MtdBlockSize 0x300000
 
 struct SysConfigAndInfo		*ShmSysConfigAndInfo;
 struct StatusCodeData		*ShmStatusCodeData;
@@ -316,7 +316,7 @@ int StoreUsrConfigData(struct SysConfigData *UsrData)
 	{
 		memset(BufTmp,0,MtdBlockSize);
 		memcpy(BufTmp,ptr,sizeof(struct SysConfigData));
-		for(i=0;i<MtdBlockSize-4;i++)
+		for(i=ARRAY_SIZE(UsrData->CsuBootLoadFwRev);i<MtdBlockSize-4;i++)
 			Chk+=*(BufTmp+i);
 		memcpy(BufTmp+MtdBlockSize-4, &Chk, 4);
 
@@ -1759,7 +1759,7 @@ int main(int argc, char *argv[]) {
 				StartDateTime[0] = json_object_new_string((char *)&ShmSysConfigAndInfo->SysInfo.CcsChargingData[CcsGunQty].StartDateTime);
 				StopDateTime[0] = json_object_new_string((char *)&ShmSysConfigAndInfo->SysInfo.CcsChargingData[CcsGunQty].StopDateTime);
 				StartMethod[0] = json_object_new_int(ShmSysConfigAndInfo->SysInfo.CcsChargingData[CcsGunQty].StartMethod);
-				if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[CcsGunQty].ConnectorTemp == 0){
+				if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[CcsGunQty].ConnectorTemp == 0 || ShmSysConfigAndInfo->SysInfo.CcsChargingData[CcsGunQty].ConnectorTemp == 255){
 					ConnectorTemp[0] = json_object_new_int(ShmSysConfigAndInfo->SysInfo.CcsChargingData[CcsGunQty].ConnectorTemp);
 				}
 				else{
@@ -1785,7 +1785,7 @@ int main(int argc, char *argv[]) {
 				StopDateTime[0] = json_object_new_string((char *)&ShmSysConfigAndInfo->SysInfo.GbChargingData[GbGunQty].StopDateTime);
 				StartMethod[0] = json_object_new_int(ShmSysConfigAndInfo->SysInfo.GbChargingData[GbGunQty].StartMethod);
 				ConnectorTemp[0] = json_object_new_int(ShmSysConfigAndInfo->SysInfo.GbChargingData[GbGunQty].ConnectorTemp);
-				if(ShmSysConfigAndInfo->SysInfo.GbChargingData[GbGunQty].ConnectorTemp == 0 ){
+				if(ShmSysConfigAndInfo->SysInfo.GbChargingData[GbGunQty].ConnectorTemp == 0 || ShmSysConfigAndInfo->SysInfo.GbChargingData[GbGunQty].ConnectorTemp == 255){
 					ConnectorTemp[0] = json_object_new_int(ShmSysConfigAndInfo->SysInfo.GbChargingData[GbGunQty].ConnectorTemp);
 				}
 				else{
@@ -1811,7 +1811,7 @@ int main(int argc, char *argv[]) {
 				StopDateTime[0] = json_object_new_string((char *)&ShmSysConfigAndInfo->SysInfo.ChademoChargingData[CHAdeMOGunQty].StopDateTime);
 				StartMethod[0] = json_object_new_int(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[CHAdeMOGunQty].StartMethod);
 				ConnectorTemp[0] = json_object_new_int(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[CHAdeMOGunQty].ConnectorTemp);
-				if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[CHAdeMOGunQty].ConnectorTemp == 0 ){
+				if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[CHAdeMOGunQty].ConnectorTemp == 0 || ShmSysConfigAndInfo->SysInfo.ChademoChargingData[CHAdeMOGunQty].ConnectorTemp == 255){
 					ConnectorTemp[0] = json_object_new_int(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[CHAdeMOGunQty].ConnectorTemp);
 				}
 				else{
@@ -1859,7 +1859,7 @@ int main(int argc, char *argv[]) {
 				StopDateTime[1] = json_object_new_string((char *)&ShmSysConfigAndInfo->SysInfo.CcsChargingData[CcsGunQty].StopDateTime);
 				StartMethod[1] = json_object_new_int(ShmSysConfigAndInfo->SysInfo.CcsChargingData[CcsGunQty].StartMethod);
 				ConnectorTemp[1] = json_object_new_int(ShmSysConfigAndInfo->SysInfo.CcsChargingData[CcsGunQty].ConnectorTemp);
-				if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[CcsGunQty].ConnectorTemp == 0 ){
+				if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[CcsGunQty].ConnectorTemp == 0 || ShmSysConfigAndInfo->SysInfo.CcsChargingData[CcsGunQty].ConnectorTemp == 255){
 					ConnectorTemp[1] = json_object_new_int(ShmSysConfigAndInfo->SysInfo.CcsChargingData[CcsGunQty].ConnectorTemp);
 				}
 				else{
@@ -1885,7 +1885,7 @@ int main(int argc, char *argv[]) {
 				StopDateTime[1] = json_object_new_string((char *)&ShmSysConfigAndInfo->SysInfo.GbChargingData[GbGunQty].StopDateTime);
 				StartMethod[1] = json_object_new_int(ShmSysConfigAndInfo->SysInfo.GbChargingData[GbGunQty].StartMethod);
 				ConnectorTemp[1] = json_object_new_int(ShmSysConfigAndInfo->SysInfo.GbChargingData[GbGunQty].ConnectorTemp);
-				if(ShmSysConfigAndInfo->SysInfo.GbChargingData[GbGunQty].ConnectorTemp == 0 ){
+				if(ShmSysConfigAndInfo->SysInfo.GbChargingData[GbGunQty].ConnectorTemp == 0 || ShmSysConfigAndInfo->SysInfo.GbChargingData[GbGunQty].ConnectorTemp == 255){
 					ConnectorTemp[1] = json_object_new_int(ShmSysConfigAndInfo->SysInfo.GbChargingData[GbGunQty].ConnectorTemp);
 				}
 				else{
@@ -1911,7 +1911,7 @@ int main(int argc, char *argv[]) {
 				StopDateTime[1] = json_object_new_string((char *)&ShmSysConfigAndInfo->SysInfo.ChademoChargingData[CHAdeMOGunQty].StopDateTime);
 				StartMethod[1] = json_object_new_int(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[CHAdeMOGunQty].StartMethod);
 				ConnectorTemp[1] = json_object_new_int(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[CHAdeMOGunQty].ConnectorTemp);
-				if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[CHAdeMOGunQty].ConnectorTemp == 0 ){
+				if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[CHAdeMOGunQty].ConnectorTemp == 0 || ShmSysConfigAndInfo->SysInfo.ChademoChargingData[CHAdeMOGunQty].ConnectorTemp == 255){
 					ConnectorTemp[1] = json_object_new_int(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[CHAdeMOGunQty].ConnectorTemp);
 				}
 				else{
@@ -1959,7 +1959,7 @@ int main(int argc, char *argv[]) {
 				StopDateTime[2] = json_object_new_string((char *)&ShmSysConfigAndInfo->SysInfo.CcsChargingData[CcsGunQty].StopDateTime);
 				StartMethod[2] = json_object_new_int(ShmSysConfigAndInfo->SysInfo.CcsChargingData[CcsGunQty].StartMethod);
 				ConnectorTemp[2] = json_object_new_int(ShmSysConfigAndInfo->SysInfo.CcsChargingData[CcsGunQty].ConnectorTemp);
-				if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[CcsGunQty].ConnectorTemp == 0 ){
+				if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[CcsGunQty].ConnectorTemp == 0 ||ShmSysConfigAndInfo->SysInfo.CcsChargingData[CcsGunQty].ConnectorTemp == 255){
 					ConnectorTemp[2] = json_object_new_int(ShmSysConfigAndInfo->SysInfo.CcsChargingData[CcsGunQty].ConnectorTemp);
 				}
 				else{
@@ -1985,7 +1985,7 @@ int main(int argc, char *argv[]) {
 				StopDateTime[2] = json_object_new_string((char *)&ShmSysConfigAndInfo->SysInfo.GbChargingData[GbGunQty].StopDateTime);
 				StartMethod[2] = json_object_new_int(ShmSysConfigAndInfo->SysInfo.GbChargingData[GbGunQty].StartMethod);
 				ConnectorTemp[2] = json_object_new_int(ShmSysConfigAndInfo->SysInfo.GbChargingData[GbGunQty].ConnectorTemp);
-				if(ShmSysConfigAndInfo->SysInfo.GbChargingData[GbGunQty].ConnectorTemp == 0 ){
+				if(ShmSysConfigAndInfo->SysInfo.GbChargingData[GbGunQty].ConnectorTemp == 0 || ShmSysConfigAndInfo->SysInfo.GbChargingData[GbGunQty].ConnectorTemp == 255){
 					ConnectorTemp[2] = json_object_new_int(ShmSysConfigAndInfo->SysInfo.GbChargingData[GbGunQty].ConnectorTemp);
 				}
 				else{
@@ -2011,7 +2011,7 @@ int main(int argc, char *argv[]) {
 				StopDateTime[2] = json_object_new_string((char *)&ShmSysConfigAndInfo->SysInfo.ChademoChargingData[CHAdeMOGunQty].StopDateTime);
 				StartMethod[2] = json_object_new_int(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[CHAdeMOGunQty].StartMethod);
 				ConnectorTemp[2] = json_object_new_int(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[CHAdeMOGunQty].ConnectorTemp);
-				if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[CHAdeMOGunQty].ConnectorTemp == 0 ){
+				if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[CHAdeMOGunQty].ConnectorTemp == 0 || ShmSysConfigAndInfo->SysInfo.ChademoChargingData[CHAdeMOGunQty].ConnectorTemp == 255){
 					ConnectorTemp[2] = json_object_new_int(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[CHAdeMOGunQty].ConnectorTemp);
 				}
 				else{
@@ -2061,7 +2061,7 @@ int main(int argc, char *argv[]) {
 				DDStopDateTime[i] = json_object_new_string((char *)&ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].GeneralChargingData.StopDateTime);
 				DDStartMethod[i] = json_object_new_int(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].GeneralChargingData.StartMethod);
 				DDConnectorTemp[i] = json_object_new_int(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].GeneralChargingData.ConnectorTemp);
-				if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].GeneralChargingData.ConnectorTemp == 0 ){
+				if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].GeneralChargingData.ConnectorTemp == 0 || ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].GeneralChargingData.ConnectorTemp == 255){
 					ConnectorTemp[i] = json_object_new_int(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].GeneralChargingData.ConnectorTemp);
 				}
 				else{

+ 52 - 6
EVSE/Modularization/ocpp20/MessageHandler.c

@@ -4813,8 +4813,19 @@ void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct Ch
 											}
 										}
 
-										break;
+										// Delete duplicate period
+										if(compositePeriodIdx > 1)
+										{
+											if(compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].limit == compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-2].limit)
+											{
+												compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].startPeriod = -1;
+												compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].limit = -1;
+												compositePeriodIdx -= 1;
+											}
+										}
 									}
+									else
+										break;
 								}
 							}
 							else
@@ -4876,8 +4887,19 @@ void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct Ch
 								}
 							}
 
-							break;
+							// Delete duplicate period
+							if(compositePeriodIdx > 1)
+							{
+								if(compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].limit == compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-2].limit)
+								{
+									compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].startPeriod = -1;
+									compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].limit = -1;
+									compositePeriodIdx -= 1;
+								}
+							}
 						}
+						else
+							break;
 					}
 				}
 				else
@@ -4908,14 +4930,14 @@ void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct Ch
 				if((maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].startPeriod >= compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].startPeriod) &&
 				   (maxProfile.chargingSchedule[idxSchedule].duration > compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].startPeriod))
 				{
-					tmpPeriod.startPeriod = compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].startPeriod;
+					tmpPeriod.startPeriod = (compositePeriodIdx==0)?0:compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].startPeriod;
 					tmpPeriod.numberPhases = compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].numberPhases;
 					tmpPeriod.limit = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].limit;
 				}
 
-				if((maxProfile.chargingSchedule[idxSchedule].duration > compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].startPeriod))
+				if((compositePeriodIdx > 0) && (maxProfile.chargingSchedule[idxSchedule].duration > compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].startPeriod))
 				{
-					tmpPeriod.startPeriod = compositeProfile->chargingSchedule[idxSchedule].duration;
+					tmpPeriod.startPeriod = (maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].startPeriod>compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].startPeriod)?maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].startPeriod:compositeProfile->chargingSchedule[idxSchedule].duration;
 					tmpPeriod.numberPhases = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].numberPhases;
 					tmpPeriod.limit = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].limit;
 				}
@@ -4934,6 +4956,17 @@ void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct Ch
 							memcpy(&compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct ChargingSchedulePeriodType));
 						}
 					}
+
+					// Delete duplicate period
+					if(compositePeriodIdx > 1)
+					{
+						if(compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].limit == compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-2].limit)
+						{
+							compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].startPeriod = -1;
+							compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].limit = -1;
+							compositePeriodIdx -= 1;
+						}
+					}
 				}
 			}
 		}
@@ -12164,12 +12197,19 @@ int handleGetCompositeScheduleRequest(char *uuid, char *payload)
   			DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule.chargingSchedule.chargingSchedulePeriod[idx].limit);
 
   			if((ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule.chargingSchedule.chargingSchedulePeriod[idx].startPeriod==0) &&
-  			   (ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule.chargingSchedule.chargingSchedulePeriod[idx].limit==0))
+  			   (ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule.chargingSchedule.chargingSchedulePeriod[idx].limit==0) &&
+			   (idx<(ARRAY_SIZE(ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule.chargingSchedule.chargingSchedulePeriod)-1)?(ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule.chargingSchedule.chargingSchedulePeriod[idx+1].startPeriod==0):TRUE))
   			{
   				confirmPeriods = idx;
   				break;
   			}
   		}
+
+  		if((confirmPeriods == 0) && (tmpProfile[0].id > 0))
+  		{
+  			confirmPeriods += 1;
+  		}
+
   		sprintf(comfirmstr, "%s", GetCompositeScheduleStatusEnumTypeStr[GenericStatusEnumType_Accepted]);
   	}
   	else
@@ -17019,6 +17059,12 @@ int GetInternetConn(void)
 	return ShmSysConfigAndInfo->SysInfo.InternetConn;
 }
 
+int GetBackendConnectionTimeout(void)
+{
+	return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
+}
+
+
 int isConnectorInitMode(int gun_index)
 {
 	int tempIndex = 0;

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

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

+ 2 - 2
EVSE/Modularization/ocpp20/Module_OcppBackend20.c

@@ -401,8 +401,8 @@ void* ConnectWsServer(void* data)  //int ConnectWsServer()
 	}
 
 	ContextInfo.protocols = protocols;
-	ContextInfo.timeout_secs = GetWebSocketPingInterval();//WebSocketPingInterval;//30;//9999;//30;
-	ContextInfo.ws_ping_pong_interval = GetWebSocketPingInterval();//WebSocketPingInterval;//30;//0 for none, else interval in seconds
+	ContextInfo.timeout_secs = GetBackendConnectionTimeout();
+	ContextInfo.ws_ping_pong_interval = GetWebSocketPingInterval();
 	ContextInfo.ka_time = 20;
 	ContextInfo.keepalive_timeout = 5;
 	ContextInfo.ka_probes = 2;

+ 52 - 6
EVSE/Modularization/ocppfiles/MessageHandler.c

@@ -2495,8 +2495,19 @@ void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct St
 											}
 										}
 
-										break;
+										// Delete duplicate period
+										if(compositePeriodIdx > 1)
+										{
+											if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
+											{
+												compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
+												compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
+												compositePeriodIdx -= 1;
+											}
+										}
 									}
+									else
+										break;
 								}
 							}
 							else
@@ -2558,8 +2569,20 @@ void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct St
 								}
 							}
 
-							break;
+							// Delete duplicate period
+							if(compositePeriodIdx > 1)
+							{
+								if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
+								{
+									compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
+									compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
+									compositePeriodIdx -= 1;
+								}
+							}
 						}
+						else
+
+							break;
 					}
 				}
 				else
@@ -2590,14 +2613,14 @@ void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct St
 				if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod >= compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod) &&
 				   (maxProfile.ChargingSchedule.Duration > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod))
 				{
-					tmpPeriod.StartPeriod = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod;
+					tmpPeriod.StartPeriod = (compositePeriodIdx==0)?0:compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod;
 					tmpPeriod.NumberPhases = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].NumberPhases;
 					tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
 				}
 
-				if((maxProfile.ChargingSchedule.Duration > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod))
+				if((compositePeriodIdx > 0 ) && (maxProfile.ChargingSchedule.Duration > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod))
 				{
-					tmpPeriod.StartPeriod = compositeProfile->ChargingSchedule.Duration;
+					tmpPeriod.StartPeriod = (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod>compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod)?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod:compositeProfile->ChargingSchedule.Duration;
 					tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
 					tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
 				}
@@ -2616,6 +2639,17 @@ void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct St
 							memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
 						}
 					}
+
+					// Delete duplicate period
+					if(compositePeriodIdx > 1)
+					{
+						if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
+						{
+							compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
+							compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
+							compositePeriodIdx -= 1;
+						}
+					}
 				}
 			}
 		}
@@ -8634,12 +8668,19 @@ int handleGetCompositeScheduleRequest(char *uuid, char *payload)
   			DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
 
   			if((ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
-  			   (ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0))
+  			   (ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0) &&
+			   (idx<(ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod)-1)?(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx+1].StartPeriod==0):TRUE))
   			{
   				confirmPeriods = idx;
   				break;
   			}
   		}
+
+  		if((confirmPeriods == 0) && (tmpProfile[0].ChargingProfileId > 0))
+  		{
+  			confirmPeriods += 1;
+  		}
+
   		sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
   	}
   	else
@@ -17617,6 +17658,11 @@ int GetInternetConn(void)
 	return ShmSysConfigAndInfo->SysInfo.InternetConn;
 }
 
+int GetBackendConnectionTimeout(void)
+{
+	return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
+}
+
 int isConnectorInitMode(int gun_index)
 {
 	int tempIndex = 0;

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

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

+ 2 - 2
EVSE/Modularization/ocppfiles/Module_OcppBackend.c

@@ -462,8 +462,8 @@ void* ConnectWsServer(void* data)  //int ConnectWsServer()
 	}
 
 	ContextInfo.protocols = protocols;
-	ContextInfo.timeout_secs = GetWebSocketPingInterval();//WebSocketPingInterval;//30;//9999;//30;
-	ContextInfo.ws_ping_pong_interval = GetWebSocketPingInterval();//WebSocketPingInterval;//30;//0 for none, else interval in seconds
+	ContextInfo.timeout_secs = GetBackendConnectionTimeout();
+	ContextInfo.ws_ping_pong_interval = GetWebSocketPingInterval();
 	ContextInfo.ka_time = 20;
 	ContextInfo.keepalive_timeout = 5;
 	ContextInfo.ka_probes = 2;

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

@@ -2,7 +2,7 @@
  * Module_LcmControl.c
  *
  * Created on : 2020-10-20
- * Update on : 2021-02-20
+ * Update on : 2021-06-23
  * Author : Folus Wen, Eason Yang
  * Version : D0.01
  *
@@ -12,6 +12,7 @@
 #include	"define.h"
 #include	"main.h"
 #include 	"lcmComm_dgus.h"
+#include	"cbmp.h"
 
 //=======================================
 // Declare share memory
@@ -68,7 +69,6 @@ void setEthernetIcon();
 void setAlarmCodeAndIcon();
 void setBillingFromWebsite();
 
-
 //=======================================
 // Declare Timer
 //=======================================
@@ -116,7 +116,7 @@ uint8_t isCharging	= YES;
 //=======================================
 // Record version and date
 //=======================================
-char *FIRMWARE_UPDATE_IMAGE[3] = {"V0.17", "2021-04-28", "REV.01.00"};
+char *FIRMWARE_UPDATE_IMAGE[3] = {"V0.18", "2021-06-23", "REV.01.00"};
 
 
 //=======================================
@@ -893,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))
@@ -1563,35 +1563,50 @@ void setBatteryAnimation(uint8_t gun_index, uint8_t system_mode)
 				// SET BATTERY PERCENTAGE TEXT TO DISAPPEAR
 				setDisplayValue(TEXT_PERCENTAGE, DISAPPEAR);
 
-				// SET BATTERY ANIMATION
-				if((BATTERY_LEVEL_STATUS == BATTERY_LEVEL_5))
-				{
-					setDisplayValue(ICON_BATTERY_CHARGING, BATTERY_CAPACITY_EMPTY);
-					BATTERY_LEVEL_STATUS = BATTERY_LEVEL_0;
-				}
-				else if((BATTERY_LEVEL_STATUS == BATTERY_LEVEL_0) && (DiffTimebWithNow(startTime[gun_index][TMR_IDX_BATTERY]) > (TIME_ANIMATION_BATTERY)))
-				{
-					setDisplayValue(ICON_BATTERY_CHARGING, BATTERY_CAPACITY_20);
-					BATTERY_LEVEL_STATUS = BATTERY_LEVEL_1;
-				}
-				else if((BATTERY_LEVEL_STATUS == BATTERY_LEVEL_1) && (DiffTimebWithNow(startTime[gun_index][TMR_IDX_BATTERY]) > (TIME_ANIMATION_BATTERY*2)))
+				if((ShmCharger->gun_info[gun_index].primaryMcuState.relay_state == ON))
 				{
-					setDisplayValue(ICON_BATTERY_CHARGING, BATTERY_CAPACITY_40);
-					BATTERY_LEVEL_STATUS = BATTERY_LEVEL_2;
-				}
-				else if((BATTERY_LEVEL_STATUS == BATTERY_LEVEL_2) && (DiffTimebWithNow(startTime[gun_index][TMR_IDX_BATTERY]) > (TIME_ANIMATION_BATTERY*3)))
-				{
-					setDisplayValue(ICON_BATTERY_CHARGING, BATTERY_CAPACITY_60);
-					BATTERY_LEVEL_STATUS = BATTERY_LEVEL_3;
-				}
-				else if((BATTERY_LEVEL_STATUS == BATTERY_LEVEL_3) && (DiffTimebWithNow(startTime[gun_index][TMR_IDX_BATTERY]) > (TIME_ANIMATION_BATTERY*4)))
-				{
-					setDisplayValue(ICON_BATTERY_CHARGING, BATTERY_CAPACITY_80);
-					BATTERY_LEVEL_STATUS = BATTERY_LEVEL_4;
+					// SET BATTERY ANIMATION
+					if((BATTERY_LEVEL_STATUS == BATTERY_LEVEL_5))
+					{
+						setDisplayValue(ICON_BATTERY_CHARGING, BATTERY_CAPACITY_EMPTY);
+						BATTERY_LEVEL_STATUS = BATTERY_LEVEL_0;
+					}
+					else if((BATTERY_LEVEL_STATUS == BATTERY_LEVEL_0) && (DiffTimebWithNow(startTime[gun_index][TMR_IDX_BATTERY]) > (TIME_ANIMATION_BATTERY)))
+					{
+						setDisplayValue(ICON_BATTERY_CHARGING, BATTERY_CAPACITY_20);
+						BATTERY_LEVEL_STATUS = BATTERY_LEVEL_1;
+					}
+					else if((BATTERY_LEVEL_STATUS == BATTERY_LEVEL_1) && (DiffTimebWithNow(startTime[gun_index][TMR_IDX_BATTERY]) > (TIME_ANIMATION_BATTERY*2)))
+					{
+						setDisplayValue(ICON_BATTERY_CHARGING, BATTERY_CAPACITY_40);
+						BATTERY_LEVEL_STATUS = BATTERY_LEVEL_2;
+					}
+					else if((BATTERY_LEVEL_STATUS == BATTERY_LEVEL_2) && (DiffTimebWithNow(startTime[gun_index][TMR_IDX_BATTERY]) > (TIME_ANIMATION_BATTERY*3)))
+					{
+						setDisplayValue(ICON_BATTERY_CHARGING, BATTERY_CAPACITY_60);
+						BATTERY_LEVEL_STATUS = BATTERY_LEVEL_3;
+					}
+					else if((BATTERY_LEVEL_STATUS == BATTERY_LEVEL_3) && (DiffTimebWithNow(startTime[gun_index][TMR_IDX_BATTERY]) > (TIME_ANIMATION_BATTERY*4)))
+					{
+						setDisplayValue(ICON_BATTERY_CHARGING, BATTERY_CAPACITY_80);
+						BATTERY_LEVEL_STATUS = BATTERY_LEVEL_4;
+					}
+					else if((BATTERY_LEVEL_STATUS == BATTERY_LEVEL_4) &&  (DiffTimebWithNow(startTime[gun_index][TMR_IDX_BATTERY]) > (TIME_ANIMATION_BATTERY*5)))
+					{
+						setDisplayValue(ICON_BATTERY_CHARGING, BATTERY_CAPACITY_100);
+						BATTERY_LEVEL_STATUS = BATTERY_LEVEL_5;
+						ftime(&startTime[gun_index][TMR_IDX_BATTERY]);
+					}
 				}
-				else if((BATTERY_LEVEL_STATUS == BATTERY_LEVEL_4) &&  (DiffTimebWithNow(startTime[gun_index][TMR_IDX_BATTERY]) > (TIME_ANIMATION_BATTERY*5)))
+				else
 				{
-					setDisplayValue(ICON_BATTERY_CHARGING, BATTERY_CAPACITY_100);
+					// SET BATTERY ICON TO EMPTY ICON
+					setDisplayValue(ICON_BATTERY_CHARGING, BATTERY_CAPACITY_EMPTY);
+
+					// SET BATTERY PERCENTAGE TO DISAPPEAR
+					setDisplayValue(TEXT_PERCENTAGE, DISAPPEAR);
+
+					// RESET TO DEFAULT VALUE
 					BATTERY_LEVEL_STATUS = BATTERY_LEVEL_5;
 					ftime(&startTime[gun_index][TMR_IDX_BATTERY]);
 				}
@@ -1687,16 +1702,34 @@ void setConnectionAnimation(uint8_t gun_index, uint8_t system_mode)
 
 			break;
 		case SYS_MODE_CHARGING:
-			if((CONNECTION_LEVEL_STATUS == CONNECTION_LEVEL_0) && (DiffTimebWithNow(startTime[gun_index][TMR_IDX_CONNECTION]) > (TIME_ANIMATION_CONNECTION)))
+
+			if((ShmCharger->gun_info[gun_index].primaryMcuState.relay_state == ON))
 			{
-				setDisplayValue(ICON_CONNECTION_CHARGING, CONNECTION_ELECTRIC_MARK_1);
-				CONNECTION_LEVEL_STATUS = CONNECTION_LEVEL_1;
+				if((CONNECTION_LEVEL_STATUS == CONNECTION_LEVEL_0) && (DiffTimebWithNow(startTime[gun_index][TMR_IDX_CONNECTION]) > (TIME_ANIMATION_CONNECTION)))
+				{
+					setDisplayValue(ICON_CONNECTION_CHARGING, CONNECTION_ELECTRIC_MARK_1);
+					CONNECTION_LEVEL_STATUS = CONNECTION_LEVEL_1;
+				}
+				else if((CONNECTION_LEVEL_STATUS == CONNECTION_LEVEL_1) && (DiffTimebWithNow(startTime[gun_index][TMR_IDX_CONNECTION]) > (TIME_ANIMATION_CONNECTION*2)))
+				{
+					setDisplayValue(ICON_CONNECTION_CHARGING, CONNECTION_ELECTRIC_MARK_2);
+					CONNECTION_LEVEL_STATUS =  CONNECTION_LEVEL_0;
+					ftime(&startTime[gun_index][TMR_IDX_CONNECTION]);
+				}
 			}
-			else if((CONNECTION_LEVEL_STATUS == CONNECTION_LEVEL_1) && (DiffTimebWithNow(startTime[gun_index][TMR_IDX_CONNECTION]) > (TIME_ANIMATION_CONNECTION*2)))
+			else
 			{
-				setDisplayValue(ICON_CONNECTION_CHARGING, CONNECTION_ELECTRIC_MARK_2);
-				CONNECTION_LEVEL_STATUS =  CONNECTION_LEVEL_0;
-				ftime(&startTime[gun_index][TMR_IDX_CONNECTION]);
+				if((CONNECTION_LEVEL_STATUS == CONNECTION_LEVEL_0) && (DiffTimebWithNow(startTime[gun_index][TMR_IDX_CONNECTION]) > (TIME_ANIMATION_CONNECTION)))
+				{
+					setDisplayValue(ICON_CONNECTION_CHARGING, CONNECTION_QUESTION_MARK_1);
+					CONNECTION_LEVEL_STATUS = CONNECTION_LEVEL_1;
+				}
+				else if((CONNECTION_LEVEL_STATUS == CONNECTION_LEVEL_1) && (DiffTimebWithNow(startTime[gun_index][TMR_IDX_CONNECTION]) > (TIME_ANIMATION_CONNECTION*2)))
+				{
+					setDisplayValue(ICON_CONNECTION_CHARGING, CONNECTION_QUESTION_MARK_2);
+					CONNECTION_LEVEL_STATUS =  CONNECTION_LEVEL_0;
+					ftime(&startTime[gun_index][TMR_IDX_CONNECTION]);
+				}
 			}
 
 			break;
@@ -2029,6 +2062,186 @@ int InitComPort()
 	return fd;
 }
 
+//=======================================
+// Download image
+//=======================================
+int downloadBMP(uint8_t picIdx, char *filename)
+{
+	int result = PASS;
+	BMP *bmp;
+	struct stat fileSt;
+	uint32_t pageSize = 0xf0;
+	uint32_t pixelSize;
+	uint32_t transferedByte=0;
+	uint16_t bufferRamAddr = 0x8000;
+
+	// Reset LCD
+	uint8_t cmd_reset[] = {0x55, 0xaa, 0x5a, 0xa5};
+	if(lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, 0x04, cmd_reset, ARRAY_SIZE(cmd_reset)) == FAIL)
+	{
+		DEBUG_INFO("LCD reset fail.\n");
+	}
+
+	// Get image file size
+	stat(filename, &fileSt);
+	bmp = bopen(filename);
+	uint8_t buf[bmp->width*bmp->height*2];
+
+	DEBUG_INFO("Image filename: %s\n", filename);
+	DEBUG_INFO("Image width: %d height: %d\n", bmp->width, bmp->height);
+	DEBUG_INFO("Image data size: %d\n", ARRAY_SIZE(buf));
+
+	// Get bmp pixel data and convert to 16 bit color
+	for(uint16_t idxY=0 ; idxY<bmp->height ; idxY++)
+	{
+		for(uint16_t idxX=0 ; idxX<bmp->width ; idxX++)
+		{
+			uint8_t r, g, b;
+			get_pixel_rgb(bmp, idxX, (bmp->height-idxY-1), &r, &g, &b);
+			buf[(2*((idxY*bmp->width) + idxX)) + 0] = ((((r>>3)<<11) | ((g>>2)<<5) | (b>>3)) >> 8) & 0xff;
+			buf[(2*((idxY*bmp->width) + idxX)) + 1] = ((((r>>3)<<11) | ((g>>2)<<5) | (b>>3)) >> 0) & 0xff;
+		}
+	}
+	bclose(bmp);
+
+	// Transfer pixel to screen page
+	pixelSize = ARRAY_SIZE(buf);
+	for(uint16_t idxSrcData=0;idxSrcData<(((pixelSize%pageSize)==0)?(pixelSize/pageSize):(pixelSize/pageSize)+1);idxSrcData++)
+	{
+		//DEBUG_INFO("Buffer start data address: 0x%08X\n", (idxSrcData*pageSize));
+		//DEBUG_INFO("  Image start ram address: 0x%08X\n", ((idxSrcData*pageSize) >> 1));
+		uint8_t display_cmd[] ={0x5a, (bufferRamAddr>>8)&0xff, (bufferRamAddr>>0)&0xff, 0x00, 0x00, 0x00, 0x00, 0x00};
+
+		if((idxSrcData+1) != (((pixelSize%pageSize)==0)?(pixelSize/pageSize):(pixelSize/pageSize)+1))
+		{
+			// Data transfer
+			while(lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, bufferRamAddr, &buf[(idxSrcData*pageSize)], pageSize) != PASS)
+			{
+				DEBUG_INFO("Transfer data to ram 0x%04X fail.\n", transferedByte);
+			}
+			transferedByte += pageSize;
+
+			display_cmd[3] = ((pageSize>>1) >> 8) & 0xff;							// Data length high byte
+			display_cmd[4] = ((pageSize>>1) >> 0) & 0xff;							// Data length low byte
+			display_cmd[5] = (((idxSrcData*pageSize)>>1) >> 16) & 0xff;				// Screen on ram address 1st byte
+			display_cmd[6] = (((idxSrcData*pageSize)>>1) >> 8) & 0xff;				// Screen on ram address 2nd byte
+			display_cmd[7] = (((idxSrcData*pageSize)>>1) >> 0) & 0xff;				// Screen on ram address 3th byte
+		}
+		else
+		{
+			// Last data transfer
+			while(lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, bufferRamAddr, &buf[(idxSrcData*pageSize)], (pixelSize-(idxSrcData*pageSize))) != PASS)
+			{
+				DEBUG_INFO("Transfer data to ram 0x%04X fail.\n", transferedByte);
+			}
+			transferedByte += (pixelSize-(idxSrcData*pageSize));
+
+			display_cmd[3] = (((pixelSize-(idxSrcData*pageSize))>>1) >> 8) & 0xff;	// Data length high byte
+			display_cmd[4] = (((pixelSize-(idxSrcData*pageSize))>>1) >> 0) & 0xff;	// Data length low byte
+			display_cmd[5] = (((idxSrcData*pageSize)>>1) >> 16) & 0xff;				// Screen on ram address 1st byte
+			display_cmd[6] = (((idxSrcData*pageSize)>>1) >> 8) & 0xff;				// Screen on ram address 2nd byte
+			display_cmd[7] = (((idxSrcData*pageSize)>>1) >> 0) & 0xff;				// Screen on ram address 3th byte
+		}
+
+		// Move data from ram to flash
+		while(lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, 0xa2, display_cmd, ARRAY_SIZE(display_cmd)) != PASS)
+		{
+			DEBUG_INFO("Write data to display buffer 0x%04X fail.\n", transferedByte);
+		}
+	}
+
+	// Save image to target address
+	uint8_t save_cmd[] ={0x5a, 0x02, ((picIdx>>8)&0xff), (picIdx&0xff)};
+	while(lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, 0x84, save_cmd, ARRAY_SIZE(save_cmd)) != PASS)
+	{
+		DEBUG_INFO("Save image fail.\n");
+	}
+	DEBUG_INFO("Save image success.\n");
+
+	return result;
+}
+
+//=======================================
+// Download image
+//=======================================
+int downloadBIN(uint8_t targetAddr, char *filename)
+{
+	int result = PASS;
+	int fd;
+	struct stat fileSt;
+	uint32_t pageSize = 128;
+	uint32_t blocklSize = 32768;
+	uint32_t transferedByte=0;
+	uint16_t bufferRamAddr = 0x8000;
+
+	// Reset LCD
+	uint8_t cmd_reset[] = {0x55, 0xaa, 0x5a, 0xa5};
+	if(lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, 0x04, cmd_reset, ARRAY_SIZE(cmd_reset)) == FAIL)
+	{
+		DEBUG_INFO("LCD reset fail.\n");
+	}
+
+	// Get image file size
+	stat(filename, &fileSt);
+	uint8_t buf[(fileSt.st_size%32768==0?fileSt.st_size/32768:(fileSt.st_size/32768)+1)*32768];
+
+	DEBUG_INFO("Bin filename: %s\n", filename);
+	DEBUG_INFO("Bin data size: %d\n", fileSt.st_size);
+
+	fd = open(filename, O_RDWR);
+	if (fd < 0)
+	{
+		DEBUG_WARN("Bin can not be open.\n");
+		result = FAIL;
+	}
+	else
+	{
+		for(uint8_t idxBinSrc=0;idxBinSrc<(fileSt.st_size%32768==0?fileSt.st_size/32768:(fileSt.st_size/32768)+1);idxBinSrc++)
+		{
+			// Read data from bin file
+			memset(buf, 0x00, ARRAY_SIZE(buf));
+			read(fd, buf, ARRAY_SIZE(buf));
+			close(fd);
+
+			// Transfer data to ram
+			for(uint16_t idxSrcData=0;idxSrcData<(((blocklSize%pageSize)==0)?(blocklSize/pageSize):(blocklSize/pageSize)+1);idxSrcData++)
+			{
+				//DEBUG_INFO("Buffer start data address: 0x%08X\n", (idxBinSrc*blocklSize)+(idxSrcData*pageSize));
+				//DEBUG_INFO("  Image start ram address: 0x%08X\n", ((idxSrcData*pageSize) >> 1));
+
+				if((idxSrcData+1) != (((blocklSize%pageSize)==0)?(blocklSize/pageSize):(blocklSize/pageSize)+1))
+				{
+					// Data transfer
+					while(lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, bufferRamAddr+((idxSrcData*pageSize)>>1), &buf[(idxBinSrc*blocklSize)+(idxSrcData*pageSize)], pageSize) != PASS)
+					{
+						DEBUG_INFO("Transfer data to ram 0x%04X fail.\n", transferedByte);
+					}
+					transferedByte += pageSize;
+				}
+				else
+				{
+					// Last data transfer
+					while(lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, bufferRamAddr+((idxSrcData*pageSize)>>1), &buf[(idxBinSrc*blocklSize)+(idxSrcData*pageSize)], (blocklSize-(idxSrcData*pageSize)))!= PASS)
+					{
+						DEBUG_INFO("Transfer data to ram 0x%04X fail.\n", transferedByte);
+					}
+					transferedByte += (blocklSize-(idxSrcData*pageSize));
+				}
+			}
+
+			// Move data from ram to flash
+			uint8_t save_cmd[] ={0x5a, 0x02, ((((targetAddr*8)+idxBinSrc)>>8)&0xff), ((((targetAddr*8)+idxBinSrc)>>0)&0xff), ((bufferRamAddr>>8)&0xff), ((bufferRamAddr>>0)&0xff), 0x00, 0x01, 0x00, 0x00, 0x00, 0x00};
+			while(lcdRegisterWrite(Uart1Fd, REG_TYPE_RAM, 0xaa, save_cmd, ARRAY_SIZE(save_cmd)) != PASS)
+			{
+				DEBUG_INFO("Save bin file to 0x%04X fail.\n", ((targetAddr*8)+idxBinSrc));
+			}
+			DEBUG_INFO("Save bin file on 0x%04X success.\n", ((targetAddr*8)+idxBinSrc));
+		}
+	}
+
+	return result;
+}
+
 //=======================================
 // Main process
 //=======================================

+ 315 - 0
EVSE/Projects/AW-CCS/Apps/LCM/cbmp.c

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

+ 54 - 0
EVSE/Projects/AW-CCS/Apps/LCM/cbmp.h

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

+ 25 - 5
EVSE/Projects/AW-CCS/Apps/LCM/lcmComm_dgus.c

@@ -2,7 +2,7 @@
  * lcmComm_dgus.c
  *
  * Created on : 2020-10-20
- * Update on : 2021-02-20
+ * Update on : 2021-06-23
  * Author : Folus Wen, Eason Yang
  * Version : D0.01
  *
@@ -51,7 +51,27 @@ int transceiverDgus(int32_t fd, uint8_t *tx, uint16_t tx_len, uint8_t *rx, uint1
 	{
 		if(tx[3] == CMD_REG_WRITE_DATA)
 		{
-			result = PASS;
+			len = read(fd, rx, rx_len);
+			if(len > 0)
+			{
+				if((rx[0] == CMD_HEADER_1) && (rx[1] == CMD_HEADER_2))
+				{
+					if((rx[3] == CMD_REG_WRITE_DATA) && ((rx[4] == CMD_ACK_VALUE_1) && (rx[5] == CMD_ACK_VALUE_2)))
+					{
+						#ifdef isDebugPrint
+						displayMessageDgus(rx, len, YES);
+						#endif
+
+						result = PASS;
+					}
+					else
+					{}
+				}
+				else
+				{}
+			}
+			else
+			{}
 		}
 		else if(tx[3] == CMD_REG_READ_DATA)
 		{
@@ -62,9 +82,9 @@ int transceiverDgus(int32_t fd, uint8_t *tx, uint16_t tx_len, uint8_t *rx, uint1
 				{
 					if(rx[3] == CMD_REG_READ_DATA)
 					{
-
+						#ifdef isDebugPrint
 						displayMessageDgus(rx, len, YES);
-
+						#endif
 
 						result = PASS;
 					}
@@ -122,7 +142,7 @@ int8_t lcdRegisterWrite(int32_t fd, uint8_t regType, uint16_t address, uint8_t *
 
 	if(fd > 0)
 	{
-		if(transceiverDgus(fd, tx, ARRAY_SIZE(tx), rx, ARRAY_SIZE(rx)))
+		if(transceiverDgus(fd, tx, ARRAY_SIZE(tx), rx, ARRAY_SIZE(rx)) == PASS)
 		{
 			result = PASS;
 		}

+ 3 - 1
EVSE/Projects/AW-CCS/Apps/LCM/lcmComm_dgus.h

@@ -2,7 +2,7 @@
  * lcmComm_dwin.h
  *
  * Created on : 2020-10-20
- * Update on : 2021-02-20
+ * Update on : 2021-06-23
  * Author : Folus Wen, Eason Yang
  * Version : D0.01
  *
@@ -79,6 +79,8 @@
 #define CMD_REG_READ						0x81
 #define CMD_REG_WRITE_DATA					0x82
 #define CMD_REG_READ_DATA					0x83
+#define CMD_ACK_VALUE_1						0x4F
+#define CMD_ACK_VALUE_2						0x4B
 
 //=======================================
 // LCD system screen

+ 2 - 2
EVSE/Projects/AW-CCS/Apps/Module_ConfigTools.c

@@ -52,7 +52,7 @@
 #define NO								0
 #define ON								1
 #define OFF								0
-#define MtdBlockSize 					0x600000
+#define MtdBlockSize 					0x300000
 
 struct SysConfigAndInfo			*ShmSysConfigAndInfo;
 struct StatusCodeData			*ShmStatusCodeData;
@@ -126,7 +126,7 @@ int StoreUsrConfigData(struct SysConfigData *UsrData)
 	{
 		memset(BufTmp,0,MtdBlockSize);
 		memcpy(BufTmp,ptr,sizeof(struct SysConfigData));
-		for(i=0;i<MtdBlockSize-4;i++)
+		for(i=ARRAY_SIZE(UsrData->CsuBootLoadFwRev);i<MtdBlockSize-4;i++)
 			Chk+=*(BufTmp+i);
 		memcpy(BufTmp+MtdBlockSize-4, &Chk, 4);
 

+ 3 - 3
EVSE/Projects/AW-CCS/Apps/Module_FactoryConfig.c

@@ -230,7 +230,7 @@ void helpOutput(void)
 int main(int argc, char *argv[])
 {
 	unsigned char outType=0;
-	unsigned int i,Chk,MtdBlockSize=0x600000;
+	unsigned int i,Chk,MtdBlockSize=0x300000;
 	unsigned char *ptr;
 	int fd,wrd;
 
@@ -347,7 +347,7 @@ int main(int argc, char *argv[])
 
 	// Calculate CRC
 	Chk=0;
-	for(i=0;i<(MtdBlockSize-4);i++)
+	for(i=ARRAY_SIZE(SysConfig.CsuBootLoadFwRev);i<(MtdBlockSize-4);i++)
 	{
 		Chk+=*(ptr+i);
 	}
@@ -393,7 +393,7 @@ int main(int argc, char *argv[])
 	 * Configuration bin file generate
 	 */
 	// Save factory default setting value to file
-	fd = open("/mnt/FactoryDefaultConfig.bin", O_RDWR|O_CREAT);
+	fd = open("/mnt/FactoryDefaultConfig.bin", O_RDWR|O_CREAT|O_TRUNC);
 	if (fd < 0)
 	{
 

+ 17 - 19
EVSE/Projects/AW-CCS/Apps/main.c

@@ -39,7 +39,7 @@
 #define GPIO_OUT_RST_QCA				115
 #define GPIO_OUT_RST_ETH				89
 
-#define MtdBlockSize 					0x600000
+#define MtdBlockSize 					0x300000
 
 #define DB_FILE							"/Storage/ChargeLog/localCgargingRecord.db"
 //==========================
@@ -1782,12 +1782,15 @@ int LoadSysConfigAndInfo(struct SysConfigData *ptr)
 		sleep(5);
 		system("reboot -f");
 	}
+
 	ChkSum=0;
-	for(wrd=0;wrd<MtdBlockSize-4;wrd++)
+	for(wrd=ARRAY_SIZE(ptr->CsuBootLoadFwRev);wrd<MtdBlockSize-4;wrd++)
 	{
 		ChkSum+=buf[wrd];
 	}
 	memcpy(&ChkSumOrg,buf+(MtdBlockSize-4),sizeof(ChkSumOrg));
+	memcpy(&ptr->ModelName,buf+(ARRAY_SIZE(ptr->CsuBootLoadFwRev)),ARRAY_SIZE(ptr->ModelName));
+	memcpy(&ptr->SerialNumber,buf+(ARRAY_SIZE(ptr->CsuBootLoadFwRev)+ARRAY_SIZE(ptr->ModelName)+ARRAY_SIZE(ptr->AcModelName)),ARRAY_SIZE(ptr->SerialNumber));
 
 	//================================================
 	// Load configuration from mtdblock11
@@ -1796,7 +1799,7 @@ int LoadSysConfigAndInfo(struct SysConfigData *ptr)
 	{
 		DEBUG_ERROR("Primary SysConfigData checksum NG, read backup\n");
 		system("nanddump /dev/mtd11 -f /mnt/EvseConfig.bin");
-		fd = open("/mnt/EvseConfig", O_RDWR);
+		fd = open("/mnt/EvseConfig.bin", O_RDWR);
 		if (fd < 0)
 		{
 			free(buf);
@@ -1830,8 +1833,9 @@ int LoadSysConfigAndInfo(struct SysConfigData *ptr)
 			sleep(5);
 			system("reboot -f");
 		}
+
 		ChkSum=0;
-		for(wrd=0;wrd<MtdBlockSize-4;wrd++)
+		for(wrd=ARRAY_SIZE(ptr->CsuBootLoadFwRev);wrd<MtdBlockSize-4;wrd++)
 		{
 			ChkSum+=buf[wrd];
 		}
@@ -1876,12 +1880,16 @@ int LoadSysConfigAndInfo(struct SysConfigData *ptr)
 				sleep(5);
 				system("reboot -f");
 			}
+
 			ChkSum=0;
-			for(wrd=0;wrd<MtdBlockSize-4;wrd++)
+			for(wrd=ARRAY_SIZE(ptr->CsuBootLoadFwRev);wrd<MtdBlockSize-4;wrd++)
 			{
 				ChkSum+=buf[wrd];
 			}
 			memcpy(&ChkSumOrg,buf+(MtdBlockSize-4),sizeof(ChkSumOrg));
+			memcpy(buf+(ARRAY_SIZE(ptr->CsuBootLoadFwRev)), &ptr->ModelName, ARRAY_SIZE(ptr->ModelName));
+			memcpy(buf+(ARRAY_SIZE(ptr->CsuBootLoadFwRev)+ARRAY_SIZE(ptr->ModelName)+ARRAY_SIZE(ptr->AcModelName)), &ptr->SerialNumber, ARRAY_SIZE(ptr->SerialNumber));
+
 			if(ChkSum!=ChkSumOrg)
 			{
 				DEBUG_WARN("factory default  SysConfigData checksum NG, restore factory default\n");
@@ -3822,7 +3830,7 @@ void checkChargingProfileLimit(uint8_t gun_index)
 						  )
 						{
 							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].NumberPhases):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;
@@ -5276,7 +5284,6 @@ int main(void)
 								if(ShmCharger->gun_info[gun_index].chargingMode == CHARGING_MODE_BS)
 								{
 									setRelay(gun_index, OFF);
-									setRequest(gun_index, OFF);
 									ShmCharger->gun_info[gun_index].isChargerStopByCondition = YES;
 								}
 								else if(ShmCharger->gun_info[gun_index].chargingMode == CHARGING_MODE_HLC)
@@ -5291,7 +5298,6 @@ int main(void)
 								if(ShmCharger->gun_info[gun_index].chargingMode == CHARGING_MODE_BS)
 								{
 									setRelay(gun_index, OFF);
-									setRequest(gun_index, OFF);
 									ShmCharger->gun_info[gun_index].isChargerStopByCondition = YES;
 								}
 								else if(ShmCharger->gun_info[gun_index].chargingMode == CHARGING_MODE_HLC)
@@ -5329,7 +5335,6 @@ int main(void)
 									if(ShmCharger->gun_info[gun_index].chargingMode == CHARGING_MODE_BS)
 									{
 										setRelay(gun_index, OFF);
-										setRequest(gun_index, OFF);
 										ShmCharger->gun_info[gun_index].isChargerStopByCondition = YES;
 									}
 									else if(ShmCharger->gun_info[gun_index].chargingMode == CHARGING_MODE_HLC)
@@ -5344,7 +5349,6 @@ int main(void)
 									if(ShmCharger->gun_info[gun_index].chargingMode == CHARGING_MODE_BS)
 									{
 										setRelay(gun_index, OFF);
-										setRequest(gun_index, OFF);
 										ShmCharger->gun_info[gun_index].isChargerStopByCondition = YES;
 									}
 									else if(ShmCharger->gun_info[gun_index].chargingMode == CHARGING_MODE_HLC)
@@ -5373,12 +5377,10 @@ int main(void)
 							}
 							else
 							{
-								if(ShmCharger->gun_info[gun_index].chargingMode == CHARGING_MODE_BS)
-								{
-									setRequest(gun_index, OFF);
-								}
+								if(ShmCharger->gun_info[gun_index].primaryMcuState.relay_state > 0)
+									DEBUG_INFO("Connector-%d can not charging in off line\n", gun_index);
+
 								setRelay(gun_index, OFF);
-								DEBUG_INFO("Connector-%d can not charging in off line\n", gun_index);
 							}
 						}
 
@@ -5433,9 +5435,6 @@ int main(void)
 					   (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].schedule.isTriggerStop == ON) ||
 					   ((ShmCharger->gun_info[gun_index].chargingMode == CHARGING_MODE_HLC) && (ShmCharger->gun_info[gun_index].acCcsInfo.EVChargeProgress == HLC_STOP_MODE)))
 					{
-						if(ShmCharger->gun_info[gun_index].chargingMode == CHARGING_MODE_BS)
-							setRequest(gun_index, OFF);
-
 						setRelay(gun_index, OFF);
 						setLedMotion(gun_index, LED_ACTION_STOP);
 
@@ -5534,7 +5533,6 @@ int main(void)
 					else
 					{
 						setRelay(gun_index, OFF);
-						setRequest(gun_index, OFF);	
 					}
 
 					if((ShmCharger->gun_info[gun_index].systemAlarmCode.SystemAlarmCode == 0))

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


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


+ 2 - 2
EVSE/Projects/AW-ChargeLab/Apps/Module_ConfigTools.c

@@ -52,7 +52,7 @@
 #define NO								0
 #define ON								1
 #define OFF								0
-#define MtdBlockSize 					0x600000
+#define MtdBlockSize 					0x300000
 
 struct SysConfigAndInfo			*ShmSysConfigAndInfo;
 struct StatusCodeData			*ShmStatusCodeData;
@@ -126,7 +126,7 @@ int StoreUsrConfigData(struct SysConfigData *UsrData)
 	{
 		memset(BufTmp,0,MtdBlockSize);
 		memcpy(BufTmp,ptr,sizeof(struct SysConfigData));
-		for(i=0;i<MtdBlockSize-4;i++)
+		for(i=ARRAY_SIZE(UsrData->CsuBootLoadFwRev);i<MtdBlockSize-4;i++)
 			Chk+=*(BufTmp+i);
 		memcpy(BufTmp+MtdBlockSize-4, &Chk, 4);
 

+ 7 - 19
EVSE/Projects/AW-ChargeLab/Apps/Module_FactoryConfig.c

@@ -69,22 +69,10 @@ int StoreLogMsg(const char *fmt, ...)
 	tm=localtime(&CurrentTime);
 	gettimeofday(&tv, NULL); // get microseconds, 10^-6
 
-	if((ShmSysConfigAndInfo->SysConfig.ModelName != NULL) && (ShmSysConfigAndInfo->SysConfig.SerialNumber != NULL) && (strlen((char*)ShmSysConfigAndInfo->SysConfig.ModelName) >= 14))
-	{
-		sprintf(Buf,"echo -n \"[%04d.%02d.%02d %02d:%02d:%02d.%06ld]-%s\" >> /Storage/SystemLog/[%04d.%02d]%s_%s_SystemLog",
-					tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,tv.tv_usec,
-					buffer,
-					tm->tm_year+1900,tm->tm_mon+1,
-					ShmSysConfigAndInfo->SysConfig.ModelName,
-					ShmSysConfigAndInfo->SysConfig.SerialNumber);
-	}
-	else
-	{
-		sprintf(Buf,"echo -n \"[%04d.%02d.%02d %02d:%02d:%02d.%06ld]-%s\" >> /Storage/SystemLog/[%04d.%02d]SystemLog",
-					tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,tv.tv_usec,
-					buffer,
-					tm->tm_year+1900,tm->tm_mon+1);
-	}
+	sprintf(Buf,"echo -n \"[%04d.%02d.%02d %02d:%02d:%02d.%06ld]-%s\" >> /Storage/SystemLog/[%04d.%02d]SystemLog",
+				tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,tv.tv_usec,
+				buffer,
+				tm->tm_year+1900,tm->tm_mon+1);
 
 #ifdef SystemLogMessage
 	system(Buf);
@@ -241,7 +229,7 @@ void helpOutput(void)
 int main(int argc, char *argv[])
 {
 	unsigned char outType=0;
-	unsigned int i,Chk,MtdBlockSize=0x600000;
+	unsigned int i,Chk,MtdBlockSize=0x300000;
 	unsigned char *ptr;
 	int fd,wrd;
 
@@ -344,7 +332,7 @@ int main(int argc, char *argv[])
 
 	// Calculate CRC
 	Chk=0;
-	for(i=0;i<(MtdBlockSize-4);i++)
+	for(i=ARRAY_SIZE(SysConfig.CsuBootLoadFwRev);i<(MtdBlockSize-4);i++)
 	{
 		Chk+=*(ptr+i);
 	}
@@ -390,7 +378,7 @@ int main(int argc, char *argv[])
 	 * Configuration bin file generate
 	 */
 	// Save factory default setting value to file
-	fd = open("/mnt/FactoryDefaultConfig.bin", O_RDWR|O_CREAT);
+	fd = open("/mnt/FactoryDefaultConfig.bin", O_RDWR|O_CREAT|O_TRUNC);
 	if (fd < 0)
 	{
 

+ 10 - 5
EVSE/Projects/AW-ChargeLab/Apps/main.c

@@ -34,7 +34,7 @@
 #define TIMEOUT_SPEC_PROFILE_PREPARE	5000
 #define TIMEOUT_SPEC_PWN_CHANGE			5000
 
-#define MtdBlockSize 					0x600000
+#define MtdBlockSize 					0x300000
 
 #define DB_FILE							"/Storage/ChargeLog/localCgargingRecord.db"
 //==========================
@@ -1485,11 +1485,13 @@ int LoadSysConfigAndInfo(struct SysConfigData *ptr)
 		system("reboot -f");
 	}
 	ChkSum=0;
-	for(wrd=0;wrd<MtdBlockSize-4;wrd++)
+	for(wrd=ARRAY_SIZE(ptr->CsuBootLoadFwRev);wrd<MtdBlockSize-4;wrd++)
 	{
 		ChkSum+=buf[wrd];
 	}
 	memcpy(&ChkSumOrg,buf+(MtdBlockSize-4),sizeof(ChkSumOrg));
+	memcpy(&ptr->ModelName,buf+(ARRAY_SIZE(ptr->CsuBootLoadFwRev)),ARRAY_SIZE(ptr->ModelName));
+	memcpy(&ptr->SerialNumber,buf+(ARRAY_SIZE(ptr->CsuBootLoadFwRev)+ARRAY_SIZE(ptr->ModelName)+ARRAY_SIZE(ptr->AcModelName)),ARRAY_SIZE(ptr->SerialNumber));
 
 	//================================================
 	// Load configuration from mtdblock11
@@ -1498,7 +1500,7 @@ int LoadSysConfigAndInfo(struct SysConfigData *ptr)
 	{
 		DEBUG_ERROR("Primary SysConfigData checksum NG, read backup\n");
 		system("nanddump /dev/mtd11 -f /mnt/EvseConfig.bin");
-		fd = open("/mnt/EvseConfig", O_RDWR);
+		fd = open("/mnt/EvseConfig.bin", O_RDWR);
 		if (fd < 0)
 		{
 			free(buf);
@@ -1533,7 +1535,7 @@ int LoadSysConfigAndInfo(struct SysConfigData *ptr)
 			system("reboot -f");
 		}
 		ChkSum=0;
-		for(wrd=0;wrd<MtdBlockSize-4;wrd++)
+		for(wrd=ARRAY_SIZE(ptr->CsuBootLoadFwRev);wrd<MtdBlockSize-4;wrd++)
 		{
 			ChkSum+=buf[wrd];
 		}
@@ -1579,11 +1581,14 @@ int LoadSysConfigAndInfo(struct SysConfigData *ptr)
 				system("reboot -f");
 			}
 			ChkSum=0;
-			for(wrd=0;wrd<MtdBlockSize-4;wrd++)
+			for(wrd=ARRAY_SIZE(ptr->CsuBootLoadFwRev);wrd<MtdBlockSize-4;wrd++)
 			{
 				ChkSum+=buf[wrd];
 			}
 			memcpy(&ChkSumOrg,buf+(MtdBlockSize-4),sizeof(ChkSumOrg));
+			memcpy(buf+(ARRAY_SIZE(ptr->CsuBootLoadFwRev)), &ptr->ModelName, ARRAY_SIZE(ptr->ModelName));
+			memcpy(buf+(ARRAY_SIZE(ptr->CsuBootLoadFwRev)+ARRAY_SIZE(ptr->ModelName)+ARRAY_SIZE(ptr->AcModelName)), &ptr->SerialNumber, ARRAY_SIZE(ptr->SerialNumber));
+
 			if(ChkSum!=ChkSumOrg)
 			{
 				DEBUG_WARN("factory default  SysConfigData checksum NG, restore factory default\n");

+ 2 - 2
EVSE/Projects/AW-Regular/Apps/Module_ConfigTools.c

@@ -52,7 +52,7 @@
 #define NO								0
 #define ON								1
 #define OFF								0
-#define MtdBlockSize 					0x600000
+#define MtdBlockSize 					0x300000
 
 struct SysConfigAndInfo			*ShmSysConfigAndInfo;
 struct StatusCodeData			*ShmStatusCodeData;
@@ -126,7 +126,7 @@ int StoreUsrConfigData(struct SysConfigData *UsrData)
 	{
 		memset(BufTmp,0,MtdBlockSize);
 		memcpy(BufTmp,ptr,sizeof(struct SysConfigData));
-		for(i=0;i<MtdBlockSize-4;i++)
+		for(i=ARRAY_SIZE(UsrData->CsuBootLoadFwRev);i<MtdBlockSize-4;i++)
 			Chk+=*(BufTmp+i);
 		memcpy(BufTmp+MtdBlockSize-4, &Chk, 4);
 

+ 7 - 19
EVSE/Projects/AW-Regular/Apps/Module_FactoryConfig.c

@@ -69,22 +69,10 @@ int StoreLogMsg(const char *fmt, ...)
 	tm=localtime(&CurrentTime);
 	gettimeofday(&tv, NULL); // get microseconds, 10^-6
 
-	if((ShmSysConfigAndInfo->SysConfig.ModelName != NULL) && (ShmSysConfigAndInfo->SysConfig.SerialNumber != NULL) && (strlen((char*)ShmSysConfigAndInfo->SysConfig.ModelName) >= 14))
-	{
-		sprintf(Buf,"echo -n \"[%04d.%02d.%02d %02d:%02d:%02d.%06ld]-%s\" >> /Storage/SystemLog/[%04d.%02d]%s_%s_SystemLog",
-					tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,tv.tv_usec,
-					buffer,
-					tm->tm_year+1900,tm->tm_mon+1,
-					ShmSysConfigAndInfo->SysConfig.ModelName,
-					ShmSysConfigAndInfo->SysConfig.SerialNumber);
-	}
-	else
-	{
-		sprintf(Buf,"echo -n \"[%04d.%02d.%02d %02d:%02d:%02d.%06ld]-%s\" >> /Storage/SystemLog/[%04d.%02d]SystemLog",
-					tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,tv.tv_usec,
-					buffer,
-					tm->tm_year+1900,tm->tm_mon+1);
-	}
+	sprintf(Buf,"echo -n \"[%04d.%02d.%02d %02d:%02d:%02d.%06ld]-%s\" >> /Storage/SystemLog/[%04d.%02d]SystemLog",
+				tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,tv.tv_usec,
+				buffer,
+				tm->tm_year+1900,tm->tm_mon+1);
 
 #ifdef SystemLogMessage
 	system(Buf);
@@ -241,7 +229,7 @@ void helpOutput(void)
 int main(int argc, char *argv[])
 {
 	unsigned char outType=0;
-	unsigned int i,Chk,MtdBlockSize=0x600000;
+	unsigned int i,Chk,MtdBlockSize=0x300000;
 	unsigned char *ptr;
 	int fd,wrd;
 
@@ -341,7 +329,7 @@ int main(int argc, char *argv[])
 
 	// Calculate CRC
 	Chk=0;
-	for(i=0;i<(MtdBlockSize-4);i++)
+	for(i=ARRAY_SIZE(SysConfig.CsuBootLoadFwRev);i<(MtdBlockSize-4);i++)
 	{
 		Chk+=*(ptr+i);
 	}
@@ -387,7 +375,7 @@ int main(int argc, char *argv[])
 	 * Configuration bin file generate
 	 */
 	// Save factory default setting value to file
-	fd = open("/mnt/FactoryDefaultConfig.bin", O_RDWR|O_CREAT);
+	fd = open("/mnt/FactoryDefaultConfig.bin", O_RDWR|O_CREAT|O_TRUNC);
 	if (fd < 0)
 	{
 

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

@@ -34,7 +34,7 @@
 #define TIMEOUT_SPEC_PROFILE_PREPARE	5000
 #define TIMEOUT_SPEC_PWN_CHANGE			5000
 
-#define MtdBlockSize 					0x600000
+#define MtdBlockSize 					0x300000
 
 #define DB_FILE							"/Storage/ChargeLog/localCgargingRecord.db"
 //==========================
@@ -1485,11 +1485,13 @@ int LoadSysConfigAndInfo(struct SysConfigData *ptr)
 		system("reboot -f");
 	}
 	ChkSum=0;
-	for(wrd=0;wrd<MtdBlockSize-4;wrd++)
+	for(wrd=ARRAY_SIZE(ptr->CsuBootLoadFwRev);wrd<MtdBlockSize-4;wrd++)
 	{
 		ChkSum+=buf[wrd];
 	}
 	memcpy(&ChkSumOrg,buf+(MtdBlockSize-4),sizeof(ChkSumOrg));
+	memcpy(&ptr->ModelName,buf+(ARRAY_SIZE(ptr->CsuBootLoadFwRev)),ARRAY_SIZE(ptr->ModelName));
+	memcpy(&ptr->SerialNumber,buf+(ARRAY_SIZE(ptr->CsuBootLoadFwRev)+ARRAY_SIZE(ptr->ModelName)+ARRAY_SIZE(ptr->AcModelName)),ARRAY_SIZE(ptr->SerialNumber));
 
 	//================================================
 	// Load configuration from mtdblock11
@@ -1498,7 +1500,7 @@ int LoadSysConfigAndInfo(struct SysConfigData *ptr)
 	{
 		DEBUG_ERROR("Primary SysConfigData checksum NG, read backup\n");
 		system("nanddump /dev/mtd11 -f /mnt/EvseConfig.bin");
-		fd = open("/mnt/EvseConfig", O_RDWR);
+		fd = open("/mnt/EvseConfig.bin", O_RDWR);
 		if (fd < 0)
 		{
 			free(buf);
@@ -1533,7 +1535,7 @@ int LoadSysConfigAndInfo(struct SysConfigData *ptr)
 			system("reboot -f");
 		}
 		ChkSum=0;
-		for(wrd=0;wrd<MtdBlockSize-4;wrd++)
+		for(wrd=ARRAY_SIZE(ptr->CsuBootLoadFwRev);wrd<MtdBlockSize-4;wrd++)
 		{
 			ChkSum+=buf[wrd];
 		}
@@ -1579,11 +1581,14 @@ int LoadSysConfigAndInfo(struct SysConfigData *ptr)
 				system("reboot -f");
 			}
 			ChkSum=0;
-			for(wrd=0;wrd<MtdBlockSize-4;wrd++)
+			for(wrd=ARRAY_SIZE(ptr->CsuBootLoadFwRev);wrd<MtdBlockSize-4;wrd++)
 			{
 				ChkSum+=buf[wrd];
 			}
 			memcpy(&ChkSumOrg,buf+(MtdBlockSize-4),sizeof(ChkSumOrg));
+			memcpy(buf+(ARRAY_SIZE(ptr->CsuBootLoadFwRev)), &ptr->ModelName, ARRAY_SIZE(ptr->ModelName));
+			memcpy(buf+(ARRAY_SIZE(ptr->CsuBootLoadFwRev)+ARRAY_SIZE(ptr->ModelName)+ARRAY_SIZE(ptr->AcModelName)), &ptr->SerialNumber, ARRAY_SIZE(ptr->SerialNumber));
+
 			if(ChkSum!=ChkSumOrg)
 			{
 				DEBUG_WARN("factory default  SysConfigData checksum NG, restore factory default\n");

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


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


+ 2 - 1
EVSE/Projects/DD360/Apps/CSU/RFID.c

@@ -20,11 +20,12 @@ static bool isCardScan = false;
 //------------------------------------------------------------------------------
 static bool canStartCharging(void)
 {
+    uint8_t index = 0;
     char buf2[16] = "";
     memset(buf2, 0, ARRAY_SIZE(buf2));
     struct OCPP16Data *ShmOCPP16Data = (struct OCPP16Data *)GetShmOCPP16Data();
 
-    for (uint8_t index = 0; index < strlen((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status); index++) {
+    for (index = 0; index < strlen((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status); index++) {
         sprintf(buf2 + (index - 1) * 2, "%02X", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status[index]);
     }
     sprintf(buf2, "%s", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);

+ 104 - 70
EVSE/Projects/DD360/Apps/CSU/main.c

@@ -261,13 +261,14 @@ void destroySelGun(uint8_t curGun)
     }
 }
 
+/*
 static int waitSelectGunPlugIt(uint8_t curGun)
 {
 #if !defined DD360Audi
     return PASS;
 #endif //!defined DD360Audi
 
-    /*switch (curGun) {
+    switch (curGun) {
     case RIGHT_GUN_NUM:
         if (ShmSelectGunInfo->SelGunInfo.RightGun == SEL_GUN_ATHOR) {
             return PASS;
@@ -283,16 +284,17 @@ static int waitSelectGunPlugIt(uint8_t curGun)
     default:
         return FAIL;
     }
-    */
 
-    if (curGun == RIGHT_GUN_NUM && (ShmSelectGunInfo->SelGunInfo.RightGun == SEL_GUN_ATHOR)) {
-        return PASS;
-    } else if ((curGun == LEFT_GUN_NUM) && (ShmSelectGunInfo->SelGunInfo.LeftGun == SEL_GUN_ATHOR)) {
-        return PASS;
-    }
+
+    //if (curGun == RIGHT_GUN_NUM && (ShmSelectGunInfo->SelGunInfo.RightGun == SEL_GUN_ATHOR)) {
+    //    return PASS;
+    //} else if ((curGun == LEFT_GUN_NUM) && (ShmSelectGunInfo->SelGunInfo.LeftGun == SEL_GUN_ATHOR)) {
+    //    return PASS;
+    //}
 
     return FAIL;
 }
+*/
 
 static int waitRightGunPlugIt(uint8_t curGun)
 {
@@ -2629,10 +2631,10 @@ void DetectPluginStart()
 bool isDetectPlugin()
 {
     if (pSysInfo->WaitForPlugit == YES) {
-        return YES;
+        return true;
     }
 
-    return NO;
+    return false;
 }
 
 //===============================================
@@ -5468,6 +5470,10 @@ void CheckOcppStatus(void)
 
 void OcppStartTransation(uint8_t gunIndex)
 {
+#if defined DD360 || defined DD360Audi || defined DD360ComBox
+    return;
+#endif //defined DD360 || defined DD360Audi || defined DD360ComBox
+
     uint8_t _OcppGunIndex = gunIndex;
     pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
 
@@ -5737,11 +5743,25 @@ void InformOcppErrOccur(uint8_t codeType)
     char _error[25];
 
     switch (codeType) {
-    case 4: strcpy(_error, "InternalError"); break;
-    case 6: strcpy(_error, "NoError"); break;
-    case 7: strcpy(_error, "OtherError"); break;
-    case 13: strcpy(_error, "UnderVoltage"); break;
-    case 14: strcpy(_error, "OverVoltage"); break;
+    case 4:
+        strcpy(_error, "InternalError");
+        break;
+
+    case 6:
+        strcpy(_error, "NoError");
+        break;
+
+    case 7:
+        strcpy(_error, "OtherError");
+        break;
+
+    case 13:
+        strcpy(_error, "UnderVoltage");
+        break;
+
+    case 14:
+        strcpy(_error, "OverVoltage");
+        break;
     }
 
     for (uint8_t gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++) {
@@ -6745,6 +6765,42 @@ static uint8_t distributionPsuModule(uint8_t *isRessign, uint8_t gunIndex)
     return NO;
 }
 
+static void checkEvBoardReqStop(uint8_t sysStatus, uint8_t gunIndex)
+{
+    uint8_t evBoardStopState = 0;
+
+    if ((evBoardStopState = isEvBoardStopChargeFlag(gunIndex)) > 0) {
+
+        // 板端要求停止 (錯誤)
+        if (sysStatus != S_CCS_PRECHARGE_ST0 &&
+                sysStatus != S_CCS_PRECHARGE_ST1) {
+            if (strcmp((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "") == EQUAL) {
+                strcpy((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "EVDisconnected");
+            }
+        }
+
+        if (evBoardStopState == EV_BOARD_STOP_CHARGING) {
+            ChargingAlarmProcess(gunIndex);
+        } else if (evBoardStopState == POWER_CABINET_STOP_CHARGING) {
+            ChargingTerminalProcess(gunIndex);
+        }
+    } else if (isEvBoardNormalStopChargeFlag(gunIndex) == YES) {
+        // 板端要求停止 (正常)
+        if (sysStatus != S_CCS_PRECHARGE_ST0 &&
+                sysStatus != S_CCS_PRECHARGE_ST1) {
+            if (strcmp((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "") == EQUAL) {
+                strcpy((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "EVDisconnected");
+            }
+        }
+
+        ChargingTerminalProcess(gunIndex);
+    } else if (OcppRemoteStop(gunIndex) == YES ||
+               WifiScheduleStop(gunIndex)) {
+        // 後臺要求停止
+        ChargingTerminalProcess(gunIndex);
+    }
+}
+
 int main(void)
 {
     bool isModelNameMatch = true;
@@ -7132,11 +7188,14 @@ int main(void)
                             ChangeGunSelectByIndex(gunIndex);
                             AddPlugInTimes(gunIndex);
                             strcpy((char *)pDcChargingInfo->StartUserId, (char *)pSysConfig->UserId);
-                            log_info("index = %d, CardNumber = %s \n", gunIndex, pDcChargingInfo->StartUserId);
+                            log_info("index = %d, CardNumber = %s \n",
+                                     gunIndex,
+                                     pDcChargingInfo->StartUserId);
                             strcpy((char *)pSysConfig->UserId, "");
                             // 當前操作的槍號,進入 Preparing
                             setChargerMode(gunIndex, MODE_REASSIGN_CHECK);
                             ClearDetectPluginFlag();
+
                             continue;
                         }
                     }
@@ -7186,46 +7245,7 @@ int main(void)
                 if (distributionPsuModule(&isRessign, gunIndex) == YES) {
                     continue;
                 }
-#if 0
-#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
-                if (pSysConfig->TotalConnectorCount > 1 && pSysInfo->IsAlternatvieConf == NO) {
-                    if (pSysInfo->MainChargingMode == _MAIN_CHARGING_MODE_MAX) {
-                        for (byte index = 0; index < pSysConfig->TotalConnectorCount; index++) {
-                            pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(index);
 
-                            // 有其他槍已經分配好 psu 模塊
-                            if (pSysInfo->CurGunSelected != index &&
-                                    pDcChargingInfo->SystemStatus >= S_PREPARNING &&
-                                    pDcChargingInfo->SystemStatus != S_MAINTAIN) {
-                                log_info("=============Smart Charging============= Step 1 \n");
-                                pSysInfo->ReAssignedFlag = _REASSIGNED_PREPARE_M_TO_A;
-                                isRessign = YES;
-                                break;
-                            }
-                        }
-                    } else if (pSysInfo->MainChargingMode == _MAIN_CHARGING_MODE_AVER &&
-                               pSysInfo->ReAssignedFlag != _REASSIGNED_NONE) {
-                        // 如果在切換最大充的過程中,需等待最大充切換完成後,在走均充流程
-                        if (pSysInfo->BridgeRelayStatus == YES) {
-                            if (pSysInfo->ReAssignedFlag != _REASSIGNED_COMP &&
-                                    pSysInfo->ReAssignedFlag != _REASSIGNED_WAITING) {
-                                log_info("=============Smart Charging============= Step 14 \n");
-                                pSysInfo->ReAssignedFlag = _REASSIGNED_WAITING;
-                            } else if (pSysInfo->ReAssignedFlag == _REASSIGNED_COMP) {
-                                pSysInfo->MainChargingMode = _MAIN_CHARGING_MODE_MAX;
-                                pSysInfo->ReAssignedFlag = _REASSIGNED_NONE;
-                                continue;
-                            }
-                        }
-
-                        if (pSysInfo->CurGunSelected == gunIndex) {
-                            pSysInfo->ConnectorPage = _LCM_PRE_CHARGE;
-                        }
-                        continue;
-                    }
-                }
-#endif // !defined DD360 && !defined DD360Audi
-#endif //0
                 if (isRessign == YES) {
                     setChargerMode(gunIndex, MODE_REASSIGN);
                 } else {
@@ -7278,11 +7298,7 @@ int main(void)
                 if (ShmPsuData->SystemPresentPsuQuantity > 0 &&
                         ShmPsuData->SystemAvailablePower > 10 &&
                         GetTimeoutValue(pDcChargingInfo->TimeoutTimer) >= 5000000) {
-                    //if ((pDcChargingInfo->MaximumChargingVoltage > 0) && //DS60-120 remove
-                    //        (pDcChargingInfo->AvailableChargingCurrent > 0) &&
-                    //        (pDcChargingInfo->AvailableChargingPower > 0)) {
                     setChargerMode(gunIndex, MODE_PREPARE_FOR_EV);
-                    //}
                 }
 
                 //DS60-120 add
@@ -7304,6 +7320,8 @@ int main(void)
                     }
                 }
 
+                checkEvBoardReqStop(pDcChargingInfo->SystemStatus, gunIndex);
+#if 0
                 if ((evBoardStopState = isEvBoardStopChargeFlag(gunIndex)) > 0) {
                     // 板端要求停止 (錯誤)
                     if (strcmp((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "") == EQUAL) {
@@ -7326,6 +7344,7 @@ int main(void)
                     // 後臺要求停止
                     ChargingTerminalProcess(gunIndex);
                 }
+#endif //0
 
                 if (pSysInfo->CurGunSelected == gunIndex) {
                     pSysInfo->ConnectorPage = _LCM_PRE_CHARGE;
@@ -7357,6 +7376,8 @@ int main(void)
                     }
                 }
 
+                checkEvBoardReqStop(pDcChargingInfo->SystemStatus, gunIndex);
+#if 0
                 if ((evBoardStopState = isEvBoardStopChargeFlag(gunIndex)) > 0) {
                     // 板端要求停止 (錯誤)
                     if (strcmp((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "") == EQUAL) {
@@ -7379,6 +7400,7 @@ int main(void)
                     // 後臺要求停止
                     ChargingTerminalProcess(gunIndex);
                 }
+#endif //0
 
                 // LCM => Pre-charging
                 if (pSysInfo->CurGunSelected == gunIndex) {
@@ -7395,7 +7417,8 @@ int main(void)
 
                 if (pDcChargingInfo->Type == _Type_Chademo) {
                     // 檢查樁端的 GFD 結果
-                    if (isPrechargeStatus_chademo(gunIndex) > 5 && isPrechargeStatus_chademo(gunIndex) < 8) {
+                    if (isPrechargeStatus_chademo(gunIndex) > 5 &&
+                            isPrechargeStatus_chademo(gunIndex) < 8) {
                         // 當前操作的槍號,進入 Charging
                         setChargerMode(gunIndex, MODE_CHARGING);
                     }
@@ -7437,6 +7460,8 @@ int main(void)
                     }
                 }
 
+                checkEvBoardReqStop(pDcChargingInfo->SystemStatus, gunIndex);
+#if 0
                 if ((evBoardStopState = isEvBoardStopChargeFlag(gunIndex)) > 0) {
                     // 板端要求停止 (錯誤)
                     if (strcmp((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "") == EQUAL) {
@@ -7459,6 +7484,7 @@ int main(void)
                     // 後臺要求停止
                     ChargingTerminalProcess(gunIndex);
                 }
+#endif //0
 
                 // LCM => Pre-charging
                 if (pSysInfo->CurGunSelected == gunIndex) {
@@ -7473,9 +7499,8 @@ int main(void)
                     ftime(&startChargingTime[gunIndex]);
                     strcpy((char *)ShmOCPP16Data->StartTransaction[gunIndex].ResponseIdTagInfo.Status, ""); //DS60-120 add
                     ChangeStartOrStopDateTime(YES, gunIndex);
-#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
+
                     OcppStartTransation(gunIndex);
-#endif //!defined DD360 && !defined DD360Audi
                 }
 
                 if (ShmOCPP16Data->CpMsg.bits[gunIndex].StartTransactionConf) {
@@ -7546,6 +7571,7 @@ int main(void)
                     if (strcmp((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "") == EQUAL) {
                         strcpy((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "EVDisconnected");
                     }
+
                     //printf("%d evBoardStopState = %d\r\n", gunIndex, evBoardStopState);
                     if (evBoardStopState == EV_BOARD_STOP_CHARGING) {
                         ChargingAlarmProcess(gunIndex);
@@ -7557,6 +7583,7 @@ int main(void)
                     if (strcmp((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "") == EQUAL) {
                         strcpy((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "EVDisconnected");
                     }
+
                     ChargingTerminalProcess(gunIndex);
                 } else if (OcppRemoteStop(gunIndex) == YES ||
                            WifiScheduleStop(gunIndex) ||
@@ -7756,6 +7783,8 @@ int main(void)
                     RecordAlarmCode(gunIndex, "012235");
                 }
 
+                checkEvBoardReqStop(pDcChargingInfo->SystemStatus, gunIndex);
+#if 0
                 if ((evBoardStopState = isEvBoardStopChargeFlag(gunIndex)) > 0) {
                     // 板端要求停止 (錯誤)
                     if (evBoardStopState == EV_BOARD_STOP_CHARGING) {
@@ -7771,10 +7800,12 @@ int main(void)
                     // 後臺要求停止
                     ChargingTerminalProcess(gunIndex);
                 }
+#endif //0
 
                 // 等待 EV 小板 (CCS) 通知可以開始 Precharge
                 // 切換 D+ Relay to Precharge Relay
-                if (isPrechargeStatus_ccs(gunIndex) == 39 || isPrechargeStatus_ccs(gunIndex) == 40) {
+                if (isPrechargeStatus_ccs(gunIndex) == 39 ||
+                        isPrechargeStatus_ccs(gunIndex) == 40) {
                     if (pDcChargingInfo->RelayKPK2Status == YES &&
                             pDcChargingInfo->PrechargeStatus != PRECHARGE_READY)
                         //if (pDcChargingInfo->PrechargeStatus != PRECHARGE_PRERELAY_PASS)
@@ -7812,6 +7843,8 @@ int main(void)
                     RecordAlarmCode(gunIndex, "012235");
                 }
 
+                checkEvBoardReqStop(pDcChargingInfo->SystemStatus, gunIndex);
+#if 0
                 if ((evBoardStopState = isEvBoardStopChargeFlag(gunIndex)) > 0) {
                     // 板端要求停止 (錯誤)
                     if (evBoardStopState == EV_BOARD_STOP_CHARGING) {
@@ -7828,7 +7861,7 @@ int main(void)
                     // 後臺要求停止
                     ChargingTerminalProcess(gunIndex);
                 }
-
+#endif //0
                 // 等待小板通知進入充電
                 // 切換 D+ Relay to Precharge Relay
                 if (pDcChargingInfo->RelayK1K2Status == YES) {
@@ -7840,8 +7873,10 @@ int main(void)
                     pSysInfo->ConnectorPage = _LCM_PRE_CHARGE;
                 }
                 break;
-            }
-        }
+            }//switch
+
+            checkEvBoardAlarmState(pDcChargingInfo->Type);
+        }//for
 
 #if defined DD360Audi
         if (pSysInfo->SystemPage != _LCM_SELECT_GUN) {
@@ -7875,11 +7910,10 @@ int main(void)
             }
         }
 
-        for (uint8_t gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++) {
-            pDcChargingInfo =  (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
-
-            checkEvBoardAlarmState(pDcChargingInfo->Type);
-        }
+        //for (uint8_t gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++) {
+        //    pDcChargingInfo =  (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
+        //    checkEvBoardAlarmState(pDcChargingInfo->Type);
+        //}
 
         //write(wtdFd, "a", 1);
         //WriteWatchDogState("a");

+ 1 - 0
EVSE/Projects/DD360/Apps/DataBase/DataBase.c

@@ -2,6 +2,7 @@
 #include <stdlib.h>     /*標準函數庫定義*/
 #include <string.h>
 #include <stdint.h>
+#include <time.h>
 
 #include "../Config.h"
 #include "../Log/log.h"

+ 4 - 0
EVSE/Projects/DD360/Apps/Define/define.h

@@ -570,6 +570,10 @@ struct ChargingInfoData
 	int 				EvBatteryStartSoc;				// 0~100%
 	unsigned char 		NormalStopChargeFlag;			// for EV board
 	ChargingStop        ChargingStopFlag;
+	char 				ReservedStartFlag;
+	float 				ConnectorMaxVoltage;			// 0~6553.5 volt
+	float 				ConnectorMaxCurrent;			// 0~6553.5 volt
+	unsigned char 		ModelType;
 };
 
 typedef union

+ 69 - 7
EVSE/Projects/DD360/Apps/FactoryConfig.c

@@ -31,12 +31,21 @@
 #include    "./Define/define.h"
 #include    "Config.h"
 
+//------------------------------------------------------------------------------
 #define Debug
 #define OUTPUT_FLASH        0x01
 #define OUTPUT_FILE         0x02
 
+#define log_info(format, args...) StoreLogMsg("[%s:%d][%s][Info] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
+#define log_warn(format, args...) StoreLogMsg("[%s:%d][%s][Warn] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
+#define log_error(format, args...) StoreLogMsg("[%s:%d][%s][Error] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
+
+//------------------------------------------------------------------------------
 struct SysConfigData            SysConfig;
+struct SysConfigAndInfo         *ShmSysConfigAndInfo;
+struct StatusCodeData           *ShmStatusCodeData;
 
+//------------------------------------------------------------------------------
 int StoreLogMsg(const char *fmt, ...)
 {
     char Buf[4096 + 256];
@@ -82,6 +91,39 @@ int runShellCmd(const char *cmd)
     return result;
 }
 
+//==========================================
+// Init all share memory
+//==========================================
+int InitShareMemory()
+{
+    int result = PASS;
+    int MeterSMId;
+
+    //creat ShmSysConfigAndInfo
+    if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo),  0777)) < 0) {
+        log_error("shmget ShmSysConfigAndInfo NG\n");
+
+        result = FAIL;
+    } else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
+        log_error("shmat ShmSysConfigAndInfo NG\n");
+
+        result = FAIL;
+    }
+
+    //creat ShmStatusCodeData
+    if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData),  0777)) < 0) {
+        log_error("shmget ShmStatusCodeData NG\n");
+
+        result = FAIL;
+    } else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
+        log_error("shmat ShmStatusCodeData NG\n");
+
+        result = FAIL;
+    }
+
+    return result;
+}
+
 void helpOutput(void)
 {
     printf("Usage: Module_FactoryConfig [OPTION]...\r\n\r\n");
@@ -113,6 +155,26 @@ int main(int argc, char *argv[])
     memset(ptr, 0, MtdBlockSize);
     memset(&SysConfig, 0, sizeof(struct SysConfigData));
 
+
+    // Initial Share Memory
+    if (InitShareMemory() == FAIL) {
+        log_error("InitShareMemory NG\n");
+
+        strcpy((char *)SysConfig.ModelName, "");
+        strcpy((char *)SysConfig.SerialNumber, "");
+        sleep(5);
+    } else {
+        memcpy((char *)SysConfig.ModelName,
+               ShmSysConfigAndInfo->SysConfig.ModelName,
+               ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.ModelName));
+
+        memcpy((char *)SysConfig.SerialNumber,
+               ShmSysConfigAndInfo->SysConfig.SerialNumber,
+               ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.SerialNumber));
+
+        log_info("InitShareMemory OK.\n");
+    }
+
     /*
      * TODO: Set factory default configuration
     */
@@ -248,13 +310,13 @@ int main(int argc, char *argv[])
         helpOutput();
     }
 
-    if (argc == 4) {
-        strcpy((char *)SysConfig.ModelName, argv[2]);
-        strcpy((char *)SysConfig.SerialNumber, argv[3]);
-    } else {
-        strcpy((char *)SysConfig.ModelName, "DDYC182V0UE2AD");
-        strcpy((char *)SysConfig.SerialNumber, "SERIALFORRD");
-    }
+    //if (argc == 4) {
+    //    strcpy((char *)SysConfig.ModelName, argv[2]);
+    //    strcpy((char *)SysConfig.SerialNumber, argv[3]);
+    //} else {
+    //    strcpy((char *)SysConfig.ModelName, "DDYC182V0UE2AD");
+    //    strcpy((char *)SysConfig.SerialNumber, "SERIALFORRD");
+    //}
 
     /*
      * Configuration bin file generate

+ 61 - 0
EVSE/Projects/DD360/Apps/Log/log.c

@@ -8,6 +8,7 @@
 #include <stdarg.h>
 
 #include <sys/timeb.h>
+#include <sys/time.h>
 
 #include "../ShareMemory/shmMem.h"
 #include "../Define/define.h"
@@ -61,3 +62,63 @@ int StoreLogMsg(const char *fmt, ...)
 
     return rc;
 }
+
+int StoreEventLogMsg(const char *fmt, ...)
+{
+    char Buf[4096 + 256];
+    char buffer[4096];
+    time_t CurrentTime;
+    struct tm *tm;
+    struct timeval tv;
+    va_list args;
+    struct SysConfigData *pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
+
+    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);
+    gettimeofday(&tv, NULL); // get microseconds, 10^-6
+
+    if ((pSysConfig->ModelName != NULL) &&
+            (pSysConfig->SerialNumber != NULL) &&
+            (strlen((char *)pSysConfig->ModelName) >= 14)) {
+        sprintf(Buf, "echo -n \"[%04d.%02d.%02d %02d:%02d:%02d.%06ld]%s\" >> /Storage/EventLog/[%04d.%02d]%s_%s_EventLog",
+                tm->tm_year + 1900,
+                tm->tm_mon + 1,
+                tm->tm_mday,
+                tm->tm_hour,
+                tm->tm_min,
+                tm->tm_sec,
+                tv.tv_usec,
+                buffer,
+                tm->tm_year + 1900,
+                tm->tm_mon + 1,
+                pSysConfig->ModelName,
+                pSysConfig->SerialNumber);
+    } else {
+        sprintf(Buf, "echo -n \"[%04d.%02d.%02d %02d:%02d:%02d.%06ld]%s\" >> /Storage/EventLog/[%04d.%02d]EventLog",
+                tm->tm_year + 1900,
+                tm->tm_mon + 1,
+                tm->tm_mday,
+                tm->tm_hour,
+                tm->tm_min,
+                tm->tm_sec,
+                tv.tv_usec,
+                buffer,
+                tm->tm_year + 1900,
+                tm->tm_mon + 1);
+    }
+
+#ifdef SystemLogMessage
+    system(Buf);
+#endif //SystemLogMessage
+
+#ifdef ConsloePrintLog
+    printf("[%04d.%02d.%02d %02d:%02d:%02d.%06ld]%s", tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec, tv.tv_usec, buffer);
+#endif //ConsloePrintLog
+
+    return rc;
+}

+ 2 - 0
EVSE/Projects/DD360/Apps/Log/log.h

@@ -6,7 +6,9 @@
 #define log_warn(format, args...) StoreLogMsg("[%s:%d][%s][Warn] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
 #define log_error(format, args...) StoreLogMsg("[%s:%d][%s][Error] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
 
+#define event_info(format, args...) StoreEventLogMsg("[%s:%d][%s][Info] "format, __FILE__, __LINE__, __FUNCTION__, ##args) //DS60-120 add
 //------------------------------------------------------------------------------
 int StoreLogMsg(const char *fmt, ...);
+int StoreEventLogMsg(const char *fmt, ...);
 
 #endif /* _LOG_H_ */

+ 31 - 13
EVSE/Projects/DD360/Apps/Makefile

@@ -75,6 +75,10 @@ MAIN_SRC_FILES = $(patsubst %.o, %.c, $(MAIN_OBJ_FILES))
 %.o: %.c
 	$(CC) $(CFLAGS) -c $<
 
+#DoComm
+DOCOMM_OBJ_FILES = $(COMMON_OBJ_FILES) $(DoCommLib)/DoComm.o
+DOCOMM_SRC_FILES = $(patsubst %.o, %.c, $(DOCOMM_OBJ_FILES))
+
 #internal comm lib
 INTERNALCOMM_OBJ_FILES = $(COMMON_OBJ_FILES) $(InternalCommLib)/internalComm.o \
 							$(InternalCommLib)/Module_InternalComm.o $(InternalCommLib)/FanBoard.o \
@@ -99,6 +103,17 @@ EVENTLOG_SRC_FILES = $(patsubst %.o, %.c, $(EVENTLOG_OBJ_FILES))
 %.o: %.c
 	$(CC) $(CFLAGS) -c $<
 
+#LCM Control
+LCM_OBJ_FILES = $(COMMON_OBJ_FILES) $(LcmLib)/Module_LcmControl.o
+LCM_SRC_FILES = $(patsubst %.o, %.c, $(LCM_OBJ_FILES))
+
+#Primary
+PRIMARY_OBJ_FILES = $(COMMON_OBJ_FILES) $(PrimaryLib)/PrimaryComm.o \
+						$(PrimaryLib)/Module_PrimaryComm.o
+PRIMARY_SRC_FILES = $(patsubst %.o, %.c, $(PRIMARY_OBJ_FILES))
+%.o: %.c
+	$(CC) $(CFLAGS) -c $<
+
 all: CopyFile apps
 
 apps: MainTask DoCommTask EvCommTask \
@@ -115,9 +130,10 @@ MainTask:
 	#$(CC) $(TFLAGS) -o main main.o timeout.o common.o ${Lib_Module_RFID} ${Lib_Module_Upgrade} ${Lib_SQLite3} $(Lib_Module_RatedCurrent)
 
 DoCommTask:
-	$(CC) $(DEFINE) $(CFLAGS) -c -o define.o $(DefineLib)/define.c
-	$(CC) $(DEFINE) $(CFLAGS) -c -o DoComm.o $(DoCommLib)/DoComm.c
-	$(CC) -o Module_DoComm DoComm.o define.o
+	$(CC) $(DEFINE) $(DOCOMM_SRC_FILES) $(CFLAGS) $(TFLAGS) $(INC_FLAGS) -o Module_DoComm
+	#$(CC) $(DEFINE) $(CFLAGS) -c -o define.o $(DefineLib)/define.c
+	#$(CC) $(DEFINE) $(CFLAGS) -c -o DoComm.o $(DoCommLib)/DoComm.c
+	#$(CC) -o Module_DoComm DoComm.o define.o
 
 EvCommTask:
 	$(CC) $(DEFINE) $(EVCOMM_SRC_FILES) $(CFLAGS) $(TFLAGS) $(INC_FLAGS) $(Lib_Module_RatedCurrent) -o Module_EvComm
@@ -126,10 +142,10 @@ EvCommTask:
 	#$(CC) -o Module_EvComm Ev_Comm.o Module_EvComm.o $(Lib_Module_RatedCurrent)
 
 EventLoggingTask:
-	#$(CC) $(DEFINE) $(EVENTLOG_SRC_FILES) $(CFLAGS) $(TFLAGS) $(INC_FLAGS) $(SQLite3_H) $(Lib_SQLite3) -o Module_EventLogging
-	$(CC) $(DEFINE) $(CFLAGS) -c -o define.o $(DefineLib)/define.c
-	$(CC) $(DEFINE) $(SQLite3_H) $(CFLAGS) -c -o Module_EventLogging.o $(EventLogLib)/Module_EventLogging.c
-	$(CC) -o Module_EventLogging Module_EventLogging.o ${Lib_SQLite3} define.o
+	$(CC) $(DEFINE) $(EVENTLOG_SRC_FILES) $(CFLAGS) $(TFLAGS) $(INC_FLAGS) $(SQLite3_H) $(Lib_SQLite3) -o Module_EventLogging
+	#$(CC) $(DEFINE) $(CFLAGS) -c -o define.o $(DefineLib)/define.c
+	#$(CC) $(DEFINE) $(SQLite3_H) $(CFLAGS) -c -o Module_EventLogging.o $(EventLogLib)/Module_EventLogging.c
+	#$(CC) -o Module_EventLogging Module_EventLogging.o ${Lib_SQLite3} define.o
 
 InternalCommTask:
 	$(CC) $(DEFINE) $(INTERNALCOMM_SRC_FILES) $(CFLAGS) $(TFLAGS) $(INC_FLAGS) -o Module_InternalComm
@@ -138,14 +154,16 @@ InternalCommTask:
 	#$(CC) $(TFLAGS) -o Module_InternalComm Module_InternalComm.o internalComm.o $(Lib_ModuleRelay)
 
 LcmControlTask:
-	$(CC) $(DEFINE) $(CFLAGS) -c -o define.o $(DefineLib)/define.c
-	$(CC) $(DEFINE) $(CFLAGS) -c -o Module_LcmControl.o $(LcmLib)/Module_LcmControl.c
-	$(CC) -o Module_LcmControl Module_LcmControl.o define.o
+	$(CC) $(DEFINE) $(LCM_SRC_FILES) $(CFLAGS) $(TFLAGS) $(INC_FLAGS) -o Module_LcmControl
+	#$(CC) $(DEFINE) $(CFLAGS) -c -o define.o $(DefineLib)/define.c
+	#$(CC) $(DEFINE) $(CFLAGS) -c -o Module_LcmControl.o $(LcmLib)/Module_LcmControl.c
+	#$(CC) -o Module_LcmControl Module_LcmControl.o define.o
 
 PrimaryCommTask:
-	$(CC) $(DEFINE) $(CFLAGS) -c -o PrimaryComm.o $(PrimaryLib)/PrimaryComm.c
-	$(CC) $(DEFINE) $(CFLAGS) -c -o Module_PrimaryComm.o $(PrimaryLib)/Module_PrimaryComm.c
-	$(CC) -o Module_PrimaryComm Module_PrimaryComm.o PrimaryComm.o
+	$(CC) $(DEFINE) $(PRIMARY_SRC_FILES) $(CFLAGS) $(TFLAGS) $(INC_FLAGS) -o Module_PrimaryComm
+	#$(CC) $(DEFINE) $(CFLAGS) -c -o PrimaryComm.o $(PrimaryLib)/PrimaryComm.c
+	#$(CC) $(DEFINE) $(CFLAGS) -c -o Module_PrimaryComm.o $(PrimaryLib)/Module_PrimaryComm.c
+	#$(CC) -o Module_PrimaryComm Module_PrimaryComm.o PrimaryComm.o
 
 PsuCommTask:
 	$(CC) $(DEFINE) $(InfypwrPsuComm_H) $(CFLAGS) -c -o Module_PsuComm.o Module_PsuComm.c

+ 212 - 172
EVSE/Projects/DD360/Apps/ModuleDoComm/DoComm.c

@@ -21,6 +21,8 @@
 #include <unistd.h>
 #include <signal.h>
 
+#include "../Log/log.h"
+#include "../ShareMemory/shmMem.h"
 #include "../Define/define.h"
 #include "../Config.h"
 #include "../SelectGun/SelectGun.h"
@@ -28,23 +30,28 @@
 #include "DoComm.h"
 
 //------------------------------------------------------------------------------
-#define log_info(format, args...) StoreLogMsg("[%s:%d][%s][Info] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
-#define log_warn(format, args...) StoreLogMsg("[%s:%d][%s][Warn] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
-#define log_error(format, args...) StoreLogMsg("[%s:%d][%s][Error] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
+//#define log_info(format, args...) StoreLogMsg("[%s:%d][%s][Info] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
+//#define log_warn(format, args...) StoreLogMsg("[%s:%d][%s][Warn] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
+//#define log_error(format, args...) StoreLogMsg("[%s:%d][%s][Error] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
 
 //------------------------------------------------------------------------------
 //static int TcpSock = 0;
 //static uint8_t PacketSe;
 static DoCommGblData gDoCommGblData = {0};
 
-static struct SysConfigAndInfo *ShmSysConfigAndInfo = NULL;
-static struct StatusCodeData *ShmStatusCodeData     = NULL;
-static struct PsuData *ShmPsuData                   = NULL;
-static struct OCPP16Data *ShmOCPP16Data             = NULL;
-static struct PrimaryMcuData *ShmPrimaryMcuData     = NULL;
-static SelectGunInfo *ShmSelectGunInfo              = NULL;
-
-static struct ChargingInfoData  *ChargingData[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
+//static struct SysConfigAndInfo *ShmSysConfigAndInfo = NULL;
+//static struct StatusCodeData *ShmStatusCodeData     = NULL;
+static struct SysConfigData *pSysConfig         = NULL;
+static struct SysInfoData *pSysInfo             = NULL;
+static struct WARNING_CODE_INFO *pSysWarning    = NULL;
+static struct AlarmCodeData *pAlarmCode         = NULL;
+static struct PsuData *ShmPsuData               = NULL;
+static struct OCPP16Data *ShmOCPP16Data         = NULL;
+static struct PrimaryMcuData *ShmPrimaryMcuData = NULL;
+static SelectGunInfo *ShmSelectGunInfo          = NULL;
+
+//static struct ChargingInfoData  *ChargingData[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY]
+static struct ChargingInfoData *pDcChargingInfo = NULL;
 static struct timeb             gRegTimeUp[2][MAX_REGISTER_NUM] = {0};
 static struct WARNING_CODE_INFO gPreSysWarningInfo = {0};
 
@@ -57,7 +64,7 @@ static int writeCsuModuleVersion(int fd);
 //------------------------------------------------------------------------------
 //--- Common function ---
 //------------------------------------------------------------------------------
-static int StoreLogMsg(const char *fmt, ...)
+/*static int StoreLogMsg(const char *fmt, ...)
 {
     char Buf[4096 + 256];
     char buffer[4096];
@@ -74,7 +81,7 @@ static int StoreLogMsg(const char *fmt, ...)
     SeqEndTime.time = time(NULL);
     tm = localtime(&SeqEndTime.time);
 
-    if (ShmSysConfigAndInfo->SysConfig.SwitchDebugFlag == 1) {
+    if (pSysConfig->SwitchDebugFlag == 1) {
         sprintf(Buf, "%02d:%02d:%02d:%03d - %s",
                 tm->tm_hour, tm->tm_min, tm->tm_sec, SeqEndTime.millitm, buffer);
         printf("%s \n", Buf);
@@ -88,6 +95,7 @@ static int StoreLogMsg(const char *fmt, ...)
 
     return rc;
 }
+*/
 
 static int DiffTimeb(struct timeb ST, struct timeb ET)
 {
@@ -187,7 +195,7 @@ static void InitSocketSigPipe(void)
 //------------------------------------------------------------------------------
 static void setTcpStatus(uint8_t setValue)
 {
-    ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DisconnectedFromDo = setValue;
+    pAlarmCode->AlarmEvents.bits.DisconnectedFromDo = setValue;
 }
 
 //------------------------------------------------------------------------------
@@ -308,17 +316,17 @@ static void clearPricesInfo(uint8_t id)
 static void ClearAuthorizedFlag(void)
 {
     ShmOCPP16Data->SpMsg.bits.AuthorizeConf = NO;
-    ShmSysConfigAndInfo->SysInfo.AuthorizeFlag = NO;
+    pSysInfo->AuthorizeFlag = NO;
 }
 
 static void ClearDetectPluginFlag(void)
 {
-    ShmSysConfigAndInfo->SysInfo.WaitForPlugit = NO;
+    pSysInfo->WaitForPlugit = NO;
 }
 
 static bool isDetectPlugin(void)
 {
-    if (ShmSysConfigAndInfo->SysInfo.WaitForPlugit == YES) {
+    if (pSysInfo->WaitForPlugit == YES) {
         return YES;
     }
 
@@ -328,18 +336,20 @@ static bool isDetectPlugin(void)
 static void destroySelectGun(uint8_t curGun)
 {
     uint8_t i = 0;
-    uint8_t totalGun = ShmSysConfigAndInfo->SysConfig.TotalConnectorCount;
+    uint8_t totalGun = pSysConfig->TotalConnectorCount;
 
     if (curGun == DESTROY_ALL_SEL) {
         ShmSelectGunInfo->SelGunInfo.RightGun = SEL_GUN_RELEASE;
         ShmSelectGunInfo->SelGunInfo.LeftGun = SEL_GUN_RELEASE;
 
         for (i = 0; i < totalGun; i++) {
-            ChargingData[i]->TimeoutFlag = Timeout_None;
+            pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(i);
+
+            pDcChargingInfo->TimeoutFlag = Timeout_None;
             clearPricesInfo(i);
         }
-        ShmSysConfigAndInfo->SysInfo.CurGunSelected = 0;
-        strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
+        pSysInfo->CurGunSelected = 0;
+        strcpy((char *)pSysConfig->UserId, "");
     }
 
     //for charging timeout or complete
@@ -465,11 +475,11 @@ static int qrCodeUrlInfoHandle(uint8_t *data)
 
     //copy QR code string
     if (strncmp((char *)localTime, (char *)&data[0], timeLen - 2) != 0) {
-        memset(ShmSysConfigAndInfo->SysConfig.SystemId, '\0', sizeof(ShmSysConfigAndInfo->SysConfig.SystemId));
+        memset(pSysConfig->SystemId, '\0', sizeof(pSysConfig->SystemId));
         //printf("data =  %s\r\n", data);
         //len =
-        string2ByteArray((char *)data, (uint8_t *)ShmSysConfigAndInfo->SysConfig.SystemId);
-        //printf("SystemId =  %s\r\n", ShmSysConfigAndInfo->SysConfig.SystemId);
+        string2ByteArray((char *)data, (uint8_t *)pSysConfig->SystemId);
+        //printf("SystemId =  %s\r\n", pSysConfig->SystemId);
     }
 
     //if ((char *)&data[len] == '\0') {
@@ -500,7 +510,7 @@ static int updateFirmwareHandle(uint8_t *imgName)
     log_info("Program ready to check file %s\n", cmdBuf);
     if ( access(cmdBuf, F_OK) != -1) {
         log_info("File '%s' exist.\n", cmdBuf);
-        ShmSysConfigAndInfo->SysInfo.FirmwareUpdate = YES;
+        pSysInfo->FirmwareUpdate = YES;
     } else {
         log_info("File '%s' doesn't exist.\n", cmdBuf);
         ret = FAIL;
@@ -527,7 +537,7 @@ static int updateFirmwareHandle(uint8_t *imgName)
         if (WIFEXITED(status)) {
             if (0 == WEXITSTATUS(status)) {
                 printf("run shell script successfully.\n");
-                ShmSysConfigAndInfo->SysInfo.FirmwareUpdate = YES;
+                pSysInfo->FirmwareUpdate = YES;
             } else {
                 printf("run shell script fail, script exit code: %d\n", WEXITSTATUS(status));
             }
@@ -597,9 +607,9 @@ static int miscCommandHandle(uint8_t dataLen, uint8_t plugNum, uint8_t *data)
             prices = transPricesUnit((int)value);
             log_info("default prices = %.2f\r\n", prices);
 
-            //ShmSysConfigAndInfo->SysConfig.BillingData.isBilling = YES;
+            //pSysConfig->BillingData.isBilling = YES;
             for (j = 0; j < 24; j++) {
-                ShmSysConfigAndInfo->SysConfig.BillingData.Fee[j] = prices;
+                pSysConfig->BillingData.Fee[j] = prices;
             }
 
             clearMiscCommand();
@@ -613,12 +623,12 @@ static int miscCommandHandle(uint8_t dataLen, uint8_t plugNum, uint8_t *data)
 
             //log_info("default currency = %s%c\r\n", (uint8_t *)Currency[value]);
             log_info("default currency = %s\r\n", (uint8_t *)GetCurrency(value));
-            ShmSysConfigAndInfo->SysConfig.BillingData.Currency = value;
+            pSysConfig->BillingData.Currency = value;
             clearMiscCommand();
             break;
 
         case MISC_CMD_ACCOUNT_BALANCE:
-            if (ShmSysConfigAndInfo->SysInfo.CurGunSelected != (plugNum)) {
+            if (pSysInfo->CurGunSelected != (plugNum)) {
                 clearMiscCommand();
                 break;
             }
@@ -652,11 +662,11 @@ static int miscCommandHandle(uint8_t dataLen, uint8_t plugNum, uint8_t *data)
             break;
 
         case MISC_CMD_BILLING_INFO:
-            ShmSysConfigAndInfo->SysConfig.BillingData.isBilling = value;
+            pSysConfig->BillingData.isBilling = value;
             break;
 
         case MISC_CMD_WEB_STOP_CHARGING:
-            ShmSysConfigAndInfo->SysConfig.StopChargingByButton = value;
+            pSysConfig->StopChargingByButton = value;
             break;
 
         //--- Control Dispenser ---
@@ -699,39 +709,39 @@ static int miscCommandHandle(uint8_t dataLen, uint8_t plugNum, uint8_t *data)
                 break;
             }
 
-            if (ShmSysConfigAndInfo->SysInfo.CurGunSelected != (plugNum)) {
+            if (pSysInfo->CurGunSelected != (plugNum)) {
                 if (plugNum == LEFT_GUN_NUM &&
                         (ShmSelectGunInfo->SelGunInfo.LeftGun == SEL_GUN_CONFIRM ||
                          ShmSelectGunInfo->SelGunInfo.LeftGun == SEL_GUN_ATHOR)) {
                     ShmSelectGunInfo->SelGunInfo.LeftGun = SEL_GUN_RELEASE;
-                    strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
-                    ShmSysConfigAndInfo->SysInfo.WaitForPlugit = NO;
+                    strcpy((char *)pSysConfig->UserId, "");
+                    pSysInfo->WaitForPlugit = NO;
                     sleep(1); //Jerry add
-                    ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_SELECT_GUN;
-                    gettimeofday(&ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer, NULL);
-                    ShmSysConfigAndInfo->SysInfo.SystemTimeoutFlag = Timeout_None;
+                    pSysInfo->SystemPage = _LCM_SELECT_GUN;
+                    gettimeofday(&pSysInfo->SystemTimeoutTimer, NULL);
+                    pSysInfo->SystemTimeoutFlag = Timeout_None;
                 }
 
                 if (plugNum == RIGHT_GUN_NUM &&
                         (ShmSelectGunInfo->SelGunInfo.RightGun == SEL_GUN_CONFIRM ||
                          ShmSelectGunInfo->SelGunInfo.RightGun == SEL_GUN_ATHOR)) {
                     ShmSelectGunInfo->SelGunInfo.RightGun = SEL_GUN_RELEASE;
-                    strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
-                    ShmSysConfigAndInfo->SysInfo.WaitForPlugit = NO;
+                    strcpy((char *)pSysConfig->UserId, "");
+                    pSysInfo->WaitForPlugit = NO;
                     sleep(1); //Jerry add
-                    ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_SELECT_GUN;
-                    gettimeofday(&ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer, NULL);
-                    ShmSysConfigAndInfo->SysInfo.SystemTimeoutFlag = Timeout_None;
+                    pSysInfo->SystemPage = _LCM_SELECT_GUN;
+                    gettimeofday(&pSysInfo->SystemTimeoutTimer, NULL);
+                    pSysInfo->SystemTimeoutFlag = Timeout_None;
                 }
 
-                ShmSysConfigAndInfo->SysInfo.CurGunSelected = (plugNum);
-                ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc = NO_DEFINE;
+                pSysInfo->CurGunSelected = (plugNum);
+                pSysInfo->CurGunSelectedByAc = NO_DEFINE;
             }
 #else
-            ShmSysConfigAndInfo->SysInfo.CurGunSelected = (plugNum);
-            ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc = NO_DEFINE;
+            pSysInfo->CurGunSelected = (plugNum);
+            pSysInfo->CurGunSelectedByAc = NO_DEFINE;
 #endif //DD360Audi
-            setConfirmSelGun(ShmSysConfigAndInfo->SysInfo.CurGunSelected);
+            setConfirmSelGun(pSysInfo->CurGunSelected);
 
             ShmOCPP16Data->CsMsg.bits[plugNum].RemoteStartTransactionReq = YES;
             ShmSelectGunInfo->PricesInfo[plugNum].Balance = 0.00;
@@ -746,11 +756,11 @@ static int miscCommandHandle(uint8_t dataLen, uint8_t plugNum, uint8_t *data)
                 break;
             }
 
-            strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
-            ShmSysConfigAndInfo->SysInfo.WaitForPlugit = NO;
-            ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_SELECT_GUN;
-            gettimeofday(&ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer, NULL);
-            ShmSysConfigAndInfo->SysInfo.SystemTimeoutFlag = Timeout_None;
+            strcpy((char *)pSysConfig->UserId, "");
+            pSysInfo->WaitForPlugit = NO;
+            pSysInfo->SystemPage = _LCM_SELECT_GUN;
+            gettimeofday(&pSysInfo->SystemTimeoutTimer, NULL);
+            pSysInfo->SystemTimeoutFlag = Timeout_None;
             destroySelectGun(plugNum);
 
             clearMiscCommand();
@@ -766,14 +776,16 @@ static int miscCommandHandle(uint8_t dataLen, uint8_t plugNum, uint8_t *data)
 
             if (isDetectPlugin() == YES) {
                 ClearDetectPluginFlag();
-                strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
-                ShmSysConfigAndInfo->SysInfo.WaitForPlugit = NO;
-                ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_SELECT_GUN;
-                gettimeofday(&ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer, NULL);
-                ShmSysConfigAndInfo->SysInfo.SystemTimeoutFlag = Timeout_None;
+                strcpy((char *)pSysConfig->UserId, "");
+                pSysInfo->WaitForPlugit = NO;
+                pSysInfo->SystemPage = _LCM_SELECT_GUN;
+                gettimeofday(&pSysInfo->SystemTimeoutTimer, NULL);
+                pSysInfo->SystemTimeoutFlag = Timeout_None;
                 destroySelectGun(plugNum);
             } else {
-                ChargingData[plugNum]->StopChargeFlag = POWER_CABINET_STOP_CHARGING;
+                pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(plugNum);
+
+                pDcChargingInfo->StopChargeFlag = POWER_CABINET_STOP_CHARGING;
             }
             break;
 
@@ -794,6 +806,7 @@ static int chargingcapabilityHandle(uint8_t *data, uint8_t plugNum)
     static PricesInfo pricesInfo[2] = {0};
     CapabilityInfo *pCapabilityInfo = NULL;
     AccountInfo *pAccountInfo = NULL;
+    pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(plugNum);
 
     //--- charging capability information --------------------------------------
     pCapabilityInfo = (CapabilityInfo *)&data[0];
@@ -803,7 +816,7 @@ static int chargingcapabilityHandle(uint8_t *data, uint8_t plugNum)
         if (MaxVolt > MAX_VOLTAGE) {
             MaxVolt = MAX_VOLTAGE;
         }
-        ChargingData[plugNum]->MaximumChargingVoltage = MaxVolt;
+        pDcChargingInfo->MaximumChargingVoltage = MaxVolt;
     }
 
     MaxCurrent = (float)(ntohs(pCapabilityInfo->OutputCurrent));
@@ -811,7 +824,7 @@ static int chargingcapabilityHandle(uint8_t *data, uint8_t plugNum)
         if (MaxCurrent > MAX_CURRENCY) {
             MaxCurrent = MAX_CURRENCY;
         }
-        ChargingData[plugNum]->AvailableChargingCurrent = MaxCurrent;
+        pDcChargingInfo->AvailableChargingCurrent = MaxCurrent;
     }
 
     MaxPower = (float)(ntohs(pCapabilityInfo->OutputPower));
@@ -819,7 +832,7 @@ static int chargingcapabilityHandle(uint8_t *data, uint8_t plugNum)
         if (MaxPower > MAX_POWER) {
             MaxPower = MAX_POWER;
         }
-        ChargingData[plugNum]->AvailableChargingPower = MaxPower;
+        pDcChargingInfo->AvailableChargingPower = MaxPower;
     }
     //MaxVolt = (float)(data[0] << 8 |data[1]);
     //MaxCurrent = (float)(data[2] << 8 | data[3]);
@@ -830,9 +843,9 @@ static int chargingcapabilityHandle(uint8_t *data, uint8_t plugNum)
     addr = (sizeof(CapabilityInfo) - 2); //2 byte reserved
     pAccountInfo = (AccountInfo *)&data[addr];
 
-    ShmSysConfigAndInfo->SysConfig.BillingData.Currency = pAccountInfo->Currency;
+    pSysConfig->BillingData.Currency = pAccountInfo->Currency;
     ShmSelectGunInfo->PricesInfo[plugNum].UserPrices    = transPricesUnit(ntohl(pAccountInfo->UserPrices));
-    ChargingData[plugNum]->ChargingFee                  = transPricesUnit(ntohl(pAccountInfo->TotalCost));
+    pDcChargingInfo->ChargingFee                  = transPricesUnit(ntohl(pAccountInfo->TotalCost));
     ShmSelectGunInfo->PricesInfo[plugNum].Balance       = transPricesUnit(ntohl(pAccountInfo->Balance));
 
     if ((pricesInfo[plugNum].UserPrices != ShmSelectGunInfo->PricesInfo[plugNum].UserPrices) ||
@@ -843,9 +856,9 @@ static int chargingcapabilityHandle(uint8_t *data, uint8_t plugNum)
         log_info("id = %d, user prices = %.2f, Total cost = %.2f, Account balances = %.2f, currency = %s\r\n",
                  plugNum,
                  ShmSelectGunInfo->PricesInfo[plugNum].UserPrices,
-                 ChargingData[plugNum]->ChargingFee,
+                 pDcChargingInfo->ChargingFee,
                  ShmSelectGunInfo->PricesInfo[plugNum].Balance,
-                 (uint8_t *)GetCurrency(ShmSysConfigAndInfo->SysConfig.BillingData.Currency)
+                 (uint8_t *)GetCurrency(pSysConfig->BillingData.Currency)
                 );
     }
 
@@ -854,13 +867,13 @@ static int chargingcapabilityHandle(uint8_t *data, uint8_t plugNum)
 
 static void addFaultCodeToBuf(uint8_t *Code)
 {
-    uint8_t warningCount = ShmSysConfigAndInfo->SysWarningInfo.WarningCount;
+    uint8_t warningCount = pSysWarning->WarningCount;
 
     if (warningCount < 10) {
-        memcpy(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[warningCount][0],
+        memcpy(&pSysWarning->WarningCode[warningCount][0],
                Code,
                strlen((char *)Code));
-        ShmSysConfigAndInfo->SysWarningInfo.WarningCount++;
+        pSysWarning->WarningCount++;
     }
 }
 
@@ -876,20 +889,20 @@ static void removeFaultCodeToBuf(uint8_t *Code)
     while (find) {
         usleep(128);
         find = 0x00;
-        for (i = 0; i < ShmSysConfigAndInfo->SysWarningInfo.WarningCount; i++) {
+        for (i = 0; i < pSysWarning->WarningCount; i++) {
             usleep(128);
             if (find == 0x00) {
-                if (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], _code, 7) == 0) {
+                if (memcmp(&pSysWarning->WarningCode[i][0], _code, 7) == 0) {
                     find = 0x01;
                 }
             } else {
-                memcpy(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i - 1][0],
-                       &ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], 7);
+                memcpy(&pSysWarning->WarningCode[i - 1][0],
+                       &pSysWarning->WarningCode[i][0], 7);
             }
         }
 
         if (find) {
-            ShmSysConfigAndInfo->SysWarningInfo.WarningCount--;
+            pSysWarning->WarningCount--;
         }
     }
 }
@@ -931,15 +944,15 @@ static int powerCabinetStatusProcess(uint8_t dataLen, uint8_t *data)
         if (dataLen < WARNING_CODE_SIZE) {
             log_error("fail status code length = %d\r\n", dataLen);
             Hexdump(data, dataLen);
-            if (ShmSysConfigAndInfo->SysWarningInfo.WarningCount > 0) {
-                for (i = 0; i < ShmSysConfigAndInfo->SysWarningInfo.WarningCount; i++) {
+            if (pSysWarning->WarningCount > 0) {
+                for (i = 0; i < pSysWarning->WarningCount; i++) {
                     usleep(128);
-                    if (ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][1] >= '3' ||  //from backend or power cabinet
-                            (ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0] >= 'B' &&
-                             ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][1] >= '4')) {
+                    if (pSysWarning->WarningCode[i][1] >= '3' ||  //from backend or power cabinet
+                            (pSysWarning->WarningCode[i][0] >= 'B' &&
+                             pSysWarning->WarningCode[i][1] >= '4')) {
                         memset(EventCodeTmp, 0, sizeof(EventCodeTmp));
                         memcpy(EventCodeTmp,
-                               ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i],
+                               pSysWarning->WarningCode[i],
                                sizeof(EventCodeTmp));
                         removeFaultCodeToBuf(EventCodeTmp);
                     }
@@ -982,9 +995,9 @@ static int powerCabinetStatusProcess(uint8_t dataLen, uint8_t *data)
             strncpy((char *)&StatusArray[count / WARNING_CODE_SIZE], (char *)&data[count], WARNING_CODE_SIZE);
 
             ret = 0;
-            for (i = 0; i < ShmSysConfigAndInfo->SysWarningInfo.WarningCount; i++) {
+            for (i = 0; i < pSysWarning->WarningCount; i++) {
                 usleep(128);
-                if (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0],
+                if (memcmp(&pSysWarning->WarningCode[i][0],
                            StatusArray[count / WARNING_CODE_SIZE],
                            WARNING_CODE_SIZE) == 0) {
                     ret = 1;
@@ -1004,17 +1017,17 @@ static int powerCabinetStatusProcess(uint8_t dataLen, uint8_t *data)
         }
     }
 
-    for (i = 0; i < ShmSysConfigAndInfo->SysWarningInfo.WarningCount; i++) {
+    for (i = 0; i < pSysWarning->WarningCount; i++) {
         usleep(128);
 
-        if (ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][1] >= '3' || //from backend or power cabinet 0x33
-                (ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0] >= 'B' &&
-                 ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][1] >= '4')) {
+        if (pSysWarning->WarningCode[i][1] >= '3' || //from backend or power cabinet 0x33
+                (pSysWarning->WarningCode[i][0] >= 'B' &&
+                 pSysWarning->WarningCode[i][1] >= '4')) {
             ret = 0;
 
             for (count = 0; count < (dataLen / WARNING_CODE_SIZE); count++) {
                 usleep(128);
-                if (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0],
+                if (memcmp(&pSysWarning->WarningCode[i][0],
                            StatusArray[count],
                            WARNING_CODE_SIZE) == 0) {
                     ret = 1;
@@ -1025,7 +1038,7 @@ static int powerCabinetStatusProcess(uint8_t dataLen, uint8_t *data)
             if (ret == 0) {
                 memset(EventCodeTmp, 0, sizeof(EventCodeTmp));
                 memcpy(EventCodeTmp,
-                       ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i],
+                       pSysWarning->WarningCode[i],
                        sizeof(EventCodeTmp));
                 removeFaultCodeToBuf(EventCodeTmp);
             }
@@ -1072,7 +1085,7 @@ static int responsePackeHandle(int fd, uint8_t *pResult, uint8_t plugNum, uint8_
     case REG_DISPENSER_STATUS:
         memset(&gPreSysWarningInfo, 0, sizeof(struct WARNING_CODE_INFO));
         memcpy((uint8_t *)&gPreSysWarningInfo,
-               &(ShmSysConfigAndInfo->SysWarningInfo),
+               pSysWarning,
                sizeof(struct WARNING_CODE_INFO));
         break;
 
@@ -1220,9 +1233,9 @@ static int composeSocketData(int fd,
 static int writeWaitPlugItState(int fd, uint8_t id)
 {
     int ret = PASS;
-    uint8_t data[2] = {ShmSysConfigAndInfo->SysInfo.WaitForPlugit, 0};
+    uint8_t data[2] = {pSysInfo->WaitForPlugit, 0};
 
-    //printf("WaitForPlugit = %d\r\n", ShmSysConfigAndInfo->SysInfo.WaitForPlugit);
+    //printf("WaitForPlugit = %d\r\n", pSysInfo->WaitForPlugit);
 
     if ((ret = composeSocketData(fd,
                                  id,
@@ -1254,11 +1267,12 @@ static int writePresentChargingInfo(int fd, uint8_t plugNum, uint8_t id)
     int ret = PASS;
     uint8_t dataBuf[16] = {0};
     PreChargingInfo *pPreChargingInfo = (PreChargingInfo *)dataBuf;
+    pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(plugNum);
 
-    pPreChargingInfo->PresentChargingVoltage = htons((uint16_t)ChargingData[plugNum]->PresentChargingVoltage * 10);
-    pPreChargingInfo->PresentChargingCurrent = htons((uint16_t)ChargingData[plugNum]->PresentChargingCurrent * 10);
-    pPreChargingInfo->RemainChargingDuration = htonl(ChargingData[plugNum]->RemainChargingDuration);
-    pPreChargingInfo->EvBatterySoc = ChargingData[plugNum]->EvBatterySoc;
+    pPreChargingInfo->PresentChargingVoltage = htons((uint16_t)pDcChargingInfo->PresentChargingVoltage * 10);
+    pPreChargingInfo->PresentChargingCurrent = htons((uint16_t)pDcChargingInfo->PresentChargingCurrent * 10);
+    pPreChargingInfo->RemainChargingDuration = htonl(pDcChargingInfo->RemainChargingDuration);
+    pPreChargingInfo->EvBatterySoc = pDcChargingInfo->EvBatterySoc;
 
     ret = composeSocketData(fd,
                             id,
@@ -1276,15 +1290,15 @@ static int writeOtherModuleVersion(int fd)
     uint8_t dataLen = 0;
 
     //report other module version message
-    memcpy(&data[dataLen], ShmSysConfigAndInfo->SysInfo.FanModuleFwRev, VERSION_BUF_SIZE);
+    memcpy(&data[dataLen], pSysInfo->FanModuleFwRev, VERSION_BUF_SIZE);
     dataLen += VERSION_BUF_SIZE;
-    memcpy(&data[dataLen], ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev, VERSION_BUF_SIZE);
+    memcpy(&data[dataLen], pSysInfo->RelayModuleFwRev, VERSION_BUF_SIZE);
     dataLen += VERSION_BUF_SIZE;
-    memcpy(&data[dataLen], ShmSysConfigAndInfo->SysInfo.Connector1FwRev, VERSION_BUF_SIZE);
+    memcpy(&data[dataLen], pSysInfo->Connector1FwRev, VERSION_BUF_SIZE);
     dataLen += VERSION_BUF_SIZE;
-    memcpy(&data[dataLen], ShmSysConfigAndInfo->SysInfo.Connector2FwRev, VERSION_BUF_SIZE);
+    memcpy(&data[dataLen], pSysInfo->Connector2FwRev, VERSION_BUF_SIZE);
     dataLen += VERSION_BUF_SIZE;
-    memcpy(&data[dataLen], ShmSysConfigAndInfo->SysInfo.LedModuleFwRev, VERSION_BUF_SIZE);
+    memcpy(&data[dataLen], pSysInfo->LedModuleFwRev, VERSION_BUF_SIZE);
     dataLen += VERSION_BUF_SIZE;
 
     ret = composeSocketData(fd,
@@ -1304,13 +1318,13 @@ static int writeCsuModuleVersion(int fd)
     uint8_t dataLen = 0;
 
     //report CSU platform version message
-    memcpy(&data[dataLen], ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev, VERSION_BUF_SIZE);
+    memcpy(&data[dataLen], pSysInfo->CsuBootLoadFwRev, VERSION_BUF_SIZE);
     dataLen += VERSION_BUF_SIZE;
-    memcpy(&data[dataLen], ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev, VERSION_BUF_SIZE);
+    memcpy(&data[dataLen], pSysInfo->CsuKernelFwRev, VERSION_BUF_SIZE);
     dataLen += VERSION_BUF_SIZE;
-    memcpy(&data[dataLen], ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev, VERSION_BUF_SIZE);
+    memcpy(&data[dataLen], pSysInfo->CsuRootFsFwRev, VERSION_BUF_SIZE);
     dataLen += VERSION_BUF_SIZE;
-    memcpy(&data[dataLen], ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev, VERSION_BUF_SIZE);
+    memcpy(&data[dataLen], pSysInfo->CsuPrimFwRev, VERSION_BUF_SIZE);
     dataLen += VERSION_BUF_SIZE;
 
     ret = composeSocketData(fd,
@@ -1378,27 +1392,28 @@ static int writeConnectorState(int fd, uint8_t plugNum, uint8_t id)
     ConnectorState *pConnState = (ConnectorState *)dataBuf;
     static char vendorErrorCodeTmp[2][WARNING_CODE_SIZE] = {0};
     int ret = PASS;
+    pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(plugNum);
 
-    pConnState->ConnectorTemp = ChargingData[plugNum]->ConnectorTemp;
-    pConnState->ChillerTemp = ChargingData[plugNum]->ChillerTemp;
+    pConnState->ConnectorTemp = pDcChargingInfo->ConnectorTemp;
+    pConnState->ChillerTemp = pDcChargingInfo->ChillerTemp;
 
-    if (ChargingData[plugNum]->SystemStatus <= S_AUTHORIZING) {
+    if (pDcChargingInfo->SystemStatus <= S_AUTHORIZING) {
         pConnState->State = CONN_ST_IDLE;    //idle
         strncpy((char *)ShmOCPP16Data->StatusNotification[plugNum].VendorErrorCode,
                 "",
                 sizeof(ShmOCPP16Data->StatusNotification[plugNum].VendorErrorCode));
 
         strncpy(&vendorErrorCodeTmp[plugNum][0], "", WARNING_CODE_SIZE);
-    } else if ((ChargingData[plugNum]->SystemStatus <= S_PREPARING_FOR_EVSE) ||
-               (ChargingData[plugNum]->SystemStatus == S_CCS_PRECHARGE_ST0) ||
-               (ChargingData[plugNum]->SystemStatus == S_CCS_PRECHARGE_ST1)) {
+    } else if ((pDcChargingInfo->SystemStatus <= S_PREPARING_FOR_EVSE) ||
+               (pDcChargingInfo->SystemStatus == S_CCS_PRECHARGE_ST0) ||
+               (pDcChargingInfo->SystemStatus == S_CCS_PRECHARGE_ST1)) {
         pConnState->State = CONN_ST_PREPARING;    //preparing
-    } else if (ChargingData[plugNum]->SystemStatus == S_CHARGING) {
+    } else if (pDcChargingInfo->SystemStatus == S_CHARGING) {
         pConnState->State = CONN_ST_CHARGING;    //charging
-    } else if (ChargingData[plugNum]->SystemStatus == S_TERMINATING) {
+    } else if (pDcChargingInfo->SystemStatus == S_TERMINATING) {
         pConnState->State = CONN_ST_TERMINATING;    //terminating
-    } else if ((ChargingData[plugNum]->SystemStatus == S_ALARM) ||
-               (ChargingData[plugNum]->SystemStatus == S_FAULT)) {
+    } else if ((pDcChargingInfo->SystemStatus == S_ALARM) ||
+               (pDcChargingInfo->SystemStatus == S_FAULT)) {
         pConnState->State = CONN_ST_ALARM;
         strncpy((char *)pConnState->WarningCode,
                 (char *)ShmOCPP16Data->StatusNotification[plugNum].VendorErrorCode,
@@ -1440,7 +1455,8 @@ static int writeConnectorState(int fd, uint8_t plugNum, uint8_t id)
 static int writePlugInStatus(int fd, uint8_t plugNum, uint8_t id)
 {
     int ret = PASS;
-    uint8_t dataBuf[2] = {ChargingData[plugNum]->ConnectorPlugIn, 0};
+    pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(plugNum);
+    uint8_t dataBuf[2] = {pDcChargingInfo->ConnectorPlugIn, 0};
 
     ret = composeSocketData(fd,
                             id,
@@ -1454,7 +1470,7 @@ static int writePlugInStatus(int fd, uint8_t plugNum, uint8_t id)
 static int readSoftwareUpdate(int fd, uint8_t gunID)
 {
     int ret = PASS;
-    uint8_t dataBuf[2] = {ShmSysConfigAndInfo->SysInfo.FirmwareUpdate, 0};
+    uint8_t dataBuf[2] = {pSysInfo->FirmwareUpdate, 0};
 
     ret = composeSocketData(fd,
                             gunID,
@@ -1471,9 +1487,10 @@ static int writeChargingTarget(int fd, uint8_t plugNum, uint8_t id)
     int ret = PASS;
     float ChargingVolt, ChargingAmp;
     uint8_t dataBuf[4] = {0};
+    pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(plugNum);
 
-    ChargingVolt = ChargingData[plugNum]->EvBatterytargetVoltage;
-    ChargingAmp = ChargingData[plugNum]->EvBatterytargetCurrent;
+    ChargingVolt = pDcChargingInfo->EvBatterytargetVoltage;
+    ChargingAmp = pDcChargingInfo->EvBatterytargetCurrent;
     ChargingVolt *= 10;
     ChargingAmp *= 10;
 
@@ -1514,14 +1531,14 @@ static int writeDispenserStatus(int fd, uint8_t gunID)
     uint8_t PreWarnCodeTmp[10][6] = {0};
     int ret = PASS;
 
-    if ((ShmSysConfigAndInfo->SysWarningInfo.WarningCount <= 0) &&
+    if ((pSysWarning->WarningCount <= 0) &&
             (gPreSysWarningInfo.WarningCount <= 0)) {
         return FAIL;
     }
 
-    warningCount = ShmSysConfigAndInfo->SysWarningInfo.WarningCount;
+    warningCount = pSysWarning->WarningCount;
     for (count = 0; count < warningCount; count++) {
-        memcpy(CurWarnCodeTmp[count], ShmSysConfigAndInfo->SysWarningInfo.WarningCode[count], WARNING_CODE_SIZE);
+        memcpy(CurWarnCodeTmp[count], pSysWarning->WarningCode[count], WARNING_CODE_SIZE);
     }
 
     warningCount = gPreSysWarningInfo.WarningCount;
@@ -1578,20 +1595,20 @@ static int WriteModelName(int fd)
     uint8_t TmpBuf[255] = {0};
 
     memcpy(TmpBuf,
-           ShmSysConfigAndInfo->SysConfig.ModelName,
-           strlen((char *)ShmSysConfigAndInfo->SysConfig.ModelName));
+           pSysConfig->ModelName,
+           strlen((char *)pSysConfig->ModelName));
 
     Tmp = (uint8_t)(ShmPrimaryMcuData->InputDet.bits.Key2 << 2 |
                     ShmPrimaryMcuData->InputDet.bits.Key1 << 1 |
                     ShmPrimaryMcuData->InputDet.bits.Key0);
 
-    TmpBuf[strlen((char *)ShmSysConfigAndInfo->SysConfig.ModelName)] = Tmp; //Dispenser switch value
+    TmpBuf[strlen((char *)pSysConfig->ModelName)] = Tmp; //Dispenser switch value
 
     ret = composeSocketData(fd,
                             ID_REGISTER,
                             OP_WRITE_DATA,
                             REG_MODEL_NAME,
-                            strlen((char *)ShmSysConfigAndInfo->SysConfig.ModelName) + 1,
+                            strlen((char *)pSysConfig->ModelName) + 1,
                             &TmpBuf[0]);
 
     return ret;
@@ -1610,7 +1627,7 @@ static void calDisconnectCount(uint8_t *pValue, uint8_t maxCount)
 
 static int CheckNetworkStatus(void)
 {
-    char *ipAddr = (char *)&ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthIpAddress;
+    char *ipAddr = (char *)&pSysConfig->Eth0Interface.EthIpAddress;
 
     //printf("Check network IP Header = %s\n", ipAddr);
     if (strstr(ipAddr, CMP_ETH_IP_HEAD) != NULL) {
@@ -1620,27 +1637,28 @@ static int CheckNetworkStatus(void)
     return 0;
 }
 
+#if 0
 static int FindChargingInfoData(uint8_t target, struct ChargingInfoData **chargingData)
 {
     uint8_t index = 0;
 
     for (index = 0; index < CHAdeMO_QUANTITY; index++) {
-        if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == target) {
-            chargingData[target] = &ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index];
+        if (pSysInfo->ChademoChargingData[index].Index == target) {
+            chargingData[target] = &pSysInfo->ChademoChargingData[index];
             return 1;
         }
     }
 
     for (index = 0; index < CCS_QUANTITY; index++) {
-        if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == target) {
-            chargingData[target] = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[index];
+        if (pSysInfo->CcsChargingData[index].Index == target) {
+            chargingData[target] = &pSysInfo->CcsChargingData[index];
             return 1;
         }
     }
 
     for (index = 0; index < GB_QUANTITY; index++) {
-        if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == target) {
-            chargingData[target] = &ShmSysConfigAndInfo->SysInfo.GbChargingData[index];
+        if (pSysInfo->GbChargingData[index].Index == target) {
+            chargingData[target] = &pSysInfo->GbChargingData[index];
             return 1;
         }
     }
@@ -1706,6 +1724,7 @@ static int InitShareMemory(void)
 
     return result;
 }
+#endif //0
 
 static void updateFirmwareProcess(int fd, uint8_t gunID, uint8_t totalConnCount)
 {
@@ -1713,12 +1732,13 @@ static void updateFirmwareProcess(int fd, uint8_t gunID, uint8_t totalConnCount)
     uint8_t plugNum = 0;
     uint8_t ackCount = 5;
     struct timeb updateTime;
+    pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(plugNum);
 
-    if (ShmSysConfigAndInfo->SysWarningInfo.Level != 2) {
+    if (pSysWarning->Level != 2) {
         for (plugNum = 0; plugNum < totalConnCount; plugNum++) {
-            if (ChargingData[plugNum]->SystemStatus != S_IDLE &&
-                    ChargingData[plugNum]->SystemStatus != S_RESERVATION &&
-                    ChargingData[plugNum]->SystemStatus != S_MAINTAIN) {
+            if (pDcChargingInfo->SystemStatus != S_IDLE &&
+                    pDcChargingInfo->SystemStatus != S_RESERVATION &&
+                    pDcChargingInfo->SystemStatus != S_MAINTAIN) {
                 canUpdateFirmware = false;
             }
         }
@@ -1731,13 +1751,13 @@ static void updateFirmwareProcess(int fd, uint8_t gunID, uint8_t totalConnCount)
             ftime(&gRegTimeUp[0][REG_SOFTWARE_UPDATE]);
         }
 
-        if (ShmSysConfigAndInfo->SysInfo.FirmwareUpdate == YES) {
+        if (pSysInfo->FirmwareUpdate == YES) {
             while (ackCount != 0) {
                 ftime(&updateTime);
                 if (DiffTimeb(gRegTimeUp[0][REG_SOFTWARE_UPDATE], updateTime) > LOOP_RETRY_TIME / 2) {
                     readSoftwareUpdate(fd, gunID);
                     ftime(&gRegTimeUp[0][REG_SOFTWARE_UPDATE]);
-                    if (ShmSysConfigAndInfo->SysInfo.FirmwareUpdate == NO) {
+                    if (pSysInfo->FirmwareUpdate == NO) {
                         ackCount--;
                     }
                 }
@@ -1754,22 +1774,22 @@ static void checkAuthorProcess(int fd, uint8_t plugNum)
     struct timeb AuthNowTime;
 
 #if defined DD360Audi
-    gunID = gDoCommGblData.ConnectorID[ShmSysConfigAndInfo->SysInfo.CurGunSelected];
+    gunID = gDoCommGblData.ConnectorID[pSysInfo->CurGunSelected];
     //gunID = gDoCommGblData.ConnectorID[plugNum];
 #else
     gunID = ID_REGISTER;
 
-    ShmSelectGunInfo->PricesInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected].Balance = 0.0;
+    ShmSelectGunInfo->PricesInfo[pSysInfo->CurGunSelected].Balance = 0.0;
 #endif // DD360Audi
 
     if ((ShmOCPP16Data->SpMsg.bits.AuthorizeReq == YES) ||
-            (ShmSysConfigAndInfo->SysInfo.AuthorizeFlag == YES)) {
+            (pSysInfo->AuthorizeFlag == YES)) {
         ftime(&AuthNowTime);
 
         if (DiffTimeb(gRegTimeUp[plugNum][REG_USER_ID], AuthNowTime) > LOOP_RETRY_TIME) {
             ret = writeUserID(fd,
                               gunID,
-                              ShmSysConfigAndInfo->SysConfig.UserId);
+                              pSysConfig->UserId);
             if (ret >= 0) {
                 memset(ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status,
                        0,
@@ -1786,11 +1806,11 @@ static void checkAuthorProcess(int fd, uint8_t plugNum)
                 //       FAIL_BALANCE_PRICES);
 
                 if (ShmSelectGunInfo->PricesInfo[plugNum].Balance != FAIL_BALANCE_PRICES) {
-                    ShmOCPP16Data->SpMsg.bits.AuthorizeConf    = YES; //isAuthorizedComplete
-                    ShmOCPP16Data->SpMsg.bits.AuthorizeReq     = NO;
-                    ShmSysConfigAndInfo->SysInfo.AuthorizeFlag = NO;
-                    ShmPsuData->SystemAvailablePower           = NO;
-                    ShmPsuData->SystemPresentPsuQuantity       = NO;
+                    ShmOCPP16Data->SpMsg.bits.AuthorizeConf = YES; //isAuthorizedComplete
+                    ShmOCPP16Data->SpMsg.bits.AuthorizeReq  = NO;
+                    pSysInfo->AuthorizeFlag                 = NO;
+                    ShmPsuData->SystemAvailablePower        = NO;
+                    ShmPsuData->SystemPresentPsuQuantity    = NO;
                 }
             }
             ftime(&gRegTimeUp[plugNum][REG_USER_ID]);
@@ -1860,7 +1880,7 @@ static int messageTrigger(int fd, uint8_t plugNum, uint8_t gunID, uint8_t curReg
         //            readSoftwareUpdate(fd);
         //            ftime(&gRegTimeUp[plugNum][curReg]);
         //        }
-        //        while (ShmSysConfigAndInfo->SysInfo.FirmwareUpdate == YES) {
+        //        while (pSysInfo->FirmwareUpdate == YES) {
         //            ftime(&NowTime);
         //            if (DiffTimeb(gRegTimeUp[plugNum][curReg], NowT ime) > LOOP_RETRY_TIME||
         //DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) < 0) {
@@ -1971,7 +1991,7 @@ static int messageTrigger(int fd, uint8_t plugNum, uint8_t gunID, uint8_t curReg
 
 //static bool isDetectPlugin()
 //{
-//    if (ShmSysConfigAndInfo->SysInfo.WaitForPlugit == YES) {
+//    if (pSysInfo->WaitForPlugit == YES) {
 //        return YES;
 //    }
 //
@@ -1982,8 +2002,9 @@ static void systemStatusProcess(int fd, uint8_t totalGun, uint8_t plugNum, uint8
 {
     uint8_t i = 0;
     struct timeb AuthNowTime = {0};
+    pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(plugNum);
 
-    switch (ChargingData[plugNum]->SystemStatus) {
+    switch (pDcChargingInfo->SystemStatus) {
     case S_IDLE:
     case S_RESERVATION:
     case S_MAINTAIN:
@@ -2020,7 +2041,9 @@ static void systemStatusProcess(int fd, uint8_t totalGun, uint8_t plugNum, uint8
         if (DiffTimeb(gRegTimeUp[plugNum][REG_CHARGING_PERMISSION], AuthNowTime) > LOOP_RETRY_TIME) {
             if (readChargePermission(fd, gunID) && readChargingCapability(fd, gunID)) {
                 for (i = 0; i < totalGun; i++) {
-                    ShmPsuData->SystemAvailablePower += ChargingData[i]->AvailableChargingPower;
+                    pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(i);
+
+                    ShmPsuData->SystemAvailablePower += pDcChargingInfo->AvailableChargingPower;
                 }
                 ShmPsuData->SystemPresentPsuQuantity = (ShmPsuData->SystemAvailablePower / 30);
             }
@@ -2047,7 +2070,7 @@ static void systemStatusProcess(int fd, uint8_t totalGun, uint8_t plugNum, uint8
                 log_info("S_PREPARING_FOR_EV Stop charging by power cabinet's permission = %d, %d\r\n",
                          plugNum,
                          REG_CHARGING_PERMISSION);
-                ChargingData[plugNum]->StopChargeFlag = POWER_CABINET_STOP_CHARGING;
+                pDcChargingInfo->StopChargeFlag = POWER_CABINET_STOP_CHARGING;
             }
             ftime(&gRegTimeUp[plugNum][REG_CHARGING_PERMISSION]);
         }
@@ -2076,7 +2099,7 @@ static void systemStatusProcess(int fd, uint8_t totalGun, uint8_t plugNum, uint8
                 log_info("S_PREPARING_FOR_EVSE Stop charging by power cabinet's permission = %d, %d\r\n",
                          plugNum,
                          REG_CHARGING_PERMISSION);
-                ChargingData[plugNum]->StopChargeFlag = POWER_CABINET_STOP_CHARGING;
+                pDcChargingInfo->StopChargeFlag = POWER_CABINET_STOP_CHARGING;
             }
             ftime(&gRegTimeUp[plugNum][REG_CHARGING_PERMISSION]);
         }
@@ -2102,8 +2125,8 @@ static void systemStatusProcess(int fd, uint8_t totalGun, uint8_t plugNum, uint8
                 log_info("Stop charging by power cabinet's permission = %d, %d\r\n",
                          plugNum,
                          REG_CHARGING_PERMISSION);
-                ChargingData[plugNum]->StopChargeFlag = POWER_CABINET_STOP_CHARGING;
-                //printf("%d StopChargeFlag = %d\r\n", plugNum, ChargingData[plugNum]->StopChargeFlag);
+                pDcChargingInfo->StopChargeFlag = POWER_CABINET_STOP_CHARGING;
+                //printf("%d StopChargeFlag = %d\r\n", plugNum, pDcChargingInfo->StopChargeFlag);
             }
             ftime(&gRegTimeUp[plugNum][REG_CHARGING_PERMISSION]);
         }
@@ -2133,7 +2156,7 @@ static int networkCreatePorcess(void)
 {
     int fd = 0;
 
-    while (ShmSysConfigAndInfo->SysInfo.SelfTestSeq != _STEST_COMPLETE) {
+    while (pSysInfo->SelfTestSeq != _STEST_COMPLETE) {
         usleep(128);
     }
 
@@ -2141,7 +2164,7 @@ static int networkCreatePorcess(void)
 
     /**************** Check Network **********/
     log_info("Check Dispenser Network Information");
-    while (ShmSysConfigAndInfo->SysInfo.SelfTestSeq != _STEST_COMPLETE) {
+    while (pSysInfo->SelfTestSeq != _STEST_COMPLETE) {
         usleep(125);
     }
 
@@ -2150,9 +2173,9 @@ static int networkCreatePorcess(void)
         log_error("disconnect count = % d\r\n", gDoCommGblData.DisConnCount);
     }
     log_info("Dispenser Network Information checked: IP = % s Netmask = % s, Gateway = % s",
-             ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthIpAddress,
-             ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthSubmaskAddress,
-             ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthGatewayAddress);
+             pSysConfig->Eth0Interface.EthIpAddress,
+             pSysConfig->Eth0Interface.EthSubmaskAddress,
+             pSysConfig->Eth0Interface.EthGatewayAddress);
 
     gDoCommGblData.DisConnCount = 0;
 
@@ -2164,9 +2187,9 @@ static int networkCreatePorcess(void)
     }
     log_info("Power cabinet connected(fd = % d): IP = % s Netmask = % s, Gateway = % s",
              fd,
-             ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthIpAddress,
-             ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthSubmaskAddress,
-             ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthGatewayAddress);
+             pSysConfig->Eth0Interface.EthIpAddress,
+             pSysConfig->Eth0Interface.EthSubmaskAddress,
+             pSysConfig->Eth0Interface.EthGatewayAddress);
 
     gDoCommGblData.DisConnCount = 0;
     destroySelectGun(DESTROY_ALL_SEL);
@@ -2191,9 +2214,9 @@ int main(int argc, char *argv[])
     InitSocketSigPipe();
 
     /**************** Initialization **********/
-    if (InitShareMemory() == 0) {
+    /*if (InitShareMemory() == 0) {
         if (ShmStatusCodeData != NULL) {
-            ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory = YES;
+            pAlarmCode->AlarmEvents.bits.FailToCreateShareMemory = YES;
         }
 
         log_error("DoComm Initial share memory fail\r\n");
@@ -2201,14 +2224,31 @@ int main(int argc, char *argv[])
 
         return 0;
     }
+    */
+    if (CreateAllCsuShareMemory() == FAIL) {
+        log_error("create share memory error\r\n");
+        return FAIL;
+    }
 
-    totalConnCount = ShmSysConfigAndInfo->SysConfig.TotalConnectorCount;
+    MappingGunChargingInfo("DoComm Task");
+
+    pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
+    pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
+    pSysWarning = (struct WARNING_CODE_INFO *)GetShmSysWarningInfo();
+
+    pAlarmCode = (struct AlarmCodeData *)GetShmAlarmCodeData();
+    ShmPsuData = (struct PsuData *)GetShmPsuData();
+    ShmPrimaryMcuData = (struct PrimaryMcuData *)GetShmPrimaryMcuData();
+    ShmOCPP16Data = (struct OCPP16Data *)GetShmOCPP16Data();
+    ShmSelectGunInfo = (SelectGunInfo *)GetShmSelectGunInfo();
+
+    totalConnCount = pSysConfig->TotalConnectorCount;
 
     for (index = 0; index < totalConnCount; index++) {
-        if (!FindChargingInfoData(index, &ChargingData[0])) {
-            log_error("FindChargingInfoData false \n");
-            break;
-        }
+        //if (!FindChargingInfoData(index, &ChargingData[0])) {
+        //    log_error("FindChargingInfoData false \n");
+        //    break;
+        //}
         clearPricesInfo(index);
     }
 
@@ -2253,10 +2293,10 @@ int main(int argc, char *argv[])
             setTcpStatus(ABNORMAL);
 
 
-            if (ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthDhcpClient == 0) {
+            if (pSysConfig->Eth0Interface.EthDhcpClient == 0) {
                 sprintf(tmpbuf,
                         "/sbin/udhcpc -i eth0 -x hostname:CSU3_%s -s /root/dhcp_script/eth0.script > /dev/null &",
-                        ShmSysConfigAndInfo->SysConfig.SystemId);
+                        pSysConfig->SystemId);
                 system(tmpbuf);
             }
 

+ 134 - 87
EVSE/Projects/DD360/Apps/ModuleEventLog/Module_EventLogging.c

@@ -26,23 +26,34 @@
 #include <time.h>
 #include <ctype.h>
 #include <ifaddrs.h>
+
+#include "../Log/log.h"
+#include "../ShareMemory/shmMem.h"
 #include "../Define/define.h"
 #include "../Config.h"
 
 //------------------------------------------------------------------------------
-struct SysConfigAndInfo         *ShmSysConfigAndInfo;
-struct StatusCodeData           *ShmStatusCodeData;
+//struct SysConfigAndInfo         *ShmSysConfigAndInfo;
+//struct StatusCodeData           *ShmStatusCodeData;
+static struct SysConfigData *pSysConfig      = NULL;
+static struct SysInfoData *pSysInfo          = NULL;
+static struct WARNING_CODE_INFO *pSysWarning = NULL;
+static struct AlarmCodeData *pAlarmCode      = NULL;
+static struct InfoCodeData *pInfoCode        = NULL;
+static struct FaultCodeData *pFaultCode      = NULL;
 
-sqlite3 *localDb; //DS60-120 add
+//sqlite3 *localDb; //DS60-120 add
 
 //------------------------------------------------------------------------------
+#define WRITE_FLASH_TIME                        (128)
 #define DB_FILE             "/Storage/ChargeLog/localCgargingRecord.db" //DS60-120 add
 
-#define log_info(format, args...) StoreLogMsg("[%s:%d][%s][Info] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
-#define log_warn(format, args...) StoreLogMsg("[%s:%d][%s][Warn] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
-#define log_error(format, args...) StoreLogMsg("[%s:%d][%s][Error] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
+//#define log_info(format, args...) StoreLogMsg("[%s:%d][%s][Info] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
+//#define log_warn(format, args...) StoreLogMsg("[%s:%d][%s][Warn] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
+//#define log_error(format, args...) StoreLogMsg("[%s:%d][%s][Error] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
 #define event_info(format, args...) StoreEventLogMsg("[%s:%d][%s][Info] "format, __FILE__, __LINE__, __FUNCTION__, ##args) //DS60-120 add
 
+/*
 int StoreLogMsg(const char *fmt, ...)
 {
     char Buf[4096 + 256];
@@ -169,15 +180,16 @@ int InitShareMemory()
 
     return result;
 }
+*/
 
 //================================================
 // Main process
 //================================================
 void AddFaultCodeToBuf(uint8_t *Code)
 {
-    if (ShmSysConfigAndInfo->SysWarningInfo.WarningCount < 10) {
-        memcpy(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[ShmSysConfigAndInfo->SysWarningInfo.WarningCount][0], Code, 7);
-        ShmSysConfigAndInfo->SysWarningInfo.WarningCount++;
+    if (pSysWarning->WarningCount < 10) {
+        memcpy(&pSysWarning->WarningCode[pSysWarning->WarningCount][0], Code, 7);
+        pSysWarning->WarningCount++;
     }
 }
 
@@ -190,23 +202,24 @@ void RemoveFaultCodeToBuf(uint8_t *Code)
     // 把相關的錯誤碼一次移除,避免重複顯示
     while (find) {
         find = 0x00;
-        for (uint8_t i = 0; i < ShmSysConfigAndInfo->SysWarningInfo.WarningCount; i++) {
+        for (uint8_t i = 0; i < pSysWarning->WarningCount; i++) {
             if (find == 0x00) {
-                if (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], _code, 7) == 0) {
+                if (memcmp(&pSysWarning->WarningCode[i][0], _code, 7) == 0) {
                     find = 0x01;
                 }
             } else {
-                memcpy(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i - 1][0],
-                       &ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], 7);
+                memcpy(&pSysWarning->WarningCode[i - 1][0],
+                       &pSysWarning->WarningCode[i][0], 7);
             }
         }
 
         if (find) {
-            ShmSysConfigAndInfo->SysWarningInfo.WarningCount--;
+            pSysWarning->WarningCount--;
         }
     }
 }
 
+#if 0
 //==========================================
 // SQLite routne
 //==========================================
@@ -274,97 +287,131 @@ int DB_Insert_Record(sqlite3 *db, uint8_t *statusCode) //DS60-120 add
 
     return result;
 }
+#endif //0
 
 int main(void)
 {
-    int ByteCount, BitCount;
-    uint8_t tmp, EventCodeTmp[7];
-
-    if (InitShareMemory() == FAIL) {
-        log_error("InitShareMemory NG\n");
-        if (ShmStatusCodeData != NULL) {
-            ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory = 1;
-        }
-        sleep(5);
-        return 0;
+    int ByteCounter, BitCounter;
+    uint8_t tmp, EventCodeTmp[7] = {0};
+
+    //if (InitShareMemory() == FAIL) {
+    //    log_error("InitShareMemory NG\n");
+    //    if (ShmStatusCodeData != NULL) {
+    //        pAlarmCode->AlarmEvents.bits.FailToCreateShareMemory = 1;
+    //    }
+    //    sleep(5);
+    //    return 0;
+    //}
+    if (CreateAllCsuShareMemory() == FAIL) {
+        log_error("create share memory error\r\n");
+        return FAIL;
     }
 
+    MappingGunChargingInfo("EventLog Task");
+
+    pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
+    pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
+    pSysWarning = (struct WARNING_CODE_INFO *)GetShmSysWarningInfo();
+
+    pAlarmCode = (struct AlarmCodeData *)GetShmAlarmCodeData();
+    pInfoCode = (struct InfoCodeData *)GetShmInfoCodeData();
+    pFaultCode = (struct FaultCodeData *)GetShmFaultCodeData();
+
+
     for (;;) {
         //check Fault Status
-        for (ByteCount = 0; ByteCount < sizeof(ShmStatusCodeData->FaultCode.PreviousFaultVal); ByteCount++) {
-            if (ShmStatusCodeData->FaultCode.FaultEvents.FaultVal[ByteCount] != ShmStatusCodeData->FaultCode.PreviousFaultVal[ByteCount]) {
-                tmp = ShmStatusCodeData->FaultCode.FaultEvents.FaultVal[ByteCount]; //prevent be modified during following process
-                for (BitCount = 0; BitCount < 8; BitCount++) {
-                    if (((tmp >> BitCount) & 0x01) != ((ShmStatusCodeData->FaultCode.PreviousFaultVal[ByteCount] >> BitCount) & 0x01)) {
-                        memset(EventCodeTmp, 0, sizeof(EventCodeTmp));
-                        memcpy(EventCodeTmp, GetFaultStatusCode(ByteCount * 8 + BitCount), sizeof(EventCodeTmp) - 1);
-                        if (((tmp >> BitCount) & 0x01) == 0) { //Recovered
-                            //EventCodeTmp[0]=1;
-                            log_info("Recovery Fault Code = %s\n", EventCodeTmp);
-                            ShmStatusCodeData->FaultCode.PreviousFaultVal[ByteCount] &= ~(1 << BitCount);
-                            RemoveFaultCodeToBuf(EventCodeTmp);
-                            EventCodeTmp[0] = '1';//DS60-120 add
-                        } else {
-                            log_info("Fault Code = %s\n", EventCodeTmp);
-                            ShmStatusCodeData->FaultCode.PreviousFaultVal[ByteCount] |= (1 << BitCount);
-                            AddFaultCodeToBuf(EventCodeTmp);
-                        }
-                        event_info("%s\n", EventCodeTmp); //DS60-120 add
-                        DB_Insert_Record(localDb, EventCodeTmp); //DS60-120 add
-                    }
+        for (ByteCounter = 0; ByteCounter < sizeof(pFaultCode->PreviousFaultVal); ByteCounter++) {
+            usleep(WRITE_FLASH_TIME);
+            if (pFaultCode->FaultEvents.FaultVal[ByteCounter] == pFaultCode->PreviousFaultVal[ByteCounter]) {
+                continue;
+            }
+
+            tmp = pFaultCode->FaultEvents.FaultVal[ByteCounter]; //prevent be modified during following process
+            for (BitCounter = 0; BitCounter < 8; BitCounter++) {
+                usleep(WRITE_FLASH_TIME);
+                if (((tmp >> BitCounter) & 0x01) == ((pFaultCode->PreviousFaultVal[ByteCounter] >> BitCounter) & 0x01)) {
+                    continue;
                 }
+
+                memset(EventCodeTmp, 0, sizeof(EventCodeTmp));
+                memcpy(EventCodeTmp, GetFaultStatusCode(ByteCounter * 8 + BitCounter), sizeof(EventCodeTmp) - 1);
+                if (((tmp >> BitCounter) & 0x01) == 0) { //Recovered
+                    //EventCodeTmp[0]=1;
+                    log_info("Recovery Fault Code = %s\n", EventCodeTmp);
+                    pFaultCode->PreviousFaultVal[ByteCounter] &= ~(1 << BitCounter);
+                    RemoveFaultCodeToBuf(EventCodeTmp);
+                    EventCodeTmp[0] = '1';//DS60-120 add
+                } else {
+                    log_info("Fault Code = %s\n", EventCodeTmp);
+                    pFaultCode->PreviousFaultVal[ByteCounter] |= (1 << BitCounter);
+                    AddFaultCodeToBuf(EventCodeTmp);
+                }
+                event_info("%s\n", EventCodeTmp); //DS60-120 add
+                InsertEventRecord(EventCodeTmp); //DS60-120 add
             }
         }
 
         //check Alarm Status
-        for (ByteCount = 0; ByteCount < sizeof(ShmStatusCodeData->AlarmCode.PreviousAlarmVal); ByteCount++) {
-            if (ShmStatusCodeData->AlarmCode.AlarmEvents.AlarmVal[ByteCount] != ShmStatusCodeData->AlarmCode.PreviousAlarmVal[ByteCount]) {
-                tmp = ShmStatusCodeData->AlarmCode.AlarmEvents.AlarmVal[ByteCount]; //prevent be modified during following process
-                for (BitCount = 0; BitCount < 8; BitCount++) {
-                    if (((tmp >> BitCount) & 0x01) != ((ShmStatusCodeData->AlarmCode.PreviousAlarmVal[ByteCount] >> BitCount) & 0x01)) {
-                        memset(EventCodeTmp, 0, sizeof(EventCodeTmp));
-                        memcpy(EventCodeTmp, GetAlarmStatusCode(ByteCount * 8 + BitCount), sizeof(EventCodeTmp) - 1);
-                        if (((tmp >> BitCount) & 0x01) == 0) { //Recovered
-                            //EventCodeTmp[0]=1;
-                            log_info("Recovery Alarm Code = %s\n", EventCodeTmp);
-                            ShmStatusCodeData->AlarmCode.PreviousAlarmVal[ByteCount] &= ~(1 << BitCount);
-                            RemoveFaultCodeToBuf(EventCodeTmp);
-                            EventCodeTmp[0] = '1';//DS60-120 add
-                        } else {
-                            log_info("Alarm Code = %s\n", EventCodeTmp);
-                            ShmStatusCodeData->AlarmCode.PreviousAlarmVal[ByteCount] |= (1 << BitCount);
-                            AddFaultCodeToBuf(EventCodeTmp);
-                        }
-                        event_info("%s\n", EventCodeTmp); //DS60-120 add
-                        DB_Insert_Record(localDb, EventCodeTmp); //DS60-120 add
-                    }
+        for (ByteCounter = 0; ByteCounter < sizeof(pAlarmCode->PreviousAlarmVal); ByteCounter++) {
+            usleep(WRITE_FLASH_TIME);
+            if (pAlarmCode->AlarmEvents.AlarmVal[ByteCounter] == pAlarmCode->PreviousAlarmVal[ByteCounter]) {
+                continue;
+            }
+
+            tmp = pAlarmCode->AlarmEvents.AlarmVal[ByteCounter]; //prevent be modified during following process
+            for (BitCounter = 0; BitCounter < 8; BitCounter++) {
+                usleep(WRITE_FLASH_TIME);
+                if (((tmp >> BitCounter) & 0x01) == ((pAlarmCode->PreviousAlarmVal[ByteCounter] >> BitCounter) & 0x01)) {
+                    continue;
+                }
+
+                memset(EventCodeTmp, 0, sizeof(EventCodeTmp));
+                memcpy(EventCodeTmp, GetAlarmStatusCode(ByteCounter * 8 + BitCounter), sizeof(EventCodeTmp) - 1);
+                if (((tmp >> BitCounter) & 0x01) == 0) { //Recovered
+                    //EventCodeTmp[0]=1;
+                    log_info("Recovery Alarm Code = %s\n", EventCodeTmp);
+                    pAlarmCode->PreviousAlarmVal[ByteCounter] &= ~(1 << BitCounter);
+                    RemoveFaultCodeToBuf(EventCodeTmp);
+                    EventCodeTmp[0] = '1';//DS60-120 add
+                } else {
+                    log_info("Alarm Code = %s\n", EventCodeTmp);
+                    pAlarmCode->PreviousAlarmVal[ByteCounter] |= (1 << BitCounter);
+                    AddFaultCodeToBuf(EventCodeTmp);
                 }
+                event_info("%s\n", EventCodeTmp); //DS60-120 add
+                InsertEventRecord(EventCodeTmp); //DS60-120 add
             }
         }
 
         //check Info Status
-        for (ByteCount = 0; ByteCount < sizeof(ShmStatusCodeData->InfoCode.PreviousInfoVal); ByteCount++) {
-            if (ShmStatusCodeData->InfoCode.InfoEvents.InfoVal[ByteCount] != ShmStatusCodeData->InfoCode.PreviousInfoVal[ByteCount]) {
-                tmp = ShmStatusCodeData->InfoCode.InfoEvents.InfoVal[ByteCount]; //prevent be modified during following process
-                for (BitCount = 0; BitCount < 8; BitCount++) {
-                    if (((tmp >> BitCount) & 0x01) != ((ShmStatusCodeData->InfoCode.PreviousInfoVal[ByteCount] >> BitCount) & 0x01)) {
-                        memset(EventCodeTmp, 0, sizeof(EventCodeTmp));
-                        memcpy(EventCodeTmp, GetInfoStatusCode(ByteCount * 8 + BitCount), sizeof(EventCodeTmp) - 1);
-                        if (((tmp >> BitCount) & 0x01) == 0) { //Recovered
-                            //EventCodeTmp[0]=1;
-                            log_info("Recovery Info Code = %s\n", EventCodeTmp);
-                            ShmStatusCodeData->InfoCode.PreviousInfoVal[ByteCount] &= ~(1 << BitCount);
-                            RemoveFaultCodeToBuf(EventCodeTmp);
-                            EventCodeTmp[0] = '1';//DS60-120 add
-                        } else {
-                            log_info("Info Code = %s\n", EventCodeTmp);
-                            ShmStatusCodeData->InfoCode.PreviousInfoVal[ByteCount] |= (1 << BitCount);
-                            AddFaultCodeToBuf(EventCodeTmp);
-                        }
-                        event_info("%s\n", EventCodeTmp); //DS60-120 add
-                        DB_Insert_Record(localDb, EventCodeTmp); //DS60-120 add
-                    }
+        for (ByteCounter = 0; ByteCounter < sizeof(pInfoCode->PreviousInfoVal); ByteCounter++) {
+            usleep(WRITE_FLASH_TIME);
+            if (pInfoCode->InfoEvents.InfoVal[ByteCounter] == pInfoCode->PreviousInfoVal[ByteCounter]) {
+                continue;
+            }
+
+            tmp = pInfoCode->InfoEvents.InfoVal[ByteCounter]; //prevent be modified during following process
+            for (BitCounter = 0; BitCounter < 8; BitCounter++) {
+                usleep(WRITE_FLASH_TIME);
+                if (((tmp >> BitCounter) & 0x01) == ((pInfoCode->PreviousInfoVal[ByteCounter] >> BitCounter) & 0x01)) {
+                    continue;
+                }
+
+                memset(EventCodeTmp, 0, sizeof(EventCodeTmp));
+                memcpy(EventCodeTmp, GetInfoStatusCode(ByteCounter * 8 + BitCounter), sizeof(EventCodeTmp) - 1);
+                if (((tmp >> BitCounter) & 0x01) == 0) { //Recovered
+                    //EventCodeTmp[0]=1;
+                    log_info("Recovery Info Code = %s\n", EventCodeTmp);
+                    pInfoCode->PreviousInfoVal[ByteCounter] &= ~(1 << BitCounter);
+                    RemoveFaultCodeToBuf(EventCodeTmp);
+                    EventCodeTmp[0] = '1';//DS60-120 add
+                } else {
+                    log_info("Info Code = %s\n", EventCodeTmp);
+                    pInfoCode->PreviousInfoVal[ByteCounter] |= (1 << BitCounter);
+                    AddFaultCodeToBuf(EventCodeTmp);
                 }
+                event_info("%s\n", EventCodeTmp); //DS60-120 add
+                InsertEventRecord(EventCodeTmp); //DS60-120 add
             }
         }
         usleep(500000);

+ 13 - 4
EVSE/Projects/DD360/Apps/ModuleInternalComm/internalComm.c

@@ -994,9 +994,18 @@ int Config_CSU_Mode(uint8_t fd, uint8_t targetAddr)
 int Config_Led_Color(uint8_t fd, uint8_t targetAddr, Led_Color *Ret_Buf)
 {
     int result = FAIL;
-    uint8_t tx[13] = {0xaa, 0x00, targetAddr, CMD_CONFIG_LEN_COLOR, 0x06, 0x00,
-                      Ret_Buf->Connect_1_Red, Ret_Buf->Connect_1_Green, Ret_Buf->Connect_1_Blue,
-                      Ret_Buf->Connect_2_Red, Ret_Buf->Connect_2_Green, Ret_Buf->Connect_2_Blue
+    uint8_t tx[13] = {0xaa,
+                      0x00,
+                      targetAddr,
+                      CMD_CONFIG_LEN_COLOR,
+                      0x06,
+                      0x00,
+                      Ret_Buf->Connect_1_Red,
+                      Ret_Buf->Connect_1_Green,
+                      Ret_Buf->Connect_1_Blue,
+                      Ret_Buf->Connect_2_Red,
+                      Ret_Buf->Connect_2_Green,
+                      Ret_Buf->Connect_2_Blue
                      };
     uint8_t rx[512];
     uint8_t chksum = 0x00;
@@ -1004,7 +1013,7 @@ int Config_Led_Color(uint8_t fd, uint8_t targetAddr, Led_Color *Ret_Buf)
     for (int idx = 0; idx < (tx[4] | tx[5] << 8); idx++) {
         chksum ^= tx[6 + idx];
     }
-    tx[13] = chksum;
+    tx[12] = chksum;
 
 //  for(int i = 0; i < 13; i++)
 //          printf ("tx = %x \n", tx[i]);

A diferenza do arquivo foi suprimida porque é demasiado grande
+ 413 - 187
EVSE/Projects/DD360/Apps/ModuleLcmCtrl/Module_LcmControl.c


+ 19 - 238
EVSE/Projects/DD360/Apps/ModuleLcmCtrl/Module_LcmControl.h

@@ -1,59 +1,27 @@
-#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>
+#ifndef MODULE_LCM_CTRL_H_
+#define MODULE_LCM_CTRL_H_
 
-#include <unistd.h>
-#include <stdarg.h>
-#include <stdio.h>      /*標準輸入輸出定義*/
-#include <stdlib.h>     /*標準函數庫定義*/
-#include <unistd.h>     /*Unix 標準函數定義*/
-#include <fcntl.h>      /*檔控制定義*/
-#include <termios.h>    /*PPSIX 終端控制定義*/
-#include <errno.h>      /*錯誤號定義*/
-#include <errno.h>
-#include <string.h>
-#include <time.h>
-#include <ctype.h>
-#include <ifaddrs.h>
-#include <stdbool.h>
-#include "../Define/define.h"
-#include "../Config.h"
+//------------------------------------------------------------------------------
+#define DEFAULT_AC_INDEX                        (2)
 
-struct SysConfigAndInfo         *ShmSysConfigAndInfo;
-struct StatusCodeData           *ShmStatusCodeData;
-struct FanModuleData            *ShmFanModuleData;
-struct PrimaryMcuData           *ShmPrimaryMcuData;
+#define TIME_MAX_SEC                            (2592000) // 一個月,秒數
+#define POWER_MAX_KW                            (5000)
+#define ENERGY_MAX_KWH                          (5000)
 
-#define DEFAULT_AC_INDEX        2
+#define CMD_TITLE_1                             (0x5A)
+#define CMD_TITLE_2                             (0xA5)
+#define CMD_READ                                (0x80)
+#define CMD_WRITE                               (0x81)
+#define CMD_MULTI_WRITE                         (0x82)
+#define CMD_MULTI_READ                          (0x83)
 
-#define TIME_MAX_SEC            2592000 // 一個月,秒數
-#define POWER_MAX_KW            5000
-#define ENERGY_MAX_KWH          5000
+#define CMD_BACKLIGHT                           (0x01)
+#define CMD_REGISTER                            (0x03)
 
-#define CMD_TITLE_1             0x5A
-#define CMD_TITLE_2             0xA5
-#define CMD_READ                0x80
-#define CMD_WRITE               0x81
-#define CMD_MULTI_WRITE         0x82
-#define CMD_MULTI_READ          0x83
-
-#define CMD_BACKLIGHT           0x01
-#define CMD_REGISTER            0x03
-
-//#define NOODOE_QR_CODE_URL      "https://ev-alpha-test.noodoe.com/station?id=" ////For Audi
-#define NOODOE_QR_CODE_URL      "https://ev.noodoe.com/station?id=" ////For Audi
+//#define NOODOE_QR_CODE_URL                    "https://ev-alpha-test.noodoe.com/station?id=" ////For Audi
+#define NOODOE_QR_CODE_URL                      "https://ev.noodoe.com/station?id=" ////For Audi
 
+//------------------------------------------------------------------------------
 enum _BATTERY_LEVEL_FOR_MAP {
     _BATTERY_LEVEL_FOR_MAP_EMP = 0x00,
     _BATTERY_LEVEL_FOR_MAP_LV1 = 0x01,
@@ -63,191 +31,4 @@ enum _BATTERY_LEVEL_FOR_MAP {
     _BATTERY_LEVEL_FOR_MAP_LV5 = 0x05,
 };
 
-int _port;
-//char* pPortName         = "/dev/ttyO2";
-char *pPortName           = "/dev/ttyS3";
-char *moduleName          = "DMT80480T070_09WT";
-uint8_t _totalCount;
-uint8_t acgunCount;
-struct ChargingInfoData *_chargingInfoData[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
-struct ChargingInfoData *ac_chargingInfo[AC_QUANTITY];
-
-uint8_t ac_ani_battery_level = _BATTERY_LEVEL_FOR_MAP_LV5;
-uint8_t isDiffStatus         = false;
-uint8_t isChangeBattMap      = false;
-// 當前選擇的槍號
-#if defined DD360Audi
-short _currentPage        = _LCM_SELECT_GUN;
-short _oldPage            = _LCM_SELECT_GUN;
-#else
-short _currentPage        = _LCM_NONE;
-short _oldPage            = _LCM_NONE;
-#endif //defined DD360Audi
-uint8_t _gunIndex            = 0;
-bool _wifi_conn_status    = false;
-bool _battery_display_ani = false;
-uint8_t _curPage_index       = 0;
-bool _page_reload         = false;
-
-// LCM - HW
-uint8_t _everyPageRollChange    = 0;
-short __conn_status          = 0x0030;
-short __ethernet_status      = 0x0032;
-short __3G4G_status          = 0x0036;
-short __3G4G_status1         = 0x0037;
-short __3G4G_move_status     = 0x0038;
-short __wifi_status          = 0x003C;
-
-short __sel_gun_btn          = 0x0040;
-short __ret_home_btn         = 0x0042;
-short __stop_method_btn      = 0x0044;
-
-short __qr_code              = 0x0250;
-short __main_rfid            = 0x0052;
-short __main_qr              = 0x0054;
-short __main_app             = 0x0056;
-
-short __plug_in_arrow        = 0x0060;
-
-short __conn_line            = 0x0066;
-
-short __gun_type_index       = 0x0070;
-short __cmp_gun_type_index   = 0x0080; ////For Audi
-short __batt_map_empty       = 0x0090; ////For Audi
-short __qr_code_pre          = 0x0280;
-
-short __side_top             = 0x0090;
-short __side_down            = 0x0092;
-short __side_mid             = 0x0094;
-
-short __conn_line_chag       = 0x0096;
-short __batt_map             = 0x0100;
-short __soc_value_charging   = 0x0102;
-short __remain_time_map      = 0x0106;
-short __power_map            = 0x0108;
-short __energy_map           = 0x010A;
-short __remain_time_tx       = 0x0110;
-
-short __trp_remain_time_map = 0x0116;
-short __trp_power_map = 0x0118;
-short __trp_energy_map = 0x011A;
-
-short __output_eng_tx        = 0x0120;
-short __total_out_eng_tx     = 0x0130;
-short __conn_line_comp       = 0x0140;
-short __charging_fee_map     = 0x0146;
-short __charging_fee_tx      = 0x0150;
-
-short __money_by_rate        = 0x0200;
-short __money_rate           = 0x0220;
-short __money_rate_map       = 0x0230;
-
-//DS60-120 add
-short __csu_ver_string = 0x0300;
-short __csu_ver_value = 0x0310;
-short __fan_speed_string = 0x0390;
-short __fan_speed_value = 0x0400;
-
-short __dc1_ver_string = 0x0320;
-short __dc1_ver_value = 0x0330;
-short __dc2_ver_string = 0x0340;
-short __dc2_ver_value = 0x0350;
-short __eth0_ip_string = 0x0360;
-short __eth0_ip_value = 0x0370;
-short __sn_string = 0x0410;
-short __sn_value = 0x0420;
-
-//For Audi, for select gun
-short __left_gun_map         = 0x0260;
-short __right_gun_map        = 0x0262;
-short __add_chk_btn          = 0x0264;
-//short __station_id         = 0x0270;
-short __balance              = 0x0270;
-short __remain_balance       = 0x0280;
-short __custStationIdL1      = 0x0450;
-//short __custStationIdL2      = 0x0470;
-short _emergency_map         = 0x011C;
-
-// ICON ID
-uint8_t _disappear              = 0;
-uint8_t _disconnect             = 1;
-uint8_t _connect                = 2;
-uint8_t _warning                = 3;
-uint8_t _arrow_dark             = 4;
-uint8_t _arrow_light            = 5;
-uint8_t _3G4G_disconnect        = 6;
-uint8_t __3G4G_connect          = 7;
-uint8_t _wifi_disconnect        = 8;
-uint8_t _wifi_connect           = 9;
-uint8_t _logo                   = 10;
-uint8_t _conn_map1              = 11;
-uint8_t _conn_map2              = 12;
-uint8_t _sel_gun_btn            = 13;
-uint8_t _back_home_btn          = 14;
-uint8_t _stop_charging_btn      = 15;
-uint8_t _stop_charging_btn_scan = 16;
-uint8_t _chademo_dark           = 17;
-uint8_t _ccs_dark               = 18;
-uint8_t _gbt_dark               = 19;
-uint8_t _actype_dark            = 20;
-uint8_t _chademo_light          = 21;
-uint8_t _ccs_light              = 22;
-uint8_t _gbt_light              = 23;
-uint8_t _actype_light           = 24;
-uint8_t _main_none_rfid         = 25;
-uint8_t _main_rfid              = 26;
-uint8_t _main_none_app          = 27;
-uint8_t _main_app               = 28;
-uint8_t _main_none_qr           = 29;
-uint8_t _main_qr                = 30;
-uint8_t _charging_map1          = 31;
-uint8_t _charging_map2          = 32;
-uint8_t _battery_empty          = 33;
-uint8_t _battery_cap_20         = 34;
-uint8_t _battery_cap_40         = 35;
-uint8_t _battery_cap_60         = 36;
-uint8_t _battery_cap_80         = 37;
-uint8_t _battery_cap_100        = 38;
-uint8_t _battery_map            = 39;
-uint8_t _power_map              = 40;
-uint8_t _time_map               = 41;
-uint8_t _complete_map           = 42;
-uint8_t _battery_soc_20         = 43;
-uint8_t _battery_soc_40         = 44;
-uint8_t _battery_soc_60         = 45;
-uint8_t _battery_soc_80         = 46;
-uint8_t _battery_soc_100        = 47;
-uint8_t _battery_eng_map        = 48;
-uint8_t _money_map              = 49;
-uint8_t _elapse_time_map        = 50;
-uint8_t _charging_money         = 51;
-//uint8_t _side_none_rfid       = 52;
-//uint8_t _side_rfid            = 53;
-//uint8_t _side_none_app        = 54;
-//uint8_t _side_app             = 55;
-//uint8_t _side_none_qr         = 56;
-//uint8_t _side_qr              = 57;
-uint8_t _eth_disconnect         = 52; //58;
-uint8_t _eth_connect            = 53; //59;
-
-uint8_t _chademo_dark_cmp       = 54;
-uint8_t _ccs_dark_cmp           = 55;
-uint8_t _gbt_dark_cmp           = 56;
-uint8_t _actype_dark_cmp        = 57;
-uint8_t _chademo_light_cmp      = 58;
-uint8_t _ccs_light_cmp          = 59;
-uint8_t _gbt_light_cmp          = 60;
-uint8_t _actype_light_cmp       = 61;
-
-uint8_t _logo_cmp = 62;
-uint8_t _battery_eng_trp_map = 63;
-uint8_t _money_trp_map = 64;
-uint8_t _elapse_time_trp_map = 65;
-
-////For Audi
-uint8_t _left_gun_disable_map   = 66;
-uint8_t _left_gun_enable_map    = 67;
-uint8_t _right_gun_disable_map  = 68;
-uint8_t _right_gun_enable_map   = 69;
-uint8_t _select_gun_btn         = 70;
-uint8_t _emergency_disable_map  = 72;
+#endif //MODULE_LCM_CTRL_H_

+ 191 - 173
EVSE/Projects/DD360/Apps/ModulePrimary/Module_PrimaryComm.c

@@ -29,22 +29,29 @@
 #include <ifaddrs.h>
 #include <math.h>
 
+#include "../Log/log.h"
 #include "../Define/define.h"
 #include "../Config.h"
+#include "../ShareMemory/shmMem.h"
 #include "PrimaryComm.h"
 #include "Module_PrimaryComm.h"
 
-struct SysConfigAndInfo *ShmSysConfigAndInfo;
-struct StatusCodeData *ShmStatusCodeData;
-struct PrimaryMcuData *ShmPrimaryMcuData;
+//------------------------------------------------------------------------------
+//struct SysConfigAndInfo *ShmSysConfigAndInfo;
+//struct StatusCodeData *ShmStatusCodeData;
+static struct SysConfigData *pSysConfig = NULL;
+static struct SysInfoData *pSysInfo = NULL;
+static struct AlarmCodeData *pAlarmCode = NULL;
+static struct FaultCodeData *pFaultCode = NULL;
+static struct PrimaryMcuData *ShmPrimaryMcuData;
 
 const char *priPortName = "/dev/ttyS1";
 uint8_t gun_count; //DS60-120 add
 
-struct ChargingInfoData *ChargingData[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
+//struct ChargingInfoData *ChargingData[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
 
 //------------------------------------------------------------------------------
-int StoreLogMsg(const char *fmt, ...)
+/*int StoreLogMsg(const char *fmt, ...)
 {
     char Buf[4096 + 256];
     char buffer[4096];
@@ -61,7 +68,7 @@ int StoreLogMsg(const char *fmt, ...)
     SeqEndTime.time = time(NULL);
     tm = localtime(&SeqEndTime.time);
 
-    if (ShmSysConfigAndInfo->SysConfig.SwitchDebugFlag == YES) {
+    if (pSysConfig->SwitchDebugFlag == YES) {
         sprintf(Buf, "%02d:%02d:%02d:%03d - %s",
                 tm->tm_hour, tm->tm_min, tm->tm_sec, SeqEndTime.millitm, buffer);
         printf("%s \n", Buf);
@@ -75,7 +82,9 @@ int StoreLogMsg(const char *fmt, ...)
 
     return rc;
 }
+*/
 
+#if 0 //non use
 int DiffTimeb(struct timeb ST, struct timeb ET)
 {
     //return milli-second
@@ -97,15 +106,22 @@ char *getTimeString(void)
     time(&timep);
     p = gmtime(&timep);
 
-    sprintf(result, "[%04d-%02d-%02d %02d:%02d:%02d]", (1900 + p->tm_year), (1 + p->tm_mon), p->tm_mday, p->tm_hour, p->tm_hour, p->tm_sec);
+    sprintf(result, "[%04d-%02d-%02d %02d:%02d:%02d]",
+            (1900 + p->tm_year),
+            (1 + p->tm_mon),
+            p->tm_mday,
+            p->tm_hour,
+            p->tm_hour,
+            p->tm_sec);
 
     return result;
 }
+#endif //0
 
 //==========================================
 // Init all share memory
 //==========================================
-int InitShareMemory()
+/*int InitShareMemory()
 {
     int result = PASS;
     int MeterSMId;
@@ -133,6 +149,7 @@ int InitShareMemory()
 
     return result;
 }
+*/
 
 //================================================
 // Function
@@ -144,7 +161,7 @@ void GetFwAndHwVersion(int fd)
     if (Query_FW_Ver(fd, OP_ADDR_IO_EXTEND, &ver) == PASS) {
         //log_info("Primary FW Rev = %s \n", ver.Version_FW);
         strcpy((char *)ShmPrimaryMcuData->version, ver.Version_FW);
-        strcpy((char *) ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev, ver.Version_FW);
+        strcpy((char *) pSysInfo->CsuPrimFwRev, ver.Version_FW);
     }
 
     //if (Query_HW_Ver(fd, OP_ADDR_IO_EXTEND, &ver) == PASS)
@@ -158,113 +175,110 @@ void GetInputGpioStatus(int fd)
     static uint8_t dispenserSw = 0;
 
     //log_info("GetInputGpioStatus \n");
-    if (Query_Gpio_Input(fd, OP_ADDR_IO_EXTEND, &gpio_in) == PASS) {
-#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
-        static uint8_t _curDeviceStatus[3] = {0};
-        static uint8_t _reCheckCount[3] = {0};
-
-        //DS60-120 add
-        if (_curDeviceStatus[_PRIMARY_CHECK_TAG_AC_CONTACT] != gpio_in.AC_Connector) {
-            if (_reCheckCount[_PRIMARY_CHECK_TAG_AC_CONTACT] >= 3) {
-                _curDeviceStatus[_PRIMARY_CHECK_TAG_AC_CONTACT] = gpio_in.AC_Connector;
-                ShmSysConfigAndInfo->SysInfo.AcContactorStatus =
-                    ShmPrimaryMcuData->InputDet.bits.AcContactorDetec =
-                        gpio_in.AC_Connector;
-            } else {
-                _reCheckCount[_PRIMARY_CHECK_TAG_AC_CONTACT]++;
-            }
-        } else {
-            _reCheckCount[_PRIMARY_CHECK_TAG_AC_CONTACT] = 0;
-        }
-
-        if (_curDeviceStatus[_PRIMARY_CHECK_TAG_MAIN_BREAKER] != gpio_in.AC_MainBreaker) {
-            if (_reCheckCount[_PRIMARY_CHECK_TAG_MAIN_BREAKER] >= 3) {
-                _curDeviceStatus[_PRIMARY_CHECK_TAG_MAIN_BREAKER] = gpio_in.AC_MainBreaker;
-                ShmPrimaryMcuData->InputDet.bits.AcMainBreakerDetec = gpio_in.AC_MainBreaker;
-            } else {
-                _reCheckCount[_PRIMARY_CHECK_TAG_MAIN_BREAKER]++;
-            }
-        } else {
-            _reCheckCount[_PRIMARY_CHECK_TAG_MAIN_BREAKER] = 0;
-        }
-        //ShmSysConfigAndInfo->SysInfo.AcContactorStatus = ShmPrimaryMcuData->InputDet.bits.AcContactorDetec = gpio_in.AC_Connector;
-        //ShmPrimaryMcuData->InputDet.bits.AcMainBreakerDetec = gpio_in.AC_MainBreaker;
-#else
-        if ((strncmp((char *)&ShmSysConfigAndInfo->SysConfig.ModelName[7], "V", 1) == 0) ||
-                (strncmp((char *)&ShmSysConfigAndInfo->SysConfig.ModelName[9], "V", 1) == 0) ||
-                (strncmp((char *)&ShmSysConfigAndInfo->SysConfig.ModelName[7], "F", 1) == 0) ||
-                (strncmp((char *)&ShmSysConfigAndInfo->SysConfig.ModelName[9], "F", 1) == 0)
-           ) {
-            ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsLiquidChillerWaterLevelWarning = ~gpio_in.AC_Connector;
-            ShmStatusCodeData->FaultCode.FaultEvents.bits.CcsLiquidChillerWaterLevelFault = ~gpio_in.AC_MainBreaker;
-        } else {
-            ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsLiquidChillerWaterLevelWarning = gpio_in.AC_Connector;
-            ShmStatusCodeData->FaultCode.FaultEvents.bits.CcsLiquidChillerWaterLevelFault = gpio_in.AC_MainBreaker;
-        }
-#endif //!defined DD360 && !defined DD360Audi
+    if (Query_Gpio_Input(fd, OP_ADDR_IO_EXTEND, &gpio_in) != PASS) {
+        return;
+    }
 
-        ShmPrimaryMcuData->InputDet.bits.SpdDetec = gpio_in.SPD;
-#if defined DD360 ||defined DD360Audi || defined DD360ComBox
+    ShmPrimaryMcuData->InputDet.bits.SpdDetec = gpio_in.SPD;
 
 #if defined DD360ComBox
-        ShmPrimaryMcuData->InputDet.bits.DoorOpen = gpio_in.Door_Open;
-#else
-        ShmPrimaryMcuData->InputDet.bits.DoorOpen = ~gpio_in.Door_Open;
-#endif //
-
-        ShmPrimaryMcuData->InputDet.bits.Key0 = ~gpio_in.Key[0] & 0x01;
-        ShmPrimaryMcuData->InputDet.bits.Key1 = ~gpio_in.Key[1] & 0x01;
-        ShmPrimaryMcuData->InputDet.bits.Key2 = ~gpio_in.Key[2] & 0x01;
-        ShmPrimaryMcuData->InputDet.bits.Key3 = ~gpio_in.Key[3] & 0x01;
-        //ShmPrimaryMcuData->InputDet.bits.EmergencyButton = gpio_in.Emergency_Btn;
+    ShmPrimaryMcuData->InputDet.bits.EmergencyButton = ~gpio_in.Emergency_Btn;
 #else
+    ShmPrimaryMcuData->InputDet.bits.EmergencyButton = gpio_in.Emergency_Btn;
+#endif //defined DD360ComBox
+
+    dispenserSwTmp |= (ShmPrimaryMcuData->InputDet.bits.Key0);
+    dispenserSwTmp |= (ShmPrimaryMcuData->InputDet.bits.Key1 << 1);
+    dispenserSwTmp |= (ShmPrimaryMcuData->InputDet.bits.Key2 << 2);
+    dispenserSwTmp |= (ShmPrimaryMcuData->InputDet.bits.Key3 << 3);
+
+    if (dispenserSwTmp != dispenserSw) {
+        dispenserSw = dispenserSwTmp;
+        log_info("Dispenser switch number =  %d, bit = %d, %d, %d, %d\r\n",
+                 dispenserSw,
+                 ShmPrimaryMcuData->InputDet.bits.Key3,
+                 ShmPrimaryMcuData->InputDet.bits.Key2,
+                 ShmPrimaryMcuData->InputDet.bits.Key1,
+                 ShmPrimaryMcuData->InputDet.bits.Key0);
+    }
 
-        ShmPrimaryMcuData->InputDet.bits.Key0 = gpio_in.Key[0] & 0x01;
-        ShmPrimaryMcuData->InputDet.bits.Key1 = gpio_in.Key[1] & 0x01;
-        ShmPrimaryMcuData->InputDet.bits.Key2 = gpio_in.Key[2] & 0x01;
-        ShmPrimaryMcuData->InputDet.bits.Key3 = gpio_in.Key[3] & 0x01;
-        //ShmPrimaryMcuData->InputDet.bits.EmergencyButton = ~gpio_in.Emergency_Btn;
-        ShmPrimaryMcuData->InputDet.bits.DoorOpen = gpio_in.Door_Open;
-#endif //defined DD360 ||defined DD360Audi
+    ShmPrimaryMcuData->InputDet.bits.Button1 = gpio_in.Button[0];
+    ShmPrimaryMcuData->InputDet.bits.Button2 = gpio_in.Button[1];
+
+#if defined DD360 || defined DD360Audi || defined DD360ComBox
+    if ((strncmp((char *)&pSysConfig->ModelName[7], "V", 1) == 0) ||
+            (strncmp((char *)&pSysConfig->ModelName[9], "V", 1) == 0) ||
+            (strncmp((char *)&pSysConfig->ModelName[7], "F", 1) == 0) ||
+            (strncmp((char *)&pSysConfig->ModelName[9], "F", 1) == 0)
+       ) {
+        pAlarmCode->AlarmEvents.bits.CcsLiquidChillerWaterLevelWarning = ~gpio_in.AC_Connector;
+        pFaultCode->FaultEvents.bits.CcsLiquidChillerWaterLevelFault = ~gpio_in.AC_MainBreaker;
+    } else {
+        pAlarmCode->AlarmEvents.bits.CcsLiquidChillerWaterLevelWarning = gpio_in.AC_Connector;
+        pFaultCode->FaultEvents.bits.CcsLiquidChillerWaterLevelFault = gpio_in.AC_MainBreaker;
+    }
 
 #if defined DD360ComBox
-        ShmPrimaryMcuData->InputDet.bits.EmergencyButton = ~gpio_in.Emergency_Btn;
+    ShmPrimaryMcuData->InputDet.bits.DoorOpen = gpio_in.Door_Open;
 #else
-        ShmPrimaryMcuData->InputDet.bits.EmergencyButton = gpio_in.Emergency_Btn;
-#endif //
-
-        dispenserSwTmp |= (ShmPrimaryMcuData->InputDet.bits.Key0);
-        dispenserSwTmp |= (ShmPrimaryMcuData->InputDet.bits.Key1 << 1);
-        dispenserSwTmp |= (ShmPrimaryMcuData->InputDet.bits.Key2 << 2);
-        dispenserSwTmp |= (ShmPrimaryMcuData->InputDet.bits.Key3 << 3);
-
-        if (dispenserSwTmp != dispenserSw) {
-            dispenserSw = dispenserSwTmp;
-            log_info("Dispenser switch number =  %d, bit = %d, %d, %d, %d\r\n",
-                     dispenserSw,
-                     ShmPrimaryMcuData->InputDet.bits.Key3,
-                     ShmPrimaryMcuData->InputDet.bits.Key2,
-                     ShmPrimaryMcuData->InputDet.bits.Key1,
-                     ShmPrimaryMcuData->InputDet.bits.Key0);
+    ShmPrimaryMcuData->InputDet.bits.DoorOpen = ~gpio_in.Door_Open;
+#endif //defined DD360ComBox
+
+    ShmPrimaryMcuData->InputDet.bits.Key0 = ~gpio_in.Key[0] & 0x01;
+    ShmPrimaryMcuData->InputDet.bits.Key1 = ~gpio_in.Key[1] & 0x01;
+    ShmPrimaryMcuData->InputDet.bits.Key2 = ~gpio_in.Key[2] & 0x01;
+    ShmPrimaryMcuData->InputDet.bits.Key3 = ~gpio_in.Key[3] & 0x01;
+
+    return;
+#endif //defined DD360 || defined DD360Audi || defined DD360ComBox
+
+    static uint8_t _curDeviceStatus[3] = {0};
+    static uint8_t _reCheckCount[3] = {0};
+
+    //DS60-120 add
+    if (_curDeviceStatus[_PRIMARY_CHECK_TAG_AC_CONTACT] != gpio_in.AC_Connector) {
+        if (_reCheckCount[_PRIMARY_CHECK_TAG_AC_CONTACT] >= 3) {
+            _curDeviceStatus[_PRIMARY_CHECK_TAG_AC_CONTACT] = gpio_in.AC_Connector;
+            pSysInfo->AcContactorStatus =
+                ShmPrimaryMcuData->InputDet.bits.AcContactorDetec =
+                    gpio_in.AC_Connector;
+        } else {
+            _reCheckCount[_PRIMARY_CHECK_TAG_AC_CONTACT]++;
         }
+    } else {
+        _reCheckCount[_PRIMARY_CHECK_TAG_AC_CONTACT] = 0;
+    }
 
-        ShmPrimaryMcuData->InputDet.bits.Button1 = gpio_in.Button[0];
-        ShmPrimaryMcuData->InputDet.bits.Button2 = gpio_in.Button[1];
-
-        /*printf(" gpio_in.Key[0]~ gpio_in.Key[3]=%d, %d, %d, %d\n",
-        ShmPrimaryMcuData->InputDet.bits.Key0 , ShmPrimaryMcuData->InputDet.bits.Key1,
-        ShmPrimaryMcuData->InputDet.bits.Key2,ShmPrimaryMcuData->InputDet.bits.Key3);
-        printf("ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsLiquidChillerWaterLevelWarning=%d\n", ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsLiquidChillerWaterLevelWarning);
-        printf("ShmStatusCodeData->FaultCode.FaultEvents.bits.CcsLiquidChillerWaterLevelFault=%d\n", ShmStatusCodeData->FaultCode.FaultEvents.bits.CcsLiquidChillerWaterLevelFault);
-        */
-        //log_info("left = %d \n", ShmPrimaryMcuData->InputDet.bits.Button1);
-        //log_info("right = %d \n", ShmPrimaryMcuData->InputDet.bits.Button2);
-        //log_info("ShmSysConfigAndInfo->SysInfo.AcContactorStatus = %d \n", ShmSysConfigAndInfo->SysInfo.AcContactorStatus);
-#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
-        if (ShmPrimaryMcuData->InputDet.bits.AcMainBreakerDetec == YES) {
-            log_error("AC Mainbreaker occur. \n");
+    if (_curDeviceStatus[_PRIMARY_CHECK_TAG_MAIN_BREAKER] != gpio_in.AC_MainBreaker) {
+        if (_reCheckCount[_PRIMARY_CHECK_TAG_MAIN_BREAKER] >= 3) {
+            _curDeviceStatus[_PRIMARY_CHECK_TAG_MAIN_BREAKER] = gpio_in.AC_MainBreaker;
+            ShmPrimaryMcuData->InputDet.bits.AcMainBreakerDetec = gpio_in.AC_MainBreaker;
+        } else {
+            _reCheckCount[_PRIMARY_CHECK_TAG_MAIN_BREAKER]++;
         }
-#endif //!defined DD360 && !defined DD360Audi
+    } else {
+        _reCheckCount[_PRIMARY_CHECK_TAG_MAIN_BREAKER] = 0;
+    }
+    //pSysInfo->AcContactorStatus = ShmPrimaryMcuData->InputDet.bits.AcContactorDetec = gpio_in.AC_Connector;
+    //ShmPrimaryMcuData->InputDet.bits.AcMainBreakerDetec = gpio_in.AC_MainBreaker;
+
+    ShmPrimaryMcuData->InputDet.bits.Key0 = gpio_in.Key[0] & 0x01;
+    ShmPrimaryMcuData->InputDet.bits.Key1 = gpio_in.Key[1] & 0x01;
+    ShmPrimaryMcuData->InputDet.bits.Key2 = gpio_in.Key[2] & 0x01;
+    ShmPrimaryMcuData->InputDet.bits.Key3 = gpio_in.Key[3] & 0x01;
+    ShmPrimaryMcuData->InputDet.bits.DoorOpen = gpio_in.Door_Open;
+
+    /*printf(" gpio_in.Key[0]~ gpio_in.Key[3]=%d, %d, %d, %d\n",
+    ShmPrimaryMcuData->InputDet.bits.Key0 , ShmPrimaryMcuData->InputDet.bits.Key1,
+    ShmPrimaryMcuData->InputDet.bits.Key2,ShmPrimaryMcuData->InputDet.bits.Key3);
+    printf("pAlarmCode->AlarmEvents.bits.CcsLiquidChillerWaterLevelWarning=%d\n", pAlarmCode->AlarmEvents.bits.CcsLiquidChillerWaterLevelWarning);
+    printf("pFaultCode->FaultEvents.bits.CcsLiquidChillerWaterLevelFault=%d\n", pFaultCode->FaultEvents.bits.CcsLiquidChillerWaterLevelFault);
+    */
+    //log_info("left = %d \n", ShmPrimaryMcuData->InputDet.bits.Button1);
+    //log_info("right = %d \n", ShmPrimaryMcuData->InputDet.bits.Button2);
+    //log_info("pSysInfo->AcContactorStatus = %d \n", pSysInfo->AcContactorStatus);
+    if (ShmPrimaryMcuData->InputDet.bits.AcMainBreakerDetec == YES) {
+        log_error("AC Mainbreaker occur. \n");
     }
 }
 
@@ -276,13 +290,13 @@ static void checkChillerStatus(Gpio_out *gpio)
     static ChillerInfo fChillerInfo[2] = {0}, *pChillerInfo = NULL;
     Gpio_out *pGpio = (Gpio_out *)gpio;
 
-    if ((strncmp((char *)&ShmSysConfigAndInfo->SysConfig.ModelName[7], "V", 1) == 0) ||
-            (strncmp((char *)&ShmSysConfigAndInfo->SysConfig.ModelName[7], "F", 1) == 0)) {
+    if ((strncmp((char *)&pSysConfig->ModelName[7], "V", 1) == 0) ||
+            (strncmp((char *)&pSysConfig->ModelName[7], "F", 1) == 0)) {
         chillerCount++;
     }
 
-    if ((strncmp((char *)&ShmSysConfigAndInfo->SysConfig.ModelName[9], "V", 1) == 0) ||
-            (strncmp((char *)&ShmSysConfigAndInfo->SysConfig.ModelName[9], "F", 1) == 0)) {
+    if ((strncmp((char *)&pSysConfig->ModelName[9], "V", 1) == 0) ||
+            (strncmp((char *)&pSysConfig->ModelName[9], "F", 1) == 0)) {
         chillerCount++;
     }
 
@@ -292,7 +306,7 @@ static void checkChillerStatus(Gpio_out *gpio)
     }
 
     for (gunIndex = 0; gunIndex < chillerCount; gunIndex++) {
-        pDcChargingInfo = (struct ChargingInfoData *)ChargingData[gunIndex];
+        pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
         pChillerInfo = (ChillerInfo *)&fChillerInfo[gunIndex];
 
         if ((pDcChargingInfo->PresentChargingCurrent) >= 150) { //當前電壓於150A,打開水冷機
@@ -325,7 +339,7 @@ void SetOutputGpio(int fd, uint8_t outputValue)
     LedConfig *pLedConfig = (LedConfig *)&outputValue;
     static uint8_t flash = NO;
 
-    if (strcmp((char *)ShmSysConfigAndInfo->SysInfo.LcmHwRev, " ") == 0x00) {
+    if (strcmp((char *)pSysInfo->LcmHwRev, " ") == 0x00) {
         if (flash == NO) {
             flash = YES;
         } else {
@@ -400,7 +414,7 @@ void SetRtcData(int fd)
 
 void SetModelName(int fd)
 {
-    if (Config_Model_Name(fd, OP_ADDR_IO_EXTEND, ShmSysConfigAndInfo->SysConfig.ModelName) == PASS) {
+    if (Config_Model_Name(fd, OP_ADDR_IO_EXTEND, pSysConfig->ModelName) == PASS) {
     }
 }
 
@@ -441,78 +455,82 @@ unsigned long GetTimeoutValue(struct timeval _sour_time)
     return 1000000 * (_end_time.tv_sec - _sour_time.tv_sec) + _end_time.tv_usec - _sour_time.tv_usec;
 }
 
-int FindChargingInfoData(uint8_t target, struct ChargingInfoData **chargingData)
-{
-    for (uint8_t index = 0; index < CHAdeMO_QUANTITY; index++) {
-        if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == target) {
-            chargingData[target] = &ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index];
-            return 1;
-        }
-    }
-
-    for (uint8_t index = 0; index < CCS_QUANTITY; index++) {
-        if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == target) {
-            chargingData[target] = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[index];
-            return 1;
-        }
-    }
-
-    for (uint8_t index = 0; index < GB_QUANTITY; index++) {
-        if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == target) {
-            chargingData[target] = &ShmSysConfigAndInfo->SysInfo.GbChargingData[index];
-            return 1;
-        }
-    }
-
-    return 0;
-}
-
-void Initialization() //DS60-120 add
-{
-    bool isPass = false;
-    while (!isPass) {
-        isPass = true;
-        for (uint8_t _index = 0; _index < gun_count; _index++) {
-            if (!FindChargingInfoData(_index, &ChargingData[0])) {
-                log_error("EvComm (main) : FindChargingInfoData false \n");
-                isPass = false;
-                break;
-            }
-        }
-        sleep(1);
-    }
-}
+//int FindChargingInfoData(uint8_t target, struct ChargingInfoData **chargingData)
+//{
+//    for (uint8_t index = 0; index < CHAdeMO_QUANTITY; index++) {
+//        if (pSysInfo->ChademoChargingData[index].Index == target) {
+//            chargingData[target] = &pSysInfo->ChademoChargingData[index];
+//            return 1;
+//        }
+//    }
+//
+//    for (uint8_t index = 0; index < CCS_QUANTITY; index++) {
+//        if (pSysInfo->CcsChargingData[index].Index == target) {
+//            chargingData[target] = &pSysInfo->CcsChargingData[index];
+//            return 1;
+//        }
+//    }
+//
+//    for (uint8_t index = 0; index < GB_QUANTITY; index++) {
+//        if (pSysInfo->GbChargingData[index].Index == target) {
+//            chargingData[target] = &pSysInfo->GbChargingData[index];
+//            return 1;
+//        }
+//    }
+//
+//    return 0;
+//}
+
+//void Initialization() //DS60-120 add
+//{
+//    bool isPass = false;
+//    while (!isPass) {
+//        isPass = true;
+//        for (uint8_t _index = 0; _index < gun_count; _index++) {
+//            if (!FindChargingInfoData(_index, &ChargingData[0])) {
+//                log_error("EvComm (main) : FindChargingInfoData false \n");
+//                isPass = false;
+//                break;
+//            }
+//        }
+//        sleep(1);
+//    }
+//}
 
 int main(void)
 {
     int Uart1Fd = -1;
 
-    if (InitShareMemory() == FAIL) {
-        log_error("InitShareMemory NG\r\n");
-        if (ShmStatusCodeData != NULL) {
-            ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory = 1;
-        }
-        sleep(5);
-        return 0;
-    }
-
-    //DS60-120 remove
-    //for (uint8_t _index = 0; _index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _index++) {
-    //    if (!FindChargingInfoData(_index, &ChargingData[0])) {
-    //        log_error("FindChargingInfoData false \n");
-    //        break;
+    //if (InitShareMemory() == FAIL) {
+    //    log_error("InitShareMemory NG\r\n");
+    //    if (ShmStatusCodeData != NULL) {
+    //        pAlarmCode->AlarmEvents.bits.FailToCreateShareMemory = 1;
     //    }
+    //    sleep(5);
+    //    return 0;
     //}
 
+    if (CreateAllCsuShareMemory() == FAIL) {
+        log_error("create share memory error\r\n");
+        return FAIL;
+    }
+
+    MappingGunChargingInfo("Primary Task");
+
+    pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
+    pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
+    pAlarmCode = (struct AlarmCodeData *)GetShmAlarmCodeData();
+    pFaultCode = (struct FaultCodeData *)GetShmFaultCodeData();
+    ShmPrimaryMcuData = (struct PrimaryMcuData *)GetShmPrimaryMcuData();
+
     Uart1Fd = InitComPort();
     //log_info("407 Port id = %d \n", Uart1Fd);
 
     if (Uart1Fd < 0) {
-#ifdef SystemLogMessage
         log_error("InitComPort (Uart1 : AM3352 - STM32) NG");
-#endif
-        if (ShmStatusCodeData != NULL) {
-            ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed = 1;
+
+        if (pAlarmCode != NULL) {
+            pAlarmCode->AlarmEvents.bits.CsuInitFailed = 1;
         }
         sleep(5);
 
@@ -522,9 +540,9 @@ int main(void)
     SetRtcData(Uart1Fd);
     SetModelName(Uart1Fd);
 
-    gun_count = ShmSysConfigAndInfo->SysConfig.TotalConnectorCount;
+    gun_count = pSysConfig->TotalConnectorCount;
 
-    Initialization();
+    //Initialization();
 
     for (;;) {
         // 程序開始之前~ 必須先確定 FW 版本與硬體版本,確認後!!~ 該模組才算是真正的 Initial Comp.

+ 4 - 4
EVSE/Projects/DD360/Apps/ModulePrimary/Module_PrimaryComm.h

@@ -5,9 +5,9 @@
 #include <stdint.h>
 
 //------------------------------------------------------------------------------
-#define log_info(format, args...) StoreLogMsg("[%s:%d][%s][Info] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
-#define log_warn(format, args...) StoreLogMsg("[%s:%d][%s][Warn] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
-#define log_error(format, args...) StoreLogMsg("[%s:%d][%s][Error] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
+//#define log_info(format, args...) StoreLogMsg("[%s:%d][%s][Info] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
+//#define log_warn(format, args...) StoreLogMsg("[%s:%d][%s][Warn] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
+//#define log_error(format, args...) StoreLogMsg("[%s:%d][%s][Error] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
 
 //------------------------------------------------------------------------------
 typedef struct StChillerInfo {
@@ -29,6 +29,6 @@ typedef struct StLedConfig {
 } LedConfig;
 
 //------------------------------------------------------------------------------
-int StoreLogMsg(const char *fmt, ...);
+//int StoreLogMsg(const char *fmt, ...);
 
 #endif /* _MODULE_PRIMARY_COMM_H_ */

+ 2 - 1
EVSE/Projects/DD360/Apps/ModulePrimary/PrimaryComm.c

@@ -27,8 +27,9 @@
 #include <ctype.h>
 #include <ifaddrs.h>
 #include <math.h>
-#include "../Config.h"
 
+#include "../Log/log.h"
+#include "../Config.h"
 #include "Module_PrimaryComm.h"
 #include "PrimaryComm.h"
 

+ 93 - 52
EVSE/Projects/DD360/Apps/ReadCmdline.c

@@ -54,6 +54,7 @@
 #define STTY_US             "stty raw -echo -F "
 #define STTY_DEF            "stty -raw echo -F "
 
+//------------------------------------------------------------------------------
 uint8_t _curAutoRunCount = 0;
 uint8_t _usingAutoRun = 0;
 struct timeval _autoTime;
@@ -80,7 +81,10 @@ char *msg = "state : get gun state (index) \n"
             "lock : get gun locked state (index) \n"
             "self : self test state (x) \n"
             "ver : ver of board (407 or index or rb or fan) \n"
-            "ac : get ac relay state (x) \n";
+            "ac : get ac relay state (x) \n"
+            "tempT : set connector header temperature\r\n"
+            "tempC : set chiller temperature\r\n"
+            "tempR : read connector header and chiller temperature\r\n";
 
 bool FindChargingInfoData(uint8_t target, struct ChargingInfoData **chargingData)
 {
@@ -1020,6 +1024,12 @@ void RunUnconditionalChargeIndex1(char *v1, char *v2, char *v3)
             _chargingData[_GunIndex]->EvBatterytargetVoltage = _vol;
             _chargingData[_GunIndex]->EvBatterytargetCurrent = _cur;
         } else if (strcmp(newString[0], "c") == 0) {
+            if (strcmp(newString[1], "-1") == 0 ||
+                    strcmp(newString[1], "") == 0) {
+                printf("argc 1 is error parameter\r\n");
+                continue;
+            }
+
             if (atoi((char *)newString[1]) != -1) {
                 ShmSysConfigAndInfo->SysInfo.CurGunSelected = atoi((char *)newString[1]);
             }
@@ -1035,6 +1045,8 @@ void RunUnconditionalChargeIndex1(char *v1, char *v2, char *v3)
 
 int main(void)
 {
+    uint8_t _GunIndex = 0;
+
     if (InitShareMemory() == FAIL) {
         printf ("InitShareMemory = FAIL \n");
         if (ShmStatusCodeData != NULL) {
@@ -1174,72 +1186,101 @@ int main(void)
             if (strcmp(newString[1], "auto") == 0) {
                 newString[2][0] = 0;
                 newString[3][0] = 0;
-            } else if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0 ||
-                       strcmp(newString[2], "-1") == 0 || strcmp(newString[2], "") == 0) {
+            } else if (strcmp(newString[1], "-1") == 0 ||
+                       strcmp(newString[1], "") == 0   ||
+                       strcmp(newString[2], "-1") == 0 ||
+                       strcmp(newString[2], "") == 0) {
                 printf ("Input cmd fail ------  strchg [vol 150-1000] [cru 2-100]\n");
                 continue;
             }
 
             // 槍狀態
             RunUnconditionalChargeIndex1(newString[1], newString[2], newString[3]);
-        } else if (strcmp(newString[0], "tempT") == 0) {
+        } else if (strcmp(newString[0], "tempT") == 0) {//修改槍頭溫度值
 
-            if (strcmp(newString[1], "0") == 0) {
-                uint8_t _GunIndex = 0;
-                if (!FindChargingInfoData(_GunIndex, &_chargingData[0])) {
-                    printf ("FindChargingInfoData error\n");
-                    return 0;
-                }
+            if (strcmp(newString[1], "-1") == 0 ||
+                    strcmp(newString[1], "") == 0) {
+                printf("argc 1 is error parameter\r\n");
+                continue;
+            }
 
-                _chargingData[0]->ConnectorTemp = atoi(newString[2]);
-                printf("ReadCmdline temp 0 = %d\r\n", _chargingData[0]->ConnectorTemp);
-            } else if (strcmp(newString[1], "1") == 0) {
-                uint8_t _GunIndex = 1;
-                if (!FindChargingInfoData(_GunIndex, &_chargingData[0])) {
-                    printf ("FindChargingInfoData error\n");
-                    return 0;
-                }
+            _GunIndex = atoi((char *)newString[1]);
 
-                _chargingData[1]->ConnectorTemp = atoi(newString[2]);
-                printf("ReadCmdline temp 1 = %d\r\n", _chargingData[1]->ConnectorTemp);
+            if (_GunIndex >= ShmSysConfigAndInfo->SysConfig.TotalConnectorCount) {
+                printf("gun index over total connector\r\n");
+                continue;
             }
-        } else if (strcmp(newString[0], "tempC") == 0) {
-            if (strcmp(newString[1], "0") == 0) {
-                uint8_t _GunIndex = 0;
-                if (!FindChargingInfoData(_GunIndex, &_chargingData[0])) {
-                    printf ("FindChargingInfoData error\n");
-                    return 0;
-                }
 
-                _chargingData[0]->ChillerTemp = atoi(newString[2]);
-                printf("ReadCmdline temp 0 = %d\r\n", _chargingData[0]->ChillerTemp);
-            } else if (strcmp(newString[1], "1") == 0) {
-                uint8_t _GunIndex = 1;
-                if (!FindChargingInfoData(_GunIndex, &_chargingData[0])) {
-                    printf ("FindChargingInfoData error\n");
-                    return 0;
-                }
+            if (!FindChargingInfoData(_GunIndex, &_chargingData[0])) {
+                printf ("FindChargingInfoData error\n");
+                return 0;
+            }
 
-                _chargingData[1]->ChillerTemp = atoi(newString[2]);
-                printf("ReadCmdline temp 1 = %d\r\n", _chargingData[1]->ChillerTemp);
+            if (atoi(newString[2]) > 255 || atoi(newString[2]) == -1) {//溫度值不會超過255
+                printf("temperature value overflow\r\n");
+                continue;
             }
-        } else if (strcmp(newString[0], "TempCR") == 0) {
-            if (strcmp(newString[1], "0") == 0) {
-                uint8_t _GunIndex = 0;
-                if (!FindChargingInfoData(_GunIndex, &_chargingData[0])) {
-                    printf ("FindChargingInfoData error\n");
-                    return 0;
-                }
-                printf("ReadCmdline temp 0 = %d\r\n", _chargingData[0]->ChillerTemp);
-            } else if (strcmp(newString[1], "1") == 0) {
-                uint8_t _GunIndex = 1;
-                if (!FindChargingInfoData(_GunIndex, &_chargingData[0])) {
-                    printf ("FindChargingInfoData error\n");
-                    return 0;
-                }
 
-                printf("ReadCmdline temp 1 = %d\r\n", _chargingData[1]->ChillerTemp);
+            _chargingData[_GunIndex]->ConnectorTemp = atoi(newString[2]);
+            printf("set %d connector temp 0 = %d\r\n",
+                   _GunIndex,
+                   _chargingData[_GunIndex]->ConnectorTemp);
+        } else if (strcmp(newString[0], "tempC") == 0) {//修改水冷機溫度值
+            if (strcmp(newString[1], "-1") == 0 ||
+                    strcmp(newString[1], "") == 0) {
+                printf("argc 1 is error parameter\r\n");
+                continue;
+            }
+
+            _GunIndex = atoi((char *)newString[1]);
+
+            if (_GunIndex >= 1) {
+                _GunIndex = 0; //只會有一個水冷機
             }
+
+            if (_GunIndex >= ShmSysConfigAndInfo->SysConfig.TotalConnectorCount) {
+                printf("gun index over total connector\r\n");
+                continue;
+            }
+
+            if (!FindChargingInfoData(_GunIndex, &_chargingData[0])) {
+                printf ("FindChargingInfoData error\n");
+                continue;
+            }
+
+            if (atoi(newString[2]) > 255 || atoi(newString[2]) == -1) {
+                printf("temperature value overflow\r\n");
+                return 0;
+            }
+
+            _chargingData[_GunIndex]->ChillerTemp = atoi(newString[2]);
+            printf("set %d chiller temperature = %d\r\n",
+                   _GunIndex,
+                   _chargingData[_GunIndex]->ChillerTemp);
+        } else if (strcmp(newString[0], "tempR") == 0) { //讀取槍頭和水冷機溫度
+
+            if (strcmp(newString[1], "-1") == 0 ||
+                    strcmp(newString[1], "") == 0) {
+                printf("argc 1 is error parameter\r\n");
+                continue;
+            }
+
+            _GunIndex = atoi((char *)newString[1]);
+
+            if (_GunIndex >= ShmSysConfigAndInfo->SysConfig.TotalConnectorCount) {
+                printf("gun index over total connector\r\n");
+                continue;
+            }
+
+            if (!FindChargingInfoData(_GunIndex, &_chargingData[0])) {
+                printf ("FindChargingInfoData error\n");
+                return 0;
+            }
+
+            printf("get %d gun temp = %d, chiller temp = %d\r\n",
+                   _GunIndex,
+                   _chargingData[_GunIndex]->ConnectorTemp,
+                   _chargingData[_GunIndex]->ChillerTemp);
         } else {
             printf ("%s\n", msg);
         }

+ 3 - 2
EVSE/Projects/DD360/Apps/Readme.md

@@ -5,5 +5,6 @@
     4. 執行DD360Audi/Apps/Script/replaceOtherDD360Project.sh
     5. 重新commit。
 
-## DD360 和 DD360ComBox 都是用DD360Audi開發和修改,完成後,執行
-   DD360Audi/Apps/Script/replaceOtherDD360Project.sh
+## 更換DD360 和 DD360ComBox project
+    DD360 和 DD360ComBox 都是用DD360Audi開發和修改,完成後,執行
+    DD360Audi/Apps/Script/replaceOtherDD360Project.sh

+ 12 - 2
EVSE/Projects/DD360/Apps/ShareMemory/shmMem.c

@@ -978,6 +978,8 @@ bool MappingGunChargingInfo(char *whichTask)
         return false;
     }
 
+    ShmDcCommonData->ChillerValve.MultiChillerGun = 0;
+
     //printf("1 CheckConnectorTypeStatus\r\n");
     for (typeIndex = 7; typeIndex <= 9; typeIndex++) {
         if (!addGunInfoByConnector(pSysConfig->ModelName[typeIndex], slots)) {
@@ -989,12 +991,20 @@ bool MappingGunChargingInfo(char *whichTask)
         if (strncmp((char *)&pSysConfig->ModelName[typeIndex], "V", 1) == 0 ||
                 strncmp((char *)&pSysConfig->ModelName[typeIndex], "F", 1) == 0
            ) {
-            ShmDcCommonData->ChillerValve.MultiChillerGun++;
-            ShmDcCommonData->ChillerValve.MultiChillerGun |= 0x80;
+            ShmDcCommonData->ChillerValve.MultiChillerGun++; //水冷槍數
         }
         slots++;
     }
 
+    if (ShmDcCommonData->ChillerValve.MultiChillerGun != 0) {
+        ShmDcCommonData->ChillerValve.MultiChillerGun |= 0x80; //有水冷槍標記
+        if (strncmp(whichTask, "CSU Task", 8) == EQUAL) {
+            log_info("get chiller gun = %x, chiller gun count = %d\r\n",
+                     (ShmDcCommonData->ChillerValve.MultiChillerGun & 0x80) >> 7,
+                     ShmDcCommonData->ChillerValve.MultiChillerGun & 0x7F);
+        }
+    }
+
     // AC index 接在 DC 後面
     //if (AC_QUANTITY > 0) {
     if (gGunIndexInfo.AcIndex > 0) { //DS60-120 add

BIN=BIN
EVSE/Projects/DD360/Images/ramdisk.gz


BIN=BIN
EVSE/Projects/DD360/output/FactoryConfig


BIN=BIN
EVSE/Projects/DD360/output/Module_DoComm


BIN=BIN
EVSE/Projects/DD360/output/Module_EvComm


BIN=BIN
EVSE/Projects/DD360/output/Module_EventLogging


BIN=BIN
EVSE/Projects/DD360/output/Module_InternalComm


BIN=BIN
EVSE/Projects/DD360/output/Module_LcmControl


BIN=BIN
EVSE/Projects/DD360/output/Module_PrimaryComm


BIN=BIN
EVSE/Projects/DD360/output/ReadCmdline


BIN=BIN
EVSE/Projects/DD360/output/main


+ 2 - 1
EVSE/Projects/DD360Audi/Apps/CSU/RFID.c

@@ -20,11 +20,12 @@ static bool isCardScan = false;
 //------------------------------------------------------------------------------
 static bool canStartCharging(void)
 {
+    uint8_t index = 0;
     char buf2[16] = "";
     memset(buf2, 0, ARRAY_SIZE(buf2));
     struct OCPP16Data *ShmOCPP16Data = (struct OCPP16Data *)GetShmOCPP16Data();
 
-    for (uint8_t index = 0; index < strlen((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status); index++) {
+    for (index = 0; index < strlen((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status); index++) {
         sprintf(buf2 + (index - 1) * 2, "%02X", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status[index]);
     }
     sprintf(buf2, "%s", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);

+ 104 - 70
EVSE/Projects/DD360Audi/Apps/CSU/main.c

@@ -261,13 +261,14 @@ void destroySelGun(uint8_t curGun)
     }
 }
 
+/*
 static int waitSelectGunPlugIt(uint8_t curGun)
 {
 #if !defined DD360Audi
     return PASS;
 #endif //!defined DD360Audi
 
-    /*switch (curGun) {
+    switch (curGun) {
     case RIGHT_GUN_NUM:
         if (ShmSelectGunInfo->SelGunInfo.RightGun == SEL_GUN_ATHOR) {
             return PASS;
@@ -283,16 +284,17 @@ static int waitSelectGunPlugIt(uint8_t curGun)
     default:
         return FAIL;
     }
-    */
 
-    if (curGun == RIGHT_GUN_NUM && (ShmSelectGunInfo->SelGunInfo.RightGun == SEL_GUN_ATHOR)) {
-        return PASS;
-    } else if ((curGun == LEFT_GUN_NUM) && (ShmSelectGunInfo->SelGunInfo.LeftGun == SEL_GUN_ATHOR)) {
-        return PASS;
-    }
+
+    //if (curGun == RIGHT_GUN_NUM && (ShmSelectGunInfo->SelGunInfo.RightGun == SEL_GUN_ATHOR)) {
+    //    return PASS;
+    //} else if ((curGun == LEFT_GUN_NUM) && (ShmSelectGunInfo->SelGunInfo.LeftGun == SEL_GUN_ATHOR)) {
+    //    return PASS;
+    //}
 
     return FAIL;
 }
+*/
 
 static int waitRightGunPlugIt(uint8_t curGun)
 {
@@ -2629,10 +2631,10 @@ void DetectPluginStart()
 bool isDetectPlugin()
 {
     if (pSysInfo->WaitForPlugit == YES) {
-        return YES;
+        return true;
     }
 
-    return NO;
+    return false;
 }
 
 //===============================================
@@ -5468,6 +5470,10 @@ void CheckOcppStatus(void)
 
 void OcppStartTransation(uint8_t gunIndex)
 {
+#if defined DD360 || defined DD360Audi || defined DD360ComBox
+    return;
+#endif //defined DD360 || defined DD360Audi || defined DD360ComBox
+
     uint8_t _OcppGunIndex = gunIndex;
     pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
 
@@ -5737,11 +5743,25 @@ void InformOcppErrOccur(uint8_t codeType)
     char _error[25];
 
     switch (codeType) {
-    case 4: strcpy(_error, "InternalError"); break;
-    case 6: strcpy(_error, "NoError"); break;
-    case 7: strcpy(_error, "OtherError"); break;
-    case 13: strcpy(_error, "UnderVoltage"); break;
-    case 14: strcpy(_error, "OverVoltage"); break;
+    case 4:
+        strcpy(_error, "InternalError");
+        break;
+
+    case 6:
+        strcpy(_error, "NoError");
+        break;
+
+    case 7:
+        strcpy(_error, "OtherError");
+        break;
+
+    case 13:
+        strcpy(_error, "UnderVoltage");
+        break;
+
+    case 14:
+        strcpy(_error, "OverVoltage");
+        break;
     }
 
     for (uint8_t gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++) {
@@ -6745,6 +6765,42 @@ static uint8_t distributionPsuModule(uint8_t *isRessign, uint8_t gunIndex)
     return NO;
 }
 
+static void checkEvBoardReqStop(uint8_t sysStatus, uint8_t gunIndex)
+{
+    uint8_t evBoardStopState = 0;
+
+    if ((evBoardStopState = isEvBoardStopChargeFlag(gunIndex)) > 0) {
+
+        // 板端要求停止 (錯誤)
+        if (sysStatus != S_CCS_PRECHARGE_ST0 &&
+                sysStatus != S_CCS_PRECHARGE_ST1) {
+            if (strcmp((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "") == EQUAL) {
+                strcpy((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "EVDisconnected");
+            }
+        }
+
+        if (evBoardStopState == EV_BOARD_STOP_CHARGING) {
+            ChargingAlarmProcess(gunIndex);
+        } else if (evBoardStopState == POWER_CABINET_STOP_CHARGING) {
+            ChargingTerminalProcess(gunIndex);
+        }
+    } else if (isEvBoardNormalStopChargeFlag(gunIndex) == YES) {
+        // 板端要求停止 (正常)
+        if (sysStatus != S_CCS_PRECHARGE_ST0 &&
+                sysStatus != S_CCS_PRECHARGE_ST1) {
+            if (strcmp((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "") == EQUAL) {
+                strcpy((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "EVDisconnected");
+            }
+        }
+
+        ChargingTerminalProcess(gunIndex);
+    } else if (OcppRemoteStop(gunIndex) == YES ||
+               WifiScheduleStop(gunIndex)) {
+        // 後臺要求停止
+        ChargingTerminalProcess(gunIndex);
+    }
+}
+
 int main(void)
 {
     bool isModelNameMatch = true;
@@ -7132,11 +7188,14 @@ int main(void)
                             ChangeGunSelectByIndex(gunIndex);
                             AddPlugInTimes(gunIndex);
                             strcpy((char *)pDcChargingInfo->StartUserId, (char *)pSysConfig->UserId);
-                            log_info("index = %d, CardNumber = %s \n", gunIndex, pDcChargingInfo->StartUserId);
+                            log_info("index = %d, CardNumber = %s \n",
+                                     gunIndex,
+                                     pDcChargingInfo->StartUserId);
                             strcpy((char *)pSysConfig->UserId, "");
                             // 當前操作的槍號,進入 Preparing
                             setChargerMode(gunIndex, MODE_REASSIGN_CHECK);
                             ClearDetectPluginFlag();
+
                             continue;
                         }
                     }
@@ -7186,46 +7245,7 @@ int main(void)
                 if (distributionPsuModule(&isRessign, gunIndex) == YES) {
                     continue;
                 }
-#if 0
-#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
-                if (pSysConfig->TotalConnectorCount > 1 && pSysInfo->IsAlternatvieConf == NO) {
-                    if (pSysInfo->MainChargingMode == _MAIN_CHARGING_MODE_MAX) {
-                        for (byte index = 0; index < pSysConfig->TotalConnectorCount; index++) {
-                            pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(index);
 
-                            // 有其他槍已經分配好 psu 模塊
-                            if (pSysInfo->CurGunSelected != index &&
-                                    pDcChargingInfo->SystemStatus >= S_PREPARNING &&
-                                    pDcChargingInfo->SystemStatus != S_MAINTAIN) {
-                                log_info("=============Smart Charging============= Step 1 \n");
-                                pSysInfo->ReAssignedFlag = _REASSIGNED_PREPARE_M_TO_A;
-                                isRessign = YES;
-                                break;
-                            }
-                        }
-                    } else if (pSysInfo->MainChargingMode == _MAIN_CHARGING_MODE_AVER &&
-                               pSysInfo->ReAssignedFlag != _REASSIGNED_NONE) {
-                        // 如果在切換最大充的過程中,需等待最大充切換完成後,在走均充流程
-                        if (pSysInfo->BridgeRelayStatus == YES) {
-                            if (pSysInfo->ReAssignedFlag != _REASSIGNED_COMP &&
-                                    pSysInfo->ReAssignedFlag != _REASSIGNED_WAITING) {
-                                log_info("=============Smart Charging============= Step 14 \n");
-                                pSysInfo->ReAssignedFlag = _REASSIGNED_WAITING;
-                            } else if (pSysInfo->ReAssignedFlag == _REASSIGNED_COMP) {
-                                pSysInfo->MainChargingMode = _MAIN_CHARGING_MODE_MAX;
-                                pSysInfo->ReAssignedFlag = _REASSIGNED_NONE;
-                                continue;
-                            }
-                        }
-
-                        if (pSysInfo->CurGunSelected == gunIndex) {
-                            pSysInfo->ConnectorPage = _LCM_PRE_CHARGE;
-                        }
-                        continue;
-                    }
-                }
-#endif // !defined DD360 && !defined DD360Audi
-#endif //0
                 if (isRessign == YES) {
                     setChargerMode(gunIndex, MODE_REASSIGN);
                 } else {
@@ -7278,11 +7298,7 @@ int main(void)
                 if (ShmPsuData->SystemPresentPsuQuantity > 0 &&
                         ShmPsuData->SystemAvailablePower > 10 &&
                         GetTimeoutValue(pDcChargingInfo->TimeoutTimer) >= 5000000) {
-                    //if ((pDcChargingInfo->MaximumChargingVoltage > 0) && //DS60-120 remove
-                    //        (pDcChargingInfo->AvailableChargingCurrent > 0) &&
-                    //        (pDcChargingInfo->AvailableChargingPower > 0)) {
                     setChargerMode(gunIndex, MODE_PREPARE_FOR_EV);
-                    //}
                 }
 
                 //DS60-120 add
@@ -7304,6 +7320,8 @@ int main(void)
                     }
                 }
 
+                checkEvBoardReqStop(pDcChargingInfo->SystemStatus, gunIndex);
+#if 0
                 if ((evBoardStopState = isEvBoardStopChargeFlag(gunIndex)) > 0) {
                     // 板端要求停止 (錯誤)
                     if (strcmp((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "") == EQUAL) {
@@ -7326,6 +7344,7 @@ int main(void)
                     // 後臺要求停止
                     ChargingTerminalProcess(gunIndex);
                 }
+#endif //0
 
                 if (pSysInfo->CurGunSelected == gunIndex) {
                     pSysInfo->ConnectorPage = _LCM_PRE_CHARGE;
@@ -7357,6 +7376,8 @@ int main(void)
                     }
                 }
 
+                checkEvBoardReqStop(pDcChargingInfo->SystemStatus, gunIndex);
+#if 0
                 if ((evBoardStopState = isEvBoardStopChargeFlag(gunIndex)) > 0) {
                     // 板端要求停止 (錯誤)
                     if (strcmp((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "") == EQUAL) {
@@ -7379,6 +7400,7 @@ int main(void)
                     // 後臺要求停止
                     ChargingTerminalProcess(gunIndex);
                 }
+#endif //0
 
                 // LCM => Pre-charging
                 if (pSysInfo->CurGunSelected == gunIndex) {
@@ -7395,7 +7417,8 @@ int main(void)
 
                 if (pDcChargingInfo->Type == _Type_Chademo) {
                     // 檢查樁端的 GFD 結果
-                    if (isPrechargeStatus_chademo(gunIndex) > 5 && isPrechargeStatus_chademo(gunIndex) < 8) {
+                    if (isPrechargeStatus_chademo(gunIndex) > 5 &&
+                            isPrechargeStatus_chademo(gunIndex) < 8) {
                         // 當前操作的槍號,進入 Charging
                         setChargerMode(gunIndex, MODE_CHARGING);
                     }
@@ -7437,6 +7460,8 @@ int main(void)
                     }
                 }
 
+                checkEvBoardReqStop(pDcChargingInfo->SystemStatus, gunIndex);
+#if 0
                 if ((evBoardStopState = isEvBoardStopChargeFlag(gunIndex)) > 0) {
                     // 板端要求停止 (錯誤)
                     if (strcmp((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "") == EQUAL) {
@@ -7459,6 +7484,7 @@ int main(void)
                     // 後臺要求停止
                     ChargingTerminalProcess(gunIndex);
                 }
+#endif //0
 
                 // LCM => Pre-charging
                 if (pSysInfo->CurGunSelected == gunIndex) {
@@ -7473,9 +7499,8 @@ int main(void)
                     ftime(&startChargingTime[gunIndex]);
                     strcpy((char *)ShmOCPP16Data->StartTransaction[gunIndex].ResponseIdTagInfo.Status, ""); //DS60-120 add
                     ChangeStartOrStopDateTime(YES, gunIndex);
-#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
+
                     OcppStartTransation(gunIndex);
-#endif //!defined DD360 && !defined DD360Audi
                 }
 
                 if (ShmOCPP16Data->CpMsg.bits[gunIndex].StartTransactionConf) {
@@ -7546,6 +7571,7 @@ int main(void)
                     if (strcmp((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "") == EQUAL) {
                         strcpy((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "EVDisconnected");
                     }
+
                     //printf("%d evBoardStopState = %d\r\n", gunIndex, evBoardStopState);
                     if (evBoardStopState == EV_BOARD_STOP_CHARGING) {
                         ChargingAlarmProcess(gunIndex);
@@ -7557,6 +7583,7 @@ int main(void)
                     if (strcmp((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "") == EQUAL) {
                         strcpy((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "EVDisconnected");
                     }
+
                     ChargingTerminalProcess(gunIndex);
                 } else if (OcppRemoteStop(gunIndex) == YES ||
                            WifiScheduleStop(gunIndex) ||
@@ -7756,6 +7783,8 @@ int main(void)
                     RecordAlarmCode(gunIndex, "012235");
                 }
 
+                checkEvBoardReqStop(pDcChargingInfo->SystemStatus, gunIndex);
+#if 0
                 if ((evBoardStopState = isEvBoardStopChargeFlag(gunIndex)) > 0) {
                     // 板端要求停止 (錯誤)
                     if (evBoardStopState == EV_BOARD_STOP_CHARGING) {
@@ -7771,10 +7800,12 @@ int main(void)
                     // 後臺要求停止
                     ChargingTerminalProcess(gunIndex);
                 }
+#endif //0
 
                 // 等待 EV 小板 (CCS) 通知可以開始 Precharge
                 // 切換 D+ Relay to Precharge Relay
-                if (isPrechargeStatus_ccs(gunIndex) == 39 || isPrechargeStatus_ccs(gunIndex) == 40) {
+                if (isPrechargeStatus_ccs(gunIndex) == 39 ||
+                        isPrechargeStatus_ccs(gunIndex) == 40) {
                     if (pDcChargingInfo->RelayKPK2Status == YES &&
                             pDcChargingInfo->PrechargeStatus != PRECHARGE_READY)
                         //if (pDcChargingInfo->PrechargeStatus != PRECHARGE_PRERELAY_PASS)
@@ -7812,6 +7843,8 @@ int main(void)
                     RecordAlarmCode(gunIndex, "012235");
                 }
 
+                checkEvBoardReqStop(pDcChargingInfo->SystemStatus, gunIndex);
+#if 0
                 if ((evBoardStopState = isEvBoardStopChargeFlag(gunIndex)) > 0) {
                     // 板端要求停止 (錯誤)
                     if (evBoardStopState == EV_BOARD_STOP_CHARGING) {
@@ -7828,7 +7861,7 @@ int main(void)
                     // 後臺要求停止
                     ChargingTerminalProcess(gunIndex);
                 }
-
+#endif //0
                 // 等待小板通知進入充電
                 // 切換 D+ Relay to Precharge Relay
                 if (pDcChargingInfo->RelayK1K2Status == YES) {
@@ -7840,8 +7873,10 @@ int main(void)
                     pSysInfo->ConnectorPage = _LCM_PRE_CHARGE;
                 }
                 break;
-            }
-        }
+            }//switch
+
+            checkEvBoardAlarmState(pDcChargingInfo->Type);
+        }//for
 
 #if defined DD360Audi
         if (pSysInfo->SystemPage != _LCM_SELECT_GUN) {
@@ -7875,11 +7910,10 @@ int main(void)
             }
         }
 
-        for (uint8_t gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++) {
-            pDcChargingInfo =  (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
-
-            checkEvBoardAlarmState(pDcChargingInfo->Type);
-        }
+        //for (uint8_t gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++) {
+        //    pDcChargingInfo =  (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
+        //    checkEvBoardAlarmState(pDcChargingInfo->Type);
+        //}
 
         //write(wtdFd, "a", 1);
         //WriteWatchDogState("a");

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

@@ -2,6 +2,7 @@
 #include <stdlib.h>     /*標準函數庫定義*/
 #include <string.h>
 #include <stdint.h>
+#include <time.h>
 
 #include "../Config.h"
 #include "../Log/log.h"

+ 4 - 0
EVSE/Projects/DD360Audi/Apps/Define/define.h

@@ -570,6 +570,10 @@ struct ChargingInfoData
 	int 				EvBatteryStartSoc;				// 0~100%
 	unsigned char 		NormalStopChargeFlag;			// for EV board
 	ChargingStop        ChargingStopFlag;
+	char 				ReservedStartFlag;
+	float 				ConnectorMaxVoltage;			// 0~6553.5 volt
+	float 				ConnectorMaxCurrent;			// 0~6553.5 volt
+	unsigned char 		ModelType;
 };
 
 typedef union

+ 69 - 7
EVSE/Projects/DD360Audi/Apps/FactoryConfig.c

@@ -31,12 +31,21 @@
 #include    "./Define/define.h"
 #include    "Config.h"
 
+//------------------------------------------------------------------------------
 #define Debug
 #define OUTPUT_FLASH        0x01
 #define OUTPUT_FILE         0x02
 
+#define log_info(format, args...) StoreLogMsg("[%s:%d][%s][Info] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
+#define log_warn(format, args...) StoreLogMsg("[%s:%d][%s][Warn] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
+#define log_error(format, args...) StoreLogMsg("[%s:%d][%s][Error] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
+
+//------------------------------------------------------------------------------
 struct SysConfigData            SysConfig;
+struct SysConfigAndInfo         *ShmSysConfigAndInfo;
+struct StatusCodeData           *ShmStatusCodeData;
 
+//------------------------------------------------------------------------------
 int StoreLogMsg(const char *fmt, ...)
 {
     char Buf[4096 + 256];
@@ -82,6 +91,39 @@ int runShellCmd(const char *cmd)
     return result;
 }
 
+//==========================================
+// Init all share memory
+//==========================================
+int InitShareMemory()
+{
+    int result = PASS;
+    int MeterSMId;
+
+    //creat ShmSysConfigAndInfo
+    if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo),  0777)) < 0) {
+        log_error("shmget ShmSysConfigAndInfo NG\n");
+
+        result = FAIL;
+    } else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
+        log_error("shmat ShmSysConfigAndInfo NG\n");
+
+        result = FAIL;
+    }
+
+    //creat ShmStatusCodeData
+    if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData),  0777)) < 0) {
+        log_error("shmget ShmStatusCodeData NG\n");
+
+        result = FAIL;
+    } else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
+        log_error("shmat ShmStatusCodeData NG\n");
+
+        result = FAIL;
+    }
+
+    return result;
+}
+
 void helpOutput(void)
 {
     printf("Usage: Module_FactoryConfig [OPTION]...\r\n\r\n");
@@ -113,6 +155,26 @@ int main(int argc, char *argv[])
     memset(ptr, 0, MtdBlockSize);
     memset(&SysConfig, 0, sizeof(struct SysConfigData));
 
+
+    // Initial Share Memory
+    if (InitShareMemory() == FAIL) {
+        log_error("InitShareMemory NG\n");
+
+        strcpy((char *)SysConfig.ModelName, "");
+        strcpy((char *)SysConfig.SerialNumber, "");
+        sleep(5);
+    } else {
+        memcpy((char *)SysConfig.ModelName,
+               ShmSysConfigAndInfo->SysConfig.ModelName,
+               ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.ModelName));
+
+        memcpy((char *)SysConfig.SerialNumber,
+               ShmSysConfigAndInfo->SysConfig.SerialNumber,
+               ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.SerialNumber));
+
+        log_info("InitShareMemory OK.\n");
+    }
+
     /*
      * TODO: Set factory default configuration
     */
@@ -248,13 +310,13 @@ int main(int argc, char *argv[])
         helpOutput();
     }
 
-    if (argc == 4) {
-        strcpy((char *)SysConfig.ModelName, argv[2]);
-        strcpy((char *)SysConfig.SerialNumber, argv[3]);
-    } else {
-        strcpy((char *)SysConfig.ModelName, "DDYC182V0UE2AD");
-        strcpy((char *)SysConfig.SerialNumber, "SERIALFORRD");
-    }
+    //if (argc == 4) {
+    //    strcpy((char *)SysConfig.ModelName, argv[2]);
+    //    strcpy((char *)SysConfig.SerialNumber, argv[3]);
+    //} else {
+    //    strcpy((char *)SysConfig.ModelName, "DDYC182V0UE2AD");
+    //    strcpy((char *)SysConfig.SerialNumber, "SERIALFORRD");
+    //}
 
     /*
      * Configuration bin file generate

+ 61 - 0
EVSE/Projects/DD360Audi/Apps/Log/log.c

@@ -8,6 +8,7 @@
 #include <stdarg.h>
 
 #include <sys/timeb.h>
+#include <sys/time.h>
 
 #include "../ShareMemory/shmMem.h"
 #include "../Define/define.h"
@@ -61,3 +62,63 @@ int StoreLogMsg(const char *fmt, ...)
 
     return rc;
 }
+
+int StoreEventLogMsg(const char *fmt, ...)
+{
+    char Buf[4096 + 256];
+    char buffer[4096];
+    time_t CurrentTime;
+    struct tm *tm;
+    struct timeval tv;
+    va_list args;
+    struct SysConfigData *pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
+
+    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);
+    gettimeofday(&tv, NULL); // get microseconds, 10^-6
+
+    if ((pSysConfig->ModelName != NULL) &&
+            (pSysConfig->SerialNumber != NULL) &&
+            (strlen((char *)pSysConfig->ModelName) >= 14)) {
+        sprintf(Buf, "echo -n \"[%04d.%02d.%02d %02d:%02d:%02d.%06ld]%s\" >> /Storage/EventLog/[%04d.%02d]%s_%s_EventLog",
+                tm->tm_year + 1900,
+                tm->tm_mon + 1,
+                tm->tm_mday,
+                tm->tm_hour,
+                tm->tm_min,
+                tm->tm_sec,
+                tv.tv_usec,
+                buffer,
+                tm->tm_year + 1900,
+                tm->tm_mon + 1,
+                pSysConfig->ModelName,
+                pSysConfig->SerialNumber);
+    } else {
+        sprintf(Buf, "echo -n \"[%04d.%02d.%02d %02d:%02d:%02d.%06ld]%s\" >> /Storage/EventLog/[%04d.%02d]EventLog",
+                tm->tm_year + 1900,
+                tm->tm_mon + 1,
+                tm->tm_mday,
+                tm->tm_hour,
+                tm->tm_min,
+                tm->tm_sec,
+                tv.tv_usec,
+                buffer,
+                tm->tm_year + 1900,
+                tm->tm_mon + 1);
+    }
+
+#ifdef SystemLogMessage
+    system(Buf);
+#endif //SystemLogMessage
+
+#ifdef ConsloePrintLog
+    printf("[%04d.%02d.%02d %02d:%02d:%02d.%06ld]%s", tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec, tv.tv_usec, buffer);
+#endif //ConsloePrintLog
+
+    return rc;
+}

+ 2 - 0
EVSE/Projects/DD360Audi/Apps/Log/log.h

@@ -6,7 +6,9 @@
 #define log_warn(format, args...) StoreLogMsg("[%s:%d][%s][Warn] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
 #define log_error(format, args...) StoreLogMsg("[%s:%d][%s][Error] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
 
+#define event_info(format, args...) StoreEventLogMsg("[%s:%d][%s][Info] "format, __FILE__, __LINE__, __FUNCTION__, ##args) //DS60-120 add
 //------------------------------------------------------------------------------
 int StoreLogMsg(const char *fmt, ...);
+int StoreEventLogMsg(const char *fmt, ...);
 
 #endif /* _LOG_H_ */

+ 31 - 13
EVSE/Projects/DD360Audi/Apps/Makefile

@@ -75,6 +75,10 @@ MAIN_SRC_FILES = $(patsubst %.o, %.c, $(MAIN_OBJ_FILES))
 %.o: %.c
 	$(CC) $(CFLAGS) -c $<
 
+#DoComm
+DOCOMM_OBJ_FILES = $(COMMON_OBJ_FILES) $(DoCommLib)/DoComm.o
+DOCOMM_SRC_FILES = $(patsubst %.o, %.c, $(DOCOMM_OBJ_FILES))
+
 #internal comm lib
 INTERNALCOMM_OBJ_FILES = $(COMMON_OBJ_FILES) $(InternalCommLib)/internalComm.o \
 							$(InternalCommLib)/Module_InternalComm.o $(InternalCommLib)/FanBoard.o \
@@ -99,6 +103,17 @@ EVENTLOG_SRC_FILES = $(patsubst %.o, %.c, $(EVENTLOG_OBJ_FILES))
 %.o: %.c
 	$(CC) $(CFLAGS) -c $<
 
+#LCM Control
+LCM_OBJ_FILES = $(COMMON_OBJ_FILES) $(LcmLib)/Module_LcmControl.o
+LCM_SRC_FILES = $(patsubst %.o, %.c, $(LCM_OBJ_FILES))
+
+#Primary
+PRIMARY_OBJ_FILES = $(COMMON_OBJ_FILES) $(PrimaryLib)/PrimaryComm.o \
+						$(PrimaryLib)/Module_PrimaryComm.o
+PRIMARY_SRC_FILES = $(patsubst %.o, %.c, $(PRIMARY_OBJ_FILES))
+%.o: %.c
+	$(CC) $(CFLAGS) -c $<
+
 all: CopyFile apps
 
 apps: MainTask DoCommTask EvCommTask \
@@ -115,9 +130,10 @@ MainTask:
 	#$(CC) $(TFLAGS) -o main main.o timeout.o common.o ${Lib_Module_RFID} ${Lib_Module_Upgrade} ${Lib_SQLite3} $(Lib_Module_RatedCurrent)
 
 DoCommTask:
-	$(CC) $(DEFINE) $(CFLAGS) -c -o define.o $(DefineLib)/define.c
-	$(CC) $(DEFINE) $(CFLAGS) -c -o DoComm.o $(DoCommLib)/DoComm.c
-	$(CC) -o Module_DoComm DoComm.o define.o
+	$(CC) $(DEFINE) $(DOCOMM_SRC_FILES) $(CFLAGS) $(TFLAGS) $(INC_FLAGS) -o Module_DoComm
+	#$(CC) $(DEFINE) $(CFLAGS) -c -o define.o $(DefineLib)/define.c
+	#$(CC) $(DEFINE) $(CFLAGS) -c -o DoComm.o $(DoCommLib)/DoComm.c
+	#$(CC) -o Module_DoComm DoComm.o define.o
 
 EvCommTask:
 	$(CC) $(DEFINE) $(EVCOMM_SRC_FILES) $(CFLAGS) $(TFLAGS) $(INC_FLAGS) $(Lib_Module_RatedCurrent) -o Module_EvComm
@@ -126,10 +142,10 @@ EvCommTask:
 	#$(CC) -o Module_EvComm Ev_Comm.o Module_EvComm.o $(Lib_Module_RatedCurrent)
 
 EventLoggingTask:
-	#$(CC) $(DEFINE) $(EVENTLOG_SRC_FILES) $(CFLAGS) $(TFLAGS) $(INC_FLAGS) $(SQLite3_H) $(Lib_SQLite3) -o Module_EventLogging
-	$(CC) $(DEFINE) $(CFLAGS) -c -o define.o $(DefineLib)/define.c
-	$(CC) $(DEFINE) $(SQLite3_H) $(CFLAGS) -c -o Module_EventLogging.o $(EventLogLib)/Module_EventLogging.c
-	$(CC) -o Module_EventLogging Module_EventLogging.o ${Lib_SQLite3} define.o
+	$(CC) $(DEFINE) $(EVENTLOG_SRC_FILES) $(CFLAGS) $(TFLAGS) $(INC_FLAGS) $(SQLite3_H) $(Lib_SQLite3) -o Module_EventLogging
+	#$(CC) $(DEFINE) $(CFLAGS) -c -o define.o $(DefineLib)/define.c
+	#$(CC) $(DEFINE) $(SQLite3_H) $(CFLAGS) -c -o Module_EventLogging.o $(EventLogLib)/Module_EventLogging.c
+	#$(CC) -o Module_EventLogging Module_EventLogging.o ${Lib_SQLite3} define.o
 
 InternalCommTask:
 	$(CC) $(DEFINE) $(INTERNALCOMM_SRC_FILES) $(CFLAGS) $(TFLAGS) $(INC_FLAGS) -o Module_InternalComm
@@ -138,14 +154,16 @@ InternalCommTask:
 	#$(CC) $(TFLAGS) -o Module_InternalComm Module_InternalComm.o internalComm.o $(Lib_ModuleRelay)
 
 LcmControlTask:
-	$(CC) $(DEFINE) $(CFLAGS) -c -o define.o $(DefineLib)/define.c
-	$(CC) $(DEFINE) $(CFLAGS) -c -o Module_LcmControl.o $(LcmLib)/Module_LcmControl.c
-	$(CC) -o Module_LcmControl Module_LcmControl.o define.o
+	$(CC) $(DEFINE) $(LCM_SRC_FILES) $(CFLAGS) $(TFLAGS) $(INC_FLAGS) -o Module_LcmControl
+	#$(CC) $(DEFINE) $(CFLAGS) -c -o define.o $(DefineLib)/define.c
+	#$(CC) $(DEFINE) $(CFLAGS) -c -o Module_LcmControl.o $(LcmLib)/Module_LcmControl.c
+	#$(CC) -o Module_LcmControl Module_LcmControl.o define.o
 
 PrimaryCommTask:
-	$(CC) $(DEFINE) $(CFLAGS) -c -o PrimaryComm.o $(PrimaryLib)/PrimaryComm.c
-	$(CC) $(DEFINE) $(CFLAGS) -c -o Module_PrimaryComm.o $(PrimaryLib)/Module_PrimaryComm.c
-	$(CC) -o Module_PrimaryComm Module_PrimaryComm.o PrimaryComm.o
+	$(CC) $(DEFINE) $(PRIMARY_SRC_FILES) $(CFLAGS) $(TFLAGS) $(INC_FLAGS) -o Module_PrimaryComm
+	#$(CC) $(DEFINE) $(CFLAGS) -c -o PrimaryComm.o $(PrimaryLib)/PrimaryComm.c
+	#$(CC) $(DEFINE) $(CFLAGS) -c -o Module_PrimaryComm.o $(PrimaryLib)/Module_PrimaryComm.c
+	#$(CC) -o Module_PrimaryComm Module_PrimaryComm.o PrimaryComm.o
 
 PsuCommTask:
 	$(CC) $(DEFINE) $(InfypwrPsuComm_H) $(CFLAGS) -c -o Module_PsuComm.o Module_PsuComm.c

+ 212 - 172
EVSE/Projects/DD360Audi/Apps/ModuleDoComm/DoComm.c

@@ -21,6 +21,8 @@
 #include <unistd.h>
 #include <signal.h>
 
+#include "../Log/log.h"
+#include "../ShareMemory/shmMem.h"
 #include "../Define/define.h"
 #include "../Config.h"
 #include "../SelectGun/SelectGun.h"
@@ -28,23 +30,28 @@
 #include "DoComm.h"
 
 //------------------------------------------------------------------------------
-#define log_info(format, args...) StoreLogMsg("[%s:%d][%s][Info] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
-#define log_warn(format, args...) StoreLogMsg("[%s:%d][%s][Warn] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
-#define log_error(format, args...) StoreLogMsg("[%s:%d][%s][Error] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
+//#define log_info(format, args...) StoreLogMsg("[%s:%d][%s][Info] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
+//#define log_warn(format, args...) StoreLogMsg("[%s:%d][%s][Warn] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
+//#define log_error(format, args...) StoreLogMsg("[%s:%d][%s][Error] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
 
 //------------------------------------------------------------------------------
 //static int TcpSock = 0;
 //static uint8_t PacketSe;
 static DoCommGblData gDoCommGblData = {0};
 
-static struct SysConfigAndInfo *ShmSysConfigAndInfo = NULL;
-static struct StatusCodeData *ShmStatusCodeData     = NULL;
-static struct PsuData *ShmPsuData                   = NULL;
-static struct OCPP16Data *ShmOCPP16Data             = NULL;
-static struct PrimaryMcuData *ShmPrimaryMcuData     = NULL;
-static SelectGunInfo *ShmSelectGunInfo              = NULL;
-
-static struct ChargingInfoData  *ChargingData[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
+//static struct SysConfigAndInfo *ShmSysConfigAndInfo = NULL;
+//static struct StatusCodeData *ShmStatusCodeData     = NULL;
+static struct SysConfigData *pSysConfig         = NULL;
+static struct SysInfoData *pSysInfo             = NULL;
+static struct WARNING_CODE_INFO *pSysWarning    = NULL;
+static struct AlarmCodeData *pAlarmCode         = NULL;
+static struct PsuData *ShmPsuData               = NULL;
+static struct OCPP16Data *ShmOCPP16Data         = NULL;
+static struct PrimaryMcuData *ShmPrimaryMcuData = NULL;
+static SelectGunInfo *ShmSelectGunInfo          = NULL;
+
+//static struct ChargingInfoData  *ChargingData[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY]
+static struct ChargingInfoData *pDcChargingInfo = NULL;
 static struct timeb             gRegTimeUp[2][MAX_REGISTER_NUM] = {0};
 static struct WARNING_CODE_INFO gPreSysWarningInfo = {0};
 
@@ -57,7 +64,7 @@ static int writeCsuModuleVersion(int fd);
 //------------------------------------------------------------------------------
 //--- Common function ---
 //------------------------------------------------------------------------------
-static int StoreLogMsg(const char *fmt, ...)
+/*static int StoreLogMsg(const char *fmt, ...)
 {
     char Buf[4096 + 256];
     char buffer[4096];
@@ -74,7 +81,7 @@ static int StoreLogMsg(const char *fmt, ...)
     SeqEndTime.time = time(NULL);
     tm = localtime(&SeqEndTime.time);
 
-    if (ShmSysConfigAndInfo->SysConfig.SwitchDebugFlag == 1) {
+    if (pSysConfig->SwitchDebugFlag == 1) {
         sprintf(Buf, "%02d:%02d:%02d:%03d - %s",
                 tm->tm_hour, tm->tm_min, tm->tm_sec, SeqEndTime.millitm, buffer);
         printf("%s \n", Buf);
@@ -88,6 +95,7 @@ static int StoreLogMsg(const char *fmt, ...)
 
     return rc;
 }
+*/
 
 static int DiffTimeb(struct timeb ST, struct timeb ET)
 {
@@ -187,7 +195,7 @@ static void InitSocketSigPipe(void)
 //------------------------------------------------------------------------------
 static void setTcpStatus(uint8_t setValue)
 {
-    ShmStatusCodeData->AlarmCode.AlarmEvents.bits.DisconnectedFromDo = setValue;
+    pAlarmCode->AlarmEvents.bits.DisconnectedFromDo = setValue;
 }
 
 //------------------------------------------------------------------------------
@@ -308,17 +316,17 @@ static void clearPricesInfo(uint8_t id)
 static void ClearAuthorizedFlag(void)
 {
     ShmOCPP16Data->SpMsg.bits.AuthorizeConf = NO;
-    ShmSysConfigAndInfo->SysInfo.AuthorizeFlag = NO;
+    pSysInfo->AuthorizeFlag = NO;
 }
 
 static void ClearDetectPluginFlag(void)
 {
-    ShmSysConfigAndInfo->SysInfo.WaitForPlugit = NO;
+    pSysInfo->WaitForPlugit = NO;
 }
 
 static bool isDetectPlugin(void)
 {
-    if (ShmSysConfigAndInfo->SysInfo.WaitForPlugit == YES) {
+    if (pSysInfo->WaitForPlugit == YES) {
         return YES;
     }
 
@@ -328,18 +336,20 @@ static bool isDetectPlugin(void)
 static void destroySelectGun(uint8_t curGun)
 {
     uint8_t i = 0;
-    uint8_t totalGun = ShmSysConfigAndInfo->SysConfig.TotalConnectorCount;
+    uint8_t totalGun = pSysConfig->TotalConnectorCount;
 
     if (curGun == DESTROY_ALL_SEL) {
         ShmSelectGunInfo->SelGunInfo.RightGun = SEL_GUN_RELEASE;
         ShmSelectGunInfo->SelGunInfo.LeftGun = SEL_GUN_RELEASE;
 
         for (i = 0; i < totalGun; i++) {
-            ChargingData[i]->TimeoutFlag = Timeout_None;
+            pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(i);
+
+            pDcChargingInfo->TimeoutFlag = Timeout_None;
             clearPricesInfo(i);
         }
-        ShmSysConfigAndInfo->SysInfo.CurGunSelected = 0;
-        strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
+        pSysInfo->CurGunSelected = 0;
+        strcpy((char *)pSysConfig->UserId, "");
     }
 
     //for charging timeout or complete
@@ -465,11 +475,11 @@ static int qrCodeUrlInfoHandle(uint8_t *data)
 
     //copy QR code string
     if (strncmp((char *)localTime, (char *)&data[0], timeLen - 2) != 0) {
-        memset(ShmSysConfigAndInfo->SysConfig.SystemId, '\0', sizeof(ShmSysConfigAndInfo->SysConfig.SystemId));
+        memset(pSysConfig->SystemId, '\0', sizeof(pSysConfig->SystemId));
         //printf("data =  %s\r\n", data);
         //len =
-        string2ByteArray((char *)data, (uint8_t *)ShmSysConfigAndInfo->SysConfig.SystemId);
-        //printf("SystemId =  %s\r\n", ShmSysConfigAndInfo->SysConfig.SystemId);
+        string2ByteArray((char *)data, (uint8_t *)pSysConfig->SystemId);
+        //printf("SystemId =  %s\r\n", pSysConfig->SystemId);
     }
 
     //if ((char *)&data[len] == '\0') {
@@ -500,7 +510,7 @@ static int updateFirmwareHandle(uint8_t *imgName)
     log_info("Program ready to check file %s\n", cmdBuf);
     if ( access(cmdBuf, F_OK) != -1) {
         log_info("File '%s' exist.\n", cmdBuf);
-        ShmSysConfigAndInfo->SysInfo.FirmwareUpdate = YES;
+        pSysInfo->FirmwareUpdate = YES;
     } else {
         log_info("File '%s' doesn't exist.\n", cmdBuf);
         ret = FAIL;
@@ -527,7 +537,7 @@ static int updateFirmwareHandle(uint8_t *imgName)
         if (WIFEXITED(status)) {
             if (0 == WEXITSTATUS(status)) {
                 printf("run shell script successfully.\n");
-                ShmSysConfigAndInfo->SysInfo.FirmwareUpdate = YES;
+                pSysInfo->FirmwareUpdate = YES;
             } else {
                 printf("run shell script fail, script exit code: %d\n", WEXITSTATUS(status));
             }
@@ -597,9 +607,9 @@ static int miscCommandHandle(uint8_t dataLen, uint8_t plugNum, uint8_t *data)
             prices = transPricesUnit((int)value);
             log_info("default prices = %.2f\r\n", prices);
 
-            //ShmSysConfigAndInfo->SysConfig.BillingData.isBilling = YES;
+            //pSysConfig->BillingData.isBilling = YES;
             for (j = 0; j < 24; j++) {
-                ShmSysConfigAndInfo->SysConfig.BillingData.Fee[j] = prices;
+                pSysConfig->BillingData.Fee[j] = prices;
             }
 
             clearMiscCommand();
@@ -613,12 +623,12 @@ static int miscCommandHandle(uint8_t dataLen, uint8_t plugNum, uint8_t *data)
 
             //log_info("default currency = %s%c\r\n", (uint8_t *)Currency[value]);
             log_info("default currency = %s\r\n", (uint8_t *)GetCurrency(value));
-            ShmSysConfigAndInfo->SysConfig.BillingData.Currency = value;
+            pSysConfig->BillingData.Currency = value;
             clearMiscCommand();
             break;
 
         case MISC_CMD_ACCOUNT_BALANCE:
-            if (ShmSysConfigAndInfo->SysInfo.CurGunSelected != (plugNum)) {
+            if (pSysInfo->CurGunSelected != (plugNum)) {
                 clearMiscCommand();
                 break;
             }
@@ -652,11 +662,11 @@ static int miscCommandHandle(uint8_t dataLen, uint8_t plugNum, uint8_t *data)
             break;
 
         case MISC_CMD_BILLING_INFO:
-            ShmSysConfigAndInfo->SysConfig.BillingData.isBilling = value;
+            pSysConfig->BillingData.isBilling = value;
             break;
 
         case MISC_CMD_WEB_STOP_CHARGING:
-            ShmSysConfigAndInfo->SysConfig.StopChargingByButton = value;
+            pSysConfig->StopChargingByButton = value;
             break;
 
         //--- Control Dispenser ---
@@ -699,39 +709,39 @@ static int miscCommandHandle(uint8_t dataLen, uint8_t plugNum, uint8_t *data)
                 break;
             }
 
-            if (ShmSysConfigAndInfo->SysInfo.CurGunSelected != (plugNum)) {
+            if (pSysInfo->CurGunSelected != (plugNum)) {
                 if (plugNum == LEFT_GUN_NUM &&
                         (ShmSelectGunInfo->SelGunInfo.LeftGun == SEL_GUN_CONFIRM ||
                          ShmSelectGunInfo->SelGunInfo.LeftGun == SEL_GUN_ATHOR)) {
                     ShmSelectGunInfo->SelGunInfo.LeftGun = SEL_GUN_RELEASE;
-                    strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
-                    ShmSysConfigAndInfo->SysInfo.WaitForPlugit = NO;
+                    strcpy((char *)pSysConfig->UserId, "");
+                    pSysInfo->WaitForPlugit = NO;
                     sleep(1); //Jerry add
-                    ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_SELECT_GUN;
-                    gettimeofday(&ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer, NULL);
-                    ShmSysConfigAndInfo->SysInfo.SystemTimeoutFlag = Timeout_None;
+                    pSysInfo->SystemPage = _LCM_SELECT_GUN;
+                    gettimeofday(&pSysInfo->SystemTimeoutTimer, NULL);
+                    pSysInfo->SystemTimeoutFlag = Timeout_None;
                 }
 
                 if (plugNum == RIGHT_GUN_NUM &&
                         (ShmSelectGunInfo->SelGunInfo.RightGun == SEL_GUN_CONFIRM ||
                          ShmSelectGunInfo->SelGunInfo.RightGun == SEL_GUN_ATHOR)) {
                     ShmSelectGunInfo->SelGunInfo.RightGun = SEL_GUN_RELEASE;
-                    strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
-                    ShmSysConfigAndInfo->SysInfo.WaitForPlugit = NO;
+                    strcpy((char *)pSysConfig->UserId, "");
+                    pSysInfo->WaitForPlugit = NO;
                     sleep(1); //Jerry add
-                    ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_SELECT_GUN;
-                    gettimeofday(&ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer, NULL);
-                    ShmSysConfigAndInfo->SysInfo.SystemTimeoutFlag = Timeout_None;
+                    pSysInfo->SystemPage = _LCM_SELECT_GUN;
+                    gettimeofday(&pSysInfo->SystemTimeoutTimer, NULL);
+                    pSysInfo->SystemTimeoutFlag = Timeout_None;
                 }
 
-                ShmSysConfigAndInfo->SysInfo.CurGunSelected = (plugNum);
-                ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc = NO_DEFINE;
+                pSysInfo->CurGunSelected = (plugNum);
+                pSysInfo->CurGunSelectedByAc = NO_DEFINE;
             }
 #else
-            ShmSysConfigAndInfo->SysInfo.CurGunSelected = (plugNum);
-            ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc = NO_DEFINE;
+            pSysInfo->CurGunSelected = (plugNum);
+            pSysInfo->CurGunSelectedByAc = NO_DEFINE;
 #endif //DD360Audi
-            setConfirmSelGun(ShmSysConfigAndInfo->SysInfo.CurGunSelected);
+            setConfirmSelGun(pSysInfo->CurGunSelected);
 
             ShmOCPP16Data->CsMsg.bits[plugNum].RemoteStartTransactionReq = YES;
             ShmSelectGunInfo->PricesInfo[plugNum].Balance = 0.00;
@@ -746,11 +756,11 @@ static int miscCommandHandle(uint8_t dataLen, uint8_t plugNum, uint8_t *data)
                 break;
             }
 
-            strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
-            ShmSysConfigAndInfo->SysInfo.WaitForPlugit = NO;
-            ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_SELECT_GUN;
-            gettimeofday(&ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer, NULL);
-            ShmSysConfigAndInfo->SysInfo.SystemTimeoutFlag = Timeout_None;
+            strcpy((char *)pSysConfig->UserId, "");
+            pSysInfo->WaitForPlugit = NO;
+            pSysInfo->SystemPage = _LCM_SELECT_GUN;
+            gettimeofday(&pSysInfo->SystemTimeoutTimer, NULL);
+            pSysInfo->SystemTimeoutFlag = Timeout_None;
             destroySelectGun(plugNum);
 
             clearMiscCommand();
@@ -766,14 +776,16 @@ static int miscCommandHandle(uint8_t dataLen, uint8_t plugNum, uint8_t *data)
 
             if (isDetectPlugin() == YES) {
                 ClearDetectPluginFlag();
-                strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
-                ShmSysConfigAndInfo->SysInfo.WaitForPlugit = NO;
-                ShmSysConfigAndInfo->SysInfo.SystemPage = _LCM_SELECT_GUN;
-                gettimeofday(&ShmSysConfigAndInfo->SysInfo.SystemTimeoutTimer, NULL);
-                ShmSysConfigAndInfo->SysInfo.SystemTimeoutFlag = Timeout_None;
+                strcpy((char *)pSysConfig->UserId, "");
+                pSysInfo->WaitForPlugit = NO;
+                pSysInfo->SystemPage = _LCM_SELECT_GUN;
+                gettimeofday(&pSysInfo->SystemTimeoutTimer, NULL);
+                pSysInfo->SystemTimeoutFlag = Timeout_None;
                 destroySelectGun(plugNum);
             } else {
-                ChargingData[plugNum]->StopChargeFlag = POWER_CABINET_STOP_CHARGING;
+                pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(plugNum);
+
+                pDcChargingInfo->StopChargeFlag = POWER_CABINET_STOP_CHARGING;
             }
             break;
 
@@ -794,6 +806,7 @@ static int chargingcapabilityHandle(uint8_t *data, uint8_t plugNum)
     static PricesInfo pricesInfo[2] = {0};
     CapabilityInfo *pCapabilityInfo = NULL;
     AccountInfo *pAccountInfo = NULL;
+    pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(plugNum);
 
     //--- charging capability information --------------------------------------
     pCapabilityInfo = (CapabilityInfo *)&data[0];
@@ -803,7 +816,7 @@ static int chargingcapabilityHandle(uint8_t *data, uint8_t plugNum)
         if (MaxVolt > MAX_VOLTAGE) {
             MaxVolt = MAX_VOLTAGE;
         }
-        ChargingData[plugNum]->MaximumChargingVoltage = MaxVolt;
+        pDcChargingInfo->MaximumChargingVoltage = MaxVolt;
     }
 
     MaxCurrent = (float)(ntohs(pCapabilityInfo->OutputCurrent));
@@ -811,7 +824,7 @@ static int chargingcapabilityHandle(uint8_t *data, uint8_t plugNum)
         if (MaxCurrent > MAX_CURRENCY) {
             MaxCurrent = MAX_CURRENCY;
         }
-        ChargingData[plugNum]->AvailableChargingCurrent = MaxCurrent;
+        pDcChargingInfo->AvailableChargingCurrent = MaxCurrent;
     }
 
     MaxPower = (float)(ntohs(pCapabilityInfo->OutputPower));
@@ -819,7 +832,7 @@ static int chargingcapabilityHandle(uint8_t *data, uint8_t plugNum)
         if (MaxPower > MAX_POWER) {
             MaxPower = MAX_POWER;
         }
-        ChargingData[plugNum]->AvailableChargingPower = MaxPower;
+        pDcChargingInfo->AvailableChargingPower = MaxPower;
     }
     //MaxVolt = (float)(data[0] << 8 |data[1]);
     //MaxCurrent = (float)(data[2] << 8 | data[3]);
@@ -830,9 +843,9 @@ static int chargingcapabilityHandle(uint8_t *data, uint8_t plugNum)
     addr = (sizeof(CapabilityInfo) - 2); //2 byte reserved
     pAccountInfo = (AccountInfo *)&data[addr];
 
-    ShmSysConfigAndInfo->SysConfig.BillingData.Currency = pAccountInfo->Currency;
+    pSysConfig->BillingData.Currency = pAccountInfo->Currency;
     ShmSelectGunInfo->PricesInfo[plugNum].UserPrices    = transPricesUnit(ntohl(pAccountInfo->UserPrices));
-    ChargingData[plugNum]->ChargingFee                  = transPricesUnit(ntohl(pAccountInfo->TotalCost));
+    pDcChargingInfo->ChargingFee                  = transPricesUnit(ntohl(pAccountInfo->TotalCost));
     ShmSelectGunInfo->PricesInfo[plugNum].Balance       = transPricesUnit(ntohl(pAccountInfo->Balance));
 
     if ((pricesInfo[plugNum].UserPrices != ShmSelectGunInfo->PricesInfo[plugNum].UserPrices) ||
@@ -843,9 +856,9 @@ static int chargingcapabilityHandle(uint8_t *data, uint8_t plugNum)
         log_info("id = %d, user prices = %.2f, Total cost = %.2f, Account balances = %.2f, currency = %s\r\n",
                  plugNum,
                  ShmSelectGunInfo->PricesInfo[plugNum].UserPrices,
-                 ChargingData[plugNum]->ChargingFee,
+                 pDcChargingInfo->ChargingFee,
                  ShmSelectGunInfo->PricesInfo[plugNum].Balance,
-                 (uint8_t *)GetCurrency(ShmSysConfigAndInfo->SysConfig.BillingData.Currency)
+                 (uint8_t *)GetCurrency(pSysConfig->BillingData.Currency)
                 );
     }
 
@@ -854,13 +867,13 @@ static int chargingcapabilityHandle(uint8_t *data, uint8_t plugNum)
 
 static void addFaultCodeToBuf(uint8_t *Code)
 {
-    uint8_t warningCount = ShmSysConfigAndInfo->SysWarningInfo.WarningCount;
+    uint8_t warningCount = pSysWarning->WarningCount;
 
     if (warningCount < 10) {
-        memcpy(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[warningCount][0],
+        memcpy(&pSysWarning->WarningCode[warningCount][0],
                Code,
                strlen((char *)Code));
-        ShmSysConfigAndInfo->SysWarningInfo.WarningCount++;
+        pSysWarning->WarningCount++;
     }
 }
 
@@ -876,20 +889,20 @@ static void removeFaultCodeToBuf(uint8_t *Code)
     while (find) {
         usleep(128);
         find = 0x00;
-        for (i = 0; i < ShmSysConfigAndInfo->SysWarningInfo.WarningCount; i++) {
+        for (i = 0; i < pSysWarning->WarningCount; i++) {
             usleep(128);
             if (find == 0x00) {
-                if (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], _code, 7) == 0) {
+                if (memcmp(&pSysWarning->WarningCode[i][0], _code, 7) == 0) {
                     find = 0x01;
                 }
             } else {
-                memcpy(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i - 1][0],
-                       &ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], 7);
+                memcpy(&pSysWarning->WarningCode[i - 1][0],
+                       &pSysWarning->WarningCode[i][0], 7);
             }
         }
 
         if (find) {
-            ShmSysConfigAndInfo->SysWarningInfo.WarningCount--;
+            pSysWarning->WarningCount--;
         }
     }
 }
@@ -931,15 +944,15 @@ static int powerCabinetStatusProcess(uint8_t dataLen, uint8_t *data)
         if (dataLen < WARNING_CODE_SIZE) {
             log_error("fail status code length = %d\r\n", dataLen);
             Hexdump(data, dataLen);
-            if (ShmSysConfigAndInfo->SysWarningInfo.WarningCount > 0) {
-                for (i = 0; i < ShmSysConfigAndInfo->SysWarningInfo.WarningCount; i++) {
+            if (pSysWarning->WarningCount > 0) {
+                for (i = 0; i < pSysWarning->WarningCount; i++) {
                     usleep(128);
-                    if (ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][1] >= '3' ||  //from backend or power cabinet
-                            (ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0] >= 'B' &&
-                             ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][1] >= '4')) {
+                    if (pSysWarning->WarningCode[i][1] >= '3' ||  //from backend or power cabinet
+                            (pSysWarning->WarningCode[i][0] >= 'B' &&
+                             pSysWarning->WarningCode[i][1] >= '4')) {
                         memset(EventCodeTmp, 0, sizeof(EventCodeTmp));
                         memcpy(EventCodeTmp,
-                               ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i],
+                               pSysWarning->WarningCode[i],
                                sizeof(EventCodeTmp));
                         removeFaultCodeToBuf(EventCodeTmp);
                     }
@@ -982,9 +995,9 @@ static int powerCabinetStatusProcess(uint8_t dataLen, uint8_t *data)
             strncpy((char *)&StatusArray[count / WARNING_CODE_SIZE], (char *)&data[count], WARNING_CODE_SIZE);
 
             ret = 0;
-            for (i = 0; i < ShmSysConfigAndInfo->SysWarningInfo.WarningCount; i++) {
+            for (i = 0; i < pSysWarning->WarningCount; i++) {
                 usleep(128);
-                if (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0],
+                if (memcmp(&pSysWarning->WarningCode[i][0],
                            StatusArray[count / WARNING_CODE_SIZE],
                            WARNING_CODE_SIZE) == 0) {
                     ret = 1;
@@ -1004,17 +1017,17 @@ static int powerCabinetStatusProcess(uint8_t dataLen, uint8_t *data)
         }
     }
 
-    for (i = 0; i < ShmSysConfigAndInfo->SysWarningInfo.WarningCount; i++) {
+    for (i = 0; i < pSysWarning->WarningCount; i++) {
         usleep(128);
 
-        if (ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][1] >= '3' || //from backend or power cabinet 0x33
-                (ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0] >= 'B' &&
-                 ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][1] >= '4')) {
+        if (pSysWarning->WarningCode[i][1] >= '3' || //from backend or power cabinet 0x33
+                (pSysWarning->WarningCode[i][0] >= 'B' &&
+                 pSysWarning->WarningCode[i][1] >= '4')) {
             ret = 0;
 
             for (count = 0; count < (dataLen / WARNING_CODE_SIZE); count++) {
                 usleep(128);
-                if (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0],
+                if (memcmp(&pSysWarning->WarningCode[i][0],
                            StatusArray[count],
                            WARNING_CODE_SIZE) == 0) {
                     ret = 1;
@@ -1025,7 +1038,7 @@ static int powerCabinetStatusProcess(uint8_t dataLen, uint8_t *data)
             if (ret == 0) {
                 memset(EventCodeTmp, 0, sizeof(EventCodeTmp));
                 memcpy(EventCodeTmp,
-                       ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i],
+                       pSysWarning->WarningCode[i],
                        sizeof(EventCodeTmp));
                 removeFaultCodeToBuf(EventCodeTmp);
             }
@@ -1072,7 +1085,7 @@ static int responsePackeHandle(int fd, uint8_t *pResult, uint8_t plugNum, uint8_
     case REG_DISPENSER_STATUS:
         memset(&gPreSysWarningInfo, 0, sizeof(struct WARNING_CODE_INFO));
         memcpy((uint8_t *)&gPreSysWarningInfo,
-               &(ShmSysConfigAndInfo->SysWarningInfo),
+               pSysWarning,
                sizeof(struct WARNING_CODE_INFO));
         break;
 
@@ -1220,9 +1233,9 @@ static int composeSocketData(int fd,
 static int writeWaitPlugItState(int fd, uint8_t id)
 {
     int ret = PASS;
-    uint8_t data[2] = {ShmSysConfigAndInfo->SysInfo.WaitForPlugit, 0};
+    uint8_t data[2] = {pSysInfo->WaitForPlugit, 0};
 
-    //printf("WaitForPlugit = %d\r\n", ShmSysConfigAndInfo->SysInfo.WaitForPlugit);
+    //printf("WaitForPlugit = %d\r\n", pSysInfo->WaitForPlugit);
 
     if ((ret = composeSocketData(fd,
                                  id,
@@ -1254,11 +1267,12 @@ static int writePresentChargingInfo(int fd, uint8_t plugNum, uint8_t id)
     int ret = PASS;
     uint8_t dataBuf[16] = {0};
     PreChargingInfo *pPreChargingInfo = (PreChargingInfo *)dataBuf;
+    pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(plugNum);
 
-    pPreChargingInfo->PresentChargingVoltage = htons((uint16_t)ChargingData[plugNum]->PresentChargingVoltage * 10);
-    pPreChargingInfo->PresentChargingCurrent = htons((uint16_t)ChargingData[plugNum]->PresentChargingCurrent * 10);
-    pPreChargingInfo->RemainChargingDuration = htonl(ChargingData[plugNum]->RemainChargingDuration);
-    pPreChargingInfo->EvBatterySoc = ChargingData[plugNum]->EvBatterySoc;
+    pPreChargingInfo->PresentChargingVoltage = htons((uint16_t)pDcChargingInfo->PresentChargingVoltage * 10);
+    pPreChargingInfo->PresentChargingCurrent = htons((uint16_t)pDcChargingInfo->PresentChargingCurrent * 10);
+    pPreChargingInfo->RemainChargingDuration = htonl(pDcChargingInfo->RemainChargingDuration);
+    pPreChargingInfo->EvBatterySoc = pDcChargingInfo->EvBatterySoc;
 
     ret = composeSocketData(fd,
                             id,
@@ -1276,15 +1290,15 @@ static int writeOtherModuleVersion(int fd)
     uint8_t dataLen = 0;
 
     //report other module version message
-    memcpy(&data[dataLen], ShmSysConfigAndInfo->SysInfo.FanModuleFwRev, VERSION_BUF_SIZE);
+    memcpy(&data[dataLen], pSysInfo->FanModuleFwRev, VERSION_BUF_SIZE);
     dataLen += VERSION_BUF_SIZE;
-    memcpy(&data[dataLen], ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev, VERSION_BUF_SIZE);
+    memcpy(&data[dataLen], pSysInfo->RelayModuleFwRev, VERSION_BUF_SIZE);
     dataLen += VERSION_BUF_SIZE;
-    memcpy(&data[dataLen], ShmSysConfigAndInfo->SysInfo.Connector1FwRev, VERSION_BUF_SIZE);
+    memcpy(&data[dataLen], pSysInfo->Connector1FwRev, VERSION_BUF_SIZE);
     dataLen += VERSION_BUF_SIZE;
-    memcpy(&data[dataLen], ShmSysConfigAndInfo->SysInfo.Connector2FwRev, VERSION_BUF_SIZE);
+    memcpy(&data[dataLen], pSysInfo->Connector2FwRev, VERSION_BUF_SIZE);
     dataLen += VERSION_BUF_SIZE;
-    memcpy(&data[dataLen], ShmSysConfigAndInfo->SysInfo.LedModuleFwRev, VERSION_BUF_SIZE);
+    memcpy(&data[dataLen], pSysInfo->LedModuleFwRev, VERSION_BUF_SIZE);
     dataLen += VERSION_BUF_SIZE;
 
     ret = composeSocketData(fd,
@@ -1304,13 +1318,13 @@ static int writeCsuModuleVersion(int fd)
     uint8_t dataLen = 0;
 
     //report CSU platform version message
-    memcpy(&data[dataLen], ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev, VERSION_BUF_SIZE);
+    memcpy(&data[dataLen], pSysInfo->CsuBootLoadFwRev, VERSION_BUF_SIZE);
     dataLen += VERSION_BUF_SIZE;
-    memcpy(&data[dataLen], ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev, VERSION_BUF_SIZE);
+    memcpy(&data[dataLen], pSysInfo->CsuKernelFwRev, VERSION_BUF_SIZE);
     dataLen += VERSION_BUF_SIZE;
-    memcpy(&data[dataLen], ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev, VERSION_BUF_SIZE);
+    memcpy(&data[dataLen], pSysInfo->CsuRootFsFwRev, VERSION_BUF_SIZE);
     dataLen += VERSION_BUF_SIZE;
-    memcpy(&data[dataLen], ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev, VERSION_BUF_SIZE);
+    memcpy(&data[dataLen], pSysInfo->CsuPrimFwRev, VERSION_BUF_SIZE);
     dataLen += VERSION_BUF_SIZE;
 
     ret = composeSocketData(fd,
@@ -1378,27 +1392,28 @@ static int writeConnectorState(int fd, uint8_t plugNum, uint8_t id)
     ConnectorState *pConnState = (ConnectorState *)dataBuf;
     static char vendorErrorCodeTmp[2][WARNING_CODE_SIZE] = {0};
     int ret = PASS;
+    pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(plugNum);
 
-    pConnState->ConnectorTemp = ChargingData[plugNum]->ConnectorTemp;
-    pConnState->ChillerTemp = ChargingData[plugNum]->ChillerTemp;
+    pConnState->ConnectorTemp = pDcChargingInfo->ConnectorTemp;
+    pConnState->ChillerTemp = pDcChargingInfo->ChillerTemp;
 
-    if (ChargingData[plugNum]->SystemStatus <= S_AUTHORIZING) {
+    if (pDcChargingInfo->SystemStatus <= S_AUTHORIZING) {
         pConnState->State = CONN_ST_IDLE;    //idle
         strncpy((char *)ShmOCPP16Data->StatusNotification[plugNum].VendorErrorCode,
                 "",
                 sizeof(ShmOCPP16Data->StatusNotification[plugNum].VendorErrorCode));
 
         strncpy(&vendorErrorCodeTmp[plugNum][0], "", WARNING_CODE_SIZE);
-    } else if ((ChargingData[plugNum]->SystemStatus <= S_PREPARING_FOR_EVSE) ||
-               (ChargingData[plugNum]->SystemStatus == S_CCS_PRECHARGE_ST0) ||
-               (ChargingData[plugNum]->SystemStatus == S_CCS_PRECHARGE_ST1)) {
+    } else if ((pDcChargingInfo->SystemStatus <= S_PREPARING_FOR_EVSE) ||
+               (pDcChargingInfo->SystemStatus == S_CCS_PRECHARGE_ST0) ||
+               (pDcChargingInfo->SystemStatus == S_CCS_PRECHARGE_ST1)) {
         pConnState->State = CONN_ST_PREPARING;    //preparing
-    } else if (ChargingData[plugNum]->SystemStatus == S_CHARGING) {
+    } else if (pDcChargingInfo->SystemStatus == S_CHARGING) {
         pConnState->State = CONN_ST_CHARGING;    //charging
-    } else if (ChargingData[plugNum]->SystemStatus == S_TERMINATING) {
+    } else if (pDcChargingInfo->SystemStatus == S_TERMINATING) {
         pConnState->State = CONN_ST_TERMINATING;    //terminating
-    } else if ((ChargingData[plugNum]->SystemStatus == S_ALARM) ||
-               (ChargingData[plugNum]->SystemStatus == S_FAULT)) {
+    } else if ((pDcChargingInfo->SystemStatus == S_ALARM) ||
+               (pDcChargingInfo->SystemStatus == S_FAULT)) {
         pConnState->State = CONN_ST_ALARM;
         strncpy((char *)pConnState->WarningCode,
                 (char *)ShmOCPP16Data->StatusNotification[plugNum].VendorErrorCode,
@@ -1440,7 +1455,8 @@ static int writeConnectorState(int fd, uint8_t plugNum, uint8_t id)
 static int writePlugInStatus(int fd, uint8_t plugNum, uint8_t id)
 {
     int ret = PASS;
-    uint8_t dataBuf[2] = {ChargingData[plugNum]->ConnectorPlugIn, 0};
+    pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(plugNum);
+    uint8_t dataBuf[2] = {pDcChargingInfo->ConnectorPlugIn, 0};
 
     ret = composeSocketData(fd,
                             id,
@@ -1454,7 +1470,7 @@ static int writePlugInStatus(int fd, uint8_t plugNum, uint8_t id)
 static int readSoftwareUpdate(int fd, uint8_t gunID)
 {
     int ret = PASS;
-    uint8_t dataBuf[2] = {ShmSysConfigAndInfo->SysInfo.FirmwareUpdate, 0};
+    uint8_t dataBuf[2] = {pSysInfo->FirmwareUpdate, 0};
 
     ret = composeSocketData(fd,
                             gunID,
@@ -1471,9 +1487,10 @@ static int writeChargingTarget(int fd, uint8_t plugNum, uint8_t id)
     int ret = PASS;
     float ChargingVolt, ChargingAmp;
     uint8_t dataBuf[4] = {0};
+    pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(plugNum);
 
-    ChargingVolt = ChargingData[plugNum]->EvBatterytargetVoltage;
-    ChargingAmp = ChargingData[plugNum]->EvBatterytargetCurrent;
+    ChargingVolt = pDcChargingInfo->EvBatterytargetVoltage;
+    ChargingAmp = pDcChargingInfo->EvBatterytargetCurrent;
     ChargingVolt *= 10;
     ChargingAmp *= 10;
 
@@ -1514,14 +1531,14 @@ static int writeDispenserStatus(int fd, uint8_t gunID)
     uint8_t PreWarnCodeTmp[10][6] = {0};
     int ret = PASS;
 
-    if ((ShmSysConfigAndInfo->SysWarningInfo.WarningCount <= 0) &&
+    if ((pSysWarning->WarningCount <= 0) &&
             (gPreSysWarningInfo.WarningCount <= 0)) {
         return FAIL;
     }
 
-    warningCount = ShmSysConfigAndInfo->SysWarningInfo.WarningCount;
+    warningCount = pSysWarning->WarningCount;
     for (count = 0; count < warningCount; count++) {
-        memcpy(CurWarnCodeTmp[count], ShmSysConfigAndInfo->SysWarningInfo.WarningCode[count], WARNING_CODE_SIZE);
+        memcpy(CurWarnCodeTmp[count], pSysWarning->WarningCode[count], WARNING_CODE_SIZE);
     }
 
     warningCount = gPreSysWarningInfo.WarningCount;
@@ -1578,20 +1595,20 @@ static int WriteModelName(int fd)
     uint8_t TmpBuf[255] = {0};
 
     memcpy(TmpBuf,
-           ShmSysConfigAndInfo->SysConfig.ModelName,
-           strlen((char *)ShmSysConfigAndInfo->SysConfig.ModelName));
+           pSysConfig->ModelName,
+           strlen((char *)pSysConfig->ModelName));
 
     Tmp = (uint8_t)(ShmPrimaryMcuData->InputDet.bits.Key2 << 2 |
                     ShmPrimaryMcuData->InputDet.bits.Key1 << 1 |
                     ShmPrimaryMcuData->InputDet.bits.Key0);
 
-    TmpBuf[strlen((char *)ShmSysConfigAndInfo->SysConfig.ModelName)] = Tmp; //Dispenser switch value
+    TmpBuf[strlen((char *)pSysConfig->ModelName)] = Tmp; //Dispenser switch value
 
     ret = composeSocketData(fd,
                             ID_REGISTER,
                             OP_WRITE_DATA,
                             REG_MODEL_NAME,
-                            strlen((char *)ShmSysConfigAndInfo->SysConfig.ModelName) + 1,
+                            strlen((char *)pSysConfig->ModelName) + 1,
                             &TmpBuf[0]);
 
     return ret;
@@ -1610,7 +1627,7 @@ static void calDisconnectCount(uint8_t *pValue, uint8_t maxCount)
 
 static int CheckNetworkStatus(void)
 {
-    char *ipAddr = (char *)&ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthIpAddress;
+    char *ipAddr = (char *)&pSysConfig->Eth0Interface.EthIpAddress;
 
     //printf("Check network IP Header = %s\n", ipAddr);
     if (strstr(ipAddr, CMP_ETH_IP_HEAD) != NULL) {
@@ -1620,27 +1637,28 @@ static int CheckNetworkStatus(void)
     return 0;
 }
 
+#if 0
 static int FindChargingInfoData(uint8_t target, struct ChargingInfoData **chargingData)
 {
     uint8_t index = 0;
 
     for (index = 0; index < CHAdeMO_QUANTITY; index++) {
-        if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == target) {
-            chargingData[target] = &ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index];
+        if (pSysInfo->ChademoChargingData[index].Index == target) {
+            chargingData[target] = &pSysInfo->ChademoChargingData[index];
             return 1;
         }
     }
 
     for (index = 0; index < CCS_QUANTITY; index++) {
-        if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == target) {
-            chargingData[target] = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[index];
+        if (pSysInfo->CcsChargingData[index].Index == target) {
+            chargingData[target] = &pSysInfo->CcsChargingData[index];
             return 1;
         }
     }
 
     for (index = 0; index < GB_QUANTITY; index++) {
-        if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == target) {
-            chargingData[target] = &ShmSysConfigAndInfo->SysInfo.GbChargingData[index];
+        if (pSysInfo->GbChargingData[index].Index == target) {
+            chargingData[target] = &pSysInfo->GbChargingData[index];
             return 1;
         }
     }
@@ -1706,6 +1724,7 @@ static int InitShareMemory(void)
 
     return result;
 }
+#endif //0
 
 static void updateFirmwareProcess(int fd, uint8_t gunID, uint8_t totalConnCount)
 {
@@ -1713,12 +1732,13 @@ static void updateFirmwareProcess(int fd, uint8_t gunID, uint8_t totalConnCount)
     uint8_t plugNum = 0;
     uint8_t ackCount = 5;
     struct timeb updateTime;
+    pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(plugNum);
 
-    if (ShmSysConfigAndInfo->SysWarningInfo.Level != 2) {
+    if (pSysWarning->Level != 2) {
         for (plugNum = 0; plugNum < totalConnCount; plugNum++) {
-            if (ChargingData[plugNum]->SystemStatus != S_IDLE &&
-                    ChargingData[plugNum]->SystemStatus != S_RESERVATION &&
-                    ChargingData[plugNum]->SystemStatus != S_MAINTAIN) {
+            if (pDcChargingInfo->SystemStatus != S_IDLE &&
+                    pDcChargingInfo->SystemStatus != S_RESERVATION &&
+                    pDcChargingInfo->SystemStatus != S_MAINTAIN) {
                 canUpdateFirmware = false;
             }
         }
@@ -1731,13 +1751,13 @@ static void updateFirmwareProcess(int fd, uint8_t gunID, uint8_t totalConnCount)
             ftime(&gRegTimeUp[0][REG_SOFTWARE_UPDATE]);
         }
 
-        if (ShmSysConfigAndInfo->SysInfo.FirmwareUpdate == YES) {
+        if (pSysInfo->FirmwareUpdate == YES) {
             while (ackCount != 0) {
                 ftime(&updateTime);
                 if (DiffTimeb(gRegTimeUp[0][REG_SOFTWARE_UPDATE], updateTime) > LOOP_RETRY_TIME / 2) {
                     readSoftwareUpdate(fd, gunID);
                     ftime(&gRegTimeUp[0][REG_SOFTWARE_UPDATE]);
-                    if (ShmSysConfigAndInfo->SysInfo.FirmwareUpdate == NO) {
+                    if (pSysInfo->FirmwareUpdate == NO) {
                         ackCount--;
                     }
                 }
@@ -1754,22 +1774,22 @@ static void checkAuthorProcess(int fd, uint8_t plugNum)
     struct timeb AuthNowTime;
 
 #if defined DD360Audi
-    gunID = gDoCommGblData.ConnectorID[ShmSysConfigAndInfo->SysInfo.CurGunSelected];
+    gunID = gDoCommGblData.ConnectorID[pSysInfo->CurGunSelected];
     //gunID = gDoCommGblData.ConnectorID[plugNum];
 #else
     gunID = ID_REGISTER;
 
-    ShmSelectGunInfo->PricesInfo[ShmSysConfigAndInfo->SysInfo.CurGunSelected].Balance = 0.0;
+    ShmSelectGunInfo->PricesInfo[pSysInfo->CurGunSelected].Balance = 0.0;
 #endif // DD360Audi
 
     if ((ShmOCPP16Data->SpMsg.bits.AuthorizeReq == YES) ||
-            (ShmSysConfigAndInfo->SysInfo.AuthorizeFlag == YES)) {
+            (pSysInfo->AuthorizeFlag == YES)) {
         ftime(&AuthNowTime);
 
         if (DiffTimeb(gRegTimeUp[plugNum][REG_USER_ID], AuthNowTime) > LOOP_RETRY_TIME) {
             ret = writeUserID(fd,
                               gunID,
-                              ShmSysConfigAndInfo->SysConfig.UserId);
+                              pSysConfig->UserId);
             if (ret >= 0) {
                 memset(ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status,
                        0,
@@ -1786,11 +1806,11 @@ static void checkAuthorProcess(int fd, uint8_t plugNum)
                 //       FAIL_BALANCE_PRICES);
 
                 if (ShmSelectGunInfo->PricesInfo[plugNum].Balance != FAIL_BALANCE_PRICES) {
-                    ShmOCPP16Data->SpMsg.bits.AuthorizeConf    = YES; //isAuthorizedComplete
-                    ShmOCPP16Data->SpMsg.bits.AuthorizeReq     = NO;
-                    ShmSysConfigAndInfo->SysInfo.AuthorizeFlag = NO;
-                    ShmPsuData->SystemAvailablePower           = NO;
-                    ShmPsuData->SystemPresentPsuQuantity       = NO;
+                    ShmOCPP16Data->SpMsg.bits.AuthorizeConf = YES; //isAuthorizedComplete
+                    ShmOCPP16Data->SpMsg.bits.AuthorizeReq  = NO;
+                    pSysInfo->AuthorizeFlag                 = NO;
+                    ShmPsuData->SystemAvailablePower        = NO;
+                    ShmPsuData->SystemPresentPsuQuantity    = NO;
                 }
             }
             ftime(&gRegTimeUp[plugNum][REG_USER_ID]);
@@ -1860,7 +1880,7 @@ static int messageTrigger(int fd, uint8_t plugNum, uint8_t gunID, uint8_t curReg
         //            readSoftwareUpdate(fd);
         //            ftime(&gRegTimeUp[plugNum][curReg]);
         //        }
-        //        while (ShmSysConfigAndInfo->SysInfo.FirmwareUpdate == YES) {
+        //        while (pSysInfo->FirmwareUpdate == YES) {
         //            ftime(&NowTime);
         //            if (DiffTimeb(gRegTimeUp[plugNum][curReg], NowT ime) > LOOP_RETRY_TIME||
         //DiffTimeb(gRegTimeUp[plugNum][curReg], NowTime) < 0) {
@@ -1971,7 +1991,7 @@ static int messageTrigger(int fd, uint8_t plugNum, uint8_t gunID, uint8_t curReg
 
 //static bool isDetectPlugin()
 //{
-//    if (ShmSysConfigAndInfo->SysInfo.WaitForPlugit == YES) {
+//    if (pSysInfo->WaitForPlugit == YES) {
 //        return YES;
 //    }
 //
@@ -1982,8 +2002,9 @@ static void systemStatusProcess(int fd, uint8_t totalGun, uint8_t plugNum, uint8
 {
     uint8_t i = 0;
     struct timeb AuthNowTime = {0};
+    pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(plugNum);
 
-    switch (ChargingData[plugNum]->SystemStatus) {
+    switch (pDcChargingInfo->SystemStatus) {
     case S_IDLE:
     case S_RESERVATION:
     case S_MAINTAIN:
@@ -2020,7 +2041,9 @@ static void systemStatusProcess(int fd, uint8_t totalGun, uint8_t plugNum, uint8
         if (DiffTimeb(gRegTimeUp[plugNum][REG_CHARGING_PERMISSION], AuthNowTime) > LOOP_RETRY_TIME) {
             if (readChargePermission(fd, gunID) && readChargingCapability(fd, gunID)) {
                 for (i = 0; i < totalGun; i++) {
-                    ShmPsuData->SystemAvailablePower += ChargingData[i]->AvailableChargingPower;
+                    pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(i);
+
+                    ShmPsuData->SystemAvailablePower += pDcChargingInfo->AvailableChargingPower;
                 }
                 ShmPsuData->SystemPresentPsuQuantity = (ShmPsuData->SystemAvailablePower / 30);
             }
@@ -2047,7 +2070,7 @@ static void systemStatusProcess(int fd, uint8_t totalGun, uint8_t plugNum, uint8
                 log_info("S_PREPARING_FOR_EV Stop charging by power cabinet's permission = %d, %d\r\n",
                          plugNum,
                          REG_CHARGING_PERMISSION);
-                ChargingData[plugNum]->StopChargeFlag = POWER_CABINET_STOP_CHARGING;
+                pDcChargingInfo->StopChargeFlag = POWER_CABINET_STOP_CHARGING;
             }
             ftime(&gRegTimeUp[plugNum][REG_CHARGING_PERMISSION]);
         }
@@ -2076,7 +2099,7 @@ static void systemStatusProcess(int fd, uint8_t totalGun, uint8_t plugNum, uint8
                 log_info("S_PREPARING_FOR_EVSE Stop charging by power cabinet's permission = %d, %d\r\n",
                          plugNum,
                          REG_CHARGING_PERMISSION);
-                ChargingData[plugNum]->StopChargeFlag = POWER_CABINET_STOP_CHARGING;
+                pDcChargingInfo->StopChargeFlag = POWER_CABINET_STOP_CHARGING;
             }
             ftime(&gRegTimeUp[plugNum][REG_CHARGING_PERMISSION]);
         }
@@ -2102,8 +2125,8 @@ static void systemStatusProcess(int fd, uint8_t totalGun, uint8_t plugNum, uint8
                 log_info("Stop charging by power cabinet's permission = %d, %d\r\n",
                          plugNum,
                          REG_CHARGING_PERMISSION);
-                ChargingData[plugNum]->StopChargeFlag = POWER_CABINET_STOP_CHARGING;
-                //printf("%d StopChargeFlag = %d\r\n", plugNum, ChargingData[plugNum]->StopChargeFlag);
+                pDcChargingInfo->StopChargeFlag = POWER_CABINET_STOP_CHARGING;
+                //printf("%d StopChargeFlag = %d\r\n", plugNum, pDcChargingInfo->StopChargeFlag);
             }
             ftime(&gRegTimeUp[plugNum][REG_CHARGING_PERMISSION]);
         }
@@ -2133,7 +2156,7 @@ static int networkCreatePorcess(void)
 {
     int fd = 0;
 
-    while (ShmSysConfigAndInfo->SysInfo.SelfTestSeq != _STEST_COMPLETE) {
+    while (pSysInfo->SelfTestSeq != _STEST_COMPLETE) {
         usleep(128);
     }
 
@@ -2141,7 +2164,7 @@ static int networkCreatePorcess(void)
 
     /**************** Check Network **********/
     log_info("Check Dispenser Network Information");
-    while (ShmSysConfigAndInfo->SysInfo.SelfTestSeq != _STEST_COMPLETE) {
+    while (pSysInfo->SelfTestSeq != _STEST_COMPLETE) {
         usleep(125);
     }
 
@@ -2150,9 +2173,9 @@ static int networkCreatePorcess(void)
         log_error("disconnect count = % d\r\n", gDoCommGblData.DisConnCount);
     }
     log_info("Dispenser Network Information checked: IP = % s Netmask = % s, Gateway = % s",
-             ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthIpAddress,
-             ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthSubmaskAddress,
-             ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthGatewayAddress);
+             pSysConfig->Eth0Interface.EthIpAddress,
+             pSysConfig->Eth0Interface.EthSubmaskAddress,
+             pSysConfig->Eth0Interface.EthGatewayAddress);
 
     gDoCommGblData.DisConnCount = 0;
 
@@ -2164,9 +2187,9 @@ static int networkCreatePorcess(void)
     }
     log_info("Power cabinet connected(fd = % d): IP = % s Netmask = % s, Gateway = % s",
              fd,
-             ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthIpAddress,
-             ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthSubmaskAddress,
-             ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthGatewayAddress);
+             pSysConfig->Eth0Interface.EthIpAddress,
+             pSysConfig->Eth0Interface.EthSubmaskAddress,
+             pSysConfig->Eth0Interface.EthGatewayAddress);
 
     gDoCommGblData.DisConnCount = 0;
     destroySelectGun(DESTROY_ALL_SEL);
@@ -2191,9 +2214,9 @@ int main(int argc, char *argv[])
     InitSocketSigPipe();
 
     /**************** Initialization **********/
-    if (InitShareMemory() == 0) {
+    /*if (InitShareMemory() == 0) {
         if (ShmStatusCodeData != NULL) {
-            ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory = YES;
+            pAlarmCode->AlarmEvents.bits.FailToCreateShareMemory = YES;
         }
 
         log_error("DoComm Initial share memory fail\r\n");
@@ -2201,14 +2224,31 @@ int main(int argc, char *argv[])
 
         return 0;
     }
+    */
+    if (CreateAllCsuShareMemory() == FAIL) {
+        log_error("create share memory error\r\n");
+        return FAIL;
+    }
 
-    totalConnCount = ShmSysConfigAndInfo->SysConfig.TotalConnectorCount;
+    MappingGunChargingInfo("DoComm Task");
+
+    pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
+    pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
+    pSysWarning = (struct WARNING_CODE_INFO *)GetShmSysWarningInfo();
+
+    pAlarmCode = (struct AlarmCodeData *)GetShmAlarmCodeData();
+    ShmPsuData = (struct PsuData *)GetShmPsuData();
+    ShmPrimaryMcuData = (struct PrimaryMcuData *)GetShmPrimaryMcuData();
+    ShmOCPP16Data = (struct OCPP16Data *)GetShmOCPP16Data();
+    ShmSelectGunInfo = (SelectGunInfo *)GetShmSelectGunInfo();
+
+    totalConnCount = pSysConfig->TotalConnectorCount;
 
     for (index = 0; index < totalConnCount; index++) {
-        if (!FindChargingInfoData(index, &ChargingData[0])) {
-            log_error("FindChargingInfoData false \n");
-            break;
-        }
+        //if (!FindChargingInfoData(index, &ChargingData[0])) {
+        //    log_error("FindChargingInfoData false \n");
+        //    break;
+        //}
         clearPricesInfo(index);
     }
 
@@ -2253,10 +2293,10 @@ int main(int argc, char *argv[])
             setTcpStatus(ABNORMAL);
 
 
-            if (ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthDhcpClient == 0) {
+            if (pSysConfig->Eth0Interface.EthDhcpClient == 0) {
                 sprintf(tmpbuf,
                         "/sbin/udhcpc -i eth0 -x hostname:CSU3_%s -s /root/dhcp_script/eth0.script > /dev/null &",
-                        ShmSysConfigAndInfo->SysConfig.SystemId);
+                        pSysConfig->SystemId);
                 system(tmpbuf);
             }
 

+ 134 - 87
EVSE/Projects/DD360Audi/Apps/ModuleEventLog/Module_EventLogging.c

@@ -26,23 +26,34 @@
 #include <time.h>
 #include <ctype.h>
 #include <ifaddrs.h>
+
+#include "../Log/log.h"
+#include "../ShareMemory/shmMem.h"
 #include "../Define/define.h"
 #include "../Config.h"
 
 //------------------------------------------------------------------------------
-struct SysConfigAndInfo         *ShmSysConfigAndInfo;
-struct StatusCodeData           *ShmStatusCodeData;
+//struct SysConfigAndInfo         *ShmSysConfigAndInfo;
+//struct StatusCodeData           *ShmStatusCodeData;
+static struct SysConfigData *pSysConfig      = NULL;
+static struct SysInfoData *pSysInfo          = NULL;
+static struct WARNING_CODE_INFO *pSysWarning = NULL;
+static struct AlarmCodeData *pAlarmCode      = NULL;
+static struct InfoCodeData *pInfoCode        = NULL;
+static struct FaultCodeData *pFaultCode      = NULL;
 
-sqlite3 *localDb; //DS60-120 add
+//sqlite3 *localDb; //DS60-120 add
 
 //------------------------------------------------------------------------------
+#define WRITE_FLASH_TIME                        (128)
 #define DB_FILE             "/Storage/ChargeLog/localCgargingRecord.db" //DS60-120 add
 
-#define log_info(format, args...) StoreLogMsg("[%s:%d][%s][Info] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
-#define log_warn(format, args...) StoreLogMsg("[%s:%d][%s][Warn] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
-#define log_error(format, args...) StoreLogMsg("[%s:%d][%s][Error] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
+//#define log_info(format, args...) StoreLogMsg("[%s:%d][%s][Info] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
+//#define log_warn(format, args...) StoreLogMsg("[%s:%d][%s][Warn] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
+//#define log_error(format, args...) StoreLogMsg("[%s:%d][%s][Error] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
 #define event_info(format, args...) StoreEventLogMsg("[%s:%d][%s][Info] "format, __FILE__, __LINE__, __FUNCTION__, ##args) //DS60-120 add
 
+/*
 int StoreLogMsg(const char *fmt, ...)
 {
     char Buf[4096 + 256];
@@ -169,15 +180,16 @@ int InitShareMemory()
 
     return result;
 }
+*/
 
 //================================================
 // Main process
 //================================================
 void AddFaultCodeToBuf(uint8_t *Code)
 {
-    if (ShmSysConfigAndInfo->SysWarningInfo.WarningCount < 10) {
-        memcpy(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[ShmSysConfigAndInfo->SysWarningInfo.WarningCount][0], Code, 7);
-        ShmSysConfigAndInfo->SysWarningInfo.WarningCount++;
+    if (pSysWarning->WarningCount < 10) {
+        memcpy(&pSysWarning->WarningCode[pSysWarning->WarningCount][0], Code, 7);
+        pSysWarning->WarningCount++;
     }
 }
 
@@ -190,23 +202,24 @@ void RemoveFaultCodeToBuf(uint8_t *Code)
     // 把相關的錯誤碼一次移除,避免重複顯示
     while (find) {
         find = 0x00;
-        for (uint8_t i = 0; i < ShmSysConfigAndInfo->SysWarningInfo.WarningCount; i++) {
+        for (uint8_t i = 0; i < pSysWarning->WarningCount; i++) {
             if (find == 0x00) {
-                if (memcmp(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], _code, 7) == 0) {
+                if (memcmp(&pSysWarning->WarningCode[i][0], _code, 7) == 0) {
                     find = 0x01;
                 }
             } else {
-                memcpy(&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i - 1][0],
-                       &ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0], 7);
+                memcpy(&pSysWarning->WarningCode[i - 1][0],
+                       &pSysWarning->WarningCode[i][0], 7);
             }
         }
 
         if (find) {
-            ShmSysConfigAndInfo->SysWarningInfo.WarningCount--;
+            pSysWarning->WarningCount--;
         }
     }
 }
 
+#if 0
 //==========================================
 // SQLite routne
 //==========================================
@@ -274,97 +287,131 @@ int DB_Insert_Record(sqlite3 *db, uint8_t *statusCode) //DS60-120 add
 
     return result;
 }
+#endif //0
 
 int main(void)
 {
-    int ByteCount, BitCount;
-    uint8_t tmp, EventCodeTmp[7];
-
-    if (InitShareMemory() == FAIL) {
-        log_error("InitShareMemory NG\n");
-        if (ShmStatusCodeData != NULL) {
-            ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory = 1;
-        }
-        sleep(5);
-        return 0;
+    int ByteCounter, BitCounter;
+    uint8_t tmp, EventCodeTmp[7] = {0};
+
+    //if (InitShareMemory() == FAIL) {
+    //    log_error("InitShareMemory NG\n");
+    //    if (ShmStatusCodeData != NULL) {
+    //        pAlarmCode->AlarmEvents.bits.FailToCreateShareMemory = 1;
+    //    }
+    //    sleep(5);
+    //    return 0;
+    //}
+    if (CreateAllCsuShareMemory() == FAIL) {
+        log_error("create share memory error\r\n");
+        return FAIL;
     }
 
+    MappingGunChargingInfo("EventLog Task");
+
+    pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
+    pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
+    pSysWarning = (struct WARNING_CODE_INFO *)GetShmSysWarningInfo();
+
+    pAlarmCode = (struct AlarmCodeData *)GetShmAlarmCodeData();
+    pInfoCode = (struct InfoCodeData *)GetShmInfoCodeData();
+    pFaultCode = (struct FaultCodeData *)GetShmFaultCodeData();
+
+
     for (;;) {
         //check Fault Status
-        for (ByteCount = 0; ByteCount < sizeof(ShmStatusCodeData->FaultCode.PreviousFaultVal); ByteCount++) {
-            if (ShmStatusCodeData->FaultCode.FaultEvents.FaultVal[ByteCount] != ShmStatusCodeData->FaultCode.PreviousFaultVal[ByteCount]) {
-                tmp = ShmStatusCodeData->FaultCode.FaultEvents.FaultVal[ByteCount]; //prevent be modified during following process
-                for (BitCount = 0; BitCount < 8; BitCount++) {
-                    if (((tmp >> BitCount) & 0x01) != ((ShmStatusCodeData->FaultCode.PreviousFaultVal[ByteCount] >> BitCount) & 0x01)) {
-                        memset(EventCodeTmp, 0, sizeof(EventCodeTmp));
-                        memcpy(EventCodeTmp, GetFaultStatusCode(ByteCount * 8 + BitCount), sizeof(EventCodeTmp) - 1);
-                        if (((tmp >> BitCount) & 0x01) == 0) { //Recovered
-                            //EventCodeTmp[0]=1;
-                            log_info("Recovery Fault Code = %s\n", EventCodeTmp);
-                            ShmStatusCodeData->FaultCode.PreviousFaultVal[ByteCount] &= ~(1 << BitCount);
-                            RemoveFaultCodeToBuf(EventCodeTmp);
-                            EventCodeTmp[0] = '1';//DS60-120 add
-                        } else {
-                            log_info("Fault Code = %s\n", EventCodeTmp);
-                            ShmStatusCodeData->FaultCode.PreviousFaultVal[ByteCount] |= (1 << BitCount);
-                            AddFaultCodeToBuf(EventCodeTmp);
-                        }
-                        event_info("%s\n", EventCodeTmp); //DS60-120 add
-                        DB_Insert_Record(localDb, EventCodeTmp); //DS60-120 add
-                    }
+        for (ByteCounter = 0; ByteCounter < sizeof(pFaultCode->PreviousFaultVal); ByteCounter++) {
+            usleep(WRITE_FLASH_TIME);
+            if (pFaultCode->FaultEvents.FaultVal[ByteCounter] == pFaultCode->PreviousFaultVal[ByteCounter]) {
+                continue;
+            }
+
+            tmp = pFaultCode->FaultEvents.FaultVal[ByteCounter]; //prevent be modified during following process
+            for (BitCounter = 0; BitCounter < 8; BitCounter++) {
+                usleep(WRITE_FLASH_TIME);
+                if (((tmp >> BitCounter) & 0x01) == ((pFaultCode->PreviousFaultVal[ByteCounter] >> BitCounter) & 0x01)) {
+                    continue;
                 }
+
+                memset(EventCodeTmp, 0, sizeof(EventCodeTmp));
+                memcpy(EventCodeTmp, GetFaultStatusCode(ByteCounter * 8 + BitCounter), sizeof(EventCodeTmp) - 1);
+                if (((tmp >> BitCounter) & 0x01) == 0) { //Recovered
+                    //EventCodeTmp[0]=1;
+                    log_info("Recovery Fault Code = %s\n", EventCodeTmp);
+                    pFaultCode->PreviousFaultVal[ByteCounter] &= ~(1 << BitCounter);
+                    RemoveFaultCodeToBuf(EventCodeTmp);
+                    EventCodeTmp[0] = '1';//DS60-120 add
+                } else {
+                    log_info("Fault Code = %s\n", EventCodeTmp);
+                    pFaultCode->PreviousFaultVal[ByteCounter] |= (1 << BitCounter);
+                    AddFaultCodeToBuf(EventCodeTmp);
+                }
+                event_info("%s\n", EventCodeTmp); //DS60-120 add
+                InsertEventRecord(EventCodeTmp); //DS60-120 add
             }
         }
 
         //check Alarm Status
-        for (ByteCount = 0; ByteCount < sizeof(ShmStatusCodeData->AlarmCode.PreviousAlarmVal); ByteCount++) {
-            if (ShmStatusCodeData->AlarmCode.AlarmEvents.AlarmVal[ByteCount] != ShmStatusCodeData->AlarmCode.PreviousAlarmVal[ByteCount]) {
-                tmp = ShmStatusCodeData->AlarmCode.AlarmEvents.AlarmVal[ByteCount]; //prevent be modified during following process
-                for (BitCount = 0; BitCount < 8; BitCount++) {
-                    if (((tmp >> BitCount) & 0x01) != ((ShmStatusCodeData->AlarmCode.PreviousAlarmVal[ByteCount] >> BitCount) & 0x01)) {
-                        memset(EventCodeTmp, 0, sizeof(EventCodeTmp));
-                        memcpy(EventCodeTmp, GetAlarmStatusCode(ByteCount * 8 + BitCount), sizeof(EventCodeTmp) - 1);
-                        if (((tmp >> BitCount) & 0x01) == 0) { //Recovered
-                            //EventCodeTmp[0]=1;
-                            log_info("Recovery Alarm Code = %s\n", EventCodeTmp);
-                            ShmStatusCodeData->AlarmCode.PreviousAlarmVal[ByteCount] &= ~(1 << BitCount);
-                            RemoveFaultCodeToBuf(EventCodeTmp);
-                            EventCodeTmp[0] = '1';//DS60-120 add
-                        } else {
-                            log_info("Alarm Code = %s\n", EventCodeTmp);
-                            ShmStatusCodeData->AlarmCode.PreviousAlarmVal[ByteCount] |= (1 << BitCount);
-                            AddFaultCodeToBuf(EventCodeTmp);
-                        }
-                        event_info("%s\n", EventCodeTmp); //DS60-120 add
-                        DB_Insert_Record(localDb, EventCodeTmp); //DS60-120 add
-                    }
+        for (ByteCounter = 0; ByteCounter < sizeof(pAlarmCode->PreviousAlarmVal); ByteCounter++) {
+            usleep(WRITE_FLASH_TIME);
+            if (pAlarmCode->AlarmEvents.AlarmVal[ByteCounter] == pAlarmCode->PreviousAlarmVal[ByteCounter]) {
+                continue;
+            }
+
+            tmp = pAlarmCode->AlarmEvents.AlarmVal[ByteCounter]; //prevent be modified during following process
+            for (BitCounter = 0; BitCounter < 8; BitCounter++) {
+                usleep(WRITE_FLASH_TIME);
+                if (((tmp >> BitCounter) & 0x01) == ((pAlarmCode->PreviousAlarmVal[ByteCounter] >> BitCounter) & 0x01)) {
+                    continue;
+                }
+
+                memset(EventCodeTmp, 0, sizeof(EventCodeTmp));
+                memcpy(EventCodeTmp, GetAlarmStatusCode(ByteCounter * 8 + BitCounter), sizeof(EventCodeTmp) - 1);
+                if (((tmp >> BitCounter) & 0x01) == 0) { //Recovered
+                    //EventCodeTmp[0]=1;
+                    log_info("Recovery Alarm Code = %s\n", EventCodeTmp);
+                    pAlarmCode->PreviousAlarmVal[ByteCounter] &= ~(1 << BitCounter);
+                    RemoveFaultCodeToBuf(EventCodeTmp);
+                    EventCodeTmp[0] = '1';//DS60-120 add
+                } else {
+                    log_info("Alarm Code = %s\n", EventCodeTmp);
+                    pAlarmCode->PreviousAlarmVal[ByteCounter] |= (1 << BitCounter);
+                    AddFaultCodeToBuf(EventCodeTmp);
                 }
+                event_info("%s\n", EventCodeTmp); //DS60-120 add
+                InsertEventRecord(EventCodeTmp); //DS60-120 add
             }
         }
 
         //check Info Status
-        for (ByteCount = 0; ByteCount < sizeof(ShmStatusCodeData->InfoCode.PreviousInfoVal); ByteCount++) {
-            if (ShmStatusCodeData->InfoCode.InfoEvents.InfoVal[ByteCount] != ShmStatusCodeData->InfoCode.PreviousInfoVal[ByteCount]) {
-                tmp = ShmStatusCodeData->InfoCode.InfoEvents.InfoVal[ByteCount]; //prevent be modified during following process
-                for (BitCount = 0; BitCount < 8; BitCount++) {
-                    if (((tmp >> BitCount) & 0x01) != ((ShmStatusCodeData->InfoCode.PreviousInfoVal[ByteCount] >> BitCount) & 0x01)) {
-                        memset(EventCodeTmp, 0, sizeof(EventCodeTmp));
-                        memcpy(EventCodeTmp, GetInfoStatusCode(ByteCount * 8 + BitCount), sizeof(EventCodeTmp) - 1);
-                        if (((tmp >> BitCount) & 0x01) == 0) { //Recovered
-                            //EventCodeTmp[0]=1;
-                            log_info("Recovery Info Code = %s\n", EventCodeTmp);
-                            ShmStatusCodeData->InfoCode.PreviousInfoVal[ByteCount] &= ~(1 << BitCount);
-                            RemoveFaultCodeToBuf(EventCodeTmp);
-                            EventCodeTmp[0] = '1';//DS60-120 add
-                        } else {
-                            log_info("Info Code = %s\n", EventCodeTmp);
-                            ShmStatusCodeData->InfoCode.PreviousInfoVal[ByteCount] |= (1 << BitCount);
-                            AddFaultCodeToBuf(EventCodeTmp);
-                        }
-                        event_info("%s\n", EventCodeTmp); //DS60-120 add
-                        DB_Insert_Record(localDb, EventCodeTmp); //DS60-120 add
-                    }
+        for (ByteCounter = 0; ByteCounter < sizeof(pInfoCode->PreviousInfoVal); ByteCounter++) {
+            usleep(WRITE_FLASH_TIME);
+            if (pInfoCode->InfoEvents.InfoVal[ByteCounter] == pInfoCode->PreviousInfoVal[ByteCounter]) {
+                continue;
+            }
+
+            tmp = pInfoCode->InfoEvents.InfoVal[ByteCounter]; //prevent be modified during following process
+            for (BitCounter = 0; BitCounter < 8; BitCounter++) {
+                usleep(WRITE_FLASH_TIME);
+                if (((tmp >> BitCounter) & 0x01) == ((pInfoCode->PreviousInfoVal[ByteCounter] >> BitCounter) & 0x01)) {
+                    continue;
+                }
+
+                memset(EventCodeTmp, 0, sizeof(EventCodeTmp));
+                memcpy(EventCodeTmp, GetInfoStatusCode(ByteCounter * 8 + BitCounter), sizeof(EventCodeTmp) - 1);
+                if (((tmp >> BitCounter) & 0x01) == 0) { //Recovered
+                    //EventCodeTmp[0]=1;
+                    log_info("Recovery Info Code = %s\n", EventCodeTmp);
+                    pInfoCode->PreviousInfoVal[ByteCounter] &= ~(1 << BitCounter);
+                    RemoveFaultCodeToBuf(EventCodeTmp);
+                    EventCodeTmp[0] = '1';//DS60-120 add
+                } else {
+                    log_info("Info Code = %s\n", EventCodeTmp);
+                    pInfoCode->PreviousInfoVal[ByteCounter] |= (1 << BitCounter);
+                    AddFaultCodeToBuf(EventCodeTmp);
                 }
+                event_info("%s\n", EventCodeTmp); //DS60-120 add
+                InsertEventRecord(EventCodeTmp); //DS60-120 add
             }
         }
         usleep(500000);

+ 13 - 4
EVSE/Projects/DD360Audi/Apps/ModuleInternalComm/internalComm.c

@@ -994,9 +994,18 @@ int Config_CSU_Mode(uint8_t fd, uint8_t targetAddr)
 int Config_Led_Color(uint8_t fd, uint8_t targetAddr, Led_Color *Ret_Buf)
 {
     int result = FAIL;
-    uint8_t tx[13] = {0xaa, 0x00, targetAddr, CMD_CONFIG_LEN_COLOR, 0x06, 0x00,
-                      Ret_Buf->Connect_1_Red, Ret_Buf->Connect_1_Green, Ret_Buf->Connect_1_Blue,
-                      Ret_Buf->Connect_2_Red, Ret_Buf->Connect_2_Green, Ret_Buf->Connect_2_Blue
+    uint8_t tx[13] = {0xaa,
+                      0x00,
+                      targetAddr,
+                      CMD_CONFIG_LEN_COLOR,
+                      0x06,
+                      0x00,
+                      Ret_Buf->Connect_1_Red,
+                      Ret_Buf->Connect_1_Green,
+                      Ret_Buf->Connect_1_Blue,
+                      Ret_Buf->Connect_2_Red,
+                      Ret_Buf->Connect_2_Green,
+                      Ret_Buf->Connect_2_Blue
                      };
     uint8_t rx[512];
     uint8_t chksum = 0x00;
@@ -1004,7 +1013,7 @@ int Config_Led_Color(uint8_t fd, uint8_t targetAddr, Led_Color *Ret_Buf)
     for (int idx = 0; idx < (tx[4] | tx[5] << 8); idx++) {
         chksum ^= tx[6 + idx];
     }
-    tx[13] = chksum;
+    tx[12] = chksum;
 
 //  for(int i = 0; i < 13; i++)
 //          printf ("tx = %x \n", tx[i]);

A diferenza do arquivo foi suprimida porque é demasiado grande
+ 413 - 187
EVSE/Projects/DD360Audi/Apps/ModuleLcmCtrl/Module_LcmControl.c


+ 19 - 238
EVSE/Projects/DD360Audi/Apps/ModuleLcmCtrl/Module_LcmControl.h

@@ -1,59 +1,27 @@
-#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>
+#ifndef MODULE_LCM_CTRL_H_
+#define MODULE_LCM_CTRL_H_
 
-#include <unistd.h>
-#include <stdarg.h>
-#include <stdio.h>      /*標準輸入輸出定義*/
-#include <stdlib.h>     /*標準函數庫定義*/
-#include <unistd.h>     /*Unix 標準函數定義*/
-#include <fcntl.h>      /*檔控制定義*/
-#include <termios.h>    /*PPSIX 終端控制定義*/
-#include <errno.h>      /*錯誤號定義*/
-#include <errno.h>
-#include <string.h>
-#include <time.h>
-#include <ctype.h>
-#include <ifaddrs.h>
-#include <stdbool.h>
-#include "../Define/define.h"
-#include "../Config.h"
+//------------------------------------------------------------------------------
+#define DEFAULT_AC_INDEX                        (2)
 
-struct SysConfigAndInfo         *ShmSysConfigAndInfo;
-struct StatusCodeData           *ShmStatusCodeData;
-struct FanModuleData            *ShmFanModuleData;
-struct PrimaryMcuData           *ShmPrimaryMcuData;
+#define TIME_MAX_SEC                            (2592000) // 一個月,秒數
+#define POWER_MAX_KW                            (5000)
+#define ENERGY_MAX_KWH                          (5000)
 
-#define DEFAULT_AC_INDEX        2
+#define CMD_TITLE_1                             (0x5A)
+#define CMD_TITLE_2                             (0xA5)
+#define CMD_READ                                (0x80)
+#define CMD_WRITE                               (0x81)
+#define CMD_MULTI_WRITE                         (0x82)
+#define CMD_MULTI_READ                          (0x83)
 
-#define TIME_MAX_SEC            2592000 // 一個月,秒數
-#define POWER_MAX_KW            5000
-#define ENERGY_MAX_KWH          5000
+#define CMD_BACKLIGHT                           (0x01)
+#define CMD_REGISTER                            (0x03)
 
-#define CMD_TITLE_1             0x5A
-#define CMD_TITLE_2             0xA5
-#define CMD_READ                0x80
-#define CMD_WRITE               0x81
-#define CMD_MULTI_WRITE         0x82
-#define CMD_MULTI_READ          0x83
-
-#define CMD_BACKLIGHT           0x01
-#define CMD_REGISTER            0x03
-
-//#define NOODOE_QR_CODE_URL      "https://ev-alpha-test.noodoe.com/station?id=" ////For Audi
-#define NOODOE_QR_CODE_URL      "https://ev.noodoe.com/station?id=" ////For Audi
+//#define NOODOE_QR_CODE_URL                    "https://ev-alpha-test.noodoe.com/station?id=" ////For Audi
+#define NOODOE_QR_CODE_URL                      "https://ev.noodoe.com/station?id=" ////For Audi
 
+//------------------------------------------------------------------------------
 enum _BATTERY_LEVEL_FOR_MAP {
     _BATTERY_LEVEL_FOR_MAP_EMP = 0x00,
     _BATTERY_LEVEL_FOR_MAP_LV1 = 0x01,
@@ -63,191 +31,4 @@ enum _BATTERY_LEVEL_FOR_MAP {
     _BATTERY_LEVEL_FOR_MAP_LV5 = 0x05,
 };
 
-int _port;
-//char* pPortName         = "/dev/ttyO2";
-char *pPortName           = "/dev/ttyS3";
-char *moduleName          = "DMT80480T070_09WT";
-uint8_t _totalCount;
-uint8_t acgunCount;
-struct ChargingInfoData *_chargingInfoData[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
-struct ChargingInfoData *ac_chargingInfo[AC_QUANTITY];
-
-uint8_t ac_ani_battery_level = _BATTERY_LEVEL_FOR_MAP_LV5;
-uint8_t isDiffStatus         = false;
-uint8_t isChangeBattMap      = false;
-// 當前選擇的槍號
-#if defined DD360Audi
-short _currentPage        = _LCM_SELECT_GUN;
-short _oldPage            = _LCM_SELECT_GUN;
-#else
-short _currentPage        = _LCM_NONE;
-short _oldPage            = _LCM_NONE;
-#endif //defined DD360Audi
-uint8_t _gunIndex            = 0;
-bool _wifi_conn_status    = false;
-bool _battery_display_ani = false;
-uint8_t _curPage_index       = 0;
-bool _page_reload         = false;
-
-// LCM - HW
-uint8_t _everyPageRollChange    = 0;
-short __conn_status          = 0x0030;
-short __ethernet_status      = 0x0032;
-short __3G4G_status          = 0x0036;
-short __3G4G_status1         = 0x0037;
-short __3G4G_move_status     = 0x0038;
-short __wifi_status          = 0x003C;
-
-short __sel_gun_btn          = 0x0040;
-short __ret_home_btn         = 0x0042;
-short __stop_method_btn      = 0x0044;
-
-short __qr_code              = 0x0250;
-short __main_rfid            = 0x0052;
-short __main_qr              = 0x0054;
-short __main_app             = 0x0056;
-
-short __plug_in_arrow        = 0x0060;
-
-short __conn_line            = 0x0066;
-
-short __gun_type_index       = 0x0070;
-short __cmp_gun_type_index   = 0x0080; ////For Audi
-short __batt_map_empty       = 0x0090; ////For Audi
-short __qr_code_pre          = 0x0280;
-
-short __side_top             = 0x0090;
-short __side_down            = 0x0092;
-short __side_mid             = 0x0094;
-
-short __conn_line_chag       = 0x0096;
-short __batt_map             = 0x0100;
-short __soc_value_charging   = 0x0102;
-short __remain_time_map      = 0x0106;
-short __power_map            = 0x0108;
-short __energy_map           = 0x010A;
-short __remain_time_tx       = 0x0110;
-
-short __trp_remain_time_map = 0x0116;
-short __trp_power_map = 0x0118;
-short __trp_energy_map = 0x011A;
-
-short __output_eng_tx        = 0x0120;
-short __total_out_eng_tx     = 0x0130;
-short __conn_line_comp       = 0x0140;
-short __charging_fee_map     = 0x0146;
-short __charging_fee_tx      = 0x0150;
-
-short __money_by_rate        = 0x0200;
-short __money_rate           = 0x0220;
-short __money_rate_map       = 0x0230;
-
-//DS60-120 add
-short __csu_ver_string = 0x0300;
-short __csu_ver_value = 0x0310;
-short __fan_speed_string = 0x0390;
-short __fan_speed_value = 0x0400;
-
-short __dc1_ver_string = 0x0320;
-short __dc1_ver_value = 0x0330;
-short __dc2_ver_string = 0x0340;
-short __dc2_ver_value = 0x0350;
-short __eth0_ip_string = 0x0360;
-short __eth0_ip_value = 0x0370;
-short __sn_string = 0x0410;
-short __sn_value = 0x0420;
-
-//For Audi, for select gun
-short __left_gun_map         = 0x0260;
-short __right_gun_map        = 0x0262;
-short __add_chk_btn          = 0x0264;
-//short __station_id         = 0x0270;
-short __balance              = 0x0270;
-short __remain_balance       = 0x0280;
-short __custStationIdL1      = 0x0450;
-//short __custStationIdL2      = 0x0470;
-short _emergency_map         = 0x011C;
-
-// ICON ID
-uint8_t _disappear              = 0;
-uint8_t _disconnect             = 1;
-uint8_t _connect                = 2;
-uint8_t _warning                = 3;
-uint8_t _arrow_dark             = 4;
-uint8_t _arrow_light            = 5;
-uint8_t _3G4G_disconnect        = 6;
-uint8_t __3G4G_connect          = 7;
-uint8_t _wifi_disconnect        = 8;
-uint8_t _wifi_connect           = 9;
-uint8_t _logo                   = 10;
-uint8_t _conn_map1              = 11;
-uint8_t _conn_map2              = 12;
-uint8_t _sel_gun_btn            = 13;
-uint8_t _back_home_btn          = 14;
-uint8_t _stop_charging_btn      = 15;
-uint8_t _stop_charging_btn_scan = 16;
-uint8_t _chademo_dark           = 17;
-uint8_t _ccs_dark               = 18;
-uint8_t _gbt_dark               = 19;
-uint8_t _actype_dark            = 20;
-uint8_t _chademo_light          = 21;
-uint8_t _ccs_light              = 22;
-uint8_t _gbt_light              = 23;
-uint8_t _actype_light           = 24;
-uint8_t _main_none_rfid         = 25;
-uint8_t _main_rfid              = 26;
-uint8_t _main_none_app          = 27;
-uint8_t _main_app               = 28;
-uint8_t _main_none_qr           = 29;
-uint8_t _main_qr                = 30;
-uint8_t _charging_map1          = 31;
-uint8_t _charging_map2          = 32;
-uint8_t _battery_empty          = 33;
-uint8_t _battery_cap_20         = 34;
-uint8_t _battery_cap_40         = 35;
-uint8_t _battery_cap_60         = 36;
-uint8_t _battery_cap_80         = 37;
-uint8_t _battery_cap_100        = 38;
-uint8_t _battery_map            = 39;
-uint8_t _power_map              = 40;
-uint8_t _time_map               = 41;
-uint8_t _complete_map           = 42;
-uint8_t _battery_soc_20         = 43;
-uint8_t _battery_soc_40         = 44;
-uint8_t _battery_soc_60         = 45;
-uint8_t _battery_soc_80         = 46;
-uint8_t _battery_soc_100        = 47;
-uint8_t _battery_eng_map        = 48;
-uint8_t _money_map              = 49;
-uint8_t _elapse_time_map        = 50;
-uint8_t _charging_money         = 51;
-//uint8_t _side_none_rfid       = 52;
-//uint8_t _side_rfid            = 53;
-//uint8_t _side_none_app        = 54;
-//uint8_t _side_app             = 55;
-//uint8_t _side_none_qr         = 56;
-//uint8_t _side_qr              = 57;
-uint8_t _eth_disconnect         = 52; //58;
-uint8_t _eth_connect            = 53; //59;
-
-uint8_t _chademo_dark_cmp       = 54;
-uint8_t _ccs_dark_cmp           = 55;
-uint8_t _gbt_dark_cmp           = 56;
-uint8_t _actype_dark_cmp        = 57;
-uint8_t _chademo_light_cmp      = 58;
-uint8_t _ccs_light_cmp          = 59;
-uint8_t _gbt_light_cmp          = 60;
-uint8_t _actype_light_cmp       = 61;
-
-uint8_t _logo_cmp = 62;
-uint8_t _battery_eng_trp_map = 63;
-uint8_t _money_trp_map = 64;
-uint8_t _elapse_time_trp_map = 65;
-
-////For Audi
-uint8_t _left_gun_disable_map   = 66;
-uint8_t _left_gun_enable_map    = 67;
-uint8_t _right_gun_disable_map  = 68;
-uint8_t _right_gun_enable_map   = 69;
-uint8_t _select_gun_btn         = 70;
-uint8_t _emergency_disable_map  = 72;
+#endif //MODULE_LCM_CTRL_H_

+ 191 - 173
EVSE/Projects/DD360Audi/Apps/ModulePrimary/Module_PrimaryComm.c

@@ -29,22 +29,29 @@
 #include <ifaddrs.h>
 #include <math.h>
 
+#include "../Log/log.h"
 #include "../Define/define.h"
 #include "../Config.h"
+#include "../ShareMemory/shmMem.h"
 #include "PrimaryComm.h"
 #include "Module_PrimaryComm.h"
 
-struct SysConfigAndInfo *ShmSysConfigAndInfo;
-struct StatusCodeData *ShmStatusCodeData;
-struct PrimaryMcuData *ShmPrimaryMcuData;
+//------------------------------------------------------------------------------
+//struct SysConfigAndInfo *ShmSysConfigAndInfo;
+//struct StatusCodeData *ShmStatusCodeData;
+static struct SysConfigData *pSysConfig = NULL;
+static struct SysInfoData *pSysInfo = NULL;
+static struct AlarmCodeData *pAlarmCode = NULL;
+static struct FaultCodeData *pFaultCode = NULL;
+static struct PrimaryMcuData *ShmPrimaryMcuData;
 
 const char *priPortName = "/dev/ttyS1";
 uint8_t gun_count; //DS60-120 add
 
-struct ChargingInfoData *ChargingData[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
+//struct ChargingInfoData *ChargingData[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
 
 //------------------------------------------------------------------------------
-int StoreLogMsg(const char *fmt, ...)
+/*int StoreLogMsg(const char *fmt, ...)
 {
     char Buf[4096 + 256];
     char buffer[4096];
@@ -61,7 +68,7 @@ int StoreLogMsg(const char *fmt, ...)
     SeqEndTime.time = time(NULL);
     tm = localtime(&SeqEndTime.time);
 
-    if (ShmSysConfigAndInfo->SysConfig.SwitchDebugFlag == YES) {
+    if (pSysConfig->SwitchDebugFlag == YES) {
         sprintf(Buf, "%02d:%02d:%02d:%03d - %s",
                 tm->tm_hour, tm->tm_min, tm->tm_sec, SeqEndTime.millitm, buffer);
         printf("%s \n", Buf);
@@ -75,7 +82,9 @@ int StoreLogMsg(const char *fmt, ...)
 
     return rc;
 }
+*/
 
+#if 0 //non use
 int DiffTimeb(struct timeb ST, struct timeb ET)
 {
     //return milli-second
@@ -97,15 +106,22 @@ char *getTimeString(void)
     time(&timep);
     p = gmtime(&timep);
 
-    sprintf(result, "[%04d-%02d-%02d %02d:%02d:%02d]", (1900 + p->tm_year), (1 + p->tm_mon), p->tm_mday, p->tm_hour, p->tm_hour, p->tm_sec);
+    sprintf(result, "[%04d-%02d-%02d %02d:%02d:%02d]",
+            (1900 + p->tm_year),
+            (1 + p->tm_mon),
+            p->tm_mday,
+            p->tm_hour,
+            p->tm_hour,
+            p->tm_sec);
 
     return result;
 }
+#endif //0
 
 //==========================================
 // Init all share memory
 //==========================================
-int InitShareMemory()
+/*int InitShareMemory()
 {
     int result = PASS;
     int MeterSMId;
@@ -133,6 +149,7 @@ int InitShareMemory()
 
     return result;
 }
+*/
 
 //================================================
 // Function
@@ -144,7 +161,7 @@ void GetFwAndHwVersion(int fd)
     if (Query_FW_Ver(fd, OP_ADDR_IO_EXTEND, &ver) == PASS) {
         //log_info("Primary FW Rev = %s \n", ver.Version_FW);
         strcpy((char *)ShmPrimaryMcuData->version, ver.Version_FW);
-        strcpy((char *) ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev, ver.Version_FW);
+        strcpy((char *) pSysInfo->CsuPrimFwRev, ver.Version_FW);
     }
 
     //if (Query_HW_Ver(fd, OP_ADDR_IO_EXTEND, &ver) == PASS)
@@ -158,113 +175,110 @@ void GetInputGpioStatus(int fd)
     static uint8_t dispenserSw = 0;
 
     //log_info("GetInputGpioStatus \n");
-    if (Query_Gpio_Input(fd, OP_ADDR_IO_EXTEND, &gpio_in) == PASS) {
-#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
-        static uint8_t _curDeviceStatus[3] = {0};
-        static uint8_t _reCheckCount[3] = {0};
-
-        //DS60-120 add
-        if (_curDeviceStatus[_PRIMARY_CHECK_TAG_AC_CONTACT] != gpio_in.AC_Connector) {
-            if (_reCheckCount[_PRIMARY_CHECK_TAG_AC_CONTACT] >= 3) {
-                _curDeviceStatus[_PRIMARY_CHECK_TAG_AC_CONTACT] = gpio_in.AC_Connector;
-                ShmSysConfigAndInfo->SysInfo.AcContactorStatus =
-                    ShmPrimaryMcuData->InputDet.bits.AcContactorDetec =
-                        gpio_in.AC_Connector;
-            } else {
-                _reCheckCount[_PRIMARY_CHECK_TAG_AC_CONTACT]++;
-            }
-        } else {
-            _reCheckCount[_PRIMARY_CHECK_TAG_AC_CONTACT] = 0;
-        }
-
-        if (_curDeviceStatus[_PRIMARY_CHECK_TAG_MAIN_BREAKER] != gpio_in.AC_MainBreaker) {
-            if (_reCheckCount[_PRIMARY_CHECK_TAG_MAIN_BREAKER] >= 3) {
-                _curDeviceStatus[_PRIMARY_CHECK_TAG_MAIN_BREAKER] = gpio_in.AC_MainBreaker;
-                ShmPrimaryMcuData->InputDet.bits.AcMainBreakerDetec = gpio_in.AC_MainBreaker;
-            } else {
-                _reCheckCount[_PRIMARY_CHECK_TAG_MAIN_BREAKER]++;
-            }
-        } else {
-            _reCheckCount[_PRIMARY_CHECK_TAG_MAIN_BREAKER] = 0;
-        }
-        //ShmSysConfigAndInfo->SysInfo.AcContactorStatus = ShmPrimaryMcuData->InputDet.bits.AcContactorDetec = gpio_in.AC_Connector;
-        //ShmPrimaryMcuData->InputDet.bits.AcMainBreakerDetec = gpio_in.AC_MainBreaker;
-#else
-        if ((strncmp((char *)&ShmSysConfigAndInfo->SysConfig.ModelName[7], "V", 1) == 0) ||
-                (strncmp((char *)&ShmSysConfigAndInfo->SysConfig.ModelName[9], "V", 1) == 0) ||
-                (strncmp((char *)&ShmSysConfigAndInfo->SysConfig.ModelName[7], "F", 1) == 0) ||
-                (strncmp((char *)&ShmSysConfigAndInfo->SysConfig.ModelName[9], "F", 1) == 0)
-           ) {
-            ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsLiquidChillerWaterLevelWarning = ~gpio_in.AC_Connector;
-            ShmStatusCodeData->FaultCode.FaultEvents.bits.CcsLiquidChillerWaterLevelFault = ~gpio_in.AC_MainBreaker;
-        } else {
-            ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsLiquidChillerWaterLevelWarning = gpio_in.AC_Connector;
-            ShmStatusCodeData->FaultCode.FaultEvents.bits.CcsLiquidChillerWaterLevelFault = gpio_in.AC_MainBreaker;
-        }
-#endif //!defined DD360 && !defined DD360Audi
+    if (Query_Gpio_Input(fd, OP_ADDR_IO_EXTEND, &gpio_in) != PASS) {
+        return;
+    }
 
-        ShmPrimaryMcuData->InputDet.bits.SpdDetec = gpio_in.SPD;
-#if defined DD360 ||defined DD360Audi || defined DD360ComBox
+    ShmPrimaryMcuData->InputDet.bits.SpdDetec = gpio_in.SPD;
 
 #if defined DD360ComBox
-        ShmPrimaryMcuData->InputDet.bits.DoorOpen = gpio_in.Door_Open;
-#else
-        ShmPrimaryMcuData->InputDet.bits.DoorOpen = ~gpio_in.Door_Open;
-#endif //
-
-        ShmPrimaryMcuData->InputDet.bits.Key0 = ~gpio_in.Key[0] & 0x01;
-        ShmPrimaryMcuData->InputDet.bits.Key1 = ~gpio_in.Key[1] & 0x01;
-        ShmPrimaryMcuData->InputDet.bits.Key2 = ~gpio_in.Key[2] & 0x01;
-        ShmPrimaryMcuData->InputDet.bits.Key3 = ~gpio_in.Key[3] & 0x01;
-        //ShmPrimaryMcuData->InputDet.bits.EmergencyButton = gpio_in.Emergency_Btn;
+    ShmPrimaryMcuData->InputDet.bits.EmergencyButton = ~gpio_in.Emergency_Btn;
 #else
+    ShmPrimaryMcuData->InputDet.bits.EmergencyButton = gpio_in.Emergency_Btn;
+#endif //defined DD360ComBox
+
+    dispenserSwTmp |= (ShmPrimaryMcuData->InputDet.bits.Key0);
+    dispenserSwTmp |= (ShmPrimaryMcuData->InputDet.bits.Key1 << 1);
+    dispenserSwTmp |= (ShmPrimaryMcuData->InputDet.bits.Key2 << 2);
+    dispenserSwTmp |= (ShmPrimaryMcuData->InputDet.bits.Key3 << 3);
+
+    if (dispenserSwTmp != dispenserSw) {
+        dispenserSw = dispenserSwTmp;
+        log_info("Dispenser switch number =  %d, bit = %d, %d, %d, %d\r\n",
+                 dispenserSw,
+                 ShmPrimaryMcuData->InputDet.bits.Key3,
+                 ShmPrimaryMcuData->InputDet.bits.Key2,
+                 ShmPrimaryMcuData->InputDet.bits.Key1,
+                 ShmPrimaryMcuData->InputDet.bits.Key0);
+    }
 
-        ShmPrimaryMcuData->InputDet.bits.Key0 = gpio_in.Key[0] & 0x01;
-        ShmPrimaryMcuData->InputDet.bits.Key1 = gpio_in.Key[1] & 0x01;
-        ShmPrimaryMcuData->InputDet.bits.Key2 = gpio_in.Key[2] & 0x01;
-        ShmPrimaryMcuData->InputDet.bits.Key3 = gpio_in.Key[3] & 0x01;
-        //ShmPrimaryMcuData->InputDet.bits.EmergencyButton = ~gpio_in.Emergency_Btn;
-        ShmPrimaryMcuData->InputDet.bits.DoorOpen = gpio_in.Door_Open;
-#endif //defined DD360 ||defined DD360Audi
+    ShmPrimaryMcuData->InputDet.bits.Button1 = gpio_in.Button[0];
+    ShmPrimaryMcuData->InputDet.bits.Button2 = gpio_in.Button[1];
+
+#if defined DD360 || defined DD360Audi || defined DD360ComBox
+    if ((strncmp((char *)&pSysConfig->ModelName[7], "V", 1) == 0) ||
+            (strncmp((char *)&pSysConfig->ModelName[9], "V", 1) == 0) ||
+            (strncmp((char *)&pSysConfig->ModelName[7], "F", 1) == 0) ||
+            (strncmp((char *)&pSysConfig->ModelName[9], "F", 1) == 0)
+       ) {
+        pAlarmCode->AlarmEvents.bits.CcsLiquidChillerWaterLevelWarning = ~gpio_in.AC_Connector;
+        pFaultCode->FaultEvents.bits.CcsLiquidChillerWaterLevelFault = ~gpio_in.AC_MainBreaker;
+    } else {
+        pAlarmCode->AlarmEvents.bits.CcsLiquidChillerWaterLevelWarning = gpio_in.AC_Connector;
+        pFaultCode->FaultEvents.bits.CcsLiquidChillerWaterLevelFault = gpio_in.AC_MainBreaker;
+    }
 
 #if defined DD360ComBox
-        ShmPrimaryMcuData->InputDet.bits.EmergencyButton = ~gpio_in.Emergency_Btn;
+    ShmPrimaryMcuData->InputDet.bits.DoorOpen = gpio_in.Door_Open;
 #else
-        ShmPrimaryMcuData->InputDet.bits.EmergencyButton = gpio_in.Emergency_Btn;
-#endif //
-
-        dispenserSwTmp |= (ShmPrimaryMcuData->InputDet.bits.Key0);
-        dispenserSwTmp |= (ShmPrimaryMcuData->InputDet.bits.Key1 << 1);
-        dispenserSwTmp |= (ShmPrimaryMcuData->InputDet.bits.Key2 << 2);
-        dispenserSwTmp |= (ShmPrimaryMcuData->InputDet.bits.Key3 << 3);
-
-        if (dispenserSwTmp != dispenserSw) {
-            dispenserSw = dispenserSwTmp;
-            log_info("Dispenser switch number =  %d, bit = %d, %d, %d, %d\r\n",
-                     dispenserSw,
-                     ShmPrimaryMcuData->InputDet.bits.Key3,
-                     ShmPrimaryMcuData->InputDet.bits.Key2,
-                     ShmPrimaryMcuData->InputDet.bits.Key1,
-                     ShmPrimaryMcuData->InputDet.bits.Key0);
+    ShmPrimaryMcuData->InputDet.bits.DoorOpen = ~gpio_in.Door_Open;
+#endif //defined DD360ComBox
+
+    ShmPrimaryMcuData->InputDet.bits.Key0 = ~gpio_in.Key[0] & 0x01;
+    ShmPrimaryMcuData->InputDet.bits.Key1 = ~gpio_in.Key[1] & 0x01;
+    ShmPrimaryMcuData->InputDet.bits.Key2 = ~gpio_in.Key[2] & 0x01;
+    ShmPrimaryMcuData->InputDet.bits.Key3 = ~gpio_in.Key[3] & 0x01;
+
+    return;
+#endif //defined DD360 || defined DD360Audi || defined DD360ComBox
+
+    static uint8_t _curDeviceStatus[3] = {0};
+    static uint8_t _reCheckCount[3] = {0};
+
+    //DS60-120 add
+    if (_curDeviceStatus[_PRIMARY_CHECK_TAG_AC_CONTACT] != gpio_in.AC_Connector) {
+        if (_reCheckCount[_PRIMARY_CHECK_TAG_AC_CONTACT] >= 3) {
+            _curDeviceStatus[_PRIMARY_CHECK_TAG_AC_CONTACT] = gpio_in.AC_Connector;
+            pSysInfo->AcContactorStatus =
+                ShmPrimaryMcuData->InputDet.bits.AcContactorDetec =
+                    gpio_in.AC_Connector;
+        } else {
+            _reCheckCount[_PRIMARY_CHECK_TAG_AC_CONTACT]++;
         }
+    } else {
+        _reCheckCount[_PRIMARY_CHECK_TAG_AC_CONTACT] = 0;
+    }
 
-        ShmPrimaryMcuData->InputDet.bits.Button1 = gpio_in.Button[0];
-        ShmPrimaryMcuData->InputDet.bits.Button2 = gpio_in.Button[1];
-
-        /*printf(" gpio_in.Key[0]~ gpio_in.Key[3]=%d, %d, %d, %d\n",
-        ShmPrimaryMcuData->InputDet.bits.Key0 , ShmPrimaryMcuData->InputDet.bits.Key1,
-        ShmPrimaryMcuData->InputDet.bits.Key2,ShmPrimaryMcuData->InputDet.bits.Key3);
-        printf("ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsLiquidChillerWaterLevelWarning=%d\n", ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CcsLiquidChillerWaterLevelWarning);
-        printf("ShmStatusCodeData->FaultCode.FaultEvents.bits.CcsLiquidChillerWaterLevelFault=%d\n", ShmStatusCodeData->FaultCode.FaultEvents.bits.CcsLiquidChillerWaterLevelFault);
-        */
-        //log_info("left = %d \n", ShmPrimaryMcuData->InputDet.bits.Button1);
-        //log_info("right = %d \n", ShmPrimaryMcuData->InputDet.bits.Button2);
-        //log_info("ShmSysConfigAndInfo->SysInfo.AcContactorStatus = %d \n", ShmSysConfigAndInfo->SysInfo.AcContactorStatus);
-#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
-        if (ShmPrimaryMcuData->InputDet.bits.AcMainBreakerDetec == YES) {
-            log_error("AC Mainbreaker occur. \n");
+    if (_curDeviceStatus[_PRIMARY_CHECK_TAG_MAIN_BREAKER] != gpio_in.AC_MainBreaker) {
+        if (_reCheckCount[_PRIMARY_CHECK_TAG_MAIN_BREAKER] >= 3) {
+            _curDeviceStatus[_PRIMARY_CHECK_TAG_MAIN_BREAKER] = gpio_in.AC_MainBreaker;
+            ShmPrimaryMcuData->InputDet.bits.AcMainBreakerDetec = gpio_in.AC_MainBreaker;
+        } else {
+            _reCheckCount[_PRIMARY_CHECK_TAG_MAIN_BREAKER]++;
         }
-#endif //!defined DD360 && !defined DD360Audi
+    } else {
+        _reCheckCount[_PRIMARY_CHECK_TAG_MAIN_BREAKER] = 0;
+    }
+    //pSysInfo->AcContactorStatus = ShmPrimaryMcuData->InputDet.bits.AcContactorDetec = gpio_in.AC_Connector;
+    //ShmPrimaryMcuData->InputDet.bits.AcMainBreakerDetec = gpio_in.AC_MainBreaker;
+
+    ShmPrimaryMcuData->InputDet.bits.Key0 = gpio_in.Key[0] & 0x01;
+    ShmPrimaryMcuData->InputDet.bits.Key1 = gpio_in.Key[1] & 0x01;
+    ShmPrimaryMcuData->InputDet.bits.Key2 = gpio_in.Key[2] & 0x01;
+    ShmPrimaryMcuData->InputDet.bits.Key3 = gpio_in.Key[3] & 0x01;
+    ShmPrimaryMcuData->InputDet.bits.DoorOpen = gpio_in.Door_Open;
+
+    /*printf(" gpio_in.Key[0]~ gpio_in.Key[3]=%d, %d, %d, %d\n",
+    ShmPrimaryMcuData->InputDet.bits.Key0 , ShmPrimaryMcuData->InputDet.bits.Key1,
+    ShmPrimaryMcuData->InputDet.bits.Key2,ShmPrimaryMcuData->InputDet.bits.Key3);
+    printf("pAlarmCode->AlarmEvents.bits.CcsLiquidChillerWaterLevelWarning=%d\n", pAlarmCode->AlarmEvents.bits.CcsLiquidChillerWaterLevelWarning);
+    printf("pFaultCode->FaultEvents.bits.CcsLiquidChillerWaterLevelFault=%d\n", pFaultCode->FaultEvents.bits.CcsLiquidChillerWaterLevelFault);
+    */
+    //log_info("left = %d \n", ShmPrimaryMcuData->InputDet.bits.Button1);
+    //log_info("right = %d \n", ShmPrimaryMcuData->InputDet.bits.Button2);
+    //log_info("pSysInfo->AcContactorStatus = %d \n", pSysInfo->AcContactorStatus);
+    if (ShmPrimaryMcuData->InputDet.bits.AcMainBreakerDetec == YES) {
+        log_error("AC Mainbreaker occur. \n");
     }
 }
 
@@ -276,13 +290,13 @@ static void checkChillerStatus(Gpio_out *gpio)
     static ChillerInfo fChillerInfo[2] = {0}, *pChillerInfo = NULL;
     Gpio_out *pGpio = (Gpio_out *)gpio;
 
-    if ((strncmp((char *)&ShmSysConfigAndInfo->SysConfig.ModelName[7], "V", 1) == 0) ||
-            (strncmp((char *)&ShmSysConfigAndInfo->SysConfig.ModelName[7], "F", 1) == 0)) {
+    if ((strncmp((char *)&pSysConfig->ModelName[7], "V", 1) == 0) ||
+            (strncmp((char *)&pSysConfig->ModelName[7], "F", 1) == 0)) {
         chillerCount++;
     }
 
-    if ((strncmp((char *)&ShmSysConfigAndInfo->SysConfig.ModelName[9], "V", 1) == 0) ||
-            (strncmp((char *)&ShmSysConfigAndInfo->SysConfig.ModelName[9], "F", 1) == 0)) {
+    if ((strncmp((char *)&pSysConfig->ModelName[9], "V", 1) == 0) ||
+            (strncmp((char *)&pSysConfig->ModelName[9], "F", 1) == 0)) {
         chillerCount++;
     }
 
@@ -292,7 +306,7 @@ static void checkChillerStatus(Gpio_out *gpio)
     }
 
     for (gunIndex = 0; gunIndex < chillerCount; gunIndex++) {
-        pDcChargingInfo = (struct ChargingInfoData *)ChargingData[gunIndex];
+        pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
         pChillerInfo = (ChillerInfo *)&fChillerInfo[gunIndex];
 
         if ((pDcChargingInfo->PresentChargingCurrent) >= 150) { //當前電壓於150A,打開水冷機
@@ -325,7 +339,7 @@ void SetOutputGpio(int fd, uint8_t outputValue)
     LedConfig *pLedConfig = (LedConfig *)&outputValue;
     static uint8_t flash = NO;
 
-    if (strcmp((char *)ShmSysConfigAndInfo->SysInfo.LcmHwRev, " ") == 0x00) {
+    if (strcmp((char *)pSysInfo->LcmHwRev, " ") == 0x00) {
         if (flash == NO) {
             flash = YES;
         } else {
@@ -400,7 +414,7 @@ void SetRtcData(int fd)
 
 void SetModelName(int fd)
 {
-    if (Config_Model_Name(fd, OP_ADDR_IO_EXTEND, ShmSysConfigAndInfo->SysConfig.ModelName) == PASS) {
+    if (Config_Model_Name(fd, OP_ADDR_IO_EXTEND, pSysConfig->ModelName) == PASS) {
     }
 }
 
@@ -441,78 +455,82 @@ unsigned long GetTimeoutValue(struct timeval _sour_time)
     return 1000000 * (_end_time.tv_sec - _sour_time.tv_sec) + _end_time.tv_usec - _sour_time.tv_usec;
 }
 
-int FindChargingInfoData(uint8_t target, struct ChargingInfoData **chargingData)
-{
-    for (uint8_t index = 0; index < CHAdeMO_QUANTITY; index++) {
-        if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == target) {
-            chargingData[target] = &ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index];
-            return 1;
-        }
-    }
-
-    for (uint8_t index = 0; index < CCS_QUANTITY; index++) {
-        if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == target) {
-            chargingData[target] = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[index];
-            return 1;
-        }
-    }
-
-    for (uint8_t index = 0; index < GB_QUANTITY; index++) {
-        if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == target) {
-            chargingData[target] = &ShmSysConfigAndInfo->SysInfo.GbChargingData[index];
-            return 1;
-        }
-    }
-
-    return 0;
-}
-
-void Initialization() //DS60-120 add
-{
-    bool isPass = false;
-    while (!isPass) {
-        isPass = true;
-        for (uint8_t _index = 0; _index < gun_count; _index++) {
-            if (!FindChargingInfoData(_index, &ChargingData[0])) {
-                log_error("EvComm (main) : FindChargingInfoData false \n");
-                isPass = false;
-                break;
-            }
-        }
-        sleep(1);
-    }
-}
+//int FindChargingInfoData(uint8_t target, struct ChargingInfoData **chargingData)
+//{
+//    for (uint8_t index = 0; index < CHAdeMO_QUANTITY; index++) {
+//        if (pSysInfo->ChademoChargingData[index].Index == target) {
+//            chargingData[target] = &pSysInfo->ChademoChargingData[index];
+//            return 1;
+//        }
+//    }
+//
+//    for (uint8_t index = 0; index < CCS_QUANTITY; index++) {
+//        if (pSysInfo->CcsChargingData[index].Index == target) {
+//            chargingData[target] = &pSysInfo->CcsChargingData[index];
+//            return 1;
+//        }
+//    }
+//
+//    for (uint8_t index = 0; index < GB_QUANTITY; index++) {
+//        if (pSysInfo->GbChargingData[index].Index == target) {
+//            chargingData[target] = &pSysInfo->GbChargingData[index];
+//            return 1;
+//        }
+//    }
+//
+//    return 0;
+//}
+
+//void Initialization() //DS60-120 add
+//{
+//    bool isPass = false;
+//    while (!isPass) {
+//        isPass = true;
+//        for (uint8_t _index = 0; _index < gun_count; _index++) {
+//            if (!FindChargingInfoData(_index, &ChargingData[0])) {
+//                log_error("EvComm (main) : FindChargingInfoData false \n");
+//                isPass = false;
+//                break;
+//            }
+//        }
+//        sleep(1);
+//    }
+//}
 
 int main(void)
 {
     int Uart1Fd = -1;
 
-    if (InitShareMemory() == FAIL) {
-        log_error("InitShareMemory NG\r\n");
-        if (ShmStatusCodeData != NULL) {
-            ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory = 1;
-        }
-        sleep(5);
-        return 0;
-    }
-
-    //DS60-120 remove
-    //for (uint8_t _index = 0; _index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _index++) {
-    //    if (!FindChargingInfoData(_index, &ChargingData[0])) {
-    //        log_error("FindChargingInfoData false \n");
-    //        break;
+    //if (InitShareMemory() == FAIL) {
+    //    log_error("InitShareMemory NG\r\n");
+    //    if (ShmStatusCodeData != NULL) {
+    //        pAlarmCode->AlarmEvents.bits.FailToCreateShareMemory = 1;
     //    }
+    //    sleep(5);
+    //    return 0;
     //}
 
+    if (CreateAllCsuShareMemory() == FAIL) {
+        log_error("create share memory error\r\n");
+        return FAIL;
+    }
+
+    MappingGunChargingInfo("Primary Task");
+
+    pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
+    pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
+    pAlarmCode = (struct AlarmCodeData *)GetShmAlarmCodeData();
+    pFaultCode = (struct FaultCodeData *)GetShmFaultCodeData();
+    ShmPrimaryMcuData = (struct PrimaryMcuData *)GetShmPrimaryMcuData();
+
     Uart1Fd = InitComPort();
     //log_info("407 Port id = %d \n", Uart1Fd);
 
     if (Uart1Fd < 0) {
-#ifdef SystemLogMessage
         log_error("InitComPort (Uart1 : AM3352 - STM32) NG");
-#endif
-        if (ShmStatusCodeData != NULL) {
-            ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed = 1;
+
+        if (pAlarmCode != NULL) {
+            pAlarmCode->AlarmEvents.bits.CsuInitFailed = 1;
         }
         sleep(5);
 
@@ -522,9 +540,9 @@ int main(void)
     SetRtcData(Uart1Fd);
     SetModelName(Uart1Fd);
 
-    gun_count = ShmSysConfigAndInfo->SysConfig.TotalConnectorCount;
+    gun_count = pSysConfig->TotalConnectorCount;
 
-    Initialization();
+    //Initialization();
 
     for (;;) {
         // 程序開始之前~ 必須先確定 FW 版本與硬體版本,確認後!!~ 該模組才算是真正的 Initial Comp.

+ 4 - 4
EVSE/Projects/DD360Audi/Apps/ModulePrimary/Module_PrimaryComm.h

@@ -5,9 +5,9 @@
 #include <stdint.h>
 
 //------------------------------------------------------------------------------
-#define log_info(format, args...) StoreLogMsg("[%s:%d][%s][Info] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
-#define log_warn(format, args...) StoreLogMsg("[%s:%d][%s][Warn] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
-#define log_error(format, args...) StoreLogMsg("[%s:%d][%s][Error] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
+//#define log_info(format, args...) StoreLogMsg("[%s:%d][%s][Info] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
+//#define log_warn(format, args...) StoreLogMsg("[%s:%d][%s][Warn] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
+//#define log_error(format, args...) StoreLogMsg("[%s:%d][%s][Error] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
 
 //------------------------------------------------------------------------------
 typedef struct StChillerInfo {
@@ -29,6 +29,6 @@ typedef struct StLedConfig {
 } LedConfig;
 
 //------------------------------------------------------------------------------
-int StoreLogMsg(const char *fmt, ...);
+//int StoreLogMsg(const char *fmt, ...);
 
 #endif /* _MODULE_PRIMARY_COMM_H_ */

+ 2 - 1
EVSE/Projects/DD360Audi/Apps/ModulePrimary/PrimaryComm.c

@@ -27,8 +27,9 @@
 #include <ctype.h>
 #include <ifaddrs.h>
 #include <math.h>
-#include "../Config.h"
 
+#include "../Log/log.h"
+#include "../Config.h"
 #include "Module_PrimaryComm.h"
 #include "PrimaryComm.h"
 

+ 93 - 52
EVSE/Projects/DD360Audi/Apps/ReadCmdline.c

@@ -54,6 +54,7 @@
 #define STTY_US             "stty raw -echo -F "
 #define STTY_DEF            "stty -raw echo -F "
 
+//------------------------------------------------------------------------------
 uint8_t _curAutoRunCount = 0;
 uint8_t _usingAutoRun = 0;
 struct timeval _autoTime;
@@ -80,7 +81,10 @@ char *msg = "state : get gun state (index) \n"
             "lock : get gun locked state (index) \n"
             "self : self test state (x) \n"
             "ver : ver of board (407 or index or rb or fan) \n"
-            "ac : get ac relay state (x) \n";
+            "ac : get ac relay state (x) \n"
+            "tempT : set connector header temperature\r\n"
+            "tempC : set chiller temperature\r\n"
+            "tempR : read connector header and chiller temperature\r\n";
 
 bool FindChargingInfoData(uint8_t target, struct ChargingInfoData **chargingData)
 {
@@ -1020,6 +1024,12 @@ void RunUnconditionalChargeIndex1(char *v1, char *v2, char *v3)
             _chargingData[_GunIndex]->EvBatterytargetVoltage = _vol;
             _chargingData[_GunIndex]->EvBatterytargetCurrent = _cur;
         } else if (strcmp(newString[0], "c") == 0) {
+            if (strcmp(newString[1], "-1") == 0 ||
+                    strcmp(newString[1], "") == 0) {
+                printf("argc 1 is error parameter\r\n");
+                continue;
+            }
+
             if (atoi((char *)newString[1]) != -1) {
                 ShmSysConfigAndInfo->SysInfo.CurGunSelected = atoi((char *)newString[1]);
             }
@@ -1035,6 +1045,8 @@ void RunUnconditionalChargeIndex1(char *v1, char *v2, char *v3)
 
 int main(void)
 {
+    uint8_t _GunIndex = 0;
+
     if (InitShareMemory() == FAIL) {
         printf ("InitShareMemory = FAIL \n");
         if (ShmStatusCodeData != NULL) {
@@ -1174,72 +1186,101 @@ int main(void)
             if (strcmp(newString[1], "auto") == 0) {
                 newString[2][0] = 0;
                 newString[3][0] = 0;
-            } else if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0 ||
-                       strcmp(newString[2], "-1") == 0 || strcmp(newString[2], "") == 0) {
+            } else if (strcmp(newString[1], "-1") == 0 ||
+                       strcmp(newString[1], "") == 0   ||
+                       strcmp(newString[2], "-1") == 0 ||
+                       strcmp(newString[2], "") == 0) {
                 printf ("Input cmd fail ------  strchg [vol 150-1000] [cru 2-100]\n");
                 continue;
             }
 
             // 槍狀態
             RunUnconditionalChargeIndex1(newString[1], newString[2], newString[3]);
-        } else if (strcmp(newString[0], "tempT") == 0) {
+        } else if (strcmp(newString[0], "tempT") == 0) {//修改槍頭溫度值
 
-            if (strcmp(newString[1], "0") == 0) {
-                uint8_t _GunIndex = 0;
-                if (!FindChargingInfoData(_GunIndex, &_chargingData[0])) {
-                    printf ("FindChargingInfoData error\n");
-                    return 0;
-                }
+            if (strcmp(newString[1], "-1") == 0 ||
+                    strcmp(newString[1], "") == 0) {
+                printf("argc 1 is error parameter\r\n");
+                continue;
+            }
 
-                _chargingData[0]->ConnectorTemp = atoi(newString[2]);
-                printf("ReadCmdline temp 0 = %d\r\n", _chargingData[0]->ConnectorTemp);
-            } else if (strcmp(newString[1], "1") == 0) {
-                uint8_t _GunIndex = 1;
-                if (!FindChargingInfoData(_GunIndex, &_chargingData[0])) {
-                    printf ("FindChargingInfoData error\n");
-                    return 0;
-                }
+            _GunIndex = atoi((char *)newString[1]);
 
-                _chargingData[1]->ConnectorTemp = atoi(newString[2]);
-                printf("ReadCmdline temp 1 = %d\r\n", _chargingData[1]->ConnectorTemp);
+            if (_GunIndex >= ShmSysConfigAndInfo->SysConfig.TotalConnectorCount) {
+                printf("gun index over total connector\r\n");
+                continue;
             }
-        } else if (strcmp(newString[0], "tempC") == 0) {
-            if (strcmp(newString[1], "0") == 0) {
-                uint8_t _GunIndex = 0;
-                if (!FindChargingInfoData(_GunIndex, &_chargingData[0])) {
-                    printf ("FindChargingInfoData error\n");
-                    return 0;
-                }
 
-                _chargingData[0]->ChillerTemp = atoi(newString[2]);
-                printf("ReadCmdline temp 0 = %d\r\n", _chargingData[0]->ChillerTemp);
-            } else if (strcmp(newString[1], "1") == 0) {
-                uint8_t _GunIndex = 1;
-                if (!FindChargingInfoData(_GunIndex, &_chargingData[0])) {
-                    printf ("FindChargingInfoData error\n");
-                    return 0;
-                }
+            if (!FindChargingInfoData(_GunIndex, &_chargingData[0])) {
+                printf ("FindChargingInfoData error\n");
+                return 0;
+            }
 
-                _chargingData[1]->ChillerTemp = atoi(newString[2]);
-                printf("ReadCmdline temp 1 = %d\r\n", _chargingData[1]->ChillerTemp);
+            if (atoi(newString[2]) > 255 || atoi(newString[2]) == -1) {//溫度值不會超過255
+                printf("temperature value overflow\r\n");
+                continue;
             }
-        } else if (strcmp(newString[0], "TempCR") == 0) {
-            if (strcmp(newString[1], "0") == 0) {
-                uint8_t _GunIndex = 0;
-                if (!FindChargingInfoData(_GunIndex, &_chargingData[0])) {
-                    printf ("FindChargingInfoData error\n");
-                    return 0;
-                }
-                printf("ReadCmdline temp 0 = %d\r\n", _chargingData[0]->ChillerTemp);
-            } else if (strcmp(newString[1], "1") == 0) {
-                uint8_t _GunIndex = 1;
-                if (!FindChargingInfoData(_GunIndex, &_chargingData[0])) {
-                    printf ("FindChargingInfoData error\n");
-                    return 0;
-                }
 
-                printf("ReadCmdline temp 1 = %d\r\n", _chargingData[1]->ChillerTemp);
+            _chargingData[_GunIndex]->ConnectorTemp = atoi(newString[2]);
+            printf("set %d connector temp 0 = %d\r\n",
+                   _GunIndex,
+                   _chargingData[_GunIndex]->ConnectorTemp);
+        } else if (strcmp(newString[0], "tempC") == 0) {//修改水冷機溫度值
+            if (strcmp(newString[1], "-1") == 0 ||
+                    strcmp(newString[1], "") == 0) {
+                printf("argc 1 is error parameter\r\n");
+                continue;
+            }
+
+            _GunIndex = atoi((char *)newString[1]);
+
+            if (_GunIndex >= 1) {
+                _GunIndex = 0; //只會有一個水冷機
             }
+
+            if (_GunIndex >= ShmSysConfigAndInfo->SysConfig.TotalConnectorCount) {
+                printf("gun index over total connector\r\n");
+                continue;
+            }
+
+            if (!FindChargingInfoData(_GunIndex, &_chargingData[0])) {
+                printf ("FindChargingInfoData error\n");
+                continue;
+            }
+
+            if (atoi(newString[2]) > 255 || atoi(newString[2]) == -1) {
+                printf("temperature value overflow\r\n");
+                return 0;
+            }
+
+            _chargingData[_GunIndex]->ChillerTemp = atoi(newString[2]);
+            printf("set %d chiller temperature = %d\r\n",
+                   _GunIndex,
+                   _chargingData[_GunIndex]->ChillerTemp);
+        } else if (strcmp(newString[0], "tempR") == 0) { //讀取槍頭和水冷機溫度
+
+            if (strcmp(newString[1], "-1") == 0 ||
+                    strcmp(newString[1], "") == 0) {
+                printf("argc 1 is error parameter\r\n");
+                continue;
+            }
+
+            _GunIndex = atoi((char *)newString[1]);
+
+            if (_GunIndex >= ShmSysConfigAndInfo->SysConfig.TotalConnectorCount) {
+                printf("gun index over total connector\r\n");
+                continue;
+            }
+
+            if (!FindChargingInfoData(_GunIndex, &_chargingData[0])) {
+                printf ("FindChargingInfoData error\n");
+                return 0;
+            }
+
+            printf("get %d gun temp = %d, chiller temp = %d\r\n",
+                   _GunIndex,
+                   _chargingData[_GunIndex]->ConnectorTemp,
+                   _chargingData[_GunIndex]->ChillerTemp);
         } else {
             printf ("%s\n", msg);
         }

+ 3 - 2
EVSE/Projects/DD360Audi/Apps/Readme.md

@@ -5,5 +5,6 @@
     4. 執行DD360Audi/Apps/Script/replaceOtherDD360Project.sh
     5. 重新commit。
 
-## DD360 和 DD360ComBox 都是用DD360Audi開發和修改,完成後,執行
-   DD360Audi/Apps/Script/replaceOtherDD360Project.sh
+## 更換DD360 和 DD360ComBox project
+    DD360 和 DD360ComBox 都是用DD360Audi開發和修改,完成後,執行
+    DD360Audi/Apps/Script/replaceOtherDD360Project.sh

+ 12 - 2
EVSE/Projects/DD360Audi/Apps/ShareMemory/shmMem.c

@@ -978,6 +978,8 @@ bool MappingGunChargingInfo(char *whichTask)
         return false;
     }
 
+    ShmDcCommonData->ChillerValve.MultiChillerGun = 0;
+
     //printf("1 CheckConnectorTypeStatus\r\n");
     for (typeIndex = 7; typeIndex <= 9; typeIndex++) {
         if (!addGunInfoByConnector(pSysConfig->ModelName[typeIndex], slots)) {
@@ -989,12 +991,20 @@ bool MappingGunChargingInfo(char *whichTask)
         if (strncmp((char *)&pSysConfig->ModelName[typeIndex], "V", 1) == 0 ||
                 strncmp((char *)&pSysConfig->ModelName[typeIndex], "F", 1) == 0
            ) {
-            ShmDcCommonData->ChillerValve.MultiChillerGun++;
-            ShmDcCommonData->ChillerValve.MultiChillerGun |= 0x80;
+            ShmDcCommonData->ChillerValve.MultiChillerGun++; //水冷槍數
         }
         slots++;
     }
 
+    if (ShmDcCommonData->ChillerValve.MultiChillerGun != 0) {
+        ShmDcCommonData->ChillerValve.MultiChillerGun |= 0x80; //有水冷槍標記
+        if (strncmp(whichTask, "CSU Task", 8) == EQUAL) {
+            log_info("get chiller gun = %x, chiller gun count = %d\r\n",
+                     (ShmDcCommonData->ChillerValve.MultiChillerGun & 0x80) >> 7,
+                     ShmDcCommonData->ChillerValve.MultiChillerGun & 0x7F);
+        }
+    }
+
     // AC index 接在 DC 後面
     //if (AC_QUANTITY > 0) {
     if (gGunIndexInfo.AcIndex > 0) { //DS60-120 add

BIN=BIN
EVSE/Projects/DD360Audi/Images/ramdisk.gz


BIN=BIN
EVSE/Projects/DD360Audi/output/FactoryConfig


BIN=BIN
EVSE/Projects/DD360Audi/output/Module_DoComm


BIN=BIN
EVSE/Projects/DD360Audi/output/Module_EvComm


BIN=BIN
EVSE/Projects/DD360Audi/output/Module_EventLogging


BIN=BIN
EVSE/Projects/DD360Audi/output/Module_InternalComm


BIN=BIN
EVSE/Projects/DD360Audi/output/Module_LcmControl


BIN=BIN
EVSE/Projects/DD360Audi/output/Module_PrimaryComm


BIN=BIN
EVSE/Projects/DD360Audi/output/ReadCmdline


BIN=BIN
EVSE/Projects/DD360Audi/output/main


+ 2 - 1
EVSE/Projects/DD360ComBox/Apps/CSU/RFID.c

@@ -20,11 +20,12 @@ static bool isCardScan = false;
 //------------------------------------------------------------------------------
 static bool canStartCharging(void)
 {
+    uint8_t index = 0;
     char buf2[16] = "";
     memset(buf2, 0, ARRAY_SIZE(buf2));
     struct OCPP16Data *ShmOCPP16Data = (struct OCPP16Data *)GetShmOCPP16Data();
 
-    for (uint8_t index = 0; index < strlen((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status); index++) {
+    for (index = 0; index < strlen((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status); index++) {
         sprintf(buf2 + (index - 1) * 2, "%02X", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status[index]);
     }
     sprintf(buf2, "%s", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);

+ 104 - 70
EVSE/Projects/DD360ComBox/Apps/CSU/main.c

@@ -261,13 +261,14 @@ void destroySelGun(uint8_t curGun)
     }
 }
 
+/*
 static int waitSelectGunPlugIt(uint8_t curGun)
 {
 #if !defined DD360Audi
     return PASS;
 #endif //!defined DD360Audi
 
-    /*switch (curGun) {
+    switch (curGun) {
     case RIGHT_GUN_NUM:
         if (ShmSelectGunInfo->SelGunInfo.RightGun == SEL_GUN_ATHOR) {
             return PASS;
@@ -283,16 +284,17 @@ static int waitSelectGunPlugIt(uint8_t curGun)
     default:
         return FAIL;
     }
-    */
 
-    if (curGun == RIGHT_GUN_NUM && (ShmSelectGunInfo->SelGunInfo.RightGun == SEL_GUN_ATHOR)) {
-        return PASS;
-    } else if ((curGun == LEFT_GUN_NUM) && (ShmSelectGunInfo->SelGunInfo.LeftGun == SEL_GUN_ATHOR)) {
-        return PASS;
-    }
+
+    //if (curGun == RIGHT_GUN_NUM && (ShmSelectGunInfo->SelGunInfo.RightGun == SEL_GUN_ATHOR)) {
+    //    return PASS;
+    //} else if ((curGun == LEFT_GUN_NUM) && (ShmSelectGunInfo->SelGunInfo.LeftGun == SEL_GUN_ATHOR)) {
+    //    return PASS;
+    //}
 
     return FAIL;
 }
+*/
 
 static int waitRightGunPlugIt(uint8_t curGun)
 {
@@ -2629,10 +2631,10 @@ void DetectPluginStart()
 bool isDetectPlugin()
 {
     if (pSysInfo->WaitForPlugit == YES) {
-        return YES;
+        return true;
     }
 
-    return NO;
+    return false;
 }
 
 //===============================================
@@ -5468,6 +5470,10 @@ void CheckOcppStatus(void)
 
 void OcppStartTransation(uint8_t gunIndex)
 {
+#if defined DD360 || defined DD360Audi || defined DD360ComBox
+    return;
+#endif //defined DD360 || defined DD360Audi || defined DD360ComBox
+
     uint8_t _OcppGunIndex = gunIndex;
     pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
 
@@ -5737,11 +5743,25 @@ void InformOcppErrOccur(uint8_t codeType)
     char _error[25];
 
     switch (codeType) {
-    case 4: strcpy(_error, "InternalError"); break;
-    case 6: strcpy(_error, "NoError"); break;
-    case 7: strcpy(_error, "OtherError"); break;
-    case 13: strcpy(_error, "UnderVoltage"); break;
-    case 14: strcpy(_error, "OverVoltage"); break;
+    case 4:
+        strcpy(_error, "InternalError");
+        break;
+
+    case 6:
+        strcpy(_error, "NoError");
+        break;
+
+    case 7:
+        strcpy(_error, "OtherError");
+        break;
+
+    case 13:
+        strcpy(_error, "UnderVoltage");
+        break;
+
+    case 14:
+        strcpy(_error, "OverVoltage");
+        break;
     }
 
     for (uint8_t gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++) {
@@ -6745,6 +6765,42 @@ static uint8_t distributionPsuModule(uint8_t *isRessign, uint8_t gunIndex)
     return NO;
 }
 
+static void checkEvBoardReqStop(uint8_t sysStatus, uint8_t gunIndex)
+{
+    uint8_t evBoardStopState = 0;
+
+    if ((evBoardStopState = isEvBoardStopChargeFlag(gunIndex)) > 0) {
+
+        // 板端要求停止 (錯誤)
+        if (sysStatus != S_CCS_PRECHARGE_ST0 &&
+                sysStatus != S_CCS_PRECHARGE_ST1) {
+            if (strcmp((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "") == EQUAL) {
+                strcpy((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "EVDisconnected");
+            }
+        }
+
+        if (evBoardStopState == EV_BOARD_STOP_CHARGING) {
+            ChargingAlarmProcess(gunIndex);
+        } else if (evBoardStopState == POWER_CABINET_STOP_CHARGING) {
+            ChargingTerminalProcess(gunIndex);
+        }
+    } else if (isEvBoardNormalStopChargeFlag(gunIndex) == YES) {
+        // 板端要求停止 (正常)
+        if (sysStatus != S_CCS_PRECHARGE_ST0 &&
+                sysStatus != S_CCS_PRECHARGE_ST1) {
+            if (strcmp((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "") == EQUAL) {
+                strcpy((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "EVDisconnected");
+            }
+        }
+
+        ChargingTerminalProcess(gunIndex);
+    } else if (OcppRemoteStop(gunIndex) == YES ||
+               WifiScheduleStop(gunIndex)) {
+        // 後臺要求停止
+        ChargingTerminalProcess(gunIndex);
+    }
+}
+
 int main(void)
 {
     bool isModelNameMatch = true;
@@ -7132,11 +7188,14 @@ int main(void)
                             ChangeGunSelectByIndex(gunIndex);
                             AddPlugInTimes(gunIndex);
                             strcpy((char *)pDcChargingInfo->StartUserId, (char *)pSysConfig->UserId);
-                            log_info("index = %d, CardNumber = %s \n", gunIndex, pDcChargingInfo->StartUserId);
+                            log_info("index = %d, CardNumber = %s \n",
+                                     gunIndex,
+                                     pDcChargingInfo->StartUserId);
                             strcpy((char *)pSysConfig->UserId, "");
                             // 當前操作的槍號,進入 Preparing
                             setChargerMode(gunIndex, MODE_REASSIGN_CHECK);
                             ClearDetectPluginFlag();
+
                             continue;
                         }
                     }
@@ -7186,46 +7245,7 @@ int main(void)
                 if (distributionPsuModule(&isRessign, gunIndex) == YES) {
                     continue;
                 }
-#if 0
-#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
-                if (pSysConfig->TotalConnectorCount > 1 && pSysInfo->IsAlternatvieConf == NO) {
-                    if (pSysInfo->MainChargingMode == _MAIN_CHARGING_MODE_MAX) {
-                        for (byte index = 0; index < pSysConfig->TotalConnectorCount; index++) {
-                            pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(index);
 
-                            // 有其他槍已經分配好 psu 模塊
-                            if (pSysInfo->CurGunSelected != index &&
-                                    pDcChargingInfo->SystemStatus >= S_PREPARNING &&
-                                    pDcChargingInfo->SystemStatus != S_MAINTAIN) {
-                                log_info("=============Smart Charging============= Step 1 \n");
-                                pSysInfo->ReAssignedFlag = _REASSIGNED_PREPARE_M_TO_A;
-                                isRessign = YES;
-                                break;
-                            }
-                        }
-                    } else if (pSysInfo->MainChargingMode == _MAIN_CHARGING_MODE_AVER &&
-                               pSysInfo->ReAssignedFlag != _REASSIGNED_NONE) {
-                        // 如果在切換最大充的過程中,需等待最大充切換完成後,在走均充流程
-                        if (pSysInfo->BridgeRelayStatus == YES) {
-                            if (pSysInfo->ReAssignedFlag != _REASSIGNED_COMP &&
-                                    pSysInfo->ReAssignedFlag != _REASSIGNED_WAITING) {
-                                log_info("=============Smart Charging============= Step 14 \n");
-                                pSysInfo->ReAssignedFlag = _REASSIGNED_WAITING;
-                            } else if (pSysInfo->ReAssignedFlag == _REASSIGNED_COMP) {
-                                pSysInfo->MainChargingMode = _MAIN_CHARGING_MODE_MAX;
-                                pSysInfo->ReAssignedFlag = _REASSIGNED_NONE;
-                                continue;
-                            }
-                        }
-
-                        if (pSysInfo->CurGunSelected == gunIndex) {
-                            pSysInfo->ConnectorPage = _LCM_PRE_CHARGE;
-                        }
-                        continue;
-                    }
-                }
-#endif // !defined DD360 && !defined DD360Audi
-#endif //0
                 if (isRessign == YES) {
                     setChargerMode(gunIndex, MODE_REASSIGN);
                 } else {
@@ -7278,11 +7298,7 @@ int main(void)
                 if (ShmPsuData->SystemPresentPsuQuantity > 0 &&
                         ShmPsuData->SystemAvailablePower > 10 &&
                         GetTimeoutValue(pDcChargingInfo->TimeoutTimer) >= 5000000) {
-                    //if ((pDcChargingInfo->MaximumChargingVoltage > 0) && //DS60-120 remove
-                    //        (pDcChargingInfo->AvailableChargingCurrent > 0) &&
-                    //        (pDcChargingInfo->AvailableChargingPower > 0)) {
                     setChargerMode(gunIndex, MODE_PREPARE_FOR_EV);
-                    //}
                 }
 
                 //DS60-120 add
@@ -7304,6 +7320,8 @@ int main(void)
                     }
                 }
 
+                checkEvBoardReqStop(pDcChargingInfo->SystemStatus, gunIndex);
+#if 0
                 if ((evBoardStopState = isEvBoardStopChargeFlag(gunIndex)) > 0) {
                     // 板端要求停止 (錯誤)
                     if (strcmp((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "") == EQUAL) {
@@ -7326,6 +7344,7 @@ int main(void)
                     // 後臺要求停止
                     ChargingTerminalProcess(gunIndex);
                 }
+#endif //0
 
                 if (pSysInfo->CurGunSelected == gunIndex) {
                     pSysInfo->ConnectorPage = _LCM_PRE_CHARGE;
@@ -7357,6 +7376,8 @@ int main(void)
                     }
                 }
 
+                checkEvBoardReqStop(pDcChargingInfo->SystemStatus, gunIndex);
+#if 0
                 if ((evBoardStopState = isEvBoardStopChargeFlag(gunIndex)) > 0) {
                     // 板端要求停止 (錯誤)
                     if (strcmp((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "") == EQUAL) {
@@ -7379,6 +7400,7 @@ int main(void)
                     // 後臺要求停止
                     ChargingTerminalProcess(gunIndex);
                 }
+#endif //0
 
                 // LCM => Pre-charging
                 if (pSysInfo->CurGunSelected == gunIndex) {
@@ -7395,7 +7417,8 @@ int main(void)
 
                 if (pDcChargingInfo->Type == _Type_Chademo) {
                     // 檢查樁端的 GFD 結果
-                    if (isPrechargeStatus_chademo(gunIndex) > 5 && isPrechargeStatus_chademo(gunIndex) < 8) {
+                    if (isPrechargeStatus_chademo(gunIndex) > 5 &&
+                            isPrechargeStatus_chademo(gunIndex) < 8) {
                         // 當前操作的槍號,進入 Charging
                         setChargerMode(gunIndex, MODE_CHARGING);
                     }
@@ -7437,6 +7460,8 @@ int main(void)
                     }
                 }
 
+                checkEvBoardReqStop(pDcChargingInfo->SystemStatus, gunIndex);
+#if 0
                 if ((evBoardStopState = isEvBoardStopChargeFlag(gunIndex)) > 0) {
                     // 板端要求停止 (錯誤)
                     if (strcmp((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "") == EQUAL) {
@@ -7459,6 +7484,7 @@ int main(void)
                     // 後臺要求停止
                     ChargingTerminalProcess(gunIndex);
                 }
+#endif //0
 
                 // LCM => Pre-charging
                 if (pSysInfo->CurGunSelected == gunIndex) {
@@ -7473,9 +7499,8 @@ int main(void)
                     ftime(&startChargingTime[gunIndex]);
                     strcpy((char *)ShmOCPP16Data->StartTransaction[gunIndex].ResponseIdTagInfo.Status, ""); //DS60-120 add
                     ChangeStartOrStopDateTime(YES, gunIndex);
-#if !defined DD360 && !defined DD360Audi && !defined DD360ComBox
+
                     OcppStartTransation(gunIndex);
-#endif //!defined DD360 && !defined DD360Audi
                 }
 
                 if (ShmOCPP16Data->CpMsg.bits[gunIndex].StartTransactionConf) {
@@ -7546,6 +7571,7 @@ int main(void)
                     if (strcmp((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "") == EQUAL) {
                         strcpy((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "EVDisconnected");
                     }
+
                     //printf("%d evBoardStopState = %d\r\n", gunIndex, evBoardStopState);
                     if (evBoardStopState == EV_BOARD_STOP_CHARGING) {
                         ChargingAlarmProcess(gunIndex);
@@ -7557,6 +7583,7 @@ int main(void)
                     if (strcmp((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "") == EQUAL) {
                         strcpy((char *)ShmOCPP16Data->StopTransaction[gunIndex].StopReason, "EVDisconnected");
                     }
+
                     ChargingTerminalProcess(gunIndex);
                 } else if (OcppRemoteStop(gunIndex) == YES ||
                            WifiScheduleStop(gunIndex) ||
@@ -7756,6 +7783,8 @@ int main(void)
                     RecordAlarmCode(gunIndex, "012235");
                 }
 
+                checkEvBoardReqStop(pDcChargingInfo->SystemStatus, gunIndex);
+#if 0
                 if ((evBoardStopState = isEvBoardStopChargeFlag(gunIndex)) > 0) {
                     // 板端要求停止 (錯誤)
                     if (evBoardStopState == EV_BOARD_STOP_CHARGING) {
@@ -7771,10 +7800,12 @@ int main(void)
                     // 後臺要求停止
                     ChargingTerminalProcess(gunIndex);
                 }
+#endif //0
 
                 // 等待 EV 小板 (CCS) 通知可以開始 Precharge
                 // 切換 D+ Relay to Precharge Relay
-                if (isPrechargeStatus_ccs(gunIndex) == 39 || isPrechargeStatus_ccs(gunIndex) == 40) {
+                if (isPrechargeStatus_ccs(gunIndex) == 39 ||
+                        isPrechargeStatus_ccs(gunIndex) == 40) {
                     if (pDcChargingInfo->RelayKPK2Status == YES &&
                             pDcChargingInfo->PrechargeStatus != PRECHARGE_READY)
                         //if (pDcChargingInfo->PrechargeStatus != PRECHARGE_PRERELAY_PASS)
@@ -7812,6 +7843,8 @@ int main(void)
                     RecordAlarmCode(gunIndex, "012235");
                 }
 
+                checkEvBoardReqStop(pDcChargingInfo->SystemStatus, gunIndex);
+#if 0
                 if ((evBoardStopState = isEvBoardStopChargeFlag(gunIndex)) > 0) {
                     // 板端要求停止 (錯誤)
                     if (evBoardStopState == EV_BOARD_STOP_CHARGING) {
@@ -7828,7 +7861,7 @@ int main(void)
                     // 後臺要求停止
                     ChargingTerminalProcess(gunIndex);
                 }
-
+#endif //0
                 // 等待小板通知進入充電
                 // 切換 D+ Relay to Precharge Relay
                 if (pDcChargingInfo->RelayK1K2Status == YES) {
@@ -7840,8 +7873,10 @@ int main(void)
                     pSysInfo->ConnectorPage = _LCM_PRE_CHARGE;
                 }
                 break;
-            }
-        }
+            }//switch
+
+            checkEvBoardAlarmState(pDcChargingInfo->Type);
+        }//for
 
 #if defined DD360Audi
         if (pSysInfo->SystemPage != _LCM_SELECT_GUN) {
@@ -7875,11 +7910,10 @@ int main(void)
             }
         }
 
-        for (uint8_t gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++) {
-            pDcChargingInfo =  (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
-
-            checkEvBoardAlarmState(pDcChargingInfo->Type);
-        }
+        //for (uint8_t gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++) {
+        //    pDcChargingInfo =  (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
+        //    checkEvBoardAlarmState(pDcChargingInfo->Type);
+        //}
 
         //write(wtdFd, "a", 1);
         //WriteWatchDogState("a");

+ 1 - 0
EVSE/Projects/DD360ComBox/Apps/DataBase/DataBase.c

@@ -2,6 +2,7 @@
 #include <stdlib.h>     /*標準函數庫定義*/
 #include <string.h>
 #include <stdint.h>
+#include <time.h>
 
 #include "../Config.h"
 #include "../Log/log.h"

+ 4 - 0
EVSE/Projects/DD360ComBox/Apps/Define/define.h

@@ -570,6 +570,10 @@ struct ChargingInfoData
 	int 				EvBatteryStartSoc;				// 0~100%
 	unsigned char 		NormalStopChargeFlag;			// for EV board
 	ChargingStop        ChargingStopFlag;
+	char 				ReservedStartFlag;
+	float 				ConnectorMaxVoltage;			// 0~6553.5 volt
+	float 				ConnectorMaxCurrent;			// 0~6553.5 volt
+	unsigned char 		ModelType;
 };
 
 typedef union

+ 69 - 7
EVSE/Projects/DD360ComBox/Apps/FactoryConfig.c

@@ -31,12 +31,21 @@
 #include    "./Define/define.h"
 #include    "Config.h"
 
+//------------------------------------------------------------------------------
 #define Debug
 #define OUTPUT_FLASH        0x01
 #define OUTPUT_FILE         0x02
 
+#define log_info(format, args...) StoreLogMsg("[%s:%d][%s][Info] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
+#define log_warn(format, args...) StoreLogMsg("[%s:%d][%s][Warn] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
+#define log_error(format, args...) StoreLogMsg("[%s:%d][%s][Error] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
+
+//------------------------------------------------------------------------------
 struct SysConfigData            SysConfig;
+struct SysConfigAndInfo         *ShmSysConfigAndInfo;
+struct StatusCodeData           *ShmStatusCodeData;
 
+//------------------------------------------------------------------------------
 int StoreLogMsg(const char *fmt, ...)
 {
     char Buf[4096 + 256];
@@ -82,6 +91,39 @@ int runShellCmd(const char *cmd)
     return result;
 }
 
+//==========================================
+// Init all share memory
+//==========================================
+int InitShareMemory()
+{
+    int result = PASS;
+    int MeterSMId;
+
+    //creat ShmSysConfigAndInfo
+    if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo),  0777)) < 0) {
+        log_error("shmget ShmSysConfigAndInfo NG\n");
+
+        result = FAIL;
+    } else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
+        log_error("shmat ShmSysConfigAndInfo NG\n");
+
+        result = FAIL;
+    }
+
+    //creat ShmStatusCodeData
+    if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData),  0777)) < 0) {
+        log_error("shmget ShmStatusCodeData NG\n");
+
+        result = FAIL;
+    } else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
+        log_error("shmat ShmStatusCodeData NG\n");
+
+        result = FAIL;
+    }
+
+    return result;
+}
+
 void helpOutput(void)
 {
     printf("Usage: Module_FactoryConfig [OPTION]...\r\n\r\n");
@@ -113,6 +155,26 @@ int main(int argc, char *argv[])
     memset(ptr, 0, MtdBlockSize);
     memset(&SysConfig, 0, sizeof(struct SysConfigData));
 
+
+    // Initial Share Memory
+    if (InitShareMemory() == FAIL) {
+        log_error("InitShareMemory NG\n");
+
+        strcpy((char *)SysConfig.ModelName, "");
+        strcpy((char *)SysConfig.SerialNumber, "");
+        sleep(5);
+    } else {
+        memcpy((char *)SysConfig.ModelName,
+               ShmSysConfigAndInfo->SysConfig.ModelName,
+               ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.ModelName));
+
+        memcpy((char *)SysConfig.SerialNumber,
+               ShmSysConfigAndInfo->SysConfig.SerialNumber,
+               ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.SerialNumber));
+
+        log_info("InitShareMemory OK.\n");
+    }
+
     /*
      * TODO: Set factory default configuration
     */
@@ -248,13 +310,13 @@ int main(int argc, char *argv[])
         helpOutput();
     }
 
-    if (argc == 4) {
-        strcpy((char *)SysConfig.ModelName, argv[2]);
-        strcpy((char *)SysConfig.SerialNumber, argv[3]);
-    } else {
-        strcpy((char *)SysConfig.ModelName, "DDYC182V0UE2AD");
-        strcpy((char *)SysConfig.SerialNumber, "SERIALFORRD");
-    }
+    //if (argc == 4) {
+    //    strcpy((char *)SysConfig.ModelName, argv[2]);
+    //    strcpy((char *)SysConfig.SerialNumber, argv[3]);
+    //} else {
+    //    strcpy((char *)SysConfig.ModelName, "DDYC182V0UE2AD");
+    //    strcpy((char *)SysConfig.SerialNumber, "SERIALFORRD");
+    //}
 
     /*
      * Configuration bin file generate

+ 61 - 0
EVSE/Projects/DD360ComBox/Apps/Log/log.c

@@ -8,6 +8,7 @@
 #include <stdarg.h>
 
 #include <sys/timeb.h>
+#include <sys/time.h>
 
 #include "../ShareMemory/shmMem.h"
 #include "../Define/define.h"
@@ -61,3 +62,63 @@ int StoreLogMsg(const char *fmt, ...)
 
     return rc;
 }
+
+int StoreEventLogMsg(const char *fmt, ...)
+{
+    char Buf[4096 + 256];
+    char buffer[4096];
+    time_t CurrentTime;
+    struct tm *tm;
+    struct timeval tv;
+    va_list args;
+    struct SysConfigData *pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
+
+    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);
+    gettimeofday(&tv, NULL); // get microseconds, 10^-6
+
+    if ((pSysConfig->ModelName != NULL) &&
+            (pSysConfig->SerialNumber != NULL) &&
+            (strlen((char *)pSysConfig->ModelName) >= 14)) {
+        sprintf(Buf, "echo -n \"[%04d.%02d.%02d %02d:%02d:%02d.%06ld]%s\" >> /Storage/EventLog/[%04d.%02d]%s_%s_EventLog",
+                tm->tm_year + 1900,
+                tm->tm_mon + 1,
+                tm->tm_mday,
+                tm->tm_hour,
+                tm->tm_min,
+                tm->tm_sec,
+                tv.tv_usec,
+                buffer,
+                tm->tm_year + 1900,
+                tm->tm_mon + 1,
+                pSysConfig->ModelName,
+                pSysConfig->SerialNumber);
+    } else {
+        sprintf(Buf, "echo -n \"[%04d.%02d.%02d %02d:%02d:%02d.%06ld]%s\" >> /Storage/EventLog/[%04d.%02d]EventLog",
+                tm->tm_year + 1900,
+                tm->tm_mon + 1,
+                tm->tm_mday,
+                tm->tm_hour,
+                tm->tm_min,
+                tm->tm_sec,
+                tv.tv_usec,
+                buffer,
+                tm->tm_year + 1900,
+                tm->tm_mon + 1);
+    }
+
+#ifdef SystemLogMessage
+    system(Buf);
+#endif //SystemLogMessage
+
+#ifdef ConsloePrintLog
+    printf("[%04d.%02d.%02d %02d:%02d:%02d.%06ld]%s", tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec, tv.tv_usec, buffer);
+#endif //ConsloePrintLog
+
+    return rc;
+}

+ 2 - 0
EVSE/Projects/DD360ComBox/Apps/Log/log.h

@@ -6,7 +6,9 @@
 #define log_warn(format, args...) StoreLogMsg("[%s:%d][%s][Warn] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
 #define log_error(format, args...) StoreLogMsg("[%s:%d][%s][Error] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
 
+#define event_info(format, args...) StoreEventLogMsg("[%s:%d][%s][Info] "format, __FILE__, __LINE__, __FUNCTION__, ##args) //DS60-120 add
 //------------------------------------------------------------------------------
 int StoreLogMsg(const char *fmt, ...);
+int StoreEventLogMsg(const char *fmt, ...);
 
 #endif /* _LOG_H_ */

+ 31 - 13
EVSE/Projects/DD360ComBox/Apps/Makefile

@@ -75,6 +75,10 @@ MAIN_SRC_FILES = $(patsubst %.o, %.c, $(MAIN_OBJ_FILES))
 %.o: %.c
 	$(CC) $(CFLAGS) -c $<
 
+#DoComm
+DOCOMM_OBJ_FILES = $(COMMON_OBJ_FILES) $(DoCommLib)/DoComm.o
+DOCOMM_SRC_FILES = $(patsubst %.o, %.c, $(DOCOMM_OBJ_FILES))
+
 #internal comm lib
 INTERNALCOMM_OBJ_FILES = $(COMMON_OBJ_FILES) $(InternalCommLib)/internalComm.o \
 							$(InternalCommLib)/Module_InternalComm.o $(InternalCommLib)/FanBoard.o \
@@ -99,6 +103,17 @@ EVENTLOG_SRC_FILES = $(patsubst %.o, %.c, $(EVENTLOG_OBJ_FILES))
 %.o: %.c
 	$(CC) $(CFLAGS) -c $<
 
+#LCM Control
+LCM_OBJ_FILES = $(COMMON_OBJ_FILES) $(LcmLib)/Module_LcmControl.o
+LCM_SRC_FILES = $(patsubst %.o, %.c, $(LCM_OBJ_FILES))
+
+#Primary
+PRIMARY_OBJ_FILES = $(COMMON_OBJ_FILES) $(PrimaryLib)/PrimaryComm.o \
+						$(PrimaryLib)/Module_PrimaryComm.o
+PRIMARY_SRC_FILES = $(patsubst %.o, %.c, $(PRIMARY_OBJ_FILES))
+%.o: %.c
+	$(CC) $(CFLAGS) -c $<
+
 all: CopyFile apps
 
 apps: MainTask DoCommTask EvCommTask \
@@ -115,9 +130,10 @@ MainTask:
 	#$(CC) $(TFLAGS) -o main main.o timeout.o common.o ${Lib_Module_RFID} ${Lib_Module_Upgrade} ${Lib_SQLite3} $(Lib_Module_RatedCurrent)
 
 DoCommTask:
-	$(CC) $(DEFINE) $(CFLAGS) -c -o define.o $(DefineLib)/define.c
-	$(CC) $(DEFINE) $(CFLAGS) -c -o DoComm.o $(DoCommLib)/DoComm.c
-	$(CC) -o Module_DoComm DoComm.o define.o
+	$(CC) $(DEFINE) $(DOCOMM_SRC_FILES) $(CFLAGS) $(TFLAGS) $(INC_FLAGS) -o Module_DoComm
+	#$(CC) $(DEFINE) $(CFLAGS) -c -o define.o $(DefineLib)/define.c
+	#$(CC) $(DEFINE) $(CFLAGS) -c -o DoComm.o $(DoCommLib)/DoComm.c
+	#$(CC) -o Module_DoComm DoComm.o define.o
 
 EvCommTask:
 	$(CC) $(DEFINE) $(EVCOMM_SRC_FILES) $(CFLAGS) $(TFLAGS) $(INC_FLAGS) $(Lib_Module_RatedCurrent) -o Module_EvComm
@@ -126,10 +142,10 @@ EvCommTask:
 	#$(CC) -o Module_EvComm Ev_Comm.o Module_EvComm.o $(Lib_Module_RatedCurrent)
 
 EventLoggingTask:
-	#$(CC) $(DEFINE) $(EVENTLOG_SRC_FILES) $(CFLAGS) $(TFLAGS) $(INC_FLAGS) $(SQLite3_H) $(Lib_SQLite3) -o Module_EventLogging
-	$(CC) $(DEFINE) $(CFLAGS) -c -o define.o $(DefineLib)/define.c
-	$(CC) $(DEFINE) $(SQLite3_H) $(CFLAGS) -c -o Module_EventLogging.o $(EventLogLib)/Module_EventLogging.c
-	$(CC) -o Module_EventLogging Module_EventLogging.o ${Lib_SQLite3} define.o
+	$(CC) $(DEFINE) $(EVENTLOG_SRC_FILES) $(CFLAGS) $(TFLAGS) $(INC_FLAGS) $(SQLite3_H) $(Lib_SQLite3) -o Module_EventLogging
+	#$(CC) $(DEFINE) $(CFLAGS) -c -o define.o $(DefineLib)/define.c
+	#$(CC) $(DEFINE) $(SQLite3_H) $(CFLAGS) -c -o Module_EventLogging.o $(EventLogLib)/Module_EventLogging.c
+	#$(CC) -o Module_EventLogging Module_EventLogging.o ${Lib_SQLite3} define.o
 
 InternalCommTask:
 	$(CC) $(DEFINE) $(INTERNALCOMM_SRC_FILES) $(CFLAGS) $(TFLAGS) $(INC_FLAGS) -o Module_InternalComm
@@ -138,14 +154,16 @@ InternalCommTask:
 	#$(CC) $(TFLAGS) -o Module_InternalComm Module_InternalComm.o internalComm.o $(Lib_ModuleRelay)
 
 LcmControlTask:
-	$(CC) $(DEFINE) $(CFLAGS) -c -o define.o $(DefineLib)/define.c
-	$(CC) $(DEFINE) $(CFLAGS) -c -o Module_LcmControl.o $(LcmLib)/Module_LcmControl.c
-	$(CC) -o Module_LcmControl Module_LcmControl.o define.o
+	$(CC) $(DEFINE) $(LCM_SRC_FILES) $(CFLAGS) $(TFLAGS) $(INC_FLAGS) -o Module_LcmControl
+	#$(CC) $(DEFINE) $(CFLAGS) -c -o define.o $(DefineLib)/define.c
+	#$(CC) $(DEFINE) $(CFLAGS) -c -o Module_LcmControl.o $(LcmLib)/Module_LcmControl.c
+	#$(CC) -o Module_LcmControl Module_LcmControl.o define.o
 
 PrimaryCommTask:
-	$(CC) $(DEFINE) $(CFLAGS) -c -o PrimaryComm.o $(PrimaryLib)/PrimaryComm.c
-	$(CC) $(DEFINE) $(CFLAGS) -c -o Module_PrimaryComm.o $(PrimaryLib)/Module_PrimaryComm.c
-	$(CC) -o Module_PrimaryComm Module_PrimaryComm.o PrimaryComm.o
+	$(CC) $(DEFINE) $(PRIMARY_SRC_FILES) $(CFLAGS) $(TFLAGS) $(INC_FLAGS) -o Module_PrimaryComm
+	#$(CC) $(DEFINE) $(CFLAGS) -c -o PrimaryComm.o $(PrimaryLib)/PrimaryComm.c
+	#$(CC) $(DEFINE) $(CFLAGS) -c -o Module_PrimaryComm.o $(PrimaryLib)/Module_PrimaryComm.c
+	#$(CC) -o Module_PrimaryComm Module_PrimaryComm.o PrimaryComm.o
 
 PsuCommTask:
 	$(CC) $(DEFINE) $(InfypwrPsuComm_H) $(CFLAGS) -c -o Module_PsuComm.o Module_PsuComm.c

Algúns arquivos non se mostraron porque demasiados arquivos cambiaron neste cambio