Browse Source

[Bug fix][Modularization][Module_OcppBackend]

2020.10.05 / Folus Wen

Actions:
1. EVSE/Modularization/ocppfiles/MessageHandler.c handleClearChargingProfileRequest() parsing profile from file method 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 4 years ago
parent
commit
2dd4aae63b
1 changed files with 51 additions and 93 deletions
  1. 51 93
      EVSE/Modularization/ocppfiles/MessageHandler.c

+ 51 - 93
EVSE/Modularization/ocppfiles/MessageHandler.c

@@ -6611,10 +6611,7 @@ int handleClearChargingProfileRequest(char *uuid, char *payload)
 	char chargingProfilePurposeStr[26]={0};
 	int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
 	char tempchargingProfilePurposeStr[26]={0};
-	char sstr[160]={0};
 	char str[100]={0};
-	int c = 0;
-	char *loc;
 	char fname[200]={0};
 	char comfirmstr[20]={0};
 	char word[1600]={0};
@@ -6662,7 +6659,6 @@ int handleClearChargingProfileRequest(char *uuid, char *payload)
 	json_object_put(ClearChargingProfile);
 
 
-
 	if(connectorIsNULL == FALSE)
 	{
 		switch(connectorIdInt)
@@ -6856,55 +6852,36 @@ int handleClearChargingProfileRequest(char *uuid, char *payload)
 			//int i= 0;
 			while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
 			{
-				//------------------------tempconnectorIdInt------------------------//
-				loc = strstr(sLineWord, "connectorId");
-				c = 0;
-				memset(sstr ,0, sizeof(sstr) );
-				while (loc[strlen("connectorId")+2+c] != ',')
+				json_object *tmpProfilee;
+				tmpProfilee = json_tokener_parse(sLineWord);
+				if(!is_error(tmpProfilee))
 				{
-					sstr[c] = loc[strlen("connectorId")+2+c];
-					c++;
-				}
-				sstr[c] = '\0';
-				tempconnectorIdInt = atoi(sstr);
-				printf("file's gun number is %d\n", tempconnectorIdInt);
+					if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
+					{
+						tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
+						DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
+					}
 
-				//--------------------------chargingProfileId--------------------//
-				c = 0;
-				loc = strstr(sLineWord, "chargingProfileId");
-				memset(sstr ,0, ARRAY_SIZE(sstr));
-				while (loc[strlen("chargingProfileId")+2+c] != ',')
-				{
-					sstr[c] = loc[strlen("chargingProfileId")+2+c];
-					//printf("i=%d sstr=%c\n",c, sstr[c]);
-					c++;
-				}
-				sstr[c] = '\0';
-				tempchargingProfileIdInt = atoi(sstr);
+					if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
+					{
+						tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
+						DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
+					}
 
-				//stackLevel
-				c = 0;
-				loc = strstr(sLineWord, "stackLevel");
-				memset(sstr ,0, ARRAY_SIZE(sstr));
-				while (loc[strlen("stackLevel")+2+c] != ',')
-				{
-					sstr[c] = loc[strlen("stackLevel")+2+c];
-					//printf("i=%d sstr=%c\n",c, sstr[c]);
-					c++;
-				}
-				sstr[c] = '\0';
-				tempstackLevelInt = atoi(sstr);
+					if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
+					{
+						tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
+						DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
+					}
 
-				c = 0;
-				loc = strstr(sLineWord, "chargingProfilePurpose");
-				memset(sstr ,0, ARRAY_SIZE(sstr));
-				while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
-				{
-					sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
-					c++;
+					if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
+					{
+						sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
+						DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
+					}
 				}
-				sstr[c] = '\0';
-				strcpy(tempchargingProfilePurposeStr, sstr);
+				json_object_put(tmpProfilee);
+
 
 				if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
 				{
@@ -7031,54 +7008,35 @@ int handleClearChargingProfileRequest(char *uuid, char *payload)
 		   //int i= 0;
 		   while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
 		   {
-			   //*************************tempconnectorIdInt*********************************/
-			   loc = strstr(sLineWord, "connectorId");
-			   c = 0;
-			   memset(sstr ,0, ARRAY_SIZE(sstr));
-			   while (loc[strlen("connectorId")+2+c] != ',')
-			   {
-				   sstr[c] = loc[strlen("connectorId")+2+c];
-				   c++;
-			   }
-			   sstr[c] = '\0';
-			   tempconnectorIdInt = atoi(sstr);
+			   	json_object *tmpProfilee;
+				tmpProfilee = json_tokener_parse(sLineWord);
+				if(!is_error(tmpProfilee))
+				{
+					if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
+					{
+						tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
+						DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
+					}
 
-			   //chargingProfileId
-			   c = 0;
-			   loc = strstr(sLineWord, "chargingProfileId");
-			   memset(sstr ,0, ARRAY_SIZE(sstr));
-			   while (loc[strlen("chargingProfileId")+2+c] != ',')
-			   {
-				   sstr[c] = loc[strlen("chargingProfileId")+2+c];
-				   //printf("i=%d sstr=%c\n",c, sstr[c]);
-				   c++;
-			   }
-			   sstr[c] = '\0';
-			   tempchargingProfileIdInt = atoi(sstr);
+					if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
+					{
+						tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
+						DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
+					}
 
-			   //stackLevel
-			   c = 0;
-			   loc = strstr(sLineWord, "stackLevel");
-			   memset(sstr ,0, ARRAY_SIZE(sstr));
-			   while (loc[strlen("stackLevel")+2+c] != ',')
-			   {
-				   sstr[c] = loc[strlen("stackLevel")+2+c];
-				   //printf("i=%d sstr=%c\n",c, sstr[c]);
-				   c++;
-			   }
-			   sstr[c] = '\0';
-			   tempstackLevelInt = atoi(sstr);
+					if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
+					{
+						tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
+						DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
+					}
 
-			   c = 0;
-			   loc = strstr(sLineWord, "chargingProfilePurpose");
-			   memset(sstr ,0, ARRAY_SIZE(sstr));
-			   while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
-			   {
-				   sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
-				   c++;
-			   }
-			   sstr[c] = '\0';
-			   strcpy(tempchargingProfilePurposeStr, sstr);
+					if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
+					{
+						sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
+						DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
+					}
+				}
+				json_object_put(tmpProfilee);
 
 			   if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
 			   {