initial commit

This commit is contained in:
Mirko Zeibig 2020-09-29 18:09:13 +02:00
parent d9b62d2e78
commit a30099447f
11 changed files with 282 additions and 0 deletions

5
.gitignore vendored Normal file
View File

@ -0,0 +1,5 @@
.pio
.vscode/.browse.c_cpp.db*
.vscode/c_cpp_properties.json
.vscode/launch.json
.vscode/ipch

7
.vscode/extensions.json vendored Normal file
View File

@ -0,0 +1,7 @@
{
// See http://go.microsoft.com/fwlink/?LinkId=827846
// for the documentation about the extensions.json format
"recommendations": [
"platformio.platformio-ide"
]
}

View File

@ -1,2 +1,4 @@
# micro_beacons
Quellcode zum Vortrag: https://media.ccc.de/v/ds20-11329-micro_beacons

44
boards/bbcmicrobit.json Normal file
View File

@ -0,0 +1,44 @@
{
"build": {
"arduino":{
"ldscript": "nrf51_xxaa.ld"
},
"core": "nRF5",
"cpu": "cortex-m0",
"extra_flags": "-DARDUINO_BBC_MICROBIT -DUSE_LFRC",
"f_cpu": "16000000L",
"mcu": "nrf51822",
"variant": "BBCmicrobit",
"zephyr": {
"variant": "bbc_microbit"
}
},
"connectivity": [
"bluetooth"
],
"debug": {
"onboard_tools": [
"cmsis-dap"
],
"svd_path": "nrf51.svd",
"jlink_device": "nRF51822_xxAA"
},
"frameworks": [
"arduino",
"mbed",
"zephyr"
],
"name": "BBC micro:bit",
"upload": {
"maximum_ram_size": 16384,
"maximum_size": 262144,
"protocol": "cmsis-dap",
"protocols": [
"cmsis-dap",
"mbed",
"jlink"
]
},
"url": "https://developer.mbed.org/platforms/Microbit/",
"vendor": "BBC"
}

34
boards/bbcmicrobit_b.json Normal file
View File

@ -0,0 +1,34 @@
{
"build": {
"cpu": "cortex-m0",
"f_cpu": "16000000L",
"mcu": "nrf51822"
},
"connectivity": [
"bluetooth"
],
"debug": {
"onboard_tools": [
"cmsis-dap"
],
"svd_path": "nrf51.svd",
"jlink_device": "nRF51822_xxAA"
},
"frameworks": [
"mbed"
],
"name": "BBC micro:bit B(S130)",
"upload": {
"maximum_ram_size": 16384,
"maximum_size": 262144,
"protocol": "cmsis-dap",
"protocols": [
"cmsis-dap",
"mbed",
"jlink"
]
},
"url": "https://developer.mbed.org/platforms/Microbit/",
"vendor": "BBC"
}

39
include/README Normal file
View File

@ -0,0 +1,39 @@
This directory is intended for project header files.
A header file is a file containing C declarations and macro definitions
to be shared between several project source files. You request the use of a
header file in your project source file (C, C++, etc) located in `src` folder
by including it, with the C preprocessing directive `#include'.
```src/main.c
#include "header.h"
int main (void)
{
...
}
```
Including a header file produces the same results as copying the header file
into each source file that needs it. Such copying would be time-consuming
and error-prone. With a header file, the related declarations appear
in only one place. If they need to be changed, they can be changed in one
place, and programs that include the header file will automatically use the
new version when next recompiled. The header file eliminates the labor of
finding and changing all the copies as well as the risk that a failure to
find one copy will result in inconsistencies within a program.
In C, the usual convention is to give header files names that end with `.h'.
It is most portable to use only letters, digits, dashes, and underscores in
header file names, and at most one dot.
Read more about using header files in official GCC documentation:
* Include Syntax
* Include Operation
* Once-Only Headers
* Computed Includes
https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html

46
lib/README Normal file
View File

@ -0,0 +1,46 @@
This directory is intended for project specific (private) libraries.
PlatformIO will compile them to static libraries and link into executable file.
The source code of each library should be placed in a an own separate directory
("lib/your_library_name/[here are source files]").
For example, see a structure of the following two libraries `Foo` and `Bar`:
|--lib
| |
| |--Bar
| | |--docs
| | |--examples
| | |--src
| | |- Bar.c
| | |- Bar.h
| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html
| |
| |--Foo
| | |- Foo.c
| | |- Foo.h
| |
| |- README --> THIS FILE
|
|- platformio.ini
|--src
|- main.c
and a contents of `src/main.c`:
```
#include <Foo.h>
#include <Bar.h>
int main (void)
{
...
}
```
PlatformIO Library Dependency Finder will find automatically dependent
libraries scanning project source files.
More information about PlatformIO Library Dependency Finder
- https://docs.platformio.org/page/librarymanager/ldf.html

7
mbed_app.json Normal file
View File

@ -0,0 +1,7 @@
{
"target_overrides": {
"*": {
"target.features_add": ["BLE"]
}
}
}

15
platformio.ini Normal file
View File

@ -0,0 +1,15 @@
[env:bbcmicrobit]
platform = nordicnrf51
board = bbcmicrobit_b
framework = mbed
lib_deps =
microbit
build_flags = -DNRF51_S130
-std=c++11
-I$PLATFORMIO_HOME_DIR/packages/framework-mbed@5.51105.190312/features/FEATURE_BLE
build_unflags = -std=gnu++98
upload_protocol = mbed
monitor_speed = 115200

72
src/main.cpp Normal file
View File

@ -0,0 +1,72 @@
#include "MicroBit.h"
#include "ble/DiscoveredCharacteristic.h"
#include "ble/DiscoveredService.h"
uint8_t counter;
MicroBit uBit;
void advertisementCallback(const Gap::AdvertisementCallbackParams_t *params)
{
if (params->advertisingDataLen == 31)
{
//len=31
//data=02011A03036FFD17166FFD86BFAF5ACE16AB0C809B47092C07E20DF6017412
// ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^
// | | | | | | | | | | +-- Associated Encrypted Metadata
// | | | | | | | | | +-- Rolling Proximity Identifier
// | | | | | | | | +------ Service - 0xFD6F
// | | | | | | | +-------- Type - 0x16
// | | | | | | +---------- Length - 0x17
// | | | | | +-------------- Service - 0xFD6F
if (params->advertisingData[0] == 0x02 &&
params->advertisingData[1] == 0x01 &&
params->advertisingData[2] == 0x1a &&
params->advertisingData[3] == 0x03 &&
params->advertisingData[4] == 0x03 &&
params->advertisingData[5] == 0x6f &&
params->advertisingData[6] == 0xfd
) {
int x;
int y;
x = (counter) % 5;
y = (counter) / 5;
uBit.display.image.setPixelValue(x, y, 0);
counter++;
counter = counter % 25;
x = counter % 5;
y = counter / 5;
char id[33];
int8_t rssi = params->rssi;
uBit.display.image.setPixelValue(x, y, (uint8_t)rssi);
BLEProtocol::AddressBytes_t peer;
memcpy(peer, params->peerAddr, BLEProtocol::ADDR_LEN);
for (int i = 0; i < 16; i++)
{
sprintf(&id[i * 2], "%02X", params->advertisingData[i + 11]);
}
uBit.serial.printf("id=%s - %i (%02x:%02x:%02x:%02x:%02x:%02x)\r\n",
id, (uint8_t)rssi, peer[5], peer[4], peer[3], peer[2], peer[1], peer[0]);
}
}
}
int main()
{
counter = 0;
uBit.display.setDisplayMode(DISPLAY_MODE_GREYSCALE);
scheduler_init(uBit.messageBus);
uBit.serial.printf("Scanner.....\r\n");
uBit.ble = new BLEDevice();
uBit.ble->init();
uBit.ble->gap().setScanParams(500, 400);
uBit.ble->gap().startScan(advertisementCallback);
while (true) {
uBit.ble->waitForEvent();
}
return 0;
}

11
test/README Normal file
View File

@ -0,0 +1,11 @@
This directory is intended for PIO Unit Testing and project tests.
Unit Testing is a software testing method by which individual units of
source code, sets of one or more MCU program modules together with associated
control data, usage procedures, and operating procedures, are tested to
determine whether they are fit for use. Unit testing finds problems early
in the development cycle.
More information about PIO Unit Testing:
- https://docs.platformio.org/page/plus/unit-testing.html