Quellcode durchsuchen

2020-03-27 / Kathy Yeh
1. modify Transaction-Related Message delivery flow
2. modify SetCharging Profile / Configuration Key ChargeProfileMaxStackLevel logic
modify the logic: ConnectWsServer()

Kathy_Yeh vor 5 Jahren
Ursprung
Commit
a33ae15394

+ 175 - 56
EVSE/Modularization/ocppfiles/MessageHandler.c

@@ -40,6 +40,7 @@
 #include 	<mcheck.h>
 
 
+
 #define PASS				1
 #define FAIL				-1
 
@@ -201,6 +202,7 @@ extern int SendBufLen;
 extern char *random_uuid( char buf[37] );
 extern void split(char **arr, char *str, const char *del);
 extern void  ChageWebSocketPingInterval(int WebSocketPingInterval);
+extern int GetTransactionQueueNum(void);
 extern pthread_mutex_t mutex1;
 extern struct Charger_Info Charger;
 extern sqlite3 *db;
@@ -1265,10 +1267,10 @@ void CheckSystemValue(void)
 		//===============================
 		if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3)/*authenrequest == FALSE*/)
 		{
-				sendAuthorizeRequest(0);
-				authorizeRetryTimes = authorizeRetryTimes + 1;
-				// authenrequest = TRUE
-				if(authorizeRetryTimes < 3)
+			sendAuthorizeRequest(0);
+			authorizeRetryTimes = authorizeRetryTimes + 1;
+
+			if(authorizeRetryTimes < 3)
 				ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
 
 		}
@@ -2031,6 +2033,7 @@ int sendStartTransactionRequest(int gun_index)
 					, ShmOCPP16Data->StartTransaction[gun_index].ReservationId
 					, ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
 
+
 	sprintf(tempdata, "StartTransaction,%d", (gun_index));
 	if(hashmap_operation(0, guid, tempdata) == 1)//if(hashmap_operation(0,NULL/*hashMap*/, mapItem[0].key_string, mapItem[0].key_value/*mapItem*/, (void**)(&mapItem)/*(void**)(&mapItem)*/) ==  MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
 	{
@@ -2039,7 +2042,10 @@ int sendStartTransactionRequest(int gun_index)
 	strcpy(queuedata, message);
 	queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
 
-	LWS_Send(message);
+	if(GetTransactionQueueNum() == 1)
+	{
+		LWS_Send(message);
+	}
 
 #if 0
 	sprintf(tempdata, "StartTransaction,%d", (gun_index));
@@ -2790,10 +2796,12 @@ int sendStopTransactionRequest(int gun_index)
 	}
 	queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
 
-	LWS_Send(queuedata);
-
-
+	if(GetTransactionQueueNum() == 1)
+	{
+		LWS_Send(queuedata);
+	}
 
+	//----------------------------replace queue StopTransaction TransactionId ---------------------------//
 	int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
 
 	if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
@@ -3213,7 +3221,12 @@ int sendMeterValuesRequest(int gun_index)
 	 	DEBUG_INFO("MeterValues mapitem pass\n");
 	}
 	queue_operation(4, guid, queuedata );//addq(guid, queuedata);  ---> remove temporally
-	LWS_Send(queuedata);
+
+	if(GetTransactionQueueNum() == 1)
+	{
+		LWS_Send(queuedata);
+
+	}
 
 #if 0
 	// Put request guid to hash map
