Adapt sender and receiver to new struct

This commit is contained in:
2020-04-22 11:36:34 +02:00
parent b3d7bf6852
commit 29a361572b
2 changed files with 31 additions and 18 deletions
+22 -9
View File
@@ -103,17 +103,30 @@ int main (int argc, char *argv[]) {
input_file.close();
zmq_send(socket,
metadata_buffer.get(),
sizeof(FileBufferMetadata),
ZMQ_SNDMORE);
for (size_t i_frame=0; i_frame<BufferUtils::FILE_MOD; i_frame++) {
ModuleFrame module_frame = {
metadata_buffer->pulse_id[i_frame],
metadata_buffer->frame_index[i_frame],
metadata_buffer->daq_rec[i_frame],
metadata_buffer->n_received_packets[i_frame],
module_id
};
zmq_send(socket,
image_buffer.get(),
BufferUtils::FILE_MOD * 512 * 1024 * 2,
0);
zmq_send(socket,
&module_frame,
sizeof(ModuleFrame),
ZMQ_SNDMORE);
this_thread::sleep_for(chrono::milliseconds(1000));
zmq_send(socket,
metadata_buffer.get(),
sizeof(FileBufferMetadata),
ZMQ_SNDMORE);
zmq_send(socket,
(char*) (image_buffer.get() + (i_frame * 512 * 1024)),
512 * 1024 * 2,
0);
}
}
zmq_close(socket);
+9 -9
View File
@@ -5,6 +5,7 @@
#include <string>
#include <RingBuffer.hpp>
#include <BufferUtils.hpp>
#include <jungfrau.hpp>
using namespace std;
@@ -45,34 +46,33 @@ int main (int argc, char *argv[])
throw runtime_error(strerror (errno));
}
auto metadata_buffer = make_unique<FileBufferMetadata>();
auto metadata_buffer = make_unique<ModuleFrame>();
auto image_buffer = make_unique<uint16_t[]>(
BufferUtils::FILE_MOD * 512 * 1024);
auto image_buffer = make_unique<uint16_t[]>(512 * 1024);
while (true) {
auto n_bytes_metadata = zmq_recv(
socket,
metadata_buffer.get(),
sizeof(FileBufferMetadata),
sizeof(ModuleFrame),
0);
if (n_bytes_metadata != sizeof(FileBufferMetadata)) {
if (n_bytes_metadata != sizeof(ModuleFrame)) {
throw runtime_error("Unexpected number of bytes in metadata.");
}
auto n_bytes_image = zmq_recv(
socket,
image_buffer.get(),
BufferUtils::FILE_MOD * 512 * 1024 * 2,
512 * 1024 * 2,
0);
if (n_bytes_image != BufferUtils::FILE_MOD * 512 * 1024 * 2) {
if (n_bytes_image != 512 * 1024 * 2) {
throw runtime_error("Unexpected number of bytes in image.");
}
cout << "Received " << metadata_buffer->start_pulse_id;
cout << " to " << metadata_buffer->stop_pulse_id;
cout << "Received " << metadata_buffer->pulse_id;
cout << " from " << metadata_buffer->module_id;
cout << endl;
}