Sfoglia il codice sorgente

[Improve][Modularization][Module_OcppBackend / Module_OcppBackend20]

2021.11.03 / Folus Wen

Actions:
1. Transaction related message timeout follow TransactionMessageRetryInterval key value.
2. When all connector busy reject RemoteStartTransaction message without connector id.

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 anni fa
parent
commit
c03f41c647

+ 50 - 19
EVSE/Modularization/ocpp20/MessageHandler.c

@@ -7083,7 +7083,7 @@ void CheckSystemValue(void)
 		}
 
 		// Sample period MeterValue
-		if(getDiffSecNow(clientTime.MeterValues[gun_index]) > ((atoi((const char *)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variableAttribute[0].value)>10)?(atoi((const char *)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variableAttribute[0].value)- 1):10))
+		if(getDiffSecNow(clientTime.MeterValues[gun_index]) >= ((atoi((const char *)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variableAttribute[0].value)>5)?(atoi((const char *)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variableAttribute[0].value)- 1):5))
 		{
 			//check Transaction active
 			if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
@@ -15163,28 +15163,57 @@ int handleRequestStartTransactionRequest(char *uuid, char *payload)
 				}
 
 				ShmOCPP20Data->CsMsg.bits[connectorIdx-1].RequestStartTransactionReq = ON;
+				sprintf((char*)ShmOCPP20Data->RequestStartTransaction[connectorIdx-1].Response_status, "%s", RequestStartStopStatusEnumTypeStr[RequestStartStopStatusEnumType_Accepted]);
+				random_uuid((char*)ShmOCPP20Data->RequestStartTransaction[connectorIdx-1].Response_transactionId);
+				result = PASS;
 			}
 			else
 			{
-				if(strlen((char*)filename) > 0)
-				{
-					// Save profile to file
-					sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_Tmp_OCPP20.json");
-					system(cmdBuf);
-
-					sprintf((char*)filename, "/Storage/OCPP/TxProfile_Tmp_OCPP20.json.json");
-					filePtr = fopen((char*)filename, "w");
-					fprintf(filePtr, "{\"evseId\":0,\"chargingProfile\":%s}\n", json_object_to_json_string_ext(json_object_object_get(RemoteStartTransaction, "chargingProfile"), JSON_C_TO_STRING_PLAIN));
-					fclose(filePtr);
-				}
-
-				refreshStartTimer(&clientTime.RemoteStartWait);
-				ShmOCPP20Data->MsMsg.bits.isRemoteStartWaitReq = ON;
+				 uint8_t isHasIdleConnector = FALSE;
+				 for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
+				 {
+					 if(!cpinitateMsg.bits[gun_index].isOnCharging)
+					 {
+						 isHasIdleConnector = TRUE;
+						 break;
+					 }
+				 }
+
+				 if(isHasIdleConnector == TRUE)
+				 {
+					 DEBUG_INFO("Start wait connector link to EV in %s seconds.\n", ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variableAttribute[0].value);
+
+					 if(strlen((char*)filename) > 0)
+					 {
+						 // Save profile to file
+						 sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_Tmp_OCPP20.json");
+						 system(cmdBuf);
+
+						 sprintf((char*)filename, "/Storage/OCPP/TxProfile_Tmp_OCPP20.json.json");
+						 filePtr = fopen((char*)filename, "w");
+						 fprintf(filePtr, "{\"evseId\":0,\"chargingProfile\":%s}\n", json_object_to_json_string_ext(json_object_object_get(RemoteStartTransaction, "chargingProfile"), JSON_C_TO_STRING_PLAIN));
+						 fclose(filePtr);
+					 }
+
+					 refreshStartTimer(&clientTime.RemoteStartWait);
+					 ShmOCPP20Data->MsMsg.bits.isRemoteStartWaitReq = ON;
+
+					 for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
+	 				 {
+						 sprintf((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].Response_status, "%s", RequestStartStopStatusEnumTypeStr[RequestStartStopStatusEnumType_Accepted]);
+						 random_uuid((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].Response_transactionId);
+	 				 }
+
+					 result = PASS;
+				 }
+				 else
+				 {
+					 DEBUG_INFO("There is not any connector is idle.\n");
+
+					 for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
+						 strcpy((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].Response_status, RequestStartStopStatusEnumTypeStr[RequestStartStopStatusEnumType_Rejected]);
+				 }
 			}
