UdsProtocolToolkit 3.0.0.13-beta

This is a prerelease version of UdsProtocolToolkit.
There is a newer version of this package available.
See the version list below for details.
dotnet add package UdsProtocolToolkit --version 3.0.0.13-beta                
NuGet\Install-Package UdsProtocolToolkit -Version 3.0.0.13-beta                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="UdsProtocolToolkit" Version="3.0.0.13-beta" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add UdsProtocolToolkit --version 3.0.0.13-beta                
#r "nuget: UdsProtocolToolkit, 3.0.0.13-beta"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install UdsProtocolToolkit as a Cake Addin
#addin nuget:?package=UdsProtocolToolkit&version=3.0.0.13-beta&prerelease

// Install UdsProtocolToolkit as a Cake Tool
#tool nuget:?package=UdsProtocolToolkit&version=3.0.0.13-beta&prerelease                

UdsCore 3

[TOC]

使用案例

使用 DoCAN 协议构造 UDS 传输器

设置字段
#region 模拟 Tester
/// <summary>
/// Tester CAN 网络
/// </summary>
private static readonly BaseConnector testerNetwork = new IsoCanFdConnector("VectorApiTest", 0) { Name = "Tester CAN" };

/// <summary>
/// Tester 传输层参数
/// </summary>
private static readonly TransportLayerParameters testerTransportLayerParameters = new()
{
    RequestId = 0x77A,
    RequestIdExtend = false,
    ResponseId = 0x7BA,
    ResponseIdExtend = false,
    BlockSize = 3,
    STmin = 20,
    UseFd = false,
    MaxDlc = 15,
    MinDlc = 8,
    //TimeoutAs = 10,
    //TimeoutAr = 10,
    //TimeoutBs = 100,
    //TimeoutCr = 10,
    //TimeBr = 10,
    //TimeCs = 10,
};

/// <summary>
/// Tester UDS 应用层参数
/// </summary>
private static readonly ApplicationLayerParameters testerApplicationLayerParameters = new()
{
    P2Client = 150,
    P2_Client = 5500,
    suppressResponseWait = false,
    checkResponseServerId = true,
};

/// <summary>
/// Tester 接收消息的通道(已经通过过滤)
/// </summary>
private static readonly Channel<byte[]> testerReceiveCanDataChannel = System.Threading.Channels.Channel.CreateBounded<byte[]>(
    new BoundedChannelOptions(1000) 
    { 
        FullMode = BoundedChannelFullMode.Wait 
    });

/// <summary>
/// Tester 计划发送的通道(将转发给发送程序)
/// </summary>
private static readonly Channel<byte[]> testerSendCanDataChannel = System.Threading.Channels.Channel.CreateBounded<byte[]>(
    new BoundedChannelOptions(1000)
    {
        FullMode = BoundedChannelFullMode.Wait
    });

/// <summary>
/// Tester 发送的热可观察流(由发送程序订阅并完成发送)
/// </summary>
private static readonly IObservable<byte[]> testerSendObservable = testerSendCanDataChannel.MakeObservable();

/// <summary>
/// Tester 接收的热可观察流(持续从接收程序中提取,过滤后添加到 Tester 接收消息的通道)
/// </summary>
private static readonly IObservable<CanFrameEvent> testerReceiveObservable = testerNetwork.ReceivedChannel.MakeObservable();

/// <summary>
/// Tester DoCAN 传输器
/// </summary>
private static DoCanTransmitter? testerDoCanTransmitter;

/// <summary>
/// Tester UDS 传输器
/// </summary>
private static UdsTransmitter? testerUdsTransmitter;
#endregion 模拟 Tester
启动准备
#region 实现 Tester 连接
#region 连接 Tester 发送和接收的通道(使用可观察流连接通道)
// 从 CAN 驱动收到全部的 CAN 帧,过滤后写入 Tester 接收 Can Data 的通道。
testerReceiveObservable.Where(onNext =>
{
    return onNext.canFrame!.CanId == testerTransportLayerParameters.TesterId && onNext.canFrame!.CanIdExtendFlag == testerTransportLayerParameters.TesterIdExtend;
}).Subscribe(async (onNext) =>
{
    testerTransportLayerParameters.SuppressFd = !onNext.canFrame!.CanFdFlag;
    await testerReceiveCanDataChannel.Writer.WriteAsync(onNext.canFrame.Data);
});

