tinyproto
|
Classes | |
struct | tiny_fd_init_t_ |
This structure is used for initialization of Tiny Full Duplex protocol. More... | |
class | tinyproto::IFd |
IFd class incapsulates Full Duplex Protocol functionality. More... | |
Macros | |
#define | TINY_FD_PRIMARY_ADDR (0) |
Address of primary stations to use with the protocol. More... | |
Typedefs | |
typedef struct tiny_fd_data_t * | tiny_fd_handle_t |
This handle points to service data, required for full-duplex functioning. | |
typedef void(* | tiny_fd_log_frame_cb_t) (void *udata, tiny_fd_handle_t handle, tiny_fd_frame_direction_t direction, tiny_fd_frame_type_t frame_type, tiny_fd_frame_subtype_t frame_subtype, uint8_t ns, uint8_t nr, const uint8_t *data, int len) |
tiny_fd_log_frame_cb_t is a callback function, which is called every time frame is sent or received. More... | |
typedef struct tiny_fd_init_t_ | tiny_fd_init_t |
This structure is used for initialization of Tiny Full Duplex protocol. | |
Enumerations | |
enum | { TINY_FD_MODE_ABM = 0x00, TINY_FD_MODE_NRM = 0x01, TINY_FD_MODE_ARM = 0x02 } |
enum | tiny_fd_frame_type_t { TINY_FD_FRAME_TYPE_I = 0x00, TINY_FD_FRAME_TYPE_S = 0x01, TINY_FD_FRAME_TYPE_U = 0x02 } |
Enumeration of frame types used in Tiny Full Duplex protocol. More... | |
enum | tiny_fd_frame_subtype_t { TINY_FD_FRAME_SUBTYPE_RR = 0x00, TINY_FD_FRAME_SUBTYPE_REJ = 0x08, TINY_FD_FRAME_SUBTYPE_UA = 0x60, TINY_FD_FRAME_SUBTYPE_FRMR = 0x84, TINY_FD_FRAME_SUBTYPE_RSET = 0x8C, TINY_FD_FRAME_SUBTYPE_SABM = 0x2C, TINY_FD_FRAME_SUBTYPE_SNRM = 0x80, TINY_FD_FRAME_SUBTYPE_DISC = 0x40 } |
Enumeration of frame subtypes used in Tiny Full Duplex protocol. More... | |
enum | tiny_fd_frame_direction_t { TINY_FD_FRAME_DIRECTION_IN = 0x00, TINY_FD_FRAME_DIRECTION_OUT = 0x01 } |
Enumeration of frame directions used in Tiny Full Duplex protocol. More... | |
Functions | |
int | tiny_fd_init (tiny_fd_handle_t *handle, tiny_fd_init_t *init) |
Initialized communication for Tiny Full Duplex protocol. More... | |
int | tiny_fd_get_status (tiny_fd_handle_t handle) |
Returns status of the connection. More... | |
int | tiny_fd_disconnect (tiny_fd_handle_t handle) |
Sends DISC command to remote side. More... | |
void | tiny_fd_close (tiny_fd_handle_t handle) |
stops Tiny Full Duplex state machine More... | |
int | tiny_fd_get_tx_data (tiny_fd_handle_t handle, void *data, int len, uint32_t timeout) |
runs tx processing to fill specified buffer with data. More... | |
int | tiny_fd_run_tx (tiny_fd_handle_t handle, write_block_cb_t write_func) |
sends tx data to the communication channel via user callback write_func() . More... | |
int | tiny_fd_on_rx_data (tiny_fd_handle_t handle, const void *data, int len) |
runs rx bytes processing for specified buffer. More... | |
int | tiny_fd_run_rx (tiny_fd_handle_t handle, read_block_cb_t read_func) |
reads rx data from the communication channel via user callback read_func() More... | |
int | tiny_fd_send_packet_to (tiny_fd_handle_t handle, uint8_t address, const void *buf, int len, uint32_t timeout) |
Sends userdata over full-duplex protocol. More... | |
int | tiny_fd_buffer_size_by_mtu (int mtu, int window) |
Returns minimum required buffer size for specified parameters. More... | |
int | tiny_fd_buffer_size_by_mtu_ex (uint8_t peers_count, int mtu, int tx_window, hdlc_crc_t crc_type, int rx_window) |
Returns minimum required buffer size for specified parameters. More... | |
int | tiny_fd_get_mtu (tiny_fd_handle_t handle) |
returns max packet size in bytes. More... | |
int | tiny_fd_send_to (tiny_fd_handle_t handle, uint8_t address, const void *buf, int len, uint32_t timeout) |
Sends userdata over full-duplex protocol. More... | |
void | tiny_fd_set_ka_timeout (tiny_fd_handle_t handle, uint32_t keep_alive) |
Sets keep alive timeout in milliseconds. More... | |
int | tiny_fd_register_peer (tiny_fd_handle_t handle, uint8_t address) |
Registers remote peer with specified address. More... | |
int | tiny_fd_send (tiny_fd_handle_t handle, const void *buf, int len, uint32_t timeout) |
Sends userdata over full-duplex protocol to primary station. More... | |
int | tiny_fd_send_packet (tiny_fd_handle_t handle, const void *buf, int len, uint32_t timeout) |
Sends packet to primary station. More... | |
#define TINY_FD_PRIMARY_ADDR (0) |
Address of primary stations to use with the protocol.
See RFC.
typedef void(* tiny_fd_log_frame_cb_t) (void *udata, tiny_fd_handle_t handle, tiny_fd_frame_direction_t direction, tiny_fd_frame_type_t frame_type, tiny_fd_frame_subtype_t frame_subtype, uint8_t ns, uint8_t nr, const uint8_t *data, int len) |
tiny_fd_log_frame_cb_t is a callback function, which is called every time frame is sent or received.
This callback is useful for debugging purposes.
The main difference between this callback and on_frame_read_cb_t / on_frame_send_cb_t is that this callback is called for every frame, regardless of whether it is sent or received: I-frames, S-frames or U-frames. It provides detailed information about the frame, including its type, subtype, sequence numbers and data.
udata | user data, passed during Tiny Full Duplex initialization. |
handle | handle of Tiny. |
direction | direction of the frame, can be TINY_FD_FRAME_DIRECTION_IN or TINY_FD_FRAME_DIRECTION_OUT. |
frame_type | type of the frame, can be TINY_FD_FRAME_TYPE_I, TINY_FD_FRAME_TYPE_S or TINY_FD_FRAME_TYPE_U. |
frame_subtype | subtype of the frame, can be TINY_FD_FRAME_SUBTYPE_RR, TINY_FD_FRAME_SUBTYPE_REJ, TINY_FD_FRAME_SUBTYPE_UA, TINY_FD_FRAME_SUBTYPE_FRMR, TINY_FD_FRAME_SUBTYPE_RSET, TINY_FD_FRAME_SUBTYPE_SABM, TINY_FD_FRAME_SUBTYPE_SNRM or TINY_FD_FRAME_SUBTYPE_DISC. |
ns | N(S) sequence number of the frame. |
nr | N(R) sequence number of the frame. |
data | pointer to the frame data. |
len | length of the frame data. |
anonymous enum |
Enumeration of frame subtypes used in Tiny Full Duplex protocol.
These subtypes are used for S-frames and U-frames. The I-frames do not have subtypes, so this enumeration is not used for I-frames.
enum tiny_fd_frame_type_t |
int tiny_fd_buffer_size_by_mtu | ( | int | mtu, |
int | window | ||
) |
Returns minimum required buffer size for specified parameters.
mtu | size of desired user payload in bytes. |
window | maximum tx queue size of I-frames. |
int tiny_fd_buffer_size_by_mtu_ex | ( | uint8_t | peers_count, |
int | mtu, | ||
int | tx_window, | ||
hdlc_crc_t | crc_type, | ||
int | rx_window | ||
) |
Returns minimum required buffer size for specified parameters.
peers_count | maximum number of peers supported by the primary. Use 0 or 1 for secondary devices |
mtu | size of desired user payload in bytes. |
tx_window | maximum tx queue size of I-frames. |
crc_type | crc type to be used with FD protocol |
rx_window | number of RX ring buffer in frames |
void tiny_fd_close | ( | tiny_fd_handle_t | handle | ) |
stops Tiny Full Duplex state machine
stops Tiny Full Duplex state machine.
handle | handle of full-duplex protocol |
int tiny_fd_disconnect | ( | tiny_fd_handle_t | handle | ) |
Sends DISC command to remote side.
The function sends DISC command to remote side and exits. It doesn't wait for UA answer back.
handle | pointer to Tiny Full Duplex data |
int tiny_fd_get_mtu | ( | tiny_fd_handle_t | handle | ) |
returns max packet size in bytes.
Returns max packet size in bytes.
handle | tiny_fd_handle_t handle |
int tiny_fd_get_status | ( | tiny_fd_handle_t | handle | ) |
Returns status of the connection.
The function returns status of the connection
handle | pointer to Tiny Full Duplex data |
int tiny_fd_get_tx_data | ( | tiny_fd_handle_t | handle, |
void * | data, | ||
int | len, | ||
uint32_t | timeout | ||
) |
runs tx processing to fill specified buffer with data.
Runs tx processing to fill specified buffer with data.
handle | handle of full-duplex protocol |
data | pointer to buffer to fill with tx data |
len | maximum size of specified buffer |
timeout | in milliseconds to wait for the data to be ready for sending |
int tiny_fd_init | ( | tiny_fd_handle_t * | handle, |
tiny_fd_init_t * | init | ||
) |
Initialized communication for Tiny Full Duplex protocol.
The function initializes internal structures for Tiny Full Duplex state machine.
handle | - pointer to Tiny Full Duplex data |
init | - pointer to tiny_fd_init_t data. |
int tiny_fd_on_rx_data | ( | tiny_fd_handle_t | handle, |
const void * | data, | ||
int | len | ||
) |
runs rx bytes processing for specified buffer.
Runs rx bytes processing for specified buffer. This is alternative method to run Full-duplex protocol for rx data. Use it, when you wish to control reading from hardware by yourself.
handle | handle of full-duplex protocol |
data | pointer to data to process |
len | length of data to process |
int tiny_fd_register_peer | ( | tiny_fd_handle_t | handle, |
uint8_t | address | ||
) |
Registers remote peer with specified address.
This API can be used only in NRM mode on primary station. The allowable range of the addresses is 1 - 62. The addresses 0, 63 cannot be used as they are dedicated to primary station and legacy support. After secondary station is registered, the primary will send establish connection to remote station. If remote station is not yet ready, this can cause reducing of the primary station performance.
handle | pointer to tiny_fd_handle_t |
address | address in range 1 - 62. |
int tiny_fd_run_rx | ( | tiny_fd_handle_t | handle, |
read_block_cb_t | read_func | ||
) |
reads rx data from the communication channel via user callback read_func()
Reads rx data from the communication channel via user callback read_func()
. Internally this function has 4-byte buffer, and tries to read 4 bytes from the channel. Then received bytes are processed by the protocol. If FD protocol detects new incoming message then it calls on_send_callback. If no data available in the channel, the function returns immediately after read_func() callback returns control.
handle | handle of full-duplex protocol |
read_func | callback to the function to read data from the physical channel. |
int tiny_fd_run_tx | ( | tiny_fd_handle_t | handle, |
write_block_cb_t | write_func | ||
) |
sends tx data to the communication channel via user callback write_func()
.
Sends tx data to the communication channel via user callback write_func()
. Internally this function generates next 4 bytes to send (or less if nothing to send), and calls user callback write_func() until all generated bytes are sent, or error happens. This function helps to simplify application code.
handle | handle of full-duplex protocol |
write_func | callback to the function to write data to the physical channel. |
int tiny_fd_send | ( | tiny_fd_handle_t | handle, |
const void * | buf, | ||
int | len, | ||
uint32_t | timeout | ||
) |
Sends userdata over full-duplex protocol to primary station.
Sends userdata over full-duplex protocol to primary station. For details, please, refer to tiny_fd_send_to().
handle | tiny_fd_handle_t handle |
buf | data to send |
len | length of data to send |
timeout | timeout in milliseconds, will be used for each block sending |
int tiny_fd_send_packet | ( | tiny_fd_handle_t | handle, |
const void * | buf, | ||
int | len, | ||
uint32_t | timeout | ||
) |
Sends packet to primary station.
For details, please, refer to tiny_fd_send_packet_to().
handle | tiny_fd_handle_t handle |
buf | data to send |
len | length of data to send |
timeout | timeout in milliseconds to wait until data are placed to outgoing queue |
int tiny_fd_send_packet_to | ( | tiny_fd_handle_t | handle, |
uint8_t | address, | ||
const void * | buf, | ||
int | len, | ||
uint32_t | timeout | ||
) |
Sends userdata over full-duplex protocol.
Sends userdata over full-duplex protocol. Note, that this command will return success, when data are copied to internal queue. That doesn't mean that data are physically sent, but they are enqueued for sending.
When timeout happens, the data were not actually enqueued. Call this function once again. If TINY_ERR_DATA_TOO_LARGE is returned, try to send less data. If you don't want to care about mtu size, please, use different function tiny_fd_send()..
handle | tiny_fd_handle_t handle |
address | address of remote peer. For primary device, please use TINY_FD_PRIMARY_ADDR |
buf | data to send |
len | length of data to send |
timeout | timeout in milliseconds to wait until data are placed to outgoing queue |
int tiny_fd_send_to | ( | tiny_fd_handle_t | handle, |
uint8_t | address, | ||
const void * | buf, | ||
int | len, | ||
uint32_t | timeout | ||
) |
Sends userdata over full-duplex protocol.
Sends userdata over full-duplex protocol. Note, that this function will try to send all data from buf. In success case it will return number of bytes sent, equal to len input parameter. But if timeout happens, it returns number of bytes actually enqueued.
If you constantly get number of sent bytes less than expected, try to increase timeout value of the speed of used communication channel.
handle | tiny_fd_handle_t handle |
address | address of remote peer. For primary device, please use TINY_FD_PRIMARY_ADDR |
buf | data to send |
len | length of data to send |
timeout | timeout in milliseconds, will be used for each block sending |
void tiny_fd_set_ka_timeout | ( | tiny_fd_handle_t | handle, |
uint32_t | keep_alive | ||
) |
Sets keep alive timeout in milliseconds.
This timeout is used to send special RR frames, when no user data queued for sending.
handle | pointer to tiny_fd_handle_t |
keep_alive | timeout in milliseconds |