Skip to content

Commit 8ce380b

Browse files
committed
Added dump debug parameters.
1 parent 7fca517 commit 8ce380b

File tree

10 files changed

+42
-21
lines changed

10 files changed

+42
-21
lines changed

sources/arg_config.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,6 @@ struct ArgConfig {
1313
std::string mqttPassword;
1414
std::string workDir = ".";
1515
bool enumerateRemote = false;
16+
bool dumpSource = false;
17+
bool dumpRecording = false;
1618
};

sources/config.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,7 @@ std::string Config::latitude() const { return m_fileConfig.position.latitude; }
5959
std::string Config::longitude() const { return m_fileConfig.position.longitude; }
6060
int Config::altitude() const { return m_fileConfig.position.altitude; }
6161

62-
std::string Config::workDir() const { return m_argConfig.workDir; }
62+
std::string Config::workDir() const { return m_argConfig.workDir; }
63+
64+
bool Config::dumpSource() const { return m_argConfig.dumpSource; }
65+
bool Config::dumpRecording() const { return m_argConfig.dumpRecording; }

sources/config.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@
1010
#include <string>
1111

1212
// INTERNAL SETTINGS
13-
constexpr auto DEBUG_SAVE_FULL_RAW_IQ = false; // save orgignal sdr data as raw iq
14-
constexpr auto DEBUG_SAVE_FULL_POWER = false; // save orgignal sdr data as raw iq
15-
constexpr auto DEBUG_SAVE_RECORDING_RAW_IQ = false; // save recordings as raw iq
1613
constexpr auto INITIAL_DELAY = std::chrono::milliseconds(1000); // delay after first start sdr device to start processing
1714
constexpr auto PERFORMANCE_LOGGER_INTERVAL = 1000; // print stats every n frames
1815
constexpr auto RECORDER_FLUSH_INTERVAL = std::chrono::milliseconds(100); // flush recordings to mqtt every 2 * n bytes
@@ -70,6 +67,8 @@ class Config {
7067
int altitude() const;
7168

7269
std::string workDir() const;
70+
bool dumpSource() const;
71+
bool dumpRecording() const;
7372

7473
private:
7574
const std::string m_id;

sources/main.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ int main(int argc, char** argv) {
3131
app.add_option("--mqtt-password", argConfig.mqttPassword, "mqtt password")->required();
3232
app.add_option("--work-dir", argConfig.workDir, "work directory");
3333
app.add_option("--remote", argConfig.enumerateRemote, "enable remote device enumeration");
34+
app.add_option("--dump-source", argConfig.dumpSource, "dump source raw IQ");
35+
app.add_option("--dump-recording", argConfig.dumpRecording, "dump recording raw IQ");
3436
CLI11_PARSE(app, argc, argv);
3537

3638
dup2(fileno(fopen("/dev/null", "w")), fileno(stderr));

sources/radio/recorder.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
constexpr auto LABEL = "recorder";
1515

16-
Recorder::Recorder(const Config& config, const std::string& zeromq, Frequency sampleRate, const Recording& recording, std::function<void(const nlohmann::json&)> send)
16+
Recorder::Recorder(const Config& config, const Device& device, const std::string& zeromq, Frequency sampleRate, const Recording& recording, std::function<void(const nlohmann::json&)> send)
1717
: m_config(config), m_sampleRate(sampleRate), m_recording(recording), m_send(send), m_tb(gr::make_top_block("recorder")), m_connector(m_tb) {
1818
Logger::info(
1919
LABEL,
@@ -44,8 +44,8 @@ Recorder::Recorder(const Config& config, const std::string& zeromq, Frequency sa
4444
blocks.push_back(m_buffer);
4545
m_connector.connect(blocks);
4646

47-
if (DEBUG_SAVE_RECORDING_RAW_IQ) {
48-
const auto fileName = getRawFileName("recording", "fc", m_recording.recordingFrequency, m_recording.bandwidth);
47+
if (config.dumpRecording()) {
48+
const auto fileName = getRawFileName(config.workDir(), device, "recording", "fc", m_recording.recordingFrequency, m_recording.bandwidth);
4949
m_connector.connect<Block>(lastResampler, gr::blocks::file_sink::make(sizeof(gr_complex), fileName.c_str()));
5050
}
5151

sources/radio/recorder.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class Recorder {
1818
Recorder(const Recorder&) = delete;
1919
Recorder& operator=(const Recorder&) = delete;
2020

21-
Recorder(const Config& config, const std::string& zeromq, Frequency sampleRate, const Recording& recording, std::function<void(const nlohmann::json&)> send);
21+
Recorder(const Config& config, const Device& device, const std::string& zeromq, Frequency sampleRate, const Recording& recording, std::function<void(const nlohmann::json&)> send);
2222
~Recorder();
2323

2424
Recording getRecording() const;

sources/radio/sdr_device.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <config.h>
44
#include <gnuradio/block_detail.h>
55
#include <gnuradio/blocks/copy.h>
6+
#include <gnuradio/blocks/file_sink.h>
67
#include <gnuradio/blocks/null_sink.h>
78
#include <gnuradio/soapy/source.h>
89
#include <gnuradio/zeromq/pub_sink.h>
@@ -46,6 +47,11 @@ SdrDevice::SdrDevice(const Config& config, const Device& device, RemoteControlle
4647
m_processorIndex[range.center()] = index++;
4748
}
4849

50+
if (config.dumpSource()) {
51+
const auto fileName = getRawFileName(config.workDir(), device, "source-all", "fc", ranges.front().center(), device.sample_rate);
52+
m_connector.connect<Block>(m_source, gr::blocks::file_sink::make(sizeof(gr_complex), fileName.c_str()));
53+
}
54+
4955
m_tb->start();
5056
Logger::info(LABEL, "started");
5157
}
@@ -110,7 +116,7 @@ void SdrDevice::updateRecordings(const std::vector<Recording> recordings) {
110116
if (m_recorders.size() < static_cast<size_t>(m_config.recordersCount())) {
111117
const auto sampleRate = m_device.sample_rate;
112118
m_recorders.push_back(
113-
std::make_unique<Recorder>(m_config, m_zeromq, sampleRate, recording, std::bind(&RemoteController::sendTransmission, m_remoteController, m_device, std::placeholders::_1)));
119+
std::make_unique<Recorder>(m_config, m_device, m_zeromq, sampleRate, recording, std::bind(&RemoteController::sendTransmission, m_remoteController, m_device, std::placeholders::_1)));
114120
} else {
115121
if (!ignoredTransmissions.count(recording.recordingFrequency)) {
116122
Logger::info(LABEL, "maximum recorders limit reached, frequency: {}", formatFrequency(recording.recordingFrequency, RED));

sources/radio/sdr_processor.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,8 @@ SdrProcessor::SdrProcessor(
5252
const auto spectrogram = std::make_shared<Spectrogram>(fftSize, sampleRate, getFrequency, sendSpectrogram);
5353
m_connector.connect<Block>(psd, spectrogram);
5454

55-
if (DEBUG_SAVE_FULL_POWER) {
56-
const auto fileName = getRawFileName("full", "power", frequencyRange.center(), device.sample_rate);
57-
m_connector.connect<Block>(psd, gr::blocks::file_sink::make(sizeof(float) * fftSize, fileName.c_str()));
58-
}
59-
60-
if (DEBUG_SAVE_FULL_RAW_IQ) {
61-
const auto fileName = getRawFileName("full", "fc", frequencyRange.center(), device.sample_rate);
55+
if (config.dumpSource()) {
56+
const auto fileName = getRawFileName(config.workDir(), device, "source", "fc", frequencyRange.center(), device.sample_rate);
6257
m_connector.connect<Block>(source, gr::blocks::file_sink::make(sizeof(gr_complex), fileName.c_str()));
6358
}
6459
}

sources/utils/radio_utils.cpp

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <logger.h>
44
#include <utils/utils.h>
55

6+
#include <filesystem>
67
#include <numeric>
78

89
namespace {
@@ -77,12 +78,25 @@ void setNoData(float* data, const int size) {
7778
}
7879
}
7980

80-
std::string getRawFileName(const char* label, const char* extension, Frequency frequency, Frequency sampleRate) {
81-
char buf[1024];
81+
std::string getRawFileName(const std::string& dir, const Device& device, const char* label, const char* extension, Frequency frequency, Frequency sampleRate) {
82+
const auto path = std::filesystem::canonical(dir.c_str());
8283
time_t rawtime = time(nullptr);
8384
struct tm* tm = localtime(&rawtime);
84-
snprintf(buf, 1024, "./%s_%04d%02d%02d_%02d%02d%02d_%d_%d_%s.raw", label, tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec, frequency, sampleRate, extension);
85-
return buf;
85+
return fmt::format(
86+
"{}/{}-{}-{}_{:04d}{:02d}{:02d}_{:02d}{:02d}{:02d}_{}_{}_{}.raw",
87+
path.c_str(),
88+
device.driver,
89+
device.serial,
90+
label,
91+
tm->tm_year + 1900,
92+
tm->tm_mon + 1,
93+
tm->tm_mday,
94+
tm->tm_hour,
95+
tm->tm_min,
96+
tm->tm_sec,
97+
frequency,
98+
sampleRate,
99+
extension);
86100
}
87101

88102
Frequency getTunedFrequency(Frequency frequency, Frequency step) {

sources/utils/radio_utils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ std::string formatPower(const float power, const char* color = nullptr);
1010

1111
void setNoData(float* data, const int size);
1212

13-
std::string getRawFileName(const char* label, const char* extension, Frequency frequency, Frequency sampleRate);
13+
std::string getRawFileName(const std::string& dir, const Device& device, const char* label, const char* extension, Frequency frequency, Frequency sampleRate);
1414

1515
Frequency getTunedFrequency(Frequency frequency, Frequency step);
1616

0 commit comments

Comments
 (0)