// 从 Tester 发送通道中提取 Can Data,调用 CAN 驱动发送。
testerSendObservable.Subscribe(async (onNext) =>
{
    var canFrame = new CanFrame()
    {
        CanId = testerTransportLayerParameters.RequestId!.Value,
        DataLength = (byte)onNext.Length,
        Data = onNext
    };
    if (testerTransportLayerParameters.RequestIdExtend) canFrame.FrameType |= CanFrame.FrameTypes.Ex;
    if (testerTransportLayerParameters.UseFd) canFrame.FrameType |= CanFrame.FrameTypes.Fd;
    var r = await testerNetwork.SendAsync(new CanFrameEvent(canFrame));
});
#endregion 连接 Tester 发送和接收的通道

#region 构造 Tester DoCanTransmitter 对象(从通道构造发送和接收方法)
testerDoCanTransmitter = new(testerSendCanDataChannel,
    testerReceiveCanDataChannel,
    testerTransportLayerParameters)
{
    LogName = "Tester DoCAN"
};
#endregion 构造 Tester DoCanTransmitter 对象

#region 构造 Tester UdsTransmitter 对象
void clearSendQueue()
{
    while (testerSendCanDataChannel.Reader.TryRead(out _)) { }
}

void clearReceiveQueue()
{
    while (testerReceiveCanDataChannel.Reader.TryRead(out _)) { }
}

void restoreFdFlagMethod()
{
    testerTransportLayerParameters.SuppressFd = false;
};

testerUdsTransmitter = new(testerDoCanTransmitter.SendAsync,
    testerDoCanTransmitter.ReceiveAsync,
    clearSendQueue,
    clearReceiveQueue,
    testerApplicationLayerParameters)
{
    LogName = "Tester UDS",
    RestoreFdFlagMethod = restoreFdFlagMethod,
};
#endregion  构造 Tester UdsTransmitter 对象
#endregion 实现 Tester 连接
开始
(var b, var message) = await testerNetwork.OpenAsync();
结束
(var b, var message) = await testerNetwork.CloseAsync();

使用 DoCAN 协议构造 UDS 传输器

设置字段
#region Tester 字段
/// <summary>
/// Tester 网络层连接器
/// </summary>
private static readonly TcpConnector testerNetwork = new()
{
    Mode = TcpConnector.Modes.Client,
    IPAddressLocal = IPAddress.Parse("127.0.0.1"),
    PortLocal = 0,
    IPAddressRemote = IPAddress.Parse("127.0.0.1"),
    PortRemote = 13400,
};

/// <summary>
/// Tester DoIP 协议传输层参数
/// </summary>
private static readonly TransportLayerParameters testerTransportLayerParameters = new()
{
    RequestLogicalAddress = 0x1015,
    ResponseLogicalAddress = 0x0E80,
};

/// <summary>
/// Tester DoIP 协议传输器
/// </summary>
private static readonly DoIpTransmitter testerDoIpTransmitter = new(testerNetwork.SendAsync, testerNetwork.ReceiveAsync, testerTransportLayerParameters);

/// <summary>
/// Tester UDS 应用层参数
/// </summary>
private static readonly ApplicationLayerParameters testerApplicationLayerParameters = new()
{
    suppressResponseWait = false,
    checkResponseServerId = true,
};

/// <summary>
/// Tester UDS 协议传输器
/// </summary>
private static readonly UdsTransmitter testerUdsTransmitter = new(testerDoIpTransmitter.SendAsync, testerDoIpTransmitter.ReceiveAsync, applicationLayerParameters: testerApplicationLayerParameters);
#endregion Tester 字段
开始
var r = await testerNetwork.OpenAsync();
结束
var r = await testerNetwork.closeAsync();

使用 UDS 传输器

var data = new byte[3] { 0x22, 0xF1, 0x8C };
var r = await testerUdsTransmitter.SendRequestAndReceiveResponseAsync(data);
// var r = await ecuUdsTransmitter.ReceiveRequestAndSendResponseAsync();
Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
3.3.1 119 9/4/2024
3.3.0.1 92 9/3/2024
3.3.0 117 8/12/2024
3.2.0 141 4/18/2024
3.1.0 106 4/3/2024
3.0.0.13-pre 97 2/22/2024
3.0.0.13-beta 104 2/22/2024