Exemplo n.º 1
0
 public override void Accept(ConnectionHandler ch, EriverProtocol packet)
 {
     ch.GetTracker().GetName(delegate(int error, int result)
     {
         packet.Name.Value = (error != 0) ? (byte)result : (byte)0;
         ch.Send(packet);
     });
 }
Exemplo n.º 2
0
        public void TransformFromEmptyProtocolTest()
        {
            EriverProtocol ep = new EriverProtocol();

            byte[] ans = EriverStreamReaderWriter.Transform(ep);

            Assert.AreEqual <int>(1, ans.Length);
            CollectionAssert.AreEqual(new byte[] { 0 }, ans);
        }
Exemplo n.º 3
0
        public void TransformFromNameProtocolTest()
        {
            Command        underTest = Command.Name;
            EriverProtocol ep        = CreateTestProtocol(underTest);

            byte[] ans = EriverStreamReaderWriter.Transform(ep);

            Assert.AreEqual <int>(CommandConvert.ToLength(underTest) + 1, ans.Length);
            CollectionAssert.AreEqual(new byte[] { (byte)underTest, 0x21 }, ans);
        }
Exemplo n.º 4
0
 static Trackers.TrackerCallback defaultAction(ConnectionHandler ch, EriverProtocol packet)
 {
     return(delegate(int error, int result)
     {
         if (error != 0 || result == 0)
         {
             packet.Kind = Command.Unavailable;
         }
         ch.Send(packet);
     });
 }
Exemplo n.º 5
0
        public void TransformFromStartCalProtocolTest()
        {
            Command        underTest = Command.StartCalibration;
            EriverProtocol ep        = CreateTestProtocol(underTest);

            byte[] ans = EriverStreamReaderWriter.Transform(ep);

            Assert.AreEqual <int>(CommandConvert.ToLength(underTest) + 1, ans.Length);
            CollectionAssert.AreEqual(new byte[] { (byte)underTest,
                                                   0x40, 0x2A, 0xBD, 0x70, 0xA3, 0xD7, 0x0A, 0x3D }, ans);
        }
Exemplo n.º 6
0
        public void TransformFromAddPointProtocolTest()
        {
            Command        underTest = Command.AddPoint;
            EriverProtocol ep        = CreateTestProtocol(Command.AddPoint);

            byte[] ans = EriverStreamReaderWriter.Transform(ep);

            Assert.AreEqual <int>(CommandConvert.ToLength(underTest) + 1, ans.Length);
            CollectionAssert.AreEqual(new byte[] { (byte)underTest,
                                                   0x3F, 0xDB, 0x95, 0x81, 0x06, 0x24, 0xDD, 0x2F,
                                                   0x3F, 0xD4, 0x18, 0x93, 0x74, 0xBC, 0x6A, 0x7F }, ans);
        }
Exemplo n.º 7
0
        public void ReadWriteTest()
        {
            foreach (Command cmd in Enum.GetValues(typeof(Command)))
            {
                SetUp();
                EriverProtocol ep = CreateTestProtocol(cmd);
                esrw.Write(ep);
                EriverProtocol new_ep = esrw.Read();

                Assert.AreEqual(ep, new_ep);
                Assert.AreEqual <EriverProtocol>(ep, new_ep);
            }
        }
Exemplo n.º 8
0
            public override void Accept(ConnectionHandler ch, EriverProtocol packet)
            {
                XConfSettings xconf = new XConfSettings(
                    Properties.Settings.Default.ScreenHeight,
                    Properties.Settings.Default.ScreenWidth,
                    Properties.Settings.Default.TrackerDeltaX,
                    Properties.Settings.Default.TrackerDeltaY,
                    Properties.Settings.Default.TrackerDeltaZ,
                    Properties.Settings.Default.TrackerDeltaAngle);

                //ch.GetTracker().SetXConfig(xconf, packet.StartCalibration.Angle);
                ch.GetTracker().StartCalibration(defaultAction(ch, packet));
            }
Exemplo n.º 9
0
 private void handle()
 {
     while (true)
     {
         if (esrw != null)
         {
             EriverProtocol ep = esrw.Read();
             if (ep.Kind == Command.GetPoint)
             {
                 MovePointer(ep.GetPoint.X, ep.GetPoint.Y);
             }
         }
     }
 }
