Beispiel #1
0
        public SumoReceiver(string host, int port, SumoSender sender, ref SumoInformations sumoInformations)
        {
            this.Host = host;
            this.Port = port;

            this._sender      = sender;
            SumoRemote        = new IPEndPoint(IPAddress.Any, port);
            this.BatteryLevel = 0;

            // Video frames
            this.VideoFrames       = new List <byte[]>();
            this.mutex_frames_Lock = new object(); // Lock();

            // Audio Frames
            this.AudioFrames = new List <byte[]>();

            _sumoInformations = sumoInformations;
        }
Beispiel #2
0
        /// <summary>
        /// If you want to have your proper piloting system
        /// </summary>
        /// <param name="DeviceIP"></param>
        public SumoController(List <string> DevicesList = null, bool _AlwaysPing = false)
        {
            // Process List of devices
            AlwaysPing = _AlwaysPing;
            if (DevicesList != null)
            {   // Start Discover thread for each device
                foreach (string device in DevicesList)
                {
                    StartPingThread(device);
                }
            }
            else
            {
                // No device list so try to detect default device
                StartPingThread(deviceIp);
            }

            LOGGER.GetInstance.Info(String.Format("Starting Controller"));
            EnableOpenCV     = false;
            sumoInformations = new SumoInformations();
        }
        public static Mat Decorate(Mat RawImage, SumoInformations sumoInformations)
        {
            if (sumoInformations == null)
            {
                return(RawImage);
            }

            Assembly _assembly = Assembly.GetExecutingAssembly();

            var dst  = new Mat();
            var logo = new Mat();

            // Double resolution to avoid bad logo
            dst = RawImage.Resize(new OpenCvSharp.Size(RawImage.Width * 2, RawImage.Height * 2), 0, 0, InterpolationFlags.Cubic);
            Scalar color;

            if (sumoInformations.IsBatteryUnderLevelAlert)
            {
                color = Scalar.Red;
            }
            else
            {
                color = Scalar.Black;
            }

            // Write Battery Level
            Cv2.PutText(dst, sumoInformations.BatteryLevel.ToString() + "%", new OpenCvSharp.Point((dst.Width / 2) - 140, 60), HersheyFonts.HersheyComplexSmall, 2.0, color, 2, LineTypes.AntiAlias, false);

            // Write wifi logo
            if (sumoInformations.Rssi < 0)
            {
                logo = BitmapConverter.ToMat(new Bitmap(_assembly.GetManifestResourceStream("SumoApplication.Images.wifi-signal-5.png")));
                if (sumoInformations.Rssi < -50)
                {
                    logo = BitmapConverter.ToMat(new Bitmap(_assembly.GetManifestResourceStream("SumoApplication.Images.wifi-signal-4.png")));
                }
                if (sumoInformations.Rssi < -60)
                {
                    logo = BitmapConverter.ToMat(new Bitmap(_assembly.GetManifestResourceStream("SumoApplication.Images.wifi-signal-3.png")));
                }
                if (sumoInformations.Rssi < -70)
                {
                    logo = BitmapConverter.ToMat(new Bitmap(_assembly.GetManifestResourceStream("SumoApplication.Images.wifi-signal-2.png")));
                }
                if (sumoInformations.Rssi < -80)
                {
                    logo = BitmapConverter.ToMat(new Bitmap(_assembly.GetManifestResourceStream("SumoApplication.Images.wifi-signal-1.png")));
                }
                if (sumoInformations.Rssi < -90)
                {
                    logo = BitmapConverter.ToMat(new Bitmap(_assembly.GetManifestResourceStream("SumoApplication.Images.wifi-signal-0.png")));
                }
                CopyTransparentImage(dst, logo, dst.Width - logo.Width - 10, 10);
            }

            // Link Quality
            logo = BitmapConverter.ToMat(new Bitmap(_assembly.GetManifestResourceStream("SumoApplication.Images.icons8-signal-filled-4.png")));
            if (sumoInformations.LinkQuality < 5)
            {
                logo = BitmapConverter.ToMat(new Bitmap(_assembly.GetManifestResourceStream("SumoApplication.Images.icons8-signal-filled-3.png")));
            }
            if (sumoInformations.LinkQuality < 4)
            {
                logo = BitmapConverter.ToMat(new Bitmap(_assembly.GetManifestResourceStream("SumoApplication.Images.icons8-signal-filled-2.png")));
            }
            if (sumoInformations.LinkQuality < 3)
            {
                logo = BitmapConverter.ToMat(new Bitmap(_assembly.GetManifestResourceStream("SumoApplication.Images.icons8-signal-filled-1.png")));
            }
            if (sumoInformations.LinkQuality < 1)
            {
                logo = BitmapConverter.ToMat(new Bitmap(_assembly.GetManifestResourceStream("SumoApplication.Images.icons8-signal-filled-0.png")));
            }

            CopyTransparentImage(dst, logo, 10, 10);

            // battery
            logo = BitmapConverter.ToMat(new Bitmap(_assembly.GetManifestResourceStream("SumoApplication.Images.icons8-low-battery-4.png")));
            if (sumoInformations.BatteryLevel < 70)
            {
                logo = BitmapConverter.ToMat(new Bitmap(_assembly.GetManifestResourceStream("SumoApplication.Images.icons8-low-battery-3.png")));
            }
            if (sumoInformations.BatteryLevel < 50)
            {
                logo = BitmapConverter.ToMat(new Bitmap(_assembly.GetManifestResourceStream("SumoApplication.Images.icons8-low-battery-2.png")));
            }
            if (sumoInformations.BatteryLevel < 20)
            {
                logo = BitmapConverter.ToMat(new Bitmap(_assembly.GetManifestResourceStream("SumoApplication.Images.icons8-low-battery-1.png")));
            }
            if (sumoInformations.BatteryLevel < 10)
            {
                logo = BitmapConverter.ToMat(new Bitmap(_assembly.GetManifestResourceStream("SumoApplication.Images.icons8-low-battery-0.png")));
            }

            CopyTransparentImage(dst, logo, (dst.Width / 2) - (logo.Width / 2), 0);

            // Posture
            if (sumoInformations.Posture == LibSumo.Net.Protocol.SumoEnumGenerated.PostureChanged_state.jumper)
            {
                logo = BitmapConverter.ToMat(new Bitmap(_assembly.GetManifestResourceStream("SumoApplication.Images.product_0902_posture_icn_jumper.png")));
            }
            else if (sumoInformations.Posture == LibSumo.Net.Protocol.SumoEnumGenerated.PostureChanged_state.kicker)
            {
                logo = BitmapConverter.ToMat(new Bitmap(_assembly.GetManifestResourceStream("SumoApplication.Images.product_0902_posture_icn_kicker.png")));
            }
            else if (sumoInformations.Posture == LibSumo.Net.Protocol.SumoEnumGenerated.PostureChanged_state.standing)
            {
                logo = BitmapConverter.ToMat(new Bitmap(_assembly.GetManifestResourceStream("SumoApplication.Images.product_0902_posture_icn_standing.png")));
            }

            CopyTransparentImage(dst, logo, 0, dst.Height - logo.Height);

            if (sumoInformations.Alert != SumoEnumGenerated.AlertStateChanged_state.none)
            {
                Cv2.PutText(dst, sumoInformations.Alert.ToString(), new OpenCvSharp.Point(100, dst.Height / 2), HersheyFonts.HersheyComplexSmall, 6.0, Scalar.Red, 4, LineTypes.AntiAlias, false);
            }

            if (sumoInformations.Speed != 0)
            {
                Cv2.PutText(dst, sumoInformations.Speed.ToString() + "cm/s", new OpenCvSharp.Point((dst.Width / 2) - 470, 60), HersheyFonts.HersheyComplexSmall, 2.0, color, 2, LineTypes.AntiAlias, false);
            }
            // TODO : Box icon (open/close)

            return(dst);
        }
