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 
35 #include <dbc/DbcMessage.h>
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 
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 
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 
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::DbcSignal * GetSignal(std::string signalName)
Definition: DbcMessage.cpp:181
static double Unpack(uint8_t *data, const NewEagle::DbcSignal &signal)
Definition: DbcUtilities.h:69
std::map< std::string, NewEagle::DbcSignal > _signals
Definition: DbcMessage.h:98
std::string _name
Definition: DbcMessage.h:103
std::string GetName()
Definition: DbcMessage.cpp:83
Definition: Dbc.h:45
void SetFrame(const can_msgs::Frame::ConstPtr &msg)
Definition: DbcMessage.cpp:134
void SetRawText(std::string rawText)
Definition: DbcMessage.cpp:197
NewEagle::DbcMessageComment _comment
Definition: DbcMessage.h:105
uint32_t GetSignalCount()
Definition: DbcMessage.cpp:202
double GetResult() const
Definition: DbcSignal.cpp:94
can_msgs::Frame GetFrame()
Definition: DbcMessage.cpp:88
static void Pack(uint8_t *data, const NewEagle::DbcSignal &signal)
Definition: DbcUtilities.h:162
std::map< std::string, NewEagle::DbcSignal > * GetSignals()
Definition: DbcMessage.cpp:212
void AddSignal(std::string signalName, NewEagle::DbcSignal signal)
Definition: DbcMessage.cpp:176
void SetComment(NewEagle::DbcMessageComment comment)
Definition: DbcMessage.cpp:207


dbc
Author(s): Ryan Borchert
autogenerated on Fri Mar 20 2020 03:31:33