Summary Files Commits Branches @commit @diff @stats
path: root / src / message.cpp
diff options
context:
space:
mode:
Commit6378e5a22e462e406eb1d44eb924d227a16af01e (patch)
Author
 Syndamia <kamen@syndamia.com>
2025-07-03 15:37:58 +0300
Committer
 Syndamia <kamen@syndamia.com>
2025-07-03 15:37:58 +0300
Filesd8b590d6e4e6ae33034ed07872c517e674bc5356 /src/message.cpp
iso-tp-parser-carista-6378e5a22e462e406eb1d44eb924d227a16af01e.tar
iso-tp-parser-carista-6378e5a22e462e406eb1d44eb924d227a16af01e.tar.gz
iso-tp-parser-carista-6378e5a22e462e406eb1d44eb924d227a16af01e.zip
Parenta1b252f1552492ac2b928276ef9d1ac95ea567af (diff)
feat: Track consecutive frame index
1 files changed, 8 insertions, 1 deletions
-rw-r--r--src/message.cpp9
diff --git a/src/message.cpp b/src/message.cpp
index 834fd87..0769533 100644
--- a/src/message.cpp
+++ b/src/message.cpp
@@ -11,6 +11,7 @@ void Message::copyFrom(const Message& other) {
this->can_id = other.can_id;
this->size = other.size;
this->received = other.received;
+ this->latest_index = other.latest_index;
this->msg = new unsigned char[this->size];
std::memcpy(this->msg, other.msg, this->size);
@@ -18,7 +19,7 @@ void Message::copyFrom(const Message& other) {
/* Public */
-Message::Message(unsigned int can_id, const Frame& first_frame) : can_id(can_id), received(0) {
+Message::Message(unsigned int can_id, const Frame& first_frame) : can_id(can_id), received(0), latest_index(0) {
this->size = first_frame.get_size();
this->msg = new unsigned char[this->size];
this->receive_frame(first_frame);
@@ -41,6 +42,12 @@ Message& Message::operator=(const Message& other) {
}
void Message::receive_frame(const Frame& f) {
+ // This logic isn't really necessary, but I like to be thorough
+ if ((this->latest_index + 1) % 16 < f.get_index()) {
+ throw std::invalid_argument("A consecutive frame was lost!");
+ }
+ this->latest_index = f.get_index();
+
// For CFs we set the data size to 7 (the maximum), however, we may be expecting
// to receive less data (in the last CF).
size_t expects = std::min(this->size - this->received, f.get_data_size());