Browse Source

2022-07-08/Jerry Wang
[OCPP 2.0.1]

Action:
1. Add function of sending CallError with 'SecurityError' if backend send Request Messages when charger haven't signed in with BootNotification yet.
2. Modify handleResetRequest function logic that charger would reply status 'Rejected' if the requested evseId > 0.
3. Correct the component name of variable 'AdditionalInfoItemsPerMessage'.
4. Fix NotifyReport logic to avoid losing some variables info.

File:
1. EVSE/Modularization/ocpp20/JsonParser.c
--> Action 1
2. EVSE/Modularization/ocpp20/MessageHandler.c
--> Action 2-4

Jerry Wang 2 years ago
parent
commit
4a9e35dc37

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

@@ -213,7 +213,14 @@ void ReceivedMessage(void *in, size_t len)
 				case MESSAGE_TYPE_CALL:
 					sprintf(Action, "%s", json_object_get_string(json_object_array_get_idx(obj, 2)));
 					sprintf(Payload, "%s", json_object_to_json_string_ext(json_object_array_get_idx(obj, 3), JSON_C_TO_STRING_PLAIN));
-					CallHandler(UniqueId,Action,Payload);
+					if(GetServerSign()==TRUE || ((strstr(Action,"TriggerMessage")!=NULL) && (strstr(Payload,"BootNotification")!=NULL)))
+						CallHandler(UniqueId,Action,Payload);
+					else
+					{
+						char callError[WEBSOCKET_BUFFER_SIZE];
+						sprintf(callError, "[%d,\"%s\",\"%s\",\"%s\",{}]",MESSAGE_TYPE_CALLERROR, UniqueId, "SecurityError", "Not sign in with BootNotification yet.");
+						LWS_Send(callError);
+					}
 					break;
 
 				case MESSAGE_TYPE_CALLRESULT:

+ 8 - 5
EVSE/Modularization/ocpp20/MessageHandler.c

@@ -1635,7 +1635,7 @@ int DB_cbVariableIsCreate(void *para, int columnCount, char **columnValue, char
 		sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_Enabled].variableAttribute[0].value, ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_ENABLE?"true":"false");
 		DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_Enabled]);
 
-		sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AdditionalInfoItemsPerMessage].component.name, "AlignedDataCtrlr");
+		sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AdditionalInfoItemsPerMessage].component.name, "AuthCtrlr");
 		sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AdditionalInfoItemsPerMessage].variable.name, "AdditionalInfoItemsPerMessage");
 		sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AdditionalInfoItemsPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
 		sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AdditionalInfoItemsPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
@@ -6995,6 +6995,7 @@ void CheckSystemValue(void)
 					sendNotifyReportRequest();
 					memset(&ShmOCPP20Data->NotifyReport.reportData[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->NotifyReport.reportData)*sizeof(struct ReportDataType));
 					reportIdx = 0;
+					idx_var--;
 				}
 			}
 		}
@@ -7018,6 +7019,7 @@ void CheckSystemValue(void)
 					sendNotifyReportRequest();
 					memset(&ShmOCPP20Data->NotifyReport.reportData[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->NotifyReport.reportData)*sizeof(struct ReportDataType));
 					reportIdx = 0;
+					idx_var--;
 				}
 			}
 		}
@@ -7478,9 +7480,6 @@ void CheckSystemValue(void)
 				{
 					if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
 					{
-						AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
-						AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
-
 						if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_AUTHORIZING)
 							cpinitateMsg.bits[gun_index].StatusNotificationReq = ON;
 
@@ -7491,6 +7490,9 @@ void CheckSystemValue(void)
 							ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq = ON;
 						}
 
+						AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
+						AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
+
 						if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
 						{
 							sprintf(filenmae,"/Storage/OCPP/TxProfile_%d_OCPP20.json",(gun_index+1));
@@ -16755,6 +16757,7 @@ int handleResetRequest(char *uuid, char *payload)
 
 	DEBUG_INFO("handleResetRequest...\n");
 	Reset = json_tokener_parse(payload);
+	ShmOCPP20Data->Reset.evseId = 0;
 
 	if(!is_error(Reset))
 	{
@@ -16771,7 +16774,7 @@ int handleResetRequest(char *uuid, char *payload)
 	}
 	json_object_put(Reset);
 
-	if((strcmp((char*)ShmOCPP20Data->Reset.type, ResetEnumTypeStr[ResetEnumType_Immediate])==0) || (strcmp((char*)ShmOCPP20Data->Reset.type, ResetEnumTypeStr[ResetEnumType_OnIdle])==0))
+	if((ShmOCPP20Data->Reset.evseId == 0) && ((strcmp((char*)ShmOCPP20Data->Reset.type, ResetEnumTypeStr[ResetEnumType_Immediate])==0) || (strcmp((char*)ShmOCPP20Data->Reset.type, ResetEnumTypeStr[ResetEnumType_OnIdle])==0)))
 	{
 	    strcpy((char *)ShmOCPP20Data->Reset.guid, uuid);
 	    strcpy((char*)ShmOCPP20Data->Reset.Response_status, ResetStatusEnumTypeStr[ResetStatusEnumType_Accepted]);