LwPKT¶
-
group
LWPKT Lightweight packet protocol.
Defines
-
lwpkt_get_from_addr(pkt)¶ Get address from where packet was sent.
- Return
Address
- Parameters
[in] pkt: LwPKT instance
-
lwpkt_get_to_addr(pkt)¶ Get address to where packet was sent.
- Return
Address
- Parameters
[in] pkt: LwPKT instance
-
lwpkt_get_data_len(pkt)¶ Get length of packet.
- Return
Number of data bytes in packet
- Parameters
[in] pkt: LwPKT instance
-
lwpkt_get_data(pkt)¶ Get pointer to packet data.
- Return
Pointer to data
- Parameters
[in] pkt: LwPKT instance
-
lwpkt_get_cmd(pkt)¶ Get packet command data field.
- Return
Command data field
- Parameters
[in] pkt: LwPKT instance
-
lwpkt_is_for_me(pkt)¶ Check if packet
tofield address matches device address.- Return
1on success,0otherwise- Parameters
[in] pkt: LwPKT instance
-
lwpkt_is_broadcast(pkt)¶ Check if packet was sent to all devices on network.
- Return
1if broadcast,0otherwise- Parameters
[in] pkt: LwPKT instance
Typedefs
-
typedef uint32_t
lwpkt_addr_t¶ Device address data type.
-
typedef void (*
lwpkt_evt_fn)(lwpkt_t *pkt, lwpkt_evt_type_t type)¶ LwPKT event function.
- Parameters
[in] pkt: LwPKT instance with valid packet[in] type: Event type
Enums
-
enum
lwpkt_state_t¶ Packet state enumeration.
Values:
-
enumerator
LWPKT_STATE_START¶ Packet waits for start byte
-
enumerator
LWPKT_STATE_FROM¶ Packet waits for “packet from” byte
-
enumerator
LWPKT_STATE_TO¶ Packet waits for “packet to” byte
-
enumerator
LWPKT_STATE_CMD¶ Packet waits for “packet cmd” byte
-
enumerator
LWPKT_STATE_LEN¶ Packet waits for (multiple) data length bytes
-
enumerator
LWPKT_STATE_DATA¶ Packet waits for actual data bytes
-
enumerator
LWPKT_STATE_CRC¶ Packet waits for CRC data
-
enumerator
LWPKT_STATE_STOP¶ Packet waits for stop byte
-
enumerator
-
enum
lwpktr_t¶ Packet result enumeration.
Values:
-
enumerator
lwpktOK¶ Function returns successfully
-
enumerator
lwpktERR¶ General error for function status
-
enumerator
lwpktINPROG¶ Receive is in progress
-
enumerator
lwpktVALID¶ packet valid and ready to be read as CRC is valid and STOP received
-
enumerator
lwpktERRCRC¶ CRC integrity error for the packet. Will not wait STOP byte if received
-
enumerator
lwpktERRSTOP¶ Packet error with STOP byte, wrong character received for STOP
-
enumerator
lwpktWAITDATA¶ Packet state is in start mode, waiting start byte to start receiving
-
enumerator
Functions
-
lwpktr_t lwpkt_init (lwpkt_t *pkt, LWRB_VOLATILE lwrb_t *tx_rb, LWRB_VOLATILE lwrb_t *rx_rb) Initialize packet instance and set device address.
-
lwpktr_t
lwpkt_set_addr(lwpkt_t *pkt, lwpkt_addr_t addr)¶ Set device address for packet instance.
-
lwpktr_t
lwpkt_read(lwpkt_t *pkt)¶ Read raw data from RX buffer and prepare packet.
- Return
lwpktVALID when packet valid, member of lwpktr_t otherwise
- Parameters
[in] pkt: Packet instance
-
lwpktr_t
lwpkt_write(lwpkt_t *pkt, lwpkt_addr_t to, uint8_t cmd, const void *data, size_t len)¶ Write packet data to TX ringbuffer.
-
lwpktr_t
lwpkt_process(lwpkt_t *pkt, uint32_t time, lwpkt_evt_fn evt_fn)¶ Process packet instance and read new data.
-
struct
lwpkt_crc_t¶ - #include <lwpkt.h>
CRC structure for packet.
Public Members
-
uint8_t
crc¶ Current CRC value
-
uint8_t
-
struct
lwpkt_t¶ - #include <lwpkt.h>
Packet structure.
Public Members
-
lwpkt_addr_t
addr¶ Current device address
-
uint8_t
data[LWPKT_CFG_MAX_DATA_LEN]¶ Memory to write received data
-
LWRB_VOLATILE lwrb_t * tx_rb TX ringbuffer
-
LWRB_VOLATILE lwrb_t * rx_rb RX ringbuffer
-
uint32_t
last_rx_time¶ Last RX time in units of milliseconds
-
lwpkt_state_t
state¶ Actual packet state machine
-
lwpkt_crc_t
crc¶ Packet CRC byte
-
lwpkt_addr_t
from¶ Device address packet is coming from
-
lwpkt_addr_t
to¶ Device address packet is intended for
-
uint8_t
cmd¶ Command packet
-
size_t
len¶ Number of bytes to receive
-
size_t
index¶ General index variable for multi-byte parts of packet
-
lwpkt_addr_t
-