public void TestServerToClient() { WearableProxyClientProtocol clientProtocol = new WearableProxyClientProtocol(); int clientIndex = 0; byte[] clientBuffer = new byte[1024]; // Register callbacks for packet processing clientProtocol.KeepAlive += () => { _lastPacketName = "KeepAlive"; }; clientProtocol.NewSensorFrame += frame => { _lastPacketName = "SensorFrame"; Assert.AreEqual(123.45f, frame.timestamp); Assert.AreEqual(0.1f, frame.deltaTime); Assert.AreEqual(Vector3.right, frame.acceleration.value); Assert.AreEqual(SensorAccuracy.Low, frame.acceleration.accuracy); Assert.AreEqual(Vector3.up, frame.angularVelocity.value); Assert.AreEqual(SensorAccuracy.High, frame.angularVelocity.accuracy); Assert.AreEqual(new Quaternion(1.0f, 2.0f, 3.0f, 4.0f), frame.rotationSixDof.value); Assert.AreEqual(15.0, frame.rotationSixDof.measurementUncertainty); Assert.AreEqual(GestureId.DoubleTap, frame.gestureId); }; clientProtocol.DeviceList += devices => { _lastPacketName = "DeviceList"; Assert.IsTrue(devices.Length == 3); Assert.IsTrue(devices[0].name == "Product Name"); Assert.IsTrue(devices[0].productId == ProductId.Undefined); Assert.IsTrue(devices[0].firmwareVersion == "0.13.2f"); Assert.IsTrue(devices[1].name == "Corey's Device"); Assert.IsTrue(devices[1].productId == ProductId.Frames); Assert.IsTrue(devices[1].variantId == (byte)FramesVariantId.Alto); Assert.IsTrue(devices[2].name == "Michael's Headphones"); Assert.IsTrue(devices[2].productId == ProductId.Frames); Assert.IsTrue(devices[2].variantId == (byte)FramesVariantId.Rondo); }; clientProtocol.ConnectionStatus += (state, device) => { _lastPacketName = "ConnectionStatus"; Assert.IsTrue(state == WearableProxyProtocolBase.ConnectionState.Connected); Assert.IsTrue(device != null); Assert.IsTrue(device.Value.name == "Product Name"); Assert.AreEqual(ProductId.Frames, device.Value.productId); Assert.AreEqual((byte)FramesVariantId.Alto, device.Value.variantId); Assert.IsTrue(device.Value.uid == "00000000-0000-0000-0000-000000000000"); }; clientProtocol.ConfigStatus += deviceConfig => { _lastPacketName = "ConfigStatus"; Assert.AreEqual(SensorUpdateInterval.ThreeHundredTwentyMs, deviceConfig.updateInterval); Assert.AreEqual(false, deviceConfig.rotationSixDof.isEnabled); Assert.AreEqual(true, deviceConfig.gyroscope.isEnabled); Assert.AreEqual(false, deviceConfig.accelerometer.isEnabled); Assert.AreEqual(false, deviceConfig.headNodGesture.isEnabled); Assert.AreEqual(true, deviceConfig.doubleTapGesture.isEnabled); }; WearableProxyProtocolBase.EncodeKeepAlive(clientBuffer, ref clientIndex); WearableProxyServerProtocol.EncodeSensorFrame( clientBuffer, ref clientIndex, new SensorFrame { timestamp = 123.45f, deltaTime = 0.1f, acceleration = new SensorVector3 { value = Vector3.right, accuracy = SensorAccuracy.Low }, angularVelocity = new SensorVector3 { value = Vector3.up, accuracy = SensorAccuracy.High }, rotationSixDof = new SensorQuaternion { value = new Quaternion(1.0f, 2.0f, 3.0f, 4.0f), measurementUncertainty = 15.0f }, gestureId = GestureId.DoubleTap }); WearableProxyServerProtocol.EncodeDeviceList( clientBuffer, ref clientIndex, new[] { new Device { isConnected = false, name = "Product Name", firmwareVersion = "0.13.2f", productId = ProductId.Undefined, variantId = (byte)FramesVariantId.Undefined, rssi = -30, uid = "00000000-0000-0000-0000-000000000000" }, new Device { isConnected = false, name = "Corey's Device", productId = ProductId.Frames, variantId = (byte)FramesVariantId.Alto, rssi = -40, uid = "00000000-0000-0000-0000-000000000000" }, new Device { isConnected = false, name = "Michael's Headphones", productId = ProductId.Frames, variantId = (byte)FramesVariantId.Rondo, rssi = -55, uid = "00000000-0000-0000-0000-000000000000" } }); WearableProxyServerProtocol.EncodeConnectionStatus( clientBuffer, ref clientIndex, WearableProxyProtocolBase.ConnectionState.Connected, new Device { isConnected = true, name = "Product Name", productId = ProductId.Frames, variantId = (byte)FramesVariantId.Alto, rssi = -30, uid = "00000000-0000-0000-0000-000000000000" }); WearableDeviceConfig config = new WearableDeviceConfig { updateInterval = SensorUpdateInterval.ThreeHundredTwentyMs, gyroscope = { isEnabled = true }, doubleTapGesture = { isEnabled = true } }; WearableProxyServerProtocol.EncodeConfigStatus(clientBuffer, ref clientIndex, config); WearableProxyProtocolBase.EncodeKeepAlive(clientBuffer, ref clientIndex); // Decode clientIndex = 0; clientProtocol.ProcessPacket(clientBuffer, ref clientIndex); Assert.AreEqual(_lastPacketName, "KeepAlive"); clientProtocol.ProcessPacket(clientBuffer, ref clientIndex); Assert.AreEqual(_lastPacketName, "SensorFrame"); clientProtocol.ProcessPacket(clientBuffer, ref clientIndex); Assert.AreEqual(_lastPacketName, "DeviceList"); clientProtocol.ProcessPacket(clientBuffer, ref clientIndex); Assert.AreEqual(_lastPacketName, "ConnectionStatus"); clientProtocol.ProcessPacket(clientBuffer, ref clientIndex); Assert.AreEqual(_lastPacketName, "ConfigStatus"); clientProtocol.ProcessPacket(clientBuffer, ref clientIndex); Assert.AreEqual(_lastPacketName, "KeepAlive"); }
public void TestServerToClient() { WearableProxyClientProtocol clientProtocol = new WearableProxyClientProtocol(); int clientIndex = 0; byte[] clientBuffer = new byte[1024]; // Register callbacks for packet processing clientProtocol.KeepAlive += () => { _lastPacketName = "KeepAlive"; }; clientProtocol.NewSensorFrame += frame => { _lastPacketName = "SensorFrame"; Assert.AreEqual(123.45f, frame.timestamp); Assert.AreEqual(0.1f, frame.deltaTime); Assert.AreEqual(Vector3.right, frame.acceleration.value); Assert.AreEqual(SensorAccuracy.Low, frame.acceleration.accuracy); Assert.AreEqual(Vector3.up, frame.angularVelocity.value); Assert.AreEqual(SensorAccuracy.High, frame.angularVelocity.accuracy); Assert.AreEqual(new Quaternion(1.0f, 2.0f, 3.0f, 4.0f), frame.rotation.value); Assert.AreEqual(15.0, frame.rotation.measurementUncertainty); Assert.AreEqual(GestureId.DoubleTap, frame.gestureId); }; clientProtocol.DeviceList += devices => { _lastPacketName = "DeviceList"; Assert.IsTrue(devices.Length == 3); Assert.IsTrue(devices[0].name == "Product Name"); Assert.IsTrue(devices[0].productId == ProductId.Undefined); Assert.IsTrue(devices[1].name == "Corey's Device"); Assert.IsTrue(devices[1].productId == ProductId.BoseFrames); Assert.IsTrue(devices[1].variantId == (byte)BoseFramesVariantId.BoseFramesAlto); Assert.IsTrue(devices[2].name == "Michael's Headphones"); Assert.IsTrue(devices[2].productId == ProductId.BoseFrames); Assert.IsTrue(devices[2].variantId == (byte)BoseFramesVariantId.BoseFramesRondo); }; clientProtocol.ConnectionStatus += (state, device) => { _lastPacketName = "ConnectionStatus"; Assert.IsTrue(state == WearableProxyProtocolBase.ConnectionState.Connected); Assert.IsTrue(device != null); Assert.IsTrue(device.Value.name == "Product Name"); Assert.AreEqual(ProductId.BoseFrames, device.Value.productId); Assert.AreEqual((byte)BoseFramesVariantId.BoseFramesAlto, device.Value.variantId); Assert.IsTrue(device.Value.uid == "00000000-0000-0000-0000-000000000000"); }; clientProtocol.SensorStatus += (id, enabled) => { _lastPacketName = "SensorStatus"; Assert.AreEqual(SensorId.Gyroscope, id); Assert.AreEqual(true, enabled); }; clientProtocol.GestureStatus += (id, enabled) => { _lastPacketName = "GestureStatus"; Assert.AreEqual(GestureId.DoubleTap, id); Assert.AreEqual(true, enabled); }; clientProtocol.SensorUpdateIntervalValue += interval => { _lastPacketName = "UpdateIntervalValue"; Assert.AreEqual(SensorUpdateInterval.FortyMs, interval); }; clientProtocol.RotationSourceValue += source => { _lastPacketName = "RotationSourceValue"; Assert.AreEqual(RotationSensorSource.NineDof, source); }; WearableProxyProtocolBase.EncodeKeepAlive(clientBuffer, ref clientIndex); WearableProxyServerProtocol.EncodeSensorFrame( clientBuffer, ref clientIndex, new SensorFrame { timestamp = 123.45f, deltaTime = 0.1f, acceleration = new SensorVector3 { value = Vector3.right, accuracy = SensorAccuracy.Low }, angularVelocity = new SensorVector3 { value = Vector3.up, accuracy = SensorAccuracy.High }, rotation = new SensorQuaternion { value = new Quaternion(1.0f, 2.0f, 3.0f, 4.0f), measurementUncertainty = 15.0f }, gestureId = GestureId.DoubleTap }); WearableProxyServerProtocol.EncodeDeviceList( clientBuffer, ref clientIndex, new[] { new Device { isConnected = false, name = "Product Name", productId = ProductId.Undefined, variantId = (byte)BoseFramesVariantId.Undefined, rssi = -30, uid = "00000000-0000-0000-0000-000000000000" }, new Device { isConnected = false, name = "Corey's Device", productId = ProductId.BoseFrames, variantId = (byte)BoseFramesVariantId.BoseFramesAlto, rssi = -40, uid = "00000000-0000-0000-0000-000000000000" }, new Device { isConnected = false, name = "Michael's Headphones", productId = ProductId.BoseFrames, variantId = (byte)BoseFramesVariantId.BoseFramesRondo, rssi = -55, uid = "00000000-0000-0000-0000-000000000000" } }); WearableProxyServerProtocol.EncodeConnectionStatus( clientBuffer, ref clientIndex, WearableProxyProtocolBase.ConnectionState.Connected, new Device { isConnected = true, name = "Product Name", productId = ProductId.BoseFrames, variantId = (byte)BoseFramesVariantId.BoseFramesAlto, rssi = -30, uid = "00000000-0000-0000-0000-000000000000" }); WearableProxyServerProtocol.EncodeSensorStatus( clientBuffer, ref clientIndex, SensorId.Gyroscope, true); WearableProxyServerProtocol.EncodeUpdateIntervalValue( clientBuffer, ref clientIndex, SensorUpdateInterval.FortyMs); WearableProxyProtocolBase.EncodeKeepAlive(clientBuffer, ref clientIndex); WearableProxyServerProtocol.EncodeRotationSourceValue( clientBuffer, ref clientIndex, RotationSensorSource.NineDof); // Decode clientIndex = 0; clientProtocol.ProcessPacket(clientBuffer, ref clientIndex); Assert.AreEqual(_lastPacketName, "KeepAlive"); clientProtocol.ProcessPacket(clientBuffer, ref clientIndex); Assert.AreEqual(_lastPacketName, "SensorFrame"); clientProtocol.ProcessPacket(clientBuffer, ref clientIndex); Assert.AreEqual(_lastPacketName, "DeviceList"); clientProtocol.ProcessPacket(clientBuffer, ref clientIndex); Assert.AreEqual(_lastPacketName, "ConnectionStatus"); clientProtocol.ProcessPacket(clientBuffer, ref clientIndex); Assert.AreEqual(_lastPacketName, "SensorStatus"); clientProtocol.ProcessPacket(clientBuffer, ref clientIndex); Assert.AreEqual(_lastPacketName, "UpdateIntervalValue"); clientProtocol.ProcessPacket(clientBuffer, ref clientIndex); Assert.AreEqual(_lastPacketName, "KeepAlive"); clientProtocol.ProcessPacket(clientBuffer, ref clientIndex); Assert.AreEqual(_lastPacketName, "RotationSourceValue"); }