Skip to content

Commit fe31faa

Browse files
committed
Merge branch 'develop'
2 parents e3831d6 + 83b9bfb commit fe31faa

26 files changed

Lines changed: 1436 additions & 597 deletions

File tree

.github/workflows/release.yml

Lines changed: 47 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Release workflow
1+
name: Create Release
22

33
on:
44
push:
@@ -7,23 +7,29 @@ on:
77
- 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10
88

99
jobs:
10-
# Create the release from the tag
1110
create-release:
12-
name: Create Release
11+
name: Create GitHub Release
1312
runs-on: ubuntu-latest
13+
14+
# Explicitly grant permission to create/write releases
15+
permissions:
16+
contents: write
17+
1418
steps:
15-
- name: Checkout code
16-
uses: actions/checkout@v2
17-
- name: Create Release
18-
id: create_release
19-
uses: actions/create-release@v1
20-
env:
21-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
19+
# Step 1: Check out the repository code
20+
# Fetch the full history to compare between tags
21+
- name: Checkout Code
22+
uses: actions/checkout@v4
23+
with:
24+
fetch-depth: 0
25+
26+
# Generate the release
27+
- name: Generate and Publish Release
28+
uses: softprops/action-gh-release@v2
2229
with:
23-
tag_name: ${{ github.ref }}
24-
release_name: Release ${{ github.ref }}
25-
body: |
26-
See the [CHANGELOG](CHANGELOG.md)
30+
tag_name: ${{ github.ref_name }}
31+
name: Release ${{ github.ref_name }}
32+
generate_release_notes: true
2733
draft: false
2834
prerelease: false
2935

@@ -46,3 +52,30 @@ jobs:
4652
env:
4753
PLATFORMIO_AUTH_TOKEN: ${{ secrets.PLATFORMIO_AUTH_TOKEN }}
4854
run: pio pkg publish --type library --non-interactive
55+
56+
# Publish python/ package to PyPI
57+
publish-pypi:
58+
runs-on: ubuntu-latest
59+
environment: pypi # must match the environment name entered when registering the trusted publisher on pypi.org
60+
permissions:
61+
id-token: write # required for PyPI trusted publishing
62+
steps:
63+
- name: Checkout code
64+
uses: actions/checkout@v4
65+
66+
- name: Set up Python
67+
uses: actions/setup-python@v5
68+
with:
69+
python-version: "3.x"
70+
71+
- name: Install build tooling
72+
run: pip install build
73+
74+
- name: Build package
75+
working-directory: python
76+
run: python -m build
77+
78+
- name: Publish to PyPI
79+
uses: pypa/gh-action-pypi-publish@release/v1
80+
with:
81+
packages-dir: python/dist

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,11 @@ paket-files/
358358
__pycache__/
359359
*.pyc
360360

361+
# Python packaging build artifacts
362+
dist/
363+
*.egg-info/
364+
.pytest_cache/
365+
361366
# Cake - Uncomment if you are using it
362367
# tools/**
363368
# !tools/packages.config

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,17 @@
22

33
## Develop
44

5+
## v2.0.0
6+
7+
- **Breaking (Python):** `rx_process()` now raises typed exceptions (`LwPKTError` and subclasses)
8+
on malformed input, instead of silently discarding or printing to console
9+
- Publish Python implementation to PyPI as `lwpkt` (`pip install lwpkt`)
10+
- Add continuation-byte limits to variable-length fields (`len`, address, `cmd`, `flags`) in both
11+
C and Python, rejecting corrupted/malicious streams instead of parsing them unbounded
12+
- Add missing `NULL`-instance checks across setter functions and `lwpkt_write`
13+
- Update bundled LwRB to latest version
14+
- Add GCC CMake preset for native builds
15+
516
## v1.5.1
617

718
- Fix the platformio library package description

CMakePresets.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@
2525
"cacheVariables": {
2626
"CMAKE_BUILD_TYPE": "Debug"
2727
}
28+
},
29+
{
30+
"name": "Gcc-Debug",
31+
"inherits": "default",
32+
"toolchainFile": "${sourceDir}/cmake/gcc.cmake",
33+
"cacheVariables": {
34+
"CMAKE_BUILD_TYPE": "Debug"
35+
}
2836
}
2937
],
3038
"buildPresets": [
@@ -35,6 +43,10 @@
3543
{
3644
"name": "Win64-Debug",
3745
"configurePreset": "Win64-Debug"
46+
},
47+
{
48+
"name": "Gcc-Debug",
49+
"configurePreset": "Gcc-Debug"
3850
}
3951
]
4052
}

cmake/gcc.cmake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Some default GCC settings
2+
# Assuming "gcc" and "g++" commands are globally available
3+
set(CMAKE_C_COMPILER gcc)
4+
set(CMAKE_CXX_COMPILER g++)

