private void ShowNextQuestion(bool isFirst) { if (result.Length <= 0 && !isFirst) { return; } if (result.Length > 0) { int resultInt = int.Parse(result.ToString()); BluetoothMessage message = new BluetoothMessage(index, resultInt); if (!isReceiving) { isSending = true; BluetoothController.Instance.BLESendMessage(message); } else { StartCoroutine(ShowNextQuestion()); } } else //第一个题 { StartCoroutine(ShowNextQuestion()); } }
public void CentralReceiveMessage(string address, string characteristic, byte[] bytes) { MyDebug.LogGreen("CentralReceiveMessage"); BluetoothMessage msg = new BluetoothMessage(bytes); if (msg == null) { MyDebug.LogYellow("CentralReceiveMessage: Message is NULL!"); return; } MyDebug.LogGreen("Index:" + msg.index + ", Result:" + msg.result + ", name:" + msg.name); if (msg.index == 0) { UnityEngine.Random.InitState(msg.result); GuiController.Instance.CompetitionGUI = GuiFrameID.BluetoothFrame; GuiController.Instance.SwitchWrapper(GuiFrameID.BluetoothFightFrame); } else { if (BLEReceiveMessage != null) { BLEReceiveMessage(msg); } } }
public void PeripheralReceiveMessage(string UUID, byte[] bytes) { MyDebug.LogGreen("PeripheralReceiveMessage"); BluetoothMessage msg = new BluetoothMessage(bytes); if (msg == null) { MyDebug.LogYellow("PeripheralReceiveMessage: Message is NULL!"); return; } MyDebug.LogGreen("Index:" + msg.index + ", Result:" + msg.result + ", name:" + msg.name); if (msg.index == 0) { UnityEngine.Random.InitState(msg.result); CurPeripheralInstance = new PeripheralInstance("", msg.name); SetSendMessageFunc(false); BLESendMessage(msg); GuiController.Instance.CompetitionGUI = GuiFrameID.BluetoothFrame; GuiController.Instance.SwitchWrapper(GuiFrameID.BluetoothFightFrame); } else { if (BLEReceiveMessage != null) { BLEReceiveMessage(msg); } } }
private void PeripheralSendMessage(BluetoothMessage message) { MyDebug.LogGreen("PeripheralSendMessage"); MyDebug.LogGreen("index:" + message.index); MyDebug.LogGreen("result:" + message.result); MyDebug.LogGreen("name:" + message.name); MyDebug.LogGreen("Length:" + message.data.Length); BluetoothLEHardwareInterface.UpdateCharacteristicValue(ReadUUID, message.data, message.data.Length); }
private IEnumerator FirstWrite() { MyDebug.LogGreen("First Write!"); yield return(new WaitForSeconds(1f)); int seed = UnityEngine.Random.Range(1, int.MaxValue); BluetoothMessage message = new BluetoothMessage(0, seed, GameManager.Instance.UserName); BluetoothController.Instance.SetSendMessageFunc(true); BluetoothController.Instance.BLESendMessage(message); }
private void CentralSendMessage(BluetoothMessage message) { MyDebug.LogGreen("CentralSendMessage"); MyDebug.LogGreen("index:" + message.index); MyDebug.LogGreen("result:" + message.result); MyDebug.LogGreen("name:" + message.name); MyDebug.LogGreen("Length:" + message.data.Length); BluetoothLEHardwareInterface.WriteCharacteristic(CurPeripheralInstance.address, ServiceUUID, WriteUUID, message.data, message.data.Length, true, (characteristicUUID) => { BluetoothLEHardwareInterface.Log("Write Succeeded"); }); }
private void OnReceiveMessage(BluetoothMessage message) { MyDebug.LogGreen("index: " + message.index + ", result: " + message.result); isReceiving = true; if (message.index == index) { int resultInt = 0; if (!int.TryParse(result.ToString(), out resultInt)) { resultInt = 0; //被抢答的情况 } lock (curInstance) //倒数第一个是自己的答案,倒数第二个是正确答案,倒数第三个是对方的答案 { curInstance.Insert(curInstance.Count - 1, message.result); curInstance.Add(resultInt); } lock (resultList) { resultList.Add(curInstance); } if (resultList.Count == amount) { if (!message.name.Equals(end)) { isSending = true; BluetoothController.Instance.BLESendMessage(new BluetoothMessage(index, resultInt, end)); } FightOver(); } else { if (isSending) { StartCoroutine(ShowNextQuestion()); } else { isSending = true; BluetoothController.Instance.BLESendMessage(new BluetoothMessage(index, resultInt)); StartCoroutine(ShowNextQuestion()); } } isSending = false; isReceiving = false; } else { string tip = "Index Wrong:" + message.index; GuiController.Instance.CurCommonTipInstance = new CommonTipInstance(CommonTipID.Single, tip); GuiController.Instance.SwitchWrapper(GuiFrameID.CommonTipFrame, true); } }
public virtual IEnumerator<ITask> ReceiveBluetoothMessageHandler(ReceiveBluetoothMessage query) { BluetoothMessage response = new BluetoothMessage(); int inbox = Math.Max(1, Math.Min(10, query.Body.Mailbox)) - 1; nxtcmd.LegoMessageRead cmd = new nxtcmd.LegoMessageRead(inbox + 10, inbox, true); yield return Arbiter.Choice(_legoBrickPort.SendNxtCommand(cmd), delegate(nxtcmd.LegoResponse ok) { nxtcmd.LegoResponseMessageRead queryResponse = nxtcmd.LegoResponse.Upcast<nxtcmd.LegoResponseMessageRead>(ok); if (queryResponse.Success) { response.Mailbox = query.Body.Mailbox; response.Message = queryResponse.Message; query.ResponsePort.Post(response); } else { query.ResponsePort.Post(Fault.FromException(new System.IO.IOException(queryResponse.ErrorCode.ToString()))); } }, delegate(Fault fault) { query.ResponsePort.Post(fault); }); yield break; }
private static void BlueConeMessageReceived(BluetoothMessage message) { tmp = message.Command.Split('#'); switch (tmp[0].Trim()) { case "NEXT": BlueConePlayer.Next(); break; case "PLAY": Debug.Print("PLAY"); break; case "PAUSE": Debug.Print("PAUSE"); break; case "STOP": Debug.Print("STOP"); break; case "PRI": Debug.Print("PRI"); Debug.Print(tmp[1].Trim()); if (tmp[1].Trim() == "0") { BlueConePlayer.UsePriority(false); } else { BlueConePlayer.UsePriority(true); } break; case "ADD": // ADD#PATH BlueConePlayer.AddTrack(tmp[1].Trim(), ((Connection)WT32.Connections[message.Link]).Address); break; case "VOLUP": VS1053.VolUp(); break; case "VOLDOWN": VS1053.VolDown(); break; case "MASTER": if (tmp[1].Trim() == Settings.MasterPassword) { WT32.SendMessage(new BluetoothMessage(message.Link, "MASTER#OK|" + BlueConePlayer.PriorityOn.ToString())); } else { WT32.SendMessage(new BluetoothMessage(message.Link, "MASTER#ERR")); } break; case "QUEUEREMOVE": int i = BlueConePlayer.RemoveTrack(tmp[1].Trim()); WT32.BroadcastMessage("REMOVE#" + i); Debug.Print("QueueRemove: " + tmp[1].Trim()); break; case "REQ_QUEUE": BlueConePlayer.SendTracks((Connection)WT32.Connections[message.Link], false); break; case "REQ_ALL": BlueConePlayer.SendTracks((Connection)WT32.Connections[message.Link], true); break; default: Debug.Print(message.Command + ", Link: " + message.Link); break; } message.Dispose(); }