Bläddra i källkod

2020.06.24 / Folus Wen

Actions:
1. EVSE/Modularization/Module_PhBackend.c cancel debug info output and connect server depend on internet available.
2. EVSE/Modularization/ocppfiles/MessageHandler.c GetTransactionId() add "isStopTransaction" parameter for query transaction id start by same idtag.
3. EVSE/Modularization/ocppfiles/MessageHandler.c LWS_Send() cancel call lws_service() function to fix websocket lock issue.
4. EVSE/Modularization/ocppfiles/Module_OcppBackend.c processTransactionQueue() sent out period modify.
5. EVSE/Modularization/ocppfiles/Module_OcppBackend.c main() connect server depend on internet available.

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 4 år sedan
förälder
incheckning
1edb9010b5

+ 6 - 1
EVSE/Modularization/Module_PhBackend.c

@@ -30,7 +30,7 @@ int StoreLogMsg(const char *fmt, ...)
 #endif
 
 #ifdef ConsloePrintLog
-	printf("[%04d.%02d.%02d %02d:%02d:%02d] - %s", tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec, buffer);
+	//printf("[%04d.%02d.%02d %02d:%02d:%02d] - %s", tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec, buffer);
 #endif
 
 	return rc;
@@ -1324,6 +1324,11 @@ int main(void)
 
 	for(;;)
 	{
+		while(!ShmSysConfigAndInfo->SysInfo.InternetConn)
+		{
+			sleep(1);
+		}
+
 		bzero(&info,sizeof(info));
 		ghbn = gethostbyname((char*)server_addr);
 		info.sin_family = PF_INET;

+ 28 - 9
EVSE/Modularization/ocppfiles/MessageHandler.c

@@ -2389,7 +2389,7 @@ void CheckSystemValue(void)
 	//==============================================
 	// Meter report
 	//==============================================
-	if(/*(server_sign == TRUE) &&*/(isOFFline() == TRUE) ||
+	if(/*(server_sign == TRUE) &&(isOFFline() == TRUE) ||*/
 	   (((time((time_t*)NULL) - clientTime.MeterValues[gun_index]) > (atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)- 1)) || ((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0)?((getTimePassSinceToday()%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0):FALSE)))
 	{
 		//check Transaction active
@@ -2554,8 +2554,6 @@ void CheckSystemValue(void)
 			}//End for AC
 		}
 
-		clientTime.MeterValues[gun_index] = time((time_t*)NULL);
-
 		if(reqSampleMeter[gun_index] == 1)
 		{
 			sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
@@ -2565,6 +2563,8 @@ void CheckSystemValue(void)
 		{
 			sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
 		}
+
+		clientTime.MeterValues[gun_index] = time((time_t*)NULL);
 		sleep(1);
 	}
 
@@ -4425,7 +4425,7 @@ int sendStopTransactionRequest(int gun_index)
 
 	//----------------------------replace queue StopTransaction TransactionId ---------------------------//
 	//int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
-	int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StartTransaction[gun_index].IdTag);
+	int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StartTransaction[gun_index].IdTag, TRUE);
 
 	if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
 	{
@@ -15186,7 +15186,7 @@ void GetStartTransactionIdTag(int gun_index)
 	strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
 }
 
-int GetTransactionId(int gunindex, unsigned char idTag[])
+int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
 {
 	char ch;
 	FILE *fptr1;
@@ -15226,17 +15226,36 @@ int GetTransactionId(int gunindex, unsigned char idTag[])
 			}
 			char *revbuf[8] = {0}; //存放分割後的子字串
 			int num = 0;//分割後子字串的個數
+			DEBUG_INFO("str: %s\n", str);
 			splitstring(str,",",revbuf,&num); //呼叫函式進行分割
+			DEBUG_INFO("revbuf[0]: %s\n", revbuf[0]);
+			DEBUG_INFO("revbuf[1]: %s\n", revbuf[1]);
+			DEBUG_INFO("revbuf[2]: %s\n", revbuf[2]);
+
 			if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
 			{
-				if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
+				if(isStopTransaction)
+				{
+					if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
+					{
+						temptransactionId = atoi(revbuf[2]);
+						break;
+					}
+				}
+				else
 				{
-					temptransactionId = atoi(revbuf[2]);
-					break;
+					if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
+					{
+						temptransactionId = atoi(revbuf[2]);
+						break;
+					}
 				}
 			}
 		}
 	}
