Skip to content

File syn_opcua.h

FileList > proto > syn_opcua.h

Go to the source code of this file

Micro OPC UA (IEC 62541) Binary Protocol Engine & Embedded Server. More...

  • #include "../common/syn_defs.h"
  • #include "../net/syn_transport.h"
  • #include "../pt/syn_pt.h"
  • #include "../sched/syn_sched.h"
  • #include <stdbool.h>
  • #include <stddef.h>
  • #include <stdint.h>

Classes

Type Name
struct SYN_OPCUA_Config
Configuration parameters for Micro OPC UA Server.
struct SYN_OPCUA_DataValue
DataValue with value, status code, and source timestamp.
struct SYN_OPCUA_Node
In-memory OPC UA Node representation.
struct SYN_OPCUA_NodeId
OPC UA NodeId.
struct SYN_OPCUA_Server
Micro OPC UA Server Instance Context.
struct SYN_OPCUA_Variant
OPC UA Variant containing dynamic value.

Public Types

Type Name
enum SYN_OPCUA_DataType
Built-in DataType enum (per Part 6).
enum SYN_OPCUA_NodeClass
NodeClass enum.
enum SYN_OPCUA_NodeIdType
NodeId identifier type.
typedef SYN_Status(* SYN_OPCUA_ReadCb
Dynamic callback invoked when a variable node is read.
enum SYN_OPCUA_ServerState
Server connection and session state.
typedef SYN_Status(* SYN_OPCUA_WriteCb
Dynamic callback invoked when a variable node is written.

Public Functions

Type Name
SYN_OPCUA_Node * syn_opcua_server_find_node_num (SYN_OPCUA_Server * srv, uint16_t ns, uint32_t num_id)
Find a node in the address space by numeric NodeId.
SYN_Status syn_opcua_server_init (SYN_OPCUA_Server * srv, const SYN_OPCUA_Config * cfg)
Initialize Micro OPC UA Server.
SYN_Status syn_opcua_server_process_message (SYN_OPCUA_Server * srv, const uint8_t * rx, size_t rx_len, uint8_t * tx, size_t max_tx, size_t * out_len)
Process an incoming raw OPC UA frame and generate a response frame.
SYN_PT_Status syn_opcua_server_pt (SYN_PT * pt, SYN_Task * task)
Protothread continuation function for syn_sched .
SYN_Status syn_opcua_server_read_variable (const SYN_OPCUA_Server * srv, uint16_t ns, uint32_t num_id, SYN_OPCUA_Variant * out_val)
Read a variable node's value from the address space.
SYN_Status syn_opcua_server_register_node (SYN_OPCUA_Server * srv, const SYN_OPCUA_Node * node)
Register a Node in the server address space.
SYN_Status syn_opcua_server_step (SYN_OPCUA_Server * srv, uint32_t now_ms)
Advance OPC UA server state machine by one step / tick.
SYN_Status syn_opcua_server_write_variable (SYN_OPCUA_Server * srv, uint16_t ns, uint32_t num_id, const SYN_OPCUA_Variant * val)
Update a variable node's value in the address space.

Macros

Type Name
define SYN_OPCUA_ATTR_ACCESS_LEVEL 17U
define SYN_OPCUA_ATTR_BROWSE_NAME 3U
define SYN_OPCUA_ATTR_DATA_TYPE 14U
define SYN_OPCUA_ATTR_DISPLAY_NAME 4U
define SYN_OPCUA_ATTR_NODE_CLASS 2U
define SYN_OPCUA_ATTR_NODE_ID 1U
define SYN_OPCUA_ATTR_VALUE 13U
define SYN_OPCUA_ATTR_VALUE_RANK 15U
define SYN_OPCUA_DEFAULT_BUFFER_SIZE 1024U
define SYN_OPCUA_DEFAULT_PORT 4840U
define SYN_OPCUA_MAX_NODES 32U
define SYN_OPCUA_MAX_REFERENCES 8U
define SYN_OPCUA_MAX_STRING_LEN 64U
define SYN_OPCUA_NODEID_OBJECTS_FOLDER 85U
define SYN_OPCUA_NODEID_ROOT 84U
define SYN_OPCUA_NODEID_SERVER 2253U
define SYN_OPCUA_NODEID_SERVER_SERVERSTATUS 2256U
define SYN_OPCUA_NS_STANDARD 0U
define SYN_OPCUA_NS_VENDOR 1U
define SYN_OPCUA_PROTOCOL_VERSION 0U
define SYN_OPCUA_STATUS_BAD_ATTRIBUTE_ID_INVALID 0x80350000U
define SYN_OPCUA_STATUS_BAD_INTERNAL_ERROR 0x80020000U
define SYN_OPCUA_STATUS_BAD_NODE_ID_UNKNOWN 0x80340000U
define SYN_OPCUA_STATUS_BAD_NOT_READABLE 0x803A0000U
define SYN_OPCUA_STATUS_BAD_NOT_WRITABLE 0x803B0000U
define SYN_OPCUA_STATUS_BAD_SECURITY_CHECKS_FAILED 0x80130000U
define SYN_OPCUA_STATUS_BAD_SERVICE_UNSUPPORTED 0x80430000U
define SYN_OPCUA_STATUS_BAD_UNEXPECTED 0x80010000U
define SYN_OPCUA_STATUS_GOOD 0x00000000U
define SYN_OPCUA_STATUS_UNCERTAIN 0x40000000U

Detailed Description

Implements a zero-heap, deterministic OPC UA Binary protocol engine: * UACP (OPC UA Connection Protocol) framing (HEL, ACK, ERR). * UASC (OPC UA Secure Conversation) framing (OPN, CLO, MSG) with Security Policy None & Basic256Sha256. * Static In-Memory Address Space: Object, Variable, and Method nodes with numeric & string NodeIds. * Core Services: Read, Write, Browse, CreateSession, ActivateSession, CreateSubscription, Publish. * Non-blocking poll step API and cooperative protothread continuation for syn_sched.

Public Types Documentation

enum SYN_OPCUA_DataType

Built-in DataType enum (per Part 6).

enum SYN_OPCUA_DataType {
    SYN_OPCUA_TYPE_NULL = 0,
    SYN_OPCUA_TYPE_BOOLEAN = 1,
    SYN_OPCUA_TYPE_SBYTE = 2,
    SYN_OPCUA_TYPE_BYTE = 3,
    SYN_OPCUA_TYPE_INT16 = 4,
    SYN_OPCUA_TYPE_UINT16 = 5,
    SYN_OPCUA_TYPE_INT32 = 6,
    SYN_OPCUA_TYPE_UINT32 = 7,
    SYN_OPCUA_TYPE_INT64 = 8,
    SYN_OPCUA_TYPE_UINT64 = 9,
    SYN_OPCUA_TYPE_FLOAT = 10,
    SYN_OPCUA_TYPE_DOUBLE = 11,
    SYN_OPCUA_TYPE_STRING = 12,
    SYN_OPCUA_TYPE_DATETIME = 13
};


enum SYN_OPCUA_NodeClass

NodeClass enum.

enum SYN_OPCUA_NodeClass {
    SYN_OPCUA_NODECLASS_UNSPECIFIED = 0,
    SYN_OPCUA_NODECLASS_OBJECT = 1,
    SYN_OPCUA_NODECLASS_VARIABLE = 2,
    SYN_OPCUA_NODECLASS_METHOD = 4
};


enum SYN_OPCUA_NodeIdType

NodeId identifier type.

enum SYN_OPCUA_NodeIdType {
    SYN_OPCUA_NODEID_NUMERIC = 0,
    SYN_OPCUA_NODEID_STRING = 1
};


typedef SYN_OPCUA_ReadCb

Dynamic callback invoked when a variable node is read.

typedef SYN_Status(* SYN_OPCUA_ReadCb) (struct SYN_OPCUA_Server *srv, const struct SYN_OPCUA_Node *node, SYN_OPCUA_DataValue *out_val, void *user_data);


enum SYN_OPCUA_ServerState

Server connection and session state.

enum SYN_OPCUA_ServerState {
    SYN_OPCUA_STATE_CLOSED = 0,
    SYN_OPCUA_STATE_HELLO_RECEIVED,
    SYN_OPCUA_STATE_SECURE_CHANNEL,
    SYN_OPCUA_STATE_SESSION_ACTIVE
};


typedef SYN_OPCUA_WriteCb

Dynamic callback invoked when a variable node is written.

typedef SYN_Status(* SYN_OPCUA_WriteCb) (struct SYN_OPCUA_Server *srv, const struct SYN_OPCUA_Node *node, const SYN_OPCUA_DataValue *in_val, void *user_data);


Public Functions Documentation

function syn_opcua_server_find_node_num

Find a node in the address space by numeric NodeId.

SYN_OPCUA_Node * syn_opcua_server_find_node_num (
    SYN_OPCUA_Server * srv,
    uint16_t ns,
    uint32_t num_id
) 

Parameters:

  • srv Server instance.
  • ns Namespace index.
  • num_id Numeric identifier.

Returns:

Pointer to node in address space or NULL if not found.


function syn_opcua_server_init

Initialize Micro OPC UA Server.

SYN_Status syn_opcua_server_init (
    SYN_OPCUA_Server * srv,
    const SYN_OPCUA_Config * cfg
) 

Parameters:

  • srv Server instance to initialize.
  • cfg Server configuration.

Returns:

SYN_OK on success, SYN_INVALID_PARAM on invalid argument.


function syn_opcua_server_process_message

Process an incoming raw OPC UA frame and generate a response frame.

SYN_Status syn_opcua_server_process_message (
    SYN_OPCUA_Server * srv,
    const uint8_t * rx,
    size_t rx_len,
    uint8_t * tx,
    size_t max_tx,
    size_t * out_len
) 

Parameters:

  • srv Server instance.
  • rx Inbound raw message frame.
  • rx_len Inbound length in bytes.
  • tx Outbound response frame buffer.
  • max_tx Outbound buffer capacity.
  • out_len Pointer receiving generated response length.

Returns:

SYN_OK on success.


function syn_opcua_server_pt

Protothread continuation function for syn_sched .

SYN_PT_Status syn_opcua_server_pt (
    SYN_PT * pt,
    SYN_Task * task
) 

Parameters:

  • pt Protothread continuation structure.
  • task Task handle containing SYN_OPCUA_Server in user_data.

Returns:

SYN_PT_Status continuation status.


function syn_opcua_server_read_variable

Read a variable node's value from the address space.

SYN_Status syn_opcua_server_read_variable (
    const SYN_OPCUA_Server * srv,
    uint16_t ns,
    uint32_t num_id,
    SYN_OPCUA_Variant * out_val
) 

Parameters:

  • srv Server instance.
  • ns Namespace index.
  • num_id Numeric identifier.
  • out_val Output variant value pointer.

Returns:

SYN_OK on success, SYN_ERROR if not found.


function syn_opcua_server_register_node

Register a Node in the server address space.

SYN_Status syn_opcua_server_register_node (
    SYN_OPCUA_Server * srv,
    const SYN_OPCUA_Node * node
) 

Parameters:

  • srv Server instance.
  • node Node descriptor to copy into address space.

Returns:

SYN_OK on success, SYN_ERROR if address space is full.


function syn_opcua_server_step

Advance OPC UA server state machine by one step / tick.

SYN_Status syn_opcua_server_step (
    SYN_OPCUA_Server * srv,
    uint32_t now_ms
) 

Parameters:

  • srv Server instance.
  • now_ms Current system timestamp in milliseconds.

Returns:

SYN_OK on success.


function syn_opcua_server_write_variable

Update a variable node's value in the address space.

SYN_Status syn_opcua_server_write_variable (
    SYN_OPCUA_Server * srv,
    uint16_t ns,
    uint32_t num_id,
    const SYN_OPCUA_Variant * val
) 

Parameters:

  • srv Server instance.
  • ns Namespace index.
  • num_id Numeric identifier.
  • val New variant value.

Returns:

SYN_OK on success, SYN_ERROR if not found.


Macro Definition Documentation

define SYN_OPCUA_ATTR_ACCESS_LEVEL

#define SYN_OPCUA_ATTR_ACCESS_LEVEL `17U`

AccessLevel attribute


define SYN_OPCUA_ATTR_BROWSE_NAME

#define SYN_OPCUA_ATTR_BROWSE_NAME `3U`

BrowseName attribute


define SYN_OPCUA_ATTR_DATA_TYPE

#define SYN_OPCUA_ATTR_DATA_TYPE `14U`

DataType attribute


define SYN_OPCUA_ATTR_DISPLAY_NAME

#define SYN_OPCUA_ATTR_DISPLAY_NAME `4U`

DisplayName attribute


define SYN_OPCUA_ATTR_NODE_CLASS

#define SYN_OPCUA_ATTR_NODE_CLASS `2U`

NodeClass attribute


define SYN_OPCUA_ATTR_NODE_ID

#define SYN_OPCUA_ATTR_NODE_ID `1U`

NodeId attribute


define SYN_OPCUA_ATTR_VALUE

#define SYN_OPCUA_ATTR_VALUE `13U`

Value attribute


define SYN_OPCUA_ATTR_VALUE_RANK

#define SYN_OPCUA_ATTR_VALUE_RANK `15U`

ValueRank attribute


define SYN_OPCUA_DEFAULT_BUFFER_SIZE

#define SYN_OPCUA_DEFAULT_BUFFER_SIZE `1024U`

Default Chunk Buffer Size


define SYN_OPCUA_DEFAULT_PORT

#define SYN_OPCUA_DEFAULT_PORT `4840U`

Standard OPC UA TCP Port


define SYN_OPCUA_MAX_NODES

#define SYN_OPCUA_MAX_NODES `32U`

Static Node Table Capacity


define SYN_OPCUA_MAX_REFERENCES

#define SYN_OPCUA_MAX_REFERENCES `8U`

Max References per Node


define SYN_OPCUA_MAX_STRING_LEN

#define SYN_OPCUA_MAX_STRING_LEN `64U`

Max Identifier & Name String Length


define SYN_OPCUA_NODEID_OBJECTS_FOLDER

#define SYN_OPCUA_NODEID_OBJECTS_FOLDER `85U`

ObjectsFolder NodeId


define SYN_OPCUA_NODEID_ROOT

#define SYN_OPCUA_NODEID_ROOT `84U`

RootFolder NodeId


define SYN_OPCUA_NODEID_SERVER

#define SYN_OPCUA_NODEID_SERVER `2253U`

Server Object NodeId


define SYN_OPCUA_NODEID_SERVER_SERVERSTATUS

#define SYN_OPCUA_NODEID_SERVER_SERVERSTATUS `2256U`

ServerStatus Variable NodeId


define SYN_OPCUA_NS_STANDARD

#define SYN_OPCUA_NS_STANDARD `0U`

OPC UA standard namespace index


define SYN_OPCUA_NS_VENDOR

#define SYN_OPCUA_NS_VENDOR `1U`

Vendor custom namespace index


define SYN_OPCUA_PROTOCOL_VERSION

#define SYN_OPCUA_PROTOCOL_VERSION `0U`

OPC UA Binary Protocol Version


define SYN_OPCUA_STATUS_BAD_ATTRIBUTE_ID_INVALID

#define SYN_OPCUA_STATUS_BAD_ATTRIBUTE_ID_INVALID `0x80350000U`

AttributeId is invalid


define SYN_OPCUA_STATUS_BAD_INTERNAL_ERROR

#define SYN_OPCUA_STATUS_BAD_INTERNAL_ERROR `0x80020000U`

Internal error occurred


define SYN_OPCUA_STATUS_BAD_NODE_ID_UNKNOWN

#define SYN_OPCUA_STATUS_BAD_NODE_ID_UNKNOWN `0x80340000U`

NodeId is unknown in address space \


define SYN_OPCUA_STATUS_BAD_NOT_READABLE

#define SYN_OPCUA_STATUS_BAD_NOT_READABLE `0x803A0000U`

Node attribute is not readable


define SYN_OPCUA_STATUS_BAD_NOT_WRITABLE

#define SYN_OPCUA_STATUS_BAD_NOT_WRITABLE `0x803B0000U`

Node attribute is not writable


define SYN_OPCUA_STATUS_BAD_SECURITY_CHECKS_FAILED

#define SYN_OPCUA_STATUS_BAD_SECURITY_CHECKS_FAILED `0x80130000U`

Security verification failed \


define SYN_OPCUA_STATUS_BAD_SERVICE_UNSUPPORTED

#define SYN_OPCUA_STATUS_BAD_SERVICE_UNSUPPORTED `0x80430000U`

Requested service is unsupported


define SYN_OPCUA_STATUS_BAD_UNEXPECTED

#define SYN_OPCUA_STATUS_BAD_UNEXPECTED `0x80010000U`

Unexpected error


define SYN_OPCUA_STATUS_GOOD

#define SYN_OPCUA_STATUS_GOOD `0x00000000U`

Operation succeeded


define SYN_OPCUA_STATUS_UNCERTAIN

#define SYN_OPCUA_STATUS_UNCERTAIN `0x40000000U`

Value is uncertain



The documentation for this class was generated from the following file src/syntropic/proto/syn_opcua.h