Преглед изворни кода

[Improve][Modularization][Module_OcppBackend / Module_OcppBackend20]

2021.11.03 / Folus Wen

Actions:
1. define.h add isRemoteStartWaitReq variable to OCPP share memory.
2. RemoteStartTransaction support without connector id when charger gun disconnected and timeout follow ConnectionTimeOut key setting value.

Files:
1. As follow commit history

Image version: D0.00.XX.XXXX.XX
Image checksum: XXXXXXXX

Hardware PWB P/N : XXXXXXX
Hardware Version : XXXXXXX
FolusWen пре 3 година
родитељ
комит
0b9561b990

+ 3 - 3
EVSE/Modularization/Makefile

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

Разлика између датотеке није приказан због своје велике величине
+ 573 - 272
EVSE/Modularization/ocpp20/MessageHandler.c


+ 9 - 10
EVSE/Modularization/ocpp20/Module_OcppBackend20.c

@@ -11,9 +11,9 @@ pthread_t tid_Watchdog;
 
 struct StartTime
 {
-	unsigned int connect;
-	unsigned int bootNotification;
-	unsigned int reConnect;
+	struct timespec connect;
+	struct timespec bootNotification;
+	struct timespec reConnect;
 }startTime;
 
 //==========================================
@@ -1165,12 +1165,11 @@ int main(void)
 			SetOcppConnStatus(FALSE);
 			SetServerSign(FALSE);
 			InitialSystemValue();
-			if((time((time_t*)NULL)-startTime.connect) >= (GetWebSocketPingInterval()>=30?GetWebSocketPingInterval()+5:30))
+			if(getDiffSecNow(startTime.connect) >= 30)
 			{
 				DEBUG_INFO("Server connecting...\n");
 				pthread_create(&tid_connectServer, NULL, ConnectWsServer, NULL);
-
-				startTime.connect=time((time_t*)NULL);
+				refreshStartTimer(&startTime.connect);
 			}
 			CheckSystemValue();
 		}
@@ -1179,11 +1178,11 @@ int main(void)
 			// Sign in
 			if((GetServerSign() == FALSE) &&
 			   (isConnectorInitMode(0) != TRUE) &&
-			   ( (GetBootNotificationInterval()>0) ? ((time((time_t*)NULL)-startTime.bootNotification) >= GetBootNotificationInterval()) : ((time((time_t*)NULL)-startTime.bootNotification) >= 10) )
+			   ( (GetBootNotificationInterval()>0) ? (getDiffSecNow(startTime.bootNotification) >= GetBootNotificationInterval()) : (getDiffSecNow(startTime.bootNotification) >= 10) )
 			  )
 			{
 				sendBootNotificationRequest();
-				startTime.bootNotification=time((time_t*)NULL);
+				refreshStartTimer(&startTime.bootNotification);
 			}
 
 			// On line operation
@@ -1209,7 +1208,7 @@ int main(void)
 
 				if((changeChageWebSocketPingInterval == TRUE) || (GetOcppConnStatus() == 0))
 				{
-					if(((time((time_t*)NULL)-startTime.reConnect) >= 3) || (((time((time_t*)NULL)-startTime.reConnect) < 0)))
+					if(getDiffSecNow(startTime.reConnect) >= 3)
 					{
 						DEBUG_INFO("GetOcppConnStatus() = %d\n", GetOcppConnStatus());
 						changeChageWebSocketPingInterval = FALSE;
@@ -1220,7 +1219,7 @@ int main(void)
 				}
 				else
 				{
-					startTime.reConnect = time((time_t*)NULL);
+					refreshStartTimer(&startTime.reConnect);
 				}
 			}
 		}

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

@@ -154,7 +154,9 @@ extern void splitstring(char *src, const char *separator, char **dest,int *num);
 extern char* stringtrim( char * s );
 extern char* stringtrimspace( char * s );
 extern char * strtrim( char * s );
-
+extern void refreshStartTimer(struct timespec *timer);
+extern int getDiffSecNow(struct timespec timer);
+extern int getDiffSecBetween(struct timespec start, struct timespec end);
 
 extern struct lws 					*wsi_client;
 extern struct lws_context 			*context;

+ 18 - 0
EVSE/Modularization/ocpp20/common.c

@@ -7,6 +7,24 @@
 
 #include "Module_OcppBackend20.h"
 
+void refreshStartTimer(struct timespec *timer)
+{
+	clock_gettime(CLOCK_MONOTONIC, timer);
+}
+
+int getDiffSecNow(struct timespec timer)
+{
+	struct timespec timerNow;
+
+	clock_gettime(CLOCK_MONOTONIC, &timerNow);
+
+	return (int)((((unsigned long)(timerNow.tv_sec - timer.tv_sec) * 1000) + ((unsigned long)((timerNow.tv_nsec / 1000000) - (timer.tv_nsec / 1000000))))/1000);
+}
+
+int getDiffSecBetween(struct timespec start, struct timespec end)
+{
+	return (int)((((unsigned long)(end.tv_sec - start.tv_sec) * 1000) + ((unsigned long)((end.tv_nsec / 1000000) - (start.tv_nsec / 1000000))))/1000);
+}
 
 void work(char s[])        // Delete space on start & end
 {

Разлика између датотеке није приказан због своје велике величине
+ 805 - 45
EVSE/Modularization/ocppfiles/MessageHandler.c


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

@@ -11,9 +11,9 @@ pthread_t tid_Watchdog;
 
 struct StartTime
 {
-	unsigned int connect;
-	unsigned int bootNotification;
-	unsigned int reConnect;
+	struct timespec connect;
+	struct timespec bootNotification;
+	struct timespec reConnect;
 }startTime;
 
 struct QueueOpInfo queueOpInfo;
@@ -1505,11 +1505,11 @@ int main(void)
 			SetOcppConnStatus(FALSE);
 			SetServerSign(FALSE);
 			InitialSystemValue();
-			if((time((time_t*)NULL)-startTime.connect) >= 30)
+			if(getDiffSecNow(startTime.connect) >= 30)
 			{
 				DEBUG_INFO("Server connecting...\n");
 				pthread_create(&tid_connectServer, NULL, ConnectWsServer, NULL);
-				startTime.connect=time((time_t*)NULL);
+				refreshStartTimer(&startTime.connect);
 			}
 			CheckSystemValue();
 		}