Beispiel #4
0
        private void Controller_SumoEvents(object sender, SumoEventArgs e)
        {
            if (e.SumoInformations == null)
            {
                return;
            }
            sumoInformations = e.SumoInformations;
            switch (e.TypeOfEvent)
            {
            case (SumoEnumCustom.TypeOfEvents.AlertEvent):
                break;

            case (SumoEnumCustom.TypeOfEvents.BatteryLevelEvent):
                lblBatteryLevel.Dispatcher.BeginInvoke((Action)(() =>
                {
                    lblBatteryLevel.Content = sumoInformations.BatteryLevel + "%";
                }));
                break;

            case (SumoEnumCustom.TypeOfEvents.Connected):
                // Enable Btn
                InitUI();

                break;

            case (SumoEnumCustom.TypeOfEvents.Disconnected):
                break;

            case (SumoEnumCustom.TypeOfEvents.Discovered):

                txtBox.Dispatcher.BeginInvoke((Action)(() =>
                {
                    txtBox.AppendText(String.Format("Sumo {1} is available {0} ", Environment.NewLine, sumoInformations.DeviceName));
                    txtBox.ScrollToEnd();
                }));
#if MULTIPLEDRONES
                // Get btn reference for multidrone And display it
                try
                {
                    MiniDevice d       = ListOfDevices.Find(x => x.Name == sumoInformations.DeviceName);
                    Button     btn     = d.Button;
                    int        suffixe = d.Id;
                    btn.Dispatcher.BeginInvoke((Action)(() =>
                    {
                        btn.Content = prefixName + suffixe.ToString();
                        btn.Visibility = Visibility.Visible;
                    }));
                }
                catch { }
#endif
                break;

            case (SumoEnumCustom.TypeOfEvents.PilotingEvent):
                break;

            case (SumoEnumCustom.TypeOfEvents.PostureEvent):
                lblPostureState.Dispatcher.BeginInvoke((Action)(() =>
                {
                    lblPostureState.Content = "Sumo in: " + sumoInformations.Posture.ToString() + " position";
                }));
                break;

            case (SumoEnumCustom.TypeOfEvents.RSSI):
                lblRssi.Dispatcher.BeginInvoke((Action)(() =>
                {
                    lblRssi.Content = "Wifi Signal : " + sumoInformations.Rssi.ToString() + " dbm";
                }));
                break;

            case (SumoEnumCustom.TypeOfEvents.LinkQuality):
                lblQuality.Dispatcher.BeginInvoke((Action)(() =>
                {
                    lblQuality.Content = "Link Quality: " + sumoInformations.LinkQuality.ToString() + "/6";
                }));
                break;

            case (SumoEnumCustom.TypeOfEvents.VolumeChange):
                slVolume.Dispatcher.BeginInvoke((Action)(() =>
                {
                    slVolume.Value = sumoInformations.Volume;
                }));
                break;

            case (SumoEnumCustom.TypeOfEvents.CapabilitiesChange):
                chkBox.Dispatcher.BeginInvoke((Action)(() =>
                {
                    chkBox.IsChecked = sumoInformations.IsCapapableOf(SumoInformations.Capability.Box);
                    chkBoost.IsChecked = sumoInformations.IsCapapableOf(SumoInformations.Capability.Boost);
                    pnlAudio.IsEnabled = sumoInformations.IsCapapableOf(SumoInformations.Capability.Audio);
                    slLight.IsEnabled = sumoInformations.IsCapapableOf(SumoInformations.Capability.Light);
                    if (pnlAudio.IsEnabled)
                    {
                        InitSoundUI();
                        controller.InitAudio();
                    }
                }));
                break;

            case (SumoEnumCustom.TypeOfEvents.WifiChanged):
                cbxWifiBand.Dispatcher.BeginInvoke((Action)(() =>
                {
                    cbxWifiBand.SelectedIndex = (int)sumoInformations.WifiBand;
                }));
                break;

            case (SumoEnumCustom.TypeOfEvents.AudioThemeChanged):
                cbxAudioTheme.Dispatcher.BeginInvoke((Action)(() =>
                {
                    cbxAudioTheme.SelectedIndex = (int)sumoInformations.AudioTheme;
                }));
                break;
            }
        }