浏览代码

2020.07.08 / Folus Wen

Actions:
1. EVSE/Modularization/ocppfiles/JsonParser.c payload parse method modify to lib json-c.
2. EVSE/Modularization/ocppfiles/MessageHandler.c checkCompositeSchedule() profile duration default value set to 86400.
3. EVSE/Modularization/ocppfiles/Module_OcppBackend.c cancel origin header in websocket handshaking content.

Files:
1. As follow commit history

Image version: D0.00.XX.XXXX.XX
Image checksum: XXXXXXXX

Hardware PWB P/N : XXXXXXX
Hardware Version : XXXXXXX
FolusWen 4 年之前
父节点
当前提交
f059b6c39b

+ 33 - 26
EVSE/Modularization/ocppfiles/JsonParser.c

@@ -96,8 +96,8 @@ void ReceivedMessage(void *in, size_t len)
 	char *substr = NULL;
 	int count = 0;
 	int i = 0;
-	int c = 0;
-	int templen = 0;
+	//int c = 0;
+	//int templen = 0;
 	char key_value[VALUE_MAX_LENGTH];
 
 	//parsing received message and do something
@@ -112,6 +112,10 @@ void ReceivedMessage(void *in, size_t len)
 	strcpy(tempin, (const char *)in);
 	memset( (void *)in, 0, sizeof(char)*len );
 
