From c44c3d8f6d4c4fef1d6b16be93cfce81ff3b58fd Mon Sep 17 00:00:00 2001 From: Alice Date: Fri, 29 May 2026 14:16:59 +0200 Subject: [PATCH] fix bug in SPI read --- .../matterhornServer/src/SPICommunication.cpp | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/slsDetectorServers/matterhornServer/src/SPICommunication.cpp b/slsDetectorServers/matterhornServer/src/SPICommunication.cpp index 7d18ea4c0..e5e423cfd 100644 --- a/slsDetectorServers/matterhornServer/src/SPICommunication.cpp +++ b/slsDetectorServers/matterhornServer/src/SPICommunication.cpp @@ -1,4 +1,5 @@ #include "SPICommunication.h" +#include #include #include #include @@ -62,6 +63,15 @@ HardwareSPICommunication::spi_read(const size_t n_bytes, const uint8_t chip_id, fmt::format("SPI write failed with {}:{}", errno, strerror(errno))); } + // copy data to output buffer + std::vector output_data(n_bytes); + std::memcpy(output_data.data(), read_data_buffer.data() + 1, n_bytes); + + LOG(logDEBUG1) << "Read data: "; + std::for_each(output_data.begin(), output_data.end(), [](std::byte b) { + LOG(logDEBUG1) << fmt::format("{} ", std::to_integer(b)); + }); + // copy the read out data back to the dummy data buffer to shift it back in send_cmd.tx_buf = send_cmd.rx_buf; @@ -76,11 +86,6 @@ HardwareSPICommunication::spi_read(const size_t n_bytes, const uint8_t chip_id, fmt::format("SPI write failed with {}:{}", errno, strerror(errno))); } - // copy data to output buffer - std::vector output_data(n_bytes); - std::memcpy(output_data.data(), - reinterpret_cast(send_cmd.tx_buf) + 1, n_bytes); - return output_data; } @@ -98,6 +103,11 @@ void HardwareSPICommunication::spi_write(const uint8_t chip_id, std::memcpy(write_data.data() + 1, data.data(), n_bytes); + LOG(logDEBUG1) << "Write data: "; + std::for_each(write_data.begin(), write_data.end(), [](std::byte b) { + LOG(logDEBUG1) << fmt::format("{} ", std::to_integer(b)); + }); + std::vector read_back_buffer(n_bytes + 1); // TODO: do we need this?