Ejemplo n.º 1
0
        protected override async Task ExecuteAsync(CancellationToken cancellationToken)
        {
            var networkTargets = configuration.GetSection("targets").Get <NetworkTarget[]>();
            var ping           = new Ping();

            while (!cancellationToken.IsCancellationRequested)
            {
                foreach (NetworkTarget networkTarget in networkTargets)
                {
                    NetworkState state;

                    try
                    {
                        PingReply pingReply = await ping.SendPingAsync(networkTarget.NameOrAddress).ConfigureAwait(false);

                        state = pingReply?.Status == IPStatus.Success ? NetworkState.Up : NetworkState.Down;
                        logger.LogInformation($"{networkTarget.Description}: Current state is {state}");
                    }
                    catch (Exception)
                    {
                        state = NetworkState.Down;
                    }

                    DetectionState detectionState = networkTarget.SaveState(state);

                    if (detectionState > DetectionState.None)
                    {
                        await mailService.SendAsync($"{networkTarget.Description}: {detectionState} detected!").ConfigureAwait(false);
                    }
                }

                await Task.Delay(TimeSpan.FromSeconds(configuration.GetValue("sleepTime", 10)), cancellationToken).ConfigureAwait(false);
            }
        }
Ejemplo n.º 2
0
 public ShapeClip(DetectionState state, Vec2F position, Vec2F boundingBox, double angle)
 {
     this.DetectionState = state;
     this.Position       = position;
     this.BoundingBox    = boundingBox;
     this.Angle          = angle;
 }
Ejemplo n.º 3
0
 public static State GetInstance()
 {
     if (mSingleton != null)
     {
         return mSingleton;
     }
     mSingleton = new DetectionState();
     return mSingleton;
 }
Ejemplo n.º 4
0
        // Token: 0x060010BE RID: 4286
        private void UpdateRelicViewHUDState(CollectibleEntityView view)
        {
            // MOD: remove artifact views that are moved off the map
            if (view.Entity.GetComponent(10).Position2D.X > Fixed64.FromInt(100000))
            {
                this.DespawnAndRemoveRelicView(view.Entity, view);
                return;
            }
            // MOD

            SimStateFrame currentSimFrame = ShipbreakersMain.CurrentSimFrame;

            if (currentSimFrame == null)
            {
                return;
            }
            RelicState relicState = currentSimFrame.FindObject <RelicState>(view.Entity);

            if (relicState == null)
            {
                return;
            }
            CollectibleState collectibleState = currentSimFrame.FindObject <CollectibleState>(view.Entity);

            if (collectibleState == null)
            {
                return;
            }
            DetectionState visibility = relicState.Visibility;

            if (ReplayPanelController.RevealAll || SimController.sSpectatorModeEnabled)
            {
                visibility = DetectionState.Sensed;
            }
            bool flag = relicState.HasTimer && relicState.TimerDirection == TimerDirection.Countup && !relicState.TimerCompleted;

            if (collectibleState.AvailableForCollection)
            {
                this.UpdateRelicDefaultIconSprite(view, visibility, flag);
            }
            else
            {
                this.UpdateRelicAttachedIconSprite(view, DetectionState.Sensed, false);
            }
            this.UpdateRelicIconTrackOnScreenEdge(view, !flag);
            bool flag2 = view.ShouldShowIcon();

            view.ShowIcon(flag2);
            if (!flag2 && this.mShowingTooltipForEntity != Entity.None && this.mShowingTooltipForEntity == view.Entity)
            {
                this.mShowingTooltipForEntity = Entity.None;
                UISystem.HideTooltip();
            }
        }
Ejemplo n.º 5
0
 protected virtual void detectedEntities_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
 {
     if (detectedEntities.Count == 0 && detectionState != DetectionState.noDetection)
     {
         detectionState = DetectionState.noDetection;
     }
     else if (detectedEntities.Count > 0 && detectionState == DetectionState.noDetection)
     {
         detectionState = DetectionState.unknownDetection;
     }
 }
Ejemplo n.º 6
0
        public async void Play(DetectionState currentState)
        {
            var avgAge = currentState.FacesFoundByApi.OrderByDescending(x => x.faceAttributes.age).First().faceAttributes.age;

            var         demographic = GetDemographicFromAge(avgAge);
            StorageFile file        = await GetScriptFromDemographic(demographic);

            var thingstosay = await FileIO.ReadLinesAsync(file);

            Say(thingstosay.ToList());
        }
Ejemplo n.º 7
0
 private void InitStates()
 {
     istate    = new IState[9];
     istate[0] = new IdleState(gameObject);
     istate[1] = new PatrolState(gameObject);
     istate[2] = new SuspiciousState(gameObject);
     istate[3] = new DetectionState(gameObject);
     istate[4] = new AlertState(gameObject);
     istate[5] = new AttackState(gameObject);
     istate[6] = new EscapeState(gameObject);
     istate[7] = new StunState(gameObject);
     istate[8] = new DeadState(gameObject);
 }
Ejemplo n.º 8
0
    /// <summary>
    /// Send image data to plugin for SLAM detection
    /// </summary>
    /// <param name="pointer">image addess, pointer to first byte</param>
    /// <param name="width">image width</param>
    /// <param name="height">image height</param>
    /// <returns>current state of detection</returns>
    public static DetectionState SetNewFrame(IntPtr pointer, int width, int height)
    {
//		 Call plugin only when running on real device
        if (ViablePlatform())
        {
            DetectionState det_state = DetectionState.Stopped;
            string         state     = Marshal.PtrToStringAnsi(_SetNewFrame(pointer, width, height));
            switch (state)
            {
            case "Started":
            {
                det_state = DetectionState.Started;
                break;
            }

            case "InProgres":
            {
                det_state = DetectionState.InProgres;
                break;
            }

            case "Stopped":
            {
                det_state = DetectionState.Stopped;
                break;
            }

            case "Finished":
            {
                det_state = DetectionState.Finished;
                break;
            }

            default:
            {
                det_state = DetectionState.Finished;
                break;
            }
            }

            //det_state = (DetectionState)Enum.Parse(typeof(DetectionState), state);

            return(det_state);
        }
        // Return mockup values for code running inside Editor
        else
        {
            return(DetectionState.Finished);
        }
    }
    protected override void RefreshFeedBack(DetectionState newState)
    {
        base.RefreshFeedBack(newState);

        if (newState == DetectionState.noDetection)
        {
            feedbackBehavior.DetectionRangeFeedBack(false);
        }
        else if (detectionState == DetectionState.noDetection)
        {
            feedbackBehavior.DetectionRangeFeedBack(true);
        }

        //if (newState == DetectionState.revealedDetection) feedbackBehavior.UpdateReveal(true);
        //else if (detectionState == DetectionState.revealedDetection && newState != DetectionState.revealedDetection) feedbackBehavior.UpdateReveal(false);
    }
Ejemplo n.º 10
0
        public void Play(DetectionState currentState)
        {
            var           avgAge        = currentState.FacesFoundByApi.OrderByDescending(x => x.faceAttributes.age).First().faceAttributes.age;
            PlayListGroup playListGroup = GetPlayListGroupByDemographic(avgAge);

            var jsonArray = this.ja.GetNamedArray(playListGroup.ToString("F"));

            var playlist = new List <PlayListItem>();

            foreach (var item in jsonArray)
            {
                playlist.Add(new PlayListItem(playListGroup, 1, item.GetString()));
            }

            PlayWav(playlist);
        }
