Browse Source

fix issues with error interpretation

try-fix-comms-errors
Alex Mikhalev 6 years ago
parent
commit
a36caa53f1
  1. 27
      main/e32_driver.cc
  2. 8
      main/e32_driver.hh
  3. 3
      main/ugv_comms.cc

27
main/e32_driver.cc

@ -251,38 +251,31 @@ esp_err_t E32_Driver::WriteParams(const Params& params) {
return ESP_OK; 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) { const uint8_t* data, size_t data_size) {
esp_err_t ret; int written;
if (params_.tx_mode == TxFixed) { if (params_.tx_mode == TxFixed) {
uint8_t header[3]; uint8_t header[3];
header[0] = address >> 8; header[0] = address >> 8;
header[1] = address & 0xFF; header[1] = address & 0xFF;
header[2] = channel; header[2] = channel;
ret = uart_write_bytes(config_.uart_port, (char*)header, sizeof(header)); written = uart_write_bytes(config_.uart_port, (char*)header, sizeof(header));
if (ret != ESP_OK) { if (written < 0) {
goto error; return written;
} }
} }
ret = uart_write_bytes(config_.uart_port, (char*)data, data_size); written = uart_write_bytes(config_.uart_port, (char*)data, data_size);
if (ret != ESP_OK) { return written;
goto error;
}
return ESP_OK;
error:
ESP_LOGE(TAG, "Write error %d", ret);
return ret;
} }
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); 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) { const std::string& data) {
return Write(address, channel, (uint8_t*)data.c_str(), data.size()); 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()); return Write((uint8_t*)data.c_str(), data.size());
} }

8
main/e32_driver.hh

@ -61,11 +61,11 @@ class E32_Driver {
esp_err_t ReadParams(Params& params); esp_err_t ReadParams(Params& params);
esp_err_t WriteParams(const 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); size_t data_size);
esp_err_t Write(const uint8_t* data, size_t data_size); int Write(const uint8_t* data, size_t data_size);
esp_err_t Write(Address address, Channel channel, const std::string& data); int Write(Address address, Channel channel, const std::string& data);
esp_err_t Write(const std::string& data); int Write(const std::string& data);
int Read(uint8_t* data, int max_len, int Read(uint8_t* data, int max_len,
TickType_t ticks_to_wait = portMAX_DELAY); TickType_t ticks_to_wait = portMAX_DELAY);

3
main/ugv_comms.cc

@ -260,7 +260,8 @@ esp_err_t CommsClass::SendPacket(const char *data, size_t size) {
} }
uint8_t sz = size; uint8_t sz = size;
lora.Write(&sz, sizeof(sz)); lora.Write(&sz, sizeof(sz));
return lora.Write((uint8_t *)data, size); lora.Write((uint8_t *)data, size);
return ESP_OK;
#endif #endif
} }

Loading…
Cancel
Save