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 8:bd3130b890e5, committed 2015-10-22
- Comitter:
- feralwookie7
- Date:
- Thu Oct 22 17:38:56 2015 +0000
- Parent:
- 7:863814fa71c3
- Commit message:
- Works w/Android code that sends/receives data after send button clicked on app; Send button click = ble event that calls writepackets(); ; writepackets(): sends 3 20-byte packets; called at: WrittenHandler, ble.waitForEvent; ; Does not wait; Does not print
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 863814fa71c3 -r bd3130b890e5 main.cpp --- a/main.cpp Thu Oct 22 16:23:36 2015 +0000 +++ b/main.cpp Thu Oct 22 17:38:56 2015 +0000 @@ -62,13 +62,6 @@ uint8_t packet3[] = {0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x5b, 0x5c}; int i = 0; -/*int currentTrial = 0; -int totalTrials = 100; - -Timer t; -float times[100];*/ - -//DigitalOut myled(LED1); //corresponds to pin 13 on nRF51822 GattCharacteristic txCharacteristic (uart_tx_uuid, txPayload, 1, TXRX_BUF_LEN, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE_WITHOUT_RESPONSE);//GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE | @@ -83,77 +76,22 @@ void disconnectionCallback(Gap::Handle_t handle, Gap::DisconnectionReason_t reason) { - /*pc.printf("Disconnected \r\n"); - pc.printf("Restart advertising \r\n");*/ ble.startAdvertising(); } void WrittenHandler(const GattWriteCallbackParams *Handler) { uint8_t buf[TXRX_BUF_LEN]; - uint16_t bytesRead, index; + uint16_t bytesRead, index;//unnecessary, but if you take it out you must take out lots of other stuff and I don't want to mess with it right now + writePackets(); if (Handler->handle == txCharacteristic.getValueAttribute().getHandle()) { - //myled = 1; - //pc.("T b4 pckt received: %f\r\n", t.read()); //time before packet received in seconds ble.readCharacteristicValue(txCharacteristic.getValueAttribute().getHandle(), buf, &bytesRead); - - //t.stop(); - //myled = 0; - //times[currentTrial] = t.read(); - //pc.printf("%f\r\n", t.read()); //Total time in seconds bytesRead = 20; memset(txPayload, 0, TXRX_BUF_LEN); - memcpy(txPayload, buf, TXRX_BUF_LEN); - //pc.("WriteHandler \r\n"); - //pc.("Length: "); - //pc.putc(bytesRead); - //pc.("\r\n"); - //pc.("Data: "); - /*for(index=0; index<bytesRead; index++) { - //pc.putc((char)txPayload[index]); - } - //pc.("\r\n"); - - //t.reset(); - //pc.("T RESET \r\n");*/ - //currentTrial++; - - /*if(currentTrial < totalTrials) - { - //pc.("CT < TT \r\n"); //Current trial less than total trials - //wait(1); - - writePackets(); - } - else - { - float difference = 0.0; - - for(int j = 0; j<totalTrials; j++) - { - if(j == 0) - { - pc.printf("%5.3f\r\n", times[j]); - } - else - { - difference = times[j] - times[j - 1]; - pc.printf("%5.3f\r\n", difference); - } - } - float total = 0.0, avg = 0.0; - for(int m = 0; m<totalTrials; m++) - { - total = total + times[m]; - } - - avg = total/100.0; - pc.printf("AVG: %5.3f\r\n", avg); - //pc.("Done. %d trials completed.\r\n", currentTrial); - }*/ + memcpy(txPayload, buf, TXRX_BUF_LEN); } } @@ -165,10 +103,9 @@ 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.("RecHandler \r\n"); - //pc.("Length: "); + pc.putc(rx_len); - //pc.("\r\n"); + rx_len = 0; break; } @@ -177,46 +114,11 @@ 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.("RecHandler \r\n"); - pc.("Length: "); - pc.putc(rx_len); - pc.("\r\n"); - rx_len = 0; - break; - } - } - */ - - //pc.printf("Updating Characteristic... \r\n"); + ble.updateCharacteristicValue(rxCharacteristic.getValueAttribute().getHandle(), packet1, 20); - //if(currentTrial < 1) - { - wait(0.1); //trials have shown that the code will not run without a delay before the first trial - //t.start(); - } - //t.start(); - //pc.printf("T START \r\n"); + ble.updateCharacteristicValue(rxCharacteristic.getValueAttribute().getHandle(), packet2, 20); - //myled = 1; - ble.updateCharacteristicValue(rxCharacteristic.getValueAttribute().getHandle(), packet1, 20); - //myled = 0; - //pc.printf("T after pckt 1 sent: %f\r\n", t.read()); - //myled = 1; - ble.updateCharacteristicValue(rxCharacteristic.getValueAttribute().getHandle(), packet2, 20); - //myled = 0; - //pc.printf("T after pckt 2 sent: %f\r\n", t.read()); - //myled = 1; ble.updateCharacteristicValue(rxCharacteristic.getValueAttribute().getHandle(), packet3, 20); - //myled = 0; - //pc.printf("T after pckt 3 sent: %f\r\n", t.read()); - } int main(void) @@ -225,9 +127,6 @@ ble.onDisconnection(disconnectionCallback); ble.onDataWritten(WrittenHandler); - pc.baud(460800); - pc.printf("SimpleChat Init \r\n"); - pc.attach( uartCB , pc.RxIrq); // setup advertising ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED); @@ -242,16 +141,13 @@ ble.addService(uartService); ble.startAdvertising(); - //pc.("Advertising Start \r\n"); while(1) { - //pc.("BEFORE BLE WAIT 4 EVENTS \r\n"); ble.waitForEvent(); - //pc.("AFTER BLE WAIT 4 EVENTS \r\n"); + if(i == 0) { - //pc.("LAST IF STATEMENT TRUE \r\n"); writePackets(); i++; }