MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / ParseCanMessage

Method ParseCanMessage

lib/mdflib/mdflib/src/canbusobserver.cpp:284–434  ·  view source on GitHub ↗

\brief Converts the record and VLSD record to a CAN message. * * The function convert a CanSample byte buffer, to a CAN message. * @param msg Returning bus message */

Source from the content-addressed store, hash-verified

282 * @param msg Returning bus message
283 */
284void CanBusObserver::ParseCanMessage(CanMessage& msg) const {
285 const auto& record = last_sample_.record;
286 if (time_channel_ != nullptr) {
287 double timestamp = 0.0;
288 GetEngValue(*time_channel_, current_sample_index_, record, timestamp);
289 msg.Timestamp(timestamp);
290 }
291
292 if (bus_channel_ != nullptr) {
293 // Sometimes this is a scaled or fixed value
294 double bus_channel = 0.0;
295 GetEngValue(*bus_channel_, current_sample_index_, record, bus_channel);
296 msg.BusChannel(static_cast<uint8_t>(bus_channel));
297 }
298
299 if (id_channel_ != nullptr) {
300 // This is either CAN ID + IDE flag or the CAN ID.
301 // Therefore add the IDE flag after the CAN ID.
302 uint32_t msg_id = 0;
303 GetChannelValue(*id_channel_, current_sample_index_, record, msg_id);
304 msg.MessageId(msg_id);
305 }
306
307 if (ide_channel_ != nullptr) {
308 bool extended = false;
309 GetChannelValue(*ide_channel_, current_sample_index_, record, extended);
310 msg.ExtendedId(extended);
311 }
312
313 if (dlc_channel_ != nullptr) {
314 uint8_t dlc = 0;
315 GetChannelValue(*dlc_channel_, current_sample_index_, record, dlc);
316 msg.Dlc(dlc);
317 }
318
319 if (length_channel_ != nullptr) {
320 double length = 0.0;
321 GetEngValue(*length_channel_, current_sample_index_, record, length);
322 msg.DataLength(static_cast<uint8_t>(length));
323 }
324
325 if (data_channel_ != nullptr) {
326 switch (channel_group_.StorageType()) {
327 case MdfStorageType::VlsdStorage:
328 msg.DataBytes(last_sample_.vlsd_data);
329 break;
330
331 case MdfStorageType::MlsdStorage: {
332 const uint8_t data_length = msg.DataLength();
333 std::vector<uint8_t> data;
334 GetChannelValue(*data_channel_, current_sample_index_, record, data);
335 if (data_length < data.size()) {
336 data.resize(data_length);
337 }
338 msg.DataBytes(data);
339 break;
340 }
341

Callers

nothing calls this directly

Calls 15

TimestampMethod · 0.80
MessageIdMethod · 0.80
ExtendedIdMethod · 0.80
DlcMethod · 0.80
SrrMethod · 0.80
EdlMethod · 0.80
BrsMethod · 0.80
EsiMethod · 0.80
R0Method · 0.80
R1Method · 0.80
WakeUpMethod · 0.80
SingleWireMethod · 0.80

Tested by

no test coverage detected