Skip to content

Commit

Permalink
ILC's getStatusString & getFaultString methods
Browse files Browse the repository at this point in the history
  • Loading branch information
pkubanek committed Dec 6, 2023
1 parent 98391ec commit c638bbd
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 6 deletions.
27 changes: 27 additions & 0 deletions include/cRIO/ILC.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,35 @@ class ILC : public ModbusBuffer {

uint8_t getLastMode(uint8_t address) { return _lastMode.at(address); }

/**
* Return string with current mode description.
*
* @param mode ILC mode, as returned by function 18.
*
* @return status description (enabled, standby,..).
*/
const char *getModeStr(uint8_t mode);

/**
* Return string with short text describing all code 18 status response.
*
* @param status status returned from function 18 (and other functions).
*
* @return vector of strings with status description
*/
virtual std::vector<const char *> getStatusString(uint8_t status);

enum ILCStatus { MajorFault = 0x0001, MinorFault = 0x0002 };

/**
* Return ILC fault textual description.
*
* @param fault ILC faults returned by function 18.
*
* @return vector of strings with fault description
*/
virtual std::vector<const char *> getFaultString(uint8_t fault);

/**
* Callback for reponse to ServerID request. See LTS-646 Code 17 (0x11) for
* details.
Expand Down
2 changes: 2 additions & 0 deletions include/cRIO/ThermalILC.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ class ThermalILC : public virtual ILC {
*/
ThermalILC(uint8_t bus = 1);

std::vector<const char*> getStatusString(uint8_t status) override;

/**
* Unicast heater PWM and fan RPM. ILC command code 88 (0x58)
*
Expand Down
64 changes: 58 additions & 6 deletions src/LSST/cRIO/ILC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,12 @@
* this program. If not, see <https://www.gnu.org/licenses/>.
*/

#include <spdlog/spdlog.h>
#include <spdlog/fmt/fmt.h>
#include <spdlog/spdlog.h>

#include <cRIO/ILC.h>

namespace LSST {
namespace cRIO {
using namespace LSST::cRIO;

ILC::ILC(uint8_t bus) {
_bus = bus;
Expand Down Expand Up @@ -191,6 +190,62 @@ const char *ILC::getModeStr(uint8_t mode) {
}
}

std::vector<const char *> ILC::getStatusString(uint8_t status) {
std::vector<const char *> ret;

if (status & ILCStatus::MajorFault) {
ret.push_back("Major Fault");
}
if (status & ILCStatus::MinorFault) {
ret.push_back("Minor Fault");
}
// 0x0003 reserved
if (status & 0x0008) {
ret.push_back("Fault Override");
}
// remaining status is ILC specific, implemented in its *ILC subclass

return ret;
}

std::vector<const char *> ILC::getFaultString(uint8_t fault) {
std::vector<const char *> ret;

if (fault & 0x0001) {
ret.push_back("Unique ID CRC error");
}
if (fault & 0x0002) {
ret.push_back("App Type & Network Node Type do not match");
}
if (fault & 0x0004) {
ret.push_back("No ILC App programmed");
}
if (fault & 0x0008) {
ret.push_back("ILC App CRC error");
}
if (fault & 0x0010) {
ret.push_back("No TEDS found");
}
if (fault & 0x0020) {
ret.push_back("TEDS copy 1 error");
}
if (fault & 0x0040) {
ret.push_back("TEDS copy 2 error");
}
// 0x0080 reserved
if (fault & 0x0100) {
ret.push_back("Reset due to Watchdog Timeout");
}
if (fault & 0x0200) {
ret.push_back("Brown Out");
}
if (fault & 0x0400) {
ret.push_back("Event Trap");
}

return ret;
}

bool ILC::responseMatchCached(uint8_t address, uint8_t func) {
try {
std::map<uint8_t, std::vector<uint8_t>> &fc = _cachedResponse.at(address);
Expand All @@ -206,6 +261,3 @@ bool ILC::responseMatchCached(uint8_t address, uint8_t func) {
}
return checkRecording(_cachedResponse[address][func]) && !_alwaysTrigger;
}

} // namespace cRIO
} // namespace LSST
26 changes: 26 additions & 0 deletions src/LSST/cRIO/ThermalILC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,32 @@ ThermalILC::ThermalILC(uint8_t bus) : ILC(bus) {
addResponse(93, reheaterGains, 221);
}

std::vector<const char*> ThermalILC::getStatusString(uint8_t status) {
std::vector<const char*> ret = ILC::getStatusString(status);
// 0x0010 NA
// 0x0020 NA
if (status & 0x0040) {
ret.push_back("Ref Resistor Error");
}
if (status & 0x0080) {
ret.push_back("RTD Error");
}
// 0x0100 NA
// 0x0200 NA
if (status & 0x0400) {
ret.push_back("Heater Breaker Failed");
}
if (status & 0x0800) {
ret.push_back("Fan Breaker Failed");
}
// 0x1000 NA
// 0x2000 NA
// 0x4000 NA
// 0x8000 reserved

return ret;
}

void ThermalILC::broadcastThermalDemand(uint8_t heaterPWM[NUM_TS_ILC], uint8_t fanRPM[NUM_TS_ILC]) {
uint8_t params[NUM_TS_ILC * 2];
for (int i = 0, o = 0; i < NUM_TS_ILC; i++, o++) {
Expand Down

0 comments on commit c638bbd

Please sign in to comment.