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
60 changes: 30 additions & 30 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
name: push_nuget

# on push on main
on:
push:
branches:
- main
paths-ignore:
- README.md

jobs:
build:
runs-on: windows-latest
steps:
- name: Git Checkout
name: push_nuget
# on push on main
on:
push:
branches:
- main
paths-ignore:
- README.md
jobs:
build:
runs-on: windows-latest
steps:
- name: Git Checkout
uses: actions/checkout@master
with:
lfs: 'true'

- name: Setup MSBuild.exe
uses: microsoft/setup-msbuild@v2

- name: Setup Nuget.exe
uses: nuget/setup-nuget@v2.0.0

- name: Publish VL Nuget
uses: vvvv/PublishVLNuget@1.0.43
with:
nuspec: deployment\VL.Devices.RPLidar.nuspec
icon-src: https://raw.githubusercontent.com/vvvv/PublicContent/master/nugeticon.png
icon-dst: ./deployment/nugeticon.png
nuget-key: ${{ secrets.VVVV_ORG_NUGET_KEY }}
lfs: 'true'
- name: Setup MSBuild.exe
uses: microsoft/setup-msbuild@v2
- name: Setup Nuget.exe
uses: nuget/setup-nuget@v2.0.0
- name: Publish VL Nuget
uses: vvvv/PublishVLNuget@1.0.43
with:
nuspec: deployment\VL.Devices.RPLidar.nuspec
icon-src: https://raw.githubusercontent.com/vvvv/PublicContent/master/nugeticon.png
icon-dst: ./deployment/nugeticon.png
nuget-key: ${{ secrets.VVVV_ORG_NUGET_KEY }}
6 changes: 6 additions & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<Project>
<PropertyGroup>
<VLVersion>2025.7.1</VLVersion>
<RPLidar4NetVersion>0.5.0</RPLidar4NetVersion>
</PropertyGroup>
</Project>
15 changes: 15 additions & 0 deletions VL.Devices.RPLidar.slnx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Solution>
<Folder Name="/.workspace/">
<File Path=".gitattributes" />
<File Path=".gitignore" />
<File Path="Directory.Packages.props" />
</Folder>
<Folder Name="/.workspace/.github/" />
<Folder Name="/.workspace/.github/workflows/">
<File Path=".github/workflows/main.yml" />
</Folder>
<Folder Name="/.workspace/deployment/">
<File Path="deployment/VL.Devices.RPLidar.nuspec" />
</Folder>
<Project Path="src/VL.Devices.RPLidar.Advanced.csproj" />
</Solution>
1,166 changes: 1,165 additions & 1 deletion VL.Devices.RPLidar.vl

Large diffs are not rendered by default.

296 changes: 296 additions & 0 deletions help/Explanation RPLidar UDP.vl

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions src/Properties/AsseblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
using VL.Core.Import;

[assembly: ImportAsIs(Namespace = "VL.Devices.RPLidar.Advanced", Category = "Devices.RPLidar.Advanced")]
13 changes: 13 additions & 0 deletions src/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"profiles": {
"VL.Devices.RPLidar.Advanced": {
"commandName": "Project"
},
"dev/antokhio": {
"commandName": "Executable",
"executablePath": "C:\\Program Files\\vvvv\\vvvv_gamma_7.1-win-x64\\vvvv.exe",
"commandLineArgs": " --allow-multiple --package-repositories ..\\..\\; --editable-packages VL.Devices.RPLidar*;",
"workingDirectory": "$(ProjectDir)"
}
}
}
178 changes: 178 additions & 0 deletions src/RPLidarUDPSocketNode.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
using RPLidar4Net.Api.Data;
using RPLidar4Net.Api.Helpers;
using System.Net;
using System.Net.Sockets;
using VL.Core.Import;
using VL.Lib.Basics.Resources;
using VL.Lib.Collections;
using NetSocket = System.Net.Sockets.Socket;

namespace VL.Devices.RPLidar.Advanced
{
public enum RPLidarUDPState
{
Idle,
ScanSimple,
ScanDense,
ScanHighQuality,
NextPacketIsInfo,
}

public enum RPLidarUDPWorkMode
{
Legacy = 0x0,
Unknown1 = 0x1,
Unknown2 = 0x2,
}

public static class RPLidarUDPSocketHelper
{
public static bool IPEndPointEquals(IPEndPoint? input, IPEndPoint? input2)
{
if (ReferenceEquals(input, input2))
return true;
if (ReferenceEquals(input, null))
return false;
return input.Equals(input2);
}

public static byte[] FormatCommand(Command command, byte[] payload, bool includePayloadSize)
{
byte commandByte = CommandHelper.GetByte(command);

var packetBytes = new List<byte>();
packetBytes.Add(Constants.SYNC_BYTE);
packetBytes.Add(commandByte);

//Add payload
if (payload != null)
{
if (includePayloadSize)
packetBytes.Add((byte)payload.Length);
packetBytes.AddRange(payload);
byte checksum = 0;
foreach (var b in packetBytes)
checksum ^= b;
packetBytes.Add(checksum);
}

var packet = packetBytes.ToArray();

return packet;
}

public static byte[] RESPONSE_DESCRIPTOR_GET_INFO = new byte[]
{
0xA5,
0x5A,
0x14,
0x0,
0x0,
0x0,
0x4,
};

public static bool IsGetInfoResponse(Spread<byte> bytes) =>
bytes.ToArray().SequenceEqual(RESPONSE_DESCRIPTOR_GET_INFO);

public static InfoDataResponse ReadInfoDataResponse(byte[] bytes) =>
InfoDataResponseHelper.ToInfoDataResponse(bytes);

public static byte[] RESPONSE_DESCRIPTOR_SCAN_SCAN = new byte[]
{
0xA5,
0x5A,
0x05,
0x0,
0x0,
0x40,
0x81,
};
public static byte[] RESPONSE_DESCRIPTOR_SCAN_DENSE = new byte[]
{
0xA5,
0x5A,
0x54,
0x00,
0x00,
0x40,
0x85,
};
public static byte[] RESPONSE_DESCRIPTOR_SCAN_HIGHQL = new byte[]
{
0xA5,
0x5A,
0x0D,
0x03,
0x0,
0x40,
0x83,
};

public static bool IsScanResponse(byte[] bytes) =>
bytes.SequenceEqual(RESPONSE_DESCRIPTOR_SCAN_SCAN);

public static bool IsScanDenseResponse(byte[] bytes) =>
bytes.SequenceEqual(RESPONSE_DESCRIPTOR_SCAN_DENSE);

public static bool IsScanHightQlResponse(byte[] bytes) =>
bytes.SequenceEqual(RESPONSE_DESCRIPTOR_SCAN_HIGHQL);

public static byte[] FormattedExpressScanCommand(
RPLidarUDPWorkMode wm = RPLidarUDPWorkMode.Legacy
) =>
//FormatCommand(Command.ExpressScan, CommandHelper.GetExpressScanPayload((byte)wm), true);
RPLidarUDPSocketHelper.FormatCommand(
Command.ExpressScan,
new byte[] { (byte)wm, 0x0, 0x0, 0x0, 0x0 },
true
);
}

[ProcessNode(Name = "RPLidar", Category = "RPLidar.UDPSocket")]
public class RPLidarUDPSocketNode
{
ResourceProviderMonitor<NetSocket>? _provider;
private bool _connect = false;
private IPEndPoint? _remoteEndpoint;

public IResourceProvider<NetSocket> Update(
IPEndPoint remoteEndpoint,
bool connect,
bool enabled = true
)
{
if (
!RPLidarUDPSocketHelper.IPEndPointEquals(_remoteEndpoint, remoteEndpoint)
|| _connect != connect
)
{
_connect = connect;
_remoteEndpoint = remoteEndpoint;

_provider = ResourceProvider
.New(() =>
{
var socket = new NetSocket(SocketType.Dgram, ProtocolType.Udp);
socket.ExclusiveAddressUse = false;
socket.SetSocketOption(
SocketOptionLevel.Socket,
SocketOptionName.ReuseAddress,
true
);
if (connect && remoteEndpoint != null)
socket.Connect(remoteEndpoint);
return socket;
})
.ShareInParallel()
.Monitor();
}

if (enabled)
return _provider;
return null;
}

public bool IsOpen => _provider?.SinkCount > 0;
}
}
14 changes: 14 additions & 0 deletions src/VL.Devices.RPLidar.Advanced.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<BaseOutputPath>..\lib\</BaseOutputPath>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="VL.Core" Version="$(VLVersion)" />
<PackageReference Include="RPLidar4Net.Core" Version="0.3.0" />
<PackageReference Include="RPLidar4Net.IO" Version="0.5.0" />
<PackageReference Include="RPLidar4Net.Api" Version="0.5.0" />
</ItemGroup>
</Project>
9 changes: 9 additions & 0 deletions src/VL.Devices.RPLidar.Advanced.csproj.user
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DebuggerFlavor>ProjectDebugger</DebuggerFlavor>
</PropertyGroup>
<PropertyGroup>
<ActiveDebugProfile>dev/antokhio</ActiveDebugProfile>
</PropertyGroup>
</Project>