feat(receive): add --no_dlt_headers option for serial mode#167
Open
mbehr1 wants to merge 6 commits into
Open
Conversation
Allows to capture raw ascii/utf8 text from serial ports as DLT messages. Messages get apid/ctid SER/ASC. Messages are split by newlines or by a 500ms timeout. Co-authored-by: Copilot <copilot@github.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #167 +/- ##
==========================================
+ Coverage 83.48% 83.61% +0.12%
==========================================
Files 40 40
Lines 21550 21973 +423
==========================================
+ Hits 17992 18373 +381
- Misses 3558 3600 +42 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
Adds support for capturing raw ASCII/UTF-8 serial data and wrapping it into synthesized DLT messages (SER/ASC), controlled via a new --no_dlt_headers flag for serial receive mode.
Changes:
- Add
--no_dlt_headersCLI flag (serial-only) and plumb it intoSerialParamsviaexpect_serial_header. - Add
ExpectedHeader::Nonemode and a newparse_dlt_without_headerpath to build DLT messages from newline-delimited (or chunked) serial text. - Add unit/integration-style tests for headerless serial parsing and CLI validation.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
src/utils/ipdltmsgreceiver.rs |
Adds headerless serial parsing (ExpectedHeader::None), new parser, and tests for the feature. |
src/bin/adlt/receive.rs |
Adds --no_dlt_headers flag, validates usage, and passes configuration into serial receive mode. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+1686
to
+1750
| fn serial_recv_non_dlt_header_split_by_timeout() { | ||
| let logger = new_logger(); | ||
| // create a pipe and use the read end as serial port for the receiver | ||
| let (read_end, mut write_end) = std::io::pipe().expect("create pipe"); | ||
| let read_end = std::mem::ManuallyDrop::new(read_end); | ||
| let read_fd = read_end.as_raw_fd(); | ||
|
|
||
| let mut serial_port = unsafe { serial2::SerialPort::from_raw_fd(read_fd) }; | ||
| serial_port | ||
| .set_read_timeout(std::time::Duration::from_millis(500)) | ||
| .expect("set read timeout"); | ||
|
|
||
| let receiver = IpDltMsgReceiver { | ||
| log: logger, | ||
| recv_mode: RecvMode::Serial(SerialParams { | ||
| device_name: "test".to_string(), | ||
| baudrate: 0, | ||
| expect_serial_header: false, | ||
| }), | ||
| recv_method: RecvMethod::Serial(serial_port), | ||
| expected_header: ExpectedHeader::None, | ||
| interface: InterfaceIndexOrAddress::Index(0), | ||
| addr: SocketAddr::new("127.0.0.1".parse().unwrap(), 0), | ||
| recv_buffer: Vec::with_capacity(65536), | ||
| storage_header_ecu: DltChar4::from_buf(b"EcuS"), | ||
| buffered_msgs: std::collections::VecDeque::new(), | ||
| recv_buffer_list: Vec::new(), | ||
| #[cfg(feature = "pcap")] | ||
| plp_stats: None, | ||
| #[cfg(feature = "pcap")] | ||
| fragment_cache: HashMap::new(), | ||
| index: 0, | ||
| }; | ||
|
|
||
| use std::io::Write; | ||
| let recv_thread = std::thread::spawn(move || { | ||
| let mut receiver = receiver; | ||
| let deadline = std::time::Instant::now() + std::time::Duration::from_secs(3); | ||
| let mut msgs = Vec::with_capacity(2); | ||
| while std::time::Instant::now() < deadline && msgs.len() < 2 { | ||
| match receiver.recv_msg() { | ||
| Ok((msg, _src_addr)) => msgs.push(msg), | ||
| Err(e) | ||
| if matches!( | ||
| e.kind(), | ||
| std::io::ErrorKind::WouldBlock | std::io::ErrorKind::TimedOut | ||
| ) => | ||
| { | ||
| continue; | ||
| } | ||
| Err(e) => panic!("recv_msg failed: {e}"), | ||
| } | ||
| } | ||
| assert_eq!(msgs.len(), 2, "Expected 2 messages within deadline"); | ||
| (msgs.remove(0), msgs.remove(0)) | ||
| }); | ||
|
|
||
| let first_chunk = "first chunk with Ċ without line separator"; // lets test a UTF8 char as well | ||
| write_end | ||
| .write_all(first_chunk.as_bytes()) | ||
| .expect("write first chunk to serial pipe"); | ||
| std::thread::sleep(std::time::Duration::from_millis(600)); | ||
| write_end | ||
| .write_all(b"second chunk with line separator\n") | ||
| .expect("write second chunk to serial pipe"); |
…al headerless mode Agent-Logs-Url: https://github.com/mbehr1/adlt/sessions/886c3e58-fe99-443e-9c0b-fa6abc1bfc43 Co-authored-by: mbehr1 <3258891+mbehr1@users.noreply.github.com>
…arse_dlt_without_header Agent-Logs-Url: https://github.com/mbehr1/adlt/sessions/4c30da48-b545-404f-991d-f8007827071f Co-authored-by: mbehr1 <3258891+mbehr1@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Allows to capture raw ascii/utf8 text from serial ports as DLT messages.
Messages get apid/ctid SER/ASC.
Messages are split by newlines or by a 500ms timeout.