Top |
ratp_link_t * | ratp_link_new_tty () |
ratp_link_t * | ratp_link_new_fifo () |
void | ratp_link_free () |
ratp_status_t | ratp_link_initialize () |
bool | ratp_link_get_initialized () |
void | ratp_link_shutdown () |
void | (*ratp_link_initialized_func) () |
void | ratp_link_set_initialized_callback () |
const char * | ratp_link_state_str () |
ratp_link_state_t | ratp_link_get_state () |
void | (*ratp_link_state_update_func) () |
void | ratp_link_set_state_update_callback () |
ratp_status_t | ratp_link_active_open () |
ratp_status_t | ratp_link_active_open_sync () |
ratp_status_t | ratp_link_passive_open () |
void | ratp_link_close () |
ratp_status_t | ratp_link_close_sync () |
void | (*ratp_link_send_ready_func) () |
ratp_status_t | ratp_link_send () |
void | (*ratp_link_receive_ready_func) () |
void | ratp_link_set_receive_callback () |
This section defines the RATP link type as well as methods to create and use them.
Example 2. Opening and closing the link
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
static const char *message = "hello world!"; ratp_link_t *ratp; ratp_status_t st; ratp = ratp_link_new_tty ("/dev/ttyUSB3", B115200, 255); if (!ratp) { fprintf (stderr, "error: couldn't create link\n"); return EXIT_FAILURE; } if ((st = ratp_link_initialize (ratp)) != RATP_STATUS_OK) { fprintf (stderr, "error: couldn't initialize link: %s\n", ratp_status_str (st)); return EXIT_FAILURE; } if ((st = ratp_link_active_open (ratp)) != RATP_STATUS_OK) { fprintf (stderr, "error: couldn't request active open: %s\n", ratp_status_str (st)); return -1; } if ((st = ratp_link_send (ratp, 10000, (const uint8_t *) message, strlen (message) + 1, NULL, NULL)) != RATP_STATUS_OK) { fprintf (stderr, "error: couldn't schedule message to send: %s\n", ratp_status_str (st)); return -1; } // Do more things here if needed ratp_link_close (ratp); ratp_link_shutdown (ratp); ratp_link_free (ratp); |
ratp_link_t * ratp_link_new_tty (const char *path
,speed_t speed
,uint8_t mdl
);
Create a new RATP link associated to a TTY.
path |
Serial port device path. |
[in] |
speed |
Baudrate to use in the serial port. |
[in] |
mdl |
Maximum data length allowed in this end. |
[in] |
a newly created ratp_link_t which should be
disposed with ratp_link_free()
or NULL
if an error happened.
[transfer full]
ratp_link_t * ratp_link_new_fifo (const char *path_in
,const char *path_out
,uint8_t mdl
);
Create a new RATP link associated to a pair of input/output FIFOs.
path_in |
Input FIFO path. |
[in] |
path_out |
Output FIFO path. |
[in] |
mdl |
Maximum data length allowed in this end. |
[in] |
a newly created ratp_link_t which should be
disposed with ratp_link_free()
or NULL
if an error happened.
[transfer full]
ratp_status_t
ratp_link_initialize (ratp_link_t *self
);
Initialize a RATP link.
This operation just opens and sets up the physical channel, it doesn't send or receive any RATP packet.
bool
ratp_link_get_initialized (ratp_link_t *self
);
Checks whether the RATP link is initialized.
void
ratp_link_shutdown (ratp_link_t *self
);
Shutdown a RATP link.
This operation closes the physical channel.
void (*ratp_link_initialized_func) (ratp_link_t *self
,void *user_data
);
Handler used to report initialization to the user.
self |
a ratp_link_t. |
[in][not nullable] |
user_data |
user data given by the user when registering the callback. |
[in] |
void ratp_link_set_initialized_callback (ratp_link_t *self
,ratp_link_initialized_func callback
,void *user_data
);
Set the callback to be called when the RATP link is initialized.
The callback is guaranteed to be called from within the link management thread.
self |
a ratp_link_t. |
[in][not nullable] |
callback |
[in][nullable] | |
user_data |
user data to be passed to |
[in][nullable] |
const char *
ratp_link_state_str (ratp_link_state_t state
);
Gets a description for the given ratp_link_state_t.
ratp_link_state_t
ratp_link_get_state (ratp_link_t *self
);
Gets the current state of the RATP link.
void (*ratp_link_state_update_func) (ratp_link_t *self
,ratp_link_state_t old_state
,ratp_link_state_t new_state
,ratp_status_t status_reason
,void *user_data
);
Handler used to report state updates to the user.
self |
a ratp_link_t. |
[in][not nullable] |
old_state |
the previous RATP link state. |
[in] |
new_state |
the new RATP link state. |
[in] |
status_reason |
the reason for the state change. |
[in] |
user_data |
user data given by the user when registering the callback. |
[in][nullable] |
void ratp_link_set_state_update_callback (ratp_link_t *self
,ratp_link_state_update_func callback
,void *user_data
);
Set the callback to be called when RATP link state updates happen.
self |
a ratp_link_t. |
[in][not nullable] |
callback |
[in][nullable] | |
user_data |
user data to be passed to |
[in][nullable] |
ratp_status_t
ratp_link_active_open (ratp_link_t *self
);
Requests to actively open the RATP link.
This method does not wait for the RATP link to be established, it just
schedules the request. Link state updates may be monitored with the callback
configured via ratp_link_set_state_update_callback()
.
ratp_status_t ratp_link_active_open_sync (ratp_link_t *self
,unsigned long timeout_ms
);
Requests to actively open the RATP link.
This method blocks until the RATP link is established or until timeout_ms
are elapsed.
Monitoring of the link state with ratp_link_set_state_update_callback()
cannot be performed while this operation is ongoing; any callback previously
configured will be ignored.
self |
a ratp_link_t. |
[in][not nullable] |
timeout_ms |
maximum time, in milliseconds, to wait for the link to be established; or 0 to wait forever. |
[in] |
ratp_status_t
ratp_link_passive_open (ratp_link_t *self
);
Requests to passively open the RATP link.
This method does not wait for the RATP link to be established, it just
schedules the request. Link state updates may be monitored with the callback
configured via ratp_link_set_state_update_callback()
.
void
ratp_link_close (ratp_link_t *self
);
Requests to close the RATP link.
This method does not wait for the RATP link to be closed, it just schedules
the request. Link state updates may be monitored with the callback configured
via ratp_link_set_state_update_callback()
.
ratp_status_t ratp_link_close_sync (ratp_link_t *self
,unsigned long timeout_ms
);
Requests to close the RATP link.
This method blocks until the RATP link is established or until timeout_ms
are elapsed.
Monitoring of the link state with ratp_link_set_state_update_callback()
cannot be performed while this operation is ongoing; any callback previously
configured will be ignored.
self |
a ratp_link_t. |
[in][not nullable] |
timeout_ms |
maximum time, in milliseconds, to wait for the link to be closed; or 0 to wait forever. |
[in] |
void (*ratp_link_send_ready_func) (ratp_link_t *self
,ratp_status_t status_reason
,void *user_data
);
Handler used to report when a sent buffer has been completely sent.
self |
a (in) (not nullable): ratp_link_t. |
|
status_reason |
the status of the send operation. |
[in] |
user_data |
user data given by the user when registering the callback. |
[in][nullable] |
ratp_status_t ratp_link_send (ratp_link_t *self
,unsigned long timeout_ms
,const uint8_t *buffer
,size_t buffer_size
,ratp_link_send_ready_func callback
,void *user_data
);
Schedules the data in buffer
to be sent. If the link is not yet established,
it will be sent as soon as the establishment is finished.
When all the data is sent and acknowledged by the peer, or if any error
happens (timeout included), callback
will be called to inform the user of
the operation result.
self |
a ratp_link_t. |
[in][not nullable] |
timeout_ms |
(in) maximum time, in milliseconds, to send the whole |
|
buffer |
data to send through the link. |
[in][array length=buffer_size][not nullable] |
buffer_size |
size of |
[in] |
callback |
[in][nullable] | |
user_data |
user data to be passed to |
[in][nullable] |
void (*ratp_link_receive_ready_func) (ratp_link_t *self
,const uint8_t *buffer
,size_t buffer_size
,void *user_data
);
Handler used to report data received to the user.
self |
a ratp_link_t. |
[in][not nullable] |
buffer |
data received through the link. |
[in][array length=buffer_size][not nullable] |
buffer_size |
size of |
[in] |
user_data |
user data given by the user when registering the callback. |
[in][nullable] |
void ratp_link_set_receive_callback (ratp_link_t *self
,ratp_link_receive_ready_func callback
,void *user_data
);
Set the callback to be called when data is received in the RATP link.
self |
a ratp_link_t. |
[in][not nullable] |
callback |
[in][nullable] | |
user_data |
user data to be passed to |
[in][nullable] |