Fixed EPAR transmit

This commit is contained in:
furrtek 2017-09-21 09:18:17 +01:00
parent c0f51c2690
commit a6d2b766f4
15 changed files with 289 additions and 208 deletions

View file

@ -21,74 +21,56 @@
*/
#include "bht.hpp"
#include "portapack.hpp"
#include "portapack_persistent_memory.hpp"
#include <cstring>
#include <stdio.h>
std::string gen_message_ep(uint8_t city_code, size_t family_code_ep, uint32_t relay_state_A, uint32_t relay_state_B) {
size_t gen_message_ep(uint8_t city_code, size_t family_code_ep, uint32_t relay_number, uint32_t relay_state) {
size_t c;
const encoder_def_t * um3750_def;
uint8_t bit[12];
std::string ep_symbols;
char ook_bitstream[256];
char ep_message[13] = { 0 };
uint8_t bits[12];
std::string ep_fragments;
//char ep_message[13] = { 0 };
(void)relay_state_B;
// EP frame
// Repeated 2x 26 times
// Whole frame + space = 128ms, data only = 64ms
um3750_def = &encoder_defs[8];
um3750_def = &encoder_defs[ENCODER_UM3750];
// City code is bit-reversed
for (c = 0; c < 8; c++)
bit[c] = (city_code >> c) & 1;
bits[c] = (city_code >> c) & 1;
bit[8] = family_code_ep >> 1;
bit[9] = family_code_ep & 1;
bit[10] = 0; // R1 first
if (relay_state_A)
bit[11] = relay_state_A - 1;
else
bit[11] = 0;
bits[8] = (family_code_ep >> 1) & 1;
bits[9] = family_code_ep & 1;
bits[10] = relay_number & 1;
bits[11] = relay_state ? 1 : 0;
for (c = 0; c < 12; c++)
ep_message[c] = bit[c] + '0';
//text_message.set(ep_message);
// Text for display
//for (c = 0; c < 12; c++)
// ep_message[c] = bits[c] + '0';
c = 0;
for (auto ch : um3750_def->word_format) {
if (ch == 'S')
ep_symbols += um3750_def->sync;
ep_fragments += um3750_def->sync;
else
ep_symbols += um3750_def->bit_format[bit[c++]];
ep_fragments += um3750_def->bit_format[bits[c++]];
}
c = 0;
for (auto ch : ep_symbols) {
if (ch != '0')
ook_bitstream[c >> 3] |= (1 << (7 - (c & 7)));
c++;
}
return ep_message;
// Return bitstream length
return make_bitstream(ep_fragments);
}
std::string gen_message_xy(const std::string& ascii_code) {
std::string local_code = ascii_code;
uint8_t ccir_message[20];
uint8_t ccir_message[XY_TONE_COUNT];
uint8_t translate;
uint32_t c;
// Replace repeats with E code
for (c = 1; c < 20; c++)
for (c = 1; c < XY_TONE_COUNT; c++)
if (local_code[c] == local_code[c - 1]) local_code[c] = 'E';
for (c = 0; c < 20; c++) {
for (c = 0; c < XY_TONE_COUNT; c++) {
if (local_code[c] <= '9')
translate = local_code[c] - '0';
else
@ -97,7 +79,7 @@ std::string gen_message_xy(const std::string& ascii_code) {
}
// Copy for baseband
memcpy(shared_memory.bb_data.tones_data.message, ccir_message, 20);
memcpy(shared_memory.bb_data.tones_data.message, ccir_message, XY_TONE_COUNT);
// Return as text for display
return local_code;
@ -106,10 +88,8 @@ std::string gen_message_xy(const std::string& ascii_code) {
std::string gen_message_xy(size_t header_code_a, size_t header_code_b, size_t city_code, size_t family_code,
bool subfamily_wc, size_t subfamily_code, bool id_wc, size_t receiver_code,
size_t relay_state_A, size_t relay_state_B, size_t relay_state_C, size_t relay_state_D) {
uint8_t ccir_message[20];
uint8_t ccir_message[XY_TONE_COUNT];
size_t c;
// Xy CCIR frame
// Header
ccir_message[0] = (header_code_a / 10);
@ -123,19 +103,19 @@ std::string gen_message_xy(size_t header_code_a, size_t header_code_b, size_t ci
ccir_message[6] = family_code;
if (subfamily_wc)
ccir_message[7] = 10; // Wildcard
ccir_message[7] = 0xA; // Wildcard
else
ccir_message[7] = subfamily_code;
if (id_wc) {
ccir_message[8] = 10; // Wildcard
ccir_message[9] = 10; // Wildcard
ccir_message[8] = 0xA; // Wildcard
ccir_message[9] = 0xA; // Wildcard
} else {
ccir_message[8] = (receiver_code / 10);
ccir_message[9] = (receiver_code % 10);
}
ccir_message[10] = 11; // B
ccir_message[10] = 0xB;
// Relay states
ccir_message[11] = relay_state_A;
@ -143,18 +123,18 @@ std::string gen_message_xy(size_t header_code_a, size_t header_code_b, size_t ci
ccir_message[13] = relay_state_C;
ccir_message[14] = relay_state_D;
ccir_message[15] = 11; // B
ccir_message[15] = 0xB;
// End
for (c = 16; c < 20; c++)
for (c = 16; c < XY_TONE_COUNT; c++)
ccir_message[c] = 0;
// Replace repeats with E code
for (c = 1; c < 20; c++)
if (ccir_message[c] == ccir_message[c - 1]) ccir_message[c] = 14;
for (c = 1; c < XY_TONE_COUNT; c++)
if (ccir_message[c] == ccir_message[c - 1]) ccir_message[c] = 0xE;
// Copy for baseband
memcpy(shared_memory.bb_data.tones_data.message, ccir_message, 20);
memcpy(shared_memory.bb_data.tones_data.message, ccir_message, XY_TONE_COUNT);
// Return as text for display
return ccir_to_ascii(ccir_message);
@ -163,7 +143,7 @@ std::string gen_message_xy(size_t header_code_a, size_t header_code_b, size_t ci
std::string ccir_to_ascii(uint8_t * ccir) {
std::string ascii;
for (size_t c = 0; c < 20; c++) {
for (size_t c = 0; c < XY_TONE_COUNT; c++) {
if (ccir[c] > 9)
ascii += (char)(ccir[c] - 10 + 'A');
else

View file

@ -21,17 +21,16 @@
*/
#include "ui.hpp"
#include "ui_widget.hpp"
#include "ui_navigation.hpp"
#include "tonesets.hpp"
#include "encoders.hpp"
#include "portapack.hpp"
using namespace encoders;
#define XY_TONE_LENGTH ((TONES_SAMPLERATE * 0.1) - 1) // 100ms
#define XY_SILENCE (TONES_SAMPLERATE * 0.4) // 400ms
#define XY_TONE_COUNT 20
struct bht_city {
std::string name;
@ -39,9 +38,7 @@ struct bht_city {
bool recent;
};
//const rf::Frequency bht_freqs[7] = { 31325000, 31387500, 31437500, 31475000, 31687500, 31975000, 88000000 };
std::string gen_message_ep(uint8_t city_code, size_t family_code_ep, uint32_t relay_state_A, uint32_t relay_state_B);
size_t gen_message_ep(uint8_t city_code, size_t family_code_ep, uint32_t relay_state_A, uint32_t relay_state_B);
std::string gen_message_xy(const std::string& code);
std::string gen_message_xy(size_t header_code_a, size_t header_code_b, size_t city_code, size_t family_code,
bool subfamily_wc, size_t subfamily_code, bool id_wc, size_t receiver_code,

View file

@ -0,0 +1,58 @@
/*
* Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc.
* Copyright (C) 2017 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 "ui.hpp"
#include "ui_navigation.hpp"
#include "encoders.hpp"
using namespace portapack;
namespace encoders {
size_t make_bitstream(std::string& fragments) {
uint8_t byte = 0;
size_t bitstream_length = 0;
uint8_t * bitstream = shared_memory.bb_data.data;
for (auto c : fragments) {
byte <<= 1;
if (c != '0')
byte |= 1;
if ((bitstream_length & 7) == 7)
bitstream[bitstream_length >> 3] = byte;
bitstream_length++;
}
// Finish last byte if needed
size_t padding = 8 - (bitstream_length & 7);
if (padding != 8) {
byte <<= padding;
bitstream[(bitstream_length + padding - 1) >> 3] = byte;
padding++;
}
return bitstream_length;
}
} /* namespace encoders */

View file

@ -20,6 +20,7 @@
* Boston, MA 02110-1301, USA.
*/
#include <vector>
#include <cstring>
#include <string>
@ -29,7 +30,11 @@
namespace encoders {
#define ENC_TYPES_COUNT 14
#define OOK_SAMPLERATE 2280000U
#define OOK_SAMPLERATE 2280000U
#define ENCODER_UM3750 8
size_t make_bitstream(std::string& fragments);
struct encoder_def_t {
std::string name; // Encoder chip ref/name
@ -151,9 +156,9 @@ namespace encoders {
96, 32,
{ "011", "001" },
12, "SAAAAAAAAAAAA",
"1",
"001",
100000, 4,
0 // ?
(3 * 12) - 6 // Compensates for pause delay bug in proc_ook
},
// UM3758