Эх сурвалжийг харах

[Improve][Modularization][Module_OcppBackend / Module_OcppBackend20]

2021.04.21 / Folus Wen

Actions:
1. Firmware update only enable req when firmware status is Downloaded.
2. Report Idle firmware status after report firmware DownloadFailed.

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 жил өмнө
parent
commit
08964ddce4

+ 18 - 21
EVSE/Modularization/ocpp20/MessageHandler.c

@@ -15424,9 +15424,9 @@ void *UpdateFirmwareProcess(void *data)
 	int retriesInt =0, retryIntervalInt=0;
 	char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
 	int port=0;
-	char locationstr[160]={0}, retrieveDatestr[30]={0};
+	char locationstr[512]={0}, retrieveDatestr[36]={0};
 	int isSuccess = 0;
-	char ftpbuf[200];
+	char ftpbuf[512];
 	char temp[100];
 	char * pch;
 
@@ -15465,8 +15465,6 @@ void *UpdateFirmwareProcess(void *data)
 	{
 		sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
 
-	    //sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^/]%199[^\n]",
-		    	    	//	         protocol, user, password, host, path);
 		sprintf(ftppath,"/%s", path);
 		DEBUG_INFO("locationstr: %s\n", locationstr);
 		DEBUG_INFO("protocol: %s\n",protocol);
@@ -15503,21 +15501,24 @@ void *UpdateFirmwareProcess(void *data)
 			{
 				sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_DownloadFailed]);
 				ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
-				sleep(retryIntervalInt);
+				if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
+				sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s",FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Idle]);
+				ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
 			}
 			else
 			{
 				sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Downloaded]);
 				ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
 			}
-		}while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
+			retriesInt--;
+		}while((isSuccess == 0)&&(retriesInt >= 0));
 	}
     else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
 	{
     	memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
     	memset(temp, 0, ARRAY_SIZE(temp));
-    	//DEBUG_INFO("locationstr=%s\n",locationstr);
-    	strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
+
+    	strcpy(ftpbuf, locationstr);
     	int ftppathlen=strlen(ftpbuf);
     	int i=1;
     	char filenametemp[50];
@@ -15555,16 +15556,6 @@ void *UpdateFirmwareProcess(void *data)
     	sscanf(host,"%[^/]%s",host1, path1);
     	sprintf(ftppath,"%s", path1);
 
-    	//DEBUG_INFO("protocol =%s\n",protocol);
-    	//DEBUG_INFO("user =%s\n",user);
-    	//DEBUG_INFO("password =%s\n",password);
-    	//DEBUG_INFO("host1 =%s\n",host1);
-    	//DEBUG_INFO("port =%d\n",port);
-    	//DEBUG_INFO("path1 =%s\n",path1);
-    	//DEBUG_INFO("ftppath=%s\n",ftppath);
-
-		//ftpFile(host, user, password, port, ftppath, fname);
-		//download firmware pthred
     	if(port == 0)
     	{
     		port = 21;
@@ -15583,7 +15574,9 @@ void *UpdateFirmwareProcess(void *data)
 				DEBUG_INFO("Update firmware request and download file fail.\n");
 				sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_DownloadFailed]);
 				ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
-				sleep(retryIntervalInt);
+				if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
+				sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s",FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Idle]);
+				ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
 			}
 			else
 			{
@@ -15591,15 +15584,19 @@ void *UpdateFirmwareProcess(void *data)
 				ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
 
 			}
-		}while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
+			retriesInt--;
+		}while((!isSuccess)&&(retriesInt >= 0));
 	}
     else
     {
 		sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_DownloadFailed]);
 		ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
+		sleep(1);
+		sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s",FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Idle]);
+		ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
     }
 
-	ShmOCPP20Data->MsMsg.bits.UpdateFirmwareReq = ON;
+	if(strstr((char*)ShmOCPP20Data->FirmwareStatusNotification.status, FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Downloaded]) != NULL)ShmOCPP20Data->MsMsg.bits.UpdateFirmwareReq = ON;
 	pthread_exit(NULL);
 
 }

+ 18 - 12
EVSE/Modularization/ocppfiles/MessageHandler.c

@@ -11750,9 +11750,9 @@ void *UpdateFirmwareProcess(void *data)
 	int retriesInt =0, retryIntervalInt=0;
 	char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
 	int port=0;
-	char locationstr[160]={0}, retrieveDatestr[30]={0};
+	char locationstr[512]={0}, retrieveDatestr[36]={0};
 	int isSuccess = 0;
-	char ftpbuf[200];
+	char ftpbuf[512];
 	char temp[100];
 	char * pch;
 
@@ -11791,8 +11791,6 @@ void *UpdateFirmwareProcess(void *data)
 	{
 		sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
 
-	    //sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^/]%199[^\n]",
-		    	    	//	         protocol, user, password, host, path);
 		sprintf(ftppath,"/%s", path);
 		DEBUG_INFO("locationstr: %s\n", locationstr);
 		DEBUG_INFO("protocol: %s\n",protocol);
@@ -11822,21 +11820,24 @@ void *UpdateFirmwareProcess(void *data)
 		{
 			sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
 			ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
-			sleep(3);
+			sleep(1);
 
 			isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
 			if(!isSuccess)
 			{
 				sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
 				ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
-				sleep(retryIntervalInt);
+				if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
+				sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
+				ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
 			}
 			else
 			{
 				sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
 				ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
 			}
-		}while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
+			retriesInt--;
+		}while((isSuccess == 0)&&(retriesInt >= 0));
 	}
     else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
 	{
@@ -11900,7 +11901,7 @@ void *UpdateFirmwareProcess(void *data)
 		{
 			sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
 			ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
-			sleep(3);
+			sleep(1);
 
 			isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
 			if(!isSuccess)
@@ -11909,24 +11910,29 @@ void *UpdateFirmwareProcess(void *data)
 				DEBUG_INFO("Update firmware request and download file fail.\n");
 				sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
 				ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
-				sleep(retryIntervalInt);
+				if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
+				sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
+				ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
 			}
 			else
 			{
 				sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
 				ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
 			}
-		}while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
+			retriesInt--;
+		}while((!isSuccess)&&(retriesInt >= 0));
 	}
     else
     {
 		sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
 		ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
+		sleep(1);
+		sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
+		ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
     }
 
-	ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
+	if(strstr((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, FirmwareStatusStr[FirmwareStatus_Downloaded]) != NULL)ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
 	pthread_exit(NULL);
-
 }
 
 int handleCertificateSignedRequest(char *uuid, char *payload)