SatCat5
posix_uart.h
1 // Copyright 2022-2025 The Aerospace Corporation.
3 // This file is a part of SatCat5, licensed under CERN-OHL-W v2 or later.
5 // POSIX and Windows interface objects for connecting to a UART
6 
7 #pragma once
8 
9 #include <satcat5/eth_checksum.h>
10 #include <satcat5/io_buffer.h>
11 #include <satcat5/polling.h>
12 
13 #ifdef _WIN32
14  #define SATCAT5_WIN32 1
15  typedef void* SATCAT5_UART_DESCRIPTOR;
16 #else
17  #define SATCAT5_WIN32 0
18  typedef int SATCAT5_UART_DESCRIPTOR;
19 #endif
20 
21 namespace satcat5 {
22  namespace io {
28  class PosixUart
30  , public satcat5::poll::Always
31  {
32  public:
36  PosixUart(const char* device, unsigned baud,
37  unsigned buffer_size_bytes=4096);
38  ~PosixUart();
39 
41  inline bool ok() const {return m_ok;}
42 
43  protected:
44  void data_rcvd(satcat5::io::Readable* src) override;
45  void poll_always() override;
46  unsigned chunk_rx();
47  unsigned chunk_tx();
48 
49  bool m_ok;
50  SATCAT5_UART_DESCRIPTOR m_uart;
51  };
52 
55  class SlipUart
58  {
59  public:
60  // Create the UART interface object. \see PosixUart.
61  SlipUart(const char* device, unsigned baud, unsigned buffer=4096);
62  inline bool ok() const {return m_uart.ok();}
63 
64  protected:
67  };
68  }
69 }
Buffered SLIP encoder / decoder pair with Ethernet FCS.
Definition: eth_checksum.h:74
Extensible transmit and receive buffer.
Definition: io_buffer.h:42
POSIX and Windows interface objects for connecting to a UART.
Definition: posix_uart.h:31
void data_rcvd(satcat5::io::Readable *src) override
The data_rcvd() callback is polled whenever data is available.
Definition: posix_uart.cc:162
void poll_always() override
Child class MUST override this method.
Definition: posix_uart.cc:169
bool ok() const
Is this device ready for input and output?
Definition: posix_uart.h:41
PosixUart(const char *device, unsigned baud, unsigned buffer_size_bytes=4096)
Create UART attached to the given device name.
Definition: posix_uart.cc:60
Abstract API for reading byte-streams and packets.
Definition: io_readable.h:68
Wrapper class for forwarding reads to another object.
Definition: io_readable.h:299
SLIP-encoded wrapper for the PosixUart class.
Definition: posix_uart.h:58
Wrapper class for forwarding writes to another object.
Definition: io_writeable.h:218
An "Always" object is polled whenever service() is called.
Definition: polling.h:96
Inline Ethernet Checksum insertion and verification.
Buffered I/O wrappers for PacketBuffer.
Core event-processing loop for SatCat5 software.