- Main
- Tutorials
- Library
- Samples

- File List
- Globals

Data Structures | Macros | Typedefs | Enumerations | Functions | Variables
demo_node_operator.c File Reference

Demo node operator More...

`#include <unistd.h>`
`#include <string.h>`
`#include <mx_node_sdk/mx_node_interface_basic.h>`
`#include <mx_node_sdk/mx_node_interface_data_access.h>`

Go to the source code of this file.

## Data Structures
struct | _MY_DATA

## Macros
#define | NUM_DATA 12
| include interfaces More...

## Typedefs
typedef struct _MY_DATA | MY_DATA

## Enumerations
enum | OPERATOR_STATE { OPERATOR_STATE_STOP, OPERATOR_STATE_STOPPING, OPERATOR_STATE_RUNNING, OPERATOR_STATE_STOP, OPERATOR_STATE_STOPPING, OPERATOR_STATE_RUNNING }
| custom define More...

## Functions
struct timeval | now ()
MX_NODE_RESULT | add_my_nodes ()
void | rotate (char *str)

## Variables
MX_NODE_NODE_OPERATOR_HANDLE | g_operator_handle
volatile OPERATOR_STATE | g_state
MY_DATA | g_my_data [NUM_DATA]

## Detailed Description

Demo node operator

Copyright
  2019 Moxa Inc. All rights reserved.

Date
  2019-06-05

Author
  Rich Liao

Version
  V1.0

    Introduction:
    This is demo node operator code.

Definition in file demo_node_operator.c.

## Macro Definition Documentation

#define NUM_DATA 12

include interfaces

Definition at line 32 of file demo_node_operator.c.

## Typedef Documentation

typedef struct _MY_DATA MY_DATA

## Enumeration Type Documentation

enum OPERATOR_STATE

custom define

Enumerator
OPERATOR_STATE_STOP |
OPERATOR_STATE_STOPPING |
OPERATOR_STATE_RUNNING |
OPERATOR_STATE_STOP |
OPERATOR_STATE_STOPPING |
OPERATOR_STATE_RUNNING |

Definition at line 35 of file demo_node_operator.c.

36 {
37 OPERATOR_STATE_STOP,
38 OPERATOR_STATE_STOPPING,
39 OPERATOR_STATE_RUNNING,
40 } OPERATOR_STATE;
OPERATOR_STATE_STOPPING
Definition: demo_node_operator.c:38
OPERATOR_STATE_RUNNING
Definition: demo_node_operator.c:39
OPERATOR_STATE_STOP
Definition: demo_node_operator.c:37
OPERATOR_STATE
OPERATOR_STATE
custom define
Definition: demo_node_operator.c:35

## Function Documentation

struct timeval now | ( |  | ) |

Definition at line 303 of file demo_node_operator.c.

304 {
305 struct timeval t;
306 gettimeofday(&t, NULL);
307 return t;
308 }

MX_NODE_RESULT add_my_nodes | ( |  | ) |

Definition at line 195 of file demo_node_operator.c.