Ejemplo n.º 11
0
    protected virtual void Update()
    {
        debugDetected = detectedEntities.ToList();

        if (inMadRange && detectionState == DetectionState.unknownDetection)
        {
            detectionState = DetectionState.revealedDetection;
        }
        else if (!inMadRange && detectionState == DetectionState.revealedDetection && detectedEntities.Count > 0)
        {
            detectionState = DetectionState.unknownDetection;
        }
        else if (!inMadRange && detectionState == DetectionState.revealedDetection && detectedEntities.Count == 0)
        {
            detectionState = DetectionState.noDetection;
        }
    }
        /// <summary>
        /// Initializes a new instance of the <see cref="WebcamFaceDetector"/> class.
        /// </summary>
        public WebcamFaceDetector()
        {
            //Defaults
            AppSettings = ResourceLoader.GetForCurrentView();
            NumberMilliSecsForFacesToDisappear = int.Parse(AppSettings.GetString("NumberMilliSecsForFacesToDisappear"));
            NumberMilliSecsToWaitForHello      = int.Parse(AppSettings.GetString("NumberMilliSecsToWaitForHello"));
            NumberMillSecsBeforeWePlayAgain    = int.Parse(AppSettings.GetString("NumberMillSecsBeforeWePlayAgain"));
            TimerInterval = TimeSpan.FromMilliseconds(int.Parse(AppSettings.GetString("TimerIntervalMilliSecs")));
            ApiIntervalMs = double.Parse(AppSettings.GetString("ApiIntervalMilliSecs"));
            NumberMilliSecsForSpeechRecognitionTimeout = int.Parse(AppSettings.GetString("NumberMilliSecsForSpeechRecognitionTimeout"));

            InitializeComponent();

            CurrentState = new DetectionState {
                State = DetectionStates.Idle
            };
            App.Current.Suspending += OnSuspending;
        }
Ejemplo n.º 13
0
    //FeedBack modification depending on the state of detectionState
    protected override void RefreshFeedBack(DetectionState newState)
    {
        base.RefreshFeedBack(newState);

        if (newState == DetectionState.revealedDetection)
        {
            if (detectedEntities[0] != null && gameObject.activeInHierarchy)
            {
                feedbackBehavior.DisplayReveal(detectedEntities[0].detectFeedback.hullSonarRevealIcon, detectedEntities[0].detectFeedback.hullSonarRevealPointer);
            }
        }
        else if (detectionState == DetectionState.revealedDetection)
        {
            if (gameObject.activeInHierarchy)
            {
                feedbackBehavior.HideReveal();
            }
        }
    }
Ejemplo n.º 14
0
        public ObstacleDetection(UltrasonicDistanceSensor _Sensor, int ScanResolutionInMs = 100)
        {
            // initialize CurrentDistance to zero
            double CurrentDistanceInCm = 0;

            // Create a separate Task to scan distance between obstacle and sensor
            Task.Factory.StartNew(async() =>
            {
                // Loop infinity until the power is down
                while (true)
                {
                    // Verify current distance ahead and raise event if MinDistance distance is breached
                    if ((CurrentDistanceInCm = _Sensor.GetDistance()) <= MinDistance && CurrentState == DetectionState.Clear)
                    {
                        // Raise event only if it is not null
                        if (ObstacleDetected != null)
                        {
                            ObstacleDetected(DetectionState.Detected, CurrentDistanceInCm);
                        }
                        // Set current state
                        CurrentState = DetectionState.Detected;
                    }
                    else if (CurrentDistanceInCm > MinDistance && CurrentState == DetectionState.Detected) // Raise event if distance between object and sensor is greater than MinDistance
                    {
                        // Raise event only if it is not null
                        if (ObstacleDetected != null)
                        {
                            ObstacleDetected(DetectionState.Clear, CurrentDistanceInCm);
                        }
                        // Set current state
                        CurrentState = DetectionState.Clear;
                    }

                    // Wait for the next scan time
                    await Task.Delay(ScanResolutionInMs);
                }
            });
        }
