Browse Source

[Improve][Modularization][Module_OcppBackend / Module_OcppBackend]

2021.03.26 / Folus Wen

Actions:
1. Get log period follow request parameter.

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
db93c03a07

+ 1 - 0
EVSE/Modularization/logPackTools.c

@@ -319,6 +319,7 @@ int main(int argc, char *argv[]) {
 		}
 		sprintf(cmd,"%s \t /Storage/ChargeLog/*.db",cmd);
 		sprintf(cmd,"%s \t /Storage/OCPP/*.db",cmd);
+		sprintf(cmd,"%s \t /Storage/EventLog/*.db",cmd);
 		if(isCCS==0){
 			sprintf(cmd,"%s \t /Storage/CCS*.zip",cmd);
 		}

+ 51 - 8
EVSE/Modularization/ocpp20/MessageHandler.c

@@ -12054,6 +12054,15 @@ void* GetLogProcess(void* data)
 	int port=0;
 	int isSuccess = FALSE;
 	char ftpbuf[200]={0};
+	char cmdBuf[2048];
+	struct tm *tmNow;
+	time_t CurrentTime;
+	struct tm tmStart;
+	struct tm tmStop;
+	CurrentTime = time(NULL);
+	tmNow=localtime(&CurrentTime);
+	uint16_t targetYear, targetMonth;
+
 	json_object *GetLog;
 
 	DEBUG_INFO("GetGetProcess...\n");
@@ -12093,9 +12102,49 @@ void* GetLogProcess(void* data)
 	}
 	json_object_put(GetLog);
 
-
 	ShmOCPP20Data->GetLog.requestId = requestId;
 
+	// Pack log to compress file
+	if((sscanf((char*)oldestTimestamp, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStart.tm_year, &tmStart.tm_mon, &tmStart.tm_mday, &tmStart.tm_hour, &tmStart.tm_min, &tmStart.tm_sec) == 6) &&
+	   (sscanf((char*)latestTimestamp, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStop.tm_year, &tmStop.tm_mon, &tmStop.tm_mday, &tmStop.tm_hour, &tmStop.tm_min, &tmStop.tm_sec) == 6))
+	{
+		sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/log.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
+		targetYear = tmStart.tm_year;
+		targetMonth = tmStart.tm_mon;
+
+		do
+		{
+			sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
+			sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
+			sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
+
+			if(targetMonth+1>=13)
+			{
+				targetYear += 1;
+				targetMonth = 1;
+			}
+			else
+			{
+				targetMonth += 1;
+			}
+		}while((targetYear < (tmNow->tm_year+1900)) ||
+			   ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
+
+		sprintf(cmdBuf, "%s \t /Storage/ChargeLog/*.db", cmdBuf);
+		sprintf(cmdBuf, "%s \t /Storage/OCPP/*.db", cmdBuf);
+		sprintf(cmdBuf, "%s \t /Storage/EventLog/*.db", cmdBuf);
+		sprintf(cmdBuf, "%s \t /Storage/CCS*.zip", cmdBuf);
+
+		system(cmdBuf);
+	}
+	else
+	{
+		system("exec /root/logPackTools 'log' 6");
+	}
+
+	sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP20Data->GetLog.Response_filename);
+	system(cmdBuf);
+	checkUploadLog();
 	//****************location*******************/
 	if(strcmp(remoteLocation,"")==0)
 	{
@@ -12230,7 +12279,6 @@ int handleGetLogRequest(char *uuid, char *payload)
 {
 	mtrace();
 	int result = FAIL;
-	char cmdBuf[512];
 	char fName[258];
 	time_t CurrentTime;
 	struct tm *tm;
@@ -12239,15 +12287,10 @@ int handleGetLogRequest(char *uuid, char *payload)
 	CurrentTime = time(NULL);
 	tm = localtime(&CurrentTime);
 	sprintf(fName ,"%s-%s-%04d%02d%02d%02d%02d%02d.zip", ShmSysConfigAndInfo->SysConfig.ModelName, ShmSysConfigAndInfo->SysConfig.SerialNumber, (tm->tm_year+1900), (tm->tm_mon+1),tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec);
-
 	sprintf((char*)ShmOCPP20Data->GetLog.Response_filename, "%s", fName);
 	sprintf((char*)ShmOCPP20Data->GetLog.Response_status, "%s", LogStatusEnumTypeStr[LogStatusEnumType_Accepted]);
-
 	sendGetLogConfirmation(uuid);
-	system("exec /root/logPackTools 'log' 6");
-	sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", fName);
-	system(cmdBuf);
-	checkUploadLog();
+
 	pthread_create(&th_Status, NULL, GetLogProcess, stringtrimspace(payload));
 
 	return result;

+ 47 - 2
EVSE/Modularization/ocppfiles/MessageHandler.c

@@ -8031,7 +8031,15 @@ void* GetDiagnosticsProcess(void* data)
 	int port=0;
 	int isSuccess = FALSE;
 	char ftpbuf[200]={0};
-	char cmdBuf[512];
+	char cmdBuf[2048];
+	struct tm *tmNow;
+	time_t CurrentTime;
+	struct tm tmStart;
+	struct tm tmStop;
+	CurrentTime = time(NULL);
+	tmNow=localtime(&CurrentTime);
+	uint16_t targetYear, targetMonth;
+
 	json_object *GetDiagnostics;
 
 	DEBUG_INFO("GetDiagnosticsProcess...\n");
@@ -8063,7 +8071,43 @@ void* GetDiagnosticsProcess(void* data)
 	json_object_put(GetDiagnostics);
 
 	// Pack log to compress file
-	system("exec /root/logPackTools 'log' 6");
+	if((sscanf((char*)startTimestr, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStart.tm_year, &tmStart.tm_mon, &tmStart.tm_mday, &tmStart.tm_hour, &tmStart.tm_min, &tmStart.tm_sec) == 6) &&
+	   (sscanf((char*)stopTimestr, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStop.tm_year, &tmStop.tm_mon, &tmStop.tm_mday, &tmStop.tm_hour, &tmStop.tm_min, &tmStop.tm_sec) == 6))
+	{
+		sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/log.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
+		targetYear = tmStart.tm_year;
+		targetMonth = tmStart.tm_mon;
+
+		do
+		{
+			sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
+			sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
+			sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
+
+			if(targetMonth+1>=13)
+			{
+				targetYear += 1;
+				targetMonth = 1;
+			}
+			else
+			{
+				targetMonth += 1;
+			}
+		}while((targetYear < (tmNow->tm_year+1900)) ||
+			   ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
+
+		sprintf(cmdBuf, "%s \t /Storage/ChargeLog/*.db", cmdBuf);
+		sprintf(cmdBuf, "%s \t /Storage/OCPP/*.db", cmdBuf);
+		sprintf(cmdBuf, "%s \t /Storage/EventLog/*.db", cmdBuf);
+		sprintf(cmdBuf, "%s \t /Storage/CCS*.zip", cmdBuf);
+
+		system(cmdBuf);
+	}
+	else
+	{
+		system("exec /root/logPackTools 'log' 6");
+	}
+
 	sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16Data->GetDiagnostics.ResponseFileName);
 	system(cmdBuf);
 	checkUploadLog();
@@ -8195,6 +8239,7 @@ void* GetDiagnosticsProcess(void* data)
 
 end:
 	DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
+	system("rm -f /mnt/*");
 	pthread_exit(NULL);
 }