define LENGTH_OF_LONG_UUID as a constant
This commit is contained in:
parent
f7e4300039
commit
efee45e600
2 changed files with 26 additions and 23 deletions
28
UUID.cpp
28
UUID.cpp
|
@ -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 @@ UUID::UUID(void)
|
|||
@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 @@ UUID::UUID(uint8_t const uuid_base[16])
|
|||
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 @@ UUID::~UUID(void)
|
|||
@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(uint8_t const uuid_base[16])
|
|||
/**************************************************************************/
|
||||
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;
|
||||
|
|
21
UUID.h
21
UUID.h
|
@ -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);
|
||||
|
||||
uint8_t type; // UUID_TYPE_SHORT or UUID_TYPE_LONG
|
||||
uint8_t base[16]; // 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(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[LENGTH_OF_LONG_UUID]; // in case of custom
|
||||
uint16_t value; // 16 bit uuid (byte 2-3 using with base)
|
||||
};
|
||||
|
||||
#endif // ifndef __UUID_H__
|
||||
|
|
Loading…
Reference in a new issue