Пример #1
0
        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);
        }
Пример #2
0
 public VImageParseResultEntity(Position pos)
 {
     Pos = new VPosition(pos.X, pos.Y);
     Pos.EntityID = pos.EntityID;
     Pos.Radius = 3;
 }
Пример #3
0
        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);
            }
        }
Пример #4
0
        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]);
            }
        }