@@ -167,14 +167,9 @@ pub mod net {
167
167
pub use std:: net:: UdpSocket ;
168
168
}
169
169
170
- #[ cfg( all( feature = "log" , feature = "defmt" ) ) ]
171
- compile_error ! (
172
- "Having both `defmt` and `log` features enabled is not supported"
173
- ) ;
174
-
175
170
#[ cfg( feature = "defmt" ) ]
176
171
use defmt:: debug;
177
- #[ cfg( feature = "log" ) ]
172
+ #[ cfg( all ( feature = "log" , not ( feature = "defmt" ) ) ) ]
178
173
use log:: debug;
179
174
180
175
/// Retrieves the current time from an NTP server.
@@ -618,9 +613,9 @@ pub mod sync {
618
613
619
614
use miniloop:: executor:: Executor ;
620
615
621
- #[ cfg( all ( feature = "defmt" , not ( feature = "log" ) ) ) ]
616
+ #[ cfg( feature = "defmt" ) ]
622
617
use defmt:: debug;
623
- #[ cfg( feature = "log" ) ]
618
+ #[ cfg( all ( feature = "log" , not ( feature = "defmt" ) ) ) ]
624
619
use log:: debug;
625
620
626
621
/// Send request to a NTP server with the given address and process the response in a single call
@@ -818,7 +813,7 @@ pub mod sync {
818
813
/// // "time.google.com:123" string here used for the sake of simplicity. In the real app
819
814
/// // you would want to fix destination address, since string hostname may resolve to
820
815
/// // different IP addresses
821
- /// let addr = "time.google.com:123".to_socket_addrs().unwrap().next().unwrap();
816
+ /// let addr = "time.google.com:123".to_socket_addrs().unwrap().filter(SocketAddr::is_ipv4). next().unwrap();
822
817
///
823
818
/// let send_request_result = sntpc::sync::sntp_send_request(addr, &socket, context).unwrap();
824
819
/// let result = sntpc::sync::sntp_process_response(addr, &socket, context, send_request_result);
@@ -999,7 +994,33 @@ fn offset_calculate(t1: u64, t2: u64, t3: u64, t4: u64, units: Units) -> i64 {
999
994
}
1000
995
}
1001
996
1002
- #[ cfg( feature = "log" ) ]
997
+ #[ cfg( feature = "defmt" ) ]
998
+ fn debug_ntp_packet ( packet : & NtpPacket , recv_timestamp : u64 ) {
999
+ let mode = shifter ( packet. li_vn_mode , MODE_MASK , MODE_SHIFT ) ;
1000
+ let version = shifter ( packet. li_vn_mode , VERSION_MASK , VERSION_SHIFT ) ;
1001
+ let li = shifter ( packet. li_vn_mode , LI_MASK , LI_SHIFT ) ;
1002
+
1003
+ debug ! ( "NTP Packet:" ) ;
1004
+ debug ! ( "Mode: {}" , mode) ;
1005
+ debug ! ( "Version: {}" , version) ;
1006
+ debug ! ( "Leap: {}" , li) ;
1007
+ debug ! ( "Stratum: {}" , packet. stratum) ;
1008
+ debug ! ( "Poll: {}" , packet. poll) ;
1009
+ debug ! ( "Precision: {}" , packet. precision) ;
1010
+ debug ! ( "Root delay: {}" , packet. root_delay) ;
1011
+ debug ! ( "Root dispersion: {}" , packet. root_dispersion) ;
1012
+ debug ! (
1013
+ "Reference ID: {}" ,
1014
+ str :: from_utf8( & packet. ref_id. to_be_bytes( ) ) . unwrap_or( "" )
1015
+ ) ;
1016
+ debug ! ( "Origin timestamp (client): {}" , packet. origin_timestamp) ;
1017
+ debug ! ( "Receive timestamp (server): {}" , packet. recv_timestamp) ;
1018
+ debug ! ( "Transmit timestamp (server): {}" , packet. tx_timestamp) ;
1019
+ debug ! ( "Receive timestamp (client): {}" , recv_timestamp) ;
1020
+ debug ! ( "Reference timestamp (server): {}" , packet. ref_timestamp) ;
1021
+ }
1022
+
1023
+ #[ cfg( all( feature = "log" , not( feature = "defmt" ) ) ) ]
1003
1024
fn debug_ntp_packet ( packet : & NtpPacket , recv_timestamp : u64 ) {
1004
1025
let mode = shifter ( packet. li_vn_mode , MODE_MASK , MODE_SHIFT ) ;
1005
1026
let version = shifter ( packet. li_vn_mode , VERSION_MASK , VERSION_SHIFT ) ;
@@ -1039,32 +1060,6 @@ fn debug_ntp_packet(packet: &NtpPacket, recv_timestamp: u64) {
1039
1060
debug ! ( "{}" , delimiter_gen( ) ) ;
1040
1061
}
1041
1062
1042
- #[ cfg( all( feature = "defmt" , not( feature = "log" ) ) ) ]
1043
- fn debug_ntp_packet ( packet : & NtpPacket , recv_timestamp : u64 ) {
1044
- let mode = shifter ( packet. li_vn_mode , MODE_MASK , MODE_SHIFT ) ;
1045
- let version = shifter ( packet. li_vn_mode , VERSION_MASK , VERSION_SHIFT ) ;
1046
- let li = shifter ( packet. li_vn_mode , LI_MASK , LI_SHIFT ) ;
1047
-
1048
- debug ! ( "NTP Packet:" ) ;
1049
- debug ! ( "Mode: {}" , mode) ;
1050
- debug ! ( "Version: {}" , version) ;
1051
- debug ! ( "Leap: {}" , li) ;
1052
- debug ! ( "Stratum: {}" , packet. stratum) ;
1053
- debug ! ( "Poll: {}" , packet. poll) ;
1054
- debug ! ( "Precision: {}" , packet. precision) ;
1055
- debug ! ( "Root delay: {}" , packet. root_delay) ;
1056
- debug ! ( "Root dispersion: {}" , packet. root_dispersion) ;
1057
- debug ! (
1058
- "Reference ID: {}" ,
1059
- str :: from_utf8( & packet. ref_id. to_be_bytes( ) ) . unwrap_or( "" )
1060
- ) ;
1061
- debug ! ( "Origin timestamp (client): {}" , packet. origin_timestamp) ;
1062
- debug ! ( "Receive timestamp (server): {}" , packet. recv_timestamp) ;
1063
- debug ! ( "Transmit timestamp (server): {}" , packet. tx_timestamp) ;
1064
- debug ! ( "Receive timestamp (client): {}" , recv_timestamp) ;
1065
- debug ! ( "Reference timestamp (server): {}" , packet. ref_timestamp) ;
1066
- }
1067
-
1068
1063
fn get_ntp_timestamp < T : NtpTimestampGenerator > ( timestamp_gen : & T ) -> u64 {
1069
1064
( ( timestamp_gen. timestamp_sec ( )
1070
1065
+ ( u64:: from ( NtpPacket :: NTP_TIMESTAMP_DELTA ) ) )
0 commit comments