|
|
|
|
@@ -55,14 +55,14 @@ class MyAdvertisedDeviceCallbacks: public BLEAdvertisedDeviceCallbacks {
|
|
|
|
|
liveDataObj->scanningDeviceIndex++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// if (advertisedDevice.getServiceDataUUID().toString() != "<NULL>") {
|
|
|
|
|
// Serial.print("ServiceDataUUID: ");
|
|
|
|
|
// Serial.println(advertisedDevice.getServiceDataUUID().toString().c_str());
|
|
|
|
|
// if (advertisedDevice.getServiceUUID().toString() != "<NULL>") {
|
|
|
|
|
// Serial.print("ServiceUUID: ");
|
|
|
|
|
// Serial.println(advertisedDevice.getServiceUUID().toString().c_str());
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// if (advertisedDevice.getServiceDataUUID().toString() != "<NULL>") {
|
|
|
|
|
// Serial.print("ServiceDataUUID: ");
|
|
|
|
|
// Serial.println(advertisedDevice.getServiceDataUUID().toString().c_str());
|
|
|
|
|
// if (advertisedDevice.getServiceUUID().toString() != "<NULL>") {
|
|
|
|
|
// Serial.print("ServiceUUID: ");
|
|
|
|
|
// Serial.println(advertisedDevice.getServiceUUID().toString().c_str());
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
if (advertisedDevice.haveServiceUUID() && advertisedDevice.isAdvertisingService(BLEUUID(liveDataObj->settings.serviceUUID)) &&
|
|
|
|
|
(strcmp(advertisedDevice.getAddress().toString().c_str(), liveDataObj->settings.obdMacAddress) == 0)) {
|
|
|
|
|
@@ -117,7 +117,7 @@ static void notifyCallback (BLERemoteCharacteristic * pBLERemoteCharacteristic,
|
|
|
|
|
|
|
|
|
|
char ch;
|
|
|
|
|
|
|
|
|
|
// Parse multi line response to single lines
|
|
|
|
|
// Parse multiframes to single response
|
|
|
|
|
liveDataObj->responseRow = "";
|
|
|
|
|
for (int i = 0; i <= length; i++) {
|
|
|
|
|
ch = pData[i];
|
|
|
|
|
@@ -129,7 +129,9 @@ static void notifyCallback (BLERemoteCharacteristic * pBLERemoteCharacteristic,
|
|
|
|
|
liveDataObj->responseRow += ch;
|
|
|
|
|
if (liveDataObj->responseRow == ">") {
|
|
|
|
|
if (liveDataObj->responseRowMerged != "") {
|
|
|
|
|
commObj->parseRowMerged();
|
|
|
|
|
Serial.print("merged:");
|
|
|
|
|
Serial.println(liveDataObj->responseRowMerged);
|
|
|
|
|
boardObj->parseRowMerged();
|
|
|
|
|
}
|
|
|
|
|
liveDataObj->responseRowMerged = "";
|
|
|
|
|
liveDataObj->canSendNextAtCommand = true;
|
|
|
|
|
@@ -146,7 +148,6 @@ void CommObd2Ble4::connectDevice() {
|
|
|
|
|
commObj = this;
|
|
|
|
|
liveDataObj = liveData;
|
|
|
|
|
boardObj = board;
|
|
|
|
|
line = "";
|
|
|
|
|
|
|
|
|
|
Serial.println("BLE4 connectDevice");
|
|
|
|
|
|
|
|
|
|
@@ -313,8 +314,8 @@ bool CommObd2Ble4::connectToServer(BLEAddress pAddress) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Main loop
|
|
|
|
|
*/
|
|
|
|
|
Main loop
|
|
|
|
|
*/
|
|
|
|
|
void CommObd2Ble4::mainLoop() {
|
|
|
|
|
|
|
|
|
|
// Connect BLE device
|
|
|
|
|
@@ -341,15 +342,15 @@ void CommObd2Ble4::mainLoop() {
|
|
|
|
|
if (Serial.available()) {
|
|
|
|
|
ch = Serial.read();
|
|
|
|
|
if (ch == '\r' || ch == '\n') {
|
|
|
|
|
board->customConsoleCommand(line);
|
|
|
|
|
line = line + ch;
|
|
|
|
|
Serial.println(line);
|
|
|
|
|
board->customConsoleCommand(response);
|
|
|
|
|
response = response + ch;
|
|
|
|
|
Serial.println(response);
|
|
|
|
|
if (liveData->bleConnected) {
|
|
|
|
|
liveData->pRemoteCharacteristicWrite->writeValue(line.c_str(), line.length());
|
|
|
|
|
liveData->pRemoteCharacteristicWrite->writeValue(response.c_str(), response.length());
|
|
|
|
|
}
|
|
|
|
|
line = "";
|
|
|
|
|
response = "";
|
|
|
|
|
} else {
|
|
|
|
|
line = line + ch;
|
|
|
|
|
response = response + ch;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -396,12 +397,11 @@ bool CommObd2Ble4::doNextAtCommand() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
Parse result from OBD, create single line liveData->responseRowMerged
|
|
|
|
|
Parse result from OBD, merge frames to sigle response
|
|
|
|
|
*/
|
|
|
|
|
bool CommObd2Ble4::parseRow() {
|
|
|
|
|
|
|
|
|
|
// Simple 1 line responses
|
|
|
|
|
Serial.print("");
|
|
|
|
|
// 1 frame data
|
|
|
|
|
Serial.println(liveData->responseRow);
|
|
|
|
|
|
|
|
|
|
// Merge 0:xxxx 1:yyyy 2:zzzz to single xxxxyyyyzzzz string
|
|
|
|
|
@@ -411,17 +411,3 @@ bool CommObd2Ble4::parseRow() {
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
Parse merged row (after merge completed)
|
|
|
|
|
*/
|
|
|
|
|
bool CommObd2Ble4::parseRowMerged() {
|
|
|
|
|
|
|
|
|
|
Serial.print("merged:");
|
|
|
|
|
Serial.println(liveData->responseRowMerged);
|
|
|
|
|
|
|
|
|
|
// Parse by selected car interface
|
|
|
|
|
board->parseRowMerged();
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|