Esempio n. 1
0
        /// <summary>
        /// Handler for notifications by the tracker.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void tracker_TrackerNotification(object sender, TrackerNotificationEventArgs e)
        {
            ServiceStatus serviceStatus = null;

            lock (_lockStatus)
            {
                switch (e.Code)
                {
                case TrackerNotificationCode.NoSignalsDetected:
                    Debug.WriteLine("NO SIGNAL DETECTED.");
                    break;

                case TrackerNotificationCode.Started:

                    // from tracking to training mode
                    Debug.WriteLine("TRACKER STARTED (training). ");
                    _localizer.Enabled = false;

                    // notify all subscribers
                    serviceStatus = new ServiceStatus
                    {
                        ContextId    = _localizer.ContextId,
                        ServiceState = ServiceStateCode.Training
                    };
                    DoReportServiceStatus(serviceStatus);
                    break;

                case TrackerNotificationCode.Stopped:

                    // from tracking to notification mode
                    Debug.WriteLine("TRACKER STOPPED.");

                    // notify all subscribers
                    serviceStatus = new ServiceStatus
                    {
                        ContextId    = _localizer.ContextId,
                        ServiceState = ServiceStateCode.Notification
                    };
                    DoReportServiceStatus(serviceStatus);
                    break;

                case TrackerNotificationCode.TrainingCompleted:

                    // from training to tracking mode
                    Debug.WriteLine("TRAINING COMPLETED.");
                    _localizer.Enabled = true;

                    // notify all subscribers
                    serviceStatus = new ServiceStatus
                    {
                        ContextId    = _localizer.ContextId,
                        ServiceState = ServiceStateCode.Tracking
                    };
                    DoReportServiceStatus(serviceStatus);
                    break;
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Each time this handler is invoked, a new WLAN scan is performed
        /// and a new example is added to the staging area.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void trackerTimer_Elapsed(object sender, ElapsedEventArgs e)
        {
            lock (_trackerLock)
            {
                if (_targetScenario == null)
                {
                    // nothing to do
                    return;
                }

                // suspend capture until completion
                _trackerTimer.Stop();

                var scanSignals = _wlanScanner.GetScanSignals();
                if (scanSignals.Count == 0)
                {
                    // notify and ignore signals
                    if (TrackerNotification != null)
                    {
                        var args = new TrackerNotificationEventArgs
                        {
                            Code = TrackerNotificationCode.NoSignalsDetected
                        };
                        ThreadPool.QueueUserWorkItem(new WaitCallback(DoNotification), args);
                    }
                }
                else
                {
                    var example = new TrainingSetExample
                    {
                        ScanDateTime = DateTime.Now,
                        ScanSignals  = scanSignals
                    };

                    _targetScenario.TrainingSet.Add(example);
                    Debug.WriteLine("[Tracker] " + _targetScenario.ContextId.ToString()
                                    + " - Count: " + _targetScenario.TrainingSet.Count);
                    if (_targetScenario.TrainingSet.Count == TrainingThreshold)
                    {
                        if (TrackerNotification != null)
                        {
                            var args = new TrackerNotificationEventArgs
                            {
                                Code           = TrackerNotificationCode.TrainingCompleted,
                                TargetScenario = _targetScenario
                            };
                            ThreadPool.QueueUserWorkItem(new WaitCallback(DoNotification), args);
                        }
                    }
                }

                // resume capture before unlock
                _trackerTimer.Start();
            }
        }