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");
119 io_example[i][j].node_handle,
120 &io_example[i][j].data,
121 &io_example[i][j].timestamp
150 if (io_example[i][j].node_handle == node_handle) {
151 printf(
"io[%d,%d] ch: %d, access: %d, var_type: %d, func_type: %d, name: %s, description: %s\n",
155 io_example[i][j].access,
156 io_example[i][j].var_type,
157 io_example[i][j].func_type,
158 io_example[i][j].
name,
159 io_example[i][j].description);
166 *node_timestamp = io_example[i][j].
timestamp;
183 if (io_example[i][j].node_handle == node_handle) {
184 printf(
"io[%d,%d] ch: %d, access: %d, var_type: %d, func_type: %d, name: %s, description: %s\n",
188 io_example[i][j].access,
189 io_example[i][j].var_type,
190 io_example[i][j].func_type,
191 io_example[i][j].
name,
192 io_example[i][j].description);
218 strcpy(folder.
node_name,
"ioThinx-4533");
232 sprintf(
object.node_name,
"Slot_%d", i);
234 strcpy(
object.description,
"number of slot");
253 memset(&io_example[i][j].data.value, 0,
sizeof(io_example[i][j].
data.
value));
266 uint8_t channel_count = 1;
269 uint8_t counter_triggers;
270 uint16_t pwm_freq = 5;
271 uint16_t pwm_duty = 50;
280 printf(
"ioThinx_DO_Config_SetModes() = %d\n", rc);
286 printf(
"ioThinx_DO_Config_SetPwmConfigures() = %d\n", rc);
296 printf(
"ioThinx_DI_Config_SetModes() = %d\n", rc);
301 printf(
"ioThinx_DI_Config_SetCntTriggers() = %d\n", rc);
310 printf(
"ioThinx_IO_Config_Reload() = %d\n", rc);
321 f=fopen(filename,
"rb");
327 data=(
char*)malloc(len+1);
331 printf(
"parse file %s complete, len=%d.\n",filename,len);
342 cJSON *json,*
item,*object, *slotItem, *chObj;
345 json=cJSON_Parse(text);
348 printf(
"Error before: [%s]\n",cJSON_GetErrorPtr());
351 slotItem=cJSON_GetObjectItem(json,
"slot");
362 chObj=cJSON_GetArrayItem(slotItem,i);
363 int chsize = cJSON_GetArraySize(chObj);
364 io_example[i] = (
NODE *)calloc(chsize,
sizeof(
NODE));
368 for(j=0;j<chsize;j++){
369 object=cJSON_GetArrayItem(chObj,j);
371 item=cJSON_GetObjectItem(
object,
"ch");
378 printf(
"cJSON_GetObjectItem: get ch failed\n");
381 item=cJSON_GetObjectItem(
object,
"access");
388 printf(
"cJSON_GetObjectItem: get access failed\n");
390 item=cJSON_GetObjectItem(
object,
"variant_type");
397 printf(
"cJSON_GetObjectItem: get variable_type failed\n");
399 item=cJSON_GetObjectItem(
object,
"func_type");
406 printf(
"cJSON_GetObjectItem: get func_type failed\n");
408 item=cJSON_GetObjectItem(
object,
"name");
412 if (i==0 && io_example[i][j].ch == -1)
415 sprintf(io_example[i][j].name,
"S%d_C%d_%s", i, io_example[i][j].ch, item->
valuestring);
417 item=cJSON_GetObjectItem(
object,
"description");
454 uint32_t di_values = 0;
455 uint32_t do_values = 0;
456 uint32_t relay_values = 0;
457 uint32_t pwm_starts = 0;
458 uint32_t counter_starts = 0;
459 uint32_t value_uint = 0;
460 uint32_t ai_raws = 0;
461 float value_float = 0;
462 uint8_t value_uint8 = 0;
464 switch(io_example[slot][index].func_type){
469 printf(
"ioThinx_DI_Config_GetModes() = %d\n", rc);
478 printf(
"ioThinx_DI_GetValues() = %d\n", rc);
481 value_int = (di_values >> io_example[slot][
index].
ch)& 0x1;
489 printf(
"\r\n ioThinx_DI_GetCntStarts() = %d\r\n", rc);
492 value_int = (counter_starts >> io_example[slot][
index].
ch)& 0x1;
499 printf(
"ioThinx_DI_GetCntValues() = %d\n", rc);
508 printf(
"ioThinx_DO_Config_GetModes() = %d\n", rc);
516 printf(
"\r\n*** [ERR] ioThinx_DO_GetValues() = %d\r\n", rc);
519 value_int = (do_values >> io_example[slot][
index].
ch)& 0x1;
527 printf(
"\r\n ioThinx_DO_GetPwmStarts() = %d\r\n", rc);
530 value_int = (pwm_starts >> io_example[slot][
index].
ch)& 0x1;
537 printf(
"ioThinx_DO_Config_GetPwmCounts() = %d\n", rc);
546 printf(
"ioThinx_Relay_GetValues() = %d\n", rc);
549 value_int = (relay_values >> io_example[slot][
index].
ch)& 0x1;
557 printf(
"ioThinx_AI_GetEngs() = %d\n", rc);
567 printf(
"ioThinx_AI_GetEngs() = %d\n", rc);
577 printf(
"ioThinx_AI_GetEngs() = %d\n", rc);
587 printf(
"ioThinx_AI_GetEngs() = %d\n", rc);
597 printf(
"ioThinx_AI_GetEngs() = %d\n", rc);
607 printf(
"ioThinx_AI_GetEngs() = %d\n", rc);
614 printf(
"IO function not found!\r\n");
617 *node_value = io_example[slot][
index].
data;
625 int32_t value_int = 0;
626 uint32_t do_values = 0;
627 uint32_t pwm_starts = 0;
628 uint32_t counter_starts = 0;
629 uint32_t value_uint = 0;
630 uint32_t relay_values = 0;
633 switch(io_example[slot][index].func_type){
641 if (value_int != 0 && value_int != 1) {
647 printf(
"\r\n ioThinx_DI_GetCntStarts() = %d\r\n", rc);
650 if (value_int == 1) {
651 counter_starts |= 0x1 << (io_example[slot][
index].
ch);
655 printf(
"ioThinx_DI_SetCntStarts() = %d\n", rc);
659 else if (value_int == 0) {
660 counter_starts |= 0x1 << (io_example[slot][
index].
ch);
664 printf(
"ioThinx_DI_SetCntStops() = %d\n", rc);
682 printf(
"ioThinx_DI_SetCntValues() = %d\n", rc);
693 if (value_int != 0 && value_int != 1) {
700 printf(
"\r\nioThinx_DO_GetValues() = %d\r\n", rc);
703 do_values = do_values & ~(0x1 << io_example[slot][
index].
ch) | (value_int << io_example[slot][index].ch);
708 printf(
"ioThinx_DO_SetValues() = %d\n", rc);
720 if (value_int != 0 && value_int != 1) {
726 printf(
"\r\n ioThinx_DO_GetPwmStarts() = %d\r\n", rc);
729 if (value_int == 1) {
731 pwm_starts |= 0x1 << (io_example[slot][
index].
ch);
735 printf(
"ioThinx_DO_SetPwmStarts() = %d\n", rc);
739 else if (value_int == 0) {
741 pwm_starts |= 0x1 << (io_example[slot][
index].
ch);
745 printf(
"ioThinx_DO_SetPwmStops() = %d\n", rc);
763 printf(
"ioThinx_DO_Config_SetPwmCounts() = %d\n", rc);
774 if (value_int != 0 && value_int != 1) {
780 printf(
"\r\nioThinx_DO_GetValues() = %d\r\n", rc);
783 relay_values = relay_values & ~(0x1 << io_example[slot][
index].
ch) | (value_int << io_example[slot][index].ch);
788 printf(
"ioThinx_DO_SetValues() = %d\n", rc);
794 printf(
"function not found!\r\n");
796 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