blob: ee8d16605023a5aaa09c7b4652605b2fea0dbd83 [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>
Patrick Venture1a7c49f2020-10-06 15:49:27 -07007#include <unordered_map>
8#include <utility>
9#include <vector>
Patrick Ventureaadb30d2020-08-10 09:17:11 -070010
11namespace pid_control
12{
13
14struct VariantToDoubleVisitor
15{
16 template <typename T>
Patrick Williams19300272025-02-01 08:22:48 -050017 std::enable_if_t<std::is_arithmetic<T>::value, double> operator()(
18 const T& t) const
Patrick Ventureaadb30d2020-08-10 09:17:11 -070019 {
20 return static_cast<double>(t);
21 }
22
23 template <typename T>
Patrick Williams19300272025-02-01 08:22:48 -050024 std::enable_if_t<!std::is_arithmetic<T>::value, double> operator()(
25 [[maybe_unused]] const T& t) const
Patrick Ventureaadb30d2020-08-10 09:17:11 -070026 {
27 throw std::invalid_argument("Cannot translate type to double");
28 }
29};
30
Chaul Lya552fe22024-11-15 10:20:28 +000031std::string getSensorUnit(const std::string& type);
Patrick Venture84c188f2020-08-10 12:39:12 -070032std::string getSensorPath(const std::string& type, const std::string& id);
Harvey.Wuf2efcbb2022-02-09 10:24:30 +080033std::string getMatch(const std::string& path);
Patrick Venture84c188f2020-08-10 12:39:12 -070034void scaleSensorReading(const double min, const double max, double& value);
35bool validType(const std::string& type);
36
Patrick Venture1a7c49f2020-10-06 15:49:27 -070037bool findSensors(const std::unordered_map<std::string, std::string>& sensors,
38 const std::string& search,
39 std::vector<std::pair<std::string, std::string>>& matches);
40
Patrick Ventureb8cfc642020-10-07 08:30:22 -070041// Set zone number for a zone, 0-based
42int64_t setZoneIndex(const std::string& name,
43 std::map<std::string, int64_t>& zones, int64_t index);
44
45// Read zone number for a zone.
46int64_t getZoneIndex(const std::string& name,
47 std::map<std::string, int64_t>& zones);
48
Patrick Ventureaadb30d2020-08-10 09:17:11 -070049} // namespace pid_control