mirror of https://github.com/rusefi/opendbc.git
Chrysler: calculate checksum in can packer/parser (#255)
* calculate chrysler checksum in can packer/parser * remove comment
This commit is contained in:
parent
0c0215516f
commit
7f3b1774dd
|
@ -35,6 +35,38 @@ unsigned int subaru_checksum(unsigned int address, uint64_t d, int l) {
|
||||||
return s & 0xFF;
|
return s & 0xFF;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsigned int chrysler_checksum(unsigned int address, uint64_t d, int l) {
|
||||||
|
/* This function does not want the checksum byte in the input data.
|
||||||
|
jeep chrysler canbus checksum from http://illmatics.com/Remote%20Car%20Hacking.pdf */
|
||||||
|
uint8_t checksum = 0xFF;
|
||||||
|
for (int j = 0; j < (l - 1); j++) {
|
||||||
|
uint8_t shift = 0x80;
|
||||||
|
uint8_t curr = (d >> 8*j) & 0xFF;
|
||||||
|
for (int i=0; i<8; i++) {
|
||||||
|
uint8_t bit_sum = curr & shift;
|
||||||
|
uint8_t temp_chk = checksum & 0x80U;
|
||||||
|
if (bit_sum != 0U) {
|
||||||
|
bit_sum = 0x1C;
|
||||||
|
if (temp_chk != 0U) {
|
||||||
|
bit_sum = 1;
|
||||||
|
}
|
||||||
|
checksum = checksum << 1;
|
||||||
|
temp_chk = checksum | 1U;
|
||||||
|
bit_sum ^= temp_chk;
|
||||||
|
} else {
|
||||||
|
if (temp_chk != 0U) {
|
||||||
|
bit_sum = 0x1D;
|
||||||
|
}
|
||||||
|
checksum = checksum << 1;
|
||||||
|
bit_sum ^= checksum;
|
||||||
|
}
|
||||||
|
checksum = bit_sum;
|
||||||
|
shift = shift >> 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ~checksum & 0xFF;
|
||||||
|
}
|
||||||
|
|
||||||
// Static lookup table for fast computation of CRC8 poly 0x2F, aka 8H2F/AUTOSAR
|
// Static lookup table for fast computation of CRC8 poly 0x2F, aka 8H2F/AUTOSAR
|
||||||
uint8_t crc8_lut_8h2f[256];
|
uint8_t crc8_lut_8h2f[256];
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
unsigned int honda_checksum(unsigned int address, uint64_t d, int l);
|
unsigned int honda_checksum(unsigned int address, uint64_t d, int l);
|
||||||
unsigned int toyota_checksum(unsigned int address, uint64_t d, int l);
|
unsigned int toyota_checksum(unsigned int address, uint64_t d, int l);
|
||||||
unsigned int subaru_checksum(unsigned int address, uint64_t d, int l);
|
unsigned int subaru_checksum(unsigned int address, uint64_t d, int l);
|
||||||
|
unsigned int chrysler_checksum(unsigned int address, uint64_t d, int l);
|
||||||
void init_crc_lookup_tables();
|
void init_crc_lookup_tables();
|
||||||
unsigned int volkswagen_crc(unsigned int address, uint64_t d, int l);
|
unsigned int volkswagen_crc(unsigned int address, uint64_t d, int l);
|
||||||
unsigned int pedal_checksum(uint64_t d, int l);
|
unsigned int pedal_checksum(uint64_t d, int l);
|
||||||
|
|
|
@ -19,7 +19,8 @@ cdef extern from "common_dbc.h":
|
||||||
PEDAL_COUNTER,
|
PEDAL_COUNTER,
|
||||||
VOLKSWAGEN_CHECKSUM,
|
VOLKSWAGEN_CHECKSUM,
|
||||||
VOLKSWAGEN_COUNTER,
|
VOLKSWAGEN_COUNTER,
|
||||||
SUBARU_CHECKSUM
|
SUBARU_CHECKSUM,
|
||||||
|
CHRYSLER_CHECKSUM
|
||||||
|
|
||||||
cdef struct Signal:
|
cdef struct Signal:
|
||||||
const char* name
|
const char* name
|
||||||
|
|
|
@ -39,6 +39,7 @@ enum SignalType {
|
||||||
VOLKSWAGEN_CHECKSUM,
|
VOLKSWAGEN_CHECKSUM,
|
||||||
VOLKSWAGEN_COUNTER,
|
VOLKSWAGEN_COUNTER,
|
||||||
SUBARU_CHECKSUM,
|
SUBARU_CHECKSUM,
|
||||||
|
CHRYSLER_CHECKSUM,
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Signal {
|
struct Signal {
|
||||||
|
|
|
@ -31,6 +31,8 @@ const Signal sigs_{{address}}[] = {
|
||||||
.type = SignalType::VOLKSWAGEN_COUNTER,
|
.type = SignalType::VOLKSWAGEN_COUNTER,
|
||||||
{% elif checksum_type == "subaru" and sig.name == "CHECKSUM" %}
|
{% elif checksum_type == "subaru" and sig.name == "CHECKSUM" %}
|
||||||
.type = SignalType::SUBARU_CHECKSUM,
|
.type = SignalType::SUBARU_CHECKSUM,
|
||||||
|
{% elif checksum_type == "chrysler" and sig.name == "CHECKSUM" %}
|
||||||
|
.type = SignalType::CHRYSLER_CHECKSUM,
|
||||||
{% elif address in [512, 513] and sig.name == "CHECKSUM_PEDAL" %}
|
{% elif address in [512, 513] and sig.name == "CHECKSUM_PEDAL" %}
|
||||||
.type = SignalType::PEDAL_CHECKSUM,
|
.type = SignalType::PEDAL_CHECKSUM,
|
||||||
{% elif address in [512, 513] and sig.name == "COUNTER_PEDAL" %}
|
{% elif address in [512, 513] and sig.name == "COUNTER_PEDAL" %}
|
||||||
|
|
|
@ -102,6 +102,9 @@ uint64_t CANPacker::pack(uint32_t address, const std::vector<SignalPackValue> &s
|
||||||
} else if (sig.type == SignalType::SUBARU_CHECKSUM) {
|
} else if (sig.type == SignalType::SUBARU_CHECKSUM) {
|
||||||
unsigned int chksm = subaru_checksum(address, ret, message_lookup[address].size);
|
unsigned int chksm = subaru_checksum(address, ret, message_lookup[address].size);
|
||||||
ret = set_value(ret, sig, chksm);
|
ret = set_value(ret, sig, chksm);
|
||||||
|
} else if (sig.type == SignalType::CHRYSLER_CHECKSUM) {
|
||||||
|
unsigned int chksm = chrysler_checksum(address, ReverseBytes(ret), message_lookup[address].size);
|
||||||
|
ret = set_value(ret, sig, chksm);
|
||||||
} else {
|
} else {
|
||||||
//WARN("CHECKSUM signal type not valid\n");
|
//WARN("CHECKSUM signal type not valid\n");
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,6 +57,11 @@ bool MessageState::parse(uint64_t sec, uint16_t ts_, uint8_t * dat) {
|
||||||
if (!update_counter_generic(tmp, sig.b2)) {
|
if (!update_counter_generic(tmp, sig.b2)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
} else if (sig.type == SignalType::CHRYSLER_CHECKSUM) {
|
||||||
|
if (chrysler_checksum(address, dat_le, size) != tmp) {
|
||||||
|
INFO("0x%X CHECKSUM FAIL\n", address);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
} else if (sig.type == SignalType::PEDAL_CHECKSUM) {
|
} else if (sig.type == SignalType::PEDAL_CHECKSUM) {
|
||||||
if (pedal_checksum(dat_be, size) != tmp) {
|
if (pedal_checksum(dat_be, size) != tmp) {
|
||||||
INFO("0x%X PEDAL CHECKSUM FAIL\n", address);
|
INFO("0x%X PEDAL CHECKSUM FAIL\n", address);
|
||||||
|
|
|
@ -53,6 +53,13 @@ def process(in_fn, out_fn):
|
||||||
checksum_start_bit = 0
|
checksum_start_bit = 0
|
||||||
counter_start_bit = None
|
counter_start_bit = None
|
||||||
little_endian = True
|
little_endian = True
|
||||||
|
elif can_dbc.name.startswith(("chrysler_")):
|
||||||
|
checksum_type = "chrysler"
|
||||||
|
checksum_size = 8
|
||||||
|
counter_size = None
|
||||||
|
checksum_start_bit = 7
|
||||||
|
counter_start_bit = None
|
||||||
|
little_endian = False
|
||||||
else:
|
else:
|
||||||
checksum_type = None
|
checksum_type = None
|
||||||
checksum_size = None
|
checksum_size = None
|
||||||
|
|
Loading…
Reference in New Issue