@@ -348,12 +348,6 @@ void BLECharacteristic::eventHandler(ble_evt_t* event)
348
348
/* ------------------------------------------------------------------*/
349
349
/* WRITE
350
350
*------------------------------------------------------------------*/
351
-
352
- err_t BLECharacteristic::write (const void * data, int len)
353
- {
354
- return write (data, len, 0 );
355
- }
356
-
357
351
err_t BLECharacteristic::write (const char * str)
358
352
{
359
353
return write ((const uint8_t *) str, strlen (str));
@@ -395,6 +389,46 @@ err_t BLECharacteristic::write(uint8_t num)
395
389
return write ( (uint8_t *) &num, sizeof (num));
396
390
}
397
391
392
+ /* ------------------------------------------------------------------*/
393
+ /* READ
394
+ *------------------------------------------------------------------*/
395
+ /* *
396
+ * Read Characteristic's value
397
+ * @param buffer memory to hold value
398
+ * @param len size of memory
399
+ * @param offset offset of value (dfeault is 0)
400
+ * @return number of read bytes
401
+ */
402
+ uint16_t BLECharacteristic::read (void * buffer, int bufsize, uint16_t offset)
403
+ {
404
+ ble_gatts_value_t value =
405
+ {
406
+ .len = (uint16_t ) bufsize,
407
+ .offset = offset,
408
+ .p_value = (uint8_t *) buffer
409
+ };
410
+
411
+ // conn handle only needed for system attribute
412
+ VERIFY_STATUS (sd_ble_gatts_value_get (BLE_CONN_HANDLE_INVALID, _handles.value_handle , &value), 0 );
413
+
414
+ return value.len ;
415
+ }
416
+
417
+ uint16_t BLECharacteristic::read (uint32_t * num)
418
+ {
419
+ return read (num, 4 );
420
+ }
421
+
422
+ uint16_t BLECharacteristic::read (uint16_t * num)
423
+ {
424
+ return read (num, 2 );
425
+ }
426
+
427
+ uint16_t BLECharacteristic::read (uint8_t * num)
428
+ {
429
+ return read (num, 1 );
430
+ }
431
+
398
432
/* ------------------------------------------------------------------*/
399
433
/* NOTIFY
400
434
*------------------------------------------------------------------*/
0 commit comments