@@ -3429,9 +3442,8 @@ int sendGetCompositeScheduleConfirmation(char *uuid,char *payload, int connector
 
 		int len = nPeriod;
 		//Last Period StartPriod is less than diffSeconds
-		if(ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[len -1].StartPeriod < diffSeconds)
+		if((ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[len -1].StartPeriod % 86400) < diffSeconds)
 		{
-
 			sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
 							, 0
 							, ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[len -1].Limit
@@ -3442,7 +3454,7 @@ int sendGetCompositeScheduleConfirmation(char *uuid,char *payload, int connector
 
 			for(int idx_sample=0;idx_sample< len;idx_sample++)
 			{
-				if((ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod < diffSeconds) && (ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample + 1].StartPeriod > diffSeconds))//if (idx_sample == 0)
+				if(((ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod % 86400) < diffSeconds) && ((ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample + 1].StartPeriod % 86400) > diffSeconds))//if (idx_sample == 0)
 				{
 					sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
 							, 0 /*ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod*/
@@ -3452,7 +3464,7 @@ int sendGetCompositeScheduleConfirmation(char *uuid,char *payload, int connector
 				else if(ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod > diffSeconds)
 				{
 					sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
-							, (ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod - diffSeconds /*-1*/)//(((ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod - diffSeconds ) <= 0)?(ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod):(ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod - diffSeconds /*-1*/))   //(((ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod - diffSeconds /*-1*/) <= 0)?(ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod):(ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod - diffSeconds /*-1*/))
+							, ((ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod % 86400) - diffSeconds /*-1*/)//(((ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod - diffSeconds ) <= 0)?(ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod):(ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod - diffSeconds /*-1*/))   //(((ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod - diffSeconds /*-1*/) <= 0)?(ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod):(ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod - diffSeconds /*-1*/))
 							, ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
 							, ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
 				}
@@ -4763,6 +4775,7 @@ int handleClearChargingProfileRequest(char *uuid, char *payload)
 	}
 	else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
 	{
+		DEBUG_INFO("ChargeProfileCount=%d\n",ChargeProfileCount);
 	   for(int k=0; k < ChargeProfileCount; k++)
 	   {
 		   fptr1 = fopen(chargingProfiles[k], "r");
@@ -4779,7 +4792,6 @@ int handleClearChargingProfileRequest(char *uuid, char *payload)
 			   }
 		   }
 		   rewind(fptr1);
-
 		   //search Charging Profile Element
 		   //int i= 0;
 		   while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
@@ -5552,37 +5564,70 @@ int handleGetCompositeScheduleRequest(char *uuid, char *payload)
   	  	  	if((ChargePointMaxProfileIsNull==FALSE)&&(TxDefaultProfileFileIsNull==FALSE))
   	  	  	{
   	  	  		strcpy(CurrentChargingProfileScheduleStr, TxDefaultProfileScheduleStr);
-  	  	  		for(int index=0; index < TxDefaultProfile.TotalPeriod ; index++)
+  	  	  		struct tm tp;
+  	  	  	  	strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
+  	  	  	  	tp.tm_isdst = -1;
+  	  	  	  	time_t utc = mktime(&tp);
+  	  	  	  	time_t t = time(NULL);
+  	  	  	  	double diff_f = difftime(t, utc);
+  	  	  	  	int diff_i = (int)diff_f;
+  	  	  	  	int quotient = diff_i / 86400;//86400 seconds/day
+
+  	  	  	  	int period = 0;
+  	  	  	  	for(int index=0; index < TxDefaultProfile.TotalPeriod ; index++)
   	  	  		{
-  	  	  			if(ChargePointMaxProfile.Period[0].Limit > TxDefaultProfile.Period[index].Limit)
-  	  	  			{
-  	  	  				ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].Limit = TxDefaultProfile.Period[index].Limit;
-  	  	  			}
-  	  	  			else
-  	  	  			{
-  	  	  				ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].Limit = ChargePointMaxProfile.Period[0].Limit;
-  	  	  			}
-
-  	  	  			ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].NumberPhases = TxDefaultProfile.Period[index].NumberPhases;  //for discussion
-  	  	  		  	ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].StartPeriod = TxDefaultProfile.Period[index].StartPeriod;
-  	  	  		  	ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = TxDefaultProfile.Duration;
+  	  	  	  		if(((TxDefaultProfile.Period[index].StartPeriod % 86400) < durationInt) && ((TxDefaultProfile.Period[index].StartPeriod / 86400) == quotient))
+  	  	  	  		{
+  	  	  	  			if(ChargePointMaxProfile.Period[0].Limit > TxDefaultProfile.Period[index].Limit)
+  	  	  	  	  	  	{
+  	  	  	  				ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[index].Limit;
+  	  	  	  	  	  	}
+  	  	  	  	  	  	else
+  	  	  	  	  	  	{
+  	  	  	  	  	  	  	ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
+  	  	  	  	  	  	}
+
+  	  	  	  	  	  	ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[index].NumberPhases;  //for discussion
+  	  	  	  	  	  	ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = (TxDefaultProfile.Period[index].StartPeriod % 86400);
+  	  	  	  	  	  	ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = TxDefaultProfile.Duration;
+  	  	  	  	  	  	period = period + 1;
+  	  	  	  		}
+
+
+
   	  	  		}
 
-  	  	  		confirmPeriods = TxDefaultProfile.TotalPeriod;
+  	  	  		confirmPeriods = period;
 
   	  	  	}
   	  	  	else if((ChargePointMaxProfileIsNull==TRUE)&&(TxDefaultProfileFileIsNull==FALSE))
   	  	  	{
   	  	  		strcpy(CurrentChargingProfileScheduleStr, TxDefaultProfileScheduleStr);
+  	  	  		struct tm tp;
+  	  	  	  	strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
+  	  	  	  	tp.tm_isdst = -1;
+  	  	  	  	time_t utc = mktime(&tp);
+  	  	  	  	time_t t = time(NULL);
+  	  	  	  	double diff_f = difftime(t, utc);
+  	  	  	  	int diff_i = (int)diff_f;
+  	  	  	  	int quotient = diff_i / 86400;//86400 seconds/day
+
+  	  	  	  	int period = 0;
   	  	  	  	for(int index=0; index < TxDefaultProfile.TotalPeriod ; index++)
   	  	  	  	{
-  	  	  	  		ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].Limit = TxDefaultProfile.Period[index].Limit;
-  	  	  	  	  	ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].NumberPhases = TxDefaultProfile.Period[index].NumberPhases;  //for discussion
-  	  	  	  	  	ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].StartPeriod = TxDefaultProfile.Period[index].StartPeriod;
-  	  	  	  	  	ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = TxDefaultProfile.Duration;
-  	  	  	  	 }
+  	  	  	  	  	if(((TxDefaultProfile.Period[index].StartPeriod % 86400) < durationInt) && ((TxDefaultProfile.Period[index].StartPeriod / 86400) == quotient))
+  	  	  	  	  	{
+  	  	  	  	  	  	ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[index].Limit;
 
-  	  	  	  	confirmPeriods = TxDefaultProfile.TotalPeriod;
+  	  	  	  	  	  	ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[index].NumberPhases;  //for discussion
+  	  	  	  	  	  	ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = (TxDefaultProfile.Period[index].StartPeriod % 86400);
+  	  	  	  	  	  	ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = TxDefaultProfile.Duration;
+  	  	  	  	  	    period = period + 1;
+  	  	  	  	  	}
+
+  	  	  	  	}
+
+  	  	  	  	confirmPeriods = period;
 
   	  	  	}
   	    	else if((ChargePointMaxProfileIsNull==FALSE)&&(TxDefaultProfileFileIsNull==TRUE))
