LwPKT
- group LWPKT
Lightweight packet protocol.
Defines
-
lwpkt_get_from_addr(pkt)
Get address from where packet was sent.
- Parameters
pkt – [in] LwPKT instance
- Returns
Address
-
lwpkt_get_to_addr(pkt)
Get address to where packet was sent.
- Parameters
pkt – [in] LwPKT instance
- Returns
Address
-
lwpkt_get_data_len(pkt)
Get length of packet.
- Parameters
pkt – [in] LwPKT instance
- Returns
Number of data bytes in packet
-
lwpkt_get_data(pkt)
Get pointer to packet data.
- Parameters
pkt – [in] LwPKT instance
- Returns
Pointer to data
-
lwpkt_get_cmd(pkt)
Get packet command data field.
- Parameters
pkt – [in] LwPKT instance
- Returns
Command data field
-
lwpkt_is_for_me(pkt)
Check if packet
to
field address matches device address.- Parameters
pkt – [in] LwPKT instance
- Returns
1
on success,0
otherwise
-
lwpkt_is_broadcast(pkt)
Check if packet was sent to all devices on network.
- Parameters
pkt – [in] LwPKT instance
- Returns
1
if broadcast,0
otherwise
Typedefs
-
typedef void (*lwpkt_evt_fn)(struct lwpkt *pkt, lwpkt_evt_type_t evt_type)
Event function prototype.
- Param pkt
[in] Packet structure
- Param evt_type
[in] Event type
-
typedef uint32_t lwpkt_addr_t
Device address data type.
Enums
-
enum lwpkt_state_t
Packet state enumeration.
Values:
-
enumerator LWPKT_STATE_START = 0x00
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 LWPKT_STATE_START = 0x00
-
enum lwpktr_t
Packet result enumeration.
Values:
-
enumerator lwpktOK = 0x00
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 lwpktERRMEM
No enough memory available for write
-
enumerator lwpktOK = 0x00
-
enum lwpkt_evt_type_t
List of event types.
Values:
-
enumerator LWPKT_EVT_PKT
Valid packet ready to read
-
enumerator LWPKT_EVT_TIMEOUT
Timeout on packat, reset event
-
enumerator LWPKT_EVT_READ
Packet read operation. Called when read operation happens from RX buffer
-
enumerator LWPKT_EVT_WRITE
Packet write operation. Called when write operation happens to TX buffer
-
enumerator LWPKT_EVT_PRE_WRITE
Packet pre-write operation. Called before write operation could even start. It can be used to get exclusive mutex access to the resource
-
enumerator LWPKT_EVT_POST_WRITE
Packet post-write operation. Called after write operation finished. It can be used to release exclusive mutex access from the resource
-
enumerator LWPKT_EVT_PRE_READ
Packet pre-read operation. Called before read operation could even start. It can be used to get exclusive mutex access to the resource
-
enumerator LWPKT_EVT_POST_READ
Packet post-read operation. Called after read operation finished. It can be used to release exclusive mutex access from the resource
-
enumerator LWPKT_EVT_PKT
Functions
-
lwpktr_t lwpkt_init(lwpkt_t *pkt, lwrb_t *tx_rb, 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.
- Parameters
pkt – [in] Packet instance
- Returns
lwpktVALID when packet valid, member of lwpktr_t otherwise
-
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.
-
struct lwpkt_crc_t
- #include <lwpkt.h>
CRC structure for packet.
Public Members
-
uint8_t crc
Current CRC value
-
uint8_t crc
-
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_t *tx_rb
TX ringbuffer
-
lwrb_t *rx_rb
RX ringbuffer
-
uint32_t last_rx_time
Last RX time in units of milliseconds
-
lwpkt_evt_fn evt_fn
Global event function for read and write operation
-
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 addr
-
lwpkt_get_from_addr(pkt)