You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

92 lines
1.8 KiB

#pragma once
#include <driver/uart.h>
#include <string>
namespace ugv {
namespace e32 {
enum TxMode {
TxTransparent = 0,
TxFixed = 1,
};
enum IoMode {
IoOpenCollector = 0,
IoPushPull = 1,
};
typedef uint16_t Address;
typedef uint8_t Channel;
constexpr Address BroadcastAddress = 0xFFFF;
struct Config {
public:
Config();
uart_port_t uart_port;
uart_parity_t uart_parity;
int uart_tx_pin;
int uart_rx_pin;
int uart_baud;
};
struct Params {
public:
Params();
bool save_params;
Address address;
uart_parity_t uart_partity;
int uart_baud; // bps
int air_data_rate; // bps
Channel comm_channel;
TxMode tx_mode;
IoMode io_mode;
uint16_t wake_up_time; // ms
bool fec_enabled;
uint16_t tx_power; // dBm
};
class E32_Driver {
public:
explicit E32_Driver();
~E32_Driver();
esp_err_t Init(Config config = Config());
esp_err_t Free();
esp_err_t ReadParams(Params& params);
esp_err_t WriteParams(const Params& params);
int Write(Address address, Channel channel, const uint8_t* data,
size_t data_size);
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 WriteLn(const uint8_t* data, size_t data_size);
int WriteLn(const std::string& data);
esp_err_t WaitWriteDone(TickType_t ticks_to_wait = portMAX_DELAY);
int Read(uint8_t* data, int max_len,
TickType_t ticks_to_wait = portMAX_DELAY);
int ReadLn(char* data, size_t data_size,
TickType_t ticks_to_wait = portMAX_DELAY);
int ReadLn(std::string& data, TickType_t ticks_to_wait = portMAX_DELAY);
void Flush();
private:
bool initialized_;
Config config_;
Params params_;
int RawWrite(const uint8_t* data, size_t data_size);
};
} // namespace e32
} // namespace ugv