Skip to content

Commit

Permalink
synchronize function signatures
Browse files Browse the repository at this point in the history
  • Loading branch information
jyoung8607 committed Jun 22, 2022
1 parent 5e2a820 commit 5abd736
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 37 deletions.
14 changes: 7 additions & 7 deletions can/common.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "common.h"

unsigned int honda_checksum(uint32_t address, const std::vector<uint8_t> &d) {
unsigned int honda_checksum(uint32_t address, const Signal &sig, const std::vector<uint8_t> &d) {
int s = 0;
bool extended = address > 0x7FF;
while (address) { s += (address & 0xF); address >>= 4; }
Expand All @@ -15,15 +15,15 @@ unsigned int honda_checksum(uint32_t address, const std::vector<uint8_t> &d) {
return s & 0xF;
}

unsigned int toyota_checksum(uint32_t address, const std::vector<uint8_t> &d) {
unsigned int toyota_checksum(uint32_t address, const Signal &sig, const std::vector<uint8_t> &d) {
unsigned int s = d.size();
while (address) { s += address & 0xFF; address >>= 8; }
for (int i = 0; i < d.size() - 1; i++) { s += d[i]; }

return s & 0xFF;
}

unsigned int subaru_checksum(uint32_t address, const std::vector<uint8_t> &d) {
unsigned int subaru_checksum(uint32_t address, const Signal &sig, const std::vector<uint8_t> &d) {
unsigned int s = 0;
while (address) { s += address & 0xFF; address >>= 8; }

Expand All @@ -33,7 +33,7 @@ unsigned int subaru_checksum(uint32_t address, const std::vector<uint8_t> &d) {
return s & 0xFF;
}

unsigned int chrysler_checksum(uint32_t address, const std::vector<uint8_t> &d) {
unsigned int chrysler_checksum(uint32_t address, const Signal &sig, const std::vector<uint8_t> &d) {
/* jeep chrysler canbus checksum from http://illmatics.com/Remote%20Car%20Hacking.pdf */
uint8_t checksum = 0xFF;
for (int j = 0; j < (d.size() - 1); j++) {
Expand Down Expand Up @@ -107,7 +107,7 @@ void init_crc_lookup_tables() {
gen_crc_lookup_table_16(0x1021, crc16_lut_xmodem); // CRC-16 XMODEM for HKG CAN FD
}

unsigned int volkswagen_crc(uint32_t address, const std::vector<uint8_t> &d) {
unsigned int volkswagen_mqb_checksum(uint32_t address, const Signal &sig, const std::vector<uint8_t> &d) {
// Volkswagen uses standard CRC8 8H2F/AUTOSAR, but they compute it with
// a magic variable padding byte tacked onto the end of the payload.
// https://www.autosar.org/fileadmin/user_upload/standards/classic/4-3/AUTOSAR_SWS_CRCLibrary.pdf
Expand Down Expand Up @@ -188,7 +188,7 @@ unsigned int volkswagen_crc(uint32_t address, const std::vector<uint8_t> &d) {
return crc ^ 0xFF; // Return after standard final XOR for CRC8 8H2F/AUTOSAR
}

unsigned int pedal_checksum(const std::vector<uint8_t> &d) {
unsigned int pedal_checksum(uint32_t address, const Signal &sig, const std::vector<uint8_t> &d) {
uint8_t crc = 0xFF;
uint8_t poly = 0xD5; // standard crc8

Expand All @@ -206,7 +206,7 @@ unsigned int pedal_checksum(const std::vector<uint8_t> &d) {
return crc;
}

unsigned int hkg_can_fd_checksum(uint32_t address, const std::vector<uint8_t> &d) {
unsigned int hkg_can_fd_checksum(uint32_t address, const Signal &sig, const std::vector<uint8_t> &d) {

uint16_t crc = 0;

Expand Down
14 changes: 7 additions & 7 deletions can/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@
void init_crc_lookup_tables();

// Car specific functions
unsigned int honda_checksum(uint32_t address, const std::vector<uint8_t> &d);
unsigned int toyota_checksum(uint32_t address, const std::vector<uint8_t> &d);
unsigned int subaru_checksum(uint32_t address, const std::vector<uint8_t> &d);
unsigned int chrysler_checksum(uint32_t address, const std::vector<uint8_t> &d);
unsigned int volkswagen_crc(uint32_t address, const std::vector<uint8_t> &d);
unsigned int hkg_can_fd_checksum(uint32_t address, const std::vector<uint8_t> &d);
unsigned int pedal_checksum(const std::vector<uint8_t> &d);
unsigned int honda_checksum(uint32_t address, const Signal &sig, const std::vector<uint8_t> &d);
unsigned int toyota_checksum(uint32_t address, const Signal &sig, const std::vector<uint8_t> &d);
unsigned int subaru_checksum(uint32_t address, const Signal &sig, const std::vector<uint8_t> &d);
unsigned int chrysler_checksum(uint32_t address, const Signal &sig, const std::vector<uint8_t> &d);
unsigned int volkswagen_mqb_checksum(uint32_t address, const Signal &sig, const std::vector<uint8_t> &d);
unsigned int hkg_can_fd_checksum(uint32_t address, const Signal &sig, const std::vector<uint8_t> &d);
unsigned int pedal_checksum(uint32_t address, const Signal &sig, const std::vector<uint8_t> &d);

class MessageState {
public:
Expand Down
4 changes: 2 additions & 2 deletions can/common.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ cdef extern from "common_dbc.h":
TOYOTA_CHECKSUM,
PEDAL_CHECKSUM,
PEDAL_COUNTER,
VOLKSWAGEN_CHECKSUM,
VOLKSWAGEN_COUNTER,
VOLKSWAGEN_MQB_CHECKSUM,
VOLKSWAGEN_MQB_COUNTER,
SUBARU_CHECKSUM,
CHRYSLER_CHECKSUM
HKG_CAN_FD_CHECKSUM,
Expand Down
4 changes: 2 additions & 2 deletions can/common_dbc.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ enum SignalType {
TOYOTA_CHECKSUM,
PEDAL_CHECKSUM,
PEDAL_COUNTER,
VOLKSWAGEN_CHECKSUM,
VOLKSWAGEN_COUNTER,
VOLKSWAGEN_MQB_CHECKSUM,
VOLKSWAGEN_MQB_COUNTER,
SUBARU_CHECKSUM,
CHRYSLER_CHECKSUM,
HKG_CAN_FD_CHECKSUM,
Expand Down
4 changes: 2 additions & 2 deletions can/dbc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ ChecksumState* get_checksum(const std::string& dbc_name) {
s = new ChecksumState({8, -1, 7, -1, false, TOYOTA_CHECKSUM});
} else if (startswith(dbc_name, "kia_ev6")) {
s = new ChecksumState({16, 8, 0, 0, true, HKG_CAN_FD_CHECKSUM, HKG_CAN_FD_COUNTER});
} else if (startswith(dbc_name, {"vw_", "volkswagen_", "audi_", "seat_", "skoda_"})) {
s = new ChecksumState({8, 4, 0, 0, true, VOLKSWAGEN_CHECKSUM, VOLKSWAGEN_COUNTER});
} else if (startswith(dbc_name, {"vw_mqb_2010"})) {
s = new ChecksumState({8, 4, 0, 0, true, VOLKSWAGEN_MQB_CHECKSUM, VOLKSWAGEN_MQB_COUNTER});
} else if (startswith(dbc_name, "subaru_global_")) {
s = new ChecksumState({8, -1, 0, -1, true, SUBARU_CHECKSUM});
} else if (startswith(dbc_name, "chrysler_")) {
Expand Down
18 changes: 9 additions & 9 deletions can/packer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ std::vector<uint8_t> CANPacker::pack(uint32_t address, const std::vector<SignalP
}
const auto& sig = sig_it->second;

if ((sig.type != SignalType::HONDA_COUNTER) && (sig.type != SignalType::VOLKSWAGEN_COUNTER)) {
if ((sig.type != SignalType::HONDA_COUNTER) && (sig.type != SignalType::VOLKSWAGEN_MQB_COUNTER)) {
//WARN("COUNTER signal type not valid\n");
}

Expand All @@ -82,25 +82,25 @@ std::vector<uint8_t> CANPacker::pack(uint32_t address, const std::vector<SignalP
if (sig_it_checksum != signal_lookup.end()) {
const auto &sig = sig_it_checksum->second;
if (sig.type == SignalType::HONDA_CHECKSUM) {
unsigned int chksm = honda_checksum(address, ret);
unsigned int chksm = honda_checksum(address, sig, ret);
set_value(ret, sig, chksm);
} else if (sig.type == SignalType::TOYOTA_CHECKSUM) {
unsigned int chksm = toyota_checksum(address, ret);
unsigned int chksm = toyota_checksum(address, sig, ret);
set_value(ret, sig, chksm);
} else if (sig.type == SignalType::VOLKSWAGEN_CHECKSUM) {
unsigned int chksm = volkswagen_crc(address, ret);
} else if (sig.type == SignalType::VOLKSWAGEN_MQB_CHECKSUM) {
unsigned int chksm = volkswagen_mqb_checksum(address, sig, ret);
set_value(ret, sig, chksm);
} else if (sig.type == SignalType::SUBARU_CHECKSUM) {
unsigned int chksm = subaru_checksum(address, ret);
unsigned int chksm = subaru_checksum(address, sig, ret);
set_value(ret, sig, chksm);
} else if (sig.type == SignalType::CHRYSLER_CHECKSUM) {
unsigned int chksm = chrysler_checksum(address, ret);
unsigned int chksm = chrysler_checksum(address, sig, ret);
set_value(ret, sig, chksm);
} else if (sig.type == SignalType::PEDAL_CHECKSUM) {
unsigned int chksm = pedal_checksum(ret);
unsigned int chksm = pedal_checksum(address, sig, ret);
set_value(ret, sig, chksm);
} else if (sig.type == SignalType::HKG_CAN_FD_CHECKSUM) {
unsigned int chksm = hkg_can_fd_checksum(address, ret);
unsigned int chksm = hkg_can_fd_checksum(address, sig, ret);
set_value(ret, sig, chksm);
} else {
//WARN("CHECKSUM signal type not valid\n");
Expand Down
16 changes: 8 additions & 8 deletions can/parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,26 +45,26 @@ bool MessageState::parse(uint64_t sec, const std::vector<uint8_t> &dat) {

bool checksum_failed = false;
if (!ignore_checksum) {
if (sig.type == SignalType::HONDA_CHECKSUM && honda_checksum(address, dat) != tmp) {
if (sig.type == SignalType::HONDA_CHECKSUM && honda_checksum(address, sig, dat) != tmp) {
checksum_failed = true;
} else if (sig.type == SignalType::TOYOTA_CHECKSUM && toyota_checksum(address, dat) != tmp) {
} else if (sig.type == SignalType::TOYOTA_CHECKSUM && toyota_checksum(address, sig, dat) != tmp) {
checksum_failed = true;
} else if (sig.type == SignalType::VOLKSWAGEN_CHECKSUM && volkswagen_crc(address, dat) != tmp) {
} else if (sig.type == SignalType::VOLKSWAGEN_MQB_CHECKSUM && volkswagen_mqb_checksum(address, sig, dat) != tmp) {
checksum_failed = true;
} else if (sig.type == SignalType::SUBARU_CHECKSUM && subaru_checksum(address, dat) != tmp) {
} else if (sig.type == SignalType::SUBARU_CHECKSUM && subaru_checksum(address, sig, dat) != tmp) {
checksum_failed = true;
} else if (sig.type == SignalType::CHRYSLER_CHECKSUM && chrysler_checksum(address, dat) != tmp) {
} else if (sig.type == SignalType::CHRYSLER_CHECKSUM && chrysler_checksum(address, sig, dat) != tmp) {
checksum_failed = true;
} else if (sig.type == SignalType::HKG_CAN_FD_CHECKSUM && hkg_can_fd_checksum(address, dat) != tmp) {
} else if (sig.type == SignalType::HKG_CAN_FD_CHECKSUM && hkg_can_fd_checksum(address, sig, dat) != tmp) {
checksum_failed = true;
} else if (sig.type == SignalType::PEDAL_CHECKSUM && pedal_checksum(dat) != tmp) {
} else if (sig.type == SignalType::PEDAL_CHECKSUM && pedal_checksum(address, sig, dat) != tmp) {
checksum_failed = true;
}
}

bool counter_failed = false;
if (!ignore_counter) {
if (sig.type == SignalType::HONDA_COUNTER || sig.type == SignalType::VOLKSWAGEN_COUNTER || sig.type == SignalType::PEDAL_COUNTER) {
if (sig.type == SignalType::HONDA_COUNTER || sig.type == SignalType::VOLKSWAGEN_MQB_COUNTER || sig.type == SignalType::PEDAL_COUNTER) {
counter_failed = !update_counter_generic(tmp, sig.size);
}
}
Expand Down

0 comments on commit 5abd736

Please sign in to comment.