Esempio n. 1
0
        /// <summary>
        /// intiialize the plugins
        /// </summary>
        public void Initialize()
        {
            _commands = new Queue<Action<ISystemController, IRaceController>>();
            _configuration = new PluginConfiguration();
            _configuration.Plugins = _allPlugins.Select(x=>x).ToList();

            _state = _raceController.State;

            var failed = new List<IPlugin>();
            foreach (var plugin in _configuration.Plugins)
            {
                try
                {
                    _logger.Info("Initializing Plugin " + plugin.GetType().Name);
                    InitializePlugin(plugin);
                }
                catch (Exception ex)
                {
                    _logger.Fatal("Exception initializing plugin "+plugin.GetType().Name, ex);
                    failed.Add(plugin);
                }
            }
            foreach (var plugin in failed)
            {
                EvictPlugin(_configuration,plugin,false);
            }

            //remove any plugins that failed to initialize
            //_configuration.Plugins = _configuration.Plugins.Where(x => x.Initialized).ToList();
            //foreach (var plugin in _configuration.Plugins)
            //{
            //    _logger.Info(plugin.GetType().Name + " Initialized OK");
            //}
            
        }
Esempio n. 2
0
        /// <inheritdoc />
        public void Initialize(PluginConfiguration configuration, Action<Action<ISystemController, IRaceController>> queueCommand)
		{
			_components = new List<IPluginComponent>();
			_initialized = false;
			var sensor = new Hmc5883Sensor(_logger,this,_compass);
			configuration.Sensors.Add(sensor);
			_components.Add(sensor);
		    _initialized = true;
		}
Esempio n. 3
0
        /// <inheritdoc />
        public void Initialize(PluginConfiguration configuration, Action<Action<ISystemController, IRaceController>> queueCommand)
        {
            _components = new List<IPluginComponent>();
        
            //scan for pebbles, we rely on MrGibbs.Configuration.BluetoothModule to have done discovery
			var pebbles = _manager.Detect (_btAdapterName, false,true,true);

			_logger.Info ("Found " + pebbles.Count + " Pebbles");

            if(pebbles.Any())
            {
                if (!string.IsNullOrEmpty(_pbwPath) && File.Exists(_pbwPath))
                {
                    using (var stream = new FileStream(_pbwPath, FileMode.Open))
                    {
                        using (var zip = new Zip())
                        {
                            zip.Open(stream);
							foreach (var pebble in pebbles) 
							{
								stream.Position = 0;
								InitializeViewer(pebble, zip, queueCommand, configuration);
							}
                        }
                    }
                }
                else
                {
                    throw new FileNotFoundException("Could not find " + _pbwPath);
                }
            }
            
            

            if (!_components.Any())
            {
                _initialized = false;
                if (pebbles.Any())
                {
                    throw new Exception("Failed to connect to any Pebbles");
                }
                else
                {
                    throw new Exception("No Pebbles found");
                }
            }
            else
            {
                _initialized = true;
            }

        }
        public void Initialize(PluginConfiguration configuration, Action<Action<ISystemController, IRaceController>> queueCommand)
        {
            _components = new List<IPluginComponent>();
        
            _initialized = false;

			_tsaGeoMag = new TSAGeoMag(_cofFilePath,_logger);

            var magvarCalc = new MagneticVariationCalculator(_logger, this, _tsaGeoMag);
            _components.Add(magvarCalc);
            configuration.Calculators.Add(magvarCalc);

            _initialized = true;
        }
Esempio n. 5
0
		/// <inheritdoc />
		public void Initialize(PluginConfiguration configuration, Action<Action<ISystemController, IRaceController>> queueCommand)
		{
			if (_recorder != null) 
			{
				_recorder.Dispose ();
			}

			_components = new List<IPluginComponent>();

			_initialized = false;

			_recorder.Plugin = this;
			configuration.Recorders.Add (_recorder);
			_components.Add (_recorder);

			_initialized = true;
		}
Esempio n. 6
0
        /// <inheritdoc />
        public void Initialize(PluginConfiguration configuration, Action<Action<ISystemController, IRaceController>> queueCommand)
        {
            _components = new List<IPluginComponent>();
        
            _initialized = false;

            var distanceCalc = new MarkCalculator(_logger, this);
            _components.Add(distanceCalc);
            configuration.Calculators.Add(distanceCalc);

            var tackCalc = new TackCalculator(_logger, this);
            _components.Add(tackCalc);
            configuration.Calculators.Add(tackCalc);



            _initialized = true;
        }
