Skip to content

Commit

Permalink
Updated to .NET Core
Browse files Browse the repository at this point in the history
  • Loading branch information
HakanL committed Dec 4, 2019
1 parent 21275de commit 48510da
Show file tree
Hide file tree
Showing 35 changed files with 211 additions and 983 deletions.
80 changes: 8 additions & 72 deletions Utils/DMXrecorder/Common/Common.csproj
Original file line number Diff line number Diff line change
@@ -1,77 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{3B9FB049-939E-4DD6-AAFD-DCC5564BAEF6}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<TargetFramework>netstandard2.0</TargetFramework>
<RootNamespace>Animatroller.Common</RootNamespace>
<AssemblyName>Common</AssemblyName>
<TargetFrameworkVersion>v4.7.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Acn">
<HintPath>..\lib\Acn.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="FseqFileReader.cs" />
<Compile Include="IFileWriter.cs" />
<Compile Include="IFileReader.cs" />
<Compile Include="BinaryFileReader.cs" />
<Compile Include="BinaryFileWriter.cs" />
<Compile Include="CsvFileWriter.cs" />
<Compile Include="BaseFileReader.cs" />
<Compile Include="BaseFileWriter.cs" />
<Compile Include="DmxData.cs" />
<Compile Include="PCapAcnFileReader.cs" />
<Compile Include="PCapAcnFileWriter.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="XLightsNetworksFileFormat.cs" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="NUnit">
<Version>3.12.0</Version>
</PackageReference>
<PackageReference Include="PcapngUtils">
<Version>1.0.7</Version>
</PackageReference>
<PackageReference Include="Haukcode.PcapngUtils" Version="1.0.8" />
<PackageReference Include="Haukcode.sACN" Version="1.0.6" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

</Project>
6 changes: 3 additions & 3 deletions Utils/DMXrecorder/Common/DmxData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public enum DataTypes

public byte[] Data { get; set; }

public ulong TimestampMS { get; set; }
public double TimestampMS { get; set; }

public long Sequence { get; set; }

Expand All @@ -29,7 +29,7 @@ public DmxData()
{
}

