Skip to content

Commit 4d59d9f

Browse files
committed
ran through formatter; added ID prefix concept - set value for first 4 chars of the ID string
1 parent 2df9b04 commit 4d59d9f

File tree

2 files changed

+78
-71
lines changed

2 files changed

+78
-71
lines changed

src/Flux/flxFlux.h

Lines changed: 42 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,16 @@
66
* trade secret of SparkFun Electronics Inc. It is not to be disclosed
77
* to anyone outside of this organization. Reproduction by any means
88
* whatsoever is prohibited without express written permission.
9-
*
9+
*
1010
*---------------------------------------------------------------------------------
1111
*/
12-
1312

1413
#pragma once
1514

1615
#include "flxCore.h"
1716
#include "flxCoreDevice.h"
1817
#include <memory>
1918

20-
21-
22-
2319
class flxApplication;
2420

2521
// // happy functions for happy users.
@@ -68,7 +64,6 @@ class flxFlux : public flxObjectContainer
6864
flxDeviceContainer Devices;
6965
flxActionContainer Actions;
7066

71-
7267
//---------------------------------------------------------------------------------
7368
bool save(flxStorage *pStorage);
7469

@@ -165,15 +160,15 @@ class flxFlux : public flxObjectContainer
165160
return Devices;
166161
}
167162

168-
flxBusSPI & spiDriver()
163+
flxBusSPI &spiDriver()
169164
{
170165
// has the driver been initialized?
171166
if (!_spiDriver.initialized())
172167
_spiDriver.begin(true);
173168

174169
return _spiDriver;
175170
}
176-
flxBusI2C & i2cDriver()
171+
flxBusI2C &i2cDriver()
177172
{
178173
// has the driver been initialized?
179174
if (!_i2cDriver.initialized())
@@ -183,27 +178,28 @@ class flxFlux : public flxObjectContainer
183178
}
184179

185180
// Version Things
186-
void setVersion(uint32_t major, uint32_t minor, uint32_t point, const char * desc, uint32_t build )
181+
void setVersion(uint32_t major, uint32_t minor, uint32_t point, const char *desc, uint32_t build)
187182
{
188183
_v_major = major;
189184
_v_minor = minor;
190185
_v_point = point;
191186
_v_build = build;
192187
_v_desc = desc;
193188
}
194-
195-
void versionString(char *buffer, size_t nbuffer, bool bFull=false)
189+
190+
void versionString(char *buffer, size_t nbuffer, bool bFull = false)
196191
{
197192
if (bFull)
198-
snprintf(buffer, nbuffer, "%02u.%02u.%02u %s - build %06x",
199-
_v_major, _v_minor, _v_point, _v_desc.c_str(), _v_build);
193+
snprintf(buffer, nbuffer, "%02u.%02u.%02u %s - build %06x", _v_major, _v_minor, _v_point, _v_desc.c_str(),
194+
_v_build);
200195
else
201-
snprintf(buffer, nbuffer, "%02u.%02u.%02u", _v_major, _v_minor, _v_point);
196+
snprintf(buffer, nbuffer, "%02u.%02u.%02u", _v_major, _v_minor, _v_point);
202197
}
203198

204199
uint32_t version()
205200
{
206-
return _v_major * 10000 + _v_minor * 100 + _v_point;;
201+
return _v_major * 10000 + _v_minor * 100 + _v_point;
202+
;
207203
}
208204
void version(uint32_t &major, uint32_t &minor, uint32_t &point)
209205
{
@@ -217,11 +213,12 @@ class flxFlux : public flxObjectContainer
217213
return _v_build;
218214
}
219215

220-
void setAppClassID(const char * ID)
216+
void setAppClassID(const char *ID, char prefix[5])
221217
{
222218
_appClassID = ID;
219+
memcpy(_v_idprefix, prefix, 5);
223220
}
224-
const char * appClassID(void)
221+
const char *appClassID(void)
225222
{
226223
return _appClassID;
227224
}
@@ -236,24 +233,7 @@ class flxFlux : public flxObjectContainer
236233
flxLog_N(F("Version: %s\n\r"), szBuffer);
237234
}
238235

239-
const char* deviceId(void)
240-
{
241-
// ID is 16 in length, use a C string
242-
static char szDeviceID[17]={0};
243-
static bool bInitialized=false;
244-
#ifdef ESP32
245-
246-
if (!bInitialized)
247-
{
248-
memset(szDeviceID, '\0', sizeof(szDeviceID));
249-
snprintf(szDeviceID, sizeof(szDeviceID), "%016llX", ESP.getEfuseMac());
250-
251-
bInitialized=true;
252-
}
253-
254-
#endif
255-
return (const char*)szDeviceID;
256-
}
236+
const char *deviceId(void);
257237

