Skip to content

Commit

Permalink
maybe fix obd response byte order
Browse files Browse the repository at this point in the history
  • Loading branch information
mck1117 committed Jan 10, 2025
1 parent c4a50ad commit 39b10cf
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions firmware/controllers/can/obd2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,12 +209,17 @@ static void handleGetDataRequest(uint8_t length, const CANRxFrame& rx, CanBusInd
}
}

static void writeDtc(CanTxMessage& msg, size_t offset, ObdCode code) {
msg[offset + 0] = (static_cast<uint16_t>(code) >> 8) & 0xFF;
msg[offset + 1] = (static_cast<uint16_t>(code) >> 0) & 0xFF;
}

static void handleDtcRequest(uint8_t service, int numCodes, ObdCode* dtcCode, CanBusIndex busIndex) {
// Hack: only report first two codes as multi-frame response isn't ready
// Hack: only report first two codes as multi-frame response isn't ready
if (numCodes > 2) {
numCodes = 2;
}

if (numCodes == 0) {
// No DTCs: Respond with no trouble codes
CanTxMessage tx(OBD_TEST_RESPONSE, 8, busIndex, false);
Expand All @@ -230,7 +235,7 @@ static void handleDtcRequest(uint8_t service, int numCodes, ObdCode* dtcCode, Ca

for (int i = 0; i < numCodes; i++) {
int dest = 3 + 2 * i;
tx.setShortValue(static_cast<uint16_t>(dtcCode[i]), dest);
writeDtc(tx, dest, dtcCode[i]);
}
} else {
// Too many codes for a single frame, respond in multiple
Expand Down

0 comments on commit 39b10cf

Please sign in to comment.