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

[Improve][Modularization][Module_OcppBackend / Module_OcppBackendPH / Module_OcppBackend20]

2022.03.04 / Folus Wen

Actions:
1. Getcomposite_Schedule fucntion bug fix.

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 жил өмнө
parent
commit
a915a9ea00

+ 348 - 62
EVSE/Modularization/ocpp20/MessageHandler.c

@@ -3450,28 +3450,180 @@ int DiffTimebWithNowSec(struct timeb ST)
 
 int getStartStop(uint8_t *start, uint8_t *stop)
 {
+	struct ParsingResult
+	{
+		int result;
+		int scanedElement;
+		int year;
+		int month;
+		int mday;
+		int hour;
+		int min;
+		int sec;
+		int tz_hour;
+		int tz_min;
+		float minSec;
+	};
+
+	struct ParsingResult parseStart;
+	struct ParsingResult parseStop;
+
 	int result = -1;
 	struct tm tmStart;
 	struct timeb tbStart;
 	struct tm tmStop;
 	struct timeb tbStop;
 
+	memset(&parseStart, 0x00, sizeof(struct ParsingResult));
+	memset(&parseStop, 0x00, sizeof(struct ParsingResult));
 
-	if((sscanf((char*)start, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStart.tm_year, &tmStart.tm_mon, &tmStart.tm_mday, &tmStart.tm_hour, &tmStart.tm_min, &tmStart.tm_sec) == 6) &&
-	   (sscanf((char*)stop, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStop.tm_year, &tmStop.tm_mon, &tmStop.tm_mday, &tmStop.tm_hour, &tmStop.tm_min, &tmStop.tm_sec) == 6))
+	// Scan start & stop date time
+	if(strstr((char*)start, ".") != NULL)
 	{
-		//DEBUG_INFO("Start: %d-%d-%d %d:%d:%d\n", tmStart.tm_year, tmStart.tm_mon, tmStart.tm_mday, tmStart.tm_hour, tmStart.tm_min, tmStart.tm_sec);
-		//DEBUG_INFO("Stop: %d-%d-%d %d:%d:%d\n", tmStop.tm_year, tmStop.tm_mon, tmStop.tm_mday, tmStop.tm_hour, tmStop.tm_min, tmStop.tm_sec);
+		// Original data with mini second
+		if(strstr((char*)start, "Z") != NULL)
+		{
+			// Original data with Z
+			parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
+														&parseStart.year,
+														&parseStart.month,
+														&parseStart.mday,
+														&parseStart.hour,
+														&parseStart.min,
+														&parseStart.sec,
+														&parseStart.minSec);
+		}
+		else
+		{
+			// Original data without Z
+			parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
+														&parseStart.year,
+														&parseStart.month,
+														&parseStart.mday,
+														&parseStart.hour,
+														&parseStart.min,
+														&parseStart.sec,
+														&parseStart.minSec,
+														&parseStart.tz_hour,
+														&parseStart.tz_min);
+		}
+	}
+	else
+	{
+		// Original data without mini second
+		if(strstr((char*)start, "Z") != NULL)
+		{
+			// Original data with Z
+			parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
+														&parseStart.year,
+														&parseStart.month,
+														&parseStart.mday,
+														&parseStart.hour,
+														&parseStart.min,
+														&parseStart.sec);
+		}
+		else
+		{
+			// Original data without Z
+			parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
+														&parseStart.year,
+														&parseStart.month,
+														&parseStart.mday,
+														&parseStart.hour,
+														&parseStart.min,
+														&parseStart.sec,
+														&parseStart.tz_hour,
+														&parseStart.tz_min);
+		}
+	}
 
-		tmStart.tm_year -= 1900;
-		tmStart.tm_mon -= 1;
+	if(strstr((char*)stop, ".") != NULL)
+	{
+		// Original data with mini second
+		if(strstr((char*)stop, "Z") != NULL)
+		{
+			// Original data with Z
+			parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%fZ",
+														&parseStop.year,
+														&parseStop.month,
+														&parseStop.mday,
+														&parseStop.hour,
+														&parseStop.min,
+														&parseStop.sec,
+														&parseStop.minSec);
+		}
+		else
+		{
+			// Original data without Z
+			parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%f%d:%d",
+														&parseStop.year,
+														&parseStop.month,
+														&parseStop.mday,
+														&parseStop.hour,
+														&parseStop.min,
+														&parseStop.sec,
+														&parseStop.minSec,
+														&parseStop.tz_hour,
+														&parseStop.tz_min);
+		}
+	}
+	else
+	{
+		// Original data without mini second
+		if(strstr((char*)stop, "Z") != NULL)
+		{
+			// Original data with Z
+			parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%dZ",
+														&parseStop.year,
+														&parseStop.month,
+														&parseStop.mday,
+														&parseStop.hour,
+														&parseStop.min,
+														&parseStop.sec);
+		}
+		else
+		{
+			// Original data without Z
+			parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d%d:%d",
+														&parseStop.year,
+														&parseStop.month,
+														&parseStop.mday,
+														&parseStop.hour,
+														&parseStop.min,
+														&parseStop.sec,
+														&parseStop.tz_hour,
+														&parseStop.tz_min);
+		}
+	}
+
+	// Calculate date time difference
+	if((parseStart.scanedElement >=6) &&
+	   (parseStop.scanedElement >=6))
+	{
+		//DEBUG_INFO("Start: %04d-%02d-%02d %02d:%02d:%02d(%02d:%02d)\n", parseStart.year, parseStart.month, parseStart.mday, parseStart.hour, parseStart.min, parseStart.sec, parseStart.tz_hour, parseStart.tz_min);
+		//DEBUG_INFO("Stop: %04d-%02d-%02d %02d:%02d:%02d(%02d:%02d)\n", parseStop.year, parseStop.month, parseStop.mday, parseStop.hour, parseStop.min, parseStop.sec, parseStop.tz_hour, parseStop.tz_min);
+
+		tmStart.tm_year = parseStart.year - 1900;
+		tmStart.tm_mon = parseStart.month - 1;
+		tmStart.tm_mday = parseStart.mday;
+		tmStart.tm_hour = parseStart.hour;
+		tmStart.tm_min = parseStart.min;
+		tmStart.tm_sec = parseStart.sec;
+		tmStart.tm_gmtoff = 0;
 		tbStart.time = mktime(&tmStart);
-		tbStart.millitm = 0;
-
-		tmStop.tm_year -= 1900;
-		tmStop.tm_mon -= 1;
+		tbStart.timezone = 0;
+		tbStart.time -= (parseStart.tz_hour*3600) + (parseStart.tz_min*60*(parseStart.tz_hour>=0?1:-1));
+
+		tmStop.tm_year = parseStop.year - 1900;
+		tmStop.tm_mon = parseStop.month - 1;
+		tmStop.tm_mday = parseStop.mday;
+		tmStop.tm_hour = parseStop.hour;
+		tmStop.tm_min = parseStop.min;
+		tmStop.tm_sec = parseStop.sec;
+		tmStop.tm_gmtoff = 0;
 		tbStop.time = mktime(&tmStop);
-		tbStop.millitm = 0;
+		tbStop.timezone = 0;
+		tbStop.time -= (parseStop.tz_hour*3600) + (parseStop.tz_min*60*(parseStop.tz_hour>=0?1:-1));
 
 		result = DiffTimebSec(tbStart, tbStop);
 
@@ -3598,26 +3750,189 @@ int isOvertNow(uint8_t *start)
 
 int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
 {
+	struct ParsingResult
+	{
+		int result;
+		int scanedElement;
+		int year;
+		int month;
+		int mday;
+		int hour;
+		int min;
+		int sec;
+		int tz_hour;
+		int tz_min;
+		float minSec;
+	};
+
+	struct ParsingResult parseStart;
+	struct ParsingResult parseStop;
+
 	int result = -1;
 	struct tm tmStart;
 	struct timeb tbStart;
 	struct tm tmStop;
 	struct timeb tbStop;
 
-	if((sscanf((char*)start, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStart.tm_year, &tmStart.tm_mon, &tmStart.tm_mday, &tmStart.tm_hour, &tmStart.tm_min, &tmStart.tm_sec) == 6) &&
-	   (sscanf((char*)stop, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStop.tm_year, &tmStop.tm_mon, &tmStop.tm_mday, &tmStop.tm_hour, &tmStop.tm_min, &tmStop.tm_sec) == 6))
+	memset(&parseStart, 0x00, sizeof(struct ParsingResult));
+	memset(&parseStop, 0x00, sizeof(struct ParsingResult));
+
+	// Scan start & stop date time
+	if(strstr((char*)start, ".") != NULL)
 	{
-		tmStart.tm_year -= 1900;
-		tmStart.tm_mon -= 1;
-		tbStart.time = mktime(&tmStart);
-		tbStart.millitm = 0;
+		// Original data with mini second
+		if(strstr((char*)start, "Z") != NULL)
+		{
+			// Original data with Z
+			parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
+														&parseStart.year,
+														&parseStart.month,
+														&parseStart.mday,
+														&parseStart.hour,
+														&parseStart.min,
+														&parseStart.sec,
+														&parseStart.minSec);
+		}
+		else
+		{
+			// Original data without Z
+			parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
+														&parseStart.year,
+														&parseStart.month,
+														&parseStart.mday,
+														&parseStart.hour,
+														&parseStart.min,
+														&parseStart.sec,
+														&parseStart.minSec,
+														&parseStart.tz_hour,
+														&parseStart.tz_min);
+		}
+	}
+	else
+	{
+		// Original data without mini second
+		if(strstr((char*)start, "Z") != NULL)
+		{
+			// Original data with Z
+			parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
+														&parseStart.year,
+														&parseStart.month,
+														&parseStart.mday,
+														&parseStart.hour,
+														&parseStart.min,
+														&parseStart.sec);
+		}
+		else
+		{
+			// Original data without Z
+			parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
+														&parseStart.year,
+														&parseStart.month,
+														&parseStart.mday,
+														&parseStart.hour,
+														&parseStart.min,
+														&parseStart.sec,
+														&parseStart.tz_hour,
+														&parseStart.tz_min);
+		}
+	}
 
