Browse Source

Pager: Add FLEX support.

chirpmodem-v8.0.0
Jon Beniston 2 months ago
parent
commit
9e003d8bc7
  1. BIN
      doc/img/PagerDemod_plugin.png
  2. 4
      plugins/channelrx/demodpager/CMakeLists.txt
  3. 32
      plugins/channelrx/demodpager/pagerdemod.cpp
  4. 31
      plugins/channelrx/demodpager/pagerdemod.h
  5. 165
      plugins/channelrx/demodpager/pagerdemodbch.cpp
  6. 43
      plugins/channelrx/demodpager/pagerdemodbch.h
  7. 1220
      plugins/channelrx/demodpager/pagerdemodflex.cpp
  8. 307
      plugins/channelrx/demodpager/pagerdemodflex.h
  9. 74
      plugins/channelrx/demodpager/pagerdemodgui.cpp
  10. 6
      plugins/channelrx/demodpager/pagerdemodgui.h
  11. 73
      plugins/channelrx/demodpager/pagerdemodgui.ui
  12. 9
      plugins/channelrx/demodpager/pagerdemodsettings.cpp
  13. 22
      plugins/channelrx/demodpager/pagerdemodsettings.h
  14. 335
      plugins/channelrx/demodpager/pagerdemodsink.cpp
  15. 11
      plugins/channelrx/demodpager/pagerdemodsink.h
  16. 47
      plugins/channelrx/demodpager/readme.md
  17. 9
      sdrbase/resources/webapi/doc/swagger/include/PagerDemod.yaml
  18. 9
      swagger/sdrangel/api/swagger/include/PagerDemod.yaml
  19. 22
      swagger/sdrangel/code/qt5/client/SWGPagerDemodSettings.cpp
  20. 6
      swagger/sdrangel/code/qt5/client/SWGPagerDemodSettings.h

BIN
doc/img/PagerDemod_plugin.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 15 KiB

After

Width:  |  Height:  |  Size: 29 KiB

4
plugins/channelrx/demodpager/CMakeLists.txt

