0.5.0
Loading...
Searching...
No Matches
UartSensor.hpp
Go to the documentation of this file.
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>
20using json = nlohmann::json; ///< json namespace
21
22namespace NAV
23{
24/// Abstract Uart Sensor Class
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 };
42
43 /// @brief Destructor
44 ~UartSensor() = default;
45 /// @brief Copy constructor
46 UartSensor(const UartSensor&) = delete;
47 /// @brief Move constructor
49 /// @brief Copy assignment operator
50 UartSensor& operator=(const UartSensor&) = delete;
51 /// @brief Move assignment operator
53
54 protected:
55 /// @brief Default constructor
56 UartSensor() = default;
57
58 /// @brief Saves the node into a json object
59 [[nodiscard]] json save() const;
60
61 /// @brief Restores the node from a json object
62 /// @param[in] j Json object with the node state
63 void restore(const json& j);
64
65 /// @brief Returns the Baudrate for the element Selected by the GUI
66 [[nodiscard]] Baudrate sensorBaudrate() const;
67
68 /// @brief Returns the guiSelection for the given baudrate
69 /// @param[in] baud Baudrate to convert
70 static int baudrate2Selection(Baudrate baud);
71
72 /// COM port where the sensor is attached to
73 ///
74 /// - "COM1" (Windows format for physical and virtual (USB) serial port)
75 /// - "/dev/ttyS1" (Linux format for physical serial port)
76 /// - "/dev/ttyUSB0" (Linux format for virtual (USB) serial port)
77 /// - "/dev/tty.usbserial-FTXXXXXX" (Mac OS X format for virtual (USB) serial port)
78 /// - "/dev/ttyS0" (CYGWIN format. Usually the Windows COM port number minus 1. This would connect to COM1)
79 std::string _sensorPort;
80
81 /// Baudrate for the sensor
83};
84
85} // namespace NAV
86
87#ifndef DOXYGEN_IGNORE
88
89template<>
90struct fmt::formatter<NAV::UartSensor::Baudrate> : ostream_formatter
91{};
92
93#endif
nlohmann::json json
json namespace
static int baudrate2Selection(Baudrate baud)
Returns the guiSelection for the given baudrate.
int _selectedBaudrate
Baudrate for the sensor.
UartSensor(const UartSensor &)=delete
Copy constructor.
Baudrate
Available Baudrates.
@ BAUDRATE_115200
Baudrate with 115200 symbols per second [Baud].
@ BAUDRATE_57600
Baudrate with 57600 symbols per second [Baud].
@ BAUDRATE_230400
Baudrate with 230400 symbols per second [Baud].
@ BAUDRATE_FASTEST
Fastest possible Baudrate will be automatically chosen.
@ BAUDRATE_128000
Baudrate with 128000 symbols per second [Baud].
@ BAUDRATE_38400
Baudrate with 38400 symbols per second [Baud].
@ BAUDRATE_9600
Baudrate with 9600 symbols per second [Baud].
@ BAUDRATE_19200
Baudrate with 19200 symbols per second [Baud].
@ BAUDRATE_921600
Baudrate with 921600 symbols per second [Baud].
@ BAUDRATE_460800
Baudrate with 460800 symbols per second [Baud].
std::string _sensorPort
UartSensor()=default
Default constructor.
UartSensor & operator=(UartSensor &&)=delete
Move assignment operator.
void restore(const json &j)
Restores the node from a json object.
UartSensor & operator=(const UartSensor &)=delete
Copy assignment operator.
UartSensor(UartSensor &&)=delete
Move constructor.
~UartSensor()=default
Destructor.
Baudrate sensorBaudrate() const
Returns the Baudrate for the element Selected by the GUI.
json save() const
Saves the node into a json object.