5
5
#define POCSAG_FRAME_SYNC_CODEWORD ((uint32_t )(0b01111100110100100001010111011000 ))
6
6
#define POCSAG_IDLE_CODEWORD_DATA ((uint32_t )(0b011110101100100111000 ))
7
7
#define POCSAG_BATCH_BIT_COUNT (POCSAG_BATCH_CODEWORD_COUNT*32 )
8
+ #define POCSAG_DATA_BITS_PER_CW 20
8
9
9
10
#define POCSAG_GEN_POLY ((uint32_t )(0b11101101001 ))
10
11
@@ -28,6 +29,11 @@ namespace pocsag {
28
29
' ['
29
30
};
30
31
32
+ Decoder::Decoder () {
33
+ // Zero out batch
34
+ memset (batch, 0 , sizeof (batch));
35
+ }
36
+
31
37
void Decoder::process (uint8_t * symbols, int count) {
32
38
for (int i = 0 ; i < count; i++) {
33
39
// Get symbol
@@ -78,8 +84,37 @@ namespace pocsag {
78
84
79
85
void Decoder::flushMessage () {
80
86
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);
82
103
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;
83
118
}
84
119
}
85
120
@@ -102,14 +137,14 @@ namespace pocsag {
102
137
if (type == CODEWORD_TYPE_IDLE) {
103
138
// If a non-empty message is available, send it out and clear
104
139
flushMessage ();
105
- flog::debug (" [{}:{}]: IDLE" , (i >> 1 ), i&1 );
106
140
}
107
141
else if (type == CODEWORD_TYPE_ADDRESS) {
108
142
// If a non-empty message is available, send it out and clear
109
143
flushMessage ();
110
144
111
145
// Decode message type
112
- msgType = (MessageType)((cw >> 11 ) & 0b11 );
146
+ msgType = MESSAGE_TYPE_ALPHANUMERIC;
147
+ // msgType = (MessageType)((cw >> 11) & 0b11);
113
148
114
149
// Decode address and append lower 8 bits from position
115
150
addr = ((cw >> 13 ) & 0b111111111111111111 ) << 3 ;
@@ -122,14 +157,38 @@ namespace pocsag {
122
157
// Decode data depending on message type
123
158
if (msgType == MESSAGE_TYPE_NUMERIC) {
124
159
// 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];
130
165
}
131
166
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);
133
192
}
134
193
135
194
// Save last data
0 commit comments