diff --git a/can/common.cc b/can/common.cc index 37b48fa6aa..9076aee81f 100644 --- a/can/common.cc +++ b/can/common.cc @@ -244,3 +244,21 @@ unsigned int hkg_can_fd_checksum(uint32_t address, const Signal &sig, const std: return crc; } + +unsigned int ocelot_checksum(uint32_t address, const Signal &sig, const std::vector &d) { + uint8_t crc = 0xFF; + uint8_t poly = 0x1D; // standard crc8 + + // skip checksum byte + for (int i = 1; i < d.size(); i++) { + crc ^= d[i]; + for (int j = 0; j < 8; j++) { + if ((crc & 0x80) != 0) { + crc = (uint8_t)((crc << 1) ^ poly); + } else { + crc <<= 1; + } + } + } + return crc; +} \ No newline at end of file diff --git a/can/common.h b/can/common.h index 03b99e5598..e38ae72b77 100644 --- a/can/common.h +++ b/can/common.h @@ -34,6 +34,7 @@ unsigned int volkswagen_mqb_checksum(uint32_t address, const Signal &sig, const unsigned int xor_checksum(uint32_t address, const Signal &sig, const std::vector &d); unsigned int hkg_can_fd_checksum(uint32_t address, const Signal &sig, const std::vector &d); unsigned int pedal_checksum(uint32_t address, const Signal &sig, const std::vector &d); +unsigned int ocelot_checksum(uint32_t address, const Signal &sig, const std::vector &d); class MessageState { public: diff --git a/can/common.pxd b/can/common.pxd index 477f71b2d3..78fa960b5e 100644 --- a/can/common.pxd +++ b/can/common.pxd @@ -22,6 +22,8 @@ cdef extern from "common_dbc.h": SUBARU_CHECKSUM, CHRYSLER_CHECKSUM HKG_CAN_FD_CHECKSUM, + OCELOT_CHECKSUM, + OCELOT_COUNTER, cdef struct Signal: string name diff --git a/can/common_dbc.h b/can/common_dbc.h index ef4c98c803..58ceeaaffd 100644 --- a/can/common_dbc.h +++ b/can/common_dbc.h @@ -29,6 +29,8 @@ enum SignalType { SUBARU_CHECKSUM, CHRYSLER_CHECKSUM, HKG_CAN_FD_CHECKSUM, + OCELOT_CHECKSUM, + OCELOT_COUNTER, }; struct Signal { diff --git a/can/dbc.cc b/can/dbc.cc index 7abe6b679c..793077c040 100644 --- a/can/dbc.cc +++ b/can/dbc.cc @@ -67,6 +67,8 @@ ChecksumState* get_checksum(const std::string& dbc_name) { s = new ChecksumState({8, -1, 7, -1, false, CHRYSLER_CHECKSUM, &chrysler_checksum}); } else if (startswith(dbc_name, "comma_body")) { s = new ChecksumState({8, 4, 7, 3, false, PEDAL_CHECKSUM, &pedal_checksum}); + } else if (startswith(dbc_name, "ocelot_")) { + s = new ChecksumState({8, 4, 0, 0, true, OCELOT_CHECKSUM, &ocelot_checksum}); } return s; }