@@ -1518,11 +1518,11 @@ int main(void)
 			// Sign in
 			if((GetServerSign() == FALSE) &&
 			   (isConnectorInitMode(0) != TRUE) &&
-			   ( (GetBootNotificationInterval()>0) ? ((time((time_t*)NULL)-startTime.bootNotification) >= GetBootNotificationInterval()) : ((time((time_t*)NULL)-startTime.bootNotification) >= defaultWaitingTime) )
+			   ( (GetBootNotificationInterval()>0) ? (getDiffSecNow(startTime.bootNotification) >= GetBootNotificationInterval()) : (getDiffSecNow(startTime.bootNotification) >= defaultWaitingTime) )
 			  )
 			{
 				sendBootNotificationRequest();
-				startTime.bootNotification=time((time_t*)NULL);
+				refreshStartTimer(&startTime.bootNotification);
 			}
 
 			// On line operation
@@ -1549,7 +1549,7 @@ int main(void)
 
 				if((changeChageWebSocketPingInterval == TRUE) || (GetOcppConnStatus() == 0))
 				{
-					if(((time((time_t*)NULL)-startTime.reConnect) >= 3) || ((time((time_t*)NULL)-startTime.reConnect) < 0))
+					if(getDiffSecNow(startTime.reConnect) >= 3)
 					{
 						DEBUG_INFO("GetOcppConnStatus() = %d\n", GetOcppConnStatus());
 
@@ -1566,7 +1566,7 @@ int main(void)
 				}
 				else
 				{
-					startTime.reConnect = time((time_t*)NULL);
+					refreshStartTimer(&startTime.reConnect);
 				}
 			}
 		}

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

@@ -154,6 +154,9 @@ extern void splitstring(char *src, const char *separator, char **dest,int *num);
 extern char* stringtrim( char * s );
 extern char* stringtrimspace( char * s );
 extern char * strtrim( char * s );
+extern void refreshStartTimer(struct timespec *timer);
+extern int getDiffSecNow(struct timespec timer);
+extern int getDiffSecBetween(struct timespec start, struct timespec end);
 
 extern struct lws 					*wsi_client;
 extern struct lws_context 			*context;

+ 18 - 0
EVSE/Modularization/ocppfiles/common.c

@@ -7,6 +7,24 @@
 
 #include "Module_OcppBackend.h"
 
+void refreshStartTimer(struct timespec *timer)
+{
+	clock_gettime(CLOCK_MONOTONIC, timer);
+}
+
+int getDiffSecNow(struct timespec timer)
+{
+	struct timespec timerNow;
+
+	clock_gettime(CLOCK_MONOTONIC, &timerNow);
+
+	return (int)((((unsigned long)(timerNow.tv_sec - timer.tv_sec) * 1000) + ((unsigned long)((timerNow.tv_nsec / 1000000) - (timer.tv_nsec / 1000000))))/1000);
+}
+
+int getDiffSecBetween(struct timespec start, struct timespec end)
+{
+	return (int)((((unsigned long)(end.tv_sec - start.tv_sec) * 1000) + ((unsigned long)((end.tv_nsec / 1000000) - (start.tv_nsec / 1000000))))/1000);
+}
 
 void work(char s[])        // Delete space on start & end
 {

Разлика између датотеке није приказан због своје велике величине
+ 801 - 42
EVSE/Modularization/ocppph/MessageHandler.c


+ 9 - 9
EVSE/Modularization/ocppph/Module_OcppBackend.c

@@ -11,9 +11,9 @@ pthread_t tid_Watchdog;
 
 struct StartTime
 {
-	unsigned int connect;
-	unsigned int bootNotification;
-	unsigned int reConnect;
+	struct timespec connect;
+	struct timespec bootNotification;
+	struct timespec reConnect;
 }startTime;
 
 struct QueueOpInfo queueOpInfo;
@@ -1506,11 +1506,11 @@ int main(void)
 			SetOcppConnStatus(FALSE);
 			SetServerSign(FALSE);
 			InitialSystemValue();
-			if((time((time_t*)NULL)-startTime.connect) >= 30)
+			if(getDiffSecNow(startTime.connect) >= 30)
 			{
 				DEBUG_INFO("Server connecting...\n");
 				pthread_create(&tid_connectServer, NULL, ConnectWsServer, NULL);
-				startTime.connect=time((time_t*)NULL);
+				refreshStartTimer(&startTime.connect);
 			}
 			CheckSystemValue();
 		}
@@ -1519,11 +1519,11 @@ int main(void)
 			// Sign in
 			if((GetServerSign() == FALSE) &&
 			   (isConnectorInitMode(0) != TRUE) &&
-			   ( (GetBootNotificationInterval()>0) ? ((time((time_t*)NULL)-startTime.bootNotification) >= GetBootNotificationInterval()) : ((time((time_t*)NULL)-startTime.bootNotification) >= defaultWaitingTime) )
+			   ( (GetBootNotificationInterval()>0) ? (getDiffSecNow(startTime.bootNotification) >= GetBootNotificationInterval()) : (getDiffSecNow(startTime.bootNotification) >= defaultWaitingTime) )
 			  )
 			{
 				sendBootNotificationRequest();
-				startTime.bootNotification=time((time_t*)NULL);
+				refreshStartTimer(&startTime.bootNotification);
 			}
 
 			// On line operation
