2015-08-28 18:50:42 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc.
|
|
|
|
*
|
|
|
|
* 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_rds.hpp"
|
|
|
|
#include "ui_lcr.hpp"
|
|
|
|
#include "ui_receiver.hpp"
|
2015-09-04 18:37:27 +00:00
|
|
|
#include "ui_afsksetup.hpp"
|
|
|
|
#include "ui_debug.hpp"
|
2015-08-28 18:50:42 +00:00
|
|
|
|
|
|
|
#include "ch.h"
|
|
|
|
|
|
|
|
#include "ff.h"
|
|
|
|
#include "hackrf_gpio.hpp"
|
|
|
|
#include "portapack.hpp"
|
|
|
|
#include "radio.hpp"
|
|
|
|
|
|
|
|
#include "hackrf_hal.hpp"
|
|
|
|
#include "portapack_shared_memory.hpp"
|
2015-09-03 04:34:00 +00:00
|
|
|
#include "portapack_persistent_memory.hpp"
|
2015-08-28 18:50:42 +00:00
|
|
|
|
|
|
|
#include <cstring>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
using namespace hackrf::one;
|
|
|
|
|
|
|
|
namespace ui {
|
|
|
|
|
|
|
|
void LCRView::focus() {
|
2015-09-05 18:17:43 +00:00
|
|
|
button_setrgsb.focus();
|
2015-08-28 18:50:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
LCRView::~LCRView() {
|
|
|
|
transmitter_model.disable();
|
|
|
|
}
|
|
|
|
|
2015-09-04 18:37:27 +00:00
|
|
|
void LCRView::make_frame() {
|
2015-09-05 18:17:43 +00:00
|
|
|
char eom[3] = { 3, 0, 0 }; // EOM and space for checksum
|
|
|
|
uint8_t i, pm;
|
2015-09-03 04:34:00 +00:00
|
|
|
uint16_t dp;
|
|
|
|
uint8_t cp, pp, cur_byte, new_byte;
|
2015-08-28 18:50:42 +00:00
|
|
|
|
2015-09-05 18:17:43 +00:00
|
|
|
// Pad litterals right to 7 chars (not required ?)
|
2015-09-04 18:37:27 +00:00
|
|
|
for (i = 0; i < 5; i++) {
|
2015-08-28 18:50:42 +00:00
|
|
|
while (strlen(litteral[i]) < 7) {
|
|
|
|
strcat(litteral[i], " ");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-05 18:17:43 +00:00
|
|
|
// Make LCR frame
|
2015-08-28 18:50:42 +00:00
|
|
|
memset(lcrframe, 0, 256);
|
2015-09-05 18:17:43 +00:00
|
|
|
lcrframe[0] = 127; // Modem sync
|
2015-08-28 18:50:42 +00:00
|
|
|
lcrframe[1] = 127;
|
|
|
|
lcrframe[2] = 127;
|
|
|
|
lcrframe[3] = 127;
|
|
|
|
lcrframe[4] = 127;
|
2015-09-03 04:34:00 +00:00
|
|
|
lcrframe[5] = 127;
|
|
|
|
lcrframe[6] = 127;
|
2015-09-05 18:17:43 +00:00
|
|
|
lcrframe[7] = 15; // SOM
|
2015-08-28 18:50:42 +00:00
|
|
|
strcat(lcrframe, rgsb);
|
2015-09-05 18:17:43 +00:00
|
|
|
strcat(lcrframe, "PA ");
|
|
|
|
if (checkbox_am_a.value() == true) {
|
|
|
|
strcat(lcrframe, "AM=1 AF=\"");
|
|
|
|
strcat(lcrframe, litteral[0]);
|
|
|
|
strcat(lcrframe, "\" CL=0 ");
|
|
|
|
}
|
|
|
|
if (checkbox_am_b.value() == true) {
|
|
|
|
strcat(lcrframe, "AM=2 AF=\"");
|
|
|
|
strcat(lcrframe, litteral[1]);
|
|
|
|
strcat(lcrframe, "\" CL=0 ");
|
|
|
|
}
|
|
|
|
if (checkbox_am_c.value() == true) {
|
|
|
|
strcat(lcrframe, "AM=3 AF=\"");
|
|
|
|
strcat(lcrframe, litteral[2]);
|
|
|
|
strcat(lcrframe, "\" CL=0 ");
|
|
|
|
}
|
|
|
|
if (checkbox_am_d.value() == true) {
|
|
|
|
strcat(lcrframe, "AM=4 AF=\"");
|
|
|
|
strcat(lcrframe, litteral[3]);
|
|
|
|
strcat(lcrframe, "\" CL=0 ");
|
|
|
|
}
|
|
|
|
if (checkbox_am_e.value() == true) {
|
|
|
|
strcat(lcrframe, "AM=5 AF=\"");
|
|
|
|
strcat(lcrframe, litteral[4]);
|
|
|
|
strcat(lcrframe, "\" CL=0 ");
|
|
|
|
}
|
2015-09-10 18:36:39 +00:00
|
|
|
strcat(lcrframe, "EC=A SAB=0");
|
2015-08-28 18:50:42 +00:00
|
|
|
|
2015-09-04 18:37:27 +00:00
|
|
|
memcpy(lcrstring, lcrframe, 256);
|
|
|
|
|
2015-08-28 18:50:42 +00:00
|
|
|
//Checksum
|
2015-09-04 18:37:27 +00:00
|
|
|
checksum = 0;
|
2015-09-03 04:34:00 +00:00
|
|
|
i = 7;
|
2015-08-28 18:50:42 +00:00
|
|
|
while (lcrframe[i]) {
|
|
|
|
checksum ^= lcrframe[i];
|
|
|
|
i++;
|
|
|
|
}
|
2015-09-05 18:17:43 +00:00
|
|
|
checksum ^= eom[0]; // EOM
|
2015-08-28 18:50:42 +00:00
|
|
|
checksum &= 0x7F;
|
|
|
|
eom[1] = checksum;
|
|
|
|
|
|
|
|
strcat(lcrframe, eom);
|
|
|
|
|
2015-09-10 18:36:39 +00:00
|
|
|
//if (persistent_memory::afsk_config() & 2)
|
2015-09-05 18:17:43 +00:00
|
|
|
pm = 0; // Even parity
|
2015-09-10 18:36:39 +00:00
|
|
|
//else
|
|
|
|
// pm = 1; // Odd parity
|
2015-09-05 18:17:43 +00:00
|
|
|
|
2015-09-10 18:36:39 +00:00
|
|
|
//if (persistent_memory::afsk_config() & 1) {
|
2015-09-05 18:17:43 +00:00
|
|
|
// LSB first
|
|
|
|
for (dp=0;dp<strlen(lcrframe);dp++) {
|
|
|
|
pp = pm;
|
|
|
|
new_byte = 0;
|
|
|
|
cur_byte = lcrframe[dp];
|
|
|
|
for (cp=0;cp<7;cp++) {
|
|
|
|
if ((cur_byte>>cp)&1) pp++;
|
2015-09-10 18:36:39 +00:00
|
|
|
new_byte |= (((cur_byte>>cp)&1)<<(7-cp));
|
2015-09-05 18:17:43 +00:00
|
|
|
}
|
2015-09-10 18:36:39 +00:00
|
|
|
lcrframe_f[dp] = new_byte|(pp&1);
|
2015-09-05 18:17:43 +00:00
|
|
|
}
|
2015-09-10 18:36:39 +00:00
|
|
|
/*} else {
|
2015-09-05 18:17:43 +00:00
|
|
|
// MSB first
|
|
|
|
for (dp=0;dp<strlen(lcrframe);dp++) {
|
|
|
|
pp = pm;
|
|
|
|
cur_byte = lcrframe[dp];
|
|
|
|
for (cp=0;cp<7;cp++) {
|
|
|
|
if ((cur_byte>>cp)&1) pp++;
|
|
|
|
}
|
2015-09-10 18:36:39 +00:00
|
|
|
lcrframe_f[dp] = (cur_byte<<1)|(pp&1);
|
2015-09-03 04:34:00 +00:00
|
|
|
}
|
2015-09-10 18:36:39 +00:00
|
|
|
}*/
|
|
|
|
|
|
|
|
lcrframe_f[dp] = 0;
|
2015-09-04 18:37:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void LCRView::paint(Painter& painter) {
|
2015-09-10 18:36:39 +00:00
|
|
|
uint8_t i;
|
|
|
|
|
2015-09-04 18:37:27 +00:00
|
|
|
static constexpr Style style_orange {
|
|
|
|
.font = font::fixed_8x16,
|
|
|
|
.background = Color::black(),
|
|
|
|
.foreground = Color::orange(),
|
|
|
|
};
|
|
|
|
|
|
|
|
Point offset = {
|
2015-09-05 18:17:43 +00:00
|
|
|
static_cast<Coord>(104),
|
2015-09-04 18:37:27 +00:00
|
|
|
static_cast<Coord>(72)
|
|
|
|
};
|
2015-09-03 04:34:00 +00:00
|
|
|
|
2015-09-10 18:36:39 +00:00
|
|
|
for (i = 0; i < 5; i++) {
|
|
|
|
painter.draw_string(
|
|
|
|
screen_pos() + offset,
|
|
|
|
style_orange,
|
|
|
|
litteral[i]
|
|
|
|
);
|
|
|
|
offset.y += 40;
|
|
|
|
}
|
2015-08-28 18:50:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
LCRView::LCRView(
|
|
|
|
NavigationView& nav,
|
|
|
|
TransmitterModel& transmitter_model
|
|
|
|
) : transmitter_model(transmitter_model)
|
|
|
|
{
|
2015-09-04 18:37:27 +00:00
|
|
|
char finalstr[24] = {0};
|
|
|
|
|
|
|
|
static constexpr Style style_val {
|
|
|
|
.font = font::fixed_8x16,
|
|
|
|
.background = Color::green(),
|
|
|
|
.foreground = Color::black(),
|
|
|
|
};
|
|
|
|
|
2016-01-05 10:47:46 +00:00
|
|
|
transmitter_model.set_modulation(TX_LCR);
|
2015-11-18 21:01:48 +00:00
|
|
|
transmitter_model.set_tuning_frequency(portapack::persistent_memory::tuned_frequency());
|
2015-09-04 18:37:27 +00:00
|
|
|
memset(litteral, 0, 5*8);
|
2015-08-28 18:50:42 +00:00
|
|
|
memset(rgsb, 0, 5);
|
|
|
|
|
2015-11-20 06:59:09 +00:00
|
|
|
strcpy(rgsb, RGSB_list[29]);
|
|
|
|
button_setrgsb.set_text(rgsb);
|
2015-08-28 18:50:42 +00:00
|
|
|
|
|
|
|
add_children({ {
|
2015-09-04 18:37:27 +00:00
|
|
|
&text_recap,
|
2015-08-28 18:50:42 +00:00
|
|
|
&button_setrgsb,
|
2015-09-03 04:34:00 +00:00
|
|
|
&button_txsetup,
|
2015-09-05 18:17:43 +00:00
|
|
|
&checkbox_am_a,
|
2015-08-28 18:50:42 +00:00
|
|
|
&button_setam_a,
|
2015-09-05 18:17:43 +00:00
|
|
|
&checkbox_am_b,
|
2015-08-28 18:50:42 +00:00
|
|
|
&button_setam_b,
|
2015-09-05 18:17:43 +00:00
|
|
|
&checkbox_am_c,
|
2015-08-28 18:50:42 +00:00
|
|
|
&button_setam_c,
|
2015-09-05 18:17:43 +00:00
|
|
|
&checkbox_am_d,
|
2015-08-28 18:50:42 +00:00
|
|
|
&button_setam_d,
|
2015-09-05 18:17:43 +00:00
|
|
|
&checkbox_am_e,
|
2015-09-04 18:37:27 +00:00
|
|
|
&button_setam_e,
|
|
|
|
&text_status,
|
|
|
|
&button_lcrdebug,
|
2015-08-28 18:50:42 +00:00
|
|
|
&button_transmit,
|
2015-09-03 04:34:00 +00:00
|
|
|
&button_transmit_scan,
|
2015-08-28 18:50:42 +00:00
|
|
|
&button_exit
|
|
|
|
} });
|
|
|
|
|
2015-09-05 18:17:43 +00:00
|
|
|
checkbox_am_a.set_value(true);
|
|
|
|
checkbox_am_b.set_value(true);
|
|
|
|
checkbox_am_c.set_value(true);
|
|
|
|
checkbox_am_d.set_value(true);
|
|
|
|
checkbox_am_e.set_value(true);
|
|
|
|
|
2015-09-04 18:37:27 +00:00
|
|
|
// Recap: tx freq @ bps
|
2015-11-18 21:01:48 +00:00
|
|
|
auto fstr = to_string_dec_int(portapack::persistent_memory::tuned_frequency() / 1000, 6);
|
|
|
|
auto bstr = to_string_dec_int(portapack::persistent_memory::afsk_bitrate(), 4);
|
2015-09-04 18:37:27 +00:00
|
|
|
|
|
|
|
strcat(finalstr, fstr.c_str());
|
|
|
|
strcat(finalstr, " @ ");
|
|
|
|
strcat(finalstr, bstr.c_str());
|
|
|
|
strcat(finalstr, "bps");
|
|
|
|
|
|
|
|
text_recap.set(finalstr);
|
|
|
|
|
|
|
|
button_transmit.set_style(&style_val);
|
|
|
|
button_transmit_scan.set_style(&style_val);
|
|
|
|
|
2015-08-28 18:50:42 +00:00
|
|
|
button_setrgsb.on_select = [this,&nav](Button&){
|
|
|
|
auto an_view = new AlphanumView { nav, rgsb, 4 };
|
2015-09-03 04:34:00 +00:00
|
|
|
an_view->on_changed = [this](char *rgsb) {
|
|
|
|
button_setrgsb.set_text(rgsb);
|
|
|
|
};
|
2015-08-28 18:50:42 +00:00
|
|
|
nav.push(an_view);
|
|
|
|
};
|
|
|
|
|
|
|
|
button_setam_a.on_select = [this,&nav](Button&){
|
|
|
|
auto an_view = new AlphanumView { nav, litteral[0], 7 };
|
2015-09-03 04:34:00 +00:00
|
|
|
an_view->on_changed = [this](char *) {};
|
2015-08-28 18:50:42 +00:00
|
|
|
nav.push(an_view);
|
|
|
|
};
|
|
|
|
button_setam_b.on_select = [this,&nav](Button&){
|
|
|
|
auto an_view = new AlphanumView { nav, litteral[1], 7 };
|
2015-09-03 04:34:00 +00:00
|
|
|
an_view->on_changed = [this](char *) {};
|
2015-08-28 18:50:42 +00:00
|
|
|
nav.push(an_view);
|
|
|
|
};
|
|
|
|
button_setam_c.on_select = [this,&nav](Button&){
|
|
|
|
auto an_view = new AlphanumView { nav, litteral[2], 7 };
|
2015-09-03 04:34:00 +00:00
|
|
|
an_view->on_changed = [this](char *) {};
|
2015-08-28 18:50:42 +00:00
|
|
|
nav.push(an_view);
|
|
|
|
};
|
|
|
|
button_setam_d.on_select = [this,&nav](Button&){
|
|
|
|
auto an_view = new AlphanumView { nav, litteral[3], 7 };
|
2015-09-03 04:34:00 +00:00
|
|
|
an_view->on_changed = [this](char *) {};
|
2015-08-28 18:50:42 +00:00
|
|
|
nav.push(an_view);
|
|
|
|
};
|
2015-09-04 18:37:27 +00:00
|
|
|
button_setam_e.on_select = [this,&nav](Button&){
|
|
|
|
auto an_view = new AlphanumView { nav, litteral[4], 7 };
|
|
|
|
an_view->on_changed = [this](char *) {};
|
|
|
|
nav.push(an_view);
|
|
|
|
};
|
|
|
|
|
|
|
|
button_lcrdebug.on_select = [this,&nav](Button&){
|
|
|
|
make_frame();
|
|
|
|
nav.push(new DebugLCRView { nav, lcrstring, checksum });
|
2015-08-28 18:50:42 +00:00
|
|
|
};
|
|
|
|
|
2016-01-05 10:47:46 +00:00
|
|
|
button_transmit.on_select = [this,&transmitter_model](Button&){
|
2015-11-18 21:01:48 +00:00
|
|
|
auto& message_map = context().message_map();
|
|
|
|
|
2015-09-04 18:37:27 +00:00
|
|
|
make_frame();
|
2015-09-03 04:34:00 +00:00
|
|
|
|
2015-11-18 21:01:48 +00:00
|
|
|
shared_memory.afsk_samples_per_bit = 228000/portapack::persistent_memory::afsk_bitrate();
|
2016-01-03 06:24:30 +00:00
|
|
|
shared_memory.afsk_phase_inc_mark = portapack::persistent_memory::afsk_mark_freq()*(0x40000*256)/2280;
|
|
|
|
shared_memory.afsk_phase_inc_space = portapack::persistent_memory::afsk_space_freq()*(0x40000*256)/2280;
|
2015-08-28 18:50:42 +00:00
|
|
|
|
2015-11-20 06:59:09 +00:00
|
|
|
shared_memory.afsk_fmmod = portapack::persistent_memory::afsk_bw() * 8;
|
2015-09-16 13:43:43 +00:00
|
|
|
|
2015-09-10 18:36:39 +00:00
|
|
|
memset(shared_memory.lcrdata, 0, 256);
|
|
|
|
memcpy(shared_memory.lcrdata, lcrframe_f, 256);
|
2015-09-04 18:37:27 +00:00
|
|
|
|
|
|
|
shared_memory.afsk_transmit_done = false;
|
2016-01-05 19:17:55 +00:00
|
|
|
shared_memory.afsk_repeat = (portapack::persistent_memory::afsk_config() >> 8) & 0xFF;
|
2015-09-04 18:37:27 +00:00
|
|
|
|
2015-11-18 21:01:48 +00:00
|
|
|
message_map.register_handler(Message::ID::TXDone,
|
|
|
|
[this,&transmitter_model](Message* const p) {
|
2016-01-05 19:17:55 +00:00
|
|
|
char str[8];
|
2015-11-18 21:01:48 +00:00
|
|
|
const auto message = static_cast<const TXDoneMessage*>(p);
|
|
|
|
if (message->n > 0) {
|
2016-01-05 19:17:55 +00:00
|
|
|
text_status.set(" ");
|
2015-11-20 06:59:09 +00:00
|
|
|
strcpy(str, to_string_dec_int(message->n).c_str());
|
|
|
|
strcat(str, "/");
|
2016-01-05 19:17:55 +00:00
|
|
|
strcat(str, to_string_dec_int((portapack::persistent_memory::afsk_config() >> 8) & 0xFF).c_str());
|
2015-11-18 21:01:48 +00:00
|
|
|
text_status.set(str);
|
|
|
|
} else {
|
|
|
|
text_status.set("Done ! ");
|
|
|
|
transmitter_model.disable();
|
|
|
|
}
|
2015-09-10 18:36:39 +00:00
|
|
|
}
|
2015-11-18 21:01:48 +00:00
|
|
|
);
|
2015-09-04 18:37:27 +00:00
|
|
|
|
2015-11-20 06:59:09 +00:00
|
|
|
char str[8];
|
|
|
|
strcpy(str, "0/");
|
|
|
|
strcat(str, to_string_dec_int(shared_memory.afsk_repeat).c_str());
|
|
|
|
text_status.set(str);
|
2015-09-04 18:37:27 +00:00
|
|
|
|
2015-08-28 18:50:42 +00:00
|
|
|
transmitter_model.enable();
|
|
|
|
};
|
2015-09-04 18:37:27 +00:00
|
|
|
|
|
|
|
button_txsetup.on_select = [&nav, &transmitter_model](Button&){
|
|
|
|
nav.push(new AFSKSetupView { nav, transmitter_model });
|
|
|
|
};
|
2015-08-28 18:50:42 +00:00
|
|
|
|
|
|
|
button_exit.on_select = [&nav](Button&){
|
|
|
|
nav.pop();
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
} /* namespace ui */
|