Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: microbit-dal microbit-dal microbit-ble-open microbit-dal ... more
Fork of BLE_API by
Revision 108:c85ab5f1eca0, committed 2014-07-24
- Comitter:
- Rohit Grover
- Date:
- Thu Jul 24 15:38:15 2014 +0100
- Parent:
- 107:bd10367dfd1c
- Child:
- 109:8559a2da6f41
- Commit message:
- add APIs for get/setDeviceName(), get/setAppearance(), getVersion(), and setTxPower().
Changed in this revision
--- a/common/BLEDeviceInstanceBase.hpp Thu Jul 24 15:35:04 2014 +0100
+++ b/common/BLEDeviceInstanceBase.hpp Thu Jul 24 15:38:15 2014 +0100
@@ -24,11 +24,13 @@
class BLEDeviceInstanceBase
{
public:
- virtual Gap& getGap() = 0;
- virtual GattServer& getGattServer() = 0;
- virtual ble_error_t init(void) = 0;
- virtual ble_error_t reset(void) = 0;
- virtual void waitForEvent(void) = 0;
+ virtual const char *getVersion(void) = 0;
+ virtual Gap& getGap() = 0;
+ virtual GattServer& getGattServer() = 0;
+ virtual ble_error_t init(void) = 0;
+ virtual ble_error_t reset(void) = 0;
+ virtual ble_error_t setTxPower(int8_t txPower) = 0;
+ virtual void waitForEvent(void) = 0;
};
/**
--- a/public/BLEDevice.h Thu Jul 24 15:35:04 2014 +0100
+++ b/public/BLEDevice.h Thu Jul 24 15:38:15 2014 +0100
@@ -242,7 +242,65 @@
ble_error_t getPreferredConnectionParams(Gap::ConnectionParams_t *params);
ble_error_t setPreferredConnectionParams(const Gap::ConnectionParams_t *params);
ble_error_t updateConnectionParams(Gap::Handle_t handle, const Gap::ConnectionParams_t *params);
- // ble_version_t getVersion(void);
+
+ /**
+ * This call allows the application to get the BLE stack version information.
+ *
+ * @return A pointer to a const string representing the version.
+ * Note: The string is owned by the BLE_API.
+ */
+ const char *getVersion(void);
+
+ /**
+ * Set the device name characteristic in the GAP service.
+ * @param deviceName The new value for the device-name. This is a UTF-8 encoded, <b>NULL-terminated</b> string.
+ */
+ ble_error_t setDeviceName(const uint8_t *deviceName);
+
+ /**
+ * Get the value of the device name characteristic in the GAP service.
+ * @param[out] deviceName Pointer to an empty buffer where the UTF-8 *non NULL-
+ * terminated* string will be placed. Set this
+ * value to NULL in order to obtain the deviceName-length
+ * from the 'length' parameter.
+ *
+ * @param[in/out] lengthP (on input) Length of the buffer pointed to by deviceName;
+ * (on output) the complete device name length (without the
+ * null terminator).
+ *
+ * @note If the device name is longer than the size of the supplied buffer,
+ * length will return the complete device name length,
+ * and not the number of bytes actually returned in deviceName.
+ * The application may use this information to retry with a suitable buffer size.
+ *
+ * Sample use:
+ * uint8_t deviceName[20];
+ * unsigned length = sizeof(deviceName);
+ * ble.getDeviceName(deviceName, &length);
+ * if (length < sizeof(deviceName)) {
+ * deviceName[length] = 0;
+ * }
+ * DEBUG("length: %u, deviceName: %s\r\n", length, deviceName);
+ */
+ ble_error_t getDeviceName(uint8_t *deviceName, unsigned *lengthP);
+
+ /**
+ * Set the appearance characteristic in the GAP service.
+ * @param[in] appearance The new value for the device-appearance.
+ */
+ ble_error_t setAppearance(uint16_t appearance);
+
+ /**
+ * Set the appearance characteristic in the GAP service.
+ * @param[out] appearance The new value for the device-appearance.
+ */
+ ble_error_t getAppearance(uint16_t *appearanceP);
+
+ /**
+ * Set the radio's transmit power.
+ * @param[in] txPower Radio transmit power in dBm.
+ */
+ ble_error_t setTxPower(int8_t txPower);
public:
BLEDevice() : transport(createBLEDeviceInstance()), advParams(), advPayload(), scanResponse(), needToSetAdvPayload(true) {
@@ -484,6 +542,42 @@
return transport->getGap().updateConnectionParams(handle, params);
}
+inline const char *
+BLEDevice::getVersion(void)
+{
+ return transport->getVersion();
+}
+
+inline ble_error_t
+BLEDevice::setDeviceName(const uint8_t *deviceName)
+{
+ return transport->getGattServer().setDeviceName(deviceName);
+}
+
+inline ble_error_t
+BLEDevice::getDeviceName(uint8_t *deviceName, unsigned *lengthP)
+{
+ return transport->getGattServer().getDeviceName(deviceName, lengthP);
+}
+
+inline ble_error_t
+BLEDevice::setAppearance(uint16_t appearance)
+{
+ return transport->getGattServer().setAppearance(appearance);
+}
+
+inline ble_error_t
+BLEDevice::getAppearance(uint16_t *appearanceP)
+{
+ return transport->getGattServer().getAppearance(appearanceP);
+}
+
+inline ble_error_t
+BLEDevice::setTxPower(int8_t txPower)
+{
+ return transport->setTxPower(txPower);
+}
+
/*
* ALL OF THE FOLLOWING METHODS ARE DEPRECATED
*/
--- a/public/GattServer.h Thu Jul 24 15:35:04 2014 +0100
+++ b/public/GattServer.h Thu Jul 24 15:38:15 2014 +0100
@@ -36,6 +36,10 @@
virtual ble_error_t addService(GattService &) = 0;
virtual ble_error_t readValue(uint16_t handle, uint8_t buffer[], uint16_t *const lengthP) = 0;
virtual ble_error_t updateValue(uint16_t, uint8_t[], uint16_t, bool localOnly = false) = 0;
+ virtual ble_error_t setDeviceName(const uint8_t *deviceName) = 0;
+ virtual ble_error_t getDeviceName(uint8_t *deviceName, unsigned *lengthP) = 0;
+ virtual ble_error_t setAppearance(uint16_t appearance) = 0;
+ virtual ble_error_t getAppearance(uint16_t *appearanceP) = 0;
// ToDo: For updateValue, check the CCCD to see if the value we are
// updating has the notify or indicate bits sent, and if BOTH are set
