瀏覽代碼

[Improve][Modularization][Module_OcppBackend / Module_OcppBackend20]

2021.04.12 / Folus Wen

Actions:
1. Handle unknown action message logic implement.

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 年之前
父節點
當前提交
84fb97b19d

+ 8 - 10
EVSE/Modularization/ocpp20/JsonParser.c

@@ -50,7 +50,8 @@ static char *requestNames[] = { "CancelReservation",
 								"TriggerMessage",
 								"UnlockConnector",
 								"UnpublishFirmware",
-								"UpdateFirmware"};
+								"UpdateFirmware",
+								"Unknown"};
 
 static char *responseNames[] = {"Authorize",
 								"BootNotification",
@@ -143,7 +144,8 @@ static FunCallPtr funcalls[] = {handleCancelReservationRequest,
 								handleTriggerMessageRequest,
 								handleUnlockConnectorRequest,
 								handleUnpublishFirmwareRequest,
-								handleUpdateFirmwareRequest};
+								handleUpdateFirmwareRequest,
+								handleUnknownRequest};
 
 static FunCallErrorPtr funcallerror[] = {	handleError	};
 
@@ -272,10 +274,9 @@ void ReceivedMessage(void *in, size_t len)
 
 int CallHandler(char *uuid, char *str1,char *payload)
 {
-	static int CallHandlerNumber = 0;
-    static int CallHandlerIndex = 0;
+	int CallHandlerNumber = 0;
+    int CallHandlerIndex = (ARRAY_SIZE(requestNames)-1);
     int (*callfptr)(char *uuid,char *payload);
-    //DEBUG_INFO("enter CallHandler\n");
 	CallHandlerNumber = sizeof(requestNames)/sizeof(requestNames[0]);
 	for(int i= 0; i < CallHandlerNumber ; i ++ )
 	{
@@ -290,20 +291,17 @@ int CallHandler(char *uuid, char *str1,char *payload)
 	callfptr = funcalls[CallHandlerIndex];
 
 	if(callfptr == NULL)
-	{
-		//printf("callfptr is null\n");
-	}
+	{}
 
 	if ( callfptr )
 	{
-		//printf("exec CallHandler ... \n");
 		callfptr(uuid, payload);
 		callfptr = NULL;
 		return PASS;
 	}
 
 	callfptr = NULL;
-	 return FAIL;
+	return FAIL;
 }
 
 void CallResultHandler(char *str1, char *payload, int gun_index)

+ 28 - 0
EVSE/Modularization/ocpp20/MessageHandler.c

@@ -9999,6 +9999,22 @@ int sendUpdateFirmwareConfirmation(char *uuid)
 	return result;
 }
 
+int sendUnknownConfirmation(char *uuid)
+{
+	mtrace();
+	int result = FAIL;
+
+	char message[256]={0};
+
+	//[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
+	DEBUG_INFO("sendUnknownConfirmation...\n");
+	sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
+	LWS_Send(message);
+	result = TRUE;
+
+	return result;
+}
+
 //==========================================
 // send CallError routine
 //==========================================
@@ -15331,6 +15347,18 @@ int handleUpdateFirmwareRequest(char *uuid, char *payload)
 	return result;
 }
 
+int handleUnknownRequest(char *uuid, char *payload)
+{
+	mtrace();
+	int result = FAIL;
+	DEBUG_INFO("handleUnknownRequest...\n");
+
+	sendUnknownConfirmation(uuid);
+	result = PASS;
+
+	return result;
+}
+
 //==========================================
 // Handle server response routine
 //==========================================

+ 2 - 0
EVSE/Modularization/ocpp20/MessageHandler.h

@@ -897,6 +897,7 @@ int sendTriggerMessageConfirmation(char *uuid);
 int sendUnlockConnectorConfirmation(char *uuid, unsigned char gun_index);
 int sendUnpublishFirmwareConfirmation(char *uuid);
 int sendUpdateFirmwareConfirmation(char *uuid);
+int sendUnknownConfirmation(char *uuid);
 
 //==========================================
 // send CallError routine
@@ -946,6 +947,7 @@ int handleTriggerMessageRequest(char *uuid, char *payload);
 int handleUnlockConnectorRequest(char *uuid, char *payload);
 int handleUnpublishFirmwareRequest(char *uuid, char *payload);
 int handleUpdateFirmwareRequest(char *uuid, char *payload);
+int handleUnknownRequest(char *uuid, char *payload);
 
 
 void handleAuthorizeResponse(char *payload, int gun_index);

+ 6 - 4
EVSE/Modularization/ocppfiles/JsonParser.c

@@ -29,7 +29,8 @@ static char *requestNames[] = { "CancelReservation",
 								"SetChargingProfile",
 								"TriggerMessage",
 								"UnlockConnector",
-								"UpdateFirmware" };
+								"UpdateFirmware",
+								"Unknown"};
 
 static char *responseNames[] = {"Authorize",
 								"BootNotification",
@@ -71,7 +72,8 @@ static FunCallPtr funcalls[] = {handleCancelReservationRequest,
 								handleSetChargingProfileRequest,
 								handleTriggerMessageRequest,
 								handleUnlockConnectorRequest,
-								handleUpdateFirmwareRequest };
+								handleUpdateFirmwareRequest,
+								handleUnknownRequest};
 
 
 static FunCallErrorPtr funcallerror[] = {	handleError	};
@@ -201,8 +203,8 @@ void ReceivedMessage(void *in, size_t len)
 
 int CallHandler(char *uuid, char *str1,char *payload)
 {
-	static int CallHandlerNumber = 0;
-    static int CallHandlerIndex = 0;
+	int CallHandlerNumber = 0;
+    int CallHandlerIndex = (ARRAY_SIZE(requestNames)-1);
     int (*callfptr)(char *uuid,char *payload);
 	CallHandlerNumber = sizeof(requestNames)/sizeof(requestNames[0]);
 	for(int i= 0; i < CallHandlerNumber ; i ++ )

+ 26 - 0
EVSE/Modularization/ocppfiles/MessageHandler.c

@@ -6538,6 +6538,21 @@ int sendUpdateFirmwareConfirmation(char *uuid)
 	return result;
 }
 
+int sendUnknownConfirmation(char *uuid)
+{
+	mtrace();
+	int result = FAIL;
+
+	char message[256]={0};
+
+	//[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
+	DEBUG_INFO("sendUnknownConfirmation...\n");
+	sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
+	LWS_Send(message);
+	result = TRUE;
+
+	return result;
+}
 //==========================================
 // Handle server request routine  Start
 //==========================================
@@ -11444,6 +11459,17 @@ void *UpdateFirmwareProcess(void *data)
 
 }
 
+int handleUnknownRequest(char *uuid, char *payload)
+{
+	mtrace();
+	int result = FAIL;
+	DEBUG_INFO("handleUnknownRequest...\n");
+
+	sendUnknownConfirmation(uuid);
+	result = PASS;
+
+	return result;
+}
 //==========================================
 // Handle server response routine
 //==========================================

+ 2 - 0
EVSE/Modularization/ocppfiles/MessageHandler.h

@@ -482,6 +482,7 @@ int sendSetChargingProfileConfirmation(char *uuid,char *payload);
 int sendTriggerMessageConfirmation(char *uuid,char *payload);
 int sendUnlockConnectorConfirmation(char *uuid,char *payload);
 int sendUpdateFirmwareConfirmation(char *uuid);
+int sendUnknownConfirmation(char *uuid);
 
 //==========================================
 // send CallError routine
@@ -510,6 +511,7 @@ int handleSetChargingProfileRequest(char *uuid, char *payload);
 int handleTriggerMessageRequest(char *uuid, char *payload);
 int handleUnlockConnectorRequest(char *uuid, char *payload);
 int handleUpdateFirmwareRequest(char *uuid, char *payload);
+int handleUnknownRequest(char *uuid, char *payload);
 void handleAuthorizeResponse(char *payload, int gun_index);
 void handleBootNotificationResponse(char *payload, int gun_index);
 void handleDataTransferResponse(char *payload, int gun_index);