+	else
+		DEBUG_INFO("EOF\n");
+
 
 	fclose(fptr1);
 	/*------- End of reading ---------------*/
@@ -16460,6 +16479,6 @@ void LWS_Send(char * str)
 	pthread_mutex_unlock(&lock_send);
 
 	lws_callback_on_writable(wsi_client);
-	lws_service(context, 0);
+	//lws_service(context, 0);
 	//sleep(1);
 }

+ 1 - 1
EVSE/Modularization/ocppfiles/MessageHandler.h

@@ -535,7 +535,7 @@ extern int queue_operation(int type, char *frontUUID, char *frontData);
 int GetOcppServerURL();
 int GetOcppPath();
 int GetOcppPort();
-int GetTransactionId(int gunindex, unsigned char idTag[]);
+int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction);
 void SetTransactionIdZero(int transactionId);
 void GetChargingProfileRequest(int gunindex);
 void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[]);

+ 53 - 40
EVSE/Modularization/ocppfiles/Module_OcppBackend.c

@@ -36,7 +36,8 @@ unsigned char StartTransactionIdTagTemp[20]={0};
 uint32_t startTimeDog;
 uint32_t startTimeQueue;
 uint8_t	isWebsocketSendable = 1;
-uint8_t	counterLwsRestart=0;;
+uint8_t	counterLwsRestart = 0;;
+uint8_t counterQueueSent = 0;
 
 sqlite3 *db;
 char *errMsg = NULL;
