예제 #1
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);
            }
        }
예제 #2
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]);
            }
        }
예제 #3
0
 public void ImgValChanged(ImageParseResult rs)
 {
     if (ImgSetupDone)
     {
         ImgValChangedNoSetup(rs);
     }
     else
     {
         ImgValChangedSetup(rs);
     }
 }
예제 #4
0
 private void ImgValChangedSetup(ImageParseResult rs)
 {
     Log.Debug("Img-Val-changed-Setup");
     foreach (Position pos in rs.ListPosition)
     {
         if (!ImgSetupPositions.ContainsKey(pos.EntityID))
         {
             ImgSetupPositions.Add(pos.EntityID, pos);
         }
         else
         {
             ImgSetupPositions[pos.EntityID] = pos;
         }
     }
 }
예제 #5
0
        private void ImgValChangedNoSetup(ImageParseResult rs)
        {
            Log.Debug("Img-Val-changed");
            // Sort by id
            rs.ListPosition.Sort((x, y) => x.EntityID.CompareTo(y.EntityID));

            // Update parsed Values
            for (int i = 0; i < rs.ListPosition.Count; i++)
            {
                VImageParseResultEntity p = new VImageParseResultEntity(rs.ListPosition[i]);
                if (!ImgParseResults.ContainsKey(rs.ListPosition[i].EntityID))
                    ImgParseResults.Add(rs.ListPosition[i].EntityID, p);
                else
                    ImgParseResults[rs.ListPosition[i].EntityID] = p;
            }

            // move the objects in the virtual model
            foreach (KeyValuePair<int, VImageParseResultEntity> entry in ImgParseResults)
            {
                if (EntityIdVirtualObjectIdMapping.ContainsKey(entry.Value.Pos.EntityID))
                {
                    ModelObject modelObj = Model.GetModelObject(EntityIdVirtualObjectIdMapping[entry.Value.Pos.EntityID]);
                    Point toPosition = getToPosition(entry.Value.Pos);
                    GameLogic.MoveModelObject(modelObj, toPosition);
                }
            }

            // Notify clients
            WcfHandler.OnImgResultChanged(ImgParseResults);
        }
예제 #6
0
        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>();
            });
        }