|
@@ -18,6 +18,8 @@ struct StartTime
|
|
|
struct timespec startTimeQueue;
|
|
|
}startTime;
|
|
|
|
|
|
+struct QueueOpInfo queueOpInfo;
|
|
|
+
|
|
|
//==========================================
|
|
|
// Function prototype
|
|
|
//==========================================
|
|
@@ -25,11 +27,7 @@ void ReceivedMessage(void *in, size_t len);
|
|
|
int SendBufLen=0;//(1024*4);//(1024*3);
|
|
|
unsigned char SendBuffer[WEBSOCKET_BUFFER_SIZE]={0};
|
|
|
static int ConnectionEstablished=0;
|
|
|
-static int TransactionMessageResend = 1; // the number of retry to submit a transaction-related message when the Central System fails to process it.
|
|
|
-static int TransactionQueueNum = 0;
|
|
|
-static int OfflineTransactionQueueNum = 0; // Number of offline transactions
|
|
|
-static int OfflineTransaction = 0;
|
|
|
-static int IsUsing = FALSE;
|
|
|
+int defaultWaitingTime = 10; //10 second
|
|
|
|
|
|
char OcppPath[384]={0};
|
|
|
char OcppProtocol[10]={0},OcppHost[128]={0}, OcppTempPath[256]={0};
|
|
@@ -46,7 +44,7 @@ uint8_t counterConnect = 0;
|
|
|
//=================================
|
|
|
int GetTransactionQueueNum(void)
|
|
|
{
|
|
|
- return TransactionQueueNum;
|
|
|
+ return queueOpInfo.TransactionQueueNum;
|
|
|
}
|
|
|
|
|
|
//==========================================
|
|
@@ -191,26 +189,10 @@ static int OCPP20Callback(struct lws *wsi, enum lws_callback_reasons reason, voi
|
|
|
case LWS_CALLBACK_CLIENT_ESTABLISHED: //3
|
|
|
DEBUG_INFO("LWS_CALLBACK_CLIENT_ESTABLISHED\n");
|
|
|
|
|
|
- char frontUUID[100] ={0};
|
|
|
- char frontData[QUEUE_MESSAGE_LENGTH] ={0};
|
|
|
- int queueNotEmpty = FALSE;
|
|
|
-
|
|
|
//connected
|
|
|
ConnectionEstablished=1;
|
|
|
SetOcppConnStatus(TRUE);
|
|
|
|
|
|
- queueNotEmpty = queue_operation(QUEUE_OPERATION_SHOWFRONT,frontUUID, frontData);
|
|
|
-
|
|
|
- if(queueNotEmpty == TRUE)
|
|
|
- {
|
|
|
- OfflineTransaction = 1; // 0: no packets in queue. 1: There are packets in queue.
|
|
|
- }
|
|
|
-
|
|
|
- TransactionMessageResend = 1;
|
|
|
-
|
|
|
- //get offline number
|
|
|
- queue_operation(QUEUE_OPERATION_SHOWQUEUE,"","");
|
|
|
- OfflineTransactionQueueNum =TransactionQueueNum ;
|
|
|
break;
|
|
|
case LWS_CALLBACK_CLIENT_CONNECTION_ERROR://1
|
|
|
DEBUG_ERROR("LWS_CALLBACK_CLIENT_CONNECTION_ERROR %s\n", (char *)in );
|
|
@@ -651,11 +633,7 @@ int addq(char *uuid, char *data)
|
|
|
fputs(data, outfile);
|
|
|
fputs("\n", outfile);
|
|
|
fclose (outfile);
|
|
|
- TransactionQueueNum = TransactionQueueNum + 1;
|
|
|
- if(OfflineTransaction == 1) // 0: no offline Transaction 1: offline Transaction
|
|
|
- {
|
|
|
- OfflineTransactionQueueNum = OfflineTransactionQueueNum + 1;
|
|
|
- }
|
|
|
+ queueOpInfo.TransactionQueueNum += 1;
|
|
|
DEBUG_INFO("add queue end\n");
|
|
|
system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
|
|
|
return FALSE;
|
|
@@ -742,8 +720,8 @@ int delq()
|
|
|
|
|
|
if(i==0)
|
|
|
{
|
|
|
- TransactionQueueNum = TransactionQueueNum - 1;
|
|
|
- TransactionMessageResend = 1;
|
|
|
+ queueOpInfo.TransactionQueueNum -= 1;
|
|
|
+ queueOpInfo.TransactionMessageResend = 0;
|
|
|
DEBUG_INFO("delete the item\n");
|
|
|
}
|
|
|
|
|
@@ -827,11 +805,11 @@ int showqueue()
|
|
|
return FALSE;
|
|
|
}
|
|
|
|
|
|
- TransactionQueueNum = 0; // the number of packets in queue
|
|
|
+ queueOpInfo.TransactionQueueNum = 0; // the number of packets in queue
|
|
|
|
|
|
while(fgets(line, sizeof line, fp) != NULL) {
|
|
|
//DEBUG_INFO("%s\n", line);
|
|
|
- TransactionQueueNum = TransactionQueueNum + 1; //the number of packets in queue
|
|
|
+ queueOpInfo.TransactionQueueNum += 1; //the number of packets in queue
|
|
|
}
|
|
|
|
|
|
fclose(fp);
|
|
@@ -893,22 +871,20 @@ int sentqueue(){
|
|
|
void* processTransactionQueue(void* data)
|
|
|
{
|
|
|
char frontUUID[100] ={0};
|
|
|
- char frontData[QUEUE_MESSAGE_LENGTH/*1024*4*/] ={0};
|
|
|
+ char frontData[QUEUE_MESSAGE_LENGTH] ={0};
|
|
|
int queueNotEmpty = FALSE;
|
|
|
|
|
|
while(1)
|
|
|
{
|
|
|
- if(!req_SendQueue && ((getDiffSecNow(startTime.startTimeQueue) > (TransactionMessageRetryIntervalGet()>10?TransactionMessageRetryIntervalGet():10)) || (isWebsocketSendable && isQueueSendable && (getDiffSecNow(startTime.startTimeQueue) >= ((counterQueueSent>=20)?5:0)))))
|
|
|
+ if(!req_SendQueue && ((getDiffSecNow(startTime.startTimeQueue) >= ((TransactionMessageRetryIntervalGet()>10?TransactionMessageRetryIntervalGet():10)*(queueOpInfo.TransactionMessageResend>1?2:1))) || (isWebsocketSendable && isQueueSendable && (getDiffSecNow(startTime.startTimeQueue) >= ((counterQueueSent>=20)?5:0)))))
|
|
|
{
|
|
|
if(FirstHeartBeatResponse() == 1)
|
|
|
{
|
|
|
memset(frontUUID, 0, ARRAY_SIZE(frontUUID));
|
|
|
memset(frontData, 0, ARRAY_SIZE(frontData));
|
|
|
- queueNotEmpty = FALSE;
|
|
|
-
|
|
|
- queueNotEmpty = queue_operation(QUEUE_OPERATION_SHOWFRONT,frontUUID, frontData);//showfront(frontUUID, frontData); ---> remove temporally
|
|
|
|
|
|
- if((queueNotEmpty == TRUE) && (GetOcppConnStatus() == 1)) //OcppConnStatus 0: disconnected, 1: connected
|
|
|
+ queueNotEmpty = queue_operation(QUEUE_OPERATION_SHOWFRONT,frontUUID, frontData);
|
|
|
+ if((queueNotEmpty == TRUE) && (GetOcppConnStatus() == 1))
|
|
|
{
|
|
|
if(isWebsocketSendable)
|
|
|
DEBUG_INFO("isWebsocketSendable on.\n");
|
|
@@ -919,48 +895,26 @@ void* processTransactionQueue(void* data)
|
|
|
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
|
|
|
+ if(queueOpInfo.TransactionMessageResend < TransactionMessageAttemptsGet())
|
|
|
{
|
|
|
- DEBUG_INFO("Sent message from queue request off-line first.\n");
|
|
|
- req_SendQueue = 1; // 0: no packets to send 1: send the top packet in queue
|
|
|
+ DEBUG_INFO("Sent message from queue request.\n");
|
|
|
+ DEBUG_INFO("TransactionMessageResend time: %d\n", queueOpInfo.TransactionMessageResend);
|
|
|
|
|
|
- OfflineTransactionQueueNum = OfflineTransactionQueueNum - 1;
|
|
|
+ req_SendQueue = 1;
|
|
|
|
|
|
- if(OfflineTransactionQueueNum == 0)
|
|
|
- {
|
|
|
- OfflineTransaction = 0;
|
|
|
- }
|
|
|
+ queueOpInfo.TransactionMessageResend += 1;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- if(TransactionMessageResend <= TransactionMessageAttemptsGet()) //
|
|
|
- {
|
|
|
- DEBUG_INFO("Sent message from queue request.\n");
|
|
|
- DEBUG_INFO("TransactionMessageResend = %d\n",TransactionMessageResend);
|
|
|
-
|
|
|
- req_SendQueue = 1;
|
|
|
+ DEBUG_INFO("Transaction message resend(%d) over spec(%d) message abandon.\n", queueOpInfo.TransactionMessageResend, TransactionMessageAttemptsGet());
|
|
|
|
|
|
- TransactionMessageResend += 1;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- DEBUG_INFO("Transaction message resend(%d) over spec(%d) message abandon.\n", TransactionMessageResend, TransactionMessageAttemptsGet());
|
|
|
-
|
|
|
- queue_operation(QUEUE_OPERATION_DEL,"",""); //// delete item
|
|
|
- TransactionMessageResend = 1;
|
|
|
- }
|
|
|
+ queue_operation(QUEUE_OPERATION_DEL,"","");
|
|
|
+ queueOpInfo.TransactionMessageResend = 0;
|
|
|
+ req_SendQueue = 0;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- if(GetOcppConnStatus() == 0)
|
|
|
- {
|
|
|
- if(queueNotEmpty == TRUE)
|
|
|
- {
|
|
|
- OfflineTransaction = 1; // 0: no offline Transaction 1: offline Transaction
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
// Refresh queue timer
|
|
|
refreshStartTimer(&startTime.startTimeQueue);
|
|
|
if((counterQueueSent >= 10) || (queueNotEmpty == FALSE))
|
|
@@ -976,7 +930,7 @@ void* processTransactionQueue(void* data)
|
|
|
usleep(500000);
|
|
|
}
|
|
|
|
|
|
- pthread_exit(NULL); //
|
|
|
+ pthread_exit(NULL);
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
@@ -1035,7 +989,7 @@ void CheckTransactionPacket(char *uuid)
|
|
|
{
|
|
|
DEBUG_INFO("Receive queue response match.\n");
|
|
|
queue_operation(QUEUE_OPERATION_DEL,"","");//delq(); ---> remove temporally
|
|
|
- TransactionMessageResend = 1;
|
|
|
+ queueOpInfo.TransactionMessageResend = 0;
|
|
|
}
|
|
|
else
|
|
|
DEBUG_INFO("Receive queue response mismatch.\n");
|
|
@@ -1048,9 +1002,9 @@ int queue_operation(int type, char *frontUUID, char *frontData)
|
|
|
|
|
|
while(1)
|
|
|
{
|
|
|
- if (!IsUsing )
|
|
|
+ if (!queueOpInfo.IsUsing )
|
|
|
{
|
|
|
- IsUsing = TRUE;
|
|
|
+ queueOpInfo.IsUsing = TRUE;
|
|
|
|
|
|
if(type == QUEUE_OPERATION_SHOWQUEUE) // show items in queue
|
|
|
{
|
|
@@ -1077,7 +1031,7 @@ int queue_operation(int type, char *frontUUID, char *frontData)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- IsUsing = FALSE;
|
|
|
+ queueOpInfo.IsUsing = FALSE;
|
|
|
break;
|
|
|
}
|
|
|
usleep(100000);
|
|
@@ -1129,6 +1083,8 @@ int main(void)
|
|
|
{
|
|
|
char rmFileCmd[100]={0};
|
|
|
struct stat stats;
|
|
|
+ queueOpInfo.IsUsing = FALSE;
|
|
|
+ queueOpInfo.TransactionMessageResend = 0;
|
|
|
|
|
|
DEBUG_INFO("Module_OcppBackend20 task initialization...\n");
|
|
|
//lws_set_log_level(LLL_PARSER | LLL_HEADER | LLL_ERR | LLL_WARN | LLL_NOTICE | LLL_INFO | LLL_DEBUG | LLL_EXT | LLL_CLIENT | LLL_LATENCY , NULL);
|
|
@@ -1167,7 +1123,6 @@ int main(void)
|
|
|
refreshStartTimer(&startTime.startTimeDog);
|
|
|
counterLwsRestart = 0;
|
|
|
// Connect server
|
|
|
-
|
|
|
if(ConnectionEstablished==0) // Check InternetConn 0: disconnected, 1: connected
|
|
|
{
|
|
|
isWebsocketSendable = 1;
|
|
@@ -1199,21 +1154,23 @@ int main(void)
|
|
|
if(GetServerSign() == TRUE)
|
|
|
{
|
|
|
// Send message from queue
|
|
|
- if((req_SendQueue == 1) && isWebsocketSendable)
|
|
|
+ if((req_SendQueue == 1) && (isWebsocketSendable || ((queueOpInfo.TransactionMessageResend > 1) && (queueOpInfo.PreTransactionMessageResend != queueOpInfo.TransactionMessageResend))))
|
|
|
{
|
|
|
queue_operation(QUEUE_OPERATION_SENT, "", "");
|
|
|
req_SendQueue = 0;
|
|
|
+ queueOpInfo.PreTransactionMessageResend = queueOpInfo.TransactionMessageResend;
|
|
|
}
|
|
|
|
|
|
// Check System Value
|
|
|
CheckSystemValue();
|
|
|
|
|
|
- if(GetHeartBeatWithNOResponse() >= 3)
|
|
|
+ if(GetHeartBeatWithNOResponse() >= 30)
|
|
|
{
|
|
|
lws_context_destroy(context);
|
|
|
ConnectionEstablished = 0;
|
|
|
context = NULL;
|
|
|
SetHeartBeatWithNOResponse();
|
|
|
+ DEBUG_WARN("Heartbeat re-send over 30 count.\n");
|
|
|
}
|
|
|
|
|
|
if((changeChageWebSocketPingInterval == TRUE) || (GetOcppConnStatus() == 0))
|
|
@@ -1221,7 +1178,13 @@ int main(void)
|
|
|
if(getDiffSecNow(startTime.reConnect) >= 3)
|
|
|
{
|
|
|
DEBUG_INFO("GetOcppConnStatus() = %d\n", GetOcppConnStatus());
|
|
|
- changeChageWebSocketPingInterval = FALSE;
|
|
|
+
|
|
|
+ if(changeChageWebSocketPingInterval)
|
|
|
+ {
|
|
|
+ DEBUG_INFO("Websocket ping interval changed request.\n");
|
|
|
+ changeChageWebSocketPingInterval = FALSE;
|
|
|
+ }
|
|
|
+
|
|
|
lws_context_destroy(context);
|
|
|
ConnectionEstablished = 0;
|
|
|
context = NULL;
|
|
@@ -1237,7 +1200,7 @@ int main(void)
|
|
|
do
|
|
|
{
|
|
|
lws_service(context, 0);//timeout_ms
|
|
|
- }while((SendBufLen>0) && (context!=NULL) && GetInternetConn());
|
|
|
+ }while((SendBufLen>0) && (context!=NULL) && GetOcppConnStatus());
|
|
|
|
|
|
refreshProcDogTimer();
|
|
|
usleep(100000);
|