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

[Imrpvoe][AW-Regular][main.c]
2022-03-14 / Eason Yang
Action:
1. Added: check charging point max proefile logic and compare with txProfile or txDefaultProfile.
2. Improve: getScheduleStart() function. Passing unsigned chart *time into function.

File:
1. main.c
Action 1
Action 2

FIRMWARE VERSION: V0.70.XX.XXXX.PX

8009 3 жил өмнө
parent
commit
c8cd265d05

+ 94 - 54
EVSE/Projects/AW-Regular/Apps/main.c

@@ -31,7 +31,7 @@
 #define TIMEOUT_SPEC_AUTH				15000
 #define TIMEOUT_SPEC_HANDSHAKING_LED	185000
 #define TIMEOUT_SPEC_LOGPPRINTOUT		30000
-#define TIMEOUT_SPEC_PROFILE_PREPARE	5000
+#define TIMEOUT_SPEC_PROFILE_PREPARE	60000
 #define TIMEOUT_SPEC_PWN_CHANGE			5000
 
 #define SPEC_TEMPERATURE_WARN			71
@@ -2657,7 +2657,6 @@ int upgrade_check()
 int isMatchStartUser(unsigned char gun_index)
 {
 	uint8_t tmpUser[32];
-	uint8_t isPrintLogOut = OFF;
 
 	if(ShmSysConfigAndInfo->SysConfig.RfidCardNumEndian)
 	{
@@ -2700,14 +2699,10 @@ int isMatchStartUser(unsigned char gun_index)
 		}
 	}
 
-	if(isPrintLogOut == OFF)
-	{
-		DEBUG_INFO("==== isMatchStartUser ==== \n");
-		DEBUG_INFO("tmpUser : %s \n", tmpUser);
-		DEBUG_INFO("StartUserId : %s \n", ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartUserId);
-		DEBUG_INFO("========================== \n");
-		isPrintLogOut = ON;
-	}
+	DEBUG_INFO("==== isMatchStartUser ==== \n");
+	DEBUG_INFO("tmpUser : %s \n", tmpUser);
+	DEBUG_INFO("StartUserId : %s \n", ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartUserId);
+	DEBUG_INFO("========================== \n");
 
 	return ((strcmp((char*)tmpUser, (char*)ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartUserId)==0)?YES:NO);
 }
@@ -3124,7 +3119,7 @@ int isProfileValid(uint8_t gun_index)
 	return result;
 }
 
