Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add blocks: Multiply, Divide, Add, Subtract #395

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

eltos
Copy link

@eltos eltos commented Aug 27, 2024

To learn how to implement blocks in gr4 I want to implement and contribute a simple math block as part of the Block Tutorial at European GNU Radio Days 2024. This PR is a work-in-progress state of my efforts.

Usage example:

gr::Graph graph{};
// source_1 counting 1,2,3,4,...,10
auto& source_1 = graph.emplaceBlock<gr::testing::CountingSource<float>>({{"n_samples_max", 10U}});
// source_2 counting 6,7,8,9,...,15
auto& source_2 = graph.emplaceBlock<gr::testing::CountingSource<float>>({{"n_samples_max", 10U}});
source_2.default_value = 5.0f;
// Add block with two inputs
auto& adder = graph.emplaceBlock<gr::math::Add<float>>({{"n_inputs", 2U}});
// Null sink
auto& sink = graph.emplaceBlock<gr::testing::CountingSink<float>>();

// Connections (note how the two inputs of the adder block are addressed)
auto connected = true;
connected &= graph.connect<"out">(source_1).to<"in", 0>(adder) == gr::ConnectionResult::SUCCESS;
connected &= graph.connect<"out">(source_2).to<"in", 1>(adder) == gr::ConnectionResult::SUCCESS;
connected &= graph.connect<"out">(adder).to<"in">(sink) == gr::ConnectionResult::SUCCESS;
if (!connected) { fmt::print("Error: Failed to connect flowgraph!\n"); return; }

// Execute flow graph
gr::scheduler::Simple<> scheduler{std::move(graph)};
scheduler.runAndWait();

Feedback:

I found it difficult to implement the block with a dynamic number of ports since I didn't find documentation on this, nor did I find a description on how to connect the ports in the graph (tried "in0", "in#0" etc. first).
I finally got it, but since this is a very general concept, it would be beneficial to provide the mechanics of "n_inputs" settings etc. in the base block and enable something like PortInMulti<T, Limits<1, 32>> in; for ease of use.
Also, having more example flowgraphs like the one above would be helpful for newcomers.

@eltos eltos marked this pull request as draft August 27, 2024 15:03
@eltos eltos changed the title WIP: Add blocks: Multiply, Divide, Add, Subtract Add blocks: Multiply, Divide, Add, Subtract Aug 30, 2024
@eltos eltos marked this pull request as ready for review August 30, 2024 15:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant