Communication Channel

LibOSDP uses a _channel_ communicate with the devices. It is upto the users to define a channel and pass it to osdp_{cp,pd}_setup() method. A cahnnel is defined as:

struct osdp_channel {
    void *data;
    int id;
    read_fn_t recv;
    write_fn_t send;
    flush_fn_t flush;
};
struct osdp_channel

User defined communication channel abstraction for OSDP devices. The methods for read/write/flush are expected to be non-blocking.

Public Members

void *data

pointer to a block of memory that will be passed to the send/receive/flush method. This is optional (can be set to NULL)

int id

channel_id; On multi-drop networks, more than one PD can share the same channel (read/write/flush pointers). On such networks, the channel_id is used to lock a PD to a channel. On multi-drop networks, this id must non-zero and be unique for each bus.

osdp_read_fn_t recv

Pointer to function used to receive osdp packet data

osdp_write_fn_t send

Pointer to function used to send osdp packet data

osdp_flush_fn_t flush

Pointer to function used to flush the channel (optional)

typedef int (*osdp_write_fn_t)(void *data, uint8_t *buf, int len)

pointer to function that sends byte array into some channel. This function should be non-blocking.

Note

For now, LibOSDP expects method to write/queue all or no bytes over the channel per-invocation; ie., it does not support partial writes and is a known limitation. Since an OSDP packet isn’t so large, and typical TX buffers are much larger than that, it’s not as bad as it sounds and hence not on the priority list to be fixed.

Param data:

for use by underlying layers. osdp_channel::data is passed

Param buf:

byte array to be sent

Param len:

number of bytes in buf

Retval +ve:

number of bytes sent. must be <= len

Retval -ve:

on errors

typedef int (*osdp_read_fn_t)(void *data, uint8_t *buf, int maxlen)

pointer to function that copies received bytes into buffer. This function should be non-blocking.

Param data:

for use by underlying layers. osdp_channel::data is passed

Param buf:

byte array copy incoming data

Param maxlen:

sizeof buf. Can copy utmost maxlen bytes into buf

Retval +ve:

number of bytes copied on to buf. Must be <= len

Retval -ve:

on errors

typedef void (*osdp_flush_fn_t)(void *data)

pointer to function that drops all bytes in TX/RX fifo. This function should be non-blocking.

Param data:

for use by underlying layers. osdp_channel::data is passed