- Main
- Tutorials
- Library
- Samples

- File List
- Globals

Data Structures | Macros | Typedefs | Enumerations | Functions
DataSet.h File Reference
`#include <sys/time.h>`
`#include <stdio.h>`
`#include <mx_node_sdk/mx_node_interface_basic.h>`
`#include <mx_node_sdk/mx_node_interface_data_access.h>`
`#include "cJSON.h"`

Go to the source code of this file.

## Data Structures
struct | _io_node

## Macros
#define | MX_PARSE_CONFIG_ERR -1
#define | MX_IO_CONTROL_OK 0
#define | MX_IO_CONTROL_ERR -1

## Typedefs
typedef struct _io_node | NODE

## Enumerations
enum | FUNC_TYPE { OPC_DI_MODE = 10, OPC_DI_STATUS, OPC_DI_COUNTERSTATUS, OPC_DI_COUNTERVALUE, OPC_DO_MODE = 20, OPC_DO_STATUS, OPC_DO_PULSESTATUS, OPC_DO_PULSECOUNT, OPC_AI_MODE = 30, OPC_AI_STATUS, OPC_AI_RAWVALUE, OPC_AI_MINIMUMRAWVALUE, OPC_AI_MAXIMUMRAWVALUE, OPC_AI_SCALEDVALUE, OPC_RELAY_VALUE = 40 }

## Functions
int | parse_json_file (const char *filename)
int | cJSON_to_struct_array (char *text)
int | io_control_read (int slot, int index, MX_NODE_VARIANT *node_value)
int | io_control_write (int slot, int index, const MX_NODE_VARIANT *node_value)
struct timeval | Now ()

## Macro Definition Documentation

#define MX_PARSE_CONFIG_ERR -1

Definition at line 10 of file DataSet.h.

#define MX_IO_CONTROL_OK 0

Definition at line 11 of file DataSet.h.

#define MX_IO_CONTROL_ERR -1

Definition at line 12 of file DataSet.h.

## Typedef Documentation

typedef struct _io_node NODE

## Enumeration Type Documentation

enum FUNC_TYPE

Enumerator
OPC_DI_MODE |
OPC_DI_STATUS |
OPC_DI_COUNTERSTATUS |
OPC_DI_COUNTERVALUE |
OPC_DO_MODE |
OPC_DO_STATUS |
OPC_DO_PULSESTATUS |
OPC_DO_PULSECOUNT |
OPC_AI_MODE |
OPC_AI_STATUS |
OPC_AI_RAWVALUE |
OPC_AI_MINIMUMRAWVALUE |
OPC_AI_MAXIMUMRAWVALUE |
OPC_AI_SCALEDVALUE |
OPC_RELAY_VALUE |

Definition at line 27 of file DataSet.h.

27 {
28 OPC_DI_MODE = 10,
29 OPC_DI_STATUS,
30 OPC_DI_COUNTERSTATUS,
31 OPC_DI_COUNTERVALUE,
32 OPC_DO_MODE = 20,
33 OPC_DO_STATUS,
34 OPC_DO_PULSESTATUS,
35 OPC_DO_PULSECOUNT,
36 OPC_AI_MODE = 30,
37 OPC_AI_STATUS,
38 OPC_AI_RAWVALUE,
39 OPC_AI_MINIMUMRAWVALUE,
40 OPC_AI_MAXIMUMRAWVALUE,
41 OPC_AI_SCALEDVALUE,
42 OPC_RELAY_VALUE = 40
43 }FUNC_TYPE;
OPC_DI_COUNTERSTATUS
Definition: DataSet.h:30
OPC_AI_STATUS
Definition: DataSet.h:37
OPC_AI_MAXIMUMRAWVALUE
Definition: DataSet.h:40
OPC_RELAY_VALUE
Definition: DataSet.h:42
OPC_DO_PULSECOUNT
Definition: DataSet.h:35
OPC_AI_MODE
Definition: DataSet.h:36
OPC_DI_MODE
Definition: DataSet.h:28
FUNC_TYPE
FUNC_TYPE
Definition: DataSet.h:27
OPC_DO_STATUS
Definition: DataSet.h:33
OPC_AI_MINIMUMRAWVALUE
Definition: DataSet.h:39
OPC_DI_STATUS
Definition: DataSet.h:29
OPC_AI_SCALEDVALUE
Definition: DataSet.h:41
OPC_AI_RAWVALUE
Definition: DataSet.h:38
OPC_DO_MODE
Definition: DataSet.h:32
OPC_DI_COUNTERVALUE
Definition: DataSet.h:31
OPC_DO_PULSESTATUS
Definition: DataSet.h:34

## Function Documentation

int parse_json_file | ( | const char * | filename | ) |

Definition at line 311 of file io_node_operator.c.

312 {
313 FILE *f;
314 int len;
315 char *data;
316
317 f=fopen(filename,"rb");
318 if (f == NULL)
319 return MX_PARSE_CONFIG_ERR;
320 fseek(f,0,SEEK_END);
321 len=ftell(f);
322 fseek(f,0,SEEK_SET);
323 data=(char*)malloc(len+1);
324 fread(data,1,len,f);
325 fclose(f);
326
327 printf("parse file %s complete, len=%d.\n",filename,len);
328
329 cJSON_to_struct_array(data);
330
331 free(data);
332 return 0;
333 }
MX_PARSE_CONFIG_ERR
#define MX_PARSE_CONFIG_ERR
Definition: DataSet.h:10
cJSON_to_struct_array
int cJSON_to_struct_array(char *text)
Definition: io_node_operator.c:336

int cJSON_to_struct_array | ( | char * | text | ) |

Definition at line 336 of file io_node_operator.c.

337 {
338 cJSON *json,*item,*object, *slotItem, *chObj;
339 int i,j;
340
341 json=cJSON_Parse(text);
342 if (!json)
343 {
344 printf("Error before: [%s]\n",cJSON_GetErrorPtr());
345 }
346 else {
347 slotItem=cJSON_GetObjectItem(json,"slot");
348 if(slotItem!=NULL)
349 {
350 g_totalSlot =cJSON_GetArraySize(slotItem);
351 //printf("cJSON_GetSlotSize: g_totalSlot=%d\n",g_totalSlot);
352 io_example = (NODE **)malloc(sizeof(NODE *)*g_totalSlot);
353 g_slotNodeCountRecorder = (int*)malloc(sizeof(int)*g_totalSlot);
354
355 for(i=0;i<g_totalSlot;i++)
356 {
357 //printf("i=%d\n",i);
358 chObj=cJSON_GetArrayItem(slotItem,i);
359 int chsize = cJSON_GetArraySize(chObj);
360 io_example[i] = (NODE *)calloc(chsize, sizeof(NODE));
361 g_slotNodeCountRecorder[i] = chsize;
362 //printf("chsize=%d\n",chsize);
363
364 for(j=0;j<chsize;j++){
365 object=cJSON_GetArrayItem(chObj,j);
366
367 item=cJSON_GetObjectItem(object,"ch");
368 if(item!=NULL)
369 {
370 //printf("cJSON_GetObjectItem: type=%d, string is %s, valueint=%d\n",item->type,item->string,item->valueint);
371 io_example[i][j].ch=item->valueint;
372 }
373 else{
374 printf("cJSON_GetObjectItem: get ch failed\n");
375 }
376
377 item=cJSON_GetObjectItem(object,"access");
378 if(item!=NULL)
379 {
380 //printf("cJSON_GetObjectItem: type=%d, string is %s, valueint=%d\n",item->type,item->string,item->valueint);
381 io_example[i][j].access=item->valueint;
382 }
383 else{
384 printf("cJSON_GetObjectItem: get access failed\n");
385 }
386 item=cJSON_GetObjectItem(object,"variant_type");
387 if(item!=NULL)
388 {
389 //printf("cJSON_GetObjectItem: type=%d, string is %s, valueint=%d\n",item->type,item->string,item->valueint);
390 io_example[i][j].var_type=item->valueint;
391 }
392 else{
393 printf("cJSON_GetObjectItem: get variable_type failed\n");
394 }
395 item=cJSON_GetObjectItem(object,"func_type");
396 if(item!=NULL)
397 {
398 //printf("cJSON_GetObjectItem: type=%d, string is %s, valueint=%d\n",item->type,item->string,item->valueint);
399 io_example[i][j].func_type=item->valueint;
400 }
401 else{
402 printf("cJSON_GetObjectItem: get func_type failed\n");
403 }
404 item=cJSON_GetObjectItem(object,"name");
405 if(item!=NULL)
406 {
407 //printf("cJSON_GetObjectItem: type=%d, string is %s\n",item->type,item->string);
408 if (i==0 && io_example[i][j].ch == -1) // slot 0 name
409 sprintf(io_example[i][j].name, "S%d_%s", i, item->valuestring);
410 else
411 sprintf(io_example[i][j].name, "S%d_C%d_%s", i, io_example[i][j].ch, item->valuestring);
412 }
413 item=cJSON_GetObjectItem(object,"description");
414 if(item!=NULL)
415 {
416 //printf("cJSON_GetObjectItem: type=%d, string is %s\n",item->type,item->string);
417 memcpy(io_example[i][j].description,item->valuestring,strlen(item->valuestring));
418 }
419 }
420 }
421 }
422
423 //for(i=0;i<g_totalSlot;i++)
424 //{
425 // for(j=0;j<g_slotNodeCountRecorder[i];j++)
426 // {
427 // printf("io[%d,%d] ch: %d, access: %d, var_type: %d, func_type: %d, name: %s, description: %s\n",
428 // i,
429 // j,
430 // io_example[i][j].ch,
431 // io_example[i][j].access,
432 // io_example[i][j].var_type,
433 // io_example[i][j].func_type,
434 // io_example[i][j].name,
435 // io_example[i][j].description);
436 // }
437 // printf("\r\n");
438 //}
439
440 cJSON_Delete(json);
441 }
442 return 0;
443 }
_io_node
Definition: DataSet.h:14
g_slotNodeCountRecorder
int * g_slotNodeCountRecorder
Definition: io_node_operator.c:53
cJSON::valueint
int valueint
Definition: cJSON.h:117
_io_node::access
int access
Definition: DataSet.h:20
_io_node::ch
int ch
Definition: DataSet.h:16
name
const char *const name
Definition: cJSON.h:258
io_example
NODE ** io_example
Definition: io_node_operator.c:51
g_totalSlot
int g_totalSlot
Definition: io_node_operator.c:52
item
cJSON * item
Definition: cJSON.h:218
_io_node::func_type
int func_type
Definition: DataSet.h:19
_io_node::var_type
int var_type
Definition: DataSet.h:18
cJSON
Definition: cJSON.h:103
cJSON::valuestring
char * valuestring
Definition: cJSON.h:115

