29static void setTTYError(
int rc, std::string &err)
36static void splitTimeoutMs(
int timeoutMs,
long &seconds,
long µseconds)
41 seconds = timeoutMs / 1000;
42 microseconds =
static_cast<long>(timeoutMs % 1000) * 1000L;
47 if (::tcflush(m_fd, TCIFLUSH) != 0)
49 err = std::string(
"tcflush(TCIFLUSH) failed: ") + std::strerror(
errno);
57 int nbytesWritten = 0;
58 const auto *buffer =
static_cast<const char *
>(data);
59 const int rc =
tty_write(m_fd, buffer,
static_cast<int>(len), &nbytesWritten);
66 if (
static_cast<size_t>(nbytesWritten) != len)
77 int nbytesWritten = 0;
85 if (nbytesWritten !=
static_cast<int>(s.size()))
100 long microseconds = 0;
101 splitTimeoutMs(timeoutMs, seconds, microseconds);
104 const int rc =
tty_read_expanded(m_fd,
reinterpret_cast<char *
>(out.data()),
static_cast<int>(n), seconds, microseconds,
108 setTTYError(rc, err);
112 if (
static_cast<size_t>(nbytesRead) != n)
124 std::vector<uint8_t> buf;
128 ch =
static_cast<char>(
byte);
137 long microseconds = 0;
138 splitTimeoutMs(timeoutMs, seconds, microseconds);
140 char buffer[1024] = {0};
145 setTTYError(rc, err);
149 out.assign(buffer, nbytesRead);
150 if (!out.empty() && out.back() ==
'#')
184 std::vector<uint8_t> buf;
bool queryStatus3(const std::string &cmd, uint8_t &b1, uint8_t &b2, uint8_t &b3, int timeoutMs, std::string &err)
bool discardInput(std::string &err)
bool writeRaw(const void *data, size_t len, std::string &err)
bool queryHash(const std::string &cmd, std::string &response, int timeoutMs, std::string &err)
bool readHashTerminated(std::string &out, int timeoutMs, std::string &err)
bool writeString(const std::string &s, std::string &err)
bool readExact(std::vector< uint8_t > &out, size_t n, int timeoutMs, std::string &err)
bool queryAck(const std::string &cmd, char &ack, int timeoutMs, std::string &err)
bool readChar(char &ch, int timeoutMs, std::string &err)
int tty_write(int fd, const char *buf, int nbytes, int *nbytes_written)
Writes a buffer to fd.
int tty_write_string(int fd, const char *buf, int *nbytes_written)
Writes a null terminated string to fd.
void tty_error_msg(int err_code, char *err_msg, int err_msg_len)
Retrieve the tty error message.
int tty_read_expanded(int fd, char *buf, int nbytes, long timeout_seconds, long timeout_microseconds, int *nbytes_read)
read buffer from terminal with a delimiter
int tty_nread_section_expanded(int fd, char *buf, int nsize, char stop_char, long timeout_seconds, long timeout_microseconds, int *nbytes_read)
read buffer from terminal with a delimiter
Implementations for common driver routines.