public static DmxData CreateNoChange(ulong millisecond, long sequence, int universe)
public static DmxData CreateNoChange(double millisecond, long sequence, int universe)
{
return new DmxData
{
Expand All @@ -41,7 +41,7 @@ public static DmxData CreateNoChange(ulong millisecond, long sequence, int unive
};
}

public static DmxData CreateFullFrame(ulong millisecond, long sequence, int universe, byte[] data)
public static DmxData CreateFullFrame(double millisecond, long sequence, int universe, byte[] data)
{
return new DmxData
{
Expand Down
37 changes: 22 additions & 15 deletions Utils/DMXrecorder/Common/PCapAcnFileReader.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using PcapngUtils;
using PcapngUtils.Pcap;
using Haukcode.PcapngUtils;
using Haukcode.PcapngUtils.Pcap;
using Haukcode.sACN;
using Haukcode.sACN.Model;
using System;
using System.Collections.Generic;
using System.IO;
Expand All @@ -12,8 +14,8 @@ namespace Animatroller.Common
{
public class PCapAcnFileReader : IFileReader, IDisposable
{
private PcapngUtils.Common.IReader reader;
private List<PcapngUtils.Common.IPacket> packets;
private Haukcode.PcapngUtils.Common.IReader reader;
private List<Haukcode.PcapngUtils.Common.IPacket> packets;
private int readPosition;

public bool DataAvailable
Expand All @@ -23,15 +25,15 @@ public bool DataAvailable

public PCapAcnFileReader(string fileName)
{
this.packets = new List<PcapngUtils.Common.IPacket>();
this.packets = new List<Haukcode.PcapngUtils.Common.IPacket>();
this.reader = IReaderFactory.GetReader(fileName);
this.reader.OnReadPacketEvent += Reader_OnReadPacketEvent;

// Reads all packets
this.reader.ReadPackets(CancellationToken.None);
}

private void Reader_OnReadPacketEvent(object context, PcapngUtils.Common.IPacket packet)
private void Reader_OnReadPacketEvent(object context, Haukcode.PcapngUtils.Common.IPacket packet)
{
this.packets.Add(packet);
}
Expand Down Expand Up @@ -86,26 +88,31 @@ public DmxData ReadFrame()

var dataStream = new MemoryStream(pcapData.Data);
ReadNetworkPacket(dataStream);
var reader = new Acn.IO.AcnBinaryReader(dataStream);
var packet = Acn.AcnPacket.ReadPacket(reader) as Acn.Packets.sAcn.StreamingAcnDmxPacket;
if (packet == null)

byte[] dataBytes = new byte[dataStream.Length - dataStream.Position];
dataStream.Read(dataBytes, 0, dataBytes.Length);

var packet = SACNPacket.Parse(dataBytes);
var framingLayer = packet?.RootLayer?.FramingLayer;
var dmpLayer = framingLayer?.DMPLayer;
if (dmpLayer == null)
throw new InvalidDataException("Not a valid Streaming DMX ACN packet");

byte[] dmxData;
if (packet.Dmx.StartCode == 0xff)
if (dmpLayer.StartCode == 0xff)
{
dmxData = new byte[packet.Dmx.Data.Length - 1];
Buffer.BlockCopy(packet.Dmx.Data, 1, dmxData, 0, dmxData.Length);
dmxData = new byte[dmpLayer.Data.Length - 1];
Buffer.BlockCopy(dmpLayer.Data, 1, dmxData, 0, dmxData.Length);
}
else
dmxData = packet.Dmx.Data;
dmxData = dmpLayer.Data;

return new DmxData
{
DataType = DmxData.DataTypes.FullFrame,
Sequence = packet.Framing.SequenceNumber,
Sequence = framingLayer.SequenceID,
TimestampMS = pcapData.Seconds * 1000 + (ulong)(pcapData.Microseconds / 1000),
Universe = packet.Framing.Universe,
Universe = framingLayer.UniverseID,
Data = dmxData
};
}
Expand Down
56 changes: 37 additions & 19 deletions Utils/DMXrecorder/Common/PCapAcnFileWriter.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
using PcapngUtils;
using PcapngUtils.Pcap;
using Haukcode.PcapngUtils;
using Haukcode.PcapngUtils.Pcap;
using Haukcode.sACN;
using Haukcode.sACN.Model;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
Expand All @@ -15,7 +18,7 @@ public class PCapAcnFileWriter : IFileWriter, IDisposable
public readonly Guid AcnId = new Guid("{29D35C91-702E-4B7E-9ACD-D343FD15DDEE}");
public const string AcnSourceName = "DmxFileWriter";

private PcapngUtils.Common.IWriter writer;
private Haukcode.PcapngUtils.Common.IWriter writer;
private byte priority;

public PCapAcnFileWriter(string fileName, byte priority = 100)
Expand Down Expand Up @@ -167,28 +170,43 @@ private void SetUDPCheckSum(MemoryStream memStream)
buf[41] = (byte)(sum & 0xFF);
}

public static IPAddress GetUniverseAddress(int universe)
{
if (universe < 0 || universe > 63999)
throw new InvalidOperationException("Unable to determine multicast group because the universe must be between 1 and 64000. Universes outside this range are not allowed.");

byte[] group = new byte[] { 239, 255, 0, 0 };

group[2] = (byte)((universe >> 8) & 0xff); //Universe Hi Byte
group[3] = (byte)(universe & 0xff); //Universe Lo Byte

return new IPAddress(group);
}

public static IPEndPoint GetUniverseEndPoint(int universe)
{
return new IPEndPoint(GetUniverseAddress(universe), 5568);
}

public void Output(DmxData dmxData)
{
if (dmxData.DataType == DmxData.DataTypes.NoChange)
return;

var packet = new Acn.Packets.sAcn.StreamingAcnDmxPacket();
packet.Framing.SourceName = AcnSourceName;
packet.Framing.Universe = (short)dmxData.Universe;
packet.Framing.Priority = this.priority;
packet.Framing.SequenceNumber = (byte)dmxData.Sequence;
packet.Dmx.StartCode = 0;
packet.Dmx.Data = dmxData.Data;
var packet = new SACNPacket(new RootLayer(
uuid: AcnId,
sourceName: AcnSourceName,
universeID: (ushort)dmxData.Universe,
sequenceID: (byte)dmxData.Sequence,
data: dmxData.Data,
priority: this.priority));

var destinationEP = Acn.Sockets.StreamingAcnSocket.GetUniverseEndPoint(dmxData.Universe);

packet.Root.SenderId = AcnId;
var destinationEP = GetUniverseEndPoint(dmxData.Universe);

using (var data = new MemoryStream())
{
var writer = new Acn.IO.AcnBinaryWriter(data);

Acn.AcnPacket.WritePacket(packet, writer);
byte[] packetBytes = packet.ToArray();
data.Write(packetBytes, 0, packetBytes.Length);

using (var networkData = new MemoryStream())
{
Expand All @@ -201,9 +219,9 @@ public void Output(DmxData dmxData)

SetUDPCheckSum(networkData);

ulong secs = dmxData.TimestampMS / 1000;
ulong usecs = (dmxData.TimestampMS * 1000) - (secs * 1000000);
var pcapData = new PcapngUtils.Pcap.PcapPacket(secs, usecs, networkData.ToArray(), 0);
ulong secs = (ulong)(dmxData.TimestampMS / 1000);
ulong usecs = (ulong)((dmxData.TimestampMS * 1000) - (secs * 1000000));
var pcapData = new PcapPacket(secs, usecs, networkData.ToArray(), 0);
this.writer.WritePacket(pcapData);
}
}
Expand Down
36 changes: 0 additions & 36 deletions Utils/DMXrecorder/Common/Properties/AssemblyInfo.cs

This file was deleted.

6 changes: 0 additions & 6 deletions Utils/DMXrecorder/ConverterUI/App.config

This file was deleted.

2 changes: 1 addition & 1 deletion Utils/DMXrecorder/ConverterUI/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
xmlns:local="clr-namespace:Animatroller.ConverterUI"
StartupUri="MainWindow.xaml">
<Application.Resources>

</Application.Resources>
</Application>
Loading

0 comments on commit 48510da

Please sign in to comment.