|
|
@@ -1,5 +1,5 @@
|
|
|
/*
|
|
|
- * SPDX-FileCopyrightText: 2016-2022 Espressif Systems (Shanghai) CO LTD
|
|
|
+ * SPDX-FileCopyrightText: 2016-2023 Espressif Systems (Shanghai) CO LTD
|
|
|
*
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
*/
|
|
|
@@ -11,11 +11,12 @@
|
|
|
#include "esp_log.h"
|
|
|
#include "esp_system.h"
|
|
|
#include "esp_wifi.h"
|
|
|
-#include "esp_mac.h"
|
|
|
#include "esp_event.h"
|
|
|
#include "esp_log.h"
|
|
|
#include "nvs_flash.h"
|
|
|
#include "esp_netif.h"
|
|
|
+#include "esp_mac.h"
|
|
|
+
|
|
|
#include "mdns.h"
|
|
|
#include "protocol_examples_common.h"
|
|
|
|
|
|
@@ -69,7 +70,7 @@ static const char *TAG = "MASTER_TEST";
|
|
|
// Enumeration of modbus device addresses accessed by master device
|
|
|
// Each address in the table is a index of TCP slave ip address in mb_communication_info_t::tcp_ip_addr table
|
|
|
enum {
|
|
|
- MB_DEVICE_ADDR1 = 1, // Slave address 1
|
|
|
+ MB_DEVICE_ADDR1 = 1, // Slave UID = 1
|
|
|
MB_DEVICE_ADDR2 = 200,
|
|
|
MB_DEVICE_ADDR3 = 35
|
|
|
};
|
|
|
@@ -85,6 +86,7 @@ enum {
|
|
|
CID_HOLD_TEST_REG,
|
|
|
CID_RELAY_P1,
|
|
|
CID_RELAY_P2,
|
|
|
+ CID_DISCR_P1,
|
|
|
CID_COUNT
|
|
|
};
|
|
|
|
|
|
@@ -100,9 +102,9 @@ enum {
|
|
|
const mb_parameter_descriptor_t device_parameters[] = {
|
|
|
// { CID, Param Name, Units, Modbus Slave Addr, Modbus Reg Type, Reg Start, Reg Size, Instance Offset, Data Type, Data Size, Parameter Options, Access Mode}
|
|
|
{ CID_INP_DATA_0, STR("Data_channel_0"), STR("Volts"), MB_DEVICE_ADDR1, MB_PARAM_INPUT, 0, 2,
|
|
|
- INPUT_OFFSET(input_data0), PARAM_TYPE_FLOAT, 4, OPTS( -10, 10, 1 ), PAR_PERMS_READ_WRITE_TRIGGER },
|
|
|
+ INPUT_OFFSET(input_data0), PARAM_TYPE_FLOAT, 4, OPTS( -10, 10, 1 ), PAR_PERMS_READ_WRITE_TRIGGER },
|
|
|
{ CID_HOLD_DATA_0, STR("Humidity_1"), STR("%rH"), MB_DEVICE_ADDR1, MB_PARAM_HOLDING, 0, 2,
|
|
|
- HOLD_OFFSET(holding_data0), PARAM_TYPE_FLOAT, 4, OPTS( 0, 100, 1 ), PAR_PERMS_READ_WRITE_TRIGGER },
|
|
|
+ HOLD_OFFSET(holding_data0), PARAM_TYPE_FLOAT, 4, OPTS( 0, 1000, 1 ), PAR_PERMS_READ_WRITE_TRIGGER },
|
|
|
{ CID_INP_DATA_1, STR("Temperature_1"), STR("C"), MB_DEVICE_ADDR1, MB_PARAM_INPUT, 2, 2,
|
|
|
INPUT_OFFSET(input_data1), PARAM_TYPE_FLOAT, 4, OPTS( -40, 100, 1 ), PAR_PERMS_READ_WRITE_TRIGGER },
|
|
|
{ CID_HOLD_DATA_1, STR("Humidity_2"), STR("%rH"), MB_DEVICE_ADDR2, MB_PARAM_HOLDING, 2, 2,
|
|
|
@@ -111,12 +113,14 @@ const mb_parameter_descriptor_t device_parameters[] = {
|
|
|
INPUT_OFFSET(input_data2), PARAM_TYPE_FLOAT, 4, OPTS( -40, 100, 1 ), PAR_PERMS_READ_WRITE_TRIGGER },
|
|
|
{ CID_HOLD_DATA_2, STR("Humidity_3"), STR("%rH"), MB_DEVICE_ADDR3, MB_PARAM_HOLDING, 4, 2,
|
|
|
HOLD_OFFSET(holding_data2), PARAM_TYPE_FLOAT, 4, OPTS( 0, 100, 1 ), PAR_PERMS_READ_WRITE_TRIGGER },
|
|
|
- { CID_HOLD_TEST_REG, STR("Test_regs"), STR("__"), MB_DEVICE_ADDR1, MB_PARAM_HOLDING, 8, 100,
|
|
|
- HOLD_OFFSET(test_regs), PARAM_TYPE_ASCII, 200, OPTS( 0, 100, 1 ), PAR_PERMS_READ_WRITE_TRIGGER },
|
|
|
- { CID_RELAY_P1, STR("RelayP1"), STR("on/off"), MB_DEVICE_ADDR1, MB_PARAM_COIL, 0, 8,
|
|
|
- COIL_OFFSET(coils_port0), PARAM_TYPE_U16, 1, OPTS( BIT1, 0, 0 ), PAR_PERMS_READ_WRITE_TRIGGER },
|
|
|
- { CID_RELAY_P2, STR("RelayP2"), STR("on/off"), MB_DEVICE_ADDR1, MB_PARAM_COIL, 8, 8,
|
|
|
- COIL_OFFSET(coils_port1), PARAM_TYPE_U16, 1, OPTS( BIT0, 0, 0 ), PAR_PERMS_READ_WRITE_TRIGGER }
|
|
|
+ { CID_HOLD_TEST_REG, STR("Test_regs"), STR("__"), MB_DEVICE_ADDR1, MB_PARAM_HOLDING, 10, 58,
|
|
|
+ HOLD_OFFSET(test_regs), PARAM_TYPE_ASCII, 116, OPTS( 0, 100, 1 ), PAR_PERMS_READ_WRITE_TRIGGER },
|
|
|
+ { CID_RELAY_P1, STR("RelayP1"), STR("on/off"), MB_DEVICE_ADDR1, MB_PARAM_COIL, 2, 6,
|
|
|
+ COIL_OFFSET(coils_port0), PARAM_TYPE_U8, 1, OPTS( 0xAA, 0x15, 0 ), PAR_PERMS_READ_WRITE_TRIGGER },
|
|
|
+ { CID_RELAY_P2, STR("RelayP2"), STR("on/off"), MB_DEVICE_ADDR1, MB_PARAM_COIL, 10, 6,
|
|
|
+ COIL_OFFSET(coils_port1), PARAM_TYPE_U8, 1, OPTS( 0x55, 0x2A, 0 ), PAR_PERMS_READ_WRITE_TRIGGER },
|
|
|
+ { CID_DISCR_P1, STR("DiscreteInpP1"), STR("on/off"), MB_DEVICE_ADDR1, MB_PARAM_DISCRETE, 2, 7,
|
|
|
+ DISCR_OFFSET(discrete_input_port1), PARAM_TYPE_U8, 1, OPTS( 0xAA, 0x15, 0 ), PAR_PERMS_READ_WRITE_TRIGGER }
|
|
|
};
|
|
|
|
|
|
// Calculate number of parameters in the table
|
|
|
@@ -146,7 +150,7 @@ const size_t ip_table_sz = (size_t)(sizeof(slave_ip_address_table) / sizeof(slav
|
|
|
char* master_scan_addr(int* index, char* buffer)
|
|
|
{
|
|
|
char* ip_str = NULL;
|
|
|
- unsigned int a[8] = {0};
|
|
|
+ int a[8] = {0};
|
|
|
int buf_cnt = 0;
|
|
|
#if !CONFIG_EXAMPLE_CONNECT_IPV6
|
|
|
buf_cnt = sscanf(buffer, "IP%d="IPSTR, index, &a[0], &a[1], &a[2], &a[3]);
|
|
|
@@ -301,8 +305,8 @@ static esp_err_t master_resolve_slave(uint8_t short_addr, mdns_result_t* result,
|
|
|
char* slave_ip = NULL;
|
|
|
char slave_name[22] = {0};
|
|
|
|
|
|
- if (sprintf(slave_name, "mb_slave_tcp_%02X", short_addr) < 0) {
|
|
|
- ESP_LOGE(TAG, "Fail to create instance name for index: %d", short_addr);
|
|
|
+ if (sprintf(slave_name, "mb_slave_tcp_%02" PRIx8, (int)short_addr) < 0) {
|
|
|
+ ESP_LOGE(TAG, "Fail to create instance name for index: %u", (unsigned)short_addr);
|
|
|
abort();
|
|
|
}
|
|
|
for (; r ; r = r->next) {
|
|
|
@@ -316,7 +320,7 @@ static esp_err_t master_resolve_slave(uint8_t short_addr, mdns_result_t* result,
|
|
|
if ((strcmp(r->instance_name, slave_name) == 0) && (r->port == CONFIG_FMB_TCP_PORT_DEFAULT)) {
|
|
|
printf(" PTR : %s\n", r->instance_name);
|
|
|
if (r->txt_count) {
|
|
|
- printf(" TXT : [%u] ", r->txt_count);
|
|
|
+ printf(" TXT : [%u] ", (unsigned)r->txt_count);
|
|
|
for ( t = 0; t < r->txt_count; t++) {
|
|
|
printf("%s=%s; ", r->txt[t].key, r->txt[t].value?r->txt[t].value:"NULL");
|
|
|
}
|
|
|
@@ -324,7 +328,7 @@ static esp_err_t master_resolve_slave(uint8_t short_addr, mdns_result_t* result,
|
|
|
}
|
|
|
slave_ip = master_get_slave_ip_str(r->addr, addr_type);
|
|
|
if (slave_ip) {
|
|
|
- ESP_LOGI(TAG, "Resolved slave %s[%s]:%u", r->hostname, slave_ip, r->port);
|
|
|
+ ESP_LOGI(TAG, "Resolved slave %s[%s]:%u", r->hostname, slave_ip, (unsigned)r->port);
|
|
|
*resolved_ip = slave_ip;
|
|
|
return ESP_OK;
|
|
|
}
|
|
|
@@ -341,7 +345,8 @@ static int master_create_slave_list(mdns_result_t* results, char** addr_table,
|
|
|
if (!results) {
|
|
|
return -1;
|
|
|
}
|
|
|
- int i, slave_addr, cid_resolve_cnt = 0;
|
|
|
+ int i, cid_resolve_cnt = 0;
|
|
|
+ uint8_t slave_addr = 0;
|
|
|
int ip_index = 0;
|
|
|
const mb_parameter_descriptor_t* pdescr = &device_parameters[0];
|
|
|
char** ip_table = addr_table;
|
|
|
@@ -363,7 +368,7 @@ static int master_create_slave_list(mdns_result_t* results, char** addr_table,
|
|
|
// Resolve new slave IP address using its short address
|
|
|
esp_err_t err = master_resolve_slave(slave_addr, results, &slave_ip, addr_type);
|
|
|
if (err != ESP_OK) {
|
|
|
- ESP_LOGE(TAG, "Index: %d, sl_addr: %d, failed to resolve!", i, slave_addr);
|
|
|
+ ESP_LOGE(TAG, "Index: %d, sl_addr: %u, failed to resolve!", i, slave_addr);
|
|
|
// Set correspond index to NULL indicate host not resolved
|
|
|
ip_table[ip_index] = NULL;
|
|
|
continue;
|
|
|
@@ -379,15 +384,15 @@ static int master_create_slave_list(mdns_result_t* results, char** addr_table,
|
|
|
new_slave_entry->p_data = NULL;
|
|
|
LIST_INSERT_HEAD(&slave_addr_list, new_slave_entry, entries);
|
|
|
ip_table[ip_index] = slave_ip;
|
|
|
- ESP_LOGI(TAG, "Index: %d, sl_addr: %d, resolved to IP: [%s]",
|
|
|
- i, slave_addr, slave_ip);
|
|
|
+ ESP_LOGI(TAG, "Index: %d, sl_addr: %u, resolved to IP: [%s]",
|
|
|
+ i, slave_addr, slave_ip);
|
|
|
cid_resolve_cnt++;
|
|
|
if (ip_index < addr_table_size) {
|
|
|
ip_index++;
|
|
|
}
|
|
|
} else {
|
|
|
ip_table[ip_index] = it ? it->ip_address : ip_table[ip_index];
|
|
|
- ESP_LOGI(TAG, "Index: %d, sl_addr: %d, set to IP: [%s]",
|
|
|
+ ESP_LOGI(TAG, "Index: %d, sl_addr: %u, set to IP: [%s]",
|
|
|
i, slave_addr, ip_table[ip_index]);
|
|
|
cid_resolve_cnt++;
|
|
|
}
|
|
|
@@ -425,7 +430,7 @@ static void master_destroy_slave_list(char** table, size_t ip_table_size)
|
|
|
{
|
|
|
#if CONFIG_MB_MDNS_IP_RESOLVER
|
|
|
slave_addr_entry_t *it;
|
|
|
- LIST_FOREACH(it, &slave_addr_list, entries) {
|
|
|
+ while ((it = LIST_FIRST(&slave_addr_list))) {
|
|
|
LIST_REMOVE(it, entries);
|
|
|
free(it);
|
|
|
}
|
|
|
@@ -467,7 +472,7 @@ static void* master_get_param_data(const mb_parameter_descriptor_t* param_descri
|
|
|
break;
|
|
|
}
|
|
|
} else {
|
|
|
- ESP_LOGE(TAG, "Wrong parameter offset for CID #%d", param_descriptor->cid);
|
|
|
+ ESP_LOGE(TAG, "Wrong parameter offset for CID #%u", param_descriptor->cid);
|
|
|
assert(instance_ptr != NULL);
|
|
|
}
|
|
|
return instance_ptr;
|
|
|
@@ -499,13 +504,13 @@ static void master_operation_func(void *arg)
|
|
|
(param_descriptor->cid == CID_HOLD_TEST_REG)) {
|
|
|
// Check for long array of registers of type PARAM_TYPE_ASCII
|
|
|
err = mbc_master_get_parameter(cid, (char*)param_descriptor->param_key,
|
|
|
- (uint8_t*)temp_data_ptr, &type);
|
|
|
+ (uint8_t*)temp_data_ptr, &type);
|
|
|
if (err == ESP_OK) {
|
|
|
- ESP_LOGI(TAG, "Characteristic #%d %s (%s) value = (0x%08x) read successful.",
|
|
|
- param_descriptor->cid,
|
|
|
- (char*)param_descriptor->param_key,
|
|
|
- (char*)param_descriptor->param_units,
|
|
|
- *(uint32_t*)temp_data_ptr);
|
|
|
+ ESP_LOGI(TAG, "Characteristic #%u %s (%s) value = (0x%" PRIx32 ") read successful.",
|
|
|
+ param_descriptor->cid,
|
|
|
+ param_descriptor->param_key,
|
|
|
+ param_descriptor->param_units,
|
|
|
+ *(uint32_t*)temp_data_ptr);
|
|
|
// Initialize data of test array and write to slave
|
|
|
if (*(uint32_t*)temp_data_ptr != 0xAAAAAAAA) {
|
|
|
memset((void*)temp_data_ptr, 0xAA, param_descriptor->param_size);
|
|
|
@@ -513,25 +518,25 @@ static void master_operation_func(void *arg)
|
|
|
err = mbc_master_set_parameter(cid, (char*)param_descriptor->param_key,
|
|
|
(uint8_t*)temp_data_ptr, &type);
|
|
|
if (err == ESP_OK) {
|
|
|
- ESP_LOGI(TAG, "Characteristic #%d %s (%s) value = (0x%08x), write successful.",
|
|
|
- param_descriptor->cid,
|
|
|
- (char*)param_descriptor->param_key,
|
|
|
- (char*)param_descriptor->param_units,
|
|
|
- *(uint32_t*)temp_data_ptr);
|
|
|
+ ESP_LOGI(TAG, "Characteristic #%u %s (%s) value = (0x%" PRIx32 "), write successful.",
|
|
|
+ param_descriptor->cid,
|
|
|
+ param_descriptor->param_key,
|
|
|
+ param_descriptor->param_units,
|
|
|
+ *(uint32_t*)temp_data_ptr);
|
|
|
} else {
|
|
|
- ESP_LOGE(TAG, "Characteristic #%d (%s) write fail, err = 0x%x (%s).",
|
|
|
- param_descriptor->cid,
|
|
|
- (char*)param_descriptor->param_key,
|
|
|
- (int)err,
|
|
|
- (char*)esp_err_to_name(err));
|
|
|
- }
|
|
|
- }
|
|
|
- } else {
|
|
|
- ESP_LOGE(TAG, "Characteristic #%d (%s) read fail, err = 0x%x (%s).",
|
|
|
+ ESP_LOGE(TAG, "Characteristic #%u (%s) write fail, err = 0x%x (%s).",
|
|
|
param_descriptor->cid,
|
|
|
- (char*)param_descriptor->param_key,
|
|
|
+ param_descriptor->param_key,
|
|
|
(int)err,
|
|
|
(char*)esp_err_to_name(err));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ ESP_LOGE(TAG, "Characteristic #%u (%s) read fail, err = 0x%x (%s).",
|
|
|
+ param_descriptor->cid,
|
|
|
+ param_descriptor->param_key,
|
|
|
+ (int)err,
|
|
|
+ (char*)esp_err_to_name(err));
|
|
|
}
|
|
|
} else {
|
|
|
err = mbc_master_get_parameter(cid, (char*)param_descriptor->param_key,
|
|
|
@@ -540,10 +545,10 @@ static void master_operation_func(void *arg)
|
|
|
if ((param_descriptor->mb_param_type == MB_PARAM_HOLDING) ||
|
|
|
(param_descriptor->mb_param_type == MB_PARAM_INPUT)) {
|
|
|
value = *(float*)temp_data_ptr;
|
|
|
- ESP_LOGI(TAG, "Characteristic #%d %s (%s) value = %f (0x%x) read successful.",
|
|
|
+ ESP_LOGI(TAG, "Characteristic #%u %s (%s) value = %f (0x%" PRIx32 ") read successful.",
|
|
|
param_descriptor->cid,
|
|
|
- (char*)param_descriptor->param_key,
|
|
|
- (char*)param_descriptor->param_units,
|
|
|
+ param_descriptor->param_key,
|
|
|
+ param_descriptor->param_units,
|
|
|
value,
|
|
|
*(uint32_t*)temp_data_ptr);
|
|
|
if (((value > param_descriptor->param_opts.max) ||
|
|
|
@@ -554,21 +559,32 @@ static void master_operation_func(void *arg)
|
|
|
} else {
|
|
|
uint8_t state = *(uint8_t*)temp_data_ptr;
|
|
|
const char* rw_str = (state & param_descriptor->param_opts.opt1) ? "ON" : "OFF";
|
|
|
- ESP_LOGI(TAG, "Characteristic #%d %s (%s) value = %s (0x%x) read successful.",
|
|
|
+ if ((state & param_descriptor->param_opts.opt2) == param_descriptor->param_opts.opt2) {
|
|
|
+ ESP_LOGI(TAG, "Characteristic #%u %s (%s) value = %s (0x%" PRIx8 ") read successful.",
|
|
|
+ param_descriptor->cid,
|
|
|
+ param_descriptor->param_key,
|
|
|
+ param_descriptor->param_units,
|
|
|
+ rw_str,
|
|
|
+ *(uint8_t*)temp_data_ptr);
|
|
|
+ } else {
|
|
|
+ ESP_LOGE(TAG, "Characteristic #%u %s (%s) value = %s (0x%" PRIx8 "), unexpected value.",
|
|
|
param_descriptor->cid,
|
|
|
- (char*)param_descriptor->param_key,
|
|
|
- (char*)param_descriptor->param_units,
|
|
|
- (const char*)rw_str,
|
|
|
+ param_descriptor->param_key,
|
|
|
+ param_descriptor->param_units,
|
|
|
+ rw_str,
|
|
|
*(uint8_t*)temp_data_ptr);
|
|
|
+ alarm_state = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
if (state & param_descriptor->param_opts.opt1) {
|
|
|
alarm_state = true;
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
} else {
|
|
|
- ESP_LOGE(TAG, "Characteristic #%d (%s) read fail, err = 0x%x (%s).",
|
|
|
+ ESP_LOGE(TAG, "Characteristic #%u (%s) read fail, err = 0x%x (%s).",
|
|
|
param_descriptor->cid,
|
|
|
- (char*)param_descriptor->param_key,
|
|
|
+ param_descriptor->param_key,
|
|
|
(int)err,
|
|
|
(char*)esp_err_to_name(err));
|
|
|
}
|
|
|
@@ -580,10 +596,9 @@ static void master_operation_func(void *arg)
|
|
|
}
|
|
|
|
|
|
if (alarm_state) {
|
|
|
- ESP_LOGI(TAG, "Alarm triggered by cid #%d.",
|
|
|
- param_descriptor->cid);
|
|
|
+ ESP_LOGI(TAG, "Alarm triggered by cid #%u.", param_descriptor->cid);
|
|
|
} else {
|
|
|
- ESP_LOGE(TAG, "Alarm is not triggered after %d retries.",
|
|
|
+ ESP_LOGE(TAG, "Alarm is not triggered after %u retries.",
|
|
|
MASTER_MAX_RETRY);
|
|
|
}
|
|
|
ESP_LOGI(TAG, "Destroy master...");
|
|
|
@@ -600,17 +615,17 @@ static esp_err_t init_services(mb_tcp_addr_type_t ip_addr_type)
|
|
|
MB_RETURN_ON_FALSE((result == ESP_OK), ESP_ERR_INVALID_STATE,
|
|
|
TAG,
|
|
|
"nvs_flash_init fail, returns(0x%x).",
|
|
|
- (uint32_t)result);
|
|
|
+ (int)result);
|
|
|
result = esp_netif_init();
|
|
|
MB_RETURN_ON_FALSE((result == ESP_OK), ESP_ERR_INVALID_STATE,
|
|
|
TAG,
|
|
|
"esp_netif_init fail, returns(0x%x).",
|
|
|
- (uint32_t)result);
|
|
|
+ (int)result);
|
|
|
result = esp_event_loop_create_default();
|
|
|
MB_RETURN_ON_FALSE((result == ESP_OK), ESP_ERR_INVALID_STATE,
|
|
|
TAG,
|
|
|
"esp_event_loop_create_default fail, returns(0x%x).",
|
|
|
- (uint32_t)result);
|
|
|
+ (int)result);
|
|
|
#if CONFIG_MB_MDNS_IP_RESOLVER
|
|
|
// Start mdns service and register device
|
|
|
master_start_mdns_service();
|
|
|
@@ -622,13 +637,13 @@ static esp_err_t init_services(mb_tcp_addr_type_t ip_addr_type)
|
|
|
MB_RETURN_ON_FALSE((result == ESP_OK), ESP_ERR_INVALID_STATE,
|
|
|
TAG,
|
|
|
"example_connect fail, returns(0x%x).",
|
|
|
- (uint32_t)result);
|
|
|
+ (int)result);
|
|
|
#if CONFIG_EXAMPLE_CONNECT_WIFI
|
|
|
result = esp_wifi_set_ps(WIFI_PS_NONE);
|
|
|
MB_RETURN_ON_FALSE((result == ESP_OK), ESP_ERR_INVALID_STATE,
|
|
|
TAG,
|
|
|
"esp_wifi_set_ps fail, returns(0x%x).",
|
|
|
- (uint32_t)result);
|
|
|
+ (int)result);
|
|
|
#endif
|
|
|
#if CONFIG_MB_MDNS_IP_RESOLVER
|
|
|
int res = 0;
|
|
|
@@ -636,7 +651,7 @@ static esp_err_t init_services(mb_tcp_addr_type_t ip_addr_type)
|
|
|
res = master_query_slave_service("_modbus", "_tcp", ip_addr_type);
|
|
|
}
|
|
|
if (res < num_device_parameters) {
|
|
|
- ESP_LOGE(TAG, "Could not resolve one or more slave IP addresses, resolved: %d out of %d.", res, num_device_parameters );
|
|
|
+ ESP_LOGE(TAG, "Could not resolve one or more slave IP addresses, resolved: %d out of %u.", res, (unsigned)num_device_parameters );
|
|
|
ESP_LOGE(TAG, "Make sure you configured all slaves according to device parameter table and they alive in the network.");
|
|
|
return ESP_ERR_NOT_FOUND;
|
|
|
}
|
|
|
@@ -662,22 +677,22 @@ static esp_err_t destroy_services(void)
|
|
|
MB_RETURN_ON_FALSE((err == ESP_OK), ESP_ERR_INVALID_STATE,
|
|
|
TAG,
|
|
|
"example_disconnect fail, returns(0x%x).",
|
|
|
- (uint32_t)err);
|
|
|
+ (int)err);
|
|
|
err = esp_event_loop_delete_default();
|
|
|
MB_RETURN_ON_FALSE((err == ESP_OK), ESP_ERR_INVALID_STATE,
|
|
|
TAG,
|
|
|
"esp_event_loop_delete_default fail, returns(0x%x).",
|
|
|
- (uint32_t)err);
|
|
|
+ (int)err);
|
|
|
err = esp_netif_deinit();
|
|
|
MB_RETURN_ON_FALSE((err == ESP_OK || err == ESP_ERR_NOT_SUPPORTED), ESP_ERR_INVALID_STATE,
|
|
|
TAG,
|
|
|
"esp_netif_deinit fail, returns(0x%x).",
|
|
|
- (uint32_t)err);
|
|
|
+ (int)err);
|
|
|
err = nvs_flash_deinit();
|
|
|
MB_RETURN_ON_FALSE((err == ESP_OK), ESP_ERR_INVALID_STATE,
|
|
|
TAG,
|
|
|
"nvs_flash_deinit fail, returns(0x%x).",
|
|
|
- (uint32_t)err);
|
|
|
+ (int)err);
|
|
|
return err;
|
|
|
}
|
|
|
|
|
|
@@ -693,26 +708,26 @@ static esp_err_t master_init(mb_communication_info_t* comm_info)
|
|
|
MB_RETURN_ON_FALSE((err == ESP_OK), ESP_ERR_INVALID_STATE,
|
|
|
TAG,
|
|
|
"mb controller initialization fail, returns(0x%x).",
|
|
|
- (uint32_t)err);
|
|
|
+ (int)err);
|
|
|
|
|
|
err = mbc_master_setup((void*)comm_info);
|
|
|
MB_RETURN_ON_FALSE((err == ESP_OK), ESP_ERR_INVALID_STATE,
|
|
|
TAG,
|
|
|
"mb controller setup fail, returns(0x%x).",
|
|
|
- (uint32_t)err);
|
|
|
+ (int)err);
|
|
|
|
|
|
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);
|
|
|
+ (int)err);
|
|
|
ESP_LOGI(TAG, "Modbus master stack initialized...");
|
|
|
|
|
|
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);
|
|
|
+ (int)err);
|
|
|
vTaskDelay(5);
|
|
|
return err;
|
|
|
}
|
|
|
@@ -723,7 +738,7 @@ static esp_err_t master_destroy(void)
|
|
|
MB_RETURN_ON_FALSE((err == ESP_OK), ESP_ERR_INVALID_STATE,
|
|
|
TAG,
|
|
|
"mbc_master_destroy fail, returns(0x%x).",
|
|
|
- (uint32_t)err);
|
|
|
+ (int)err);
|
|
|
ESP_LOGI(TAG, "Modbus master stack destroy...");
|
|
|
return err;
|
|
|
}
|
|
|
@@ -746,7 +761,6 @@ void app_main(void)
|
|
|
comm_info.ip_netif_ptr = (void*)get_example_netif();
|
|
|
|
|
|
ESP_ERROR_CHECK(master_init(&comm_info));
|
|
|
- vTaskDelay(50);
|
|
|
|
|
|
master_operation_func(NULL);
|
|
|
ESP_ERROR_CHECK(master_destroy());
|