Browse Source

2020-3-26 / Kathy Yeh
1. modify the logic of Clear Charging Profile's gun 0
2. modify the logic: dynamically naming charging Profile file name for different guns
3. add plug in logic : When system status is available and Connector Plug In,ocpp report Preparing status to OCPP Server

Kathy_Yeh 5 years ago
parent
commit
a97595cd60
1 changed files with 86 additions and 16 deletions
  1. 86 16
      EVSE/Modularization/ocppfiles/MessageHandler.c

+ 86 - 16
EVSE/Modularization/ocppfiles/MessageHandler.c

@@ -65,6 +65,18 @@
 #define LocalAuthorizationList_JSON		"/Storage/OCPP/LocalAuthorizationList.json"
 
 
+//===================================
+//	Define CP State constant
+//===================================
+#define CP_STATE_UNKNOWN			0
+#define CP_STATE_A					1
+#define CP_STATE_B					2
+#define CP_STATE_C					3
+#define CP_STATE_D					4
+#define CP_STATE_E					5
+#define CP_STATE_F					6
+
+
 struct SysConfigAndInfo			*ShmSysConfigAndInfo;
 struct StatusCodeData 			*ShmStatusCodeData;
 struct PsuData 					*ShmPsuData ;
@@ -2099,7 +2111,15 @@ S_FAULT                 =12
 		{
 			if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
 			{
-				currentStatus = 0; //OCPP Status: Available
+				if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
+				{
+					currentStatus = 1; //OCPP Status: Preparing
+				}
+				else
+				{
+					currentStatus = 0; //OCPP Status: Available
+				}
+
 			}
 			else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
 			{
@@ -2136,7 +2156,15 @@ S_FAULT                 =12
 		{
 			if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
 			{
-				currentStatus = 0; //OCPP Status: Available
+				if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
+				{
+					currentStatus = 1; //OCPP Status: Preparing
+				}
+				else
+				{
+					currentStatus = 0; //OCPP Status: Available
+				}
+
 			}
 			else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
 			{
@@ -2173,7 +2201,14 @@ S_FAULT                 =12
 		{
 			if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index) &&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
 			{
-				currentStatus = 0; //OCPP Status: Available
+				if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
+				{
+					currentStatus = 1; //OCPP Status: Preparing
+				}
+				else
+				{
+					currentStatus = 0; //OCPP Status: Available
+				}
 			}
 			else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index) &&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
 			{
@@ -2212,7 +2247,15 @@ S_FAULT                 =12
 		{
 			if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
 			{
-				currentStatus = 0; //OCPP Status: Available
+				if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B) ||(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_C) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_D))
+				{
+					currentStatus = 1; //OCPP Status: Preparing
+				}
+				else
+				{
+					currentStatus = 0; //OCPP Status: Available
+				}
+
 			}
 			else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
 			{
@@ -4503,14 +4546,19 @@ int handleClearChargingProfileRequest(char *uuid, char *payload)
 
 	if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
 	{
-		//clear file in C
-		sprintf(str,"rm -f %s",fname);
-		system(str);
-
+		memset(str, 0, sizeof str);
 		// clear temp file
 		sprintf(str,"rm -f %s",temp);
 		system(str);
 
+		for(int k=0; k < ChargeProfileCount; k++)
+		{
+			memset(str, 0, sizeof str);
+			//clear file in C
+			sprintf(str,"rm -f %s",chargingProfiles[k]);
+			system(str);
+		}
+
 		sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
 		goto end;
 	}
@@ -5772,7 +5820,7 @@ int handleGetCompositeScheduleRequest(char *uuid, char *payload)
 
 
   			//****************************TxDefaultProfile************************************************/
-
+#if 0
   			switch(connectorIdInt)
   			{
   			  	case 0:
@@ -5790,6 +5838,9 @@ int handleGetCompositeScheduleRequest(char *uuid, char *payload)
   			  		strcpy(fname, TxDefaultProfile_1_JSON );
   			  		break;
   			}
+#endif
+  			memset(fname, 0, sizeof fname);
+  			sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
 
   			TxDefaultProfileFileIsNull=TRUE;
   			if((access(fname,F_OK))!=-1)
@@ -6071,6 +6122,7 @@ int handleGetCompositeScheduleRequest(char *uuid, char *payload)
   			}// the end of ACCESS TxDefaultProfile
 
   			//****************************TxProfile************************************************/
+#if 0
   			switch(connectorIdInt)
   			{
   			  	case 0:
@@ -6088,6 +6140,9 @@ int handleGetCompositeScheduleRequest(char *uuid, char *payload)
   			  		strcpy(fname, TxProfile_1_JSON );
   			  		break;
   			}
+#endif
+  			memset(fname, 0, sizeof fname);
+  			sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
 
   			TxProfileIsNull=TRUE;
   			if((access(fname,F_OK))!=-1)
@@ -9014,7 +9069,6 @@ int handleSetChargingProfileRequest(char *uuid, char *payload)
 	}
 
 	//DEBUG_INFO("chargingSchedulePeriodCount=%d\n",chargingSchedulePeriodCount);
-	//DEBUG_INFO("handleSetChargingProfileRequest -13 -1\n");
 	//where = payload;
 	int templength = 0;
 	//int searchstart = 0;
@@ -9071,7 +9125,7 @@ int handleSetChargingProfileRequest(char *uuid, char *payload)
 		}
 
 		templength = templength + strlen("limit")+2+c;
