Пример #1
0
        /// <summary>
        /// Gets the device informations for the given thing id.
        /// First the cached devices data is queried. If no device info for the given uid was found, a web request is executed to get the latest device data.
        /// </summary>
        /// <param name="thingId">thing id</param>
        /// <param name="handleDeviceInfo">the callback method</param>
        public void GetDeviceInfo(string thingId, Action <DeviceInfo> handleDeviceInfo)
        {
            DeviceInfo outValue = null;

            if (!DeviceInfos.TryGetValue(thingId, out outValue))
            {
                StartCoroutine(RequestAllThings(thingId, handleDeviceInfo));
            }
            else
            {
                handleDeviceInfo(outValue);
            }
        }
Пример #2
0
        private void InstantiateExisitingDevices()
        {
            if (initializedExisitingDevices)
            {
                return;
            }

            initializedExisitingDevices = true;

            if (WorldAnchorManager.IsInitialized)
            {
                foreach (string anchorId in WorldAnchorManager.Instance.AnchorStore.GetAllIds())
                {
                    DeviceInfo info = null;
                    DeviceInfos.TryGetValue(anchorId, out info);
                    if (info == null)
                    {
                        Debug.LogErrorFormat("device with anchor id '{0}' not found\n removing from AnchorManager...", anchorId);
                        if (WorldAnchorManager.IsInitialized)
                        {
                            WorldAnchorManager.Instance.RemoveAnchor(anchorId);
                        }
                    }
                    else
                    {
                        DeviceSpawner.Instance.SpawnDevice(anchorId, e =>
                        {
                            if (e != null)
                            {
                                Debug.LogFormat("spawned exisiting device with id '{0}'", anchorId);
                            }
                            else
                            {
                                Debug.LogErrorFormat("failed to spawn exisiting device with anchor id '{0}'\n removing from AnchorManager...", anchorId);
                                if (WorldAnchorManager.IsInitialized)
                                {
                                    WorldAnchorManager.Instance.RemoveAnchor(anchorId);
                                }
                            }
                        });
                    }
                }
            }
        }
Пример #3
0
        /// <summary>
        /// Requests all things data from th SAL. If thingUid and callback action added, the callback is called with the device data.
        /// </summary>
        private IEnumerator RequestAllThings(string thingUid = null, Action <DeviceInfo> handleDeviceInfo = null)
        {
            var request = new AllThingsRequest(openhabUri, HandleAllThingsData);

            yield return(request.ExecuteRequest());

            if (thingUid != null)
            {
                DeviceInfo outInfo = null;
                if (!DeviceInfos.TryGetValue(thingUid, out outInfo))
                {
                    Debug.LogErrorFormat("device info not found for uid '{0}'", thingUid);
                }
                handleDeviceInfo?.Invoke(outInfo);
            }

            //instantiate devices, which have an anchor stored on the hololens
            InstantiateExisitingDevices();
        }