Browse Source

[Improve][Modularization / AW-CCS][Module_OcppBackend / Module_OcppBackend20 / main]

2021.09.13 / Folus Wen

Actions:
1. AW-CCS isReservationExpired implement time zone logic.
2. Module_OcppBackend reservation expired checking implement time zone logic.
3. Module_OcppBackend20 reservation expired checking implement time zone logic.

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 years ago
parent
commit
a7a7dc3eb5

+ 3 - 1
EVSE/Modularization/ocpp20/MessageHandler.c

@@ -3402,6 +3402,8 @@ int isOvertNow(uint8_t *start)
 	struct tm tmStart;
 	struct timeb tbStart;
 
+	memset(&parsingResult, 0x00, sizeof(struct ParsingResult));
+
 	if(strstr((char*)start, ".") != NULL)
 	{
 		// Original data with mini second
@@ -6767,7 +6769,7 @@ void CheckSystemValue(void)
 		//===============================
 		if((server_sign == TRUE) && (ShmOCPP20Data->ReserveNow[gun_index].expiryDateTime[0] != 0))
 		{
-			if(isOvertNow((uint8_t *)ShmOCPP20Data->ReserveNow[gun_index].expiryDateTime))
+			if(isOvertNow(ShmOCPP20Data->ReserveNow[gun_index].expiryDateTime))
 			{
 				DEBUG_INFO("reserve expired.\n");
 				ShmOCPP20Data->ReservationStatusUpdate[gun_index].reservationId = ShmOCPP20Data->ReserveNow[gun_index].id;

+ 4 - 12
EVSE/Modularization/ocppfiles/MessageHandler.c

@@ -1336,6 +1336,8 @@ int isOvertNow(uint8_t *start)
 	struct tm tmStart;
 	struct timeb tbStart;
 
+	memset(&parsingResult, 0x00, sizeof(struct ParsingResult));
+
 	if(strstr((char*)start, ".") != NULL)
 	{
 		// Original data with mini second
@@ -4410,23 +4412,13 @@ void CheckSystemValue(void)
 		//===============================
 		// Check if Reserve is expired
 		//===============================
-		if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0) )
+		if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0))
 		{
-			double diff_t;
-			struct tm tp;
-			// current time
-			time_t t = time(NULL);
-			strptime((char *)ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
-			tp.tm_isdst = -1;
-			time_t utc = mktime(&tp);
-			diff_t = difftime(utc, t);
-
-			if(diff_t <= 0)
+			if(isOvertNow(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate))
 			{
 				DEBUG_INFO("reserve expired.\n");
 				memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
 			}
-
 		}//END OF Check if Reserve is expired
 
 		//==========================================

+ 124 - 34
EVSE/Projects/AW-CCS/Apps/main.c

@@ -217,6 +217,128 @@ long long DiffTimeb(struct timeb ST, struct timeb ET)
 	return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
 }
 
+int DiffTimebWithNowSec(struct timeb ST)
+{
+	//return milli-second
+	struct timeb ET;
+	unsigned int StartTime,StopTime;
+
+	ftime(&ET);
+	StartTime=(unsigned int)ST.time;
+	StopTime=(unsigned int)ET.time;
+	return (StopTime-StartTime);
+}
+
+int isOvertNow(uint8_t *start)
+{
+	int result = YES;
+	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;
+	}parsingResult;
+
+	struct tm tmStart;
+	struct timeb tbStart;
+
+	memset(&parsingResult, 0x00, sizeof(struct ParsingResult));
+
+	if(strstr((char*)start, ".") != NULL)
+	{
+		// Original data with mini second
+		if(strstr((char*)start, "Z") != NULL)
+		{
+			// Original data with Z
+			parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
+																&parsingResult.year,
+																&parsingResult.month,
+																&parsingResult.mday,
+																&parsingResult.hour,
+																&parsingResult.min,
+																&parsingResult.sec,
+																&parsingResult.minSec);
+		}
+		else
+		{
+			// Original data without Z
+			parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
+												&parsingResult.year,
+												&parsingResult.month,
+												&parsingResult.mday,
+												&parsingResult.hour,
+												&parsingResult.min,
+												&parsingResult.sec,
+												&parsingResult.minSec,
+												&parsingResult.tz_hour,
+												&parsingResult.tz_min);
+		}
+	}
+	else
+	{
+		// Original data without mini second
+		if(strstr((char*)start, "Z") != NULL)
+		{
+			// Original data with Z
+			parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
+												&parsingResult.year,
+												&parsingResult.month,
+												&parsingResult.mday,
+												&parsingResult.hour,
+												&parsingResult.min,
+												&parsingResult.sec);
+		}
+		else
+		{
+			// Original data without Z
+			parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
+												&parsingResult.year,
+												&parsingResult.month,
+												&parsingResult.mday,
+												&parsingResult.hour,
+												&parsingResult.min,
+												&parsingResult.sec,
+												&parsingResult.tz_hour,
+												&parsingResult.tz_min);
+		}
+	}
+
+	if(parsingResult.scanedElement >= 6)
+	{
+		tmStart.tm_year = parsingResult.year - 1900;
+		tmStart.tm_mon = parsingResult.month - 1;
+		tmStart.tm_mday = parsingResult.mday;
+		tmStart.tm_hour = parsingResult.hour;
+		tmStart.tm_min = parsingResult.min;
+		tmStart.tm_sec = parsingResult.sec;
+		tmStart.tm_gmtoff = 0;
+		tbStart.time = mktime(&tmStart);
+		tbStart.timezone = 0;
+		tbStart.millitm = 0;
+
+		tbStart.time -= (parsingResult.tz_hour*3600) + (parsingResult.tz_min*60*(parsingResult.tz_hour>=0?1:-1));
+
+		if(DiffTimebWithNowSec(tbStart) <= 0)
+			result = NO;
+		else
+			result = YES;
+	}
+	else
+	{
+		DEBUG_WARN("Start date parsing error.\n");
+	}
+
+	return result;
+}
+
 void getDateTimeString(char* result)
 {
 	time_t CurrentTime;
@@ -3471,48 +3593,16 @@ int isRouteFail()
 int isReservationExpired(unsigned char gun_index)
 {
 	int result = NO;
-	struct tm expiredDate;
-	struct timeb expiredTime;
 
 	if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
 	{
-		if(sscanf((char*)ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate, "%4d-%2d-%2dT%2d:%2d:%2d", &expiredDate.tm_year, &expiredDate.tm_mon, &expiredDate.tm_mday, &expiredDate.tm_hour, &expiredDate.tm_min, &expiredDate.tm_sec) == 6)
-		{
-			expiredDate.tm_year -= 1900;
-			expiredDate.tm_mon -= 1;
-			expiredTime.time = mktime(&expiredDate);
-
-			if(DiffTimebWithNow(expiredTime)>=0)
-			{
-				result = YES;
-			}
-		}
-		else
-		{
-			DEBUG_WARN("Expired date parsing error.\n");
-			DEBUG_INFO("Date expired.\n");
+		if(isOvertNow(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate))
 			result = YES;
-		}
 	}
 	else if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
 	{
-		if(sscanf((char*)ShmOCPP20Data->ReserveNow[gun_index].expiryDateTime, "%4d-%2d-%2dT%2d:%2d:%2d", &expiredDate.tm_year, &expiredDate.tm_mon, &expiredDate.tm_mday, &expiredDate.tm_hour, &expiredDate.tm_min, &expiredDate.tm_sec) == 6)
-		{
-			expiredDate.tm_year -= 1900;
-			expiredDate.tm_mon -= 1;
-			expiredTime.time = mktime(&expiredDate);
-
-			if(DiffTimebWithNow(expiredTime)>=0)
-			{
-				result = YES;
-			}
-		}
-		else
-		{
-			DEBUG_WARN("Expired date parsing error.\n");
-			DEBUG_INFO("Date expired.\n");
+		if(isOvertNow(ShmOCPP20Data->ReserveNow[gun_index].expiryDateTime))
 			result = YES;
-		}
 	}
 
 	return result;