Skip to content

Commit

Permalink
Merge pull request #40 from mika-eng/main
Browse files Browse the repository at this point in the history
Issue #30
  • Loading branch information
densogiaichned authored Aug 30, 2023
2 parents 8ad7111 + f0fbe15 commit b166830
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ bld/
# Visual Studio 2017 auto generated files
Generated\ Files/

# Rider auto generated files
.idea/

# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*
Expand Down
4 changes: 2 additions & 2 deletions src/dsian.TcPnScanner.CLI/Export/TC/XtiExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ private static TcSmItem MapDevices(IEnumerable<Device> devices)
{
var tcSmItem = Create();

var boxes = new List<TcSmItemDeviceBox>(devices.Count());
foreach (var device in devices)
var boxes = new List<TcSmItemDeviceBox>(devices.Count(x => x.PnIoConnectRequestPacket is not null));
foreach (var device in devices.Where(x => x.PnIoConnectRequestPacket is not null))
{
var box = new TcSmItemDeviceBox
{
Expand Down
27 changes: 24 additions & 3 deletions src/dsian.TcPnScanner.CLI/Packets/PacketHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,11 @@ private void SendProfinetDcpIdentResponsePacket(ProfinetDcpIdentRequestPacket pn
data.Add(0x0);

var blockDevName = BlockDeviceNameOfStation(pnPacket).Reverse().ToArray();

data.AddRange(BitConverter.GetBytes((ushort)blockDevName.Length).Reverse());

var blockIpIp = BlockIpIp().Reverse().ToArray();

data.AddRange(BitConverter.GetBytes((ushort)(blockDevName.Length + blockIpIp.Length)).Reverse());
data.AddRange(blockDevName);
data.AddRange(blockIpIp);

responsePacket.PayloadData = data.ToArray();
_captureDevice.SendPacketHandler(responsePacket);
Expand All @@ -102,6 +103,26 @@ private byte[] BlockDeviceNameOfStation(ProfinetDcpIdentRequestPacket pnPacket)
data.AddRange(BitConverter.GetBytes((ushort)(lenName + 2)).Reverse()); // DcpBlockLength
data.AddRange(BitConverter.GetBytes((ushort)0x0)); //reserved
data.AddRange(Encoding.UTF8.GetBytes(pnPacket.NameOfStation));

if (lenName % 2 != 0)
{
data.Add(0x0); //Padding byte
}

data.Reverse();
return data.ToArray();
}

private byte[] BlockIpIp()
{
var data = new List<byte>();
data.Add(0x1); // Option: IP
data.Add(0x2); // Suboption: IP Parameter
data.AddRange(BitConverter.GetBytes((ushort)14).Reverse()); // DcpBlockLength
data.AddRange(BitConverter.GetBytes((ushort)0x0000).Reverse()); // IP not set
data.AddRange(BitConverter.GetBytes((uint)0x00000000).Reverse()); // IP Address
data.AddRange(BitConverter.GetBytes((uint)0x00000000).Reverse()); // Subnet Mask
data.AddRange(BitConverter.GetBytes((uint)0x00000000).Reverse()); // Gateway
data.Reverse();
return data.ToArray();
}
Expand Down

0 comments on commit b166830

Please sign in to comment.