Exemple #1
0
        private void KeepAlive()
        {
            _logger.Log(NLog.LogLevel.Debug, "KeepAlive Elapsed");

            lock (_restartLock)
                if (_pioneerController?.Port != null && _pioneerController.FirstUnconfirmedSendTime != null && _pioneerController.FirstUnconfirmedSendTime.Value.AddSeconds(10) < DateTime.Now)
                {
                    _logger.Debug("suspect not receiving anything. Resetting Device...");
                    var hostname = _pioneerController.Hostname;
                    var port     = _pioneerController.Port.Value;
                    _pioneerController.Dispose();
                    _pioneerController = new PioneerAmp(hostname, port);
                    OnStart();
                }

            var sendTime = DateTime.Now;

            do
            {
                System.Threading.Thread.Sleep(100);
            } while (!(sendTime.AddMilliseconds(new[] { _keepAliveTimer.Interval, 10000 }.Min()) > DateTime.Now || (_pioneerController?.LastReceiveTime.GetValueOrDefault(DateTime.MinValue) > sendTime && _pioneerController.PowerOn != null)));

            if (_pioneerController?.PowerOn != null)
            {
                _pioneerController.SetPowerState(_pioneerController.PowerOn.Value);
            }
            else
            {
                _pioneerController?.RequestPowerState();
            }
        }
Exemple #2
0
        public PioneerStatusMonitor(Config config)
        {
            _config = config;
            _config.FillBlanksWithDefault();

            _pioneerController = new PioneerAmp(_config.IpAddress, _config.Port);

            _keepAliveTimer = new Timer(_config.KeepAliveTime ?? 1800000)
            {
                AutoReset = true
            };
            _keepAliveTimer.Elapsed += KeepAliveTimerElapsed;

            if (_config.KeepAlive == true)
            {
                _keepAliveTimer.Start();
            }
        }