This commit is contained in:
Timur A. Fatkhullin 2024-12-06 11:48:22 +03:00
parent 5f6b7fa4cf
commit c6c825faee
2 changed files with 111 additions and 38 deletions

View File

@ -659,7 +659,7 @@ void RaptorEagleCCD::initAttrComm()
// helper to setup 8-bit register attributes // helper to setup 8-bit register attributes
// 'validator' is a callable with signature: std::pair<uchar, std::string> validator(const uchar&) // 'validator' is a callable with signature: std::pair<uchar, std::string> validator(const uchar&)
auto create8BitAttr = [this](attr_ident_t name, auto reg_addr, auto&& validator, std::string_view log_mark) { 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, name,
[this, reg_addr, log_mark]() { [this, reg_addr, log_mark]() {
auto bytes = readRegisters(reg_addr); auto bytes = readRegisters(reg_addr);
@ -688,7 +688,7 @@ void RaptorEagleCCD::initAttrComm()
// helper to setup 12-bit register attributes // helper to setup 12-bit register attributes
// 'validator' is a callable with signature: std::pair<uint16_t, std::string> validator(const uint16_t&) // 'validator' is a callable with signature: std::pair<uint16_t, std::string> validator(const uint16_t&)
auto create12BitAttr = [this](attr_ident_t name, auto reg_addrs, auto&& validator, std::string_view log_mark) { 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, name,
[this, reg_addrs, log_mark]() { [this, reg_addrs, log_mark]() {
auto bytes = readRegisters(reg_addrs); auto bytes = readRegisters(reg_addrs);
@ -717,7 +717,7 @@ void RaptorEagleCCD::initAttrComm()
}; };
/* commands */ /* ------- COMMANDS ------- */
addCommand(CAMERA_CMD_INITCAM, [this]() { addCommand(CAMERA_CMD_INITCAM, [this]() {
logDebug("Try to execute '{}' command", CAMERA_CMD_INITCAM); 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( addAttribute(
CAMERA_ATTR_CAMLINK_SETUP, CAMERA_ATTR_PERM_KEYW,
[this]() { [this]() {
logTrace("Return CameraLink setup bits (current values: command-ack = {}, checksum = {})", _clCommandAckBit, auto N = _permanentFitsKeywords.size();
_clChecksumBit); logTrace("Return permanent FITS keywords ({} keys)", N);
return std::vector<uint8_t>({_clCommandAckBit, _clChecksumBit}); return _permanentFitsKeywords;
}, },
[this](const std::vector<uint8_t>& setup) { [this](const std::vector<std::string>& keys) {
logDebug("Try to set CameraLink setup bits ..."); 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) { if (_permanentFitsKeywords.size() > 1) {
throw std::error_code(RaptorEagleCCDError::ERROR_INVALID_ATTR_VALUE); 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; return res;
_clChecksumBit = },
(setup[1] && _clCommandAckBit) ? 1 : 0; // checksum will be enabled only if command ack is set [this](const attribute_t::serialized_t& char_seq) {
for (auto const& key : char_seq | std::views::split(USER_FITS_KEY_SEP_SEQ)) {
logDebug("Set CameraLink setup bits to: command-ack = {}, checksum = {}", _clCommandAckBit, _clChecksumBit); _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<std::string>& 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 AND FRAMERATE */
// exposure time // exposure time
addAttribute( addAttribute(RaptorEagleCCD::attribute_t::makeArithAttr(
CAMERA_ATTR_EXPTIME, CAMERA_ATTR_EXPTIME,
[this]() { [this]() {
auto bytes = readRegisters(CL_EXPTIME_ADDR); auto bytes = readRegisters(CL_EXPTIME_ADDR);
@ -795,11 +857,11 @@ void RaptorEagleCCD::initAttrComm()
writeRegisters(CL_EXPTIME_ADDR, bytes); writeRegisters(CL_EXPTIME_ADDR, bytes);
logDebug("Acquisition duration is set to {} second ({} 25nsec ticks)", etime, counts); logDebug("Acquisition duration is set to {} second ({} 25nsec ticks)", etime, counts);
}); }));
// frame rate // frame rate
addAttribute( addAttribute(RaptorEagleCCD::attribute_t::makeArithAttr(
CAMERA_ATTR_FRAME_RATE, CAMERA_ATTR_FRAME_RATE,
[this]() { [this]() {
auto bytes = readRegisters(CL_FRAMERATE_ADDR); auto bytes = readRegisters(CL_FRAMERATE_ADDR);
@ -831,22 +893,22 @@ void RaptorEagleCCD::initAttrComm()
writeRegisters(CL_FRAMERATE_ADDR, bytes); writeRegisters(CL_FRAMERATE_ADDR, bytes);
logDebug("Frame rate is set to {} MHz ({} 40MHz ticks)", r, counts); logDebug("Frame rate is set to {} MHz ({} 40MHz ticks)", r, counts);
}); }));
// number of exposures // number of exposures
addAttribute( addAttribute(RaptorEagleCCD::attribute_t::makeArithAttr(
CAMERA_ATTR_NEXP, CAMERA_ATTR_NEXP,
[this]() { [this]() -> size_t {
logTrace("Return number of frames in acquisition sequence (current value is {})", _frameNumbers); logTrace("Return number of frames in acquisition sequence (current value is {})", _frameNumbers.load());
return _frameNumbers; return _frameNumbers;
}, },
[this](const size_t& nframes) { [this](const size_t& nframes) {
_frameNumbers = 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 */ /* FRAME GEOMETRY RELATED ATTRIBUTES */
@ -1002,7 +1064,7 @@ void RaptorEagleCCD::initAttrComm()
"TEC set point")); "TEC set point"));
// floating-point value // floating-point value
addAttribute( addAttribute(RaptorEagleCCD::attribute_t::makeArithAttr(
CAMERA_ATTR_TECPOINT, CAMERA_ATTR_TECPOINT,
[this]() { [this]() {
double counts = (*this)[CAMERA_ATTR_TECPOINT_DAC]; double counts = (*this)[CAMERA_ATTR_TECPOINT_DAC];
@ -1021,7 +1083,7 @@ void RaptorEagleCCD::initAttrComm()
logInfo("Set TEC setup point to {} C", temp); logInfo("Set TEC setup point to {} C", temp);
(*this)[CAMERA_ATTR_TECPOINT_DAC] = counts; (*this)[CAMERA_ATTR_TECPOINT_DAC] = counts;
}); }));
addAttribute( addAttribute(
@ -1048,7 +1110,7 @@ void RaptorEagleCCD::initAttrComm()
/* CCD and PCB temperature (read-only) */ /* 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; uint16_t bits = 0x0FFF;
double val = -1000; // impossible value double val = -1000; // impossible value
@ -1065,10 +1127,10 @@ void RaptorEagleCCD::initAttrComm()
logTrace("Return PCB temperature (current value: {}; bits: {})", val, bits); logTrace("Return PCB temperature (current value: {}; bits: {})", val, bits);
return val; return val;
}); }));
addAttribute(CAMERA_ATTR_CCD_TEMP, [this]() { addAttribute(RaptorEagleCCD::attribute_t::makeArithAttr(CAMERA_ATTR_CCD_TEMP, [this]() {
uint16_t bits = 0xFFFF; uint16_t bits = 0xFFFF;
double val = -1000; // impossible value double val = -1000; // impossible value
@ -1086,7 +1148,7 @@ void RaptorEagleCCD::initAttrComm()
logTrace("Return CCD temperature (current value: {}; bits: {})", val, bits); logTrace("Return CCD temperature (current value: {}; bits: {})", val, bits);
return val; return val;
}); }));
/* READ-OUT MODE (std::string_view "NORMAL" or "TEST") */ /* READ-OUT MODE (std::string_view "NORMAL" or "TEST") */
@ -1217,7 +1279,7 @@ void RaptorEagleCCD::initAttrComm()
// floating-point, value is expected in millisecs // floating-point, value is expected in millisecs
addAttribute( addAttribute(RaptorEagleCCD::attribute_t::makeArithAttr(
CAMERA_ATTR_SHUTTER_CLOSEDELAY, CAMERA_ATTR_SHUTTER_CLOSEDELAY,
[this]() { [this]() {
auto bytes = readRegisters({0xA7}); auto bytes = readRegisters({0xA7});
@ -1245,11 +1307,11 @@ void RaptorEagleCCD::initAttrComm()
logInfo("Shutter closed delay is set to {} msecs", d); logInfo("Shutter closed delay is set to {} msecs", d);
logDebug("Shutter closed delay bits are set to 0x{:02X}", counts); logDebug("Shutter closed delay bits are set to 0x{:02X}", counts);
}); }));
// floating-point, value is expected in millisecs // floating-point, value is expected in millisecs
addAttribute( addAttribute(RaptorEagleCCD::attribute_t::makeArithAttr(
CAMERA_ATTR_SHUTTER_OPENDELAY, CAMERA_ATTR_SHUTTER_OPENDELAY,
[this]() { [this]() {
auto bytes = readRegisters({0xA6}); auto bytes = readRegisters({0xA6});
@ -1277,7 +1339,7 @@ void RaptorEagleCCD::initAttrComm()
logInfo("Shutter open delay is set to {} msecs", d); logInfo("Shutter open delay is set to {} msecs", d);
logDebug("Shutter open delay bits are set to 0x{:02X}", counts); logDebug("Shutter open delay bits are set to 0x{:02X}", counts);
}); }));
/* TRIGGER MODE */ /* TRIGGER MODE */

View File

@ -23,6 +23,11 @@ class RaptorEagleCCD : public adc::AdcGenericDevice<std::string,
base_t; base_t;
public: public:
/* class constants */
// separator char sequence of serialized representation of user FITS keywords array
static constexpr std::string_view USER_FITS_KEY_SEP_SEQ{"\n"};
/* some Eagle V camera constants */ /* some Eagle V camera constants */
// static constexpr double EAGLE_CAMERA_MAX_EXPTIME = 27487.7906944; // in seconds (0xFFFFFFFFFF * 25nsec) // static constexpr double EAGLE_CAMERA_MAX_EXPTIME = 27487.7906944; // in seconds (0xFFFFFFFFFF * 25nsec)
static constexpr double EAGLE_CAMERA_MAX_EXPTIME = 2.5E-8 * 0xFFFFFFFFFF; // in seconds (0xFFFFFFFFFF * 25nsec) static constexpr double EAGLE_CAMERA_MAX_EXPTIME = 2.5E-8 * 0xFFFFFFFFFF; // in seconds (0xFFFFFFFFFF * 25nsec)
@ -67,10 +72,13 @@ public:
static constexpr std::string_view CAMERA_ATTR_SHUTTER_CLOSEDELAY{"SHUTTER_CLOSE_DELAY"}; static constexpr std::string_view CAMERA_ATTR_SHUTTER_CLOSEDELAY{"SHUTTER_CLOSE_DELAY"};
static constexpr std::string_view CAMERA_ATTR_CCDDIM{"CCDDIM"}; static constexpr std::string_view CAMERA_ATTR_CCDDIM{"CCDDIM"};
static constexpr std::string_view CAMERA_ATTR_CAMLINK_SETUP{"CAMLINK_SETUP"}; static constexpr std::string_view CAMERA_ATTR_CAMLINK_SETUP{"CAMLINK_SETUP"};
static constexpr std::string_view CAMERA_ATTR_PERM_KEYW{"PERM_FITS_KEY"};
static constexpr std::string_view CAMERA_ATTR_CURR_KEYW{"CURR_FITS_KEY"};
static constexpr std::string_view CAMERA_CMD_INITCAM{"INITCAM"}; static constexpr std::string_view CAMERA_CMD_INITCAM{"INITCAM"};
static constexpr std::string_view CAMERA_CMD_START_EXP{"START_EXP"}; static constexpr std::string_view CAMERA_CMD_START_EXP{"START_EXP"};
static constexpr std::string_view CAMERA_CMD_STOP_EXP{"STOP_EXP"}; static constexpr std::string_view CAMERA_CMD_STOP_EXP{"STOP_EXP"};
static constexpr std::string_view CAMERA_CMD_CLEAR_PERM_KEYW{"CLEAR_PERM_FITS_KEYW"};
// some character attributes values // some character attributes values
static constexpr std::string_view CAMERA_ATTR_STR_INVALID{"INVALID"}; static constexpr std::string_view CAMERA_ATTR_STR_INVALID{"INVALID"};
@ -130,8 +138,11 @@ private:
std::recursive_mutex _camlinkMutex; std::recursive_mutex _camlinkMutex;
// attributes inner variables // attributes inner variables
size_t _frameNumbers; std::atomic_size_t _frameNumbers;
std::string _currentFitsFile; // current acquisition FITS filename
std::vector<std::string> _currentTemplateFile; // CFITSIO template filename
std::vector<std::string> _currentFitsKeywords; // current acquisition FITS keywords
std::vector<std::string> _permanentFitsKeywords; // permanent user FITS keywords
// hardware version info // hardware version info