RTU unit_id in server callbacks
This commit is contained in:
parent
44f3191735
commit
2da601fd80
20
nanomodbus.c
20
nanomodbus.c
@ -595,7 +595,8 @@ nmbs_error recv_write_multiple_registers_res(nmbs_t* nmbs, uint16_t address, uin
|
|||||||
|
|
||||||
#ifndef NMBS_SERVER_DISABLED
|
#ifndef NMBS_SERVER_DISABLED
|
||||||
#if !defined(NMBS_SERVER_READ_COILS_DISABLED) || !defined(NMBS_SERVER_READ_DISCRETE_INPUTS_DISABLED)
|
#if !defined(NMBS_SERVER_READ_COILS_DISABLED) || !defined(NMBS_SERVER_READ_DISCRETE_INPUTS_DISABLED)
|
||||||
static nmbs_error handle_read_discrete(nmbs_t* nmbs, nmbs_error (*callback)(uint16_t, uint16_t, nmbs_bitfield, void*)) {
|
static nmbs_error handle_read_discrete(nmbs_t* nmbs,
|
||||||
|
nmbs_error (*callback)(uint16_t, uint16_t, nmbs_bitfield, uint8_t, void*)) {
|
||||||
nmbs_error err = recv(nmbs, 4);
|
nmbs_error err = recv(nmbs, 4);
|
||||||
if (err != NMBS_ERROR_NONE)
|
if (err != NMBS_ERROR_NONE)
|
||||||
return err;
|
return err;
|
||||||
@ -618,7 +619,7 @@ static nmbs_error handle_read_discrete(nmbs_t* nmbs, nmbs_error (*callback)(uint
|
|||||||
|
|
||||||
if (callback) {
|
if (callback) {
|
||||||
nmbs_bitfield bitfield = {0};
|
nmbs_bitfield bitfield = {0};
|
||||||
err = callback(address, quantity, bitfield, nmbs->platform.arg);
|
err = callback(address, quantity, bitfield, nmbs->msg.unit_id, nmbs->platform.arg);
|
||||||
if (err != NMBS_ERROR_NONE) {
|
if (err != NMBS_ERROR_NONE) {
|
||||||
if (nmbs_error_is_exception(err))
|
if (nmbs_error_is_exception(err))
|
||||||
return send_exception_msg(nmbs, err);
|
return send_exception_msg(nmbs, err);
|
||||||
@ -659,7 +660,8 @@ static nmbs_error handle_read_discrete(nmbs_t* nmbs, nmbs_error (*callback)(uint
|
|||||||
|
|
||||||
|
|
||||||
#if !defined(NMBS_SERVER_READ_HOLDING_REGISTERS_DISABLED) || !defined(NMBS_SERVER_READ_INPUT_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*, uint8_t, void*)) {
|
||||||
nmbs_error err = recv(nmbs, 4);
|
nmbs_error err = recv(nmbs, 4);
|
||||||
if (err != NMBS_ERROR_NONE)
|
if (err != NMBS_ERROR_NONE)
|
||||||
return err;
|
return err;
|
||||||
@ -682,7 +684,7 @@ static nmbs_error handle_read_registers(nmbs_t* nmbs, nmbs_error (*callback)(uin
|
|||||||
|
|
||||||
if (callback) {
|
if (callback) {
|
||||||
uint16_t regs[125] = {0};
|
uint16_t regs[125] = {0};
|
||||||
err = callback(address, quantity, regs, nmbs->platform.arg);
|
err = callback(address, quantity, regs, nmbs->msg.unit_id, nmbs->platform.arg);
|
||||||
if (err != NMBS_ERROR_NONE) {
|
if (err != NMBS_ERROR_NONE) {
|
||||||
if (nmbs_error_is_exception(err))
|
if (nmbs_error_is_exception(err))
|
||||||
return send_exception_msg(nmbs, err);
|
return send_exception_msg(nmbs, err);
|
||||||
@ -770,7 +772,8 @@ static nmbs_error handle_write_single_coil(nmbs_t* nmbs) {
|
|||||||
if (value != 0 && value != 0xFF00)
|
if (value != 0 && value != 0xFF00)
|
||||||
return send_exception_msg(nmbs, NMBS_EXCEPTION_ILLEGAL_DATA_VALUE);
|
return send_exception_msg(nmbs, NMBS_EXCEPTION_ILLEGAL_DATA_VALUE);
|
||||||
|
|
||||||
err = nmbs->callbacks.write_single_coil(address, value == 0 ? false : true, nmbs->platform.arg);
|
err = nmbs->callbacks.write_single_coil(address, value == 0 ? false : true, nmbs->msg.unit_id,
|
||||||
|
nmbs->platform.arg);
|
||||||
if (err != NMBS_ERROR_NONE) {
|
if (err != NMBS_ERROR_NONE) {
|
||||||
if (nmbs_error_is_exception(err))
|
if (nmbs_error_is_exception(err))
|
||||||
return send_exception_msg(nmbs, err);
|
return send_exception_msg(nmbs, err);
|
||||||
@ -820,7 +823,7 @@ static nmbs_error handle_write_single_register(nmbs_t* nmbs) {
|
|||||||
|
|
||||||
if (!nmbs->msg.ignored) {
|
if (!nmbs->msg.ignored) {
|
||||||
if (nmbs->callbacks.write_single_register) {
|
if (nmbs->callbacks.write_single_register) {
|
||||||
err = nmbs->callbacks.write_single_register(address, value, nmbs->platform.arg);
|
err = nmbs->callbacks.write_single_register(address, value, nmbs->msg.unit_id, nmbs->platform.arg);
|
||||||
if (err != NMBS_ERROR_NONE) {
|
if (err != NMBS_ERROR_NONE) {
|
||||||
if (nmbs_error_is_exception(err))
|
if (nmbs_error_is_exception(err))
|
||||||
return send_exception_msg(nmbs, err);
|
return send_exception_msg(nmbs, err);
|
||||||
@ -893,7 +896,7 @@ static nmbs_error handle_write_multiple_coils(nmbs_t* nmbs) {
|
|||||||
return send_exception_msg(nmbs, NMBS_EXCEPTION_ILLEGAL_DATA_VALUE);
|
return send_exception_msg(nmbs, NMBS_EXCEPTION_ILLEGAL_DATA_VALUE);
|
||||||
|
|
||||||
if (nmbs->callbacks.write_multiple_coils) {
|
if (nmbs->callbacks.write_multiple_coils) {
|
||||||
err = nmbs->callbacks.write_multiple_coils(address, quantity, coils, nmbs->platform.arg);
|
err = nmbs->callbacks.write_multiple_coils(address, quantity, coils, nmbs->msg.unit_id, nmbs->platform.arg);
|
||||||
if (err != NMBS_ERROR_NONE) {
|
if (err != NMBS_ERROR_NONE) {
|
||||||
if (nmbs_error_is_exception(err))
|
if (nmbs_error_is_exception(err))
|
||||||
return send_exception_msg(nmbs, err);
|
return send_exception_msg(nmbs, err);
|
||||||
@ -966,7 +969,8 @@ static nmbs_error handle_write_multiple_registers(nmbs_t* nmbs) {
|
|||||||
return send_exception_msg(nmbs, NMBS_EXCEPTION_ILLEGAL_DATA_VALUE);
|
return send_exception_msg(nmbs, NMBS_EXCEPTION_ILLEGAL_DATA_VALUE);
|
||||||
|
|
||||||
if (nmbs->callbacks.write_multiple_registers) {
|
if (nmbs->callbacks.write_multiple_registers) {
|
||||||
err = nmbs->callbacks.write_multiple_registers(address, quantity, registers, nmbs->platform.arg);
|
err = nmbs->callbacks.write_multiple_registers(address, quantity, registers, nmbs->msg.unit_id,
|
||||||
|
nmbs->platform.arg);
|
||||||
if (err != NMBS_ERROR_NONE) {
|
if (err != NMBS_ERROR_NONE) {
|
||||||
if (nmbs_error_is_exception(err))
|
if (nmbs_error_is_exception(err))
|
||||||
return send_exception_msg(nmbs, err);
|
return send_exception_msg(nmbs, err);
|
||||||
|
|||||||
21
nanomodbus.h
21
nanomodbus.h
@ -146,35 +146,40 @@ typedef struct nmbs_platform_conf {
|
|||||||
typedef struct nmbs_callbacks {
|
typedef struct nmbs_callbacks {
|
||||||
#ifndef NMBS_SERVER_DISABLED
|
#ifndef NMBS_SERVER_DISABLED
|
||||||
#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, uint8_t unit_id, 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, uint8_t unit_id,
|
||||||
|
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, uint8_t unit_id,
|
||||||
|
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, uint8_t unit_id,
|
||||||
|
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, uint8_t unit_id, 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, uint8_t unit_id, 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, uint8_t unit_id,
|
||||||
|
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,
|
||||||
|
uint8_t unit_id, void* arg);
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@ -155,8 +155,9 @@ void test_server_receive_base(nmbs_transport transport) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
nmbs_error read_discrete(uint16_t address, uint16_t quantity, nmbs_bitfield coils_out, void* arg) {
|
nmbs_error read_discrete(uint16_t address, uint16_t quantity, nmbs_bitfield coils_out, uint8_t unit_id, void* arg) {
|
||||||
UNUSED_PARAM(arg);
|
UNUSED_PARAM(arg);
|
||||||
|
UNUSED_PARAM(unit_id);
|
||||||
|
|
||||||
if (address == 1)
|
if (address == 1)
|
||||||
return -1;
|
return -1;
|
||||||
@ -324,8 +325,9 @@ void test_fc2(nmbs_transport transport) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
nmbs_error read_registers(uint16_t address, uint16_t quantity, uint16_t* registers_out, void* arg) {
|
nmbs_error read_registers(uint16_t address, uint16_t quantity, uint16_t* registers_out, uint8_t unit_id, void* arg) {
|
||||||
UNUSED_PARAM(arg);
|
UNUSED_PARAM(arg);
|
||||||
|
UNUSED_PARAM(unit_id);
|
||||||
|
|
||||||
if (address == 1)
|
if (address == 1)
|
||||||
return -1;
|
return -1;
|
||||||
@ -456,8 +458,9 @@ void test_fc4(nmbs_transport transport) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
nmbs_error write_coil(uint16_t address, bool value, void* arg) {
|
nmbs_error write_coil(uint16_t address, bool value, uint8_t unit_id, void* arg) {
|
||||||
UNUSED_PARAM(arg);
|
UNUSED_PARAM(arg);
|
||||||
|
UNUSED_PARAM(unit_id);
|
||||||
|
|
||||||
if (address == 1)
|
if (address == 1)
|
||||||
return -1;
|
return -1;
|
||||||
@ -523,8 +526,9 @@ void test_fc5(nmbs_transport transport) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
nmbs_error write_register(uint16_t address, uint16_t value, void* arg) {
|
nmbs_error write_register(uint16_t address, uint16_t value, uint8_t unit_id, void* arg) {
|
||||||
UNUSED_PARAM(arg);
|
UNUSED_PARAM(arg);
|
||||||
|
UNUSED_PARAM(unit_id);
|
||||||
|
|
||||||
if (address == 1)
|
if (address == 1)
|
||||||
return -1;
|
return -1;
|
||||||
@ -583,8 +587,9 @@ void test_fc6(nmbs_transport transport) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
nmbs_error write_coils(uint16_t address, uint16_t quantity, const nmbs_bitfield coils, void* arg) {
|
nmbs_error write_coils(uint16_t address, uint16_t quantity, const nmbs_bitfield coils, uint8_t unit_id, void* arg) {
|
||||||
UNUSED_PARAM(arg);
|
UNUSED_PARAM(arg);
|
||||||
|
UNUSED_PARAM(unit_id);
|
||||||
|
|
||||||
if (address == 1)
|
if (address == 1)
|
||||||
return -1;
|
return -1;
|
||||||
@ -699,8 +704,9 @@ void test_fc15(nmbs_transport transport) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
nmbs_error write_registers(uint16_t address, uint16_t quantity, const uint16_t* registers, void* arg) {
|
nmbs_error write_registers(uint16_t address, uint16_t quantity, const uint16_t* registers, uint8_t unit_id, void* arg) {
|
||||||
UNUSED_PARAM(arg);
|
UNUSED_PARAM(arg);
|
||||||
|
UNUSED_PARAM(unit_id);
|
||||||
|
|
||||||
if (address == 1)
|
if (address == 1)
|
||||||
return -1;
|
return -1;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user