fix(esp-modem): Add filename/line info to exception message

This is useful if exceptions are enabled, but caught internally on C++ API boundary
This commit is contained in:
David Cermak
2022-07-13 08:45:43 +02:00
parent 341fcb0f40
commit 89e1bd27b3
13 changed files with 58 additions and 36 deletions

View File

@ -56,7 +56,7 @@ command_result DTE::command(const std::string &command, got_line_cb got_line, ui
command_term->write((uint8_t *)command.c_str(), command.length());
auto got_lf = signal.wait(GOT_LINE, time_ms);
if (got_lf && res == command_result::TIMEOUT) {
throw_if_esp_fail(ESP_ERR_INVALID_STATE);
ESP_MODEM_THROW_IF_ERROR(ESP_ERR_INVALID_STATE);
}
buffer.consumed = 0;
command_term->set_read_cb(nullptr);

View File

@ -82,11 +82,11 @@ Netif::Netif(std::shared_ptr<DTE> e, esp_netif_t *ppp_netif) :
driver.base.netif = ppp_netif;
driver.ppp = this;
driver.base.post_attach = esp_modem_post_attach;
throw_if_esp_fail(esp_event_handler_register(NETIF_PPP_STATUS, ESP_EVENT_ANY_ID, &on_ppp_changed, (void *) this));
throw_if_esp_fail(esp_event_handler_register(IP_EVENT, IP_EVENT_PPP_GOT_IP, esp_netif_action_connected, ppp_netif));
throw_if_esp_fail(
ESP_MODEM_THROW_IF_ERROR(esp_event_handler_register(NETIF_PPP_STATUS, ESP_EVENT_ANY_ID, &on_ppp_changed, (void *) this));
ESP_MODEM_THROW_IF_ERROR(esp_event_handler_register(IP_EVENT, IP_EVENT_PPP_GOT_IP, esp_netif_action_connected, ppp_netif));
ESP_MODEM_THROW_IF_ERROR(
esp_event_handler_register(IP_EVENT, IP_EVENT_PPP_LOST_IP, esp_netif_action_disconnected, ppp_netif));
throw_if_esp_fail(esp_netif_attach(ppp_netif, &driver));
ESP_MODEM_THROW_IF_ERROR(esp_netif_attach(ppp_netif, &driver));
}
void Netif::start()

View File

@ -28,7 +28,7 @@ void Lock::unlock()
Lock::Lock(): m(nullptr)
{
m = xSemaphoreCreateRecursiveMutex();
throw_if_false(m != nullptr, "create signal event group failed");
ESP_MODEM_THROW_IF_FALSE(m != nullptr, "create signal event group failed");
}
Lock::~Lock()
@ -45,7 +45,7 @@ void Lock::lock()
SignalGroup::SignalGroup(): event_group(nullptr)
{
event_group = xEventGroupCreate();
throw_if_false(event_group != nullptr, "create signal event group failed");
ESP_MODEM_THROW_IF_FALSE(event_group != nullptr, "create signal event group failed");
}
void SignalGroup::set(uint32_t bits)
@ -86,7 +86,7 @@ Task::Task(size_t stack_size, size_t priority, void *task_param, TaskFunction_t
: task_handle(nullptr)
{
BaseType_t ret = xTaskCreate(task_function, "vfs_task", stack_size, task_param, priority, &task_handle);
throw_if_false(ret == pdTRUE, "create vfs task failed");
ESP_MODEM_THROW_IF_FALSE(ret == pdTRUE, "create vfs task failed");
}
Task::~Task()

View File

@ -40,7 +40,7 @@ uart_resource::uart_resource(const esp_modem_uart_term_config *config, QueueHand
: UART_HW_FLOWCTRL_DISABLE;
uart_config.source_clk = config->source_clk;
throw_if_esp_fail(uart_param_config(config->port_num, &uart_config), "config uart parameter failed");
ESP_MODEM_THROW_IF_ERROR(uart_param_config(config->port_num, &uart_config), "config uart parameter failed");
if (config->flow_control == ESP_MODEM_FLOW_CONTROL_HW) {
res = uart_set_pin(config->port_num, config->tx_io_num, config->rx_io_num,
@ -49,24 +49,24 @@ uart_resource::uart_resource(const esp_modem_uart_term_config *config, QueueHand
res = uart_set_pin(config->port_num, config->tx_io_num, config->rx_io_num,
UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE);
}
throw_if_esp_fail(res, "config uart gpio failed");
ESP_MODEM_THROW_IF_ERROR(res, "config uart gpio failed");
/* Set flow control threshold */
if (config->flow_control == ESP_MODEM_FLOW_CONTROL_HW) {
res = uart_set_hw_flow_ctrl(config->port_num, UART_HW_FLOWCTRL_CTS_RTS, UART_FIFO_LEN - 8);
} else if (config->flow_control == ESP_MODEM_FLOW_CONTROL_SW) {
res = uart_set_sw_flow_ctrl(config->port_num, true, 8, UART_FIFO_LEN - 8);
}
throw_if_esp_fail(res, "config uart flow control failed");
ESP_MODEM_THROW_IF_ERROR(res, "config uart flow control failed");
/* Install UART driver and get event queue used inside driver */
res = uart_driver_install(config->port_num,
config->rx_buffer_size, config->tx_buffer_size,
config->event_queue_size, config->event_queue_size ? event_queue : nullptr,
0);
throw_if_esp_fail(res, "install uart driver failed");
throw_if_esp_fail(uart_set_rx_timeout(config->port_num, 1), "set rx timeout failed");
ESP_MODEM_THROW_IF_ERROR(res, "install uart driver failed");
ESP_MODEM_THROW_IF_ERROR(uart_set_rx_timeout(config->port_num, 1), "set rx timeout failed");
throw_if_esp_fail(uart_set_rx_full_threshold(config->port_num, 64), "config rx full threshold failed");
ESP_MODEM_THROW_IF_ERROR(uart_set_rx_full_threshold(config->port_num, 64), "config rx full threshold failed");
/* mark UART as initialized */
port = config->port_num;

View File

@ -33,7 +33,7 @@ struct uart_task {
task_handle(nullptr)
{
BaseType_t ret = xTaskCreate(task_function, "uart_task", stack_size, task_param, priority, &task_handle);
throw_if_false(ret == pdTRUE, "create uart event task failed");
ESP_MODEM_THROW_IF_FALSE(ret == pdTRUE, "create uart event task failed");
}
~uart_task()

View File

@ -27,7 +27,7 @@ uart_resource::uart_resource(const esp_modem_uart_term_config *config, QueueHand
{
ESP_LOGD(TAG, "Creating uart resource" );
struct termios tty = {};
throw_if_false(tcgetattr(fd, &tty) == 0, "Failed to tcgetattr()");
ESP_MODEM_THROW_IF_FALSE(tcgetattr(fd, &tty) == 0, "Failed to tcgetattr()");
tty.c_cflag &= ~PARENB;
tty.c_cflag &= ~CSTOPB;

View File

@ -91,7 +91,7 @@ bool vfs_create_socket(struct esp_modem_vfs_socket_creator *config, struct esp_m
}
TRY_CATCH_OR_DO(
int fd = -1;
esp_modem::throw_if_esp_fail(hostname_to_fd(config->host_name, config->port, &fd));
ESP_MODEM_THROW_IF_ERROR(hostname_to_fd(config->host_name, config->port, &fd));
// Set the FD to non-blocking mode
int flags = fcntl(fd, F_GETFL, nullptr) | O_NONBLOCK;

View File

@ -48,7 +48,7 @@ bool vfs_create_uart(struct esp_modem_vfs_uart_creator *config, struct esp_modem
}
TRY_CATCH_OR_DO(
int fd = open(config->dev_name, O_RDWR);
esp_modem::throw_if_false(fd >= 0, "Cannot open the fd");
ESP_MODEM_THROW_IF_FALSE(fd >= 0, "Cannot open the fd");
created_config->resource = new esp_modem_vfs_resource(&config->uart, fd);
created_config->fd = fd;