int io_control_read | ( | int | slot,
|  | int | index,
|  | MX_NODE_VARIANT * | node_value
| ) |  |

Definition at line 445 of file io_node_operator.c.

446 {
447 FUNC_TYPE fn;
448 int32_t rc = 0;
449 int32_t value_int;
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;
459
460 switch(io_example[slot][index].func_type){
461 case OPC_DI_MODE:
462 rc = ioThinx_DI_Config_GetModes(slot, io_example[slot][index].ch, 1, &value_uint8);
463 if (rc != IOTHINX_ERR_OK)
464 {
465 printf("ioThinx_DI_Config_GetModes() = %d\n", rc);
466 return MX_IO_CONTROL_ERR;
467 }
468 io_example[slot][index].data.value.u32 = (uint32_t)value_uint8;
469 break;
470 case OPC_DI_STATUS:
471 rc = ioThinx_DI_GetValues(slot, &di_values);
472 if (rc != IOTHINX_ERR_OK)
473 {
474 printf("ioThinx_DI_GetValues() = %d\n", rc);
475 return MX_IO_CONTROL_ERR;
476 }
477 value_int = (di_values >> io_example[slot][index].ch)& 0x1;
478 //printf("\r\n=========> MX_Read() set value = %d\r\n", value_int);
479 io_example[slot][index].data.value.i32 = value_int;
480 break;
481 case OPC_DI_COUNTERSTATUS:
482 rc = ioThinx_DI_GetCntStarts(slot, &counter_starts);
483 if (rc != IOTHINX_ERR_OK)
484 {
485 printf("\r\n ioThinx_DI_GetCntStarts() = %d\r\n", rc);
486 return MX_IO_CONTROL_ERR;
487 }
488 value_int = (counter_starts >> io_example[slot][index].ch)& 0x1;
489 io_example[slot][index].data.value.i32 = value_int;
490 break;
491 case OPC_DI_COUNTERVALUE:
492 rc = ioThinx_DI_GetCntValues(slot, io_example[slot][index].ch, 1, &value_uint);
493 if (rc != IOTHINX_ERR_OK)
494 {
495 printf("ioThinx_DI_GetCntValues() = %d\n", rc);
496 return MX_IO_CONTROL_ERR;
497 }
498 io_example[slot][index].data.value.u32 = value_uint;
499 break;
500 case OPC_DO_MODE:
501 rc = ioThinx_DO_Config_GetModes(slot, io_example[slot][index].ch, 1, &value_uint8);
502 if (rc != IOTHINX_ERR_OK)
503 {
504 printf("ioThinx_DO_Config_GetModes() = %d\n", rc);
505 }
506 io_example[slot][index].data.value.u32 = (uint32_t)value_uint8;
507 break;
508 case OPC_DO_STATUS:
509 rc = ioThinx_DO_GetValues(slot, &do_values);
510 if (rc != IOTHINX_ERR_OK)
511 {
512 printf("\r\n*** [ERR] ioThinx_DO_GetValues() = %d\r\n", rc);
513 return MX_IO_CONTROL_ERR;
514 }
515 value_int = (do_values >> io_example[slot][index].ch)& 0x1;
516 //printf("\r\n=========> MX_Read() set value = %d\r\n", value_int);
517 io_example[slot][index].data.value.i32 = value_int;
518 break;
519 case OPC_DO_PULSESTATUS:
520 rc = ioThinx_DO_GetPwmStarts(slot, &pwm_starts);
521 if (rc != IOTHINX_ERR_OK)
522 {
523 printf("\r\n ioThinx_DO_GetPwmStarts() = %d\r\n", rc);
524 return MX_IO_CONTROL_ERR;
525 }
526 value_int = (pwm_starts >> io_example[slot][index].ch)& 0x1;
527 io_example[slot][index].data.value.i32 = value_int;
528 break;
529 case OPC_DO_PULSECOUNT:
530 rc = ioThinx_DO_GetPwmCounts(slot, io_example[slot][index].ch, 1, &value_uint);
531 if (rc != IOTHINX_ERR_OK)
532 {
533 printf("ioThinx_DO_Config_GetPwmCounts() = %d\n", rc);
534 return MX_IO_CONTROL_ERR;
535 }
536 io_example[slot][index].data.value.u32 = value_uint;
537 break;
538 case OPC_RELAY_VALUE:
539 rc = ioThinx_Relay_GetValues(slot, &relay_values);
540 if (rc != IOTHINX_ERR_OK)
541 {
542 printf("ioThinx_Relay_GetValues() = %d\n", rc);
543 return MX_IO_CONTROL_ERR;
544 }
545 value_int = (relay_values >> io_example[slot][index].ch)& 0x1;
546 //printf("\r\n=========> MX_Read() set value = %d\r\n", value_int);
547 io_example[slot][index].data.value.i32 = value_int;
548 break;
549 case OPC_AI_MODE:
550 rc = ioThinx_AI_Config_GetRanges(slot, io_example[slot][index].ch, 1, &value_uint8);
551 if (rc != IOTHINX_ERR_OK)
552 {
553 printf("ioThinx_AI_GetEngs() = %d\n", rc);
554 return MX_IO_CONTROL_ERR;
555 }
556 //printf("\r\n=========> MX_Read() set value = %u\r\n", value_uint8);
557 io_example[slot][index].data.value.u8 = value_uint8;
558 break;
559 case OPC_AI_STATUS:
560 rc = ioThinx_AI_GetStatuss(slot, io_example[slot][index].ch, 1, &value_uint8);
561 if (rc != IOTHINX_ERR_OK)
562 {
563 printf("ioThinx_AI_GetEngs() = %d\n", rc);
564 return MX_IO_CONTROL_ERR;
565 }
566 //printf("\r\n=========> MX_Read() set value = %u\r\n", value_uint8);
567 io_example[slot][index].data.value.u8 = value_uint8;
568 break;
569 case OPC_AI_RAWVALUE:
570 rc = ioThinx_AI_GetRaws(slot, io_example[slot][index].ch, 1, &ai_raws);
571 if (rc != IOTHINX_ERR_OK)
572 {
573 printf("ioThinx_AI_GetEngs() = %d\n", rc);
574 return MX_IO_CONTROL_ERR;
575 }
576 //printf("\r\n=========> MX_Read() set value = %lu\r\n", ai_raws);
577 io_example[slot][index].data.value.u32 = ai_raws;
578 break;
579 case OPC_AI_MINIMUMRAWVALUE:
580 rc = ioThinx_AI_GetMinRaws(slot, io_example[slot][index].ch, 1, &ai_raws);
581 if (rc != IOTHINX_ERR_OK)
582 {
583 printf("ioThinx_AI_GetEngs() = %d\n", rc);
584 return MX_IO_CONTROL_ERR;
585 }
586 //printf("\r\n=========> MX_Read() set value = %lu\r\n", ai_raws);
587 io_example[slot][index].data.value.u32 = ai_raws;
588 break;
589 case OPC_AI_MAXIMUMRAWVALUE:
590 rc = ioThinx_AI_GetMaxRaws(slot, io_example[slot][index].ch, 1, &ai_raws);
591 if (rc != IOTHINX_ERR_OK)
592 {
593 printf("ioThinx_AI_GetEngs() = %d\n", rc);
594 return MX_IO_CONTROL_ERR;
595 }
596 //printf("\r\n=========> MX_Read() set value = %lu\r\n", ai_raws);
597 io_example[slot][index].data.value.u32 = ai_raws;
598 break;
599 case OPC_AI_SCALEDVALUE:
600 rc = ioThinx_AI_GetEngs(slot, io_example[slot][index].ch, 1, &value_float);
601 if (rc != IOTHINX_ERR_OK)
602 {
603 printf("ioThinx_AI_GetEngs() = %d\n", rc);
604 return MX_IO_CONTROL_ERR;
605 }
606 //printf("\r\n=========> MX_Read() set value = %f\r\n", value_float);
607 io_example[slot][index].data.value.f = value_float;
608 break;
609 default:
610 printf("IO function not found!\r\n");
611 return MX_IO_CONTROL_ERR;
612 }
613 *node_value = io_example[slot][index].data;
614
615 return MX_IO_CONTROL_OK;
616 }
_MX_NODE_VARIANT::u8
uint8_t u8
Definition: mx_node_node_def.h:107
ioThinx_AI_GetMinRaws
IOTHINX_ERR ioThinx_AI_GetMinRaws(uint32_t slot, uint8_t start, uint8_t count, uint32_t buf[])
ioThinx_DI_GetCntStarts
IOTHINX_ERR ioThinx_DI_GetCntStarts(uint32_t slot, uint32_t *p_starts)
OPC_DI_COUNTERSTATUS
Definition: DataSet.h:30
OPC_AI_STATUS
Definition: DataSet.h:37
_io_node::ch
int ch
Definition: DataSet.h:16
OPC_AI_MAXIMUMRAWVALUE
Definition: DataSet.h:40
ioThinx_DO_GetPwmCounts
IOTHINX_ERR ioThinx_DO_GetPwmCounts(uint32_t slot, uint8_t start, uint8_t count, uint32_t buf[])
ioThinx_Relay_GetValues
IOTHINX_ERR ioThinx_Relay_GetValues(uint32_t slot, uint32_t *p_values)
index
int index
Definition: cJSON.h:168
ioThinx_DO_GetPwmStarts
IOTHINX_ERR ioThinx_DO_GetPwmStarts(uint32_t slot, uint32_t *p_starts)
ioThinx_DI_GetCntValues
IOTHINX_ERR ioThinx_DI_GetCntValues(uint32_t slot, uint8_t start, uint8_t count, uint32_t buf[])
_MX_NODE_VARIANT::i32
int32_t i32
Definition: mx_node_node_def.h:105
_MX_NODE_VARIANT::u32
uint32_t u32
Definition: mx_node_node_def.h:109
ioThinx_AI_GetMaxRaws
IOTHINX_ERR ioThinx_AI_GetMaxRaws(uint32_t slot, uint8_t start, uint8_t count, uint32_t buf[])
IOTHINX_ERR_OK
#define IOTHINX_ERR_OK
Definition: iothinxio.h:35
io_example
NODE ** io_example
Definition: io_node_operator.c:51
OPC_RELAY_VALUE
Definition: DataSet.h:42
OPC_DO_PULSECOUNT
Definition: DataSet.h:35
ioThinx_AI_GetRaws
IOTHINX_ERR ioThinx_AI_GetRaws(uint32_t slot, uint8_t start, uint8_t count, uint32_t buf[])
OPC_AI_MODE
Definition: DataSet.h:36
ioThinx_DI_Config_GetModes
IOTHINX_ERR ioThinx_DI_Config_GetModes(uint32_t slot, uint8_t start, uint8_t count, uint8_t buf[])
OPC_DI_MODE
Definition: DataSet.h:28
MX_IO_CONTROL_ERR
#define MX_IO_CONTROL_ERR
Definition: DataSet.h:12
ioThinx_AI_GetEngs
IOTHINX_ERR ioThinx_AI_GetEngs(uint32_t slot, uint8_t start, uint8_t count, float buf[])
ioThinx_AI_Config_GetRanges
IOTHINX_ERR ioThinx_AI_Config_GetRanges(uint32_t slot, uint8_t start, uint8_t count, uint8_t buf[])
FUNC_TYPE
FUNC_TYPE
Definition: DataSet.h:27
OPC_DO_STATUS
Definition: DataSet.h:33
OPC_AI_MINIMUMRAWVALUE
Definition: DataSet.h:39
OPC_DI_STATUS
Definition: DataSet.h:29
ioThinx_DI_GetValues
IOTHINX_ERR ioThinx_DI_GetValues(uint32_t slot, uint32_t *p_values)
MX_IO_CONTROL_OK
#define MX_IO_CONTROL_OK
Definition: DataSet.h:11
OPC_AI_SCALEDVALUE
Definition: DataSet.h:41
_MX_NODE_VARIANT::f
float f
Definition: mx_node_node_def.h:111
ioThinx_DO_Config_GetModes
IOTHINX_ERR ioThinx_DO_Config_GetModes(uint32_t slot, uint8_t start, uint8_t count, uint8_t buf[])
OPC_AI_RAWVALUE
Definition: DataSet.h:38
_MX_NODE_VARIANT::value
union _MX_NODE_VARIANT::@0 value
ioThinx_DO_GetValues
IOTHINX_ERR ioThinx_DO_GetValues(uint32_t slot, uint32_t *p_values)
ioThinx_AI_GetStatuss
IOTHINX_ERR ioThinx_AI_GetStatuss(uint32_t slot, uint8_t start, uint8_t count, uint8_t buf[])
_io_node::data
MX_NODE_VARIANT data
Definition: DataSet.h:23
OPC_DO_MODE
Definition: DataSet.h:32
OPC_DI_COUNTERVALUE
Definition: DataSet.h:31
OPC_DO_PULSESTATUS
Definition: DataSet.h:34

