espressif / esp-mesh-lite

A lite version Wi-Fi Mesh, each node can access the network over the IP layer.
110 stars 15 forks source link

mesh_lite_local_control & use esp-modbus a compilation error occurred (AEGHB-542) #58

Closed yel-best closed 5 months ago

yel-best commented 5 months ago

When I add esp-modbus to the mesh_lite_local_control example of mesh-lite, the following error occurs during compilation. Is it because of incompatibility?

image

In file included from E:/MyProject/IoT/esp/esp-idf/components/esp_common/include/esp_check.h:9,
                 from E:/MyProject/IoT/PlatformIO-ESP/esp-idf-mesh-lite/mesh-lite-test/managed_components/espressif__esp-modbus/freemodbus/common/include/esp_modbus_common.h:18,
                 from E:/MyProject/IoT/PlatformIO-ESP/esp-idf-mesh-lite/mesh-lite-test/managed_components/espressif__esp-modbus/freemodbus/common/include/esp_modbus_master.h:13,
                 from E:/MyProject/IoT/PlatformIO-ESP/esp-idf-mesh-lite/mesh-lite-test/managed_components/espressif__esp-modbus/freemodbus/common/include/mbcontroller.h:20,
                 from E:/MyProject/IoT/PlatformIO-ESP/esp-idf-mesh-lite/mesh-lite-test/main/app_power_modbus.c:10:
E:/MyProject/IoT/PlatformIO-ESP/esp-idf-mesh-lite/mesh-lite-test/main/app_power_modbus.c: In function 'master_init':
E:/MyProject/IoT/esp/esp-idf/components/log/include/esp_log.h:265:27: error: format '%x' expects argument of type 'unsigned int', but argument 8 has type 'long unsigned int' [-Werror=format=]
  265 | #define LOG_COLOR(COLOR)  "\033[0;" COLOR "m"

E:/MyProject/IoT/esp/esp-idf/components/log/include/esp_log.h:340:38: note: in expansion of macro 'ESP_LOG_LEVEL_LOCAL'
  340 | #define ESP_LOGE( tag, format, ... ) ESP_LOG_LEVEL_LOCAL(ESP_LOG_ERROR,   tag, format, ##__VA_ARGS__)
      |                                      ^~~~~~~~~~~~~~~~~~~
E:/MyProject/IoT/esp/esp-idf/components/esp_common/include/esp_check.h:264:13: note: in expansion of macro 'ESP_LOGE'
  264 |             ESP_LOGE(log_tag, "%s(%d): " format, __FUNCTION__, __LINE__, ##__VA_ARGS__);        \
      |             ^~~~~~~~
E:/MyProject/IoT/PlatformIO-ESP/esp-idf-mesh-lite/mesh-lite-test/managed_components/espressif__esp-modbus/freemodbus/common/include/esp_modbus_common.h:21:59: note: in expansion of macro 'ESP_RETURN_ON_FALSE'       
   21 | #define MB_RETURN_ON_FALSE(a, err_code, tag, format, ...) ESP_RETURN_ON_FALSE(a, err_code, tag, format __VA_OPT__(,) __VA_ARGS__)
      |                                                           ^~~~~~~~~~~~~~~~~~~
E:/MyProject/IoT/PlatformIO-ESP/esp-idf-mesh-lite/mesh-lite-test/main/app_power_modbus.c:208:5: note: in expansion of macro 'MB_RETURN_ON_FALSE'
  208 |     MB_RETURN_ON_FALSE((err == ESP_OK), ESP_ERR_INVALID_STATE, TAG,
      |     ^~~~~~~~~~~~~~~~~~
cc1.exe: some warnings being treated as errors
ninja: build stopped: subcommand failed.
// Modbus master initialization
static esp_err_t master_init(void)
{
    // Initialize and start Modbus controller
    mb_communication_info_t comm = {
        .port = MB_PORT_NUM,
#if CONFIG_MB_COMM_MODE_ASCII
        .mode = MB_MODE_ASCII,
#elif CONFIG_MB_COMM_MODE_RTU
        .mode = MB_MODE_RTU,
#endif
        .baudrate = MB_UART_SPEED,
        .parity = MB_PARITY_NONE
    };
    void *master_handler = NULL;

    esp_err_t err = mbc_master_init(MB_PORT_SERIAL_MASTER, &master_handler);
    MB_RETURN_ON_FALSE((master_handler != NULL), ESP_ERR_INVALID_STATE, TAG,
                       "mb controller initialization fail.");
    MB_RETURN_ON_FALSE((err == ESP_OK), ESP_ERR_INVALID_STATE, TAG,
                       "mb controller initialization fail, returns(0x%x).",
                       (uint32_t)err);
    err = mbc_master_setup((void *)&comm);
    MB_RETURN_ON_FALSE((err == ESP_OK), ESP_ERR_INVALID_STATE, TAG,
                       "mb controller setup fail, returns(0x%x).",
                       (uint32_t)err);

    // Set UART pin numbers
    err = uart_set_pin(MB_PORT_NUM, MB_UART_TXD, MB_UART_RXD, CONFIG_MB_UART_RTS, UART_PIN_NO_CHANGE);
    MB_RETURN_ON_FALSE((err == ESP_OK), ESP_ERR_INVALID_STATE, TAG,
                       "mb serial set pin failure, uart_set_pin() returned (0x%x).", (uint32_t)err);

    err = mbc_master_start();
    MB_RETURN_ON_FALSE((err == ESP_OK), ESP_ERR_INVALID_STATE, TAG,
                       "mb controller start fail, returns(0x%x).",
                       (uint32_t)err);

    // Set driver mode to Half Duplex
    err = uart_set_mode(MB_PORT_NUM, UART_MODE_RS485_HALF_DUPLEX);
    MB_RETURN_ON_FALSE((err == ESP_OK), ESP_ERR_INVALID_STATE, TAG,
                       "mb serial set mode failure, uart_set_mode() returned (0x%x).", (uint32_t)err);

    vTaskDelay(5);
    err = mbc_master_set_descriptor(&device_parameters[0], num_device_parameters);
    MB_RETURN_ON_FALSE((err == ESP_OK), ESP_ERR_INVALID_STATE, TAG,
                       "mb controller set descriptor fail, returns(0x%x).",
                       (uint32_t)err);
    ESP_LOGI(TAG, "Modbus master stack initialized...");
    return err;
}
yel-best commented 5 months ago

But when I comment out the code about MB_RETURN_ON_FALSE, it compiles normally. Is it because of compatibility issues?

// MB_RETURN_ON_FALSE((master_handler != NULL), ESP_ERR_INVALID_STATE, TAG, // "mb controller initialization fail."); // MB_RETURN_ON_FALSE((err == ESP_OK), ESP_ERR_INVALID_STATE, TAG, // "mb controller initialization fail, returns(0x%x).", // (uint32_t)err);

image

tswen commented 5 months ago

Printed type does not match actual type

error: format '%x' expects argument of type 'unsigned int', but argument 8 has type 'long unsigned int' [-Werror=format=]

yel-best commented 5 months ago

Printed type does not match actual type

error: format '%x' expects argument of type 'unsigned int', but argument 8 has type 'long unsigned int' [-Werror=format=]

yes, this question has been answered by the modbus components team. Thank you very much for your concern, thanks