diff --git a/src/Console/Program.cs b/src/Console/Program.cs index 0e66d22a..2e7b8a41 100644 --- a/src/Console/Program.cs +++ b/src/Console/Program.cs @@ -218,7 +218,7 @@ private static void RegisterEvents() _controlPanel.RawCardDataReplyReceived += (_, args) => { DisplayReceivedReply($"Received raw card data reply for address {args.Address}", - args.RawCardData.ToString()); + args.RawCardData.ToString() + args.RawCardData.HexData + "\n" + args.RawCardData.AsciiData); }; _controlPanel.KeypadReplyReceived += (_, args) => { diff --git a/src/OSDP.Net.Tests/OSDP.Net.Tests.csproj b/src/OSDP.Net.Tests/OSDP.Net.Tests.csproj index 6af477f5..b95a1ba2 100644 --- a/src/OSDP.Net.Tests/OSDP.Net.Tests.csproj +++ b/src/OSDP.Net.Tests/OSDP.Net.Tests.csproj @@ -1,7 +1,7 @@  - net8.0 + net6.0 false diff --git a/src/OSDP.Net/Model/ReplyData/DeviceCapability.cs b/src/OSDP.Net/Model/ReplyData/DeviceCapability.cs index eac8d4a9..e3c5bd83 100644 --- a/src/OSDP.Net/Model/ReplyData/DeviceCapability.cs +++ b/src/OSDP.Net/Model/ReplyData/DeviceCapability.cs @@ -54,12 +54,12 @@ public override string ToString() internal byte[] BuildData() { - return [(byte)Function, Compliance, NumberOf]; + return new byte[] { (byte)Function, Compliance, NumberOf }; } internal static DeviceCapability ParseData(byte[] data) { - var func = typeof(CapabilityFunction).IsEnumDefined((int)data[0]) + var func = typeof(CapabilityFunction).IsEnumDefined((int)data[0]) ? (CapabilityFunction)data[0] : CapabilityFunction.Unknown; @@ -75,7 +75,7 @@ internal static DeviceCapability ParseData(byte[] data) return cap; } - private static Dictionary> _capFactories = new () + private static Dictionary> _capFactories = new() { {CapabilityFunction.CommunicationSecurity, () => new CommSecurityDeviceCap() }, {CapabilityFunction.ReceiveBufferSize, () => new RcvBuffSizeDeviceCap() }, @@ -101,12 +101,12 @@ public override string ToString() /// /// Receive Buffer Size PD capability /// - public class RcvBuffSizeDeviceCap : MsgSizeDeviceCap; + public class RcvBuffSizeDeviceCap : MsgSizeDeviceCap { } /// /// Largest Combined Message Size PD capability /// - public class LargestCombMsgSizeDeviceCap : MsgSizeDeviceCap; + public class LargestCombMsgSizeDeviceCap : MsgSizeDeviceCap { } /// /// Communication Security PD capability diff --git a/src/OSDP.Net/Model/ReplyData/RawCardData.cs b/src/OSDP.Net/Model/ReplyData/RawCardData.cs index f10191a3..93e27a91 100644 --- a/src/OSDP.Net/Model/ReplyData/RawCardData.cs +++ b/src/OSDP.Net/Model/ReplyData/RawCardData.cs @@ -45,7 +45,9 @@ public RawCardData(byte readerNumber, FormatCode format, BitArray data) /// The raw card data. /// public BitArray Data { get; } - + public string HexData { get; private set; } + public string AsciiData { get; private set; } + /// public override byte Type => (byte)ReplyType.RawReaderData; @@ -64,11 +66,17 @@ public static RawCardData ParseData(ReadOnlySpan data) } ushort bitCount = Message.ConvertBytesToUnsignedShort(new[] {dataArray[2], dataArray[3]}); - var cardData = new BitArray(dataArray.Skip(4).Take(dataArray.Length - 4).Reverse().ToArray()); + var cardDatabytes = dataArray.Skip(4).Take(dataArray.Length - 4); + var cardData = new BitArray(cardDatabytes.Reverse().ToArray()); + Reverse(cardData); cardData.Length = bitCount; - return new RawCardData(dataArray[0], (FormatCode)dataArray[1], cardData); + return new RawCardData(dataArray[0], (FormatCode)dataArray[1], cardData) + { + HexData = BitConverter.ToString(cardDatabytes.ToArray()).Replace("-", ""), + AsciiData = Encoding.UTF8.GetString(cardDatabytes.ToArray()) + }; } /// diff --git a/src/OSDP.Net/OSDP.Net.csproj b/src/OSDP.Net/OSDP.Net.csproj index 1dcfe210..6f903b4c 100644 --- a/src/OSDP.Net/OSDP.Net.csproj +++ b/src/OSDP.Net/OSDP.Net.csproj @@ -7,7 +7,7 @@ Apache-2.0 icon.png default - net6.0;netstandard2.0;net8.0 + net6.0 true true snupkg diff --git a/src/OSDP.Net/PanelCommands/DeviceDiscover.cs b/src/OSDP.Net/PanelCommands/DeviceDiscover.cs index 91420075..8e77f009 100644 --- a/src/OSDP.Net/PanelCommands/DeviceDiscover.cs +++ b/src/OSDP.Net/PanelCommands/DeviceDiscover.cs @@ -14,7 +14,7 @@ namespace DeviceDiscover /// This namespace contains type definitions used specifically for /// /// - public static class NamespaceDoc; + public static class NamespaceDoc { } /// /// Represents an error condition encountered during device discovery diff --git a/src/samples/CardReader/CardReader.csproj b/src/samples/CardReader/CardReader.csproj index 9356b566..60cd4702 100644 --- a/src/samples/CardReader/CardReader.csproj +++ b/src/samples/CardReader/CardReader.csproj @@ -2,7 +2,7 @@ Exe - net8.0 + net6.0 enable enable default diff --git a/src/samples/CardReader/MySampleDevice.cs b/src/samples/CardReader/MySampleDevice.cs index 06844dab..db1559b7 100644 --- a/src/samples/CardReader/MySampleDevice.cs +++ b/src/samples/CardReader/MySampleDevice.cs @@ -9,7 +9,7 @@ internal class MySampleDevice : Device { protected override PayloadData HandleIdReport() { - return new DeviceIdentification([0x00, 0x00, 0x00], 0, 1, 0, 0, 0, 0); + return new DeviceIdentification(new byte[] { 0x00, 0x00, 0x00 }, 0, 1, 0, 0, 0, 0); } protected override PayloadData HandleDeviceCap(IncomingMessage command) diff --git a/src/samples/PivDataReader/Program.cs b/src/samples/PivDataReader/Program.cs index 6de0a6e6..d177ec4f 100644 --- a/src/samples/PivDataReader/Program.cs +++ b/src/samples/PivDataReader/Program.cs @@ -37,16 +37,16 @@ private static async Task Main() Console.Write( $"Device is {(eventArgs.IsConnected ? "Online" : "Offline")} in {(eventArgs.IsSecureChannelEstablished ? "Secure" : "Clear Text")} mode"); - if (eventArgs.IsConnected) - { - await panel.ACUReceivedSize(_connectionId, deviceAddress, maximumReceiveSize); - } + //if (eventArgs.IsConnected) + //{ + // await panel.ACUReceivedSize(_connectionId, deviceAddress, maximumReceiveSize); + //} }; panel.RawCardDataReplyReceived += (_, eventArgs) => { Console.WriteLine(); Console.WriteLine("Received raw card data"); - Console.Write(eventArgs.RawCardData.ToString()); + Console.Write(eventArgs.RawCardData.ToString() + eventArgs.RawCardData.HexData + "\n" + eventArgs.RawCardData.AsciiData); }; panel.NakReplyReceived += (_, args) => { @@ -71,33 +71,114 @@ private static async Task Main() while (!exit) { Console.WriteLine(); - Console.WriteLine("PIV Data Reader"); + Console.WriteLine("Data Reader"); Console.WriteLine(); - Console.WriteLine("1) Get PIV Data"); - + Console.WriteLine("1) Get ID Report"); + Console.WriteLine("2) Get Test LED"); + //Console.WriteLine("1) Get PIV Data"); + Console.WriteLine(); Console.WriteLine("0) Exit"); Console.WriteLine(); Console.Write("Select an action:"); - switch (Console.ReadKey(true).Key) + ConsoleKeyInfo key = default; + switch ((key= Console.ReadKey(true)).Key) { case ConsoleKey.D1: - await GetPivData(); + case ConsoleKey.NumPad1: + //await GetPivData(); + await GetIdReport(); + break; + case ConsoleKey.D2: + case ConsoleKey.NumPad2: + //await GetPivData(); + await TestLed(); break; case ConsoleKey.D0: exit = true; break; } + Console.WriteLine(); if (!exit) Console.Clear(); } await panel.Shutdown(); - + + async Task GetIdReport() + { + + Console.WriteLine(); + Console.Write("***Attempting to get Id Report***"); + Console.WriteLine(); + + try + { + var data = await panel.IdReport(_connectionId, deviceAddress); + + Console.Write(data); + } + catch (TimeoutException) + { + Console.WriteLine("Timeout waiting for Id Report"); + } + catch (Exception exception) + { + Console.WriteLine($"Exception: {exception}"); + } + + Console.WriteLine(); + Console.Write("Press enter to continue"); + Console.ReadLine(); + } + + async Task TestLed() + { + + Console.WriteLine(); + Console.Write("***Test LED***"); + Console.WriteLine(); + + try + { + //var readerLedControl = new ReaderLedControl(0, 0, + // TemporaryReaderControlCode.SetTemporaryAndStartTimer, + // 10, 0, LedColor.Red, LedColor.Black, 30, + // PermanentReaderControlCode.SetPermanentState,1,1, LedColor.Green, LedColor.Green + // ); + var readerLedControl = new ReaderLedControl(0, 0, + TemporaryReaderControlCode.SetTemporaryAndStartTimer, + 10, 10, LedColor.Red, LedColor.Black, 200, + PermanentReaderControlCode.Nop, 0, 0, LedColor.Black, LedColor.Black + ); + // var readerLedControl = new ReaderLedControl(0, 0, + // TemporaryReaderControlCode.Nop, + // 0, 0, LedColor.Black, LedColor.Black, 0, + // PermanentReaderControlCode.SetPermanentState, 1, 1, LedColor.Red, LedColor.Black + //); + var readerLedControls = new ReaderLedControls(new List() { readerLedControl }); + var data = await panel.ReaderLedControl(_connectionId, deviceAddress, readerLedControls); + + Console.Write(data); + } + catch (TimeoutException) + { + Console.WriteLine("Timeout waiting for testing LED"); + } + catch (Exception exception) + { + Console.WriteLine($"Exception: {exception}"); + } + + Console.WriteLine(); + Console.Write("Press enter to continue"); + Console.ReadLine(); + } + async Task GetPivData() { Console.Clear(); diff --git a/src/samples/PivDataReader/Properties/PublishProfiles/FolderProfile.pubxml b/src/samples/PivDataReader/Properties/PublishProfiles/FolderProfile.pubxml new file mode 100644 index 00000000..6b2d9f7a --- /dev/null +++ b/src/samples/PivDataReader/Properties/PublishProfiles/FolderProfile.pubxml @@ -0,0 +1,18 @@ + + + + + Debug + Any CPU + bin\Debug\net6.0\publish\linux-arm\ + FileSystem + <_TargetId>Folder + net6.0 + linux-arm + true + false + false + + \ No newline at end of file diff --git a/src/samples/PivDataReader/appsettings.json b/src/samples/PivDataReader/appsettings.json index e2abaad5..94e88002 100644 --- a/src/samples/PivDataReader/appsettings.json +++ b/src/samples/PivDataReader/appsettings.json @@ -7,7 +7,7 @@ } }, "OSDP": { - "PortName": "/dev/tty.usbserial-AB0MC3MS", + "PortName": "COM4", "BaudRate": "9600", "DeviceAddress": "0", "UseNetwork": "False",