-		//DEBUG_INFO("handleSetChargingProfileRequest -13 -3\n");
+
 		//****************numberPhases*******************/
 		loc = strstr(tempChargingProfile + templength, "numberPhases");
 		if(loc != NULL)
@@ -9103,7 +9157,7 @@ int handleSetChargingProfileRequest(char *uuid, char *payload)
 		//where = loc;
 
 	}
-	//DEBUG_INFO("handleSetChargingProfileRequest -14\n");
+
 	//****************chargingSchedulePeriod count end*******************/
 
 
@@ -9191,6 +9245,7 @@ int handleSetChargingProfileRequest(char *uuid, char *payload)
 			goto end;
 		}
 
+#if 0
 		switch(connectorIdInt)
 		{
 			case 0:
@@ -9209,6 +9264,9 @@ int handleSetChargingProfileRequest(char *uuid, char *payload)
 				strcpy(filename, TxDefaultProfile_0_JSON );
 				break;
 		}
+#endif
+		memset(filename, 0, sizeof filename);
+		sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
 
 		fptr1 = fopen(filename, "r");
 		if (!fptr1)
@@ -9301,7 +9359,7 @@ int handleSetChargingProfileRequest(char *uuid, char *payload)
 			goto end;
 		}
 
-
+#if 0
 		switch(connectorIdInt)
 		{
 			case 0:
@@ -9319,6 +9377,8 @@ int handleSetChargingProfileRequest(char *uuid, char *payload)
 				strcpy(filename, TxProfile_1_JSON);
 				break;
 		}
+#endif
+		sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
 
 		fptr1 = fopen(filename, "r");
 		if (!fptr1)
@@ -9353,7 +9413,7 @@ int handleSetChargingProfileRequest(char *uuid, char *payload)
 	}
 
 
-	// Check all Charging Files
+	//------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
 	{
 		int i = 0;
 	    char fnametemp[200]={0};
@@ -9463,7 +9523,10 @@ int handleSetChargingProfileRequest(char *uuid, char *payload)
 			goto end;
 		}
 
-	}// End connectorIsNULL is TRUE
+	}
+	//------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
+
+
 
 
 	//**********************************Write to File********************************************************/
@@ -15405,7 +15468,7 @@ void GetChargingProfileRequest(int gunindex)
 
 
 	  	//****************************TxDefaultProfile************************************************/
-
+#if 0
 	  	switch(gunindex + 1)
 	  	{
 	  		case 0:
@@ -15424,6 +15487,9 @@ void GetChargingProfileRequest(int gunindex)
 	  			  strcpy(fname, TxDefaultProfile_1_JSON );
 	  			  break;
 	  	}
+#endif
+	  	memset(fname, 0, sizeof fname);
+	  	sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", (gunindex + 1));
 
 	  	TxDefaultProfileFileIsNull=TRUE;
 	  	if((access(fname,F_OK))!=-1)
@@ -15838,6 +15904,7 @@ void GetChargingProfileRequest(int gunindex)
 	  			}// the end of ACCESS TxDefaultProfile
 
 	  			//****************************TxProfile************************************************/
+#if 0
 	  			switch(gunindex + 1)
 	  			{
 	  			  	case 0:
@@ -15855,6 +15922,9 @@ void GetChargingProfileRequest(int gunindex)
 	  			  		strcpy(fname, TxProfile_1_JSON );
 	  			  		break;
 	  			}
+#endif
+	  			memset(fname, 0, sizeof fname);
+	  			sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", (gunindex + 1));
 
 	  			TxProfileIsNull=TRUE;
 	  			if((access(fname,F_OK))!=-1)