Bläddra i källkod

2022-06-02/Jerry Wang
[OCPP 1.6][OCPP 1.6PH]
Action:
1. Add logic for checking if ErrorCode is illegal in sendStatusNotificationRequest function.

File:
1. EVSE/Modularization/ocppfiles/MessageHandler.c
--> Action 1
2. EVSE/Modularization/ocppph/MessageHandler.c
--> Action 1

Jerry Wang 2 år sedan
förälder
incheckning
55b1b1f09f

+ 16 - 2
EVSE/Modularization/ocppfiles/MessageHandler.c

@@ -153,7 +153,6 @@ struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurati
 struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
 struct StructLocalAuthorizationList staticLocalAuthorizationList[1]={0};
 
-#if 0
 static char *ChargePointErrorCodeStr[] = {
     MACROSTR(ConnectorLockFailure),
     MACROSTR(EVCommunicationError),
@@ -172,7 +171,6 @@ static char *ChargePointErrorCodeStr[] = {
 	MACROSTR(UnderVoltage),
 	MACROSTR(WeakSignal)
 };
-#endif
 
 static char * ChargePointStatusStr[] = {
     MACROSTR(Available),
@@ -6172,6 +6170,7 @@ int sendStatusNotificationRequest(int gun_index)
 	char tempdata[65]={0};
 	int tempIndex = 0;
 	uint8_t isStateChanged = TRUE;
+	uint8_t isContentIllegal = TRUE;
 
 	DEBUG_INFO("sendStatusNotificationRequest...\n");
 	gettimeofday(&tmnow, NULL);
@@ -6527,6 +6526,21 @@ S_FAULT                 =12
 	strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
 	strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
 
+	isContentIllegal = TRUE;
+	for(int index = 0; index < ARRAY_SIZE(ChargePointErrorCodeStr); index++)
+	{
+		if(strcmp((char *)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, ChargePointErrorCodeStr[index])==0)
+		{
+			isContentIllegal = FALSE;
+			break;
+		}
+	}
+	if(isContentIllegal)
+	{
+		//DEBUG_WARN("Detect illegal ErrorCode: %s \n",(char *)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode);
+		strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, ChargePointErrorCodeStr[6]);
+	}
+
 	random_uuid(guid);
 
 	sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"

+ 16 - 2
EVSE/Modularization/ocppph/MessageHandler.c

@@ -155,7 +155,6 @@ struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurati
 struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
 struct StructLocalAuthorizationList staticLocalAuthorizationList[1]={0};
 
-#if 0
 static char *ChargePointErrorCodeStr[] = {
     MACROSTR(ConnectorLockFailure),
     MACROSTR(EVCommunicationError),
@@ -174,7 +173,6 @@ static char *ChargePointErrorCodeStr[] = {
 	MACROSTR(UnderVoltage),
 	MACROSTR(WeakSignal)
 };
-#endif
 
 static char * ChargePointStatusStr[] = {
     MACROSTR(Available),
@@ -5703,6 +5701,7 @@ int sendStatusNotificationRequest(int gun_index)
 	char tempdata[65]={0};
 	int tempIndex = 0;
 	uint8_t isStateChanged = TRUE;
+	uint8_t isContentIllegal = TRUE;
 
 	DEBUG_INFO("sendStatusNotificationRequest...\n");
 	gettimeofday(&tmnow, NULL);
@@ -6060,6 +6059,21 @@ S_FAULT                 =12
 	memcpy(ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode, ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, ARRAY_SIZE(ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode));
 	memcpy(ShmOCPP16DataPH->StatusNotification[gun_index].VendorErrorCode, ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode, ARRAY_SIZE(ShmOCPP16DataPH->StatusNotification[gun_index].VendorErrorCode));
 
+	isContentIllegal = TRUE;
+	for(int index = 0; index < ARRAY_SIZE(ChargePointErrorCodeStr); index++)
+	{
+		if(strcmp((char *)ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode, ChargePointErrorCodeStr[index])==0)
+		{
+			isContentIllegal = FALSE;
+			break;
+		}
+	}
+	if(isContentIllegal)
+	{
+		//DEBUG_WARN("Detect illegal ErrorCode: %s \n",(char *)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode);
+		strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode, ChargePointErrorCodeStr[6]);
+	}
+
 	random_uuid(guid);
 
 	sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"