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); }); }
public void TransformFromEmptyProtocolTest() { EriverProtocol ep = new EriverProtocol(); byte[] ans = EriverStreamReaderWriter.Transform(ep); Assert.AreEqual <int>(1, ans.Length); CollectionAssert.AreEqual(new byte[] { 0 }, ans); }
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); }
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); }); }
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); }
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); }
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); } }
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)); }
private void handle() { while (true) { if (esrw != null) { EriverProtocol ep = esrw.Read(); if (ep.Kind == Command.GetPoint) { MovePointer(ep.GetPoint.X, ep.GetPoint.Y); } } } }
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(); } }
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(); }
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); }); } }); }
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(); } }
public override void Accept(ConnectionHandler ch, EriverProtocol packet) { ch.GetTracker().ClearCalibration(defaultAction(ch, packet)); }
public override void Accept(ConnectionHandler ch, EriverProtocol packet) { ch.Listen = !ch.Listen; }
public abstract void Accept(ConnectionHandler ch, EriverProtocol packet);
public override void Accept(ConnectionHandler ch, EriverProtocol packet) { ch.GetTracker().StartCalibration(packet.StartCalibration.Angle, defaultAction(ch, packet)); }
public override void Accept(ConnectionHandler ch, EriverProtocol packet) { ch.Send(packet); }
public override void Accept(ConnectionHandler ch, EriverProtocol packet) { ch.GetTracker().AddPoint(packet.AddPoint.X, packet.AddPoint.Y, defaultAction(ch, packet)); }