LwPKT branch-0133920 documentation

Welcome to the documentation for version branch-0133920.

LwPKT is a generic packet protocol library optimized for embedded systems.

_images/logo.svg

Features

  • Written in ANSI C99, compatible with size_t for size data types

  • Platform independent, no architecture specific code

  • Uses LwRB library for data read/write operations

  • Support for events on packet ready, read or write operation

  • Optimized for embedded systems, allows high optimization for data transfer

  • Configurable settings for packet structure and variable data length

  • Allows multiple notes in network with from and to addresses

  • Separate optional field for command data type

  • Variable data length to support theoretically unlimited packet length

  • CRC check to handle data transmission errors

  • User friendly MIT license

Requirements

  • C compiler

  • Few kB of non-volatile memory

Contribute

Fresh contributions are always welcome. Simple instructions to proceed:

  1. Fork Github repository

  2. Respect C style & coding rules used by the library

  3. Create a pull request to develop branch with new features or bug fixes

Alternatively you may:

  1. Report a bug

  2. Ask for a feature request

License

MIT License

Copyright (c) 2020 Tilen MAJERLE

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

Table of contents

Getting started

Getting started may be the most challenging part of every new library. This guide is describing how to start with the library quickly and effectively

Download library

Library is primarly hosted on Github.

You can get it with:

  • Downloading latest release from releases area on Github

  • Cloning master branch for latest stable version

  • Cloning develop branch for latest development

Download from releases

All releases are available on Github releases area.

Clone from Github
First-time clone

This is used when you do not have yet local copy on your machine.

  • Make sure git is installed.

  • Open console and navigate to path in the system to clone repository to. Use command cd your_path

  • Clone repository with one of available 3 options

    • Run git clone --recurse-submodules https://github.com/MaJerle/lwpkt command to clone entire repository, including submodules

    • Run git clone --recurse-submodules --branch develop https://github.com/MaJerle/lwpkt to clone development branch, including submodules

    • Run git clone --recurse-submodules --branch master https://github.com/MaJerle/lwpkt to clone latest stable branch, including submodules

  • Navigate to examples directory and run favourite example

Update cloned to latest version
  • Open console and navigate to path in the system where your resources repository is. Use command cd your_path

  • Run git pull origin master --recurse-submodules command to pull latest changes and to fetch latest changes from submodules on master branch

  • Run git pull origin develop --recurse-submodules command to pull latest changes and to fetch latest changes from submodules on develop branch

  • Run git submodule foreach git pull origin master to update & merge all submodules

Note

This is preferred option to use when you want to evaluate library and run prepared examples. Repository consists of multiple submodules which can be automatically downloaded when cloning and pulling changes from root repository.

Add library to project

At this point it is assumed that you have successfully download library, either cloned it or from releases page. Next step is to add the library to the project, by means of source files to compiler inputs and header files in search path

  • Copy lwpkt folder to your project, it contains library files

  • Add lwpkt/src/include folder to include path of your toolchain. This is where C/C++ compiler can find the files during compilation process. Usually using -I flag

  • Add source files from lwpkt/src/ folder to toolchain build. These files are built by C/C++ compiler

  • Copy lwpkt/src/include/lwpkt/lwpkt_opts_template.h to project folder and rename it to lwpkt_opts.h

  • Build the project

Configuration file

Configuration file is used to overwrite default settings defined for the essential use case. Library comes with template config file, which can be modified according to needs. and it should be copied (or simply renamed in-place) and named lwpkt_opts.h

Note

Default configuration template file location: lwpkt/src/include/lwpkt/lwpkt_opts_template.h. File must be renamed to lwpkt_opts.h first and then copied to the project directory where compiler include paths have access to it by using #include "lwpkt_opts.h".

List of configuration options are available in the Configuration section. If any option is about to be modified, it should be done in configuration file