cmake/i686-w64-mingw32-gcc.cmake

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
set(CMAKE_SYSTEM_NAME Windows)
1+
set(CMAKE_SYSTEM_NAME Windows)
22

33
# Some default GCC settings
4-
set(CMAKE_C_COMPILER i686-w64-mingw32-gcc)
5-
set(CMAKE_CXX_COMPILER i686-w64-mingw32-g++)
4+
# Use MSYS2's "mingw-w64-i686-gcc" package
5+
set(CMAKE_C_COMPILER i686-w64-mingw32-gcc)
6+
set(CMAKE_CXX_COMPILER i686-w64-mingw32-g++)
67

78
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)

cmake/x86_64-w64-mingw32-gcc.cmake

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
set(CMAKE_SYSTEM_NAME Windows)
1+
set(CMAKE_SYSTEM_NAME Windows)
22

33
# Some default GCC settings
4-
set(CMAKE_C_COMPILER x86_64-w64-mingw32-gcc)
5-
set(CMAKE_CXX_COMPILER x86_64-w64-mingw32-g++)
4+
# Use MSYS2's "mingw-w64-x86_64-gcc" package
5+
set(CMAKE_C_COMPILER x86_64-w64-mingw32-gcc)
6+
set(CMAKE_CXX_COMPILER x86_64-w64-mingw32-g++)
67

78
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)