258238
void setApplication(flxApplication &theApp)
259239
{
@@ -266,11 +246,11 @@ class flxFlux : public flxObjectContainer
266246
{
267247
_theApplication = theApp;
268248
// set the app as the first entry of our actions list
269-
Actions.insert(Actions.begin(), (flxAction*)theApp);
249+
Actions.insert(Actions.begin(), (flxAction *)theApp);
270250
}
271251
}
272252

273-
flxApplication * application(void)
253+
flxApplication *application(void)
274254
{
275255
return _theApplication;
276256
}
@@ -280,42 +260,41 @@ class flxFlux : public flxObjectContainer
280260
bool getAppToken(uint8_t token[32]);
281261

282262
private:
283-
284-
flxBusI2C _i2cDriver;
285-
flxBusSPI _spiDriver;
263+
flxBusI2C _i2cDriver;
264+
flxBusSPI _spiDriver;
286265

287266
uint32_t _v_major;
288267
uint32_t _v_minor;
289268
uint32_t _v_point;
290269
uint32_t _v_build;
291270
std::string _v_desc;
271+
char _v_idprefix[5];
292272

293273
const char *_appClassID;
294274

295-
flxApplication * _theApplication;
275+
flxApplication *_theApplication;
296276

297277
uint8_t _token[32];
298278
bool _hasToken;
299279

300280
// Note private constructor...
301-
flxFlux() : _v_major{0}, _v_minor{0}, _v_point{0}, _v_build{0}, _v_desc{""},
302-
_appClassID{nullptr}, _theApplication{nullptr}, _token{0}, _hasToken{false}
281+
flxFlux()
282+
: _v_major{0}, _v_minor{0}, _v_point{0}, _v_build{0}, _v_desc{""}, _v_idprefix{"0000"}, _appClassID{nullptr},
283+
_theApplication{nullptr}, _token{0}, _hasToken{false}
303284
{
304285

305286
// setup some default heirarchy things ...
306287
this->setName("Flux", "The SparkFun Flux Framework");
307288
Actions.setName("Settings", "System settings and operations");
308289
Devices.setName("Devices Settings", "Settings for connected devices");
309290

310-
311291
// Our container has two children, the device and the actions container
312292
// Cast the devices and actions to objects to add. And had to use
313293
// a temp var to get the references to take.
314-
flxObject * pTmp = &Actions;
294+
flxObject *pTmp = &Actions;
315295
this->push_back(pTmp);
316296
pTmp = &Devices;
317297
this->push_back(pTmp);
318-
319298
}
320299

321300
flxOperation *_getByType(flxTypeID type)
@@ -344,24 +323,24 @@ extern flxFlux &flux;
344323
class flxApplication : public flxActionType<flxApplication>
345324
{
346325

347-
public:
326+
public:
348327
flxApplication()
349328
{
350329
flux.setApplication(this);
351330

352331
// Set a name/descriptor that shows up in the menu system.
353-
((flxObject*)this)->setName("Application Settings", "Main Application Settings");
332+
((flxObject *)this)->setName("Application Settings", "Main Application Settings");
354333
}
355-
334+
356335
// Name things - the overall base object of the system has a descriptor - we want this
357336
// method signature to name the app, but also allow this app object (which is an action)
358337
// to be used in the menuing system ... so
359338
// - override the flxDescriptor methods on the app object
360339
// -- use a descriptor instance variable to store the data
361340
// - Methods called on the application will get these name/desc values
362341
// - Methods called on sub-class objects get the base object name/desc
363-
// So we can use the same methods is both cases, but leverage the fact that
364-
// the base descriptor class methods are not virtual.
342+
// So we can use the same methods is both cases, but leverage the fact that
343+
// the base descriptor class methods are not virtual.
365344

366345
void setName(const char *name)
367346
{
@@ -375,7 +354,7 @@ class flxApplication : public flxActionType<flxApplication>
375354
{
376355
this->setName(name);
377356
this->setDescription(desc);
378-
}
357+
}
379358
const char *name(void)
380359
{
381360
return appDesc.name();
@@ -405,16 +384,22 @@ class flxApplication : public flxActionType<flxApplication>
405384
return;
406385
}
407386

408-
void setVersion(uint major, uint minor, uint point, const char * desc, uint32_t build )
387+
// called just prior to system restore on startup
388+
virtual void onRestore(void)
389+
{
390+
return;
391+
}
392+
393+
void setVersion(uint major, uint minor, uint point, const char *desc, uint32_t build)
409394
{
410395
flux.setVersion(major, minor, point, desc, build);
411396
}
412397

413-
void setAppClassID(const char * ID)
398+
void setAppClassID(const char *ID, char prefix[5])
414399
{
415-
flux.setAppClassID(ID);
400+
flux.setAppClassID(ID, prefix);
416401
}
417-
private:
418-
flxDescriptor appDesc;
419402

403+
private:
404+
flxDescriptor appDesc;
420405
};

