瀏覽代碼

[Bug fix][Modularization][Module_OcppBackend]

2020.08.31 / Folus Wen

Actions:
1. EVSE/Modularization/ocppfiles/MessageHandler.c GetDiagnosticsProcess() parsing logic bug fix.
2. EVSE/Modularization/ocppfiles/MessageHandler.c GetDiagnosticsProcess() implement send diagnostics status when retry occur.
3. EVSE/Modularization/ocppfiles/MessageHandler.c UpdateFirmwareProcess() implement send firmware status when retry occur.
4. EVSE/Modularization/ocppfiles/MessageHandler.c wget command add timeout parameter as 120 seconds.

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 4 年之前
父節點
當前提交
206df45c96
共有 1 個文件被更改,包括 82 次插入163 次删除
  1. 82 163
      EVSE/Modularization/ocppfiles/MessageHandler.c

+ 82 - 163
EVSE/Modularization/ocppfiles/MessageHandler.c

@@ -7556,122 +7556,48 @@ void* GetDiagnosticsProcess(void* data)
 	mtrace();
 	int retriesInt=0, retryIntervalInt=0;
 	char locationstr[100]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
-	int retriesIsNULL,retryIntervalIsNULL, startTimeIsNULL, stopTimeIsNULL;
 	char protocol[10]={0}, user[50]={0},password[50]={0},host[50]={0}, path[50]={0}, ftppath[60]={0},host1[50]={0},path1[50]={0};
 	int port=0;
-	char sstr[260]={ 0 };
-	int c = 0;
-	char *loc;
 	int isSuccess = FALSE;
 	char ftpbuf[200]={0};
-	char * pch;
-
-	char str[300]={ 0 };
-	strcpy(str,(const char*)data);
+	json_object *GetDiagnostics;
 
-	retriesIsNULL = retryIntervalIsNULL = startTimeIsNULL = stopTimeIsNULL = FALSE;
-
-	DEBUG_INFO("GetDiagnosticsProcess...%s\n", str);
+	DEBUG_INFO("GetDiagnosticsProcess...\n");
 	sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
 
-	//****************location*******************/
-	c = 0;
-	memset(sstr ,0, ARRAY_SIZE(sstr));
-	loc = strstr(str, "location");
-	while (loc[3+strlen("location")+c] != '\"')
+	GetDiagnostics = json_tokener_parse(data);
+	if(!is_error(GetDiagnostics))
 	{
-		sstr[c] = loc[3+strlen("location")+c];
-		c++;
-	}
-	sstr[c] = '\0';
-	strcpy(locationstr,sstr);
-	//strcpy(locationstr,"http://test.evsocket.phihong.com.cn:9001/UploadFiles/Diagnostics/");
+		// Required data
+		if(json_object_object_get(GetDiagnostics, "location") != NULL)
+			sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
 
-	if(strcmp(locationstr,"")==0)
-	{
-		DEBUG_INFO("location is <Empty>!\n");
-		sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
-		goto end;
-	}
+		// Optional data
+		if(json_object_object_get(GetDiagnostics, "retries") != NULL)
+			retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
+		else
+			retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
 
-	//****************retries*******************/
-	c = 0;
-	loc = strstr(str, "retries");
-	if(loc == NULL)
-	{
-		retriesIsNULL = TRUE;
-	}
-	else
-	{
-		while ((loc[strlen("retries")+2+c] != ',')&&(loc[strlen("retries")+2+c] != '}'))
-		{
-			sstr[c] = loc[strlen("retries")+2+c];
-			c++;
-		}
-		sstr[c] = '\0';
-		retriesInt = atoi(sstr);
-	}
+		if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
+			retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
+		else
+			retryIntervalInt = 30;
 
-	if(retriesIsNULL == TRUE)
-	{
-		retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
-	}
+		if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
+			sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
 
-	//****************retryInterval*******************/
-	c = 0;
-	loc = strstr(str, "retryInterval");
-	if(loc == NULL)
-	{
-		retryIntervalIsNULL = TRUE;
-		retryIntervalInt = 30; // if this field is not present, it is left to Charge Point to decide how long to wait between attempts.
-	}
-	else
-	{
-		while ((loc[strlen("retryInterval")+2+c] != ',')&&(loc[strlen("retries")+2+c] != '}'))
-		{
-			sstr[c] = loc[strlen("retryInterval")+2+c];
-			c++;
-		}
-		sstr[c] = '\0';
-		retryIntervalInt = atoi(sstr);
+		if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
+			sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
 	}
+	json_object_put(GetDiagnostics);
 