int io_control_write | ( | int | slot,
|  | int | index,
|  | const MX_NODE_VARIANT * | node_value
| ) |  |

Definition at line 618 of file io_node_operator.c.

619 {
620 FUNC_TYPE fn;
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;
627 int rc = 0;
628
629 switch(io_example[slot][index].func_type){
630 case OPC_DI_COUNTERSTATUS:
631 if (node_value->type == MX_NODE_VALUE_TYPE_INT32) {
632 value_int = node_value->value.i32;
633 }
634 else {
635 return MX_IO_CONTROL_ERR;
636 }
637 if (value_int != 0 && value_int != 1) {
638 return MX_IO_CONTROL_ERR;
639 }
640 rc = ioThinx_DI_GetCntStarts(slot, &counter_starts);
641 if (rc != IOTHINX_ERR_OK)
642 {
643 printf("\r\n ioThinx_DI_GetCntStarts() = %d\r\n", rc);
644 return MX_IO_CONTROL_ERR;
645 }
646 if (value_int == 1) {
647 counter_starts |= 0x1 << (io_example[slot][index].ch);
648 rc = ioThinx_DI_SetCntStarts(slot, counter_starts);
649 if (rc != IOTHINX_ERR_OK)
650 {
651 printf("ioThinx_DI_SetCntStarts() = %d\n", rc);
652 return MX_IO_CONTROL_ERR;
653 }
654 }
655 else if (value_int == 0) {
656 counter_starts |= 0x1 << (io_example[slot][index].ch);
657 rc = ioThinx_DI_SetCntStops(slot, counter_starts);
658 if (rc != IOTHINX_ERR_OK)
659 {
660 printf("ioThinx_DI_SetCntStops() = %d\n", rc);
661 return MX_IO_CONTROL_ERR;
662 }
663 }
664 else {
665 return MX_IO_CONTROL_ERR;
666 }
667 break;
668 case OPC_DI_COUNTERVALUE:
669 if (node_value->type == MX_NODE_VALUE_TYPE_UINT32) {
670 value_uint = node_value->value.u32;
671 }
672 else {
673 return MX_IO_CONTROL_ERR;
674 }
675 rc = ioThinx_DI_SetCntValues(slot, io_example[slot][index].ch, 1, &value_uint);
676 if (rc != IOTHINX_ERR_OK)
677 {
678 printf("ioThinx_DI_SetCntValues() = %d\n", rc);
679 return MX_IO_CONTROL_ERR;
680 }
681 break;
682 case OPC_DO_STATUS:
683 if (node_value->type == MX_NODE_VALUE_TYPE_INT32) {
684 value_int = node_value->value.i32;
685 }
686 else {
687 return MX_IO_CONTROL_ERR;
688 }
689 if (value_int != 0 && value_int != 1) {
690 return MX_IO_CONTROL_ERR;
691 }
692 //printf("\r\n=========> MX_Write() set value = %d\r\n", value_int);
693 rc = ioThinx_DO_GetValues(slot, &do_values);
694 if (rc != IOTHINX_ERR_OK)
695 {
696 printf("\r\nioThinx_DO_GetValues() = %d\r\n", rc);
697 return MX_IO_CONTROL_ERR;
698 }
699 do_values = do_values & ~(0x1 << io_example[slot][index].ch) | (value_int << io_example[slot][index].ch);
700 //printf("do value = %lu\n", (unsigned long)do_values);
701 rc = ioThinx_DO_SetValues(slot, do_values);
702 if (rc != IOTHINX_ERR_OK)
703 {
704 printf("ioThinx_DO_SetValues() = %d\n", rc);
705 return MX_IO_CONTROL_ERR;
706 }
707 //printf("\r\n******************* [%lu:%u] DO value = %x\r\n", do_slot, do_channel, (do_values >> do_channel) & 0x1);
708 break;
709 case OPC_DO_PULSESTATUS:
710 if (node_value->type == MX_NODE_VALUE_TYPE_INT32) {
711 value_int = node_value->value.i32;
712 }
713 else {
714 return MX_IO_CONTROL_ERR;
715 }
716 if (value_int != 0 && value_int != 1) {
717 return MX_IO_CONTROL_ERR;
718 }
719 rc = ioThinx_DO_GetPwmStarts(slot, &pwm_starts);
720 if (rc != IOTHINX_ERR_OK)
721 {
722 printf("\r\n ioThinx_DO_GetPwmStarts() = %d\r\n", rc);
723 return MX_IO_CONTROL_ERR;
724 }
725 if (value_int == 1) {
726 // start pwm
727 pwm_starts |= 0x1 << (io_example[slot][index].ch);
728 rc = ioThinx_DO_SetPwmStarts(slot, pwm_starts);
729 if (rc != IOTHINX_ERR_OK)
730 {
731 printf("ioThinx_DO_SetPwmStarts() = %d\n", rc);
732 return MX_IO_CONTROL_ERR;
733 }
734 }
735 else if (value_int == 0) {
736 // stop pwm
737 pwm_starts |= 0x1 << (io_example[slot][index].ch);
738 rc = ioThinx_DO_SetPwmStops(slot, pwm_starts);
739 if (rc != IOTHINX_ERR_OK)
740 {
741 printf("ioThinx_DO_SetPwmStops() = %d\n", rc);
742 return MX_IO_CONTROL_ERR;
743 }
744 }
745 else {
746 return MX_IO_CONTROL_ERR;
747 }
748 break;
749 case OPC_DO_PULSECOUNT:
750 if (node_value->type == MX_NODE_VALUE_TYPE_UINT32) {
751 value_uint = node_value->value.u32;
752 }
753 else {
754 return MX_IO_CONTROL_ERR;
755 }
756 rc = ioThinx_DO_SetPwmCounts(slot, io_example[slot][index].ch, 1, &value_uint);
757 if (rc != IOTHINX_ERR_OK)
758 {
759 printf("ioThinx_DO_Config_SetPwmCounts() = %d\n", rc);
760 }
761 break;
762 case OPC_RELAY_VALUE:
763 if (node_value->type == MX_NODE_VALUE_TYPE_INT32) {
764 value_int = node_value->value.i32;
765 }
766 else {
767 return MX_IO_CONTROL_ERR;
768 }
769 //printf("\r\n=========> MX_Write() set value = %d\r\n", value_int);
770 if (value_int != 0 && value_int != 1) {
771 return MX_IO_CONTROL_ERR;
772 }
773 rc = ioThinx_Relay_GetValues(slot, &relay_values);
774 if (rc != IOTHINX_ERR_OK)
775 {
776 printf("\r\nioThinx_DO_GetValues() = %d\r\n", rc);
777 return MX_IO_CONTROL_ERR;
778 }
779 relay_values = relay_values & ~(0x1 << io_example[slot][index].ch) | (value_int << io_example[slot][index].ch);
780 //printf("relay value = %lu\n", (unsigned long)relay_values);
781 rc = ioThinx_Relay_SetValues(slot, relay_values);
782 if (rc != IOTHINX_ERR_OK)
783 {
784 printf("ioThinx_DO_SetValues() = %d\n", rc);
785 return MX_IO_CONTROL_ERR;
786 }
787 //printf("\r\n******************* [%lu:%u] DO value = %x\r\n", slot, io_example[slot][index].ch, (relay_values >> io_example[slot][index].ch) & 0x1);
788 break;
789 default:
790 printf("function not found!\r\n");
791 }
792 io_example[slot][index].data = *node_value;
793 return MX_IO_CONTROL_OK;
794 }
ioThinx_DO_SetPwmCounts
IOTHINX_ERR ioThinx_DO_SetPwmCounts(uint32_t slot, uint8_t start, uint8_t count, uint32_t buf[])
ioThinx_DI_SetCntStops
IOTHINX_ERR ioThinx_DI_SetCntStops(uint32_t slot, uint32_t stops)
ioThinx_DI_GetCntStarts
IOTHINX_ERR ioThinx_DI_GetCntStarts(uint32_t slot, uint32_t *p_starts)
OPC_DI_COUNTERSTATUS
Definition: DataSet.h:30
ioThinx_DI_SetCntStarts
IOTHINX_ERR ioThinx_DI_SetCntStarts(uint32_t slot, uint32_t starts)
_io_node::ch
int ch
Definition: DataSet.h:16
ioThinx_DO_SetPwmStops
IOTHINX_ERR ioThinx_DO_SetPwmStops(uint32_t slot, uint32_t stops)
ioThinx_Relay_GetValues
IOTHINX_ERR ioThinx_Relay_GetValues(uint32_t slot, uint32_t *p_values)
ioThinx_DO_SetValues
IOTHINX_ERR ioThinx_DO_SetValues(uint32_t slot, uint32_t values)
index
int index
Definition: cJSON.h:168
ioThinx_DO_GetPwmStarts
IOTHINX_ERR ioThinx_DO_GetPwmStarts(uint32_t slot, uint32_t *p_starts)
_MX_NODE_VARIANT::i32
int32_t i32
Definition: mx_node_node_def.h:105
_MX_NODE_VARIANT::u32
uint32_t u32
Definition: mx_node_node_def.h:109
IOTHINX_ERR_OK
#define IOTHINX_ERR_OK
Definition: iothinxio.h:35
io_example
NODE ** io_example
Definition: io_node_operator.c:51
OPC_RELAY_VALUE
Definition: DataSet.h:42
OPC_DO_PULSECOUNT
Definition: DataSet.h:35
ioThinx_Relay_SetValues
IOTHINX_ERR ioThinx_Relay_SetValues(uint32_t slot, uint32_t values)
MX_NODE_VALUE_TYPE_INT32
Definition: mx_node_node_def.h:71
MX_IO_CONTROL_ERR
#define MX_IO_CONTROL_ERR
Definition: DataSet.h:12
FUNC_TYPE
FUNC_TYPE
Definition: DataSet.h:27
OPC_DO_STATUS
Definition: DataSet.h:33
MX_NODE_VALUE_TYPE_UINT32
Definition: mx_node_node_def.h:75
ioThinx_DI_SetCntValues
IOTHINX_ERR ioThinx_DI_SetCntValues(uint32_t slot, uint8_t start, uint8_t count, uint32_t buf[])
_MX_NODE_VARIANT::type
MX_NODE_VALUE_TYPE type
Definition: mx_node_node_def.h:99
MX_IO_CONTROL_OK
#define MX_IO_CONTROL_OK
Definition: DataSet.h:11
_MX_NODE_VARIANT::value
union _MX_NODE_VARIANT::@0 value
ioThinx_DO_GetValues
IOTHINX_ERR ioThinx_DO_GetValues(uint32_t slot, uint32_t *p_values)
ioThinx_DO_SetPwmStarts
IOTHINX_ERR ioThinx_DO_SetPwmStarts(uint32_t slot, uint32_t starts)
_io_node::data
MX_NODE_VARIANT data
Definition: DataSet.h:23
OPC_DI_COUNTERVALUE
Definition: DataSet.h:31
OPC_DO_PULSESTATUS
Definition: DataSet.h:34

struct timeval Now | ( |  | ) |

Definition at line 50 of file DataSet.h.

51 {
52 struct timeval now;
53 gettimeofday(&now, NULL);
54 return now;
55 }
now
struct timeval now()
Definition: demo_node_operator.c:303