blob: 013207388d6dc56f6f477a365980d4c6d4e46716 [file] [log] [blame]
Patrick Ventureaadb30d2020-08-10 09:17:11 -07001#pragma once
2
Patrick Ventureb8cfc642020-10-07 08:30:22 -07003#include <cstdint>
4#include <map>
Patrick Ventureef1f8862020-08-17 09:34:35 -07005#include <stdexcept>
Patrick Venture84c188f2020-08-10 12:39:12 -07006#include <string>
Ed Tanousf8b6e552025-06-27 13:27:50 -07007#include <type_traits>
Patrick Venture1a7c49f2020-10-06 15:49:27 -07008#include <unordered_map>
9#include <utility>
10#include <vector>
Patrick Ventureaadb30d2020-08-10 09:17:11 -070011
12namespace pid_control
13{
14
15struct VariantToDoubleVisitor
16{
17 template <typename T>
Patrick Williams19300272025-02-01 08:22:48 -050018 std::enable_if_t<std::is_arithmetic<T>::value, double> operator()(
19 const T& t) const
Patrick Ventureaadb30d2020-08-10 09:17:11 -070020 {
21 return static_cast<double>(t);
22 }
23
24 template <typename T>
Patrick Williams19300272025-02-01 08:22:48 -050025 std::enable_if_t<!std::is_arithmetic<T>::value, double> operator()(
26 [[maybe_unused]] const T& t) const
Patrick Ventureaadb30d2020-08-10 09:17:11 -070027 {
28 throw std::invalid_argument("Cannot translate type to double");
29 }
30};
31
Chaul Lya552fe22024-11-15 10:20:28 +000032std::string getSensorUnit(const std::string& type);
Patrick Venture84c188f2020-08-10 12:39:12 -070033std::string getSensorPath(const std::string& type, const std::string& id);
Harvey.Wuf2efcbb2022-02-09 10:24:30 +080034std::string getMatch(const std::string& path);
Patrick Venture84c188f2020-08-10 12:39:12 -070035void scaleSensorReading(const double min, const double max, double& value);
36bool validType(const std::string& type);
37
Patrick Venture1a7c49f2020-10-06 15:49:27 -070038bool findSensors(const std::unordered_map<std::string, std::string>& sensors,
39 const std::string& search,
40 std::vector<std::pair<std::string, std::string>>& matches);
41
Patrick Ventureb8cfc642020-10-07 08:30:22 -070042// Set zone number for a zone, 0-based
43int64_t setZoneIndex(const std::string& name,
44 std::map<std::string, int64_t>& zones, int64_t index);
45
46// Read zone number for a zone.
47int64_t getZoneIndex(const std::string& name,
48 std::map<std::string, int64_t>& zones);
49
Patrick Ventureaadb30d2020-08-10 09:17:11 -070050} // namespace pid_control