コード例 #1
0
ファイル: TLVProcessor.cs プロジェクト: Lucasvo1/FHVGame
        private void NotifyObservers(Purpose p, bool isAsync)
        {
            // actually this try-block is bullshit, but for diagnostic purposes, we try it
            try
            {
                Log.DebugFormat("Tlv-decoded: {0}", p != null ? p.ToString() : null);

                if (p == null) return;

                if (dictObserver.ContainsKey(p.MethodID))
                {
                    if (dictObserver[p.MethodID].AsAsync && !isAsync)
                    {
                        Task.Factory.StartNew(() => dictObserver[p.MethodID].Observer.NewTlvInput(p.MethodID, p));
                    }
                    else
                    {
                        dictObserver[p.MethodID].Observer.NewTlvInput(p.MethodID, p);
                    }
                }
                else
                {
                    Log.WarnFormat("There is no Observer for methodID {0}", p.MethodID);
                }
            }
            catch (Exception e)
            {
                Log.Fatal(e);
            }
        }
コード例 #2
0
ファイル: BoardOptions.cs プロジェクト: Lucasvo1/FHVGame
        public BoardOptions()
        {
            SetDefault();

            AppName = "board";
            AppDescription = "tool to simulate data from control board";

            Add("n|number=", "'{NUMBER}' of button that was pressed (0=red, 1=yellow)", (int nr) => { ButtonNr = nr; });
            Add("p|player=", "'{PLAYER-NR}' that issues the button-press", (int nr) =>
            {
                val.Nr = nr;
            });

            Add("s|submit", "submit the current JoystickVal", (dummy) =>
            {
                try
                {
                    Purpose p = new Purpose();
                    SetButtonValue();
                    p.Value = val;
                    p.MethodID = 2;
                    Transmitter.Transmit(p);

                    SetDefault();

                }
                catch (FaultException<ServerFaultException> e)
                {
                    HandleServerFault(e);
                }
                catch (Exception e)
                {
                    HandleException(e);
                    throw e;
                }
            });

            Add("b|button=", "Whether the button is pressed (1) or released (0)", (int val) =>
            {
                ButtonVal = val;
            });
        }
コード例 #3
0
ファイル: JoyStickVM.cs プロジェクト: Lucasvo1/FHVGame
 private void OnVelocityChanged()
 {
     Purpose p = new Purpose();
     p.MethodID = 4;
     p.Value = new JoystickVal() { Value = CurrentVelocity.Value };
     Transmitter.Transmit(p);
 }
コード例 #4
0
ファイル: TLVDecoderTest.cs プロジェクト: Lucasvo1/FHVGame
        public void Decode_PurposePosition_Test()
        {
            byte[] tlvTest = {
                0x61 , // T (Purpose)
                20 , // L

                0x02 , // T (MethodID)
                0x01 , // L
                0x18 , // V

                0x63 , // T (Position)
                15 , // L

                0x02 , // T (int)
                0x01 , // L
                0x01, // V

                0x02 , // T (int)
                0x01 , // L
                0x02, // V

                0x02 , // T (int)
                0x01 , // L
                0x03, // V

                0x02 , // T (int)
                0x01 , // L
                0x04, // V

                0x02 , // T (int)
                0x01 , // L
                0x11 // V
            };

            Purpose p = new Purpose();
            Position pos = new Position();

            p.Value = pos;
            p.MethodID = 0x18;
            pos.EntityID = 1;
            pos.X = 2;
            pos.Y = 3;
            pos.X_Direction = 4;
            pos.Y_Direction = 17;

            ITLVable rs = TLVDec.Decode(tlvTest);

            Purpose rsPurpose = rs as Purpose;

            Assert.AreEqual(pos.EntityID, ((Position)rsPurpose.Value).EntityID);
            Assert.AreEqual(pos.X, ((Position)rsPurpose.Value).X);
            Assert.AreEqual(pos.Y, ((Position)rsPurpose.Value).Y);
            Assert.AreEqual(pos.X_Direction, ((Position)rsPurpose.Value).X_Direction);
            Assert.AreEqual(pos.Y_Direction, ((Position)rsPurpose.Value).Y_Direction);

            Assert.AreEqual(p.MethodID, rsPurpose.MethodID);
        }
