Exemplo n.º 1
0
        public ServiceController()
        {
            _sensor = new WiFiSensor(stopThread: _sensorStop, pauseThread: _sensorPause,
                playThread: _sensorPlay, output: _sensorOutputLocalizerInput);
            _localizer = new LocationLocalizer(stopThread: _localizerStop, pauseThread: _localizerPause,
                playThread: _localizerPlay, input: _sensorOutputLocalizerInput, algorithm: _localizationAlgorithm);

            _sensorState = ThreadState.Playing;
            _localizerState = ThreadState.Playing;

            _sensorThread = new Thread(new ThreadStart(_sensor.WiFiSensorLoop));
            _localizerThread = new Thread(new ThreadStart(_localizer.LocationLocalizerLoop));

            _sensorThread.IsBackground = true;
            _localizerThread.IsBackground = true;

            _sensorThread.Name = "WiFiSensorThread";
            _localizerThread.Name = "LocationLocalizerThread";
        }
Exemplo n.º 2
0
        public void WiFiSensorTest()
        {
            var stopThread = new AutoResetEvent(false);
            var pauseThread = new AutoResetEvent(false);
            var playThread = new AutoResetEvent(false);
            var wifiSensor = new WiFiSensor(stopThread: stopThread, pauseThread: pauseThread,
                playThread: playThread, output: new SensorToLocalizer<SensorOutput>());
            var wifiDelegate = new ThreadStart(wifiSensor.WiFiSensorLoop);
            var wifiThread = new Thread(wifiDelegate);
            wifiThread.Start();

            Log.Debug("Main Thread go to sleep");
            Thread.Sleep(16000);
            Log.Debug("Main thread is awake");

            Log.Debug("Pause WiFiSensor");
            pauseThread.Set();

            Log.Debug("Main Thread go to sleep");
            Thread.Sleep(8000);
            Log.Debug("Main thread is awake");

            Log.Debug("Restart WiFiSensor");
            playThread.Set();

            Log.Debug("Main Thread go to sleep");
            Thread.Sleep(16000);
            Log.Debug("Main thread is awake");

            Log.Debug("Stop WiFiSensor");
            stopThread.Set();

            Log.Debug("Wait for WiFiSensor");
            wifiThread.Join();
            Log.Debug("WiFiSensor has spontaneously terminated");
        }