From 14fd3251e854a28fec529536c51704fbc273c541 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Kub=C3=A1nek?= Date: Tue, 29 Oct 2024 12:18:57 -0300 Subject: [PATCH] Transportation flush commnad --- include/Transports/FPGASerialDevice.h | 2 ++ include/Transports/SimulatedTransport.h | 2 ++ include/Transports/Transport.h | 5 +++++ src/Transports/FPGASerialDevice.cpp | 21 +++++++++++++++++++-- src/Transports/SimulatedTransport.cpp | 2 ++ 5 files changed, 30 insertions(+), 2 deletions(-) diff --git a/include/Transports/FPGASerialDevice.h b/include/Transports/FPGASerialDevice.h index 5bd6080..e44d894 100644 --- a/include/Transports/FPGASerialDevice.h +++ b/include/Transports/FPGASerialDevice.h @@ -53,6 +53,8 @@ class FPGASerialDevice : public Transport { void commands(Modbus::BusList& bus_list, std::chrono::microseconds timeout, LSST::cRIO::Thread* calling_thread = NULL) override; + void flush() override; + void telemetry(uint64_t& write_bytes, uint64_t& read_bytes) override; private: diff --git a/include/Transports/SimulatedTransport.h b/include/Transports/SimulatedTransport.h index 3ee95dc..adeb5a2 100644 --- a/include/Transports/SimulatedTransport.h +++ b/include/Transports/SimulatedTransport.h @@ -55,6 +55,8 @@ class SimulatedTransport : public Transport { void commands(Modbus::BusList& bus_list, std::chrono::microseconds timeout, LSST::cRIO::Thread* calling_thread = NULL) override; + void flush() override; + void telemetry(uint64_t& write_bytes, uint64_t& read_bytes) override; protected: diff --git a/include/Transports/Transport.h b/include/Transports/Transport.h index d9ee291..dc85ffb 100644 --- a/include/Transports/Transport.h +++ b/include/Transports/Transport.h @@ -88,6 +88,11 @@ class Transport { virtual void commands(Modbus::BusList& bus_list, std::chrono::microseconds timeout, LSST::cRIO::Thread* calling_thread = NULL) = 0; + /** + * Flush transport buffers. + */ + virtual void flush() = 0; + /** * Retrieve transport telemetry. * diff --git a/src/Transports/FPGASerialDevice.cpp b/src/Transports/FPGASerialDevice.cpp index ec442ac..03153dd 100644 --- a/src/Transports/FPGASerialDevice.cpp +++ b/src/Transports/FPGASerialDevice.cpp @@ -113,6 +113,22 @@ void FPGASerialDevice::commands(Modbus::BusList& bus_list, std::chrono::microsec bus_list.clear(); } +void FPGASerialDevice::flush() { + uint8_t req = 3; + NiThrowError("Reading FIFO requesting port flush", + NiFpga_WriteFifoU8(_fpga_session, _write_fifo, &req, 1, 0, NULL)); + + uint8_t response; + NiThrowError("Reading FIFO flush response ", + NiFpga_ReadFifoU8(_fpga_session, _read_fifo, &response, 1, 1, NULL)); + + if (response != req) { + throw std::runtime_error( + fmt::format("Invalid response from FIFO #{} on flush request - expected 3, recieved {}", + _read_fifo, response)); + } +} + void FPGASerialDevice::telemetry(uint64_t& write_bytes, uint64_t& read_bytes) { uint8_t req = 0; NiThrowError("Reading FIFO requesting telemetry", @@ -123,8 +139,9 @@ void FPGASerialDevice::telemetry(uint64_t& write_bytes, uint64_t& read_bytes) { NiFpga_ReadFifoU8(_fpga_session, _read_fifo, response, 17, 1, NULL)); if (response[0] != 0) { - throw std::runtime_error(fmt::format("Invalid response from FIFO #{} - expected 3, received ", - _read_fifo, response[0])); + throw std::runtime_error( + fmt::format("Invalid response from FIFO #{} on telemetry request - expected 0, received {}", + _read_fifo, response[0])); } write_bytes = be64toh(*(reinterpret_cast(response + 1))); diff --git a/src/Transports/SimulatedTransport.cpp b/src/Transports/SimulatedTransport.cpp index a6a5c70..4830f5d 100644 --- a/src/Transports/SimulatedTransport.cpp +++ b/src/Transports/SimulatedTransport.cpp @@ -60,6 +60,8 @@ void SimulatedTransport::commands(Modbus::BusList& bus_list, std::chrono::micros bus_list.clear(); } +void SimulatedTransport::flush() {} + void SimulatedTransport::telemetry(uint64_t& write_bytes, uint64_t& read_bytes) { write_bytes = _bytes_written; read_bytes = _bytes_read;