-int getScheduleStart(int gun_index)
+int getScheduleStart(unsigned char *time)
 {
 	int result = -1;
 	struct tm tmScheduleStart;;
@@ -3132,7 +3127,8 @@ int getScheduleStart(int gun_index)
 
 	if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
 	{
-		if((sscanf((char*)ShmOCPP16Data->SmartChargingProfile[gun_index].ChargingSchedule.StartSchedule, "%4d-%2d-%2dT%2d:%2d:%2d", &tmScheduleStart.tm_year, &tmScheduleStart.tm_mon, &tmScheduleStart.tm_mday, &tmScheduleStart.tm_hour, &tmScheduleStart.tm_min, &tmScheduleStart.tm_sec) == 6))
+		// ShmOCPP16Data->SmartChargingProfile[gun_index].ChargingSchedule.StartSchedule
+		if((sscanf((char*)time, "%4d-%2d-%2dT%2d:%2d:%2d", &tmScheduleStart.tm_year, &tmScheduleStart.tm_mon, &tmScheduleStart.tm_mday, &tmScheduleStart.tm_hour, &tmScheduleStart.tm_min, &tmScheduleStart.tm_sec) == 6))
 		{
 			tmScheduleStart.tm_year -= 1900;
 			tmScheduleStart.tm_mon -= 1;
@@ -3149,7 +3145,8 @@ int getScheduleStart(int gun_index)
 	}
 	else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
 	{
-		if((sscanf((char*)ShmOCPP20Data->SmartChargingProfile[gun_index].chargingSchedule[0].startSchedule, "%4d-%2d-%2dT%2d:%2d:%2d", &tmScheduleStart.tm_year, &tmScheduleStart.tm_mon, &tmScheduleStart.tm_mday, &tmScheduleStart.tm_hour, &tmScheduleStart.tm_min, &tmScheduleStart.tm_sec) == 6))
+		// ShmOCPP20Data->SmartChargingProfile[gun_index].chargingSchedule[0].startSchedule
+		if((sscanf((char*)time, "%4d-%2d-%2dT%2d:%2d:%2d", &tmScheduleStart.tm_year, &tmScheduleStart.tm_mon, &tmScheduleStart.tm_mday, &tmScheduleStart.tm_hour, &tmScheduleStart.tm_min, &tmScheduleStart.tm_sec) == 6))
 		{
 			tmScheduleStart.tm_year -= 1900;
 			tmScheduleStart.tm_mon -= 1;
@@ -3536,19 +3533,13 @@ void checkAvailability(uint8_t gun_index)
 
 void checkChargingProfileLimit(uint8_t gun_index, uint8_t system_mode)
 {
-	/*
-	static struct PreviousData
-	{
-		uint16_t targetCurrent;
-		uint16_t current_limit;
-		uint16_t primaryMcuCp_Pwn_Duty;
-	}previousData[4];
-	*/
-
+	uint16_t MaxChargingProfileChargingCurrent = ShmCharger->gun_info[gun_index].primaryMcuState.rating_current;
 	if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
 	{
+		//========================================
+		// Check TxProfile and TxDefaultProfile
+		//========================================
 		if((ocpp_get_smartcharging_profileId(gun_index) > 0) &&
-		   //(ocpp_get_profile_req(gun_index) != ON) &&
 		   (((strlen((char*)ShmOCPP16Data->SmartChargingProfile[gun_index].ValidFrom)>0) && (strlen((char*)ShmOCPP16Data->SmartChargingProfile[gun_index].ValidTo)>0)) ? isProfileValid(gun_index) : ON))
 		{
 			// Debug information
@@ -3572,35 +3563,60 @@ void checkChargingProfileLimit(uint8_t gun_index, uint8_t system_mode)
 			// Checking profile kind
 			if((mystrcmp((char*)ShmOCPP16Data->SmartChargingProfile[gun_index].ChargingProfileKind, "Absolute") == PASS))
 			{
-				// Absolute profile
-				if(((mystrcmp((char*)ShmOCPP16Data->SmartChargingProfile[gun_index].ChargingProfilePurpose, "TxProfile") == PASS) && (ShmOCPP16Data->SmartChargingProfile[gun_index].TransactionId == ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId)) ||
-					(mystrcmp((char*)ShmOCPP16Data->SmartChargingProfile[gun_index].ChargingProfilePurpose, "TxProfile") == FAIL))
+				// Checking limitation
+				for(uint8_t idx_period=0;idx_period<ARRAY_SIZE(ShmOCPP16Data->SmartChargingProfile[gun_index].ChargingSchedule.ChargingSchedulePeriod);idx_period++)
 				{
-					// Checking limitation
-					for(uint8_t idx_period=0;idx_period<ARRAY_SIZE(ShmOCPP16Data->SmartChargingProfile[gun_index].ChargingSchedule.ChargingSchedulePeriod);idx_period++)
+					if((getScheduleStart(ShmOCPP16Data->SmartChargingProfile[gun_index].ChargingSchedule.StartSchedule) >= ShmOCPP16Data->SmartChargingProfile[gun_index].ChargingSchedule.ChargingSchedulePeriod[idx_period].StartPeriod) &&
+					   ((idx_period == 0) || (ShmOCPP16Data->SmartChargingProfile[gun_index].ChargingSchedule.ChargingSchedulePeriod[idx_period].StartPeriod > 0))
+					  )
 					{
-						if((getScheduleStart(gun_index) > ShmOCPP16Data->SmartChargingProfile[gun_index].ChargingSchedule.ChargingSchedulePeriod[idx_period].StartPeriod) &&
-						   ((idx_period == 0) || (ShmOCPP16Data->SmartChargingProfile[gun_index].ChargingSchedule.ChargingSchedulePeriod[idx_period].StartPeriod > 0))
-						  )
-						{
-							ShmCharger->gun_info[gun_index].targetCurrent = (mystrcmp((char*)ShmOCPP16Data->SmartChargingProfile[gun_index].ChargingSchedule.ChargingRateUnit,"W")==PASS?ShmOCPP16Data->SmartChargingProfile[gun_index].ChargingSchedule.ChargingSchedulePeriod[idx_period].Limit/(220*ShmOCPP16Data->SmartChargingProfile[gun_index].ChargingSchedule.ChargingSchedulePeriod[idx_period].NumberPhases):ShmOCPP16Data->SmartChargingProfile[gun_index].ChargingSchedule.ChargingSchedulePeriod[idx_period].Limit);
-							//DEBUG_INFO("ShmCharger->gun_info[%d].targetCurrent on period[%d]: %d\n", gun_index, idx_period, ShmCharger->gun_info[gun_index].targetCurrent);
-						}
-						else
-							break;
+						ShmCharger->gun_info[gun_index].targetCurrent = (mystrcmp((char*)ShmOCPP16Data->SmartChargingProfile[gun_index].ChargingSchedule.ChargingRateUnit,"W")==PASS?ShmOCPP16Data->SmartChargingProfile[gun_index].ChargingSchedule.ChargingSchedulePeriod[idx_period].Limit/(220*ShmOCPP16Data->SmartChargingProfile[gun_index].ChargingSchedule.ChargingSchedulePeriod[idx_period].NumberPhases):ShmOCPP16Data->SmartChargingProfile[gun_index].ChargingSchedule.ChargingSchedulePeriod[idx_period].Limit);
+						//DEBUG_INFO("ShmCharger->gun_info[%d].targetCurrent on period[%d]: %d\n", gun_index, idx_period, ShmCharger->gun_info[gun_index].targetCurrent);
 					}
+					else
+						break;
 				}
 			}
 		}
-		else if((ShmOCPP16Data->SmartChargingProfile[gun_index].ChargingProfileId == 0))//&& (ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq != ON))
+		else if((ShmOCPP16Data->SmartChargingProfile[gun_index].ChargingProfileId == 0))
 		{
 			ShmCharger->gun_info[gun_index].targetCurrent = ShmCharger->gun_info[gun_index].primaryMcuState.rating_current;
 		}
+
+		//========================================
+		// Check ChargingPointMaxProfile
+		//========================================
+		if(ShmOCPP16Data->MaxChargingProfile.ChargingProfileId > 0)
+		{
+			// Absolute profile
+			if((mystrcmp((char*)ShmOCPP16Data->MaxChargingProfile.ChargingProfileKind, "Absolute") == PASS))
+			{		
+				for(uint8_t idx_period=0;idx_period<ARRAY_SIZE(ShmOCPP16Data->MaxChargingProfile.ChargingSchedule.ChargingSchedulePeriod);idx_period++)
+				{
+					if((getScheduleStart(ShmOCPP16Data->MaxChargingProfile.ChargingSchedule.StartSchedule) >= ShmOCPP16Data->MaxChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idx_period].StartPeriod) &&
+					   ((idx_period == 0) || (ShmOCPP16Data->MaxChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idx_period].StartPeriod > 0))
+					  )
+					{
+						MaxChargingProfileChargingCurrent = (mystrcmp((char*)ShmOCPP16Data->MaxChargingProfile.ChargingSchedule.ChargingRateUnit,"W")==PASS?ShmOCPP16Data->MaxChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idx_period].Limit/(220*ShmOCPP16Data->MaxChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idx_period].NumberPhases):ShmOCPP16Data->MaxChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idx_period].Limit);
+						//DEBUG_INFO("ShmCharger->gun_info[%d].targetCurrent on period[%d]: %d\n", gun_index, idx_period, ShmCharger->gun_info[gun_index].targetCurrent);
+					}
+					else
+						break;
+				}
+			}
+
+			if(ShmCharger->gun_info[gun_index].targetCurrent > MaxChargingProfileChargingCurrent)
+			{
+				ShmCharger->gun_info[gun_index].targetCurrent = MaxChargingProfileChargingCurrent;
+			}
+		}
 	}
 	else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
 	{
+		//========================================
+		// Check TxProfile and TxDefaultProfile
+		//========================================
 		if((ocpp_get_smartcharging_profileId(gun_index) > 0) &&
-		   //(ocpp_get_profile_req(gun_index) != ON) &&
 		   (((strlen((char*)ShmOCPP20Data->SmartChargingProfile[gun_index].validFrom)>0) && (strlen((char*)ShmOCPP20Data->SmartChargingProfile[gun_index].validTo)>0)) ? isProfileValid(gun_index) : ON))
 		{
 			// Debug information
@@ -3624,30 +3640,54 @@ void checkChargingProfileLimit(uint8_t gun_index, uint8_t system_mode)
 			// Checking profile kind
 			if((mystrcmp((char*)ShmOCPP20Data->SmartChargingProfile[gun_index].chargingProfileKind, "Absolute") == PASS))
 			{
-				// Absolute profile
-				if(((mystrcmp((char*)ShmOCPP20Data->SmartChargingProfile[gun_index].chargingProfilePurpose, "TxProfile") == PASS) && (ShmOCPP20Data->SmartChargingProfile[gun_index].transactionId == ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId)) ||
-					(mystrcmp((char*)ShmOCPP20Data->SmartChargingProfile[gun_index].chargingProfilePurpose, "TxProfile") == FAIL))
+				// Checking limitation
+				for(uint8_t idx_period=0;idx_period<ARRAY_SIZE(ShmOCPP20Data->SmartChargingProfile[gun_index].chargingSchedule[0].chargingSchedulePeriod);idx_period++)
 				{
-					// Checking limitation
-					for(uint8_t idx_period=0;idx_period<ARRAY_SIZE(ShmOCPP20Data->SmartChargingProfile[gun_index].chargingSchedule[0].chargingSchedulePeriod);idx_period++)
+					if((getScheduleStart(ShmOCPP20Data->SmartChargingProfile[gun_index].chargingSchedule[0].startSchedule) >= ShmOCPP20Data->SmartChargingProfile[gun_index].chargingSchedule[0].chargingSchedulePeriod[idx_period].startPeriod) &&
+					   ((idx_period == 0) || (ShmOCPP20Data->SmartChargingProfile[gun_index].chargingSchedule[0].chargingSchedulePeriod[idx_period].startPeriod > 0))
+					  )
 					{
-						if((getScheduleStart(gun_index) > ShmOCPP20Data->SmartChargingProfile[gun_index].chargingSchedule[0].chargingSchedulePeriod[idx_period].startPeriod) &&
-						   ((idx_period == 0) || (ShmOCPP20Data->SmartChargingProfile[gun_index].chargingSchedule[0].chargingSchedulePeriod[idx_period].startPeriod > 0))
-						  )
-						{
-							ShmCharger->gun_info[gun_index].targetCurrent = (mystrcmp((char*)ShmOCPP20Data->SmartChargingProfile[gun_index].chargingSchedule[0].chargingRateUnit,"W")==PASS?ShmOCPP20Data->SmartChargingProfile[gun_index].chargingSchedule[0].chargingSchedulePeriod[idx_period].limit/(220*ShmOCPP20Data->SmartChargingProfile[gun_index].chargingSchedule[0].chargingSchedulePeriod[idx_period].numberPhases):ShmOCPP20Data->SmartChargingProfile[gun_index].chargingSchedule[0].chargingSchedulePeriod[idx_period].limit);
-							//DEBUG_INFO("ShmCharger->gun_info[%d].targetCurrent on period[%d]: %d\n", gun_index, idx_period, ShmCharger->gun_info[gun_index].targetCurrent);
-						}
-						else
-							break;
+						ShmCharger->gun_info[gun_index].targetCurrent = (mystrcmp((char*)ShmOCPP20Data->SmartChargingProfile[gun_index].chargingSchedule[0].chargingRateUnit,"W")==PASS?ShmOCPP20Data->SmartChargingProfile[gun_index].chargingSchedule[0].chargingSchedulePeriod[idx_period].limit/(220*ShmOCPP20Data->SmartChargingProfile[gun_index].chargingSchedule[0].chargingSchedulePeriod[idx_period].numberPhases):ShmOCPP20Data->SmartChargingProfile[gun_index].chargingSchedule[0].chargingSchedulePeriod[idx_period].limit);
+						//DEBUG_INFO("ShmCharger->gun_info[%d].targetCurrent on period[%d]: %d\n", gun_index, idx_period, ShmCharger->gun_info[gun_index].targetCurrent);
 					}
+					else
+						break;
 				}
 			}
 		}
-		else if((ShmOCPP20Data->SmartChargingProfile[gun_index].id == 0))// && (ShmOCPP20Data->CSUMsg.bits[gun_index].ChargingProfileReq != ON))
+		else if((ShmOCPP20Data->SmartChargingProfile[gun_index].id == 0))
 		{
 			ShmCharger->gun_info[gun_index].targetCurrent = ShmCharger->gun_info[gun_index].primaryMcuState.rating_current;
 		}
+
+		//========================================
+		// Check ChargingPointMaxProfile
+		//========================================
+		if(ShmOCPP20Data->MaxChargingProfile.id > 0)
+		{
+			// Absolute profile
+			if((mystrcmp((char*)ShmOCPP20Data->MaxChargingProfile.chargingProfileKind, "Absolute") == PASS))
+			{
+				// Checking limitation
+				for(uint8_t idx_period=0;idx_period<ARRAY_SIZE(ShmOCPP20Data->MaxChargingProfile.chargingSchedule[0].chargingSchedulePeriod);idx_period++)
+				{
+					if((getScheduleStart(ShmOCPP20Data->MaxChargingProfile.chargingSchedule[0].startSchedule) >= ShmOCPP20Data->MaxChargingProfile.chargingSchedule[0].chargingSchedulePeriod[idx_period].startPeriod) &&
+					   ((idx_period == 0) || (ShmOCPP20Data->MaxChargingProfile.chargingSchedule[0].chargingSchedulePeriod[idx_period].startPeriod > 0))
+					  )
+					{
+						MaxChargingProfileChargingCurrent = (mystrcmp((char*)ShmOCPP20Data->MaxChargingProfile.chargingSchedule[0].chargingRateUnit,"W")==PASS?ShmOCPP20Data->MaxChargingProfile.chargingSchedule[0].chargingSchedulePeriod[idx_period].limit/(220*ShmOCPP20Data->MaxChargingProfile.chargingSchedule[0].chargingSchedulePeriod[idx_period].numberPhases):ShmOCPP20Data->MaxChargingProfile.chargingSchedule[0].chargingSchedulePeriod[idx_period].limit);
+						//DEBUG_INFO("ShmCharger->gun_info[%d].targetCurrent on period[%d]: %d\n", gun_index, idx_period, ShmCharger->gun_info[gun_index].targetCurrent);
+					}
+					else
+						break;
+				}
+			}
+
+			if(ShmCharger->gun_info[gun_index].targetCurrent > MaxChargingProfileChargingCurrent)
+			{
+				ShmCharger->gun_info[gun_index].targetCurrent = MaxChargingProfileChargingCurrent;
+			}
+		}
 	}
 
 	switch(system_mode)