コード例 #1
0
        void MqttMsgReceived(object sender, MqttMsgPublishEventArgs e)
        {
            string topic = e.Topic;

            string[] topicComponents = topic.Split('/');
            string   msg             = System.Text.Encoding.UTF8.GetString(e.Message);
//            Debug.Log("Received on topic: " + e.Topic + "[" + (msgReceived++) + "] : " + System.Text.Encoding.UTF8.GetString(e.Message));

            MsgHeader msgHeader = MsgHeader.CreateFromJSON(msg);

            if (msgHeader.type != null && msgHeader.type.Equals("POSE_UPDATE"))
            {
                long pingTime = DateTimeOffset.Now.ToUnixTimeMilliseconds() - msgHeader.sendTime;
//                Debug.Log("Pose event received (ping: " + pingTime + ")");
                int       startIndex = msg.IndexOf("payload\":") + "payload\":".Length;
                PoseEvent pose       = PoseEvent.CreateFromJSON(msg.Substring(startIndex, msg.Length - (startIndex + 1)));
                pose.setAllValuesWithoutValueToNull();
                if (poseCoreEventManager != null)
                {
                    poseCoreEventManager.HandlePoseEvent(pose);
                }
            }
            else
            {
                Debug.Log("Unknown msg received: " + msg);
            }
        }