diff --git a/DotNetDash.CameraViews/BitmapSink.cs b/DotNetDash.CameraViews/BitmapSink.cs new file mode 100644 index 0000000..26083a1 --- /dev/null +++ b/DotNetDash.CameraViews/BitmapSink.cs @@ -0,0 +1,116 @@ +using FRC.CameraServer; +using FRC.CameraServer.Interop; +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Drawing.Imaging; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using CsPixelFormat = FRC.CameraServer.PixelFormat; + +namespace DotNetDash.CameraViews +{ + public class BitmapSink : ImageSink + { + private CS_RawFrame frame = new CS_RawFrame(); + unsafe byte* dataPtr; + int width; + int height; + int pixelFormat; + + + public BitmapSink(string name) + : base(CsCore.CreateRawSink(name.AsSpan())) + { + + } + + public long GrabFrame(ref Bitmap image) + { + return GrabFrame(ref image, .225); + } + + public unsafe long GrabFrame(ref Bitmap image, double timeout) + { + frame.width = 0; + frame.height = 0; + frame.pixelFormat = (int)CsPixelFormat.BGR; + + ulong rv = CsCore.GrabRawSinkFrameTimeout(Handle, ref frame, timeout); + if (rv == 0) return 0; + + + if (dataPtr != frame.data || width != frame.width || height != frame.height || pixelFormat != frame.pixelFormat) + { + dataPtr = frame.data; + width = frame.width; + height = frame.height; + pixelFormat = frame.pixelFormat; + } + + if (image == null || image.Width != width || image.Height != height || image.PixelFormat != System.Drawing.Imaging.PixelFormat.Format24bppRgb) + { + image = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format24bppRgb); + } + + ToBitmap(frame, image); + + //BitmapConverter.ToBitmap(tmpMat, image); + return (long)rv; + } + + private unsafe void ToBitmap(in CS_RawFrame src, Bitmap dst) + { + var pf = dst.PixelFormat; + + if (pf != System.Drawing.Imaging.PixelFormat.Format24bppRgb) + { + throw new Exception("Unsupported pixel format"); + } + + int w = src.width; + int h = src.height; + + Rectangle rect = new Rectangle(0, 0, w, h); + BitmapData bd = null; + + try + { + bd = dst.LockBits(rect, ImageLockMode.WriteOnly, pf); + + IntPtr srcData = (IntPtr)src.data; + byte* pSrc = (byte*)srcData.ToPointer(); + byte* pDst = (byte*)bd.Scan0.ToPointer(); + int ch = 3; + int sstep = src.width * ch; + int dstep = ((src.width * 3) + 3) / 4 * 4; + int stride = bd.Stride; + + if (sstep == dstep) + { + CopyMemory(pDst, pSrc, src.totalData); + } + else + { + for (int y = 0; y < h; y++) + { + long offsetSrc = (long)y * sstep; + long offsetDst = (long)y * dstep; + + CopyMemory(pDst + offsetDst, pSrc + offsetSrc, w * ch); + } + } + } + finally + { + dst.UnlockBits(bd); + } + } + + private unsafe void CopyMemory(void* outDest, void* inSrc, int inNumOfBytes) + { + Buffer.MemoryCopy(inSrc, outDest, inNumOfBytes, inNumOfBytes); + } + } +} diff --git a/DotNetDash.CameraViews/CameraInfoRootTableProcessor.cs b/DotNetDash.CameraViews/CameraInfoRootTableProcessor.cs index a63954b..e7f70a4 100644 --- a/DotNetDash.CameraViews/CameraInfoRootTableProcessor.cs +++ b/DotNetDash.CameraViews/CameraInfoRootTableProcessor.cs @@ -5,13 +5,13 @@ using System.Text; using System.Threading.Tasks; using DotNetDash.BuiltinProcessors; -using NetworkTables.Tables; +using FRC.NetworkTables; namespace DotNetDash.CameraViews { class CameraInfoRootTableProcessor : DefaultRootTableProcessor { - public CameraInfoRootTableProcessor(string name, ITable table, IEnumerable> processorFactories) : base(name, table, processorFactories) + public CameraInfoRootTableProcessor(string name, NetworkTable table, IEnumerable> processorFactories) : base(name, table, processorFactories) { } @@ -29,7 +29,7 @@ public CameraInfoRootTableProcessorFactory([ImportMany] IEnumerable> processorFactories) : base(name, table, processorFactories) + public CameraInformationProcessor(string name, NetworkTable table, IEnumerable> processorFactories) : base(name, table, processorFactories) { } @@ -31,7 +31,7 @@ public CameraInformationProcessorFactory([ImportMany] IEnumerable /// Interaction logic for BaseCameraView.xaml /// - public partial class CameraView : UserControl, INotifyPropertyChanged + public partial class CsCameraView : UserControl, INotifyPropertyChanged { - public CameraView() + public CsCameraView() { DataContext = this; InitializeComponent(); IsVisibleChanged += OnIsVisibleChanged; } + volatile bool doUpdate = false; + private void OnIsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e) { var isVisible = (bool)e.NewValue; - if (isVisible) - CurrentDevice?.Start(); - else - CurrentDevice?.SignalToStop(); + doUpdate = isVisible; } - public IVideoSource currentDevice; + public CsVideoSource currentDevice; - public IVideoSource CurrentDevice + public CsVideoSource CurrentDevice { get { @@ -42,7 +41,6 @@ public IVideoSource CurrentDevice { if (currentDevice != null) { - currentDevice.NewFrame -= NewFrame; currentDevice.Stop(); } currentDevice = value; @@ -54,15 +52,14 @@ public IVideoSource CurrentDevice } } - private void NewFrame(object sender, NewFrameEventArgs eventArgs) + private void NewFrame(object sender, Bitmap bitmap) { - var bitmap = eventArgs.Frame.Clone() as System.Drawing.Bitmap; + if (!doUpdate) return; var previous = View; Stream stream = unusedStream; stream.Seek(0, SeekOrigin.Begin); bitmap.Save(stream, System.Drawing.Imaging.ImageFormat.Bmp); stream.Seek(0, SeekOrigin.Begin); - bitmap.Dispose(); Dispatcher.Invoke(() => { diff --git a/DotNetDash.CameraViews/CsVideoSource.cs b/DotNetDash.CameraViews/CsVideoSource.cs new file mode 100644 index 0000000..d2fe617 --- /dev/null +++ b/DotNetDash.CameraViews/CsVideoSource.cs @@ -0,0 +1,56 @@ +using FRC.CameraServer; +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace DotNetDash.CameraViews +{ + public class CsVideoSource + { + private Thread readThread; + private volatile bool isRunning = true; + private BitmapSink cvSink; + private Bitmap bitmap; + private VideoSource source; + + public event EventHandler NewFrame; + + public CsVideoSource(BitmapSink sink, VideoSource source) + { + cvSink = sink; + this.source = source; + } + + public void Start() + { + readThread = new Thread(ThreadMain); + readThread.IsBackground = true; + readThread.Start(); + } + + private void ThreadMain() + { + while (isRunning) + { + var ret = cvSink.GrabFrame(ref bitmap); + if (!isRunning) return; + if (ret == 0) continue; + + NewFrame?.Invoke(this, bitmap); + } + } + + public void Stop() + { + isRunning = false; + if (readThread != null) + { + readThread.Join(); + } + } + } +} diff --git a/DotNetDash.CameraViews/DotNetDash.CameraViews.csproj b/DotNetDash.CameraViews/DotNetDash.CameraViews.csproj index e677fff..d2b6082 100644 --- a/DotNetDash.CameraViews/DotNetDash.CameraViews.csproj +++ b/DotNetDash.CameraViews/DotNetDash.CameraViews.csproj @@ -1,128 +1,32 @@ - - - + + - Debug - AnyCPU - {75EFB940-7C2F-4535-9C6B-A6A3BC01622B} - Library - Properties - DotNetDash.CameraViews - DotNetDash.CameraViews - v4.6 - 512 + netcoreapp3.1 + true + true + true + Debug;Release;Publish - - true - full - false - ..\bin\Debug\Plugins\CameraViews\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - ..\bin\Release\Plugins\CameraViews\ - TRACE - prompt - 4 - - - - ..\packages\AForge.2.2.5\lib\AForge.dll - True - - - ..\packages\AForge.Video.2.2.5\lib\AForge.Video.dll - True - - - ..\packages\AForge.Video.DirectShow.2.2.5\lib\AForge.Video.DirectShow.dll - True - - - ..\packages\FRC.NetworkTables.3.1.6\lib\net46\FRC.NetworkTables.dll - True - - - ..\packages\Nito.AsyncEx.Coordination.1.0.2\lib\net46\Nito.AsyncEx.Coordination.dll - True - - - ..\packages\Nito.AsyncEx.Tasks.1.0.1\lib\net46\Nito.AsyncEx.Tasks.dll - True - - - ..\packages\Nito.Collections.Deque.1.0.0\lib\portable45-net45+win8+wp8+wpa81\Nito.Collections.Deque.dll - True - - - ..\packages\Nito.Disposables.1.0.0\lib\portable45-net45+win8+wp8+wpa81\Nito.Disposables.dll - True - - - - - - - - - - - - - - - - - - - - CameraInformationView.xaml - - - - CameraView.xaml - - - LocalCameraSelector.xaml - - - - - - - - Designer - MSBuild:Compile - - - Designer - MSBuild:Compile - - - Designer - MSBuild:Compile - - + - + + + + + + - - {8907117d-e11d-4f1d-8a26-7d0f1d8aceab} - DotNetDash.Core - False - + - - + + \ No newline at end of file diff --git a/DotNetDash.CameraViews/LocalCameraView.cs b/DotNetDash.CameraViews/LocalCameraView.cs deleted file mode 100644 index 039cd96..0000000 --- a/DotNetDash.CameraViews/LocalCameraView.cs +++ /dev/null @@ -1,38 +0,0 @@ -using System.Windows; -using AForge.Video.DirectShow; - -namespace DotNetDash.CameraViews -{ - class LocalCameraView : CameraView - { - public LocalCameraView() - { - CameraDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice); - CameraSelector.Content = new LocalCameraSelector(); - } - - public FilterInfoCollection CameraDevices { get; private set; } - - public FilterInfo SelectedFilter - { - set - { - CurrentDevice = value != null ? new VideoCaptureDevice(value.MonikerString) : null; - } - } - } - - sealed class LocalCameraViewProcessor : IViewProcessor - { - public FrameworkElement View { get; } = new LocalCameraView(); - } - - [CustomViewFactory(Name = "Laptop Camera")] - public class LocalCameraViewProcessorFactory : IViewProcessorFactory - { - public IViewProcessor Create() - { - return new LocalCameraViewProcessor(); - } - } -} diff --git a/DotNetDash.CameraViews/LocalCsCameraView.cs b/DotNetDash.CameraViews/LocalCsCameraView.cs new file mode 100644 index 0000000..9614865 --- /dev/null +++ b/DotNetDash.CameraViews/LocalCsCameraView.cs @@ -0,0 +1,54 @@ +using FRC.CameraServer; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; + +namespace DotNetDash.CameraViews +{ + public class LocalCsCameraView : CsCameraView + { + public LocalCsCameraView() + { + CameraSelector.Content = new LocalCameraSelector(); + } + + public UsbCameraInfo[] CameraDevices => UsbCamera.EnumerateUsbCameras(); + + public UsbCameraInfo? SelectedFilter + { + set + { + if (value == null) + { + CurrentDevice?.Stop(); + CurrentDevice = null; + return; + } + + UsbCamera camera = new UsbCamera("Usb", value.Value.Path); + BitmapSink sink = new BitmapSink("Streamer"); + sink.Source = camera; + + CurrentDevice = new CsVideoSource(sink, camera); + ; + } + } + } + + sealed class LocalCsCameraViewProcessor : IViewProcessor + { + public FrameworkElement View { get; } = new LocalCsCameraView(); + } + + [CustomViewFactory(Name = "USB Camera")] + public class LocalCCameraViewProcessorFactory : IViewProcessorFactory + { + public IViewProcessor Create() + { + return new LocalCsCameraViewProcessor(); + } + } +} diff --git a/DotNetDash.CameraViews/Properties/AssemblyInfo.cs b/DotNetDash.CameraViews/Properties/AssemblyInfo.cs index e9d1386..3acc200 100644 --- a/DotNetDash.CameraViews/Properties/AssemblyInfo.cs +++ b/DotNetDash.CameraViews/Properties/AssemblyInfo.cs @@ -1,18 +1,6 @@ using System.Reflection; using System.Runtime.InteropServices; -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("DotNetDash.CameraViews")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("DotNetDash.CameraViews")] -[assembly: AssemblyCopyright("Copyright © 2016")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - // Setting ComVisible to false makes the types in this assembly not visible // to COM components. If you need to access a type in this assembly from // COM, set the ComVisible attribute to true on that type. @@ -30,6 +18,4 @@ // // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] +// [assembly: AssemblyVersion("1.0.*")] \ No newline at end of file diff --git a/DotNetDash.CameraViews/WebCameraView.cs b/DotNetDash.CameraViews/WebCameraView.cs index 61932a8..2bcbe61 100644 --- a/DotNetDash.CameraViews/WebCameraView.cs +++ b/DotNetDash.CameraViews/WebCameraView.cs @@ -7,11 +7,12 @@ using System.Windows; using System.Windows.Controls; using System.Windows.Data; -using NetworkTables; +using FRC.CameraServer; +using FRC.NetworkTables; namespace DotNetDash.CameraViews { - class WebCameraView : CameraView + class WebCameraView : CsCameraView { public WebCameraView(INetworkTablesInterface ntInterface) { @@ -54,13 +55,13 @@ private static ObservableCollection GetCameraServerCameras(INetwor Action subTableCallback = (name, flags) => { - if (flags == NotifyFlags.NotifyNew || flags == NotifyFlags.NotifyImmediate) + if (flags == NotifyFlags.New || flags == NotifyFlags.Immediate) { - cameraTable.GetSubTable(name).AddTableListener("streams", (subTable, __, value, valueFlags) => + cameraTable.GetSubTable(name).AddEntryListener("streams", (NetworkTable subTable, ReadOnlySpan key, in NetworkTableEntry notification, in RefNetworkTableValue value, NotifyFlags valueFlags) => { + var streamsArray = value.GetStringArray().ToArray(); context.Post(state => { - var streamsArray = value.GetStringArray(); for (int i = 0; i < streamsArray.Length; i++) { if(streamsArray[i].StartsWith("mjpeg:", StringComparison.InvariantCultureIgnoreCase)) @@ -71,24 +72,24 @@ private static ObservableCollection GetCameraServerCameras(INetwor var streams = streamsArray.Select(stream => new CameraStream { CameraName = name, Stream = stream }); - valueFlags &= ~NotifyFlags.NotifyLocal; + valueFlags &= ~NotifyFlags.Local; switch (valueFlags) { - case NotifyFlags.NotifyImmediate: - case NotifyFlags.NotifyNew: + case NotifyFlags.Immediate: + case NotifyFlags.New: cache[name] = streams; foreach (var stream in streams) { collection.Add(stream); } break; - case NotifyFlags.NotifyDelete: + case NotifyFlags.Delete: foreach (var stream in cache[name]) { collection.Remove(stream); } break; - case NotifyFlags.NotifyUpdate: + case NotifyFlags.Update: foreach (var stream in cache[name]) { collection.Remove(stream); @@ -101,9 +102,9 @@ private static ObservableCollection GetCameraServerCameras(INetwor break; } }, null); - }, true); + }, NotifyFlags.Update | NotifyFlags.Immediate); } - else if (flags == NotifyFlags.NotifyDelete) + else if (flags == NotifyFlags.Delete) { cache.Remove(name); var toRemove = collection.Where(stream => stream.CameraName == name).ToList(); @@ -114,11 +115,11 @@ private static ObservableCollection GetCameraServerCameras(INetwor } }; - cameraTable.AddSubTableListener((table, name, _, flags) => subTableCallback(name, flags), true); + cameraTable.AddSubTableListener((table, name, flags) => subTableCallback(name.ToString(), flags), true); foreach(var subTable in cameraTable.GetSubTables()) { - subTableCallback(subTable, NotifyFlags.NotifyImmediate); + subTableCallback(subTable, NotifyFlags.Immediate); } return collection; @@ -131,7 +132,11 @@ public string WebcamUrl try { - CurrentDevice = new AForge.Video.MJPEGStream(value); + HttpCamera camera = new HttpCamera("Http", value); + BitmapSink sink = new BitmapSink("Streamer"); + sink.Source = camera; + + CurrentDevice = new CsVideoSource(sink, camera); } catch (ArgumentException) { diff --git a/DotNetDash.CameraViews/app.config b/DotNetDash.CameraViews/app.config new file mode 100644 index 0000000..199e715 --- /dev/null +++ b/DotNetDash.CameraViews/app.config @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/DotNetDash.CameraViews/packages.config b/DotNetDash.CameraViews/packages.config deleted file mode 100644 index f7fd9f0..0000000 --- a/DotNetDash.CameraViews/packages.config +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/DotNetDash.Core/BuiltinProcessors/DefaultProcessor.cs b/DotNetDash.Core/BuiltinProcessors/DefaultProcessor.cs index 1294cb2..c333f56 100644 --- a/DotNetDash.Core/BuiltinProcessors/DefaultProcessor.cs +++ b/DotNetDash.Core/BuiltinProcessors/DefaultProcessor.cs @@ -1,16 +1,15 @@ -using System; +using FRC.NetworkTables; +using System; using System.Collections.Generic; using System.Threading; using System.Windows; using System.Windows.Controls; -using NetworkTables; -using NetworkTables.Tables; namespace DotNetDash.BuiltinProcessors { class DefaultProcessor : TableProcessor { - public DefaultProcessor(string name, ITable table, IEnumerable> processorFactories) + public DefaultProcessor(string name, NetworkTable table, IEnumerable> processorFactories) : base(name, table, processorFactories) { baseTable.AddTableListenerOnSynchronizationContext(SynchronizationContext.Current, (sendingTable, key, value, flags) => @@ -19,7 +18,7 @@ public DefaultProcessor(string name, ITable table, IEnumerable "Default Table View"; - private UIElement CreateNewElementView(string key, Value value) + private UIElement CreateNewElementView(string key, NetworkTableValue value) { var keyValueLine = new StackPanel { Orientation = Orientation.Horizontal }; keyValueLine.Children.Add(new Label { Content = key, VerticalAlignment = VerticalAlignment.Center }); @@ -53,7 +52,7 @@ private UIElement CreateNewElementView(string key, Value value) return keyValueLine; } - private static string DetermineValueNetworkType(Value value) + private static string DetermineValueNetworkType(NetworkTableValue value) { switch (value.Type) { diff --git a/DotNetDash.Core/BuiltinProcessors/DefaultRootTableProcessor.cs b/DotNetDash.Core/BuiltinProcessors/DefaultRootTableProcessor.cs index fd096b6..2a7ddbd 100644 --- a/DotNetDash.Core/BuiltinProcessors/DefaultRootTableProcessor.cs +++ b/DotNetDash.Core/BuiltinProcessors/DefaultRootTableProcessor.cs @@ -1,15 +1,15 @@ -using System; +using FRC.NetworkTables; +using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.ComponentModel.Composition; using System.Windows; -using NetworkTables.Tables; namespace DotNetDash.BuiltinProcessors { public class DefaultRootTableProcessor : TableProcessor { - public DefaultRootTableProcessor(string name, ITable table, IEnumerable> processorFactories) + public DefaultRootTableProcessor(string name, NetworkTable table, IEnumerable> processorFactories) : base(name, table, processorFactories) { KeyToMultiProcessorMap.Add(name, @@ -35,7 +35,7 @@ public DefaultRootTableProcessorFactory([ImportMany] IEnumerable(); } - public TableProcessor Create(string subTable, ITable table) + public TableProcessor Create(string subTable, NetworkTable table) { var xamlViews = LoadXamlDocs(); - var matchingView = xamlViews.FirstOrDefault(view => view.DashboardType == table.GetString("~TYPE~", "")); + var matchingView = xamlViews.FirstOrDefault(view => view.DashboardType == table.GetEntry("~TYPE~").GetString("")); return matchingView != null ? CreateProcessorForFirstView(subTable, table, matchingView) : (TableProcessor)new DefaultProcessor(subTable, table, processorFactories); } - private XamlProcessor CreateProcessorForFirstView(string subTable, ITable table, XamlView view) + private XamlProcessor CreateProcessorForFirstView(string subTable, NetworkTable table, XamlView view) { return new XamlProcessor(subTable, table, processorFactories, view); } diff --git a/DotNetDash.Core/BuiltinProcessors/XamlProcessor.cs b/DotNetDash.Core/BuiltinProcessors/XamlProcessor.cs index 9d938aa..555cb81 100644 --- a/DotNetDash.Core/BuiltinProcessors/XamlProcessor.cs +++ b/DotNetDash.Core/BuiltinProcessors/XamlProcessor.cs @@ -1,7 +1,7 @@ -using System; +using FRC.NetworkTables; +using System; using System.Collections.Generic; using System.Windows; -using NetworkTables.Tables; namespace DotNetDash.BuiltinProcessors { @@ -9,7 +9,7 @@ class XamlProcessor : TableProcessor { private readonly XamlView view; - public XamlProcessor(string name, ITable table, IEnumerable> processorFactories, XamlView view) + public XamlProcessor(string name, NetworkTable table, IEnumerable> processorFactories, XamlView view) :base(name, table, processorFactories) { this.view = view; diff --git a/DotNetDash.Core/DotNetDash.Core.csproj b/DotNetDash.Core/DotNetDash.Core.csproj index ef29fa9..d6e9a9d 100644 --- a/DotNetDash.Core/DotNetDash.Core.csproj +++ b/DotNetDash.Core/DotNetDash.Core.csproj @@ -1,115 +1,17 @@ - - - + + - Debug - AnyCPU - {8907117D-E11D-4F1D-8A26-7D0F1D8ACEAB} - Library - Properties - DotNetDash - DotNetDash.Core - v4.6 - 512 - + netcoreapp3.1 + true + Debug;Release;Publish - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - ..\packages\FRC.NetworkTables.3.1.6\lib\net46\FRC.NetworkTables.dll - True - - - ..\packages\hellosam.net.collections.1.0.0\lib\net35-client\Hellosam.Net.Collections.dll - True - - - ..\packages\Nito.AsyncEx.Coordination.1.0.2\lib\net46\Nito.AsyncEx.Coordination.dll - True - - - ..\packages\Nito.AsyncEx.Tasks.1.0.1\lib\net46\Nito.AsyncEx.Tasks.dll - True - - - ..\packages\Nito.Collections.Deque.1.0.0\lib\portable45-net45+win8+wp8+wpa81\Nito.Collections.Deque.dll - True - - - ..\packages\Nito.Disposables.1.0.0\lib\portable45-net45+win8+wp8+wpa81\Nito.Disposables.dll - True - - - - - ..\packages\Serilog.2.3.0\lib\net46\Serilog.dll - True - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - + + + + + - - + \ No newline at end of file diff --git a/DotNetDash.Core/INetworkTablesInterface.cs b/DotNetDash.Core/INetworkTablesInterface.cs index 4a6030f..e5cb699 100644 --- a/DotNetDash.Core/INetworkTablesInterface.cs +++ b/DotNetDash.Core/INetworkTablesInterface.cs @@ -3,7 +3,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -using NetworkTables.Tables; +using FRC.NetworkTables; namespace DotNetDash { @@ -15,7 +15,7 @@ public interface INetworkTablesInterface event EventHandler OnClientConnectionAttempt; event EventHandler OnDisconnect; event EventHandler OnConnectionStatus; - ITable GetTable(string path); + NetworkTable GetTable(string path); } public class ConnectionChangedEventArgs : EventArgs @@ -28,7 +28,7 @@ public static class NetworkTableInterfaceExtensions { public static void ConnectToServer(this INetworkTablesInterface nt, string server) { - nt.ConnectToServer(server, NetworkTables.NetworkTable.DefaultPort); + nt.ConnectToServer(server, NetworkTableInstance.DefaultPort); } } } diff --git a/DotNetDash.Core/ITableProcessorFactory.cs b/DotNetDash.Core/ITableProcessorFactory.cs index 7ede952..64f4f03 100644 --- a/DotNetDash.Core/ITableProcessorFactory.cs +++ b/DotNetDash.Core/ITableProcessorFactory.cs @@ -1,9 +1,9 @@ -using NetworkTables.Tables; +using FRC.NetworkTables; namespace DotNetDash { public interface ITableProcessorFactory { - TableProcessor Create(string subTable, ITable table); + TableProcessor Create(string subTable, NetworkTable table); } } diff --git a/DotNetDash.Core/NetworkTableBackedLookup.cs b/DotNetDash.Core/NetworkTableBackedLookup.cs index a5d41f8..e165bea 100644 --- a/DotNetDash.Core/NetworkTableBackedLookup.cs +++ b/DotNetDash.Core/NetworkTableBackedLookup.cs @@ -1,20 +1,30 @@ -using System; +using FRC.NetworkTables; +using System; using System.ComponentModel; using System.Linq; using System.Runtime.CompilerServices; using System.Threading; -using NetworkTables; -using NetworkTables.Tables; namespace DotNetDash { public sealed class NetworkTableBackedLookup : INotifyPropertyChanged { - private readonly ITable table; + private readonly Type[] SupportedValueTypes = + { + typeof(string), + typeof(double), + typeof(byte[]), + typeof(bool), + typeof(string[]), + typeof(double[]), + typeof(bool[]), + }; + + private readonly NetworkTable table; - public NetworkTableBackedLookup(ITable table) + public NetworkTableBackedLookup(NetworkTable table) { - bool validType = Value.GetSupportedValueTypes().Contains(typeof(T)); + bool validType = SupportedValueTypes.Contains(typeof(T)); if (!validType) { @@ -31,11 +41,11 @@ public T this[string key] { get { - var value = table.GetValue(key, null); + var value = table.GetEntry(key).GetObjectValue(); if (value == null) return default(T); try { - return (T)value.GetObjectValue(); + return (T)value; } catch (InvalidCastException) { @@ -44,9 +54,8 @@ public T this[string key] } set { - var val = Value.MakeValue(value); - if (val == null) return; - table.PutValue(key, val); + // TODO see if this needs a catch + table.GetEntry(key).SetValue(value); NotifyPropertyChanged(System.Windows.Data.Binding.IndexerName); } } diff --git a/DotNetDash.Core/NetworkTableContext.cs b/DotNetDash.Core/NetworkTableContext.cs index 693b213..99e3919 100644 --- a/DotNetDash.Core/NetworkTableContext.cs +++ b/DotNetDash.Core/NetworkTableContext.cs @@ -1,25 +1,25 @@ -using System.Collections.Generic; +using FRC.NetworkTables; +using System.Collections.Generic; using System.ComponentModel; using System.Runtime.CompilerServices; -using NetworkTables.Tables; namespace DotNetDash { public class NetworkTableContext : INotifyPropertyChanged { - private ITable table; + private NetworkTable table; - public NetworkTableContext(string tableName, ITable table) + public NetworkTableContext(string tableName, NetworkTable table) { Name = tableName; this.table = table; Numbers = new NetworkTableBackedLookup(table); Booleans = new NetworkTableBackedLookup(table); Strings = new NetworkTableBackedLookup(table); - Raw = new NetworkTableBackedLookup>(table); - StringArrays = new NetworkTableBackedLookup>(table); - BooleanArrays = new NetworkTableBackedLookup>(table); - NumberArrays = new NetworkTableBackedLookup>(table); + Raw = new NetworkTableBackedLookup(table); + StringArrays = new NetworkTableBackedLookup(table); + BooleanArrays = new NetworkTableBackedLookup(table); + NumberArrays = new NetworkTableBackedLookup(table); } public string Name { get; } @@ -30,13 +30,13 @@ public NetworkTableContext(string tableName, ITable table) public NetworkTableBackedLookup Strings { get; } - public NetworkTableBackedLookup> Raw { get; } + public NetworkTableBackedLookup Raw { get; } - public NetworkTableBackedLookup> StringArrays { get; } + public NetworkTableBackedLookup StringArrays { get; } - public NetworkTableBackedLookup> BooleanArrays { get; } + public NetworkTableBackedLookup BooleanArrays { get; } - public NetworkTableBackedLookup> NumberArrays { get; } + public NetworkTableBackedLookup NumberArrays { get; } public event PropertyChangedEventHandler PropertyChanged; diff --git a/DotNetDash.Core/NetworkTablesExtensions.cs b/DotNetDash.Core/NetworkTablesExtensions.cs index 694241f..e1550bd 100644 --- a/DotNetDash.Core/NetworkTablesExtensions.cs +++ b/DotNetDash.Core/NetworkTablesExtensions.cs @@ -1,86 +1,92 @@ -using System; +using FRC.NetworkTables; +using System; using System.Diagnostics; using System.Threading; -using NetworkTables; -using NetworkTables.Tables; namespace DotNetDash { public static class NetworkTablesExtensions { - public static void AddSubTableListenerOnSynchronizationContext(this ITable table, SynchronizationContext context, Action callback) + public static void AddSubTableListenerOnSynchronizationContext(this NetworkTable table, SynchronizationContext context, Action callback) { if (callback == null) { throw new ArgumentNullException(nameof(callback)); } - table.AddSubTableListener((tbl, name, _, flags) => + table.AddSubTableListener((NetworkTable tbl, ReadOnlySpan key, NotifyFlags flags) => { + var name = key.ToString(); if (context != null) { - context.Post(state => callback(tbl, name, flags), null); + context.Post(state => callback(tbl, name), null); } else { - ThreadPool.QueueUserWorkItem(state => callback(tbl, name, flags), null); + ThreadPool.QueueUserWorkItem(state => callback(tbl, name), null); } - }); + }, false); } - public static void AddTableListenerOnSynchronizationContext(this ITable table, SynchronizationContext context, Action callback, bool immediateNotify = false) + public static void AddTableListenerOnSynchronizationContext(this NetworkTable table, SynchronizationContext context, Action callback, bool immediateNotify = false) { if (callback == null) { throw new ArgumentNullException(nameof(callback)); } - table.AddTableListener((tbl, name, value, flags) => + NotifyFlags flags = NotifyFlags.Update; + if (immediateNotify) flags |= NotifyFlags.Immediate; + table.AddEntryListener((NetworkTable tbl, ReadOnlySpan key, in NetworkTableEntry entry, in RefNetworkTableValue value, NotifyFlags flgs) => { + var name = key.ToString(); + var v = value.ToValue(); if (context != null) { - context.Post(state => callback(tbl, name, value, flags), null); + context.Post(state => callback(tbl, name, v, flgs), null); } else { - ThreadPool.QueueUserWorkItem(state => callback(tbl, name, value, flags), null); + ThreadPool.QueueUserWorkItem(state => callback(tbl, name, v, flgs), null); } - }, immediateNotify); + }, flags); } - public static void AddTableListenerOnSynchronizationContext(this ITable table, SynchronizationContext context, Action callback, NotifyFlags flags) + public static void AddTableListenerOnSynchronizationContext(this NetworkTable table, SynchronizationContext context, Action callback, NotifyFlags flags) { if (callback == null) { throw new ArgumentNullException(nameof(callback)); } - table.AddTableListenerEx((tbl, name, value, _flags) => + table.AddEntryListener((NetworkTable tbl, ReadOnlySpan key, in NetworkTableEntry entry, in RefNetworkTableValue value, NotifyFlags flgs) => { + var name = key.ToString(); + var v = value.ToValue(); if (context != null) { - context.Post(state => callback(tbl, name, value, _flags), null); + context.Post(state => callback(tbl, name, v, flgs), null); } else { - ThreadPool.QueueUserWorkItem(state => callback(tbl, name, value, _flags), null); + ThreadPool.QueueUserWorkItem(state => callback(tbl, name, v, flgs), null); } }, flags); } - public static void AddGlobalConnectionListenerOnSynchronizationContext(SynchronizationContext context, Action callback, bool notifyImmediate) + public static void AddGlobalConnectionListenerOnSynchronizationContext(SynchronizationContext context, Action callback, bool notifyImmediate) { if (callback == null) { throw new ArgumentNullException(nameof(callback)); } - - NetworkTable.AddGlobalConnectionListener((remote, info, connected) => + NetworkTableInstance.Default.AddConnectionListener((in ConnectionNotification notification) => { + var connected = notification.Connected; if (context != null) { - context.Post(state => callback(remote, info, connected), null); + context.Post(state => callback(connected), null); } else { - ThreadPool.QueueUserWorkItem(state => callback(remote, info, connected), null); + ThreadPool.QueueUserWorkItem(state => callback(connected), null); } }, notifyImmediate); } diff --git a/DotNetDash.Core/NetworkTablesRoot.cs b/DotNetDash.Core/NetworkTablesRoot.cs index ab00abc..efa4d5a 100644 --- a/DotNetDash.Core/NetworkTablesRoot.cs +++ b/DotNetDash.Core/NetworkTablesRoot.cs @@ -10,7 +10,7 @@ namespace DotNetDash { - [Export] + [Export(typeof(NetworkTablesRoot))] public class NetworkTablesRoot : INotifyPropertyChanged { private IEnumerable> rootTableFactories; diff --git a/DotNetDash.Core/Properties/AssemblyInfo.cs b/DotNetDash.Core/Properties/AssemblyInfo.cs index ccafd08..b916e01 100644 --- a/DotNetDash.Core/Properties/AssemblyInfo.cs +++ b/DotNetDash.Core/Properties/AssemblyInfo.cs @@ -3,18 +3,6 @@ using System.Runtime.InteropServices; using System.Windows.Markup; -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("DotNetDash.Core")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("DotNetDash.Core")] -[assembly: AssemblyCopyright("Copyright © 2017")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - // Setting ComVisible to false makes the types in this assembly not visible // to COM components. If you need to access a type in this assembly from // COM, set the ComVisible attribute to true on that type. @@ -33,8 +21,6 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] [assembly: InternalsVisibleTo("DotNetDash.Test")] [assembly: XmlnsDefinition("https://robotdotnet.github.io/dotnetdash", nameof(DotNetDash))] diff --git a/DotNetDash.Core/TableProcessor.cs b/DotNetDash.Core/TableProcessor.cs index 4a0cc8d..13d46ee 100644 --- a/DotNetDash.Core/TableProcessor.cs +++ b/DotNetDash.Core/TableProcessor.cs @@ -7,15 +7,15 @@ using System.Threading; using System.Windows; using System.Windows.Controls; +using FRC.NetworkTables; using Hellosam.Net.Collections; -using NetworkTables.Tables; using Serilog; namespace DotNetDash { public abstract class TableProcessor : IViewProcessor, INotifyPropertyChanged { - protected readonly ITable baseTable; + protected readonly NetworkTable baseTable; protected ObservableDictionary> keyToMultiProcessorMap = new ObservableDictionary>(); protected readonly ILogger logger; @@ -23,7 +23,7 @@ public abstract class TableProcessor : IViewProcessor, INotifyPropertyChanged private FrameworkElement view; - protected TableProcessor(string name, ITable table, IEnumerable> processorFactories) + protected TableProcessor(string name, NetworkTable table, IEnumerable> processorFactories) { logger = Log.ForContext(GetType()).ForContext("Table", name); logger.Information("Creating table processor for table"); @@ -86,7 +86,7 @@ protected FrameworkElement CreateSubTableHolder(string styleName) return new ContentControl { Content = content }; } - protected virtual NetworkTableContext GetTableContext(string name, ITable table) => new NetworkTableContext(name, table); + protected virtual NetworkTableContext GetTableContext(string name, NetworkTable table) => new NetworkTableContext(name, table); protected virtual string DefaultTableType => string.Empty; @@ -96,7 +96,7 @@ private void AddProcessorOptionsForTable(string subTableName) { logger.Information($"Creating processors for subtable {subTableName}"); var subTable = baseTable.GetSubTable(subTableName); - var tableType = subTable.GetString("~TYPE~", DefaultTableType); + var tableType = subTable.GetEntry("~TYPE~").GetString(DefaultTableType); logger.Information($"Subtable {subTableName} has a Dashboard type of '{tableType}'"); var selectedProcessors = new ObservableCollection(GetSortedTableProcessorsForType(subTable, subTableName, tableType)); logger.Information($"Found {selectedProcessors.Count} applicable subprocessors for table '{subTableName}'"); @@ -114,7 +114,7 @@ private FrameworkElement GetBoundView() return view; } - protected IEnumerable GetSortedTableProcessorsForType(ITable table, string tableName, string tableType) + protected IEnumerable GetSortedTableProcessorsForType(NetworkTable table, string tableName, string tableType) { var matchedProcessorFactories = processorFactories.Where(factory => factory.Metadata.IsMatch(tableType)).ToList(); matchedProcessorFactories.Sort((factory1, factory2) => @@ -139,7 +139,7 @@ private void InitCurrentSubTables() private void InitProcessorListener() { baseTable.AddSubTableListenerOnSynchronizationContext(SynchronizationContext.Current, - (table, newTableName, flags) => AddProcessorOptionsForTable(newTableName)); + (table, newTableName) => AddProcessorOptionsForTable(newTableName)); } private void NotifyPropertyChanged([CallerMemberName] string prop = "") diff --git a/DotNetDash.Core/XamlView.cs b/DotNetDash.Core/XamlView.cs index d59437e..c211b4f 100644 --- a/DotNetDash.Core/XamlView.cs +++ b/DotNetDash.Core/XamlView.cs @@ -20,6 +20,7 @@ public string DashboardType } set { + SetValue(DashboardTypeProperty, value); } } diff --git a/DotNetDash.Core/app.config b/DotNetDash.Core/app.config new file mode 100644 index 0000000..f15b114 --- /dev/null +++ b/DotNetDash.Core/app.config @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/DotNetDash.Core/packages.config b/DotNetDash.Core/packages.config deleted file mode 100644 index 73dd7db..0000000 --- a/DotNetDash.Core/packages.config +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - - - - \ No newline at end of file diff --git a/DotNetDash.LiveWindow/DotNetDash.LiveWindow.csproj b/DotNetDash.LiveWindow/DotNetDash.LiveWindow.csproj index 8c2ecc7..31b930b 100644 --- a/DotNetDash.LiveWindow/DotNetDash.LiveWindow.csproj +++ b/DotNetDash.LiveWindow/DotNetDash.LiveWindow.csproj @@ -1,100 +1,27 @@ - - - + + - Debug - AnyCPU - {BDA47DB8-EB8E-43AD-A8A1-AAD0AE9B2C8E} - Library - Properties - DotNetDash.LiveWindow - DotNetDash.LiveWindow - v4.6 - 512 + netcoreapp3.1 + true + Debug;Release;Publish - - true - full - false - ..\bin\Debug\Plugins\LiveWindow\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - ..\bin\Release\Plugins\LiveWindow\ - TRACE - prompt - 4 - - - - ..\packages\FRC.NetworkTables.3.1.6\lib\net46\FRC.NetworkTables.dll - True - - - ..\packages\hellosam.net.collections.1.0.0\lib\net35-client\Hellosam.Net.Collections.dll - False - - - ..\packages\Nito.AsyncEx.Coordination.1.0.2\lib\net46\Nito.AsyncEx.Coordination.dll - True - - - ..\packages\Nito.AsyncEx.Tasks.1.0.1\lib\net46\Nito.AsyncEx.Tasks.dll - True - - - ..\packages\Nito.Collections.Deque.1.0.0\lib\portable45-net45+win8+wp8+wpa81\Nito.Collections.Deque.dll - True - - - ..\packages\Nito.Disposables.1.0.0\lib\portable45-net45+win8+wp8+wpa81\Nito.Disposables.dll - True - - - - - ..\packages\Serilog.2.3.0\lib\net46\Serilog.dll - True - - - - - - - - - - - - - - - - - - - - + - + + + - - {8907117D-E11D-4F1D-8A26-7D0F1D8ACEAB} - DotNetDash.Core - False - + - - + \ No newline at end of file diff --git a/DotNetDash.LiveWindow/Properties/AssemblyInfo.cs b/DotNetDash.LiveWindow/Properties/AssemblyInfo.cs index 77bc45b..7ea0f27 100644 --- a/DotNetDash.LiveWindow/Properties/AssemblyInfo.cs +++ b/DotNetDash.LiveWindow/Properties/AssemblyInfo.cs @@ -1,18 +1,6 @@ using System.Reflection; using System.Runtime.InteropServices; -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("DotNetDash.LiveWindow")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("DotNetDash.LiveWindow")] -[assembly: AssemblyCopyright("Copyright © 2016")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - // Setting ComVisible to false makes the types in this assembly not visible // to COM components. If you need to access a type in this assembly from // COM, set the ComVisible attribute to true on that type. @@ -21,15 +9,3 @@ // The following GUID is for the ID of the typelib if this project is exposed to COM [assembly: Guid("bda47db8-eb8e-43ad-a8a1-aad0ae9b2c8e")] -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/DotNetDash.LiveWindow/RootTableContext.cs b/DotNetDash.LiveWindow/RootTableContext.cs index 2fd7d2a..984d34f 100644 --- a/DotNetDash.LiveWindow/RootTableContext.cs +++ b/DotNetDash.LiveWindow/RootTableContext.cs @@ -1,15 +1,16 @@ -using NetworkTables.Tables; +using FRC.NetworkTables; +using System; namespace DotNetDash.LiveWindow { public class RootTableContext : NetworkTableContext { - private ITable statusTable; - public RootTableContext(string tableName, ITable table) : base(tableName, table) + private NetworkTable statusTable; + public RootTableContext(string tableName, NetworkTable table) : base(tableName, table) { statusTable = table.GetSubTable("~STATUS~"); - statusTable.AddTableListener("LW Enabled", (changedTable, _, value, flags) => - Enabled = value.GetBoolean(), true); + statusTable.AddEntryListener("LW Enabled", (NetworkTable changedTable, ReadOnlySpan _, in NetworkTableEntry entry, in RefNetworkTableValue value, NotifyFlags flags) => + Enabled = value.GetBoolean(), NotifyFlags.Update | NotifyFlags.Immediate); } private bool enabled; diff --git a/DotNetDash.LiveWindow/RootTableProcessor.cs b/DotNetDash.LiveWindow/RootTableProcessor.cs index 126db79..e7abf59 100644 --- a/DotNetDash.LiveWindow/RootTableProcessor.cs +++ b/DotNetDash.LiveWindow/RootTableProcessor.cs @@ -8,16 +8,16 @@ using System.Windows.Data; using System.Windows.Media; using DotNetDash.BuiltinProcessors; -using NetworkTables.Tables; +using FRC.NetworkTables; namespace DotNetDash.LiveWindow { class RootTableProcessor : DefaultRootTableProcessor { - public RootTableProcessor(string name, ITable table, IEnumerable> processorFactories) + public RootTableProcessor(string name, NetworkTable table, IEnumerable> processorFactories) : base(name, table, processorFactories) { - baseTable.AddSubTableListenerOnSynchronizationContext(SynchronizationContext.Current, (tbl, subTableName, flags) => + baseTable.AddSubTableListenerOnSynchronizationContext(SynchronizationContext.Current, (tbl, subTableName) => { if (subTableName == "~STATUS~") { @@ -49,7 +49,7 @@ protected override FrameworkElement GetViewCore() return outline; } - protected override NetworkTableContext GetTableContext(string name, ITable table) => new RootTableContext(name, table); + protected override NetworkTableContext GetTableContext(string name, NetworkTable table) => new RootTableContext(name, table); } @@ -64,7 +64,7 @@ public RootTableProcessorFactory([ImportMany] IEnumerable> processorFactories) + public SubsystemProcessor(string name, NetworkTable table, IEnumerable> processorFactories) : base(name, table, processorFactories) { } @@ -38,7 +38,7 @@ public SubsystemProcessorFactory([ImportMany] IEnumerable + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/DotNetDash.LiveWindow/packages.config b/DotNetDash.LiveWindow/packages.config deleted file mode 100644 index 73dd7db..0000000 --- a/DotNetDash.LiveWindow/packages.config +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - - - - \ No newline at end of file diff --git a/DotNetDash.SpeedController/CANControllerProcessor.cs b/DotNetDash.SpeedController/CANControllerProcessor.cs index eb27ae9..0c37318 100644 --- a/DotNetDash.SpeedController/CANControllerProcessor.cs +++ b/DotNetDash.SpeedController/CANControllerProcessor.cs @@ -2,13 +2,13 @@ using System.Collections.Generic; using System.ComponentModel.Composition; using System.Windows; -using NetworkTables.Tables; +using FRC.NetworkTables; namespace DotNetDash.SpeedController { class CANControllerProcessor : TableProcessor { - public CANControllerProcessor(string name, ITable table, IEnumerable> processorFactories) + public CANControllerProcessor(string name, NetworkTable table, IEnumerable> processorFactories) : base(name, table, processorFactories) { } @@ -18,7 +18,7 @@ protected override FrameworkElement GetViewCore() return new CANView(); } - protected override NetworkTableContext GetTableContext(string name, ITable table) => new ControllerModel(name, table); + protected override NetworkTableContext GetTableContext(string name, NetworkTable table) => new ControllerModel(name, table); public override string Name => "CAN Speed Controller View"; } @@ -34,7 +34,7 @@ public ControllerProcessorFactory([ImportMany] IEnumerable ControlModes => controlModes; - public ControllerModel(string tableName, ITable table) : base(tableName, table) + public ControllerModel(string tableName, NetworkTable table) : base(tableName, table) { if(controlModes == null) { @@ -32,7 +32,7 @@ public ControllerModel(string tableName, ITable table) : base(tableName, table) default: break; } - }, NetworkTables.NotifyFlags.NotifyImmediate | NetworkTables.NotifyFlags.NotifyUpdate | NetworkTables.NotifyFlags.NotifyNew); + }, NotifyFlags.Immediate | NotifyFlags.Update | NotifyFlags.New); ZeroOutput = new Command(() => Numbers["Value"] = 0.0); ClearGraph = new Command(() => { diff --git a/DotNetDash.SpeedController/DotNetDash.SpeedController.csproj b/DotNetDash.SpeedController/DotNetDash.SpeedController.csproj index e237834..9825788 100644 --- a/DotNetDash.SpeedController/DotNetDash.SpeedController.csproj +++ b/DotNetDash.SpeedController/DotNetDash.SpeedController.csproj @@ -1,119 +1,28 @@ - - - + + - Debug - AnyCPU - {B49B9A6F-A3ED-4BA9-A5A3-8EA783237DFC} - Library - Properties - DotNetDash.CANSpeedController - DotNetDash.CANSpeedController - v4.6 - 512 + netcoreapp3.1 + true + Debug;Release;Publish + true - - true - full - false - ..\bin\Debug\Plugins\SpeedController\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - ..\bin\Release\Plugins\SpeedController\ - TRACE - prompt - 4 - - - - ..\packages\FRC.NetworkTables.3.1.6\lib\net46\FRC.NetworkTables.dll - True - - - ..\packages\Nito.AsyncEx.Coordination.1.0.2\lib\net46\Nito.AsyncEx.Coordination.dll - True - - - ..\packages\Nito.AsyncEx.Tasks.1.0.1\lib\net46\Nito.AsyncEx.Tasks.dll - True - - - ..\packages\Nito.Collections.Deque.1.0.0\lib\portable45-net45+win8+wp8+wpa81\Nito.Collections.Deque.dll - True - - - ..\packages\Nito.Disposables.1.0.0\lib\portable45-net45+win8+wp8+wpa81\Nito.Disposables.dll - True - - - ..\packages\OxyPlot.Core.1.0.0\lib\net45\OxyPlot.dll - True - - - ..\packages\OxyPlot.Wpf.1.0.0\lib\net45\OxyPlot.Wpf.dll - True - - - - - - - - - - - - - - - - - - - - CANView.xaml - - - - - - - - SpeedControllerView.xaml - - - - - - + - - Designer - MSBuild:Compile - - - Designer - MSBuild:Compile - + + + + - - {8907117d-e11d-4f1d-8a26-7d0f1d8aceab} - DotNetDash.Core - False - + - - + \ No newline at end of file diff --git a/DotNetDash.SpeedController/PWMControllerProcessor.cs b/DotNetDash.SpeedController/PWMControllerProcessor.cs index 88350c7..77a8b5a 100644 --- a/DotNetDash.SpeedController/PWMControllerProcessor.cs +++ b/DotNetDash.SpeedController/PWMControllerProcessor.cs @@ -1,14 +1,14 @@ -using System; +using FRC.NetworkTables; +using System; using System.Collections.Generic; using System.ComponentModel.Composition; using System.Windows; -using NetworkTables.Tables; namespace DotNetDash.SpeedController { class PWMControllerProcessor : TableProcessor { - public PWMControllerProcessor(string name, ITable table, IEnumerable> processorFactories) + public PWMControllerProcessor(string name, NetworkTable table, IEnumerable> processorFactories) : base(name, table, processorFactories) { } @@ -18,7 +18,7 @@ protected override FrameworkElement GetViewCore() return new SpeedControllerView(); } - protected override NetworkTableContext GetTableContext(string name, ITable table) => new ControllerModel(name, table); + protected override NetworkTableContext GetTableContext(string name, NetworkTable table) => new ControllerModel(name, table); public override string Name => "PWM Speed Controller View"; } @@ -34,7 +34,7 @@ public PWMControllerProcessorFactory([ImportMany] IEnumerable + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/DotNetDash.SpeedController/packages.config b/DotNetDash.SpeedController/packages.config deleted file mode 100644 index 4ac395c..0000000 --- a/DotNetDash.SpeedController/packages.config +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - - - - \ No newline at end of file diff --git a/DotNetDash.Test/DotNetDash.Test.csproj b/DotNetDash.Test/DotNetDash.Test.csproj index 6b3914b..3c03375 100644 --- a/DotNetDash.Test/DotNetDash.Test.csproj +++ b/DotNetDash.Test/DotNetDash.Test.csproj @@ -1,5 +1,6 @@  + Debug @@ -9,8 +10,11 @@ Properties DotNetDash.Test DotNetDash.Test - v4.6 + v4.7.2 512 + + + true @@ -30,35 +34,36 @@ 4 - - ..\packages\FRC.NetworkTables.3.1.6\lib\net46\FRC.NetworkTables.dll - True + + ..\packages\FRC.NetworkTables.Core.4.1.1\lib\netstandard2.0\FRC.NetworkTables.Core.dll - - ..\packages\Nito.AsyncEx.Coordination.1.0.2\lib\net46\Nito.AsyncEx.Coordination.dll - True + + ..\packages\FRC.NetworkTables.Core.DesktopLibraries.4.1.1\lib\netstandard2.0\FRC.NetworkTables.Core.DesktopLibraries.dll - - ..\packages\Nito.AsyncEx.Tasks.1.0.1\lib\net46\Nito.AsyncEx.Tasks.dll - True + + ..\packages\FRC.Utilities.3.0.4\lib\netstandard2.0\FRC.Utilities.dll - - ..\packages\Nito.Collections.Deque.1.0.0\lib\portable45-net45+win8+wp8+wpa81\Nito.Collections.Deque.dll - True - - - ..\packages\Nito.Disposables.1.0.0\lib\portable45-net45+win8+wp8+wpa81\Nito.Disposables.dll - True - - - ..\packages\NUnit.2.6.4\lib\nunit.framework.dll - True + + ..\packages\NUnit.3.12.0\lib\net45\nunit.framework.dll + + ..\packages\System.Buffers.4.5.0\lib\netstandard2.0\System.Buffers.dll + + + ..\packages\System.Memory.4.5.3\lib\netstandard2.0\System.Memory.dll + + + + ..\packages\System.Numerics.Vectors.4.5.0\lib\net46\System.Numerics.Vectors.dll + + + ..\packages\System.Runtime.CompilerServices.Unsafe.4.7.0\lib\netstandard2.0\System.Runtime.CompilerServices.Unsafe.dll + @@ -73,6 +78,7 @@ + @@ -85,6 +91,12 @@ + + + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + + \ No newline at end of file diff --git a/DotNetDash/Properties/AssemblyInfo.cs b/DotNetDash/Properties/AssemblyInfo.cs index e4824cd..37445f9 100644 --- a/DotNetDash/Properties/AssemblyInfo.cs +++ b/DotNetDash/Properties/AssemblyInfo.cs @@ -3,18 +3,6 @@ using System.Runtime.InteropServices; using System.Windows; -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("DotNetDash")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("DotNetDash")] -[assembly: AssemblyCopyright("Copyright © 2016")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - // Setting ComVisible to false makes the types in this assembly not visible // to COM components. If you need to access a type in this assembly from // COM, set the ComVisible attribute to true on that type. @@ -38,17 +26,3 @@ //(used if a resource is not found in the page, // app, or any theme specific resource dictionaries) )] - - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] \ No newline at end of file diff --git a/DotNetDash/Properties/Resources.Designer.cs b/DotNetDash/Properties/Resources.Designer.cs index 25466b6..a964b04 100644 --- a/DotNetDash/Properties/Resources.Designer.cs +++ b/DotNetDash/Properties/Resources.Designer.cs @@ -8,10 +8,10 @@ // //------------------------------------------------------------------------------ -namespace DotNetDash.Properties -{ - - +namespace DotNetDash.Properties { + using System; + + /// /// A strongly-typed resource class, for looking up localized strings, etc. /// @@ -19,51 +19,43 @@ namespace DotNetDash.Properties // class via a tool like ResGen or Visual Studio. // To add or remove a member, edit your .ResX file then rerun ResGen // with the /str option, or rebuild your VS project. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - internal class Resources - { - + internal class Resources { + private static global::System.Resources.ResourceManager resourceMan; - + private static global::System.Globalization.CultureInfo resourceCulture; - + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] - internal Resources() - { + internal Resources() { } - + /// /// Returns the cached ResourceManager instance used by this class. /// [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Resources.ResourceManager ResourceManager - { - get - { - if ((resourceMan == null)) - { + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("DotNetDash.Properties.Resources", typeof(Resources).Assembly); resourceMan = temp; } return resourceMan; } } - + /// /// Overrides the current thread's CurrentUICulture property for all /// resource lookups using this strongly typed resource class. /// [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Globalization.CultureInfo Culture - { - get - { + internal static global::System.Globalization.CultureInfo Culture { + get { return resourceCulture; } - set - { + set { resourceCulture = value; } } diff --git a/DotNetDash/Properties/Settings.Designer.cs b/DotNetDash/Properties/Settings.Designer.cs index 21fa367..7117fff 100644 --- a/DotNetDash/Properties/Settings.Designer.cs +++ b/DotNetDash/Properties/Settings.Designer.cs @@ -12,7 +12,7 @@ namespace DotNetDash.Properties { [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "14.0.0.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "16.3.0.0")] public sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); diff --git a/DotNetDash/RoboRioConnectionWindow.xaml.cs b/DotNetDash/RoboRioConnectionWindow.xaml.cs index 7f320bf..d94c716 100644 --- a/DotNetDash/RoboRioConnectionWindow.xaml.cs +++ b/DotNetDash/RoboRioConnectionWindow.xaml.cs @@ -1,6 +1,5 @@ using System.ComponentModel.Composition; using System.Windows; -using NetworkTables; namespace DotNetDash { diff --git a/DotNetDash/ServerConnectionWindow.xaml.cs b/DotNetDash/ServerConnectionWindow.xaml.cs index 7d3bc47..e936bd6 100644 --- a/DotNetDash/ServerConnectionWindow.xaml.cs +++ b/DotNetDash/ServerConnectionWindow.xaml.cs @@ -1,5 +1,4 @@ using System.Windows; -using NetworkTables; namespace DotNetDash { diff --git a/DotNetDash/SingletonNetworkTablesInterface.cs b/DotNetDash/SingletonNetworkTablesInterface.cs index a1e9ee5..ac83d20 100644 --- a/DotNetDash/SingletonNetworkTablesInterface.cs +++ b/DotNetDash/SingletonNetworkTablesInterface.cs @@ -6,8 +6,7 @@ using System.Threading; using System.Threading.Tasks; using DotNetDash; -using NetworkTables; -using NetworkTables.Tables; +using FRC.NetworkTables; namespace DotNetDash { @@ -21,34 +20,31 @@ public class SingletonNetworkTablesInterface : INetworkTablesInterface public SingletonNetworkTablesInterface() { NetworkTablesExtensions.AddGlobalConnectionListenerOnSynchronizationContext(SynchronizationContext.Current, - (remote, info, connected) => OnConnectionStatus?.Invoke(this, new ConnectionChangedEventArgs { Connected = connected }), true); + (connected) => OnConnectionStatus?.Invoke(this, new ConnectionChangedEventArgs { Connected = connected }), true); } public void ConnectToServer(string server, int port) { - NetworkTable.SetClientMode(); - NetworkTable.SetIPAddress(server); - NetworkTable.SetPort(port); - NetworkTable.Initialize(); + var inst = NetworkTableInstance.Default; + inst.StartClient(server, port); OnClientConnectionAttempt?.Invoke(this, EventArgs.Empty); } public void ConnectToTeam(int team) { - NetworkTable.SetClientMode(); - NetworkTable.SetTeam(team); - NetworkTable.Initialize(); + var inst = NetworkTableInstance.Default; + inst.StartClientTeam(team); OnClientConnectionAttempt?.Invoke(this, EventArgs.Empty); } - public ITable GetTable(string path) + public NetworkTable GetTable(string path) { - return NetworkTable.GetTable(path); + return NetworkTableInstance.Default.GetTable(path); } public void Disconnect() { - NetworkTable.Shutdown(); + NetworkTableInstance.Default.StopClient(); OnDisconnect?.Invoke(this, EventArgs.Empty); } } diff --git a/DotNetDash/packages.config b/DotNetDash/packages.config deleted file mode 100644 index 5934119..0000000 --- a/DotNetDash/packages.config +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - - - - - \ No newline at end of file