-		tmStop.tm_year -= 1900;
-		tmStop.tm_mon -= 1;
+	if(strstr((char*)stop, ".") != NULL)
+	{
+		// Original data with mini second
+		if(strstr((char*)stop, "Z") != NULL)
+		{
+			// Original data with Z
+			parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%fZ",
+														&parseStop.year,
+														&parseStop.month,
+														&parseStop.mday,
+														&parseStop.hour,
+														&parseStop.min,
+														&parseStop.sec,
+														&parseStop.minSec);
+		}
+		else
+		{
+			// Original data without Z
+			parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%f%d:%d",
+														&parseStop.year,
+														&parseStop.month,
+														&parseStop.mday,
+														&parseStop.hour,
+														&parseStop.min,
+														&parseStop.sec,
+														&parseStop.minSec,
+														&parseStop.tz_hour,
+														&parseStop.tz_min);
+		}
+	}
+	else
+	{
+		// Original data without mini second
+		if(strstr((char*)stop, "Z") != NULL)
+		{
+			// Original data with Z
+			parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%dZ",
+														&parseStop.year,
+														&parseStop.month,
+														&parseStop.mday,
+														&parseStop.hour,
+														&parseStop.min,
+														&parseStop.sec);
+		}
+		else
+		{
+			// Original data without Z
+			parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d%d:%d",
+														&parseStop.year,
+														&parseStop.month,
+														&parseStop.mday,
+														&parseStop.hour,
+														&parseStop.min,
+														&parseStop.sec,
+														&parseStop.tz_hour,
+														&parseStop.tz_min);
+		}
+	}
+
+	// Calculate date time difference
+	if((parseStart.scanedElement >=6) &&
+	   (parseStop.scanedElement >=6))
+	{
+		//DEBUG_INFO("Start: %04d-%02d-%02d %02d:%02d:%02d(%02d:%02d)\n", parseStart.year, parseStart.month, parseStart.mday, parseStart.hour, parseStart.min, parseStart.sec, parseStart.tz_hour, parseStart.tz_min);
+		//DEBUG_INFO("Stop: %04d-%02d-%02d %02d:%02d:%02d(%02d:%02d)\n", parseStop.year, parseStop.month, parseStop.mday, parseStop.hour, parseStop.min, parseStop.sec, parseStop.tz_hour, parseStop.tz_min);
+
+		tmStart.tm_year = parseStart.year - 1900;
+		tmStart.tm_mon = parseStart.month - 1;
+		tmStart.tm_mday = parseStart.mday;
+		tmStart.tm_hour = parseStart.hour;
+		tmStart.tm_min = parseStart.min;
+		tmStart.tm_sec = parseStart.sec;
+		tmStart.tm_gmtoff = 0;
+		tbStart.time = mktime(&tmStart);
+		tbStart.timezone = 0;
+		tbStart.time -= (parseStart.tz_hour*3600) + (parseStart.tz_min*60*(parseStart.tz_hour>=0?1:-1));
+
+		tmStop.tm_year = parseStop.year - 1900;
+		tmStop.tm_mon = parseStop.month - 1;
+		tmStop.tm_mday = parseStop.mday;
+		tmStop.tm_hour = parseStop.hour;
+		tmStop.tm_min = parseStop.min;
+		tmStop.tm_sec = parseStop.sec;
+		tmStop.tm_gmtoff = 0;
 		tbStop.time = mktime(&tmStop);
-		tbStop.millitm = 0;
+		tbStop.timezone = 0;
+		tbStop.time -= (parseStop.tz_hour*3600) + (parseStop.tz_min*60*(parseStop.tz_hour>=0?1:-1));
 
 		result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
+
+		//DEBUG_INFO("getStartStop(): %d\n", result);
+
+	}
+	else
+	{
+		DEBUG_WARN("Start or stop date parsing error.\r\n");
 	}
 
 	return result;
@@ -3710,8 +4025,6 @@ void checkChargePointMaxProfile(uint32_t durationReq, struct ChargingProfileType
 									maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = -1;
 									maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 3;
 								}
-								maxProfile.id = -1;
-								maxProfile.stackLevel = -1;
 
 								if(maxProfile.id == -1)
 									DEBUG_INFO("MaxProfile found.\n");
@@ -3824,8 +4137,6 @@ void checkChargePointMaxProfile(uint32_t durationReq, struct ChargingProfileType
 							maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = -1;
 							maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 3;
 						}
-						maxProfile.id = -1;
-						maxProfile.stackLevel = -1;
 
 						if(maxProfile.id == -1)
 							DEBUG_INFO("MaxProfile found.\n");
@@ -4082,7 +4393,7 @@ void checkChargePointMaxProfile(uint32_t durationReq, struct ChargingProfileType
 		DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
 		DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.recurrencyKind);
 
-		DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
+		DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
 		DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.chargingSchedule[idxSchedule].Duration);
 		DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.chargingSchedule[idxSchedule].ChargingRateUnit);
 		DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.chargingSchedule[idxSchedule].MinChargingRate);
@@ -4256,8 +4567,6 @@ void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct Ch
 									txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 3;
 									txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].phaseToUse = 0;
 								}
-								txProfile.id = -1;
-								txProfile.stackLevel = -1;
 
 								if(txProfile.id == -1)
 									DEBUG_INFO("TxProfile found.\n");
@@ -4370,8 +4679,6 @@ void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct Ch
 							txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 3;
 							txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].phaseToUse = 0;
 						}
-						txProfile.id = -1;
-						txProfile.stackLevel = -1;
 
 						if(txProfile.id == -1)
 							DEBUG_INFO("TxProfile found.\n");
@@ -4560,8 +4867,6 @@ void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct Ch
 									defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 3;
 									defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].phaseToUse = 0;
 								}
-								defaultTxProfile.id = -1;
-								defaultTxProfile.stackLevel = -1;
 
 								if(defaultTxProfile.id == -1)
 									DEBUG_INFO("TxDefaultProfile found.\n");
@@ -4674,8 +4979,6 @@ void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct Ch
 							defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 3;
 							defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].phaseToUse = 0;
 						}
-						defaultTxProfile.id = -1;
-						defaultTxProfile.stackLevel = -1;
 
 						if(defaultTxProfile.id == -1)
 							DEBUG_INFO("TxDefaultProfile found.\n");
@@ -4861,8 +5164,6 @@ void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct Ch
 									maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = -1;
 									maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 3;
 								}
-								maxProfile.id = -1;
-								maxProfile.stackLevel = -1;
 
 								if(maxProfile.id == -1)
 									DEBUG_INFO("MaxProfile found.\n");
@@ -4975,8 +5276,6 @@ void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct Ch
 							maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = -1;
 							maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 3;
 						}
-						maxProfile.id = -1;
-						maxProfile.stackLevel = -1;
 
 						if(maxProfile.id == -1)
 							DEBUG_INFO("MaxProfile found.\n");
@@ -5248,7 +5547,7 @@ void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct Ch
 		DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
 		DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.recurrencyKind);
 
-		DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
+		DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
 		DEBUG_INFO("Profile schedule duration: %d\n", txProfile.chargingSchedule[idxSchedule].Duration);
 		DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.chargingSchedule[idxSchedule].ChargingRateUnit);
 		DEBUG_INFO("Profile charging min rate: %f\n", txProfile.chargingSchedule[idxSchedule].MinChargingRate);
@@ -5283,11 +5582,6 @@ void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct Ch
 																								 0:
 																								 (defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule)));
 
-					if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod < txProfile.chargingSchedule[idxSchedule].duration)
-					{
-						defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod += (txProfile.chargingSchedule[idxSchedule].duration-defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod);
-					}
-
 					if(idxPeriod > 0)
 					{
 						if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
@@ -5315,11 +5609,6 @@ void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct Ch
 																																																												0:
 																																																											   (defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(ShmOCPP20Data->TransactionEvent[(connectorId==0?0:connectorId-1)].timestamp, compositeProfile.chargingSchedule[idxSchedule].startSchedule)));
 
-					if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod < txProfile.chargingSchedule[idxSchedule].duration)
-					{
-						defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod += (txProfile.chargingSchedule[idxSchedule].duration-defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod);
-					}
-
 					if(idxPeriod > 0)
 					{
 						if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
@@ -5349,11 +5638,6 @@ void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct Ch
 																									 0:
 																									 (defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE)));
 
-						if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod < txProfile.chargingSchedule[idxSchedule].duration)
-						{
-							defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod += (txProfile.chargingSchedule[idxSchedule].duration-defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod);
-						}
-
 						if(idxPeriod > 0)
 						{
 							if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
@@ -5381,11 +5665,6 @@ void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct Ch
 																									 0:
 																									 (defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE)));
 
-						if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod < txProfile.chargingSchedule[idxSchedule].duration)
-						{
-							defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod += (txProfile.chargingSchedule[idxSchedule].duration-defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod);
-						}
-
 						if(idxPeriod > 0)
 						{
 							if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
@@ -5407,7 +5686,7 @@ void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct Ch
 		DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
 		DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.recurrencyKind);
 
-		DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
+		DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
 		DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.chargingSchedule[idxSchedule].Duration);
 		DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.chargingSchedule[idxSchedule].ChargingRateUnit);
 		DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.chargingSchedule[idxSchedule].MinChargingRate);
@@ -5547,7 +5826,7 @@ void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct Ch
 		DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
 		DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.recurrencyKind);
 
-		DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
+		DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
 		DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.chargingSchedule[idxSchedule].Duration);
 		DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.chargingSchedule[idxSchedule].ChargingRateUnit);
 		DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.chargingSchedule[idxSchedule].MinChargingRate);
@@ -5925,8 +6204,6 @@ void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct Ch
 	if(line)
 		free(line);
 
-	checkChargePointMaxProfile(durationReq, &ShmOCPP20Data->MaxChargingProfile, idxSchedule, isUnitA);
-
 	ShmOCPP20Data->CSUMsg.bits[(connectorId==0?0:connectorId-1)].ChargingProfileConf = ON;
 }
 
@@ -7100,6 +7377,7 @@ void CheckSystemValue(void)
 		//==============================================
 		if(ShmOCPP20Data->CSUMsg.bits[gun_index].ChargingProfileReq == ON)
 		{
+			checkChargePointMaxProfile(86400, &ShmOCPP20Data->MaxChargingProfile, 0, TRUE);
 			checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP20Data->SmartChargingProfile[gun_index], 0, TRUE);
 			ShmOCPP20Data->CSUMsg.bits[gun_index].ChargingProfileReq = OFF;
 		}
@@ -13156,11 +13434,15 @@ end:
 		{
 			for(uint8_t idx=0;idx<gunTotalNumber;idx++)
 			{
+				checkChargePointMaxProfile(86400, &ShmOCPP20Data->MaxChargingProfile, 0, TRUE);
 				checkCompositeSchedule((idx+1), 86400, &ShmOCPP20Data->SmartChargingProfile[idx], 0, TRUE);
 			}
 		}
 		else
+		{
+			checkChargePointMaxProfile(86400, &ShmOCPP20Data->MaxChargingProfile, 0, TRUE);
 			checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP20Data->SmartChargingProfile[connectorIdInt-1], 0, TRUE);
+		}
     }
 
 
@@ -16544,11 +16826,15 @@ int handleSetChargingProfileRequest(char *uuid, char *payload)
 		{
 			for(uint8_t idx=0;idx<gunTotalNumber;idx++)
 			{
+				checkChargePointMaxProfile(86400, &ShmOCPP20Data->MaxChargingProfile, 0, TRUE);
 				checkCompositeSchedule((idx+1), 86400, &ShmOCPP20Data->SmartChargingProfile[idx], 0, TRUE);
 			}
 		}
 		else
+		{
+			checkChargePointMaxProfile(86400, &ShmOCPP20Data->MaxChargingProfile, 0, TRUE);
 			checkCompositeSchedule(SetProfileReq.evseId, 86400, &ShmOCPP20Data->SmartChargingProfile[SetProfileReq.evseId-1], 0, TRUE);
+		}
 	}
 
 	sendSetChargingProfileConfirmation(uuid, (SetProfileReq.evseId==0?SetProfileReq.evseId:SetProfileReq.evseId-1));

+ 338 - 59
EVSE/Modularization/ocppfiles/MessageHandler.c

@@ -1594,28 +1594,180 @@ int DiffTimebWithNowSec(struct timeb ST)
 
 int getStartStop(uint8_t *start, uint8_t *stop)
 {
+	struct ParsingResult
+	{
+		int result;
+		int scanedElement;
+		int year;
+		int month;
+		int mday;
+		int hour;
+		int min;
+		int sec;
+		int tz_hour;
+		int tz_min;
+		float minSec;
+	};
+
+	struct ParsingResult parseStart;
+	struct ParsingResult parseStop;
+
 	int result = -1;
 	struct tm tmStart;
 	struct timeb tbStart;
 	struct tm tmStop;
 	struct timeb tbStop;
 
+	memset(&parseStart, 0x00, sizeof(struct ParsingResult));
+	memset(&parseStop, 0x00, sizeof(struct ParsingResult));
 
-	if((sscanf((char*)start, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStart.tm_year, &tmStart.tm_mon, &tmStart.tm_mday, &tmStart.tm_hour, &tmStart.tm_min, &tmStart.tm_sec) == 6) &&
-	   (sscanf((char*)stop, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStop.tm_year, &tmStop.tm_mon, &tmStop.tm_mday, &tmStop.tm_hour, &tmStop.tm_min, &tmStop.tm_sec) == 6))
+	// Scan start & stop date time
+	if(strstr((char*)start, ".") != NULL)
+	{
+		// Original data with mini second
+		if(strstr((char*)start, "Z") != NULL)
+		{
+			// Original data with Z
+			parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
+														&parseStart.year,
+														&parseStart.month,
+														&parseStart.mday,
+														&parseStart.hour,
+														&parseStart.min,
+														&parseStart.sec,
+														&parseStart.minSec);
+		}
+		else
+		{
+			// Original data without Z
+			parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
+														&parseStart.year,
+														&parseStart.month,
+														&parseStart.mday,
+														&parseStart.hour,
+														&parseStart.min,
+														&parseStart.sec,
+														&parseStart.minSec,
+														&parseStart.tz_hour,
+														&parseStart.tz_min);
+		}
+	}
+	else
 	{
-		//DEBUG_INFO("Start: %d-%d-%d %d:%d:%d\n", tmStart.tm_year, tmStart.tm_mon, tmStart.tm_mday, tmStart.tm_hour, tmStart.tm_min, tmStart.tm_sec);
-		//DEBUG_INFO("Stop: %d-%d-%d %d:%d:%d\n", tmStop.tm_year, tmStop.tm_mon, tmStop.tm_mday, tmStop.tm_hour, tmStop.tm_min, tmStop.tm_sec);
+		// Original data without mini second
+		if(strstr((char*)start, "Z") != NULL)
+		{
+			// Original data with Z
+			parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
+														&parseStart.year,
+														&parseStart.month,
+														&parseStart.mday,
+														&parseStart.hour,
+														&parseStart.min,
+														&parseStart.sec);
+		}
+		else
+		{
+			// Original data without Z
+			parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
+														&parseStart.year,
+														&parseStart.month,
+														&parseStart.mday,
+														&parseStart.hour,
+														&parseStart.min,
+														&parseStart.sec,
+														&parseStart.tz_hour,
+														&parseStart.tz_min);
+		}
+	}
 
-		tmStart.tm_year -= 1900;
-		tmStart.tm_mon -= 1;
+	if(strstr((char*)stop, ".") != NULL)
+	{
+		// Original data with mini second
+		if(strstr((char*)stop, "Z") != NULL)
+		{
+			// Original data with Z
+			parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%fZ",
+														&parseStop.year,
+														&parseStop.month,
+														&parseStop.mday,
+														&parseStop.hour,
+														&parseStop.min,
+														&parseStop.sec,
+														&parseStop.minSec);
+		}
+		else
+		{
+			// Original data without Z
+			parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%f%d:%d",
+														&parseStop.year,
+														&parseStop.month,
+														&parseStop.mday,
+														&parseStop.hour,
+														&parseStop.min,
+														&parseStop.sec,
+														&parseStop.minSec,
+														&parseStop.tz_hour,
+														&parseStop.tz_min);
+		}
+	}
+	else
+	{
+		// Original data without mini second
+		if(strstr((char*)stop, "Z") != NULL)
+		{
+			// Original data with Z
+			parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%dZ",
+														&parseStop.year,
+														&parseStop.month,
+														&parseStop.mday,
+														&parseStop.hour,
+														&parseStop.min,
+														&parseStop.sec);
+		}
+		else
+		{
+			// Original data without Z
+			parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d%d:%d",
+														&parseStop.year,
+														&parseStop.month,
+														&parseStop.mday,
+														&parseStop.hour,
+														&parseStop.min,
+														&parseStop.sec,
+														&parseStop.tz_hour,
+														&parseStop.tz_min);
+		}
+	}
+
+	// Calculate date time difference
+	if((parseStart.scanedElement >=6) &&
+	   (parseStop.scanedElement >=6))
+	{
+		//DEBUG_INFO("Start: %04d-%02d-%02d %02d:%02d:%02d(%02d:%02d)\n", parseStart.year, parseStart.month, parseStart.mday, parseStart.hour, parseStart.min, parseStart.sec, parseStart.tz_hour, parseStart.tz_min);
+		//DEBUG_INFO("Stop: %04d-%02d-%02d %02d:%02d:%02d(%02d:%02d)\n", parseStop.year, parseStop.month, parseStop.mday, parseStop.hour, parseStop.min, parseStop.sec, parseStop.tz_hour, parseStop.tz_min);
+
+		tmStart.tm_year = parseStart.year - 1900;
+		tmStart.tm_mon = parseStart.month - 1;
+		tmStart.tm_mday = parseStart.mday;
+		tmStart.tm_hour = parseStart.hour;
+		tmStart.tm_min = parseStart.min;
+		tmStart.tm_sec = parseStart.sec;
+		tmStart.tm_gmtoff = 0;
 		tbStart.time = mktime(&tmStart);
-		tbStart.millitm = 0;
-
-		tmStop.tm_year -= 1900;
-		tmStop.tm_mon -= 1;
+		tbStart.timezone = 0;
+		tbStart.time -= (parseStart.tz_hour*3600) + (parseStart.tz_min*60*(parseStart.tz_hour>=0?1:-1));
+
+		tmStop.tm_year = parseStop.year - 1900;
+		tmStop.tm_mon = parseStop.month - 1;
+		tmStop.tm_mday = parseStop.mday;
+		tmStop.tm_hour = parseStop.hour;
+		tmStop.tm_min = parseStop.min;
+		tmStop.tm_sec = parseStop.sec;
+		tmStop.tm_gmtoff = 0;
 		tbStop.time = mktime(&tmStop);
-		tbStop.millitm = 0;
+		tbStop.timezone = 0;
+		tbStop.time -= (parseStop.tz_hour*3600) + (parseStop.tz_min*60*(parseStop.tz_hour>=0?1:-1));
 
 		result = DiffTimebSec(tbStart, tbStop);
 
@@ -1742,26 +1894,189 @@ int isOvertNow(uint8_t *start)
 
 int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
 {
+	struct ParsingResult
+	{
+		int result;
+		int scanedElement;
+		int year;
+		int month;
+		int mday;
+		int hour;
+		int min;
+		int sec;
+		int tz_hour;
+		int tz_min;
+		float minSec;
+	};
+
+	struct ParsingResult parseStart;
+	struct ParsingResult parseStop;
+
 	int result = -1;
 	struct tm tmStart;
 	struct timeb tbStart;
 	struct tm tmStop;
 	struct timeb tbStop;
 
-	if((sscanf((char*)start, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStart.tm_year, &tmStart.tm_mon, &tmStart.tm_mday, &tmStart.tm_hour, &tmStart.tm_min, &tmStart.tm_sec) == 6) &&
-	   (sscanf((char*)stop, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStop.tm_year, &tmStop.tm_mon, &tmStop.tm_mday, &tmStop.tm_hour, &tmStop.tm_min, &tmStop.tm_sec) == 6))
+	memset(&parseStart, 0x00, sizeof(struct ParsingResult));
+	memset(&parseStop, 0x00, sizeof(struct ParsingResult));
+
+	// Scan start & stop date time
+	if(strstr((char*)start, ".") != NULL)
 	{
-		tmStart.tm_year -= 1900;
-		tmStart.tm_mon -= 1;
-		tbStart.time = mktime(&tmStart);
-		tbStart.millitm = 0;
+		// Original data with mini second
+		if(strstr((char*)start, "Z") != NULL)
+		{
+			// Original data with Z
+			parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
+														&parseStart.year,
+														&parseStart.month,
+														&parseStart.mday,
+														&parseStart.hour,
+														&parseStart.min,
+														&parseStart.sec,
+														&parseStart.minSec);
+		}
+		else
+		{
+			// Original data without Z
+			parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
+														&parseStart.year,
+														&parseStart.month,
+														&parseStart.mday,
+														&parseStart.hour,
+														&parseStart.min,
+														&parseStart.sec,
+														&parseStart.minSec,
+														&parseStart.tz_hour,
+														&parseStart.tz_min);
+		}
+	}
+	else
+	{
+		// Original data without mini second
+		if(strstr((char*)start, "Z") != NULL)
+		{
+			// Original data with Z
+			parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
+														&parseStart.year,
+														&parseStart.month,
+														&parseStart.mday,
+														&parseStart.hour,
+														&parseStart.min,
+														&parseStart.sec);
+		}
+		else
+		{
+			// Original data without Z
+			parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
+														&parseStart.year,
+														&parseStart.month,
+														&parseStart.mday,
+														&parseStart.hour,
+														&parseStart.min,
+														&parseStart.sec,
+														&parseStart.tz_hour,
+														&parseStart.tz_min);
+		}
+	}
 
-		tmStop.tm_year -= 1900;
-		tmStop.tm_mon -= 1;
+	if(strstr((char*)stop, ".") != NULL)
+	{
+		// Original data with mini second
+		if(strstr((char*)stop, "Z") != NULL)
+		{
+			// Original data with Z
+			parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%fZ",
+														&parseStop.year,
+														&parseStop.month,
+														&parseStop.mday,
+														&parseStop.hour,
+														&parseStop.min,
+														&parseStop.sec,
+														&parseStop.minSec);
+		}
+		else
+		{
+			// Original data without Z
+			parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%f%d:%d",
+														&parseStop.year,
+														&parseStop.month,
+														&parseStop.mday,
+														&parseStop.hour,
+														&parseStop.min,
+														&parseStop.sec,
+														&parseStop.minSec,
+														&parseStop.tz_hour,
+														&parseStop.tz_min);
+		}
+	}
+	else
+	{
+		// Original data without mini second
+		if(strstr((char*)stop, "Z") != NULL)
+		{
+			// Original data with Z
+			parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%dZ",
+														&parseStop.year,
+														&parseStop.month,
+														&parseStop.mday,
+														&parseStop.hour,
+														&parseStop.min,
+														&parseStop.sec);
+		}
+		else
+		{
+			// Original data without Z
+			parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d%d:%d",
+														&parseStop.year,
+														&parseStop.month,
+														&parseStop.mday,
+														&parseStop.hour,
+														&parseStop.min,
+														&parseStop.sec,
+														&parseStop.tz_hour,
+														&parseStop.tz_min);
+		}
+	}
+
+	// Calculate date time difference
+	if((parseStart.scanedElement >=6) &&
+	   (parseStop.scanedElement >=6))
+	{
+		//DEBUG_INFO("Start: %04d-%02d-%02d %02d:%02d:%02d(%02d:%02d)\n", parseStart.year, parseStart.month, parseStart.mday, parseStart.hour, parseStart.min, parseStart.sec, parseStart.tz_hour, parseStart.tz_min);
+		//DEBUG_INFO("Stop: %04d-%02d-%02d %02d:%02d:%02d(%02d:%02d)\n", parseStop.year, parseStop.month, parseStop.mday, parseStop.hour, parseStop.min, parseStop.sec, parseStop.tz_hour, parseStop.tz_min);
+
+		tmStart.tm_year = parseStart.year - 1900;
+		tmStart.tm_mon = parseStart.month - 1;
+		tmStart.tm_mday = parseStart.mday;
+		tmStart.tm_hour = parseStart.hour;
+		tmStart.tm_min = parseStart.min;
+		tmStart.tm_sec = parseStart.sec;
+		tmStart.tm_gmtoff = 0;
+		tbStart.time = mktime(&tmStart);
+		tbStart.timezone = 0;
+		tbStart.time -= (parseStart.tz_hour*3600) + (parseStart.tz_min*60*(parseStart.tz_hour>=0?1:-1));
+
+		tmStop.tm_year = parseStop.year - 1900;
+		tmStop.tm_mon = parseStop.month - 1;
+		tmStop.tm_mday = parseStop.mday;
+		tmStop.tm_hour = parseStop.hour;
+		tmStop.tm_min = parseStop.min;
+		tmStop.tm_sec = parseStop.sec;
+		tmStop.tm_gmtoff = 0;
 		tbStop.time = mktime(&tmStop);
-		tbStop.millitm = 0;
+		tbStop.timezone = 0;
+		tbStop.time -= (parseStop.tz_hour*3600) + (parseStop.tz_min*60*(parseStop.tz_hour>=0?1:-1));
 
 		result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
+
+		//DEBUG_INFO("getStartStop(): %d\n", result);
+
+	}
+	else
+	{
+		DEBUG_WARN("Start or stop date parsing error.\r\n");
 	}
 
 	return result;
@@ -1854,8 +2169,6 @@ void checkChargePointMaxProfile(uint32_t durationReq, struct StructChargingProfi
 									maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
 									maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
 								}
-								maxProfile.ChargingProfileId = -1;
-								maxProfile.StackLevel = -1;
 
 								if(maxProfile.ChargingProfileId == -1)
 									DEBUG_INFO("MaxProfile found.\n");
