Home
About
Blog
Products
Forum
Support
Contact
Sunbelt Computer Software
PL/B Language Development and Support
Home
About
Blog
Products
Forum
Support
Contact
MMDVM_HS/M17RX.cpp at master · M17-Project/MMDVM_HS · GitHub
Skip to content
Navigation Menu
Sign in
Appearance settings
Platform
AI CODE CREATION
GitHub Copilot
Write better code with AI
GitHub Copilot app
Direct agents from issue to merge
MCP Registry
Integrate external tools
DEVELOPER WORKFLOWS
Actions
Automate any workflow
Codespaces
Instant dev environments
Issues
Plan and track work
Code Review
Manage code changes
Code Quality
Enforce quality at merge
APPLICATION SECURITY
GitHub Advanced Security
Find and fix vulnerabilities
Code security
Secure your code as you build
Secret protection
Stop leaks before they start
EXPLORE
Why GitHub
Documentation
Blog
Changelog
Marketplace
View all features
Solutions
BY COMPANY SIZE
Enterprises
Small and medium teams
Startups
Nonprofits
BY USE CASE
App Modernization
DevSecOps
DevOps
CI/CD
View all use cases
BY INDUSTRY
Healthcare
Financial services
Manufacturing
Government
See all industries
View all solutions
Resources
EXPLORE BY TOPIC
AI
Software Development
DevOps
Security
View all topics
EXPLORE BY TYPE
Customer stories
Events & webinars
Ebooks & reports
Business insights
GitHub Skills
SUPPORT & SERVICES
Documentation
Customer support
Community forum
Trust center
Partners
View all resources
Open Source
COMMUNITY
GitHub Sponsors
Fund open source developers
PROGRAMS
Security Lab
Maintainer Community
GitHub Stars
Archive Program
REPOSITORIES
Topics
Trending
Collections
Enterprise
ENTERPRISE SOLUTIONS
Enterprise platform
AI-powered developer platform
AVAILABLE ADD-ONS
GitHub Advanced Security
Enterprise-grade security features
Copilot for Business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
M17-Project
MMDVM_HS
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
More
items
Files
Expand file tree
master
Breadcrumbs
MMDVM_HS
/
M17RX.cpp
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
254 lines (213 loc) · 7.09 KB
master
Breadcrumbs
MMDVM_HS
/
M17RX.cpp
Copy path
Top
File metadata and controls
Code
Blame
254 lines (213 loc) · 7.09 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
/*
* Copyright (C) 2009-2018,2020,2021 by Jonathan Naylor G4KLX
* Copyright (C) 2016-2018 by Andy Uribe CA6JAU
*
* 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
"
Config.h
"
#
include
"
Globals.h
"
#
include
"
M17RX.h
"
#
include
"
Utils.h
"
#
include
<
stdio.h
>
const
uint8_t
MAX_SYNC_BIT_START_ERRS
=
0U
;
const
uint8_t
MAX_SYNC_BIT_RUN_ERRS
=
2U
;
const
unsigned
int
MAX_SYNC_FRAMES
=
3U
+
1U
;
const
uint8_t
BIT_MASK_TABLE
[] = {
0x80U
,
0x40U
,
0x20U
,
0x10U
,
0x08U
,
0x04U
,
0x02U
,
0x01U
};
#
define
WRITE_BIT1
(
p,i,b
) p[(i)>>
3
] = (b) ? (p[(i)>>
3
] |
BIT_MASK_TABLE
[(i)&
7
]) : (p[(i)>>
3
] & ~
BIT_MASK_TABLE
[(i)&
7
])
CM17RX
::
CM17RX
() :
m_state
(
M17RXS_NONE
),
m_bitBuffer(
0x00U
),
m_outBuffer(),
m_buffer(
NULL
),
m_bufferPtr(
0U
),
m_lostCount(
0U
)
{
m_buffer = m_outBuffer +
1U
;
}
void
CM17RX::reset
()
{
m_state =
M17RXS_NONE
;
m_bitBuffer =
0x00U
;
m_bufferPtr =
0U
;
m_lostCount =
0U
;
}
void
CM17RX::databit
(
bool
bit)
{
switch
(m_state) {
case
M17RXS_LINK_SETUP
:
case
M17RXS_STREAM
:
case
M17RXS_PACKET
:
processData
(bit);
break
;
default
:
processNone
(bit);
break
;
}
}
void
CM17RX::processNone
(
bool
bit)
{
m_bitBuffer <<=
1
;
if
(bit)
m_bitBuffer |=
0x01U
;
//
Exact matching of the packet sync bit sequence
if
(
countBits16
(m_bitBuffer ^
M17_PACKET_SYNC_BITS
) <=
MAX_SYNC_BIT_START_ERRS
) {
DEBUG1
(
"
M17RX: packet sync found in None
"
);
for
(
uint8_t
i =
0U
; i <
M17_SYNC_BYTES_LENGTH
; i++)
m_buffer[i] =
M17_PACKET_SYNC_BYTES
[i];
m_lostCount =
MAX_SYNC_FRAMES
;
m_bufferPtr =
M17_SYNC_LENGTH_BITS
;
m_state =
M17RXS_PACKET
;
io.
setDecode
(
true
);
return
;
}
//
Exact matching of the link setup sync bit sequence
if
(
countBits16
(m_bitBuffer ^
M17_LINK_SETUP_SYNC_BITS
) <=
MAX_SYNC_BIT_START_ERRS
) {
DEBUG1
(
"
M17RX: link setup sync found in None
"
);
for
(
uint8_t
i =
0U
; i <
M17_SYNC_BYTES_LENGTH
; i++)
m_buffer[i] =
M17_LINK_SETUP_SYNC_BYTES
[i];
m_lostCount =
MAX_SYNC_FRAMES
;
m_bufferPtr =
M17_SYNC_LENGTH_BITS
;
m_state =
M17RXS_LINK_SETUP
;
io.
setDecode
(
true
);
return
;
}
//
Exact matching of the stream sync bit sequence
if
(
countBits16
(m_bitBuffer ^
M17_STREAM_SYNC_BITS
) <=
MAX_SYNC_BIT_START_ERRS
) {
DEBUG1
(
"
M17RX: stream sync found in None
"
);
for
(
uint8_t
i =
0U
; i <
M17_SYNC_BYTES_LENGTH
; i++)
m_buffer[i] =
M17_STREAM_SYNC_BYTES
[i];
m_lostCount =
MAX_SYNC_FRAMES
;
m_bufferPtr =
M17_SYNC_LENGTH_BITS
;
m_state =
M17RXS_STREAM
;
io.
setDecode
(
true
);
return
;
}
}
void
CM17RX::processData
(
bool
bit)
{
m_bitBuffer <<=
1
;
if
(bit)
m_bitBuffer |=
0x01U
;
WRITE_BIT1
(m_buffer, m_bufferPtr, bit);
m_bufferPtr++;
if
(m_bufferPtr >
M17_FRAME_LENGTH_BITS
)
reset
();
//
Only search for the syncs in the right place +-1 bit
if
(m_bufferPtr >= (
M17_SYNC_LENGTH_BITS
-
1U
) && m_bufferPtr <= (
M17_SYNC_LENGTH_BITS
+
1U
)) {
//
Fuzzy matching of the packet sync bit sequence
if
(
countBits16
(m_bitBuffer ^
M17_PACKET_SYNC_BITS
) <=
MAX_SYNC_BIT_RUN_ERRS
) {
DEBUG2
(
"
M17RX: found packet sync, pos
"
, m_bufferPtr -
M17_SYNC_LENGTH_BITS
);
m_lostCount =
MAX_SYNC_FRAMES
;
m_bufferPtr =
M17_SYNC_LENGTH_BITS
;
m_state =
M17RXS_PACKET
;
return
;
}
//
Fuzzy matching of the link setup sync bit sequence
if
(
countBits16
(m_bitBuffer ^
M17_LINK_SETUP_SYNC_BITS
) <=
MAX_SYNC_BIT_RUN_ERRS
) {
DEBUG2
(
"
M17RX: found link setup sync, pos
"
, m_bufferPtr -
M17_SYNC_LENGTH_BITS
);
m_lostCount =
MAX_SYNC_FRAMES
;
m_bufferPtr =
M17_SYNC_LENGTH_BITS
;
m_state =
M17RXS_LINK_SETUP
;
return
;
}
//
Fuzzy matching of the stream sync bit sequence
if
(
countBits16
(m_bitBuffer ^
M17_STREAM_SYNC_BITS
) <=
MAX_SYNC_BIT_RUN_ERRS
) {
DEBUG2
(
"
M17RX: found stream sync, pos
"
, m_bufferPtr -
M17_SYNC_LENGTH_BITS
);
m_lostCount =
MAX_SYNC_FRAMES
;
m_bufferPtr =
M17_SYNC_LENGTH_BITS
;
m_state =
M17RXS_STREAM
;
return
;
}
//
Fuzzy matching of the packet sync bit sequence
if
(
countBits16
(m_bitBuffer ^
M17_PACKET_SYNC_BITS
) <=
MAX_SYNC_BIT_RUN_ERRS
) {
DEBUG2
(
"
M17RX: found packet sync, pos
"
, m_bufferPtr -
M17_SYNC_LENGTH_BITS
);
m_lostCount =
MAX_SYNC_FRAMES
;
m_bufferPtr =
M17_SYNC_LENGTH_BITS
;
m_state =
M17RXS_PACKET
;
return
;
}
//
Fuzzy matching of the EOT sync bit sequence
if
(
countBits16
(m_bitBuffer ^
M17_EOT_SYNC_BITS
) <=
MAX_SYNC_BIT_RUN_ERRS
) {
DEBUG2
(
"
M17RX: found eot sync, pos
"
, m_bufferPtr -
M17_SYNC_LENGTH_BITS
);
io.
setDecode
(
false
);
serial.
writeM17EOT
();
reset
();
return
;
}
}
//
Send a frame to the host if the required number of bits have been received
if
(m_bufferPtr ==
M17_FRAME_LENGTH_BITS
) {
//
We've not seen a sync for too long, signal RXLOST and change to RX_NONE
m_lostCount--;
if
(m_lostCount ==
0U
) {
DEBUG1
(
"
M17RX: sync timed out, lost lock
"
);
io.
setDecode
(
false
);
serial.
writeM17Lost
();
reset
();
}
else
{
//
Write data to host
m_outBuffer[
0U
] = m_lostCount == (
MAX_SYNC_FRAMES
-
1U
) ?
0x01U
:
0x00U
;
switch
(m_state) {
case
M17RXS_LINK_SETUP
:
writeRSSILinkSetup
(m_outBuffer);
break
;
case
M17RXS_STREAM
:
writeRSSIStream
(m_outBuffer);
break
;
case
M17RXS_PACKET
:
writeRSSIPacket
(m_outBuffer);
break
;
default
:
break
;
}
//
Start the next frame
::memset
(m_outBuffer,
0x00U
,
M17_FRAME_LENGTH_BYTES
+
3U
);
m_bufferPtr =
0U
;
}
}
}
void
CM17RX::writeRSSILinkSetup
(
uint8_t
* data)
{
#
if
defined(SEND_RSSI_DATA)
uint16_t
rssi = io.
readRSSI
();
data[
49U
] = (rssi >>
8
) &
0xFFU
;
data[
50U
] = (rssi >>
0
) &
0xFFU
;
serial.
writeM17LinkSetup
(data,
M17_FRAME_LENGTH_BYTES
+
3U
);
#
else
serial.
writeM17LinkSetup
(data,
M17_FRAME_LENGTH_BYTES
+
1U
);
#
endif
}
void
CM17RX::writeRSSIStream
(
uint8_t
* data)
{
#
if
defined(SEND_RSSI_DATA)
uint16_t
rssi = io.
readRSSI
();
data[
49U
] = (rssi >>
8
) &
0xFFU
;
data[
50U
] = (rssi >>
0
) &
0xFFU
;
serial.
writeM17Stream
(data,
M17_FRAME_LENGTH_BYTES
+
3U
);
#
else
serial.
writeM17Stream
(data,
M17_FRAME_LENGTH_BYTES
+
1U
);
#
endif
}
void
CM17RX::writeRSSIPacket
(
uint8_t
* data)
{
#
if
defined(SEND_RSSI_DATA)
uint16_t
rssi = io.
readRSSI
();
data[
49U
] = (rssi >>
8
) &
0xFFU
;
data[
50U
] = (rssi >>
0
) &
0xFFU
;
serial.
writeM17Packet
(data,
M17_FRAME_LENGTH_BYTES
+
3U
);
#
else
serial.
writeM17Packet
(data,
M17_FRAME_LENGTH_BYTES
+
1U
);
#
endif
}
You can’t perform that action at this time.