コード例 #5
0
ファイル: TLVDecoderTest.cs プロジェクト: Lucasvo1/FHVGame
        public void DecodeList_Test()
        {
            // This test converts the same object than in test TLVEncoderTest::ListEncode_Test
            // just the other way round

            byte[] input = new byte[44];

            int j = 0;
            // Purpose
            input[j++] = 0x61; // T [7:6]=01, [5]=1, [4:0]=00001
            input[j++] = 42; // (L)

            // MethodID (not set)
            input[j++] = 0x02; // (L)
            input[j++] = 0x00; // (L)

            // ImageParseResult
            input[j++] = 0x66;  // T
            input[j++] = 38; // L

            // Array/List 38
            input[j++] = 0x30; // T [7:6]=00, [5]=1, [4:0]=10000
            input[j++] = 36; // L

            // # A # (Position) 18
            input[j++] = 0x63; // T [7:6]=01, [5]=1, [4:0]=00011
            input[j++] = 16;  // L

            // Entity ID
            input[j++] = 0x02;  // T (int)
            input[j++] = 0x01;  // L
            input[j++] = 0x01;  // V
            // X
            input[j++] = 0x02;  // T (int)
            input[j++] = 0x01;  // L
            input[j++] = 0x0A;  // V
            // Y
            input[j++] = 0x02;  // T (int)
            input[j++] = 0x01;  // L
            input[j++] = 0x0F;  // V
            // X_Direction
            input[j++] = 0x02;  // T (int)
            input[j++] = 0x02;  // L
            input[j++] = 0x01;  // V
            input[j++] = 0x00;  // V
            // Y_Direction
            input[j++] = 0x02;  // T (int)
            input[j++] = 0x01;  // L
            input[j++] = 0x11;  // V

            // # B # (Position) 18
            input[j++] = 0x63; // T [7:6]=01, [5]=1, [4:0]=00011
            input[j++] = 16;  // L

            // Entity ID
            input[j++] = 0x02;  // T (int)
            input[j++] = 0x01;  // L
            input[j++] = 0x02;  // V
            // X
            input[j++] = 0x02;  // T (int)
            input[j++] = 0x01;  // L
            input[j++] = 100;  // V
            // Y
            input[j++] = 0x02;  // T (int)
            input[j++] = 0x01;  // L
            input[j++] = 150;  // V
            // X_Direction
            input[j++] = 0x02;  // T (int)
            input[j++] = 0x02;  // L
            input[j++] = 0x0A;  // V
            input[j++] = 0x00;  // V
            // Y_Direction
            input[j++] = 0x02;  // T (int)
            input[j++] = 0x01;  // L
            input[j++] = 0xFF;  // V

            // Expected
            // Create input
            Purpose purpose = new Purpose();
            ImageParseResult img = new ImageParseResult();

            Position a = new Position();
            a.X = 10;
            a.Y = 15;
            a.X_Direction = 256;
            a.Y_Direction = 17;
            a.EntityID = 1;

            Position b = new Position();
            b.X = 100;
            b.Y = 150;
            b.X_Direction = 2560;
            b.X_Direction = 255;
            b.EntityID = 2;

            img.ListPosition.Add(a);
            img.ListPosition.Add(b);

            purpose.Value = img;

            // Result
            ITLVable rawRS = TLVDec.Decode(input);

            Purpose purposeRS = rawRS as Purpose;

            Assert.AreEqual(purpose.MethodID, purposeRS.MethodID);

            ImageParseResult imgRS = purposeRS.Value as ImageParseResult;

            Assert.AreEqual(imgRS.ListPosition.Count, img.ListPosition.Count);

            for (int i = 0; i < imgRS.ListPosition.Count; i++)
            {
                Assert.AreEqual(img.ListPosition[0].X_Direction, imgRS.ListPosition[0].X_Direction);
                Assert.AreEqual(img.ListPosition[0].Y_Direction, imgRS.ListPosition[0].Y_Direction);
                Assert.AreEqual(img.ListPosition[0].X, imgRS.ListPosition[0].X);
                Assert.AreEqual(img.ListPosition[0].Y, imgRS.ListPosition[0].Y);
                Assert.AreEqual(img.ListPosition[0].EntityID, imgRS.ListPosition[0].EntityID);
            }
        }
コード例 #6
0
ファイル: TLVDecoderTest.cs プロジェクト: Lucasvo1/FHVGame
        public void Decode_Composite_Test()
        {
            int i = -1;
            // Input
            byte[] input = new byte[14];

            input[++i] = 0x61;  // T
            input[++i] = 12;    // L
            input[++i] = 0x02;  // T (int)
            input[++i] = 1;     // L
            input[++i] = 0x13;    // V
            input[++i] = 0x62;  // T (constructed: PrimitivePurposeWrapper)
            input[++i] = 7;     // L
            input[++i] = 0x02;  // T (int)
            input[++i] = 1;    // L
            input[++i] = 17;   // V
            input[++i] = 0x02; // T (int)
            input[++i] = 2;    // L
            input[++i] = 0x1;  // V
            input[++i] = 0x0;  // V

            // Expected input
            Purpose purpose = new Purpose();
            PrimitivePurposeWrapper primPurp = new PrimitivePurposeWrapper();
            primPurp.A = 17;
            primPurp.B = 256;
            purpose.Value = primPurp;
            purpose.MethodID = 0x13;

            ITLVable result = TLVDec.Decode(input);
            Purpose convResult = result as Purpose;
            PrimitivePurposeWrapper embedded = convResult.Value as PrimitivePurposeWrapper;

            Assert.AreEqual(17, embedded.A);
            Assert.AreEqual(256, embedded.B);
            Assert.AreEqual(0x13, convResult.MethodID);
        }
