From 4dd6893674171e756c5936e3bf62773198dadbc9 Mon Sep 17 00:00:00 2001 From: "Timur A. Fatkhullin" Date: Fri, 6 Dec 2024 22:31:23 +0300 Subject: [PATCH] ... --- raptor_eagle_ccd.cpp | 50 ++++++++++++++++++++++++++++++++++++++++++++ raptor_eagle_ccd.h | 37 ++++++++++++++++++++++++++++++++ 2 files changed, 87 insertions(+) diff --git a/raptor_eagle_ccd.cpp b/raptor_eagle_ccd.cpp index 60f29e4..a54c6a8 100644 --- a/raptor_eagle_ccd.cpp +++ b/raptor_eagle_ccd.cpp @@ -111,6 +111,11 @@ R convertUIntTo12Bit(uint16_t counts) } // namespace details + +/***********************************************************/ +/* ======= RaptorEagleCCD CLASS IMPLEMENTATION ======= */ +/***********************************************************/ + #define DEFAULT_EPIX_VIDEO_FMT_FILE "raptor_eagle-v.fmt" /* CONSTRUCTORS AND DESTRUCTOR */ @@ -744,6 +749,51 @@ void RaptorEagleCCD::getFPGAVersion() } +/* ACQUISITION PROCESS */ + +void RaptorEagleCCD::startAquisition(acq_params_t acq_pars) +{ + acq_pars.startTime = std::chrono::utc_clock::now(); + std::chrono::milliseconds snap_tm = + CAMERA_CAPTURE_TIMEOUT_ADD_CONSTANT + + std::chrono::milliseconds(static_cast(acq_pars.expTime * 1000)); + + _doSnapAndCopyFuture = std::async( + std::launch::async, + [acq_pars = std::move(acq_pars), this](std::chrono::milliseconds timeout) mutable { + static char color_space[] = "Grey"; + std::stringstream st; + st << std::this_thread::get_id(); + + logDebug("Arm grabber and wait for acquisition start trigger (thread id: {}) ...", st.str()); + + xclibApiCall(pxd_doSnap(_cameraUnitmap, 1, timeout.count()), + std::format("pxd_doSnap({},1,{})", _cameraUnitmap, timeout.count())); + + logDebug("Capture is finished (thread id: {})!", st.str()); + + logDebug("Copy image from grabber to buffer (thread id: {}) ...", st.str()); + + size_t npix = acq_pars.roiWidth * acq_pars.roiHeight; + + acq_pars.imageBufferRows = static_cast(std::ceil(npix / _dimCCD[0])); + size_t sz = acq_pars.imageBufferRows * npix; + + if (acq_pars.imageBufferSize < sz) { + acq_pars.imageBufferSize = sz; + acq_pars.imageBuffer.reset(new ushort[sz]); // may thow std::bad_alloc here! + } + + auto log_str = + std::format("pxd_readushort({}, 1, 0, 0, -1, {}, {}, {}, {})", _cameraUnitmap, acq_pars.imageBufferRows, + (void*)acq_pars.imageBuffer.get(), acq_pars.imageBufferSize, (void*)color_space); + xclibApiCall(pxd_readushort(_cameraUnitmap, 1, 0, 0, -1, acq_pars.imageBufferRows, + acq_pars.imageBuffer.get(), acq_pars.imageBufferSize, (char*)color_space), + log_str); + }, + std::move(snap_tm)); +} + /* CREATE COMMANDS AND ATTRIBUTES */ diff --git a/raptor_eagle_ccd.h b/raptor_eagle_ccd.h index 6e3c0c9..48a8fd3 100644 --- a/raptor_eagle_ccd.h +++ b/raptor_eagle_ccd.h @@ -8,6 +8,7 @@ #include #include +#include #include "raptor_eagle_exception.h" @@ -62,6 +63,10 @@ public: std::chrono::milliseconds(1000)}; + // additive constant to timeout for capture process (see pxd_doSnap XCLIB function) + // this constant will be added to exposure to compute actual timeout + static constexpr std::chrono::milliseconds CAMERA_CAPTURE_TIMEOUT_ADD_CONSTANT{240000}; // 4 mins + static constexpr std::string_view CAMERA_ATTR_XBIN{"XBIN"}; static constexpr std::string_view CAMERA_ATTR_YBIN{"YBIN"}; static constexpr std::string_view CAMERA_ATTR_ROI_STARTX{"ROI_STARTX"}; @@ -138,6 +143,28 @@ public: private: typedef std::vector byte_seq_t; + struct acq_params_t { + uint16_t ccdDim[2]; + std::chrono::utc_clock::time_point startTime; + double expTime; // in seconds + uint16_t roiStartX; + uint16_t roiStartY; + uint16_t roiWidth; + uint16_t roiHeight; + uint8_t binX; + uint8_t binY; + std::string_view readRate; + std::string_view readMode; + std::string filename; + std::string templateFilename; + std::vector permanentKeywords; + std::vector currentKeywords; + + std::unique_ptr imageBuffer; + size_t imageBufferSize; + size_t imageBufferRows; + }; + std::string _epixFmtVideoFilename; int _cameraUnitmap; @@ -181,6 +208,12 @@ private: // must be interpretated as 2-element array of calibration points [at 0C, at +40C] (4 bytes) const uint16_t* _dacTECSetPointCalibData{reinterpret_cast(_manufacturerData.data() + 14)}; + + // acquisition process members + std::future _doSnapAndCopyFuture; + std::future _saveFitsFile; + std::atomic_bool _isAcqInProgress; + void initAttrComm(); bool initCamera(int unitmap = 1); @@ -236,6 +269,10 @@ private: void getMicroVersion(); void getFPGAVersion(); + // acquisition process methods + void startAquisition(acq_params_t); + void stopAcquisition(); + // logging helper methods template