library.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "LwPKT",
3-
"version": "1.5.1",
3+
"version": "2.0.0",
44
"description": "Lightweight packet protocol library for communication implementation",
55
"keywords": "lwpkt, packet, protocol, manager, communication, com, lightweight, rs-485, rs-422, rs485, rs422, rs-232, rs232, uart, usart, lpuart",
66
"repository": {

libs/lwrb/src/include/lwrb/lwrb.h

Lines changed: 56 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,12 @@
2929
* This file is part of LwRB - Lightweight ring buffer library.
3030
*
3131
* Author: Tilen MAJERLE <tilen@majerle.eu>
32-
* Version: v3.0.0-rc1
32+
* Version: v3.3.0
3333
*/
3434
#ifndef LWRB_HDR_H
3535
#define LWRB_HDR_H
3636

37+
#include <stddef.h>
3738
#include <stdint.h>
3839
#include <string.h>
3940

@@ -47,11 +48,30 @@ extern "C" {
4748
* \{
4849
*/
4950

50-
#ifdef LWRB_DISABLE_ATOMIC
51-
typedef unsigned long lwrb_ulong_t;
52-
#else
51+
#if !defined(LWRB_DISABLE_ATOMIC) || __DOXYGEN__
5352
#include <stdatomic.h>
54-
typedef atomic_ulong lwrb_ulong_t;
53+
54+
/**
55+
* \brief Atomic type for size variable.
56+
* Default value is set to be `unsigned 32-bits` type
57+
*/
58+
typedef atomic_ulong lwrb_sz_atomic_t;
59+
60+
/**
61+
* \brief Size variable for all library operations.
62+
* Default value is set to be `unsigned 32-bits` type
63+
*/
64+
typedef unsigned long lwrb_sz_t;
65+
#else
66+
/*
67+
* LWRB_DISABLE_ATOMIC is defined, so the atomic type is dropped in favor of a
68+
* plain one. This is not "atomicity off, everything else still guaranteed" -
69+
* there is no ordering or visibility guarantee between the write and read
70+
* side left in the library at all. If you define this, it is entirely up to
71+
* the application to make sure the target handles concurrent access safely.
72+
*/
73+
typedef unsigned long lwrb_sz_atomic_t;
74+
typedef unsigned long lwrb_sz_t;
5575
#endif
5676

5777
/**
@@ -74,46 +94,61 @@ struct lwrb;
7494
* \param[in] evt: Event type
7595
* \param[in] bp: Number of bytes written or read (when used), depends on event type
7696
*/
77-
typedef void (*lwrb_evt_fn)(struct lwrb* buff, lwrb_evt_type_t evt, size_t bp);
97+
typedef void (*lwrb_evt_fn)(struct lwrb* buff, lwrb_evt_type_t evt, lwrb_sz_t bp);
98+
99+
/* List of flags */
100+
#define LWRB_FLAG_READ_ALL ((uint16_t)0x0001)
101+
#define LWRB_FLAG_WRITE_ALL ((uint16_t)0x0001)
78102

79103
/**
80104
* \brief Buffer structure
81105
*/
82106
typedef struct lwrb {
83107
uint8_t* buff; /*!< Pointer to buffer data. Buffer is considered initialized when `buff != NULL` and `size > 0` */
84-
size_t size; /*!< Size of buffer data. Size of actual buffer is `1` byte less than value holds */
85-
lwrb_ulong_t r; /*!< Next read pointer. Buffer is considered empty when `r == w` and full when `w == r - 1` */
86-
lwrb_ulong_t w; /*!< Next write pointer. Buffer is considered empty when `r == w` and full when `w == r - 1` */
87-
lwrb_evt_fn evt_fn; /*!< Pointer to event callback function */
108+
lwrb_sz_t size; /*!< Size of buffer data. Size of actual buffer is `1` byte less than value holds */
109+
lwrb_sz_atomic_t r_ptr; /*!< Next read pointer.
110+
Buffer is considered empty when `r == w` and full when `w == r - 1` */
111+
lwrb_sz_atomic_t w_ptr; /*!< Next write pointer.
112+
Buffer is considered empty when `r == w` and full when `w == r - 1` */
113+
lwrb_evt_fn evt_fn; /*!< Pointer to event callback function */
114+
void* arg; /*!< Event custom user argument */
88115
} lwrb_t;
89116

90-
uint8_t lwrb_init(lwrb_t* buff, void* buffdata, size_t size);
117+
uint8_t lwrb_init(lwrb_t* buff, void* buffdata, lwrb_sz_t size);
91118
uint8_t lwrb_is_ready(lwrb_t* buff);
92119
void lwrb_free(lwrb_t* buff);
93120
void lwrb_reset(lwrb_t* buff);
94121
void lwrb_set_evt_fn(lwrb_t* buff, lwrb_evt_fn fn);
122+
void lwrb_set_arg(lwrb_t* buff, void* arg);
123+
void* lwrb_get_arg(lwrb_t* buff);
95124

96125
/* Read/Write functions */
97-
size_t lwrb_write(lwrb_t* buff, const void* data, size_t btw);
98-
size_t lwrb_read(lwrb_t* buff, void* data, size_t btr);
99-
size_t lwrb_peek(const lwrb_t* buff, size_t skip_count, void* data, size_t btp);
126+
lwrb_sz_t lwrb_write(lwrb_t* buff, const void* data, lwrb_sz_t btw);
127+
lwrb_sz_t lwrb_read(lwrb_t* buff, void* data, lwrb_sz_t btr);
128+
lwrb_sz_t lwrb_peek(const lwrb_t* buff, lwrb_sz_t skip_count, void* data, lwrb_sz_t btp);
129+
130+
/* Extended read/write functions */
131+
uint8_t lwrb_write_ex(lwrb_t* buff, const void* data, lwrb_sz_t btw, lwrb_sz_t* bwritten, uint16_t flags);
132+
uint8_t lwrb_read_ex(lwrb_t* buff, void* data, lwrb_sz_t btr, lwrb_sz_t* bread, uint16_t flags);
100133

101134
/* Buffer size information */
102-
size_t lwrb_get_free(const lwrb_t* buff);
103-
size_t lwrb_get_full(const lwrb_t* buff);
135+
lwrb_sz_t lwrb_get_free(const lwrb_t* buff);
136+
lwrb_sz_t lwrb_get_full(const lwrb_t* buff);
104137

105138
/* Read data block management */
106139
void* lwrb_get_linear_block_read_address(const lwrb_t* buff);
107-
size_t lwrb_get_linear_block_read_length(const lwrb_t* buff);
108-
size_t lwrb_skip(lwrb_t* buff, size_t len);
140+
lwrb_sz_t lwrb_get_linear_block_read_length(const lwrb_t* buff);
141+
lwrb_sz_t lwrb_skip(lwrb_t* buff, lwrb_sz_t len);
109142

110143
/* Write data block management */
111144
void* lwrb_get_linear_block_write_address(const lwrb_t* buff);
112-
size_t lwrb_get_linear_block_write_length(const lwrb_t* buff);
113-
size_t lwrb_advance(lwrb_t* buff, size_t len);
145+
lwrb_sz_t lwrb_get_linear_block_write_length(const lwrb_t* buff);
146+
lwrb_sz_t lwrb_advance(lwrb_t* buff, lwrb_sz_t len);
114147

115148
/* Search in buffer */
116-
uint8_t lwrb_find(const lwrb_t* buff, const void* bts, size_t len, size_t start_offset, size_t* found_idx);
149+
uint8_t lwrb_find(const lwrb_t* buff, const void* bts, lwrb_sz_t len, lwrb_sz_t start_offset, lwrb_sz_t* found_idx);
150+
lwrb_sz_t lwrb_overwrite(lwrb_t* buff, const void* data, lwrb_sz_t btw);
151+
lwrb_sz_t lwrb_move(lwrb_t* dest, lwrb_t* src);
117152

118153
/**
119154
* \}

0 commit comments

Comments
 (0)