mirror of
https://github.com/portapack-mayhem/mayhem-firmware.git
synced 2026-09-01 20:39:08 +00:00
Compare commits
31 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 7a87e3f3af | |||
| 68f960e4e7 | |||
| 6784fe72dd | |||
| 312df0fcec | |||
| 2913a41aec | |||
| adabbfbef1 | |||
| 2b7962fa7c | |||
| 645f02e2f3 | |||
| b178462e47 | |||
| 1639348b94 | |||
| f67fe262bb | |||
| 0681117af6 | |||
| b5c244a09b | |||
| dceb7255b0 | |||
| 62307b93d7 | |||
| 61ce8b11a6 | |||
| 211f40ddf3 | |||
| 01dd0c79ed | |||
| be7b402c95 | |||
| a11929d2ca | |||
| 0bacb31d17 | |||
| cc7e4aec8a | |||
| 15c338e5b3 | |||
| 80bfcd5eb1 | |||
| b96f14762f | |||
| 0feacfa102 | |||
| a1496c1b79 | |||
| 1b73a138b6 | |||
| efcedd9005 | |||
| 86d4b17257 | |||
| f6a437f7fb |
+2
-1
@@ -55,10 +55,11 @@ CMakeFiles/
|
||||
# Debugging
|
||||
.gdbinit*
|
||||
|
||||
# Editor files
|
||||
# Editor/IDE files
|
||||
*.sublime-project
|
||||
*.sublime-workspace
|
||||
.vscode
|
||||
.idea
|
||||
|
||||
# VSCodium extensions
|
||||
.history
|
||||
|
||||
@@ -20,7 +20,9 @@ This repository expands upon the previous work by many people and aims to consta
|
||||
|
||||
## What to buy?
|
||||
|
||||
:heavy_check_mark: A recommended one is this [PortaPack H2](https://s.click.aliexpress.com/e/_DmU7GQX) pack, that includes everything you need. Sadly, the people making the H2 never made the updated schematics available (against the terms of the license).
|
||||
:heavy_check_mark: A recommended one is this [PortaPack H2](https://s.click.aliexpress.com/e/_DmU7GQX), that includes everything you need with the plastic case "inspired" on [this](https://github.com/eried/portapack-mayhem/wiki/H2-Enclosure).
|
||||
|
||||
:heavy_check_mark: Our friends at OpenSourceSDRLab give away five units every three months in [our discord](https://discord.com/channels/719669764804444213/1165624357129834547) of this [PortaPack H2](https://www.aliexpress.com/item/4000247041639.html?gatewayAdapt=4itemAdapt), you can support them too.
|
||||
|
||||
:heavy_check_mark: Another popular option is the clone of the [PortaPack H1](https://s.click.aliexpress.com/e/_Dkbqs2X).
|
||||
|
||||
|
||||
@@ -244,6 +244,8 @@ set(CPPSRC
|
||||
apps/ais_app.cpp
|
||||
apps/analog_audio_app.cpp
|
||||
apps/analog_tv_app.cpp
|
||||
apps/ble_rx_app.cpp
|
||||
apps/ble_tx_app.cpp
|
||||
apps/capture_app.cpp
|
||||
apps/ert_app.cpp
|
||||
apps/gps_sim_app.cpp
|
||||
@@ -268,6 +270,7 @@ set(CPPSRC
|
||||
apps/ui_fileman.cpp
|
||||
apps/ui_flash_utility.cpp
|
||||
apps/ui_freqman.cpp
|
||||
apps/ui_fsk_rx.cpp
|
||||
apps/ui_iq_trim.cpp
|
||||
apps/ui_jammer.cpp
|
||||
# apps/ui_keyfob.cpp
|
||||
|
||||
@@ -156,6 +156,7 @@ bool save_settings(std::string_view store_name, const SettingBindings& bindings)
|
||||
File f;
|
||||
auto path = get_settings_path(std::string{store_name});
|
||||
|
||||
make_new_directory(SETTINGS_DIR);
|
||||
auto error = f.create(path);
|
||||
if (error)
|
||||
return false;
|
||||
@@ -249,7 +250,7 @@ SettingsManager::SettingsManager(
|
||||
settings_.options = options;
|
||||
|
||||
// Pre-alloc enough for app settings and additional settings.
|
||||
additional_settings.reserve(17 + additional_settings.size());
|
||||
additional_settings.reserve(COMMON_APP_SETTINGS_COUNT + additional_settings.size());
|
||||
bindings_ = std::move(additional_settings);
|
||||
|
||||
// Settings should always be loaded because apps now rely
|
||||
|
||||
@@ -36,9 +36,14 @@
|
||||
#include "max283x.hpp"
|
||||
#include "string_format.hpp"
|
||||
|
||||
// Folder to store app settings, pmem_fileflag, and date_fileflag
|
||||
#define SETTINGS_DIR u"/SETTINGS"
|
||||
|
||||
// Bring in the string_view literal.
|
||||
using std::literals::operator""sv;
|
||||
|
||||
#define COMMON_APP_SETTINGS_COUNT 19
|
||||
|
||||
/* Represents a named setting bound to a variable instance. */
|
||||
/* Using void* instead of std::variant, because variant is a pain to dispatch over. */
|
||||
class BoundSetting {
|
||||
@@ -140,8 +145,8 @@ struct AppSettings {
|
||||
uint8_t nbfm_config_index = 0;
|
||||
uint8_t wfm_config_index = 0;
|
||||
uint8_t squelch = 80;
|
||||
|
||||
uint8_t volume;
|
||||
// NOTE: update COMMON_APP_SETTINGS_COUNT when adding to this
|
||||
};
|
||||
|
||||
/* Copies common values to the receiver/transmitter models. */
|
||||
|
||||
@@ -0,0 +1,572 @@
|
||||
/*
|
||||
* Copyright (C) 2014 Jared Boone, ShareBrained Technology, Inc.
|
||||
* Copyright (C) 2017 Furrtek
|
||||
* Copyright (C) 2023 TJ Baginski
|
||||
*
|
||||
* 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 "ble_rx_app.hpp"
|
||||
#include "ble_tx_app.hpp"
|
||||
|
||||
#include "ui_modemsetup.hpp"
|
||||
|
||||
#include "modems.hpp"
|
||||
#include "audio.hpp"
|
||||
#include "rtc_time.hpp"
|
||||
#include "baseband_api.hpp"
|
||||
#include "string_format.hpp"
|
||||
#include "portapack_persistent_memory.hpp"
|
||||
#include "ui_textentry.hpp"
|
||||
|
||||
using namespace portapack;
|
||||
using namespace modems;
|
||||
|
||||
void BLELogger::log_raw_data(const std::string& data) {
|
||||
log_file.write_entry(data);
|
||||
}
|
||||
|
||||
std::string pad_string_with_spaces(int snakes) {
|
||||
std::string paddedStr(snakes, ' ');
|
||||
return paddedStr;
|
||||
}
|
||||
|
||||
uint64_t copy_mac_address_to_uint64(const uint8_t* macAddress) {
|
||||
uint64_t result = 0;
|
||||
|
||||
// Copy each byte of the MAC address to the corresponding byte in the uint64_t.
|
||||
for (int i = 0; i < 6; ++i) {
|
||||
result |= static_cast<uint64_t>(macAddress[i]) << ((5 - i) * 8);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
namespace ui {
|
||||
template <>
|
||||
void RecentEntriesTable<BleRecentEntries>::draw(
|
||||
const Entry& entry,
|
||||
const Rect& target_rect,
|
||||
Painter& painter,
|
||||
const Style& style) {
|
||||
std::string line{};
|
||||
|
||||
if (!entry.nameString.empty()) {
|
||||
line = entry.nameString;
|
||||
|
||||
if (line.length() < 17) {
|
||||
line += pad_string_with_spaces(17 - line.length());
|
||||
} else {
|
||||
line = truncate(line, 17);
|
||||
}
|
||||
} else {
|
||||
line = to_string_mac_address(entry.packetData.macAddress, 6, false);
|
||||
}
|
||||
|
||||
// Pushing single digit values down right justified.
|
||||
std::string hitsStr = to_string_dec_int(entry.numHits);
|
||||
int hitsDigits = hitsStr.length();
|
||||
uint8_t hits_spacing = 8 - hitsDigits;
|
||||
|
||||
// Pushing single digit values down right justified.
|
||||
std::string dbStr = to_string_dec_int(entry.dbValue);
|
||||
int dbDigits = dbStr.length();
|
||||
uint8_t db_spacing = 5 - dbDigits;
|
||||
|
||||
line += pad_string_with_spaces(hits_spacing) + hitsStr;
|
||||
|
||||
line += pad_string_with_spaces(db_spacing) + dbStr;
|
||||
|
||||
line.resize(target_rect.width() / 8, ' ');
|
||||
painter.draw_string(target_rect.location(), style, line);
|
||||
}
|
||||
|
||||
BleRecentEntryDetailView::BleRecentEntryDetailView(NavigationView& nav, const BleRecentEntry& entry)
|
||||
: nav_{nav},
|
||||
entry_{entry} {
|
||||
add_children({&button_done,
|
||||
&button_send,
|
||||
&label_mac_address,
|
||||
&text_mac_address,
|
||||
&labels});
|
||||
|
||||
text_mac_address.set(to_string_mac_address(entry.packetData.macAddress, 6, false));
|
||||
|
||||
button_done.on_select = [this](const ui::Button&) {
|
||||
nav_.pop();
|
||||
};
|
||||
|
||||
button_send.on_select = [this](const ui::Button&) {
|
||||
nav_.set_on_pop([this]() { launch_bletx(entry_); });
|
||||
nav_.pop();
|
||||
};
|
||||
}
|
||||
|
||||
void BleRecentEntryDetailView::update_data() {
|
||||
}
|
||||
|
||||
void BleRecentEntryDetailView::focus() {
|
||||
button_done.focus();
|
||||
}
|
||||
|
||||
Rect BleRecentEntryDetailView::draw_field(
|
||||
Painter& painter,
|
||||
const Rect& draw_rect,
|
||||
const Style& style,
|
||||
const std::string& label,
|
||||
const std::string& value) {
|
||||
const int label_length_max = 4;
|
||||
|
||||
painter.draw_string(Point{draw_rect.left(), draw_rect.top()}, style, label);
|
||||
painter.draw_string(Point{draw_rect.left() + (label_length_max + 1) * 8, draw_rect.top()}, style, value);
|
||||
|
||||
return {draw_rect.left(), draw_rect.top() + draw_rect.height(), draw_rect.width(), draw_rect.height()};
|
||||
}
|
||||
|
||||
void BleRecentEntryDetailView::paint(Painter& painter) {
|
||||
View::paint(painter);
|
||||
|
||||
const auto s = style();
|
||||
const auto rect = screen_rect();
|
||||
|
||||
auto field_rect = Rect{rect.left(), rect.top() + 48, rect.width(), 16};
|
||||
|
||||
uint8_t type[total_data_lines];
|
||||
uint8_t length[total_data_lines];
|
||||
uint8_t data[total_data_lines][40];
|
||||
|
||||
int currentByte = 0;
|
||||
int currentPacket = 0;
|
||||
int i = 0;
|
||||
int j = 0;
|
||||
int k = 0;
|
||||
|
||||
for (currentByte = 0; (currentByte < entry_.packetData.dataLen) && (currentPacket < total_data_lines);) {
|
||||
length[currentPacket] = entry_.packetData.data[currentByte++];
|
||||
type[currentPacket] = entry_.packetData.data[currentByte++];
|
||||
|
||||
// Subtract 1 because type is part of the length.
|
||||
for (i = 0; i < length[currentPacket] - 1; i++) {
|
||||
data[currentPacket][i] = entry_.packetData.data[currentByte++];
|
||||
}
|
||||
|
||||
currentPacket++;
|
||||
}
|
||||
|
||||
for (i = 0; i < currentPacket; i++) {
|
||||
uint8_t number_data_lines = ceil((float)(length[i] - 1) / 10.0);
|
||||
uint8_t current_line = 0;
|
||||
std::array<std::string, total_data_lines> data_strings{};
|
||||
|
||||
for (j = 0; (j < (number_data_lines * 10)) && (j < length[i] - 1); j++) {
|
||||
if ((j / 10) != current_line) {
|
||||
current_line++;
|
||||
}
|
||||
|
||||
data_strings[current_line] += to_string_hex(data[i][j], 2);
|
||||
}
|
||||
|
||||
// Read the type back to the total length.
|
||||
field_rect = draw_field(painter, field_rect, s, to_string_hex(length[i]), to_string_hex(type[i]) + pad_string_with_spaces(3) + data_strings[0]);
|
||||
|
||||
if (number_data_lines > 1) {
|
||||
for (k = 1; k < number_data_lines; k++) {
|
||||
if (!data_strings[k].empty()) {
|
||||
field_rect = draw_field(painter, field_rect, s, "", pad_string_with_spaces(5) + data_strings[k]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void BleRecentEntryDetailView::set_entry(const BleRecentEntry& entry) {
|
||||
entry_ = entry;
|
||||
set_dirty();
|
||||
}
|
||||
|
||||
void BleRecentEntryDetailView::launch_bletx(BleRecentEntry packetEntry) {
|
||||
BLETxPacket bleTxPacket;
|
||||
|
||||
std::string macAddressStr = to_string_mac_address(packetEntry.packetData.macAddress, 6, true);
|
||||
|
||||
strncpy(bleTxPacket.macAddress, macAddressStr.c_str(), 13);
|
||||
strncpy(bleTxPacket.advertisementData, packetEntry.dataString.c_str(), (packetEntry.packetData.dataLen * 2) + 1);
|
||||
strncpy(bleTxPacket.packetCount, "50", 3);
|
||||
bleTxPacket.packet_count = 50;
|
||||
|
||||
nav_.replace<BLETxView>(bleTxPacket);
|
||||
}
|
||||
|
||||
static std::uint64_t get_freq_by_channel_number(uint8_t channel_number) {
|
||||
uint64_t freq_hz;
|
||||
|
||||
switch (channel_number) {
|
||||
case 37:
|
||||
freq_hz = 2'402'000'000ull;
|
||||
break;
|
||||
case 38:
|
||||
freq_hz = 2'426'000'000ull;
|
||||
break;
|
||||
case 39:
|
||||
freq_hz = 2'480'000'000ull;
|
||||
break;
|
||||
case 0 ... 10:
|
||||
freq_hz = 2'404'000'000ull + channel_number * 2'000'000ull;
|
||||
break;
|
||||
case 11 ... 36:
|
||||
freq_hz = 2'428'000'000ull + (channel_number - 11) * 2'000'000ull;
|
||||
break;
|
||||
default:
|
||||
freq_hz = UINT64_MAX;
|
||||
}
|
||||
|
||||
return freq_hz;
|
||||
}
|
||||
|
||||
void BLERxView::focus() {
|
||||
options_channel.focus();
|
||||
}
|
||||
|
||||
BLERxView::BLERxView(NavigationView& nav)
|
||||
: nav_{nav} {
|
||||
baseband::run_image(portapack::spi_flash::image_tag_btle_rx);
|
||||
|
||||
add_children({&rssi,
|
||||
&channel,
|
||||
&field_rf_amp,
|
||||
&field_lna,
|
||||
&field_vga,
|
||||
&options_channel,
|
||||
&field_frequency,
|
||||
&check_log,
|
||||
&label_sort,
|
||||
&options_sort,
|
||||
&button_filter,
|
||||
&button_switch,
|
||||
&recent_entries_view,
|
||||
&recent_entries_filter_view,
|
||||
&recent_entry_detail_view});
|
||||
|
||||
recent_entry_detail_view.hidden(true);
|
||||
recent_entries_filter_view.hidden(true);
|
||||
|
||||
recent_entries_view.on_select = [this](const BleRecentEntry& entry) {
|
||||
nav_.push<BleRecentEntryDetailView>(entry);
|
||||
};
|
||||
|
||||
recent_entries_filter_view.on_select = [this](const BleRecentEntry& entry) {
|
||||
nav_.push<BleRecentEntryDetailView>(entry);
|
||||
};
|
||||
|
||||
button_filter.on_select = [this, &nav](Button&) {
|
||||
text_prompt(
|
||||
nav,
|
||||
filterBuffer,
|
||||
64,
|
||||
[this](std::string& buffer) {
|
||||
on_switch_table(buffer);
|
||||
});
|
||||
};
|
||||
|
||||
button_switch.on_select = [this, &nav](Button&) {
|
||||
nav_.set_on_pop([this]() { nav_.push<BLETxView>(); });
|
||||
nav_.pop();
|
||||
};
|
||||
|
||||
field_frequency.set_step(0);
|
||||
|
||||
check_log.set_value(logging);
|
||||
|
||||
check_log.on_select = [this](Checkbox&, bool v) {
|
||||
str_log = "";
|
||||
logging = v;
|
||||
|
||||
if (logger && logging)
|
||||
logger->append(LOG_ROOT_DIR "/BLELOG_" + to_string_timestamp(rtc_time::now()) + ".TXT");
|
||||
};
|
||||
|
||||
options_channel.on_change = [this](size_t, int32_t i) {
|
||||
field_frequency.set_value(get_freq_by_channel_number(i));
|
||||
channel_number = i;
|
||||
|
||||
baseband::set_btlerx(channel_number);
|
||||
};
|
||||
|
||||
options_sort.on_change = [this](size_t, int32_t i) {
|
||||
switch (i) {
|
||||
case 0:
|
||||
sortEntriesBy(
|
||||
recent, [](const BleRecentEntry& entry) { return entry.macAddress; }, true);
|
||||
sortEntriesBy(
|
||||
filterEntries, [](const BleRecentEntry& entry) { return entry.macAddress; }, true);
|
||||
break;
|
||||
case 1:
|
||||
sortEntriesBy(
|
||||
recent, [](const BleRecentEntry& entry) { return entry.numHits; }, false);
|
||||
sortEntriesBy(
|
||||
filterEntries, [](const BleRecentEntry& entry) { return entry.numHits; }, false);
|
||||
break;
|
||||
case 2:
|
||||
sortEntriesBy(
|
||||
recent, [](const BleRecentEntry& entry) { return entry.dbValue; }, true);
|
||||
sortEntriesBy(
|
||||
filterEntries, [](const BleRecentEntry& entry) { return entry.dbValue; }, true);
|
||||
break;
|
||||
case 3:
|
||||
sortEntriesBy(
|
||||
recent, [](const BleRecentEntry& entry) { return entry.timestamp; }, false);
|
||||
sortEntriesBy(
|
||||
filterEntries, [](const BleRecentEntry& entry) { return entry.timestamp; }, false);
|
||||
break;
|
||||
case 4:
|
||||
sortEntriesBy(
|
||||
recent, [](const BleRecentEntry& entry) { return entry.nameString; }, true);
|
||||
sortEntriesBy(
|
||||
filterEntries, [](const BleRecentEntry& entry) { return entry.nameString; }, true);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
recent_entries_view.set_dirty();
|
||||
recent_entries_filter_view.set_dirty();
|
||||
};
|
||||
|
||||
options_channel.set_selected_index(0, true);
|
||||
options_sort.set_selected_index(0, true);
|
||||
|
||||
logger = std::make_unique<BLELogger>();
|
||||
|
||||
// Auto-configure modem for LCR RX (will be removed later)
|
||||
baseband::set_btlerx(channel_number);
|
||||
|
||||
receiver_model.enable();
|
||||
}
|
||||
|
||||
void BLERxView::on_data(BlePacketData* packet) {
|
||||
std::string str_console = "";
|
||||
|
||||
if (!logging) {
|
||||
str_log = "";
|
||||
}
|
||||
|
||||
switch ((ADV_PDU_TYPE)packet->type) {
|
||||
case ADV_IND:
|
||||
str_console += "ADV_IND";
|
||||
break;
|
||||
case ADV_DIRECT_IND:
|
||||
str_console += "ADV_DIRECT_IND";
|
||||
break;
|
||||
case ADV_NONCONN_IND:
|
||||
str_console += "ADV_NONCONN_IND";
|
||||
break;
|
||||
case SCAN_REQ:
|
||||
str_console += "SCAN_REQ";
|
||||
break;
|
||||
case SCAN_RSP:
|
||||
str_console += "SCAN_RSP";
|
||||
break;
|
||||
case CONNECT_REQ:
|
||||
str_console += "CONNECT_REQ";
|
||||
break;
|
||||
case ADV_SCAN_IND:
|
||||
str_console += "ADV_SCAN_IND";
|
||||
break;
|
||||
case RESERVED0:
|
||||
case RESERVED1:
|
||||
case RESERVED2:
|
||||
case RESERVED3:
|
||||
case RESERVED4:
|
||||
case RESERVED5:
|
||||
case RESERVED6:
|
||||
case RESERVED7:
|
||||
case RESERVED8:
|
||||
str_console += "RESERVED";
|
||||
break;
|
||||
default:
|
||||
str_console += "UNKNOWN";
|
||||
break;
|
||||
}
|
||||
|
||||
str_console += " Len:";
|
||||
str_console += to_string_dec_uint(packet->size);
|
||||
|
||||
str_console += "\n";
|
||||
|
||||
str_console += "Mac:";
|
||||
str_console += to_string_mac_address(packet->macAddress, 6, false);
|
||||
|
||||
str_console += "\n";
|
||||
str_console += "Data:";
|
||||
|
||||
int i;
|
||||
|
||||
for (i = 0; i < packet->dataLen; i++) {
|
||||
str_console += to_string_hex(packet->data[i], 2);
|
||||
}
|
||||
|
||||
str_console += "\n";
|
||||
|
||||
uint64_t macAddressEncoded = copy_mac_address_to_uint64(packet->macAddress);
|
||||
|
||||
// Start of Packet stuffing.
|
||||
// Masking off the top 2 bytes to avoid invalid keys.
|
||||
auto& entry = ::on_packet(recent, macAddressEncoded & 0xFFFFFFFFFFFF);
|
||||
truncate_entries(recent, 32);
|
||||
updateEntry(packet, entry);
|
||||
|
||||
// Log at End of Packet.
|
||||
if (logger && logging) {
|
||||
logger->log_raw_data(str_console);
|
||||
}
|
||||
}
|
||||
|
||||
void BLERxView::on_switch_table(const std::string value) {
|
||||
filter = value;
|
||||
|
||||
if (!value.empty()) {
|
||||
removeEntriesWithoutKey(recent, filterEntries, [&value](const BleRecentEntry& entry) {
|
||||
return entry.dataString.find(value) == std::string::npos;
|
||||
});
|
||||
|
||||
recent_entries_view.set_dirty();
|
||||
|
||||
recent_entries_filter_view.hidden(false);
|
||||
recent_entries_view.hidden(true);
|
||||
} else {
|
||||
recent_entries_view.hidden(false);
|
||||
recent_entries_filter_view.hidden(true);
|
||||
}
|
||||
|
||||
recent_entries_view.set_dirty();
|
||||
recent_entries_filter_view.set_dirty();
|
||||
}
|
||||
|
||||
void BLERxView::set_parent_rect(const Rect new_parent_rect) {
|
||||
View::set_parent_rect(new_parent_rect);
|
||||
const Rect content_rect{0, header_height, new_parent_rect.width(), new_parent_rect.height() - header_height - switch_button_height};
|
||||
recent_entries_view.set_parent_rect(content_rect);
|
||||
recent_entry_detail_view.set_parent_rect(content_rect);
|
||||
recent_entries_filter_view.set_parent_rect(content_rect);
|
||||
}
|
||||
|
||||
BLERxView::~BLERxView() {
|
||||
receiver_model.disable();
|
||||
baseband::shutdown();
|
||||
}
|
||||
|
||||
void BLERxView::updateEntry(const BlePacketData* packet, BleRecentEntry& entry) {
|
||||
std::string data_string;
|
||||
|
||||
int i;
|
||||
|
||||
for (i = 0; i < packet->dataLen; i++) {
|
||||
data_string += to_string_hex(packet->data[i], 2);
|
||||
}
|
||||
|
||||
entry.dbValue = packet->max_dB;
|
||||
entry.timestamp = to_string_timestamp(rtc_time::now());
|
||||
entry.dataString = data_string;
|
||||
|
||||
entry.packetData.type = packet->type;
|
||||
entry.packetData.size = packet->size;
|
||||
entry.packetData.dataLen = packet->dataLen;
|
||||
|
||||
entry.packetData.macAddress[0] = packet->macAddress[0];
|
||||
entry.packetData.macAddress[1] = packet->macAddress[1];
|
||||
entry.packetData.macAddress[2] = packet->macAddress[2];
|
||||
entry.packetData.macAddress[3] = packet->macAddress[3];
|
||||
entry.packetData.macAddress[4] = packet->macAddress[4];
|
||||
entry.packetData.macAddress[5] = packet->macAddress[5];
|
||||
|
||||
entry.numHits++;
|
||||
|
||||
for (int i = 0; i < packet->dataLen; i++) {
|
||||
entry.packetData.data[i] = packet->data[i];
|
||||
}
|
||||
|
||||
entry.nameString = "";
|
||||
|
||||
uint8_t currentByte = 0;
|
||||
uint8_t length = 0;
|
||||
uint8_t type = 0;
|
||||
|
||||
bool stringFound = false;
|
||||
|
||||
for (currentByte = 0; (currentByte < entry.packetData.dataLen);) {
|
||||
length = entry.packetData.data[currentByte++];
|
||||
type = entry.packetData.data[currentByte++];
|
||||
|
||||
// Subtract 1 because type is part of the length.
|
||||
for (int i = 0; i < length - 1; i++) {
|
||||
if (((type == 0x08) || (type == 0x09)) && !stringFound) {
|
||||
entry.nameString += (char)entry.packetData.data[currentByte];
|
||||
}
|
||||
|
||||
currentByte++;
|
||||
}
|
||||
|
||||
if (!entry.nameString.empty()) {
|
||||
stringFound = true;
|
||||
}
|
||||
}
|
||||
|
||||
switch (options_sort.selected_index()) {
|
||||
case 0:
|
||||
sortEntriesBy(
|
||||
recent, [](const BleRecentEntry& entry) { return entry.macAddress; }, true);
|
||||
sortEntriesBy(
|
||||
filterEntries, [](const BleRecentEntry& entry) { return entry.macAddress; }, true);
|
||||
break;
|
||||
case 1:
|
||||
sortEntriesBy(
|
||||
recent, [](const BleRecentEntry& entry) { return entry.numHits; }, false);
|
||||
sortEntriesBy(
|
||||
filterEntries, [](const BleRecentEntry& entry) { return entry.numHits; }, false);
|
||||
break;
|
||||
case 2:
|
||||
sortEntriesBy(
|
||||
recent, [](const BleRecentEntry& entry) { return entry.dbValue; }, true);
|
||||
sortEntriesBy(
|
||||
filterEntries, [](const BleRecentEntry& entry) { return entry.dbValue; }, true);
|
||||
break;
|
||||
case 3:
|
||||
sortEntriesBy(
|
||||
recent, [](const BleRecentEntry& entry) { return entry.timestamp; }, false);
|
||||
sortEntriesBy(
|
||||
filterEntries, [](const BleRecentEntry& entry) { return entry.timestamp; }, false);
|
||||
break;
|
||||
case 4:
|
||||
sortEntriesBy(
|
||||
recent, [](const BleRecentEntry& entry) { return entry.nameString; }, true);
|
||||
sortEntriesBy(
|
||||
filterEntries, [](const BleRecentEntry& entry) { return entry.nameString; }, true);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
on_switch_table(filter);
|
||||
|
||||
// TODO: Crude hack, should be a more formal listener arrangement...
|
||||
if (entry.key() == recent_entry_detail_view.entry().key()) {
|
||||
recent_entry_detail_view.set_entry(entry);
|
||||
}
|
||||
}
|
||||
|
||||
} /* namespace ui */
|
||||
@@ -0,0 +1,276 @@
|
||||
/*
|
||||
* Copyright (C) 2014 Jared Boone, ShareBrained Technology, Inc.
|
||||
* Copyright (C) 2017 Furrtek
|
||||
* Copyright (C) 2023 TJ Baginski
|
||||
*
|
||||
* 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 __BLE_RX_APP_H__
|
||||
#define __BLE_RX_APP_H__
|
||||
|
||||
#include "ui.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"
|
||||
|
||||
#include "recent_entries.hpp"
|
||||
|
||||
class BLELogger {
|
||||
public:
|
||||
Optional<File::Error> append(const std::string& filename) {
|
||||
return log_file.append(filename);
|
||||
}
|
||||
|
||||
void log_raw_data(const std::string& data);
|
||||
|
||||
private:
|
||||
LogFile log_file{};
|
||||
};
|
||||
|
||||
namespace ui {
|
||||
typedef enum {
|
||||
ADV_IND = 0,
|
||||
ADV_DIRECT_IND = 1,
|
||||
ADV_NONCONN_IND = 2,
|
||||
SCAN_REQ = 3,
|
||||
SCAN_RSP = 4,
|
||||
CONNECT_REQ = 5,
|
||||
ADV_SCAN_IND = 6,
|
||||
RESERVED0 = 7,
|
||||
RESERVED1 = 8,
|
||||
RESERVED2 = 9,
|
||||
RESERVED3 = 10,
|
||||
RESERVED4 = 11,
|
||||
RESERVED5 = 12,
|
||||
RESERVED6 = 13,
|
||||
RESERVED7 = 14,
|
||||
RESERVED8 = 15
|
||||
} ADV_PDU_TYPE;
|
||||
|
||||
struct BleRecentEntry {
|
||||
using Key = uint64_t;
|
||||
|
||||
static constexpr Key invalid_key = 0xffffffff;
|
||||
|
||||
uint64_t macAddress;
|
||||
int dbValue;
|
||||
BlePacketData packetData;
|
||||
std::string timestamp;
|
||||
std::string dataString;
|
||||
std::string nameString;
|
||||
uint16_t numHits;
|
||||
|
||||
BleRecentEntry()
|
||||
: BleRecentEntry{0} {
|
||||
}
|
||||
|
||||
BleRecentEntry(
|
||||
const uint64_t macAddress)
|
||||
: macAddress{macAddress},
|
||||
dbValue{},
|
||||
packetData{},
|
||||
timestamp{},
|
||||
dataString{},
|
||||
nameString{},
|
||||
numHits{} {
|
||||
}
|
||||
|
||||
Key key() const {
|
||||
return macAddress;
|
||||
}
|
||||
};
|
||||
|
||||
using BleRecentEntries = RecentEntries<BleRecentEntry>;
|
||||
using BleRecentEntriesView = RecentEntriesView<BleRecentEntries>;
|
||||
|
||||
class BleRecentEntryDetailView : public View {
|
||||
public:
|
||||
BleRecentEntryDetailView(NavigationView& nav, const BleRecentEntry& entry);
|
||||
|
||||
void set_entry(const BleRecentEntry& new_entry);
|
||||
const BleRecentEntry& entry() const { return entry_; };
|
||||
|
||||
void update_data();
|
||||
void focus() override;
|
||||
void paint(Painter&) override;
|
||||
|
||||
private:
|
||||
NavigationView& nav_;
|
||||
BleRecentEntry entry_{};
|
||||
void launch_bletx(BleRecentEntry packetEntry);
|
||||
|
||||
static constexpr uint8_t total_data_lines{5};
|
||||
|
||||
Labels label_mac_address{
|
||||
{{0 * 8, 0 * 16}, "Mac Address:", Color::light_grey()}};
|
||||
|
||||
Text text_mac_address{
|
||||
{12 * 8, 0 * 16, 17 * 8, 16},
|
||||
"-"};
|
||||
|
||||
Labels labels{
|
||||
{{0 * 8, 2 * 16}, "Len", Color::light_grey()},
|
||||
{{5 * 8, 2 * 16}, "Type", Color::light_grey()},
|
||||
{{10 * 8, 2 * 16}, "Value", Color::light_grey()},
|
||||
};
|
||||
|
||||
Button button_send{
|
||||
{19, 224, 96, 24},
|
||||
"Send"};
|
||||
|
||||
Button button_done{
|
||||
{125, 224, 96, 24},
|
||||
"Done"};
|
||||
|
||||
bool send_updates{false};
|
||||
|
||||
Rect draw_field(
|
||||
Painter& painter,
|
||||
const Rect& draw_rect,
|
||||
const Style& style,
|
||||
const std::string& label,
|
||||
const std::string& value);
|
||||
};
|
||||
|
||||
class BLERxView : public View {
|
||||
public:
|
||||
BLERxView(NavigationView& nav);
|
||||
~BLERxView();
|
||||
|
||||
void set_parent_rect(const Rect new_parent_rect) override;
|
||||
void paint(Painter&) override{};
|
||||
|
||||
void focus() override;
|
||||
|
||||
std::string title() const override { return "BLE RX"; };
|
||||
|
||||
private:
|
||||
void on_data(BlePacketData* packetData);
|
||||
void on_switch_table(const std::string value);
|
||||
void updateEntry(const BlePacketData* packet, BleRecentEntry& entry);
|
||||
|
||||
NavigationView& nav_;
|
||||
RxRadioState radio_state_{
|
||||
2402000000 /* frequency */,
|
||||
4000000 /* bandwidth */,
|
||||
4000000 /* sampling rate */,
|
||||
ReceiverModel::Mode::WidebandFMAudio};
|
||||
app_settings::SettingsManager settings_{
|
||||
"BLE Rx", app_settings::Mode::RX};
|
||||
|
||||
uint8_t console_color{0};
|
||||
uint32_t prev_value{0};
|
||||
uint8_t channel_number = 37;
|
||||
|
||||
std::string filterBuffer{};
|
||||
std::string filter{};
|
||||
|
||||
static constexpr auto header_height = 3 * 16;
|
||||
static constexpr auto switch_button_height = 3 * 16;
|
||||
|
||||
OptionsField options_channel{
|
||||
{0 * 8, 0 * 8},
|
||||
5,
|
||||
{{"Ch.37 ", 37},
|
||||
{"Ch.38", 38},
|
||||
{"Ch.39", 39}}};
|
||||
|
||||
RxFrequencyField field_frequency{
|
||||
{6 * 8, 0 * 16},
|
||||
nav_};
|
||||
|
||||
RFAmpField field_rf_amp{
|
||||
{16 * 8, 0 * 16}};
|
||||
|
||||
LNAGainField field_lna{
|
||||
{18 * 8, 0 * 16}};
|
||||
|
||||
VGAGainField field_vga{
|
||||
{21 * 8, 0 * 16}};
|
||||
|
||||
RSSI rssi{
|
||||
{24 * 8, 0, 6 * 8, 4}};
|
||||
|
||||
Channel channel{
|
||||
{24 * 8, 5, 6 * 8, 4}};
|
||||
|
||||
Labels label_sort{
|
||||
{{0 * 8, 3 * 8}, "Sort:", Color::light_grey()}};
|
||||
|
||||
OptionsField options_sort{
|
||||
{5 * 8, 3 * 8},
|
||||
4,
|
||||
{{"MAC", 0},
|
||||
{"Hits", 1},
|
||||
{"dB", 2},
|
||||
{"Time", 3},
|
||||
{"Name", 4}}};
|
||||
|
||||
Button button_filter{
|
||||
{12 * 8, 3 * 8, 4 * 8, 16},
|
||||
"Filter"};
|
||||
|
||||
Checkbox check_log{
|
||||
{20 * 8, 3 * 8},
|
||||
3,
|
||||
"Log",
|
||||
true};
|
||||
|
||||
Console console{
|
||||
{0, 4 * 16, 240, 240}};
|
||||
|
||||
Button button_switch{
|
||||
{8 * 8, 16 * 16, 14 * 8, 2 * 16},
|
||||
"Switch to Tx"};
|
||||
|
||||
std::string str_log{""};
|
||||
bool logging{false};
|
||||
|
||||
std::unique_ptr<BLELogger> logger{};
|
||||
|
||||
BleRecentEntries recent{};
|
||||
BleRecentEntries filterEntries{};
|
||||
|
||||
const RecentEntriesColumns columns{{
|
||||
{"Mac Address", 17},
|
||||
{"Hits", 7},
|
||||
{"dB", 4},
|
||||
}};
|
||||
|
||||
BleRecentEntry entry_{};
|
||||
BleRecentEntriesView recent_entries_view{columns, recent};
|
||||
BleRecentEntriesView recent_entries_filter_view{columns, filterEntries};
|
||||
BleRecentEntryDetailView recent_entry_detail_view{nav_, entry_};
|
||||
|
||||
MessageHandlerRegistration message_handler_packet{
|
||||
Message::ID::BlePacket,
|
||||
[this](Message* const p) {
|
||||
const auto message = static_cast<const BLEPacketMessage*>(p);
|
||||
this->on_data(message->packet);
|
||||
}};
|
||||
};
|
||||
|
||||
} /* namespace ui */
|
||||
|
||||
#endif /*__UI_AFSK_RX_H__*/
|
||||
@@ -0,0 +1,479 @@
|
||||
/*
|
||||
* Copyright (C) 2014 Jared Boone, ShareBrained Technology, Inc.
|
||||
* Copyright (C) 2017 Furrtek
|
||||
* Copyright (C) 2023 TJ Baginski
|
||||
*
|
||||
* 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 "ble_tx_app.hpp"
|
||||
#include "ble_rx_app.hpp"
|
||||
|
||||
#include "ui_fileman.hpp"
|
||||
#include "ui_modemsetup.hpp"
|
||||
|
||||
#include "audio.hpp"
|
||||
#include "baseband_api.hpp"
|
||||
#include "io_file.hpp"
|
||||
#include "modems.hpp"
|
||||
#include "portapack_persistent_memory.hpp"
|
||||
#include "rtc_time.hpp"
|
||||
#include "string_format.hpp"
|
||||
|
||||
using namespace portapack;
|
||||
using namespace modems;
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
void BLELoggerTx::log_raw_data(const std::string& data) {
|
||||
log_file.write_entry(data);
|
||||
}
|
||||
|
||||
bool hasValidHexPairs(const std::string& str, int totalPairs) {
|
||||
int validPairs = 0;
|
||||
|
||||
for (int i = 0; i < totalPairs * 2; i += 2) {
|
||||
char c1 = str[i];
|
||||
char c2 = str[i + 1];
|
||||
|
||||
if (!(std::isxdigit(c1) && std::isxdigit(c2))) {
|
||||
return false; // Return false if any pair is invalid.
|
||||
}
|
||||
|
||||
validPairs++;
|
||||
}
|
||||
|
||||
return (validPairs == totalPairs);
|
||||
}
|
||||
|
||||
std::vector<std::string> splitIntoStrings(const char* input) {
|
||||
std::vector<std::string> result;
|
||||
int length = std::strlen(input);
|
||||
int start = 0;
|
||||
|
||||
while (start < length) {
|
||||
int remaining = length - start;
|
||||
int chunkSize = (remaining > 30) ? 30 : remaining;
|
||||
result.push_back(std::string(input + start, chunkSize));
|
||||
start += chunkSize;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
uint32_t stringToUint32(const std::string& str) {
|
||||
size_t pos = 0;
|
||||
uint32_t result = 0;
|
||||
|
||||
while (pos < str.size() && std::isdigit(str[pos])) {
|
||||
int digit = str[pos] - '0';
|
||||
|
||||
// Check for overflow before adding the next digit
|
||||
if (result > (UINT32_MAX - digit) / 10) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
result = result * 10 + digit;
|
||||
pos++;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void readUntil(File& file, char* result, std::size_t maxBufferSize, char delimiter) {
|
||||
std::size_t bytesRead = 0;
|
||||
|
||||
while (true) {
|
||||
char ch;
|
||||
File::Result<File::Size> readResult = file.read(&ch, 1);
|
||||
|
||||
if (readResult.is_ok() && readResult.value() > 0) {
|
||||
if (ch == delimiter) {
|
||||
// Found a space character, stop reading
|
||||
break;
|
||||
} else if (bytesRead < maxBufferSize) {
|
||||
// Append the character to the result if there's space
|
||||
result[bytesRead++] = ch;
|
||||
} else {
|
||||
// Buffer is full, break to prevent overflow
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
break; // End of file or error
|
||||
}
|
||||
}
|
||||
|
||||
// Null-terminate the result string
|
||||
result[bytesRead] = '\0';
|
||||
}
|
||||
|
||||
void generateRandomMacAddress(char* macAddress) {
|
||||
const char hexDigits[] = "0123456789ABCDEF";
|
||||
|
||||
// Generate 12 random hexadecimal characters
|
||||
for (int i = 0; i < 12; i++) {
|
||||
int randomIndex = rand() % 16;
|
||||
macAddress[i] = hexDigits[randomIndex];
|
||||
}
|
||||
macAddress[12] = '\0'; // Null-terminate the string
|
||||
}
|
||||
|
||||
static std::uint64_t get_freq_by_channel_number(uint8_t channel_number) {
|
||||
uint64_t freq_hz;
|
||||
|
||||
switch (channel_number) {
|
||||
case 37:
|
||||
freq_hz = 2'402'000'000ull;
|
||||
break;
|
||||
case 38:
|
||||
freq_hz = 2'426'000'000ull;
|
||||
break;
|
||||
case 39:
|
||||
freq_hz = 2'480'000'000ull;
|
||||
break;
|
||||
case 0 ... 10:
|
||||
freq_hz = 2'404'000'000ull + channel_number * 2'000'000ull;
|
||||
break;
|
||||
case 11 ... 36:
|
||||
freq_hz = 2'428'000'000ull + (channel_number - 11) * 2'000'000ull;
|
||||
break;
|
||||
default:
|
||||
freq_hz = UINT64_MAX;
|
||||
}
|
||||
|
||||
return freq_hz;
|
||||
}
|
||||
|
||||
namespace ui {
|
||||
|
||||
void BLETxView::focus() {
|
||||
button_open.focus();
|
||||
}
|
||||
|
||||
bool BLETxView::is_active() const {
|
||||
return (bool)is_running;
|
||||
}
|
||||
|
||||
void BLETxView::file_error() {
|
||||
nav_.display_modal("Error", "File read error.");
|
||||
}
|
||||
|
||||
bool BLETxView::saveFile(const std::filesystem::path& path) {
|
||||
File f;
|
||||
auto error = f.create(path);
|
||||
if (error)
|
||||
return false;
|
||||
|
||||
for (uint32_t i = 0; i < num_packets; i++) {
|
||||
std::string macAddressStr = packets[i].macAddress;
|
||||
std::string advertisementDataStr = packets[i].advertisementData;
|
||||
std::string packetCountStr = packets[i].packetCount;
|
||||
|
||||
std::string packetString = macAddressStr + ' ' + advertisementDataStr + ' ' + packetCountStr;
|
||||
|
||||
// Are we on the last line?
|
||||
if (i != num_packets - 1) {
|
||||
packetString += '\n';
|
||||
}
|
||||
|
||||
f.write(packetString.c_str(), packetString.length());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void BLETxView::toggle() {
|
||||
if (is_active()) {
|
||||
stop();
|
||||
} else {
|
||||
start();
|
||||
}
|
||||
}
|
||||
|
||||
void BLETxView::start() {
|
||||
// Generate new random Mac Address.
|
||||
generateRandomMacAddress(randomMac);
|
||||
|
||||
if (!is_active()) {
|
||||
// Check if file is present before continuing.
|
||||
File data_file;
|
||||
|
||||
auto error = data_file.open(file_path);
|
||||
if (error && !file_override) {
|
||||
file_error();
|
||||
check_loop.set_value(false);
|
||||
return;
|
||||
} else {
|
||||
// Send first or single packet.
|
||||
packet_counter = packets[current_packet].packet_count;
|
||||
progressbar.set_max(packets[current_packet].packet_count);
|
||||
button_play.set_bitmap(&bitmap_stop);
|
||||
|
||||
baseband::set_btletx(channel_number, random_mac ? randomMac : packets[current_packet].macAddress, packets[current_packet].advertisementData, pduType);
|
||||
transmitter_model.enable();
|
||||
|
||||
is_running = true;
|
||||
}
|
||||
} else {
|
||||
// Send next packet.
|
||||
baseband::set_btletx(channel_number, random_mac ? randomMac : packets[current_packet].macAddress, packets[current_packet].advertisementData, pduType);
|
||||
}
|
||||
|
||||
if ((packet_counter % 10) == 0) {
|
||||
text_packets_sent.set(to_string_dec_uint(packet_counter));
|
||||
}
|
||||
|
||||
packet_counter--;
|
||||
|
||||
progressbar.set_value(packets[current_packet].packet_count - packet_counter);
|
||||
}
|
||||
|
||||
void BLETxView::stop() {
|
||||
transmitter_model.disable();
|
||||
progressbar.set_value(0);
|
||||
button_play.set_bitmap(&bitmap_play);
|
||||
check_loop.set_value(false);
|
||||
|
||||
current_packet = 0;
|
||||
text_packets_sent.set(to_string_dec_uint(packets[0].packet_count));
|
||||
packet_counter = packets[0].packet_count;
|
||||
update_packet_display(packets[0]);
|
||||
|
||||
is_running = false;
|
||||
}
|
||||
|
||||
void BLETxView::on_tx_progress(const bool done) {
|
||||
if (done) {
|
||||
if (is_active()) {
|
||||
// Reached end of current packet repeats.
|
||||
if (packet_counter == 0) {
|
||||
// Done sending all packets.
|
||||
if (current_packet == (num_packets - 1)) {
|
||||
// If looping, restart from beginning.
|
||||
if (check_loop.value()) {
|
||||
current_packet = 0;
|
||||
packet_counter = packets[current_packet].packet_count;
|
||||
update_packet_display(packets[current_packet]);
|
||||
} else {
|
||||
stop();
|
||||
}
|
||||
} else {
|
||||
current_packet++;
|
||||
packet_counter = packets[current_packet].packet_count;
|
||||
update_packet_display(packets[current_packet]);
|
||||
}
|
||||
} else {
|
||||
if ((timer_count % timer_period) == 0) {
|
||||
start();
|
||||
}
|
||||
}
|
||||
|
||||
timer_count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BLETxView::BLETxView(NavigationView& nav)
|
||||
: nav_{nav} {
|
||||
baseband::run_image(portapack::spi_flash::image_tag_btle_tx);
|
||||
|
||||
add_children({&button_open,
|
||||
&text_filename,
|
||||
&progressbar,
|
||||
&check_rand_mac,
|
||||
&field_frequency,
|
||||
&tx_view, // now it handles previous rfgain, rfamp.
|
||||
&check_loop,
|
||||
&button_play,
|
||||
&label_speed,
|
||||
&options_speed,
|
||||
&options_channel,
|
||||
&options_adv_type,
|
||||
&label_packet_index,
|
||||
&text_packet_index,
|
||||
&label_packets_sent,
|
||||
&text_packets_sent,
|
||||
&label_mac_address,
|
||||
&text_mac_address,
|
||||
&label_data_packet,
|
||||
&button_save_packet,
|
||||
&button_switch,
|
||||
&console});
|
||||
|
||||
field_frequency.set_step(0);
|
||||
|
||||
ensure_directory(packet_save_path);
|
||||
|
||||
button_play.on_select = [this](ImageButton&) {
|
||||
this->toggle();
|
||||
};
|
||||
|
||||
options_channel.on_change = [this](size_t, int32_t i) {
|
||||
field_frequency.set_value(get_freq_by_channel_number(i));
|
||||
channel_number = i;
|
||||
};
|
||||
|
||||
options_speed.on_change = [this](size_t, int32_t i) {
|
||||
timer_period = i;
|
||||
};
|
||||
|
||||
options_adv_type.on_change = [this](size_t, int32_t i) {
|
||||
pduType = (PKT_TYPE)i;
|
||||
};
|
||||
|
||||
options_speed.set_selected_index(0);
|
||||
options_channel.set_selected_index(0);
|
||||
options_adv_type.set_selected_index(0);
|
||||
|
||||
check_rand_mac.set_value(false);
|
||||
check_rand_mac.on_select = [this](Checkbox&, bool v) {
|
||||
random_mac = v;
|
||||
};
|
||||
|
||||
button_open.on_select = [this, &nav](Button&) {
|
||||
auto open_view = nav.push<FileLoadView>(".TXT");
|
||||
open_view->on_changed = [this](std::filesystem::path new_file_path) {
|
||||
on_file_changed(new_file_path);
|
||||
|
||||
nav_.set_on_pop([this]() { button_play.focus(); });
|
||||
};
|
||||
};
|
||||
|
||||
button_save_packet.on_select = [this, &nav](Button&) {
|
||||
packetFileBuffer = "";
|
||||
text_prompt(
|
||||
nav,
|
||||
packetFileBuffer,
|
||||
64,
|
||||
[this](std::string& buffer) {
|
||||
on_save_file(buffer);
|
||||
});
|
||||
};
|
||||
|
||||
button_switch.on_select = [this, &nav](Button&) {
|
||||
nav_.set_on_pop([this]() { nav_.push<BLERxView>(); });
|
||||
nav_.pop();
|
||||
};
|
||||
}
|
||||
|
||||
BLETxView::BLETxView(
|
||||
NavigationView& nav,
|
||||
BLETxPacket packet)
|
||||
: BLETxView(nav) {
|
||||
packets[0] = packet;
|
||||
update_packet_display(packets[0]);
|
||||
|
||||
num_packets = 1;
|
||||
file_override = true;
|
||||
}
|
||||
|
||||
void BLETxView::on_file_changed(const fs::path& new_file_path) {
|
||||
file_path = fs::path(u"/") + new_file_path;
|
||||
num_packets = 0;
|
||||
|
||||
{ // Get the size of the data file.
|
||||
File data_file;
|
||||
auto error = data_file.open(file_path);
|
||||
if (error) {
|
||||
file_error();
|
||||
file_path = "";
|
||||
return;
|
||||
}
|
||||
|
||||
do {
|
||||
readUntil(data_file, packets[num_packets].macAddress, mac_address_size_str, ' ');
|
||||
readUntil(data_file, packets[num_packets].advertisementData, max_packet_size_str, ' ');
|
||||
readUntil(data_file, packets[num_packets].packetCount, max_packet_repeat_str, '\n');
|
||||
|
||||
uint64_t macAddressSize = strlen(packets[num_packets].macAddress);
|
||||
uint64_t advertisementDataSize = strlen(packets[num_packets].advertisementData);
|
||||
uint64_t packetCountSize = strlen(packets[num_packets].packetCount);
|
||||
|
||||
packets[num_packets].packet_count = stringToUint32(packets[num_packets].packetCount);
|
||||
packet_counter = packets[num_packets].packet_count;
|
||||
|
||||
// Verify Data.
|
||||
if ((macAddressSize == mac_address_size_str) && (advertisementDataSize < max_packet_size_str) && (packetCountSize < max_packet_repeat_str) &&
|
||||
hasValidHexPairs(packets[num_packets].macAddress, macAddressSize / 2) && hasValidHexPairs(packets[num_packets].advertisementData, advertisementDataSize / 2) && (packets[num_packets].packet_count >= 50) && (packets[num_packets].packet_count < max_packet_repeat_count)) {
|
||||
text_filename.set(truncate(file_path.filename().string(), 12));
|
||||
|
||||
} else {
|
||||
// Did not find any packets.
|
||||
if (num_packets == 0) {
|
||||
file_path = "";
|
||||
return;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
num_packets++;
|
||||
|
||||
} while (num_packets < max_num_packets);
|
||||
|
||||
update_packet_display(packets[0]);
|
||||
}
|
||||
}
|
||||
|
||||
void BLETxView::on_save_file(const std::string value) {
|
||||
auto folder = packet_save_path.parent_path();
|
||||
auto ext = packet_save_path.extension();
|
||||
auto new_path = folder / value + ext;
|
||||
|
||||
saveFile(new_path);
|
||||
}
|
||||
|
||||
void BLETxView::on_data(uint32_t value, bool is_data) {
|
||||
std::string str_console = "";
|
||||
|
||||
if (is_data) {
|
||||
str_console += (char)(value);
|
||||
}
|
||||
|
||||
console.write(str_console);
|
||||
}
|
||||
|
||||
void BLETxView::update_packet_display(BLETxPacket packet) {
|
||||
std::string formattedMacAddress = to_string_formatted_mac_address(packet.macAddress);
|
||||
|
||||
std::vector<std::string> strings = splitIntoStrings(packet.advertisementData);
|
||||
|
||||
text_packet_index.set(to_string_dec_uint(current_packet));
|
||||
|
||||
text_packets_sent.set(to_string_dec_uint(packet.packet_count));
|
||||
|
||||
text_mac_address.set(formattedMacAddress);
|
||||
|
||||
console.clear(true);
|
||||
|
||||
for (const std::string& str : strings) {
|
||||
console.writeln(str);
|
||||
}
|
||||
}
|
||||
|
||||
void BLETxView::set_parent_rect(const Rect new_parent_rect) {
|
||||
View::set_parent_rect(new_parent_rect);
|
||||
const Rect content_rect{0, header_height, new_parent_rect.width(), new_parent_rect.height() - header_height - switch_button_height};
|
||||
console.set_parent_rect(content_rect);
|
||||
}
|
||||
|
||||
BLETxView::~BLETxView() {
|
||||
transmitter_model.disable();
|
||||
baseband::shutdown();
|
||||
}
|
||||
|
||||
} /* namespace ui */
|
||||
@@ -0,0 +1,290 @@
|
||||
/*
|
||||
* Copyright (C) 2014 Jared Boone, ShareBrained Technology, Inc.
|
||||
* Copyright (C) 2017 Furrtek
|
||||
* Copyright (C) 2023 TJ Baginski
|
||||
*
|
||||
* 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 __BLE_TX_APP_H__
|
||||
#define __BLE_TX_APP_H__
|
||||
|
||||
#include "ui.hpp"
|
||||
#include "ui_navigation.hpp"
|
||||
#include "ui_receiver.hpp"
|
||||
#include "ui_transmitter.hpp"
|
||||
#include "ui_freq_field.hpp"
|
||||
#include "ui_record_view.hpp"
|
||||
#include "app_settings.hpp"
|
||||
#include "radio_state.hpp"
|
||||
#include "replay_thread.hpp"
|
||||
#include "log_file.hpp"
|
||||
#include "utility.hpp"
|
||||
|
||||
#include "recent_entries.hpp"
|
||||
|
||||
#include <string>
|
||||
#include <memory>
|
||||
|
||||
class BLELoggerTx {
|
||||
public:
|
||||
Optional<File::Error> append(const std::string& filename) {
|
||||
return log_file.append(filename);
|
||||
}
|
||||
|
||||
void log_raw_data(const std::string& data);
|
||||
|
||||
private:
|
||||
LogFile log_file{};
|
||||
};
|
||||
|
||||
namespace ui {
|
||||
|
||||
struct BLETxPacket {
|
||||
char macAddress[13];
|
||||
char advertisementData[63];
|
||||
char packetCount[11];
|
||||
uint32_t packet_count;
|
||||
};
|
||||
|
||||
class BLETxView : public View {
|
||||
public:
|
||||
BLETxView(NavigationView& nav);
|
||||
BLETxView(NavigationView& nav, BLETxPacket packet);
|
||||
~BLETxView();
|
||||
|
||||
void set_parent_rect(const Rect new_parent_rect) override;
|
||||
void paint(Painter&) override{};
|
||||
|
||||
void focus() override;
|
||||
|
||||
bool is_active() const;
|
||||
void toggle();
|
||||
void start();
|
||||
void stop();
|
||||
void handle_replay_thread_done(const uint32_t return_code);
|
||||
void file_error();
|
||||
bool saveFile(const std::filesystem::path& path);
|
||||
|
||||
std::string title() const override { return "BLE TX"; };
|
||||
|
||||
private:
|
||||
void on_data(uint32_t value, bool is_data);
|
||||
void on_tx_progress(const bool done);
|
||||
void on_file_changed(const std::filesystem::path& new_file_path);
|
||||
void update_packet_display(BLETxPacket packet);
|
||||
void on_save_file(const std::string value);
|
||||
|
||||
NavigationView& nav_;
|
||||
TxRadioState radio_state_{
|
||||
2'402'000'000 /* frequency */,
|
||||
4'000'000 /* bandwidth */,
|
||||
4'000'000 /* sampling rate */
|
||||
};
|
||||
app_settings::SettingsManager settings_{
|
||||
"ble_tx_app", app_settings::Mode::TX};
|
||||
|
||||
uint8_t console_color{0};
|
||||
uint32_t prev_value{0};
|
||||
|
||||
std::filesystem::path file_path{};
|
||||
std::filesystem::path packet_save_path{u"BLETX/BLETX_????.TXT"};
|
||||
uint8_t channel_number = 37;
|
||||
|
||||
char randomMac[13] = "010203040506";
|
||||
|
||||
bool is_running = false;
|
||||
uint64_t timer_count{0};
|
||||
uint64_t timer_period{256};
|
||||
bool repeatLoop = false;
|
||||
uint32_t packet_counter{0};
|
||||
uint32_t num_packets{0};
|
||||
uint32_t current_packet{0};
|
||||
bool random_mac = false;
|
||||
bool file_override = false;
|
||||
|
||||
enum PKT_TYPE {
|
||||
INVALID_TYPE,
|
||||
RAW,
|
||||
DISCOVERY,
|
||||
IBEACON,
|
||||
ADV_IND,
|
||||
ADV_DIRECT_IND,
|
||||
ADV_NONCONN_IND,
|
||||
ADV_SCAN_IND,
|
||||
SCAN_REQ,
|
||||
SCAN_RSP,
|
||||
CONNECT_REQ,
|
||||
LL_DATA,
|
||||
LL_CONNECTION_UPDATE_REQ,
|
||||
LL_CHANNEL_MAP_REQ,
|
||||
LL_TERMINATE_IND,
|
||||
LL_ENC_REQ,
|
||||
LL_ENC_RSP,
|
||||
LL_START_ENC_REQ,
|
||||
LL_START_ENC_RSP,
|
||||
LL_UNKNOWN_RSP,
|
||||
LL_FEATURE_REQ,
|
||||
LL_FEATURE_RSP,
|
||||
LL_PAUSE_ENC_REQ,
|
||||
LL_PAUSE_ENC_RSP,
|
||||
LL_VERSION_IND,
|
||||
LL_REJECT_IND,
|
||||
NUM_PKT_TYPE
|
||||
};
|
||||
|
||||
static constexpr uint8_t mac_address_size_str{12};
|
||||
static constexpr uint8_t max_packet_size_str{62};
|
||||
static constexpr uint8_t max_packet_repeat_str{10};
|
||||
static constexpr uint32_t max_packet_repeat_count{UINT32_MAX};
|
||||
static constexpr uint32_t max_num_packets{256};
|
||||
|
||||
BLETxPacket packets[max_num_packets];
|
||||
|
||||
PKT_TYPE pduType = {DISCOVERY};
|
||||
|
||||
static constexpr auto header_height = 9 * 16;
|
||||
static constexpr auto switch_button_height = 3 * 16;
|
||||
|
||||
Button button_open{
|
||||
{0 * 8, 0 * 16, 10 * 8, 2 * 16},
|
||||
"Open file"};
|
||||
|
||||
Text text_filename{
|
||||
{11 * 8, 0 * 16, 12 * 8, 16},
|
||||
"-"};
|
||||
|
||||
ProgressBar progressbar{
|
||||
{11 * 8, 1 * 16, 9 * 8, 16}};
|
||||
|
||||
Checkbox check_rand_mac{
|
||||
{21 * 8, 1 * 16},
|
||||
6,
|
||||
"Random",
|
||||
true};
|
||||
|
||||
TxFrequencyField field_frequency{
|
||||
{0 * 8, 2 * 16},
|
||||
nav_};
|
||||
|
||||
TransmitterView2 tx_view{
|
||||
{11 * 8, 2 * 16},
|
||||
/*short_ui*/ true};
|
||||
|
||||
Checkbox check_loop{
|
||||
{21 * 8, 2 * 16},
|
||||
4,
|
||||
"Loop",
|
||||
true};
|
||||
|
||||
ImageButton button_play{
|
||||
{28 * 8, 2 * 16, 2 * 8, 1 * 16},
|
||||
&bitmap_play,
|
||||
Color::green(),
|
||||
Color::black()};
|
||||
|
||||
Labels label_speed{
|
||||
{{0 * 8, 6 * 8}, "Speed:", Color::light_grey()}};
|
||||
|
||||
OptionsField options_speed{
|
||||
{7 * 8, 6 * 8},
|
||||
3,
|
||||
{{"1 ", 256},
|
||||
{"2 ", 128},
|
||||
{"3 ", 64},
|
||||
{"4 ", 32},
|
||||
{"5 ", 16}}};
|
||||
|
||||
OptionsField options_channel{
|
||||
{11 * 8, 6 * 8},
|
||||
5,
|
||||
{{"Ch.37 ", 37},
|
||||
{"Ch.38", 38},
|
||||
{"Ch.39", 39}}};
|
||||
|
||||
OptionsField options_adv_type{
|
||||
{17 * 8, 6 * 8},
|
||||
14,
|
||||
{{"DISCOVERY ", DISCOVERY},
|
||||
{"ADV_IND", ADV_IND},
|
||||
{"ADV_DIRECT", ADV_DIRECT_IND},
|
||||
{"ADV_NONCONN", ADV_NONCONN_IND},
|
||||
{"SCAN_REQ", SCAN_REQ},
|
||||
{"SCAN_RSP", SCAN_RSP},
|
||||
{"CONNECT_REQ", CONNECT_REQ}}};
|
||||
|
||||
Labels label_packet_index{
|
||||
{{0 * 8, 10 * 8}, "Packet Index:", Color::light_grey()}};
|
||||
|
||||
Text text_packet_index{
|
||||
{13 * 8, 5 * 16, 12 * 8, 16},
|
||||
"-"};
|
||||
|
||||
Labels label_packets_sent{
|
||||
{{0 * 8, 12 * 8}, "Packets Left:", Color::light_grey()}};
|
||||
|
||||
Text text_packets_sent{
|
||||
{13 * 8, 6 * 16, 12 * 8, 16},
|
||||
"-"};
|
||||
|
||||
Labels label_mac_address{
|
||||
{{0 * 8, 14 * 8}, "Mac Address:", Color::light_grey()}};
|
||||
|
||||
Text text_mac_address{
|
||||
{12 * 8, 7 * 16, 20 * 8, 16},
|
||||
"-"};
|
||||
|
||||
Labels label_data_packet{
|
||||
{{0 * 8, 16 * 8}, "Packet Data:", Color::light_grey()}};
|
||||
|
||||
Console console{
|
||||
{0, 8 * 16, 240, 240}};
|
||||
|
||||
Button button_save_packet{
|
||||
{1 * 8, 16 * 16, 13 * 8, 2 * 16},
|
||||
"Save Packet"};
|
||||
|
||||
Button button_switch{
|
||||
{16 * 8, 16 * 16, 13 * 8, 2 * 16},
|
||||
"Switch to Rx"};
|
||||
|
||||
std::string str_log{""};
|
||||
bool logging{true};
|
||||
bool logging_done{false};
|
||||
std::string packetFileBuffer{};
|
||||
|
||||
std::unique_ptr<BLELoggerTx> logger{};
|
||||
|
||||
MessageHandlerRegistration message_handler_packet{
|
||||
Message::ID::AFSKData,
|
||||
[this](Message* const p) {
|
||||
const auto message = static_cast<const AFSKDataMessage*>(p);
|
||||
this->on_data(message->value, message->is_data);
|
||||
}};
|
||||
|
||||
MessageHandlerRegistration message_handler_tx_progress{
|
||||
Message::ID::TXProgress,
|
||||
[this](const Message* const p) {
|
||||
const auto message = *reinterpret_cast<const TXProgressMessage*>(p);
|
||||
this->on_tx_progress(message.done);
|
||||
}};
|
||||
};
|
||||
|
||||
} /* namespace ui */
|
||||
|
||||
#endif /*__UI_AFSK_RX_H__*/
|
||||
@@ -37,6 +37,7 @@ void AboutView::update() {
|
||||
break;
|
||||
case 2:
|
||||
console.writeln("NotherNgineer,zxkmm,u-foka");
|
||||
console.writeln("Netro");
|
||||
console.writeln("");
|
||||
break;
|
||||
|
||||
|
||||
@@ -70,7 +70,7 @@ BTLERxView::BTLERxView(NavigationView& nav)
|
||||
};
|
||||
|
||||
// Auto-configure modem for LCR RX (will be removed later)
|
||||
baseband::set_btle(persistent_memory::modem_baudrate(), 8, 0, false);
|
||||
baseband::set_btlerx(channel_number);
|
||||
|
||||
audio::set_rate(audio::Rate::Hz_24000);
|
||||
audio::output::start();
|
||||
|
||||
@@ -60,6 +60,8 @@ class BTLERxView : public View {
|
||||
uint8_t console_color{0};
|
||||
uint32_t prev_value{0};
|
||||
|
||||
static constexpr uint8_t channel_number = 37;
|
||||
|
||||
RFAmpField field_rf_amp{
|
||||
{13 * 8, 0 * 16}};
|
||||
LNAGainField field_lna{
|
||||
|
||||
@@ -124,8 +124,8 @@ void TemperatureWidget::paint(Painter& painter) {
|
||||
}
|
||||
|
||||
TemperatureWidget::temperature_t TemperatureWidget::temperature(const sample_t sensor_value) const {
|
||||
/*It seems to be a temperature difference of 25C*/
|
||||
return -40 + (sensor_value * 4.31) + 25; // max2837 datasheet temp 25ºC has sensor value: 15
|
||||
// Scaling is different for MAX2837 vs MAX2839 so it's now done in the respective chip-specific module
|
||||
return sensor_value;
|
||||
}
|
||||
|
||||
std::string TemperatureWidget::temperature_str(const temperature_t temperature) const {
|
||||
|
||||
@@ -156,7 +156,7 @@ void FileManBaseView::load_directory_contents(const fs::path& dir_path) {
|
||||
|
||||
for (const auto& entry : fs::directory_iterator(dir_path, u"*")) {
|
||||
// Hide files starting with '.' (hidden / tmp).
|
||||
if (is_hidden_file(entry.path()))
|
||||
if (!show_hidden_files && is_hidden_file(entry.path()))
|
||||
continue;
|
||||
|
||||
if (fs::is_regular_file(entry.status())) {
|
||||
@@ -568,6 +568,7 @@ FileManagerView::FileManagerView(
|
||||
&button_open_notepad,
|
||||
&button_rename_timestamp,
|
||||
&button_open_iq_trim,
|
||||
&button_show_hidden_files,
|
||||
});
|
||||
|
||||
menu_view.on_highlight = [this]() {
|
||||
@@ -658,6 +659,12 @@ FileManagerView::FileManagerView(
|
||||
} else
|
||||
nav_.display_modal("IQ Trim", "Not a capture file.");
|
||||
};
|
||||
|
||||
button_show_hidden_files.on_select = [this]() {
|
||||
show_hidden_files = !show_hidden_files;
|
||||
button_show_hidden_files.set_color(show_hidden_files ? Color::green() : Color::dark_grey());
|
||||
reload_current();
|
||||
};
|
||||
}
|
||||
|
||||
} // namespace ui
|
||||
|
||||
@@ -104,6 +104,8 @@ class FileManBaseView : public View {
|
||||
std::vector<fileman_entry> entry_list{};
|
||||
std::vector<uint32_t> saved_index_stack{};
|
||||
|
||||
bool show_hidden_files{false};
|
||||
|
||||
Labels labels{
|
||||
{{0, 0}, "Path:", Color::light_grey()}};
|
||||
|
||||
@@ -278,6 +280,12 @@ class FileManagerView : public FileManBaseView {
|
||||
{},
|
||||
&bitmap_icon_trim,
|
||||
Color::orange()};
|
||||
|
||||
NewButton button_show_hidden_files{
|
||||
{13 * 8, 34 * 8, 4 * 8, 32},
|
||||
{},
|
||||
&bitmap_icon_hide,
|
||||
Color::dark_grey()};
|
||||
};
|
||||
|
||||
} /* namespace ui */
|
||||
|
||||
@@ -0,0 +1,197 @@
|
||||
/*
|
||||
* Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc.
|
||||
* Copyright (C) 2016 Furrtek
|
||||
*
|
||||
* This file is part of PortaPack.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, Inc., 51 Franklin Street,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "ui_fsk_rx.hpp"
|
||||
|
||||
#include "audio.hpp"
|
||||
#include "baseband_api.hpp"
|
||||
#include "portapack_persistent_memory.hpp"
|
||||
#include "string_format.hpp"
|
||||
#include "utility.hpp"
|
||||
|
||||
#include "ui_freqman.hpp"
|
||||
|
||||
using namespace portapack;
|
||||
namespace pmem = portapack::persistent_memory;
|
||||
|
||||
void FskRxLogger::log_raw_data(const std::string& data, const uint32_t frequency) {
|
||||
std::string entry = "Raw: F:" + to_string_dec_uint(frequency) + "Hz";
|
||||
|
||||
// // Raw hex dump of all the codewords
|
||||
// for (size_t c = 0; c < 16; c++)
|
||||
// entry += to_string_hex(packet[c], 8) + " ";
|
||||
|
||||
log_file.write_entry(data + entry);
|
||||
}
|
||||
|
||||
void FskRxLogger::log_decoded(Timestamp timestamp, const std::string& text) {
|
||||
log_file.write_entry(timestamp, text);
|
||||
}
|
||||
|
||||
namespace ui {
|
||||
//---------------------------------------------------------------------------------------------------------------
|
||||
// Console View
|
||||
//---------------------------------------------------------------------------------------------------------------
|
||||
FskRxAppConsoleView::FskRxAppConsoleView(NavigationView& nav, Rect parent_rect)
|
||||
: View(parent_rect), nav_{nav} {
|
||||
add_child(&console);
|
||||
};
|
||||
|
||||
void FskRxAppConsoleView::on_packet(uint32_t value, bool is_data) {
|
||||
if (is_data) {
|
||||
console.write(to_string_dec_uint(value) + " ");
|
||||
}
|
||||
}
|
||||
|
||||
void FskRxAppConsoleView::on_show() {
|
||||
hidden(false);
|
||||
}
|
||||
|
||||
void FskRxAppConsoleView::on_hide() {
|
||||
hidden(true);
|
||||
}
|
||||
|
||||
FskRxAppConsoleView::~FskRxAppConsoleView() {
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------
|
||||
// Spectrum View
|
||||
//---------------------------------------------------------------------------------------------------------------
|
||||
FskRxAppView::FskRxAppView(NavigationView& nav, Rect parent_rect)
|
||||
: View(parent_rect), nav_{nav} {
|
||||
add_child(&waterfall);
|
||||
hidden(true);
|
||||
}
|
||||
|
||||
FskRxAppView::~FskRxAppView() {
|
||||
}
|
||||
|
||||
void FskRxAppView::focus() {
|
||||
}
|
||||
|
||||
void FskRxAppView::on_show() {
|
||||
hidden(false);
|
||||
waterfall.start();
|
||||
}
|
||||
|
||||
void FskRxAppView::on_hide() {
|
||||
hidden(true);
|
||||
waterfall.stop();
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------
|
||||
// Base View
|
||||
//---------------------------------------------------------------------------------------------------------------
|
||||
FskxRxMainView::FskxRxMainView(NavigationView& nav)
|
||||
: nav_{nav} {
|
||||
add_children({&tab_view,
|
||||
&view_data,
|
||||
&view_stream,
|
||||
&labels,
|
||||
&rssi,
|
||||
&channel,
|
||||
&field_rf_amp,
|
||||
&field_lna,
|
||||
&field_vga,
|
||||
&field_frequency,
|
||||
&deviation_frequency,
|
||||
&record_view});
|
||||
|
||||
baseband::run_image(portapack::spi_flash::image_tag_fskrx);
|
||||
|
||||
// DEBUG
|
||||
record_view.on_error = [&nav](std::string message) {
|
||||
nav.display_modal("Error", message);
|
||||
};
|
||||
|
||||
deviation_frequency.on_change = [this](rf::Frequency f) {
|
||||
refresh_ui(f);
|
||||
};
|
||||
|
||||
// Set initial sampling rate
|
||||
/* Bandwidth of 2FSK is 2 * Deviation */
|
||||
record_view.set_sampling_rate(initial_deviation * 2);
|
||||
|
||||
field_frequency.set_value(initial_target_frequency);
|
||||
deviation_frequency.set_value(initial_deviation);
|
||||
|
||||
logger.append(LOG_ROOT_DIR "/FSKRX.TXT");
|
||||
|
||||
baseband::set_fsk(initial_deviation);
|
||||
|
||||
audio::output::start();
|
||||
receiver_model.enable();
|
||||
}
|
||||
|
||||
void FskxRxMainView::handle_decoded(Timestamp timestamp, const std::string& prefix) {
|
||||
if (logging()) {
|
||||
logger.log_decoded(timestamp, prefix);
|
||||
}
|
||||
}
|
||||
|
||||
void FskxRxMainView::refresh_ui(rf::Frequency deviationHz) {
|
||||
/* Nyquist would imply a sample rate of 2x bandwidth, but because the ADC
|
||||
* provides 2 values (I,Q), the sample_rate is equal to bandwidth here. */
|
||||
/* Bandwidth of 2FSK is 2 * Deviation */
|
||||
auto sample_rate = deviationHz * 2;
|
||||
|
||||
/* base_rate (bandwidth) is used for FFT calculation and display LCD, and also in recording writing SD Card rate. */
|
||||
/* ex. sampling_rate values, 4Mhz, when recording 500 kHz (BW) and fs 8 Mhz, when selected 1 Mhz BW ... */
|
||||
/* ex. recording 500kHz BW to .C16 file, base_rate clock 500kHz x2(I,Q) x 2 bytes (int signed) =2MB/sec rate SD Card. */
|
||||
|
||||
if (!view_stream.hidden()) {
|
||||
view_stream.waterfall.stop();
|
||||
}
|
||||
|
||||
// record_view determines the correct oversampling to apply and returns the actual sample rate.
|
||||
// NB: record_view is what actually updates proc_capture baseband settings.
|
||||
auto actual_sample_rate = record_view.set_sampling_rate(sample_rate);
|
||||
|
||||
// Update the radio model with the actual sampling rate.
|
||||
receiver_model.set_sampling_rate(actual_sample_rate);
|
||||
|
||||
// Get suitable anti-aliasing BPF bandwidth for MAX2837 given the actual sample rate.
|
||||
auto anti_alias_filter_bandwidth = filter_bandwidth_for_sampling_rate(actual_sample_rate);
|
||||
receiver_model.set_baseband_bandwidth(anti_alias_filter_bandwidth);
|
||||
|
||||
if (!view_stream.hidden()) {
|
||||
view_stream.waterfall.start();
|
||||
}
|
||||
}
|
||||
|
||||
void FskxRxMainView::focus() {
|
||||
field_frequency.focus();
|
||||
}
|
||||
|
||||
void FskxRxMainView::set_parent_rect(const Rect new_parent_rect) {
|
||||
View::set_parent_rect(new_parent_rect);
|
||||
|
||||
ui::Rect waterfall_rect{0, 0, new_parent_rect.width(), new_parent_rect.height() - header_height};
|
||||
view_stream.waterfall.set_parent_rect(waterfall_rect);
|
||||
}
|
||||
|
||||
FskxRxMainView::~FskxRxMainView() {
|
||||
audio::output::stop();
|
||||
receiver_model.disable();
|
||||
baseband::shutdown();
|
||||
}
|
||||
} /* namespace ui */
|
||||
@@ -0,0 +1,178 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef __UI_FSK_RX_H__
|
||||
#define __UI_FSK_RX_H__
|
||||
|
||||
#include "ui_widget.hpp"
|
||||
#include "ui_freq_field.hpp"
|
||||
#include "ui_receiver.hpp"
|
||||
#include "ui_record_view.hpp"
|
||||
#include "ui_rssi.hpp"
|
||||
#include "ui_spectrum.hpp"
|
||||
#include "ui_styles.hpp"
|
||||
#include "ui_tabview.hpp"
|
||||
|
||||
#include "app_settings.hpp"
|
||||
#include "log_file.hpp"
|
||||
#include "radio_state.hpp"
|
||||
#include "pocsag_app.hpp"
|
||||
|
||||
#include <functional>
|
||||
|
||||
class FskRxLogger {
|
||||
public:
|
||||
Optional<File::Error> append(const std::string& filename) {
|
||||
return log_file.append(filename);
|
||||
}
|
||||
|
||||
void log_raw_data(const std::string& data, const uint32_t frequency);
|
||||
void log_decoded(Timestamp timestamp, const std::string& text);
|
||||
|
||||
private:
|
||||
LogFile log_file{};
|
||||
};
|
||||
|
||||
namespace ui {
|
||||
class FskRxAppConsoleView : public View {
|
||||
public:
|
||||
FskRxAppConsoleView(NavigationView& nav, Rect parent_rec);
|
||||
~FskRxAppConsoleView();
|
||||
|
||||
std::string title() const override { return "FSK RX Data"; };
|
||||
|
||||
void on_packet(uint32_t value, bool is_data);
|
||||
|
||||
void on_show() override;
|
||||
void on_hide() override;
|
||||
|
||||
private:
|
||||
NavigationView& nav_;
|
||||
|
||||
Console console{
|
||||
{0, 0, 240, 224}};
|
||||
};
|
||||
|
||||
class FskRxAppView : public View {
|
||||
public:
|
||||
FskRxAppView(NavigationView& nav, Rect parent_rect);
|
||||
~FskRxAppView();
|
||||
|
||||
void focus() override;
|
||||
void on_show() override;
|
||||
void on_hide() override;
|
||||
|
||||
spectrum::WaterfallView waterfall{};
|
||||
|
||||
std::string title() const override { return "FSK RX Stream"; };
|
||||
|
||||
private:
|
||||
NavigationView& nav_;
|
||||
RxRadioState radio_state_{};
|
||||
};
|
||||
|
||||
class FskxRxMainView : public View {
|
||||
public:
|
||||
FskxRxMainView(NavigationView& nav);
|
||||
~FskxRxMainView();
|
||||
|
||||
void focus() override;
|
||||
void set_parent_rect(const Rect new_parent_rect) override;
|
||||
|
||||
std::string title() const override { return "FSK RX"; };
|
||||
|
||||
private:
|
||||
static constexpr uint32_t initial_target_frequency = 902'075'000;
|
||||
static constexpr ui::Dim header_height = (5 * 16);
|
||||
|
||||
uint32_t initial_deviation{3750};
|
||||
|
||||
bool logging() const { return false; };
|
||||
bool logging_raw() const { return false; };
|
||||
|
||||
NavigationView& nav_;
|
||||
Rect view_rect = {0, header_height, 240, 224};
|
||||
|
||||
FskRxAppView view_stream{nav_, view_rect};
|
||||
FskRxAppConsoleView view_data{nav_, view_rect};
|
||||
|
||||
TabView tab_view{
|
||||
{"Data", Color::yellow(), &view_data},
|
||||
{"Stream", Color::cyan(), &view_stream}};
|
||||
|
||||
void refresh_ui(rf::Frequency f);
|
||||
void on_packet(uint32_t value, bool is_data);
|
||||
void handle_decoded(Timestamp timestamp, const std::string& prefix);
|
||||
|
||||
uint32_t last_address = 0;
|
||||
FskRxLogger logger{};
|
||||
uint16_t packet_count = 0;
|
||||
|
||||
RxFrequencyField field_frequency{
|
||||
{0 * 8, 4 * 8},
|
||||
nav_};
|
||||
|
||||
RFAmpField field_rf_amp{
|
||||
{11 * 8, 2 * 16}};
|
||||
|
||||
LNAGainField field_lna{
|
||||
{13 * 8, 2 * 16}};
|
||||
|
||||
VGAGainField field_vga{
|
||||
{16 * 8, 2 * 16}};
|
||||
|
||||
RSSI rssi{
|
||||
{19 * 8 - 4, 35, 6 * 8, 4}};
|
||||
|
||||
Channel channel{
|
||||
{19 * 8 - 4, 40, 6 * 8, 4}};
|
||||
|
||||
Labels labels{
|
||||
{{0 * 8, 3 * 16}, "Deviation:", Color::light_grey()},
|
||||
};
|
||||
|
||||
FrequencyField deviation_frequency{
|
||||
{10 * 8, 3 * 16},
|
||||
{3750, 500000},
|
||||
};
|
||||
|
||||
// DEBUG
|
||||
RecordView record_view{
|
||||
{0 * 8, 4 * 16, 30 * 8, 1 * 16},
|
||||
u"FSKRX_????.C16",
|
||||
u"FSKRX",
|
||||
RecordView::FileType::RawS16,
|
||||
16384,
|
||||
3};
|
||||
|
||||
MessageHandlerRegistration message_handler_packet{
|
||||
Message::ID::AFSKData,
|
||||
[this](Message* const p) {
|
||||
const auto message = static_cast<const AFSKDataMessage*>(p);
|
||||
this->view_data.on_packet(message->value, message->is_data);
|
||||
}};
|
||||
};
|
||||
|
||||
} /* namespace ui */
|
||||
|
||||
#endif /*__POCSAG_APP_H__*/
|
||||
@@ -40,6 +40,7 @@ IQTrimView::IQTrimView(NavigationView& nav)
|
||||
&text_samples,
|
||||
&text_max,
|
||||
&field_cutoff,
|
||||
&field_amplify,
|
||||
&button_trim,
|
||||
});
|
||||
|
||||
@@ -72,6 +73,11 @@ IQTrimView::IQTrimView(NavigationView& nav)
|
||||
refresh_ui();
|
||||
};
|
||||
|
||||
field_amplify.set_value(1); // 1X is default (no amplification)
|
||||
field_amplify.on_change = [this](int32_t) {
|
||||
refresh_ui();
|
||||
};
|
||||
|
||||
button_trim.on_select = [this](Button&) {
|
||||
if (trim_capture()) {
|
||||
profile_capture();
|
||||
@@ -133,7 +139,18 @@ void IQTrimView::focus() {
|
||||
void IQTrimView::refresh_ui() {
|
||||
field_path.set_text(path_.filename().string());
|
||||
text_samples.set(to_string_dec_uint(info_->sample_count));
|
||||
text_max.set(to_string_dec_uint(info_->max_power));
|
||||
|
||||
// show max power after amplification applied
|
||||
uint64_t power_amp = field_amplify.value() * field_amplify.value() * field_amplify.value() * field_amplify.value();
|
||||
text_max.set(to_string_dec_uint(info_->max_power * power_amp));
|
||||
|
||||
// show max power in red if amplification is too high, causing clipping
|
||||
uint32_t clipping_limit = (fs::capture_file_sample_size(path_) == sizeof(complex8_t)) ? 0x80 : 0x8000;
|
||||
if ((field_amplify.value() * info_->max_iq) > clipping_limit)
|
||||
text_max.set_style(&Styles::red);
|
||||
else
|
||||
text_max.set_style(&Styles::light_grey);
|
||||
|
||||
set_dirty();
|
||||
}
|
||||
|
||||
@@ -191,7 +208,7 @@ bool IQTrimView::trim_capture() {
|
||||
}
|
||||
|
||||
progress_ui.show_trimming();
|
||||
trimmed = iq::trim_capture_with_range(path_, trim_range, progress_ui.get_callback());
|
||||
trimmed = iq::trim_capture_with_range(path_, trim_range, progress_ui.get_callback(), field_amplify.value());
|
||||
progress_ui.clear();
|
||||
|
||||
if (!trimmed)
|
||||
|
||||
@@ -107,6 +107,8 @@ class IQTrimView : public View {
|
||||
{{0 * 8, 9 * 16}, "Max Pwr:", Color::light_grey()},
|
||||
{{0 * 8, 10 * 16}, "Cutoff :", Color::light_grey()},
|
||||
{{12 * 8, 10 * 16}, "%", Color::light_grey()},
|
||||
{{0 * 8, 12 * 16}, "Amplify:", Color::light_grey()},
|
||||
{{10 * 8, 12 * 16}, "x", Color::light_grey()},
|
||||
};
|
||||
|
||||
TextField field_path{
|
||||
@@ -135,7 +137,7 @@ class IQTrimView : public View {
|
||||
"0"};
|
||||
|
||||
Text text_max{
|
||||
{9 * 8, 9 * 16, 10 * 8, 1 * 16},
|
||||
{9 * 8, 9 * 16, 20 * 8, 1 * 16},
|
||||
"0"};
|
||||
|
||||
NumberField field_cutoff{
|
||||
@@ -145,6 +147,13 @@ class IQTrimView : public View {
|
||||
1,
|
||||
' '};
|
||||
|
||||
NumberField field_amplify{
|
||||
{9 * 8, 12 * 16},
|
||||
1,
|
||||
{1, 9},
|
||||
1,
|
||||
' '};
|
||||
|
||||
Button button_trim{
|
||||
{20 * 8, 16 * 16, 8 * 8, 2 * 16},
|
||||
"Trim"};
|
||||
|
||||
@@ -142,31 +142,24 @@ LevelView::LevelView(NavigationView& nav)
|
||||
}
|
||||
|
||||
void LevelView::on_statistics_update(const ChannelStatistics& statistics) {
|
||||
static int last_max_db = -1000;
|
||||
static int last_min_rssi = -1000;
|
||||
static int last_avg_rssi = -1000;
|
||||
static int last_max_rssi = -1000;
|
||||
static int16_t last_max_db = -1000;
|
||||
static int16_t last_min_rssi = -1000;
|
||||
static int16_t last_avg_rssi = -1000;
|
||||
static int16_t last_max_rssi = -1000;
|
||||
|
||||
rssi_graph.add_values(rssi.get_min(), rssi.get_avg(), rssi.get_max(), statistics.max_db);
|
||||
|
||||
bool refresh_db = false;
|
||||
bool refresh_rssi = false;
|
||||
|
||||
// refresh db
|
||||
if (last_max_db != statistics.max_db) {
|
||||
refresh_db = true;
|
||||
}
|
||||
if (last_min_rssi != rssi.get_min() || last_avg_rssi != rssi.get_avg() || last_max_rssi != rssi.get_max()) {
|
||||
refresh_rssi = true;
|
||||
}
|
||||
if (refresh_db) {
|
||||
last_max_db = statistics.max_db;
|
||||
freq_stats_db.set("Power: " + to_string_dec_int(statistics.max_db) + " db");
|
||||
}
|
||||
if (refresh_rssi) {
|
||||
last_min_rssi = rssi.get_min();
|
||||
last_avg_rssi = rssi.get_avg();
|
||||
last_max_rssi = rssi.get_max();
|
||||
freq_stats_rssi.set("RSSI: " + to_string_dec_int(rssi.get_min()) + "/" + to_string_dec_int(rssi.get_avg()) + "/" + to_string_dec_int(rssi.get_max()) + ",dt: " + to_string_dec_int(rssi.get_delta()));
|
||||
// refresh rssi
|
||||
if (last_min_rssi != rssi_graph.get_graph_min() || last_avg_rssi != rssi_graph.get_graph_avg() || last_max_rssi != rssi_graph.get_graph_max()) {
|
||||
last_min_rssi = rssi_graph.get_graph_min();
|
||||
last_avg_rssi = rssi_graph.get_graph_avg();
|
||||
last_max_rssi = rssi_graph.get_graph_max();
|
||||
freq_stats_rssi.set("RSSI: " + to_string_dec_int(last_min_rssi) + "/" + to_string_dec_int(last_avg_rssi) + "/" + to_string_dec_int(last_max_rssi) + ",dt: " + to_string_dec_int(rssi_graph.get_graph_delta()));
|
||||
}
|
||||
} /* on_statistic_updates */
|
||||
|
||||
|
||||
@@ -51,7 +51,7 @@ void MicTXView::focus() {
|
||||
field_rxfrequency.focus();
|
||||
break;
|
||||
default:
|
||||
field_va.focus();
|
||||
check_va.focus();
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -60,24 +60,56 @@ void MicTXView::update_vumeter() {
|
||||
vumeter.set_value(audio_level);
|
||||
}
|
||||
|
||||
void MicTXView::update_tx_icon() {
|
||||
tx_icon.set_foreground(transmitting ? Color::red() : Color::black());
|
||||
tx_icon.set_background(transmitting ? Color::yellow() : Color::black());
|
||||
}
|
||||
|
||||
void MicTXView::on_tx_progress(const bool done) {
|
||||
// Roger beep played, stop transmitting
|
||||
if (done)
|
||||
set_tx(false);
|
||||
}
|
||||
|
||||
uint8_t MicTXView::shift_bits(void) {
|
||||
uint8_t shift_bits_s16{4}; // shift bits factor to the captured ADC S16 audio sample.
|
||||
|
||||
if (audio::debug::codec_name() == "WM8731") {
|
||||
switch (ak4951_alc_and_wm8731_boost_GUI) {
|
||||
case 0: // +12 dB’s respect reference level orig fw 1.5.x fw FM : when +20dB's boost ON) and shift bits (>>8),
|
||||
shift_bits_s16 = 6; // now mic-boost on (+20dBs) and shift bits (>>6), +20+12=32 dB’s (orig fw +20 dBs+ 0dBs)=> +12dB's respect ref.
|
||||
break;
|
||||
case 1: // +06 dB’s reference level, (when +20dB's boost ON)
|
||||
shift_bits_s16 = 7; // now mic-boost on (+20dBs) and shift bits (>>7), +20+06=26 dB’s (orig fw +20 dBs+ 0dBs) => +06dB's respect ref.
|
||||
break;
|
||||
case 2:
|
||||
shift_bits_s16 = 4; // +04 dB’s respect ref level, (when +20dB's boost OFF)
|
||||
break; // now mic-boost off (+00dBs) shift bits (4) (+0+24dB's)=24 dBs => +04dB's respect ref.
|
||||
case 3:
|
||||
shift_bits_s16 = 5; // -02 dB’s respect ref level, (when +20dB's boost OFF)
|
||||
break; // now mic-boost off (+00dBs) shift bits (5) (+0+18dB's)=18 dBs => -02dB's respect ref.
|
||||
case 4:
|
||||
shift_bits_s16 = 6; // -08 dB’s respect ref level, (when +20dB's boost OFF)
|
||||
break; // now mic-boost off (+00dBs) shift bits (6) (+0+12dB's)=12 dBs => -08dB's respect ref.
|
||||
}
|
||||
} else {
|
||||
shift_bits_s16 = 8; // Initialized default fixed >>8_FM for FM tx mod, shift audio data for AK4951, using top 8 bits s16 data (>>8)
|
||||
}
|
||||
return shift_bits_s16;
|
||||
}
|
||||
|
||||
void MicTXView::configure_baseband() {
|
||||
// TODO: Can this use the transmitter model instead?
|
||||
baseband::set_audiotx_config(
|
||||
sampling_rate / 20, // Update vu-meter at 20Hz
|
||||
transmitting ? transmitter_model.channel_bandwidth() : 0,
|
||||
mic_gain,
|
||||
shift_bits_s16, // to be used in dsp_modulate
|
||||
mic_gain_x10 / 10.0,
|
||||
shift_bits(), // to be used in dsp_modulate
|
||||
TONES_F2D(tone_key_frequency(tone_key_index), sampling_rate),
|
||||
enable_am,
|
||||
enable_dsb,
|
||||
enable_usb,
|
||||
enable_lsb);
|
||||
(mic_mod_index == MIC_MOD_AM),
|
||||
(mic_mod_index == MIC_MOD_DSB),
|
||||
(mic_mod_index == MIC_MOD_USB),
|
||||
(mic_mod_index == MIC_MOD_LSB));
|
||||
}
|
||||
|
||||
void MicTXView::set_tx(bool enable) {
|
||||
@@ -101,12 +133,24 @@ void MicTXView::set_tx(bool enable) {
|
||||
transmitting = false;
|
||||
configure_baseband();
|
||||
transmitter_model.disable();
|
||||
if (rx_enabled) // If audio RX is enabled and we've been transmitting
|
||||
|
||||
if (rx_enabled) {
|
||||
rxaudio(true); // Turn back on audio RX
|
||||
|
||||
// TODO FIXME: this isn't working: vu meter isn't going to 0:
|
||||
vumeter.set_value(0); // Reset vumeter
|
||||
vumeter.dirty(); // Force to refresh vumeter.
|
||||
}
|
||||
}
|
||||
}
|
||||
update_tx_icon();
|
||||
}
|
||||
|
||||
bool MicTXView::tx_button_held() {
|
||||
const auto switches_state = get_switches_state();
|
||||
return switches_state[(size_t)ui::KeyEvent::Select];
|
||||
};
|
||||
|
||||
void MicTXView::do_timing() {
|
||||
if (va_enabled) {
|
||||
if (!transmitting) {
|
||||
@@ -128,7 +172,8 @@ void MicTXView::do_timing() {
|
||||
if ((decay_timer >> 8) >= decay_ms) {
|
||||
decay_timer = 0;
|
||||
attack_timer = 0;
|
||||
set_tx(false);
|
||||
if (!button_touch && !tx_button_held())
|
||||
set_tx(false);
|
||||
} else {
|
||||
decay_timer += lcd_frame_duration;
|
||||
}
|
||||
@@ -138,42 +183,39 @@ void MicTXView::do_timing() {
|
||||
}
|
||||
} else {
|
||||
// Check for PTT release
|
||||
const auto switches_state = get_switches_state();
|
||||
if (!switches_state[4] && transmitting && !button_touch) // Select button
|
||||
if (transmitting && !button_touch && !tx_button_held())
|
||||
set_tx(false);
|
||||
}
|
||||
}
|
||||
|
||||
void MicTXView::rxaudio(bool is_on) {
|
||||
if (is_on) {
|
||||
void MicTXView::rxaudio(bool enable) {
|
||||
if (enable) {
|
||||
audio::input::stop();
|
||||
baseband::shutdown();
|
||||
|
||||
if (enable_am || enable_usb || enable_lsb || enable_dsb) { // "NFM/FM", 0, " WFM ", 1, " AM ", 2, " USB ", 3, " LSB ", 4, " DSB-SC", 5
|
||||
baseband::run_image(portapack::spi_flash::image_tag_am_audio);
|
||||
receiver_model.set_modulation(ReceiverModel::Mode::AMAudio); // that AM demodulation engine is common to all Amplitude mod : AM/USB/LSB/DSB (2,3,4,5)
|
||||
if (options_mode.selected_index() < 5) // We will be called here with 2,3,4,5. We treat here demod. filter 2,3,4; (excluding DSB-C case (5) it is treated more down).
|
||||
receiver_model.set_am_configuration(options_mode.selected_index() - 1); // selecting proper filter(2,3,4). 2-1=1=>6k-AM(1), 3-1=2=>+3k-USB(2), 4-1=3=>-3K-LSB(3),
|
||||
} else { // We are in NFM/FM or WFM (NFM BW:8k5 or 11k / FM BW 16k / WFM BW:200k)
|
||||
|
||||
if (enable_wfm) { // WFM, BW 200Khz aprox, or the two new addional BW filters (180k, 40k)
|
||||
switch (mic_mod_index) {
|
||||
case MIC_MOD_NFM: // NFM BW:8k5 or 11k / FM BW 16k
|
||||
baseband::run_image(portapack::spi_flash::image_tag_nfm_audio);
|
||||
receiver_model.set_modulation(ReceiverModel::Mode::NarrowbandFMAudio);
|
||||
// receiver_model.set_nbfm_configuration(n); is called above, depending user's selection (8k5, 11k, 16k).
|
||||
break;
|
||||
case MIC_MOD_WFM: // WFM, BW 200Khz aprox, or the two new addional BW filters (180k, 40k)
|
||||
baseband::run_image(portapack::spi_flash::image_tag_wfm_audio);
|
||||
receiver_model.set_modulation(ReceiverModel::Mode::WidebandFMAudio);
|
||||
// receiver_model.set_wfm_configuration(n); // it is called above, depending user's selection (200k, 180k, 0k).
|
||||
} else { // NFM BW:8k5 or 11k / FM BW 16k
|
||||
baseband::run_image(portapack::spi_flash::image_tag_nfm_audio);
|
||||
receiver_model.set_modulation(ReceiverModel::Mode::NarrowbandFMAudio); //
|
||||
// receiver_model.set_nbfm_configuration(n); is called above, depending user's selection (8k5, 11k, 16k).
|
||||
}
|
||||
// receiver_model.set_wfm_configuration(n); is called above, depending user's selection (200k, 180k, 0k).
|
||||
break;
|
||||
case MIC_MOD_AM:
|
||||
case MIC_MOD_DSB:
|
||||
case MIC_MOD_USB:
|
||||
case MIC_MOD_LSB:
|
||||
baseband::run_image(portapack::spi_flash::image_tag_am_audio);
|
||||
receiver_model.set_modulation(ReceiverModel::Mode::AMAudio); // that AM demodulation engine is common to all Amplitude mod : AM/USB/LSB/DSB (2,3,4,5)
|
||||
if (options_mode.selected_index() < 5) // We will be called here with 2,3,4,5. We treat here demod. filter 2,3,4; (excluding DSB-C case (5) it is treated more down).
|
||||
receiver_model.set_am_configuration(options_mode.selected_index() - 1); // selecting proper filter(2,3,4). 2-1=1=>6k-AM(1), 3-1=2=>+3k-USB(2), 4-1=3=>-3K-LSB(3),
|
||||
break;
|
||||
}
|
||||
|
||||
if (bool_same_F_tx_rx_enabled) // when stop TX, define to which freq RX we return
|
||||
receiver_model.set_target_frequency(tx_frequency); // Update freq also for RX = TX
|
||||
else
|
||||
receiver_model.set_target_frequency(rx_frequency); // Now with separate freq controls!
|
||||
receiver_model.set_lna(rx_lna);
|
||||
receiver_model.set_vga(rx_vga);
|
||||
receiver_model.set_rf_amp(rx_amp);
|
||||
receiver_model.set_target_frequency(bool_same_F_tx_rx_enabled ? tx_frequency : rx_frequency);
|
||||
receiver_model.enable();
|
||||
audio::output::start();
|
||||
} else { // These incredibly convoluted steps are required for the vumeter to reappear when stopping RX.
|
||||
@@ -183,14 +225,82 @@ void MicTXView::rxaudio(bool is_on) {
|
||||
|
||||
baseband::run_image(portapack::spi_flash::image_tag_mic_tx);
|
||||
audio::output::stop();
|
||||
audio::input::start(ak4951_alc_and_wm8731_boost_GUI); // When detected AK4951 => set up ALC mode; when detected WM8731 => set up mic_boost ON/OFF.
|
||||
audio::input::start(ak4951_alc_and_wm8731_boost_GUI, mic_to_HP_enabled); // set up ALC mode (AK4951) or set up mic_boost ON/OFF (WM8731). and the check box "Hear Mic"
|
||||
portapack::pin_i2s0_rx_sda.mode(3);
|
||||
configure_baseband();
|
||||
}
|
||||
}
|
||||
|
||||
void MicTXView::set_ptt_visibility(bool v) {
|
||||
tx_button.hidden(!v);
|
||||
void MicTXView::set_rxbw_options(void) {
|
||||
using option_t = std::pair<std::string, int32_t>;
|
||||
using options_t = std::vector<option_t>;
|
||||
options_t rxbw; // Aux structure to change dynamically field_rxbw contents
|
||||
|
||||
switch (mic_mod_index) {
|
||||
case MIC_MOD_NFM:
|
||||
freqman_set_bandwidth_option(NFM_MODULATION, field_rxbw); // restore dynamic field_rxbw value with NFM options from freqman_db.cpp
|
||||
field_rxbw.set_by_value(receiver_model.nbfm_configuration());
|
||||
break;
|
||||
case MIC_MOD_WFM:
|
||||
freqman_set_bandwidth_option(WFM_MODULATION, field_rxbw); // restore dynamic field_rxbw value with WFM options from freqman_db.cpp
|
||||
field_rxbw.set_by_value(receiver_model.wfm_configuration());
|
||||
break;
|
||||
case MIC_MOD_AM:
|
||||
rxbw.emplace_back("DSB 9k", 0); // we offer in AM DSB two audio BW 9k / 6k.
|
||||
rxbw.emplace_back("DSB 6k", 1);
|
||||
field_rxbw.set_options(rxbw); // store that aux GUI option to the field_rxbw.
|
||||
break;
|
||||
case MIC_MOD_DSB:
|
||||
rxbw.emplace_back("USB+3k", 0); // added dynamically two options (index 0,1) to that DSB-SC case to the field_rxbw value.
|
||||
rxbw.emplace_back("LSB-3k", 1);
|
||||
field_rxbw.set_options(rxbw); // store that aux GUI option to the field_rxbw.
|
||||
break;
|
||||
case MIC_MOD_USB:
|
||||
rxbw.emplace_back("USB+3k", 0); // locked a fixed option, to display it.
|
||||
field_rxbw.set_options(rxbw); // store that aux GUI option to the field_rxbw.
|
||||
break;
|
||||
case MIC_MOD_LSB:
|
||||
rxbw.emplace_back("LSB-3k", 0); // locked a fixed option, to display it.
|
||||
field_rxbw.set_options(rxbw); // store that aux GUI option to the field_rxbw.
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void MicTXView::set_rxbw_defaults(bool use_app_settings) {
|
||||
if (use_app_settings) {
|
||||
field_bw.set_value(transmitter_model.channel_bandwidth() / 1000);
|
||||
field_rxbw.set_by_value(rxbw_index);
|
||||
} else if (mic_mod_index == MIC_MOD_NFM) {
|
||||
field_bw.set_value(10); // NFM TX bw 10k, RX bw 16k (2) default
|
||||
field_rxbw.set_by_value(2);
|
||||
} else if (mic_mod_index == MIC_MOD_WFM) {
|
||||
field_bw.set_value(75); // WFM TX bw 75K, RX bw 200k (0) default
|
||||
field_rxbw.set_by_value(0);
|
||||
}
|
||||
// field_bw is hidden in other modulation cases
|
||||
}
|
||||
|
||||
void MicTXView::update_receiver_rxbw(void) {
|
||||
// In Previous fw versions, that nbfm_configuration(n) was done in any mode (FM/AM/SSB/DSB)...strictly speaking only need it in (NFM/FM)
|
||||
// In AM TX mode, we will allow both independent RX audio BW : AM 9K (9K00AE3 / AM 6K (6K00AE3). (In AM option v can be 0 (9k), 1 (6k)
|
||||
// In DSB-SC TX mode, we will allow both independent RX SSB demodulation (USB / LSB side band). in that submenu, v is 0 (SSB1 USB) or 1 (SSB2 LSB)
|
||||
switch (mic_mod_index) {
|
||||
case MIC_MOD_NFM:
|
||||
receiver_model.set_nbfm_configuration(rxbw_index); // we are in NFM/FM case, we need to select proper NFM/FM RX channel filter, NFM BW 8K5(0), NFM BW 11K(1), FM BW 16K (2)
|
||||
break;
|
||||
case MIC_MOD_WFM:
|
||||
receiver_model.set_wfm_configuration(rxbw_index); // we are in WFM case, we need to select proper WFB RX BW filter, WFM BW 200K(0), WFM BW 180K(1), WFM BW 40K(2)
|
||||
break;
|
||||
case MIC_MOD_AM:
|
||||
receiver_model.set_am_configuration(rxbw_index); // we are in AM TX mode, we need to select proper AM full path config AM-9K filter. 0+0 =>AM-9K(0), 0+1=1 =>AM-6K(1),
|
||||
break;
|
||||
case MIC_MOD_USB:
|
||||
case MIC_MOD_LSB:
|
||||
break; // change can't happen in these modes because there's only one BW choice
|
||||
case MIC_MOD_DSB:
|
||||
receiver_model.set_am_configuration(rxbw_index + 2); // we are in DSB-SC TX mode, we need to select proper SSB filter. 0+2 =>usb(2), 1+2=3 =>lsb(3),
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
MicTXView::MicTXView(
|
||||
@@ -199,400 +309,260 @@ MicTXView::MicTXView(
|
||||
|
||||
baseband::run_image(portapack::spi_flash::image_tag_mic_tx);
|
||||
|
||||
if (audio::debug::codec_name() == "WM8731") {
|
||||
add_children({&labels_WM8731, // we have audio codec WM8731, same MIC menu as original.
|
||||
&vumeter,
|
||||
&options_gain, // MIC GAIN float factor on the GUI.
|
||||
&options_wm8731_boost_mode,
|
||||
// &check_va,
|
||||
&field_va,
|
||||
&field_va_level,
|
||||
&field_va_attack,
|
||||
&field_va_decay,
|
||||
&field_bw,
|
||||
&tx_view, // it already integrates previous rfgain, rfamp.
|
||||
&options_mode,
|
||||
&field_frequency,
|
||||
&options_tone_key,
|
||||
&check_rogerbeep,
|
||||
&check_common_freq_tx_rx, // added to handle common or separate freq- TX/RX
|
||||
&check_rxactive,
|
||||
&field_volume,
|
||||
&field_rxbw,
|
||||
&field_squelch,
|
||||
&field_rxfrequency,
|
||||
&field_rxlna,
|
||||
&field_rxvga,
|
||||
&field_rxamp,
|
||||
&tx_button});
|
||||
bool wm = (audio::debug::codec_name() == "WM8731");
|
||||
add_children({&labels_both,
|
||||
wm ? &labels_WM8731 : &labels_AK4951, // enable ALC if AK4951
|
||||
&vumeter,
|
||||
&options_gain, // MIC GAIN float factor on the GUI.
|
||||
wm ? &options_wm8731_boost_mode : &options_ak4951_alc_mode,
|
||||
&check_va,
|
||||
&field_va_level,
|
||||
&field_va_attack,
|
||||
&field_va_decay,
|
||||
&field_bw,
|
||||
&tx_view, // it already integrates previous rfgain, rfamp.
|
||||
&options_mode,
|
||||
&field_frequency,
|
||||
&options_tone_key,
|
||||
&check_rogerbeep,
|
||||
&check_mic_to_HP, // check box to activate "hear mic"
|
||||
&check_common_freq_tx_rx, // added to handle common or separate freq- TX/RX
|
||||
&check_rxactive,
|
||||
&field_volume,
|
||||
&field_rxbw,
|
||||
&field_squelch,
|
||||
&field_rxfrequency,
|
||||
&field_rxlna,
|
||||
&field_rxvga,
|
||||
&field_rxamp,
|
||||
&tx_button,
|
||||
&tx_icon});
|
||||
|
||||
} else {
|
||||
add_children({&labels_AK4951, // we have audio codec AK4951, enable Automatic Level Control
|
||||
&vumeter,
|
||||
&options_gain,
|
||||
&options_ak4951_alc_mode,
|
||||
// &check_va,
|
||||
&field_va,
|
||||
&field_va_level,
|
||||
&field_va_attack,
|
||||
&field_va_decay,
|
||||
&field_bw,
|
||||
&tx_view, // it already integrates previous rfgain, rfamp.
|
||||
&options_mode,
|
||||
&field_frequency,
|
||||
&options_tone_key,
|
||||
&check_rogerbeep,
|
||||
&check_common_freq_tx_rx, // added to handle common or separate freq- TX/RX
|
||||
&check_rxactive,
|
||||
&field_volume,
|
||||
&field_rxbw,
|
||||
&field_squelch,
|
||||
&field_rxfrequency,
|
||||
&field_rxlna,
|
||||
&field_rxvga,
|
||||
&field_rxamp,
|
||||
&tx_button});
|
||||
}
|
||||
set_rxbw_options();
|
||||
set_rxbw_defaults(settings_.loaded());
|
||||
|
||||
tone_keys_populate(options_tone_key);
|
||||
options_tone_key.set_selected_index(tone_key_index);
|
||||
options_tone_key.on_change = [this](size_t i, int32_t) {
|
||||
tone_key_index = i;
|
||||
};
|
||||
options_tone_key.set_selected_index(0);
|
||||
|
||||
check_rogerbeep.set_value(rogerbeep_enabled);
|
||||
check_rogerbeep.on_select = [this](Checkbox&, bool v) {
|
||||
rogerbeep_enabled = v;
|
||||
};
|
||||
|
||||
field_rxlna.set_value(receiver_model.lna());
|
||||
field_rxlna.on_change = [this](int32_t v) {
|
||||
receiver_model.set_lna(v);
|
||||
};
|
||||
|
||||
field_rxvga.set_value(receiver_model.vga());
|
||||
field_rxvga.on_change = [this](int32_t v) {
|
||||
receiver_model.set_vga(v);
|
||||
};
|
||||
|
||||
field_rxamp.set_value(receiver_model.rf_amp());
|
||||
field_rxamp.on_change = [this](int32_t v) {
|
||||
receiver_model.set_rf_amp(v);
|
||||
};
|
||||
|
||||
options_gain.on_change = [this](size_t, int32_t v) {
|
||||
mic_gain = v / 10.0;
|
||||
mic_gain_x10 = v;
|
||||
configure_baseband();
|
||||
};
|
||||
options_gain.set_selected_index(1); // x1.0 preselected default.
|
||||
options_gain.set_by_value(mic_gain_x10); // x1.0 preselected default.
|
||||
|
||||
field_rxbw.on_change = [this](size_t, int32_t v) {
|
||||
rxbw_index = v;
|
||||
update_receiver_rxbw();
|
||||
};
|
||||
field_rxbw.set_by_value(rxbw_index);
|
||||
|
||||
field_squelch.set_value(receiver_model.squelch_level());
|
||||
field_squelch.on_change = [this](int32_t v) {
|
||||
receiver_model.set_squelch_level(v);
|
||||
};
|
||||
|
||||
if (audio::debug::codec_name() == "WM8731") {
|
||||
options_wm8731_boost_mode.on_change = [this](size_t, int8_t v) {
|
||||
switch (v) {
|
||||
case 0: // +12 dB’s respect reference level orig fw 1.5.x fw FM : when +20dB's boost ON) and shift bits (>>8),
|
||||
shift_bits_s16 = 6; // now mic-boost on (+20dBs) and shift bits (>>6), +20+12=32 dB’s (orig fw +20 dBs+ 0dBs)=> +12dB's respect ref.
|
||||
break;
|
||||
case 1: // +06 dB’s reference level, (when +20dB's boost ON)
|
||||
shift_bits_s16 = 7; // now mic-boost on (+20dBs) and shift bits (>>7), +20+06=26 dB’s (orig fw +20 dBs+ 0dBs) => +06dB's respect ref.
|
||||
break;
|
||||
case 2:
|
||||
shift_bits_s16 = 4; // +04 dB’s respect ref level, (when +20dB's boost OFF)
|
||||
break; // now mic-boost off (+00dBs) shift bits (4) (+0+24dB's)=24 dBs => +04dB's respect ref.
|
||||
case 3:
|
||||
shift_bits_s16 = 5; // -02 dB’s respect ref level, (when +20dB's boost OFF)
|
||||
break; // now mic-boost off (+00dBs) shift bits (5) (+0+18dB's)=18 dBs => -02dB's respect ref.
|
||||
case 4:
|
||||
shift_bits_s16 = 6; // -08 dB’s respect ref level, (when +20dB's boost OFF)
|
||||
break; // now mic-boost off (+00dBs) shift bits (6) (+0+12dB's)=12 dBs => -08dB's respect ref.
|
||||
}
|
||||
ak4951_alc_and_wm8731_boost_GUI = v; // 0..4, WM8731_boost dB's options, (combination boost on/off, and effective gain in captured data >>x)
|
||||
audio::input::start(ak4951_alc_and_wm8731_boost_GUI); // Detected (WM8731), set up the proper wm_boost on/off, 0..4 (0,1) boost_on, (2,3,4) boost_off
|
||||
configure_baseband(); // to update in real time, sending msg, var-parameters >>shift_bits FM msg, to audio_tx from M0 to M4 Proc -
|
||||
ak4951_alc_and_wm8731_boost_GUI = v; // 0..4, WM8731_boost dB's options, (combination boost on/off, and effective gain in captured data >>x)
|
||||
audio::input::start(ak4951_alc_and_wm8731_boost_GUI, mic_to_HP_enabled); // Detected (WM8731), set up the proper wm_boost on/off, 0..4 (0,1) boost_on, (2,3,4) boost_off,and the check box "Hear Mic"
|
||||
configure_baseband(); // to update in real time, sending msg, var-parameters >>shift_bits FM msg, to audio_tx from M0 to M4 Proc -
|
||||
};
|
||||
options_wm8731_boost_mode.set_selected_index(3); // preset GUI index 3 as default WM -> -02 dB's.
|
||||
if (!settings_.loaded()) {
|
||||
ak4951_alc_and_wm8731_boost_GUI = 3; // preset GUI index 3 as default WM -> -02 dB's
|
||||
}
|
||||
options_wm8731_boost_mode.set_selected_index(ak4951_alc_and_wm8731_boost_GUI);
|
||||
} else {
|
||||
shift_bits_s16 = 8; // Initialized default fixed >>8_FM for FM tx mod, shift audio data for AK4951, using top 8 bits s16 data (>>8)
|
||||
options_ak4951_alc_mode.on_change = [this](size_t, int8_t v) {
|
||||
ak4951_alc_and_wm8731_boost_GUI = v; // 0..11, AK4951 Mic -Automatic volume Level Control options,
|
||||
audio::input::start(ak4951_alc_and_wm8731_boost_GUI); // Detected (AK4951) ==> Set up proper ALC mode from 0..11 options
|
||||
configure_baseband(); // sending fixed >>8_FM, var-parameters msg, to audiotx from this M0 to M4 process.
|
||||
ak4951_alc_and_wm8731_boost_GUI = v; // 0..11, AK4951 Mic -Automatic volume Level Control options,
|
||||
audio::input::start(ak4951_alc_and_wm8731_boost_GUI, mic_to_HP_enabled); // Detected (AK4951) ==> Set up proper ALC mode from 0..11 options, and the check box "Hear Mic"
|
||||
configure_baseband(); // sending fixed >>8_FM, var-parameters msg, to audiotx from this M0 to M4 process.
|
||||
};
|
||||
if (!settings_.loaded())
|
||||
ak4951_alc_and_wm8731_boost_GUI = 0;
|
||||
options_ak4951_alc_mode.set_selected_index(ak4951_alc_and_wm8731_boost_GUI);
|
||||
}
|
||||
|
||||
// options_ak4951_alc_mode.set_selected_index(0);
|
||||
|
||||
// WARNING: transmitter_model.set_target_frequency() and receiver_model.set_target_frequency() both update the same tuning freq, but one has an offset!
|
||||
tx_frequency = transmitter_model.target_frequency();
|
||||
field_frequency.set_value(transmitter_model.target_frequency());
|
||||
field_frequency.set_step(receiver_model.frequency_step());
|
||||
field_frequency.on_change = [this](rf::Frequency f) {
|
||||
tx_frequency = f;
|
||||
if (!rx_enabled) { // not activated receiver. just update freq TX
|
||||
if (!rx_enabled)
|
||||
transmitter_model.set_target_frequency(f);
|
||||
} else { // activated receiver.
|
||||
if (bool_same_F_tx_rx_enabled) // user selected common freq- TX = RX
|
||||
receiver_model.set_target_frequency(f); // Update common freq also for RX
|
||||
}
|
||||
else if (bool_same_F_tx_rx_enabled)
|
||||
receiver_model.set_target_frequency(f);
|
||||
// else tuning freq will be updated when rx is enabled, transmitting starts, or when rx_frequency is changed (if rx_enabled)
|
||||
};
|
||||
field_frequency.on_edit = [this, &nav]() {
|
||||
focused_ui = 0;
|
||||
// TODO: Provide separate modal method/scheme?
|
||||
auto new_view = nav.push<FrequencyKeypadView>(tx_frequency);
|
||||
new_view->on_changed = [this](rf::Frequency f) {
|
||||
tx_frequency = f;
|
||||
if (!rx_enabled) {
|
||||
transmitter_model.set_target_frequency(f);
|
||||
} else {
|
||||
if (bool_same_F_tx_rx_enabled)
|
||||
receiver_model.set_target_frequency(f); // Update freq also for RX
|
||||
}
|
||||
this->field_frequency.set_value(f);
|
||||
set_dirty();
|
||||
};
|
||||
};
|
||||
field_frequency.set_value(tx_frequency);
|
||||
|
||||
field_bw.on_change = [this](uint32_t v) {
|
||||
transmitter_model.set_channel_bandwidth(v * 1000);
|
||||
};
|
||||
field_bw.set_value(10); // pre-default first time, TX deviation FM for NFM / FM
|
||||
// TODO: would be nice if frequency step was configurable in this app
|
||||
field_frequency.set_step(receiver_model.frequency_step());
|
||||
|
||||
// now, no need direct update, field_rfgain, field_rfamp (it is done in ui_transmitter.cpp)
|
||||
|
||||
options_mode.on_change = [this](size_t, int32_t v) { // { "NFM/FM", 0 }, { " WFM ", 1 }, { "AM", 2 }, { "USB", 3 }, { "LSB", 4 }, { "DSB", 5 }
|
||||
enable_am = false;
|
||||
enable_usb = false;
|
||||
enable_lsb = false;
|
||||
enable_dsb = false;
|
||||
enable_wfm = false;
|
||||
|
||||
using option_t = std::pair<std::string, int32_t>;
|
||||
using options_t = std::vector<option_t>;
|
||||
options_t rxbw; // Aux structure to change dynamically field_rxbw contents,
|
||||
|
||||
switch (v) {
|
||||
case 0: //{ "FM", 0 }
|
||||
enable_am = false;
|
||||
enable_usb = false;
|
||||
enable_lsb = false;
|
||||
enable_dsb = false;
|
||||
field_bw.set_value(10); // pre-default deviation FM for WFM
|
||||
// field_bw.set_value(transmitter_model.channel_bandwidth() / 1000);
|
||||
// if (rx_enabled)
|
||||
rxaudio(rx_enabled); // Update now if we have RX audio on
|
||||
options_tone_key.hidden(0); // we are in FM mode, we should have active the Key-tones & CTCSS option.
|
||||
|
||||
freqman_set_bandwidth_option(NFM_MODULATION, field_rxbw); // restore dynamic field_rxbw value with NFM options from freqman_db.cpp
|
||||
field_rxbw.set_by_value(2); // // bw 16k (2) default
|
||||
field_rxbw.hidden(0); // we are in FM mode, we need to allow the user set up of the RX NFM BW selection (8K5, 11K, 16K)
|
||||
field_bw.hidden(0); // we are in FM mode, we need to allow FM deviation parameter, in non FM mode.
|
||||
break;
|
||||
case 1: //{ "WFM", 1 }
|
||||
enable_am = false;
|
||||
enable_usb = false;
|
||||
enable_lsb = false;
|
||||
enable_dsb = false;
|
||||
enable_wfm = true;
|
||||
field_bw.set_value(75); // pre-default deviation FM for WFM
|
||||
// field_bw.set_value(transmitter_model.channel_bandwidth() / 1000);
|
||||
// if (rx_enabled)
|
||||
rxaudio(rx_enabled); // Update now if we have RX audio on
|
||||
options_tone_key.hidden(0); // we are in WFM mode, we should have active the Key-tones & CTCSS option.
|
||||
|
||||
freqman_set_bandwidth_option(WFM_MODULATION, field_rxbw); // restore dynamic field_rxbw value with WFM options from freqman_db.cpp
|
||||
field_rxbw.set_by_value(0); // bw 200k (0) default
|
||||
field_rxbw.hidden(0); // we are in WFM mode, we need to show to the user the selected BW WFM filter.
|
||||
field_bw.hidden(0); // we are in WFM mode, we need to allow WFM deviation parameter, in non FM mode.
|
||||
break;
|
||||
case 2: //{ "AM", 2 }
|
||||
enable_am = true;
|
||||
rxaudio(rx_enabled); // Update now if we have RX audio on
|
||||
options_tone_key.set_selected_index(0); // we are NOT in FM mode, we reset the possible previous key-tones &CTCSS selection.
|
||||
set_dirty(); // Refresh display
|
||||
options_tone_key.hidden(1); // we hide that Key-tones & CTCSS input selecction, (no meaning in AM/DSB/SSB).
|
||||
|
||||
rxbw.emplace_back("DSB 9k", 0); // we offer in AM DSB two audio BW 9k / 6k.
|
||||
rxbw.emplace_back("DSB 6k", 1);
|
||||
field_rxbw.set_options(rxbw); // store that aux GUI option to the field_rxbw.
|
||||
|
||||
field_rxbw.hidden(0); // we show fixed RX AM BW 6Khz
|
||||
field_bw.hidden(1); // we hide the FM TX deviation parameter, in non FM mode.
|
||||
check_rogerbeep.hidden(0); // make visible again the "rogerbeep" selection.
|
||||
break;
|
||||
case 3: //{ "USB", 3 }
|
||||
enable_usb = true;
|
||||
rxaudio(rx_enabled); // Update now if we have RX audio on
|
||||
check_rogerbeep.set_value(false); // reset the possible activation of roger beep, because it is not compatible with SSB, by now.
|
||||
check_rogerbeep.hidden(1); // hide that roger beep selection.
|
||||
|
||||
rxbw.emplace_back("USB+3k", 0); // locked a fixed option, to display it.
|
||||
field_rxbw.set_options(rxbw); // store that aux GUI option to the field_rxbw.
|
||||
|
||||
set_dirty(); // Refresh display
|
||||
break;
|
||||
case 4: //{ "LSB", 4 }
|
||||
enable_lsb = true;
|
||||
rxaudio(rx_enabled); // Update now if we have RX audio on
|
||||
check_rogerbeep.set_value(false); // reset the possible activation of roger beep, because it is not compatible with SSB, by now.
|
||||
check_rogerbeep.hidden(1); // hide that roger beep selection.
|
||||
|
||||
rxbw.emplace_back("LSB-3k", 0); // locked a fixed option, to display it.
|
||||
field_rxbw.set_options(rxbw); // store that aux GUI option to the field_rxbw.
|
||||
|
||||
set_dirty(); // Refresh display
|
||||
break;
|
||||
case 5: //{ "DSB-SC", 5 }
|
||||
enable_dsb = true;
|
||||
rxaudio(rx_enabled); // Update now if we have RX audio on
|
||||
check_rogerbeep.hidden(0); // make visible again the "rogerbeep" selection.
|
||||
|
||||
rxbw.emplace_back("USB+3k", 0); // added dynamically two options (index 0,1) to that DSB-SC case to the field_rxbw value.
|
||||
rxbw.emplace_back("LSB-3k", 1);
|
||||
|
||||
field_rxbw.set_options(rxbw); // store that aux GUI option to the field_rxbw.
|
||||
|
||||
break;
|
||||
}
|
||||
// configure_baseband();
|
||||
};
|
||||
|
||||
/*
|
||||
check_va.on_select = [this](Checkbox&, bool v) {
|
||||
va_enabled = v;
|
||||
text_ptt.hidden(v); //hide / show PTT text
|
||||
check_rxactive.hidden(v); //hide / show the RX AUDIO
|
||||
set_dirty(); //Refresh display
|
||||
};
|
||||
*/
|
||||
field_va.set_selected_index(1);
|
||||
field_va.on_change = [this](size_t, int32_t v) {
|
||||
switch (v) {
|
||||
case 0:
|
||||
va_enabled = 0;
|
||||
this->set_ptt_visibility(0);
|
||||
check_rxactive.hidden(0);
|
||||
ptt_enabled = 0;
|
||||
break;
|
||||
case 1:
|
||||
va_enabled = 0;
|
||||
this->set_ptt_visibility(1);
|
||||
check_rxactive.hidden(0);
|
||||
ptt_enabled = 1;
|
||||
break;
|
||||
case 2:
|
||||
if (!rx_enabled) {
|
||||
va_enabled = 1;
|
||||
this->set_ptt_visibility(0);
|
||||
check_rxactive.hidden(1);
|
||||
ptt_enabled = 0;
|
||||
} else {
|
||||
field_va.set_selected_index(1);
|
||||
}
|
||||
break;
|
||||
}
|
||||
set_dirty();
|
||||
};
|
||||
|
||||
check_rogerbeep.on_select = [this](Checkbox&, bool v) {
|
||||
rogerbeep_enabled = v;
|
||||
};
|
||||
|
||||
check_common_freq_tx_rx.on_select = [this](Checkbox&, bool v) {
|
||||
bool_same_F_tx_rx_enabled = v;
|
||||
field_rxfrequency.hidden(v); // Hide or show separated freq RX field. (When no hide user can enter down indep. freq for RX)
|
||||
set_dirty(); // Refresh GUI interface
|
||||
receiver_model.set_target_frequency(v ? tx_frequency : rx_frequency); // To go to the proper tuned freq. when toggling it
|
||||
};
|
||||
|
||||
field_va_level.on_change = [this](int32_t v) {
|
||||
va_level = v;
|
||||
vumeter.set_mark(v);
|
||||
};
|
||||
field_va_level.set_value(40);
|
||||
|
||||
field_va_attack.on_change = [this](int32_t v) {
|
||||
attack_ms = v;
|
||||
};
|
||||
field_va_attack.set_value(500);
|
||||
|
||||
field_va_decay.on_change = [this](int32_t v) {
|
||||
decay_ms = v;
|
||||
};
|
||||
field_va_decay.set_value(1000);
|
||||
|
||||
check_rxactive.on_select = [this](Checkbox&, bool v) {
|
||||
// vumeter.set_value(0); //Start with a clean vumeter
|
||||
rx_enabled = v;
|
||||
// check_va.hidden(v); //Hide or show voice activation
|
||||
rxaudio(v); // Activate-Deactivate audio rx accordingly
|
||||
set_dirty(); // Refresh interface
|
||||
};
|
||||
|
||||
field_rxbw.on_change = [this](size_t, int32_t v) {
|
||||
if (!(enable_am || enable_usb || enable_lsb || enable_dsb || enable_wfm)) {
|
||||
// In Previous fw versions, that nbfm_configuration(n) was done in any mode (FM/AM/SSB/DSB)...strictly speaking only need it in (NFM/FM)
|
||||
receiver_model.set_nbfm_configuration(v); // we are in NFM/FM case, we need to select proper NFM/FM RX channel filter, NFM BW 8K5(0), NFM BW 11K(1), FM BW 16K (2)
|
||||
} else { // we are not in NFM/FM mode. (we could be in any of the rest : AM /USB/LSB/DSB-SC)
|
||||
if (enable_am) { // we are in AM TX mode, we will allow both independent RX audio BW : AM 9K (9K00AE3 / AM 6K (6K00AE3). (In AM option v can be 0 (9k), 1 (6k)
|
||||
receiver_model.set_am_configuration(v); // we are in AM TX mode, we need to select proper AM full path config AM-9K filter. 0+0 =>AM-9K(0), 0+1=1 =>AM-6K(1),
|
||||
}
|
||||
if (enable_dsb) { // we are in DSB-SC in TX mode, we will allow both independent RX SSB demodulation (USB / LSB side band). in that submenu, v is 0 (SSB1 USB) or 1 (SSB2 LSB)
|
||||
receiver_model.set_am_configuration(v + 2); // we are in DSB-SC TX mode, we need to select proper SSB filter. 0+2 =>usb(2), 1+2=3 =>lsb(3),
|
||||
}
|
||||
if (enable_wfm) {
|
||||
receiver_model.set_wfm_configuration(v); // we are in WFM case, we need to select proper WFB RX BW filter, WFM BW 200K(0), WFM BW 180K(1), WFM BW 40K(2)
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
field_squelch.on_change = [this](int32_t v) {
|
||||
receiver_model.set_squelch_level(100 - v);
|
||||
};
|
||||
field_squelch.set_value(0);
|
||||
receiver_model.set_squelch_level(0);
|
||||
|
||||
rx_frequency = receiver_model.target_frequency();
|
||||
// WARNING: transmitter_model.set_target_frequency() and receiver_model.set_target_frequency() both update the same tuning freq, but one has an offset!
|
||||
field_rxfrequency.set_value(rx_frequency);
|
||||
field_rxfrequency.set_step(receiver_model.frequency_step());
|
||||
field_rxfrequency.on_change = [this](rf::Frequency f) { // available when field rxfrequency not hidden => user selected separated freq RX/TX-
|
||||
rx_frequency = f;
|
||||
if (rx_enabled)
|
||||
receiver_model.set_target_frequency(f);
|
||||
receiver_model.set_target_frequency(rx_frequency);
|
||||
};
|
||||
field_rxfrequency.on_edit = [this, &nav]() { // available when field rxfrequency not hidden => user selected separated freq RX/TX-
|
||||
focused_ui = 1;
|
||||
// TODO: Provide separate modal method/scheme?
|
||||
auto new_view = nav.push<FrequencyKeypadView>(rx_frequency);
|
||||
new_view->on_changed = [this](rf::Frequency f) {
|
||||
rx_frequency = f;
|
||||
if (rx_enabled)
|
||||
receiver_model.set_target_frequency(f);
|
||||
this->field_rxfrequency.set_value(f);
|
||||
set_dirty();
|
||||
};
|
||||
};
|
||||
|
||||
rx_lna = receiver_model.lna();
|
||||
field_rxlna.on_change = [this](int32_t v) {
|
||||
rx_lna = v;
|
||||
if (rx_enabled)
|
||||
receiver_model.set_lna(v);
|
||||
};
|
||||
field_rxlna.set_value(rx_lna);
|
||||
// TODO: would be nice if frequency step was configurable in this app
|
||||
field_rxfrequency.set_step(receiver_model.frequency_step());
|
||||
|
||||
rx_vga = receiver_model.vga();
|
||||
field_rxvga.on_change = [this](int32_t v) {
|
||||
rx_vga = v;
|
||||
if (rx_enabled)
|
||||
receiver_model.set_vga(v);
|
||||
check_common_freq_tx_rx.on_select = [this](Checkbox&, bool v) {
|
||||
bool_same_F_tx_rx_enabled = v;
|
||||
field_rxfrequency.hidden(v);
|
||||
set_dirty();
|
||||
receiver_model.set_target_frequency(bool_same_F_tx_rx_enabled ? tx_frequency : rx_frequency); // To go to the proper tuned freq. when toggling it
|
||||
};
|
||||
field_rxvga.set_value(rx_vga);
|
||||
check_common_freq_tx_rx.set_value(bool_same_F_tx_rx_enabled);
|
||||
|
||||
rx_amp = receiver_model.rf_amp();
|
||||
field_rxamp.on_change = [this](int32_t v) {
|
||||
rx_amp = v;
|
||||
if (rx_enabled)
|
||||
receiver_model.set_rf_amp(rx_amp);
|
||||
field_bw.on_change = [this](uint32_t v) {
|
||||
transmitter_model.set_channel_bandwidth(v * 1000);
|
||||
};
|
||||
field_rxamp.set_value(rx_amp);
|
||||
field_bw.set_value(transmitter_model.channel_bandwidth() / 1000); // pre-default first time, TX deviation FM for NFM / FM
|
||||
|
||||
// now, no need direct update, field_rfgain, field_rfamp (it is done in ui_transmitter.cpp)
|
||||
|
||||
options_mode.on_change = [this](size_t, int32_t v) {
|
||||
mic_mod_index = v;
|
||||
|
||||
// update bw & tone key visibility - only visible in NFM/WFM modes
|
||||
if ((mic_mod_index == MIC_MOD_NFM) || (mic_mod_index == MIC_MOD_WFM)) {
|
||||
field_bw.hidden(false);
|
||||
options_tone_key.hidden(false);
|
||||
} else {
|
||||
field_bw.hidden(true);
|
||||
options_tone_key.set_selected_index(0);
|
||||
options_tone_key.hidden(true);
|
||||
}
|
||||
|
||||
// update rogerbeep visibility - disable in USB/LSB modes
|
||||
if ((mic_mod_index == MIC_MOD_USB) || (mic_mod_index == MIC_MOD_LSB)) {
|
||||
check_rogerbeep.set_value(false);
|
||||
check_rogerbeep.hidden(true);
|
||||
} else {
|
||||
check_rogerbeep.hidden(false);
|
||||
}
|
||||
|
||||
// update squelch visibility - only visible in NFM mode
|
||||
field_squelch.hidden(mic_mod_index != MIC_MOD_NFM);
|
||||
|
||||
// update bandwidth
|
||||
set_rxbw_options();
|
||||
set_rxbw_defaults(false);
|
||||
field_rxbw.hidden(false);
|
||||
set_dirty(); // Refresh display
|
||||
|
||||
rxaudio(rx_enabled); // Update now if we have RX audio on
|
||||
// configure_baseband();
|
||||
};
|
||||
options_mode.set_selected_index(mic_mod_index);
|
||||
|
||||
check_mic_to_HP.on_select = [this](Checkbox&, bool v) {
|
||||
mic_to_HP_enabled = v;
|
||||
if (mic_to_HP_enabled) { // When user click to "hear mic to HP", we will select the higher acoustic sound Option MODE ALC or BOOST-
|
||||
audio::input::loopback_mic_to_hp_enable();
|
||||
if (audio::debug::codec_name() == "WM8731") {
|
||||
options_wm8731_boost_mode.set_selected_index(0); // In WM we always go to Boost +12 dB’s respect reference level
|
||||
} else if (ak4951_alc_and_wm8731_boost_GUI == 0) // In AK we are changing only that ALC index =0, because in that option, there is no sound.
|
||||
options_ak4951_alc_mode.set_selected_index(1); // alc_mode =0 , means no ALC,no DIGITAL filter block (by passed), and that mode has no loopback mode.
|
||||
} else {
|
||||
audio::input::loopback_mic_to_hp_disable();
|
||||
}
|
||||
};
|
||||
check_mic_to_HP.set_value(mic_to_HP_enabled);
|
||||
|
||||
check_rxactive.on_select = [this](Checkbox&, bool v) {
|
||||
// vumeter.set_value(0); //Start with a clean vumeter
|
||||
rx_enabled = v;
|
||||
check_mic_to_HP.hidden(rx_enabled); // Toggle Hide / show "Hear Mic" checkbox depending if we activate or not the receiver. (if RX on => no visible "Mic Hear" option)
|
||||
if ((rx_enabled) && (transmitting))
|
||||
check_mic_to_HP.set_value(transmitting); // Once we activate the "Rx audio" in reception time we disable "Hear Mic", but we allow it again in TX time.
|
||||
|
||||
if (rx_enabled)
|
||||
check_va.set_value(false); // Disallow voice activation during RX audio (for now) - Future TODO: Should allow VOX during RX audio
|
||||
|
||||
rxaudio(v); // Activate-Deactivate audio RX (receiver) accordingly
|
||||
set_dirty(); // Refresh interface
|
||||
};
|
||||
check_rxactive.set_value(rx_enabled);
|
||||
|
||||
tx_button.on_select = [this](Button&) {
|
||||
if (ptt_enabled && !transmitting) {
|
||||
if (!transmitting) {
|
||||
set_tx(true);
|
||||
}
|
||||
};
|
||||
|
||||
tx_button.on_touch_release = [this](Button&) {
|
||||
if (button_touch) {
|
||||
button_touch = false;
|
||||
set_tx(false);
|
||||
}
|
||||
button_touch = false;
|
||||
};
|
||||
|
||||
tx_button.on_touch_press = [this](Button&) {
|
||||
if (!transmitting) {
|
||||
button_touch = true;
|
||||
}
|
||||
button_touch = true;
|
||||
};
|
||||
|
||||
field_va_level.on_change = [this](int32_t v) {
|
||||
va_level = v;
|
||||
vumeter.set_mark(v);
|
||||
};
|
||||
field_va_level.set_value(va_level);
|
||||
|
||||
field_va_attack.set_value(attack_ms);
|
||||
field_va_attack.on_change = [this](int32_t v) {
|
||||
attack_ms = v;
|
||||
};
|
||||
|
||||
field_va_decay.set_value(decay_ms);
|
||||
field_va_decay.on_change = [this](int32_t v) {
|
||||
decay_ms = v;
|
||||
};
|
||||
|
||||
check_va.on_select = [this](Checkbox&, bool v) {
|
||||
va_enabled = v;
|
||||
if (va_enabled)
|
||||
check_rxactive.set_value(false); // Disallow RX-audio in VOX mode (for now) - Future TODO: Should allow VOX during RX audio
|
||||
};
|
||||
check_va.set_value(va_enabled);
|
||||
|
||||
// These shouldn't be necessary, but because
|
||||
// this app uses both transmitter_model and directly
|
||||
// configures the baseband, these end up being required.
|
||||
@@ -602,7 +572,12 @@ MicTXView::MicTXView(
|
||||
set_tx(false);
|
||||
|
||||
audio::set_rate(audio::Rate::Hz_24000);
|
||||
audio::input::start(ak4951_alc_and_wm8731_boost_GUI); // When detected AK4951 => set up ALC mode; when detected WM8731 => set up mic_boost ON/OFF.
|
||||
audio::input::start(ak4951_alc_and_wm8731_boost_GUI, mic_to_HP_enabled); // set up ALC mode (AK4951) or set up mic_boost ON/OFF (WM8731). and the check box "Hear Mic"
|
||||
|
||||
// Workaround for bad RX reception when app first started -- shouldn't be necessary:
|
||||
// Trigger receiver to update modulation.
|
||||
if (rx_enabled)
|
||||
receiver_model.set_squelch_level(receiver_model.squelch_level());
|
||||
}
|
||||
|
||||
MicTXView::MicTXView(
|
||||
@@ -611,16 +586,15 @@ MicTXView::MicTXView(
|
||||
: MicTXView(nav) {
|
||||
// Try to use the modulation/bandwidth from RX settings.
|
||||
// TODO: These concepts should be merged so there's only one.
|
||||
// TODO: enums/constants for these indexes.
|
||||
switch (override.mode) {
|
||||
case ReceiverModel::Mode::AMAudio:
|
||||
options_mode.set_selected_index(2);
|
||||
options_mode.set_selected_index(MIC_MOD_AM);
|
||||
break;
|
||||
case ReceiverModel::Mode::NarrowbandFMAudio:
|
||||
options_mode.set_selected_index(0);
|
||||
options_mode.set_selected_index(MIC_MOD_NFM);
|
||||
break;
|
||||
case ReceiverModel::Mode::WidebandFMAudio:
|
||||
options_mode.set_selected_index(1);
|
||||
options_mode.set_selected_index(MIC_MOD_WFM);
|
||||
break;
|
||||
|
||||
// Unsupported modulations.
|
||||
@@ -630,6 +604,8 @@ MicTXView::MicTXView(
|
||||
break;
|
||||
}
|
||||
|
||||
check_common_freq_tx_rx.set_value(true); // freq passed from other app is in tx_frequency, so set rx_frequency=tx_frequency
|
||||
|
||||
// TODO: bandwidth selection is tied too tightly to the UI
|
||||
// controls. It's not possible to set the bandwidth here without
|
||||
// refactoring. Also options_mode seems to have a category error.
|
||||
@@ -637,10 +613,12 @@ MicTXView::MicTXView(
|
||||
|
||||
MicTXView::~MicTXView() {
|
||||
audio::input::stop();
|
||||
transmitter_model.set_target_frequency(tx_frequency);
|
||||
transmitter_model.disable();
|
||||
if (rx_enabled) // Also turn off audio rx if enabled
|
||||
if (rx_enabled) { // Also turn off both (audio rx if enabled, and disable mic_loop to HP)
|
||||
rxaudio(false);
|
||||
audio::input::loopback_mic_to_hp_disable(); // Leave Mic audio off in the main menu (as original audio path, otherwise we had No audio in next "Audio App")
|
||||
}
|
||||
transmitter_model.set_target_frequency(tx_frequency); // Set tx_frequency here to be saved in app_settings (might not match rx_frequency)
|
||||
transmitter_model.disable();
|
||||
baseband::shutdown();
|
||||
}
|
||||
|
||||
|
||||
@@ -70,67 +70,85 @@ class MicTXView : public View {
|
||||
static constexpr uint32_t lcd_frame_duration = (256 * 1000UL) / 60; // 1 frame @ 60fps in ms .8 fixed point /60
|
||||
|
||||
void update_vumeter();
|
||||
bool tx_button_held();
|
||||
void do_timing();
|
||||
void set_tx(bool enable);
|
||||
// void on_target_frequency_changed(rf::Frequency f);
|
||||
void on_tx_progress(const bool done);
|
||||
void update_tx_icon();
|
||||
uint8_t shift_bits(void);
|
||||
void configure_baseband();
|
||||
|
||||
void set_rxbw_options(void);
|
||||
void set_rxbw_defaults(bool use_app_settings);
|
||||
void update_receiver_rxbw(void);
|
||||
void rxaudio(bool is_on);
|
||||
|
||||
void set_ptt_visibility(bool v);
|
||||
|
||||
RxRadioState rx_radio_state_{};
|
||||
TxRadioState tx_radio_state_{
|
||||
0 /* frequency */,
|
||||
1750000 /* bandwidth */,
|
||||
sampling_rate /* sampling rate */
|
||||
};
|
||||
app_settings::SettingsManager settings_{
|
||||
"tx_mic", app_settings::Mode::RX_TX,
|
||||
app_settings::Options::UseGlobalTargetFrequency};
|
||||
|
||||
bool transmitting{false};
|
||||
enum Mic_Modulation : uint32_t {
|
||||
MIC_MOD_NFM = 0,
|
||||
MIC_MOD_WFM = 1,
|
||||
MIC_MOD_AM = 2,
|
||||
MIC_MOD_USB = 3,
|
||||
MIC_MOD_LSB = 4,
|
||||
MIC_MOD_DSB = 5,
|
||||
};
|
||||
|
||||
// Settings
|
||||
uint32_t mic_mod_index{0};
|
||||
uint32_t rxbw_index{0};
|
||||
bool va_enabled{false};
|
||||
bool ptt_enabled{true};
|
||||
bool rogerbeep_enabled{false};
|
||||
bool mic_to_HP_enabled{false};
|
||||
bool bool_same_F_tx_rx_enabled{false};
|
||||
rf::Frequency rx_frequency{0};
|
||||
bool rx_enabled{false};
|
||||
uint32_t tone_key_index{};
|
||||
float mic_gain{1.0};
|
||||
uint32_t tone_key_index{0};
|
||||
uint32_t mic_gain_x10{1};
|
||||
uint8_t ak4951_alc_and_wm8731_boost_GUI{0};
|
||||
uint32_t va_level{40};
|
||||
uint32_t attack_ms{500};
|
||||
uint32_t decay_ms{1000};
|
||||
app_settings::SettingsManager settings_{
|
||||
"tx_mic",
|
||||
app_settings::Mode::RX_TX,
|
||||
app_settings::Options::UseGlobalTargetFrequency,
|
||||
{
|
||||
{"mic_mod_index"sv, &mic_mod_index},
|
||||
{"rxbw_index"sv, &rxbw_index},
|
||||
{"same_F_tx_rx"sv, &bool_same_F_tx_rx_enabled},
|
||||
{"mic_rx_frequency"sv, &rx_frequency},
|
||||
{"rx_enabled"sv, &rx_enabled},
|
||||
{"mic_gain_x10"sv, &mic_gain_x10},
|
||||
{"mic_to_HP"sv, &mic_to_HP_enabled},
|
||||
{"alc_and_boost"sv, &ak4951_alc_and_wm8731_boost_GUI},
|
||||
{"va_level"sv, &va_level},
|
||||
{"attack_ms"sv, &attack_ms},
|
||||
{"decay_ms"sv, &decay_ms},
|
||||
{"vox"sv, &va_enabled},
|
||||
{"rogerbeep"sv, &rogerbeep_enabled},
|
||||
{"tone_key_index"sv, &tone_key_index},
|
||||
}};
|
||||
|
||||
rf::Frequency tx_frequency{0};
|
||||
bool transmitting{false};
|
||||
uint32_t audio_level{0};
|
||||
uint32_t va_level{};
|
||||
uint32_t attack_ms{};
|
||||
uint32_t decay_ms{};
|
||||
uint32_t attack_timer{0};
|
||||
uint32_t decay_timer{0};
|
||||
int32_t tx_gain{47};
|
||||
bool rf_amp{false};
|
||||
int32_t rx_lna{32};
|
||||
int32_t rx_vga{32};
|
||||
bool rx_amp{false};
|
||||
rf::Frequency tx_frequency{0};
|
||||
rf::Frequency rx_frequency{0};
|
||||
int32_t focused_ui{2};
|
||||
bool button_touch{false};
|
||||
uint8_t shift_bits_s16{4}; // shift bits factor to the captured ADC S16 audio sample.
|
||||
|
||||
// AM TX Stuff
|
||||
// TODO: Some of this stuff is mutually exclusive. Need a better representation.
|
||||
bool enable_am{false};
|
||||
bool enable_dsb{false};
|
||||
bool enable_usb{false};
|
||||
bool enable_lsb{false};
|
||||
bool enable_wfm{false}; // added to distinguish in the FM mode, RX BW : NFM (8K5, 11K), FM (16K), WFM(200K)
|
||||
|
||||
Labels labels_WM8731{
|
||||
Labels labels_both{
|
||||
{{3 * 8, 1 * 8}, "MIC-GAIN:", Color::light_grey()},
|
||||
{{17 * 8, 1 * 8}, "Boost", Color::light_grey()},
|
||||
{{3 * 8, 3 * 8}, "F:", Color::light_grey()},
|
||||
{{15 * 8, 3 * 8}, "FM TXBW: kHz", Color::light_grey()}, // to be more symetric and consistent to the below FM RXBW
|
||||
{{18 * 8, (5 * 8)}, "Mode:", Color::light_grey()}, // now, no need to handle GAIN, Amp here It is handled by ui_transmitter.cpp
|
||||
{{3 * 8, 8 * 8}, "TX Activation:", Color::light_grey()}, // we delete { { 3 * 8, 5 * 8 }, "GAIN:", Color::light_grey() },
|
||||
{{4 * 8, 10 * 8}, "LVL:", Color::light_grey()}, // we delete { {11 * 8, 5 * 8 }, "Amp:", Color::light_grey() },
|
||||
{{12 * 8, 10 * 8}, "ATT:", Color::light_grey()},
|
||||
{{20 * 8, 10 * 8}, "DEC:", Color::light_grey()},
|
||||
@@ -143,25 +161,10 @@ class MicTXView : public View {
|
||||
{{5 * 8, (27 * 8) + 2}, "LNA:", Color::light_grey()},
|
||||
{{12 * 8, (27 * 8) + 2}, "VGA:", Color::light_grey()},
|
||||
{{19 * 8, (27 * 8) + 2}, "AMP:", Color::light_grey()}};
|
||||
Labels labels_WM8731{
|
||||
{{17 * 8, 1 * 8}, "Boost", Color::light_grey()}};
|
||||
Labels labels_AK4951{
|
||||
{{3 * 8, 1 * 8}, "MIC-GAIN:", Color::light_grey()},
|
||||
{{17 * 8, 1 * 8}, "ALC", Color::light_grey()},
|
||||
{{3 * 8, 3 * 8}, "F:", Color::light_grey()},
|
||||
{{15 * 8, 3 * 8}, "FM TXBW: kHz", Color::light_grey()},
|
||||
{{18 * 8, (5 * 8)}, "Mode:", Color::light_grey()}, // now, no need to handle GAIN, Amp here It is handled by ui_transmitter.cpp
|
||||
{{3 * 8, 8 * 8}, "TX Activation:", Color::light_grey()}, // we delete { { 3 * 8, 5 * 8 }, "GAIN:", Color::light_grey() },
|
||||
{{4 * 8, 10 * 8}, "LVL:", Color::light_grey()}, // we delete { {11 * 8, 5 * 8 }, "Amp:", Color::light_grey() },
|
||||
{{12 * 8, 10 * 8}, "ATT:", Color::light_grey()},
|
||||
{{20 * 8, 10 * 8}, "DEC:", Color::light_grey()},
|
||||
{{3 * 8, (13 * 8) - 5}, "TONE KEY:", Color::light_grey()},
|
||||
{{3 * 8, (18 * 8) - 1}, "======== Receiver ========", Color::green()},
|
||||
{{(5 * 8), (23 * 8) + 2}, "VOL:", Color::light_grey()},
|
||||
{{14 * 8, (23 * 8) + 2}, "RXBW:", Color::light_grey()}, // we remove the label "FM" because we will display all MOD types RX_BW.
|
||||
{{20 * 8, (25 * 8) + 2}, "SQ:", Color::light_grey()},
|
||||
{{5 * 8, (25 * 8) + 2}, "F_RX:", Color::light_grey()},
|
||||
{{5 * 8, (27 * 8) + 2}, "LNA:", Color::light_grey()},
|
||||
{{12 * 8, (27 * 8) + 2}, "VGA:", Color::light_grey()},
|
||||
{{19 * 8, (27 * 8) + 2}, "AMP:", Color::light_grey()}};
|
||||
{{17 * 8, 1 * 8}, "ALC", Color::light_grey()}};
|
||||
|
||||
VuMeter vumeter{
|
||||
{0 * 8, 1 * 8, 2 * 8, 33 * 8},
|
||||
@@ -224,28 +227,19 @@ class MicTXView : public View {
|
||||
{24 * 8, 5 * 8},
|
||||
6,
|
||||
{
|
||||
{"NFM/FM", 0},
|
||||
{" WFM ", 1},
|
||||
{" AM ", 2}, // in fact that TX mode = AM -DSB with carrier.
|
||||
{" USB ", 3},
|
||||
{" LSB ", 4},
|
||||
{"DSB-SC", 5} // We are TX Double Side AM Band with suppressed carrier, and allowing in RX both indep SSB lateral band (USB/LSB).
|
||||
{"NFM/FM", MIC_MOD_NFM},
|
||||
{" WFM ", MIC_MOD_WFM},
|
||||
{" AM ", MIC_MOD_AM}, // in fact that TX mode = AM -DSB with carrier.
|
||||
{" USB ", MIC_MOD_USB},
|
||||
{" LSB ", MIC_MOD_LSB},
|
||||
{"DSB-SC", MIC_MOD_DSB} // We are TX Double Side AM Band with suppressed carrier, and allowing in RX both indep SSB lateral band (USB/LSB).
|
||||
}};
|
||||
/*
|
||||
Checkbox check_va {
|
||||
{ 3 * 8, (10 * 8) - 4 },
|
||||
7,
|
||||
"Voice activation",
|
||||
false
|
||||
};
|
||||
*/
|
||||
|
||||
OptionsField field_va{
|
||||
{17 * 8, 8 * 8},
|
||||
4,
|
||||
{{" OFF", 0},
|
||||
{" PTT", 1},
|
||||
{"AUTO", 2}}};
|
||||
Checkbox check_va{
|
||||
{3 * 8, 8 * 7},
|
||||
10,
|
||||
"VOX enable",
|
||||
false};
|
||||
|
||||
NumberField field_va_level{
|
||||
{8 * 8, 10 * 8},
|
||||
@@ -277,6 +271,12 @@ class MicTXView : public View {
|
||||
"Roger beep",
|
||||
false};
|
||||
|
||||
Checkbox check_mic_to_HP{
|
||||
{18 * 8, (14 * 8) + 4},
|
||||
10,
|
||||
"Hear Mic",
|
||||
false};
|
||||
|
||||
Checkbox check_rxactive{
|
||||
{3 * 8, (21 * 8) - 7},
|
||||
8, // it was 18, but if it is string size should be 8
|
||||
@@ -286,7 +286,7 @@ class MicTXView : public View {
|
||||
Checkbox check_common_freq_tx_rx{
|
||||
{18 * 8, (21 * 8) - 7},
|
||||
8,
|
||||
"F TX=RX",
|
||||
"F RX=TX",
|
||||
false};
|
||||
|
||||
AudioVolumeField field_volume{
|
||||
@@ -340,9 +340,15 @@ class MicTXView : public View {
|
||||
|
||||
Button tx_button{
|
||||
{10 * 8, 30 * 8, 10 * 8, 5 * 8},
|
||||
"TX",
|
||||
"PTT TX",
|
||||
true};
|
||||
|
||||
Image tx_icon{
|
||||
{6 * 8, 31 * 8 + 4, 16, 16},
|
||||
&bitmap_icon_microphone,
|
||||
Color::black(),
|
||||
Color::black()};
|
||||
|
||||
MessageHandlerRegistration message_handler_lcd_sync{
|
||||
Message::ID::DisplayFrameSync,
|
||||
[this](const Message* const) {
|
||||
|
||||
@@ -481,10 +481,9 @@ ReconView::ReconView(NavigationView& nav)
|
||||
|
||||
button_remove.on_select = [this](ButtonWithEncoder&) {
|
||||
handle_remove_current_item();
|
||||
|
||||
// TODO: refresh UI.
|
||||
timer = 0;
|
||||
freq_lock = 0;
|
||||
recon_redraw();
|
||||
};
|
||||
|
||||
button_remove.on_change = [this]() {
|
||||
@@ -567,7 +566,7 @@ ReconView::ReconView(NavigationView& nav)
|
||||
};
|
||||
|
||||
button_restart.on_select = [this](Button&) {
|
||||
frequency_file_load(true);
|
||||
frequency_file_load();
|
||||
if (frequency_list.size() > 0) {
|
||||
if (fwd) {
|
||||
button_dir.set_text("FW>");
|
||||
@@ -614,7 +613,7 @@ ReconView::ReconView(NavigationView& nav)
|
||||
button_scanner_mode.set_text("SCAN");
|
||||
button_remove.set_text("DELETE");
|
||||
}
|
||||
frequency_file_load(true);
|
||||
frequency_file_load();
|
||||
if (autostart) {
|
||||
recon_resume();
|
||||
} else {
|
||||
@@ -642,7 +641,7 @@ ReconView::ReconView(NavigationView& nav)
|
||||
load_persisted_settings();
|
||||
ui_settings.save();
|
||||
|
||||
frequency_file_load(false);
|
||||
frequency_file_load();
|
||||
freqlist_cleared_for_ui_action = false;
|
||||
|
||||
if (autostart) {
|
||||
@@ -709,7 +708,7 @@ ReconView::ReconView(NavigationView& nav)
|
||||
delete_file(freq_file_path);
|
||||
}
|
||||
|
||||
frequency_file_load(false); /* do not stop all at start */
|
||||
frequency_file_load(); /* do not stop all at start */
|
||||
if (autostart) {
|
||||
recon_resume();
|
||||
} else {
|
||||
@@ -718,7 +717,7 @@ ReconView::ReconView(NavigationView& nav)
|
||||
recon_redraw();
|
||||
}
|
||||
|
||||
void ReconView::frequency_file_load(bool) {
|
||||
void ReconView::frequency_file_load() {
|
||||
if (field_mode.selected_index_value() != SPEC_MODULATION)
|
||||
audio::output::stop();
|
||||
|
||||
@@ -784,7 +783,7 @@ void ReconView::on_statistics_update(const ChannelStatistics& statistics) {
|
||||
// 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(false);
|
||||
frequency_file_load();
|
||||
}
|
||||
if (autostart && !user_pause) {
|
||||
recon_resume();
|
||||
@@ -1214,11 +1213,12 @@ void ReconView::handle_remove_current_item() {
|
||||
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();
|
||||
}
|
||||
|
||||
|
||||
@@ -81,7 +81,7 @@ class ReconView : public View {
|
||||
void show_max(bool refresh_display = false);
|
||||
void recon_pause();
|
||||
void recon_resume();
|
||||
void frequency_file_load(bool stop_all_before = false);
|
||||
void frequency_file_load();
|
||||
void on_statistics_update(const ChannelStatistics& statistics);
|
||||
void on_index_delta(int32_t v);
|
||||
void on_stepper_delta(int32_t v);
|
||||
@@ -154,8 +154,8 @@ class ReconView : public View {
|
||||
uint16_t last_nb_match{999};
|
||||
uint16_t last_freq_lock{999};
|
||||
size_t last_list_size{0};
|
||||
int8_t last_rssi_min{-127};
|
||||
int8_t last_rssi_med{-127};
|
||||
int8_t last_rssi_min{127};
|
||||
int8_t last_rssi_med{0};
|
||||
int8_t last_rssi_max{-127};
|
||||
int32_t last_index{-1};
|
||||
int64_t last_freq{0};
|
||||
|
||||
@@ -39,10 +39,10 @@ namespace ui {
|
||||
ReconSetupViewMain::ReconSetupViewMain(NavigationView& nav, Rect parent_rect, std::string input_file, std::string output_file)
|
||||
: View(parent_rect), _input_file{input_file}, _output_file{output_file} {
|
||||
hidden(true);
|
||||
add_children({&button_load_freqs,
|
||||
add_children({&button_input_file,
|
||||
&text_input_file,
|
||||
&button_save_freqs,
|
||||
&button_output_file,
|
||||
&button_choose_output_file,
|
||||
&button_choose_output_name,
|
||||
&checkbox_autosave_freqs,
|
||||
&checkbox_autostart_recon,
|
||||
&checkbox_clear_output});
|
||||
@@ -52,9 +52,9 @@ ReconSetupViewMain::ReconSetupViewMain(NavigationView& nav, Rect parent_rect, st
|
||||
checkbox_clear_output.set_value(persistent_memory::recon_clear_output());
|
||||
|
||||
text_input_file.set(_input_file);
|
||||
button_output_file.set_text(_output_file);
|
||||
button_choose_output_name.set_text(_output_file);
|
||||
|
||||
button_load_freqs.on_select = [this, &nav](Button&) {
|
||||
button_input_file.on_select = [this, &nav](Button&) {
|
||||
auto open_view = nav.push<FileLoadView>(".TXT");
|
||||
open_view->push_dir(freqman_dir);
|
||||
open_view->on_changed = [this, &nav](std::filesystem::path new_file_path) {
|
||||
@@ -67,25 +67,24 @@ ReconSetupViewMain::ReconSetupViewMain(NavigationView& nav, Rect parent_rect, st
|
||||
};
|
||||
};
|
||||
|
||||
button_save_freqs.on_select = [this, &nav](Button&) {
|
||||
button_choose_output_file.on_select = [this, &nav](Button&) {
|
||||
auto open_view = nav.push<FileLoadView>(".TXT");
|
||||
open_view->push_dir(freqman_dir);
|
||||
open_view->on_changed = [this, &nav](std::filesystem::path new_file_path) {
|
||||
if (new_file_path.native().find(freqman_dir.native()) == 0) {
|
||||
_output_file = new_file_path.stem().string();
|
||||
button_output_file.set_text(_output_file);
|
||||
button_choose_output_name.set_text(_output_file);
|
||||
} else {
|
||||
nav.display_modal("LOAD ERROR", "A valid file from\nFREQMAN directory is\nrequired.");
|
||||
nav.display_modal("SAVE ERROR", "A valid file from\nFREQMAN directory is\nrequired.");
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
button_output_file.on_select = [this, &nav](Button&) {
|
||||
text_prompt(nav, _output_file, 28,
|
||||
[this](std::string& buffer) {
|
||||
_output_file = std::move(buffer);
|
||||
button_output_file.set_text(_output_file);
|
||||
});
|
||||
button_choose_output_name.on_select = [this, &nav](Button&) {
|
||||
text_prompt(nav, _output_file, 28, [this](std::string& buffer) {
|
||||
_output_file = buffer;
|
||||
button_choose_output_name.set_text(_output_file);
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
@@ -105,7 +104,7 @@ void ReconSetupViewMore::save() {
|
||||
};
|
||||
|
||||
void ReconSetupViewMain::focus() {
|
||||
button_load_freqs.focus();
|
||||
button_input_file.focus();
|
||||
}
|
||||
|
||||
ReconSetupViewMore::ReconSetupViewMore(NavigationView& nav, Rect parent_rect)
|
||||
|
||||
@@ -73,17 +73,18 @@ class ReconSetupViewMain : public View {
|
||||
std::string _input_file{"RECON"};
|
||||
std::string _output_file{"RECON_RESULTS"};
|
||||
|
||||
Button button_load_freqs{
|
||||
Button button_input_file{
|
||||
{1 * 8, 12, 18 * 8, 22},
|
||||
"select input file"};
|
||||
Text text_input_file{
|
||||
{1 * 8, 4 + 2 * 16, 18 * 8, 22},
|
||||
"RECON"};
|
||||
|
||||
Button button_save_freqs{
|
||||
Button button_choose_output_file{
|
||||
{1 * 8, 4 * 16 - 8, 18 * 8, 22},
|
||||
"select output file"};
|
||||
Button button_output_file{
|
||||
|
||||
Button button_choose_output_name{
|
||||
{1 * 8, 5 * 16 - 2, 18 * 8, 22},
|
||||
"RECON_RESULTS"};
|
||||
|
||||
|
||||
@@ -87,10 +87,18 @@ SigGenView::SigGenView(
|
||||
&field_stop,
|
||||
&tx_view});
|
||||
|
||||
symfield_tone.hidden(1); // At first launch , by default we are in CW Shape has NO MOD , we are not using Tone modulation.
|
||||
symfield_tone.set_value(1000); // Default: 1000 Hz
|
||||
options_shape.on_change = [this](size_t, OptionsField::value_t v) {
|
||||
text_shape.set(shape_strings[v]);
|
||||
if (auto_update)
|
||||
update_config();
|
||||
if ((v == 0) || (v == 6)) { // In Shapes Options (CW & Pseudo Random Noise) we are not using Tone modulation freq.
|
||||
symfield_tone.hidden(1);
|
||||
} else {
|
||||
symfield_tone.hidden(0);
|
||||
}
|
||||
set_dirty();
|
||||
};
|
||||
options_shape.set_selected_index(0);
|
||||
text_shape.set(shape_strings[0]);
|
||||
|
||||
@@ -58,15 +58,16 @@ class SigGenView : public View {
|
||||
app_settings::SettingsManager settings_{
|
||||
"tx_siggen", app_settings::Mode::TX};
|
||||
|
||||
const std::string shape_strings[7] = {
|
||||
"CW-just carrier",
|
||||
"Sine signal ",
|
||||
"Triangle signal",
|
||||
"Saw up signal ",
|
||||
"Saw down signal",
|
||||
"Square signal ",
|
||||
"Noise signal " // using 16 bits LFSR register, 16 order polynomial feedback.
|
||||
};
|
||||
const std::string shape_strings[9] = {
|
||||
"CW (No mod.) ",
|
||||
"Sine mod. FM",
|
||||
"Triangle mod.FM", // max 15 character text space.
|
||||
"Saw up mod. FM",
|
||||
"Saw down mod.FM",
|
||||
"Square mod. FM",
|
||||
"Pseudo Noise FM", // using 16 bits LFSR register, 16 order polynomial feedback.
|
||||
"BPSK 0,1,0,1...",
|
||||
"QPSK 00-01-10.."};
|
||||
|
||||
bool auto_update{false};
|
||||
|
||||
@@ -86,10 +87,12 @@ class SigGenView : public View {
|
||||
{&bitmap_sig_saw_up, 3},
|
||||
{&bitmap_sig_saw_down, 4},
|
||||
{&bitmap_sig_square, 5},
|
||||
{&bitmap_sig_noise, 6}}};
|
||||
{&bitmap_sig_noise, 6},
|
||||
{&bitmap_sig_noise, 7}, // Pending to add a correct BPSK icon.
|
||||
{&bitmap_sig_noise, 8}}}; // Pending to add a correct QPSK icon.
|
||||
|
||||
Text text_shape{
|
||||
{15 * 8, 4 + 10, 8 * 8, 16},
|
||||
{15 * 8, 4 + 10, 15 * 8, 16},
|
||||
""};
|
||||
|
||||
SymField symfield_tone{
|
||||
|
||||
@@ -198,8 +198,8 @@ void update_audio_mute() {
|
||||
|
||||
namespace input {
|
||||
|
||||
void start(int8_t alc_mode) {
|
||||
audio_codec->microphone_enable(alc_mode); // added user-GUI selection for AK4951, ALC mode parameter.
|
||||
void start(int8_t alc_mode, bool mic_to_HP_enabled) {
|
||||
audio_codec->microphone_enable(alc_mode, mic_to_HP_enabled); // added user-GUI selection for AK4951, ALC mode parameter. and the check box "Hear Mic"
|
||||
i2s::i2s0::rx_start();
|
||||
}
|
||||
|
||||
@@ -208,6 +208,14 @@ void stop() {
|
||||
audio_codec->microphone_disable();
|
||||
}
|
||||
|
||||
void loopback_mic_to_hp_enable() {
|
||||
audio_codec->microphone_to_HP_enable();
|
||||
}
|
||||
|
||||
void loopback_mic_to_hp_disable() {
|
||||
audio_codec->microphone_to_HP_disable();
|
||||
}
|
||||
|
||||
} /* namespace input */
|
||||
|
||||
namespace headphone {
|
||||
|
||||
@@ -50,9 +50,12 @@ class Codec {
|
||||
virtual volume_range_t headphone_gain_range() const = 0;
|
||||
virtual void set_headphone_volume(const volume_t volume) = 0;
|
||||
|
||||
virtual void microphone_enable(int8_t alc_mode) = 0; // added user-GUI AK4951 ,selected ALC mode.
|
||||
virtual void microphone_enable(int8_t alc_mode, bool mic_to_HP_enabled) = 0; // added user-GUI AK4951 ,selected ALC mode.
|
||||
virtual void microphone_disable() = 0;
|
||||
|
||||
virtual void microphone_to_HP_enable() = 0;
|
||||
virtual void microphone_to_HP_disable() = 0;
|
||||
|
||||
virtual size_t reg_count() const = 0;
|
||||
virtual size_t reg_bits() const = 0;
|
||||
virtual uint32_t reg_read(const size_t register_number) = 0;
|
||||
@@ -76,9 +79,12 @@ void update_audio_mute();
|
||||
|
||||
namespace input {
|
||||
|
||||
void start(int8_t alc_mode); // added parameter user-GUI select AK4951-ALC mode for config mic path,(recording mode in datasheet),
|
||||
void start(int8_t alc_mode, bool mic_to_HP_enabled); // added parameters -GUI select AK4951-ALC mode for config mic path,(recording mode),and the check box "Hear Mic"
|
||||
void stop();
|
||||
|
||||
void loopback_mic_to_hp_enable();
|
||||
void loopback_mic_to_hp_disable();
|
||||
|
||||
} /* namespace input */
|
||||
|
||||
namespace headphone {
|
||||
|
||||
@@ -149,12 +149,18 @@ void set_aprs(const uint32_t baudrate) {
|
||||
send_message(&message);
|
||||
}
|
||||
|
||||
void set_btle(const uint32_t baudrate, const uint32_t word_length, const uint32_t trigger_value, const bool trigger_word) {
|
||||
void set_btlerx(uint8_t channel_number) {
|
||||
const BTLERxConfigureMessage message{
|
||||
baudrate,
|
||||
word_length,
|
||||
trigger_value,
|
||||
trigger_word};
|
||||
channel_number};
|
||||
send_message(&message);
|
||||
}
|
||||
|
||||
void set_btletx(uint8_t channel_number, char* macAddress, char* advertisementData, uint8_t pduType) {
|
||||
const BTLETxConfigureMessage message{
|
||||
channel_number,
|
||||
macAddress,
|
||||
advertisementData,
|
||||
pduType};
|
||||
send_message(&message);
|
||||
}
|
||||
|
||||
@@ -167,6 +173,17 @@ void set_nrf(const uint32_t baudrate, const uint32_t word_length, const uint32_t
|
||||
send_message(&message);
|
||||
}
|
||||
|
||||
void set_fsk(const size_t deviation) {
|
||||
const FSKRxConfigureMessage message{
|
||||
taps_200k_decim_0,
|
||||
taps_16k0_decim_1,
|
||||
taps_11k0_channel,
|
||||
2,
|
||||
deviation};
|
||||
|
||||
send_message(&message);
|
||||
}
|
||||
|
||||
void set_afsk_data(const uint32_t afsk_samples_per_bit, const uint32_t afsk_phase_inc_mark, const uint32_t afsk_phase_inc_space, const uint8_t afsk_repeat, const uint32_t afsk_bw, const uint8_t symbol_count) {
|
||||
const AFSKTxConfigureMessage message{
|
||||
afsk_samples_per_bit,
|
||||
|
||||
@@ -69,9 +69,11 @@ void set_pitch_rssi(int32_t avg, bool enabled);
|
||||
void set_afsk_data(const uint32_t afsk_samples_per_bit, const uint32_t afsk_phase_inc_mark, const uint32_t afsk_phase_inc_space, const uint8_t afsk_repeat, const uint32_t afsk_bw, const uint8_t symbol_count);
|
||||
void kill_afsk();
|
||||
void set_afsk(const uint32_t baudrate, const uint32_t word_length, const uint32_t trigger_value, const bool trigger_word);
|
||||
void set_fsk(const size_t deviation);
|
||||
void set_aprs(const uint32_t baudrate);
|
||||
|
||||
void set_btle(const uint32_t baudrate, const uint32_t word_length, const uint32_t trigger_value, const bool trigger_word);
|
||||
void set_btlerx(uint8_t channel_number);
|
||||
void set_btletx(uint8_t channel_number, char* macAddress, char* advertisementData, uint8_t pduType);
|
||||
|
||||
void set_nrf(const uint32_t baudrate, const uint32_t word_length, const uint32_t trigger_value, const bool trigger_word);
|
||||
|
||||
|
||||
@@ -5683,6 +5683,44 @@ static constexpr Bitmap bitmap_icon_trim{
|
||||
{16, 16},
|
||||
bitmap_icon_trim_data};
|
||||
|
||||
static constexpr uint8_t bitmap_icon_hide_data[] = {
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x40,
|
||||
0x00,
|
||||
0x20,
|
||||
0xE0,
|
||||
0x17,
|
||||
0x18,
|
||||
0x18,
|
||||
0xC4,
|
||||
0x27,
|
||||
0x62,
|
||||
0x42,
|
||||
0x21,
|
||||
0x85,
|
||||
0xA1,
|
||||
0x84,
|
||||
0x62,
|
||||
0x46,
|
||||
0xA4,
|
||||
0x23,
|
||||
0x18,
|
||||
0x18,
|
||||
0xE8,
|
||||
0x07,
|
||||
0x04,
|
||||
0x00,
|
||||
0x02,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
};
|
||||
static constexpr Bitmap bitmap_icon_hide{
|
||||
{16, 16},
|
||||
bitmap_icon_hide_data};
|
||||
|
||||
} /* namespace ui */
|
||||
|
||||
#endif /*__BITMAP_HPP__*/
|
||||
|
||||
@@ -321,7 +321,7 @@ void MAX2837::set_rx_buff_vcm(const size_t v) {
|
||||
flush();
|
||||
}
|
||||
|
||||
reg_t MAX2837::temp_sense() {
|
||||
int8_t MAX2837::temp_sense() {
|
||||
if (!_map.r.rx_top.ts_en) {
|
||||
_map.r.rx_top.ts_en = 1;
|
||||
flush_one(Register::RX_TOP);
|
||||
@@ -334,12 +334,15 @@ reg_t MAX2837::temp_sense() {
|
||||
|
||||
halPolledDelay(ticks_for_temperature_sense_adc_conversion);
|
||||
|
||||
const auto value = read(Register::TEMP_SENSE);
|
||||
/*
|
||||
* Conversion to degrees C determined by testing - does not match data sheet.
|
||||
*/
|
||||
reg_t value = read(Register::TEMP_SENSE) & 0x1F;
|
||||
|
||||
_map.r.rx_top.ts_adc_trigger = 0;
|
||||
flush_one(Register::RX_TOP);
|
||||
|
||||
return value;
|
||||
return value * 4.31 - 6; // reg value is 0 to 31; possible return range is -6 C to 127 C
|
||||
}
|
||||
|
||||
} // namespace max2837
|
||||
|
||||
@@ -833,7 +833,7 @@ class MAX2837 : public MAX283x {
|
||||
void set_vco_bias(const size_t v);
|
||||
void set_rx_buff_vcm(const size_t v) override;
|
||||
|
||||
reg_t temp_sense() override;
|
||||
int8_t temp_sense() override;
|
||||
|
||||
reg_t read(const address_t reg_num) override;
|
||||
|
||||
|
||||
@@ -351,7 +351,7 @@ void MAX2839::set_rx_buff_vcm(const size_t v) {
|
||||
flush();
|
||||
}
|
||||
|
||||
reg_t MAX2839::temp_sense() {
|
||||
int8_t MAX2839::temp_sense() {
|
||||
if (!_map.r.rx_top_2.ts_en) {
|
||||
_map.r.rx_top_2.ts_en = 1;
|
||||
flush_one(Register::RX_TOP_2);
|
||||
@@ -365,15 +365,14 @@ reg_t MAX2839::temp_sense() {
|
||||
halPolledDelay(ticks_for_temperature_sense_adc_conversion);
|
||||
|
||||
/*
|
||||
* Things look very similar to MAX2837, so this probably works, but the
|
||||
* MAX2839 data sheet does not describe the TEMP_SENSE register contents.
|
||||
* Conversion to degrees C determined by testing - does not match data sheet.
|
||||
*/
|
||||
const auto value = read(Register::TEMP_SENSE);
|
||||
reg_t value = read(Register::TEMP_SENSE) & 0x1F;
|
||||
|
||||
_map.r.rx_top_2.ts_adc_trigger = 0;
|
||||
flush_one(Register::RX_TOP_2);
|
||||
|
||||
return value;
|
||||
return value * 4.31 - 75; // reg value is 0 to 31; possible return range is -75 C to 58 C
|
||||
}
|
||||
|
||||
} // namespace max2839
|
||||
@@ -692,7 +692,7 @@ class MAX2839 : public MAX283x {
|
||||
void set_rx_lo_iq_calibration(const size_t v) override;
|
||||
void set_rx_buff_vcm(const size_t v) override;
|
||||
|
||||
reg_t temp_sense() override;
|
||||
int8_t temp_sense() override;
|
||||
|
||||
reg_t read(const address_t reg_num) override;
|
||||
|
||||
|
||||
@@ -131,7 +131,7 @@ class MAX283x {
|
||||
virtual void set_rx_lo_iq_calibration(const size_t v);
|
||||
virtual void set_rx_buff_vcm(const size_t v);
|
||||
|
||||
virtual reg_t temp_sense();
|
||||
virtual int8_t temp_sense();
|
||||
|
||||
virtual reg_t read(const address_t reg_num);
|
||||
};
|
||||
|
||||
@@ -36,6 +36,13 @@ uint32_t power(T value) {
|
||||
return (real * real) + (imag * imag);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
uint32_t iq_max(T value) {
|
||||
auto real = abs(value.real());
|
||||
auto imag = abs(value.imag());
|
||||
return (real > imag) ? real : imag;
|
||||
}
|
||||
|
||||
/* Collects capture file metadata and sample power buckets. */
|
||||
template <typename T>
|
||||
Optional<CaptureInfo> profile_capture(
|
||||
@@ -51,7 +58,8 @@ Optional<CaptureInfo> profile_capture(
|
||||
.file_size = f.size(),
|
||||
.sample_count = f.size() / sizeof(T),
|
||||
.sample_size = sizeof(T),
|
||||
.max_power = 0};
|
||||
.max_power = 0,
|
||||
.max_iq = 0};
|
||||
|
||||
auto profile_samples = buckets.size * samples_per_bucket;
|
||||
auto sample_interval = info.sample_count / profile_samples;
|
||||
@@ -67,8 +75,11 @@ Optional<CaptureInfo> profile_capture(
|
||||
if (*result != info.sample_size)
|
||||
break; // EOF
|
||||
|
||||
auto mag_squared = power(value);
|
||||
auto max_iq = iq_max(value);
|
||||
if (max_iq > info.max_iq)
|
||||
info.max_iq = max_iq;
|
||||
|
||||
auto mag_squared = power(value);
|
||||
if (mag_squared > info.max_power)
|
||||
info.max_power = mag_squared;
|
||||
|
||||
@@ -133,13 +144,50 @@ TrimRange compute_trim_range(
|
||||
info.sample_size};
|
||||
}
|
||||
|
||||
void amplify_iq_buffer(uint8_t* buffer, uint32_t length, uint32_t amplification, uint8_t sample_size) {
|
||||
uint32_t mult_count = length / sample_size / 2;
|
||||
|
||||
switch (sample_size) {
|
||||
case sizeof(complex16_t): {
|
||||
int16_t* buf_ptr = (int16_t*)buffer;
|
||||
for (uint32_t i = 0; i < mult_count; i++) {
|
||||
int32_t val = *buf_ptr * amplification;
|
||||
if (val > 0x7FFF)
|
||||
val = 0x7FFF;
|
||||
else if (val < -0x7FFF)
|
||||
val = -0x7FFF;
|
||||
*buf_ptr++ = val;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case sizeof(complex8_t): {
|
||||
int8_t* buf_ptr = (int8_t*)buffer;
|
||||
for (uint32_t i = 0; i < mult_count; i++) {
|
||||
int32_t val = *buf_ptr * amplification;
|
||||
if (val > 0x7F)
|
||||
val = 0x7F;
|
||||
else if (val < -0x7F)
|
||||
val = -0x7F;
|
||||
*buf_ptr++ = val;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
bool trim_capture_with_range(
|
||||
const fs::path& path,
|
||||
TrimRange range,
|
||||
const std::function<void(uint8_t)>& on_progress) {
|
||||
const std::function<void(uint8_t)>& on_progress,
|
||||
const uint32_t amplification) {
|
||||
constexpr size_t buffer_size = std::filesystem::max_file_block_size;
|
||||
uint8_t buffer[buffer_size];
|
||||
auto temp_path = path + u"-tmp";
|
||||
auto sample_size = fs::capture_file_sample_size(path);
|
||||
|
||||
// end_sample is the first sample to _not_ include.
|
||||
auto start_byte = range.start_sample * range.sample_size;
|
||||
@@ -168,6 +216,9 @@ bool trim_capture_with_range(
|
||||
auto remaining = length - processed;
|
||||
auto to_write = std::min(remaining, *result);
|
||||
|
||||
if (amplification > 1)
|
||||
amplify_iq_buffer(buffer, to_write, amplification, sample_size);
|
||||
|
||||
result = dst->write(buffer, to_write);
|
||||
if (result.is_error()) return false;
|
||||
|
||||
|
||||
@@ -37,6 +37,7 @@ struct CaptureInfo {
|
||||
uint64_t sample_count;
|
||||
uint8_t sample_size;
|
||||
uint32_t max_power;
|
||||
uint32_t max_iq;
|
||||
};
|
||||
|
||||
/* Holds sample average power by bucket. */
|
||||
@@ -82,11 +83,19 @@ TrimRange compute_trim_range(
|
||||
const PowerBuckets& buckets,
|
||||
uint8_t cutoff_percent);
|
||||
|
||||
/* Multiplies samples in an IQ buffer by amplification value */
|
||||
void amplify_iq_buffer(
|
||||
uint8_t* buffer,
|
||||
uint32_t length,
|
||||
uint32_t amplification,
|
||||
uint8_t sample_size);
|
||||
|
||||
/* Trims the capture file with the specified range. */
|
||||
bool trim_capture_with_range(
|
||||
const std::filesystem::path& path,
|
||||
TrimRange range,
|
||||
const std::function<void(uint8_t)>& on_progress);
|
||||
const std::function<void(uint8_t)>& on_progress,
|
||||
const uint32_t amplification);
|
||||
|
||||
} // namespace iq
|
||||
|
||||
|
||||
@@ -295,8 +295,8 @@ uint32_t register_read(const size_t register_number) {
|
||||
return radio::second_if->read(register_number);
|
||||
}
|
||||
|
||||
uint8_t temp_sense() {
|
||||
return radio::second_if->temp_sense() & 0x1f;
|
||||
int8_t temp_sense() {
|
||||
return radio::second_if->temp_sense();
|
||||
}
|
||||
|
||||
} /* namespace second_if */
|
||||
|
||||
@@ -73,7 +73,7 @@ namespace second_if {
|
||||
uint32_t register_read(const size_t register_number);
|
||||
|
||||
// TODO: This belongs somewhere else.
|
||||
uint8_t temp_sense();
|
||||
int8_t temp_sense();
|
||||
|
||||
} /* namespace second_if */
|
||||
|
||||
|
||||
@@ -88,6 +88,27 @@ static std::pair<typename ContainerType::const_iterator, typename ContainerType:
|
||||
return {start, end};
|
||||
}
|
||||
|
||||
template <typename ContainerType, typename KeySelector, typename SortOrder>
|
||||
void sortEntriesBy(ContainerType& entries, KeySelector keySelector, SortOrder ascending) {
|
||||
entries.sort([keySelector, ascending](const auto& a, const auto& b) {
|
||||
return ascending ? keySelector(a) < keySelector(b) : keySelector(a) > keySelector(b);
|
||||
});
|
||||
}
|
||||
|
||||
template <typename ContainerType, typename KeySelector>
|
||||
void removeEntriesWithoutKey(ContainerType& entries, ContainerType& filteredEntries, KeySelector keySelector) {
|
||||
// Clear the filteredEntries container
|
||||
filteredEntries.clear();
|
||||
|
||||
auto it = entries.begin();
|
||||
while (it != entries.end()) {
|
||||
if (!keySelector(*it)) {
|
||||
filteredEntries.emplace_back(*it); // Add a new entry to filteredEntries
|
||||
}
|
||||
++it; // Move to the next element, outside of the if block
|
||||
}
|
||||
}
|
||||
|
||||
namespace ui {
|
||||
|
||||
using RecentEntriesColumn = std::pair<std::string, size_t>;
|
||||
@@ -272,6 +293,10 @@ class RecentEntriesView : public View {
|
||||
_table.focus();
|
||||
}
|
||||
|
||||
void set_table(Entries& new_table) {
|
||||
_table = new_table;
|
||||
}
|
||||
|
||||
private:
|
||||
RecentEntriesHeader _header;
|
||||
RecentEntriesTable<Entries> _table;
|
||||
|
||||
@@ -311,6 +311,32 @@ std::string to_string_file_size(uint32_t file_size) {
|
||||
return to_string_dec_uint(file_size) + suffix[suffix_index];
|
||||
}
|
||||
|
||||
std::string to_string_mac_address(const uint8_t* macAddress, uint8_t length, bool noColon) {
|
||||
std::string string;
|
||||
|
||||
string += to_string_hex(macAddress[0], 2);
|
||||
|
||||
for (int i = 1; i < length; i++) {
|
||||
string += noColon ? to_string_hex(macAddress[i], 2) : ":" + to_string_hex(macAddress[i], 2);
|
||||
}
|
||||
|
||||
return string;
|
||||
}
|
||||
|
||||
std::string to_string_formatted_mac_address(const char* macAddress) {
|
||||
std::string formattedAddress;
|
||||
|
||||
for (int i = 0; i < 12; i += 2) {
|
||||
if (i > 0) {
|
||||
formattedAddress += ':';
|
||||
}
|
||||
formattedAddress += macAddress[i];
|
||||
formattedAddress += macAddress[i + 1];
|
||||
}
|
||||
|
||||
return formattedAddress;
|
||||
}
|
||||
|
||||
std::string unit_auto_scale(double n, const uint32_t base_unit, uint32_t precision) {
|
||||
const uint32_t powers_of_ten[5] = {1, 10, 100, 1000, 10000};
|
||||
std::string string{""};
|
||||
|
||||
@@ -76,6 +76,10 @@ std::string to_string_FAT_timestamp(const FATTimestamp& timestamp);
|
||||
// Gets a human readable file size string.
|
||||
std::string to_string_file_size(uint32_t file_size);
|
||||
|
||||
// Converts Mac Address to string.
|
||||
std::string to_string_mac_address(const uint8_t* macAddress, uint8_t length, bool noColon);
|
||||
std::string to_string_formatted_mac_address(const char* macAddress);
|
||||
|
||||
/* Scales 'n' to be a value less than 1000. 'base_unit' is the index of the unit from
|
||||
* 'unit_prefix' that 'n' is in initially. 3 is the index of the '1s' unit. */
|
||||
std::string unit_auto_scale(double n, const uint32_t base_unit, uint32_t precision);
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
|
||||
class TemperatureLogger {
|
||||
public:
|
||||
using sample_t = uint8_t;
|
||||
using sample_t = int8_t;
|
||||
|
||||
void second_tick();
|
||||
|
||||
|
||||
@@ -118,7 +118,12 @@ void AlphanumView::refresh_keys() {
|
||||
|
||||
size_t n = 0;
|
||||
for (auto& button : buttons) {
|
||||
button.set_text(std::string{key_list[n]});
|
||||
if (n > strlen(key_list)) {
|
||||
button.set_text(std::string{'\0'});
|
||||
} else {
|
||||
button.set_text(std::string{key_list[n]});
|
||||
}
|
||||
|
||||
n++;
|
||||
}
|
||||
|
||||
@@ -137,7 +142,9 @@ void AlphanumView::refresh_keys() {
|
||||
|
||||
void AlphanumView::on_button(Button& button) {
|
||||
const auto c = button.text()[0];
|
||||
char_add(c);
|
||||
if (c != '\0') {
|
||||
char_add(c);
|
||||
}
|
||||
|
||||
// TODO: Consolidate shift handling.
|
||||
if (shift_mode == ShiftMode::Shift) {
|
||||
|
||||
@@ -57,6 +57,7 @@ class AlphanumView : public TextEntryView {
|
||||
const char* const keys_upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ, .";
|
||||
const char* const keys_digit = "1234567890()'`\"+-*/=<>_\\!?, .";
|
||||
const char* const keys_symbl = "!@#$%^&*()[]'`\"{}|:;<>-_~?, .";
|
||||
const char* const keys_hex = "1234567890ABCDEF ";
|
||||
|
||||
struct key_set_t {
|
||||
const char* name;
|
||||
@@ -64,9 +65,10 @@ class AlphanumView : public TextEntryView {
|
||||
const char* shifted;
|
||||
};
|
||||
|
||||
const key_set_t key_sets[2] = {
|
||||
const key_set_t key_sets[3] = {
|
||||
{"abc", keys_lower, keys_upper},
|
||||
{"123", keys_digit, keys_symbl}};
|
||||
{"123", keys_digit, keys_symbl},
|
||||
{"hex", keys_hex, keys_hex}};
|
||||
|
||||
int16_t focused_button = 0;
|
||||
uint32_t mode = 0; // Letters.
|
||||
|
||||
@@ -246,13 +246,24 @@ void load_blacklist() {
|
||||
if (error)
|
||||
return;
|
||||
|
||||
blacklist_ptr = std::unique_ptr<char>(new char[f.size()]);
|
||||
if (f.read(blacklist_ptr.get(), f.size()))
|
||||
blacklist_len = f.size();
|
||||
// allocating two extra bytes for leading & trailing commas
|
||||
blacklist_ptr = std::unique_ptr<char>(new char[f.size() + 2]);
|
||||
if (f.read(blacklist_ptr.get() + 1, f.size())) {
|
||||
blacklist_len = f.size() + 2;
|
||||
|
||||
// replace any CR/LF characters with comma delineator, and add comma prefix/suffix, to simplify searching
|
||||
char* ptr = blacklist_ptr.get();
|
||||
*ptr = ',';
|
||||
*(ptr + blacklist_len - 1) = ',';
|
||||
for (size_t i = 0; i < blacklist_len; i++, ptr++) {
|
||||
if (*ptr == 0x0D || *ptr == 0x0A)
|
||||
*ptr = ',';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool BtnGridView::blacklisted_app(GridItem new_item) {
|
||||
std::string app_name = new_item.text;
|
||||
std::string app_name = "," + new_item.text + ",";
|
||||
|
||||
if (blacklist_len < app_name.size())
|
||||
return false;
|
||||
|
||||
@@ -42,6 +42,16 @@ FrequencyField::FrequencyField(
|
||||
set_focusable(true);
|
||||
}
|
||||
|
||||
FrequencyField::FrequencyField(
|
||||
const Point parent_pos,
|
||||
const rf::FrequencyRange range)
|
||||
: Widget{{parent_pos, {8 * 10, 16}}},
|
||||
length_{11},
|
||||
range_{range} {
|
||||
initial_switch_config_ = get_switches_long_press_config();
|
||||
set_focusable(true);
|
||||
}
|
||||
|
||||
FrequencyField::~FrequencyField() {
|
||||
reset_switch_config();
|
||||
}
|
||||
|
||||
@@ -48,6 +48,7 @@ class FrequencyField : public Widget {
|
||||
using range_t = rf::FrequencyRange;
|
||||
|
||||
FrequencyField(Point parent_pos);
|
||||
FrequencyField(Point parent_pos, rf::FrequencyRange range);
|
||||
~FrequencyField();
|
||||
|
||||
rf::Frequency value() const;
|
||||
@@ -66,8 +67,7 @@ class FrequencyField : public Widget {
|
||||
|
||||
private:
|
||||
const size_t length_;
|
||||
const range_t range_;
|
||||
|
||||
range_t range_;
|
||||
rf::Frequency value_{0};
|
||||
rf::Frequency step_{25000};
|
||||
uint64_t last_ms_{0};
|
||||
|
||||
@@ -30,6 +30,10 @@
|
||||
#define max(a, b) ((a) > (b) ? (a) : (b))
|
||||
#define abs(x) ((x) > 0 ? (x) : -(x))
|
||||
|
||||
// flag value for graph min
|
||||
// If it does not change, then all graph min values are is zero
|
||||
#define GRAPH_MIN_ALL_ZERO_FLAG 666
|
||||
|
||||
namespace ui {
|
||||
|
||||
RSSI::RSSI(
|
||||
@@ -209,17 +213,48 @@ void RSSI::on_statistics_update(const RSSIStatistics& statistics) {
|
||||
set_dirty();
|
||||
}
|
||||
|
||||
int16_t RSSIGraph::get_graph_min() {
|
||||
return graph_min_;
|
||||
}
|
||||
|
||||
int16_t RSSIGraph::get_graph_avg() {
|
||||
return graph_avg_;
|
||||
}
|
||||
|
||||
int16_t RSSIGraph::get_graph_max() {
|
||||
return graph_max_;
|
||||
}
|
||||
|
||||
int16_t RSSIGraph::get_graph_delta() {
|
||||
return graph_max_ - graph_min_;
|
||||
}
|
||||
|
||||
void RSSIGraph::paint(Painter& painter) {
|
||||
const auto r = screen_rect();
|
||||
|
||||
RSSIGraph_entry& prev_entry = graph_list[0];
|
||||
int xpos = 0, prev_xpos = r.width();
|
||||
if (graph_list.size() == 0)
|
||||
return;
|
||||
|
||||
int xpos = 0, prev_xpos = r.width();
|
||||
RSSIGraph_entry& prev_entry = graph_list[0];
|
||||
|
||||
graph_min_ = GRAPH_MIN_ALL_ZERO_FLAG; // if it stays at that value the whole graphlist min are zero
|
||||
graph_max_ = 0;
|
||||
int avg_sum = 0;
|
||||
for (int n = 1; (unsigned)n <= graph_list.size(); n++) {
|
||||
xpos = (r.width() * (graph_list.size() - n)) / graph_list.size();
|
||||
int size = abs(xpos - prev_xpos);
|
||||
RSSIGraph_entry& entry = graph_list[n - 1];
|
||||
|
||||
// stats
|
||||
if (entry.rssi_min != 0 && entry.rssi_min < graph_min_) {
|
||||
graph_min_ = entry.rssi_min;
|
||||
}
|
||||
if (entry.rssi_max > graph_max_) {
|
||||
graph_max_ = entry.rssi_max;
|
||||
}
|
||||
avg_sum += entry.rssi_avg;
|
||||
|
||||
// black
|
||||
const Rect r0{r.right() - prev_xpos, r.top(), size, r.height()};
|
||||
painter.fill_rectangle(
|
||||
@@ -293,6 +328,10 @@ void RSSIGraph::paint(Painter& painter) {
|
||||
prev_entry = entry;
|
||||
prev_xpos = xpos;
|
||||
}
|
||||
graph_avg_ = (avg_sum / graph_list.size());
|
||||
// hack to only set to 0 if all graphlist min values are 0
|
||||
if (graph_min_ == GRAPH_MIN_ALL_ZERO_FLAG)
|
||||
graph_min_ = 0;
|
||||
}
|
||||
|
||||
/*void RSSIGraph::paintOld(Painter& painter) {
|
||||
|
||||
@@ -49,6 +49,7 @@ class RSSI : public Widget {
|
||||
: RSSI{{}, {}} {
|
||||
}
|
||||
|
||||
// get last used/received min/avg/max/delta
|
||||
int16_t get_min();
|
||||
int16_t get_avg();
|
||||
int16_t get_max();
|
||||
@@ -113,8 +114,16 @@ class RSSIGraph : public Widget {
|
||||
|
||||
void on_hide() override;
|
||||
void on_show() override;
|
||||
// get whole graph_list min/avg/max/delta
|
||||
int16_t get_graph_min();
|
||||
int16_t get_graph_avg();
|
||||
int16_t get_graph_max();
|
||||
int16_t get_graph_delta();
|
||||
|
||||
private:
|
||||
int16_t graph_min_ = 0;
|
||||
int16_t graph_avg_ = 0;
|
||||
int16_t graph_max_ = 0;
|
||||
uint16_t nb_columns_before_hide = 16;
|
||||
uint16_t nb_columns = 16;
|
||||
RSSIGraphList graph_list{};
|
||||
|
||||
@@ -45,6 +45,7 @@
|
||||
#include "ui_flash_utility.hpp"
|
||||
#include "ui_font_fixed_8x16.hpp"
|
||||
#include "ui_freqman.hpp"
|
||||
#include "ui_fsk_rx.hpp"
|
||||
#include "ui_iq_trim.hpp"
|
||||
#include "ui_jammer.hpp"
|
||||
// #include "ui_keyfob.hpp"
|
||||
@@ -85,6 +86,8 @@
|
||||
#include "ais_app.hpp"
|
||||
#include "analog_audio_app.hpp"
|
||||
#include "analog_tv_app.hpp"
|
||||
#include "ble_rx_app.hpp"
|
||||
#include "ble_tx_app.hpp"
|
||||
#include "capture_app.hpp"
|
||||
#include "ert_app.hpp"
|
||||
#include "gps_sim_app.hpp"
|
||||
@@ -395,6 +398,7 @@ void SystemStatusView::rtc_battery_workaround() {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
make_new_directory(SETTINGS_DIR);
|
||||
make_new_file(DATE_FILEFLAG);
|
||||
|
||||
year = 1980;
|
||||
@@ -546,7 +550,8 @@ ReceiversMenuView::ReceiversMenuView(NavigationView& nav) {
|
||||
{"Analog TV", Color::yellow(), &bitmap_icon_sstv, [&nav]() { nav.push<AnalogTvView>(); }},
|
||||
{"APRS", Color::green(), &bitmap_icon_aprs, [&nav]() { nav.push<APRSRXView>(); }},
|
||||
{"Audio", Color::green(), &bitmap_icon_speaker, [&nav]() { nav.push<AnalogAudioView>(); }},
|
||||
{"BTLE", Color::yellow(), &bitmap_icon_btle, [&nav]() { nav.push<BTLERxView>(); }},
|
||||
//{"BTLE", Color::yellow(), &bitmap_icon_btle, [&nav]() { nav.push<BTLERxView>(); }},
|
||||
{"BLE Rx", Color::green(), &bitmap_icon_btle, [&nav]() { nav.push<BLERxView>(); }},
|
||||
{"ERT Meter", Color::green(), &bitmap_icon_ert, [&nav]() { nav.push<ERTAppView>(); }},
|
||||
{"Level", Color::green(), &bitmap_icon_options_radio, [&nav]() { nav.push<LevelView>(); }},
|
||||
{"NRF", Color::yellow(), &bitmap_icon_nrf, [&nav]() { nav.push<NRFRxView>(); }},
|
||||
@@ -555,6 +560,7 @@ ReceiversMenuView::ReceiversMenuView(NavigationView& nav) {
|
||||
{"Recon", Color::green(), &bitmap_icon_scanner, [&nav]() { nav.push<ReconView>(); }},
|
||||
{"Search", Color::yellow(), &bitmap_icon_search, [&nav]() { nav.push<SearchView>(); }},
|
||||
{"TPMS Cars", Color::green(), &bitmap_icon_tpms, [&nav]() { nav.push<TPMSAppView>(); }},
|
||||
// {"FSK RX", Color::yellow(), &bitmap_icon_remote, [&nav]() { nav.push<FskxRxMainView>(); }},
|
||||
// {"DMR", Color::dark_grey(), &bitmap_icon_dmr, [&nav](){ nav.push<NotImplementedView>(); }},
|
||||
// {"SIGFOX", Color::dark_grey(), &bitmap_icon_fox, [&nav](){ nav.push<NotImplementedView>(); }},
|
||||
// {"LoRa", Color::dark_grey(), &bitmap_icon_lora, [&nav](){ nav.push<NotImplementedView>(); }},
|
||||
@@ -577,6 +583,7 @@ TransmittersMenuView::TransmittersMenuView(NavigationView& nav) {
|
||||
{"ADS-B TX", ui::Color::green(), &bitmap_icon_adsb, [&nav]() { nav.push<ADSBTxView>(); }},
|
||||
{"APRS TX", ui::Color::green(), &bitmap_icon_aprs, [&nav]() { nav.push<APRSTXView>(); }},
|
||||
{"BHT Xy/EP", ui::Color::green(), &bitmap_icon_bht, [&nav]() { nav.push<BHTView>(); }},
|
||||
{"BLE Tx", ui::Color::green(), &bitmap_icon_btle, [&nav]() { nav.push<BLETxView>(); }},
|
||||
{"BurgerPgr", ui::Color::yellow(), &bitmap_icon_burger, [&nav]() { nav.push<CoasterPagerView>(); }},
|
||||
{"GPS Sim", ui::Color::green(), &bitmap_icon_gps_sim, [&nav]() { nav.push<GpsSimAppView>(); }},
|
||||
{"Jammer", ui::Color::green(), &bitmap_icon_jammer, [&nav]() { nav.push<JammerView>(); }},
|
||||
|
||||
@@ -322,7 +322,7 @@ void RecordView::trim_capture() {
|
||||
auto trim_range = iq::compute_trim_range(*info, power_buckets, 7);
|
||||
|
||||
trim_ui.show_trimming();
|
||||
iq::trim_capture_with_range(trim_path, trim_range, trim_ui.get_callback());
|
||||
iq::trim_capture_with_range(trim_path, trim_range, trim_ui.get_callback(), 1);
|
||||
}
|
||||
|
||||
trim_ui.clear();
|
||||
|
||||
@@ -360,6 +360,14 @@ set(MODE_CPPSRC
|
||||
proc_btlerx.cpp
|
||||
)
|
||||
DeclareTargets(PBTR btlerx)
|
||||
|
||||
### BTLE TX
|
||||
|
||||
set(MODE_CPPSRC
|
||||
proc_ble_tx.cpp
|
||||
)
|
||||
DeclareTargets(PBTT btletx)
|
||||
|
||||
### AIS
|
||||
|
||||
set(MODE_CPPSRC
|
||||
@@ -416,6 +424,13 @@ set(MODE_CPPSRC
|
||||
)
|
||||
DeclareTargets(PFSK fsktx)
|
||||
|
||||
### FSK RX
|
||||
|
||||
set(MODE_CPPSRC
|
||||
proc_fsk_rx.cpp
|
||||
)
|
||||
DeclareTargets(PFSR fskrx)
|
||||
|
||||
### Jammer
|
||||
|
||||
set(MODE_CPPSRC
|
||||
|
||||
@@ -0,0 +1,411 @@
|
||||
/*
|
||||
* Copyright (C) 2014 Jared Boone, ShareBrained Technology, Inc.
|
||||
* Copyright (C) 2016 Furrtek
|
||||
* Copyright (C) 2023 TJ Baginski
|
||||
*
|
||||
* 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 "proc_ble_tx.hpp"
|
||||
#include "portapack_shared_memory.hpp"
|
||||
#include "sine_table_int8.hpp"
|
||||
#include "event_m4.hpp"
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
#define new_way
|
||||
|
||||
int BTLETxProcessor::gen_sample_from_phy_bit(char* bit, char* sample, int num_bit) {
|
||||
int num_sample = (num_bit * SAMPLE_PER_SYMBOL) + (LEN_GAUSS_FILTER * SAMPLE_PER_SYMBOL);
|
||||
|
||||
int8_t* tmp_phy_bit_over_sampling_int8 = (int8_t*)tmp_phy_bit_over_sampling;
|
||||
|
||||
int i, j;
|
||||
|
||||
for (i = 0; i < (LEN_GAUSS_FILTER * SAMPLE_PER_SYMBOL - 1); i++) {
|
||||
tmp_phy_bit_over_sampling_int8[i] = 0;
|
||||
}
|
||||
for (i = (LEN_GAUSS_FILTER * SAMPLE_PER_SYMBOL - 1 + num_bit * SAMPLE_PER_SYMBOL); i < (2 * LEN_GAUSS_FILTER * SAMPLE_PER_SYMBOL - 2 + num_bit * SAMPLE_PER_SYMBOL); i++) {
|
||||
tmp_phy_bit_over_sampling_int8[i] = 0;
|
||||
}
|
||||
for (i = 0; i < (num_bit * SAMPLE_PER_SYMBOL); i++) {
|
||||
if (i % SAMPLE_PER_SYMBOL == 0) {
|
||||
tmp_phy_bit_over_sampling_int8[i + (LEN_GAUSS_FILTER * SAMPLE_PER_SYMBOL - 1)] = (bit[i / SAMPLE_PER_SYMBOL]) * 2 - 1;
|
||||
} else {
|
||||
tmp_phy_bit_over_sampling_int8[i + (LEN_GAUSS_FILTER * SAMPLE_PER_SYMBOL - 1)] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
int16_t tmp = 0;
|
||||
sample[0] = cos_table_int8[tmp];
|
||||
sample[1] = sin_table_int8[tmp];
|
||||
|
||||
int len_conv_result = num_sample - 1;
|
||||
for (i = 0; i < len_conv_result; i++) {
|
||||
int16_t acc = 0;
|
||||
for (j = 3; j < (LEN_GAUSS_FILTER * SAMPLE_PER_SYMBOL - 4); j++) {
|
||||
acc = acc + gauss_coef_int8[(LEN_GAUSS_FILTER * SAMPLE_PER_SYMBOL) - j - 1] * tmp_phy_bit_over_sampling_int8[i + j];
|
||||
}
|
||||
|
||||
tmp = (tmp + acc) & 1023;
|
||||
sample[(i + 1) * 2 + 0] = cos_table_int8[tmp];
|
||||
sample[(i + 1) * 2 + 1] = sin_table_int8[tmp];
|
||||
}
|
||||
|
||||
return (num_sample);
|
||||
}
|
||||
|
||||
void BTLETxProcessor::octet_hex_to_bit(char* hex, char* bit) {
|
||||
char tmp_hex[3];
|
||||
|
||||
tmp_hex[0] = hex[0];
|
||||
tmp_hex[1] = hex[1];
|
||||
tmp_hex[2] = 0;
|
||||
|
||||
int n = strtol(tmp_hex, NULL, 16);
|
||||
|
||||
bit[0] = 0x01 & (n >> 0);
|
||||
bit[1] = 0x01 & (n >> 1);
|
||||
bit[2] = 0x01 & (n >> 2);
|
||||
bit[3] = 0x01 & (n >> 3);
|
||||
bit[4] = 0x01 & (n >> 4);
|
||||
bit[5] = 0x01 & (n >> 5);
|
||||
bit[6] = 0x01 & (n >> 6);
|
||||
bit[7] = 0x01 & (n >> 7);
|
||||
}
|
||||
|
||||
int BTLETxProcessor::convert_hex_to_bit(char* hex, char* bit, int stream_flip, int octet_limit) {
|
||||
int num_hex_orig = strlen(hex);
|
||||
|
||||
int i, num_hex;
|
||||
num_hex = num_hex_orig;
|
||||
for (i = 0; i < num_hex_orig; i++) {
|
||||
if (!((hex[i] >= 48 && hex[i] <= 57) || (hex[i] >= 65 && hex[i] <= 70) || (hex[i] >= 97 && hex[i] <= 102))) // not a hex
|
||||
num_hex--;
|
||||
}
|
||||
|
||||
if (num_hex % 2 != 0) {
|
||||
return (-1);
|
||||
}
|
||||
|
||||
if (num_hex > (octet_limit * 2)) {
|
||||
return (-1);
|
||||
}
|
||||
if (num_hex <= 1) { // NULL data
|
||||
return (-1);
|
||||
}
|
||||
|
||||
char tmp_str[max_char];
|
||||
|
||||
if (stream_flip == 1) {
|
||||
strcpy(tmp_str, hex);
|
||||
for (i = 0; i < num_hex; i = i + 2) {
|
||||
hex[num_hex - i - 2] = tmp_str[i];
|
||||
hex[num_hex - i - 1] = tmp_str[i + 1];
|
||||
}
|
||||
}
|
||||
|
||||
int num_bit = num_hex * 4;
|
||||
|
||||
int j;
|
||||
for (i = 0; i < num_hex; i = i + 2) {
|
||||
j = i * 4;
|
||||
octet_hex_to_bit(hex + i, bit + j);
|
||||
}
|
||||
|
||||
return (num_bit);
|
||||
}
|
||||
|
||||
void BTLETxProcessor::crc24(char* bit_in, int num_bit, char* init_hex, char* crc_result) {
|
||||
char bit_store[24], bit_store_update[24];
|
||||
int i;
|
||||
convert_hex_to_bit(init_hex, bit_store, 0, 3);
|
||||
|
||||
for (i = 0; i < num_bit; i++) {
|
||||
char new_bit = (bit_store[23] + bit_in[i]) % 2;
|
||||
bit_store_update[0] = new_bit;
|
||||
bit_store_update[1] = (bit_store[0] + new_bit) % 2;
|
||||
bit_store_update[2] = bit_store[1];
|
||||
bit_store_update[3] = (bit_store[2] + new_bit) % 2;
|
||||
bit_store_update[4] = (bit_store[3] + new_bit) % 2;
|
||||
bit_store_update[5] = bit_store[4];
|
||||
bit_store_update[6] = (bit_store[5] + new_bit) % 2;
|
||||
|
||||
bit_store_update[7] = bit_store[6];
|
||||
bit_store_update[8] = bit_store[7];
|
||||
|
||||
bit_store_update[9] = (bit_store[8] + new_bit) % 2;
|
||||
bit_store_update[10] = (bit_store[9] + new_bit) % 2;
|
||||
|
||||
memcpy(bit_store_update + 11, bit_store + 10, 13);
|
||||
|
||||
memcpy(bit_store, bit_store_update, 24);
|
||||
}
|
||||
|
||||
for (i = 0; i < 24; i++) {
|
||||
crc_result[i] = bit_store[23 - i];
|
||||
}
|
||||
}
|
||||
|
||||
void BTLETxProcessor::scramble(char* bit_in, int num_bit, int channel_number, char* bit_out) {
|
||||
char bit_store[7], bit_store_update[7];
|
||||
int i;
|
||||
|
||||
bit_store[0] = 1;
|
||||
bit_store[1] = 0x01 & (channel_number >> 5);
|
||||
bit_store[2] = 0x01 & (channel_number >> 4);
|
||||
bit_store[3] = 0x01 & (channel_number >> 3);
|
||||
bit_store[4] = 0x01 & (channel_number >> 2);
|
||||
bit_store[5] = 0x01 & (channel_number >> 1);
|
||||
bit_store[6] = 0x01 & (channel_number >> 0);
|
||||
|
||||
for (i = 0; i < num_bit; i++) {
|
||||
bit_out[i] = (bit_store[6] + bit_in[i]) % 2;
|
||||
|
||||
bit_store_update[0] = bit_store[6];
|
||||
|
||||
bit_store_update[1] = bit_store[0];
|
||||
bit_store_update[2] = bit_store[1];
|
||||
bit_store_update[3] = bit_store[2];
|
||||
|
||||
bit_store_update[4] = (bit_store[3] + bit_store[6]) % 2;
|
||||
|
||||
bit_store_update[5] = bit_store[4];
|
||||
bit_store_update[6] = bit_store[5];
|
||||
|
||||
memcpy(bit_store, bit_store_update, 7);
|
||||
}
|
||||
}
|
||||
|
||||
void BTLETxProcessor::disp_bit_in_hex(char* bit, int num_bit) {
|
||||
int i, a;
|
||||
|
||||
for (i = 0; i < num_bit; i = i + 8) {
|
||||
a = bit[i] + bit[i + 1] * 2 + bit[i + 2] * 4 + bit[i + 3] * 8 + bit[i + 4] * 16 + bit[i + 5] * 32 + bit[i + 6] * 64 + bit[i + 7] * 128;
|
||||
|
||||
data_message.is_data = true;
|
||||
data_message.value = (uint8_t)a;
|
||||
shared_memory.application_queue.push(data_message);
|
||||
}
|
||||
}
|
||||
|
||||
void BTLETxProcessor::crc24_and_scramble_to_gen_phy_bit(char* crc_init_hex, PKT_INFO* pkt) {
|
||||
crc24(pkt->info_bit + 5 * 8, pkt->num_info_bit - 5 * 8, crc_init_hex, pkt->info_bit + pkt->num_info_bit);
|
||||
|
||||
// disp_bit_in_hex(pkt->info_bit, pkt->num_info_bit + 3*8);
|
||||
|
||||
scramble(pkt->info_bit + 5 * 8, pkt->num_info_bit - 5 * 8 + 24, pkt->channel_number, pkt->phy_bit + 5 * 8);
|
||||
memcpy(pkt->phy_bit, pkt->info_bit, 5 * 8);
|
||||
pkt->num_phy_bit = pkt->num_info_bit + 24;
|
||||
|
||||
// disp_bit_in_hex(pkt->phy_bit, pkt->num_phy_bit);
|
||||
}
|
||||
|
||||
void BTLETxProcessor::fill_adv_pdu_header(PKT_INFO* pkt, int txadd, int rxadd, int payload_len, char* bit_out) {
|
||||
if (pkt->pkt_type == ADV_IND || pkt->pkt_type == IBEACON) {
|
||||
bit_out[3] = 0;
|
||||
bit_out[2] = 0;
|
||||
bit_out[1] = 0;
|
||||
bit_out[0] = 0;
|
||||
} else if (pkt->pkt_type == ADV_DIRECT_IND) {
|
||||
bit_out[3] = 0;
|
||||
bit_out[2] = 0;
|
||||
bit_out[1] = 0;
|
||||
bit_out[0] = 1;
|
||||
} else if (pkt->pkt_type == ADV_NONCONN_IND || pkt->pkt_type == DISCOVERY) {
|
||||
bit_out[3] = 0;
|
||||
bit_out[2] = 0;
|
||||
bit_out[1] = 1;
|
||||
bit_out[0] = 0;
|
||||
} else if (pkt->pkt_type == SCAN_REQ) {
|
||||
bit_out[3] = 0;
|
||||
bit_out[2] = 0;
|
||||
bit_out[1] = 1;
|
||||
bit_out[0] = 1;
|
||||
} else if (pkt->pkt_type == SCAN_RSP) {
|
||||
bit_out[3] = 0;
|
||||
bit_out[2] = 1;
|
||||
bit_out[1] = 0;
|
||||
bit_out[0] = 0;
|
||||
} else if (pkt->pkt_type == CONNECT_REQ) {
|
||||
bit_out[3] = 0;
|
||||
bit_out[2] = 1;
|
||||
bit_out[1] = 0;
|
||||
bit_out[0] = 1;
|
||||
} else if (pkt->pkt_type == ADV_SCAN_IND) {
|
||||
bit_out[3] = 0;
|
||||
bit_out[2] = 1;
|
||||
bit_out[1] = 1;
|
||||
bit_out[0] = 0;
|
||||
} else {
|
||||
bit_out[3] = 1;
|
||||
bit_out[2] = 1;
|
||||
bit_out[1] = 1;
|
||||
bit_out[0] = 1;
|
||||
}
|
||||
|
||||
bit_out[4] = 0;
|
||||
bit_out[5] = 0;
|
||||
|
||||
bit_out[6] = txadd;
|
||||
bit_out[7] = rxadd;
|
||||
|
||||
bit_out[8] = 0x01 & (payload_len >> 0);
|
||||
bit_out[9] = 0x01 & (payload_len >> 1);
|
||||
bit_out[10] = 0x01 & (payload_len >> 2);
|
||||
bit_out[11] = 0x01 & (payload_len >> 3);
|
||||
bit_out[12] = 0x01 & (payload_len >> 4);
|
||||
bit_out[13] = 0x01 & (payload_len >> 5);
|
||||
|
||||
bit_out[14] = 0;
|
||||
bit_out[15] = 0;
|
||||
}
|
||||
|
||||
int BTLETxProcessor::calculate_sample_for_ADV(PKT_INFO* pkt) {
|
||||
pkt->num_info_bit = 0;
|
||||
|
||||
// gen preamble and access address
|
||||
const char* AA = "AA";
|
||||
const char* AAValue = "D6BE898E";
|
||||
pkt->num_info_bit = pkt->num_info_bit + convert_hex_to_bit((char*)AA, pkt->info_bit, 0, 1);
|
||||
pkt->num_info_bit = pkt->num_info_bit + convert_hex_to_bit((char*)AAValue, pkt->info_bit + pkt->num_info_bit, 0, 4);
|
||||
|
||||
// get txadd and rxadd
|
||||
int txadd = 0, rxadd = 0;
|
||||
|
||||
pkt->num_info_bit = pkt->num_info_bit + 16; // 16 is header length
|
||||
|
||||
// get AdvA and AdvData
|
||||
pkt->num_info_bit = pkt->num_info_bit + convert_hex_to_bit(macAddress, pkt->info_bit + pkt->num_info_bit, 1, 6);
|
||||
|
||||
pkt->num_info_bit = pkt->num_info_bit + convert_hex_to_bit(advertisementData, pkt->info_bit + pkt->num_info_bit, 0, 31);
|
||||
|
||||
int payload_len = (pkt->num_info_bit / 8) - 7;
|
||||
|
||||
fill_adv_pdu_header(pkt, txadd, rxadd, payload_len, pkt->info_bit + 5 * 8);
|
||||
const char* checksumInit = "555555";
|
||||
crc24_and_scramble_to_gen_phy_bit((char*)checksumInit, pkt);
|
||||
|
||||
#ifdef new_way
|
||||
pkt->num_phy_sample = gen_sample_from_phy_bit(pkt->phy_bit, pkt->phy_sample, pkt->num_phy_bit);
|
||||
#endif
|
||||
|
||||
// disp_bit_in_hex(pkt->phy_sample, pkt->num_phy_sample);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
int BTLETxProcessor::calculate_sample_from_pkt_type(PKT_INFO* pkt) {
|
||||
// Todo: Handle other Enum values.
|
||||
// if (packetType == ADV_IND);
|
||||
|
||||
if (calculate_sample_for_ADV(pkt) == -1) {
|
||||
return (-1);
|
||||
}
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
int BTLETxProcessor::calculate_pkt_info(PKT_INFO* pkt) {
|
||||
if (calculate_sample_from_pkt_type(pkt) == -1) {
|
||||
return (-1);
|
||||
}
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
void BTLETxProcessor::execute(const buffer_c8_t& buffer) {
|
||||
int8_t re, im;
|
||||
|
||||
// This is called at 4M/2048 = 1953Hz
|
||||
for (size_t i = 0; i < buffer.count; i++) {
|
||||
if (configured) {
|
||||
// This is going to loop through each sample bit and push it to the output buffer.
|
||||
if (sample_count > length) {
|
||||
configured = false;
|
||||
sample_count = 0;
|
||||
} else {
|
||||
// Real and imaginary was already calculated in gen_sample_from_phy_bit.
|
||||
// It was processed from each data bit, run through a Gaussian Filter, and then ran through sin and cos table to get each IQ bit.
|
||||
re = (int8_t)packets.phy_sample[sample_count++];
|
||||
im = (int8_t)packets.phy_sample[sample_count++];
|
||||
|
||||
buffer.p[i] = {re, im};
|
||||
|
||||
if (progress_count >= progress_notice) {
|
||||
progress_count = 0;
|
||||
txprogress_message.progress++;
|
||||
txprogress_message.done = false;
|
||||
shared_memory.application_queue.push(txprogress_message);
|
||||
} else {
|
||||
progress_count++;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
re = 0;
|
||||
im = 0;
|
||||
|
||||
buffer.p[i] = {re, im};
|
||||
}
|
||||
}
|
||||
|
||||
txprogress_message.done = true;
|
||||
shared_memory.application_queue.push(txprogress_message);
|
||||
}
|
||||
|
||||
void BTLETxProcessor::on_message(const Message* const message) {
|
||||
if (message->id == Message::ID::BTLETxConfigure) {
|
||||
configure(*reinterpret_cast<const BTLETxConfigureMessage*>(message));
|
||||
}
|
||||
}
|
||||
|
||||
void BTLETxProcessor::configure(const BTLETxConfigureMessage& message) {
|
||||
channel_number = message.channel_number;
|
||||
packetType = (PKT_TYPE)message.pduType;
|
||||
|
||||
memcpy(macAddress, message.macAddress, sizeof(macAddress));
|
||||
memcpy(advertisementData, message.advertisementData, sizeof(advertisementData));
|
||||
|
||||
packets.channel_number = channel_number;
|
||||
packets.pkt_type = packetType;
|
||||
|
||||
// Calculates the samples based on the BLE packet data and generates IQ values into an array to be sent out.
|
||||
calculate_pkt_info(&packets);
|
||||
|
||||
#ifdef new_way
|
||||
// This is because each sample contains I and Q, but packet.num_phy_samples just returns the total samples.
|
||||
length = (uint32_t)(packets.num_phy_sample * 2);
|
||||
#else
|
||||
length = (uint32_t)packets.num_phy_bit;
|
||||
#endif
|
||||
|
||||
// Starting at sample_count 0 since packets.num_phy_sample contains every sample needed to be sent out.
|
||||
sample_count = 0;
|
||||
progress_count = 0;
|
||||
progress_notice = 64;
|
||||
|
||||
txprogress_message.progress = 0;
|
||||
txprogress_message.done = false;
|
||||
configured = true;
|
||||
}
|
||||
|
||||
int main() {
|
||||
EventDispatcher event_dispatcher{std::make_unique<BTLETxProcessor>()};
|
||||
event_dispatcher.run();
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,240 @@
|
||||
/*
|
||||
* Copyright (C) 2014 Jared Boone, ShareBrained Technology, Inc.
|
||||
* Copyright (C) 2016 Furrtek
|
||||
* Copyright (C) 2023 TJ Baginski
|
||||
*
|
||||
* 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 __PROC_BLE_TX_H__
|
||||
#define __PROC_BLE_TX_H__
|
||||
|
||||
#include "baseband_processor.hpp"
|
||||
#include "baseband_thread.hpp"
|
||||
|
||||
class BTLETxProcessor : public BasebandProcessor {
|
||||
public:
|
||||
void execute(const buffer_c8_t& buffer) override;
|
||||
void on_message(const Message* const message) override;
|
||||
void configure(const BTLETxConfigureMessage& message);
|
||||
|
||||
private:
|
||||
static constexpr int max_char{256};
|
||||
static constexpr int SAMPLE_PER_SYMBOL{4};
|
||||
static constexpr float AMPLITUDE{127.0};
|
||||
static constexpr float MOD_IDX{0.5};
|
||||
static constexpr int LEN_GAUSS_FILTER{4};
|
||||
static constexpr int MAX_NUM_INFO_BYTE{43};
|
||||
static constexpr int MAX_NUM_PHY_BYTE{47};
|
||||
static constexpr int MAX_NUM_PHY_SAMPLE{(MAX_NUM_PHY_BYTE * 8 * SAMPLE_PER_SYMBOL) + (LEN_GAUSS_FILTER * SAMPLE_PER_SYMBOL)};
|
||||
|
||||
enum PKT_TYPE {
|
||||
INVALID_TYPE,
|
||||
RAW,
|
||||
DISCOVERY,
|
||||
IBEACON,
|
||||
ADV_IND,
|
||||
ADV_DIRECT_IND,
|
||||
ADV_NONCONN_IND,
|
||||
ADV_SCAN_IND,
|
||||
SCAN_REQ,
|
||||
SCAN_RSP,
|
||||
CONNECT_REQ,
|
||||
LL_DATA,
|
||||
LL_CONNECTION_UPDATE_REQ,
|
||||
LL_CHANNEL_MAP_REQ,
|
||||
LL_TERMINATE_IND,
|
||||
LL_ENC_REQ,
|
||||
LL_ENC_RSP,
|
||||
LL_START_ENC_REQ,
|
||||
LL_START_ENC_RSP,
|
||||
LL_UNKNOWN_RSP,
|
||||
LL_FEATURE_REQ,
|
||||
LL_FEATURE_RSP,
|
||||
LL_PAUSE_ENC_REQ,
|
||||
LL_PAUSE_ENC_RSP,
|
||||
LL_VERSION_IND,
|
||||
LL_REJECT_IND,
|
||||
NUM_PKT_TYPE
|
||||
};
|
||||
|
||||
struct PKT_INFO {
|
||||
int channel_number;
|
||||
PKT_TYPE pkt_type;
|
||||
|
||||
int num_info_bit;
|
||||
char info_bit[MAX_NUM_PHY_BYTE * 8]; // without CRC and whitening
|
||||
|
||||
int num_info_byte;
|
||||
uint8_t info_byte[MAX_NUM_PHY_BYTE];
|
||||
|
||||
int num_phy_bit;
|
||||
char phy_bit[MAX_NUM_PHY_BYTE * 8]; // all bits which will be fed to GFSK modulator
|
||||
|
||||
int num_phy_byte;
|
||||
uint8_t phy_byte[MAX_NUM_PHY_BYTE];
|
||||
|
||||
int num_phy_sample;
|
||||
char phy_sample[2 * MAX_NUM_PHY_SAMPLE]; // GFSK output to D/A (hackrf board)
|
||||
int8_t phy_sample1[2 * MAX_NUM_PHY_SAMPLE]; // GFSK output to D/A (hackrf board)
|
||||
|
||||
int space; // how many millisecond null signal shouwl be padded after this packet
|
||||
};
|
||||
|
||||
PKT_INFO packets{};
|
||||
|
||||
int calculate_pkt_info(PKT_INFO* pkt);
|
||||
int calculate_sample_from_pkt_type(PKT_INFO* pkt);
|
||||
int calculate_sample_for_ADV(PKT_INFO* pkt);
|
||||
void fill_adv_pdu_header(PKT_INFO* pkt, int txadd, int rxadd, int payload_len, char* bit_out);
|
||||
void crc24_and_scramble_to_gen_phy_bit(char* crc_init_hex, PKT_INFO* pkt);
|
||||
void disp_bit_in_hex(char* bit, int num_bit);
|
||||
void scramble(char* bit_in, int num_bit, int channel_number, char* bit_out);
|
||||
void crc24(char* bit_in, int num_bit, char* init_hex, char* crc_result);
|
||||
int convert_hex_to_bit(char* hex, char* bit, int stream_flip, int octet_limit);
|
||||
void octet_hex_to_bit(char* hex, char* bit);
|
||||
int gen_sample_from_phy_bit(char* bit, char* sample, int num_bit);
|
||||
bool configured = false;
|
||||
|
||||
float tmp_phy_bit_over_sampling[MAX_NUM_PHY_SAMPLE + 2 * LEN_GAUSS_FILTER * SAMPLE_PER_SYMBOL];
|
||||
float gauss_coef[LEN_GAUSS_FILTER * SAMPLE_PER_SYMBOL] = {7.561773e-09, 1.197935e-06, 8.050684e-05, 2.326833e-03, 2.959908e-02, 1.727474e-01, 4.999195e-01, 8.249246e-01, 9.408018e-01, 8.249246e-01, 4.999195e-01, 1.727474e-01, 2.959908e-02, 2.326833e-03, 8.050684e-05, 1.197935e-06};
|
||||
|
||||
uint32_t samples_per_bit{4};
|
||||
uint32_t channel_number{37};
|
||||
char macAddress[13] = "FFFFFFFFFF";
|
||||
char advertisementData[63] = {0};
|
||||
|
||||
uint32_t length{0};
|
||||
uint32_t shift_zero{}, shift_one{};
|
||||
uint32_t progress_notice{}, progress_count{0};
|
||||
uint32_t sample_count{0};
|
||||
uint32_t phase{0}, sphase{0};
|
||||
|
||||
uint8_t cur_bit{0};
|
||||
uint16_t bit_pos{0};
|
||||
|
||||
uint16_t process{0};
|
||||
|
||||
// clang-format off
|
||||
const int8_t gauss_coef_int8[16] = {
|
||||
0, 0, 0, 0, 2, 11, 32, 53, 60, 53, 32, 11, 2, 0, 0, 0, };
|
||||
|
||||
const int8_t cos_table_int8[1024] = {
|
||||
127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 126, 126, 126, 126, 126, 126, 126, 126, 126,
|
||||
126, 126, 125, 125, 125, 125, 125, 125, 125, 124, 124, 124, 124, 124, 124, 123, 123, 123, 123, 123, 122, 122, 122, 122,
|
||||
122, 121, 121, 121, 121, 120, 120, 120, 120, 119, 119, 119, 118, 118, 118, 118, 117, 117, 117, 116, 116, 116, 115, 115,
|
||||
115, 114, 114, 114, 113, 113, 113, 112, 112, 112, 111, 111, 111, 110, 110, 109, 109, 109, 108, 108, 107, 107, 106, 106,
|
||||
106, 105, 105, 104, 104, 103, 103, 102, 102, 102, 101, 101, 100, 100, 99, 99, 98, 98, 97, 97, 96, 96, 95, 95,
|
||||
94, 94, 93, 93, 92, 91, 91, 90, 90, 89, 89, 88, 88, 87, 86, 86, 85, 85, 84, 84, 83, 82, 82, 81,
|
||||
81, 80, 79, 79, 78, 78, 77, 76, 76, 75, 74, 74, 73, 72, 72, 71, 71, 70, 69, 69, 68, 67, 67, 66,
|
||||
65, 65, 64, 63, 63, 62, 61, 61, 60, 59, 58, 58, 57, 56, 56, 55, 54, 54, 53, 52, 51, 51, 50, 49,
|
||||
49, 48, 47, 46, 46, 45, 44, 44, 43, 42, 41, 41, 40, 39, 38, 38, 37, 36, 35, 35, 34, 33, 32, 32,
|
||||
31, 30, 29, 29, 28, 27, 26, 26, 25, 24, 23, 22, 22, 21, 20, 19, 19, 18, 17, 16, 16, 15, 14, 13,
|
||||
12, 12, 11, 10, 9, 9, 8, 7, 6, 5, 5, 4, 3, 2, 2, 1, 0, -1, -2, -2, -3, -4, -5, -5,
|
||||
-6, -7, -8, -9, -9, -10, -11, -12, -12, -13, -14, -15, -16, -16, -17, -18, -19, -19, -20, -21, -22, -22, -23, -24,
|
||||
-25, -26, -26, -27, -28, -29, -29, -30, -31, -32, -32, -33, -34, -35, -35, -36, -37, -38, -38, -39, -40, -41, -41, -42,
|
||||
-43, -44, -44, -45, -46, -46, -47, -48, -49, -49, -50, -51, -51, -52, -53, -54, -54, -55, -56, -56, -57, -58, -58, -59,
|
||||
-60, -61, -61, -62, -63, -63, -64, -65, -65, -66, -67, -67, -68, -69, -69, -70, -71, -71, -72, -72, -73, -74, -74, -75,
|
||||
-76, -76, -77, -78, -78, -79, -79, -80, -81, -81, -82, -82, -83, -84, -84, -85, -85, -86, -86, -87, -88, -88, -89, -89,
|
||||
-90, -90, -91, -91, -92, -93, -93, -94, -94, -95, -95, -96, -96, -97, -97, -98, -98, -99, -99, -100, -100, -101, -101, -102,
|
||||
-102, -102, -103, -103, -104, -104, -105, -105, -106, -106, -106, -107, -107, -108, -108, -109, -109, -109, -110, -110, -111, -111, -111, -112,
|
||||
-112, -112, -113, -113, -113, -114, -114, -114, -115, -115, -115, -116, -116, -116, -117, -117, -117, -118, -118, -118, -118, -119, -119, -119,
|
||||
-120, -120, -120, -120, -121, -121, -121, -121, -122, -122, -122, -122, -122, -123, -123, -123, -123, -123, -124, -124, -124, -124, -124, -124,
|
||||
-125, -125, -125, -125, -125, -125, -125, -126, -126, -126, -126, -126, -126, -126, -126, -126, -126, -126, -127, -127, -127, -127, -127, -127,
|
||||
-127, -127, -127, -127, -127, -127, -127, -127, -127, -127, -127, -127, -127, -127, -127, -127, -127, -127, -127, -127, -127, -127, -127, -126,
|
||||
-126, -126, -126, -126, -126, -126, -126, -126, -126, -126, -125, -125, -125, -125, -125, -125, -125, -124, -124, -124, -124, -124, -124, -123,
|
||||
-123, -123, -123, -123, -122, -122, -122, -122, -122, -121, -121, -121, -121, -120, -120, -120, -120, -119, -119, -119, -118, -118, -118, -118,
|
||||
-117, -117, -117, -116, -116, -116, -115, -115, -115, -114, -114, -114, -113, -113, -113, -112, -112, -112, -111, -111, -111, -110, -110, -109,
|
||||
-109, -109, -108, -108, -107, -107, -106, -106, -106, -105, -105, -104, -104, -103, -103, -102, -102, -102, -101, -101, -100, -100, -99, -99,
|
||||
-98, -98, -97, -97, -96, -96, -95, -95, -94, -94, -93, -93, -92, -91, -91, -90, -90, -89, -89, -88, -88, -87, -86, -86,
|
||||
-85, -85, -84, -84, -83, -82, -82, -81, -81, -80, -79, -79, -78, -78, -77, -76, -76, -75, -74, -74, -73, -72, -72, -71,
|
||||
-71, -70, -69, -69, -68, -67, -67, -66, -65, -65, -64, -63, -63, -62, -61, -61, -60, -59, -58, -58, -57, -56, -56, -55,
|
||||
-54, -54, -53, -52, -51, -51, -50, -49, -49, -48, -47, -46, -46, -45, -44, -44, -43, -42, -41, -41, -40, -39, -38, -38,
|
||||
-37, -36, -35, -35, -34, -33, -32, -32, -31, -30, -29, -29, -28, -27, -26, -26, -25, -24, -23, -22, -22, -21, -20, -19,
|
||||
-19, -18, -17, -16, -16, -15, -14, -13, -12, -12, -11, -10, -9, -9, -8, -7, -6, -5, -5, -4, -3, -2, -2, -1,
|
||||
0, 1, 2, 2, 3, 4, 5, 5, 6, 7, 8, 9, 9, 10, 11, 12, 12, 13, 14, 15, 16, 16, 17, 18,
|
||||
19, 19, 20, 21, 22, 22, 23, 24, 25, 26, 26, 27, 28, 29, 29, 30, 31, 32, 32, 33, 34, 35, 35, 36,
|
||||
37, 38, 38, 39, 40, 41, 41, 42, 43, 44, 44, 45, 46, 46, 47, 48, 49, 49, 50, 51, 51, 52, 53, 54,
|
||||
54, 55, 56, 56, 57, 58, 58, 59, 60, 61, 61, 62, 63, 63, 64, 65, 65, 66, 67, 67, 68, 69, 69, 70,
|
||||
71, 71, 72, 72, 73, 74, 74, 75, 76, 76, 77, 78, 78, 79, 79, 80, 81, 81, 82, 82, 83, 84, 84, 85,
|
||||
85, 86, 86, 87, 88, 88, 89, 89, 90, 90, 91, 91, 92, 93, 93, 94, 94, 95, 95, 96, 96, 97, 97, 98,
|
||||
98, 99, 99, 100, 100, 101, 101, 102, 102, 102, 103, 103, 104, 104, 105, 105, 106, 106, 106, 107, 107, 108, 108, 109,
|
||||
109, 109, 110, 110, 111, 111, 111, 112, 112, 112, 113, 113, 113, 114, 114, 114, 115, 115, 115, 116, 116, 116, 117, 117,
|
||||
117, 118, 118, 118, 118, 119, 119, 119, 120, 120, 120, 120, 121, 121, 121, 121, 122, 122, 122, 122, 122, 123, 123, 123,
|
||||
123, 123, 124, 124, 124, 124, 124, 124, 125, 125, 125, 125, 125, 125, 125, 126, 126, 126, 126, 126, 126, 126, 126, 126,
|
||||
126, 126, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, };
|
||||
|
||||
const int8_t sin_table_int8[1024] = {
|
||||
0, 1, 2, 2, 3, 4, 5, 5, 6, 7, 8, 9, 9, 10, 11, 12, 12, 13, 14, 15, 16, 16, 17, 18,
|
||||
19, 19, 20, 21, 22, 22, 23, 24, 25, 26, 26, 27, 28, 29, 29, 30, 31, 32, 32, 33, 34, 35, 35, 36,
|
||||
37, 38, 38, 39, 40, 41, 41, 42, 43, 44, 44, 45, 46, 46, 47, 48, 49, 49, 50, 51, 51, 52, 53, 54,
|
||||
54, 55, 56, 56, 57, 58, 58, 59, 60, 61, 61, 62, 63, 63, 64, 65, 65, 66, 67, 67, 68, 69, 69, 70,
|
||||
71, 71, 72, 72, 73, 74, 74, 75, 76, 76, 77, 78, 78, 79, 79, 80, 81, 81, 82, 82, 83, 84, 84, 85,
|
||||
85, 86, 86, 87, 88, 88, 89, 89, 90, 90, 91, 91, 92, 93, 93, 94, 94, 95, 95, 96, 96, 97, 97, 98,
|
||||
98, 99, 99, 100, 100, 101, 101, 102, 102, 102, 103, 103, 104, 104, 105, 105, 106, 106, 106, 107, 107, 108, 108, 109,
|
||||
109, 109, 110, 110, 111, 111, 111, 112, 112, 112, 113, 113, 113, 114, 114, 114, 115, 115, 115, 116, 116, 116, 117, 117,
|
||||
117, 118, 118, 118, 118, 119, 119, 119, 120, 120, 120, 120, 121, 121, 121, 121, 122, 122, 122, 122, 122, 123, 123, 123,
|
||||
123, 123, 124, 124, 124, 124, 124, 124, 125, 125, 125, 125, 125, 125, 125, 126, 126, 126, 126, 126, 126, 126, 126, 126,
|
||||
126, 126, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127,
|
||||
127, 127, 127, 127, 127, 127, 127, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 125, 125, 125, 125, 125, 125,
|
||||
125, 124, 124, 124, 124, 124, 124, 123, 123, 123, 123, 123, 122, 122, 122, 122, 122, 121, 121, 121, 121, 120, 120, 120,
|
||||
120, 119, 119, 119, 118, 118, 118, 118, 117, 117, 117, 116, 116, 116, 115, 115, 115, 114, 114, 114, 113, 113, 113, 112,
|
||||
112, 112, 111, 111, 111, 110, 110, 109, 109, 109, 108, 108, 107, 107, 106, 106, 106, 105, 105, 104, 104, 103, 103, 102,
|
||||
102, 102, 101, 101, 100, 100, 99, 99, 98, 98, 97, 97, 96, 96, 95, 95, 94, 94, 93, 93, 92, 91, 91, 90,
|
||||
90, 89, 89, 88, 88, 87, 86, 86, 85, 85, 84, 84, 83, 82, 82, 81, 81, 80, 79, 79, 78, 78, 77, 76,
|
||||
76, 75, 74, 74, 73, 72, 72, 71, 71, 70, 69, 69, 68, 67, 67, 66, 65, 65, 64, 63, 63, 62, 61, 61,
|
||||
60, 59, 58, 58, 57, 56, 56, 55, 54, 54, 53, 52, 51, 51, 50, 49, 49, 48, 47, 46, 46, 45, 44, 44,
|
||||
43, 42, 41, 41, 40, 39, 38, 38, 37, 36, 35, 35, 34, 33, 32, 32, 31, 30, 29, 29, 28, 27, 26, 26,
|
||||
25, 24, 23, 22, 22, 21, 20, 19, 19, 18, 17, 16, 16, 15, 14, 13, 12, 12, 11, 10, 9, 9, 8, 7,
|
||||
6, 5, 5, 4, 3, 2, 2, 1, 0, -1, -2, -2, -3, -4, -5, -5, -6, -7, -8, -9, -9, -10, -11, -12,
|
||||
-12, -13, -14, -15, -16, -16, -17, -18, -19, -19, -20, -21, -22, -22, -23, -24, -25, -26, -26, -27, -28, -29, -29, -30,
|
||||
-31, -32, -32, -33, -34, -35, -35, -36, -37, -38, -38, -39, -40, -41, -41, -42, -43, -44, -44, -45, -46, -46, -47, -48,
|
||||
-49, -49, -50, -51, -51, -52, -53, -54, -54, -55, -56, -56, -57, -58, -58, -59, -60, -61, -61, -62, -63, -63, -64, -65,
|
||||
-65, -66, -67, -67, -68, -69, -69, -70, -71, -71, -72, -72, -73, -74, -74, -75, -76, -76, -77, -78, -78, -79, -79, -80,
|
||||
-81, -81, -82, -82, -83, -84, -84, -85, -85, -86, -86, -87, -88, -88, -89, -89, -90, -90, -91, -91, -92, -93, -93, -94,
|
||||
-94, -95, -95, -96, -96, -97, -97, -98, -98, -99, -99, -100, -100, -101, -101, -102, -102, -102, -103, -103, -104, -104, -105, -105,
|
||||
-106, -106, -106, -107, -107, -108, -108, -109, -109, -109, -110, -110, -111, -111, -111, -112, -112, -112, -113, -113, -113, -114, -114, -114,
|
||||
-115, -115, -115, -116, -116, -116, -117, -117, -117, -118, -118, -118, -118, -119, -119, -119, -120, -120, -120, -120, -121, -121, -121, -121,
|
||||
-122, -122, -122, -122, -122, -123, -123, -123, -123, -123, -124, -124, -124, -124, -124, -124, -125, -125, -125, -125, -125, -125, -125, -126,
|
||||
-126, -126, -126, -126, -126, -126, -126, -126, -126, -126, -127, -127, -127, -127, -127, -127, -127, -127, -127, -127, -127, -127, -127, -127,
|
||||
-127, -127, -127, -127, -127, -127, -127, -127, -127, -127, -127, -127, -127, -127, -127, -126, -126, -126, -126, -126, -126, -126, -126, -126,
|
||||
-126, -126, -125, -125, -125, -125, -125, -125, -125, -124, -124, -124, -124, -124, -124, -123, -123, -123, -123, -123, -122, -122, -122, -122,
|
||||
-122, -121, -121, -121, -121, -120, -120, -120, -120, -119, -119, -119, -118, -118, -118, -118, -117, -117, -117, -116, -116, -116, -115, -115,
|
||||
-115, -114, -114, -114, -113, -113, -113, -112, -112, -112, -111, -111, -111, -110, -110, -109, -109, -109, -108, -108, -107, -107, -106, -106,
|
||||
-106, -105, -105, -104, -104, -103, -103, -102, -102, -102, -101, -101, -100, -100, -99, -99, -98, -98, -97, -97, -96, -96, -95, -95,
|
||||
-94, -94, -93, -93, -92, -91, -91, -90, -90, -89, -89, -88, -88, -87, -86, -86, -85, -85, -84, -84, -83, -82, -82, -81,
|
||||
-81, -80, -79, -79, -78, -78, -77, -76, -76, -75, -74, -74, -73, -72, -72, -71, -71, -70, -69, -69, -68, -67, -67, -66,
|
||||
-65, -65, -64, -63, -63, -62, -61, -61, -60, -59, -58, -58, -57, -56, -56, -55, -54, -54, -53, -52, -51, -51, -50, -49,
|
||||
-49, -48, -47, -46, -46, -45, -44, -44, -43, -42, -41, -41, -40, -39, -38, -38, -37, -36, -35, -35, -34, -33, -32, -32,
|
||||
-31, -30, -29, -29, -28, -27, -26, -26, -25, -24, -23, -22, -22, -21, -20, -19, -19, -18, -17, -16, -16, -15, -14, -13,
|
||||
-12, -12, -11, -10, -9, -9, -8, -7, -6, -5, -5, -4, -3, -2, -2, -1, };
|
||||
// clang-format on
|
||||
|
||||
PKT_TYPE packetType = ADV_IND;
|
||||
|
||||
TXProgressMessage txprogress_message{};
|
||||
|
||||
/* NB: Threads should be the last members in the class definition. */
|
||||
|
||||
// BasebandThread baseband_thread{4000000, this, baseband::Direction::Transmit};
|
||||
// Rx for now because trying to test formulation of packet.
|
||||
AFSKDataMessage data_message{false, 0};
|
||||
BasebandThread baseband_thread{4000000, this, baseband::Direction::Transmit};
|
||||
};
|
||||
|
||||
#endif
|
||||
+434
-202
@@ -2,6 +2,7 @@
|
||||
* Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc.
|
||||
* Copyright (C) 2016 Furrtek
|
||||
* Copyright (C) 2020 Shao
|
||||
* Copyright (C) 2023 TJ Baginski
|
||||
*
|
||||
* This file is part of PortaPack.
|
||||
*
|
||||
@@ -26,245 +27,475 @@
|
||||
|
||||
#include "event_m4.hpp"
|
||||
|
||||
uint32_t BTLERxProcessor::crc_init_reorder(uint32_t crc_init) {
|
||||
int i;
|
||||
uint32_t crc_init_tmp, crc_init_input, crc_init_input_tmp;
|
||||
|
||||
crc_init_input_tmp = crc_init;
|
||||
crc_init_input = 0;
|
||||
|
||||
crc_init_input = crc_init_input_tmp & 0xFF;
|
||||
|
||||
crc_init_input_tmp = (crc_init_input_tmp >> 8);
|
||||
crc_init_input = ((crc_init_input << 8) | (crc_init_input_tmp & 0xFF));
|
||||
|
||||
crc_init_input_tmp = (crc_init_input_tmp >> 8);
|
||||
crc_init_input = ((crc_init_input << 8) | (crc_init_input_tmp & 0xFF));
|
||||
|
||||
crc_init_input = (crc_init_input << 1);
|
||||
crc_init_tmp = 0;
|
||||
|
||||
for (i = 0; i < 24; i++) {
|
||||
crc_init_input = (crc_init_input >> 1);
|
||||
crc_init_tmp = ((crc_init_tmp << 1) | (crc_init_input & 0x01));
|
||||
}
|
||||
|
||||
return (crc_init_tmp);
|
||||
}
|
||||
|
||||
uint_fast32_t BTLERxProcessor::crc_update(uint_fast32_t crc, const void* data, size_t data_len) {
|
||||
const unsigned char* d = (const unsigned char*)data;
|
||||
unsigned int tbl_idx;
|
||||
|
||||
while (data_len--) {
|
||||
tbl_idx = (crc ^ *d) & 0xff;
|
||||
crc = (crc_table[tbl_idx] ^ (crc >> 8)) & 0xffffff;
|
||||
|
||||
d++;
|
||||
}
|
||||
|
||||
return crc & 0xffffff;
|
||||
}
|
||||
|
||||
uint_fast32_t BTLERxProcessor::crc24_byte(uint8_t* byte_in, int num_byte, uint32_t init_hex) {
|
||||
uint_fast32_t crc = init_hex;
|
||||
|
||||
crc = crc_update(crc, byte_in, num_byte);
|
||||
|
||||
return (crc);
|
||||
}
|
||||
|
||||
bool BTLERxProcessor::crc_check(uint8_t* tmp_byte, int body_len, uint32_t crc_init) {
|
||||
int crc24_checksum;
|
||||
|
||||
crc24_checksum = crc24_byte(tmp_byte, body_len, crc_init); // 0x555555 --> 0xaaaaaa. maybe because byte order
|
||||
checksumReceived = 0;
|
||||
checksumReceived = ((checksumReceived << 8) | tmp_byte[body_len + 2]);
|
||||
checksumReceived = ((checksumReceived << 8) | tmp_byte[body_len + 1]);
|
||||
checksumReceived = ((checksumReceived << 8) | tmp_byte[body_len + 0]);
|
||||
|
||||
return (crc24_checksum != checksumReceived);
|
||||
}
|
||||
|
||||
void BTLERxProcessor::scramble_byte(uint8_t* byte_in, int num_byte, const uint8_t* scramble_table_byte, uint8_t* byte_out) {
|
||||
int i;
|
||||
|
||||
for (i = 0; i < num_byte; i++) {
|
||||
byte_out[i] = byte_in[i] ^ scramble_table_byte[i];
|
||||
}
|
||||
}
|
||||
|
||||
// void BTLERxProcessor::demod_byte(int num_byte, uint8_t *out_byte)
|
||||
//{
|
||||
// int i, j;
|
||||
// int I0, Q0, I1, Q1;
|
||||
// uint8_t bit_decision;
|
||||
// int sample_idx = 0;
|
||||
|
||||
// for (i = 0; i < num_byte; i++)
|
||||
// {
|
||||
// out_byte[i] = 0;
|
||||
|
||||
// for (j = 0; j < 8; j++)
|
||||
// {
|
||||
// I0 = dst_buffer.p[sample_idx].real();
|
||||
// Q0 = dst_buffer.p[sample_idx].imag();
|
||||
// I1 = dst_buffer.p[sample_idx + 1].real();
|
||||
// Q1 = dst_buffer.p[sample_idx + 1].imag();
|
||||
|
||||
// bit_decision = (I0 * Q1 - I1 * Q0) > 0 ? 1 : 0;
|
||||
|
||||
// out_byte[i] = out_byte[i] | (bit_decision << j);
|
||||
|
||||
// sample_idx += SAMPLE_PER_SYMBOL;;}
|
||||
//}
|
||||
|
||||
int BTLERxProcessor::parse_adv_pdu_payload_byte(uint8_t* payload_byte, int num_payload_byte, ADV_PDU_TYPE pdu_type, void* adv_pdu_payload) {
|
||||
// Should at least have 6 bytes for the MAC Address.
|
||||
// Also ensuring that there is at least 1 byte of data.
|
||||
if (num_payload_byte <= 6) {
|
||||
// printf("Error: Payload Too Short (only %d bytes)!\n", num_payload_byte);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (pdu_type == ADV_IND || pdu_type == ADV_NONCONN_IND || pdu_type == SCAN_RSP || pdu_type == ADV_SCAN_IND) {
|
||||
payload_type_0_2_4_6 = (ADV_PDU_PAYLOAD_TYPE_0_2_4_6*)adv_pdu_payload;
|
||||
|
||||
macAddress[0] = payload_byte[5];
|
||||
macAddress[1] = payload_byte[4];
|
||||
macAddress[2] = payload_byte[3];
|
||||
macAddress[3] = payload_byte[2];
|
||||
macAddress[4] = payload_byte[1];
|
||||
macAddress[5] = payload_byte[0];
|
||||
|
||||
memcpy(payload_type_0_2_4_6->Data, payload_byte + 6, num_payload_byte - 6);
|
||||
}
|
||||
// Only processing advertisments for right now.
|
||||
else {
|
||||
return -1;
|
||||
}
|
||||
// else if (pdu_type == ADV_DIRECT_IND || pdu_type == SCAN_REQ)
|
||||
// {
|
||||
// if (num_payload_byte != 12)
|
||||
// {
|
||||
// //printf("Error: Payload length %d bytes. Need to be 12 for PDU Type %s!\n", num_payload_byte, ADV_PDU_TYPE_STR[pdu_type]);
|
||||
// return(-1);
|
||||
// }
|
||||
|
||||
// payload_type_1_3 = (ADV_PDU_PAYLOAD_TYPE_1_3 *)adv_pdu_payload;
|
||||
|
||||
// //AdvA = reorder_bytes_str( payload_bytes(1 : (2*6)) );
|
||||
// macAddress[0] = payload_byte[5];
|
||||
// macAddress[1] = payload_byte[4];
|
||||
// macAddress[2] = payload_byte[3];
|
||||
// macAddress[3] = payload_byte[2];
|
||||
// macAddress[4] = payload_byte[1];
|
||||
// macAddress[5] = payload_byte[0];
|
||||
|
||||
// //InitA = reorder_bytes_str( payload_bytes((2*6+1):end) );
|
||||
// payload_type_1_3->A1[0] = payload_byte[11];
|
||||
// payload_type_1_3->A1[1] = payload_byte[10];
|
||||
// payload_type_1_3->A1[2] = payload_byte[9];
|
||||
// payload_type_1_3->A1[3] = payload_byte[8];
|
||||
// payload_type_1_3->A1[4] = payload_byte[7];
|
||||
// payload_type_1_3->A1[5] = payload_byte[6];
|
||||
|
||||
// //payload_parse_result_str = ['AdvA:' AdvA ' InitA:' InitA];
|
||||
// }
|
||||
// else if (pdu_type == CONNECT_REQ)
|
||||
// {
|
||||
// if (num_payload_byte != 34)
|
||||
// {
|
||||
// //printf("Error: Payload length %d bytes. Need to be 34 for PDU Type %s!\n", num_payload_byte, ADV_PDU_TYPE_STR[pdu_type]);
|
||||
// return(-1);
|
||||
// }
|
||||
|
||||
// payload_type_5 = (ADV_PDU_PAYLOAD_TYPE_5 *)adv_pdu_payload;
|
||||
|
||||
// //InitA = reorder_bytes_str( payload_bytes(1 : (2*6)) );
|
||||
// macAddress[0] = payload_byte[5];
|
||||
// macAddress[1] = payload_byte[4];
|
||||
// macAddress[2] = payload_byte[3];
|
||||
// macAddress[3] = payload_byte[2];
|
||||
// macAddress[4] = payload_byte[1];
|
||||
// macAddress[5] = payload_byte[0];
|
||||
|
||||
// //AdvA = reorder_bytes_str( payload_bytes((2*6+1):(2*6+2*6)) );
|
||||
// payload_type_5->AdvA[0] = payload_byte[11];
|
||||
// payload_type_5->AdvA[1] = payload_byte[10];
|
||||
// payload_type_5->AdvA[2] = payload_byte[9];
|
||||
// payload_type_5->AdvA[3] = payload_byte[8];
|
||||
// payload_type_5->AdvA[4] = payload_byte[7];
|
||||
// payload_type_5->AdvA[5] = payload_byte[6];
|
||||
|
||||
// //AA = reorder_bytes_str( payload_bytes((2*6+2*6+1):(2*6+2*6+2*4)) );
|
||||
// payload_type_5->AA[0] = payload_byte[15];
|
||||
// payload_type_5->AA[1] = payload_byte[14];
|
||||
// payload_type_5->AA[2] = payload_byte[13];
|
||||
// payload_type_5->AA[3] = payload_byte[12];
|
||||
|
||||
// //CRCInit = payload_bytes((2*6+2*6+2*4+1):(2*6+2*6+2*4+2*3));
|
||||
// payload_type_5->CRCInit = ( payload_byte[16] );
|
||||
// payload_type_5->CRCInit = ( (payload_type_5->CRCInit << 8) | payload_byte[17] );
|
||||
// payload_type_5->CRCInit = ( (payload_type_5->CRCInit << 8) | payload_byte[18] );
|
||||
|
||||
// //WinSize = payload_bytes((2*6+2*6+2*4+2*3+1):(2*6+2*6+2*4+2*3+2*1));
|
||||
// payload_type_5->WinSize = payload_byte[19];
|
||||
|
||||
// //WinOffset = reorder_bytes_str( payload_bytes((2*6+2*6+2*4+2*3+2*1+1):(2*6+2*6+2*4+2*3+2*1+2*2)) );
|
||||
// payload_type_5->WinOffset = ( payload_byte[21] );
|
||||
// payload_type_5->WinOffset = ( (payload_type_5->WinOffset << 8) | payload_byte[20] );
|
||||
|
||||
// //Interval = reorder_bytes_str( payload_bytes((2*6+2*6+2*4+2*3+2*1+2*2+1):(2*6+2*6+2*4+2*3+2*1+2*2+2*2)) );
|
||||
// payload_type_5->Interval = ( payload_byte[23] );
|
||||
// payload_type_5->Interval = ( (payload_type_5->Interval << 8) | payload_byte[22] );
|
||||
|
||||
// //Latency = reorder_bytes_str( payload_bytes((2*6+2*6+2*4+2*3+2*1+2*2+2*2+1):(2*6+2*6+2*4+2*3+2*1+2*2+2*2+2*2)) );
|
||||
// payload_type_5->Latency = ( payload_byte[25] );
|
||||
// payload_type_5->Latency = ( (payload_type_5->Latency << 8) | payload_byte[24] );
|
||||
|
||||
// //Timeout = reorder_bytes_str( payload_bytes((2*6+2*6+2*4+2*3+2*1+2*2+2*2+2*2+1):(2*6+2*6+2*4+2*3+2*1+2*2+2*2+2*2+2*2)) );
|
||||
// payload_type_5->Timeout = ( payload_byte[27] );
|
||||
// payload_type_5->Timeout = ( (payload_type_5->Timeout << 8) | payload_byte[26] );
|
||||
|
||||
// //ChM = reorder_bytes_str( payload_bytes((2*6+2*6+2*4+2*3+2*1+2*2+2*2+2*2+2*2+1):(2*6+2*6+2*4+2*3+2*1+2*2+2*2+2*2+2*2+2*5)) );
|
||||
// payload_type_5->ChM[0] = payload_byte[32];
|
||||
// payload_type_5->ChM[1] = payload_byte[31];
|
||||
// payload_type_5->ChM[2] = payload_byte[30];
|
||||
// payload_type_5->ChM[3] = payload_byte[29];
|
||||
// payload_type_5->ChM[4] = payload_byte[28];
|
||||
|
||||
// //tmp_bits = payload_bits((end-7) : end);
|
||||
// //Hop = num2str( bi2de(tmp_bits(1:5), 'right-msb') );
|
||||
// //SCA = num2str( bi2de(tmp_bits(6:end), 'right-msb') );
|
||||
// payload_type_5->Hop = (payload_byte[33]&0x1F);
|
||||
// payload_type_5->SCA = ((payload_byte[33]>>5)&0x07);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// //TODO: Handle Unknown PDU.
|
||||
// payload_type_R = (ADV_PDU_PAYLOAD_TYPE_R *)adv_pdu_payload;
|
||||
// memcpy(payload_type_R->payload_byte, payload_byte, num_payload_byte);
|
||||
// return(-1);
|
||||
// }
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void BTLERxProcessor::execute(const buffer_c8_t& buffer) {
|
||||
if (!configured) return;
|
||||
|
||||
// FM demodulation
|
||||
// Pulled this implementation from channel_stats_collector.c to time slice a specific packet's dB.
|
||||
uint32_t max_squared = 0;
|
||||
|
||||
/*const auto decim_0_out = decim_0.execute(buffer, dst_buffer);
|
||||
const auto channel = decim_1.execute(decim_0_out, dst_buffer);
|
||||
void* src_p = buffer.p;
|
||||
|
||||
feed_channel_stats(channel);
|
||||
|
||||
auto audio_oversampled = demod.execute(channel, work_audio_buffer);*/
|
||||
|
||||
const auto decim_0_out = decim_0.execute(buffer, dst_buffer);
|
||||
feed_channel_stats(decim_0_out);
|
||||
|
||||
auto audio_oversampled = demod.execute(decim_0_out, work_audio_buffer);
|
||||
|
||||
/*std::fill(spectrum.begin(), spectrum.end(), 0);
|
||||
for(size_t i=0; i<spectrum.size(); i++) {
|
||||
spectrum[i] += buffer.p[i];
|
||||
while (src_p < &buffer.p[buffer.count]) {
|
||||
const uint32_t sample = *__SIMD32(src_p)++;
|
||||
const uint32_t mag_sq = __SMUAD(sample, sample);
|
||||
if (mag_sq > max_squared) {
|
||||
max_squared = mag_sq;
|
||||
}
|
||||
const buffer_c16_t buffer_c16 {spectrum.data(),spectrum.size(),buffer.sampling_rate};
|
||||
feed_channel_stats(buffer_c16);
|
||||
}
|
||||
|
||||
auto audio_oversampled = demod.execute(buffer_c16, work_audio_buffer);*/
|
||||
// Audio signal processing
|
||||
for (size_t c = 0; c < audio_oversampled.count; c++) {
|
||||
/*const int32_t sample_int = audio_oversampled.p[c] * 32768.0f;
|
||||
int32_t current_sample = __SSAT(sample_int, 16);
|
||||
current_sample /= 128;*/
|
||||
const float max_squared_f = max_squared;
|
||||
const int32_t max_dB = mag2_to_dbv_norm(max_squared_f * (1.0f / (32768.0f * 32768.0f)));
|
||||
|
||||
int32_t current_sample = audio_oversampled.p[c]; // if I directly use this, some results can pass crc but not correct.
|
||||
rb_head++;
|
||||
rb_head = (rb_head) % RB_SIZE;
|
||||
decim_0.execute(buffer, dst_buffer);
|
||||
feed_channel_stats(dst_buffer);
|
||||
|
||||
rb_buf[rb_head] = current_sample;
|
||||
const buffer_c8_t iq_buffer{
|
||||
buffer.p,
|
||||
buffer.count,
|
||||
baseband_fs};
|
||||
|
||||
skipSamples = skipSamples - 1;
|
||||
// process++;
|
||||
|
||||
if (skipSamples < 1) {
|
||||
int32_t threshold_tmp = 0;
|
||||
for (int c = 0; c < 8; c++) {
|
||||
threshold_tmp = threshold_tmp + (int32_t)rb_buf[(rb_head + c) % RB_SIZE];
|
||||
}
|
||||
g_threshold = (int32_t)threshold_tmp / 8;
|
||||
// if ((process % 50) != 0) return;
|
||||
|
||||
int transitions = 0;
|
||||
if (rb_buf[(rb_head + 9) % RB_SIZE] > g_threshold) {
|
||||
for (int c = 0; c < 8; c++) {
|
||||
if (rb_buf[(rb_head + c) % RB_SIZE] > rb_buf[(rb_head + c + 1) % RB_SIZE])
|
||||
transitions = transitions + 1;
|
||||
}
|
||||
} else {
|
||||
for (int c = 0; c < 8; c++) {
|
||||
if (rb_buf[(rb_head + c) % RB_SIZE] < rb_buf[(rb_head + c + 1) % RB_SIZE])
|
||||
transitions = transitions + 1;
|
||||
// 4Mhz 2048 samples
|
||||
|
||||
//--------------Variable Defines---------------------------------//
|
||||
|
||||
int i, sp, j = 0;
|
||||
int I0, Q0, I1, Q1 = 0;
|
||||
int k, p, phase_idx = 0;
|
||||
int num_demod_byte = 0;
|
||||
|
||||
bool unequal_flag;
|
||||
|
||||
const int demod_buf_len = LEN_DEMOD_BUF_ACCESS; // For AA
|
||||
int demod_buf_offset = 0;
|
||||
int num_symbol_left = dst_buffer.count / SAMPLE_PER_SYMBOL; // One buffer sample consist of I and Q.
|
||||
int symbols_eaten = 0;
|
||||
int hit_idx = (-1);
|
||||
|
||||
//--------------Start Parsing For Access Address---------------//
|
||||
|
||||
static uint8_t demod_buf_access[SAMPLE_PER_SYMBOL][LEN_DEMOD_BUF_ACCESS];
|
||||
|
||||
uint32_t uint32_tmp = DEFAULT_ACCESS_ADDR;
|
||||
uint8_t accessAddrBits[LEN_DEMOD_BUF_ACCESS];
|
||||
|
||||
uint32_t accesssAddress = 0;
|
||||
|
||||
// Filling up addressBits with the access address we are looking to find.
|
||||
for (i = 0; i < 32; i++) {
|
||||
accessAddrBits[i] = 0x01 & uint32_tmp;
|
||||
uint32_tmp = (uint32_tmp >> 1);
|
||||
}
|
||||
|
||||
memset(demod_buf_access, 0, SAMPLE_PER_SYMBOL * demod_buf_len);
|
||||
|
||||
for (i = 0; i < num_symbol_left * SAMPLE_PER_SYMBOL; i += SAMPLE_PER_SYMBOL) {
|
||||
sp = ((demod_buf_offset - demod_buf_len + 1) & (demod_buf_len - 1));
|
||||
|
||||
for (j = 0; j < SAMPLE_PER_SYMBOL; j++) {
|
||||
// Sample and compare with the adjacent next sample.
|
||||
I0 = dst_buffer.p[i + j].real();
|
||||
Q0 = dst_buffer.p[i + j].imag();
|
||||
I1 = dst_buffer.p[i + j + 1].real();
|
||||
Q1 = dst_buffer.p[i + j + 1].imag();
|
||||
|
||||
phase_idx = j;
|
||||
|
||||
demod_buf_access[phase_idx][demod_buf_offset] = (I0 * Q1 - I1 * Q0) > 0 ? 1 : 0;
|
||||
|
||||
k = sp;
|
||||
unequal_flag = false;
|
||||
|
||||
accesssAddress = 0;
|
||||
|
||||
for (p = 0; p < demod_buf_len; p++) {
|
||||
if (demod_buf_access[phase_idx][k] != accessAddrBits[p]) {
|
||||
unequal_flag = true;
|
||||
hit_idx = (-1);
|
||||
break;
|
||||
}
|
||||
|
||||
accesssAddress = (accesssAddress & (~(1 << p))) | (demod_buf_access[phase_idx][k] << p);
|
||||
|
||||
k = ((k + 1) & (demod_buf_len - 1));
|
||||
}
|
||||
|
||||
bool packet_detected = false;
|
||||
// if ( transitions==4 && abs(g_threshold)<15500)
|
||||
if (transitions == 4) {
|
||||
uint8_t packet_data[500];
|
||||
int packet_length;
|
||||
uint32_t packet_crc;
|
||||
// uint32_t calced_crc; // NOTE: restore when CRC is passing
|
||||
uint64_t packet_addr_l;
|
||||
// uint32_t result; // NOTE: restore when CRC is passing
|
||||
uint8_t crc[3];
|
||||
uint8_t packet_header_arr[2];
|
||||
if (unequal_flag == false) {
|
||||
hit_idx = (i + j - (demod_buf_len - 1) * SAMPLE_PER_SYMBOL);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
packet_addr_l = 0;
|
||||
for (int i = 0; i < 4; i++) {
|
||||
bool current_bit;
|
||||
uint8_t byte = 0;
|
||||
for (int c = 0; c < 8; c++) {
|
||||
if (rb_buf[(rb_head + (i + 1) * 8 + c) % RB_SIZE] > g_threshold)
|
||||
current_bit = true;
|
||||
else
|
||||
current_bit = false;
|
||||
byte |= current_bit << (7 - c);
|
||||
}
|
||||
uint8_t byte_temp = (uint8_t)(((byte * 0x0802LU & 0x22110LU) | (byte * 0x8020LU & 0x88440LU)) * 0x10101LU >> 16);
|
||||
packet_addr_l |= ((uint64_t)byte_temp) << (8 * i);
|
||||
}
|
||||
if (unequal_flag == false) {
|
||||
break;
|
||||
}
|
||||
|
||||
channel_number = 38;
|
||||
demod_buf_offset = ((demod_buf_offset + 1) & (demod_buf_len - 1));
|
||||
}
|
||||
|
||||
for (int t = 0; t < 2; t++) {
|
||||
bool current_bit;
|
||||
uint8_t byte = 0;
|
||||
for (int c = 0; c < 8; c++) {
|
||||
if (rb_buf[(rb_head + 5 * 8 + t * 8 + c) % RB_SIZE] > g_threshold)
|
||||
current_bit = true;
|
||||
else
|
||||
current_bit = false;
|
||||
byte |= current_bit << (7 - c);
|
||||
}
|
||||
if (hit_idx == -1) {
|
||||
// Process more samples.
|
||||
return;
|
||||
}
|
||||
|
||||
packet_header_arr[t] = byte;
|
||||
}
|
||||
symbols_eaten += hit_idx;
|
||||
|
||||
uint8_t byte_temp2 = (uint8_t)(((channel_number * 0x0802LU & 0x22110LU) | (channel_number * 0x8020LU & 0x88440LU)) * 0x10101LU >> 16);
|
||||
uint8_t lfsr_1 = byte_temp2 | 2;
|
||||
int header_length = 2;
|
||||
int header_counter = 0;
|
||||
while (header_length--) {
|
||||
for (uint8_t i = 0x80; i; i >>= 1) {
|
||||
if (lfsr_1 & 0x80) {
|
||||
lfsr_1 ^= 0x11;
|
||||
(packet_header_arr[header_counter]) ^= i;
|
||||
}
|
||||
lfsr_1 <<= 1;
|
||||
}
|
||||
header_counter = header_counter + 1;
|
||||
}
|
||||
symbols_eaten += (8 * NUM_ACCESS_ADDR_BYTE * SAMPLE_PER_SYMBOL); // move to beginning of PDU header
|
||||
|
||||
if (packet_addr_l == 0x8E89BED6) {
|
||||
uint8_t byte_temp3 = (uint8_t)(((packet_header_arr[1] * 0x0802LU & 0x22110LU) | (packet_header_arr[1] * 0x8020LU & 0x88440LU)) * 0x10101LU >> 16);
|
||||
packet_length = byte_temp3 & 0x3F;
|
||||
num_symbol_left = num_symbol_left - symbols_eaten;
|
||||
|
||||
} else {
|
||||
packet_length = 0;
|
||||
}
|
||||
//--------------Start PDU Header Parsing-----------------------//
|
||||
|
||||
for (int t = 0; t < packet_length + 2 + 3; t++) {
|
||||
bool current_bit;
|
||||
uint8_t byte = 0;
|
||||
for (int c = 0; c < 8; c++) {
|
||||
if (rb_buf[(rb_head + 5 * 8 + t * 8 + c) % RB_SIZE] > g_threshold)
|
||||
current_bit = true;
|
||||
else
|
||||
current_bit = false;
|
||||
byte |= current_bit << (7 - c);
|
||||
}
|
||||
num_demod_byte = 2; // PDU header has 2 octets
|
||||
|
||||
packet_data[t] = byte;
|
||||
}
|
||||
symbols_eaten += 8 * num_demod_byte * SAMPLE_PER_SYMBOL;
|
||||
|
||||
uint8_t byte_temp4 = (uint8_t)(((channel_number * 0x0802LU & 0x22110LU) | (channel_number * 0x8020LU & 0x88440LU)) * 0x10101LU >> 16);
|
||||
uint8_t lfsr_2 = byte_temp4 | 2;
|
||||
int pdu_crc_length = packet_length + 2 + 3;
|
||||
int pdu_crc_counter = 0;
|
||||
while (pdu_crc_length--) {
|
||||
for (uint8_t i = 0x80; i; i >>= 1) {
|
||||
if (lfsr_2 & 0x80) {
|
||||
lfsr_2 ^= 0x11;
|
||||
(packet_data[pdu_crc_counter]) ^= i;
|
||||
}
|
||||
lfsr_2 <<= 1;
|
||||
}
|
||||
pdu_crc_counter = pdu_crc_counter + 1;
|
||||
}
|
||||
if (symbols_eaten > (int)dst_buffer.count) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (packet_addr_l == 0x8E89BED6) {
|
||||
crc[0] = crc[1] = crc[2] = 0x55;
|
||||
} else {
|
||||
crc[0] = crc[1] = crc[2] = 0;
|
||||
}
|
||||
// //Demod the PDU Header
|
||||
uint8_t bit_decision;
|
||||
|
||||
uint8_t v, t, d, crc_length;
|
||||
uint32_t crc_result = 0;
|
||||
crc_length = packet_length + 2;
|
||||
int counter = 0;
|
||||
while (crc_length--) {
|
||||
uint8_t byte_temp5 = (uint8_t)(((packet_data[counter] * 0x0802LU & 0x22110LU) | (packet_data[counter] * 0x8020LU & 0x88440LU)) * 0x10101LU >> 16);
|
||||
d = byte_temp5;
|
||||
for (v = 0; v < 8; v++, d >>= 1) {
|
||||
t = crc[0] >> 7;
|
||||
crc[0] <<= 1;
|
||||
if (crc[1] & 0x80) crc[0] |= 1;
|
||||
crc[1] <<= 1;
|
||||
if (crc[2] & 0x80) crc[1] |= 1;
|
||||
crc[2] <<= 1;
|
||||
if (t != (d & 1)) {
|
||||
crc[2] ^= 0x5B;
|
||||
crc[1] ^= 0x06;
|
||||
}
|
||||
}
|
||||
counter = counter + 1;
|
||||
}
|
||||
for (v = 0; v < 3; v++) crc_result = (crc_result << 8) | crc[v];
|
||||
// calced_crc = crc_result; // NOTE: restore when CRC is passing
|
||||
// Jump back down to beginning of PDU header.
|
||||
int sample_idx = symbols_eaten - (8 * num_demod_byte * SAMPLE_PER_SYMBOL);
|
||||
|
||||
packet_crc = 0;
|
||||
for (int c = 0; c < 3; c++) packet_crc = (packet_crc << 8) | packet_data[packet_length + 2 + c];
|
||||
uint16_t packet_index = 0;
|
||||
|
||||
if (packet_addr_l == 0x8E89BED6)
|
||||
// if (packet_crc==calced_crc) // NOTE: restore when CRC is passing
|
||||
{
|
||||
uint8_t mac_data[6];
|
||||
int counter = 0;
|
||||
for (int i = 7; i >= 2; i--) {
|
||||
uint8_t byte_temp6 = (uint8_t)(((packet_data[i] * 0x0802LU & 0x22110LU) | (packet_data[i] * 0x8020LU & 0x88440LU)) * 0x10101LU >> 16);
|
||||
// result = byte_temp6; // NOTE: restore when CRC is passing
|
||||
mac_data[counter] = byte_temp6;
|
||||
counter = counter + 1;
|
||||
}
|
||||
for (i = 0; i < num_demod_byte; i++) {
|
||||
rb_buf[packet_index] = 0;
|
||||
|
||||
data_message.is_data = false;
|
||||
data_message.value = 'A';
|
||||
shared_memory.application_queue.push(data_message);
|
||||
for (j = 0; j < 8; j++) {
|
||||
I0 = dst_buffer.p[sample_idx].real();
|
||||
Q0 = dst_buffer.p[sample_idx].imag();
|
||||
I1 = dst_buffer.p[sample_idx + 1].real();
|
||||
Q1 = dst_buffer.p[sample_idx + 1].imag();
|
||||
|
||||
data_message.is_data = true;
|
||||
data_message.value = mac_data[0];
|
||||
shared_memory.application_queue.push(data_message);
|
||||
bit_decision = (I0 * Q1 - I1 * Q0) > 0 ? 1 : 0;
|
||||
rb_buf[packet_index] = rb_buf[packet_index] | (bit_decision << j);
|
||||
|
||||
data_message.is_data = true;
|
||||
data_message.value = mac_data[1];
|
||||
shared_memory.application_queue.push(data_message);
|
||||
sample_idx += SAMPLE_PER_SYMBOL;
|
||||
}
|
||||
|
||||
data_message.is_data = true;
|
||||
data_message.value = mac_data[2];
|
||||
shared_memory.application_queue.push(data_message);
|
||||
packet_index++;
|
||||
}
|
||||
|
||||
data_message.is_data = true;
|
||||
data_message.value = mac_data[3];
|
||||
shared_memory.application_queue.push(data_message);
|
||||
// demod_byte(num_demod_byte, rb_buf);
|
||||
|
||||
data_message.is_data = true;
|
||||
data_message.value = mac_data[4];
|
||||
shared_memory.application_queue.push(data_message);
|
||||
scramble_byte(rb_buf, num_demod_byte, scramble_table[channel_number], rb_buf);
|
||||
|
||||
data_message.is_data = true;
|
||||
data_message.value = mac_data[5];
|
||||
shared_memory.application_queue.push(data_message);
|
||||
uint8_t pdu_type = (ADV_PDU_TYPE)(rb_buf[0] & 0x0F);
|
||||
// uint8_t tx_add = ((rb_buf[0] & 0x40) != 0);
|
||||
// uint8_t rx_add = ((rb_buf[0] & 0x80) != 0);
|
||||
uint8_t payload_len = (rb_buf[1] & 0x3F);
|
||||
|
||||
data_message.is_data = false;
|
||||
data_message.value = 'B';
|
||||
shared_memory.application_queue.push(data_message);
|
||||
// Not valid Advertise Payload.
|
||||
if ((payload_len < 6) || (payload_len > 37)) {
|
||||
return;
|
||||
}
|
||||
|
||||
packet_detected = true;
|
||||
} else
|
||||
packet_detected = false;
|
||||
//--------------Start Payload Parsing--------------------------//
|
||||
|
||||
num_demod_byte = (payload_len + 3);
|
||||
symbols_eaten += 8 * num_demod_byte * SAMPLE_PER_SYMBOL;
|
||||
|
||||
if (symbols_eaten > (int)dst_buffer.count) {
|
||||
return;
|
||||
}
|
||||
|
||||
// sample_idx = symbols_eaten - (8 * num_demod_byte * SAMPLE_PER_SYMBOL);
|
||||
|
||||
for (i = 0; i < num_demod_byte; i++) {
|
||||
rb_buf[packet_index] = 0;
|
||||
|
||||
for (j = 0; j < 8; j++) {
|
||||
I0 = dst_buffer.p[sample_idx].real();
|
||||
Q0 = dst_buffer.p[sample_idx].imag();
|
||||
I1 = dst_buffer.p[sample_idx + 1].real();
|
||||
Q1 = dst_buffer.p[sample_idx + 1].imag();
|
||||
|
||||
bit_decision = (I0 * Q1 - I1 * Q0) > 0 ? 1 : 0;
|
||||
rb_buf[packet_index] = rb_buf[packet_index] | (bit_decision << j);
|
||||
|
||||
sample_idx += SAMPLE_PER_SYMBOL;
|
||||
}
|
||||
|
||||
packet_index++;
|
||||
}
|
||||
|
||||
// demod_byte(num_demod_byte, rb_buf + 2);
|
||||
|
||||
scramble_byte(rb_buf + 2, num_demod_byte, scramble_table[channel_number] + 2, rb_buf + 2);
|
||||
|
||||
//--------------Start CRC Checking-----------------------------//
|
||||
|
||||
// Check CRC
|
||||
bool crc_flag = crc_check(rb_buf, payload_len + 2, crc_init_internal);
|
||||
// pkt_count++;
|
||||
|
||||
// This should be the flag that determines if the data should be sent to the application layer.
|
||||
bool sendPacket = false;
|
||||
|
||||
// Checking CRC and excluding Reserved PDU types.
|
||||
if (pdu_type < RESERVED0 && !crc_flag) {
|
||||
if (parse_adv_pdu_payload_byte(rb_buf + 2, payload_len, (ADV_PDU_TYPE)pdu_type, (void*)(&adv_pdu_payload)) == 0) {
|
||||
sendPacket = true;
|
||||
}
|
||||
|
||||
// TODO: Make this a packet builder function?
|
||||
if (sendPacket) {
|
||||
blePacketData.max_dB = max_dB;
|
||||
|
||||
blePacketData.type = pdu_type;
|
||||
blePacketData.size = payload_len;
|
||||
|
||||
blePacketData.macAddress[0] = macAddress[0];
|
||||
blePacketData.macAddress[1] = macAddress[1];
|
||||
blePacketData.macAddress[2] = macAddress[2];
|
||||
blePacketData.macAddress[3] = macAddress[3];
|
||||
blePacketData.macAddress[4] = macAddress[4];
|
||||
blePacketData.macAddress[5] = macAddress[5];
|
||||
|
||||
// Skip Header Byte and MAC Address
|
||||
uint8_t startIndex = 8;
|
||||
|
||||
for (i = 0; i < payload_len - 6; i++) {
|
||||
blePacketData.data[i] = rb_buf[startIndex++];
|
||||
}
|
||||
|
||||
if (packet_detected) {
|
||||
skipSamples = 20;
|
||||
}
|
||||
blePacketData.dataLen = i;
|
||||
|
||||
BLEPacketMessage data_message{&blePacketData};
|
||||
|
||||
shared_memory.application_queue.push(data_message);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -275,12 +506,13 @@ void BTLERxProcessor::on_message(const Message* const message) {
|
||||
}
|
||||
|
||||
void BTLERxProcessor::configure(const BTLERxConfigureMessage& message) {
|
||||
(void)message; // avoid warning
|
||||
channel_number = message.channel_number;
|
||||
decim_0.configure(taps_200k_wfm_decim_0.taps);
|
||||
decim_1.configure(taps_200k_wfm_decim_1.taps);
|
||||
demod.configure(audio_fs, 5000);
|
||||
demod.configure(48000, 5000);
|
||||
|
||||
configured = true;
|
||||
|
||||
crc_init_internal = crc_init_reorder(crc_initalVale);
|
||||
}
|
||||
|
||||
int main() {
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
* Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc.
|
||||
* Copyright (C) 2016 Furrtek
|
||||
* Copyright (C) 2020 Shao
|
||||
* Copyright (C) 2023 Netro
|
||||
*
|
||||
* This file is part of PortaPack.
|
||||
*
|
||||
@@ -42,48 +43,191 @@ class BTLERxProcessor : public BasebandProcessor {
|
||||
void on_message(const Message* const message) override;
|
||||
|
||||
private:
|
||||
static constexpr int SAMPLE_PER_SYMBOL{1};
|
||||
static constexpr int LEN_DEMOD_BUF_ACCESS{32};
|
||||
static constexpr uint32_t DEFAULT_ACCESS_ADDR{0x8E89BED6};
|
||||
static constexpr int NUM_ACCESS_ADDR_BYTE{4};
|
||||
|
||||
enum ADV_PDU_TYPE {
|
||||
ADV_IND = 0,
|
||||
ADV_DIRECT_IND = 1,
|
||||
ADV_NONCONN_IND = 2,
|
||||
SCAN_REQ = 3,
|
||||
SCAN_RSP = 4,
|
||||
CONNECT_REQ = 5,
|
||||
ADV_SCAN_IND = 6,
|
||||
RESERVED0 = 7,
|
||||
RESERVED1 = 8,
|
||||
RESERVED2 = 9,
|
||||
RESERVED3 = 10,
|
||||
RESERVED4 = 11,
|
||||
RESERVED5 = 12,
|
||||
RESERVED6 = 13,
|
||||
RESERVED7 = 14,
|
||||
RESERVED8 = 15
|
||||
};
|
||||
|
||||
uint8_t macAddress[6];
|
||||
int checksumReceived = 0;
|
||||
|
||||
struct ADV_PDU_PAYLOAD_TYPE_0_2_4_6 {
|
||||
uint8_t Data[31];
|
||||
};
|
||||
|
||||
struct ADV_PDU_PAYLOAD_TYPE_1_3 {
|
||||
uint8_t A1[6];
|
||||
};
|
||||
|
||||
struct ADV_PDU_PAYLOAD_TYPE_5 {
|
||||
uint8_t AdvA[6];
|
||||
uint8_t AA[4];
|
||||
uint32_t CRCInit;
|
||||
uint8_t WinSize;
|
||||
uint16_t WinOffset;
|
||||
uint16_t Interval;
|
||||
uint16_t Latency;
|
||||
uint16_t Timeout;
|
||||
uint8_t ChM[5];
|
||||
uint8_t Hop;
|
||||
uint8_t SCA;
|
||||
};
|
||||
|
||||
struct ADV_PDU_PAYLOAD_TYPE_R {
|
||||
uint8_t payload_byte[40];
|
||||
};
|
||||
|
||||
static constexpr size_t baseband_fs = 4000000;
|
||||
static constexpr size_t audio_fs = baseband_fs / 8 / 8 / 2;
|
||||
|
||||
std::array<complex16_t, 512> dst{};
|
||||
uint_fast32_t crc_update(uint_fast32_t crc, const void* data, size_t data_len);
|
||||
uint_fast32_t crc24_byte(uint8_t* byte_in, int num_byte, uint32_t init_hex);
|
||||
bool crc_check(uint8_t* tmp_byte, int body_len, uint32_t crc_init);
|
||||
uint32_t crc_init_reorder(uint32_t crc_init);
|
||||
|
||||
uint32_t crc_initalVale = 0x555555;
|
||||
uint32_t crc_init_internal = 0x00;
|
||||
|
||||
void scramble_byte(uint8_t* byte_in, int num_byte, const uint8_t* scramble_table_byte, uint8_t* byte_out);
|
||||
// void demod_byte(int num_byte, uint8_t *out_byte);
|
||||
int parse_adv_pdu_payload_byte(uint8_t* payload_byte, int num_payload_byte, ADV_PDU_TYPE pdu_type, void* adv_pdu_payload);
|
||||
|
||||
std::array<complex16_t, 1024> dst{};
|
||||
const buffer_c16_t dst_buffer{
|
||||
dst.data(),
|
||||
dst.size()};
|
||||
|
||||
std::array<complex16_t, 512> spectrum{};
|
||||
const buffer_c16_t spectrum_buffer{
|
||||
spectrum.data(),
|
||||
spectrum.size()};
|
||||
static constexpr int RB_SIZE = 2048;
|
||||
uint8_t rb_buf[2048];
|
||||
|
||||
const buffer_s16_t work_audio_buffer{
|
||||
(int16_t*)dst.data(),
|
||||
sizeof(dst) / sizeof(int16_t)};
|
||||
|
||||
// Array size ok down to 375 bauds (24000 / 375)
|
||||
std::array<int32_t, 64> delay_line{0};
|
||||
std::array<int16_t, 1000> rb_buf{0};
|
||||
|
||||
/*dsp::decimate::FIRC8xR16x24FS4Decim8 decim_0 { };
|
||||
dsp::decimate::FIRC16xR16x32Decim8 decim_1 { };
|
||||
dsp::decimate::FIRAndDecimateComplex channel_filter { };*/
|
||||
dsp::decimate::FIRC8xR16x24FS4Decim4 decim_0{};
|
||||
dsp::decimate::FIRC16xR16x16Decim2 decim_1{};
|
||||
|
||||
dsp::demodulate::FM demod{};
|
||||
int rb_head{-1};
|
||||
int32_t g_threshold{0};
|
||||
uint8_t channel_number{38};
|
||||
int skipSamples{1000};
|
||||
int RB_SIZE{1000};
|
||||
uint8_t channel_number{37};
|
||||
|
||||
uint16_t process = 0;
|
||||
|
||||
bool configured{false};
|
||||
AFSKDataMessage data_message{false, 0};
|
||||
BlePacketData blePacketData{};
|
||||
|
||||
/* NB: Threads should be the last members in the class definition. */
|
||||
BasebandThread baseband_thread{baseband_fs, this, baseband::Direction::Receive};
|
||||
RSSIThread rssi_thread{};
|
||||
|
||||
void configure(const BTLERxConfigureMessage& message);
|
||||
|
||||
ADV_PDU_PAYLOAD_TYPE_0_2_4_6* payload_type_0_2_4_6 = nullptr;
|
||||
ADV_PDU_PAYLOAD_TYPE_1_3* payload_type_1_3 = nullptr;
|
||||
ADV_PDU_PAYLOAD_TYPE_5* payload_type_5 = nullptr;
|
||||
ADV_PDU_PAYLOAD_TYPE_R* payload_type_R = nullptr;
|
||||
ADV_PDU_PAYLOAD_TYPE_R adv_pdu_payload = {0};
|
||||
|
||||
// clang-format off
|
||||
// Scramble table definition
|
||||
const uint8_t scramble_table[40][42] =
|
||||
{
|
||||
{64, 178, 188, 195, 31, 55, 74, 95, 133, 246, 156, 154, 193, 214, 197, 68, 32, 89, 222, 225, 143, 27, 165, 175, 66, 123, 78, 205, 96, 235, 98, 34, 144, 44, 239, 240, 199, 141, 210, 87, 161, 61, },
|
||||
{137, 64, 178, 188, 195, 31, 55, 74, 95, 133, 246, 156, 154, 193, 214, 197, 68, 32, 89, 222, 225, 143, 27, 165, 175, 66, 123, 78, 205, 96, 235, 98, 34, 144, 44, 239, 240, 199, 141, 210, 87, 161, },
|
||||
{210, 87, 161, 61, 167, 102, 176, 117, 49, 17, 72, 150, 119, 248, 227, 70, 233, 171, 208, 158, 83, 51, 216, 186, 152, 8, 36, 203, 59, 252, 113, 163, 244, 85, 104, 207, 169, 25, 108, 93, 76, 4, },
|
||||
{27, 165, 175, 66, 123, 78, 205, 96, 235, 98, 34, 144, 44, 239, 240, 199, 141, 210, 87, 161, 61, 167, 102, 176, 117, 49, 17, 72, 150, 119, 248, 227, 70, 233, 171, 208, 158, 83, 51, 216, 186, 152, },
|
||||
{100, 121, 135, 63, 110, 148, 190, 10, 237, 57, 53, 131, 173, 139, 137, 64, 178, 188, 195, 31, 55, 74, 95, 133, 246, 156, 154, 193, 214, 197, 68, 32, 89, 222, 225, 143, 27, 165, 175, 66, 123, 78, },
|
||||
{173, 139, 137, 64, 178, 188, 195, 31, 55, 74, 95, 133, 246, 156, 154, 193, 214, 197, 68, 32, 89, 222, 225, 143, 27, 165, 175, 66, 123, 78, 205, 96, 235, 98, 34, 144, 44, 239, 240, 199, 141, 210, },
|
||||
{246, 156, 154, 193, 214, 197, 68, 32, 89, 222, 225, 143, 27, 165, 175, 66, 123, 78, 205, 96, 235, 98, 34, 144, 44, 239, 240, 199, 141, 210, 87, 161, 61, 167, 102, 176, 117, 49, 17, 72, 150, 119, },
|
||||
{63, 110, 148, 190, 10, 237, 57, 53, 131, 173, 139, 137, 64, 178, 188, 195, 31, 55, 74, 95, 133, 246, 156, 154, 193, 214, 197, 68, 32, 89, 222, 225, 143, 27, 165, 175, 66, 123, 78, 205, 96, 235, },
|
||||
{8, 36, 203, 59, 252, 113, 163, 244, 85, 104, 207, 169, 25, 108, 93, 76, 4, 146, 229, 29, 254, 184, 81, 250, 42, 180, 231, 212, 12, 182, 46, 38, 2, 201, 242, 14, 127, 220, 40, 125, 21, 218, },
|
||||
{193, 214, 197, 68, 32, 89, 222, 225, 143, 27, 165, 175, 66, 123, 78, 205, 96, 235, 98, 34, 144, 44, 239, 240, 199, 141, 210, 87, 161, 61, 167, 102, 176, 117, 49, 17, 72, 150, 119, 248, 227, 70, },
|
||||
{154, 193, 214, 197, 68, 32, 89, 222, 225, 143, 27, 165, 175, 66, 123, 78, 205, 96, 235, 98, 34, 144, 44, 239, 240, 199, 141, 210, 87, 161, 61, 167, 102, 176, 117, 49, 17, 72, 150, 119, 248, 227, },
|
||||
{83, 51, 216, 186, 152, 8, 36, 203, 59, 252, 113, 163, 244, 85, 104, 207, 169, 25, 108, 93, 76, 4, 146, 229, 29, 254, 184, 81, 250, 42, 180, 231, 212, 12, 182, 46, 38, 2, 201, 242, 14, 127, },
|
||||
{44, 239, 240, 199, 141, 210, 87, 161, 61, 167, 102, 176, 117, 49, 17, 72, 150, 119, 248, 227, 70, 233, 171, 208, 158, 83, 51, 216, 186, 152, 8, 36, 203, 59, 252, 113, 163, 244, 85, 104, 207, 169, },
|
||||
{229, 29, 254, 184, 81, 250, 42, 180, 231, 212, 12, 182, 46, 38, 2, 201, 242, 14, 127, 220, 40, 125, 21, 218, 115, 106, 6, 91, 23, 19, 129, 100, 121, 135, 63, 110, 148, 190, 10, 237, 57, 53, },
|
||||
{190, 10, 237, 57, 53, 131, 173, 139, 137, 64, 178, 188, 195, 31, 55, 74, 95, 133, 246, 156, 154, 193, 214, 197, 68, 32, 89, 222, 225, 143, 27, 165, 175, 66, 123, 78, 205, 96, 235, 98, 34, 144, },
|
||||
{119, 248, 227, 70, 233, 171, 208, 158, 83, 51, 216, 186, 152, 8, 36, 203, 59, 252, 113, 163, 244, 85, 104, 207, 169, 25, 108, 93, 76, 4, 146, 229, 29, 254, 184, 81, 250, 42, 180, 231, 212, 12, },
|
||||
{208, 158, 83, 51, 216, 186, 152, 8, 36, 203, 59, 252, 113, 163, 244, 85, 104, 207, 169, 25, 108, 93, 76, 4, 146, 229, 29, 254, 184, 81, 250, 42, 180, 231, 212, 12, 182, 46, 38, 2, 201, 242, },
|
||||
{25, 108, 93, 76, 4, 146, 229, 29, 254, 184, 81, 250, 42, 180, 231, 212, 12, 182, 46, 38, 2, 201, 242, 14, 127, 220, 40, 125, 21, 218, 115, 106, 6, 91, 23, 19, 129, 100, 121, 135, 63, 110, },
|
||||
{66, 123, 78, 205, 96, 235, 98, 34, 144, 44, 239, 240, 199, 141, 210, 87, 161, 61, 167, 102, 176, 117, 49, 17, 72, 150, 119, 248, 227, 70, 233, 171, 208, 158, 83, 51, 216, 186, 152, 8, 36, 203, },
|
||||
{139, 137, 64, 178, 188, 195, 31, 55, 74, 95, 133, 246, 156, 154, 193, 214, 197, 68, 32, 89, 222, 225, 143, 27, 165, 175, 66, 123, 78, 205, 96, 235, 98, 34, 144, 44, 239, 240, 199, 141, 210, 87, },
|
||||
{244, 85, 104, 207, 169, 25, 108, 93, 76, 4, 146, 229, 29, 254, 184, 81, 250, 42, 180, 231, 212, 12, 182, 46, 38, 2, 201, 242, 14, 127, 220, 40, 125, 21, 218, 115, 106, 6, 91, 23, 19, 129, },
|
||||
{61, 167, 102, 176, 117, 49, 17, 72, 150, 119, 248, 227, 70, 233, 171, 208, 158, 83, 51, 216, 186, 152, 8, 36, 203, 59, 252, 113, 163, 244, 85, 104, 207, 169, 25, 108, 93, 76, 4, 146, 229, 29, },
|
||||
{102, 176, 117, 49, 17, 72, 150, 119, 248, 227, 70, 233, 171, 208, 158, 83, 51, 216, 186, 152, 8, 36, 203, 59, 252, 113, 163, 244, 85, 104, 207, 169, 25, 108, 93, 76, 4, 146, 229, 29, 254, 184, },
|
||||
{175, 66, 123, 78, 205, 96, 235, 98, 34, 144, 44, 239, 240, 199, 141, 210, 87, 161, 61, 167, 102, 176, 117, 49, 17, 72, 150, 119, 248, 227, 70, 233, 171, 208, 158, 83, 51, 216, 186, 152, 8, 36, },
|
||||
{152, 8, 36, 203, 59, 252, 113, 163, 244, 85, 104, 207, 169, 25, 108, 93, 76, 4, 146, 229, 29, 254, 184, 81, 250, 42, 180, 231, 212, 12, 182, 46, 38, 2, 201, 242, 14, 127, 220, 40, 125, 21, },
|
||||
{81, 250, 42, 180, 231, 212, 12, 182, 46, 38, 2, 201, 242, 14, 127, 220, 40, 125, 21, 218, 115, 106, 6, 91, 23, 19, 129, 100, 121, 135, 63, 110, 148, 190, 10, 237, 57, 53, 131, 173, 139, 137, },
|
||||
{10, 237, 57, 53, 131, 173, 139, 137, 64, 178, 188, 195, 31, 55, 74, 95, 133, 246, 156, 154, 193, 214, 197, 68, 32, 89, 222, 225, 143, 27, 165, 175, 66, 123, 78, 205, 96, 235, 98, 34, 144, 44, },
|
||||
{195, 31, 55, 74, 95, 133, 246, 156, 154, 193, 214, 197, 68, 32, 89, 222, 225, 143, 27, 165, 175, 66, 123, 78, 205, 96, 235, 98, 34, 144, 44, 239, 240, 199, 141, 210, 87, 161, 61, 167, 102, 176, },
|
||||
{188, 195, 31, 55, 74, 95, 133, 246, 156, 154, 193, 214, 197, 68, 32, 89, 222, 225, 143, 27, 165, 175, 66, 123, 78, 205, 96, 235, 98, 34, 144, 44, 239, 240, 199, 141, 210, 87, 161, 61, 167, 102, },
|
||||
{117, 49, 17, 72, 150, 119, 248, 227, 70, 233, 171, 208, 158, 83, 51, 216, 186, 152, 8, 36, 203, 59, 252, 113, 163, 244, 85, 104, 207, 169, 25, 108, 93, 76, 4, 146, 229, 29, 254, 184, 81, 250, },
|
||||
{46, 38, 2, 201, 242, 14, 127, 220, 40, 125, 21, 218, 115, 106, 6, 91, 23, 19, 129, 100, 121, 135, 63, 110, 148, 190, 10, 237, 57, 53, 131, 173, 139, 137, 64, 178, 188, 195, 31, 55, 74, 95, },
|
||||
{231, 212, 12, 182, 46, 38, 2, 201, 242, 14, 127, 220, 40, 125, 21, 218, 115, 106, 6, 91, 23, 19, 129, 100, 121, 135, 63, 110, 148, 190, 10, 237, 57, 53, 131, 173, 139, 137, 64, 178, 188, 195, },
|
||||
{96, 235, 98, 34, 144, 44, 239, 240, 199, 141, 210, 87, 161, 61, 167, 102, 176, 117, 49, 17, 72, 150, 119, 248, 227, 70, 233, 171, 208, 158, 83, 51, 216, 186, 152, 8, 36, 203, 59, 252, 113, 163, },
|
||||
{169, 25, 108, 93, 76, 4, 146, 229, 29, 254, 184, 81, 250, 42, 180, 231, 212, 12, 182, 46, 38, 2, 201, 242, 14, 127, 220, 40, 125, 21, 218, 115, 106, 6, 91, 23, 19, 129, 100, 121, 135, 63, },
|
||||
{242, 14, 127, 220, 40, 125, 21, 218, 115, 106, 6, 91, 23, 19, 129, 100, 121, 135, 63, 110, 148, 190, 10, 237, 57, 53, 131, 173, 139, 137, 64, 178, 188, 195, 31, 55, 74, 95, 133, 246, 156, 154, },
|
||||
{59, 252, 113, 163, 244, 85, 104, 207, 169, 25, 108, 93, 76, 4, 146, 229, 29, 254, 184, 81, 250, 42, 180, 231, 212, 12, 182, 46, 38, 2, 201, 242, 14, 127, 220, 40, 125, 21, 218, 115, 106, 6, },
|
||||
{68, 32, 89, 222, 225, 143, 27, 165, 175, 66, 123, 78, 205, 96, 235, 98, 34, 144, 44, 239, 240, 199, 141, 210, 87, 161, 61, 167, 102, 176, 117, 49, 17, 72, 150, 119, 248, 227, 70, 233, 171, 208, },
|
||||
{141, 210, 87, 161, 61, 167, 102, 176, 117, 49, 17, 72, 150, 119, 248, 227, 70, 233, 171, 208, 158, 83, 51, 216, 186, 152, 8, 36, 203, 59, 252, 113, 163, 244, 85, 104, 207, 169, 25, 108, 93, 76, },
|
||||
{214, 197, 68, 32, 89, 222, 225, 143, 27, 165, 175, 66, 123, 78, 205, 96, 235, 98, 34, 144, 44, 239, 240, 199, 141, 210, 87, 161, 61, 167, 102, 176, 117, 49, 17, 72, 150, 119, 248, 227, 70, 233, },
|
||||
{31, 55, 74, 95, 133, 246, 156, 154, 193, 214, 197, 68, 32, 89, 222, 225, 143, 27, 165, 175, 66, 123, 78, 205, 96, 235, 98, 34, 144, 44, 239, 240, 199, 141, 210, 87, 161, 61, 167, 102, 176, 117, },
|
||||
};
|
||||
|
||||
/**
|
||||
* Static table used for the table_driven implementation.
|
||||
*****************************************************************************/
|
||||
const uint_fast32_t crc_table[256] =
|
||||
{
|
||||
0x000000, 0x01b4c0, 0x036980, 0x02dd40, 0x06d300, 0x0767c0, 0x05ba80, 0x040e40,
|
||||
0x0da600, 0x0c12c0, 0x0ecf80, 0x0f7b40, 0x0b7500, 0x0ac1c0, 0x081c80, 0x09a840,
|
||||
0x1b4c00, 0x1af8c0, 0x182580, 0x199140, 0x1d9f00, 0x1c2bc0, 0x1ef680, 0x1f4240,
|
||||
0x16ea00, 0x175ec0, 0x158380, 0x143740, 0x103900, 0x118dc0, 0x135080, 0x12e440,
|
||||
0x369800, 0x372cc0, 0x35f180, 0x344540, 0x304b00, 0x31ffc0, 0x332280, 0x329640,
|
||||
0x3b3e00, 0x3a8ac0, 0x385780, 0x39e340, 0x3ded00, 0x3c59c0, 0x3e8480, 0x3f3040,
|
||||
0x2dd400, 0x2c60c0, 0x2ebd80, 0x2f0940, 0x2b0700, 0x2ab3c0, 0x286e80, 0x29da40,
|
||||
0x207200, 0x21c6c0, 0x231b80, 0x22af40, 0x26a100, 0x2715c0, 0x25c880, 0x247c40,
|
||||
0x6d3000, 0x6c84c0, 0x6e5980, 0x6fed40, 0x6be300, 0x6a57c0, 0x688a80, 0x693e40,
|
||||
0x609600, 0x6122c0, 0x63ff80, 0x624b40, 0x664500, 0x67f1c0, 0x652c80, 0x649840,
|
||||
0x767c00, 0x77c8c0, 0x751580, 0x74a140, 0x70af00, 0x711bc0, 0x73c680, 0x727240,
|
||||
0x7bda00, 0x7a6ec0, 0x78b380, 0x790740, 0x7d0900, 0x7cbdc0, 0x7e6080, 0x7fd440,
|
||||
0x5ba800, 0x5a1cc0, 0x58c180, 0x597540, 0x5d7b00, 0x5ccfc0, 0x5e1280, 0x5fa640,
|
||||
0x560e00, 0x57bac0, 0x556780, 0x54d340, 0x50dd00, 0x5169c0, 0x53b480, 0x520040,
|
||||
0x40e400, 0x4150c0, 0x438d80, 0x423940, 0x463700, 0x4783c0, 0x455e80, 0x44ea40,
|
||||
0x4d4200, 0x4cf6c0, 0x4e2b80, 0x4f9f40, 0x4b9100, 0x4a25c0, 0x48f880, 0x494c40,
|
||||
0xda6000, 0xdbd4c0, 0xd90980, 0xd8bd40, 0xdcb300, 0xdd07c0, 0xdfda80, 0xde6e40,
|
||||
0xd7c600, 0xd672c0, 0xd4af80, 0xd51b40, 0xd11500, 0xd0a1c0, 0xd27c80, 0xd3c840,
|
||||
0xc12c00, 0xc098c0, 0xc24580, 0xc3f140, 0xc7ff00, 0xc64bc0, 0xc49680, 0xc52240,
|
||||
0xcc8a00, 0xcd3ec0, 0xcfe380, 0xce5740, 0xca5900, 0xcbedc0, 0xc93080, 0xc88440,
|
||||
0xecf800, 0xed4cc0, 0xef9180, 0xee2540, 0xea2b00, 0xeb9fc0, 0xe94280, 0xe8f640,
|
||||
0xe15e00, 0xe0eac0, 0xe23780, 0xe38340, 0xe78d00, 0xe639c0, 0xe4e480, 0xe55040,
|
||||
0xf7b400, 0xf600c0, 0xf4dd80, 0xf56940, 0xf16700, 0xf0d3c0, 0xf20e80, 0xf3ba40,
|
||||
0xfa1200, 0xfba6c0, 0xf97b80, 0xf8cf40, 0xfcc100, 0xfd75c0, 0xffa880, 0xfe1c40,
|
||||
0xb75000, 0xb6e4c0, 0xb43980, 0xb58d40, 0xb18300, 0xb037c0, 0xb2ea80, 0xb35e40,
|
||||
0xbaf600, 0xbb42c0, 0xb99f80, 0xb82b40, 0xbc2500, 0xbd91c0, 0xbf4c80, 0xbef840,
|
||||
0xac1c00, 0xada8c0, 0xaf7580, 0xaec140, 0xaacf00, 0xab7bc0, 0xa9a680, 0xa81240,
|
||||
0xa1ba00, 0xa00ec0, 0xa2d380, 0xa36740, 0xa76900, 0xa6ddc0, 0xa40080, 0xa5b440,
|
||||
0x81c800, 0x807cc0, 0x82a180, 0x831540, 0x871b00, 0x86afc0, 0x847280, 0x85c640,
|
||||
0x8c6e00, 0x8ddac0, 0x8f0780, 0x8eb340, 0x8abd00, 0x8b09c0, 0x89d480, 0x886040,
|
||||
0x9a8400, 0x9b30c0, 0x99ed80, 0x985940, 0x9c5700, 0x9de3c0, 0x9f3e80, 0x9e8a40,
|
||||
0x972200, 0x9696c0, 0x944b80, 0x95ff40, 0x91f100, 0x9045c0, 0x929880, 0x932c40
|
||||
};
|
||||
// clang-format on
|
||||
};
|
||||
|
||||
#endif /*__PROC_BTLERX_H__*/
|
||||
|
||||
@@ -0,0 +1,318 @@
|
||||
/*
|
||||
* Copyright (C) 1996 Thomas Sailer (sailer@ife.ee.ethz.ch, hb9jnx@hb9w.che.eu)
|
||||
* Copyright (C) 2012-2014 Elias Oenal (multimon-ng@eliasoenal.com)
|
||||
* Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc.
|
||||
* Copyright (C) 2016 Furrtek
|
||||
* Copyright (C) 2023 Kyle Reed
|
||||
*
|
||||
* 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 "proc_fsk_rx.hpp"
|
||||
|
||||
#include "event_m4.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include <cstdint>
|
||||
#include <cstddef>
|
||||
|
||||
using namespace std;
|
||||
using namespace dsp::decimate;
|
||||
|
||||
namespace {
|
||||
/* Count of bits that differ between the two values. */
|
||||
uint8_t diff_bit_count(uint32_t left, uint32_t right) {
|
||||
uint32_t diff = left ^ right;
|
||||
uint8_t count = 0;
|
||||
for (size_t i = 0; i < sizeof(diff) * 8; ++i) {
|
||||
if (((diff >> i) & 0x1) == 1)
|
||||
++count;
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
/* AudioNormalizer ***************************************/
|
||||
|
||||
void AudioNormalizer::execute_in_place(const buffer_f32_t& audio) {
|
||||
// Decay min/max every second (@24kHz).
|
||||
if (counter_ >= 24'000) {
|
||||
// 90% decay factor seems to work well.
|
||||
// This keeps large transients from wrecking the filter.
|
||||
max_ *= 0.9f;
|
||||
min_ *= 0.9f;
|
||||
counter_ = 0;
|
||||
calculate_thresholds();
|
||||
}
|
||||
|
||||
counter_ += audio.count;
|
||||
|
||||
for (size_t i = 0; i < audio.count; ++i) {
|
||||
auto& val = audio.p[i];
|
||||
|
||||
if (val > max_) {
|
||||
max_ = val;
|
||||
calculate_thresholds();
|
||||
}
|
||||
if (val < min_) {
|
||||
min_ = val;
|
||||
calculate_thresholds();
|
||||
}
|
||||
|
||||
if (val >= t_hi_)
|
||||
val = 1.0f;
|
||||
else if (val <= t_lo_)
|
||||
val = -1.0f;
|
||||
else
|
||||
val = 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
void AudioNormalizer::calculate_thresholds() {
|
||||
auto center = (max_ + min_) / 2.0f;
|
||||
auto range = (max_ - min_) / 2.0f;
|
||||
|
||||
// 10% off center force either +/-1.0f.
|
||||
// Higher == larger dead zone.
|
||||
// Lower == more false positives.
|
||||
auto threshold = range * 0.1;
|
||||
t_hi_ = center + threshold;
|
||||
t_lo_ = center - threshold;
|
||||
}
|
||||
|
||||
/* FSKRxProcessor ******************************************/
|
||||
|
||||
void FSKRxProcessor::clear_data_bits() {
|
||||
data = 0;
|
||||
bit_count = 0;
|
||||
}
|
||||
|
||||
void FSKRxProcessor::handle_sync(bool inverted) {
|
||||
clear_data_bits();
|
||||
has_sync_ = true;
|
||||
inverted = inverted;
|
||||
word_count = 0;
|
||||
}
|
||||
|
||||
void FSKRxProcessor::process_bits(const buffer_c8_t& buffer) {
|
||||
// Process all of the bits in the bits queue.
|
||||
while (buffer.count > 0) {
|
||||
// Wait until data_ is full.
|
||||
if (bit_count < data_bit_count)
|
||||
continue;
|
||||
|
||||
// Wait for the sync frame.
|
||||
if (!has_sync_) {
|
||||
if (diff_bit_count(data, sync_codeword) <= 2)
|
||||
handle_sync(/*inverted=*/false);
|
||||
else if (diff_bit_count(data, ~sync_codeword) <= 2)
|
||||
handle_sync(/*inverted=*/true);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* FSKRxProcessor ***************************************/
|
||||
|
||||
FSKRxProcessor::FSKRxProcessor() {
|
||||
}
|
||||
|
||||
void FSKRxProcessor::execute(const buffer_c8_t& buffer) {
|
||||
if (!configured) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Decimate by current decim 0 and decim 1.
|
||||
const auto decim_0_out = decim_0.execute(buffer, dst_buffer);
|
||||
const auto decim_1_out = decim_1.execute(decim_0_out, dst_buffer);
|
||||
|
||||
feed_channel_stats(decim_1_out);
|
||||
|
||||
spectrum_samples += decim_1_out.count;
|
||||
|
||||
if (spectrum_samples >= spectrum_interval_samples) {
|
||||
spectrum_samples -= spectrum_interval_samples;
|
||||
channel_spectrum.feed(decim_1_out, channel_filter_low_f,
|
||||
channel_filter_high_f, channel_filter_transition);
|
||||
}
|
||||
|
||||
// process_bits();
|
||||
|
||||
// Update the status.
|
||||
samples_processed += buffer.count;
|
||||
|
||||
if (samples_processed >= stat_update_threshold) {
|
||||
// send_packet(data);
|
||||
samples_processed -= stat_update_threshold;
|
||||
}
|
||||
}
|
||||
|
||||
void FSKRxProcessor::on_message(const Message* const message) {
|
||||
switch (message->id) {
|
||||
case Message::ID::FSKRxConfigure:
|
||||
configure(*reinterpret_cast<const FSKRxConfigureMessage*>(message));
|
||||
break;
|
||||
case Message::ID::UpdateSpectrum:
|
||||
case Message::ID::SpectrumStreamingConfig:
|
||||
channel_spectrum.on_message(message);
|
||||
break;
|
||||
|
||||
case Message::ID::SampleRateConfig:
|
||||
sample_rate_config(*reinterpret_cast<const SampleRateConfigMessage*>(message));
|
||||
break;
|
||||
|
||||
case Message::ID::CaptureConfig:
|
||||
capture_config(*reinterpret_cast<const CaptureConfigMessage*>(message));
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void FSKRxProcessor::configure(const FSKRxConfigureMessage& message) {
|
||||
// Extract message variables.
|
||||
deviation = message.deviation;
|
||||
channel_decimation = message.channel_decimation;
|
||||
// channel_filter_taps = message.channel_filter;
|
||||
|
||||
channel_spectrum.set_decimation_factor(1);
|
||||
}
|
||||
|
||||
void FSKRxProcessor::capture_config(const CaptureConfigMessage& message) {
|
||||
if (message.config) {
|
||||
audio_output.set_stream(std::make_unique<StreamInput>(message.config));
|
||||
} else {
|
||||
audio_output.set_stream(nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
void FSKRxProcessor::sample_rate_config(const SampleRateConfigMessage& message) {
|
||||
const auto sample_rate = message.sample_rate;
|
||||
|
||||
// The actual sample rate is the requested rate * the oversample rate.
|
||||
// See oversample.hpp for more details on oversampling.
|
||||
baseband_fs = sample_rate * toUType(message.oversample_rate);
|
||||
baseband_thread.set_sampling_rate(baseband_fs);
|
||||
|
||||
// TODO: Do we need to use the taps that the decimators get configured with?
|
||||
channel_filter_low_f = taps_200k_decim_1.low_frequency_normalized * sample_rate;
|
||||
channel_filter_high_f = taps_200k_decim_1.high_frequency_normalized * sample_rate;
|
||||
channel_filter_transition = taps_200k_decim_1.transition_normalized * sample_rate;
|
||||
|
||||
// Compute the scalar that corrects the oversample_rate to be x8 when computing
|
||||
// the spectrum update interval. The original implementation only supported x8.
|
||||
// TODO: Why is this needed here but not in proc_replay? There must be some other
|
||||
// assumption about x8 oversampling in some component that makes this necessary.
|
||||
const auto oversample_correction = toUType(message.oversample_rate) / 8.0;
|
||||
|
||||
// The spectrum update interval controls how often the waterfall is fed new samples.
|
||||
spectrum_interval_samples = sample_rate / (spectrum_rate_hz * oversample_correction);
|
||||
spectrum_samples = 0;
|
||||
|
||||
// For high sample rates, the M4 is busy collecting samples so the
|
||||
// waterfall runs slower. Reduce the update interval so it runs faster.
|
||||
// NB: Trade off: looks nicer, but more frequent updates == more CPU.
|
||||
if (sample_rate >= 1'500'000)
|
||||
spectrum_interval_samples /= (sample_rate / 750'000);
|
||||
|
||||
switch (message.oversample_rate) {
|
||||
case OversampleRate::x4:
|
||||
// M4 can't handle 2 decimation passes for sample rates needing x4.
|
||||
decim_0.set<FIRC8xR16x24FS4Decim4>().configure(taps_200k_decim_0.taps);
|
||||
decim_1.set<NoopDecim>();
|
||||
break;
|
||||
|
||||
case OversampleRate::x8:
|
||||
// M4 can't handle 2 decimation passes for sample rates <= 600k.
|
||||
if (message.sample_rate < 600'000) {
|
||||
decim_0.set<FIRC8xR16x24FS4Decim4>().configure(taps_200k_decim_0.taps);
|
||||
decim_1.set<FIRC16xR16x16Decim2>().configure(taps_200k_decim_1.taps);
|
||||
} else {
|
||||
// Using 180k taps to provide better filtering with a single pass.
|
||||
decim_0.set<FIRC8xR16x24FS4Decim8>().configure(taps_180k_wfm_decim_0.taps);
|
||||
decim_1.set<NoopDecim>();
|
||||
}
|
||||
break;
|
||||
|
||||
case OversampleRate::x16:
|
||||
decim_0.set<FIRC8xR16x24FS4Decim8>().configure(taps_200k_decim_0.taps);
|
||||
decim_1.set<FIRC16xR16x16Decim2>().configure(taps_200k_decim_1.taps);
|
||||
break;
|
||||
|
||||
case OversampleRate::x32:
|
||||
decim_0.set<FIRC8xR16x24FS4Decim4>().configure(taps_200k_decim_0.taps);
|
||||
decim_1.set<FIRC16xR16x32Decim8>().configure(taps_16k0_decim_1.taps);
|
||||
break;
|
||||
|
||||
case OversampleRate::x64:
|
||||
decim_0.set<FIRC8xR16x24FS4Decim8>().configure(taps_200k_decim_0.taps);
|
||||
decim_1.set<FIRC16xR16x32Decim8>().configure(taps_16k0_decim_1.taps);
|
||||
break;
|
||||
|
||||
default:
|
||||
chDbgPanic("Unhandled OversampleRate");
|
||||
break;
|
||||
}
|
||||
|
||||
// Update demodulator based on new decimation. Todo: Confirm this works.
|
||||
size_t decim_0_input_fs = baseband_fs;
|
||||
size_t decim_0_output_fs = decim_0_input_fs / decim_0.decimation_factor();
|
||||
|
||||
size_t decim_1_input_fs = decim_0_output_fs;
|
||||
size_t decim_1_output_fs = decim_1_input_fs / decim_1.decimation_factor();
|
||||
|
||||
// size_t channel_filter_input_fs = decim_1_output_fs;
|
||||
// size_t channel_filter_output_fs = channel_filter_input_fs / channel_decimation;
|
||||
|
||||
size_t demod_input_fs = decim_1_output_fs;
|
||||
|
||||
send_packet((uint32_t)demod_input_fs);
|
||||
|
||||
// Set ready to process data.
|
||||
configured = true;
|
||||
}
|
||||
|
||||
void FSKRxProcessor::flush() {
|
||||
// word_extractor.flush();
|
||||
}
|
||||
|
||||
void FSKRxProcessor::reset() {
|
||||
clear_data_bits();
|
||||
has_sync_ = false;
|
||||
inverted = false;
|
||||
word_count = 0;
|
||||
|
||||
samples_processed = 0;
|
||||
}
|
||||
|
||||
void FSKRxProcessor::send_packet(uint32_t data) {
|
||||
data_message.is_data = true;
|
||||
data_message.value = data;
|
||||
shared_memory.application_queue.push(data_message);
|
||||
}
|
||||
|
||||
/* main **************************************************/
|
||||
|
||||
int main() {
|
||||
EventDispatcher event_dispatcher{std::make_unique<FSKRxProcessor>()};
|
||||
event_dispatcher.run();
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,225 @@
|
||||
/*
|
||||
* Copyright (C) 2014 Jared Boone, ShareBrained Technology, Inc.
|
||||
* Copyright (C) 2016 Furrtek
|
||||
*
|
||||
* This file is part of PortaPack.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, Inc., 51 Franklin Street,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef __PROC_FSK_RX_H__
|
||||
#define __PROC_FSK_RX_H__
|
||||
|
||||
#include "audio_output.hpp"
|
||||
#include "baseband_processor.hpp"
|
||||
#include "baseband_thread.hpp"
|
||||
#include "rssi_thread.hpp"
|
||||
|
||||
#include "dsp_decimate.hpp"
|
||||
#include "dsp_demodulate.hpp"
|
||||
#include "dsp_iir_config.hpp"
|
||||
#include "dsp_fir_taps.hpp"
|
||||
|
||||
#include "spectrum_collector.hpp"
|
||||
#include "stream_input.hpp"
|
||||
|
||||
#include "message.hpp"
|
||||
#include "portapack_shared_memory.hpp"
|
||||
|
||||
#include <array>
|
||||
#include <memory>
|
||||
#include <tuple>
|
||||
#include <variant>
|
||||
#include <cstdint>
|
||||
#include <functional>
|
||||
|
||||
/* Normalizes audio stream to +/-1.0f */
|
||||
class AudioNormalizer {
|
||||
public:
|
||||
void execute_in_place(const buffer_f32_t& audio);
|
||||
|
||||
private:
|
||||
void calculate_thresholds();
|
||||
|
||||
uint32_t counter_ = 0;
|
||||
float min_ = 99.0f;
|
||||
float max_ = -99.0f;
|
||||
float t_hi_ = 1.0;
|
||||
float t_lo_ = 1.0;
|
||||
};
|
||||
|
||||
/* A decimator that just returns the source buffer. */
|
||||
class NoopDecim {
|
||||
public:
|
||||
static constexpr int decimation_factor = 1;
|
||||
|
||||
template <typename Buffer>
|
||||
Buffer execute(const Buffer& src, const Buffer&) {
|
||||
// TODO: should this copy to 'dst'?
|
||||
return {src.p, src.count, src.sampling_rate};
|
||||
}
|
||||
};
|
||||
|
||||
/* Decimator wrapper that can hold one of a set of decimators and dispatch at runtime. */
|
||||
template <typename... Args>
|
||||
class MultiDecimator {
|
||||
public:
|
||||
/* Dispatches to the underlying type's execute. */
|
||||
template <typename Source, typename Destination>
|
||||
Destination execute(
|
||||
const Source& src,
|
||||
const Destination& dst) {
|
||||
return std::visit(
|
||||
[&src, &dst](auto&& arg) -> Destination {
|
||||
return arg.execute(src, dst);
|
||||
},
|
||||
decimator_);
|
||||
}
|
||||
|
||||
size_t decimation_factor() const {
|
||||
return std::visit(
|
||||
[](auto&& arg) -> size_t {
|
||||
return arg.decimation_factor;
|
||||
},
|
||||
decimator_);
|
||||
}
|
||||
|
||||
/* Sets this decimator to a new instance of the specified decimator type.
|
||||
* NB: The instance is returned by-ref so 'configure' can easily be called. */
|
||||
template <typename Decimator>
|
||||
Decimator& set() {
|
||||
decimator_ = Decimator{};
|
||||
return std::get<Decimator>(decimator_);
|
||||
}
|
||||
|
||||
private:
|
||||
std::variant<Args...> decimator_{};
|
||||
};
|
||||
|
||||
class FSKRxProcessor : public BasebandProcessor {
|
||||
public:
|
||||
FSKRxProcessor();
|
||||
void execute(const buffer_c8_t& buffer) override;
|
||||
void on_message(const Message* const message) override;
|
||||
|
||||
private:
|
||||
size_t baseband_fs = 1024000; // aka: sample_rate
|
||||
uint8_t stat_update_interval = 10;
|
||||
uint32_t stat_update_threshold = baseband_fs / stat_update_interval;
|
||||
static constexpr auto spectrum_rate_hz = 50.0f;
|
||||
|
||||
void configure(const FSKRxConfigureMessage& message);
|
||||
void capture_config(const CaptureConfigMessage& message);
|
||||
void sample_rate_config(const SampleRateConfigMessage& message);
|
||||
void flush();
|
||||
void reset();
|
||||
void send_packet(uint32_t data);
|
||||
void process_bits(const buffer_c8_t& buffer);
|
||||
|
||||
void clear_data_bits();
|
||||
void handle_sync(bool inverted);
|
||||
|
||||
/* Returns true if the batch has as sync frame. */
|
||||
bool has_sync() const { return has_sync_; }
|
||||
|
||||
/* Set once app is ready to receive messages. */
|
||||
bool configured = false;
|
||||
|
||||
/* Buffer for decimated IQ data. */
|
||||
std::array<complex16_t, 512> dst{};
|
||||
const buffer_c16_t dst_buffer{
|
||||
dst.data(),
|
||||
dst.size()};
|
||||
|
||||
/* Buffer for demodulated audio. */
|
||||
std::array<float, 16> audio{};
|
||||
const buffer_f32_t audio_buffer{audio.data(), audio.size()};
|
||||
|
||||
/* The actual type will be configured depending on the sample rate. */
|
||||
MultiDecimator<
|
||||
dsp::decimate::FIRC8xR16x24FS4Decim4,
|
||||
dsp::decimate::FIRC8xR16x24FS4Decim8>
|
||||
decim_0{};
|
||||
MultiDecimator<
|
||||
dsp::decimate::FIRC16xR16x16Decim2,
|
||||
dsp::decimate::FIRC16xR16x32Decim8,
|
||||
NoopDecim>
|
||||
decim_1{};
|
||||
|
||||
/* Filter to 24kHz and demodulate. */
|
||||
dsp::decimate::FIRAndDecimateComplex channel_filter{};
|
||||
size_t deviation = 3750;
|
||||
// fir_taps_real<32> channel_filter_taps = 0;
|
||||
size_t channel_decimation = 2;
|
||||
int32_t channel_filter_low_f = 0;
|
||||
int32_t channel_filter_high_f = 0;
|
||||
int32_t channel_filter_transition = 0;
|
||||
|
||||
/* Squelch to ignore noise. */
|
||||
FMSquelch squelch{};
|
||||
uint64_t squelch_history = 0;
|
||||
|
||||
// /* LPF to reduce noise. POCSAG supports 2400 baud, but that falls
|
||||
// * nicely into the transition band of this 1800Hz filter.
|
||||
// * scipy.signal.butter(2, 1800, "lowpass", fs=24000, analog=False) */
|
||||
// IIRBiquadFilter lpf{{{0.04125354f, 0.082507070f, 0.04125354f},
|
||||
// {1.00000000f, -1.34896775f, 0.51398189f}}};
|
||||
|
||||
/* Attempts to de-noise and normalize signal. */
|
||||
AudioNormalizer normalizer{};
|
||||
|
||||
/* Handles writing audio stream to hardware. */
|
||||
AudioOutput audio_output{};
|
||||
|
||||
/* Holds the data sent to the app. */
|
||||
AFSKDataMessage data_message{false, 0};
|
||||
|
||||
/* Used to keep track of how many samples were processed
|
||||
* between status update messages. */
|
||||
uint32_t samples_processed = 0;
|
||||
|
||||
/* Number of bits in 'data_' member. */
|
||||
static constexpr uint8_t data_bit_count = sizeof(uint32_t) * 8;
|
||||
|
||||
/* Sync frame codeword. */
|
||||
static constexpr uint32_t sync_codeword = 0x12345678;
|
||||
|
||||
/* When true, sync frame has been received. */
|
||||
bool has_sync_ = false;
|
||||
|
||||
/* When true, bit vales are flipped in the codewords. */
|
||||
bool inverted = false;
|
||||
|
||||
uint32_t data = 0;
|
||||
uint8_t bit_count = 0;
|
||||
uint8_t word_count = 0;
|
||||
|
||||
/* LPF to reduce noise. POCSAG supports 2400 baud, but that falls
|
||||
* nicely into the transition band of this 1800Hz filter.
|
||||
* scipy.signal.butter(2, 1800, "lowpass", fs=24000, analog=False) */
|
||||
IIRBiquadFilter lpf{{{0.04125354f, 0.082507070f, 0.04125354f},
|
||||
{1.00000000f, -1.34896775f, 0.51398189f}}};
|
||||
|
||||
SpectrumCollector channel_spectrum{};
|
||||
size_t spectrum_interval_samples = 0;
|
||||
size_t spectrum_samples = 0;
|
||||
|
||||
/* NB: Threads should be the last members in the class definition. */
|
||||
BasebandThread baseband_thread{baseband_fs, this, baseband::Direction::Receive};
|
||||
RSSIThread rssi_thread{};
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -40,7 +40,7 @@ void SigGenProcessor::execute(const buffer_c8_t& buffer) {
|
||||
|
||||
if (tone_shape == 0) {
|
||||
// CW
|
||||
re = 127;
|
||||
re = 127; // max. signed 8 bits value . (-128 ...+127), max. amplitude , static phasor at 0º
|
||||
im = 0;
|
||||
} else {
|
||||
if (tone_shape == 1) {
|
||||
@@ -79,20 +79,58 @@ void SigGenProcessor::execute(const buffer_c8_t& buffer) {
|
||||
if (counter == 15) {
|
||||
counter = 0;
|
||||
}
|
||||
} else if (tone_shape == 7) {
|
||||
// Digital BPSK consecutive 0,1,0,...continuous cycle, 1 bit/symbol, at rate of 2 symbols / Freq Tone Periode... without any Pulse shape at the moment .
|
||||
re = (((tone_phase & 0xFF000000) >> 24) & 0x80) ? 127 : -128; // Sending 2 bits by Periode T of the GUI tone, alternative static phasor to 0, -180º , 0º
|
||||
im = 0;
|
||||
} else if (tone_shape == 8) {
|
||||
// Digital QPSK consecutive 00, 01, 10, 11,00, ...continuous cycle ,2 bits/symbol, at rate of 4 symbols / Freq Tone Periode. not random., without any Pulse shape at the moment .
|
||||
|
||||
switch (((tone_phase & 0xFF000000) >> 24)) {
|
||||
case 0 ... 63: // equivalent to 1/4 of total 360º degrees.
|
||||
/* "00" */
|
||||
re = (sine_table_i8[32]); // we are sending symbol-phasor 45º during 1/4 of the total periode
|
||||
im = (sine_table_i8[32 + 64]); // 32 index = rounded (45º/360º * 255 total sin table steps) = 31,875
|
||||
break;
|
||||
|
||||
case 64 ... 127:
|
||||
/* "01" */
|
||||
re = (sine_table_i8[96]); // symbol-phasor 135º
|
||||
im = (sine_table_i8[96 + 64]); // 96 index = 32 + 256/4
|
||||
break;
|
||||
break;
|
||||
|
||||
case 128 ... 191:
|
||||
/* "10" */
|
||||
re = (sine_table_i8[159]); // symbol-phasor 225º
|
||||
im = (sine_table_i8[159 + 64]); // 159 rounded index = 96 + 256/4 = 159.3
|
||||
break;
|
||||
|
||||
case 192 ... 255:
|
||||
/* "11" */
|
||||
re = (sine_table_i8[223]); // symbol-phasor 315º ; 223 rounded index = (315/360) * 255 =223.125
|
||||
im = (sine_table_i8[((223 + 64) & 0xFF)]); // Max index 255, circular periodic conversion.
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (tone_shape < 6) { // we are in periodic signals, we need tone phases update.
|
||||
tone_phase += tone_delta;
|
||||
if (tone_shape != 6) { //(all except Pseudo Random White Noise). We are in (1):periodic signals or (2):BPSK/QPSK , in both cases ,we need Tone updated acum sum phases to modulate in FM / or control phasor phase (BPSK & QPSK.)
|
||||
tone_phase += tone_delta; // In periodic signals(Sine/triangle/square) we are using to FM mod. in BPSK-QSPK we are using to calculate each 1/4 of the periode.
|
||||
}
|
||||
|
||||
// Do FM modulation
|
||||
delta = sample * fm_delta;
|
||||
if (tone_shape < 7) { // All Option shape signals except BPSK(7) & QPSK(8) we are modulating in FM. (Those two has phase shift modulation XPSK , not FM )
|
||||
// Do FM modulation
|
||||
delta = sample * fm_delta;
|
||||
|
||||
phase += delta;
|
||||
sphase = phase + (64 << 24);
|
||||
phase += delta;
|
||||
sphase = phase + (64 << 24);
|
||||
|
||||
re = (sine_table_i8[(sphase & 0xFF000000) >> 24]);
|
||||
im = (sine_table_i8[(phase & 0xFF000000) >> 24]);
|
||||
re = (sine_table_i8[(sphase & 0xFF000000) >> 24]); // sin LUT is not dealing with decimals , output range [-128 ,...127]
|
||||
im = (sine_table_i8[(phase & 0xFF000000) >> 24]);
|
||||
}
|
||||
}
|
||||
|
||||
buffer.p[i] = {re, im};
|
||||
|
||||
@@ -224,7 +224,7 @@ void AK4951::speaker_disable() {
|
||||
set_speaker_power(false);
|
||||
}
|
||||
|
||||
void AK4951::microphone_enable(int8_t alc_mode) {
|
||||
void AK4951::microphone_enable(int8_t alc_mode, bool mic_to_HP_enabled) {
|
||||
// alc_mode =0 = (OFF =same as original code = NOT using AK4951 Programmable digital filter block),
|
||||
// alc_mode >1 (with DIGITAL FILTER BLOCK , example : 1:(+12dB) , 2:(+9dB)", 3:(+6dB), ...)
|
||||
|
||||
@@ -279,7 +279,7 @@ void AK4951::microphone_enable(int8_t alc_mode) {
|
||||
update(Register::DigitalFilterMode); // Writing the Audio Path : NO DIGITAL BLOCK or DIG BLOCK FOR MIC , Audio mode path : Playback mode /-Recording mode.
|
||||
|
||||
map.r.power_management_1.PMADL = 1; // ADC Lch = Lch input signal. Mic Amp Lch and ADC Lch Power Management
|
||||
map.r.power_management_1.PMADR = 1; // ADC Rch = Rch input signal. Mic Amp Rch and ADC Rch Power Management
|
||||
map.r.power_management_1.PMADR = 0; // ADC Rch = Rch input signal. Mic Amp Rch and ADC Rch Power Management. (PMADL=1, PMADR=0) means MONO MIC input connected to Left pin.
|
||||
map.r.power_management_1.PMPFIL = 0; // Pre-loading , Programmable Dig. filter OFF ,filter unused, routed around.(original value = 0 )
|
||||
update(Register::PowerManagement1); // Activating the Power management of the used blocks . (Mic ADC always + Dig Block filter , when used )
|
||||
|
||||
@@ -461,7 +461,7 @@ void AK4951::microphone_enable(int8_t alc_mode) {
|
||||
// When changing those modes, PMPFIL bit must be “0”, it is OK (*1)
|
||||
map.r.digital_filter_mode.ADCPF = 1; // ADCPF bit swith ("0" Mic after ADC Output connected (recording mode) to the DIGITAL FILTER BLOCK. ("1" Playback mode)
|
||||
map.r.digital_filter_mode.PFSDO = 1; // ADC (+ 1st order HPF) Output
|
||||
map.r.digital_filter_mode.PFDAC = 0b00; // (Input selector for DAC (not used in MIC), SDTI= Audio Serial Data Input Pin)
|
||||
map.r.digital_filter_mode.PFDAC = 0b00; // (Input selector for DAC (initially not used in MIC), SDTI= Audio Serial Data Input Pin)
|
||||
update(Register::DigitalFilterMode); // Writing the Audio Path : NO DIGITAL BLOCK or DIG BLOCK FOR MIC , Audio mode path : Playback mode /-Recording mode.
|
||||
|
||||
// The EQn (n=1, 2, 3, 4 or 5) coefficient must be set when EQn bit = “0” or PMPFIL bit = “0”., but we are already (*1)
|
||||
@@ -501,10 +501,15 @@ void AK4951::microphone_enable(int8_t alc_mode) {
|
||||
|
||||
// Acitivating digital block , power supply
|
||||
map.r.power_management_1.PMADL = 1; // ADC Lch = Lch input signal. Mic Amp Lch and ADC Lch Power Management
|
||||
map.r.power_management_1.PMADR = 1; // ADC Rch = Rch input signal. Mic Amp Rch and ADC Rch Power Management
|
||||
map.r.power_management_1.PMADR = 0; // ADC Rch = Rch input signal. Mic Amp Rch and ADC Rch Power Management. (PMADL=1, PMADR=0) means MONO MIC input connected to Left pin.
|
||||
map.r.power_management_1.PMPFIL = 1; // Pre-loaded in top part. Orig value=0, Programmable Digital filter unused (not power up), routed around.
|
||||
update(Register::PowerManagement1); // Activating the Power management of the used blocks . (Mic ADC always + Dig Block filter , when used )
|
||||
|
||||
if (mic_to_HP_enabled)
|
||||
microphone_to_HP_enable();
|
||||
else
|
||||
microphone_to_HP_disable();
|
||||
|
||||
// 1059/fs, 22ms @ 48kHz
|
||||
chThdSleepMilliseconds(22);
|
||||
}
|
||||
@@ -522,8 +527,13 @@ void AK4951::microphone_disable() {
|
||||
map.r.power_management_1.PMADL = 0; // original code , disable Power managem.Mic ADC L
|
||||
map.r.power_management_1.PMADR = 0; // original code , disable Power managem.Mic ADC R
|
||||
map.r.power_management_1.PMPFIL = 0; // original code , disable Power managem. all Programmable Dig. block
|
||||
map.r.power_management_1.PMDAC = 0; // Pre-loaded power management DAC block OFF
|
||||
update(Register::PowerManagement1);
|
||||
|
||||
map.r.power_management_2.PMHPL = 0; // Pre-loaded power management HP LEFT block OFF
|
||||
map.r.power_management_2.PMHPR = 0; // Pre-loaded power management HP RIGHT block OFF
|
||||
update(Register::PowerManagement2); // Deactivating the Power management of the HP L&R blocks.
|
||||
|
||||
map.r.alc_mode_control_1.ALC = 0; // original code , Restore , disable ALC block.
|
||||
update(Register::ALCModeControl1);
|
||||
|
||||
@@ -560,6 +570,30 @@ void AK4951::microphone_disable() {
|
||||
update(Register::DigitalFilterSelect3);
|
||||
}
|
||||
|
||||
void AK4951::microphone_to_HP_enable() {
|
||||
map.r.digital_filter_mode.PFDAC = 0b01; // (Input selector for DAC, audio Loopback Mode .
|
||||
update(Register::DigitalFilterMode); // Writing the Audio Path , Audio mode path : Loopback Mode .
|
||||
|
||||
map.r.power_management_1.PMDAC = 1; // Pre-loaded power management DAC block ON
|
||||
update(Register::PowerManagement1); // Activating the Power management of the DAC block for the loopback mode
|
||||
|
||||
map.r.power_management_2.PMHPL = 1; // Pre-loaded power management HP LEFT block ON
|
||||
map.r.power_management_2.PMHPR = 1; // Pre-loaded power management HP RIGHT block ON
|
||||
update(Register::PowerManagement2); // Activating the Power management of the HP L&R blocks.
|
||||
}
|
||||
|
||||
void AK4951::microphone_to_HP_disable() {
|
||||
map.r.digital_filter_mode.PFDAC = 0b00; // (Input selector for DAC (not used in MIC), SDTI= Audio Serial Data Input Pin)
|
||||
update(Register::DigitalFilterMode); // Writing the Audio Path , Audio mode path : Loopback Mode .
|
||||
|
||||
map.r.power_management_1.PMDAC = 0; // Pre-loaded power management DAC block OFF
|
||||
update(Register::PowerManagement1); // Deactivating the Power management of the DAC block for the loopback mode
|
||||
|
||||
map.r.power_management_2.PMHPL = 0; // Pre-loaded power management HP LEFT block OFF
|
||||
map.r.power_management_2.PMHPR = 0; // Pre-loaded power management HP RIGHT block OFF
|
||||
update(Register::PowerManagement2); // Deactivating the Power management of the HP L&R blocks.
|
||||
}
|
||||
|
||||
reg_t AK4951::read(const address_t reg_address) {
|
||||
const std::array<uint8_t, 1> tx{reg_address};
|
||||
std::array<uint8_t, 1> rx{0x00};
|
||||
|
||||
@@ -844,9 +844,12 @@ class AK4951 : public audio::Codec {
|
||||
void set_headphone_volume(const volume_t volume) override;
|
||||
void headphone_mute();
|
||||
|
||||
void microphone_enable(int8_t alc_mode); // added user GUI parameter , to set up AK4951 ALC mode.
|
||||
void microphone_enable(int8_t alc_mode, bool mic_to_HP_enabled); // added user GUI parameter , to set up AK4951 ALC mode, and mic_to_HP_enabled to control "Hear to Mic"
|
||||
void microphone_disable();
|
||||
|
||||
void microphone_to_HP_enable();
|
||||
void microphone_to_HP_disable();
|
||||
|
||||
size_t reg_count() const override {
|
||||
return asahi_kasei::ak4951::reg_count;
|
||||
}
|
||||
|
||||
+68
-12
@@ -112,6 +112,9 @@ class Message {
|
||||
SpectrumPainterBufferRequestConfigure = 55,
|
||||
SpectrumPainterBufferResponseConfigure = 56,
|
||||
POCSAGStats = 57,
|
||||
FSKRxConfigure = 58,
|
||||
BlePacket = 58,
|
||||
BTLETxConfigure = 59,
|
||||
MAX
|
||||
};
|
||||
|
||||
@@ -400,6 +403,26 @@ class AFSKDataMessage : public Message {
|
||||
uint32_t value;
|
||||
};
|
||||
|
||||
struct BlePacketData {
|
||||
int max_dB;
|
||||
uint8_t type;
|
||||
uint8_t size;
|
||||
uint8_t macAddress[6];
|
||||
uint8_t data[40];
|
||||
uint8_t dataLen;
|
||||
};
|
||||
|
||||
class BLEPacketMessage : public Message {
|
||||
public:
|
||||
constexpr BLEPacketMessage(
|
||||
BlePacketData* packet)
|
||||
: Message{ID::BlePacket},
|
||||
packet{packet} {
|
||||
}
|
||||
|
||||
BlePacketData* packet{nullptr};
|
||||
};
|
||||
|
||||
class CodedSquelchMessage : public Message {
|
||||
public:
|
||||
constexpr CodedSquelchMessage(
|
||||
@@ -726,20 +749,30 @@ class APRSRxConfigureMessage : public Message {
|
||||
class BTLERxConfigureMessage : public Message {
|
||||
public:
|
||||
constexpr BTLERxConfigureMessage(
|
||||
const uint32_t baudrate,
|
||||
const uint32_t word_length,
|
||||
const uint32_t trigger_value,
|
||||
const bool trigger_word)
|
||||
const uint8_t channel_number)
|
||||
: Message{ID::BTLERxConfigure},
|
||||
baudrate(baudrate),
|
||||
word_length(word_length),
|
||||
trigger_value(trigger_value),
|
||||
trigger_word(trigger_word) {
|
||||
channel_number(channel_number) {
|
||||
}
|
||||
const uint32_t baudrate;
|
||||
const uint32_t word_length;
|
||||
const uint32_t trigger_value;
|
||||
const bool trigger_word;
|
||||
const uint8_t channel_number;
|
||||
};
|
||||
|
||||
class BTLETxConfigureMessage : public Message {
|
||||
public:
|
||||
constexpr BTLETxConfigureMessage(
|
||||
const uint8_t channel_number,
|
||||
char* macAddress,
|
||||
char* advertisementData,
|
||||
const uint8_t pduType)
|
||||
: Message{ID::BTLETxConfigure},
|
||||
channel_number(channel_number),
|
||||
macAddress(macAddress),
|
||||
advertisementData(advertisementData),
|
||||
pduType(pduType) {
|
||||
}
|
||||
const uint8_t channel_number;
|
||||
char* macAddress;
|
||||
char* advertisementData;
|
||||
const uint8_t pduType;
|
||||
};
|
||||
|
||||
class NRFRxConfigureMessage : public Message {
|
||||
@@ -1013,6 +1046,29 @@ class FSKConfigureMessage : public Message {
|
||||
const uint32_t progress_notice;
|
||||
};
|
||||
|
||||
class FSKRxConfigureMessage : public Message {
|
||||
public:
|
||||
constexpr FSKRxConfigureMessage(
|
||||
const fir_taps_real<24> decim_0_filter,
|
||||
const fir_taps_real<32> decim_1_filter,
|
||||
const fir_taps_real<32> channel_filter,
|
||||
const size_t channel_decimation,
|
||||
const size_t deviation)
|
||||
: Message{ID::FSKRxConfigure},
|
||||
decim_0_filter(decim_0_filter),
|
||||
decim_1_filter(decim_1_filter),
|
||||
channel_filter(channel_filter),
|
||||
channel_decimation{channel_decimation},
|
||||
deviation{deviation} {
|
||||
}
|
||||
|
||||
const fir_taps_real<24> decim_0_filter;
|
||||
const fir_taps_real<32> decim_1_filter;
|
||||
const fir_taps_real<32> channel_filter;
|
||||
const size_t channel_decimation;
|
||||
const size_t deviation;
|
||||
};
|
||||
|
||||
class POCSAGConfigureMessage : public Message {
|
||||
public:
|
||||
constexpr POCSAGConfigureMessage()
|
||||
|
||||
@@ -868,6 +868,8 @@ bool should_use_sdcard_for_pmem() {
|
||||
|
||||
int save_persistent_settings_to_file() {
|
||||
File outfile;
|
||||
|
||||
make_new_directory(SETTINGS_DIR);
|
||||
auto error = outfile.create(PMEM_SETTING_FILE);
|
||||
if (error)
|
||||
return false;
|
||||
@@ -912,7 +914,9 @@ bool debug_dump() {
|
||||
painter.draw_string({0, 320 - 16}, ui::Styles::red, "ERROR DUMPING " + filename.filename().string() + " !");
|
||||
return false;
|
||||
}
|
||||
pmem_dump_file.write_line("FW version " VERSION_STRING);
|
||||
pmem_dump_file.write_line("FW version: " VERSION_STRING);
|
||||
pmem_dump_file.write_line("Ext APPS version req'd: 0x" + to_string_hex(VERSION_MD5));
|
||||
pmem_dump_file.write_line("GCC version: " + to_string_dec_int(__GNUC__) + "." + to_string_dec_int(__GNUC_MINOR__) + "." + to_string_dec_int(__GNUC_PATCHLEVEL__));
|
||||
|
||||
// write persistent memory
|
||||
pmem_dump_file.write_line("\n[Persistent Memory]");
|
||||
|
||||
@@ -78,6 +78,7 @@ constexpr image_tag_t image_tag_adsb_rx{'P', 'A', 'D', 'R'};
|
||||
constexpr image_tag_t image_tag_afsk_rx{'P', 'A', 'F', 'R'};
|
||||
constexpr image_tag_t image_tag_aprs_rx{'P', 'A', 'P', 'R'};
|
||||
constexpr image_tag_t image_tag_btle_rx{'P', 'B', 'T', 'R'};
|
||||
constexpr image_tag_t image_tag_btle_tx{'P', 'B', 'T', 'T'};
|
||||
constexpr image_tag_t image_tag_nrf_rx{'P', 'N', 'R', 'R'};
|
||||
constexpr image_tag_t image_tag_ais{'P', 'A', 'I', 'S'};
|
||||
constexpr image_tag_t image_tag_am_audio{'P', 'A', 'M', 'A'};
|
||||
@@ -97,6 +98,7 @@ constexpr image_tag_t image_tag_adsb_tx{'P', 'A', 'D', 'T'};
|
||||
constexpr image_tag_t image_tag_afsk{'P', 'A', 'F', 'T'};
|
||||
constexpr image_tag_t image_tag_audio_tx{'P', 'A', 'T', 'X'};
|
||||
constexpr image_tag_t image_tag_fsktx{'P', 'F', 'S', 'K'};
|
||||
constexpr image_tag_t image_tag_fskrx{'P', 'F', 'S', 'R'};
|
||||
constexpr image_tag_t image_tag_jammer{'P', 'J', 'A', 'M'};
|
||||
constexpr image_tag_t image_tag_mic_tx{'P', 'M', 'T', 'X'};
|
||||
constexpr image_tag_t image_tag_ook{'P', 'O', 'O', 'K'};
|
||||
|
||||
@@ -349,17 +349,36 @@ class WM8731 : public audio::Codec {
|
||||
return false;
|
||||
}
|
||||
|
||||
void microphone_enable(int8_t wm8731_boost_GUI) override {
|
||||
void microphone_enable(int8_t wm8731_boost_GUI, bool mic_to_HP_enabled) override {
|
||||
microphone_mute(true); // c/m to reduce "plop noise" when changing wm8731_boost_GUI.
|
||||
// chThdSleepMilliseconds(20); // does not help to reduce the "plop noise"
|
||||
microphone_boost((wm8731_boost_GUI < 2) ? 1 : 0); // 1 = Enable Boost (+20 dBs) . 0 = Disable Boost (0dBs).
|
||||
chThdSleepMilliseconds(120); // >50 msegs, very effective , >100 msegs minor improvement ,120 msegs trade off speed .
|
||||
microphone_mute(false);
|
||||
// (void)alc_mode; In prev. fw version , when we did not use at all param., to avoid "unused warning" when compiling.)
|
||||
|
||||
if (mic_to_HP_enabled)
|
||||
microphone_to_HP_enable();
|
||||
else
|
||||
microphone_to_HP_disable();
|
||||
}
|
||||
|
||||
void microphone_disable() override {
|
||||
// TODO: Implement
|
||||
microphone_mute(true);
|
||||
microphone_to_HP_disable();
|
||||
}
|
||||
|
||||
void microphone_to_HP_enable() override {
|
||||
map.r.analog_audio_path_control.sidetone = 1; // Side Tone Switch (Analogue) 1 = Enable Side Tone
|
||||
map.r.analog_audio_path_control.sideatt = 0b00; // Side Tone Attenuation 00 = -6dB
|
||||
write(Register::AnalogAudioPathControl);
|
||||
headphone_enable();
|
||||
}
|
||||
|
||||
void microphone_to_HP_disable() override {
|
||||
map.r.analog_audio_path_control.sidetone = 0; // Side Tone Switch (Analogue) 0 = Disable Side Tone
|
||||
map.r.analog_audio_path_control.sideatt = 0b11; // Side Tone Attenuation 11 = -15dB
|
||||
write(Register::AnalogAudioPathControl);
|
||||
}
|
||||
|
||||
void microphone_boost(const bool boost) {
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 202 B |
+1
-1
Submodule hackrf updated: 50c22aa05b...f5dd48a5bc
@@ -0,0 +1 @@
|
||||
010203040506 00112233445566778899AABBCCDDEEFF 1000
|
||||
@@ -0,0 +1 @@
|
||||
010203040506 190953445220426c7565746f6f7468204c6f7720456e65726779 1000
|
||||
Binary file not shown.
Reference in New Issue
Block a user