|
|
@ -104,12 +104,15 @@ esp_err_t E32_Driver::Free() { |
|
|
|
esp_err_t E32_Driver::ReadParams(Params& params) { |
|
|
|
esp_err_t E32_Driver::ReadParams(Params& params) { |
|
|
|
esp_err_t ret; |
|
|
|
esp_err_t ret; |
|
|
|
ret = RawWrite(CMD_READ_PARAMS, sizeof(CMD_READ_PARAMS)); |
|
|
|
ret = RawWrite(CMD_READ_PARAMS, sizeof(CMD_READ_PARAMS)); |
|
|
|
|
|
|
|
ret = WaitWriteDone(); |
|
|
|
if (ret != ESP_OK) { |
|
|
|
if (ret != ESP_OK) { |
|
|
|
|
|
|
|
ESP_LOGE(TAG, "error writing read params cmd"); |
|
|
|
return ret; |
|
|
|
return ret; |
|
|
|
} |
|
|
|
} |
|
|
|
uint8_t param_data[PARAMS_LEN]; |
|
|
|
uint8_t param_data[PARAMS_LEN]; |
|
|
|
ret = Read(param_data, PARAMS_LEN, pdMS_TO_TICKS(1000)); |
|
|
|
ret = Read(param_data, PARAMS_LEN, pdMS_TO_TICKS(1000)); |
|
|
|
if (ret != ESP_OK) { |
|
|
|
if (ret != PARAMS_LEN) { |
|
|
|
|
|
|
|
ESP_LOGE(TAG, "error reading params"); |
|
|
|
return ret; |
|
|
|
return ret; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -241,7 +244,8 @@ esp_err_t E32_Driver::WriteParams(const Params& params) { |
|
|
|
param_data[5] |= 3; |
|
|
|
param_data[5] |= 3; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
ret = RawWrite(param_data, PARAMS_LEN); |
|
|
|
RawWrite(param_data, PARAMS_LEN); |
|
|
|
|
|
|
|
ret = WaitWriteDone(); |
|
|
|
if (ret != ESP_OK) { |
|
|
|
if (ret != ESP_OK) { |
|
|
|
return ret; |
|
|
|
return ret; |
|
|
|
} |
|
|
|
} |
|
|
@ -251,8 +255,8 @@ esp_err_t E32_Driver::WriteParams(const Params& params) { |
|
|
|
return ESP_OK; |
|
|
|
return ESP_OK; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
int E32_Driver::Write(Address address, Channel channel, |
|
|
|
int E32_Driver::Write(Address address, Channel channel, const uint8_t* data, |
|
|
|
const uint8_t* data, size_t data_size) { |
|
|
|
size_t data_size) { |
|
|
|
int written; |
|
|
|
int written; |
|
|
|
if (params_.tx_mode == TxFixed) { |
|
|
|
if (params_.tx_mode == TxFixed) { |
|
|
|
uint8_t header[3]; |
|
|
|
uint8_t header[3]; |
|
|
@ -260,7 +264,8 @@ int E32_Driver::Write(Address address, Channel channel, |
|
|
|
header[1] = address & 0xFF; |
|
|
|
header[1] = address & 0xFF; |
|
|
|
header[2] = channel; |
|
|
|
header[2] = channel; |
|
|
|
|
|
|
|
|
|
|
|
written = uart_write_bytes(config_.uart_port, (char*)header, sizeof(header)); |
|
|
|
written = |
|
|
|
|
|
|
|
uart_write_bytes(config_.uart_port, (char*)header, sizeof(header)); |
|
|
|
if (written < 0) { |
|
|
|
if (written < 0) { |
|
|
|
return written; |
|
|
|
return written; |
|
|
|
} |
|
|
|
} |
|
|
@ -272,13 +277,17 @@ 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); |
|
|
|
} |
|
|
|
} |
|
|
|
int 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()); |
|
|
|
} |
|
|
|
} |
|
|
|
int 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()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
esp_err_t E32_Driver::WaitWriteDone(TickType_t ticks_to_wait) { |
|
|
|
|
|
|
|
return uart_wait_tx_done(config_.uart_port, ticks_to_wait); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
int E32_Driver::Read(uint8_t* data, int max_len, TickType_t ticks_to_wait) { |
|
|
|
int E32_Driver::Read(uint8_t* data, int max_len, TickType_t ticks_to_wait) { |
|
|
|
return uart_read_bytes(config_.uart_port, (uint8_t*)data, max_len, |
|
|
|
return uart_read_bytes(config_.uart_port, (uint8_t*)data, max_len, |
|
|
|
ticks_to_wait); |
|
|
|
ticks_to_wait); |
|
|
@ -304,8 +313,13 @@ int E32_Driver::Read(std::string& data, TickType_t ticks_to_wait) { |
|
|
|
return total_read; |
|
|
|
return total_read; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
esp_err_t E32_Driver::RawWrite(const uint8_t* data, size_t data_size) { |
|
|
|
int E32_Driver::RawWrite(const uint8_t* data, size_t data_size) { |
|
|
|
return uart_write_bytes(config_.uart_port, (const char*)data, data_size); |
|
|
|
int written = |
|
|
|
|
|
|
|
uart_write_bytes(config_.uart_port, (const char*)data, data_size); |
|
|
|
|
|
|
|
if (written < 0) { |
|
|
|
|
|
|
|
ESP_LOGE(TAG, "RawWrite error: %d", written); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return written; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} // namespace e32
|
|
|
|
} // namespace e32
|
|
|
|