Esempio n. 7
0
        /// <inheritdoc />
        public void Initialize(PluginConfiguration configuration, Action<Action<ISystemController, IRaceController>> queueCommand)
        {
            _components = new List<IPluginComponent>();
            _initialized = false;
			GpsSensor sensor;
			if (_simulated)
			{
				sensor = new SimulatedGpsSensor (_logger, this);
			}
			else
			{
				sensor = new GpsSensor(_logger, this, _gpsPort, _gpsBaud);
			}
			sensor.Start ();
            configuration.Sensors.Add(sensor);
            _components.Add(sensor);
            _initialized = true;
        }
        /// <inheritdoc />
        public void Initialize(PluginConfiguration configuration, Action<Action<ISystemController, IRaceController>> queueCommand)
        {
			_components = new List<IPluginComponent>();
            _initialized = false;

			//TODO: maybe use the container or child container for this?
			ISensor sensor;
			if (_simulated) 
			{
				sensor = new SimulatedWindSensor (_logger,this);
			} 
			else 
			{
				if (string.IsNullOrWhiteSpace (_deviceAddress)) 
				{
					throw new ArgumentNullException ("deviceAddress");
				}

				var bmas = new BlendMicroAnemometerSensor (_logger, _clock, _maximumDataAge, this,_btAdapterName,_deviceAddress, _connection,_windAngleOffset);
				bmas.Start ();
				sensor = bmas;
			}

			_components.Add (sensor);
			configuration.Sensors.Add (sensor);

			var trueCalculator = new TrueWindCalculator (_logger, this);
			_components.Add (trueCalculator);
			configuration.Calculators.Add (trueCalculator);

			var mastBendCalculator = new MastBendCalculator (_logger, this);
			_components.Add (mastBendCalculator);
			configuration.Calculators.Add (mastBendCalculator);

            _initialized = true;
        }
Esempio n. 9
0
        /// <summary>
        /// initialize a given pebble and add it to the viewers if successful
        /// </summary>
        /// <param name="pebble"></param>
        /// <param name="zip"></param>
        /// <param name="queueCommand"></param>
        /// <param name="configuration"></param>
		private void InitializeViewer(PebbleSharp.Core.Pebble pebble,PebbleSharp.Core.IZip zip, Action<Action<ISystemController, IRaceController>> queueCommand,PluginConfiguration configuration)
		{
			try
			{
				var viewer = new PebbleViewer(_logger, this, pebble,zip,queueCommand);

				_components.Add(viewer);
				configuration.DashboardViewers.Add(viewer);
			}
			catch (Exception ex)
			{
				_logger.Error("Failed to connect to pebble "+pebble.PebbleID,ex);
			}
		}
Esempio n. 10
0
        /// <summary>
        /// evicts a plugin and optionally reloads it
        /// </summary>
        /// <param name="configuration">the configuration object</param>
        /// <param name="plugin">the plugin to evict</param>
        /// <param name="reinitialize">whether to re-initialize the plugin or leave it out</param>
        private void EvictPlugin(PluginConfiguration configuration,IPlugin plugin,bool reinitialize)
        {
            _logger.Warn("Evicting "+plugin.GetType().Name+" "+(reinitialize? "with" : "without")+" reinitialize");

            configuration.Sensors = configuration.Sensors.Where(x => x.Plugin != plugin).ToList();
            configuration.Calculators = configuration.Calculators.Where(x => x.Plugin != plugin).ToList();
            configuration.Recorders = configuration.Recorders.Where(x => x.Plugin != plugin).ToList();
            configuration.DashboardViewers = configuration.DashboardViewers.Where(x => x.Plugin != plugin).ToList();
            
            if (reinitialize)
            {
                //allow it to re-add the components and attempt to restart
                InitializePlugin(plugin);

                if (!plugin.Initialized)
                {
                    EvictPlugin(configuration,plugin,false);
                }
            }
            else
            {
                //remove it entirely
                configuration.Plugins = configuration.Plugins.Where(x => x != plugin).ToList();
            }
        }