Esempio n. 1
0
        public void TestDataExtractor()
        {
            var path = @"C:\Repos\mwwhited\BinaryDataDecoders\src\BinaryDataDecoders.ElectronicScoringMachines.Fencing\Favero\RawData.txt";

            var chunks = File.ReadAllText(path)
                         .Where(c => (c >= '0' && c <= '9') || (c >= 'A' && c <= 'F') || (c >= 'a' && c <= 'f'))
                         .AsMemory()
                         .BytesFromHexString()
                         .Split(0xff, Carry)
            ;

            //var segments = (from c in chunks
            //                select c.ToArray().ToHexString(",0x"))
            //               .Distinct()
            //               .OrderBy(i => i)
            //               .Aggregate(new StringBuilder(), (sb, v) => sb.Append("0x").Append(v).AppendLine())
            //               .ToString();
            // this.TestContext.WriteLine(segments);

            var parser = new FaveroStateParser();

            foreach (var c in chunks.Distinct())
            {
                try
                {
                    var state = parser.Parse(c.Span);
                    this.TestContext.WriteLine(state.ToString());
                }
                catch
                {
                    this.TestContext.WriteLine($"ERROR Decoding {c.ToArray().ToHexString()}");
                }
            }
        }
Esempio n. 2
0
        public void DecodeTest()
        {
            /*
             *   FFh, 06h, 12h, 56h, 02h, 14h, 0Ah, 00h, 38h, 56h
             *              which will display:
             *              Right score = 6
             *              Left score = 12
             *              Time = 2:56
             *              The Lamps ON are: Red, Yellow right, Left priorite.
             *              Number of Matches = 2
             *              Left yellow penalty lamp = ON.
             */
            var frame = new byte[]
            {
                0xff, 0x06, 0x12, 0x56, 0x02, 0x14, 0x0a, 0x00, 0x38, 0x56,
            };

            var parser = new FaveroStateParser();
            var state  = parser.Parse(frame);

            this.TestContext.WriteLine(state.ToString());
            // R:S>012 L>Yellow C>None P>False G:S>006 L>Touch C>None P>True T:00:02:56 M:0

            Assert.AreEqual(12, state.Left.Score, "Check Left Score");
            Assert.AreEqual(Lights.Touch, state.Left.Lights, "Check Left Lights");
            Assert.AreEqual(Cards.Yellow, state.Left.Cards, "Check Left Cards");
            Assert.AreEqual(true, state.Left.Priority, "Check Left Priority");

            Assert.AreEqual(6, state.Right.Score, "Check Right Score");
            Assert.AreEqual(Lights.Yellow, state.Right.Lights, "Check Right Lights");
            Assert.AreEqual(Cards.None, state.Right.Cards, "Check Right Cards");
            Assert.AreEqual(false, state.Right.Priority, "Check Right Priority");

            Assert.AreEqual(new TimeSpan(0, 2, 56), state.Clock, "Check Clock");
            Assert.AreEqual(2, state.Match, "Check Match");
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            Application.Init();
            var top = Application.Top;

            // Creates the top-level window to show
            var win = new Window("Fencing Score Board")
            {
                X = 0,
                Y = 1, // Leave one row for the toplevel menu

                // By using Dim.Fill(), it will automatically resize without manual intervention
                Width  = Dim.Fill(),
                Height = Dim.Fill()
            };

            top.Add(win);

            // Creates a menubar, the item "New" has a help menu.
            var menu = new MenuBar(new MenuBarItem[] {
                new MenuBarItem("_File", new MenuItem [] {
                    //new MenuItem ("_New", "Creates new file", NewFile),
                    //new MenuItem ("_Close", "", () => Close ()),
                    new MenuItem("_Quit", "", () => { if (Quit())
                                                      {
                                                          top.Running = false;
                                                      }
                                 })
                }),
                //new MenuBarItem ("_Edit", new MenuItem [] {
                //    new MenuItem ("_Copy", "", null),
                //    new MenuItem ("C_ut", "", null),
                //    new MenuItem ("_Paste", "", null)
                //})
            });

            top.Add(menu);

            var ms        = new MemoryStream();
            var hexViewer = new HexView(ms);

            IParseScoreMachineState parser = new FaveroStateParser();
            var provider = new SerialPortProvider(data =>
            {
                Debug.WriteLine(data);
                ms.Write(data.ToArray(), 0, data.Length);

                return(Task.FromResult(0));
            });

            var deviceTypes     = new ListView(new[] { "SG", "Favero" }.ToList());
            var deviceTypeFrame = new FrameView("Devices")
            {
                Height = Dim.Percent(50),
                Width  = Dim.Percent(25),
            };

            deviceTypeFrame.Add(deviceTypes);

            var ports     = new ListView(provider.ListPorts().ToList());
            var portFrame = new FrameView("Serial Ports")
            {
                Y      = Pos.Percent(50),
                Height = Dim.Percent(100),
                Width  = Dim.Percent(25),
            };

            portFrame.Add(ports);

            //var connect = new Button("Open")
            //{
            //    Y = Pos.Bottom(portFrame),
            //};
            //connect.Clicked = () =>
            //{
            //    var portName = ports.Source is List<string> names ? names[ports.SelectedItem] : null;
            //    Debug.WriteLine(portName);
            //    if (!string.IsNullOrWhiteSpace(portName))
            //        provider.Open(portName);
            //};
            //portFrame.Add(connect);

            var scoreFrame = new FrameView("Scores")
            {
                X      = Pos.Percent(25),
                Height = Dim.Percent(85),
                Width  = Dim.Percent(100),
            };

            var dataFrame = new FrameView("Data")
            {
                X      = Pos.Percent(25),
                Y      = Pos.Percent(85),
                Height = Dim.Percent(100),
                Width  = Dim.Percent(100),
            };


            win.Add(deviceTypeFrame);
            win.Add(portFrame);
            win.Add(scoreFrame);
            win.Add(dataFrame);


            //var ports =  provider.ListPorts();
            // foreach(var port in ports)
            // {
            //     Console.WriteLine(port);
            // }

            Application.Run();
        }