Selaa lähdekoodia

2020-03-20 / Kathy Yeh
1. modify OCPP Connection from main process to fork process

Kathy_Yeh 5 vuotta sitten
vanhempi
commit
34ad4235a0
1 muutettua tiedostoa jossa 10 lisäystä ja 7 poistoa
  1. 10 7
      EVSE/Modularization/ocppfiles/Module_OcppBackend.c

+ 10 - 7
EVSE/Modularization/ocppfiles/Module_OcppBackend.c

@@ -33,7 +33,6 @@
 #include    	"MessageHandler.h"
 #include	"sqlite3.h"
 
-
 #ifndef SPEC_LATEST_SUPPORTED
 #define SPEC_LATEST_SUPPORTED 13
 #endif
@@ -669,8 +668,9 @@ static struct lws_protocols protocols[] = {
 };
 
 
-int ConnectWsServer(int  WebSocketPingInterval)
+void* ConnectWsServer(void* data)  //int ConnectWsServer()
 {
+	pthread_detach(pthread_self());
 	int result = PASS;
 	struct lws_context_creation_info ContextInfo;
 	struct lws_client_connect_info ConnInfo;
@@ -687,7 +687,7 @@ int ConnectWsServer(int  WebSocketPingInterval)
 	{
 		result = FAIL;
 		DEBUG_ERROR("OCPP URL is NULL or OCPP Port is zero or  OCPP Path is NULL\n");
-		return result;
+		//return result;
 	}
 
 	if((strcmp(OcppProtocol,"ws")==0)&&(strlen(OcppProtocol)== 2))
@@ -716,9 +716,9 @@ int ConnectWsServer(int  WebSocketPingInterval)
 	}
 
 	ContextInfo.protocols = protocols;
-	ContextInfo.timeout_secs = WebSocketPingInterval;//30;//9999;//30;
+	ContextInfo.timeout_secs = GetWebSocketPingInterval();//WebSocketPingInterval;//30;//9999;//30;
 	//if(ping pong enabled)
-	ContextInfo.ws_ping_pong_interval = WebSocketPingInterval;//30;//0 for none, else interval in seconds
+	ContextInfo.ws_ping_pong_interval = GetWebSocketPingInterval();//WebSocketPingInterval;//30;//0 for none, else interval in seconds
 	context = lws_create_context(&ContextInfo);
 	if (context == NULL)
 	{
@@ -757,7 +757,8 @@ int ConnectWsServer(int  WebSocketPingInterval)
 		result = FAIL;
 	}
 
-	return result;
+	pthread_exit(NULL/*(void *) fname*/);
+	//return result;
 }
 
 //void createq();
@@ -1594,6 +1595,7 @@ int main(void)
 	char rmFileCmd[100]={0};
 	struct stat stats;
 	pthread_t t;
+	pthread_t pid;
 	#ifdef SystemLogMessage
 	DEBUG_INFO("Initialization...\n");
 	#endif
@@ -1704,7 +1706,8 @@ int main(void)
 				#ifdef Debug
 				DEBUG_INFO("Execute ConnectWsServer\n");
 				#endif
-				ConnectWsServer(GetWebSocketPingInterval());
+				//ConnectWsServer();
+				pthread_create(&pid, NULL, ConnectWsServer, NULL);
 				startTime.connect=time((time_t*)NULL);
 			}