You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
20 lines
576 B
20 lines
576 B
1 week ago
|
#pragma once
|
||
|
#include "opendbc/safety/board/drivers/can_common_declarations.h"
|
||
|
|
||
|
uint8_t calculate_checksum(const uint8_t *dat, uint32_t len) {
|
||
|
uint8_t checksum = 0U;
|
||
|
for (uint32_t i = 0U; i < len; i++) {
|
||
|
checksum ^= dat[i];
|
||
|
}
|
||
|
return checksum;
|
||
|
}
|
||
|
|
||
|
void can_set_checksum(CANPacket_t *packet) {
|
||
|
packet->checksum = 0U;
|
||
|
packet->checksum = calculate_checksum((uint8_t *) packet, CANPACKET_HEAD_SIZE + GET_LEN(packet));
|
||
|
}
|
||
|
|
||
|
bool can_check_checksum(CANPacket_t *packet) {
|
||
|
return (calculate_checksum((uint8_t *) packet, CANPACKET_HEAD_SIZE + GET_LEN(packet)) == 0U);
|
||
|
}
|