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.
|
||||||
|
|
||||||
|
|||||||
14
nanomodbus.c
14
nanomodbus.c
@ -255,8 +255,7 @@ 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) {
|
||||||
nmbs_error err = recv(nmbs, 1);
|
nmbs_error err = recv(nmbs, 1);
|
||||||
@ -266,8 +265,7 @@ 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,8 +283,7 @@ 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
|
||||||
discard_1(nmbs);
|
discard_1(nmbs);
|
||||||
@ -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)
|
||||||
|
|||||||
34
nanomodbus.h
34
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
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -161,37 +160,38 @@ typedef struct nmbs_platform_conf {
|
|||||||
*/
|
*/
|
||||||
typedef struct nmbs_callbacks {
|
typedef struct nmbs_callbacks {
|
||||||
#ifndef NMBS_SERVER_READ_COILS_DISABLED
|
#ifndef NMBS_SERVER_READ_COILS_DISABLED
|
||||||
nmbs_error (*read_coils)(uint16_t address, uint16_t quantity, nmbs_bitfield coils_out, void *arg);
|
nmbs_error (*read_coils)(uint16_t address, uint16_t quantity, nmbs_bitfield coils_out, void* arg);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef NMBS_SERVER_READ_DISCRETE_INPUTS_DISABLED
|
#ifndef NMBS_SERVER_READ_DISCRETE_INPUTS_DISABLED
|
||||||
nmbs_error (*read_discrete_inputs)(uint16_t address, uint16_t quantity, nmbs_bitfield inputs_out, void *arg);
|
nmbs_error (*read_discrete_inputs)(uint16_t address, uint16_t quantity, nmbs_bitfield inputs_out, void* arg);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef NMBS_SERVER_READ_HOLDING_REGISTERS_DISABLED
|
#ifndef NMBS_SERVER_READ_HOLDING_REGISTERS_DISABLED
|
||||||
nmbs_error (*read_holding_registers)(uint16_t address, uint16_t quantity, uint16_t* registers_out, void *arg);
|
nmbs_error (*read_holding_registers)(uint16_t address, uint16_t quantity, uint16_t* registers_out, void* arg);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef NMBS_SERVER_READ_INPUT_REGISTERS_DISABLED
|
#ifndef NMBS_SERVER_READ_INPUT_REGISTERS_DISABLED
|
||||||
nmbs_error (*read_input_registers)(uint16_t address, uint16_t quantity, uint16_t* registers_out, void *arg);
|
nmbs_error (*read_input_registers)(uint16_t address, uint16_t quantity, uint16_t* registers_out, void* arg);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef NMBS_SERVER_WRITE_SINGLE_COIL_DISABLED
|
#ifndef NMBS_SERVER_WRITE_SINGLE_COIL_DISABLED
|
||||||
nmbs_error (*write_single_coil)(uint16_t address, bool value, void *arg);
|
nmbs_error (*write_single_coil)(uint16_t address, bool value, void* arg);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef NMBS_SERVER_WRITE_SINGLE_REGISTER_DISABLED
|
#ifndef NMBS_SERVER_WRITE_SINGLE_REGISTER_DISABLED
|
||||||
nmbs_error (*write_single_register)(uint16_t address, uint16_t value, void *arg);
|
nmbs_error (*write_single_register)(uint16_t address, uint16_t value, void* arg);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef NMBS_SERVER_WRITE_MULTIPLE_COILS_DISABLED
|
#ifndef NMBS_SERVER_WRITE_MULTIPLE_COILS_DISABLED
|
||||||
nmbs_error (*write_multiple_coils)(uint16_t address, uint16_t quantity, const nmbs_bitfield coils, void *arg);
|
nmbs_error (*write_multiple_coils)(uint16_t address, uint16_t quantity, const nmbs_bitfield coils, void* arg);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef NMBS_SERVER_WRITE_MULTIPLE_REGISTERS_DISABLED
|
#ifndef NMBS_SERVER_WRITE_MULTIPLE_REGISTERS_DISABLED
|
||||||
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