Skip to content

Commit

Permalink
Integrate the graph-prototype into the application for signal handling
Browse files Browse the repository at this point in the history
  • Loading branch information
giucam committed Aug 30, 2023
1 parent 123115a commit 22d6aef
Show file tree
Hide file tree
Showing 22 changed files with 893 additions and 433 deletions.
6 changes: 4 additions & 2 deletions src/ui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -130,5 +130,7 @@ else () # native build
target_compile_definitions(${target_name} PRIVATE BLOCKS_DIR="${GNURADIO_PREFIX}/share/gnuradio/grc/blocks/")
endif()

target_link_libraries(${target_name} PRIVATE function2::function2)
target_include_directories(${target_name} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../service/acquisition) #for daq_api.hpp
target_link_libraries(${target_name} PRIVATE function2::function2 graph-prototype fftw)
target_include_directories(${target_name} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../service/acquisition #for daq_api.hpp
${graph-prototype_SOURCE_DIR}/test)
target_compile_options(${target_name} PRIVATE "-Wfatal-errors")
34 changes: 34 additions & 0 deletions src/ui/app.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,40 @@ struct App {
ImFont *fontIconsSolidBig;
ImFont *fontIconsSolidLarge;
std::chrono::seconds editPaneCloseDelay{ 15 };
struct SchedWrapper {
SchedWrapper() {}
// // template<typename T>
// // SchedWrapper(T &&sched)
// // : handler(std::make_unique<HandlerImpl<T>>(std::move(sched)))
// // {
// // }

template<typename T, typename... Args>
void emplace(Args &&...args) {
handler = std::make_unique<HandlerImpl<T>>(std::forward<Args>(args)...);
}

void run() { handler->run(); }

private:
struct Handler {
virtual ~Handler() = default;
virtual void run() = 0;
};
template<typename T>
struct HandlerImpl : Handler {
T data;
template<typename... Args>
HandlerImpl(Args &&...args)
: data(std::forward<Args>(args)...) {
data.init();
}
void run() final { data.run_and_wait(); }
};

std::unique_ptr<Handler> handler;
};
SchedWrapper scheduler;

private:
App();
Expand Down
8 changes: 2 additions & 6 deletions src/ui/assets/sampleDashboards/DemoDashboard.grc
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,11 @@ blocks:
- name: sine source 1
id: sine_source
parameters:
frequency: 0.100000
frequency: 1.000000
- name: sine source 3
id: sine_source
parameters:
frequency: 0.130000
- name: source for sink 1
id: sink_source
- name: source for sink 2
id: sink_source
frequency: 1.300000
- name: sink 1
id: sink
- name: sink 2
Expand Down
10 changes: 8 additions & 2 deletions src/ui/cmake/Dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,21 @@ FetchContent_Declare(
GIT_TAG 4.2.2
)

FetchContent_Declare(
graph-prototype
GIT_REPOSITORY https://github.com/fair-acc/graph-prototype.git
GIT_TAG 9f07e7b61de5d2ed27b33d4ffccaa9d8adfdbc3e
)

if (EMSCRIPTEN)
FetchContent_MakeAvailable(imgui implot imgui-node-editor yaml-cpp stb opencmw-cpp plf_colony function2)
FetchContent_MakeAvailable(imgui implot imgui-node-editor yaml-cpp stb opencmw-cpp plf_colony function2 graph-prototype)
else () # native build
# FetchContent_Declare(
# sdl2
# GIT_REPOSITORY "https://github.com/libsdl-org/SDL"
# GIT_TAG release-2.24.2
# )
FetchContent_MakeAvailable(imgui implot imgui-node-editor yaml-cpp plf_colony stb opencmw-cpp function2)
FetchContent_MakeAvailable(imgui implot imgui-node-editor yaml-cpp plf_colony stb opencmw-cpp function2 graph-prototype)
find_package(SDL2 REQUIRED)
find_package(OpenGL REQUIRED COMPONENTS OpenGL)
# target_link_libraries(SDL2 PUBLIC OpenGL::GL )
Expand Down
24 changes: 12 additions & 12 deletions src/ui/dashboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,17 +221,17 @@ Dashboard::Dashboard(const std::shared_ptr<DashboardDescription> &desc)
: m_desc(desc) {
m_desc->lastUsed = std::chrono::floor<std::chrono::days>(std::chrono::system_clock::now());

localFlowGraph.sourceBlockAddedCallback = [this](Block *b) {
if (dynamic_cast<DataSinkSource *>(b)) {
return;
}
for (int i = 0; i < b->type->outputs.size(); ++i) {
auto name = fmt::format("{}.{}", b->name, b->type->outputs[i].name);
m_sources.insert({ b, i, name, randomColor() });
}
};
// localFlowGraph.sourceBlockAddedCallback = [this](Block *b) {
// if (dynamic_cast<DataSinkSource *>(b)) {
// return;
// }
// for (int i = 0; i < b->type->outputs.size(); ++i) {
// auto name = fmt::format("{}.{}", b->name, b->type->outputs[i].name);
// m_sources.insert({ b, i, name, randomColor() });
// }
// };
localFlowGraph.sinkBlockAddedCallback = [this](Block *b) {
m_sources.insert({ b, -1, b->name, randomColor() });
m_sources.insert({ static_cast<DataSink *>(b), -1, b->name, randomColor() });
};
localFlowGraph.blockDeletedCallback = [this](Block *b) {
for (auto &p : m_plots) {
Expand All @@ -252,8 +252,8 @@ DataSink *Dashboard::createSink() {
auto sink = std::make_unique<DigitizerUi::DataSink>(name);
auto sinkptr = sink.get();
localFlowGraph.addSinkBlock(std::move(sink));
name = fmt::format("source for sink {}", n);
localFlowGraph.addSourceBlock(std::make_unique<DigitizerUi::DataSinkSource>(name));
// name = fmt::format("source for sink {}", n);
// localFlowGraph.addSourceBlock(std::make_unique<DigitizerUi::DataSinkSource>(name));
return sinkptr;
}

Expand Down
2 changes: 1 addition & 1 deletion src/ui/dashboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ struct DashboardDescription {
class Dashboard {
public:
struct Source {
Block *block;
DataSink *block;
int port;
std::string name;
uint32_t color;
Expand Down
34 changes: 20 additions & 14 deletions src/ui/dashboardpage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -286,27 +286,33 @@ void DashboardPage::drawPlot(DigitizerUi::Dashboard::Plot &plot) noexcept {
auto color = ImGui::ColorConvertU32ToFloat4(source->color);
ImPlot::SetNextLineStyle(color);

const auto [dataType, dataSet] = [&]() -> std::tuple<DataType, DataSet> {
if (auto *sink = dynamic_cast<DataSink *>(source->block)) {
return { sink->dataType, sink->data };
}
auto &port = const_cast<const Block *>(source->block)->outputs()[source->port];
return { port.type, port.dataSet };
}();

auto *sink = static_cast<DataSink *>(source->block);
ImPlot::HideNextItem(false, ImPlotCond_Always);
if (dataSet.empty()) {
sink->update();
if (sink->data.empty()) {
// Plot one single dummy value so that the sink shows up in the plot legend
float v = 0;
if (source->visible) {
ImPlot::PlotLine(source->name.c_str(), &v, 1);
}
} else {
switch (dataType) {
} else if (source->visible) {
switch (sink->dataType) {
case DigitizerUi::DataType::Float32: {
if (source->visible) {
auto values = dataSet.asFloat32();
ImPlot::PlotLine(source->name.c_str(), values.data(), values.size());
auto values = sink->data.asFloat32();
std::lock_guard lock(sink->m_mutex);
ImPlot::PlotLine(source->name.c_str(), values.data(), int(values.size()));
break;
}
case DigitizerUi::DataType::DataSetFloat32: {
auto ds = sink->data.asDataSetFloat32();
if (ds.extents.empty()) {
break;
}
auto &values = ds.signal_values;
std::lock_guard lock(sink->m_mutex);
for (int i = 0; i < ds.extents[0]; ++i) {
auto n = ds.extents[1];
ImPlot::PlotLine(ds.signal_names[i].c_str(), values.data() + n*i, n);
}
break;
}
Expand Down
Loading

0 comments on commit 22d6aef

Please sign in to comment.