diff --git a/.gitignore b/.gitignore index 2d7331e0..9ef38749 100644 --- a/.gitignore +++ b/.gitignore @@ -33,8 +33,8 @@ *.exe *.out *.app -*.bin *.img +/firmware/baseband/*.bin # Other compiler/linker outputs *.cmake diff --git a/firmware/CMakeLists.txt b/firmware/CMakeLists.txt index 9a7bb2d1..d035513a 100644 --- a/firmware/CMakeLists.txt +++ b/firmware/CMakeLists.txt @@ -36,7 +36,7 @@ set(STRIP_DFU ${PROJECT_SOURCE_DIR}/tools/strip_dfu.py) set(MAKE_SPI_IMAGE ${PROJECT_SOURCE_DIR}/tools/make_spi_image.py) set(MAKE_IMAGE_CHUNK ${PROJECT_SOURCE_DIR}/tools/make_image_chunk.py) -set(FIRMWARE_NAME portapack-h1-firmware) +set(FIRMWARE_NAME portapack-h1-havoc) set(FIRMWARE_FILENAME ${FIRMWARE_NAME}.bin) add_subdirectory(application) diff --git a/firmware/application/main.cpp b/firmware/application/main.cpp index 16afe649..23a3181d 100755 --- a/firmware/application/main.cpp +++ b/firmware/application/main.cpp @@ -25,6 +25,7 @@ //BUG: No audio in about when shown second time +//TODO: Make frequency set button in afsksetup accept GHz frequencies (longer label buffer) //TODO: Check AFSK transmit end, skips last bits ? //TODO: Use msgpack for settings, lists... on sd card //TODO: Frequency manager diff --git a/firmware/application/pocsag_app.cpp b/firmware/application/pocsag_app.cpp index 940b89cd..11b94c61 100644 --- a/firmware/application/pocsag_app.cpp +++ b/firmware/application/pocsag_app.cpp @@ -25,6 +25,7 @@ #include "baseband_api.hpp" #include "portapack.hpp" +#include "portapack_persistent_memory.hpp" using namespace portapack; #include "string_format.hpp" @@ -50,8 +51,8 @@ static std::string signal_rate_str(SignalRate signal_rate) { } /* namespace pocsag */ -void POCSAGLogger::on_packet(const pocsag::POCSAGPacket& packet) { - std::string entry = pocsag::format::signal_rate_str(packet.signal_rate()) + " "; +void POCSAGLogger::on_packet(const pocsag::POCSAGPacket& packet, const uint32_t frequency) { + std::string entry = pocsag::format::signal_rate_str(packet.signal_rate()) + " " + to_string_dec_uint(frequency) + "Hz "; for (size_t c = 0; c < 16; c++) entry += to_string_hex(packet[c], 8) + " "; @@ -60,17 +61,35 @@ void POCSAGLogger::on_packet(const pocsag::POCSAGPacket& packet) { namespace ui { +void POCSAGAppView::update_freq(rf::Frequency f) { + char finalstr[10] = {0}; + + options_freq.set_selected_index(0); + set_target_frequency(f); + + portapack::persistent_memory::set_tuned_frequency(f); // Maybe not ? + + auto mhz = to_string_dec_int(f / 1000000, 3); + auto hz100 = to_string_dec_int((f / 100) % 10000, 4, '0'); + + strcat(finalstr, mhz.c_str()); + strcat(finalstr, "."); + strcat(finalstr, hz100.c_str()); + + this->button_setfreq.set_text(finalstr); +} + POCSAGAppView::POCSAGAppView(NavigationView& nav) { baseband::run_image(portapack::spi_flash::image_tag_pocsag); add_children({ { &rssi, &channel, - &options_band, + &options_freq, + &button_setfreq, &field_rf_amp, &field_lna, &field_vga, - //&text_debug, &console } }); @@ -85,10 +104,17 @@ POCSAGAppView::POCSAGAppView(NavigationView& nav) { 1, }); - options_band.on_change = [this](size_t, OptionsField::value_t v) { + options_freq.on_change = [this](size_t, OptionsField::value_t v) { this->on_band_changed(v); }; - options_band.set_by_value(target_frequency()); + options_freq.set_by_value(target_frequency()); + + button_setfreq.on_select = [this,&nav](Button&) { + auto new_view = nav.push(target_frequency_); + new_view->on_changed = [this](rf::Frequency f) { + update_freq(f); + }; + }; logger = std::make_unique(); if( logger ) { @@ -104,7 +130,7 @@ POCSAGAppView::~POCSAGAppView() { } void POCSAGAppView::focus() { - options_band.focus(); + options_freq.focus(); } void POCSAGAppView::set_parent_rect(const Rect new_parent_rect) { @@ -114,18 +140,53 @@ void POCSAGAppView::set_parent_rect(const Rect new_parent_rect) { void POCSAGAppView::on_packet(const POCSAGPacketMessage * message) { bool eom = false; uint32_t codeword; + std::string alphanum_text = ""; + std::string output_text = ""; + char ascii_char; if( logger ) { - logger->on_packet(message->packet); + logger->on_packet(message->packet, target_frequency()); } - for (size_t c = 0; c < 16; c++) { - codeword = message->packet[c]; + for (size_t i = 0; i < 16; i++) { + codeword = message->packet[i]; if (codeword & 0x80000000) { // Message - console.writeln("Message !"); + ascii_data |= ((codeword >> 11) & 0xFFFFF); // 20 bits + ascii_idx += 20; + // AAAAAAABBBBBBBCCCCCC C + // 20 -> 13 -> 6 + // CCCCCC CDDDDDDDEEEEEEEFFFFF FF + // 26 -> 19 -> 12 -> 5 + // FFFFF FFGGGGGGGHHHHHHHIIII III + // 25 -> 18 -> 11 -> 4 + // IIII IIIJJJJJJJKKKKKKKLLL LLLL + // 24 -> 17 -> 10 -> 3 + // LLL LLLLMMMMMMMNNNNNNNOO OOOOO + // 23 -> 16 -> 9 -> 2 + // OO OOOOOPPPPPPPQQQQQQQR RRRRRR + // 22 -> 15 -> 8 -> 1 + // R RRRRRRSSSSSSSTTTTTTT UUUUUUU + // 21 -> 14 -> 7 -> 0 + + while (ascii_idx >= 7) { + ascii_idx -= 7; + ascii_char = (ascii_data >> ascii_idx) & 0x7F; + alphanum_text += ascii_char; + } + ascii_data = ascii_data << 20; + + // Todo: same code in ui_lcr, make function in string_format ! + for(const auto c : alphanum_text) { + if ((c < 32) || (c > 126)) + output_text += "[" + to_string_dec_uint(c) + "]"; + else + output_text += c; + } + + console.writeln(output_text); } else { // Address if (codeword == POCSAG_IDLE) { @@ -137,19 +198,18 @@ void POCSAGAppView::on_packet(const POCSAGPacketMessage * message) { } } - if (eom) - console.writeln("Address:" + to_string_hex(address, 6) + " Function:" + to_string_dec_uint(function)); - //console.writeln("EOM"); - //console.writeln(to_string_hex(message->packet[0], 8) + "/"+ to_string_hex(message->packet[1], 8)); - - if (eom) + if (eom) { + console.writeln("ADDR:" + to_string_hex(address, 6) + " F:" + to_string_dec_uint(function) + " "); + ascii_idx = 0; + ascii_data = 0; batch_cnt = 0; - else + } else { batch_cnt++; + } } void POCSAGAppView::on_band_changed(const uint32_t new_band_frequency) { - set_target_frequency(new_band_frequency); + if (new_band_frequency) set_target_frequency(new_band_frequency); } void POCSAGAppView::set_target_frequency(const uint32_t new_value) { diff --git a/firmware/application/pocsag_app.hpp b/firmware/application/pocsag_app.hpp index dc2e399a..dea54ba6 100644 --- a/firmware/application/pocsag_app.hpp +++ b/firmware/application/pocsag_app.hpp @@ -41,7 +41,7 @@ public: return log_file.append(filename); } - void on_packet(const pocsag::POCSAGPacket& packet); + void on_packet(const pocsag::POCSAGPacket& packet, const uint32_t frequency); private: LogFile log_file; @@ -69,6 +69,7 @@ private: uint32_t batch_cnt = 0; uint32_t address, function; + uint32_t ascii_data, ascii_idx; MessageHandlerRegistration message_handler_packet { Message::ID::POCSAGPacket, @@ -88,10 +89,11 @@ private: { 21 * 8, 5, 6 * 8, 4 }, }; - OptionsField options_band { + OptionsField options_freq { { 0 * 8, 0 * 16 }, - 7, + 8, { + { "Entered", 0 }, { "FR .025", 466025000 }, { "FR .050", 466050000 }, { "FR .075", 466075000 }, @@ -100,14 +102,13 @@ private: { "FR .231", 466231250 } } }; - - Text text_debug { - { 0, 40, 240, 16 }, - "Debug..." + Button button_setfreq { + { 0, 20, 12 * 8, 20 }, + "---.----M" }; Console console { - { 0, 32, 240, 272 } + { 0, 48, 240, 256 } }; RFAmpField field_rf_amp { @@ -125,6 +126,8 @@ private: std::unique_ptr logger; uint32_t target_frequency_ = initial_target_frequency; + + void update_freq(rf::Frequency f); void on_packet(const POCSAGPacketMessage * message); void on_show_list(); diff --git a/firmware/portapack-h1-firmware.bin b/firmware/portapack-h1-havoc.bin similarity index 87% rename from firmware/portapack-h1-firmware.bin rename to firmware/portapack-h1-havoc.bin index d257526b..56ef9cbd 100644 Binary files a/firmware/portapack-h1-firmware.bin and b/firmware/portapack-h1-havoc.bin differ