From 390f6bef31fba7e957ad35fbbb0a803ad1ba2c26 Mon Sep 17 00:00:00 2001 From: Chris Tacke Date: Tue, 20 Aug 2024 16:57:00 -0500 Subject: [PATCH] added can error info --- .../Contracts/PortsAndBuses/CAN/CanBitrate.cs | 36 +++++++++---------- .../PortsAndBuses/CAN/CanErrorInfo.cs | 16 +++++++++ .../Contracts/PortsAndBuses/CAN/ICanBus.cs | 13 ++++--- 3 files changed, 43 insertions(+), 22 deletions(-) create mode 100644 Source/Meadow.Contracts/Hardware/Contracts/PortsAndBuses/CAN/CanErrorInfo.cs diff --git a/Source/Meadow.Contracts/Hardware/Contracts/PortsAndBuses/CAN/CanBitrate.cs b/Source/Meadow.Contracts/Hardware/Contracts/PortsAndBuses/CAN/CanBitrate.cs index 74279c2f..80271781 100644 --- a/Source/Meadow.Contracts/Hardware/Contracts/PortsAndBuses/CAN/CanBitrate.cs +++ b/Source/Meadow.Contracts/Hardware/Contracts/PortsAndBuses/CAN/CanBitrate.cs @@ -8,90 +8,90 @@ public enum CanBitrate /// /// 5 kbps CAN bitrate. /// - Can_5kbps, + Can_5kbps = 5_000, /// /// 10 kbps CAN bitrate. /// - Can_10kbps, + Can_10kbps = 10_000, /// /// 20 kbps CAN bitrate. /// - Can_20kbps, + Can_20kbps = 20_000, /// /// 33 kbps CAN bitrate. /// - Can_33kbps, + Can_33kbps = 33_000, /// /// 40 kbps CAN bitrate. /// - Can_40kbps, + Can_40kbps = 40_000, /// /// 47 kbps CAN bitrate. /// - Can_47kbps, + Can_47kbps = 47_000, /// /// 50 kbps CAN bitrate. /// - Can_50kbps, + Can_50kbps = 50_000, /// /// 80 kbps CAN bitrate. /// - Can_80kbps, + Can_80kbps = 80_000, /// /// 83 kbps CAN bitrate. /// - Can_83kbps, + Can_83kbps = 83_000, /// /// 95 kbps CAN bitrate. /// - Can_95kbps, + Can_95kbps = 95_000, /// /// 100 kbps CAN bitrate. /// - Can_100kbps, + Can_100kbps = 100_000, /// /// 125 kbps CAN bitrate. /// - Can_125kbps, + Can_125kbps = 125_000, /// /// 200 kbps CAN bitrate. /// - Can_200kbps, + Can_200kbps = 200_000, /// /// 250 kbps CAN bitrate. /// - Can_250kbps, + Can_250kbps = 250_000, /// /// 500 kbps CAN bitrate. /// - Can_500kbps, + Can_500kbps = 500_000, /// /// 800 kbps CAN bitrate. /// - Can_800kbps, + Can_800kbps = 800_000, /// /// 1 Mbps CAN bitrate. /// - Can_1Mbps, + Can_1Mbps = 1_000_000, /// /// Flexible Data Rate /// - Can_FD, + Can_FD = -1, } diff --git a/Source/Meadow.Contracts/Hardware/Contracts/PortsAndBuses/CAN/CanErrorInfo.cs b/Source/Meadow.Contracts/Hardware/Contracts/PortsAndBuses/CAN/CanErrorInfo.cs new file mode 100644 index 00000000..e0de8690 --- /dev/null +++ b/Source/Meadow.Contracts/Hardware/Contracts/PortsAndBuses/CAN/CanErrorInfo.cs @@ -0,0 +1,16 @@ +namespace Meadow.Hardware; + +/// +/// Represents CAN bus error information +/// +public class CanErrorInfo +{ + /// + /// The number of transmit errors detected + /// + public byte TransmitErrorCount { get; set; } + /// + /// The number of receive errors detected + /// + public byte ReceiveErrorCount { get; set; } +} diff --git a/Source/Meadow.Contracts/Hardware/Contracts/PortsAndBuses/CAN/ICanBus.cs b/Source/Meadow.Contracts/Hardware/Contracts/PortsAndBuses/CAN/ICanBus.cs index d820f736..6004f1db 100644 --- a/Source/Meadow.Contracts/Hardware/Contracts/PortsAndBuses/CAN/ICanBus.cs +++ b/Source/Meadow.Contracts/Hardware/Contracts/PortsAndBuses/CAN/ICanBus.cs @@ -8,14 +8,19 @@ namespace Meadow.Hardware; public interface ICanBus { /// - /// Gets or sets the bus bit rate + /// Raised when a CAN frame is received. /// - CanBitrate BitRate { get; set; } + event EventHandler? FrameReceived; /// - /// Occurs when a CAN frame is received. + /// Raised when a bus error occurs /// - event EventHandler? FrameReceived; + event EventHandler? BusError; + + /// + /// Gets or sets the bus bit rate + /// + CanBitrate BitRate { get; set; } /// /// Writes a CAN frame to the specified buffer.