-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBasicPOCModule.h
More file actions
201 lines (159 loc) · 5.83 KB
/
BasicPOCModule.h
File metadata and controls
201 lines (159 loc) · 5.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
///-------------------------------------------------------------------------------------------------
/// @file POC\BasicPOCModule.h.
///
/// @brief Declares the basic poc module class
#pragma once
#include "Device.h"
#include "POCController.h"
#include "Component.h"
#include "SPIComponent.h"
#include <shared_mutex>
#include <list>
#include <exception>
#include <memory>
#include <atomic>
using namespace std;
///-------------------------------------------------------------------------------------------------
/// @class BasicPOCModule
///
/// @brief A basic PoC module
///
/// @author Benjamin
/// @date 09.01.2020
class BasicPOCModule :
public Device {
private:
/// @brief List of modules
static list<BasicPOCModule*> moduleList;
/// @brief True if is module is active, false if not
atomic<bool> isActive = false;
///-------------------------------------------------------------------------------------------------
/// @brief The mutex that guards the module de-/activation, only one board may be active at a
/// time
static mutex pocMutex;
/// @brief The currently active module
BasicPOCModule* activeModule = nullptr;
///-------------------------------------------------------------------------------------------------
/// @brief The mutex that guards the module SPI component de-/activation, only one SPI component
/// may be active on a board at a time
mutex spiMutex;
/// @brief The currently active SPI component
SPIComponent* activeSPIComponent = nullptr;
///-------------------------------------------------------------------------------------------------
/// @fn void BasicPOCModule::deactivate();
///
/// @brief Deactivates this module
///
/// @author Benjamin
/// @date 05.09.2020
void deactivate();
protected:
/// @brief The a reference to this module's controller, used by the module for de-/activation
shared_ptr<POCController> pocControllerRef;
/// @brief List of I2C/SPI components located on this board
list<Component*> componentList;
public:
///-------------------------------------------------------------------------------------------------
/// @fn void BasicPOCModule::activate();
///
/// @brief Activates this module.
///
/// @author Benjamin
/// @date 09.01.2020
void activate();
///-------------------------------------------------------------------------------------------------
/// @fn void BasicPOCModule::canBeDeactivated();
///
/// @brief Deactivates this module.
///
/// @author Benjamin
/// @date 09.01.2020
void canBeDeactivated();
///-------------------------------------------------------------------------------------------------
/// @fn BasicPOCModule::BasicPOCModule(string name, shared_ptr<POCController> pocControllerRef = nullptr);
///
/// @brief Constructor
///
/// @author Benjamin
/// @date 09.01.2020
///
/// @param name The name of this module.
/// @param pocControllerRef (Optional) default I2C Slave-Id for the controller of this module.
BasicPOCModule(string name, shared_ptr<POCController> pocControllerRef = nullptr);
///-------------------------------------------------------------------------------------------------
/// @fn static void BasicPOCModule::fixAddressConflicts();
///
/// @brief Fix address conflicts between modules
///
/// @author Benjamin
/// @date 09.01.2020
static void fixAddressConflicts();
///-------------------------------------------------------------------------------------------------
/// @fn void BasicPOCModule::activate(SPIComponent& component);
///
/// @brief Activates the given SPI component. If another SPI component is still active, is waits
/// until the other SPI component calls canBeDeactivated. After that the POCController
/// will by itself deactivated the other SPI component befor activating this SPI Component
///
/// @author Benjamin
/// @date 05.09.2020
///
/// @param [in,out] component The SPI component that will be activated.
void activate(SPIComponent& component);
///-------------------------------------------------------------------------------------------------
/// @fn void BasicPOCModule::canBeDeactivated(SPIComponent& component);
///
/// @brief Declares the component ready for deactivation
///
/// @author Benjamin
/// @date 05.09.2020
///
/// @param [in,out] component The component.
void canBeDeactivated(SPIComponent& component);
///-------------------------------------------------------------------------------------------------
/// @fn static void BasicPOCModule::listAllModules();
///
/// @brief prints the names of all modules
///
/// @author Benjamin
/// @date 09.01.2020
static void listAllModules();
///-------------------------------------------------------------------------------------------------
/// @fn bool BasicPOCModule::getIsActive() const;
///
/// @brief Destructor, removes this POC Module from the ModuleList
///
/// @author Benjamin
/// @date 16.01.2020
///
/// @returns True if it succeeds, false if it fails.
bool getIsActive() const;
///-------------------------------------------------------------------------------------------------
/// @fn virtual const uint16_t BasicPOCModule::getId() const = 0;
///
/// @brief Gets the identifier
///
/// @author Benjamin
/// @date 28.09.2020
///
/// @returns The identifier.
virtual const uint16_t getId() const = 0;
///-------------------------------------------------------------------------------------------------
/// @fn virtual const string BasicPOCModule::getClassName() const = 0;
///
/// @brief Gets class name
///
/// @author Benjamin
/// @date 28.09.2020
///
/// @returns The class name.
virtual const string getClassName() const = 0;
///-------------------------------------------------------------------------------------------------
/// @fn virtual BasicPOCModule::~BasicPOCModule();
///
/// @brief Destructor
///
/// @author Benjamin
/// @date 28.09.2020
virtual ~BasicPOCModule();
};