Various fixes to NMBS_SERVER_* defines handling
This commit is contained in:
parent
c12ba4b8a3
commit
fd101fe77f
@ -119,8 +119,8 @@ values will be treated as transport errors.
|
|||||||
|
|
||||||
### Platform functions argument
|
### Platform functions argument
|
||||||
|
|
||||||
Platform functions can access arbitrary user data through their `void* arg` argument. The argument is useful, for
|
Platform functions and server callbacks can access arbitrary user data through their `void* arg` argument. The argument
|
||||||
example, to pass the connection a function should operate on.
|
is useful, for example, to pass the connection a function should operate on.
|
||||||
Its initial value can be set inside the `nmbs_platform_conf` struct when creating the `nmbs_t` instance, and changed at
|
Its initial value can be set inside the `nmbs_platform_conf` struct when creating the `nmbs_t` instance, and changed at
|
||||||
any time via the `nmbs_set_platform_arg` API method.
|
any time via the `nmbs_set_platform_arg` API method.
|
||||||
|
|
||||||
|
|||||||
@ -255,7 +255,6 @@ static nmbs_error recv_msg_header(nmbs_t* nmbs, bool* first_byte_received) {
|
|||||||
|
|
||||||
msg_state_reset(nmbs);
|
msg_state_reset(nmbs);
|
||||||
|
|
||||||
if (first_byte_received)
|
|
||||||
*first_byte_received = false;
|
*first_byte_received = false;
|
||||||
|
|
||||||
if (nmbs->platform.transport == NMBS_TRANSPORT_RTU) {
|
if (nmbs->platform.transport == NMBS_TRANSPORT_RTU) {
|
||||||
@ -266,7 +265,6 @@ static nmbs_error recv_msg_header(nmbs_t* nmbs, bool* first_byte_received) {
|
|||||||
if (err != NMBS_ERROR_NONE)
|
if (err != NMBS_ERROR_NONE)
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
if (first_byte_received)
|
|
||||||
*first_byte_received = true;
|
*first_byte_received = true;
|
||||||
|
|
||||||
nmbs->msg.unit_id = get_1(nmbs);
|
nmbs->msg.unit_id = get_1(nmbs);
|
||||||
@ -285,7 +283,6 @@ static nmbs_error recv_msg_header(nmbs_t* nmbs, bool* first_byte_received) {
|
|||||||
if (err != NMBS_ERROR_NONE)
|
if (err != NMBS_ERROR_NONE)
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
if (first_byte_received)
|
|
||||||
*first_byte_received = true;
|
*first_byte_received = true;
|
||||||
|
|
||||||
// Advance buf_idx
|
// Advance buf_idx
|
||||||
@ -341,7 +338,8 @@ static nmbs_error recv_res_header(nmbs_t* nmbs) {
|
|||||||
uint8_t req_unit_id = nmbs->msg.unit_id;
|
uint8_t req_unit_id = nmbs->msg.unit_id;
|
||||||
uint8_t req_fc = nmbs->msg.fc;
|
uint8_t req_fc = nmbs->msg.fc;
|
||||||
|
|
||||||
nmbs_error err = recv_msg_header(nmbs, NULL);
|
bool first_byte_received;
|
||||||
|
nmbs_error err = recv_msg_header(nmbs, &first_byte_received);
|
||||||
if (err != NMBS_ERROR_NONE)
|
if (err != NMBS_ERROR_NONE)
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
@ -503,7 +501,7 @@ static nmbs_error handle_read_discrete(nmbs_t* nmbs, nmbs_error (*callback)(uint
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#if !defined(NMBS_SERVER_READ_HOLDING_REGISTERS_DISABLED) || !defined(NMBS_SERVER_READ_INPUTS_REGISTERS_DISABLED)
|
#if !defined(NMBS_SERVER_READ_HOLDING_REGISTERS_DISABLED) || !defined(NMBS_SERVER_READ_INPUT_REGISTERS_DISABLED)
|
||||||
static nmbs_error handle_read_registers(nmbs_t* nmbs, nmbs_error (*callback)(uint16_t, uint16_t, uint16_t*, void*)) {
|
static nmbs_error handle_read_registers(nmbs_t* nmbs, nmbs_error (*callback)(uint16_t, uint16_t, uint16_t*, void*)) {
|
||||||
nmbs_error err = recv(nmbs, 4);
|
nmbs_error err = recv(nmbs, 4);
|
||||||
if (err != NMBS_ERROR_NONE)
|
if (err != NMBS_ERROR_NONE)
|
||||||
|
|||||||
18
nanomodbus.h
18
nanomodbus.h
@ -53,15 +53,14 @@ extern "C" {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#ifdef NMBS_SERVER_DISABLED
|
#ifdef NMBS_SERVER_DISABLED
|
||||||
#define NMBS_SERVER_READ_COILS_DISABLED 1
|
#define NMBS_SERVER_READ_COILS_DISABLED
|
||||||
#define NMBS_SERVER_READ_COILS_DISABLED 1
|
#define NMBS_SERVER_READ_DISCRETE_INPUTS_DISABLED
|
||||||
#define NMBS_SERVER_READ_DISCRETE_INPUTS_DISABLED 1
|
#define NMBS_SERVER_READ_HOLDING_REGISTERS_DISABLED
|
||||||
#define NMBS_SERVER_READ_HOLDING_REGISTERS_DISABLED 1
|
#define NMBS_SERVER_READ_INPUT_REGISTERS_DISABLED
|
||||||
#define NMBS_SERVER_READ_INPUT_REGISTERS_DISABLED 1
|
#define NMBS_SERVER_WRITE_SINGLE_COIL_DISABLED
|
||||||
#define NMBS_SERVER_WRITE_SINGLE_COIL_DISABLED 1
|
#define NMBS_SERVER_WRITE_SINGLE_REGISTER_DISABLED
|
||||||
#define NMBS_SERVER_WRITE_SINGLE_REGISTER_DISABLED 1
|
#define NMBS_SERVER_WRITE_MULTIPLE_COILS_DISABLED
|
||||||
#define NMBS_SERVER_WRITE_MULTIPLE_COILS_DISABLED 1
|
#define NMBS_SERVER_WRITE_MULTIPLE_REGISTERS_DISABLED
|
||||||
#define NMBS_SERVER_WRITE_MULTIPLE_REGISTERS_DISABLED 1
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -192,6 +191,7 @@ typedef struct nmbs_callbacks {
|
|||||||
nmbs_error (*write_multiple_registers)(uint16_t address, uint16_t quantity, const uint16_t* registers, void* arg);
|
nmbs_error (*write_multiple_registers)(uint16_t address, uint16_t quantity, const uint16_t* registers, void* arg);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
char _nonempty; // Struct may become empty, which is undefined behavior
|
||||||
} nmbs_callbacks;
|
} nmbs_callbacks;
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user