void ParseMarkerPositions() { string markerString = udpReceive.getLatestUDPPacket(0); string[] markers = markerString.Split('\n'); for (int i = 0; i < markers.Length; i++) { if (markers[i].Length > 0) { string[] infos = markers[i].Split(':'); try { // parse message int id = int.Parse(infos[0]); string[] pos = infos[1].Trim().Split(' '); Vector3 position = new Vector3(float.Parse(pos[0]), float.Parse(pos[1]), float.Parse(pos[2])); Quaternion quaternion = new Quaternion(float.Parse(pos[3]), float.Parse(pos[4]), float.Parse(pos[5]), float.Parse(pos[6])); reconstructedCamera[id].localRotation = Quaternion.identity; reconstructedCamera[id].localPosition = Vector3.zero; reconstructedCamera[id].Rotate(Quaternion.Inverse(quaternion).eulerAngles); reconstructedCamera[id].Translate(-10 * position, Space.Self); reconstructedCamera[id].gameObject.GetComponent <Renderer>().material.SetColor("_Color", Color.red); frameMarkerIds.Add(id); } catch (Exception e) { //Debug.LogException(e, this); //Debug.LogWarning("cannot parse: " + markers[i]); } } } }
private void updateMotors() { string json = udpreceiver.getLatestUDPPacket((int)UDPReceive.MessageType.MOTORS); if (json.Length < 10) { return; } int startIndex = json.IndexOf("{") + 1; json = json.Substring(startIndex + 1, json.Length - 2 - startIndex); string[] motorArray = json.Split('m'); for (int i = 0; i < motorArray.Length; i++) { int index = motorArray[i].IndexOf("{"); motorArray[i] = motorArray[i].Substring(index, motorArray[i].Length - index); SerializedSCS15 scs15 = JsonUtility.FromJson <SerializedSCS15>(motorArray[i]); int id = scs15.i - 2; float pos = sens[id] * 100.0f * ((float)(scs15.p) - offset[id] - 512.0f) / 512.0f; motorController.SetPosition(id, pos); } }
// check for incomming messages void LateUpdate() { // get the latest message from the smartphone string _str = _udpListener.getLatestUDPPacket(); // strA[0] is the message, strA[1] is the priority p (0 = low; 1 = high) string[] _strA = _str.Split(';'); // if a new message comes in fire an event if (_lastMessage != _str && _strA.Length == 2) { Debug.Log("New Message (priority p = " + _strA[1] + ") : \"" + _strA[0] + "\""); _lastMessage = _str; ProcessIncomingNotification(_strA[0], float.Parse(_strA[1])); } }