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
main.cpp@6:6e0eedc8e0a9, 2015-08-06 (annotated)
- Committer:
- feralwookie7
- Date:
- Thu Aug 06 14:24:53 2015 +0000
- Revision:
- 6:6e0eedc8e0a9
- Parent:
- 5:5e55081e4d7a
- Child:
- 7:863814fa71c3
Normal test;
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| RedBearLab | 1:1c058e553423 | 1 | /* |
| RedBearLab | 0:cffe8ac1bdf0 | 2 | |
| RedBearLab | 1:1c058e553423 | 3 | Copyright (c) 2012-2014 RedBearLab |
| RedBearLab | 1:1c058e553423 | 4 | |
| RedBearLab | 1:1c058e553423 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
| RedBearLab | 1:1c058e553423 | 6 | and associated documentation files (the "Software"), to deal in the Software without restriction, |
| RedBearLab | 1:1c058e553423 | 7 | including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| RedBearLab | 1:1c058e553423 | 8 | and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, |
| RedBearLab | 1:1c058e553423 | 9 | subject to the following conditions: |
| RedBearLab | 1:1c058e553423 | 10 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. |
| RedBearLab | 1:1c058e553423 | 11 | |
| RedBearLab | 1:1c058e553423 | 12 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, |
| RedBearLab | 1:1c058e553423 | 13 | INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR |
| RedBearLab | 1:1c058e553423 | 14 | PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE |
| RedBearLab | 1:1c058e553423 | 15 | FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
| RedBearLab | 1:1c058e553423 | 16 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| RedBearLab | 1:1c058e553423 | 17 | |
| RedBearLab | 1:1c058e553423 | 18 | */ |
| RedBearLab | 1:1c058e553423 | 19 | |
| RedBearLab | 1:1c058e553423 | 20 | /* |
| RedBearLab | 1:1c058e553423 | 21 | * The application works with the BLEController iOS/Android App. |
| RedBearLab | 1:1c058e553423 | 22 | * Type something from the Terminal to send |
| RedBearLab | 1:1c058e553423 | 23 | * to the BLEController App or vice verse. |
| RedBearLab | 1:1c058e553423 | 24 | * Characteristics received from App will print on Terminal. |
| RedBearLab | 1:1c058e553423 | 25 | */ |
| RedBearLab | 1:1c058e553423 | 26 | |
| RedBearLab | 0:cffe8ac1bdf0 | 27 | #include "mbed.h" |
| RedBearLab | 2:4b66b69c7ecb | 28 | #include "ble/BLE.h" |
| RedBearLab | 0:cffe8ac1bdf0 | 29 | |
| RedBearLab | 0:cffe8ac1bdf0 | 30 | |
| RedBearLab | 0:cffe8ac1bdf0 | 31 | #define BLE_UUID_TXRX_SERVICE 0x0000 /**< The UUID of the Nordic UART Service. */ |
| RedBearLab | 0:cffe8ac1bdf0 | 32 | #define BLE_UUID_TX_CHARACTERISTIC 0x0002 /**< The UUID of the TX Characteristic. */ |
| RedBearLab | 0:cffe8ac1bdf0 | 33 | #define BLE_UUIDS_RX_CHARACTERISTIC 0x0003 /**< The UUID of the RX Characteristic. */ |
| RedBearLab | 0:cffe8ac1bdf0 | 34 | |
| feralwookie7 | 5:5e55081e4d7a | 35 | #define TXRX_BUF_LEN 20 //maximum payload: 20 bytes per packet |
| RedBearLab | 0:cffe8ac1bdf0 | 36 | |
| feralwookie7 | 5:5e55081e4d7a | 37 | #define MIN_CONN_INTERVAL 6 //lowest possible connection interval (6 * 1.25 = 7.5ms) |
| feralwookie7 | 5:5e55081e4d7a | 38 | #define MAX_CONN_INTERVAL 6 |
| feralwookie7 | 5:5e55081e4d7a | 39 | #define SLAVE_LATENCY 0 //lowest possible |
| feralwookie7 | 5:5e55081e4d7a | 40 | #define CONN_SUP_TIMEOUT 6000 //default; changing this value has not been shown to make a difference in data transfer rate |
| jck125 | 3:d67fc41e20e2 | 41 | |
| jck125 | 3:d67fc41e20e2 | 42 | BLE ble; |
| RedBearLab | 0:cffe8ac1bdf0 | 43 | |
| RedBearLab | 0:cffe8ac1bdf0 | 44 | Serial pc(USBTX, USBRX); |
| RedBearLab | 0:cffe8ac1bdf0 | 45 | |
| RedBearLab | 0:cffe8ac1bdf0 | 46 | |
| RedBearLab | 0:cffe8ac1bdf0 | 47 | // The Nordic UART Service |
| RedBearLab | 0:cffe8ac1bdf0 | 48 | static const uint8_t uart_base_uuid[] = {0x71, 0x3D, 0, 0, 0x50, 0x3E, 0x4C, 0x75, 0xBA, 0x94, 0x31, 0x48, 0xF1, 0x8D, 0x94, 0x1E}; |
| RedBearLab | 0:cffe8ac1bdf0 | 49 | static const uint8_t uart_tx_uuid[] = {0x71, 0x3D, 0, 3, 0x50, 0x3E, 0x4C, 0x75, 0xBA, 0x94, 0x31, 0x48, 0xF1, 0x8D, 0x94, 0x1E}; |
| RedBearLab | 0:cffe8ac1bdf0 | 50 | static const uint8_t uart_rx_uuid[] = {0x71, 0x3D, 0, 2, 0x50, 0x3E, 0x4C, 0x75, 0xBA, 0x94, 0x31, 0x48, 0xF1, 0x8D, 0x94, 0x1E}; |
| RedBearLab | 0:cffe8ac1bdf0 | 51 | static const uint8_t uart_base_uuid_rev[] = {0x1E, 0x94, 0x8D, 0xF1, 0x48, 0x31, 0x94, 0xBA, 0x75, 0x4C, 0x3E, 0x50, 0, 0, 0x3D, 0x71}; |
| RedBearLab | 0:cffe8ac1bdf0 | 52 | |
| RedBearLab | 0:cffe8ac1bdf0 | 53 | |
| RedBearLab | 0:cffe8ac1bdf0 | 54 | uint8_t txPayload[TXRX_BUF_LEN] = {0,}; |
| RedBearLab | 0:cffe8ac1bdf0 | 55 | uint8_t rxPayload[TXRX_BUF_LEN] = {0,}; |
| RedBearLab | 0:cffe8ac1bdf0 | 56 | |
| RedBearLab | 0:cffe8ac1bdf0 | 57 | static uint8_t rx_buf[TXRX_BUF_LEN]; |
| RedBearLab | 0:cffe8ac1bdf0 | 58 | static uint8_t rx_len=0; |
| RedBearLab | 0:cffe8ac1bdf0 | 59 | |
| jck125 | 3:d67fc41e20e2 | 60 | uint8_t packet1[] = {0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33, 0x34}; |
| jck125 | 3:d67fc41e20e2 | 61 | uint8_t packet2[] = {0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48}; |
| jck125 | 3:d67fc41e20e2 | 62 | uint8_t packet3[] = {0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x5b, 0x5c}; |
| jck125 | 3:d67fc41e20e2 | 63 | |
| feralwookie7 | 5:5e55081e4d7a | 64 | int i = 0; |
| feralwookie7 | 5:5e55081e4d7a | 65 | int currentTrial = 0; |
| feralwookie7 | 5:5e55081e4d7a | 66 | int totalTrials = 100; |
| RedBearLab | 0:cffe8ac1bdf0 | 67 | |
| feralwookie7 | 5:5e55081e4d7a | 68 | Timer t; |
| feralwookie7 | 5:5e55081e4d7a | 69 | float times[100]; |
| feralwookie7 | 5:5e55081e4d7a | 70 | |
| feralwookie7 | 5:5e55081e4d7a | 71 | DigitalOut myled(LED1); //corresponds to pin 13 on nRF51822 |
| feralwookie7 | 5:5e55081e4d7a | 72 | |
| feralwookie7 | 5:5e55081e4d7a | 73 | GattCharacteristic txCharacteristic (uart_tx_uuid, txPayload, 1, TXRX_BUF_LEN, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE_WITHOUT_RESPONSE);//GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE | |
| jck125 | 3:d67fc41e20e2 | 74 | |
| RedBearLab | 0:cffe8ac1bdf0 | 75 | GattCharacteristic rxCharacteristic (uart_rx_uuid, rxPayload, 1, TXRX_BUF_LEN, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY); |
| jck125 | 3:d67fc41e20e2 | 76 | |
| RedBearLab | 0:cffe8ac1bdf0 | 77 | GattCharacteristic *uartChars[] = {&txCharacteristic, &rxCharacteristic}; |
| RedBearLab | 0:cffe8ac1bdf0 | 78 | |
| RedBearLab | 0:cffe8ac1bdf0 | 79 | GattService uartService(uart_base_uuid, uartChars, sizeof(uartChars) / sizeof(GattCharacteristic *)); |
| RedBearLab | 0:cffe8ac1bdf0 | 80 | |
| jck125 | 4:2f9c7d53a099 | 81 | |
| jck125 | 4:2f9c7d53a099 | 82 | void writePackets(void); |
| RedBearLab | 0:cffe8ac1bdf0 | 83 | |
| RedBearLab | 0:cffe8ac1bdf0 | 84 | void disconnectionCallback(Gap::Handle_t handle, Gap::DisconnectionReason_t reason) |
| RedBearLab | 0:cffe8ac1bdf0 | 85 | { |
| feralwookie7 | 5:5e55081e4d7a | 86 | //pc.printf("Disconnected \r\n"); |
| feralwookie7 | 5:5e55081e4d7a | 87 | //pc.("Restart advertising \r\n"); |
| RedBearLab | 0:cffe8ac1bdf0 | 88 | ble.startAdvertising(); |
| RedBearLab | 0:cffe8ac1bdf0 | 89 | } |
| RedBearLab | 0:cffe8ac1bdf0 | 90 | |
| RedBearLab | 2:4b66b69c7ecb | 91 | void WrittenHandler(const GattWriteCallbackParams *Handler) |
| RedBearLab | 0:cffe8ac1bdf0 | 92 | { |
| RedBearLab | 0:cffe8ac1bdf0 | 93 | uint8_t buf[TXRX_BUF_LEN]; |
| RedBearLab | 0:cffe8ac1bdf0 | 94 | uint16_t bytesRead, index; |
| RedBearLab | 0:cffe8ac1bdf0 | 95 | |
| RedBearLab | 2:4b66b69c7ecb | 96 | if (Handler->handle == txCharacteristic.getValueAttribute().getHandle()) |
| RedBearLab | 0:cffe8ac1bdf0 | 97 | { |
| feralwookie7 | 5:5e55081e4d7a | 98 | //myled = 1; |
| feralwookie7 | 5:5e55081e4d7a | 99 | //pc.("T b4 pckt received: %f\r\n", t.read()); //time before packet received in seconds |
| feralwookie7 | 5:5e55081e4d7a | 100 | ble.readCharacteristicValue(txCharacteristic.getValueAttribute().getHandle(), buf, &bytesRead); |
| feralwookie7 | 5:5e55081e4d7a | 101 | |
| feralwookie7 | 5:5e55081e4d7a | 102 | //t.stop(); |
| feralwookie7 | 5:5e55081e4d7a | 103 | myled = 0; |
| feralwookie7 | 5:5e55081e4d7a | 104 | times[currentTrial] = t.read(); |
| feralwookie7 | 5:5e55081e4d7a | 105 | //pc.printf("%f\r\n", t.read()); //Total time in seconds |
| jck125 | 3:d67fc41e20e2 | 106 | |
| jck125 | 3:d67fc41e20e2 | 107 | bytesRead = 20; |
| RedBearLab | 0:cffe8ac1bdf0 | 108 | memset(txPayload, 0, TXRX_BUF_LEN); |
| jck125 | 3:d67fc41e20e2 | 109 | memcpy(txPayload, buf, TXRX_BUF_LEN); |
| feralwookie7 | 5:5e55081e4d7a | 110 | //pc.("WriteHandler \r\n"); |
| feralwookie7 | 5:5e55081e4d7a | 111 | //pc.("Length: "); |
| feralwookie7 | 5:5e55081e4d7a | 112 | //pc.putc(bytesRead); |
| feralwookie7 | 5:5e55081e4d7a | 113 | //pc.("\r\n"); |
| feralwookie7 | 5:5e55081e4d7a | 114 | //pc.("Data: "); |
| feralwookie7 | 5:5e55081e4d7a | 115 | /*for(index=0; index<bytesRead; index++) { |
| feralwookie7 | 5:5e55081e4d7a | 116 | //pc.putc((char)txPayload[index]); |
| RedBearLab | 0:cffe8ac1bdf0 | 117 | } |
| feralwookie7 | 5:5e55081e4d7a | 118 | //pc.("\r\n"); |
| jck125 | 4:2f9c7d53a099 | 119 | |
| feralwookie7 | 5:5e55081e4d7a | 120 | //t.reset(); |
| feralwookie7 | 5:5e55081e4d7a | 121 | //pc.("T RESET \r\n");*/ |
| jck125 | 4:2f9c7d53a099 | 122 | currentTrial++; |
| jck125 | 4:2f9c7d53a099 | 123 | |
| jck125 | 4:2f9c7d53a099 | 124 | if(currentTrial < totalTrials) |
| jck125 | 4:2f9c7d53a099 | 125 | { |
| feralwookie7 | 5:5e55081e4d7a | 126 | //pc.("CT < TT \r\n"); //Current trial less than total trials |
| feralwookie7 | 5:5e55081e4d7a | 127 | //wait(1); |
| jck125 | 4:2f9c7d53a099 | 128 | |
| jck125 | 4:2f9c7d53a099 | 129 | writePackets(); |
| jck125 | 4:2f9c7d53a099 | 130 | } |
| jck125 | 4:2f9c7d53a099 | 131 | else |
| jck125 | 4:2f9c7d53a099 | 132 | { |
| feralwookie7 | 5:5e55081e4d7a | 133 | float difference = 0.0; |
| feralwookie7 | 5:5e55081e4d7a | 134 | |
| feralwookie7 | 5:5e55081e4d7a | 135 | for(int j = 0; j<totalTrials; j++) |
| feralwookie7 | 5:5e55081e4d7a | 136 | { |
| feralwookie7 | 5:5e55081e4d7a | 137 | if(j == 0) |
| feralwookie7 | 5:5e55081e4d7a | 138 | { |
| feralwookie7 | 5:5e55081e4d7a | 139 | pc.printf("%5.3f\r\n", times[j]); |
| feralwookie7 | 5:5e55081e4d7a | 140 | } |
| feralwookie7 | 5:5e55081e4d7a | 141 | else |
| feralwookie7 | 5:5e55081e4d7a | 142 | { |
| feralwookie7 | 5:5e55081e4d7a | 143 | difference = times[j] - times[j - 1]; |
| feralwookie7 | 5:5e55081e4d7a | 144 | pc.printf("%5.3f\r\n", difference); |
| feralwookie7 | 5:5e55081e4d7a | 145 | } |
| feralwookie7 | 5:5e55081e4d7a | 146 | } |
| feralwookie7 | 5:5e55081e4d7a | 147 | /*float total = 0.0, avg = 0.0; |
| feralwookie7 | 5:5e55081e4d7a | 148 | for(int m = 0; m<totalTrials; m++) |
| feralwookie7 | 5:5e55081e4d7a | 149 | { |
| feralwookie7 | 5:5e55081e4d7a | 150 | total = total + times[m]; |
| feralwookie7 | 5:5e55081e4d7a | 151 | } |
| feralwookie7 | 5:5e55081e4d7a | 152 | |
| feralwookie7 | 5:5e55081e4d7a | 153 | avg = total/100.0; |
| feralwookie7 | 5:5e55081e4d7a | 154 | pc.printf("AVG: %5.3f\r\n", avg); |
| feralwookie7 | 5:5e55081e4d7a | 155 | //pc.("Done. %d trials completed.\r\n", currentTrial);*/ |
| feralwookie7 | 5:5e55081e4d7a | 156 | } |
| RedBearLab | 0:cffe8ac1bdf0 | 157 | } |
| RedBearLab | 0:cffe8ac1bdf0 | 158 | } |
| RedBearLab | 0:cffe8ac1bdf0 | 159 | |
| RedBearLab | 0:cffe8ac1bdf0 | 160 | void uartCB(void) |
| RedBearLab | 0:cffe8ac1bdf0 | 161 | { |
| RedBearLab | 0:cffe8ac1bdf0 | 162 | while(pc.readable()) |
| RedBearLab | 0:cffe8ac1bdf0 | 163 | { |
| RedBearLab | 0:cffe8ac1bdf0 | 164 | rx_buf[rx_len++] = pc.getc(); |
| RedBearLab | 0:cffe8ac1bdf0 | 165 | if(rx_len>=20 || rx_buf[rx_len-1]=='\0' || rx_buf[rx_len-1]=='\n') |
| RedBearLab | 0:cffe8ac1bdf0 | 166 | { |
| RedBearLab | 0:cffe8ac1bdf0 | 167 | ble.updateCharacteristicValue(rxCharacteristic.getValueAttribute().getHandle(), rx_buf, rx_len); |
| feralwookie7 | 5:5e55081e4d7a | 168 | //pc.("RecHandler \r\n"); |
| feralwookie7 | 5:5e55081e4d7a | 169 | //pc.("Length: "); |
| RedBearLab | 0:cffe8ac1bdf0 | 170 | pc.putc(rx_len); |
| feralwookie7 | 5:5e55081e4d7a | 171 | //pc.("\r\n"); |
| RedBearLab | 0:cffe8ac1bdf0 | 172 | rx_len = 0; |
| RedBearLab | 0:cffe8ac1bdf0 | 173 | break; |
| RedBearLab | 0:cffe8ac1bdf0 | 174 | } |
| RedBearLab | 0:cffe8ac1bdf0 | 175 | } |
| RedBearLab | 0:cffe8ac1bdf0 | 176 | } |
| RedBearLab | 0:cffe8ac1bdf0 | 177 | |
| jck125 | 3:d67fc41e20e2 | 178 | void writePackets(void) |
| jck125 | 3:d67fc41e20e2 | 179 | { |
| jck125 | 3:d67fc41e20e2 | 180 | /* |
| jck125 | 3:d67fc41e20e2 | 181 | while(pc.readable()) |
| jck125 | 3:d67fc41e20e2 | 182 | { |
| jck125 | 3:d67fc41e20e2 | 183 | rx_buf[rx_len++] = pc.getc(); |
| jck125 | 3:d67fc41e20e2 | 184 | if(rx_len>=20 || rx_buf[rx_len-1]=='\0' || rx_buf[rx_len-1]=='\n') |
| jck125 | 3:d67fc41e20e2 | 185 | { |
| jck125 | 3:d67fc41e20e2 | 186 | ble.updateCharacteristicValue(rxCharacteristic.getValueAttribute().getHandle(), rx_buf, rx_len); |
| feralwookie7 | 5:5e55081e4d7a | 187 | pc.("RecHandler \r\n"); |
| feralwookie7 | 5:5e55081e4d7a | 188 | pc.("Length: "); |
| jck125 | 3:d67fc41e20e2 | 189 | pc.putc(rx_len); |
| feralwookie7 | 5:5e55081e4d7a | 190 | pc.("\r\n"); |
| jck125 | 3:d67fc41e20e2 | 191 | rx_len = 0; |
| jck125 | 3:d67fc41e20e2 | 192 | break; |
| jck125 | 3:d67fc41e20e2 | 193 | } |
| jck125 | 3:d67fc41e20e2 | 194 | } |
| jck125 | 3:d67fc41e20e2 | 195 | */ |
| jck125 | 3:d67fc41e20e2 | 196 | |
| feralwookie7 | 5:5e55081e4d7a | 197 | //pc.("Updating Characteristic... \r\n"); |
| jck125 | 3:d67fc41e20e2 | 198 | |
| feralwookie7 | 5:5e55081e4d7a | 199 | if(currentTrial < 1) |
| feralwookie7 | 5:5e55081e4d7a | 200 | { |
| feralwookie7 | 5:5e55081e4d7a | 201 | wait(1); //trials have shown that the code will not run without a delay before the first trial |
| jck125 | 3:d67fc41e20e2 | 202 | t.start(); |
| feralwookie7 | 5:5e55081e4d7a | 203 | } |
| feralwookie7 | 5:5e55081e4d7a | 204 | //t.start(); |
| feralwookie7 | 5:5e55081e4d7a | 205 | //pc.("T START \r\n"); |
| jck125 | 3:d67fc41e20e2 | 206 | |
| feralwookie7 | 5:5e55081e4d7a | 207 | myled = 1; |
| jck125 | 3:d67fc41e20e2 | 208 | ble.updateCharacteristicValue(rxCharacteristic.getValueAttribute().getHandle(), packet1, 20); |
| feralwookie7 | 5:5e55081e4d7a | 209 | //myled = 0; |
| feralwookie7 | 5:5e55081e4d7a | 210 | //pc.("T after pckt 1 sent: %f\r\n", t.read()); |
| feralwookie7 | 5:5e55081e4d7a | 211 | //myled = 1; |
| jck125 | 3:d67fc41e20e2 | 212 | ble.updateCharacteristicValue(rxCharacteristic.getValueAttribute().getHandle(), packet2, 20); |
| feralwookie7 | 5:5e55081e4d7a | 213 | //myled = 0; |
| feralwookie7 | 5:5e55081e4d7a | 214 | //pc.("T after pckt 2 sent: %f\r\n", t.read()); |
| feralwookie7 | 5:5e55081e4d7a | 215 | //myled = 1; |
| jck125 | 3:d67fc41e20e2 | 216 | ble.updateCharacteristicValue(rxCharacteristic.getValueAttribute().getHandle(), packet3, 20); |
| feralwookie7 | 5:5e55081e4d7a | 217 | //myled = 0; |
| feralwookie7 | 5:5e55081e4d7a | 218 | //pc.("T after pckt 3 sent: %f\r\n", t.read()); |
| feralwookie7 | 5:5e55081e4d7a | 219 | |
| jck125 | 3:d67fc41e20e2 | 220 | } |
| jck125 | 3:d67fc41e20e2 | 221 | |
| RedBearLab | 0:cffe8ac1bdf0 | 222 | int main(void) |
| RedBearLab | 0:cffe8ac1bdf0 | 223 | { |
| RedBearLab | 0:cffe8ac1bdf0 | 224 | ble.init(); |
| RedBearLab | 0:cffe8ac1bdf0 | 225 | ble.onDisconnection(disconnectionCallback); |
| RedBearLab | 0:cffe8ac1bdf0 | 226 | ble.onDataWritten(WrittenHandler); |
| RedBearLab | 0:cffe8ac1bdf0 | 227 | |
| feralwookie7 | 5:5e55081e4d7a | 228 | pc.baud(460800); |
| feralwookie7 | 5:5e55081e4d7a | 229 | //pc.("SimpleChat Init \r\n"); |
| RedBearLab | 0:cffe8ac1bdf0 | 230 | |
| RedBearLab | 0:cffe8ac1bdf0 | 231 | pc.attach( uartCB , pc.RxIrq); |
| RedBearLab | 0:cffe8ac1bdf0 | 232 | // setup advertising |
| RedBearLab | 0:cffe8ac1bdf0 | 233 | ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED); |
| RedBearLab | 0:cffe8ac1bdf0 | 234 | ble.setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED); |
| RedBearLab | 0:cffe8ac1bdf0 | 235 | ble.accumulateAdvertisingPayload(GapAdvertisingData::SHORTENED_LOCAL_NAME, |
| jck125 | 3:d67fc41e20e2 | 236 | (const uint8_t *)"Megatron", sizeof("Megatron") - 1); |
| RedBearLab | 0:cffe8ac1bdf0 | 237 | ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_128BIT_SERVICE_IDS, |
| RedBearLab | 0:cffe8ac1bdf0 | 238 | (const uint8_t *)uart_base_uuid_rev, sizeof(uart_base_uuid)); |
| RedBearLab | 0:cffe8ac1bdf0 | 239 | // 100ms; in multiples of 0.625ms. |
| RedBearLab | 0:cffe8ac1bdf0 | 240 | ble.setAdvertisingInterval(160); |
| RedBearLab | 0:cffe8ac1bdf0 | 241 | |
| RedBearLab | 0:cffe8ac1bdf0 | 242 | ble.addService(uartService); |
| RedBearLab | 0:cffe8ac1bdf0 | 243 | |
| RedBearLab | 0:cffe8ac1bdf0 | 244 | ble.startAdvertising(); |
| feralwookie7 | 5:5e55081e4d7a | 245 | //pc.("Advertising Start \r\n"); |
| RedBearLab | 0:cffe8ac1bdf0 | 246 | |
| jck125 | 3:d67fc41e20e2 | 247 | while(1) |
| RedBearLab | 0:cffe8ac1bdf0 | 248 | { |
| feralwookie7 | 5:5e55081e4d7a | 249 | //wait(1); |
| feralwookie7 | 5:5e55081e4d7a | 250 | //pc.("BEFORE BLE WAIT 4 EVENTS \r\n"); |
| jck125 | 3:d67fc41e20e2 | 251 | ble.waitForEvent(); |
| feralwookie7 | 5:5e55081e4d7a | 252 | //pc.("AFTER BLE WAIT 4 EVENTS \r\n"); |
| jck125 | 3:d67fc41e20e2 | 253 | if(i == 0) |
| jck125 | 3:d67fc41e20e2 | 254 | { |
| feralwookie7 | 5:5e55081e4d7a | 255 | //pc.("LAST IF STATEMENT TRUE \r\n"); |
| jck125 | 3:d67fc41e20e2 | 256 | writePackets(); |
| jck125 | 3:d67fc41e20e2 | 257 | i++; |
| jck125 | 3:d67fc41e20e2 | 258 | } |
| jck125 | 3:d67fc41e20e2 | 259 | } |
| jck125 | 3:d67fc41e20e2 | 260 | } |
