/// <summary>
        /// see <see cref="ICrazyflieParamConfigurator.RefreshParameterValue(string)"/>
        /// </summary>
        public Task <object> RefreshParameterValue(string completeName)
        {
            EnsureToc();
            var id = CurrentToc.GetElementId(completeName);

            if (id == null)
            {
                throw new ArgumentException($"{completeName} not found in toc", nameof(completeName));
            }

            var request = new ParamRequest(id.Value);

            lock (_openLoadRequestLock)
            {
                _openLoadRequests.Add(request);
            }

            return(Task.Run(() =>
            {
                _paramSynchronizer.RequestLoadParamValue(id.Value);
                try
                {
                    if (!request.Wait(10000))
                    {
                        throw new ApplicationException($"failed to update parameter value {completeName} (timeout)");
                    }
                    return GetLoadedParameterValue(completeName);
                }
                finally
                {
                    request.Dispose();
                }
            }));
        }
示例#2
0
 /// <summary>
 /// <see cref="ICrazyflieLogger.IsLogVariableKnown(string)"/>
 /// </summary>
 public bool IsLogVariableKnown(string completeName)
 {
     if (CurrentToc == null)
     {
         throw new InvalidOperationException("no toc for log entries available.");
     }
     return(CurrentToc.GetElementByCompleteName(completeName) != null);
 }
        /// <summary>
        /// <see cref="ICrazyflieParamConfigurator.GetLoadedParameterValue(string)"/>
        /// </summary>
        public object GetLoadedParameterValue(string completeName)
        {
            EnsureToc();
            var id = CurrentToc.GetElementId(completeName);

            if (id != null && _paramValues.ContainsKey(id.Value))
            {
                return(_paramValues[id.Value]);
            }
            return(null);
        }
        private void ParameterReceived(object sender, ParameterReceivedEventArgs e)
        {
            var element = CurrentToc.GetElementById(e.Id);
            var packId  = ParamTocElement.GetIdFromCString(element.CType);

            _paramValues[e.Id] = ParamTocElement.Unpack(packId, e.ParamValue);
            if (!_isUpdated && AreAllParamValuesUpdated())
            {
                _isUpdated = true;
                _waitForAllParams.Set();
                AllParametersUpdated?.Invoke(this, new AllParamsUpdatedEventArgs());
            }
            UpdateOpenRequests(_openLoadRequests, _openLoadRequestLock, e.Id, "load");
        }
示例#5
0
        private LogTocElement EnsureVariableInToc(LogConfig config, string name)
        {
            var tocVariable = CurrentToc.GetElementByCompleteName(name);

            if (tocVariable == null)
            {
                _log.Warn(
                    $"{name} not in TOC, this block cannot be used!");
                config.Valid = false;
                throw new InvalidOperationException($"variable {name} not in TOC");
            }

            return(tocVariable);
        }
        /// <summary>
        /// <see cref="ICrazyflieParamConfigurator.SetValue(string, object)"/>
        /// </summary>
        public Task SetValue(string completeName, object value)
        {
            EnsureToc();
            var id = CurrentToc.GetElementId(completeName);

            if (id == null)
            {
                throw new ArgumentException($"{completeName} not found in toc", nameof(completeName));
            }

            if (CurrentToc.GetElementById(id.Value).Access != ParamTocElement.AccessLevel.Readwrite)
            {
                throw new InvalidOperationException("unable to set a readonly parameter: " + completeName);
            }

            var element = CurrentToc.GetElementById(id.Value);
            var packId  = ParamTocElement.GetIdFromCString(element.CType);
            var content = ParamTocElement.Pack(packId, value);

            var request = new ParamRequest(id.Value);

            lock (_openStoreRequestLock)
            {
                _openStoreRequests.Add(request);
            }

            return(Task.Run(() =>
            {
                _paramSynchronizer.StoreParamValue(id.Value, content);
                try
                {
                    if (!request.Wait(10000))
                    {
                        throw new ApplicationException($"failed to store new parameter value {completeName} (timeout)");
                    }
                }
                finally
                {
                    request.Dispose();
                }
            }));
        }
 /// <summary>
 /// <see cref="ICrazyflieParamConfigurator.IsParameterKnown(string)"/>
 /// </summary>
 public bool IsParameterKnown(string completeName)
 {
     EnsureToc();
     return(CurrentToc.GetElementByCompleteName(completeName) != null);
 }