public void TestClientToServer() { WearableProxyServerProtocol serverProtocol = new WearableProxyServerProtocol(); int serverIndex = 0; byte[] serverBuffer = new byte[1024]; // Register callbacks for packet processing serverProtocol.KeepAlive += () => { _lastPacketName = "KeepAlive"; }; serverProtocol.PingQuery += () => { _lastPacketName = "PingQuery"; }; serverProtocol.PingResponse += () => { _lastPacketName = "PingResponse"; }; serverProtocol.SensorControl += (id, enabled) => { _lastPacketName = "SensorControl"; Assert.AreEqual(SensorId.Gyroscope, id); Assert.AreEqual(enabled, true); }; serverProtocol.GestureControl += (id, enabled) => { _lastPacketName = "GestureControl"; Assert.AreEqual(GestureId.DoubleTap, id); Assert.AreEqual(enabled, true); }; serverProtocol.RSSIFilterValueChange += value => { _lastPacketName = "SetRSSI"; Assert.AreEqual(-40, value); }; serverProtocol.InitiateDeviceSearch += () => { _lastPacketName = "StartSearch"; }; serverProtocol.StopDeviceSearch += () => { _lastPacketName = "StopSearch"; }; serverProtocol.ConnectToDevice += uid => { _lastPacketName = "ConnectToDevice"; Assert.AreEqual("00000000-0000-0000-0000-000000000000", uid); }; serverProtocol.DisconnectFromDevice += () => { _lastPacketName = "DisconnectFromDevice"; }; serverProtocol.QueryConnectionStatus += () => { _lastPacketName = "QueryConnection"; }; serverProtocol.QueryUpdateInterval += () => { _lastPacketName = "QueryUpdateInterval"; }; serverProtocol.SetUpdateInterval += interval => { _lastPacketName = "SetUpdateInterval"; Assert.AreEqual(SensorUpdateInterval.OneHundredSixtyMs, interval); }; serverProtocol.QuerySensorStatus += () => { _lastPacketName = "QuerySensorStatus"; }; serverProtocol.QueryGestureStatus += () => { _lastPacketName = "QueryGestureStatus"; }; serverProtocol.QueryRotationSource += () => { _lastPacketName = "QueryRotationSource"; }; serverProtocol.SetRotationSource += source => { _lastPacketName = "SetRotationSource"; Assert.AreEqual(RotationSensorSource.NineDof, source); }; // Encode WearableProxyProtocolBase.EncodeKeepAlive(serverBuffer, ref serverIndex); WearableProxyProtocolBase.EncodePingQuery(serverBuffer, ref serverIndex); WearableProxyProtocolBase.EncodePingResponse(serverBuffer, ref serverIndex); WearableProxyClientProtocol.EncodeSensorControl(serverBuffer, ref serverIndex, SensorId.Gyroscope, true); WearableProxyClientProtocol.EncodeGestureControl(serverBuffer, ref serverIndex, GestureId.DoubleTap, true); WearableProxyClientProtocol.EncodeRSSIFilterControl(serverBuffer, ref serverIndex, -40); WearableProxyClientProtocol.EncodeInitiateDeviceSearch(serverBuffer, ref serverIndex); WearableProxyClientProtocol.EncodeStopDeviceSearch(serverBuffer, ref serverIndex); WearableProxyClientProtocol.EncodeConnectToDevice(serverBuffer, ref serverIndex, "00000000-0000-0000-0000-000000000000"); WearableProxyClientProtocol.EncodeDisconnectFromDevice(serverBuffer, ref serverIndex); WearableProxyClientProtocol.EncodeQueryConnectionStatus(serverBuffer, ref serverIndex); WearableProxyClientProtocol.EncodeQueryUpdateInterval(serverBuffer, ref serverIndex); WearableProxyClientProtocol.EncodeSetUpdateInterval(serverBuffer, ref serverIndex, SensorUpdateInterval.OneHundredSixtyMs); WearableProxyClientProtocol.EncodeQuerySensorStatus(serverBuffer, ref serverIndex); WearableProxyProtocolBase.EncodeKeepAlive(serverBuffer, ref serverIndex); WearableProxyClientProtocol.EncodeQueryRotationSource(serverBuffer, ref serverIndex); WearableProxyClientProtocol.EncodeSetRotationSource(serverBuffer, ref serverIndex, RotationSensorSource.NineDof); // Decode serverIndex = 0; serverProtocol.ProcessPacket(serverBuffer, ref serverIndex); Assert.AreEqual("KeepAlive", _lastPacketName); serverProtocol.ProcessPacket(serverBuffer, ref serverIndex); Assert.AreEqual("PingQuery", _lastPacketName); serverProtocol.ProcessPacket(serverBuffer, ref serverIndex); Assert.AreEqual("PingResponse", _lastPacketName); serverProtocol.ProcessPacket(serverBuffer, ref serverIndex); Assert.AreEqual("SensorControl", _lastPacketName); serverProtocol.ProcessPacket(serverBuffer, ref serverIndex); Assert.AreEqual("GestureControl", _lastPacketName); serverProtocol.ProcessPacket(serverBuffer, ref serverIndex); Assert.AreEqual("SetRSSI", _lastPacketName); serverProtocol.ProcessPacket(serverBuffer, ref serverIndex); Assert.AreEqual("StartSearch", _lastPacketName); serverProtocol.ProcessPacket(serverBuffer, ref serverIndex); Assert.AreEqual("StopSearch", _lastPacketName); serverProtocol.ProcessPacket(serverBuffer, ref serverIndex); Assert.AreEqual("ConnectToDevice", _lastPacketName); serverProtocol.ProcessPacket(serverBuffer, ref serverIndex); Assert.AreEqual("DisconnectFromDevice", _lastPacketName); serverProtocol.ProcessPacket(serverBuffer, ref serverIndex); Assert.AreEqual("QueryConnection", _lastPacketName); serverProtocol.ProcessPacket(serverBuffer, ref serverIndex); Assert.AreEqual("QueryUpdateInterval", _lastPacketName); serverProtocol.ProcessPacket(serverBuffer, ref serverIndex); Assert.AreEqual("SetUpdateInterval", _lastPacketName); serverProtocol.ProcessPacket(serverBuffer, ref serverIndex); Assert.AreEqual("QuerySensorStatus", _lastPacketName); serverProtocol.ProcessPacket(serverBuffer, ref serverIndex); Assert.AreEqual("KeepAlive", _lastPacketName); serverProtocol.ProcessPacket(serverBuffer, ref serverIndex); Assert.AreEqual("QueryRotationSource", _lastPacketName); serverProtocol.ProcessPacket(serverBuffer, ref serverIndex); Assert.AreEqual("SetRotationSource", _lastPacketName); }