...
This commit is contained in:
parent
159e3ad796
commit
432ff52ff4
@ -57,55 +57,70 @@ RaptorEagleCCD::AcquisitionProcess::~AcquisitionProcess()
|
|||||||
|
|
||||||
void RaptorEagleCCD::AcquisitionProcess::start(const std::shared_ptr<acq_params_t>& params)
|
void RaptorEagleCCD::AcquisitionProcess::start(const std::shared_ptr<acq_params_t>& params)
|
||||||
{
|
{
|
||||||
|
// if (isAcqInProgress) {
|
||||||
|
// throw std::system_error(RaptorEagleCCDError::ERROR_ACQUISITION_IN_PROGRESS);
|
||||||
|
// }
|
||||||
|
|
||||||
isAcqInProgress = true;
|
isAcqInProgress = true;
|
||||||
|
|
||||||
// _acqParams = std::move(params);
|
// _acqParams = std::move(params);
|
||||||
_acqParams = params;
|
_acqParams = params;
|
||||||
_acqParams->abortTime = std::chrono::utc_clock::time_point(); // to ensure the time point is in past
|
// _acqParams->abortTime = std::chrono::utc_clock::time_point(); // to ensure the time point is in past
|
||||||
|
|
||||||
_snapAndCopyFuture = std::async(std::launch::async, [self = shared_from_this(), this]() {
|
_snapAndCopyFuture = std::async(std::launch::async, [self = shared_from_this(), this]() {
|
||||||
std::chrono::milliseconds timeout =
|
std::chrono::milliseconds timeout =
|
||||||
CAMERA_CAPTURE_TIMEOUT_ADD_CONSTANT +
|
CAMERA_CAPTURE_TIMEOUT_ADD_CONSTANT +
|
||||||
std::chrono::milliseconds(static_cast<std::chrono::milliseconds::rep>(_acqParams->expTime * 1000));
|
std::chrono::milliseconds(static_cast<std::chrono::milliseconds::rep>(_acqParams->expTime * 1000));
|
||||||
|
|
||||||
static char color_space[] = "Grey";
|
static char color_space[] = "Gray";
|
||||||
std::stringstream st;
|
std::stringstream st;
|
||||||
st << std::this_thread::get_id();
|
st << std::this_thread::get_id();
|
||||||
|
|
||||||
_manager->logDebug("Arm grabber and wait for acquisition starting trigger (thread id: {}) ...", st.str());
|
_manager->logDebug("Arm grabber and wait for acquisition starting trigger (thread id: {}) ...", st.str());
|
||||||
|
|
||||||
_manager->xclibApiCall(pxd_doSnap(_manager->_cameraUnitmap, 1, timeout.count()),
|
_manager->xclibApiCall(pxd_doSnap(_manager->_cameraUnitmap, 1, timeout.count()),
|
||||||
std::format("pxd_doSnap({},1,{})", _manager->_cameraUnitmap, timeout.count()));
|
std::format("pxd_doSnap({}, 1, {})", _manager->_cameraUnitmap, timeout.count()));
|
||||||
|
|
||||||
_manager->logDebug("Capture is finished (thread id: {})!", st.str());
|
_manager->logDebug("Capture is finished (thread id: {})!", st.str());
|
||||||
|
|
||||||
if ((_acqParams->abortTime > _acqParams->startTime) &&
|
if ((_acqParams->abortTime > _acqParams->startTime) &&
|
||||||
!_acqParams->saveInAbort) { // abort acquisition was occured! hust exit
|
!_acqParams->saveInAbort) { // abort acquisition was occured! just exit
|
||||||
_manager->logInfo("It seems the acquisition was aborted! Do not save acquired image!");
|
_manager->logInfo("It seems the acquisition was aborted! Do not save acquired image!");
|
||||||
|
|
||||||
|
isAcqInProgress = false;
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_manager->logDebug("Image ROI [{}, {}, {}, {}] (binned {}x{})", _acqParams->roiStartX, _acqParams->roiStartY,
|
||||||
|
_acqParams->roiWidth, _acqParams->roiHeight, _acqParams->binX, _acqParams->binY);
|
||||||
_manager->logDebug("Copy image from grabber to buffer (thread id: {}) ...", st.str());
|
_manager->logDebug("Copy image from grabber to buffer (thread id: {}) ...", st.str());
|
||||||
|
|
||||||
size_t npix = _acqParams->roiWidth * _acqParams->roiHeight;
|
size_t npix = _acqParams->roiWidth * _acqParams->roiHeight;
|
||||||
|
|
||||||
_imageBufferRows = static_cast<size_t>(std::ceil(npix / _manager->_dimCCD[0]));
|
_imageBufferRows = static_cast<size_t>(std::ceil(npix / _manager->_dimCCD[0]));
|
||||||
size_t sz = _imageBufferRows * npix;
|
size_t sz = _imageBufferRows * _manager->_dimCCD[0];
|
||||||
|
|
||||||
if (_imageBufferSize < sz) {
|
try {
|
||||||
_imageBufferSize = sz;
|
if (_imageBufferSize < sz) {
|
||||||
_imageBuffer.reset(new ushort[sz]); // may thow std::bad_alloc here!
|
_manager->logDebug("Reallocate image buffer to {} elements", sz);
|
||||||
|
_imageBufferSize = sz;
|
||||||
|
_imageBuffer.reset(new ushort[sz]); // may thow std::bad_alloc here!
|
||||||
|
}
|
||||||
|
|
||||||
|
auto log_str = std::format("pxd_readushort({}, 1, 0, 0, -1, {}, {}, {}, \"{}\")", _manager->_cameraUnitmap,
|
||||||
|
_imageBufferRows, (void*)_imageBuffer.get(), _imageBufferSize, color_space);
|
||||||
|
|
||||||
|
_manager->xclibApiCall(pxd_readushort(_manager->_cameraUnitmap, 1, 0, 0, -1, _imageBufferRows,
|
||||||
|
_imageBuffer.get(), _imageBufferSize, (char*)color_space),
|
||||||
|
log_str);
|
||||||
|
|
||||||
|
isAcqInProgress = false;
|
||||||
|
} catch (...) {
|
||||||
|
isAcqInProgress = false;
|
||||||
|
throw;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto log_str = std::format("pxd_readushort({}, 1, 0, 0, -1, {}, {}, {}, \"{}\")", _manager->_cameraUnitmap,
|
|
||||||
_imageBufferRows, (void*)_imageBuffer.get(), _imageBufferSize, color_space);
|
|
||||||
|
|
||||||
_manager->xclibApiCall(pxd_readushort(_manager->_cameraUnitmap, 1, 0, 0, -1, _imageBufferRows,
|
|
||||||
_imageBuffer.get(), _imageBufferSize, (char*)color_space),
|
|
||||||
log_str);
|
|
||||||
|
|
||||||
isAcqInProgress = false;
|
|
||||||
|
|
||||||
// ------- save to FITS file --------
|
// ------- save to FITS file --------
|
||||||
|
|
||||||
@ -114,7 +129,11 @@ void RaptorEagleCCD::AcquisitionProcess::start(const std::shared_ptr<acq_params_
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string fname{"!"}; // to overwrite existing file
|
||||||
|
fname += _acqParams->filename;
|
||||||
|
|
||||||
_manager->logInfo("Try to save FITS file with name '{}'", _acqParams->filename);
|
_manager->logInfo("Try to save FITS file with name '{}'", _acqParams->filename);
|
||||||
|
_manager->logTrace("Actual saving filename: {}", fname);
|
||||||
|
|
||||||
fitsfile* fitsFilePtr;
|
fitsfile* fitsFilePtr;
|
||||||
int status = 0;
|
int status = 0;
|
||||||
@ -129,13 +148,13 @@ void RaptorEagleCCD::AcquisitionProcess::start(const std::shared_ptr<acq_params_
|
|||||||
fits_clear_errmsg();
|
fits_clear_errmsg();
|
||||||
|
|
||||||
_manager->logDebug("Create an empty FITS file ...");
|
_manager->logDebug("Create an empty FITS file ...");
|
||||||
fits_create_file(&fitsFilePtr, _acqParams->filename.c_str(), &status);
|
fits_create_file(&fitsFilePtr, fname.c_str(), &status);
|
||||||
|
|
||||||
_manager->logDebug("Create primary FITS HDU (dim = [{}, {}])", naxes[0], naxes[1]);
|
_manager->logDebug("Create primary FITS HDU (dim = [{}, {}])", naxes[0], naxes[1]);
|
||||||
fits_create_img(fitsFilePtr, USHORT_IMG, 2, naxes, &status);
|
fits_create_img(fitsFilePtr, USHORT_IMG, 2, naxes, &status);
|
||||||
|
|
||||||
_manager->logDebug("Write {} pixels to the HDU ...", npix);
|
_manager->logDebug("Write {} pixels to the HDU ...", npix);
|
||||||
fits_write_img(fitsFilePtr, USHORT_IMG, 1, (LONGLONG)npix, _imageBuffer.get(), &status);
|
fits_write_img(fitsFilePtr, TUSHORT, 1, (LONGLONG)npix, _imageBuffer.get(), &status);
|
||||||
|
|
||||||
|
|
||||||
// helper to convert std::string_view to C-lang null-terminated string
|
// helper to convert std::string_view to C-lang null-terminated string
|
||||||
@ -315,12 +334,15 @@ void RaptorEagleCCD::AcquisitionProcess::stop(bool save)
|
|||||||
if (isAcqInProgress) {
|
if (isAcqInProgress) {
|
||||||
_manager->logInfo("Abort current acquisition process!");
|
_manager->logInfo("Abort current acquisition process!");
|
||||||
|
|
||||||
auto bytes = _manager->readRegisters({0xD4}); // trigger mode register
|
_acqParams->saveInAbort = save;
|
||||||
bytes[0] |= CL_ABORT_CURRENT_EXP; // set abort acquisition bit
|
|
||||||
_manager->writeRegisters({0xD4}, bytes);
|
auto bytes = _manager->readRegisters({0xD4}); // curent trigger mode register
|
||||||
|
|
||||||
|
bytes[0] |= CL_ABORT_CURRENT_EXP; // set abort acquisition bit
|
||||||
|
|
||||||
_acqParams->abortTime = std::chrono::utc_clock::now();
|
_acqParams->abortTime = std::chrono::utc_clock::now();
|
||||||
_acqParams->saveInAbort = save;
|
_manager->writeRegisters({0xD4}, bytes);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
_manager->logWarn("There was no active acquisition process! Ignore!");
|
_manager->logWarn("There was no active acquisition process! Ignore!");
|
||||||
}
|
}
|
||||||
|
|||||||
@ -262,7 +262,7 @@ void RaptorEagleCCD::flipSystemStateBit(const size_t pos)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// FPGS control register get/set
|
// FPGA control register get/set
|
||||||
|
|
||||||
std::bitset<8> RaptorEagleCCD::getFPGAState()
|
std::bitset<8> RaptorEagleCCD::getFPGAState()
|
||||||
{
|
{
|
||||||
@ -272,7 +272,7 @@ std::bitset<8> RaptorEagleCCD::getFPGAState()
|
|||||||
|
|
||||||
std::bitset<8> bits{ans[0]};
|
std::bitset<8> bits{ans[0]};
|
||||||
|
|
||||||
logDebug("Get FPGS control register as 0b{} bits", bits.to_string());
|
logDebug("Get FPGA control register as 0b{} bits", bits.to_string());
|
||||||
|
|
||||||
return bits;
|
return bits;
|
||||||
}
|
}
|
||||||
@ -365,6 +365,32 @@ bool RaptorEagleCCD::initCamera(int unitmap)
|
|||||||
getMicroVersion();
|
getMicroVersion();
|
||||||
getFPGAVersion();
|
getFPGAVersion();
|
||||||
|
|
||||||
|
|
||||||
|
xclibApiCall(_dimCCD[0] = pxd_imageXdim(), "pxd_imageXdim()");
|
||||||
|
xclibApiCall(_dimCCD[1] = pxd_imageYdim(), "pxd_imageYdim()");
|
||||||
|
xclibApiCall(_bitsPerPixel = pxd_imageBdim(), "pxd_imageBdim()");
|
||||||
|
xclibApiCall(_imageFrameBuffNumber = pxd_imageZdim(), "pxd_imageZdim()");
|
||||||
|
|
||||||
|
logDebug("------- CCD and grabber hardware info -------");
|
||||||
|
logDebug("CCD full-frame dimension [{}, {}] pixels", _dimCCD[0], _dimCCD[1]);
|
||||||
|
logDebug("CCD bits per pixel: {}", _bitsPerPixel);
|
||||||
|
logDebug("Number of grabber image framebuffers: {}", _imageFrameBuffNumber);
|
||||||
|
logDebug("-----------------------------------------------");
|
||||||
|
|
||||||
|
|
||||||
|
logDebug("Set initial state (IDLE, full frame, binning to 1x1) ...");
|
||||||
|
(*this)[CAMERA_ATTR_READ_MODE] = CAMERA_ATTR_READ_MODE_NORMAL;
|
||||||
|
(*this)[CAMERA_ATTR_READ_RATE] = CAMERA_ATTR_READ_RATE_FAST;
|
||||||
|
(*this)[CAMERA_ATTR_ROI_STARTX] = 1; // in FITS notation (started from 1)!!!
|
||||||
|
(*this)[CAMERA_ATTR_ROI_STARTY] = 1; // in FITS notation (started from 1)!!!
|
||||||
|
(*this)[CAMERA_ATTR_ROI_WIDTH] = _dimCCD[0];
|
||||||
|
(*this)[CAMERA_ATTR_ROI_HEIGHT] = _dimCCD[1];
|
||||||
|
(*this)[CAMERA_ATTR_XBIN] = 1;
|
||||||
|
(*this)[CAMERA_ATTR_YBIN] = 1;
|
||||||
|
|
||||||
|
// IDLE mode
|
||||||
|
(*this)[CAMERA_ATTR_TRIGGER_MODE] = CAMERA_ATTR_TRIGGER_MODE_SNAPSHOT;
|
||||||
|
|
||||||
logInfo("Camera with unitmap '{}' is initialized", _cameraUnitmap);
|
logInfo("Camera with unitmap '{}' is initialized", _cameraUnitmap);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -381,7 +407,8 @@ void RaptorEagleCCD::openPIXCI()
|
|||||||
} else {
|
} else {
|
||||||
xclibApiCall(pxd_PIXCIopen("", "DEFAULT", ""), "pxd_PIXCIopen(\"\", \"DEFAULT\", \"\")");
|
xclibApiCall(pxd_PIXCIopen("", "DEFAULT", ""), "pxd_PIXCIopen(\"\", \"DEFAULT\", \"\")");
|
||||||
|
|
||||||
#include DEFAULT_EPIX_VIDEO_FMT_FILE // exported from XCAP (Linux 64-bit!): bin 1x1, full CCD frame
|
// #include DEFAULT_EPIX_VIDEO_FMT_FILE // exported from XCAP (Linux 64-bit!): bin 1x1, full CCD frame
|
||||||
|
#include "raptor_eagle-v.fmt" // exported from XCAP (Linux 64-bit!): bin 1x1, full CCD frame
|
||||||
pxd_videoFormatAsIncludedInit(0);
|
pxd_videoFormatAsIncludedInit(0);
|
||||||
xclibApiCall(pxd_videoFormatAsIncluded(0), "pxd_videoFormatAsIncluded(0)");
|
xclibApiCall(pxd_videoFormatAsIncluded(0), "pxd_videoFormatAsIncluded(0)");
|
||||||
}
|
}
|
||||||
@ -492,12 +519,12 @@ size_t RaptorEagleCCD::clWrite(const byte_seq_t& bytes)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_loggerSPtr->level() == spdlog::level::trace) {
|
// if (_loggerSPtr->level() == spdlog::level::trace) {
|
||||||
std::string s;
|
// std::string s;
|
||||||
adc::utils::AdcCharRangeFromValueRange(s, bytes, std::string_view(", "));
|
// adc::utils::AdcCharRangeFromValueRange(s, bytes, std::string_view(", "));
|
||||||
|
|
||||||
logTrace("Send to controller: [{}]", s);
|
// logTrace("Send to controller: [{}]", s);
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
|
||||||
size_t nbytes, tr_nbytes = 1 + _clChecksumBit;
|
size_t nbytes, tr_nbytes = 1 + _clChecksumBit;
|
||||||
@ -749,9 +776,9 @@ void RaptorEagleCCD::getHardwareInfo()
|
|||||||
ADC_CALIBRATION_POINT_1, ADC_CALIBRATION_POINT_2);
|
ADC_CALIBRATION_POINT_1, ADC_CALIBRATION_POINT_2);
|
||||||
|
|
||||||
// compute linear relation: Temp = k*ADC + b
|
// compute linear relation: Temp = k*ADC + b
|
||||||
_adcCCDTempCalibCoeffs[0] = (cnt2 - cnt1) / (ADC_CALIBRATION_POINT_2 - ADC_CALIBRATION_POINT_1); // k
|
_adcCCDTempCalibCoeffs[0] = (ADC_CALIBRATION_POINT_2 - ADC_CALIBRATION_POINT_1) / (cnt2 - cnt1); // k
|
||||||
_adcCCDTempCalibCoeffs[1] = ADC_CALIBRATION_POINT_2 - _adcCCDTempCalibCoeffs[0] * cnt2;
|
_adcCCDTempCalibCoeffs[1] = ADC_CALIBRATION_POINT_2 - _adcCCDTempCalibCoeffs[0] * cnt2;
|
||||||
logDebug("Computed ADC-to-Temp linear relation: Temp(C) = {:7.4f}*ADC(counts)+{:6.2f}", _adcCCDTempCalibCoeffs[0],
|
logDebug("Computed ADC-to-Temp linear relation: Temp(C) = {:7.4f}*ADC(counts) + {:6.2f}", _adcCCDTempCalibCoeffs[0],
|
||||||
_adcCCDTempCalibCoeffs[1]);
|
_adcCCDTempCalibCoeffs[1]);
|
||||||
|
|
||||||
logDebug("");
|
logDebug("");
|
||||||
@ -763,12 +790,17 @@ void RaptorEagleCCD::getHardwareInfo()
|
|||||||
|
|
||||||
_dacTECSetPointCalibCoeffs[0] = (cnt2 - cnt1) / (DAC_CALIBRATION_POINT_2 - DAC_CALIBRATION_POINT_1);
|
_dacTECSetPointCalibCoeffs[0] = (cnt2 - cnt1) / (DAC_CALIBRATION_POINT_2 - DAC_CALIBRATION_POINT_1);
|
||||||
_dacTECSetPointCalibCoeffs[1] = DAC_CALIBRATION_POINT_2 - _dacTECSetPointCalibCoeffs[0] * cnt2;
|
_dacTECSetPointCalibCoeffs[1] = DAC_CALIBRATION_POINT_2 - _dacTECSetPointCalibCoeffs[0] * cnt2;
|
||||||
logDebug("Computed DAC-to-Temp linear relation: Temp(C) = {:7.4f}*DAC(counts)+{:6.2f}",
|
if (_dacTECSetPointCalibCoeffs[1] > 0.0) {
|
||||||
_dacTECSetPointCalibCoeffs[0], _dacTECSetPointCalibCoeffs[1]);
|
logDebug("Computed DAC-to-Temp linear relation: Temp(C) = {:7.4f}*DAC(counts) + {:6.2f}",
|
||||||
|
_dacTECSetPointCalibCoeffs[0], _dacTECSetPointCalibCoeffs[1]);
|
||||||
|
} else {
|
||||||
|
logDebug("Computed DAC-to-Temp linear relation: Temp(C) = {:7.4f}*DAC(counts) - {:6.2f}",
|
||||||
|
_dacTECSetPointCalibCoeffs[0], std::abs(_dacTECSetPointCalibCoeffs[1]));
|
||||||
|
}
|
||||||
|
|
||||||
_dacTECSetPointCalibCoeffs[2] = (DAC_CALIBRATION_POINT_2 - DAC_CALIBRATION_POINT_1) / (cnt2 - cnt1);
|
_dacTECSetPointCalibCoeffs[2] = (DAC_CALIBRATION_POINT_2 - DAC_CALIBRATION_POINT_1) / (cnt2 - cnt1);
|
||||||
_dacTECSetPointCalibCoeffs[3] = cnt2 - _dacTECSetPointCalibCoeffs[0] * DAC_CALIBRATION_POINT_2;
|
_dacTECSetPointCalibCoeffs[3] = cnt2 - _dacTECSetPointCalibCoeffs[0] * DAC_CALIBRATION_POINT_2;
|
||||||
logDebug("Computed DAC-to-Temp linear relation: DAC(counts) = {}*Temp(C)+{}", _dacTECSetPointCalibCoeffs[2],
|
logDebug("Computed Temp-to-Dac linear relation: DAC(counts) = {}*Temp(C)+{}", _dacTECSetPointCalibCoeffs[2],
|
||||||
_dacTECSetPointCalibCoeffs[3]);
|
_dacTECSetPointCalibCoeffs[3]);
|
||||||
|
|
||||||
logDebug("---------------------------------");
|
logDebug("---------------------------------");
|
||||||
@ -807,7 +839,6 @@ void RaptorEagleCCD::getFPGAVersion()
|
|||||||
|
|
||||||
void RaptorEagleCCD::startAquisition()
|
void RaptorEagleCCD::startAquisition()
|
||||||
{
|
{
|
||||||
// if (_isAcqInProgress) {
|
|
||||||
if (AcquisitionProcess::isAcqInProgress) {
|
if (AcquisitionProcess::isAcqInProgress) {
|
||||||
logError("Acquisition is in progress! Exit!");
|
logError("Acquisition is in progress! Exit!");
|
||||||
throw std::system_error(RaptorEagleCCDError::ERROR_ACQUISITION_IN_PROGRESS);
|
throw std::system_error(RaptorEagleCCDError::ERROR_ACQUISITION_IN_PROGRESS);
|
||||||
@ -822,7 +853,7 @@ void RaptorEagleCCD::startAquisition()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
logInfo("Start acquisition process");
|
logInfo("Start acquisition process ...");
|
||||||
|
|
||||||
|
|
||||||
auto acq_pars = std::make_shared<acq_params_t>(acq_params_t({
|
auto acq_pars = std::make_shared<acq_params_t>(acq_params_t({
|
||||||
@ -850,69 +881,57 @@ void RaptorEagleCCD::startAquisition()
|
|||||||
.currentKeywords = std::move(_currentFitsKeywords) // move!!!
|
.currentKeywords = std::move(_currentFitsKeywords) // move!!!
|
||||||
}));
|
}));
|
||||||
|
|
||||||
// arm grabber
|
|
||||||
std::make_shared<AcquisitionProcess>(this)->start(acq_pars);
|
// adjust geometry
|
||||||
|
auto w = acq_pars->roiWidth / acq_pars->binX;
|
||||||
|
|
||||||
|
if (acq_pars->binX > 1) {
|
||||||
|
}
|
||||||
|
|
||||||
|
std::lock_guard lock_guard(_acqProcessesMutex);
|
||||||
|
|
||||||
|
auto sptr = std::make_shared<AcquisitionProcess>(this);
|
||||||
|
for (auto it = _acqProcesses.begin(); it != _acqProcesses.end();) {
|
||||||
|
if (it->expired()) {
|
||||||
|
it = _acqProcesses.erase(it);
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_acqProcesses.emplace_back(sptr);
|
||||||
|
// arm grabber here
|
||||||
|
sptr->start(acq_pars);
|
||||||
|
|
||||||
|
bits.set(CL_TRIGGER_MODE_SNAPSHOT_BIT); // start snapshot bit
|
||||||
|
bytes[0] = static_cast<uint8_t>(bits.to_ulong());
|
||||||
|
|
||||||
acq_pars->startTime = std::chrono::utc_clock::now();
|
acq_pars->startTime = std::chrono::utc_clock::now();
|
||||||
bits.set(CL_TRIGGER_MODE_SNAPSHOT_BIT); // start snapshot
|
writeRegisters({0xD4}, bytes); // write to trigger mode register (start snapshot)
|
||||||
|
|
||||||
|
int status;
|
||||||
// _doSnapAndCopyFuture = std::async(std::launch::async, [acq_pars = std::move(acq_pars), this]() mutable {
|
xclibApiCall(status = pxd_goneLive(_cameraUnitmap, 0), std::format("psxd_goneLive({}, 0)", _cameraUnitmap));
|
||||||
// std::chrono::milliseconds timeout =
|
if (status == 0) {
|
||||||
// CAMERA_CAPTURE_TIMEOUT_ADD_CONSTANT +
|
logError("CANNOT START ACQUIRING!!!");
|
||||||
// std::chrono::milliseconds(static_cast<std::chrono::milliseconds::rep>(acq_pars.expTime * 1000));
|
}
|
||||||
|
|
||||||
// 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<size_t>(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, 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);
|
|
||||||
// });
|
|
||||||
|
|
||||||
// logInfo("Start acquisition process");
|
|
||||||
|
|
||||||
// _isAcqInProgress = true;
|
|
||||||
// acq_pars.startTime = std::chrono::utc_clock::now();
|
|
||||||
// bits.set(CL_TRIGGER_MODE_SNAPSHOT_BIT); // start snapshot
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void RaptorEagleCCD::stopAcquisition()
|
void RaptorEagleCCD::stopAcquisition(bool save_acq)
|
||||||
{
|
{
|
||||||
if (_isAcqInProgress) {
|
std::lock_guard lock_guard(_acqProcessesMutex);
|
||||||
logInfo("Abort current acquisition process!");
|
|
||||||
auto bytes = readRegisters({0xD4}); // trigger mode register
|
for (auto it = _acqProcesses.begin(); it != _acqProcesses.end();) {
|
||||||
bytes[0] |= CL_ABORT_CURRENT_EXP; // set abort acquisition bit
|
if (it->expired()) {
|
||||||
writeRegisters({0xD4}, bytes);
|
it = _acqProcesses.erase(it);
|
||||||
} else {
|
} else {
|
||||||
logWarn("There was no active acquisition process! Ignore!");
|
auto sptr = it->lock();
|
||||||
|
sptr->stop(save_acq);
|
||||||
|
return; // there was only the single active aquisition, so exit here!
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logWarn("Stop acquisition is asked but there is no active one! Ignore!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -995,12 +1014,18 @@ void RaptorEagleCCD::initAttrComm()
|
|||||||
|
|
||||||
addCommand(CAMERA_CMD_START_EXP, [this]() {
|
addCommand(CAMERA_CMD_START_EXP, [this]() {
|
||||||
logDebug("Try to execute '{}' command", CAMERA_CMD_START_EXP);
|
logDebug("Try to execute '{}' command", CAMERA_CMD_START_EXP);
|
||||||
//
|
startAquisition();
|
||||||
});
|
});
|
||||||
|
|
||||||
addCommand(CAMERA_CMD_STOP_EXP, [this]() {
|
addCommand(CAMERA_CMD_STOP_EXP, [this]() {
|
||||||
logDebug("Try to execute '{}' command", CAMERA_CMD_STOP_EXP);
|
logDebug("Try to execute '{}' command", CAMERA_CMD_STOP_EXP);
|
||||||
//
|
stopAcquisition(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
addCommand(CAMERA_CMD_ABORT_EXP, [this]() {
|
||||||
|
logDebug("Try to execute '{}' command", CAMERA_CMD_ABORT_EXP);
|
||||||
|
stopAcquisition(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
@ -1756,10 +1781,10 @@ void RaptorEagleCCD::initAttrComm()
|
|||||||
logWarn("Invalid trigger mode! Set it to {}!", CAMERA_ATTR_TRIGGER_MODE_SNAPSHOT);
|
logWarn("Invalid trigger mode! Set it to {}!", CAMERA_ATTR_TRIGGER_MODE_SNAPSHOT);
|
||||||
}
|
}
|
||||||
|
|
||||||
// snapshot mode is self-clearing bit so activate it directly in 'startAcquision' method
|
// // snapshot mode is self-clearing bit so activate it directly in 'startAcquision' method
|
||||||
if (mode != CAMERA_ATTR_TRIGGER_MODE_SNAPSHOT) {
|
// if (mode != CAMERA_ATTR_TRIGGER_MODE_SNAPSHOT) {
|
||||||
writeRegisters({0xD4}, {bits});
|
writeRegisters({0xD4}, {bits});
|
||||||
}
|
// }
|
||||||
|
|
||||||
logDebug("Trigger mode bits are set to 0b{:08b}", bits);
|
logDebug("Trigger mode bits are set to 0b{:08b}", bits);
|
||||||
},
|
},
|
||||||
|
|||||||
@ -202,19 +202,21 @@ private:
|
|||||||
inline static std::atomic_bool isAcqInProgress = false;
|
inline static std::atomic_bool isAcqInProgress = false;
|
||||||
|
|
||||||
RaptorEagleCCD* _manager;
|
RaptorEagleCCD* _manager;
|
||||||
std::shared_ptr<acq_params_t> _acqParams;
|
std::shared_ptr<acq_params_t> _acqParams{};
|
||||||
std::unique_ptr<ushort> _imageBuffer;
|
std::unique_ptr<ushort[]> _imageBuffer{};
|
||||||
size_t _imageBufferSize;
|
size_t _imageBufferSize = 0;
|
||||||
size_t _imageBufferRows;
|
size_t _imageBufferRows = 0;
|
||||||
|
|
||||||
std::future<void> _snapAndCopyFuture;
|
std::future<void> _snapAndCopyFuture;
|
||||||
std::future<void> _saveFitsFileFuture;
|
// std::future<void> _saveFitsFileFuture;
|
||||||
};
|
};
|
||||||
|
|
||||||
std::string _epixFmtVideoFilename;
|
std::string _epixFmtVideoFilename;
|
||||||
int _cameraUnitmap;
|
int _cameraUnitmap;
|
||||||
|
|
||||||
uint16_t _dimCCD[2] = {2048, 2048}; // init to E2V 4240 CCD dimension
|
uint16_t _dimCCD[2] = {2048, 2048}; // init to E2V 4240 CCD dimension
|
||||||
|
int _bitsPerPixel = 16; // init to E2V 4240 CCD
|
||||||
|
int _imageFrameBuffNumber = 1;
|
||||||
|
|
||||||
// CCD temperature and TEC set point calibration relation coefficients
|
// CCD temperature and TEC set point calibration relation coefficients
|
||||||
double _adcCCDTempCalibCoeffs[2] = {0, 0}; // [k, b], Temp(degs C) = k*ADC + b
|
double _adcCCDTempCalibCoeffs[2] = {0, 0}; // [k, b], Temp(degs C) = k*ADC + b
|
||||||
@ -259,9 +261,12 @@ private:
|
|||||||
|
|
||||||
|
|
||||||
// acquisition process members
|
// acquisition process members
|
||||||
std::future<void> _doSnapAndCopyFuture;
|
std::mutex _acqProcessesMutex;
|
||||||
std::future<void> _saveFitsFile;
|
std::list<std::weak_ptr<AcquisitionProcess>> _acqProcesses{};
|
||||||
std::atomic_bool _isAcqInProgress;
|
|
||||||
|
// std::future<void> _doSnapAndCopyFuture;
|
||||||
|
// std::future<void> _saveFitsFile;
|
||||||
|
// std::atomic_bool _isAcqInProgress;
|
||||||
|
|
||||||
void initAttrComm();
|
void initAttrComm();
|
||||||
|
|
||||||
@ -320,7 +325,7 @@ private:
|
|||||||
|
|
||||||
// acquisition process methods
|
// acquisition process methods
|
||||||
void startAquisition();
|
void startAquisition();
|
||||||
void stopAcquisition();
|
void stopAcquisition(bool save_acq);
|
||||||
|
|
||||||
// logging helper methods
|
// logging helper methods
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user