INSTINCT Code Coverage Report


Directory: src/
File: Nodes/DataProvider/Protocol/UartSensor.hpp
Date: 2025-11-25 23:34:18
Exec Total Coverage
Lines: 2 2 100.0%
Functions: 2 2 100.0%
Branches: 0 0 -%

Line Branch Exec Source
1 // This file is part of INSTINCT, the INS Toolkit for Integrated
2 // Navigation Concepts and Training by the Institute of Navigation of
3 // the University of Stuttgart, Germany.
4 //
5 // This Source Code Form is subject to the terms of the Mozilla Public
6 // License, v. 2.0. If a copy of the MPL was not distributed with this
7 // file, You can obtain one at https://mozilla.org/MPL/2.0/.
8
9 /// @file UartSensor.hpp
10 /// @brief Abstract Uart Sensor Class
11 /// @author T. Topp (topp@ins.uni-stuttgart.de)
12 /// @date 2020-03-11
13
14 #pragma once
15
16 #include <string>
17
18 #include <fmt/ostream.h>
19 #include <nlohmann/json.hpp>
20 using json = nlohmann::json; ///< json namespace
21
22 namespace NAV
23 {
24 /// Abstract Uart Sensor Class
25 class UartSensor
26 {
27 public:
28 /// Available Baudrates
29 enum Baudrate : uint32_t
30 {
31 BAUDRATE_FASTEST = 0, ///< Fastest possible Baudrate will be automatically chosen
32 BAUDRATE_9600 = 9600, ///< Baudrate with 9600 symbols per second [Baud]
33 BAUDRATE_19200 = 19200, ///< Baudrate with 19200 symbols per second [Baud]
34 BAUDRATE_38400 = 38400, ///< Baudrate with 38400 symbols per second [Baud]
35 BAUDRATE_57600 = 57600, ///< Baudrate with 57600 symbols per second [Baud]
36 BAUDRATE_115200 = 115200, ///< Baudrate with 115200 symbols per second [Baud]
37 BAUDRATE_128000 = 128000, ///< Baudrate with 128000 symbols per second [Baud]
38 BAUDRATE_230400 = 230400, ///< Baudrate with 230400 symbols per second [Baud]
39 BAUDRATE_460800 = 460800, ///< Baudrate with 460800 symbols per second [Baud]
40 BAUDRATE_921600 = 921600, ///< Baudrate with 921600 symbols per second [Baud]
41 BAUDRATE_2000000 = 2000000 ///< Baudrate with 2000000 symbols per second [Baud]
42 };
43
44 /// @brief Destructor
45 684 ~UartSensor() = default;
46 /// @brief Copy constructor
47 UartSensor(const UartSensor&) = delete;
48 /// @brief Move constructor
49 UartSensor(UartSensor&&) = delete;
50 /// @brief Copy assignment operator
51 UartSensor& operator=(const UartSensor&) = delete;
52 /// @brief Move assignment operator
53 UartSensor& operator=(UartSensor&&) = delete;
54
55 protected:
56 /// @brief Default constructor
57 684 UartSensor() = default;
58
59 /// @brief Saves the node into a json object
60 [[nodiscard]] json save() const;
61
62 /// @brief Restores the node from a json object
63 /// @param[in] j Json object with the node state
64 void restore(const json& j);
65
66 /// @brief Returns the Baudrate for the element Selected by the GUI
67 [[nodiscard]] Baudrate sensorBaudrate() const;
68
69 /// @brief Returns the guiSelection for the given baudrate
70 /// @param[in] baud Baudrate to convert
71 static int baudrate2Selection(Baudrate baud);
72
73 /// COM port where the sensor is attached to
74 ///
75 /// - "COM1" (Windows format for physical and virtual (USB) serial port)
76 /// - "/dev/ttyS1" (Linux format for physical serial port)
77 /// - "/dev/ttyUSB0" (Linux format for virtual (USB) serial port)
78 /// - "/dev/tty.usbserial-FTXXXXXX" (Mac OS X format for virtual (USB) serial port)
79 /// - "/dev/ttyS0" (CYGWIN format. Usually the Windows COM port number minus 1. This would connect to COM1)
80 std::string _sensorPort;
81
82 /// Baudrate for the sensor
83 int _selectedBaudrate = 0;
84 };
85
86 } // namespace NAV
87
88 #ifndef DOXYGEN_IGNORE
89
90 template<>
91 struct fmt::formatter<NAV::UartSensor::Baudrate> : ostream_formatter
92 {};
93
94 #endif
95