-
-			sprintf((char*)ShmOCPP20Data->RequestStartTransaction[connectorIdx-1].Response_status, "%s", RequestStartStopStatusEnumTypeStr[RequestStartStopStatusEnumType_Accepted] );
-			random_uuid((char*)ShmOCPP20Data->RequestStartTransaction[connectorIdx-1].Response_transactionId);
-			result = PASS;
 		}
 		else
 		{
@@ -17897,6 +17926,7 @@ void handleMeterValuesResponse(char *payload, int gun_index)
 	mtrace();
 
 	DEBUG_INFO("handleMeterValuesResponse...\n");
+	isQueueSendable = ON;
 }
 
 void handleNotifyChargingLimitResponse(char *payload, int gun_index)
@@ -18126,6 +18156,7 @@ void handleTransactionEvenResponse(char *payload, int gun_index)
 	}
 	json_object_put(TransactionEven);
 
+	isQueueSendable = ON;
 	ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventConf = ON;
 }
 

+ 21 - 11
EVSE/Modularization/ocpp20/Module_OcppBackend20.c

@@ -14,6 +14,8 @@ struct StartTime
 	struct timespec connect;
 	struct timespec bootNotification;
 	struct timespec reConnect;
+	struct timespec startTimeDog;
+	struct timespec startTimeQueue;
 }startTime;
 
 //==========================================
@@ -33,9 +35,8 @@ char OcppPath[384]={0};
 char OcppProtocol[10]={0},OcppHost[128]={0}, OcppTempPath[256]={0};
 int OcppPort=0;
 unsigned char StartTransactionIdTagTemp[20]={0};
-uint32_t startTimeDog;
-uint32_t startTimeQueue;
 uint8_t	isWebsocketSendable = 1;
+uint8_t	isQueueSendable = 1;
 uint8_t	counterLwsRestart = 0;;
 uint8_t counterQueueSent = 0;
 uint8_t	counterConnect = 0;
@@ -59,8 +60,13 @@ int SendData(struct lws *wsi)
 
     len = strlen((char *)SendBuffer);
 
-    if(len == 0)
-    	return 0;
+    if(len == 0)return 0;
+
+	if((strstr((char*)SendBuffer, "\"MeterValues\"") != NULL)
+	|| (strstr((char*)SendBuffer, "\"TransactionEven\"") != NULL))
+	{
+		isQueueSendable = OFF;
+	}
 
     memcpy (out + LWS_SEND_BUFFER_PRE_PADDING, SendBuffer, len );
     DEBUG_OCPPMESSAGE_INFO("===========> %s\n", out + LWS_SEND_BUFFER_PRE_PADDING);
