Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,7 @@ members = [
"canadensis_udp",
"canadensis_write_crc"
]

[workspace.dependencies]
defmt = "1.0.1"
l0g = "1"
7 changes: 4 additions & 3 deletions canadensis/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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"
Expand All @@ -50,4 +52,3 @@ path = "../canadensis_serial"
[dev-dependencies.canadensis_udp]
version = "0.4.1"
path = "../canadensis_udp"

3 changes: 2 additions & 1 deletion canadensis/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T: Transport> {
Expand Down Expand Up @@ -560,7 +561,7 @@ impl<T> ServiceToken<T> {
}

/// Errors that may occur when starting to send messages or requests
#[derive(Debug)]
#[derive(Debug, Format)]
pub enum StartSendError<E> {
/// Memory to store the publisher was not available
Memory(OutOfMemoryError),
Expand Down
9 changes: 5 additions & 4 deletions canadensis/src/register.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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()) {
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
5 changes: 3 additions & 2 deletions canadensis/src/service/pnp_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<N, M> {
Expand Down Expand Up @@ -85,7 +86,7 @@ where
}

/// Error type returned by [`PnpClientService::new`].
#[derive(Debug)]
#[derive(Debug, Format)]
pub enum NewError<N: Node> {
/// The client could not subscribe to the message subject due to a receiver error.
Subscribe(<N::Receiver as Receiver<N::Clock>>::Error),
Expand All @@ -98,7 +99,7 @@ pub enum NewError<N: Node> {
}

/// Error type returned by [`PnpClientService::send_request`].
#[derive(Debug)]
#[derive(Debug, Format)]
pub enum SendRequestError<N: Node> {
/// The client has allocated an address already and no longer holds a publish token.
Allocated,
Expand Down
2 changes: 1 addition & 1 deletion canadensis/src/service/register_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<N: Node, B: RegisterBlock> {
Expand Down
1 change: 0 additions & 1 deletion canadensis/tests/can_loopback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion canadensis_bxcan/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 0 additions & 1 deletion canadensis_bxcan/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion canadensis_can/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 0 additions & 1 deletion canadensis_can/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand Down
3 changes: 2 additions & 1 deletion canadensis_can/src/redundant/redundant_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
///
Expand Down Expand Up @@ -102,7 +103,7 @@ where
}

/// An error from a DoubleRedundantQueueDriver
#[derive(Debug)]
#[derive(Debug, Format)]
pub enum RedundantError<E0, E1> {
/// An error from driver 0
Driver0(E0),
Expand Down
7 changes: 4 additions & 3 deletions canadensis_can/src/rx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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;
}
}
Expand Down
12 changes: 7 additions & 5 deletions canadensis_can/src/rx/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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,
Expand All @@ -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.
Expand Down Expand Up @@ -130,7 +132,7 @@ impl Session {
}
}

#[derive(Debug)]
#[derive(Debug, Format)]
pub enum SessionError {
/// A transfer CRC was invalid
Crc,
Expand Down
11 changes: 6 additions & 5 deletions canadensis_can/src/rx/subscription.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand All @@ -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()
}
Expand Down Expand Up @@ -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,
Expand Down
5 changes: 3 additions & 2 deletions canadensis_can/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(());
Expand Down Expand Up @@ -125,7 +126,7 @@ impl From<CanNodeId> for usize {
const VALID_TRANSFER_IDS: RangeInclusive<u8> = 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 {
Expand Down Expand Up @@ -192,7 +193,7 @@ impl Default for CanTransferId {
}

/// CAN transport errors
#[derive(Debug, PartialEq)]
#[derive(Debug, PartialEq, Format)]
pub enum Error<E> {
/// Memory allocation failed
Memory(OutOfMemoryError),
Expand Down
5 changes: 3 additions & 2 deletions canadensis_core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 3 additions & 2 deletions canadensis_core/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<TryReserveError> for OutOfMemoryError {
Expand All @@ -15,7 +16,7 @@ impl From<TryReserveError> 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<E> {
/// Can't subscribe to a service because this is an anonymous node
Anonymous,
Expand Down
Loading