Ejemplo n.º 15
0
        void recognizer_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
        {
            PluginLog.Log("Recognized text: " + e.Result.Text);

            var synthesizer = new SpeechSynthesizer();

            synthesizer.SetOutputToDefaultAudioDevice();

            try
            {
                switch (state)
                {
                case DetectionState.Hotword:

                    recognizer.RecognizeAsyncStop();

                    recognizer.UnloadGrammar(heyDalamudGrammar);
                    recognizer.LoadGrammar(actionGrammar);

                    recognizer.SetInputToDefaultAudioDevice();
                    recognizer.RecognizeAsync(RecognizeMode.Single);

                    player.SoundLocation =
                        Path.Combine(Path.GetDirectoryName(Assembly.GetAssembly(typeof(Plugin)).Location),
                                     "sound.wav");
                    player.Play();

                    state = DetectionState.Verb;

                    Task.Run(() =>
                    {
                        Thread.Sleep(9000);


                        if (state != DetectionState.Verb)
                        {
                            return;
                        }


                        synthesizer.SpeakAsync("Sorry, I didn't quite get that, please try again.");
                        recognizer.RecognizeAsyncStop();

                        recognizer.UnloadAllGrammars();
                        recognizer.LoadGrammar(heyDalamudGrammar);

                        state = DetectionState.Hotword;
                        recognizer.SetInputToDefaultAudioDevice();
                        recognizer.RecognizeAsync(RecognizeMode.Multiple);
                    });

                    break;

                case DetectionState.Verb:
                    state = DetectionState.Hotword;

                    recognizer.RecognizeAsyncStop();


                    var firstName = this.pluginInterface.ClientState.LocalPlayer != null
                            ? this.pluginInterface.ClientState.LocalPlayer.Name.Split()[0]
                            : string.Empty;

                    // realistic delay for interpretation
                    Thread.Sleep(700);

                    if (e.Result.Text.StartsWith("teleport to"))
                    {
                        var tpLoc = e.Result.Text.Substring("teleport to".Length);

                        if (string.IsNullOrEmpty(tpLoc))
                        {
                            synthesizer.Speak("You didn't tell me where to teleport to. Please try again.");
                        }
                        else
                        {
                            synthesizer.Speak($"Ok {firstName}, teleporting to {tpLoc}");

                            Thread.Sleep(200);

                            this.pluginInterface.CommandManager.ProcessCommand("/tp " + tpLoc);
                        }
                    }
                    else if (e.Result.Text.StartsWith("open item search"))
                    {
                        synthesizer.Speak($"Ok {firstName}, opening the item search");

                        Thread.Sleep(100);

                        this.pluginInterface.CommandManager.ProcessCommand("/xlitem");
                    }
                    else if (e.Result.Text.StartsWith("open the plugin installer"))
                    {
                        synthesizer.Speak($"Ok {firstName}, opening the plugin installer");

                        Thread.Sleep(100);

                        this.pluginInterface.CommandManager.ProcessCommand("/xlplugins");
                    }
                    else if (e.Result.Text.StartsWith("help me"))
                    {
                        synthesizer.Speak($"Hello {firstName}, thank you kindly for installing this plugin. Welcome to this virtual tour, which we will experience together! I am Dalamud, your virtual, intelligent FFXIV assistant, developed for you by our best R&D personnel. You can access me any time you are logged in by saying hey dalamud. Currently, you can say teleport to teleport to any location in-game. You can also open the plugin installer and the item search just with your vocal chords. Isn't that amazing? Now go and have fun!");

                        Thread.Sleep(100);

                        this.pluginInterface.CommandManager.ProcessCommand("/xlplugins");
                    }

                    recognizer.UnloadGrammar(actionGrammar);
                    recognizer.LoadGrammar(heyDalamudGrammar);

                    recognizer.SetInputToDefaultAudioDevice();
                    recognizer.RecognizeAsync(RecognizeMode.Multiple);
                    break;
                }
            }
            catch (Exception ex)
            {
                PluginLog.Error(ex, "Error in voice handling.");
            }
        }
