|
@@ -4,17 +4,10 @@
|
|
|
#include <string.h>
|
|
|
#include <assert.h>
|
|
|
#include "hashmap.h"
|
|
|
-//#include "HashTable.h"
|
|
|
-//#include "json-c/arraylist.h"
|
|
|
-//#include "json-c/json_tokener.h"
|
|
|
-
|
|
|
-//#include "json.h"
|
|
|
-//#include "./lib/Headers/json-c/JsonParser.h"
|
|
|
-//#include "parse_flags.h"
|
|
|
-//#include "./lib/Headers/json-c/linkhash.h"
|
|
|
#include "MessageHandler.h"
|
|
|
|
|
|
|
|
|
+
|
|
|
#define MESSAGE_TYPE_CALL 2
|
|
|
#define MESSAGE_TYPE_CALLRESULT 3
|
|
|
#define MESSAGE_TYPE_CALLERROR 4
|
|
@@ -58,13 +51,13 @@ static FunPtr funs[] = { handleAuthorizeResponse, handleBootNotificationResponse
|
|
|
handleHeartbeatResponse, handleMeterValuesResponse, \
|
|
|
handleStartTransactionResponse, \
|
|
|
handleStatusNotificationResponse, \
|
|
|
- handleStopTransactionnResponse }; // 將函式集中在陣列中。
|
|
|
+ handleStopTransactionnResponse }; //
|
|
|
|
|
|
static FunCallPtr funcalls[] = { handleCancelReservationRequest, handleChangeAvailabilityRequest, handleChangeConfigurationRequest,handleClearCacheRequest, \
|
|
|
handleClearChargingProfileRequest, handleDataTransferRequest, handleGetCompositeScheduleRequest, handleGetConfigurationRequest, \
|
|
|
handleGetDiagnosticsRequest, handleGetLocalListVersionRequest, handleRemoteStartRequest, handleRemoteStopTransactionRequest, \
|
|
|
handleReserveNowTransactionRequest, handleResetRequest, handleSendLocalListRequest, handleSetChargingProfileRequest, \
|
|
|
- handleTriggerMessageRequest, handleUnlockConnectorRequest, handleUpdateFirmwareRequest }; // 將函式集中在陣列中。
|
|
|
+ handleTriggerMessageRequest, handleUnlockConnectorRequest, handleUpdateFirmwareRequest }; //
|
|
|
|
|
|
|
|
|
static FunCallErrorPtr funcallerror[] = { handleError };
|
|
@@ -106,14 +99,14 @@ void ReceivedMessage(void *in, size_t len)
|
|
|
//char *str = "[ ]";
|
|
|
if(strcmp((const char *)tempin,"[ ]") == 0)
|
|
|
{
|
|
|
- printf("jobj is empty arrary. \n");
|
|
|
+ printf("Message is empty arrary. \n");
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
if(tempin[0] != '\0')//if(jobj != NULL)
|
|
|
{
|
|
|
MsgType = tempin[1] - '0';
|
|
|
- printf("MsgType=%d\n",MsgType);
|
|
|
+ //printf("MsgType=%d\n",MsgType);
|
|
|
c = 0;
|
|
|
|
|
|
if((MsgType != 2) && (MsgType != 3) && (MsgType != 4) )
|
|
@@ -128,7 +121,7 @@ void ReceivedMessage(void *in, size_t len)
|
|
|
c++;
|
|
|
}
|
|
|
UniqueId[c] = '\0';
|
|
|
- printf("UniqueId=%s\n",UniqueId);
|
|
|
+ //printf("UniqueId=%s\n",UniqueId);
|
|
|
|
|
|
if(UniqueId[0] == '\0')
|
|
|
{
|
|
@@ -143,7 +136,7 @@ void ReceivedMessage(void *in, size_t len)
|
|
|
switch (MsgType)
|
|
|
{
|
|
|
case MESSAGE_TYPE_CALL:
|
|
|
- printf("MESSAGE_TYPE_CALL\n");
|
|
|
+ //DEBUG_INFO("MESSAGE_TYPE_CALL\n");
|
|
|
|
|
|
c = 0;
|
|
|
while (tempin[4+4+strlen(UniqueId)-1+c] != '\"')
|
|
@@ -154,7 +147,7 @@ void ReceivedMessage(void *in, size_t len)
|
|
|
}
|
|
|
Action[c] = '\0';
|
|
|
|
|
|
- printf("Action=%s\n",Action);
|
|
|
+ //printf("Action=%s\n",Action);
|
|
|
|
|
|
c = 0;
|
|
|
int templen= 4+4+3+strlen(UniqueId)-1+strlen(Action)-1;
|
|
@@ -166,14 +159,14 @@ void ReceivedMessage(void *in, size_t len)
|
|
|
}
|
|
|
Payload[c] = '\0';
|
|
|
|
|
|
- printf("Payload=%s\n",Payload);
|
|
|
+ //printf("Payload=%s\n",Payload);
|
|
|
|
|
|
CallHandler(UniqueId,Action,Payload);
|
|
|
break;
|
|
|
|
|
|
case MESSAGE_TYPE_CALLRESULT:
|
|
|
|
|
|
- printf("MESSAGE_TYPE_CALLRESULT\n");
|
|
|
+ //DEBUG_INFO("MESSAGE_TYPE_CALLRESULT\n");
|
|
|
|
|
|
c = 0;
|
|
|
templen= 4+3+strlen(UniqueId)-1;
|
|
@@ -185,14 +178,14 @@ void ReceivedMessage(void *in, size_t len)
|
|
|
}
|
|
|
Payload[c] = '\0';
|
|
|
|
|
|
- printf("Payload=%s\n",Payload);
|
|
|
+ //printf("Payload=%s\n",Payload);
|
|
|
|
|
|
if(hashmap_operation(1, UniqueId, key_value) == TRUE)//if(hashmap_operation(1,NULL/*hashMap*/, UniqueId, mapItem, key_value/*(void**)(&mapItem)*/) == MAP_OK/*hashmap_get(hashMap, UniqueId, (void**)(&mapItem)) == MAP_OK*/)
|
|
|
{
|
|
|
hashmap_operation(2, UniqueId, key_value);//hashmap_operation(2,NULL/*hashMap*/, UniqueId, mapItem, key_value/*(void**)(&mapItem)*/);//hashmap_remove(hashMap, UniqueId);
|
|
|
char * const testdup = strdup(key_value/*mapItem->key_value*/);
|
|
|
|
|
|
- printf("original string: %s (@%p)\n", testdup, testdup);
|
|
|
+ //printf("original string: %s (@%p)\n", testdup, testdup);
|
|
|
|
|
|
substr = strtok(testdup, del);
|
|
|
while (substr != NULL) {
|
|
@@ -205,20 +198,20 @@ void ReceivedMessage(void *in, size_t len)
|
|
|
|
|
|
i=0;
|
|
|
sprintf(Action, "%s", *(arr+i++));
|
|
|
- printf("Action=%s\n",Action);
|
|
|
+ // printf("Action=%s\n",Action);
|
|
|
|
|
|
gun_index = atoi(*(arr+i++));
|
|
|
- printf("gun_index=%d\n",gun_index);
|
|
|
+ // printf("gun_index=%d\n",gun_index);
|
|
|
|
|
|
- #ifdef Debug
|
|
|
- DEBUG_INFO("<<<<<%s response\n", Action);
|
|
|
- DEBUG_INFO("Payload: %s\n", Payload);
|
|
|
- #endif
|
|
|
+ // #ifdef Debug
|
|
|
+ // DEBUG_INFO("<<<<<%s response\n", Action);
|
|
|
+ // DEBUG_INFO("Payload: %s\n", Payload);
|
|
|
+ // #endif
|
|
|
CallResultHandler(Action, Payload, gun_index);
|
|
|
|
|
|
- #ifdef Debug
|
|
|
- DEBUG_INFO("After pull hash length: %d\n", hashmap_length(hashMap));
|
|
|
- #endif
|
|
|
+ // #ifdef Debug
|
|
|
+ // DEBUG_INFO("After pull hash length: %d\n", hashmap_length(hashMap));
|
|
|
+ // #endif
|
|
|
|
|
|
free(testdup);
|
|
|
}
|
|
@@ -226,7 +219,7 @@ void ReceivedMessage(void *in, size_t len)
|
|
|
break;
|
|
|
|
|
|
case MESSAGE_TYPE_CALLERROR:
|
|
|
- printf("MESSAGE_TYPE_CALLERROR\n");
|
|
|
+ //DEBUG_INFO("MESSAGE_TYPE_CALLERROR\n");
|
|
|
|
|
|
c = 0;
|
|
|
while (tempin[4+4+strlen(UniqueId)-1+c] != '\"')
|
|
@@ -237,7 +230,7 @@ void ReceivedMessage(void *in, size_t len)
|
|
|
}
|
|
|
ErrorCode[c] = '\0';
|
|
|
|
|
|
- printf("ErrorCode=%s\n",ErrorCode);
|
|
|
+ // DEBUG_INFO("ErrorCode=%s\n",ErrorCode);
|
|
|
|
|
|
c = 0;
|
|
|
while (tempin[4+4+4+strlen(UniqueId)-1+strlen(ErrorCode)-1+c] != '\"')
|
|
@@ -248,7 +241,7 @@ void ReceivedMessage(void *in, size_t len)
|
|
|
}
|
|
|
ErrorDescription[c] = '\0';
|
|
|
|
|
|
- printf("ErrorDescription=%s\n",ErrorDescription);
|
|
|
+ // DEBUG_INFO("ErrorDescription=%s\n",ErrorDescription);
|
|
|
|
|
|
|
|
|
c = 0;
|
|
@@ -261,7 +254,7 @@ void ReceivedMessage(void *in, size_t len)
|
|
|
}
|
|
|
Payload[c] = '\0';
|
|
|
|
|
|
- printf("Payload=%s\n",Payload);
|
|
|
+ // DEBUG_INFO("Payload=%s\n",Payload);
|
|
|
|
|
|
|
|
|
|
|
@@ -298,7 +291,7 @@ void ReceivedMessage(void *in, size_t len)
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- printf("jobj is null. cant parse messgae. \n");
|
|
|
+ printf("Message is null. cant parse messgae. \n");
|
|
|
}
|
|
|
|
|
|
}
|
|
@@ -308,7 +301,7 @@ int CallHandler(char *uuid, char *str1,char *payload)
|
|
|
static int CallHandlerNumber = 0;
|
|
|
static int CallHandlerIndex = 0;
|
|
|
int (*callfptr)(char *uuid,char *payload);
|
|
|
- printf("enter CallHandler\n");
|
|
|
+ //DEBUG_INFO("enter CallHandler\n");
|
|
|
CallHandlerNumber = sizeof(requestNames)/sizeof(requestNames[0]);
|
|
|
for(int i= 0; i < CallHandlerNumber ; i ++ )
|
|
|
{
|
|
@@ -325,12 +318,12 @@ int CallHandler(char *uuid, char *str1,char *payload)
|
|
|
|
|
|
if(callfptr == NULL)
|
|
|
{
|
|
|
- printf("callfptr is null\n");
|
|
|
+ //printf("callfptr is null\n");
|
|
|
}
|
|
|
|
|
|
if ( callfptr )
|
|
|
{
|
|
|
- printf("exec CallHandler ... \n");
|
|
|
+ //printf("exec CallHandler ... \n");
|
|
|
callfptr(uuid, payload);
|
|
|
callfptr = NULL;
|
|
|
return PASS;
|
|
@@ -346,7 +339,7 @@ void CallResultHandler(char *str1, char *payload, int gun_index)
|
|
|
static int CallResultHandlerNumber = 0;
|
|
|
static int CallResultHandlerIndex = 0;
|
|
|
void (*callResultfptr)(char *payload, int gun_index );
|
|
|
- printf("enter CallResultHandler\n");
|
|
|
+ //printf("enter CallResultHandler\n");
|
|
|
CallResultHandlerNumber = sizeof(responseNames)/sizeof(responseNames[0]);
|
|
|
for(int i= 0; i < CallResultHandlerNumber ; i ++ )
|
|
|
{
|
|
@@ -357,20 +350,17 @@ void CallResultHandler(char *str1, char *payload, int gun_index)
|
|
|
}
|
|
|
|
|
|
}
|
|
|
- printf("CallResultHandlerIndex=%d\n",CallResultHandlerIndex);
|
|
|
|
|
|
callResultfptr = NULL;
|
|
|
callResultfptr = funs[CallResultHandlerIndex];
|
|
|
|
|
|
-
|
|
|
if(callResultfptr == NULL)
|
|
|
{
|
|
|
- printf("callResultfptr is null\n");
|
|
|
+ //printf("callResultfptr is null\n");
|
|
|
}
|
|
|
|
|
|
if ( callResultfptr )
|
|
|
{
|
|
|
- printf("exec CallResultHandler\n");
|
|
|
callResultfptr(payload, gun_index);
|
|
|
}
|
|
|
|
|
@@ -384,7 +374,7 @@ void CallErrorHandler(char *id, char *errorCode, char *errorDescription,char *pa
|
|
|
callErrorfptr = NULL;
|
|
|
callErrorfptr = funcallerror[0];
|
|
|
|
|
|
- printf("CallErrorHandler \n");
|
|
|
+ //printf("CallErrorHandler \n");
|
|
|
|
|
|
if(callErrorfptr == NULL)
|
|
|
{
|
|
@@ -393,7 +383,7 @@ void CallErrorHandler(char *id, char *errorCode, char *errorDescription,char *pa
|
|
|
|
|
|
if ( callErrorfptr )
|
|
|
{
|
|
|
- printf("callErrorfptr is not null\n");
|
|
|
+ //printf("callErrorfptr is not null\n");
|
|
|
|
|
|
callErrorfptr(id, errorCode, errorDescription, payload);
|
|
|
}
|