+
+	MsgType = json_object_get_int(json_object_array_get_idx(json_tokener_parse(tempin), 0));
+	sprintf(UniqueId, "%s", json_object_get_string(json_object_array_get_idx(json_tokener_parse(tempin), 1)));
+
 	//char *str = "[ ]";
 	if(strcmp((const char *)tempin,"[ ]") == 0)
 	{
@@ -121,22 +125,23 @@ void ReceivedMessage(void *in, size_t len)
 
 	if(tempin[0] != '\0')//if(jobj != NULL)
 	{
-		MsgType = tempin[1] - '0';
+		//MsgType = tempin[1] - '0';
 		//printf("MsgType=%d\n",MsgType);
-		c = 0;
+		//c = 0;
 
 		if((MsgType != 2) && (MsgType != 3) && (MsgType != 4) )
 		{
 			return;
 		}
 
+		/*
 		while ((tempin[4+c] != '\"') && (tempin[4+c] != '\0'))
 		{
 			UniqueId[c] = tempin[4+c];
 			//printf("i=%d UniqueId[c]=%c\n",c, UniqueId[c]);
 			c++;
 		}
-		UniqueId[c] = '\0';
+		UniqueId[c] = '\0';*/
 		//printf("UniqueId=%s\n",UniqueId);
 
 		if(UniqueId[0] == '\0')
@@ -150,7 +155,7 @@ void ReceivedMessage(void *in, size_t len)
 		{
 			case MESSAGE_TYPE_CALL:
 				//DEBUG_INFO("MESSAGE_TYPE_CALL\n");
-
+				/*
 				c = 0;
 				while (tempin[4+4+strlen(UniqueId)-1+c] != '\"')
 				{
@@ -158,10 +163,10 @@ void ReceivedMessage(void *in, size_t len)
 					//printf("i=%d Action[c]=%c\n",c, Action[c]);
 					c++;
 				}
-				Action[c] = '\0';
-
+				Action[c] = '\0';*/
+				sprintf(Action, "%s", json_object_get_string(json_object_array_get_idx(json_tokener_parse(tempin), 2)));
 				//printf("Action=%s\n",Action);
-
+				/*
 				c = 0;
 				templen= 4+4+3+strlen(UniqueId)-1+strlen(Action)-1;
 				while ((c+ templen) < (strlen(tempin)-1))
@@ -170,14 +175,15 @@ void ReceivedMessage(void *in, size_t len)
 					//printf("i=%d Payload[c]=%c\n",c, Payload[c]);
 					c++;
 				}
-				Payload[c] = '\0';
-				//printf("Payload=%s\n",Payload);
+				Payload[c] = '\0';*/
 
+				//printf("Payload=%s\n",Payload);
+				sprintf(Payload, "%s", json_object_get_string(json_object_array_get_idx(json_tokener_parse(tempin), 3)));
 			   	CallHandler(UniqueId,Action,Payload);
 			   	break;
 
 			case MESSAGE_TYPE_CALLRESULT:
-
+				/*
 			   	c = 0;
 			   	templen= 4+3+strlen(UniqueId)-1;
 			   	while ((c+ templen) < (strlen(tempin)-1))
@@ -186,13 +192,13 @@ void ReceivedMessage(void *in, size_t len)
 			   		//printf("i=%d sstr=%c\n",c, Payload[c]);
 			   		c++;
 			   	}
-			   	Payload[c] = '\0';
-
+			   	Payload[c] = '\0';*/
+				sprintf(Payload, "%s", json_object_get_string(json_object_array_get_idx(json_tokener_parse(tempin), 2)));
 			   	//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*/)
+			   	if(hashmap_operation(HASH_OP_GET, 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);
+			   		hashmap_operation(HASH_OP_REMOVE, 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);
@@ -219,7 +225,7 @@ void ReceivedMessage(void *in, size_t len)
 
 		   case MESSAGE_TYPE_CALLERROR:
 			   //DEBUG_INFO("MESSAGE_TYPE_CALLERROR\n");
-
+			   /*
 			   c = 0;
 			   while (tempin[4+4+strlen(UniqueId)-1+c] != '\"')
 			   {
@@ -227,10 +233,11 @@ void ReceivedMessage(void *in, size_t len)
 				  // printf("i=%d sstr=%c\n",c, ErrorCode[c]);
 				   c++;
 			   }
-			   ErrorCode[c] = '\0';
+			   ErrorCode[c] = '\0';*/
 
+			   sprintf(ErrorCode, "%s", json_object_get_string(json_object_array_get_idx(json_tokener_parse(tempin), 2)));
 			  // DEBUG_INFO("ErrorCode=%s\n",ErrorCode);
-
+			   /*
 			   c = 0;
 			   while (tempin[4+4+4+strlen(UniqueId)-1+strlen(ErrorCode)-1+c] != '\"')
 			   {
@@ -238,11 +245,12 @@ void ReceivedMessage(void *in, size_t len)
 				   //printf("i=%d sstr=%c\n",c, ErrorDescription[c]);
 				   c++;
 			   }
-			   ErrorDescription[c] = '\0';
+			   ErrorDescription[c] = '\0';*/
+			   sprintf(ErrorDescription, "%s", json_object_get_string(json_object_array_get_idx(json_tokener_parse(tempin), 3)));
 
 			  // DEBUG_INFO("ErrorDescription=%s\n",ErrorDescription);
 
-
+			   /*
 			   c = 0;
 			   templen= 4+4+4+3+strlen(UniqueId)-1+strlen(ErrorCode)-1+strlen(ErrorDescription)-1;
 			   while ((c+ templen) < (strlen(tempin)-1))
@@ -251,15 +259,15 @@ void ReceivedMessage(void *in, size_t len)
 				  // printf("i=%d sstr=%c\n",c, Payload[c]);
 				   c++;
 			   }
-			   Payload[c] = '\0';
-
+			   Payload[c] = '\0';*/
+			   sprintf(Payload, "%s", json_object_get_string(json_object_array_get_idx(json_tokener_parse(tempin), 4)));
 			  // DEBUG_INFO("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*/)
+			   if(hashmap_operation(HASH_OP_GET, 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);
+				   hashmap_operation(HASH_OP_REMOVE, UniqueId, key_value);//hashmap_operation(2,NULL/*hashMap*/, UniqueId, mapItem, key_value/*(void**)(&mapItem)*/);//hashmap_remove(hashMap, UniqueId);
 
 					sprintf(Action, "%s", key_value/*mapItem->key_value*/);
 
@@ -277,7 +285,6 @@ void ReceivedMessage(void *in, size_t len)
 	{
 		printf("Message is null. cant parse messgae. \n");
 	}
-
 }
 
 int CallHandler(char *uuid, char *str1,char *payload)

+ 6 - 6
EVSE/Modularization/ocppfiles/MessageHandler.c

@@ -732,7 +732,7 @@ void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct St
 								}
 								else
 								{
-									txProfile.ChargingSchedule.Duration = -1;
+									txProfile.ChargingSchedule.Duration = 86400;
 								}
 
 								if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
@@ -820,7 +820,7 @@ void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct St
 						}
 						else
 						{
-							txProfile.ChargingSchedule.Duration = -1;
+							txProfile.ChargingSchedule.Duration = 86400;
 						}
 
 						if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
@@ -992,7 +992,7 @@ void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct St
 								}
 								else
 								{
-									defaultTxProfile.ChargingSchedule.Duration = -1;
+									defaultTxProfile.ChargingSchedule.Duration = 86400;
 								}
 
 								if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
@@ -1080,7 +1080,7 @@ void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct St
 						}
 						else
 						{
-							defaultTxProfile.ChargingSchedule.Duration = -1;
+							defaultTxProfile.ChargingSchedule.Duration = 86400;
 						}
 
 						if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
@@ -1251,7 +1251,7 @@ void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct St
 								}
 								else
 								{
-									maxProfile.ChargingSchedule.Duration = -1;
+									maxProfile.ChargingSchedule.Duration = 86400;
 								}
 
 								if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
@@ -1339,7 +1339,7 @@ void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct St
 						}
 						else
 						{
-							maxProfile.ChargingSchedule.Duration = -1;
+							maxProfile.ChargingSchedule.Duration = 86400;
 						}
 
 						if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)

+ 1 - 1
EVSE/Modularization/ocppfiles/Module_OcppBackend.c

@@ -442,7 +442,7 @@ void* ConnectWsServer(void* data)  //int ConnectWsServer()
 	sprintf(addr_port, "%s:%u", ConnInfo.address, (ConnInfo.port & 65535) );
 
 	ConnInfo.host= addr_port; // ConnInfo.address;//lws_canonical_hostname(context);
-	ConnInfo.origin="origin";
+	//ConnInfo.origin="origin";
 	ConnInfo.protocol = protocols[1].name;
 	ConnInfo.ietf_version_or_minus_one = -1;