7#ifndef DCS_ANDOR_LIB_COM_ADPT_HPP_H_
8#define DCS_ANDOR_LIB_COM_ADPT_HPP_H_
31template<
typename T,
typename... Types>
37template<
typename T,
typename U,
typename... Types>
38struct is_any_of<T, U, Types...> : std::conditional_t<std::is_same_v<T, U>, std::true_type, is_any_of<T, Types...>> {};
60constexpr const char*
SIM_TYPE =
"Andor SimCam";
101 return std::visit([](
auto&& arg) -> std::size_t {
102 return std::hash<std::underlying_type_t<std::decay_t<
decltype(arg)>>>()(
static_cast<std::underlying_type_t<std::decay_t<decltype(arg)
>>>(arg));
114 return std::visit([](
auto&& arg) -> std::size_t {
115 return std::hash<std::underlying_type_t<std::decay_t<
decltype(arg)>>>()(
static_cast<std::underlying_type_t<std::decay_t<decltype(arg)
>>>(arg));
135 auto it = enumerated_errors.find(errorCode);
136 if (it != enumerated_errors.end()) {
139 return "Unknown error";
152 std::string_view config_filename =
"",
153 bool compute_latency =
false,
223 virtual short Start()
override;
230 virtual short Stop()
override;
237 virtual short Init();
241 virtual short SetLogLevel(std::string& level, std::string& logger);
248 virtual short Reset()
override;
256 virtual short Setup() ;
268 virtual void Monitor();
273 void StartAcqThread();
278 void StartMonThread();
283 void StopAcqThread();
288 void StopMonThread();
295 short SetupAcquisition();
321 void WaitForInitialisation();
326 void GetCameraInfo();
331 void GetCameraStatus();
336 void StartAcquisition();
343 void WaitForEmptyQueue(
const int timeout_ms)
const;
353 typename std::enable_if<is_any_of<T, bool, int, double, long long>::value,
int>::type
354 SetParam(
const AT_WC* feature, T value);
364 typename std::enable_if<is_any_of<T, bool, int, double, long long>::value,
int>::type
365 GetParam(
const AT_WC* feature, T& value);
368 typename std::enable_if<is_any_of<T, std::string>::value,
int>::type
369 GetParam(
const AT_WC* feature, T& value);
378 typename std::enable_if<is_any_of<T, const AT_WC*, const wchar_t*>::value,
int>::type
379 SetParam(
const AT_WC* feature, T value);
382 typename std::enable_if<is_any_of<T, std::string_view>::value,
int>::type
383 SetParam(
const AT_WC* feature, T value);
396 int GetEnumParam(
const AT_WC* feature, std::string& value);
413 std::unique_ptr<RtmsLlnetioPublisher> m_publisher;
416 std::condition_variable m_acq_condvar;
419 std::condition_variable m_mon_condvar;
425 static std::atomic<bool> m_stopped ;
426 static std::atomic<bool> m_mon_stopped ;
427 bool m_acq_active{
false};
434 std::thread m_acq_thread;
436 std::thread m_mon_thread;
442 log4cplus::Logger m_logger;
445 double m_mudpi_basetimestamp{0.0};
448 std::vector<image_t> images;
449 int m_buffer_segments{1000};
450 int m_number_frames{1000};
451 unsigned char * m_image_buffer{
nullptr};
452 unsigned char *m_image_data{
nullptr};
453 unsigned char** m_acq_buffers;
454 unsigned char** m_aligned_buffers;
456 int m_cam_handle{AT_HANDLE_UNINITIALISED};
457 unsigned int m_frame_counter{0};
458 AT_64 m_width, m_height;
459 AT_64 m_size_in_bytes;
460 AT_64 m_timestamp_clock_freq;
461 int m_buffer_size{0};
463 std::string m_config_filename{};
464 std::unique_ptr<fgf::andor::Config> m_config;
467 static const std::map<int, std::string> enumerated_errors;
476typename std::enable_if<is_any_of<T, bool, int, double, long long>::value,
int>::type
477CommAdapter::SetParam(
const AT_WC* feature, T value) {
478 int i_err = AT_SUCCESS;
480 size_t len = std::wcstombs(
nullptr, feature, 0);
481 std::string command(len,
'\0');
482 std::wcstombs(&command[0], feature, len);
484 const std::string msg =
"Setting " + command +
" to " + std::to_string(value) +
" ...";
485 LOG4CPLUS_INFO(m_logger, msg);
487 if (std::is_same_v<T, AT_64>) {
488 LOG4CPLUS_DEBUG(m_logger,
"long long type");
489 i_err = AT_SetInt(m_cam_handle, feature, value);
490 }
else if (std::is_same_v<T, AT_BOOL>) {
491 LOG4CPLUS_DEBUG(m_logger,
"SDK boolean type");
492 i_err = AT_SetBool(m_cam_handle, feature, value);
493 }
else if (std::is_same_v<T, bool>) {
494 AT_BOOL bool_value = value ? AT_TRUE : AT_FALSE;
495 LOG4CPLUS_DEBUG(m_logger,
"boolean type");
496 i_err = AT_SetBool(m_cam_handle, feature, bool_value);
497 }
else if (std::is_same_v<T, double>) {
498 LOG4CPLUS_DEBUG(m_logger,
"double type");
499 i_err = AT_SetFloat(m_cam_handle, feature, value);
501 if (i_err != AT_SUCCESS) {
502 const std::string msg =
"Failure setting " + command +
", SDK error: " +
504 LOG4CPLUS_ERROR(m_logger, msg);
505 m_andor_status.cmd_error_text = msg;
511typename std::enable_if<is_any_of<T, bool, int, double, long long>::value,
int>::type
512CommAdapter::GetParam(
const AT_WC* feature, T& value) {
513 int i_err = AT_SUCCESS;
515 size_t len = std::wcstombs(
nullptr, feature, 0);
516 std::string command(len,
'\0');
517 std::wcstombs(&command[0], feature, len);
519 const std::string msg =
"Getting " + command +
"...";
520 LOG4CPLUS_INFO(m_logger, msg);
522 if (std::is_same_v<T, AT_64>) {
523 LOG4CPLUS_DEBUG(m_logger,
"long long type");
525 i_err = AT_GetInt(m_cam_handle, feature, &local_value);
526 if (i_err == AT_SUCCESS) {
527 LOG4CPLUS_INFO(m_logger,
"Read " << command <<
"=" << local_value);
528 value =
static_cast<T
>(local_value);
530 }
else if (std::is_same_v<T, bool>) {
531 LOG4CPLUS_DEBUG(m_logger,
"boolean type");
533 i_err = AT_GetBool(m_cam_handle, feature, &local_value);
534 if (i_err == AT_SUCCESS) {
535 LOG4CPLUS_INFO(m_logger,
"Read " << command <<
"=" << local_value);
536 if (local_value == AT_TRUE) {
542 }
else if (std::is_same_v<T, AT_BOOL>) {
543 LOG4CPLUS_DEBUG(m_logger,
"boolean type");
545 i_err = AT_GetBool(m_cam_handle, feature, &local_value);
546 if (i_err == AT_SUCCESS) {
547 LOG4CPLUS_INFO(m_logger,
"Read " << command <<
"=" << local_value);
548 value =
static_cast<T
>(local_value);
550 }
else if (std::is_same_v<T, double>) {
551 LOG4CPLUS_DEBUG(m_logger,
"double type");
553 i_err = AT_GetFloat(m_cam_handle, feature, &local_value);
554 if (i_err == AT_SUCCESS) {
555 LOG4CPLUS_INFO(m_logger,
"Read " << command <<
"=" << local_value);
556 value =
static_cast<T
>(local_value);
559 if (i_err != AT_SUCCESS) {
560 const std::string msg =
"Failure getting " + command +
", SDK error: " +
562 LOG4CPLUS_ERROR(m_logger, msg);
563 m_andor_status.cmd_error_text = msg;
569typename std::enable_if<is_any_of<T, std::string>::value,
int>::type
570CommAdapter::GetParam(
const AT_WC* feature, T& value) {
571 int i_err = AT_SUCCESS;
573 size_t len = std::wcstombs(
nullptr, feature, 0);
574 std::string command(len,
'\0');
575 std::wcstombs(&command[0], feature, len);
577 const std::string msg =
"Getting " + command +
"...";
578 LOG4CPLUS_INFO(m_logger, msg);
581 i_err = AT_GetStringMaxLength(m_cam_handle,feature, &length);
582 if(AT_SUCCESS != i_err) {
583 LOG4CPLUS_ERROR(m_logger,
"Problems getting maximum string length");
587 std::vector<AT_WC> string_value(
static_cast<size_t>(length));
588 string_value.resize(
static_cast<size_t>(length));
589 i_err = AT_GetString(m_cam_handle,feature,string_value.data(),
static_cast<int>(string_value.size()));
590 if(i_err == AT_SUCCESS) {
591 std::string local_value;
592 local_value = std::string(string_value.begin(), string_value.end());
593 value =
static_cast<T
>(local_value);
594 LOG4CPLUS_INFO(m_logger,
"Read " << command <<
"=" << value);
598 if (feature == std::wstring(L
"CameraName")) {
600 wcstombs(szStr, &string_value[0],string_value.size());
601 std::string camera_type{szStr};
605 LOG4CPLUS_INFO(m_logger,
"Andor Marana ");
606 }
else if (camera_type == std::string(
BALOR_TYPE)) {
608 LOG4CPLUS_INFO(m_logger,
"Andor Balor ");
609 }
else if (camera_type == std::string(
SIM_TYPE)) {
611 LOG4CPLUS_INFO(m_logger,
"Andor Sim Camera ");
613 LOG4CPLUS_ERROR(m_logger,
"Wrong camera name ");
616 string_value.clear();
620 if (i_err != AT_SUCCESS) {
621 const std::string msg =
"Failure getting " + command +
", SDK error: " +
623 LOG4CPLUS_ERROR(m_logger, msg);
624 m_andor_status.cmd_error_text = msg;
631typename std::enable_if<is_any_of<T, const AT_WC*, const wchar_t*>::value,
int>::type
632CommAdapter::SetParam(
const AT_WC* feature, T value) {
634 int i_err = AT_SUCCESS;
636 size_t len = std::wcstombs(
nullptr, feature, 0);
637 std::string command(len,
'\0');
638 std::wcstombs(&command[0], feature, len);
640 size_t lenval = std::wcstombs(
nullptr, value, 0);
641 std::string strvalue(lenval,
'\0');
642 std::wcstombs(&strvalue[0], value, lenval);
644 const std::string msg =
"Setting " + command +
" to " + strvalue +
" ...";
645 LOG4CPLUS_INFO(m_logger, msg);
647 i_err = AT_SetEnumString(m_cam_handle, feature, value);
648 if (i_err != AT_SUCCESS) {
649 const std::string msg =
"Failure setting " + command +
", SDK error: " +
651 LOG4CPLUS_ERROR(m_logger, msg);
652 m_andor_status.cmd_error_text = msg;
659typename std::enable_if<is_any_of<T, std::string_view>::value,
int>::type
660CommAdapter::SetParam(
const AT_WC* feature, T value) {
662 int i_err = AT_SUCCESS;
664 size_t len = value.length() + 1;
665 std::vector<wchar_t> wstr_value(len);
666 std::mbstowcs(&wstr_value[0], value.data(), len);
668 len = std::wcstombs(
nullptr, feature, 0);
669 std::string command(len,
'\0');
670 std::wcstombs(&command[0], feature, len);
675 LOG4CPLUS_INFO(m_logger,
"Setting " << command <<
" to " << value <<
" ...");
677 i_err = AT_SetEnumString(m_cam_handle, feature, &wstr_value[0]);
678 if (i_err != AT_SUCCESS) {
679 const std::string msg =
"Failure setting " + command +
", SDK error: " +
681 LOG4CPLUS_ERROR(m_logger, msg);
682 m_andor_status.cmd_error_text = msg;
Frame Grabber Camera Base Class definitions.
std::unique_ptr< AT_U8[]> image_t
Definition commAdapter.hpp:28
CommAdapter(const RtmsNetworkConfig &rtms_cfg, std::string_view config_filename="", bool compute_latency=false, const PublisherThreadConfig &thread_cfg=PublisherThreadConfig())
Constructor for CommAdapter.
Definition commAdaptor.cpp:73
virtual short Stop() override
Stops the acquisition process.
Definition commAdaptor.cpp:739
int m_img_bpp
Bits per pixel of the current image.
Definition commAdapter.hpp:405
virtual void Initialise()
Initializes the communication adapter.
Definition commAdaptor.cpp:112
virtual short Start() override
Starts the acquisition process.
Definition commAdaptor.cpp:664
static std::string getErrorMessage(int errorCode)
Definition commAdapter.hpp:134
int m_img_height
Height of the current image.
Definition commAdapter.hpp:409
virtual ~CommAdapter()
Destructor for CommAdapter.
Definition commAdaptor.cpp:155
virtual void CheckConnection(bool &connected)
Checks if the connection to the camera is established.
Definition commAdaptor.cpp:186
std::shared_ptr< ifw::fgf::common::RawImage > m_rawimage
Pointer to latest received image.
Definition commAdapter.hpp:403
virtual void Read(ifw::fgf::common::VectorVariant ¶ms) const override
Reads multiple parameters from the camera.
Definition commAdaptor.cpp:929
virtual short Reset() override
Resets the camera to its initial state.
Definition commAdaptor.cpp:801
virtual bool IsConnected() const
Checks if the adapter is currently connected to the camera.
Definition commAdaptor.cpp:192
virtual short Setup()
Download parameters to the camera.
Definition commAdaptor.cpp:914
virtual short SetLogLevel(std::string &level, std::string &logger)
Definition commAdaptor.cpp:787
virtual void Connect()
Establishes a connection to the camera.
Definition commAdaptor.cpp:198
virtual void Write(const ifw::fgf::common::VectorVariant ¶ms) override
Writes multiple parameters to the camera.
Definition commAdaptor.cpp:972
virtual std::string GetLoggers()
Definition commAdaptor.cpp:773
virtual void Disconnect()
Disconnects from the camera.
Definition commAdaptor.cpp:224
virtual short Init()
Initializes the camera for acquisition.
Definition commAdaptor.cpp:764
int m_img_width
Width of the current image.
Definition commAdapter.hpp:407
Abstract base class for implementing FGF Communication Adapters.
Definition iCommAdapter.hpp:24
Frame Grabber Camera Base Class definitions.
Abstract base class for implementing FGF Communication Adapters.
Image class for handling images from the camera.
Definition commAdaptor.cpp:34
const uint32_t STREAM_BYTES_PER_SECOND_MAX
Definition commAdapter.hpp:52
const AT_64 ALIGNMENT
Definition commAdapter.hpp:57
const double FRAME_REC_THR_SLEEP_TIME
Definition commAdapter.hpp:47
const short RPC_ERROR
Definition commAdapter.hpp:55
constexpr const char * MARANA_TYPE
Definition commAdapter.hpp:59
const int TIMEOUTMS
Definition commAdapter.hpp:53
constexpr const char * BALOR_TYPE
Definition commAdapter.hpp:58
constexpr const char * SIM_TYPE
Definition commAdapter.hpp:60
RpcError
Definition commAdapter.hpp:70
@ PARAM_SETUP_ERROR
Definition commAdapter.hpp:71
std::variant< ifw::fgf::common::SetupParam::ParamEnum, ifw::fgf::andor::SetupParam::ParamEnum > AndorCtrlEnumKey
RTMS network configuration (defined in rtmsLlnetioPublisher.hpp)
Definition commAdapter.hpp:78
const uint16_t NB_OF_INPUT_BUFFERS
Definition commAdapter.hpp:49
const uint32_t STREAM_BYTES_PER_SECOND_MIN
Definition commAdapter.hpp:51
constexpr const char * CAMERA_INTERFACE
Definition commAdapter.hpp:61
const double CONNECT_TIMEOUT
Definition commAdapter.hpp:46
const int32_t DEFAULT_PACKET_SIZE
Definition commAdapter.hpp:50
const short FEATURE_ERROR
Definition commAdapter.hpp:56
const uint16_t MAX_NB_OF_RECEP_BUFFERS
Definition commAdapter.hpp:48
const short RPC_SUCCESS
Definition commAdapter.hpp:54
std::variant< ifw::fgf::common::StatusParam::StatusEnum, ifw::fgf::andor::StatusParam::StatusEnum, ifw::fgf::common::SetupParam::ParamEnum, ifw::fgf::andor::SetupParam::ParamEnum > AndorStatEnumKey
Definition commAdapter.hpp:107
CameraType
Definition commAdapter.hpp:62
@ UNKNOWN
Definition commAdapter.hpp:63
@ MARANA
Definition commAdapter.hpp:65
@ SIM
Definition commAdapter.hpp:66
@ BALOR
Definition commAdapter.hpp:64
std::variant< bool, int, unsigned int, short, double, std::string > Variant
Definition setupParam.hpp:21
std::vector< PairVariant > VectorVariant
Definition setupParam.hpp:24
std::pair< std::string, Variant > PairVariant
Definition setupParam.hpp:23
RTMS publisher thread for LLNETIO-based adapters.
A custom hash function for AndorStatEnumKey, which supports hashing of variant-like types (e....
Definition commAdapter.hpp:89
std::size_t operator()(const AndorCtrlEnumKey &key) const
Generates a hash value for the given AndorCtrlEnumKey.
Definition commAdapter.hpp:100
Definition commAdapter.hpp:112
std::size_t operator()(const AndorStatEnumKey &key) const
Definition commAdapter.hpp:113
Definition camAndor.hpp:14
Definition camAndor.hpp:28
Thread-level tuning for the publisher.
Definition rtmsLlnetioPublisher.hpp:51
RTMS network configuration (shared with CommAdapter).
Definition rtmsLlnetioPublisher.hpp:34
ParamEnum
Definition setupParam.hpp:37
StatusEnum
Definition statusParam.hpp:44
Structure to hold camera setup parameters.
Definition camBase.hpp:27
Structure to hold camera status parameters.
Definition camBase.hpp:43
ParamEnum
Definition setupParam.hpp:42
StatusEnum
Status ("stat" category) parameters enums.
Definition statusParam.hpp:42
Definition commAdapter.hpp:32