From 881491220ebf1de4ade6fe9f89c84454cb103ed7 Mon Sep 17 00:00:00 2001 From: Andrej Babic Date: Tue, 6 Jul 2021 11:24:11 +0200 Subject: [PATCH] Add config to streamer --- std-stream-send/include/StreamSendConfig.hpp | 8 +++---- std-stream-send/src/main.cpp | 22 ++++++++++++++++++-- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/std-stream-send/include/StreamSendConfig.hpp b/std-stream-send/include/StreamSendConfig.hpp index 36ecd2c..5bf5531 100644 --- a/std-stream-send/include/StreamSendConfig.hpp +++ b/std-stream-send/include/StreamSendConfig.hpp @@ -17,16 +17,16 @@ struct StreamSendConfig { return { config_parameters["detector_name"].GetString(), - config_parameters["detector_type"].GetString(), config_parameters["n_modules"].GetInt(), - config_parameters["start_udp_port"].GetInt(), + config_parameters["image_n_pixels"].GetInt(), + config_parameters["stream_address"].GetString() }; } const std::string detector_name; - const std::string detector_type; const int n_modules; - const int start_udp_port; + const int image_n_pixels; + const std::string stream_address; }; diff --git a/std-stream-send/src/main.cpp b/std-stream-send/src/main.cpp index c832578..2418c87 100644 --- a/std-stream-send/src/main.cpp +++ b/std-stream-send/src/main.cpp @@ -3,14 +3,30 @@ #include "stream_config.hpp" #include #include +#include #include "RamBuffer.hpp" using namespace std; using namespace stream_config; +using namespace buffer_config; int main (int argc, char *argv[]) { + if (argc != 3) { + cout << endl; + cout << "Usage: std_stream_send [detector_json_filename]" + " [bit_depth]" << endl; + cout << "\tdetector_json_filename: detector config file path." << endl; + cout << "\tbit_depth: bit depth of the incoming udp packets." << endl; + cout << endl; + + exit(-1); + } + + const auto config = StreamSendConfig::from_json_file(string(argv[1])); + const int bit_depth = atoi(argv[2]); + auto ctx = zmq_ctx_new(); zmq_ctx_set(ctx, ZMQ_IO_THREADS, STREAM_ZMQ_IO_THREADS); @@ -27,12 +43,14 @@ int main (int argc, char *argv[]) throw runtime_error(zmq_strerror(errno)); } - if (zmq_bind(sender, "tcp://127.0.0.1:10000") != 0) { + if (zmq_bind(sender, config.stream_address.c_str()) != 0) { throw runtime_error(zmq_strerror(errno)); } + const size_t IMAGE_N_BYTES = config.image_n_pixels * bit_depth / 8; RamBuffer image_buffer(config.detector_name + "_assembler", - sizeof(ImageMetadata), assembler.get_image_n_bytes(), 1); + sizeof(ImageMetadata), IMAGE_N_BYTES, + config.n_modules, RAM_BUFFER_N_SLOTS); while (true) {