/// <summary> /// Process the tennis message /// </summary> /// <param name="message"></param> private async void AppMessageReceived(P3bbleMessage message) { try { var localSettings = ApplicationData.Current.LocalSettings; switch (message.Endpoint) { case P3bble.Constants.Endpoint.WatchFaceSelect: WatchFaceMessage _watchFaceMessage = (WatchFaceMessage)message; System.Diagnostics.Debug.WriteLine("WatchFaceMessage received: " + _watchFaceMessage.CurrentWatchFace.ToString()); var WatchItem = _pc.WatchItems.FindLast(x => x.ID == _watchFaceMessage.CurrentWatchFace); if (WatchItem != null) { await WatchItem.Ready(); } break; case P3bble.Constants.Endpoint.ApplicationMessage: P3bble.Messages.AppMessage _appMessage = (P3bble.Messages.AppMessage)message; if (_appMessage.AppUuid != Guid.Parse("51a56b50-f87d-ce41-a0ff-30d03a88fa8d")) { System.Diagnostics.Debug.WriteLine("AppMessage received: " + _appMessage.AppUuid.ToString()); } WatchItem = _pc.WatchItems.FindLast(x => x.ID == _appMessage.AppUuid); if (WatchItem != null) { System.Diagnostics.Debug.WriteLine("AppMessage received: " + WatchItem.Name); await WatchItem.AppMessage(_appMessage.Content); } break; } } catch (Exception exp) { AddToLog(exp.Message); } }
/// <summary> /// Creates an incoming message. /// </summary> /// <param name="endpoint">The endpoint.</param> /// <param name="payload">The payload.</param> /// <returns>A specific message type</returns> public static P3bbleMessage CreateMessage(Endpoint endpoint, List<byte> payload) { P3bbleMessage frame = null; switch (endpoint) { case Endpoint.Ping: frame = new PingMessage(); break; case Endpoint.Version: frame = new VersionMessage(); break; case Endpoint.Time: frame = new TimeMessage(); break; case Endpoint.Logs: frame = new LogsMessage(); break; case Endpoint.AppManager: frame = new AppManagerMessage(); break; case Endpoint.MusicControl: frame = new MusicMessage(); break; case Endpoint.ApplicationMessage: frame = new AppMessage(endpoint); break; case Endpoint.PutBytes: frame = new PutBytesMessage(); break; } if (frame != null) { frame.GetContentFromMessage(payload); } return frame; }
/// <summary> /// Process the tennis message /// </summary> /// <param name="message"></param> private async void TennisMessageReceived(P3bbleMessage message) { var localSettings = ApplicationData.Current.LocalSettings; if (message.Endpoint == P3bble.Constants.Endpoint.ApplicationMessage) { P3bble.Messages.AppMessage _tennisMessage = (P3bble.Messages.AppMessage)message; if (_tennisMessage.AppUuid == Guid.Parse("51a56b50-f87d-ce41-a0ff-30d03a88fa8d")) { System.Diagnostics.Debug.WriteLine("TennisMessage received"); P3bble.Messages.AppMessage AckMessage = new P3bble.Messages.AppMessage(); AckMessage.Command = P3bble.Messages.AppCommand.Ack; AckMessage.TransactionId = _tennisMessage.TransactionId; await _pc.Pebble._protocol.WriteMessage(AckMessage); System.Diagnostics.Debug.WriteLine("TennisMessage Acknowledged"); if (TennisMatch.Paused) { System.Diagnostics.Debug.WriteLine("Match suspended; message ignored."); return; } if (_tennisMessage.Content.ContainsKey(1)) { int ActionCode = (int)_tennisMessage.Content[1]; System.Diagnostics.Debug.WriteLine(String.Format("Tennis action: {0}", ActionCode)); switch (ActionCode) { case 0: TennisMatch.ProcessAction("CommandLose"); break; case 1: TennisMatch.ProcessAction("CommandWin"); break; case 2: TennisMatch.ProcessAction("CommandSecondServe"); System.Diagnostics.Debug.WriteLine("CommandSecondServe"); break; case 3: TennisMatch.ProcessAction("CommandAce"); break; case 5: TennisMatch.ProcessAction("CommandDoubleFault"); System.Diagnostics.Debug.WriteLine("CommandDoubleFault"); break; case 4: TennisMatch.ProcessAction("CommandUndo"); break; case 16: TennisMatch.ProcessAction("CommandExtend"); break; case 128: string log = (string)_tennisMessage.Content[2]; System.Diagnostics.Debug.WriteLine(log); break; case 254: //request new state System.Diagnostics.Debug.WriteLine("Tennis: new state requested"); break; } await SaveMatchState(); } } } }