2017-02-05 15:57:20 -05:00
|
|
|
/*
|
|
|
|
* 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__
|
|
|
|
|
2017-02-06 15:32:33 -05:00
|
|
|
#define POCSAG_PREAMBLE_LENGTH 576
|
2023-05-18 16:16:05 -04:00
|
|
|
#define POCSAG_TIMEOUT (576 * 2) // Preamble length * 2
|
2017-02-06 15:32:33 -05:00
|
|
|
#define POCSAG_SYNCWORD 0x7CD215D8
|
|
|
|
#define POCSAG_IDLEWORD 0x7A89C197
|
2017-02-05 15:57:20 -05:00
|
|
|
#define POCSAG_AUDIO_RATE 24000
|
|
|
|
#define POCSAG_BATCH_LENGTH (17 * 32)
|
|
|
|
|
|
|
|
#include "pocsag_packet.hpp"
|
2017-02-06 15:32:33 -05:00
|
|
|
#include "bch_code.hpp"
|
2017-02-05 15:57:20 -05:00
|
|
|
|
|
|
|
namespace pocsag {
|
|
|
|
|
2023-08-26 14:43:34 -04:00
|
|
|
// TODO: these enums suck, make a better decode_batch
|
2017-02-06 15:32:33 -05:00
|
|
|
|
2017-02-05 15:57:20 -05:00
|
|
|
enum Mode : uint32_t {
|
2023-05-18 16:16:05 -04:00
|
|
|
STATE_CLEAR,
|
|
|
|
STATE_HAVE_ADDRESS,
|
|
|
|
STATE_GETTING_MSG
|
2017-02-05 15:57:20 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
enum OutputType : uint32_t {
|
2023-05-18 16:16:05 -04:00
|
|
|
EMPTY,
|
2023-08-26 14:43:34 -04:00
|
|
|
IDLE,
|
2023-05-18 16:16:05 -04:00
|
|
|
ADDRESS,
|
|
|
|
MESSAGE
|
2017-02-05 15:57:20 -05:00
|
|
|
};
|
|
|
|
|
2017-02-07 20:19:29 -05:00
|
|
|
enum MessageType : uint32_t {
|
2023-05-18 16:16:05 -04:00
|
|
|
ADDRESS_ONLY,
|
|
|
|
NUMERIC_ONLY,
|
|
|
|
ALPHANUMERIC
|
2017-02-07 20:19:29 -05:00
|
|
|
};
|
|
|
|
|
2023-08-27 18:56:40 -04:00
|
|
|
/* Holds error correction arrays. This allows the arrays to
|
|
|
|
* be freed when POCSAG is not running, saving ~4kb of RAM. */
|
|
|
|
class EccContainer {
|
|
|
|
public:
|
|
|
|
EccContainer();
|
|
|
|
|
|
|
|
EccContainer(const EccContainer&) = delete;
|
|
|
|
EccContainer(EccContainer&&) = delete;
|
|
|
|
EccContainer& operator=(const EccContainer&) = delete;
|
|
|
|
EccContainer& operator=(EccContainer&&) = delete;
|
|
|
|
|
|
|
|
int error_correct(uint32_t& val);
|
|
|
|
|
|
|
|
private:
|
|
|
|
void setup_ecc();
|
|
|
|
|
|
|
|
/* error correction sequence */
|
|
|
|
uint32_t ecs[32];
|
|
|
|
uint32_t bch[1025];
|
|
|
|
};
|
|
|
|
|
2017-02-05 15:57:20 -05:00
|
|
|
struct POCSAGState {
|
2023-08-27 18:56:40 -04:00
|
|
|
EccContainer* ecc = nullptr;
|
|
|
|
uint8_t codeword_index = 0;
|
|
|
|
uint32_t function = 0;
|
|
|
|
uint32_t address = 0;
|
2023-05-18 16:16:05 -04:00
|
|
|
Mode mode = STATE_CLEAR;
|
|
|
|
OutputType out_type = EMPTY;
|
2023-08-27 18:56:40 -04:00
|
|
|
uint32_t ascii_data = 0;
|
|
|
|
uint32_t ascii_idx = 0;
|
|
|
|
uint32_t errors = 0;
|
|
|
|
std::string output{};
|
2017-02-05 15:57:20 -05:00
|
|
|
};
|
|
|
|
|
2021-02-14 13:52:56 -05:00
|
|
|
const pocsag::BitRate pocsag_bitrates[4] = {
|
2023-05-18 16:16:05 -04:00
|
|
|
pocsag::BitRate::FSK512,
|
|
|
|
pocsag::BitRate::FSK1200,
|
|
|
|
pocsag::BitRate::FSK2400,
|
2023-08-27 18:56:40 -04:00
|
|
|
pocsag::BitRate::FSK3200,
|
|
|
|
};
|
2017-02-07 14:54:18 -05:00
|
|
|
|
2017-02-05 15:57:20 -05:00
|
|
|
std::string bitrate_str(BitRate bitrate);
|
|
|
|
std::string flag_str(PacketFlag packetflag);
|
|
|
|
|
2023-05-18 16:16:05 -04:00
|
|
|
void insert_BCH(BCHCode& BCH_code, uint32_t* codeword);
|
2017-02-07 20:19:29 -05:00
|
|
|
uint32_t get_digit_code(char code);
|
2023-05-18 16:16:05 -04:00
|
|
|
void pocsag_encode(const MessageType type, BCHCode& BCH_code, const uint32_t function, const std::string message, const uint32_t address, std::vector<uint32_t>& codewords);
|
2023-08-26 14:43:34 -04:00
|
|
|
|
|
|
|
// Returns true if the batch has more to process.
|
|
|
|
bool pocsag_decode_batch(const POCSAGPacket& batch, POCSAGState& state);
|
2017-02-05 15:57:20 -05:00
|
|
|
|
|
|
|
} /* namespace pocsag */
|
|
|
|
|
2023-05-18 16:16:05 -04:00
|
|
|
#endif /*__POCSAG_H__*/
|