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
Diff: hw/nrf51822.cpp
- Revision:
- 23:f19c60478e1b
- Parent:
- 20:c6ceaa206674
diff -r 260313bcf4d0 -r f19c60478e1b hw/nrf51822.cpp
--- a/hw/nrf51822.cpp Tue Jan 07 10:54:02 2014 +0000
+++ b/hw/nrf51822.cpp Tue Jan 07 19:58:06 2014 +0000
@@ -30,8 +30,9 @@
/* Add flow control for UART (required by the nRF51822) */
uart.set_flow_control(RawSerial::RTSCTS, p30, p29);
- /* Reset the service counter */
+ /* Reset the service and characteristic counters */
serviceCount = 0;
+ characteristicCount = 0;
}
/**************************************************************************/
@@ -263,8 +264,8 @@
{
/* Command ID = 0x0002 */
uart.printf("10 02 00 0F 01 02 %02X %02X 04 02 %02X %02X 05 02 %02X %02X 03 01 %02X\r\n",
- service.characteristics[i].id & 0xFF,
- service.characteristics[i].id >> 8,
+ service.characteristics[i].uuid & 0xFF,
+ service.characteristics[i].uuid >> 8,
service.characteristics[i].lenMin & 0xFF,
service.characteristics[i].lenMin >> 8,
service.characteristics[i].lenMax & 0xFF,
@@ -273,9 +274,13 @@
/* ToDo: Check response */
wait(0.1);
- }
+
+ /* Update the characteristic handle */
+ service.characteristics[i].handle = characteristicCount;
+ characteristicCount++;
+ }
- /* Update the service index value */
+ /* Update the service handle */
service.handle = serviceCount;
serviceCount++;
@@ -287,10 +292,8 @@
@brief Reads the value of a characteristic, based on the service
and characteristic index fields
- @param[in] service
- The GattService to read from
- @param[in] characteristic
- The GattCharacteristic to read from
+ @param[in] charHandle
+ The handle of the GattCharacteristic to read from
@param[in] buffer
Buffer to hold the the characteristic's value
(raw byte array in LSB format)
@@ -309,7 +312,7 @@
@endcode
*/
/**************************************************************************/
-ble_error_t nRF51822::readCharacteristic(GattService &service, GattCharacteristic &characteristic, uint8_t buffer[], uint16_t len)
+ble_error_t nRF51822::readCharacteristic(uint8_t charHandle, uint8_t buffer[], uint16_t len)
{
/* ToDo */
@@ -320,11 +323,9 @@
/*!
@brief Updates the value of a characteristic, based on the service
and characteristic index fields
-
- @param[in] service
- The GattService to write to
- @param[in] characteristic
- The GattCharacteristic to write to
+
+ @param[in] charHandle
+ The handle of the GattCharacteristic to write to
@param[in] buffer
Data to use when updating the characteristic's value
(raw byte array in LSB format)
@@ -343,10 +344,10 @@
@endcode
*/
/**************************************************************************/
-ble_error_t nRF51822::writeCharacteristic(GattService &service, GattCharacteristic &characteristic, uint8_t buffer[], uint16_t len)
+ble_error_t nRF51822::writeCharacteristic(uint8_t charHandle, uint8_t buffer[], uint16_t len)
{
- /* Command ID = 0x0006, Payload = Service ID, Characteristic ID, Value */
- uart.printf("10 06 00 %02X %02X %02X", len + 2, characteristic.handle, service.handle);
+ /* Command ID = 0x0006, Payload = Characteristic ID, Value */
+ uart.printf("10 06 00 %02X %02X", len + 1, charHandle);
for (uint16_t i = 0; i<len; i++)
{
uart.printf(" %02X", buffer[i]);
@@ -438,8 +439,9 @@
/* Command ID = 0x0005, No payload */
uart.printf("10 05 00 00\r\n");
- /* Reset the service counter */
+ /* Reset the service and characteristic counters */
serviceCount = 0;
+ characteristicCount = 0;
/* Wait for the radio to come back up */
wait(1);