@@ -892,7 +898,7 @@ void* processTransactionQueue(void* data)
 
 	while(1)
 	{
-		if(!req_SendQueue && ((((time((time_t*)NULL) - startTimeQueue) > (TransactionMessageRetryIntervalGet()>10?TransactionMessageRetryIntervalGet():10))) || (isWebsocketSendable && ((time((time_t*)NULL) - startTimeQueue) >= ((counterQueueSent>=20)?5:1)))))
+		if(!req_SendQueue && ((getDiffSecNow(startTime.startTimeQueue) > (TransactionMessageRetryIntervalGet()>10?TransactionMessageRetryIntervalGet():10)) || (isWebsocketSendable && isQueueSendable && (getDiffSecNow(startTime.startTimeQueue) >= ((counterQueueSent>=20)?5:0)))))
 		{
 			if(FirstHeartBeatResponse() == 1)
 			{
@@ -907,8 +913,11 @@ void* processTransactionQueue(void* data)
 					if(isWebsocketSendable)
 						DEBUG_INFO("isWebsocketSendable on.\n");
 
-					if((((time((time_t*)NULL) - startTimeQueue) > (TransactionMessageRetryIntervalGet()>10?TransactionMessageRetryIntervalGet():10))))
-						DEBUG_INFO("Queue timer(%d) over spec(%d).\n", (time((time_t*)NULL) - startTimeQueue), TransactionMessageRetryIntervalGet());
+					if(isQueueSendable)
+						DEBUG_INFO("isQueueSendable on.\n");
+
+					if(((getDiffSecNow(startTime.startTimeQueue) > (TransactionMessageRetryIntervalGet()>10?TransactionMessageRetryIntervalGet():10))))
+						DEBUG_INFO("Queue timer(%d) over spec(%d).\n", getDiffSecNow(startTime.startTimeQueue), TransactionMessageRetryIntervalGet());
 
 					if((OfflineTransaction == 1) && (OfflineTransactionQueueNum != 0))  //OfflineTransaction   0: no offline Transaction     1: offline Transaction
 					{
@@ -953,7 +962,7 @@ void* processTransactionQueue(void* data)
 			}
 
 			// Refresh queue timer
-			startTimeQueue = time((time_t*)NULL);
+			refreshStartTimer(&startTime.startTimeQueue);
 			if((counterQueueSent >= 10) || (queueNotEmpty == FALSE))
 			{
 				counterQueueSent = 0;
@@ -975,7 +984,7 @@ void* processWatchdog()
 {
 	for(;;)
 	{
-		if(((time((time_t*)NULL) - startTimeDog) > 10) && (context != NULL))
+		if((getDiffSecNow(startTime.startTimeDog) > 10) && (context != NULL))
 		{
 			DEBUG_INFO("LWS watch dog timeout.\n");
 			lws_cancel_service(context);
@@ -989,7 +998,7 @@ void* processWatchdog()
 			else
 				counterLwsRestart++;
 
-			startTimeDog = time((time_t*)NULL);
+			refreshStartTimer(&startTime.startTimeDog);
 		}
 		
 		if(counterConnect >= 2)
@@ -1155,13 +1164,14 @@ int main(void)
 
 	for(;;)
 	{
-		startTimeDog = time((time_t*)NULL);
+		refreshStartTimer(&startTime.startTimeDog);
 		counterLwsRestart = 0;
 		// Connect server
 
 		if(ConnectionEstablished==0) // Check InternetConn 0: disconnected, 1: connected
 		{
 			isWebsocketSendable = 1;
+			isQueueSendable = 1;
 			SetOcppConnStatus(FALSE);
 			SetServerSign(FALSE);
 			InitialSystemValue();

+ 1 - 2
EVSE/Modularization/ocpp20/Module_OcppBackend20.h

@@ -169,9 +169,8 @@ extern char 						OcppTempPath[256];
 extern int 							OcppPort;
 extern unsigned char 				StartTransactionIdTagTemp[20];
 extern pthread_mutex_t 				lock_send;
-extern uint32_t						startTimeDog;
-extern uint32_t						startTimeQueue;
 extern uint8_t						isWebsocketSendable;
+extern uint8_t						isQueueSendable;
 extern uint8_t						counterLwsRestart;
 extern uint8_t 						counterQueueSent;
 #endif /* HEADER_MODULE_OCPPBACKEND20_H_ */

+ 47 - 26
EVSE/Modularization/ocppfiles/MessageHandler.c

@@ -4727,7 +4727,7 @@ void CheckSystemValue(void)
 		}
 
 		// Sample period MeterValue
-		if(((getDiffSecNow(clientTime.MeterValues[gun_index]) > ((atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData))>5?(atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)- 1):5))))
+		if(((getDiffSecNow(clientTime.MeterValues[gun_index]) >= ((atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData))>5?(atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)- 1):5))))
 		{
 			//check Transaction active
 			if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
@@ -11686,7 +11686,7 @@ int handleRemoteStartRequest(char *uuid, char *payload)
 								&& (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) 	//S_PREPARING_FOR_EV
 								&& (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE ))   // S_PREPARING_FOR_EVSE
 							{
-								DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n.");
+								DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n");
 								strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
 								goto end;
 							}
@@ -11732,7 +11732,7 @@ int handleRemoteStartRequest(char *uuid, char *payload)
 								&& (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV)   	//S_PREPARING_FOR_EV
 								&& (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) 	// S_PREPARING_FOR_EVSE
 							{
-								DEBUG_WARN("CCS connector not allow start cause busy.\n.");
+								DEBUG_WARN("CCS connector not allow start cause busy.\n");
 								strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
 								goto end;
 							}
@@ -11779,7 +11779,7 @@ int handleRemoteStartRequest(char *uuid, char *payload)
 								&& (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV)		//S_PREPARING_FOR_EV
 								&& (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) 		// S_PREPARING_FOR_EVSE
 							{
-								DEBUG_WARN("GBT connector not allow start cause busy.\n.");
+								DEBUG_WARN("GBT connector not allow start cause busy.\n");
 								strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
 								goto end;
 							}
@@ -11820,7 +11820,7 @@ int handleRemoteStartRequest(char *uuid, char *payload)
 								&& (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV)		//S_PREPARING_FOR_EV
 								&& (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) 		// S_PREPARING_FOR_EVSE
 							{
-								DEBUG_WARN("Dispenser connector not allow start cause busy.\n.");
+								DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
 								strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
 								goto end;
 							}
@@ -11869,7 +11869,7 @@ int handleRemoteStartRequest(char *uuid, char *payload)
 								&& (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) 	//S_PREPARING_FOR_EV
 								&& (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE))   // S_PREPARING_FOR_EVSE
 							{
-								DEBUG_WARN("AC connector not allow start cause busy.\n.");
+								DEBUG_WARN("AC connector not allow start cause busy.\n");
 								strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
 								goto end;
 							}
@@ -11894,7 +11894,7 @@ int handleRemoteStartRequest(char *uuid, char *payload)
 				}
 				else
 				{
-					DEBUG_WARN("Profile purpose not TxProfile.\n.");
+					DEBUG_WARN("Profile purpose not TxProfile.\n");
 					strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
 					goto end;
 				}
@@ -11912,31 +11912,49 @@ int handleRemoteStartRequest(char *uuid, char *payload)
 		 }
 		 else
 		 {
-			 DEBUG_WARN("Start wait connector link to EV in %s seconds.\n.", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
-
-			 if(ShmOCPP16Data->RemoteStartTransaction[0].ChargingProfile.ChargingProfileId > -1)
+			 uint8_t isHasIdleConnector = FALSE;
+			 for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
 			 {
-				 if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[0].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
+				 if(!cpinitateMsg.bits[gun_index].isOnCharging)
 				 {
-					 // Save profile to file
-					 sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_Tmp.json");
-					 system(cmdBuf);
-
-					 sprintf(cmdBuf, "/Storage/OCPP/TxProfile_Tmp.json");
-					 fp = fopen(cmdBuf, "w");
-					 fprintf(fp, "{\"connectorId\":0,\"csChargingProfiles\":%s}\n", json_object_to_json_string_ext(json_object_object_get(RemoteStartTransaction, "chargingProfile"), JSON_C_TO_STRING_PLAIN));
-					 fclose(fp);
-
-					 refreshStartTimer(&clientTime.RemoteStartWait);
-					 ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 1;
-					 strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
+					 isHasIdleConnector = TRUE;
+					 break;
 				 }
-				 else
+			 }
+
+			 if(isHasIdleConnector == TRUE)
+			 {
+				 DEBUG_INFO("Start wait connector link to EV in %s seconds.\n", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
+
+				 if(ShmOCPP16Data->RemoteStartTransaction[0].ChargingProfile.ChargingProfileId > -1)
 				 {
-					 DEBUG_WARN("Profile purpose not TxProfile.\n.");
-					 strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
+					 if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[0].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
+					 {
+						 // Save profile to file
+						 sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_Tmp.json");
+						 system(cmdBuf);
+
+						 sprintf(cmdBuf, "/Storage/OCPP/TxProfile_Tmp.json");
+						 fp = fopen(cmdBuf, "w");
+						 fprintf(fp, "{\"connectorId\":0,\"csChargingProfiles\":%s}\n", json_object_to_json_string_ext(json_object_object_get(RemoteStartTransaction, "chargingProfile"), JSON_C_TO_STRING_PLAIN));
+						 fclose(fp);
+
+						 refreshStartTimer(&clientTime.RemoteStartWait);
+						 ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 1;
+						 strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
+					 }
+					 else
+					 {
+						 DEBUG_WARN("Profile purpose not TxProfile.\n");
+						 strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
+					 }
 				 }
 			 }
+			 else
+			 {
+				 DEBUG_INFO("There is not any connector is idle.\n");
+				 strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
+			 }
 		 }
 	}
 	else
@@ -14605,6 +14623,7 @@ void handleMeterValuesResponse(char *payload, int gun_index)
 {
 	mtrace();
 	DEBUG_INFO("handleMeterValuesResponse...\n");
+	isQueueSendable = 1;
 }
 
 void handleStartTransactionResponse(char *payload, int gun_index)
@@ -14634,6 +14653,7 @@ void handleStartTransactionResponse(char *payload, int gun_index)
 	}
 	json_object_put(StartTransaction);
 
