Commit a70e5dc1 authored by Bjørn Inge Hanssen's avatar Bjørn Inge Hanssen Committed by GitHub
Browse files

Merge pull request #52 from NordicSemiconductor/feature/s132v5

Feature/s132v5
parents 99b5e78f 6214600a
......@@ -3,6 +3,7 @@ _build
**/CMakeFiles
**/CMakeCache.txt
*.pyc
**/build
sdk/
# Object files
......
......@@ -105,9 +105,11 @@ foreach(SD_API_VER ${SD_API_VERS})
src/${SD_API_VER_L}/sdk/components/serialization/application/codecs/common
src/${SD_API_VER_L}/sdk/components/serialization/application/codecs/s130/serializers
src/${SD_API_VER_L}/sdk/components/serialization/application/codecs/s132/serializers
src/${SD_API_VER_L}/sdk/components/serialization/application/codecs/ble/serializers
src/${SD_API_VER_L}/sdk/components/serialization/common
src/${SD_API_VER_L}/sdk/components/serialization/common/struct_ser/s130
src/${SD_API_VER_L}/sdk/components/serialization/common/struct_ser/s132
src/${SD_API_VER_L}/sdk/components/serialization/common/struct_ser/ble
src/${SD_API_VER_L}/sdk/components/softdevice/s132/headers
)
# Provide the NRF_SD_BLE_API_VERSION macro to each variant
......
......@@ -3,7 +3,7 @@
The libraries generated are compatible with the following SoftDevice API versions and nRF5x ICs:
* SoftDevice s130 API version 2: `s130_nrf51_2.x.x` (nRF51 and nRF52 series ICs)
* SoftDevice s132 API version 3: `s132_nrf52_3.x.x` (only for nRF52 series ICs)
* SoftDevice s132 API version 5: `s132_nrf52_5.x.x` (only for nRF52 series ICs)
The .hex files included in the `hex/sd_api_v<x>` folder include both the SoftDevice and the connectivity firmware required to communicate with it.
......
......@@ -3,7 +3,7 @@
`pc-ble-driver` provides C/C++ libraries for Bluetooth Low Energy nRF5 SoftDevice serialization.
## Overview
`pc-ble-driver` consists of a set of static and shared libraries that provide [SoftDevice](http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.softdevices52/dita/nrf52/softdevices.html?cp=2_3) functionality to the application via serial port communication with an nRF5 connectivity chip running the SoftDevice and connectivity software, included as a single .hex file [here](./hex/). For more information on SoftDevice serialization see [Serialization](http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.sdk5.v13.0.0/lib_serialization.html?cp=4_0_0_3_33).
`pc-ble-driver` consists of a set of static and shared libraries that provide [SoftDevice](http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.softdevices52/dita/nrf52/softdevices.html?cp=2_3) functionality to the application via serial port communication with an nRF5 connectivity chip running the SoftDevice and connectivity software, included as a single .hex file [here](./hex/). For more information on SoftDevice serialization see [Serialization](http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.sdk5.v14.0.0/lib_serialization.html?cp=4_0_0_3_33).
The C/C++ libraries can be interfaced with directly, but are also provided as higher-level bindings that ease development at the cost of reduced control (acceptable in most cases):
......@@ -22,13 +22,13 @@ Now that you have successfully built and installed `pc-ble-driver`, you are read
$ cd pc-ble-driver/
$ ls build/
> libpc_ble_driver_static_sd_api_v2.a libpc_ble_driver_shared_sd_api_v2.dylib libpc_ble_driver_static_sd_api_v3.a libpc_ble_driver_shared_sd_api_v3.dylib test_uart ...
> libpc_ble_driver_static_sd_api_v2.a libpc_ble_driver_shared_sd_api_v2.dylib libpc_ble_driver_static_sd_api_v5.a libpc_ble_driver_shared_sd_api_v5.dylib test_uart ...
To quickly get the examples up and running, see [examples/README.md](https://github.com/NordicSemiconductor/pc-ble-driver/blob/master/examples/README.md).
## Architecture
![alt tag](http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.sdk5.v13.0.0/architecture_overview_serialization.svg)
![alt tag](http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.sdk5.v14.0.0/architecture_overview_serialization.svg)
Where the 'Application chip' is just generic hardware (i.e. a Windows, OS X or Linux device), although it could also be an Arduino or Raspberry Pi for example.
......
......@@ -55,7 +55,7 @@ set(Boost_USE_STATIC_LIBS ON)
find_package ( Boost 1.54.0 REQUIRED COMPONENTS thread system regex date_time chrono )
# Add or remove SD API versions here
set(SD_API_VER_NUMS 2 3)
set(SD_API_VER_NUMS 2 5)
list(LENGTH SD_API_VER_NUMS SD_API_VER_COUNT)
set(SD_API_VER_PREFIX "SD_API_V")
......@@ -79,7 +79,7 @@ set(SD_API_VER_COMPILER_DEF "NRF_SD_BLE_API_VERSION")
#MESSAGE( STATUS "list1: " "${SD_API_VER_NUMS}" )
#MESSAGE( STATUS "list2: " "${SD_API_VERS}" )
#MESSAGE( STATUS "proj2: " "${PC_BLE_DRIVER_SD_API_V2_PROJECT_NAME}" )
#MESSAGE( STATUS "proj3: " "${PC_BLE_DRIVER_SD_API_V3_PROJECT_NAME}" )
#MESSAGE( STATUS "proj5: " "${PC_BLE_DRIVER_SD_API_V5_PROJECT_NAME}" )
# pc-ble-driver root folder
set(PC_BLE_DRIVER_ROOT_DIR ${CMAKE_CURRENT_LIST_DIR}/..)
......
......@@ -18,9 +18,9 @@ Note: this step depends on your operating system [as documented here](https://gi
If everything went well, you should see:
$ ls pc-ble-driver/examples/heart_rate_monitor/build/
> hrm_v2 hrm_v3 ...
> hrm_v2 hrm_v5 ...
Where `hrm_v2` and `hrm_v3` are the executables you will run.
Where `hrm_v2` and `hrm_v5` are the executables you will run.
#### Running
......
......@@ -23,26 +23,27 @@ include_directories (
if(MSVC)
add_definitions(-DPC_BLE_DRIVER_STATIC)
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
endif()
# Build executable
add_executable(hrc_v2 main.c)
add_executable(hrc_v3 main.c)
add_executable(hrc_v5 main.c)
target_compile_definitions(hrc_v2 PRIVATE -DNRF_SD_BLE_API=2)
target_compile_definitions(hrc_v3 PRIVATE -DNRF_SD_BLE_API=3)
target_compile_definitions(hrc_v5 PRIVATE -DNRF_SD_BLE_API=5)
target_include_directories(hrc_v2 PRIVATE ../../src/sd_api_v2/sdk/components/softdevice/s132/headers)
target_include_directories(hrc_v3 PRIVATE ../../src/sd_api_v3/sdk/components/softdevice/s132/headers)
target_include_directories(hrc_v5 PRIVATE ../../src/sd_api_v5/sdk/components/softdevice/s132/headers)
# Specify libraries to link with
if(MSVC)
target_link_libraries(hrc_v3 PRIVATE pc_ble_driver_static_sd_api_v3)
target_link_libraries(hrc_v2 PRIVATE pc_ble_driver_static_sd_api_v2)
target_link_libraries(hrc_v5 PRIVATE pc_ble_driver_static_sd_api_v5)
else()
target_link_libraries(hrc_v2 PRIVATE pc_ble_driver_shared_sd_api_v2)
target_link_libraries(hrc_v3 PRIVATE pc_ble_driver_shared_sd_api_v3)
target_link_libraries(hrc_v5 PRIVATE pc_ble_driver_shared_sd_api_v5)
endif()
target_link_libraries(hrc_v2 PRIVATE ${Boost_LIBRARIES})
target_link_libraries(hrc_v3 PRIVATE ${Boost_LIBRARIES})
target_link_libraries(hrc_v5 PRIVATE ${Boost_LIBRARIES})
......@@ -26,16 +26,18 @@
#include <string.h>
#ifdef _WIN32
#define UART_PORT_NAME "COM1"
#define DEFAULT_UART_PORT_NAME "COM1"
#define DEFAULT_BAUD_RATE 1000000 /**< The baud rate to be used for serial communication with nRF5 device. */
#endif
#ifdef __APPLE__
#define UART_PORT_NAME "/dev/tty.usbmodem00000"
#define DEFAULT_UART_PORT_NAME "/dev/tty.usbmodem00000"
#define DEFAULT_BAUD_RATE 115200 /* 1M baud rate is not supported on MacOS */
#endif
#ifdef __linux__
#define UART_PORT_NAME "/dev/ttyACM0"
#define DEFAULT_UART_PORT_NAME "/dev/ttyACM0"
#define DEFAULT_BAUD_RATE 1000000
#endif
#define BAUD_RATE 115200 /**< The baud rate to be used for serial communication with nRF5 device. */
enum
{
......@@ -79,6 +81,7 @@ static uint16_t m_hrm_char_handle = 0;
static uint16_t m_hrm_cccd_handle = 0;
static bool m_connection_is_in_progress = false;
static adapter_t * m_adapter = NULL;
static uint32_t m_config_id = 1;
static const ble_gap_scan_params_t m_scan_param =
{
......@@ -203,8 +206,11 @@ static void on_adv_report(const ble_gap_evt_t * const p_ble_gap_evt)
err_code = sd_ble_gap_connect(m_adapter,
&(p_ble_gap_evt->params.adv_report.peer_addr),
&m_scan_param,
&m_connection_param);
&m_connection_param
#if NRF_SD_BLE_API >= 5
, m_config_id
#endif
);
if (err_code != NRF_SUCCESS)
{
printf("Connection Request Failed, reason %d\n", err_code);
......@@ -427,8 +433,14 @@ static void on_conn_params_update_request(const ble_gap_evt_t * const p_ble_gap_
*/
static void on_exchange_mtu_request(const ble_gatts_evt_t * const p_ble_gatts_evt)
{
uint32_t err_code = sd_ble_gatts_exchange_mtu_reply(m_adapter, m_connection_handle,
GATT_MTU_SIZE_DEFAULT);
uint32_t err_code = sd_ble_gatts_exchange_mtu_reply(
m_adapter,
m_connection_handle,
#if NRF_SD_BLE_API < 5
GATT_MTU_SIZE_DEFAULT);
#else
BLE_GATT_ATT_MTU_DEFAULT);
#endif
if (err_code != NRF_SUCCESS)
{
......@@ -458,13 +470,13 @@ static void on_exchange_mtu_response(const ble_gattc_evt_t * const p_ble_gattc_e
*
* @return The new transport adapter.
*/
static adapter_t * adapter_init(char * serial_port)
static adapter_t * adapter_init(char * serial_port, uint32_t baud_rate)
{
physical_layer_t * phy;
data_link_layer_t * data_link_layer;
transport_layer_t * transport_layer;
phy = sd_rpc_physical_layer_create_uart(serial_port, BAUD_RATE, SD_RPC_FLOW_CONTROL_NONE,
phy = sd_rpc_physical_layer_create_uart(serial_port, baud_rate, SD_RPC_FLOW_CONTROL_NONE,
SD_RPC_PARITY_NONE);
data_link_layer = sd_rpc_data_link_layer_create_bt_three_wire(phy, 100);
transport_layer = sd_rpc_transport_layer_create(data_link_layer, 100);
......@@ -579,14 +591,16 @@ static bool find_adv_name(const ble_gap_evt_adv_report_t *p_adv_report, const ch
static uint32_t ble_stack_init()
{
uint32_t err_code;
ble_enable_params_t ble_enable_params;
uint32_t * app_ram_base = NULL;
#if NRF_SD_BLE_API <= 3
ble_enable_params_t ble_enable_params;
memset(&ble_enable_params, 0, sizeof(ble_enable_params));
#endif
#if NRF_SD_BLE_API >= 3
#if NRF_SD_BLE_API == 3
ble_enable_params.gatt_enable_params.att_mtu = GATT_MTU_SIZE_DEFAULT;
#endif
#elif NRF_SD_BLE_API < 3
ble_enable_params.gatts_enable_params.attr_tab_size = BLE_GATTS_ATTR_TAB_SIZE_DEFAULT;
ble_enable_params.gatts_enable_params.service_changed = false;
ble_enable_params.gap_enable_params.periph_conn_count = 1;
......@@ -594,8 +608,13 @@ static uint32_t ble_stack_init()
ble_enable_params.gap_enable_params.central_sec_count = 1;
ble_enable_params.common_enable_params.p_conn_bw_counts = NULL;
ble_enable_params.common_enable_params.vs_uuid_count = 1;
#endif
#if NRF_SD_BLE_API <= 3
err_code = sd_ble_enable(m_adapter, &ble_enable_params, app_ram_base);
#else
err_code = sd_ble_enable(m_adapter, app_ram_base);
#endif
switch (err_code) {
case NRF_SUCCESS:
......@@ -619,6 +638,7 @@ static uint32_t ble_stack_init()
*/
static uint32_t ble_options_set()
{
#if NRF_SD_BLE_API <= 3
ble_opt_t opt;
ble_common_opt_t common_opt;
......@@ -628,7 +648,47 @@ static uint32_t ble_options_set()
opt.common_opt = common_opt;
return sd_ble_opt_set(m_adapter, BLE_COMMON_OPT_CONN_BW, &opt);
#else
return NRF_ERROR_NOT_SUPPORTED;
#endif
}
#if NRF_SD_BLE_API >= 5
uint32_t ble_cfg_set(uint8_t conn_cfg_tag)
{
const uint32_t ram_start = 0; // Value is not used by ble-driver
uint32_t error_code;
ble_cfg_t ble_cfg;
// Configure the connection roles.
memset(&ble_cfg, 0, sizeof(ble_cfg));
ble_cfg.gap_cfg.role_count_cfg.periph_role_count = 1;
ble_cfg.gap_cfg.role_count_cfg.central_role_count = 1;
ble_cfg.gap_cfg.role_count_cfg.central_sec_count = 1;
error_code = sd_ble_cfg_set(m_adapter, BLE_GAP_CFG_ROLE_COUNT, &ble_cfg, ram_start);
if (error_code != NRF_SUCCESS)
{
printf("sd_ble_cfg_set() failed when attempting to set BLE_GAP_CFG_ROLE_COUNT. Error code: 0x%02X\n", error_code);
fflush(stdout);
return error_code;
}
memset(&ble_cfg, 0x00, sizeof(ble_cfg));
ble_cfg.conn_cfg.conn_cfg_tag = conn_cfg_tag;
ble_cfg.conn_cfg.params.gatt_conn_cfg.att_mtu = 150;
error_code = sd_ble_cfg_set(m_adapter, BLE_CONN_CFG_GATT, &ble_cfg, ram_start);
if (error_code != NRF_SUCCESS)
{
printf("sd_ble_cfg_set() failed when attempting to set BLE_CONN_CFG_GATT. Error code: 0x%02X\n", error_code);
fflush(stdout);
return error_code;
}
return NRF_SUCCESS;
}
#endif
/**@brief Start scanning (GAP Discovery procedure, Observer Procedure).
* *
......@@ -835,27 +895,42 @@ static void ble_evt_dispatch(adapter_t * adapter, ble_evt_t * p_ble_evt)
/**@brief Function for application main entry.
*
* @param[in] argc Number of arguments (program expects 0 or 1 arguments).
* @param[in] argv The serial port of the target nRF5 device (Optional).
* @param[in] argv The serial port and baud rate of the target nRF5 device (Optional).
*/
int main(int argc, char * argv[])
{
uint32_t error_code;
char * serial_port;
char * serial_port = DEFAULT_UART_PORT_NAME;
uint32_t baud_rate = DEFAULT_BAUD_RATE;
uint8_t cccd_value = 0;
if (argc > 1)
if (argc > 2)
{
serial_port = argv[1];
if (strcmp(argv[2], "1000000") == 0)
{
baud_rate = 1000000;
}
else if (strcmp(argv[2], "115200") == 0)
{
baud_rate = 115200;
}
else
{
printf("Supported baud rate values are: 115200, 1000000\n");
fflush(stdout);
}
}
else
if (argc > 1)
{
serial_port = UART_PORT_NAME;
serial_port = argv[1];
}
printf("Serial port used: %s\n", serial_port);
printf("Baud rate used: %d\n", baud_rate);
fflush(stdout);
m_adapter = adapter_init(serial_port);
m_adapter = adapter_init(serial_port, baud_rate);
sd_rpc_log_handler_severity_filter_set(m_adapter, SD_RPC_LOG_INFO);
error_code = sd_rpc_open(m_adapter, status_handler, ble_evt_dispatch, log_handler);
......@@ -866,6 +941,10 @@ int main(int argc, char * argv[])
return error_code;
}
#if NRF_SD_BLE_API >= 5
ble_cfg_set(m_config_id);
#endif
error_code = ble_stack_init();
if (error_code != NRF_SUCCESS)
......@@ -873,13 +952,15 @@ int main(int argc, char * argv[])
return error_code;
}
#if NRF_SD_BLE_API < 5
error_code = ble_options_set();
if (error_code != NRF_SUCCESS)
{
return error_code;
}
#endif
error_code = scan_start();
if (error_code != NRF_SUCCESS)
......
......@@ -5,7 +5,7 @@ set(Boost_USE_MULTITHREADED ON)
# Use static boost libraries so the dynamic library
# can run anywhere
set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_STATIC_LIBS ON)
# Find the necessary boost components on the system.
# Minimum version required is 1.54.0
......@@ -23,26 +23,27 @@ include_directories (
if(MSVC)
add_definitions(-DPC_BLE_DRIVER_STATIC)
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
endif()
# Build executable
add_executable(hrm_v2 main.c)
add_executable(hrm_v3 main.c)
add_executable(hrm_v5 main.c)
target_compile_definitions(hrm_v2 PRIVATE -DNRF_SD_BLE_API=2)
target_compile_definitions(hrm_v3 PRIVATE -DNRF_SD_BLE_API=3)
target_compile_definitions(hrm_v5 PRIVATE -DNRF_SD_BLE_API=5)
target_include_directories(hrm_v2 PRIVATE ../../src/sd_api_v2/sdk/components/softdevice/s132/headers)
target_include_directories(hrm_v3 PRIVATE ../../src/sd_api_v3/sdk/components/softdevice/s132/headers)
target_include_directories(hrm_v5 PRIVATE ../../src/sd_api_v5/sdk/components/softdevice/s132/headers)
# Specify libraries to link with
if (MSVC)
target_link_libraries(hrm_v3 PRIVATE pc_ble_driver_static_sd_api_v3)
target_link_libraries(hrm_v2 PRIVATE pc_ble_driver_static_sd_api_v2)
else()
target_link_libraries(hrm_v5 PRIVATE pc_ble_driver_static_sd_api_v5)
else()
target_link_libraries(hrm_v2 PRIVATE pc_ble_driver_shared_sd_api_v2)
target_link_libraries(hrm_v3 PRIVATE pc_ble_driver_shared_sd_api_v3)
target_link_libraries(hrm_v5 PRIVATE pc_ble_driver_shared_sd_api_v5)
endif()
target_link_libraries(hrm_v2 PRIVATE ${Boost_LIBRARIES})
target_link_libraries(hrm_v3 PRIVATE ${Boost_LIBRARIES})
target_link_libraries(hrm_v5 PRIVATE ${Boost_LIBRARIES})
......@@ -34,23 +34,28 @@
#endif
#ifdef _WIN32
#define UART_PORT_NAME "COM1"
#define DEFAULT_UART_PORT_NAME "COM1"
#define DEFAULT_BAUD_RATE 1000000 /**< The baud rate to be used for serial communication with nRF5 device. */
#endif
#ifdef __APPLE__
#define UART_PORT_NAME "/dev/tty.usbmodem00000"
#define DEFAULT_UART_PORT_NAME "/dev/tty.usbmodem00000"
#define DEFAULT_BAUD_RATE 115200 /* 1M baud rate is not supported on MacOS */
#endif
#ifdef __linux__
#define UART_PORT_NAME "/dev/ttyACM0"
#define DEFAULT_UART_PORT_NAME "/dev/ttyACM0"
#define DEFAULT_BAUD_RATE 1000000
#endif
#define BAUD_RATE 115200 /**< The baud rate to be used for serial communication with nRF5 device. */
#define ADVERTISING_INTERVAL_40_MS 64 /**< 0.625 ms = 40 ms */
#define ADVERTISING_TIMEOUT_3_MIN 180 /**< 1 sec = 3 min */
#define OPCODE_LENGTH 1 /**< Length of opcode inside Heart Rate Measurement packet. */
#define HANDLE_LENGTH 2 /**< Length of handle inside Heart Rate Measurement packet. */
#if NRF_SD_BLE_API <= 3
#define MAX_HRM_LEN (BLE_L2CAP_MTU_DEF - OPCODE_LENGTH - HANDLE_LENGTH) /**< Maximum size of a transmitted Heart Rate Measurement. */
#else
#define MAX_HRM_LEN (BLE_EVT_LEN_MAX(GATT_MTU_SIZE_DEFAULT) - OPCODE_LENGTH - HANDLE_LENGTH)
#endif
#define BLE_UUID_HEART_RATE_SERVICE 0x180D /**< Heart Rate service UUID. */
#define BLE_UUID_HEART_RATE_MEASUREMENT_CHAR 0x2A37 /**< Heart Rate Measurement characteristic UUID. */
......@@ -62,6 +67,10 @@
#define BUFFER_SIZE 30 /**< Sufficiently large buffer for the advertising data. */
#define DEVICE_NAME "Nordic_HRM" /**< Name device advertises as over Bluetooth. */
#ifndef GATT_MTU_SIZE_DEFAULT
#define GATT_MTU_SIZE_DEFAULT BLE_GATT_ATT_MTU_DEFAULT
#endif
static uint16_t m_connection_handle = BLE_CONN_HANDLE_INVALID;
static uint16_t m_heart_rate_service_handle = 0;
static ble_gatts_char_handles_t m_heart_rate_measurement_handle;
......@@ -69,6 +78,7 @@ static uint8_t m_heart_rate = HEART_RATE_BAS
static bool m_send_notifications = false;
static bool m_advertisement_timed_out = false;
static adapter_t * m_adapter = NULL;
static uint32_t m_config_id = 1;
static uint32_t advertising_start();
......@@ -197,7 +207,11 @@ static void ble_evt_dispatch(adapter_t * adapter, ble_evt_t * p_ble_evt)
break;
#endif
#if NRF_SD_BLE_API <= 3
case BLE_EVT_TX_COMPLETE:
#else
case BLE_GATTS_EVT_HVN_TX_COMPLETE:
#endif
#ifdef DEBUG
printf("Successfully transmitted a heart rate reading.");
fflush(stdout);
......@@ -217,13 +231,13 @@ static void ble_evt_dispatch(adapter_t * adapter, ble_evt_t * p_ble_evt)
*
* @return The new transport adapter.
*/
static adapter_t * adapter_init(char * serial_port)
static adapter_t * adapter_init(char * serial_port, uint32_t baud_rate)
{
physical_layer_t * phy;
data_link_layer_t * data_link_layer;
transport_layer_t * transport_layer;
phy = sd_rpc_physical_layer_create_uart(serial_port, BAUD_RATE, SD_RPC_FLOW_CONTROL_NONE,
phy = sd_rpc_physical_layer_create_uart(serial_port, baud_rate, SD_RPC_FLOW_CONTROL_NONE,
SD_RPC_PARITY_NONE);
data_link_layer = sd_rpc_data_link_layer_create_bt_three_wire(phy, 100);
transport_layer = sd_rpc_transport_layer_create(data_link_layer, 100);
......@@ -237,37 +251,84 @@ static adapter_t * adapter_init(char * serial_port)
static uint32_t ble_stack_init()
{
uint32_t err_code;
ble_enable_params_t ble_enable_params;
uint32_t * app_ram_base = NULL;
#if NRF_SD_BLE_API <= 3
ble_enable_params_t ble_enable_params;
memset(&ble_enable_params, 0, sizeof(ble_enable_params));
#endif
ble_enable_params.gatts_enable_params.attr_tab_size = BLE_GATTS_ATTR_TAB_SIZE_DEFAULT;
ble_enable_params.gatts_enable_params.service_changed = false;
ble_enable_params.gap_enable_params.periph_conn_count = 1;
ble_enable_params.gap_enable_params.central_conn_count = 0;
ble_enable_params.gap_enable_params.central_sec_count = 0;
#if NRF_SD_BLE_API == 3
ble_enable_params.gatt_enable_params.att_mtu = GATT_MTU_SIZE_DEFAULT;
#elif NRF_SD_BLE_API < 3
ble_enable_params.gatts_enable_params.attr_tab_size = BLE_GATTS_ATTR_TAB_SIZE_DEFAULT;
ble_enable_params.gatts_enable_params.service_changed = false;
ble_enable_params.gap_enable_params.periph_conn_count = 1;
ble_enable_params.gap_enable_params.central_conn_count = 0;
ble_enable_params.gap_enable_params.central_sec_count = 0;
ble_enable_params.common_enable_params.p_conn_bw_counts = NULL;
ble_enable_params.common_enable_params.vs_uuid_count = 1;
ble_enable_params.common_enable_params.vs_uuid_count = 1;
#endif
#if NRF_SD_BLE_API <= 3
err_code = sd_ble_enable(m_adapter, &ble_enable_params, app_ram_base);
#else
err_code = sd_ble_enable(m_adapter, app_ram_base);
#endif
switch (err_code) {
case NRF_SUCCESS:
break;
case NRF_ERROR_INVALID_STATE:
printf("BLE stack already enabled\n");
fflush(stdout);
break;
default:
printf("Failed to enable BLE stack. Error code: %d\n", err_code);
fflush(stdout);
break;
case NRF_SUCCESS:
break;
case NRF_ERROR_INVALID_STATE:
printf("BLE stack already enabled\n");
fflush(stdout);
break;
default:
printf("Failed to enable BLE stack. Error code: %d\n", err_code);
fflush(stdout);
break;
}
return err_code;
}
#if NRF_SD_BLE_API >= 5
uint32_t ble_cfg_set(uint8_t conn_cfg_tag)
{
const uint32_t ram_start = 0; // Value is not used by ble-driver
uint32_t error_code;
ble_cfg_t ble_cfg;
// Configure the connection roles.
memset(&ble_cfg, 0, sizeof(ble_cfg));
ble_cfg.gap_cfg.role_count_cfg.periph_role_count = 1;
ble_cfg.gap_cfg.role_count_cfg.central_role_count = 1;
ble_cfg.gap_cfg.role_count_cfg.central_sec_count = 1;
error_code = sd_ble_cfg_set(m_adapter, BLE_GAP_CFG_ROLE_COUNT, &ble_cfg, ram_start);
if (error_code != NRF_SUCCESS)
{
printf("sd_ble_cfg_set() failed when attempting to set BLE_GAP_CFG_ROLE_COUNT. Error code: 0x%02X\n", error_code);
fflush(stdout);
return error_code;
}
memset(&ble_cfg, 0x00, sizeof(ble_cfg));
ble_cfg.conn_cfg.conn_cfg_tag = conn_cfg_tag;
ble_cfg.conn_cfg.params.gatt_conn_cfg.att_mtu = 150;
error_code = sd_ble_cfg_set(m_adapter, BLE_CONN_CFG_GATT, &ble_cfg, ram_start);
if (error_code != NRF_SUCCESS)
{
printf("sd_ble_cfg_set() failed when attempting to set BLE_CONN_CFG_GATT. Error code: 0x%02X\n", error_code);
fflush(stdout);
return error_code;
}
return NRF_SUCCESS;
}
#endif
/**@brief Function for setting the advertisement data.
*
* @details Sets the full device name and its available BLE services in the advertisement data.
......@@ -281,7 +342,7 @@ static uint32_t advertisement_data_set()
uint8_t data_buffer[BUFFER_SIZE];
const char * device_name = DEVICE_NAME;
const uint8_t name_length = strlen(device_name);
const uint8_t name_length = (uint8_t)strlen(device_name);
const uint8_t data_type = BLE_GAP_AD_TYPE_COMPLETE_LOCAL_NAME;
// Set the device name.
......@@ -333,7 +394,11 @@ static uint32_t advertising_start()
adv_params.p_whitelist = NULL;
#endif
#if NRF_SD_BLE_API <= 3
error_code = sd_ble_gap_adv_start(m_adapter, &adv_params);
#else
error_code = sd_ble_gap_adv_start(m_adapter, &adv_params, BLE_CONN_CFG_TAG_DEFAULT);
#endif
if (error_code != NRF_SUCCESS)
{
......@@ -524,26 +589,42 @@ static uint32_t heart_rate_measurement_send()
/**@brief Function for application main entry.
*
* @param[in] argc Number of arguments (program expects 0 or 1 arguments).
* @param[in] argv The serial port of the target nRF5 device (Optional).
* @param[in] argv The serial port and baud rate of the target nRF5 device (Optional).
*/
int main(int argc, char * argv[])
{
uint32_t error_code;
char * serial_port;
char * serial_port = DEFAULT_UART_PORT_NAME;
uint32_t baud_rate = DEFAULT_BAUD_RATE;
uint8_t cccd_value = 0;