Skip to content

Commit

Permalink
Improve dead code flagging
Browse files Browse the repository at this point in the history
- nanomodbus.c: silence GCC -Wunused-function warnings
- nanomodbus.h: fix compilation errors when only READ_WRITE_REGISTER
  function is included
  • Loading branch information
stefanb2 committed Sep 20, 2024
1 parent 67bd7b2 commit 624a115
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
23 changes: 23 additions & 0 deletions nanomodbus.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,13 @@ static void discard_1(nmbs_t* nmbs) {


#ifndef NMBS_SERVER_DISABLED
#if !defined(NMBS_SERVER_READ_FILE_RECORD_DISABLED) || \
!defined(NMBS_SERVER_WRITE_FILE_RECORD_DISABLED)
static void discard_n(nmbs_t* nmbs, uint16_t n) {
nmbs->msg.buf_idx += n;
}
#endif
#endif


static uint16_t get_2(nmbs_t* nmbs) {
Expand All @@ -79,6 +82,7 @@ static void put_2(nmbs_t* nmbs, uint16_t data) {


#ifndef NMBS_SERVER_DISABLED
#if !defined(NMBS_SERVER_READ_DEVICE_IDENTIFICATION_DISABLED)
static void set_1(nmbs_t* nmbs, uint8_t data, uint8_t index) {
nmbs->msg.buf[index] = data;
}
Expand All @@ -89,6 +93,7 @@ static void set_2(nmbs_t* nmbs, uint16_t data, uint8_t index) {
nmbs->msg.buf[index + 1] = (uint8_t) data;
}
#endif
#endif


static uint8_t* get_n(nmbs_t* nmbs, uint16_t n) {
Expand All @@ -99,12 +104,15 @@ static uint8_t* get_n(nmbs_t* nmbs, uint16_t n) {


#ifndef NMBS_SERVER_DISABLED
#if !defined(NMBS_SERVER_READ_DEVICE_IDENTIFICATION_DISABLED)
static void put_n(nmbs_t* nmbs, const uint8_t* data, uint8_t size) {
memcpy(&nmbs->msg.buf[nmbs->msg.buf_idx], data, size);
nmbs->msg.buf_idx += size;
}
#endif


#if !defined(NMBS_SERVER_WRITE_FILE_RECORD_DISABLED)
static uint16_t* get_regs(nmbs_t* nmbs, uint16_t n) {
uint16_t* msg_buf_ptr = (uint16_t*) (nmbs->msg.buf + nmbs->msg.buf_idx);
nmbs->msg.buf_idx += n * 2;
Expand All @@ -114,6 +122,7 @@ static uint16_t* get_regs(nmbs_t* nmbs, uint16_t n) {
return msg_buf_ptr;
}
#endif
#endif


#ifndef NMBS_CLIENT_DISABLED
Expand Down Expand Up @@ -368,13 +377,15 @@ static void put_msg_header(nmbs_t* nmbs, uint16_t data_length) {


#ifndef NMBS_SERVER_DISABLED
#if !defined(NMBS_SERVER_READ_DEVICE_IDENTIFICATION_DISABLED)
static void set_msg_header_size(nmbs_t* nmbs, uint16_t data_length) {
if (nmbs->platform.transport == NMBS_TRANSPORT_TCP) {
data_length += 2;
set_2(nmbs, data_length, 4);
}
}
#endif
#endif


static nmbs_error send_msg(nmbs_t* nmbs) {
Expand Down Expand Up @@ -494,6 +505,11 @@ static void put_req_header(nmbs_t* nmbs, uint16_t data_length) {
#endif


#if !defined(NMBS_CLIENT_DISABLED) || \
(!defined(NMBS_SERVER_DISABLED) && ( \
!defined(NMBS_SERVER_READ_COILS_DISABLED) || \
!defined(NMBS_SERVER_READ_DISCRETE_INPUTS_DISABLED) \
))
static nmbs_error recv_read_discrete_res(nmbs_t* nmbs, nmbs_bitfield values) {
nmbs_error err = recv_res_header(nmbs);
if (err != NMBS_ERROR_NONE)
Expand Down Expand Up @@ -528,8 +544,14 @@ static nmbs_error recv_read_discrete_res(nmbs_t* nmbs, nmbs_bitfield values) {

return NMBS_ERROR_NONE;
}
#endif


#if !defined(NMBS_CLIENT_DISABLED) || \
(!defined(NMBS_SERVER_DISABLED) && ( \
!defined(NMBS_SERVER_READ_HOLDING_REGISTERS_DISABLED) || \
!defined(NMBS_SERVER_READ_INPUT_REGISTERS_DISABLED) \
))
static nmbs_error recv_read_registers_res(nmbs_t* nmbs, uint16_t quantity, uint16_t* registers) {
nmbs_error err = recv_res_header(nmbs);
if (err != NMBS_ERROR_NONE)
Expand Down Expand Up @@ -566,6 +588,7 @@ static nmbs_error recv_read_registers_res(nmbs_t* nmbs, uint16_t quantity, uint1

return NMBS_ERROR_NONE;
}
#endif


nmbs_error recv_write_single_coil_res(nmbs_t* nmbs, uint16_t address, uint16_t value_req) {
Expand Down
6 changes: 4 additions & 2 deletions nanomodbus.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,8 @@ typedef struct nmbs_callbacks {
void* arg);
#endif

#ifndef NMBS_SERVER_READ_HOLDING_REGISTERS_DISABLED
#if !defined(NMBS_SERVER_READ_HOLDING_REGISTERS_DISABLED) || \
!defined(NMBS_SERVER_READ_WRITE_REGISTERS_DISABLED)
nmbs_error (*read_holding_registers)(uint16_t address, uint16_t quantity, uint16_t* registers_out, uint8_t unit_id,
void* arg);
#endif
Expand All @@ -194,7 +195,8 @@ typedef struct nmbs_callbacks {
void* arg);
#endif

#ifndef NMBS_SERVER_WRITE_MULTIPLE_REGISTERS_DISABLED
#if !defined(NMBS_SERVER_WRITE_MULTIPLE_REGISTERS_DISABLED) || \
!defined(NMBS_SERVER_READ_WRITE_REGISTERS_DISABLED)
nmbs_error (*write_multiple_registers)(uint16_t address, uint16_t quantity, const uint16_t* registers,
uint8_t unit_id, void* arg);
#endif
Expand Down

0 comments on commit 624a115

Please sign in to comment.