ANSI C Based OPC UA Client/Server/PubSub SDK  1.9.1.442
uaprovider_demo_alarmcondition.c
/*****************************************************************************
* *
* Copyright (c) 2006-2020 Unified Automation GmbH. All rights reserved. *
* *
* Software License Agreement ("SLA") Version 2.7 *
* *
* Unless explicitly acquired and licensed from Licensor under another *
* license, the contents of this file are subject to the Software License *
* Agreement ("SLA") Version 2.7, or subsequent versions as allowed by the *
* SLA, and You may not copy or use this file in either source code or *
* executable form, except in compliance with the terms and conditions of *
* the SLA. *
* *
* All software distributed under the SLA is provided strictly on an "AS *
* IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, *
* AND LICENSOR HEREBY DISCLAIMS ALL SUCH WARRANTIES, INCLUDING WITHOUT *
* LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR *
* PURPOSE, QUIET ENJOYMENT, OR NON-INFRINGEMENT. See the SLA for specific *
* language governing rights and limitations under the SLA. *
* *
* The complete license agreement can be found here: *
* http://unifiedautomation.com/License/SLA/2.7/ *
* *
* Project: Unified Automation ANSI C based OPC UA Server SDK *
* *
*****************************************************************************/
#include "uaprovider_demo_alarmcondition.h"
#include <uaserver_utilities.h>
#include <opcua_identifiers.h>
#include <opcua_memory.h>
#include <opcua_string.h>
#include <opcua_errorhandling.h>
OPCUA_BEGIN_EXTERN_C
OpcUa_StatusCode UaProvider_Demo_InitializeAlarmConditionTypeEvent(
UaServer_Event *a_pAlarmConditionTypeEvent,
OpcUa_NodeId *a_pSourceNode,
const OpcUa_CharA *a_sSourceName,
OpcUa_NodeId *a_pConditionId,
const OpcUa_CharA *a_sConditionName)
{
OpcUa_NodeId nodeId;
OpcUa_ReturnErrorIfArgumentNull(a_pAlarmConditionTypeEvent);
OpcUa_NodeId_Initialize(&nodeId);
nodeId.Identifier.Numeric = OpcUaId_AlarmConditionType;
/* set base event type fields */
UaServer_Events_SetEventType(a_pAlarmConditionTypeEvent, &nodeId);
UaServer_Events_SetSourceNode(a_pAlarmConditionTypeEvent, a_pSourceNode);
UaServer_Events_SetSourceName(a_pAlarmConditionTypeEvent, a_sSourceName);
UaServer_Events_SetMessage(a_pAlarmConditionTypeEvent, "", "condition event message");
UaServer_Events_SetSeverity(a_pAlarmConditionTypeEvent, 500);
/* set condition type fields */
OpcUa_Variant_Initialize(&value);
value.Value.NodeId = (OpcUa_NodeId*)OpcUa_Alloc(sizeof(OpcUa_NodeId));
OpcUa_ReturnErrorIfAllocFailed(value.Value.NodeId);
OpcUa_NodeId_Initialize(value.Value.NodeId);
value.Datatype = OpcUaType_NodeId;
UaServer_Events_SetEventField(a_pAlarmConditionTypeEvent, ConditionTypeField_BranchId, &value);
OpcUa_Variant_Clear(&value);
value.Datatype = OpcUaType_String;
OpcUa_String_Initialize(&value.Value.String);
UaServer_Events_SetEventField(a_pAlarmConditionTypeEvent, ConditionTypeField_ClientUserId, &value);
OpcUa_Variant_Clear(&value);
value.Value.LocalizedText = (OpcUa_LocalizedText*)OpcUa_Alloc(sizeof(OpcUa_LocalizedText));
OpcUa_ReturnErrorIfAllocFailed(value.Value.LocalizedText);
OpcUa_LocalizedText_Initialize(value.Value.LocalizedText);
value.Datatype = OpcUaType_LocalizedText;
UaServer_Events_SetEventField(a_pAlarmConditionTypeEvent, ConditionTypeField_Comment, &value);
OpcUa_Variant_Clear(&value);
value.Datatype = OpcUaType_DateTime;
value.Value.DateTime.dwHighDateTime = 0;
value.Value.DateTime.dwLowDateTime = 0;
UaServer_Events_SetEventField(a_pAlarmConditionTypeEvent, ConditionTypeField_Comment_SourceTimestamp, &value);
OpcUa_Variant_Clear(&value);
value.Value.NodeId = (OpcUa_NodeId*)OpcUa_Alloc(sizeof(OpcUa_NodeId));
OpcUa_ReturnErrorIfAllocFailed(value.Value.NodeId);
OpcUa_NodeId_Initialize(value.Value.NodeId);
value.Datatype = OpcUaType_NodeId;
UaServer_Events_SetEventField(a_pAlarmConditionTypeEvent, ConditionTypeField_ConditionClassId, &value);
OpcUa_Variant_Clear(&value);
value.Value.LocalizedText = (OpcUa_LocalizedText*)OpcUa_Alloc(sizeof(OpcUa_LocalizedText));
OpcUa_ReturnErrorIfAllocFailed(value.Value.LocalizedText);
OpcUa_LocalizedText_Initialize(value.Value.LocalizedText);
value.Datatype = OpcUaType_LocalizedText;
UaServer_Events_SetEventField(a_pAlarmConditionTypeEvent, ConditionTypeField_ConditionClassName, &value);
OpcUa_Variant_Clear(&value);
value.Datatype = OpcUaType_String;
OpcUa_String_Initialize(&value.Value.String);
OpcUa_String_StrnCat(&value.Value.String, OpcUa_String_FromCString(a_sConditionName), OPCUA_STRING_LENDONTCARE);
UaServer_Events_SetEventField(a_pAlarmConditionTypeEvent, ConditionTypeField_ConditionName, &value);
OpcUa_Variant_Clear(&value);
value.Value.LocalizedText = (OpcUa_LocalizedText*)OpcUa_Alloc(sizeof(OpcUa_LocalizedText));
OpcUa_ReturnErrorIfAllocFailed(value.Value.LocalizedText);
OpcUa_LocalizedText_Initialize(value.Value.LocalizedText);
value.Datatype = OpcUaType_LocalizedText;
OpcUa_String_StrnCat(&value.Value.LocalizedText->Text, OpcUa_String_FromCString("true"), OPCUA_STRING_LENDONTCARE);
UaServer_Events_SetEventField(a_pAlarmConditionTypeEvent, ConditionTypeField_EnabledState, &value);
OpcUa_Variant_Clear(&value);
value.Value.LocalizedText = (OpcUa_LocalizedText*)OpcUa_Alloc(sizeof(OpcUa_LocalizedText));
OpcUa_ReturnErrorIfAllocFailed(value.Value.LocalizedText);
OpcUa_LocalizedText_Initialize(value.Value.LocalizedText);
value.Datatype = OpcUaType_LocalizedText;
UaServer_Events_SetEventField(a_pAlarmConditionTypeEvent, ConditionTypeField_EnabledState_EffectiveDisplayName, &value);
OpcUa_Variant_Clear(&value);
value.Datatype = OpcUaType_DateTime;
value.Value.DateTime.dwHighDateTime = 0;
value.Value.DateTime.dwLowDateTime = 0;
UaServer_Events_SetEventField(a_pAlarmConditionTypeEvent, ConditionTypeField_EnabledState_EffectiveTransitionTime, &value);
OpcUa_Variant_Clear(&value);
value.Datatype = OpcUaType_Boolean;
value.Value.Boolean = OpcUa_True;
UaServer_Events_SetEventField(a_pAlarmConditionTypeEvent, ConditionTypeField_EnabledState_Id, &value);
OpcUa_Variant_Clear(&value);
value.Datatype = OpcUaType_DateTime;
value.Value.DateTime.dwHighDateTime = 0;
value.Value.DateTime.dwLowDateTime = 0;
UaServer_Events_SetEventField(a_pAlarmConditionTypeEvent, ConditionTypeField_EnabledState_TransitionTime, &value);
OpcUa_Variant_Clear(&value);
value.Datatype = OpcUaType_UInt16;
value.Value.UInt16 = 500;
UaServer_Events_SetEventField(a_pAlarmConditionTypeEvent, ConditionTypeField_LastSeverity, &value);
OpcUa_Variant_Clear(&value);
value.Datatype = OpcUaType_DateTime;
value.Value.DateTime.dwHighDateTime = 0;
value.Value.DateTime.dwLowDateTime = 0;
UaServer_Events_SetEventField(a_pAlarmConditionTypeEvent, ConditionTypeField_LastSeverity_SourceTimestamp, &value);
OpcUa_Variant_Clear(&value);
value.Datatype = OpcUaType_StatusCode;
value.Value.StatusCode = OpcUa_Good;
UaServer_Events_SetEventField(a_pAlarmConditionTypeEvent, ConditionTypeField_Quality, &value);
OpcUa_Variant_Clear(&value);
value.Datatype = OpcUaType_DateTime;
value.Value.DateTime.dwHighDateTime = 0;
value.Value.DateTime.dwLowDateTime = 0;
UaServer_Events_SetEventField(a_pAlarmConditionTypeEvent, ConditionTypeField_Quality_SourceTimestamp, &value);
OpcUa_Variant_Clear(&value);
value.Datatype = OpcUaType_Boolean;
value.Value.Boolean = OpcUa_False;
UaServer_Events_SetEventField(a_pAlarmConditionTypeEvent, ConditionTypeField_Retain, &value);
OpcUa_Variant_Clear(&value);
value.Value.NodeId = (OpcUa_NodeId*)OpcUa_Alloc(sizeof(OpcUa_NodeId));
OpcUa_ReturnErrorIfAllocFailed(value.Value.NodeId);
OpcUa_NodeId_Initialize(value.Value.NodeId);
value.Datatype = OpcUaType_NodeId;
OpcUa_NodeId_CopyTo(a_pConditionId, value.Value.NodeId);
UaServer_Events_SetEventField(a_pAlarmConditionTypeEvent, ConditionTypeField_ConditionNodeId, &value);
OpcUa_Variant_Clear(&value);
/* set acknowledgeable condition type fields */
value.Value.LocalizedText = (OpcUa_LocalizedText*)OpcUa_Alloc(sizeof(OpcUa_LocalizedText));
OpcUa_ReturnErrorIfAllocFailed(value.Value.LocalizedText);
OpcUa_LocalizedText_Initialize(value.Value.LocalizedText);
value.Datatype = OpcUaType_LocalizedText;
OpcUa_String_StrnCat(&value.Value.LocalizedText->Text, OpcUa_String_FromCString("Unacknowledged"), OPCUA_STRING_LENDONTCARE);
UaServer_Events_SetEventField(a_pAlarmConditionTypeEvent, AcknowledgeableConditionTypeField_AckedState, &value);
OpcUa_Variant_Clear(&value);
value.Datatype = OpcUaType_Boolean;
value.Value.Boolean = OpcUa_False;
UaServer_Events_SetEventField(a_pAlarmConditionTypeEvent, AcknowledgeableConditionTypeField_AckedState_Id, &value);
OpcUa_Variant_Clear(&value);
value.Datatype = OpcUaType_DateTime;
value.Value.DateTime.dwHighDateTime = 0;
value.Value.DateTime.dwLowDateTime = 0;
UaServer_Events_SetEventField(a_pAlarmConditionTypeEvent, AcknowledgeableConditionTypeField_AckedState_TransitionTime, &value);
OpcUa_Variant_Clear(&value);
value.Value.LocalizedText = (OpcUa_LocalizedText*)OpcUa_Alloc(sizeof(OpcUa_LocalizedText));
OpcUa_ReturnErrorIfAllocFailed(value.Value.LocalizedText);
OpcUa_LocalizedText_Initialize(value.Value.LocalizedText);
value.Datatype = OpcUaType_LocalizedText;
OpcUa_String_StrnCat(&value.Value.LocalizedText->Text, OpcUa_String_FromCString("Unconfirmed"), OPCUA_STRING_LENDONTCARE);
UaServer_Events_SetEventField(a_pAlarmConditionTypeEvent, AcknowledgeableConditionTypeField_ConfirmedState, &value);
OpcUa_Variant_Clear(&value);
value.Datatype = OpcUaType_Boolean;
value.Value.Boolean = OpcUa_False;
UaServer_Events_SetEventField(a_pAlarmConditionTypeEvent, AcknowledgeableConditionTypeField_ConfirmedState_Id, &value);
OpcUa_Variant_Clear(&value);
value.Datatype = OpcUaType_DateTime;
value.Value.DateTime.dwHighDateTime = 0;
value.Value.DateTime.dwLowDateTime = 0;
UaServer_Events_SetEventField(a_pAlarmConditionTypeEvent, AcknowledgeableConditionTypeField_ConfirmedState_TransitionTime, &value);
OpcUa_Variant_Clear(&value);
/* set alarm condition type fields */
value.Value.LocalizedText = (OpcUa_LocalizedText*)OpcUa_Alloc(sizeof(OpcUa_LocalizedText));
OpcUa_ReturnErrorIfAllocFailed(value.Value.LocalizedText);
OpcUa_LocalizedText_Initialize(value.Value.LocalizedText);
value.Datatype = OpcUaType_LocalizedText;
OpcUa_String_StrnCat(&value.Value.LocalizedText->Text, OpcUa_String_FromCString("Inactive"), OPCUA_STRING_LENDONTCARE);
UaServer_Events_SetEventField(a_pAlarmConditionTypeEvent, AlarmConditionTypeField_ActiveState, &value);
OpcUa_Variant_Clear(&value);
value.Datatype = OpcUaType_Boolean;
value.Value.Boolean = OpcUa_False;
UaServer_Events_SetEventField(a_pAlarmConditionTypeEvent, AlarmConditionTypeField_ActiveState_Id, &value);
OpcUa_Variant_Clear(&value);
value.Value.NodeId = (OpcUa_NodeId*)OpcUa_Alloc(sizeof(OpcUa_NodeId));
OpcUa_ReturnErrorIfAllocFailed(value.Value.NodeId);
OpcUa_NodeId_Initialize(value.Value.NodeId);
value.Datatype = OpcUaType_NodeId;
OpcUa_NodeId_CopyTo(a_pSourceNode, value.Value.NodeId);
UaServer_Events_SetEventField(a_pAlarmConditionTypeEvent, AlarmConditionTypeField_InputNode, &value);
OpcUa_Variant_Clear(&value);
value.Datatype = OpcUaType_Boolean;
value.Value.Boolean = OpcUa_False;
UaServer_Events_SetEventField(a_pAlarmConditionTypeEvent, AlarmConditionTypeField_SuppressedOrShelved, &value);
OpcUa_Variant_Clear(&value);
return OpcUa_Good;
}
OpcUa_StatusCode UaProvider_Demo_FireAlarmConditionTypeEvent(UaServer_Event *a_pEvent)
{
OpcUa_ByteString bsEventId;
OpcUa_DateTime utcNow = OpcUa_DateTime_UtcNow();
/* set base event type fields */
OpcUa_ByteString_Initialize(&bsEventId);
UaServer_Events_CreateEventId(OpcUa_Null, &bsEventId);
UaServer_Events_SetEventId(a_pEvent, &bsEventId);
OpcUa_ByteString_Clear(&bsEventId);
UaServer_Events_SetTime(a_pEvent, utcNow);
UaServer_Events_SetReceiveTime(a_pEvent, utcNow);
/* set condition type fields */
OpcUa_Variant_Initialize(&value);
value.Value.LocalizedText = (OpcUa_LocalizedText*)OpcUa_Alloc(sizeof(OpcUa_LocalizedText));
OpcUa_ReturnErrorIfAllocFailed(value.Value.LocalizedText);
OpcUa_LocalizedText_Initialize(value.Value.LocalizedText);
value.Datatype = OpcUaType_LocalizedText;
OpcUa_String_StrnCat(&value.Value.LocalizedText->Text, OpcUa_String_FromCString("true"), OPCUA_STRING_LENDONTCARE);
UaServer_Events_SetEventField(a_pEvent, ConditionTypeField_EnabledState, &value);
OpcUa_Variant_Clear(&value);
value.Value.LocalizedText = (OpcUa_LocalizedText*)OpcUa_Alloc(sizeof(OpcUa_LocalizedText));
OpcUa_ReturnErrorIfAllocFailed(value.Value.LocalizedText);
OpcUa_LocalizedText_Initialize(value.Value.LocalizedText);
value.Datatype = OpcUaType_LocalizedText;
UaServer_Events_SetEventField(a_pEvent, ConditionTypeField_EnabledState_EffectiveDisplayName, &value);
OpcUa_Variant_Clear(&value);
value.Datatype = OpcUaType_DateTime;
value.Value.DateTime.dwHighDateTime = 0;
value.Value.DateTime.dwLowDateTime = 0;
UaServer_Events_SetEventField(a_pEvent, ConditionTypeField_EnabledState_EffectiveTransitionTime, &value);
OpcUa_Variant_Clear(&value);
value.Datatype = OpcUaType_Boolean;
value.Value.Boolean = OpcUa_True;
UaServer_Events_SetEventField(a_pEvent, ConditionTypeField_EnabledState_Id, &value);
OpcUa_Variant_Clear(&value);
value.Datatype = OpcUaType_DateTime;
value.Value.DateTime.dwHighDateTime = 0;
value.Value.DateTime.dwLowDateTime = 0;
UaServer_Events_SetEventField(a_pEvent, ConditionTypeField_EnabledState_TransitionTime, &value);
OpcUa_Variant_Clear(&value);
value.Datatype = OpcUaType_Boolean;
value.Value.Boolean = OpcUa_True;
UaServer_Events_SetEventField(a_pEvent, ConditionTypeField_Retain, &value);
OpcUa_Variant_Clear(&value);
/* set acknowledgeable condition type fields */
value.Value.LocalizedText = (OpcUa_LocalizedText*)OpcUa_Alloc(sizeof(OpcUa_LocalizedText));
OpcUa_ReturnErrorIfAllocFailed(value.Value.LocalizedText);
OpcUa_LocalizedText_Initialize(value.Value.LocalizedText);
value.Datatype = OpcUaType_LocalizedText;
OpcUa_String_StrnCat(&value.Value.LocalizedText->Text, OpcUa_String_FromCString("Unacknowledged"), OPCUA_STRING_LENDONTCARE);
UaServer_Events_SetEventField(a_pEvent, AcknowledgeableConditionTypeField_AckedState, &value);
OpcUa_Variant_Clear(&value);
value.Datatype = OpcUaType_Boolean;
value.Value.Boolean = OpcUa_False;
UaServer_Events_SetEventField(a_pEvent, AcknowledgeableConditionTypeField_AckedState_Id, &value);
OpcUa_Variant_Clear(&value);
value.Datatype = OpcUaType_DateTime;
value.Value.DateTime.dwHighDateTime = 0;
value.Value.DateTime.dwLowDateTime = 0;
UaServer_Events_SetEventField(a_pEvent, AcknowledgeableConditionTypeField_AckedState_TransitionTime, &value);
OpcUa_Variant_Clear(&value);
value.Value.LocalizedText = (OpcUa_LocalizedText*)OpcUa_Alloc(sizeof(OpcUa_LocalizedText));
OpcUa_ReturnErrorIfAllocFailed(value.Value.LocalizedText);
OpcUa_LocalizedText_Initialize(value.Value.LocalizedText);
value.Datatype = OpcUaType_LocalizedText;
OpcUa_String_StrnCat(&value.Value.LocalizedText->Text, OpcUa_String_FromCString("Unconfirmed"), OPCUA_STRING_LENDONTCARE);
UaServer_Events_SetEventField(a_pEvent, AcknowledgeableConditionTypeField_ConfirmedState, &value);
OpcUa_Variant_Clear(&value);
value.Datatype = OpcUaType_Boolean;
value.Value.Boolean = OpcUa_False;
UaServer_Events_SetEventField(a_pEvent, AcknowledgeableConditionTypeField_ConfirmedState_Id, &value);
OpcUa_Variant_Clear(&value);
value.Datatype = OpcUaType_DateTime;
value.Value.DateTime.dwHighDateTime = 0;
value.Value.DateTime.dwLowDateTime = 0;
UaServer_Events_SetEventField(a_pEvent, AcknowledgeableConditionTypeField_ConfirmedState_TransitionTime, &value);
OpcUa_Variant_Clear(&value);
/* set alarm condition type fields */
value.Value.LocalizedText = (OpcUa_LocalizedText*)OpcUa_Alloc(sizeof(OpcUa_LocalizedText));
OpcUa_ReturnErrorIfAllocFailed(value.Value.LocalizedText);
OpcUa_LocalizedText_Initialize(value.Value.LocalizedText);
value.Datatype = OpcUaType_LocalizedText;
OpcUa_String_StrnCat(&value.Value.LocalizedText->Text, OpcUa_String_FromCString("Active"), OPCUA_STRING_LENDONTCARE);
UaServer_Events_SetEventField(a_pEvent, AlarmConditionTypeField_ActiveState, &value);
OpcUa_Variant_Clear(&value);
value.Datatype = OpcUaType_Boolean;
value.Value.Boolean = OpcUa_True;
UaServer_Events_SetEventField(a_pEvent, AlarmConditionTypeField_ActiveState_Id, &value);
OpcUa_Variant_Clear(&value);
result = UaServer_Events_FireEvent(a_pEvent);
return result;
}
#if UASERVER_SUPPORT_CONDITION_BRANCHES
OpcUa_StatusCode UaProvider_Demo_CreateConditionBranch(UaServer_Event* a_pEvent)
{
OpcUa_UInt32 branchId = 0;
UaServer_Event *pPreviousConditionBranch = OpcUa_Null;
OpcUa_NodeId eventTypeId;
UaServer_EventType *pEventType = OpcUa_Null;
UaServer_Event *pConditionBranch = OpcUa_Null;
OpcUa_ByteString bsEventId;
OpcUa_Variant *pValue = OpcUa_Null;
OpcUa_ReturnErrorIfArgumentNull(a_pEvent);
OpcUa_NodeId_Initialize(&eventTypeId);
OpcUa_Variant_Initialize(&value);
UaBase_CreateNumericNodeIdEx(&eventTypeId, OpcUaId_AlarmConditionType, 0);
pEventType = UaServer_Events_FindEventType(&eventTypeId);
pConditionBranch = OpcUa_Alloc(sizeof(UaServer_Event));
OpcUa_ReturnErrorIfAllocFailed(pConditionBranch);
UaServer_Event_Initialize(pConditionBranch, pEventType);
/* set new EventId */
OpcUa_ByteString_Initialize(&bsEventId);
UaServer_Events_CreateEventId(OpcUa_Null, &bsEventId);
UaServer_Events_SetEventId(pConditionBranch, &bsEventId);
OpcUa_ByteString_Clear(&bsEventId);
/* set other base event type fields as copy of the current condition state (main branch) */
UaServer_Events_SetSourceName(pConditionBranch, OpcUa_String_GetRawString(UaServer_Events_GetSourceName(a_pEvent)));
UaServer_Events_SetMessage(pConditionBranch, "en", OpcUa_String_GetRawString(&UaServer_Events_GetMessage(a_pEvent)->Text));
UaServer_Events_SetTime(pConditionBranch, UaServer_Events_GetTime(a_pEvent));
/* generate and set a Condition Branch NodeId */
OpcUa_List_ResetCurrent(a_pEvent->pConditionBranchList);
pPreviousConditionBranch = OpcUa_List_GetCurrentElement(a_pEvent->pConditionBranchList);
if (pPreviousConditionBranch != OpcUa_Null)
{
pValue = UaServer_Events_GetEventField(pPreviousConditionBranch, ConditionTypeField_BranchId);
OpcUa_ReturnErrorIfNull(pValue, OpcUa_BadNotFound);
branchId = pValue->Value.NodeId->Identifier.Numeric;
}
value.Datatype = OpcUaType_NodeId;
value.Value.NodeId = (OpcUa_NodeId*)OpcUa_Alloc(sizeof(OpcUa_NodeId));
if (value.Value.NodeId == OpcUa_Null)
{
UaServer_Event_Clear(pConditionBranch);
OpcUa_Free(pConditionBranch);
pConditionBranch = OpcUa_Null;
return OpcUa_BadOutOfMemory;
}
UaBase_CreateNumericNodeId(value.Value.NodeId, branchId + 1);
UaServer_Events_SetEventField(pConditionBranch, ConditionTypeField_BranchId, &value);
OpcUa_Variant_Clear(&value);
/* set other condition type fields as copy of the current condition state (main branch) */
UaServer_Events_SetEventField(pConditionBranch, ConditionTypeField_ClientUserId, UaServer_Events_GetEventField(a_pEvent, ConditionTypeField_ClientUserId));
UaServer_Events_SetEventField(pConditionBranch, ConditionTypeField_Comment, UaServer_Events_GetEventField(a_pEvent, ConditionTypeField_Comment));
UaServer_Events_SetEventField(pConditionBranch, ConditionTypeField_Comment_SourceTimestamp, UaServer_Events_GetEventField(a_pEvent, ConditionTypeField_Comment_SourceTimestamp));
UaServer_Events_SetEventField(pConditionBranch, ConditionTypeField_ConditionClassId, UaServer_Events_GetEventField(a_pEvent, ConditionTypeField_ConditionClassId));
UaServer_Events_SetEventField(pConditionBranch, ConditionTypeField_ConditionClassName, UaServer_Events_GetEventField(a_pEvent, ConditionTypeField_ConditionClassName));
UaServer_Events_SetEventField(pConditionBranch, ConditionTypeField_ConditionName, UaServer_Events_GetEventField(a_pEvent, ConditionTypeField_ConditionName));
UaServer_Events_SetEventField(pConditionBranch, ConditionTypeField_EnabledState, UaServer_Events_GetEventField(a_pEvent, ConditionTypeField_EnabledState));
UaServer_Events_SetEventField(pConditionBranch, ConditionTypeField_EnabledState_EffectiveDisplayName, UaServer_Events_GetEventField(a_pEvent, ConditionTypeField_EnabledState_EffectiveDisplayName));
UaServer_Events_SetEventField(pConditionBranch, ConditionTypeField_EnabledState_EffectiveTransitionTime, UaServer_Events_GetEventField(a_pEvent, ConditionTypeField_EnabledState_EffectiveTransitionTime));
UaServer_Events_SetEventField(pConditionBranch, ConditionTypeField_EnabledState_Id, UaServer_Events_GetEventField(a_pEvent, ConditionTypeField_EnabledState_Id));
UaServer_Events_SetEventField(pConditionBranch, ConditionTypeField_EnabledState_TransitionTime, UaServer_Events_GetEventField(a_pEvent, ConditionTypeField_EnabledState_TransitionTime));
UaServer_Events_SetEventField(pConditionBranch, ConditionTypeField_LastSeverity, UaServer_Events_GetEventField(a_pEvent, ConditionTypeField_LastSeverity));
UaServer_Events_SetEventField(pConditionBranch, ConditionTypeField_LastSeverity_SourceTimestamp, UaServer_Events_GetEventField(a_pEvent, ConditionTypeField_LastSeverity_SourceTimestamp));
UaServer_Events_SetEventField(pConditionBranch, ConditionTypeField_Quality, UaServer_Events_GetEventField(a_pEvent, ConditionTypeField_Quality));
UaServer_Events_SetEventField(pConditionBranch, ConditionTypeField_Quality_SourceTimestamp, UaServer_Events_GetEventField(a_pEvent, ConditionTypeField_Quality_SourceTimestamp));
UaServer_Events_SetEventField(pConditionBranch, ConditionTypeField_Retain, UaServer_Events_GetEventField(a_pEvent, ConditionTypeField_Retain));
UaServer_Events_SetEventField(pConditionBranch, ConditionTypeField_ConditionNodeId, UaServer_Events_GetEventField(a_pEvent, ConditionTypeField_ConditionNodeId));
UaServer_Events_SetEventField(pConditionBranch, AcknowledgeableConditionTypeField_AckedState, UaServer_Events_GetEventField(a_pEvent, AcknowledgeableConditionTypeField_AckedState));
UaServer_Events_SetEventField(pConditionBranch, AcknowledgeableConditionTypeField_AckedState_Id, UaServer_Events_GetEventField(a_pEvent, AcknowledgeableConditionTypeField_AckedState_Id));
UaServer_Events_SetEventField(pConditionBranch, AcknowledgeableConditionTypeField_AckedState_TransitionTime, UaServer_Events_GetEventField(a_pEvent, AcknowledgeableConditionTypeField_AckedState_TransitionTime));
UaServer_Events_SetEventField(pConditionBranch, AcknowledgeableConditionTypeField_ConfirmedState, UaServer_Events_GetEventField(a_pEvent, AcknowledgeableConditionTypeField_ConfirmedState));
UaServer_Events_SetEventField(pConditionBranch, AcknowledgeableConditionTypeField_ConfirmedState_Id, UaServer_Events_GetEventField(a_pEvent, AcknowledgeableConditionTypeField_ConfirmedState_Id));
UaServer_Events_SetEventField(pConditionBranch, AcknowledgeableConditionTypeField_ConfirmedState_TransitionTime, UaServer_Events_GetEventField(a_pEvent, AcknowledgeableConditionTypeField_ConfirmedState_TransitionTime));
UaServer_Events_SetEventField(pConditionBranch, AlarmConditionTypeField_ActiveState, UaServer_Events_GetEventField(a_pEvent, AlarmConditionTypeField_ActiveState));
UaServer_Events_SetEventField(pConditionBranch, AlarmConditionTypeField_ActiveState_Id, UaServer_Events_GetEventField(a_pEvent, AlarmConditionTypeField_ActiveState_Id));
UaServer_Events_SetEventField(pConditionBranch, AlarmConditionTypeField_InputNode, UaServer_Events_GetEventField(a_pEvent, AlarmConditionTypeField_InputNode));
UaServer_Events_SetEventField(pConditionBranch, AlarmConditionTypeField_SuppressedOrShelved, UaServer_Events_GetEventField(a_pEvent, AlarmConditionTypeField_SuppressedOrShelved));
/* add branch to the branch list of the condition */
result = OpcUa_List_AddElement(a_pEvent->pConditionBranchList, pConditionBranch);
OpcUa_ReturnErrorIfBad(result);
/* fire state of new branch as event to clients */
result = UaServer_Events_FireEvent(pConditionBranch);
return result;
}
#endif
OpcUa_StatusCode UaProvider_Demo_DisableAlarmConditionTypeEvent(UaServer_Event *a_pEvent)
{
OpcUa_DateTime utcNow = OpcUa_DateTime_UtcNow();
#if UASERVER_SUPPORT_CONDITION_BRANCHES
OpcUa_Variant *pValue = OpcUa_Null;
OpcUa_Boolean bConditionAcknowledged = OpcUa_False;
OpcUa_Boolean bConditionConfirmed = OpcUa_False;
/* get AckedState for check if a branch is needed */
pValue = UaServer_Events_GetEventField(a_pEvent, AcknowledgeableConditionTypeField_AckedState_Id);
if (pValue != OpcUa_Null)
{
bConditionAcknowledged = pValue->Value.Boolean;
}
/* get ConfirmedState for check if a branch is needed */
pValue = UaServer_Events_GetEventField(a_pEvent, AcknowledgeableConditionTypeField_ConfirmedState_Id);
if (pValue != OpcUa_Null)
{
bConditionConfirmed = pValue->Value.Boolean;
}
#endif
/* set condition type fields */
OpcUa_Variant_Initialize(&value);
value.Value.LocalizedText = (OpcUa_LocalizedText*)OpcUa_Alloc(sizeof(OpcUa_LocalizedText));
OpcUa_ReturnErrorIfAllocFailed(value.Value.LocalizedText);
OpcUa_LocalizedText_Initialize(value.Value.LocalizedText);
value.Datatype = OpcUaType_LocalizedText;
OpcUa_String_StrnCat(&value.Value.LocalizedText->Text, OpcUa_String_FromCString("Disabled"), OPCUA_STRING_LENDONTCARE);
UaServer_Events_SetEventField(a_pEvent, ConditionTypeField_EnabledState, &value);
OpcUa_Variant_Clear(&value);
value.Datatype = OpcUaType_Boolean;
value.Value.Boolean = OpcUa_False;
UaServer_Events_SetEventField(a_pEvent, ConditionTypeField_EnabledState_Id, &value);
OpcUa_Variant_Clear(&value);
value.Datatype = OpcUaType_DateTime;
value.Value.DateTime = utcNow;
UaServer_Events_SetEventField(a_pEvent, ConditionTypeField_EnabledState_TransitionTime, &value);
OpcUa_Variant_Clear(&value);
/* set alarm condition type fields */
value.Value.LocalizedText = (OpcUa_LocalizedText*)OpcUa_Alloc(sizeof(OpcUa_LocalizedText));
OpcUa_ReturnErrorIfAllocFailed(value.Value.LocalizedText);
OpcUa_LocalizedText_Initialize(value.Value.LocalizedText);
value.Datatype = OpcUaType_LocalizedText;
OpcUa_String_StrnCat(&value.Value.LocalizedText->Text, OpcUa_String_FromCString("Inactive"), OPCUA_STRING_LENDONTCARE);
UaServer_Events_SetEventField(a_pEvent, AlarmConditionTypeField_ActiveState, &value);
OpcUa_Variant_Clear(&value);
value.Datatype = OpcUaType_Boolean;
value.Value.Boolean = OpcUa_False;
UaServer_Events_SetEventField(a_pEvent, AlarmConditionTypeField_ActiveState_Id, &value);
OpcUa_Variant_Clear(&value);
#if UASERVER_SUPPORT_CONDITION_BRANCHES
if (bConditionAcknowledged == OpcUa_False || bConditionConfirmed == OpcUa_False)
{
/* if the state is unacknowledged or unconfirmed, we create a branch*/
if (a_pEvent->pConditionBranchList == OpcUa_Null)
{
/* create the branch list */
result = OpcUa_List_Create(&a_pEvent->pConditionBranchList);
OpcUa_ReturnErrorIfBad(result);
}
/* create the condition branch */
result = UaProvider_Demo_CreateConditionBranch(a_pEvent);
OpcUa_ReturnErrorIfBad(result);
}
#endif
value.Datatype = OpcUaType_Boolean;
value.Value.Boolean = OpcUa_False;
UaServer_Events_SetEventField(a_pEvent, ConditionTypeField_Retain, &value);
OpcUa_Variant_Clear(&value);
result = UaServer_Events_FireEvent(a_pEvent);
return result;
}
OPCUA_END_EXTERN_C