Compare commits
10 Commits
7938f1ecb1
...
7df6f11fb0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7df6f11fb0 | ||
|
|
979f66fac0 | ||
|
|
6605f9162e | ||
|
|
e39085552c | ||
|
|
99c59c2266 | ||
|
|
2d8fee908c | ||
|
|
b5fde1c6b3 | ||
|
|
d3ac9c1696 | ||
|
|
546040c448 | ||
|
|
a980f7f4c4 |
8
.github/workflows/ci.yml
vendored
8
.github/workflows/ci.yml
vendored
@ -9,7 +9,7 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Clone repo
|
||||
uses: actions/checkout@v2
|
||||
uses: actions/checkout@v3
|
||||
- name: configure
|
||||
run: |
|
||||
cmake -S . -B build -DBUILD_TESTS=ON -DCMAKE_BUILD_TYPE=Debug
|
||||
@ -19,7 +19,7 @@ jobs:
|
||||
- name: Compress Build Directory
|
||||
run: tar -czf build.tar.gz build/
|
||||
- name: Upload Build Artifact
|
||||
uses: actions/upload-artifact@v3
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: build
|
||||
path: build.tar.gz
|
||||
@ -27,7 +27,7 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Clone repo
|
||||
uses: actions/checkout@v2
|
||||
uses: actions/checkout@v3
|
||||
- name: Build Arduino examples
|
||||
run: |
|
||||
mkdir -p build
|
||||
@ -60,7 +60,7 @@ jobs:
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: Download Build Directory
|
||||
uses: actions/download-artifact@v3
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
name: build
|
||||
- name: Extract Build Directory
|
||||
|
||||
@ -12,14 +12,14 @@ include_directories(tests examples/linux .)
|
||||
add_library(nanomodbus nanomodbus.c)
|
||||
target_include_directories(nanomodbus PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
|
||||
if(BUILD_EXAMPLES)
|
||||
if (BUILD_EXAMPLES)
|
||||
add_executable(client-tcp examples/linux/client-tcp.c)
|
||||
target_link_libraries(client-tcp nanomodbus)
|
||||
add_executable(server-tcp examples/linux/server-tcp.c)
|
||||
target_link_libraries(server-tcp nanomodbus)
|
||||
endif()
|
||||
endif ()
|
||||
|
||||
if(BUILD_TESTS)
|
||||
if (BUILD_TESTS)
|
||||
add_executable(nanomodbus_tests nanomodbus.c tests/nanomodbus_tests.c)
|
||||
target_link_libraries(nanomodbus_tests pthread)
|
||||
|
||||
@ -38,4 +38,4 @@ if(BUILD_TESTS)
|
||||
add_test(NAME test_server_disabled COMMAND $<TARGET_FILE:server_disabled>)
|
||||
add_test(NAME test_client_disabled COMMAND $<TARGET_FILE:client_disabled>)
|
||||
add_test(NAME test_multi_server_rtu COMMAND $<TARGET_FILE:multi_server_rtu>)
|
||||
endif()
|
||||
endif ()
|
||||
@ -114,7 +114,7 @@ FetchContent_Declare(
|
||||
|
||||
FetchContent_MakeAvailable(nanomodbus)
|
||||
|
||||
...
|
||||
#...
|
||||
|
||||
add_executable(your_program source_codes)
|
||||
target_link_libraries(your_program nanomodbus)
|
||||
@ -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`
|
||||
|
||||
@ -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 > 250) {
|
||||
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 > 2000)
|
||||
if (quantity < 1 || quantity > NMBS_BITFIELD_MAX)
|
||||
return NMBS_ERROR_INVALID_ARGUMENT;
|
||||
|
||||
if ((uint32_t) address + (uint32_t) quantity > ((uint32_t) 0xFFFF) + 1)
|
||||
@ -2126,7 +2126,7 @@ nmbs_error nmbs_write_multiple_registers(nmbs_t* nmbs, uint16_t address, uint16_
|
||||
return err;
|
||||
|
||||
if (!nmbs->msg.broadcast)
|
||||
return recv_write_single_register_res(nmbs, address, quantity);
|
||||
return recv_write_multiple_registers_res(nmbs, address, quantity);
|
||||
|
||||
return NMBS_ERROR_NONE;
|
||||
}
|
||||
|
||||
22
nanomodbus.h
22
nanomodbus.h
@ -78,11 +78,21 @@ typedef enum nmbs_error {
|
||||
*/
|
||||
#define nmbs_error_is_exception(e) ((e) > 0 && (e) < 5)
|
||||
|
||||
#ifndef NMBS_BITFIELD_MAX
|
||||
#define NMBS_BITFIELD_MAX 2000
|
||||
#endif
|
||||
|
||||
/* check coil count divisible by 8 */
|
||||
#if ((NMBS_BITFIELD_MAX & 7) > 0)
|
||||
#error "NMBS_BITFIELD_MAX must be divisible by 8"
|
||||
#endif
|
||||
|
||||
#define NMBS_BITFIELD_BYTES_MAX (NMBS_BITFIELD_MAX / 8)
|
||||
|
||||
/**
|
||||
* Bitfield consisting of 2000 coils/discrete inputs
|
||||
*/
|
||||
typedef uint8_t nmbs_bitfield[250];
|
||||
typedef uint8_t nmbs_bitfield[NMBS_BITFIELD_BYTES_MAX];
|
||||
|
||||
/**
|
||||
* Bitfield consisting of 256 values
|
||||
@ -92,24 +102,22 @@ typedef uint8_t nmbs_bitfield_256[32];
|
||||
/**
|
||||
* Read a bit from the nmbs_bitfield bf at position b
|
||||
*/
|
||||
#define nmbs_bitfield_read(bf, b) ((bool) ((bf)[(b) / 8] & (0x1 << ((b) % 8))))
|
||||
#define nmbs_bitfield_read(bf, b) ((bool) ((bf)[(b) >> 3] & (0x1 << ((b) & (8 - 1)))))
|
||||
|
||||
/**
|
||||
* Set a bit of the nmbs_bitfield bf at position b
|
||||
*/
|
||||
#define nmbs_bitfield_set(bf, b) (((bf)[(b) / 8]) = (((bf)[(b) / 8]) | (0x1 << ((b) % 8))))
|
||||
#define nmbs_bitfield_set(bf, b) (((bf)[(b) >> 3]) = (((bf)[(b) >> 3]) | (0x1 << ((b) & (8 - 1)))))
|
||||
|
||||
/**
|
||||
* Reset a bit of the nmbs_bitfield bf at position b
|
||||
*/
|
||||
#define nmbs_bitfield_unset(bf, b) (((bf)[(b) / 8]) = (((bf)[(b) / 8]) & ~(0x1 << ((b) % 8))))
|
||||
#define nmbs_bitfield_unset(bf, b) (((bf)[(b) >> 3]) = (((bf)[(b) >> 3]) & ~(0x1 << ((b) & (8 - 1)))))
|
||||
|
||||
/**
|
||||
* Write value v to the nmbs_bitfield bf at position b
|
||||
*/
|
||||
#define nmbs_bitfield_write(bf, b, v) \
|
||||
(((bf)[(b) / 8]) = ((v) ? (((bf)[(b) / 8]) | (0x1 << ((b) % 8))) : (((bf)[(b) / 8]) & ~(0x1 << ((b) % 8)))))
|
||||
|
||||
#define nmbs_bitfield_write(bf, b, v) ((bf)[(b) >> 3] = ((bf)[(b) >> 3] & ~(1 << ((b) & 7))) | ((v) << ((b) & 7)))
|
||||
/**
|
||||
* Reset (zero) the whole bitfield
|
||||
*/
|
||||
|
||||
Loading…
Reference in New Issue
Block a user