Bluenet  5.7.0
Bluenet, firmware for nRF52 smart home devices
Loading...
Searching...
No Matches
cs_Crownstone.h
Go to the documentation of this file.
1/*
2 * Author: Crownstone Team
3 * Copyright: Crownstone (https://crownstone.rocks)
4 * Date: Apr 24, 2015
5 * License: LGPLv3+, Apache License 2.0, and/or MIT (triple-licensed)
6 */
7#pragma once
8
9
11#include <ble/cs_Advertiser.h>
12#include <ble/cs_BleCentral.h>
14#include <ble/cs_Stack.h>
15#include <ble/cs_iBeacon.h>
16#include <cfg/cs_Boards.h>
31#include <storage/cs_State.h>
33#include <time/cs_SystemTime.h>
35#include <test/cs_TestAccess.h>
36
37#if BUILD_MESHING == 1
38#include <mesh/cs_Mesh.h>
39#endif
40
41#if BUILD_MICROAPP_SUPPORT == 1
43#endif
44
45#if BUILD_MEM_USAGE_TEST == 1
47#endif
48
49#if BUILD_TWI == 1
50#include <drivers/cs_Twi.h>
51#endif
52
53#if BUILD_GPIOTE == 1
54#include <drivers/cs_Gpio.h>
55#endif
56
60class Crownstone : public EventListener, public Component {
61 friend class TestAccess<Crownstone>;
62public:
70 };
71
103
123 void init(uint16_t step);
124
139 void startUp();
140
149 void run();
150
157 void handleEvent(event_t& event);
158
162 static void updateHeapStats();
163
169 static void updateMinStackEnd();
170
174 static void printLoadStats();
175
178 static void staticTick(Crownstone* ptr) { ptr->tick(); }
179
180protected:
181 std::vector<Component*> getChildren() override;
182
183private:
187 void init0();
188 void init1();
189
201
217
231 void configure();
232
259
264 void setName();
265
272 void createService(const ServiceEvent event);
273
277
281
295
301 void switchMode(const OperationMode& mode);
302
309 void tick();
310
314
322
323 // Keep the board config in memory, so other classes can store a pointer to it.
325
326 // drivers
334
337
338 // services
342
343 // advertise
345
346 // processing
347#if BUILD_MESHING == 1
348 Mesh* _mesh = nullptr;
349#endif
351 Scanner* _scanner = nullptr;
356
358
359 // TODO: allocate and init only in normal mode.
365
366#if BUILD_MICROAPP_SUPPORT == 1
367 Microapp* _microapp;
368#endif
369
370#if BUILD_MEM_USAGE_TEST == 1
371 MemUsageTest _memTest;
372#endif
373
374#if BUILD_TWI == 1
375 Twi* _twi = nullptr;
376#endif
377
378#if BUILD_GPIOTE == 1
379 Gpio* _gpio = nullptr;
380#endif
381
382 app_timer_t _mainTimerData;
383 app_timer_id_t _mainTimerId;
384 TYPIFY(EVT_TICK) _tickCount = 0;
385
387 OperationMode _oldOperationMode = OperationMode::OPERATION_MODE_UNINITIALIZED;
388
390 uint32_t _gpregret[2] = {0};
391
393 uint32_t _resetReason = 0;
394
396
402
404};
Definition: cs_Advertiser.h:20
Definition: cs_AssetFiltering.h:19
Keeps track of the behaviours that are active on this crownstone.
Definition: cs_BehaviourStore.h:25
Class that enables you to connect to a device, and perform write or read operations.
Definition: cs_BleCentral.h:27
Definition: cs_CommandAdvHandler.h:58
Every command from an external device such as a smartphone goes through the CommandHandler.
Definition: cs_CommandHandler.h:34
Helper class to manage decoupling of components.
Definition: cs_Component.h:35
Class to connect to another crownstone, and write control commands.
Definition: cs_CrownstoneCentral.h:26
Author: Crownstone Team Copyright: Crownstone (https://crownstone.rocks) Date: Oct 22,...
Definition: cs_CrownstoneService.h:25
Crownstone encapsulates all functionality, stack, services, and configuration.
Definition: cs_Crownstone.h:60
ServiceData * _serviceData
Definition: cs_Crownstone.h:344
SetupService * _setupService
Definition: cs_Crownstone.h:341
void createCrownstoneServices()
Create services available in normal operation mode.
TrackedDevices _trackedDevices
Definition: cs_Crownstone.h:360
FactoryReset * _factoryReset
Definition: cs_Crownstone.h:352
static void updateHeapStats()
Update the heap statistics.
PowerSampling * _powerSampler
Definition: cs_Crownstone.h:336
app_timer_t _mainTimerData
Definition: cs_Crownstone.h:382
OperationMode _operationMode
Definition: cs_Crownstone.h:386
void run()
run main
Timer * _timer
Definition: cs_Crownstone.h:331
void init1()
AssetFiltering _assetFiltering
Definition: cs_Crownstone.h:362
void increaseResetCounter()
Increase reset counter.
Scanner * _scanner
Definition: cs_Crownstone.h:351
OperationMode _oldOperationMode
Definition: cs_Crownstone.h:387
void createSetupServices()
Create services available in setup mode.
void configure()
configure the crownstone.
void handleEvent(event_t &event)
handle (crownstone) events
SwitchAggregator _switchAggregator
Definition: cs_Crownstone.h:357
bool _clearedGpRegRetCount
Definition: cs_Crownstone.h:403
void scheduleNextTick()
schedule next execution of tick function
void init(uint16_t step)
Initialize the crownstone:
SystemTime _systemTime
Definition: cs_Crownstone.h:355
bool _setStateValuesAfterStorageRecover
If storage was recovered by erasing all pages, we want to set some state variables different than aft...
Definition: cs_Crownstone.h:401
TemperatureGuard * _temperatureGuard
Definition: cs_Crownstone.h:335
CrownstoneService * _crownstoneService
Definition: cs_Crownstone.h:340
CommandAdvHandler * _commandAdvHandler
Definition: cs_Crownstone.h:353
void initDrivers1()
The distinct driver init phases.
static void updateMinStackEnd()
Update the minimal stack end location.
void init0()
The distinct init phases.
ServiceEvent
Definition: cs_Crownstone.h:63
@ CREATE_SETUP_SERVICE
Definition: cs_Crownstone.h:65
@ REMOVE_SETUP_SERVICE
Definition: cs_Crownstone.h:68
@ CREATE_CROWNSTONE_SERVICE
Definition: cs_Crownstone.h:66
@ CREATE_DEVICE_INFO_SERVICE
Definition: cs_Crownstone.h:64
@ REMOVE_DEVICE_INFO_SERVICE
Definition: cs_Crownstone.h:67
@ REMOVE_CROWNSTONE_SERVICE
Definition: cs_Crownstone.h:69
Stack * _stack
Definition: cs_Crownstone.h:327
Storage * _storage
Definition: cs_Crownstone.h:332
static void printLoadStats()
Print load stats: RAM usage, app scheduler usage, etc.
void tick()
tick function for crownstone to update/execute periodically
BleCentral * _bleCentral
Definition: cs_Crownstone.h:328
MeshTopology _meshTopology
Definition: cs_Crownstone.h:361
PresenceHandler _presenceHandler
Definition: cs_Crownstone.h:364
Crownstone(boards_config_t &board)
Allocate Crownstone class and internal references.
app_timer_id_t _mainTimerId
Definition: cs_Crownstone.h:383
void initDrivers0()
initialize drivers (stack, timer, storage, pwm, etc), loads settings from storage.
State * _state
Definition: cs_Crownstone.h:333
MultiSwitchHandler * _multiSwitchHandler
Definition: cs_Crownstone.h:354
static void staticTick(Crownstone *ptr)
tick function called by app timer
Definition: cs_Crownstone.h:178
void switchMode(const OperationMode &mode)
Switch from one operation mode to another.
void setName()
The default name.
static cs_ram_stats_t _ramStats
Definition: cs_Crownstone.h:395
uint32_t _gpregret[2]
Store gpregret as it was on boot.
Definition: cs_Crownstone.h:390
void startOperationMode(const OperationMode &mode)
Start operation for Crownstone.
void startUp()
startup the crownstone:
void createService(const ServiceEvent event)
Create a particular service.
boards_config_t _boardsConfig
Definition: cs_Crownstone.h:324
BehaviourStore _behaviourStore
Definition: cs_Crownstone.h:363
std::vector< Component * > getChildren() override
Components with children can override this method to return them.
CrownstoneCentral * _crownstoneCentral
Definition: cs_Crownstone.h:329
void configureAdvertisement()
Sets default parameters of the Bluetooth connection.
Advertiser * _advertiser
Definition: cs_Crownstone.h:330
CommandHandler * _commandHandler
Definition: cs_Crownstone.h:350
TYPIFY(EVT_TICK) _tickCount=0
DeviceInformationService * _deviceInformationService
Definition: cs_Crownstone.h:339
uint32_t _resetReason
Store reset reason as it was on boot.
Definition: cs_Crownstone.h:393
The DeviceInformationService is a BLE service that gives info on hardware and firmware revisions.
Definition: cs_DeviceInformationService.h:14
Event listener.
Definition: cs_EventListener.h:17
Definition: cs_FactoryReset.h:28
Definition: cs_Gpio.h:31
Definition: cs_MemUsageTest.h:12
Definition: cs_MeshTopology.h:19
Author: Crownstone Team Copyright: Crownstone (https://crownstone.rocks) Date: 12 Apr....
Definition: cs_Mesh.h:36
Class that enables the feature to run microapps on the firmware.
Definition: cs_Microapp.h:21
Definition: cs_MultiSwitchHandler.h:13
Sample power.
Definition: cs_PowerSampling.h:24
Keeps up all the locations each profile is present in.
Definition: cs_PresenceHandler.h:22
Scanner scans for BLE devices.
Definition: cs_Scanner.h:14
Definition: cs_ServiceData.h:20
Author: Crownstone Team Copyright: Crownstone (https://crownstone.rocks) Date: Oct 22,...
Definition: cs_SetupService.h:20
nRF51822 specific implementation of the BLEStack
Definition: cs_Stack.h:41
Stores state values in RAM and/or FLASH.
Definition: cs_State.h:145
Class to store items persistently in flash (persistent) memory.
Definition: cs_Storage.h:57
Author: Crownstone Team Copyright: Crownstone (https://crownstone.rocks) Date: Sep 26,...
Definition: cs_SwitchAggregator.h:24
Author: Crownstone Team Copyright: Crownstone (https://crownstone.rocks) Date: Sep 24,...
Definition: cs_SystemTime.h:49
Check if the temperature exceeds a certain threshold.
Definition: cs_TemperatureGuard.h:25
Definition: cs_TestAccess.h:11
Timer on top of the timer peripheral.
Definition: cs_Timer.h:22
Class that keeps up devices to be tracked.
Definition: cs_TrackedDevices.h:27
Class that implements twi/i2c.
Definition: cs_Twi.h:18
Author: Crownstone Team Copyright: Crownstone (https://crownstone.rocks) Date: Oct 9,...
Definition: cs_Event.h:26
Manufacturing data.
OperationMode
Definition: cs_Types.h:440
Universally Unique IDentifiers for BLE services and characteristics.
Board configuration.
Definition: cs_Boards.h:169
Definition: cs_Packets.h:502