@@ -1969,8 +2282,6 @@ void checkChargePointMaxProfile(uint32_t durationReq, struct StructChargingProfi
 							maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
 							maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
 						}
-						maxProfile.ChargingProfileId = -1;
-						maxProfile.StackLevel = -1;
 
 						if(maxProfile.ChargingProfileId == -1)
 							DEBUG_INFO("MaxProfile found.\n");
@@ -2400,8 +2711,6 @@ void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct St
 									txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
 									txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
 								}
-								txProfile.ChargingProfileId = -1;
-								txProfile.StackLevel = -1;
 
 								if(txProfile.ChargingProfileId == -1)
 									DEBUG_INFO("TxProfile found.\n");
@@ -2514,8 +2823,6 @@ void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct St
 							txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
 							txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
 						}
-						txProfile.ChargingProfileId = -1;
-						txProfile.StackLevel = -1;
 
 						if(txProfile.ChargingProfileId == -1)
 							DEBUG_INFO("TxProfile found.\n");
@@ -2703,8 +3010,6 @@ void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct St
 									defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
 									defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
 								}
-								defaultTxProfile.ChargingProfileId = -1;
-								defaultTxProfile.StackLevel = -1;
 
 								if(defaultTxProfile.ChargingProfileId == -1)
 									DEBUG_INFO("TxDefaultProfile found.\n");
@@ -2818,8 +3123,6 @@ void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct St
 							defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
 							defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
 						}
-						defaultTxProfile.ChargingProfileId = -1;
-						defaultTxProfile.StackLevel = -1;
 
 						if(defaultTxProfile.ChargingProfileId == -1)
 							DEBUG_INFO("TxDefaultProfile found.\n");
@@ -3006,8 +3309,6 @@ void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct St
 									maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
 									maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
 								}
-								maxProfile.ChargingProfileId = -1;
-								maxProfile.StackLevel = -1;
 
 								if(maxProfile.ChargingProfileId == -1)
 									DEBUG_INFO("MaxProfile found.\n");
@@ -3121,8 +3422,6 @@ void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct St
 							maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
 							maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
 						}
-						maxProfile.ChargingProfileId = -1;
-						maxProfile.StackLevel = -1;
 
 						if(maxProfile.ChargingProfileId == -1)
 							DEBUG_INFO("MaxProfile found.\n");
@@ -3395,7 +3694,7 @@ void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct St
 		DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
 		DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
 
-		DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
+		DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
 		DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
 		DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
 		DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
