Browse Source

[Bugfix][Modularization][Module_OcppBackend / Module_OcppBackend20]

2021.04.06 / Folus Wen

Actions:
1. When http upload fail ocpp module can not catch result bug fixed.

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 years ago
parent
commit
4a052a30a7

+ 27 - 12
EVSE/Modularization/ocpp20/MessageHandler.c

@@ -12096,7 +12096,7 @@ void* GetLogProcess(void* data)
 			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(GetLog, "retryInterval") != NULL)
-			retriesInt = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
+			retryIntervalInt = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
 		else
 			retryIntervalInt = 30;
 	}
@@ -12248,7 +12248,8 @@ void* GetLogProcess(void* data)
 				DEBUG_INFO("sendLogStatusNotificationRequest Uploaded\n");
 				sendLogStatusNotificationRequest(UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_Uploaded]);
 			}
-		}while((isSuccess == 0)&&(retriesInt > 0 && retriesInt--));
+			retriesInt--;
+		}while((isSuccess == 0)&&(retriesInt >= 0));
 	}
 	else
 	{
@@ -12297,7 +12298,8 @@ void* GetLogProcess(void* data)
 				DEBUG_INFO("sendLogStatusNotificationRequest Uploaded\n");
 				sendLogStatusNotificationRequest(UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_Uploaded]);
 			}
-		}while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
+		    retriesInt--;
+		}while((!isSuccess)&&(retriesInt >= 0));
 	}
 
 end:
@@ -15902,8 +15904,8 @@ int httpUploadFile(char *location, char *path, char *filename,char *url)
 {
 	char rmFileCmd[100]={0};
     char FilePath[100]={0};
-	char ftpbuf[200];
-	int systemresult;
+	char buf[512];
+	int systemresult = 0;
 
 	//DEBUG_INFO("filename=%s\n",filename);
 	//DEBUG_INFO("url=%s\n",url);
@@ -15917,7 +15919,6 @@ int httpUploadFile(char *location, char *path, char *filename,char *url)
 	}
 
 	FILE *fp = fopen("/mnt/upload_file.txt", "w+");
-
 	if(fp == NULL)
 	{
 		DEBUG_INFO("log is NULL\n");
@@ -15930,14 +15931,28 @@ int httpUploadFile(char *location, char *path, char *filename,char *url)
 		fclose(fp);
 	}
 
-	memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
-	sprintf(ftpbuf, "%s","/bin/php-cgi /var/www/ocpp_upload.php");
-	systemresult = system(ftpbuf);
+	FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
+	if(phpFP == NULL)
+	{
+		DEBUG_INFO("PHP upload fail.\n");
+		return FALSE;
+	}
+	else
+	{
+		while(fgets(buf, sizeof(buf), phpFP) != NULL)
+		{
+			if(strstr(buf, "result") != NULL)
+			{
+				sscanf(buf, "result: %d", &systemresult);
+				DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
+			}
+		}
+		pclose(phpFP);
+	}
 
-	DEBUG_INFO("systemresult = %d\n",systemresult);
-	if(systemresult != 0)
+	if(systemresult != 1)
 	{
-		DEBUG_INFO("http upload error!\n");
+		DEBUG_INFO("HTTP upload error!\n");
 		return FALSE;
 	}
 

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

@@ -8122,7 +8122,7 @@ void* GetDiagnosticsProcess(void* data)
 			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, "retryInterval") != NULL)
-			retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
+			retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
 		else
 			retryIntervalInt = 30;
 
@@ -8279,7 +8279,8 @@ void* GetDiagnosticsProcess(void* data)
 				DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
 				sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
 			}
-		}while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
+			retriesInt--;
+		}while((isSuccess == 0)&&(retriesInt >= 0));
 	}
 	else
 	{
@@ -8328,7 +8329,8 @@ void* GetDiagnosticsProcess(void* data)
 				DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
 				sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
 			}
-		}while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
+		    retriesInt--;
+		}while((!isSuccess)&&(retriesInt >= 0));
 	}
 
 end:
@@ -15030,8 +15032,8 @@ int httpUploadFile(char *location, char *path, char *filename,char *url)
 {
 	char rmFileCmd[100]={0};
     char FilePath[100]={0};
-	char ftpbuf[200];
-	int systemresult;
+	char buf[512];
+	int systemresult = 0;
 
 	//DEBUG_INFO("filename=%s\n",filename);
 	//DEBUG_INFO("url=%s\n",url);
@@ -15045,7 +15047,6 @@ int httpUploadFile(char *location, char *path, char *filename,char *url)
 	}
 
 	FILE *fp = fopen("/mnt/upload_file.txt", "w+");
-
 	if(fp == NULL)
 	{
 		DEBUG_INFO("log is NULL\n");
@@ -15058,14 +15059,28 @@ int httpUploadFile(char *location, char *path, char *filename,char *url)
 		fclose(fp);
 	}
 
-	memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
-	sprintf(ftpbuf, "%s","/bin/php-cgi /var/www/ocpp_upload.php");
-	systemresult = system(ftpbuf);
+	FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
+	if(phpFP == NULL)
+	{
+		DEBUG_INFO("PHP upload fail.\n");
+		return FALSE;
+	}
+	else
+	{
+		while(fgets(buf, sizeof(buf), phpFP) != NULL)
+		{
+			if(strstr(buf, "result") != NULL)
+			{
+				sscanf(buf, "result: %d", &systemresult);
+				DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
+			}
+		}
+		pclose(phpFP);
+	}
 
-	DEBUG_INFO("systemresult = %d\n",systemresult);
-	if(systemresult != 0)
+	if(systemresult != 1)
 	{
-		DEBUG_INFO("http upload error!\n");
+		DEBUG_INFO("HTTP upload error!\n");
 		return FALSE;
 	}
 

+ 5 - 4
EVSE/rootfs/var/www/ocpp_upload.php

@@ -17,6 +17,7 @@ curl_setopt_array($curl, array(
   CURLOPT_ENCODING => "",
   CURLOPT_MAXREDIRS => 10,
   CURLOPT_TIMEOUT => 0,
+  CURLOPT_CONNECTTIMEOUT => 30,
   CURLOPT_STDERR          => $curl_log,
   CURLOPT_FOLLOWLOCATION => 0,
   CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
@@ -30,12 +31,12 @@ curl_setopt_array($curl, array(
 ));
 
 $response = curl_exec($curl);
-$response_text=1;
+$response_text="result: 0";
 if($response) {
-	$response_text=1;
+	$response_text="result: 1";
 }
 else{
-	$response_text=0;
+	$response_text="result: 0";
 }
 $error=curl_error($curl);
 curl_close($curl);
@@ -44,4 +45,4 @@ fwrite($curl_log,$response_text."\n");
 fclose($curl_log);  
 
 echo $response_text;
-?>
+?>