Created
May 10, 2020 12:57
-
-
Save MZachmann/36988eb989ee26b2afc850f281ab6c05 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// GATT Device Information Service | |
// Copyright 2020 MZachmann | |
// MIT License | |
#include <bluetooth/bluetooth.h> | |
#include <bluetooth/hci.h> | |
#include <bluetooth/conn.h> | |
#include <bluetooth/uuid.h> | |
#include <bluetooth/gatt.h> | |
#include <logging/log.h> | |
LOG_MODULE_REGISTER(BtDis, LOG_LEVEL_INF); | |
#define BT_GATT_DIS_MODEL "BlueLora" | |
#define BT_GATT_DIS_MANUF "Audua, LLC" | |
// following defines are paired as enable, value | |
#define CONFIG_BT_GATT_DIS_SERIAL_NUMBER | |
#define BT_GATT_DIS_SERIAL_NUMBER_STR "10012" | |
#define CONFIG_BT_GATT_DIS_FW_REV | |
#define BT_GATT_DIS_FW_REV_STR "1.58" | |
#define CONFIG_BT_GATT_DIS_HW_REV | |
#define BT_GATT_DIS_HW_REV_STR "8" | |
// #define CONFIG_BT_GATT_DIS_SW_REV | |
#define BT_GATT_DIS_SW_REV_STR "1.5" | |
static ssize_t read_str(struct bt_conn *conn, | |
const struct bt_gatt_attr *attr, void *buf, | |
u16_t len, u16_t offset) | |
{ | |
return bt_gatt_attr_read(conn, attr, buf, len, offset, attr->user_data, | |
strlen(attr->user_data)); | |
} | |
/* Device Information Service Declaration */ | |
BT_GATT_SERVICE_DEFINE(dis_svc, | |
BT_GATT_PRIMARY_SERVICE(BT_UUID_DIS), | |
BT_GATT_CHARACTERISTIC(BT_UUID_DIS_MODEL_NUMBER, | |
BT_GATT_CHRC_READ, BT_GATT_PERM_READ, | |
read_str, NULL, BT_GATT_DIS_MODEL), | |
BT_GATT_CHARACTERISTIC(BT_UUID_DIS_MANUFACTURER_NAME, | |
BT_GATT_CHRC_READ, BT_GATT_PERM_READ, | |
read_str, NULL, BT_GATT_DIS_MANUF) | |
#if defined(CONFIG_BT_GATT_DIS_SERIAL_NUMBER) | |
,BT_GATT_CHARACTERISTIC(BT_UUID_DIS_SERIAL_NUMBER, | |
BT_GATT_CHRC_READ, BT_GATT_PERM_READ, | |
read_str, NULL, | |
BT_GATT_DIS_SERIAL_NUMBER_STR) | |
#endif | |
#if defined(CONFIG_BT_GATT_DIS_FW_REV) | |
,BT_GATT_CHARACTERISTIC(BT_UUID_DIS_FIRMWARE_REVISION, | |
BT_GATT_CHRC_READ, BT_GATT_PERM_READ, | |
read_str, NULL, BT_GATT_DIS_FW_REV_STR) | |
#endif | |
#if defined(CONFIG_BT_GATT_DIS_HW_REV) | |
,BT_GATT_CHARACTERISTIC(BT_UUID_DIS_HARDWARE_REVISION, | |
BT_GATT_CHRC_READ, BT_GATT_PERM_READ, | |
read_str, NULL, BT_GATT_DIS_HW_REV_STR) | |
#endif | |
#if defined(CONFIG_BT_GATT_DIS_SW_REV) | |
,BT_GATT_CHARACTERISTIC(BT_UUID_DIS_SOFTWARE_REVISION, | |
BT_GATT_CHRC_READ, BT_GATT_PERM_READ, | |
read_str, NULL, BT_GATT_DIS_SW_REV_STR) | |
#endif | |
); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment