Skip to content

Commit f87f391

Browse files
committed
comments copied
1 parent 561450a commit f87f391

File tree

6 files changed

+1583
-16
lines changed

6 files changed

+1583
-16
lines changed

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
build/
2-
sdkconfig
3-
sdkconfig.old
2+
sdkconfig

docs/links

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
github.com/apache/mynewt-nimble/blob/master/apps/bleprph/src/main.c
2-
github.com/apache/mynewt-nimble/blob/master/apps/blehr/src/main.c
3-
github.com/espressif/esp-idf/blob/master/examples/bluetooth/nimble/blehr/main/main.c
4-
github.com/espressif/esp-idf/blob/master/examples/bluetooth/nimble/bleprph/main/main.c
51
mynewt.apache.org/latest/network/ble_hs/ble_att.html
62
docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/bluetooth/nimble.index.html
73
https://iotespresso.com/esp32-nimble-how-to-send-notifications/

docs/todo

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,6 @@
33
- Bei einem erneuten verbindungsaufbau wird das gestoppte updaten der daten nicht wieder gestartet
44

55
- Code cleanup
6-
- Kommentare von main nehmen und in diesen branch hinzufügen
7-
- Mergen in main
8-
9-
10-
116

127

138
Kann ich nicht ändern --> wie https://github.com/h2zero/NimBLE-Arduino/blob/release/1.4/src/NimBLEDevice.cpp alles gemacht:

main/gatt_svr.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,11 +296,21 @@ gatt_svr_init(void)
296296
ble_svc_gap_init();
297297
ble_svc_gatt_init();
298298

299+
/*Adjusts a host configuration object's settings to accommodate the specified
300+
service definition array. This function adds the counts to the appropriate
301+
fields in the supplied configuration object without clearing them first, so
302+
it can be called repeatedly with different inputs to calculate totals. Be
303+
sure to zero the GATT server settings prior to the first call to this
304+
function.*/
299305
rc = ble_gatts_count_cfg(gatt_svr_svcs);
300306
if (rc != 0) {
301307
return rc;
302308
}
303309

310+
/*
311+
Queues a set of service definitions for registration. All services queued
312+
in this manner get registered when ble_gatts_start() is called.
313+
*/
304314
rc = ble_gatts_add_svcs(gatt_svr_svcs);
305315
if (rc != 0) {
306316
return rc;

main/main.c

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,14 @@
1717
#include "esp_peripheral.h"
1818
#include "host/ble_hs_pvcy.h"
1919

20-
static const char *tag = "NimBLE_BLE_HeartRate";
20+
static const char *tag = "SimLinkModule_BLE";
2121
static const ble_uuid16_t hid_service_uuid = BLE_UUID16_INIT(0x1812);
2222

2323
static xTimerHandle blehr_tx_timer;
2424

2525
static bool notify_state;
2626

27+
//eindeutiges handle was bei einem verbindungsaufbau einer verbindung zugeordnet wird
2728
static uint16_t conn_handle;
2829

2930
static const char *device_name = "HID Device";
@@ -191,6 +192,7 @@ blehr_tx_hrate(xTimerHandle ev)
191192
blehr_tx_hrate_reset();
192193
}
193194

195+
//The callback to associate with this advertising procedure. If advertising ends, the event is reported through this callback. If advertising results in a connection, the connection inherits this callback as its event-reporting mechanism.
194196
static int
195197
blehr_gap_event(struct ble_gap_event *event, void *arg)
196198
{
@@ -343,6 +345,7 @@ blehr_gap_event(struct ble_gap_event *event, void *arg)
343345
return 0;
344346
}
345347

348+
//This callback is executed when the host and controller become synced. This happens at startup and after a reset
346349
static void
347350
blehr_on_sync(void)
348351
{
@@ -357,6 +360,7 @@ blehr_on_sync(void)
357360
rc = ble_hs_util_ensure_addr(0);
358361

359362

363+
/*use privacy*/
360364
rc = ble_hs_id_infer_auto(blehr_addr_type, &blehr_addr_type);
361365
assert(rc == 0);
362366

@@ -369,16 +373,18 @@ blehr_on_sync(void)
369373

370374
taskYIELD();
371375

372-
/* Begin advertising */
376+
/*start advertising, when controller and host are in sync*/
373377
blehr_advertise();
374378
}
375379

