From 10aed00a1c87bc5fcc0c00c94d9c65a7c2b0f3f2 Mon Sep 17 00:00:00 2001 From: chain40 Date: Wed, 10 May 2023 20:23:34 +0800 Subject: [PATCH] create EIS service --- app_config.h | 4 +- bmd380_peripheral.vcxproj | 1 + bmd380_peripheral.vcxproj.filters | 3 ++ le_eis_srv.c | 65 +++++++++++++++++++++++++++++++ le_srv.c | 13 ++++--- 5 files changed, 80 insertions(+), 6 deletions(-) create mode 100644 le_eis_srv.c diff --git a/app_config.h b/app_config.h index 23e237f..25e4612 100644 --- a/app_config.h +++ b/app_config.h @@ -83,7 +83,7 @@ extern "C" // SoftDevice BLE event handler #define NRF_SDH_BLE_ENABLED 1 // The number of vendor-specific UUIDs. -#define NRF_SDH_BLE_VS_UUID_COUNT 0 +#define NRF_SDH_BLE_VS_UUID_COUNT 1 // Attribute Table size in bytes. The size must be a multiple of 4. #define NRF_SDH_BLE_GATTS_ATTR_TAB_SIZE 1408 // BLE Observers - Observers and priority levels @@ -128,12 +128,14 @@ extern "C" #define MINOR_PRODUCT_NUMBER 4 #define MAJOR_VERSION_NUMBER 1 #define MINOR_VERSION_NUMBER 0 +#define BLE_EIS_ENABLED 1 #elif (DEF_ELITE_MODEL == DEF_ELITE_EIS_11) #define ELITE_DEVICE_NAME "EIS" #define MAJOR_PRODUCT_NUMBER 0 #define MINOR_PRODUCT_NUMBER 4 #define MAJOR_VERSION_NUMBER 1 #define MINOR_VERSION_NUMBER 1 +#define BLE_EIS_ENABLED 1 #elif (DEF_ELITE_MODEL == DEF_ELITE_EIS_MINI_10) #define ELITE_DEVICE_NAME "EIS" #define MAJOR_PRODUCT_NUMBER 0 diff --git a/bmd380_peripheral.vcxproj b/bmd380_peripheral.vcxproj index b598214..f80c015 100644 --- a/bmd380_peripheral.vcxproj +++ b/bmd380_peripheral.vcxproj @@ -163,6 +163,7 @@ + diff --git a/bmd380_peripheral.vcxproj.filters b/bmd380_peripheral.vcxproj.filters index 58fae81..4422578 100644 --- a/bmd380_peripheral.vcxproj.filters +++ b/bmd380_peripheral.vcxproj.filters @@ -1356,6 +1356,9 @@ Source files + + Source files + diff --git a/le_eis_srv.c b/le_eis_srv.c new file mode 100644 index 0000000..7b67c38 --- /dev/null +++ b/le_eis_srv.c @@ -0,0 +1,65 @@ +#include "sdk_common.h" +#if NRF_MODULE_ENABLED(BLE_EIS) + +#include "app_error.h" +#include "ble_gatts.h" +#include "ble_srv_common.h" +#include "nrf_sdh_ble.h" + +#include +#include + +/**< Used vendor specific UUID. */ +#define BLE_EIS_BASE_UUID \ + { \ + { \ + 0x4D, 0x3C, 0x56, 0x45, 0x12, 0x8B, 0x44, 0x1D, 0x8D, 0x6F, 0xC5, 0x95, 0x00, 0x00, 0x9B, 0xD8 \ + } \ + } +#define BLE_UUID_EIS_SERVICE 0x0001 + +typedef struct +{ + uint16_t conn_handle; + uint16_t service_handle; +} ble_eis_t; + +typedef struct +{ + uint16_t battery_volt; +} ble_eis_init_t; + +static ble_eis_t ble_eis; + +static uint32_t ble_eis_init(ble_eis_init_t const *p_eis_init) +{ + uint32_t err_code; + ble_uuid128_t base_uuid = BLE_EIS_BASE_UUID; + ble_uuid_t ble_uuid = { + .type = BLE_UUID_TYPE_UNKNOWN, + .uuid = BLE_UUID_EIS_SERVICE, + }; + + // Adding vendor specific UUID to the SoftDevice + err_code = sd_ble_uuid_vs_add(&base_uuid, &ble_uuid.type); + APP_ERROR_CHECK(err_code); + + // Adding proprietary service to the SoftDevice + err_code = sd_ble_gatts_service_add(BLE_GATTS_SRVC_TYPE_PRIMARY, &ble_uuid, &ble_eis.service_handle); + APP_ERROR_CHECK(err_code); + + return NRF_SUCCESS; +} + +void le_eis_init(void) +{ + ble_eis_init_t eis_init; + memset(&eis_init, 0x00, sizeof(eis_init)); + + extern uint16_t bas_volt_read(void); + eis_init.battery_volt = bas_volt_read(); + ret_code_t err_code = ble_eis_init(&eis_init); + APP_ERROR_CHECK(err_code); +} + +#endif // NRF_MODULE_ENABLED(BLE_EIS) diff --git a/le_srv.c b/le_srv.c index d9c52c8..d8ce81b 100644 --- a/le_srv.c +++ b/le_srv.c @@ -28,11 +28,11 @@ extern "C" } #endif -#define MANUFACTURER_NAME "MEMCHIP" /**< Manufacturer. Will be passed to Device Information Service. */ -#define HW_REV STRINGIFY(MAJOR_PRODUCT_NUMBER) "." STRINGIFY(MINOR_PRODUCT_NUMBER) "." STRINGIFY(MAJOR_VERSION_NUMBER) "." STRINGIFY(MINOR_VERSION_NUMBER) -#define FW_REV "0.1.0" -#define SER_NUM "0000-00-00-00001" -#define MODULE_NAME ELITE_DEVICE_NAME +#define MANUFACTURER_NAME "MEMCHIP" /**< Manufacturer. Will be passed to Device Information Service. */ +#define HW_REV STRINGIFY(MAJOR_PRODUCT_NUMBER) "." STRINGIFY(MINOR_PRODUCT_NUMBER) "." STRINGIFY(MAJOR_VERSION_NUMBER) "." STRINGIFY(MINOR_VERSION_NUMBER) +#define FW_REV "0.1.0" +#define SER_NUM "0000-00-00-00001" +#define MODULE_NAME ELITE_DEVICE_NAME static void le_dis_init(void) { @@ -53,4 +53,7 @@ static void le_dis_init(void) void le_srv_init(void) { le_dis_init(); + + extern void le_eis_init(void); + le_eis_init(); }