libdrmconf 0.14.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:
16 enum class Type {
17 None, CTCSS, DCS
18 };
19
20public:
24 SelectiveCall(double ctcssFreq);
26 SelectiveCall(unsigned int octalDSCCode, bool inverted);
27
29 bool operator==(const SelectiveCall &other) const;
31 bool operator!=(const SelectiveCall &other) const;
32
34 bool isInvalid() const;
36 bool isValid() const;
38 bool isCTCSS() const;
40 bool isDCS() const;
41
43 double Hz() const;
45 unsigned int mHz() const;
46
48 unsigned int binCode() const;
50 unsigned int octalCode() const;
52 bool isInverted() const;
53
55 QString format() const;
56
57public:
59 static SelectiveCall parseCTCSS(const QString &text);
61 static SelectiveCall parseDCS(const QString &text);
63 static SelectiveCall fromBinaryDCS(unsigned int code, bool inverted);
65 static const QVector<SelectiveCall> &standard();
66
67protected:
70 union {
72 uint16_t ctcss;
73 struct {
75 uint16_t code;
78 } dcs;
79 };
80
81protected:
83 static QVector<SelectiveCall> _standard;
84};
85
86Q_DECLARE_METATYPE(SelectiveCall)
87
88
89namespace YAML
90{
92 template<>
93 struct convert<SelectiveCall>
94 {
96 static Node encode(const SelectiveCall& rhs) {
97 Node node;
98 if (rhs.isCTCSS())
99 node["ctcss"] = rhs.format().toStdString();
100 else if (rhs.isDCS())
101 node["dcs"] = rhs.format().toStdString();
102 return node;
103 }
104
106 static bool decode(const Node& node, SelectiveCall& rhs) {
107 if (node.IsNull()) {
108 rhs = SelectiveCall();
109 return true;
110 }
111
112 if ((! node.IsMap()) || (1 != node.size()))
113 return false;
114
115 if (node["ctcss"])
116 rhs = SelectiveCall::parseCTCSS(QString::fromStdString(node["ctcss"].as<std::string>()));
117
118 if (node["dcs"])
119 rhs = SelectiveCall::parseDCS(QString::fromStdString(node["dcs"].as<std::string>()));
120
121 return rhs.isValid();
122 }
123 };
124}
125
126#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
Type
Type of the subtone.
Definition signaling.hh:16
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:75
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:69
static QVector< SelectiveCall > _standard
Fixed table of standard values.
Definition signaling.hh:14
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:77
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:72
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:96
static bool decode(const Node &node, SelectiveCall &rhs)
Parses the selective call.
Definition signaling.hh:106