* ProtoView first tests

* Imp

* fix, reset
This commit is contained in:
Totoo
2024-07-29 07:45:56 +02:00
committed by GitHub
parent 96a60e82bc
commit 9211975868
17 changed files with 669 additions and 7 deletions

View File

@@ -80,6 +80,10 @@ set(EXTCPPSRC
#tpmsrx
external/tpmsrx/main.cpp
external/tpmsrx/tpms_app.cpp
#protoview
external/protoview/main.cpp
external/protoview/ui_protoview.cpp
)
set(EXTAPPLIST
@@ -102,4 +106,5 @@ set(EXTAPPLIST
audio_test
wardrivemap
tpmsrx
protoview
)

View File

@@ -42,6 +42,7 @@ MEMORY
ram_external_app_audio_test(rwx) : org = 0xADC10000, len = 32k
ram_external_app_wardrivemap(rwx) : org = 0xADC20000, len = 32k
ram_external_app_tpmsrx(rwx) : org = 0xADC30000, len = 32k
ram_external_app_protoview(rwx) : org = 0xADC40000, len = 32k
}
SECTIONS
@@ -160,4 +161,12 @@ SECTIONS
*(*ui*external_app*tpmsrx*);
} > ram_external_app_tpmsrx
.external_app_protoview : ALIGN(4) SUBALIGN(4)
{
KEEP(*(.external_app.app_protoview.application_information));
*(*ui*external_app*protoview*);
} > ram_external_app_protoview
}

View File

@@ -0,0 +1,82 @@
/*
* Copyright (C) 2024 HTotoo
*
* 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 "ui_protoview.hpp"
#include "ui_navigation.hpp"
#include "external_app.hpp"
namespace ui::external_app::protoview {
void initialize_app(ui::NavigationView& nav) {
nav.push<ProtoView>();
}
} // namespace ui::external_app::protoview
extern "C" {
__attribute__((section(".external_app.app_protoview.application_information"), used)) application_information_t _application_information_protoview = {
/*.memory_location = */ (uint8_t*)0x00000000,
/*.externalAppEntry = */ ui::external_app::protoview::initialize_app,
/*.header_version = */ CURRENT_HEADER_VERSION,
/*.app_version = */ VERSION_MD5,
/*.app_name = */ "ProtoView",
/*.bitmap_data = */ {
0x00,
0x00,
0x00,
0x00,
0xF8,
0x87,
0x08,
0x84,
0x0F,
0xFC,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0xF3,
0xE0,
0x92,
0xA0,
0x9E,
0xBF,
0x00,
0x00,
0x00,
0x00,
0xFC,
0xF3,
0x04,
0x12,
0x07,
0x1E,
},
/*.icon_color = */ ui::Color::orange().v,
/*.menu_location = */ app_location_t::RX,
/*.m4_app_tag = portapack::spi_flash::image_tag_protoview */ {'P', 'P', 'V', 'W'},
/*.m4_app_offset = */ 0x00000000, // will be filled at compile time
};
}

View File

