@@ -6,6 +6,9 @@ use crate::lib::std::error::Error as StdError;
66use tokio:: fs:: File ;
77use tokio:: io:: { AsyncBufReadExt , BufReader } ;
88use tokio:: net:: { TcpStream , UdpSocket } ;
9+ use std:: println;
10+ use std:: eprintln;
11+
912/// Parses a single line of NMEA data using the provided AIS parser.
1013///
1114/// 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};
1720///
1821
1922async fn parse_nmea_line ( parser : & mut AisParser , line : & [ u8 ] ) {
20- // Convert the line to a string
2123 let line_str = std:: str:: from_utf8 ( line) . expect ( "Invalid UTF-8 sequence" ) ;
2224
23- // Print the received message
25+ # [ cfg ( feature = "std" ) ]
2426 println ! ( "Received message: {}" , line_str) ;
2527
26- // Check for a tag block by looking for the start of a NMEA sentence ('!')
2728 if let Some ( nmea_start_idx) = line_str. find ( '!' ) {
2829 // Extract the tag block (everything before the '!') and the NMEA sentence
2930 let tag_block_str = & line_str[ ..nmea_start_idx] ;
3031 let nmea_sentence = & line_str[ nmea_start_idx..] ;
3132
32- // Check if there's a valid tag block (should start and end with '\')
3333 if tag_block_str. starts_with ( '\\' ) && tag_block_str. ends_with ( '\\' ) {
34- // Remove the leading and trailing backslashes from the tag block
3534 let tag_block_content = & tag_block_str[ 1 ..tag_block_str. len ( ) - 1 ] ;
3635
3736 // Parse the tag block
@@ -52,20 +51,24 @@ async fn parse_nmea_line(parser: &mut AisParser, line: &[u8]) {
5251 // Parse the NMEA sentence
5352 match parser. parse ( nmea_sentence. as_bytes ( ) , true ) {
5453 Ok ( ( _, AisFragments :: Complete ( sentence) ) ) => {
54+
55+ #[ cfg( feature = "std" ) ]
5556 println ! (
5657 "Parsed NMEA Sentence: {:?}\n Message: {:?}" ,
5758 nmea_sentence, sentence. message
5859 ) ;
5960 }
6061 Err ( err) => {
62+ #[ cfg( feature = "std" ) ]
6163 eprintln ! ( "Error parsing line {:?}: {:?}" , nmea_sentence, err) ;
6264 }
6365 _ => { }
6466 }
6567
66- // Print separator between messages
68+ # [ cfg ( feature = "std" ) ]
6769 println ! ( "*************************" ) ;
6870 } else {
71+ #[ cfg( feature = "std" ) ]
6972 eprintln ! ( "No valid NMEA sentence found in line" ) ;
7073 }
7174}
@@ -150,6 +153,7 @@ pub fn decode(message: &[u8]) -> Result<AisMessage, Error> {
150153 let mut parser = AisParser :: new ( ) ;
151154 match parser. parse ( message, true ) ? {
152155 ( Some ( tag_block) , AisFragments :: Complete ( sentence) ) => {
156+ #[ cfg( feature = "std" ) ]
153157 println ! ( "TagBlock: {:?}" , tag_block) ;
154158 sentence. message . ok_or ( Error :: Nmea {
155159 msg : "Incomplete message" . into ( ) ,
0 commit comments