Bluenet  5.7.0
Bluenet, firmware for nRF52 smart home devices
Loading...
Searching...
No Matches
cs_PacketsInternal.h
Go to the documentation of this file.
1/*
2 * Author: Crownstone Team
3 * Copyright: Crownstone (https://crownstone.rocks)
4 * Date: May 17, 2019
5 * License: LGPLv3+, Apache License 2.0, and/or MIT (triple-licensed)
6 */
7#pragma once
8
10#include <protocol/cs_Packets.h>
11
27struct cs_data_t {
28 buffer_ptr_t data = nullptr;
31 cs_data_t() : data(nullptr), len(0) {}
32 cs_data_t(buffer_ptr_t buf, cs_buffer_size_t size) : data(buf), len(size) {}
33};
34
39 const uint8_t* data = nullptr;
42 cs_const_data_t() : data(nullptr), len(0) {}
43 cs_const_data_t(const uint8_t* buf, cs_buffer_size_t size) : data(buf), len(size) {}
44};
45
53
58
65
69};
70
75
80};
81
90 CS_ADDRESS_TYPE_PUBLIC = 0, // Public (registered) static address.
91 CS_ADDRESS_TYPE_RANDOM_STATIC = 1, // Random static address (can only change at boot).
92 CS_ADDRESS_TYPE_RANDOM_PRIVATE_RESOLVABLE = 2, // Random resolvable address (can change at any moment).
93 CS_ADDRESS_TYPE_RANDOM_PRIVATE_NON_RESOLVABLE = 3, // Random address (can change at any moment).
94 CS_ADDRESS_TYPE_ANONYMOUS = 0x7F, // No address is advertised.
95};
96
97struct __attribute__((packed)) device_address_t {
98 uint8_t address[MAC_ADDRESS_LEN];
99 uint8_t addressType = CS_ADDRESS_TYPE_RANDOM_STATIC;
100};
101
107struct __attribute__((packed)) scanned_device_t {
108 int8_t rssi;
109 uint8_t address[MAC_ADDRESS_LEN];
111 uint8_t addressType; // See CS_ADDRESS_TYPE
112 uint8_t channel;
113 uint8_t setId;
114 uint8_t advType;
115 uint8_t dataSize;
116 uint8_t* data; // Advertisement or scan response data.
117 // More possibilities: addressType, connectable, isScanResponse, directed, scannable, extended advertisements, etc.
118};
119
124struct __attribute__((packed)) internal_multi_switch_item_cmd_t {
125 uint8_t switchCmd;
126};
127
131struct __attribute__((packed)) internal_multi_switch_item_t {
134};
135
137 return (size == sizeof(internal_multi_switch_item_t) && item->id != 0);
138}
139
140struct __attribute__((packed)) control_command_packet_t {
141 uint8_t protocolVersion = CS_CONNECTION_PROTOCOL_VERSION;
146};
147
151struct __attribute__((__packed__)) mesh_control_command_packet_t {
155};
156
170};
171
180};
181
197 uint8_t reliability = 0;
199 uint8_t idCount = 0;
202 uint8_t* payload = nullptr;
203};
204
212};
213
224};
225
229struct __attribute__((__packed__)) adv_background_t {
230 uint8_t protocol;
231 uint8_t sphereId;
232 uint8_t* data;
233 uint8_t dataSize;
234 uint8_t* macAddress;
235 int8_t rssi;
236};
237
241struct __attribute__((__packed__)) adv_background_parsed_t {
242 uint8_t* macAddress;
244 uint8_t locationId;
245 uint8_t profileId;
246 uint8_t flags;
247};
248
249struct __attribute__((__packed__)) adv_background_parsed_v1_t {
250 uint8_t* macAddress;
251 int8_t rssi;
252 uint8_t deviceToken[TRACKED_DEVICE_TOKEN_SIZE];
253};
254
255enum class PresenceMutation : uint8_t {
257 Online, // when no previous PresenceStateDescription was available but now it is
258 Offline, // when a previous PresenceStateDescription was available but now it isn't
262};
263
265 uint8_t profileId;
266 uint8_t locationId;
267 bool fromMesh = false;
268 bool simulated = false;
269};
270
271struct __attribute__((packed)) internal_register_tracked_device_packet_t {
273 uint8_t accessLevel = NOT_SET;
274};
275
277
278struct __attribute__((packed)) internal_tracked_device_heartbeat_packet_t {
280 uint8_t accessLevel = NOT_SET;
281};
282
283#define CS_ADC_REF_PIN_NOT_AVAILABLE 255
284#define CS_ADC_PIN_VDD 100
285
293struct __attribute__((packed)) adc_channel_config_t {
297};
298
306struct __attribute__((packed)) adc_config_t {
310};
311
333struct __attribute__((packed)) adc_channel_config_result_t {
341};
342
352 bool valid = false;
353
360
365
370};
371
373 uint8_t type; // 0 for encrypted service data.
374 uint8_t version;
375 uint16_t appUuid;
377};
378
382};
383
387};
388
390 uint8_t stoneId;
392};
393
394struct __attribute__((packed)) cs_twi_init_t {
395 uint8_t scl;
396 uint8_t sda;
397 uint8_t freq;
398};
399
400struct __attribute__((packed)) cs_twi_write_t {
401 uint8_t address;
402 uint8_t length;
403 uint8_t* buf;
404 bool stop;
405};
406
407struct __attribute__((packed)) cs_twi_read_t {
408 uint8_t address;
409 uint8_t length;
410 uint8_t* buf;
411 bool stop;
412};
413
414struct __attribute__((packed)) cs_gpio_init_t {
415 uint8_t pinIndex;
416 uint8_t direction;
417 uint8_t pull;
418 uint8_t polarity;
419 uintptr_t callback;
420};
421
422struct __attribute__((packed)) cs_gpio_write_t {
423 uint8_t pinIndex;
424 uint8_t length;
425 uint8_t* buf;
426};
427
428struct __attribute__((packed)) cs_gpio_read_t {
429 uint8_t pinIndex;
430 uint8_t length;
431 uint8_t* buf;
432};
433
434struct __attribute__((packed)) cs_gpio_update_t {
435 uint8_t pinIndex;
436 uint8_t length;
437 uint8_t* buf;
438};
CommandHandlerTypes
Author: Crownstone Team Copyright: Crownstone (https://crownstone.rocks) Date: Jun 3,...
Definition: cs_CommandTypes.h:10
#define CS_CONNECTION_PROTOCOL_VERSION
Definition: cs_Config.h:23
#define CS_ADC_NUM_CHANNELS
Definition: cs_Config.h:147
@ ERR_EVENT_UNHANDLED
Definition: cs_ErrorCodes.h:52
cs_mesh_model_msg_type_t
Definition: cs_MeshModelPackets.h:61
bool cs_multi_switch_item_is_valid(internal_multi_switch_item_t *item, size16_t size)
Definition: cs_PacketsInternal.h:136
internal_register_tracked_device_packet_t internal_update_tracked_device_packet_t
Definition: cs_PacketsInternal.h:276
CS_ADDRESS_TYPE
Copy of BLE_GAP_ADDR_TYPES.
Definition: cs_PacketsInternal.h:89
@ CS_ADDRESS_TYPE_ANONYMOUS
Definition: cs_PacketsInternal.h:94
@ CS_ADDRESS_TYPE_RANDOM_STATIC
Definition: cs_PacketsInternal.h:91
@ CS_ADDRESS_TYPE_RANDOM_PRIVATE_RESOLVABLE
Definition: cs_PacketsInternal.h:92
@ CS_ADDRESS_TYPE_PUBLIC
Definition: cs_PacketsInternal.h:90
@ CS_ADDRESS_TYPE_RANDOM_PRIVATE_NON_RESOLVABLE
Definition: cs_PacketsInternal.h:93
cs_mesh_msg_reliability
How reliable a mesh message should be.
Definition: cs_PacketsInternal.h:164
@ CS_MESH_RELIABILITY_MEDIUM
Definition: cs_PacketsInternal.h:168
@ CS_MESH_RELIABILITY_LOWEST
Definition: cs_PacketsInternal.h:166
@ CS_MESH_RELIABILITY_HIGH
Definition: cs_PacketsInternal.h:169
@ CS_MESH_RELIABILITY_INVALID
Definition: cs_PacketsInternal.h:165
@ CS_MESH_RELIABILITY_LOW
Definition: cs_PacketsInternal.h:167
PresenceMutation
Definition: cs_PacketsInternal.h:255
cs_mesh_msg_urgency
How urgent a message is.
Definition: cs_PacketsInternal.h:177
@ CS_MESH_URGENCY_LOW
Definition: cs_PacketsInternal.h:178
@ CS_MESH_URGENCY_HIGH
Definition: cs_PacketsInternal.h:179
EncryptionAccessLevel
Packets (structs) that are used over the air, over uart, or stored in flash.
Definition: cs_Packets.h:36
@ NOT_SET
Definition: cs_Packets.h:43
uint16_t size16_t
Definition: cs_Typedefs.h:25
uint16_t cs_buffer_size_t
Definition: cs_Typedefs.h:20
uint8_t adc_buffer_seq_nr_t
Definition: cs_Typedefs.h:35
uint8_t adc_pin_id_t
Definition: cs_Typedefs.h:32
uint8_t stone_id_t
Definition: cs_Typedefs.h:23
#define TRACKED_DEVICE_TOKEN_SIZE
Definition: cs_Typedefs.h:38
static const uint8_t MAC_ADDRESS_LEN
Length of a MAC address.
Definition: cs_Typedefs.h:43
int16_t adc_sample_value_t
Definition: cs_Typedefs.h:34
uint16_t cs_ret_code_t
Definition: cs_Typedefs.h:21
uint8_t adc_channel_id_t
Definition: cs_Typedefs.h:31
uint8_t * buffer_ptr_t
Author: Crownstone Team Copyright: Crownstone (https://crownstone.rocks) Date: 10 May....
Definition: cs_Typedefs.h:19
Struct communicated from the ADC class when it's done sampling a buffer.
Definition: cs_PacketsInternal.h:346
adc_buffer_seq_nr_t seqNr
Sequence number.
Definition: cs_PacketsInternal.h:359
bool valid
Whether this buffer has valid data.
Definition: cs_PacketsInternal.h:352
adc_channel_config_result_t config[CS_ADC_NUM_CHANNELS]
The ADC config that was used to sample this buffer.
Definition: cs_PacketsInternal.h:364
adc_sample_value_t * samples
Pointer to the samples.
Definition: cs_PacketsInternal.h:369
Result struct after configuring an ADC channel.
Definition: cs_PacketsInternal.h:333
int16_t maxValueMilliVolt
Maximum of the measured voltage (Vpin - Vpinref) range, in mV.
Definition: cs_PacketsInternal.h:338
adc_pin_id_t referencePin
The AIN pin of which its voltage will be subtracted from the voltage measured on adc_channel_config_r...
Definition: cs_PacketsInternal.h:335
adc_sample_value_t maxSampleValue
Maximum of the sample value range.
Definition: cs_PacketsInternal.h:340
adc_sample_value_t minSampleValue
Minimum of the sample value range.
Definition: cs_PacketsInternal.h:339
adc_pin_id_t pin
The AIN pin of this channel.
Definition: cs_PacketsInternal.h:334
int16_t minValueMilliVolt
Minimum of the measured voltage (Vpin - Vpinref) range, in mV.
Definition: cs_PacketsInternal.h:337
uint16_t samplingIntervalUs
The sampling interval in μs.
Definition: cs_PacketsInternal.h:336
Struct to configure an ADC channel.
Definition: cs_PacketsInternal.h:293
adc_pin_id_t pin
Definition: cs_PacketsInternal.h:294
adc_pin_id_t referencePin
Definition: cs_PacketsInternal.h:296
uint32_t rangeMilliVolt
Definition: cs_PacketsInternal.h:295
Struct to configure the ADC.
Definition: cs_PacketsInternal.h:306
adc_channel_id_t channelCount
Definition: cs_PacketsInternal.h:307
uint32_t samplingIntervalUs
Definition: cs_PacketsInternal.h:309
Parsed background advertisement.
Definition: cs_PacketsInternal.h:241
uint8_t flags
Definition: cs_PacketsInternal.h:246
uint8_t profileId
Definition: cs_PacketsInternal.h:245
uint8_t * macAddress
Definition: cs_PacketsInternal.h:242
uint8_t locationId
Definition: cs_PacketsInternal.h:244
int8_t adjustedRssi
Definition: cs_PacketsInternal.h:243
Definition: cs_PacketsInternal.h:249
uint8_t * macAddress
Definition: cs_PacketsInternal.h:250
int8_t rssi
Definition: cs_PacketsInternal.h:251
Unparsed background advertisement.
Definition: cs_PacketsInternal.h:229
uint8_t dataSize
Definition: cs_PacketsInternal.h:233
int8_t rssi
Definition: cs_PacketsInternal.h:235
uint8_t protocol
Definition: cs_PacketsInternal.h:230
uint8_t sphereId
Definition: cs_PacketsInternal.h:231
uint8_t * data
Definition: cs_PacketsInternal.h:232
uint8_t * macAddress
Definition: cs_PacketsInternal.h:234
Definition: cs_PacketsInternal.h:214
cs_data_t advertisementBuffer
Buffer that's no longer in use because advertising stopped.
Definition: cs_PacketsInternal.h:219
uint8_t advertisementHandle
Advertisement handle that stopped advertising.
Definition: cs_PacketsInternal.h:217
cs_data_t scanResponseBuffer
Buffer that's no longer in use because advertising stopped.
Definition: cs_PacketsInternal.h:221
uint16_t connectionHandle
Definition: cs_PacketsInternal.h:215
device_address_t address
Address of the connected device.
Definition: cs_PacketsInternal.h:223
Definition: cs_PacketsInternal.h:140
EncryptionAccessLevel accessLevel
Definition: cs_PacketsInternal.h:145
size16_t size
Definition: cs_PacketsInternal.h:144
buffer_ptr_t data
Definition: cs_PacketsInternal.h:143
CommandHandlerTypes type
Definition: cs_PacketsInternal.h:142
Definition: cs_PacketsInternal.h:71
cs_async_result_t(CommandHandlerTypes type, cs_ret_code_t resultCode)
Definition: cs_PacketsInternal.h:76
CommandHandlerTypes commandType
Definition: cs_PacketsInternal.h:72
cs_ret_code_t resultCode
Definition: cs_PacketsInternal.h:73
cs_data_t resultData
Definition: cs_PacketsInternal.h:74
cs_async_result_t(CommandHandlerTypes type, cs_ret_code_t resultCode, cs_data_t data)
Definition: cs_PacketsInternal.h:78
Variable length data encapsulation in terms of length and pointer to data.
Definition: cs_PacketsInternal.h:38
cs_buffer_size_t len
< Pointer to data.
Definition: cs_PacketsInternal.h:40
cs_const_data_t()
< Length of data.
Definition: cs_PacketsInternal.h:42
cs_const_data_t(const uint8_t *buf, cs_buffer_size_t size)
Definition: cs_PacketsInternal.h:43
const uint8_t * data
Definition: cs_PacketsInternal.h:39
Packets (structs) that are used internally in the firmware, and can be changed freely.
Definition: cs_PacketsInternal.h:27
cs_data_t()
< Length of data.
Definition: cs_PacketsInternal.h:31
cs_data_t(buffer_ptr_t buf, cs_buffer_size_t size)
Definition: cs_PacketsInternal.h:32
cs_buffer_size_t len
< Pointer to data.
Definition: cs_PacketsInternal.h:29
buffer_ptr_t data
Definition: cs_PacketsInternal.h:28
Definition: cs_PacketsInternal.h:414
uint8_t polarity
Definition: cs_PacketsInternal.h:418
uint8_t direction
Definition: cs_PacketsInternal.h:416
uintptr_t callback
Definition: cs_PacketsInternal.h:419
uint8_t pull
Definition: cs_PacketsInternal.h:417
uint8_t pinIndex
Definition: cs_PacketsInternal.h:415
Definition: cs_PacketsInternal.h:428
uint8_t length
Definition: cs_PacketsInternal.h:430
uint8_t pinIndex
Definition: cs_PacketsInternal.h:429
uint8_t * buf
Definition: cs_PacketsInternal.h:431
Definition: cs_PacketsInternal.h:434
uint8_t * buf
Definition: cs_PacketsInternal.h:437
uint8_t length
Definition: cs_PacketsInternal.h:436
uint8_t pinIndex
Definition: cs_PacketsInternal.h:435
Definition: cs_PacketsInternal.h:422
uint8_t * buf
Definition: cs_PacketsInternal.h:425
uint8_t pinIndex
Definition: cs_PacketsInternal.h:423
uint8_t length
Definition: cs_PacketsInternal.h:424
Struct to communicate a mesh message.
Definition: cs_PacketsInternal.h:194
size16_t size
Definition: cs_PacketsInternal.h:201
cs_mesh_msg_urgency urgency
Definition: cs_PacketsInternal.h:198
mesh_control_command_packet_flags_t flags
Definition: cs_PacketsInternal.h:196
cs_mesh_model_msg_type_t type
Definition: cs_PacketsInternal.h:195
uint8_t reliability
Definition: cs_PacketsInternal.h:197
uint8_t idCount
Definition: cs_PacketsInternal.h:199
uint8_t * payload
Definition: cs_PacketsInternal.h:202
stone_id_t * targetIds
Definition: cs_PacketsInternal.h:200
Definition: cs_PacketsInternal.h:46
cs_result_t(cs_data_t buf)
Definition: cs_PacketsInternal.h:67
cs_result_t(cs_ret_code_t returnCode)
Definition: cs_PacketsInternal.h:68
cs_result_t()
Definition: cs_PacketsInternal.h:66
cs_ret_code_t returnCode
Return code.
Definition: cs_PacketsInternal.h:52
cs_buffer_size_t dataSize
Length of the data in the buffer.
Definition: cs_PacketsInternal.h:64
cs_data_t buf
Buffer to put the result data in (can be nullptr).
Definition: cs_PacketsInternal.h:57
Definition: cs_PacketsInternal.h:394
uint8_t scl
Definition: cs_PacketsInternal.h:395
uint8_t sda
Definition: cs_PacketsInternal.h:396
uint8_t freq
Definition: cs_PacketsInternal.h:397
Definition: cs_PacketsInternal.h:407
bool stop
Definition: cs_PacketsInternal.h:411
uint8_t * buf
Definition: cs_PacketsInternal.h:410
uint8_t length
Definition: cs_PacketsInternal.h:409
uint8_t address
Definition: cs_PacketsInternal.h:408
Definition: cs_PacketsInternal.h:400
uint8_t length
Definition: cs_PacketsInternal.h:402
uint8_t * buf
Definition: cs_PacketsInternal.h:403
bool stop
Definition: cs_PacketsInternal.h:404
uint8_t address
Definition: cs_PacketsInternal.h:401
Definition: cs_PacketsInternal.h:97
A single multi switch command.
Definition: cs_PacketsInternal.h:124
uint8_t switchCmd
Definition: cs_PacketsInternal.h:125
A single multi switch packet, with target id.
Definition: cs_PacketsInternal.h:131
internal_multi_switch_item_cmd_t cmd
Definition: cs_PacketsInternal.h:133
stone_id_t id
Definition: cs_PacketsInternal.h:132
Definition: cs_PacketsInternal.h:271
register_tracked_device_packet_t data
Definition: cs_PacketsInternal.h:272
Definition: cs_PacketsInternal.h:278
tracked_device_heartbeat_packet_t data
Definition: cs_PacketsInternal.h:279
Mesh control command header packet.
Definition: cs_Packets.h:180
Mesh control command packet.
Definition: cs_PacketsInternal.h:151
control_command_packet_t controlCommand
Definition: cs_PacketsInternal.h:154
stone_id_t * targetIds
Definition: cs_PacketsInternal.h:153
mesh_control_command_packet_header_t header
Definition: cs_PacketsInternal.h:152
Definition: cs_PacketsInternal.h:389
uint8_t macAddress[MAC_ADDRESS_LEN]
Definition: cs_PacketsInternal.h:391
uint8_t stoneId
Definition: cs_PacketsInternal.h:390
Definition: cs_PacketsInternal.h:372
uint8_t version
Definition: cs_PacketsInternal.h:374
cs_data_t data
Definition: cs_PacketsInternal.h:376
uint16_t appUuid
Definition: cs_PacketsInternal.h:375
uint8_t type
Definition: cs_PacketsInternal.h:373
Definition: cs_MicroappPackets.h:67
Definition: cs_PacketsInternal.h:384
cs_data_t payload
Definition: cs_PacketsInternal.h:386
microapp_ctrl_header_t header
Definition: cs_PacketsInternal.h:385
Definition: cs_PacketsInternal.h:379
microapp_upload_t header
Definition: cs_PacketsInternal.h:380
cs_data_t data
Definition: cs_PacketsInternal.h:381
Definition: cs_MicroappPackets.h:74
Definition: cs_PacketsInternal.h:264
uint8_t profileId
Definition: cs_PacketsInternal.h:265
bool fromMesh
Definition: cs_PacketsInternal.h:267
uint8_t locationId
Definition: cs_PacketsInternal.h:266
bool simulated
Definition: cs_PacketsInternal.h:268
Definition: cs_Packets.h:351
Scanned device.
Definition: cs_PacketsInternal.h:107
uint8_t setId
Definition: cs_PacketsInternal.h:113
uint8_t addressType
Definition: cs_PacketsInternal.h:111
int8_t rssi
Definition: cs_PacketsInternal.h:108
uint8_t dataSize
Definition: cs_PacketsInternal.h:115
bool resolvedPrivateAddress
Definition: cs_PacketsInternal.h:110
uint8_t channel
Definition: cs_PacketsInternal.h:112
uint8_t advType
Definition: cs_PacketsInternal.h:114
uint8_t * data
Definition: cs_PacketsInternal.h:116
This data is encrypted.
Definition: cs_ServiceDataPackets.h:169
Struct to communicate received state of other stones.
Definition: cs_PacketsInternal.h:210
service_data_encrypted_t data
Definition: cs_PacketsInternal.h:211
Definition: cs_Packets.h:371
Flags to determine how to send the mesh message.
Definition: cs_Packets.h:167