Template configuration file
 1/**
 2 * \file            lwpkt_opts_template.h
 3 * \brief           LwPKT configuration file
 4 */
 5
 6/*
 7 * Copyright (c) 2020 Tilen MAJERLE
 8 *
 9 * Permission is hereby granted, free of charge, to any person
10 * obtaining a copy of this software and associated documentation
11 * files (the "Software"), to deal in the Software without restriction,
12 * including without limitation the rights to use, copy, modify, merge,
13 * publish, distribute, sublicense, and/or sell copies of the Software,
14 * and to permit persons to whom the Software is furnished to do so,
15 * subject to the following conditions:
16 *
17 * The above copyright notice and this permission notice shall be
18 * included in all copies or substantial portions of the Software.
19 *
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
22 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
23 * AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
24 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
25 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
27 * OTHER DEALINGS IN THE SOFTWARE.
28 *
29 * This file is part of LwPKT - Lightweight packet protocol library.
30 *
31 * Author:          Tilen MAJERLE <tilen@majerle.eu>
32 * Version:         v1.2.0
33 */
34#ifndef LWPKT_HDR_OPTS_H
35#define LWPKT_HDR_OPTS_H
36
37/* Rename this file to "lwpkt_opts.h" for your application */
38
39/*
40 * Open "include/lwpkt/lwpkt_opt.h" and
41 * copy & replace here settings you want to change values
42 */
43
44#endif /* LWPKT_HDR_OPTS_H */

Note

If you prefer to avoid using configuration file, application must define a global symbol LWPKT_IGNORE_USER_OPTS, visible across entire application. This can be achieved with -D compiler option.

Minimal example code

To verify proper library setup, minimal example has been prepared. Run it in your main application file to verify its proper execution

Absolute minimum example
  1#include <stdio.h>
  2#include "lwpkt/lwpkt.h"
  3
  4/* LwPKT data */
  5static lwpkt_t pkt;
  6static lwrb_t pkt_tx_rb, pkt_rx_rb;
  7static uint8_t pkt_tx_rb_data[64], pkt_rx_rb_data[64];
  8
  9/* Data to read and write */
 10static const char* data = "Hello World\r\n";
 11
 12/**
 13 * \brief           LwPKT example code
 14 */
 15void
 16example_lwpkt(void) {
 17    lwpktr_t res;
 18    uint8_t b;
 19
 20    printf("---\r\nLwPKT default example..\r\n\r\n");
 21
 22    /* 
 23     * Initialize both ring buffers, for TX and RX operations
 24     *
 25     * Initialize LwPKT and link buffers together
 26     */
 27    lwrb_init(&pkt_tx_rb, pkt_tx_rb_data, sizeof(pkt_tx_rb_data));
 28    lwrb_init(&pkt_rx_rb, pkt_rx_rb_data, sizeof(pkt_rx_rb_data));
 29    lwpkt_init(&pkt, &pkt_tx_rb, &pkt_rx_rb);
 30
 31#if LWPKT_CFG_USE_ADDR
 32    /* Set device address (if feature enabled) */
 33    lwpkt_set_addr(&pkt, 0x12);
 34#endif /* LWPKT_CFG_USE_ADDR */
 35
 36    /* 
 37     * Write packet to the TX ringbuffer,
 38     * act as device wants to send some data
 39     */
 40    res = lwpkt_write(&pkt,
 41#if LWPKT_CFG_USE_ADDR
 42        0x11,                       /* End address to whom to send */
 43#endif /* LWPKT_CFG_USE_ADDR */
 44#if LWPKT_CFG_USE_CMD
 45        0x85,                       /* Command type */
 46#endif /* LWPKT_CFG_USE_CMD */
 47        data, strlen(data));        /* Length of data and actual data */
 48
 49    /*
 50     * LwPKT wrote data to pkt_tx_rb ringbuffer
 51     * Now actually transmit data over your interface
 52     * (USART for example, ...)
 53     */
 54
 55    /*
 56     * For the purpose of this example, application will
 57     * fake data transmission by doing reading from TX buffer
 58     * and writing it to RX buffer
 59     */
 60    while (lwrb_read(&pkt_tx_rb, &b, 1) == 1) {
 61        lwrb_write(&pkt_rx_rb, &b, 1);
 62    }
 63
 64    /*
 65     * Here we have our data in RX buffer
 66     * means we received data over network interface
 67     */
 68
 69    /* Now read and process packet */
 70    res = lwpkt_read(&pkt);
 71
 72    if (res == lwpktVALID) {
 73        size_t len;
 74
 75        /* Packet is valid */
 76        printf("Packet is valid!\r\n");
 77
 78        /* Print debug messages for packet */
 79#if LWPKT_CFG_USE_ADDR
 80        printf("Packet from: 0x%08X\r\n", (unsigned)lwpkt_get_from_addr(&pkt));
 81        printf("Packet to: 0x%08X\r\n", (unsigned)lwpkt_get_to_addr(&pkt));
 82#endif /* LWPKT_CFG_USE_ADDR */
 83#if LWPKT_CFG_USE_CMD
 84        printf("Packet cmd: 0x%02X\r\n", (unsigned)lwpkt_get_cmd(&pkt));
 85#endif /* LWPKT_CFG_USE_CMD */
 86        printf("Packet data length: 0x%08X\r\n", (unsigned)lwpkt_get_data_len(&pkt));
 87        if ((len = lwpkt_get_data_len(&pkt)) > 0) {
 88            uint8_t* d = lwpkt_get_data(&pkt);
 89            printf("Packet data: ");
 90            for (size_t i = 0; i < len; ++i) {
 91                printf("0x%02X ", (unsigned)d[i]);
 92            }
 93            printf("\r\n");
 94        }
 95
 96        /* Check who should be dedicated receiver */
 97#if LWPKT_CFG_USE_ADDR
 98        if (lwpkt_is_for_me(&pkt)) {
 99            printf("Packet is for me\r\n");
100        } else if (lwpkt_is_broadcast(&pkt)) {
101            printf("Packet is broadcast to all devices\r\n");
102        } else {
103            printf("Packet is for device ID: 0x%08X\r\n", (unsigned)lwpkt_get_to_addr(&pkt));
104        }
105#endif /* LWPKT_CFG_USE_ADDR */
106    } else if (res == lwpktINPROG) {
107        printf("Packet is still in progress, did not receive yet all bytes..\r\n");
108    } else {
109        printf("Packet is not valid!\r\n");
110    }
111}

