Oakrey.Capsule.Lin
2.0.2
dotnet add package Oakrey.Capsule.Lin --version 2.0.2
NuGet\Install-Package Oakrey.Capsule.Lin -Version 2.0.2
<PackageReference Include="Oakrey.Capsule.Lin" Version="2.0.2" />
<PackageVersion Include="Oakrey.Capsule.Lin" Version="2.0.2" />
<PackageReference Include="Oakrey.Capsule.Lin" />
paket add Oakrey.Capsule.Lin --version 2.0.2
#r "nuget: Oakrey.Capsule.Lin, 2.0.2"
#:package Oakrey.Capsule.Lin@2.0.2
#addin nuget:?package=Oakrey.Capsule.Lin&version=2.0.2
#tool nuget:?package=Oakrey.Capsule.Lin&version=2.0.2
Oakrey.Capsule.Lin
Project overview
Oakrey.Capsule.Lin is a .NET 10 class library that encodes LIN bus data into the Oakrey Capsule binary framing protocol (v2). It provides strongly-typed capsule types for LIN data frames, channel information, and channel settings, together with supporting enumerations and a message factory. The library targets automotive, industrial, and IoT data-logging scenarios where LIN bus traffic must be captured and transmitted in a compact binary format.
Main features
- LinDataCapsule (capsule ID
0x0201) � carries one or moreLinMessagerecords in a single capsule. Supports multi-message batching via theLinStatus.MultiModeMessageflag and compact delta-timestamp encoding for subsequent messages. - LinChannelInfoCapsule (capsule ID
0x0200) � reports the current state of a LIN channel: status (Disabled,Ok,BusError), capability flags, maximum baud rate, and optional alias. - LinChannelSettingCapsule (capsule ID
0x0202) � carries the desired configuration for a LIN channel: operating mode, data baud rate, pull-up setting, and optional alias. - LinMessageFactory � creates
LinMessageinstances from raw binary payloads; handles both single-timestamp and delta-timestamp formats. - Full serialize / deserialize round-trip via
CapsuleBaseinfrastructure. - Static
GetRequestPayload()helpers on each capsule for generating query frames.
Architecture
classDiagram
class CapsuleBase {
+Serialize() byte[]
+Head : CapsuleHead
}
class LinDataCapsule {
+Id : ushort = 0x0201
+ChannelIndex : byte
+Flag : LinStatus
+Messages : IList~LinMessage~
}
class LinChannelInfoCapsule {
+Id : ushort = 0x0200
+ChannelIndex : byte
+Status : LinChannelStatus
+Setting : LinChannelFlag
+MaxBaudRate : ushort
+Alias : string
}
class LinChannelSettingCapsule {
+Id : ushort = 0x0202
+ChannelIndex : byte
+Setting : LinChannelSetting
+Mode : LinChannelMode
+DataBaudRate : uint
+Alias : string
}
class LinMessage {
+Timestamp : long
+Id : long
+Data : byte[]
}
class LinMessageFactory {
+FromPayload(payload, out totalSize) LinMessage
+FromPayload(payload, out totalSize, timestamp) LinMessage
}
CapsuleBase <|-- LinDataCapsule
CapsuleBase <|-- LinChannelInfoCapsule
CapsuleBase <|-- LinChannelSettingCapsule
LinDataCapsule "1" --> "*" LinMessage
LinMessageFactory ..> LinMessage : creates
Enumerations
| Type | Kind | Values |
|---|---|---|
LinChannelMode |
enum | Observer, Slave, Master, Scheduler |
LinChannelStatus |
enum | Disabled, Ok, BusError |
LinChannelFlag |
flags | HasPullUp, SupportObserverMode, SupportSlaveMode, SupportMasterMode, SupportSchedulerMode |
LinChannelSetting |
flags | PullUpEnabled |
LinStatus |
flags | PullUpEnabled, MultiModeMessage |
Requirements
- .NET 10 or higher
Oakrey.Collections2.0.0 (transitive dependency)Oakrey.Capsule2.x (project reference / NuGet)
Build instructions
dotnet build Capsule.Lin/Capsule.Lin.csproj
To produce a NuGet package:
dotnet pack Capsule.Lin/Capsule.Lin.csproj -c Release
Installation
.NET CLI
dotnet add package Oakrey.Capsule.Lin
Package Manager Console
Install-Package Oakrey.Capsule.Lin
NuGet Package Manager
Search for Oakrey.Capsule.Lin in Tools > NuGet Package Manager > Manage NuGet Packages for Solution.
Example usage
Serialize a single LIN message
using Oakrey.Capsule.Lin;
byte[] data = [0x01, 0x02, 0x03, 0x04];
LinMessage message = new(DateTime.UtcNow.Ticks, frameId: 0x10, data);
LinDataCapsule capsule = new(message, LinStatus.PullUpEnabled, channelIndex: 0, hwId: 1);
byte[] frame = capsule.Serialize();
Serialize multiple LIN messages (batched)
IEnumerable<LinMessage> messages = GetMessages();
LinDataCapsule capsule = new(
messages,
LinStatus.PullUpEnabled | LinStatus.MultiModeMessage,
channelIndex: 0,
hwId: 1);
byte[] frame = capsule.Serialize();
Deserialize a received capsule
byte[] received = ReceiveFrame();
LinDataCapsule capsule = new(received);
foreach (LinMessage msg in capsule.Messages)
{
Console.WriteLine(msg);
}
Request channel information
byte[] requestFrame = LinChannelInfoCapsule.GetRequestPayload();
// send requestFrame over transport
Deserialize a channel info reply
byte[] reply = ReceiveFrame();
LinChannelInfoCapsule info = new(reply);
Console.WriteLine($"Channel {info.ChannelIndex}: {info.Status}, max {info.MaxBaudRate} baud");
Configure a channel
LinChannelSettingCapsule setting = new(
channelIndex: 0,
setting: LinChannelSetting.PullUpEnabled,
mode: LinChannelMode.Master,
dataBaudRate: 19200,
alias: "LIN_1");
byte[] frame = setting.Serialize();
Development notes
- All capsule types inherit from
CapsuleBaseand follow the Capsule binary protocol v2 framing. LinDataCapsuleuses a compact delta-timestamp encoding whenLinStatus.MultiModeMessageis set: the first message carries an absolute timestamp from the capsule header, and subsequent messages carry auinttick difference relative to the first message. The maximum representable delta isuint.MaxValueticks.LinMessageFactorydistinguishes between single-message payloads (10 + N bytes) and multi-message payloads (14 + N bytes per subsequent message) based on the call overload, not an inline marker.GetRequestPayload()serializes an empty capsule instance, which is the standard way to request data from a device using the Capsule protocol.
License
MIT. Copyright Oakrey 2016-present.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Oakrey.Capsule.Base (>= 2.0.2)
- Oakrey.Collections (>= 2.0.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.