From 16e58f264fef253ca0e5d3670525b775ec256719 Mon Sep 17 00:00:00 2001 From: "Timur A. Fatkhullin" Date: Fri, 13 Dec 2024 11:34:34 +0300 Subject: [PATCH] RaptorEagleCCD::clWrite: fix! (pxd_serialWrite returns 0 if success!) RaptorEagleCCD::clRead: wait for Rx-buffer data during timeout --- raptor_eagle_ccd.cpp | 42 ++++++++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/raptor_eagle_ccd.cpp b/raptor_eagle_ccd.cpp index 181091d..3c2faf8 100644 --- a/raptor_eagle_ccd.cpp +++ b/raptor_eagle_ccd.cpp @@ -386,12 +386,27 @@ size_t RaptorEagleCCD::clRead(byte_seq_t& bytes) size_t nbytes; - // how many byte are available - xclibApiCall(nbytes = pxd_serialRead(_cameraUnitmap, 0, nullptr, 0), - std::format("pxd_serialRead({}, 0, NULL, 0)", _cameraUnitmap)); + auto start_tp = std::chrono::steady_clock::now(); + + // // how many byte are available + // xclibApiCall(nbytes = pxd_serialRead(_cameraUnitmap, 0, nullptr, 0), + // std::format("pxd_serialRead({}, 0, NULL, 0)", _cameraUnitmap)); + + // if (!nbytes) { + // logWarn("There are no bytes in Rx-buffer! Nothing to do!"); + // return 0; + // } + + do { + // how many byte are available + xclibApiCall(nbytes = pxd_serialRead(_cameraUnitmap, 0, nullptr, 0), + std::format("pxd_serialRead({}, 0, NULL, 0)", _cameraUnitmap)); + logWarn("There are no bytes in Rx-buffer! Waiting for ..."); + std::this_thread::sleep_for(std::chrono::milliseconds(1)); + } while ((std::chrono::steady_clock::now() - start_tp) <= CL_DEFAULT_TIMEOUT); if (!nbytes) { - logWarn("There are no bytes in Rx-buffer! Nothing to do!"); + logWarn("Cameralink reading operation timeout!"); return 0; } @@ -471,7 +486,7 @@ size_t RaptorEagleCCD::clWrite(const byte_seq_t& bytes) logWarn( "Not enough of available space in the internal Tx-buffer (needs = {}, available = {})! Nothing to do!", bytes.size() + tr_nbytes, nbytes); - nbytes = 0; + return 0; } else { if (_clChecksumBit) { etx_checksum_bytes[1] = details::computeChecksum(bytes); @@ -481,32 +496,23 @@ size_t RaptorEagleCCD::clWrite(const byte_seq_t& bytes) nbytes = pxd_serialWrite(_cameraUnitmap, 0, (char*)bytes.data(), bytes.size()), std::format("pxd_serialWrite({}, 0, {}, {})", _cameraUnitmap, (void*)bytes.data(), bytes.size())); - if (nbytes != bytes.size()) { - throw std::system_error(RaptorEagleCCDError::ERROR_CAMLINK_WRITE); - } - // send trailing ETX and possible checksum bytes - size_t n; if (tr_nbytes > 1) { logDebug("Write trailing ETX and checksum bytes"); } else { logDebug("Write trailing ETX byte"); } - xclibApiCall( - n = pxd_serialWrite(_cameraUnitmap, 0, (char*)etx_checksum_bytes, tr_nbytes), - std::format("pxd_serialWrite({}, 0, {}, {})", _cameraUnitmap, (void*)etx_checksum_bytes, tr_nbytes)); - if (n != tr_nbytes) { - throw std::system_error(RaptorEagleCCDError::ERROR_CAMLINK_WRITE); - } - nbytes += n; + xclibApiCall( + pxd_serialWrite(_cameraUnitmap, 0, (char*)etx_checksum_bytes, tr_nbytes), + std::format("pxd_serialWrite({}, 0, {}, {})", _cameraUnitmap, (void*)etx_checksum_bytes, tr_nbytes)); } } else { logWarn("No available space in the internal Tx-buffer! Nothing to do!"); } - return nbytes; + return bytes.size(); }