src/Flux/spSpark.cpp

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,17 @@
66
* trade secret of SparkFun Electronics Inc. It is not to be disclosed
77
* to anyone outside of this organization. Reproduction by any means
88
* whatsoever is prohibited without express written permission.
9-
*
9+
*
1010
*---------------------------------------------------------------------------------
1111
*/
12-
1312

1413
#include <Arduino.h>
1514

15+
#include "flxFlux.h"
1616
#include "flxSerial.h"
1717
#include "flxSettings.h"
18-
#include "flxFlux.h"
1918
#include "flxStorage.h"
2019

21-
2220
#include "mbedtls/base64.h"
2321

2422
// for logging - define output driver on the stack
@@ -40,8 +38,6 @@ bool flxFlux::start(bool bAutoLoad)
4038
flxLog.setLogDriver(_logDriver);
4139
flxLog.setLogLevel(flxLogInfo); // TODO - adjust?
4240

43-
44-
4541
// Loop in the application
4642
if (_theApplication)
4743
{
@@ -55,12 +51,12 @@ bool flxFlux::start(bool bAutoLoad)
5551
this->setName(_theApplication->name());
5652

5753
if (strlen(_theApplication->description()) > 0)
58-
this->setDescription(_theApplication->description());
54+
this->setDescription(_theApplication->description());
5955
}
6056

6157
writeBanner();
6258

63-
// Build drivers for the registered devices connected to the system
59+
// Build drivers for the registered devices connected to the system
6460
if (bAutoLoad)
6561
flxDeviceFactory::get().buildDevices(i2cDriver());
6662

@@ -70,6 +66,10 @@ bool flxFlux::start(bool bAutoLoad)
7066
// Everything should be loaded -- restore settings from storage
7167
if (flxSettings.isAvailable())
7268
{
69+
// Let the device know we're starting up
70+
if (_theApplication)
71+
_theApplication->onRestore();
72+
7373
flxLog_I_(F("Restoring System Settings ..."));
7474
if (!flxSettings.restoreSystem())
7575
flxLog_W(F("Error encountered restoring system settings..."));
@@ -175,8 +175,9 @@ bool flxFlux::save(flxStorage *pStorage)
175175
status = stBlk->write(kApplicationHashIDTag, szHash);
176176

177177
pStorage->endBlock(stBlk);
178-
}else
179-
status = true; // external storage - so continue with save ...
178+
}
179+
else
180+
status = true; // external storage - so continue with save ...
180181

181182
// everything go okay?
182183
if (!status)
@@ -200,9 +201,9 @@ bool flxFlux::restore(flxStorage *pStorage)
200201
return false;
201202

202203
// If the storage kind is *internal*, check for our app hash key. This provides
203-
// a quick check to validate the storage source.
204+
// a quick check to validate the storage source.
204205
//
205-
// Note for external sources (files...etc), we load in and validate based on
206+
// Note for external sources (files...etc), we load in and validate based on
206207
// source name. This makes it easier to manually write out a settings file
207208
bool status;
208209
if (pStorage->kind() == flxStorage::flxStorageKindInternal)
@@ -229,8 +230,9 @@ bool flxFlux::restore(flxStorage *pStorage)
229230
}
230231

231232
pStorage->endBlock(stBlk);
232-
}else
233-
status = true; // restoring form an external source
233+
}
234+
else
235+
status = true; // restoring form an external source
234236

235237
// everything go okay?
236238
if (!status)
@@ -241,6 +243,26 @@ bool flxFlux::restore(flxStorage *pStorage)
241243
// call superclass
242244
return flxObjectContainer::restore(pStorage);
243245
}
246+
//---------------------------------------------------------------------------------
247+
// get the device ID
248+
//
249+
const char *flxFlux::deviceId(void)
250+
{
251+
// ID is 16 in length, use a C string
252+
static char szDeviceID[17] = {0};
253+
static bool bInitialized = false;
254+
#ifdef ESP32
255+
256+
if (!bInitialized)
257+
{
258+
memset(szDeviceID, '\0', sizeof(szDeviceID));
259+
snprintf(szDeviceID, sizeof(szDeviceID), "%4s%012llX", _v_idprefix, ESP.getEfuseMac());
260+
bInitialized = true;
261+
}
262+
263+
#endif
264+
return (const char *)szDeviceID;
265+
}
244266

245267
//---------------------------------------------------------------------------------
246268
//

0 commit comments

Comments
 (0)