Crownstone encapsulates all functionality, stack, services, and configuration.
More...
#include <cs_Crownstone.h>
Crownstone encapsulates all functionality, stack, services, and configuration.
◆ ServiceEvent
Enumerator |
---|
CREATE_DEVICE_INFO_SERVICE | |
CREATE_SETUP_SERVICE | |
CREATE_CROWNSTONE_SERVICE | |
REMOVE_DEVICE_INFO_SERVICE | |
REMOVE_SETUP_SERVICE | |
REMOVE_CROWNSTONE_SERVICE | |
◆ Crownstone()
Allocate Crownstone class and internal references.
Create buffers, timers, storage, state, etc. We are running on an embedded device. Only allocate something in a constructor. For dynamic information use the stack. Do not allocate/deallocate anything during runtime. It is too risky. It might not be freed and memory might overflow. This type of hardware should run months without interruption.
There is a function IS_CROWNSTONE. What this actually is contrasted with are other BLE type devices, in particular the Guidestone. The latter devices do not have the ability to switch, dim, or measure power consumption.
The order with which items are created.
- buffers
- event distpatcher
- BLE stack
- timer
- persistent storage
- state
- command handler
- factory reset
- scanner
- tracker
- mesh
- switch
- temperature guard
- power sampling
The initialization is done in separate function.
◆ configure()
void Crownstone::configure |
( |
| ) |
|
|
private |
configure the crownstone.
this will call the other configureXXX functions in turn
- configure ble stack
- set ble name
- configure advertisement Configure the Bluetooth stack. This also increments the reset counter.
The order within this function is important. For example setName() sets the BLE device name and configureAdvertisements() defines advertisement parameters on appearance. These have to be called after the storage has been initialized.
◆ configureAdvertisement()
void Crownstone::configureAdvertisement |
( |
| ) |
|
|
private |
Sets default parameters of the Bluetooth connection.
Data is transmitted with TX_POWER dBm.
On transmission of data within a connection (higher interval -> lower power consumption, slow communication)
- minimum connection interval (in steps of 1.25 ms, 16*1.25 = 20 ms)
- maximum connection interval (in steps of 1.25 ms, 32*1.25 = 40 ms) The supervision timeout multiplier is 400 The slave latency is 10 On advertising:
- advertising interval (in steps of 0.625 ms, 1600*0.625 = 1 sec) (can be between 0x0020 and 0x4000)
- advertising timeout (disabled, can be between 0x0001 and 0x3FFF, and is in steps of seconds)
There is no whitelist defined, nor peer addresses.
Process: [31.05.16] we used to stop / start scanning after a disconnect, now starting advertising is enough [23.06.16] restart the mesh on disconnect, otherwise we have ~10s delay until the device starts advertising. [29.06.16] restart the mesh disabled, this was limited to pca10000, it does crash dobeacon v0.7 Populate advertisement (including service data) with information. The persistence mode is obtained from storage (the _operationMode var is not used).
◆ createCrownstoneServices()
void Crownstone::createCrownstoneServices |
( |
| ) |
|
|
private |
Create services available in normal operation mode.
◆ createService()
Create a particular service.
Depending on the mode we can choose to create a set of services that we would need. After creation of a service it cannot be deleted. This is a restriction of the Nordic Softdevice. If you need a new set of services, you will need to change the mode of operation (in a persisted field). Then you can restart the device and use the mode to enable another set of services.
◆ createSetupServices()
void Crownstone::createSetupServices |
( |
| ) |
|
|
private |
Create services available in setup mode.
◆ getChildren()
std::vector< Component * > Crownstone::getChildren |
( |
| ) |
|
|
overrideprotectedvirtual |
Components with children can override this method to return them.
This is used by getComponent<> to search for available components.
Reimplemented from Component.
◆ handleEvent()
void Crownstone::handleEvent |
( |
event_t & |
event | ) |
|
|
virtual |
handle (crownstone) events
Handle events that can come from other parts of the Crownstone firmware and even originate from outside of the firmware via the BLE interface (an application, or the mesh).
Implements EventListener.
◆ increaseResetCounter()
void Crownstone::increaseResetCounter |
( |
| ) |
|
|
private |
Increase reset counter.
This will be stored in FLASH so it persists over reboots. Increase the reset counter. This can be used for debugging purposes. The reset counter is written to FLASH and persists over reboots.
◆ init()
void Crownstone::init |
( |
uint16_t |
step | ) |
|
Initialize the crownstone:
- start UART
- configure (drivers, stack, advertisement)
- check operation mode 3a. for setup mode, create setup services 3b. for normal operation mode, create crownstone services and prepare Crownstone for operation
- initialize services
Since some classes initialize asynchronous, this function is called multiple times to continue the process. When the class is initialized, the init done event will continue the initialization of other classes. Initialize Crownstone firmware. First drivers are initialized (log modules, storage modules, ADC conversion, timers). Then everything is configured independent of the mode (everything that is common to whatever mode the Crownstone runs on). A callback to the local staticTick function for a timer is set up. Then the mode of operation is switched and the BLE services are initialized.
◆ init0()
void Crownstone::init0 |
( |
| ) |
|
|
private |
The distinct init phases.
◆ init1()
void Crownstone::init1 |
( |
| ) |
|
|
private |
◆ initDrivers0()
void Crownstone::initDrivers0 |
( |
| ) |
|
|
private |
initialize drivers (stack, timer, storage, pwm, etc), loads settings from storage.
This must be called after the SoftDevice has started. The order in which things should be initialized is as follows:
- Stack. Starts up the softdevice. It controls a lot of devices, so need to set it early.
- Timer. Also initializes the app scheduler.
- Storage. Definitely after the stack has been initialized.
- State. Storage should be initialized here.
◆ initDrivers1()
void Crownstone::initDrivers1 |
( |
| ) |
|
|
private |
The distinct driver init phases.
◆ printLoadStats()
static void Crownstone::printLoadStats |
( |
| ) |
|
|
static |
Print load stats: RAM usage, app scheduler usage, etc.
◆ run()
run main
- execute app scheduler
- wait for ble events An infinite loop in which the application ceases control to the SoftDevice at regular times. It runs the scheduler, waits for events, and handles them. Also the printed statements in the log module are flushed.
◆ scheduleNextTick()
void Crownstone::scheduleNextTick |
( |
| ) |
|
|
private |
schedule next execution of tick function
◆ setName()
void Crownstone::setName |
( |
| ) |
|
|
private |
The default name.
This can later be altered by the user if the corresponding service and characteristic is enabled. It is loaded from memory or from the default and written to the Stack.
◆ startOperationMode()
void Crownstone::startOperationMode |
( |
const OperationMode & |
mode | ) |
|
|
private |
Start operation for Crownstone.
This currently only enables parts in Normal operation mode. This includes:
- prepare mesh
- prepare scanner
- prepare tracker
- ... Start the different modules depending on the operational mode. For example, in normal mode we use a scanner and the mesh. In setup mode we use the serial module (but only RX).
◆ startUp()
void Crownstone::startUp |
( |
| ) |
|
startup the crownstone:
- start advertising
- start processing (mesh, scanner, tracker, tempGuard, etc) After allocation of all modules, after initialization of each module, and after configuration of each module, we are ready to "start". This means:
- advertise
- turn on/off switch at boot (depending on default)
- watch temperature excess
- power sampling
- schedule tasks
◆ staticTick()
static void Crownstone::staticTick |
( |
Crownstone * |
ptr | ) |
|
|
inlinestatic |
tick function called by app timer
◆ switchMode()
Switch from one operation mode to another.
Depending on the operation mode we have a different set of services / characteristics enabled. Subsequently, also different entities are started (for example a scanner, or the BLE mesh).
◆ tick()
void Crownstone::tick |
( |
| ) |
|
|
private |
tick function for crownstone to update/execute periodically
Operations that are not sensitive with respect to time and only need to be called at regular intervals. TODO: describe function calls and why they are required.
◆ TYPIFY()
◆ updateHeapStats()
static void Crownstone::updateHeapStats |
( |
| ) |
|
|
static |
Update the heap statistics.
◆ updateMinStackEnd()
static void Crownstone::updateMinStackEnd |
( |
| ) |
|
|
static |
Update the minimal stack end location.
Should be called regularly from high level interrupt.
◆ TestAccess< Crownstone >
◆ _advertiser
◆ _assetFiltering
◆ _behaviourStore
◆ _bleCentral
◆ _boardsConfig
◆ _clearedGpRegRetCount
bool Crownstone::_clearedGpRegRetCount = false |
|
private |
◆ _commandAdvHandler
◆ _commandHandler
◆ _crownstoneCentral
◆ _crownstoneService
◆ _deviceInformationService
◆ _factoryReset
◆ _gpregret
uint32_t Crownstone::_gpregret[2] = {0} |
|
private |
Store gpregret as it was on boot.
◆ _mainTimerData
app_timer_t Crownstone::_mainTimerData |
|
private |
◆ _mainTimerId
app_timer_id_t Crownstone::_mainTimerId |
|
private |
◆ _meshTopology
◆ _multiSwitchHandler
◆ _oldOperationMode
OperationMode Crownstone::_oldOperationMode = OperationMode::OPERATION_MODE_UNINITIALIZED |
|
private |
◆ _operationMode
◆ _powerSampler
◆ _presenceHandler
◆ _ramStats
◆ _resetReason
uint32_t Crownstone::_resetReason = 0 |
|
private |
Store reset reason as it was on boot.
◆ _scanner
Scanner* Crownstone::_scanner = nullptr |
|
private |
◆ _serviceData
◆ _setStateValuesAfterStorageRecover
bool Crownstone::_setStateValuesAfterStorageRecover = false |
|
private |
If storage was recovered by erasing all pages, we want to set some state variables different than after a factory reset.
◆ _setupService
◆ _stack
Stack* Crownstone::_stack |
|
private |
◆ _state
State* Crownstone::_state |
|
private |
◆ _storage
◆ _switchAggregator
◆ _systemTime
◆ _temperatureGuard
◆ _timer
Timer* Crownstone::_timer |
|
private |
◆ _trackedDevices
The documentation for this class was generated from the following file: