Kconfigure BLE service data length
This commit is contained in:
parent
c5a5fcaf5f
commit
d18e7ab2d6
4 changed files with 18 additions and 19 deletions
|
|
@ -12,7 +12,7 @@ config PRST_NETWORK_BLE
|
|||
bool "Uses BLE as the network"
|
||||
depends on BT
|
||||
|
||||
endchoice
|
||||
endchoice # PRST_NETWORK
|
||||
|
||||
###
|
||||
### BLE configs
|
||||
|
|
@ -29,4 +29,11 @@ config PRST_BLE_ENCODING_BPARASITE_V2
|
|||
config PRST_BLE_ENCODING_BTHOME
|
||||
bool "Uses the BTHome (bthome.io) BLE encoding"
|
||||
|
||||
endchoice
|
||||
endchoice # PRST_BLE_ENCODING
|
||||
|
||||
config PRST_BLE_ENCODING_SERVICE_DATA_LEN
|
||||
int
|
||||
help
|
||||
Size of the service data buffer
|
||||
default 20 if PRST_BLE_ENCODING_BPARASITE_V2
|
||||
default 18 if PRST_BLE_ENCODING_BTHOME
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@
|
|||
|
||||
LOG_MODULE_REGISTER(ble, LOG_LEVEL_DBG);
|
||||
|
||||
static uint8_t service_data[PRST_BLE_ENCODING_SERVICE_DATA_LEN] = {0};
|
||||
static uint8_t service_data[CONFIG_PRST_BLE_ENCODING_SERVICE_DATA_LEN] = {0};
|
||||
|
||||
static const struct bt_data ad[] = {
|
||||
BT_DATA_BYTES(BT_DATA_FLAGS, (BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR)),
|
||||
|
|
|
|||
|
|
@ -9,46 +9,40 @@ LOG_MODULE_DECLARE(ble, LOG_LEVEL_DBG);
|
|||
int prst_ble_encode_service_data(const prst_sensors_t* sensors,
|
||||
const bt_addr_le_t* bt_addr, uint8_t* out,
|
||||
uint8_t out_len) {
|
||||
RET_CHECK(out_len >= PRST_BLE_ENCODING_SERVICE_DATA_LEN,
|
||||
RET_CHECK(out_len >= CONFIG_PRST_BLE_ENCODING_SERVICE_DATA_LEN,
|
||||
"Buffer is not large enough");
|
||||
|
||||
// 0x181c - BTHome Service UUID.
|
||||
out[0] = 0x1c;
|
||||
#if CONFIG_PRST_BLE_ENCODING_BPARASITE_V2
|
||||
// 0x181a - Environmental sensing service UUID.
|
||||
out[0] = 0x1a;
|
||||
out[1] = 0x18;
|
||||
|
||||
// Soil Moisture.
|
||||
//
|
||||
// Four bits for the protocol version.
|
||||
out[2] |= (2 << 4) & 0xf0;
|
||||
|
||||
// Bit 0 of byte 0 specifies whether or not ambient light data exists in the
|
||||
// payload.
|
||||
out[2] |= 1;
|
||||
|
||||
// 4 bits for a small wrap-around counter for deduplicating messages on the
|
||||
// receiver.
|
||||
// out[3] = sensors->run_counter & 0x0f;
|
||||
|
||||
out[4] = sensors->batt.millivolts >> 8;
|
||||
out[5] = sensors->batt.millivolts & 0xff;
|
||||
|
||||
int16_t temp_centicelsius = 100 * sensors->shtc3.temp_c;
|
||||
out[6] = temp_centicelsius >> 8;
|
||||
out[7] = temp_centicelsius & 0xff;
|
||||
|
||||
uint16_t humi = sensors->shtc3.rel_humi * UINT16_MAX;
|
||||
out[8] = humi >> 8;
|
||||
out[9] = humi & 0xff;
|
||||
|
||||
uint16_t soil_moisture = sensors->soil.percentage * UINT16_MAX;
|
||||
out[10] = soil_moisture >> 8;
|
||||
out[11] = soil_moisture & 0xff;
|
||||
|
||||
// MAC address in big-endian.
|
||||
memcpy(out + 12, bt_addr->a.val, BT_ADDR_SIZE);
|
||||
|
||||
out[18] = sensors->photo.brightness >> 8;
|
||||
out[19] = sensors->photo.brightness & 0xff;
|
||||
#elif CONFIG_PRST_BLE_ENCODING_BTHOME
|
||||
// TODO.
|
||||
memset(out, 0xab, out_len);
|
||||
#endif // Enccoding protocols
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -5,8 +5,6 @@
|
|||
|
||||
#include "prst/data.h"
|
||||
|
||||
#define PRST_BLE_ENCODING_SERVICE_DATA_LEN 20
|
||||
|
||||
int prst_ble_encode_service_data(const prst_sensors_t* sensors,
|
||||
const bt_addr_le_t* bt_addr, uint8_t* out,
|
||||
uint8_t out_len);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue