📖
README.md
SharpDlt
A pure, dependency free .NET library to read AUTOSAR DLT (Diagnostic Log and Trace) data.
The parser is modelled after the PyDLT reader, but exposes an idiomatic C# API: the entry point is a function that turns a stream into a lazily evaluated sequence of DLT messages.
Usage
using SharpDlt;
// From a file (the file is opened and closed by the reader)
foreach (var message in DltReader.ReadMessages("trace.dlt"))
{
Console.WriteLine(message);
}
// From any stream (the caller keeps ownership of the stream)
using var stream = File.OpenRead("trace.dlt");
foreach (var message in DltReader.ReadMessages(stream))
{
if (message.VerbosePayload is { } payload)
{
foreach (var argument in payload.Arguments)
{
Console.WriteLine(argument);
}
}
}
// Asynchronously
await foreach (var message in DltReader.ReadMessagesAsync("trace.dlt"))
{
Console.WriteLine(message.StandardHeader.Timestamp);
}
Options are passed via DltReaderOptions:
var options = new DltReaderOptions
{
HasStorageHeader = false, // messages without a Storage Header, e.g. from a socket
StringEncoding = Encoding.Latin1, // encoding of 8 bit coded string arguments (default: ASCII)
};
var messages = DltReader.ReadMessages(stream, options);
A single message can also be parsed from a span of bytes:
var message = DltMessage.Parse(bytes, options);
Object model
| Type | Description |
|---|---|
DltMessage |
Storage Header, Standard Header, Extended Header and payload of one message |
StorageHeader |
Timestamp and ECU ID of a message stored in a DLT file |
StandardHeader |
Header type, message counter, length and the optional ECU ID, session ID and timestamp |
ExtendedHeader |
Verbose flag, message type and type info, argument count, application and context ID |
NonVerbosePayload |
Message ID and non-static data |
VerbosePayload |
List of DltArgument values |
DltArgument |
DltBoolArgument, DltSignedArgument, DltUnsignedArgument, DltFloatArgument, DltStringArgument, DltRawArgument |
All of these are records, so they can be compared, deconstructed and pattern matched.
DltMessage.ToString() renders the same overview line as the reference implementation.
Behavior
- Reading stops silently as soon as the remaining data does not contain a complete message.
- Malformed data throws a
DltParseException. - If a numeric argument at the end of a payload has fewer bytes than its declared type, it is reduced to the next smaller type, which mirrors DLT Viewer and the reference implementation.
- Not supported (as in the reference implementation): arrays, structs, trace info, variable info, fixed point and 128 bit types.
Development
dotnet build
dotnet test
dotnet csharpier format .
This project uses git hooks for code style checks. Activate them by including the .githooks file:
git config --local include.path ../.githooks