New checksum functions
parent
03b188cb75
commit
dea617297b
|
@ -69,6 +69,7 @@ unsigned int chrysler_checksum(unsigned int address, uint64_t d, int l) {
|
||||||
|
|
||||||
// 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];
|
||||||
|
uint8_t crc8_lut_d5[256];
|
||||||
|
|
||||||
void gen_crc_lookup_table(uint8_t poly, uint8_t crc_lut[]) {
|
void gen_crc_lookup_table(uint8_t poly, uint8_t crc_lut[]) {
|
||||||
uint8_t crc;
|
uint8_t crc;
|
||||||
|
@ -90,6 +91,7 @@ void init_crc_lookup_tables() {
|
||||||
// At init time, set up static lookup tables for fast CRC computation.
|
// At init time, set up static lookup tables for fast CRC computation.
|
||||||
|
|
||||||
gen_crc_lookup_table(0x2F, crc8_lut_8h2f); // CRC-8 8H2F/AUTOSAR for Volkswagen
|
gen_crc_lookup_table(0x2F, crc8_lut_8h2f); // CRC-8 8H2F/AUTOSAR for Volkswagen
|
||||||
|
gen_crc_lookup_table(0xD5, crc8_lut_d5); // CRC-8 for pedal
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int volkswagen_crc(unsigned int address, uint64_t d, int l) {
|
unsigned int volkswagen_crc(unsigned int address, uint64_t d, int l) {
|
||||||
|
@ -190,6 +192,16 @@ unsigned int pedal_checksum(uint64_t d, int l) {
|
||||||
return crc;
|
return crc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsigned int ocelot_checksum(uint64_t d, int l) {
|
||||||
|
uint8_t crc = 0xFF; // Standard init value for CRC8
|
||||||
|
|
||||||
|
// CRC the payload, skipping over the first byte where the CRC lives.
|
||||||
|
for (int i = 1; i < l; i++) {
|
||||||
|
crc ^= (d >> (i*8)) & 0xFF;
|
||||||
|
crc = crc8_lut_d5[crc];
|
||||||
|
}
|
||||||
|
return crc;
|
||||||
|
}
|
||||||
|
|
||||||
uint64_t read_u64_be(const uint8_t* v) {
|
uint64_t read_u64_be(const uint8_t* v) {
|
||||||
return (((uint64_t)v[0] << 56)
|
return (((uint64_t)v[0] << 56)
|
||||||
|
|
|
@ -18,6 +18,7 @@ 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);
|
||||||
|
unsigned int ocelot_checksum(uint64_t d, int l);
|
||||||
uint64_t read_u64_be(const uint8_t* v);
|
uint64_t read_u64_be(const uint8_t* v);
|
||||||
uint64_t read_u64_le(const uint8_t* v);
|
uint64_t read_u64_le(const uint8_t* v);
|
||||||
|
|
||||||
|
|
|
@ -40,6 +40,8 @@ enum SignalType {
|
||||||
VOLKSWAGEN_COUNTER,
|
VOLKSWAGEN_COUNTER,
|
||||||
SUBARU_CHECKSUM,
|
SUBARU_CHECKSUM,
|
||||||
CHRYSLER_CHECKSUM,
|
CHRYSLER_CHECKSUM,
|
||||||
|
OCELOT_CHECKSUM,
|
||||||
|
OCELOT_COUNTER,
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Signal {
|
struct Signal {
|
||||||
|
|
|
@ -37,6 +37,10 @@ const Signal sigs_{{address}}[] = {
|
||||||
.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" %}
|
||||||
.type = SignalType::PEDAL_COUNTER,
|
.type = SignalType::PEDAL_COUNTER,
|
||||||
|
{% if checksum_type == "ocelot" and sig.name == "CHECKSUM" %}
|
||||||
|
.type = SignalType::OCELOT_CHECKSUM,
|
||||||
|
{% elif checksum_type == "ocelot" and sig.name == "COUNTER" %}
|
||||||
|
.type = SignalType::OCELOT_COUNTER,
|
||||||
{% else %}
|
{% else %}
|
||||||
.type = SignalType::DEFAULT,
|
.type = SignalType::DEFAULT,
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
|
@ -77,7 +77,7 @@ uint64_t CANPacker::pack(uint32_t address, const std::vector<SignalPackValue> &s
|
||||||
}
|
}
|
||||||
auto sig = sig_it->second;
|
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_COUNTER) && (sig.type != SignalType::OCELOT_COUNTER)) {
|
||||||
WARN("COUNTER signal type not valid\n");
|
WARN("COUNTER signal type not valid\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -105,7 +105,10 @@ uint64_t CANPacker::pack(uint32_t address, const std::vector<SignalPackValue> &s
|
||||||
} else if (sig.type == SignalType::CHRYSLER_CHECKSUM) {
|
} else if (sig.type == SignalType::CHRYSLER_CHECKSUM) {
|
||||||
unsigned int chksm = chrysler_checksum(address, ReverseBytes(ret), message_lookup[address].size);
|
unsigned int chksm = chrysler_checksum(address, ReverseBytes(ret), message_lookup[address].size);
|
||||||
ret = set_value(ret, sig, chksm);
|
ret = set_value(ret, sig, chksm);
|
||||||
} else {
|
} else if (sig.type == SignalType::OCELOT_CHECKSUM) {
|
||||||
|
unsigned int chksm = chrysler_checksum(ret, message_lookup[address].size);
|
||||||
|
ret = set_value(ret, sig, chksm);
|
||||||
|
else {
|
||||||
//WARN("CHECKSUM signal type not valid\n");
|
//WARN("CHECKSUM signal type not valid\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -76,6 +76,15 @@ 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::OCELOT_CHECKSUM) {
|
||||||
|
if (ocelot_checksum(dat_be, size) != tmp) {
|
||||||
|
INFO("0x%X OCELOT CHECKSUM FAIL\n", address);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else if (sig.type == SignalType::OCELOT_COUNTER) {
|
||||||
|
if (!update_counter_generic(tmp, sig.b2)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
vals[i] = tmp * sig.factor + sig.offset;
|
vals[i] = tmp * sig.factor + sig.offset;
|
||||||
|
|
|
@ -61,6 +61,13 @@ def process(in_fn, out_fn):
|
||||||
checksum_start_bit = 7
|
checksum_start_bit = 7
|
||||||
counter_start_bit = None
|
counter_start_bit = None
|
||||||
little_endian = False
|
little_endian = False
|
||||||
|
elif can_dbc.name.startswith(("ocelot_")):
|
||||||
|
checksum_type = "ocelot"
|
||||||
|
checksum_size = 8
|
||||||
|
counter_size = 4
|
||||||
|
checksum_start_bit = 0
|
||||||
|
counter_start_bit = 4
|
||||||
|
little_endian = True
|
||||||
else:
|
else:
|
||||||
checksum_type = None
|
checksum_type = None
|
||||||
checksum_size = None
|
checksum_size = None
|
||||||
|
|
|
@ -59,21 +59,21 @@ BO_ 512 GAS_COMMAND: 8 EON
|
||||||
SG_ GAS_COMMAND : 7|16@0+ (0.159375,-75.555) [0|1] "" PED
|
SG_ GAS_COMMAND : 7|16@0+ (0.159375,-75.555) [0|1] "" PED
|
||||||
SG_ GAS_COMMAND2 : 23|16@0+ (0.159375,-151.111) [0|1] "" PED
|
SG_ GAS_COMMAND2 : 23|16@0+ (0.159375,-151.111) [0|1] "" PED
|
||||||
SG_ ENABLE : 39|1@0+ (1,0) [0|1] "" PED
|
SG_ ENABLE : 39|1@0+ (1,0) [0|1] "" PED
|
||||||
SG_ COUNTER_PEDAL : 35|4@0+ (1,0) [0|15] "" PED
|
SG_ COUNTER : 32|4@1+ (1,0) [0|15] "" PED
|
||||||
SG_ CHECKSUM_PEDAL : 47|8@0+ (1,0) [0|255] "" PED
|
SG_ CHECKSUM : 40|8@1+ (1,0) [0|255] "" PED
|
||||||
|
|
||||||
BO_ 513 GAS_SENSOR: 8 PED
|
BO_ 513 GAS_SENSOR: 8 PED
|
||||||
SG_ PED_GAS : 7|16@0+ (0.159375,-75.555) [0|1] "" EON
|
SG_ PED_GAS : 7|16@0+ (0.159375,-75.555) [0|1] "" EON
|
||||||
SG_ PED_GAS2 : 23|16@0+ (0.159375,-151.111) [0|1] "" EON
|
SG_ PED_GAS2 : 23|16@0+ (0.159375,-151.111) [0|1] "" EON
|
||||||
SG_ STATE : 39|4@0+ (1,0) [0|15] "" EON
|
SG_ STATE : 39|4@0+ (1,0) [0|15] "" EON
|
||||||
SG_ COUNTER_PEDAL : 35|4@0+ (1,0) [0|15] "" EON
|
SG_ COUNTER : 32|4@1+ (1,0) [0|15] "" EON
|
||||||
SG_ CHECKSUM_PEDAL : 47|8@0+ (1,0) [0|255] "" EON
|
SG_ CHECKSUM : 40|8@1+ (1,0) [0|255] "" EON
|
||||||
|
|
||||||
BO_ 870 CURRENT_STATE: 4 EON
|
BO_ 870 CURRENT_STATE: 4 EON
|
||||||
SG_ ENABLED : 0|1@0+ (1,0) [0|0] "" HIM
|
SG_ ENABLED : 0|1@0+ (1,0) [0|0] "" HIM
|
||||||
SG_ SET_SPEED : 15|8@0+ (1,0) [0|255] "mph" HIM
|
SG_ SET_SPEED : 15|8@0+ (1,0) [0|255] "mph" HIM
|
||||||
SG_ CURRENT_SPEED : 23|8@0+ (1,0) [0|255] "kph" IBST
|
SG_ CURRENT_SPEED : 23|8@0+ (1,0) [0|255] "kph" IBST
|
||||||
SG_ CHECKSUM_CTRLS : 31|8@0+ (1,0) [0|255] "" HIM
|
SG_ CHECKSUM : 24|8@1+ (1,0) [0|255] "" HIM
|
||||||
|
|
||||||
BO_ 869 HIM_CTRLS: 3 HIM
|
BO_ 869 HIM_CTRLS: 3 HIM
|
||||||
SG_ SPEEDDN_BTN : 3|1@0+ (1,0) [0|0] "" EON
|
SG_ SPEEDDN_BTN : 3|1@0+ (1,0) [0|0] "" EON
|
||||||
|
@ -81,7 +81,7 @@ BO_ 869 HIM_CTRLS: 3 HIM
|
||||||
SG_ CANCEL_BTN : 1|1@0+ (1,0) [0|0] "" EON
|
SG_ CANCEL_BTN : 1|1@0+ (1,0) [0|0] "" EON
|
||||||
SG_ SET_BTN : 0|1@0+ (1,0) [0|0] "" EON
|
SG_ SET_BTN : 0|1@0+ (1,0) [0|0] "" EON
|
||||||
SG_ STATE : 11|4@0+ (1,0) [0|15] "" EON
|
SG_ STATE : 11|4@0+ (1,0) [0|15] "" EON
|
||||||
SG_ CHECKSUM_CTRLS : 23|8@0+ (1,0) [0|255] "" EON
|
SG_ CHECKSUM : 16|8@1+ (1,0) [0|255] "" EON
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue