Nordic Semiconductor nRF5 AirFuel SDK  version 2.2.0
ble_wpts_common.c
Go to the documentation of this file.
1 /* Copyright (c) 2013 Nordic Semiconductor. All Rights Reserved.
2  *
3  * The information contained herein is property of Nordic Semiconductor ASA.
4  * Terms and conditions of usage are described in detail in NORDIC
5  * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
6  *
7  * Licensees are granted free, non-transferable use of the information. NO
8  * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
9  * the file.
10  *
11  */
12 
15 #include <stdint.h>
16 #include <stdbool.h>
17 #include "ble.h"
18 
19 #include "ble_srv_common.h"
20 #include "ble_wpts_common.h"
21 #include "nrf_assert.h"
22 #include "nrf_error.h"
23 
24 bool wpts_uuids_initialized = false;
26 /******************************************************************************/
29 /******************************************************************************/
30 
31 static ble_uuid_t m_uuids128[BLE_WPTS_UUID128_CNT];
35 /******************************************************************************/
38 /******************************************************************************/
39 
41 {
42  uint32_t err_code;
43  uint8_t i;
44  uint16_t uuid16;
45  uint8_t ref_byte;
46  ble_uuid128_t uuid128 = {BLE_WPTS_UUID128_CHAR_BASE};
47  ref_byte = uuid128.uuid128[BLE_WPTS_MODIFIED_BYTE];
48 
49  // Create 16-bit representations of 128-bit characteristics
50  uuid16 = uint16_decode(&uuid128.uuid128[12]);
51  for(i = 0; i < BLE_WPTS_UUID128_CNT; i++)
52  {
53  m_uuids128[i].uuid = uuid16;
54  }
55 
56  // Add PRU Control char UUID
57  uuid128.uuid128[BLE_WPTS_MODIFIED_BYTE] = (ref_byte + BLE_WPTS_UUID_PRU_CONTROL_CHAR_OFFSET);
58  err_code = sd_ble_uuid_vs_add(&uuid128, &m_uuids128[BLE_WPTS_UUID128_PRU_CONTROL_CHAR].type);
59  if (err_code != NRF_SUCCESS)
60  {
61  return err_code;
62  }
63 
64  // Add PTU Static Parameter Char UUID
66  err_code = sd_ble_uuid_vs_add(&uuid128, &m_uuids128[BLE_WPTS_UUID128_PTU_STATIC_PARAMETER_CHAR].type);
67  if (err_code != NRF_SUCCESS)
68  {
69  return err_code;
70  }
71 
72  // Add PRU Alert Char UUID
73  uuid128.uuid128[BLE_WPTS_MODIFIED_BYTE] = (ref_byte + BLE_WPTS_UUID_PRU_ALERT_CHAR_OFFSET);
74  err_code = sd_ble_uuid_vs_add(&uuid128, &m_uuids128[BLE_WPTS_UUID128_PRU_ALERT_CHAR].type);
75  if (err_code != NRF_SUCCESS)
76  {
77  return err_code;
78  }
79 
80  // Add PRU Static Parameter Char UUID
82  err_code = sd_ble_uuid_vs_add(&uuid128, &m_uuids128[BLE_WPTS_UUID128_PRU_STATIC_PARAMETER_CHAR].type);
83  if (err_code != NRF_SUCCESS)
84  {
85  return err_code;
86  }
87 
88  // Add PRU Dynamic Parameter Char UUID
90  err_code = sd_ble_uuid_vs_add(&uuid128, &m_uuids128[BLE_WPTS_UUID128_PRU_DYNAMIC_PARAMETER_CHAR].type);
91  if (err_code != NRF_SUCCESS)
92  {
93  return err_code;
94  }
95 
97 
98  return NRF_SUCCESS;
99 }
100 
101 void ble_wpts_uuid_get(ble_wpts_uuid128_t uuid128, ble_uuid_t * ble_uuid)
102 {
103  ASSERT(wpts_uuids_initialized);
104  *ble_uuid = m_uuids128[uuid128];
105 }
106 
#define BLE_WPTS_UUID_PRU_ALERT_CHAR_OFFSET
uint32_t ble_wpts_uuid_init()
Prepare softdevice for using the WPTS 128 bit UUIDs.
bool wpts_uuids_initialized
#define BLE_WPTS_MODIFIED_BYTE
static ble_uuid_t m_uuids128[BLE_WPTS_UUID128_CNT]
#define BLE_WPTS_UUID_PRU_DYNAMIC_PARAMETER_CHAR_OFFSET
void ble_wpts_uuid_get(ble_wpts_uuid128_t uuid128, ble_uuid_t *ble_uuid)
Get ble_uuid representation of 128 bit UUID.
#define BLE_WPTS_UUID_PRU_STATIC_PARAMETER_CHAR_OFFSET
#define BLE_WPTS_UUID_PTU_STATIC_PARAMETER_CHAR_OFFSET
#define BLE_WPTS_UUID128_CHAR_BASE
ble_wpts_uuid128_t
Identification of 128 bit UUIDs.
#define BLE_WPTS_UUID_PRU_CONTROL_CHAR_OFFSET