/// <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(); } })); }
/// <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(); } })); }