@@ -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 }
0 commit comments