瀏覽代碼

[Improve][Modularization][Module_OcppBackend / Module_OcppBackend20]

2021.09.16 / Folus Wen

Actions:
1. SetChargingProfile logic improve.
2. TxProfile delete timing improve.

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 年之前
父節點
當前提交
2bff45c780
共有 3 個文件被更改,包括 769 次插入1219 次删除
  1. 190 202
      EVSE/Modularization/ocpp20/MessageHandler.c
  2. 293 508
      EVSE/Modularization/ocppfiles/MessageHandler.c
  3. 286 509
      EVSE/Modularization/ocppph/MessageHandler.c

+ 190 - 202
EVSE/Modularization/ocpp20/MessageHandler.c

@@ -6258,19 +6258,18 @@ void CheckSystemValue(void)
 						{
 							cpinitateMsg.bits[gun_index].TransactionEventReq = ON;
 						}
-					}
 
-					if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
-					{
-						sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
-						if((access(filenmae,F_OK))!=-1)
+						if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
 						{
-							DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
+							sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
+							if((access(filenmae,F_OK))!=-1)
+							{
+								DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
 
-							sprintf(str,"rm -f %s",filenmae);
-							system(str);
+								sprintf(str,"rm -f %s",filenmae);
+								system(str);
+							}
 						}
-
 					}
 
 					cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
@@ -6313,16 +6312,16 @@ void CheckSystemValue(void)
 						{
 							cpinitateMsg.bits[gun_index].TransactionEventReq = ON;
 						}
-					}
 
-					if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
-					{
-						sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
-						if((access(filenmae,F_OK))!=-1)
+						if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
 						{
-							DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
-							sprintf(str,"rm -f %s",filenmae);
-							system(str);
+							sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
+							if((access(filenmae,F_OK))!=-1)
+							{
+								DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
+								sprintf(str,"rm -f %s",filenmae);
+								system(str);
+							}
 						}
 					}
 
@@ -6366,16 +6365,16 @@ void CheckSystemValue(void)
 						{
 							cpinitateMsg.bits[gun_index].TransactionEventReq = ON;
 						}
-					}
 
-					if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
-					{
-						sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
-						if((access(filenmae,F_OK))!=-1)
+						if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
 						{
-							DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
-							sprintf(str,"rm -f %s",filenmae);
-							system(str);
+							sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
+							if((access(filenmae,F_OK))!=-1)
+							{
+								DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
+								sprintf(str,"rm -f %s",filenmae);
+								system(str);
+							}
 						}
 					}
 
@@ -6412,16 +6411,16 @@ void CheckSystemValue(void)
 						{
 							cpinitateMsg.bits[gun_index].TransactionEventReq = ON;
 						}
-					}
 
-					if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // complete
-					{
-						sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
-						if((access(filenmae,F_OK))!=-1)
+						if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_IDLE))) // complete
 						{
-							DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
-							sprintf(str,"rm -f %s",filenmae);
-							system(str);
+							sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
+							if((access(filenmae,F_OK))!=-1)
+							{
+								DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
+								sprintf(str,"rm -f %s",filenmae);
+								system(str);
+							}
 						}
 					}
 
@@ -6464,17 +6463,17 @@ void CheckSystemValue(void)
 						{
 							cpinitateMsg.bits[gun_index].TransactionEventReq = ON;
 						}
-					}
 
-					if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
-					{
-						sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
-						if((access(filenmae,F_OK))!=-1)
+						if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
 						{
-							DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
+							sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
+							if((access(filenmae,F_OK))!=-1)
+							{
+								DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
 
-							sprintf(str,"rm -f %s",filenmae);
-							system(str);
+								sprintf(str,"rm -f %s",filenmae);
+								system(str);
+							}
 						}
 					}
 