@@ -1550,7 +1550,7 @@ int main(void)
 
 				if((changeChageWebSocketPingInterval == TRUE) || (GetOcppConnStatus() == 0))
 				{
-					if(((time((time_t*)NULL)-startTime.reConnect) >= 3) || ((time((time_t*)NULL)-startTime.reConnect) < 0))
+					if(getDiffSecNow(startTime.reConnect) >= 3)
 					{
 						DEBUG_INFO("GetOcppConnStatus() = %d\n", GetOcppConnStatus());
 
@@ -1567,7 +1567,7 @@ int main(void)
 				}
 				else
 				{
-					startTime.reConnect = time((time_t*)NULL);
+					refreshStartTimer(&startTime.reConnect);
 				}
 			}
 		}

+ 3 - 0
EVSE/Modularization/ocppph/Module_OcppBackend.h

@@ -154,6 +154,9 @@ extern void splitstring(char *src, const char *separator, char **dest,int *num);
 extern char* stringtrim( char * s );
 extern char* stringtrimspace( char * s );
 extern char * strtrim( char * s );
+extern void refreshStartTimer(struct timespec *timer);
+extern int getDiffSecNow(struct timespec timer);
+extern int getDiffSecBetween(struct timespec start, struct timespec end);
 
 extern struct lws 					*wsi_client;
 extern struct lws_context 			*context;

+ 18 - 0
EVSE/Modularization/ocppph/common.c

@@ -7,6 +7,24 @@
 
 #include "Module_OcppBackend.h"
 
+void refreshStartTimer(struct timespec *timer)
+{
+	clock_gettime(CLOCK_MONOTONIC, timer);
+}
+
+int getDiffSecNow(struct timespec timer)
+{
+	struct timespec timerNow;
+
+	clock_gettime(CLOCK_MONOTONIC, &timerNow);
+
+	return (int)((((unsigned long)(timerNow.tv_sec - timer.tv_sec) * 1000) + ((unsigned long)((timerNow.tv_nsec / 1000000) - (timer.tv_nsec / 1000000))))/1000);
+}
+
+int getDiffSecBetween(struct timespec start, struct timespec end)
+{
+	return (int)((((unsigned long)(end.tv_sec - start.tv_sec) * 1000) + ((unsigned long)((end.tv_nsec / 1000000) - (start.tv_nsec / 1000000))))/1000);
+}
 
 void work(char s[])        // Delete space on start & end
 {

+ 4 - 5
EVSE/Projects/AX80/Apps/Module_Cabinet.c

@@ -977,17 +977,16 @@ int main(void)
 
 	/*
 	 * 	TODO:
-	 * 		1. Check rotary switch to determine socket server is rising up
-	 *
+	 * 		1. Rotary switch define change with system specification
 	 */
 
 	while(ShmDispenser->gun_info.mcuFlag.isReadFwVerPass ||
 	      ShmDispenser->gun_info.mcuFlag.isSetModelNamePass ||
 	      ShmDispenser->gun_info.mcuFlag.isSetSerialNumberPass)sleep(5);
 
-	if(ShmDispenser->gun_info.primaryMcuState.rotatory_switch == 0)
+	if(ShmDispenser->gun_info.primaryMcuState.rotatory_switch == ROTARY_SWITCH_E_DISPENSER)
 	{
-		system("/sbin/ifconfig eth0:1 192.168.201.201 netmask 255.255.255.248 up &");
+		system("/sbin/ifconfig eth0:1 192.168.201.202 netmask 255.255.255.248 up &");
 	}
 	else
 	{
@@ -995,7 +994,7 @@ int main(void)
 	}
 
 	DEBUG_SERVER_INFO("Module_Cabinet initialized...\n");
-	if(1)
+	if(ShmDispenser->gun_info.primaryMcuState.rotatory_switch != ROTARY_SWITCH_E_DISPENSER)
 	{
 		// TCP socket server start
 		if(fork() == 0)

+ 233 - 222
EVSE/Projects/AX80/Apps/main.c

@@ -2511,41 +2511,35 @@ void InitEthernet()
 	DEBUG_INFO("Initial Ethernet OK\n");
 }
 
-int SpawnTask(uint8_t gun_index)
+int SpawnTask()
 {
-	if(gun_index == 0)
+	system ("pkill Module_");
+	system ("pkill OcppBackend");
+
+	/*
+	if((ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'T') || (ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D'))
 	{
-		system ("pkill Module_");
-		system ("pkill OcppBackend");
+		system("/root/Module_4g &");
+	}
 
-		if((ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'T') || (ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D'))
-		{
-			system("/root/Module_4g &");
-		}
-		else if(ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'W')
-		{
-			system("/root/Module_Wifi &");
-		}
+	if(ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'W' || (ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D'))
+	{
+		system("/root/Module_Wifi &");
+	}*/
 
-		system("/root/Module_EventLogging &");
+	system("/root/Module_EventLogging &");
 
-		if(strcmp((char *)&ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0)
-		{
-			ocpp_process_start();
-		}
-		else
-		{
-			DEBUG_INFO("OCPP URL is empty, need to create a configuration table !!!\n");
-			ocpp_process_start();
-		}
-		system ("/root/Module_AlarmDetect &");
-		system ("/root/Module_InternalComm &");
-		system ("/root/Module_Speaker &");
-		system ("/root/Module_ProduceUtils &");
-		system ("/root/Module_LcmControl &");
-		system ("/root/Module_Cabinet &");
-		system ("/root/Module_Dispenser &");
-	}
+	ocpp_process_start();
+	if(strcmp((char *)&ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") == 0)
+		DEBUG_INFO("OCPP URL is empty, need to create a configuration table !!!\n");
+
+	//system ("/root/Module_AlarmDetect &");
+	system ("/root/Module_InternalComm &");
+	//system ("/root/Module_Speaker &");
+	system ("/root/Module_ProduceUtils &");
+	//system ("/root/Module_LcmControl &");
+	system ("/root/Module_Cabinet &");
+	system ("/root/Module_Dispenser &");
 
 	return PASS;
 }
@@ -2571,42 +2565,39 @@ int Initialization(uint8_t gun_index)
 {
 	int result = PASS;
 
-	if(gun_index == 0)
-	{
-		InitGPIO();
-
-		InitEthernet();
+	InitGPIO();
 
-		if(InitQca7000() != PASS)
-		{
-			DEBUG_ERROR("QCA7000 initial fail.\n");
-			result = FAIL;
-		}
+	InitEthernet();
 
-		if(DB_Open(localDb) != PASS)
-		{
-			DEBUG_ERROR("Local database initial fail.\n");
-			result = FAIL;
-		}
+	if(InitQca7000() != PASS)
+	{
+		DEBUG_ERROR("QCA7000 initial fail.\n");
+		result = FAIL;
+	}
 
-		if((rfidFd = InitRfidPort()) == FAIL)
-		{
-			DEBUG_ERROR("RFID port initial fail.\n");
-			result = FAIL;
-		}
+	if(DB_Open(localDb) != PASS)
+	{
+		DEBUG_ERROR("Local database initial fail.\n");
+		result = FAIL;
+	}
 
-		if((wtdFd = InitWatchDog()) == FAIL)
-		{
-			DEBUG_ERROR("Watchdog initial fail.\n");
-			result = FAIL;
-		}
+	if((rfidFd = InitRfidPort()) == FAIL)
+	{
+		DEBUG_ERROR("RFID port initial fail.\n");
+		result = FAIL;
+	}
 
-		if(result == PASS)
-			DEBUG_INFO("Initialization OK.\n");
-		else
-			DEBUG_INFO("Initialization Fail.\n");
+	if((wtdFd = InitWatchDog()) == FAIL)
+	{
+		DEBUG_ERROR("Watchdog initial fail.\n");
+		result = FAIL;
 	}
 
+	if(result == PASS)
+		DEBUG_INFO("Initialization OK.\n");
+	else
+		DEBUG_INFO("Initialization Fail.\n");
+
 	ShmCharger->gun_info[gun_index].isOperactive = DB_Get_Operactive(localDb, gun_index);
 
 	return result;
@@ -3930,72 +3921,107 @@ int isValidLocalWhiteCard()
 //==========================================
 void checkTask()
 {
-	if((ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'T') || (ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D'))
+	/*
+	 * 	TODO:
+	 * 		1. Rotary switch define change with system specification
+	 */
+	// Task run only on cabinet
+	if(ShmDispenser->gun_info.primaryMcuState.rotatory_switch != ROTARY_SWITCH_E_DISPENSER)
 	{
-		if(system("pidof -s Module_4g > /dev/null") != 0)
+		if((ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'T') || (ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D'))
 		{
-			DEBUG_INFO("Module_4g not running, restart it.\n");
-			system("/root/Module_4g &");
+			if(system("pidof -s Module_4g > /dev/null") != 0)
+			{
+				DEBUG_INFO("Module_4g not running, restart it.\n");
+				system("/root/Module_4g &");
+			}
 		}
-	}
 
-	if((ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D'))
-	{
-		if(system("pidof -s Module_Wifi > /dev/null") != 0)
+		if((ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D'))
 		{
-			DEBUG_INFO("Module_Wifi not running, restart it.\n");
-			system("/root/Module_Wifi &");
+			if(system("pidof -s Module_Wifi > /dev/null") != 0)
+			{
+				DEBUG_INFO("Module_Wifi not running, restart it.\n");
+				system("/root/Module_Wifi &");
+			}
 		}
-	}
 
-	if(system("pidof -s Module_EventLogging > /dev/null") != 0)
-	{
-		DEBUG_INFO("Module_EventLogging not running, restart it.\n");
-		system("/root/Module_EventLogging &");
-	}
-
-	if((strcmp((char *)&ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) && !ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharging)
-	{
-		if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
+		if((strcmp((char *)&ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) && !ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharging)
 		{
-			if((time((time_t*)NULL) - ShmOCPP16Data->procDogTime) > 180)
+			if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
 			{
-				DEBUG_WARN("OcppBackend watch dog timeout task restart.\n");
-				ShmOCPP16Data->procDogTime =  time((time_t*)NULL);
-				system("pkill OcppBackend");
-				sleep(3);
-				ocpp_process_start();
-			}
+				if((time((time_t*)NULL) - ShmOCPP16Data->procDogTime) > 180)
+				{
+					DEBUG_WARN("OcppBackend watch dog timeout task restart.\n");
+					ShmOCPP16Data->procDogTime =  time((time_t*)NULL);
+					system("pkill OcppBackend");
+					sleep(3);
+					ocpp_process_start();
+				}
 
-			if(system("pidof -s OcppBackend > /dev/null") != 0)
+				if(system("pidof -s OcppBackend > /dev/null") != 0)
+				{
+					DEBUG_INFO("OcppBackend not running, restart it.\n");
+					ocpp_process_start();
+				}
+			}
+			else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
 			{
-				DEBUG_INFO("OcppBackend not running, restart it.\n");
-				ocpp_process_start();
+				if((time((time_t*)NULL) - ShmOCPP20Data->procDogTime) > 180)
+				{
+					DEBUG_WARN("OcppBackend20 watch dog timeout task restart.\n");
+					ShmOCPP20Data->procDogTime =  time((time_t*)NULL);
+					system("pkill OcppBackend20");
+					sleep(3);
+					ocpp_process_start();
+				}
+
+				if(system("pidof -s OcppBackend20 > /dev/null") != 0)
+				{
+					DEBUG_INFO("OcppBackend20 not running, restart it.\n");
+					ocpp_process_start();
+				}
 			}
 		}
-		else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
+
+		if(system("pidof -s Module_Speaker > /dev/null") != 0)
 		{
-			if((time((time_t*)NULL) - ShmOCPP20Data->procDogTime) > 180)
-			{
-				DEBUG_WARN("OcppBackend20 watch dog timeout task restart.\n");
-				ShmOCPP20Data->procDogTime =  time((time_t*)NULL);
-				system("pkill OcppBackend20");
-				sleep(3);
-				ocpp_process_start();
-			}
+			DEBUG_INFO("Module_Speaker not running, restart it.\n");
+			system("/root/Module_Speaker &");
+		}
 
-			if(system("pidof -s OcppBackend20 > /dev/null") != 0)
-			{
-				DEBUG_INFO("OcppBackend20 not running, restart it.\n");
-				ocpp_process_start();
-			}
+		if(system("pidof -s Module_LcmControl > /dev/null") != 0)
+		{
+			DEBUG_INFO("Module_LcmControl not running, restart it.\n");
+			system ("/root/Module_LcmControl &");
+		}
+
+		if((system("pidof -s Module_PowerSharing > /dev/null") != 0) &&
+			ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharging)
+		{
+			DEBUG_INFO("Module_PowerSharing not running, restart it.\n");
+			system ("/root/Module_PowerSharing &");
+		}
+
+		if((system("pidof -s Module_InitUpgrade > /dev/null") != 0) &&
+			ShmSysConfigAndInfo->SysConfig.isReqFirstUpgrade)
+		{
+			DEBUG_INFO("Module_InitUpgrade not running, restart it.\n");
+			system ("/root/Module_InitUpgrade &");
+		}
+
+		if(system("pidof -s Module_AlarmDetect > /dev/null") != 0)
+		{
+			DEBUG_INFO("Module_AlarmDetect not running, restart it.\n");
+			system("/root/Module_AlarmDetect &");
 		}
 	}
 
-	if(system("pidof -s Module_AlarmDetect > /dev/null") != 0)
+	// Task run both on cabinet and dispenser
+	if(system("pidof -s Module_EventLogging > /dev/null") != 0)
 	{
-		DEBUG_INFO("Module_AlarmDetect not running, restart it.\n");
-		system("/root/Module_AlarmDetect &");
+		DEBUG_INFO("Module_EventLogging not running, restart it.\n");
+		system("/root/Module_EventLogging &");
 	}
 
 	if(system("pidof -s Module_InternalComm > /dev/null") != 0)
@@ -4004,38 +4030,12 @@ void checkTask()
 		system("/root/Module_InternalComm &");
 	}
 
-	if(system("pidof -s Module_Speaker > /dev/null") != 0)
-	{
-		DEBUG_INFO("Module_Speaker not running, restart it.\n");
-		system("/root/Module_Speaker &");
-	}
-
 	if(system("pidof -s Module_ProduceUtils > /dev/null") != 0)
 	{
 		DEBUG_INFO("Module_ProduceUtils not running, restart it.\n");
 		system ("/root/Module_ProduceUtils &");
 	}
 
-	if(system("pidof -s Module_LcmControl > /dev/null") != 0)
-	{
-		DEBUG_INFO("Module_LcmControl not running, restart it.\n");
-		system ("/root/Module_LcmControl &");
-	}
-
-	if((system("pidof -s Module_PowerSharing > /dev/null") != 0) &&
-		ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharging)
-	{
-		DEBUG_INFO("Module_PowerSharing not running, restart it.\n");
-		system ("/root/Module_PowerSharing &");
-	}
-
-	if((system("pidof -s Module_InitUpgrade > /dev/null") != 0) &&
-		ShmSysConfigAndInfo->SysConfig.isReqFirstUpgrade)
-	{
-		DEBUG_INFO("Module_InitUpgrade not running, restart it.\n");
-		system ("/root/Module_InitUpgrade &");
-	}
-
 	if((system("pidof -s Module_Cabinet > /dev/null") != 0))
 	{
 		DEBUG_INFO("Module_Cabinet not running, restart it.\n");
@@ -4809,6 +4809,12 @@ int main(void)
 		DEBUG_INFO("CreatShareMemory OK\n");
 	}
 
+	if(SpawnTask() != PASS)
+	{
+		ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed = ON;
+		DEBUG_ERROR("Task spawn fail.\n");
+	}
+
 	for(int gun_index = 0;gun_index<AC_QUANTITY;gun_index++)
 	{
 		ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PreviousSystemStatus = 0xff;
@@ -4852,10 +4858,14 @@ int main(void)
 		//==============================================
 		// Connector loop
 		//==============================================
-		for(int gun_index = 0;gun_index<modelnameInfo.GetGunCount;gun_index++)
+		/*
+		 * 	TODO:
+		 * 		1. Rotary switch define change with system specification
+		 */
+		// Only process main logic on cabinet
+		if(ShmDispenser->gun_info.primaryMcuState.rotatory_switch != ROTARY_SWITCH_E_DISPENSER)
 		{
-			// Only process main logic on cabinet
-			if(gun_index == 0)
+			for(int gun_index = 0;gun_index<modelnameInfo.GetGunCount;gun_index++)
 			{
 				//==============================================
 				// Synchronize share memory from OCPP struct
@@ -4926,121 +4936,124 @@ int main(void)
 				//==========================================
 				// Power saving logic
 				//==========================================
-				if(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PilotState == CP_STATE_A)
+				if(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].SystemStatus > SYS_MODE_BOOTING)
 				{
-					refreshStartTimer(&startTime[gun_index][TMR_IDX_POWERSAVING_STATE_B]);
-				}
+					if(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PilotState == CP_STATE_A)
+					{
+						refreshStartTimer(&startTime[gun_index][TMR_IDX_POWERSAVING_STATE_B]);
+					}
 
-				if((ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].SystemStatus == SYS_MODE_ALARM) ||
-				   (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].SystemStatus == SYS_MODE_FAULT) ||
-				   (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].SystemStatus == SYS_MODE_UPDATE) ||
-				   (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].SystemStatus == SYS_MODE_MAINTAIN) ||
-				   (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].SystemStatus == SYS_MODE_CHARGING) ||
-				   (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].SystemStatus == SYS_MODE_TERMINATING) ||
-				   (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].SystemStatus == SYS_MODE_COMPLETE))
-				{
-					refreshStartTimer(&startTime[gun_index][TMR_IDX_POWERSAVING_LCD]);
-					refreshStartTimer(&startTime[gun_index][TMR_IDX_POWERSAVING_RFID]);
-					refreshStartTimer(&startTime[gun_index][TMR_IDX_POWERSAVING_METER]);
-					refreshStartTimer(&startTime[gun_index][TMR_IDX_POWERSAVING_LED_STATUS]);
-				}
-				else
-				{
-					if((gpio_get_value(GPIO_IN_WAKEUP) == OFF) ||
-					   (ShmCharger->gun_info[gun_index].GPIO_Input.Button_Mode_Switch == ON) ||
-					   (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PreviousSystemStatus != ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].SystemStatus) ||
-					   (((ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].SystemStatus == SYS_MODE_IDLE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].SystemStatus == SYS_MODE_RESERVATION)) &&
-						(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PilotState == CP_STATE_B) &&
-						(getDiffSecNow(startTime[gun_index][TMR_IDX_POWERSAVING_STATE_B]) < 10)))
+					if((ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].SystemStatus == SYS_MODE_ALARM) ||
+					   (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].SystemStatus == SYS_MODE_FAULT) ||
+					   (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].SystemStatus == SYS_MODE_UPDATE) ||
+					   (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].SystemStatus == SYS_MODE_MAINTAIN) ||
+					   (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].SystemStatus == SYS_MODE_CHARGING) ||
+					   (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].SystemStatus == SYS_MODE_TERMINATING) ||
+					   (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].SystemStatus == SYS_MODE_COMPLETE))
 					{
 						refreshStartTimer(&startTime[gun_index][TMR_IDX_POWERSAVING_LCD]);
 						refreshStartTimer(&startTime[gun_index][TMR_IDX_POWERSAVING_RFID]);
 						refreshStartTimer(&startTime[gun_index][TMR_IDX_POWERSAVING_METER]);
 						refreshStartTimer(&startTime[gun_index][TMR_IDX_POWERSAVING_LED_STATUS]);
-
-						if(((gpio_get_value(GPIO_IN_WAKEUP) == OFF) || (ShmCharger->gun_info[gun_index].GPIO_Input.Button_Mode_Switch == ON)) &&
-						   (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].SystemStatus == SYS_MODE_IDLE) &&
-						   (getDiffSecNow(startTime[ShmCharger->gun_selectd][TMR_IDX_CHECK_POWER_CONSUMPTION]) > TIMEOUT_SPEC_CEHCK_POWER_CONSUMPTION))
-						{
-							ShmCharger->gun_info[gun_index].isCheckPowerConsumption = YES;
-							refreshStartTimer(&startTime[gun_index][TMR_IDX_LCM_POWER_CONSUMPTION]);
-						}
 					}
 					else
 					{
-						refreshStartTimer(&startTime[gun_index][TMR_IDX_CHECK_POWER_CONSUMPTION]);
-						if((getDiffSecNow(startTime[ShmCharger->gun_selectd][TMR_IDX_LCM_POWER_CONSUMPTION]) > TIMEOUT_SPEC_CEHCK_POWER_CONSUMPTION))
+						if((gpio_get_value(GPIO_IN_WAKEUP) == OFF) ||
+						   (ShmCharger->gun_info[gun_index].GPIO_Input.Button_Mode_Switch == ON) ||
+						   (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PreviousSystemStatus != ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].SystemStatus) ||
+						   (((ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].SystemStatus == SYS_MODE_IDLE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].SystemStatus == SYS_MODE_RESERVATION)) &&
+							(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].PilotState == CP_STATE_B) &&
+							(getDiffSecNow(startTime[gun_index][TMR_IDX_POWERSAVING_STATE_B]) < 10)))
 						{
-							ShmCharger->gun_info[gun_index].isCheckPowerConsumption = NO;
+							refreshStartTimer(&startTime[gun_index][TMR_IDX_POWERSAVING_LCD]);
+							refreshStartTimer(&startTime[gun_index][TMR_IDX_POWERSAVING_RFID]);
+							refreshStartTimer(&startTime[gun_index][TMR_IDX_POWERSAVING_METER]);
+							refreshStartTimer(&startTime[gun_index][TMR_IDX_POWERSAVING_LED_STATUS]);
+
+							if(((gpio_get_value(GPIO_IN_WAKEUP) == OFF) || (ShmCharger->gun_info[gun_index].GPIO_Input.Button_Mode_Switch == ON)) &&
+							   (ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].SystemStatus == SYS_MODE_IDLE) &&
+							   (getDiffSecNow(startTime[ShmCharger->gun_selectd][TMR_IDX_CHECK_POWER_CONSUMPTION]) > TIMEOUT_SPEC_CEHCK_POWER_CONSUMPTION))
+							{
+								ShmCharger->gun_info[gun_index].isCheckPowerConsumption = YES;
+								refreshStartTimer(&startTime[gun_index][TMR_IDX_LCM_POWER_CONSUMPTION]);
+							}
+						}
+						else
+						{
+							refreshStartTimer(&startTime[gun_index][TMR_IDX_CHECK_POWER_CONSUMPTION]);
+							if((getDiffSecNow(startTime[ShmCharger->gun_selectd][TMR_IDX_LCM_POWER_CONSUMPTION]) > TIMEOUT_SPEC_CEHCK_POWER_CONSUMPTION))
+							{
+								ShmCharger->gun_info[gun_index].isCheckPowerConsumption = NO;
+							}
 						}
 					}
