Nix (Dev) 3.5.10
dev - 3.5.10 - 1af9301
Loading...
Searching...
No Matches
enums.hpp
Go to the documentation of this file.
1#ifndef IV_SRC_COMMS_SERIAL_ENUMS_HPP_
2#define IV_SRC_COMMS_SERIAL_ENUMS_HPP_
3
5
6#include <map>
7#include <ranges>
8#include <termios.h>
9
11{
12
13enum class eSerialMode
14{
15 Read = 1,
16 Write = 2,
17 ReadWrite = 3
18};
19
20namespace constants
21{
22
23inline constexpr std::string_view BR0 = "0";
24inline constexpr std::string_view BR50 = "50";
25inline constexpr std::string_view BR75 = "75";
26inline constexpr std::string_view BR110 = "110";
27inline constexpr std::string_view BR134 = "134";
28inline constexpr std::string_view BR150 = "150";
29inline constexpr std::string_view BR200 = "200";
30inline constexpr std::string_view BR300 = "300";
31inline constexpr std::string_view BR600 = "600";
32inline constexpr std::string_view BR1200 = "1200";
33inline constexpr std::string_view BR1800 = "1800";
34inline constexpr std::string_view BR2400 = "2400";
35inline constexpr std::string_view BR4800 = "4800";
36inline constexpr std::string_view BR9600 = "9600";
37inline constexpr std::string_view BR19200 = "19200";
38inline constexpr std::string_view BR38400 = "38400";
39inline constexpr std::string_view BR57600 = "57600";
40inline constexpr std::string_view BR115200 = "115200";
41inline constexpr std::string_view BR230400 = "230400";
42inline constexpr std::string_view BR460800 = "460800";
43inline constexpr std::string_view BR500000 = "500000";
44inline constexpr std::string_view BR576000 = "576000";
45inline constexpr std::string_view BR921600 = "921600";
46inline constexpr std::string_view BR1000000 = "1000000";
47inline constexpr std::string_view BR1152000 = "1152000";
48inline constexpr std::string_view BR1500000 = "1500000";
49inline constexpr std::string_view BR2000000 = "2000000";
50inline constexpr std::string_view BR2500000 = "2500000";
51inline constexpr std::string_view BR3000000 = "3000000";
52inline constexpr std::string_view BR3500000 = "3500000";
53inline constexpr std::string_view BR4000000 = "4000000";
54
55inline constexpr std::string_view DB5 = "5";
56inline constexpr std::string_view DB6 = "6";
57inline constexpr std::string_view DB7 = "7";
58inline constexpr std::string_view DB8 = "8";
59
60inline constexpr std::string_view SB1 = "1";
61inline constexpr std::string_view SB2 = "2";
62
63inline std::map<iv::model::comms::serial::eBaudRate, std::string_view> baudRateMap {
83#ifdef __linux__
84 {iv::model::comms::serial::eBaudRate::BR460800, BR460800},
85 {iv::model::comms::serial::eBaudRate::BR500000, BR500000},
86 {iv::model::comms::serial::eBaudRate::BR576000, BR576000},
87 {iv::model::comms::serial::eBaudRate::BR921600, BR921600},
88 {iv::model::comms::serial::eBaudRate::BR1000000, BR1000000},
89 {iv::model::comms::serial::eBaudRate::BR1152000, BR1152000},
90 {iv::model::comms::serial::eBaudRate::BR1500000, BR1500000},
91#if __MAX_BAUD > B2000000
92 {iv::model::comms::serial::eBaudRate::BR2000000, BR2000000},
93 {iv::model::comms::serial::eBaudRate::BR2500000, BR2500000},
94 {iv::model::comms::serial::eBaudRate::BR3000000, BR3000000},
95 {iv::model::comms::serial::eBaudRate::BR3500000, BR3500000},
96 {iv::model::comms::serial::eBaudRate::BR4000000, BR4000000},
97#endif
98#endif
99};
100
106
107inline std::map<iv::model::comms::serial::eStopBits, std::string_view> stopBitsMap {
110
112{
113 return baudRateMap[baudRate].data();
114}
115
116inline iv::model::comms::serial::eBaudRate getBaudRateEnum(const std::string &baudRate)
117{
118 auto baudRateEnum =
119 std::ranges::find_if(baudRateMap, [baudRate](auto &baudPair) { return baudPair.second == baudRate; });
120
121 return baudRateEnum != baudRateMap.end() ? baudRateEnum->first : iv::model::comms::serial::eBaudRate::BR0;
122}
123
125{
126 return dataBitsMap[dataBits].data();
127}
128
129inline iv::model::comms::serial::eDataBits getDataBitsEnum(const std::string &dataBits)
130{
131 auto dataBitsEnum =
132 std::ranges::find_if(dataBitsMap, [dataBits](auto &dataPair) { return dataPair.second == dataBits; });
133
134 return dataBitsEnum != dataBitsMap.end() ? dataBitsEnum->first : iv::model::comms::serial::eDataBits::DB5;
135}
136
138{
139 return stopBitsMap[stopBits].data();
140}
141
142inline iv::model::comms::serial::eStopBits getStopBitsEnum(const std::string &stopBits)
143{
144 auto stopBitsEnum =
145 std::ranges::find_if(stopBitsMap, [stopBits](auto &stopPair) { return stopPair.second == stopBits; });
146
147 return stopBitsEnum != stopBitsMap.end() ? stopBitsEnum->first : iv::model::comms::serial::eStopBits::SB1;
148}
149
150}// namespace constants
151
152}// namespace iv::comms::serial
153
154#endif//IV_SRC_COMMS_SERIAL_ENUMS_HPP_
std::string getDataBitsString(const iv::model::comms::serial::eDataBits dataBits)
Definition enums.hpp:124
std::map< iv::model::comms::serial::eDataBits, std::string_view > dataBitsMap
Definition enums.hpp:101
constexpr std::string_view SB2
Definition enums.hpp:61
constexpr std::string_view BR115200
Definition enums.hpp:40
constexpr std::string_view BR1200
Definition enums.hpp:32
constexpr std::string_view BR600
Definition enums.hpp:31
std::map< iv::model::comms::serial::eBaudRate, std::string_view > baudRateMap
Definition enums.hpp:63
constexpr std::string_view DB6
Definition enums.hpp:56
constexpr std::string_view BR2000000
Definition enums.hpp:49
constexpr std::string_view BR75
Definition enums.hpp:25
constexpr std::string_view BR921600
Definition enums.hpp:45
constexpr std::string_view BR4800
Definition enums.hpp:35
std::string getStopBitsString(const iv::model::comms::serial::eStopBits stopBits)
Definition enums.hpp:137
iv::model::comms::serial::eDataBits getDataBitsEnum(const std::string &dataBits)
Definition enums.hpp:129
constexpr std::string_view BR1000000
Definition enums.hpp:46
constexpr std::string_view BR50
Definition enums.hpp:24
constexpr std::string_view DB7
Definition enums.hpp:57
constexpr std::string_view BR134
Definition enums.hpp:27
constexpr std::string_view DB5
Definition enums.hpp:55
constexpr std::string_view BR38400
Definition enums.hpp:38
constexpr std::string_view BR2500000
Definition enums.hpp:50
constexpr std::string_view BR230400
Definition enums.hpp:41
std::string getBaudRateString(const iv::model::comms::serial::eBaudRate baudRate)
Definition enums.hpp:111
constexpr std::string_view BR4000000
Definition enums.hpp:53
constexpr std::string_view BR3500000
Definition enums.hpp:52
std::map< iv::model::comms::serial::eStopBits, std::string_view > stopBitsMap
Definition enums.hpp:107
constexpr std::string_view BR1800
Definition enums.hpp:33
constexpr std::string_view SB1
Definition enums.hpp:60
constexpr std::string_view BR19200
Definition enums.hpp:37
constexpr std::string_view BR300
Definition enums.hpp:30
constexpr std::string_view BR3000000
Definition enums.hpp:51
constexpr std::string_view BR1152000
Definition enums.hpp:47
constexpr std::string_view BR9600
Definition enums.hpp:36
constexpr std::string_view BR110
Definition enums.hpp:26
constexpr std::string_view BR460800
Definition enums.hpp:42
constexpr std::string_view BR200
Definition enums.hpp:29
iv::model::comms::serial::eStopBits getStopBitsEnum(const std::string &stopBits)
Definition enums.hpp:142
constexpr std::string_view BR576000
Definition enums.hpp:44
iv::model::comms::serial::eBaudRate getBaudRateEnum(const std::string &baudRate)
Definition enums.hpp:116
constexpr std::string_view BR500000
Definition enums.hpp:43
constexpr std::string_view BR57600
Definition enums.hpp:39
constexpr std::string_view BR1500000
Definition enums.hpp:48
constexpr std::string_view BR2400
Definition enums.hpp:34
constexpr std::string_view BR0
Definition enums.hpp:23
constexpr std::string_view BR150
Definition enums.hpp:28
constexpr std::string_view DB8
Definition enums.hpp:58
Definition enums.hpp:11
eSerialMode
Definition enums.hpp:14
eBaudRate
Definition SerialPortSettings.hpp:13
eStopBits
Definition SerialPortSettings.hpp:75
eDataBits
Definition SerialPortSettings.hpp:54