@@ -6,6 +6,9 @@ use crate::lib::std::error::Error as StdError;
6
6
use tokio:: fs:: File ;
7
7
use tokio:: io:: { AsyncBufReadExt , BufReader } ;
8
8
use tokio:: net:: { TcpStream , UdpSocket } ;
9
+ use std:: println;
10
+ use std:: eprintln;
11
+
9
12
/// Parses a single line of NMEA data using the provided AIS parser.
10
13
///
11
14
/// This function attempts to parse a given NMEA line into a tag block and an AIS message,
@@ -17,21 +20,17 @@ use tokio::net::{TcpStream, UdpSocket};
17
20
///
18
21
19
22
async fn parse_nmea_line ( parser : & mut AisParser , line : & [ u8 ] ) {
20
- // Convert the line to a string
21
23
let line_str = std:: str:: from_utf8 ( line) . expect ( "Invalid UTF-8 sequence" ) ;
22
24
23
- // Print the received message
25
+ # [ cfg ( feature = "std" ) ]
24
26
println ! ( "Received message: {}" , line_str) ;
25
27
26
- // Check for a tag block by looking for the start of a NMEA sentence ('!')
27
28
if let Some ( nmea_start_idx) = line_str. find ( '!' ) {
28
29
// Extract the tag block (everything before the '!') and the NMEA sentence
29
30
let tag_block_str = & line_str[ ..nmea_start_idx] ;
30
31
let nmea_sentence = & line_str[ nmea_start_idx..] ;
31
32
32
- // Check if there's a valid tag block (should start and end with '\')
33
33
if tag_block_str. starts_with ( '\\' ) && tag_block_str. ends_with ( '\\' ) {
34
- // Remove the leading and trailing backslashes from the tag block
35
34
let tag_block_content = & tag_block_str[ 1 ..tag_block_str. len ( ) - 1 ] ;
36
35
37
36
// Parse the tag block
@@ -52,20 +51,24 @@ async fn parse_nmea_line(parser: &mut AisParser, line: &[u8]) {
52
51
// Parse the NMEA sentence
53
52
match parser. parse ( nmea_sentence. as_bytes ( ) , true ) {
54
53
Ok ( ( _, AisFragments :: Complete ( sentence) ) ) => {
54
+
55
+ #[ cfg( feature = "std" ) ]
55
56
println ! (
56
57
"Parsed NMEA Sentence: {:?}\n Message: {:?}" ,
57
58
nmea_sentence, sentence. message
58
59
) ;
59
60
}
60
61
Err ( err) => {
62
+ #[ cfg( feature = "std" ) ]
61
63
eprintln ! ( "Error parsing line {:?}: {:?}" , nmea_sentence, err) ;
62
64
}
63
65
_ => { }
64
66
}
65
67
66
- // Print separator between messages
68
+ # [ cfg ( feature = "std" ) ]
67
69
println ! ( "*************************" ) ;
68
70
} else {
71
+ #[ cfg( feature = "std" ) ]
69
72
eprintln ! ( "No valid NMEA sentence found in line" ) ;
70
73
}
71
74
}
@@ -150,6 +153,7 @@ pub fn decode(message: &[u8]) -> Result<AisMessage, Error> {
150
153
let mut parser = AisParser :: new ( ) ;
151
154
match parser. parse ( message, true ) ? {
152
155
( Some ( tag_block) , AisFragments :: Complete ( sentence) ) => {
156
+ #[ cfg( feature = "std" ) ]
153
157
println ! ( "TagBlock: {:?}" , tag_block) ;
154
158
sentence. message . ok_or ( Error :: Nmea {
155
159
msg : "Incomplete message" . into ( ) ,
0 commit comments