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

2022-12-19/Jerry Wang
[OCPP 1.6PH] confVersion 18->19
Action:
Synchronize partial code with OCPP 1.6.(since 2022-11-24 to now)
1. Improve the ConfigurationKey related functions with json-c method.
2. Fix the problem that charger cannot send out queues if HeartbeatInterval is 0.
3. Add logic of packaging Dispenser log file in GetDiagnostics function.
4. Increase buffer length and do some improvements for UpdateFirmware related functions.
5. Add logic of authorizing the certificate of download link with protocol 'https' or 'ftps' for UpdateFirmware function.
6. Add new Configuration Key 'AuthDownloadlinkCertificate'.
7. Fix UpdateFirmwareProcess() while loop stocked problem caused by isOverNow() function.

File:
1. EVSE/Modularization/ocppph/MessageHandler.c
--> Action 1-7
2. EVSE/Modularization/ocppfiles/MessageHandler.h
--> Action 6

Jerry Wang 2 жил өмнө
parent
commit
89ec3c1178

+ 189 - 129
EVSE/Modularization/ocppph/MessageHandler.c

@@ -1316,6 +1316,8 @@ int isOvertNow(uint8_t *start)
 	struct tm tmStart;
 	struct tm tmStart;
 	struct timeb tbStart;
 	struct timeb tbStart;
 
 
