fix bug crash after 3 minutes

Dependencies:   BLE_API MbedJSONValue mbed nRF51822

Fork of BLE_RedBearNano-SAndroidE by gio wild

Files at this revision

API Documentation at this revision

Comitter:
giowild
Date:
Thu Oct 05 15:00:10 2017 +0000
Parent:
2:6c45738bba43
Commit message:
bug: check-gcd every 5 seconds fills the queue in 3 minutes causing buffer overflow and firmware to crash; fix: message is now enqueued only when bluetooth state is "connected"

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 6c45738bba43 -r 16b7d807fa8c main.cpp
--- a/main.cpp	Mon Jul 24 09:36:09 2017 +0000
+++ b/main.cpp	Thu Oct 05 15:00:10 2017 +0000
@@ -77,14 +77,14 @@
 AnalogIn analogs[] = {P0_1, P0_2, P0_3, P0_4, P0_5, P0_6};
 int mapAnalogs[] =  {-1, 0, 1, 2, 3, 4, 5,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1};
 
-
-
 void enqueueItem(Queue *queue, uint8_t *buf, int len) {
-    NODE *item = NULL;
-    item = (NODE*) malloc(sizeof (NODE));
-    memcpy(item->data.payload, buf, len); 
-    item->data.length = len;
-    Enqueue(queue, item);
+    if (ble.getGapState().connected) {
+        NODE *item = NULL;
+        item = (NODE*) malloc(sizeof (NODE));
+        memcpy(item->data.payload, buf, len); 
+        item->data.length = len;
+        Enqueue(queue, item);
+    }
 }
 
 void disconnectionCallback(const Gap::DisconnectionCallbackParams_t *params)
@@ -470,16 +470,6 @@
 
 
 void changeGcdTiming(){
-    /*if (gcdChanged) {
-        gcdChanged =false;
-        if (gcd>0) {
-            pTicker->attach(NULL,5);
-            pTicker->attach(triggerSensor, 0.001*gcd);
-        } else {
-            pTicker->attach(NULL,5);
-        }
-    }*/
-
     uint8_t buf[TXRX_BUF_LEN];
     int len = sprintf((char *)buf,"check-gcd %d",gcd);
     enqueueItem(toSendQueue, buf, len);
@@ -498,11 +488,6 @@
         pinGroups[i]=NO_GROUP;
     }
 
-    initPin(7,PIN_OUTPUT);
-    initPin(28,PIN_OUTPUT);
-    writeDigital(7,true);
-    writeDigital(28,false);
-    
     ble.init();
     ble.onDisconnection(disconnectionCallback);
     ble.onDataWritten(WrittenHandler);