@@ -1024,7 +1025,7 @@ int sentqueue(){
 
 			//From StartTransaction取得IdTag, 存到 StartTransactionIdTagTemp,主要是 給Queue中StopTransaction使用(StartTransaction. StopTransaction不同卡號 ),取得真正的TransactionId
 			GetStartTransactionIdTag(tempconnectorId-1);
-			gettransactionId = GetTransactionId(tempconnectorId, (uint8_t *)StartTransactionIdTagTemp);
+			gettransactionId = GetTransactionId(tempconnectorId, (uint8_t *)StartTransactionIdTagTemp, IsStopTransaction);
 
 			DEBUG_INFO("tempconnectorId = %d\n", tempconnectorId);
 			DEBUG_INFO("temptransactionId = %d\n",temptransactionId);
@@ -1072,7 +1073,7 @@ void* processTransactionQueue(void* data)
 
 	while(1)
 	{
-		if(!req_SendQueue && ((((time((time_t*)NULL) - startTimeQueue) > (TransactionMessageRetryIntervalGet()>10?TransactionMessageRetryIntervalGet():10))) || isWebsocketSendable))
+		if(!req_SendQueue && ((((time((time_t*)NULL) - startTimeQueue) > (TransactionMessageRetryIntervalGet()>10?TransactionMessageRetryIntervalGet():10))) || (isWebsocketSendable && ((time((time_t*)NULL) - startTimeQueue) >= ((counterQueueSent>=10)?10:1)))))
 		{
 			if(FirstHeartBeatResponse() == 1)
 			{
@@ -1134,6 +1135,14 @@ void* processTransactionQueue(void* data)
 
 			// Refresh queue timer
 			startTimeQueue = time((time_t*)NULL);
+			if(counterQueueSent >= 10)
+			{
+				counterQueueSent = 0;
+			}
+			else
+			{
+				counterQueueSent += 1;
+			}
 		}
 
 		usleep(100000);
@@ -1359,7 +1368,7 @@ int main(void)
 		startTimeDog = time((time_t*)NULL);
 		counterLwsRestart = 0;
 		// Connect server
-		while(ConnectionEstablished==0) // Check InternetConn 0: disconnected, 1: connected
+		if(ConnectionEstablished==0) // Check InternetConn 0: disconnected, 1: connected
 		{
 			isWebsocketSendable = 1;
 			SetOcppConnStatus(FALSE);
@@ -1367,52 +1376,56 @@ int main(void)
 			InitialSystemValue();
 			if((time((time_t*)NULL)-startTime.connect) >= 30)
 			{
-				DEBUG_INFO("Server connecting...\n");
-				pthread_create(&tid_connectServer, NULL, ConnectWsServer, NULL);
+				if(GetInternetConn())
+				{
+					DEBUG_INFO("Server connecting...\n");
+					pthread_create(&tid_connectServer, NULL, ConnectWsServer, NULL);
+				}
 				startTime.connect=time((time_t*)NULL);
 			}
 			CheckSystemValue();
-			lws_service(context, 100);//timeout_ms
 		}
-
-		// Sign in
-		if( ((GetBootNotificationInterval() != 0  && ((time((time_t*)NULL)-startTime.bootNotification)>= GetBootNotificationInterval()) )  ||
-			((time((time_t*)NULL)-startTime.bootNotification) >= defaultWaitingTime) ) && (GetServerSign() == FALSE))
-		{
-			sendBootNotificationRequest();
-			startTime.bootNotification=time((time_t*)NULL);
-		}
-
-		// On line operation
-		if(GetServerSign() == TRUE)
+		else
 		{
-			SetOcppConnStatus(TRUE);
-
-			// Send message from queue
-			if((req_SendQueue == 1) && isWebsocketSendable)
+			// Sign in
+			if( ((GetBootNotificationInterval() != 0  && ((time((time_t*)NULL)-startTime.bootNotification)>= GetBootNotificationInterval()) )  ||
+				((time((time_t*)NULL)-startTime.bootNotification) >= defaultWaitingTime) ) && (GetServerSign() == FALSE))
 			{
-				queue_operation(QUEUE_OPERATION_SENT, "", "");
-				req_SendQueue = 0;
+				sendBootNotificationRequest();
+				startTime.bootNotification=time((time_t*)NULL);
 			}
 
-			// Check System Value
-			CheckSystemValue();
-
-			if(GetHeartBeatWithNOResponse() >= 3)
+			// On line operation
+			if(GetServerSign() == TRUE)
 			{
-				lws_context_destroy(context);
-				ConnectionEstablished = 0;
-				context = NULL;
-				SetHeartBeatWithNOResponse();
-			}
+				SetOcppConnStatus(TRUE);
 
-			if((changeChageWebSocketPingInterval == TRUE) || (GetInternetConn() == 0))
-			{
-				DEBUG_INFO("GetInternetConn() = %d\n", GetInternetConn());
-				changeChageWebSocketPingInterval = FALSE;
-				lws_context_destroy(context);
-				ConnectionEstablished = 0;
-				context = NULL;
+				// Send message from queue
+				if((req_SendQueue == 1) && isWebsocketSendable)
+				{
+					queue_operation(QUEUE_OPERATION_SENT, "", "");
+					req_SendQueue = 0;
+				}
+
+				// Check System Value
+				CheckSystemValue();
+
+				if(GetHeartBeatWithNOResponse() >= 3)
+				{
+					lws_context_destroy(context);
+					ConnectionEstablished = 0;
+					context = NULL;
+					SetHeartBeatWithNOResponse();
+				}
+
+				if((changeChageWebSocketPingInterval == TRUE) || (GetInternetConn() == 0))
+				{
+					DEBUG_INFO("GetInternetConn() = %d\n", GetInternetConn());
+					changeChageWebSocketPingInterval = FALSE;
+					lws_context_destroy(context);
+					ConnectionEstablished = 0;
+					context = NULL;
+				}
 			}
 		}
 		lws_service(context, 0);//timeout_ms

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

@@ -120,4 +120,5 @@ extern uint32_t						startTimeDog;
 extern uint32_t						startTimeQueue;
 extern uint8_t						isWebsocketSendable;
 extern uint8_t						counterLwsRestart;
+extern uint8_t 						counterQueueSent;
 #endif /* HEADER_MODULE_OCPPBACKEND_H_ */

BIN
EVSE/rootfs/root/Module_PhBackend