Skip to content

Commit

Permalink
added initial test files
Browse files Browse the repository at this point in the history
  • Loading branch information
vChavezB committed Apr 12, 2024
1 parent 88604b6 commit 183a29a
Show file tree
Hide file tree
Showing 12 changed files with 688 additions and 34 deletions.
33 changes: 10 additions & 23 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ jobs:
env:
CMAKE_PREFIX_PATH: /opt/toolchains
ZEPHYR_VERSION: 3.6.0
BOARD: nrf52840dk_nrf52840
steps:
- name: Checkout
uses: actions/checkout@v4
Expand All @@ -21,30 +22,16 @@ jobs:
west init --mr v$ZEPHYR_VERSION
west update -o=--depth=1 -n
- name: Build
- name: Build Uptime Sample
working-directory: /tmp/
run: |
west build $GITHUB_WORKSPACE/samples/uptime -b native_posix_64 --build-dir $GITHUB_WORKSPACE/build
- name: check build
run: |
ls
- name : Upload
uses: actions/upload-artifact@v4
with:
name: posix-build
path: |
build/zephyr/zephyr.exe
test:
needs: build
runs-on: ubuntu-22.04
steps:
- name: Dependencies
run: |
python3 -m pip install bumble==0.0.190
- name: Checkout
uses: actions/checkout@v4
- name: Run Test
west build $GITHUB_WORKSPACE/samples/uptime -b $BOARD --build-dir $GITHUB_WORKSPACE/build_uptime
- name: Build Uptime Sample
working-directory: /tmp/
run: |
python3 test/bumble/controllers.py tcp-server:_:9000 tcp-server:_:9001 &
sleep 5
west build $GITHUB_WORKSPACE/test/renode/uptime_central -b $BOARD --build-dir $GITHUB_WORKSPACE/build_central
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
build*
*.pyc
*.idea
11 changes: 0 additions & 11 deletions samples/uptime/src/uptime_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,7 @@
namespace uptime
{

namespace uuid
{
static constexpr bt_uuid_128 svc_base = ble_utils::uuid::uuid128_init(0xABCD0000,
0x1234,
0x5678,
0x9ABC,
0xDEF012345678);

static constexpr bt_uuid_128 char_basic = ble_utils::uuid::derive_uuid(svc_base,0x0001);
static constexpr bt_uuid_128 char_notify = ble_utils::uuid::derive_uuid(svc_base,0x0002);
static constexpr bt_uuid_128 char_indicate = ble_utils::uuid::derive_uuid(svc_base,0x0003);
}

namespace characteristic
{
Expand Down
13 changes: 13 additions & 0 deletions samples/uptime/src/uptime_service.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,19 @@
namespace uptime
{

namespace uuid
{
static constexpr bt_uuid_128 svc_base = ble_utils::uuid::uuid128_init(0xABCD0000,
0x1234,
0x5678,
0x9ABC,
0xDEF012345678);

static constexpr bt_uuid_128 char_basic = ble_utils::uuid::derive_uuid(svc_base,0x0001);
static constexpr bt_uuid_128 char_notify = ble_utils::uuid::derive_uuid(svc_base,0x0002);
static constexpr bt_uuid_128 char_indicate = ble_utils::uuid::derive_uuid(svc_base,0x0003);
}

namespace characteristic
{

Expand Down
124 changes: 124 additions & 0 deletions test/bumble/scan.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
import asyncio
import os
import logging

import bumble
import click

from bumble.colors import color
from bumble.device import Device
from bumble.transport import open_transport_or_link
from bumble.keys import JsonKeyStore
from bumble.smp import AddressResolver
from bumble.device import Advertisement
from bumble.hci import Address, HCI_Constant, HCI_LE_1M_PHY, HCI_LE_CODED_PHY


adv_queue = asyncio.Queue()

class AdvertisementPrinter:
def __init__(self, resolver):
self.resolver = resolver
def on_advertisement(self, advertisement):
print("Found advertisement ", advertisement.address)
asyncio.run_coroutine_threadsafe(adv_queue.put(advertisement), asyncio.get_event_loop())
def on_advertising_report(self, report):
pass



TRANSPORT = "tcp-client:localhost:8001"


async def check_connection(device: bumble.device):
"""
Task to send carl data to the M2B cloud
:return:
"""
try:
message = await asyncio.wait_for(adv_queue.get(), timeout=5.0)
await device.connect(message.address)
print("Connected")
except asyncio.TimeoutError:
print("No BLE Devices found")


async def scan(
passive,
scan_interval,
scan_window,
phy,
filter_duplicates
):
async with await open_transport_or_link(TRANSPORT) as (hci_source, hci_sink):
device = Device.with_hci(
'Bumble', 'F0:F1:F2:F3:F4:F5', hci_source, hci_sink
)

await device.power_on()
resolving_keys = []

resolver = AddressResolver(resolving_keys) if resolving_keys else None

printer = AdvertisementPrinter(resolver)

device.on('advertisement', printer.on_advertisement)

if phy is None:
scanning_phys = [HCI_LE_1M_PHY, HCI_LE_CODED_PHY]
else:
scanning_phys = [{'1m': HCI_LE_1M_PHY, 'coded': HCI_LE_CODED_PHY}[phy]]

await device.start_scanning(
active=(not passive),
scan_interval=scan_interval,
scan_window=scan_window,
filter_duplicates=filter_duplicates,
scanning_phys=scanning_phys,
)

check_task = asyncio.create_task(check_connection(device))
await asyncio.gather(check_task)

await hci_source.wait_for_termination()


# -----------------------------------------------------------------------------
@click.command()
@click.option('--min-rssi', type=int, help='Minimum RSSI value')
@click.option('--passive', is_flag=True, default=False, help='Perform passive scanning')
@click.option('--scan-interval', type=int, default=60, help='Scan interval')
@click.option('--scan-window', type=int, default=60, help='Scan window')
@click.option(
'--phy', type=click.Choice(['1m', 'coded']), help='Only scan on the specified PHY'
)
@click.option(
'--filter-duplicates',
type=bool,
default=True,
help='Filter duplicates at the controller level',
)

def main(
min_rssi,
passive,
scan_interval,
scan_window,
phy,
filter_duplicates
):
logging.basicConfig(level=os.environ.get('BUMBLE_LOGLEVEL', 'WARNING').upper())
asyncio.run(
scan(
passive,
scan_interval,
scan_window,
phy,
filter_duplicates
)
)


# -----------------------------------------------------------------------------
if __name__ == '__main__':
main()
1 change: 1 addition & 0 deletions test/renode/tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- uptime_test.robot
14 changes: 14 additions & 0 deletions test/renode/uptime_central/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Copyright (c) 2024 Victor Chavez
# SPDX-License-Identifier: Apache-2.0

cmake_minimum_required(VERSION 3.20.0)
set(ZEPHYR_EXTRA_MODULES ${CMAKE_CURRENT_SOURCE_DIR}/ble_utils)

find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(uptime_central)
set(ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../..)
target_sources(app PRIVATE src/main.cpp
src/discovery.cpp)

target_include_directories(app PRIVATE ${ROOT_DIR}/samples/uptime/src
${ROOT_DIR}/include)
22 changes: 22 additions & 0 deletions test/renode/uptime_central/prj.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright (c) 2024 Victor Chavez
# SPDX-License-Identifier: Apache-2.0
#---------
#C++
#----------
CONFIG_CPLUSPLUS=y
CONFIG_LIB_CPLUSPLUS=y
CONFIG_STD_CPP17=y
CONFIG_NEWLIB_LIBC=y
CONFIG_UART_CONSOLE=y
CONFIG_BLE_UTILS=y
CONFIG_CBPRINTF_FP_SUPPORT=y
CONFIG_BT_ASSERT=n

CONFIG_BT=y
CONFIG_LOG=y
CONFIG_BT_CENTRAL=y
CONFIG_BT_SMP=y
CONFIG_BT_GATT_CLIENT=y
#increase mtu for sensor data notification
CONFIG_BT_L2CAP_TX_MTU=600
CONFIG_BT_BUF_ACL_RX_SIZE=600
Loading

0 comments on commit 183a29a

Please sign in to comment.