diff --git a/examples/multiplication/multiplication.ino b/examples/multiplication/multiplication.ino index 8a29c41..b04eeda 100644 --- a/examples/multiplication/multiplication.ino +++ b/examples/multiplication/multiplication.ino @@ -30,7 +30,7 @@ void loop() { // I do initialization in loop because this array must live as long as the program BLETypes::IInput* inputs[] = { &in }; - BLE.start(SERVICE_UUID, inputs); + BLE.start(SERVICE_UUID, "multiplication service", inputs); while(true) { BLE.poll(); diff --git a/extras/nina-src/main/main.c b/extras/nina-src/main/main.c index 9a05c26..5e8113b 100644 --- a/extras/nina-src/main/main.c +++ b/extras/nina-src/main/main.c @@ -18,7 +18,12 @@ void app_main(void) } else if (msg.type == BLE_CREATE_INPUT) { BleBackend_add_input(id, msg.length); } else if (msg.type == BLE_START) { - BleBackend_start("testname", &id->u); + const uint16_t namelen = msg.length; + char *name = malloc(namelen + 1); + read_from_uart(name, namelen); + name[namelen] = '\0'; + + BleBackend_start(name, &id->u); break; } } diff --git a/src/FastBLE.h b/src/FastBLE.h index b5b5003..9190576 100644 --- a/src/FastBLE.h +++ b/src/FastBLE.h @@ -76,7 +76,7 @@ class BLEClass { return { id, cb }; }; - void start(ble_uuid_any_t, BLETypes::IInput**); + void start(ble_uuid_any_t, const char *, BLETypes::IInput**); void poll(); private: diff --git a/src/FastBle.cpp b/src/FastBle.cpp index fb3ee79..f2c1077 100644 --- a/src/FastBle.cpp +++ b/src/FastBle.cpp @@ -19,7 +19,7 @@ void BLEClass::init_if_not_initialized() { while(!Serial2); } -void BLEClass::start(ble_uuid_any_t svc_id, BLETypes::IInput** inputs) { +void BLEClass::start(ble_uuid_any_t svc_id, const char *name, BLETypes::IInput** inputs) { init_if_not_initialized(); _inputs = inputs; @@ -28,12 +28,17 @@ void BLEClass::start(ble_uuid_any_t svc_id, BLETypes::IInput** inputs) { inputs[i]->setup(); } + uint16_t name_length = 0; + while(name[name_length++] != '\0'); + SetupMessage msg { type: BLE_START, uuid: svc_id, + length: name_length, }; Serial2.write((uint8_t*)&msg, sizeof(SetupMessage)); + Serial2.write((uint8_t*)name, name_length); } void BLEClass::poll() { diff --git a/src/protocol/protocol.h b/src/protocol/protocol.h index 3956c3f..3f7fe59 100644 --- a/src/protocol/protocol.h +++ b/src/protocol/protocol.h @@ -13,8 +13,12 @@ enum SetupMessageType }; // A number of Create Output / Input messages can be sent +// // Then a Start message should be sent with the uuid field set to the -// UUID that the Service containing the characteristics should have. +// UUID that the Service containing the characteristics should have and +// the length field set to the length of the device's name. +// +// Then length bytes (the name) should be sent. typedef struct { uint8_t type;