#include <uaserver_config.h>
#include <opcua_statuscodes.h>
#include <uaserver_call.h>
#include <uaserver_basenode.h>
#include <uaserver_utilities.h>
#include <uaserver_p_atomic.h>
#include "custom_provider_helper.h"
OPCUA_BEGIN_EXTERN_C
OpcUa_StatusCode CustomProvider_CallAcknowledge(
UaServer_Event *a_pEvent, OpcUa_CallMethodRequest* a_pRequest, OpcUa_CallMethodResult* a_pResult)
{
if (a_pRequest->NoOfInputArguments == 2)
{
a_pResult->StatusCode = OpcUa_Good;
a_pResult->NoOfInputArgumentResults = 2;
a_pResult->InputArgumentResults = (OpcUa_StatusCode*)OpcUa_Alloc(a_pResult->NoOfInputArgumentResults * sizeof(OpcUa_StatusCode));
OpcUa_MemSet(a_pResult->InputArgumentResults, 0, a_pResult->NoOfInputArgumentResults * sizeof(OpcUa_StatusCode));
if (a_pRequest->InputArguments[0].Datatype != OpcUaType_ByteString
|| a_pRequest->InputArguments[0].ArrayType != OpcUa_VariantArrayType_Scalar)
{
a_pResult->InputArgumentResults[0] = OpcUa_BadTypeMismatch;
a_pResult->StatusCode = OpcUa_BadTypeMismatch;
}
if (a_pRequest->InputArguments[1].Datatype != OpcUaType_LocalizedText
|| a_pRequest->InputArguments[1].ArrayType != OpcUa_VariantArrayType_Scalar)
{
a_pResult->InputArgumentResults[1] = OpcUa_BadTypeMismatch;
a_pResult->StatusCode = OpcUa_BadTypeMismatch;
}
if (OpcUa_IsGood(a_pResult->StatusCode))
{
if (OpcUa_ByteString_Compare(pEventId, &a_pRequest->InputArguments[0].Value.ByteString) != 0)
{
a_pResult->StatusCode = OpcUa_BadEventIdUnknown;
}
}
if (OpcUa_IsGood(a_pResult->StatusCode))
{
a_pResult->StatusCode = OpcUa_BadConditionBranchAlreadyAcked;
if (pAckedState != OpcUa_Null
&& pAckedState->Datatype == OpcUaType_Boolean
&& pAckedState->ArrayType == OpcUa_VariantArrayType_Scalar
&& pAckedState->Value.Boolean == OpcUa_False)
{
a_pResult->StatusCode = OpcUa_Good;
}
}
if (OpcUa_IsGood(a_pResult->StatusCode))
{
OpcUa_Variant value;
OpcUa_NodeId *pSourceNode;
OpcUa_Variant_Initialize(&value);
value.Datatype = OpcUaType_LocalizedText;
value.Value.LocalizedText = (OpcUa_LocalizedText*)OpcUa_Alloc(sizeof(OpcUa_LocalizedText));
OpcUa_LocalizedText_Initialize(value.Value.LocalizedText);
OpcUa_String_StrnCat(&value.Value.LocalizedText->Text, OpcUa_String_FromCString("Acknowledged"), OPCUA_STRING_LENDONTCARE);
OpcUa_Variant_Clear(&value);
value.Datatype = OpcUaType_Boolean;
value.Value.Boolean = OpcUa_True;
OpcUa_Variant_Clear(&value);
value.Datatype = OpcUaType_DateTime;
value.Value.DateTime = OpcUa_DateTime_UtcNow();
OpcUa_Variant_Clear(&value);
value.Datatype = OpcUaType_LocalizedText;
value.Value.LocalizedText = (OpcUa_LocalizedText*)OpcUa_Alloc(sizeof(OpcUa_LocalizedText));
OpcUa_LocalizedText_Initialize(value.Value.LocalizedText);
OpcUa_LocalizedText_CopyTo(a_pRequest->InputArguments[1].Value.LocalizedText, value.Value.LocalizedText);
OpcUa_Variant_Clear(&value);
value.Datatype = OpcUaType_DateTime;
value.Value.DateTime = OpcUa_DateTime_UtcNow();
OpcUa_Variant_Clear(&value);
if (pSourceNode != OpcUa_Null)
{
OpcUa_BaseNode *pBaseNode;
if (pBaseNode != OpcUa_Null)
{
if (pUserData && pUserData->Type == UserDataMachine)
{
Machine *pMachineData = (Machine*)pUserData;
OpcUa_ReferenceParameter(pMachineData);
}
}
}
}
}
else
{
a_pResult->StatusCode = OpcUa_BadArgumentsMissing;
}
return OpcUa_Good;
}
{
OpcUa_CallRequest *pRequest;
OpcUa_CallResponse *pResponse;
OpcUa_Int32 i;
OpcUa_BaseNode *pNode;
OpcUa_InitializeStatus(OpcUa_Module_Server, "CustomProvider_CallAsync");
OpcUa_ReturnErrorIfArgumentNull(a_pCallContext);
for (i = 0; i < pRequest->NoOfMethodsToCall; i++)
{
if (pRequest->MethodsToCall[i].MethodId.NamespaceIndex == g_uCustomProvider_NamespaceIndex &&
pRequest->MethodsToCall[i].ObjectId.NamespaceIndex == g_uCustomProvider_NamespaceIndex)
{
if (pNode != OpcUa_Null)
{
if (pUserData != OpcUa_Null)
{
switch (pUserData->Type)
{
case UserDataMachine:
{
Machine *pMachine = (Machine*)pUserData;
if (OpcUa_NodeId_Compare(&pRequest->MethodsToCall[i].ObjectId, &pMachine->nodeId) != 0)
{
pResponse->Results[i].StatusCode = OpcUa_BadNotFound;
break;
}
if (pRequest->MethodsToCall[i].NoOfInputArguments == 1)
{
OpcUa_Variant *pInArg = &pRequest->MethodsToCall[i].InputArguments[0];
OpcUa_CallMethodResult *pResult = &pResponse->Results[i];
pResult->NoOfInputArgumentResults = 1;
pResult->InputArgumentResults = (OpcUa_StatusCode*)OpcUa_Alloc(sizeof(OpcUa_StatusCode));
if (pInArg->ArrayType == OpcUa_VariantArrayType_Scalar &&
pInArg->Datatype == OpcUaType_Boolean)
{
*pMachine->pHeaterSwitch->pValue = pInArg->Value.Boolean;
pResult->InputArgumentResults[0] = OpcUa_Good;
}
else
{
pResult->InputArgumentResults[0] = OpcUa_BadTypeMismatch;
}
pResult->NoOfOutputArguments = 1;
pResult->OutputArguments = (OpcUa_Variant*)OpcUa_Alloc(sizeof(OpcUa_Variant));
OpcUa_Variant_Initialize(&pResult->OutputArguments[0]);
pResult->OutputArguments[0].Datatype = OpcUaType_Double;
pResult->OutputArguments[0].Value.Double = *pMachine->pTemperatureSensor->pValue;
pResult->StatusCode = OpcUa_Good;
}
else
{
pResponse->Results[i].StatusCode = OpcUa_BadArgumentsMissing;
}
break;
}
default:
{
pResponse->Results[i].StatusCode = OpcUa_BadNotFound;
break;
}
}
}
}
}
else if (pRequest->MethodsToCall[i].ObjectId.NamespaceIndex == g_uCustomProvider_NamespaceIndex
&& pRequest->MethodsToCall[i].MethodId.NamespaceIndex == 0
&& pRequest->MethodsToCall[i].MethodId.IdentifierType == OpcUa_IdentifierType_Numeric)
{
switch (pRequest->MethodsToCall[i].MethodId.Identifier.Numeric)
{
case OpcUaId_AcknowledgeableConditionType_Acknowledge:
{
&pRequest->MethodsToCall[i].ObjectId);
if (pEvent != OpcUa_Null)
{
CustomProvider_CallAcknowledge(pEvent, &pRequest->MethodsToCall[i], &pResponse->Results[i]);
}
break;
}
default:
break;
}
}
}
OpcUa_ReturnStatusCode;
OpcUa_BeginErrorHandling;
OpcUa_FinishErrorHandling;
}
OPCUA_END_EXTERN_C