Ejemplo n.º 16
0
 //Override this to perform feedBack modification depending on the state of detectionState
 protected virtual void RefreshFeedBack(DetectionState newState)
 {
 }
        // Token: 0x06001491 RID: 5265 RVA: 0x00083F90 File Offset: 0x00082190
        private void UpdateUnitHUDState(UnitView view)
        {
            if (view.PresentationControlOnly)
            {
                if (view.SensorView != null)
                {
                    view.SensorView.Enabled = false;
                }
                view.UnderlayActive          = false;
                view.AltitudeIndicatorActive = false;
                return;
            }
            SimStateFrame currentSimFrame = ShipbreakersMain.CurrentSimFrame;

            if (currentSimFrame == null)
            {
                return;
            }
            UnitState nonInterpolatedTickState = view.NonInterpolatedTickState;

            if (nonInterpolatedTickState == null || nonInterpolatedTickState.IsDocked)
            {
                return;
            }
            CommanderRelationship relationship = this.mInteractionProvider.GetRelationship(this.mCommanderManager.LocalCommanderID, nonInterpolatedTickState.OwnerCommander);
            bool           flag           = relationship != CommanderRelationship.Self;
            bool           flag2          = relationship == CommanderRelationship.Enemy;
            DetectionState detectionState = nonInterpolatedTickState.Visibility;

            if (ReplayPanelController.RevealAll || SimController.sSpectatorModeEnabled)
            {
                detectionState = DetectionState.Sensed;
            }
            bool flag3 = detectionState == DetectionState.Sensed;
            bool sTacticalOverlayEnabled = TacticalOverlayController.sTacticalOverlayEnabled;
            bool underlayActive          = Cursor.visible && (view.Selected || view.IsHovered) && sTacticalOverlayEnabled && !this.mSensorsActive && flag3;

            view.UnderlayActive = underlayActive;
            bool altitudeIndicatorActive = (view.Selected || this.mSensorsActive || sTacticalOverlayEnabled) && flag3;

            view.AltitudeIndicatorActive = altitudeIndicatorActive;
            if (view.SensorView != null)
            {
                // MOD
                bool enabled = !view.IsDriverDead && flag3 && (!flag || !flag2 ||
                                                               (ShipbreakersMain.ReplayMode == ReplayMode.ReplayingGame ||
                                                                mCommanderManager.GetCommanderFromID(mCommanderManager.LocalCommanderID).CommanderAttributes.Name == "SPECTATOR") &&
                                                               MapModManager.EnableEnemySensors); // Check if the player is spectating
                view.SensorView.IsFriendly = (relationship == CommanderRelationship.Self || relationship == CommanderRelationship.Ally);
                //MOD
                view.SensorView.Enabled = enabled;

                view.SensorView.Mode = (this.mSensorsActive ? UnitSensorView.SensorMode.SensorsView : UnitSensorView.SensorMode.GameView);
            }
            view.ForceIconOnlyMode = (this.mSensorsActive && view.ViewAttrs.LODTunings.ForceIconOnlyInSensors);
            UnitIconController iconControllerForView = this.GetIconControllerForView(view);

            if (iconControllerForView != null)
            {
                iconControllerForView.UpdateIconVisibilityAndSize(currentSimFrame);
            }
        }