@ -5,6 +5,8 @@ set(demodpager_SOURCES @@ -5,6 +5,8 @@ set(demodpager_SOURCES
pagerdemodsettings.cpp
pagerdemodbaseband.cpp
pagerdemodsink.cpp
pagerdemodbch.cpp
pagerdemodflex.cpp
pagerdemodplugin.cpp
pagerdemodwebapiadapter.cpp
)
@ -14,6 +16,8 @@ set(demodpager_HEADERS @@ -14,6 +16,8 @@ set(demodpager_HEADERS
pagerdemodsettings.h
pagerdemodbaseband.h
pagerdemodsink.h
pagerdemodbch.h
pagerdemodflex.h
pagerdemodplugin.h
pagerdemodwebapiadapter.h
)

32
plugins/channelrx/demodpager/pagerdemod.cpp

@ -176,6 +176,12 @@ bool PagerDemod::handleMessage(const Message& cmd) @@ -176,6 +176,12 @@ bool PagerDemod::handleMessage(const Message& cmd)
getMessageQueueToGUI()->push(msg);
}
bool flex = report.getProtocol() == PagerDemodSettings::FLEX;
QString address = PagerDemodSettings::formatAddress(report.getAddress(), report.getProtocol());
// Function bits only exist in POCSAG
QString functionBits = flex ? QString() : QString::number(report.getFunctionBits());
QString protocol = PagerDemodSettings::protocolName(report.getProtocol());
// Forward via UDP
if (m_settings.m_udpEnabled)
{
@ -184,14 +190,18 @@ bool PagerDemod::handleMessage(const Message& cmd) @@ -184,14 +190,18 @@ bool PagerDemod::handleMessage(const Message& cmd)
message.append('\0');
message.append(report.getDateTime().time().toString().toLatin1());
message.append('\0');
message.append(QString("%1").arg(report.getAddress(), 7, 10, QChar('0')).toLatin1());
message.append(address.toLatin1());
message.append('\0');
message.append(QString::number(report.getFunctionBits()).toLatin1());
message.append(functionBits.toLatin1());
message.append('\0');
message.append(report.getAlphaMessage().toLatin1());
message.append('\0');
message.append(report.getNumericMessage().toLatin1());
message.append('\0');
message.append(protocol.toLatin1());
message.append('\0');
message.append(report.getType().toLatin1());
message.append('\0');
m_udpSocket.writeDatagram(message.data(), message.size(),
QHostAddress(m_settings.m_udpAddress), m_settings.m_udpPort);
}
@ -201,13 +211,16 @@ bool PagerDemod::handleMessage(const Message& cmd) @@ -201,13 +211,16 @@ bool PagerDemod::handleMessage(const Message& cmd)
{
m_logStream << report.getDateTime().date().toString() << ","
<< report.getDateTime().time().toString() << ","
<< QString("%1").arg(report.getAddress(), 7, 10, QChar('0')) << ","
<< QString::number(report.getFunctionBits()) << ","
<< address << ","
<< functionBits << ","
<< CSV::escape(report.getAlphaMessage()) << ","
<< report.getNumericMessage() << ","
<< QString::number(report.getEvenParityErrors()) << ","
<< QString::number(report.getBCHParityErrors()) << ","
<< QString::number(report.getBaud()) << "\n";
<< QString::number(report.getBaud()) << ","
<< protocol << ","
<< CSV::escape(report.getType()) << ","
<< report.getFrame() << "\n";
m_logStream.flush();
}
@ -294,7 +307,7 @@ void PagerDemod::applySettings(const QStringList& settingsKeys, const PagerDemod @@ -294,7 +307,7 @@ void PagerDemod::applySettings(const QStringList& settingsKeys, const PagerDemod
if (newFile)
{
// Write header
m_logStream << "Date,Time,Address,Function Bits,Alpha,Numeric,Even Parity Errors,BCH Parity Errors,Baud\n";
m_logStream << "Date,Time,Address,Function Bits,Alpha,Numeric,Even Parity Errors,BCH Parity Errors,Baud,Protocol,Type,Frame\n";
}
}
else
@ -413,6 +426,9 @@ void PagerDemod::webapiUpdateChannelSettings( @@ -413,6 +426,9 @@ void PagerDemod::webapiUpdateChannelSettings(
const QStringList& channelSettingsKeys,
SWGSDRangel::SWGChannelSettings& response)
{
if (channelSettingsKeys.contains("modulation")) {
settings.m_modulation = (PagerDemodSettings::Modulation) response.getPagerDemodSettings()->getModulation();
}
if (channelSettingsKeys.contains("decode")) {
settings.m_decode = (PagerDemodSettings::Decode) response.getPagerDemodSettings()->getDecode();
}
@ -480,6 +496,7 @@ void PagerDemod::webapiUpdateChannelSettings( @@ -480,6 +496,7 @@ void PagerDemod::webapiUpdateChannelSettings(
void PagerDemod::webapiFormatChannelSettings(SWGSDRangel::SWGChannelSettings& response, const PagerDemodSettings& settings)
{
response.getPagerDemodSettings()->setModulation((int) settings.m_modulation);
response.getPagerDemodSettings()->setDecode((int) settings.m_decode);
response.getPagerDemodSettings()->setReverse(settings.m_reverse ? 1 : 0);
response.getPagerDemodSettings()->setInputFrequencyOffset(settings.m_inputFrequencyOffset);
@ -617,6 +634,9 @@ void PagerDemod::webapiFormatChannelSettings( @@ -617,6 +634,9 @@ void PagerDemod::webapiFormatChannelSettings(
// transfer data that has been modified. When force is on transfer all data except reverse API data
if (channelSettingsKeys.contains("modulation") || force) {
swgPagerDemodSettings->setModulation((int) settings.m_modulation);
}
if (channelSettingsKeys.contains("decode") || force) {
swgPagerDemodSettings->setDecode((int) settings.m_decode);
}

31
plugins/channelrx/demodpager/pagerdemod.h

@ -76,23 +76,29 @@ public: @@ -76,23 +76,29 @@ public:
MESSAGE_CLASS_DECLARATION
public:
int getAddress() const { return m_address; }
qint64 getAddress() const { return m_address; }
int getFunctionBits() const { return m_functionBits; }
QString getAlphaMessage() const { return m_alphaMessage; }
QString getNumericMessage() const { return m_numericMessage; }
int getEvenParityErrors() const { return m_evenParityErrors; }
int getBCHParityErrors() const { return m_bchParityErrors; }
int getBaud() const { return m_baud; }
PagerDemodSettings::Modulation getProtocol() const { return m_protocol; }
QString getType() const { return m_type; }
QString getFrame() const { return m_frame; }
QDateTime getDateTime() const { return m_dateTime; }
static MsgPagerMessage* create(
int address,
qint64 address,
int functionBits,
const QString& alphaMessage,
const QString& numericMessage,
int evenParityErrors,
int bchParityErrors,
int baud
int baud,
PagerDemodSettings::Modulation protocol = PagerDemodSettings::POCSAG,
const QString& type = QString(),
const QString& frame = QString()
)
{
return new MsgPagerMessage(
@ -103,21 +109,29 @@ public: @@ -103,21 +109,29 @@ public:
evenParityErrors,
bchParityErrors,
baud,
protocol,
type,
frame,
QDateTime::currentDateTime()
);
}
private:
int m_address;
int m_functionBits;
qint64 m_address; //!< POCSAG address or FLEX capcode
int m_functionBits; //!< POCSAG only
QString m_alphaMessage;
QString m_numericMessage;
int m_evenParityErrors;
int m_bchParityErrors;
int m_baud;
int m_baud; //!< POCSAG baud rate or FLEX bit rate
PagerDemodSettings::Modulation m_protocol;
QString m_type; //!< FLEX message type. Empty for POCSAG, where it's ambiguous
QString m_frame; //!< FLEX cycle/frame and phase
QDateTime m_dateTime;
MsgPagerMessage(int address, int functionBits, const QString& alphaMessage, const QString& numericMessage, int evenParityErrors, int bchParityErrors, int baud, QDateTime dateTime) :
MsgPagerMessage(qint64 address, int functionBits, const QString& alphaMessage, const QString& numericMessage,
int evenParityErrors, int bchParityErrors, int baud, PagerDemodSettings::Modulation protocol,
const QString& type, const QString& frame, QDateTime dateTime) :
Message(),
m_address(address),
m_functionBits(functionBits),
@ -126,6 +140,9 @@ public: @@ -126,6 +140,9 @@ public:
m_evenParityErrors(evenParityErrors),
m_bchParityErrors(bchParityErrors),
m_baud(baud),
m_protocol(protocol),
m_type(type),
m_frame(frame),
m_dateTime(dateTime)
{
}

165
plugins/channelrx/demodpager/pagerdemodbch.cpp

@ -0,0 +1,165 @@ @@ -0,0 +1,165 @@
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2021-2026 Jon Beniston, M7RCE <jon@beniston.com> //
// Some code by AI //
// //
// This program is free software; you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation as version 3 of the License, or //
// (at your option) any later version. //
// //
// This program is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU General Public License V3 for more details. //
// //
// You should have received a copy of the GNU General Public License //
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
///////////////////////////////////////////////////////////////////////////////////
#include "pagerdemodbch.h"
// XOR bits together for parity check
int PagerDemodBCH::xorBits(quint32 word, int firstBit, int lastBit)
{
int x = 0;
for (int i = firstBit; i <= lastBit; i++)
{
x ^= (word >> i) & 1;
}
return x;
}
// Check for even parity
bool PagerDemodBCH::evenParity(quint32 word, int firstBit, int lastBit, int parityBit)
{
return xorBits(word, firstBit, lastBit) == parityBit;
}
// Reverse order of bits
quint32 PagerDemodBCH::reverse(quint32 x)
{
x = (((x & 0xaaaaaaaa) >> 1) | ((x & 0x55555555) << 1));
x = (((x & 0xcccccccc) >> 2) | ((x & 0x33333333) << 2));
x = (((x & 0xf0f0f0f0) >> 4) | ((x & 0x0f0f0f0f) << 4));
x = (((x & 0xff00ff00) >> 8) | ((x & 0x00ff00ff) << 8));
return((x >> 16) | (x << 16));
}
// Calculate BCH parity bits
quint32 PagerDemodBCH::encode(const quint32 cw)
{
quint32 bit = 0;
quint32 localCW = cw & 0xFFFFF800; // Mask off BCH parity and even parity bits
quint32 cwE = localCW;
// Calculate BCH bits
for (bit = 1; bit <= 21; bit++)
{
if (cwE & 0x80000000) {
cwE ^= 0xED200000;
}
cwE <<= 1;
}
localCW |= (cwE >> 21);
return localCW;
}
// Use BCH decoding to try to fix any bit errors
// Returns true if able to be decode/repair successful
// See: https://www.eevblog.com/forum/microcontrollers/practical-guides-to-bch-fec/
bool PagerDemodBCH::decode(const quint32 cw, quint32& correctedCW)
{
// Calculate syndrome
// We do this by recalculating the BCH parity bits and XORing them against the received ones
quint32 syndrome = ((encode(cw) ^ cw) >> 1) & 0x3FF;
if (syndrome == 0)
{
// Syndrome of zero indicates no repair required
correctedCW = cw;
return true;
}
// Meggitt decoder
quint32 result = 0;
quint32 damagedCW = cw;
// Calculate BCH bits
for (quint32 xbit = 0; xbit < 31; xbit++)
{
// Produce the next corrected bit in the high bit of the result
result <<= 1;
if ((syndrome == 0x3B4) || // 0x3B4: Syndrome when a single error is detected in the MSB
(syndrome == 0x26E) || // 0x26E: Two adjacent errors
(syndrome == 0x359) || // 0x359: Two errors, one OK bit between
(syndrome == 0x076) || // 0x076: Two errors, two OK bits between
(syndrome == 0x255) || // 0x255: Two errors, three OK bits between
(syndrome == 0x0F0) || // 0x0F0: Two errors, four OK bits between
(syndrome == 0x216) ||
(syndrome == 0x365) ||
(syndrome == 0x068) ||
(syndrome == 0x25A) ||
(syndrome == 0x343) ||
(syndrome == 0x07B) ||
(syndrome == 0x1E7) ||
(syndrome == 0x129) ||
(syndrome == 0x14E) ||
(syndrome == 0x2C9) ||
(syndrome == 0x0BE) ||
(syndrome == 0x231) ||
(syndrome == 0x0C2) ||
(syndrome == 0x20F) ||
(syndrome == 0x0DD) ||
(syndrome == 0x1B4) ||
(syndrome == 0x2B4) ||
(syndrome == 0x334) ||
(syndrome == 0x3F4) ||
(syndrome == 0x394) ||
(syndrome == 0x3A4) ||
(syndrome == 0x3BC) ||
(syndrome == 0x3B0) ||
(syndrome == 0x3B6) ||
(syndrome == 0x3B5)
)
{
// Syndrome matches an error in the MSB
// Correct that error and adjust the syndrome to account for it
syndrome ^= 0x3B4;
result |= (~damagedCW & 0x80000000) >> 30;
}
else
{
// No error
result |= (damagedCW & 0x80000000) >> 30;
}
damagedCW <<= 1;
// Handle syndrome shift register feedback
if (syndrome & 0x200)
{
syndrome <<= 1;
syndrome ^= 0x769; // 0x769 = POCSAG generator polynomial -- x^10 + x^9 + x^8 + x^6 + x^5 + x^3 + 1
}
else
{
syndrome <<= 1;
}
// Mask off bits which fall off the end of the syndrome shift register
syndrome &= 0x3FF;
}
// Check if error correction was successful
if (syndrome != 0)
{
// Syndrome nonzero at end indicates uncorrectable errors
correctedCW = cw;
return false;
}
// The BCH decoder operates on bits 31 through 1. Preserve the separate
// overall parity bit in bit 0 so it can be checked after correction.
correctedCW = result | (cw & 0x1);
return true;
}

43
plugins/channelrx/demodpager/pagerdemodbch.h

@ -0,0 +1,43 @@ @@ -0,0 +1,43 @@
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2021-2026 Jon Beniston, M7RCE <jon@beniston.com> //
// Some code by AI //
// //
// This program is free software; you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation as version 3 of the License, or //
// (at your option) any later version. //
// //
// This program is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU General Public License V3 for more details. //
// //
// You should have received a copy of the GNU General Public License //
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
///////////////////////////////////////////////////////////////////////////////////
#ifndef INCLUDE_PAGERDEMODBCH_H
#define INCLUDE_PAGERDEMODBCH_H
#include <QtGlobal>
// BCH(31,21) code plus an even parity bit, as used by both POCSAG and FLEX.
//
// Codewords are in POCSAG bit order: bit 31 is transmitted first, bits 31-11 are data,
// bits 10-1 are the BCH check bits and bit 0 is even parity over the whole word.
// FLEX transmits codewords LSB first, so FLEX words are bit reversed with reverse()
// before and after decoding.
class PagerDemodBCH
{
public:
//!< Returns cw with the BCH check bits (10-1) calculated. Parity bit 0 is cleared
static quint32 encode(quint32 cw);
//!< Corrects up to two bit errors in bits 31-1. Bit 0 is passed through unchanged.
//!< Returns false if the errors are uncorrectable, in which case correctedCW = cw
static bool decode(quint32 cw, quint32& correctedCW);
static quint32 reverse(quint32 x);
static int xorBits(quint32 word, int firstBit, int lastBit);
static bool evenParity(quint32 word, int firstBit, int lastBit, int parityBit);
};
#endif // INCLUDE_PAGERDEMODBCH_H

1220
plugins/channelrx/demodpager/pagerdemodflex.cpp

File diff suppressed because it is too large Load Diff

307
plugins/channelrx/demodpager/pagerdemodflex.h

@ -0,0 +1,307 @@ @@ -0,0 +1,307 @@
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2026 Jon Beniston, M7RCE <jon@beniston.com> //
// Some code by AI //
// //
// This program is free software; you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation as version 3 of the License, or //
// (at your option) any later version. //
// //
// This program is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU General Public License V3 for more details. //
// //
// You should have received a copy of the GNU General Public License //
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
///////////////////////////////////////////////////////////////////////////////////
#ifndef INCLUDE_PAGERDEMODFLEX_H
#define INCLUDE_PAGERDEMODFLEX_H
#include <QHash>
#include <QList>
#include <QString>
#include <vector>
// FLEX paging protocol receiver.
//
// A FLEX frame is 1.875s long: sync 1 and the frame information word (FIW) at 1600 bit/s
// 2-level FSK, then sync 2 and 11 blocks of data at the frame's own symbol rate (1600 or
// 3200 baud) and number of levels (2 or 4). This gives four modes: 1600/2, 1600/4, 3200/2
// and 3200/4, carrying 1, 2, 2 and 4 interleaved phases (A to D) of 88 codewords each.
//
// Codewords are BCH(31,21) plus even parity, the same code as POCSAG, but transmitted LSB
// first. Field definitions follow ARIB RCR STD-43A; message layout and the handling of
// corner cases follow multimon-ng's demod_flex.c, so decodes are comparable with it.
// A message decoded from a FLEX frame
struct PagerDemodFlexMessage
{
// Vector types, as transmitted
enum Type {
Secure = 0,
ShortInstruction = 1,
Tone = 2,
StandardNumeric = 3,
SpecialNumeric = 4,
Alphanumeric = 5,
Binary = 6,
NumberedNumeric = 7
};
qint64 m_capcode = 0;
bool m_longAddress = false;
Type m_type = Alphanumeric;
QString m_text; //!< 7-bit characters (alphanumeric, secure), digits (numeric, tone) or hex (binary)
int m_bchErrors = 0; //!< Uncorrectable codewords in the message
int m_parityErrors = 0; //!< Corrected codewords failing even parity
int m_bitRate = 0; //!< Data bit rate of the frame: 1600, 3200 or 6400
int m_cycle = 0; //!< Cycle number (0-14) of the first fragment
int m_frame = 0; //!< Frame number (0-127) of the first fragment
char m_phase = 'A';
bool m_incomplete = false; //!< One or more fragments of a multi-frame message were lost
int m_group = -1; //!< Temporary address (0-15) of a group call, or -1
bool isNumeric() const; //!< Whether m_text holds digits rather than characters
static QString typeName(Type type);
};
// Decodes the codewords of a received frame into messages, including reassembly of
// alphanumeric messages that are fragmented over several frames.
//
// Group calls: a short instruction vector assigns a pager's capcode to one of 16 temporary
// addresses, for a given frame. A message sent to that temporary address in that frame is
// for every pager assigned to it, so it is output once for each of their capcodes. If no
// assignments were received, it is output with the temporary address as the capcode.
class PagerDemodFlexDecoder
{
public:
static const int m_wordsPerPhase = 88;
static const int m_wordsPerBlock = 8;
static const int m_framesPerCycle = 128;
static const int m_cycles = 15;
//!< A fragmented message whose next fragment hasn't arrived after this many frames
//!< (one minute) is output marked incomplete
static const int m_fragmentTimeoutFrames = 32;
//!< Capcodes of the temporary addresses used for group calls
static const qint64 m_groupCapcodeFirst = 2029568;
static const int m_groups = 16;
static const int m_maxGroupMembers = 1000;
struct Phase {
char m_name = 'A';
quint32 m_words[m_wordsPerPhase] = {}; //!< Received codewords, first received bit in bit 0
bool m_erased[m_wordsPerPhase] = {}; //!< Codeword received while the carrier was lost
};
struct Frame {
int m_cycle = 0;
int m_frame = 0;
int m_bitRate = 1600;
std::vector<Phase> m_phases;
};
//!< Decode a frame. Returns completed messages, including fragmented messages that timed out
QList<PagerDemodFlexMessage> decodeFrame(const Frame& frame);
//!< Output any partly received fragmented messages, marked incomplete
QList<PagerDemodFlexMessage> flush();
bool hasFragments() const { return !m_fragments.isEmpty(); }
void reset();
// Codeword statistics for the last decoded frame
int getCodewords() const { return m_codewords; }
int getUncorrectable() const { return m_uncorrectable; }
//!< The 4-bit checksum used by the FIW, BIW and vector words: nibble sum of the 21 data bits is 0xF
static bool checksumValid(quint32 data);
//!< Set the checksum bits (3-0) of a 21-bit data word, so checksumValid() is true
static quint32 setChecksum(quint32 data);
//!< Correct a received codeword (first received bit in bit 0). Returns false if uncorrectable
static bool correct(quint32 word, quint32& data, bool& parityError);
//!< Encode 21 data bits as a codeword, first transmitted bit in bit 0
static quint32 encode(quint32 data);
static bool isLongAddress(quint32 addressWord);
static const char m_numericChars[17];
private:
struct Fragment {
PagerDemodFlexMessage m_message;
int m_messageNumber; //!< From the header, to tell parts of different messages apart
int m_nextFragment; //!< Expected fragment number of the next part
int m_frameIndex; //!< Absolute frame index (cycle * 128 + frame) of the last part
};
struct Group {
QList<qint64> m_capcodes; //!< Capcodes assigned to the temporary address
int m_frameIndex = -1; //!< Absolute frame index of the group call, -1 if none
};
QHash<qint64, Fragment> m_fragments; //!< Fragmented messages being reassembled, by capcode
Group m_groupCalls[m_groups];
int m_codewords = 0;
int m_uncorrectable = 0;
void decodePhase(const Frame& frame, const Phase& phase, QList<PagerDemodFlexMessage>& messages);
void addFragment(PagerDemodFlexMessage& message, int fragment, bool continued, int messageNumber, int frameIndex, QList<PagerDemodFlexMessage>& messages);
void assignGroup(const Frame& frame, qint64 capcode, quint32 viw);
void expireGroups(int frameIndex);
QList<PagerDemodFlexMessage> expandGroups(const QList<PagerDemodFlexMessage>& messages);
};
// Recovers FLEX frames from FM discriminator output and passes them to the decoder.
//
// Sync 1 is found by a 64-bit correlator on each sample phase of the 1600 bit/s stream. Of
// the phases that match, the one with the largest matched filter output over the sync code
// gives the symbol timing, and the DC offset and
// deviation are measured from sync 1 and the FIW. Data symbols are then tracked by a timing
// loop that uses transitions of at least two levels, and the slicer levels are tracked by
// decision direction, so a frame survives receiver clock and carrier frequency errors.
//
// Frames are sent every 1.875s, so once a frame has been received, the flywheel predicts
// when the next sync 1 should end. Around that time, a much weaker match to the expected
// sync code is accepted, for frames where sync 1 is damaged (e.g. by a transmitter keying
// up). To keep this from creating frames from noise, such a frame is only received if its
// FIW has the expected cycle and frame number.
class PagerDemodFlex
{
public:
// Information about a received frame, for diagnostics and tests
struct FrameInfo {
qint64 m_syncSample = 0; //!< Sample index of the end of the sync 1 code
quint16 m_code = 0; //!< Sync 1 mode code
bool m_inverted = false; //!< Whether the sync was received with inverted polarity
int m_baud = 0;
int m_levels = 0;
int m_cycle = 0;
int m_frame = 0;
int m_codewords = 0; //!< Codewords in the frame (88 per phase)
int m_uncorrectable = 0; //!< Codewords with uncorrectable errors (not counting erasures)
int m_erasedBlocks = 0; //!< Blocks where the carrier was lost
float m_deviation = 0.0f; //!< Measured outer level deviation, in discriminator units
float m_offset = 0.0f; //!< Measured DC offset, in discriminator units
bool m_flywheel = false; //!< Sync 1 was found by the flywheel
};
explicit PagerDemodFlex(int sampleRate = 38400);
void reset();
//!< Process one sample of FM discriminator output, with its magnitude squared
void process(float fm, float magsq);
//!< True from finding sync 1 to the end of the frame
bool isReceiving() const { return m_state != Hunting; }
bool hasMessages() const { return !m_messages.isEmpty(); }
PagerDemodFlexMessage takeMessage() { return m_messages.takeFirst(); }
int getFrameCount() const { return m_frameCount; } //!< Frames whose FIW decoded
const FrameInfo& getLastFrame() const { return m_lastFrame; }
//!< Blocks whose mean power is this far below sync 1 are treated as lost
static constexpr float m_carrierLossDB = 15.0f;
//!< Frame periods after the last frame received that the flywheel predicts sync for
static const int m_flywheelFrames = 4;
//!< Bit errors allowed in the 64-bit sync code, when found by the flywheel
static const int m_flywheelSyncErrors = 16;
private:
enum State {
Hunting, //!< Searching for sync 1
FIW, //!< Receiving the rest of sync 1 and the FIW at 1600 bit/s
Data //!< Receiving sync 2 and the data blocks
};
static const int m_syncBits = 64;
static const int m_syncTailBits = 16; //!< Bits after the 64-bit sync code, before the FIW
static const int m_fiwBits = 32;
static const int m_blocks = 11;
int m_sampleRate;
int m_sps1600; //!< Samples per symbol at 1600 baud
State m_state;
qint64 m_sampleCount;
// History of FM samples and running sums, for the matched filters and the DC estimate
std::vector<float> m_fm;
std::vector<float> m_magsq;
std::vector<float> m_mfHist; //!< 1600 baud matched filter output
int m_histMask;
double m_sum1600; //!< Over one symbol at 1600 baud
double m_sum3200; //!< Over one symbol at 3200 baud
double m_sumSync; //!< Over the 64-bit sync code
double m_sumMagsqSync;
float m_mf1600; //!< Matched filter outputs (mean over a symbol)
float m_mf3200;
// Sync 1 search
std::vector<quint64> m_syncReg; //!< One shift register per sample phase
bool m_candidate;
bool m_candidateFlywheel; //!< Candidate is the flywheel's search window, rather than a sync match
qint64 m_candidateFirst;
qint64 m_candidateEnd;
// Per sample of the candidate
std::vector<float> m_candidateMetric; //!< Matched filter output over the sync code. 0 if no match
std::vector<quint16> m_candidateCode; //!< Mode code, corrected
std::vector<bool> m_candidateInverted;
std::vector<float> m_candidateDC;
std::vector<float> m_candidatePower;
// Flywheel
bool m_flywheel; //!< Next sync is predicted
double m_flywheelSyncEnd; //!< Predicted end of the next sync code
int m_flywheelPeriods; //!< Frame periods since the last frame
quint16 m_flywheelCode;
bool m_flywheelInverted;
int m_flywheelCycle; //!< Expected cycle and frame of the predicted frame
int m_flywheelFrame;
// Current frame
FrameInfo m_info;
double m_syncEnd; //!< Sample at which the last bit of the sync code ends
float m_polarity; //!< +1 or -1, so the highest level is positive
float m_dc;
float m_deviation;
float m_syncPower;
int m_bitIndex; //!< Bit counter for sync tail and FIW
double m_nextBitSample;
double m_deviationSum;
quint32 m_fiw;
// Data symbol recovery
int m_sps; //!< Samples per symbol
double m_timing; //!< Samples until the next symbol instant
bool m_gotMid;
float m_mid; //!< Matched filter output midway between symbols
float m_prevSymbol;
bool m_havePrevSymbol;
float m_prevMf;
int m_symbolIndex;
int m_sync2Symbols;
int m_dataSymbols;
double m_blockPower[m_blocks];
int m_blockSamples[m_blocks];
PagerDemodFlexDecoder::Frame m_frame;
PagerDemodFlexDecoder m_decoder;
QList<PagerDemodFlexMessage> m_messages;
qint64 m_lastFrameSample; //!< When the last frame ended, to time out fragments if transmission stops
int m_frameCount;
FrameInfo m_lastFrame;
static constexpr float m_timingGain = 0.05f; //!< Fraction of the timing error corrected per transition
static constexpr float m_levelGain = 0.01f; //!< Slicer level tracking per symbol
void hunt(qint64 n, quint64 reg, float dc);
void flywheelSample(qint64 n, quint64 reg, float dc);
void openCandidate(qint64 first, qint64 end, bool flywheel);
void startFrame();
void fiwBit(float mf);
void dataSample(float mf, float magsq);
void symbol(float value);
void endFrame();
static bool syncMatch(quint64 reg, quint16& code);
//!< Find the mode closest to a received code. Returns false if none is within 3 bits
static bool mode(quint16& code, int& baud, int& levels);
static int popcount64(quint64 x);
};
#endif // INCLUDE_PAGERDEMODFLEX_H

74
plugins/channelrx/demodpager/pagerdemodgui.cpp

@ -58,14 +58,17 @@ void PagerDemodGUI::resizeTable() @@ -58,14 +58,17 @@ void PagerDemodGUI::resizeTable()
ui->messages->setRowCount(row + 1);
ui->messages->setItem(row, PagerDemodSettings::MESSAGE_COL_DATE, new QTableWidgetItem("Fri Apr 15 2016--"));
ui->messages->setItem(row, PagerDemodSettings::MESSAGE_COL_TIME, new QTableWidgetItem("10:17:00"));
ui->messages->setItem(row, PagerDemodSettings::MESSAGE_COL_ADDRESS, new QTableWidgetItem("1000000"));
ui->messages->setItem(row, PagerDemodSettings::MESSAGE_COL_ADDRESS, new QTableWidgetItem("100000000"));
ui->messages->setItem(row, PagerDemodSettings::MESSAGE_COL_MESSAGE, new QTableWidgetItem("ABCEDGHIJKLMNOPQRSTUVWXYZABCEDGHIJKLMNOPQRSTUVWXYZ"));
ui->messages->setItem(row, PagerDemodSettings::MESSAGE_COL_FUNCTION, new QTableWidgetItem("0"));
ui->messages->setItem(row, PagerDemodSettings::MESSAGE_COL_ALPHA, new QTableWidgetItem("ABCEDGHIJKLMNOPQRSTUVWXYZABCEDGHIJKLMNOPQRSTUVWXYZ"));
ui->messages->setItem(row, PagerDemodSettings::MESSAGE_COL_NUMERIC, new QTableWidgetItem("123456789123456789123456789123456789123456789123456789"));
ui->messages->setItem(row, PagerDemodSettings::MESSAGE_COL_EVEN_PE, new QTableWidgetItem("0"));
ui->messages->setItem(row, PagerDemodSettings::MESSAGE_COL_BCH_PE, new QTableWidgetItem("0"));
ui->messages->setItem(row, PagerDemodSettings::MESSAGE_COL_BAUD, new QTableWidgetItem("2400-"));
ui->messages->setItem(row, PagerDemodSettings::MESSAGE_COL_BAUD, new QTableWidgetItem("6400-"));
ui->messages->setItem(row, PagerDemodSettings::MESSAGE_COL_PROTOCOL, new QTableWidgetItem("POCSAG-"));
ui->messages->setItem(row, PagerDemodSettings::MESSAGE_COL_TYPE, new QTableWidgetItem("Alpha (group, partial)"));
ui->messages->setItem(row, PagerDemodSettings::MESSAGE_COL_FRAME, new QTableWidgetItem("14/127 D-"));
ui->messages->resizeColumnsToContents();
ui->messages->removeRow(row);
}
@ -222,12 +225,35 @@ QString PagerDemodGUI::selectMessage(int functionBits, const QString &numericMes @@ -222,12 +225,35 @@ QString PagerDemodGUI::selectMessage(int functionBits, const QString &numericMes
}
// Add row to table
void PagerDemodGUI::messageReceived(const QDateTime dateTime, int address, int functionBits, int baud,
void PagerDemodGUI::messageReceived(const QDateTime dateTime, qint64 address, int functionBits, int baud,
const QString &numericMessage, const QString &alphaMessage,
int evenParityErrors, int bchParityErrors)
int evenParityErrors, int bchParityErrors,
PagerDemodSettings::Modulation protocol, const QString &type, const QString &frame)
{
QString message = selectMessage(functionBits, numericMessage, alphaMessage);
QString addressString = QString("%1").arg(address, 7, 10, QChar('0'));
bool flex = protocol == PagerDemodSettings::FLEX;
QString message;
QString typeString = type;
if (flex)
{
// FLEX states the message type, so only one of alpha and numeric is set
message = alphaMessage.isEmpty() ? numericMessage : alphaMessage;
}
else
{
message = selectMessage(functionBits, numericMessage, alphaMessage);
if (typeString.isEmpty())
{
if (numericMessage.isEmpty() && alphaMessage.isEmpty()) {
typeString = "Tone";
} else {
typeString = (message == numericMessage) ? "Numeric" : "Alpha";
}
}
}
QString addressString = PagerDemodSettings::formatAddress(address, protocol);
// Should we ignore the message if it is a duplicate?
if (m_settings.m_filterDuplicates)
@ -283,6 +309,9 @@ void PagerDemodGUI::messageReceived(const QDateTime dateTime, int address, int f @@ -283,6 +309,9 @@ void PagerDemodGUI::messageReceived(const QDateTime dateTime, int address, int f
QTableWidgetItem *evenPEItem = new QTableWidgetItem();
QTableWidgetItem *bchPEItem = new QTableWidgetItem();
QTableWidgetItem *baudItem = new QTableWidgetItem();
QTableWidgetItem *protocolItem = new QTableWidgetItem();
QTableWidgetItem *typeItem = new QTableWidgetItem();
QTableWidgetItem *frameItem = new QTableWidgetItem();
ui->messages->setItem(row, PagerDemodSettings::MESSAGE_COL_DATE, dateItem);
ui->messages->setItem(row, PagerDemodSettings::MESSAGE_COL_TIME, timeItem);
ui->messages->setItem(row, PagerDemodSettings::MESSAGE_COL_ADDRESS, addressItem);
@ -293,16 +322,22 @@ void PagerDemodGUI::messageReceived(const QDateTime dateTime, int address, int f @@ -293,16 +322,22 @@ void PagerDemodGUI::messageReceived(const QDateTime dateTime, int address, int f
ui->messages->setItem(row, PagerDemodSettings::MESSAGE_COL_EVEN_PE, evenPEItem);
ui->messages->setItem(row, PagerDemodSettings::MESSAGE_COL_BCH_PE, bchPEItem);
ui->messages->setItem(row, PagerDemodSettings::MESSAGE_COL_BAUD, baudItem);
ui->messages->setItem(row, PagerDemodSettings::MESSAGE_COL_PROTOCOL, protocolItem);
ui->messages->setItem(row, PagerDemodSettings::MESSAGE_COL_TYPE, typeItem);
ui->messages->setItem(row, PagerDemodSettings::MESSAGE_COL_FRAME, frameItem);
dateItem->setText(dateTime.date().toString());
timeItem->setText(dateTime.time().toString());
addressItem->setText(addressString);
messageItem->setText(message);
functionItem->setText(QString("%1").arg(functionBits));
functionItem->setText(flex ? QString() : QString("%1").arg(functionBits)); // Function bits are POCSAG only
alphaItem->setText(alphaMessage);
numericItem->setText(numericMessage);
evenPEItem->setText(QString("%1").arg(evenParityErrors));
bchPEItem->setText(QString("%1").arg(bchParityErrors));
baudItem->setData(Qt::DisplayRole, baud);
protocolItem->setText(PagerDemodSettings::protocolName(protocol));
typeItem->setText(typeString);
frameItem->setText(frame);
if (!m_loadingData)
{
filterRow(row);
@ -333,7 +368,8 @@ bool PagerDemodGUI::handleMessage(const Message& message) @@ -333,7 +368,8 @@ bool PagerDemodGUI::handleMessage(const Message& message)
const PagerDemod::MsgPagerMessage& report = (const PagerDemod::MsgPagerMessage&) message;
messageReceived(report.getDateTime(), report.getAddress(), report.getFunctionBits(), report.getBaud(),
report.getNumericMessage(), report.getAlphaMessage(),
report.getEvenParityErrors(), report.getBCHParityErrors());
report.getEvenParityErrors(), report.getBCHParityErrors(),
report.getProtocol(), report.getType(), report.getFrame());
return true;
}
else if (DSPSignalNotification::match(message))
@ -399,6 +435,12 @@ void PagerDemodGUI::on_fmDev_valueChanged(int value) @@ -399,6 +435,12 @@ void PagerDemodGUI::on_fmDev_valueChanged(int value)
applySettings(QStringList("fmDeviation"));
}
void PagerDemodGUI::on_modulation_currentIndexChanged(int index)
{
m_settings.m_modulation = (PagerDemodSettings::Modulation)index;
applySettings(QStringList("modulation"));
}
void PagerDemodGUI::on_decode_currentIndexChanged(int index)
{
m_settings.m_decode = (PagerDemodSettings::Decode)index;
@ -675,6 +717,7 @@ void PagerDemodGUI::displaySettings() @@ -675,6 +717,7 @@ void PagerDemodGUI::displaySettings()
ui->deltaFrequency->setValue(m_channelMarker.getCenterFrequency());
ui->modulation->setCurrentIndex((int)m_settings.m_modulation);
ui->decode->setCurrentIndex((int)m_settings.m_decode);
ui->rfBWText->setText(QString("%1k").arg(m_settings.m_rfBandwidth / 1000.0, 0, 'f', 1));
@ -841,7 +884,11 @@ void PagerDemodGUI::on_logOpen_clicked() @@ -841,7 +884,11 @@ void PagerDemodGUI::on_logOpen_clicked()
int numericCol = colIndexes.value("Numeric");
int evenCol = colIndexes.value("Even Parity Errors");
int bchCol = colIndexes.value("BCH Parity Errors");
// Columns absent from logs written before they were recorded
int baudCol = colIndexes.value("Baud", -1);
int protocolCol = colIndexes.value("Protocol", -1);
int typeCol = colIndexes.value("Type", -1);
int frameCol = colIndexes.value("Frame", -1);
int maxCol = std::max({dateCol, timeCol, addressCol, functionCol, alphaCol, numericCol, evenCol, bchCol});
QMessageBox dialog(this);
@ -866,18 +913,22 @@ void PagerDemodGUI::on_logOpen_clicked() @@ -866,18 +913,22 @@ void PagerDemodGUI::on_logOpen_clicked()
QDate date = QDate::fromString(cols[dateCol]);
QTime time = QTime::fromString(cols[timeCol]);
QDateTime dateTime(date, time);
int address = cols[addressCol].toInt();
qint64 address = cols[addressCol].toLongLong();
int functionBits = cols[functionCol].toInt();
int evenErrors = cols[evenCol].toInt();
int bchErrors = cols[bchCol].toInt();
// Baud is absent from logs written before it was recorded
int baud = ((baudCol >= 0) && (baudCol < cols.size()))
? cols[baudCol].toInt() : 0;
PagerDemodSettings::Modulation protocol = ((protocolCol >= 0) && (protocolCol < cols.size()) && (cols[protocolCol] == "FLEX"))
? PagerDemodSettings::FLEX : PagerDemodSettings::POCSAG;
QString type = ((typeCol >= 0) && (typeCol < cols.size())) ? cols[typeCol] : QString();
QString frame = ((frameCol >= 0) && (frameCol < cols.size())) ? cols[frameCol] : QString();
messageReceived(dateTime, address, functionBits, baud,
cols[numericCol], cols[alphaCol],
evenErrors, bchErrors);
evenErrors, bchErrors,
protocol, type, frame);
if (count % 1000 == 0)
{
@ -914,6 +965,7 @@ void PagerDemodGUI::makeUIConnections() @@ -914,6 +965,7 @@ void PagerDemodGUI::makeUIConnections()
QObject::connect(ui->deltaFrequency, &ValueDialZ::changed, this, &PagerDemodGUI::on_deltaFrequency_changed);
QObject::connect(ui->rfBW, &QSlider::valueChanged, this, &PagerDemodGUI::on_rfBW_valueChanged);
QObject::connect(ui->fmDev, &QSlider::valueChanged, this, &PagerDemodGUI::on_fmDev_valueChanged);
QObject::connect(ui->modulation, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &PagerDemodGUI::on_modulation_currentIndexChanged);
QObject::connect(ui->decode, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &PagerDemodGUI::on_decode_currentIndexChanged);
QObject::connect(ui->charset, &QToolButton::clicked, this, &PagerDemodGUI::on_charset_clicked);
QObject::connect(ui->filterAddress, &QLineEdit::editingFinished, this, &PagerDemodGUI::on_filterAddress_editingFinished);

6
plugins/channelrx/demodpager/pagerdemodgui.h

@ -107,9 +107,10 @@ private: @@ -107,9 +107,10 @@ private:
void applySettings(const QStringList& settingsKeys, bool force = false);
void displaySettings();
QString selectMessage(int functionBits, const QString &numericMessage, const QString &alphaMessage) const;
void messageReceived(const QDateTime dateTime, int address, int functionBits, int baud,
void messageReceived(const QDateTime dateTime, qint64 address, int functionBits, int baud,
const QString &numericMessage, const QString &alphaMessage,
int evenParityErrors, int bchParityErrors);
int evenParityErrors, int bchParityErrors,
PagerDemodSettings::Modulation protocol, const QString &type, const QString &frame);
bool handleMessage(const Message& message);
void makeUIConnections();
void updateAbsoluteCenterFrequency();
@ -132,6 +133,7 @@ private slots: @@ -132,6 +133,7 @@ private slots:
void on_deltaFrequency_changed(qint64 value);
void on_rfBW_valueChanged(int index);
void on_fmDev_valueChanged(int value);
void on_modulation_currentIndexChanged(int index);
void on_decode_currentIndexChanged(int index);
void on_charset_clicked();
void on_filterAddress_editingFinished();

73
plugins/channelrx/demodpager/pagerdemodgui.ui

@ -343,7 +343,7 @@ @@ -343,7 +343,7 @@
<item>
<widget class="QLabel" name="modulationLabel">
<property name="text">
<string>Mod</string>
<string>Mode</string>
</property>
</widget>
</item>
@ -356,20 +356,23 @@ @@ -356,20 +356,23 @@
</size>
</property>
<property name="toolTip">
<string>Pager modulation</string>
<string>Pager protocols to receive. Auto receives both POCSAG and FLEX</string>
</property>
<item>
<property name="text">
<string>Auto</string>
</property>
</item>
<item>
<property name="text">
<string>POCSAG</string>
</property>
</item>
</widget>
</item>
<item>
<widget class="Line" name="line_10">
<property name="orientation">
<enum>Qt::Orientation::Vertical</enum>
</property>
<item>
<property name="text">
<string>FLEX</string>
</property>
</item>
</widget>
</item>
<item>
@ -395,7 +398,7 @@ @@ -395,7 +398,7 @@
</size>
</property>
<property name="toolTip">
<string>How to choose between decoding a message as numeric or alphanumeric</string>
<string>How to choose between decoding a POCSAG message as numeric or alphanumeric. FLEX messages state their type</string>
</property>
<item>
<property name="text">
@ -725,16 +728,16 @@ @@ -725,16 +728,16 @@
<number>2</number>
</property>
<property name="leftMargin">
<number>3</number>
<number>0</number>
</property>
<property name="topMargin">
<number>3</number>
<number>0</number>
</property>
<property name="rightMargin">
<number>3</number>
<number>0</number>
</property>
<property name="bottomMargin">
<number>3</number>
<number>0</number>
</property>
<item>
<widget class="QTableWidget" name="messages">
@ -765,7 +768,7 @@ @@ -765,7 +768,7 @@
<string>Address</string>
</property>
<property name="toolTip">
<string>21-bit pager address the message is for</string>
<string>21-bit POCSAG address or FLEX capcode the message is for</string>
</property>
</column>
<column>
@ -778,7 +781,7 @@ @@ -778,7 +781,7 @@
<string>Function</string>
</property>
<property name="toolTip">
<string>Function bits / source address</string>
<string>POCSAG function bits / source address</string>
</property>
</column>
<column>
@ -818,7 +821,31 @@ @@ -818,7 +821,31 @@
<string>Baud</string>
</property>
<property name="toolTip">
<string>Baud rate the message was received at, detected from the preamble</string>
<string>POCSAG baud rate, detected from the preamble, or FLEX bit rate</string>
</property>
</column>
<column>
<property name="text">
<string>Protocol</string>
</property>
<property name="toolTip">
<string>Paging protocol: POCSAG or FLEX</string>
</property>
</column>
<column>
<property name="text">
<string>Type</string>
</property>
<property name="toolTip">
<string>Message type. Partial indicates a fragment of a FLEX message was lost</string>
</property>
</column>
<column>
<property name="text">
<string>Frame</string>
</property>
<property name="toolTip">
<string>FLEX cycle/frame and phase the message was received in</string>
</property>
</column>
</widget>
@ -1038,6 +1065,12 @@ @@ -1038,6 +1065,12 @@
<header>gui/rollupcontents.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>ValueDialZ</class>
<extends>QWidget</extends>
<header>gui/valuedialz.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>ButtonSwitch</class>
<extends>QToolButton</extends>
@ -1049,12 +1082,6 @@ @@ -1049,12 +1082,6 @@
<header>gui/levelmeter.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>ValueDialZ</class>
<extends>QWidget</extends>
<header>gui/valuedialz.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>GLScope</class>
<extends>QWidget</extends>

9
plugins/channelrx/demodpager/pagerdemodsettings.cpp

@ -37,6 +37,7 @@ PagerDemodSettings::PagerDemodSettings() : @@ -37,6 +37,7 @@ PagerDemodSettings::PagerDemodSettings() :
void PagerDemodSettings::resetToDefaults()
{
m_inputFrequencyOffset = 0;
m_modulation = Auto;
m_rfBandwidth = 20000.0f;
m_fmDeviation = 4500.0f;
m_decode = Standard;
@ -121,6 +122,7 @@ QByteArray PagerDemodSettings::serialize() const @@ -121,6 +122,7 @@ QByteArray PagerDemodSettings::serialize() const
s.writeBool(32, m_filterDuplicates);
s.writeBool(33, m_duplicateMatchMessageOnly);
s.writeBool(34, m_duplicateMatchLastOnly);
s.writeS32(35, (int)m_modulation);
for (int i = 0; i < PAGERDEMOD_MESSAGE_COLUMNS; i++) {
s.writeS32(100 + i, m_messageColumnIndexes[i]);
@ -221,6 +223,7 @@ bool PagerDemodSettings::deserialize(const QByteArray& data) @@ -221,6 +223,7 @@ bool PagerDemodSettings::deserialize(const QByteArray& data)
d.readBool(32, &m_filterDuplicates);
d.readBool(33, &m_duplicateMatchMessageOnly);
d.readBool(34, &m_duplicateMatchLastOnly);
d.readS32(35, (int*)&m_modulation, (int)Auto);
for (int i = 0; i < PAGERDEMOD_MESSAGE_COLUMNS; i++) {
d.readS32(100 + i, &m_messageColumnIndexes[i], i);
@ -244,6 +247,9 @@ void PagerDemodSettings::applySettings(const QStringList& settingsKeys, const Pa @@ -244,6 +247,9 @@ void PagerDemodSettings::applySettings(const QStringList& settingsKeys, const Pa
if (settingsKeys.contains("inputFrequencyOffset")) {
m_inputFrequencyOffset = settings.m_inputFrequencyOffset;
}
if (settingsKeys.contains("modulation")) {
m_modulation = settings.m_modulation;
}
if (settingsKeys.contains("rfBandwidth")) {
m_rfBandwidth = settings.m_rfBandwidth;
}
@ -350,6 +356,9 @@ QString PagerDemodSettings::getDebugString(const QStringList& settingsKeys, bool @@ -350,6 +356,9 @@ QString PagerDemodSettings::getDebugString(const QStringList& settingsKeys, bool
if (settingsKeys.contains("inputFrequencyOffset") || force) {
ostr << " m_inputFrequencyOffset: " << m_inputFrequencyOffset;
}
if (settingsKeys.contains("modulation") || force) {
ostr << " m_modulation: " << m_modulation;
}
if (settingsKeys.contains("rfBandwidth") || force) {
ostr << " m_rfBandwidth: " << m_rfBandwidth;
}

22
plugins/channelrx/demodpager/pagerdemodsettings.h

@ -33,7 +33,7 @@ class QDataStream; @@ -33,7 +33,7 @@ class QDataStream;
class Serializable;
// Number of columns in the tables
#define PAGERDEMOD_MESSAGE_COLUMNS 10
#define PAGERDEMOD_MESSAGE_COLUMNS 13
struct PagerDemodSettings
{
@ -47,7 +47,10 @@ struct PagerDemodSettings @@ -47,7 +47,10 @@ struct PagerDemodSettings
MESSAGE_COL_NUMERIC,
MESSAGE_COL_EVEN_PE,
MESSAGE_COL_BCH_PE,
MESSAGE_COL_BAUD
MESSAGE_COL_BAUD,
MESSAGE_COL_PROTOCOL,
MESSAGE_COL_TYPE,
MESSAGE_COL_FRAME
};
struct NotificationSettings {
@ -68,6 +71,11 @@ struct PagerDemodSettings @@ -68,6 +71,11 @@ struct PagerDemodSettings
};
qint32 m_inputFrequencyOffset;
enum Modulation {
Auto, //!< Receive both POCSAG and FLEX
POCSAG,
FLEX
} m_modulation;
Real m_rfBandwidth;
Real m_fmDeviation; //<! 4.5k for POCSAG
enum Decode {
@ -76,7 +84,7 @@ struct PagerDemodSettings @@ -76,7 +84,7 @@ struct PagerDemodSettings
Numeric,
Alphanumeric,
Heuristic
} m_decode; //!< Whether to decode as numeric or alphanumeric
} m_decode; //!< Whether to decode POCSAG as numeric or alphanumeric
bool m_udpEnabled;
QString m_udpAddress;
uint16_t m_udpPort;
@ -115,7 +123,13 @@ struct PagerDemodSettings @@ -115,7 +123,13 @@ struct PagerDemodSettings
int m_messageColumnIndexes[PAGERDEMOD_MESSAGE_COLUMNS];//!< How the columns are ordered in the table
int m_messageColumnSizes[PAGERDEMOD_MESSAGE_COLUMNS]; //!< Size of the columns in the table
static const int m_channelSampleRate = 38400; //!< lcm(512,2400) baud rates
static const int m_channelSampleRate = 38400; //!< lcm(512,2400) POCSAG baud rates, and a multiple of FLEX's 1600 and 3200
static QString protocolName(Modulation protocol) { return protocol == FLEX ? "FLEX" : "POCSAG"; }
//!< POCSAG addresses are 21 bits. FLEX capcodes can be up to 10 digits
static QString formatAddress(qint64 address, Modulation protocol) {
return QString("%1").arg(address, protocol == FLEX ? 9 : 7, 10, QChar('0'));
}
PagerDemodSettings();
void resetToDefaults();

335
plugins/channelrx/demodpager/pagerdemodsink.cpp

@ -27,6 +27,7 @@ @@ -27,6 +27,7 @@
#include "maincore.h"
#include "pagerdemod.h"
#include "pagerdemodbch.h"
#include "pagerdemodsink.h"
PagerDemodSink::PagerDemodSink() :
@ -64,6 +65,7 @@ PagerDemodSink::PagerDemodSink() : @@ -64,6 +65,7 @@ PagerDemodSink::PagerDemodSink() :
m_bchErrors(0),
m_alphaBitBuffer(0),
m_alphaBitBufferBits(0),
m_flex(PagerDemodSettings::m_channelSampleRate),
m_sampleBufferIndex(0)
{
m_magsq = 0.0;
@ -124,152 +126,6 @@ void PagerDemodSink::feed(const SampleVector::const_iterator& begin, const Sampl @@ -124,152 +126,6 @@ void PagerDemodSink::feed(const SampleVector::const_iterator& begin, const Sampl
}
}
// XOR bits together for parity check
int PagerDemodSink::xorBits(quint32 word, int firstBit, int lastBit)
{
int x = 0;
for (int i = firstBit; i <= lastBit; i++)
{
x ^= (word >> i) & 1;
}
return x;
}
// Check for even parity
bool PagerDemodSink::evenParity(quint32 word, int firstBit, int lastBit, int parityBit)
{
return xorBits(word, firstBit, lastBit) == parityBit;
}
// Reverse order of bits
quint32 PagerDemodSink::reverse(quint32 x)
{
x = (((x & 0xaaaaaaaa) >> 1) | ((x & 0x55555555) << 1));
x = (((x & 0xcccccccc) >> 2) | ((x & 0x33333333) << 2));
x = (((x & 0xf0f0f0f0) >> 4) | ((x & 0x0f0f0f0f) << 4));
x = (((x & 0xff00ff00) >> 8) | ((x & 0x00ff00ff) << 8));
return((x >> 16) | (x << 16));
}
// Calculate BCH parity and even parity bits
quint32 PagerDemodSink::bchEncode(const quint32 cw)
{
quint32 bit = 0;
quint32 localCW = cw & 0xFFFFF800; // Mask off BCH parity and even parity bits
quint32 cwE = localCW;
// Calculate BCH bits
for (bit = 1; bit <= 21; bit++)
{
if (cwE & 0x80000000) {
cwE ^= 0xED200000;
}
cwE <<= 1;
}
localCW |= (cwE >> 21);
return localCW;
}
// Use BCH decoding to try to fix any bit errors
// Returns true if able to be decode/repair successful
// See: https://www.eevblog.com/forum/microcontrollers/practical-guides-to-bch-fec/
bool PagerDemodSink::bchDecode(const quint32 cw, quint32& correctedCW)
{
// Calculate syndrome
// We do this by recalculating the BCH parity bits and XORing them against the received ones
quint32 syndrome = ((bchEncode(cw) ^ cw) >> 1) & 0x3FF;
if (syndrome == 0)
{
// Syndrome of zero indicates no repair required
correctedCW = cw;
return true;
}
// Meggitt decoder
quint32 result = 0;
quint32 damagedCW = cw;
// Calculate BCH bits
for (quint32 xbit = 0; xbit < 31; xbit++)
{
// Produce the next corrected bit in the high bit of the result
result <<= 1;
if ((syndrome == 0x3B4) || // 0x3B4: Syndrome when a single error is detected in the MSB
(syndrome == 0x26E) || // 0x26E: Two adjacent errors
(syndrome == 0x359) || // 0x359: Two errors, one OK bit between
(syndrome == 0x076) || // 0x076: Two errors, two OK bits between
(syndrome == 0x255) || // 0x255: Two errors, three OK bits between
(syndrome == 0x0F0) || // 0x0F0: Two errors, four OK bits between
(syndrome == 0x216) ||
(syndrome == 0x365) ||
(syndrome == 0x068) ||
(syndrome == 0x25A) ||
(syndrome == 0x343) ||
(syndrome == 0x07B) ||
(syndrome == 0x1E7) ||
(syndrome == 0x129) ||
(syndrome == 0x14E) ||
(syndrome == 0x2C9) ||
(syndrome == 0x0BE) ||
(syndrome == 0x231) ||
(syndrome == 0x0C2) ||
(syndrome == 0x20F) ||
(syndrome == 0x0DD) ||
(syndrome == 0x1B4) ||
(syndrome == 0x2B4) ||
(syndrome == 0x334) ||
(syndrome == 0x3F4) ||
(syndrome == 0x394) ||
(syndrome == 0x3A4) ||
(syndrome == 0x3BC) ||
(syndrome == 0x3B0) ||
(syndrome == 0x3B6) ||
(syndrome == 0x3B5)
)
{
// Syndrome matches an error in the MSB
// Correct that error and adjust the syndrome to account for it
syndrome ^= 0x3B4;
result |= (~damagedCW & 0x80000000) >> 30;
}
else
{
// No error
result |= (damagedCW & 0x80000000) >> 30;
}
damagedCW <<= 1;
// Handle syndrome shift register feedback
if (syndrome & 0x200)
{
syndrome <<= 1;
syndrome ^= 0x769; // 0x769 = POCSAG generator polynomial -- x^10 + x^9 + x^8 + x^6 + x^5 + x^3 + 1
}
else
{
syndrome <<= 1;
}
// Mask off bits which fall off the end of the syndrome shift register
syndrome &= 0x3FF;
}
// Check if error correction was successful
if (syndrome != 0)
{
// Syndrome nonzero at end indicates uncorrectable errors
correctedCW = cw;
return false;
}
// The BCH decoder operates on bits 31 through 1. Preserve the separate
// overall parity bit in bit 0 so it can be checked after correction.
correctedCW = result | (cw & 0x1);
return true;
}
// Decode a batch of codewords to addresses and messages
// Messages may be spreadout over multiple batches
// https://www.itu.int/dms_pubrec/itu-r/rec/m/R-REC-M.584-1-198607-S!!PDF-E.pdf
@ -306,9 +162,9 @@ void PagerDemodSink::decodeBatch() @@ -306,9 +162,9 @@ void PagerDemodSink::decodeBatch()
}
// Check parity bit
bool parityError = !evenParity(m_codeWords[i], 1, 31, m_codeWords[i] & 0x1);
bool parityError = !PagerDemodBCH::evenParity(m_codeWords[i], 1, 31, m_codeWords[i] & 0x1);
// The overall parity bit is preserved by bchDecode() so it can be
// The overall parity bit is preserved by PagerDemodBCH::decode() so it can be
// reported separately. Ignore it when identifying the idle word.
if ((m_codeWords[i] & 0xfffffffeU) == (PAGERDEMOD_POCSAG_IDLECODE & 0xfffffffeU))
{
@ -462,7 +318,7 @@ void PagerDemodSink::handleBit(int bit) @@ -462,7 +318,7 @@ void PagerDemodSink::handleBit(int bit)
else if (popcount((m_bits ^ PAGERDEMOD_POCSAG_SYNCCODE) & 0xfffffffeU) <= 2)
{
quint32 correctedCW;
if (bchDecode(m_bits, correctedCW)
if (PagerDemodBCH::decode(m_bits, correctedCW)
&& ((correctedCW & 0xfffffffeU) == (PAGERDEMOD_POCSAG_SYNCCODE & 0xfffffffeU)))
{
m_gotSOP = true;
@ -472,7 +328,7 @@ void PagerDemodSink::handleBit(int bit) @@ -472,7 +328,7 @@ void PagerDemodSink::handleBit(int bit)
else if (popcount((m_bits ^ PAGERDEMOD_POCSAG_SYNCCODE_INV) & 0xfffffffeU) <= 2)
{
quint32 correctedCW;
if (bchDecode(~m_bits, correctedCW)
if (PagerDemodBCH::decode(~m_bits, correctedCW)
&& ((correctedCW & 0xfffffffeU) == (PAGERDEMOD_POCSAG_SYNCCODE & 0xfffffffeU)))
{
m_gotSOP = true;
@ -496,7 +352,7 @@ void PagerDemodSink::handleBit(int bit) @@ -496,7 +352,7 @@ void PagerDemodSink::handleBit(int bit)
// to fix any bit errors
quint32 cw = m_inverted ? ~m_bits : m_bits;
quint32 correctedCW;
m_codeWordsBCHError[m_wordCount] = !bchDecode(cw, correctedCW);
m_codeWordsBCHError[m_wordCount] = !PagerDemodBCH::decode(cw, correctedCW);
m_codeWords[m_wordCount] = correctedCW;
m_wordCount++;
@ -542,20 +398,7 @@ void PagerDemodSink::sendMessage() @@ -542,20 +398,7 @@ void PagerDemodSink::sendMessage()
m_numericMessage = m_numericMessage.trimmed(); // Remove trailing spaces
if (getMessageQueueToChannel())
{
// Convert from 7-bit to UTF-8 using user specified encoding
for (int i = 0; i < m_alphaMessage.size(); i++)
{
QChar c = m_alphaMessage[i];
int idx = m_settings.m_sevenbit.indexOf(c.toLatin1());
if (idx >= 0) {
c = QChar(m_settings.m_unicode[idx]);
}
m_alphaMessage[i] = c;
}
// Reverse reading order, if required
if (m_settings.m_reverse) {
std::reverse(m_alphaMessage.begin(), m_alphaMessage.end());
}
mapCharacters(m_alphaMessage);
// Send to channel and GUI
PagerDemod::MsgPagerMessage *msg = PagerDemod::MsgPagerMessage::create(m_address, m_functionBits, m_alphaMessage, m_numericMessage, m_parityErrors, m_bchErrors, m_baud);
getMessageQueueToChannel()->push(msg);
@ -563,6 +406,76 @@ void PagerDemodSink::sendMessage() @@ -563,6 +406,76 @@ void PagerDemodSink::sendMessage()
m_addressValid = false;
}
// Convert from 7-bit to UTF-8 using user specified encoding, and reverse reading order, if required
void PagerDemodSink::mapCharacters(QString& message) const
{
for (int i = 0; i < message.size(); i++)
{
QChar c = message[i];
int idx = m_settings.m_sevenbit.indexOf(c.toLatin1());
if (idx >= 0) {
c = QChar(m_settings.m_unicode[idx]);
}
message[i] = c;
}
if (m_settings.m_reverse) {
std::reverse(message.begin(), message.end());
}
}
void PagerDemodSink::sendFlexMessage(const PagerDemodFlexMessage& flexMessage)
{
if (!getMessageQueueToChannel() || (flexMessage.m_type == PagerDemodFlexMessage::ShortInstruction)) {
return;
}
// The vector type says how the message is encoded, so only one of alpha and numeric is set
QString alpha;
QString numeric;
if (flexMessage.isNumeric())
{
numeric = flexMessage.m_text.trimmed();
}
else
{
alpha = flexMessage.m_text;
if (flexMessage.m_type != PagerDemodFlexMessage::Binary) {
mapCharacters(alpha);
}
}
QString type = PagerDemodFlexMessage::typeName(flexMessage.m_type);
QStringList qualifiers;
if (flexMessage.m_group >= 0) {
qualifiers.append("group");
}
if (flexMessage.m_incomplete) {
qualifiers.append("partial");
}
if (!qualifiers.isEmpty()) {
type.append(QString(" (%1)").arg(qualifiers.join(", ")));
}
QString frame = QString("%1/%2 %3")
.arg(flexMessage.m_cycle)
.arg(flexMessage.m_frame, 3, 10, QChar('0'))
.arg(QChar(flexMessage.m_phase));
PagerDemod::MsgPagerMessage *msg = PagerDemod::MsgPagerMessage::create(
flexMessage.m_capcode,
0,
alpha,
numeric,
flexMessage.m_parityErrors,
flexMessage.m_bchErrors,
flexMessage.m_bitRate,
PagerDemodSettings::FLEX,
type,
frame
);
getMessageQueueToChannel()->push(msg);
}
// Decode the 20 message bits of a codeword as both numeric and 7-bit alphanumeric
void PagerDemodSink::addMessageBits(int messageBits)
{
@ -570,7 +483,7 @@ void PagerDemodSink::addMessageBits(int messageBits) @@ -570,7 +483,7 @@ void PagerDemodSink::addMessageBits(int messageBits)
for (int j = 16; j >= 0; j -= 4)
{
quint32 numericBits = (messageBits >> j) & 0xf;
numericBits = reverse(numericBits) >> (32-4);
numericBits = PagerDemodBCH::reverse(numericBits) >> (32-4);
// Spec has 0xa as 'spare', but other decoders treat is as .
const char numericChars[] = {
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '.', 'U', ' ', '-', ')', '('
@ -587,7 +500,7 @@ void PagerDemodSink::addMessageBits(int messageBits) @@ -587,7 +500,7 @@ void PagerDemodSink::addMessageBits(int messageBits)
// Extract next 7-bit character from bit buffer
char c = (m_alphaBitBuffer >> (m_alphaBitBufferBits-7)) & 0x7f;
// Reverse bit ordering
c = reverse(c) >> (32-7);
c = PagerDemodBCH::reverse(c) >> (32-7);
// Add to received message string (excluding, null, end of text, end ot transmission)
if (c != 0 && c != 0x3 && c != 0x4) {
m_alphaMessage.append(c);
@ -621,40 +534,70 @@ void PagerDemodSink::processOneSample(Complex &ci) @@ -621,40 +534,70 @@ void PagerDemodSink::processOneSample(Complex &ci)
m_magsqCount++;
// Detect the baud rate from the preamble. Only run while unsynced: that is when the
// rate can change, and it keeps the per-rate filters out of the decoding path
if (!m_gotSOP)
// FLEX frames are found by their 64-bit sync code, which is far less likely to occur
// by chance than POCSAG's 32-bit one, so FLEX takes over from POCSAG when it's found
bool flexReceiving = false;
if (m_settings.m_modulation != PagerDemodSettings::POCSAG)
{
int best = m_baudDetector.process(fmDemod);
bool wasReceiving = m_flex.isReceiving();
if (m_baudDetector.metric(best) >= m_preambleThreshold)
{
int baud = PagerDemodBaudDetector::m_rates[best];
m_flex.process(fmDemod, magsq);
flexReceiving = m_flex.isReceiving();
if (baud != m_baud) {
setBaud(baud);
if (flexReceiving && !wasReceiving && m_gotSOP)
{
if (m_addressValid) {
sendMessage();
}
m_gotSOP = false;
m_addressValid = false;
}
while (m_flex.hasMessages()) {
sendFlexMessage(m_flex.takeMessage());
}
}
// Low pass filter
Real filt = m_lowpassBaud.filter(fmDemod);
Real filt = 0.0f;
int data = 0;
bool sample = false;
// An input frequency offset corresponds to a DC offset after FM demodulation
// To calculate what it is, we average part of the preamble, which should be zero
if (!m_gotSOP)
if ((m_settings.m_modulation != PagerDemodSettings::FLEX) && !flexReceiving)
{
m_preambleMovingAverage(filt);
m_dcOffset = m_preambleMovingAverage.asDouble();
}
// Detect the baud rate from the preamble. Only run while unsynced: that is when the
// rate can change, and it keeps the per-rate filters out of the decoding path
if (!m_gotSOP)
{
int best = m_baudDetector.process(fmDemod);
bool sample = false;
if (m_baudDetector.metric(best) >= m_preambleThreshold)
{
int baud = PagerDemodBaudDetector::m_rates[best];
// Slice data
int data = (filt - m_dcOffset) >= 0.0;
if (baud != m_baud) {
setBaud(baud);
}
}
}
// Low pass filter
filt = m_lowpassBaud.filter(fmDemod);
// Matched filter and timing recovery produce the bits
sample = matchedFilterAndDpll(filt - m_dcOffset);
// An input frequency offset corresponds to a DC offset after FM demodulation
// To calculate what it is, we average part of the preamble, which should be zero
if (!m_gotSOP)
{
m_preambleMovingAverage(filt);
m_dcOffset = m_preambleMovingAverage.asDouble();
}
// Slice data
data = (filt - m_dcOffset) >= 0.0;
// Matched filter and timing recovery produce the bits
sample = matchedFilterAndDpll(filt - m_dcOffset);
}
// Save data for edge detection
// Select signals to feed to scope
@ -690,7 +633,7 @@ void PagerDemodSink::processOneSample(Complex &ci) @@ -690,7 +633,7 @@ void PagerDemodSink::processOneSample(Complex &ci)
scopeSample.real(m_bit);
break;
case 9:
scopeSample.real(m_gotSOP);
scopeSample.real(m_gotSOP || flexReceiving);
break;
}
@ -724,7 +667,7 @@ void PagerDemodSink::processOneSample(Complex &ci) @@ -724,7 +667,7 @@ void PagerDemodSink::processOneSample(Complex &ci)
scopeSample.imag(m_bit);
break;
case 9:
scopeSample.imag(m_gotSOP);
scopeSample.imag(m_gotSOP || flexReceiving);
break;
}
@ -795,6 +738,16 @@ void PagerDemodSink::applySettings(const QStringList& settingsKeys, const PagerD @@ -795,6 +738,16 @@ void PagerDemodSink::applySettings(const QStringList& settingsKeys, const PagerD
m_phaseDiscri.setFMScaling(PagerDemodSettings::m_channelSampleRate / (2.0f * settings.m_fmDeviation));
}
if ((settingsKeys.contains("modulation") && (settings.m_modulation != m_settings.m_modulation)) || force)
{
m_flex.reset();
if (settings.m_modulation == PagerDemodSettings::FLEX)
{
m_gotSOP = false;
m_addressValid = false;
}
}
if (force)
{
// The baud rate is detected from the preamble rather than configured, as POCSAG

11
plugins/channelrx/demodpager/pagerdemodsink.h

@ -35,6 +35,7 @@ @@ -35,6 +35,7 @@
#include "util/messagequeue.h"
#include "pagerdemodsettings.h"
#include "pagerdemodflex.h"
#define PAGERDEMOD_FRAMES_PER_BATCH 8
#define PAGERDEMOD_CODEWORDS_PER_FRAME 2
@ -186,6 +187,7 @@ public: @@ -186,6 +187,7 @@ public:
void setChannel(ChannelAPI *channel) { m_channel = channel; }
double getMagSq() const { return m_magsq; }
const PagerDemodFlex& getFlex() const { return m_flex; }
void getMagSqLevels(double& avg, double& peak, int& nbSamples)
{
@ -285,6 +287,8 @@ private: @@ -285,6 +287,8 @@ private:
quint32 m_alphaBitBuffer; // Bit buffer to 7-bit chars spread across codewords
int m_alphaBitBufferBits; // Count of bits in m_alphaBitBuffer
PagerDemodFlex m_flex; // FLEX receiver, run on the same FM demodulator output
QVector<qint16> m_demodBuffer;
int m_demodBufferFill;
ComplexVector m_sampleBuffer;
@ -296,15 +300,12 @@ private: @@ -296,15 +300,12 @@ private:
void sampleToScope(Complex sample);
void decodeBatch();
void sendMessage();
void sendFlexMessage(const PagerDemodFlexMessage& flexMessage);
void mapCharacters(QString& message) const;
void addMessageBits(int messageBits);
void setBaud(int baud);
void handleBit(int bit);
bool matchedFilterAndDpll(Real v);
int xorBits(quint32 word, int firstBit, int lastBit);
bool evenParity(quint32 word, int firstBit, int lastBit, int parityBit);
quint32 reverse(quint32 x);
quint32 bchEncode(const quint32 cw);
bool bchDecode(const quint32 cw, quint32& correctedCW);
};

47
plugins/channelrx/demodpager/readme.md

@ -2,7 +2,7 @@ @@ -2,7 +2,7 @@
<h2>Introduction</h2>
This plugin can be used to demodulate POCSAG pager messages.
This plugin can be used to demodulate POCSAG and FLEX pager messages.
<h2>Interface</h2>
@ -30,11 +30,17 @@ This specifies the bandwidth of a LPF that is applied to the input signal to lim @@ -30,11 +30,17 @@ This specifies the bandwidth of a LPF that is applied to the input signal to lim
<h3>5: Dev - Frequency deviation</h3>
Adjusts the expected peak frequency deviation in 0.1 kHz steps from 1 to 6 kHz. POCSAG uses FSK with a ±4.5 kHz shift.
Adjusts the expected peak frequency deviation in 0.1 kHz steps from 1 to 6 kHz.
POCSAG uses FSK with a ±4.5 kHz shift.
FLEX measures its deviation from each frame's sync, so doesn't depend on this setting.
<h3>6: Mod - Modulation</h3>
<h3>6: Mode</h3>
Specifies the pager modulation. Currently only POCSAG is supported.
Specifies which pager protocols to receive:
* Auto - Receive both POCSAG and FLEX, on the same channel.
* POCSAG - Receive POCSAG only.
* FLEX - Receive FLEX only.
POCSAG uses FSK with 4.5kHz frequency shift, at 512, 1200 or 2400 baud. The baud rate is
detected automatically from the preamble, as networks mix rates and a single channel can
@ -42,9 +48,21 @@ carry different rates at different times. @@ -42,9 +48,21 @@ carry different rates at different times.
High frequency is typically 0, with low 1, but occasionally this appears to be reversed, so the demodulator supports either.
Data is framed as specified in [ITU-R M.584-2](https://www.itu.int/dms_pubrec/itu-r/rec/m/R-REC-M.584-2-199711-I!!PDF-E.pdf)
FLEX uses 2-level or 4-level FSK with a ±4.8 kHz shift, at 1600 or 3200 baud, giving 1600, 3200 or 6400 bit/s.
All four modes are supported, and are detected automatically from each frame's sync code, as is the polarity.
Messages are sent in 1.875 s frames, with 1 to 4 interleaved phases (A to D) per frame. Long alphanumeric messages
may be split over several frames; these are reassembled before being displayed.
Once a frame has been received, the start of following frames is predicted, so frames whose sync is damaged
(e.g. when a transmitter keys up) can still be received, provided they have the expected frame number.
Short and long addresses (capcodes), and alphanumeric, numeric, tone, secure and binary messages are supported.
Group calls are supported: pagers are first assigned to one of 16 temporary addresses for a particular frame,
and a message sent to that temporary address in that frame is displayed once for each assigned capcode.
If the assignments were not received, the message is displayed with the temporary address (2029568 to 2029583).
<h3>7: Decode</h3>
Specifies how messages are decoded in the Message column in the table:
Specifies how POCSAG messages are decoded in the Message column in the table. FLEX messages state their type,
so this setting doesn't apply to them:
* Standard - As per ITU-R M.584-2 - Function 0 = numeric, function 1-3 = alphanumeric.
* Inverted - Function 3 = numeric, function 0-2 = alphanumeric.
@ -74,7 +92,7 @@ Pressing this button clears all messages from the table. @@ -74,7 +92,7 @@ Pressing this button clears all messages from the table.
When checked, received messages are forwarded to the specified UDP address (12) and port (13).
The messages are forwarded as null terminated ASCII strings, in the format: data time address function alpha numeric
The messages are forwarded as null terminated ASCII strings, in the format: date time address function alpha numeric protocol type.
<h3>12: UDP address</h3>
@ -134,13 +152,16 @@ The received messages table displays each pager message received. @@ -134,13 +152,16 @@ The received messages table displays each pager message received.
* Date - The date the message was received.
* Time - The time the message was received.
* Address - The 21-bit pager address the message is for.
* Message - The decoded message, as per Decode setting (8). This will be empty for "tone only" messages (i.e. when the pager beeps without a message).
* Function - Function bits. In some instances this is used to specify the encoding of the message (Numeric/alphanumeric). In others, it is the pager source address.
* Alpha - Message decoded as alphanumeric text, regardless of Decode setting (8)
* Numeric - Message decoded as numeric, regardless of Decode setting (8).
* Address - The 21-bit POCSAG pager address (7 digits) or FLEX capcode (9 digits) the message is for.
* Message - The decoded message, as per Decode setting (7) for POCSAG. This will be empty for "tone only" messages (i.e. when the pager beeps without a message).
* Function - POCSAG function bits. In some instances this is used to specify the encoding of the message (Numeric/alphanumeric). In others, it is the pager source address. Blank for FLEX.
* Alpha - For POCSAG, the message decoded as alphanumeric text, regardless of Decode setting (7). For FLEX, the text of alphanumeric, secure and binary (shown as hex) messages.
* Numeric - For POCSAG, the message decoded as numeric, regardless of Decode setting (7). For FLEX, the digits of numeric and tone messages.
* Even PE - Number of even parity errors detected in the code words of the message.
* BCH PE - Number of uncorrectable BCH parity errors detected in the code words of the message.
* Baud - The baud rate the message was received at, detected automatically from the preamble.
* BCH PE - Number of uncorrectable BCH parity errors detected in the code words of the message. For FLEX, this includes code words received after the carrier was lost.
* Baud - For POCSAG, the baud rate the message was received at, detected automatically from the preamble. For FLEX, the bit rate of the frame.
* Protocol - POCSAG or FLEX.
* Type - The message type: Alpha, Numeric or Tone for POCSAG, as chosen by the Decode setting (7); for FLEX, the type given in the message vector. For FLEX, "(group)" is appended to group calls and "(partial)" to messages where one or more fragments were lost.
* Frame - For FLEX, the cycle (0-14), frame (0-127) and phase (A-D) the message started in.
Right clicking on the table header allows you to select which columns to show. The columns can be reordered by left clicking and dragging the column header. Right clicking on an item in the table allows you to copy the value to the clipboard.

9
sdrbase/resources/webapi/doc/swagger/include/PagerDemod.yaml

@ -1,6 +1,15 @@ @@ -1,6 +1,15 @@
PagerDemodSettings:
description: PagerDemod
properties:
modulation:
type: integer
minimum: 0
maximum: 2
description: >
Pager protocols to receive
* 0 - Auto (POCSAG and FLEX)
* 1 - POCSAG
* 2 - FLEX
decode:
type: integer
minimum: 0

9
swagger/sdrangel/api/swagger/include/PagerDemod.yaml

@ -1,6 +1,15 @@ @@ -1,6 +1,15 @@
PagerDemodSettings:
description: PagerDemod
properties:
modulation:
type: integer
minimum: 0
maximum: 2
description: >
Pager protocols to receive
* 0 - Auto (POCSAG and FLEX)
* 1 - POCSAG
* 2 - FLEX
decode:
type: integer
minimum: 0

22
swagger/sdrangel/code/qt5/client/SWGPagerDemodSettings.cpp

@ -28,6 +28,8 @@ SWGPagerDemodSettings::SWGPagerDemodSettings(QString* json) { @@ -28,6 +28,8 @@ SWGPagerDemodSettings::SWGPagerDemodSettings(QString* json) {
}
SWGPagerDemodSettings::SWGPagerDemodSettings() {
modulation = 0;
m_modulation_isSet = false;
decode = 0;
m_decode_isSet = false;
reverse = 0;
@ -78,6 +80,8 @@ SWGPagerDemodSettings::~SWGPagerDemodSettings() { @@ -78,6 +80,8 @@ SWGPagerDemodSettings::~SWGPagerDemodSettings() {
void
SWGPagerDemodSettings::init() {
modulation = 0;
m_modulation_isSet = false;
decode = 0;
m_decode_isSet = false;
reverse = 0;
@ -172,6 +176,8 @@ SWGPagerDemodSettings::fromJson(QString &json) { @@ -172,6 +176,8 @@ SWGPagerDemodSettings::fromJson(QString &json) {
void
SWGPagerDemodSettings::fromJsonObject(QJsonObject &pJson) {
::SWGSDRangel::setValue(&modulation, pJson["modulation"], "qint32", "");
::SWGSDRangel::setValue(&decode, pJson["decode"], "qint32", "");
::SWGSDRangel::setValue(&reverse, pJson["reverse"], "qint32", "");
@ -230,6 +236,9 @@ SWGPagerDemodSettings::asJson () @@ -230,6 +236,9 @@ SWGPagerDemodSettings::asJson ()
QJsonObject*
SWGPagerDemodSettings::asJsonObject() {
QJsonObject* obj = new QJsonObject();
if(m_modulation_isSet){
obj->insert("modulation", QJsonValue(modulation));
}
if(m_decode_isSet){
obj->insert("decode", QJsonValue(decode));
}
@ -297,6 +306,16 @@ SWGPagerDemodSettings::asJsonObject() { @@ -297,6 +306,16 @@ SWGPagerDemodSettings::asJsonObject() {
return obj;
}
qint32
SWGPagerDemodSettings::getModulation() {
return modulation;
}
void
SWGPagerDemodSettings::setModulation(qint32 modulation) {
this->modulation = modulation;
this->m_modulation_isSet = true;
}
qint32
SWGPagerDemodSettings::getDecode() {
return decode;
@ -512,6 +531,9 @@ bool @@ -512,6 +531,9 @@ bool
SWGPagerDemodSettings::isSet(){
bool isObjectUpdated = false;
do{
if(m_modulation_isSet){
isObjectUpdated = true; break;
}
if(m_decode_isSet){
isObjectUpdated = true; break;
}

6
swagger/sdrangel/code/qt5/client/SWGPagerDemodSettings.h

@ -45,6 +45,9 @@ public: @@ -45,6 +45,9 @@ public:
virtual void fromJsonObject(QJsonObject &json) override;
virtual SWGPagerDemodSettings* fromJson(QString &jsonString) override;
qint32 getModulation();
void setModulation(qint32 modulation);
qint32 getDecode();
void setDecode(qint32 decode);
@ -112,6 +115,9 @@ public: @@ -112,6 +115,9 @@ public:
virtual bool isSet() override;
private:
qint32 modulation;
bool m_modulation_isSet;
qint32 decode;
bool m_decode_isSet;

Loading…
Cancel
Save