Larus glider flight sensor system 3.9.2024
Software-In-The-Loop test and validation system
Loading...
Searching...
No Matches
generic_CAN_driver.h
Go to the documentation of this file.
1/***********************************************************************/
25#ifndef GENERIC_CAN_DRIVER_H_
26#define GENERIC_CAN_DRIVER_H_
27
28#include "stdint.h"
29
32{
33public:
40 {
41 return (id == right.id) &&
42 (dlc = right.dlc) &&
43 (data_l == right.data_l);
44 }
47 union
48 {
55 float data_f[2];
57 };
58} ;
59
60#pragma pack(push, 2)
61
64{
65public:
67 : ID_checked(p.id),
68 DLC_checksum(p.dlc),
69 data(p.data_l)
70 {
71 uint16_t checksum = ~(p.id % 31);
72 ID_checked |= checksum << 11;
73
74 checksum = (uint16_t) ~(p.data_l % 4095);
75 DLC_checksum |= checksum << 4;
76 }
77
79 {
80 uint16_t checksum = ~((ID_checked & 0x7ff) % 31) & 0x1f;
81 if( ID_checked >> 11 != checksum)
82 return false;
83
84 checksum = ~(data % 4095) & 0xfff;
85 if( DLC_checksum >> 4 != checksum)
86 return false;
87
88 p.id = ID_checked & 0x7ff;
89 p.dlc = DLC_checksum & 0x0f;
90 p.data_l = data;
91
92 return true;
93 }
94
95public:
99};
100
101#pragma pack(pop)
102
104bool CAN_send( const CANpacket &p, unsigned dummy);
105
106#endif /* GENERIC_CAN_DRIVER_H_ */
CAN packet tunneled through USART gateway.
bool to_CANpacket(CANpacket &p)
CAN_gateway_packet(const CANpacket &p)
basic CAN packet type
uint16_t data_h[4]
data seen as 4 times uint16_t
bool operator==(const CANpacket &right)
uint16_t dlc
data length code
int16_t data_sh[4]
data seen as 4 times int16_t
CANpacket(uint16_t _id=0, uint16_t _dlc=0, uint64_t _data=0)
float data_f[2]
data seen as 2 times 32-bit floats
int32_t data_sw[2]
data seen as 2 times int32_t
int8_t data_sb[8]
data seen as 8 times int8_t
uint16_t id
identifier
uint32_t data_w[2]
data seen as 2 times uint32_t
uint8_t data_b[8]
data seen as 8 times uint8_t
uint64_t data_l
data seen as 64-bit integer
mathematical vector of arbitrary type and size
Definition vector.h:40
bool CAN_send(const CANpacket &p, unsigned dummy)
Global CAN send procedure.