private void WebSocket_MessageReceived(Windows.Networking.Sockets.MessageWebSocket sender, Windows.Networking.Sockets.MessageWebSocketMessageReceivedEventArgs args) { using (DataReader dataReader = args.GetDataReader()) { byte[] bytes = new byte[dataReader.UnconsumedBufferLength]; dataReader.ReadBytes(bytes); Gabriel.ToClient toClient = Gabriel.ToClient.Parser.ParseFrom(bytes); if (toClient.ResultWrapper == null) { // Set num tokens on welcome message lock (_tokenLock) { _numTokens = toClient.NumTokens; } return; } // We only return one to avoid race conditions when we have multiple messages in flight lock (_tokenLock) { _numTokens++; } Gabriel.ResultWrapper resultWrapper = toClient.ResultWrapper; if (resultWrapper.Status != Gabriel.ResultWrapper.Types.Status.Success) { UnityEngine.Debug.Log("Output status was: " + resultWrapper.Status); return; } Instruction.EngineFields newEngineFields = resultWrapper.EngineFields.Unpack <Instruction.EngineFields>(); if (newEngineFields.UpdateCount <= _engineFields.UpdateCount) { // There was no update or there was an update based on a stale frame return; } for (int i = 0; i < resultWrapper.Results.Count(); i++) { Gabriel.ResultWrapper.Types.Result result = resultWrapper.Results[i]; if (!result.EngineName.Equals(Const.ENGINE_NAME)) { UnityEngine.Debug.LogError("Got result from engine " + result.EngineName); } if (result.PayloadType == Gabriel.PayloadType.Text) { _speechFeedback = result.Payload.ToStringUtf8(); textToSpeechManager.SpeakText(_speechFeedback); } } _engineFields = newEngineFields; UpdateHologram(newEngineFields, resultWrapper.FrameId); } }
private void UpdateHologram(Instruction.EngineFields engineFields, long frameID) { switch (engineFields.Sandwich.State) { case Instruction.Sandwich.Types.State.Bread: _hologram = Hologram.Ham; break; case Instruction.Sandwich.Types.State.Ham: _hologram = Hologram.Lettuce; break; case Instruction.Sandwich.Types.State.Lettuce: _hologram = Hologram.Bread; break; case Instruction.Sandwich.Types.State.Half: _hologram = Hologram.Tomato; break; case Instruction.Sandwich.Types.State.Tomato: _hologram = Hologram.BreadTop; break; default: _hologram = Hologram.None; _guidancePosReady = true; return; } UnityEngine.Debug.Log("Hologram x: " + engineFields.Sandwich.HoloX); UnityEngine.Debug.Log("Hologram y: " + engineFields.Sandwich.HoloY); UnityEngine.Debug.Log("Hologram depth: " + engineFields.Sandwich.HoloDepth); Matricies matricies; _frameIdMatriciesMap.TryRemove(frameID, out matricies); _guidancePos = Pixel2WorldPos( (float)engineFields.Sandwich.HoloX, (float)engineFields.Sandwich.HoloY, (float)engineFields.Sandwich.HoloDepth, matricies.projectionMatrix, matricies.cameraToWorldMatrix); _guidancePosReady = true; }