Skyward boardcore
Loading...
Searching...
No Matches
SensorManager.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
27
28#include <map>
29
30#include "SensorInfo.h"
31#include "SensorSampler.h"
32
33namespace Boardcore
34{
35
48{
49public:
50 using function_t = std::function<void()>;
51 using SensorMap_t = std::map<AbstractSensor*, SensorInfo>;
52
53 explicit SensorManager(const SensorMap_t& sensorsMap);
54
55 SensorManager(const SensorMap_t& sensorsMap, TaskScheduler* scheduler);
56
61
65 bool start();
66
70 void stop();
71
77 void enableSensor(AbstractSensor* sensor);
78
84 void disableSensor(AbstractSensor* sensor);
85
86 void enableAllSensors();
87
88 void disableAllSensors();
89
94
96
101 const vector<TaskStatsResult> getSamplersStats();
102
103private:
104 SensorManager(const SensorManager&) = delete;
105 SensorManager& operator=(const SensorManager&) = delete;
106
118 bool init(const SensorMap_t& sensorsMap);
119
125 bool initSensor(AbstractSensor* sensor);
126
130 void initScheduler();
131
138 uint8_t getFirstTaskID();
139
148 SensorSampler* createSampler(uint8_t id, std::chrono::nanoseconds period);
149
150 const uint8_t MAX_TASK_ID = 255;
151
153 scheduler;
154 bool customScheduler;
155
156 std::vector<SensorSampler*>
157 samplers;
158
159 std::map<AbstractSensor*, SensorSampler*>
160 samplersMap;
161
162 bool initResult = true;
163
164 PrintLogger logger = Logging::getLogger("sensormanager");
165};
166
167} // namespace Boardcore
Base abstract class for sensor drivers.
Definition Sensor.h:52
static PrintLogger getLogger(const string &name)
The SensorManager handles sensors initialization and sampling.
std::map< AbstractSensor *, SensorInfo > SensorMap_t
bool start()
Starts the task scheduler.
void enableSensor(AbstractSensor *sensor)
Enable sampling for the specified sensor.
void stop()
Starts the task scheduler.
bool areAllSensorsInitialized()
Checks whether all the sensors have been initialized correctly.
std::function< void()> function_t
SensorManager(const SensorMap_t &sensorsMap)
~SensorManager()
Deallocates samplers (through the samplers vector).
void disableSensor(AbstractSensor *sensor)
Disable sampling for the specified sensor.
const SensorInfo getSensorInfo(AbstractSensor *sensor)
const vector< TaskStatsResult > getSamplersStats()
Virtual sensor sampler class.
The Task Scheduler allow to manage simple tasks with a single thread. All the task added must not tak...
This file includes all the types the logdecoder script will decode.
Sensors information struct needed by the SensorManager.
Definition SensorInfo.h:42