Переглянути джерело

2020-04-09 /Kathy Yeh
1. modify offline transaction packets number in queue
2. add ShmSysConfigAndInfo->SysInfo.InternetConn adjudgement

Kathy_Yeh 5 роки тому
батько
коміт
7380d508bd

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

@@ -2037,7 +2037,6 @@ int sendStartTransactionRequest(int gun_index)
 
 	}//END OF ELSE
 
-
 	random_uuid(guid);
 
 	sprintf(message, "[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
@@ -11159,13 +11158,6 @@ DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].
 DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
 #endif
 
-	//if(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "Accepted") == 0)
-	//{
-	//	//add Charging Record
-	//	SettingChargingRecord(gun_index, transactionIdInt);
-	//}
-
-	//DEBUG_INFO("Start Charging ErrorCode=%s\n", ShmOCPP16Data->StatusNotification[gun_index].ErrorCode);
 }
 
 void handleStatusNotificationResponse(char *payload, int gun_index)
@@ -16884,7 +16876,12 @@ void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart
 
 int GetWebSocketPingInterval(void)
 {
-  return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
+	return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
+}
+
+int GetInternetConn(void)
+{
+	return ShmSysConfigAndInfo->SysInfo.InternetConn;
 }
 
 void LWS_Send(char * str)

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

@@ -128,6 +128,7 @@ void GetChargingProfileRequest(int gunindex);
 void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[]);
 void splitstring(char *src,const char *separator,char **dest,int *num);
 int GetWebSocketPingInterval(void);
+int GetInternetConn(void);
  //===============================================
  // sqlite related routine
  //===============================================

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

@@ -33,11 +33,11 @@
 #include    	"MessageHandler.h"
 #include	"sqlite3.h"
 
-
 #ifndef SPEC_LATEST_SUPPORTED
 #define SPEC_LATEST_SUPPORTED 13
 #endif
 
+
 #define Debug
 //#define ARRAY_SIZE(A)		(sizeof(A) / sizeof(A[0]))
 #define PASS				1
@@ -96,10 +96,10 @@ int SendBufLen=(1024*4);//(1024*3);
 int SendBufLen=(1024*4);//(1024*3);
 unsigned char SendBuffer[1024*4]={0};
 static int ConnectionEstablished=0;
-static int TransactionMessageResend = 1;
-static int TransactionQueueInterval = 10;//3; // TransactionMessageAttempts
+static int TransactionMessageResend = 1;  // the number of retry to submit a transaction-related message when the Central System fails to process it.
+static int TransactionQueueInterval = 10;//3;
 static int TransactionQueueNum = 0;
-static int OfflineTransactionQueueNum = 0;
+static int OfflineTransactionQueueNum = 0;  // Number of offline transactions
 static int  OfflineTransaction = 0;
 int defaultWaitingTime = 10; //10 second
 char OcppPath[160]={0};
@@ -497,18 +497,6 @@ static int OCPP16Callback(struct lws *wsi, enum lws_callback_reasons reason, voi
 		#ifdef SystemLogMessage
 		DEBUG_INFO("LWS_CALLBACK_CLIENT_APPEND_HANDSHAKE_HEADER\n");
 		#endif
-#if 0
-		unsigned char **p, *end;
-		struct lws *parent;
-		char buf[8192];
-
-		parent = lws_get_parent(wsi);
-		if (!parent)
-			break;
-
-		p = (unsigned char **)in;
-		end = (*p) + len;
-#endif
 		}
 
 			break;
@@ -519,7 +507,7 @@ DEBUG_INFO("LWS_CALLBACK_CLIENT_ESTABLISHED\n");
 #endif
 				char frontUUID[100] ={0};
 				char frontData[1200] ={0};
-				int queueNotEmpty = 0;
+				int queueNotEmpty = FALSE;
 
 				//connected
 				ConnectionEstablished=1;
