From 2e923a62e4aaeebc5183de1ad704db5153a3a2e6 Mon Sep 17 00:00:00 2001
From: Giordon Holtsberg Stark <giordon.holtsberg.stark@cern.ch>
Date: Wed, 21 Apr 2021 14:49:21 +0000
Subject: [PATCH] feat: baud enum

---
 src/examples/Si7021_example.cpp           |  3 +-
 src/examples/Si7021_example.py            |  3 +-
 src/examples/chiller_example.cpp          | 10 ++--
 src/examples/chiller_example.py           |  3 +-
 src/examples/devcomuino_example.cpp       |  2 +-
 src/examples/devcomuino_example.py        |  3 +-
 src/examples/ntc_example.cpp              |  2 +-
 src/examples/ntc_example.py               |  2 +-
 src/examples/sht85_example.cpp            |  3 +-
 src/examples/sht85_example.py             |  3 +-
 src/examples/temp_hum_monitor_example.cpp |  2 +-
 src/labRemote/module.cpp                  |  4 +-
 src/libChiller/PolySciLM.h                |  2 +-
 src/libCom/GPIBSerialCom.cpp              |  5 +-
 src/libCom/GPIBSerialCom.h                | 10 ++--
 src/libCom/SerialCom.cpp                  | 58 +++++++++++++++++------
 src/libCom/SerialCom.h                    | 46 ++++++++++++++++--
 src/libCom/TextSerialCom.cpp              |  4 +-
 src/libCom/TextSerialCom.h                | 10 ++--
 src/libCom/python.cpp                     | 52 ++++++++++++++++----
 src/libLoad/TTILD400P.cpp                 |  3 +-
 src/libLoad/TTILD400P.h                   |  2 +-
 src/libMeter/Fluke8842.cpp                |  3 +-
 src/libMeter/Fluke8842.h                  |  2 +-
 src/libMeter/HP3478A.cpp                  |  3 +-
 src/libMeter/HP3478A.h                    |  2 +-
 src/libMeter/Keithley2000.cpp             |  3 +-
 src/libMeter/Keithley2000.h               |  3 +-
 src/libScope/Tektronix654C.cpp            |  3 +-
 src/libScope/Tektronix654C.h              |  2 +-
 src/tools/arduino_eeprom.cpp              |  2 +-
 31 files changed, 185 insertions(+), 70 deletions(-)

