From a36caa53f1b770fd42b90be10e870722cb37bbdf Mon Sep 17 00:00:00 2001 From: Alex Mikhalev Date: Wed, 23 Jan 2019 19:26:27 -0800 Subject: [PATCH] fix issues with error interpretation --- main/e32_driver.cc | 27 ++++++++++----------------- main/e32_driver.hh | 8 ++++---- main/ugv_comms.cc | 3 ++- 3 files changed, 16 insertions(+), 22 deletions(-) diff --git a/main/e32_driver.cc b/main/e32_driver.cc index 5ea5b87..d2549f4 100644 --- a/main/e32_driver.cc +++ b/main/e32_driver.cc @@ -251,38 +251,31 @@ esp_err_t E32_Driver::WriteParams(const Params& params) { return ESP_OK; } -esp_err_t E32_Driver::Write(Address address, Channel channel, +int E32_Driver::Write(Address address, Channel channel, const uint8_t* data, size_t data_size) { - esp_err_t ret; + int written; if (params_.tx_mode == TxFixed) { uint8_t header[3]; header[0] = address >> 8; header[1] = address & 0xFF; header[2] = channel; - ret = uart_write_bytes(config_.uart_port, (char*)header, sizeof(header)); - if (ret != ESP_OK) { - goto error; + written = uart_write_bytes(config_.uart_port, (char*)header, sizeof(header)); + if (written < 0) { + return written; } } - ret = uart_write_bytes(config_.uart_port, (char*)data, data_size); - if (ret != ESP_OK) { - goto error; - } - return ESP_OK; - -error: - ESP_LOGE(TAG, "Write error %d", ret); - return ret; + written = uart_write_bytes(config_.uart_port, (char*)data, data_size); + return written; } -esp_err_t E32_Driver::Write(const uint8_t* data, size_t data_size) { +int E32_Driver::Write(const uint8_t* data, size_t data_size) { return Write(params_.address, params_.comm_channel, data, data_size); } -esp_err_t E32_Driver::Write(Address address, Channel channel, +int E32_Driver::Write(Address address, Channel channel, const std::string& data) { return Write(address, channel, (uint8_t*)data.c_str(), data.size()); } -esp_err_t E32_Driver::Write(const std::string& data) { +int E32_Driver::Write(const std::string& data) { return Write((uint8_t*)data.c_str(), data.size()); } diff --git a/main/e32_driver.hh b/main/e32_driver.hh index b7ca363..29f5d9a 100644 --- a/main/e32_driver.hh +++ b/main/e32_driver.hh @@ -61,11 +61,11 @@ class E32_Driver { esp_err_t ReadParams(Params& params); esp_err_t WriteParams(const Params& params); - esp_err_t Write(Address address, Channel channel, const uint8_t* data, + int Write(Address address, Channel channel, const uint8_t* data, size_t data_size); - esp_err_t Write(const uint8_t* data, size_t data_size); - esp_err_t Write(Address address, Channel channel, const std::string& data); - esp_err_t Write(const std::string& data); + int Write(const uint8_t* data, size_t data_size); + int Write(Address address, Channel channel, const std::string& data); + int Write(const std::string& data); int Read(uint8_t* data, int max_len, TickType_t ticks_to_wait = portMAX_DELAY); diff --git a/main/ugv_comms.cc b/main/ugv_comms.cc index eef3f61..368c0be 100644 --- a/main/ugv_comms.cc +++ b/main/ugv_comms.cc @@ -260,7 +260,8 @@ esp_err_t CommsClass::SendPacket(const char *data, size_t size) { } uint8_t sz = size; lora.Write(&sz, sizeof(sz)); - return lora.Write((uint8_t *)data, size); + lora.Write((uint8_t *)data, size); + return ESP_OK; #endif }