Summary Files Commits Branches @commit @diff @stats
path: root / src
diff options
context:
space:
mode:
Commita1b252f1552492ac2b928276ef9d1ac95ea567af (patch)
Author
 Syndamia <kamen@syndamia.com>
2025-07-03 15:22:05 +0300
Committer
 Syndamia <kamen@syndamia.com>
2025-07-03 15:22:05 +0300
Filesaebba26ab308174730515907aad5ed273f885c74 /src
iso-tp-parser-carista-a1b252f1552492ac2b928276ef9d1ac95ea567af.tar
iso-tp-parser-carista-a1b252f1552492ac2b928276ef9d1ac95ea567af.tar.gz
iso-tp-parser-carista-a1b252f1552492ac2b928276ef9d1ac95ea567af.zip
Parent61c4f3192d742be4c9a7a5f5e2bf84e42b9a6306 (diff)
chore: Add documentation comments where needed
4 files changed, 16 insertions, 5 deletions
-rw-r--r--src/frame.cpp16
-rw-r--r--src/frame.h1
-rw-r--r--src/main.cpp1
-rw-r--r--src/message.cpp3
diff --git a/src/frame.cpp b/src/frame.cpp
index babfef7..bfa9daf 100644
--- a/src/frame.cpp
+++ b/src/frame.cpp
@@ -9,6 +9,7 @@ unsigned char hex_byte_to_byte(unsigned char byte) {
}
unsigned char hex_value_to_byte(const unsigned char* hex) {
+ // Could've been done with sprintf, however this is faster
return (hex_byte_to_byte(hex[0]) << 4) | hex_byte_to_byte(hex[1]);
}
@@ -23,13 +24,16 @@ unsigned char next_hex_byte(const unsigned char*& iso_tp_frame) {
/* Private */
-// b0 b1 b2 b3 b4 b5 b6 b7
-// 02 10 C0 00 00 00 00 00
void Frame::parse_frame_str(const unsigned char* iso_tp_frame) {
+ // Every two characters in a frame represent the hex value of a single byte
+ // Example (spaces added for visual clarity):
+ // b0 b1 b2 b3 b4 b5 b6 b7
+ // 02 10 C0 00 00 00 00 00
+
unsigned char byte0 = next_hex_byte(iso_tp_frame);
this->type =(FrameType)((byte0 & 0b11110000) >> 4);
- this->size = byte0 & 0b00001111;
+ this->size = byte0 & 0b00001111;
switch (this->type) {
// Single frame
@@ -45,11 +49,13 @@ void Frame::parse_frame_str(const unsigned char* iso_tp_frame) {
break;
// Consecutive frame
- case CF: this->data_size = 7;
+ case CF: this->data_size = 7; // Message objects track total amount of data
+ // from multipart messages
break;
// Flow control frame
- case FC: this->data_size = 2;
+ case FC: this->data_size = 2; // The FC flag takes less than a byte, so I'm
+ // not considering it data. Maybe I should?
this->size = 2;
break;
}
diff --git a/src/frame.h b/src/frame.h
index 989ee38..c928edd 100644
--- a/src/frame.h
+++ b/src/frame.h
@@ -4,6 +4,7 @@
#include <ostream>
enum FrameType {
+ // Explicit values, so it is apparent they correspond to the appropriate type values
SF = 0, FF = 1, CF = 2, FC = 3
};
diff --git a/src/main.cpp b/src/main.cpp
index 1e7d7d0..6a1bf2c 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -21,6 +21,7 @@ int main() {
sscanf(data, "%3x", &can_id);
Frame frame(data + 3);
+ // When the message is split into multiple frames (an FF and then multiple CFs)
if (unfinished_messages.count(can_id)) {
Message& m = unfinished_messages[can_id];
diff --git a/src/message.cpp b/src/message.cpp
index ee1d8fe..834fd87 100644
--- a/src/message.cpp
+++ b/src/message.cpp
@@ -41,7 +41,10 @@ Message& Message::operator=(const Message& other) {
}
void Message::receive_frame(const Frame& f) {
+ // 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());
+
std::memcpy(this->msg + this->received, f.get_data(), expects);
this->received += expects;
}