Bluenet
5.7.0
Bluenet, firmware for nRF52 smart home devices
|
#include <cs_ServiceData.h>
Public Member Functions | |
ServiceData () | |
void | init (uint8_t deviceType) |
Init the service data, make sure you set important fields first. More... | |
void | setDeviceType (uint8_t deviceType) |
Set the device type field of the service data. More... | |
void | updatePowerUsage (int32_t powerUsage) |
Set the power usage field of the service data. More... | |
void | updateAccumulatedEnergy (int32_t energy) |
Set the energy used field of the service data. More... | |
void | updateCrownstoneId (stone_id_t crownstoneId) |
Set the ID field of the service data. More... | |
void | updateSwitchState (uint8_t switchState) |
Set the switch state field of the service data. More... | |
void | updateTemperature (int8_t temperature) |
Set the temperature field of the service data. More... | |
void | updateServiceData (bool initial) |
Update the service data. More... | |
uint8_t * | getArray () |
Get the service data as array. More... | |
uint16_t | getArraySize () |
Get the size of the service data. More... | |
Private Member Functions | |
TYPIFY (STATE_ERRORS) _stateErrors | |
Cache the state errors. More... | |
bool | fillServiceData (uint32_t timestamp) |
Selects a type of data and puts this in the service data. More... | |
void | encryptServiceData () |
Encrypt the service data. More... | |
void | fillWithSetupState (uint32_t timestamp) |
Put the state of this Crownstone in setup mode in the service data. More... | |
void | fillWithState (uint32_t timestamp) |
Put the state of this Crownstone in the service data. More... | |
void | fillWithError (uint32_t timestamp) |
Put the error state of this Crownstone in the service data. More... | |
bool | fillWithExternalState () |
Put the state or error state of another Crownstone in the service data. More... | |
void | fillWithAlternativeState (uint32_t timestamp) |
Put the alternative state of this Crownstone in the service data. More... | |
void | fillWithHubState (uint32_t timestamp) |
Put the hub state in the service data. More... | |
bool | fillWithMicroapp (uint32_t timestamp) |
Put microapp data in the service data. More... | |
void | handleEvent (event_t &event) |
Called when there are events to handle. More... | |
int16_t | compressPowerUsageMilliWatt (int32_t powerUsageMW) |
Compress power usage, according to service data protocol v3. More... | |
int32_t | decompressPowerUsage (int16_t compressedPowerUsage) |
Decompress power usage, according to service data protocol v3. More... | |
uint16_t | timestampToPartialTimestamp (uint32_t timestamp) |
Convert timestamp to a partial timestamp, according to service data protocol v3. More... | |
uint16_t | getPartialTimestampOrCounter (uint32_t timestamp, uint32_t counter) |
When a timestamp is available, return partial timestamp, else returns a counter. More... | |
uint16_t | getPartialBehaviourHash (uint32_t behaviourHash) |
Get a part of the behaviour hash. More... | |
void | sendMeshState (bool event) |
Send the state over the mesh. More... | |
![]() | |
EventListener () | |
virtual | ~EventListener () |
unregisters the listener. More... | |
virtual void | handleEvent (event_t &event)=0 |
Handle events. More... | |
void | listen () |
Registers this with the EventDispatcher. More... | |
Static Private Member Functions | |
static void | staticTimeout (ServiceData *ptr) |
Private Attributes | |
app_timer_t | _updateTimerData |
Timer used to periodically update the advertisement. More... | |
app_timer_id_t | _updateTimerId = NULL |
service_data_t | _serviceData |
Stores the last (current) advertised service data. More... | |
stone_id_t | _crownstoneId = 0 |
Cache own ID. More... | |
uint8_t | _switchState = 0 |
Cache switch state. More... | |
service_data_state_flags_t | _flags |
Cache flags. More... | |
service_data_state_extra_flags_t | _extraFlags |
Cache extra flags. More... | |
int8_t | _temperature = 0 |
Cache the temperature. More... | |
int8_t | _powerFactor = 0 |
Cache the power factor. More... | |
int32_t | _powerUsageReal = 0 |
Cache the power usage in mW. More... | |
int32_t | _energyUsed = 0 |
Cache the energy used, in units of 64 J. More... | |
uint32_t | _firstErrorTimestamp = 0 |
Cache timestamp of first error. More... | |
uint32_t | _sendStateCountdown = MESH_SEND_STATE_INTERVAL_MS / TICK_INTERVAL_MS |
OperationMode | _operationMode = OperationMode::OPERATION_MODE_UNINITIALIZED |
Cache the operation mode. More... | |
uint32_t | _updateCount = 0 |
Counter that keeps up the number of times that the advertisement has been updated. More... | |
ExternalStates | _externalStates |
bool | _microappServiceDataSet = false |
Whether the microapp wants to advertise service data. More... | |
service_data_encrypted_microapp_t | _microappServiceData |
Microapp data to be advertised in crownstone service data. More... | |
|
private |
Compress power usage, according to service data protocol v3.
[in] | powerUsageMW | Power usage in milliWatt |
|
private |
Decompress power usage, according to service data protocol v3.
[in] | powerUsageMW | Compressed representation of the power usage. |
|
private |
Encrypt the service data.
|
private |
Selects a type of data and puts this in the service data.
|
private |
Put the alternative state of this Crownstone in the service data.
|
private |
Put the error state of this Crownstone in the service data.
|
private |
Put the state or error state of another Crownstone in the service data.
|
private |
Put the hub state in the service data.
|
private |
Put microapp data in the service data.
|
private |
Put the state of this Crownstone in setup mode in the service data.
|
private |
Put the state of this Crownstone in the service data.
uint8_t * ServiceData::getArray | ( | ) |
Get the service data as array.
uint16_t ServiceData::getArraySize | ( | ) |
Get the size of the service data.
|
private |
Get a part of the behaviour hash.
|
private |
When a timestamp is available, return partial timestamp, else returns a counter.
[in] | timestamp | The timestamp. |
[in] | counter | The counter. |
|
privatevirtual |
Called when there are events to handle.
[in] | evt | Event type, see cs_EventTypes.h. |
[in] | p_data | Pointer to the data. |
[in] | length | Length of the data. |
Implements EventListener.
void ServiceData::init | ( | uint8_t | deviceType | ) |
Init the service data, make sure you set important fields first.
[in] | deviceType | The device type, see cs_DeviceTypes.h |
|
private |
Send the state over the mesh.
[in] | event | True when sending state because of an event. |
void ServiceData::setDeviceType | ( | uint8_t | deviceType | ) |
Set the device type field of the service data.
[in] | deviceType | The device type, see cs_DeviceTypes.h |
|
inlinestaticprivate |
|
private |
Convert timestamp to a partial timestamp, according to service data protocol v3.
[in] | timestamp | The timestamp. |
|
private |
Cache the state errors.
void ServiceData::updateAccumulatedEnergy | ( | int32_t | energy | ) |
Set the energy used field of the service data.
[in] | energy | The energy used in units of 64 Joule. |
void ServiceData::updateCrownstoneId | ( | stone_id_t | crownstoneId | ) |
Set the ID field of the service data.
[in] | crownstoneId | The Crownstone ID. |
void ServiceData::updatePowerUsage | ( | int32_t | powerUsage | ) |
Set the power usage field of the service data.
[in] | powerUsage | The power usage in milliWatt. |
void ServiceData::updateServiceData | ( | bool | initial | ) |
Update the service data.
Updates some states. Selects a type of data, and puts this in the service data. Writes the service data to UART. Sends out event EVT_ADVERTISEMENT_UPDATED.
[in] | initial | Set initial to true when this is just the initial data when there's no need to send out the event. |
void ServiceData::updateSwitchState | ( | uint8_t | switchState | ) |
Set the switch state field of the service data.
[in] | switchState | The switch state. |
void ServiceData::updateTemperature | ( | int8_t | temperature | ) |
Set the temperature field of the service data.
[in] | temperature | The temperature. |
|
private |
Cache own ID.
|
private |
Cache the energy used, in units of 64 J.
|
private |
|
private |
Cache extra flags.
|
private |
Cache timestamp of first error.
|
private |
Cache flags.
|
private |
Microapp data to be advertised in crownstone service data.
|
private |
Whether the microapp wants to advertise service data.
|
private |
Cache the operation mode.
|
private |
Cache the power factor.
|
private |
Cache the power usage in mW.
|
private |
|
private |
Stores the last (current) advertised service data.
This data will be copied by the advertiser.
|
private |
Cache switch state.
|
private |
Cache the temperature.
|
private |
Counter that keeps up the number of times that the advertisement has been updated.
|
private |
Timer used to periodically update the advertisement.
|
private |