Explorar o código

[Improve][Modularization][Module_OcppBackend / Module_OcppBackend20 / Module_OcppBackendPH]

2022.10.21 / Folus Wen

Actions:
1. Task kill every 2 hours if disconnected from OCPP server.

Files:
1. As follow commit history

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

Hardware PWB P/N : XXXXXXX
Hardware Version : XXXXXXX
Folus Wen %!s(int64=2) %!d(string=hai) anos
pai
achega
d4e091a841

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

@@ -14,7 +14,7 @@ struct StartTime
 	struct timespec connect;
 	struct timespec bootNotification;
 	struct timespec reConnect;
-	struct timespec startTimeDog;
+	struct timespec disconnectServer;
 	struct timespec startTimeQueue;
 	struct timespec pingOn;
 }startTime;
@@ -36,7 +36,6 @@ int OcppPort=0;
 unsigned char StartTransactionIdTagTemp[20]={0};
 uint8_t	isWebsocketSendable = 1;
 uint8_t	isQueueSendable = 1;
-uint8_t	counterLwsRestart = 0;;
 uint8_t counterQueueSent = 0;
 uint8_t	counterConnect = 0;
 uint8_t counterPingSend = 0;
@@ -957,21 +956,10 @@ void* processWatchdog()
 {
 	for(;;)
 	{
-		if((getDiffSecNow(startTime.startTimeDog) > 10) && (context != NULL))
+		if((getDiffSecNow(startTime.disconnectServer) >= 7200))
 		{
-			DEBUG_INFO("LWS watch dog timeout.\n");
-			lws_cancel_service(context);
-			lws_cancel_service_pt(wsi_client);
-
-			if(counterLwsRestart >= 3)
-			{
-				DEBUG_INFO("LWS watch dog timeout over 3 count.\n");
-				system("killall OcppBackend20");
-			}
-			else
-				counterLwsRestart++;
-
-			refreshStartTimer(&startTime.startTimeDog);
+			DEBUG_INFO("OCPP server disconnect timer(%d) over 7200 seconds.\n", getDiffSecNow(startTime.disconnectServer));
+			system("killall OcppBackend20");
 		}
 		
 		if(counterConnect >= 3)
@@ -1124,6 +1112,7 @@ int main(void)
 	memset(rmFileCmd, 0, ARRAY_SIZE(rmFileCmd));
 
 	// Create Process: Resend Transaction
+	refreshStartTimer(&startTime.disconnectServer);
 	pthread_create(&tid_ProcQueue, NULL, processTransactionQueue, NULL);
 	pthread_create(&tid_Watchdog, NULL, processWatchdog, NULL);
 
@@ -1139,8 +1128,6 @@ int main(void)
 
 	for(;;)
 	{
-		refreshStartTimer(&startTime.startTimeDog);
-		counterLwsRestart = 0;
 		// Connect server
 		if(ConnectionEstablished==0) // Check InternetConn 0: disconnected, 1: connected
 		{
@@ -1215,6 +1202,8 @@ int main(void)
 				{
 					refreshStartTimer(&startTime.reConnect);
 				}
+				
+				refreshStartTimer(&startTime.disconnectServer);
 			}
 		}
 

+ 7 - 18
EVSE/Modularization/ocppfiles/Module_OcppBackend.c

@@ -14,7 +14,7 @@ struct StartTime
 	struct timespec connect;
 	struct timespec bootNotification;
 	struct timespec reConnect;
-	struct timespec startTimeDog;
+	struct timespec disconnectServer;
 	struct timespec startTimeQueue;
 	struct timespec pingOn;
 }startTime;
@@ -37,7 +37,6 @@ unsigned char StartTransactionIdTagTemp[20]={0};
 int LastQueuedTransactionId[8] = {0};
 uint8_t	isWebsocketSendable = 1;
 uint8_t	isQueueSendable = 1;
-uint8_t	counterLwsRestart = 0;
 uint8_t counterQueueSent = 0;
 uint8_t	counterConnect = 0;
 uint8_t counterPingSend = 0;
@@ -1227,21 +1226,10 @@ void* processWatchdog()
 {
 	for(;;)
 	{
-		if((getDiffSecNow(startTime.startTimeDog) > 10) && (context != NULL))
+		if((getDiffSecNow(startTime.disconnectServer) >= 7200))
 		{
-			DEBUG_INFO("LWS watch dog timeout.\n");
-			lws_cancel_service(context);
-			lws_cancel_service_pt(wsi_client);
-
-			if(counterLwsRestart >= 3)
-			{
-				DEBUG_INFO("LWS watch dog timeout over 3 count.\n");
-				system("killall OcppBackend");
-			}
-			else
-				counterLwsRestart++;
-
-			refreshStartTimer(&startTime.startTimeDog);
+			DEBUG_INFO("OCPP server disconnect timer(%d) over 7200 seconds.\n", getDiffSecNow(startTime.disconnectServer));
+			system("killall OcppBackend");
 		}
 
 		if(counterConnect >= 3)
@@ -1395,6 +1383,7 @@ int main(void)
 	memset(rmFileCmd, 0, ARRAY_SIZE(rmFileCmd));
 
 	// Create Process: Resend Transaction
+	refreshStartTimer(&startTime.disconnectServer);
 	pthread_create(&tid_ProcQueue, NULL, processTransactionQueue, NULL);
 	pthread_create(&tid_Watchdog, NULL, processWatchdog, NULL);
 
@@ -1511,8 +1500,6 @@ int main(void)
 
 	for(;;)
 	{
-		refreshStartTimer(&startTime.startTimeDog);
-		counterLwsRestart = 0;
 		// Connect server
 		if(ConnectionEstablished==0) // Check InternetConn 0: disconnected, 1: connected
 		{
@@ -1585,6 +1572,8 @@ int main(void)
 				{
 					refreshStartTimer(&startTime.reConnect);
 				}
+
+				refreshStartTimer(&startTime.disconnectServer);
 			}
 		}
 

+ 8 - 19
EVSE/Modularization/ocppph/Module_OcppBackend.c

@@ -14,7 +14,7 @@ struct StartTime
 	struct timespec connect;
 	struct timespec bootNotification;
 	struct timespec reConnect;
-	struct timespec startTimeDog;
+	struct timespec disconnectServer;
 	struct timespec startTimeQueue;
 	struct timespec pingOn;
 }startTime;
@@ -36,7 +36,6 @@ int OcppPort=0;
 unsigned char StartTransactionIdTagTemp[20]={0};
 uint8_t	isWebsocketSendable = 1;
 uint8_t	isQueueSendable = 1;
-uint8_t	counterLwsRestart = 0;
 uint8_t counterQueueSent = 0;
 uint8_t	counterConnect = 0;
 uint8_t counterPingSend = 0;
@@ -1177,21 +1176,10 @@ void* processWatchdog()
 {
 	for(;;)
 	{
-		if((getDiffSecNow(startTime.startTimeDog) > 10) && (context != NULL))
+		if((getDiffSecNow(startTime.disconnectServer) >= 7200))
 		{
-			DEBUG_INFO("LWS watch dog timeout.\n");
-			lws_cancel_service(context);
-			lws_cancel_service_pt(wsi_client);
-
-			if(counterLwsRestart >= 3)
-			{
-				DEBUG_INFO("LWS watch dog timeout over 3 count.\n");
-				system("killall OcppBackendPH");
-			}
-			else
-				counterLwsRestart++;
-
-			refreshStartTimer(&startTime.startTimeDog);
+			DEBUG_INFO("OCPP server disconnect timer(%d) over 7200 seconds.\n", getDiffSecNow(startTime.disconnectServer));
+			system("killall OcppBackendPH");
 		}
 
 		if(counterConnect >= 3)
@@ -1346,6 +1334,7 @@ int main(void)
 	memset(rmFileCmd, 0, ARRAY_SIZE(rmFileCmd));
 
 	// Create Process: Resend Transaction
+	refreshStartTimer(&startTime.disconnectServer);
 	pthread_create(&tid_ProcQueue, NULL, processTransactionQueue, NULL);
 	pthread_create(&tid_Watchdog, NULL, processWatchdog, NULL);
 
@@ -1429,9 +1418,7 @@ int main(void)
 	removeMessageSentFile();
 
 	for(;;)
-	{
-		refreshStartTimer(&startTime.startTimeDog);
-		counterLwsRestart = 0;
+	{			
 		// Connect server
 		if(ConnectionEstablished==0) // Check InternetConn 0: disconnected, 1: connected
 		{
@@ -1504,6 +1491,8 @@ int main(void)
 				{
 					refreshStartTimer(&startTime.reConnect);
 				}
+				
+				refreshStartTimer(&startTime.disconnectServer);
 			}
 		}
 

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

@@ -125,7 +125,7 @@ echo 3 > /proc/sys/kernel/panic
 #swapon /dev/loop7
 
 echo -e " Starting SSH           	: \n"
-/sbin/dropbear
+/sbin/dropbear -I 300 -T 3
 echo -e " Starting FTPD	  		: \n"
 tcpsvd -vE 0.0.0.0 21 ftpd -w -t 30 / &
 echo -e " Starting LIGHTTPD		: \n"