Exemplo n.º 10
0
 public void Send(EriverProtocol proto)
 {
     logger.Debug("Writing packet: " + proto);
     byte[] buf = EriverStreamReaderWriter.Transform(proto);
     try
     {
         stream.Write(buf, 0, buf.Length);
     }
     catch (IOException e)
     {
         logger.Error("IOException while writing to stream. Closing handler.");
         logger.Debug(e);
         stop.Set();
     }
 }
Exemplo n.º 11
0
        private void Run()
        {
            EriverProtocol prot = new EriverProtocol();

            // Sending name first according to spec.
            prot.Kind       = Command.Name;
            prot.Name       = new Name();
            prot.Name.Value = name;
            Send(prot);

            while (!stop.WaitOne(0))
            {
                try
                {
                    prot = readerWriter.Read();
                    using (log4net.ThreadContext.Stacks["NDC"].Push("ConnHandler_Handlers"))
                    {
                        logger.Debug("Read packet: " + prot);
                        try
                        {
                            var m = ConnHandler_Handlers.Messages[CommandConvert.ToByte(prot.Kind)]();
                            m.Accept(this, prot);
                        }
                        catch (KeyNotFoundException)
                        {
                            logger.Error("Package type not supported. Different versions?");
                            stop.Set();
                            break;
                        }
                    }
                }
                catch (InvalidOperationException e)
                {
                    using (log4net.ThreadContext.Stacks["NDC"].Push("InvalidOperationException"))
                    {
                        stop.Set();
                        logger.Error("Error in stream.");
                        logger.Debug(e);
                    }
                }
            }
            stream.Close();
        }
Exemplo n.º 12
0
        public void Start()
        {
            tracker.RegisterOnETEvent(delegate(GetPoint point)
            {
                if (stop.WaitOne(0))
                {
                    OnStatusChanged(this, new EventArgs());
                    tracker.Disable(null);
                    Thread.CurrentThread.Abort(); // Shutting down this thread.
                    return;
                }
                if (Listen)
                {
                    EriverProtocol proto = new EriverProtocol();
                    proto.Kind           = Command.GetPoint;
                    proto.GetPoint       = point;
                    Send(proto);
                }
            });

            tracker.Enable(null);
            using (log4net.ThreadContext.Stacks["NDC"].Push("Run"))
            {
                Run();
            }

            //Finalize calibration if disconnecting during calibration.
            tracker.GetState(delegate(int state, int error)
            {
                if ((state & 2) != 0)
                {
                    tracker.ClearCalibration(delegate(int res, int err)
                    {
                        tracker.EndCalibration(null);
                    });
                }
            });
        }
Exemplo n.º 13
0
        public void Start()
        {
            tracker.RegisterOnETEvent(delegate(GetPoint point)
            {
                if (stop.WaitOne(0))
                {
                    OnStatusChanged(this, new EventArgs());
                    tracker.Disable(null);
                    Thread.CurrentThread.Abort(); // Shutting down this thread.
                    return;
                }
                EriverProtocol proto = new EriverProtocol();
                proto.Kind           = Command.GetPoint;
                proto.GetPoint       = point;
                Send(proto);
            });

            tracker.Enable(null);
            using (log4net.ThreadContext.Stacks["NDC"].Push("Run"))
            {
                Run();
            }
        }
Exemplo n.º 14
0
 public override void Accept(ConnectionHandler ch, EriverProtocol packet)
 {
     ch.GetTracker().ClearCalibration(defaultAction(ch, packet));
 }
Exemplo n.º 15
0
 public override void Accept(ConnectionHandler ch, EriverProtocol packet)
 {
     ch.Listen = !ch.Listen;
 }
Exemplo n.º 16
0
 public abstract void Accept(ConnectionHandler ch, EriverProtocol packet);
Exemplo n.º 17
0
 public override void Accept(ConnectionHandler ch, EriverProtocol packet)
 {
     ch.GetTracker().StartCalibration(packet.StartCalibration.Angle, defaultAction(ch, packet));
 }
Exemplo n.º 18
0
 public override void Accept(ConnectionHandler ch, EriverProtocol packet)
 {
     ch.Send(packet);
 }
Exemplo n.º 19
0
 public override void Accept(ConnectionHandler ch, EriverProtocol packet)
 {
     ch.GetTracker().AddPoint(packet.AddPoint.X, packet.AddPoint.Y, defaultAction(ch, packet));
 }