-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
195 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |