ble
This commit is contained in:
+3
-1
@@ -4,6 +4,8 @@
|
|||||||
#include "LiveData.h"
|
#include "LiveData.h"
|
||||||
|
|
||||||
void CommInterface::initComm(LiveData* pLiveData, BoardInterface* pBoard) {
|
void CommInterface::initComm(LiveData* pLiveData, BoardInterface* pBoard) {
|
||||||
|
|
||||||
liveData = pLiveData;
|
liveData = pLiveData;
|
||||||
board = pBoard;
|
board = pBoard;
|
||||||
|
response = "";
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -11,7 +11,7 @@ class CommInterface {
|
|||||||
LiveData* liveData;
|
LiveData* liveData;
|
||||||
BoardInterface* board;
|
BoardInterface* board;
|
||||||
char ch;
|
char ch;
|
||||||
String line;
|
String response;
|
||||||
public:
|
public:
|
||||||
void initComm(LiveData* pLiveData, BoardInterface* pBoard);
|
void initComm(LiveData* pLiveData, BoardInterface* pBoard);
|
||||||
virtual void connectDevice() = 0;
|
virtual void connectDevice() = 0;
|
||||||
|
|||||||
+29
-43
@@ -21,7 +21,7 @@ class MyClientCallback : public BLEClientCallbacks {
|
|||||||
void onDisconnect(BLEClient* pclient) {
|
void onDisconnect(BLEClient* pclient) {
|
||||||
//connected = false;
|
//connected = false;
|
||||||
Serial.println("onDisconnect");
|
Serial.println("onDisconnect");
|
||||||
|
|
||||||
boardObj->displayMessage("BLE disconnected", "");
|
boardObj->displayMessage("BLE disconnected", "");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -54,15 +54,15 @@ class MyAdvertisedDeviceCallbacks: public BLEAdvertisedDeviceCallbacks {
|
|||||||
}
|
}
|
||||||
liveDataObj->scanningDeviceIndex++;
|
liveDataObj->scanningDeviceIndex++;
|
||||||
}
|
}
|
||||||
|
|
||||||
// if (advertisedDevice.getServiceDataUUID().toString() != "<NULL>") {
|
// if (advertisedDevice.getServiceDataUUID().toString() != "<NULL>") {
|
||||||
// Serial.print("ServiceDataUUID: ");
|
// Serial.print("ServiceDataUUID: ");
|
||||||
// Serial.println(advertisedDevice.getServiceDataUUID().toString().c_str());
|
// Serial.println(advertisedDevice.getServiceDataUUID().toString().c_str());
|
||||||
// if (advertisedDevice.getServiceUUID().toString() != "<NULL>") {
|
// if (advertisedDevice.getServiceUUID().toString() != "<NULL>") {
|
||||||
// Serial.print("ServiceUUID: ");
|
// Serial.print("ServiceUUID: ");
|
||||||
// Serial.println(advertisedDevice.getServiceUUID().toString().c_str());
|
// Serial.println(advertisedDevice.getServiceUUID().toString().c_str());
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
|
||||||
if (advertisedDevice.haveServiceUUID() && advertisedDevice.isAdvertisingService(BLEUUID(liveDataObj->settings.serviceUUID)) &&
|
if (advertisedDevice.haveServiceUUID() && advertisedDevice.isAdvertisingService(BLEUUID(liveDataObj->settings.serviceUUID)) &&
|
||||||
(strcmp(advertisedDevice.getAddress().toString().c_str(), liveDataObj->settings.obdMacAddress) == 0)) {
|
(strcmp(advertisedDevice.getAddress().toString().c_str(), liveDataObj->settings.obdMacAddress) == 0)) {
|
||||||
@@ -107,7 +107,7 @@ class MySecurity : public BLESecurityCallbacks {
|
|||||||
liveDataObj->bleConnect = false;
|
liveDataObj->bleConnect = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -117,7 +117,7 @@ static void notifyCallback (BLERemoteCharacteristic * pBLERemoteCharacteristic,
|
|||||||
|
|
||||||
char ch;
|
char ch;
|
||||||
|
|
||||||
// Parse multi line response to single lines
|
// Parse multiframes to single response
|
||||||
liveDataObj->responseRow = "";
|
liveDataObj->responseRow = "";
|
||||||
for (int i = 0; i <= length; i++) {
|
for (int i = 0; i <= length; i++) {
|
||||||
ch = pData[i];
|
ch = pData[i];
|
||||||
@@ -129,7 +129,9 @@ static void notifyCallback (BLERemoteCharacteristic * pBLERemoteCharacteristic,
|
|||||||
liveDataObj->responseRow += ch;
|
liveDataObj->responseRow += ch;
|
||||||
if (liveDataObj->responseRow == ">") {
|
if (liveDataObj->responseRow == ">") {
|
||||||
if (liveDataObj->responseRowMerged != "") {
|
if (liveDataObj->responseRowMerged != "") {
|
||||||
commObj->parseRowMerged();
|
Serial.print("merged:");
|
||||||
|
Serial.println(liveDataObj->responseRowMerged);
|
||||||
|
boardObj->parseRowMerged();
|
||||||
}
|
}
|
||||||
liveDataObj->responseRowMerged = "";
|
liveDataObj->responseRowMerged = "";
|
||||||
liveDataObj->canSendNextAtCommand = true;
|
liveDataObj->canSendNextAtCommand = true;
|
||||||
@@ -146,8 +148,7 @@ void CommObd2Ble4::connectDevice() {
|
|||||||
commObj = this;
|
commObj = this;
|
||||||
liveDataObj = liveData;
|
liveDataObj = liveData;
|
||||||
boardObj = board;
|
boardObj = board;
|
||||||
line = "";
|
|
||||||
|
|
||||||
Serial.println("BLE4 connectDevice");
|
Serial.println("BLE4 connectDevice");
|
||||||
|
|
||||||
// Start BLE connection
|
// Start BLE connection
|
||||||
@@ -183,7 +184,7 @@ void CommObd2Ble4::disconnectDevice() {
|
|||||||
Scan device list, from menu
|
Scan device list, from menu
|
||||||
*/
|
*/
|
||||||
void CommObd2Ble4::scanDevices() {
|
void CommObd2Ble4::scanDevices() {
|
||||||
|
|
||||||
Serial.println("COMM scanDevices");
|
Serial.println("COMM scanDevices");
|
||||||
startBleScan();
|
startBleScan();
|
||||||
}
|
}
|
||||||
@@ -313,10 +314,10 @@ bool CommObd2Ble4::connectToServer(BLEAddress pAddress) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Main loop
|
Main loop
|
||||||
*/
|
*/
|
||||||
void CommObd2Ble4::mainLoop() {
|
void CommObd2Ble4::mainLoop() {
|
||||||
|
|
||||||
// Connect BLE device
|
// Connect BLE device
|
||||||
if (liveData->bleConnect == true && liveData->foundMyBleDevice != NULL) {
|
if (liveData->bleConnect == true && liveData->foundMyBleDevice != NULL) {
|
||||||
liveData->pServerAddress = new BLEAddress(liveData->settings.obdMacAddress);
|
liveData->pServerAddress = new BLEAddress(liveData->settings.obdMacAddress);
|
||||||
@@ -341,15 +342,15 @@ void CommObd2Ble4::mainLoop() {
|
|||||||
if (Serial.available()) {
|
if (Serial.available()) {
|
||||||
ch = Serial.read();
|
ch = Serial.read();
|
||||||
if (ch == '\r' || ch == '\n') {
|
if (ch == '\r' || ch == '\n') {
|
||||||
board->customConsoleCommand(line);
|
board->customConsoleCommand(response);
|
||||||
line = line + ch;
|
response = response + ch;
|
||||||
Serial.println(line);
|
Serial.println(response);
|
||||||
if (liveData->bleConnected) {
|
if (liveData->bleConnected) {
|
||||||
liveData->pRemoteCharacteristicWrite->writeValue(line.c_str(), line.length());
|
liveData->pRemoteCharacteristicWrite->writeValue(response.c_str(), response.length());
|
||||||
}
|
}
|
||||||
line = "";
|
response = "";
|
||||||
} else {
|
} else {
|
||||||
line = line + ch;
|
response = response + ch;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -394,14 +395,13 @@ bool CommObd2Ble4::doNextAtCommand() {
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Parse result from OBD, create single line liveData->responseRowMerged
|
Parse result from OBD, merge frames to sigle response
|
||||||
*/
|
*/
|
||||||
bool CommObd2Ble4::parseRow() {
|
bool CommObd2Ble4::parseRow() {
|
||||||
|
|
||||||
// Simple 1 line responses
|
// 1 frame data
|
||||||
Serial.print("");
|
|
||||||
Serial.println(liveData->responseRow);
|
Serial.println(liveData->responseRow);
|
||||||
|
|
||||||
// Merge 0:xxxx 1:yyyy 2:zzzz to single xxxxyyyyzzzz string
|
// Merge 0:xxxx 1:yyyy 2:zzzz to single xxxxyyyyzzzz string
|
||||||
@@ -411,17 +411,3 @@ bool CommObd2Ble4::parseRow() {
|
|||||||
|
|
||||||
return true;
|
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;
|
|
||||||
}
|
|
||||||
|
|||||||
+1
-1
@@ -18,5 +18,5 @@ class CommObd2Ble4 : public CommInterface {
|
|||||||
bool connectToServer(BLEAddress pAddress);
|
bool connectToServer(BLEAddress pAddress);
|
||||||
bool doNextAtCommand();
|
bool doNextAtCommand();
|
||||||
bool parseRow();
|
bool parseRow();
|
||||||
bool parseRowMerged();
|
//
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -7,8 +7,6 @@
|
|||||||
*/
|
*/
|
||||||
void CommObd2Can::connectDevice() {
|
void CommObd2Can::connectDevice() {
|
||||||
|
|
||||||
line = "";
|
|
||||||
|
|
||||||
Serial.println("CAN connectDevice");
|
Serial.println("CAN connectDevice");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user