DbcMessage.cpp
Go to the documentation of this file.
1 /*********************************************************************
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2018 New Eagle
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above
14  * copyright notice, this list of conditions and the following
15  * disclaimer in the documentation and/or other materials provided
16  * with the distribution.
17  * * Neither the name of New Eagle nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  *********************************************************************/
34 
36 
37 #include "DbcUtilities.h"
38 
39 namespace NewEagle
40 {
42  {
43  };
44 
46  uint8_t dlc,
47  uint32_t id,
48  IdType idType,
49  std::string name,
50  uint32_t rawId)
51  {
52  _dlc = dlc;
53  _id = id;
54  _idType = idType;
55  _name = name;
56  _rawId = rawId;
57  }
58 
60  {
61  }
62 
63  uint8_t DbcMessage::GetDlc()
64  {
65  return _dlc;
66  }
67 
68  uint32_t DbcMessage::GetId()
69  {
70  return _id;
71  }
72 
74  {
75  return _rawId;
76  }
77 
79  {
80  return _idType;
81  }
82 
83  std::string DbcMessage::GetName()
84  {
85  return _name;
86  }
87 
88  can_msgs::Frame DbcMessage::GetFrame()
89  {
90  can_msgs::Frame frame;
91 
92  frame.id = _id;
93  frame.dlc = _dlc;
94  frame.is_extended = _idType == EXT;
95 
96  uint8_t *ptr = (uint8_t*)frame.data.elems;
97  memset(ptr, 0x00, 8);
98 
99  if(!AnyMultiplexedSignals()) {
100  for(std::map<std::string, NewEagle::DbcSignal>::iterator it = _signals.begin(); it != _signals.end(); it++) {
101  Pack(ptr, it->second);
102  }
103  }
104  else{
105  // Start by looping through an only setting signals that are not multiplexed
106  // While we're at it, we can pick out the mutliplexer switch.
107  // Perform a second loop to find the mulitplexed signal based on the multiplexer switch.
108 
109  NewEagle::DbcSignal* muxSwitch; // only one multiplexer switch per message is allowed
110 
111  for(std::map<std::string, NewEagle::DbcSignal>::iterator it = _signals.begin(); it != _signals.end(); it++) {
112  if (NewEagle::NONE == it->second.GetMultiplexerMode()) {
113  Pack(ptr, it->second);
114  }
115  if (NewEagle::MUX_SWITCH == it->second.GetMultiplexerMode()) {
116  muxSwitch = &it->second;
117  Pack(ptr, it->second);
118  }
119  }
120 
121  for(std::map<std::string, NewEagle::DbcSignal>::iterator it = _signals.begin(); it != _signals.end(); it++) {
122  if (NewEagle::MUX_SIGNAL == it->second.GetMultiplexerMode()) {
123  if (muxSwitch->GetResult() == it->second.GetMultiplexerSwitch()) {
124  Pack(ptr, it->second);
125  }
126 
127  }
128  }
129  }
130 
131  return frame;
132  }
133 
134  void DbcMessage::SetFrame(const can_msgs::Frame::ConstPtr& msg)
135  {
136  uint8_t *ptr = (uint8_t*)msg->data.elems;
137 
138  if(!AnyMultiplexedSignals()) {
139  for(std::map<std::string, NewEagle::DbcSignal>::iterator it = _signals.begin(); it != _signals.end(); it++) {
140  double res = Unpack(ptr, it->second);
141  it->second.SetResult(res);
142  }
143  }
144  else{
145  // Start by looping through an only setting signals that are not multiplexed
146  // While we're at it, we can pick out the mutliplexer switch.
147  // Perform a second loop to find the mulitplexed signal based on the multiplexer switch.
148 
149  NewEagle::DbcSignal* muxSwitch; // only one multiplexer switch per message is allowed
150 
151  for(std::map<std::string, NewEagle::DbcSignal>::iterator it = _signals.begin(); it != _signals.end(); it++) {
152  if (NewEagle::NONE == it->second.GetMultiplexerMode()) {
153  double res = Unpack(ptr, it->second);
154  it->second.SetResult(res);
155  }
156  if (NewEagle::MUX_SWITCH == it->second.GetMultiplexerMode()) {
157  muxSwitch = &it->second;
158  double res = Unpack(ptr, it->second);
159  it->second.SetResult(res);
160  }
161  }
162 
163  for(std::map<std::string, NewEagle::DbcSignal>::iterator it = _signals.begin(); it != _signals.end(); it++) {
164  if (NewEagle::MUX_SIGNAL == it->second.GetMultiplexerMode()) {
165  if (muxSwitch->GetResult() == it->second.GetMultiplexerSwitch()) {
166  double res = Unpack(ptr, it->second);
167  it->second.SetResult(res);
168  }
169 
170  }
171  }
172  }
173 
174  }
175 
176  void DbcMessage::AddSignal(std::string signalName, NewEagle::DbcSignal signal)
177  {
178  _signals.insert(std::pair<std::string, NewEagle::DbcSignal>(signalName, signal));
179  }
180 
181  NewEagle::DbcSignal* DbcMessage::GetSignal(std::string signalName)
182  {
183  std::map<std::string, NewEagle::DbcSignal>::iterator it;
184 
185  it = _signals.find(signalName);
186 
187  if (_signals.end() == it)
188  {
189  return NULL;
190  }
191 
192  NewEagle::DbcSignal* signal = &it->second;
193 
194  return signal;
195  }
196 
197  void DbcMessage::SetRawText(std::string rawText)
198  {
199 
200  }
201 
202  uint32_t DbcMessage::GetSignalCount()
203  {
204  return _signals.size();
205  }
206 
208  {
209  _comment = comment;
210  }
211 
212  std::map<std::string, NewEagle::DbcSignal>* DbcMessage::GetSignals()
213  {
214  return &_signals;
215  }
216 
218  {
219  for(std::map<std::string, NewEagle::DbcSignal>::iterator it = _signals.begin(); it != _signals.end(); it++)
220  {
221  if (NewEagle::MUX_SWITCH == it->second.GetMultiplexerMode())
222  {
223  return true;
224  }
225  }
226 
227  return false;
228  }
229 }
NewEagle::DbcMessage::GetSignals
std::map< std::string, NewEagle::DbcSignal > * GetSignals()
Definition: DbcMessage.cpp:244
NewEagle::DbcMessage::AddSignal
void AddSignal(std::string signalName, NewEagle::DbcSignal signal)
Definition: DbcMessage.cpp:208
NewEagle::DbcMessage::DbcMessage
DbcMessage()
Definition: DbcMessage.cpp:73
NewEagle::DbcMessage::GetDlc
uint8_t GetDlc()
Definition: DbcMessage.cpp:95
NewEagle::DbcMessage::GetId
uint32_t GetId()
Definition: DbcMessage.cpp:100
NewEagle::DbcMessage::_dlc
uint8_t _dlc
Definition: DbcMessage.h:132
NewEagle::DbcMessage::GetRawId
uint32_t GetRawId()
Definition: DbcMessage.cpp:105
NewEagle::EXT
@ EXT
Definition: DbcMessage.h:86
NewEagle::Pack
static void Pack(uint8_t *data, const NewEagle::DbcSignal &signal)
Definition: DbcUtilities.h:194
NewEagle::DbcMessage::~DbcMessage
~DbcMessage()
Definition: DbcMessage.cpp:91
NewEagle::DbcMessage::AnyMultiplexedSignals
bool AnyMultiplexedSignals()
Definition: DbcMessage.cpp:249
NewEagle
Definition: Dbc.h:45
NewEagle::DbcMessage::_idType
IdType _idType
Definition: DbcMessage.h:134
NewEagle::IdType
IdType
Definition: DbcMessage.h:83
NewEagle::DbcMessage::GetSignal
NewEagle::DbcSignal * GetSignal(std::string signalName)
Definition: DbcMessage.cpp:213
NewEagle::NONE
@ NONE
Definition: DbcSignal.h:104
NewEagle::DbcMessage::SetComment
void SetComment(NewEagle::DbcMessageComment comment)
Definition: DbcMessage.cpp:239
NewEagle::DbcSignal::GetResult
double GetResult() const
Definition: DbcSignal.cpp:126
NewEagle::DbcMessage::_id
uint32_t _id
Definition: DbcMessage.h:133
NewEagle::DbcMessageComment
Definition: DbcMessage.h:77
NewEagle::DbcMessage::SetFrame
void SetFrame(const can_msgs::Frame::ConstPtr &msg)
Definition: DbcMessage.cpp:166
NewEagle::DbcSignal
Definition: DbcSignal.h:109
NewEagle::DbcMessage::_signals
std::map< std::string, NewEagle::DbcSignal > _signals
Definition: DbcMessage.h:130
NewEagle::MUX_SIGNAL
@ MUX_SIGNAL
Definition: DbcSignal.h:106
DbcUtilities.h
NewEagle::DbcMessage::_name
std::string _name
Definition: DbcMessage.h:135
NewEagle::DbcMessage::SetRawText
void SetRawText(std::string rawText)
Definition: DbcMessage.cpp:229
NewEagle::DbcMessage::GetIdType
IdType GetIdType()
Definition: DbcMessage.cpp:110
NewEagle::DbcMessage::GetName
std::string GetName()
Definition: DbcMessage.cpp:115
NewEagle::DbcMessage::GetSignalCount
uint32_t GetSignalCount()
Definition: DbcMessage.cpp:234
NewEagle::MUX_SWITCH
@ MUX_SWITCH
Definition: DbcSignal.h:105
NewEagle::DbcMessage::_comment
NewEagle::DbcMessageComment _comment
Definition: DbcMessage.h:137
NewEagle::Unpack
static double Unpack(uint8_t *data, const NewEagle::DbcSignal &signal)
Definition: DbcUtilities.h:101
NewEagle::DbcMessage::GetFrame
can_msgs::Frame GetFrame()
Definition: DbcMessage.cpp:120
DbcMessage.h
NewEagle::DbcMessage::_rawId
uint32_t _rawId
Definition: DbcMessage.h:136


can_dbc_parser
Author(s): Ryan Borchert
autogenerated on Sat Apr 9 2022 02:34:32