26 #ifndef _icl_hardware_can_CANMESSAGEHELPER_H 27 #define _icl_hardware_can_CANMESSAGEHELPER_H 39 void constructCanMessageData(
unsigned char *_data,
int value,
const unsigned int start_bit,
const unsigned int signal_length,
bool little_endian)
41 assert(start_bit > 0);
42 assert(signal_length > 0);
43 assert((start_bit-1)+signal_length <= 64);
50 unsigned int number_of_bytes =
static_cast<unsigned int>(((signal_length-1)/8))+1;
54 for (
unsigned int i= 0; i < number_of_bytes; ++i)
57 tmp_data |= (data & 0xFF);
62 if (signal_length < 8)
64 offset =2*(start_bit%8 == 0? 1:start_bit%8)-8;
69 data <<= 64 - (start_bit-offset) - signal_length;
72 for (
int i=7; i >= 0; --i)
74 _data[i] =
static_cast<unsigned char>(data & 0xFF);
79 double parseCanMessage(
const tCanMessage &message,
const unsigned int start_bit,
const unsigned int signal_length,
const bool little_endian,
const bool signedness,
const double factor,
const double offset)
115 uint8_t bit_len = signal_length;
116 uint8_t start_offset = (start_bit-1) & 7;
117 uint8_t start_byte = (start_bit-1) / 8;
124 if(little_endian ==
false) {
125 uint8_t end_byte = start_byte + (7 + bit_len - start_offset - 1)/8;
126 uint8_t end_offset = (start_offset - bit_len + 1) & 7;
129 for(work_byte = start_byte; work_byte <= end_byte; work_byte++) {
131 data = message.
data[work_byte];
134 if(work_byte == start_byte && start_offset != 7) {
136 data &= (
uint8_t)~0 >> (7 - start_offset);
137 shift = start_offset + 1;
141 if(work_byte == end_byte && end_offset != 0) {
153 uint8_t end_byte = start_byte + (bit_len + start_offset - 1)/8;
154 uint8_t end_offset = (start_offset + bit_len - 1) & 7;
156 for(work_byte = end_byte; work_byte >= start_byte; work_byte--) {
157 data = message.
data[work_byte];
158 if(work_byte == end_byte && end_offset != 7) {
159 data &= (
uint8_t)~0 >> (7 - end_offset);
160 shift = end_offset + 1;
164 if(work_byte == start_byte && start_offset != 0) {
165 data >>= start_offset;
166 shift -= start_offset;
173 double physicalValue;
176 if(signedness && (bit_len < 32)) {
178 rawValue = ((
int32_t)rawValue ^ m) - m;
193 physicalValue = (double)(
int32_t)rawValue
196 physicalValue = (double) rawValue
199 return physicalValue;
202 template <
typename T>
204 const unsigned int start_bit,
205 const unsigned int signal_length,
208 const T lower_border,
209 const T upper_border,
210 const bool little_endian,
211 const bool signedness,
214 data =
static_cast<T
>(
parseCanMessage(message, start_bit, signal_length, little_endian, signedness, factor, offset));
215 if ( (data < lower_border) || (data > upper_border) )
222 template <
typename T>
238 #endif // _icl_hardware_can_CANMESSAGEHELPER_H
Implements a struct representing a can message.
unsigned int signal_length
This modul constructs a map of a can-mask-file the map can be request by getcanmatrix() ...
Contains CAN driver interface functions.
void constructCanMessageData(unsigned char *_data, int value, const unsigned int start_bit, const unsigned int signal_length, bool little_endian)
double parseCanMessage(const tCanMessage &message, const unsigned int start_bit, const unsigned int signal_length, const bool little_endian, const bool signedness, const double factor, const double offset)