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.
Fork of BLE_API by
Revision 50:9078969e80e4, committed 2014-05-28
- Comitter:
- Rohit Grover
- Date:
- Wed May 28 15:25:55 2014 +0100
- Parent:
- 49:03a51f0006f8
- Child:
- 51:0329477be5e2
- Commit message:
- define LENGTH_OF_LONG_UUID as a constant
Changed in this revision
| UUID.cpp | Show annotated file Show diff for this revision Revisions of this file |
| UUID.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/UUID.cpp Fri May 23 17:45:16 2014 +0100
+++ b/UUID.cpp Wed May 28 15:25:55 2014 +0100
@@ -28,11 +28,11 @@
function before it can be safely used!
*/
/**************************************************************************/
-UUID::UUID(void)
+UUID::UUID(void) : type(UUID_TYPE_SHORT),
+ base(),
+ value(0)
{
- memset(base, 0, 16);
- value = 0;
- type = UUID_TYPE_SHORT;
+ /* empty */
}
/**************************************************************************/
@@ -79,9 +79,12 @@
@endcode
*/
/**************************************************************************/
-UUID::UUID(uint8_t const uuid_base[16])
+UUID::UUID(const uint8_t uuid_base[LENGTH_OF_LONG_UUID]) :
+ type(UUID_TYPE_SHORT),
+ base(),
+ value(0)
{
- memcpy(base, uuid_base, 16);
+ memcpy(base, uuid_base, LENGTH_OF_LONG_UUID);
value = (uint16_t)((uuid_base[3] << 8) | (uuid_base[2]));
/* Check if this is a short of a long UUID */
@@ -103,12 +106,11 @@
The 16-bit BLE UUID value.
*/
/**************************************************************************/
-UUID::UUID(uint16_t const ble_uuid)
+UUID::UUID(const uint16_t ble_uuid) : type(UUID_TYPE_SHORT),
+ base(),
+ value(ble_uuid)
{
- memset(base, 0, 16);
memcpy(base + 2, (uint8_t *)&ble_uuid, 2);
- value = ble_uuid;
- type = UUID_TYPE_SHORT;
}
/**************************************************************************/
@@ -140,9 +142,9 @@
@endcode
*/
/**************************************************************************/
-ble_error_t UUID::update(uint8_t const uuid_base[16])
+ble_error_t UUID::update(uint8_t const uuid_base[LENGTH_OF_LONG_UUID])
{
- memcpy(base, uuid_base, 16);
+ memcpy(base, uuid_base, LENGTH_OF_LONG_UUID);
value = (uint16_t)((uuid_base[3] << 8) | (uuid_base[2]));
/* Check if this is a short of a long UUID */
@@ -179,7 +181,7 @@
/**************************************************************************/
ble_error_t UUID::update(uint16_t const ble_uuid)
{
- memset(base, 0, 16);
+ memset(base, 0, LENGTH_OF_LONG_UUID);
memcpy(base + 2, (uint8_t *)&ble_uuid, 2);
value = ble_uuid;
type = UUID_TYPE_SHORT;
--- a/UUID.h Fri May 23 17:45:16 2014 +0100
+++ b/UUID.h Wed May 28 15:25:55 2014 +0100
@@ -22,26 +22,27 @@
class UUID
{
-private:
-
public:
- enum
- {
+ enum {
UUID_TYPE_SHORT = 0, // Short BLE UUID
UUID_TYPE_LONG = 1 // Full 128-bit UUID
};
+ static const unsigned LENGTH_OF_LONG_UUID = 16;
+
+public:
UUID(void);
- UUID(uint8_t const[16]);
+ UUID(uint8_t const[LENGTH_OF_LONG_UUID]);
UUID(uint16_t const);
virtual ~UUID(void);
+ ble_error_t update(uint8_t const[LENGTH_OF_LONG_UUID]);
+ ble_error_t update(uint16_t const);
+
+public:
uint8_t type; // UUID_TYPE_SHORT or UUID_TYPE_LONG
- uint8_t base[16]; // in case of custom
+ uint8_t base[LENGTH_OF_LONG_UUID]; // in case of custom
uint16_t value; // 16 bit uuid (byte 2-3 using with base)
-
- ble_error_t update(uint8_t const[16]);
- ble_error_t update(uint16_t const);
};
#endif // ifndef __UUID_H__
