@@ -348,12 +348,6 @@ void BLECharacteristic::eventHandler(ble_evt_t* event)
348348/* ------------------------------------------------------------------*/
349349/* WRITE
350350 *------------------------------------------------------------------*/
351-
352- err_t BLECharacteristic::write (const void * data, int len)
353- {
354- return write (data, len, 0 );
355- }
356-
357351err_t BLECharacteristic::write (const char * str)
358352{
359353 return write ((const uint8_t *) str, strlen (str));
@@ -395,6 +389,46 @@ err_t BLECharacteristic::write(uint8_t num)
395389 return write ( (uint8_t *) &num, sizeof (num));
396390}
397391
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+
398432/* ------------------------------------------------------------------*/
399433/* NOTIFY
400434 *------------------------------------------------------------------*/
0 commit comments