mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-11-10 17:41:35 +08:00
Implemented flush for Serial UART API
This commit is contained in:
@@ -80,6 +80,11 @@ ssize_t Serial::write(const void *buffer, size_t buffer_size)
|
||||
return _impl.write(buffer, buffer_size);
|
||||
}
|
||||
|
||||
void Serial::flush()
|
||||
{
|
||||
return _impl.flush();
|
||||
}
|
||||
|
||||
uint32_t Serial::getBaudrate() const
|
||||
{
|
||||
return _impl.getBaudrate();
|
||||
|
||||
@@ -64,6 +64,8 @@ public:
|
||||
|
||||
ssize_t write(const void *buffer, size_t buffer_size);
|
||||
|
||||
void flush();
|
||||
|
||||
// If port is already open then the following configuration functions
|
||||
// will reconfigure the port. If the port is not yet open then they will
|
||||
// simply store the configuration in preparation for the port to be opened.
|
||||
|
||||
@@ -309,6 +309,13 @@ ssize_t SerialImpl::write(const void *buffer, size_t buffer_size)
|
||||
return written;
|
||||
}
|
||||
|
||||
void SerialImpl::flush()
|
||||
{
|
||||
if (_open) {
|
||||
tcflush(_serial_fd, TCIOFLUSH);
|
||||
}
|
||||
}
|
||||
|
||||
const char *SerialImpl::getPort() const
|
||||
{
|
||||
return _port;
|
||||
|
||||
@@ -64,6 +64,8 @@ public:
|
||||
|
||||
ssize_t write(const void *buffer, size_t buffer_size);
|
||||
|
||||
void flush();
|
||||
|
||||
const char *getPort() const;
|
||||
|
||||
uint32_t getBaudrate() const;
|
||||
|
||||
@@ -64,6 +64,8 @@ public:
|
||||
|
||||
ssize_t write(const void *buffer, size_t buffer_size);
|
||||
|
||||
void flush();
|
||||
|
||||
const char *getPort() const;
|
||||
|
||||
uint32_t getBaudrate() const;
|
||||
|
||||
@@ -309,6 +309,13 @@ ssize_t SerialImpl::write(const void *buffer, size_t buffer_size)
|
||||
return written;
|
||||
}
|
||||
|
||||
void SerialImpl::flush()
|
||||
{
|
||||
if (_open) {
|
||||
tcflush(_serial_fd, TCIOFLUSH);
|
||||
}
|
||||
}
|
||||
|
||||
const char *SerialImpl::getPort() const
|
||||
{
|
||||
return _port;
|
||||
|
||||
@@ -63,6 +63,8 @@ public:
|
||||
|
||||
ssize_t write(const void *buffer, size_t buffer_size);
|
||||
|
||||
void flush();
|
||||
|
||||
const char *getPort() const;
|
||||
bool setPort(const char *port);
|
||||
|
||||
|
||||
@@ -251,6 +251,15 @@ ssize_t SerialImpl::write(const void *buffer, size_t buffer_size)
|
||||
return ret_write;
|
||||
}
|
||||
|
||||
void SerialImpl::flush()
|
||||
{
|
||||
if (_open) {
|
||||
uint8_t buffer[4];
|
||||
// A read clears out all current data
|
||||
read(buffer, 4);
|
||||
}
|
||||
}
|
||||
|
||||
const char *SerialImpl::getPort() const
|
||||
{
|
||||
return _port;
|
||||
|
||||
Reference in New Issue
Block a user