Skip to content

Commit

Permalink
WIP: ocelot checksums
Browse files Browse the repository at this point in the history
  • Loading branch information
wocsor committed Oct 10, 2023
1 parent 647fb8a commit adf9f6c
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 0 deletions.
18 changes: 18 additions & 0 deletions can/common.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint8_t> &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;
}
1 change: 1 addition & 0 deletions can/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<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);
unsigned int ocelot_checksum(uint32_t address, const Signal &sig, const std::vector<uint8_t> &d);

class MessageState {
public:
Expand Down
2 changes: 2 additions & 0 deletions can/common.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions can/common_dbc.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ enum SignalType {
SUBARU_CHECKSUM,
CHRYSLER_CHECKSUM,
HKG_CAN_FD_CHECKSUM,
OCELOT_CHECKSUM,
OCELOT_COUNTER,
};

struct Signal {
Expand Down
2 changes: 2 additions & 0 deletions can/dbc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit adf9f6c

Please sign in to comment.