@@ -0,0 +1,195 @@
/*
* Copyright (C) 2014 Jared Boone, ShareBrained Technology, Inc.
* Copyright (C) 2017 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_protoview.hpp"
#include "audio.hpp"
#include "rtc_time.hpp"
#include "baseband_api.hpp"
#include "string_format.hpp"
#include "portapack_persistent_memory.hpp"
#include "file_path.hpp"
using namespace portapack;
using namespace modems;
using namespace ui;
namespace ui::external_app::protoview {
void ProtoView::focus() {
field_frequency.focus();
}
ProtoView::ProtoView(NavigationView& nav)
: nav_{nav} {
baseband::run_prepared_image(portapack::memory::map::m4_code.base());
add_children({&rssi,
&field_rf_amp,
&field_lna,
&field_vga,
&field_volume,
&field_frequency,
&labels,
&options_zoom,
&button_reset,
&waveform,
&waveform2,
&waveform3,
&waveform4});
field_frequency.set_step(100);
options_zoom.on_change = [this](size_t, int32_t v) {
zoom = v;
draw();
draw2();
};
button_reset.on_select = [this](Button&) {
reset();
};
baseband::set_subghzd_config(0, receiver_model.sampling_rate());
audio::set_rate(audio::Rate::Hz_24000);
audio::output::start();
receiver_model.enable();
}
void ProtoView::reset() {
cnt = 0;
for (uint16_t i = 0; i < MAXSIGNALBUFFER; i++) time_buffer[i] = 0;
needCntReset = false;
draw();
draw2();
}
void ProtoView::on_timer() {
timercnt++;
if ((timercnt % 90) == 0) {
if (datacnt == 0) {
needCntReset = true;
}
datacnt = 0;
}
}
void ProtoView::draw2() {
if (drawcnt < MAXDRAWCNTPERWF) {
waveform.set_length(drawcnt);
waveform2.set_length(0);
waveform3.set_length(0);
waveform4.set_length(0);
} else if (drawcnt < MAXDRAWCNTPERWF * 2) {
waveform.set_length(MAXDRAWCNTPERWF);
waveform2.set_length(drawcnt - MAXDRAWCNTPERWF);
waveform3.set_length(0);
waveform4.set_length(0);
} else if (drawcnt < MAXDRAWCNTPERWF * 3) {
waveform.set_length(MAXDRAWCNTPERWF);
waveform2.set_length(MAXDRAWCNTPERWF);
waveform3.set_length(drawcnt - MAXDRAWCNTPERWF * 2);
waveform4.set_length(0);
} else {
waveform.set_length(MAXDRAWCNTPERWF);
waveform2.set_length(MAXDRAWCNTPERWF);
waveform3.set_length(MAXDRAWCNTPERWF);
waveform4.set_length(drawcnt - MAXDRAWCNTPERWF * 3);
}
waveform.set_dirty();
waveform2.set_dirty();
waveform3.set_dirty();
waveform4.set_dirty();
}
void ProtoView::draw() {
uint32_t remain = 0;
int32_t lmax = 0;
bool lmaxstate = false;
bool state = false;
drawcnt = 0;
for (uint16_t i = 0; i < MAXDRAWCNT; i++) waveform_buffer[i] = 0; // reset
for (uint16_t i = 0; i < MAXSIGNALBUFFER; ++i) {
state = time_buffer[i] >= 0;
int32_t timeabs = state ? time_buffer[i] : -1 * time_buffer[i];
int32_t timesize = timeabs / zoom;
if (timesize == 0) {
remain += timeabs;
if (lmax < timeabs) {
lmax = timeabs;
lmaxstate = state;
}
if (remain / zoom > 0) {
timesize = remain / zoom;
state = lmaxstate;
} else {
continue;
}
}
remain = 0;
lmax = 0;
for (int32_t ii = 0; ii < timesize; ++ii) {
waveform_buffer[drawcnt++] = state;
if (drawcnt >= MAXDRAWCNT) return;
}
}
}
void ProtoView::add_time(int32_t time) {
if (cnt >= MAXSIGNALBUFFER) cnt = 0;
time_buffer[cnt++] = time;
}
void ProtoView::on_data(const ProtoViewDataMessage* message) {
// filter out invalid ones.
uint16_t start = 0;
uint16_t stop = 0;
bool has_valid = false;
for (uint16_t i = 0; i <= message->maxptr; ++i) {
if (message->times[i] >= 30000 || message->times[i] <= -30000) {
if (!has_valid) {
start = i;
}
} else {
has_valid = true;
stop = i;
}
}
if (!has_valid) return; // no valid data arrived
// if (needCntReset) reset(); //todo implement auto reset
datacnt++;
// valid data, redraw
for (uint16_t i = start; i <= stop; i++) {
add_time(message->times[i]);
}
draw();
draw2();
}
ProtoView::~ProtoView() {
audio::output::stop();
receiver_model.disable();
baseband::shutdown();
}
} // namespace ui::external_app::protoview

View File

@@ -0,0 +1,164 @@
/*
* Copyright (C) 2014 Jared Boone, ShareBrained Technology, Inc.
* Copyright (C) 2017 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.
*/
#ifndef __UI_PROTOVIEW_H__
#define __UI_PROTOVIEW_H__
#define MAXSIGNALBUFFER 400
#define MAXDRAWCNT 600
#define MAXDRAWCNTPERWF 150
#include "ui.hpp"
#include "ui_language.hpp"
#include "ui_navigation.hpp"
#include "ui_receiver.hpp"
#include "ui_freq_field.hpp"
#include "ui_record_view.hpp"
#include "app_settings.hpp"
#include "radio_state.hpp"
#include "log_file.hpp"
#include "utility.hpp"
using namespace ui;
namespace ui::external_app::protoview {
class ProtoView : public View {
public:
ProtoView(NavigationView& nav);
~ProtoView();
void focus() override;
std::string title() const override { return "ProtoView"; };
private:
int16_t waveform_buffer[MAXDRAWCNT];
int32_t time_buffer[MAXSIGNALBUFFER];
NavigationView& nav_;
RxRadioState radio_state_{};
app_settings::SettingsManager settings_{
"rx_protoview", app_settings::Mode::RX};
RFAmpField field_rf_amp{
{13 * 8, 0 * 16}};
LNAGainField field_lna{
{15 * 8, 0 * 16}};
VGAGainField field_vga{
{18 * 8, 0 * 16}};
RSSI rssi{
{21 * 8, 0, 6 * 8, 4}};
AudioVolumeField field_volume{
{28 * 8, 0 * 16}};
RxFrequencyField field_frequency{
{0 * 8, 0 * 16},
nav_};
Labels labels{
{{0 * 8, 1 * 16}, "Zoom: ", Theme::getInstance()->fg_light->foreground}};
OptionsField options_zoom{
{7 * 8, 1 * 16},
4,
{{"1", 1},
{"2", 2},
{"5", 5},
{"15", 15},
{"30", 30},
{"50", 50},
{"100", 100},
{"200", 200},
{"500", 500},
{"1000", 1000}}};
Button button_reset{
{screen_width - 12 * 8, 1 * 16, 96, 24},
LanguageHelper::currentMessages[LANG_RESET]};
Waveform waveform{
{0, 5 * 8, 240, 50},
waveform_buffer,
0,
0,
true,
Theme::getInstance()->fg_yellow->foreground};
Waveform waveform2{
{0, 5 * 8 + 55, 240, 50},
&waveform_buffer[MAXDRAWCNTPERWF],
0,
0,
true,
Theme::getInstance()->fg_yellow->foreground};
Waveform waveform3{
{0, 5 * 8 + 110, 240, 50},
&waveform_buffer[MAXDRAWCNTPERWF * 2],
0,
0,
true,
Theme::getInstance()->fg_yellow->foreground};
Waveform waveform4{
{0, 5 * 8 + 165, 240, 50},
&waveform_buffer[MAXDRAWCNTPERWF * 3],
0,
0,
true,
Theme::getInstance()->fg_yellow->foreground};
bool needCntReset = false;
int16_t zoom = 1; // one value in ms
uint16_t cnt = 0; // pointer to next element
uint16_t drawcnt = 0; // pointer to draw next element
uint16_t timercnt = 0; // screen refresh count
uint16_t datacnt = 0; // how many data i got. these are for track if there is no data, so need a cnt reset
void add_time(int32_t time);
void on_timer();
void on_data(const ProtoViewDataMessage* message);
void draw();
void draw2();
void reset();
MessageHandlerRegistration message_handler_packet{
Message::ID::ProtoViewData,
[this](Message* const p) {
const auto message = static_cast<const ProtoViewDataMessage*>(p);
this->on_data(message);
}};
MessageHandlerRegistration message_handler_frame_sync{
Message::ID::DisplayFrameSync,
[this](const Message* const) {
this->on_timer();
}};
};
} // namespace ui::external_app::protoview
#endif /*__UI_PROTOVIEW_H__*/