|
@@ -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
|