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.
Dependencies: BLE_API mbed nRF51822
Fork of nRF51822_Updated by
Revision 3:d67fc41e20e2, committed 2015-07-27
- Comitter:
- jck125
- Date:
- Mon Jul 27 18:06:26 2015 +0000
- Parent:
- 2:4b66b69c7ecb
- Child:
- 4:2f9c7d53a099
- Commit message:
- SimpleChat with updated libraries
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Mon Jul 27 06:52:44 2015 +0000
+++ b/main.cpp Mon Jul 27 18:06:26 2015 +0000
@@ -34,7 +34,12 @@
#define TXRX_BUF_LEN 20
-BLE ble;
+#define MIN_CONN_INTERVAL 6
+#define MAX_CONN_INTERVAL 10
+#define SLAVE_LATENCY 4
+#define CONN_SUP_TIMEOUT 6000
+
+BLE ble;
Serial pc(USBTX, USBRX);
@@ -52,16 +57,21 @@
static uint8_t rx_buf[TXRX_BUF_LEN];
static uint8_t rx_len=0;
+uint8_t packet1[] = {0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33, 0x34};
+uint8_t packet2[] = {0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48};
+uint8_t packet3[] = {0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x5b, 0x5c};
+
+Timer t;
GattCharacteristic txCharacteristic (uart_tx_uuid, txPayload, 1, TXRX_BUF_LEN, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE_WITHOUT_RESPONSE);
-
+
GattCharacteristic rxCharacteristic (uart_rx_uuid, rxPayload, 1, TXRX_BUF_LEN, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY);
-
+
GattCharacteristic *uartChars[] = {&txCharacteristic, &rxCharacteristic};
GattService uartService(uart_base_uuid, uartChars, sizeof(uartChars) / sizeof(GattCharacteristic *));
-
+int i = 0;
void disconnectionCallback(Gap::Handle_t handle, Gap::DisconnectionReason_t reason)
{
@@ -77,17 +87,22 @@
if (Handler->handle == txCharacteristic.getValueAttribute().getHandle())
{
+ pc.printf("Time before packet received in seconds: %f\n", t.read());
ble.readCharacteristicValue(txCharacteristic.getValueAttribute().getHandle(), buf, &bytesRead);
+
+ t.stop();
+ pc.printf("Time in seconds: %f\n", t.read());
+
+ bytesRead = 20;
memset(txPayload, 0, TXRX_BUF_LEN);
- memcpy(txPayload, buf, TXRX_BUF_LEN);
+ memcpy(txPayload, buf, TXRX_BUF_LEN);
pc.printf("WriteHandler \r\n");
pc.printf("Length: ");
pc.putc(bytesRead);
pc.printf("\r\n");
pc.printf("Data: ");
- for(index=0; index<bytesRead; index++)
- {
- pc.putc(txPayload[index]);
+ for(index=0; index<bytesRead; index++) {
+ pc.putc((char)txPayload[index]);
}
pc.printf("\r\n");
}
@@ -111,6 +126,39 @@
}
}
+void writePackets(void)
+{
+ /*
+ while(pc.readable())
+ {
+ rx_buf[rx_len++] = pc.getc();
+ if(rx_len>=20 || rx_buf[rx_len-1]=='\0' || rx_buf[rx_len-1]=='\n')
+ {
+ ble.updateCharacteristicValue(rxCharacteristic.getValueAttribute().getHandle(), rx_buf, rx_len);
+ pc.printf("RecHandler \r\n");
+ pc.printf("Length: ");
+ pc.putc(rx_len);
+ pc.printf("\r\n");
+ rx_len = 0;
+ break;
+ }
+ }
+ */
+
+ pc.printf("Updating Characteristic... \r\n");
+
+ wait(1);
+
+ t.start();
+
+ ble.updateCharacteristicValue(rxCharacteristic.getValueAttribute().getHandle(), packet1, 20);
+ pc.printf("Time after first packet sent in seconds: %f\n", t.read());
+ ble.updateCharacteristicValue(rxCharacteristic.getValueAttribute().getHandle(), packet2, 20);
+ pc.printf("Time after second packet sent in seconds: %f\n", t.read());
+ ble.updateCharacteristicValue(rxCharacteristic.getValueAttribute().getHandle(), packet3, 20);
+ pc.printf("Time after third packet sent in seconds: %f\n", t.read());
+}
+
int main(void)
{
ble.init();
@@ -125,7 +173,7 @@
ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED);
ble.setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED);
ble.accumulateAdvertisingPayload(GapAdvertisingData::SHORTENED_LOCAL_NAME,
- (const uint8_t *)"Biscuit", sizeof("Biscuit") - 1);
+ (const uint8_t *)"Megatron", sizeof("Megatron") - 1);
ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_128BIT_SERVICE_IDS,
(const uint8_t *)uart_base_uuid_rev, sizeof(uart_base_uuid));
// 100ms; in multiples of 0.625ms.
@@ -136,24 +184,14 @@
ble.startAdvertising();
pc.printf("Advertising Start \r\n");
- while(1)
+ while(1)
{
- ble.waitForEvent();
- }
-}
-
-
-
-
-
+ ble.waitForEvent();
-
-
-
-
-
-
-
-
-
-
+ if(i == 0)
+ {
+ writePackets();
+ i++;
+ }
+ }
+}
\ No newline at end of file