-				}
 
-				if(getDiffSecNow(startTime[ShmCharger->gun_selectd][TMR_IDX_POWERSAVING_LCD]) > TIMEOUT_SPEC_POWERSAVING_LCD)
-				{
-					if(ShmCharger->isLcdOn == ON)
+					if(getDiffSecNow(startTime[ShmCharger->gun_selectd][TMR_IDX_POWERSAVING_LCD]) > TIMEOUT_SPEC_POWERSAVING_LCD)
 					{
-						DEBUG_INFO("LCD into power saving...%d\n", getDiffSecNow(startTime[ShmCharger->gun_selectd][TMR_IDX_POWERSAVING_LCD]));
-						ShmCharger->isLcdOn = OFF;
+						if(ShmCharger->isLcdOn == ON)
+						{
+							DEBUG_INFO("LCD into power saving...%d\n", getDiffSecNow(startTime[ShmCharger->gun_selectd][TMR_IDX_POWERSAVING_LCD]));
+							ShmCharger->isLcdOn = OFF;
+						}
 					}
-				}
-				else
-				{
-					if(ShmCharger->isLcdOn == OFF)
+					else
 					{
-						DEBUG_INFO("LCD exit power saving...%d\n", getDiffSecNow(startTime[ShmCharger->gun_selectd][TMR_IDX_POWERSAVING_LCD]));
-						ShmCharger->isLcdOn = ON;
+						if(ShmCharger->isLcdOn == OFF)
+						{
+							DEBUG_INFO("LCD exit power saving...%d\n", getDiffSecNow(startTime[ShmCharger->gun_selectd][TMR_IDX_POWERSAVING_LCD]));
+							ShmCharger->isLcdOn = ON;
+						}
 					}
-				}
 
