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.
		
		
		
		
		
			
		
			
				
					
					
						
							18 lines
						
					
					
						
							534 B
						
					
					
				
			
		
		
	
	
							18 lines
						
					
					
						
							534 B
						
					
					
				#include "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);
 | 
						|
}
 | 
						|
 |