コード例 #1
0
        public async Task ReadAllParams(CancellationToken cancel, IProgress <double> progress = null)
        {
            progress = progress ?? new Progress <double>();
            var packet = new ParamRequestListPacket
            {
                ComponenId = _identity.ComponentId,
                SystemId   = _identity.SystemId,
                Payload    =
                {
                    TargetComponent = _identity.TargetComponentId,
                    TargetSystem    = _identity.TargetSystemId,
                }
            };

            var samplesBySecond = _connection
                                  .Where(FilterVehicle)
                                  .Where(_ => _.MessageId == ParamValuePacket.PacketMessageId)
                                  .Cast <ParamValuePacket>().Buffer(TimeSpan.FromSeconds(1)).Next();

            _logger.Info($"Request all params from vehicle[{_identity}]");
            await _connection.Send(packet, cancel).ConfigureAwait(false);


            var timeout = DateTime.Now + TimeSpan.FromMilliseconds(_config.TimeoutToReadAllParamsMs);

            int?totalCnt = null;

            progress.Report(0);
            var paramsNames = new HashSet <string>();

            foreach (var paramsPart in samplesBySecond)
            {
                if (DateTime.Now >= timeout)
                {
                    throw new TimeoutException(string.Format(RS.Vehicle_ReadAllParams_Timeout_to_read_all_params_from_Vehicle, _config.TimeoutToReadAllParamsMs));
                }
                foreach (var p in paramsPart)
                {
                    totalCnt = totalCnt ?? p.Payload.ParamCount;
                    var name = GetParamName(p.Payload);
                    paramsNames.Add(name);
                }
                if (totalCnt.HasValue && totalCnt.Value <= paramsNames.Count)
                {
                    break;
                }
                var val = totalCnt == null ? 0 : Math.Min(1d, paramsNames.Count / (double)totalCnt);
                progress.Report(val);
                _logger.Trace($"Request all params from vehicle[{_identity}]: {val:P0}");
            }
            _logger.Trace($"Request all params from vehicle[{_identity}]: SUCCESS");
            progress.Report(1);
        }
コード例 #2
0
        public Task RequestAllParams(CancellationToken cancel)
        {
            _logger.Info($"Request all params from vehicle[{_identity}]");
            var packet = new ParamRequestListPacket
            {
                ComponenId = _identity.ComponentId,
                SystemId   = _identity.SystemId,
                Payload    =
                {
                    TargetComponent = _identity.TargetComponentId,
                    TargetSystem    = _identity.TargetSystemId,
                }
            };

            return(_connection.Send(packet, cancel));
        }
コード例 #3
0
 private void OnRequestList(ParamRequestListPacket obj)
 {
     if (Interlocked.CompareExchange(ref _isSending, 1, 0) != 0)
     {
         return;
     }
     try
     {
     }
     catch (Exception e)
     {
     }
     finally
     {
         Interlocked.Exchange(ref _isSending, 0);
     }
 }