+	memset(&parsingResult, 0x00, sizeof(struct ParsingResult));
+
 	if(strstr((char*)start, ".") != NULL)
 	if(strstr((char*)start, ".") != NULL)
 	{
 	{
 		// Original data with mini second
 		// Original data with mini second
@@ -8598,73 +8600,61 @@ int sendGetConfigurationConfirmation(char *uuid)
 
 
 	MaxKeySupported = atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
 	MaxKeySupported = atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
 
 
-	//DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
-
-	sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
-			,MESSAGE_TYPE_CALLRESULT
-			,uuid );
-
-	 //configuration key
+	//configuration key
+	json_object *GetConfiguration = json_object_new_object();
+	json_object *configurationKey = json_object_new_array();
 	for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
 	for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
 	{
 	{
 		if(strcmp((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
 		if(strcmp((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
 		{
 		{
-			if (sentConfigurationNumber == 0)
-			{
-				sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
-						, ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
-						, atoi((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
-						, ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
-			}
-			else
-			{
-				sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
-						, ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
-						, atoi((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
-						, ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
-			}
+			json_object *keyValue = json_object_new_object();
+			json_object_object_add(keyValue, "key", json_object_new_string((char*)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key));
+			json_object_object_add(keyValue, "readonly", atoi((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1?json_object_new_boolean(1):json_object_new_boolean(0));
+			json_object_object_add(keyValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Value));
+
+			json_object_array_add(configurationKey, keyValue);
 
 
 			sentConfigurationNumber = sentConfigurationNumber + 1;
 			sentConfigurationNumber = sentConfigurationNumber + 1;
 		}
 		}
-
 	}
 	}
 
 
-
-	sprintf(message + strlen(message), "]");
-
-
+	json_object *unknownKey = json_object_new_array();
 	if(UnknownKeynum != 0)
 	if(UnknownKeynum != 0)
 	{
 	{
-		sprintf(message + strlen(message), ",\"unknownKey\":[");
-		//unkown key
 		for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
 		for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
 		{
 		{
-			// json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
-
-			DEBUG_INFO("unkown key:%s\n", ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
+			DEBUG_INFO("unknown key:%s\n", ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
+			json_object_array_add(unknownKey, json_object_new_string((char*)ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item));
 
 
-			if(sentunConfigurationNumber == 0)
-			{
-				sprintf(message + strlen(message), "\"%s\""
-						, ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
-			}
-			else
-			{
-				sprintf(message + strlen(message), ",\"%s\""
-						, ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
-			}
 			sentunConfigurationNumber = sentunConfigurationNumber + 1;
 			sentunConfigurationNumber = sentunConfigurationNumber + 1;
-
 		}
 		}
+	}
 
 
-		sprintf(message + strlen(message), "]");
+	if((sentConfigurationNumber>0) && (sentunConfigurationNumber>0))
+	{
+		json_object_object_add(GetConfiguration, "configurationKey", configurationKey);
+		json_object_object_add(GetConfiguration, "unknownKey", unknownKey);
 
 
 	}
 	}
+	else if(sentConfigurationNumber>0)
+	{
+		json_object_object_add(GetConfiguration, "configurationKey", configurationKey);
+		json_object_put(unknownKey);
+	}
+	else
+	{
+		json_object_object_add(GetConfiguration, "unknownKey", unknownKey);
+		json_object_put(configurationKey);
+	}
 
 
-	sprintf(message + strlen(message), "}]");
+	sprintf(message,"[%d,\"%s\",%s]"
+					,MESSAGE_TYPE_CALLRESULT
+					,uuid
+					,json_object_to_json_string_ext(GetConfiguration, JSON_C_TO_STRING_PLAIN));
 
 
-	LWS_Send(message);
+	json_object_put(GetConfiguration);
 
 
+	LWS_Send(message);
 	return result;
 	return result;
 }
 }
 
 
@@ -11560,6 +11550,7 @@ void* GetDiagnosticsProcess(void* data)
 		sprintf(cmdBuf, "%s /Storage/OCPP/TransactionRelatedQueue", cmdBuf);
 		sprintf(cmdBuf, "%s /Storage/OCPP/TransactionRelatedQueue", cmdBuf);
 		sprintf(cmdBuf, "%s /Storage/OCPP/QueueTransactionId", cmdBuf);
 		sprintf(cmdBuf, "%s /Storage/OCPP/QueueTransactionId", cmdBuf);
 		sprintf(cmdBuf, "%s /Storage/OCPP/OCPPConfiguration", cmdBuf);
 		sprintf(cmdBuf, "%s /Storage/OCPP/OCPPConfiguration", cmdBuf);
+		sprintf(cmdBuf, "%s /Storage/SystemLog/*Dispenser*Log.zip", cmdBuf);
 		system(cmdBuf);
 		system(cmdBuf);
 
 
 		// Pack charging & event log
 		// Pack charging & event log
@@ -11742,6 +11733,7 @@ void* GetDiagnosticsProcess(void* data)
 
 
 end:
 end:
 	system("rm -f /mnt/*");
 	system("rm -f /mnt/*");
+	system("rm -f /Storage/SystemLog/*Dispenser*Log.zip");
 	sleep(5);
 	sleep(5);
 	sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
 	sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
 	ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
 	ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
@@ -14375,21 +14367,19 @@ end:
 	return result;
 	return result;
 }
 }
 
 
-static char UpdateFirmwarepayloadData[300]={0};
 int handleUpdateFirmwareRequest(char *uuid, char *payload)
 int handleUpdateFirmwareRequest(char *uuid, char *payload)
 {
 {
 	mtrace();
 	mtrace();
 	int result = FAIL;
 	int result = FAIL;
 	pthread_t t;
 	pthread_t t;
 
 
+	DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
 	sendUpdateFirmwareConfirmation(uuid);
 	sendUpdateFirmwareConfirmation(uuid);
-	memset(UpdateFirmwarepayloadData, 0, 300);
-	strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
 
 
 	if(!interLock.isUpdateFirmwareGoing)
 	if(!interLock.isUpdateFirmwareGoing)
 	{
 	{
 		interLock.isUpdateFirmwareGoing = 1;
 		interLock.isUpdateFirmwareGoing = 1;
-		pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
+		pthread_create(&t, NULL, UpdateFirmwareProcess, payload);
 		sleep(1);
 		sleep(1);
 	}
 	}
 	else
 	else
@@ -14404,18 +14394,17 @@ void *UpdateFirmwareProcess(void *data)
 	pthread_detach(pthread_self());
 	pthread_detach(pthread_self());
 	mtrace();
 	mtrace();
 	int retriesInt =0, retryIntervalInt=0;
 	int retriesInt =0, retryIntervalInt=0;
-	char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
+	char protocol[10], user[64],password[64],host[256], path[1024], ftppath[1024],host1[256],path1[1024];
 	int port=0;
 	int port=0;
-	char locationstr[512]={0}, retrieveDatestr[36]={0};
+	char locationstr[2048]={0}, retrieveDatestr[36]={0};
 	int isSuccess = 0;
 	int isSuccess = 0;
-	char ftpbuf[512];
-	char temp[100];
+	char ftpbuf[2048];
+	char temp[2048];
+	char filenametemp[256];
 	char * pch;
 	char * pch;
 
 
-	DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
-
 	json_object *UpdateFirmware;
 	json_object *UpdateFirmware;
-	UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
+	UpdateFirmware = json_tokener_parse(data);
 	if(!is_error(UpdateFirmware))
 	if(!is_error(UpdateFirmware))
 	{
 	{
 		// Required data
 		// Required data
@@ -14465,7 +14454,7 @@ void *UpdateFirmwareProcess(void *data)
 
 
 		int ftppathlen=strlen(ftppath);
 		int ftppathlen=strlen(ftppath);
 		int i=1;
 		int i=1;
-		char filenametemp[50];
+
 		while(i < ftppathlen)
 		while(i < ftppathlen)
 		{
 		{
 		   int len=ftppathlen-i;
 		   int len=ftppathlen-i;
@@ -14483,6 +14472,7 @@ void *UpdateFirmwareProcess(void *data)
 
 
 		do
 		do
 		{
 		{
+			sleep(1);
 			sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
 			sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
 			ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
 			ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
 			sleep(1);
 			sleep(1);
@@ -14490,15 +14480,17 @@ void *UpdateFirmwareProcess(void *data)
 			isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
 			isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
 			if(!isSuccess)
 			if(!isSuccess)
 			{
 			{
+				sleep(1);
 				sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
 				sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
 				ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
 				ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
-				if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
+				if(retriesInt>0)sleep(retryIntervalInt);else sleep(3);
 				sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
 				sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
 				ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
 				ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
 			}
 			}
 			else
 			else
 			{
 			{
 				sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
 				sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
+				sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
 				ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
 				ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
 			}
 			}
 			retriesInt--;
 			retriesInt--;
@@ -14512,7 +14504,7 @@ void *UpdateFirmwareProcess(void *data)
 		strcpy(ftpbuf, locationstr);
 		strcpy(ftpbuf, locationstr);
 		int ftppathlen=strlen(ftpbuf);
 		int ftppathlen=strlen(ftpbuf);
 		int i=1;
 		int i=1;
-		char filenametemp[50];
+
 		while(i < ftppathlen)
 		while(i < ftppathlen)
 		{
 		{
 			int len=ftppathlen-i;
 			int len=ftppathlen-i;
@@ -14554,6 +14546,7 @@ void *UpdateFirmwareProcess(void *data)
 
 
 		do
 		do
 		{
 		{
+			sleep(1);
 			sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
 			sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
 			ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
 			ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
 			sleep(1);
 			sleep(1);
@@ -14565,19 +14558,20 @@ void *UpdateFirmwareProcess(void *data)
 				DEBUG_INFO("Update firmware request and download file fail.\n");
 				DEBUG_INFO("Update firmware request and download file fail.\n");
 				sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
 				sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
 				ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
 				ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
-				if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
+				if(retriesInt>0)sleep(retryIntervalInt);else sleep(3);
 				sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
 				sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
 				ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
 				ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
 			}
 			}
 			else
 			else
 			{
 			{
 				sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
 				sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
+				sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
 				ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
 				ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
 			}
 			}
 			retriesInt--;
 			retriesInt--;
 		}while((!isSuccess)&&(retriesInt >= 0));
 		}while((!isSuccess)&&(retriesInt >= 0));
 	}
 	}
-    else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
+	else if((strncmp(locationstr,"ftp", 3) == 0) || (strncmp(locationstr,"ftps", 4) == 0)) // ftp/ftps
 	{
 	{
     	memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
     	memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
     	memset(temp, 0, ARRAY_SIZE(temp));
     	memset(temp, 0, ARRAY_SIZE(temp));
@@ -14585,7 +14579,7 @@ void *UpdateFirmwareProcess(void *data)
     	strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
     	strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
     	int ftppathlen=strlen(ftpbuf);
     	int ftppathlen=strlen(ftpbuf);
     	int i=1;
     	int i=1;
-    	char filenametemp[50];
+
     	while(i < ftppathlen)
     	while(i < ftppathlen)
     	{
     	{
     		int len=ftppathlen-i;
     		int len=ftppathlen-i;
@@ -14637,6 +14631,7 @@ void *UpdateFirmwareProcess(void *data)
 
 
 		do
 		do
 		{
 		{
+			sleep(1);
 			sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
 			sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
 			ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
 			ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
 			sleep(1);
 			sleep(1);
@@ -14648,13 +14643,14 @@ void *UpdateFirmwareProcess(void *data)
 				DEBUG_INFO("Update firmware request and download file fail.\n");
 				DEBUG_INFO("Update firmware request and download file fail.\n");
 				sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
 				sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
 				ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
 				ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
-				if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
+				if(retriesInt>0)sleep(retryIntervalInt);else sleep(3);
 				sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
 				sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
 				ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
 				ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
 			}
 			}
 			else
 			else
 			{
 			{
 				sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
 				sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
+				sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
 				ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
 				ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
 			}
 			}
 			retriesInt--;
 			retriesInt--;
@@ -14670,7 +14666,11 @@ void *UpdateFirmwareProcess(void *data)
     }
     }
 
 
 	// OCPPPH only, must announce CSU upgrade firmware
 	// OCPPPH only, must announce CSU upgrade firmware
-	if(strstr((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, FirmwareStatusStr[FirmwareStatus_Downloaded]) != NULL)ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
+	if(strstr((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, FirmwareStatusStr[FirmwareStatus_Downloaded]) != NULL)
+	{
+		sleep(3);
+		ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
+	}
 
 
 	interLock.isUpdateFirmwareGoing = 0;
 	interLock.isUpdateFirmwareGoing = 0;
 	pthread_exit(NULL);
 	pthread_exit(NULL);
@@ -15395,10 +15395,7 @@ int initialConfigurationTable(void)
 	FILE *fp;
 	FILE *fp;
 	FILE *outfile;
 	FILE *outfile;
 	char str[512]={0};
 	char str[512]={0};
-	char sstr[256]={0};
-	int c = 0;
-	char *loc;
-	int	confVersion = 18;
+	int	confVersion = 19;
 
 
 	DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
 	DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
 	//start_t = clock();
 	//start_t = clock();
@@ -15842,6 +15839,13 @@ int initialConfigurationTable(void)
 
 
 		fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppSoftwareVersion", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData);
 		fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppSoftwareVersion", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData);
 
 
+		// Check certificate of download link
+		ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemAccessibility = 1;
+		strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemName, "AuthDownloadlinkCertificate");
+		sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemData, "%s", "FALSE");
+
+		fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthDownloadlinkCertificate", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemData);
+
 		//* Local Auth List Management Profile*/
 		//* Local Auth List Management Profile*/
 		#if 0
 		#if 0
 			//For OCTT Test Case
 			//For OCTT Test Case
@@ -15934,54 +15938,19 @@ int initialConfigurationTable(void)
 		while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
 		while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
 		{
 		{
 			//DEBUG_INFO("Get Configuration \n");
 			//DEBUG_INFO("Get Configuration \n");
-
 			if(strlen(str) > 0)
 			if(strlen(str) > 0)
 			{
 			{
-				str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
-				//*************************key*********************************/
-				if(strstr(str, "key") != NULL)
-				{
-					loc = strstr(str, "key");
-					c = 0;
-					memset(sstr ,0, ARRAY_SIZE(sstr) );
-					while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
-					{
-						sstr[c] = loc[strlen("key")+3+c];
-						c++;
-					}
-					sstr[c] = '\0';
-					strcpy(keystr,sstr);
-				}
+				json_object *OCPPConfiguration;
+				OCPPConfiguration = json_tokener_parse(str);
 
 
-				//*************************readonly*********************************/
-				if(strstr(str, "readonly") != NULL)
-				{
-					loc = strstr(str, "readonly");
-					c = 0;
-					memset(sstr ,0, ARRAY_SIZE(sstr) );
-					while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
-					{
-						sstr[c] = loc[strlen("readonly")+2+c];
-						c++;
-					}
-					sstr[c] = '\0';
-					strcpy(readonlystr,sstr);
-				}
+				if(json_object_object_get(OCPPConfiguration, "key") != NULL)
+					strcpy(keystr, json_object_get_string(json_object_object_get(OCPPConfiguration,"key")));
+				if(json_object_object_get(OCPPConfiguration, "readonly") != NULL)
+					strcpy(readonlystr, json_object_get_string(json_object_object_get(OCPPConfiguration,"readonly")));
+				if(json_object_object_get(OCPPConfiguration, "value") != NULL)
+					strcpy(valuestr, json_object_get_string(json_object_object_get(OCPPConfiguration,"value")));
 
 
-				//*************************value*********************************/
-				if(strstr(str, "value") != NULL)
-				{
-					loc = strstr(str, "value");
-					c = 0;
-					memset(sstr ,0, ARRAY_SIZE(sstr) );
-					while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
-					{
-						sstr[c] = loc[strlen("value")+3+c];
-						c++;
-					}
-					sstr[c] = '\0';
-					strcpy(valuestr,sstr);
-				}
+				json_object_put(OCPPConfiguration);
 
 
 	//			DEBUG_INFO("keystr=%s\n",keystr);
 	//			DEBUG_INFO("keystr=%s\n",keystr);
 	//			DEBUG_INFO("readonlystr=%s\n",readonlystr);
 	//			DEBUG_INFO("readonlystr=%s\n",readonlystr);
@@ -16324,6 +16293,12 @@ int initialConfigurationTable(void)
 					sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData, "%s", valuestr);
 					sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData, "%s", valuestr);
 				}
 				}
 
 
+				if(strcmp(keystr, "AuthDownloadlinkCertificate") == 0)
+				{
+					ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
+					sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemData, "%s", valuestr);
+				}
+
 				if(strcmp(keystr, "LocalAuthListEnabled") == 0)
 				if(strcmp(keystr, "LocalAuthListEnabled") == 0)
 				{
 				{
 					ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
 					ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
@@ -16757,7 +16732,25 @@ void StoreConfigurationTable(void)
 	strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
 	strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
 	*/
 	*/
 
 
-	fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
+	json_object *tmp;
+	tmp = json_tokener_parse((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
+	if(!is_error(tmp))
+	{
+		DEBUG_INFO("JSON string type\n");
+		json_object *target = json_object_new_object();
+		json_object_object_add(target, "key", json_object_new_string("DefaultPrice"));
+		json_object_object_add(target, "readonly", (ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility?json_object_new_boolean(0):json_object_new_boolean(1)));
+		json_object_object_add(target, "value", json_object_new_string((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData));
+
+	   fprintf(outfile, "%s\n", json_object_to_json_string_ext(target, JSON_C_TO_STRING_PLAIN));
+		json_object_put(target);
+	}
+	else
+	{
+		DEBUG_INFO("Normal string type\n");
+		fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
+	}
+	json_object_put(tmp);
 
 
 	// CustomDisplayCostAndPrice
 	// CustomDisplayCostAndPrice
 	/*
 	/*
@@ -16903,6 +16896,15 @@ void StoreConfigurationTable(void)
 
 
 	fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppSoftwareVersion", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData);
 	fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppSoftwareVersion", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData);
 
 
+	// AuthDownloadlinkCertificate
+	/*
+	ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemAccessibility = 1;
+	strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemName, "AuthDownloadlinkCertificate");
+	strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemData, "" );
+	*/
+
+	fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthDownloadlinkCertificate", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemData);
+
 	//* Local Auth List Management Profile*/
 	//* Local Auth List Management Profile*/
 	//LocalAuthListEnabled
 	//LocalAuthListEnabled
 	/*
 	/*
@@ -17990,6 +17992,24 @@ void getKeyValue(char *keyReq)
 			  strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppSoftwareVersion].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData );
 			  strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppSoftwareVersion].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData );
 			  isKnowKey = TRUE;
 			  isKnowKey = TRUE;
 		  }
 		  }
+
+		  if(isEmpty ||  strcmp(keyReq, "AuthDownloadlinkCertificate") == 0 )
+		  {
+			  strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthDownloadlinkCertificate].Item, "AuthDownloadlinkCertificate");
+			  strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthDownloadlinkCertificate].Key, "AuthDownloadlinkCertificate");
+
+			  if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemAccessibility == 1)
+			  {
+				  strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthDownloadlinkCertificate].ReadOnly, "0"/*"FALSE"*/);
+			  }
+			  else
+			  {
+				  strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthDownloadlinkCertificate].ReadOnly, "1"/*"TRUE"*/);
+			  }
+
+			  strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthDownloadlinkCertificate].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemData );
+			  isKnowKey = TRUE;
+		  }
 #if 1
 #if 1
 	      if(isEmpty ||  strcmp(keyReq, "LocalAuthListEnabled") == 0 )
 	      if(isEmpty ||  strcmp(keyReq, "LocalAuthListEnabled") == 0 )
 	      {
 	      {
@@ -19322,6 +19342,34 @@ int setKeyValue(char *key, char *value)
 			isSuccess = ConfigurationStatus_Rejected;
 			isSuccess = ConfigurationStatus_Rejected;
 		}
 		}
 	}
 	}
+
+	if(strcmp(key, "OcppSoftwareVersion") == 0)
+	{
+		if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemAccessibility == 1)
+		{
+			strcpy(str, (const char*)value);
+			sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData, "%s", str );
+			isSuccess = ConfigurationStatus_Accepted;
+		}
+		else
+		{
+			isSuccess = ConfigurationStatus_Rejected;
+		}
+	}
+
+	if(strcmp(key, "AuthDownloadlinkCertificate") == 0)
+	{
+		if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemAccessibility == 1)
+		{
+			strcpy(str, (const char*)value);
+			sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemData, "%s", str );
+			isSuccess = ConfigurationStatus_Accepted;
+		}
+		else
+		{
+			isSuccess = ConfigurationStatus_Rejected;
+		}
+	}
 #if 0
 #if 0
     //For OCPP Test Case
     //For OCPP Test Case
     if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
     if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
@@ -19615,9 +19663,9 @@ int ParseHeader(int sock)
 int httpDownLoadFile(char *location, char *path, char *filename,char *url)
 int httpDownLoadFile(char *location, char *path, char *filename,char *url)
 {
 {
 	int result = TRUE;
 	int result = TRUE;
-	char rmFileCmd[100]={0};
-    char FilePath[100]={0};
-	char ftpbuf[200];
+	char rmFileCmd[300]={0};
+    char FilePath[256]={0};
+	char ftpbuf[2048];
 	int systemresult;
 	int systemresult;
 
 
 	sprintf(FilePath,"/mnt/%s",filename);
 	sprintf(FilePath,"/mnt/%s",filename);
@@ -19630,7 +19678,10 @@ int httpDownLoadFile(char *location, char *path, char *filename,char *url)
 		system(rmFileCmd);
 		system(rmFileCmd);
 	}
 	}
 	memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
 	memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
-	sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --no-check-certificate",filename, url);
+	if(strstr((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemData, "TRUE") != NULL)
+		sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --ca-certificate=/root/cacert.pem",filename, url);
+	else
+		sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --no-check-certificate",filename, url);
 	DEBUG_INFO("Download command: %s\n",ftpbuf);
 	DEBUG_INFO("Download command: %s\n",ftpbuf);
 
 
 	systemresult = system(ftpbuf);
 	systemresult = system(ftpbuf);
@@ -19647,9 +19698,9 @@ int httpDownLoadFile(char *location, char *path, char *filename,char *url)
 int sftpDownLoadFile(char *location, char *user, int port, char *path, char *filename,char *url)
 int sftpDownLoadFile(char *location, char *user, int port, char *path, char *filename,char *url)
 {
 {
 	int result = TRUE;
 	int result = TRUE;
-	char rmFileCmd[100]={0};
-	char FilePath[100]={0};
-	char ftpbuf[200];
+	char rmFileCmd[300]={0};
+	char FilePath[256]={0};
+	char ftpbuf[2048];
 	int systemresult;
 	int systemresult;
 
 
 	sprintf(FilePath,"/mnt/%s",filename);
 	sprintf(FilePath,"/mnt/%s",filename);
@@ -19680,9 +19731,9 @@ int sftpDownLoadFile(char *location, char *user, int port, char *path, char *fil
 int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
 int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
 {
 {
 	int result = TRUE;
 	int result = TRUE;
-	char rmFileCmd[100]={0};
-	char FilePath[100]={0};
-	char ftpbuf[200];
+	char rmFileCmd[300]={0};
+	char FilePath[256]={0};
+	char ftpbuf[2048];
 	int systemresult;
 	int systemresult;
 
 
 	sprintf(FilePath,"/mnt/%s",filename);
 	sprintf(FilePath,"/mnt/%s",filename);
@@ -19696,14 +19747,20 @@ int ftpDownLoadFile(char *location, char *user, char *password, int port, char *
 	}
 	}
 
 
 	memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
 	memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
-
-	sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120",filename, url);
+	if(strstr((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemData, "TRUE") != NULL)
+		sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --ca-certificate=/root/cacert.pem",filename, url);
+	else
+		sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --no-check-certificate",filename, url);
 	DEBUG_INFO("Download command: %s\n",ftpbuf);
 	DEBUG_INFO("Download command: %s\n",ftpbuf);
 
 
 	systemresult = system(ftpbuf);
 	systemresult = system(ftpbuf);
 	if(systemresult != 0)
 	if(systemresult != 0)
 	{
 	{
-		sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --no-passive-ftp",filename, url);
+		if(strstr((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemData, "TRUE") != NULL)
+			sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --no-passive-ftp --ca-certificate=/root/cacert.pem",filename, url);
+		else
+			sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --no-passive-ftp --no-check-certificate",filename, url);
+
 		DEBUG_INFO("Download command: %s\n",ftpbuf);
 		DEBUG_INFO("Download command: %s\n",ftpbuf);
 
 
 		systemresult = system(ftpbuf);
 		systemresult = system(ftpbuf);
@@ -21274,10 +21331,13 @@ void InitialSystemValue(void)
 	TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
 	TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
 	TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
 	TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
 
 
-	//Hear Beat
+	//Heart Beat
 	HeartBeatWithNOResponse = 0;
 	HeartBeatWithNOResponse = 0;
-	HeartBeatWaitTime = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
-	FirstHeartBeat = 0;
+	HeartBeatWaitTime = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
+	if(HeartBeatWaitTime == 0)
+		FirstHeartBeat = TRUE;
+	else
+		FirstHeartBeat = FALSE;
 
 
 	FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;  // Idle
 	FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;  // Idle
 	DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
 	DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle

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

@@ -415,6 +415,7 @@ enum GetConfigurationKey {
 	GetConfiguration_ConfigurationVersion,
 	GetConfiguration_ConfigurationVersion,
 	GetConfiguration_CharingProfileRefreshInterval,
 	GetConfiguration_CharingProfileRefreshInterval,
 	GetConfiguration_OcppSoftwareVersion,
 	GetConfiguration_OcppSoftwareVersion,
+	GetConfiguration_AuthDownloadlinkCertificate,
 	_GetConfiguration_CNT
 	_GetConfiguration_CNT
 };
 };