|
@@ -20,7 +20,7 @@ struct StartTime
|
|
|
//==========================================
|
|
|
void ReceivedMessage(void *in, size_t len);
|
|
|
int SendBufLen=0;//(1024*4);//(1024*3);
|
|
|
-unsigned char SendBuffer[1024*4]={0};
|
|
|
+unsigned char SendBuffer[1024*20]={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;
|
|
@@ -54,7 +54,7 @@ int SendData(struct lws *wsi)
|
|
|
{
|
|
|
int n;
|
|
|
int len;
|
|
|
- unsigned char out[LWS_SEND_BUFFER_PRE_PADDING + 4096 + LWS_SEND_BUFFER_POST_PADDING] = {0};
|
|
|
+ unsigned char out[LWS_SEND_BUFFER_PRE_PADDING + (1024*20) + LWS_SEND_BUFFER_POST_PADDING] = {0};
|
|
|
|
|
|
// Only disable isWebsocketSendable operation initiated by charger
|
|
|
if((strstr((char*)SendBuffer, "\"Authorize\"") != NULL)
|
|
@@ -86,7 +86,7 @@ int SendData(struct lws *wsi)
|
|
|
return n;
|
|
|
}
|
|
|
|
|
|
-static int OCPP16Callback(struct lws *wsi, enum lws_callback_reasons reason, void *user, void *in, size_t len)
|
|
|
+static int OCPP20Callback(struct lws *wsi, enum lws_callback_reasons reason, void *user, void *in, size_t len)
|
|
|
{
|
|
|
char buf[256]={0}, hash[20]={0}, key_b64[40]={0}, tempin[65536]={0}, sstr[65536]={0};
|
|
|
uint8_t auth_b64[256]={0}, boxId[128]={0}, password[64]={0};
|
|
@@ -335,13 +335,13 @@ static struct lws_protocols protocols[] =
|
|
|
{
|
|
|
{
|
|
|
"ocpp2.0",
|
|
|
- OCPP16Callback,
|
|
|
+ OCPP20Callback,
|
|
|
65536,//65536,//10240,
|
|
|
65536,//65536,//10240,
|
|
|
},
|
|
|
{
|
|
|
"ocpp2.0",
|
|
|
- OCPP16Callback,
|
|
|
+ OCPP20Callback,
|
|
|
65536,//65536,//10240,
|
|
|
65536,//65536,//10240,
|
|
|
},
|
|
@@ -808,27 +808,10 @@ int showqueue()
|
|
|
int sentqueue(){
|
|
|
FILE *fp;
|
|
|
int result = FALSE; // 1: TRUE 0:FALSE
|
|
|
- int temptransactionId = 0, gettransactionId = 0;
|
|
|
- int tempconnectorId = 0;
|
|
|
- //int gunIndex = 0;
|
|
|
- char guid[37]={0};
|
|
|
- char tempdata[65]={0};
|
|
|
- char key_value[65]={0};
|
|
|
- int IsStopTransaction = FALSE;
|
|
|
- //int IsconnectorIdNULL = FALSE;
|
|
|
- //int IsIdtagNULL = FALSE;
|
|
|
char str[QUEUE_MESSAGE_LENGTH]={0};
|
|
|
- char strcomposite[QUEUE_MESSAGE_LENGTH]={0};
|
|
|
char rmFileCmd[100]={0};
|
|
|
- char connectorStr[2]={0};
|
|
|
struct stat stats;
|
|
|
- char sstr[28]={0};
|
|
|
- unsigned char IdtagStr[20]={0};
|
|
|
- unsigned char timestampStr[30]={0};
|
|
|
- int tempmeterStart = 0;
|
|
|
- int tempreservationId = 0;
|
|
|
- int c = 0;
|
|
|
- char *loc;
|
|
|
+ json_object *queueJson;
|
|
|
|
|
|
DEBUG_INFO("Sent queue.\n");
|
|
|
|
|
@@ -855,213 +838,15 @@ int sentqueue(){
|
|
|
return FALSE;
|
|
|
}
|
|
|
|
|
|
- if( fgets (str, QUEUE_MESSAGE_LENGTH, fp)!=NULL ) {
|
|
|
-
|
|
|
- //---- writing content to stdout ---//
|
|
|
-
|
|
|
- //*********************Start: StopTransaction***************************/
|
|
|
- loc = strstr(str, "StopTransaction");
|
|
|
- c = 0;
|
|
|
- memset(sstr ,0, ARRAY_SIZE(sstr) );
|
|
|
- if(loc != NULL)
|
|
|
- {
|
|
|
- IsStopTransaction = TRUE;
|
|
|
- }
|
|
|
+ if( fgets (str, QUEUE_MESSAGE_LENGTH, fp)!=NULL )
|
|
|
+ {
|
|
|
+ queueJson = json_tokener_parse(str+2);
|
|
|
|
|
|
- memset(connectorStr,0,ARRAY_SIZE(connectorStr));
|
|
|
- strncpy(connectorStr, str, 1);
|
|
|
- tempconnectorId = atoi(connectorStr);
|
|
|
- //*********************End: StopTransaction***************************/
|
|
|
-
|
|
|
- #if 0
|
|
|
- //*********************Start:connectorId***************************/
|
|
|
- loc = strstr(str, "connectorId");
|
|
|
- c = 0;
|
|
|
- memset(sstr ,0, ARRAY_SIZE(sstr) );
|
|
|
- if(loc != NULL)
|
|
|
+ if(!is_error(queueJson))
|
|
|
{
|
|
|
- while (loc[strlen("connectorId")+2+c] != ',')
|
|
|
- {
|
|
|
- sstr[c] = loc[strlen("connectorId")+2+c];
|
|
|
- c++;
|
|
|
- }
|
|
|
- sstr[c] = '\0';
|
|
|
- tempconnectorId = atoi(sstr);
|
|
|
- }
|
|
|
- // else
|
|
|
- // {
|
|
|
- // IsconnectorIdNULL = TRUE;
|
|
|
- // }
|
|
|
- //*********************End:connectorId***************************/
|
|
|
- #endif
|
|
|
-
|
|
|
- //*********************Start:idTag***************************/
|
|
|
- loc = strstr(str, "idTag");
|
|
|
- c = 0;
|
|
|
- memset(sstr ,0, ARRAY_SIZE(sstr) );
|
|
|
- if(loc != NULL)
|
|
|
- {
|
|
|
- while (loc[3+strlen("idTag")+c] != '\"')
|
|
|
- {
|
|
|
- sstr[c] = loc[3+strlen("idTag")+c];
|
|
|
- c++;
|
|
|
- }
|
|
|
- sstr[c] = '\0';
|
|
|
- strcpy((char*)IdtagStr, sstr);
|
|
|
- }
|
|
|
- // else
|
|
|
- // {
|
|
|
- // IsIdtagNULL = TRUE;
|
|
|
- // }
|
|
|
- //*********************End:idTag***************************/
|
|
|
-
|
|
|
-
|
|
|
- //*********************Start: StartTransaction***************************/
|
|
|
- loc = strstr(str, "StartTransaction");
|
|
|
- c = 0;
|
|
|
- memset(sstr ,0, ARRAY_SIZE(sstr) );
|
|
|
- if(loc != NULL)
|
|
|
- {
|
|
|
- // [2,0200000000000000000000000001584415776,StartTransaction,{connectorId:1,idTag:123,meterStart:100,reservationId:0,timestamp:2020-03-17T03:29:36Z}]
|
|
|
- //DEBUG_INFO("\n sent queue StartTransaction\n");
|
|
|
- if(tempconnectorId > 0)
|
|
|
- {
|
|
|
- sprintf(tempdata, "StartTransaction,%d", (tempconnectorId-1));
|
|
|
- }
|
|
|
-
|
|
|
- //GUID
|
|
|
- memset(sstr ,0, ARRAY_SIZE(sstr) );
|
|
|
- c=0;
|
|
|
- while (str[6+c] != '\"')
|
|
|
- {
|
|
|
- sstr[c] = str[6+c];
|
|
|
- c++;
|
|
|
- }
|
|
|
- sstr[c] = '\0';
|
|
|
- strcpy(guid, sstr);
|
|
|
-
|
|
|
-
|
|
|
- //Idtag
|
|
|
- loc = strstr(str, "idTag");
|
|
|
- memset(sstr ,0, ARRAY_SIZE(sstr) );
|
|
|
- c=0;
|
|
|
- while (loc[3+strlen("idTag")+c] != '\"')
|
|
|
- {
|
|
|
- sstr[c] = loc[3+strlen("idTag")+c];
|
|
|
- c++;
|
|
|
- }
|
|
|
- sstr[c] = '\0';
|
|
|
- strcpy((char*)IdtagStr, sstr);
|
|
|
-
|
|
|
- //meterStart
|
|
|
- loc = strstr(str, "meterStart");
|
|
|
- c = 0;
|
|
|
- memset(sstr ,0, ARRAY_SIZE(sstr) );
|
|
|
- if(loc != NULL)
|
|
|
- {
|
|
|
- while (loc[strlen("meterStart")+2+c] != ',')
|
|
|
- {
|
|
|
- sstr[c] = loc[strlen("meterStart")+2+c];
|
|
|
- c++;
|
|
|
- }
|
|
|
- sstr[c] = '\0';
|
|
|
- tempmeterStart = atoi(sstr);
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- //reservationId
|
|
|
- loc = strstr(str, "reservationId");
|
|
|
- c = 0;
|
|
|
- memset(sstr ,0, ARRAY_SIZE(sstr) );
|
|
|
- if(loc != NULL)
|
|
|
- {
|
|
|
- while (loc[strlen("reservationId")+2+c] != ',')
|
|
|
- {
|
|
|
- sstr[c] = loc[strlen("reservationId")+2+c];
|
|
|
- c++;
|
|
|
- }
|
|
|
- sstr[c] = '\0';
|
|
|
- tempreservationId = atoi(sstr);
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- //timestamp
|
|
|
- loc = strstr(str, "timestamp");
|
|
|
- memset(sstr ,0, ARRAY_SIZE(sstr) );
|
|
|
- c=0;
|
|
|
- while (loc[3+strlen("timestamp")+c] != '\"')
|
|
|
- {
|
|
|
- sstr[c] = loc[3+strlen("timestamp")+c];
|
|
|
- c++;
|
|
|
- }
|
|
|
- sstr[c] = '\0';
|
|
|
- strcpy((char*)timestampStr, sstr);
|
|
|
-
|
|
|
-
|
|
|
- if(hashmap_operation(HASH_OP_GET, guid, key_value) == TRUE)
|
|
|
- {
|
|
|
- //DEBUG_INFO("\n 1. sent queue guid=%s\n",guid);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- hashmap_operation(HASH_OP_ADD, guid, tempdata);
|
|
|
- FillStartTransaction(tempconnectorId, IdtagStr, tempmeterStart, tempreservationId, timestampStr);
|
|
|
- //DEBUG_INFO("\n 2. sent queue guid=%s\n",guid);
|
|
|
- }
|
|
|
+ LWS_Send(str+2);
|
|
|
}
|
|
|
- //*********************End: StartTransaction***************************/
|
|
|
-
|
|
|
-
|
|
|
- //****************transactionId********************/
|
|
|
- c=0;
|
|
|
- loc = strstr(str, "transactionId");
|
|
|
- memset(sstr ,0, ARRAY_SIZE(sstr) );
|
|
|
- if(loc != NULL)
|
|
|
- {
|
|
|
-
|
|
|
- while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
|
|
|
- {
|
|
|
- sstr[c] = loc[strlen("transactionId")+2+c];
|
|
|
- c++;
|
|
|
- }
|
|
|
-
|
|
|
- sstr[c] = '\0';
|
|
|
- temptransactionId = atoi(sstr);
|
|
|
-
|
|
|
- //gettransactionId = GetTransactionId(tempconnectorId, IdtagStr);
|
|
|
-
|
|
|
- //From StartTransaction取得IdTag, 存到 StartTransactionIdTagTemp,主要是 給Queue中StopTransaction使用(StartTransaction. StopTransaction不同卡號 ),取得真正的TransactionId
|
|
|
- GetStartTransactionIdTag(tempconnectorId-1);
|
|
|
- gettransactionId = GetTransactionId(tempconnectorId, (uint8_t *)StartTransactionIdTagTemp, IsStopTransaction);
|
|
|
-
|
|
|
- DEBUG_INFO("queue map transactionId = %d\n",gettransactionId);
|
|
|
- DEBUG_INFO("original connectorId = %d\n", tempconnectorId);
|
|
|
- DEBUG_INFO("original transactionId = %d\n",temptransactionId);
|
|
|
- DEBUG_INFO("StartTransactionIdTagTemp = %s\n", StartTransactionIdTagTemp);
|
|
|
- if((gettransactionId != 0)&&(temptransactionId != gettransactionId))
|
|
|
- {
|
|
|
- //replace transactionId of metervalue or stopTransaction
|
|
|
- strncpy(strcomposite,str, (loc-str)+2+strlen("transactionId"));
|
|
|
- sprintf(strcomposite+((loc-str)+2+strlen("transactionId")),"%d",gettransactionId);
|
|
|
- strcat(strcomposite, loc+strlen("transactionId")+2+c); // 把 字串中transactionId後面的字串串接到 strcomposite後面
|
|
|
- LWS_Send(strcomposite+2); // skip 2 bytes String -> Connector ID,
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- LWS_Send(str+2); // skip 2 bytes String -> Connector ID
|
|
|
- gettransactionId = temptransactionId;
|
|
|
- }
|
|
|
-
|
|
|
- DEBUG_INFO("Final transactionId = %d\n", gettransactionId);
|
|
|
- if(IsStopTransaction == TRUE)//if((IsStopTransaction == TRUE)&&(gettransactionId != 0))
|
|
|
- {
|
|
|
- SetTransactionIdZero(gettransactionId);
|
|
|
- }
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- LWS_Send(str+2);
|
|
|
- }
|
|
|
+ json_object_put(queueJson);
|
|
|
|
|
|
result = TRUE;
|
|
|
}
|