mirror of
https://github.com/eried/portapack-mayhem.git
synced 2024-10-01 01:26:06 -04:00
Improved POCSAG receiver reliability
This commit is contained in:
parent
46482a110c
commit
98f89a84bb
@ -196,6 +196,7 @@ set(CPPSRC
|
||||
${COMMON}/ais_baseband.cpp
|
||||
${COMMON}/ais_packet.cpp
|
||||
${COMMON}/pocsag_packet.cpp
|
||||
${COMMON}/pocsag.cpp
|
||||
ais_app.cpp
|
||||
tpms_app.cpp
|
||||
pocsag_app.cpp
|
||||
@ -298,6 +299,7 @@ set(CPPWARN "-Wall -Wextra")
|
||||
# List all default C defines here, like -D_DEBUG=1
|
||||
# TODO: Switch -DCRT0_INIT_DATA depending on load from RAM or SPIFI?
|
||||
# NOTE: _RANDOM_TCC to kill a GCC 4.9.3 error with std::max argument types
|
||||
|
||||
set(DDEFS -DLPC43XX -DLPC43XX_M0 -D__NEWLIB__ -DHACKRF_ONE -DTOOLCHAIN_GCC -DTOOLCHAIN_GCC_ARM -D_RANDOM_TCC=0 -DGIT_REVISION=\"${GIT_REVISION}\")
|
||||
|
||||
# List all default ASM defines here, like -D_DEBUG=1
|
||||
|
@ -2516,6 +2516,33 @@ __/common/png_writer.cpp.s:
|
||||
cd /home/furrtek/portapack-hackrf && $(MAKE) -f firmware/application/CMakeFiles/application.elf.dir/build.make firmware/application/CMakeFiles/application.elf.dir/__/common/png_writer.cpp.s
|
||||
.PHONY : __/common/png_writer.cpp.s
|
||||
|
||||
__/common/pocsag.obj: __/common/pocsag.cpp.obj
|
||||
|
||||
.PHONY : __/common/pocsag.obj
|
||||
|
||||
# target to build an object file
|
||||
__/common/pocsag.cpp.obj:
|
||||
cd /home/furrtek/portapack-hackrf && $(MAKE) -f firmware/application/CMakeFiles/application.elf.dir/build.make firmware/application/CMakeFiles/application.elf.dir/__/common/pocsag.cpp.obj
|
||||
.PHONY : __/common/pocsag.cpp.obj
|
||||
|
||||
__/common/pocsag.i: __/common/pocsag.cpp.i
|
||||
|
||||
.PHONY : __/common/pocsag.i
|
||||
|
||||
# target to preprocess a source file
|
||||
__/common/pocsag.cpp.i:
|
||||
cd /home/furrtek/portapack-hackrf && $(MAKE) -f firmware/application/CMakeFiles/application.elf.dir/build.make firmware/application/CMakeFiles/application.elf.dir/__/common/pocsag.cpp.i
|
||||
.PHONY : __/common/pocsag.cpp.i
|
||||
|
||||
__/common/pocsag.s: __/common/pocsag.cpp.s
|
||||
|
||||
.PHONY : __/common/pocsag.s
|
||||
|
||||
# target to generate assembly for a file
|
||||
__/common/pocsag.cpp.s:
|
||||
cd /home/furrtek/portapack-hackrf && $(MAKE) -f firmware/application/CMakeFiles/application.elf.dir/build.make firmware/application/CMakeFiles/application.elf.dir/__/common/pocsag.cpp.s
|
||||
.PHONY : __/common/pocsag.cpp.s
|
||||
|
||||
__/common/pocsag_packet.obj: __/common/pocsag_packet.cpp.obj
|
||||
|
||||
.PHONY : __/common/pocsag_packet.obj
|
||||
@ -5571,6 +5598,9 @@ help:
|
||||
@echo "... __/common/png_writer.obj"
|
||||
@echo "... __/common/png_writer.i"
|
||||
@echo "... __/common/png_writer.s"
|
||||
@echo "... __/common/pocsag.obj"
|
||||
@echo "... __/common/pocsag.i"
|
||||
@echo "... __/common/pocsag.s"
|
||||
@echo "... __/common/pocsag_packet.obj"
|
||||
@echo "... __/common/pocsag_packet.i"
|
||||
@echo "... __/common/pocsag_packet.s"
|
||||
|
@ -24,7 +24,7 @@
|
||||
// Gimp image > indexed colors (16), then "xxd -i *.bmp"
|
||||
|
||||
//BUG: (fixed ?) POCSAG: Bad console scroll init
|
||||
//BUG: POCSAG misses alphanum messages, cuts them off sometimes
|
||||
//BUG: (fixed ?) POCSAG misses alphanum messages, cuts them off sometimes
|
||||
//BUG: Check AFSK transmit end, skips last bits ?
|
||||
//BUG: RDS doesn't stop baseband when stopping tx ?
|
||||
|
||||
|
@ -24,46 +24,19 @@
|
||||
|
||||
#include "baseband_api.hpp"
|
||||
|
||||
#include "audio.hpp"
|
||||
#include "portapack.hpp"
|
||||
#include "portapack_persistent_memory.hpp"
|
||||
using namespace portapack;
|
||||
using namespace pocsag;
|
||||
|
||||
#include "pocsag.hpp"
|
||||
#include "string_format.hpp"
|
||||
|
||||
#include "utility.hpp"
|
||||
|
||||
#define POCSAG_SYNC 0x7CD215D8
|
||||
#define POCSAG_IDLE 0x7A89C197
|
||||
|
||||
namespace pocsag {
|
||||
|
||||
namespace format {
|
||||
|
||||
static std::string bitrate_str(BitRate bitrate) {
|
||||
switch (bitrate) {
|
||||
case BitRate::FSK512: return "512 ";
|
||||
case BitRate::FSK1200: return "1200";
|
||||
case BitRate::FSK2400: return "2400";
|
||||
default: return "????";
|
||||
}
|
||||
}
|
||||
|
||||
static std::string flag_str(PacketFlag packetflag) {
|
||||
switch (packetflag) {
|
||||
case PacketFlag::NORMAL: return "OK";
|
||||
case PacketFlag::IDLE: return "IDLE";
|
||||
case PacketFlag::TIMED_OUT: return "TIMED OUT";
|
||||
case PacketFlag::TOO_LONG: return "TOO LONG";
|
||||
default: return "";
|
||||
}
|
||||
}
|
||||
|
||||
} /* namespace format */
|
||||
|
||||
} /* namespace pocsag */
|
||||
|
||||
void POCSAGLogger::on_packet(const pocsag::POCSAGPacket& packet, const uint32_t frequency) {
|
||||
std::string entry = pocsag::format::bitrate_str(packet.bitrate()) + " " + to_string_dec_uint(frequency) + "Hz ";
|
||||
std::string entry = pocsag::bitrate_str(packet.bitrate()) + " " + to_string_dec_uint(frequency) + "Hz ";
|
||||
|
||||
// Raw hex dump of all the codewords
|
||||
for (size_t c = 0; c < 16; c++)
|
||||
@ -118,16 +91,6 @@ POCSAGAppView::POCSAGAppView(NavigationView& nav) {
|
||||
&console
|
||||
});
|
||||
|
||||
radio::enable({
|
||||
tuning_frequency(),
|
||||
sampling_rate,
|
||||
baseband_bandwidth,
|
||||
rf::Direction::Receive,
|
||||
receiver_model.rf_amp(),
|
||||
static_cast<int8_t>(receiver_model.lna()),
|
||||
static_cast<int8_t>(receiver_model.vga())
|
||||
});
|
||||
|
||||
check_log.set_value(logging);
|
||||
check_log.on_select = [this](Checkbox&, bool v) {
|
||||
logging = v;
|
||||
@ -153,11 +116,20 @@ POCSAGAppView::POCSAGAppView(NavigationView& nav) {
|
||||
logger = std::make_unique<POCSAGLogger>();
|
||||
if (logger) logger->append("pocsag.txt");
|
||||
|
||||
receiver_model.set_sampling_rate(3072000);
|
||||
receiver_model.set_baseband_bandwidth(1750000);
|
||||
receiver_model.enable();
|
||||
|
||||
const auto new_volume = volume_t::decibel(60 - 99) + audio::headphone::volume_range().max;
|
||||
receiver_model.set_headphone_volume(new_volume);
|
||||
audio::output::start();
|
||||
|
||||
baseband::set_pocsag(pocsag::BitRate::FSK1200);
|
||||
}
|
||||
|
||||
POCSAGAppView::~POCSAGAppView() {
|
||||
radio::disable();
|
||||
audio::output::stop();
|
||||
receiver_model.disable();
|
||||
baseband::shutdown();
|
||||
}
|
||||
|
||||
@ -165,89 +137,63 @@ void POCSAGAppView::focus() {
|
||||
options_freq.focus();
|
||||
}
|
||||
|
||||
// Useless ?
|
||||
void POCSAGAppView::set_parent_rect(const Rect new_parent_rect) {
|
||||
View::set_parent_rect(new_parent_rect);
|
||||
}
|
||||
|
||||
void POCSAGAppView::on_packet(const POCSAGPacketMessage * message) {
|
||||
bool eom = false;
|
||||
uint32_t codeword;
|
||||
std::string alphanum_text = "";
|
||||
char ascii_char;
|
||||
|
||||
for (size_t i = 0; i < 16; i++) {
|
||||
codeword = message->packet[i];
|
||||
|
||||
if (codeword & 0x80000000U) {
|
||||
// Message
|
||||
ascii_data |= ((codeword >> 11) & 0xFFFFF);
|
||||
ascii_idx += 20;
|
||||
|
||||
// Raw 20 bits to 7 bit reversed ASCII
|
||||
while (ascii_idx >= 7) {
|
||||
ascii_idx -= 7;
|
||||
ascii_char = (ascii_data >> ascii_idx) & 0x7F;
|
||||
|
||||
// Bottom's up
|
||||
ascii_char = (ascii_char & 0xF0) >> 4 | (ascii_char & 0x0F) << 4; // 01234567 -> 45670123
|
||||
ascii_char = (ascii_char & 0xCC) >> 2 | (ascii_char & 0x33) << 2; // 45670123 -> 67452301
|
||||
ascii_char = (ascii_char & 0xAA) >> 2 | (ascii_char & 0x55); // 67452301 -> *7654321
|
||||
|
||||
// Translate non-printable chars
|
||||
if ((ascii_char < 32) || (ascii_char > 126))
|
||||
output_text += "[" + to_string_dec_uint(ascii_char) + "]";
|
||||
else
|
||||
output_text += ascii_char;
|
||||
|
||||
}
|
||||
ascii_data = ascii_data << 20;
|
||||
} else {
|
||||
// Address
|
||||
if ((codeword == POCSAG_IDLE) || (codeword == POCSAG_SYNC)) {
|
||||
eom = true;
|
||||
} else {
|
||||
if ((codeword) && (!address)) {
|
||||
// Set address if none set and codeword is valid
|
||||
function = (codeword >> 11) & 3;
|
||||
address = ((codeword >> 10) & 0x1FFFF8) | ((codeword >> 1) & 7);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Log raw data
|
||||
if (logger && logging) logger->on_packet(message->packet, target_frequency());
|
||||
|
||||
if (eom) {
|
||||
std::string console_info;
|
||||
|
||||
console_info = to_string_time(message->packet.timestamp()) + " ";
|
||||
|
||||
if (address || function) {
|
||||
console_info += pocsag::format::bitrate_str( message->packet.bitrate()) + " ";
|
||||
console_info += pocsag::format::flag_str(message->packet.flag()) + " ";
|
||||
console_info += "ADDR:" + to_string_dec_uint(address) + " F:" + to_string_dec_uint(function);
|
||||
|
||||
console.writeln(console_info);
|
||||
|
||||
if (output_text != "") console.writeln("Alpha:" + output_text);
|
||||
|
||||
if (logger) logger->on_decoded(message->packet, console_info, output_text);
|
||||
|
||||
} else {
|
||||
console_info += pocsag::format::bitrate_str(message->packet.bitrate()) + " ";
|
||||
console_info += pocsag::format::flag_str(message->packet.flag());
|
||||
|
||||
console.writeln(console_info);
|
||||
if (message->packet.flag() != NORMAL) {
|
||||
console.writeln(
|
||||
"RX ERROR: " + pocsag::flag_str(message->packet.flag()) +
|
||||
" Codewords: " + to_string_dec_uint(message->packet[0])
|
||||
);
|
||||
}
|
||||
|
||||
output_text = "";
|
||||
ascii_idx = 0;
|
||||
ascii_data = 0;
|
||||
batch_cnt = 0;
|
||||
address = 0;
|
||||
function = 0;
|
||||
bool result = decode_batch(message->packet, &pocsag_state);
|
||||
|
||||
if (result) {
|
||||
std::string console_info;
|
||||
|
||||
if (pocsag_state.out_type == ADDRESS) {
|
||||
// Address only
|
||||
console_info = to_string_time(message->packet.timestamp()) + " ";
|
||||
console_info += pocsag::bitrate_str(message->packet.bitrate()) + " ";
|
||||
console_info += "ADDR:" + to_string_dec_uint(pocsag_state.address);
|
||||
console_info += " F" + to_string_dec_uint(pocsag_state.function);
|
||||
|
||||
console.writeln(console_info);
|
||||
|
||||
if (logger) logger->on_decoded(message->packet, console_info, pocsag_state.output);
|
||||
|
||||
last_address = pocsag_state.address;
|
||||
} else if (pocsag_state.out_type == MESSAGE) {
|
||||
if (pocsag_state.address != last_address) {
|
||||
// New message
|
||||
console_info = to_string_time(message->packet.timestamp()) + " ";
|
||||
console_info += pocsag::bitrate_str( message->packet.bitrate()) + " ";
|
||||
console_info += "ADDR:" + to_string_dec_uint(pocsag_state.address);
|
||||
console_info += " F" + to_string_dec_uint(pocsag_state.function);
|
||||
|
||||
console.writeln(console_info);
|
||||
|
||||
console.writeln("Alpha:" + pocsag_state.output);
|
||||
|
||||
if (logger) logger->on_decoded(message->packet, console_info, pocsag_state.output);
|
||||
|
||||
last_address = pocsag_state.address;
|
||||
} else {
|
||||
batch_cnt++;
|
||||
// Message continues...
|
||||
}
|
||||
} else if (pocsag_state.out_type == EMPTY)
|
||||
console.writeln("-");
|
||||
|
||||
console.write(pocsag_state.output);
|
||||
}
|
||||
}
|
||||
|
||||
@ -267,15 +213,11 @@ void POCSAGAppView::on_band_changed(const uint32_t new_band_frequency) {
|
||||
|
||||
void POCSAGAppView::set_target_frequency(const uint32_t new_value) {
|
||||
target_frequency_ = new_value;
|
||||
radio::set_tuning_frequency(tuning_frequency());
|
||||
receiver_model.set_tuning_frequency(new_value);
|
||||
}
|
||||
|
||||
uint32_t POCSAGAppView::target_frequency() const {
|
||||
return target_frequency_;
|
||||
}
|
||||
|
||||
uint32_t POCSAGAppView::tuning_frequency() const {
|
||||
return target_frequency() - (sampling_rate / 4);
|
||||
}
|
||||
|
||||
} /* namespace ui */
|
||||
|
@ -33,6 +33,7 @@
|
||||
|
||||
#include "log_file.hpp"
|
||||
|
||||
#include "pocsag.hpp"
|
||||
#include "pocsag_packet.hpp"
|
||||
|
||||
class POCSAGLogger {
|
||||
@ -66,15 +67,11 @@ public:
|
||||
private:
|
||||
static constexpr uint32_t initial_target_frequency = 466175000;
|
||||
static constexpr uint32_t sampling_rate = 3072000;
|
||||
static constexpr uint32_t baseband_bandwidth = 1750000;
|
||||
//static constexpr uint32_t baseband_bandwidth = 1750000;
|
||||
|
||||
bool logging { false };
|
||||
uint32_t batch_cnt = 0;
|
||||
uint32_t address { 0 };
|
||||
uint32_t function { 0 };
|
||||
uint32_t ascii_data { 0 };
|
||||
uint32_t ascii_idx { 0 };
|
||||
std::string output_text = "";
|
||||
uint32_t last_address = 0xFFFFFFFF;
|
||||
pocsag::POCSAGState pocsag_state { };
|
||||
|
||||
MessageHandlerRegistration message_handler_packet {
|
||||
Message::ID::POCSAGPacket,
|
||||
@ -158,8 +155,6 @@ private:
|
||||
|
||||
uint32_t target_frequency() const;
|
||||
void set_target_frequency(const uint32_t new_value);
|
||||
|
||||
uint32_t tuning_frequency() const;
|
||||
};
|
||||
|
||||
} /* namespace ui */
|
||||
|
@ -22,8 +22,6 @@
|
||||
|
||||
#include "proc_nfm_audio.hpp"
|
||||
|
||||
#include "audio_output.hpp"
|
||||
|
||||
#include "event_m4.hpp"
|
||||
|
||||
#include <cstdint>
|
||||
|
@ -29,13 +29,6 @@
|
||||
#include <cstdint>
|
||||
#include <cstddef>
|
||||
|
||||
#define POCSAG_AUDIO_RATE 24000
|
||||
|
||||
#define POCSAG_SYNC 0x7CD215D8
|
||||
#define POCSAG_IDLE 0x7A89C197
|
||||
#define POCSAG_PREAMBLE_LENGTH 576
|
||||
#define POCSAG_BATCH_LENGTH (9 * 32)
|
||||
|
||||
void POCSAGProcessor::execute(const buffer_c8_t& buffer) {
|
||||
// This is called at 1500Hz
|
||||
|
||||
@ -46,12 +39,11 @@ void POCSAGProcessor::execute(const buffer_c8_t& buffer) {
|
||||
const auto decim_1_out = decim_1.execute(decim_0_out, dst_buffer);
|
||||
const auto channel_out = channel_filter.execute(decim_1_out, dst_buffer);
|
||||
auto audio = demod.execute(channel_out, audio_buffer);
|
||||
//audio_output.write(audio);
|
||||
|
||||
// End up with 32 samples ?
|
||||
for (uint32_t c = 0; c < 16; c++) {
|
||||
|
||||
const int32_t sample_int = audio.p[c] * 32768.0f;
|
||||
//const int32_t audio_sample = audio.p[c] * 32768.0f;
|
||||
const int32_t audio_sample = __SSAT(sample_int, 16);
|
||||
|
||||
slicer_sr <<= 1;
|
||||
@ -84,23 +76,22 @@ void POCSAGProcessor::execute(const buffer_c8_t& buffer) {
|
||||
break;
|
||||
|
||||
case PREAMBLE:
|
||||
if (sync_timeout < POCSAG_PREAMBLE_LENGTH) {
|
||||
if (sync_timeout < POCSAG_TIMEOUT) {
|
||||
sync_timeout++;
|
||||
|
||||
if (rx_data == POCSAG_SYNC) {
|
||||
packet.clear();
|
||||
frame_counter = 0;
|
||||
codeword_count = 0;
|
||||
rx_bit = 0;
|
||||
msg_timeout = 0;
|
||||
last_rx_data = rx_data;
|
||||
rx_state = SYNC;
|
||||
} else if (rx_data == POCSAG_IDLE) {
|
||||
push_packet(pocsag::PacketFlag::IDLE);
|
||||
} /*else if (rx_data == POCSAG_IDLE) {
|
||||
rx_state = WAITING;
|
||||
}
|
||||
}*/
|
||||
|
||||
} else {
|
||||
rx_state = WAITING; // Timed out: abort
|
||||
push_packet(pocsag::PacketFlag::TOO_LONG); // DEBUG
|
||||
}
|
||||
break;
|
||||
|
||||
@ -116,29 +107,18 @@ void POCSAGProcessor::execute(const buffer_c8_t& buffer) {
|
||||
|
||||
//pocsag_brute_repair(&s->l2.pocsag, &rx_data);
|
||||
|
||||
packet.set(frame_counter, rx_data);
|
||||
packet.set(codeword_count, rx_data);
|
||||
|
||||
if ((rx_data == POCSAG_IDLE) && (!(last_rx_data & 0x80000000))) {
|
||||
// SYNC then IDLE always means end of message ?
|
||||
if (frame_counter)
|
||||
if (codeword_count < 15) {
|
||||
codeword_count++;
|
||||
} else {
|
||||
push_packet(pocsag::PacketFlag::NORMAL);
|
||||
else
|
||||
push_packet(pocsag::PacketFlag::IDLE);
|
||||
rx_state = WAITING;
|
||||
} else {
|
||||
if (frame_counter < 15) {
|
||||
frame_counter++;
|
||||
} else {
|
||||
// More than 17-1 codewords
|
||||
push_packet(pocsag::PacketFlag::TOO_LONG);
|
||||
rx_state = WAITING;
|
||||
}
|
||||
}
|
||||
|
||||
last_rx_data = rx_data;
|
||||
}
|
||||
} else {
|
||||
// Timed out (no end of message received)
|
||||
packet.set(0, codeword_count); // DEBUG
|
||||
push_packet(pocsag::PacketFlag::TIMED_OUT);
|
||||
rx_state = WAITING;
|
||||
}
|
||||
@ -180,6 +160,7 @@ void POCSAGProcessor::configure(const POCSAGConfigureMessage& message) {
|
||||
decim_1.configure(taps_11k0_decim_1.taps, 131072);
|
||||
channel_filter.configure(taps_11k0_channel.taps, 2);
|
||||
demod.configure(demod_input_fs, 4500);
|
||||
//audio_output.configure(false);
|
||||
|
||||
bitrate = message.bitrate;
|
||||
sphase_delta = 0x10000u * bitrate / POCSAG_AUDIO_RATE;
|
||||
|
@ -34,7 +34,9 @@
|
||||
|
||||
#include "pocsag_packet.hpp"
|
||||
|
||||
#include "pocsag.hpp"
|
||||
#include "message.hpp"
|
||||
#include "audio_output.hpp"
|
||||
#include "portapack_shared_memory.hpp"
|
||||
|
||||
#include <cstdint>
|
||||
@ -78,6 +80,8 @@ private:
|
||||
dsp::decimate::FIRAndDecimateComplex channel_filter { };
|
||||
dsp::demodulate::FM demod { };
|
||||
|
||||
//AudioOutput audio_output { };
|
||||
|
||||
uint32_t sync_timeout { 0 };
|
||||
uint32_t msg_timeout { 0 };
|
||||
|
||||
@ -87,12 +91,11 @@ private:
|
||||
uint32_t sphase_delta_half { 0 };
|
||||
uint32_t sphase_delta_eighth { 0 };
|
||||
uint32_t rx_data { 0 };
|
||||
uint32_t last_rx_data { 0 };
|
||||
uint32_t rx_bit { 0 };
|
||||
bool configured = false;
|
||||
rx_states rx_state { WAITING };
|
||||
pocsag::BitRate bitrate { pocsag::BitRate::FSK1200 };
|
||||
uint32_t frame_counter { 0 };
|
||||
uint32_t codeword_count { 0 };
|
||||
pocsag::POCSAGPacket packet { };
|
||||
|
||||
void push_packet(pocsag::PacketFlag flag);
|
||||
|
124
firmware/common/pocsag.cpp
Normal file
124
firmware/common/pocsag.cpp
Normal file
@ -0,0 +1,124 @@
|
||||
/*
|
||||
* Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc.
|
||||
* Copyright (C) 2016 Furrtek
|
||||
*
|
||||
* This file is part of PortaPack.
|
||||
*
|
||||
* 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; either version 2, 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 for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, Inc., 51 Franklin Street,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "pocsag.hpp"
|
||||
|
||||
#include "baseband_api.hpp"
|
||||
|
||||
#include "portapack.hpp"
|
||||
#include "portapack_persistent_memory.hpp"
|
||||
using namespace portapack;
|
||||
|
||||
#include "string_format.hpp"
|
||||
|
||||
#include "utility.hpp"
|
||||
|
||||
namespace pocsag {
|
||||
|
||||
std::string bitrate_str(BitRate bitrate) {
|
||||
switch (bitrate) {
|
||||
case BitRate::FSK512: return "512 ";
|
||||
case BitRate::FSK1200: return "1200";
|
||||
case BitRate::FSK2400: return "2400";
|
||||
default: return "????";
|
||||
}
|
||||
}
|
||||
|
||||
std::string flag_str(PacketFlag packetflag) {
|
||||
switch (packetflag) {
|
||||
case PacketFlag::NORMAL: return "OK";
|
||||
case PacketFlag::IDLE: return "IDLE";
|
||||
case PacketFlag::TIMED_OUT: return "TIMED OUT";
|
||||
case PacketFlag::TOO_LONG: return "TOO LONG";
|
||||
default: return "";
|
||||
}
|
||||
}
|
||||
|
||||
bool decode_batch(const POCSAGPacket& batch, POCSAGState * const state) {
|
||||
uint32_t codeword;
|
||||
char ascii_char;
|
||||
std::string output_text = "";
|
||||
|
||||
state->out_type = EMPTY;
|
||||
|
||||
// For each codeword...
|
||||
for (size_t i = 0; i < 16; i++) {
|
||||
codeword = batch[i];
|
||||
|
||||
if (!(codeword & 0x80000000U)) {
|
||||
// Address codeword
|
||||
if (state->mode == STATE_CLEAR) {
|
||||
if (codeword != POCSAG_IDLE) {
|
||||
state->function = (codeword >> 11) & 3;
|
||||
state->address = (codeword >> 10) & 0x1FFFF8U; // 18 MSBs are transmitted
|
||||
state->mode = STATE_HAVE_ADDRESS;
|
||||
state->out_type = ADDRESS;
|
||||
|
||||
state->ascii_idx = 0;
|
||||
state->ascii_data = 0;
|
||||
}
|
||||
} else {
|
||||
state->mode = STATE_CLEAR; // New address = new message
|
||||
}
|
||||
} else {
|
||||
// Message codeword
|
||||
if (state->mode == STATE_HAVE_ADDRESS) {
|
||||
// First message codeword: complete address
|
||||
state->address |= (i >> 1); // Add in the 3 LSBs (frame #)
|
||||
state->mode = STATE_GETTING_MSG;
|
||||
}
|
||||
|
||||
state->out_type = MESSAGE;
|
||||
|
||||
state->ascii_data |= ((codeword >> 11) & 0xFFFFF); // Get 20 message bits
|
||||
state->ascii_idx += 20;
|
||||
|
||||
// Raw 20 bits to 7 bit reversed ASCII
|
||||
while (state->ascii_idx >= 7) {
|
||||
state->ascii_idx -= 7;
|
||||
ascii_char = ((state->ascii_data) >> (state->ascii_idx)) & 0x7F;
|
||||
|
||||
// Bottom's up
|
||||
ascii_char = (ascii_char & 0xF0) >> 4 | (ascii_char & 0x0F) << 4; // 01234567 -> 45670123
|
||||
ascii_char = (ascii_char & 0xCC) >> 2 | (ascii_char & 0x33) << 2; // 45670123 -> 67452301
|
||||
ascii_char = (ascii_char & 0xAA) >> 2 | (ascii_char & 0x55); // 67452301 -> *7654321
|
||||
|
||||
// Translate non-printable chars
|
||||
if ((ascii_char < 32) || (ascii_char > 126))
|
||||
output_text += "[" + to_string_dec_uint(ascii_char) + "]";
|
||||
else
|
||||
output_text += ascii_char;
|
||||
}
|
||||
|
||||
state->ascii_data <<= 20; // Remaining bits are for next time...
|
||||
}
|
||||
}
|
||||
|
||||
state->output = output_text;
|
||||
|
||||
if (state->mode == STATE_HAVE_ADDRESS)
|
||||
state->mode = STATE_CLEAR;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
} /* namespace pocsag */
|
65
firmware/common/pocsag.hpp
Normal file
65
firmware/common/pocsag.hpp
Normal file
@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc.
|
||||
* Copyright (C) 2016 Furrtek
|
||||
*
|
||||
* This file is part of PortaPack.
|
||||
*
|
||||
* 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; either version 2, 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 for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, Inc., 51 Franklin Street,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef __POCSAG_H__
|
||||
#define __POCSAG_H__
|
||||
|
||||
#define POCSAG_TIMEOUT (576 * 2) // Preamble length * 2
|
||||
#define POCSAG_SYNC 0x7CD215D8
|
||||
#define POCSAG_IDLE 0x7A89C197
|
||||
#define POCSAG_AUDIO_RATE 24000
|
||||
#define POCSAG_BATCH_LENGTH (17 * 32)
|
||||
|
||||
#include "pocsag_packet.hpp"
|
||||
|
||||
namespace pocsag {
|
||||
|
||||
enum Mode : uint32_t {
|
||||
STATE_CLEAR,
|
||||
STATE_HAVE_ADDRESS,
|
||||
STATE_GETTING_MSG
|
||||
};
|
||||
|
||||
enum OutputType : uint32_t {
|
||||
EMPTY,
|
||||
ADDRESS,
|
||||
MESSAGE
|
||||
};
|
||||
|
||||
struct POCSAGState {
|
||||
uint32_t function;
|
||||
uint32_t address;
|
||||
Mode mode = STATE_CLEAR;
|
||||
OutputType out_type = EMPTY;
|
||||
uint32_t ascii_data;
|
||||
uint32_t ascii_idx;
|
||||
std::string output;
|
||||
};
|
||||
|
||||
std::string bitrate_str(BitRate bitrate);
|
||||
std::string flag_str(PacketFlag packetflag);
|
||||
|
||||
bool decode_batch(const POCSAGPacket& batch, POCSAGState * const state);
|
||||
|
||||
} /* namespace pocsag */
|
||||
|
||||
#endif/*__POCSAG_H__*/
|
Binary file not shown.
Loading…
Reference in New Issue
Block a user