RaptorEagleCCD::clWrite: fix! (pxd_serialWrite returns 0 if success!)

RaptorEagleCCD::clRead: wait for Rx-buffer data during timeout
This commit is contained in:
Timur A. Fatkhullin 2024-12-13 11:34:34 +03:00
parent 1dacab88fe
commit 16e58f264f

View File

@ -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();
}