2023-07-15 23:13:46 +02:00
|
|
|
#include "udp_source.h"
|
|
|
|
|
|
|
|
|
|
void UDPSource::set_settings(nlohmann::json settings)
|
|
|
|
|
{
|
|
|
|
|
d_settings = settings;
|
|
|
|
|
|
|
|
|
|
port = getValueOrDefault(d_settings["port"], port);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nlohmann::json UDPSource::get_settings()
|
|
|
|
|
{
|
|
|
|
|
d_settings["port"] = port;
|
|
|
|
|
|
|
|
|
|
return d_settings;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void UDPSource::open()
|
|
|
|
|
{
|
|
|
|
|
// Nothing to do
|
|
|
|
|
is_open = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void UDPSource::run_thread()
|
|
|
|
|
{
|
|
|
|
|
while (should_run)
|
|
|
|
|
{
|
|
|
|
|
if (is_started)
|
|
|
|
|
{
|
|
|
|
|
int bytes = udp_server->recv((uint8_t *)output_stream->writeBuf, 8192 * sizeof(complex_t));
|
|
|
|
|
// logger->info(bytes);
|
|
|
|
|
output_stream->swap(bytes / sizeof(complex_t));
|
|
|
|
|
// logger->info("done");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void UDPSource::start()
|
|
|
|
|
{
|
|
|
|
|
udp_server = std::make_shared<net::UDPServer>(port);
|
|
|
|
|
|
|
|
|
|
DSPSampleSource::start();
|
|
|
|
|
|
|
|
|
|
set_frequency(d_frequency);
|
|
|
|
|
|
|
|
|
|
is_started = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void UDPSource::stop()
|
|
|
|
|
{
|
2023-10-17 14:49:24 -04:00
|
|
|
if (!is_started)
|
|
|
|
|
return;
|
|
|
|
|
|
2023-07-15 23:13:46 +02:00
|
|
|
is_started = false;
|
2023-10-06 22:51:20 -04:00
|
|
|
udp_server.reset();
|
2023-10-07 20:54:08 -04:00
|
|
|
output_stream->flush();
|
2023-07-15 23:13:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void UDPSource::close()
|
|
|
|
|
{
|
|
|
|
|
is_open = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void UDPSource::set_frequency(uint64_t frequency)
|
|
|
|
|
{
|
|
|
|
|
// if (is_open && is_connected)
|
|
|
|
|
// {
|
|
|
|
|
// client->setFrequency(frequency);
|
|
|
|
|
// logger->debug("Set SDR++ Server frequency to %d", frequency);
|
|
|
|
|
// }
|
|
|
|
|
DSPSampleSource::set_frequency(frequency);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void UDPSource::drawControlUI()
|
|
|
|
|
{
|
|
|
|
|
if (is_started)
|
|
|
|
|
style::beginDisabled();
|
|
|
|
|
|
2023-09-08 00:30:58 -04:00
|
|
|
current_samplerate.draw();
|
2023-07-15 23:13:46 +02:00
|
|
|
|
|
|
|
|
ImGui::InputInt("Port", &port);
|
|
|
|
|
|
|
|
|
|
if (is_started)
|
|
|
|
|
style::endDisabled();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void UDPSource::set_samplerate(uint64_t samplerate)
|
|
|
|
|
{
|
2023-09-08 00:30:58 -04:00
|
|
|
current_samplerate.set(samplerate);
|
2023-07-15 23:13:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint64_t UDPSource::get_samplerate()
|
|
|
|
|
{
|
2023-09-08 00:30:58 -04:00
|
|
|
return current_samplerate.get();
|
2023-07-15 23:13:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::vector<dsp::SourceDescriptor> UDPSource::getAvailableSources()
|
|
|
|
|
{
|
|
|
|
|
std::vector<dsp::SourceDescriptor> results;
|
|
|
|
|
|
2023-09-12 20:01:50 +02:00
|
|
|
results.push_back({"udp_source", "UDP Source", 0, false});
|
2023-07-15 23:13:46 +02:00
|
|
|
|
|
|
|
|
return results;
|
2023-09-08 00:30:58 -04:00
|
|
|
}
|