ZMQPreviewPublisher: Stream CBOR data

This commit is contained in:
2023-11-08 19:19:32 +01:00
parent cc34a9801e
commit 56476e3e5f
7 changed files with 157 additions and 279 deletions
+18 -51
View File
@@ -14,48 +14,23 @@ TEST_CASE("ZMQPreviewPublisher","[ZMQ]") {
DiffractionExperiment experiment(DetectorGeometry(1, 1, 0, 0, false));
std::string z = "Msg 0";
JFCalibration calibration(experiment);
publisher.Start(experiment, calibration);
publisher.StartDataCollection((uint8_t *) z.data(), z.size(), experiment.GetPreviewStride());
std::vector<int16_t> image(experiment.GetPixelsNum());
// Predictable random number generator
std::mt19937 g1(19876);
std::uniform_int_distribution<int16_t> distribution(-200,25000);
for (auto &i: image)
i = distribution(g1);
std::vector<SpotToSave> spots;
spots.push_back(SpotToSave{.x = 7, .y = 8, .intensity = 34, .indexed = false});
spots.push_back(SpotToSave{.x = 37, .y = 48, .intensity = 123, .indexed = true});
DataMessage message{.number = 564, .spots = spots};
publisher.Publish(experiment, image.data(), message);
z = "Msg 1";
publisher.SendImage((uint8_t *) z.data(), z.size(), 0);
std::string s;
// Pixel mask
REQUIRE(socket.Receive(s, false) > 0);
JFJochProtoBuf::PreviewFrame frame;
REQUIRE_NOTHROW(frame = jsonToGrpc<JFJochProtoBuf::PreviewFrame>(s));
REQUIRE(frame.pixel_depth() == 4);
REQUIRE(frame.image_number() == -1);
REQUIRE(s == "Msg 0");
// Frame
REQUIRE(socket.Receive(s, false) > 0);
REQUIRE_NOTHROW(frame = jsonToGrpc<JFJochProtoBuf::PreviewFrame>(s));
REQUIRE(frame.pixel_depth() == 2);
REQUIRE(frame.image_number() == 564);
std::vector<char> image_out = {frame.data().begin(), frame.data().end()};
REQUIRE(memcmp(image.data(), image_out.data(), experiment.GetPixelsNum() * experiment.GetPixelDepth()) == 0);
REQUIRE(frame.spots_size() == 2);
REQUIRE(frame.spots(0).x() == 7);
REQUIRE(!frame.spots(0).indexed());
REQUIRE(frame.spots(1).y() == 48);
REQUIRE(frame.spots(1).indexed());
REQUIRE(s == "Msg 1");
REQUIRE(socket.Receive(s, false) < 0);
}
@@ -73,39 +48,31 @@ TEST_CASE("ZMQPreviewPublisher_FrameNumbers","[ZMQ]") {
REQUIRE(experiment.GetPreviewStride() == 10);
JFCalibration calibration(experiment);
publisher.Start(experiment, calibration);
std::vector<int16_t> image(experiment.GetPixelsNum());
std::string z = "Start";
publisher.Publish(experiment, image.data(), DataMessage{.number = 0});
publisher.Publish(experiment, image.data(), DataMessage{.number = 9});
publisher.Publish(experiment, image.data(), DataMessage{.number = 12});
publisher.Publish(experiment, image.data(), DataMessage{.number = 10});
publisher.Publish(experiment, image.data(), DataMessage{.number = 25});
publisher.Publish(experiment, image.data(), DataMessage{.number = 20});
publisher.Publish(experiment, image.data(), DataMessage{.number = 18});
publisher.StartDataCollection((uint8_t *) z.data(), z.size(), experiment.GetPreviewStride());
for (const auto& i: {0, 9, 12, 10, 25, 20, 18}) {
z = "Msg " + std::to_string(i);
publisher.SendImage((uint8_t *) z.data(), z.size(), i);
}
std::string s;
JFJochProtoBuf::PreviewFrame frame;
// Pixel mask
REQUIRE(socket.Receive(s, false) > 0);
REQUIRE(s == "Start");
// Frame
REQUIRE(socket.Receive(s, false) > 0);
REQUIRE_NOTHROW(frame = jsonToGrpc<JFJochProtoBuf::PreviewFrame>(s));
REQUIRE(frame.image_number() == 0);
std::vector<char> image_out = {frame.data().begin(), frame.data().end()};
REQUIRE(s == "Msg 0");
REQUIRE(socket.Receive(s, false) > 0);
REQUIRE_NOTHROW(frame = jsonToGrpc<JFJochProtoBuf::PreviewFrame>(s));
REQUIRE(frame.image_number() == 12);
REQUIRE(s == "Msg 12");
REQUIRE(socket.Receive(s, false) > 0);
REQUIRE_NOTHROW(frame = jsonToGrpc<JFJochProtoBuf::PreviewFrame>(s));
REQUIRE(frame.image_number() == 25);
REQUIRE(s == "Msg 25");
REQUIRE(socket.Receive(s, false) < 0);
}