User manual

LwPKT protocol library is a simple state-machine parser and raw data generator to allow 2 or more devices in a network to communicate in a structure way.

It is perfectly suitable for communication in embedded systems, suchs as RS-485, where multiple devices could be easily connected to one big network.

LwPKT library uses well known and easy implementation of LwRB library for data read and data write. It expects 2 different buffer instances.

Parser is simple state machine that reads and processes every received character from read buffer. When application wants to transmit data, LwPKT library generates raw data and writes them to TX buffer.

Combination of both gives embedded applications freedom to implement communication protocols for TX and RX.

Packet structure

Packet structure consists of several fields, where some are optional and some are mandatory.

Default packet structure

Default packet structure

  • START: Byte with fixed value to represent start of packet

  • FROM: Byte(s) from where this packet is coming from. Optional field, can be disabled with LWPKT_CFG_USE_ADDR

  • TO: Byte(s) to where this packet is targeting. Optional field, can be disabled with LWPKT_CFG_USE_ADDR

  • CMD: Byte with optional command field to better align with multiple packets. Optional field, can be disabled with LWPKT_CFG_USE_CMD

  • LEN: Length of data part field. This is variable multi-byte length to support data length >= 256 bytes. Always present

  • DATA: Optional data field. Number of bytes is as in LEN field

  • CRC: 8-bit CRC of all enabled fields except START and STOP bytes. Optional field, can be disabled with LWPKT_CFG_USE_CRC

  • STOP: Byte with fixed value to represent stop of packet

Tip

If only 2 devices are communicating and are in the network, considering disabling LWPKT_CFG_USE_ADDR to improve data bandwidth and remove unnecessary packet overhead

Data input output

LwPKT library only reads and writes to 2 ringbuffers used for read and write operations. It is up to application to implement how buffers are actually later written for read operation and sent out on the network for write operation.

Warning

LwPKT is platform independant and requires final application to actually take care of data being read/written from/to ringbuffers and transferred further over the network

Variable data length

Some fields implement variable data length feature, to optimize data transfer length. Currently supported fields are:

Variable data length is a feature that uses minimum number of bytes to transfer data. It uses 7 LSB bits per byte for actual data, and MSB bit to indicate if there are more bytes coming after. For example, values between 0x00 - 0x7F are codified within single byte, while values between 0x80 - 0x3F require 2 bytes for transfer. To transfer 32-bit variable, minimum 1-byte and maximum 5-bytes are used.