Ejemplo n.º 18
0
    private ShapeClip DetectClip(CvSeq <CvPoint> contour, IplImage image)
    {
        // Approximate contours to rectange.
        CvMemStorage    cstorage = new CvMemStorage();
        CvSeq <CvPoint> verts    = contour.ApproxPoly(CvContour.SizeOf, cstorage, ApproxPolyMethod.DP, contour.ContourPerimeter() * 0.05);
        CvRect          rect     = Cv.BoundingRect(verts);

        // scale BB
        CvSize originalSize = rect.Size;
        CvSize size         = new CvSize((int)(rect.Width * 1.5), (int)(rect.Height * 1.5));
        CvSize sizeDist     = new CvSize(rect.Width - size.Width, rect.Height - size.Height);

        rect = new CvRect(
            Math.Max(rect.Location.X + sizeDist.Width / 2, 0),
            Math.Max(rect.Location.Y + sizeDist.Height / 2, 0), size.Width, size.Height);

        // If rect, convert to region of interest and approximate top.
        if (verts.Total >= 4 && new CvRect(0, 0, image.Width, image.Height).Contains(rect))
        {
            DetectionState detectionState = verts.Total == 4 ? DetectionState.SemiOriented : DetectionState.Candidate;
            double         angle          = (180.0 / Math.PI) * ComputeOrientationFromVerts(verts.ToArray());

            using (IplImage region = image.Clone(rect))
                using (IplImage finalRegion = image.Clone(rect))
                    using (IplImage colorRegion = new IplImage(region.Size.Width, region.Size.Height, BitDepth.U8, 3))
                        using (IplImage debug = new IplImage(region.Size.Width + 20, region.Size.Height + 20, BitDepth.U8, 3))
                        {
                            // Rotate into position based on the line angle estimate
                            Cv.WarpAffine(region, region, Cv.GetRotationMatrix2D(new CvPoint2D32f(rect.Width / 2, rect.Height / 2), angle, 1));
                            Cv.FloodFill(region, new CvPoint(0, 0), 255, 0, 150);

                            // Project image and find clusters
                            region.Not(region);
                            double[] horizontalProjection, verticalProjection;
                            int[]    horizontalPrjClusters = ComputeClusters(region, true, out horizontalProjection);
                            int      horizontalClusters = horizontalPrjClusters[0], lastHorizontalCluster = horizontalPrjClusters[1];
                            int[]    verticalPrjClusters = ComputeClusters(region, false, out verticalProjection);
                            int      verticalClusters = verticalPrjClusters[0], lastVerticalCluster = verticalPrjClusters[1];



                            // Correct the orientation based on the clusters found
                            bool foundLDRs = false;
                            if (verticalClusters > horizontalClusters)
                            {
                                // 90 deg

                                if (lastHorizontalCluster < region.Width / 2)
                                {
                                    // 90deg
                                    angle    += 90;
                                    foundLDRs = true;
                                }
                                else
                                {
                                    // 270 deg
                                    angle    += 270;
                                    foundLDRs = true;
                                }
                            }
                            else if (verticalClusters < horizontalClusters)
                            {
                                // 0 deg
                                if (lastVerticalCluster < region.Height / 2)
                                {
                                    // 0deg
                                    foundLDRs = true;
                                }
                                else
                                {
                                    // 180 deg
                                    angle    += 180;
                                    foundLDRs = true;
                                }
                            }
                            else
                            {
                                // something went wrong with our initial alignment
                                //    NO proper orientation found - could not identify the LDRs
                            }

                            #region DEBUG
                            //debug.Zero();
                            //Cv.CvtColor(finalRegion, colorRegion, ColorConversion.GrayToRgb);
                            //debug.DrawImage(20, 0, region.Width, region.Height, colorRegion);

                            //for (int i = 0; i < region.Width / 2; i++)
                            //    debug.DrawRect(20 + i, debug.Height - (int)(horizontalProjection[i] * 100), 20 + i, debug.Height, CvColor.Red, 1);
                            //for (int i = 0; i < region.Height / 2; i++)
                            //    debug.DrawRect(0, i, (int)(verticalProjection[i] * 100), i, CvColor.Red, 1);
                            //debugWindow.ShowImage(debug);
                            #endregion

                            if (foundLDRs)
                            {
                                detectionState = DetectionState.FullyOriented;
                            }
                        }

            // Compute pixel space mapping
            Vec2F scale = new Vec2F(screenResolution.X / image.Width, screenResolution.Y / image.Height);

            return(new ShapeClip(
                       detectionState,
                       new Vec2F(rect.Location.X + 0.5f * rect.Width, rect.Location.Y + 0.5f * rect.Height).Scale(scale),
                       new Vec2F(originalSize).Scale(scale),
                       angle));
        }
        else
        {
            return(null);
        }
    }