Skip to content

Commit a08d2a0

Browse files
more work on debugging the pager decoder
1 parent 7ab743d commit a08d2a0

File tree

4 files changed

+91
-18
lines changed

4 files changed

+91
-18
lines changed

decoder_modules/pager_decoder/src/pocsag/decoder.h

+11-4
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,12 @@ const char* msgTypes[] = {
1515
"Alphanumeric",
1616
};
1717

18+
#define BAUDRATE 2400
19+
#define SAMPLERATE (BAUDRATE*10)
20+
1821
class POCSAGDecoder : public Decoder {
1922
public:
20-
POCSAGDecoder(const std::string& name, VFOManager::VFO* vfo) : diag(0.6, 2400) {
23+
POCSAGDecoder(const std::string& name, VFOManager::VFO* vfo) : diag(0.6, BAUDRATE) {
2124
this->name = name;
2225
this->vfo = vfo;
2326

@@ -28,9 +31,9 @@ class POCSAGDecoder : public Decoder {
2831

2932
// Init DSP
3033
vfo->setBandwidthLimits(12500, 12500, true);
31-
vfo->setSampleRate(24000, 12500);
32-
dsp.init(vfo->output, 24000, 2400);
33-
reshape.init(&dsp.soft, 2400.0, (2400 / 30.0) - 2400.0);
34+
vfo->setSampleRate(SAMPLERATE, 12500);
35+
dsp.init(vfo->output, SAMPLERATE, BAUDRATE);
36+
reshape.init(&dsp.soft, BAUDRATE, (BAUDRATE / 30.0) - BAUDRATE);
3437
dataHandler.init(&dsp.out, _dataHandler, this);
3538
diagHandler.init(&reshape.out, _diagHandler, this);
3639

@@ -49,6 +52,10 @@ class POCSAGDecoder : public Decoder {
4952
// TODO
5053
}
5154

55+
if (ImGui::Button("Detune")) {
56+
dsp.detune();
57+
}
58+
5259
ImGui::FillWidth();
5360
diag.draw();
5461
}

decoder_modules/pager_decoder/src/pocsag/dsp.h

+9-5
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ class POCSAGDSP : public dsp::Processor<dsp::complex_t, uint8_t> {
2323

2424
// Configure blocks
2525
demod.init(NULL, -4500.0, samplerate);
26-
dcBlock.init(NULL, 0.001);
26+
//dcBlock.init(NULL, 0.001); // NOTE: DC blocking causes issues because no scrambling, think more about it
2727
float taps[] = { 0.1f, 0.1f, 0.1f, 0.1f, 0.1f, 0.1f, 0.1f, 0.1f, 0.1f, 0.1f };
2828
shape = dsp::taps::fromArray<float>(10, taps);
2929
fir.init(NULL, shape);
30-
recov.init(NULL, samplerate/baudrate, 1e5, 0.1, 0.05);
30+
recov.init(NULL, samplerate/baudrate, 1e-4, 1.0, 0.05);
3131

3232
// Free useless buffers
33-
dcBlock.out.free();
33+
// dcBlock.out.free();
3434
fir.out.free();
3535
recov.out.free();
3636

@@ -40,13 +40,17 @@ class POCSAGDSP : public dsp::Processor<dsp::complex_t, uint8_t> {
4040

4141
int process(int count, dsp::complex_t* in, float* softOut, uint8_t* out) {
4242
count = demod.process(count, in, demod.out.readBuf);
43-
count = dcBlock.process(count, demod.out.readBuf, demod.out.readBuf);
43+
//count = dcBlock.process(count, demod.out.readBuf, demod.out.readBuf);
4444
count = fir.process(count, demod.out.readBuf, demod.out.readBuf);
4545
count = recov.process(count, demod.out.readBuf, softOut);
4646
dsp::digital::BinarySlicer::process(count, softOut, out);
4747
return count;
4848
}
4949

50+
void detune() {
51+
recov.setOmega(9.99);
52+
}
53+
5054
int run() {
5155
int count = base_type::_in->read();
5256
if (count < 0) { return -1; }
@@ -63,7 +67,7 @@ class POCSAGDSP : public dsp::Processor<dsp::complex_t, uint8_t> {
6367

6468
private:
6569
dsp::demod::Quadrature demod;
66-
dsp::correction::DCBlocker<float> dcBlock;
70+
//dsp::correction::DCBlocker<float> dcBlock;
6771
dsp::tap<float> shape;
6872
dsp::filter::FIR<float, float> fir;
6973
dsp::clock_recovery::MM<float> recov;

decoder_modules/pager_decoder/src/pocsag/pocsag.cpp

+68-9
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#define POCSAG_FRAME_SYNC_CODEWORD ((uint32_t)(0b01111100110100100001010111011000))
66
#define POCSAG_IDLE_CODEWORD_DATA ((uint32_t)(0b011110101100100111000))
77
#define POCSAG_BATCH_BIT_COUNT (POCSAG_BATCH_CODEWORD_COUNT*32)
8+
#define POCSAG_DATA_BITS_PER_CW 20
89

910
#define POCSAG_GEN_POLY ((uint32_t)(0b11101101001))
1011

@@ -28,6 +29,11 @@ namespace pocsag {
2829
'['
2930
};
3031

32+
Decoder::Decoder() {
33+
// Zero out batch
34+
memset(batch, 0, sizeof(batch));
35+
}
36+
3137
void Decoder::process(uint8_t* symbols, int count) {
3238
for (int i = 0; i < count; i++) {
3339
// Get symbol
@@ -78,8 +84,37 @@ namespace pocsag {
7884

7985
void Decoder::flushMessage() {
8086
if (!msg.empty()) {
81-
onMessage(addr, msgType, msg);
87+
88+
// Unpack bits
89+
std::string outStr = "";
90+
91+
for (int i = 0; (i+7) <= msg.size(); i += 7) {
92+
uint8_t b0 = msg[i];
93+
uint8_t b1 = msg[i+1];
94+
uint8_t b2 = msg[i+2];
95+
uint8_t b3 = msg[i+3];
96+
uint8_t b4 = msg[i+4];
97+
uint8_t b5 = msg[i+5];
98+
uint8_t b6 = msg[i+6];
99+
outStr += (char)((b6<<6) | (b5<<5) | (b4<<4) | (b3<<3) | (b2<<2) | (b1<<1) | b0);
100+
}
101+
102+
onMessage(addr, msgType, outStr);
82103
msg.clear();
104+
leftInLast = 0;
105+
}
106+
}
107+
108+
void printbin(uint32_t cw) {
109+
for (int i = 31; i >= 0; i--) {
110+
printf("%c", ((cw >> i) & 1) ? '1':'0');
111+
}
112+
}
113+
114+
void bitswapChar(char in, char& out) {
115+
out = 0;
116+
for (int i = 0; i < 7; i++) {
117+
out |= ((in >> (6-i)) & 1) << i;
83118
}
84119
}
85120

@@ -102,14 +137,14 @@ namespace pocsag {
102137
if (type == CODEWORD_TYPE_IDLE) {
103138
// If a non-empty message is available, send it out and clear
104139
flushMessage();
105-
flog::debug("[{}:{}]: IDLE", (i >> 1), i&1);
106140
}
107141
else if (type == CODEWORD_TYPE_ADDRESS) {
108142
// If a non-empty message is available, send it out and clear
109143
flushMessage();
110144

111145
// Decode message type
112-
msgType = (MessageType)((cw >> 11) & 0b11);
146+
msgType = MESSAGE_TYPE_ALPHANUMERIC;
147+
// msgType = (MessageType)((cw >> 11) & 0b11);
113148

114149
// Decode address and append lower 8 bits from position
115150
addr = ((cw >> 13) & 0b111111111111111111) << 3;
@@ -122,14 +157,38 @@ namespace pocsag {
122157
// Decode data depending on message type
123158
if (msgType == MESSAGE_TYPE_NUMERIC) {
124159
// Numeric messages pack 5 characters per message codeword
125-
msg += NUMERIC_CHARSET[(data >> 16) & 0b1111];
126-
msg += NUMERIC_CHARSET[(data >> 12) & 0b1111];
127-
msg += NUMERIC_CHARSET[(data >> 8) & 0b1111];
128-
msg += NUMERIC_CHARSET[(data >> 4) & 0b1111];
129-
msg += NUMERIC_CHARSET[data & 0b1111];
160+
//msg += NUMERIC_CHARSET[(data >> 16) & 0b1111];
161+
//msg += NUMERIC_CHARSET[(data >> 12) & 0b1111];
162+
//msg += NUMERIC_CHARSET[(data >> 8) & 0b1111];
163+
//msg += NUMERIC_CHARSET[(data >> 4) & 0b1111];
164+
//msg += NUMERIC_CHARSET[data & 0b1111];
130165
}
131166
else if (msgType == MESSAGE_TYPE_ALPHANUMERIC) {
132-
167+
// Alpha messages pack 7bit characters in the entire codeword stream
168+
// int lasti;
169+
// for (int i = -leftInLast; i <= POCSAG_DATA_BITS_PER_CW-7; i += 7) {
170+
// // Read 7 bits
171+
// char c = 0;
172+
// if (i < 0) {
173+
// c = (lastMsgData & ((1 << (-i)) - 1)) << (7+i);
174+
// }
175+
// c |= (data >> (13 - i)) & 0b1111111;
176+
177+
// // Save character
178+
// bitswapChar(c, c);
179+
// msg += c;
180+
181+
// // Update last successful unpack
182+
// lasti = i;
183+
// }
184+
185+
// Pack the bits backwards
186+
for (int i = 19; i >= 0; i--) {
187+
msg += (char)((data >> i) & 1);
188+
}
189+
190+
// Save how much is still left to read
191+
//leftInLast = 20 - (lasti + 7);
133192
}
134193

135194
// Save last data

decoder_modules/pager_decoder/src/pocsag/pocsag.h

+3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ namespace pocsag {
2323

2424
class Decoder {
2525
public:
26+
Decoder();
27+
2628
void process(uint8_t* symbols, int count);
2729

2830
NewEvent<Address, MessageType, const std::string&> onMessage;
@@ -44,5 +46,6 @@ namespace pocsag {
4446
std::string msg;
4547

4648
uint32_t lastMsgData;
49+
bool leftInLast = 0;
4750
};
4851
}

0 commit comments

Comments
 (0)