kopia lustrzana https://github.com/mobilinkd/tnc3-firmware
Add StdDev/SNR calc for debug.
rodzic
f84a4a289e
commit
6420bd4f58
|
@ -3,7 +3,7 @@
|
||||||
<configuration id="ilg.gnuarmeclipse.managedbuild.cross.config.elf.debug.1309195742.6250637" name="ARM_Debug">
|
<configuration id="ilg.gnuarmeclipse.managedbuild.cross.config.elf.debug.1309195742.6250637" name="ARM_Debug">
|
||||||
<extension point="org.eclipse.cdt.core.LanguageSettingsProvider">
|
<extension point="org.eclipse.cdt.core.LanguageSettingsProvider">
|
||||||
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
|
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
|
||||||
<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="-1332118872860258658" id="ilg.gnuarmeclipse.managedbuild.cross.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT ARM Cross GCC Built-in Compiler Settings " parameter="${COMMAND} ${FLAGS} ${cross_toolchain_flags} -E -P -v -dD "${INPUTS}"" prefer-non-shared="true">
|
<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="-875080106735501948" id="ilg.gnuarmeclipse.managedbuild.cross.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT ARM Cross GCC Built-in Compiler Settings " parameter="${COMMAND} ${FLAGS} ${cross_toolchain_flags} -E -P -v -dD "${INPUTS}"" prefer-non-shared="true">
|
||||||
<language-scope id="org.eclipse.cdt.core.gcc"/>
|
<language-scope id="org.eclipse.cdt.core.gcc"/>
|
||||||
<language-scope id="org.eclipse.cdt.core.g++"/>
|
<language-scope id="org.eclipse.cdt.core.g++"/>
|
||||||
</provider>
|
</provider>
|
||||||
|
@ -14,7 +14,7 @@
|
||||||
<configuration id="ilg.gnuarmeclipse.managedbuild.cross.config.elf.debug.1309195742.6250637.815824991" name="ARM_Release">
|
<configuration id="ilg.gnuarmeclipse.managedbuild.cross.config.elf.debug.1309195742.6250637.815824991" name="ARM_Release">
|
||||||
<extension point="org.eclipse.cdt.core.LanguageSettingsProvider">
|
<extension point="org.eclipse.cdt.core.LanguageSettingsProvider">
|
||||||
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
|
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
|
||||||
<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="-1246452000316836338" id="ilg.gnuarmeclipse.managedbuild.cross.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT ARM Cross GCC Built-in Compiler Settings " parameter="${COMMAND} ${FLAGS} ${cross_toolchain_flags} -E -P -v -dD "${INPUTS}"" prefer-non-shared="true">
|
<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="-789413234192079628" id="ilg.gnuarmeclipse.managedbuild.cross.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT ARM Cross GCC Built-in Compiler Settings " parameter="${COMMAND} ${FLAGS} ${cross_toolchain_flags} -E -P -v -dD "${INPUTS}"" prefer-non-shared="true">
|
||||||
<language-scope id="org.eclipse.cdt.core.gcc"/>
|
<language-scope id="org.eclipse.cdt.core.gcc"/>
|
||||||
<language-scope id="org.eclipse.cdt.core.g++"/>
|
<language-scope id="org.eclipse.cdt.core.g++"/>
|
||||||
</provider>
|
</provider>
|
||||||
|
|
|
@ -895,7 +895,7 @@ static void MX_DAC1_Init(void)
|
||||||
sConfig.DAC_SampleAndHold = DAC_SAMPLEANDHOLD_DISABLE;
|
sConfig.DAC_SampleAndHold = DAC_SAMPLEANDHOLD_DISABLE;
|
||||||
sConfig.DAC_Trigger = DAC_TRIGGER_T7_TRGO;
|
sConfig.DAC_Trigger = DAC_TRIGGER_T7_TRGO;
|
||||||
sConfig.DAC_OutputBuffer = DAC_OUTPUTBUFFER_ENABLE;
|
sConfig.DAC_OutputBuffer = DAC_OUTPUTBUFFER_ENABLE;
|
||||||
sConfig.DAC_ConnectOnChipPeripheral = DAC_CHIPCONNECT_ENABLE;
|
sConfig.DAC_ConnectOnChipPeripheral = DAC_CHIPCONNECT_DISABLE;
|
||||||
sConfig.DAC_UserTrimming = DAC_TRIMMING_FACTORY;
|
sConfig.DAC_UserTrimming = DAC_TRIMMING_FACTORY;
|
||||||
if (HAL_DAC_ConfigChannel(&hdac1, &sConfig, DAC_CHANNEL_1) != HAL_OK)
|
if (HAL_DAC_ConfigChannel(&hdac1, &sConfig, DAC_CHANNEL_1) != HAL_OK)
|
||||||
{
|
{
|
||||||
|
@ -904,9 +904,11 @@ static void MX_DAC1_Init(void)
|
||||||
|
|
||||||
/**DAC channel OUT2 config
|
/**DAC channel OUT2 config
|
||||||
*/
|
*/
|
||||||
|
sConfig.DAC_SampleAndHold = DAC_SAMPLEANDHOLD_DISABLE;
|
||||||
sConfig.DAC_Trigger = DAC_TRIGGER_NONE;
|
sConfig.DAC_Trigger = DAC_TRIGGER_NONE;
|
||||||
sConfig.DAC_ConnectOnChipPeripheral = DAC_CHIPCONNECT_ENABLE;
|
sConfig.DAC_OutputBuffer = DAC_OUTPUTBUFFER_ENABLE;
|
||||||
sConfig.DAC_SampleAndHold = DAC_SAMPLEANDHOLD_ENABLE;
|
sConfig.DAC_ConnectOnChipPeripheral = DAC_CHIPCONNECT_DISABLE;
|
||||||
|
sConfig.DAC_UserTrimming = DAC_TRIMMING_FACTORY;
|
||||||
if (HAL_DAC_ConfigChannel(&hdac1, &sConfig, DAC_CHANNEL_2) != HAL_OK)
|
if (HAL_DAC_ConfigChannel(&hdac1, &sConfig, DAC_CHANNEL_2) != HAL_OK)
|
||||||
{
|
{
|
||||||
_Error_Handler(__FILE__, __LINE__);
|
_Error_Handler(__FILE__, __LINE__);
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
#include "Goertzel.h"
|
#include "Goertzel.h"
|
||||||
#include "AudioInput.hpp"
|
#include "AudioInput.hpp"
|
||||||
#include "GPIO.hpp"
|
#include "GPIO.hpp"
|
||||||
|
#include "Log.h"
|
||||||
|
|
||||||
namespace mobilinkd { namespace tnc {
|
namespace mobilinkd { namespace tnc {
|
||||||
|
|
||||||
|
@ -32,8 +33,31 @@ hdlc::IoFrame* Fsk9600Demodulator::operator()(const q15_t* samples)
|
||||||
if (tmp) hdlc::release(tmp);
|
if (tmp) hdlc::release(tmp);
|
||||||
} else {
|
} else {
|
||||||
result = hdlc_decoder_(nrzi_.decode(lfsr_(bit)), locked_);
|
result = hdlc_decoder_(nrzi_.decode(lfsr_(bit)), locked_);
|
||||||
|
#ifdef KISS_LOGGING
|
||||||
|
if (result) {
|
||||||
|
INFO("samples = %ld, mean = %d, dev = %d",
|
||||||
|
snr_.samples, int(snr_.mean), int(snr_.stdev()));
|
||||||
|
INFO("SNR = %dmB", int(snr_.SNR() * 100.0f));
|
||||||
|
snr_.reset();
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef KISS_LOGGING
|
||||||
|
if (hdlc_decoder_.active())
|
||||||
|
{
|
||||||
|
if (!decoding_)
|
||||||
|
{
|
||||||
|
snr_.reset();
|
||||||
|
decoding_ = true;
|
||||||
|
}
|
||||||
|
snr_.capture(float(abs(sample)));
|
||||||
|
} else {
|
||||||
|
decoding_ = false;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
#include "NRZI.hpp"
|
#include "NRZI.hpp"
|
||||||
#include "HdlcDecoder.hpp"
|
#include "HdlcDecoder.hpp"
|
||||||
#include "KissHardware.hpp"
|
#include "KissHardware.hpp"
|
||||||
|
#include "StandardDeviation.hpp"
|
||||||
|
|
||||||
namespace mobilinkd { namespace tnc {
|
namespace mobilinkd { namespace tnc {
|
||||||
|
|
||||||
|
@ -46,6 +47,8 @@ struct Fsk9600Demodulator : IDemodulator
|
||||||
Descrambler lfsr_;
|
Descrambler lfsr_;
|
||||||
libafsk::NRZI nrzi_;
|
libafsk::NRZI nrzi_;
|
||||||
hdlc::NewDecoder hdlc_decoder_;
|
hdlc::NewDecoder hdlc_decoder_;
|
||||||
|
StandardDeviation snr_;
|
||||||
|
bool decoding_{false};
|
||||||
|
|
||||||
virtual ~Fsk9600Demodulator() {}
|
virtual ~Fsk9600Demodulator() {}
|
||||||
|
|
||||||
|
|
|
@ -205,6 +205,7 @@ struct Encoder {
|
||||||
|
|
||||||
void send_delay() {
|
void send_delay() {
|
||||||
const size_t tmp = tx_delay_ * 1.25 * modulator_->bits_per_ms();
|
const size_t tmp = tx_delay_ * 1.25 * modulator_->bits_per_ms();
|
||||||
|
|
||||||
INFO("Sending %u IDLE bytes", tmp);
|
INFO("Sending %u IDLE bytes", tmp);
|
||||||
for (size_t i = 0; i != tmp; i++) {
|
for (size_t i = 0; i != tmp; i++) {
|
||||||
send_raw(IDLE);
|
send_raw(IDLE);
|
||||||
|
|
|
@ -68,6 +68,11 @@ struct NewDecoder
|
||||||
{
|
{
|
||||||
dcd = config;
|
dcd = config;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool active() const
|
||||||
|
{
|
||||||
|
return state != State::IDLE;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
}}} // mobilinkd::tnc::hdlc
|
}}} // mobilinkd::tnc::hdlc
|
||||||
|
|
|
@ -112,7 +112,7 @@ void reply16(uint8_t cmd, uint16_t result) {
|
||||||
ioport->write(data, 3, 6, osWaitForever);
|
ioport->write(data, 3, 6, osWaitForever);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void reply(uint8_t cmd, const uint8_t* data, uint16_t len) {
|
void reply(uint8_t cmd, const uint8_t* data, uint16_t len) {
|
||||||
uint8_t* buffer = static_cast<uint8_t*>(alloca(len + 1));
|
uint8_t* buffer = static_cast<uint8_t*>(alloca(len + 1));
|
||||||
buffer[0] = cmd;
|
buffer[0] = cmd;
|
||||||
for (uint16_t i = 0; i != len; i++)
|
for (uint16_t i = 0; i != len; i++)
|
||||||
|
|
|
@ -105,6 +105,8 @@ constexpr const uint8_t GET_MAC_ADDRESS = 48;
|
||||||
constexpr const uint8_t GET_DATETIME = 49;
|
constexpr const uint8_t GET_DATETIME = 49;
|
||||||
constexpr const uint8_t SET_DATETIME = 50;
|
constexpr const uint8_t SET_DATETIME = 50;
|
||||||
constexpr const uint8_t GET_ERROR_MSG = 51;
|
constexpr const uint8_t GET_ERROR_MSG = 51;
|
||||||
|
constexpr const uint8_t GET_SNR = 52;
|
||||||
|
constexpr const uint8_t GET_BER = 53;
|
||||||
|
|
||||||
constexpr const uint8_t SET_BLUETOOTH_NAME = 65;
|
constexpr const uint8_t SET_BLUETOOTH_NAME = 65;
|
||||||
constexpr const uint8_t GET_BLUETOOTH_NAME = 66;
|
constexpr const uint8_t GET_BLUETOOTH_NAME = 66;
|
||||||
|
@ -402,4 +404,6 @@ void reply8(uint8_t cmd, uint8_t result) __attribute__((noinline));
|
||||||
|
|
||||||
void reply16(uint8_t cmd, uint16_t result) __attribute__((noinline));
|
void reply16(uint8_t cmd, uint16_t result) __attribute__((noinline));
|
||||||
|
|
||||||
|
void reply(uint8_t cmd, const uint8_t* data, uint16_t len) __attribute__((noinline));
|
||||||
|
|
||||||
}}} // mobilinkd::tnc::kiss
|
}}} // mobilinkd::tnc::kiss
|
||||||
|
|
|
@ -0,0 +1,59 @@
|
||||||
|
// Copyright 2020 Mobilinkd LLC <rob@mobilinkd.com>
|
||||||
|
// All rights reserved.
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "main.h"
|
||||||
|
|
||||||
|
#include <arm_math.h>
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
|
namespace mobilinkd {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compute a running standard deviation.
|
||||||
|
*
|
||||||
|
* Based on https://dsp.stackexchange.com/a/1187/36581
|
||||||
|
*/
|
||||||
|
struct StandardDeviation
|
||||||
|
{
|
||||||
|
float mean{0.0};
|
||||||
|
float S{0.0};
|
||||||
|
uint32_t samples{0};
|
||||||
|
|
||||||
|
void reset()
|
||||||
|
{
|
||||||
|
mean = 0.0;
|
||||||
|
S = 0.0;
|
||||||
|
samples = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void capture(float sample)
|
||||||
|
{
|
||||||
|
auto prev = mean;
|
||||||
|
samples += 1;
|
||||||
|
mean = mean + (sample - mean) / samples;
|
||||||
|
S = S + (sample - mean) * (sample - prev);
|
||||||
|
}
|
||||||
|
|
||||||
|
float variance() const
|
||||||
|
{
|
||||||
|
return samples == 0 ? -1.0 : S / samples;
|
||||||
|
}
|
||||||
|
|
||||||
|
float stdev() const
|
||||||
|
{
|
||||||
|
float result = -1.0;
|
||||||
|
arm_sqrt_f32(variance(), &result);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
// SNR in dB
|
||||||
|
float SNR() const
|
||||||
|
{
|
||||||
|
return 10.0 * log10(mean / stdev());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
} // mobilinkd
|
|
@ -9,4 +9,4 @@ source [find target/stm32l4x.cfg]
|
||||||
|
|
||||||
reset_config srst_only
|
reset_config srst_only
|
||||||
itm port 0 on
|
itm port 0 on
|
||||||
tpiu config internal swv uart off 48000000
|
tpiu config internal swv uart off 80000000
|
||||||
|
|
Ładowanie…
Reference in New Issue