-	//****************startTime*******************/
-	c = 0;
-	memset(sstr ,0, ARRAY_SIZE(sstr));
-	loc = strstr(str, "startTime");
-	if(loc == NULL)
-	{
-		startTimeIsNULL = TRUE;
-	}
-	else
-	{
-		while (loc[3+strlen("startTime")+c] != '\"')
-		{
-			sstr[c] = loc[3+strlen("startTime")+c];
-			c++;
-		}
-		sstr[c] = '\0';
-		strcpy(startTimestr,sstr);
-	}
 
-	//****************stopTime*******************/
-	c = 0;
-	memset(sstr ,0, ARRAY_SIZE(sstr));
-	loc = strstr(str, "stopTime");
-	if(loc == NULL)
-	{
-		stopTimeIsNULL = TRUE;
-	}
-	else
+	//****************location*******************/
+	if(strcmp(locationstr,"")==0)
 	{
-		while (loc[3+strlen("stopTime")+c] != '\"')
-		{
-			sstr[c] = loc[3+strlen("stopTime")+c];
-			c++;
-		}
-		sstr[c] = '\0';
-		strcpy(stopTimestr,sstr);
+		DEBUG_INFO("location is <Empty>!\n");
+		sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
+		goto end;
 	}
 
 	memset(protocol, 0, ARRAY_SIZE(protocol));
@@ -7695,12 +7621,9 @@ void* GetDiagnosticsProcess(void* data)
 		DEBUG_INFO("fnamePlusPath not exist!\n");
 		sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
 		goto end;
-
 	}
 
-	pch=strchr(locationstr,'@');
-
-	if(pch==NULL)
+	if(strchr(locationstr,'@')==NULL)
 	{
 		sscanf(locationstr,
 			         "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
@@ -7720,31 +7643,30 @@ void* GetDiagnosticsProcess(void* data)
 		DEBUG_INFO("protocol is not ftp/http ! \n");
 		sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
 		goto end;
-
 	}
 
 	if(strncmp(locationstr,"http", 4) == 0)
 	{
 		sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
-
 		sprintf(ftppath,"/%s", path);
 
-		do{
-			isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
-			sleep(retryIntervalInt);
-		}while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
-
-		if(!isSuccess)
-		{
-			DEBUG_INFO("Diagnostics fail.\n");
-			sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
-		}
-		else
+		do
 		{
-			DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
-			sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
-		}
+			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
 	{
@@ -7773,21 +7695,22 @@ void* GetDiagnosticsProcess(void* data)
 		if(port == 0)
 		   port = 21;
 
-		do{
+		do
+		{
 		    isSuccess = ftpFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
-		    sleep(retryIntervalInt);
+		    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)&&(retriesInt > 0 && retriesInt --));
-
-		if(!isSuccess)
-		{
-			DEBUG_INFO("Diagnostics fail.\n");
-			sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
-		}
-		else
-		{
-			DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
-			sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
-		}
 	}
 
 end:
@@ -10698,20 +10621,18 @@ void *UpdateFirmwareProcess(void *data)
 
 		do
 		{
-			 isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
-		   	 sleep(retryIntervalInt);
+			isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
+			if(!isSuccess)
+			{
+				sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
+				sleep(retryIntervalInt);
+				sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
+			}
+			else
+			{
+				sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
+			}
 		}while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
-
-
-		if(!isSuccess)
-		{
-		   	sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
-		}
-		else
-		{
-			sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
-		}
-
 	}
     else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
 	{
@@ -10732,7 +10653,6 @@ void *UpdateFirmwareProcess(void *data)
     		}
 
     		i=i+1;
-
     	}
 
     	memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
@@ -10774,21 +10694,20 @@ void *UpdateFirmwareProcess(void *data)
 
 		do
 		{
-			 isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
-			 sleep(retryIntervalInt);
+			isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
+			if(!isSuccess)
+			{
+				//BulldogUtil.sleepMs(interval*1000);
+				DEBUG_INFO("Update firmware request and download file fail.\n");
+				sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
+				sleep(retryIntervalInt);
+				sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
+			}
+			else
+			{
+				sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
+			}
 		}while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
-
-
-		if(!isSuccess)
-		{
-	        //BulldogUtil.sleepMs(interval*1000);
-			DEBUG_INFO("Update firmware request and download file fail.\n");
-			sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
-		}
-		else
-		{
-			sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
-		}
 	}
     else
     {
@@ -14498,7 +14417,7 @@ int httpDownLoadFile(char *location, char *path, char *filename,char *url)
 		system(rmFileCmd);
 	}
 	memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
-	sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s",filename, url);
+	sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
 			//sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
 	systemresult = system(ftpbuf);
 
@@ -14530,7 +14449,7 @@ int ftpDownLoadFile(char *location, char *user, char *password, int port, char *
 
 	memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
 
-	sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s",filename, url);
+	sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
 	//sprintf(ftpbuf, "ftpget -u %s -p %s %s -P %d %s %s%s",user,password,IPbuffer,port/*21*/,filename,path,filename); --- remove temporally
 	//DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
 		//sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);