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
// '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) {
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<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) {
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<uint8_t>({_clCommandAckBit, _clChecksumBit});
return _permanentFitsKeywords;
},
[this](const std::vector<uint8_t>& setup) {
logDebug("Try to set CameraLink setup bits ...");
[this](const std::vector<std::string>& 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<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 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 */

View File

@ -23,6 +23,11 @@ class RaptorEagleCCD : public adc::AdcGenericDevice<std::string,
base_t;
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 */
// 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)
@ -67,10 +72,13 @@ public:
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_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_START_EXP{"START_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
static constexpr std::string_view CAMERA_ATTR_STR_INVALID{"INVALID"};
@ -130,8 +138,11 @@ private:
std::recursive_mutex _camlinkMutex;
// 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