From 02b4c2c20958c9fb04e657c58c41f3fe1b550f49 Mon Sep 17 00:00:00 2001 From: Jens Ahrensfeld Date: Fri, 11 Jan 2019 16:39:37 +0000 Subject: [PATCH] -a dded git-svn-id: http://moon:8086/svn/software/trunk/projects/GnuRadio@404 b431acfa-c32f-4a4a-93f1-934dc6c82436 --- gr-jay/lib/PocsagDecoder.cpp | 167 +++++++++++++++++++++++++++++++++++ gr-jay/lib/PocsagDecoder.hpp | 47 ++++++++++ 2 files changed, 214 insertions(+) create mode 100644 gr-jay/lib/PocsagDecoder.cpp create mode 100644 gr-jay/lib/PocsagDecoder.hpp diff --git a/gr-jay/lib/PocsagDecoder.cpp b/gr-jay/lib/PocsagDecoder.cpp new file mode 100644 index 0000000..40126c6 --- /dev/null +++ b/gr-jay/lib/PocsagDecoder.cpp @@ -0,0 +1,167 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ + +/* + * File: PocsagDecoder.cpp + * Author: jens + * + * Created on 11. Januar 2019, 17:20 + */ + +#include "PocsagDecoder.hpp" + +const char numericChar[16] = +{ + '0', '1', '2', '3', + '4', '5', '6', '7', + '8', '9', '.', 'U', + ' ', '-', ']', '[', +}; + +PocsagDecoder::PocsagDecoder() +: state(Sync) +, dataCount(0) +, msgPos(0) +, msgWord(0) +, func(0) +, msgActive(0) +{ +} + +PocsagDecoder::PocsagDecoder(const PocsagDecoder& orig) +{ +} + +PocsagDecoder::~PocsagDecoder() +{ +} + +void PocsagDecoder::messageFinish() +{ + if (msgActive) + { + msgActive = 0; + msgPos = 0; + msgWord = 0; + fprintf(stderr, "\n"); + } +} + +size_t PocsagDecoder::process(uint8_t const *pData, size_t size) +{ + size_t remain = size; + size_t numProcessed = 0; + while(remain >= 4) + { + int incr = 4; + uint32_t word + = (uint32_t)pData[0] << 24 & 0xFF000000 + | (uint32_t)pData[1] << 16 & 0x00FF0000 + | (uint32_t)pData[2] << 8 & 0x0000FF00 + | (uint32_t)pData[3] << 0 & 0x000000FF; + +// printf ("word=%08X\n", word); + + State stateNext = state; + switch(state) + { + case Sync: + if (word == 0x7CD215D8) + { + stateNext = Data; + dataCount = 0x00; + } + else + { + incr = 1; + } + break; + case Data: + if (word == 0x7CD215D8) + { + dataCount = 0x00; + break; + } + if (word & 0x80000000) + { + // Message word + if (func == 0x00) + { + // Numeric + msgActive = 1; + for (size_t i=1; i < 21; i++) + { + uint32_t bit = 0x80000000 & (word << i); + msgWord >>= 1; + + msgWord |= (uint8_t)(0x8*(bit != 0)); + msgPos++; + if (msgPos == 4) + { + fprintf(stderr, "%c", numericChar[msgWord]); + msgPos = 0; + msgWord = 0; + } + } + } + if (func == 0x03) + { + // Alpha numeric + msgActive = 1; + for (size_t i=1; i < 21; i++) + { + uint32_t bit = 0x80000000 & (word << i); + msgWord >>= 1; + + msgWord |= (uint8_t)(0x40*(bit != 0)); + msgPos++; + if (msgPos == 7) + { + if (msgWord != 0x04) + { + fprintf(stderr, "%c", msgWord); + msgPos = 0; + msgWord = 0; + } + } + } + } + } + else + { + if (word == 0x7A89C197) + { + // Idle + messageFinish(); + } + else + { + // Address word + messageFinish(); + uint32_t addr = (word >> 13) & 0x3FFFF; + func = (word >> 11) & 0x03; + fprintf(stderr, "%02X: [%07u](%02X): ", (uint8_t)(dataCount), 8*addr+dataCount/2, func); + } + } + dataCount++; + if (dataCount == 0x10) + { + stateNext = Sync; + dataCount = 0; +// incr = 1; + } + break; + + } + pData += incr; + remain -= incr; + state = stateNext; + numProcessed += incr; + + } + + return numProcessed; +} \ No newline at end of file diff --git a/gr-jay/lib/PocsagDecoder.hpp b/gr-jay/lib/PocsagDecoder.hpp new file mode 100644 index 0000000..21bbccd --- /dev/null +++ b/gr-jay/lib/PocsagDecoder.hpp @@ -0,0 +1,47 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ + +/* + * File: PocsagDecoder.hpp + * Author: jens + * + * Created on 11. Januar 2019, 17:20 + */ + +#ifndef POCSAGDECODER_HPP +#define POCSAGDECODER_HPP + +#include +#include +#include + +class PocsagDecoder +{ +public: + PocsagDecoder(); + PocsagDecoder(const PocsagDecoder& orig); + virtual ~PocsagDecoder(); + size_t process(uint8_t const *pData, size_t size); + +private: + enum State + { + Sync, + Data + }; + + State state = Sync; + size_t dataCount; + size_t msgPos = 0; + uint8_t msgWord = 0; + uint32_t func = 0; + bool msgActive = 0; + + void messageFinish(); +}; + +#endif /* POCSAGDECODER_HPP */ +