From c6c825faee8bcb53009cd0e3bfba72888bca93a8 Mon Sep 17 00:00:00 2001 From: "Timur A. Fatkhullin" Date: Fri, 6 Dec 2024 11:48:22 +0300 Subject: [PATCH] ... --- raptor_eagle_ccd.cpp | 134 +++++++++++++++++++++++++++++++------------ raptor_eagle_ccd.h | 15 ++++- 2 files changed, 111 insertions(+), 38 deletions(-) diff --git a/raptor_eagle_ccd.cpp b/raptor_eagle_ccd.cpp index 4d40120..751567d 100644 --- a/raptor_eagle_ccd.cpp +++ b/raptor_eagle_ccd.cpp @@ -659,7 +659,7 @@ void RaptorEagleCCD::initAttrComm() // helper to setup 8-bit register attributes // 'validator' is a callable with signature: std::pair validator(const uchar&) auto create8BitAttr = [this](attr_ident_t name, auto reg_addr, auto&& validator, std::string_view log_mark) { - return RaptorEagleCCD::attribute_t( + return RaptorEagleCCD::attribute_t::makeArithAttr( name, [this, reg_addr, log_mark]() { auto bytes = readRegisters(reg_addr); @@ -688,7 +688,7 @@ void RaptorEagleCCD::initAttrComm() // helper to setup 12-bit register attributes // 'validator' is a callable with signature: std::pair validator(const uint16_t&) auto create12BitAttr = [this](attr_ident_t name, auto reg_addrs, auto&& validator, std::string_view log_mark) { - return RaptorEagleCCD::attribute_t( + return RaptorEagleCCD::attribute_t::makeArithAttr( name, [this, reg_addrs, log_mark]() { auto bytes = readRegisters(reg_addrs); @@ -717,7 +717,7 @@ void RaptorEagleCCD::initAttrComm() }; - /* commands */ + /* ------- COMMANDS ------- */ addCommand(CAMERA_CMD_INITCAM, [this]() { logDebug("Try to execute '{}' command", CAMERA_CMD_INITCAM); @@ -735,35 +735,97 @@ void RaptorEagleCCD::initAttrComm() // }); - /* attributes */ + addCommand(CAMERA_CMD_CLEAR_PERM_KEYW, [this]() { + auto N = _permanentFitsKeywords.size(); + _permanentFitsKeywords.clear(); + logInfo("Permanent FITS keywords are deleted! ({} keywords were cleared)", N); + }); + + + /* ------- ATTRIBUTES ------- */ + + /* PERMANENT AND CURRENT USER FITS KEYWORDS */ + + // NOTE: setter and deserializer adds keywords to the end of current array!!! addAttribute( - CAMERA_ATTR_CAMLINK_SETUP, + CAMERA_ATTR_PERM_KEYW, [this]() { - logTrace("Return CameraLink setup bits (current values: command-ack = {}, checksum = {})", _clCommandAckBit, - _clChecksumBit); + auto N = _permanentFitsKeywords.size(); + logTrace("Return permanent FITS keywords ({} keys)", N); - return std::vector({_clCommandAckBit, _clChecksumBit}); + return _permanentFitsKeywords; }, - [this](const std::vector& setup) { - logDebug("Try to set CameraLink setup bits ..."); + [this](const std::vector& keys) { + logInfo("Add permanent FITS keywords to current array ({} keys)", keys.size()); + for (auto& key : keys) { + logTrace("\tadd keyword record: |{}|", key); + _permanentFitsKeywords.push_back(key); + } + }, + [this]() { // serialize as "USER_FITS_KEY_SEP_SEQ" separated char sequences + attribute_t::serialized_t res; - if (setup.size() < 2) { - throw std::error_code(RaptorEagleCCDError::ERROR_INVALID_ATTR_VALUE); + if (_permanentFitsKeywords.size() > 1) { + for (auto& key : _permanentFitsKeywords) { + std::ranges::copy(key, std::back_inserter(res)); + std::ranges::copy(USER_FITS_KEY_SEP_SEQ, std::back_inserter(res)); + } + } else { + std::ranges::copy(_permanentFitsKeywords.front(), std::back_inserter(res)); } - _clCommandAckBit = setup[0] ? 1 : 0; - _clChecksumBit = - (setup[1] && _clCommandAckBit) ? 1 : 0; // checksum will be enabled only if command ack is set - - logDebug("Set CameraLink setup bits to: command-ack = {}, checksum = {}", _clCommandAckBit, _clChecksumBit); + return res; + }, + [this](const attribute_t::serialized_t& char_seq) { + for (auto const& key : char_seq | std::views::split(USER_FITS_KEY_SEP_SEQ)) { + _permanentFitsKeywords.push_back({key.begin(), key.end()}); + } }); + // NOTE: setter and deserializer adds keywords to the end of current array!!! + addAttribute( + CAMERA_ATTR_CURR_KEYW, + [this]() { + auto N = _currentFitsKeywords.size(); + logTrace("Return current FITS keywords ({} keys)", N); + + return _currentFitsKeywords; + }, + [this](const std::vector& keys) { + logInfo("Add current FITS keywords to current array ({} keys)", keys.size()); + for (auto& key : keys) { + logTrace("\tadd keyword record: |{}|", key); + _currentFitsKeywords.push_back(key); + } + }, + [this]() { // serialize as "USER_FITS_KEY_SEP_SEQ" separated char sequences + attribute_t::serialized_t res; + + if (_currentFitsKeywords.size() > 1) { + for (auto& key : _currentFitsKeywords) { + std::ranges::copy(key, std::back_inserter(res)); + std::ranges::copy(USER_FITS_KEY_SEP_SEQ, std::back_inserter(res)); + } + } else { + std::ranges::copy(_currentFitsKeywords.front(), std::back_inserter(res)); + } + + return res; + }, + [this](const attribute_t::serialized_t& char_seq) { + for (auto const& key : char_seq | std::views::split(USER_FITS_KEY_SEP_SEQ)) { + _currentFitsKeywords.push_back({key.begin(), key.end()}); + } + }); + + + /* EXPOSURE AND FRAMERATE */ // exposure time - addAttribute( + addAttribute(RaptorEagleCCD::attribute_t::makeArithAttr( CAMERA_ATTR_EXPTIME, [this]() { auto bytes = readRegisters(CL_EXPTIME_ADDR); @@ -795,11 +857,11 @@ void RaptorEagleCCD::initAttrComm() writeRegisters(CL_EXPTIME_ADDR, bytes); logDebug("Acquisition duration is set to {} second ({} 25nsec ticks)", etime, counts); - }); + })); // frame rate - addAttribute( + addAttribute(RaptorEagleCCD::attribute_t::makeArithAttr( CAMERA_ATTR_FRAME_RATE, [this]() { auto bytes = readRegisters(CL_FRAMERATE_ADDR); @@ -831,22 +893,22 @@ void RaptorEagleCCD::initAttrComm() writeRegisters(CL_FRAMERATE_ADDR, bytes); logDebug("Frame rate is set to {} MHz ({} 40MHz ticks)", r, counts); - }); + })); // number of exposures - addAttribute( + addAttribute(RaptorEagleCCD::attribute_t::makeArithAttr( CAMERA_ATTR_NEXP, - [this]() { - logTrace("Return number of frames in acquisition sequence (current value is {})", _frameNumbers); + [this]() -> size_t { + logTrace("Return number of frames in acquisition sequence (current value is {})", _frameNumbers.load()); return _frameNumbers; }, [this](const size_t& nframes) { _frameNumbers = nframes; - logDebug("Number of frames in acquisition sequence is set to {}", _frameNumbers); - }); + logDebug("Number of frames in acquisition sequence is set to {}", _frameNumbers.load()); + })); /* FRAME GEOMETRY RELATED ATTRIBUTES */ @@ -1002,7 +1064,7 @@ void RaptorEagleCCD::initAttrComm() "TEC set point")); // floating-point value - addAttribute( + addAttribute(RaptorEagleCCD::attribute_t::makeArithAttr( CAMERA_ATTR_TECPOINT, [this]() { double counts = (*this)[CAMERA_ATTR_TECPOINT_DAC]; @@ -1021,7 +1083,7 @@ void RaptorEagleCCD::initAttrComm() logInfo("Set TEC setup point to {} C", temp); (*this)[CAMERA_ATTR_TECPOINT_DAC] = counts; - }); + })); addAttribute( @@ -1048,7 +1110,7 @@ void RaptorEagleCCD::initAttrComm() /* CCD and PCB temperature (read-only) */ - addAttribute(CAMERA_ATTR_PCB_TEMP, [this]() { + addAttribute(RaptorEagleCCD::attribute_t::makeArithAttr(CAMERA_ATTR_PCB_TEMP, [this]() { uint16_t bits = 0x0FFF; double val = -1000; // impossible value @@ -1065,10 +1127,10 @@ void RaptorEagleCCD::initAttrComm() logTrace("Return PCB temperature (current value: {}; bits: {})", val, bits); return val; - }); + })); - addAttribute(CAMERA_ATTR_CCD_TEMP, [this]() { + addAttribute(RaptorEagleCCD::attribute_t::makeArithAttr(CAMERA_ATTR_CCD_TEMP, [this]() { uint16_t bits = 0xFFFF; double val = -1000; // impossible value @@ -1086,7 +1148,7 @@ void RaptorEagleCCD::initAttrComm() logTrace("Return CCD temperature (current value: {}; bits: {})", val, bits); return val; - }); + })); /* READ-OUT MODE (std::string_view "NORMAL" or "TEST") */ @@ -1217,7 +1279,7 @@ void RaptorEagleCCD::initAttrComm() // floating-point, value is expected in millisecs - addAttribute( + addAttribute(RaptorEagleCCD::attribute_t::makeArithAttr( CAMERA_ATTR_SHUTTER_CLOSEDELAY, [this]() { auto bytes = readRegisters({0xA7}); @@ -1245,11 +1307,11 @@ void RaptorEagleCCD::initAttrComm() logInfo("Shutter closed delay is set to {} msecs", d); logDebug("Shutter closed delay bits are set to 0x{:02X}", counts); - }); + })); // floating-point, value is expected in millisecs - addAttribute( + addAttribute(RaptorEagleCCD::attribute_t::makeArithAttr( CAMERA_ATTR_SHUTTER_OPENDELAY, [this]() { auto bytes = readRegisters({0xA6}); @@ -1277,7 +1339,7 @@ void RaptorEagleCCD::initAttrComm() logInfo("Shutter open delay is set to {} msecs", d); logDebug("Shutter open delay bits are set to 0x{:02X}", counts); - }); + })); /* TRIGGER MODE */ diff --git a/raptor_eagle_ccd.h b/raptor_eagle_ccd.h index bf3adfc..d253d87 100644 --- a/raptor_eagle_ccd.h +++ b/raptor_eagle_ccd.h @@ -23,6 +23,11 @@ class RaptorEagleCCD : public adc::AdcGenericDevice _currentTemplateFile; // CFITSIO template filename + std::vector _currentFitsKeywords; // current acquisition FITS keywords + std::vector _permanentFitsKeywords; // permanent user FITS keywords // hardware version info