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 all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Binary file added .DS_Store
Binary file not shown.
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"files.associations": {
"kernel.h": "c"
}
}
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)
53 changes: 26 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,26 @@
# 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.
# Updates Made
- Removed functionality unrelated to interview questions
- Tested project using Adafruit ItsyBitsy, nRF Connect BLE Desktop, & nRF Connect Mobile
- Monitored printk messages using screen command, wrote output to connection_log.txt
## Application Description
This application supports up to two simultaneous BLE connections. It will only connect to devices being advertised as either "DXC" or "Jacobs IPhone". Connections are managed using a struct bt_conn array. Scan scheduling is done using a delayable work item. It can support more than two connections if CONFIG_BT_MAX_CONN is increased, but has not been tested for more than 2.
## Q1 Implementation
- bt_data_parse() is called in device_found()
- the callback function, find_device_name(), checks if the device name is a match, and initiates a connection if so
- is_device_connected() is also called inside of find_device_name() to ensure a connection isn't attempted to an already connected device
## Q2 Implmentation
- struct array "connections" of type bt_conn manages connections
- global variable conn_count keeps track of # of connections
- bt_le_conn_creat adds connections to connections array
- connected() function increments count
- disconnected() function removes connections and decrements count
## Scanning
Scanning is managed by scheduling a work item with a handler that calls start_scan(). If a connection is made and conn_count is less than 2, another scan will be scheduled. If max connection count (2) is reached, a new scan will not be initiated. If a device is disconnected and a scan is not active, another scan will be scheduled. Global variable scan_active is used to check if scan is currently active.
## Testing
I used nRF Connect Mobile to advertise a BLE device named "Jacobs IPhone" and my laptop with a dongle and nRF Connect BLE Desktop to advertise BLE device "DXC". Printk messages are spread throughout main.c. I monitored these by connecting to the ItsyBitsy's serial port and wrote the output to file (see connection_log.txt).
### Files Updated
- main.c
- prj.conf
- build folder
### Files Added
- connection_log.txt
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