29 #include <iothinx/iothinxio.h> 32 #include <mx_node_sdk/mx_node_interface_basic.h> 33 #include <mx_node_sdk/mx_node_interface_data_access.h> 79 printf(
"ioThinx_IO_Client_Init() = %d\n", rc);
84 rc =
parse_json_file(
"/usr/local/bin/embeddedopcuaserver/Config/io.conf");
86 printf(
"Load configure error, can not open config file.");
101 printf(
"Uninit finished!...\n");
115 io_example[i][j].node_handle,
116 &io_example[i][j].data,
117 &io_example[i][j].timestamp
146 if (io_example[i][j].node_handle == node_handle) {
147 printf(
"io[%d,%d] ch: %d, access: %d, var_type: %d, func_type: %d, name: %s, description: %s\n",
151 io_example[i][j].access,
152 io_example[i][j].var_type,
153 io_example[i][j].func_type,
154 io_example[i][j].
name,
155 io_example[i][j].description);
162 *node_timestamp = io_example[i][j].
timestamp;
179 if (io_example[i][j].node_handle == node_handle) {
180 printf(
"io[%d,%d] ch: %d, access: %d, var_type: %d, func_type: %d, name: %s, description: %s\n",
184 io_example[i][j].access,
185 io_example[i][j].var_type,
186 io_example[i][j].func_type,
187 io_example[i][j].
name,
188 io_example[i][j].description);
214 strcpy(folder.
node_name,
"ioThinx-4533");
228 sprintf(
object.node_name,
"Slot_%d", i);
230 strcpy(
object.description,
"number of slot");
249 memset(&io_example[i][j].data.value, 0,
sizeof(io_example[i][j].
data.
value));
262 uint8_t channel_count = 1;
265 uint8_t counter_triggers;
266 uint16_t pwm_freq = 5;
267 uint16_t pwm_duty = 50;
276 printf(
"ioThinx_DO_Config_SetModes() = %d\n", rc);
282 printf(
"ioThinx_DO_Config_SetPwmConfigures() = %d\n", rc);
292 printf(
"ioThinx_DI_Config_SetModes() = %d\n", rc);
297 printf(
"ioThinx_DI_Config_SetCntTriggers() = %d\n", rc);
306 printf(
"ioThinx_IO_Config_Reload() = %d\n", rc);
317 f=fopen(filename,
"rb");
323 data=(
char*)malloc(len+1);
327 printf(
"parse file %s complete, len=%d.\n",filename,len);
338 cJSON *json,*
item,*object, *slotItem, *chObj;
341 json=cJSON_Parse(text);
344 printf(
"Error before: [%s]\n",cJSON_GetErrorPtr());
347 slotItem=cJSON_GetObjectItem(json,
"slot");
358 chObj=cJSON_GetArrayItem(slotItem,i);
359 int chsize = cJSON_GetArraySize(chObj);
360 io_example[i] = (
NODE *)calloc(chsize,
sizeof(
NODE));
364 for(j=0;j<chsize;j++){
365 object=cJSON_GetArrayItem(chObj,j);
367 item=cJSON_GetObjectItem(
object,
"ch");
374 printf(
"cJSON_GetObjectItem: get ch failed\n");
377 item=cJSON_GetObjectItem(
object,
"access");
384 printf(
"cJSON_GetObjectItem: get access failed\n");
386 item=cJSON_GetObjectItem(
object,
"variant_type");
393 printf(
"cJSON_GetObjectItem: get variable_type failed\n");
395 item=cJSON_GetObjectItem(
object,
"func_type");
402 printf(
"cJSON_GetObjectItem: get func_type failed\n");
404 item=cJSON_GetObjectItem(
object,
"name");
408 if (i==0 && io_example[i][j].ch == -1)
411 sprintf(io_example[i][j].name,
"S%d_C%d_%s", i, io_example[i][j].ch, item->
valuestring);
413 item=cJSON_GetObjectItem(
object,
"description");
450 uint32_t di_values = 0;
451 uint32_t do_values = 0;
452 uint32_t relay_values = 0;
453 uint32_t pwm_starts = 0;
454 uint32_t counter_starts = 0;
455 uint32_t value_uint = 0;
456 uint32_t ai_raws = 0;
457 float value_float = 0;
458 uint8_t value_uint8 = 0;
460 switch(io_example[slot][index].func_type){
465 printf(
"ioThinx_DI_Config_GetModes() = %d\n", rc);
474 printf(
"ioThinx_DI_GetValues() = %d\n", rc);
477 value_int = (di_values >> io_example[slot][
index].
ch)& 0x1;
485 printf(
"\r\n ioThinx_DI_GetCntStarts() = %d\r\n", rc);
488 value_int = (counter_starts >> io_example[slot][
index].
ch)& 0x1;
495 printf(
"ioThinx_DI_GetCntValues() = %d\n", rc);
504 printf(
"ioThinx_DO_Config_GetModes() = %d\n", rc);
512 printf(
"\r\n*** [ERR] ioThinx_DO_GetValues() = %d\r\n", rc);
515 value_int = (do_values >> io_example[slot][
index].
ch)& 0x1;
523 printf(
"\r\n ioThinx_DO_GetPwmStarts() = %d\r\n", rc);
526 value_int = (pwm_starts >> io_example[slot][
index].
ch)& 0x1;
533 printf(
"ioThinx_DO_Config_GetPwmCounts() = %d\n", rc);
542 printf(
"ioThinx_Relay_GetValues() = %d\n", rc);
545 value_int = (relay_values >> io_example[slot][
index].
ch)& 0x1;
553 printf(
"ioThinx_AI_GetEngs() = %d\n", rc);
563 printf(
"ioThinx_AI_GetEngs() = %d\n", rc);
573 printf(
"ioThinx_AI_GetEngs() = %d\n", rc);
583 printf(
"ioThinx_AI_GetEngs() = %d\n", rc);
593 printf(
"ioThinx_AI_GetEngs() = %d\n", rc);
603 printf(
"ioThinx_AI_GetEngs() = %d\n", rc);
610 printf(
"IO function not found!\r\n");
613 *node_value = io_example[slot][
index].
data;
621 int32_t value_int = 0;
622 uint32_t do_values = 0;
623 uint32_t pwm_starts = 0;
624 uint32_t counter_starts = 0;
625 uint32_t value_uint = 0;
626 uint32_t relay_values = 0;
629 switch(io_example[slot][index].func_type){
637 if (value_int != 0 && value_int != 1) {
643 printf(
"\r\n ioThinx_DI_GetCntStarts() = %d\r\n", rc);
646 if (value_int == 1) {
647 counter_starts |= 0x1 << (io_example[slot][
index].
ch);
651 printf(
"ioThinx_DI_SetCntStarts() = %d\n", rc);
655 else if (value_int == 0) {
656 counter_starts |= 0x1 << (io_example[slot][
index].
ch);
660 printf(
"ioThinx_DI_SetCntStops() = %d\n", rc);
678 printf(
"ioThinx_DI_SetCntValues() = %d\n", rc);
689 if (value_int != 0 && value_int != 1) {
696 printf(
"\r\nioThinx_DO_GetValues() = %d\r\n", rc);
699 do_values = do_values & ~(0x1 << io_example[slot][
index].
ch) | (value_int << io_example[slot][index].ch);
704 printf(
"ioThinx_DO_SetValues() = %d\n", rc);
716 if (value_int != 0 && value_int != 1) {
722 printf(
"\r\n ioThinx_DO_GetPwmStarts() = %d\r\n", rc);
725 if (value_int == 1) {
727 pwm_starts |= 0x1 << (io_example[slot][
index].
ch);
731 printf(
"ioThinx_DO_SetPwmStarts() = %d\n", rc);
735 else if (value_int == 0) {
737 pwm_starts |= 0x1 << (io_example[slot][
index].
ch);
741 printf(
"ioThinx_DO_SetPwmStops() = %d\n", rc);
759 printf(
"ioThinx_DO_Config_SetPwmCounts() = %d\n", rc);
770 if (value_int != 0 && value_int != 1) {
776 printf(
"\r\nioThinx_DO_GetValues() = %d\r\n", rc);
779 relay_values = relay_values & ~(0x1 << io_example[slot][
index].
ch) | (value_int << io_example[slot][index].ch);
784 printf(
"ioThinx_DO_SetValues() = %d\n", rc);
790 printf(
"function not found!\r\n");
792 io_example[slot][
index].
data = *node_value;
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.
IOTHINX_ERR ioThinx_DO_SetPwmCounts(uint32_t slot, uint8_t start, uint8_t count, uint32_t buf[])
MX_NODE_RESULT mx_node_operator_write_node(MX_NODE_NODE_HANDLE node_handle, const MX_NODE_VARIANT *node_value)
Write data by handle index.
A variant structure is used to store different type's data.
void mx_node_operator_start()
A notify to inform node operator start with non-blocking.
IOTHINX_ERR ioThinx_DI_SetCntStops(uint32_t slot, uint32_t stops)
IOTHINX_ERR ioThinx_AI_GetMinRaws(uint32_t slot, uint8_t start, uint8_t count, uint32_t buf[])
IOTHINX_ERR ioThinx_DI_GetCntStarts(uint32_t slot, uint32_t *p_starts)
size_t MX_NODE_NODE_HANDLE
Handle of a node.
#define INTERFACE_MX_NODE_BASIC
Interface basic's flag.
int * g_slotNodeCountRecorder
#define MX_PARSE_CONFIG_ERR
MX_NODE_VARIABLE variable
enum _MX_NODE_RESULT MX_NODE_RESULT
A result enumeration represents success or not.
volatile OPERATOR_STATE g_state
IOTHINX_ERR ioThinx_DI_SetCntStarts(uint32_t slot, uint32_t starts)
IOTHINX_ERR ioThinx_DO_SetPwmStops(uint32_t slot, uint32_t stops)
IOTHINX_ERR ioThinx_DO_GetPwmCounts(uint32_t slot, uint8_t start, uint8_t count, uint32_t buf[])
IOTHINX_ERR ioThinx_Relay_GetValues(uint32_t slot, uint32_t *p_values)
IOTHINX_ERR ioThinx_DO_SetValues(uint32_t slot, uint32_t values)
void mx_node_operator_stop()
A notify to inform node operator stopping.
A node's sturcture contain name, description, node type and attribute.
IOTHINX_ERR ioThinx_DI_Config_SetModes(uint32_t slot, uint8_t start, uint8_t count, uint8_t buf[])
MX_NODE_RESULT mx_node_set_parent_node(MX_NODE_NODE_HANDLE node_handle, MX_NODE_NODE_HANDLE parent_node_handle)
Set a node's parent.
IOTHINX_ERR ioThinx_DO_GetPwmStarts(uint32_t slot, uint32_t *p_starts)
#define INTERFACE_MX_NODE_DATA_ACCESS
Interface data access's flag.
IOTHINX_ERR ioThinx_DI_GetCntValues(uint32_t slot, uint8_t start, uint8_t count, uint32_t buf[])
const char * mx_node_operator_get_version()
Get node operator's version.
MX_NODE_RESULT mx_node_operator_read_node(MX_NODE_NODE_HANDLE node_handle, MX_NODE_VARIANT *node_value, struct timeval *node_timestamp)
Read a node's data and timestamp.
long long mx_node_operator_get_supported_interfaces()
Get supported interfaces.
IOTHINX_ERR ioThinx_AI_GetMaxRaws(uint32_t slot, uint8_t start, uint8_t count, uint32_t buf[])
int io_control_write(int slot, int index, const MX_NODE_VARIANT *node_value)
MX_NODE_ACCESS_RIGHT access_right
IOTHINX_ERR ioThinx_Relay_SetValues(uint32_t slot, uint32_t values)
IOTHINX_ERR ioThinx_DO_Config_SetModes(uint32_t slot, uint8_t start, uint8_t count, uint8_t buf[])
IOTHINX_ERR ioThinx_AI_GetRaws(uint32_t slot, uint8_t start, uint8_t count, uint32_t buf[])
int parse_json_file(const char *filename)
int cJSON_to_struct_array(char *text)
IOTHINX_ERR ioThinx_DI_Config_GetModes(uint32_t slot, uint8_t start, uint8_t count, uint8_t buf[])
#define MX_IO_CONTROL_ERR
MX_NODE_RESULT add_io_nodes()
struct timeval now()
custom function
IOTHINX_ERR ioThinx_AI_GetEngs(uint32_t slot, uint8_t start, uint8_t count, float buf[])
IOTHINX_ERR ioThinx_AI_Config_GetRanges(uint32_t slot, uint8_t start, uint8_t count, uint8_t buf[])
IOTHINX_ERR ioThinx_IO_Config_Reload(void)
IOTHINX_ERR ioThinx_DI_Config_SetCntTriggers(uint32_t slot, uint8_t start, uint8_t count, uint8_t buf[])
int io_control_read(int slot, int index, MX_NODE_VARIANT *node_value)
char node_name[MAX_NODE_NAME_LEN]
IOTHINX_ERR ioThinx_DO_Config_SetPwmConfigures(uint32_t slot, uint8_t start, uint8_t count, uint16_t frequencies[], uint16_t duty_cycles[])
MX_NODE_NODE_OPERATOR_HANDLE g_operator_handle
IOTHINX_ERR ioThinx_DI_SetCntValues(uint32_t slot, uint8_t start, uint8_t count, uint32_t buf[])
IOTHINX_ERR ioThinx_DI_GetValues(uint32_t slot, uint32_t *p_values)
OPERATOR_STATE
include interfaces
char description[MAX_NODE_DESC_LEN]
void mx_node_operator_uninitialize()
Do node operator's uninitialize.
IOTHINX_ERR ioThinx_DO_Config_GetModes(uint32_t slot, uint8_t start, uint8_t count, uint8_t buf[])
union _MX_NODE_VARIANT::@0 value
IOTHINX_ERR ioThinx_IO_Client_Init(void)
IOTHINX_ERR ioThinx_DO_GetValues(uint32_t slot, uint32_t *p_values)
IOTHINX_ERR ioThinx_DO_SetPwmStarts(uint32_t slot, uint32_t starts)
IOTHINX_ERR ioThinx_AI_GetStatuss(uint32_t slot, uint8_t start, uint8_t count, uint8_t buf[])
MX_NODE_NODE_TYPE node_type
MX_NODE_RESULT mx_node_operator_initialize(MX_NODE_NODE_OPERATOR_HANDLE operator_handle)
Do node operator's initialize, like create nodes.
MX_NODE_RESULT mx_node_update_node(MX_NODE_NODE_HANDLE node_handle, MX_NODE_VARIANT *value, struct timeval *timestamp)
Update a node's data and timestamp.
size_t MX_NODE_NODE_OPERATOR_HANDLE
Handle of a node operator.
OPERATOR_STATE
custom define