diff --git a/CMakeLists.txt b/CMakeLists.txt index 3acf973b..94a782bc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -43,7 +43,7 @@ option(OPT_BUILD_FALCON9_DECODER "Build the falcon9 live decoder (Dependencies: option(OPT_BUILD_KG_SSTV_DECODER "Build the KG SSTV (KG-STV) decoder module (no dependencies required)" OFF) option(OPT_BUILD_M17_DECODER "Build the M17 decoder module (Dependencies: codec2)" OFF) option(OPT_BUILD_METEOR_DEMODULATOR "Build the meteor demodulator module (no dependencies required)" ON) -option(OPT_BUILD_PAGER_DECODER "Build the pager decoder module (no dependencies required)" OFF) +option(OPT_BUILD_PAGER_DECODER "Build the pager decoder module (no dependencies required)" ON) option(OPT_BUILD_RADIO "Main audio modulation decoder (AM, FM, SSB, etc...)" ON) option(OPT_BUILD_WEATHER_SAT_DECODER "Build the HRPT decoder module (no dependencies required)" OFF) diff --git a/decoder_modules/pager_decoder/src/pocsag/pocsag.cpp b/decoder_modules/pager_decoder/src/pocsag/pocsag.cpp index cea144da..41dda240 100644 --- a/decoder_modules/pager_decoder/src/pocsag/pocsag.cpp +++ b/decoder_modules/pager_decoder/src/pocsag/pocsag.cpp @@ -84,27 +84,13 @@ namespace pocsag { void Decoder::flushMessage() { if (!msg.empty()) { - - // Unpack bits - std::string outStr = ""; - for (int i = 0; (i+7) <= msg.size(); i += 7) { - uint8_t b0 = msg[i]; - uint8_t b1 = msg[i+1]; - uint8_t b2 = msg[i+2]; - uint8_t b3 = msg[i+3]; - uint8_t b4 = msg[i+4]; - uint8_t b5 = msg[i+5]; - uint8_t b6 = msg[i+6]; - outStr += (char)((b6<<6) | (b5<<5) | (b4<<4) | (b3<<3) | (b2<<2) | (b1<<1) | b0); - } - onMessage(addr, msgType, outStr); - - // // Send out message - // onMessage(addr, msgType, msg); + // Send out message + onMessage(addr, msgType, msg); // Reset state msg.clear(); - leftInLast = 0; + currChar = 0; + currOffset = 0; } } @@ -160,42 +146,27 @@ namespace pocsag { // Decode data depending on message type if (msgType == MESSAGE_TYPE_NUMERIC) { // Numeric messages pack 5 characters per message codeword - //msg += NUMERIC_CHARSET[(data >> 16) & 0b1111]; - //msg += NUMERIC_CHARSET[(data >> 12) & 0b1111]; - //msg += NUMERIC_CHARSET[(data >> 8) & 0b1111]; - //msg += NUMERIC_CHARSET[(data >> 4) & 0b1111]; - //msg += NUMERIC_CHARSET[data & 0b1111]; + msg += NUMERIC_CHARSET[(data >> 16) & 0b1111]; + msg += NUMERIC_CHARSET[(data >> 12) & 0b1111]; + msg += NUMERIC_CHARSET[(data >> 8) & 0b1111]; + msg += NUMERIC_CHARSET[(data >> 4) & 0b1111]; + msg += NUMERIC_CHARSET[data & 0b1111]; } else if (msgType == MESSAGE_TYPE_ALPHANUMERIC) { - // // Alpha messages pack 7bit characters in the entire codeword stream - // int lasti; - // for (int i = -leftInLast; i <= POCSAG_DATA_BITS_PER_CW-7; i += 7) { - // // Read 7 bits - // char c = 0; - // if (i < 0) { - // c = (lastMsgData & ((1 << (-i)) - 1)) << (7+i); - // } - // c |= (data >> (13 - i)) & 0b1111111; - - // // Save character - // bitswapChar(c, c); - // msg += c; - - // // Update last successful unpack - // lasti = i; - // } - - // // Save how much is still left to read - // leftInLast = 20 - (lasti + 7); - - // Pack the bits backwards + // Unpack ascii bits 7 at a time (TODO: could be more efficient) for (int i = 19; i >= 0; i--) { - msg += (char)((data >> i) & 1); + // Append bit to char + currChar |= ((data >> i) & 1) << (currOffset++); + + // When the char is full, append to message + if (currOffset >= 7) { + // TODO: maybe replace with std::isprint + if (currChar) { msg += currChar; } + currChar = 0; + currOffset = 0; + } } } - - // Save last data - lastMsgData = data; } } } diff --git a/decoder_modules/pager_decoder/src/pocsag/pocsag.h b/decoder_modules/pager_decoder/src/pocsag/pocsag.h index 6452f59c..d464f672 100644 --- a/decoder_modules/pager_decoder/src/pocsag/pocsag.h +++ b/decoder_modules/pager_decoder/src/pocsag/pocsag.h @@ -45,7 +45,7 @@ namespace pocsag { MessageType msgType; std::string msg; - uint32_t lastMsgData; - bool leftInLast = 0; + char currChar = 0; + int currOffset = 0; }; } \ No newline at end of file