@@ -528,7 +516,7 @@ DEBUG_INFO("LWS_CALLBACK_CLIENT_ESTABLISHED\n");
 
 				if(queueNotEmpty == TRUE)
 				{
-					OfflineTransaction = 1;
+					OfflineTransaction = 1; // 0: no packets in queue.     1: There are packets in queue.
 				}
 
 				TransactionQueueInterval = 0;
@@ -615,11 +603,9 @@ DEBUG_INFO("LWS_CALLBACK_CLIENT_ESTABLISHED\n");
 
 		case LWS_CALLBACK_CLIENT_RECEIVE://8
 
-			// lws_rx_flow_control( wsi, 0 );
-
 			((char *)in)[len] = '\0';
 
-			//Print Out Adjudgement
+			//Print out OCPP Message , except for HeartBeat
 			{
 				char *ret, *ret1;
 				ret = strstr((const char *)in, "currentTime");
@@ -863,7 +849,7 @@ else
 	if(log == NULL)
 	{
 		DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
-		return 0;
+		return FALSE;
 	}
 	else
 	{
@@ -976,7 +962,7 @@ else
 	if(log == NULL)
 	{
 		//DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
-		return 0;
+		return FALSE;
 	}
 	else
 	{
@@ -991,8 +977,12 @@ fputs(data, outfile);
 fputs("\n", outfile);
 fclose (outfile);
 TransactionQueueNum = TransactionQueueNum + 1;
+if(OfflineTransaction == 1)  // 0: no offline Transaction      1: offline Transaction
+{
+	OfflineTransactionQueueNum = OfflineTransactionQueueNum + 1;
+}
 DEBUG_INFO("add queue end\n");
-return 0;
+return FALSE;
 
 }
 
@@ -1145,7 +1135,7 @@ else
 	if(log == NULL)
 	{
 		DEBUG_INFO("log is NULL\n");
-		return 0;
+		return FALSE;
 	}
 	else
 	{
@@ -1158,18 +1148,18 @@ char line[1200]={0};
 // check if file exist (and you can open it) or not
 if (fp == NULL) {
 	DEBUG_INFO("can open file TransactionRelatedQueue!");
-  return 0;
+  return FALSE;
 }
 
-TransactionQueueNum = 0;
+TransactionQueueNum = 0;  // the number of packets in queue
 
 while(fgets(line, sizeof line, fp) != NULL) {
 	//DEBUG_INFO("%s\n", line);
-	TransactionQueueNum = TransactionQueueNum + 1;
+	TransactionQueueNum = TransactionQueueNum + 1; //the number of packets in queue
 }
 
 fclose(fp);
-return 1;
+return TRUE;
 
 }
 
@@ -1426,7 +1416,7 @@ return result;
 void* processTransactionQueue(void* data) {
 	char frontUUID[100] ={0};
 	char frontData[1200/*1024*4*/] ={0};
-	int queueNotEmpty = 0;
+	int queueNotEmpty = FALSE;
 
 	while(1)
 	{
@@ -1434,17 +1424,19 @@ void* processTransactionQueue(void* data) {
 		{
 			memset(frontUUID, 0, sizeof(frontUUID));
 			memset(frontData, 0, sizeof(frontData));
-			queueNotEmpty = 0;
+			queueNotEmpty = FALSE;
 
 			queueNotEmpty = queue_operation(1,frontUUID, frontData);//showfront(frontUUID, frontData);    ---> remove temporally
 
-			if((queueNotEmpty == 1) && (GetOcppConnStatus() == 1))
+			if((queueNotEmpty == TRUE) && (GetOcppConnStatus() == 1)) //OcppConnStatus  0: disconnected, 1: connected
 			{
 
-				if((OfflineTransaction == 1) && (OfflineTransactionQueueNum != 0))
+				//DEBUG_INFO("OfflineTransaction=%d\n",OfflineTransaction);
+				//DEBUG_INFO("OfflineTransactionQueueNum=%d\n",OfflineTransactionQueueNum);
+				if((OfflineTransaction == 1) && (OfflineTransactionQueueNum != 0))  //OfflineTransaction   0: no offline Transaction     1: offline Transaction
 				{
 					TransactionQueueInterval = 10;//10;//2;
-					sendbuffer = 1;
+					sendbuffer = 1; // 0: no packets to send    1: send the top packet in queue
 					OfflineTransactionQueueNum = OfflineTransactionQueueNum - 1;
 
 					if(OfflineTransactionQueueNum == 0)
@@ -1452,23 +1444,23 @@ void* processTransactionQueue(void* data) {
 						OfflineTransaction = 0;
 
 					}
-					DEBUG_INFO(" Offline Transaction , online sent queue .... \n");
+					//DEBUG_INFO(" Offline Transaction , online sent queue .... \n");
 					sleep(TransactionQueueInterval);
 				}
 				else
 				{
-					DEBUG_INFO(" online sent queue .... \n");
+					//DEBUG_INFO(" online sent queue .... \n");
 					//OfflineTransaction = 0;
-					if(TransactionMessageResend < TransactionMessageAttemptsGet()) //
+					if(TransactionMessageResend <= TransactionMessageAttemptsGet()) //
 					{
-						//DEBUG_INFO("processTransactionQueue queue is not empty!\n");
-
+						DEBUG_INFO("processTransactionQueue queue is not empty!\n");
 						TransactionQueueInterval= TransactionMessageRetryIntervalGet()* TransactionMessageResend;
-						//DEBUG_INFO("TransactionQueueInterval =%d\n",TransactionQueueInterval);
+						DEBUG_INFO("TransactionQueueInterval =%d\n",TransactionQueueInterval);
+						sleep(TransactionQueueInterval);
 						sendbuffer = 1;
 						TransactionMessageResend = TransactionMessageResend + 1;
-						//DEBUG_INFO("After ADD,TransactionMessageResend=%d\n",TransactionMessageResend);
-						sleep(TransactionQueueInterval);
+						DEBUG_INFO("After ADD,TransactionMessageResend=%d\n",TransactionMessageResend);
+						//sleep(TransactionQueueInterval);
 
 					}
 					else
@@ -1490,10 +1482,10 @@ void* processTransactionQueue(void* data) {
 		if(GetOcppConnStatus() == 0)
 		{
 			//DEBUG_INFO(" Offline .... \n");
-			if(queueNotEmpty == 1)
+			if(queueNotEmpty == TRUE)
 			{
-				OfflineTransaction = 1;
-				DEBUG_INFO(" Offline Transaction .... \n");
+				OfflineTransaction = 1;  // 0: no offline Transaction      1: offline Transaction
+				//DEBUG_INFO(" Offline Transaction .... \n");
 			}
 
 		}
@@ -1509,13 +1501,13 @@ void CheckTransactionPacket(char *uuid)
 {
 	char frontUUID[100]={0};
 	char frontData[1200]={0};
-	int queueNotEmpty = 0;
+	int queueNotEmpty = FALSE;
 	int cmpResult = 0;
 
 	//queue_operation(0,"","");//showqueue(); ---> remove temporally
 	queueNotEmpty = queue_operation(1,frontUUID, frontData);//showfront(frontUUID, frontData);  ---> remove temporally
 
-	if(queueNotEmpty == 1)
+	if(queueNotEmpty == TRUE)
 	{
 		cmpResult = strcmp(frontUUID, uuid);
 
@@ -1776,7 +1768,7 @@ int main(void)
 				SetHeartBeatWithNOResponse();
 			}
 
-			if(changeChageWebSocketPingInterval == TRUE)
+			if((changeChageWebSocketPingInterval == TRUE) || (GetInternetConn() == 0)) // Check InternetConn 0: disconnected, 1: connected
 			{
 				changeChageWebSocketPingInterval = FALSE;
 				lws_context_destroy(context);