ongoing Development Project for interfacing a BM019 Module with nrf51-dk, acting as a nfc 2 ble bridge. Base project for opensource blueReader Device

Dependencies:   BLE_API mbed nRF51822

Revision:
1:e4e03060b32f
Parent:
0:d156731c291b
--- a/main.cpp	Sat Apr 16 14:00:28 2016 +0000
+++ b/main.cpp	Thu Apr 21 19:09:42 2016 +0000
@@ -21,6 +21,20 @@
 }
 char answer[512];
 
+Ticker ticker;
+void timerCallback(void)
+{
+    DEBUG("start timer callback");
+    sprintf(answer,"+.!");
+    DEBUG("writing beatpulse \"%s\" with len %d to ble\n",answer,strlen(answer));
+    int l = strlen(answer);
+    for(int i = 0; i*20 < strlen(answer); i++) {
+        int len = 20 < l ? 20 : l;
+        ble.updateCharacteristicValue(uartServicePtr->getRXCharacteristicHandle(), (uint8_t *)&answer[i*20], len);
+        l -= 20;
+    }
+    ticker.detach();
+}
 void onDataWritten(const GattWriteCallbackParams *params)
 {
     if ((uartServicePtr != NULL) && (params->handle == uartServicePtr->getTXCharacteristicHandle())) {
@@ -53,6 +67,27 @@
                 }
                 break;
 
+                case 'b':
+                case 'B':
+                    DEBUG("Handling b\n");
+                    if(i + 5 <= bytesRead) {
+                        sprintf(answer,"+b!");
+                        int adr = 0;
+                        char b[3];
+                        b[0] = params->data[i+4];
+                        b[1] = params->data[i+5];
+                        b[2] = 0;
+                        sscanf(b,"%x",&adr);
+                        DEBUG("beat in %d sec\n",adr);
+                        ticker.attach(timerCallback, adr);
+                        i+=5;
+                        handled=true;
+                    } else {
+                        sprintf(answer,"-b!");
+                        handled=true;
+                    }
+
+                    break;
                 case 'h':
                 case 'H': {
                     DEBUG("Handling h\n");
@@ -272,21 +307,21 @@
     //ble.setAdvertisingType(GapAdvertisingParams::ADV_SCANNABLE_UNDIRECTED);
     ble.accumulateAdvertisingPayload(GapAdvertisingData::SHORTENED_LOCAL_NAME,
                                      (const uint8_t *)"BLE UART2NFC", sizeof("BLE UART2NFC") - 1);
-                                     
-                                     
+
+
     /*ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_128BIT_SERVICE_IDS,
                                      (const uint8_t *)UARTServiceUUID_reversed, sizeof(UARTServiceUUID_reversed));
-*/
+    */
 
-ble.accumulateScanResponse(GapAdvertisingData::COMPLETE_LIST_128BIT_SERVICE_IDS,
-                                     (const uint8_t *)UARTServiceUUID_reversed, sizeof(UARTServiceUUID_reversed));
+    ble.accumulateScanResponse(GapAdvertisingData::COMPLETE_LIST_128BIT_SERVICE_IDS,
+                               (const uint8_t *)UARTServiceUUID_reversed, sizeof(UARTServiceUUID_reversed));
     ble.setAdvertisingInterval(1000); /* 1000ms; in multiples of 0.625ms. */
     //ble.setAdvertisingTimeout(0x1);
     ble.startAdvertising();
 
     UARTService uartService(ble);
     uartServicePtr = &uartService;
-    
+
     while (true) {
         ble.waitForEvent();
     }