-				if(getDiffSecNow(startTime[ShmCharger->gun_selectd][TMR_IDX_POWERSAVING_RFID]) > TIMEOUT_SPEC_POWERSAVING_RFID)
-				{
-					if(gpio_get_value(GPIO_OUT_RST_RFID) == ON)
+					if(getDiffSecNow(startTime[ShmCharger->gun_selectd][TMR_IDX_POWERSAVING_RFID]) > TIMEOUT_SPEC_POWERSAVING_RFID)
 					{
-						DEBUG_INFO("RFID into power saving...%d\n", getDiffSecNow(startTime[ShmCharger->gun_selectd][TMR_IDX_POWERSAVING_RFID]));
-						gpio_set_value(GPIO_OUT_RST_RFID, OFF);
+						if(gpio_get_value(GPIO_OUT_RST_RFID) == ON)
+						{
+							DEBUG_INFO("RFID into power saving...%d\n", getDiffSecNow(startTime[ShmCharger->gun_selectd][TMR_IDX_POWERSAVING_RFID]));
+							gpio_set_value(GPIO_OUT_RST_RFID, OFF);
+						}
 					}
-				}
-				else
-				{
-					if(gpio_get_value(GPIO_OUT_RST_RFID) == OFF)
+					else
 					{
-						DEBUG_INFO("RFID exit power saving...%d\n", getDiffSecNow(startTime[ShmCharger->gun_selectd][TMR_IDX_POWERSAVING_RFID]));
-						gpio_set_value(GPIO_OUT_RST_RFID, ON);
+						if(gpio_get_value(GPIO_OUT_RST_RFID) == OFF)
+						{
+							DEBUG_INFO("RFID exit power saving...%d\n", getDiffSecNow(startTime[ShmCharger->gun_selectd][TMR_IDX_POWERSAVING_RFID]));
+							gpio_set_value(GPIO_OUT_RST_RFID, ON);
+						}
 					}
-				}
 