Tip

Data codification is always LSB Byte first.

Event management

LwPKT may operate in event mode, meaning that application receives notifications on different events:

  • New packet has been received

  • Timeout during packet receive

Timeout function is used when network doesn’t transmit all bytes or if data got lost in the middle of transmission. This is to make sure that packet protocol library easily recovers to be able to receive more packets in the future

Warning

To use this feature, application must provide accurate timing in units of milliseconds to be able to properly handle timeout function.

LwPKT example with events
  1#include <stdio.h>
  2#include "lwpkt/lwpkt.h"
  3
  4/* LwPKT data */
  5static lwpkt_t pkt;
  6static lwrb_t pkt_tx_rb, pkt_rx_rb;
  7static uint8_t pkt_tx_rb_data[64], pkt_rx_rb_data[64];
  8
  9/* Data to read and write */
 10static const char* data = "Hello World\r\n";
 11
 12/**
 13 * \brief           LwPKT application callback
 14 */
 15static void
 16my_lwpkt_evt_fn(lwpkt_t* pkt, lwpkt_evt_type_t type) {
 17    switch (type) {
 18        case LWPKT_EVT_PKT: {
 19            printf("Valid packet received..\r\n");
 20
 21            /* Packet is valid */
 22            printf("Packet is valid!\r\n");
 23
 24            /* Print debug messages for packet */
 25#if LWPKT_CFG_USE_ADDR
 26            printf("Packet from: 0x%08X\r\n", (unsigned)lwpkt_get_from_addr(pkt));
 27            printf("Packet to: 0x%08X\r\n", (unsigned)lwpkt_get_to_addr(pkt));
 28#endif /* LWPKT_CFG_USE_ADDR */
 29#if LWPKT_CFG_USE_CMD
 30            printf("Packet cmd: 0x%08X\r\n", (unsigned)lwpkt_get_cmd(pkt));
 31#endif /* LWPKT_CFG_USE_CMD */
 32            printf("Packet data length: 0x%08X\r\n", (unsigned)lwpkt_get_data_len(pkt));
 33
 34            /* Do other thins... */
 35            break;
 36        }
 37        case LWPKT_EVT_TIMEOUT: {
 38            printf("Timeout detected during read operation..\r\n");
 39            break;
 40        }
 41    }
 42}
 43
 44/**
 45 * \brief           LwPKT example code with event feature
 46 */
 47void
 48example_lwpkt_evt(void) {
 49    lwpktr_t res;
 50    uint32_t time;
 51    uint8_t b;
 52
 53    printf("---\r\nLwPKT event type..\r\n\r\n");
 54
 55    /* 
 56     * Initialize both ring buffers, for TX and RX operations
 57     *
 58     * Initialize LwPKT and link buffers together
 59     */
 60    lwrb_init(&pkt_tx_rb, pkt_tx_rb_data, sizeof(pkt_tx_rb_data));
 61    lwrb_init(&pkt_rx_rb, pkt_rx_rb_data, sizeof(pkt_rx_rb_data));
 62    lwpkt_init(&pkt, &pkt_tx_rb, &pkt_rx_rb);
 63
 64#if LWPKT_CFG_USE_ADDR
 65    /* Set device address (if feature enabled) */
 66    lwpkt_set_addr(&pkt, 0x12);
 67#endif /* LWPKT_CFG_USE_ADDR */
 68
 69    /* 
 70     * Write packet to the TX ringbuffer,
 71     * act as device wants to send some data
 72     */
 73    res = lwpkt_write(&pkt,
 74#if LWPKT_CFG_USE_ADDR
 75        0x11,                       /* End address to whom to send */
 76#endif /* LWPKT_CFG_USE_ADDR */
 77#if LWPKT_CFG_USE_CMD
 78        0x85,                       /* Command type */
 79#endif /* LWPKT_CFG_USE_CMD */
 80        data, strlen(data));        /* Length of data and actual data */
 81
 82    /*
 83     * LwPKT wrote data to pkt_tx_rb ringbuffer
 84     * Now actually transmit data over your interface
 85     * (USART for example, ...)
 86     */
 87
 88    /*
 89     * For the purpose of this example, application will
 90     * fake data transmission by doing reading from TX buffer
 91     * and writing it to RX buffer
 92     */
 93    while (lwrb_read(&pkt_tx_rb, &b, 1) == 1) {
 94        lwrb_write(&pkt_rx_rb, &b, 1);
 95    }
 96
 97    /*
 98     * Here we have our data in RX buffer
 99     * means we received data over network interface
100     */
101
102    /* Set callback function */
103    lwpkt_set_evt_fn(&pkt, my_lwpkt_evt_fn);
104
105    /* Now call process function instead */
106    time = 100; /* Get_current_time_in_milliseconds */
107    lwpkt_process(&pkt, time);
108}

API reference

List of all the modules:

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

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

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 lwpktERRMEM

No enough memory available for write

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

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.

Parameters
  • pkt[in] Packet instance

  • tx_rb[in] TX LwRB instance for data write

  • rx_rb[in] RX LwRB instance for data read

Returns

lwpktOK on success, member of lwpktr_t otherwise

lwpktr_t lwpkt_set_addr(lwpkt_t *pkt, lwpkt_addr_t addr)

Set device address for packet instance.

Parameters
  • pkt[in] Packet instance

  • addr[in] New device address

Returns

lwpktOK on success, member of lwpktr_t otherwise

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.

Parameters
  • pkt[in] Packet instance

  • to[in] End device address

  • cmd[in] Packet command

  • data[in] Pointer to input data. Set to NULL if not used

  • len[in] Length of input data. Must be set to 0 if data == NULL

Returns

lwpktOK on success, member of lwpktr_t otherwise

lwpktr_t lwpkt_reset(lwpkt_t *pkt)

Reset packet state.

Parameters

pkt[in] Packet instance

Returns

lwpktOK on success, member of lwpktr_t otherwise

lwpktr_t lwpkt_process(lwpkt_t *pkt, uint32_t time)

Process packet instance and read new data.

Parameters
  • pkt[in] Packet instance

  • time[in] Current time in units of milliseconds

Returns

lwpktOK if processing OK, member of lwpktr_t otherwise

lwpktr_t lwpkt_set_evt_fn(lwpkt_t *pkt, lwpkt_evt_fn evt_fn)

Set event function for packet events.

Parameters
  • pkt[in] Packet structure

  • evt_fn[in] Function pointer for events

Returns

lwpktOK on success, member of lwpktr_t otherwise

struct lwpkt_crc_t
#include <lwpkt.h>

CRC structure for packet.

Public Members

uint8_t crc

Current CRC value

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_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

struct lwpkt_t::[anonymous] m

Module that is periodically reset for next packet

Configuration

This is the default configuration of the middleware. When any of the settings shall be modified, it shall be done in dedicated application config lwpkt_opts.h file.

Note

Check Getting started for guidelines on how to create and use configuration file.

group LWPKT_OPT

Default configuration setup.

Defines

LWPKT_CFG_MAX_DATA_LEN

Maximum length of data part of the packet in units of bytes.

LWPKT_CFG_ADDR_BROADCAST

Address identifying broadcast message to all devices.

LWPKT_CFG_USE_ADDR

Enables 1 or disables 0 from and to fields in the protocol.

This features is useful if communication is between 2 devices exclusively, without addressing requirements

LWPKT_CFG_ADDR_EXTENDED

Enables 1 or disables 0 extended address length.

When enabled, multi-byte addresses are supported with MSB codification. Maximum address is limited to 32-bits.

When disabled, simple 8-bit address is fixed with single byte.

Feature is disabled by default to keep architecture compatibility

LWPKT_CFG_USE_CMD

Enables 1 or disables 0 cmd field in the protocol.

When disabled, command part is not used

LWPKT_CFG_USE_CRC

Enables 1 or disables 0 CRC check in the protocol.

LWPKT_CFG_PROCESS_INPROG_TIMEOUT

Defines timeout time before packet is considered as not valid when too long time in data-read mode.

Used with lwpkt_process function

LWPKT_CFG_USE_EVT

Enables 1 or disables 0 event functions for read and write operations.