Skip to content

Commit

Permalink
Radiosonde beep tone tweaks (#2020)
Browse files Browse the repository at this point in the history
* Tweak RSSI audio beep frequency range
* Clang & changed min freq
* Save beep/log/crc settings in .ini file
* Update copyright string
* Added generic audio_beep message
  • Loading branch information
NotherNgineer authored Mar 21, 2024
1 parent 8391ca8 commit 4aeaf94
Show file tree
Hide file tree
Showing 9 changed files with 99 additions and 36 deletions.
6 changes: 3 additions & 3 deletions firmware/application/apps/ui_mictx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,9 @@ void MicTXView::set_tx(bool enable) {
portapack::pin_i2s0_rx_sda.mode(3); // This is already done in audio::init but gets changed by the CPLD overlay reprogramming
} else {
if (transmitting && rogerbeep_enabled) {
baseband::request_beep(); // Transmit the roger beep
transmitting = false; // And flag the end of the transmission so ...
} else { // (if roger beep was enabled, this will be executed after the beep ends transmitting.
baseband::request_roger_beep(); // Transmit the roger beep
transmitting = false; // Flag the end of the transmission (transmitter will be disabled after the beep)
} else {
transmitting = false;
configure_baseband();
transmitter_model.disable();
Expand Down
10 changes: 7 additions & 3 deletions firmware/application/apps/ui_sonde.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*
* Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc.
* Copyright (C) 2017 Furrtek
* Copyright (C) 2024 Mark Thompson
*
* This file is part of PortaPack.
*
Expand Down Expand Up @@ -70,16 +71,19 @@ SondeView::SondeView(NavigationView& nav)

geopos.set_read_only(true);

check_beep.set_value(beep);
check_beep.on_select = [this](Checkbox&, bool v) {
beep = v;
if (v)
baseband::request_beep();
if (beep)
baseband::request_audio_beep(1000, 60); // 1khz tone for 60ms to acknowledge enablement
};

check_log.set_value(logging);
check_log.on_select = [this](Checkbox&, bool v) {
logging = v;
};

check_crc.set_value(use_crc);
check_crc.on_select = [this](Checkbox&, bool v) {
use_crc = v;
};
Expand Down Expand Up @@ -222,7 +226,7 @@ void SondeView::on_packet(const sonde::Packet& packet) {
}

if (beep) {
baseband::request_beep();
baseband::request_rssi_beep();
}
}
}
Expand Down
15 changes: 11 additions & 4 deletions firmware/application/apps/ui_sonde.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*
* Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc.
* Copyright (C) 2017 Furrtek
* Copyright (C) 2024 Mark Thompson
*
* This file is part of PortaPack.
*
Expand Down Expand Up @@ -74,13 +75,19 @@ class SondeView : public View {
1750000 /* bandwidth */,
2457600 /* sampling rate */
};
bool beep{false};
bool logging{false};
bool use_crc{false};
app_settings::SettingsManager settings_{
"rx_sonde", app_settings::Mode::RX};
"rx_sonde",
app_settings::Mode::RX,
{
{"beep"sv, &beep},
{"logging"sv, &logging},
{"use_crc"sv, &use_crc},
}};

std::unique_ptr<SondeLogger> logger{};
bool logging{false};
bool use_crc{false};
bool beep{false};

char geo_uri[32] = {};

Expand Down
21 changes: 19 additions & 2 deletions firmware/application/baseband_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -428,8 +428,25 @@ void replay_stop() {
send_message(&message);
}