380+
//This callback is executed when the host resets itself and the controller
376381
static void
377382
blehr_on_reset(int reason)
378383
{
379384
ESP_LOGI("ASDF", "Resetting state; reason=%d\n", reason);
380385
}
381386

387+
//start nimble in a task
382388
void blehr_host_task(void *param)
383389
{
384390
ESP_LOGI(tag, "BLE Host Task Started");
@@ -390,9 +396,14 @@ void blehr_host_task(void *param)
390396

391397
void app_main(void)
392398
{
399+
//returncodes von nimble functionen zwischenspeichern --> geben viele informationen über den status der funktionen
400+
//mynewt.apache.org/latest/network/ble_hs/ble_hs_return_codes.html
393401
int rc;
394402

395403
/* Initialize NVS — it is used to store PHY calibration data */
404+
//NVS = Non-volatile storage library is designed to store key-balue pairs in flash
405+
//Ablauf ist in esp idf beschrieben
406+
//docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/bluetooth/nimble/index.html
396407
esp_err_t ret = nvs_flash_init();
397408
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
398409
ESP_ERROR_CHECK(nvs_flash_erase());
@@ -419,21 +430,28 @@ void app_main(void)
419430
//optional wird ausgeführt wenn ein gatt resource (characteristic, descriptor, sevice) hinzugefügt wird. Also nicht benötigt
420431
ble_hs_cfg.gatts_register_cb = gatt_svr_register_cb;
421432

433+
/*Security Manager local input output capabilities*/
422434
//io types zum aufbau einer sicheren verbindung
423435
//BLE_SM_IO_CAP_DISP_ONLY = Display only
424436
//BLE_SM_IO_CAP_DISP_YES_NO = Display & yes & no buttons
425437
//BLE_SM_IO_CAP_KEYBOARD_ONLY = Keyboard only
426438
//BLE_SM_IO_CAP_NO_IO = just work
427439
//BLE_SM_IO_CAP_KEYBOARD_DISP = Keyboard and display
428440
ble_hs_cfg.sm_io_cap = BLE_SM_IO_CAP_NO_IO;
429-
//perform secure connection pairing, false we will use legacy pairing.
441+
/*Security Manager secure connections flag
442+
if set proper flag in pairing request/response will be set. this results in using LE Secure Connections for pairing if also supported by remote device. Fallback to legacy pairing if not supported by remote.*/
430443
ble_hs_cfg.sm_sc = 1;
444+
/*security Manager bond flag
445+
if set proper flag in Pairing request/response will be set. This results in storing keys distributed during bonding.*/
431446
ble_hs_cfg.sm_bonding = 1;
432-
//man in the middle protection
447+
/*security manager mitm flag
448+
if set proper flag in pairing request/response will be set. This results in requiring man-in-the-middle protection when pairing.*/
433449
ble_hs_cfg.sm_mitm = 1;
450+
/*Security Manager Local Key Distribution Mask*/
434451
ble_hs_cfg.sm_our_key_dist = BLE_SM_PAIR_KEY_DIST_ENC | BLE_SM_PAIR_KEY_DIST_ID;
435452
/* Refer components/nimble/nimble/nimble/host/include/host/ble_sm.h for
436453
* more information */
454+
/*Security Manager Remote Key Distribution Mask*/
437455
ble_hs_cfg.sm_their_key_dist = BLE_SM_PAIR_KEY_DIST_ENC | BLE_SM_PAIR_KEY_DIST_ID;
438456

439457
/* name, period/time, auto reload, timer ID, callback */
@@ -443,7 +461,7 @@ void app_main(void)
443461
assert(rc == 0);
444462

445463
/* Set the default device name */
446-
rc = ble_svc_gap_device_name_set(device_name);
464+
rc = ble_svc_gap_device_name_set(CONFIG_BT_NIMBLE_SVC_GAP_DEVICE_NAME);
447465
assert(rc == 0);
448466

449467
/* Start the task */

0 commit comments

Comments
 (0)