1 #include "../include/sttybuf.hpp"
2 #include "../include/util.hpp"
3 #if !defined CSDBG_WITH_PLUGIN && !defined CSDBG_WITH_HIGHLIGHT
4 #include "../include/exception.hpp"
26 return const_cast<sttybuf&
> (*this);
32 conf.c_cflag = real_baud | CS8 | CRTSCTS | CREAD | CLOCAL;
33 conf.c_iflag = IGNPAR;
38 retval = tcsetattr(
m_handle, TCSANOW, &conf);
40 while (
unlikely(retval < 0 && errno == EINTR) );
44 "failed to configure serial interface '%s' (errno %d - %s)",
74 throw exception(
"invalid argument: port (=%p)", port);
263 "failed to stat path '%s' (errno %d - %s)",
275 u32 flags = O_WRONLY;
287 "failed to open serial interface '%s' (errno %d - %s)",
314 "failed to send data to serial interface '%s' (errno %d - %s)",
336 while (
unlikely(retval < 0 && errno == EINTR) );
340 "failed to flush serial interface '%s' (errno %d - %s)",
346 return const_cast<sttybuf&
> (*this);
359 retval = tcflush(
m_handle, TCIOFLUSH);
361 while (
unlikely(retval < 0 && errno == EINTR) );
363 #if CSDBG_DBG_LEVEL & CSDBG_DBGL_WARNING
366 "failed to clear the buffers of serial interface '%s' (errno %d - %s)",
373 return const_cast<sttybuf&
> (*this);
415 throw exception(
"invalid argument: rate (=%d)", rate);
sttybuf(const i8 *, u32=9600)
Object constructor.
A buffered output stream for serial interfaces.
virtual streambuf & flush()=0
To be implemented.
static bool is_writable(const fileinfo_t &)
Check if the process has write access to a file.
static u32 translate_baud(u32)
Translate a number to a baud rate as defined in termios.h.
virtual sttybuf & sync() const
Commit cached data to the serial interface line.
This abstract class is the base for all buffered output stream types (for files, sockets, serial interfaces e.t.c)
static void * memset(void *, u8, u32)
Fill a memory block with a constant byte.
char i8
8-bit signed integer
struct stat fileinfo_t
File metadata.
i32 m_handle
Stream handle (descriptor)
virtual const i8 * devnode() const
Get the path of the serial interface device node.
virtual sttybuf * clone() const
Object virtual copy constructor.
#define likely(expr)
Offer a hint (positive) to the pipeline branch predictor.
static void dbg_warn(const i8 *,...)
Print a warning debug message on the standard error stream.
virtual sttybuf & open()
Open the serial interface for output.
virtual sttybuf & flush()
Flush the buffered data to the serial interface.
virtual streambuf & operator=(const streambuf &)
Assignment operator.
virtual ~sttybuf()
Object destructor.
static bool is_chardev(const fileinfo_t &)
Check if a file is a character device node.
virtual sttybuf & discard() const
Discard the data cached in the serial interface (in-kernel) buffers.
i8 * m_devnode
Device node file (devfs)
virtual sttybuf & set_baud(u32)
Set the baud rate.
unsigned int u32
32-bit unsigned integer
int i32
32-bit signed integer
virtual sttybuf & config() const
Configure the serial interface.
virtual u32 baud() const
Get the baud rate.
virtual bool is_tty() const
Check if the device node is a terminal.
This class is a throwable with a textual description of an error.
#define unlikely(expr)
Offer a hint (negative) to the pipeline branch predictor.
virtual streambuf & close()
Close the stream.
virtual sttybuf & operator=(const sttybuf &)
Assignment operator.
#define __D_ASSERT(x)
Assertion macro.