diff --git a/include/Modbus/BusList.h b/include/Modbus/BusList.h index 362bd03f..17f94a03 100644 --- a/include/Modbus/BusList.h +++ b/include/Modbus/BusList.h @@ -40,7 +40,7 @@ namespace Modbus { * Error thrown when a response is missing. This is mostly caused by an @glos{ILC} on * the bus being dead/not reacting to the command send. */ -class MissingResponse : std::runtime_error { +class MissingResponse : public std::runtime_error { public: /** * Construct missing response exception. @@ -49,7 +49,7 @@ class MissingResponse : std::runtime_error { * @param func Expected function which wasn't responded by the @glos{ILC} */ MissingResponse(uint8_t address, uint8_t func) - : std::runtime_error(fmt::format("Missing response for function {} from ILC with address {}", + : std::runtime_error(fmt::format("Missing response for function {0} (0x{0:02x}) from ILC with address {1}", func, address)) {} }; @@ -59,7 +59,7 @@ class MissingResponse : std::runtime_error { * * @see BusList::addResponse */ -class UnexpectedResponse : std::runtime_error { +class UnexpectedResponse : public std::runtime_error { public: /** * Construct unexpected response. diff --git a/include/Modbus/Parser.h b/include/Modbus/Parser.h index 13300f92..c21ff963 100644 --- a/include/Modbus/Parser.h +++ b/include/Modbus/Parser.h @@ -31,6 +31,8 @@ #include #include +#include + #include namespace Modbus { @@ -78,7 +80,7 @@ class CRCError : public std::runtime_error { /** * Thrown when response continue after CRC. */ -class LongResponse : std::runtime_error { +class LongResponse : public std::runtime_error { public: /** * Construct LongResponse from the given buffer. @@ -124,7 +126,7 @@ class Parser : public std::vector { */ void readBuffer(void *buf, size_t len) { if (_data + len > size()) { - throw std::out_of_range("Trying to access data beyond buffer are."); + throw std::out_of_range(fmt::format("Attempt to access data beyond buffer end (buffer index {}, but buffer length is {}).", _data + len, size())); } memcpy(buf, data() + _data, len); _data += len; diff --git a/src/ILC/ILCBusList.cpp b/src/ILC/ILCBusList.cpp index b9984af7..822c7cbe 100644 --- a/src/ILC/ILCBusList.cpp +++ b/src/ILC/ILCBusList.cpp @@ -189,7 +189,7 @@ std::vector ILCBusList::getFaultString(uint16_t fault) { void ILCBusList::changeILCMode(uint8_t address, uint16_t mode) { uint32_t timeout = 335; try { - if ((getLastMode(address) == Mode::Standby && mode == Mode::Bootloader) || + if ((mode == Mode::Bootloader) || (getLastMode(address) == Mode::Bootloader && mode == Mode::Standby)) { timeout = 100000; } diff --git a/src/LSST/cRIO/FPGA.cpp b/src/LSST/cRIO/FPGA.cpp index 63f993b1..31417710 100644 --- a/src/LSST/cRIO/FPGA.cpp +++ b/src/LSST/cRIO/FPGA.cpp @@ -91,12 +91,13 @@ void FPGA::ilcCommands(ILC::ILCBusList &ilc, int32_t timeout) { uint16_t responseLen; readU16ResponseFIFO(&responseLen, 1, 20); - if (responseLen < 4) { + // minimal response is timestamp + 4 ILC bytes + if (responseLen < 8) { if (responseLen > 0) { uint16_t buffer[responseLen]; readU16ResponseFIFO(buffer, responseLen, 10); } - throw std::runtime_error("FPGA::ilcCommands timeout on response: " + std::to_string(responseLen)); + throw Modbus::MissingResponse(ilc[0].buffer.address(), ilc[0].buffer.func()); } uint16_t buffer[responseLen];