Skip to content

Commit

Permalink
Transport::telemetry method
Browse files Browse the repository at this point in the history
  • Loading branch information
pkubanek committed Oct 2, 2024
1 parent 2890dc1 commit 23d8ec0
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
2 changes: 2 additions & 0 deletions include/Transports/FPGASerialDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ class FPGASerialDevice : public Transport {
std::vector<uint8_t> read(size_t len, const std::chrono::duration<long int>& timeout,
LSST::cRIO::Thread* calling_thread = NULL) override;

virtual void telemetry(uint64_t& write_bytes, uint64_t& read_bytes) override;

private:
uint32_t _fpga_session;
int _write_fifo;
Expand Down
8 changes: 8 additions & 0 deletions include/Transports/Transport.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,14 @@ class Transport {
*/
virtual std::vector<uint8_t> read(size_t len, const std::chrono::duration<long int>& timeout,
LSST::cRIO::Thread* calling_thread = NULL) = 0;

/**
* Retrieve transport telemetry.
*
* @param write_bytes number of bytes written to serial device
* @param read_bytes number of bytes read from serial device
*/
virtual void telemetry(uint64_t& write_bytes, uint64_t& read_bytes) = 0;
};

} // namespace Transports
Expand Down
17 changes: 17 additions & 0 deletions src/Transports/FPGASerialDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,20 @@ std::vector<uint8_t> FPGASerialDevice::read(size_t len, const std::chrono::durat

return ret;
}

void FPGASerialDevice::telemetry(uint64_t& write_bytes, uint64_t& read_bytes) {
uint8_t req = 0;
NiThrowError("Reading FIFO requesting telemetry",
NiFpga_WriteFifoU8(_fpga_session, _write_fifo, &req, 1, 0, NULL));

uint8_t response[17];
NiThrowError("Reading FIFO reading telemetry",
NiFpga_WriteFifoU8(_fpga_session, _read_fifo, response, 17, 1, NULL));

if (response[0] != 0) {
throw std::runtime_error("Invalid response - expected 3, received " + std::to_string(response[0]));
}

write_bytes = be64toh(*(reinterpret_cast<const uint64_t*>(response + 1)));
read_bytes = be64toh(*(reinterpret_cast<const uint64_t*>(response + 9)));
}

0 comments on commit 23d8ec0

Please sign in to comment.