/*
 * Copyright (C) 2022 EXOLIGENT (www.exoligent.com)
 * Author: Maxime Coroyer <maxime.coroyer@exoligent.com>
 */

#ifndef __OPC_RT_H__
#define __OPC_RT_H__

#include <open62541/server.h>

#define OPC_RT_QBV_OFFSET               (125 * 1000) /* Qbv offset */
#define OPC_RT_SOCKET_PRIORITY          7
#define OPC_RT_PUBSUB_SCHED_PRIORITY    90
#define OPC_RT_PUBSUB_CORE              2
#define OPC_RT_PUB_WKUP_PERCENTAGE      0.8

/* add a callback for cyclic repetition */
UA_StatusCode opc_rt_cb_add(UA_Server *srv, UA_NodeId group_id,
    UA_ServerCallback cb, void *data, UA_Double interval_ms,
    UA_DateTime *baseTime, UA_TimerPolicy timerPolicy, UA_UInt64 *cb_id);

/* change cycle repetition of the callback */
UA_StatusCode opc_rt_cb_change(UA_Server *srv, UA_NodeId group_id,
    UA_UInt64 cb_id, UA_Double interval_ms, UA_DateTime *baseTime,
    UA_TimerPolicy timerPolicy);

/* remove the callback added for cyclic repetition */
void opc_rt_cb_remove(UA_Server *srv, UA_NodeId group_id, UA_UInt64 cb_id);

UA_StatusCode opc_rt_cb_ext_datawrite(UA_Server *srv,
    const UA_NodeId *sess_id, void *sess_ctx, const UA_NodeId *node_id,
    void *node_ctx, const UA_NumericRange *range,
    const UA_DataValue *data_value);

UA_StatusCode opc_rt_cb_ext_dataread_notif(UA_Server *srv,
    const UA_NodeId *sess_id, void *sess_ctx, const UA_NodeId *node_id,
    void *node_ctx, const UA_NumericRange *range);

int opc_rt_app_start(void *args);
int opc_rt_app_stop(void *args);

#endif
