Skip to content

Commit 974a7e9

Browse files
committed
Connect scheduler with scanner.
1 parent 2ebd8d0 commit 974a7e9

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

sources/scanner.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <logger.h>
55

66
constexpr auto LABEL = "scanner";
7+
constexpr auto LOOP_TIMEOUT = std::chrono::milliseconds(10);
78

89
Scanner::Scanner(const Config& config, const Device& device, Mqtt& mqtt, RemoteController& remoteController, const int recordersCount)
910
: m_device(config, device, mqtt, m_notification, recordersCount),
@@ -34,13 +35,35 @@ Scanner::~Scanner() {
3435
m_thread.join();
3536
}
3637

38+
void Scanner::runScheduler(const std::optional<FrequencyRange>& activeRange) {
39+
auto recordings = m_scheduler.getRecordings(getTime());
40+
if (recordings) {
41+
m_device.updateRecordings({});
42+
m_device.setFrequencyRange(recordings->first);
43+
while (m_isRunning && recordings) {
44+
m_device.updateRecordings(recordings->second);
45+
recordings = m_scheduler.getRecordings(getTime());
46+
std::this_thread::sleep_for(LOOP_TIMEOUT);
47+
}
48+
m_device.updateRecordings({});
49+
if (activeRange) {
50+
m_device.setFrequencyRange(*activeRange);
51+
}
52+
}
53+
}
54+
3755
void Scanner::worker() {
3856
Logger::info(LABEL, "thread started");
3957
if (m_ranges.empty()) {
4058
Logger::warn(LABEL, "empty scanned ranges");
59+
while (m_isRunning) {
60+
runScheduler(std::nullopt);
61+
std::this_thread::sleep_for(LOOP_TIMEOUT);
62+
}
4163
} else if (m_ranges.size() == 1) {
4264
m_device.setFrequencyRange(m_ranges.front());
4365
while (m_isRunning) {
66+
runScheduler(m_ranges.front());
4467
m_device.updateRecordings(m_notification.wait());
4568
}
4669
} else {
@@ -51,6 +74,7 @@ void Scanner::worker() {
5174
const auto startScanningTime = getTime();
5275
bool isRecording = true;
5376
while ((getTime() <= startScanningTime + RANGE_SCANNING_TIME || isRecording) && m_isRunning) {
77+
runScheduler(range);
5478
const auto notification = m_notification.wait();
5579
isRecording = !notification.empty();
5680
m_device.updateRecordings(notification);

sources/scanner.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class Scanner {
1717
~Scanner();
1818

1919
private:
20+
void runScheduler(const std::optional<FrequencyRange>& activeRange);
2021
void worker();
2122

2223
SdrDevice m_device;

0 commit comments

Comments
 (0)