working streaming of raw accel/gyro data. must restart firmware after run of test_basic.py
This commit is contained in:
64
firmware/app/src/bt_services.c
Normal file
64
firmware/app/src/bt_services.c
Normal file
@ -0,0 +1,64 @@
|
||||
|
||||
#include <zephyr/types.h>
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <zephyr/sys/printk.h>
|
||||
#include <zephyr/sys/byteorder.h>
|
||||
#include <zephyr/kernel.h>
|
||||
|
||||
#include <zephyr/bluetooth/bluetooth.h>
|
||||
#include <zephyr/bluetooth/hci.h>
|
||||
#include <zephyr/bluetooth/conn.h>
|
||||
#include <zephyr/bluetooth/uuid.h>
|
||||
#include <zephyr/bluetooth/gatt.h>
|
||||
|
||||
#include "bt_services.h"
|
||||
|
||||
#include <zephyr/logging/log.h>
|
||||
|
||||
LOG_MODULE_DECLARE(main, CONFIG_APP_LOG_LEVEL);
|
||||
|
||||
static sensors_raw_t sensors;
|
||||
|
||||
void set_sensors(const sensors_raw_t *values)
|
||||
{
|
||||
sensors = *values;
|
||||
}
|
||||
|
||||
// Callback definitions
|
||||
static ssize_t read_sensors(struct bt_conn *conn, const struct bt_gatt_attr *attr, void *buf,
|
||||
uint16_t len, uint16_t offset)
|
||||
{
|
||||
const char *value = attr->user_data;
|
||||
size_t size = sizeof(sensors_raw_t);
|
||||
|
||||
LOG_INF("Attribute read, handle: %u, conn: %p, bytes: %d", attr->handle, (void *)conn, size);
|
||||
|
||||
return bt_gatt_attr_read(conn, attr, buf, len, offset, value, size);
|
||||
}
|
||||
|
||||
// Service declaration
|
||||
|
||||
static ssize_t read_string(struct bt_conn *conn, const struct bt_gatt_attr *attr, void *buf, uint16_t len, uint16_t offset)
|
||||
{
|
||||
const char *value = attr->user_data;
|
||||
LOG_INF("String read, handle: %u, conn: %p\t%s", attr->handle, (void *)conn, value);
|
||||
return bt_gatt_attr_read(conn, attr, buf, len, offset, attr->user_data, strlen((char *)attr->user_data));
|
||||
}
|
||||
|
||||
BT_GATT_SERVICE_DEFINE(my_lbs_svc, BT_GATT_PRIMARY_SERVICE(BT_UUID_IMU),
|
||||
// Read raw sensor values
|
||||
BT_GATT_CHARACTERISTIC(BT_UUID_IMU_SENSORS,
|
||||
BT_GATT_CHRC_READ,
|
||||
BT_GATT_PERM_READ,
|
||||
read_sensors,
|
||||
NULL,
|
||||
&sensors),
|
||||
BT_GATT_DESCRIPTOR(BT_UUID_GATT_CUD,
|
||||
BT_GATT_PERM_READ,
|
||||
read_string,
|
||||
NULL,
|
||||
"Read raw sensor values"),
|
||||
// TODO: add characteristic to read state estimate
|
||||
);
|
Reference in New Issue
Block a user