@@ -6381,6 +6426,16 @@ int handleGetCompositeScheduleRequest(char *uuid, char *payload)
   			if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==FALSE) )
   			{
   				strcpy(CurrentChargingProfileScheduleStr,TxProfileScheduleStr);
+  				struct tm tp;
+  			  	strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
+  			  	tp.tm_isdst = -1;
+  			  	time_t utc = mktime(&tp);
+  			  	time_t t = time(NULL);
+  			  	double diff_f = difftime(t, utc);
+  			  	int diff_i = (int)diff_f;
+  			  	int quotient = diff_i / 86400;//86400 seconds/day
+  			  	//int remainder = diff_i % 86400;
+
   				for(int k=0; k < TxProfile.TotalPeriod;k++)
   				{
   					if(TxProfile.Period[k].Limit < ChargePointMaxProfile.Period[0].Limit)
@@ -6409,7 +6464,7 @@ int handleGetCompositeScheduleRequest(char *uuid, char *payload)
 
   				for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
   				{
-  					if((TxDefaultProfile.Period[l].StartPeriod < durationInt)&&(TxDefaultProfile.Period[l].StartPeriod > ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period-1].StartPeriod))
+  					if(((TxDefaultProfile.Period[l].StartPeriod % 86400) < durationInt)&& ((TxDefaultProfile.Period[l].StartPeriod / 86400) == quotient)&&((TxDefaultProfile.Period[l].StartPeriod %86400) > ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period-1].StartPeriod))
   					{
   						if(TxDefaultProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
   						{
@@ -6421,14 +6476,14 @@ int handleGetCompositeScheduleRequest(char *uuid, char *payload)
 
   						}
   						ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
-  					  	ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
+  					  	ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = (TxDefaultProfile.Period[l].StartPeriod % 86400);
 
   						period = period + 1;
   				   }
 
-
   			    }
 
+  				// Check Last Period
   				if((TxDefaultProfile.Duration < durationInt) && (ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period-1].Limit) < ChargePointMaxProfile.Period[0].Limit)
   				{
   					ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
@@ -6442,35 +6497,100 @@ int handleGetCompositeScheduleRequest(char *uuid, char *payload)
   			else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==TRUE) )
   			{
   				strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
+  				struct tm tp;
+  				strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
+  			    tp.tm_isdst = -1;
+  			  	time_t utc = mktime(&tp);
+  			  	time_t t = time(NULL);
+  			  	double diff_f = difftime(t, utc);
+  			  	int diff_i = (int)diff_f;
+  			  	int quotient = diff_i / 86400;//86400 seconds/day
+  			  	//int remainder = diff_i % 86400;
+
   				for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
   				{
-  					if(TxProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
+  					if((TxDefaultProfile.Period[l].StartPeriod < durationInt) && ((TxDefaultProfile.Period[l].StartPeriod / 86400) == quotient))
   					{
-  					  	ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
-  					  	ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
-  					  	ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
-  					  	period = period + 1;
+  						if(TxDefaultProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
+  						{
+  					  		ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
+  					  		ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
+  					  		ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
+  					  		period = period + 1;
+  					  	}
+  					  	else
+  					  	{
+  					  	  	ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
+  					  	  	ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
+  					  	  	ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
+  					  	  	period = period + 1;
+  					  	}
   					}
-  					else
-  					{
+  					else if(TxDefaultProfile.Period[l].StartPeriod > durationInt)
+  				  	{
+  				  		 if((TxDefaultProfile.Period[l].StartPeriod / 86400) == quotient)
+  				  		 {
+  				  			 if((TxDefaultProfile.Period[l].StartPeriod % 86400) < durationInt)
+  				  			 {
+  				  				if(TxDefaultProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
+  				  				{
+  				  				  	ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
+  				  				  	ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
+  				  				  	ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
+  				  				  	period = period + 1;
+  				  				}
+  				  				else
+  				  				{
+  				  				  	ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
+  				  				  	ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
+  				  				  	ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
+  				  				  	period = period + 1;
+  				  				}
+  				  			 }
+
+  				  		 }
+  				  	}
 
-  	  				  	ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = ChargePointMaxProfile.Period[0].Limit;
-  	  				  	ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
-  	  				  	ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
-  	  				  	period = period + 1;
-  					}
   				}
 
   			}
   			else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==TRUE) && (TxProfileIsNull==TRUE) )
   		  	{
   				strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
+  				struct tm tp;
+  				strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
+  				tp.tm_isdst = -1;
+  				time_t utc = mktime(&tp);
+  				time_t t = time(NULL);
+  				double diff_f = difftime(t, utc);
+  				int diff_i = (int)diff_f;
+  				int quotient = diff_i / 86400;//86400 seconds/day
+  				//int remainder = diff_i % 86400;
+
   		  		for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
   		  		{
-  		  	  		ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
-  		  	  		ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
-  		  	  		ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
-  		  	  		period = period + 1;
+  		  			if((TxDefaultProfile.Period[l].StartPeriod < durationInt) && ((TxDefaultProfile.Period[l].StartPeriod / 86400) == quotient))
+  		  			{
+  		  				ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
+  		  			  	ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
+  		  			  	ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
+  		  			    period = period + 1;
+  		  			}
+  		  			else if(TxDefaultProfile.Period[l].StartPeriod > durationInt)
+  		  			{
+  		  				if((TxDefaultProfile.Period[l].StartPeriod / 86400) == quotient)
+  		  				{
+  		  					if((TxDefaultProfile.Period[l].StartPeriod % 86400) < durationInt)
+  		  				  	{
+  		  				  		 ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
+  		  				  		 ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
+  		  				  		 ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
+  		  				  		 period = period + 1;
+  		  				  	}
+
+  		  				}
+  		  			}
+
   		  		}
 
   		  	}
@@ -9243,7 +9363,6 @@ int handleSetChargingProfileRequest(char *uuid, char *payload)
 
 	if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
 	{
-		//printf("set chargingProfile 1-2\n");
 		DEBUG_INFO("chargingProfilePurposeStr is ChargePointMaxProfile !!! \n");
 		if(connectorIdInt != 0)
 		{
@@ -9278,7 +9397,6 @@ int handleSetChargingProfileRequest(char *uuid, char *payload)
 	}
 	else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
 	{
-		//printf("set chargingProfile 1-3\n");
 		DEBUG_INFO("chargingProfilePurposeStr is TxDefaultProfile !!! \n");
 		if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
 		{
@@ -9444,10 +9562,11 @@ int handleSetChargingProfileRequest(char *uuid, char *payload)
 			}
 		}
 		fclose(fptr1);
+		DEBUG_INFO("n_chargingProfile_3=%d\n",n_chargingProfile);
 	}
 
 	// Check ChargeProfileMaxStackLevel
-	if(n_chargingProfile > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
+	if(n_chargingProfile >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
 	{
 		sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
 		goto end;

+ 16 - 9
EVSE/Modularization/ocppfiles/Module_OcppBackend.c

@@ -38,7 +38,6 @@
 #define SPEC_LATEST_SUPPORTED 13
 #endif
 
-
 #define Debug
 //#define ARRAY_SIZE(A)		(sizeof(A) / sizeof(A[0]))
 #define PASS				1
@@ -352,6 +351,10 @@ char *random_uuid( char buf[37] )
     return buf;
 }
 
+int GetTransactionQueueNum(void)
+{
+	return TransactionQueueNum;
+}
 
 //==========================================
 // Web socket tranceive routine
@@ -676,7 +679,7 @@ static struct lws_protocols protocols[] = {
 void* ConnectWsServer(void* data)  //int ConnectWsServer()
 {
 	pthread_detach(pthread_self());
-	int result = PASS;
+	//int result = PASS;
 	struct lws_context_creation_info ContextInfo;
 	struct lws_client_connect_info ConnInfo;
 	int use_ssl=0;
@@ -690,8 +693,9 @@ void* ConnectWsServer(void* data)  //int ConnectWsServer()
 
 	if((GetOcppServerURL()==0) || (GetOcppPort() == 0) || (GetOcppPath()==0) )
 	{
-		result = FAIL;
+		//result = FAIL;
 		DEBUG_ERROR("OCPP URL is NULL or OCPP Port is zero or  OCPP Path is NULL\n");
+        goto end;
 		//return result;
 	}
 
@@ -727,10 +731,11 @@ void* ConnectWsServer(void* data)  //int ConnectWsServer()
 	context = lws_create_context(&ContextInfo);
 	if (context == NULL)
 	{
-		#ifdef SystemLogMessage
+		//#ifdef SystemLogMessage
 		DEBUG_ERROR("lws_create_context NG");
-		#endif
-		result = FAIL;
+		//#endif
+		//result = FAIL;
+		goto end;
 	}
 
 	memset(&ConnInfo,0,sizeof(struct lws_client_connect_info));
@@ -756,12 +761,14 @@ void* ConnectWsServer(void* data)  //int ConnectWsServer()
 	wsi_client = lws_client_connect_via_info(&ConnInfo);
 	if (!wsi_client)
 	{
-		#ifdef SystemLogMessage
+		//#ifdef SystemLogMessage
 		DEBUG_ERROR("lws_client_connect_via_info NG");
-		#endif
-		result = FAIL;
+		//#endif
+		//result = FAIL;
+		goto end;
 	}
 
+end:
 	pthread_exit(NULL/*(void *) fname*/);
 	//return result;
 }