diff --git a/acquisition_device/CMakeLists.txt b/acquisition_device/CMakeLists.txt index 020a8f684..2918bf4bc 100644 --- a/acquisition_device/CMakeLists.txt +++ b/acquisition_device/CMakeLists.txt @@ -2,6 +2,7 @@ ADD_LIBRARY(JFJochAcquisitionDevice STATIC AcquisitionDevice.cpp AcquisitionDevice.h AcquisitionCounters.cpp AcquisitionCounters.h HLSSimulatedDevice.cpp HLSSimulatedDevice.h + MockAcquisitionDevice.cpp MockAcquisitionDevice.h Completion.cpp Completion.h ../fpga/pcie_driver/jfjoch_fpga.h PCIExpressDevice.cpp PCIExpressDevice.h FPGAAcquisitionDevice.cpp FPGAAcquisitionDevice.h diff --git a/acquisition_device/MockAcquisitionDevice.cpp b/acquisition_device/MockAcquisitionDevice.cpp new file mode 100644 index 000000000..31a0c5ac1 --- /dev/null +++ b/acquisition_device/MockAcquisitionDevice.cpp @@ -0,0 +1,522 @@ +// SPDX-FileCopyrightText: 2026 Filip Leonarski, Paul Scherrer Institute +// SPDX-License-Identifier: GPL-3.0-only + +#include + +#include "MockAcquisitionDevice.h" + +namespace { + bool MaskEmpty(const uint64_t packet_mask[8]) { + for (int i = 0; i < 8; i++) { + if (packet_mask[i] != 0) + return false; + } + return true; + } +} + +MockAcquisitionDevice::MockAcquisitionDevice(uint16_t data_stream, size_t in_frame_buffer_size_modules) + : FPGAAcquisitionDevice(data_stream), + collected_modules(2 * MAX_MODULES_FPGA), + summation_completions(MAX_MODULES_FPGA * MAX_FPGA_SUMMATION), + summation_mask(MAX_MODULES_FPGA, std::vector(MAX_FPGA_SUMMATION)), + summation_count(MAX_MODULES_FPGA), + summation_frame_prefix(MAX_MODULES_FPGA) { + mac_addr = 0xCCAA11223344; + ipv4_addr = 0x0132010A; + + max_modules = MAX_MODULES_FPGA; + + buffers.reserve(in_frame_buffer_size_modules); + for (size_t i = 0; i < in_frame_buffer_size_modules; i++) { + buffers.push_back(std::make_unique()); + buffer_device.push_back(reinterpret_cast(buffers.back().get())); + } +} + +MockAcquisitionDevice::~MockAcquisitionDevice() { + if (action_thread.joinable()) + action_thread.join(); + stop_frame_generator = true; +} + +void MockAcquisitionDevice::SetOutput(uint64_t image, uint32_t module_number, const DeviceOutput &output) { + if (outputs.size() <= image) + outputs.resize(image + 1); + if (outputs[image].size() <= module_number) + outputs[image].resize(module_number + 1); + outputs[image][module_number] = std::make_unique(output); +} + +void MockAcquisitionDevice::AddPacket(const Packet &packet) { + std::unique_lock ul(packets_mutex); + packets.push_back(packet); +} + +void MockAcquisitionDevice::CreateJFPacket(const DiffractionExperiment &experiment, uint64_t frame_number, + uint32_t eth_packet, uint32_t module_number, const uint16_t *data, + int8_t adjust_axis, uint8_t user) { + uint32_t half_module = ((eth_packet >= 64) ? 1 : 0); + AddPacket(Packet{ + .frame_number = frame_number, + .packet_number = eth_packet % 64, + .udp_port = static_cast(2 * module_number + half_module), + .column = 0, + .detector_type = SLS_DETECTOR_TYPE_JUNGFRAU, + .exptime = 0, + .bunchid = 0x1234567898765431L, + .timestamp = 0xABCDEF0000FEDCBAL, + .debug = 0, + .eth_error = (user % 2 == 1), + .len_error = (adjust_axis != 0) + }); +} + +void MockAcquisitionDevice::CreateJFPackets(const DiffractionExperiment &experiment, uint64_t frame_number_0, + uint64_t frames, uint32_t module_number, const uint16_t *data) { + for (uint64_t i = 0; i < frames; i++) { + for (int j = 0; j < 128; j++) + CreateJFPacket(experiment, frame_number_0 + i, j, module_number, nullptr, 0, 0); + } +} + +void MockAcquisitionDevice::CreateEIGERPacket(const DiffractionExperiment &experiment, uint64_t frame_number, + uint32_t eth_packet, uint32_t module_number, uint32_t col, + uint32_t row, const uint16_t *data) { + AddPacket(Packet{ + .frame_number = frame_number, + .packet_number = eth_packet % 128, + .udp_port = static_cast(2 * module_number + row), + .column = static_cast(col % 2), + .detector_type = SLS_DETECTOR_TYPE_EIGER, + .exptime = 0, + .bunchid = 0x1234567898765431L, + .timestamp = 0xABCDEF0000FEDCBAL, + .debug = 0 + }); +} + +void MockAcquisitionDevice::CreateXfelBunchIDPacket(double pulse_id, uint32_t event_code) { + Packet packet{}; + packet.bunchid_packet = true; + memcpy(&packet.bunchid, &pulse_id, sizeof(uint64_t)); + AddPacket(packet); +} + +void MockAcquisitionDevice::CreateFinalPacket(const DiffractionExperiment &experiment) { + CreateJFPacket(experiment, UINT64_MAX, 0, 0, nullptr, false); +} + +void MockAcquisitionDevice::HW_ReadActionRegister(DataCollectionConfig *job) { + memcpy(job, &cfg, sizeof(DataCollectionConfig)); +} + +void MockAcquisitionDevice::HW_WriteActionRegister(const DataCollectionConfig *job) { + memcpy(&cfg, job, sizeof(DataCollectionConfig)); +} + +void MockAcquisitionDevice::FPGA_StartAction(const DiffractionExperiment &experiment) { + if (action_thread.joinable()) + action_thread.join(); + + run_counter += 1; + idle = false; + action_thread = std::thread(&MockAcquisitionDevice::DataCollectionThread, this); +} + +void MockAcquisitionDevice::FPGA_EndAction() { + if (action_thread.joinable()) + action_thread.join(); +} + +bool MockAcquisitionDevice::HW_IsIdle() const { + return idle; +} + +bool MockAcquisitionDevice::HW_ReadMailbox(uint32_t *values) { + return completions.Get(*values); +} + +bool MockAcquisitionDevice::HW_SendWorkRequest(uint32_t handle) { + work_requests.Put(handle); + return true; +} + +void MockAcquisitionDevice::Cancel() { + cancel = true; +} + +// The mock does not process data, so calibration and spot finder settings are not used +void MockAcquisitionDevice::HW_LoadCalibration(const LoadCalibrationConfig &config) {} + +void MockAcquisitionDevice::HW_SetSpotFinderParameters(const SpotFinderParameters ¶ms) {} + +void MockAcquisitionDevice::HW_RunInternalGenerator(const FrameGeneratorConfig &config) { + frame_generator_future = std::async(std::launch::async, &MockAcquisitionDevice::FrameGenerator, this, config); +} + +void MockAcquisitionDevice::FrameGenerator(FrameGeneratorConfig config) { + // frame_generator.cpp, packet headers only + if ((config.modules > MAX_MODULES_FPGA) || (config.modules == 0)) + return; + if ((config.detector_type != SLS_DETECTOR_TYPE_EIGER) && (config.detector_type != SLS_DETECTOR_TYPE_JUNGFRAU)) + return; + if ((config.detector_type == SLS_DETECTOR_TYPE_EIGER) + && (config.eiger_bit_depth != 8) && (config.eiger_bit_depth != 16) && (config.eiger_bit_depth != 32)) + return; + if (config.frames == 0) + return; + // The frames for the generator have to fit in the card memory (64 modules) + uint32_t module_slots = config.modules * (config.images_in_memory + 1); + if ((config.detector_type == SLS_DETECTOR_TYPE_EIGER) && (config.eiger_bit_depth == 32)) + module_slots *= 2; + if (module_slots >= 64) + return; + + double pulse_id = config.pulse_id; + uint16_t data_stream_port = (config.data_stream & UINT8_MAX) << 8; + + // The packets wait until the data collection takes them - only a limited number of them + auto send = [this] (const Packet &packet) { + while (!cancel && !stop_frame_generator) { + { + std::unique_lock ul(packets_mutex); + if (packets.size() < 16384) { + packets.push_back(packet); + return; + } + } + std::this_thread::sleep_for(std::chrono::microseconds(10)); + } + }; + + // One packet with TUSER = 1, to reset the network cores on the way - it is dropped as an Ethernet error + send(Packet{.frame_number = 1, .udp_port = data_stream_port, .detector_type = SLS_DETECTOR_TYPE_JUNGFRAU, + .eth_error = true}); + + for (uint32_t f = 0; f < config.frames; f++) { + if (cancel || stop_frame_generator) + break; + uint64_t bunchid; + memcpy(&bunchid, &pulse_id, sizeof(uint64_t)); + + for (uint32_t m = 0; m < config.modules; m++) { + if (config.detector_type == SLS_DETECTOR_TYPE_JUNGFRAU) { + for (uint32_t p = 0; p < 128; p++) + send(Packet{ + .frame_number = f + 1, + .packet_number = p, + .udp_port = static_cast(data_stream_port | (2 * m)), + .column = 0, + .detector_type = SLS_DETECTOR_TYPE_JUNGFRAU, + .exptime = config.exptime, + .bunchid = bunchid, + .timestamp = config.exptime * f, + .debug = config.debug + }); + } else { + uint32_t bit_depth = config.eiger_bit_depth; + for (uint32_t p = 0; p < 16 * bit_depth; p++) { + uint32_t half_module = (p >= 8 * bit_depth) ? 1 : 0; + send(Packet{ + .frame_number = f + 1, + .packet_number = (p / 2) % (4 * bit_depth), + .udp_port = static_cast(data_stream_port | (2 * m + half_module)), + .column = static_cast(p % 2), + .detector_type = SLS_DETECTOR_TYPE_EIGER, + .exptime = config.exptime, + .bunchid = 0, + .timestamp = config.exptime * f, + .debug = config.debug + }); + } + } + } + pulse_id += 1.0; + } +} + +void MockAcquisitionDevice::DataCollectionThread() { + cancel = false; + stop_frame_generator = false; + + for (auto &c: collected_modules) + c = ModuleCompletion{.frame_number = UINT64_MAX}; + for (int m = 0; m < MAX_MODULES_FPGA; m++) { + summation_mask[m].assign(MAX_FPGA_SUMMATION, false); + summation_count[m] = 0; + summation_frame_prefix[m] = 0; + } + frames_in_group = 0; + handle_to_complete = HANDLE_START; + + uint32_t data_collection_id = (cfg.mode >> 16) & UINT16_MAX; + + // host_writer.cpp: work requests left from the previous data collection are returned unused + uint32_t handle; + while (work_requests.Get(handle)) + completions.Put((DATA_COLLECTION_ID_PURGE << 16) | handle); + completions.Put((data_collection_id << 16) | HANDLE_START); + + // data_collection_fsm.cpp: cancel is checked between packets + while (!cancel) { + Packet packet; + bool received = false; + { + std::unique_lock ul(packets_mutex); + if (!packets.empty()) { + packet = packets.front(); + packets.pop_front(); + received = true; + } + } + if (!received) + std::this_thread::sleep_for(std::chrono::microseconds(10)); + else if (!ReceivePacket(packet)) + break; + } + + EndDataCollection(); + + // Packets after the end of the data collection are dropped + stop_frame_generator = true; + if (frame_generator_future.valid()) + frame_generator_future.get(); + { + std::unique_lock ul(packets_mutex); + packets.clear(); + } + idle = true; +} + +bool MockAcquisitionDevice::ReceivePacket(const Packet &packet) { + // udp.cpp and sls_detector.cpp + udp_packets++; + if (packet.bunchid_packet) { + current_pulse_id = packet.bunchid; + return true; + } + if (packet.eth_error || packet.len_error) + return true; + if ((((packet.udp_port >> 8) & 0xF) != (cfg.data_stream & 0xF)) || (packet.frame_number == 0)) + return true; + sls_packets++; + + // data_collection_fsm.cpp: a frame far enough after the last one ends the data collection + uint64_t frame_number = packet.frame_number - 1; + if (frame_number >= static_cast(cfg.nframes) - 1 + DELAY_FRAMES_STOP_AND_QUIT) + return false; + + // stream512to768.cpp: location of the packet in the module, in units of 32 beats = 1024 pixels + uint32_t module = (packet.udp_port >> 1) & 0x1F; + uint32_t row = packet.udp_port & 1; + uint32_t column = packet.column & 1; + uint32_t eth_packet = packet.packet_number & 0x1FF; + uint32_t packet_parts; + + if (packet.detector_type == SLS_DETECTOR_TYPE_JUNGFRAU) { + packet_parts = 4; + eth_packet = (eth_packet % 128) | (row * 64); + } else if (cfg.mode & MODE_EIGER_8BIT) { + packet_parts = 4; + eth_packet = (row ? (64 + (eth_packet % 32) * 2) : (62 - (eth_packet % 32) * 2)) | column; + } else if (cfg.mode & MODE_EIGER_32BIT) { + packet_parts = 1; + uint32_t pos_of_4_line = (eth_packet % 128) / 2; + uint32_t pos_within_2_lines = eth_packet % 2; + eth_packet = (row ? (256 + pos_of_4_line * 4) : (252 - pos_of_4_line * 4)) | (2 * column) | pos_within_2_lines; + } else { + packet_parts = 2; + eth_packet = (row ? (128 + (eth_packet % 64) * 2) : (126 - (eth_packet % 64) * 2)) | column; + } + + // save_to_hbm.cpp: a module is complete only when the next frame of the same parity arrives + // for that module, or at the end of the data collection + ModuleCompletion &c = collected_modules[module * 2 + frame_number % 2]; + if (c.frame_number != frame_number) { + if (!MaskEmpty(c.packet_mask)) + SendCompletion(c); + c = ModuleCompletion{ + .frame_number = frame_number, + .exptime = packet.exptime, + .timestamp = packet.timestamp, + .bunchid = packet.bunchid, + .debug = packet.debug, + .module = module, + .detector_type = packet.detector_type + }; + } + for (uint32_t i = eth_packet * packet_parts; i < (eth_packet + 1) * packet_parts; i++) + c.packet_mask[i / 64] |= (1LU << (i % 64)); + c.packet_count += packet_parts; + return true; +} + +void MockAcquisitionDevice::SendCompletion(const ModuleCompletion &c) { + // frame_summation_reorder_compl.cpp: with summation, frames are grouped per module and only complete + // groups are written + uint32_t sum = cfg.nsummation & UINT8_MAX; + if (sum == 0) { + LoadModule(c); + return; + } + + uint64_t frame_prefix = c.frame_number / (sum + 1); + uint32_t frame_loc = c.frame_number % (sum + 1); + uint32_t m = c.module; + + if (frame_prefix > summation_frame_prefix[m]) { + SendSummationGroup(m); + summation_mask[m].assign(MAX_FPGA_SUMMATION, false); + summation_completions[m * MAX_FPGA_SUMMATION + frame_loc] = c; + summation_mask[m][frame_loc] = true; + summation_count[m] = 1; + summation_frame_prefix[m] = frame_prefix; + } else if (frame_prefix == summation_frame_prefix[m]) { + summation_completions[m * MAX_FPGA_SUMMATION + frame_loc] = c; + summation_mask[m][frame_loc] = true; + summation_count[m] += 1; + } else { + ModuleCompletion late = c; + late.ignore = true; + LoadModule(late); + } +} + +void MockAcquisitionDevice::SendSummationGroup(uint32_t m) { + uint32_t sum = cfg.nsummation & UINT8_MAX; + for (int i = 0; i <= sum; i++) { + if (summation_mask[m][i]) { + ModuleCompletion c = summation_completions[m * MAX_FPGA_SUMMATION + i]; + if (summation_count[m] != sum + 1) + c.ignore = true; + LoadModule(c); + } + } +} + +void MockAcquisitionDevice::LoadModule(const ModuleCompletion &c) { + // load_from_hbm.cpp: an incomplete summation group is dropped + if (c.ignore) + return; + + // frame_summation.cpp: one module per group, with the header of the first frame and the packets + // present in all frames + uint32_t sum = cfg.nsummation & UINT8_MAX; + if (sum == 0) { + WriteToHost(c); + return; + } + if (frames_in_group == 0) { + group_completion = c; + group_completion.frame_number = c.frame_number / (sum + 1); + } else { + for (int i = 0; i < 8; i++) + group_completion.packet_mask[i] &= c.packet_mask[i]; + group_completion.packet_count += c.packet_count; + } + frames_in_group++; + if (frames_in_group == sum + 1) { + frames_in_group = 0; + WriteToHost(group_completion); + } +} + +void MockAcquisitionDevice::WriteToHost(const ModuleCompletion &c) { + // host_writer.cpp: waits for a host buffer; only when the data collection is cancelled the module + // is dropped instead + uint32_t handle; + while (!work_requests.Get(handle)) { + if (cancel) + return; + std::this_thread::sleep_for(std::chrono::microseconds(10)); + } + if (handle >= buffer_device.size()) + return; + DeviceOutput *output = buffer_device[handle]; + + const DeviceOutput *ready_output = nullptr; + if (!outputs.empty()) { + auto &image = outputs[c.frame_number % outputs.size()]; + if (c.module < image.size()) + ready_output = image[c.module].get(); + } + if (ready_output != nullptr) + memcpy(output, ready_output, sizeof(DeviceOutput)); + else + memset(output, 0, sizeof(DeviceOutput)); + + ModuleStatistics &stats = output->module_statistics; + stats.frame_number = c.frame_number; + stats.timestamp = c.timestamp; + memcpy(&stats.pulse_id, &c.bunchid, sizeof(uint64_t)); + stats.detector_type = c.detector_type; + stats.exptime = c.exptime; + stats.debug = c.debug; + stats.pedestal = 0; + stats.packet_count = c.packet_count; + stats.module_number = c.module; + stats.load_calibration_destination = 0; + memcpy(stats.packet_mask, c.packet_mask, sizeof(stats.packet_mask)); + + // host_writer.cpp: a module is announced to the host only when the next one is written, or at the end + uint32_t data_collection_id = (cfg.mode >> 16) & UINT16_MAX; + if (handle_to_complete != HANDLE_START) + completions.Put((data_collection_id << 16) | handle_to_complete); + handle_to_complete = handle; +} + +void MockAcquisitionDevice::EndDataCollection() { + // save_to_hbm.cpp: modules still being collected, for each module the older frame first + for (int m = 0; m < MAX_MODULES_FPGA; m++) { + const ModuleCompletion &c0 = collected_modules[2 * m]; + const ModuleCompletion &c1 = collected_modules[2 * m + 1]; + const ModuleCompletion &first = (c0.frame_number < c1.frame_number) ? c0 : c1; + const ModuleCompletion &second = (c0.frame_number < c1.frame_number) ? c1 : c0; + if (!MaskEmpty(first.packet_mask)) + SendCompletion(first); + if (!MaskEmpty(second.packet_mask)) + SendCompletion(second); + } + + // frame_summation_reorder_compl.cpp + if ((cfg.nsummation & UINT8_MAX) > 0) { + for (int m = 0; m < MAX_MODULES_FPGA; m++) + SendSummationGroup(m); + } + + // host_writer.cpp + uint32_t data_collection_id = (cfg.mode >> 16) & UINT16_MAX; + if (handle_to_complete != HANDLE_START) + completions.Put((data_collection_id << 16) | handle_to_complete); + completions.Put((data_collection_id << 16) | HANDLE_END); +} + +DataCollectionStatus MockAcquisitionDevice::GetDataCollectionStatus() const { + DataCollectionStatus status{}; + + uint64_t pulse_id_u64 = current_pulse_id; + double pulse_id; + memcpy(&pulse_id, &pulse_id_u64, sizeof(double)); + + status.ctrl_reg = idle ? (1 << 4) : 0; + status.max_modules = MAX_MODULES_FPGA; + status.run_counter = run_counter; + status.current_pulseid = pulse_id; + status.packets_udp = udp_packets; + status.packets_sls = sls_packets; + return status; +} + +DeviceStatus MockAcquisitionDevice::GetDeviceStatus() const { + DeviceStatus status{}; + + strncpy(status.serial_number, "MOCK1", sizeof(status.serial_number)); + strncpy(status.device_number, "Mock device", sizeof(status.device_number)); + status.fpga_default_mac_addr = mac_addr; + status.eth_link_count = 1; + status.eth_link_status = 1; + status.packets_sls = sls_packets; + status.packets_udp = udp_packets; + return status; +} diff --git a/acquisition_device/MockAcquisitionDevice.h b/acquisition_device/MockAcquisitionDevice.h new file mode 100644 index 000000000..8a713d237 --- /dev/null +++ b/acquisition_device/MockAcquisitionDevice.h @@ -0,0 +1,134 @@ +// SPDX-FileCopyrightText: 2026 Filip Leonarski, Paul Scherrer Institute +// SPDX-License-Identifier: GPL-3.0-only + +#pragma once + +#include +#include +#include + +#include "FPGAAcquisitionDevice.h" + +// Behavioural mock of the FPGA card, for tests. It computes nothing: what the card writes for a module +// (pixels, spot finder, integration, ADU histogram, ROI, pixel statistics) is given ready-made with +// SetOutput(). The mock reproduces the contract of the card, as in HLSSimulatedDevice: which module is +// written to which host buffer and when, the order of completions, packet counts and masks, frames +// that are missing or late, summation, end of the data collection and cancel. +// +// The packets are given as for HLSSimulatedDevice (CreateJFPacket() etc. or the internal packet +// generator), only their pixel content is ignored. The module written for frame (after summation) F +// and module M is the output set for image F % (number of images set) and M - zeros if none was set - +// with the header part of ModuleStatistics (frame number, timestamp, pulse ID, exposure time, debug, +// detector type, module number, packet count and mask) filled by the mock from the packets. +// +// Unlike the HLS simulation, which keeps its state in function-local statics, any number of these +// devices can run at the same time. +class MockAcquisitionDevice : public FPGAAcquisitionDevice { + struct alignas(4096) FrameBuffer { uint8_t data[FPGA_BUFFER_LOCATION_SIZE]; }; + std::vector> buffers; + + // Header of one UDP packet, as the network cores of the card see it + struct Packet { + uint64_t frame_number; // as in the detector header, i.e. counted from one + uint32_t packet_number; + uint16_t udp_port; + uint16_t column; + uint8_t detector_type; + uint32_t exptime; + uint64_t bunchid; + uint64_t timestamp; + uint32_t debug; + bool eth_error; + bool len_error; + bool bunchid_packet; + }; + + // axis_completion in fpga/hls/hls_jfjoch.h + struct ModuleCompletion { + uint64_t packet_mask[8]; + uint64_t frame_number; + uint64_t exptime; + uint64_t timestamp; + uint64_t bunchid; + uint32_t debug; + uint16_t packet_count; + uint32_t module; + uint32_t detector_type; + bool ignore; + }; + + std::vector>> outputs; + + std::mutex packets_mutex; + std::deque packets; + + ThreadSafeFIFO work_requests; + ThreadSafeFIFO completions; + + DataCollectionConfig cfg{}; + + // save_to_hbm.cpp: module being collected, for each module and frame parity + std::vector collected_modules; + + // frame_summation_reorder_compl.cpp and frame_summation.cpp + std::vector summation_completions; + std::vector> summation_mask; + std::vector summation_count; + std::vector summation_frame_prefix; + uint32_t frames_in_group = 0; + ModuleCompletion group_completion{}; + + // host_writer.cpp + uint32_t handle_to_complete = HANDLE_START; + + std::thread action_thread; + std::future frame_generator_future; + std::atomic cancel = false; + std::atomic stop_frame_generator = false; + std::atomic idle = true; + + uint32_t run_counter = 0; + std::atomic current_pulse_id = UINT64_MAX; + std::atomic udp_packets = 0; + std::atomic sls_packets = 0; + + void HW_ReadActionRegister(DataCollectionConfig *job) override; + void HW_WriteActionRegister(const DataCollectionConfig *job) override; + void FPGA_StartAction(const DiffractionExperiment &experiment) override; + void FPGA_EndAction() override; + bool HW_IsIdle() const override; + bool HW_ReadMailbox(uint32_t *values) override; + bool HW_SendWorkRequest(uint32_t handle) override; + void HW_LoadCalibration(const LoadCalibrationConfig &config) override; + void HW_SetSpotFinderParameters(const SpotFinderParameters ¶ms) override; + void HW_RunInternalGenerator(const FrameGeneratorConfig &config) override; + + void AddPacket(const Packet &packet); + void FrameGenerator(FrameGeneratorConfig config); + + void DataCollectionThread(); + bool ReceivePacket(const Packet &packet); + void SendCompletion(const ModuleCompletion &c); + void SendSummationGroup(uint32_t module); + void LoadModule(const ModuleCompletion &c); + void WriteToHost(const ModuleCompletion &c); + void EndDataCollection(); +public: + MockAcquisitionDevice(uint16_t data_stream, size_t in_frame_buffer_size_modules); + ~MockAcquisitionDevice() override; + + void SetOutput(uint64_t image, uint32_t module_number, const DeviceOutput &output); + + void CreateJFPacket(const DiffractionExperiment& experiment, uint64_t frame_number, uint32_t eth_packet, + uint32_t module_number, const uint16_t *data, int8_t adjust_axis = 0, uint8_t user = 0); + void CreateJFPackets(const DiffractionExperiment& experiment, uint64_t frame_number_0, uint64_t frames, + uint32_t module_number, const uint16_t *data); + void CreateEIGERPacket(const DiffractionExperiment& experiment, uint64_t frame_number, uint32_t eth_packet, + uint32_t module_number, uint32_t col, uint32_t row, + const uint16_t *data); + void CreateXfelBunchIDPacket(double bunchid, uint32_t event_code); + void CreateFinalPacket(const DiffractionExperiment& experiment); + DataCollectionStatus GetDataCollectionStatus() const override; + void Cancel() override; + DeviceStatus GetDeviceStatus() const override; +};