no-OS
iiod_private.h
Go to the documentation of this file.
1 /***************************************************************************/
40 #ifndef IIOD_PRIVATE_H
41 #define IIOD_PRIVATE_H
42 
43 #define IIOD_WR 0x1
44 #define IIOD_ENDL 0x2
45 #define IIOD_RD 0x4
46 #define IIOD_PARSER_MAX_BUF_SIZE 128
47 
48 #define IIOD_STR(cmd) {(cmd), sizeof(cmd) - 1}
49 
50 #define IIOD_CTX(desc, conn) {.instance = (desc)->app_instance,\
51  .conn = (conn)->conn}
52 
53 
54 /* Used to store a string and its size */
55 struct iiod_str {
56  char *str;
57  uint32_t len;
58 };
59 
60 /*
61  * Commads are the ones documented int the link:
62  * https://wiki.analog.com/resources/tools-software/linux-software/libiio_internals#the_network_backend_and_iio_daemon
63  */
64 enum iiod_cmd {
79 };
80 
81 /*
82  * Structure to be filled after a command is parsed.
83  * Depending of cmd some fields are set or not
84  */
85 struct comand_desc {
86  enum iiod_cmd cmd;
87  uint32_t mask;
88  uint32_t timeout;
89  uint32_t sample_count;
90  uint32_t bytes_count;
91  uint32_t count;
92  bool cyclic;
98 };
99 
100 /* Used to store buffer indexes for non blocking transfers */
101 struct iiod_buff {
102  char *buf;
103  uint32_t idx;
104  uint32_t len;
105 };
106 
107 /* Result after executing a command. */
109  uint32_t val;
110  /* If set. Val needs to be sent */
111  bool write_val;
112  /* If buf.len != 0 buf has to be sent */
113  struct iiod_buff buf;
114 };
115 
116 /* Internal structure to handle a connection state */
118  /* User instance of the connection to be sent in iiod_ctx */
119  void *conn;
120  /* Unset when can be used from the connection pool */
121  bool used;
122 
123  /* Command data after parsed */
125  /* Result of an executed cmd */
127  /* IIOD States */
128  enum {
129  /* Reading line until \n */
131  /* Execut cmd without I/O operations */
133  /* Write result of executed cmd */
135  /* I/O operations for READBUF and WRITEBUF cmds */
137  /* I/O operations for WRITE cmd */
139  /* Set when a operation is finalized */
141  /* Pushing cyclic buffer until IIO device is closed */
143  } state;
144 
145  /* Buffer to store received line */
147  /* Index in parser_buf. For nonblocking operation */
148  uint32_t parser_idx;
149  /* Buffer to store raw data (attributes or buffer data).*/
150  char *payload_buf;
151  /* Length of payload_buf_len */
152  uint32_t payload_buf_len;
153  /* Used in nonbloking transfers to save indexes */
155 
156  /* Mask of current opened buffer */
157  uint32_t mask;
158  /* Buffer to store mask as a string */
159  char buf_mask[10];
160  /* Context for strtok_r function */
161  char *strtok_ctx;
162  /* True if the device was open with cyclic buffer flag */
164 };
165 
166 /* Private iiod information */
167 struct iiod_desc {
168  /* Pool of iiod connections */
170  /* Application operations */
171  struct iiod_ops ops;
172  /* Application instance */
174  /* Address of xml */
175  char *xml;
176  /* XML length in bytes */
177  uint32_t xml_len;
178 };
179 
180 #endif //IIOD_PRIVATE_H
comand_desc::trigger
char trigger[MAX_TRIG_ID]
Definition: iiod_private.h:96
iiod_desc::app_instance
void * app_instance
Definition: iiod_private.h:173
iiod_conn_priv::IIOD_LINE_DONE
@ IIOD_LINE_DONE
Definition: iiod_private.h:140
IIOD_CMD_EXIT
@ IIOD_CMD_EXIT
Definition: iiod_private.h:66
iiod_conn_priv::used
bool used
Definition: iiod_private.h:121
comand_desc::timeout
uint32_t timeout
Definition: iiod_private.h:88
iiod_buff
Definition: iiod_private.h:101
iiod_conn_priv::conn
void * conn
Definition: iiod_private.h:119
IIOD_CMD_OPEN
@ IIOD_CMD_OPEN
Definition: iiod_private.h:70
MAX_TRIG_ID
#define MAX_TRIG_ID
Definition: iiod.h:52
IIOD_CMD_SET
@ IIOD_CMD_SET
Definition: iiod_private.h:78
iiod_conn_priv::buf_mask
char buf_mask[10]
Definition: iiod_private.h:159
iiod_desc
Definition: iiod_private.h:167
iiod_conn_priv::IIOD_READING_WRITE_DATA
@ IIOD_READING_WRITE_DATA
Definition: iiod_private.h:138
iiod_str::str
char * str
Definition: iiod_private.h:56
iiod_run_cmd_result::write_val
bool write_val
Definition: iiod_private.h:111
iiod_str
Definition: iiod_private.h:55
device
Definition: ad9361_util.h:75
iiod_conn_priv::parser_buf
char parser_buf[IIOD_PARSER_MAX_BUF_SIZE]
Definition: iiod_private.h:146
iiod_desc::xml_len
uint32_t xml_len
Definition: iiod_private.h:177
iiod_desc::xml
char * xml
Definition: iiod_private.h:175
iio_attr_type
iio_attr_type
Definition: iiod.h:56
IIOD_CMD_READ
@ IIOD_CMD_READ
Definition: iiod_private.h:72
iiod_conn_priv::payload_buf
char * payload_buf
Definition: iiod_private.h:150
IIOD_CMD_WRITEBUF
@ IIOD_CMD_WRITEBUF
Definition: iiod_private.h:75
iiod_str::len
uint32_t len
Definition: iiod_private.h:57
iiod_buff::idx
uint32_t idx
Definition: iiod_private.h:103
iiod_conn_priv
Definition: iiod_private.h:117
IIOD_MAX_CONNECTIONS
#define IIOD_MAX_CONNECTIONS
Definition: iiod.h:47
comand_desc::type
enum iio_attr_type type
Definition: iiod_private.h:97
iiod_conn_priv::state
enum iiod_conn_priv::@2 state
comand_desc::mask
uint32_t mask
Definition: iiod_private.h:87
iiod_conn_priv::IIOD_RW_BUF
@ IIOD_RW_BUF
Definition: iiod_private.h:136
iiod_conn_priv::mask
uint32_t mask
Definition: iiod_private.h:157
IIOD_CMD_PRINT
@ IIOD_CMD_PRINT
Definition: iiod_private.h:67
comand_desc::cyclic
bool cyclic
Definition: iiod_private.h:92
iiod_desc::conns
struct iiod_conn_priv conns[IIOD_MAX_CONNECTIONS]
Definition: iiod_private.h:169
comand_desc::cmd
enum iiod_cmd cmd
Definition: iiod_private.h:86
iiod_buff::buf
char * buf
Definition: iiod_private.h:102
IIOD_PARSER_MAX_BUF_SIZE
#define IIOD_PARSER_MAX_BUF_SIZE
Definition: iiod_private.h:46
iiod_conn_priv::nb_buf
struct iiod_buff nb_buf
Definition: iiod_private.h:154
comand_desc::count
uint32_t count
Definition: iiod_private.h:91
iiod_desc::ops
struct iiod_ops ops
Definition: iiod_private.h:171
comand_desc::attr
char attr[MAX_ATTR_NAME]
Definition: iiod_private.h:95
iiod_conn_priv::IIOD_READING_LINE
@ IIOD_READING_LINE
Definition: iiod_private.h:130
iiod_conn_priv::cmd_data
struct comand_desc cmd_data
Definition: iiod_private.h:124
MAX_DEV_ID
#define MAX_DEV_ID
Definition: iiod.h:51
IIOD_CMD_CLOSE
@ IIOD_CMD_CLOSE
Definition: iiod_private.h:71
MAX_CHN_ID
#define MAX_CHN_ID
Definition: iiod.h:53
IIOD_CMD_GETTRIG
@ IIOD_CMD_GETTRIG
Definition: iiod_private.h:76
iiod_run_cmd_result::buf
struct iiod_buff buf
Definition: iiod_private.h:113
iiod_conn_priv::IIOD_WRITING_CMD_RESULT
@ IIOD_WRITING_CMD_RESULT
Definition: iiod_private.h:134
comand_desc::sample_count
uint32_t sample_count
Definition: iiod_private.h:89
IIOD_CMD_WRITE
@ IIOD_CMD_WRITE
Definition: iiod_private.h:73
iiod_conn_priv::IIOD_RUNNING_CMD
@ IIOD_RUNNING_CMD
Definition: iiod_private.h:132
iiod_conn_priv::payload_buf_len
uint32_t payload_buf_len
Definition: iiod_private.h:152
comand_desc::bytes_count
uint32_t bytes_count
Definition: iiod_private.h:90
iiod_buff::len
uint32_t len
Definition: iiod_private.h:104
iiod_run_cmd_result
Definition: iiod_private.h:108
MAX_ATTR_NAME
#define MAX_ATTR_NAME
Definition: iiod.h:54
iiod_conn_priv::strtok_ctx
char * strtok_ctx
Definition: iiod_private.h:161
iiod_ops
Definition: iiod.h:92
IIOD_CMD_SETTRIG
@ IIOD_CMD_SETTRIG
Definition: iiod_private.h:77
IIOD_CMD_HELP
@ IIOD_CMD_HELP
Definition: iiod_private.h:65
comand_desc::channel
char channel[MAX_CHN_ID]
Definition: iiod_private.h:94
iiod_conn_priv::res
struct iiod_run_cmd_result res
Definition: iiod_private.h:126
iiod_conn_priv::IIOD_PUSH_CYCLIC_BUFFER
@ IIOD_PUSH_CYCLIC_BUFFER
Definition: iiod_private.h:142
IIOD_CMD_READBUF
@ IIOD_CMD_READBUF
Definition: iiod_private.h:74
IIOD_CMD_TIMEOUT
@ IIOD_CMD_TIMEOUT
Definition: iiod_private.h:69
IIOD_CMD_VERSION
@ IIOD_CMD_VERSION
Definition: iiod_private.h:68
iiod_conn_priv::parser_idx
uint32_t parser_idx
Definition: iiod_private.h:148
iiod_conn_priv::is_cyclic_buffer
bool is_cyclic_buffer
Definition: iiod_private.h:163
iiod_cmd
iiod_cmd
Definition: iiod_private.h:64
iiod_run_cmd_result::val
uint32_t val
Definition: iiod_private.h:109
comand_desc
Definition: iiod_private.h:85