Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Central Update #1

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
11 changes: 11 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# SPDX-License-Identifier: Apache-2.0

cmake_minimum_required(VERSION 3.20.0)
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(central)

target_sources(app PRIVATE
src/main.c
)

zephyr_library_include_directories(${ZEPHYR_BASE}/samples/bluetooth)
81 changes: 54 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,54 @@
# Stel Interview Question

## Instruction for Setup

For detailed instructions on setting up the environment, please refer to the [Nordic Semiconductor documentation](https://docs.nordicsemi.com/bundle/ncs-latest/page/nrf/installation/install_ncs.html).

## Project Sample

> **Note:** If you want to compile the project, feel free to use any nRF52 boards. You don't need to load the firmware to the device.

You can find the project sample at the following path: `zephyr/samples/bluetooth/central`.

## Questions

### Q1: Filter Device by Name in `device_found` Function

In the `device_found` function, filter the connecting device based on its name. Example: Device with name `DXC`. Please update the `device_found` function using the `bt_data_parse` API to filter by `type: BT_DATA_NAME_COMPLETE`.

### Q2: Support for Multiple Device Connections

The current application only supports a single device connection. Please propose an idea for adding support for multiple device connections and add changes to the current central app.

> **Note:** This is only an interview project. You don't really need to make it work properly. We are able to understand your ideas :)

## Submission

Please create a branch based on your name and submit the central app you changed.
bt_data_parse accepts three parameters: a buffer of the ad data, a callback function, and a pointer where the parsed data of interest can be stored.

Line 52 and 53 of main.c define the character array that will be used to store the parsed data. The variable decays to a pointer to the first element of the array when passed to bt_data_parse.

bt_data_parse calls find_device_name repeated until false is returns. False indicates the device name has been found and parsing can stop.

Device name is printed using printk.

## Q2 - Implementation Summary

Support for multiple devices is effectively managed by utilizing 3 global variables.
```c
static struct bt_conn *conn_connecting = NULL;
static uint8_t volatile conn_count;
static bool volatile is_connecting = false;
```
bt_conn is the major data structure used in Zephyr's Bluetooth stack that keeps track of a connected device's important information. It is passed to bt_conn_le_create, which creates the connection and adds it to a list of connected devices.
```c
bt_conn_le_create(addr, BT_CONN_LE_CREATE_CONN,
BT_LE_CONN_PARAM_DEFAULT, &conn_connecting);
```
In the connected function, is_connecting is set back to false, conn_connecting is set back to NULL and conn_count is incremented. Similar logic is used in disconnected callback function.
```c
is_connecting = false;
conn_connecting = NULL;
conn_count++;
```
Main enters an infinite while loop after initiating the first scan. The while loop will check to see if a new scan should be initiated and intermittently yield CPU.
```c
k_sleep(K_MSEC(100));

if (conn_count < CONFIG_BT_MAX_CONN && !is_connecting) {
start_scan();
}
```
## Other Functionality Implemented
- The settings subsystem was configured to store device pairing information.
- SMP was configured for additional security.
- Privacy was configured for added anonymity.
## prj.conf
- System is configured to support up to 5 simultaneous connections and remember up to 10 devices.
```
CONFIG_BT=y
CONFIG_BT_CENTRAL=y
CONFIG_BT_MAX_CONN=5
CONFIG_BT_MAX_PAIRED=10
CONFIG_BT_SMP=y
CONFIG_BT_PRIVACY=y
CONFIG_BT_SETTINGS=y
CONFIG_SETTINGS=y
CONFIG_BT_HCI=y
```
### Files Changed
main.c and prj.conf
26 changes: 26 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
.. _bluetooth_central:

Bluetooth: Central
##################

Overview
********

Application demonstrating very basic BLE Central role functionality by scanning
for other BLE devices and establishing a connection to the first one with a
strong enough signal.



Requirements
************

* BlueZ running on the host, or
* A board with BLE support

Building and Running
********************
This sample can be found under :zephyr_file:`samples/bluetooth/central` in the
Zephyr tree.

See :ref:`bluetooth samples section <bluetooth-samples>` for details.
22 changes: 22 additions & 0 deletions boards/rv32m1_vega_openisa_rv32m1_ri5cy.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright 2019 NXP
*
* SPDX-License-Identifier: Apache-2.0
*/

&lptmr1 {
interrupt-parent = <&intmux0_ch2>;
};

&intmux0_ch2 {
status = "okay";
};

&intmux0_ch3 {
status = "okay";
};

&generic_fsk {
interrupt-parent = <&intmux0_ch3>;
status = "okay";
};
94 changes: 94 additions & 0 deletions build/CMakeCache.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
# This is the CMakeCache file.
# For build in directory: /Users/jacobjunk/dev/zephyr/bt_central/build
# It was generated by CMake: /opt/nordic/ncs/toolchains/f8037e9b83/Cellar/cmake/3.21.0/bin/cmake
# You can edit this file to change values found and used by cmake.
# If you do not want to change any of the values, simply exit the editor.
# If you do want to change a value, simply edit, save, and exit the editor.
# The syntax for the file is as follows:
# KEY:TYPE=VALUE
# KEY is the name of a variable in the cache.
# TYPE is a hint to GUIs for the type of VALUE, DO NOT EDIT TYPE!.
# VALUE is the current value for the KEY.

########################
# EXTERNAL cache entries
########################

//Application Binary Directory
APPLICATION_BINARY_DIR:PATH=/Users/jacobjunk/dev/zephyr/bt_central/build

//Application Source Directory
APPLICATION_SOURCE_DIR:PATH=/Users/jacobjunk/dev/zephyr/bt_central

//Selected board
BOARD:STRING=rv32m1_vega_openisa_rv32m1_ri5cy

//No help, variable specified on the command line.
BOARD_ROOT:UNINITIALIZED=/opt/nordic/ncs/v2.7.0/zephyr/samples/bluetooth/central;/Users/jacobjunk/dev/zephyr/bt_central;/opt/nordic/ncs/v2.7.0/zephyr/samples/bluetooth/central_hr

//Path to a program.
CCACHE_FOUND:FILEPATH=/opt/nordic/ncs/toolchains/f8037e9b83/bin/ccache

//No help, variable specified on the command line.
NCS_TOOLCHAIN_VERSION:UNINITIALIZED=NONE

//No help, variable specified on the command line.
WEST_PYTHON:UNINITIALIZED=/opt/nordic/ncs/toolchains/f8037e9b83/opt/[email protected]/bin/python3.9

//Zephyr base
ZEPHYR_BASE:PATH=/opt/nordic/ncs/v2.7.0/zephyr

//The directory containing a CMake configuration file for ZephyrAppConfiguration.
ZephyrAppConfiguration_DIR:PATH=ZephyrAppConfiguration_DIR-NOTFOUND

//The directory containing a CMake configuration file for ZephyrBuildConfiguration.
ZephyrBuildConfiguration_DIR:PATH=/opt/nordic/ncs/v2.7.0/nrf/share/zephyrbuild-package/cmake

//The directory containing a CMake configuration file for Zephyr.
Zephyr_DIR:PATH=/opt/nordic/ncs/v2.7.0/zephyr/share/zephyr-package/cmake


########################
# INTERNAL cache entries
########################

//This is the directory where this CMakeCache.txt was created
CMAKE_CACHEFILE_DIR:INTERNAL=/Users/jacobjunk/dev/zephyr/bt_central/build
//Major version of cmake used to create the current loaded cache
CMAKE_CACHE_MAJOR_VERSION:INTERNAL=3
//Minor version of cmake used to create the current loaded cache
CMAKE_CACHE_MINOR_VERSION:INTERNAL=21
//Patch version of cmake used to create the current loaded cache
CMAKE_CACHE_PATCH_VERSION:INTERNAL=0
//Path to CMake executable.
CMAKE_COMMAND:INTERNAL=/opt/nordic/ncs/toolchains/f8037e9b83/Cellar/cmake/3.21.0/bin/cmake
//Path to cpack program executable.
CMAKE_CPACK_COMMAND:INTERNAL=/opt/nordic/ncs/toolchains/f8037e9b83/Cellar/cmake/3.21.0/bin/cpack
//Path to ctest program executable.
CMAKE_CTEST_COMMAND:INTERNAL=/opt/nordic/ncs/toolchains/f8037e9b83/Cellar/cmake/3.21.0/bin/ctest
//Name of external makefile project generator.
CMAKE_EXTRA_GENERATOR:INTERNAL=
//Name of generator.
CMAKE_GENERATOR:INTERNAL=Ninja
//Generator instance identifier.
CMAKE_GENERATOR_INSTANCE:INTERNAL=
//Name of generator platform.
CMAKE_GENERATOR_PLATFORM:INTERNAL=
//Name of generator toolset.
CMAKE_GENERATOR_TOOLSET:INTERNAL=
//Source directory with the top level CMakeLists.txt file for this
// project
CMAKE_HOME_DIRECTORY:INTERNAL=/Users/jacobjunk/dev/zephyr/bt_central
//number of local generators
CMAKE_NUMBER_OF_MAKEFILES:INTERNAL=1
//Path to CMake installation.
CMAKE_ROOT:INTERNAL=/opt/nordic/ncs/toolchains/f8037e9b83/Cellar/cmake/3.21.0/share/cmake
//Details about finding Python3
FIND_PACKAGE_MESSAGE_DETAILS_Python3:INTERNAL=[/opt/nordic/ncs/toolchains/f8037e9b83/opt/[email protected]/bin/python3.9][cfound components: Interpreter ][v3.9.6(3.8)]
//West
WEST:INTERNAL=/opt/nordic/ncs/toolchains/f8037e9b83/opt/[email protected]/bin/python3.9;-m;west
_Python3_EXECUTABLE:INTERNAL=/opt/nordic/ncs/toolchains/f8037e9b83/opt/[email protected]/bin/python3.9
//Python3 Properties
_Python3_INTERPRETER_PROPERTIES:INTERNAL=Python;3;9;6;64;;cpython-39-darwin;/opt/nordic/ncs/toolchains/f8037e9b83/opt/[email protected]/Frameworks/Python.framework/Versions/3.9/lib/python3.9;/opt/nordic/ncs/toolchains/f8037e9b83/opt/[email protected]/Frameworks/Python.framework/Versions/3.9/lib/python3.9;/opt/nordic/ncs/toolchains/f8037e9b83/opt/[email protected]/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages;/opt/nordic/ncs/toolchains/f8037e9b83/opt/[email protected]/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages
_Python3_INTERPRETER_SIGNATURE:INTERNAL=396ffb7fd36708041338b90b48c8cc7b

1 change: 1 addition & 0 deletions build/CMakeFiles/cmake.check_cache
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# This file is generated by cmake for dependency checking of the CMakeCache.txt file
Loading