can sorting

This commit is contained in:
Lubos Petrovic
2020-12-21 09:21:37 +01:00
parent b2eea06bf6
commit 58e4faebdd

View File

@@ -10,7 +10,7 @@ void CommObd2Can::connectDevice() {
Serial.println("CAN connectDevice");
//CAN = new MCP_CAN(pinCanCs); // todo: remove if smart pointer is ok
//CAN = new MCP_CAN(pinCanCs); // todo: remove if smart pointer is ok
CAN.reset(new MCP_CAN(pinCanCs)); // smart pointer so it's automatically cleaned when out of context and also free to re-init
if (CAN == nullptr) {
Serial.println("Error: Not enough memory to instantiate CAN class");
@@ -29,7 +29,7 @@ void CommObd2Can::connectDevice() {
}
if (MCP2515_OK != CAN->setMode(MCP_NORMAL)) { // Set operation mode to normal so the MCP2515 sends acks to received data.
Serial.println("Error: CAN->setMode(MCP_NORMAL) failed");
Serial.println("Error: CAN->setMode(MCP_NORMAL) failed");
board->displayMessage(" > CAN init failed", "");
return;
}
@@ -217,11 +217,14 @@ bool CommObd2Can::processFrame() {
switch (frameType) {
// Single frame
case 0:
rxRemaining = (rxBuf[1] & 0x0f)+1;
rxRemaining = (rxBuf[1] & 0x0f) + 1;
break;
// First frame
case 1:
rxRemaining = ((rxBuf[0] & 0x0f) << 8) + rxBuf[1]+1;
rxRemaining = ((rxBuf[0] & 0x0f) << 8) + rxBuf[1] + 1;
liveData->responseRowMerged = "";
for (uint16_t i = 0; i < 62; i++)
liveData->responseRowMerged += "00";
liveData->responseRow = "0:";
start = 2;
break;
@@ -249,7 +252,19 @@ bool CommObd2Can::processFrame() {
Serial.print(rxRemaining);
Serial.println(" ");
parseResponse();
//parseResponse();
// We need to sort frames
// 1 frame data
Serial.println(liveData->responseRow);
// Merge frames 0:xxxx 1:yyyy 2:zzzz to single response xxxxyyyyzzzz string
if (liveData->responseRow.length() >= 2 && liveData->responseRow.charAt(1) == ':') {
//liveData->responseRowMerged += liveData->responseRow.substring(2);
uint8_t rowNo = liveData->hexToDec(liveData->responseRow.substring(0, 1), 1, false);
uint16_t startPos = (rowNo * 14) - ((rowNo > 0) ? 2 : 0);
uint16_t endPos = ((rowNo + 1) * 14) - ((rowNo > 0) ? 2 : 0);
liveData->responseRowMerged = liveData->responseRowMerged.substring(0, startPos) + liveData->responseRow.substring(2) + liveData->responseRowMerged.substring(endPos);
Serial.println(liveData->responseRowMerged);
}
// Send command to board module (obd2 simulation)
if (rxRemaining <= 0) {