Browse Source

[Improve][Modularization][Module_OcppBackend / logPackTools]

2021.08.13 / Folus Wen

Actions:
1. Pack OCPP message log without password.
2. handleSendLocalListRequest() parsing payload change by JSON-C lib.

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

+ 2 - 1
EVSE/Modularization/logPackTools.c

@@ -330,7 +330,7 @@ int main(int argc, char *argv[])
 				ty=year;
 			}
 			sprintf(cmd,"%s \t /Storage/SystemLog/*%04d*%02d*",cmd,ty,tm);
-			sprintf(cmd,"%s \t /Storage/OCPP/*%04d*%02d*",cmd,ty,tm);
+			sprintf(cmd,"%s \t /Storage/OCPP/*%04d*%02d*SystemLog",cmd,ty,tm);
 		}
 		sprintf(cmd,"%s \t /Storage/OCPP/*.db",cmd);
 
@@ -354,6 +354,7 @@ int main(int argc, char *argv[])
 				ty=year;
 			}
 			sprintf(cmd,"%s \t /Storage/EventLog/*%04d*%02d*",cmd,ty,tm);
+			sprintf(cmd,"%s \t /Storage/OCPP/*%04d*%02d*OcppMessageLog",cmd,ty,tm);
 		}
 		sprintf(cmd,"%s \t /Storage/ChargeLog/*.db",cmd);
 		sprintf(cmd,"%s \t /Storage/EventLog/*.db",cmd);

+ 111 - 227
EVSE/Modularization/ocppfiles/MessageHandler.c

@@ -38,7 +38,7 @@ static uint8_t gunType[4] 			= {0};
 //===============================
 // Local List Version
 //===============================
-static int localversion=0;
+static int locallistVersion=0;
 static char idTagAuthorization[32]	= {0};
 
 //===============================
