private void DaemonFunction() { byte[] buf = new byte[5]; // Stopwatch sw = Stopwatch.StartNew(); while (true) { dc.Receive(ref buf, 5); byte idx = buf [0]; float val = BitConverter.ToSingle(buf, 1); switch (idx) { case 26: lock (this) positionState.x = val; break; case 27: lock (this) positionState.y = val; break; case 28: lock (this) positionState.z = val; break; case 29: lock (this) positionState.wx = val; break; case 30: lock (this) positionState.wy = val; break; case 31: lock (this) positionState.wz = val; break; default: string name = jointDict [idx]; lock (this) jointState [name] = val; break; } // Console.WriteLine(String.Format("Network read took {0}ms.", sw.ElapsedMilliseconds)); // sw.Restart(); } }
public void Receive_Deserializes_Input_From_Buffer() { string expectedInput = "1234567"; var buffer = new ArrayBuffer(Encoding.UTF8.GetBytes(expectedInput), 0, expectedInput.Length); var reader = A.Fake<IBufferedReader>(); A.CallTo(() => reader.Read()).Returns(buffer); var channel = new InputChannel<string>(reader, new StringDeserializer()); string actualInput = channel.Receive(); Assert.That(actualInput, Is.EqualTo(expectedInput)); }
protected void camera() { bool active = true; while (active) { videoChannel.Flash(42); videoChannel.Receive(ref imageBuffer, imageBuffer.Length); lock (imageBuffer) { imagePixBuf = new Gdk.Pixbuf(imageBuffer, Gdk.Colorspace.Rgb, false, 8, cam_width, cam_height, 3 * cam_width); active = cameraActive; } Thread.Sleep((int)(1000.0 / fps)); } videoChannel.Flash(0); }