196 {
197 // DemoFolder
198 // |--DemoObject
199 // |--DemoBoolean
200 // |--DemoTimeZone (property, value: 480)
201 // |--DemoInt8
202 // |--DemoTimeZone (property, value: 480)
203 // |--DemoInt16
204 // |--DemoTimeZone (property, value: 480)
205 // |--DemoInt32
206 // |--DemoTimeZone (property, value: 480)
207 // |--DemoInt64
208 // |--DemoTimeZone (property, value: 480)
209 // |--DemoUInt8
210 // |--DemoTimeZone (property, value: 480)
211 // |--DemoUInt16
212 // |--DemoTimeZone (property, value: 480)
213 // |--DemoUInt32
214 // |--DemoTimeZone (property, value: 480)
215 // |--DemoUInt64
216 // |--DemoTimeZone (property, value: 480)
217 // |--DemoFloat
218 // |--DemoTimeZone (property, value: 480)
219 // |--DemoDouble
220 // |--DemoTimeZone (property, value: 480)
221 // |--DemoString
222 // |--DemoTimeZone (property, value: 480)
223
224 MX_NODE_RESULT res;
225
226 // folder
227 MX_NODE_NODE folder;
228 {
229 strcpy(folder.node_name, "DemoFolder");
230 folder.node_type = MX_NODE_NODE_TYPE_FOLDER;
231 strcpy(folder.description, "DemoFolder's Description");
232 }
233 MX_NODE_NODE_HANDLE folder_handle;
234 res = mx_node_add_node(g_operator_handle, &folder, &folder_handle);
235 if (res != MX_NODE_RESULT_GOOD)
236 return res;
237
238 // object
239 MX_NODE_NODE object;
240 {
241 strcpy(object.node_name, "DemoObject");
242 object.node_type = MX_NODE_NODE_TYPE_OBJECT;
243 strcpy(object.description, "DemoObject's Description");
244 }
245 MX_NODE_NODE_HANDLE object_handle;
246 res = mx_node_add_node(g_operator_handle, &object, &object_handle);
247 if (res != MX_NODE_RESULT_GOOD)
248 return res;
249 res = mx_node_set_parent_node(object_handle, folder_handle);
250 if (res != MX_NODE_RESULT_GOOD)
251 return res;
252
253 // variable
254 char* node_name[NUM_DATA] = {
255 "DemoBoolean", "DemoInt8", "DemoInt16", "DemoInt32",
256 "DemoInt64", "DemoUInt8", "DemoUInt16", "DemoUInt32",
257 "DemoUInt64", "DemoFloat", "DemoDouble", "DemoString"
258 };
259
260 for (int i = 0; i < NUM_DATA; ++i)
261 {
262 MX_NODE_NODE variable;
263 {
264 strcpy(variable.node_name, node_name[i]);
265 variable.node_type = MX_NODE_NODE_TYPE_VARIABLE;
266 strcpy(variable.description, node_name[i]);
267 strcat(variable.description, "'s Description");
268 variable.variable.access_right = MX_NODE_ACCESS_RIGHT_READWRITE;
269 variable.variable.value = g_my_data[i].data;
270 }
271 res = mx_node_add_node(g_operator_handle, &variable, &g_my_data[i].node_handle);
272 if (res != MX_NODE_RESULT_GOOD)
273 return res;
274 res = mx_node_set_parent_node(g_my_data[i].node_handle, object_handle);
275 if (res != MX_NODE_RESULT_GOOD)
276 return res;
277 }
278
279 // property
280 MX_NODE_NODE property;
281 {
282 strcpy(property.node_name, "DemoTimeZone");
283 property.node_type = MX_NODE_NODE_TYPE_PROPERTY;
284 strcpy(property.description, "DemoTimeZone's Description");
285 property.property.access_right = MX_NODE_ACCESS_RIGHT_READONLY;
286 property.property.value.type = MX_NODE_VALUE_TYPE_INT32;
287 property.property.value.value.i32 = 480;
288 }
289 for (int i = 0; i < NUM_DATA; ++i)
290 {
291 MX_NODE_NODE_HANDLE property_handle;
292 res = mx_node_add_node(g_operator_handle, &property, &property_handle);
293 if (res != MX_NODE_RESULT_GOOD)
294 return res;
295 res = mx_node_set_parent_node(property_handle, g_my_data[i].node_handle);
296 if (res != MX_NODE_RESULT_GOOD)
297 return res;
298 }
299
300 return MX_NODE_RESULT_GOOD;
301 }
_MX_NODE_VARIABLE::value
MX_NODE_VARIANT value
Definition: mx_node_node_def.h:123
mx_node_add_node
MX_NODE_RESULT mx_node_add_node(MX_NODE_NODE_OPERATOR_HANDLE operator_handle, MX_NODE_NODE *node, MX_NODE_NODE_HANDLE *node_handle)
Add a node to OPC UA server.
MX_NODE_NODE_HANDLE
size_t MX_NODE_NODE_HANDLE
Handle of a node.
Definition: mx_node_node.h:42
MX_NODE_ACCESS_RIGHT_READWRITE
Definition: mx_node_node_def.h:90
MX_NODE_NODE_TYPE_VARIABLE
Definition: mx_node_node_def.h:44
_MX_NODE_NODE::variable
MX_NODE_VARIABLE variable
Definition: mx_node_node_def.h:148
MX_NODE_RESULT
enum _MX_NODE_RESULT MX_NODE_RESULT
A result enumeration represents success or not.
NUM_DATA
#define NUM_DATA
include interfaces
Definition: demo_node_operator.c:32
MX_NODE_ACCESS_RIGHT_READONLY
Definition: mx_node_node_def.h:88
_MY_DATA::data
MX_NODE_VARIANT data
Definition: demo_node_operator.c:45
_MX_NODE_NODE
A node&#39;s sturcture contain name, description, node type and attribute.
Definition: mx_node_node_def.h:139
g_my_data
MY_DATA g_my_data[NUM_DATA]
Definition: demo_node_operator.c:55
mx_node_set_parent_node
MX_NODE_RESULT mx_node_set_parent_node(MX_NODE_NODE_HANDLE node_handle, MX_NODE_NODE_HANDLE parent_node_handle)
Set a node&#39;s parent.
MX_NODE_NODE_TYPE_PROPERTY
Definition: mx_node_node_def.h:45
_MX_NODE_VARIABLE::access_right
MX_NODE_ACCESS_RIGHT access_right
Definition: mx_node_node_def.h:124
MX_NODE_RESULT_GOOD
Definition: mx_node_node_def.h:158
MX_NODE_NODE_TYPE_OBJECT
Definition: mx_node_node_def.h:43
MX_NODE_VALUE_TYPE_INT32
Definition: mx_node_node_def.h:71
_MX_NODE_NODE::node_name
char node_name[MAX_NODE_NAME_LEN]
Definition: mx_node_node_def.h:141
_MX_NODE_NODE::description
char description[MAX_NODE_DESC_LEN]
Definition: mx_node_node_def.h:142
MX_NODE_NODE_TYPE_FOLDER
Definition: mx_node_node_def.h:42
_MX_NODE_NODE::node_type
MX_NODE_NODE_TYPE node_type
Definition: mx_node_node_def.h:143
g_operator_handle
MX_NODE_NODE_OPERATOR_HANDLE g_operator_handle
Definition: demo_node_operator.c:53

void rotate | ( | char * | str | ) |

Definition at line 310 of file demo_node_operator.c.

311 {
312 if (str[0] != '\0')
313 {
314 char tmp = str[0];
315 int i = 0;
316 while (str[i + 1] != '\0')
317 {
318 str[i] = str[i + 1];
319 ++i;
320 }
321 str[i] = tmp;
322 }
323 }

## Variable Documentation

MX_NODE_NODE_OPERATOR_HANDLE g_operator_handle

Definition at line 53 of file demo_node_operator.c.

volatile OPERATOR_STATE g_state

Definition at line 54 of file demo_node_operator.c.

MY_DATA g_my_data[NUM_DATA]

Definition at line 55 of file demo_node_operator.c.