diff --git a/firmware/application/pocsag_app.cpp b/firmware/application/pocsag_app.cpp index 374388c0..b1932188 100644 --- a/firmware/application/pocsag_app.cpp +++ b/firmware/application/pocsag_app.cpp @@ -25,12 +25,12 @@ #include "baseband_api.hpp" #include "portapack_persistent_memory.hpp" +#include "pocsag.hpp" + using namespace portapack; using namespace pocsag; -#include "pocsag.hpp" #include "string_format.hpp" - #include "utility.hpp" void POCSAGLogger::log_raw_data(const pocsag::POCSAGPacket& packet, const uint32_t frequency) { diff --git a/firmware/application/ui_pocsag_tx.cpp b/firmware/application/ui_pocsag_tx.cpp index 55d06d2a..f025eba3 100644 --- a/firmware/application/ui_pocsag_tx.cpp +++ b/firmware/application/ui_pocsag_tx.cpp @@ -28,17 +28,13 @@ #include "portapack_persistent_memory.hpp" -#include -#include -#include - using namespace portapack; using namespace pocsag; namespace ui { void POCSAGTXView::focus() { - tx_view.focus(); + field_address.focus(); } POCSAGTXView::~POCSAGTXView() { @@ -59,30 +55,24 @@ bool POCSAGTXView::start_tx() { uint32_t total_frames, i, codeword, bi, address; pocsag::BitRate bitrate; std::vector codewords; - MessageType type; - - type = (MessageType)options_type.selected_index_value(); address = field_address.value_dec_u32(); if (address > 0x1FFFFFU) { - nav_.display_modal("Bad address", "Address must be less\nthan 2097152.", INFO, nullptr); + nav_.display_modal("Bad address", "Address must be less\nthan 2097152."); return false; } + MessageType type = (MessageType)options_type.selected_index_value(); + if (type == MessageType::NUMERIC_ONLY) { // Check for invalid characters if (message.find_first_not_of("0123456789SU -][") != std::string::npos) { - nav_.display_modal( - "Bad message", - "A numeric only message must\nonly contain:\n0123456789SU][- or space.", - INFO, - nullptr - ); + nav_.display_modal("Bad message", "A numeric only message must\nonly contain:\n0123456789SU][- or space."); return false; } } - pocsag_encode(type, BCH_code, message, address, codewords); + pocsag_encode(type, BCH_code, options_function.selected_index_value(), message, address, codewords); total_frames = codewords.size() / 2; @@ -124,16 +114,13 @@ void POCSAGTXView::paint(Painter&) { } void POCSAGTXView::on_set_text(NavigationView& nav) { - text_prompt(nav, &buffer, 16); + text_prompt(nav, &buffer, 30); } POCSAGTXView::POCSAGTXView( NavigationView& nav ) : nav_ (nav) { - uint32_t reload_address; - uint32_t c; - baseband::run_image(portapack::spi_flash::image_tag_fsktx); add_children({ @@ -141,6 +128,7 @@ POCSAGTXView::POCSAGTXView( &options_bitrate, &field_address, &options_type, + &options_function, &text_message, &button_message, &progressbar, @@ -151,12 +139,17 @@ POCSAGTXView::POCSAGTXView( options_type.set_selected_index(0); // Address only // TODO: set_value for whole symfield - reload_address = persistent_memory::pocsag_last_address(); - for (c = 0; c < 7; c++) { + uint32_t reload_address = persistent_memory::pocsag_last_address(); + for (uint32_t c = 0; c < 7; c++) { field_address.set_sym(6 - c, reload_address % 10); reload_address /= 10; } + options_type.on_change = [this](size_t, int32_t i) { + if (i == 2) + options_function.set_selected_index(3); + }; + button_message.on_select = [this, &nav](Button&) { this->on_set_text(nav); }; diff --git a/firmware/application/ui_pocsag_tx.hpp b/firmware/application/ui_pocsag_tx.hpp index 052b568a..5a7fb24a 100644 --- a/firmware/application/ui_pocsag_tx.hpp +++ b/firmware/application/ui_pocsag_tx.hpp @@ -70,7 +70,8 @@ private: { { 3 * 8, 4 * 8 }, "Bitrate:", Color::light_grey() }, { { 3 * 8, 6 * 8 }, "Address:", Color::light_grey() }, { { 6 * 8, 8 * 8 }, "Type:", Color::light_grey() }, - { { 3 * 8, 12 * 8 }, "Message:", Color::light_grey() } + { { 2 * 8, 10 * 8 }, "Function:", Color::light_grey() }, + { { 0 * 8, 14 * 8 }, "Message:", Color::light_grey() } }; OptionsField options_bitrate { @@ -99,13 +100,24 @@ private: } }; + OptionsField options_function { + { 11 * 8, 10 * 8 }, + 1, + { + { "A", 0 }, + { "B", 1 }, + { "C", 2 }, + { "D", 3 } + } + }; + Text text_message { - { 11 * 8, 12 * 8, 16 * 8, 16 }, + { 0 * 8, 16 * 8, 16 * 8, 16 }, "" }; Button button_message { - { 3 * 8, 14 * 8, 12 * 8, 28 }, + { 0 * 8, 18 * 8, 14 * 8, 32 }, "Set message" }; diff --git a/firmware/common/pocsag.cpp b/firmware/common/pocsag.cpp index 7e30abb6..2bddb481 100644 --- a/firmware/common/pocsag.cpp +++ b/firmware/common/pocsag.cpp @@ -102,8 +102,7 @@ uint32_t get_digit_code(char code) { return code; } -void pocsag_encode( - const MessageType type, BCHCode& BCH_code, const std::string message, const uint32_t address, +void pocsag_encode(const MessageType type, BCHCode& BCH_code, const uint32_t function, const std::string message, const uint32_t address, std::vector& codewords) { size_t b, c, address_slot; @@ -122,8 +121,7 @@ void pocsag_encode( codeword = (address & 0x1FFFF8U) << 10; address_slot = (address & 7) * 2; // Function - if (type == MessageType::ALPHANUMERIC) - codeword |= (3 << 11); + codeword |= (function << 11); insert_BCH(BCH_code, &codeword); diff --git a/firmware/common/pocsag.hpp b/firmware/common/pocsag.hpp index 5d852490..2614b418 100644 --- a/firmware/common/pocsag.hpp +++ b/firmware/common/pocsag.hpp @@ -76,7 +76,7 @@ std::string flag_str(PacketFlag packetflag); void insert_BCH(BCHCode& BCH_code, uint32_t * codeword); uint32_t get_digit_code(char code); -void pocsag_encode(const MessageType type, BCHCode& BCH_code, const std::string message, +void pocsag_encode(const MessageType type, BCHCode& BCH_code, const uint32_t function, const std::string message, const uint32_t address, std::vector& codewords); void pocsag_decode_batch(const POCSAGPacket& batch, POCSAGState * const state); diff --git a/firmware/common/pocsag_packet.hpp b/firmware/common/pocsag_packet.hpp index bb19e8b7..39a71060 100644 --- a/firmware/common/pocsag_packet.hpp +++ b/firmware/common/pocsag_packet.hpp @@ -79,8 +79,7 @@ public: } void clear() { - for (uint32_t c = 0; c < 16; c++) - codewords[c] = 0; + codewords.fill(0); bitrate_ = UNKNOWN; flag_ = NORMAL; } @@ -88,7 +87,7 @@ public: private: BitRate bitrate_ { UNKNOWN }; PacketFlag flag_ { NORMAL }; - uint32_t codewords[16]; + std::array codewords; Timestamp timestamp_ { }; }; diff --git a/firmware/portapack-h1-havoc.bin b/firmware/portapack-h1-havoc.bin index 7bdb3fcd..35d4a62f 100644 Binary files a/firmware/portapack-h1-havoc.bin and b/firmware/portapack-h1-havoc.bin differ