void request_beep() {
RequestSignalMessage message{RequestSignalMessage::Signal::BeepRequest};
void request_beep(RequestSignalMessage::Signal beep_type) {
RequestSignalMessage message{beep_type};
send_message(&message);
}

void request_roger_beep() {
request_beep(RequestSignalMessage::Signal::RogerBeepRequest);
}

void request_rssi_beep() {
request_beep(RequestSignalMessage::Signal::RSSIBeepRequest);
}

void request_beep_stop() {
request_beep(RequestSignalMessage::Signal::BeepStopRequest);
}

void request_audio_beep(uint32_t freq, uint32_t duration_ms) {
AudioBeepMessage message{freq, duration_ms};
send_message(&message);
}

Expand Down
6 changes: 5 additions & 1 deletion firmware/application/baseband_api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,11 @@ void set_siggen_tone(const uint32_t tone);
void set_siggen_config(const uint32_t bw, const uint32_t shape, const uint32_t duration);
void set_spectrum_painter_config(const uint16_t width, const uint16_t height, bool update, int32_t bw);
void set_subghzd_config(uint8_t modulation, uint32_t sampling_rate);
void request_beep();

void request_roger_beep();
void request_rssi_beep();
void request_beep_stop();
void request_audio_beep(uint32_t freq, uint32_t duration_ms);

void run_image(const portapack::spi_flash::image_tag_t image_tag);
void run_prepared_image(const uint32_t m4_code);
Expand Down
2 changes: 1 addition & 1 deletion firmware/baseband/proc_mictx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ void MicTXProcessor::on_message(const Message* const msg) {
break;

case Message::ID::RequestSignal:
if (request_message.signal == RequestSignalMessage::Signal::BeepRequest) {
if (request_message.signal == RequestSignalMessage::Signal::RogerBeepRequest) {
beep_index = 0;
beep_timer = 0;
play_beep = true;
Expand Down
46 changes: 29 additions & 17 deletions firmware/baseband/proc_sonde.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,35 +57,47 @@ void SondeProcessor::execute(const buffer_c8_t& buffer) {
void SondeProcessor::on_message(const Message* const msg) {
switch (msg->id) {
case Message::ID::RequestSignal:
if ((*reinterpret_cast<const RequestSignalMessage*>(msg)).signal == RequestSignalMessage::Signal::BeepRequest) {
float rssi_ratio = (float)last_rssi / (float)RSSI_CEILING;
uint32_t beep_duration = 0;

if (rssi_ratio <= PROPORTIONAL_BEEP_THRES) {
beep_duration = BEEP_MIN_DURATION;
} else if (rssi_ratio < 1) {
beep_duration = (int)rssi_ratio * BEEP_DURATION_RANGE + BEEP_MIN_DURATION;
} else {
beep_duration = BEEP_DURATION_RANGE + BEEP_MIN_DURATION;
}

audio::dma::beep_start(beep_freq, AUDIO_SAMPLE_RATE, beep_duration);
}
on_signal_message(*reinterpret_cast<const RequestSignalMessage*>(msg));
break;

case Message::ID::AudioBeep:
on_beep_message(*reinterpret_cast<const AudioBeepMessage*>(msg));
break;

case Message::ID::PitchRSSIConfigure:
pitch_rssi_config(*reinterpret_cast<const PitchRSSIConfigureMessage*>(msg));
on_pitch_rssi_config(*reinterpret_cast<const PitchRSSIConfigureMessage*>(msg));
break;

default:
break;
}
}

void SondeProcessor::pitch_rssi_config(const PitchRSSIConfigureMessage& message) {
void SondeProcessor::on_signal_message(const RequestSignalMessage& message) {
if (message.signal == RequestSignalMessage::Signal::RSSIBeepRequest) {
float rssi_ratio = (float)last_rssi / RSSI_CEILING;
uint32_t beep_duration = 0;

if (rssi_ratio <= PROPORTIONAL_BEEP_THRES) {
beep_duration = BEEP_MIN_DURATION;
} else if (rssi_ratio < 1) {
beep_duration = rssi_ratio * BEEP_DURATION_RANGE + BEEP_MIN_DURATION;
} else {
beep_duration = BEEP_DURATION_RANGE + BEEP_MIN_DURATION;
}

audio::dma::beep_start(beep_freq, AUDIO_SAMPLE_RATE, beep_duration);
}
}

void SondeProcessor::on_beep_message(const AudioBeepMessage& message) {
audio::dma::beep_start(message.freq, AUDIO_SAMPLE_RATE, message.duration_ms);
}

void SondeProcessor::on_pitch_rssi_config(const PitchRSSIConfigureMessage& message) {
pitch_rssi_enabled = message.enabled;

beep_freq = (int)((float)message.rssi * (float)RSSI_PITCH_WEIGHT + (float)BEEP_BASE_FREQ);
beep_freq = message.rssi * RSSI_PITCH_WEIGHT + BEEP_BASE_FREQ;
last_rssi = message.rssi;
}

Expand Down
10 changes: 7 additions & 3 deletions firmware/baseband/proc_sonde.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,12 @@

#define BEEP_MIN_DURATION 60
#define BEEP_DURATION_RANGE 100
#define BEEP_BASE_FREQ 200
#define BEEP_BASE_FREQ 400 // Lowest audible freq for some PortaPack speakers
#define BEEP_MAX_FREQ 8000 // Highest audible freq for some PortaPack speakers
#define BEEP_SIMPLE_FREQ 1000
#define RSSI_CEILING 1000
#define PROPORTIONAL_BEEP_THRES 0.8
#define RSSI_PITCH_WEIGHT 0.5
#define RSSI_PITCH_WEIGHT (float(BEEP_MAX_FREQ - BEEP_BASE_FREQ) / RSSI_CEILING)
#define AUDIO_SAMPLE_RATE 24000

class SondeProcessor : public BasebandProcessor {
Expand Down Expand Up @@ -168,7 +170,9 @@ class SondeProcessor : public BasebandProcessor {
baseband_fs, this, baseband::Direction::Receive, /*auto_start*/ false};
RSSIThread rssi_thread{};

void pitch_rssi_config(const PitchRSSIConfigureMessage& message);
void on_signal_message(const RequestSignalMessage& message);
void on_beep_message(const AudioBeepMessage& message);
void on_pitch_rssi_config(const PitchRSSIConfigureMessage& message);
};

#endif /*__PROC_ERT_H__*/
19 changes: 17 additions & 2 deletions firmware/common/message.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ class Message {
GPSPosData = 63,
OrientationData = 64,
EnvironmentData = 65,
AudioBeep = 66,
MAX
};

Expand Down Expand Up @@ -1165,8 +1166,10 @@ class RequestSignalMessage : public Message {
public:
enum class Signal : char {
FillRequest = 1,
BeepRequest = 2,
Squelched = 3
RogerBeepRequest = 2,
RSSIBeepRequest = 3,
BeepStopRequest = 4,
Squelched = 5,
};

constexpr RequestSignalMessage(
Expand Down Expand Up @@ -1361,4 +1364,16 @@ class EnvironmentDataMessage : public Message {
uint16_t light = 0; // lux
};

class AudioBeepMessage : public Message {
public:
constexpr AudioBeepMessage(
uint32_t freq = 1000,
uint32_t duration_ms = 100)
: Message{ID::AudioBeep},
freq{freq},
duration_ms{duration_ms} {
}
uint32_t freq = 1000;
uint32_t duration_ms = 100;
};
#endif /*__MESSAGE_H__*/

0 comments on commit 4aeaf94

Please sign in to comment.