Added mazda radar checksum to opendbc

This commit is contained in:
Ryley
2022-04-21 19:58:11 -05:00
parent 016e69a2db
commit 2bf9f77354
7 changed files with 24 additions and 1 deletions
+8
View File
@@ -69,6 +69,14 @@ unsigned int chrysler_checksum(unsigned int address, uint64_t d, int l) {
return ~checksum & 0xFF;
}
uint8_t mazda_checksum(uint64_t data) {
uint8_t sum = 0;
for (int i = 0; i < 8; i++) {
sum += data >> (56 - 8*i);
}
return ~sum;
}
// Static lookup table for fast computation of CRC8 poly 0x2F, aka 8H2F/AUTOSAR
uint8_t crc8_lut_8h2f[256];
+1
View File
@@ -19,6 +19,7 @@ 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 subaru_checksum(unsigned int address, uint64_t d, int l);
unsigned int chrysler_checksum(unsigned int address, uint64_t d, int l);
uint8_t mazda_checksum(uint64_t data);
void init_crc_lookup_tables();
unsigned int volkswagen_crc(unsigned int address, uint64_t d, int l);
unsigned int pedal_checksum(uint64_t d, int l);
+2 -1
View File
@@ -20,7 +20,8 @@ cdef extern from "common_dbc.h":
VOLKSWAGEN_CHECKSUM,
VOLKSWAGEN_COUNTER,
SUBARU_CHECKSUM,
CHRYSLER_CHECKSUM
CHRYSLER_CHECKSUM,
MAZDA_CHECKSUM
cdef struct Signal:
const char* name
+1
View File
@@ -41,6 +41,7 @@ enum SignalType {
VOLKSWAGEN_COUNTER,
SUBARU_CHECKSUM,
CHRYSLER_CHECKSUM,
MAZDA_CHECKSUM,
};
struct Signal {
+2
View File
@@ -33,6 +33,8 @@ const Signal sigs_{{address}}[] = {
.type = SignalType::SUBARU_CHECKSUM,
{% elif checksum_type == "chrysler" and sig.name == "CHECKSUM" %}
.type = SignalType::CHRYSLER_CHECKSUM,
{% elif checksum_type == "mazda" and sig.name == "CHECKSUM" %}
.type = SignalType::MAZDA_CHECKSUM,
{% elif address in [512, 513] and sig.name == "CHECKSUM_PEDAL" %}
.type = SignalType::PEDAL_CHECKSUM,
{% elif address in [512, 513] and sig.name == "COUNTER_PEDAL" %}
+3
View File
@@ -104,6 +104,9 @@ uint64_t CANPacker::pack(uint32_t address, const std::vector<SignalPackValue> &s
} 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 if (sig.type == SignalType::MAZDA_CHECKSUM) {
unsigned int chksm = mazda_checksum(ret);
ret = set_value(ret, sig, chksm);
} else {
//WARN("CHECKSUM signal type not valid\n");
}
+7
View File
@@ -61,6 +61,13 @@ def process(in_fn, out_fn):
checksum_start_bit = 7
counter_start_bit = None
little_endian = False
elif can_dbc.name.startswith(("mazda_")):
checksum_type = "mazda"
checksum_size = 8
counter_size = None
checksum_start_bit = 0
counter_start_bit = None
little_endian = True
else:
checksum_type = None
checksum_size = None