Skip to content

Commit f076922

Browse files
authored
Modernize synapse-cpp client (v2.0.0-rc1) (#25)
* feat!: modernize synapse-cpp client (v2.0.0-rc1) BREAKING CHANGE: Major API and architecture update Streaming: - Replace NDTP with Taps for high-throughput ZMQ-based data streaming - Remove StreamIn/StreamOut nodes - Add Tap client with producer/consumer support Nodes: - Add DiskWriter node for HDF5 recording - Add SpikeBinner node for spike binning - Rename SpikeDetect → SpikeDetector (API alignment) - Remove UdpNode base class Device: - Add query(), get_logs(), update_settings(), list_apps() methods - Remove NodeSocket (deprecated in synapse-api) Build: - Add Dockerfile for containerized ARM/x86 builds - Replace libndtp with cppzmq dependency - Update to latest synapse-api Misc: - Modernize device discovery with async support - Update examples with new Tap-based streaming * fix: update synapse-api submodule to v2.1.0 The build was failing because spike_binner.pb.h couldn't be generated - the submodule was pointing to v2.0.0 which predates the spike_binner.proto addition.
1 parent b3ca993 commit f076922

38 files changed

Lines changed: 1377 additions & 1545 deletions

.dockerignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
build/
2+
dist/
3+
.git/
4+
external/microsoft/vcpkg/
5+
*.o
6+
*.a
7+
*.so
8+
*.dylib

CMakeLists.txt

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
cmake_minimum_required(VERSION 3.23.5)
22

3-
file(READ "${CMAKE_CURRENT_SOURCE_DIR}/version.txt" SYNAPSE_CPP_VERSION)
4-
string(STRIP "${SYNAPSE_CPP_VERSION}" SYNAPSE_CPP_VERSION)
3+
file(READ "${CMAKE_CURRENT_SOURCE_DIR}/version.txt" SYNAPSE_CPP_VERSION_FULL)
4+
string(STRIP "${SYNAPSE_CPP_VERSION_FULL}" SYNAPSE_CPP_VERSION_FULL)
5+
# Extract semver (before any -suffix) for CMake VERSION
6+
string(REGEX REPLACE "^([0-9]+\\.[0-9]+\\.[0-9]+).*" "\\1" SYNAPSE_CPP_VERSION "${SYNAPSE_CPP_VERSION_FULL}")
57
project(synapse VERSION ${SYNAPSE_CPP_VERSION})
68

79
set(CMAKE_CXX_STANDARD 17)
@@ -10,7 +12,7 @@ set(CMAKE_CXX_EXTENSIONS OFF)
1012

1113
find_package(gRPC CONFIG REQUIRED)
1214
find_package(Protobuf REQUIRED CONFIG)
13-
find_package(science-libndtp REQUIRED CONFIG)
15+
find_package(cppzmq CONFIG REQUIRED)
1416
find_package(science-scipp REQUIRED CONFIG)
1517

1618
add_library(${PROJECT_NAME})
@@ -70,7 +72,7 @@ target_link_libraries(
7072
PRIVATE
7173
gRPC::grpc++
7274
protobuf::libprotobuf
73-
science::libndtp
75+
cppzmq
7476
science::scipp
7577
)
7678

@@ -111,21 +113,11 @@ install(
111113
)
112114

113115
if ("examples" IN_LIST VCPKG_MANIFEST_FEATURES)
114-
add_executable(stream_out examples/stream_out/main.cpp)
115-
file(GLOB_RECURSE TEST_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/examples/stream_out/*.cpp")
116-
target_sources(stream_out PRIVATE ${TEST_SOURCES})
117-
target_include_directories(stream_out PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/examples)
118-
target_link_libraries(stream_out PRIVATE ${PROJECT_NAME} science::scipp)
119-
set_target_properties(stream_out PROPERTIES
120-
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/examples"
121-
)
122-
123-
add_executable(stats examples/stats/main.cpp)
124-
file(GLOB_RECURSE TEST_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/examples/stats/*.cpp")
125-
target_sources(stats PRIVATE ${TEST_SOURCES})
126-
target_include_directories(stats PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/examples)
127-
target_link_libraries(stats PRIVATE ${PROJECT_NAME} science::scipp)
128-
set_target_properties(stats PROPERTIES
116+
# Tap example
117+
add_executable(tap_example examples/tap/main.cpp)
118+
target_include_directories(tap_example PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/examples)
119+
target_link_libraries(tap_example PRIVATE ${PROJECT_NAME} science::scipp)
120+
set_target_properties(tap_example PROPERTIES
129121
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/examples"
130122
)
131123
endif()

Dockerfile

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
FROM ubuntu:22.04
2+
3+
ENV DEBIAN_FRONTEND=noninteractive
4+
5+
# Install build dependencies
6+
RUN apt-get update && apt-get install -y \
7+
build-essential \
8+
git \
9+
curl \
10+
zip \
11+
unzip \
12+
tar \
13+
pkg-config \
14+
ninja-build \
15+
autoconf \
16+
automake \
17+
libtool \
18+
python3 \
19+
wget \
20+
gpg \
21+
&& rm -rf /var/lib/apt/lists/*
22+
23+
# Install CMake 3.27 via direct binary download (compatible with preset v6 and older vcpkg)
24+
ARG CMAKE_VERSION=3.27.9
25+
RUN wget -qO- "https://github.com/Kitware/CMake/releases/download/v${CMAKE_VERSION}/cmake-${CMAKE_VERSION}-linux-aarch64.tar.gz" \
26+
| tar --strip-components=1 -xz -C /usr/local
27+
28+
# Set up vcpkg (VCPKG_FORCE_SYSTEM_BINARIES required for ARM platforms)
29+
ENV VCPKG_ROOT=/vcpkg
30+
ENV VCPKG_FORCE_SYSTEM_BINARIES=1
31+
RUN git clone https://github.com/microsoft/vcpkg.git $VCPKG_ROOT && \
32+
cd $VCPKG_ROOT && \
33+
git checkout 1751f9f8c732c2e6f9e81ce56c10e4c4aa265b4a && \
34+
./bootstrap-vcpkg.sh
35+
36+
WORKDIR /src
37+
38+
# Copy source files (excluding git dirs and build artifacts via .dockerignore)
39+
COPY . .
40+
41+
# Clone submodules at pinned versions
42+
RUN rm -rf external/sciencecorp/synapse-api && \
43+
git clone --branch v2.1.0 https://github.com/sciencecorp/synapse-api.git external/sciencecorp/synapse-api
44+
45+
RUN if [ ! -d "external/sciencecorp/vcpkg/ports" ]; then \
46+
rm -rf external/sciencecorp/vcpkg && \
47+
git clone https://github.com/sciencecorp/vcpkg.git external/sciencecorp/vcpkg; \
48+
fi
49+
50+
# Configure and build
51+
RUN cmake --preset=static -DCMAKE_BUILD_TYPE=Debug -DVCPKG_MANIFEST_FEATURES="examples;tests"
52+
RUN cmake --build build
53+
54+
# Run tests
55+
CMD ["./build/synapse_tests"]

README.md

Lines changed: 68 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,72 @@ synapse provides CMake targets:
5252

5353
This library offers a C++ interface to the Synapse API.
5454

55-
See the [examples](./examples) for more details.
55+
### Device Operations
56+
57+
```cpp
58+
#include <science/synapse/device.h>
59+
#include <science/synapse/config.h>
60+
61+
// Connect to a device
62+
synapse::Device device("192.168.1.100:50051");
63+
64+
// Get device info
65+
synapse::DeviceInfo info;
66+
device.info(&info);
67+
68+
// Configure, start, and stop
69+
synapse::Config config;
70+
// ... add nodes to config ...
71+
device.configure(&config);
72+
device.start();
73+
device.stop();
74+
75+
// Query the device
76+
synapse::QueryRequest req;
77+
req.set_query_type(synapse::QueryType::kListTaps);
78+
synapse::QueryResponse res;
79+
device.query(req, &res);
80+
```
81+
82+
### Tap Client (High-Throughput Data Streaming)
83+
84+
```cpp
85+
#include <science/synapse/tap.h>
86+
87+
// Connect to a tap for streaming data
88+
synapse::Tap tap("192.168.1.100:50051");
89+
90+
// List available taps
91+
auto taps = tap.list_taps();
92+
93+
// Connect to a producer tap (read data from device)
94+
tap.connect("broadband_tap");
95+
96+
// Read data
97+
std::vector<uint8_t> data;
98+
while (tap.read(&data).ok()) {
99+
// Process protobuf-encoded data (e.g., BroadbandFrame)
100+
}
56101
57-
https://github.com/sciencecorp/synapse-cpp/blob/main/examples/stream_out/main.cpp
102+
// Or read in batches for higher throughput
103+
std::vector<std::vector<uint8_t>> batch;
104+
size_t count = tap.read_batch(&batch, 100, 10); // up to 100 messages, 10ms timeout
105+
```
106+
107+
### Discovery
108+
109+
```cpp
110+
#include <science/synapse/util/discover.h>
111+
112+
// Discover devices on the network (passive UDP listening)
113+
std::vector<synapse::DeviceAdvertisement> devices;
114+
synapse::discover(5000, &devices); // 5 second timeout
115+
116+
// Or use callback-based discovery
117+
synapse::discover_iter([](const synapse::DeviceAdvertisement& device) {
118+
std::cout << "Found: " << device.name << " at " << device.host << std::endl;
119+
return true; // continue discovery
120+
}, 10000);
121+
```
122+
123+
See the [examples](./examples) for more details.

build.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash
2+
set -e
3+
4+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
5+
cd "$SCRIPT_DIR"
6+
7+
IMAGE_NAME="synapse-cpp-builder"
8+
CONTAINER_NAME="synapse-cpp-build"
9+
10+
echo "Building Docker image..."
11+
docker build -t "$IMAGE_NAME" .
12+
13+
echo "Build successful!"
14+
echo ""
15+
echo "To run tests:"
16+
echo " docker run --rm $IMAGE_NAME"
17+
echo ""
18+
echo "To get an interactive shell:"
19+
echo " docker run --rm -it $IMAGE_NAME /bin/bash"

cmake/Config.cmake.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
find_package(gRPC REQUIRED CONFIG)
44
find_package(Protobuf REQUIRED CONFIG)
5-
find_package(science-libndtp REQUIRED CONFIG)
5+
find_package(cppzmq REQUIRED CONFIG)
66
find_package(science-scipp REQUIRED CONFIG)
77

88
include("${CMAKE_CURRENT_LIST_DIR}/synapseTargets.cmake")

examples/stats/main.cpp

Lines changed: 0 additions & 152 deletions
This file was deleted.

0 commit comments

Comments
 (0)