diff --git a/Cargo.toml b/Cargo.toml index de0480e..e1208ab 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,3 +22,7 @@ members = [ "canadensis_udp", "canadensis_write_crc" ] + +[workspace.dependencies] +defmt = "1.0.1" +l0g = "1" \ No newline at end of file diff --git a/canadensis/Cargo.toml b/canadensis/Cargo.toml index 18fb142..5591a2c 100644 --- a/canadensis/Cargo.toml +++ b/canadensis/Cargo.toml @@ -12,9 +12,10 @@ description = "A Cyphal implementation: Node types and re-exports from some othe [dependencies] crc-any = { version = "2.4.0", default-features = false } fallible_collections = "0.5.1" -heapless = "0.8.0" +heapless = { version = "0.8.0", features = ["defmt-03"] } half = { version = ">=2.2, <2.5", default-features = false } -log = "0.4" +defmt.workspace = true +l0g.workspace = true # Depends on most other canadensis crates that are not transport-specific [dependencies.canadensis_core] @@ -37,6 +38,7 @@ path = "../canadensis_data_types" socketcan = { version = "3.5.0", default-features = false } rand = "0.8.0" simplelog = "0.12.0" +log = "0.4" [dev-dependencies.canadensis_linux] version = "0.3.0" @@ -50,4 +52,3 @@ path = "../canadensis_serial" [dev-dependencies.canadensis_udp] version = "0.4.1" path = "../canadensis_udp" - diff --git a/canadensis/src/lib.rs b/canadensis/src/lib.rs index 3d95765..aef76da 100644 --- a/canadensis/src/lib.rs +++ b/canadensis/src/lib.rs @@ -45,6 +45,7 @@ use canadensis_core::transfer::*; use canadensis_core::transport::{Receiver, Transmitter}; use canadensis_core::{ServiceId, SubjectId}; use canadensis_encoding::{Message, Request, Response, Serialize}; +use defmt::Format; /// A token from a request that is needed to send a response pub struct ResponseToken { @@ -560,7 +561,7 @@ impl ServiceToken { } /// Errors that may occur when starting to send messages or requests -#[derive(Debug)] +#[derive(Debug, Format)] pub enum StartSendError { /// Memory to store the publisher was not available Memory(OutOfMemoryError), diff --git a/canadensis/src/register.rs b/canadensis/src/register.rs index 342e6c7..1bddc01 100644 --- a/canadensis/src/register.rs +++ b/canadensis/src/register.rs @@ -17,6 +17,7 @@ use canadensis_data_types::uavcan::register::name_1_0::Name; use canadensis_data_types::uavcan::register::value_1_0::Value; use canadensis_data_types::uavcan::time::synchronized_timestamp_1_0::SynchronizedTimestamp; use canadensis_encoding::Deserialize; +use l0g::{debug, warn}; pub use canadensis_derive_register_block::RegisterBlock; @@ -165,7 +166,7 @@ where fn handle_access_request(&mut self, request: &AccessRequest) -> AccessResponse { match str::from_utf8(&request.name.name) { Ok(register_name) => { - log::debug!("Handling access request for {}", register_name); + debug!("Handling access request for {}", register_name); if let Some(register) = self.block.register_by_name_mut(register_name) { register_handle_access(register, request) } else { @@ -195,7 +196,7 @@ where } fn handle_list_request(&mut self, request: &ListRequest) -> ListResponse { - log::debug!("Handling register list request, index {}", { + debug!("Handling register list request, index {}", { request.index }); match self.block.register_by_index(request.index.into()) { @@ -262,7 +263,7 @@ where let response = self.handle_access_request(&request); let status = node.send_response(token, milliseconds(1000), &response); if status.is_err() { - log::warn!("Out of memory when sending register access response"); + warn!("Out of memory when sending register access response"); } true } else { @@ -274,7 +275,7 @@ where let response = self.handle_list_request(&request); let status = node.send_response(token, milliseconds(1000), &response); if status.is_err() { - log::warn!("Out of memory when sending register list response"); + warn!("Out of memory when sending register list response"); } true } else { diff --git a/canadensis/src/service/pnp_client.rs b/canadensis/src/service/pnp_client.rs index d8a3b44..e375a6b 100644 --- a/canadensis/src/service/pnp_client.rs +++ b/canadensis/src/service/pnp_client.rs @@ -17,6 +17,7 @@ use canadensis_data_types::uavcan::pnp::{ use core::convert::TryFrom; use core::marker::PhantomData; use crc_any::CRCu64; +use defmt::Format; /// A plug-and-play allocation client that can be used to find a node ID pub struct PnpClientService { @@ -85,7 +86,7 @@ where } /// Error type returned by [`PnpClientService::new`]. -#[derive(Debug)] +#[derive(Debug, Format)] pub enum NewError { /// The client could not subscribe to the message subject due to a receiver error. Subscribe(>::Error), @@ -98,7 +99,7 @@ pub enum NewError { } /// Error type returned by [`PnpClientService::send_request`]. -#[derive(Debug)] +#[derive(Debug, Format)] pub enum SendRequestError { /// The client has allocated an address already and no longer holds a publish token. Allocated, diff --git a/canadensis/src/service/register_server.rs b/canadensis/src/service/register_server.rs index bbe6e0e..62958af 100644 --- a/canadensis/src/service/register_server.rs +++ b/canadensis/src/service/register_server.rs @@ -14,7 +14,7 @@ use canadensis_data_types::uavcan::time::synchronized_timestamp_1_0::Synchronize use canadensis_encoding::Deserialize; use core::marker::PhantomData; use core::str; -use log::{debug, warn}; +use l0g::{debug, warn}; /// A service that responds to `uavcan.register.List` and `uavcan.register.Access` pub struct RegisterServerService { diff --git a/canadensis/tests/can_loopback.rs b/canadensis/tests/can_loopback.rs index 0860159..ef7b206 100644 --- a/canadensis/tests/can_loopback.rs +++ b/canadensis/tests/can_loopback.rs @@ -4,7 +4,6 @@ extern crate canadensis; extern crate canadensis_can; extern crate canadensis_data_types; extern crate canadensis_encoding; -extern crate log; extern crate simplelog; use canadensis::node::CoreNode; diff --git a/canadensis_bxcan/Cargo.toml b/canadensis_bxcan/Cargo.toml index 31f0e21..29164d9 100644 --- a/canadensis_bxcan/Cargo.toml +++ b/canadensis_bxcan/Cargo.toml @@ -14,7 +14,6 @@ description = "Bridge between Canadensis and the BXCAN peripherals found in some [dependencies] bxcan = "0.7.0" nb = "1.0.0" -log = "0.4" fallible_collections = "0.5.1" heapless = "0.8.0" cortex-m = "0.7.3" diff --git a/canadensis_bxcan/src/lib.rs b/canadensis_bxcan/src/lib.rs index 551aecf..26c4e93 100644 --- a/canadensis_bxcan/src/lib.rs +++ b/canadensis_bxcan/src/lib.rs @@ -18,7 +18,6 @@ extern crate canadensis_pnp_client; extern crate cortex_m; extern crate fallible_collections; extern crate heapless; -extern crate log; extern crate nb; pub mod pnp; diff --git a/canadensis_can/Cargo.toml b/canadensis_can/Cargo.toml index f931a72..daba847 100644 --- a/canadensis_can/Cargo.toml +++ b/canadensis_can/Cargo.toml @@ -12,7 +12,8 @@ description = "A Cyphal implementation: Cyphal/CAN (CAN and CAN FD) transport la [dependencies] fallible_collections = "0.5.1" heapless = "0.8.0" -log = "0.4" +defmt.workspace = true +l0g.workspace = true [dependencies.canadensis_core] version = "0.3.1" diff --git a/canadensis_can/src/lib.rs b/canadensis_can/src/lib.rs index 8bdade8..9b208b3 100644 --- a/canadensis_can/src/lib.rs +++ b/canadensis_can/src/lib.rs @@ -13,7 +13,6 @@ extern crate canadensis_core; extern crate canadensis_filter_config; extern crate fallible_collections; extern crate heapless; -extern crate log; pub use crate::crc::TransferCrc; pub use crate::data::*; diff --git a/canadensis_can/src/redundant/redundant_queue.rs b/canadensis_can/src/redundant/redundant_queue.rs index f06b74e..e45ff4c 100644 --- a/canadensis_can/src/redundant/redundant_queue.rs +++ b/canadensis_can/src/redundant/redundant_queue.rs @@ -2,6 +2,7 @@ use crate::driver::TransmitDriver; use crate::Frame; use canadensis_core::time::Clock; use canadensis_core::{nb, OutOfMemoryError}; +use defmt::Format; /// An aggregation of two outgoing frame queues that can be used for double-redundant transports /// @@ -102,7 +103,7 @@ where } /// An error from a DoubleRedundantQueueDriver -#[derive(Debug)] +#[derive(Debug, Format)] pub enum RedundantError { /// An error from driver 0 Driver0(E0), diff --git a/canadensis_can/src/rx.rs b/canadensis_can/src/rx.rs index e9b1f3d..eb3d65f 100644 --- a/canadensis_can/src/rx.rs +++ b/canadensis_can/src/rx.rs @@ -12,6 +12,7 @@ use core::fmt::Debug; use core::marker::PhantomData; use fallible_collections::FallibleVec; +use l0g::{debug, info}; use crate::data::{CanId, Frame}; use crate::driver::ReceiveDriver; @@ -294,7 +295,7 @@ where Some(data) => data, None => { // Can't use this frame - log::debug!("Frame failed sanity checks, ignoring"); + debug!("Frame failed sanity checks, ignoring"); self.increment_error_count(); return Ok(None); } @@ -338,7 +339,7 @@ where } Ok(None) => Ok(None), Err(e) => { - log::info!("Receiver accept error {:?}", e); + info!("Receiver accept error {:?}", e); self.increment_error_count(); match e { SubscriptionError::Session(SessionError::Memory(e)) @@ -369,7 +370,7 @@ where if message_header.source.is_none() { // Anonymous message transfers must always fit into one frame if !(tail_byte.toggle && tail_byte.start && tail_byte.end) { - log::debug!("Anonymous multi-frame transfer, ignoring"); + debug!("Anonymous multi-frame transfer, ignoring"); return None; } } diff --git a/canadensis_can/src/rx/session.rs b/canadensis_can/src/rx/session.rs index 000f990..330b1e4 100644 --- a/canadensis_can/src/rx/session.rs +++ b/canadensis_can/src/rx/session.rs @@ -6,6 +6,8 @@ use alloc::vec::Vec; use canadensis_core::time::{MicrosecondDuration32, Microseconds32}; use canadensis_core::OutOfMemoryError; use core::fmt::Debug; +use defmt::Format; +use l0g::{info, warn}; /// A receive session, associated with a particular port ID and source node #[derive(Debug)] @@ -53,17 +55,17 @@ impl Session { if tail.transfer_id != self.buildup.transfer_id() { // This is a frame from some other transfer. Ignore it, but keep this session to receive // possible later frames. - log::info!("Frame transfer ID does not match, ignoring"); + info!("Frame transfer ID does not match, ignoring"); return Ok(None); } if frame.loopback() != self.loopback { - log::info!("Frame loopback flag does not match, ignoring"); + info!("Frame loopback flag does not match, ignoring"); return Ok(None); } // Check if this frame will make the transfer exceed the maximum length let new_payload_length = self.buildup.payload_length() + (frame.data().len() - 1); if new_payload_length > max_payload_length { - log::warn!( + warn!( "Payload too large ({} + {} > {}), ending session", self.buildup.payload_length(), frame.data().len() - 1, @@ -76,7 +78,7 @@ impl Session { if time_since_first_frame > transfer_timeout { // Frame arrived too late. Give up on this session. - log::info!("Frame timeout expired, ending session"); + info!("Frame timeout expired, ending session"); return Err(SessionError::Timeout); } // This frame looks OK. Do the reassembly. @@ -130,7 +132,7 @@ impl Session { } } -#[derive(Debug)] +#[derive(Debug, Format)] pub enum SessionError { /// A transfer CRC was invalid Crc, diff --git a/canadensis_can/src/rx/subscription.rs b/canadensis_can/src/rx/subscription.rs index 54c3a1d..a3e14ef 100644 --- a/canadensis_can/src/rx/subscription.rs +++ b/canadensis_can/src/rx/subscription.rs @@ -8,7 +8,9 @@ use canadensis_core::time::MicrosecondDuration32; use canadensis_core::{OutOfMemoryError, PortId}; use core::fmt; use core::fmt::Debug; +use defmt::Format; use fallible_collections::{FallibleBox, FallibleVec, TryReserveError}; +use l0g::debug; /// One session per node ID const RX_SESSIONS_PER_SUBSCRIPTION: usize = CanNodeId::MAX.to_u8() as usize + 1; @@ -125,7 +127,7 @@ impl Subscription { let slot = &mut self.sessions[usize::from(source_node)]; let session = match slot { Some(session) => { - log::debug!( + debug!( "Using existing session with transfer ID {:?} for port {:?} (frame transfer ID {:?})", session.transfer_id(), self.port_id, @@ -146,10 +148,9 @@ impl Subscription { self.payload_size_max, frame.loopback(), )?)?); - log::debug!( + debug!( "Created new session for transfer ID {:?} on port {:?}", - tail.transfer_id, - self.port_id + tail.transfer_id, self.port_id ); slot.as_deref_mut().unwrap() } @@ -214,7 +215,7 @@ impl Subscription { } /// Errors that a subscription may encounter -#[derive(Debug)] +#[derive(Debug, Format)] pub enum SubscriptionError { /// Received a frame with no corresponding session, but its start bit was not set NotStart, diff --git a/canadensis_can/src/types.rs b/canadensis_can/src/types.rs index 80daecd..8d4d5d8 100644 --- a/canadensis_can/src/types.rs +++ b/canadensis_can/src/types.rs @@ -6,6 +6,7 @@ use core::convert::TryFrom; use core::fmt; use core::fmt::Debug; use core::ops::RangeInclusive; +use defmt::Format; /// The Cyphal/CAN transport pub struct CanTransport(()); @@ -125,7 +126,7 @@ impl From for usize { const VALID_TRANSFER_IDS: RangeInclusive = 0..=31; /// Transfer ID, 5 bits, in range 0..=31 -#[derive(Debug, Copy, Clone, Ord, PartialOrd, Eq, PartialEq)] +#[derive(Debug, Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Format)] pub struct CanTransferId(u8); impl CanTransferId { @@ -192,7 +193,7 @@ impl Default for CanTransferId { } /// CAN transport errors -#[derive(Debug, PartialEq)] +#[derive(Debug, PartialEq, Format)] pub enum Error { /// Memory allocation failed Memory(OutOfMemoryError), diff --git a/canadensis_core/Cargo.toml b/canadensis_core/Cargo.toml index da73e58..4cc97f0 100644 --- a/canadensis_core/Cargo.toml +++ b/canadensis_core/Cargo.toml @@ -13,5 +13,6 @@ description = "A Cyphal implementation: Common definitions" fugit = "0.3.7" fallible_collections = "0.5.1" heapless = "0.8.0" -log = "0.4.14" -nb = "1.0.0" +nb = { version = "1.0.0", features = ["defmt-0-3"] } +defmt.workspace = true +l0g.workspace = true diff --git a/canadensis_core/src/error.rs b/canadensis_core/src/error.rs index 3952f6f..2c55a48 100644 --- a/canadensis_core/src/error.rs +++ b/canadensis_core/src/error.rs @@ -2,10 +2,11 @@ //! Error definitions //! +use defmt::Format; use fallible_collections::TryReserveError; /// An error indicating that memory could not be allocated -#[derive(Debug, Eq, PartialEq, Clone)] +#[derive(Debug, Eq, PartialEq, Clone, Format)] pub struct OutOfMemoryError; impl From for OutOfMemoryError { @@ -15,7 +16,7 @@ impl From for OutOfMemoryError { } /// An error that may occur when subscribing to a service -#[derive(Debug, Eq, PartialEq, Clone)] +#[derive(Debug, Eq, PartialEq, Clone, Format)] pub enum ServiceSubscribeError { /// Can't subscribe to a service because this is an anonymous node Anonymous, diff --git a/canadensis_core/src/lib.rs b/canadensis_core/src/lib.rs index 4ec714d..d745768 100644 --- a/canadensis_core/src/lib.rs +++ b/canadensis_core/src/lib.rs @@ -9,7 +9,6 @@ extern crate alloc; extern crate fallible_collections; extern crate fugit; extern crate heapless; -extern crate log; pub extern crate nb; mod error; @@ -19,14 +18,15 @@ pub mod time; pub mod transfer; pub mod transport; +pub use crate::error::{OutOfMemoryError, ServiceSubscribeError}; use core::convert::TryFrom; use core::ops::RangeInclusive; use core::str::FromStr; +use defmt::Format; /// An error indicating that an unacceptable integer was provided to a TryFrom implementation -#[derive(Debug)] +#[derive(Debug, Format)] pub struct InvalidValue; -pub use crate::error::{OutOfMemoryError, ServiceSubscribeError}; /// Allowed subject ID values const VALID_SUBJECT_IDS: RangeInclusive = 0..=8191; @@ -127,7 +127,7 @@ impl From for usize { } /// A value that can represent a service ID (0..=511) or a subject ID (0..=8192) -#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)] +#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash, Format)] pub struct PortId(u16); impl From for PortId { diff --git a/canadensis_core/src/session.rs b/canadensis_core/src/session.rs index 8e68a6b..17e21cd 100644 --- a/canadensis_core/src/session.rs +++ b/canadensis_core/src/session.rs @@ -4,7 +4,9 @@ use crate::time::{MicrosecondDuration32, Microseconds32}; use crate::OutOfMemoryError; use alloc::collections::BTreeMap; use core::fmt::Debug; +use defmt::Format; use heapless::LinearMap; +use l0g::debug; /// Something that can keep track of receive sessions associated with other nodes /// @@ -314,7 +316,7 @@ where impl SessionTracker for SessionDynamicMap where - N: Ord + Clone + Debug, + N: Ord + Clone + Debug + Format, { fn get(&self, node: N) -> Option<&Session> { self.sessions.get(&node) @@ -356,7 +358,7 @@ where } match expired_node_id { Some(id) => { - log::debug!("Removing expired session from node {:?}", id); + debug!("Removing expired session from node {:?}", id); self.sessions.remove(&id); } None => break, diff --git a/canadensis_header/Cargo.toml b/canadensis_header/Cargo.toml index 555e4f3..b18da87 100644 --- a/canadensis_header/Cargo.toml +++ b/canadensis_header/Cargo.toml @@ -11,3 +11,4 @@ description = "The frame header format used by Cyphal/Serial and Cyphal/UDP" canadensis_core = { version = "0.3.1", path = "../canadensis_core" } zerocopy = "0.6.1" crc-any = "2.4.0" +defmt.workspace = true diff --git a/canadensis_header/src/lib.rs b/canadensis_header/src/lib.rs index 7de7a21..d37769f 100644 --- a/canadensis_header/src/lib.rs +++ b/canadensis_header/src/lib.rs @@ -11,6 +11,7 @@ use canadensis_core::{InvalidValue, Priority, ServiceId, SubjectId}; use core::convert::TryFrom; use core::mem; use crc_any::CRCu16; +use defmt::Format; use zerocopy::byteorder::{U16, U32, U64}; use zerocopy::{AsBytes, BigEndian, FromBytes, LittleEndian}; @@ -337,7 +338,7 @@ pub fn header_crc() -> CRCu16 { /// A 16-bit node ID /// /// This allows all u16 values except 65535, which is reserved for anonymous transfers -#[derive(Debug, Copy, Clone, Eq, PartialEq, PartialOrd, Ord, Hash)] +#[derive(Debug, Copy, Clone, Eq, PartialEq, PartialOrd, Ord, Hash, Format)] pub struct NodeId16(u16); const NODE_ID_RESERVED_ANONYMOUS_OR_BROADCAST: u16 = 0xffff; diff --git a/canadensis_serial/Cargo.toml b/canadensis_serial/Cargo.toml index ac965ad..3c3c9c1 100644 --- a/canadensis_serial/Cargo.toml +++ b/canadensis_serial/Cargo.toml @@ -14,7 +14,8 @@ zerocopy = "0.6.0" heapless = "0.8.0" crc-any = "2.4.0" fallible_collections = "0.5.1" -log = "0.4.14" +defmt.workspace = true +l0g.workspace = true [dependencies.canadensis_core] version = "0.3.1" @@ -25,3 +26,4 @@ path = "../canadensis_header" [dev-dependencies] simplelog = "0.12.0" +log = "0.4" diff --git a/canadensis_serial/src/lib.rs b/canadensis_serial/src/lib.rs index fa30b14..24cfdcb 100644 --- a/canadensis_serial/src/lib.rs +++ b/canadensis_serial/src/lib.rs @@ -6,7 +6,6 @@ extern crate canadensis_header; extern crate crc_any; extern crate fallible_collections; extern crate heapless; -extern crate log; extern crate zerocopy; use crc_any::CRCu32; diff --git a/canadensis_serial/src/rx.rs b/canadensis_serial/src/rx.rs index 8f59506..9c6bde4 100644 --- a/canadensis_serial/src/rx.rs +++ b/canadensis_serial/src/rx.rs @@ -4,6 +4,7 @@ use core::marker::PhantomData; use core::mem; use fallible_collections::{FallibleVec, TryHashMap}; +use l0g::debug; use canadensis_core::subscription::SubscriptionManager; use canadensis_core::time::{Clock, MicrosecondDuration32, Microseconds32}; @@ -79,7 +80,7 @@ where State::BetweenTransfers => { if byte != 0 { // Start decoding - log::debug!("Starting frame"); + debug!("Starting frame"); let mut unescaper = Unescaper::new(); match unescaper.accept(byte) { Ok(Some(byte)) => { @@ -132,13 +133,13 @@ where } } else { // Not interested in this transfer - log::debug!("Got header, but not subscribed"); + debug!("Got header, but not subscribed"); State::Idle } } Err(e) => { // Invalid header CRC or format - log::debug!("Header format or CRC invalid: {:?}", e); + debug!("Header format or CRC invalid: {:?}", e); State::Idle } }