-				if(getDiffSecNow(startTime[gun_index][TMR_IDX_POWERSAVING_METER]) > TIMEOUT_SPEC_POWERSAVING_METER)
-				{
-					if(ShmCharger->gun_info[gun_index].isMeterOn)
+					if(getDiffSecNow(startTime[gun_index][TMR_IDX_POWERSAVING_METER]) > TIMEOUT_SPEC_POWERSAVING_METER)
 					{
-						DEBUG_INFO("Meter into power saving...%d\n", getDiffSecNow(startTime[gun_index][TMR_IDX_POWERSAVING_METER]));
-						ShmCharger->gun_info[gun_index].isMeterOn = OFF;
+						if(ShmCharger->gun_info[gun_index].isMeterOn)
+						{
+							DEBUG_INFO("Meter into power saving...%d\n", getDiffSecNow(startTime[gun_index][TMR_IDX_POWERSAVING_METER]));
+							ShmCharger->gun_info[gun_index].isMeterOn = OFF;
+						}
 					}
-				}
-				else
-				{
-					if(!ShmCharger->gun_info[gun_index].isMeterOn)
+					else
 					{
-						DEBUG_INFO("Meter exit power saving...%d\n", getDiffSecNow(startTime[gun_index][TMR_IDX_POWERSAVING_METER]));
-						ShmCharger->gun_info[gun_index].isMeterOn = ON;
+						if(!ShmCharger->gun_info[gun_index].isMeterOn)
+						{
+							DEBUG_INFO("Meter exit power saving...%d\n", getDiffSecNow(startTime[gun_index][TMR_IDX_POWERSAVING_METER]));
+							ShmCharger->gun_info[gun_index].isMeterOn = ON;
+						}
 					}
-				}
 
