Rodbus-FFI  0.1.1
Idiomatic C API to the Rodbus crate via Rust FFI
rodbus.h
Go to the documentation of this file.
1 #ifndef RODBUS_FFI_H
2 #define RODBUS_FFI_H
3 
4 /* Generated with cbindgen:0.14.4 */
5 
6 /* Warning, this file is autogenerated by cbindgen. Don't modify this manually. */
7 
8 #include <stdarg.h>
9 #include <stdbool.h>
10 #include <stdint.h>
11 #include <stdlib.h>
12 #include "prelude.h"
13 
17 #define MAX_READ_COILS_COUNT 2000
18 
22 #define MAX_READ_REGISTERS_COUNT 125
23 
27 #define MAX_WRITE_COILS_COUNT 1968
28 
32 #define MAX_WRITE_REGISTERS_COUNT 123
33 
37 enum Exception {
82 };
83 typedef uint8_t Exception;
84 
88 enum Level {
94 };
95 typedef uint8_t Level;
96 
100 enum Status {
141 };
142 typedef uint8_t Status;
143 
144 typedef struct BitIterator BitIterator;
145 
146 typedef struct Handler Handler;
147 
149 
150 typedef struct ServerHandle ServerHandle;
151 
152 typedef struct Updater Updater;
153 
157 typedef struct Session {
169  uint8_t unit_id;
173  uint32_t timeout_ms;
174 } Session;
175 
176 typedef bool (*WriteSingleCallback_bool)(bool, uint16_t, void*);
177 
178 typedef bool (*WriteSingleCallback_u16)(uint16_t, uint16_t, void*);
179 
180 typedef bool (*WriteMultipleCallback_bool)(const bool*, uint16_t, uint16_t, void*);
181 
182 typedef bool (*WriteMultipleCallback_u16)(const uint16_t*, uint16_t, uint16_t, void*);
183 
184 typedef struct Callbacks {
189 } Callbacks;
190 
191 typedef struct Sizes {
192  uint16_t num_coils;
196 } Sizes;
197 
201 typedef struct RuntimeConfig {
207 } RuntimeConfig;
208 
209 typedef struct Bit {
210  bool value;
211  uint16_t index;
212 } Bit;
213 
214 typedef struct Register {
215  uint16_t value;
216  uint16_t index;
217 } Register;
218 
222 typedef struct Result {
231  uint8_t exception;
232 } Result;
233 
234 Updater *acquire_updater(Handler *handler);
235 
248  Channel *channel,
249  uint8_t unit_id,
250  uint32_t timeout_ms);
251 
256 
257 Handler *create_handler(Runtime *runtime, Sizes sizes, Callbacks callbacks, void *user_data);
258 
260  const char *address,
261  uint8_t unit_id,
262  Handler *handler);
263 
264 Sizes create_sizes(uint16_t num_coils,
265  uint16_t num_discrete_inputs,
266  uint16_t num_holding_registers,
267  uint16_t num_input_registers);
268 
283  const char *address,
284  uint16_t max_queued_requests);
285 
298 
311 
312 void destroy_handler(Handler *handler);
313 
327 
328 void destroy_server(ServerHandle *handle);
329 
338 bool get_next_bit(BitIterator *iterator, Bit *value);
339 
348 bool get_next_register(RegisterIterator *iterator, Register *value);
349 
362 Result read_coils(Session *session,
363  uint16_t start,
364  uint16_t count,
365  bool *output);
366 
378 void read_coils_cb(Session *session,
379  uint16_t start,
380  uint16_t count,
381  void (*callback)(Result, BitIterator*, void*),
382  void *user_data);
383 
397  uint16_t start,
398  uint16_t count,
399  bool *output);
400 
412 void read_discrete_inputs_cb(Session *session,
413  uint16_t start,
414  uint16_t count,
415  void (*callback)(Result, BitIterator*, void*),
416  void *user_data);
417 
431  uint16_t start,
432  uint16_t count,
433  uint16_t *output);
434 
446 void read_holding_registers_cb(Session *session,
447  uint16_t start,
448  uint16_t count,
449  void (*callback)(Result, RegisterIterator*, void*),
450  void *user_data);
451 
465  uint16_t start,
466  uint16_t count,
467  uint16_t *output);
468 
480 void read_input_registers_cb(Session *session,
481  uint16_t start,
482  uint16_t count,
483  void (*callback)(Result, RegisterIterator*, void*),
484  void *user_data);
485 
486 void release_updater(Updater *updater);
487 
496 bool set_log_callback(void (*callback)(Level level, const char *message));
497 
503 void set_max_level(Level level);
504 
505 bool update_coil(Updater *updater, bool value, uint16_t index);
506 
507 void update_handler(Handler *handler, void *user_data, void (*callback)(Updater*, void*));
508 
522 Result write_multiple_coils(Session *session, uint16_t start, const bool *values, uint16_t count);
523 
538 void write_multiple_coils_cb(Session *session,
539  uint16_t start,
540  const bool *values,
541  uint16_t count,
542  void (*callback)(Result, void*),
543  void *user_data);
544 
559  uint16_t start,
560  const uint16_t *values,
561  uint16_t count);
562 
578  uint16_t start,
579  const uint16_t *values,
580  uint16_t count,
581  void (*callback)(Result, void*),
582  void *user_data);
583 
594 Result write_single_coil(Session *session, uint16_t index, bool value);
595 
607 void write_single_coil_cb(Session *session,
608  uint16_t index,
609  bool value,
610  void (*callback)(Result, void*),
611  void *user_data);
612 
623 Result write_single_register(Session *session, uint16_t index, uint16_t value);
624 
636 void write_single_register_cb(Session *session,
637  uint16_t index,
638  uint16_t value,
639  void (*callback)(Result, void*),
640  void *user_data);
641 
642 #endif /* RODBUS_FFI_H */
void destroy_channel(Channel *channel)
Destroy a previously created channel instance.
Definition: rodbus.h:92
Struct that bundles together the types needed to make requests on a channel.
Definition: rodbus.h:157
WriteSingleCallback_u16 write_single_register_cb
Definition: rodbus.h:186
struct Sizes Sizes
Definition: rodbus.h:91
uint16_t num_input_registers
Definition: rodbus.h:195
Runtime * runtime
Definition: rodbus.h:161
Definition: rodbus.h:41
Definition: rodbus.h:120
struct RuntimeConfig RuntimeConfig
Optional non-default configuration of the Tokio runtime.
Optional non-default configuration of the Tokio runtime.
Definition: rodbus.h:201
Definition: rodbus.h:45
WriteMultipleCallback_bool write_multiple_coils
Definition: rodbus.h:187
Definition: rodbus.h:104
Definition: rodbus.h:70
Session build_session(Runtime *runtime, Channel *channel, uint8_t unit_id, uint32_t timeout_ms)
Convenience function to build a session struct.
void write_multiple_registers_cb(Session *session, uint16_t start, const uint16_t *values, uint16_t count, void(*callback)(Result, void *), void *user_data)
perform a non-blocking operation to write multiple registers
Handler * create_handler(Runtime *runtime, Sizes sizes, Callbacks callbacks, void *user_data)
void read_holding_registers_cb(Session *session, uint16_t start, uint16_t count, void(*callback)(Result, RegisterIterator *, void *), void *user_data)
perform a non-blocking operation to read holding registers
Channel * channel
Definition: rodbus.h:165
ServerHandle * create_server(Runtime *runtime, const char *address, uint8_t unit_id, Handler *handler)
Definition: rodbus.h:90
struct ServerHandle ServerHandle
Definition: rodbus.h:150
Definition: rodbus.h:76
bool(* WriteSingleCallback_u16)(uint16_t, uint16_t, void *)
Definition: rodbus.h:178
bool set_log_callback(void(*callback)(Level level, const char *message))
set the callback to invoke when an enabled level is logged
Definition: rodbus.h:136
Result read_input_registers(Session *session, uint16_t start, uint16_t count, uint16_t *output)
perform a blocking operation to read input registers
void update_handler(Handler *handler, void *user_data, void(*callback)(Updater *, void *))
uint16_t num_discrete_inputs
Definition: rodbus.h:193
Definition: rodbus.h:59
Definition: rodbus.h:89
Definition: rodbus.h:128
Definition: rodbus.h:54
struct Callbacks Callbacks
struct Result Result
Type that describes the success or failure of an operation.
Definition: rodbus.h:93
Result write_single_register(Session *session, uint16_t index, uint16_t value)
perform a blocking operation to write a single register
struct RegisterIterator RegisterIterator
Definition: rodbus.h:148
Result read_discrete_inputs(Session *session, uint16_t start, uint16_t count, bool *output)
perform a blocking operation to read discrete inputs
Definition: rodbus.h:191
struct Runtime Runtime
Opaque pointer type for the Tokio runtime.
Definition: prelude.h:8
Definition: rodbus.h:112
void destroy_runtime(Runtime *runtime)
Destroy a previously created runtime instance.
uint16_t num_core_threads
Definition: rodbus.h:206
Definition: rodbus.h:49
Definition: rodbus.h:214
void write_single_coil_cb(Session *session, uint16_t index, bool value, void(*callback)(Result, void *), void *user_data)
perform a non-blocking operation to write a single coil
void write_multiple_coils_cb(Session *session, uint16_t start, const bool *values, uint16_t count, void(*callback)(Result, void *), void *user_data)
perform a non-blocking operation to write multiple coils
Runtime * create_threaded_runtime(const RuntimeConfig *config)
create an instance of the multi-threaded work-stealing Tokio runtime
void destroy_handler(Handler *handler)
struct Handler Handler
Definition: rodbus.h:146
Definition: rodbus.h:132
uint8_t exception
Definition: rodbus.h:231
WriteSingleCallback_bool write_single_coil_cb
Definition: rodbus.h:185
bool(* WriteMultipleCallback_u16)(const uint16_t *, uint16_t, uint16_t, void *)
Definition: rodbus.h:182
Channel * create_tcp_client(Runtime *runtime, const char *address, uint16_t max_queued_requests)
Create an instance of a TCP client channel.
uint16_t index
Definition: rodbus.h:216
Definition: rodbus.h:140
Definition: rodbus.h:64
Result read_holding_registers(Session *session, uint16_t start, uint16_t count, uint16_t *output)
perform a blocking operation to read holding registers
Definition: rodbus.h:124
void set_max_level(Level level)
set the maximum log level
struct Session Session
Struct that bundles together the types needed to make requests on a channel.
Definition: rodbus.h:209
Updater * acquire_updater(Handler *handler)
uint8_t unit_id
Definition: rodbus.h:169
struct Updater Updater
Definition: rodbus.h:152
Status status
Definition: rodbus.h:226
Definition: rodbus.h:116
bool(* WriteMultipleCallback_bool)(const bool *, uint16_t, uint16_t, void *)
Definition: rodbus.h:180
void read_discrete_inputs_cb(Session *session, uint16_t start, uint16_t count, void(*callback)(Result, BitIterator *, void *), void *user_data)
perform a non-blocking operation to read discrete inputs
Exception
Definition: rodbus.h:37
Sizes create_sizes(uint16_t num_coils, uint16_t num_discrete_inputs, uint16_t num_holding_registers, uint16_t num_input_registers)
bool update_coil(Updater *updater, bool value, uint16_t index)
Status
Definition: rodbus.h:100
struct Bit Bit
bool value
Definition: rodbus.h:210
uint16_t value
Definition: rodbus.h:215
void read_input_registers_cb(Session *session, uint16_t start, uint16_t count, void(*callback)(Result, RegisterIterator *, void *), void *user_data)
perform a non-blocking operation to read input registers
uint32_t timeout_ms
Definition: rodbus.h:173
uint16_t num_coils
Definition: rodbus.h:192
Result write_single_coil(Session *session, uint16_t index, bool value)
perform a blocking operation to write a single coil
bool get_next_register(RegisterIterator *iterator, Register *value)
retrieve the next register value and/or index from iterator
void read_coils_cb(Session *session, uint16_t start, uint16_t count, void(*callback)(Result, BitIterator *, void *), void *user_data)
perform a non-blocking operation to read coils
struct Register Register
Definition: rodbus.h:108
struct Channel Channel
Opaque pointer type for the Channel.
Definition: prelude.h:11
Result write_multiple_coils(Session *session, uint16_t start, const bool *values, uint16_t count)
perform a blocking operation to write multiple coils
void write_single_register_cb(Session *session, uint16_t index, uint16_t value, void(*callback)(Result, void *), void *user_data)
perform a non-blocking operation to write a single register
Level
Definition: rodbus.h:88
Callbacks create_callbacks(WriteSingleCallback_bool write_single_coil_cb, WriteSingleCallback_u16 write_single_register_cb, WriteMultipleCallback_bool write_multiple_coils, WriteMultipleCallback_u16 write_multiple_registers)
WriteMultipleCallback_u16 write_multiple_registers
Definition: rodbus.h:188
Result write_multiple_registers(Session *session, uint16_t start, const uint16_t *values, uint16_t count)
perform a blocking operation to write multiple registers
uint16_t index
Definition: rodbus.h:211
uint16_t num_holding_registers
Definition: rodbus.h:194
bool(* WriteSingleCallback_bool)(bool, uint16_t, void *)
Definition: rodbus.h:176
void destroy_server(ServerHandle *handle)
struct BitIterator BitIterator
Definition: rodbus.h:144
bool get_next_bit(BitIterator *iterator, Bit *value)
retrieve the next bit and/or index from iterator
void release_updater(Updater *updater)
Result read_coils(Session *session, uint16_t start, uint16_t count, bool *output)
perform a blocking operation to read coils
Type that describes the success or failure of an operation.
Definition: rodbus.h:222
Definition: rodbus.h:184