Skip to content

Commit 7fca517

Browse files
committed
Fixed device_name, source, name in spectrogram and transmission mqtt messages.
1 parent 9f6bf9f commit 7fca517

File tree

10 files changed

+40
-20
lines changed

10 files changed

+40
-20
lines changed

sources/config.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ constexpr auto SPECTROGRAM_PREFERRED_MAX_STEP = 1000; //
3636
constexpr auto SPECTROGRAM_MAX_FFT = 16384; // spectrogram fft limit
3737
constexpr auto SPECTROGRAM_SEND_INTERVAL = std::chrono::milliseconds(1000); // send spectrogram data interval
3838

39+
// SOURCE AND RECORDING NAMES
40+
constexpr auto GAIN_TESTER_SOURCE_NAME = "gain tester";
41+
constexpr auto GAIN_TESTER_RECORDING_NAME = "auto";
42+
constexpr auto SCANNER_SOURCE_NAME = "scanner";
43+
constexpr auto SCANNER_RECORDING_NAME = "auto";
44+
3945
class Config {
4046
public:
4147
Config(const ArgConfig& argConfig, const FileConfig& fileConfig);

sources/network/remote_controller.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,14 @@ void RemoteController::resetTmpConfigResponse(const bool& success) { m_mqtt.publ
3232
void RemoteController::setTmpConfigQuery(const Mqtt::JsonCallback& callback) { m_mqtt.setJsonMessageCallback(fmt::format("sdr/{}/{}", TMP_CONFIG, m_config.getId()), callback); }
3333
void RemoteController::setTmpConfigResponse(const bool& success) { m_mqtt.publish(fmt::format("sdr/{}/{}/{}", TMP_CONFIG, m_config.getId(), success ? SUCCESS : FAILED), "", 2); }
3434

35-
void RemoteController::schedulerQuery(const std::string& device, const std::string& query) { m_mqtt.publish(fmt::format("sdr/{}/{}/{}/get", SCHEDULER, m_config.getId(), device), query, 2); }
36-
void RemoteController::schedulerCallback(const std::string& device, const Mqtt::JsonCallback& callback) {
37-
m_mqtt.setJsonMessageCallback(fmt::format("sdr/{}/{}/{}/set", SCHEDULER, m_config.getId(), device), callback);
35+
void RemoteController::schedulerQuery(const Device& device, const std::string& query) { m_mqtt.publish(fmt::format("sdr/{}/{}/{}/get", SCHEDULER, m_config.getId(), device.getName()), query, 2); }
36+
void RemoteController::schedulerCallback(const Device& device, const Mqtt::JsonCallback& callback) {
37+
m_mqtt.setJsonMessageCallback(fmt::format("sdr/{}/{}/{}/set", SCHEDULER, m_config.getId(), device.getName()), callback);
3838
}
3939

40-
void RemoteController::sendSpectrogram(const std::string& device, const nlohmann::json& json) { m_mqtt.publish(fmt::format("sdr/{}/{}/{}", SPECTROGRAM, m_config.getId(), device), json.dump(), 2); }
41-
void RemoteController::sendTransmission(const std::string& device, const nlohmann::json& json) { m_mqtt.publish(fmt::format("sdr/{}/{}/{}", TRANSMISSION, m_config.getId(), device), json.dump(), 2); }
40+
void RemoteController::sendSpectrogram(const Device& device, const nlohmann::json& json) {
41+
m_mqtt.publish(fmt::format("sdr/{}/{}/{}", SPECTROGRAM, m_config.getId(), device.getAliasName()), json.dump(), 2);
42+
}
43+
void RemoteController::sendTransmission(const Device& device, const nlohmann::json& json) {
44+
m_mqtt.publish(fmt::format("sdr/{}/{}/{}", TRANSMISSION, m_config.getId(), device.getAliasName()), json.dump(), 2);
45+
}

sources/network/remote_controller.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include <config.h>
44
#include <network/mqtt.h>
5+
#include <radio/help_structures.h>
56

67
#include <functional>
78
#include <nlohmann/json.hpp>
@@ -22,11 +23,11 @@ class RemoteController {
2223
void setTmpConfigQuery(const Mqtt::JsonCallback& callback);
2324
void setTmpConfigResponse(const bool& success);
2425

25-
void schedulerQuery(const std::string& device, const std::string& query);
26-
void schedulerCallback(const std::string& device, const Mqtt::JsonCallback& callback);
26+
void schedulerQuery(const Device& device, const std::string& query);
27+
void schedulerCallback(const Device& device, const Mqtt::JsonCallback& callback);
2728

28-
void sendSpectrogram(const std::string& device, const nlohmann::json& json);
29-
void sendTransmission(const std::string& device, const nlohmann::json& json);
29+
void sendSpectrogram(const Device& device, const nlohmann::json& json);
30+
void sendTransmission(const Device& device, const nlohmann::json& json);
3031

3132
private:
3233
void listCallback(const std::string& data);

sources/radio/blocks/spectrogram.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,13 @@
22

33
#include <config.h>
44
#include <logger.h>
5-
#include <network/query.h>
65
#include <utils/utils.h>
76

87
constexpr auto LABEL = "spectogram";
98

109
Spectrogram::Container::Container(int size) : m_counter(0), m_lastDataSendTime(getTime()) { m_sum.resize(size); }
1110

12-
Spectrogram::Spectrogram(const int itemSize, const Frequency sampleRate, std::function<Frequency()> getFrequency, std::function<void(const nlohmann::json&)> send)
11+
Spectrogram::Spectrogram(const int itemSize, const Frequency sampleRate, std::function<Frequency()> getFrequency, SendFunction send)
1312
: gr::sync_block("Spectrogram", gr::io_signature::make(1, 1, sizeof(float) * itemSize), gr::io_signature::make(0, 0, 0)),
1413
m_inputSize(itemSize),
1514
m_outputSize(std::min(SPECTROGRAM_MAX_FFT, getFft(sampleRate, SPECTROGRAM_PREFERRED_MAX_STEP))),
@@ -68,8 +67,7 @@ void Spectrogram::send(Container& container) {
6867
for (int j = 0; j < m_outputSize; ++j) {
6968
tmp[j] = container.m_sum[j] / container.m_counter;
7069
}
71-
SpectrogramQuery spectrogram("", now, frequency, m_sampleRate, encode_base64(tmp.data(), m_outputSize));
72-
m_send(spectrogram);
70+
m_send(now, frequency, tmp);
7371
std::memset(container.m_sum.data(), 0, sizeof(float) * container.m_sum.size());
7472
container.m_counter = 0;
7573
container.m_lastDataSendTime = now;

sources/radio/blocks/spectrogram.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@ class Spectrogram : virtual public gr::sync_block {
1515
std::chrono::milliseconds m_lastDataSendTime;
1616
};
1717

18+
using SendFunction = std::function<void(const std::chrono::milliseconds&, const Frequency&, const std::vector<int8_t>&)>;
19+
1820
public:
19-
Spectrogram(const int itemSize, const Frequency sampleRate, std::function<Frequency()> getFrequency, std::function<void(const nlohmann::json&)> send);
21+
Spectrogram(const int itemSize, const Frequency sampleRate, std::function<Frequency()> getFrequency, SendFunction send);
2022

2123
int work(int noutput_items, gr_vector_const_void_star& input_items, gr_vector_void_star& output_items) override;
2224

@@ -29,6 +31,6 @@ class Spectrogram : virtual public gr::sync_block {
2931
const int m_decimatorFactor;
3032
const Frequency m_sampleRate;
3133
const std::function<Frequency()> m_getFrequency;
32-
const std::function<void(const nlohmann::json&)> m_send;
34+
const SendFunction m_send;
3335
std::map<Frequency, Container> m_containers;
3436
};

sources/radio/blocks/transmission.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,9 @@ std::vector<Recording> Transmission::getSortedTransmissions(const std::chrono::m
158158
for (const auto& index : indexes) {
159159
const auto deviceFrequency = m_getFrequency();
160160
const auto shiftFrequency = getTunedFrequency(m_indexToShift(index), m_config.recordingTuningStep());
161-
transmissions.emplace_back("scanner", "", deviceFrequency, deviceFrequency + shiftFrequency, m_config.recordingBandwidth(), "", m_signals.at(index).needFlush(now));
161+
const auto source = m_device.alias.empty() ? SCANNER_SOURCE_NAME : GAIN_TESTER_SOURCE_NAME;
162+
const auto name = m_device.alias.empty() ? SCANNER_RECORDING_NAME : GAIN_TESTER_RECORDING_NAME;
163+
transmissions.emplace_back(source, name, deviceFrequency, deviceFrequency + shiftFrequency, m_config.recordingBandwidth(), "", m_signals.at(index).needFlush(now));
162164
}
163165
return transmissions;
164166
}

sources/radio/help_structures.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ struct Device {
8484
std::vector<Crontab> crontabs;
8585

8686
std::string getName() const { return driver + "_" + serial; }
87+
std::string getAliasName() const { return alias.empty() ? getName() : alias; }
8788
};
8889
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(
8990
Device, connected, enabled, gains, serial, driver, alias, sample_rate, ranges, start_recording_level, stop_recording_level, satellites, sample_rates, crontabs)

sources/radio/scheduler.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ std::optional<std::pair<FrequencyRange, std::vector<Recording>>> Scheduler::getR
6565
}
6666

6767
void Scheduler::worker() {
68-
m_remoteController.schedulerCallback(m_device.getName(), std::bind(&Scheduler::callback, this, _1));
68+
m_remoteController.schedulerCallback(m_device, std::bind(&Scheduler::callback, this, _1));
6969
while (m_isRunning) {
7070
const auto now = getTime();
7171
if (m_isRefreshEnabled && m_lastUpdateTime + UPDATE_INTERVAL <= now) {
@@ -79,7 +79,7 @@ void Scheduler::worker() {
7979
void Scheduler::query() {
8080
Logger::info(LABEL, "send query");
8181
const SchedulerQuery query(m_config.latitude(), m_config.longitude(), m_config.altitude(), m_device.satellites, m_device.crontabs);
82-
m_remoteController.schedulerQuery(m_device.getName(), static_cast<nlohmann::json>(query).dump());
82+
m_remoteController.schedulerQuery(m_device, static_cast<nlohmann::json>(query).dump());
8383
}
8484

8585
void Scheduler::callback(const nlohmann::json& json) {

sources/radio/sdr_device.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ void SdrDevice::updateRecordings(const std::vector<Recording> recordings) {
110110
if (m_recorders.size() < static_cast<size_t>(m_config.recordersCount())) {
111111
const auto sampleRate = m_device.sample_rate;
112112
m_recorders.push_back(
113-
std::make_unique<Recorder>(m_config, m_zeromq, sampleRate, recording, std::bind(&RemoteController::sendTransmission, m_remoteController, m_device.getName(), std::placeholders::_1)));
113+
std::make_unique<Recorder>(m_config, m_zeromq, sampleRate, recording, std::bind(&RemoteController::sendTransmission, m_remoteController, m_device, std::placeholders::_1)));
114114
} else {
115115
if (!ignoredTransmissions.count(recording.recordingFrequency)) {
116116
Logger::info(LABEL, "maximum recorders limit reached, frequency: {}", formatFrequency(recording.recordingFrequency, RED));

sources/radio/sdr_processor.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@
55
#include <gnuradio/blocks/stream_to_vector.h>
66
#include <gnuradio/fft/fft_v.h>
77
#include <gnuradio/fft/window.h>
8+
#include <network/query.h>
89
#include <radio/blocks/decimator.h>
910
#include <radio/blocks/noise_learner.h>
1011
#include <radio/blocks/psd.h>
1112
#include <radio/blocks/spectrogram.h>
1213
#include <radio/blocks/transmission.h>
1314
#include <utils/radio_utils.h>
15+
#include <utils/utils.h>
1416

1517
constexpr auto LABEL = "processor";
1618

@@ -25,6 +27,10 @@ SdrProcessor::SdrProcessor(
2527
: m_connector(connector) {
2628
const auto getFrequency = [frequencyRange]() { return frequencyRange.center(); };
2729
const auto sampleRate = device.sample_rate;
30+
const auto sendSpectrogram = [&remoteController, device, sampleRate](const std::chrono::milliseconds& time, const Frequency& frequency, const std::vector<int8_t>& data) {
31+
SpectrogramQuery spectrogram(device.alias.empty() ? SCANNER_SOURCE_NAME : GAIN_TESTER_SOURCE_NAME, time, frequency, sampleRate, encode_base64(data.data(), data.size()));
32+
remoteController.sendSpectrogram(device, spectrogram);
33+
};
2834

2935
const auto fftSize = getFft(sampleRate, SIGNAL_DETECTION_MAX_STEP);
3036
const auto step = static_cast<double>(sampleRate) / fftSize;
@@ -43,7 +49,7 @@ SdrProcessor::SdrProcessor(
4349
const auto transmission = std::make_shared<Transmission>(config, device, fftSize, indexStep, notification, getFrequency, indexToFrequency, indexToShift, isIndexInRange);
4450
m_connector.connect<Block>(source, s2c, decimator, fft, psd, noiseLearner, transmission);
4551

46-
const auto spectrogram = std::make_shared<Spectrogram>(fftSize, sampleRate, getFrequency, std::bind(&RemoteController::sendSpectrogram, remoteController, device.getName(), std::placeholders::_1));
52+
const auto spectrogram = std::make_shared<Spectrogram>(fftSize, sampleRate, getFrequency, sendSpectrogram);
4753
m_connector.connect<Block>(psd, spectrogram);
4854

4955
if (DEBUG_SAVE_FULL_POWER) {

0 commit comments

Comments
 (0)