PIDUINO
Loading...
Searching...
No Matches
database.h
1/* Copyright © 2018-2025 Pascal JEAN, All rights reserved.
2 This file is part of the Piduino Library.
3
4 The Piduino Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 3 of the License, or (at your option) any later version.
8
9 The Piduino Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public License
15 along with the Piduino Library; if not, see <http://www.gnu.org/licenses/>.
16*/
17#pragma once
18
19#include <string>
20#include <memory>
21#include <iostream>
22#include <cppdb/frontend.h>
23#include <piduino/soc.h>
24#include <piduino/system.h>
25
34namespace Piduino {
35
36 class Database : public cppdb::session {
37
38 public:
39 class Board {
40 public:
41
42 // -------------------------------------------------------------------
43 //
44 // Database::Board::Family Class
45 //
46 // -------------------------------------------------------------------
47 class Family {
48 public:
49
50 enum Id {
55 // Add New item here and update board_family table in database !
56
57 //---
58 Unknown = -1
59 };
60
62 setId (i);
63 }
64 virtual ~Family() {}
65
66 inline Id id() const {
67 return _id;
68 }
69
70 inline const std::string &name() const {
71 return _name;
72 }
73
74 inline const std::string &i2cSysPath() const {
75 return _i2c_syspath;
76 }
77
78 inline const std::string &spiSysPath() const {
79 return _spi_syspath;
80 }
81
82 inline const std::string &uartSysPath() const {
83 return _uart_syspath;
84 }
85
86 void setId (Id i);
87
88 private:
90 std::string _name;
91 std::string _i2c_syspath;
92 std::string _spi_syspath;
93 std::string _uart_syspath;
94 };
95
96 // -------------------------------------------------------------------
97 //
98 // Database::Board::Model Class
99 //
100 // -------------------------------------------------------------------
101 class Model {
102 public:
103
104 enum Id { // board_family.id : /!\ enum value must be the same as in database
105 RaspberryPiA = 0, // 0
117 NanoPiM1, // 12
133 // Not yet supported
138
139 // Add New item here and update board_model table in database !
140
141 //---
142 Unknown = -1
143 };
144
146 setId (i);
147 }
148 virtual ~Model() {}
149
150 inline Id id() const {
151 return _id;
152 }
153
154 inline const std::string &name() const {
155 return _name;
156 }
157
158 inline const Family &family() const {
159 return _family;
160 }
161
162 inline const SoC &soc() const {
163 return _soc;
164 }
165
166 void setId (Id i);
167
168 private:
170 std::string _name;
173 };
174
175
176 // -------------------------------------------------------------------
177 //
178 // Database::Board Class
179 //
180 // -------------------------------------------------------------------
181
182 Board (bool isSelectFromSystem = false);
183 Board (int rpiBoardRevision);
184 Board (const std::string &armbianBoardTag);
185 virtual ~Board();
186
187 inline long long id() const {
188 return _id;
189 }
190
191 inline const std::string &name() const {
192 return _name;
193 }
194
195 inline const std::string &tag() const {
196 return _tag;
197 }
198
199 inline int revision() const {
200 return _revision;
201 }
202
203 inline const Family &family() const {
204 return model().family();
205 }
206
207 inline const SoC &soc() const {
208 return model().soc();
209 }
210
211 inline std::string pcbRevision() const {
212 return _pcb_revision;
213 }
214
215 inline long long gpioId() const {
216 return _gpio_id;
217 }
218
219 inline const Model &model() const {
220 return _model;
221 }
222
223 inline const Manufacturer &manufacturer() const {
224 return _manufacturer;
225 }
226
227 inline unsigned long totalRam() const {
228 return _ram;
229 }
230
231 inline bool found() const {
232 return _found;
233 }
234
238 inline int defaultI2cBus() const {
239 return _default_i2c_id;
240 }
241
245 inline int defaultSpiBus() const {
246 return _default_spi_id;
247 }
248
252 inline int defaultUart() const {
253 return _default_uart_id;
254 }
255
259 friend std::ostream &operator<< (std::ostream &os, const Board &c);
260
264 static bool boardList (std::map<long long, Board> &boardList);
265
266 private:
268 bool selectWhereRevision (int rev);
269 bool selectWhereTag (const std::string &armbianBoardTag);
271
272 private:
273 long long _id;
276 long long _gpio_id; // Révision du GPIO
277 std::string _pcb_revision;
279 bool _found;
280 std::string _tag;
281 long _ram; // RAM en Mo
285 std::string _name;
286 };
287
288 // -----------------------------------------------------------------------
289 //
290 // Database Class
291 //
292 // -----------------------------------------------------------------------
293 Database (const std::string &connectionInfo = std::string());
294 Database (int cpuinfoBoardRevision, const std::string &connectionInfo = std::string());
295 Database (const std::string &armbianBoardTag, const std::string &connectionInfo = std::string());
296 virtual ~Database();
297
298 static std::string findConnectionInfo (const std::string &connectionInfo = std::string());
299
300 void setConnectionInfo (const std::string &connectionInfo);
301
302 inline const std::string &connectionInfo() const {
303 return _cinfo;
304 }
305
306 inline const Board &board() const {
307 return *_board;
308 }
309
310 private:
311 std::shared_ptr<Board> _board;
312 std::string _cinfo;
313 };
314
315 // ---------------------------------------------------------------------------
316 //
317 // Piduino Database Global Object
318 //
319 // ---------------------------------------------------------------------------
320 extern Database db;
324}
329/* ========================================================================== */
const std::string & spiSysPath() const
Definition database.h:78
const std::string & name() const
Definition database.h:70
const std::string & i2cSysPath() const
Definition database.h:74
const std::string & uartSysPath() const
Definition database.h:82
const std::string & name() const
Definition database.h:154
const SoC & soc() const
Definition database.h:162
const Family & family() const
Definition database.h:158
int defaultUart() const
Numéro de l'UART par défaut.
Definition database.h:252
Board(int rpiBoardRevision)
const SoC & soc() const
Definition database.h:207
int defaultSpiBus() const
Numéro du bus SPI par défaut.
Definition database.h:245
const std::string & tag() const
Definition database.h:195
Manufacturer _manufacturer
Definition database.h:275
std::string pcbRevision() const
Definition database.h:211
bool selectWhereTag(const std::string &armbianBoardTag)
const std::string & name() const
Definition database.h:191
const Model & model() const
Definition database.h:219
Board(const std::string &armbianBoardTag)
int defaultI2cBus() const
Numéro du bus I2C par défaut.
Definition database.h:238
long long gpioId() const
Definition database.h:215
long long id() const
Definition database.h:187
bool selectWhereRevision(int rev)
bool selectWhereModel(Model::Id modelId)
static bool boardList(std::map< long long, Board > &boardList)
return the list of all boards in the database
const Family & family() const
Definition database.h:203
const Manufacturer & manufacturer() const
Definition database.h:223
std::string _pcb_revision
Definition database.h:277
unsigned long totalRam() const
Definition database.h:227
Board(bool isSelectFromSystem=false)
friend std::ostream & operator<<(std::ostream &os, const Board &c)
stream operator for printing the board information
virtual ~Database()
Database(const std::string &connectionInfo=std::string())
static std::string findConnectionInfo(const std::string &connectionInfo=std::string())
const std::string & connectionInfo() const
Definition database.h:302
Database(const std::string &armbianBoardTag, const std::string &connectionInfo=std::string())
const Board & board() const
Definition database.h:306
Database(int cpuinfoBoardRevision, const std::string &connectionInfo=std::string())
std::string _cinfo
Definition database.h:312
void setConnectionInfo(const std::string &connectionInfo)
std::shared_ptr< Board > _board
Definition database.h:311
Global namespace for Piduino.
Definition board.h:28
Database db
Piduino Database Global Object.