diff --git a/firmware/application/CMakeLists.txt b/firmware/application/CMakeLists.txt index 0fd0b3df8..35559e760 100644 --- a/firmware/application/CMakeLists.txt +++ b/firmware/application/CMakeLists.txt @@ -135,16 +135,17 @@ set(CPPSRC debounce.cpp touch.cpp touch_adc.cpp - adsb.cpp + protocols/adsb.cpp + protocols/bht.cpp + protocols/dcs.cpp + protocols/lcr.cpp + protocols/rds.cpp afsk.cpp audio.cpp ${COMMON}/bch_code.cpp - bht.cpp ctcss.cpp - dcs.cpp encoder.cpp freqman.cpp - rds.cpp ${COMMON}/lcd_ili9341.cpp ${COMMON}/ui.cpp ${COMMON}/ui_text.cpp @@ -270,6 +271,7 @@ set(INCDIR ${CMAKE_CURRENT_BINARY_DIR} ${COMMON} ${PORTINC} ${KERNINC} ${TESTINC ${FATFSINC} ${CHIBIOS}/os/various bitmaps + protocols ) # diff --git a/firmware/application/afsk.cpp b/firmware/application/afsk.cpp index f7efc0910..59da03166 100644 --- a/firmware/application/afsk.cpp +++ b/firmware/application/afsk.cpp @@ -26,7 +26,7 @@ namespace afsk { -void generate_data(const char * in_message, char * out_data) { +void generate_data(const std::string & in_message, char * out_data) { const afsk_formats_t * format_def; uint8_t pm, pp, bit, cp, cur_byte, new_byte; uint16_t dp; @@ -40,7 +40,7 @@ void generate_data(const char * in_message, char * out_data) { if (format_def->data_bits == 7) { if (!format_def->use_LUT) { - for (dp = 0; dp < strlen(in_message); dp++) { + for (dp = 0; dp < in_message.length(); dp++) { pp = pm; new_byte = 0; cur_byte = in_message[dp]; @@ -55,14 +55,10 @@ void generate_data(const char * in_message, char * out_data) { out_data[dp++] = 0; out_data[dp] = 0; } else { - for (dp = 0; dp < strlen(in_message); dp++) { + for (dp = 0; dp < in_message.length(); dp++) { pp = pm; - // Do not apply LUT on checksum (last byte) ? - if (dp != strlen(in_message) - 1) - cur_byte = alt_lookup[(uint8_t)in_message[dp] & 0x7F]; - else - cur_byte = in_message[dp]; + cur_byte = in_message[dp]; for (cp = 0; cp < 8; cp++) if ((cur_byte >> cp) & 1) pp++; diff --git a/firmware/application/afsk.hpp b/firmware/application/afsk.hpp index b78b0864b..a5fc3678f 100644 --- a/firmware/application/afsk.hpp +++ b/firmware/application/afsk.hpp @@ -54,19 +54,7 @@ const afsk_formats_t afsk_formats[4] = { { "8-Even-0 ", "8E0", 8, EVEN, 1, true, false } }; -// TODO: Complete table -const char alt_lookup[128] = { - 0, 0, 0, 0x5F, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x0F, // 0 - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 10 - 0xF8, 0, 0x99, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 20 !"#$%&'()*+,-./ - 0xF5, 0, 0x94, 0x55, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x1C, 0, 0, // 30 0123456789:;<=>? - 0, 0x3C, 0x9C, 0x5D, 0, 0, 0, 0, 0, 0x44, 0x85, 0, 0xD5, 0x14, 0, 0, // 40 @ABCDEFGHIJKLMNO - 0xF0, 0, 0, 0x50, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 50 PQRSTUVWXYZ[\]^_ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 60 `abcdefghijklmno - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x7F // 70 pqrstuvwxyz{|}~ -}; - -void generate_data(const char * in_message, char * out_data); +void generate_data(const std::string & in_message, char * out_data); } /* namespace afsk */ diff --git a/firmware/application/baseband_api.cpp b/firmware/application/baseband_api.cpp index 2f93c7478..ca639cb6a 100644 --- a/firmware/application/baseband_api.cpp +++ b/firmware/application/baseband_api.cpp @@ -96,6 +96,17 @@ void set_tones_config(const uint32_t bw, const uint32_t pre_silence, const uint1 send_message(&message); } +void kill_tone() { + const TonesConfigureMessage message { + 0, + 0, + 0, + false, + false + }; + send_message(&message); +} + void set_sstv_data(const uint8_t vis_code, const uint32_t pixel_duration) { const SSTVConfigureMessage message { vis_code, @@ -117,6 +128,18 @@ void set_afsk_data(const uint32_t afsk_samples_per_bit, const uint32_t afsk_phas send_message(&message); } +void kill_afsk() { + const AFSKConfigureMessage message { + 0, + 0, + 0, + 0, + 0, + false + }; + send_message(&message); +} + void set_audiotx_data(const uint32_t divider, const uint32_t bw, const uint32_t gain_x10, const bool ctcss_enabled, const uint32_t ctcss_phase_inc) { const AudioTXConfigMessage message { diff --git a/firmware/application/baseband_api.hpp b/firmware/application/baseband_api.hpp index f276716c5..3a1c34fb9 100644 --- a/firmware/application/baseband_api.hpp +++ b/firmware/application/baseband_api.hpp @@ -58,6 +58,7 @@ struct WFMConfig { void set_tone(const uint32_t index, const uint32_t delta, const uint32_t duration); void set_tones_config(const uint32_t bw, const uint32_t pre_silence, const uint16_t tone_count, const bool dual_tone, const bool audio_out); +void kill_tone(); void set_sstv_data(const uint8_t vis_code, const uint32_t pixel_duration); void set_audiotx_data(const uint32_t divider, const uint32_t bw, const uint32_t gain_x10, const bool ctcss_enabled, const uint32_t ctcss_phase_inc); @@ -65,6 +66,7 @@ void set_fifo_data(const int8_t * data); void set_pwmrssi(int32_t avg, bool enabled); void set_afsk_data(const uint32_t afsk_samples_per_bit, const uint32_t afsk_phase_inc_mark, const uint32_t afsk_phase_inc_space, const uint8_t afsk_repeat, const uint32_t afsk_bw, const bool afsk_alt_format); +void kill_afsk(); void set_ook_data(const uint32_t stream_length, const uint32_t samples_per_bit, const uint8_t repeat, const uint32_t pause_symbols); void set_fsk_data(const uint32_t stream_length, const uint32_t samples_per_bit, const uint32_t shift, diff --git a/firmware/application/adsb.cpp b/firmware/application/protocols/adsb.cpp similarity index 100% rename from firmware/application/adsb.cpp rename to firmware/application/protocols/adsb.cpp diff --git a/firmware/application/adsb.hpp b/firmware/application/protocols/adsb.hpp similarity index 100% rename from firmware/application/adsb.hpp rename to firmware/application/protocols/adsb.hpp diff --git a/firmware/application/bht.cpp b/firmware/application/protocols/bht.cpp similarity index 100% rename from firmware/application/bht.cpp rename to firmware/application/protocols/bht.cpp diff --git a/firmware/application/bht.hpp b/firmware/application/protocols/bht.hpp similarity index 100% rename from firmware/application/bht.hpp rename to firmware/application/protocols/bht.hpp diff --git a/firmware/application/dcs.cpp b/firmware/application/protocols/dcs.cpp similarity index 100% rename from firmware/application/dcs.cpp rename to firmware/application/protocols/dcs.cpp diff --git a/firmware/application/dcs.hpp b/firmware/application/protocols/dcs.hpp similarity index 100% rename from firmware/application/dcs.hpp rename to firmware/application/protocols/dcs.hpp diff --git a/firmware/application/encoders.hpp b/firmware/application/protocols/encoders.hpp similarity index 100% rename from firmware/application/encoders.hpp rename to firmware/application/protocols/encoders.hpp diff --git a/firmware/application/protocols/lcr.cpp b/firmware/application/protocols/lcr.cpp new file mode 100644 index 000000000..f1221eecf --- /dev/null +++ b/firmware/application/protocols/lcr.cpp @@ -0,0 +1,73 @@ +/* + * Copyright (C) 2014 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 "lcr.hpp" +#include "string_format.hpp" + +//#include "portapack_persistent_memory.hpp" + +namespace lcr { + +std::string generate_message(std::string rgsb, std::vector litterals, size_t option_ec) { + const std::string ec_lut[4] = { "A", "J", "N", "S" }; // Eclairage (Auto, Jour, Nuit) + char eom[3] = { 3, 0, 0 }; // EOM and space for checksum + uint8_t i; + std::string lcr_message { 127, 127, 127, 127, 127, 127, 127, 15 }; // Modem sync and SOM + char checksum = 0; + + // Pad litterals to 7 chars (not required ?) + for (auto & litteral : litterals) + while (litteral.length() < 7) + litteral += ' '; + + // Compose LCR message + lcr_message += rgsb; + lcr_message += "PA "; + + i = 1; + for (auto & litteral : litterals) { + lcr_message += "AM="; + lcr_message += to_string_dec_uint(i, 1); + lcr_message += " AF=\""; + lcr_message += litteral; + lcr_message += "\" CL=0 "; + i++; + } + + lcr_message += "EC="; + lcr_message += ec_lut[option_ec]; + lcr_message += " SAB=0"; + + // Checksum + i = 7; // Skip modem sync + while (lcr_message[i]) + checksum ^= lcr_message[i++]; + checksum ^= eom[0]; // EOM char + checksum &= 0x7F; // Trim + eom[1] = checksum; + + lcr_message += eom; + + return lcr_message; +} + +} /* namespace lcr */ diff --git a/firmware/application/protocols/lcr.hpp b/firmware/application/protocols/lcr.hpp new file mode 100644 index 000000000..e8aaa6cb8 --- /dev/null +++ b/firmware/application/protocols/lcr.hpp @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2014 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 "ui.hpp" +#include +#include +#include + +#ifndef __LCR_H__ +#define __LCR_H__ + +namespace lcr { + +std::string generate_message(std::string rgsb, std::vector litterals, size_t option_ec); + +} /* namespace lcr */ + +#endif/*__LCR_H__*/ diff --git a/firmware/application/rds.cpp b/firmware/application/protocols/rds.cpp similarity index 100% rename from firmware/application/rds.cpp rename to firmware/application/protocols/rds.cpp diff --git a/firmware/application/rds.hpp b/firmware/application/protocols/rds.hpp similarity index 100% rename from firmware/application/rds.hpp rename to firmware/application/protocols/rds.hpp diff --git a/firmware/application/ui_debug.cpp b/firmware/application/ui_debug.cpp index 3d13bf021..a1a81d2a3 100644 --- a/firmware/application/ui_debug.cpp +++ b/firmware/application/ui_debug.cpp @@ -281,7 +281,7 @@ DebugMenuView::DebugMenuView(NavigationView& nav) { on_left = [&nav](){ nav.pop(); }; } -DebugLCRView::DebugLCRView(NavigationView& nav, std::string lcr_string, uint8_t checksum) { +DebugLCRView::DebugLCRView(NavigationView& nav, std::string lcr_string) { std::string debug_text; @@ -299,7 +299,7 @@ DebugLCRView::DebugLCRView(NavigationView& nav, std::string lcr_string, uint8_t debug_text += "\n\n"; debug_text += "Length: " + to_string_dec_uint(lcr_string.length()) + '\n'; - debug_text += "Checksum: " + to_string_dec_uint(checksum) + '\n'; + debug_text += "Checksum: " + to_string_dec_uint(lcr_string.back()) + '\n'; console.write(debug_text); diff --git a/firmware/application/ui_debug.hpp b/firmware/application/ui_debug.hpp index fa6a64607..ae1fa31d6 100644 --- a/firmware/application/ui_debug.hpp +++ b/firmware/application/ui_debug.hpp @@ -210,7 +210,7 @@ private: class DebugLCRView : public View { public: - DebugLCRView(NavigationView& nav, std::string lcrstring, uint8_t checksum); + DebugLCRView(NavigationView& nav, std::string lcrstring); void focus() override; diff --git a/firmware/application/ui_lcr.cpp b/firmware/application/ui_lcr.cpp index 6ac4d3c4a..20a2fbbd7 100644 --- a/firmware/application/ui_lcr.cpp +++ b/firmware/application/ui_lcr.cpp @@ -25,6 +25,7 @@ #include "ui_debug.hpp" #include "afsk.hpp" +#include "lcr.hpp" #include "baseband_api.hpp" #include "string_format.hpp" @@ -47,58 +48,6 @@ LCRView::~LCRView() { baseband::shutdown(); } -void LCRView::generate_message() { - const char lcr_init[8] = { 127, 127, 127, 127, 127, 127, 127, 15 }; // Modem sync and SOM - const char ec_lut[4][2] = { { 'A', 0x00 }, // Eclairage (Auto, Jour, Nuit) - { 'J', 0x00 }, - { 'N', 0x00 }, - { 'S', 0x00 } }; - char eom[3] = { 3, 0, 0 }; // EOM and space for checksum - - uint8_t i; - - button_setrgsb.set_text(rgsb); - - // Pad litterals to 7 chars (not required ?) - for (i = 0; i < 5; i++) - while (strlen(litteral[i]) < 7) - strcat(litteral[i], " "); - - // Compose LCR message - memset(lcr_message, 0, 512); - memcpy(lcr_message, lcr_init, 8); - - strcat(lcr_message, rgsb); // Address - strcat(lcr_message, "PA "); - - for (i = 0; i < 5; i++) { - if (checkboxes[i].value() == true) { - strcat(lcr_message, "AM="); - strcat(lcr_message, to_string_dec_uint(i + 1, 1).c_str()); - strcat(lcr_message, " AF=\""); - strcat(lcr_message, litteral[i]); - strcat(lcr_message, "\" CL=0 "); - } - } - strcat(lcr_message, "EC="); - strcat(lcr_message, ec_lut[options_ec.selected_index()]); - strcat(lcr_message, " SAB=0"); - - // Checksum - checksum = 0; - i = 7; // Skip modem sync - while (lcr_message[i]) - checksum ^= lcr_message[i++]; - - checksum ^= eom[0]; // EOM char - checksum &= 0x7F; // Trim - eom[1] = checksum; - - strcat(lcr_message, eom); - - afsk::generate_data(lcr_message, lcr_message_data); -} - void LCRView::paint(Painter& painter) { uint8_t i; std::string final_str; @@ -134,6 +83,17 @@ void LCRView::paint(Painter& painter) { text_recap.set(final_str); } +std::vector LCRView::parse_litterals() { + std::vector litterals; + + for (size_t i = 0; i < 5; i++) { + if (checkboxes[i].value()) + litterals.push_back(litteral[i]); + } + + return litterals; +} + void LCRView::update_progress() { char str[16]; @@ -162,8 +122,6 @@ void LCRView::update_progress() { } void LCRView::on_txdone(int n) { - char str[16]; - if (n > 0) { // Repeating... repeat_index = n + 1; @@ -177,25 +135,13 @@ void LCRView::on_txdone(int n) { // Done transmitting if ((tx_mode == SCAN) && (scan_index < (scan_count - 1))) { transmitter_model.disable(); - if (abort_scan) { - // Kill scan process - strcpy(str, "Abort @"); - strcat(str, rgsb); - text_status.set(str); - progress.set_value(0); - tx_mode = IDLE; - abort_scan = false; - button_scan.set_style(&style_val); - button_scan.set_text("SCAN"); - } else { - // Next address - scan_index++; - strcpy(rgsb, &scan_list[options_scanlist.selected_index()].addresses[scan_index * 5]); - scan_progress++; - repeat_index = 1; - update_progress(); - start_tx(true); - } + // Next address + scan_index++; + strcpy(rgsb, &scan_list[options_scanlist.selected_index()].addresses[scan_index * 5]); + scan_progress++; + repeat_index = 1; + update_progress(); + start_tx(true); } else { transmitter_model.disable(); tx_mode = IDLE; @@ -230,7 +176,8 @@ void LCRView::start_tx(const bool scan) { update_progress(); } - generate_message(); + button_setrgsb.set_text(rgsb); + afsk::generate_data(lcr::generate_message(rgsb, parse_litterals(), options_ec.selected_index()), lcr_message_data); switch (portapack::persistent_memory::afsk_format()) { case 0: @@ -259,10 +206,10 @@ void LCRView::start_tx(const bool scan) { baseband::set_afsk_data( (153600 * 5) / portapack::persistent_memory::afsk_bitrate(), - portapack::persistent_memory::afsk_mark_freq() * 437 * 5, //(0x40000 * 256) / (153600 / 25), - portapack::persistent_memory::afsk_space_freq() * 437 * 5, //(0x40000 * 256) / (153600 / 25), + portapack::persistent_memory::afsk_mark_freq() * 437 * 5, // (0x40000 * 256) / (153600 / 25), + portapack::persistent_memory::afsk_space_freq() * 437 * 5, // (0x40000 * 256) / (153600 / 25), afsk_repeats, - portapack::persistent_memory::afsk_bw() * 115, // See proc_afsk.cpp + portapack::persistent_memory::afsk_bw() * 115, // See proc_afsk.cpp afsk_format ); } @@ -355,8 +302,7 @@ LCRView::LCRView(NavigationView& nav) { }; button_lcrdebug.on_select = [this, &nav](Button&) { - generate_message(); - nav.push(std::string(lcr_message), checksum); + nav.push(lcr::generate_message(rgsb, parse_litterals(), options_ec.selected_index())); }; button_transmit.on_select = [this](Button&) { @@ -364,12 +310,22 @@ LCRView::LCRView(NavigationView& nav) { }; button_scan.on_select = [this](Button&) { + char str[16]; + if (tx_mode == IDLE) { button_scan.set_style(&style_cancel); button_scan.set_text("ABORT"); start_tx(true); } else { - abort_scan = true; + // Kill scan process + baseband::kill_afsk(); + strcpy(str, "Abort @"); + strcat(str, rgsb); + text_status.set(str); + progress.set_value(0); + tx_mode = IDLE; + button_scan.set_style(&style_val); + button_scan.set_text("SCAN"); } }; @@ -383,8 +339,6 @@ LCRView::LCRView(NavigationView& nav) { checkboxes[n].set_value(true); set_dirty(); start_tx(false); - } else if (tx_mode == SCAN) { - abort_scan = true; } }; } diff --git a/firmware/application/ui_lcr.hpp b/firmware/application/ui_lcr.hpp index 7a05311ab..146fc62b3 100644 --- a/firmware/application/ui_lcr.hpp +++ b/firmware/application/ui_lcr.hpp @@ -79,18 +79,16 @@ private: }; tx_modes tx_mode = IDLE; - bool abort_scan = false; uint8_t scan_count { 0 }, scan_index { 0 }; double scan_progress { 0 }; char litteral[5][8] = { { 0 }, { 0 }, { 0 }, { 0 }, { 0 } }; char rgsb[5] = { 0 }; char lcr_message[512]; char lcr_message_data[512]; - char checksum = 0; rf::Frequency f { 0 }; uint8_t repeat_index { 0 }; - void generate_message(); + std::vector parse_litterals(); void update_progress(); void start_tx(const bool scan); void on_txdone(int n); diff --git a/firmware/application/ui_morse.cpp b/firmware/application/ui_morse.cpp index 1ca6e8527..5bfd8e0fd 100644 --- a/firmware/application/ui_morse.cpp +++ b/firmware/application/ui_morse.cpp @@ -208,7 +208,7 @@ MorseView::MorseView( tx_view.on_stop = [this]() { if (ookthread) chThdTerminate(ookthread); transmitter_model.disable(); - baseband::set_tones_config(0, 0, 0, false, false); + baseband::kill_tone(); tx_view.set_transmitting(false); }; } diff --git a/firmware/application/ui_navigation.cpp b/firmware/application/ui_navigation.cpp index 84b344e0c..efffe250c 100644 --- a/firmware/application/ui_navigation.cpp +++ b/firmware/application/ui_navigation.cpp @@ -326,7 +326,7 @@ TransmitterAudioMenuView::TransmitterAudioMenuView(NavigationView& nav) { { "Soundboard", ui::Color::green(), &bitmap_icon_soundboard, [&nav](){ nav.push(); } }, { "Numbers station", ui::Color::yellow(),&bitmap_icon_numbers, [&nav](){ nav.push(); } }, { "Microphone", ui::Color::green(), &bitmap_icon_microphone, [&nav](){ nav.push(); } }, - { "Whistle", ui::Color::orange(),&bitmap_icon_whistle, [&nav](){ nav.push(); } }, + { "Whistle", ui::Color::green(), &bitmap_icon_whistle, [&nav](){ nav.push(); } }, } }); on_left = [&nav](){ nav.pop(); }; } diff --git a/firmware/application/ui_script.cpp b/firmware/application/ui_script.cpp index bfd68a303..d2e68ac49 100644 --- a/firmware/application/ui_script.cpp +++ b/firmware/application/ui_script.cpp @@ -36,12 +36,13 @@ void ScriptView::on_frequency_select() { } void ScriptView::on_edit_freq(rf::Frequency f) { + (void)f; //frequencies[menu_view.highlighted()].value = f; setup_list(); } void ScriptView::on_edit_desc(NavigationView& nav) { - + (void)nav; } void ScriptView::on_delete() { @@ -50,7 +51,7 @@ void ScriptView::on_delete() { } void ScriptView::setup_list() { - size_t n; + //size_t n; menu_view.clear(); diff --git a/firmware/application/ui_transmitter.hpp b/firmware/application/ui_transmitter.hpp index 7090f7cc1..051cfd1a0 100644 --- a/firmware/application/ui_transmitter.hpp +++ b/firmware/application/ui_transmitter.hpp @@ -100,11 +100,11 @@ private: }; Text text_bw { - { 11 * 8, 1 * 8, 9 * 8, 1 * 16 }, + { 11 * 8, 2 * 8, 9 * 8, 1 * 16 }, "BW: kHz" }; NumberField field_bw { - { 14 * 8, 1 * 8 }, + { 14 * 8, 2 * 8 }, 3, { 1, 150 }, 1, diff --git a/firmware/application/ui_whistle.cpp b/firmware/application/ui_whistle.cpp index 7488c50e0..05648e785 100644 --- a/firmware/application/ui_whistle.cpp +++ b/firmware/application/ui_whistle.cpp @@ -22,92 +22,86 @@ #include "ui_whistle.hpp" #include "ui_receiver.hpp" +#include "tonesets.hpp" -#include "portapack.hpp" -#include "hackrf_hal.hpp" -#include "portapack_shared_memory.hpp" -#include "portapack_persistent_memory.hpp" +#include "baseband_api.hpp" #include #include -using namespace hackrf::one; +using namespace portapack; namespace ui { +void WhistleView::start_tx() { + baseband::set_tone( + 0, + field_tone.value() * TONES_DELTA_COEF, + (checkbox_stop.value()) ? field_stop.value() * TONES_SAMPLERATE : 0xFFFFFFFF); // (Almost) infinite duration :) + + shared_memory.bb_data.tones_data.message[0] = 0; + + transmitter_model.set_sampling_rate(1536000); + transmitter_model.set_rf_amp(true); + transmitter_model.set_baseband_bandwidth(1750000); + transmitter_model.enable(); + + baseband::set_tones_config(transmitter_model.bandwidth(), 0, 1, false, false); + + tx_mode = SINGLE; +} + +void WhistleView::on_tx_progress(const bool done) { + if (done) { + transmitter_model.disable(); + tx_view.set_transmitting(false); + tx_mode = IDLE; + } +} + void WhistleView::focus() { - button_transmit.focus(); + tx_view.focus(); } WhistleView::~WhistleView() { - //transmitter_model.disable(); + transmitter_model.disable(); + baseband::shutdown(); } -void WhistleView::paint(Painter& painter) { - (void)painter; -} - -Button WhistleView::button_scan = { - { 76, 270, 72, 32 }, - "SCAN" -}; - WhistleView::WhistleView( NavigationView& nav ) { + baseband::run_image(portapack::spi_flash::image_tag_tones); + add_children({ - &button_transmit, - &button_exit + &labels, + &field_tone, + &checkbox_stop, + &field_stop, + &tx_view }); - button_transmit.on_select = [this](Button&){ - /*uint16_t c; - ui::Context context; - - make_frame(); - - shared_memory.afsk_samples_per_bit = 228000/persistent_memory::afsk_bitrate(); - shared_memory.afsk_phase_inc_mark = persistent_memory::afsk_mark_freq()*(65536*1024)/2280; - shared_memory.afsk_phase_inc_space = persistent_memory::afsk_space_freq()*(65536*1024)/2280; - - for (c = 0; c < 256; c++) { - shared_memory.lcrdata[c] = this->lcrframe[c]; + field_tone.set_value(1520); + field_stop.set_value(15); + + tx_view.on_edit_frequency = [this, &nav]() { + auto new_view = nav.push(receiver_model.tuning_frequency()); + new_view->on_changed = [this](rf::Frequency f) { + receiver_model.set_tuning_frequency(f); + }; + }; + + tx_view.on_start = [this]() { + if (tx_mode == IDLE) { + tx_view.set_transmitting(true); + start_tx(); } - - shared_memory.afsk_transmit_done = false; - shared_memory.afsk_repeat = 5; // DEFAULT - - text_status.set("Send...");*/ - - //transmitter_model.enable(); }; - - button_exit.on_select = [&nav](Button&){ - nav.pop(); + + tx_view.on_stop = [this]() { + baseband::kill_tone(); }; - - //static VirtualTimer vt1; - //msg_t msg, result; - - /*static EvTimer evt; - static EventListener el0; - - evtInit(&evt, MS2ST(2000)); - evtStart(&evt); - chEvtRegister(&evt.et_es, &el0, 0);*/ - - //chVTSet(&vt1, MS2ST(2000), whistle_th, (void *)&mbox); - - //while(1) { - /*result = chMBFetch(&mbox, &msg, TIME_INFINITE); - if(result == RDY_OK) { - if(msg & 1) - button_scan.set_text("POUET"); - }*/ - //chThdSleepMilliseconds(500); - //} - } } /* namespace ui */ diff --git a/firmware/application/ui_whistle.hpp b/firmware/application/ui_whistle.hpp index 7f6466d01..9cec2bf50 100644 --- a/firmware/application/ui_whistle.hpp +++ b/firmware/application/ui_whistle.hpp @@ -24,7 +24,7 @@ #include "ui_widget.hpp" #include "ui_painter.hpp" #include "ui_navigation.hpp" -#include "ui_font_fixed_8x16.hpp" +#include "ui_transmitter.hpp" #include "message.hpp" #include "transmitter_model.hpp" @@ -36,33 +36,59 @@ public: ~WhistleView(); void focus() override; - void paint(Painter& painter) override; - static void whistle_th(void *p); + + std::string title() const override { return "Whistle"; }; private: - rf::Frequency f; + void start_tx(); + void on_tx_progress(const bool done); - Text text_status { - { 172, 196, 64, 16 }, - "Ready" + enum tx_modes { + IDLE = 0, + SINGLE }; - Checkbox checkbox_am_a { - { 16, 68 }, - 20, - "" + tx_modes tx_mode = IDLE; + + Labels labels { + { { 3 * 8, 4 * 8 }, "Tone frequency: Hz", Color::light_grey() }, + { { 22 * 8, 8 * 8 + 4 }, "s.", Color::light_grey() } }; - Button button_transmit { - { 24, 270, 48, 32 }, - "TX" + NumberField field_tone { + { 19 * 8, 4 * 8 }, + 4, + { 1, 9999 }, + 5, + ' ' }; - static Button button_scan; + Checkbox checkbox_stop { + { 5 * 8, 8 * 8 }, + 10, + "Stop after" + }; - Button button_exit { - { 176, 270, 48, 32 }, - "Exit" + NumberField field_stop { + { 20 * 8, 8 * 8 + 4 }, + 2, + { 1, 99 }, + 1, + ' ' + }; + + TransmitterView tx_view { + 16 * 16, + 10000, + 12 + }; + + MessageHandlerRegistration message_handler_tx_done { + Message::ID::TXDone, + [this](const Message* const p) { + const auto message = *reinterpret_cast(p); + this->on_tx_progress(message.done); + } }; }; diff --git a/firmware/baseband/hackrf.img b/firmware/baseband/hackrf.img index 7b17e2671..a21cad092 100644 Binary files a/firmware/baseband/hackrf.img and b/firmware/baseband/hackrf.img differ diff --git a/firmware/baseband/proc_afsk.cpp b/firmware/baseband/proc_afsk.cpp index e3597d097..00fdf8195 100644 --- a/firmware/baseband/proc_afsk.cpp +++ b/firmware/baseband/proc_afsk.cpp @@ -124,22 +124,25 @@ void AFSKProcessor::on_message(const Message* const msg) { const auto message = *reinterpret_cast(msg); if (message.id == Message::ID::AFSKConfigure) { - afsk_samples_per_bit = message.samples_per_bit; - afsk_phase_inc_mark = message.phase_inc_mark; - afsk_phase_inc_space = message.phase_inc_space; - afsk_repeat = message.repeat - 1; - afsk_bw = message.bw; - afsk_format = message.format; - - s = 0; - sample_count = afsk_samples_per_bit; - repeat_counter = 0; - bit_pos = 0; - byte_pos = 0; - cur_byte = 0; - ext_byte = 0; - cur_bit = 0; - configured = true; + if (message.samples_per_bit) { + afsk_samples_per_bit = message.samples_per_bit; + afsk_phase_inc_mark = message.phase_inc_mark; + afsk_phase_inc_space = message.phase_inc_space; + afsk_repeat = message.repeat - 1; + afsk_bw = message.bw; + afsk_format = message.format; + + s = 0; + sample_count = afsk_samples_per_bit; + repeat_counter = 0; + bit_pos = 0; + byte_pos = 0; + cur_byte = 0; + ext_byte = 0; + cur_bit = 0; + configured = true; + } else + configured = false; // Kill } } diff --git a/firmware/bootstrap/bootstrap.bin b/firmware/bootstrap/bootstrap.bin index 784058649..c7875d1ad 100755 Binary files a/firmware/bootstrap/bootstrap.bin and b/firmware/bootstrap/bootstrap.bin differ diff --git a/firmware/portapack-h1-havoc.bin b/firmware/portapack-h1-havoc.bin index 6e1141700..d150f88a6 100644 Binary files a/firmware/portapack-h1-havoc.bin and b/firmware/portapack-h1-havoc.bin differ