-
Notifications
You must be signed in to change notification settings - Fork 5
Parsing message #12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Parsing message #12
Conversation
dbcd3cb
to
13bec82
Compare
… parse the value which might be wrong.
…has to be changed
…is for CANMessages
09c887b
to
e09a41c
Compare
2f31a22
to
39f8f90
Compare
d64f851
to
80f60f4
Compare
49d0a8d
to
a7b9a75
Compare
Just getting back from vacation. I see you marked as draft. Are you ready or have other changes coming down the pipeline? |
Hi, I found a big issue in the parsing, this was completely wrong and worked only in specific scenarios. Currently in my hack branch I used a quite performant approach, but is not ready yet. |
bool Message::parseSignals(const uint8_t* data, int size, std::vector<double>& values) const {
if (!m_prepared)
return false;
if (size > 8)
return false; // not supported yet
// Only little endian supported yet!
// All signals must be little endian
for (const auto& signal: m_signals) {
if (signal.is_bigendian)
return false;
}
const uint32_t len = size * 8;
uint64_t d = 0;
for (int i=0; i < size; i++) {
d |= ((uint64_t)data[i]) << i * 8;
}
uint64_t v = 0;
for (const auto& signal: m_signals) {
const uint32_t shiftLeft = (len - (signal.size + signal.start_bit));
v = d << shiftLeft;
v = v >> (shiftLeft + signal.start_bit);
values.push_back(v * signal.factor + signal.offset);
}
return true;
} This can be extended for bigendian too. But then it does not support longer once. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch on the endianess! Not sure how i missed that or flipped it... sorry about the headache with that one. Thank you for the work on this one! Here are a few more comments on it.
Not sure completely sure what you meant about this comment since I didn't see it in the PR.
// Only little endian supported yet!
// All signals must be little endian
for (const auto& signal: m_signals) {
if (signal.is_bigendian)
return false;
}
Not sure what is the best way to get the signals out
I think you did a good job with this interface to get them out.
@@ -0,0 +1,2 @@ | |||
Bitstream reader. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need this extra library? I was hoping to keep the dependencies for this library down to zero. I guess so long as we can keep it single header which I think we can. If we are using this we might want to pull it in with cmake instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the library from python CAN tools. This are two files, a .c and a .h. I created the cmake file for it to be able to import it to dbc_parser
double min = std::stod(match.str(11)); | ||
double max = std::stod(match.str(13)); | ||
double factor; | ||
fast_float::from_chars(match.str(7).data(), match.str(7).data() + match.str(7).size(), factor); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think i commented on the bitstream but do we need this library as well? If this gets you going I am good with it. I might come back and rework it out if the single header fails with the new libraries.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the problem is you have to convert the values to a double, but std::stod considers localization. I did not find another way, and this library is way faster than the std lib, and is only a single header
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah gotcha. I didn't realize that #8 mattered with this. Learned something new on that.
include/libdbc/message.hpp
Outdated
/*! | ||
* \brief prepareMessage | ||
* Preparing message to be able to parse signals afterwards. This speeds up parsing | ||
*/ | ||
void prepareMessage(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How does sorting them speed up parsing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in the current approach not. I tried to reimplement the parser like in the python CAN tools, but I was not yet finished. I think the approach I currently have for <8Byte length and little endian is really fast, only 2 shifts + 3 operations (+-).
Sorry I forgott to push. Now |
@LinuxDevon fixed the conflict and the test. I have to check when I find the time to implement also bigendian.... |
@LinuxDevon I cleaned the branch up and added support for big endian as well |
Reason: otherwise it might search through the complete string to find a match Files: dbc.cpp
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the delay on this. Looks good! thank you for the work on this one! I'll try and get the format set and cleaned up here soon as we discussed in the other PR.
Hi @LinuxDevon thanks for merging. I am trying now to add ability to parse VAL_ symbols, but this is anymore that easy |
@Murmele no worries. I haven't either and was my first attempt at one. Learned as I went. Let me know if you need any help or anything. I should hopefully have time in the up coming weeks to spend some time on this project |
Uh oh!
There was an error while loading. Please reload this page.