Changes to nmbs_bitfield after merge

This commit is contained in:
Valerio De Benedetto 2025-06-26 23:37:48 +02:00
parent 6605f9162e
commit 979f66fac0
3 changed files with 9 additions and 8 deletions

View File

@ -187,4 +187,5 @@ Please refer to `examples/arduino/README.md` for more info about building and ru
- `NMBS_SERVER_READ_WRITE_REGISTERS_DISABLED`
- `NMBS_SERVER_READ_DEVICE_IDENTIFICATION_DISABLED`
- `NMBS_STRERROR_DISABLED` to disable the code that converts `nmbs_error`s to strings
- `NMBS_BITFIELD_MAX` to set the size of the `nmbs_bitfield` type, used to store coil values (default is `2000`)
- Debug prints about received and sent messages can be enabled by defining `NMBS_DEBUG`

View File

@ -546,7 +546,7 @@ static nmbs_error recv_read_discrete_res(nmbs_t* nmbs, nmbs_bitfield values) {
uint8_t coils_bytes = get_1(nmbs);
NMBS_DEBUG_PRINT("b %d\t", coils_bytes);
if (coils_bytes > NMBS_MAX_COIL_BYTES) {
if (coils_bytes > NMBS_BITFIELD_BYTES_MAX) {
return NMBS_ERROR_INVALID_RESPONSE;
}
@ -1958,7 +1958,7 @@ nmbs_error nmbs_client_create(nmbs_t* nmbs, const nmbs_platform_conf* platform_c
static nmbs_error read_discrete(nmbs_t* nmbs, uint8_t fc, uint16_t address, uint16_t quantity, nmbs_bitfield values) {
if (quantity < 1 || quantity > NMBS_MAX_COILS)
if (quantity < 1 || quantity > NMBS_BITFIELD_MAX)
return NMBS_ERROR_INVALID_ARGUMENT;
if ((uint32_t) address + (uint32_t) quantity > ((uint32_t) 0xFFFF) + 1)

View File

@ -78,21 +78,21 @@ typedef enum nmbs_error {
*/
#define nmbs_error_is_exception(e) ((e) > 0 && (e) < 5)
#ifndef NMBS_MAX_COILS
#define NMBS_MAX_COILS 2000
#ifndef NMBS_BITFIELD_MAX
#define NMBS_BITFIELD_MAX 2000
#endif
/* check coil count divisible by 8 */
#if ((NMBS_MAX_COILS & 7) > 0)
#error "NMBS_MAX_COILS must be disible by 8"
#if ((NMBS_BITFIELD_MAX & 7) > 0)
#error "NMBS_BITFIELD_MAX must be divisible by 8"
#endif
#define NMBS_MAX_COIL_BYTES (NMBS_MAX_COILS / 8)
#define NMBS_BITFIELD_BYTES_MAX (NMBS_BITFIELD_MAX / 8)
/**
* Bitfield consisting of 2000 coils/discrete inputs
*/
typedef uint8_t nmbs_bitfield[NMBS_MAX_COIL_BYTES];
typedef uint8_t nmbs_bitfield[NMBS_BITFIELD_BYTES_MAX];
/**
* Bitfield consisting of 256 values