2023-11-28 15:11:30 -05:00
|
|
|
/*
|
|
|
|
* 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 "proc_weather.hpp"
|
|
|
|
#include "portapack_shared_memory.hpp"
|
|
|
|
#include "event_m4.hpp"
|
2024-03-29 16:29:50 -04:00
|
|
|
#include "audio_dma.hpp"
|
2023-11-28 15:11:30 -05:00
|
|
|
|
|
|
|
void WeatherProcessor::execute(const buffer_c8_t& buffer) {
|
|
|
|
if (!configured) return;
|
|
|
|
|
2023-12-08 15:33:48 -05:00
|
|
|
// SR = 4Mhz , and we are decimating by /8 in total , decim1_out clock 4Mhz /8= 500khz samples/sec.
|
|
|
|
// buffer has 2048 complex i8 I,Q signed samples
|
|
|
|
// decim0 out: 2048/4 = 512 complex i16 I,Q signed samples
|
|
|
|
// decim1 out: 512/2 = 256 complex i16 I,Q signed samples
|
|
|
|
// Regarding Filters, we are re-using existing FIR filters, @4Mhz, FIR decim1 ilter, BW =+-220Khz (at -3dB's). BW = 440kHZ.
|
|
|
|
|
|
|
|
const auto decim_0_out = decim_0.execute(buffer, dst_buffer); // Input:2048 complex/4 (decim factor) = 512_output complex (1024 I/Q samples)
|
|
|
|
const auto decim_1_out = decim_1.execute(decim_0_out, dst_buffer); // Input:512 complex/2 (decim factor) = 256_output complex ( 512 I/Q samples)
|
|
|
|
|
|
|
|
for (size_t i = 0; i < decim_1_out.count; i++) {
|
|
|
|
int16_t re = decim_1_out.p[i].real();
|
|
|
|
int16_t im = decim_1_out.p[i].imag();
|
2023-11-28 15:11:30 -05:00
|
|
|
uint32_t mag = ((uint32_t)re * (uint32_t)re) + ((uint32_t)im * (uint32_t)im);
|
2023-12-08 15:33:48 -05:00
|
|
|
|
|
|
|
mag = (mag >> 12); // Decim samples are calculated with saturated gain . (we could also reduce that sat. param at configure time)
|
|
|
|
|
2023-11-28 15:11:30 -05:00
|
|
|
bool meashl = (mag > threshold);
|
|
|
|
tm += mag;
|
Subghz decoder (#1646)
* Initial commit - wip
* Half part of the transition of baseband processor.
* More SGD
* WIP, Weather refactor, UI improv
* Rename
* Added 4msps, and fixes
* Fixes
* princeton working
* Renamed proc_weather, bc now multifunctional
* Proto: bett
* FPS_CAME = 4,
FPS_PRASTEL = 5,
FPS_AIRFORCE = 6,
* Came Atomo, fixes
* Separate weather and sgd, bc of baseband size limit
* Fix display
* Save space
* More protos
* Dooya proto added
* More protos
* add protos
* More protos
* Move weather to ext app
* nw
* Revert "Move weather to ext app"
This reverts commit 8a84aac2f59274b72de7c7803deb137a21838076.
* revert
* Fix merge
* Better naming
* More protos
* More protos
* Add protos
* Fix warning
* Add NeroRadio
* more protos
* more protos
* More protos
* Shrink a bit
* fixes
* More protos
* Nicer code
* Fix naming
* Fix format
* Remove unused
* Fix some protos, that needs a LOOOONG part with the same lo/high
* Modify key calculation
2023-12-16 17:37:51 -05:00
|
|
|
if (meashl == currentHiLow && currentDuration < 30'000'000) // allow pass 'end' signal
|
2023-11-28 15:11:30 -05:00
|
|
|
{
|
2023-12-21 13:33:06 -05:00
|
|
|
currentDuration += nsPerDecSamp;
|
2023-11-28 15:11:30 -05:00
|
|
|
} else { // called on change, so send the last duration and dir.
|
Subghz decoder (#1646)
* Initial commit - wip
* Half part of the transition of baseband processor.
* More SGD
* WIP, Weather refactor, UI improv
* Rename
* Added 4msps, and fixes
* Fixes
* princeton working
* Renamed proc_weather, bc now multifunctional
* Proto: bett
* FPS_CAME = 4,
FPS_PRASTEL = 5,
FPS_AIRFORCE = 6,
* Came Atomo, fixes
* Separate weather and sgd, bc of baseband size limit
* Fix display
* Save space
* More protos
* Dooya proto added
* More protos
* add protos
* More protos
* Move weather to ext app
* nw
* Revert "Move weather to ext app"
This reverts commit 8a84aac2f59274b72de7c7803deb137a21838076.
* revert
* Fix merge
* Better naming
* More protos
* More protos
* Add protos
* Fix warning
* Add NeroRadio
* more protos
* more protos
* More protos
* Shrink a bit
* fixes
* More protos
* Nicer code
* Fix naming
* Fix format
* Remove unused
* Fix some protos, that needs a LOOOONG part with the same lo/high
* Modify key calculation
2023-12-16 17:37:51 -05:00
|
|
|
if (protoList) protoList->feed(currentHiLow, currentDuration / 1000);
|
2023-12-10 17:40:11 -05:00
|
|
|
currentDuration = nsPerDecSamp;
|
2023-11-28 15:11:30 -05:00
|
|
|
currentHiLow = meashl;
|
|
|
|
}
|
|
|
|
}
|
2023-12-08 15:33:48 -05:00
|
|
|
|
|
|
|
cnt += decim_1_out.count; // TODO , check if it is necessary that xdecim factor.
|
Subghz decoder (#1646)
* Initial commit - wip
* Half part of the transition of baseband processor.
* More SGD
* WIP, Weather refactor, UI improv
* Rename
* Added 4msps, and fixes
* Fixes
* princeton working
* Renamed proc_weather, bc now multifunctional
* Proto: bett
* FPS_CAME = 4,
FPS_PRASTEL = 5,
FPS_AIRFORCE = 6,
* Came Atomo, fixes
* Separate weather and sgd, bc of baseband size limit
* Fix display
* Save space
* More protos
* Dooya proto added
* More protos
* add protos
* More protos
* Move weather to ext app
* nw
* Revert "Move weather to ext app"
This reverts commit 8a84aac2f59274b72de7c7803deb137a21838076.
* revert
* Fix merge
* Better naming
* More protos
* More protos
* Add protos
* Fix warning
* Add NeroRadio
* more protos
* more protos
* More protos
* Shrink a bit
* fixes
* More protos
* Nicer code
* Fix naming
* Fix format
* Remove unused
* Fix some protos, that needs a LOOOONG part with the same lo/high
* Modify key calculation
2023-12-16 17:37:51 -05:00
|
|
|
if (cnt > 90'000) {
|
2023-11-28 15:11:30 -05:00
|
|
|
threshold = (tm / cnt) / 2;
|
|
|
|
cnt = 0;
|
|
|
|
tm = 0;
|
|
|
|
if (threshold < 50) threshold = 50;
|
|
|
|
if (threshold > 1700) threshold = 1700;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void WeatherProcessor::on_message(const Message* const message) {
|
2024-03-29 16:29:50 -04:00
|
|
|
switch (message->id) {
|
|
|
|
case Message::ID::SubGhzFPRxConfigure:
|
|
|
|
configure(*reinterpret_cast<const SubGhzFPRxConfigureMessage*>(message));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Message::ID::AudioBeep:
|
|
|
|
on_beep_message(*reinterpret_cast<const AudioBeepMessage*>(message));
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2023-11-28 15:11:30 -05:00
|
|
|
}
|
|
|
|
|
Subghz decoder (#1646)
* Initial commit - wip
* Half part of the transition of baseband processor.
* More SGD
* WIP, Weather refactor, UI improv
* Rename
* Added 4msps, and fixes
* Fixes
* princeton working
* Renamed proc_weather, bc now multifunctional
* Proto: bett
* FPS_CAME = 4,
FPS_PRASTEL = 5,
FPS_AIRFORCE = 6,
* Came Atomo, fixes
* Separate weather and sgd, bc of baseband size limit
* Fix display
* Save space
* More protos
* Dooya proto added
* More protos
* add protos
* More protos
* Move weather to ext app
* nw
* Revert "Move weather to ext app"
This reverts commit 8a84aac2f59274b72de7c7803deb137a21838076.
* revert
* Fix merge
* Better naming
* More protos
* More protos
* Add protos
* Fix warning
* Add NeroRadio
* more protos
* more protos
* More protos
* Shrink a bit
* fixes
* More protos
* Nicer code
* Fix naming
* Fix format
* Remove unused
* Fix some protos, that needs a LOOOONG part with the same lo/high
* Modify key calculation
2023-12-16 17:37:51 -05:00
|
|
|
void WeatherProcessor::configure(const SubGhzFPRxConfigureMessage& message) {
|
2023-12-21 13:33:06 -05:00
|
|
|
baseband_fs = message.sampling_rate;
|
|
|
|
baseband_thread.set_sampling_rate(baseband_fs);
|
|
|
|
nsPerDecSamp = 1'000'000'000 / baseband_fs * 8; // Scaled it due to less array buffer sampes due to /8 decimation. 250 nseg (4Mhz) * 8
|
|
|
|
|
Subghz decoder (#1646)
* Initial commit - wip
* Half part of the transition of baseband processor.
* More SGD
* WIP, Weather refactor, UI improv
* Rename
* Added 4msps, and fixes
* Fixes
* princeton working
* Renamed proc_weather, bc now multifunctional
* Proto: bett
* FPS_CAME = 4,
FPS_PRASTEL = 5,
FPS_AIRFORCE = 6,
* Came Atomo, fixes
* Separate weather and sgd, bc of baseband size limit
* Fix display
* Save space
* More protos
* Dooya proto added
* More protos
* add protos
* More protos
* Move weather to ext app
* nw
* Revert "Move weather to ext app"
This reverts commit 8a84aac2f59274b72de7c7803deb137a21838076.
* revert
* Fix merge
* Better naming
* More protos
* More protos
* Add protos
* Fix warning
* Add NeroRadio
* more protos
* more protos
* More protos
* Shrink a bit
* fixes
* More protos
* Nicer code
* Fix naming
* Fix format
* Remove unused
* Fix some protos, that needs a LOOOONG part with the same lo/high
* Modify key calculation
2023-12-16 17:37:51 -05:00
|
|
|
// constexpr size_t decim_0_output_fs = baseband_fs / decim_0.decimation_factor; //unused
|
|
|
|
// constexpr size_t decim_1_output_fs = decim_0_output_fs / decim_1.decimation_factor; //unused
|
2023-12-08 15:33:48 -05:00
|
|
|
|
|
|
|
decim_0.configure(taps_200k_wfm_decim_0.taps);
|
|
|
|
decim_1.configure(taps_200k_wfm_decim_1.taps);
|
|
|
|
|
2023-11-28 15:11:30 -05:00
|
|
|
configured = true;
|
|
|
|
}
|
|
|
|
|
2024-03-29 16:29:50 -04:00
|
|
|
void WeatherProcessor::on_beep_message(const AudioBeepMessage& message) {
|
|
|
|
audio::dma::beep_start(message.freq, message.sample_rate, message.duration_ms);
|
|
|
|
}
|
|
|
|
|
2023-11-28 15:11:30 -05:00
|
|
|
int main() {
|
2024-03-29 16:29:50 -04:00
|
|
|
audio::dma::init_audio_out();
|
2023-11-28 15:11:30 -05:00
|
|
|
EventDispatcher event_dispatcher{std::make_unique<WeatherProcessor>()};
|
|
|
|
event_dispatcher.run();
|
|
|
|
return 0;
|
|
|
|
}
|