From a2a16545fc964ff9bad7def0284d4d86739ce219 Mon Sep 17 00:00:00 2001 From: aleks Date: Wed, 5 Feb 2025 12:02:04 +0100 Subject: [PATCH] fix cpp compilation issues --- .../common/include/esp_modbus_common.h | 13 +++++-------- modbus/mb_objects/include/mb_port_types.h | 16 +++++++--------- 2 files changed, 12 insertions(+), 17 deletions(-) diff --git a/modbus/mb_controller/common/include/esp_modbus_common.h b/modbus/mb_controller/common/include/esp_modbus_common.h index 8375185..31b4558 100644 --- a/modbus/mb_controller/common/include/esp_modbus_common.h +++ b/modbus/mb_controller/common/include/esp_modbus_common.h @@ -5,6 +5,7 @@ */ #pragma once +#include #include "driver/uart.h" // for UART types #include "sdkconfig.h" @@ -13,20 +14,12 @@ #include "mb_endianness_utils.h" #endif -#ifdef __cplusplus -extern "C" { -#endif - #include "port_common.h" #if __has_include("esp_check.h") #include "esp_check.h" #include "esp_log.h" -#include - -#include "mb_port_types.h" - #define MB_RETURN_ON_FALSE(a, err_code, tag, format, ...) ESP_RETURN_ON_FALSE(a, err_code, tag, format __VA_OPT__(,) __VA_ARGS__) #else @@ -42,6 +35,10 @@ extern "C" { #endif +#ifdef __cplusplus +extern "C" { +#endif + #define MB_SLAVE_ADDR_PLACEHOLDER (0xFF) #define MB_CONTROLLER_STACK_SIZE (CONFIG_FMB_CONTROLLER_STACK_SIZE) // Stack size for Modbus controller #define MB_CONTROLLER_PRIORITY (CONFIG_FMB_PORT_TASK_PRIO - 1) // priority of MB controller task diff --git a/modbus/mb_objects/include/mb_port_types.h b/modbus/mb_objects/include/mb_port_types.h index aad49e7..f1413b8 100644 --- a/modbus/mb_objects/include/mb_port_types.h +++ b/modbus/mb_objects/include/mb_port_types.h @@ -9,19 +9,18 @@ #include "mb_config.h" #include "mb_types.h" +#define MB_ATTR_WEAK __attribute__ ((weak)) + #ifdef __cplusplus extern "C" { #endif -#define MB_ATTR_WEAK __attribute__ ((weak)) - typedef enum _mb_comm_mode mb_mode_type_t; #if (CONFIG_FMB_COMM_MODE_ASCII_EN || CONFIG_FMB_COMM_MODE_RTU_EN) #include "driver/uart.h" -__attribute__((__packed__)) struct _port_serial_opts { mb_mode_type_t mode; /*!< Modbus communication mode */ uart_port_t port; /*!< Modbus communication port (UART) number */ @@ -32,7 +31,7 @@ struct _port_serial_opts { uart_word_length_t data_bits; /*!< Modbus number of data bits */ uart_stop_bits_t stop_bits; /*!< Modbus number of stop bits */ uart_parity_t parity; /*!< Modbus UART parity settings */ -}; +} __attribute__((__packed__)); typedef struct _port_serial_opts mb_serial_opts_t; @@ -44,16 +43,15 @@ typedef enum _addr_type_enum { MB_IPV6 = 2 /*!< TCP IPV6 addressing */ } mb_addr_type_t; -__attribute__((__packed__)) + struct _port_common_opts { mb_mode_type_t mode; /*!< Modbus communication mode */ uint16_t port; /*!< Modbus communication port (UART) number */ uint8_t uid; /*!< Modbus slave address field (dummy for master) */ uint32_t response_tout_ms; /*!< Modbus slave response timeout */ uint64_t test_tout_us; /*!< Modbus test timeout (reserved) */ -}; +} __attribute__((__packed__)); -__attribute__((__packed__)) struct _port_tcp_opts { mb_mode_type_t mode; /*!< Modbus communication mode */ uint16_t port; /*!< Modbus communication port (UART) number */ @@ -65,7 +63,7 @@ struct _port_tcp_opts { void *ip_netif_ptr; /*!< Modbus network interface */ char *dns_name; /*!< Modbus node DNS name */ bool start_disconnected; /*!< (Master only option) do not wait for connection to all nodes before polling */ -}; +} __attribute__((__packed__)); typedef struct _port_tcp_opts mb_tcp_opts_t; @@ -100,7 +98,7 @@ typedef struct _uid_info { uint16_t uid; /*!< node unit ID (UID) field for MBAP frame */ uint16_t port; /*!< node port number */ mb_comm_mode_t proto; /*!< protocol type */ - _Atomic mb_sock_state_t state; /*!< node state */ + atomic_int state; /*!< node state */ void *inst; /*!< pointer to linked instance */ } mb_uid_info_t;