-				if(getDiffSecNow(startTime[gun_index][TMR_IDX_POWERSAVING_LED_STATUS]) > TIMEOUT_SPEC_POWERSAVING_LED_STATUS)
-				{
-					if(ShmCharger->gun_info[gun_index].isSleepOn == NO)
+					if(getDiffSecNow(startTime[gun_index][TMR_IDX_POWERSAVING_LED_STATUS]) > TIMEOUT_SPEC_POWERSAVING_LED_STATUS)
 					{
-						DEBUG_INFO("LED status into power saving...%d\n", getDiffSecNow(startTime[gun_index][TMR_IDX_POWERSAVING_LED_STATUS]));
-						ShmCharger->gun_info[gun_index].isSleepOn = YES;
+						if(ShmCharger->gun_info[gun_index].isSleepOn == NO)
+						{
+							DEBUG_INFO("LED status into power saving...%d\n", getDiffSecNow(startTime[gun_index][TMR_IDX_POWERSAVING_LED_STATUS]));
+							ShmCharger->gun_info[gun_index].isSleepOn = YES;
+						}
 					}
-				}
-				else
-				{
-					if(ShmCharger->gun_info[gun_index].isSleepOn == YES)
+					else
 					{
-						DEBUG_INFO("LED status exit power saving...%d\n", getDiffSecNow(startTime[gun_index][TMR_IDX_POWERSAVING_LED_STATUS]));
-						ShmCharger->gun_info[gun_index].isSleepOn = NO;
+						if(ShmCharger->gun_info[gun_index].isSleepOn == YES)
+						{
+							DEBUG_INFO("LED status exit power saving...%d\n", getDiffSecNow(startTime[gun_index][TMR_IDX_POWERSAVING_LED_STATUS]));
+							ShmCharger->gun_info[gun_index].isSleepOn = NO;
+						}
 					}
 				}
 
@@ -5137,8 +5150,7 @@ int main(void)
 							setLedMotion(gun_index,LED_ACTION_INIT);
 
 							//CSU Initialization & task spawn
-							if((Initialization(gun_index) != PASS) ||
-							   (SpawnTask(gun_index) != PASS))
+							if(Initialization(gun_index) != PASS)
 							{
 								ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed = ON;
 							}
@@ -5432,6 +5444,7 @@ int main(void)
 							refreshStartTimer(&startTime[gun_index][TMR_IDX_HANDSHAKING]);
 							setLedMotion(gun_index, LED_ACTION_AUTHED);
 							ShmCharger->gun_info[gun_index].resultAuthorization = DEFAULT_RFID;
+							if(ShmCharger->isCcsEnable)refreshStartTimer(&startTime[gun_index][TMR_IDX_BS_HLC_HANDSHAKE]);
 						}
 
 						// If control pilot detect Bx, skip watch dog time out.
@@ -5449,7 +5462,6 @@ int main(void)
 							switch(ShmCharger->gun_info[gun_index].ccsHandshakeState)
 							{
 								case HANDSHAKE_DUTY_5:
-									break;
 								case HANDSHAKE_DUTY_5_CHECK:
 									refreshStartTimer(&startTime[gun_index][TMR_IDX_BS_HLC_HANDSHAKE]);
 									DEBUG_INFO("HLC slac handshake start.\n");
@@ -6262,7 +6274,6 @@ int main(void)
 				}
 			}
 		}
-
 		// System watch dog reset
 		write(wtdFd, "a", 1);
 

+ 26 - 1
EVSE/Projects/AX80/Apps/main.h

@@ -252,6 +252,31 @@ enum RFID_AUTHORIZATION_STATUS
 	UNKNOW_RFID
 };
 
+
+/*
+ * 	TODO:
+ * 		1. Rotary switch define change with system specification
+ */
+enum ROTARY_SWITCH
+{
+	ROTARY_SWITCH_0_DEBUG=0,
+	ROTARY_SWITCH_1_6A,
+	ROTARY_SWITCH_2_8A,
+	ROTARY_SWITCH_3_10A,
+	ROTARY_SWITCH_4_13A,
+	ROTARY_SWITCH_5_16A,
+	ROTARY_SWITCH_6_20A,
+	ROTARY_SWITCH_7_25A,
+	ROTARY_SWITCH_8_30A,
+	ROTARY_SWITCH_9_32A,
+	ROTARY_SWITCH_A_40A,
+	ROTARY_SWITCH_B_48A,
+	ROTARY_SWITCH_C_RESERVE,
+	ROTARY_SWITCH_D_80A,
+	ROTARY_SWITCH_E_DISPENSER,
+	ROTARY_SWITCH_F_POWERSHARING_SLAVE
+};
+
 #define DEBUG_INFO(format, args...) StoreLogMsg("[%s:%d][%s][Info] "format, (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__), __LINE__, __FUNCTION__, ##args)
 #define DEBUG_WARN(format, args...) StoreLogMsg("[%s:%d][%s][Warn] "format, (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__), __LINE__, __FUNCTION__, ##args)
 #define DEBUG_ERROR(format, args...) StoreLogMsg("[%s:%d][%s][Error] "format, (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__), __LINE__, __FUNCTION__, ##args)
@@ -774,7 +799,7 @@ struct Charger
 {
 	Ver 					ver;
 	Evse_Id					evseId;
-	Gun_Info 				gun_info[2];
+	Gun_Info 				gun_info[3];
 	Fw_Upgrade_Info			fwUpgradeInfo;
 	Timeout_Spec			timeoutSpec;
 

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


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


+ 4 - 2
EVSE/Projects/define.h

@@ -4670,7 +4670,8 @@ struct OCPP16Data
             unsigned char InstallCertificateConf :1;                //bit 3
             unsigned char SignedUpdateFirmwareReq :1;               //bit 4
             unsigned char SignedUpdateFirmwareConf :1;              //bit 5
-            unsigned char :2;                                       //bit 6 & 7
+            unsigned char isRemoteStartWaitReq :1;					//bit 6
+            unsigned char :1;                                       //bit 7
         } bits;
     } MsMsg;
 
@@ -6020,7 +6021,8 @@ struct OCPP20Data
 			unsigned char UnpublishFirmwareConf :1;
 			unsigned char UpdateFirmwareReq :1;
 			unsigned char UpdateFirmwareConf :1;
-			unsigned char :2;
+			unsigned char isRemoteStartWaitReq :1;
+			unsigned char :1;
 		} bits;
 	} MsMsg;
 

Неке датотеке нису приказане због велике количине промена