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;
93  const char *device;
94  const char *channel;
95  const char *attr;
96  const char *trigger;
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  } state;
142 
143  /* Buffer to store received line */
145  /* Index in parser_buf. For nonblocking operation */
146  uint32_t parser_idx;
147  /* Buffer to store raw data (attributes or buffer data).*/
148  char *payload_buf;
149  /* Length of payload_buf_len */
150  uint32_t payload_buf_len;
151  /* Used in nonbloking transfers to save indexes */
153 
154  /* Mask of current opened buffer */
155  uint32_t mask;
156  /* Buffer to store mask as a string */
157  char buf_mask[10];
158  /* Context for strtok_r function */
159  char *strtok_ctx;
160 };
161 
162 /* Private iiod information */
163 struct iiod_desc {
164  /* Pool of iiod connections */
166  /* Application operations */
167  struct iiod_ops ops;
168  /* Application instance */
170  /* Address of xml */
171  char *xml;
172  /* XML length in bytes */
173  uint32_t xml_len;
174 };
175 
176 #endif //IIOD_PRIVATE_H
comand_desc::attr
const char * attr
Definition: iiod_private.h:95
iiod_desc::app_instance
void * app_instance
Definition: iiod_private.h:169
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
IIOD_CMD_SET
@ IIOD_CMD_SET
Definition: iiod_private.h:78
iiod_conn_priv::buf_mask
char buf_mask[10]
Definition: iiod_private.h:157
iiod_desc
Definition: iiod_private.h:163
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
comand_desc::trigger
const char * trigger
Definition: iiod_private.h:96
iiod_str
Definition: iiod_private.h:55
iiod_conn_priv::parser_buf
char parser_buf[IIOD_PARSER_MAX_BUF_SIZE]
Definition: iiod_private.h:144
iiod_desc::xml_len
uint32_t xml_len
Definition: iiod_private.h:173
iiod_desc::xml
char * xml
Definition: iiod_private.h:171
iio_attr_type
iio_attr_type
Definition: iiod.h:51
IIOD_CMD_READ
@ IIOD_CMD_READ
Definition: iiod_private.h:72
iiod_conn_priv::payload_buf
char * payload_buf
Definition: iiod_private.h:148
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:155
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:165
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
comand_desc::device
const char * device
Definition: iiod_private.h:93
iiod_conn_priv::nb_buf
struct iiod_buff nb_buf
Definition: iiod_private.h:152
comand_desc::count
uint32_t count
Definition: iiod_private.h:91
iiod_desc::ops
struct iiod_ops ops
Definition: iiod_private.h:167
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
IIOD_CMD_CLOSE
@ IIOD_CMD_CLOSE
Definition: iiod_private.h:71
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:150
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
iiod_conn_priv::strtok_ctx
char * strtok_ctx
Definition: iiod_private.h:159
iiod_ops
Definition: iiod.h:87
IIOD_CMD_SETTRIG
@ IIOD_CMD_SETTRIG
Definition: iiod_private.h:77
IIOD_CMD_HELP
@ IIOD_CMD_HELP
Definition: iiod_private.h:65
iiod_conn_priv::res
struct iiod_run_cmd_result res
Definition: iiod_private.h:126
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:146
comand_desc::channel
const char * channel
Definition: iiod_private.h:94
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