Skip to content

Commit

Permalink
Add first PS 4000A impl
Browse files Browse the repository at this point in the history
  • Loading branch information
frankosterfeld committed Sep 21, 2023
1 parent 251f74b commit 28b923a
Show file tree
Hide file tree
Showing 20 changed files with 1,428 additions and 248 deletions.
9 changes: 8 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ cmake_minimum_required(VERSION 3.12)
project(gr-digitizers CXX)
set(CMAKE_CXX_STANDARD 20)

list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules)

include(FetchContent)

FetchContent_Declare(
graph-prototype
GIT_REPOSITORY https://github.com/fair-acc/graph-prototype.git
GIT_TAG 39c680c37d1a7a79bde8a5098dc42fb5efe03c02
GIT_TAG 27aac9208152ccd61b34197f30f95e9d094a698b
)

FetchContent_Declare(
Expand All @@ -25,6 +27,11 @@ FetchContent_Declare(

FetchContent_MakeAvailable(graph-prototype zeromq ut)

option(ENABLE_PICOSCOPE "Enable PicoScope support" ON)
set(PICOSCOPE_PREFIX "/opt/picoscope" CACHE PATH "Picoscope drivers prefix") # TODO use proper find_package

find_package(Volk REQUIRED)

add_subdirectory(blocklib)

option(ENABLE_TESTING "Enable Test Builds" ON)
Expand Down
5 changes: 5 additions & 0 deletions blocklib/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
add_subdirectory(helpers)
add_subdirectory(digitizers)

if (ENABLE_PICOSCOPE)
add_subdirectory(picoscope4000a)
endif ()
2 changes: 1 addition & 1 deletion blocklib/digitizers/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ set(DIGITIZERS_HEADERS

target_include_directories(gr-digitizers INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}> $<INSTALL_INTERFACE:include/>)

target_link_libraries(gr-digitizers INTERFACE graph-prototype)
target_link_libraries(gr-digitizers INTERFACE gr-helpers graph-prototype)
set_target_properties(gr-digitizers PROPERTIES PUBLIC_HEADER "${DIGITIZERS_HEADERS}")

if (ENABLE_TESTING)
Expand Down
39 changes: 2 additions & 37 deletions blocklib/digitizers/test/qa_block_scaling_offset.cc
Original file line number Diff line number Diff line change
@@ -1,52 +1,17 @@
#include <boost/ut.hpp>

#include <block_scaling_offset.h>
#include <helper_blocks.h>

#include <scheduler.hpp>

template <typename T>
struct vector_source : public fair::graph::node<vector_source<T>> {
fair::graph::OUT<T> out;

std::vector<T> data;
std::size_t _produced = 0;

explicit vector_source(std::vector<T> data_) : data{ std::move(data_) } {}

constexpr std::make_signed_t<std::size_t>
available_samples(const vector_source&) noexcept
{
const auto v =
static_cast<std::make_signed_t<std::size_t>>(data.size()) - _produced;
return v > 0 ? v : -1;
}

T process_one() noexcept
{
const auto n = _produced;
_produced++;
return data[n];
}
};

ENABLE_REFLECTION_FOR_TEMPLATE(vector_source, out, data);

template <typename T>
struct vector_sink : public fair::graph::node<vector_sink<T>> {
fair::graph::IN<T> in;
std::vector<T> data;

void process_one(T v) { data.push_back(v); }
};

ENABLE_REFLECTION_FOR_TEMPLATE(vector_sink, in, data);

namespace gr::digitizers::block_scaling_offset_test {

const boost::ut::suite BlockScalingOffsetTests = [] {
using namespace boost::ut;
using namespace fair::graph;
using namespace gr::digitizers;
using namespace gr::helpers;

"scale and offset"_test = [] {
double scale = 1.5;
Expand Down
11 changes: 11 additions & 0 deletions blocklib/helpers/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# setup header only library
add_library(gr-helpers INTERFACE)

set(HELPERS_HEADERS
helper_blocks.h
)

target_include_directories(gr-helpers INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}> $<INSTALL_INTERFACE:include/>)

target_link_libraries(gr-helpers INTERFACE graph-prototype)
set_target_properties(gr-helpers PROPERTIES PUBLIC_HEADER "${HELPERS_HEADERS}")
64 changes: 64 additions & 0 deletions blocklib/helpers/helper_blocks.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#ifndef GR_HELPERS_HELPER_BLOCKS_H
#define GR_HELPERS_HELPER_BLOCKS_H

#include <node.hpp>

/**
* TRANSITIONAL: some simple helpers blocks for tests, should go upstream or
* replaced by upstream blocks.
*/
namespace gr::helpers {

template <typename T>
struct vector_source : public fair::graph::node<vector_source<T>> {
fair::graph::OUT<T> out;

std::vector<T> data;
std::size_t _produced = 0;

explicit vector_source(std::vector<T> data_) : data{ std::move(data_) } {}

constexpr std::make_signed_t<std::size_t>
available_samples(const vector_source&) noexcept
{
const auto v =
static_cast<std::make_signed_t<std::size_t>>(data.size()) - _produced;
return v > 0 ? v : -1;
}

T process_one() noexcept
{
const auto n = _produced;
_produced++;
return data[n];
}
};

template <typename T>
struct vector_sink : public fair::graph::node<vector_sink<T>> {
fair::graph::IN<T> in;
std::vector<T> data;

fair::graph::work_return_status_t process_bulk(std::span<const T> input) {
std::cout << "Hello " << input.size() << std::endl;
data.insert(data.end(), input.begin(), input.end());
return fair::graph::work_return_status_t::OK;
}
};

template <typename T>
struct null_sink : public fair::graph::node<null_sink<T>> {
fair::graph::IN<T> in;

fair::graph::work_return_status_t process_bulk(std::span<const T>) const noexcept {
return fair::graph::work_return_status_t::OK;
}
};

}

ENABLE_REFLECTION_FOR_TEMPLATE(gr::helpers::vector_source, out, data);
ENABLE_REFLECTION_FOR_TEMPLATE(gr::helpers::vector_sink, in, data);
ENABLE_REFLECTION_FOR_TEMPLATE(gr::helpers::null_sink, in);

#endif
23 changes: 23 additions & 0 deletions blocklib/picoscope4000a/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
set(PICOSCOPE4000A_SOURCES
picoscope4000a.cc
)

set(PICOSCOPE4000A_HEADERS
picoscope4000a.h
)

# TODO do not hardcode
add_library(ps4000a SHARED IMPORTED)
set_property(TARGET ps4000a PROPERTY
IMPORTED_LOCATION ${PICOSCOPE_PREFIX}/lib/libps4000a.so)
target_include_directories(ps4000a INTERFACE ${PICOSCOPE_PREFIX}/include/libps4000a ${PICOSCOPE_PREFIX}/include/libps5000a) # TODO PicoCallback.h is missing in libps4000a/

add_library(gr-picoscope4000a SHARED ${PICOSCOPE4000A_SOURCES})
target_include_directories(gr-picoscope4000a INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}> $<INSTALL_INTERFACE:include/>)

target_link_libraries(gr-picoscope4000a ps4000a gr-helpers graph-prototype volk refl-cpp fmt)
set_target_properties(gr-digitizers PROPERTIES PUBLIC_HEADER "${PICOSCOPE4000A_HEADERS}")

if (ENABLE_TESTING)
add_subdirectory(test)
endif ()
14 changes: 0 additions & 14 deletions blocklib/picoscope4000a/enums.yml

This file was deleted.

This file was deleted.

22 changes: 0 additions & 22 deletions blocklib/picoscope4000a/lib/meson.build

This file was deleted.

Loading

0 comments on commit 28b923a

Please sign in to comment.