+	isQueueSendable = 1;
 	ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
 	ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
 
@@ -14706,6 +14726,7 @@ void handleStopTransactionnResponse(char *payload, int gun_index)
 	}
 	json_object_put(StopTransaction);
 
+	isQueueSendable = 1;
 	ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
 	ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
 

+ 22 - 11
EVSE/Modularization/ocppfiles/Module_OcppBackend.c

@@ -14,6 +14,8 @@ struct StartTime
 	struct timespec connect;
 	struct timespec bootNotification;
 	struct timespec reConnect;
+	struct timespec startTimeDog;
+	struct timespec startTimeQueue;
 }startTime;
 
 struct QueueOpInfo queueOpInfo;
@@ -31,9 +33,8 @@ char OcppPath[384]={0};
 char OcppProtocol[10]={0},OcppHost[128]={0}, OcppTempPath[256]={0};
 int OcppPort=0;
 unsigned char StartTransactionIdTagTemp[20]={0};
-uint32_t startTimeDog;
-uint32_t startTimeQueue;
 uint8_t	isWebsocketSendable = 1;
+uint8_t	isQueueSendable = 1;
 uint8_t	counterLwsRestart = 0;
 uint8_t counterQueueSent = 0;
 uint8_t	counterConnect = 0;
@@ -110,8 +111,14 @@ int SendData(struct lws *wsi)
 
     len = strlen((char *)SendBuffer);
 
