portapack-mayhem/firmware/application/apps/ui_recon.cpp
gullradriel 1dbfc50dbe
Stable merge v2.2.0 (#2736)
* Update README.md

Actually valid complete ali h4m link

* Fake brightness reimplementation  (#2444)

* Fake brightness reimplementation
* indentation
* added call to the function which is caching the display settings values
* use cached values instead of pmem

* app manager (#2442)

* fix unset autostart
* clean up - add comments to prevent misleading
* move the app to external and with necessary changes
* replace autostart app

* Add + - buttons in Encoder dial settings (#2447)

* M10 additional parser (#2448)

* Remember previous capture settings (#2450)

* Renamed parameters in rx_capture.ini file (#2452)

* Rename settings in file to match screen
* Renamed variables for hopefully better clarity

* Navigation buttons (#2458)

* regenerate bitmap data
* pagination in submenu
* using little font so we are not eating menu buttons

* docker improvements (#2455)

* Update README.md

New metal case link

* The gerber files of the portapack H4 (#2463)

* Create README.txt

* Update README.txt

* Add files via upload

The gerber files of the portapack h4.

* delete

* Upload the gerber files for H4

* Update README.md (#2456)

Added a link to Lab401.com as a purchase option for EU customers.
(Lab401 was added as the EU exclusive distributor for the H4M - https://opensourcesdrlab.com/pages/distributors)

* Update README.md

* rename bitmaps into bmp

* disabling button on main menu, change labels and add 'icons' (#2466)

* disabling button on main menu, change labels and add 'icons'

* fix reverse order of buttons

---------

Co-authored-by: gullradriel <gullradriel@no-mail.com>

* fix for empty text prompt crash (#2468)

* added discord server information (#2471)

* Add the feature to decide rotate direction of encoder (#2472)

* Update README.md

Lab401 link with our redirection

* Fix encoder setting p.mem issue (#2475)

* Update README.md

Discord badge was broken, switching to shields.io

* Add fast flash script for sdcard switch hardware (#2480)

* fix cmake_minimum_required to 3.16 (#2499)

* fix fallthrough warning (#2497)

* Flipper tx: use file_path, example file (#2496)

* added subghz_dir
* use subghz_dir from file_path
* example file

* Externalize antenna calc and wav view (#2498)

* externalize antenna calc and wav view
* Added a tool to check if all the pictures in graphics are used in internal apps

* APRS: add frequency settings for Brazil (#2494)

* Add frequency settings for Brazil, named 'BR' that tunes to 145.570 MHz.
* Also added: Japan: 144.640 MHz (JAP), Thailand: 144.900 MHz (THA), Philippines: 144.740 MHz (PHI)
* Reordered list by increasing frequency
Co-authored-by: gullradriel <3157857+gullradriel@users.noreply.github.com>

* Added different modulations in signal generator (#2492)

* Added DSB, AM 100% mod index and AM 50% mod index. Changed UI.

* put back app in 'Utilities' (#2500)

Co-authored-by: gullradriel <gullradriel@no-mail.com>

* fix baseband (#2501)

* externalize wipe sdcard (#2502)

* Removing vim swap files (#2503)

* Removing vim swap files
* Added vim swap file to .gitignore

* Add modal to turn off screen when charging is detected (#2514)

* Moved country-specific FREQMAN files to the separate repository set up for it. (#2517)

* fix docker build warnings in dockerfile-nogit (#2518)

* Add new app "hopper" app. (#2482)

* make both jammer and hopper exist
* add example hopper payload
* example files
* swap scanner and recon app location

* Add widget preview tool (#2520)

* PoC

* opt

* opt

* Playlist editor (#2506)

* make both exist
* format
* fix focusing issue
* add example hopper payload
* fix compiler err
* clean up
* correct linker script addr
* lint
* PoC
* unknown: write_line issue
* clean up
* merge
* fix read line
* remove debug code
* fix english
* support new file
* support enter delay
* fix crash
* remove debug code
* some final tune

* Support Bug Key AKA Auto Key for OOK Editor app (#2523)

* _

* some final tune

* textual

* rename following gull's suggestion

* add cursor to font viewer app (#2528)

* Allow disable/enable waveform in Audio app to remove decoding problem on some frequencies

* Added different modulations in signal generator

* Added DSB, AM 100% mod index and AM 50% mod index. 
* Changed UI.
* Added pulsed CW

* Adding Wefax demodulation mode inside Audio App (#2539)

* Adding_new_WFAX_GUI_mode_Audio_App

* Wefax_APT_demodulation_structure

* Solving REC Apt signal.wav from WFAX

* clang format issues

* correcting comments

* Breakout - The Portapack remake game rises from the pirate's lair (#2541)

* Breakout - The Portapack remake game rises from the pirate's lair

* Fixes

* Added a signature

* Trivial textual change about missing SD content (#2542)

* _

* _

* waveform fix 3 and trivial change (#2540)

* Moved games to new game menu (#2544)

* Moved games to new game menu
* There's enough games to have a menu now and I plan to make more. Having them in "Utilities" made no sense.

* Wefax warning fix modulation fix (#2543)

* changed order of modulations, changed case to avoid capture
* added missing AMAudioFMApt mode to dump pmem
* reorder demod, adding missing ones, fix warnings
* removed uneeded 'previous_modulation', renamed WFAX to AMFM to match other places
* removing uneeded 'previous_modulation' uneeded check in change_modulation
* move capture at the end so AMAUdioFMApt is matching the other arrays for position 4
* added AMFM to Recon Level and Scanner

* clang + more details in some comments

---------

Co-authored-by: gullradriel <gullradriel@no-mail.com>

* Snake (#2549)

* Create the Shopping Cart Lock app

Will demonstrate tomorrow. Don't merge until I do 😁

* Fixes for HTotoo's comments 😎

* Improved audio the best I can.

If nobody has any ideas to further improve high frequencies of the audio, the hardware may not be capable. I still need to check with line-out to better speaker to make sure it's not just the speaker, but it shouldn't be.

* Compared against baseband_api.cpp - matched some things better but still playback seems to be missing higher fq sounds

* renamed wav files to a more specific / less generic name

* indentation + using variables instead of litteral names for wav files to use

* indentation

* Made a Snake game - enjoy

* Code formatting. I always forget.

* move to keep sort order

* Update external.ld

Sorry I should have also asked if there was any reason that address ranges 0xADDA0000--0xADDD0000 were skipped in external.ld.  I assumed there wasn't so I changed it to be consecutive using the same 0x10000 step as the other modules.  If there is any reason to skip them then we should add a comment to note it.  Of course these are all just temporary address values used for linking and get overwritten by a kludgy "search & replace" during the build process.

Resolves enhancement request #764

---------

Co-authored-by: gullradriel <gullradriel@no-mail.com>
Co-authored-by: Mark Thompson <129641948+NotherNgineer@users.noreply.github.com>

* Nested Debug menu into Utilities menu to tidy Home screen (#2551)

* rename rand pwd app (#2552)

* _

* remove wip code that forgot to add in old branch

* Moved speaker 1px to the right to match muted icon variant. (#2554)

* Stopwatch external app (#2553)

* updated bitmaps for speaker icon (#2555)

* updated bitmaps for speaker icon
* removed opera cake icon that was added by mistake
* adding missing Game menu source png
* cyan for Game menu
* regenerated icons

* Breakout icon change (#2556)

- Changed Breakout icon
- Changed Tetris icon color to green

* Snake icon change (#2557)

* Remove deprecated QR Code code (#2558)

* Setting for faster Button Repeat delays (#2559)

* Setting for faster Button Repeat delays

* Tweak fast delay times

* Tweak delay times

* Added description line and tweaked delay again

* OokBrute app opt (#2561)

* zooming_spectrum_AMFM_mode (#2565)

* Update README.md

Fixing opesourcesdrlab link

* Update README.md

Other link broken

* WeFax rx ext app (#2566)

* wf3

* Ookbrute (#2354)

* Revert "Ookbrute (#2354)"

This reverts commit abb8143eec.

* fix

* test edition

* re enable ble

* re enable ert

* steal amfm stuff

* something happens

* save bmp on start btn

* kinda works

* exit crash fixed

* redline, remove some hardcoded

* removed cpu killer red line, and some fixes

* simplify #1

* seems ok. time to improve

* added hidden freq offset to receiver model, so wefax can be set to the "correct" freq without users needs to substract 300 hz

* badly implemented sync detection, and disabled it.

* fix for fix

* fixes

* fix offset to real life off

* no line on freq enter

* fixes

* Doom - Mayhem Edition (#2570)

* Doom - Mini Mayhem version

* Update ui_doom.cpp

* Update ui_doom.cpp

* Update ui_doom.cpp

* Update ui_doom.cpp

* Update ui_doom.cpp

* Update ui_doom.cpp

* Update ui_doom.cpp

* Update ui_doom.cpp

* Doom - Mayhem Edition

Made the Doom - Mayhem Edition game. Some little bugs but good enough for nightly.

* Code formatting. Forgot like always.

* give more initial ammo until i put ammo around the maze to collect

* Update Doom main.cpp for better icon (#2575)

* fix external app address list (#2573)

* Add WEFAX freqman file (#2567)

* Add WEFAX freqman file
* fix bad escaped spaces and unicode characters

* Add icon for the doom game (#2574)

* Add icon for the doom game
* Add b/w .png to convert as doom icon

* Added wefax offset to audio app too. (#2572)

* added wefax offset to audio app too.

* moved from head to cpp

* Put ticker class and pp_colors in hpp file in namespace and remove helper files (#2577)

* stopwatch opt (#2578)

* stopwatch opt

* comments

* format

* fxi ms display when user tune display level

* issue template fine tune (#2579)

* Combined cpp files, stuffed helper files in hpp, updates start and game over screens (#2583)

* Combine cpp, move helpers to hpp (#2584)

* naming space (#2585)

* Tetris: Combined cpp files. Helper files into hpp. Dark mode. Encoder on. (#2587)

* Adding_Waterfall_ZOOM_x2_in_AM_modes_Audio_App (#2586)

* adding zoom_factor to app settings
* separated zoom_factor settings for AM and AMFM
* fix order so zoom factor is also applied correctly on modulation change
* fix zoom not applied when changing bandwidth
* temporary disable the Scanner so we are not breaking the nightly. Until we are choosing to finally remove it or find a better solution

---------

Co-authored-by: gullradriel <3157857+gullradriel@users.noreply.github.com>
Co-authored-by: gullradriel <gullradriel@no-mail.com>

* Fixed the I Tetromino rotation using SRS (Super Rotation System) (#2588)

* Externalize dump pmem (#2590)

* initial commit

* clang

* memory icon

* text output and exit button, FOCUS OVERRIDE TO AVOID COMPILATION ERROR

* modem and data_structure_version accessor

---------

Co-authored-by: gullradriel <gullradriel@no-mail.com>

* remove dead code (#2593)

* remove not yet enabled screening app (#2594)

* move default splash into sdcard (#2595)

* move bmps to sdcard
* remove unrelated files
* gitignore
* credit
* format

* Externalize scanner (#2589)

* externalize scanner
* NFM as main baseband as it's the biggest used one
* fix modulation bug introduced with AMFM

* Externalize level (#2596)

* removing ability to focus on RSSI bars and to launch level app, until a solution to launch external apps from internal ones is given
* externalize Level app

* Remove unneeded AMFM support in those apps (#2597)

* Create CODE_OF_CONDUCT.md

* Create pull_request_template.md

* Create SECURITY.md

* Create CONTRIBUTING.md (#2598)

* Force 433.92 and remove metadata check (#2599)

* Force 433.92 and remove metadata check: we already know the frequency for all files so don't need a million metadata files to match.
* Variable fixes and move to header

* Added more Wefax stations (#2600)

* Delete sdcard/FREQMAN/WEFAX.TXT

Replace with 2 files

* Add more WeFax frequencies

* Update comments

* Oops wrong folder

* Oops wrong folder

* Change comments

* Remove RF TX and use PATX baseband for audio --> speaker out only (#2601)

* Force 433.92 and remove metadata check

We already know the frequency for all files so don't need a million metadata files to match.

* Remove RF TX. Improve PATX baseband.

* code formatting of course

* Issue template again (#2602)

* test1

* test2

* add tap tempo to metronomic app (#2605)

* _

* format

* fix new tree in Arch

* solving_Audio_App_AM_GUI_Problem_issue_2604 (#2609)

* make the ptext_prompt func can define which keyboard to enter (#2608)

* _

* format

* use define

* prevent long life var for audio app - AM (#2610)

* static vars so no external linkage is possible

* persistent settings and no more global living variables

---------

Co-authored-by: gullradriel <gullradriel@no-mail.com>

* theme fix again (#2611)

* theme fix again

* _

* user can disable battery change hint (#2612)

* theme fix again

* _

* _

* GFX EQ App (#2607)

* Make the beginnings of rf3d
* Name change...
* Add mood button
* Remove forced amp settings and add persistent user settings
* Fix options bar layout and SettingsManager
* Make the background paint to black again after opening fq modal
* fix audio/mod/settings and cleaned unneeded parts
* Mapped bars to audio spectrum
* Improved frequency response... still needs work i think
* add on_freqchg to be able to answer to serial frequency change command
* Made calculations for 14 bars to fit screen and little adjustments
* Visual improvements
Co-authored-by: gullradriel

* Improved make_bitmap tool (#2615)

* Enhance Graphic Equalizer Visualization with Improved Frequency Bands and Response (#2614)

* Custom waterfall colors (#2617)

* Custom waterfall gradient
* Installing a custom waterfall gradient via fileman
* default file for user friendly swap
Co-authored-by: gullradriel <gullradriel@no-mail.com>

* Delete dead code in ble_rx_app.cpp (#2620)

Duplicate include on line 24 removed.

* Fix default waterfall file (#2621)

* correct default settings from file
* correct colors names

* fix comments (#2622)

* Touch on waterfall to set cursor pos (#2624)

* init

* fix typo that found by Copilot

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Adding 8.33KHz spacing (#2628)

* Adding 8.33KHz spacing
* remove extern options_db_t freqman_steps which is now brought by ui_receiver.hpp
* use freqman db steps instead of static array
Co-authored-by: gullradriel <gullradriel@no-mail.com>

* Added menu group for transceivers (#2623)

* Added menu group for transceivers

* Reorder apps icons

* Support IPS screen & brightness set for IPS screen (#2629)

* _

* format

* format

* format

* Fix bug that created by PR "Added menu group for transceivers" (#2630)

* spectrum cursor opt again (#2634)

* spectrum cursor opt

* fmt

* remove blink

* remove End event

* cleanup

* Update README.md

Links were dead for opensourcesdrlab

* Fix for #2538 (#2635)

* Fix for #2538

Fix for #2538
Added on_bandwidth_changed Callback to ui_transmitter.hpp
Modified the field_bw.on_change lambda in the TransmitterView constructor to trigger the on_bandwidth_changed callback
Connected the Callback in ui_siggen.cpp

I am not a C++ programmer so this change was proposed by Gemini AI.

I have built and tested the App and it works as expected and I don't think the change will have any unexpected side effects.

* Fix clang issues

Fix clang issues

* Update ui_transmitter.cpp

typo

* Revised change

The proposed change mirrors the way a change to the frequency (on_edit_frequency) is triggered in ui_siggen by the tx_view.
The bw parameter is not passed because it is stored in _setting in the tx_view and will be read by update_config.
A change to the bw is not checked against auto_update to keep its behaviour consistent with a change to the gain, amplitude or frequency.

* Make changes to the channel_bandwidth dynamic whist playing

Behaviour of channel bandwidth is now consistent with frequency, amp and gain.

* comment edit

* revert hackrf submodule checkpoint to the repo

* comment

---------

Co-authored-by: zxkmm <zxkmm@hotmail.com>

* Adding_WFM_AM_mode_to_Audio_App (#2644)

* Adding_WFM_AM_mode_to_Audio_App
* more precise values for cos and sin theta, fix sen_theta to sin_theta
* fix sen_theta to sin_theta

* going back to WFM as main baseband in main.cpp as NFM is now making the apps crashing. Looks like last additions to WFM made it bigger. (#2646)

* remove dead code (#2647)

* Update ui_tetris.cpp (#2650)

Start "I" tetromino a bit higher and block rotate if it will cause out of bounds collision.

* Noaa apt decoder (#2648)

* Explicit_naming_wefax_NOAA_and_small_addition (#2651)

* slightly improved ads-b receiver module (#2649)

* slightly improved ads-b receiver module:
* fix Heading, Speed and Vrate decoders
* decode more ModeS messages
* log all ModeS messages (except DF11)
* fix formatting (clang-style); advice on data alignment taken into account
* ADS-B module: convert Indicated AirSpeed to True AirSpeed if altitute is known
* ADS-B rx module: replacing floating point with integer arithmetic

* adding 10Hz and 50Hz to freqman_steps (#2652)

* Improve_RF_sensitivity_NOAA_signal (#2654)

* Upload the PCB file of PortaPack H4 and update the schematic file (#2657)

* Create README.txt

* Update README.txt

* Add files via upload

The gerber files of the portapack h4.

* delete

* Upload the gerber files for H4

* Create README.txt

This is the V1.0 version PCB file of PortaPack H4.

* Upload the pcb file for H4

* Update README.txt

* Update LCD_TF_Schematic.pdf

* Jammer app add modes (#2659)

* Add new jammer modes

Overview

This PR enhances the PortaPack Jammer app by introducing eight new signal types, ported from my Flipper Zero RF Jammer app (https://github.com/RocketGod-git/flipper-zero-rf-jammer). These modes expand the app's capability to disrupt a wide range of RF communication protocols, from analog radios to modern digital systems. The implementation preserves the original app structure, resolves namespace conflicts, and ensures compatibility with the Mayhem firmware.

New Modes

The following modes have been added to the options_type in ui_jammer.hpp, with corresponding signal generation in proc_jammer.cpp:

Noise: Generates broadband white noise to interfere with analog and digital signals (e.g., Wi-Fi, Bluetooth, key fobs). Highly effective for overwhelming receivers across a frequency range.

Sine: Produces a continuous, unmodulated sine wave to jam narrowband receivers, ideal for analog FM/AM radios or telemetry systems.

Square: Emits a harmonic-rich square wave, disrupting digital protocols (e.g., OOK, ASK) and systems sensitive to sharp transitions, such as remote keyless entry.

Sawtooth (Experimental): Generates a sawtooth wave with a unique harmonic profile, useful for testing interference against PWM-based or niche analog systems.

Triangle (Experimental): Creates a triangle wave with minimal harmonics, suitable for exploratory jamming of narrowband systems or receiver linearity testing.

Chirp: Outputs a rapid frequency-sweeping chirp signal, effective against frequency-hopping and spread-spectrum systems (e.g., some Wi-Fi, Bluetooth, or military radios).

Gauss: Generates Gaussian noise to mimic natural interference, targeting digital systems like GPS or data links by degrading signal-to-noise ratios.

Brute (Experimental): Transmits a constant maximum-amplitude signal to saturate simple receiver front-ends, useful for brute-force jamming of basic analog devices.

* Add new jammer modes

Overview

This PR enhances the PortaPack Jammer app by introducing eight new signal types, ported from my Flipper Zero RF Jammer app (https://github.com/RocketGod-git/flipper-zero-rf-jammer). These modes expand the app's capability to disrupt a wide range of RF communication protocols, from analog radios to modern digital systems. The implementation preserves the original app structure, resolves namespace conflicts, and ensures compatibility with the Mayhem firmware.

New Modes

The following modes have been added to the options_type in ui_jammer.hpp, with corresponding signal generation in proc_jammer.cpp:

Noise: Generates broadband white noise to interfere with analog and digital signals (e.g., Wi-Fi, Bluetooth, key fobs). Highly effective for overwhelming receivers across a frequency range.

Sine: Produces a continuous, unmodulated sine wave to jam narrowband receivers, ideal for analog FM/AM radios or telemetry systems.

Square: Emits a harmonic-rich square wave, disrupting digital protocols (e.g., OOK, ASK) and systems sensitive to sharp transitions, such as remote keyless entry.

Sawtooth (Experimental): Generates a sawtooth wave with a unique harmonic profile, useful for testing interference against PWM-based or niche analog systems.

Triangle (Experimental): Creates a triangle wave with minimal harmonics, suitable for exploratory jamming of narrowband systems or receiver linearity testing.

Chirp: Outputs a rapid frequency-sweeping chirp signal, effective against frequency-hopping and spread-spectrum systems (e.g., some Wi-Fi, Bluetooth, or military radios).

Gauss: Generates Gaussian noise to mimic natural interference, targeting digital systems like GPS or data links by degrading signal-to-noise ratios.

Brute (Experimental): Transmits a constant maximum-amplitude signal to saturate simple receiver front-ends, useful for brute-force jamming of basic analog devices.

* refactor the serial log logic of BLE Rx (#2660)

* Prepare for display orientation part 1 (#2661)

* fix png part

* screen max width fixes (#2663)

* max width fixes

* format

* Audio to right (#2664)

* r.align

* Storing_selected_NOAA_filter_in_settings_file (#2665)

* Storing_selected_NOAA_filter_in_settings_file

* format_issues

* wfm_filters_GUI_name_std (#2668)

* getres cmd (#2671)

* ui new coord system examples and macros (#2672)

* Detector RX ext app (#2673)

* Jammer improvements (#2674)

* Add new jammer modes
Overview:
This PR enhances the PortaPack Jammer app by introducing eight new signal types, ported from my Flipper Zero RF Jammer app (https://github.com/RocketGod-git/flipper-zero-rf-jammer). These modes expand the app's capability to disrupt a wide range of RF communication protocols, from analog radios to modern digital systems. The implementation preserves the original app structure, resolves namespace conflicts, and ensures compatibility with the Mayhem firmware.

New Modes

The following modes have been added to the options_type in ui_jammer.hpp, with corresponding signal generation in proc_jammer.cpp:

Noise: Generates broadband white noise to interfere with analog and digital signals (e.g., Wi-Fi, Bluetooth, key fobs). Highly effective for overwhelming receivers across a frequency range.

Sine: Produces a continuous, unmodulated sine wave to jam narrowband receivers, ideal for analog FM/AM radios or telemetry systems.

Square: Emits a harmonic-rich square wave, disrupting digital protocols (e.g., OOK, ASK) and systems sensitive to sharp transitions, such as remote keyless entry.

Sawtooth (Experimental): Generates a sawtooth wave with a unique harmonic profile, useful for testing interference against PWM-based or niche analog systems.

Triangle (Experimental): Creates a triangle wave with minimal harmonics, suitable for exploratory jamming of narrowband systems or receiver linearity testing.

Chirp: Outputs a rapid frequency-sweeping chirp signal, effective against frequency-hopping and spread-spectrum systems (e.g., some Wi-Fi, Bluetooth, or military radios).

Gauss: Generates Gaussian noise to mimic natural interference, targeting digital systems like GPS or data links by degrading signal-to-noise ratios.

Brute (Experimental): Transmits a constant maximum-amplitude signal to saturate simple receiver front-ends, useful for brute-force jamming of basic analog devices.

* Fixed and made brutal.

This PR introduces user-focused improvements to the Jammer App in the HackRF PortaPack Mayhem Firmware, enhancing usability and flexibility. The changes address specific user requirements for a more intuitive default configuration, continuous waveform support, and dynamic setting adjustments during transmission.

* jammer fix (#2676)

* jammer fix

* Adding_BPF_selection_to_the_NOAA_APT_signal (#2675)

* Adding_BPF_selection_to_the_NOAA_APT_signal
* comments, spell mistake .

* trivial apps folder movement (#2677)

* Clean_LCD_beat_in_NOAA_Rx_App (#2678)

* Added ability to enter custom tone values in Morse app (#2679)

* Added ability to enter custom tone values in Morse app

Added the ability to type in a custom tone value in the morse TX app (issue#2582)

*Click on the tone field to open a keyboard for entering in a desired value between 100hz - 9999hz.

*Maintains original step value of 20 when scrolling the rotary wheel.

* Update ui_morse.cpp

Replaced std::to_string with to_string_dec_uint

* Moved tone_input_buffer init to in-class

* removed some std stuff only used here (#2681)

* 80mhz jammer range (#2682)

Looks great 😎🤘🚀

* Radio app improvements (#2680)

* Rename looking glass preset for clarity and consistency (#2686)

* Gfx widget and Radio (#2685)

* widgetize
* gfx and Radio improvement
* format + handle not wfm visual states
* wf or gf

* Externalize widget (#2688)

* Add all jammer modes in hopper app (#2691)

Added all modes that jammer app supports in hopper app.

* Super secret dont look (#2690)

* Add new jammer modes

Overview

This PR enhances the PortaPack Jammer app by introducing eight new signal types, ported from my Flipper Zero RF Jammer app (https://github.com/RocketGod-git/flipper-zero-rf-jammer). These modes expand the app's capability to disrupt a wide range of RF communication protocols, from analog radios to modern digital systems. The implementation preserves the original app structure, resolves namespace conflicts, and ensures compatibility with the Mayhem firmware.

New Modes

The following modes have been added to the options_type in ui_jammer.hpp, with corresponding signal generation in proc_jammer.cpp:

Noise: Generates broadband white noise to interfere with analog and digital signals (e.g., Wi-Fi, Bluetooth, key fobs). Highly effective for overwhelming receivers across a frequency range.

Sine: Produces a continuous, unmodulated sine wave to jam narrowband receivers, ideal for analog FM/AM radios or telemetry systems.

Square: Emits a harmonic-rich square wave, disrupting digital protocols (e.g., OOK, ASK) and systems sensitive to sharp transitions, such as remote keyless entry.

Sawtooth (Experimental): Generates a sawtooth wave with a unique harmonic profile, useful for testing interference against PWM-based or niche analog systems.

Triangle (Experimental): Creates a triangle wave with minimal harmonics, suitable for exploratory jamming of narrowband systems or receiver linearity testing.

Chirp: Outputs a rapid frequency-sweeping chirp signal, effective against frequency-hopping and spread-spectrum systems (e.g., some Wi-Fi, Bluetooth, or military radios).

Gauss: Generates Gaussian noise to mimic natural interference, targeting digital systems like GPS or data links by degrading signal-to-noise ratios.

Brute (Experimental): Transmits a constant maximum-amplitude signal to saturate simple receiver front-ends, useful for brute-force jamming of basic analog devices.

* Super secret

* You gotta get (Get) that (That) dirt off your shoulder

* Add 1ms hop option to hopper app + 0ms (freeze UI) (#2692)

* add dark theme (#2695)

* Made the Dino Game (#2697)

* Add vendor name in bluetooth rx app (#2696)

* add macaddress db, add vendor name in bluetooth rx app

* show "missing macaddress.db" instead of unknown if db not found

* bluetooth rx list with colors based on mac vendor

* bug fix

* Modified Text Editor to handle long presses. (#2698)

* Improved FPV_ANALOG.txt FREQMAN file (#2700)

* Improved FPV_ANALOG.txt FREQMAN file
Removed unused or super rare analog fpv bands: U, O, H, D
Added 1.2GHz -1.3GHz channels sometimes used for long range analog fpv


* Corrected and updated the labels to be more consistent.

Corrected the labels to be more consistent.

I also somehow messed up the correct channels because 1.3GHz FPV is not fully standardized, but these channels seem to be the most common.
It should be all correct now.

Example transmitters using those channels:
https://greenchip.com.ua/0-0-1615-2.html
https://flymod.net/en/item/walksnail_vtx_9ch
https://pl.aliexpress.com/item/1005006505365351.html

* Filemanager: go to parent directory keep track of the right selected … (#2702)

* Filemanager: go to parent directory keep track of the right selected item and page number
* review: avoid unnecessary copies in get_extension

* ADSB database update (tools, db) (#2701)

* enhance make_airlines_db tool
* enhance make_icao24_db tool
* update airlinescode (.txt, .db), aircraftdatabase/icao24 (.csv, .db)

* Made the Space Invaders game. Argh matey! (#2709)

* Made the Space Invaders game. Argh matey!
* Format code, sigh.

* Made the Blackjack game (#2712)

* Made the Blackjack game
* Format Blackjack main.cpp
* Changed spade to diamond for dark mode visibility
* Format code

* Update app icons for Space Invaders and Dino Game (#2713)

* BLE Rx Improvements (#2710)

* Work to allow for unique beacon parsing functions.
* Fix Copyright
* Update firmware/application/apps/ble_rx_app.cpp
* Update firmware/baseband/proc_btlerx.cpp
* PR suggestions.
* Fix String.
* Refactor

* Added 3d printed cases for the H4M (#2715)

* Battleship (#2720)

* Made the Battleship 2P 2PP game - FSK is wip
* Using POCSAG

* Adding simple FSK Rx Processor. Can be used with New Apps. (#2716)

* Work to allow for unique beacon parsing functions.

* Fixing pull.

* Changes.

* Formatting.

* Fix Copyright

* Update firmware/application/apps/ble_rx_app.cpp

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update firmware/baseband/proc_btlerx.cpp

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* PR suggestions.

* Fix String.

* FSK Rx Improvements. Works for my custom protocol.

* Fix buffer size.

* Refactor

* Formatting.

* Formatting.

* Fixing compiling, and BLE Rx UI/Performance.

* More improvements.

* Fixing stuck state.

* More stuck parsing fix.

* Combining PR changes.

* Improvements from previous PR.

* Fix dbM calculation relative to device RSSI.

* Formatting.

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: TJ <tj.baginski@cognosos.com>

* Add blue bar to subghzd+weather (#2724)

* AIS map improv (#2725)

* AIS map improv

* format code mismatch with vc

* Add radio settings, new app icon, and other UI improvements (#2732)

* update submodule (#2734)

Co-authored-by: gullradriel <gullradriel@no-mail.com>

* update version (#2735)

Co-authored-by: gullradriel <gullradriel@no-mail.com>

---------

Co-authored-by: Erwin Ried <1091420+eried@users.noreply.github.com>
Co-authored-by: hackrfstuff <leszczyleszczy@icloud.com>
Co-authored-by: sommermorgentraum <24917424+zxkmm@users.noreply.github.com>
Co-authored-by: Totoo <ttotoo@gmail.com>
Co-authored-by: Mark Thompson <129641948+NotherNgineer@users.noreply.github.com>
Co-authored-by: E.T. <tamas@eisenberger.hu>
Co-authored-by: OpenSourceSDRLab <opensourcesdr@outlook.com>
Co-authored-by: quantum-x <simon.yorkston@gmail.com>
Co-authored-by: gullradriel <gullradriel@no-mail.com>
Co-authored-by: Lucas C. Villa Real <lucasvr@users.noreply.github.com>
Co-authored-by: Davide Rovelli <103165301+daviderud@users.noreply.github.com>
Co-authored-by: Gaurav Chaturvedi <oddtazz@users.noreply.github.com>
Co-authored-by: RocketGod <57732082+RocketGod-git@users.noreply.github.com>
Co-authored-by: Lerold <github@lerold.slmail.me>
Co-authored-by: Brumi-2021 <86470699+Brumi-2021@users.noreply.github.com>
Co-authored-by: dark-juju <2839275+dark-juju@users.noreply.github.com>
Co-authored-by: Benjamin Møller <37707273+LupusE@users.noreply.github.com>
Co-authored-by: Oleg Belousov <belousov.oleg@gmail.com>
Co-authored-by: haruk <104354987+exe-noisy@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Luca <61653175+iu2frl@users.noreply.github.com>
Co-authored-by: Richard <richard.toy@gmail.com>
Co-authored-by: zxkmm <zxkmm@hotmail.com>
Co-authored-by: horrordash <45861453+horrordash@users.noreply.github.com>
Co-authored-by: Alien <2142224+mythic-alien@users.noreply.github.com>
Co-authored-by: Petro Danylevskyi <petro@danylevskyi.com>
Co-authored-by: Tommaso Ventafridda <33782489+tomventa@users.noreply.github.com>
Co-authored-by: Netro <146584182+iNetro@users.noreply.github.com>
Co-authored-by: plomek <86431917+plomek@users.noreply.github.com>
Co-authored-by: TJ <tj.baginski@cognosos.com>
2025-07-11 16:33:21 +02:00

1470 lines
56 KiB
C++

/*
* Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc.
* Copyright (C) 2018 Furrtek
* Copyright (C) 2023 gullradriel, Nilorea Studio 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_recon.hpp"
#include "ui_freqman.hpp"
#include "capture_app.hpp"
#include "convert.hpp"
#include "file.hpp"
#include "file_reader.hpp"
#include "tone_key.hpp"
#include "string_format.hpp"
#include "ui_fileman.hpp"
#include "io_file.hpp"
#include "io_convert.hpp"
#include "oversample.hpp"
#include "baseband_api.hpp"
#include "metadata_file.hpp"
#include "portapack.hpp"
#include "portapack_persistent_memory.hpp"
#include "utility.hpp"
#include "replay_thread.hpp"
using namespace portapack;
using namespace tonekey;
using portapack::memory::map::backup_ram;
namespace fs = std::filesystem;
namespace ui {
void ReconView::reload_restart_recon() {
// force reload of current
change_mode(field_mode.selected_index_value());
uint8_t previous_index = current_index;
reset_indexes();
frequency_file_load();
current_index = previous_index;
handle_retune();
if (frequency_list.size() > 0) {
if (fwd) {
button_dir.set_text("FW>");
} else {
button_dir.set_text("<RW");
}
recon_resume();
}
if (scanner_mode) {
file_name.set_style(Theme::getInstance()->fg_red);
button_scanner_mode.set_style(Theme::getInstance()->fg_red);
button_scanner_mode.set_text("SCAN");
} else {
file_name.set_style(Theme::getInstance()->fg_blue);
button_scanner_mode.set_style(Theme::getInstance()->fg_blue);
button_scanner_mode.set_text("RECON");
}
if (frequency_list.size() > FREQMAN_MAX_PER_FILE) {
file_name.set_style(Theme::getInstance()->fg_yellow);
}
}
void ReconView::check_update_ranges_from_current() {
if (frequency_list.size() && current_is_valid() && current_entry().type == freqman_type::Range) {
if (update_ranges && !manual_mode) {
button_manual_start.set_text(to_string_short_freq(current_entry().frequency_a));
frequency_range.min = current_entry().frequency_a;
if (current_entry().frequency_b != 0) {
button_manual_end.set_text(to_string_short_freq(current_entry().frequency_b));
frequency_range.max = current_entry().frequency_b;
} else {
button_manual_end.set_text(to_string_short_freq(current_entry().frequency_a));
frequency_range.max = current_entry().frequency_a;
}
}
}
}
bool ReconView::current_is_valid() {
return (unsigned)current_index < frequency_list.size();
}
freqman_entry& ReconView::current_entry() {
return *frequency_list[current_index];
}
void ReconView::set_loop_config(bool v) {
continuous = v;
button_loop_config.set_style(v ? Theme::getInstance()->fg_green : Theme::getInstance()->bg_darkest);
persistent_memory::set_recon_continuous(continuous);
}
void ReconView::recon_stop_recording(bool exiting) {
if (is_recording) {
record_view->stop();
is_recording = false;
if (field_mode.selected_index_value() == SPEC_MODULATION) {
button_audio_app.set_text("RAW");
// repeater mode
if (!exiting && persistent_memory::recon_repeat_recorded()) {
start_repeat();
}
} else {
button_audio_app.set_text("AUDIO");
}
button_audio_app.set_style(Theme::getInstance()->bg_darkest);
button_config.set_style(Theme::getInstance()->bg_darkest);
}
}
void ReconView::clear_freqlist_for_ui_action() {
recon_stop_recording(false);
if (field_mode.selected_index_value() != SPEC_MODULATION)
audio::output::stop();
// flag to detect and reload frequency_list
if (!manual_mode) {
// Clear doesn't actually free, re-assign so destructor runs on previous instance.
frequency_list = freqman_db{};
} else
frequency_list.shrink_to_fit();
freqlist_cleared_for_ui_action = true;
}
void ReconView::reset_indexes() {
last_entry.modulation = freqman_invalid_index;
last_entry.bandwidth = freqman_invalid_index;
last_entry.step = freqman_invalid_index;
current_index = 0;
}
void ReconView::update_description() {
if (frequency_list.empty() || current_entry().description.empty()) {
description = "...no description...";
} else {
switch (current_entry().type) {
case freqman_type::Range:
description = "R: ";
break;
case freqman_type::HamRadio:
description = "H: ";
break;
case freqman_type::Repeater:
description = "L: ";
break;
default:
description = "S: ";
}
description += current_entry().description;
}
desc_cycle.set(description);
}
void ReconView::colorize_waits() {
// colorize wait on match
if (wait == 0) {
field_wait.set_style(Theme::getInstance()->fg_blue);
} else if (wait >= 500) {
field_wait.set_style(Theme::getInstance()->bg_darkest);
} else if (wait > -500 && wait < 500) {
field_wait.set_style(Theme::getInstance()->fg_red);
} else if (wait <= -500) {
field_wait.set_style(Theme::getInstance()->fg_green);
}
// colorize lock time if in SPARSE mode as in continuous the lock_wait time is disarmed at first lock count
if (recon_match_mode == RECON_MATCH_SPARSE) {
if ((recon_lock_duration / STATS_UPDATE_INTERVAL) <= recon_lock_nb_match) {
field_lock_wait.set_style(Theme::getInstance()->fg_yellow);
} else {
field_lock_wait.set_style(Theme::getInstance()->bg_darkest);
}
} else {
field_lock_wait.set_style(Theme::getInstance()->bg_darkest);
}
}
bool ReconView::recon_save_freq(const fs::path& path, size_t freq_index, bool warn_if_exists) {
if (frequency_list.size() == 0 || !current_is_valid())
return false;
FreqmanDB freq_db;
if (!freq_db.open(path, /*create*/ true))
return false;
freqman_entry entry = *frequency_list[freq_index]; // Makes a copy.
// For ranges, save the current frequency instead.
if (entry.type == freqman_type::Range) {
entry.frequency_a = freq;
entry.frequency_b = 0;
entry.type = freqman_type::Single;
entry.modulation = last_entry.modulation;
entry.bandwidth = last_entry.bandwidth;
entry.step = freqman_invalid_index;
}
auto it = freq_db.find_entry(entry);
auto found = (it != freq_db.end());
if (found && warn_if_exists)
nav_.display_modal("Error", "Frequency already exists");
if (!found)
freq_db.append_entry(entry);
return true;
}
void ReconView::load_persisted_settings() {
autostart = persistent_memory::recon_autostart_recon();
autosave = persistent_memory::recon_autosave_freqs();
continuous = persistent_memory::recon_continuous();
filedelete = persistent_memory::recon_clear_output();
load_freqs = persistent_memory::recon_load_freqs();
load_ranges = persistent_memory::recon_load_ranges();
load_hamradios = persistent_memory::recon_load_hamradios();
load_repeaters = persistent_memory::recon_load_repeaters();
update_ranges = persistent_memory::recon_update_ranges_when_recon();
auto_record_locked = persistent_memory::recon_auto_record_locked();
}
void ReconView::audio_output_start() {
if (field_mode.selected_index_value() != SPEC_MODULATION)
audio::output::start();
receiver_model.set_headphone_volume(receiver_model.headphone_volume()); // WM8731 hack.
}
void ReconView::recon_redraw() {
if (last_rssi_min != rssi.get_min() || last_rssi_med != rssi.get_avg() || last_rssi_max != rssi.get_max()) {
last_rssi_min = rssi.get_min();
last_rssi_med = rssi.get_avg();
last_rssi_max = rssi.get_max();
freq_stats.set("RSSI: " + to_string_dec_int(rssi.get_min()) + "/" + to_string_dec_int(rssi.get_avg()) + "/" + to_string_dec_int(rssi.get_max()) + " db");
}
if (last_entry.frequency_a != freq) {
last_entry.frequency_a = freq;
big_display.set("FREQ:" + to_string_short_freq(freq) + " MHz");
}
if (last_nb_match != recon_lock_nb_match || last_freq_lock != freq_lock) {
last_freq_lock = freq_lock;
last_nb_match = recon_lock_nb_match;
text_nb_locks.set(to_string_dec_uint(freq_lock) + "/" + to_string_dec_uint(recon_lock_nb_match));
if (freq_lock == 0) {
// NO FREQ LOCK, ONGOING STANDARD SCANNING
big_display.set_style(Theme::getInstance()->bg_darkest);
if (recon)
button_pause.set_text("<PAUSE>");
else
button_pause.set_text("<RESUME>");
} else if (freq_lock == 1 && recon_lock_nb_match != 1) {
// STARTING LOCK FREQ
big_display.set_style(Theme::getInstance()->fg_yellow);
button_pause.set_text("<SKPLCK>");
} else if (freq_lock >= recon_lock_nb_match) {
big_display.set_style(Theme::getInstance()->fg_green);
button_pause.set_text("<UNLOCK>");
}
}
if (last_db != db || last_list_size != frequency_list.size()) {
last_list_size = frequency_list.size();
last_db = db;
text_max.set("/" + to_string_dec_uint(frequency_list.size()) + " " + to_string_dec_int(db) + " db");
}
}
void ReconView::handle_retune() {
if (last_freq != freq) {
last_freq = freq;
receiver_model.set_target_frequency(freq); // Retune
}
if (frequency_list.size() > 0) {
if (last_entry.modulation != current_entry().modulation && is_valid(current_entry().modulation)) {
last_entry.modulation = current_entry().modulation;
field_mode.set_selected_index(current_entry().modulation);
last_entry.bandwidth = freqman_invalid_index;
}
// Set bandwidth if any
if (last_entry.bandwidth != current_entry().bandwidth && is_valid(current_entry().bandwidth)) {
last_entry.bandwidth = current_entry().bandwidth;
field_bw.set_selected_index(current_entry().bandwidth);
}
if (last_entry.step != current_entry().step && is_valid(current_entry().step)) {
last_entry.step = current_entry().step;
step = freqman_entry_get_step_value(last_entry.step);
step_mode.set_selected_index(step);
}
if (last_index != current_index) {
last_index = current_index;
check_update_ranges_from_current();
text_cycle.set_text(to_string_dec_uint(current_index + 1, 3));
update_description();
}
}
}
void ReconView::focus() {
button_pause.focus();
}
ReconView::~ReconView() {
if (recon_tx) {
replay_thread.reset();
}
recon_stop_recording(true);
if (field_mode.selected_index_value() != SPEC_MODULATION)
audio::output::stop();
transmitter_model.disable();
receiver_model.disable();
baseband::shutdown();
}
ReconView::ReconView(NavigationView& nav)
: nav_{nav} {
chrono_start = chTimeNow();
tx_view.hidden(true);
// set record View
record_view = std::make_unique<RecordView>(Rect{0, 0, screen_width, 1 * 16},
u"AUTO_AUDIO", audio_dir,
RecordView::FileType::WAV, 4096, 4);
record_view->set_filename_date_frequency(true);
record_view->set_auto_trim(false);
record_view->hidden(true);
record_view->on_error = [&nav](std::string message) {
nav.display_modal("Error", message);
};
add_children({&labels,
&field_lna,
&field_vga,
&field_rf_amp,
&field_volume,
&field_bw,
&field_squelch,
&field_nblocks,
&field_wait,
&field_lock_wait,
&button_config,
&button_scanner_mode,
&button_loop_config,
&file_name,
&rssi,
&text_cycle,
&text_max,
&text_nb_locks,
&desc_cycle,
&big_display,
&freq_stats,
&text_timer,
&text_ctcss,
&button_manual_start,
&button_manual_end,
&button_manual_recon,
&field_mode,
&field_recon_match_mode,
&step_mode,
&button_pause,
&button_audio_app,
&button_add,
&button_dir,
&button_restart,
&button_mic_app,
&button_remove,
record_view.get(),
&progressbar,
&tx_view});
def_step = 0;
load_persisted_settings();
// When update_ranges is set or range invalid, use the rx model frequency instead of the saved values.
if (update_ranges || frequency_range.max == 0) {
rf::Frequency stored_freq = receiver_model.target_frequency();
frequency_range.min = clip<rf::Frequency>(stored_freq - OneMHz, 0, MAX_UFREQ);
frequency_range.max = clip<rf::Frequency>(stored_freq + OneMHz, 0, MAX_UFREQ);
}
button_manual_start.set_text(to_string_short_freq(frequency_range.min));
button_manual_end.set_text(to_string_short_freq(frequency_range.max));
button_manual_start.on_select = [this, &nav](ButtonWithEncoder& button) {
clear_freqlist_for_ui_action();
auto new_view = nav_.push<FrequencyKeypadView>(frequency_range.min);
new_view->on_changed = [this, &button](rf::Frequency f) {
frequency_range.min = f;
button_manual_start.set_text(to_string_short_freq(f));
};
};
button_manual_end.on_select = [this, &nav](ButtonWithEncoder& button) {
clear_freqlist_for_ui_action();
auto new_view = nav.push<FrequencyKeypadView>(frequency_range.max);
new_view->on_changed = [this, &button](rf::Frequency f) {
frequency_range.max = f;
button_manual_end.set_text(to_string_short_freq(f));
};
};
text_cycle.on_select = [this, &nav](ButtonWithEncoder& button) {
if (frequency_list.size() > 0) {
auto new_view = nav_.push<FrequencyKeypadView>(current_index);
new_view->on_changed = [this, &button](rf::Frequency f) {
// NB: This is using the freq keypad to select an index.
f = f / OneMHz;
if (f >= 1 && f <= frequency_list.size()) {
index_stepper = f - 1 - current_index;
freq_lock = 0;
}
};
}
};
button_manual_start.on_change = [this]() {
auto step_val = freqman_entry_get_step_value(def_step);
frequency_range.min = frequency_range.min + button_manual_start.get_encoder_delta() * step_val;
if (frequency_range.min < 0) {
frequency_range.min = 0;
}
if (frequency_range.min > (MAX_UFREQ - step_val)) {
frequency_range.min = MAX_UFREQ - step_val;
}
if (frequency_range.min > (frequency_range.max - step_val)) {
frequency_range.max = frequency_range.min + step_val;
if (frequency_range.max > MAX_UFREQ) {
frequency_range.min = MAX_UFREQ - step_val;
frequency_range.max = MAX_UFREQ;
}
}
button_manual_start.set_text(to_string_short_freq(frequency_range.min));
button_manual_end.set_text(to_string_short_freq(frequency_range.max));
button_manual_start.set_encoder_delta(0);
};
button_manual_end.on_change = [this]() {
auto step_val = freqman_entry_get_step_value(def_step);
frequency_range.max = frequency_range.max + button_manual_end.get_encoder_delta() * step_val;
if (frequency_range.max < (step_val + 1)) {
frequency_range.max = (step_val + 1);
}
if (frequency_range.max > MAX_UFREQ) {
frequency_range.max = MAX_UFREQ;
}
if (frequency_range.max < (frequency_range.min + step_val)) {
frequency_range.min = frequency_range.max - step_val;
if (frequency_range.max < (step_val + 1)) {
frequency_range.min = 1;
frequency_range.max = (step_val + 1);
}
}
button_manual_start.set_text(to_string_short_freq(frequency_range.min));
button_manual_end.set_text(to_string_short_freq(frequency_range.max));
button_manual_end.set_encoder_delta(0);
};
text_cycle.on_change = [this]() {
on_index_delta(text_cycle.get_encoder_delta());
text_cycle.set_encoder_delta(0);
};
button_pause.on_select = [this](ButtonWithEncoder&) {
if (frequency_list.size() > 0) {
if (freq_lock > 0) {
if (fwd) {
on_stepper_delta(1);
} else {
on_stepper_delta(-1);
}
button_pause.set_text("<PAUSE>"); // Show button for non continuous stop
} else {
if (!recon) {
recon_resume();
user_pause = false;
} else {
recon_pause();
user_pause = true;
}
}
}
};
button_pause.on_change = [this]() {
on_stepper_delta(button_pause.get_encoder_delta());
button_pause.set_encoder_delta(0);
};
button_audio_app.on_select = [this](Button&) {
auto settings = receiver_model.settings();
settings.frequency_step = step_mode.selected_index_value();
if (field_mode.selected_index_value() == SPEC_MODULATION)
nav_.replace<CaptureAppView>(settings);
else
nav_.replace<AnalogAudioView>(settings);
};
button_loop_config.on_select = [this](Button&) {
set_loop_config(!continuous);
};
set_loop_config(continuous);
rssi.set_peak(true, 500);
// TODO: *BUG* Both transmitter_model and receiver_model share the same pmem setting for target_frequency.
button_mic_app.on_select = [this](Button&) {
if (frequency_list.size() > 0 && current_index >= 0 && (unsigned)current_index < frequency_list.size()) {
if (current_entry().type == freqman_type::HamRadio) {
// if it's a HamRadio entry, then frequency_a is the freq at which the repeater receives, so we have to set it in transmit in mic app
transmitter_model.set_target_frequency(current_entry().frequency_a);
// if it's a HamRadio entry, then frequency_b is the freq at which the repeater transmits, so we have to set it in receive in mic app
receiver_model.set_target_frequency(current_entry().frequency_b);
} else {
// it's single or range so we us actual tuned frequency
transmitter_model.set_target_frequency(freq);
receiver_model.set_target_frequency(freq);
}
}
// MicTX wants Frequency, Modulation and Bandwidth overrides, but that's only stored on the RX model.
nav_.replace<MicTXView>(receiver_model.settings());
};
button_remove.on_select = [this](ButtonWithEncoder&) {
handle_remove_current_item();
timer = 0;
freq_lock = 0;
recon_redraw();
};
button_remove.on_change = [this]() {
on_stepper_delta(button_remove.get_encoder_delta());
button_remove.set_encoder_delta(0);
};
button_manual_recon.on_select = [this](Button&) {
button_remove.set_text("<DELETE>");
button_add.hidden(false);
scanner_mode = false;
manual_mode = true;
recon_pause();
if (!frequency_range.min || !frequency_range.max) {
nav_.display_modal("Error", "Both START and END freqs\nneed a value");
} else {
if (frequency_range.min > frequency_range.max) {
std::swap(frequency_range.min, frequency_range.max);
button_manual_start.set_text(to_string_short_freq(frequency_range.min));
button_manual_end.set_text(to_string_short_freq(frequency_range.max));
}
// no need to stop audio in SPEC
if (field_mode.selected_index_value() != SPEC_MODULATION)
audio::output::stop();
// Clear doesn't actually free, re-assign so destructor runs on previous instance.
frequency_list = freqman_db{};
current_index = 0;
frequency_list.push_back(std::make_unique<freqman_entry>());
def_step = step_mode.selected_index();
current_entry().type = freqman_type::Range;
current_entry().description =
to_string_short_freq(frequency_range.min).erase(0, 1) + ">" + // euquiq: lame kludge to reduce spacing in step freq
to_string_short_freq(frequency_range.max).erase(0, 1) + " S:" +
freqman_entry_get_step_string_short(def_step);
current_entry().frequency_a = frequency_range.min;
current_entry().frequency_b = frequency_range.max;
current_entry().modulation = freqman_invalid_index;
current_entry().bandwidth = freqman_invalid_index;
current_entry().step = def_step;
big_display.set_style(Theme::getInstance()->bg_darkest); // Back to white color
freq_stats.set_style(Theme::getInstance()->bg_darkest);
freq_stats.set("0/0/0");
text_cycle.set_text("1");
text_max.set("/1");
button_scanner_mode.set_style(Theme::getInstance()->bg_darkest);
button_scanner_mode.set_text("MANUAL");
file_name.set_style(Theme::getInstance()->bg_darkest);
file_name.set("MANUAL => " + output_file);
desc_cycle.set_style(Theme::getInstance()->bg_darkest);
last_entry.modulation = freqman_invalid_index;
last_entry.bandwidth = freqman_invalid_index;
last_entry.step = freqman_invalid_index;
last_index = -1;
freq = current_entry().frequency_a;
handle_retune();
recon_redraw();
recon_resume();
}
};
button_dir.on_select = [this](Button&) {
if (fwd) {
fwd = false;
button_dir.set_text("<RW");
} else {
fwd = true;
button_dir.set_text("FW>");
}
timer = 0;
if (!recon)
recon_resume();
};
button_restart.on_select = [this](Button&) {
reload_restart_recon();
};
button_add.on_select = [this](ButtonWithEncoder&) {
if (!scanner_mode) {
recon_save_freq(freq_file_path, current_index, true);
}
};
button_add.on_change = [this]() {
on_stepper_delta(button_add.get_encoder_delta());
button_add.set_encoder_delta(0);
};
button_scanner_mode.on_select = [this, &nav](Button&) {
manual_mode = false;
if (scanner_mode) {
scanner_mode = false;
button_scanner_mode.set_style(Theme::getInstance()->fg_blue);
button_scanner_mode.set_text("RECON");
button_remove.set_text("<REMOVE>");
} else {
scanner_mode = true;
button_scanner_mode.set_style(Theme::getInstance()->fg_red);
button_scanner_mode.set_text("SCAN");
button_remove.set_text("<DELETE>");
}
frequency_file_load();
if (autostart) {
recon_resume();
} else {
recon_pause();
}
button_add.hidden(scanner_mode);
if (scanner_mode) // only needed when hiding, UI mayhem
set_dirty();
};
button_config.on_select = [this, &nav](Button&) {
if (is_recording) // disabling config while recording
return;
clear_freqlist_for_ui_action();
freq_lock = 0;
timer = 0;
auto open_view = nav.push<ReconSetupView>(input_file, output_file);
open_view->on_changed = [this](std::vector<std::string> result) {
input_file = result[0];
output_file = result[1];
freq_file_path = get_freqman_path(output_file).string();
load_persisted_settings();
ui_settings.save();
frequency_file_load();
freqlist_cleared_for_ui_action = false;
if (autostart) {
recon_resume();
} else {
recon_pause();
}
};
};
field_recon_match_mode.on_change = [this](size_t, OptionsField::value_t v) {
recon_match_mode = v;
colorize_waits();
};
field_wait.on_change = [this](int32_t v) {
wait = v;
// replacing -100 by 200 else it's freezing the device
if (wait == -100)
wait = -200;
colorize_waits();
};
field_nblocks.on_change = [this](int32_t v) {
recon_lock_nb_match = v;
if ((unsigned)v < freq_lock)
freq_lock = v;
colorize_waits();
};
field_lock_wait.on_change = [this](uint32_t v) {
recon_lock_duration = v;
colorize_waits();
};
field_squelch.on_change = [this](int32_t v) {
squelch = v;
};
// PRE-CONFIGURATION:
button_scanner_mode.set_style(Theme::getInstance()->fg_blue);
button_scanner_mode.set_text("RECON");
file_name.set("=>");
// Loading input and output file from settings
freq_file_path = get_freqman_path(output_file).string();
field_recon_match_mode.set_selected_index(recon_match_mode);
field_squelch.set_value(squelch);
field_wait.set_value(wait);
field_lock_wait.set_value(recon_lock_duration);
field_nblocks.set_value(recon_lock_nb_match);
colorize_waits();
// fill modulation and step options
freqman_set_modulation_option(field_mode);
freqman_set_step_option(step_mode);
// set radio
change_mode(AM_MODULATION); // start on AM.
field_mode.set_by_value(AM_MODULATION); // reflect the mode into the manual selector
// tx progress bar
progressbar.hidden(true);
if (filedelete) {
delete_file(freq_file_path);
}
frequency_file_load(); /* do not stop all at start */
if (autostart) {
recon_resume();
} else {
recon_pause();
}
recon_redraw();
}
void ReconView::frequency_file_load() {
if (field_mode.selected_index_value() != SPEC_MODULATION)
audio::output::stop();
def_step = step_mode.selected_index(); // use def_step from manual selector
std::string file_input = input_file; // default recon mode
if (scanner_mode) {
file_input = output_file;
file_name.set_style(Theme::getInstance()->fg_red);
button_scanner_mode.set_style(Theme::getInstance()->fg_red);
desc_cycle.set_style(Theme::getInstance()->fg_red);
button_scanner_mode.set_text("SCAN");
} else {
file_name.set_style(Theme::getInstance()->fg_blue);
button_scanner_mode.set_style(Theme::getInstance()->fg_blue);
desc_cycle.set_style(Theme::getInstance()->fg_blue);
button_scanner_mode.set_text("RECON");
}
file_name.set(file_input + "=>" + output_file);
freqman_load_options options{
.load_freqs = load_freqs,
.load_ranges = load_ranges,
.load_hamradios = load_hamradios,
.load_repeaters = load_repeaters};
if (!load_freqman_file(file_input, frequency_list, options) || frequency_list.empty()) {
file_name.set_style(Theme::getInstance()->fg_red);
desc_cycle.set("...empty file...");
frequency_list.clear();
text_cycle.set_text(" ");
return;
}
if (frequency_list.size() > FREQMAN_MAX_PER_FILE) {
file_name.set_style(Theme::getInstance()->fg_yellow);
}
reset_indexes();
step = freqman_entry_get_step_value(
is_valid(current_entry().step) ? current_entry().step : def_step);
if (current_entry().type == freqman_type::Single) {
freq = current_entry().frequency_a;
} else if (current_entry().type != freqman_type::Unknown) {
minfreq = current_entry().frequency_a;
maxfreq = current_entry().frequency_b;
freq = fwd ? minfreq : maxfreq;
}
step_mode.set_selected_index(def_step); // Impose the default step into the manual step selector
receiver_model.enable();
receiver_model.set_squelch_level(0);
text_cycle.set_text(to_string_dec_uint(current_index + 1, 3));
check_update_ranges_from_current();
update_description();
handle_retune();
}
void ReconView::on_statistics_update(const ChannelStatistics& statistics) {
if (recon_tx)
return;
if (is_repeat_active())
return;
chrono_end = chTimeNow();
systime_t time_interval = chrono_end - chrono_start;
chrono_start = chrono_end;
// hack to reload the list if it was cleared by going into CONFIG
if (freqlist_cleared_for_ui_action) {
if (!manual_mode) {
frequency_file_load();
}
if (autostart && !user_pause) {
recon_resume();
} else {
recon_pause();
}
freqlist_cleared_for_ui_action = false;
}
db = statistics.max_db;
if (recon) {
if (!timer) {
status = 0;
freq_lock = 0;
timer = recon_lock_duration;
}
if (freq_lock < recon_lock_nb_match) // LOCKING
{
if (status != 1) {
status = 1;
if (wait != 0) {
recon_stop_recording(false);
if (field_mode.selected_index_value() != SPEC_MODULATION)
audio::output::stop();
}
}
if (db > squelch) // MATCHING LEVEL
{
freq_lock++;
timer += time_interval; // give some more time for next lock
} else {
// continuous, direct cut it if not consecutive match after 1 first match
if (recon_match_mode == RECON_MATCH_CONTINUOUS) {
freq_lock = 0;
timer = 0;
}
}
}
if (freq_lock >= recon_lock_nb_match) // LOCKED
{
if (status != 2) {
status = 2;
// FREQ IS STRONG: GREEN and recon will pause when on_statistics_update()
if ((!scanner_mode) && autosave && frequency_list.size() > 0) {
recon_save_freq(freq_file_path, current_index, false);
}
if (wait != 0) {
if (field_mode.selected_index_value() != SPEC_MODULATION)
audio_output_start();
// contents of a possible recon_start_recording(), but not yet since it's only called once
if (auto_record_locked && !is_recording) {
button_audio_app.set_style(Theme::getInstance()->fg_red);
if (field_mode.selected_index_value() == SPEC_MODULATION) {
button_audio_app.set_text("RAW REC");
} else
button_audio_app.set_text("WAV REC");
record_view->start();
button_config.set_style(Theme::getInstance()->fg_light); // disable config while recording as it's causing an IO error pop up at exit
is_recording = true;
}
// FREQ IS STRONG: GREEN and recon will pause when on_statistics_update()
if ((!scanner_mode) && autosave && frequency_list.size() > 0) {
recon_save_freq(freq_file_path, current_index, false);
}
}
if (wait >= 0) {
timer = wait;
}
}
if (wait < 0) {
if (db > squelch) // MATCHING LEVEL IN STAY X AFTER LAST ACTIVITY
{
timer = abs(wait);
}
}
}
}
if (last_timer != timer) {
last_timer = timer;
text_timer.set("TIMER: " + to_string_dec_int(timer));
}
if (timer != 0) {
timer -= time_interval;
if (timer < 0) {
timer = 0;
}
}
if (recon || stepper != 0 || index_stepper != 0) {
if (!timer || stepper != 0 || index_stepper != 0) {
// IF THERE IS A FREQUENCY LIST ...
if (frequency_list.size() > 0) {
has_looped = false;
entry_has_changed = false;
if (recon || stepper != 0 || index_stepper != 0) {
if (index_stepper == 0) {
/* we are doing a range */
if (current_entry().type == freqman_type::Range) {
if ((fwd && stepper == 0) || stepper > 0) {
// forward
freq += step;
// if bigger than range max
if (freq > maxfreq) {
// when going forward we already know that we can skip a whole range => two values in the list
current_index++;
entry_has_changed = true;
// looping
if ((uint32_t)current_index >= frequency_list.size()) {
has_looped = true;
current_index = 0;
}
}
} else if ((!fwd && stepper == 0) || stepper < 0) {
// reverse
freq -= step;
// if lower than range min
if (freq < minfreq) {
// when back we have to check one step at a time
current_index--;
entry_has_changed = true;
// looping
if (current_index < 0) {
has_looped = true;
current_index = frequency_list.size() - 1;
}
}
}
} else if (current_entry().type == freqman_type::Single) {
if ((fwd && stepper == 0) || stepper > 0) { // forward
current_index++;
entry_has_changed = true;
// looping
if ((uint32_t)current_index >= frequency_list.size()) {
has_looped = true;
current_index = 0;
}
} else if ((!fwd && stepper == 0) || stepper < 0) {
// reverse
current_index--;
entry_has_changed = true;
// if previous if under the list => go back from end
if (current_index < 0) {
has_looped = true;
current_index = frequency_list.size() - 1;
}
}
} else if (current_entry().type == freqman_type::HamRadio) {
if ((fwd && stepper == 0) || stepper > 0) { // forward
if ((minfreq != maxfreq) && freq == minfreq) {
freq = maxfreq;
} else {
current_index++;
entry_has_changed = true;
// looping
if ((uint32_t)current_index >= frequency_list.size()) {
has_looped = true;
current_index = 0;
}
}
} else if ((!fwd && stepper == 0) || stepper < 0) {
// reverse
if ((minfreq != maxfreq) && freq == maxfreq) {
freq = minfreq;
} else {
current_index--;
entry_has_changed = true;
// if previous if under the list => go back from end
if (current_index < 0) {
has_looped = true;
current_index = frequency_list.size() - 1;
}
}
}
} else if (current_entry().type == freqman_type::Repeater) {
// repeater is like single, we only listen on frequency_a and then jump to next entry
if ((fwd && stepper == 0) || stepper > 0) { // forward
current_index++;
entry_has_changed = true;
// looping
if ((uint32_t)current_index >= frequency_list.size()) {
has_looped = true;
current_index = 0;
}
} else if ((!fwd && stepper == 0) || stepper < 0) {
// reverse
current_index--;
entry_has_changed = true;
// if previous if under the list => go back from end
if (current_index < 0) {
has_looped = true;
current_index = frequency_list.size() - 1;
}
}
}
// set index to boundary if !continuous
if (has_looped && !continuous) {
entry_has_changed = true;
/* prepare values for the next run, when user will resume */
if ((fwd && stepper == 0) || stepper > 0) {
current_index = 0;
} else if ((!fwd && stepper == 0) || stepper < 0) {
current_index = frequency_list.size() - 1;
}
}
} else {
current_index += index_stepper;
if (current_index < 0)
current_index += frequency_list.size();
if ((unsigned)current_index >= frequency_list.size())
current_index -= frequency_list.size();
entry_has_changed = true;
// for some motive, audio output gets stopped.
if (!recon && field_mode.selected_index_value() != SPEC_MODULATION)
audio_output_start();
}
// reload entry if changed
if (entry_has_changed) {
timer = 0;
switch (current_entry().type) {
case freqman_type::Repeater:
case freqman_type::Single:
freq = current_entry().frequency_a;
break;
case freqman_type::Range:
minfreq = current_entry().frequency_a;
maxfreq = current_entry().frequency_b;
if ((fwd && !stepper && !index_stepper) || stepper > 0 || index_stepper > 0) {
freq = minfreq;
} else if ((!fwd && !stepper && !index_stepper) || stepper < 0 || index_stepper < 0) {
freq = maxfreq;
}
break;
case freqman_type::HamRadio:
minfreq = current_entry().frequency_a;
maxfreq = current_entry().frequency_b;
if ((fwd && !stepper && !index_stepper) || stepper > 0 || index_stepper > 0) {
freq = minfreq;
} else if ((!fwd && !stepper && !index_stepper) || stepper < 0 || index_stepper < 0) {
freq = maxfreq;
}
break;
default:
break;
}
}
if (has_looped && !continuous) {
recon_pause();
}
index_stepper = 0;
if (stepper < 0) stepper++;
if (stepper > 0) stepper--;
} // if( recon || stepper != 0 || index_stepper != 0 )
} // if (frequency_list.size() > 0 )
} /* on_statistics_updates */
}
handle_retune();
recon_redraw();
}
void ReconView::recon_pause() {
timer = 0;
freq_lock = 0;
recon = false;
if (field_mode.selected_index_value() != SPEC_MODULATION)
audio_output_start();
big_display.set_style(Theme::getInstance()->bg_darkest);
button_pause.set_text("<RESUME>"); // PAUSED, show resume
}
void ReconView::recon_resume() {
timer = 0;
freq_lock = 0;
recon = true;
if (field_mode.selected_index_value() != SPEC_MODULATION)
audio::output::stop();
big_display.set_style(Theme::getInstance()->bg_darkest);
button_pause.set_text("<PAUSE>");
}
void ReconView::on_index_delta(int32_t v) {
if (v > 0) {
fwd = true;
button_dir.set_text("FW>");
}
if (v < 0) {
fwd = false;
button_dir.set_text("<RW");
}
if (frequency_list.size() > 0)
index_stepper = v;
freq_lock = 0;
timer = 0;
}
void ReconView::on_stepper_delta(int32_t v) {
if (v > 0) {
fwd = true;
button_dir.set_text("FW>");
}
if (v < 0) {
fwd = false;
button_dir.set_text("<RW");
}
if (frequency_list.size() > 0)
stepper = v;
freq_lock = 0;
timer = 0;
}
size_t ReconView::change_mode(freqman_index_t new_mod) {
if (recon_tx || is_repeat_active() || is_recording)
return 0;
field_mode.on_change = [this](size_t, OptionsField::value_t) {};
field_bw.on_change = [this](size_t, OptionsField::value_t) {};
recon_stop_recording(false);
if (record_view != nullptr) {
remove_child(record_view.get());
record_view.reset();
}
if (field_mode.selected_index_value() != SPEC_MODULATION) {
audio::output::stop();
}
if (new_mod == SPEC_MODULATION) {
if (persistent_memory::recon_repeat_recorded()) {
record_view = std::make_unique<RecordView>(Rect{0, 0, screen_width, 1 * 16},
u"RECON_REPEAT.C16", captures_dir,
RecordView::FileType::RawS16, 16384, 3);
record_view->set_filename_as_is(true);
} else {
record_view = std::make_unique<RecordView>(Rect{0, 0, screen_width, 1 * 16},
u"AUTO_RAW", captures_dir,
RecordView::FileType::RawS16, 16384, 3);
record_view->set_filename_date_frequency(true);
}
} else {
record_view = std::make_unique<RecordView>(Rect{0, 0, screen_width, 1 * 16},
u"AUTO_AUDIO", audio_dir,
RecordView::FileType::WAV, 4096, 4);
record_view->set_filename_date_frequency(true);
}
record_view->set_auto_trim(false);
add_child(record_view.get());
record_view->hidden(true);
record_view->on_error = [this](std::string message) {
nav_.display_modal("Error", message);
};
receiver_model.disable();
transmitter_model.disable();
baseband::shutdown();
size_t recording_sampling_rate = 0;
switch (new_mod) {
case AM_MODULATION:
freqman_set_bandwidth_option(new_mod, field_bw);
baseband::run_image(portapack::spi_flash::image_tag_am_audio);
receiver_model.set_modulation(ReceiverModel::Mode::AMAudio);
receiver_model.set_am_configuration(field_bw.selected_index_value());
field_bw.on_change = [this](size_t, OptionsField::value_t n) { receiver_model.set_am_configuration(n); };
// bw DSB (0) default
field_bw.set_by_value(0);
text_ctcss.set(" ");
recording_sampling_rate = 12000;
break;
case NFM_MODULATION:
freqman_set_bandwidth_option(new_mod, field_bw);
baseband::run_image(portapack::spi_flash::image_tag_nfm_audio);
receiver_model.set_modulation(ReceiverModel::Mode::NarrowbandFMAudio);
receiver_model.set_nbfm_configuration(field_bw.selected_index_value());
field_bw.on_change = [this](size_t, OptionsField::value_t n) { receiver_model.set_nbfm_configuration(n); };
// bw 16k (2) default
field_bw.set_by_value(2);
recording_sampling_rate = 24000;
break;
case WFM_MODULATION:
freqman_set_bandwidth_option(new_mod, field_bw);
baseband::run_image(portapack::spi_flash::image_tag_wfm_audio);
receiver_model.set_modulation(ReceiverModel::Mode::WidebandFMAudio);
receiver_model.set_wfm_configuration(field_bw.selected_index_value());
field_bw.on_change = [this](size_t, OptionsField::value_t n) { receiver_model.set_wfm_configuration(n); };
// bw 200k (0) default
field_bw.set_by_value(0);
text_ctcss.set(" ");
recording_sampling_rate = 48000;
break;
case SPEC_MODULATION:
freqman_set_bandwidth_option(new_mod, field_bw);
baseband::run_image(portapack::spi_flash::image_tag_capture);
receiver_model.set_modulation(ReceiverModel::Mode::Capture);
field_bw.on_change = [this](size_t, OptionsField::value_t sampling_rate) {
// record_view determines the correct oversampling to apply and returns the actual sample rate.
auto actual_sampling_rate = record_view->set_sampling_rate(sampling_rate);
// The radio needs to know the effective sampling rate.
receiver_model.set_sampling_rate(actual_sampling_rate);
receiver_model.set_baseband_bandwidth(filter_bandwidth_for_sampling_rate(actual_sampling_rate));
};
// bw 12k5 (0) default
field_bw.set_by_value(0);
text_ctcss.set(" ");
break;
default:
break;
}
if (new_mod != SPEC_MODULATION) {
button_audio_app.set_text("AUDIO");
record_view->set_sampling_rate(recording_sampling_rate);
// reset receiver model to fix bug when going from SPEC to audio, the sound is distorted
receiver_model.set_sampling_rate(3072000);
receiver_model.set_baseband_bandwidth(1750000);
} else {
button_audio_app.set_text("RAW");
}
field_mode.set_selected_index(new_mod);
field_mode.on_change = [this](size_t, OptionsField::value_t v) {
// initialize to a value under SPEC
static freqman_index_t last_mode = WFM_MODULATION;
if (v > SPEC_MODULATION) {
if (last_mode == SPEC_MODULATION)
v = AM_MODULATION;
else
v = SPEC_MODULATION;
field_mode.set_selected_index(v);
}
last_mode = v;
change_mode(v);
};
// for some motive, audio output gets stopped.
if (!recon && field_mode.selected_index_value() != SPEC_MODULATION)
audio::output::start(); // so if recon was stopped we resume audio
receiver_model.enable();
return freqman_entry_get_step_value(def_step);
}
void ReconView::handle_coded_squelch(const uint32_t value) {
if (field_mode.selected_index() == NFM_MODULATION)
text_ctcss.set(tone_key_string_by_value(value, text_ctcss.parent_rect().width() / 8));
else
text_ctcss.set(" ");
}
void ReconView::handle_remove_current_item() {
if (frequency_list.empty() || !current_is_valid())
return;
auto entry = current_entry(); // Copy the current entry.
// In Scanner or Recon modes, remove from the in-memory list.
if (mode() != recon_mode::Manual) {
if (current_is_valid()) {
frequency_list.erase(frequency_list.begin() + current_index);
}
}
// In Scanner or Manual mode, remove the entry from the output file.
if (mode() != recon_mode::Recon) {
FreqmanDB freq_db;
if (!freq_db.open(freq_file_path))
return;
freq_db.delete_entry(entry);
}
// Clip
if (frequency_list.size() > 0) {
current_index = clip<int32_t>(current_index, 0u, frequency_list.size() - 1);
text_cycle.set_text(to_string_dec_uint(current_index + 1, 3));
entry = current_entry();
freq = entry.frequency_a;
} else {
current_index = 0;
text_cycle.set_text(" ");
}
update_description();
}
void ReconView::on_repeat_tx_progress(const uint32_t progress) {
progressbar.set_value(progress);
}
void ReconView::repeat_file_error(const std::filesystem::path& path, const std::string& message) {
nav_.display_modal("Error", "Error opening file \n" + path.string() + "\n" + message);
}
bool ReconView::is_repeat_active() const {
return replay_thread != nullptr;
}
void ReconView::start_repeat() {
// Prepare to send a file.
if (recon_tx == false) {
recon_tx = true;
if (record_view != nullptr) {
record_view->stop();
remove_child(record_view.get());
record_view.reset();
}
receiver_model.disable();
transmitter_model.disable();
baseband::shutdown();
baseband::run_image(portapack::spi_flash::image_tag_replay);
size_t rawsize = 0;
{
File capture_file;
auto error = capture_file.open(rawfile);
if (error) {
repeat_file_error(rawfile, "Can't open file to send for size");
return;
}
rawsize = capture_file.size();
}
// Reset the transmit progress bar.
uint8_t sample_size = std::filesystem::capture_file_sample_size(rawfile);
progressbar.set_value(0);
progressbar.set_max(rawsize * sizeof(complex16_t) / sample_size);
progressbar.hidden(false);
auto metadata = read_metadata_file(rawmeta);
// If no metadata found, fallback to the TX frequency.
if (!metadata) {
metadata = {freq, 500'000};
repeat_file_error(rawmeta, "Can't open file to read meta, using default rx_freq,500'000");
}
// Update the sample rate in proc_replay baseband.
baseband::set_sample_rate(metadata->sample_rate,
get_oversample_rate(metadata->sample_rate));
transmitter_model.set_sampling_rate(get_actual_sample_rate(metadata->sample_rate));
transmitter_model.set_baseband_bandwidth(metadata->sample_rate <= 500'000 ? 1'750'000 : 2'500'000); // TX LPF min 1M75 for SR <=500K, and 2M5 (by experimental test) for SR >500K
// set TX to repeater TX freq if entry is Repeater and have a valid freq, else use recorded one
if (current_entry().type == freqman_type::Repeater && current_entry().frequency_b != 0) {
transmitter_model.set_target_frequency(current_entry().frequency_b);
} else {
transmitter_model.set_target_frequency(metadata->center_frequency);
}
// set TX powers and enable transmitter
transmitter_model.set_tx_gain(persistent_memory::recon_repeat_gain());
transmitter_model.set_rf_amp(persistent_memory::recon_repeat_amp());
transmitter_model.enable();
}
// clear replay thread and set reader
replay_thread.reset();
auto reader = std::make_unique<FileConvertReader>();
auto error = reader->open(rawfile);
if (error) {
repeat_file_error(rawfile, "Can't open file to send to thread");
return;
}
// wait for TX if needed (hackish, direct screen update since the UI will be blocked)
if (persistent_memory::recon_repeat_delay() > 0) {
uint8_t delay = persistent_memory::recon_repeat_delay();
Painter p;
while (delay > 0) {
std::string delay_message = "TX DELAY: " + to_string_dec_uint(delay) + "s";
// update display information
p.fill_rectangle({0, (screen_height / 2) - 16, screen_width, 64}, Theme::getInstance()->fg_light->foreground);
p.draw_string({(screen_width / 2) - 7 * 8, screen_height / 2}, *Theme::getInstance()->fg_red, delay_message);
// sleep 1 second
chThdSleepMilliseconds(1000);
// decre delay
if (delay > 0)
delay = delay - 1;
else
break;
}
}
// ReplayThread starts immediately on construction; must be set before creating.
repeat_ready_signal = true;
repeat_cur_rep++;
replay_thread = std::make_unique<ReplayThread>(
std::move(reader),
/* read_size */ repeat_read_size,
/* buffer_count */ repeat_buffer_count,
&repeat_ready_signal,
[](uint32_t return_code) {
ReplayThreadDoneMessage message{return_code};
EventDispatcher::send_message(message);
});
}
void ReconView::stop_repeat(const bool do_loop) {
repeat_ready_signal = false;
if (is_repeat_active()) {
replay_thread.reset();
transmitter_model.disable();
}
// repeat transmit if current number of repetitions (repeat_cur_rep) is < recon configured number of repetitions (recon_repeat_nb)
if (do_loop && repeat_cur_rep < persistent_memory::recon_repeat_nb()) {
start_repeat();
} else {
repeat_cur_rep = 0;
recon_tx = false;
if (persistent_memory::recon_repeat_recorded_file_mode() == RECON_REPEAT_AND_KEEP) {
// rename file here to keep
std::filesystem::path base_path = next_filename_matching_pattern(repeat_rec_path / u"REC_????.*");
rename_file(rawfile, base_path.replace_extension(u".C16"));
rename_file(rawmeta, base_path.replace_extension(u".TXT"));
}
reload_restart_recon();
progressbar.hidden(true);
set_dirty(); // fix progressbar no hiding
}
}
void ReconView::handle_repeat_thread_done(const uint32_t return_code) {
if (return_code == ReplayThread::END_OF_FILE) {
stop_repeat(true);
} else if (return_code == ReplayThread::READ_ERROR) {
stop_repeat(false);
repeat_file_error(rawfile, "Can't open file to send.");
}
}
} /* namespace ui */