diff --git a/src/examples/Si7021_example.cpp b/src/examples/Si7021_example.cpp
index 33a9a4aa..9e8c7012 100644
--- a/src/examples/Si7021_example.cpp
+++ b/src/examples/Si7021_example.cpp
@@ -13,7 +13,8 @@
 #include "Si7021.h"
 
 int main(int argc, char* argv[]) {
-    std::shared_ptr<TextSerialCom> TC(new TextSerialCom("/dev/ttyACM2", B9600));
+    std::shared_ptr<TextSerialCom> TC(
+        new TextSerialCom("/dev/ttyACM2", SerialCom::BaudRate::Baud9600));
     TC->setTermination("\r\n");
     TC->init();
     std::shared_ptr<I2CCom> i2c(new I2CDevComuino(0x40, TC));
diff --git a/src/examples/Si7021_example.py b/src/examples/Si7021_example.py
index 90d7999f..5c4f1567 100644
--- a/src/examples/Si7021_example.py
+++ b/src/examples/Si7021_example.py
@@ -14,7 +14,8 @@ def si7021_example(device, baud, address) :
     ## initialize the communication line
     ##
     try :
-        serial = com.TextSerialCom(device, baud)
+        baud_rate = getattr(com.SerialCom.BaudRate, 'Baud{0:d}'.format(baud))
+        serial = com.TextSerialCom(device, baud_rate)
     except :
         logger.error(f"Unable to initialize serial communication with device at port \"{device}\"")
         sys.exit(1)
diff --git a/src/examples/chiller_example.cpp b/src/examples/chiller_example.cpp
index 6e82c847..69ca58df 100644
--- a/src/examples/chiller_example.cpp
+++ b/src/examples/chiller_example.cpp
@@ -39,7 +39,7 @@ int main(int argc, char* argv[]) {
     // inputs
     float target_temp = 15;
     std::string device = "";
-    speed_t baud = B9600;
+    SerialCom::BaudRate baud = SerialCom::BaudRate::Baud9600;
 
     int c;
     while (true) {
@@ -61,13 +61,13 @@ int main(int argc, char* argv[]) {
             case 'b': {
                 std::string baud_str = optarg;
                 if (baud_str == "2400")
-                    baud = B2400;
+                    baud = SerialCom::BaudRate::Baud2400;
                 else if (baud_str == "4800")
-                    baud = B4800;
+                    baud = SerialCom::BaudRate::Baud4800;
                 else if (baud_str == "9600")
-                    baud = B9600;
+                    baud = SerialCom::BaudRate::Baud9600;
                 else if (baud_str == "19200")
-                    baud = B19200;
+                    baud = SerialCom::BaudRate::Baud19200;
                 else {
                     std::cerr << "Invalid baud rate '" << optarg
                               << "' supplied. Use either 2400, 4800, 9600, or "
diff --git a/src/examples/chiller_example.py b/src/examples/chiller_example.py
index af21bf26..3c498322 100644
--- a/src/examples/chiller_example.py
+++ b/src/examples/chiller_example.py
@@ -14,7 +14,8 @@ def chiller_example(device, baud, temperature) :
     ## setup the communication line
     ##
     try :
-        serial = com.TextSerialCom(device, baud)
+        baud_rate = getattr(com.SerialCom.BaudRate, 'Baud{0:d}'.format(baud))
+        serial = com.TextSerialCom(device, baud_rate)
     except :
         logger.error(f"Unable to initialize serial communication with device at port \"{device}\"")
         sys.exit(1)
diff --git a/src/examples/devcomuino_example.cpp b/src/examples/devcomuino_example.cpp
index dd7bb95d..bbae1ec4 100644
--- a/src/examples/devcomuino_example.cpp
+++ b/src/examples/devcomuino_example.cpp
@@ -13,7 +13,7 @@
 // https://cdn-learn.adafruit.com/assets/assets/000/035/931/original/Support_Documents_TechnicalDocs_Si7021-A20.pdf
 
 int main(int argc, char* argv[]) {
-    TextSerialCom com("/dev/ttyACM2", B9600);
+    TextSerialCom com("/dev/ttyACM2", SerialCom::BaudRate::Baud9600);
     com.setTermination("\r\n");
     com.init();
 
diff --git a/src/examples/devcomuino_example.py b/src/examples/devcomuino_example.py
index cf31fa78..692f9c4c 100644
--- a/src/examples/devcomuino_example.py
+++ b/src/examples/devcomuino_example.py
@@ -25,7 +25,8 @@ def devcomuino_example(device, baud) :
     ## initialize the communication line
     ##
     try :
-        serial = com.TextSerialCom(device, baud)
+        baud_rate = getattr(com.SerialCom.BaudRate, 'Baud{0:d}'.format(baud))
+        serial = com.TextSerialCom(device, baud_rate)
     except :
         logger.error(f"Unable to initialize serial communication with device at port \"{device}\"")
         sys.exit(1)
diff --git a/src/examples/ntc_example.cpp b/src/examples/ntc_example.cpp
index 277c3f87..59599f99 100644
--- a/src/examples/ntc_example.cpp
+++ b/src/examples/ntc_example.cpp
@@ -132,7 +132,7 @@ int main(int argc, char* argv[]) {
     logger(logDEBUG) << "Pin: " << (int)pin;
 
     std::shared_ptr<TextSerialCom> com =
-        std::make_shared<TextSerialCom>(port, B9600);
+        std::make_shared<TextSerialCom>(port, SerialCom::BaudRate::Baud9600);
     com->setTermination("\r\n");
     com->setTimeout(5);
     com->init();
diff --git a/src/examples/ntc_example.py b/src/examples/ntc_example.py
index 246f8899..a881c01b 100644
--- a/src/examples/ntc_example.py
+++ b/src/examples/ntc_example.py
@@ -33,7 +33,7 @@ def ntc_example(device, pin) :
     ## initialize the communication line
     ##
     try :
-        serial = com.TextSerialCom(device, 9600)
+        serial = com.TextSerialCom(device, com.SerialCom.BaudRate.Baud9600)
     except :
         logger.error(f"Unable to initialize serial communication with device at port \"{device}\"")
         sys.exit(1)
diff --git a/src/examples/sht85_example.cpp b/src/examples/sht85_example.cpp
index 3c81b817..9ffdbbf0 100644
--- a/src/examples/sht85_example.cpp
+++ b/src/examples/sht85_example.cpp
@@ -19,7 +19,8 @@ int main(int argc, char* argv[]) {
         MPSSEChip::Endianness::MSBFirst);
     std::shared_ptr<I2CCom> i2c = std::make_shared<I2CFTDICom>(ftdi, 0x44);
 #else
-    std::shared_ptr<TextSerialCom> TC(new TextSerialCom("/dev/ttyACM0", B9600));
+    std::shared_ptr<TextSerialCom> TC(
+        new TextSerialCom("/dev/ttyACM0", SerialCom::BaudRate::Baud9600));
     TC->setTermination("\r\n");
     TC->init();
 
diff --git a/src/examples/sht85_example.py b/src/examples/sht85_example.py
index 36e87323..f610cacd 100644
--- a/src/examples/sht85_example.py
+++ b/src/examples/sht85_example.py
@@ -27,7 +27,8 @@ def sht85_example(use_ftdi, device, baud) :
         ## initialize the communication line
         ##
         try :
-            serial = com.TextSerialCom(device, baud)
+            baud_rate = getattr(com.SerialCom.BaudRate, 'Baud{0:d}'.format(baud))
+            serial = com.TextSerialCom(device, baud_rate)
         except :
             logger.error(f"Unable to initialize serial communication with the device at port \"{device}\"")
             sys.exit(1)
diff --git a/src/examples/temp_hum_monitor_example.cpp b/src/examples/temp_hum_monitor_example.cpp
index da470dd5..2e37494c 100644
--- a/src/examples/temp_hum_monitor_example.cpp
+++ b/src/examples/temp_hum_monitor_example.cpp
@@ -87,7 +87,7 @@ int main(int argc, char** argv) {
     }
 
     // open serial device
-    speed_t baud = B9600;
+    SerialCom::BaudRate baud = SerialCom::BaudRate::Baud9600;
     std::shared_ptr<TextSerialCom> sc(
         new TextSerialCom("/dev/ttyACM" + std::to_string(rport), baud));
     sc->init();
diff --git a/src/labRemote/module.cpp b/src/labRemote/module.cpp
index e9e26ac5..7c088e4e 100644
--- a/src/labRemote/module.cpp
+++ b/src/labRemote/module.cpp
@@ -1,7 +1,7 @@
-#include "Logger.h"
-
 #include <pybind11/pybind11.h>
 
+#include "Logger.h"
+
 namespace py = pybind11;
 
 void register_com(py::module&);
diff --git a/src/libChiller/PolySciLM.h b/src/libChiller/PolySciLM.h
index 11e8977c..0c69ec93 100644
--- a/src/libChiller/PolySciLM.h
+++ b/src/libChiller/PolySciLM.h
@@ -19,7 +19,7 @@
  *
  * ```
  * std::shared_ptr<TextSerialCom> com =
- *   std::make_shared<TextSerialCom>("/dev/ttyUSB0",B9600);
+ *   std::make_shared<TextSerialCom>("/dev/ttyUSB0",SerialCom::BaudRate::Baud9600);
  * com->setTermination("\r");
  * com->init();
  *
diff --git a/src/libCom/GPIBSerialCom.cpp b/src/libCom/GPIBSerialCom.cpp
index e82f3895..3e7f03b0 100644
--- a/src/libCom/GPIBSerialCom.cpp
+++ b/src/libCom/GPIBSerialCom.cpp
@@ -16,8 +16,9 @@
 REGISTER_COM(GPIBSerialCom)
 
 GPIBSerialCom::GPIBSerialCom(uint16_t gpib_addr, const std::string& port,
-                             speed_t baud, bool parityBit, bool twoStopBits,
-                             bool flowControl, CharSize charsize)
+                             SerialCom::BaudRate baud, bool parityBit,
+                             bool twoStopBits, bool flowControl,
+                             SerialCom::CharSize charsize)
     : TextSerialCom(port, baud, parityBit, twoStopBits, flowControl, charsize),
       m_gpib_addr(gpib_addr) {}
 
diff --git a/src/libCom/GPIBSerialCom.h b/src/libCom/GPIBSerialCom.h
index f4bbae45..5c379877 100644
--- a/src/libCom/GPIBSerialCom.h
+++ b/src/libCom/GPIBSerialCom.h
@@ -26,10 +26,12 @@ class GPIBSerialCom : public TextSerialCom {
      * @param flowControl Enable hardware flow control
      * @param charsize Size of a character
      */
-    GPIBSerialCom(uint16_t gpib_addr, const std::string& port,
-                  speed_t baud = B19200, bool parityBit = false,
-                  bool twoStopBits = false, bool flowControl = false,
-                  CharSize charsize = CharSize::CharSize8);
+    GPIBSerialCom(
+        uint16_t gpib_addr, const std::string& port,
+        SerialCom::BaudRate baud = SerialCom::BaudRate::Baud19200,
+        bool parityBit = false, bool twoStopBits = false,
+        bool flowControl = false,
+        SerialCom::CharSize charsize = SerialCom::CharSize::CharSize8);
     GPIBSerialCom();
 
     ~GPIBSerialCom();
diff --git a/src/libCom/SerialCom.cpp b/src/libCom/SerialCom.cpp
index edaccca4..3a4aad9d 100644
--- a/src/libCom/SerialCom.cpp
+++ b/src/libCom/SerialCom.cpp
@@ -17,19 +17,46 @@
 #include "ComRegistry.h"
 REGISTER_COM(SerialCom)
 
-const std::unordered_map<std::string, speed_t> SerialCom::mapBAUDRATE = {
-    {"B0", B0},       {"B50", B50},     {"B75", B75},       {"B110", B110},
-    {"B134", B134},   {"B150", B150},   {"B200", B200},     {"B300", B300},
-    {"B600", B600},   {"B1200", B1200}, {"B1800", B1800},   {"B2400", B2400},
-    {"B4800", B4800}, {"B9600", B9600}, {"B19200", B19200}, {"B38400", B38400}};
+const std::unordered_map<std::string, SerialCom::BaudRate>
+    SerialCom::mapBAUDRATE = {{"B0", SerialCom::BaudRate::Baud0},
+                              {"B50", SerialCom::BaudRate::Baud50},
+                              {"B75", SerialCom::BaudRate::Baud75},
+                              {"B110", SerialCom::BaudRate::Baud110},
+                              {"B134", SerialCom::BaudRate::Baud134},
+                              {"B150", SerialCom::BaudRate::Baud150},
+                              {"B200", SerialCom::BaudRate::Baud200},
+                              {"B300", SerialCom::BaudRate::Baud300},
+                              {"B600", SerialCom::BaudRate::Baud600},
+                              {"B1200", SerialCom::BaudRate::Baud1200},
+                              {"B1800", SerialCom::BaudRate::Baud1800},
+                              {"B2400", SerialCom::BaudRate::Baud2400},
+                              {"B4800", SerialCom::BaudRate::Baud4800},
+                              {"B9600", SerialCom::BaudRate::Baud9600},
+                              {"B19200", SerialCom::BaudRate::Baud19200},
+                              {"B38400", SerialCom::BaudRate::Baud38400},
+                              {"B57600", SerialCom::BaudRate::Baud57600},
+                              {"B115200", SerialCom::BaudRate::Baud115200},
+                              {"B230400", SerialCom::BaudRate::Baud230400},
+                              {"B460800", SerialCom::BaudRate::Baud460800},
+                              {"B500000", SerialCom::BaudRate::Baud500000},
+                              {"B576000", SerialCom::BaudRate::Baud576000},
+                              {"B921600", SerialCom::BaudRate::Baud921600},
+                              {"B1000000", SerialCom::BaudRate::Baud1000000},
+                              {"B1152000", SerialCom::BaudRate::Baud1152000},
+                              {"B1500000", SerialCom::BaudRate::Baud1500000},
+                              {"B2000000", SerialCom::BaudRate::Baud2000000},
+                              {"B2500000", SerialCom::BaudRate::Baud2500000},
+                              {"B3000000", SerialCom::BaudRate::Baud3000000},
+                              {"B3500000", SerialCom::BaudRate::Baud3500000},
+                              {"B4000000", SerialCom::BaudRate::Baud4000000}};
 
 const std::unordered_map<std::string, SerialCom::CharSize>
-    SerialCom::mapCHARSIZE = {{"CS5", CharSize5},
-                              {"CS6", CharSize6},
-                              {"CS7", CharSize7},
-                              {"CS8", CharSize8}};
+    SerialCom::mapCHARSIZE = {{"CS5", SerialCom::CharSize::CharSize5},
+                              {"CS6", SerialCom::CharSize::CharSize6},
+                              {"CS7", SerialCom::CharSize::CharSize7},
+                              {"CS8", SerialCom::CharSize::CharSize8}};
 
-SerialCom::SerialCom(const std::string &port, speed_t baud, bool parityBit,
+SerialCom::SerialCom(const std::string &port, BaudRate baud, bool parityBit,
                      bool twoStopBits, bool flowControl, CharSize charsize)
     : m_port(port),
       m_baudrate(baud),
@@ -98,11 +125,12 @@ void SerialCom::config() {
     logger(logDEBUG3) << __PRETTY_FUNCTION__;
 
     logger(logDEBUG3) << "Configuring serial device " << m_port;
-    logger(logDEBUG3) << "  Baud Rate: " << m_baudrate;
+    logger(logDEBUG3) << "  Baud Rate: " << static_cast<speed_t>(m_baudrate);
     logger(logDEBUG3) << "  Enable parity bit: " << m_parityBit;
     logger(logDEBUG3) << "  Use two stop bits: " << m_twoStopBits;
     logger(logDEBUG3) << "  Enable hardware flow control: " << m_flowControl;
-    logger(logDEBUG3) << "  Character size: " << m_charsize;
+    logger(logDEBUG3) << "  Character size: "
+                      << static_cast<tcflag_t>(m_charsize);
 
     ScopeLock lock(this);
     if (tcgetattr(m_dev, &m_tty))
@@ -111,8 +139,8 @@ void SerialCom::config() {
 
     m_tty_old = m_tty;
 
-    cfsetospeed(&m_tty, m_baudrate);
-    cfsetispeed(&m_tty, m_baudrate);
+    cfsetospeed(&m_tty, static_cast<speed_t>(m_baudrate));
+    cfsetispeed(&m_tty, static_cast<speed_t>(m_baudrate));
 
     if (m_parityBit)
         m_tty.c_cflag &= PARENB;
@@ -130,7 +158,7 @@ void SerialCom::config() {
         m_tty.c_cflag &= ~CRTSCTS;
 
     m_tty.c_cflag &= ~CSIZE;
-    m_tty.c_cflag |= m_charsize;
+    m_tty.c_cflag |= static_cast<tcflag_t>(m_charsize);
     m_tty.c_cflag |= CREAD | CLOCAL;  // turn on READ & ignore ctrl lines
 
     cfmakeraw(&m_tty);
diff --git a/src/libCom/SerialCom.h b/src/libCom/SerialCom.h
index 1e434434..8d437baa 100644
--- a/src/libCom/SerialCom.h
+++ b/src/libCom/SerialCom.h
@@ -24,8 +24,43 @@
  */
 class SerialCom : public ICom {
  public:
+    /** Available baud rates */
+    enum class BaudRate : speed_t {
+        Baud0 = B0,
+        Baud50 = B50,
+        Baud75 = B75,
+        Baud110 = B110,
+        Baud134 = B134,
+        Baud150 = B150,
+        Baud200 = B200,
+        Baud300 = B300,
+        Baud600 = B600,
+        Baud1200 = B1200,
+        Baud1800 = B1800,
+        Baud2400 = B2400,
+        Baud4800 = B4800,
+        Baud9600 = B9600,
+        Baud19200 = B19200,
+        Baud38400 = B38400,
+        Baud57600 = B57600,
+        Baud115200 = B115200,
+        Baud230400 = B230400,
+        Baud460800 = B460800,
+        Baud500000 = B500000,
+        Baud576000 = B576000,
+        Baud921600 = B921600,
+        Baud1000000 = B1000000,
+        Baud1152000 = B1152000,
+        Baud1500000 = B1500000,
+        Baud2000000 = B2000000,
+        Baud2500000 = B2500000,
+        Baud3000000 = B3000000,
+        Baud3500000 = B3500000,
+        Baud4000000 = B4000000
+    };
+
     /** Available character sizes */
-    enum CharSize {
+    enum class CharSize : tcflag_t {
         CharSize5 = CS5,
         CharSize6 = CS6,
         CharSize7 = CS7,
@@ -41,7 +76,7 @@ class SerialCom : public ICom {
      * @param flowControl Enable hardware flow control
      * @param charsize Size of a character
      */
-    SerialCom(const std::string& port, speed_t baud = B19200,
+    SerialCom(const std::string& port, BaudRate baud = BaudRate::Baud19200,
               bool parityBit = false, bool twoStopBits = false,
               bool flowControl = false,
               CharSize charsize = CharSize::CharSize8);
@@ -187,7 +222,7 @@ class SerialCom : public ICom {
     std::string m_port;
 
     /// Baud rate to use
-    speed_t m_baudrate = B19200;
+    BaudRate m_baudrate = BaudRate::Baud19200;
 
     /// Use parity bit
     bool m_parityBit = false;
@@ -228,8 +263,9 @@ class SerialCom : public ICom {
     //! Temporary buffer for ::read()
     char m_tmpbuf[MAX_READ];
 
-    //! Maps valid baud rate settings to `speed_t` type
-    static const std::unordered_map<std::string, speed_t> mapBAUDRATE;
+    //! Maps valid baud rate settings to `BaudRate` type
+    static const std::unordered_map<std::string, SerialCom::BaudRate>
+        mapBAUDRATE;
 
     //! Maps valid char size settings to `CharSize` type
     static const std::unordered_map<std::string, SerialCom::CharSize>
diff --git a/src/libCom/TextSerialCom.cpp b/src/libCom/TextSerialCom.cpp
index 69396132..df5af5e8 100644
--- a/src/libCom/TextSerialCom.cpp
+++ b/src/libCom/TextSerialCom.cpp
@@ -15,9 +15,9 @@
 #include "ComRegistry.h"
 REGISTER_COM(TextSerialCom)
 
-TextSerialCom::TextSerialCom(const std::string& port, speed_t baud,
+TextSerialCom::TextSerialCom(const std::string& port, SerialCom::BaudRate baud,
                              bool parityBit, bool twoStopBits, bool flowControl,
-                             CharSize charsize)
+                             SerialCom::CharSize charsize)
     : SerialCom(port, baud, parityBit, twoStopBits, flowControl, charsize) {}
 
 TextSerialCom::TextSerialCom() : SerialCom() {}
diff --git a/src/libCom/TextSerialCom.h b/src/libCom/TextSerialCom.h
index 986203ec..1b4e9833 100644
--- a/src/libCom/TextSerialCom.h
+++ b/src/libCom/TextSerialCom.h
@@ -22,10 +22,12 @@ class TextSerialCom : public SerialCom {
      * @param flowControl Enable hardware flow control
      * @param charsize Size of a character
      */
-    TextSerialCom(const std::string& port, speed_t baud = B19200,
-                  bool parityBit = false, bool twoStopBits = false,
-                  bool flowControl = false,
-                  CharSize charsize = CharSize::CharSize8);
+    TextSerialCom(
+        const std::string& port,
+        SerialCom::BaudRate baud = SerialCom::BaudRate::Baud19200,
+        bool parityBit = false, bool twoStopBits = false,
+        bool flowControl = false,
+        SerialCom::CharSize charsize = SerialCom::CharSize::CharSize8);
     TextSerialCom();
 
     ~TextSerialCom() = default;
diff --git a/src/libCom/python.cpp b/src/libCom/python.cpp
index 359195bb..d71be8c9 100644
--- a/src/libCom/python.cpp
+++ b/src/libCom/python.cpp
@@ -149,6 +149,39 @@ void register_com(py::module &m) {
     py::class_<SerialCom, PyCom<SerialCom>, ICom, std::shared_ptr<SerialCom>>
         py_serialcom(m, "SerialCom");
     // nb: enum defined first because it is used in py_serialcom init() default
+    py::enum_<SerialCom::BaudRate>(py_serialcom, "BaudRate")
+        .value("Baud0", SerialCom::BaudRate::Baud0)
+        .value("Baud50", SerialCom::BaudRate::Baud50)
+        .value("Baud75", SerialCom::BaudRate::Baud75)
+        .value("Baud110", SerialCom::BaudRate::Baud110)
+        .value("Baud134", SerialCom::BaudRate::Baud134)
+        .value("Baud150", SerialCom::BaudRate::Baud150)
+        .value("Baud200", SerialCom::BaudRate::Baud200)
+        .value("Baud300", SerialCom::BaudRate::Baud300)
+        .value("Baud600", SerialCom::BaudRate::Baud600)
+        .value("Baud1200", SerialCom::BaudRate::Baud1200)
+        .value("Baud1800", SerialCom::BaudRate::Baud1800)
+        .value("Baud2400", SerialCom::BaudRate::Baud2400)
+        .value("Baud4800", SerialCom::BaudRate::Baud4800)
+        .value("Baud9600", SerialCom::BaudRate::Baud9600)
+        .value("Baud19200", SerialCom::BaudRate::Baud19200)
+        .value("Baud38400", SerialCom::BaudRate::Baud38400)
+        .value("Baud57600", SerialCom::BaudRate::Baud57600)
+        .value("Baud115200", SerialCom::BaudRate::Baud115200)
+        .value("Baud230400", SerialCom::BaudRate::Baud230400)
+        .value("Baud460800", SerialCom::BaudRate::Baud460800)
+        .value("Baud500000", SerialCom::BaudRate::Baud500000)
+        .value("Baud576000", SerialCom::BaudRate::Baud576000)
+        .value("Baud921600", SerialCom::BaudRate::Baud921600)
+        .value("Baud1000000", SerialCom::BaudRate::Baud1000000)
+        .value("Baud1152000", SerialCom::BaudRate::Baud1152000)
+        .value("Baud1500000", SerialCom::BaudRate::Baud1500000)
+        .value("Baud2000000", SerialCom::BaudRate::Baud2000000)
+        .value("Baud2500000", SerialCom::BaudRate::Baud2500000)
+        .value("Baud3000000", SerialCom::BaudRate::Baud3000000)
+        .value("Baud3500000", SerialCom::BaudRate::Baud3500000)
+        .value("Baud4000000", SerialCom::BaudRate::Baud4000000);
+
     py::enum_<SerialCom::CharSize>(py_serialcom, "CharSize")
         .value("CharSize5", SerialCom::CharSize::CharSize5)
         .value("CharSize6", SerialCom::CharSize::CharSize6)
@@ -156,9 +189,9 @@ void register_com(py::module &m) {
         .value("CharSize8", SerialCom::CharSize::CharSize8);
 
     py_serialcom
-        .def(py::init<const std::string &, speed_t, bool, bool, bool,
-                      SerialCom::CharSize>(),
-             py::arg("port"), py::arg("baud") = B19200,
+        .def(py::init<const std::string &, SerialCom::BaudRate, bool, bool,
+                      bool, SerialCom::CharSize>(),
+             py::arg("port"), py::arg("baud") = SerialCom::BaudRate::Baud19200,
              py::arg("parityBit") = false, py::arg("twoStopBits") = false,
              py::arg("flowControl") = false,
              py::arg("charsize") = SerialCom::CharSize::CharSize8)
@@ -167,9 +200,9 @@ void register_com(py::module &m) {
 
     py::class_<TextSerialCom, PyTextSerialCom, SerialCom,
                std::shared_ptr<TextSerialCom>>(m, "TextSerialCom")
-        .def(py::init<const std::string &, speed_t, bool, bool, bool,
-                      SerialCom::CharSize>(),
-             py::arg("port"), py::arg("baud") = B19200,
+        .def(py::init<const std::string &, SerialCom::BaudRate, bool, bool,
+                      bool, SerialCom::CharSize>(),
+             py::arg("port"), py::arg("baud") = SerialCom::BaudRate::Baud19200,
              py::arg("parityBit") = false, py::arg("twoStopBits") = false,
              py::arg("flowControl") = false,
              py::arg("charsize") = SerialCom::CharSize::CharSize8)
@@ -178,9 +211,10 @@ void register_com(py::module &m) {
 
     py::class_<GPIBSerialCom, PyGPIBSerialCom, TextSerialCom,
                std::shared_ptr<GPIBSerialCom>>(m, "GPIBSerialCom")
-        .def(py::init<uint16_t, const std::string &, speed_t, bool, bool, bool,
-                      SerialCom::CharSize>(),
-             py::arg("gpib_addr"), py::arg("port"), py::arg("baud") = B19200,
+        .def(py::init<uint16_t, const std::string &, SerialCom::BaudRate, bool,
+                      bool, bool, SerialCom::CharSize>(),
+             py::arg("gpib_addr"), py::arg("port"),
+             py::arg("baud") = SerialCom::BaudRate::Baud19200,
              py::arg("parityBit") = false, py::arg("twoStopBits") = false,
              py::arg("flowControl") = false,
              py::arg("charsize") = SerialCom::CharSize::CharSize8);
diff --git a/src/libLoad/TTILD400P.cpp b/src/libLoad/TTILD400P.cpp
index 70c86a90..022137f5 100644
--- a/src/libLoad/TTILD400P.cpp
+++ b/src/libLoad/TTILD400P.cpp
@@ -3,9 +3,10 @@
 #include <algorithm>
 
 #include "Logger.h"
+#include "SerialCom.h"
 
 TTILD400P::TTILD400P(std::string dev, unsigned addr) {
-    m_com = new SerialCom(dev, B115200);
+    m_com = new SerialCom(dev, SerialCom::BaudRate::Baud115200);
     m_addr = addr;
     m_com->send("++auto 0\n\r");
     m_channel = 0;
diff --git a/src/libLoad/TTILD400P.h b/src/libLoad/TTILD400P.h
index c46e6237..5d6edbb4 100644
--- a/src/libLoad/TTILD400P.h
+++ b/src/libLoad/TTILD400P.h
@@ -13,7 +13,7 @@
 #include <thread>
 
 #include "GenericLoad.h"
-#include "SerialCom.h"
+class SerialCom;
 
 class TTILD400P : public GenericLoad {
  public:
diff --git a/src/libMeter/Fluke8842.cpp b/src/libMeter/Fluke8842.cpp
index 91447204..a0e0aad7 100644
--- a/src/libMeter/Fluke8842.cpp
+++ b/src/libMeter/Fluke8842.cpp
@@ -1,9 +1,10 @@
 #include "Fluke8842.h"
 
 #include "Logger.h"
+#include "SerialCom.h"
 
 Fluke8842::Fluke8842(std::string dev, unsigned addr) {
-    m_com = new SerialCom(dev, B115200);
+    m_com = new SerialCom(dev, SerialCom::BaudRate::Baud115200);
     m_addr = addr;
     m_com->send("++auto 0\n\r");
 }
diff --git a/src/libMeter/Fluke8842.h b/src/libMeter/Fluke8842.h
index f33998dd..fb0cdb9a 100644
--- a/src/libMeter/Fluke8842.h
+++ b/src/libMeter/Fluke8842.h
@@ -13,7 +13,7 @@
 #include <string>
 #include <thread>
 
-#include "SerialCom.h"
+class SerialCom;
 
 enum class FlukeMode { VOLTAGEDC, VOLTAGEAC, CURRENTDC, CURRENTAC };
 
diff --git a/src/libMeter/HP3478A.cpp b/src/libMeter/HP3478A.cpp
index 60f08e87..8ab9639b 100644
--- a/src/libMeter/HP3478A.cpp
+++ b/src/libMeter/HP3478A.cpp
@@ -1,11 +1,12 @@
 #include "HP3478A.h"
 
 #include "Logger.h"
+#include "SerialCom.h"
 
 // Commands predate SCPI. See manual for more details.
 
 HP3478A::HP3478A(std::string dev, unsigned addr) {
-    m_com = new SerialCom(dev, B115200);
+    m_com = new SerialCom(dev, SerialCom::BaudRate::Baud115200);
     m_addr = addr;
     m_com->send("++auto 0\n\r");
 }
diff --git a/src/libMeter/HP3478A.h b/src/libMeter/HP3478A.h
index 1f51b11f..06cddee0 100644
--- a/src/libMeter/HP3478A.h
+++ b/src/libMeter/HP3478A.h
@@ -14,7 +14,7 @@
 #include <string>
 #include <thread>
 
-#include "SerialCom.h"
+class SerialCom;
 
 enum class HPMode {
     SETTING,
diff --git a/src/libMeter/Keithley2000.cpp b/src/libMeter/Keithley2000.cpp
index 65e4d923..89eb5e6a 100644
--- a/src/libMeter/Keithley2000.cpp
+++ b/src/libMeter/Keithley2000.cpp
@@ -1,9 +1,10 @@
 #include "Keithley2000.h"
 
 #include "Logger.h"
+#include "SerialCom.h"
 
 Keithley2000::Keithley2000(std::string dev, unsigned addr) {
-    m_com = new SerialCom(dev, B115200);
+    m_com = new SerialCom(dev, SerialCom::BaudRate::Baud115200);
     m_addr = addr;
     m_com->send("++auto 0\n\r");
 }
diff --git a/src/libMeter/Keithley2000.h b/src/libMeter/Keithley2000.h
index a5d3bddf..ce3be327 100644
--- a/src/libMeter/Keithley2000.h
+++ b/src/libMeter/Keithley2000.h
@@ -13,7 +13,8 @@
 #include <string>
 #include <thread>
 
-#include "SerialCom.h"
+//#include "SerialCom.h"
+class SerialCom;
 
 enum class KeithleyMode { VOLTAGE, CURRENT };
 
diff --git a/src/libScope/Tektronix654C.cpp b/src/libScope/Tektronix654C.cpp
index 3b741599..69aad17d 100644
--- a/src/libScope/Tektronix654C.cpp
+++ b/src/libScope/Tektronix654C.cpp
@@ -11,9 +11,10 @@
 #include <string>
 
 #include "Logger.h"
+#include "SerialCom.h"
 
 Tektronix654C::Tektronix654C(std::string dev, unsigned addr) {
-    m_com = new SerialCom(dev, B9600);
+    m_com = new SerialCom(dev, SerialCom::BaudRate::Baud9600);
     m_addr = addr;
     m_com->send("++auto 0\n\r");
 }
diff --git a/src/libScope/Tektronix654C.h b/src/libScope/Tektronix654C.h
index 724b42e8..eff151fa 100644
--- a/src/libScope/Tektronix654C.h
+++ b/src/libScope/Tektronix654C.h
@@ -13,7 +13,7 @@
 #include <string>
 #include <thread>
 
-#include "SerialCom.h"
+class SerialCom;
 
 class Tektronix654C {
  public:
diff --git a/src/tools/arduino_eeprom.cpp b/src/tools/arduino_eeprom.cpp
index ff9c0ada..27635236 100644
--- a/src/tools/arduino_eeprom.cpp
+++ b/src/tools/arduino_eeprom.cpp
@@ -103,7 +103,7 @@ int main(int argc, char* argv[]) {
     }
 
     std::shared_ptr<TextSerialCom> com =
-        std::make_shared<TextSerialCom>(device, B9600);
+        std::make_shared<TextSerialCom>(device, SerialCom::BaudRate::Baud9600);
     com->setTermination("\r\n");
     com->setTimeout(20);
     com->init();
-- 
GitLab