-    if(len == 0)
-    	return 0;
+    if(len == 0)return 0;
+
+	if((strstr((char*)SendBuffer, "\"MeterValues\"") != NULL)
+	|| (strstr((char*)SendBuffer, "\"StartTransaction\"") != NULL)
+	|| (strstr((char*)SendBuffer, "\"StopTransaction\"") != NULL))
+	{
+		isQueueSendable = 0;
+	}
 
     memcpy (out + LWS_SEND_BUFFER_PRE_PADDING, SendBuffer, len );
     DEBUG_OCPPMESSAGE_INFO("===========> %s\n", out + LWS_SEND_BUFFER_PRE_PADDING);
@@ -1172,7 +1179,7 @@ void* processTransactionQueue(void* data)
 
 	while(1)
 	{
-		if(!req_SendQueue && ((((time((time_t*)NULL) - startTimeQueue) > (TransactionMessageRetryIntervalGet()>10?TransactionMessageRetryIntervalGet():10))) || (isWebsocketSendable && ((time((time_t*)NULL) - startTimeQueue) >= ((counterQueueSent>=20)?5:0)))))
+		if(!req_SendQueue && ((getDiffSecNow(startTime.startTimeQueue) > (TransactionMessageRetryIntervalGet()>10?TransactionMessageRetryIntervalGet():10)) || (isWebsocketSendable && isQueueSendable && (getDiffSecNow(startTime.startTimeQueue) >= ((counterQueueSent>=20)?5:0)))))
 		{
 			if(FirstHeartBeatResponse() == 1)
 			{
@@ -1187,8 +1194,11 @@ void* processTransactionQueue(void* data)
 					if(isWebsocketSendable)
 						DEBUG_INFO("isWebsocketSendable on.\n");
 
-					if((((time((time_t*)NULL) - startTimeQueue) > (TransactionMessageRetryIntervalGet()>10?TransactionMessageRetryIntervalGet():10))))
-						DEBUG_INFO("Queue timer(%d) over spec(%d).\n", (time((time_t*)NULL) - startTimeQueue), TransactionMessageRetryIntervalGet());
+					if(isQueueSendable)
+						DEBUG_INFO("isQueueSendable on.\n");
+
+					if(((getDiffSecNow(startTime.startTimeQueue) > (TransactionMessageRetryIntervalGet()>10?TransactionMessageRetryIntervalGet():10))))
+						DEBUG_INFO("Queue timer(%d) over spec(%d).\n", getDiffSecNow(startTime.startTimeQueue), TransactionMessageRetryIntervalGet());
 
 					if((queueOpInfo.OfflineTransaction == 1) && (queueOpInfo.OfflineTransactionQueueNum != 0))  //OfflineTransaction   0: no offline Transaction     1: offline Transaction
 					{
@@ -1233,7 +1243,7 @@ void* processTransactionQueue(void* data)
 			}
 
 			// Refresh queue timer
-			startTimeQueue = time((time_t*)NULL);
+			refreshStartTimer(&startTime.startTimeQueue);
 			if((counterQueueSent >= 10) || (queueNotEmpty == FALSE))
 			{
 				counterQueueSent = 0;
@@ -1255,7 +1265,7 @@ void* processWatchdog()
 {
 	for(;;)
 	{
-		if(((time((time_t*)NULL) - startTimeDog) > 10) && (context != NULL))
+		if((getDiffSecNow(startTime.startTimeDog) > 10) && (context != NULL))
 		{
 			DEBUG_INFO("LWS watch dog timeout.\n");
 			lws_cancel_service(context);
@@ -1269,7 +1279,7 @@ void* processWatchdog()
 			else
 				counterLwsRestart++;
 
-			startTimeDog = time((time_t*)NULL);
+			refreshStartTimer(&startTime.startTimeDog);
 		}
 
 		if(counterConnect >= 2)
@@ -1496,12 +1506,13 @@ int main(void)
 
 	for(;;)
 	{
-		startTimeDog = time((time_t*)NULL);
+		refreshStartTimer(&startTime.startTimeDog);
 		counterLwsRestart = 0;
 		// Connect server
 		if(ConnectionEstablished==0) // Check InternetConn 0: disconnected, 1: connected
 		{
 			isWebsocketSendable = 1;
+			isQueueSendable = 1;
 			SetOcppConnStatus(FALSE);
 			SetServerSign(FALSE);
 			InitialSystemValue();

+ 1 - 2
EVSE/Modularization/ocppfiles/Module_OcppBackend.h

@@ -170,9 +170,8 @@ extern char 						OcppTempPath[256];
 extern int 							OcppPort;
 extern unsigned char 				StartTransactionIdTagTemp[20];
 extern pthread_mutex_t 				lock_send;
-extern uint32_t						startTimeDog;
-extern uint32_t						startTimeQueue;
 extern uint8_t						isWebsocketSendable;
+extern uint8_t						isQueueSendable;
 extern uint8_t						counterLwsRestart;
 extern uint8_t 						counterQueueSent;
 #endif /* HEADER_MODULE_OCPPBACKEND_H_ */

+ 47 - 27
EVSE/Modularization/ocppph/MessageHandler.c

@@ -4448,7 +4448,7 @@ void CheckSystemValue(void)
 		}
 
 		// Sample period MeterValue
-		if(((getDiffSecNow(clientTime.MeterValues[gun_index]) > ((atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData))>5?(atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)- 1):5))))
+		if(((getDiffSecNow(clientTime.MeterValues[gun_index]) >= ((atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData))>5?(atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)- 1):5))))
 				{
 			//check Transaction active
 			if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
@@ -11427,7 +11427,7 @@ int handleRemoteStartRequest(char *uuid, char *payload)
 								&& (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) 	//S_PREPARING_FOR_EV
 								&& (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE ))   // S_PREPARING_FOR_EVSE
 							{
-								DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n.");
+								DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n");
 								strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
 								goto end;
 							}
@@ -11473,7 +11473,7 @@ int handleRemoteStartRequest(char *uuid, char *payload)
 								&& (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV)   	//S_PREPARING_FOR_EV
 								&& (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) 	// S_PREPARING_FOR_EVSE
 							{
-								DEBUG_WARN("CCS connector not allow start cause busy.\n.");
+								DEBUG_WARN("CCS connector not allow start cause busy.\n");
 								strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
 								goto end;
 							}
@@ -11520,7 +11520,7 @@ int handleRemoteStartRequest(char *uuid, char *payload)
 								&& (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV)		//S_PREPARING_FOR_EV
 								&& (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) 		// S_PREPARING_FOR_EVSE
 							{
-								DEBUG_WARN("GBT connector not allow start cause busy.\n.");
+								DEBUG_WARN("GBT connector not allow start cause busy.\n");
 								strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
 								goto end;
 							}
@@ -11561,7 +11561,7 @@ int handleRemoteStartRequest(char *uuid, char *payload)
 								&& (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV)		//S_PREPARING_FOR_EV
 								&& (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) 		// S_PREPARING_FOR_EVSE
 							{
-								DEBUG_WARN("Dispenser connector not allow start cause busy.\n.");
+								DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
 								strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
 								goto end;
 							}
@@ -11610,7 +11610,7 @@ int handleRemoteStartRequest(char *uuid, char *payload)
 								&& (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) 	//S_PREPARING_FOR_EV
 								&& (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE))   // S_PREPARING_FOR_EVSE
 							{
-								DEBUG_WARN("AC connector not allow start cause busy.\n.");
+								DEBUG_WARN("AC connector not allow start cause busy.\n");
 								strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
 								goto end;
 							}
@@ -11635,7 +11635,7 @@ int handleRemoteStartRequest(char *uuid, char *payload)
 				}
 				else
 				{
-					DEBUG_WARN("Profile purpose not TxProfile.\n.");
+					DEBUG_WARN("Profile purpose not TxProfile.\n");
 					strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
 					goto end;
 				}
@@ -11653,31 +11653,49 @@ int handleRemoteStartRequest(char *uuid, char *payload)
 		 }
 		 else
 		 {
-			 DEBUG_WARN("Start wait connector link to EV in %s seconds.\n.", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
-
-			 if(ShmOCPP16DataPH->RemoteStartTransaction[0].ChargingProfile.ChargingProfileId > -1)
+			 uint8_t isHasIdleConnector = FALSE;
+			 for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
 			 {
-				 if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[0].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
+				 if(!cpinitateMsg.bits[gun_index].isOnCharging)
 				 {
-					 // Save profile to file
-					 sprintf(cmdBuf, "rm -f /Storage/OCPP_PH/TxProfile_Tmp.json");
-					 system(cmdBuf);
-
-					 sprintf(cmdBuf, "/Storage/OCPP_PH/TxProfile_Tmp.json");
-					 fp = fopen(cmdBuf, "w");
-					 fprintf(fp, "{\"connectorId\":0,\"csChargingProfiles\":%s}\n", json_object_to_json_string_ext(json_object_object_get(RemoteStartTransaction, "chargingProfile"), JSON_C_TO_STRING_PLAIN));
-					 fclose(fp);
-
-					 refreshStartTimer(&clientTime.RemoteStartWait);
-					 ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq = 1;
-					 strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
+					 isHasIdleConnector = TRUE;
+					 break;
 				 }
-				 else
+			 }
+
+			 if(isHasIdleConnector == TRUE)
+			 {
+				 DEBUG_INFO("Start wait connector link to EV in %s seconds.\n", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
+
+				 if(ShmOCPP16DataPH->RemoteStartTransaction[0].ChargingProfile.ChargingProfileId > -1)
 				 {
-					 DEBUG_WARN("Profile purpose not TxProfile.\n.");
-					 strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
+					 if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[0].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
+					 {
+						 // Save profile to file
+						 sprintf(cmdBuf, "rm -f /Storage/OCPP_PH/TxProfile_Tmp.json");
+						 system(cmdBuf);
+
+						 sprintf(cmdBuf, "/Storage/OCPP_PH/TxProfile_Tmp.json");
+						 fp = fopen(cmdBuf, "w");
+						 fprintf(fp, "{\"connectorId\":0,\"csChargingProfiles\":%s}\n", json_object_to_json_string_ext(json_object_object_get(RemoteStartTransaction, "chargingProfile"), JSON_C_TO_STRING_PLAIN));
+						 fclose(fp);
+
+						 refreshStartTimer(&clientTime.RemoteStartWait);
+						 ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq = 1;
+						 strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
+					 }
+					 else
+					 {
+						 DEBUG_WARN("Profile purpose not TxProfile.\n");
+						 strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
+					 }
 				 }
 			 }
+			 else
+			 {
+				 DEBUG_INFO("There is not any connector is idle.\n");
+				 strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
+			 }
 		 }
 	}
 	else
@@ -14340,6 +14358,7 @@ void handleMeterValuesResponse(char *payload, int gun_index)
 {
 	mtrace();
 	DEBUG_INFO("handleMeterValuesResponse...\n");
+	isQueueSendable = 1;
 }
 
 void handleStartTransactionResponse(char *payload, int gun_index)
@@ -14369,6 +14388,7 @@ void handleStartTransactionResponse(char *payload, int gun_index)
 	}
 	json_object_put(StartTransaction);
 
+	isQueueSendable = 1;
 	ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionConf = 1;
 	ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq = 0;
 
@@ -14441,7 +14461,7 @@ void handleStopTransactionnResponse(char *payload, int gun_index)
 	}
 	json_object_put(StopTransaction);
 
-
+	isQueueSendable = 1;
 	ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionConf = 1;
 	ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
 

+ 22 - 11
EVSE/Modularization/ocppph/Module_OcppBackend.c

@@ -14,6 +14,8 @@ struct StartTime
 	struct timespec connect;
 	struct timespec bootNotification;
 	struct timespec reConnect;
+	struct timespec startTimeDog;
+	struct timespec startTimeQueue;
 }startTime;
 
 struct QueueOpInfo queueOpInfo;
@@ -31,9 +33,8 @@ char OcppPath[384]={0};
 char OcppProtocol[10]={0},OcppHost[128]={0}, OcppTempPath[256]={0};
 int OcppPort=0;
 unsigned char StartTransactionIdTagTemp[20]={0};
-uint32_t startTimeDog;
-uint32_t startTimeQueue;
 uint8_t	isWebsocketSendable = 1;
+uint8_t	isQueueSendable = 1;
 uint8_t	counterLwsRestart = 0;
 uint8_t counterQueueSent = 0;
 uint8_t	counterConnect = 0;
@@ -110,8 +111,14 @@ int SendData(struct lws *wsi)
 
     len = strlen((char *)SendBuffer);
 
-    if(len == 0)
-    	return 0;
+    if(len == 0)return 0;
+
+    if((strstr((char*)SendBuffer, "\"MeterValues\"") != NULL)
+    || (strstr((char*)SendBuffer, "\"StartTransaction\"") != NULL)
+    || (strstr((char*)SendBuffer, "\"StopTransaction\"") != NULL))
+    {
+    	isQueueSendable = 0;
+    }
 
     memcpy (out + LWS_SEND_BUFFER_PRE_PADDING, SendBuffer, len );
     DEBUG_OCPPMESSAGE_INFO("===========> %s\n", out + LWS_SEND_BUFFER_PRE_PADDING);
@@ -1173,7 +1180,7 @@ void* processTransactionQueue(void* data)
 
 	while(1)
 	{
-		if(!req_SendQueue && ((((time((time_t*)NULL) - startTimeQueue) > (TransactionMessageRetryIntervalGet()>10?TransactionMessageRetryIntervalGet():10))) || (isWebsocketSendable && ((time((time_t*)NULL) - startTimeQueue) >= ((counterQueueSent>=20)?5:0)))))
+		if(!req_SendQueue && ((getDiffSecNow(startTime.startTimeQueue) > (TransactionMessageRetryIntervalGet()>10?TransactionMessageRetryIntervalGet():10)) || (isWebsocketSendable && isQueueSendable && (getDiffSecNow(startTime.startTimeQueue) >= ((counterQueueSent>=20)?5:0)))))
 		{
 			if(FirstHeartBeatResponse() == 1)
 			{
@@ -1188,8 +1195,11 @@ void* processTransactionQueue(void* data)
 					if(isWebsocketSendable)
 						DEBUG_INFO("isWebsocketSendable on.\n");
 
-					if((((time((time_t*)NULL) - startTimeQueue) > (TransactionMessageRetryIntervalGet()>10?TransactionMessageRetryIntervalGet():10))))
-						DEBUG_INFO("Queue timer(%d) over spec(%d).\n", (time((time_t*)NULL) - startTimeQueue), TransactionMessageRetryIntervalGet());
+					if(isQueueSendable)
+						DEBUG_INFO("isQueueSendable on.\n");
+
+					if(((getDiffSecNow(startTime.startTimeQueue) > (TransactionMessageRetryIntervalGet()>10?TransactionMessageRetryIntervalGet():10))))
+						DEBUG_INFO("Queue timer(%d) over spec(%d).\n", getDiffSecNow(startTime.startTimeQueue), TransactionMessageRetryIntervalGet());
 
 					if((queueOpInfo.OfflineTransaction == 1) && (queueOpInfo.OfflineTransactionQueueNum != 0))  //OfflineTransaction   0: no offline Transaction     1: offline Transaction
 					{
@@ -1234,7 +1244,7 @@ void* processTransactionQueue(void* data)
 			}
 
 			// Refresh queue timer
-			startTimeQueue = time((time_t*)NULL);
+			refreshStartTimer(&startTime.startTimeQueue);
 			if((counterQueueSent >= 10) || (queueNotEmpty == FALSE))
 			{
 				counterQueueSent = 0;
@@ -1256,7 +1266,7 @@ void* processWatchdog()
 {
 	for(;;)
 	{
-		if(((time((time_t*)NULL) - startTimeDog) > 10) && (context != NULL))
+		if((getDiffSecNow(startTime.startTimeDog) > 10) && (context != NULL))
 		{
 			DEBUG_INFO("LWS watch dog timeout.\n");
 			lws_cancel_service(context);
@@ -1270,7 +1280,7 @@ void* processWatchdog()
 			else
 				counterLwsRestart++;
 
-			startTimeDog = time((time_t*)NULL);
+			refreshStartTimer(&startTime.startTimeDog);
 		}
 
 		if(counterConnect >= 2)
@@ -1497,12 +1507,13 @@ int main(void)
 
 	for(;;)
 	{
-		startTimeDog = time((time_t*)NULL);
+		refreshStartTimer(&startTime.startTimeDog);
 		counterLwsRestart = 0;
 		// Connect server
 		if(ConnectionEstablished==0) // Check InternetConn 0: disconnected, 1: connected
 		{
 			isWebsocketSendable = 1;
+			isQueueSendable = 1;
 			SetOcppConnStatus(FALSE);
 			SetServerSign(FALSE);
 			InitialSystemValue();

+ 1 - 2
EVSE/Modularization/ocppph/Module_OcppBackend.h

@@ -170,9 +170,8 @@ extern char 						OcppTempPath[256];
 extern int 							OcppPort;
 extern unsigned char 				StartTransactionIdTagTemp[20];
 extern pthread_mutex_t 				lock_send;
-extern uint32_t						startTimeDog;
-extern uint32_t						startTimeQueue;
 extern uint8_t						isWebsocketSendable;
+extern uint8_t						isQueueSendable;
 extern uint8_t						counterLwsRestart;
 extern uint8_t 						counterQueueSent;
 #endif /* HEADER_MODULE_OCPPBACKEND_H_ */