#include <uaserver_config.h>
#include <opcua_identifiers.h>
#include <opcua_memory.h>
#include <opcua_string.h>
#include <opcua_errorhandling.h>
#include <uaserver_events.h>
#include <uaserver_utilities.h>
#include "custom_provider_helper.h"
OPCUA_BEGIN_EXTERN_C
OpcUa_UInt32 g_HeaterSwitchedEventTypeId;
OpcUa_Int32 g_HeaterSwitchedEventType_IndexSwitchPosition;
OpcUa_Int32 g_HeaterSwitchedEventType_IndexCurrentTemperature;
OpcUa_StatusCode CustomProvider_RegisterEventTypes(OpcUa_NodeId *a_pStartingNodeId)
{
OpcUa_NodeId parentEventTypeId, nodeId;
OpcUa_BaseNode *pBaseNode = OpcUa_Null;
OpcUa_ObjectType *pEventType = OpcUa_Null;
OpcUa_Property *pProperty = OpcUa_Null;
OpcUa_InitializeStatus(OpcUa_Module_Server, "CustomProvider_RegisterEventTypes");
OpcUa_ReturnErrorIfArgumentNull(a_pStartingNodeId);
OpcUa_NodeId_Initialize(&parentEventTypeId);
OpcUa_NodeId_Initialize(&nodeId);
a_pStartingNodeId->Identifier.Numeric++;
g_HeaterSwitchedEventTypeId = a_pStartingNodeId->Identifier.Numeric;
parentEventTypeId.NamespaceIndex = 0;
parentEventTypeId.Identifier.Numeric = OpcUaId_BaseEventType;
OpcUa_GotoErrorIfBad(uStatus);
eventField.
BrowsePath.
Elements = (OpcUa_QualifiedName*)OpcUa_Alloc(
sizeof(OpcUa_QualifiedName));
OpcUa_String_FromCString("SwitchPosition"),
OPCUA_STRING_LENDONTCARE);
&eventField);
OpcUa_String_FromCString("CurrentTemperature"),
OPCUA_STRING_LENDONTCARE);
&eventField);
nodeId.NamespaceIndex = 0;
nodeId.Identifier.Numeric = OpcUaId_BaseEventType;
&pEventType,
(OpcUa_BaseNode*)pBaseNode,
a_pStartingNodeId->Identifier.Numeric,
g_uCustomProvider_NamespaceIndex,
"HeaterSwitchedEventType");
OpcUa_GotoErrorIfBad(uStatus);
a_pStartingNodeId->Identifier.Numeric++;
&pProperty,
(OpcUa_BaseNode*)pEventType,
a_pStartingNodeId->Identifier.Numeric,
g_uCustomProvider_NamespaceIndex,
"SwitchPosition");
OpcUa_GotoErrorIfBad(uStatus);
a_pStartingNodeId->Identifier.Numeric++;
&pProperty,
(OpcUa_BaseNode*)pEventType,
a_pStartingNodeId->Identifier.Numeric,
g_uCustomProvider_NamespaceIndex,
"CurrentTemperature");
OpcUa_GotoErrorIfBad(uStatus);
OpcUa_ReturnStatusCode;
OpcUa_BeginErrorHandling;
OpcUa_FinishErrorHandling;
}
OpcUa_StatusCode CustomProvider_UnregisterEventTypes()
{
OpcUa_NodeId eventTypeId;
OpcUa_InitializeStatus(OpcUa_Module_Server, "CustomProvider_UnregisterEventTypes");
OpcUa_NodeId_Initialize(&eventTypeId);
eventTypeId.NamespaceIndex = g_uCustomProvider_NamespaceIndex;
eventTypeId.Identifier.Numeric = g_HeaterSwitchedEventTypeId;
OpcUa_GotoErrorIfBad(uStatus);
OpcUa_ReturnStatusCode;
OpcUa_BeginErrorHandling;
OpcUa_FinishErrorHandling;
}
OpcUa_StatusCode CustomProvider_FireHeaterSwitchedEvent(Machine *a_pMachine)
{
OpcUa_NodeId eventTypeId;
OpcUa_ByteString bsEventId;
OpcUa_Variant value;
OpcUa_InitializeStatus(OpcUa_Module_Server, "CustomProvider_FireHeaterSwitchedEvent");
OpcUa_ReturnErrorIfArgumentNull(a_pMachine);
OpcUa_NodeId_Initialize(&eventTypeId);
OpcUa_ByteString_Initialize(&bsEventId);
OpcUa_Variant_Initialize(&value);
eventTypeId.NamespaceIndex = g_uCustomProvider_NamespaceIndex;
eventTypeId.Identifier.Numeric = g_HeaterSwitchedEventTypeId;
if (*a_pMachine->pHeaterSwitch->pValue == OpcUa_False)
{
}
else
{
}
value.Datatype = OpcUaType_Boolean;
value.Value.Boolean = *a_pMachine->pHeaterSwitch->pValue;
value.Datatype = OpcUaType_Double;
value.Value.Double = *a_pMachine->pTemperatureSensor->pValue;
OpcUa_ByteString_Clear(&bsEventId);
OpcUa_ReturnStatusCode;
OpcUa_BeginErrorHandling;
OpcUa_FinishErrorHandling;
}
OPCUA_END_EXTERN_C