HardwareCanFilterInterpretMessage.cpp
Go to the documentation of this file.
1 // this is for emacs file handling -*- mode: c++; indent-tabs-mode: nil -*-
2 
3 // -- BEGIN LICENSE BLOCK ----------------------------------------------
4 // This file is part of FZIs ic_workspace.
5 //
6 // This program is free software licensed under the LGPL
7 // (GNU LESSER GENERAL PUBLIC LICENSE Version 3).
8 // You can find a copy of this license in LICENSE folder in the top
9 // directory of the source code.
10 //
11 // © Copyright 2016 FZI Forschungszentrum Informatik, Karlsruhe, Germany
12 //
13 // -- END LICENSE BLOCK ------------------------------------------------
14 
15 //----------------------------------------------------------------------
22 //----------------------------------------------------------------------
24 
25 #include <icl_core_config/Config.h>
26 #include <icl_sourcesink/SimpleURI.h>
29 
30 namespace icl_hardware {
31 namespace can {
32 
33 HardwareCanFilterInterpretMessage::HardwareCanFilterInterpretMessage(const std::string &uri, const std::string &name)
34  : icl_sourcesink::DataFilter<tCanMessage, InterpretedCanMessages>(uri, name),
35  m_can_mask()
36 {
37  icl_sourcesink::SimpleURI parsed_uri(uri);
38 
39  std::string can_mask = "";
40  boost::optional<std::string> uri_can_mask = parsed_uri.getQuery<std::string>("can_mask");
41  if (uri_can_mask)
42  {
43  can_mask = *uri_can_mask;
44  }
45  else
46  {
47  can_mask = icl_core::config::getDefault<std::string>("/icl_hardware_can/can_mask", "");
48  }
49 
50  // Set CAN mask
51  if (can_mask != "")
52  {
53  tCanMatrixParser parser(can_mask);
54  if (parser.isActive())
55  {
56  m_can_mask = parser.getCanMatrix();
57  LOGGING_DEBUG(CAN, "Using CAN Mask: " << can_mask << endl);
58  }
59  else
60  {
61  LOGGING_WARNING(CAN, "Could not use provided CAN mask " << can_mask << endl);
62  }
63  }
64 }
65 
67 { }
68 
71 {
72  if (input_msg->id == 0 && input_msg->dlc == 0 && input_msg->rtr == 0)
73  {
74  LOGGING_WARNING(CAN, "Received empty message." << endl);
75  return false;
76  }
77 
78  output_msg.header() = input_msg.header();
79  output_msg->clear();
80 
81  CanMatrix::const_iterator mask_iter = m_can_mask.find(input_msg->id);
82  if (mask_iter != m_can_mask.end())
83  {
84  for (std::size_t i = 0; i < mask_iter->second.size(); ++i)
85  {
86  double msg_value;
87  parseCanMessage<double>(*input_msg,
88  mask_iter->second.at(i).start_bit,
89  mask_iter->second.at(i).signal_length,
90  mask_iter->second.at(i).conversion,
91  mask_iter->second.at(i).offset,
92  mask_iter->second.at(i).lower_border,
93  mask_iter->second.at(i).upper_border,
94  mask_iter->second.at(i).little_endian,
95  mask_iter->second.at(i).signedness,
96  msg_value);
97 
98  output_msg->push_back(InterpretedCanMessage(msg_value,
99  mask_iter->second.at(i).description,
100  mask_iter->second.at(i).unit));
101  }
102  }
103 
104  return true;
105 }
106 
107 }
108 }
Implements a struct representing a can message.
Definition: tCanMessage.h:43
virtual DataHeader & header()
virtual bool filter(const icl_core::Stamped< tCanMessage > &input_data, icl_core::Stamped< InterpretedCanMessages > &output_data)
#define LOGGING_DEBUG(streamname, arg)
CanMatrix m_can_mask
Describes how the CAN traffic is to be interpreted.
ThreadStream & endl(ThreadStream &stream)
#define LOGGING_WARNING(streamname, arg)
HardwareCanFilterInterpretMessage(const std::string &uri="HardwareCanFilterInterpretMessage", const std::string &name="UnnamedHardwareCanFilterInterpretMessage")
Constructor.
const CanMatrix & getCanMatrix() const
std::vector< InterpretedCanMessage > InterpretedCanMessages


fzi_icl_can
Author(s):
autogenerated on Mon Jun 10 2019 13:17:02