Parcourir la source

[Improve][Modularization][Module_OcppBackend]

2020.09.01 / Folus Wen

Actions:
1. EVSE/Modularization/ocppfiles/MessageHandler.h add LWS_SendNow(char * str) declare.
2. EVSE/Modularization/ocppfiles/MessageHandler.c handleClearChargingProfileRequest() implement clear all profile without get parameter.
3. EVSE/Modularization/ocppfiles/MessageHandler.c UpdateFirmwareProcess() delete all file in /mnt before start download new image.
4. EVSE/Modularization/ocppfiles/MessageHandler.c FirmwareStatusNotification and DiagnosticsStatusNotification message send out logic improve.

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 il y a 4 ans
Parent
commit
02bd0ff315

+ 51 - 19
EVSE/Modularization/ocppfiles/MessageHandler.c

@@ -3024,7 +3024,7 @@ int sendDiagnosticsStatusNotificationRequest(char *status)
 	random_uuid(guid);
 
 	sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
-	LWS_Send(message);
+	LWS_SendNow(message);
 
 	sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
 
@@ -3079,7 +3079,7 @@ int sendFirmwareStatusNotificationRequest(char *status)
 	random_uuid(guid);
 
 	sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
-	LWS_Send(message);
+	LWS_SendNow(message);
 
 	sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
 
@@ -6647,7 +6647,7 @@ int handleClearChargingProfileRequest(char *uuid, char *payload)
     char sLineWord[1600]={0};
     char chargingProfiles[10][100]={0};
     int ChargeProfileCount = 0;
-    char ch;
+    int ch;
     connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
     DEBUG_INFO("handleClearChargingProfileRequest...\n");
     json_object *ClearChargingProfile;
@@ -6938,6 +6938,10 @@ int handleClearChargingProfileRequest(char *uuid, char *payload)
 					//------- not write to  fptr2-------//
 					sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
 				}
+				else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
+				{
+					sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
+				}
 				else
 				{
 					fprintf(fptr2, sLineWord);//writing data into file
@@ -6973,17 +6977,16 @@ int handleClearChargingProfileRequest(char *uuid, char *payload)
 
 			   if(resultRename == 0)
 			   {
-			       DEBUG_INFO("File ChargingProfile renamed successfully");
+			       DEBUG_INFO("File ChargingProfile renamed successfully\n");
 			   }
 			   else
 			   {
-			       DEBUG_INFO("Error: unable to rename the ChargingProfile file");
+			       DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
 			   }
 
 			   if(comfirmstr[0]== 0)
 			   {
 			       sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
-
 			   }
 
 			    //Check chargingProfile is empty file
@@ -6997,7 +7000,6 @@ int handleClearChargingProfileRequest(char *uuid, char *payload)
 			        while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
 			        {
 			        	str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
-
 			        	if(sLineWord[0]=='\0')
 			        	{
 			        		isEmptyFile = TRUE;
@@ -7010,6 +7012,9 @@ int handleClearChargingProfileRequest(char *uuid, char *payload)
 			        	}
 			        }
 			    }
+			    else
+			    	isEmptyFile = TRUE;
+
 			    fclose(fptr1);
 
 			    if(isEmptyFile == TRUE)
@@ -7019,7 +7024,6 @@ int handleClearChargingProfileRequest(char *uuid, char *payload)
 			        system(str);
 			    }
 			}
-
 	  }// End of while(int k=0; k < ChargePointCount; k++)
 	}
 	else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
@@ -7178,6 +7182,9 @@ int handleClearChargingProfileRequest(char *uuid, char *payload)
 					   }
 				   }
 			   }
+			   else
+				   isEmptyFile = TRUE;
+
 			   fclose(fptr1);
 
 			   if(isEmptyFile == TRUE)
@@ -7188,9 +7195,7 @@ int handleClearChargingProfileRequest(char *uuid, char *payload)
 			   }
 			   /*------- End of reading ---------------*/
 		   }
-
 	  } //  while(int k=0; k < ChargeProfileCount; k++)
-
 	}// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
 
 end:
@@ -7563,7 +7568,6 @@ void* GetDiagnosticsProcess(void* data)
 	json_object *GetDiagnostics;
 
 	DEBUG_INFO("GetDiagnosticsProcess...\n");
-	sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
 
 	GetDiagnostics = json_tokener_parse(data);
 	if(!is_error(GetDiagnostics))
@@ -7652,20 +7656,22 @@ void* GetDiagnosticsProcess(void* data)
 
 		do
 		{
+			sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
+			sleep(3);
+
 			isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
 			if(!isSuccess)
 			{
 				DEBUG_INFO("Diagnostics fail.\n");
 				sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
 				sleep(retryIntervalInt);
-				sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
+
 			}
 			else
 			{
 				DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
 				sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
 			}
-
 		}while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
 	}
 	else
@@ -7697,13 +7703,15 @@ void* GetDiagnosticsProcess(void* data)
 
 		do
 		{
+			sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
+			sleep(3);
+
 		    isSuccess = ftpFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
 		    if(!isSuccess)
 			{
 				DEBUG_INFO("Diagnostics fail.\n");
 				sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
 				sleep(retryIntervalInt);
-				sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
 			}
 			else
 			{
@@ -10585,9 +10593,7 @@ void *UpdateFirmwareProcess(void *data)
 	memset(ftppath, 0, ARRAY_SIZE(ftppath));
 	memset(path, 0, ARRAY_SIZE(path));
 
-	sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
-	//ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
-
+	system("rm -f /mnt/*");
 	if(strncmp(locationstr,"http", 4) == 0)
 	{
 		sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
@@ -10621,12 +10627,14 @@ void *UpdateFirmwareProcess(void *data)
 
 		do
 		{
+			sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
+			sleep(3);
+
 			isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
 			if(!isSuccess)
 			{
 				sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
 				sleep(retryIntervalInt);
-				sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
 			}
 			else
 			{
@@ -10694,6 +10702,9 @@ void *UpdateFirmwareProcess(void *data)
 
 		do
 		{
+			sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
+			sleep(3);
+
 			isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
 			if(!isSuccess)
 			{
@@ -10701,7 +10712,6 @@ void *UpdateFirmwareProcess(void *data)
 				DEBUG_INFO("Update firmware request and download file fail.\n");
 				sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
 				sleep(retryIntervalInt);
-				sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
 			}
 			else
 			{
@@ -16210,3 +16220,25 @@ void LWS_Send(char * str)
 	//lws_service(context, 0);
 	//sleep(1);
 }
+
+void LWS_SendNow(char * str)
+{
+	//=====================================================
+	// Check InternetConn 0: disconnected, 1: connected
+	//====================================================
+	if(ShmSysConfigAndInfo->SysInfo.InternetConn == 0)
+	{
+		DEBUG_INFO("offline  now !!!\n");
+		return;
+	}
+
+	pthread_mutex_lock(&lock_send);
+	memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
+	sprintf((char *)SendBuffer, "%s", str);
+	SendBufLen = strlen(str);
+	pthread_mutex_unlock(&lock_send);
+
+	lws_callback_on_writable(wsi_client);
+	lws_service(context, 0);
+	//sleep(1);
+}

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

@@ -532,6 +532,7 @@ int httpUploadFile(char *location, char *path, char *filename,char *url);
 int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename);
 int get_file_contents(const char* filename, char** outbuffer);
 void LWS_Send(char * str);
+void LWS_SendNow(char * str);
 extern int queue_operation(int type, char *frontUUID, char *frontData);
 int GetOcppServerURL();
 int GetOcppPath();