8 #if !(defined(__linux__) || defined(__APPLE__)) 9 #error This HostUartComponent implementation is not supported on this host OS 18 #include <sys/ioctl.h> 26 speed_t get_baud(
int baud) {
102 static const char *
const TAG =
"uart.host";
112 ESP_LOGCONFIG(TAG,
"Opening UART port...");
115 ESP_LOGE(TAG,
"Unsupported baud rate: %d", this->
baud_rate_);
126 struct termios options;
128 options.c_cflag &= ~CRTSCTS;
129 options.c_cflag |= CREAD | CLOCAL;
130 options.c_lflag &= ~ICANON;
131 options.c_lflag &= ~ECHO;
132 options.c_lflag &= ~ECHOE;
133 options.c_lflag &= ~ECHONL;
134 options.c_lflag &= ~ISIG;
135 options.c_iflag &= ~(IXON | IXOFF | IXANY);
136 options.c_iflag &= ~(IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL);
137 options.c_oflag &= ~OPOST;
138 options.c_oflag &= ~ONLCR;
140 options.c_cflag &= ~CSIZE;
143 options.c_cflag |= CS5;
146 options.c_cflag |= CS6;
149 options.c_cflag |= CS7;
153 options.c_cflag |= CS8;
159 options.c_cflag &= ~PARENB;
162 options.c_cflag |= PARENB;
163 options.c_cflag &= ~PARODD;
166 options.c_cflag |= PARENB;
167 options.c_cflag |= PARODD;
172 options.c_cflag |= CSTOPB;
174 options.c_cflag &= ~CSTOPB;
176 cfsetispeed(&options, baud);
177 cfsetospeed(&options, baud);
182 ESP_LOGCONFIG(TAG,
"UART:");
183 ESP_LOGCONFIG(TAG,
" Port: %s", this->
port_name_.c_str());
185 ESP_LOGCONFIG(TAG,
" Port status: Not opened");
187 ESP_LOGCONFIG(TAG,
" Error: %s", this->
first_error_.c_str());
191 ESP_LOGCONFIG(TAG,
" Port status: opened");
192 ESP_LOGCONFIG(TAG,
" Baud Rate: %d", this->
baud_rate_);
193 ESP_LOGCONFIG(TAG,
" Data Bits: %d", this->
data_bits_);
194 ESP_LOGCONFIG(TAG,
" Parity: %s",
198 ESP_LOGCONFIG(TAG,
" Stop Bits: %d", this->
stop_bits_);
207 if (written != len) {
211 #ifdef USE_UART_DEBUGGER 212 for (
size_t i = 0; i <
len; i++) {
243 uint8_t *data_ptr = data;
244 size_t length_to_read =
len;
251 if (length_to_read > 0) {
258 #ifdef USE_UART_DEBUGGER 259 for (
size_t i = 0; i <
len; i++) {
286 ESP_LOGV(TAG,
" Flushing...");
293 ESP_LOGE(TAG,
"Port error: %s", error.c_str());
void dump_config() override
void check_logger_conflict() override
UARTParityOptions parity_
void write_array(const uint8_t *data, size_t len) override
void update_error_(const std::string &error)
virtual ~HostUartComponent()
virtual void mark_failed()
Mark this component as failed.
Implementation of SPI Controller mode.
bool read_array(uint8_t *data, size_t len) override
bool check_read_timeout_(size_t len=1)
CallbackManager< void(UARTDirection, uint8_t)> debug_callback_
bool peek_byte(uint8_t *data) override