Browse Source

tap_esc: improve error handling & reporting

sbg
Beat Küng 9 years ago committed by Lorenz Meier
parent
commit
3f9f320f18
  1. 28
      src/drivers/tap_esc/tap_esc.cpp

28
src/drivers/tap_esc/tap_esc.cpp

@ -114,7 +114,7 @@ private:
// It needs to support the numbe of ESC // It needs to support the numbe of ESC
int _control_subs[actuator_controls_s::NUM_ACTUATOR_CONTROL_GROUPS]; int _control_subs[actuator_controls_s::NUM_ACTUATOR_CONTROL_GROUPS];
px4_pollfd_struct_t _poll_fds[actuator_controls_s::NUM_ACTUATOR_CONTROL_GROUPS]; pollfd _poll_fds[actuator_controls_s::NUM_ACTUATOR_CONTROL_GROUPS];
actuator_controls_s _controls[actuator_controls_s::NUM_ACTUATOR_CONTROL_GROUPS]; actuator_controls_s _controls[actuator_controls_s::NUM_ACTUATOR_CONTROL_GROUPS];
@ -155,7 +155,7 @@ actuator_armed_s TAP_ESC::_armed = {};
namespace namespace
{ {
TAP_ESC *tap_esc; TAP_ESC *tap_esc = nullptr;
} }
# define TAP_ESC_DEVICE_PATH "/dev/tap_esc" # define TAP_ESC_DEVICE_PATH "/dev/tap_esc"
@ -292,7 +292,7 @@ TAP_ESC::init()
} }
} }
if (retries == 0 || !valid) { if (!valid) {
return -EIO; return -EIO;
} }
} }
@ -921,6 +921,7 @@ int tap_esc_start(void)
ret = tap_esc->init(); ret = tap_esc->init();
if (ret != OK) { if (ret != OK) {
PX4_ERR("failed to initialize tap_esc (%i)", ret);
delete tap_esc; delete tap_esc;
tap_esc = nullptr; tap_esc = nullptr;
} }
@ -946,7 +947,7 @@ int tap_esc_stop(void)
int initialise_uart() int initialise_uart()
{ {
// open uart // open uart
_uart_fd = px4_open(_device, O_RDWR | O_NOCTTY | O_NONBLOCK); _uart_fd = open(_device, O_RDWR | O_NOCTTY | O_NONBLOCK);
int termios_state = -1; int termios_state = -1;
if (_uart_fd < 0) { if (_uart_fd < 0) {
@ -964,14 +965,14 @@ int initialise_uart()
// set baud rate // set baud rate
if (cfsetispeed(&uart_config, speed) < 0 || cfsetospeed(&uart_config, speed) < 0) { if (cfsetispeed(&uart_config, speed) < 0 || cfsetospeed(&uart_config, speed) < 0) {
warnx("ERR SET BAUD %s: %d\n", _device, termios_state); PX4_ERR("failed to set baudrate for %s: %d\n", _device, termios_state);
::close(_uart_fd); close(_uart_fd);
return -1; return -1;
} }
if ((termios_state = tcsetattr(_uart_fd, TCSANOW, &uart_config)) < 0) { if ((termios_state = tcsetattr(_uart_fd, TCSANOW, &uart_config)) < 0) {
PX4_WARN("ERR SET CONF %s\n", _device); PX4_ERR("tcsetattr failed for %s\n", _device);
px4_close(_uart_fd); close(_uart_fd);
return -1; return -1;
} }
@ -1027,7 +1028,9 @@ void task_main(int argc, char *argv[])
} }
if (tap_esc_start() != OK) { if (tap_esc_start() != OK) {
PX4_ERR("Failed to start TAP_ESC."); PX4_ERR("failed to start tap_esc.");
_is_running = false;
return;
} }
@ -1062,7 +1065,8 @@ void start()
nullptr); nullptr);
if (_task_handle < 0) { if (_task_handle < 0) {
warn("task start failed"); PX4_ERR("task start failed");
_task_handle = -1;
return; return;
} }
} }
@ -1119,6 +1123,10 @@ int tap_esc_main(int argc, char *argv[])
} }
} }
if (!tap_esc && tap_esc_drv::_task_handle != -1) {
tap_esc_drv::_task_handle = -1;
}
// Start/load the driver. // Start/load the driver.
if (!strcmp(verb, "start")) { if (!strcmp(verb, "start")) {
if (tap_esc_drv::_is_running) { if (tap_esc_drv::_is_running) {

Loading…
Cancel
Save