forked from g4klx/MMDVMHost
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DMRLC.cpp
218 lines (175 loc) · 3.96 KB
/
DMRLC.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
/*
* Copyright (C) 2015,2016,2019,2021,2022 by Jonathan Naylor G4KLX
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "DMRLC.h"
#include "Utils.h"
#include <cstdio>
#include <cassert>
CDMRLC::CDMRLC(FLCO flco, unsigned int srcId, unsigned int dstId) :
m_PF(false),
m_R(false),
m_FLCO(flco),
m_FID(0U),
m_options(0U),
m_srcId(srcId),
m_dstId(dstId)
{
}
CDMRLC::CDMRLC(const unsigned char* bytes) :
m_PF(false),
m_R(false),
m_FLCO(FLCO_GROUP),
m_FID(0U),
m_options(0U),
m_srcId(0U),
m_dstId(0U)
{
assert(bytes != NULL);
m_PF = (bytes[0U] & 0x80U) == 0x80U;
m_R = (bytes[0U] & 0x40U) == 0x40U;
m_FLCO = FLCO(bytes[0U] & 0x3FU);
m_FID = bytes[1U];
m_options = bytes[2U];
m_dstId = bytes[3U] << 16 | bytes[4U] << 8 | bytes[5U];
m_srcId = bytes[6U] << 16 | bytes[7U] << 8 | bytes[8U];
}
CDMRLC::CDMRLC(const bool* bits) :
m_PF(false),
m_R(false),
m_FLCO(FLCO_GROUP),
m_FID(0U),
m_options(0U),
m_srcId(0U),
m_dstId(0U)
{
assert(bits != NULL);
m_PF = bits[0U];
m_R = bits[1U];
unsigned char temp1, temp2, temp3;
CUtils::bitsToByteBE(bits + 0U, temp1);
m_FLCO = FLCO(temp1 & 0x3FU);
CUtils::bitsToByteBE(bits + 8U, temp2);
m_FID = temp2;
CUtils::bitsToByteBE(bits + 16U, temp3);
m_options = temp3;
unsigned char d1, d2, d3;
CUtils::bitsToByteBE(bits + 24U, d1);
CUtils::bitsToByteBE(bits + 32U, d2);
CUtils::bitsToByteBE(bits + 40U, d3);
unsigned char s1, s2, s3;
CUtils::bitsToByteBE(bits + 48U, s1);
CUtils::bitsToByteBE(bits + 56U, s2);
CUtils::bitsToByteBE(bits + 64U, s3);
m_srcId = s1 << 16 | s2 << 8 | s3;
m_dstId = d1 << 16 | d2 << 8 | d3;
}
CDMRLC::CDMRLC() :
m_PF(false),
m_R(false),
m_FLCO(FLCO_GROUP),
m_FID(0U),
m_options(0U),
m_srcId(0U),
m_dstId(0U)
{
}
CDMRLC::~CDMRLC()
{
}
void CDMRLC::getData(unsigned char* bytes) const
{
assert(bytes != NULL);
bytes[0U] = (unsigned char)m_FLCO;
if (m_PF)
bytes[0U] |= 0x80U;
if (m_R)
bytes[0U] |= 0x40U;
bytes[1U] = m_FID;
bytes[2U] = m_options;
bytes[3U] = m_dstId >> 16;
bytes[4U] = m_dstId >> 8;
bytes[5U] = m_dstId >> 0;
bytes[6U] = m_srcId >> 16;
bytes[7U] = m_srcId >> 8;
bytes[8U] = m_srcId >> 0;
}
void CDMRLC::getData(bool* bits) const
{
assert(bits != NULL);
unsigned char bytes[9U];
getData(bytes);
CUtils::byteToBitsBE(bytes[0U], bits + 0U);
CUtils::byteToBitsBE(bytes[1U], bits + 8U);
CUtils::byteToBitsBE(bytes[2U], bits + 16U);
CUtils::byteToBitsBE(bytes[3U], bits + 24U);
CUtils::byteToBitsBE(bytes[4U], bits + 32U);
CUtils::byteToBitsBE(bytes[5U], bits + 40U);
CUtils::byteToBitsBE(bytes[6U], bits + 48U);
CUtils::byteToBitsBE(bytes[7U], bits + 56U);
CUtils::byteToBitsBE(bytes[8U], bits + 64U);
}
bool CDMRLC::getPF() const
{
return m_PF;
}
void CDMRLC::setPF(bool pf)
{
m_PF = pf;
}
FLCO CDMRLC::getFLCO() const
{
return m_FLCO;
}
void CDMRLC::setFLCO(FLCO flco)
{
m_FLCO = flco;
}
unsigned char CDMRLC::getFID() const
{
return m_FID;
}
void CDMRLC::setFID(unsigned char fid)
{
m_FID = fid;
}
bool CDMRLC::getOVCM() const
{
return (m_options & 0x04U) == 0x04U;
}
void CDMRLC::setOVCM(bool ovcm)
{
if (ovcm)
m_options |= 0x04U;
else
m_options &= 0xFBU;
}
unsigned int CDMRLC::getSrcId() const
{
return m_srcId;
}
void CDMRLC::setSrcId(unsigned int id)
{
m_srcId = id;
}
unsigned int CDMRLC::getDstId() const
{
return m_dstId;
}
void CDMRLC::setDstId(unsigned int id)
{
m_dstId = id;
}