Skyward boardcore
Loading...
Searching...
No Matches
SensorInfo.h
Go to the documentation of this file.
1/* Copyright (c) 2020 Skyward Experimental Rocketry
2 * Author: Luca Conterio
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 * THE SOFTWARE.
21 */
22
23#pragma once
24
25#include <units/Frequency.h>
26#include <utils/KernelTime.h>
27
28#include <chrono>
29#include <functional>
30
31namespace Boardcore
32{
33
42{
43 std::string id;
44 std::chrono::nanoseconds period;
45 std::function<void()> callback;
48
50 // cppcheck-suppress passedByValue
51 const std::string id = "", uint32_t period = 0,
52 std::function<void()> callback = []() {}, bool isEnabled = true)
53 : SensorInfo(id, std::chrono::milliseconds{period}, std::move(callback),
55 {
56 }
57
59 // cppcheck-suppress passedByValue
60 const std::string id, Units::Frequency::Hertz frequency,
61 std::function<void()> callback = []() {}, bool isEnabled = true)
62 : SensorInfo(id,
63 std::chrono::nanoseconds{
64 static_cast<int64_t>(sToNs(1) / frequency.value())},
65 std::move(callback), isEnabled)
66 {
67 }
68
70 // cppcheck-suppress passedByValue
71 const std::string id, std::chrono::nanoseconds period,
72 std::function<void()> callback = []() {}, bool isEnabled = true)
73 : id(id), period(period), callback(std::move(callback)),
75 {
76 }
77
79 {
80 id = info.id;
81 period = info.period;
82 callback = info.callback;
83 isEnabled = info.isEnabled;
85
86 return *this;
87 }
88
89 bool operator==(const SensorInfo& info) const
90 {
91 return id == info.id && period == info.period &&
92 isEnabled == info.isEnabled &&
94 callback.target_type() == info.callback.target_type() &&
95 callback.target<void()>() == info.callback.target<void()>();
96 };
97};
98
99} // namespace Boardcore
This file includes all the types the logdecoder script will decode.
constexpr long long sToNs(long long s)
Convert seconds to nanoseconds.
Definition TimeUtils.h:64
Definition WIZ5500.h:318
Sensors information struct needed by the SensorManager.
Definition SensorInfo.h:42
std::chrono::nanoseconds period
Definition SensorInfo.h:44
SensorInfo & operator=(const SensorInfo &info)
Definition SensorInfo.h:78
SensorInfo(const std::string id, Units::Frequency::Hertz frequency, std::function< void()> callback=[]() {}, bool isEnabled=true)
Definition SensorInfo.h:58
SensorInfo(const std::string id="", uint32_t period=0, std::function< void()> callback=[]() {}, bool isEnabled=true)
Definition SensorInfo.h:49
bool operator==(const SensorInfo &info) const
Definition SensorInfo.h:89
std::function< void()> callback
Definition SensorInfo.h:45
SensorInfo(const std::string id, std::chrono::nanoseconds period, std::function< void()> callback=[]() {}, bool isEnabled=true)
Definition SensorInfo.h:69