EventFilter
Resumen
OPC UA Part 4 §7.18 EventFilter:
- select_clauses — ¿Qué campos hay que tener en cuenta?
- where_clause — Condiciones de filtrado (V1 basta con dejar NULL)
DarraUa_SimpleAttributeOperand Campos: type_definition_id / browse_path / attribute_id / index_range.
Filtrado de eventos API en SDK los encabezados de extensión (no ABI en los encabezados de la pila de protocolos):
#include <opcua/opcua.h>
#include "../include/opcua_filter.h"
API
typedef struct {
/** Tipo de evento: cadena NodeId , como "i=2041" (BaseEventType). NULL = comodín BaseEventType. */
const char* type_definition_id;
/** Campo BrowsePath (cada segmento BrowseName). NULL O bien, si count == 0, se seleccionan todos los eventos. */
const char* const* browse_path;
size_t browse_path_count;
/** Propiedad ID, por defecto UA_ATTR_VALUE. */
DarraUa_AttributeId attribute_id;
/** Rango de índices del array (NumericRange cadena). NULL = No se ha establecido. */
const char* index_range;
} DarraUa_SimpleAttributeOperand;
typedef struct {
const DarraUa_SimpleAttributeOperand* select_clauses;
size_t select_clauses_count;
const char* where_clause; /* NULL = sin «where» */
} DarraUa_EventFilter;
| Función | Categoría | Lectura y escritura | Explicación |
|---|---|---|---|
| DarraUa_EventSubscription_SubscribeWithFilter(sub, object_node_id, filter, cb, user_context, out_mi) | Función | Escribir | Crear un evento con un filtro personalizado MI |
UA_SDK_API DarraUa_Status UA_SDK_CALL DarraUa_EventSubscription_SubscribeWithFilter(
DarraUa_SubscriptionHandle sub,
const char* object_node_id, /* NULL = "i=2253" */
const DarraUa_EventFilter* filter, /* NULL = Utilizar los 4 campos predeterminados */
DarraUa_OnEvent cb,
void* user_context,
DarraUa_MonitoredItemHandle* out_mi);
La firma de la llamada de retorno del evento se encuentra en Suscripción a eventos DarraUa_OnEvent.
Ejemplo de código
#include <opcua/opcua.h>
#include "../include/opcua_filter.h"
DarraUa_SessionConfig cfg;
DarraUa_SessionConfig_Init(&cfg);
cfg.endpoint_url = "opc.tcp://localhost:4840";
cfg.security_mode = UA_MSG_SECURITY_MODE_NONE;
cfg.security_policy_uri = "http://opcfoundation.org/UA/SecurityPolicy#None";
cfg.user_token_type = UA_USER_TOKEN_ANONYMOUS;
DarraUa_SessionHandle h = UA_INVALID_SESSION_HANDLE;
DarraUa_Session_Create(&cfg, &h);
DarraUa_Session_Connect(h);
DarraUa_SubscriptionConfig sc;
DarraUa_SubscriptionConfig_Init(&sc);
sc.publishing_interval_ms = 500.0;
sc.publishing_enabled = 1;
DarraUa_SubscriptionHandle sub = UA_INVALID_SUBSCRIPTION_HANDLE;
DarraUa_Subscription_Create(h, &sc, &sub);
// Crear filtro
const char* event_id_path[] = { "EventId" };
const char* source_path[] = { "SourceName" };
const char* time_path[] = { "Time" };
const char* msg_path[] = { "Message" };
const char* sev_path[] = { "Severity" };
const char* cond_id_path[] = { "ConditionId" };
const char* active_state_path[] = { "ActiveState", "Id" };
DarraUa_SimpleAttributeOperand selects[7] = {
{ "i=2041", event_id_path, 1, UA_ATTR_VALUE, NULL },
{ "i=2041", source_path, 1, UA_ATTR_VALUE, NULL },
{ "i=2041", time_path, 1, UA_ATTR_VALUE, NULL },
{ "i=2041", msg_path, 1, UA_ATTR_VALUE, NULL },
{ "i=2041", sev_path, 1, UA_ATTR_VALUE, NULL },
{ "i=2782", cond_id_path, 1, UA_ATTR_VALUE, NULL },
{ "i=2915", active_state_path, 2, UA_ATTR_VALUE, NULL },
};
DarraUa_EventFilter filter = {
.select_clauses = selects,
.select_clauses_count = 7,
.where_clause = NULL,
};
DarraUa_MonitoredItemHandle ev_mi = UA_INVALID_MONITORED_ITEM_HANDLE;
DarraUa_Status st = DarraUa_EventSubscription_SubscribeWithFilter(
sub, "i=2253", &filter, on_event, NULL, &ev_mi);
on_event
El campo de DarraUa_Event
carga se calcula de forma fija SDK
severity
/ message
/ source_name
/ time
/ event_type
, y no varía con el desarrollo por términos select_clauses
; las cláusulas select_clauses personalizadas determinan**¿Qué campos envía el servidor?**。
Referencia rápida de campos
| EventType | BrowsePath | Significado |
|---|---|---|
| BaseEventType (i=2041) | ["EventId"] | ID único del evento |
| BaseEventType | ["Severity"] | Gravedad: 1-1000 |
| ConditionType (i=2782) | ["ConditionId"] | Condiciones NodeId |
| AcknowledgeableConditionType (i=2881) | ["AckedState", "Id"] | ¿Se ha confirmado? |
| AlarmConditionType (i=2915) | ["ActiveState", "Id"] | ¿Está activado? |
Descripción de la implementación
- Todos los campos se toman prestados; se realiza una copia profunda en el punto de entrada RPC del SDK; al
SubscribeWithFilterregresar, la estructura se puede liberar o salir del ámbito. - Stack no admite la degradación gradual personalizada SelectClauses : recambioPor defecto, 4 campos (Gravedad / Mensaje / SourceName / Hora), y registrar un mensaje de información en el log
Buenas prácticas
- Campos de columna explícitos
- Es imprescindible instalar un panel de alarma ConditionId
Comparación entre idiomas
| C# | Python | Java | C++ | Rust | C |
|---|---|---|---|---|---|
| EventFilter | EventFilter | EventFilter | EventFilter | EventFilter | DarraUa_EventFilter |
| SimpleAttributeOperand | SimpleAttributeOperand | SimpleAttributeOperand | SimpleAttributeOperand | SimpleAttributeOperand | DarraUa_SimpleAttributeOperand |