@@ -513,8 +513,8 @@ static int callback(void *data, int argc, char **argv, char **azColName){
 static int versioncallback(void *data, int argc, char **argv, char **azColName){
    //int i;
    //printf("%s:\n", (const char*)data);
-   localversion = argv[5] ? atoi(argv[5]) : 0;
-   //printf("localversion=%d\n", localversion);
+	locallistVersion = (argv[5] ? atoi(argv[5]) : 0);
+   DEBUG_INFO("Callback query locallistVersion : %d\n", locallistVersion);
    return 0;
 }
 
@@ -9141,7 +9141,7 @@ void* GetDiagnosticsProcess(void* data)
 		do
 		{
 			sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
-			sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
+			sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog", cmdBuf, targetYear, targetMonth);
 
 			if(targetMonth+1>=13)
 			{
@@ -9156,6 +9156,7 @@ void* GetDiagnosticsProcess(void* data)
 			   ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
 
 		sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
+		sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
 		system(cmdBuf);
 
 		// Pack charging & event log
@@ -9167,7 +9168,7 @@ void* GetDiagnosticsProcess(void* data)
 		do
 		{
 			sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
-
+			sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*OcppMessageLog", cmdBuf, targetYear, targetMonth);
 			if(targetMonth+1>=13)
 			{
 				targetYear += 1;
@@ -9352,7 +9353,7 @@ int handleGetLocalListVersionRequest(char *uuid, char *payload)
 	if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
 	{
 		DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
-		localversion = -1;
+		locallistVersion = -1;
 	}
 	else
 	{
@@ -9361,7 +9362,7 @@ int handleGetLocalListVersionRequest(char *uuid, char *payload)
 	}
 
 	//from db.OCPP_getListVerion
-	ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = localversion;
+	ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = locallistVersion;
 	//ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
 	sendGetLocalListVersionConfirmation(uuid,"");
 	//ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
@@ -10546,28 +10547,11 @@ int handleSendLocalListRequest(char *uuid, char *payload)
 {
 	mtrace();
 	int result = FAIL;
-	int listVersionInt;
-	//char *updateTypestr, *idTagstr, *expiryDatestr, *parentIdTagstr, *statusstr;
-	char listsearch[]="listVersion";
-	char updateTypesearch[]="updateType";
-	char localAuthorizationListsearch[]="localAuthorizationList";
-	char sstr[60500]={ 0 },sstrtemp[60500]={ 0 };//sstr[200]={ 0 };
-	char CardList[500][160]={0};
-	char updateTypestr[15]={0};
-	char idTagstr[20]={0};
-	char parentIdTag[20]={0};
-	char expiryDate[30]={0};
-	char idTagstatus[16]={0};
-	int  c = 0;
-	int i = 0;
-	char *delim1 = "}";
-	char * pch;
-	char *loc;
-	//char *ptr;
 	char comfirmstr[20];
-	//int n_localAuthorizations = 0;
 	int checkState_Faulted = FALSE;
 
+	json_object *SendLocalList;
+
 	DEBUG_INFO("handleSendLocalListRequest...\n");
 
 	if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
@@ -10583,7 +10567,6 @@ int handleSendLocalListRequest(char *uuid, char *payload)
 		{
 			checkState_Faulted = TRUE; //OCPP Status: Faulted
 		}
-
 	}
 
 	for (int index = 0; index < CCS_QUANTITY; index++)
@@ -10592,7 +10575,6 @@ int handleSendLocalListRequest(char *uuid, char *payload)
 		{
 			checkState_Faulted = TRUE; //OCPP Status
 		}
-
 	}
 
 	for (int index = 0; index < GB_QUANTITY; index++)
@@ -10603,6 +10585,15 @@ int handleSendLocalListRequest(char *uuid, char *payload)
 		}
 	}
 
+	//check Charge Point state
+	for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
+	{
+		if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) //S_FAULT   ---> Faulted
+		{
+			checkState_Faulted = TRUE; //OCPP Status: Faulted
+		}
+	}
+
 	//check Charge Point state
 	for (int index = 0; index < AC_QUANTITY; index++)
 	{
@@ -10618,240 +10609,133 @@ int handleSendLocalListRequest(char *uuid, char *payload)
 		goto end;
 	}
 
-	//Filter payload space
-	strcpy(sstrtemp, stringtrimspace(payload));
-
-	//listVersion
-	c = 0;
-	loc = strstr(sstrtemp, listsearch);
-	while ((loc[strlen("listVersion")+2+c] != ',')&&(loc[strlen("listVersion")+2+c] != '}'))
-	{
-		sstr[c] = loc[strlen("listVersion")+2+c];
-		c++;
-	}
-	sstr[c] = '\0';
-	listVersionInt = atoi(sstr);
-
-
-	ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
-
-	//updateType
-	loc = strstr(sstrtemp, updateTypesearch);
-	c = 0;
-	while (loc[3+strlen(updateTypesearch)+c] != '\"')
-	{
-		sstr[c] = loc[3+strlen(updateTypesearch)+c];
-		c++;
-	}
-	sstr[c] = '\0';
-	strcpy(updateTypestr, sstr);
-	sprintf((char *)ShmOCPP16Data->SendLocalList.UpdateType, "%s",  updateTypestr);
-
-	//localAuthorizationList
-	memset(sstr ,0, ARRAY_SIZE(sstr) );
-	loc = strstr(sstrtemp, localAuthorizationListsearch);
-	if(loc != NULL) // localAuthorizationList is not NULL
+	// Parsing payload
+	SendLocalList = json_tokener_parse(payload);
+	if(!is_error(SendLocalList))
 	{
-		//Check UpdateType
-		if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
-		{
-			//Local list full update
-			printf("Local list full update.\n");
-
-			OCPP_getListVerion();
-
-			if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
-			{
-				strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
-				goto end;
-			}
-
-			OCPP_cleanLocalList();
+		// Required data
+		ShmOCPP16Data->SendLocalList.ListVersion = json_object_get_int(json_object_object_get(SendLocalList, "listVersion"));
+		sprintf((char*)ShmOCPP16Data->SendLocalList.UpdateType, "%s", json_object_get_string(json_object_object_get(SendLocalList, "updateType")));
 
-		}
-		else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
+		// Optional data
+		if(json_object_object_get(SendLocalList, "localAuthorizationList") != NULL)
 		{
-			//Local list different update
-			printf("Local list different update.\n");
-
-			OCPP_getListVerion();
-
-			if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
+			//Check UpdateType
+			if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
 			{
-				strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
-				goto end;
-			}
-		}
-		else
-		{
-			strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
-			goto end;
-		}
-
-		c = 0;
-		while (loc[3+strlen(localAuthorizationListsearch)+c] != ']')
-		{
-			sstr[c] = loc[3+strlen(localAuthorizationListsearch)+c];
-			//printf("i=%d sstr=%c\n",c, sstr[c]);
-			c++;
-		}
-		sstr[c] = '\0';
-
-		//DEBUG_INFO("sstr=%s\n", sstr);
-
-		//parsing strings to words
-		i = 0;
-		pch = strtok(sstr,delim1);
-		while (pch != NULL)
-		{
-			strcpy(CardList[i], pch);
-			//DEBUG_INFO("CardList[i]=%s\n", CardList[i]);
-			pch = strtok (NULL, delim1);
-			i = i + 1;
-		}
-
-		//DEBUG_INFO("listVersionInt=%s\n", sstr);
-		//local Authorizations List Numbers
-		//n_localAuthorizations = i;
-		ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
-
-		memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)* 500);
+				//Local list full update
+				DEBUG_INFO("Local list full update.\n");
 
