Skip to content

Commit

Permalink
Update to latest gnuradio4
Browse files Browse the repository at this point in the history
  • Loading branch information
frankosterfeld committed Sep 20, 2024
1 parent 40eca10 commit bb1cdd1
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 22 deletions.
5 changes: 3 additions & 2 deletions cmake/Dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ include(FetchContent)
FetchContent_Declare(
gnuradio4
GIT_REPOSITORY https://github.com/fair-acc/gnuradio4.git
GIT_TAG c51a5d5253bdd2ce7bbc785970b7ec4bbe2878dc # main as of 2024-06-14
#GIT_TAG 6d85d74a09194f30e538f1a87e586944a6aae86d # main as of 2024-09-16
GIT_TAG frank/upgrade-fmt-11.0.2
SYSTEM
)

FetchContent_Declare(
opencmw-cpp
GIT_REPOSITORY https://github.com/fair-acc/opencmw-cpp.git
GIT_TAG 0fb3758c3ffe7707aa5e0bd2ad25f9e8fb19f79d # main as of 2024-04-26
GIT_TAG frank/upgrade-fmt-11.0.2
SYSTEM
)

Expand Down
6 changes: 3 additions & 3 deletions src/service/gnuradio/GnuRadioWorker.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ class GnuRadioAcquisitionWorker : public Worker<serviceName, TimeDomainContext,
}
_updateSignalEntriesCallback(std::move(entries));
}
auto sched = std::make_unique<scheduler::Simple<scheduler::multiThreaded>>(std::move(*pendingFlowGraph));
auto sched = std::make_unique<scheduler::Simple<scheduler::ExecutionPolicy::multiThreaded>>(std::move(*pendingFlowGraph));
toScheduler = std::make_unique<MsgPortOut>();
fromScheduler = std::make_unique<MsgPortIn>();
std::ignore = toScheduler->connect(sched->msgIn);
Expand Down Expand Up @@ -417,8 +417,8 @@ class GnuRadioAcquisitionWorker : public Worker<serviceName, TimeDomainContext,

