RaptorEagleV/raptor_eagle_ccd.h
Timur A. Fatkhullin 41b9c52129 ...
2024-12-03 00:14:32 +03:00

146 lines
5.1 KiB
C++

#pragma once
#include <spdlog/sinks/null_sink.h>
#include <common/adc_spdlog.h>
#include <device/adc_device.h>
#include <device/adc_device_attribute.h>
#include <device/adc_device_command.h>
#include <xcliball.h>
#include "raptor_eagle_exception.h"
class RaptorEagleCCD : public adc::AdcGenericDevice<std::string, adc::AdcDeviceAttribute<>, adc::AdcDeviceCommand<>>,
adc::AdcSpdlogLogger
{
typedef adc::AdcGenericDevice<std::string, adc::AdcDeviceAttribute<>, adc::AdcDeviceCommand<>> base_t;
public:
/* 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)
static constexpr size_t EAGLE_CAMERA_MAX_FRAMERATE = 0xFFFFFFFFFF * 40; // in MHz (0xFFFFFFFFFF * 40MHz)
static constexpr uint16_t EAGLE_CAMERA_CCDDIM[] = {2048, 2048};
static constexpr std::string_view CAMERA_ATTR_HBIN{"HBIN"};
static constexpr std::string_view CAMERA_ATTR_VBIN{"VBIN"};
static constexpr std::string_view CAMERA_ATTR_ROI_LEFT{"ROI_LEFT"};
static constexpr std::string_view CAMERA_ATTR_ROI_TOP{"ROI_TOP"};
static constexpr std::string_view CAMERA_ATTR_ROI_WIDTH{"ROI_WIDTH"};
static constexpr std::string_view CAMERA_ATTR_ROI_HEIGHT{"ROI_HEIGHT"};
static constexpr std::string_view CAMERA_ATTR_GAIN{"GAIN"};
static constexpr std::string_view CAMERA_ATTR_READ_RATE{"READ_RATE"};
static constexpr std::string_view CAMERA_ATTR_CCD_TEMP{"CCD_TEMP"};
static constexpr std::string_view CAMERA_ATTR_PCB_TEMP{"PCB_TEMP"};
static constexpr std::string_view CAMERA_ATTR_EXPTIME{"EXPTIME"};
static constexpr std::string_view CAMERA_ATTR_FRAME_RATE{"FRAME_RATE"};
static constexpr std::string_view CAMERA_ATTR_NEXP{"NEXP"};
static constexpr std::string_view CAMERA_ATTR_SHUTTER_STATE{"SHUTTER_STATE"};
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_CMD_START_EXP{"START_EXP"};
static constexpr std::string_view CAMERA_CMD_STOP_EXP{"STOP_EXP"};
// static constexpr std::string_view CAMERA_CMD_OPEN_SHUTTER{"OPEN_SHUTTER"};
// static constexpr std::string_view CAMERA_CMD_CLOSE_SHUTTER{"CLOSE_SHUTTER"};
// system status byte bits
struct SystemStatus {
bool checkSumEnabled;
bool ackEnabled;
bool bootedFPGA;
bool holdFPGAInReset;
bool commsFPGAEnabled;
};
// FPGA status bits
struct FPGAStatus {
bool highGainEnabled;
bool overTemp;
bool TECEnabled;
};
RaptorEagleCCD(const adc::traits::adc_input_char_range auto& epix_video_fmt_filename,
std::shared_ptr<spdlog::logger> logger = spdlog::null_logger_mt("EAGLE_CCD_NULLLOGGER"));
RaptorEagleCCD(std::shared_ptr<spdlog::logger> logger = spdlog::null_logger_mt("EAGLE_CCD_NULLLOGGER"));
~RaptorEagleCCD();
private:
typedef std::vector<unsigned char> byte_seq_t;
std::string _epixFmtVideoFilename;
int _cameraUnitmap;
// CameraLink read/write setup flags
uint8_t _clCommandAckBit;
uint8_t _clChecksumBit;
std::mutex _camlinkMutex;
// attributes inner variables
size_t _frameNumbers;
void initAttrComm();
void initCamera(int unitmap = 1);
void openPIXCI();
void closePIXCI();
// CameraLink-related low-level methods
size_t clRead(byte_seq_t& bytes);
size_t clReadAndCheckAck(byte_seq_t& bytes);
size_t clReadAndCheckAck();
size_t clWrite(const byte_seq_t& bytes);
// CameraLink-related registers read/write methods
// there are two kind of SET-READ_REGISTER-ADDRESS command in the current version of the camera controller firmware:
// {0x53, 0xE0, 0x01} and
// {0x53, 0xE0, 0x02}
//
// NOTE: given 'set_addr_cmd' byte sequence must be one-byte longer than the command itself!!!
byte_seq_t readRegisters(const byte_seq_t& addrs, byte_seq_t set_addr_cmd = {0x53, 0xE0, 0x01, 0x00});
void writeRegisters(const byte_seq_t& addrs, const byte_seq_t& values);
// logging helper methods
template <bool NOEXCEPT = false>
void xclibApiCall(int err, const adc::traits::adc_input_char_range auto& func_name)
{
if (err < 0) {
if (std::ranges::size(func_name)) {
logError("XCLIB API call ('{}') returns: {} ({})", func_name, err, pxd_mesgErrorCode(err));
} else {
logError("XCLIB API call returns: {} ({})", err, pxd_mesgErrorCode(err));
}
if constexpr (!NOEXCEPT) {
throw std::error_code(err, XCLIBErrorCategory::get());
}
} else {
if (std::ranges::size(func_name)) {
logDebug("XCLIB API call ('{}') finished successfully", func_name);
}
}
}
template <bool NOEXCEPT = false>
void xclibApiCall(int err)
{
xclibApiCall<NOEXCEPT>(err, std::string_view(""));
}
};