-		c= 0;
-		while(c < i) // i is CardList Number
-		{
-			//Search "IdToken"
-			memset(sstr ,0, ARRAY_SIZE(sstr) );
-			loc = strstr(CardList[c], "idTag");
-			int j = 0;
-			while (loc[3+strlen("idTag")+j] != '\"')
-			{
-				sstr[j] = loc[3+strlen("idTag")+j];
-				//printf("i=%d sstr=%c\n",c, sstr[j]);
-				j++;
-			}
-			sstr[j] = '\0';
-			strcpy(idTagstr, sstr);
-			//DEBUG_INFO("idTagstr=%s\n", idTagstr);
+				OCPP_getListVerion();
 
-			//Search "expiryDate"
-			memset(sstr ,0, ARRAY_SIZE(sstr) );
-			loc = strstr(CardList[c], "expiryDate");
-			j = 0;
-			if(loc != NULL)
-			{
-				while (loc[3+strlen("expiryDate")+j] != '\"')
+				if(ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion)
 				{
-					sstr[j] = loc[3+strlen("expiryDate")+j];
-					//printf("i=%d sstr=%c\n",c, sstr[j]);
-					j++;
+					strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
+					goto end;
 				}
-				sstr[j] = '\0';
-				strcpy(expiryDate, sstr);
+
+				OCPP_cleanLocalList();
 
 			}
-			else
+			else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
 			{
-				strcpy(expiryDate, "");
-			}
+				//Local list different update
+				DEBUG_INFO("Local list different update.\n");
 
-			//DEBUG_INFO("expiryDate=%s\n", expiryDate);
+				OCPP_getListVerion();
 
-			//Search "parentIdTag"
-			memset(sstr ,0, ARRAY_SIZE(sstr) );
-			loc = strstr(CardList[c], "parentIdTag");
-			j = 0;
-			if(loc != NULL)
-			{
-				while (loc[3+strlen("parentIdTag")+j] != '\"')
+				if(ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion)
 				{
-					sstr[j] = loc[3+strlen("parentIdTag")+j];
-					//printf("i=%d sstr=%c\n",c, sstr[j]);
-					j++;
+					strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
+					goto end;
 				}
-				sstr[j] = '\0';
-				strcpy(parentIdTag, sstr);
 			}
 			else
 			{
-				strcpy(parentIdTag, "");
+				strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
+				goto end;
 			}
 
-			//DEBUG_INFO("parentIdTag=%s\n", parentIdTag);
-
-
-			//Search "status"
-			memset(sstr ,0, ARRAY_SIZE(sstr) );
-			loc = strstr(CardList[c], "status");
-			j = 0;
-			while (loc[3+strlen("status")+j] != '\"')
+			memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)* 500);
+			for(int idx=0;idx<json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList"));idx++)
 			{
-				sstr[j] = loc[3+strlen("status")+j];
-				//printf("i=%d sstr=%c\n",c, sstr[j]);
-				j++;
-			}
-			sstr[j] = '\0';
-			strcpy(idTagstatus, sstr);
+				sprintf((char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTag, "%s", json_object_get_string(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTag")));
 
-			//DEBUG_INFO("idTagstatus=%s\n", idTagstatus);
+				if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo") != NULL)
+				{
+					sprintf((char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "status")));
 
-			OCPP_getIdTagFromLocalList(idTagstr);
-			//OCPP_getIdTagFromLocalList("test"); For Test
-			//DEBUG_INFO("idTagAuthorization=%s\n",idTagAuthorization);
-			//DEBUG_INFO("updateTypestr=%s\n",updateTypestr);
+					if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate") != NULL)
+						sprintf((char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate")));
 
-			if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
-			{
-				//Local list full update
-				DEBUG_INFO("Local list full update %d, %d, %s, %s, %s, %s.\n", c, listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
-				// update list
-				OCPP_addLocalList(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
-				//DEBUG_INFO("Local list full update. 1\n");
-				//OCPP_get_TableAuthlocalAllData();
-				//DEBUG_INFO("Local list full update. 2\n");
+					if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag") != NULL)
+						sprintf((char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag")));
+				}
+
+				// Add to db
+				if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
+				{
+					//Local list full update
+					DEBUG_INFO("Local list full update item: %d, listVer: %d, %s, %s, %s, %s.\n",
+																				   idx,
+																				   ShmOCPP16Data->SendLocalList.ListVersion,
+																				   ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTag,
+																				   ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ParentIdTag,
+																				   ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ExpiryDate,
+																				   ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.Status);
+					// update list
+					OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
+									  (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTag,
+									  (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ParentIdTag,
+									  (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ExpiryDate,
+									  (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.Status);
+				}
+				else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
+				{
+					DEBUG_INFO("Local list diff update item: %d,listVer:  %d, %s, %s, %s, %s.\n",
+																					idx,
+																				   ShmOCPP16Data->SendLocalList.ListVersion,
+																				   ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTag,
+																				   ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ParentIdTag,
+																				   ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ExpiryDate,
+																				   ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.Status);
+					OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
+									  (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTag,
+									  (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ParentIdTag,
+									  (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ExpiryDate,
+									  (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.Status);
+				}
 			}
-			else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
+		}
+		else
+		{
+			//Check UpdateType
+			if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
 			{
-				DEBUG_INFO("Local list diff update %d, %d, %s, %s, %s, %s.\n", c, listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
-				OCPP_addLocalList(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus); // update or add
+				//Local list full update
+				DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
+				OCPP_cleanLocalList();
+				strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
+				goto end;
 			}
 
-			strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTag, idTagstr);
-			strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ExpiryDate, expiryDate);
-			strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ParentIdTag, parentIdTag);
-			strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.Status, idTagstatus);
+			if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
+			{
+				 //Local list different update
+				DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
+				strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
+				goto end;
 
-			c++;
-		}
-	}
-	else
-	{
-		//Check UpdateType
-		if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
-		{
-			//Local list full update
-			DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
-			OCPP_cleanLocalList();
-			strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
-			goto end;
+			}
 		}
 
-		if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
-		{
-			 //Local list different update
-			DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
-			strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
-			goto end;
-
-		}
+		result = PASS;
 	}
-
 	strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
 
 end:
-
+	json_object_put(SendLocalList);
 	sendSendLocalListConfirmation(uuid, comfirmstr);
-	//ShmOCPP16Data->MsMsg.bits.SendLocalListConf = 1;
 
 	return result;
 }
@@ -18019,7 +17903,7 @@ void InitialSystemValue(void)
 	server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
 	gunTotalNumber=0;
 	SystemInitial = 0;
-	localversion=0;
+	locallistVersion=0;
 	BootNotificationInterval = 0;
 	authorizeRetryTimes = 0;
 	GunStatusInterval = 10;

+ 111 - 227
EVSE/Modularization/ocppph/MessageHandler.c

@@ -39,7 +39,7 @@ static uint8_t gunType[4] 			= {0};
 //===============================
 // Local List Version
 //===============================
-static int localversion=0;
+static int locallistVersion=0;
 static char idTagAuthorization[32]	= {0};
 
 //===============================
@@ -513,8 +513,8 @@ static int callback(void *data, int argc, char **argv, char **azColName){
 static int versioncallback(void *data, int argc, char **argv, char **azColName){
    //int i;
    //printf("%s:\n", (const char*)data);
-   localversion = argv[5] ? atoi(argv[5]) : 0;
-   //printf("localversion=%d\n", localversion);
+	locallistVersion = (argv[5] ? atoi(argv[5]) : 0);
+   DEBUG_INFO("Callback query locallistVersion : %d\n", locallistVersion);
    return 0;
 }
 
@@ -9159,7 +9159,7 @@ void* GetDiagnosticsProcess(void* data)
 		do
 		{
 			sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
-			sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
+			sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog", cmdBuf, targetYear, targetMonth);
 
 			if(targetMonth+1>=13)
 			{
@@ -9174,6 +9174,7 @@ void* GetDiagnosticsProcess(void* data)
 			   ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
 
 		sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
+		sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
 		system(cmdBuf);
 
 		// Pack charging & event log
@@ -9185,7 +9186,7 @@ void* GetDiagnosticsProcess(void* data)
 		do
 		{
 			sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
-
+			sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*OcppMessageLog", cmdBuf, targetYear, targetMonth);
 			if(targetMonth+1>=13)
 			{
 				targetYear += 1;
@@ -9371,7 +9372,7 @@ int handleGetLocalListVersionRequest(char *uuid, char *payload)
 	if(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
 	{
 		DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
-		localversion = -1;
+		locallistVersion = -1;
 	}
 	else
 	{
@@ -9380,7 +9381,7 @@ int handleGetLocalListVersionRequest(char *uuid, char *payload)
 	}
 
 	//from db.OCPP_getListVerion
-	ShmOCPP16DataPH->GetLocalListVersion.ResponseListVersion = localversion;
+	ShmOCPP16DataPH->GetLocalListVersion.ResponseListVersion = locallistVersion;
 	//ShmOCPP16DataPH->MsMsg.bits.GetLocalListVersionReq = 1;
 	sendGetLocalListVersionConfirmation(uuid,"");
 	//ShmOCPP16DataPH->MsMsg.bits.GetLocalListVersionConf = 1;
@@ -10565,28 +10566,11 @@ int handleSendLocalListRequest(char *uuid, char *payload)
 {
 	mtrace();
 	int result = FAIL;
-	int listVersionInt;
-	//char *updateTypestr, *idTagstr, *expiryDatestr, *parentIdTagstr, *statusstr;
-	char listsearch[]="listVersion";
-	char updateTypesearch[]="updateType";
-	char localAuthorizationListsearch[]="localAuthorizationList";
-	char sstr[60500]={ 0 },sstrtemp[60500]={ 0 };//sstr[200]={ 0 };
-	char CardList[500][160]={0};
-	char updateTypestr[15]={0};
-	char idTagstr[20]={0};
-	char parentIdTag[20]={0};
-	char expiryDate[30]={0};
-	char idTagstatus[16]={0};
-	int  c = 0;
-	int i = 0;
-	char *delim1 = "}";
-	char * pch;
-	char *loc;
-	//char *ptr;
 	char comfirmstr[20];
-	//int n_localAuthorizations = 0;
 	int checkState_Faulted = FALSE;
 
+	json_object *SendLocalList;
+
 	DEBUG_INFO("handleSendLocalListRequest...\n");
 
 	if(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
@@ -10602,7 +10586,6 @@ int handleSendLocalListRequest(char *uuid, char *payload)
 		{
 			checkState_Faulted = TRUE; //OCPP Status: Faulted
 		}
-
 	}
 
 	for (int index = 0; index < CCS_QUANTITY; index++)
@@ -10611,7 +10594,6 @@ int handleSendLocalListRequest(char *uuid, char *payload)
 		{
 			checkState_Faulted = TRUE; //OCPP Status
 		}
-
 	}
 
 	for (int index = 0; index < GB_QUANTITY; index++)
@@ -10622,6 +10604,15 @@ int handleSendLocalListRequest(char *uuid, char *payload)
 		}
 	}
 
+	//check Charge Point state
+	for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
+	{
+		if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) //S_FAULT   ---> Faulted
+		{
+			checkState_Faulted = TRUE; //OCPP Status: Faulted
+		}
+	}
+
 	//check Charge Point state
 	for (int index = 0; index < AC_QUANTITY; index++)
 	{
@@ -10637,240 +10628,133 @@ int handleSendLocalListRequest(char *uuid, char *payload)
 		goto end;
 	}
 
-	//Filter payload space
-	strcpy(sstrtemp, stringtrimspace(payload));
-
-	//listVersion
-	c = 0;
-	loc = strstr(sstrtemp, listsearch);
-	while ((loc[strlen("listVersion")+2+c] != ',')&&(loc[strlen("listVersion")+2+c] != '}'))
-	{
-		sstr[c] = loc[strlen("listVersion")+2+c];
-		c++;
-	}
-	sstr[c] = '\0';
-	listVersionInt = atoi(sstr);
-
-
-	ShmOCPP16DataPH->SendLocalList.ListVersion = listVersionInt;
-
-	//updateType
-	loc = strstr(sstrtemp, updateTypesearch);
-	c = 0;
-	while (loc[3+strlen(updateTypesearch)+c] != '\"')
-	{
-		sstr[c] = loc[3+strlen(updateTypesearch)+c];
-		c++;
-	}
-	sstr[c] = '\0';
-	strcpy(updateTypestr, sstr);
-	sprintf((char *)ShmOCPP16DataPH->SendLocalList.UpdateType, "%s",  updateTypestr);
-
-	//localAuthorizationList
-	memset(sstr ,0, ARRAY_SIZE(sstr) );
-	loc = strstr(sstrtemp, localAuthorizationListsearch);
-	if(loc != NULL) // localAuthorizationList is not NULL
+	// Parsing payload
+	SendLocalList = json_tokener_parse(payload);
+	if(!is_error(SendLocalList))
 	{
-		//Check UpdateType
-		if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
-		{
-			//Local list full update
-			printf("Local list full update.\n");
-
-			OCPP_getListVerion();
-
-			if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
-			{
-				strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
-				goto end;
-			}
-
-			OCPP_cleanLocalList();
+		// Required data
+		ShmOCPP16DataPH->SendLocalList.ListVersion = json_object_get_int(json_object_object_get(SendLocalList, "listVersion"));
+		sprintf((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, "%s", json_object_get_string(json_object_object_get(SendLocalList, "updateType")));
 
-		}
-		else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
+		// Optional data
+		if(json_object_object_get(SendLocalList, "localAuthorizationList") != NULL)
 		{
-			//Local list different update
-			printf("Local list different update.\n");
-
-			OCPP_getListVerion();
-
-			if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
+			//Check UpdateType
+			if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
 			{
-				strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
-				goto end;
-			}
-		}
-		else
-		{
-			strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
-			goto end;
-		}
-
-		c = 0;
-		while (loc[3+strlen(localAuthorizationListsearch)+c] != ']')
-		{
-			sstr[c] = loc[3+strlen(localAuthorizationListsearch)+c];
-			//printf("i=%d sstr=%c\n",c, sstr[c]);
-			c++;
-		}
-		sstr[c] = '\0';
-
-		//DEBUG_INFO("sstr=%s\n", sstr);
-
-		//parsing strings to words
-		i = 0;
-		pch = strtok(sstr,delim1);
-		while (pch != NULL)
-		{
-			strcpy(CardList[i], pch);
-			//DEBUG_INFO("CardList[i]=%s\n", CardList[i]);
-			pch = strtok (NULL, delim1);
-			i = i + 1;
-		}
-
-		//DEBUG_INFO("listVersionInt=%s\n", sstr);
-		//local Authorizations List Numbers
-		//n_localAuthorizations = i;
-		ShmOCPP16DataPH->SendLocalList.ListVersion = listVersionInt;
-
-		memset(ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)* 500);
+				//Local list full update
+				DEBUG_INFO("Local list full update.\n");
 
-		c= 0;
-		while(c < i) // i is CardList Number
-		{
-			//Search "IdToken"
-			memset(sstr ,0, ARRAY_SIZE(sstr) );
-			loc = strstr(CardList[c], "idTag");
-			int j = 0;
-			while (loc[3+strlen("idTag")+j] != '\"')
-			{
-				sstr[j] = loc[3+strlen("idTag")+j];
-				//printf("i=%d sstr=%c\n",c, sstr[j]);
-				j++;
-			}
-			sstr[j] = '\0';
-			strcpy(idTagstr, sstr);
-			//DEBUG_INFO("idTagstr=%s\n", idTagstr);
+				OCPP_getListVerion();
 
-			//Search "expiryDate"
-			memset(sstr ,0, ARRAY_SIZE(sstr) );
-			loc = strstr(CardList[c], "expiryDate");
-			j = 0;
-			if(loc != NULL)
-			{
-				while (loc[3+strlen("expiryDate")+j] != '\"')
+				if(ShmOCPP16DataPH->SendLocalList.ListVersion < locallistVersion)
 				{
-					sstr[j] = loc[3+strlen("expiryDate")+j];
-					//printf("i=%d sstr=%c\n",c, sstr[j]);
-					j++;
+					strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
+					goto end;
 				}
-				sstr[j] = '\0';
-				strcpy(expiryDate, sstr);
+
+				OCPP_cleanLocalList();
 
 			}
-			else
+			else if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
 			{
-				strcpy(expiryDate, "");
-			}
+				//Local list different update
+				DEBUG_INFO("Local list different update.\n");
 
-			//DEBUG_INFO("expiryDate=%s\n", expiryDate);
+				OCPP_getListVerion();
 
-			//Search "parentIdTag"
-			memset(sstr ,0, ARRAY_SIZE(sstr) );
-			loc = strstr(CardList[c], "parentIdTag");
-			j = 0;
-			if(loc != NULL)
-			{
-				while (loc[3+strlen("parentIdTag")+j] != '\"')
+				if(ShmOCPP16DataPH->SendLocalList.ListVersion < locallistVersion)
 				{
-					sstr[j] = loc[3+strlen("parentIdTag")+j];
-					//printf("i=%d sstr=%c\n",c, sstr[j]);
-					j++;
+					strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
+					goto end;
 				}
-				sstr[j] = '\0';
-				strcpy(parentIdTag, sstr);
 			}
 			else
 			{
-				strcpy(parentIdTag, "");
+				strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
+				goto end;
 			}
 
-			//DEBUG_INFO("parentIdTag=%s\n", parentIdTag);
-
-
-			//Search "status"
-			memset(sstr ,0, ARRAY_SIZE(sstr) );
-			loc = strstr(CardList[c], "status");
-			j = 0;
-			while (loc[3+strlen("status")+j] != '\"')
+			memset(ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)* 500);
+			for(int idx=0;idx<json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList"));idx++)
 			{
-				sstr[j] = loc[3+strlen("status")+j];
-				//printf("i=%d sstr=%c\n",c, sstr[j]);
-				j++;
-			}
-			sstr[j] = '\0';
-			strcpy(idTagstatus, sstr);
+				sprintf((char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[idx].IdTag, "%s", json_object_get_string(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTag")));
 
-			//DEBUG_INFO("idTagstatus=%s\n", idTagstatus);
+				if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo") != NULL)
+				{
+					sprintf((char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "status")));
 
-			OCPP_getIdTagFromLocalList(idTagstr);
-			//OCPP_getIdTagFromLocalList("test"); For Test
-			//DEBUG_INFO("idTagAuthorization=%s\n",idTagAuthorization);
-			//DEBUG_INFO("updateTypestr=%s\n",updateTypestr);
+					if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate") != NULL)
+						sprintf((char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate")));
 
-			if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
-			{
-				//Local list full update
-				DEBUG_INFO("Local list full update %d, %d, %s, %s, %s, %s.\n", c, listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
-				// update list
-				OCPP_addLocalList(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
-				//DEBUG_INFO("Local list full update. 1\n");
-				//OCPP_get_TableAuthlocalAllData();
-				//DEBUG_INFO("Local list full update. 2\n");
+					if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag") != NULL)
+						sprintf((char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag")));
+				}
+
+				// Add to db
+				if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
+				{
+					//Local list full update
+					DEBUG_INFO("Local list full update item: %d, listVer: %d, %s, %s, %s, %s.\n",
+																				   idx,
+																				   ShmOCPP16DataPH->SendLocalList.ListVersion,
+																				   ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[idx].IdTag,
+																				   ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ParentIdTag,
+																				   ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ExpiryDate,
+																				   ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.Status);
+					// update list
+					OCPP_addLocalList(ShmOCPP16DataPH->SendLocalList.ListVersion,
+									  (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[idx].IdTag,
+									  (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ParentIdTag,
+									  (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ExpiryDate,
+									  (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.Status);
+				}
+				else if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
+				{
+					DEBUG_INFO("Local list diff update item: %d,listVer:  %d, %s, %s, %s, %s.\n",
+																					idx,
+																				   ShmOCPP16DataPH->SendLocalList.ListVersion,
+																				   ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[idx].IdTag,
+																				   ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ParentIdTag,
+																				   ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ExpiryDate,
+																				   ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.Status);
+					OCPP_addLocalList(ShmOCPP16DataPH->SendLocalList.ListVersion,
+									  (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[idx].IdTag,
+									  (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ParentIdTag,
+									  (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ExpiryDate,
+									  (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.Status);
+				}
 			}
-			else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
+		}
+		else
+		{
+			//Check UpdateType
+			if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
 			{
-				DEBUG_INFO("Local list diff update %d, %d, %s, %s, %s, %s.\n", c, listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
-				OCPP_addLocalList(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus); // update or add
+				//Local list full update
+				DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
+				OCPP_cleanLocalList();
+				strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
+				goto end;
 			}
 
-			strcpy((char *)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[c].IdTag, idTagstr);
-			strcpy((char *)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ExpiryDate, expiryDate);
-			strcpy((char *)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ParentIdTag, parentIdTag);
-			strcpy((char *)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[c].IdTagInfo.Status, idTagstatus);
+			if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
+			{
+				 //Local list different update
+				DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
+				strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
+				goto end;
 
-			c++;
-		}
-	}
-	else
-	{
-		//Check UpdateType
-		if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
-		{
-			//Local list full update
-			DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
-			OCPP_cleanLocalList();
-			strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
-			goto end;
+			}
 		}
 
-		if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
-		{
-			 //Local list different update
-			DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
-			strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
-			goto end;
-
-		}
+		result = PASS;
 	}
-
 	strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
 
 end:
-
+	json_object_put(SendLocalList);
 	sendSendLocalListConfirmation(uuid, comfirmstr);
-	//ShmOCPP16DataPH->MsMsg.bits.SendLocalListConf = 1;
 
 	return result;
 }
@@ -17988,7 +17872,7 @@ void InitialSystemValue(void)
 	server_cycle_Status = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
 	gunTotalNumber=0;
 	SystemInitial = 0;
-	localversion=0;
+	locallistVersion=0;
 	BootNotificationInterval = 0;
 	authorizeRetryTimes = 0;
 	GunStatusInterval = 10;