Skip to content

Commit

Permalink
Transportation flush commnad
Browse files Browse the repository at this point in the history
  • Loading branch information
pkubanek committed Oct 29, 2024
1 parent ebf8964 commit 14fd325
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 2 deletions.
2 changes: 2 additions & 0 deletions include/Transports/FPGASerialDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 2 additions & 0 deletions include/Transports/SimulatedTransport.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 5 additions & 0 deletions include/Transports/Transport.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
21 changes: 19 additions & 2 deletions src/Transports/FPGASerialDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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<const uint64_t*>(response + 1)));
Expand Down
2 changes: 2 additions & 0 deletions src/Transports/SimulatedTransport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 14fd325

Please sign in to comment.