Skip to content

Commit f66f2c2

Browse files
improve pocsag alpha decoding
1 parent bddfe53 commit f66f2c2

File tree

3 files changed

+23
-52
lines changed

3 files changed

+23
-52
lines changed

CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ option(OPT_BUILD_FALCON9_DECODER "Build the falcon9 live decoder (Dependencies:
4343
option(OPT_BUILD_KG_SSTV_DECODER "Build the KG SSTV (KG-STV) decoder module (no dependencies required)" OFF)
4444
option(OPT_BUILD_M17_DECODER "Build the M17 decoder module (Dependencies: codec2)" OFF)
4545
option(OPT_BUILD_METEOR_DEMODULATOR "Build the meteor demodulator module (no dependencies required)" ON)
46-
option(OPT_BUILD_PAGER_DECODER "Build the pager decoder module (no dependencies required)" OFF)
46+
option(OPT_BUILD_PAGER_DECODER "Build the pager decoder module (no dependencies required)" ON)
4747
option(OPT_BUILD_RADIO "Main audio modulation decoder (AM, FM, SSB, etc...)" ON)
4848
option(OPT_BUILD_WEATHER_SAT_DECODER "Build the HRPT decoder module (no dependencies required)" OFF)
4949

decoder_modules/pager_decoder/src/pocsag/pocsag.cpp

+20-49
Original file line numberDiff line numberDiff line change
@@ -84,27 +84,13 @@ namespace pocsag {
8484

8585
void Decoder::flushMessage() {
8686
if (!msg.empty()) {
87-
88-
// Unpack bits
89-
std::string outStr = "";
90-
for (int i = 0; (i+7) <= msg.size(); i += 7) {
91-
uint8_t b0 = msg[i];
92-
uint8_t b1 = msg[i+1];
93-
uint8_t b2 = msg[i+2];
94-
uint8_t b3 = msg[i+3];
95-
uint8_t b4 = msg[i+4];
96-
uint8_t b5 = msg[i+5];
97-
uint8_t b6 = msg[i+6];
98-
outStr += (char)((b6<<6) | (b5<<5) | (b4<<4) | (b3<<3) | (b2<<2) | (b1<<1) | b0);
99-
}
100-
onMessage(addr, msgType, outStr);
101-
102-
// // Send out message
103-
// onMessage(addr, msgType, msg);
87+
// Send out message
88+
onMessage(addr, msgType, msg);
10489

10590
// Reset state
10691
msg.clear();
107-
leftInLast = 0;
92+
currChar = 0;
93+
currOffset = 0;
10894
}
10995
}
11096

@@ -160,42 +146,27 @@ namespace pocsag {
160146
// Decode data depending on message type
161147
if (msgType == MESSAGE_TYPE_NUMERIC) {
162148
// Numeric messages pack 5 characters per message codeword
163-
//msg += NUMERIC_CHARSET[(data >> 16) & 0b1111];
164-
//msg += NUMERIC_CHARSET[(data >> 12) & 0b1111];
165-
//msg += NUMERIC_CHARSET[(data >> 8) & 0b1111];
166-
//msg += NUMERIC_CHARSET[(data >> 4) & 0b1111];
167-
//msg += NUMERIC_CHARSET[data & 0b1111];
149+
msg += NUMERIC_CHARSET[(data >> 16) & 0b1111];
150+
msg += NUMERIC_CHARSET[(data >> 12) & 0b1111];
151+
msg += NUMERIC_CHARSET[(data >> 8) & 0b1111];
152+
msg += NUMERIC_CHARSET[(data >> 4) & 0b1111];
153+
msg += NUMERIC_CHARSET[data & 0b1111];
168154
}
169155
else if (msgType == MESSAGE_TYPE_ALPHANUMERIC) {
170-
// // Alpha messages pack 7bit characters in the entire codeword stream
171-
// int lasti;
172-
// for (int i = -leftInLast; i <= POCSAG_DATA_BITS_PER_CW-7; i += 7) {
173-
// // Read 7 bits
174-
// char c = 0;
175-
// if (i < 0) {
176-
// c = (lastMsgData & ((1 << (-i)) - 1)) << (7+i);
177-
// }
178-
// c |= (data >> (13 - i)) & 0b1111111;
179-
180-
// // Save character
181-
// bitswapChar(c, c);
182-
// msg += c;
183-
184-
// // Update last successful unpack
185-
// lasti = i;
186-
// }
187-
188-
// // Save how much is still left to read
189-
// leftInLast = 20 - (lasti + 7);
190-
191-
// Pack the bits backwards
156+
// Unpack ascii bits 7 at a time (TODO: could be more efficient)
192157
for (int i = 19; i >= 0; i--) {
193-
msg += (char)((data >> i) & 1);
158+
// Append bit to char
159+
currChar |= ((data >> i) & 1) << (currOffset++);
160+
161+
// When the char is full, append to message
162+
if (currOffset >= 7) {
163+
// TODO: maybe replace with std::isprint
164+
if (currChar) { msg += currChar; }
165+
currChar = 0;
166+
currOffset = 0;
167+
}
194168
}
195169
}
196-
197-
// Save last data
198-
lastMsgData = data;
199170
}
200171
}
201172
}

decoder_modules/pager_decoder/src/pocsag/pocsag.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ namespace pocsag {
4545
MessageType msgType;
4646
std::string msg;
4747

48-
uint32_t lastMsgData;
49-
bool leftInLast = 0;
48+
char currChar = 0;
49+
int currOffset = 0;
5050
};
5151
}

0 commit comments

Comments
 (0)