auto pollerIt = pollers.find(key);
if (pollerIt == pollers.end()) {
auto matcher = [trigger_name = context.triggerNameFilter](const gr::Tag& tag) {
using enum gr::basic::TriggerMatchResult;
auto matcher = [trigger_name = context.triggerNameFilter](std::string_view, const gr::Tag& tag, const gr::property_map&) {
using enum gr::trigger::MatchResult;
const auto v = tag.get(gr::tag::TRIGGER_NAME);
if (trigger_name.empty()) {
return v ? Matching : Ignore;
Expand Down
2 changes: 1 addition & 1 deletion src/service/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
// TODO instead of including and registering blocks manually here, rely on the plugin system
#include <gnuradio-4.0/basic/Selector.hpp>
#include <gnuradio-4.0/basic/common_blocks.hpp>
#include <gnuradio-4.0/basic/function_generator.h>
#include <gnuradio-4.0/basic/function_generator.hpp>

#ifndef __EMSCRIPTEN__
#include <Picoscope4000a.hpp>
Expand Down
6 changes: 4 additions & 2 deletions src/ui/App.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "FlowgraphItem.hpp"
#include "OpenDashboardPage.hpp"

#include <gnuradio-4.0/CircularBuffer.hpp>
#include <gnuradio-4.0/Message.hpp>
#include <gnuradio-4.0/Scheduler.hpp>

Expand Down Expand Up @@ -117,7 +118,8 @@ class App {
std::string_view uniqueName() const override { return _scheduler.unique_name; }

void sendMessage(const gr::Message& msg) final {
_toScheduler.streamWriter().publish([&](auto& output) { output[0] = msg; }, 1);
auto output = _toScheduler.streamWriter().reserve<gr::SpanReleasePolicy::ProcessAll>(1UZ);
output[0] = msg;
}

void handleMessages(FlowGraph& fg) final {
Expand Down Expand Up @@ -200,7 +202,7 @@ class App {

template<typename Graph>
void assignScheduler(Graph&& graph) {
using Scheduler = gr::scheduler::Simple<gr::scheduler::multiThreaded>;
using Scheduler = gr::scheduler::Simple<gr::scheduler::ExecutionPolicy::multiThreaded>;

_scheduler.emplace<Scheduler>(std::forward<Graph>(graph), schedulerThreadPool);
}
Expand Down
57 changes: 45 additions & 12 deletions src/ui/Flowgraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,10 +280,10 @@ void Block::setCurrentInstantiation(const std::string& newInstantiation) {
m_outputs.reserve(instantiation.outputs.size());
m_inputs.reserve(instantiation.inputs.size());
for (auto& o : instantiation.outputs) {
m_outputs.push_back({this, o.type, o.dataset, Port::Direction::Output});
m_outputs.push_back({this, o.name, o.type, o.dataset, Port::Direction::Output});
}
for (auto& o : instantiation.inputs) {
m_inputs.push_back({this, o.type, o.dataset, Port::Direction::Input});
m_inputs.push_back({this, o.name, o.type, o.dataset, Port::Direction::Input});
}
}

Expand Down Expand Up @@ -337,22 +337,55 @@ void FlowGraph::parse(const std::string& str) {
return it == m_blocks.end() ? nullptr : it->get();
};

auto findPort = [&](const auto& portDefinition, auto& ports) {
return std::visit(gr::meta::overloaded(
[&](const gr::PortDefinition::IndexBased& definition) {
if (definition.topLevel >= ports.size()) {
fmt::println(std::cerr, "Cannot connect, index {} is not valid (only {} ports available)", definition.topLevel, definition.topLevel);
}
// TODO check subIndex once we support port collections
return std::pair{ports.begin() + definition.topLevel, definition.subIndex};
},
[&](const gr::PortDefinition::StringBased& definition) {
auto split = std::string_view(definition.name) | std::ranges::views::split('#');
const auto segs = std::vector(split.begin(), split.end());
const auto name = std::string_view(segs[0].data(), segs[0].size());
const auto subIndex = [&] {
if (segs.size() < 2) {
return 0UZ;
}
auto index = 0UZ;
const auto& [_, ec] = std::from_chars(segs[1].begin(), segs[1].end(), index);
if (ec != std::errc{}) {
throw std::runtime_error(fmt::format("Invalid subindex in '{}'", definition.name));
}
return index;
}();
const auto it = std::ranges::find_if(ports, [&name](const auto& port) { return port.name == name; });
if (it == ports.end()) {
fmt::println(std::cerr, "Cannot connect, no port with name '{}'", name);
}

// TODO check subIndex once we support port collections

return std::pair{it, subIndex};
}),
portDefinition.definition);
};

graph.forEachEdge([&](const auto& edge) {
auto srcBlock = findBlock(edge._sourceBlock->uniqueName());
assert(srcBlock);
const auto sourcePort = edge._sourcePortDefinition.topLevel;
auto dstBlock = findBlock(edge._destinationBlock->uniqueName());
// TODO do not ignore subindexes
const auto& [srcPort, _] = findPort(edge.sourcePortDefinition(), srcBlock->m_outputs);
auto dstBlock = findBlock(edge._destinationBlock->uniqueName());
assert(dstBlock);
const auto destinationPort = edge._destinationPortDefinition.topLevel;
// TODO support port collections
const auto& [dstPort, _] = findPort(edge.destinationPortDefinition(), dstBlock->m_inputs);

if (sourcePort >= srcBlock->m_outputs.size()) {
fmt::print("ERROR: Cannot connect, no output port with index {} in {}, have only {} ports\n", sourcePort, srcBlock->m_uniqueName, srcBlock->m_outputs.size());
} else if (destinationPort >= dstBlock->m_inputs.size()) {
fmt::print("ERROR: Cannot connect, no input port with index {} in {}, have only {} ports\n", destinationPort, dstBlock->m_uniqueName, dstBlock->m_inputs.size());
} else {
connect(&srcBlock->m_outputs[sourcePort], &dstBlock->m_inputs[destinationPort]);
if (srcPort == srcBlock->m_outputs.end() || dstPort == dstBlock->m_inputs.end()) {
return;
}
connect(&*srcPort, &*dstPort);
});

m_graphChanged = true;
Expand Down
1 change: 1 addition & 0 deletions src/ui/Flowgraph.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ class Block {
};

Block* owningUiBlock;
const std::string name;
const std::string rawPortType;
bool isDataset;
const Direction portDirection;
Expand Down
4 changes: 2 additions & 2 deletions src/ui/cmake/Dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ FetchContent_Declare( # needed to load images in ImGui
FetchContent_Declare(
opencmw-cpp
GIT_REPOSITORY https://github.com/fair-acc/opencmw-cpp.git
GIT_TAG 0fb3758c3ffe7707aa5e0bd2ad25f9e8fb19f79d# main as of 2024-04-26
GIT_TAG frank/upgrade-fmt-11.0.2
SYSTEM
)

FetchContent_Declare(
gnuradio4
GIT_REPOSITORY https://github.com/fair-acc/gnuradio4.git
GIT_TAG c51a5d5253bdd2ce7bbc785970b7ec4bbe2878dc # main as of 2024-06-14
GIT_TAG frank/upgrade-fmt-11.0.2
SYSTEM
)

Expand Down

0 comments on commit bb1cdd1

Please sign in to comment.