コード例 #7
0
ファイル: TLVEncoder.Test.cs プロジェクト: Lucasvo1/FHVGame
        public void ListEncode_Test()
        {
            // Create input
            Purpose purpose = new Purpose();
            ImageParseResult imgRS = new ImageParseResult();

            // int (0000 0010)

            Position a = new Position();
            a.X = 10;
            a.Y = 15;
            a.X_Direction = 256;
            a.Y_Direction = 255;
            a.EntityID = 1;

            Position b = new Position();
            b.X = 100;
            b.Y = 150;
            b.X_Direction = 2560;
            b.Y_Direction = 2550;
            b.EntityID = 2;

            imgRS.ListPosition.Add(a);
            imgRS.ListPosition.Add(b);

            purpose.Value = imgRS;

            // Exptected result
            byte[] exp = new byte[45];

            int j = 0;
            // Purpose
            exp[j++] = 0x61; // T [7:6]=01, [5]=1, [4:0]=11111
            exp[j++] = 43; // (L)

            // MethodID (not set)
            exp[j++] = 0x02; // (L)
            exp[j++] = 0x00; // (L)

            // ImageParseResult 41
            exp[j++] = 0x66;  // T
            exp[j++] = 39; // L

            // Array/List 39
            exp[j++] = 0x30; // T [7:6]=00, [5]=1, [4:0]=10000
            exp[j++] = 37; // L

            // # A # (Position) 18
            exp[j++] = 0x63; // T [7:6]=01, [5]=1, [4:0]=00011
            exp[j++] = 16;  // L

            // Entity ID
            exp[j++] = 0x02;  // T (int)
            exp[j++] = 0x01;  // L
            exp[j++] = 0x01;  // V
            // X
            exp[j++] = 0x02;  // T (int)
            exp[j++] = 0x01;  // L
            exp[j++] = 0x0A;  // V
            // Y
            exp[j++] = 0x02;  // T (int)
            exp[j++] = 0x01;  // L
            exp[j++] = 0x0F;  // V
            // X_Direction
            exp[j++] = 0x02;  // T (int)
            exp[j++] = 0x02;  // L
            exp[j++] = 0x01;  // V
            exp[j++] = 0x00;  // V
            // Y_Direction
            exp[j++] = 0x02;  // T (int)
            exp[j++] = 0x01;  // L
            exp[j++] = 0xFF;  // V

            // # B # (Position) 19
            exp[j++] = 0x63; // T [7:6]=01, [5]=1, [4:0]=00011
            exp[j++] = 17;  // L

            // Entity ID
            exp[j++] = 0x02;  // T (int)
            exp[j++] = 0x01;  // L
            exp[j++] = 0x02;  // V
            // X
            exp[j++] = 0x02;  // T (int)
            exp[j++] = 0x01;  // L
            exp[j++] = 100;  // V
            // Y
            exp[j++] = 0x02;  // T (int)
            exp[j++] = 0x01;  // L
            exp[j++] = 150;  // V
            // X_Direction
            exp[j++] = 0x02;  // T (int)
            exp[j++] = 0x02;  // L
            exp[j++] = 0x0A;  // V
            exp[j++] = 0x00;  // V
            // Y_Direction
            exp[j++] = 0x02;  // T (int)
            exp[j++] = 0x02;  // L
            exp[j++] = 0x09;  // V
            exp[j++] = 0xF6;  // V

            byte[] arr = TlvConv.Encode(purpose);

            Assert.AreEqual(exp.Length, arr.Length);
            for (int i = 0; i < exp.Length; i++)
            {
                Assert.AreEqual(exp[i], arr[i]);
            }
        }
コード例 #8
0
ファイル: TLVEncoder.Test.cs プロジェクト: Lucasvo1/FHVGame
        public void MinimalCompositeTest()
        {
            int i = -1;

            // Create input
            Purpose purpose = new Purpose();
            PrimitivePurposeWrapper primPurp = new PrimitivePurposeWrapper();
            primPurp.A = 17;
            primPurp.B = 256;
            purpose.Value = primPurp;
            purpose.MethodID = 13;

            // Exptected result
            byte[] exp = new byte[14];

            exp[++i] = 0x61;  // T
            exp[++i] = 12;    // L
            exp[++i] = 0x02;  // T (int)
            exp[++i] = 1;     // L
            exp[++i] = 13;    // V
            exp[++i] = 0x62;  // T (constructed: PrimitivePurposeWrapper)
            exp[++i] = 7;     // L
            exp[++i] = 0x02;  // T (int)
            exp[++i] = 1;    // L
            exp[++i] = 17;   // V
            exp[++i] = 0x02; // T (int)
            exp[++i] = 2;    // L
            exp[++i] = 0x1;  // V
            exp[++i] = 0x0;  // V

            byte[] result = TlvConv.Encode(purpose);

            Assert.IsNotNull(result);
            Assert.AreEqual(14, result.Length);

            for (i = 0; i < 14; i++)
            {
                Assert.AreEqual(exp[i], result[i]);
            }
        }
コード例 #9
0
ファイル: ParserService.cs プロジェクト: Lucasvo1/FHVGame
        private void SetupReceived(Purpose p)
        {
            ImgParseSetup setup = p.Value as ImgParseSetup;

            if (setup == null)
            {
                Log.WarnFormat("Received input from parser, but cannot convert to ImgParseSetup, data is: {0}", p.ToString());
                return;
            }

            VMSvc.RegisterImageObjects(setup);
        }
コード例 #10
0
ファイル: ParserService.cs プロジェクト: Lucasvo1/FHVGame
        private void NewResultReceived(Purpose p)
        {
            // Do some further calculations
            ImageParseResult rs = p.Value as ImageParseResult;

            if (rs == null)
            {
                Log.WarnFormat("Received input from parser, but cannot convert to ImageParseResult, data is: {0}", p.ToString());
                return;
            }

            // pass to virtual model
            VMSvc.ImgValChanged(rs);
        }
コード例 #11
0
ファイル: ImgOptions.cs プロジェクト: Lucasvo1/FHVGame
        public ImgOptions()
        {
            ImgRs = new ImageParseResult();

            AppName = "img";
            AppDescription = "tool to simulate img parse results";

            Add("n=", "sets object '{NUMBER}'", (int nr) => { Nr = nr; });
            Add("x=", "sets '{X}'", (int x) => { X = x; });
            Add("y=", "sets '{Y}'", (int y) => { Y = y; });
            Add("xd=", "sets '{X_Dir}'", (int x) => { X_Dir = x; });
            Add("yd=", "sets '{Y_Dir}'", (int x) => { Y_Dir = x; });

            Add("a|add", "Adds a position to the current result", (dummy) => ImgRs.ListPosition.Add(new Position(Nr, X, Y, X_Dir, Y_Dir)));

            Add("s|submit", "Sends the current result to the server", (dummy) =>
            {
                Action<ImageParseResult> aa = new Action<ImageParseResult>((ImageParseResult rs) =>
                {
                    try
                    {
                        Purpose p = new Purpose();
                        p.MethodID = 1;
                        p.Value = rs;
                        TlvTrans.Transmit(p);
                    }
                    catch (FaultException<ServerFaultException> e)
                    {
                        HandleServerFault(e);
                    }
                    catch (Exception e)
                    {
                        HandleException(e);
                        throw e;
                    }
                });

                jobQueue.Add(new ActionContext<ImageParseResult>(aa, ImgRs));
                ImgRs = new ImageParseResult();
            });

            // Setup-Part
            Add("height=", "Set the '{HEIGHT}' for setup", (int height) => { Height = height; });
            Add("width=", "Set the '{WIDTH}' for setup", (int width) => { Width = width; });
            Add("sid|addsetupid=", "Add this '{NUMBER}' to setup-ids", (int nr) => { SetupIds.Add(nr); });
            Add("ss|submit setup", "Send the current setup to the server", (dummy) =>
            {
                Action<List<int>> aa = new Action<List<int>>((List<int> rs) =>
                {
                    try
                    {
                        Purpose p = new Purpose();
                        p.MethodID = 5;
                        p.Value = new ImgParseSetup() { ListOfObjectIds = rs };
                        TlvTrans.Transmit(p);
                    }
                    catch (FaultException<ServerFaultException> e)
                    {
                        HandleServerFault(e);
                    }
                    catch (Exception e)
                    {
                        HandleException(e);
                        throw e;
                    }
                });

                jobQueue.Add(new ActionContext<List<int>>(aa, SetupIds));
                SetupIds = new List<int>();
            });
        }