this is using the mbed os version 5-13-1
Diff: source/BleManager.cpp
- Branch:
- PassingRegression
- Revision:
- 120:779b74689747
- Parent:
- 119:8d939a902333
- Child:
- 121:ac4f59839e4f
--- a/source/BleManager.cpp Mon May 27 12:34:58 2019 +0000
+++ b/source/BleManager.cpp Mon May 27 17:00:43 2019 +0000
@@ -317,14 +317,12 @@
/** Send data aynchronously using BLE */
-void SMDevice::sendBLEUartData(char * str)
+void SMDevice::sendBLEUartData(const uint8_t * buf, int len)
{
- //Gap::GapState_t gapState = _ble.gap().getState();
- //Gap::GapState_t gapState = _ble.getGapState();
//gapState.connected
if(isConnected){
- uart->writeString(str);
- uart->writeString("\n"); //flushes uart output buffer and sends data
+ uart->write(buf, len);
+ //uart->writeString("\n"); //flushes uart output buffer and sends data
}
else
{
@@ -356,10 +354,13 @@
}
buffer[index++] = 0;
-
+ at_data_resp = new ble_at_msg_t;
+ at_data_resp->dataLen = params->len;
+ memcpy(at_data_resp->buffer, params->data, params->len);
dbg_printf(LOG, "Data : %s ",buffer);
dbg_printf(LOG, "\r\n");
/* start echo in 50 ms */
+ _event_queue.call(this, &SMDevice::setNextCommand, BLE_CMD_SEND_RX_DATA_2AT);
_event_queue.call_in(50, this, &SMDevice::EchoBleUartReceived);
//_event_queue.call(EchoBleUartReceived);
@@ -507,6 +508,7 @@
}
dbg_printf(LOG, "SM::setLinkSecurity setup\r\n");
isConnected = true;
+ _event_queue.call(this, &SMDevicePeripheral::setNextCommand, BLE_CMD_CONNECT);
}
void SMDevicePeripheral::stopAdvertising()
@@ -549,18 +551,32 @@
bleCmd = BLE_CMD_NONE;
break;
case BLE_CMD_CONNECT:
- _aT2BleDatamPool->free(data_msg);
+ at_data_resp = new ble_at_msg_t;
+ at_data_resp->dataLen = 10; // 10 bytes total
+ int idx = 0;
+ // connect type BLE = 0x01
+ at_data_resp->buffer[idx++] = 0x01;
+ // Serial Port Service BLE profile = 0x0E (14)
+ at_data_resp->buffer[idx++] = 0x0E;
+ // copy peer device address
+ memcpy(&at_data_resp->buffer[idx], _peer_address, sizeof(_peer_address));
+ idx+=sizeof(_peer_address);
+ // frame size 0x0166
+ at_data_resp->buffer[idx++] = 0x01;
+ at_data_resp->buffer[idx++] = 0x66;
bleCmd = BLE_CMD_NONE;
+ sendATresponseBytes(BLE_CONNECT_EVENT);
break;
case BLE_CMD_DISCONNECT:
- _aT2BleDatamPool->free(data_msg);
+ sendATresponseBytes(BLE_CONNECT_EVENT);
bleCmd = BLE_CMD_NONE;
break;
case BLE_CMD_SEND_RX_DATA_2AT:
- _aT2BleDatamPool->free(data_msg);
+ sendATresponseBytes(AT_BLE_RESPONSE);
bleCmd = BLE_CMD_NONE;
break;
case BLE_CMD_SEND_AT_DATA_2BLE:
+ sendBLEUartData(data_msg->buffer, data_msg->dataLen);
_aT2BleDatamPool->free(data_msg);
bleCmd = BLE_CMD_NONE;
break;
@@ -597,14 +613,14 @@
return true;
}
-void SMDevicePeripheral::sendATresponseBytes(at_cmd_resp_t at_cmd, const uint8_t * buf, int len)
+void SMDevicePeripheral::sendATresponseBytes(at_cmd_resp_t at_cmd)
{
- at_data_resp = new ble_at_msg_t;
+ //at_data_resp = new ble_at_msg_t;
// package and send on BLE data queue
// set string length
- at_data_resp->dataLen = len;
+ //at_data_resp->dataLen = len;
// copy data
- memcpy(at_data_resp->buffer, buf, len);
+ //memcpy(at_data_resp->buffer, buf, len);
// copy response type
at_data_resp->at_resp = at_cmd;
bool queueResult = true;