@@ -3430,11 +3729,6 @@ void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct St
 																								 0:
 																								 (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
 
-					if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
-					{
-						defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
-					}
-
 					if(idxPeriod > 0)
 					{
 						if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
@@ -3462,11 +3756,6 @@ void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct St
 																																																												0:
 																																																											   (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
 
-					if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
-					{
-						defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
-					}
-
 					if(idxPeriod > 0)
 					{
 						if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
@@ -3496,11 +3785,6 @@ void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct St
 																									 0:
 																									 (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
 
-						if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
-						{
-							defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
-						}
-
 						if(idxPeriod > 0)
 						{
 							if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
@@ -3528,11 +3812,6 @@ void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct St
 																									 0:
 																									 (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
 
-						if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
-						{
-							defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
-						}
-
 						if(idxPeriod > 0)
 						{
 							if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
@@ -3554,7 +3833,7 @@ void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct St
 		DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
 		DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
 
-		DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
+		DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
 		DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
 		DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
 		DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
@@ -3694,7 +3973,7 @@ void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct St
 		DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
 		DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
 
-		DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
+		DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
 		DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
 		DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
 		DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);

+ 338 - 59
EVSE/Modularization/ocppph/MessageHandler.c

@@ -1101,28 +1101,180 @@ int DiffTimebWithNowSec(struct timeb ST)
 
 int getStartStop(uint8_t *start, uint8_t *stop)
 {
+	struct ParsingResult
+	{
+		int result;
+		int scanedElement;
+		int year;
+		int month;
+		int mday;
+		int hour;
+		int min;
+		int sec;
+		int tz_hour;
+		int tz_min;
+		float minSec;
+	};
+
+	struct ParsingResult parseStart;
+	struct ParsingResult parseStop;
+
 	int result = -1;
 	struct tm tmStart;
 	struct timeb tbStart;
 	struct tm tmStop;
 	struct timeb tbStop;
 
+	memset(&parseStart, 0x00, sizeof(struct ParsingResult));
+	memset(&parseStop, 0x00, sizeof(struct ParsingResult));
 
-	if((sscanf((char*)start, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStart.tm_year, &tmStart.tm_mon, &tmStart.tm_mday, &tmStart.tm_hour, &tmStart.tm_min, &tmStart.tm_sec) == 6) &&
-	   (sscanf((char*)stop, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStop.tm_year, &tmStop.tm_mon, &tmStop.tm_mday, &tmStop.tm_hour, &tmStop.tm_min, &tmStop.tm_sec) == 6))
+	// Scan start & stop date time
+	if(strstr((char*)start, ".") != NULL)
 	{
-		//DEBUG_INFO("Start: %d-%d-%d %d:%d:%d\n", tmStart.tm_year, tmStart.tm_mon, tmStart.tm_mday, tmStart.tm_hour, tmStart.tm_min, tmStart.tm_sec);
-		//DEBUG_INFO("Stop: %d-%d-%d %d:%d:%d\n", tmStop.tm_year, tmStop.tm_mon, tmStop.tm_mday, tmStop.tm_hour, tmStop.tm_min, tmStop.tm_sec);
+		// Original data with mini second
+		if(strstr((char*)start, "Z") != NULL)
+		{
+			// Original data with Z
+			parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
+														&parseStart.year,
+														&parseStart.month,
+														&parseStart.mday,
+														&parseStart.hour,
+														&parseStart.min,
+														&parseStart.sec,
+														&parseStart.minSec);
+		}
+		else
+		{
+			// Original data without Z
+			parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
+														&parseStart.year,
+														&parseStart.month,
+														&parseStart.mday,
+														&parseStart.hour,
+														&parseStart.min,
+														&parseStart.sec,
+														&parseStart.minSec,
+														&parseStart.tz_hour,
+														&parseStart.tz_min);
+		}
+	}
+	else
+	{
+		// Original data without mini second
+		if(strstr((char*)start, "Z") != NULL)
+		{
+			// Original data with Z
+			parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
+														&parseStart.year,
+														&parseStart.month,
+														&parseStart.mday,
+														&parseStart.hour,
+														&parseStart.min,
+														&parseStart.sec);
+		}
+		else
+		{
+			// Original data without Z
+			parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
+														&parseStart.year,
+														&parseStart.month,
+														&parseStart.mday,
+														&parseStart.hour,
+														&parseStart.min,
+														&parseStart.sec,
+														&parseStart.tz_hour,
+														&parseStart.tz_min);
+		}
+	}
 
-		tmStart.tm_year -= 1900;
-		tmStart.tm_mon -= 1;
+	if(strstr((char*)stop, ".") != NULL)
+	{
+		// Original data with mini second
+		if(strstr((char*)stop, "Z") != NULL)
+		{
+			// Original data with Z
+			parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%fZ",
+														&parseStop.year,
+														&parseStop.month,
+														&parseStop.mday,
+														&parseStop.hour,
+														&parseStop.min,
+														&parseStop.sec,
+														&parseStop.minSec);
+		}
+		else
+		{
+			// Original data without Z
+			parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%f%d:%d",
+														&parseStop.year,
+														&parseStop.month,
+														&parseStop.mday,
+														&parseStop.hour,
+														&parseStop.min,
+														&parseStop.sec,
+														&parseStop.minSec,
+														&parseStop.tz_hour,
+														&parseStop.tz_min);
+		}
+	}
+	else
+	{
+		// Original data without mini second
+		if(strstr((char*)stop, "Z") != NULL)
+		{
+			// Original data with Z
+			parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%dZ",
+														&parseStop.year,
+														&parseStop.month,
+														&parseStop.mday,
+														&parseStop.hour,
+														&parseStop.min,
+														&parseStop.sec);
+		}
+		else
+		{
+			// Original data without Z
+			parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d%d:%d",
+														&parseStop.year,
+														&parseStop.month,
+														&parseStop.mday,
+														&parseStop.hour,
+														&parseStop.min,
+														&parseStop.sec,
+														&parseStop.tz_hour,
+														&parseStop.tz_min);
+		}
+	}
+
+	// Calculate date time difference
+	if((parseStart.scanedElement >=6) &&
+	   (parseStop.scanedElement >=6))
+	{
+		//DEBUG_INFO("Start: %04d-%02d-%02d %02d:%02d:%02d(%02d:%02d)\n", parseStart.year, parseStart.month, parseStart.mday, parseStart.hour, parseStart.min, parseStart.sec, parseStart.tz_hour, parseStart.tz_min);
+		//DEBUG_INFO("Stop: %04d-%02d-%02d %02d:%02d:%02d(%02d:%02d)\n", parseStop.year, parseStop.month, parseStop.mday, parseStop.hour, parseStop.min, parseStop.sec, parseStop.tz_hour, parseStop.tz_min);
+
+		tmStart.tm_year = parseStart.year - 1900;
+		tmStart.tm_mon = parseStart.month - 1;
+		tmStart.tm_mday = parseStart.mday;
+		tmStart.tm_hour = parseStart.hour;
+		tmStart.tm_min = parseStart.min;
+		tmStart.tm_sec = parseStart.sec;
+		tmStart.tm_gmtoff = 0;
 		tbStart.time = mktime(&tmStart);
-		tbStart.millitm = 0;
-
-		tmStop.tm_year -= 1900;
-		tmStop.tm_mon -= 1;
+		tbStart.timezone = 0;
+		tbStart.time -= (parseStart.tz_hour*3600) + (parseStart.tz_min*60*(parseStart.tz_hour>=0?1:-1));
+
+		tmStop.tm_year = parseStop.year - 1900;
+		tmStop.tm_mon = parseStop.month - 1;
+		tmStop.tm_mday = parseStop.mday;
+		tmStop.tm_hour = parseStop.hour;
+		tmStop.tm_min = parseStop.min;
+		tmStop.tm_sec = parseStop.sec;
+		tmStop.tm_gmtoff = 0;
 		tbStop.time = mktime(&tmStop);
-		tbStop.millitm = 0;
+		tbStop.timezone = 0;
+		tbStop.time -= (parseStop.tz_hour*3600) + (parseStop.tz_min*60*(parseStop.tz_hour>=0?1:-1));
 
 		result = DiffTimebSec(tbStart, tbStop);
 
@@ -1247,26 +1399,189 @@ int isOvertNow(uint8_t *start)
 
 int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
 {
+	struct ParsingResult
+	{
+		int result;
+		int scanedElement;
+		int year;
+		int month;
+		int mday;
+		int hour;
+		int min;
+		int sec;
+		int tz_hour;
+		int tz_min;
+		float minSec;
+	};
+
+	struct ParsingResult parseStart;
+	struct ParsingResult parseStop;
+
 	int result = -1;
 	struct tm tmStart;
 	struct timeb tbStart;
 	struct tm tmStop;
 	struct timeb tbStop;
 
-	if((sscanf((char*)start, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStart.tm_year, &tmStart.tm_mon, &tmStart.tm_mday, &tmStart.tm_hour, &tmStart.tm_min, &tmStart.tm_sec) == 6) &&
-	   (sscanf((char*)stop, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStop.tm_year, &tmStop.tm_mon, &tmStop.tm_mday, &tmStop.tm_hour, &tmStop.tm_min, &tmStop.tm_sec) == 6))
+	memset(&parseStart, 0x00, sizeof(struct ParsingResult));
+	memset(&parseStop, 0x00, sizeof(struct ParsingResult));
+
+	// Scan start & stop date time
+	if(strstr((char*)start, ".") != NULL)
 	{
-		tmStart.tm_year -= 1900;
-		tmStart.tm_mon -= 1;
-		tbStart.time = mktime(&tmStart);
-		tbStart.millitm = 0;
+		// Original data with mini second
+		if(strstr((char*)start, "Z") != NULL)
+		{
+			// Original data with Z
+			parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
+														&parseStart.year,
+														&parseStart.month,
+														&parseStart.mday,
+														&parseStart.hour,
+														&parseStart.min,
+														&parseStart.sec,
+														&parseStart.minSec);
+		}
+		else
+		{
+			// Original data without Z
+			parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
+														&parseStart.year,
+														&parseStart.month,
+														&parseStart.mday,
+														&parseStart.hour,
+														&parseStart.min,
+														&parseStart.sec,
+														&parseStart.minSec,
+														&parseStart.tz_hour,
+														&parseStart.tz_min);
+		}
+	}
+	else
+	{
+		// Original data without mini second
+		if(strstr((char*)start, "Z") != NULL)
+		{
+			// Original data with Z
+			parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
+														&parseStart.year,
+														&parseStart.month,
+														&parseStart.mday,
+														&parseStart.hour,
+														&parseStart.min,
+														&parseStart.sec);
+		}
+		else
+		{
+			// Original data without Z
+			parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
+														&parseStart.year,
+														&parseStart.month,
+														&parseStart.mday,
+														&parseStart.hour,
+														&parseStart.min,
+														&parseStart.sec,
+														&parseStart.tz_hour,
+														&parseStart.tz_min);
+		}
+	}
 
