Skip to content

Commit 9cde1de

Browse files
author
unknownconstant
committed
Merged master
2 parents c663798 + be365c9 commit 9cde1de

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+21205
-415
lines changed

.github/workflows/spell-check.yml

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
name: Spell Check
2+
23
on: [push, pull_request]
4+
35
jobs:
4-
build:
5-
runs-on: ubuntu-latest
6-
7-
steps:
8-
- uses: actions/checkout@v1
9-
with:
10-
fetch-depth: 1
11-
- uses: arduino/actions/libraries/spell-check@master
6+
build:
7+
runs-on: ubuntu-latest
8+
9+
steps:
10+
- name: Checkout
11+
uses: actions/checkout@v2
12+
13+
- name: Spell check
14+
uses: arduino/actions/libraries/spell-check@master
15+
with:
16+
skip-paths: ./extras/test

examples/Central/Scan/Scan.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Scan
33
44
This example scans for BLE peripherals and prints out their advertising details:
5-
address, local name, adverised service UUID's.
5+
address, local name, advertised service UUID's.
66
77
The circuit:
88
- Arduino MKR WiFi 1010, Arduino Uno WiFi Rev2 board, Arduino Nano 33 IoT,

examples/Central/ScanCallback/ScanCallback.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Scan Callback
33
44
This example scans for BLE peripherals and prints out their advertising details:
5-
address, local name, adverised service UUIDs. Unlike the Scan example, it uses
5+
address, local name, advertised service UUIDs. Unlike the Scan example, it uses
66
the callback style APIs and disables filtering so the peripheral discovery is
77
reported for every single advertisement it makes.
88

extras/arduino-ble-parser.py

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
'''
2+
Convert ArduinoBLE debug files into Btsnoop files ready to be analyzed using wireshark or hcidump
3+
Btsnoop file format reference
4+
https://www.fte.com/WebHelpII/Sodera/Content/Technical_Information/BT_Snoop_File_Format.htm
5+
'''
6+
7+
import os
8+
import argparse
9+
10+
DEBUG = False
11+
12+
parser = argparse.ArgumentParser()
13+
parser.add_argument('-i', dest='inputPath', type=str, required=True, help='input file containing debug log')
14+
parser.add_argument('-o', dest='outputPath', type=str, required=True, help='result file that will contain the btsnoop encoded debug file')
15+
args = parser.parse_args()
16+
17+
# Extract only hci debug messages
18+
def extractHCIDebugPrint(inputPath, outputPath):
19+
inputFile = open(inputPath, 'r')
20+
outputFile = open(outputPath, 'w')
21+
for inputLine in inputFile:
22+
lineItems = inputLine.split()
23+
if (len(lineItems) < 7) or (lineItems[1] != "->") or (lineItems[2] != "HCI"):
24+
if (len(lineItems) < 4) or (lineItems[0] != "HCI") or ((lineItems[3] != "<-") and (lineItems[3] != "->")):
25+
continue
26+
outputFile.write(inputLine)
27+
outputFile.close()
28+
29+
# Return packet in btsnoop format
30+
def buildBinaryPacket(hciMessage, hciDirection, hciType):
31+
commandFlag = 1 if (hciType == "COMMAND" or hciType == "EVENT") else 0
32+
directionFlag = 0 if (hciDirection == "TX") else 1
33+
flagHex = ("0" * 7) + str((commandFlag * 2) + directionFlag)
34+
timestampHex = "0" * 16
35+
packetDropHex = "0" * 8
36+
dataLengthHex = format( (int(len(hciMessage) / 2)), 'x')
37+
packetLengthHex = ("0" * (8 - len(dataLengthHex))) + dataLengthHex
38+
binaryPacket = bytearray.fromhex(packetLengthHex + packetLengthHex + flagHex + packetDropHex + timestampHex + hciMessage)
39+
if DEBUG:
40+
print(len(hciMessage))
41+
print(dataLengthHex)
42+
print(packetLengthHex)
43+
print(flagHex)
44+
print('\n')
45+
return binaryPacket
46+
47+
def buildBinaryHeader():
48+
defaultHeader = "6274736e6f6f700000000001000003ea"
49+
binaryHeader = bytearray.fromhex(defaultHeader)
50+
return binaryHeader
51+
52+
def convertToBtsnoop(inputPath, outputPath):
53+
# Open output file and write the Btsnoop header
54+
outputFile = open(outputPath,'wb')
55+
header = buildBinaryHeader()
56+
outputFile.write(header)
57+
58+
# Open input file containing HCI debug packets
59+
inputFile = open(inputPath, 'r')
60+
for inputLine in inputFile:
61+
lineItems = inputLine.split()
62+
# For a safer script, do not use indexes but look for symbols in the line
63+
baseIndex = lineItems.index("HCI")
64+
hciMessage = lineItems[baseIndex + 4]
65+
hciDirection = lineItems[baseIndex + 2]
66+
hciType = lineItems[baseIndex + 1]
67+
# Build and write the encoded line
68+
btsnoopPacket = buildBinaryPacket(hciMessage, hciDirection, hciType)
69+
outputFile.write(btsnoopPacket)
70+
if DEBUG:
71+
print(hciDirection)
72+
print(hciMessage)
73+
print(hciType)
74+
print('\n')
75+
outputFile.close()
76+
77+
inputPath = args.inputPath
78+
outputPath = args.outputPath
79+
tempFile = "temp-debug-print.txt"
80+
# Run
81+
extractHCIDebugPrint(inputPath,tempFile)
82+
convertToBtsnoop(tempFile, outputPath)
83+
# Delete temp file
84+
os.remove(tempFile)
85+

extras/test/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
build

extras/test/CMakeLists.txt

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
##########################################################################
2+
3+
set(CMAKE_VERBOSE_MAKEFILE ON)
4+
cmake_minimum_required(VERSION 2.8)
5+
6+
##########################################################################
7+
8+
project(testArduinoBLE)
9+
10+
##########################################################################
11+
12+
set(CMAKE_CXX_STANDARD 11)
13+
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
14+
15+
##########################################################################
16+
17+
set(COMMON_TEST_SRCS
18+
src/test_main.cpp
19+
src/Arduino.cpp
20+
src/util/itoa.c
21+
src/util/TestUtil.cpp
22+
src/util/String.cpp
23+
src/util/Common.cpp
24+
)
25+
26+
set(DUT_SRCS
27+
../../src/utility/BLEUuid.cpp
28+
../../src/BLEDevice.cpp
29+
../../src/BLECharacteristic.cpp
30+
../../src/BLEDescriptor.cpp
31+
../../src/BLEService.cpp
32+
../../src/BLEAdvertisingData.cpp
33+
../../src/utility/ATT.cpp
34+
../../src/utility/GAP.cpp
35+
../../src/utility/HCI.cpp
36+
../../src/utility/GATT.cpp
37+
../../src/utility/L2CAPSignaling.cpp
38+
../../src/local/BLELocalAttribute.cpp
39+
../../src/local/BLELocalCharacteristic.cpp
40+
../../src/local/BLELocalDescriptor.cpp
41+
../../src/local/BLELocalDevice.cpp
42+
../../src/local/BLELocalService.cpp
43+
../../src/remote/BLERemoteAttribute.cpp
44+
../../src/remote/BLERemoteCharacteristic.cpp
45+
../../src/remote/BLERemoteDescriptor.cpp
46+
../../src/remote/BLERemoteDevice.cpp
47+
../../src/remote/BLERemoteService.cpp
48+
../../src/BLEStringCharacteristic.cpp
49+
../../src/BLETypedCharacteristics.cpp
50+
)
51+
52+
set(TEST_TARGET_UUID_SRCS
53+
# Test files
54+
${COMMON_TEST_SRCS}
55+
src/test_uuid/test_uuid.cpp
56+
# DUT files
57+
#${DUT_SRCS}
58+
../../src/utility/BLEUuid.cpp
59+
)
60+
61+
set(TEST_TARGET_DISC_DEVICE_SRCS
62+
# Test files
63+
${COMMON_TEST_SRCS}
64+
src/test_discovered_device/test_discovered_device.cpp
65+
# DUT files
66+
${DUT_SRCS}
67+
# Fake classes files
68+
src/util/HCIFakeTransport.cpp
69+
src/test_discovered_device/FakeGAP.cpp
70+
)
71+
72+
set(TEST_TARGET_ADVERTISING_DATA_SRCS
73+
# Test files
74+
${COMMON_TEST_SRCS}
75+
src/test_advertising_data/test_advertising_data.cpp
76+
src/test_advertising_data/test_service.cpp
77+
src/test_advertising_data/test_local_name.cpp
78+
src/test_advertising_data/test_manufacturer.cpp
79+
# DUT files
80+
${DUT_SRCS}
81+
# Fake classes files
82+
src/util/HCIFakeTransport.cpp
83+
src/test_advertising_data/FakeBLELocalDevice.cpp
84+
)
85+
86+
##########################################################################
87+
88+
set(CMAKE_C_FLAGS ${CMAKE_C_FLAGS} "--coverage")
89+
set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} "--coverage")
90+
91+
##########################################################################
92+
93+
add_executable(TEST_TARGET_UUID ${TEST_TARGET_UUID_SRCS})
94+
add_executable(TEST_TARGET_DISC_DEVICE ${TEST_TARGET_DISC_DEVICE_SRCS})
95+
add_executable(TEST_TARGET_ADVERTISING_DATA ${TEST_TARGET_ADVERTISING_DATA_SRCS})
96+
97+
##########################################################################
98+
99+
include_directories(include)
100+
include_directories(include/util)
101+
include_directories(../../src)
102+
include_directories(../../src/local)
103+
include_directories(../../src/remote)
104+
include_directories(../../src/utility)
105+
include_directories(external/catch/v2.12.1/include)
106+
107+
target_include_directories(TEST_TARGET_DISC_DEVICE PUBLIC include/test_discovered_device)
108+
target_include_directories(TEST_TARGET_ADVERTISING_DATA PUBLIC include/test_advertising_data)
109+
110+
##########################################################################
111+
112+
target_compile_definitions(TEST_TARGET_DISC_DEVICE PUBLIC FAKE_GAP)
113+
target_compile_definitions(TEST_TARGET_ADVERTISING_DATA PUBLIC FAKE_BLELOCALDEVICE)
114+
115+
##########################################################################
116+
117+
# Build unit tests as a post build step
118+
add_custom_command(TARGET TEST_TARGET_UUID POST_BUILD
119+
COMMAND ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/TEST_TARGET_UUID
120+
)
121+
add_custom_command(TARGET TEST_TARGET_DISC_DEVICE POST_BUILD
122+
COMMAND ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/TEST_TARGET_DISC_DEVICE
123+
)
124+
add_custom_command(TARGET TEST_TARGET_ADVERTISING_DATA POST_BUILD
125+
COMMAND ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/TEST_TARGET_ADVERTISING_DATA
126+
)

0 commit comments

Comments
 (0)