| 266 | } |
| 267 | |
| 268 | String BLEUUID::toString() const { |
| 269 | if (!m_valueSet) { |
| 270 | return "<NULL>"; // If we have no value, nothing to format. |
| 271 | } |
| 272 | |
| 273 | if (UUID_LEN(m_uuid) == BLE_UUID_16_BITS) { // If the UUID is 16bit, pad correctly. |
| 274 | char hex[9]; |
| 275 | snprintf(hex, sizeof(hex), "%08x", UUID_VAL_16(m_uuid)); |
| 276 | return String(hex) + "-0000-1000-8000-00805f9b34fb"; |
| 277 | } // End 16bit UUID |
| 278 | |
| 279 | if (UUID_LEN(m_uuid) == BLE_UUID_32_BITS) { // If the UUID is 32bit, pad correctly. |
| 280 | char hex[9]; |
| 281 | snprintf(hex, sizeof(hex), "%08" PRIx32, UUID_VAL_32(m_uuid)); |
| 282 | return String(hex) + "-0000-1000-8000-00805f9b34fb"; |
| 283 | } // End 32bit UUID |
| 284 | |
| 285 | // The UUID is not 16bit or 32bit which means that it is 128bit. |
| 286 | auto size = 37; // 32 for UUID data, 4 for '-' delimiters and one for a terminator == 37 chars |
| 287 | char *hex = (char *)malloc(size); |
| 288 | snprintf( |
| 289 | hex, size, "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x", UUID_VAL_128(m_uuid)[15], UUID_VAL_128(m_uuid)[14], |
| 290 | UUID_VAL_128(m_uuid)[13], UUID_VAL_128(m_uuid)[12], UUID_VAL_128(m_uuid)[11], UUID_VAL_128(m_uuid)[10], UUID_VAL_128(m_uuid)[9], UUID_VAL_128(m_uuid)[8], |
| 291 | UUID_VAL_128(m_uuid)[7], UUID_VAL_128(m_uuid)[6], UUID_VAL_128(m_uuid)[5], UUID_VAL_128(m_uuid)[4], UUID_VAL_128(m_uuid)[3], UUID_VAL_128(m_uuid)[2], |
| 292 | UUID_VAL_128(m_uuid)[1], UUID_VAL_128(m_uuid)[0] |
| 293 | ); |
| 294 | |
| 295 | String res(hex); |
| 296 | free(hex); |
| 297 | return res; |
| 298 | } // toString |
| 299 | |
| 300 | bool BLEUUID::operator==(const BLEUUID &rhs) const { |
| 301 | return equals(rhs); |
no test coverage detected