40 #include <boost/filesystem.hpp> 44 #ifdef _IC_BUILDER_CANTOOLS_ 47 #include <dbcReader.h> 55 : m_data_file_name(NULL),
66 throw std::runtime_error(
"No CAN matrix provided!");
73 #if !defined(BOOST_FILESYSTEM_VERSION) || BOOST_FILESYSTEM_VERSION == 2 79 if (extension ==
".xml" || extension ==
".canxml")
82 TiXmlHandle doc_handle(NULL);
85 if (default_header_file.LoadFile())
87 doc_handle = TiXmlHandle(&default_header_file);
88 if (!doc_handle.FirstChildElement().ToElement())
91 throw std::runtime_error(
"Found no root tag in " +
getDataFileName().
string());
97 throw std::runtime_error(
"File " +
getDataFileName().
string() +
" is not well-formed XML");
103 else if (extension ==
".dbc")
105 #ifdef _IC_BUILDER_CANTOOLS_ 113 throw std::runtime_error(
"File " +
getDataFileName().
string() +
" is not a valid DBC file");
121 throw std::runtime_error(
"File " +
getDataFileName().
string() +
" is not a valid file");
125 throw std::runtime_error(
"Missing dbc support, please compile with cantools library.");
132 throw std::runtime_error(
"CanMatrix could not be read.");
174 TiXmlElement * element = doc_handle.FirstChildElement().ToElement();
175 if (std::string(element->Value()) !=
"icl_hardware_can")
181 TiXmlElement* message_data = doc_handle.FirstChildElement().FirstChildElement().FirstChildElement().ToElement();
182 if (std::string(message_data->Value()) ==
"message")
186 struct CanMatrixElement can_matrix_data = {
"", 0.,
"", 0 , 0 , 0., 0., 0.,
false,
false};
192 id = atoi(message_data->FirstChild(
"canid")->ToElement()->GetText());
193 can_matrix_data.
conversion = atof(message_data->FirstChild(
"conversion")->ToElement()->GetText());
194 can_matrix_data.
description = message_data->FirstChild(
"description")->ToElement()->GetText();
195 can_matrix_data.
unit = message_data->FirstChild(
"unit")->ToElement()->GetText();
196 can_matrix_data.
start_bit = atoi(message_data->FirstChild(
"data_start_bit")->ToElement()->GetText());
197 can_matrix_data.
signal_length = atoi(message_data->FirstChild(
"signal_length")->ToElement()->GetText());
198 can_matrix_data.
offset = atof(message_data->FirstChild(
"offset")->ToElement()->GetText());
199 can_matrix_data.
lower_border = atof(message_data->FirstChild(
"lower_border")->ToElement()->GetText());
200 can_matrix_data.
upper_border = atof(message_data->FirstChild(
"upper_border")->ToElement()->GetText());
201 can_matrix_data.
little_endian = bool(atoi(message_data->FirstChild(
"little_endian")->ToElement()->GetText()));
202 can_matrix_data.
signedness = bool(atoi(message_data->FirstChild(
"signedness")->ToElement()->GetText()));
209 iter->second.insert(iter->second.end(), can_matrix_data);
214 m_canmatrix.insert(std::pair<
unsigned int, std::vector<CanMatrixElement> >(
id, std::vector<CanMatrixElement>(1, can_matrix_data)));
218 while ((message_data = message_data->NextSiblingElement()));
241 if (element->FirstChild(
"canid") && element->FirstChild(
"conversion") && element->FirstChild(
"description")
242 && element->FirstChild(
"unit") && element->FirstChild(
"data_start_bit") && element->FirstChild(
"signal_length")
243 && element->FirstChild(
"offset") && element->FirstChild(
"lower_border") && element->FirstChild(
"upper_border")
244 && element->FirstChild(
"little_endian") && element->FirstChild(
"signedness") )
256 #ifndef _IC_BUILDER_CANTOOLS_ 259 dbc_t *dbc =
reinterpret_cast<dbc_t*
>(dbc_);
269 for(ml = dbc->message_list; ml != NULL; ml = ml->next) {
270 unsigned int id = ml->message->id;
272 for(sl = ml->message->signal_list; sl != NULL; sl = sl->next) {
273 struct CanMatrixElement can_matrix_data = {
"", 0.,
"", 0 , 0 , 0., 0., 0.,
false,
false};
275 can_matrix_data.
conversion = sl->signal->scale;
277 can_matrix_data.
unit = sl->signal->unit?sl->signal->unit:
"";
278 can_matrix_data.
start_bit = sl->signal->bit_start + 1;
280 can_matrix_data.
offset = sl->signal->offset;
284 can_matrix_data.
signedness = sl->signal->signedness;
291 iter->second.insert(iter->second.end(), can_matrix_data);
296 m_canmatrix.insert(std::pair<
unsigned int, std::vector<CanMatrixElement> >(
id, std::vector<CanMatrixElement>(1, can_matrix_data)));
327 stream << can_matrix.size();
#define LOGGING_DEBUG(streamname, arg)
unsigned int signal_length
virtual ~tCanMatrixParser()
std::ostream & operator<<(std::ostream &os, InterpretedCanMessages const &interpreted_can_messages)
#define LOGGING_ERROR(streamname, arg)
This modul constructs a map of a can-mask-file the map can be request by getcanmatrix() ...
boost::filesystem::path * m_data_file_name
ThreadStream & endl(ThreadStream &stream)
const boost::filesystem::path & getDataFileName() const
const int checkXmlFile(TiXmlElement *element) const
tCanMatrixParser(const std::string identifier="")
int mapContentOfFile(TiXmlHandle &doc_handle)
const CanMatrix & getCanMatrix() const
std::map< unsigned int, std::vector< CanMatrixElement > > CanMatrix
const bool isActive() const
void setDataFileName(const boost::filesystem::path &file_name)