From 5d96925d9a9d1ef5adab20ac9376740a7f1b4192 Mon Sep 17 00:00:00 2001 From: Charlie B <11893617+qubitter@users.noreply.github.com> Date: Wed, 19 Apr 2023 16:17:07 -0400 Subject: [PATCH 1/6] added IAS service --- .../src/clients/BLEClientIas.cpp | 5 +++ .../Bluefruit52Lib/src/clients/BLEClientIas.h | 14 ++++++++ .../Bluefruit52Lib/src/services/BLEIas.cpp | 34 +++++++++++++++++++ .../Bluefruit52Lib/src/services/BLEIas.h | 33 ++++++++++++++++++ 4 files changed, 86 insertions(+) create mode 100644 libraries/Bluefruit52Lib/src/clients/BLEClientIas.cpp create mode 100644 libraries/Bluefruit52Lib/src/clients/BLEClientIas.h create mode 100644 libraries/Bluefruit52Lib/src/services/BLEIas.cpp create mode 100644 libraries/Bluefruit52Lib/src/services/BLEIas.h diff --git a/libraries/Bluefruit52Lib/src/clients/BLEClientIas.cpp b/libraries/Bluefruit52Lib/src/clients/BLEClientIas.cpp new file mode 100644 index 00000000..10fab201 --- /dev/null +++ b/libraries/Bluefruit52Lib/src/clients/BLEClientIas.cpp @@ -0,0 +1,5 @@ +// +// Created by Charlie Bershatsky on 4/19/23. +// + +#include "BLEClientIas.h" diff --git a/libraries/Bluefruit52Lib/src/clients/BLEClientIas.h b/libraries/Bluefruit52Lib/src/clients/BLEClientIas.h new file mode 100644 index 00000000..f35f6541 --- /dev/null +++ b/libraries/Bluefruit52Lib/src/clients/BLEClientIas.h @@ -0,0 +1,14 @@ +// +// Created by Charlie Bershatsky on 4/19/23. +// + +#ifndef ADAFRUIT_NRF52_ARDUINO_BLECLIENTIAS_H +#define ADAFRUIT_NRF52_ARDUINO_BLECLIENTIAS_H + + +class BLEClientIas { + +}; + + +#endif //ADAFRUIT_NRF52_ARDUINO_BLECLIENTIAS_H diff --git a/libraries/Bluefruit52Lib/src/services/BLEIas.cpp b/libraries/Bluefruit52Lib/src/services/BLEIas.cpp new file mode 100644 index 00000000..aba87409 --- /dev/null +++ b/libraries/Bluefruit52Lib/src/services/BLEIas.cpp @@ -0,0 +1,34 @@ +// +// Created by Charlie Bershatsky on 4/19/23. +// + +#include "BLEIas.h" +#include "bluefruit.h" +#include "utility/utilities.h" +#include "BLEService.h" + +BLEIas::BLEIas(void) : BLEService(UUID16_SVC_IMMEDIATE_ALERT) { + +} + +void BLEIas::setAlertLevel(const uint8_t alert_level) { + _alert_level = alert_level; +} + +err_t BLEIas::begin(void) { + + // Invoke the superclass begin() + VERIFY_STATUS(BLEService::begin()); + + BLECharacteristic chars; + + chars.setUuid(UUID16_CHR_ALERT_LEVEL); + chars.setTempMemory(); + chars.setProperties(CHR_PROPS_READ); + chars.setFixedLen(sizeof(_alert_level)); + VERIFY_STATUS(chars.begin()); + chars.write(_alert_level, sizeof(_alert_level)); + + return ERROR_NONE; + +} \ No newline at end of file diff --git a/libraries/Bluefruit52Lib/src/services/BLEIas.h b/libraries/Bluefruit52Lib/src/services/BLEIas.h new file mode 100644 index 00000000..9330ddb9 --- /dev/null +++ b/libraries/Bluefruit52Lib/src/services/BLEIas.h @@ -0,0 +1,33 @@ +// +// Created by Charlie Bershatsky on 4/19/23. +// + +#ifndef ADAFRUIT_NRF52_ARDUINO_BLEIAS_H +#define ADAFRUIT_NRF52_ARDUINO_BLEIAS_H + +#include "bluefruit_common.h" + +#include "BLEService.h" +#include "BLECharacteristic.h" + + +class BLEIas : public BLEService { + +protected: + union { + struct { + const uint8_t _alert_level; // UUID 0x2A06 + }; + }; + +public: + BLEIas(void); + + void setAlertLevel(uint8_t alert_level); + + virtual err_t begin(void); + +}; + + +#endif //ADAFRUIT_NRF52_ARDUINO_BLEIAS_H From 97649cee90d8322703e64f5b13a455899a726e72 Mon Sep 17 00:00:00 2001 From: Charlie B <11893617+qubitter@users.noreply.github.com> Date: Wed, 19 Apr 2023 17:16:49 -0400 Subject: [PATCH 2/6] added client IAS --- .../src/clients/BLEClientIas.cpp | 33 +++++++++++++++++++ .../Bluefruit52Lib/src/clients/BLEClientIas.h | 13 +++++++- 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/libraries/Bluefruit52Lib/src/clients/BLEClientIas.cpp b/libraries/Bluefruit52Lib/src/clients/BLEClientIas.cpp index 10fab201..7c86f344 100644 --- a/libraries/Bluefruit52Lib/src/clients/BLEClientIas.cpp +++ b/libraries/Bluefruit52Lib/src/clients/BLEClientIas.cpp @@ -3,3 +3,36 @@ // #include "BLEClientIas.h" +#include "bluefruit.h" + +BLEClientIas::BLEClientIas() : BLEClientService(UUID16_SVC_IMMEDIATE_ALERT) { + +} + +bool BLEClientIas::begin(void) { + // invoke superclass begin() + BLEClientService::begin(); + return true; +} + +bool BLEClientIas::discover(uint16_t conn_handle) { + VERIFY(BLEClientService::discover(conn_handle)); + + return true; +} + +uint16_t BLEClientIas::getAlertLevel() { + + uint16_t level = 0; + + BLEClientCharacteristic chr(uuid); + chr.begin(this); + + if (Bluefruit.Discovery.discoverCharacteristic(_conn_hdl, chr)) { + level = chr.read16(); + } + + Bluefruit.Discovery.setHandleRange(bck_range); + + return level; +} \ No newline at end of file diff --git a/libraries/Bluefruit52Lib/src/clients/BLEClientIas.h b/libraries/Bluefruit52Lib/src/clients/BLEClientIas.h index f35f6541..61d94dff 100644 --- a/libraries/Bluefruit52Lib/src/clients/BLEClientIas.h +++ b/libraries/Bluefruit52Lib/src/clients/BLEClientIas.h @@ -5,8 +5,19 @@ #ifndef ADAFRUIT_NRF52_ARDUINO_BLECLIENTIAS_H #define ADAFRUIT_NRF52_ARDUINO_BLECLIENTIAS_H +#include "bluefruit_common.h" +#include "BLEClientCharacteristic.h" +#include "BLEClientService.h" -class BLEClientIas { +class BLEClientIas : public BLEClientService { + +public: + BLEClientIas(void); + + virtual bool begin(void); + virtual bool discover(uint16_t conn_handle); + + uint16_t getAlertLevel (void); }; From ea5a2da214710acdf3aac4351d75bbb03a192ccb Mon Sep 17 00:00:00 2001 From: Charlie B <11893617+qubitter@users.noreply.github.com> Date: Wed, 19 Apr 2023 17:17:40 -0400 Subject: [PATCH 3/6] updated gitignore to work with CLion --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index ccf361c8..8ed3dac8 100644 --- a/.gitignore +++ b/.gitignore @@ -13,6 +13,7 @@ /tools/.idea/ /tools/midi_tests/node_modules +.idea/ .DS_Store *.swp /Output From 687a54525eb15327d1a41b4430a8aa0b781b81a6 Mon Sep 17 00:00:00 2001 From: Charlie B <11893617+qubitter@users.noreply.github.com> Date: Wed, 19 Apr 2023 19:56:41 -0400 Subject: [PATCH 4/6] Updated main bluefruit to include IAS --- libraries/Bluefruit52Lib/src/bluefruit.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libraries/Bluefruit52Lib/src/bluefruit.h b/libraries/Bluefruit52Lib/src/bluefruit.h index 49afda36..f4f85a4c 100644 --- a/libraries/Bluefruit52Lib/src/bluefruit.h +++ b/libraries/Bluefruit52Lib/src/bluefruit.h @@ -62,6 +62,7 @@ #include "services/BLEDfu.h" #include "services/BLEUart.h" #include "services/BLEBas.h" +#include "services/BLEIas.h" #include "services/BLEBeacon.h" #include "services/BLEHidGeneric.h" #include "services/BLEHidAdafruit.h" @@ -75,6 +76,7 @@ #include "clients/BLEClientCts.h" #include "clients/BLEClientHidAdafruit.h" #include "clients/BLEClientBas.h" +#include "clients/BLEClientIas.h" #include "utility/AdaCallback.h" #include "utility/bonding.h" From 9388e7358cced4de888be2ecbbc5f508a59cdc4c Mon Sep 17 00:00:00 2001 From: Charlie B <11893617+qubitter@users.noreply.github.com> Date: Wed, 19 Apr 2023 19:57:53 -0400 Subject: [PATCH 5/6] updated to be consistent with uint8_t --- libraries/Bluefruit52Lib/src/clients/BLEClientIas.cpp | 5 +++-- libraries/Bluefruit52Lib/src/services/BLEIas.cpp | 4 ++-- libraries/Bluefruit52Lib/src/services/BLEIas.h | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/libraries/Bluefruit52Lib/src/clients/BLEClientIas.cpp b/libraries/Bluefruit52Lib/src/clients/BLEClientIas.cpp index 7c86f344..1b5099f3 100644 --- a/libraries/Bluefruit52Lib/src/clients/BLEClientIas.cpp +++ b/libraries/Bluefruit52Lib/src/clients/BLEClientIas.cpp @@ -23,13 +23,14 @@ bool BLEClientIas::discover(uint16_t conn_handle) { uint16_t BLEClientIas::getAlertLevel() { - uint16_t level = 0; + uint8_t level = 0; + ble_gattc_handle_range_t bck_range = Bluefruit.Discovery.getHandleRange(); BLEClientCharacteristic chr(uuid); chr.begin(this); if (Bluefruit.Discovery.discoverCharacteristic(_conn_hdl, chr)) { - level = chr.read16(); + level = chr.read8(); } Bluefruit.Discovery.setHandleRange(bck_range); diff --git a/libraries/Bluefruit52Lib/src/services/BLEIas.cpp b/libraries/Bluefruit52Lib/src/services/BLEIas.cpp index aba87409..1c06ded3 100644 --- a/libraries/Bluefruit52Lib/src/services/BLEIas.cpp +++ b/libraries/Bluefruit52Lib/src/services/BLEIas.cpp @@ -11,7 +11,7 @@ BLEIas::BLEIas(void) : BLEService(UUID16_SVC_IMMEDIATE_ALERT) { } -void BLEIas::setAlertLevel(const uint8_t alert_level) { +void BLEIas::setAlertLevel(uint8_t alert_level) { _alert_level = alert_level; } @@ -27,7 +27,7 @@ err_t BLEIas::begin(void) { chars.setProperties(CHR_PROPS_READ); chars.setFixedLen(sizeof(_alert_level)); VERIFY_STATUS(chars.begin()); - chars.write(_alert_level, sizeof(_alert_level)); + chars.write8(_alert_level); return ERROR_NONE; diff --git a/libraries/Bluefruit52Lib/src/services/BLEIas.h b/libraries/Bluefruit52Lib/src/services/BLEIas.h index 9330ddb9..47c6f3a7 100644 --- a/libraries/Bluefruit52Lib/src/services/BLEIas.h +++ b/libraries/Bluefruit52Lib/src/services/BLEIas.h @@ -16,7 +16,7 @@ class BLEIas : public BLEService { protected: union { struct { - const uint8_t _alert_level; // UUID 0x2A06 + uint8_t _alert_level; // UUID 0x2A06 }; }; From a59ffc545c13d4818ec113673dee73530974ed2e Mon Sep 17 00:00:00 2001 From: Charlie B <11893617+qubitter@users.noreply.github.com> Date: Thu, 20 Apr 2023 03:07:28 -0400 Subject: [PATCH 6/6] updated to be more similar to battery service --- .../src/clients/BLEClientIas.cpp | 15 +++++++++------ .../Bluefruit52Lib/src/clients/BLEClientIas.h | 3 +++ .../Bluefruit52Lib/src/services/BLEIas.cpp | 18 ++++++++---------- libraries/Bluefruit52Lib/src/services/BLEIas.h | 8 ++------ 4 files changed, 22 insertions(+), 22 deletions(-) diff --git a/libraries/Bluefruit52Lib/src/clients/BLEClientIas.cpp b/libraries/Bluefruit52Lib/src/clients/BLEClientIas.cpp index 1b5099f3..33735132 100644 --- a/libraries/Bluefruit52Lib/src/clients/BLEClientIas.cpp +++ b/libraries/Bluefruit52Lib/src/clients/BLEClientIas.cpp @@ -5,19 +5,23 @@ #include "BLEClientIas.h" #include "bluefruit.h" -BLEClientIas::BLEClientIas() : BLEClientService(UUID16_SVC_IMMEDIATE_ALERT) { +BLEClientIas::BLEClientIas() : +BLEClientService(UUID16_SVC_IMMEDIATE_ALERT), _alert(UUID16_SVC_IMMEDIATE_ALERT) { } bool BLEClientIas::begin(void) { // invoke superclass begin() BLEClientService::begin(); + + _alert.begin(this); + return true; } bool BLEClientIas::discover(uint16_t conn_handle) { VERIFY(BLEClientService::discover(conn_handle)); - + _conn_hdl = conn_handle; return true; } @@ -26,11 +30,10 @@ uint16_t BLEClientIas::getAlertLevel() { uint8_t level = 0; ble_gattc_handle_range_t bck_range = Bluefruit.Discovery.getHandleRange(); - BLEClientCharacteristic chr(uuid); - chr.begin(this); + _alert.begin(this); - if (Bluefruit.Discovery.discoverCharacteristic(_conn_hdl, chr)) { - level = chr.read8(); + if (Bluefruit.Discovery.discoverCharacteristic(_conn_hdl, _alert)) { + level = _alert.read8(); } Bluefruit.Discovery.setHandleRange(bck_range); diff --git a/libraries/Bluefruit52Lib/src/clients/BLEClientIas.h b/libraries/Bluefruit52Lib/src/clients/BLEClientIas.h index 61d94dff..800ddce1 100644 --- a/libraries/Bluefruit52Lib/src/clients/BLEClientIas.h +++ b/libraries/Bluefruit52Lib/src/clients/BLEClientIas.h @@ -19,6 +19,9 @@ public: uint16_t getAlertLevel (void); +private: + BLEClientCharacteristic _alert; + }; diff --git a/libraries/Bluefruit52Lib/src/services/BLEIas.cpp b/libraries/Bluefruit52Lib/src/services/BLEIas.cpp index 1c06ded3..12b6f06d 100644 --- a/libraries/Bluefruit52Lib/src/services/BLEIas.cpp +++ b/libraries/Bluefruit52Lib/src/services/BLEIas.cpp @@ -7,12 +7,13 @@ #include "utility/utilities.h" #include "BLEService.h" -BLEIas::BLEIas(void) : BLEService(UUID16_SVC_IMMEDIATE_ALERT) { +BLEIas::BLEIas(void) : +BLEService(UUID16_SVC_IMMEDIATE_ALERT), _alert(UUID16_SVC_IMMEDIATE_ALERT) { } -void BLEIas::setAlertLevel(uint8_t alert_level) { - _alert_level = alert_level; +void BLEIas::write(uint8_t alert_level) { + _alert.write8(alert_level); } err_t BLEIas::begin(void) { @@ -20,14 +21,11 @@ err_t BLEIas::begin(void) { // Invoke the superclass begin() VERIFY_STATUS(BLEService::begin()); - BLECharacteristic chars; + _alert.setProperties(CHR_PROPS_READ); + _alert.setPermission(SECMODE_OPEN, SECMODE_NO_ACCESS); + _alert.setFixedLen(1); - chars.setUuid(UUID16_CHR_ALERT_LEVEL); - chars.setTempMemory(); - chars.setProperties(CHR_PROPS_READ); - chars.setFixedLen(sizeof(_alert_level)); - VERIFY_STATUS(chars.begin()); - chars.write8(_alert_level); + VERIFY_STATUS( _alert.begin() ); return ERROR_NONE; diff --git a/libraries/Bluefruit52Lib/src/services/BLEIas.h b/libraries/Bluefruit52Lib/src/services/BLEIas.h index 47c6f3a7..280adbdb 100644 --- a/libraries/Bluefruit52Lib/src/services/BLEIas.h +++ b/libraries/Bluefruit52Lib/src/services/BLEIas.h @@ -14,16 +14,12 @@ class BLEIas : public BLEService { protected: - union { - struct { - uint8_t _alert_level; // UUID 0x2A06 - }; - }; + BLECharacteristic _alert; public: BLEIas(void); - void setAlertLevel(uint8_t alert_level); + void write(uint8_t level); virtual err_t begin(void);