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 abstaction for OSDP devices. The methods for read/write/flush are expected to be non-blocking.

param 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)

param 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.

param recv

Pointer to function used to receive osdp packet data

param send

Pointer to function used to send osdp packet data

param 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.

Parameters
  • data – for use by underlying layers. osdp_channel::data is passed

  • buf – byte array to be sent

  • len – number of bytes in buf

Returns

  • +ve – number of bytes sent. must be <= len

  • -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.

Parameters
  • data – for use by underlying layers. osdp_channel::data is passed

  • buf – byte array copy incoming data

  • len – sizeof buf. Can copy utmost len bytes into buf

Returns

  • +ve – number of bytes copied on to buf. Must be <= len

  • -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.

Parameters

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