libdrmconf 0.12.1
A library to program DMR radios.
Loading...
Searching...
No Matches
signaling.hh
1#ifndef SIGNALING_HH
2#define SIGNALING_HH
3
4#include <yaml-cpp/yaml.h>
5#include <QString>
6#include <QObject>
7
8
13{
14protected:
15 enum class Type {
16 None, CTCSS, DCS
17 };
18
19public:
23 SelectiveCall(double ctcssFreq);
25 SelectiveCall(unsigned int octalDSCCode, bool inverted);
26
28 bool operator==(const SelectiveCall &other) const;
30 bool operator!=(const SelectiveCall &other) const;
31
33 bool isInvalid() const;
35 bool isValid() const;
37 bool isCTCSS() const;
39 bool isDCS() const;
40
42 double Hz() const;
44 unsigned int mHz() const;
45
47 unsigned int binCode() const;
49 unsigned int octalCode() const;
51 bool isInverted() const;
52
54 QString format() const;
55
56public:
58 static SelectiveCall parseCTCSS(const QString &text);
60 static SelectiveCall parseDCS(const QString &text);
62 static SelectiveCall fromBinaryDCS(unsigned int code, bool inverted);
64 static const QVector<SelectiveCall> &standard();
65
66protected:
68 Type type;
69 union {
71 uint16_t ctcss;
72 struct {
74 uint16_t code;
77 } dcs;
78 };
79
80protected:
81 static QVector<SelectiveCall> _standard;
82};
83
84
85Q_DECLARE_METATYPE(SelectiveCall)
86
87
88namespace YAML
89{
91 template<>
92 struct convert<SelectiveCall>
93 {
95 static Node encode(const SelectiveCall& rhs) {
96 Node node;
97 if (rhs.isCTCSS())
98 node["ctcss"] = rhs.format().toStdString();
99 else if (rhs.isDCS())
100 node["dcs"] = rhs.format().toStdString();
101 return node;
102 }
103
105 static bool decode(const Node& node, SelectiveCall& rhs) {
106 if (node.IsNull()) {
107 rhs = SelectiveCall();
108 return true;
109 }
110
111 if ((! node.IsMap()) || (1 != node.size()))
112 return false;
113
114 if (node["ctcss"])
115 rhs = SelectiveCall::parseCTCSS(QString::fromStdString(node["ctcss"].as<std::string>()));
116
117 if (node["dcs"])
118 rhs = SelectiveCall::parseDCS(QString::fromStdString(node["dcs"].as<std::string>()));
119
120 return rhs.isValid();
121 }
122 };
123}
124
125#endif // SIGNALING_HH
Encodes a selective call.
Definition signaling.hh:13
unsigned int mHz() const
If a CTCSS sub tone is set, returns the frequency in mHz (integer).
Definition signaling.cc:113
static SelectiveCall parseDCS(const QString &text)
Parses a DCS code.
Definition signaling.cc:159
unsigned int binCode() const
If a DCS code is set, returns the binary code.
Definition signaling.cc:118
bool operator==(const SelectiveCall &other) const
Comparison operator.
Definition signaling.cc:74
bool isDCS() const
Returns true, if a DCS code is set.
Definition signaling.cc:103
uint16_t code
Binary DCS code.
Definition signaling.hh:74
bool isInvalid() const
Returns false, if a selective call is set.
Definition signaling.cc:88
static SelectiveCall parseCTCSS(const QString &text)
Parses a CTCSS frequency.
Definition signaling.cc:149
Type type
Specifies the selective call type.
Definition signaling.hh:68
unsigned int octalCode() const
If a DCS code is set, returns the octal code.
Definition signaling.cc:123
bool inverted
If true, the code is inverted.
Definition signaling.hh:76
bool isInverted() const
If a DCS code is set, returns the inversion flag.
Definition signaling.cc:133
bool isValid() const
Returns true, if a selective call is set.
Definition signaling.cc:93
static SelectiveCall fromBinaryDCS(unsigned int code, bool inverted)
Construct from binary DCS code.
Definition signaling.cc:171
uint16_t ctcss
CTCSS frequency in 0.1Hz.
Definition signaling.hh:71
bool operator!=(const SelectiveCall &other) const
Comparison operator.
Definition signaling.cc:83
QString format() const
Formats the selective call.
Definition signaling.cc:138
static const QVector< SelectiveCall > & standard()
Returns a vector of standard selective calls.
Definition signaling.cc:181
bool isCTCSS() const
Returns true, if a CTCSS sub tone is set.
Definition signaling.cc:98
SelectiveCall()
Empty constructor, no selective call defined.
Definition signaling.cc:51
double Hz() const
If a CTCSS sub tone is set, returns the frequency in Hz (floating point).
Definition signaling.cc:108
static Node encode(const SelectiveCall &rhs)
Serializes the selective call.
Definition signaling.hh:95
static bool decode(const Node &node, SelectiveCall &rhs)
Parses the selective call.
Definition signaling.hh:105