-		tmStop.tm_year -= 1900;
-		tmStop.tm_mon -= 1;
+	if(strstr((char*)stop, ".") != NULL)
+	{
+		// Original data with mini second
+		if(strstr((char*)stop, "Z") != NULL)
+		{
+			// Original data with Z
+			parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%fZ",
+														&parseStop.year,
+														&parseStop.month,
+														&parseStop.mday,
+														&parseStop.hour,
+														&parseStop.min,
+														&parseStop.sec,
+														&parseStop.minSec);
+		}
+		else
+		{
+			// Original data without Z
+			parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%f%d:%d",
+														&parseStop.year,
+														&parseStop.month,
+														&parseStop.mday,
+														&parseStop.hour,
+														&parseStop.min,
+														&parseStop.sec,
+														&parseStop.minSec,
+														&parseStop.tz_hour,
+														&parseStop.tz_min);
+		}
+	}
+	else
+	{
+		// Original data without mini second
+		if(strstr((char*)stop, "Z") != NULL)
+		{
+			// Original data with Z
+			parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%dZ",
+														&parseStop.year,
+														&parseStop.month,
+														&parseStop.mday,
+														&parseStop.hour,
+														&parseStop.min,
+														&parseStop.sec);
+		}
+		else
+		{
+			// Original data without Z
+			parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d%d:%d",
+														&parseStop.year,
+														&parseStop.month,
+														&parseStop.mday,
+														&parseStop.hour,
+														&parseStop.min,
+														&parseStop.sec,
+														&parseStop.tz_hour,
+														&parseStop.tz_min);
+		}
+	}
+
+	// Calculate date time difference
+	if((parseStart.scanedElement >=6) &&
+	   (parseStop.scanedElement >=6))
+	{
+		//DEBUG_INFO("Start: %04d-%02d-%02d %02d:%02d:%02d(%02d:%02d)\n", parseStart.year, parseStart.month, parseStart.mday, parseStart.hour, parseStart.min, parseStart.sec, parseStart.tz_hour, parseStart.tz_min);
+		//DEBUG_INFO("Stop: %04d-%02d-%02d %02d:%02d:%02d(%02d:%02d)\n", parseStop.year, parseStop.month, parseStop.mday, parseStop.hour, parseStop.min, parseStop.sec, parseStop.tz_hour, parseStop.tz_min);
+
+		tmStart.tm_year = parseStart.year - 1900;
+		tmStart.tm_mon = parseStart.month - 1;
+		tmStart.tm_mday = parseStart.mday;
+		tmStart.tm_hour = parseStart.hour;
+		tmStart.tm_min = parseStart.min;
+		tmStart.tm_sec = parseStart.sec;
+		tmStart.tm_gmtoff = 0;
+		tbStart.time = mktime(&tmStart);
+		tbStart.timezone = 0;
+		tbStart.time -= (parseStart.tz_hour*3600) + (parseStart.tz_min*60*(parseStart.tz_hour>=0?1:-1));
+
+		tmStop.tm_year = parseStop.year - 1900;
+		tmStop.tm_mon = parseStop.month - 1;
+		tmStop.tm_mday = parseStop.mday;
+		tmStop.tm_hour = parseStop.hour;
+		tmStop.tm_min = parseStop.min;
+		tmStop.tm_sec = parseStop.sec;
+		tmStop.tm_gmtoff = 0;
 		tbStop.time = mktime(&tmStop);
-		tbStop.millitm = 0;
+		tbStop.timezone = 0;
+		tbStop.time -= (parseStop.tz_hour*3600) + (parseStop.tz_min*60*(parseStop.tz_hour>=0?1:-1));
 
 		result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
+
+		//DEBUG_INFO("getStartStop(): %d\n", result);
+
+	}
+	else
+	{
+		DEBUG_WARN("Start or stop date parsing error.\r\n");
 	}
 
 	return result;
@@ -1359,8 +1674,6 @@ void checkChargePointMaxProfile(uint32_t durationReq, struct StructChargingProfi
 									maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
 									maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
 								}
-								maxProfile.ChargingProfileId = -1;
-								maxProfile.StackLevel = -1;
 
 								if(maxProfile.ChargingProfileId == -1)
 									DEBUG_INFO("MaxProfile found.\n");
@@ -1474,8 +1787,6 @@ void checkChargePointMaxProfile(uint32_t durationReq, struct StructChargingProfi
 							maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
 							maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
 						}
-						maxProfile.ChargingProfileId = -1;
-						maxProfile.StackLevel = -1;
 
 						if(maxProfile.ChargingProfileId == -1)
 							DEBUG_INFO("MaxProfile found.\n");
@@ -1905,8 +2216,6 @@ void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct St
 									txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
 									txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
 								}
-								txProfile.ChargingProfileId = -1;
-								txProfile.StackLevel = -1;
 
 								if(txProfile.ChargingProfileId == -1)
 									DEBUG_INFO("TxProfile found.\n");
@@ -2019,8 +2328,6 @@ void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct St
 							txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
 							txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
 						}
-						txProfile.ChargingProfileId = -1;
-						txProfile.StackLevel = -1;
 
 						if(txProfile.ChargingProfileId == -1)
 							DEBUG_INFO("TxProfile found.\n");
@@ -2208,8 +2515,6 @@ void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct St
 									defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
 									defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
 								}
-								defaultTxProfile.ChargingProfileId = -1;
-								defaultTxProfile.StackLevel = -1;
 
 								if(defaultTxProfile.ChargingProfileId == -1)
 									DEBUG_INFO("TxDefaultProfile found.\n");
@@ -2323,8 +2628,6 @@ void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct St
 							defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
 							defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
 						}
-						defaultTxProfile.ChargingProfileId = -1;
-						defaultTxProfile.StackLevel = -1;
 
 						if(defaultTxProfile.ChargingProfileId == -1)
 							DEBUG_INFO("TxDefaultProfile found.\n");
@@ -2511,8 +2814,6 @@ void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct St
 									maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
 									maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
 								}
-								maxProfile.ChargingProfileId = -1;
-								maxProfile.StackLevel = -1;
 
 								if(maxProfile.ChargingProfileId == -1)
 									DEBUG_INFO("MaxProfile found.\n");
@@ -2626,8 +2927,6 @@ void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct St
 							maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
 							maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
 						}
-						maxProfile.ChargingProfileId = -1;
-						maxProfile.StackLevel = -1;
 
 						if(maxProfile.ChargingProfileId == -1)
 							DEBUG_INFO("MaxProfile found.\n");
@@ -2900,7 +3199,7 @@ void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct St
 		DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
 		DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
 
-		DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
+		DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
 		DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
 		DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
 		DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
@@ -2935,11 +3234,6 @@ void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct St
 																								 0:
 																								 (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
 
-					if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
-					{
-						defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
-					}
-
 					if(idxPeriod > 0)
 					{
 						if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
@@ -2967,11 +3261,6 @@ void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct St
 																																																												0:
 																																																											   (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
 
-					if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
-					{
-						defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
-					}
-
 					if(idxPeriod > 0)
 					{
 						if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
@@ -3001,11 +3290,6 @@ void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct St
 																									 0:
 																									 (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
 
-						if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
-						{
-							defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
-						}
-
 						if(idxPeriod > 0)
 						{
 							if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
@@ -3033,11 +3317,6 @@ void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct St
 																									 0:
 																									 (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
 
-						if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
-						{
-							defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
-						}
-
 						if(idxPeriod > 0)
 						{
 							if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
@@ -3059,7 +3338,7 @@ void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct St
 		DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
 		DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
 
-		DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
+		DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
 		DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
 		DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
 		DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
@@ -3199,7 +3478,7 @@ void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct St
 		DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
 		DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
 
-		DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
+		DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
 		DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
 		DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
 		DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);

+ 1 - 1
EVSE/Projects/define.h

@@ -5127,7 +5127,7 @@ struct ChargingScheduleType
 
 struct ChargingProfileType
 {
-	unsigned short int id;											// Required. Id of ChargingProfile.
+	int id;											// Required. Id of ChargingProfile.
 	unsigned short int stackLevel;									// Required. Value determining level in hierarchy stack of profiles. Higher values have precedence over lower values. Lowest level is 0.
 	unsigned char chargingProfilePurpose[36];						// Required. Defines the purpose of the schedule transferred by this profile
 	unsigned char chargingProfileKind[16];							// Required. Indicates the kind of schedule.