Skip to content

Commit

Permalink
SensorMonitor for ILCs 4,5 and 6
Browse files Browse the repository at this point in the history
  • Loading branch information
pkubanek committed Jun 28, 2024
1 parent a4abb66 commit db705d6
Show file tree
Hide file tree
Showing 6 changed files with 195 additions and 3 deletions.
5 changes: 5 additions & 0 deletions doc/version-history.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
Version History
###############


v1.11.2
-------
* SensorMonitor ILC

v1.11.1
-------
* broadcast commands to step and freeze
Expand Down
2 changes: 1 addition & 1 deletion include/ILC/ILCBusList.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* ILC Bus List handling communication (receiving and
* ILC Bus List handling communication (commanding ILCs and receiving replies).
*
* Developed for the Vera C. Rubin Observatory Telescope & Site Software Systems.
* This product includes software developed by the Vera C.Rubin Observatory Project
Expand Down
61 changes: 61 additions & 0 deletions include/ILC/SensorMonitor.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* Sensors handling. Adds handling of the function 84 (0x54), readout of the
* sensors values.
*
* Developed for the Vera C. Rubin Observatory Telescope & Site Software Systems.
* This product includes software developed by the Vera C.Rubin Observatory Project
* (https://www.lsst.org). See the COPYRIGHT file at the top-level directory of
* this distribution for details of code ownership.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, either version 3 of the License, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>.
*/

#ifndef __ILC_SensorMonitor__
#define __ILC_SensorMonitor__

#include <ILC/ILCBusList.h>

namespace ILC {

/**
* Class handling sensor monitoring. Intended for ILCs running application
* fimrware of type 4, 5 and 6 - Temperature, Displacement and Inclinometer
* monitors.
*/
class SensorMonitor : public virtual ILCBusList {
public:
SensorMonitor(uint8_t bus);

/**
* Calls function 84 (0x54), requestion measured sensor values.
*
* @param address @glos{ILC} address
*/
void reportSensorValues(uint8_t address) { callFunction(address, SENSOR_VALUES, 400); }

enum SENSOR_MONITOR_CMD { SENSOR_VALUES = 84 };

protected:
/***
* Process response containing sensor values.
*
* @param address @glos{ILC} address
* @param values retrieved values
*/
virtual void processSensorValues(uint8_t address, std::vector<float> values) = 0;
};

} // namespace ILC

#endif //* !__ILC_SensorMonitor__
4 changes: 2 additions & 2 deletions include/Modbus/BusList.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ class CommandRecord {
*/
CommandRecord(Buffer _buffer, uint32_t _timing) : buffer(_buffer), timing(_timing) {}

Buffer buffer; ///< Buffer send to the bus
Buffer buffer; ///< Buffer send to the bus
uint32_t timing; ///< Timing value in microseconds. An error shall be thrown when the response isn't
///< received in the specified time.
///< received in the specified time.
};

/**
Expand Down
49 changes: 49 additions & 0 deletions src/ILC/SensorMonitor.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Sensor Monitor ILC handling.
*
* Developed for the Vera C. Rubin Observatory Telescope & Site Software Systems.
* This product includes software developed by the Vera C.Rubin Observatory Project
* (https://www.lsst.org). See the COPYRIGHT file at the top-level directory of
* this distribution for details of code ownership.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, either version 3 of the License, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>.
*/

#include <vector>

#include <spdlog/spdlog.h>

#include <ILC/SensorMonitor.h>

using namespace ILC;

SensorMonitor::SensorMonitor(uint8_t bus) : ILCBusList(bus) {
addResponse(
SENSOR_VALUES,
[this](Modbus::Parser parser) {
std::vector<float> values;
// there should be 4 bytes floats and 2 bytes CRC
if (parser.size() % 4 != 2) {
throw std::runtime_error(fmt::format(
"Invalid reponse length - expected 4*x + 2, received {}", parser.size()));
}

for (int i = 0; i < static_cast<int>(parser.size()) / 4; i++) {
values.push_back(parser.read<float>());
}

processSensorValues(parser.address(), values);
},
SENSOR_VALUES | 0x80);
}
77 changes: 77 additions & 0 deletions tests/test_SensorMonitor.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* This file is part of LSST cRIOcpp test suite. Tests ILC Sensor Monitor functions.
*
* Developed for the Vera C. Rubin Observatory Telescope & Site Software Systems.
* This product includes software developed by the Vera C.Rubin Observatory Project
* (https://www.lsst.org). See the COPYRIGHT file at the top-level directory of
* this distribution for details of code ownership.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, either version 3 of the License, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>.
*/

#include <catch2/catch_test_macros.hpp>

#include <ILC/SensorMonitor.h>
#include <Modbus/Parser.h>

using namespace ILC;

class TestSensorMonitor : public SensorMonitor {
public:
TestSensorMonitor() : ILC::ILCBusList(1), SensorMonitor(1) {}

std::vector<float> values;

protected:
void processServerID(uint8_t address, uint64_t uniqueID, uint8_t ilcAppType, uint8_t networkNodeType,
uint8_t ilcSelectedOptions, uint8_t networkNodeOptions, uint8_t majorRev,
uint8_t minorRev, std::string firmwareName) override {}

void processServerStatus(uint8_t address, uint8_t mode, uint16_t status, uint16_t faults) override {}

void processChangeILCMode(uint8_t address, uint16_t mode) override {}

void processSetTempILCAddress(uint8_t address, uint8_t newAddress) override {}

void processResetServer(uint8_t address) override {}

void processSensorValues(uint8_t address, std::vector<float> _values) override { values = _values; }
};

TEST_CASE("Process response of the SensorValue", "[SensorValues]") {
TestSensorMonitor ilc;

ilc.reportSensorValues(83);

Modbus::Parser parser(ilc[0].buffer);

CHECK(parser.address() == 83);
CHECK(parser.func() == 84);
CHECK_NOTHROW(parser.checkCRC());

Modbus::Buffer response;

response.write<uint8_t>(83);
response.write<uint8_t>(84);
for (size_t i = 0; i < 4; i++) {
response.write<float>(i + 0.01f * i);
}
response.writeCRC();

CHECK_NOTHROW(ilc.parse(response.data(), response.size()));

for (size_t i = 0; i < 4; i++) {
CHECK(ilc.values[i] == i + 0.01f * i);
}
}

0 comments on commit db705d6

Please sign in to comment.