this is using the mbed os version 5-13-1

Dependencies:   mbed-http

Branch:
PassingRegression
Revision:
119:8d939a902333
Parent:
118:8df0e9c2ee3f
Child:
120:779b74689747
--- a/source/BleManager.cpp	Sat May 25 16:25:42 2019 +0000
+++ b/source/BleManager.cpp	Mon May 27 12:34:58 2019 +0000
@@ -32,7 +32,7 @@
 //static const uint8_t DEVICE_NAME[] = "SM_device";
 //static const uint16_t uuid16_list[] = {LEDService::LED_SERVICE_UUID};
 extern UARTService *uart;
-extern char buffer[BUFFER_LEN];
+
 /** This example demonstrates all the basic setup required
  *  for pairing and setting up link security both as a central and peripheral
  *
@@ -97,10 +97,13 @@
     ble_error_t error;
 
     /* to show we're running we'll blink every 10secs */
-    _event_queue.call_every(10000, this, &SMDevice::blink);
+    //_event_queue.call_every(10000, this, &SMDevice::blink);
 
     /* to show we're advertising we'll print status every minute */
-    _event_queue.call_every(60000, this, &SMDevice::reportGapState);
+    //_event_queue.call_every(60000, this, &SMDevice::reportGapState);
+
+    /* process queues every BLE_PROCESS_QUEUES_INTERVAL_MS */
+    _event_queue.call_every(BLE_PROCESS_QUEUES_INTERVAL_MS, this, &SMDevice::processQueues);
 
 
 
@@ -534,6 +537,94 @@
 }
 
 
+void SMDevicePeripheral::processQueues()
+{
+    dequeueATdataResponse();
+    switch(bleCmd)
+    {
+    case BLE_CMD_NONE:
+        break;
+    case BLE_CMD_CONFIG:
+        _aT2BleDatamPool->free(data_msg);
+        bleCmd = BLE_CMD_NONE;
+        break;
+    case BLE_CMD_CONNECT:
+        _aT2BleDatamPool->free(data_msg);
+        bleCmd = BLE_CMD_NONE;
+        break;
+    case BLE_CMD_DISCONNECT:
+        _aT2BleDatamPool->free(data_msg);
+        bleCmd = BLE_CMD_NONE;
+        break;
+    case BLE_CMD_SEND_RX_DATA_2AT:
+        _aT2BleDatamPool->free(data_msg);
+        bleCmd = BLE_CMD_NONE;
+        break;
+    case BLE_CMD_SEND_AT_DATA_2BLE:
+        _aT2BleDatamPool->free(data_msg);
+        bleCmd = BLE_CMD_NONE;
+        break;
+    default:
+        _aT2BleDatamPool->free(data_msg);
+        bleCmd = BLE_CMD_NONE;
+        break;
+    }
+    
+}
+
+
+bool SMDevicePeripheral::queueBleDataResponse(ble_at_msg_t at_resp)
+{
+    ble_at_msg_t *atData = _ble2ATDatamPool->alloc();
+    if(atData == NULL) return false; // queue full;
+    atData->at_resp        = at_resp.at_resp;
+    atData->dataLen        = at_resp.dataLen;
+    memcpy(atData->buffer, at_resp.buffer, at_resp.dataLen);
+    _ble2ATDataQueue->put(atData);
+    dbg_printf(LOG, "[BLE-MAN] queued data size = %d : at_resp = %d\n", at_resp.dataLen, at_resp.at_resp);
+    return true;
+}
+
+
+bool SMDevicePeripheral::dequeueATdataResponse(){
+    if(bleCmd != BLE_CMD_NONE) return false; // busy
+    osEvent evt = _aT2BleDataQueue->get(0);
+    if(evt.status == osEventMessage){
+        data_msg = (at_ble_msg_t*)evt.value.p;
+        setNextCommand(data_msg->ble_cmd);
+        //_wiFi2ATDatamPool->free(data_msg);
+    }
+    return true;
+}
+
+void  SMDevicePeripheral::sendATresponseBytes(at_cmd_resp_t at_cmd, const uint8_t * buf, int len)
+{
+    at_data_resp = new ble_at_msg_t;
+    // package and send on BLE data queue    
+    // set string length 
+    at_data_resp->dataLen = len;
+    // copy data
+    memcpy(at_data_resp->buffer, buf, len);
+    // copy response type
+    at_data_resp->at_resp = at_cmd;
+    bool queueResult = true;
+    int wait_count = 0;
+    queueResult = queueBleDataResponse(*at_data_resp);
+    delete at_data_resp;
+    at_data_resp = NULL;
+    dbg_printf(LOG, "[BLE-MAN] sendATresponseBytes completed successfully\r\n");
+}                                            
+
+bool SMDevicePeripheral::setNextCommand(ble_cmd_t cmd)
+{
+    dbg_printf(LOG, "\n [BLE-MAN] About to set next BLE manager command to %d\n", cmd);
+    if(bleCmd == BLE_CMD_NONE){
+        bleCmd = cmd;
+        return true; // success
+    }
+    dbg_printf(LOG, "\n [BLE-MAN] Busy : current state = %d \n", bleCmd);
+    return false; // BleManager busy
+}
 
 /** A central device will scan, connect to a peer and request pairing. */