@@ -15524,13 +15523,14 @@ int handleSetChargingProfileRequest(char *uuid, char *payload)
 {
 	mtrace();
 	int result = FAIL;
-	int8_t gun_index = -1;
+	struct SetChargingProfile_20 SetProfileReq = {0};
+	uint8_t isLostConnectorId = FALSE;
 	uint8_t isPeriodOverMax = FALSE;
 	uint8_t isProfileOverMax = FALSE;
 	uint8_t isConnectorMismatch = FALSE;
 	uint8_t existProfileQuantity = 0;
 	uint8_t filename[128]={0};
-	uint8_t word[2048]={0};
+	uint8_t dataLine[4096]={0};
 	FILE *filePtr;
 	json_object *SetChargingProfile;
 
@@ -15540,12 +15540,17 @@ int handleSetChargingProfileRequest(char *uuid, char *payload)
 	{
 		// Required data
 		if(json_object_object_get(SetChargingProfile, "evseId") != NULL)
-		{
-			gun_index = json_object_get_int(json_object_object_get(SetChargingProfile, "evseId"));
-		}
+			SetProfileReq.evseId = json_object_get_int(json_object_object_get(SetChargingProfile, "evseId"));
+		else
+			isLostConnectorId = TRUE;
+
+		if(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "id") != NULL)
+			SetProfileReq.chargingProfile.id = json_object_get_int((json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "id")));
 
 		if(json_object_object_get(SetChargingProfile, "chargingProfile") != NULL)
 		{
+			sprintf((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingProfilePurpose")));
+
 			// Check periods is over max configuration
 			if(json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod")) > atoi((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule].variableAttribute[0].value))
 			{
@@ -15555,7 +15560,7 @@ int handleSetChargingProfileRequest(char *uuid, char *payload)
 			// Check periods is over max configuration
 			if(strstr(json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingProfilePurpose")), ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_ChargingStationMaxProfile]) != NULL)
 			{
-				if(gun_index == 0)
+				if(SetProfileReq.evseId == 0)
 				{
 					sprintf((char*)filename, ChargePointMaxProfile_JSON);
 					filePtr = fopen((char*)filename, "r");
@@ -15567,10 +15572,10 @@ int handleSetChargingProfileRequest(char *uuid, char *payload)
 					else
 					{
 						//Check Charging Profile Count
-						while(fscanf(filePtr, "%s", word) != EOF)
+						while(fscanf(filePtr, "%s", dataLine) != EOF)
 						{
 							//DEBUG_INFO("word=%s\n",word);
-							if(strstr((char*)word, "chargingProfileId")!= NULL)
+							if(strstr((char*)dataLine, "chargingProfileId")!= NULL)
 							{
 								existProfileQuantity += 1;
 							}
@@ -15583,38 +15588,70 @@ int handleSetChargingProfileRequest(char *uuid, char *payload)
 			}
 			else if(strstr(json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingProfilePurpose")), ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_TxDefaultProfile]) != NULL)
 			{
-				if(gun_index < 5)
-					sprintf((char*)filename, "/Storage/OCPP/TxDefaultProfile_%d_OCPP20.json", gun_index);
-				else
+				if((0 < SetProfileReq.evseId) && (SetProfileReq.evseId > gunTotalNumber))
 					isConnectorMismatch = TRUE;
 
 				if(!isConnectorMismatch)
 				{
-					filePtr = fopen((char*)filename, "r");
-					if (!filePtr)
+					if(SetProfileReq.evseId == 0)
 					{
-						DEBUG_INFO("%s not exist, create it.\n", filename);
-						filePtr = fopen((char*)filename, "w+");
+						int tmpExistProfileQuantity;
+
+						for(int idxCon=1;idxCon<=gunTotalNumber;idxCon++)
+						{
+							sprintf((char*)filename, "/Storage/OCPP/TxDefaultProfile_%d_OCPP20.json", idxCon);
+							filePtr = fopen((char*)filename, "r");
+							if (!filePtr)
+							{
+								DEBUG_INFO("%s not exist, create it.\n", filename);
+								filePtr = fopen((char*)filename, "w+");
+							}
+							else
+							{
+								//Check Charging Profile Count
+								while(fscanf(filePtr, "%s", dataLine) != EOF)
+								{
+									//DEBUG_INFO("word=%s\n",word);
+									if(strstr((char*)dataLine, "chargingProfileId")!= NULL)
+									{
+										tmpExistProfileQuantity += 1;
+									}
+								}
+							}
+							fclose(filePtr);
+
+							existProfileQuantity = (existProfileQuantity < tmpExistProfileQuantity) ? tmpExistProfileQuantity : existProfileQuantity;
+						}
 					}
 					else
 					{
-						//Check Charging Profile Count
-						while(fscanf(filePtr, "%s", word) != EOF)
+						sprintf((char*)filename, "/Storage/OCPP/TxDefaultProfile_%d_OCPP20.json", SetProfileReq.evseId);
+						filePtr = fopen((char*)filename, "r");
+						if (!filePtr)
 						{
-							//DEBUG_INFO("word=%s\n",word);
-							if(strstr((char*)word, "chargingProfileId")!= NULL)
+							DEBUG_INFO("%s not exist, create it.\n", filename);
+							filePtr = fopen((char*)filename, "w+");
+						}
+						else
+						{
+							//Check Charging Profile Count
+							while(fscanf(filePtr, "%s", dataLine) != EOF)
 							{
-								existProfileQuantity += 1;
+								//DEBUG_INFO("word=%s\n",word);
+								if(strstr((char*)dataLine, "chargingProfileId")!= NULL)
+								{
+									existProfileQuantity += 1;
+								}
 							}
 						}
+						fclose(filePtr);
 					}
-					fclose(filePtr);
 				}
 			}
 			else if(strstr(json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingProfilePurpose")), ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_TxProfile]) != NULL)
 			{
-				if(gun_index>0)
-					sprintf((char*)filename, "/Storage/OCPP/TxProfile_%d_OCPP20.json", gun_index);
+				if((SetProfileReq.evseId > 0) && (SetProfileReq.evseId <= gunTotalNumber))
+					sprintf((char*)filename, "/Storage/OCPP/TxProfile_%d_OCPP20.json", SetProfileReq.evseId);
 				else
 					isConnectorMismatch = TRUE;
 
@@ -15629,10 +15666,10 @@ int handleSetChargingProfileRequest(char *uuid, char *payload)
 					else
 					{
 						//Check Charging Profile Count
-						while(fscanf(filePtr, "%s", word) != EOF)
+						while(fscanf(filePtr, "%s", dataLine) != EOF)
 						{
 							//DEBUG_INFO("word=%s\n",word);
-							if(strstr((char*)word, "chargingProfileId")!= NULL)
+							if(strstr((char*)dataLine, "chargingProfileId")!= NULL)
 							{
 								existProfileQuantity += 1;
 							}
@@ -15643,188 +15680,139 @@ int handleSetChargingProfileRequest(char *uuid, char *payload)
 			}
 			else if(strstr(json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingProfilePurpose")), ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_ChargingStationExternalConstraints]) != NULL)
 			{
-
+				/*
+				 *	TODO:
+				 *
+				 */
 			}
 			else
-			{
-
-			}
+			{}
 
 			if(existProfileQuantity >= atoi((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].variableAttribute[0].value))
 				isProfileOverMax = TRUE;
 		}
 
 		// Profile replace or add info
-		if((gun_index > -1) && !isPeriodOverMax && !isProfileOverMax && !isConnectorMismatch)
+		if(!isLostConnectorId && !isPeriodOverMax && !isProfileOverMax && !isConnectorMismatch)
 		{
 			FILE *infile;
 			FILE *outfile;
-			char tmpProfileName[32];
+			char tmpProfileName[] = "/Storage/OCPP/SetChargingProfiletemp_OCPP20.json";
 			char rmFileCmd[128];
-			char tempchargingProfilePurposeStr[30]={0};
-			int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
-
-			sprintf((char*)tmpProfileName, "/Storage/OCPP/tmpProfile");
-			infile = fopen ((char*)filename, "r");
-			outfile = fopen ((char*)tmpProfileName, "w");
+			int tempchargingProfileIdInt;
+			int chkChar;
 
-			int d = fgetc(infile);
-			rewind(infile);
-
-			if(d == EOF)
+			for(int idxCon=1; idxCon <= (SetProfileReq.evseId==0?gunTotalNumber:1); idxCon++)
 			{
-				// Profile is empty
-				fprintf(outfile,"%s\n", payload);
-
-				fclose(infile);
-				fclose(outfile);
+				if(strcmp((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_ChargingStationMaxProfile]) == 0)
+				{
+					sprintf((char*)filename, "%s", ChargePointMaxProfile_JSON);
+				}
+				else if(strcmp((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_TxDefaultProfile]) == 0)
+				{
+					if(SetProfileReq.evseId==0)
+						sprintf((char*)filename, "/Storage/OCPP/TxDefaultProfile_%d_OCPP20.json", idxCon);
+					else
+						sprintf((char*)filename, "/Storage/OCPP/TxDefaultProfile_%d_OCPP20.json", SetProfileReq.evseId);
+				}
+				else if(strcmp((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_TxProfile]) == 0)
+				{
+					sprintf((char*)filename, "/Storage/OCPP/TxProfile_%d_OCPP20.json", SetProfileReq.evseId);
+				}
+				else
+				{
+					/*
+					 *	TODO:
+					 *
+					 */
+				}
 
-				sprintf(rmFileCmd,"rm -f %s",filename);
-				system(rmFileCmd);
 
-				rename((char*)tmpProfileName, (char*)filename);
-			}
-			else
-			{
-				// Profile is not empty
-				char buf[2048]={0};
-				int ChargingProfileAdded = FALSE;
+				infile = fopen ((char*)filename, "r");
+				outfile = fopen ((char*)tmpProfileName, "w");
 
-				while (fgets(buf, sizeof(buf), infile) != NULL)
+				chkChar = fgetc(infile);
+				rewind(infile);
+				if(chkChar == EOF)
 				{
-					buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
+					// Profile is empty
+					if((strcmp((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_TxDefaultProfile]) == 0) && (SetProfileReq.evseId==0))
+						json_object_object_add(SetChargingProfile, "evseId", json_object_new_int(idxCon));
+					fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
 
-					json_object *tmpChargingProfile;
-					tmpChargingProfile = json_tokener_parse(buf);
-					if(!is_error(tmpChargingProfile))
-					{
-						if(json_object_object_get(tmpChargingProfile, "evseId") != NULL)
-						{
-							tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpChargingProfile, "evseId") );
-						}
+					fclose(infile);
+					fclose(outfile);
 
-						if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
-						{
-							if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
-							{
-								tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
-							}
+					sprintf(rmFileCmd,"rm -f %s",filename);
+					system(rmFileCmd);
 
-							if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
-							{
-								tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel"));
-							}
-
-							if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
-							{
-								strcpy(tempchargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
-							}
-						}
-					}
-					json_object_put(tmpChargingProfile);
+					rename((char*)tmpProfileName, (char*)filename);
+				}
+				else
+				{
+					// Profile is not empty
+					int ChargingProfileAdded = FALSE;
 
-					if((tempconnectorIdInt == gun_index) &&
-					   (tempchargingProfileIdInt == json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"))))
+					while (fgets((char*)dataLine, ARRAY_SIZE(dataLine), infile) != NULL)
 					{
-						if((tempstackLevelInt == json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"))) &&
-						   (strcmp(tempchargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose"))) == 0))
-						{
-							//DEBUG_INFO("update set chargingProfile to file -0\n");
-							if(ChargingProfileAdded == FALSE)
-							{
-								fprintf(outfile,"%s\n",payload);
-								ChargingProfileAdded = TRUE;
-							}
-						}
-						else
+						dataLine[strlen((char*)dataLine) - 1] = '\0'; // eat the newline fgets() stores
+
+						json_object *tmpChargingProfile;
+						tmpChargingProfile = json_tokener_parse((char*)dataLine);
+						if(!is_error(tmpChargingProfile))
 						{
-							if(tempstackLevelInt < json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel")))
-							{
-								if(ChargingProfileAdded == FALSE)
-								{
-									fprintf(outfile,"%s\n",buf);
-									fprintf(outfile,"%s\n",payload);
-									ChargingProfileAdded = TRUE;
-								}
-								else
-								{
-									fprintf(outfile,"%s\n",buf);
-								}
-							}
-							else
+							if(json_object_object_get(tmpChargingProfile, "chargingProfile") != NULL)
 							{
-								if(ChargingProfileAdded == FALSE)
+								if(json_object_object_get(json_object_object_get(tmpChargingProfile, "chargingProfile"), "id") != NULL)
 								{
-									fprintf(outfile,"%s\n",buf);
-									fprintf(outfile,"%s\n",payload);
-									ChargingProfileAdded = TRUE;
-								}
-								else
-								{
-									fprintf(outfile,"%s\n",buf);
+									tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "chargingProfile"), "id"));
+									DEBUG_INFO("tempchargingProfileIdInt: %d\n", tempchargingProfileIdInt);
+									DEBUG_INFO("SetProfileReq.chargingProfile.id: %d\n", SetProfileReq.chargingProfile.id);
 								}
 							}
 						}
-					}
-					else
-					{
-						if(tempchargingProfileIdInt < json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId")))
-						{
-							if(ChargingProfileAdded == FALSE)
-							{
-								fprintf(outfile,"%s\n",buf);
-								fprintf(outfile,"%s\n",payload);
-								ChargingProfileAdded = TRUE;
-							}
-							else
-							{
-								fprintf(outfile,"%s\n",buf);
-							}
-						}
-						else if(tempstackLevelInt < json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel")))
+						json_object_put(tmpChargingProfile);
+
+						if((tempchargingProfileIdInt == SetProfileReq.chargingProfile.id))
 						{
 							if(ChargingProfileAdded == FALSE)
 							{
-								fprintf(outfile,"%s\n",buf);
-								fprintf(outfile,"%s\n",payload);
+								if((strcmp((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_TxDefaultProfile]) == 0) && (SetProfileReq.evseId==0))
+									json_object_object_add(SetChargingProfile, "evseId", json_object_new_int(idxCon));
+								fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
 								ChargingProfileAdded = TRUE;
 							}
-							else
-							{
-								fprintf(outfile,"%s\n",buf);
-							}
 						}
 						else
 						{
+							fprintf(outfile,"%s\n",dataLine);
 							if(ChargingProfileAdded == FALSE)
 							{
-								fprintf(outfile,"%s\n",buf);
-								fprintf(outfile,"%s\n",payload);
+								if((strcmp((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_TxDefaultProfile]) == 0) && (SetProfileReq.evseId==0))
+									json_object_object_add(SetChargingProfile, "evseId", json_object_new_int(idxCon));
+								fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
 								ChargingProfileAdded = TRUE;
 							}
-							else
-							{
-								fprintf(outfile,"%s\n",buf);
-							}
 						}
-					}
-				} // end of while loop
+					} // end of while loop
 
-				fclose(infile);
-				fclose(outfile);
+					fclose(infile);
+					fclose(outfile);
 
-				sprintf(rmFileCmd,"rm -f %s",filename);
-				system(rmFileCmd);
+					sprintf(rmFileCmd,"rm -f %s",filename);
+					system(rmFileCmd);
 
-				rename((char*)tmpProfileName, (char*)filename);
+					rename((char*)tmpProfileName, (char*)filename);
+				}
 			}
 
-			sprintf((char*)ShmOCPP20Data->SetChargingProfile[(gun_index==0?gun_index:gun_index-1)].Response_status, "%s", ChargingProfileStatusEnumTypeStr[ChargingProfileStatusEnumType_Accepted] );
+			sleep(1);
+			sprintf((char*)ShmOCPP20Data->SetChargingProfile[(SetProfileReq.evseId==0?SetProfileReq.evseId:SetProfileReq.evseId-1)].Response_status, "%s", ChargingProfileStatusEnumTypeStr[ChargingProfileStatusEnumType_Accepted] );
 			result = PASS;
 		}
 		else
 		{
-			if(gun_index == -1)
+			if(isLostConnectorId)
 				DEBUG_WARN("Connector id is wrong.\n");
 
 			if(isConnectorMismatch)
@@ -15836,14 +15824,14 @@ int handleSetChargingProfileRequest(char *uuid, char *payload)
 			if(isProfileOverMax)
 				DEBUG_WARN("Profile quantity is over spec.\n");
 
-			sprintf((char*)ShmOCPP20Data->SetChargingProfile[(gun_index==0?gun_index:gun_index-1)].Response_status, "%s", ChargingProfileStatusEnumTypeStr[ChargingProfileStatusEnumType_Rejected] );
+			sprintf((char*)ShmOCPP20Data->SetChargingProfile[(SetProfileReq.evseId==0?SetProfileReq.evseId:SetProfileReq.evseId-1)].Response_status, "%s", ChargingProfileStatusEnumTypeStr[ChargingProfileStatusEnumType_Rejected] );
 		}
 	}
 	json_object_put(SetChargingProfile);
 
-	if(strcmp((char*)ShmOCPP20Data->SetChargingProfile[(gun_index==0?gun_index:gun_index-1)].Response_status, ChargingProfileStatusEnumTypeStr[ChargingProfileStatusEnumType_Accepted]) == 0)
+	if(strcmp((char*)ShmOCPP20Data->SetChargingProfile[(SetProfileReq.evseId==0?SetProfileReq.evseId:SetProfileReq.evseId-1)].Response_status, ChargingProfileStatusEnumTypeStr[ChargingProfileStatusEnumType_Accepted]) == 0)
 	{
-		if(gun_index == 0)
+		if(SetProfileReq.evseId == 0)
 		{
 			for(uint8_t idx=0;idx<gunTotalNumber;idx++)
 			{
@@ -15851,10 +15839,10 @@ int handleSetChargingProfileRequest(char *uuid, char *payload)
 			}
 		}
 		else
-			checkCompositeSchedule(gun_index, 86400, &ShmOCPP20Data->SmartChargingProfile[gun_index-1], 0, TRUE);
+			checkCompositeSchedule(SetProfileReq.evseId, 86400, &ShmOCPP20Data->SmartChargingProfile[SetProfileReq.evseId-1], 0, TRUE);
 	}
 
-	sendSetChargingProfileConfirmation(uuid, (gun_index==0?gun_index:gun_index-1));
+	sendSetChargingProfileConfirmation(uuid, (SetProfileReq.evseId==0?SetProfileReq.evseId:SetProfileReq.evseId-1));
 	system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
 	return result;
 }

文件差異過大導致無法顯示
+ 293 - 508
EVSE/Modularization/ocppfiles/MessageHandler.c


文件差異過大導致無法顯示
+ 286 - 509
EVSE/Modularization/ocppph/MessageHandler.c


部分文件因文件數量過多而無法顯示